diff options
Diffstat (limited to 'mplayer.c')
-rw-r--r-- | mplayer.c | 1750 |
1 files changed, 1091 insertions, 659 deletions
@@ -4,7 +4,9 @@ #include <stdio.h> #include <stdlib.h> +#include <stdbool.h> #include "config.h" +#include "talloc.h" #if defined(__MINGW32__) || defined(__CYGWIN__) #define _UWIN 1 /*disable Non-underscored versions of non-ANSI functions as otherwise int eof would conflict with eof()*/ @@ -43,6 +45,8 @@ #include "m_option.h" #include "m_config.h" +#include "mplayer.h" +#include "access_mpcontext.h" #include "m_property.h" #include "cfg-mplayer-def.h" @@ -51,6 +55,7 @@ #include "subreader.h" +#include "mp_osd.h" #include "libvo/video_out.h" #include "libvo/font_load.h" @@ -71,6 +76,7 @@ #include "osdep/getch2.h" #include "osdep/timer.h" +#include "osdep/findfiles.h" #ifdef CONFIG_GUI #include "gui/interface.h" @@ -78,6 +84,7 @@ #include "input/input.h" +const int under_mencoder = 0; int slave_mode=0; int player_idle_mode=0; int quiet=0; @@ -127,27 +134,15 @@ int import_initial_playtree_into_gui(play_tree_t* my_playtree, m_config_t* confi #include "parser-cfg.h" #include "parser-mpcmd.h" -m_config_t* mconfig; - //**************************************************************************// // 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.h" //**************************************************************************// -// XScreensaver -//**************************************************************************// - -void xscreensaver_heartbeat(void); - -//**************************************************************************// //**************************************************************************// // Input media streaming & demultiplexer: //**************************************************************************// @@ -175,6 +170,8 @@ static int max_framesize=0; #include "mixer.h" #include "mp_core.h" +#include "options.h" +#include "defaultopts.h" //**************************************************************************// //**************************************************************************// @@ -184,24 +181,6 @@ static int max_framesize=0; int noconsolecontrols=0; //**************************************************************************// -// Not all functions in mplayer.c take the context as an argument yet -static MPContext mpctx_s = { - .osd_function = OSD_PLAY, - .begin_skip = MP_NOPTS_VALUE, - .play_tree_step = 1, - .global_sub_pos = -1, - .set_of_sub_pos = -1, - .file_format = DEMUXER_TYPE_UNKNOWN, - .loop_times = -1, -#ifdef CONFIG_DVBIN - .last_dvb_step = 1, -#endif -}; - -static MPContext *mpctx = &mpctx_s; - -int fixed_vo=0; - // benchmark: double video_time_usage=0; double vout_time_usage=0; @@ -215,8 +194,6 @@ int benchmark=0; int auto_quality=0; static int output_quality=0; -float playback_speed=1.0; - int use_gui=0; #ifdef CONFIG_GUI @@ -225,11 +202,6 @@ int enqueue=0; static int list_properties = 0; -int osd_level=1; -// if nonzero, hide current OSD contents when GetTimerMS() reaches this -unsigned int osd_visible; -int osd_duration = 1000; - int term_osd = 1; static char* term_osd_esc = "\x1b[A\r\x1b[K"; static char* playing_msg = NULL; @@ -237,17 +209,12 @@ static char* playing_msg = NULL; static double seek_to_sec; static off_t seek_to_byte=0; static off_t step_sec=0; -static int loop_seek=0; static m_time_size_t end_at = { .type = END_AT_NONE, .pos = 0 }; // A/V sync: int autosync=0; // 30 might be a good default value. -// may be changed by GUI: (FIXME!) -float rel_seek_secs=0; -int abs_seek_pos=0; - // codecs: char **audio_codec_list=NULL; // override audio codec char **video_codec_list=NULL; // override video codec @@ -259,15 +226,10 @@ extern char *demuxer_name; // override demuxer extern char *audio_demuxer_name; // override audio demuxer extern char *sub_demuxer_name; // override sub demuxer -// streaming: -int audio_id=-1; -int video_id=-1; -int dvdsub_id=-2; 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; int file_filter=1; @@ -288,8 +250,6 @@ static char *stream_dump_name="stream.dump"; // 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 ignore_start=0; @@ -302,10 +262,6 @@ static int audio_output_format=-1; // AF_FORMAT_UNKNOWN static int play_n_frames=-1; static int play_n_frames_mf=-1; -// screen info: -char** video_driver_list=NULL; -char** audio_driver_list=NULL; - // sub: char *font_name=NULL; char *sub_font_name=NULL; @@ -333,9 +289,9 @@ char* current_module=NULL; // for debugging #ifdef CONFIG_MENU #include "m_struct.h" #include "libmenu/menu.h" -void vf_menu_pause_update(struct vf_instance_s* vf); +void vf_menu_pause_update(struct vf_instance* vf); extern vf_info_t vf_info_menu; -static vf_info_t* libmenu_vfs[] = { +static const vf_info_t* const libmenu_vfs[] = { &vf_info_menu, NULL }; @@ -353,11 +309,9 @@ static char* rtc_device; edl_record_ptr edl_records = NULL; ///< EDL entries memory area edl_record_ptr next_edl_record = NULL; ///< only for traversing edl_records -short edl_decision = 0; ///< 1 when an EDL operation has been made. FILE* edl_fd = NULL; ///< fd to write to when in -edlout mode. int use_filedir_conf; -static unsigned int initialized_flags=0; #include "mpcommon.h" #include "command.h" @@ -400,7 +354,15 @@ int mpctx_get_osd_function(MPContext *mpctx) return mpctx->osd_function; } -static int is_valid_metadata_type (metadata_t type) { +static float get_relative_time(struct MPContext *mpctx) +{ + unsigned int new_time = GetTimer(); + unsigned int delta = new_time - mpctx->last_time; + mpctx->last_time = new_time; + return delta * 0.000001; +} + +static int is_valid_metadata_type(struct MPContext *mpctx, metadata_t type) { switch (type) { /* check for valid video stream */ @@ -444,7 +406,7 @@ static int is_valid_metadata_type (metadata_t type) { return 1; } -static char *get_demuxer_info (char *tag) { +static char *get_demuxer_info(struct MPContext *mpctx, char *tag) { char **info = mpctx->demuxer->info; int n; @@ -458,19 +420,20 @@ static char *get_demuxer_info (char *tag) { return info[2*n+1] ? strdup (info[2*n+1]) : NULL; } -char *get_metadata (metadata_t type) { +char *get_metadata(struct MPContext *mpctx, metadata_t type) +{ char *meta = NULL; sh_audio_t * const sh_audio = mpctx->sh_audio; sh_video_t * const sh_video = mpctx->sh_video; - if (!is_valid_metadata_type (type)) + if (!is_valid_metadata_type(mpctx, type)) return NULL; switch (type) { case META_NAME: { - return strdup (mp_basename2 (filename)); + return strdup (mp_basename2 (mpctx->filename)); } case META_VIDEO_CODEC: @@ -533,25 +496,25 @@ char *get_metadata (metadata_t type) { /* check for valid demuxer */ case META_INFO_TITLE: - return get_demuxer_info ("Title"); + return get_demuxer_info(mpctx, "Title"); case META_INFO_ARTIST: - return get_demuxer_info ("Artist"); + return get_demuxer_info(mpctx, "Artist"); case META_INFO_ALBUM: - return get_demuxer_info ("Album"); + return get_demuxer_info(mpctx, "Album"); case META_INFO_YEAR: - return get_demuxer_info ("Year"); + return get_demuxer_info(mpctx, "Year"); case META_INFO_COMMENT: - return get_demuxer_info ("Comment"); + return get_demuxer_info(mpctx, "Comment"); case META_INFO_TRACK: - return get_demuxer_info ("Track"); + return get_demuxer_info(mpctx, "Track"); case META_INFO_GENRE: - return get_demuxer_info ("Genre"); + return get_demuxer_info(mpctx, "Genre"); default: break; @@ -574,13 +537,13 @@ static void mp_dvdnav_context_free(MPContext *ctx){ } #endif -void uninit_player(unsigned int mask){ - mask=initialized_flags&mask; +void uninit_player(struct MPContext *mpctx, unsigned int mask){ + mask=mpctx->initialized_flags&mask; mp_msg(MSGT_CPLAYER,MSGL_DBG2,"\n*** uninit(0x%X)\n",mask); if(mask&INITIALIZED_ACODEC){ - initialized_flags&=~INITIALIZED_ACODEC; + mpctx->initialized_flags&=~INITIALIZED_ACODEC; current_module="uninit_acodec"; if(mpctx->sh_audio) uninit_audio(mpctx->sh_audio); #ifdef CONFIG_GUI @@ -591,7 +554,7 @@ void uninit_player(unsigned int mask){ } if(mask&INITIALIZED_VCODEC){ - initialized_flags&=~INITIALIZED_VCODEC; + mpctx->initialized_flags&=~INITIALIZED_VCODEC; current_module="uninit_vcodec"; if(mpctx->sh_video) uninit_video(mpctx->sh_video); mpctx->sh_video=NULL; @@ -601,8 +564,24 @@ void uninit_player(unsigned int mask){ } if(mask&INITIALIZED_DEMUXER){ - initialized_flags&=~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++) { + 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->num_chapters = 0; + mpctx->video_offset = 0; if(mpctx->demuxer){ mpctx->stream=mpctx->demuxer->stream; free_demuxer(mpctx->demuxer); @@ -612,16 +591,16 @@ void uninit_player(unsigned int mask){ // kill the cache process: if(mask&INITIALIZED_STREAM){ - initialized_flags&=~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){ - initialized_flags&=~INITIALIZED_VO; + mpctx->initialized_flags&=~INITIALIZED_VO; current_module="uninit_vo"; - mpctx->video_out->uninit(); + vo_destroy(mpctx->video_out); mpctx->video_out=NULL; #ifdef CONFIG_DVDNAV mp_dvdnav_context_free(mpctx); @@ -630,7 +609,7 @@ void uninit_player(unsigned int mask){ // Must be after libvo uninit, as few vo drivers (svgalib) have tty code. if(mask&INITIALIZED_GETCH2){ - initialized_flags&=~INITIALIZED_GETCH2; + mpctx->initialized_flags&=~INITIALIZED_GETCH2; current_module="uninit_getch2"; mp_msg(MSGT_CPLAYER,MSGL_DBG2,"\n[[[uninit getch2]]]\n"); // restore terminal: @@ -638,51 +617,42 @@ void uninit_player(unsigned int mask){ } if(mask&INITIALIZED_VOBSUB){ - initialized_flags&=~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){ - initialized_flags&=~INITIALIZED_SPUDEC; + mpctx->initialized_flags&=~INITIALIZED_SPUDEC; current_module="uninit_spudec"; spudec_free(vo_spudec); vo_spudec=NULL; } if(mask&INITIALIZED_AO){ - initialized_flags&=~INITIALIZED_AO; + mpctx->initialized_flags&=~INITIALIZED_AO; current_module="uninit_ao"; if (mpctx->edl_muted) mixer_mute(&mpctx->mixer); - mpctx->audio_out->uninit(mpctx->eof?0:1); mpctx->audio_out=NULL; + mpctx->audio_out->uninit(mpctx->stop_play != AT_END_OF_FILE); + mpctx->audio_out=NULL; } #ifdef CONFIG_GUI if(mask&INITIALIZED_GUI){ - initialized_flags&=~INITIALIZED_GUI; + mpctx->initialized_flags&=~INITIALIZED_GUI; current_module="uninit_gui"; guiDone(); } #endif - if(mask&INITIALIZED_INPUT){ - initialized_flags&=~INITIALIZED_INPUT; - current_module="uninit_input"; - mp_input_uninit(); -#ifdef CONFIG_MENU - if (use_menu) - menu_uninit(); -#endif - } - current_module=NULL; } -void exit_player_with_rc(exit_reason_t how, int rc){ - +void exit_player_with_rc(struct MPContext *mpctx, exit_reason_t how, int rc) +{ if (mpctx->user_muted && !mpctx->edl_muted) mixer_mute(&mpctx->mixer); - uninit_player(INITIALIZED_ALL); + uninit_player(mpctx, INITIALIZED_ALL); #if defined(__MINGW32__) || defined(__CYGWIN__) timeEndPeriod(1); #endif @@ -690,18 +660,25 @@ void exit_player_with_rc(exit_reason_t how, int rc){ #ifdef CONFIG_GUI if ( !use_gui ) #endif - vo_uninit(); // 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"; + mp_input_uninit(mpctx->input); +#ifdef CONFIG_MENU + if (use_menu) + menu_uninit(); #endif #ifdef CONFIG_FREETYPE current_module="uninit_font"; - if (sub_font && sub_font != vo_font) free_font_desc(sub_font); - sub_font = NULL; - if (vo_font) free_font_desc(vo_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 - free_osd_list(); + osd_free(mpctx->osd); #ifdef CONFIG_ASS ass_library_done(ass_library); @@ -710,12 +687,13 @@ void exit_player_with_rc(exit_reason_t how, int rc){ current_module="exit_player"; // free mplayer config - if(mconfig) - m_config_free(mconfig); + if(mpctx->mconfig) + m_config_free(mpctx->mconfig); if(mpctx->playtree) play_tree_free(mpctx->playtree, 1); + talloc_free(mpctx->key_fifo); if(edl_records != NULL) free(edl_records); // free mem allocated for EDL switch(how) { @@ -739,8 +717,9 @@ void exit_player_with_rc(exit_reason_t how, int rc){ exit(rc); } -void exit_player(exit_reason_t how){ - exit_player_with_rc(how, 1); +static void exit_player(struct MPContext *mpctx, exit_reason_t how) +{ + exit_player_with_rc(mpctx, how, 1); } #ifndef __MINGW32__ @@ -761,7 +740,6 @@ static void exit_sighandler(int x){ if (!crash_debug || x != SIGTRAP) #endif ++sig_count; - if(initialized_flags==0 && sig_count>1) exit(1); if(sig_count==5) { /* We're crashing bad and can't uninit cleanly :( @@ -826,17 +804,20 @@ static void exit_sighandler(int x){ exit(1); } -void mp_input_register_options(m_config_t* cfg); - #include "cfg-mplayer.h" -static void parse_cfgfiles( m_config_t* conf ) +static int cfg_include(m_option_t *conf, char *filename) +{ + return m_config_parse_config_file(conf->priv, filename); +} + +static void parse_cfgfiles(struct MPContext *mpctx, m_config_t* conf) { char *conffile; int conffile_fd; if (!disable_system_conf && m_config_parse_config_file(conf, MPLAYER_CONFDIR "/mplayer.conf") < 0) - exit_player(EXIT_NONE); + exit_player(mpctx, EXIT_NONE); if ((conffile = get_path("")) == NULL) { mp_msg(MSGT_CPLAYER,MSGL_WARN,MSGTR_NoHomeDir); } else { @@ -856,7 +837,7 @@ if ((conffile = get_path("")) == NULL) { } if (!disable_user_conf && m_config_parse_config_file(conf, conffile) < 0) - exit_player(EXIT_NONE); + exit_player(mpctx, EXIT_NONE); free(conffile); } } @@ -894,7 +875,7 @@ static void load_per_extension_config (m_config_t* conf, const char *const file) m_profile_t *p; /* does filename actually have an extension ? */ - str = strrchr (filename, '.'); + str = strrchr (file, '.'); if (!str) return; @@ -962,38 +943,39 @@ static void load_per_file_config (m_config_t* conf, const char *const file) * 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) { +static int libmpdemux_was_interrupted(struct MPContext *mpctx, int stop_play) +{ mp_cmd_t* cmd; - if((cmd = mp_input_get_cmd(0,0,0)) != NULL) { + if((cmd = mp_input_get_cmd(mpctx->input, 0,0,0)) != NULL) { switch(cmd->id) { case MP_CMD_QUIT: - exit_player_with_rc(EXIT_QUIT, (cmd->nargs > 0)? cmd->args[0].v.i : 0); + exit_player_with_rc(mpctx, 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; + 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: { - eof = (cmd->args[0].v.i > 0) ? PT_UP_NEXT : PT_UP_PREV; + stop_play = (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; + stop_play = (cmd->args[0].v.i > 0) ? PT_NEXT_SRC : PT_PREV_SRC; } break; } mp_cmd_free(cmd); } - return eof; + return stop_play; } #define mp_basename(s) (strrchr(s,'\\')==NULL?(mp_basename2(s)):(strrchr(s,'\\')+1)) -static int playtree_add_playlist(play_tree_t* entry) +static int playtree_add_playlist(struct MPContext *mpctx, play_tree_t* entry) { - play_tree_add_bpf(entry,filename); + play_tree_add_bpf(entry,mpctx->filename); #ifdef CONFIG_GUI if (use_gui) { if (entry) { - import_playtree_playlist_into_gui(entry, mconfig); + import_playtree_playlist_into_gui(entry, mpctx->mconfig); play_tree_free_list(entry,1); } } else @@ -1023,7 +1005,7 @@ static int playtree_add_playlist(play_tree_t* entry) return PT_NEXT_SRC; } -void add_subtitles(char *filename, float fps, int noerr) +void add_subtitles(struct MPContext *mpctx, char *filename, float fps, int noerr) { sub_data *subd; #ifdef CONFIG_ASS @@ -1068,7 +1050,7 @@ void add_subtitles(char *filename, float fps, int noerr) } // FIXME: if/when the GUI calls this, global sub numbering gets (potentially) broken. -void update_set_of_subtitles(void) +void update_set_of_subtitles(struct MPContext *mpctx) // subdata was changed, set_of_sub... have to be updated. { sub_data ** const set_of_subtitles = mpctx->set_of_subtitles; @@ -1089,10 +1071,11 @@ void update_set_of_subtitles(void) } } -void init_vo_spudec(void) { +void init_vo_spudec(struct MPContext *mpctx) +{ if (vo_spudec) spudec_free(vo_spudec); - initialized_flags &= ~INITIALIZED_SPUDEC; + mpctx->initialized_flags &= ~INITIALIZED_SPUDEC; vo_spudec = NULL; if (spudec_ifo) { unsigned int palette[16], width, height; @@ -1126,7 +1109,7 @@ void init_vo_spudec(void) { } if (vo_spudec!=NULL) { - initialized_flags|=INITIALIZED_SPUDEC; + mpctx->initialized_flags|=INITIALIZED_SPUDEC; mp_property_do("sub_forced_only", M_PROPERTY_SET, &forced_subs_only, mpctx); } } @@ -1183,15 +1166,25 @@ static void sadd_hhmmssf(char *buf, unsigned *pos, int len, float time) { 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) +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 - sh_video->pts - audio_delay; + if (mpctx->last_av_difference > 0.5 && drop_frame_cnt > 50 + && !mpctx->drop_message_shown) { + mp_msg(MSGT_AVSYNC,MSGL_WARN,MSGTR_SystemTooSlow); + mpctx->drop_message_shown = true; + } + } + if (quiet) + return; + + int width; char *line; unsigned pos = 0; @@ -1226,7 +1219,8 @@ static void print_status(float a_pos, float a_v, float corr) // A-V sync if (mpctx->sh_audio && sh_video) - saddf(line, &pos, width, "A-V:%7.3f ct:%7.3f ", a_v, corr); + saddf(line, &pos, width, "A-V:%7.3f ct:%7.3f ", + mpctx->last_av_difference, mpctx->total_avsync_change); // Video stats if (sh_video) @@ -1238,9 +1232,9 @@ static void print_status(float a_pos, float a_v, float corr) 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)); + (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) { @@ -1262,8 +1256,8 @@ static void print_status(float a_pos, float a_v, float corr) #endif // other - if (playback_speed != 1) - saddf(line, &pos, width, "%4.2fx ", playback_speed); + if (opts->playback_speed != 1) + saddf(line, &pos, width, "%4.2fx ", opts->playback_speed); // end if (erase_to_end_of_line) { @@ -1283,8 +1277,9 @@ static void print_status(float a_pos, float a_v, float corr) * \param sh_audio describes the requested input format of the chain. * \param ao_data describes the requested output format of the chain. */ -int build_afilter_chain(sh_audio_t *sh_audio, ao_data_t *ao_data) +int build_afilter_chain(struct MPContext *mpctx, sh_audio_t *sh_audio, ao_data_t *ao_data) { + struct MPOpts *opts = &mpctx->opts; int new_srate; int result; if (!sh_audio) @@ -1297,17 +1292,17 @@ int build_afilter_chain(sh_audio_t *sh_audio, ao_data_t *ao_data) } if(af_control_any_rev(sh_audio->afilter, AF_CONTROL_PLAYBACK_SPEED | AF_CONTROL_SET, - &playback_speed)) { + &opts->playback_speed)) { new_srate = sh_audio->samplerate; } else { - new_srate = sh_audio->samplerate * playback_speed; + new_srate = sh_audio->samplerate * opts->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; + opts->playback_speed = (float)new_srate / (float)sh_audio->samplerate; } } result = init_audio_filters(sh_audio, new_srate, @@ -1418,24 +1413,27 @@ static void clear_osd_msgs(void) { * */ -static mp_osd_msg_t* get_osd_msg(void) { +static mp_osd_msg_t* get_osd_msg(struct MPContext *mpctx) +{ + struct MPOpts *opts = &mpctx->opts; mp_osd_msg_t *msg,*prev,*last = NULL; static unsigned last_update = 0; unsigned now = GetTimerMS(); unsigned diff; char hidden_dec_done = 0; - if (osd_visible) { + 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 - if (osd_visible - now > 36000000) { - osd_visible = 0; + if (mpctx->osd_visible - now > 36000000) { + mpctx->osd_visible = 0; vo_osd_progbar_type = -1; // disable vo_osd_changed(OSDTYPE_PROGBAR); - if (mpctx->osd_function != OSD_PAUSE) - mpctx->osd_function = OSD_PLAY; + 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; diff = now >= last_update ? now - last_update : 0; @@ -1445,14 +1443,16 @@ static mp_osd_msg_t* get_osd_msg(void) { // Look for the first message in the stack with high enough level. for(msg = osd_msg_stack ; msg ; last = msg, msg = prev) { prev = msg->prev; - if(msg->level > osd_level && hidden_dec_done) continue; + 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; // display it - if(msg->level <= osd_level) return msg; + if (msg->level <= opts->osd_level) + return msg; hidden_dec_done = 1; continue; } @@ -1477,20 +1477,21 @@ static mp_osd_msg_t* get_osd_msg(void) { * */ -void set_osd_bar(int type,const char* name,double min,double max,double val) { - - if(osd_level < 1) return; +void set_osd_bar(struct MPContext *mpctx, int type,const char* name,double min,double max,double val) { + struct MPOpts *opts = &mpctx->opts; + if (opts->osd_level < 1) + return; if(mpctx->sh_video) { - osd_visible = (GetTimerMS() + 1000) | 1; + mpctx->osd_visible = (GetTimerMS() + 1000) | 1; vo_osd_progbar_type = type; vo_osd_progbar_value = 256*(val-min)/(max-min); vo_osd_changed(OSDTYPE_PROGBAR); return; } - set_osd_msg(OSD_MSG_BAR,1,osd_duration,"%s: %d %%", - name,ROUND(100*(val-min)/(max-min))); + set_osd_msg(OSD_MSG_BAR, 1, opts->osd_duration, "%s: %d %%", + name, ROUND(100*(val-min)/(max-min))); } @@ -1503,18 +1504,30 @@ void set_osd_bar(int type,const char* name,double min,double max,double val) { * */ -static void update_osd_msg(void) { +static void update_osd_msg(struct MPContext *mpctx) +{ + struct MPOpts *opts = &mpctx->opts; mp_osd_msg_t *msg; - static char osd_text[128] = ""; - static char osd_text_timer[128]; - - // we need some mem for vo_osd_text - vo_osd_text = (unsigned char*)osd_text; - + struct osd_state *osd = mpctx->osd; + char osd_text_timer[128]; + + if (mpctx->add_osd_seek_info) { + double percentage; + if (mpctx->timeline && mpctx->sh_video) + percentage = mpctx->sh_video->pts * 100 / + mpctx->timeline[mpctx->num_timeline_parts].start; + else + percentage = demuxer_get_percent_pos(mpctx->demuxer); + set_osd_bar(mpctx, 0, "Position", 0, 100, percentage); + if (mpctx->sh_video) + mpctx->osd_show_percentage_until = (GetTimerMS() + 1000) | 1; + mpctx->add_osd_seek_info = false; + } + // Look if we have a msg - if((msg = get_osd_msg())) { - if(strcmp(osd_text,msg->msg)) { - strncpy((char*)osd_text, msg->msg, 127); + if((msg = get_osd_msg(mpctx))) { + if (strcmp(osd->osd_text, msg->msg)) { + strncpy(osd->osd_text, msg->msg, 127); if(mpctx->sh_video) vo_osd_changed(OSDTYPE_OSD); else if(term_osd) mp_msg(MSGT_CPLAYER,MSGL_STATUS,"%s%s\n",term_osd_esc,msg->msg); } @@ -1523,21 +1536,29 @@ static void update_osd_msg(void) { if(mpctx->sh_video) { // fallback on the timer - if(osd_level>=2) { - int len = demuxer_get_time_length(mpctx->demuxer); + if (opts->osd_level >= 2) { + int len; + if (mpctx->timeline) + len = mpctx->timeline[mpctx->num_timeline_parts].start; + else + len = demuxer_get_time_length(mpctx->demuxer); int percentage = -1; char percentage_text[10]; int pts = demuxer_get_current_time(mpctx->demuxer); - if (mpctx->osd_show_percentage) - percentage = demuxer_get_percent_pos(mpctx->demuxer); + if (mpctx->osd_show_percentage_until) + if (mpctx->timeline) + percentage = mpctx->sh_video->pts * 100 / + mpctx->timeline[mpctx->num_timeline_parts].start; + else + percentage = demuxer_get_percent_pos(mpctx->demuxer); if (percentage >= 0) snprintf(percentage_text, 9, " (%d%%)", percentage); else percentage_text[0] = 0; - if (osd_level == 3) + if (opts->osd_level == 3) snprintf(osd_text_timer, 63, "%c %02d:%02d:%02d / %02d:%02d:%02d%s", mpctx->osd_function,pts/3600,(pts/60)%60,pts%60, @@ -1549,20 +1570,16 @@ static void update_osd_msg(void) { } else osd_text_timer[0]=0; - // always decrement the percentage timer - if(mpctx->osd_show_percentage) - mpctx->osd_show_percentage--; - - if(strcmp(osd_text,osd_text_timer)) { - strncpy(osd_text, osd_text_timer, 63); + if (strcmp(osd->osd_text, osd_text_timer)) { + strncpy(osd->osd_text, osd_text_timer, 63); vo_osd_changed(OSDTYPE_OSD); } return; } // Clear the term osd line - if(term_osd && osd_text[0]) { - osd_text[0] = 0; + if (term_osd && osd->osd_text[0]) { + osd->osd_text[0] = 0; printf("%s\n",term_osd_esc); } } @@ -1571,7 +1588,9 @@ static void update_osd_msg(void) { // OSDMsgStack -void reinit_audio_chain(void) { +void reinit_audio_chain(struct MPContext *mpctx) +{ + struct MPOpts *opts = &mpctx->opts; if(mpctx->sh_audio){ current_module="init_audio_codec"; mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n"); @@ -1580,7 +1599,7 @@ if(mpctx->sh_audio){ mpctx->d_audio->id = -2; return; } else - initialized_flags|=INITIALIZED_ACODEC; + mpctx->initialized_flags|=INITIALIZED_ACODEC; mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n"); @@ -1597,24 +1616,24 @@ if(mpctx->sh_audio){ // output: &ao_data.samplerate, &ao_data.channels, &ao_data.format)){ mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_AudioFilterChainPreinitError); - exit_player(EXIT_ERROR); + exit_player(mpctx, EXIT_ERROR); } #endif current_module="ao2_init"; - if(!(mpctx->audio_out=init_best_audio_out(audio_driver_list, + if(!(mpctx->audio_out=init_best_audio_out(opts->audio_driver_list, 0, // plugin flag ao_data.samplerate, ao_data.channels, ao_data.format,0))){ // FAILED: mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CannotInitAO); - uninit_player(INITIALIZED_ACODEC); // close codec + uninit_player(mpctx, INITIALIZED_ACODEC); // close codec mpctx->sh_audio=mpctx->d_audio->sh=NULL; // -> nosound mpctx->d_audio->id = -2; return; } else { // SUCCESS: - initialized_flags|=INITIALIZED_AO; + mpctx->initialized_flags|=INITIALIZED_AO; mp_msg(MSGT_CPLAYER,MSGL_INFO,"AO: [%s] %dHz %dch %s (%d bytes per sample)\n", mpctx->audio_out->info->short_name, ao_data.samplerate, ao_data.channels, @@ -1627,10 +1646,10 @@ if(mpctx->sh_audio){ // init audio filters: #if 1 current_module="af_init"; - if(!build_afilter_chain(mpctx->sh_audio, &ao_data)) { + if(!build_afilter_chain(mpctx, mpctx->sh_audio, &ao_data)) { mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_NoMatchingFilter); // mp_msg(MSGT_CPLAYER,MSGL_ERR,"Couldn't find matching filter / ao format! -> NOSOUND\n"); -// uninit_player(INITIALIZED_ACODEC|INITIALIZED_AO); // close codec & ao +// uninit_player(mpctx, INITIALIZED_ACODEC|INITIALIZED_AO); // close codec & ao // sh_audio=mpctx->d_audio->sh=NULL; // -> nosound } #endif @@ -1647,8 +1666,10 @@ if(mpctx->sh_audio){ // Return pts value corresponding to the end point of audio written to the // ao so far. -static double written_audio_pts(sh_audio_t *sh_audio, demux_stream_t *d_audio) +static double written_audio_pts(struct MPContext *mpctx) { + sh_audio_t *sh_audio = mpctx->sh_audio; + demux_stream_t *d_audio = mpctx->d_audio; double buffered_output; // first calculate the end pts of audio that has been output by decoder double a_pts = sh_audio->pts; @@ -1691,31 +1712,31 @@ static double written_audio_pts(sh_audio_t *sh_audio, demux_stream_t *d_audio) // Filters divide audio length by playback_speed, so multiply by it // to get the length in original units without speedup or slowdown - a_pts -= buffered_output * playback_speed / ao_data.bps; + a_pts -= buffered_output * mpctx->opts.playback_speed / ao_data.bps; - return a_pts; + return a_pts + mpctx->video_offset; } // Return pts value corresponding to currently playing audio. -double playing_audio_pts(sh_audio_t *sh_audio, demux_stream_t *d_audio, - const ao_functions_t *audio_out) +double playing_audio_pts(struct MPContext *mpctx) { - return written_audio_pts(sh_audio, d_audio) - playback_speed * - audio_out->get_delay(); + return written_audio_pts(mpctx) - mpctx->opts.playback_speed * + mpctx->audio_out->get_delay(); } -static int check_framedrop(double frame_time) { +static int check_framedrop(struct MPContext *mpctx, double frame_time) { + struct MPOpts *opts = &mpctx->opts; // check for frame-drop: current_module = "check_framedrop"; if (mpctx->sh_audio && !mpctx->d_audio->eof) { static int dropped_frames; - float delay = playback_speed*mpctx->audio_out->get_delay(); + float delay = opts->playback_speed*mpctx->audio_out->get_delay(); float d = delay-mpctx->delay; |