diff options
author | uau <uau@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2007-02-21 00:49:24 +0000 |
---|---|---|
committer | uau <uau@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2007-02-21 00:49:24 +0000 |
commit | d5d4c6c7e224709c53d28352ce6aadc3c6e72374 (patch) | |
tree | 9fe98ae571ad6bda5cf04273cefabd6ffcbf92ae /mplayer.c | |
parent | e23b2395c0265c0a0bd92c0468e20e8ce42793e6 (diff) | |
download | mpv-d5d4c6c7e224709c53d28352ce6aadc3c6e72374.tar.bz2 mpv-d5d4c6c7e224709c53d28352ce6aadc3c6e72374.tar.xz |
Split command/property handling from mplayer.c to a new file command.c.
Move some global and static variables under a struct that can be given
as a parameter. Add a context argument to the property functions so that
they do not have to depend on global/static variables.
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@22298 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'mplayer.c')
-rw-r--r-- | mplayer.c | 2964 |
1 files changed, 480 insertions, 2484 deletions
@@ -111,8 +111,6 @@ char * proc_priority=NULL; #ifdef HAS_DVBIN_SUPPORT #include "stream/dvbin.h" -static int last_dvb_step = 1; -static int dvbin_reopen = 0; #include "stream/cache2.h" #endif @@ -127,17 +125,6 @@ extern int import_playtree_playlist_into_gui(play_tree_t* my_playtree, m_config_ extern int import_initial_playtree_into_gui(play_tree_t* my_playtree, m_config_t* config, int enqueue); #endif -play_tree_t* playtree; -play_tree_iter_t* playtree_iter = NULL; -static int play_tree_step = 1; - -#define PT_NEXT_ENTRY 1 -#define PT_PREV_ENTRY -1 -#define PT_NEXT_SRC 2 -#define PT_PREV_SRC -2 -#define PT_UP_NEXT 3 -#define PT_UP_PREV -3 - //**************************************************************************// // Config //**************************************************************************// @@ -193,9 +180,9 @@ static int max_framesize=0; #include "libmpcodecs/vf.h" #include "libmpcodecs/vd.h" -//**************************************************************************// +#include "mixer.h" -static void reinit_audio_chain(void); +#include "mp_core.h" //**************************************************************************// //**************************************************************************// @@ -205,11 +192,18 @@ static void reinit_audio_chain(void); int noconsolecontrols=0; //**************************************************************************// -vo_functions_t *video_out=NULL; -ao_functions_t *audio_out=NULL; +// Not all functions in mplayer.c take the context as an argument yet +static MPContext *mpctx = &(MPContext){ + .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, + .last_dvb_step = 1, +}; int fixed_vo=0; -int eof=0; // benchmark: double video_time_usage=0; @@ -234,17 +228,12 @@ int enqueue=0; static int list_properties = 0; -#define MAX_OSD_LEVEL 3 -#define MAX_TERM_OSD_LEVEL 1 - int osd_level=1; // if nonzero, hide current OSD contents when GetTimerMS() reaches this unsigned int osd_visible; -static int osd_function=OSD_PLAY; -static int osd_show_percentage = 0; -static int osd_duration = 1000; +int osd_duration = 1000; -static int term_osd = 1; +int term_osd = 1; static char* term_osd_esc = "\x1b[A\r\x1b[K"; static char* playing_msg = NULL; // seek: @@ -342,45 +331,16 @@ char *vobsub_name=NULL; int subcc_enabled=0; int suboverlap_enabled = 1; -sub_data* set_of_subtitles[MAX_SUBTITLE_FILES]; -int set_of_sub_size = 0; -int set_of_sub_pos = -1; - -int global_sub_size = 0; // this encompasses all subtitle sources -int global_sub_pos = -1; // this encompasses all subtitle sources -#define SUB_SOURCE_SUBS 0 -#define SUB_SOURCE_VOBSUB 1 -#define SUB_SOURCE_DEMUX 2 -#define SUB_SOURCES 3 -int global_sub_indices[SUB_SOURCES]; - #ifdef USE_ASS #include "libass/ass.h" #include "libass/ass_mp.h" - -// set_of_ass_tracks[i] contains subtitles from set_of_subtitles[i] parsed by libass -// or NULL if format unsupported -ass_track_t* set_of_ass_tracks[MAX_SUBTITLE_FILES]; #endif extern int mp_msg_levels[MSGT_MAX]; extern int mp_msg_level_all; -static stream_t* stream=NULL; -static demuxer_t *demuxer=NULL; -static sh_audio_t *sh_audio=NULL; -static sh_video_t *sh_video=NULL; -static demux_stream_t *d_audio=NULL; -static demux_stream_t *d_video=NULL; -static demux_stream_t *d_dvdsub=NULL; - char* current_module=NULL; // for debugging -extern int vo_gamma_gamma; -extern int vo_gamma_brightness; -extern int vo_gamma_contrast; -extern int vo_gamma_saturation; -extern int vo_gamma_hue; // --- @@ -407,27 +367,13 @@ 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 user_muted = 0; ///< Stores whether user wanted muted mode. -short edl_muted = 0; ///< Stores whether EDL is currently in muted mode. short edl_decision = 0; ///< 1 when an EDL operation has been made. FILE* edl_fd = NULL; ///< fd to write to when in -edlout mode. -float begin_skip = MP_NOPTS_VALUE; ///< start time of the current skip while on edlout mode int use_filedir_conf; static unsigned int inited_flags=0; #include "mpcommon.h" -#define INITED_VO 1 -#define INITED_AO 2 -#define INITED_GUI 4 -#define INITED_GETCH2 8 -#define INITED_SPUDEC 32 -#define INITED_STREAM 64 -#define INITED_INPUT 128 -#define INITED_VOBSUB 256 -#define INITED_DEMUXER 512 -#define INITED_ACODEC 1024 -#define INITED_VCODEC 2048 -#define INITED_ALL 0xFFFF +#include "command.h" #include "metadata.h" @@ -441,7 +387,7 @@ static int is_valid_metadata_type (metadata_t type) { case META_VIDEO_BITRATE: case META_VIDEO_RESOLUTION: { - if (!sh_video) + if (!mpctx->sh_video) return 0; break; } @@ -451,7 +397,7 @@ static int is_valid_metadata_type (metadata_t type) { case META_AUDIO_BITRATE: case META_AUDIO_SAMPLES: { - if (!sh_audio) + if (!mpctx->sh_audio) return 0; break; } @@ -465,7 +411,7 @@ static int is_valid_metadata_type (metadata_t type) { case META_INFO_TRACK: case META_INFO_GENRE: { - if (!demuxer) + if (!mpctx->demuxer) return 0; break; } @@ -478,7 +424,7 @@ static int is_valid_metadata_type (metadata_t type) { } static char *get_demuxer_info (char *tag) { - char **info = demuxer->info; + char **info = mpctx->demuxer->info; int n; if (!info || !tag) @@ -493,10 +439,12 @@ static char *get_demuxer_info (char *tag) { char *get_metadata (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)) return NULL; - + switch (type) { case META_NAME: @@ -591,12 +539,10 @@ char *get_metadata (metadata_t type) { return meta; } -#include "mixer.h" -mixer_t mixer; /// step size of mixer changes int volstep = 3; -static void uninit_player(unsigned int mask){ +void uninit_player(unsigned int mask){ mask=inited_flags&mask; mp_msg(MSGT_CPLAYER,MSGL_DBG2,"\n*** uninit(0x%X)\n",mask); @@ -604,18 +550,18 @@ static void uninit_player(unsigned int mask){ if(mask&INITED_ACODEC){ inited_flags&=~INITED_ACODEC; current_module="uninit_acodec"; - if(sh_audio) uninit_audio(sh_audio); + if(mpctx->sh_audio) uninit_audio(mpctx->sh_audio); #ifdef HAVE_NEW_GUI guiGetEvent(guiSetAfilter, (char *)NULL); #endif - sh_audio=NULL; + mpctx->sh_audio=NULL; } if(mask&INITED_VCODEC){ inited_flags&=~INITED_VCODEC; current_module="uninit_vcodec"; - if(sh_video) uninit_video(sh_video); - sh_video=NULL; + if(mpctx->sh_video) uninit_video(mpctx->sh_video); + mpctx->sh_video=NULL; #ifdef HAVE_MENU vf_menu=NULL; #endif @@ -624,26 +570,26 @@ static void uninit_player(unsigned int mask){ if(mask&INITED_DEMUXER){ inited_flags&=~INITED_DEMUXER; current_module="free_demuxer"; - if(demuxer){ - stream=demuxer->stream; - free_demuxer(demuxer); + if(mpctx->demuxer){ + mpctx->stream=mpctx->demuxer->stream; + free_demuxer(mpctx->demuxer); } - demuxer=NULL; + mpctx->demuxer=NULL; } // kill the cache process: if(mask&INITED_STREAM){ inited_flags&=~INITED_STREAM; current_module="uninit_stream"; - if(stream) free_stream(stream); - stream=NULL; + if(mpctx->stream) free_stream(mpctx->stream); + mpctx->stream=NULL; } if(mask&INITED_VO){ inited_flags&=~INITED_VO; current_module="uninit_vo"; - video_out->uninit(); - video_out=NULL; + mpctx->video_out->uninit(); + mpctx->video_out=NULL; } // Must be after libvo uninit, as few vo drivers (svgalib) have tty code. @@ -672,8 +618,8 @@ static void uninit_player(unsigned int mask){ if(mask&INITED_AO){ inited_flags&=~INITED_AO; current_module="uninit_ao"; - if (user_muted | edl_muted) mixer_mute(&mixer); - audio_out->uninit(eof?0:1); audio_out=NULL; + if (mpctx->user_muted | mpctx->edl_muted) mixer_mute(&mpctx->mixer); + mpctx->audio_out->uninit(mpctx->eof?0:1); mpctx->audio_out=NULL; } #ifdef HAVE_NEW_GUI @@ -693,7 +639,7 @@ static void uninit_player(unsigned int mask){ current_module=NULL; } -static void exit_player_with_rc(const char* how, int rc){ +void exit_player_with_rc(const char* how, int rc){ uninit_player(INITED_ALL); #ifdef HAVE_X11 @@ -721,8 +667,8 @@ static void exit_player_with_rc(const char* how, int rc){ if(mconfig) m_config_free(mconfig); - if(playtree) - play_tree_free(playtree, 1); + if(mpctx->playtree) + play_tree_free(mpctx->playtree, 1); if(edl_records != NULL) free(edl_records); // free mem allocated for EDL @@ -896,7 +842,7 @@ static int libmpdemux_was_interrupted(int eof) { 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; + 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; @@ -926,22 +872,22 @@ int playtree_add_playlist(play_tree_t* entry) #endif { if(!entry) { - entry = playtree_iter->tree; - if(play_tree_iter_step(playtree_iter,1,0) != PLAY_TREE_ITER_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(playtree_iter->tree == entry ) { // Loop with a single file - if(play_tree_iter_up_step(playtree_iter,1,0) != PLAY_TREE_ITER_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; } } 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) { + 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); @@ -949,21 +895,6 @@ int playtree_add_playlist(play_tree_t* entry) 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; -} - void add_subtitles(char *filename, float fps, int silent) { sub_data *subd; @@ -971,7 +902,7 @@ void add_subtitles(char *filename, float fps, int silent) ass_track_t *asst = 0; #endif - if (filename == NULL || set_of_sub_size >= MAX_SUBTITLE_FILES) { + if (filename == NULL || mpctx->set_of_sub_size >= MAX_SUBTITLE_FILES) { return; } @@ -995,16 +926,16 @@ void add_subtitles(char *filename, float fps, int silent) #ifdef USE_ASS if (!asst && !subd) return; - set_of_ass_tracks[set_of_sub_size] = asst; + mpctx->set_of_ass_tracks[mpctx->set_of_sub_size] = asst; #else if (!subd) return; #endif - set_of_subtitles[set_of_sub_size] = subd; - mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_FILE_SUB_ID=%d\n", set_of_sub_size); + mpctx->set_of_subtitles[mpctx->set_of_sub_size] = subd; + 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)); - ++set_of_sub_size; - mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AddedSubtitleFile, set_of_sub_size, + ++mpctx->set_of_sub_size; + mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AddedSubtitleFile, mpctx->set_of_sub_size, filename_recode(filename)); } @@ -1012,20 +943,21 @@ void add_subtitles(char *filename, float fps, int silent) void update_set_of_subtitles(void) // subdata was changed, set_of_sub... have to be updated. { + sub_data ** const set_of_subtitles = mpctx->set_of_subtitles; 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) + if (mpctx->set_of_sub_size > 0 && subdata == NULL) { // *subdata was deleted + for (i = mpctx->set_of_sub_pos + 1; i < mpctx->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]; + set_of_subtitles[mpctx->set_of_sub_size-1] = NULL; + --mpctx->set_of_sub_size; + if (mpctx->set_of_sub_size > 0) subdata = set_of_subtitles[mpctx->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 (mpctx->set_of_sub_size > 0 && subdata != NULL) { // *subdata was changed + set_of_subtitles[mpctx->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; + else if (mpctx->set_of_sub_size <= 0 && subdata != NULL) { // *subdata was added + set_of_subtitles[mpctx->set_of_sub_pos=mpctx->set_of_sub_size] = subdata; + ++mpctx->set_of_sub_size; } } @@ -1042,24 +974,24 @@ void init_vo_spudec(void) { } #ifdef USE_DVDREAD - if (vo_spudec==NULL && stream->type==STREAMTYPE_DVD) { + if (vo_spudec==NULL && mpctx->stream->type==STREAMTYPE_DVD) { current_module="spudec_init_dvdread"; - vo_spudec=spudec_new_scaled(((dvd_priv_t *)(stream->priv))->cur_pgc->palette, - sh_video->disp_w, sh_video->disp_h); + vo_spudec=spudec_new_scaled(((dvd_priv_t *)(mpctx->stream->priv))->cur_pgc->palette, + mpctx->sh_video->disp_w, mpctx->sh_video->disp_h); } #endif #ifdef USE_DVDNAV - if (vo_spudec==NULL && stream->type==STREAMTYPE_DVDNAV) { - unsigned int *palette = mp_dvdnav_get_spu_clut(stream); + 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, sh_video->disp_w, sh_video->disp_h); + vo_spudec=spudec_new_scaled(palette, mpctx->sh_video->disp_w, mpctx->sh_video->disp_h); } #endif - if ((vo_spudec == NULL) && (demuxer->type == DEMUXER_TYPE_MATROSKA) && - (d_dvdsub->sh != NULL) && (((sh_sub_t *)d_dvdsub->sh)->type == 'v')) { - sh_sub_t *mkv_sh_sub = (sh_sub_t *)d_dvdsub->sh; + if ((vo_spudec == NULL) && (mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA) && + (mpctx->d_sub->sh != NULL) && (((sh_sub_t *)mpctx->d_sub->sh)->type == 'v')) { + sh_sub_t *mkv_sh_sub = (sh_sub_t *)mpctx->d_sub->sh; current_module = "spudec_init_matroska"; vo_spudec = spudec_new_scaled_vobsub(mkv_sh_sub->palette, mkv_sh_sub->colors, @@ -1069,12 +1001,12 @@ void init_vo_spudec(void) { } if (vo_spudec==NULL) { - sh_sub_t *sh = (sh_sub_t *)d_dvdsub->sh; + sh_sub_t *sh = (sh_sub_t *)mpctx->d_sub->sh; unsigned int *palette = NULL; if (sh && sh->has_palette) palette = sh->palette; current_module="spudec_init_normal"; - vo_spudec=spudec_new_scaled(palette, sh_video->disp_w, sh_video->disp_h); + vo_spudec=spudec_new_scaled(palette, mpctx->sh_video->disp_w, mpctx->sh_video->disp_h); spudec_set_font_factor(vo_spudec,font_factor); } @@ -1142,6 +1074,7 @@ static void sadd_hhmmssf(char *buf, unsigned *pos, int len, float time) { */ static void print_status(float a_pos, float a_v, float corr) { + sh_video_t * const sh_video = mpctx->sh_video; int width; char *line; unsigned pos = 0; @@ -1158,10 +1091,10 @@ static void print_status(float a_pos, float a_v, float corr) line = malloc(width + 1); // one additional char for the terminating null // Audio time - if (sh_audio) { + if (mpctx->sh_audio) { saddf(line, &pos, width, "A:%6.1f ", a_pos); if (!sh_video) { - float len = demuxer_get_time_length(demuxer); + float len = demuxer_get_time_length(mpctx->demuxer); saddf(line, &pos, width, "("); sadd_hhmmssf(line, &pos, width, a_pos); saddf(line, &pos, width, ") of %.1f (", len); @@ -1175,7 +1108,7 @@ static void print_status(float a_pos, float a_v, float corr) saddf(line, &pos, width, "V:%6.1f ", sh_video->pts); // A-V sync - if (sh_audio && sh_video) + if (mpctx->sh_audio && sh_video) saddf(line, &pos, width, "A-V:%7.3f ct:%7.3f ", a_v, corr); // Video stats @@ -1193,10 +1126,10 @@ static void print_status(float a_pos, float a_v, float corr) (100.0*audio_time_usage*playback_speed/(double)sh_video->timer)); else saddf(line, &pos, width, "??%% ??%% ??,?%% "); - } else if (sh_audio) { - if (sh_audio->delay > 0.5) + } else if (mpctx->sh_audio) { + if (mpctx->sh_audio->delay > 0.5) saddf(line, &pos, width, "%4.1f%% ", - 100.0*audio_time_usage/(double)sh_audio->delay); + 100.0*audio_time_usage/(double)mpctx->sh_audio->delay); else saddf(line, &pos, width, "??,?%% "); } @@ -1233,7 +1166,7 @@ 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. */ -static int build_afilter_chain(sh_audio_t *sh_audio, ao_data_t *ao_data) +int build_afilter_chain(sh_audio_t *sh_audio, ao_data_t *ao_data) { int new_srate; int result; @@ -1242,7 +1175,7 @@ static int build_afilter_chain(sh_audio_t *sh_audio, ao_data_t *ao_data) #ifdef HAVE_NEW_GUI guiGetEvent(guiSetAfilter, (char *)NULL); #endif - mixer.afilter = NULL; + mpctx->mixer.afilter = NULL; return 0; } new_srate = sh_audio->samplerate * playback_speed; @@ -1258,63 +1191,13 @@ static int build_afilter_chain(sh_audio_t *sh_audio, ao_data_t *ao_data) sh_audio->channels, sh_audio->sample_format, &ao_data->samplerate, &ao_data->channels, &ao_data->format, ao_data->outburst * 4, ao_data->buffersize); - mixer.afilter = sh_audio->afilter; + mpctx->mixer.afilter = sh_audio->afilter; #ifdef HAVE_NEW_GUI guiGetEvent(guiSetAfilter, (char *)sh_audio->afilter); #endif return result; } -/** - * \brief Log the currently displayed subtitle to a file - * - * Logs the current or last displayed subtitle together with filename - * and time information to ~/.mplayer/subtitle_log - * - * Intended purpose is to allow convenient marking of bogus subtitles - * which need to be fixed while watching the movie. - */ - -static void log_sub(void){ - char *fname; - FILE *f; - int i; - - if (subdata == NULL || vo_sub_last == NULL) return; - fname = get_path("subtitle_log"); - f = fopen(fname, "a"); - if (!f) return; - fprintf(f, "----------------------------------------------------------\n"); - if (subdata->sub_uses_time) { - fprintf(f, "N: %s S: %02ld:%02ld:%02ld.%02ld E: %02ld:%02ld:%02ld.%02ld\n", filename, - vo_sub_last->start/360000, (vo_sub_last->start/6000)%60, - (vo_sub_last->start/100)%60, vo_sub_last->start%100, - vo_sub_last->end/360000, (vo_sub_last->end/6000)%60, - (vo_sub_last->end/100)%60, vo_sub_last->end%100); - } else { - fprintf(f, "N: %s S: %ld E: %ld\n", filename, vo_sub_last->start, vo_sub_last->end); - } - for (i = 0; i < vo_sub_last->lines; i++) { - fprintf(f, "%s\n", vo_sub_last->text[i]); - } - fclose(f); -} - -/// \defgroup OSDMsgStack OSD message stack -/// -///@{ - -#define OSD_MSG_TV_CHANNEL 0 -#define OSD_MSG_TEXT 1 -#define OSD_MSG_SUB_DELAY 2 -#define OSD_MSG_SPEED 3 -#define OSD_MSG_OSD_STATUS 4 -#define OSD_MSG_BAR 5 -#define OSD_MSG_PAUSE 6 -#define OSD_MSG_RADIO_CHANNEL 7 -/// Base id for messages generated from the commmand to property bridge. -#define OSD_MSG_PROPERTY 0x100 - typedef struct mp_osd_msg mp_osd_msg_t; struct mp_osd_msg { @@ -1338,7 +1221,7 @@ static mp_osd_msg_t* osd_msg_stack = NULL; * */ -static void set_osd_msg(int id, int level, int time, const char* fmt, ...) { +void set_osd_msg(int id, int level, int time, const char* fmt, ...) { mp_osd_msg_t *msg,*last=NULL; va_list va; int r; @@ -1375,7 +1258,7 @@ static void set_osd_msg(int id, int level, int time, const char* fmt, ...) { * */ -static void rm_osd_msg(int id) { +void rm_osd_msg(int id) { mp_osd_msg_t *msg,*last=NULL; // Search for the msg @@ -1461,11 +1344,11 @@ static mp_osd_msg_t* get_osd_msg(void) { * */ -static void set_osd_bar(int type,const char* name,double min,double max,double val) { +void set_osd_bar(int type,const char* name,double min,double max,double val) { if(osd_level < 1) return; - if(sh_video) { + if(mpctx->sh_video) { osd_visible = (GetTimerMS() + 1000) | 1; vo_osd_progbar_type = type; vo_osd_progbar_value = 256*(val-min)/(max-min); @@ -1499,22 +1382,22 @@ static void update_osd_msg(void) { if((msg = get_osd_msg())) { if(strcmp(osd_text,msg->msg)) { strncpy((char*)osd_text, msg->msg, 63); - if(sh_video) vo_osd_changed(OSDTYPE_OSD); else + 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); } return; } - if(sh_video) { + if(mpctx->sh_video) { // fallback on the timer if(osd_level>=2) { - int len = demuxer_get_time_length(demuxer); + int len = demuxer_get_time_length(mpctx->demuxer); int percentage = -1; char percentage_text[10]; - int pts = demuxer_get_current_time(demuxer); + int pts = demuxer_get_current_time(mpctx->demuxer); - if (osd_show_percentage) - percentage = demuxer_get_percent_pos(demuxer); + if (mpctx->osd_show_percentage) + percentage = demuxer_get_percent_pos(mpctx->demuxer); if (percentage >= 0) snprintf(percentage_text, 9, " (%d%%)", percentage); @@ -1524,18 +1407,18 @@ static void update_osd_msg(void) { if (osd_level == 3) snprintf(osd_text_timer, 63, "%c %02d:%02d:%02d / %02d:%02d:%02d%s", - osd_function,pts/3600,(pts/60)%60,pts%60, + mpctx->osd_function,pts/3600,(pts/60)%60,pts%60, len/3600,(len/60)%60,len%60,percentage_text); else snprintf(osd_text_timer, 63, "%c %02d:%02d:%02d%s", - osd_function,pts/3600,(pts/60)%60, + mpctx->osd_function,pts/3600,(pts/60)%60, pts%60,percentage_text); } else osd_text_timer[0]=0; // always decrement the percentage timer - if(osd_show_percentage) - osd_show_percentage--; + if(mpctx->osd_show_percentage) + mpctx->osd_show_percentage--; if(strcmp(osd_text,osd_text_timer)) { strncpy(osd_text, osd_text_timer, 63); @@ -1554,1217 +1437,14 @@ static void update_osd_msg(void) { ///@} // OSDMsgStack -/// \defgroup Properties -///@{ - -/// \defgroup GeneralProperties General properties -/// \ingroup Properties -///@{ - -/// OSD level (RW) -static int mp_property_osdlevel(m_option_t* prop,int action,void* arg) { - return m_property_choice(prop,action,arg,&osd_level); -} - -/// Playback speed (RW) -static int mp_property_playback_speed(m_option_t* prop,int action,void* arg) { - switch(action) { - case M_PROPERTY_SET: - if(!arg) return M_PROPERTY_ERROR; - M_PROPERTY_CLAMP(prop,*(float*)arg); - playback_speed = *(float*)arg; - build_afilter_chain(sh_audio, &ao_data); - return M_PROPERTY_OK; - case M_PROPERTY_STEP_UP: - case M_PROPERTY_STEP_DOWN: - playback_speed += (arg ? *(float*)arg : 0.1) * - (action == M_PROPERTY_STEP_DOWN ? -1 : 1); - M_PROPERTY_CLAMP(prop,playback_speed); - build_afilter_chain(sh_audio, &ao_data); - return M_PROPERTY_OK; - } - return m_property_float_range(prop,action,arg,&playback_speed); -} - -/// filename with path (RO) -static int mp_property_path(m_option_t* prop,int action,void* arg) { - return m_property_string_ro(prop,action,arg,filename); -} - -/// filename without path (RO) -static int mp_property_filename(m_option_t* prop,int action,void* arg) { - char* f; - if(!filename) return M_PROPERTY_UNAVAILABLE; - if(((f = strrchr(filename,'/')) || (f = strrchr(filename,'\\'))) && f[1]) - f++; - else - f = filename; - return m_property_string_ro(prop,action,arg,f); -} - -/// Demuxer name (RO) -static int mp_property_demuxer(m_option_t* prop,int action,void* arg) { - if(!demuxer) return M_PROPERTY_UNAVAILABLE; - return m_property_string_ro(prop,action,arg,(char*)demuxer->desc->name); -} - -/// Position in the stream (RW) -static int mp_property_stream_pos(m_option_t* prop,int action,void* arg) { - if (!demuxer || !demuxer->stream) return M_PROPERTY_UNAVAILABLE; - if (!arg) return M_PROPERTY_ERROR; - switch (action) { - case M_PROPERTY_GET: - *(off_t*)arg = stream_tell(demuxer->stream); - return M_PROPERTY_OK; - case M_PROPERTY_SET: - M_PROPERTY_CLAMP(prop,*(off_t*)arg); - stream_seek(demuxer->stream, *(off_t*)arg); - return M_PROPERTY_OK; - } - return M_PROPERTY_NOT_IMPLEMENTED; -} - -/// Stream start offset (RO) -static int mp_property_stream_start(m_option_t* prop,int action,void* arg) { - if (!demuxer || !demuxer->stream) return M_PROPERTY_UNAVAILABLE; - switch (action) { - case M_PROPERTY_GET: - *(off_t*)arg = demuxer->stream->start_pos; - return M_PROPERTY_OK; - } - return M_PROPERTY_NOT_IMPLEMENTED; -} - -/// Stream end offset (RO) -static int mp_property_stream_end(m_option_t* prop,int action,void* arg) { - if (!demuxer || !demuxer->stream) return M_PROPERTY_UNAVAILABLE; - switch (action) { - case M_PROPERTY_GET: - *(off_t*)arg = demuxer->stream->end_pos; - return M_PROPERTY_OK; - } - return M_PROPERTY_NOT_IMPLEMENTED; -} - -/// Stream length (RO) -static int mp_property_stream_length(m_option_t* prop,int action,void* arg) { - if (!demuxer || !demuxer->stream) return M_PROPERTY_UNAVAILABLE; - switch (action) { - case M_PROPERTY_GET: - *(off_t*)arg = demuxer->stream->end_pos - demuxer->stream->start_pos; - return M_PROPERTY_OK; - } - return M_PROPERTY_NOT_IMPLEMENTED; -} - -/// Media length in seconds (RO) -static int mp_property_length(m_option_t* prop,int action,void* arg) { - double len; - - if(!demuxer || - !(int)(len = demuxer_get_time_length(demuxer))) - return M_PROPERTY_UNAVAILABLE; - - switch(action) { - case M_PROPERTY_PRINT: - if(!arg) return M_PROPERTY_ERROR; - else { - int h, m, s = len; - h = s/3600; - s -= h*3600; - m = s/60; - s -= m*60; - *(char**)arg = malloc(20); - if(h > 0) sprintf(*(char**)arg,"%d:%02d:%02d",h,m,s); - else if(m > 0) sprintf(*(char**)arg,"%d:%02d",m,s); - else sprintf(*(char**)arg,"%d",s); - return M_PROPERTY_OK; - } - break; - } - return m_property_double_ro(prop,action,arg,len); -} - -///@} - -/// \defgroup AudioProperties Audio properties -/// \ingroup Properties -///@{ - -/// Volume (RW) -static int mp_property_volume(m_option_t* prop,int action,void* arg) { - - if(!sh_audio) return M_PROPERTY_UNAVAILABLE; - - switch(action) { - case M_PROPERTY_GET: - if(!arg) return M_PROPERTY_ERROR; - mixer_getbothvolume(&mixer,arg); - return M_PROPERTY_OK; - case M_PROPERTY_PRINT:{ - float vol; - if(!arg) return M_PROPERTY_ERROR; - mixer_getbothvolume(&mixer,&vol); - return m_property_float_range(prop,action,arg,&vol); - } - case M_PROPERTY_STEP_UP: - case M_PROPERTY_STEP_DOWN: - case M_PROPERTY_SET: - break; - default: - return M_PROPERTY_NOT_IMPLEMENTED; - } - - if (edl_muted) return M_PROPERTY_DISABLED; - user_muted = 0; - - switch(action) { - case M_PROPERTY_SET: - if(!arg) return M_PROPERTY_ERROR; - M_PROPERTY_CLAMP(prop,*(float*)arg); - mixer_setvolume(&mixer,*(float*)arg,*(float*)arg); - return M_PROPERTY_OK; - case M_PROPERTY_STEP_UP: - if(arg && *(float*)arg <= 0) - mixer_decvolume(&mixer); - else - mixer_incvolume(&mixer); - return M_PROPERTY_OK; - case M_PROPERTY_STEP_DOWN: - if(arg && *(float*)arg <= 0) - mixer_incvolume(&mixer); - else - mixer_decvolume(&mixer); - return M_PROPERTY_OK; - } - return M_PROPERTY_NOT_IMPLEMENTED; -} - -/// Mute (RW) -static int mp_property_mute(m_option_t* prop,int action,void* arg) { - - if(!sh_audio) return M_PROPERTY_UNAVAILABLE; - - switch(action) { - case M_PROPERTY_SET: - if(edl_muted) return M_PROPERTY_DISABLED; - if(!arg) return M_PROPERTY_ERROR; - if((!!*(int*)arg) != mixer.muted) - mixer_mute(&mixer); - user_muted = mixer.muted; - return M_PROPERTY_OK; - case M_PROPERTY_STEP_UP: - case M_PROPERTY_STEP_DOWN: - if(edl_muted) return M_PROPERTY_DISABLED; - mixer_mute(&mixer); - user_muted = mixer.muted; - return M_PROPERTY_OK; - case M_PROPERTY_PRINT: - if(!arg) return M_PROPERTY_ERROR; - if(edl_muted) { - *(char**)arg = strdup(MSGTR_EnabledEdl); - return M_PROPERTY_OK; - } - default: - return m_property_flag(prop,action,arg,&mixer.muted); - - } -} - -/// Audio delay (RW) -static int mp_property_audio_delay(m_option_t* prop,int action,void* arg) { - if(!(sh_audio && sh_video)) return M_PROPERTY_UNAVAILABLE; - switch(action) { - case M_PROPERTY_SET: - case M_PROPERTY_STEP_UP: - case M_PROPERTY_STEP_DOWN: - if(!arg) return M_PROPERTY_ERROR; - else { - float delay = audio_delay; - m_property_delay(prop,action,arg,&audio_delay); - if(sh_audio) sh_audio->delay -= audio_delay-delay; - } - return M_PROPERTY_OK; - default: - return m_property_delay(prop,action,arg,&audio_delay); - } -} - -/// Audio codec tag (RO) -static int mp_property_audio_format(m_option_t* prop,int action,void* arg) { - if(!sh_audio) return M_PROPERTY_UNAVAILABLE; - return m_property_int_ro(prop,action,arg,sh_audio->format); -} -/// Audio bitrate (RO) -static int mp_property_audio_bitrate(m_option_t* prop,int action,void* arg) { - if(!sh_audio) return M_PROPERTY_UNAVAILABLE; - return m_property_int_ro(prop,action,arg,sh_audio->i_bps); -} - -/// Samplerate (RO) -static int mp_property_samplerate(m_option_t* prop,int action,void* arg) { - if(!sh_audio) return M_PROPERTY_UNAVAILABLE; - return m_property_int_ro(prop,action,arg,sh_audio->samplerate); -} - -/// Number of channels (RO) -static int mp_property_channels(m_option_t* prop,int action,void* arg) { - if(!sh_audio) return M_PROPERTY_UNAVAILABLE; - switch(action) { - case M_PROPERTY_PRINT: - if(!arg) return M_PROPERTY_ERROR; - switch(sh_audio->channels) { - case 1: *(char**)arg = strdup("mono"); break; - case 2: *(char**)arg = strdup("stereo"); break; - default: - *(char**)arg = malloc(32); - sprintf(*(char**)arg,"%d channels",sh_audio->channels); - } - return M_PROPERTY_OK; - } - return m_property_int_ro(prop,action,arg,sh_audio->channels); -} - -/// Selected audio id (RW) -static int mp_property_audio(m_option_t* prop,int action,void* arg) { - int current_id = -1, tmp; - - switch(action) { - case M_PROPERTY_GET: - if(!sh_audio) return M_PROPERTY_UNAVAILABLE; - if(!arg) return M_PROPERTY_ERROR; - *(int*)arg = audio_id; - return M_PROPERTY_OK; - case M_PROPERTY_PRINT: - if(!sh_audio) return M_PROPERTY_UNAVAILABLE; - if(!arg) |