Exemplo n.º 1
0
int tv_step_channel_real(tvi_handle_t *tvh, int direction)
{
    struct CHANLIST cl;

    tvh->tv_param->scan=0;
    if (direction == TV_CHANNEL_LOWER)
    {
	if (tvh->channel-1 >= 0)
	{
	    strcpy(tv_channel_last_real, tvh->chanlist_s[tvh->channel].name);
	    cl = tvh->chanlist_s[--tvh->channel];
	    mp_msg(MSGT_TV, MSGL_INFO, MSGTR_TV_SelectedChannel2,
		cl.name, (float)cl.freq/1000);
	    tv_set_freq(tvh, (unsigned long)(((float)cl.freq/1000)*16));
	}
    }

    if (direction == TV_CHANNEL_HIGHER)
    {
	if (tvh->channel+1 < chanlists[tvh->chanlist].count)
	{
	    strcpy(tv_channel_last_real, tvh->chanlist_s[tvh->channel].name);
	    cl = tvh->chanlist_s[++tvh->channel];
	    mp_msg(MSGT_TV, MSGL_INFO, MSGTR_TV_SelectedChannel2,
		cl.name, (float)cl.freq/1000);
	    tv_set_freq(tvh, (unsigned long)(((float)cl.freq/1000)*16));
	}
    }
    return 1;
}
Exemplo n.º 2
0
int tv_step_channel(tvi_handle_t *tvh, int direction) {
	tvh->tv_param->scan=0;
	if (tv_channel_list) {
		if (direction == TV_CHANNEL_HIGHER) {
			tv_channel_last = tv_channel_current;
			if (tv_channel_current->next)
				tv_channel_current = tv_channel_current->next;
			else
				tv_channel_current = tv_channel_list;

				tv_set_norm_i(tvh, tv_channel_current->norm);
				tv_set_freq(tvh, (unsigned long)(((float)tv_channel_current->freq/1000)*16));
				mp_msg(MSGT_TV, MSGL_INFO, MSGTR_TV_SelectedChannel3,
			tv_channel_current->number, tv_channel_current->name, (float)tv_channel_current->freq/1000);
		}
		if (direction == TV_CHANNEL_LOWER) {
			tv_channel_last = tv_channel_current;
			if (tv_channel_current->prev)
				tv_channel_current = tv_channel_current->prev;
			else
				while (tv_channel_current->next)
					tv_channel_current = tv_channel_current->next;
				tv_set_norm_i(tvh, tv_channel_current->norm);
				tv_set_freq(tvh, (unsigned long)(((float)tv_channel_current->freq/1000)*16));
				mp_msg(MSGT_TV, MSGL_INFO, MSGTR_TV_SelectedChannel3,
			tv_channel_current->number, tv_channel_current->name, (float)tv_channel_current->freq/1000);
		}
	} else tv_step_channel_real(tvh, direction);
	return 1;
}
Exemplo n.º 3
0
int tv_last_channel(tvi_handle_t *tvh) {

	tvh->tv_param->scan=0;
	if (tv_channel_list) {
		tv_channels_t *tmp;

		tmp = tv_channel_last;
		tv_channel_last = tv_channel_current;
		tv_channel_current = tmp;

		mp_msg(MSGT_TV, MSGL_INFO, MSGTR_TV_SelectedChannel3, tv_channel_current->number,
				tv_channel_current->name, (float)tv_channel_current->freq/1000);
		tv_set_norm_i(tvh, tv_channel_current->norm);
		tv_set_freq(tvh, (unsigned long)(((float)tv_channel_current->freq/1000)*16));
	} else {
		int i;
		struct CHANLIST cl;

		for (i = 0; i < chanlists[tvh->chanlist].count; i++)
		{
		    cl = tvh->chanlist_s[i];
		    if (!strcasecmp(cl.name, tv_channel_last_real))
		    {
			strcpy(tv_channel_last_real, tvh->chanlist_s[tvh->channel].name);
			tvh->channel = i;
			mp_msg(MSGT_TV, MSGL_INFO, MSGTR_TV_SelectedChannel2,
			    cl.name, (float)cl.freq/1000);
			tv_set_freq(tvh, (unsigned long)(((float)cl.freq/1000)*16));
			break;
		    }
		}
	}
	return 1;
}
Exemplo n.º 4
0
/*****************************************************************
 * \brief tune current frequency by step_interval value
 * \parameter step_interval increment value in 1/16 MHz
 * \note frequency is rounded to 1/16 MHz value
 * \return 1
 *
 */
