📄 init.cxx
字号:
if(mask&INITED_VO){ inited_flags&=~INITED_VO; current_module="uninit_vo"; video_out->uninit(); video_out=NULL; } // Must be after libvo uninit, as few vo drivers (svgalib) have 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_VOBSUB){ inited_flags&=~INITED_VOBSUB; current_module="uninit_vobsub"; if(vo_vobsub) vobsub_close(vo_vobsub); vo_vobsub=NULL; } if (mask&INITED_SPUDEC){ inited_flags&=~INITED_SPUDEC; current_module="uninit_spudec"; spudec_free(vo_spudec); vo_spudec=NULL; } 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);#ifdef HAVE_X11#ifdef HAVE_NEW_GUI if ( !use_gui )#endif vo_uninit(); // Close the X11 connection (if any is open).#endif#ifdef HAVE_FREETYPE current_module="uninit_font"; if (vo_font) free_font_desc(vo_font); vo_font = NULL; done_freetype();#endif free_osd_list(); current_module="exit_player";// free mplayer config if(mconfig) m_config_free(mconfig); if(playtree) play_tree_free(playtree, 1); if(edl_records != NULL) free(edl_records); // free mem allocated for EDL if(how) mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_ExitingHow,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);}#endif#ifdef CRASH_DEBUGstatic char *prog_path;static int crash_debug = 0;#endifstatic void exit_sighandler(int x){ static int sig_count=0;#ifdef CRASH_DEBUG if (!crash_debug || x != SIGTRAP)#endif ++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:"unknown" ); mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_SIGNAL=%d\n", x); if(sig_count<=1) switch(x){ case SIGINT: case SIGQUIT: case SIGTERM: case SIGKILL: break; // killed from keyboard (^C) or killed [-9] case SIGILL:#ifdef RUNTIME_CPUDETECT mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGILL_RTCpuSel);#else mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGILL);#endif case SIGFPE: case SIGSEGV: mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGSEGV_SIGFPE); default: mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_Exit_SIGCRASH);#ifdef CRASH_DEBUG if (crash_debug) { int gdb_pid; char spid[20]; snprintf(spid, 19, "%i", getpid()); spid[19] = 0; mp_msg(MSGT_CPLAYER, MSGL_INFO, "Forking...\n"); gdb_pid = fork(); mp_msg(MSGT_CPLAYER, MSGL_INFO, "Forked...\n"); if (gdb_pid == 0) { // We are the child if (execlp("gdb", "gdb", prog_path, spid, NULL) == -1) mp_msg(MSGT_CPLAYER, MSGL_ERR, "Couldn't start gdb\n"); } else if (gdb_pid < 0) mp_msg(MSGT_CPLAYER, MSGL_ERR, "Couldn't fork\n"); else { waitpid(gdb_pid, NULL, 0); } if (x == SIGTRAP) return; }#endif } 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 performs a blocking operation (network connection or * cache filling) if the operation fails we use this function to check * if it was interrupted by the user. * The function returns 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; play_tree_step = (cmd->args[0].v.i == 0) ? 1 : cmd->args[0].v.i; } 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); } 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);#ifdef HAVE_NEW_GUI if (use_gui) { if (entry) { import_playtree_playlist_into_gui(entry, mconfig); play_tree_free_list(entry,1); } } else#endif { 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;}int sub_source(void){ int source = -1; int top = -1; int i; for (i = 0; i < SUB_SOURCES; i++) { int j = global_sub_indices[i]; if ((j >= 0) && (j > top) && (global_sub_pos >= j)) { source = i; top = j; } } return source;}#ifdef USE_SUBsub_data* subdata = NULL;static subtitle* vo_sub_last = NULL;void add_subtitles(char *filename, float fps, int silent){ sub_data *subd; if (filename == NULL) { return; } subd = sub_read_file(filename, fps); if(!subd && !silent) mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_CantLoadSub, filename); if (subd == NULL || set_of_sub_size >= MAX_SUBTITLE_FILES) return; set_of_subtitles[set_of_sub_size] = subd; mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_FILE_SUB_ID=%d\n", set_of_sub_size); mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_FILE_SUB_FILENAME=%s\n", filename); ++set_of_sub_size; mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AddedSubtitleFile, set_of_sub_size, filename);}// FIXME: if/when the GUI calls this, global sub numbering gets (potentially) broken.void update_set_of_subtitles(void) // subdata was changed, set_of_sub... have to be updated.{ int i; if (set_of_sub_size > 0 && subdata == NULL) { // *subdata was deleted for (i = set_of_sub_pos + 1; i < set_of_sub_size; ++i) set_of_subtitles[i-1] = set_of_subtitles[i]; set_of_subtitles[set_of_sub_size-1] = NULL; --set_of_sub_size; if (set_of_sub_size > 0) subdata = set_of_subtitles[set_of_sub_pos=0]; } else if (set_of_sub_size > 0 && subdata != NULL) { // *subdata was changed set_of_subtitles[set_of_sub_pos] = subdata; } else if (set_of_sub_size <= 0 && subdata != NULL) { // *subdata was added set_of_subtitles[set_of_sub_pos=set_of_sub_size] = subdata; ++set_of_sub_size; }}#endif /* USE_SUB *//* * In Mac OS X the SDL-lib is built upon Cocoa. The easiest way to * make it all work is to use the builtin SDL-bootstrap code, which * will be done automatically by replacing our main() if we include SDL.h. */#if defined(SYS_DARWIN) && defined(HAVE_SDL)#include <SDL.h>#endif/** * \brief append a formatted string * \param buf buffer to print into * \param pos position of terminating 0 in buf * \param len maximum number of characters in buf, not including terminating 0 * \param format printf format string */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 append time in the hh:mm:ss.f format * \param buf buffer to print into * \param pos position of terminating 0 in buf * \param len maximum number of characters in buf, not including terminating 0 * \param time time value to convert/append */static void sadd_hhmmssf(char *buf, unsigned *pos, int len, float time) { long tenths = 10 * time; int f1 = tenths % 10; int ss = (tenths / 10) % 60; int mm = (tenths / 600) % 60; int hh = tenths / 36000; if (time <= 0) { saddf(buf, pos, len, "unknown"); return; } if (hh > 0) saddf(buf, pos, len, "%2d:", hh); if (hh > 0 || mm > 0) saddf(buf, pos, len, "%02d:", mm); saddf(buf, pos, len, "%02d.%1d", ss, f1);}/** * \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, but we * should not depend on that). */ width--;#endif line = malloc(width + 1); // one additional char for the terminating null // Audio time if (sh_audio) { saddf(line, &pos, width, "A:%6.1f ", a_pos); if (!sh_video) { float len = demuxer_get_time_length(demuxer); saddf(line, &pos, width, "(");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -