Beispiel #1
0
Datei: tv.c Projekt: candux/mpv
int tv_set_norm(tvi_handle_t *tvh, char* norm)
{
    tvh->norm = norm_from_string(tvh, norm);

    MP_VERBOSE(tvh, "Selected norm : %s\n", norm);
    if (tvh->functions->control(tvh->priv, TVI_CONTROL_TUN_SET_NORM, &tvh->norm) != TVI_CONTROL_TRUE) {
        MP_ERR(tvh, "Error: Cannot set norm!\n");
        return 0;
    }
    return 1;
}
Beispiel #2
0
int tv_set_norm(tvi_handle_t *tvh, char* norm)
{
    tvh->norm = norm_from_string(tvh, norm);

    mp_msg(MSGT_TV, MSGL_V, MSGTR_TV_SelectedNorm, tvh->tv_param->norm);
    if (tvh->functions->control(tvh->priv, TVI_CONTROL_TUN_SET_NORM, &tvh->norm) != TVI_CONTROL_TRUE) {
	mp_msg(MSGT_TV, MSGL_ERR, MSGTR_TV_CannotSetNorm);
	return 0;
    }
    tvh->functions->control(tvh->priv,TV_VBI_CONTROL_RESET,tvh->tv_param);
    return(1);
}
Beispiel #3
0
int tv_set_norm(tvi_handle_t *tvh, char* norm)
{
    tvh->norm = norm_from_string(tvh, norm);

    mp_msg(MSGT_TV, MSGL_V, "Selected norm : %s\n", norm);
    if (tvh->functions->control(tvh->priv, TVI_CONTROL_TUN_SET_NORM, &tvh->norm) != TVI_CONTROL_TRUE) {
        mp_msg(MSGT_TV, MSGL_ERR, MSGTR_TV_CannotSetNorm);
        return 0;
    }
    teletext_control(tvh->demuxer->teletext,TV_VBI_CONTROL_RESET,
                     &tvh->tv_param->teletext);
    return 1;
}
Beispiel #4
0
static void parse_channels(tvi_handle_t *tvh)
{
    char** channels = tvh->tv_param->channels;

    mp_msg(MSGT_TV, MSGL_INFO, MSGTR_TV_ChannelNamesDetected);
    tv_channel_list = malloc(sizeof(tv_channels_t));
    tv_channel_list->index=1;
    tv_channel_list->next=NULL;
    tv_channel_list->prev=NULL;
    tv_channel_current = tv_channel_list;
    tv_channel_current->norm = tvh->norm;

    while (*channels) {
        char* tmp = *(channels++);
        char* sep = strchr(tmp,'-');
        int i;
        struct CHANLIST cl;

        if (!sep) continue; // Wrong syntax, but mplayer should not crash

        av_strlcpy(tv_channel_current->name, sep + 1,
                   sizeof(tv_channel_current->name));
        sep[0] = '\0';
        strncpy(tv_channel_current->number, tmp, 5);
        tv_channel_current->number[4]='\0';

        while ((sep=strchr(tv_channel_current->name, '_')))
            sep[0] = ' ';

        // if channel number is a number and larger than 1000 threat it as frequency
        // tmp still contain pointer to null-terminated string with channel number here
        if (atoi(tmp)>1000) {
            tv_channel_current->freq=atoi(tmp);
        } else {
            tv_channel_current->freq = 0;
            for (i = 0; i < chanlists[tvh->chanlist].count; i++) {
                cl = tvh->chanlist_s[i];
                if (!strcasecmp(cl.name, tv_channel_current->number)) {
                    tv_channel_current->freq=cl.freq;
                    break;
                }
            }
        }
        if (tv_channel_current->freq == 0)
            mp_msg(MSGT_TV, MSGL_ERR, MSGTR_TV_NoFreqForChannel,
                   tv_channel_current->number, tv_channel_current->name);
        else {
            sep = strchr(tv_channel_current->name, '-');
            if ( !sep ) sep = strchr(tv_channel_current->name, '+');

            if ( sep ) {
                i = atoi (sep+1);
                if ( sep[0] == '+' ) tv_channel_current->freq += i * 100;
                if ( sep[0] == '-' ) tv_channel_current->freq -= i * 100;
                sep[0] = '\0';
            }

            sep = strchr(tv_channel_current->name, '=');
            if ( sep ) {
                tv_channel_current->norm = norm_from_string(tvh, sep+1);
                sep[0] = '\0';
            }
        }

        /*mp_msg(MSGT_TV, MSGL_INFO, "-- Detected channel %s - %s (%5.3f)\n",
                        tv_channel_current->number, tv_channel_current->name,
                        (float)tv_channel_current->freq/1000);*/

        tv_channel_current->next = malloc(sizeof(tv_channels_t));
        tv_channel_current->next->index = tv_channel_current->index + 1;
        tv_channel_current->next->prev = tv_channel_current;
        tv_channel_current->next->next = NULL;
        tv_channel_current = tv_channel_current->next;
        tv_channel_current->norm = tvh->norm;
    }
    if (tv_channel_current->prev)
        tv_channel_current->prev->next = NULL;
    free(tv_channel_current);
}
Beispiel #5
0
static int open_tv(tvi_handle_t *tvh)
{
    int i;
    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);

#ifdef HAVE_TV_V4L2
    if (!strcmp(tvh->tv_param->driver, "v4l2") && tvh->tv_param->normid >= 0) {
	mp_msg(MSGT_TV, MSGL_V, MSGTR_TV_SelectedNormId, tvh->tv_param->normid);
	if (funcs->control(tvh->priv, TVI_CONTROL_TUN_SET_NORM, &tvh->tv_param->normid) != TVI_CONTROL_TRUE) {
	    mp_msg(MSGT_TV, MSGL_ERR, MSGTR_TV_CannotSetNorm);
	}
    } else {
#endif
    /* select video norm */
    tvh->norm = norm_from_string(tvh, tvh->tv_param->norm);

    mp_msg(MSGT_TV, MSGL_V, MSGTR_TV_SelectedNorm, tvh->tv_param->norm);
    if (funcs->control(tvh->priv, TVI_CONTROL_TUN_SET_NORM, &tvh->norm) != TVI_CONTROL_TRUE) {
	mp_msg(MSGT_TV, MSGL_ERR, MSGTR_TV_CannotSetNorm);
    }
#ifdef HAVE_TV_V4L2
    }
#endif

#ifdef HAVE_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 */
    /* 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, MSGTR_TV_SelectedChanlist,
	    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_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, MSGTR_TV_SelectedFrequency,
	    freq, (float)freq/16);
    }

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

	mp_msg(MSGT_TV, MSGL_V, MSGTR_TV_RequestedChannel, 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;
}