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

📄 mpeg2ts1394dec.c

📁 从 IEEE 1394总线接收传输流
💻 C
字号:
/* * MPEG2-TS over IEEE 1394 decoder - receive and decode MPEG-2 transport *                                   streams according to IEC 61883-4 * * Copyright (C) 2000-2007, Manfred Weihs <mweihs@users.sourceforge.net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the 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 of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */#include <stdio.h>#include <string.h>#include <stdlib.h>#include "config.h"#include "iso1394dataflowsource.h"#include "mpeg2demux.h"#include "videobuffer.h" //for selecting video out driver#ifdef VIDEO_FIX_WINDOWextern int init_video_out_tv();extern void done_video_out_tv();extern int resize_tv_window(unsigned int width, unsigned int height);#endif#define INPUT_STRING_LENGTH 500int debug=0;static int done=0;static int demuxing=0;static int print_help(){	if (strtok(NULL," \n")) {		fprintf(stdout,"too many arguments\n");		return 1;	}	fprintf(stdout,"available commands:\n");	fprintf(stdout,"help               print this help\n");	fprintf(stdout,"exit               exit program\n");	fprintf(stdout,"listen ch          listen to isochronous channel ch\n");	fprintf(stdout,"unlisten           stop listening to isochronous data\n");	fprintf(stdout,"print pat          print program association table\n");	fprintf(stdout,"print pmt          print program map table\n");	fprintf(stdout,"print pids         print pid table\n");	fprintf(stdout,"status             print status of buffers\n");	fprintf(stdout,"decode pn          decode program pn\n");	fprintf(stdout,"decode any         decode any program\n");	fprintf(stdout,"decode first       decode first program\n");	fprintf(stdout,"decode v a p       decode program with video, audio and pcr pid\n");#ifdef VIDEO_FIX_WINDOW	fprintf(stdout,"resize w h         resize TV window to width w and height h\n");	fprintf(stdout,"resize pal         resize TV window to PAL resolution (default)\n");	fprintf(stdout,"resize ntsc        resize TV window to NTSC resolution\n");#endif	fprintf(stdout,"drivers            print a list of available video out drivers\n");	fprintf(stdout,"driver dn          select video out driver dn\n");	fprintf(stdout,"debug              output debugging information\n");	fprintf(stdout,"nodebug            do not output debug information\n");	fprintf(stdout,"version            print version information\n");	return 0;}static int exit_program(){	if (strtok(NULL," \n")) {		fprintf(stdout,"too many arguments\n");		return 1;	}	fprintf(stdout,"exiting program\n");	if (demuxing) {		mpeg2demux_done();		iso_done();	}	done=1;	return 0;}static int listen(){	char *token, *endptr;	unsigned long int channel;	token = strtok(NULL, " \n");	if (!token) {		fprintf(stdout,"insufficient arguments! specify channel!\n");		return 1;	}	channel = strtoul(token, &endptr , 0);	if ((channel > 63) || (*endptr)) {		fprintf(stdout,"invalid channel specified\n");		return 1;	}	if (strtok(NULL," \n")) {		fprintf(stdout,"too many arguments\n");		return 1;	}	 	if (demuxing) {		fprintf(stdout,"we are already listening. issue unlisten before!\n");		return 1;	}	if (iso_init(channel)) {		fprintf(stdout,"cannot start IEEE 1394 subsystem\n");		return 1;	}	if (mpeg2demux_init()) {		fprintf(stdout,"cannot init mpeg demux\n");		iso_done();		return 1;	}	demuxing=1;	return 0;}static int unlisten(){	if (strtok(NULL," \n")) {		fprintf(stdout,"too many arguments\n");		return 1;	}	if (!demuxing) {		fprintf(stdout,"we are not listening.\n");		return 1;	}	mpeg2demux_done();	iso_done();	demuxing=0;	return 0;}#ifdef VIDEO_FIX_WINDOWstatic int resize(){	char *token, *endptr;	long int n1, n2;	token = strtok(NULL, " \n");	if (!token) {		fprintf(stdout,"insufficient arguments!\n");		return 1;	}	if (!strcmp(token,"pal")) {		if (strtok(NULL," \n")) {			fprintf(stdout,"too many arguments\n");			return 1;		}		return resize_tv_window(720, 576);	}	if (!strcmp(token,"ntsc")) {		if (strtok(NULL," \n")) {			fprintf(stdout,"too many arguments\n");			return 1;		}		return resize_tv_window(720, 480);	}	n1 = strtol(token, &endptr , 0);	if (*endptr) {		fprintf(stdout,"invalid width\n");		return 1;	}	token = strtok(NULL, " \n");	if (!token) {		fprintf(stdout,"too little arguments\n");		return 1;	}	n2 = strtol(token, &endptr , 0);	if (*endptr) {		fprintf(stdout,"invalid height\n");		return 1;	}	if (strtok(NULL," \n")) {		fprintf(stdout,"too many arguments\n");		return 1;	}	 	return resize_tv_window(n1, n2);}#endifstatic int decode(){	char *token, *endptr;	long int n1, n2, n3;	token = strtok(NULL, " \n");	if (!token) {		fprintf(stdout,"insufficient arguments!\n");		return 1;	}	if (!demuxing) {		fprintf(stdout,"we are not listening, therefore we cannot decode.\n");		return 1;	}	if (!strcmp(token,"any")) {		if (strtok(NULL," \n")) {			fprintf(stdout,"too many arguments\n");			return 1;		}		return select_any_program();	}	if (!strcmp(token,"first")) {		if (strtok(NULL," \n")) {			fprintf(stdout,"too many arguments\n");			return 1;		}		return select_first_program();	}	if (!strcmp(token,"stop")) {		if (strtok(NULL," \n")) {			fprintf(stdout,"too many arguments\n");			return 1;		}		set_pids(-1, -1, -1);		return 0;	}	n1 = strtol(token, &endptr , 0);	if (*endptr) {		fprintf(stdout,"invalid number/video pid\n");		return 1;	}	token = strtok(NULL, " \n");	if (!token) {		return select_program(n1);	}	n2 = strtol(token, &endptr , 0);	if (*endptr) {		fprintf(stdout,"invalid audio pid\n");		return 1;	}	token = strtok(NULL, " \n");	if (!token) {		fprintf(stdout,"insufficient arguments, pcr pid missing!\n");		return 1;	}	n3 = strtol(token, &endptr , 0);	if (*endptr) {		fprintf(stdout,"invalid pcr pid\n");		return 1;	}	if (strtok(NULL," \n")) {		fprintf(stdout,"too many arguments\n");		return 1;	}	 	set_pids(n1, n2, n3);	return 0;}static int print(){	char *token;	token = strtok(NULL, " \n");	if (!token) {		fprintf(stdout,"insufficient arguments!\n");		return 1;	}	if (!demuxing) {		fprintf(stdout,"we are not listening, therefore we cannot print info about the stream.\n");		return 1;	}	if (!strcmp(token,"pmt")) {		if (strtok(NULL," \n")) {			fprintf(stdout,"too many arguments\n");			return 1;		}		printPMT(stdout);		return 0;	}	if (!strcmp(token,"pat")) {		if (strtok(NULL," \n")) {			fprintf(stdout,"too many arguments\n");			return 1;		}		printPAT(stdout);		return 0;	}	if (!strcmp(token,"pids")) {		if (strtok(NULL," \n")) {			fprintf(stdout,"too many arguments\n");			return 1;		}		printPidTable(stdout);		return 0;	}	fprintf(stdout,"illegal arument\n");	return 1;}static int set_debug(int i){	if (strtok(NULL," \n")) {		fprintf(stdout,"too many arguments\n");		return 1;	}	debug=i;	return 0;}static int status(){	if (strtok(NULL," \n")) {		fprintf(stdout,"too many arguments\n");		return 1;	}	if (demuxing) {		int size, state;		int vpid, apid, pcrpid;		size=get_videobuffer_size();		state=get_videobuffer_state();		fprintf(stdout,"video buffer size: %d, state: %d, filled %f%%\n", size, state, (double) (state*100)/size);		size=get_audiobuffer_size();		state=get_audiobuffer_state();		fprintf(stdout,"audio buffer size: %d, state: %d, filled %f%%\n", size, state, (double) (state*100)/size);		get_pids(&vpid, &apid, &pcrpid);		fprintf(stdout,"decoding video pid %d (0x%x), audio pid %d (0x%x), pcr_pid %d (0x%x)\n", vpid, vpid, apid, apid, pcrpid, pcrpid);	} else {		fprintf(stdout,"not listening to isochronous data\n");	}	return 0;}static int select_video_out_driver(){	char *token;	token = strtok(NULL, "\n");	if (!token) {		fprintf(stdout,"insufficient arguments! specify driver name!\n");		return 1;	}	if (demuxing) {		fprintf(stdout,"we are already listening. issue unlisten before!\n");		return 1;	}	set_vo_driver(token);		return 0;}static int print_video_out_drivers(){	print_vo_drivers();	return 0;}static int print_version(){	fprintf(stdout, "%s %s\n", PACKAGE, VERSION);	return 0;}static int parse_command(char *input){	char *token;	token = strtok(input, " \n");	if (!token)		return 0;	if (!strcmp(token,"help"))		return print_help();	if (!strcmp(token,"exit"))		return exit_program();	if (!strcmp(token,"listen"))		return listen();	if (!strcmp(token,"unlisten"))		return unlisten();	if (!strcmp(token,"decode"))		return decode();#ifdef VIDEO_FIX_WINDOW	if (!strcmp(token,"resize"))		return resize();#endif		if (!strcmp(token,"print"))		return print();	if (!strcmp(token,"driver"))		return select_video_out_driver();	if (!strcmp(token,"drivers"))		return print_video_out_drivers();	if (!strcmp(token,"debug"))		return set_debug(1);	if (!strcmp(token,"nodebug"))		return set_debug(0);	if (!strcmp(token,"status"))		return status();	if (!strcmp(token,"version"))		return print_version();	fprintf(stdout,"illegal command\n");	return 1;}int main(int argc, char **argv){	char input[INPUT_STRING_LENGTH];	(void) print_version();	fprintf(stdout,"MPEG-2 transport stream over IEEE 1394 decoder\n");	fprintf(stdout,"Copyright (C) 2000-2007 by Manfred Weihs <mweihs@users.sourceforge.net>\n");	fprintf(stdout,"This software comes with absolutely no warranty.\n");	fprintf(stdout,"\nType 'help' for more information\n\n");	fflush(stdout);#ifdef VIDEO_FIX_WINDOW	if (init_video_out_tv()) {		fprintf(stderr,"cannot initialize TV window\n");		return 1;	}#endif	while (!done) {		if (fgets(input, INPUT_STRING_LENGTH, stdin)) {			if (parse_command(input)) {				fprintf(stdout,"ERR.\n");			} else {				fprintf(stdout,"OK.\n");			}			fflush(stdout);		} else {			fprintf(stdout,"reached EOF -> exit\n");			done = 1;		}	}#ifdef VIDEO_FIX_WINDOW	done_video_out_tv();#endif		return 0;}

⌨️ 快捷键说明

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