int tv_step_freq(tvi_handle_t* tvh, float step_interval) {
    unsigned long frequency;

    tvh->tv_param->scan=0;
    tv_get_freq(tvh,&frequency);
    frequency+=step_interval;
    return tv_set_freq(tvh,frequency);
}
Exemplo n.º 5
0
int tv_set_channel(tvi_handle_t *tvh, char *channel) {
	int i, channel_int;

	tvh->tv_param->scan=0;
	if (tv_channel_list) {
		tv_channel_last = tv_channel_current;
		channel_int = atoi(channel);
		tv_channel_current = tv_channel_list;
		for (i = 1; i < channel_int; i++)
			if (tv_channel_current->next)
				tv_channel_current = tv_channel_current->next;
		mp_msg(MSGT_TV, MSGL_INFO, MSGTR_TV_SelectedChannel3, tv_channel_current->number,
				tv_channel_current->name, (float)tv_channel_current->freq/1000);
		tv_set_freq(tvh, (unsigned long)(((float)tv_channel_current->freq/1000)*16));
	} else tv_set_channel_real(tvh, channel);
	return(1);
}
Exemplo n.º 6
0
Arquivo: tv.c Projeto: HermiG/mplayer2
int tv_set_channel(tvi_handle_t *tvh, char *channel) {
	int i, channel_int;

	tvh->tv_param->scan=0;
	if (tv_channel_list) {
		tv_channel_last = tv_channel_current;
		channel_int = atoi(channel);
		tv_channel_current = tv_channel_list;
		for (i = 1; i < channel_int; i++)
			if (tv_channel_current->next)
				tv_channel_current = tv_channel_current->next;
		mp_tmsg(MSGT_TV, MSGL_INFO, "Selected channel: %s - %s (freq: %.3f)\n", tv_channel_current->number,
				tv_channel_current->name, (float)tv_channel_current->freq/1000);
		tv_set_norm_i(tvh, tv_channel_current->norm);
		tv_set_freq(tvh, (unsigned long)(((float)tv_channel_current->freq/1000)*16));
	} else tv_set_channel_real(tvh, channel);
	return 1;
}
Exemplo n.º 7
0
Arquivo: tv.c Projeto: AddictXQ/mpv
int tv_stream_control(tvi_handle_t *tvh, int cmd, void *arg)
{
    switch (cmd) {
    case STREAM_CTRL_TV_SET_SCAN:
        tv_start_scan(tvh, *(int *)arg);
        return STREAM_OK;
    case STREAM_CTRL_SET_TV_FREQ:
        tv_set_freq(tvh, *(float *)arg * 16.0f);
        return STREAM_OK;
    case STREAM_CTRL_GET_TV_FREQ: {
        unsigned long tmp = 0;
        tv_get_freq(tvh, &tmp);
        *(float *)arg = tmp / 16.0f;
        return STREAM_OK;
    }
    case STREAM_CTRL_SET_TV_COLORS:
        tv_set_color_options(tvh, ((int *)arg)[0], ((int *)arg)[1]);
        return STREAM_OK;
    case STREAM_CTRL_GET_TV_COLORS:
        tv_get_color_options(tvh, ((int *)arg)[0], &((int *)arg)[1]);
        return STREAM_OK;
    case STREAM_CTRL_TV_SET_NORM:
        tv_set_norm(tvh, (char *)arg);
        return STREAM_OK;
    case STREAM_CTRL_TV_STEP_NORM:
        tv_step_norm(tvh);
        return STREAM_OK;
    case STREAM_CTRL_TV_SET_CHAN:
        tv_set_channel(tvh, (char *)arg);
        return STREAM_OK;
    case STREAM_CTRL_TV_STEP_CHAN:
        if (*(int *)arg >= 0) {
            tv_step_channel(tvh, TV_CHANNEL_HIGHER);
        } else {
            tv_step_channel(tvh, TV_CHANNEL_LOWER);
        }
        return STREAM_OK;
    case STREAM_CTRL_TV_LAST_CHAN:
        tv_last_channel(tvh);
        return STREAM_OK;
    }
    return STREAM_UNSUPPORTED;
}
Exemplo n.º 8
0
int tv_set_channel_real(tvi_handle_t *tvh, char *channel) {
	int i;
	struct CHANLIST cl;

        tvh->tv_param->scan=0;
        strcpy(tv_channel_last_real, tvh->chanlist_s[tvh->channel].name);
	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, channel))
	    {
		tvh->channel = i;
		mp_msg(MSGT_TV, MSGL_INFO, MSGTR_TV_SelectedChannel2,
		    cl.name, (float)cl.freq/1000);
		tv_set_freq(tvh, (unsigned long)(((float)cl.freq/1000)*16));
		break;
	    }
	}
	return 1;
}
Exemplo n.º 9
0
static int tv_set_freq_float(tvi_handle_t *tvh, float freq)
{
    return tv_set_freq(tvh, freq/1000.0*16);
}
Exemplo n.º 10
0
static int open_tv(tvi_handle_t *tvh)
{
    int i;
    const tvi_functions_t *funcs = tvh->functions;
    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);
    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;
	}

	mp_msg(MSGT_TV, MSGL_INFO, MSGTR_TV_SelectedChannel3, tv_channel_current->number,
			tv_channel_current->name, (float)tv_channel_current->freq/1000);
	tv_set_norm_i(tvh, tv_channel_current->norm);
	tv_set_freq(tvh, (unsigned long)(((float)tv_channel_current->freq/1000)*16));
	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, (float)freq/16);
    }

	    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, (float)cl.freq/1000);
		tv_set_freq(tvh, (unsigned long)(((float)cl.freq/1000)*16));
		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;
}
Exemplo n.º 11
0
static void tv_scan(tvi_handle_t *tvh)
{
    unsigned int now;
    struct CHANLIST cl;
    tv_channels_t *tv_channel_tmp=NULL;
    tv_channels_t *tv_channel_add=NULL;
    tv_scan_t* scan;
    int found=0, index=1;

    //Channel scanner without tuner is useless and causes crash due to uninitialized chanlist_s
    if (tvh->functions->control(tvh->priv, TVI_CONTROL_IS_TUNER, 0) != TVI_CONTROL_TRUE)
    {
        mp_msg(MSGT_TV, MSGL_WARN, MSGTR_TV_ScannerNotAvailableWithoutTuner);
        tvh->tv_param->scan=0;
        return;
    }

    scan = tvh->scan;
    now=GetTimer();
    if (!scan) {
        scan=calloc(1,sizeof(tv_scan_t));
        tvh->scan=scan;
        cl = tvh->chanlist_s[scan->channel_num];
        tv_set_freq(tvh, (unsigned long)(((float)cl.freq/1000)*16));
        scan->scan_timer=now+1e6*tvh->tv_param->scan_period;
    }
    if(scan->scan_timer>now)
        return;

    if (tv_get_signal(tvh)>tvh->tv_param->scan_threshold) {
        cl = tvh->chanlist_s[scan->channel_num];
        tv_channel_tmp=tv_channel_list;
        while (tv_channel_tmp) {
            index++;
            if (cl.freq==tv_channel_tmp->freq){
                found=1;
                break;
            }
            tv_channel_add=tv_channel_tmp;
            tv_channel_tmp=tv_channel_tmp->next;
        }
        if (!found) {
            mp_msg(MSGT_TV, MSGL_INFO, "Found new channel: %s (#%d). \n",cl.name,index);
            scan->new_channels++;
            tv_channel_tmp = malloc(sizeof(tv_channels_t));
            tv_channel_tmp->index=index;
            tv_channel_tmp->next=NULL;
            tv_channel_tmp->prev=tv_channel_add;
            tv_channel_tmp->freq=cl.freq;
            snprintf(tv_channel_tmp->name,sizeof(tv_channel_tmp->name),"ch%d",index);
            strncpy(tv_channel_tmp->number, cl.name, 5);
            tv_channel_tmp->number[4]='\0';
            if (!tv_channel_list)
                tv_channel_list=tv_channel_tmp;
            else {
                tv_channel_add->next=tv_channel_tmp;
                tv_channel_list->prev=tv_channel_tmp;
            }
        }else
            mp_msg(MSGT_TV, MSGL_INFO, "Found existing channel: %s-%s.\n",
                tv_channel_tmp->number,tv_channel_tmp->name);
    }
    scan->channel_num++;
    scan->scan_timer=now+1e6*tvh->tv_param->scan_period;
    if (scan->channel_num>=chanlists[tvh->chanlist].count) {
        tvh->tv_param->scan=0;
        mp_msg(MSGT_TV, MSGL_INFO, "TV scan end. Found %d new channels.\n", scan->new_channels);
        tv_channel_tmp=tv_channel_list;
        if(tv_channel_tmp){
            mp_msg(MSGT_TV,MSGL_INFO,"channels=");
            while(tv_channel_tmp){
                mp_msg(MSGT_TV,MSGL_INFO,"%s-%s",tv_channel_tmp->number,tv_channel_tmp->name);
                if(tv_channel_tmp->next)
                    mp_msg(MSGT_TV,MSGL_INFO,",");
                tv_channel_tmp=tv_channel_tmp->next;
            }
            mp_msg(MSGT_TV, MSGL_INFO, "\n");
        }
        if (!tv_channel_current) tv_channel_current=tv_channel_list;
        if (tv_channel_current)
            tv_set_freq(tvh, (unsigned long)(((float)tv_channel_current->freq/1000)*16));
        free(tvh->scan);
        tvh->scan=NULL;
    }else{
        cl = tvh->chanlist_s[scan->channel_num];
        tv_set_freq(tvh, (unsigned long)(((float)cl.freq/1000)*16));
        mp_msg(MSGT_TV, MSGL_INFO, "Trying: %s (%.2f). \n",cl.name,1e-3*cl.freq);
    }
}
Exemplo n.º 12
0
Arquivo: tv.c Projeto: HermiG/mplayer2
static int open_tv(tvi_handle_t *tvh)
{
    int i;
    const tvi_functions_t *funcs = tvh->functions;
    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_tmsg(MSGT_TV, MSGL_ERR, "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 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_tmsg(MSGT_TV, MSGL_ERR,
			"==================================================================\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 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_tmsg(MSGT_TV, MSGL_INFO,
	       "  MJP: width %d height %d\n", 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_tmsg(MSGT_TV, MSGL_ERR, "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_tmsg(MSGT_TV, MSGL_ERR, "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_tmsg(MSGT_TV, MSGL_WARN, "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_tmsg(MSGT_TV, MSGL_WARN, "Unable to find selected channel list! (%s)\n",
	    tvh->tv_param->chanlist);
    else
	mp_tmsg(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_tmsg(MSGT_TV, MSGL_WARN, "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 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;
	}

	mp_tmsg(MSGT_TV, MSGL_INFO, "Selected channel: %s - %s (freq: %.3f)\n", tv_channel_current->number,
			tv_channel_current->name, (float)tv_channel_current->freq/1000);
	tv_set_norm_i(tvh, tv_channel_current->norm);
	tv_set_freq(tvh, (unsigned long)(((float)tv_channel_current->freq/1000)*16));
	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_tmsg(MSGT_TV, MSGL_V, "Selected frequency: %lu (%.3f)\n",
	    freq, (float)freq/16);
    }

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

	mp_tmsg(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_tmsg(MSGT_TV, MSGL_INFO, "Selected channel: %s (freq: %.3f)\n",
		    cl.name, (float)cl.freq/1000);
		tv_set_freq(tvh, (unsigned long)(((float)cl.freq/1000)*16));
		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;
}