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

📄 mplayer.c

📁 自己移植的linux下的流媒体播放器原代码,支持mms协议,支持ftp和http协议.
💻 C
📖 第 1 页 / 共 4 页
字号:
/*============================================== 1. can play video files' audio, but can't display video===============================================*/#include <stdio.h>#include <stdlib.h>#include <stdarg.h>#include "config.h"#define NO_VIDEO 1#ifdef WIN32#define _UWIN 1  /*disable Non-underscored versions of non-ANSI functions as otherwise int eof would conflict with eof()*/#include <windows.h>#endif#include <string.h>#include <unistd.h>// #include <sys/mman.h>#include <sys/types.h>#ifndef __MINGW32__#include <sys/ioctl.h>#include <sys/wait.h>#else#define	SIGHUP	1	/* hangup */#define	SIGQUIT	3	/* quit */#define	SIGKILL	9	/* kill (cannot be caught or ignored) */#define	SIGBUS	10	/* bus error */extern int mp_input_win32_slave_cmd_func(int fd,char* dest,int size);#endif//==================================#define OSD_PLAY 0x01#define OSD_PAUSE 0x02#define OSD_STOP 0x03#define OSD_REW 0x04#define OSD_FFW 0x05#define OSD_CLOCK 0x06#define OSD_CONTRAST 0x07#define OSD_SATURATION 0x08#define OSD_VOLUME 0x09#define OSD_BRIGHTNESS 0x0A#define OSD_HUE 0x0B#define OSD_PANSCAN 0x50#define OSD_PB_START 0x10#define OSD_PB_0 0x11#define OSD_PB_END 0x12#define OSD_PB_1 0x13//========================================#include <sys/time.h>#include <sys/stat.h>#include <signal.h>#include <time.h>#include <fcntl.h>#include <limits.h>#include <errno.h>#include "version.h"#include "mp_msg.h"#define HELP_MP_DEFINE_STATIC#include "help_mp.h"#include "m_option.h"#include "m_config.h"#include "cfg-mplayer-def.h"#include "libao2/audio_out.h"#include "codec-cfg.h"#include "osdep/getch2.h"#include "osdep/timer.h"#include "cpudetect.h"#include "input/input.h"int slave_mode=0;int verbose=0;int identify=0;int quiet=0;#ifdef WIN32char * proc_priority=NULL;#endif#define ABS(x) (((x)>=0)?(x):(-(x)))#define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))//**************************************************************************////             Playtree//**************************************************************************//#include "playtree.h"#include "playtreeparser.h"#ifdef HAVE_NEW_GUIextern int import_playtree_playlist_into_gui(play_tree_t* my_playtree, m_config_t* config);extern int import_initial_playtree_into_gui(play_tree_t* my_playtree, m_config_t* config, int enqueue);#endifplay_tree_t* playtree;play_tree_iter_t* playtree_iter = NULL;#define PT_NEXT_ENTRY 1#define PT_PREV_ENTRY -1#define PT_NEXT_SRC 2#define PT_PREV_SRC -2#define PT_UP_NEXT 3#define PT_UP_PREV -3//**************************************************************************////             Config//**************************************************************************//m_config_t* mconfig;extern play_tree_t*m_config_parse_mp_command_line(m_config_t *config, int argc, char **argv);extern intm_config_parse_config_file(m_config_t* config, char *conffile);//**************************************************************************////             Config file//**************************************************************************//static int cfg_inc_verbose(m_option_t *conf){ ++verbose; return 0;}static int cfg_include(m_option_t *conf, char *filename){	return m_config_parse_config_file(mconfig, filename);}#include "get_path.c"//**************************************************************************////             Input media streaming & demultiplexer://**************************************************************************//static int max_framesize=0;#include "libmpdemux/stream.h"#include "libmpdemux/demuxer.h"#include "libmpdemux/stheader.h"#include "libmpcodecs/dec_audio.h"//#include "libmpcodecs/dec_video.h"#include "libmpcodecs/mp_image.h"//#include "libmpcodecs/vf.h"extern void vf_list_plugins();//**************************************************************************//// Common FIFO functions, and keyboard/event FIFO code#include "fifo.c"int noconsolecontrols=0;//**************************************************************************//ao_functions_t *audio_out=NULL;int fixed_vo=0;int eof=0;// benchmark:double video_time_usage=0;double vout_time_usage=0;static double audio_time_usage=0;static int total_time_usage_start=0;static int total_frame_cnt=0;static int drop_frame_cnt=0; // total number of dropped framesint benchmark=0;// options:       int auto_quality=0;static int output_quality=0;float playback_speed=1.0;int use_gui=0;#ifdef HAVE_NEW_GUIint enqueue=0;#endif#define MAX_OSD_LEVEL 3int osd_level=1;int osd_level_saved=-1;int osd_visible=100;// seek:static char *seek_to_sec=NULL;static off_t seek_to_byte=0;static off_t step_sec=0;static int loop_times=-1;static int loop_seek=0;// may be changed by GUI:  (FIXME!)float rel_seek_secs=0;int abs_seek_pos=0;// codecs:char **audio_codec_list=NULL; // override audio codecchar **audio_fm_list=NULL;    // override audio codec family // streaming:int audio_id=-1;int video_id=-1;int dvdsub_id=-1;int vobsub_id=-1;char* audio_lang=NULL;char* dvdsub_lang=NULL;static char* spudec_ifo=NULL;char* filename=NULL; //"MI2-Trailer.avi";int forced_subs_only=0;// cache2:       int stream_cache_size=-1;#ifdef USE_STREAM_CACHEextern int cache_fill_status;float stream_cache_min_percent=20.0;float stream_cache_prefill_percent=5.0;#else#define cache_fill_status 0#endif// dump:static char *stream_dump_name="stream.dump";       int stream_dump_type=0;// A-V sync:static float default_max_pts_correction=-1;//0.01f;static float max_pts_correction=0;//default_max_pts_correction;static float c_total=0;       float audio_delay=0;static int softsleep=0;       float force_fps=0;static int force_srate=0;static int audio_output_format=0;       int frame_dropping=0; // option  0=no drop  1= drop vo  2= drop decodestatic int play_n_frames=-1;static int play_n_frames_mf=-1;// screen info:char** video_driver_list=NULL;char** audio_driver_list=NULL;extern char *vo_subdevice;extern char *ao_subdevice;// codec outfmt flags (defined in libmpcodecs/vd.c)extern int vo_flags;static stream_t* stream=NULL;static demuxer_t *demuxer=NULL;static sh_audio_t *sh_audio=NULL;static sh_video_t *sh_video=NULL;char* current_module=NULL; // for debuggingstatic unsigned int inited_flags=0;#define INITED_VO 1#define INITED_AO 2#define INITED_GUI 4#define INITED_GETCH2 8#define INITED_SPUDEC 32#define INITED_STREAM 64#define INITED_INPUT    128#define INITED_VOBSUB  256#define INITED_DEMUXER 512#define INITED_ACODEC  1024#define INITED_VCODEC  2048#define INITED_ALL 0xFFFFstatic void uninit_player(unsigned int mask){  mask=inited_flags&mask;  mp_msg(MSGT_CPLAYER,MSGL_DBG2,"\n*** uninit(0x%X)\n",mask);  if(mask&INITED_ACODEC){    inited_flags&=~INITED_ACODEC;    current_module="uninit_acodec";    if(sh_audio) uninit_audio(sh_audio);#ifdef HAVE_NEW_GUI    guiGetEvent(guiSetAfilter, (char *)NULL);#endif    sh_audio=NULL;  }  if(mask&INITED_DEMUXER){    inited_flags&=~INITED_DEMUXER;    current_module="free_demuxer";    if(demuxer){	stream=demuxer->stream;	free_demuxer(demuxer);    }    demuxer=NULL;  }  // kill the cache process:  if(mask&INITED_STREAM){    inited_flags&=~INITED_STREAM;    current_module="uninit_stream";    if(stream) free_stream(stream);    stream=NULL;  }  // must be after libvo uninit, as few vo drivers (svgalib) has tty code  if(mask&INITED_GETCH2){    inited_flags&=~INITED_GETCH2;    current_module="uninit_getch2";    mp_msg(MSGT_CPLAYER,MSGL_DBG2,"\n[[[uninit getch2]]]\n");  // restore terminal:    getch2_disable();  }  if(mask&INITED_AO){    inited_flags&=~INITED_AO;    current_module="uninit_ao";    audio_out->uninit(eof?0:1); audio_out=NULL;  }#ifdef HAVE_NEW_GUI  if(mask&INITED_GUI){    inited_flags&=~INITED_GUI;    current_module="uninit_gui";    guiDone();  }#endif  if(mask&INITED_INPUT){    inited_flags&=~INITED_INPUT;    current_module="uninit_input";    mp_input_uninit();  }  current_module=NULL;}static void exit_player_with_rc(char* how, int rc){  uninit_player(INITED_ALL);  current_module="exit_player";// free mplayer config  free(mconfig);  if(how) mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_ExitingHow,mp_gettext(how));  mp_msg(MSGT_CPLAYER,MSGL_DBG2,"max framesize was %d bytes\n",max_framesize);  exit(rc);}void exit_player(char* how){  exit_player_with_rc(how, 1);}#ifndef __MINGW32__static void child_sighandler(int x){    pid_t pid;  while((pid=waitpid(-1,NULL,WNOHANG)) > 0);}#endifstatic void exit_sighandler(int x){  static int sig_count=0;  ++sig_count;  if(inited_flags==0 && sig_count>1) exit(1);  if(sig_count==5)    {      /* We're crashing bad and can't uninit cleanly :(        * by popular request, we make one last (dirty)        * effort to restore the user's        * terminal. */      getch2_disable();      exit(1);    }  if(sig_count==6) exit(1);  if(sig_count>6){    // can't stop :(#ifndef __MINGW32__    kill(getpid(),SIGKILL);#endif  }  mp_msg(MSGT_CPLAYER,MSGL_FATAL,"\n" MSGTR_IntBySignal,x,      current_module?current_module:mp_gettext("unknown")  );  if(sig_count<=1)  switch(x){  case SIGINT:  case SIGQUIT:  case SIGTERM:  case SIGKILL:      break;  // killed from keyboard (^C) or killed [-9]  case SIGILL:      mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGILL);  case SIGFPE:  case SIGSEGV:      mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGSEGV_SIGFPE);  default:      mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGCRASH);  }  exit_player(NULL);}//extern void write_avi_header_1(FILE *f,int fcc,float fps,int width,int height);extern void mp_input_register_options(m_config_t* cfg);#include "mixer.h"mixer_t mixer;/// step size of mixer changesint volstep = 3;#include "cfg-mplayer.h"void parse_cfgfiles( m_config_t* conf ){char *conffile;int conffile_fd;if (m_config_parse_config_file(conf, MPLAYER_CONFDIR "/mplayer.conf") < 0)  exit_player(NULL);if ((conffile = get_path("")) == NULL) {  mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_NoHomeDir);} else {#ifdef __MINGW32__  mkdir(conffile);#else  mkdir(conffile, 0777);#endif  free(conffile);  if ((conffile = get_path("config")) == NULL) {    mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_GetpathProblem);  } else {    if ((conffile_fd = open(conffile, O_CREAT | O_EXCL | O_WRONLY, 0666)) != -1) {      mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CreatingCfgFile, conffile);      write(conffile_fd, default_config, strlen(default_config));      close(conffile_fd);    }    if (m_config_parse_config_file(conf, conffile) < 0)      exit_player(NULL);    free(conffile);  }}}void load_per_file_config (m_config_t* conf, const char *const file){    char *confpath;    char cfg[strlen(file)+10];    struct stat st;    char *name;    sprintf (cfg, "%s.conf", file);        if (!stat (cfg, &st))    {	mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_LoadingConfig, cfg);	m_config_parse_config_file (conf, cfg);	return;    }    if ((name = strrchr (cfg, '/')) == NULL)	name = cfg;    else	name++;    if ((confpath = get_path (name)) != NULL)    {	if (!stat (confpath, &st))	{	    mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_LoadingConfig, confpath);	    m_config_parse_config_file (conf, confpath);	}	free (confpath);    }}// When libmpdemux perform a blocking operation (network connection or cache filling)// if the operation fail we use this function to check if it was interrupted by the user.// The function return a new value for eof.static int libmpdemux_was_interrupted(int eof) {  mp_cmd_t* cmd;  if((cmd = mp_input_get_cmd(0,0,0)) != NULL) {       switch(cmd->id) {       case MP_CMD_QUIT:	 exit_player_with_rc(MSGTR_Exit_quit, (cmd->nargs > 0)? cmd->args[0].v.i : 0);       case MP_CMD_PLAY_TREE_STEP: {	 eof = (cmd->args[0].v.i > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;       } break;       case MP_CMD_PLAY_TREE_UP_STEP: {	 eof = (cmd->args[0].v.i > 0) ? PT_UP_NEXT : PT_UP_PREV;       } break;	         case MP_CMD_PLAY_ALT_SRC_STEP: {	 eof = (cmd->args[0].v.i > 0) ?  PT_NEXT_SRC : PT_PREV_SRC;       } break;       }       mp_cmd_free(cmd);

⌨️ 快捷键说明

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