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

📄 mplayer.c

📁 自己移植的linux下的流媒体播放器原代码,支持mms协议,支持ftp和http协议.
💻 C
📖 第 1 页 / 共 4 页
字号:
  }  return eof;}#define mp_basename2(s) (strrchr(s,'/')==NULL?(char*)s:(strrchr(s,'/')+1))#define mp_basename(s) (strrchr(s,'\\')==NULL?(mp_basename2(s)):(strrchr(s,'\\')+1))int playtree_add_playlist(play_tree_t* entry){  play_tree_add_bpf(entry,filename);  if(!entry) {          entry = playtree_iter->tree;    if(play_tree_iter_step(playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) {        return PT_NEXT_ENTRY;    }    if(playtree_iter->tree == entry ) { // Loop with a single file      if(play_tree_iter_up_step(playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) {	return PT_NEXT_ENTRY;      }    }    play_tree_remove(entry,1,1);    return PT_NEXT_SRC;  }  play_tree_insert_entry(playtree_iter->tree,entry);  play_tree_set_params_from(entry,playtree_iter->tree);  entry = playtree_iter->tree;  if(play_tree_iter_step(playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) {    return PT_NEXT_ENTRY;  }        play_tree_remove(entry,1,1);  return PT_NEXT_SRC;}static int play_tree_step = 1;static void saddf(char *buf, unsigned *pos, int len, const char *format, ...){  va_list va;  va_start(va, format);  *pos += vsnprintf(&buf[*pos], len - *pos, format, va);  va_end(va);  if (*pos >= len ) {    buf[len] = 0;    *pos = len;  }}/** * \brief print the status line * \param a_pos audio position * \param a_v A-V desynchronization * \param corr amount out A-V synchronization */static void print_status(float a_pos, float a_v, float corr){  int width;  char *line;  unsigned pos = 0;  get_screen_size();  if (screen_width > 0)    width = screen_width;  else  width = 80;#ifdef WIN32  // windows command line is broken (MinGW's rxvt works though, but we  // should not depend on that).  width--;#endif  line = malloc(width + 1); // one additional for terminating null    // Audio time  if (sh_audio) {    saddf(line, &pos, width, "A:%6.1f ", a_pos);    if (!sh_video) {      // convert time to HH:MM:SS.F format      long tenths = 10 * a_pos;      int f1 = tenths % 10;      int ss = (tenths /  10) % 60;      int mm = (tenths / 600) % 60;      int hh = (tenths / 36000) % 100;      saddf(line, &pos, width, "(");      if (hh > 0)        saddf(line, &pos, width, "%2d:", hh);      if (hh > 0 || mm > 0)        saddf(line, &pos, width, "%02d:", mm);      saddf(line, &pos, width, "%02d.", ss);      saddf(line, &pos, width, "%1d", f1);      saddf(line, &pos, width, ") ");    }  }  // Video time  if (sh_video)    saddf(line, &pos, width, "V:%6.1f ", sh_video->pts);  // A-V sync  if (sh_audio && sh_video)    saddf(line, &pos, width, "A-V:%7.3f ct:%7.3f ", a_v, corr);  // Video stats  if (sh_video)    saddf(line, &pos, width, "%3d/%3d ",      (int)sh_video->num_frames,      (int)sh_video->num_frames_decoded);  // CPU usage  if (sh_video) {    if (sh_video->timer > 0.5)      saddf(line, &pos, width, "%2d%% %2d%% %4.1f%% ",        (int)(100.0*video_time_usage*playback_speed/(double)sh_video->timer),        (int)(100.0*vout_time_usage*playback_speed/(double)sh_video->timer),        (100.0*audio_time_usage*playback_speed/(double)sh_video->timer));    else      saddf(line, &pos, width, "??%% ??%% ??,?%% ");  } else if (sh_audio) {    if (sh_audio->delay > 0.5)      saddf(line, &pos, width, "%4.1f%% ",        100.0*audio_time_usage/(double)sh_audio->delay);    else      saddf(line, &pos, width, "??,?%% ");  }  // VO stats  if (sh_video)     saddf(line, &pos, width, "%d %d ", drop_frame_cnt, output_quality);#ifdef USE_STREAM_CACHE  // cache stats  if (stream_cache_size > 0)    saddf(line, &pos, width, "%d%% ", cache_fill_status);#endif  // other  if (playback_speed != 1)    saddf(line, &pos, width, "%4.2fx ", playback_speed);  // end  memset(&line[pos], ' ', width - pos);  line[width] = 0;  mp_msg(MSGT_AVSYNC, MSGL_STATUS, "%s\r", line);  free(line);}/** * \brief build a chain of audio filters that converts the input format * to the ao's format, taking into account the current playback_speed. * \param sh_audio describes the requested input format of the chain. * \param ao_data describes the requested output format of the chain. */static int build_afilter_chain(sh_audio_t *sh_audio, ao_data_t *ao_data){  int new_srate;  int result;  if (!sh_audio)  {    mixer.afilter = NULL;    return 0;  }  new_srate = sh_audio->samplerate * playback_speed;  if (new_srate != ao_data->samplerate) {    // limits are taken from libaf/af_resample.c    if (new_srate < 8000)      new_srate = 8000;    if (new_srate > 192000)      new_srate = 192000;    playback_speed = (float)new_srate / (float)sh_audio->samplerate;  }  result =  init_audio_filters(sh_audio, new_srate,           sh_audio->channels, sh_audio->sample_format,           ao_data->samplerate, ao_data->channels, ao_data->format,           ao_data->outburst * 4, ao_data->buffersize);  mixer.afilter = sh_audio->afilter;  return result;}int main(int argc,char* argv[]){char * mem_ptr;static demux_stream_t *d_audio=NULL;static demux_stream_t *d_video=NULL;static demux_stream_t *d_dvdsub=NULL;int file_format=DEMUXER_TYPE_UNKNOWN;int delay_corrected=1;// movie info:int osd_function=OSD_PLAY;int rtc_fd=-1;//float a_frame=0;    // Audioint i;char *tmp;int gui_no_filename=0;  srand((int) time(NULL));   mp_msg_init();  mp_msg_set_level(MSGL_STATUS);  mp_msg(MSGT_CPLAYER,MSGL_INFO, "MPlayer " VERSION " (C) 2000-2005 MPlayer Team\n");  /* Test for cpu capabilities (and corresponding OS support) for optimizing */  GetCpuCaps(&gCpuCaps);#if defined(ARCH_X86) || defined(ARCH_X86_64)  mp_msg(MSGT_CPLAYER,MSGL_INFO,"CPUflags:  MMX: %d MMX2: %d 3DNow: %d 3DNow2: %d SSE: %d SSE2: %d\n",      gCpuCaps.hasMMX,gCpuCaps.hasMMX2,      gCpuCaps.has3DNow, gCpuCaps.has3DNowExt,      gCpuCaps.hasSSE, gCpuCaps.hasSSE2);#ifdef RUNTIME_CPUDETECT  mp_msg(MSGT_CPLAYER,MSGL_INFO, MSGTR_CompiledWithRuntimeDetection);#else  mp_msg(MSGT_CPLAYER,MSGL_INFO, MSGTR_CompiledWithCPUExtensions);#ifdef HAVE_MMX  mp_msg(MSGT_CPLAYER,MSGL_INFO," MMX");#endif#ifdef HAVE_MMX2  mp_msg(MSGT_CPLAYER,MSGL_INFO," MMX2");#endif#ifdef HAVE_3DNOW  mp_msg(MSGT_CPLAYER,MSGL_INFO," 3DNow");#endif#ifdef HAVE_3DNOWEX  mp_msg(MSGT_CPLAYER,MSGL_INFO," 3DNowEx");#endif#ifdef HAVE_SSE  mp_msg(MSGT_CPLAYER,MSGL_INFO," SSE");#endif#ifdef HAVE_SSE2  mp_msg(MSGT_CPLAYER,MSGL_INFO," SSE2");#endif  mp_msg(MSGT_CPLAYER,MSGL_INFO,"\n\n");#endif#endif#if defined(WIN32) && defined(USE_WIN32DLL){  /*make our codec dirs available for LoadLibraryA()*/  char tmppath[MAX_PATH*2 + 1];  char win32path[MAX_PATH];  char realpath[MAX_PATH];#ifdef __CYGWIN__  cygwin_conv_to_full_win32_path(WIN32_PATH,win32path);  strcpy(tmppath,win32path);#ifdef USE_REALCODECS  cygwin_conv_to_full_win32_path(REALCODEC_PATH,realpath);  sprintf(tmppath,"%s;%s",win32path,realpath);#endif /*USE_REALCODECS*/#else  if(!strstr(WIN32_PATH,":")){    GetModuleFileNameA(NULL, win32path, MAX_PATH);    strcpy(win32path + strlen(win32path) - strlen("mplayer.exe"), WIN32_PATH);  }  else strcpy(win32path,WIN32_PATH);  strcpy(tmppath,win32path);#ifdef USE_REALCODECS  if(!strstr(REALCODEC_PATH,":")){    GetModuleFileNameA(NULL, realpath, MAX_PATH);    strcpy(realpath + strlen(realpath) - strlen("mplayer.exe"), REALCODEC_PATH);  }  else strcpy(realpath,REALCODEC_PATH);  sprintf(tmppath,"%s;%s",win32path,realpath);#endif /*USE_REALCODECS*/#endif /*__CYGWIN__*/  SetEnvironmentVariableA("PATH", tmppath);}#endif /*WIN32 && USE_WIN32DLL*/#ifdef USE_TV  tv_param_immediate = 1;#endifif ( argv[0] )    mconfig = m_config_new();    m_config_register_options(mconfig,mplayer_opts);    // TODO : add something to let modules register their options    mp_input_register_options(mconfig);    parse_cfgfiles(mconfig);#ifdef HAVE_NEW_GUI    if ( use_gui ) cfg_read();#endif    playtree = m_config_parse_mp_command_line(mconfig, argc, argv);    if(playtree == NULL)      exit_player(NULL);    playtree = play_tree_cleanup(playtree);    if(playtree) {      playtree_iter = play_tree_iter_new(playtree,mconfig);      if(playtree_iter) {  	if(play_tree_iter_step(playtree_iter,0,0) != PLAY_TREE_ITER_ENTRY) {	  play_tree_iter_free(playtree_iter);	  playtree_iter = NULL;	}	filename = play_tree_iter_get_file(playtree_iter,1);      }    }	#ifdef WIN32	if(proc_priority){		int i;        	for(i=0; priority_presets_defs[i].name; i++){        		if(strcasecmp(priority_presets_defs[i].name, proc_priority) == 0)				break;		}		mp_msg(MSGT_CPLAYER,MSGL_STATUS,"Setting process priority: %s\n",				priority_presets_defs[i].name);		SetPriorityClass(GetCurrentProcess(), priority_presets_defs[i].prio);	}#endif	#ifndef HAVE_NEW_GUI    if(use_gui){      mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_NoGui);      use_gui=0;    }#else    if(use_gui && !vo_init()){      mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_GuiNeedsX);      use_gui=0;    }    if (use_gui && playtree_iter){      char cwd[PATH_MAX+2];      // Remove Playtree and Playtree-Iter from memory as its not used by gui      play_tree_iter_free(playtree_iter);      playtree_iter=NULL;            if (getcwd(cwd, PATH_MAX) != (char *)NULL)      {	  strcat(cwd, "/");          // Prefix relative paths with current working directory          play_tree_add_bpf(playtree, cwd);      }            // Import initital playtree into gui      import_initial_playtree_into_gui(playtree, mconfig, enqueue);    }#endif    if(audio_driver_list && strcmp(audio_driver_list[0],"help")==0){      list_audio_out();      exit_player_with_rc(NULL, 0);    }// check codec.confif(!codecs_file || !parse_codec_cfg(codecs_file)){  if(!parse_codec_cfg(mem_ptr=get_path("codecs.conf"))){    if(!parse_codec_cfg(MPLAYER_CONFDIR "/codecs.conf")){      if(!parse_codec_cfg(NULL)){	mp_msg(MSGT_CPLAYER,MSGL_HINT,MSGTR_CopyCodecsConf);        exit_player_with_rc(NULL, 0);      }      mp_msg(MSGT_CPLAYER,MSGL_V,MSGTR_BuiltinCodecsConf);    }  }  free( mem_ptr ); // release the buffer created by get_path()}    if(audio_codec_list && strcmp(audio_codec_list[0],"help")==0){      mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AvailableAudioCodecs);      list_codecs(1);      mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");      exit_player_with_rc(NULL, 0);    }    if(audio_fm_list && strcmp(audio_fm_list[0],"help")==0){      afm_help();      mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");      exit_player_with_rc(NULL, 0);    }    if(af_cfg.list && strcmp(af_cfg.list[0],"help")==0){      af_help();      printf("\n");      exit_player_with_rc(NULL, 0);    }#ifdef HAVE_X11    if(vo_fstype_list && strcmp(vo_fstype_list[0],"help")==0){      fstype_help();      mp_msg(MSGT_FIXME, MSGL_FIXME, "\n");      exit_player_with_rc(NULL, 0);    }#endif#ifdef USE_EDLif (edl_check_mode() == EDL_ERROR && edl_filename){    mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_EdlCantUseBothModes);    exit_player(NULL);} else if (edl_filename){    if (edl_records) free_edl(edl_records);    next_edl_record = edl_records = edl_parse_file();} else if (edl_output_filename){    if ((edl_fd = fopen(edl_output_filename, "w")) == NULL)    {        mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_EdlCantOpenForWrite,               edl_output_filename);        exit_player(NULL);    }}#endif    if(!filename){      if(!use_gui){	// no file/vcd/dvd -> show HELP:	mp_msg(MSGT_CPLAYER, MSGL_INFO, help_text);        exit_player_with_rc(NULL, 0);      } else gui_no_filename=1;    }    // Many users forget to include command line in bugreports...    if(verbose>0){      mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_CommandLine);      for(i=1;i<argc;i++)mp_msg(MSGT_CPLAYER, MSGL_INFO," '%s'",argv[i]);      mp_msg(MSGT_CPLAYER, MSGL_INFO, "\n");    }    mp_msg_set_level(verbose+MSGL_STATUS);//------ load global data first ------// check font     mp_msg(MSGT_CPLAYER, MSGL_V, "Using %s timing\n",	     softsleep?"software":timer_name);#ifdef USE_TERMCAP  if ( !use_gui ) load_termcap(NULL); // load key-codes#endif// ========== Init keyboard FIFO (connection to libvo) ============// Init input systemcurrent_module = "init_input";mp_input_init();#if 0make_pipe(&keyb_fifo_get,&keyb_fifo_put);if(keyb_fifo_get > 0)  mp_input_add_key_fd(keyb_fifo_get,1,NULL,NULL);#else  mp_input_add_key_fd(-1,0,mplayer_get_key,NULL);#endifif(slave_mode)#ifndef __MINGW32__   mp_input_add_cmd_fd(0,1,NULL,NULL);#else  mp_input_add_cmd_fd(0,0,mp_input_win32_slave_cmd_func,NULL);#endifelse if(!noconsolecontrols)#ifndef HAVE_NO_POSIX_SELECT  mp_input_add_key_fd(0,1,NULL,NULL);#else  mp_input_add_key_fd(0,0,NULL,NULL);#endifinited_flags|=INITED_INPUT;current_module = NULL;#ifdef HAVE_MENU if(use_menu) {   if(menu_cfg && menu_init(menu_cfg))     mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MenuInitialized, menu_cfg);   else {     menu_cfg = get_path("menu.conf");     if(menu_init(menu_cfg))       mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MenuInitialized, menu_cfg);     else {       if(menu_init(MPLAYER_CONFDIR "/menu.conf"))         mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MenuInitialized, MPLAYER_CONFDIR"/menu.conf");       else {         mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MenuInitFailed);         use_menu = 0;       }     }   } }#endif    /// Catch signals#ifndef __MINGW32__  signal(SIGCHLD,child_sighandler);#endif#ifdef CRASH_DEBUG

⌨️ 快捷键说明

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