⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tv.c

📁 自己移植的linux下的流媒体播放器原代码,支持mms协议,支持ftp和http协议.
💻 C
📖 第 1 页 / 共 2 页
字号:
    }        /* 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;}int demux_open_tv(demuxer_t *demuxer){    tvi_handle_t *tvh;    sh_video_t *sh_video;    sh_audio_t *sh_audio = NULL;    tvi_functions_t *funcs;        if(!(tvh=tv_begin())) return 0;    if (!tv_init(tvh)) return 0;    if (!open_tv(tvh)){	tv_uninit(tvh);	return 0;    }    funcs = tvh->functions;    demuxer->priv=tvh;        sh_video = new_sh_video(demuxer, 0);    /* get IMAGE FORMAT */    funcs->control(tvh->priv, TVI_CONTROL_VID_GET_FORMAT, &sh_video->format);//    if (IMGFMT_IS_RGB(sh_video->format) || IMGFMT_IS_BGR(sh_video->format))//	sh_video->format = 0x0;    /* set FPS and FRAMETIME */    if(!sh_video->fps)    {        float tmp;        if (funcs->control(tvh->priv, TVI_CONTROL_VID_GET_FPS, &tmp) != TVI_CONTROL_TRUE)             sh_video->fps = 25.0f; /* on PAL */        else sh_video->fps = tmp;    }    if (tv_param_fps != -1.0f)        sh_video->fps = tv_param_fps;    sh_video->frametime = 1.0f/sh_video->fps;    /* If playback only mode, go to immediate mode, fail silently */    if(tv_param_immediate == 1)        {        funcs->control(tvh->priv, TVI_CONTROL_IMMEDIATE, 0);        tv_param_noaudio = 1;         }    /* disable TV audio if -nosound is present */    if (!demuxer->audio || demuxer->audio->id == -2) {        tv_param_noaudio = 1;     }    /* set width */    funcs->control(tvh->priv, TVI_CONTROL_VID_GET_WIDTH, &sh_video->disp_w);    /* set height */    funcs->control(tvh->priv, TVI_CONTROL_VID_GET_HEIGHT, &sh_video->disp_h);    demuxer->video->sh = sh_video;    sh_video->ds = demuxer->video;    demuxer->video->id = 0;    demuxer->seekable = 0;    /* here comes audio init */    if (tv_param_noaudio == 0 && funcs->control(tvh->priv, TVI_CONTROL_IS_AUDIO, 0) == TVI_CONTROL_TRUE)    {	int audio_format;	int sh_audio_format;	char buf[128];	/* yeah, audio is present */	funcs->control(tvh->priv, TVI_CONTROL_AUD_SET_SAMPLERATE, 				  &tv_param_audiorate);	if (funcs->control(tvh->priv, TVI_CONTROL_AUD_GET_FORMAT, &audio_format) != TVI_CONTROL_TRUE)	    goto no_audio;	switch(audio_format)	{	    case AF_FORMAT_U8:	    case AF_FORMAT_S8:	    case AF_FORMAT_U16_LE:	    case AF_FORMAT_U16_BE:	    case AF_FORMAT_S16_LE:	    case AF_FORMAT_S16_BE:	    case AF_FORMAT_S32_LE:	    case AF_FORMAT_S32_BE:		sh_audio_format = 0x1; /* PCM */		break;	    case AF_FORMAT_IMA_ADPCM:	    case AF_FORMAT_MU_LAW:	    case AF_FORMAT_A_LAW:	    case AF_FORMAT_MPEG2:	    case AF_FORMAT_AC3:	    default:		mp_msg(MSGT_TV, MSGL_ERR, "Audio type '%s (%x)' unsupported!\n",		    af_fmt2str(audio_format, buf, 128), audio_format);		goto no_audio;	}		sh_audio = new_sh_audio(demuxer, 0);	funcs->control(tvh->priv, TVI_CONTROL_AUD_GET_SAMPLERATE,                    &sh_audio->samplerate);	funcs->control(tvh->priv, TVI_CONTROL_AUD_GET_SAMPLESIZE,                    &sh_audio->samplesize);	funcs->control(tvh->priv, TVI_CONTROL_AUD_GET_CHANNELS,                    &sh_audio->channels);	sh_audio->format = sh_audio_format;	sh_audio->sample_format = audio_format;	sh_audio->i_bps = sh_audio->o_bps =	    sh_audio->samplerate * sh_audio->samplesize * 	    sh_audio->channels;	// emulate WF for win32 codecs:	sh_audio->wf = (WAVEFORMATEX *)malloc(sizeof(WAVEFORMATEX));	sh_audio->wf->wFormatTag = sh_audio->format;	sh_audio->wf->nChannels = sh_audio->channels;	sh_audio->wf->wBitsPerSample = sh_audio->samplesize * 8;	sh_audio->wf->nSamplesPerSec = sh_audio->samplerate;	sh_audio->wf->nBlockAlign = sh_audio->samplesize * sh_audio->channels;	sh_audio->wf->nAvgBytesPerSec = sh_audio->i_bps;	mp_msg(MSGT_DECVIDEO, MSGL_V, "  TV audio: %d channels, %d bits, %d Hz\n",          sh_audio->wf->nChannels, sh_audio->wf->wBitsPerSample,          sh_audio->wf->nSamplesPerSec);	demuxer->audio->sh = sh_audio;	sh_audio->ds = demuxer->audio;	demuxer->audio->id = 0;    }no_audio:    if(!(funcs->start(tvh->priv))){	// start failed :(	tv_uninit(tvh);	return 0;    }    /* set color eq */    tv_set_color_options(tvh, TV_COLOR_BRIGHTNESS, tv_param_brightness);    tv_set_color_options(tvh, TV_COLOR_HUE, tv_param_hue);    tv_set_color_options(tvh, TV_COLOR_SATURATION, tv_param_saturation);    tv_set_color_options(tvh, TV_COLOR_CONTRAST, tv_param_contrast);    return 1;}int demux_close_tv(demuxer_t *demuxer){    tvi_handle_t *tvh=(tvi_handle_t*)(demuxer->priv);    return(tvh->functions->uninit(tvh->priv));}/* ================== STREAM_TV ===================== */tvi_handle_t *tvi_init_dummy(char *device);tvi_handle_t *tvi_init_v4l(char *device, char *adevice);tvi_handle_t *tvi_init_v4l2(char *device, char *adevice);tvi_handle_t *tvi_init_bsdbt848(char *device);tvi_handle_t *tv_begin(void){    if (!strcmp(tv_param_driver, "dummy"))	return tvi_init_dummy(tv_param_device);#ifdef HAVE_TV_V4L    if (!strcmp(tv_param_driver, "v4l"))	return tvi_init_v4l(tv_param_device, tv_param_adevice);#endif#ifdef HAVE_TV_V4L2    if (!strcmp(tv_param_driver, "v4l2"))	return tvi_init_v4l2(tv_param_device, tv_param_adevice);#endif#ifdef HAVE_TV_BSDBT848    if (!strcmp(tv_param_driver, "bsdbt848"))	return tvi_init_bsdbt848(tv_param_device);#endif    mp_msg(MSGT_TV, MSGL_ERR, "No such driver: %s\n", tv_param_driver);     return(NULL);}int tv_init(tvi_handle_t *tvh){    mp_msg(MSGT_TV, MSGL_INFO, "Selected driver: %s\n", tvh->info->short_name);    mp_msg(MSGT_TV, MSGL_INFO, " name: %s\n", tvh->info->name);    mp_msg(MSGT_TV, MSGL_INFO, " author: %s\n", tvh->info->author);    if (tvh->info->comment)	mp_msg(MSGT_TV, MSGL_INFO, " comment: %s\n", tvh->info->comment);    return(tvh->functions->init(tvh->priv));}int tv_uninit(tvi_handle_t *tvh){    return(tvh->functions->uninit(tvh->priv));}/* utilities for mplayer (not mencoder!!) */int tv_set_color_options(tvi_handle_t *tvh, int opt, int value){    tvi_functions_t *funcs = tvh->functions;    switch(opt)    {	case TV_COLOR_BRIGHTNESS:	    funcs->control(tvh->priv, TVI_CONTROL_VID_SET_BRIGHTNESS, &value);	    break;	case TV_COLOR_HUE:	    funcs->control(tvh->priv, TVI_CONTROL_VID_SET_HUE, &value);	    break;	case TV_COLOR_SATURATION:	    funcs->control(tvh->priv, TVI_CONTROL_VID_SET_SATURATION, &value);	    break;	case TV_COLOR_CONTRAST:	    funcs->control(tvh->priv, TVI_CONTROL_VID_SET_CONTRAST, &value);	    break;	default:	    mp_msg(MSGT_TV, MSGL_WARN, "Unknown color option (%d) specified!\n", opt);    }        return(1);}int tv_get_freq(tvi_handle_t *tvh, unsigned long *freq){    if (tvh->functions->control(tvh->priv, TVI_CONTROL_IS_TUNER, 0) == TVI_CONTROL_TRUE)    {	tvh->functions->control(tvh->priv, TVI_CONTROL_TUN_GET_FREQ, freq);	mp_msg(MSGT_TV, MSGL_V, "Current frequency: %lu (%.3f)\n",	    *freq, (float)*freq/16);    }    return(1);}int tv_set_freq(tvi_handle_t *tvh, unsigned long freq){    if (tvh->functions->control(tvh->priv, TVI_CONTROL_IS_TUNER, 0) == TVI_CONTROL_TRUE)    {//	unsigned long freq = atof(tv_param_freq)*16;        /* set freq in MHz */	tvh->functions->control(tvh->priv, TVI_CONTROL_TUN_SET_FREQ, &freq);	tvh->functions->control(tvh->priv, TVI_CONTROL_TUN_GET_FREQ, &freq);	mp_msg(MSGT_TV, MSGL_V, "Current frequency: %lu (%.3f)\n",	    freq, (float)freq/16);    }    return(1);}int tv_step_channel_real(tvi_handle_t *tvh, int direction){    struct CHANLIST cl;    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, "Selected channel: %s (freq: %.3f)\n",		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, "Selected channel: %s (freq: %.3f)\n",		cl.name, (float)cl.freq/1000);	    tv_set_freq(tvh, (unsigned long)(((float)cl.freq/1000)*16));	}	    }    return(1);}int tv_step_channel(tvi_handle_t *tvh, int direction) {	if (tv_channel_list) {		if (direction == TV_CHANNEL_HIGHER) {			if (tv_channel_current->next) {				tv_channel_last = tv_channel_current;				tv_channel_current = tv_channel_current->next;				tv_set_freq(tvh, (unsigned long)(((float)tv_channel_current->freq/1000)*16));				mp_msg(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);			}		}		if (direction == TV_CHANNEL_LOWER) {			if (tv_channel_current->prev) {				tv_channel_last = tv_channel_current;				tv_channel_current = tv_channel_current->prev;				tv_set_freq(tvh, (unsigned long)(((float)tv_channel_current->freq/1000)*16));				mp_msg(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);			}		}	} else tv_step_channel_real(tvh, direction);	return(1);}int tv_set_channel_real(tvi_handle_t *tvh, char *channel) {	int i;	struct CHANLIST cl;        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, "Selected channel: %s (freq: %.3f)\n",		    cl.name, (float)cl.freq/1000);		tv_set_freq(tvh, (unsigned long)(((float)cl.freq/1000)*16));		break;	    }	}	return(1);}int tv_set_channel(tvi_handle_t *tvh, char *channel) {	int i, channel_int;	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, "Selected channel: %s - %s (freq: %.3f)\n", 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);}int tv_last_channel(tvi_handle_t *tvh) {	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, "Selected channel: %s - %s (freq: %.3f)\n", 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 {		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, "Selected channel: %s (freq: %.3f)\n",			    cl.name, (float)cl.freq/1000);			tv_set_freq(tvh, (unsigned long)(((float)cl.freq/1000)*16));			break;		    }		}	}	return(1);}int tv_step_norm(tvi_handle_t *tvh){    return(1);}int tv_step_chanlist(tvi_handle_t *tvh){    return(1);}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", 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, "Error: Cannot set norm!\n");	return 0;    }    return(1);}#endif /* USE_TV */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -