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

📄 stream_dvb.c

📁 君正早期ucos系统(只有早期的才不没有打包成库),MPLAYER,文件系统,图片解码,浏览,电子书,录音,想学ucos,识货的人就下吧 russblock fmradio explore set
💻 C
📖 第 1 页 / 共 2 页
字号:
/*dvbstream(C) Dave Chapman <dave@dchapman.com> 2001, 2002.The latest version can be found at http://www.linuxstb.org/dvbstreamModified for use with MPlayer, for details see the changelog athttp://svn.mplayerhq.hu/mplayer/trunk/$Id: stream_dvb.c,v 1.3 2008/04/12 07:14:45 dsqiu Exp $Copyright notice:This program is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2 of the License, or(at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA*/#include "config.h"#include <mplaylib.h>#include <mplaylib.h>#include <mplaylib.h>#include <errno.h>#include <mplaylib.h>#include "stream.h"#include "libmpdemux/demuxer.h"#include "help_mp.h"#include "m_option.h"#include "m_struct.h"#include "get_path.h"#include "libavutil/avstring.h"#include "dvbin.h"#undef memcpy#define memcpy uc_memcpy#define MAX_CHANNELS 8#define CHANNEL_LINE_LEN 256#define min(a, b) ((a) <= (b) ? (a) : (b))//TODO: CAMBIARE list_ptr e da globale a per_privstatic struct stream_priv_s{	char *prog;	int card;	char *type;	int vid, aid;	int timeout;	char *file;}stream_defaults ={	"", 1, "", 0, 0, 30, NULL};#define ST_OFF(f) M_ST_OFF(struct stream_priv_s, f)/// URL definitionstatic m_option_t stream_params[] = {	{"prog", ST_OFF(prog), CONF_TYPE_STRING, 0, 0 ,0, NULL},	{"card", ST_OFF(card), CONF_TYPE_INT, M_OPT_RANGE, 1, 4, NULL},	{"type", ST_OFF(type), CONF_TYPE_STRING, 0, 0 ,0, NULL},	{"vid",  ST_OFF(vid),  CONF_TYPE_INT, 0, 0 ,0, NULL},	{"aid",  ST_OFF(aid),  CONF_TYPE_INT, 0, 0 ,0, NULL},	{"timeout",ST_OFF(timeout),  CONF_TYPE_INT, M_OPT_RANGE, 1, 30, NULL},	{"file", ST_OFF(file), CONF_TYPE_STRING, 0, 0 ,0, NULL},	{"hostname", 	ST_OFF(prog), CONF_TYPE_STRING, 0, 0, 0, NULL },	{"username", 	ST_OFF(card), CONF_TYPE_INT, M_OPT_RANGE, 1, 4, NULL},	{NULL, NULL, 0, 0, 0, 0, NULL}};static struct m_struct_st stream_opts = {	"dvbin",	sizeof(struct stream_priv_s),	&stream_defaults,	stream_params};m_option_t dvbin_opts_conf[] = {	{"prog", &stream_defaults.prog, CONF_TYPE_STRING, 0, 0 ,0, NULL},	{"card", &stream_defaults.card, CONF_TYPE_INT, M_OPT_RANGE, 1, 4, NULL},	{"type", "DVB card type is autodetected and can't be overridden\n", CONF_TYPE_PRINT, CONF_NOCFG, 0 ,0, NULL},	{"vid",  &stream_defaults.vid,  CONF_TYPE_INT, 0, 0 ,0, NULL},	{"aid",  &stream_defaults.aid,  CONF_TYPE_INT, 0, 0 ,0, NULL},	{"timeout",  &stream_defaults.timeout,  CONF_TYPE_INT, M_OPT_RANGE, 1, 30, NULL},	{"file", &stream_defaults.file, CONF_TYPE_STRING, 0, 0 ,0, NULL},	{NULL, NULL, 0, 0, 0, 0, NULL}};extern int dvb_set_ts_filt(int fd, uint16_t pid, dmx_pes_type_t pestype);extern int dvb_demux_stop(int fd);extern int dvb_get_tuner_type(int fd);int dvb_open_devices(dvb_priv_t *priv, int n, int demux_cnt, int *pids);int dvb_fix_demuxes(dvb_priv_t *priv, int cnt, int *pids);extern int dvb_tune(dvb_priv_t *priv, int freq, char pol, int srate, int diseqc, int tone,		fe_spectral_inversion_t specInv, fe_modulation_t modulation, fe_guard_interval_t guardInterval,		fe_transmit_mode_t TransmissionMode, fe_bandwidth_t bandWidth, fe_code_rate_t HP_CodeRate,		fe_code_rate_t LP_CodeRate, fe_hierarchy_t hier, int timeout);extern char *dvb_dvrdev[4], *dvb_demuxdev[4], *dvb_frontenddev[4];static dvb_config_t *dvb_config = NULL;static dvb_channels_list *dvb_get_channels(char *filename, int type){	dvb_channels_list  *list;	FILE *f;	char line[CHANNEL_LINE_LEN], *colon;	int fields, cnt, pcnt, k;	int has8192, has0;	dvb_channel_t *ptr, *tmp, chn;	char tmp_lcr[256], tmp_hier[256], inv[256], bw[256], cr[256], mod[256], transm[256], gi[256], vpid_str[256], apid_str[256];	const char *cbl_conf = "%d:%255[^:]:%d:%255[^:]:%255[^:]:%255[^:]:%255[^:]\n";	const char *sat_conf = "%d:%c:%d:%d:%255[^:]:%255[^:]\n";	const char *ter_conf = "%d:%255[^:]:%255[^:]:%255[^:]:%255[^:]:%255[^:]:%255[^:]:%255[^:]:%255[^:]:%255[^:]:%255[^:]\n";	const char *atsc_conf = "%d:%255[^:]:%255[^:]:%255[^:]\n";		mp_msg(MSGT_DEMUX, MSGL_V, "CONFIG_READ FILE: %s, type: %d\n", filename, type);	if((f=fopen(filename, "r"))==NULL)	{		mp_msg(MSGT_DEMUX, MSGL_FATAL, "CAN'T READ CONFIG FILE %s\n", filename);		return NULL;	}	list = malloc(sizeof(dvb_channels_list));	if(list == NULL)	{		fclose(f);		mp_msg(MSGT_DEMUX, MSGL_V, "DVB_GET_CHANNELS: couldn't malloc enough memory\n");		return NULL;	}	ptr = &chn;	list->NUM_CHANNELS = 0;	list->channels = NULL;	while(! feof(f))	{		if( fgets(line, CHANNEL_LINE_LEN, f) == NULL )			continue;		if((line[0] == '#') || (strlen(line) == 0))			continue;		colon = strchr(line, ':');		if(colon)		{			k = colon - line;			if(!k)				continue;			ptr->name = malloc(k+1);			if(! ptr->name)				continue;			av_strlcpy(ptr->name, line, k+1);		}		else			continue;		k++;		apid_str[0] = vpid_str[0] = 0;		ptr->pids_cnt = 0;		ptr->freq = 0;		if(type == TUNER_TER)		{			fields = sscanf(&line[k], ter_conf,				&ptr->freq, inv, bw, cr, tmp_lcr, mod,				transm, gi, tmp_hier, vpid_str, apid_str);			mp_msg(MSGT_DEMUX, MSGL_V,				"TER, NUM: %d, NUM_FIELDS: %d, NAME: %s, FREQ: %d",				list->NUM_CHANNELS, fields, ptr->name, ptr->freq);		}		else if(type == TUNER_CBL)		{			fields = sscanf(&line[k], cbl_conf,				&ptr->freq, inv, &ptr->srate,				cr, mod, vpid_str, apid_str);			mp_msg(MSGT_DEMUX, MSGL_V,				"CBL, NUM: %d, NUM_FIELDS: %d, NAME: %s, FREQ: %d, SRATE: %d",				list->NUM_CHANNELS, fields, ptr->name, ptr->freq, ptr->srate);		}#ifdef DVB_ATSC		else if(type == TUNER_ATSC)		{			fields = sscanf(&line[k], atsc_conf,				 &ptr->freq, mod, vpid_str, apid_str);			mp_msg(MSGT_DEMUX, MSGL_V,				"ATSC, NUM: %d, NUM_FIELDS: %d, NAME: %s, FREQ: %d\n",				list->NUM_CHANNELS, fields, ptr->name, ptr->freq);		}#endif		else //SATELLITE		{			fields = sscanf(&line[k], sat_conf,				&ptr->freq, &ptr->pol, &ptr->diseqc, &ptr->srate, vpid_str, apid_str);			ptr->pol = toupper(ptr->pol);			ptr->freq *=  1000UL;			ptr->srate *=  1000UL;			ptr->tone = -1;			ptr->inv = INVERSION_AUTO;			ptr->cr = FEC_AUTO;			if((ptr->diseqc > 4) || (ptr->diseqc < 0))			    continue;			if(ptr->diseqc > 0)			    ptr->diseqc--;			mp_msg(MSGT_DEMUX, MSGL_V,				"SAT, NUM: %d, NUM_FIELDS: %d, NAME: %s, FREQ: %d, SRATE: %d, POL: %c, DISEQC: %d",				list->NUM_CHANNELS, fields, ptr->name, ptr->freq, ptr->srate, ptr->pol, ptr->diseqc);		}		if(vpid_str[0])		{			pcnt = sscanf(vpid_str, "%d+%d+%d+%d+%d+%d+%d", &ptr->pids[0], &ptr->pids[1], &ptr->pids[2], &ptr->pids[3],				&ptr->pids[4], &ptr->pids[5], &ptr->pids[6]);			if(pcnt > 0)			{				ptr->pids_cnt = pcnt;				fields++;			}		}				if(apid_str[0])		{			cnt = ptr->pids_cnt;			pcnt = sscanf(apid_str, "%d+%d+%d+%d+%d+%d+%d+%d", &ptr->pids[cnt], &ptr->pids[cnt+1], &ptr->pids[cnt+2],				&ptr->pids[cnt+3], &ptr->pids[cnt+4], &ptr->pids[cnt+5], &ptr->pids[cnt+6], &ptr->pids[cnt+7]);			if(pcnt > 0)			{				ptr->pids_cnt += pcnt;				fields++;			}		}		if((fields < 2) || (ptr->pids_cnt <= 0) || (ptr->freq == 0) || (strlen(ptr->name) == 0))			continue;		has8192 = has0 = 0;		for(cnt = 0; cnt < ptr->pids_cnt; cnt++)		{			if(ptr->pids[cnt] == 8192)				has8192 = 1;			if(ptr->pids[cnt] == 0)				has0 = 1;		}		if(has8192)		{			ptr->pids[0] = 8192;			ptr->pids_cnt = 1;		}		else if(! has0)		{			ptr->pids[ptr->pids_cnt] = 0;	//PID 0 is the PAT			ptr->pids_cnt++;		}		mp_msg(MSGT_DEMUX, MSGL_V, " PIDS: ");		for(cnt = 0; cnt < ptr->pids_cnt; cnt++)			mp_msg(MSGT_DEMUX, MSGL_V, " %d ", ptr->pids[cnt]);		mp_msg(MSGT_DEMUX, MSGL_V, "\n");				if((type == TUNER_TER) || (type == TUNER_CBL))		{			if(! strcmp(inv, "INVERSION_ON"))				ptr->inv = INVERSION_ON;			else if(! strcmp(inv, "INVERSION_OFF"))				ptr->inv = INVERSION_OFF;			else				ptr->inv = INVERSION_AUTO;			if(! strcmp(cr, "FEC_1_2"))				ptr->cr =FEC_1_2;			else if(! strcmp(cr, "FEC_2_3"))				ptr->cr =FEC_2_3;			else if(! strcmp(cr, "FEC_3_4"))				ptr->cr =FEC_3_4;#ifdef HAVE_DVB_HEAD			else if(! strcmp(cr, "FEC_4_5"))				ptr->cr =FEC_4_5;			else if(! strcmp(cr, "FEC_6_7"))				ptr->cr =FEC_6_7;			else if(! strcmp(cr, "FEC_8_9"))				ptr->cr =FEC_8_9;#endif			else if(! strcmp(cr, "FEC_5_6"))				ptr->cr =FEC_5_6;			else if(! strcmp(cr, "FEC_7_8"))				ptr->cr =FEC_7_8;			else if(! strcmp(cr, "FEC_NONE"))				ptr->cr =FEC_NONE;			else ptr->cr =FEC_AUTO;		}			if((type == TUNER_TER) || (type == TUNER_CBL) || (type == TUNER_ATSC))		{			if(! strcmp(mod, "QAM_128"))				ptr->mod = QAM_128;			else if(! strcmp(mod, "QAM_256"))				ptr->mod = QAM_256;			else if(! strcmp(mod, "QAM_64"))				ptr->mod = QAM_64;			else if(! strcmp(mod, "QAM_32"))				ptr->mod = QAM_32;			else if(! strcmp(mod, "QAM_16"))				ptr->mod = QAM_16;#ifdef DVB_ATSC				else if(! strcmp(mod, "VSB_8") || ! strcmp(mod, "8VSB"))				ptr->mod = VSB_8;			else if(! strcmp(mod, "VSB_16") || !strcmp(mod, "16VSB"))				ptr->mod = VSB_16;			ptr->inv = INVERSION_AUTO;#endif		}		if(type == TUNER_TER)		{			if(! strcmp(bw, "BANDWIDTH_6_MHZ"))				ptr->bw = BANDWIDTH_6_MHZ;			else if(! strcmp(bw, "BANDWIDTH_7_MHZ"))				ptr->bw = BANDWIDTH_7_MHZ;			else if(! strcmp(bw, "BANDWIDTH_8_MHZ"))				ptr->bw = BANDWIDTH_8_MHZ;			if(! strcmp(transm, "TRANSMISSION_MODE_2K"))				ptr->trans = TRANSMISSION_MODE_2K;			else if(! strcmp(transm, "TRANSMISSION_MODE_8K"))				ptr->trans = TRANSMISSION_MODE_8K;			if(! strcmp(gi, "GUARD_INTERVAL_1_32"))				ptr->gi = GUARD_INTERVAL_1_32;			else if(! strcmp(gi, "GUARD_INTERVAL_1_16"))				ptr->gi = GUARD_INTERVAL_1_16;			else if(! strcmp(gi, "GUARD_INTERVAL_1_8"))				ptr->gi = GUARD_INTERVAL_1_8;			else ptr->gi = GUARD_INTERVAL_1_4;						if(! strcmp(tmp_lcr, "FEC_1_2"))				ptr->cr_lp =FEC_1_2;			else if(! strcmp(tmp_lcr, "FEC_2_3"))				ptr->cr_lp =FEC_2_3;			else if(! strcmp(tmp_lcr, "FEC_3_4"))				ptr->cr_lp =FEC_3_4;#ifdef HAVE_DVB_HEAD			else if(! strcmp(tmp_lcr, "FEC_4_5"))				ptr->cr_lp =FEC_4_5;			else if(! strcmp(tmp_lcr, "FEC_6_7"))				ptr->cr_lp =FEC_6_7;			else if(! strcmp(tmp_lcr, "FEC_8_9"))				ptr->cr_lp =FEC_8_9;#endif			else if(! strcmp(tmp_lcr, "FEC_5_6"))				ptr->cr_lp =FEC_5_6;			else if(! strcmp(tmp_lcr, "FEC_7_8"))				ptr->cr_lp =FEC_7_8;			else if(! strcmp(tmp_lcr, "FEC_NONE"))				ptr->cr_lp =FEC_NONE;			else ptr->cr_lp =FEC_AUTO;									if(! strcmp(tmp_hier, "HIERARCHY_1"))				ptr->hier = HIERARCHY_1;			else if(! strcmp(tmp_hier, "HIERARCHY_2"))				ptr->hier = HIERARCHY_2;			else if(! strcmp(tmp_hier, "HIERARCHY_4"))				ptr->hier = HIERARCHY_4;#ifdef HAVE_DVB_HEAD							else if(! strcmp(tmp_hier, "HIERARCHY_AUTO"))				ptr->hier = HIERARCHY_AUTO;#endif			else	ptr->hier = HIERARCHY_NONE;		}		tmp = realloc(list->channels, sizeof(dvb_channel_t) * (list->NUM_CHANNELS + 1));		if(tmp == NULL)			break;		list->channels = tmp;		memcpy(&(list->channels[list->NUM_CHANNELS]), ptr, sizeof(dvb_channel_t));		list->NUM_CHANNELS++;		if(sizeof(dvb_channel_t) * list->NUM_CHANNELS >= 1024*1024)		{			mp_msg(MSGT_DEMUX, MSGL_V, "dvbin.c, > 1MB allocated for channels struct, dropping the rest of the file\r\n");			break;		}	}	fclose(f);	if(list->NUM_CHANNELS == 0)	{		if(list->channels != NULL)			free(list->channels);		free(list);		return NULL;	}	list->current = 0;	return list;}

⌨️ 快捷键说明

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