Beispiel #1
0
int setup_option(int c)
{
	switch(c)
	{
		case O_CHANNEL:parse_channels(optarg); break;
		case O_PCAP:   pcap_filename = optarg; break;
		case O_USER:   username = optarg; break;
		default: return 0;
	}

	return 1;
}
Beispiel #2
0
static int open_tv(tvi_handle_t *tvh)
{
    int i;
    const tvi_functions_t *funcs = tvh->functions;
    static const int tv_fmt_list[] = {
        IMGFMT_YV12,
        IMGFMT_I420,
        IMGFMT_UYVY,
        IMGFMT_YUY2,
        IMGFMT_RGB32,
        IMGFMT_RGB24,
        IMGFMT_RGB16,
        IMGFMT_RGB15
    };

    if (funcs->control(tvh->priv, TVI_CONTROL_IS_VIDEO, 0) != TVI_CONTROL_TRUE)
    {
        mp_msg(MSGT_TV, MSGL_ERR, MSGTR_TV_NoVideoInputPresent);
        return 0;
    }

    if (tvh->tv_param->outfmt == -1)
        for (i = 0; i < sizeof (tv_fmt_list) / sizeof (*tv_fmt_list); i++)
        {
            tvh->tv_param->outfmt = tv_fmt_list[i];
            if (funcs->control (tvh->priv, TVI_CONTROL_VID_SET_FORMAT,
                                &tvh->tv_param->outfmt) == TVI_CONTROL_TRUE)
                break;
        }
    else
    {
        switch(tvh->tv_param->outfmt)
        {
        case IMGFMT_YV12:
        case IMGFMT_I420:
        case IMGFMT_UYVY:
        case IMGFMT_YUY2:
        case IMGFMT_RGB32:
        case IMGFMT_RGB24:
        case IMGFMT_BGR32:
        case IMGFMT_BGR24:
        case IMGFMT_BGR16:
        case IMGFMT_BGR15:
            break;
        default:
            mp_msg(MSGT_TV, MSGL_ERR, MSGTR_TV_UnknownImageFormat,tvh->tv_param->outfmt);
        }
        funcs->control(tvh->priv, TVI_CONTROL_VID_SET_FORMAT, &tvh->tv_param->outfmt);
    }

    /* set some params got from cmdline */
    funcs->control(tvh->priv, TVI_CONTROL_SPC_SET_INPUT, &tvh->tv_param->input);

#if defined(CONFIG_TV_V4L2) || defined(CONFIG_TV_DSHOW)
    if (0
#ifdef CONFIG_TV_V4L2
            || (!strcmp(tvh->tv_param->driver, "v4l2") && tvh->tv_param->normid >= 0)
#endif
#ifdef CONFIG_TV_DSHOW
            || (!strcmp(tvh->tv_param->driver, "dshow") && tvh->tv_param->normid >= 0)
#endif
       )
        tv_set_norm_i(tvh, tvh->tv_param->normid);
    else
#endif
        tv_set_norm(tvh,tvh->tv_param->norm);

#ifdef CONFIG_TV_V4L1
    if ( tvh->tv_param->mjpeg )
    {
        /* set width to expected value */
        if (tvh->tv_param->width == -1)
        {
            tvh->tv_param->width = 704/tvh->tv_param->decimation;
        }
        if (tvh->tv_param->height == -1)
        {
            if ( tvh->norm != TV_NORM_NTSC )
                tvh->tv_param->height = 576/tvh->tv_param->decimation;
            else
                tvh->tv_param->height = 480/tvh->tv_param->decimation;
        }
        mp_msg(MSGT_TV, MSGL_INFO,
               MSGTR_TV_MJP_WidthHeight, tvh->tv_param->width, tvh->tv_param->height);
    }
#endif

    /* limits on w&h are norm-dependent -- JM */
    if (tvh->tv_param->width != -1 && tvh->tv_param->height != -1) {
        // first tell the driver both width and height, some drivers do not support setting them independently.
        int dim[2];
        dim[0] = tvh->tv_param->width;
        dim[1] = tvh->tv_param->height;
        funcs->control(tvh->priv, TVI_CONTROL_VID_SET_WIDTH_HEIGHT, dim);
    }
    /* set width */
    if (tvh->tv_param->width != -1)
    {
        if (funcs->control(tvh->priv, TVI_CONTROL_VID_CHK_WIDTH, &tvh->tv_param->width) == TVI_CONTROL_TRUE)
            funcs->control(tvh->priv, TVI_CONTROL_VID_SET_WIDTH, &tvh->tv_param->width);
        else
        {
            mp_msg(MSGT_TV, MSGL_ERR, MSGTR_TV_UnableToSetWidth, tvh->tv_param->width);
            funcs->control(tvh->priv, TVI_CONTROL_VID_GET_WIDTH, &tvh->tv_param->width);
        }
    }

    /* set height */
    if (tvh->tv_param->height != -1)
    {
        if (funcs->control(tvh->priv, TVI_CONTROL_VID_CHK_HEIGHT, &tvh->tv_param->height) == TVI_CONTROL_TRUE)
            funcs->control(tvh->priv, TVI_CONTROL_VID_SET_HEIGHT, &tvh->tv_param->height);
        else
        {
            mp_msg(MSGT_TV, MSGL_ERR, MSGTR_TV_UnableToSetHeight, tvh->tv_param->height);
            funcs->control(tvh->priv, TVI_CONTROL_VID_GET_HEIGHT, &tvh->tv_param->height);
        }
    }

    if (funcs->control(tvh->priv, TVI_CONTROL_IS_TUNER, 0) != TVI_CONTROL_TRUE)
    {
        mp_msg(MSGT_TV, MSGL_WARN, MSGTR_TV_NoTuner);
        goto done;
    }

    /* select channel list */
    for (i = 0; chanlists[i].name != NULL; i++)
    {
        if (!strcasecmp(chanlists[i].name, tvh->tv_param->chanlist))
        {
            tvh->chanlist = i;
            tvh->chanlist_s = chanlists[i].list;
            break;
        }
    }

    if (tvh->chanlist == -1) {
        mp_msg(MSGT_TV, MSGL_WARN, MSGTR_TV_UnableFindChanlist,
               tvh->tv_param->chanlist);
        return 0;
    } else
        mp_msg(MSGT_TV, MSGL_V, "Selected channel list: %s (including %d channels)\n",
               chanlists[tvh->chanlist].name, chanlists[tvh->chanlist].count);

    if (tvh->tv_param->freq && tvh->tv_param->channel)
    {
        mp_msg(MSGT_TV, MSGL_WARN, MSGTR_TV_ChannelFreqParamConflict);
        goto done;
    }

    /* Handle channel names */
    if (tvh->tv_param->channels) {
        parse_channels(tvh);
    } else
        tv_channel_last_real = malloc(5);

    if (tv_channel_list) {
        int i;
        int channel = 0;
        if (tvh->tv_param->channel)
        {
            if (isdigit(*tvh->tv_param->channel))
                /* if tvh->tv_param->channel begins with a digit interpret it as a number */
                channel = atoi(tvh->tv_param->channel);
            else
            {
                /* if tvh->tv_param->channel does not begin with a digit
                   set the first channel that contains tvh->tv_param->channel in its name */

                tv_channel_current = tv_channel_list;
                while ( tv_channel_current ) {
                    if ( strstr(tv_channel_current->name, tvh->tv_param->channel) )
                        break;
                    tv_channel_current = tv_channel_current->next;
                }
                if ( !tv_channel_current ) tv_channel_current = tv_channel_list;
            }
        }
        else
            channel = 1;

        if ( channel ) {
            tv_channel_current = tv_channel_list;
            for (i = 1; i < channel; i++)
                if (tv_channel_current->next)
                    tv_channel_current = tv_channel_current->next;
        }

        set_norm_and_freq(tvh, tv_channel_current);
        tv_channel_last = tv_channel_current;
    } else {
        /* we need to set frequency */
        if (tvh->tv_param->freq)
        {
            unsigned long freq = atof(tvh->tv_param->freq)*16;

            /* set freq in MHz */
            funcs->control(tvh->priv, TVI_CONTROL_TUN_SET_FREQ, &freq);

            funcs->control(tvh->priv, TVI_CONTROL_TUN_GET_FREQ, &freq);
            mp_msg(MSGT_TV, MSGL_V, "Selected frequency: %lu (%.3f)\n",
                   freq, freq/16.0);
        }

        if (tvh->tv_param->channel) {
            struct CHANLIST cl;

            mp_msg(MSGT_TV, MSGL_V, "Requested channel: %s\n", tvh->tv_param->channel);
            for (i = 0; i < chanlists[tvh->chanlist].count; i++)
            {
                cl = tvh->chanlist_s[i];
                //  printf("count%d: name: %s, freq: %d\n",
                //	i, cl.name, cl.freq);
                if (!strcasecmp(cl.name, tvh->tv_param->channel))
                {
                    strcpy(tv_channel_last_real, cl.name);
                    tvh->channel = i;
                    mp_msg(MSGT_TV, MSGL_INFO, MSGTR_TV_SelectedChannel2,
                           cl.name, cl.freq/1000.0);
                    tv_set_freq_float(tvh, cl.freq);
                    break;
                }
            }
        }
    }

    /* grep frequency in chanlist */
    {
        unsigned long i2;
        int freq;

        tv_get_freq(tvh, &i2);

        freq = (int) (((float)(i2/16))*1000)+250;

        for (i = 0; i < chanlists[tvh->chanlist].count; i++)
        {
            if (tvh->chanlist_s[i].freq == freq)
            {
                tvh->channel = i+1;
                break;
            }
        }
    }

done:
    /* also start device! */
    return 1;
}
Beispiel #3
0
Datei: tv.c Projekt: candux/mpv
static int open_tv(tvi_handle_t *tvh)
{
    int i;
    const tvi_functions_t *funcs = tvh->functions;
    static const int tv_fmt_list[] = {
      MP_FOURCC_YV12,
      MP_FOURCC_I420,
      MP_FOURCC_UYVY,
      MP_FOURCC_YUY2,
      MP_FOURCC_RGB32,
      MP_FOURCC_RGB24,
      MP_FOURCC_RGB16,
      MP_FOURCC_RGB15
    };

    if (funcs->control(tvh->priv, TVI_CONTROL_IS_VIDEO, 0) != TVI_CONTROL_TRUE)
    {
        MP_ERR(tvh, "Error: No video input present!\n");
        return 0;
    }

    if (tvh->tv_param->outfmt == -1)
      for (i = 0; i < sizeof (tv_fmt_list) / sizeof (*tv_fmt_list); i++)
        {
          tvh->tv_param->outfmt = tv_fmt_list[i];
          if (funcs->control (tvh->priv, TVI_CONTROL_VID_SET_FORMAT,
                              &tvh->tv_param->outfmt) == TVI_CONTROL_TRUE)
            break;
        }
    else
    {
    switch(tvh->tv_param->outfmt)
    {
        case MP_FOURCC_YV12:
        case MP_FOURCC_I420:
        case MP_FOURCC_UYVY:
        case MP_FOURCC_YUY2:
        case MP_FOURCC_RGB32:
        case MP_FOURCC_RGB24:
        case MP_FOURCC_BGR32:
        case MP_FOURCC_BGR24:
        case MP_FOURCC_BGR16:
        case MP_FOURCC_BGR15:
            break;
        default:
            MP_ERR(tvh, "==================================================================\n"\
                        " WARNING: UNTESTED OR UNKNOWN OUTPUT IMAGE FORMAT REQUESTED (0x%x)\n"\
                        " This may cause buggy playback or program crash! Bug reports will\n"\
                        " be ignored! You should try again with YV12 (which is the default\n"\
                        " colorspace) and read the documentation!\n"\
                        "==================================================================\n"
                ,tvh->tv_param->outfmt);
    }
    funcs->control(tvh->priv, TVI_CONTROL_VID_SET_FORMAT, &tvh->tv_param->outfmt);
    }

    /* set some params got from cmdline */
    funcs->control(tvh->priv, TVI_CONTROL_SPC_SET_INPUT, &tvh->tv_param->input);

    if ((!strcmp(tvh->tv_param->driver, "v4l2") && tvh->tv_param->normid >= 0))
        tv_set_norm_i(tvh, tvh->tv_param->normid);
    else
        tv_set_norm(tvh,tvh->tv_param->norm);

    /* limits on w&h are norm-dependent -- JM */
    if (tvh->tv_param->width != -1 && tvh->tv_param->height != -1) {
        // first tell the driver both width and height, some drivers do not support setting them independently.
        int dim[2];
        dim[0] = tvh->tv_param->width; dim[1] = tvh->tv_param->height;
        funcs->control(tvh->priv, TVI_CONTROL_VID_SET_WIDTH_HEIGHT, dim);
    }
    /* set width */
    if (tvh->tv_param->width != -1)
    {
        if (funcs->control(tvh->priv, TVI_CONTROL_VID_CHK_WIDTH, &tvh->tv_param->width) == TVI_CONTROL_TRUE)
            funcs->control(tvh->priv, TVI_CONTROL_VID_SET_WIDTH, &tvh->tv_param->width);
        else
        {
            MP_ERR(tvh, "Unable to set requested width: %d\n", tvh->tv_param->width);
            funcs->control(tvh->priv, TVI_CONTROL_VID_GET_WIDTH, &tvh->tv_param->width);
        }
    }

    /* set height */
    if (tvh->tv_param->height != -1)
    {
        if (funcs->control(tvh->priv, TVI_CONTROL_VID_CHK_HEIGHT, &tvh->tv_param->height) == TVI_CONTROL_TRUE)
            funcs->control(tvh->priv, TVI_CONTROL_VID_SET_HEIGHT, &tvh->tv_param->height);
        else
        {
            MP_ERR(tvh, "Unable to set requested height: %d\n", tvh->tv_param->height);
            funcs->control(tvh->priv, TVI_CONTROL_VID_GET_HEIGHT, &tvh->tv_param->height);
        }
    }

    if (funcs->control(tvh->priv, TVI_CONTROL_IS_TUNER, 0) != TVI_CONTROL_TRUE)
    {
        MP_WARN(tvh, "Selected input hasn't got a tuner!\n");
        goto done;
    }

    /* select channel list */
    for (i = 0; chanlists[i].name != NULL; i++)
    {
        if (!strcasecmp(chanlists[i].name, tvh->tv_param->chanlist))
        {
            tvh->chanlist = i;
            tvh->chanlist_s = chanlists[i].list;
            break;
        }
    }

    if (tvh->chanlist == -1) {
        MP_WARN(tvh, "Unable to find selected channel list! (%s)\n",
            tvh->tv_param->chanlist);
        return 0;
    } else
        MP_VERBOSE(tvh, "Selected channel list: %s (including %d channels)\n",
            chanlists[tvh->chanlist].name, chanlists[tvh->chanlist].count);

    if (tvh->tv_param->freq && tvh->tv_param->channel)
    {
        MP_WARN(tvh, "You can't set frequency and channel simultaneously!\n");
        goto done;
    }

    /* Handle channel names */
    if (tvh->tv_param->channels) {
        parse_channels(tvh);
    } else
            tv_channel_last_real = malloc(5);

    if (tv_channel_list) {
        int channel = 0;
        if (tvh->tv_param->channel)
         {
           if (isdigit(*tvh->tv_param->channel))
                /* if tvh->tv_param->channel begins with a digit interpret it as a number */
                channel = atoi(tvh->tv_param->channel);
           else
              {
                /* if tvh->tv_param->channel does not begin with a digit
                   set the first channel that contains tvh->tv_param->channel in its name */

                tv_channel_current = tv_channel_list;
                while ( tv_channel_current ) {
                        if ( strstr(tv_channel_current->name, tvh->tv_param->channel) )
                          break;
                        tv_channel_current = tv_channel_current->next;
                        }
                if ( !tv_channel_current ) tv_channel_current = tv_channel_list;
              }
         }
        else
                channel = 1;

        if ( channel ) {
        tv_channel_current = tv_channel_list;
        for (int n = 1; n < channel; n++)
                if (tv_channel_current->next)
                        tv_channel_current = tv_channel_current->next;
        }

        set_norm_and_freq(tvh, tv_channel_current);
        tv_channel_last = tv_channel_current;
    } else {
    /* we need to set frequency */
    if (tvh->tv_param->freq)
    {
        unsigned long freq = atof(tvh->tv_param->freq)*16;

        /* set freq in MHz */
        funcs->control(tvh->priv, TVI_CONTROL_TUN_SET_FREQ, &freq);

        funcs->control(tvh->priv, TVI_CONTROL_TUN_GET_FREQ, &freq);
        MP_VERBOSE(tvh, "Selected frequency: %lu (%.3f)\n",
            freq, freq/16.0);
    }

            if (tvh->tv_param->channel) {
        struct CHANLIST cl;

        MP_VERBOSE(tvh, "Requested channel: %s\n", tvh->tv_param->channel);
        for (i = 0; i < chanlists[tvh->chanlist].count; i++)
        {
            cl = tvh->chanlist_s[i];
                    //  printf("count%d: name: %s, freq: %d\n",
                    //  i, cl.name, cl.freq);
            if (!strcasecmp(cl.name, tvh->tv_param->channel))
            {
                        strcpy(tv_channel_last_real, cl.name);
                tvh->channel = i;
                MP_INFO(tvh, "Selected channel: %s (freq: %.3f)\n",
                    cl.name, cl.freq/1000.0);
                tv_set_freq_float(tvh, cl.freq);
                break;
            }
        }
    }
    }

    /* grep frequency in chanlist */
    {
        unsigned long i2;
        int freq;

        tv_get_freq(tvh, &i2);

        freq = (int) (((float)(i2/16))*1000)+250;

        for (i = 0; i < chanlists[tvh->chanlist].count; i++)
        {
            if (tvh->chanlist_s[i].freq == freq)
            {
                tvh->channel = i+1;
                break;
            }
        }
    }

done:
    /* also start device! */
        return 1;
}
bool pa_conversion_parse_input_channels(const char *fn, const unsigned ln,
                                        const char *str, bool legacy,
                                        audio_channel_mask_t *channels) {
    return parse_channels(fn, ln, str, false, legacy, channels);
}
/*****************************************************************
 * Stream initialization
 * \return STREAM_OK if success, STREAM_ERROR otherwise
 */
static int open_s(stream_t *stream,int mode, void* opts, int* file_format) {
    radio_priv_t* priv;
    float frequency=0;
    int i;

    if (strncmp("radio://",stream->url,8) != 0)
        return STREAM_UNSUPPORTED;

    if(mode != STREAM_READ)
        return STREAM_UNSUPPORTED;

    priv=calloc(1,sizeof(radio_priv_t));

    if (!priv)
        return STREAM_ERROR;


    priv->radio_param=opts;

#ifdef CONFIG_RADIO_CAPTURE
    if (priv->radio_param->capture && strncmp("capture",priv->radio_param->capture,7)==0)
        priv->do_capture=1;
    else
        priv->do_capture=0;
#endif



    if (strncmp(priv->radio_param->driver,"default",7)==0)
        priv->driver=radio_drivers[0];
    else
        priv->driver=NULL;

    mp_tmsg(MSGT_RADIO,MSGL_V,"[radio] Available drivers: ");
    for(i=0; radio_drivers[i]; i++) {
        mp_msg(MSGT_RADIO,MSGL_V,"%s, ",radio_drivers[i]->name);
        if(strcmp(priv->radio_param->driver,radio_drivers[i]->name)==0)
            priv->driver=radio_drivers[i];
    }
    mp_msg(MSGT_RADIO,MSGL_V,"\n");

    if(priv->driver)
        mp_msg(MSGT_RADIO, MSGL_INFO, priv->driver->info);
    else {
        mp_tmsg(MSGT_RADIO, MSGL_INFO, "[radio] Unknown driver name: %s\n",priv->radio_param->driver);
        close_s(stream);
        return STREAM_ERROR;
    }

    stream->type = STREAMTYPE_RADIO;
    /* using rawaudio demuxer */
    *file_format =  DEMUXER_TYPE_RAWAUDIO;
    stream->flags = STREAM_READ;

    priv->radio_fd=-1;

    stream->start_pos=0;
    stream->end_pos=0;
    stream->priv=priv;
    stream->close=close_s;
    stream->fill_buffer=fill_buffer_s;

    priv->radio_fd = open(priv->radio_param->device, O_RDONLY);
    if (priv->radio_fd < 0) {
        mp_tmsg(MSGT_RADIO, MSGL_ERR, "[radio] Unable to open '%s': %s\n",
                priv->radio_param->device, strerror(errno));
        close_s(stream);
        return STREAM_ERROR;
    }
    mp_tmsg(MSGT_RADIO, MSGL_V, "[radio] Radio fd: %d, %s\n", priv->radio_fd,priv->radio_param->device);
    fcntl(priv->radio_fd, F_SETFD, FD_CLOEXEC);

    get_volume(priv, &priv->old_snd_volume);
    set_volume(priv,0);

    if (init_frac(priv)!=STREAM_OK) {
        close_s(stream);
        return STREAM_ERROR;
    };

    if (parse_channels(priv,priv->radio_param->freq_channel,&frequency)!=STREAM_OK) {
        close_s(stream);
        return STREAM_ERROR;
    }

    if ((frequency<priv->rangelow)||(frequency>priv->rangehigh)) {
        mp_tmsg(MSGT_RADIO, MSGL_ERR, "[radio] Wrong frequency: %.2f\n",frequency);
        close_s(stream);
        return STREAM_ERROR;
    } else
        mp_tmsg(MSGT_RADIO, MSGL_INFO, "[radio] Using frequency: %.2f.\n",frequency);

    if(set_frequency(priv,frequency)!=STREAM_OK) {
        close_s(stream);
        return STREAM_ERROR;
    }


    if (init_audio(priv)!=STREAM_OK) {
        close_s(stream);
        return STREAM_ERROR;
    }

#if defined(CONFIG_RADIO_CAPTURE) && defined(CONFIG_STREAM_CACHE)
    if(priv->do_capture) {
        //5 second cache
        if(!stream_enable_cache(stream,5*priv->audio_in.samplerate*priv->audio_in.channels*
                                priv->audio_in.bytes_per_sample,2*priv->audio_in.samplerate*priv->audio_in.channels*
                                priv->audio_in.bytes_per_sample,priv->audio_in.blocksize)) {
            mp_tmsg(MSGT_RADIO, MSGL_ERR, "[radio] Call to stream_enable_cache failed: %s\n",strerror(errno));
            close_s(stream);
            return STREAM_ERROR;
        }
    }
#endif

    set_volume(priv,priv->radio_param->volume);

    return STREAM_OK;
}
Beispiel #6
0
static void conf_channel(char *data)
{
	parse_channels(data);
}