From 1663d97a112261c10f989b70547545048f9e31c3 Mon Sep 17 00:00:00 2001 From: reimar Date: Sat, 10 Jul 2010 20:48:50 +0000 Subject: subs: Change global subtitle numbering scheme Change numbering so that demuxers can "asynchronously" add subtitles during playback. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31678 b3059339-0415-0410-9bf9-f77b7e298cf2 Fix calculation of global_sub_size. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31711 b3059339-0415-0410-9bf9-f77b7e298cf2 Update global_sub_pos if we auto-selected a subtitle. This avoid strange behaviour with subtitle selection in that case, because the subtitle selection code thinks no subtitle was displayed while we actually did display one. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31863 b3059339-0415-0410-9bf9-f77b7e298cf2 Move function to avoid a forward declaration. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31864 b3059339-0415-0410-9bf9-f77b7e298cf2 Fix subtitle selection: make selecting -sid 0 work again by replacing the M_PROPERTY_STEP_UP hack by M_PROPERTY_SET and set the global sub pos also when we do not yet have a subtitle stream but do know the number of subs from out-of-band as e.g. for DVD. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31882 b3059339-0415-0410-9bf9-f77b7e298cf2 100l, re-add vobsub_get_id_by_index call accidentally removed in r31678. Patch by ubitux [ubitux gmail com]. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31985 b3059339-0415-0410-9bf9-f77b7e298cf2 --- mplayer.c | 76 +++++++++++++++++++++++++++------------------------------------ 1 file changed, 32 insertions(+), 44 deletions(-) (limited to 'mplayer.c') diff --git a/mplayer.c b/mplayer.c index ad25bd9cbd..f29edd7021 100644 --- a/mplayer.c +++ b/mplayer.c @@ -1949,33 +1949,43 @@ static float timing_sleep(struct MPContext *mpctx, float time_frame) return time_frame; } -static void select_subtitle(MPContext *mpctx) +static int select_subtitle(MPContext *mpctx) { struct MPOpts *opts = &mpctx->opts; // find the best sub to use - int vobsub_index_id = vobsub_get_index_by_id(vo_vobsub, vobsub_id); + int id; + int found = 0; mpctx->global_sub_pos = -1; // no subs by default - if (vobsub_index_id >= 0) { + if (vobsub_id >= 0) { // if user asks for a vobsub id, use that first. - mpctx->global_sub_pos = mpctx->global_sub_indices[SUB_SOURCE_VOBSUB] + vobsub_index_id; - } else if (opts->sub_id >= 0 && mpctx->global_sub_indices[SUB_SOURCE_DEMUX] >= 0) { + id = vobsub_id; + found = mp_property_do("sub_vob", M_PROPERTY_SET, &id, mpctx) == M_PROPERTY_OK; + } + + if (!found && opts->sub_id >= 0) { // if user asks for a dvd sub id, use that next. - mpctx->global_sub_pos = mpctx->global_sub_indices[SUB_SOURCE_DEMUX] + opts->sub_id; - } else if (mpctx->global_sub_indices[SUB_SOURCE_SUBS] >= 0) { + id = opts->sub_id; + found = mp_property_do("sub_demux", M_PROPERTY_SET, &id, mpctx) == M_PROPERTY_OK; + } + + if (!found) { // if there are text subs to use, use those. (autosubs come last here) - mpctx->global_sub_pos = mpctx->global_sub_indices[SUB_SOURCE_SUBS]; - } else if (opts->sub_id == -1 && mpctx->global_sub_indices[SUB_SOURCE_DEMUX] >= 0) { + id = 0; + found = mp_property_do("sub_file", M_PROPERTY_SET, &id, mpctx) == M_PROPERTY_OK; + } + + if (!found && opts->sub_id == -1) { // finally select subs by language and container hints if (opts->sub_id == -1 && opts->sub_lang) opts->sub_id = demuxer_sub_track_by_lang(mpctx->demuxer, opts->sub_lang); if (opts->sub_id == -1) opts->sub_id = demuxer_default_sub_track(mpctx->demuxer); - if (opts->sub_id >= 0) - mpctx->global_sub_pos = mpctx->global_sub_indices[SUB_SOURCE_DEMUX] + opts->sub_id; + if (opts->sub_id >= 0) { + id = opts->sub_id; + found = mp_property_do("sub_demux", M_PROPERTY_SET, &id, mpctx) == M_PROPERTY_OK; + } } - // rather than duplicate code, use the SUB_SELECT handler to init the right one. - mpctx->global_sub_pos--; - mp_property_do("sub",M_PROPERTY_STEP_UP,NULL, mpctx); + return found; } #ifdef CONFIG_DVDNAV @@ -2035,7 +2045,7 @@ static void mp_dvdnav_reset_stream (MPContext *ctx) { } audio_delay = 0.0f; - ctx->global_sub_size = ctx->global_sub_indices[SUB_SOURCE_DEMUX] + mp_dvdnav_number_of_subs(ctx->stream); + ctx->sub_counts[SUB_SOURCE_DEMUX] = mp_dvdnav_number_of_subs(ctx->stream); if (opts->sub_lang && opts->sub_id == dvdsub_lang_id) { dvdsub_lang_id = mp_dvdnav_sid_from_lang(ctx->stream, opts->sub_lang); if (dvdsub_lang_id != opts->sub_id) { @@ -3438,7 +3448,7 @@ play_next_file: // init global sub numbers mpctx->global_sub_size = 0; - { int i; for (i = 0; i < SUB_SOURCES; i++) mpctx->global_sub_indices[i] = -1; } + memset(mpctx->sub_counts, 0, sizeof(mpctx->sub_counts)); if (mpctx->filename) { load_per_protocol_config (mpctx->mconfig, mpctx->filename); @@ -3586,8 +3596,7 @@ if (edl_output_filename) { mp_property_do("sub_forced_only", M_PROPERTY_SET, &forced_subs_only, mpctx); // setup global sub numbering - mpctx->global_sub_indices[SUB_SOURCE_VOBSUB] = mpctx->global_sub_size; // the global # of the first vobsub. - mpctx->global_sub_size += vobsub_get_indexes_count(vo_vobsub); + mpctx->sub_counts[SUB_SOURCE_VOBSUB] = vobsub_get_indexes_count(vo_vobsub); } //============ Open & Sync STREAM --- fork cache2 ==================== @@ -3677,8 +3686,7 @@ if(mpctx->stream->type==STREAMTYPE_DVD){ if(opts->audio_id==-1) opts->audio_id=dvd_aid_from_lang(mpctx->stream,opts->audio_lang); if(opts->sub_lang && opts->sub_id==-1) opts->sub_id=dvd_sid_from_lang(mpctx->stream,opts->sub_lang); // setup global sub numbering - mpctx->global_sub_indices[SUB_SOURCE_DEMUX] = mpctx->global_sub_size; // the global # of the first demux-specific sub. - mpctx->global_sub_size += dvd_number_of_subs(mpctx->stream); + mpctx->sub_counts[SUB_SOURCE_DEMUX] = dvd_number_of_subs(mpctx->stream); current_module=NULL; } #endif @@ -3691,8 +3699,7 @@ if(mpctx->stream->type==STREAMTYPE_DVDNAV){ if(opts->sub_lang && opts->sub_id==-1) dvdsub_lang_id = opts->sub_id = mp_dvdnav_sid_from_lang(mpctx->stream,opts->sub_lang); // setup global sub numbering - mpctx->global_sub_indices[SUB_SOURCE_DEMUX] = mpctx->global_sub_size; // the global # of the first demux-specific sub. - mpctx->global_sub_size += mp_dvdnav_number_of_subs(mpctx->stream); + mpctx->sub_counts[SUB_SOURCE_DEMUX] = mp_dvdnav_number_of_subs(mpctx->stream); current_module=NULL; } #endif @@ -3790,20 +3797,6 @@ if(!mpctx->demuxer) mpctx->initialized_flags|=INITIALIZED_DEMUXER; -if (mpctx->stream->type != STREAMTYPE_DVD && mpctx->stream->type != STREAMTYPE_DVDNAV) { - int i; - int maxid = -1; - // setup global sub numbering - mpctx->global_sub_indices[SUB_SOURCE_DEMUX] = mpctx->global_sub_size; // the global # of the first demux-specific sub. - for (i = 0; i < MAX_S_STREAMS; i++) - if (mpctx->demuxer->s_streams[i]) - maxid = FFMAX(maxid, mpctx->demuxer->s_streams[i]->sid); - mpctx->global_sub_size += maxid + 1; -} -// Make opts->sub_id always selectable if set. -if (mpctx->global_sub_size <= mpctx->global_sub_indices[SUB_SOURCE_DEMUX] + opts->sub_id) - mpctx->global_sub_size = mpctx->global_sub_indices[SUB_SOURCE_DEMUX] + opts->sub_id + 1; - #ifdef CONFIG_ASS if (opts->ass_enabled && ass_library) { for (int j = 0; j < mpctx->num_sources; j++) { @@ -3959,15 +3952,10 @@ if(vo_spudec==NULL && } free(tmp); } - if (mpctx->set_of_sub_size > 0) { - // setup global sub numbering - mpctx->global_sub_indices[SUB_SOURCE_SUBS] = mpctx->global_sub_size; // the global # of the first sub. - mpctx->global_sub_size += mpctx->set_of_sub_size; - } - + if (mpctx->set_of_sub_size > 0) + mpctx->sub_counts[SUB_SOURCE_SUBS] = mpctx->set_of_sub_size; -if (mpctx->global_sub_size) { - select_subtitle(mpctx); +if (select_subtitle(mpctx)) { if(subdata) switch (stream_dump_type) { case 3: list_sub_file(subdata); break; -- cgit v1.2.3