From 0fd7e6ec93c54b5f22c6e8730448cc9170ae7d99 Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Sun, 7 Aug 2011 03:58:12 +0300 Subject: cleanup: reformat mplayer.c I had delayed reformatting mplayer.c as I wanted to split it, but since I didn't come up with a good way to do that I'll clean up the messy formatting now. --- mplayer.c | 4174 ++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 2174 insertions(+), 2000 deletions(-) (limited to 'mplayer.c') diff --git a/mplayer.c b/mplayer.c index bc99557a58..7ddcf48a5c 100644 --- a/mplayer.c +++ b/mplayer.c @@ -41,11 +41,11 @@ #include #include #else -#define SIGHUP 1 /* hangup */ -#define SIGQUIT 3 /* quit */ -#define SIGKILL 9 /* kill (cannot be caught or ignored) */ -#define SIGBUS 10 /* bus error */ -#define SIGPIPE 13 /* broken pipe */ +#define SIGHUP 1 /* hangup */ +#define SIGQUIT 3 /* quit */ +#define SIGKILL 9 /* kill (cannot be caught or ignored) */ +#define SIGBUS 10 /* bus error */ +#define SIGPIPE 13 /* broken pipe */ #endif #include @@ -103,8 +103,8 @@ #include "input/input.h" -int slave_mode=0; -int enable_mouse_movements=0; +int slave_mode = 0; +int enable_mouse_movements = 0; float start_volume = -1; #include "osdep/priority.h" @@ -144,7 +144,11 @@ char *heartbeat_cmd; // Config file //**************************************************************************// -static int cfg_inc_verbose(m_option_t *conf){ ++verbose; return 0;} +static int cfg_inc_verbose(m_option_t *conf) +{ + ++verbose; + return 0; +} #include "path.h" @@ -153,7 +157,7 @@ static int cfg_inc_verbose(m_option_t *conf){ ++verbose; return 0;} // Input media streaming & demultiplexer: //**************************************************************************// -static int max_framesize=0; +static int max_framesize = 0; #include "stream/stream.h" #include "libmpdemux/demuxer.h" @@ -176,7 +180,7 @@ static int max_framesize=0; #include "options.h" #include "defaultopts.h" -static const char help_text[]=_( +static const char help_text[] = _( "Usage: mplayer [options] [url|path/]filename\n" "\n" "Basic options: (complete list in the man page)\n" @@ -271,67 +275,67 @@ static const char help_text[]=_( #include "mp_fifo.h" // 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 frames +double video_time_usage; +double vout_time_usage; +static double audio_time_usage; +static int total_time_usage_start; +static int total_frame_cnt; +static int drop_frame_cnt; // total number of dropped frames // options: -static int output_quality=0; +static int output_quality; // seek: -static off_t seek_to_byte=0; -static off_t step_sec=0; +static off_t seek_to_byte; +static off_t step_sec; static m_time_size_t end_at = { .type = END_AT_NONE, .pos = 0 }; // codecs: -char **audio_codec_list=NULL; // override audio codec -char **video_codec_list=NULL; // override video codec -char **audio_fm_list=NULL; // override audio codec family -char **video_fm_list=NULL; // override video codec family +char **audio_codec_list; // override audio codec +char **video_codec_list; // override video codec +char **audio_fm_list; // override audio codec family +char **video_fm_list; // override video codec family // this dvdsub_id was selected via slang // use this to allow dvdnav to follow -slang across stream resets, // in particular the subtitle ID for a language changes int dvdsub_lang_id; -int vobsub_id=-1; -static char* spudec_ifo=NULL; -int forced_subs_only=0; -int file_filter=1; +int vobsub_id = -1; +static char *spudec_ifo = NULL; +int forced_subs_only = 0; +int file_filter = 1; // cache2: - int stream_cache_size=-1; +int stream_cache_size = -1; // dump: - int stream_dump_type=0; +int stream_dump_type = 0; // A-V sync: -static float default_max_pts_correction=-1;//0.01f; - float audio_delay=0; -static int ignore_start=0; +static float default_max_pts_correction = -1; +float audio_delay = 0; +static int ignore_start = 0; - double force_fps=0; -static int force_srate=0; - int frame_dropping=0; // option 0=no drop 1= drop vo 2= drop decode -static int play_n_frames=-1; -static int play_n_frames_mf=-1; +double force_fps = 0; +static int force_srate = 0; +int frame_dropping = 0; // option 0=no drop 1= drop vo 2= drop decode +static int play_n_frames = -1; +static int play_n_frames_mf = -1; // sub: -char *font_name=NULL; -char *sub_font_name=NULL; +char *font_name = NULL; +char *sub_font_name = NULL; extern int font_fontconfig; -float font_factor=0.75; -float sub_delay=0; -float sub_fps=0; -int subcc_enabled=0; +float font_factor = 0.75; +float sub_delay = 0; +float sub_fps = 0; +int subcc_enabled = 0; int suboverlap_enabled = 1; #include "sub/ass_mp.h" -char* current_module=NULL; // for debugging +char *current_module; // for debugging // --- @@ -339,20 +343,20 @@ char* current_module=NULL; // for debugging #ifdef CONFIG_MENU #include "m_struct.h" #include "libmenu/menu.h" -static const vf_info_t* const libmenu_vfs[] = { - &vf_info_menu, - NULL +static const vf_info_t * const libmenu_vfs[] = { + &vf_info_menu, + NULL }; -static vf_instance_t* vf_menu = NULL; -int use_menu = 0; -static char* menu_cfg = NULL; -static char* menu_root = "main"; +static vf_instance_t *vf_menu; +int use_menu; +static char *menu_cfg; +static char *menu_root = "main"; #endif edl_record_ptr edl_records = NULL; ///< EDL entries memory area edl_record_ptr next_edl_record = NULL; ///< only for traversing edl_records -FILE* edl_fd = NULL; ///< fd to write to when in -edlout mode. +FILE *edl_fd; // file to write to when in -edlout mode. int use_filedir_conf; int use_filename_title; @@ -399,62 +403,57 @@ static float get_relative_time(struct MPContext *mpctx) return delta * 0.000001; } -static int is_valid_metadata_type(struct MPContext *mpctx, metadata_t type) { - switch (type) - { - /* check for valid video stream */ - case META_VIDEO_CODEC: - case META_VIDEO_BITRATE: - case META_VIDEO_RESOLUTION: - { - if (!mpctx->sh_video) - return 0; - break; - } - - /* check for valid audio stream */ - case META_AUDIO_CODEC: - case META_AUDIO_BITRATE: - case META_AUDIO_SAMPLES: - { - if (!mpctx->sh_audio) - return 0; - break; - } - - /* check for valid demuxer */ - case META_INFO_TITLE: - case META_INFO_ARTIST: - case META_INFO_ALBUM: - case META_INFO_YEAR: - case META_INFO_COMMENT: - case META_INFO_TRACK: - case META_INFO_GENRE: - { - if (!mpctx->demuxer) - return 0; - break; - } - - default: - break; - } - - return 1; +static int is_valid_metadata_type(struct MPContext *mpctx, metadata_t type) +{ + switch (type) { + /* check for valid video stream */ + case META_VIDEO_CODEC: + case META_VIDEO_BITRATE: + case META_VIDEO_RESOLUTION: + if (!mpctx->sh_video) + return 0; + break; + + /* check for valid audio stream */ + case META_AUDIO_CODEC: + case META_AUDIO_BITRATE: + case META_AUDIO_SAMPLES: + if (!mpctx->sh_audio) + return 0; + break; + + /* check for valid demuxer */ + case META_INFO_TITLE: + case META_INFO_ARTIST: + case META_INFO_ALBUM: + case META_INFO_YEAR: + case META_INFO_COMMENT: + case META_INFO_TRACK: + case META_INFO_GENRE: + if (!mpctx->demuxer) + return 0; + break; + + default: + break; + } + + return 1; } -static char *get_demuxer_info(struct MPContext *mpctx, char *tag) { - char **info = mpctx->demuxer->info; - int n; +static char *get_demuxer_info(struct MPContext *mpctx, char *tag) +{ + char **info = mpctx->demuxer->info; + int n; - if (!info || !tag) - return talloc_strdup(NULL, ""); + if (!info || !tag) + return talloc_strdup(NULL, ""); - for (n = 0; info[2*n] != NULL ; n++) - if (!strcasecmp (info[2*n], tag)) - break; + for (n = 0; info[2 * n] != NULL; n++) + if (!strcasecmp(info[2 * n], tag)) + break; - return talloc_strdup(NULL, info[2*n+1] ? info[2*n+1] : ""); + return talloc_strdup(NULL, info[2 * n + 1] ? info[2 * n + 1] : ""); } char *get_metadata(struct MPContext *mpctx, metadata_t type) @@ -493,96 +492,116 @@ char *get_metadata(struct MPContext *mpctx, metadata_t type) return talloc_strdup(NULL, ""); case META_AUDIO_BITRATE: return talloc_asprintf(NULL, "%d kbps", - (int) (sh_audio->i_bps * 8/1000)); + (int) (sh_audio->i_bps * 8 / 1000)); case META_AUDIO_SAMPLES: return talloc_asprintf(NULL, "%d Hz, %d ch.", sh_audio->samplerate, sh_audio->channels); - /* check for valid demuxer */ - case META_INFO_TITLE: - return get_demuxer_info(mpctx, "Title"); + /* check for valid demuxer */ + case META_INFO_TITLE: + return get_demuxer_info(mpctx, "Title"); - case META_INFO_ARTIST: - return get_demuxer_info(mpctx, "Artist"); + case META_INFO_ARTIST: + return get_demuxer_info(mpctx, "Artist"); - case META_INFO_ALBUM: - return get_demuxer_info(mpctx, "Album"); + case META_INFO_ALBUM: + return get_demuxer_info(mpctx, "Album"); - case META_INFO_YEAR: - return get_demuxer_info(mpctx, "Year"); + case META_INFO_YEAR: + return get_demuxer_info(mpctx, "Year"); - case META_INFO_COMMENT: - return get_demuxer_info(mpctx, "Comment"); + case META_INFO_COMMENT: + return get_demuxer_info(mpctx, "Comment"); - case META_INFO_TRACK: - return get_demuxer_info(mpctx, "Track"); + case META_INFO_TRACK: + return get_demuxer_info(mpctx, "Track"); - case META_INFO_GENRE: - return get_demuxer_info(mpctx, "Genre"); + case META_INFO_GENRE: + return get_demuxer_info(mpctx, "Genre"); - default: - break; - } + default: + break; + } return talloc_strdup(NULL, ""); } static void print_file_properties(struct MPContext *mpctx, const char *filename) { - double start_pts = MP_NOPTS_VALUE; - double video_start_pts = MP_NOPTS_VALUE; - mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_FILENAME=%s\n", - filename_recode(filename)); - mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_DEMUXER=%s\n", mpctx->demuxer->desc->name); - if (mpctx->sh_video) { - /* Assume FOURCC if all bytes >= 0x20 (' ') */ - if (mpctx->sh_video->format >= 0x20202020) - mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_VIDEO_FORMAT=%.4s\n", (char *)&mpctx->sh_video->format); - else - mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_VIDEO_FORMAT=0x%08X\n", mpctx->sh_video->format); - mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_VIDEO_BITRATE=%d\n", mpctx->sh_video->i_bps*8); - mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_VIDEO_WIDTH=%d\n", mpctx->sh_video->disp_w); - mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_VIDEO_HEIGHT=%d\n", mpctx->sh_video->disp_h); - mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_VIDEO_FPS=%5.3f\n", mpctx->sh_video->fps); - mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_VIDEO_ASPECT=%1.4f\n", mpctx->sh_video->aspect); - video_start_pts = ds_get_next_pts(mpctx->d_video); - } - if (mpctx->sh_audio) { - /* Assume FOURCC if all bytes >= 0x20 (' ') */ - if (mpctx->sh_audio->format >= 0x20202020) - mp_msg(MSGT_IDENTIFY,MSGL_INFO, "ID_AUDIO_FORMAT=%.4s\n", (char *)&mpctx->sh_audio->format); + double start_pts = MP_NOPTS_VALUE; + double video_start_pts = MP_NOPTS_VALUE; + mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_FILENAME=%s\n", + filename_recode(filename)); + mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_DEMUXER=%s\n", + mpctx->demuxer->desc->name); + if (mpctx->sh_video) { + /* Assume FOURCC if all bytes >= 0x20 (' ') */ + if (mpctx->sh_video->format >= 0x20202020) + mp_msg(MSGT_IDENTIFY, MSGL_INFO, + "ID_VIDEO_FORMAT=%.4s\n", (char *)&mpctx->sh_video->format); + else + mp_msg(MSGT_IDENTIFY, MSGL_INFO, + "ID_VIDEO_FORMAT=0x%08X\n", mpctx->sh_video->format); + mp_msg(MSGT_IDENTIFY, MSGL_INFO, + "ID_VIDEO_BITRATE=%d\n", mpctx->sh_video->i_bps * 8); + mp_msg(MSGT_IDENTIFY, MSGL_INFO, + "ID_VIDEO_WIDTH=%d\n", mpctx->sh_video->disp_w); + mp_msg(MSGT_IDENTIFY, MSGL_INFO, + "ID_VIDEO_HEIGHT=%d\n", mpctx->sh_video->disp_h); + mp_msg(MSGT_IDENTIFY, MSGL_INFO, + "ID_VIDEO_FPS=%5.3f\n", mpctx->sh_video->fps); + mp_msg(MSGT_IDENTIFY, MSGL_INFO, + "ID_VIDEO_ASPECT=%1.4f\n", mpctx->sh_video->aspect); + video_start_pts = ds_get_next_pts(mpctx->d_video); + } + if (mpctx->sh_audio) { + /* Assume FOURCC if all bytes >= 0x20 (' ') */ + if (mpctx->sh_audio->format >= 0x20202020) + mp_msg(MSGT_IDENTIFY, MSGL_INFO, + "ID_AUDIO_FORMAT=%.4s\n", (char *)&mpctx->sh_audio->format); + else + mp_msg(MSGT_IDENTIFY, MSGL_INFO, + "ID_AUDIO_FORMAT=%d\n", mpctx->sh_audio->format); + mp_msg(MSGT_IDENTIFY, MSGL_INFO, + "ID_AUDIO_BITRATE=%d\n", mpctx->sh_audio->i_bps * 8); + mp_msg(MSGT_IDENTIFY, MSGL_INFO, + "ID_AUDIO_RATE=%d\n", mpctx->sh_audio->samplerate); + mp_msg(MSGT_IDENTIFY, MSGL_INFO, + "ID_AUDIO_NCH=%d\n", mpctx->sh_audio->channels); + start_pts = ds_get_next_pts(mpctx->d_audio); + } + if (video_start_pts != MP_NOPTS_VALUE) { + if (start_pts == MP_NOPTS_VALUE || !mpctx->sh_audio || + (mpctx->sh_video && video_start_pts < start_pts)) + start_pts = video_start_pts; + } + if (start_pts != MP_NOPTS_VALUE) + mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_START_TIME=%.2f\n", start_pts); else - mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_AUDIO_FORMAT=%d\n", mpctx->sh_audio->format); - mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_AUDIO_BITRATE=%d\n", mpctx->sh_audio->i_bps*8); - mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_AUDIO_RATE=%d\n", mpctx->sh_audio->samplerate); - mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_AUDIO_NCH=%d\n", mpctx->sh_audio->channels); - start_pts = ds_get_next_pts(mpctx->d_audio); - } - if (video_start_pts != MP_NOPTS_VALUE) { - if (start_pts == MP_NOPTS_VALUE || !mpctx->sh_audio || - (mpctx->sh_video && video_start_pts < start_pts)) - start_pts = video_start_pts; - } - if (start_pts != MP_NOPTS_VALUE) - mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_START_TIME=%.2f\n", start_pts); - else - mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_START_TIME=unknown\n"); - mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_LENGTH=%.2f\n", get_time_length(mpctx)); - mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_SEEKABLE=%d\n", - mpctx->stream->seek && (!mpctx->demuxer || mpctx->demuxer->seekable)); - if (mpctx->demuxer) { - if (mpctx->demuxer->num_chapters == 0) - stream_control(mpctx->demuxer->stream, STREAM_CTRL_GET_NUM_CHAPTERS, &mpctx->demuxer->num_chapters); - mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_CHAPTERS=%d\n", mpctx->demuxer->num_chapters); - } + mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_START_TIME=unknown\n"); + mp_msg(MSGT_IDENTIFY, MSGL_INFO, + "ID_LENGTH=%.2f\n", get_time_length(mpctx)); + mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_SEEKABLE=%d\n", + mpctx->stream->seek + && (!mpctx->demuxer || mpctx->demuxer->seekable)); + if (mpctx->demuxer) { + if (mpctx->demuxer->num_chapters == 0) + stream_control(mpctx->demuxer->stream, + STREAM_CTRL_GET_NUM_CHAPTERS, + &mpctx->demuxer->num_chapters); + mp_msg(MSGT_IDENTIFY, MSGL_INFO, + "ID_CHAPTERS=%d\n", mpctx->demuxer->num_chapters); + } } /// step size of mixer changes int volstep = 3; #ifdef CONFIG_DVDNAV -static void mp_dvdnav_context_free(MPContext *ctx){ - if (ctx->nav_smpi) free_mp_image(ctx->nav_smpi); +static void mp_dvdnav_context_free(MPContext *ctx) +{ + if (ctx->nav_smpi) + free_mp_image(ctx->nav_smpi); ctx->nav_smpi = NULL; free(ctx->nav_buffer); ctx->nav_buffer = NULL; @@ -600,199 +619,208 @@ static void uninit_subs(struct demuxer *demuxer) } } -void uninit_player(struct MPContext *mpctx, unsigned int mask){ - mask &= mpctx->initialized_flags; - - mp_msg(MSGT_CPLAYER,MSGL_DBG2,"\n*** uninit(0x%X)\n",mask); - - if(mask&INITIALIZED_ACODEC){ - mpctx->initialized_flags&=~INITIALIZED_ACODEC; - current_module="uninit_acodec"; - if(mpctx->sh_audio) uninit_audio(mpctx->sh_audio); - mpctx->sh_audio=NULL; - mpctx->mixer.afilter = NULL; - } - - if (mask & INITIALIZED_SUB) { - mpctx->initialized_flags &= ~INITIALIZED_SUB; - if (mpctx->d_sub->sh) - sub_switchoff(mpctx->d_sub->sh, mpctx->osd); - } - - if(mask&INITIALIZED_VCODEC){ - mpctx->initialized_flags&=~INITIALIZED_VCODEC; - current_module="uninit_vcodec"; - if(mpctx->sh_video) uninit_video(mpctx->sh_video); - mpctx->sh_video=NULL; +void uninit_player(struct MPContext *mpctx, unsigned int mask) +{ + mask &= mpctx->initialized_flags; + + mp_msg(MSGT_CPLAYER, MSGL_DBG2, "\n*** uninit(0x%X)\n", mask); + + if (mask & INITIALIZED_ACODEC) { + mpctx->initialized_flags &= ~INITIALIZED_ACODEC; + current_module = "uninit_acodec"; + if (mpctx->sh_audio) + uninit_audio(mpctx->sh_audio); + mpctx->sh_audio = NULL; + mpctx->mixer.afilter = NULL; + } + + if (mask & INITIALIZED_SUB) { + mpctx->initialized_flags &= ~INITIALIZED_SUB; + if (mpctx->d_sub->sh) + sub_switchoff(mpctx->d_sub->sh, mpctx->osd); + } + + if (mask & INITIALIZED_VCODEC) { + mpctx->initialized_flags &= ~INITIALIZED_VCODEC; + current_module = "uninit_vcodec"; + if (mpctx->sh_video) + uninit_video(mpctx->sh_video); + mpctx->sh_video = NULL; #ifdef CONFIG_MENU - vf_menu=NULL; + vf_menu = NULL; #endif - } - - if(mask&INITIALIZED_DEMUXER){ - mpctx->initialized_flags&=~INITIALIZED_DEMUXER; - current_module="free_demuxer"; - if (mpctx->num_sources) { - mpctx->demuxer = mpctx->sources[0].demuxer; - for (int i = 1; i < mpctx->num_sources; i++) { - uninit_subs(mpctx->sources[i].demuxer); - free_stream(mpctx->sources[i].stream); - free_demuxer(mpctx->sources[i].demuxer); + } + + if (mask & INITIALIZED_DEMUXER) { + mpctx->initialized_flags &= ~INITIALIZED_DEMUXER; + current_module = "free_demuxer"; + if (mpctx->num_sources) { + mpctx->demuxer = mpctx->sources[0].demuxer; + for (int i = 1; i < mpctx->num_sources; i++) { + uninit_subs(mpctx->sources[i].demuxer); + free_stream(mpctx->sources[i].stream); + free_demuxer(mpctx->sources[i].demuxer); + } } + talloc_free(mpctx->sources); + mpctx->sources = NULL; + mpctx->num_sources = 0; + talloc_free(mpctx->timeline); + mpctx->timeline = NULL; + mpctx->num_timeline_parts = 0; + talloc_free(mpctx->chapters); + mpctx->chapters = NULL; + mpctx->num_chapters = 0; + mpctx->video_offset = 0; + if (mpctx->demuxer) { + mpctx->stream = mpctx->demuxer->stream; + uninit_subs(mpctx->demuxer); + free_demuxer(mpctx->demuxer); + } + mpctx->demuxer = NULL; } - talloc_free(mpctx->sources); - mpctx->sources = NULL; - mpctx->num_sources = 0; - talloc_free(mpctx->timeline); - mpctx->timeline = NULL; - mpctx->num_timeline_parts = 0; - talloc_free(mpctx->chapters); - mpctx->chapters = NULL; - mpctx->num_chapters = 0; - mpctx->video_offset = 0; - if(mpctx->demuxer){ - mpctx->stream=mpctx->demuxer->stream; - uninit_subs(mpctx->demuxer); - free_demuxer(mpctx->demuxer); - } - mpctx->demuxer=NULL; - } - - // kill the cache process: - if(mask&INITIALIZED_STREAM){ - mpctx->initialized_flags&=~INITIALIZED_STREAM; - current_module="uninit_stream"; - if(mpctx->stream) free_stream(mpctx->stream); - mpctx->stream=NULL; - } - - if(mask&INITIALIZED_VO){ - mpctx->initialized_flags&=~INITIALIZED_VO; - current_module="uninit_vo"; - vo_destroy(mpctx->video_out); - mpctx->video_out=NULL; + + // kill the cache process: + if (mask & INITIALIZED_STREAM) { + mpctx->initialized_flags &= ~INITIALIZED_STREAM; + current_module = "uninit_stream"; + if (mpctx->stream) + free_stream(mpctx->stream); + mpctx->stream = NULL; + } + + if (mask & INITIALIZED_VO) { + mpctx->initialized_flags &= ~INITIALIZED_VO; + current_module = "uninit_vo"; + vo_destroy(mpctx->video_out); + mpctx->video_out = NULL; #ifdef CONFIG_DVDNAV - mp_dvdnav_context_free(mpctx); + mp_dvdnav_context_free(mpctx); #endif - } - - // Must be after libvo uninit, as few vo drivers (svgalib) have tty code. - if(mask&INITIALIZED_GETCH2){ - mpctx->initialized_flags&=~INITIALIZED_GETCH2; - current_module="uninit_getch2"; - mp_msg(MSGT_CPLAYER,MSGL_DBG2,"\n[[[uninit getch2]]]\n"); - // restore terminal: - getch2_disable(); - } - - if(mask&INITIALIZED_VOBSUB){ - mpctx->initialized_flags&=~INITIALIZED_VOBSUB; - current_module="uninit_vobsub"; - if(vo_vobsub) vobsub_close(vo_vobsub); - vo_vobsub=NULL; - } - - if (mask&INITIALIZED_SPUDEC){ - mpctx->initialized_flags&=~INITIALIZED_SPUDEC; - current_module="uninit_spudec"; - spudec_free(vo_spudec); - vo_spudec=NULL; - } - - if(mask&INITIALIZED_AO){ - mpctx->initialized_flags&=~INITIALIZED_AO; - current_module="uninit_ao"; - if (mpctx->edl_muted) mixer_mute(&mpctx->mixer); - if (mpctx->ao) - ao_uninit(mpctx->ao, mpctx->stop_play != AT_END_OF_FILE); - mpctx->ao = NULL; - } - - current_module=NULL; + } + + // Must be after libvo uninit, as few vo drivers (svgalib) have tty code. + if (mask & INITIALIZED_GETCH2) { + mpctx->initialized_flags &= ~INITIALIZED_GETCH2; + current_module = "uninit_getch2"; + mp_msg(MSGT_CPLAYER, MSGL_DBG2, "\n[[[uninit getch2]]]\n"); + // restore terminal: + getch2_disable(); + } + + if (mask & INITIALIZED_VOBSUB) { + mpctx->initialized_flags &= ~INITIALIZED_VOBSUB; + current_module = "uninit_vobsub"; + if (vo_vobsub) + vobsub_close(vo_vobsub); + vo_vobsub = NULL; + } + + if (mask & INITIALIZED_SPUDEC) { + mpctx->initialized_flags &= ~INITIALIZED_SPUDEC; + current_module = "uninit_spudec"; + spudec_free(vo_spudec); + vo_spudec = NULL; + } + + if (mask & INITIALIZED_AO) { + mpctx->initialized_flags &= ~INITIALIZED_AO; + current_module = "uninit_ao"; + if (mpctx->edl_muted) + mixer_mute(&mpctx->mixer); + if (mpctx->ao) + ao_uninit(mpctx->ao, mpctx->stop_play != AT_END_OF_FILE); + mpctx->ao = NULL; + } + + current_module = NULL; } void exit_player_with_rc(struct MPContext *mpctx, enum exit_reason how, int rc) { - if (mpctx->user_muted && !mpctx->edl_muted) mixer_mute(&mpctx->mixer); - uninit_player(mpctx, INITIALIZED_ALL); + if (mpctx->user_muted && !mpctx->edl_muted) + mixer_mute(&mpctx->mixer); + uninit_player(mpctx, INITIALIZED_ALL); #if defined(__MINGW32__) || defined(__CYGWIN__) - timeEndPeriod(1); + timeEndPeriod(1); #endif #ifdef CONFIG_X11 - vo_uninit(mpctx->x11_state); // Close the X11 connection (if any is open). + vo_uninit(mpctx->x11_state); // Close the X11 connection (if any is open). #endif - current_module="uninit_input"; + current_module = "uninit_input"; mp_input_uninit(mpctx->input); #ifdef CONFIG_MENU if (use_menu) - menu_uninit(); + menu_uninit(); #endif #ifdef CONFIG_FREETYPE - current_module="uninit_font"; - if (mpctx->osd && mpctx->osd->sub_font != vo_font) - free_font_desc(mpctx->osd->sub_font); - free_font_desc(vo_font); - vo_font = NULL; - done_freetype(); + current_module = "uninit_font"; + if (mpctx->osd && mpctx->osd->sub_font != vo_font) + free_font_desc(mpctx->osd->sub_font); + free_font_desc(vo_font); + vo_font = NULL; + done_freetype(); #endif - osd_free(mpctx->osd); + osd_free(mpctx->osd); #ifdef CONFIG_ASS - ass_library_done(mpctx->ass_library); - mpctx->ass_library = NULL; + ass_library_done(mpctx->ass_library); + mpctx->ass_library = NULL; #endif - current_module="exit_player"; - - if(mpctx->playtree_iter) - play_tree_iter_free(mpctx->playtree_iter); - mpctx->playtree_iter = NULL; - if(mpctx->playtree) - play_tree_free(mpctx->playtree, 1); - mpctx->playtree = NULL; - - talloc_free(mpctx->key_fifo); - - free(edl_records); // free mem allocated for EDL - edl_records = NULL; - switch(how) { - case EXIT_QUIT: - mp_tmsg(MSGT_CPLAYER,MSGL_INFO,"\nExiting... (%s)\n","Quit"); - mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_EXIT=QUIT\n"); - break; - case EXIT_EOF: - mp_tmsg(MSGT_CPLAYER,MSGL_INFO,"\nExiting... (%s)\n","End of file"); - mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_EXIT=EOF\n"); - break; - case EXIT_ERROR: - mp_tmsg(MSGT_CPLAYER,MSGL_INFO,"\nExiting... (%s)\n","Fatal error"); - mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_EXIT=ERROR\n"); - break; - default: - mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_EXIT=NONE\n"); - } - mp_msg(MSGT_CPLAYER,MSGL_DBG2,"max framesize was %d bytes\n",max_framesize); - - // must be last since e.g. mp_msg uses option values - // that will be freed by this. - if (mpctx->mconfig) - m_config_free(mpctx->mconfig); - mpctx->mconfig = NULL; - - exit(rc); + current_module = "exit_player"; + + if (mpctx->playtree_iter) + play_tree_iter_free(mpctx->playtree_iter); + mpctx->playtree_iter = NULL; + if (mpctx->playtree) + play_tree_free(mpctx->playtree, 1); + mpctx->playtree = NULL; + + talloc_free(mpctx->key_fifo); + + free(edl_records); // free mem allocated for EDL + edl_records = NULL; + switch (how) { + case EXIT_QUIT: + mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "\nExiting... (%s)\n", "Quit"); + mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_EXIT=QUIT\n"); + break; + case EXIT_EOF: + mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "\nExiting... (%s)\n", "End of file"); + mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_EXIT=EOF\n"); + break; + case EXIT_ERROR: + mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "\nExiting... (%s)\n", "Fatal error"); + mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_EXIT=ERROR\n"); + break; + default: + mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_EXIT=NONE\n"); + } + mp_msg(MSGT_CPLAYER, MSGL_DBG2, + "max framesize was %d bytes\n", max_framesize); + + // must be last since e.g. mp_msg uses option values + // that will be freed by this. + if (mpctx->mconfig) + m_config_free(mpctx->mconfig); + mpctx->mconfig = NULL; + + exit(rc); } static void exit_player(struct MPContext *mpctx, enum exit_reason how) { - exit_player_with_rc(mpctx, how, 1); + exit_player_with_rc(mpctx, how, 1); } #ifndef __MINGW32__ -static void child_sighandler(int x){ - pid_t pid; - while((pid=waitpid(-1,NULL,WNOHANG)) > 0); +static void child_sighandler(int x) +{ + pid_t pid; + while ((pid = waitpid(-1, NULL, WNOHANG)) > 0) ; } #endif @@ -801,76 +829,77 @@ static char *prog_path; static int crash_debug = 0; #endif -static void exit_sighandler(int x){ - static int sig_count=0; +static void exit_sighandler(int x) +{ + static int sig_count = 0; #ifdef CONFIG_CRASH_DEBUG - if (!crash_debug || x != SIGTRAP) + if (!crash_debug || x != SIGTRAP) #endif - ++sig_count; - 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 :( + ++sig_count; + 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); + kill(getpid(), SIGKILL); #endif - } - mp_msg(MSGT_CPLAYER, MSGL_FATAL, "\n"); - mp_tmsg(MSGT_CPLAYER,MSGL_FATAL, - "\nMPlayer interrupted by signal %d in module: %s\n", 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 SIGPIPE: - case SIGQUIT: - case SIGTERM: - case SIGKILL: - async_quit_request = 1; - return; // killed from keyboard (^C) or killed [-9] - case SIGILL: + } + mp_msg(MSGT_CPLAYER, MSGL_FATAL, "\n"); + mp_tmsg(MSGT_CPLAYER, MSGL_FATAL, + "\nMPlayer interrupted by signal %d in module: %s\n", 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 SIGPIPE: + case SIGQUIT: + case SIGTERM: + case SIGKILL: + async_quit_request = 1; + return; // killed from keyboard (^C) or killed [-9] + case SIGILL: #if CONFIG_RUNTIME_CPUDETECT - mp_tmsg(MSGT_CPLAYER,MSGL_FATAL,Exit_SIGILL_RTCpuSel); + mp_tmsg(MSGT_CPLAYER, MSGL_FATAL, Exit_SIGILL_RTCpuSel); #else - mp_tmsg(MSGT_CPLAYER,MSGL_FATAL,Exit_SIGILL); + mp_tmsg(MSGT_CPLAYER, MSGL_FATAL, Exit_SIGILL); #endif - case SIGFPE: - case SIGSEGV: - mp_tmsg(MSGT_CPLAYER,MSGL_FATAL,Exit_SIGSEGV_SIGFPE); - default: - mp_tmsg(MSGT_CPLAYER,MSGL_FATAL,Exit_SIGCRASH); + case SIGFPE: + case SIGSEGV: + mp_tmsg(MSGT_CPLAYER, MSGL_FATAL, Exit_SIGSEGV_SIGFPE); + default: + mp_tmsg(MSGT_CPLAYER, MSGL_FATAL, Exit_SIGCRASH); #ifdef CONFIG_CRASH_DEBUG - if (crash_debug) { - int gdb_pid; - 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 - char spid[20]; - snprintf(spid, sizeof(spid), "%i", getppid()); - getch2_disable(); // allow terminal to work properly with gdb - if (execlp("gdb", "gdb", prog_path, spid, "-ex", "bt", 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; - } + if (crash_debug) { + int gdb_pid; + 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 + char spid[20]; + snprintf(spid, sizeof(spid), "%i", getppid()); + getch2_disable(); // allow terminal to work properly with gdb + if (execlp("gdb", "gdb", prog_path, spid, "-ex", "bt", 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 - } - getch2_disable(); - exit(1); + } + getch2_disable(); + exit(1); } #include "cfg-mplayer.h" @@ -882,99 +911,101 @@ static int cfg_include(m_option_t *conf, char *filename) #define DEF_CONFIG "# Write your default config options here!\n\n\n" -static void parse_cfgfiles(struct MPContext *mpctx, m_config_t* conf) +static void parse_cfgfiles(struct MPContext *mpctx, m_config_t *conf) { struct MPOpts *opts = &mpctx->opts; -char *conffile; -int conffile_fd; - if (!(opts->noconfig & 2) && - m_config_parse_config_file(conf, MPLAYER_CONFDIR "/mplayer.conf") < 0) - exit_player(mpctx, EXIT_NONE); -if ((conffile = get_path("")) == NULL) { - mp_tmsg(MSGT_CPLAYER,MSGL_WARN,"Cannot find HOME directory.\n"); -} else { + char *conffile; + int conffile_fd; + if (!(opts->noconfig & 2) && + m_config_parse_config_file(conf, MPLAYER_CONFDIR "/mplayer.conf") < 0) + exit_player(mpctx, EXIT_NONE); + if ((conffile = get_path("")) == NULL) + mp_tmsg(MSGT_CPLAYER, MSGL_WARN, "Cannot find HOME directory.\n"); + else { #ifdef __MINGW32__ - mkdir(conffile); + mkdir(conffile); #else - mkdir(conffile, 0777); + mkdir(conffile, 0777); #endif - free(conffile); - if ((conffile = get_path("config")) == NULL) { - mp_tmsg(MSGT_CPLAYER,MSGL_ERR,"get_path(\"config\") problem\n"); - } else { - if ((conffile_fd = open(conffile, O_CREAT | O_EXCL | O_WRONLY, 0666)) != -1) { - mp_tmsg(MSGT_CPLAYER,MSGL_INFO,"Creating config file: %s\n", conffile); - write(conffile_fd, DEF_CONFIG, sizeof(DEF_CONFIG) - 1); - close(conffile_fd); - } - if (!(opts->noconfig & 1) && - m_config_parse_config_file(conf, conffile) < 0) - exit_player(mpctx, EXIT_NONE); - free(conffile); - } -} + free(conffile); + if ((conffile = get_path("config")) == NULL) + mp_tmsg(MSGT_CPLAYER, MSGL_ERR, "get_path(\"config\") problem\n"); + else { + if ((conffile_fd = open(conffile, O_CREAT | O_EXCL | O_WRONLY, + 0666)) != -1) { + mp_tmsg(MSGT_CPLAYER, MSGL_INFO, + "Creating config file: %s\n", conffile); + write(conffile_fd, DEF_CONFIG, sizeof(DEF_CONFIG) - 1); + close(conffile_fd); + } + if (!(opts->noconfig & 1) && + m_config_parse_config_file(conf, conffile) < 0) + exit_player(mpctx, EXIT_NONE); + free(conffile); + } + } } #define PROFILE_CFG_PROTOCOL "protocol." -static void load_per_protocol_config (m_config_t* conf, const char *const file) +static void load_per_protocol_config(m_config_t *conf, const char * const file) { char *str; - char protocol[strlen (PROFILE_CFG_PROTOCOL) + strlen (file) + 1]; + char protocol[strlen(PROFILE_CFG_PROTOCOL) + strlen(file) + 1]; m_profile_t *p; /* does filename actually uses a protocol ? */ - str = strstr (file, "://"); + str = strstr(file, "://"); if (!str) return; - sprintf (protocol, "%s%s", PROFILE_CFG_PROTOCOL, file); - protocol[strlen (PROFILE_CFG_PROTOCOL)+strlen(file)-strlen(str)] = '\0'; - p = m_config_get_profile (conf, protocol); - if (p) - { - mp_tmsg(MSGT_CPLAYER,MSGL_INFO,"Loading protocol-related profile '%s'\n", protocol); - m_config_set_profile(conf,p); + sprintf(protocol, "%s%s", PROFILE_CFG_PROTOCOL, file); + protocol[strlen(PROFILE_CFG_PROTOCOL) + strlen(file) - strlen(str)] = '\0'; + p = m_config_get_profile(conf, protocol); + if (p) { + mp_tmsg(MSGT_CPLAYER, MSGL_INFO, + "Loading protocol-related profile '%s'\n", protocol); + m_config_set_profile(conf, p); } } #define PROFILE_CFG_EXTENSION "extension." -static void load_per_extension_config (m_config_t* conf, const char *const file) +static void load_per_extension_config(m_config_t *conf, const char * const file) { char *str; - char extension[strlen (PROFILE_CFG_EXTENSION) + 8]; + char extension[strlen(PROFILE_CFG_EXTENSION) + 8]; m_profile_t *p; /* does filename actually have an extension ? */ - str = strrchr (file, '.'); + str = strrchr(file, '.'); if (!str) return; - sprintf (extension, PROFILE_CFG_EXTENSION); - strncat (extension, ++str, 7); - p = m_config_get_profile (conf, extension); - if (p) - { - mp_tmsg(MSGT_CPLAYER,MSGL_INFO,"Loading extension-related profile '%s'\n", extension); - m_config_set_profile(conf,p); + sprintf(extension, PROFILE_CFG_EXTENSION); + strncat(extension, ++str, 7); + p = m_config_get_profile(conf, extension); + if (p) { + mp_tmsg(MSGT_CPLAYER, MSGL_INFO, + "Loading extension-related profile '%s'\n", extension); + m_config_set_profile(conf, p); } } #define PROFILE_CFG_VO "vo." #define PROFILE_CFG_AO "ao." -static void load_per_output_config (m_config_t* conf, char *cfg, char *out) +static void load_per_output_config(m_config_t *conf, char *cfg, char *out) { - char profile[strlen (cfg) + strlen (out) + 1]; + char profile[strlen(cfg) + strlen(out) + 1]; m_profile_t *p; - sprintf (profile, "%s%s", cfg, out); - p = m_config_get_profile (conf, profile); - if (p) - { - mp_tmsg(MSGT_CPLAYER,MSGL_INFO,"Loading extension-related profile '%s'\n", profile); - m_config_set_profile(conf,p); + sprintf(profile, "%s%s", cfg, out); + p = m_config_get_profile(conf, profile); + if (p) { + mp_tmsg(MSGT_CPLAYER, MSGL_INFO, + "Loading extension-related profile '%s'\n", profile); + m_config_set_profile(conf, p); } } @@ -988,21 +1019,22 @@ static int try_load_config(m_config_t *conf, const char *file) if (stat(file, &st)) return 0; mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "Loading config '%s'\n", file); - m_config_parse_config_file (conf, file); + m_config_parse_config_file(conf, file); return 1; } -static void load_per_file_config (m_config_t* conf, const char *const file) +static void load_per_file_config(m_config_t *conf, const char * const file) { char *confpath; char cfg[PATH_MAX]; const char *name; if (strlen(file) > PATH_MAX - 14) { - mp_msg(MSGT_CPLAYER, MSGL_WARN, "Filename is too long, can not load file or directory specific config files\n"); + mp_msg(MSGT_CPLAYER, MSGL_WARN, "Filename is too long, " + "can not load file or directory specific config files\n"); return; } - sprintf (cfg, "%s.conf", file); + sprintf(cfg, "%s.conf", file); name = mp_basename(cfg); if (use_filedir_conf) { @@ -1015,11 +1047,10 @@ static void load_per_file_config (m_config_t* conf, const char *const file) return; } - if ((confpath = get_path (name)) != NULL) - { - try_load_config(conf, confpath); + if ((confpath = get_path(name)) != NULL) { + try_load_config(conf, confpath); - free (confpath); + free(confpath); } } @@ -1029,57 +1060,60 @@ static void load_per_file_config (m_config_t* conf, const char *const file) * The function returns a new value for eof. */ static int libmpdemux_was_interrupted(struct MPContext *mpctx, int stop_play) { - mp_cmd_t* cmd; - if((cmd = mp_input_get_cmd(mpctx->input, 0, 0)) != NULL) { - switch(cmd->id) { - case MP_CMD_QUIT: - exit_player_with_rc(mpctx, EXIT_QUIT, (cmd->nargs > 0)? cmd->args[0].v.i : 0); - case MP_CMD_PLAY_TREE_STEP: { - stop_play = (cmd->args[0].v.i > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY; - mpctx->play_tree_step = (cmd->args[0].v.i == 0) ? 1 : cmd->args[0].v.i; - } break; - case MP_CMD_PLAY_TREE_UP_STEP: { - stop_play = (cmd->args[0].v.i > 0) ? PT_UP_NEXT : PT_UP_PREV; - } break; - case MP_CMD_PLAY_ALT_SRC_STEP: { - stop_play = (cmd->args[0].v.i > 0) ? PT_NEXT_SRC : PT_PREV_SRC; - } break; - } - mp_cmd_free(cmd); - } - return stop_play; + mp_cmd_t *cmd; + if ((cmd = mp_input_get_cmd(mpctx->input, 0, 0)) != NULL) { + switch (cmd->id) { + case MP_CMD_QUIT: + exit_player_with_rc(mpctx, EXIT_QUIT, + (cmd->nargs > 0) ? cmd->args[0].v.i : 0); + case MP_CMD_PLAY_TREE_STEP: { + stop_play = (cmd->args[0].v.i > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY; + mpctx->play_tree_step = + (cmd->args[0].v.i == 0) ? 1 : cmd->args[0].v.i; + } break; + case MP_CMD_PLAY_TREE_UP_STEP: { + stop_play = (cmd->args[0].v.i > 0) ? PT_UP_NEXT : PT_UP_PREV; + } break; + case MP_CMD_PLAY_ALT_SRC_STEP: { + stop_play = (cmd->args[0].v.i > 0) ? PT_NEXT_SRC : PT_PREV_SRC; + } break; + } + mp_cmd_free(cmd); + } + return stop_play; } -static int playtree_add_playlist(struct MPContext *mpctx, play_tree_t* entry) +static int playtree_add_playlist(struct MPContext *mpctx, play_tree_t *entry) { play_tree_add_bpf(entry, bstr(mpctx->filename)); - { - if(!entry) { - entry = mpctx->playtree_iter->tree; - if(play_tree_iter_step(mpctx->playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) { - return PT_NEXT_ENTRY; - } - if(mpctx->playtree_iter->tree == entry ) { // Loop with a single file - if(play_tree_iter_up_step(mpctx->playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) { - return PT_NEXT_ENTRY; - } + { + if (!entry) { + entry = mpctx->playtree_iter->tree; + if (play_tree_iter_step(mpctx->playtree_iter, 1, 0) + != PLAY_TREE_ITER_ENTRY) + return PT_NEXT_ENTRY; + if (mpctx->playtree_iter->tree == entry) { // Single file loop + if (play_tree_iter_up_step(mpctx->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(mpctx->playtree_iter->tree, entry); + play_tree_set_params_from(entry, mpctx->playtree_iter->tree); + entry = mpctx->playtree_iter->tree; + if (play_tree_iter_step(mpctx->playtree_iter, 1, 0) + != PLAY_TREE_ITER_ENTRY) + return PT_NEXT_ENTRY; + play_tree_remove(entry, 1, 1); } - play_tree_remove(entry,1,1); return PT_NEXT_SRC; - } - play_tree_insert_entry(mpctx->playtree_iter->tree,entry); - play_tree_set_params_from(entry,mpctx->playtree_iter->tree); - entry = mpctx->playtree_iter->tree; - if(play_tree_iter_step(mpctx->playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) { - return PT_NEXT_ENTRY; - } - play_tree_remove(entry,1,1); - } - return PT_NEXT_SRC; } -void add_subtitles(struct MPContext *mpctx, char *filename, float fps, int noerr) +void add_subtitles(struct MPContext *mpctx, char *filename, float fps, + int noerr) { struct MPOpts *opts = &mpctx->opts; sub_data *subd = NULL; @@ -1087,7 +1121,7 @@ void add_subtitles(struct MPContext *mpctx, char *filename, float fps, int noerr bool is_native_ass = false; if (filename == NULL || mpctx->set_of_sub_size >= MAX_SUBTITLE_FILES) - return; + return; #ifdef CONFIG_ASS if (opts->ass_enabled) { @@ -1107,7 +1141,7 @@ void add_subtitles(struct MPContext *mpctx, char *filename, float fps, int noerr } } else #endif - subd = sub_read_file(filename, fps, &mpctx->opts); + subd = sub_read_file(filename, fps, &mpctx->opts); if (!asst && !subd) { @@ -1119,63 +1153,66 @@ void add_subtitles(struct MPContext *mpctx, char *filename, float fps, int noerr mpctx->set_of_ass_tracks[mpctx->set_of_sub_size] = asst; mpctx->set_of_subtitles[mpctx->set_of_sub_size] = subd; mpctx->track_was_native_ass[mpctx->set_of_sub_size] = is_native_ass; - mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_FILE_SUB_ID=%d\n", mpctx->set_of_sub_size); + mp_msg(MSGT_IDENTIFY, MSGL_INFO, + "ID_FILE_SUB_ID=%d\n", mpctx->set_of_sub_size); mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_FILE_SUB_FILENAME=%s\n", - filename_recode(filename)); + filename_recode(filename)); ++mpctx->set_of_sub_size; - mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "SUB: Added subtitle file (%d): %s\n", mpctx->set_of_sub_size, - filename_recode(filename)); + mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "SUB: Added subtitle file (%d): %s\n", + mpctx->set_of_sub_size, filename_recode(filename)); } void init_vo_spudec(struct MPContext *mpctx) { - unsigned width, height; - spudec_free(vo_spudec); - mpctx->initialized_flags &= ~INITIALIZED_SPUDEC; - vo_spudec = NULL; + unsigned width, height; + spudec_free(vo_spudec); + mpctx->initialized_flags &= ~INITIALIZED_SPUDEC; + vo_spudec = NULL; - // we currently can't work without video stream - if (!mpctx->sh_video) - return; + // we currently can't work without video stream + if (!mpctx->sh_video) + return; - if (spudec_ifo) { - unsigned int palette[16]; - current_module="spudec_init_vobsub"; - if (vobsub_parse_ifo(NULL,spudec_ifo, palette, &width, &height, 1, -1, NULL) >= 0) - vo_spudec=spudec_new_scaled(palette, width, height, NULL, 0); - } + if (spudec_ifo) { + unsigned int palette[16]; + current_module = "spudec_init_vobsub"; + if (vobsub_parse_ifo(NULL, spudec_ifo, palette, &width, &height, + 1, -1, NULL) >= 0) + vo_spudec = spudec_new_scaled(palette, width, height, NULL, 0); + } width = mpctx->sh_video->disp_w; height = mpctx->sh_video->disp_h; #ifdef CONFIG_DVDREAD - if (vo_spudec==NULL && mpctx->stream->type==STREAMTYPE_DVD) { - current_module="spudec_init_dvdread"; - vo_spudec=spudec_new_scaled(((dvd_priv_t *)(mpctx->stream->priv))->cur_pgc->palette, - width, height, - NULL, 0); - } + if (vo_spudec == NULL && mpctx->stream->type == STREAMTYPE_DVD) { + current_module = "spudec_init_dvdread"; + vo_spudec = spudec_new_scaled(((dvd_priv_t *)(mpctx->stream->priv))-> + cur_pgc->palette, width, height, NULL, 0); + } #endif #ifdef CONFIG_DVDNAV - if (vo_spudec==NULL && mpctx->stream->type==STREAMTYPE_DVDNAV) { - unsigned int *palette = mp_dvdnav_get_spu_clut(mpctx->stream); - current_module="spudec_init_dvdnav"; - vo_spudec=spudec_new_scaled(palette, width, height, NULL, 0); - } + if (vo_spudec == NULL && mpctx->stream->type == STREAMTYPE_DVDNAV) { + unsigned int *palette = mp_dvdnav_get_spu_clut(mpctx->stream); + current_module = "spudec_init_dvdnav"; + vo_spudec = spudec_new_scaled(palette, width, height, NULL, 0); + } #endif - if (vo_spudec==NULL) { - sh_sub_t *sh = mpctx->d_sub->sh; - current_module="spudec_init_normal"; - vo_spudec=spudec_new_scaled(NULL, width, height, sh->extradata, sh->extradata_len); - spudec_set_font_factor(vo_spudec,font_factor); - } - - if (vo_spudec!=NULL) { - mpctx->initialized_flags|=INITIALIZED_SPUDEC; - mp_property_do("sub_forced_only", M_PROPERTY_SET, &forced_subs_only, mpctx); - } + if (vo_spudec == NULL) { + sh_sub_t *sh = mpctx->d_sub->sh; + current_module = "spudec_init_normal"; + vo_spudec = spudec_new_scaled(NULL, width, height, sh->extradata, + sh->extradata_len); + spudec_set_font_factor(vo_spudec, font_factor); + } + + if (vo_spudec != NULL) { + mpctx->initialized_flags |= INITIALIZED_SPUDEC; + mp_property_do("sub_forced_only", M_PROPERTY_SET, &forced_subs_only, + mpctx); + } } /* @@ -1200,14 +1237,14 @@ void init_vo_spudec(struct MPContext *mpctx) */ 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; - } + 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; + } } /** @@ -1217,130 +1254,133 @@ static void saddf(char *buf, unsigned *pos, int len, const char *format, ...) * \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) { - int64_t 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); +static void sadd_hhmmssf(char *buf, unsigned *pos, int len, float time) +{ + int64_t 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); } static void print_status(struct MPContext *mpctx, double a_pos, bool at_frame) { struct MPOpts *opts = &mpctx->opts; - sh_video_t * const sh_video = mpctx->sh_video; - - if (mpctx->sh_audio && a_pos == MP_NOPTS_VALUE) - a_pos = playing_audio_pts(mpctx); - if (mpctx->sh_audio && sh_video && at_frame) { - mpctx->last_av_difference = a_pos - mpctx->video_pts - audio_delay; - if (mpctx->time_frame > 0) - mpctx->last_av_difference += mpctx->time_frame * opts->playback_speed; - if (mpctx->last_av_difference > 0.5 && drop_frame_cnt > 50 - && !mpctx->drop_message_shown) { - mp_tmsg(MSGT_AVSYNC,MSGL_WARN,SystemTooSlow); - mpctx->drop_message_shown = true; - } - } - if (opts->quiet) - return; - - if (a_pos == MP_NOPTS_VALUE) - a_pos = -9; // don't print a huge negative number - - int width; - char *line; - unsigned pos = 0; - get_screen_size(); - if (screen_width > 0) - width = screen_width; - else - width = 80; + sh_video_t * const sh_video = mpctx->sh_video; + + if (mpctx->sh_audio && a_pos == MP_NOPTS_VALUE) + a_pos = playing_audio_pts(mpctx); + if (mpctx->sh_audio && sh_video && at_frame) { + mpctx->last_av_difference = a_pos - mpctx->video_pts - audio_delay; + if (mpctx->time_frame > 0) + mpctx->last_av_difference += + mpctx->time_frame * opts->playback_speed; + if (mpctx->last_av_difference > 0.5 && drop_frame_cnt > 50 + && !mpctx->drop_message_shown) { + mp_tmsg(MSGT_AVSYNC, MSGL_WARN, SystemTooSlow); + mpctx->drop_message_shown = true; + } + } + if (opts->quiet) + return; + + if (a_pos == MP_NOPTS_VALUE) + a_pos = -9; // don't print a huge negative number + + int width; + char *line; + unsigned pos = 0; + get_screen_size(); + if (screen_width > 0) + width = screen_width; + else + width = 80; #if defined(__MINGW32__) || defined(__CYGWIN__) || defined(__OS2__) - /* Windows command line is broken (MinGW's rxvt works, but we - * should not depend on that). */ - width--; + /* 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 (mpctx->sh_audio) { - saddf(line, &pos, width, "A:%6.1f ", a_pos); - if (!sh_video) { - float len = get_time_length(mpctx); - saddf(line, &pos, width, "("); - sadd_hhmmssf(line, &pos, width, a_pos); - saddf(line, &pos, width, ") of %.1f (", len); - sadd_hhmmssf(line, &pos, width, len); - saddf(line, &pos, width, ") "); - } - } - - // Video time - if (sh_video) - saddf(line, &pos, width, "V:%6.1f ", mpctx->video_pts); - - // A-V sync - if (mpctx->sh_audio && sh_video) - saddf(line, &pos, width, "A-V:%7.3f ct:%7.3f ", - mpctx->last_av_difference, mpctx->total_avsync_change); - - // 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*opts->playback_speed/(double)sh_video->timer), - (int)(100.0*vout_time_usage*opts->playback_speed/(double)sh_video->timer), - (100.0*audio_time_usage*opts->playback_speed/(double)sh_video->timer)); - else - saddf(line, &pos, width, "??%% ??%% ??,?%% "); - } else if (mpctx->sh_audio) { - if (mpctx->delay > 0.5) - saddf(line, &pos, width, "%4.1f%% ", - 100.0*audio_time_usage/(double)mpctx->delay); - else - saddf(line, &pos, width, "??,?%% "); - } + line = malloc(width + 1); // one additional char for the terminating null + + // Audio time + if (mpctx->sh_audio) { + saddf(line, &pos, width, "A:%6.1f ", a_pos); + if (!sh_video) { + float len = get_time_length(mpctx); + saddf(line, &pos, width, "("); + sadd_hhmmssf(line, &pos, width, a_pos); + saddf(line, &pos, width, ") of %.1f (", len); + sadd_hhmmssf(line, &pos, width, len); + saddf(line, &pos, width, ") "); + } + } + + // Video time + if (sh_video) + saddf(line, &pos, width, "V:%6.1f ", mpctx->video_pts); - // VO stats - if (sh_video) - saddf(line, &pos, width, "%d %d ", drop_frame_cnt, output_quality); + // A-V sync + if (mpctx->sh_audio && sh_video) + saddf(line, &pos, width, "A-V:%7.3f ct:%7.3f ", + mpctx->last_av_difference, mpctx->total_avsync_change); + + // 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 * opts->playback_speed / (double)sh_video->timer), + (int)(100.0 * vout_time_usage * opts->playback_speed / (double)sh_video->timer), + (100.0 * audio_time_usage * opts->playback_speed / (double)sh_video->timer)); + else + saddf(line, &pos, width, "??%% ??%% ??,?%% "); + } else if (mpctx->sh_audio) { + if (mpctx->delay > 0.5) + saddf(line, &pos, width, "%4.1f%% ", + 100.0 * audio_time_usage / (double)mpctx->delay); + else + saddf(line, &pos, width, "??,?%% "); + } + + // VO stats + if (sh_video) + saddf(line, &pos, width, "%d %d ", drop_frame_cnt, output_quality); #ifdef CONFIG_STREAM_CACHE - // cache stats - if (stream_cache_size > 0) - saddf(line, &pos, width, "%d%% ", cache_fill_status(mpctx->stream)); + // cache stats + if (stream_cache_size > 0) + saddf(line, &pos, width, "%d%% ", cache_fill_status(mpctx->stream)); #endif - // other - if (opts->playback_speed != 1) - saddf(line, &pos, width, "%4.2fx ", opts->playback_speed); - - // end - if (erase_to_end_of_line) { - line[pos] = 0; - mp_msg(MSGT_STATUSLINE, MSGL_STATUS, "%s%s\r", line, erase_to_end_of_line); - } else { - memset(&line[pos], ' ', width - pos); - line[width] = 0; - mp_msg(MSGT_STATUSLINE, MSGL_STATUS, "%s\r", line); - } - free(line); + // other + if (opts->playback_speed != 1) + saddf(line, &pos, width, "%4.2fx ", opts->playback_speed); + + // end + if (erase_to_end_of_line) { + line[pos] = 0; + mp_msg(MSGT_STATUSLINE, MSGL_STATUS, + "%s%s\r", line, erase_to_end_of_line); + } else { + memset(&line[pos], ' ', width - pos); + line[width] = 0; + mp_msg(MSGT_STATUSLINE, MSGL_STATUS, "%s\r", line); + } + free(line); } struct stream_dump_progress { @@ -1371,19 +1411,19 @@ static void stream_dump_progress(struct stream_dump_progress *p, /* TODO: pretty print sizes; ETA */ if (end > start && pos >= start && pos <= end) { mp_tmsg(MSGT_STATUSLINE, MSGL_STATUS, - "dump: %"PRIu64" bytes written (~%.1f%%)", - p->count, 100.0 * (pos - start) / (end - start)); + "dump: %"PRIu64 " bytes written (~%.1f%%)", + p->count, 100.0 * (pos - start) / (end - start)); mp_msg(MSGT_STATUSLINE, MSGL_STATUS, "\r"); } else { mp_tmsg(MSGT_STATUSLINE, MSGL_STATUS, - "dump: %"PRIu64" bytes written", p->count); + "dump: %"PRIu64 " bytes written", p->count); mp_msg(MSGT_STATUSLINE, MSGL_STATUS, "\r"); } } static void stream_dump_progress_end(struct stream_dump_progress *p, char *name) { - mp_msg(MSGT_CPLAYER, MSGL_INFO, "dump: %"PRIu64" bytes written to '%s'.\n", + mp_msg(MSGT_CPLAYER, MSGL_INFO, "dump: %"PRIu64 " bytes written to '%s'.\n", p->count, name); } @@ -1398,48 +1438,47 @@ static int build_afilter_chain(struct MPContext *mpctx) struct sh_audio *sh_audio = mpctx->sh_audio; struct ao *ao = mpctx->ao; struct MPOpts *opts = &mpctx->opts; - int new_srate; - int result; - if (!sh_audio) - { - mpctx->mixer.afilter = NULL; - return 0; - } - if(af_control_any_rev(sh_audio->afilter, - AF_CONTROL_PLAYBACK_SPEED | AF_CONTROL_SET, - &opts->playback_speed)) { - new_srate = sh_audio->samplerate; - } else { - new_srate = sh_audio->samplerate * opts->playback_speed; - if (new_srate != ao->samplerate) { - // limits are taken from libaf/af_resample.c - if (new_srate < 8000) - new_srate = 8000; - if (new_srate > 192000) - new_srate = 192000; - opts->playback_speed = (float)new_srate / (float)sh_audio->samplerate; - } - } - result = init_audio_filters(sh_audio, new_srate, - &ao->samplerate, &ao->channels, &ao->format); - mpctx->mixer.afilter = sh_audio->afilter; - return result; + int new_srate; + int result; + if (!sh_audio) { + mpctx->mixer.afilter = NULL; + return 0; + } + if (af_control_any_rev(sh_audio->afilter, + AF_CONTROL_PLAYBACK_SPEED | AF_CONTROL_SET, + &opts->playback_speed)) + new_srate = sh_audio->samplerate; + else { + new_srate = sh_audio->samplerate * opts->playback_speed; + if (new_srate != ao->samplerate) { + // limits are taken from libaf/af_resample.c + if (new_srate < 8000) + new_srate = 8000; + if (new_srate > 192000) + new_srate = 192000; + opts->playback_speed = (float)new_srate / sh_audio->samplerate; + } + } + result = init_audio_filters(sh_audio, new_srate, + &ao->samplerate, &ao->channels, &ao->format); + mpctx->mixer.afilter = sh_audio->afilter; + return result; } typedef struct mp_osd_msg mp_osd_msg_t; struct mp_osd_msg { /// Previous message on the stack. - mp_osd_msg_t* prev; + mp_osd_msg_t *prev; /// Message text. char msg[128]; - int id,level,started; + int id, level, started; /// Display duration in ms. - unsigned time; + unsigned time; }; /// OSD message stack. -static mp_osd_msg_t* osd_msg_stack = NULL; +static mp_osd_msg_t *osd_msg_stack = NULL; /** * \brief Add a message on the OSD message stack @@ -1451,25 +1490,26 @@ static mp_osd_msg_t* osd_msg_stack = NULL; static void set_osd_msg_va(int id, int level, int time, const char *fmt, va_list ap) { - mp_osd_msg_t *msg,*last=NULL; + mp_osd_msg_t *msg, *last = NULL; int r; // look if the id is already in the stack - for(msg = osd_msg_stack ; msg && msg->id != id ; - last = msg, msg = msg->prev); + for (msg = osd_msg_stack; msg && msg->id != id; + last = msg, msg = msg->prev) ; // not found: alloc it - if(!msg) { - msg = calloc(1,sizeof(mp_osd_msg_t)); + if (!msg) { + msg = calloc(1, sizeof(mp_osd_msg_t)); msg->prev = osd_msg_stack; osd_msg_stack = msg; - } else if(last) { // found, but it's not on top of the stack + } else if (last) { // found, but it's not on top of the stack last->prev = msg->prev; msg->prev = osd_msg_stack; osd_msg_stack = msg; } // write the msg r = vsnprintf(msg->msg, 128, fmt, ap); - if(r >= 128) msg->msg[127] = 0; + if (r >= 128) + msg->msg[127] = 0; // set id and time msg->id = id; msg->level = level; @@ -1501,16 +1541,18 @@ void set_osd_tmsg(int id, int level, int time, const char *fmt, ...) * */ -void rm_osd_msg(int id) { - mp_osd_msg_t *msg,*last=NULL; +void rm_osd_msg(int id) +{ + mp_osd_msg_t *msg, *last = NULL; // Search for the msg - for(msg = osd_msg_stack ; msg && msg->id != id ; - last = msg, msg = msg->prev); - if(!msg) return; + for (msg = osd_msg_stack; msg && msg->id != id; + last = msg, msg = msg->prev) ; + if (!msg) + return; // Detach it from the stack and free it - if(last) + if (last) last->prev = msg->prev; else osd_msg_stack = msg->prev; @@ -1522,9 +1564,10 @@ void rm_osd_msg(int id) { * */ -static void clear_osd_msgs(void) { - mp_osd_msg_t* msg = osd_msg_stack, *prev = NULL; - while(msg) { +static void clear_osd_msgs(void) +{ + mp_osd_msg_t *msg = osd_msg_stack, *prev = NULL; + while (msg) { prev = msg->prev; free(msg); msg = prev; @@ -1540,43 +1583,46 @@ static void clear_osd_msgs(void) { * */ -static mp_osd_msg_t* get_osd_msg(struct MPContext *mpctx) +static mp_osd_msg_t *get_osd_msg(struct MPContext *mpctx) { struct MPOpts *opts = &mpctx->opts; - mp_osd_msg_t *msg,*prev,*last = NULL; + mp_osd_msg_t *msg, *prev, *last = NULL; static unsigned last_update = 0; unsigned now = GetTimerMS(); unsigned diff; char hidden_dec_done = 0; if (mpctx->osd_visible) { - // 36000000 means max timed visibility is 1 hour into the future, if - // the difference is greater assume it's wrapped around from below 0 + // 36000000 means max timed visibility is 1 hour into the future, if + // the difference is greater assume it's wrapped around from below 0 if (mpctx->osd_visible - now > 36000000) { mpctx->osd_visible = 0; - vo_osd_progbar_type = -1; // disable - vo_osd_changed(OSDTYPE_PROGBAR); + vo_osd_progbar_type = -1; // disable + vo_osd_changed(OSDTYPE_PROGBAR); mpctx->osd_function = mpctx->paused ? OSD_PAUSE : OSD_PLAY; - } + } } if (mpctx->osd_show_percentage_until - now > 36000000) mpctx->osd_show_percentage_until = 0; - if(!last_update) last_update = now; + if (!last_update) + last_update = now; diff = now >= last_update ? now - last_update : 0; last_update = now; // Look for the first message in the stack with high enough level. - for(msg = osd_msg_stack ; msg ; last = msg, msg = prev) { + for (msg = osd_msg_stack; msg; last = msg, msg = prev) { prev = msg->prev; if (msg->level > opts->osd_level && hidden_dec_done) continue; // The message has a high enough level or it is the first hidden one // in both cases we decrement the timer or kill it. - if(!msg->started || msg->time > diff) { - if(msg->started) msg->time -= diff; - else msg->started = 1; + if (!msg->started || msg->time > diff) { + if (msg->started) + msg->time -= diff; + else + msg->started = 1; // display it if (msg->level <= opts->osd_level) return msg; @@ -1585,7 +1631,7 @@ static mp_osd_msg_t* get_osd_msg(struct MPContext *mpctx) } // kill the message free(