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

📄 dawnlightplayer.c

📁 DawnLightPlayer,一个新的基于ffmpeg的全功能播放器
💻 C
字号:
/********************************************************* * Dawn Light Player * * A very sample player for h264 and aac * writed by maddrone and kf701. * * DawnLightPlayer.c * * Created by maddrone and kf701 * Mon Feb 25 17:05:41 CST 2008 * * $Id: DawnLightPlayer.c 174 2008-03-22 06:30:04Z kf701 $ *********************************************************/#include "avcodec.h"#include "avformat.h"#include "swscale.h"#include "cmdutils.h"#include "avinput.h"#include "avoutput.h"#include "avdecode.h"#include "global.h"DLPContext dlpctx, *dlpctxp = &dlpctx;loop_func dlp_main_loop = NULL;/* function for parse options */static void opt_show_help(void);static void opt_sr(const char *arg);static void opt_width(const char *arg);static void opt_height(const char *arg);static void opt_pwidth(const char *arg);static void opt_pheight(const char *arg);static void opt_avin(const char *arg);static void opt_vo(const char *arg);static void opt_ao(const char *arg);static void opt_fps(const char *arg);static void opt_debug(void);const OptionDef options[] ={	{ "h", 0, {(void*)opt_show_help}, "show help" },	{ "debug", 0, {(void*)opt_debug}, "print specific debug info", "" },	{ "width", HAS_ARG, {(void*)opt_width}, "video orig width", "width" },	{ "height", HAS_ARG, {(void*)opt_height}, "video orig height", "height" },	{ "pw", HAS_ARG, {(void*)opt_pwidth}, "fix vo width", "width" },	{ "ph", HAS_ARG, {(void*)opt_pheight}, "fix vo height", "height" },	{ "sr", HAS_ARG, {(void*)opt_sr}, "audio sample rate", "sample rate" },	{ "in", HAS_ARG, {(void*)opt_avin}, "av input(file, ha1, ha2)", "avin" },	{ "vo", HAS_ARG, {(void*)opt_vo}, "vo dev(sdl, x11, fb, gl, directx)", "dev" },	{ "ao", HAS_ARG, {(void*)opt_ao}, "ao dev(oss, alsa, sdl, dsound)", "dev" },	{ "fps", HAS_ARG, {(void*)opt_fps}, "vo fps", "fps" },	{ "fs", OPT_BOOL, {(void*)&dlpctx.fs}, "force full screen" },	{ NULL, },};static void opt_show_help(void){	show_help_options(options, "DawnLightPlayer options:\n", OPT_EXPERT, 0);	show_ui_key();	exit(0);}static void opt_sr(const char *arg){	dlpctx.sample_rate = atoi(arg);}static void opt_width(const char *arg){	dlpctx.width = atoi(arg);}static void opt_height(const char *arg){	dlpctx.height = atoi(arg);}static void opt_pwidth(const char *arg){	dlpctx.pwidth = atoi(arg);}static void opt_pheight(const char *arg){	dlpctx.pheight = atoi(arg);}static void opt_avin(const char *arg){	dlpctx.avin = (char*)arg;}static void opt_ao(const char *arg){	dlpctx.ao = (char*)arg;}static void opt_vo(const char *arg){	dlpctx.vo = (char*)arg;}static void opt_fps(const char *arg){	dlpctx.fps = atoi(arg);}static void opt_debug(void){	av_log_set_level(99);}static void opt_input_file(const char *filename){	dlpctx.filename = (char*)filename;}#if defined(__MINGW32__)static void enable_term_key(void) {}static void disable_term_key(void){}#else#include <termios.h>static struct termios tio_orig;static int term_key_enabled = 0;static void enable_term_key(void){	struct termios tio_new;	tcgetattr(0,&tio_orig);	tio_new=tio_orig;	tio_new.c_lflag &= ~(ICANON|ECHO);	tio_new.c_cc[VMIN] = 1;	tio_new.c_cc[VTIME] = 0;	tcsetattr(0,TCSANOW,&tio_new);	term_key_enabled = 1;}static void disable_term_key(void){	if ( term_key_enabled )	{		tcsetattr(0,TCSANOW,&tio_orig);		term_key_enabled = 0;	}}#endifstatic void default_main_loop(void){	char buf[16];	int len;	while (1)	{		len = read(0, buf, 16);		if ( 1 == len )		{			switch (buf[0])			{			case 'q':			case 27: /* esc */				dlp_exit(-2);			case '9':				dlp_sub_volume();				break;			case '0':				dlp_add_volume();				break;			case 'p':			case 32: /* space */				dlp_pause_play();				break;			case 'h':				show_ui_key();				break;			case 's':				dlp_screen_shot();				break;			}		}		else if ( len > 1 )		{			/* <- , -> , pgup , pgdown */			if ( 0x1b == buf[0] && 0x5b == buf[1] && 0x44 == buf[2] )				dlp_seek(-10);			if ( 0x1b == buf[0] && 0x5b == buf[1] && 0x43 == buf[2] )				dlp_seek(10);			if ( 0x1b == buf[0] && 0x5b == buf[1] && 0x35 == buf[2] )				dlp_seek(-60);			if ( 0x1b == buf[0] && 0x5b == buf[1] && 0x36 == buf[2] )				dlp_seek(60);		}	}}static void init_signal(void){	signal(SIGTERM,dlp_exit);	signal(SIGINT,dlp_exit);	signal(SIGSEGV,dlp_exit);	signal(SIGILL,dlp_exit);	signal(SIGFPE,dlp_exit);	signal(SIGABRT,dlp_exit);#if !defined(__MINGW32__)	signal(SIGHUP,dlp_exit);	signal(SIGBUS,dlp_exit);	signal(SIGQUIT,dlp_exit);	signal(SIGTRAP,dlp_exit);#endif}static void dlpctx_init_first(void){	/* set default avin, vo, ao */	if ( NULL == dlpctxp->avin )		dlpctxp->avin = "file";	if ( NULL == dlpctxp->vo )#if !defined(__MINGW32__)		dlpctxp->vo	= "x11";#else		dlpctxp->vo	= "sdl";#endif	if ( NULL == dlpctxp->ao )#if !defined(__MINGW32__)		dlpctxp->ao	= "oss";#else		dlpctxp->ao	= "dsound";#endif	dlpctxp->last_audio_pts = -1;	dlpctxp->paused = 0;	/* output picture format is YUV420P */	dlpctxp->pixfmt = PIX_FMT_YUV420P;}static void dlpctx_reinit(void){	/* reinit dlpavctx here, some field find out from input already*/	if ( dlp_vctxp )	{		if ( 0 == dlpctxp->width )			dlpctxp->width = dlp_vctxp->width;		if ( 0 == dlpctxp->height )			dlpctxp->height = dlp_vctxp->height;		if ( 0 == dlpctxp->pwidth )			dlpctxp->pwidth = dlp_vctxp->width;		if ( 0 == dlpctxp->pheight )			dlpctxp->pheight = dlp_vctxp->height;		av_log(NULL, AV_LOG_INFO, "size: %dx%d, vo: %dx%d, fps: %5.2f, vfmt: %d\n",		       dlpctxp->width, dlpctxp->height,		       dlpctxp->width, dlpctxp->height,		       dlpctxp->fps, dlpctxp->pixfmt);	}	if ( dlp_actxp )	{		if ( 0 == dlpctxp->sample_rate )			dlpctxp->sample_rate = dlp_actxp->sample_rate;		if ( 0 == dlpctxp->channels )			dlpctxp->channels = dlp_actxp->channels;		if ( 0 == dlpctxp->bit_rate )			dlpctxp->bit_rate = dlp_actxp->bit_rate;		if ( 0 == dlpctxp->sample_fmt )			dlpctxp->sample_fmt = dlp_actxp->sample_fmt;		av_log(NULL, AV_LOG_INFO, "afmt: %d, sr: %d, br: %d\n",		       dlpctxp->sample_fmt, dlpctxp->sample_rate, dlpctxp->bit_rate);	}}static void dlpctx_init_default(void){	if ( 0 == dlpctxp->width )		dlpctxp->width = 320;	if ( 0 == dlpctxp->height )		dlpctxp->height = 240;	if ( 0 == dlpctxp->pwidth )		dlpctxp->pwidth = 320;	if ( 0 == dlpctxp->pheight )		dlpctxp->pheight = 240;}int main(int argc, char **argv){	av_register_all();	show_banner();	parse_options(argc, argv, options, opt_input_file);	init_signal();	dlpctx_init_first();	av_input_init();	dlpctx_reinit();	av_decode_init();	dlpctx_init_default();	av_output_init();	create_avinput_thread(NULL);	create_avoutput_thread(NULL);	create_avdecode_thread(NULL);	enable_term_key();	if ( dlp_main_loop )		dlp_main_loop();	else		default_main_loop();	return 0;}void dlp_exit( int s ){	dlpctxp->exiting = 1;	disable_term_key();	switch (s)	{	case -1:		av_log(NULL, AV_LOG_INFO, "%s,%d: Terminal by Normal Error\n", __func__, s);		break;	case -2:		av_log(NULL, AV_LOG_INFO, "%s,%d: Terminal by User\n", __func__, s);		break;	default:		av_log(NULL, AV_LOG_INFO, "%s,%d: Terminal by Signal Error\n", __func__, s);		break;	}	usleep(500*1000); /* wait threads exit */	exit(0);}

⌨️ 快捷键说明

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