From b26fbeddd85aae6cda93d01335bed5f108a3ff57 Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Tue, 11 Jan 2011 17:28:10 +0200 Subject: options: move -noconfig to option struct, simplify --- cfg-common.h | 3 ++- mpcommon.c | 19 ------------------- mpcommon.h | 3 --- mplayer.c | 5 +++-- options.h | 1 + 5 files changed, 6 insertions(+), 25 deletions(-) diff --git a/cfg-common.h b/cfg-common.h index 7657864f02..e71ec8c0df 100644 --- a/cfg-common.h +++ b/cfg-common.h @@ -381,7 +381,8 @@ const m_option_t common_opts[] = { {"priority", &proc_priority, CONF_TYPE_STRING, 0, 0, 0, NULL}, #endif {"codecpath", &codec_path, CONF_TYPE_STRING, 0, 0, 0, NULL}, - {"noconfig", (void *) noconfig_opts, CONF_TYPE_SUBCONFIG, CONF_GLOBAL|CONF_NOCFG|CONF_PRE_PARSE, 0, 0, NULL}, + OPT_CHOICE("noconfig", noconfig, CONF_GLOBAL | CONF_NOCFG | CONF_PRE_PARSE, + ({"off", 0}, {"user", 1}, {"system", 2}, {"all", 3})), // ------------------------- stream options -------------------- diff --git a/mpcommon.c b/mpcommon.c index 2fa7b6d0a8..a5e71b839e 100644 --- a/mpcommon.c +++ b/mpcommon.c @@ -346,22 +346,3 @@ bool attachment_is_font(struct demux_attachment *att) } return false; } - -/* Parse -noconfig common to both programs */ -int disable_system_conf=0; -int disable_user_conf=0; - -/* Disable all configuration files */ -static void noconfig_all(void) -{ - disable_system_conf = 1; - disable_user_conf = 1; -} - -const m_option_t noconfig_opts[] = { - {"all", noconfig_all, CONF_TYPE_FUNC, CONF_GLOBAL|CONF_NOCFG|CONF_PRE_PARSE, 0, 0, NULL}, - {"system", &disable_system_conf, CONF_TYPE_FLAG, CONF_GLOBAL|CONF_NOCFG|CONF_PRE_PARSE, 0, 1, NULL}, - {"user", &disable_user_conf, CONF_TYPE_FLAG, CONF_GLOBAL|CONF_NOCFG|CONF_PRE_PARSE, 0, 1, NULL}, - {NULL, NULL, 0, 0, 0, 0, NULL} -}; - diff --git a/mpcommon.h b/mpcommon.h index f1f01d7942..5f11c5e458 100644 --- a/mpcommon.h +++ b/mpcommon.h @@ -27,9 +27,6 @@ extern double sub_last_pts; extern struct ass_track *ass_track; extern struct subtitle *vo_sub_last; -extern int disable_system_conf; -extern int disable_user_conf; - extern const char *mencoder_version; extern const char *mplayer_version; diff --git a/mplayer.c b/mplayer.c index 893ae77694..6565f75904 100644 --- a/mplayer.c +++ b/mplayer.c @@ -869,9 +869,10 @@ static int cfg_include(m_option_t *conf, char *filename) static void parse_cfgfiles(struct MPContext *mpctx, m_config_t* conf) { + struct MPOpts *opts = &mpctx->opts; char *conffile; int conffile_fd; -if (!disable_system_conf && + 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) { @@ -891,7 +892,7 @@ if ((conffile = get_path("")) == NULL) { write(conffile_fd, default_config, strlen(default_config)); close(conffile_fd); } - if (!disable_user_conf && + if (!(opts->noconfig & 1) && m_config_parse_config_file(conf, conffile) < 0) exit_player(mpctx, EXIT_NONE); free(conffile); diff --git a/options.h b/options.h index 12ac475f9e..0fb0a7d809 100644 --- a/options.h +++ b/options.h @@ -39,6 +39,7 @@ typedef struct MPOpts { int ordered_chapters; int chapter_merge_threshold; int quiet; + int noconfig; float stream_cache_min_percent; float stream_cache_seek_min_percent; int chapterrange[2]; -- cgit v1.2.3 From f95674fb6cbd459e6b484caf94b490b7efede9d5 Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Tue, 11 Jan 2011 17:35:28 +0200 Subject: subtitles: remove sub_last_pts hack This code was probably added because of bad pts handling in old timing code, and should not be needed any more. --- mpcommon.c | 12 +++--------- mpcommon.h | 1 - 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/mpcommon.c b/mpcommon.c index a5e71b839e..a7e89d9ee1 100644 --- a/mpcommon.c +++ b/mpcommon.c @@ -40,8 +40,6 @@ #include "ffmpeg_files/intreadwrite.h" #include "m_option.h" -double sub_last_pts = -303; - #ifdef CONFIG_ASS #include "ass_mp.h" ASS_Track *ass_track = 0; // current track to render @@ -128,13 +126,9 @@ void update_subtitles(struct MPContext *mpctx, struct MPOpts *opts, if (subdata) { if (sub_fps==0) sub_fps = sh_video ? sh_video->fps : 25; current_module = "find_sub"; - if (refpts > sub_last_pts || refpts < sub_last_pts-1.0) { - find_sub(mpctx, subdata, curpts * - (subdata->sub_uses_time ? 100. : sub_fps)); - if (vo_sub) vo_sub_last = vo_sub; - // FIXME! frame counter... - sub_last_pts = refpts; - } + find_sub(mpctx, subdata, curpts * + (subdata->sub_uses_time ? 100. : sub_fps)); + if (vo_sub) vo_sub_last = vo_sub; } // DVD sub: diff --git a/mpcommon.h b/mpcommon.h index 5f11c5e458..e0baee4f8d 100644 --- a/mpcommon.h +++ b/mpcommon.h @@ -23,7 +23,6 @@ struct subtitle; -extern double sub_last_pts; extern struct ass_track *ass_track; extern struct subtitle *vo_sub_last; -- cgit v1.2.3 From a1692437d0a2cc88a2b3440bbcfb5e6f66cfd90e Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Tue, 11 Jan 2011 17:48:45 +0200 Subject: core: move global "subdata" and "vo_sub_last" to mpctx --- command.c | 17 +++++++++-------- libvo/sub.h | 1 - mp_core.h | 3 +++ mpcommon.c | 13 ++++++------- mpcommon.h | 1 - mplayer.c | 18 +++++++++--------- 6 files changed, 27 insertions(+), 26 deletions(-) diff --git a/command.c b/command.c index 4408a584a6..238e62cd04 100644 --- a/command.c +++ b/command.c @@ -193,15 +193,16 @@ static void log_sub(struct MPContext *mpctx) char *fname; FILE *f; int i; + struct subtitle *vo_sub_last = mpctx->vo_sub_last; - if (subdata == NULL || vo_sub_last == NULL) + if (mpctx->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) { + if (mpctx->subdata->sub_uses_time) { fprintf(f, "N: %s S: %02ld:%02ld:%02ld.%02ld E: %02ld:%02ld:%02ld.%02ld\n", mpctx->filename, vo_sub_last->start / 360000, @@ -1542,8 +1543,8 @@ static int mp_property_sub(m_option_t *prop, int action, void *arg, *(char **) arg = malloc(64); (*(char **) arg)[63] = 0; sub_name = 0; - if (subdata) - sub_name = subdata->filename; + if (mpctx->subdata) + sub_name = mpctx->subdata->filename; #ifdef CONFIG_ASS if (ass_track && ass_track->name) sub_name = ass_track->name; @@ -1644,7 +1645,7 @@ static int mp_property_sub(m_option_t *prop, int action, void *arg, mpctx->global_sub_pos, source); mpctx->set_of_sub_pos = -1; - subdata = NULL; + mpctx->subdata = NULL; vobsub_id = -1; opts->sub_id = -1; @@ -1667,7 +1668,7 @@ static int mp_property_sub(m_option_t *prop, int action, void *arg, else #endif { - subdata = mpctx->set_of_subtitles[mpctx->set_of_sub_pos]; + mpctx->subdata = mpctx->set_of_subtitles[mpctx->set_of_sub_pos]; vo_osd_changed(OSDTYPE_SUBTITLE); } } else if (source == SUB_SOURCE_DEMUX) { @@ -2692,7 +2693,7 @@ static void remove_subtitle_range(MPContext *mpctx, int start, int count) if (mpctx->set_of_sub_pos >= start && mpctx->set_of_sub_pos < end) { mpctx->global_sub_pos = -2; - subdata = NULL; + mpctx->subdata = NULL; #ifdef CONFIG_ASS ass_track = NULL; #endif @@ -2931,7 +2932,7 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd) case MP_CMD_SUB_STEP: if (sh_video) { int movement = cmd->args[0].v.i; - step_sub(subdata, mpctx->video_pts, movement); + step_sub(mpctx->subdata, mpctx->video_pts, movement); #ifdef CONFIG_ASS if (ass_track) sub_delay += diff --git a/libvo/sub.h b/libvo/sub.h index d5a30e0b86..f3a6f072c2 100644 --- a/libvo/sub.h +++ b/libvo/sub.h @@ -73,7 +73,6 @@ struct osd_state { #include "subreader.h" -extern sub_data* subdata; //currently used subtitles extern subtitle* vo_sub; extern void* vo_osd_teletext_page; diff --git a/mp_core.h b/mp_core.h index 00b8fa91ef..f8b286e5b9 100644 --- a/mp_core.h +++ b/mp_core.h @@ -88,6 +88,9 @@ typedef struct MPContext { struct mp_fifo *key_fifo; struct input_ctx *input; struct osd_state *osd; + struct sub_data *subdata; // current sub_data style subtitles if any + // last sub_data style sub line if any, used by log_sub() only + struct subtitle *vo_sub_last; bool add_osd_seek_info; // if nonzero, hide current OSD contents when GetTimerMS() reaches this diff --git a/mpcommon.c b/mpcommon.c index a7e89d9ee1..2af26314bb 100644 --- a/mpcommon.c +++ b/mpcommon.c @@ -39,15 +39,13 @@ #include "libmpcodecs/dec_teletext.h" #include "ffmpeg_files/intreadwrite.h" #include "m_option.h" +#include "mp_core.h" #ifdef CONFIG_ASS #include "ass_mp.h" ASS_Track *ass_track = 0; // current track to render #endif -sub_data* subdata = NULL; -subtitle* vo_sub_last = NULL; - const char *mencoder_version = "MEncoder " VERSION; const char *mplayer_version = "MPlayer " VERSION; @@ -123,12 +121,13 @@ void update_subtitles(struct MPContext *mpctx, struct MPOpts *opts, return; } // find sub - if (subdata) { + if (mpctx->subdata) { if (sub_fps==0) sub_fps = sh_video ? sh_video->fps : 25; current_module = "find_sub"; - find_sub(mpctx, subdata, curpts * - (subdata->sub_uses_time ? 100. : sub_fps)); - if (vo_sub) vo_sub_last = vo_sub; + find_sub(mpctx, mpctx->subdata, curpts * + (mpctx->subdata->sub_uses_time ? 100. : sub_fps)); + if (vo_sub) + mpctx->vo_sub_last = vo_sub; } // DVD sub: diff --git a/mpcommon.h b/mpcommon.h index e0baee4f8d..5d114f38a5 100644 --- a/mpcommon.h +++ b/mpcommon.h @@ -24,7 +24,6 @@ struct subtitle; extern struct ass_track *ass_track; -extern struct subtitle *vo_sub_last; extern const char *mencoder_version; extern const char *mplayer_version; diff --git a/mplayer.c b/mplayer.c index 6565f75904..567114cfd3 100644 --- a/mplayer.c +++ b/mplayer.c @@ -4415,14 +4415,14 @@ if(vo_spudec==NULL && mpctx->sub_counts[SUB_SOURCE_SUBS] = mpctx->set_of_sub_size; if (select_subtitle(mpctx)) { - if(subdata) + if(mpctx->subdata) switch (stream_dump_type) { - case 3: list_sub_file(subdata); break; - case 4: dump_mpsub(subdata, mpctx->sh_video->fps); break; - case 6: dump_srt(subdata, mpctx->sh_video->fps); break; - case 7: dump_microdvd(subdata, mpctx->sh_video->fps); break; - case 8: dump_jacosub(subdata, mpctx->sh_video->fps); break; - case 9: dump_sami(subdata, mpctx->sh_video->fps); break; + case 3: list_sub_file(mpctx->subdata); break; + case 4: dump_mpsub(mpctx->subdata, mpctx->sh_video->fps); break; + case 6: dump_srt(mpctx->subdata, mpctx->sh_video->fps); break; + case 7: dump_microdvd(mpctx->subdata, mpctx->sh_video->fps); break; + case 8: dump_jacosub(mpctx->subdata, mpctx->sh_video->fps); break; + case 9: dump_sami(mpctx->subdata, mpctx->sh_video->fps); break; } } @@ -4645,8 +4645,8 @@ if(mpctx->set_of_sub_size > 0) { } mpctx->set_of_sub_size = 0; } -vo_sub_last = vo_sub=NULL; -subdata=NULL; +mpctx->vo_sub_last = vo_sub=NULL; +mpctx->subdata=NULL; #ifdef CONFIG_ASS ass_track = NULL; if(ass_library) -- cgit v1.2.3 From 43b1de1dd72a9c2f98b3419626c81c58bbc3cf64 Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Wed, 12 Jan 2011 01:37:02 +0200 Subject: core: move most mpcommon.c contents to mplayer.c The contents of mpcommon.c were quite arbitrary; the most common reason to place some functions in this file had been "MEncoder happens to need similar code as MPlayer and we want to share some parts, but we have no clue whatsoever how to organize things in a sensible way, so we'll just dump those parts we want to share in mpcommon.c". As a result of containing an essentially random subset of top-level player functionality the mpcommon.h header required access to central structs and was unsuitable for inclusion in lower-level code, but was nonetheless included there for the mplayer_version symbol. Move almost all contents from mpcommon.c to mplayer.c. mplayer.c is already big and should perhaps be split further, but keeping a few random functions in mpcommon.c would not be an improvement. --- command.c | 2 +- find_sub.c | 4 +- mp_core.h | 2 + mpcommon.c | 320 ------------------------------------------------------------- mpcommon.h | 23 ----- mplayer.c | 314 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- mplayer.h | 5 + 7 files changed, 314 insertions(+), 356 deletions(-) diff --git a/command.c b/command.c index 238e62cd04..cab0c0b87f 100644 --- a/command.c +++ b/command.c @@ -1711,7 +1711,7 @@ static int mp_property_sub(m_option_t *prop, int action, void *arg, } #endif - update_subtitles(mpctx, &mpctx->opts, mpctx->sh_video, 0, 0, d_sub, 1); + update_subtitles(mpctx, 0, 0, true); return M_PROPERTY_OK; } diff --git a/find_sub.c b/find_sub.c index d0ea3c0016..7eeefda9d1 100644 --- a/find_sub.c +++ b/find_sub.c @@ -28,6 +28,7 @@ #include "mp_msg.h" #include "mpcommon.h" +#include "mplayer.h" static int current_sub=0; @@ -36,9 +37,6 @@ static int nosub_range_start=-1; static int nosub_range_end=-1; static const sub_data *last_sub_data = NULL; -extern float sub_delay; -extern float sub_fps; - void step_sub(sub_data *subd, float pts, int movement) { subtitle *subs; int key; diff --git a/mp_core.h b/mp_core.h index f8b286e5b9..51337b4ee1 100644 --- a/mp_core.h +++ b/mp_core.h @@ -246,5 +246,7 @@ double get_current_time(struct MPContext *mpctx); int get_percent_pos(struct MPContext *mpctx); int get_current_chapter(struct MPContext *mpctx); char *chapter_display_name(struct MPContext *mpctx, int chapter); +void update_subtitles(struct MPContext *mpctx, double refpts, + double sub_offset, bool reset); #endif /* MPLAYER_MP_CORE_H */ diff --git a/mpcommon.c b/mpcommon.c index 2af26314bb..47c056a08e 100644 --- a/mpcommon.c +++ b/mpcommon.c @@ -16,326 +16,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#if defined(__MINGW32__) || defined(__CYGWIN__) -#include -#endif -#include -#include - -#include "mpcommon.h" -#include "options.h" -#include "stream/stream.h" -#include "libmpdemux/demuxer.h" -#include "libmpdemux/stheader.h" -#include "mplayer.h" -#include "libvo/sub.h" -#include "libvo/video_out.h" -#include "cpudetect.h" -#include "mp_msg.h" -#include "spudec.h" #include "version.h" -#include "vobsub.h" -#include "av_sub.h" -#include "libmpcodecs/dec_teletext.h" -#include "ffmpeg_files/intreadwrite.h" -#include "m_option.h" -#include "mp_core.h" - -#ifdef CONFIG_ASS -#include "ass_mp.h" -ASS_Track *ass_track = 0; // current track to render -#endif -const char *mencoder_version = "MEncoder " VERSION; const char *mplayer_version = "MPlayer " VERSION; - -void print_version(const char* name) -{ - mp_msg(MSGT_CPLAYER, MSGL_INFO, MP_TITLE, name); - - /* Test for CPU capabilities (and corresponding OS support) for optimizing */ - GetCpuCaps(&gCpuCaps); -#if ARCH_X86 - mp_msg(MSGT_CPLAYER, MSGL_V, - "CPUflags: MMX: %d MMX2: %d 3DNow: %d 3DNowExt: %d SSE: %d SSE2: %d SSSE3: %d\n", - gCpuCaps.hasMMX, gCpuCaps.hasMMX2, - gCpuCaps.has3DNow, gCpuCaps.has3DNowExt, - gCpuCaps.hasSSE, gCpuCaps.hasSSE2, gCpuCaps.hasSSSE3); -#if CONFIG_RUNTIME_CPUDETECT - mp_tmsg(MSGT_CPLAYER,MSGL_V, "Compiled with runtime CPU detection.\n"); -#else - mp_tmsg(MSGT_CPLAYER,MSGL_V, "Compiled for x86 CPU with extensions:"); -if (HAVE_MMX) - mp_msg(MSGT_CPLAYER,MSGL_V," MMX"); -if (HAVE_MMX2) - mp_msg(MSGT_CPLAYER,MSGL_V," MMX2"); -if (HAVE_AMD3DNOW) - mp_msg(MSGT_CPLAYER,MSGL_V," 3DNow"); -if (HAVE_AMD3DNOWEXT) - mp_msg(MSGT_CPLAYER,MSGL_V," 3DNowExt"); -if (HAVE_SSE) - mp_msg(MSGT_CPLAYER,MSGL_V," SSE"); -if (HAVE_SSE2) - mp_msg(MSGT_CPLAYER,MSGL_V," SSE2"); -if (HAVE_SSSE3) - mp_msg(MSGT_CPLAYER,MSGL_V," SSSE3"); -if (HAVE_CMOV) - mp_msg(MSGT_CPLAYER,MSGL_V," CMOV"); - mp_msg(MSGT_CPLAYER,MSGL_V,"\n"); -#endif /* CONFIG_RUNTIME_CPUDETECT */ -#endif /* ARCH_X86 */ -} - -static bool is_text_sub(int type) -{ - return type == 't' || type == 'm' || type == 'a'; -} - -static bool is_av_sub(int type) -{ - return type == 'b' || type == 'p' || type == 'x'; -} - -void update_subtitles(struct MPContext *mpctx, struct MPOpts *opts, - sh_video_t *sh_video, double refpts, double sub_offset, - demux_stream_t *d_dvdsub, int reset) -{ - double curpts = refpts + sub_delay; - unsigned char *packet=NULL; - int len; - int type = d_dvdsub->sh ? ((sh_sub_t *)d_dvdsub->sh)->type : 'v'; - static subtitle subs; - if (reset) { - sub_clear_text(&subs, MP_NOPTS_VALUE); - if (vo_sub) { - set_osd_subtitle(mpctx, NULL); - } - if (vo_spudec) { - spudec_reset(vo_spudec); - vo_osd_changed(OSDTYPE_SPU); - } -#ifdef CONFIG_FFMPEG - if (is_av_sub(type)) - reset_avsub(d_dvdsub->sh); -#endif - return; - } - // find sub - if (mpctx->subdata) { - if (sub_fps==0) sub_fps = sh_video ? sh_video->fps : 25; - current_module = "find_sub"; - find_sub(mpctx, mpctx->subdata, curpts * - (mpctx->subdata->sub_uses_time ? 100. : sub_fps)); - if (vo_sub) - mpctx->vo_sub_last = vo_sub; - } - - // DVD sub: - if (vobsub_id >= 0 || type == 'v') { - int timestamp; - current_module = "spudec"; - /* Get a sub packet from the DVD or a vobsub */ - while(1) { - // Vobsub - len = 0; - if (vo_vobsub) { - if (curpts >= 0) { - len = vobsub_get_packet(vo_vobsub, curpts, - (void**)&packet, ×tamp); - if (len > 0) { - mp_dbg(MSGT_CPLAYER,MSGL_V,"\rVOB sub: len=%d v_pts=%5.3f v_timer=%5.3f sub=%5.3f ts=%d \n",len,refpts,sh_video->timer,timestamp / 90000.0,timestamp); - } - } - } else { - // DVD sub - len = ds_get_packet_sub(d_dvdsub, (unsigned char**)&packet); - if (len > 0) { - // XXX This is wrong, sh_video->pts can be arbitrarily - // much behind demuxing position. Unfortunately using - // d_video->pts which would have been the simplest - // improvement doesn't work because mpeg specific hacks - // in video.c set d_video->pts to 0. - float x = d_dvdsub->pts - refpts; - if (x > -20 && x < 20) // prevent missing subs on pts reset - timestamp = 90000*d_dvdsub->pts; - else timestamp = 90000*curpts; - mp_dbg(MSGT_CPLAYER, MSGL_V, "\rDVD sub: len=%d " - "v_pts=%5.3f s_pts=%5.3f ts=%d \n", len, - refpts, d_dvdsub->pts, timestamp); - } - } - if (len<=0 || !packet) break; - // create it only here, since with some broken demuxers we might - // type = v but no DVD sub and we currently do not change the - // "original frame size" ever after init, leading to wrong-sized - // PGS subtitles. - if (!vo_spudec) - vo_spudec = spudec_new(NULL); - if (vo_vobsub || timestamp >= 0) - spudec_assemble(vo_spudec, packet, len, timestamp); - } - } else if (is_text_sub(type) || is_av_sub(type) || type == 'd') { - if (type == 'd' && !d_dvdsub->demuxer->teletext) { - tt_stream_props tsp = {0}; - void *ptr = &tsp; - if (teletext_control(NULL, TV_VBI_CONTROL_START, &ptr) == VBI_CONTROL_TRUE) - d_dvdsub->demuxer->teletext = ptr; - } - if (d_dvdsub->non_interleaved) - ds_get_next_pts(d_dvdsub); - - int orig_type = type; - while (d_dvdsub->first) { - double subpts = ds_get_next_pts(d_dvdsub) + sub_offset; - type = orig_type; - if (subpts > curpts) { - // Libass handled subs can be fed to it in advance - if (!opts->ass_enabled || !is_text_sub(type)) - break; - // Try to avoid demuxing whole file at once - if (d_dvdsub->non_interleaved && subpts > curpts + 1) - break; - } - double endpts = d_dvdsub->first->endpts + sub_offset; - len = ds_get_packet_sub(d_dvdsub, &packet); - if (is_av_sub(type)) { -#ifdef CONFIG_FFMPEG - type = decode_avsub(d_dvdsub->sh, &packet, &len, &subpts, &endpts); - if (type <= 0) -#endif - continue; - } - if (type == 'm') { - if (len < 2) continue; - len = FFMIN(len - 2, AV_RB16(packet)); - packet += 2; - } - if (type == 'd') { - if (d_dvdsub->demuxer->teletext) { - uint8_t *p = packet; - p++; - len--; - while (len >= 46) { - int sublen = p[1]; - if (p[0] == 2 || p[0] == 3) - teletext_control(d_dvdsub->demuxer->teletext, - TV_VBI_CONTROL_DECODE_DVB, p + 2); - p += sublen + 2; - len -= sublen + 2; - } - } - continue; - } -#ifdef CONFIG_ASS - if (opts->ass_enabled) { - sh_sub_t* sh = d_dvdsub->sh; - ass_track = sh ? sh->ass_track : NULL; - if (!ass_track) continue; - if (type == 'a') { // ssa/ass subs with libass - ass_process_chunk(ass_track, packet, len, - (long long)(subpts*1000 + 0.5), - (long long)((endpts-subpts)*1000 + 0.5)); - } else { // plaintext subs with libass - if (subpts != MP_NOPTS_VALUE) { - subtitle tmp_subs = {0}; - if (endpts == MP_NOPTS_VALUE) endpts = subpts + 3; - sub_add_text(&tmp_subs, packet, len, endpts); - tmp_subs.start = subpts * 100; - tmp_subs.end = endpts * 100; - ass_process_subtitle(ass_track, &tmp_subs); - sub_clear_text(&tmp_subs, MP_NOPTS_VALUE); - } - } - continue; - } -#endif - if (subpts != MP_NOPTS_VALUE) { - if (endpts == MP_NOPTS_VALUE) - sub_clear_text(&subs, MP_NOPTS_VALUE); - if (type == 'a') { // ssa/ass subs without libass => convert to plaintext - int i; - unsigned char* p = packet; - for (i=0; i < 8 && *p != '\0'; p++) - if (*p == ',') - i++; - if (*p == '\0') /* Broken line? */ - continue; - len -= p - packet; - packet = p; - } - sub_add_text(&subs, packet, len, endpts); - set_osd_subtitle(mpctx, &subs); - } - if (d_dvdsub->non_interleaved) - ds_get_next_pts(d_dvdsub); - } - if (!opts->ass_enabled) - if (sub_clear_text(&subs, curpts)) - set_osd_subtitle(mpctx, &subs); - } - if (vo_spudec) { - spudec_heartbeat(vo_spudec, 90000*curpts); - if (spudec_changed(vo_spudec)) - vo_osd_changed(OSDTYPE_SPU); - } - - current_module=NULL; -} - -void update_teletext(sh_video_t *sh_video, demuxer_t *demuxer, int reset) -{ - int page_changed; - - if (!demuxer->teletext) - return; - - //Also forcing page update when such ioctl is not supported or call error occured - if(teletext_control(demuxer->teletext,TV_VBI_CONTROL_IS_CHANGED,&page_changed)!=VBI_CONTROL_TRUE) - page_changed=1; - - if(!page_changed) - return; - - if(teletext_control(demuxer->teletext,TV_VBI_CONTROL_GET_VBIPAGE,&vo_osd_teletext_page)!=VBI_CONTROL_TRUE) - vo_osd_teletext_page=NULL; - if(teletext_control(demuxer->teletext,TV_VBI_CONTROL_GET_HALF_PAGE,&vo_osd_teletext_half)!=VBI_CONTROL_TRUE) - vo_osd_teletext_half=0; - if(teletext_control(demuxer->teletext,TV_VBI_CONTROL_GET_MODE,&vo_osd_teletext_mode)!=VBI_CONTROL_TRUE) - vo_osd_teletext_mode=0; - if(teletext_control(demuxer->teletext,TV_VBI_CONTROL_GET_FORMAT,&vo_osd_teletext_format)!=VBI_CONTROL_TRUE) - vo_osd_teletext_format=0; - vo_osd_changed(OSDTYPE_TELETEXT); - - teletext_control(demuxer->teletext,TV_VBI_CONTROL_MARK_UNCHANGED,NULL); -} - -int select_audio(demuxer_t* demuxer, int audio_id, char* audio_lang) -{ - if (audio_id == -1) - audio_id = demuxer_audio_track_by_lang_and_default(demuxer, audio_lang); - if (audio_id != -1) // -1 (automatic) is the default behaviour of demuxers - demuxer_switch_audio(demuxer, audio_id); - if (audio_id == -2) { // some demuxers don't yet know how to switch to no sound - demuxer->audio->id = -2; - demuxer->audio->sh = NULL; - } - return demuxer->audio->id; -} - -bool attachment_is_font(struct demux_attachment *att) -{ - if (!att->name || !att->type || !att->data || !att->data_size) - return false; - // match against MIME types - if (strcmp(att->type, "application/x-truetype-font") == 0 - || strcmp(att->type, "application/x-font") == 0) - return true; - // fallback: match against file extension - if (strlen(att->name) > 4) { - char *ext = att->name + strlen(att->name) - 4; - if (strcasecmp(ext, ".ttf") == 0 || strcasecmp(ext, ".ttc") == 0 - || strcasecmp(ext, ".otf") == 0) - return true; - } - return false; -} diff --git a/mpcommon.h b/mpcommon.h index 5d114f38a5..8a55d33a9f 100644 --- a/mpcommon.h +++ b/mpcommon.h @@ -19,31 +19,8 @@ #ifndef MPLAYER_MPCOMMON_H #define MPLAYER_MPCOMMON_H -#include - -struct subtitle; - extern struct ass_track *ass_track; -extern const char *mencoder_version; extern const char *mplayer_version; -struct MPContext; -struct demuxer; -struct demux_stream; -struct demux_attachment; -struct sh_video; -struct MPOpts; - -void print_version(const char* name); -void update_subtitles(struct MPContext *mpctx, struct MPOpts *opts, - struct sh_video *sh_video, double refpts, - double sub_offset, struct demux_stream *d_dvdsub, - int reset); -void update_teletext(struct sh_video *sh_video, struct demuxer *demuxer, - int reset); -int select_audio(struct demuxer *demuxer, int audio_id, char *audio_lang); -void set_osd_subtitle(struct MPContext *mpctx, struct subtitle *subs); -bool attachment_is_font(struct demux_attachment *att); - #endif /* MPLAYER_MPCOMMON_H */ diff --git a/mplayer.c b/mplayer.c index 567114cfd3..091287c1fd 100644 --- a/mplayer.c +++ b/mplayer.c @@ -78,6 +78,11 @@ #include "libvo/font_load.h" #include "libvo/sub.h" +#include "ffmpeg_files/intreadwrite.h" +#include "av_sub.h" +#include "libmpcodecs/dec_teletext.h" +#include "cpudetect.h" +#include "version.h" #ifdef CONFIG_X11 #include "libvo/x11_common.h" @@ -330,6 +335,9 @@ int subcc_enabled=0; int suboverlap_enabled = 1; #include "ass_mp.h" +#ifdef CONFIG_ASS +ASS_Track *ass_track = 0; // current track to render +#endif char* current_module=NULL; // for debugging @@ -1797,6 +1805,230 @@ double playing_audio_pts(struct MPContext *mpctx) mpctx->audio_out->get_delay(); } +static bool is_text_sub(int type) +{ + return type == 't' || type == 'm' || type == 'a'; +} + +static bool is_av_sub(int type) +{ + return type == 'b' || type == 'p' || type == 'x'; +} + +void update_subtitles(struct MPContext *mpctx, double refpts, + double sub_offset, bool reset) +{ + struct MPOpts *opts = &mpctx->opts; + struct sh_video *sh_video = mpctx->sh_video; + struct demux_stream *d_sub = mpctx->d_sub; + double curpts = refpts + sub_delay; + unsigned char *packet=NULL; + int len; + int type = d_sub->sh ? ((sh_sub_t *)d_sub->sh)->type : 'v'; + static subtitle subs; + if (reset) { + sub_clear_text(&subs, MP_NOPTS_VALUE); + if (vo_sub) + set_osd_subtitle(mpctx, NULL); + if (vo_spudec) { + spudec_reset(vo_spudec); + vo_osd_changed(OSDTYPE_SPU); + } +#ifdef CONFIG_FFMPEG + if (is_av_sub(type)) + reset_avsub(d_sub->sh); +#endif + return; + } + // find sub + if (mpctx->subdata) { + if (sub_fps==0) sub_fps = sh_video ? sh_video->fps : 25; + current_module = "find_sub"; + find_sub(mpctx, mpctx->subdata, curpts * + (mpctx->subdata->sub_uses_time ? 100. : sub_fps)); + if (vo_sub) + mpctx->vo_sub_last = vo_sub; + } + + // DVD sub: + if (vobsub_id >= 0 || type == 'v') { + int timestamp; + current_module = "spudec"; + /* Get a sub packet from the DVD or a vobsub */ + while(1) { + // Vobsub + len = 0; + if (vo_vobsub) { + if (curpts >= 0) { + len = vobsub_get_packet(vo_vobsub, curpts, + (void**)&packet, ×tamp); + if (len > 0) { + mp_dbg(MSGT_CPLAYER,MSGL_V,"\rVOB sub: len=%d v_pts=%5.3f v_timer=%5.3f sub=%5.3f ts=%d \n",len,refpts,sh_video->timer,timestamp / 90000.0,timestamp); + } + } + } else { + // DVD sub + len = ds_get_packet_sub(d_sub, (unsigned char**)&packet); + if (len > 0) { + // XXX This is wrong, sh_video->pts can be arbitrarily + // much behind demuxing position. Unfortunately using + // d_video->pts which would have been the simplest + // improvement doesn't work because mpeg specific hacks + // in video.c set d_video->pts to 0. + float x = d_sub->pts - refpts; + if (x > -20 && x < 20) // prevent missing subs on pts reset + timestamp = 90000*d_sub->pts; + else timestamp = 90000*curpts; + mp_dbg(MSGT_CPLAYER, MSGL_V, "\rDVD sub: len=%d " + "v_pts=%5.3f s_pts=%5.3f ts=%d \n", len, + refpts, d_sub->pts, timestamp); + } + } + if (len<=0 || !packet) break; + // create it only here, since with some broken demuxers we might + // type = v but no DVD sub and we currently do not change the + // "original frame size" ever after init, leading to wrong-sized + // PGS subtitles. + if (!vo_spudec) + vo_spudec = spudec_new(NULL); + if (vo_vobsub || timestamp >= 0) + spudec_assemble(vo_spudec, packet, len, timestamp); + } + } else if (is_text_sub(type) || is_av_sub(type) || type == 'd') { + if (type == 'd' && !d_sub->demuxer->teletext) { + tt_stream_props tsp = {0}; + void *ptr = &tsp; + if (teletext_control(NULL, TV_VBI_CONTROL_START, &ptr) == VBI_CONTROL_TRUE) + d_sub->demuxer->teletext = ptr; + } + if (d_sub->non_interleaved) + ds_get_next_pts(d_sub); + + int orig_type = type; + while (d_sub->first) { + double subpts = ds_get_next_pts(d_sub) + sub_offset; + type = orig_type; + if (subpts > curpts) { + // Libass handled subs can be fed to it in advance + if (!opts->ass_enabled || !is_text_sub(type)) + break; + // Try to avoid demuxing whole file at once + if (d_sub->non_interleaved && subpts > curpts + 1) + break; + } + double endpts = d_sub->first->endpts + sub_offset; + len = ds_get_packet_sub(d_sub, &packet); + if (is_av_sub(type)) { +#ifdef CONFIG_FFMPEG + type = decode_avsub(d_sub->sh, &packet, &len, &subpts, &endpts); + if (type <= 0) +#endif + continue; + } + if (type == 'm') { + if (len < 2) continue; + len = FFMIN(len - 2, AV_RB16(packet)); + packet += 2; + } + if (type == 'd') { + if (d_sub->demuxer->teletext) { + uint8_t *p = packet; + p++; + len--; + while (len >= 46) { + int sublen = p[1]; + if (p[0] == 2 || p[0] == 3) + teletext_control(d_sub->demuxer->teletext, + TV_VBI_CONTROL_DECODE_DVB, p + 2); + p += sublen + 2; + len -= sublen + 2; + } + } + continue; + } +#ifdef CONFIG_ASS + if (opts->ass_enabled) { + sh_sub_t* sh = d_sub->sh; + ass_track = sh ? sh->ass_track : NULL; + if (!ass_track) continue; + if (type == 'a') { // ssa/ass subs with libass + ass_process_chunk(ass_track, packet, len, + (long long)(subpts*1000 + 0.5), + (long long)((endpts-subpts)*1000 + 0.5)); + } else { // plaintext subs with libass + if (subpts != MP_NOPTS_VALUE) { + subtitle tmp_subs = {0}; + if (endpts == MP_NOPTS_VALUE) endpts = subpts + 3; + sub_add_text(&tmp_subs, packet, len, endpts); + tmp_subs.start = subpts * 100; + tmp_subs.end = endpts * 100; + ass_process_subtitle(ass_track, &tmp_subs); + sub_clear_text(&tmp_subs, MP_NOPTS_VALUE); + } + } + continue; + } +#endif + if (subpts != MP_NOPTS_VALUE) { + if (endpts == MP_NOPTS_VALUE) + sub_clear_text(&subs, MP_NOPTS_VALUE); + if (type == 'a') { // ssa/ass subs without libass => convert to plaintext + int i; + unsigned char* p = packet; + for (i=0; i < 8 && *p != '\0'; p++) + if (*p == ',') + i++; + if (*p == '\0') /* Broken line? */ + continue; + len -= p - packet; + packet = p; + } + sub_add_text(&subs, packet, len, endpts); + set_osd_subtitle(mpctx, &subs); + } + if (d_sub->non_interleaved) + ds_get_next_pts(d_sub); + } + if (!opts->ass_enabled) + if (sub_clear_text(&subs, curpts)) + set_osd_subtitle(mpctx, &subs); + } + if (vo_spudec) { + spudec_heartbeat(vo_spudec, 90000*curpts); + if (spudec_changed(vo_spudec)) + vo_osd_changed(OSDTYPE_SPU); + } + + current_module=NULL; +} + +static void update_teletext(sh_video_t *sh_video, demuxer_t *demuxer, int reset) +{ + int page_changed; + + if (!demuxer->teletext) + return; + + //Also forcing page update when such ioctl is not supported or call error occured + if(teletext_control(demuxer->teletext,TV_VBI_CONTROL_IS_CHANGED,&page_changed)!=VBI_CONTROL_TRUE) + page_changed=1; + + if(!page_changed) + return; + + if(teletext_control(demuxer->teletext,TV_VBI_CONTROL_GET_VBIPAGE,&vo_osd_teletext_page)!=VBI_CONTROL_TRUE) + vo_osd_teletext_page=NULL; + if(teletext_control(demuxer->teletext,TV_VBI_CONTROL_GET_HALF_PAGE,&vo_osd_teletext_half)!=VBI_CONTROL_TRUE) + vo_osd_teletext_half=0; + if(teletext_control(demuxer->teletext,TV_VBI_CONTROL_GET_MODE,&vo_osd_teletext_mode)!=VBI_CONTROL_TRUE) + vo_osd_teletext_mode=0; + if(teletext_control(demuxer->teletext,TV_VBI_CONTROL_GET_FORMAT,&vo_osd_teletext_format)!=VBI_CONTROL_TRUE) + vo_osd_teletext_format=0; + vo_osd_changed(OSDTYPE_TELETEXT); + + teletext_control(demuxer->teletext,TV_VBI_CONTROL_MARK_UNCHANGED,NULL); +} + static int check_framedrop(struct MPContext *mpctx, double frame_time) { struct MPOpts *opts = &mpctx->opts; // check for frame-drop: @@ -2758,9 +2990,8 @@ static void seek_reset(struct MPContext *mpctx) // be completely wrong (probably 0). mpctx->sh_video->pts = mpctx->d_video->pts + mpctx->video_offset; mpctx->video_pts = mpctx->sh_video->pts; - update_subtitles(mpctx, &mpctx->opts, mpctx->sh_video, - mpctx->sh_video->pts, mpctx->video_offset, - mpctx->d_sub, 1); + update_subtitles(mpctx, mpctx->sh_video->pts, mpctx->video_offset, + true); update_teletext(mpctx->sh_video, mpctx->demuxer, 1); } @@ -2771,8 +3002,8 @@ static void seek_reset(struct MPContext *mpctx) mpctx->sh_audio->a_buffer_len = 0; mpctx->sh_audio->a_out_buffer_len = 0; if (!mpctx->sh_video) - update_subtitles(mpctx, &mpctx->opts, NULL, mpctx->sh_audio->pts, - mpctx->video_offset, mpctx->d_sub, 1); + update_subtitles(mpctx, mpctx->sh_audio->pts, + mpctx->video_offset, true); } if (vo_vobsub && mpctx->sh_video) { @@ -3110,8 +3341,7 @@ static void run_playloop(struct MPContext *mpctx) if (end_at.type == END_AT_TIME && end_at.pos < a_pos) mpctx->stop_play = PT_NEXT_ENTRY; - update_subtitles(mpctx, &mpctx->opts, NULL, a_pos, mpctx->video_offset, - mpctx->d_sub, 0); + update_subtitles(mpctx, a_pos, mpctx->video_offset, false); update_osd_msg(mpctx); } else { @@ -3182,8 +3412,7 @@ static void run_playloop(struct MPContext *mpctx) if (!frame_time_remaining && blit_frame) { struct sh_video *sh_video = mpctx->sh_video; mpctx->video_pts = sh_video->pts; - update_subtitles(mpctx, &mpctx->opts, sh_video, sh_video->pts, - mpctx->video_offset, mpctx->d_sub, 0); + update_subtitles(mpctx, sh_video->pts, mpctx->video_offset, false); update_teletext(sh_video, mpctx->demuxer, 0); update_osd_msg(mpctx); struct vf_instance *vf = sh_video->vfilter; @@ -3576,6 +3805,73 @@ static int read_keys(void *ctx, int fd) return mplayer_get_key(ctx, 0); } +static bool attachment_is_font(struct demux_attachment *att) +{ + if (!att->name || !att->type || !att->data || !att->data_size) + return false; + // match against MIME types + if (strcmp(att->type, "application/x-truetype-font") == 0 + || strcmp(att->type, "application/x-font") == 0) + return true; + // fallback: match against file extension + if (strlen(att->name) > 4) { + char *ext = att->name + strlen(att->name) - 4; + if (strcasecmp(ext, ".ttf") == 0 || strcasecmp(ext, ".ttc") == 0 + || strcasecmp(ext, ".otf") == 0) + return true; + } + return false; +} + +static int select_audio(demuxer_t *demuxer, int audio_id, char *audio_lang) +{ + if (audio_id == -1) + audio_id = demuxer_audio_track_by_lang_and_default(demuxer, audio_lang); + if (audio_id != -1) // -1 (automatic) is the default behaviour of demuxers + demuxer_switch_audio(demuxer, audio_id); + if (audio_id == -2) { // some demuxers don't yet know how to switch to no sound + demuxer->audio->id = -2; + demuxer->audio->sh = NULL; + } + return demuxer->audio->id; +} + +static void print_version(const char* name) +{ + mp_msg(MSGT_CPLAYER, MSGL_INFO, MP_TITLE, name); + + /* Test for CPU capabilities (and corresponding OS support) for optimizing */ + GetCpuCaps(&gCpuCaps); +#if ARCH_X86 + mp_msg(MSGT_CPLAYER, MSGL_V, + "CPUflags: MMX: %d MMX2: %d 3DNow: %d 3DNowExt: %d SSE: %d SSE2: %d SSSE3: %d\n", + gCpuCaps.hasMMX, gCpuCaps.hasMMX2, + gCpuCaps.has3DNow, gCpuCaps.has3DNowExt, + gCpuCaps.hasSSE, gCpuCaps.hasSSE2, gCpuCaps.hasSSSE3); +#if CONFIG_RUNTIME_CPUDETECT + mp_tmsg(MSGT_CPLAYER,MSGL_V, "Compiled with runtime CPU detection.\n"); +#else + mp_tmsg(MSGT_CPLAYER,MSGL_V, "Compiled for x86 CPU with extensions:"); +if (HAVE_MMX) + mp_msg(MSGT_CPLAYER,MSGL_V," MMX"); +if (HAVE_MMX2) + mp_msg(MSGT_CPLAYER,MSGL_V," MMX2"); +if (HAVE_AMD3DNOW) + mp_msg(MSGT_CPLAYER,MSGL_V," 3DNow"); +if (HAVE_AMD3DNOWEXT) + mp_msg(MSGT_CPLAYER,MSGL_V," 3DNowExt"); +if (HAVE_SSE) + mp_msg(MSGT_CPLAYER,MSGL_V," SSE"); +if (HAVE_SSE2) + mp_msg(MSGT_CPLAYER,MSGL_V," SSE2"); +if (HAVE_SSSE3) + mp_msg(MSGT_CPLAYER,MSGL_V," SSSE3"); +if (HAVE_CMOV) + mp_msg(MSGT_CPLAYER,MSGL_V," CMOV"); + mp_msg(MSGT_CPLAYER,MSGL_V,"\n"); +#endif /* CONFIG_RUNTIME_CPUDETECT */ +#endif /* ARCH_X86 */ +} /* This preprocessor directive is a hack to generate a mplayer-nomain.o object * file for some tools to link against. */ diff --git a/mplayer.h b/mplayer.h index 7a8eec34e8..4f0c927763 100644 --- a/mplayer.h +++ b/mplayer.h @@ -19,6 +19,8 @@ #ifndef MPLAYER_MPLAYER_H #define MPLAYER_MPLAYER_H +#include + #include "mp_msg.h" extern char* current_module; @@ -57,5 +59,8 @@ static inline void exit_player_bad(const char *how) } struct MPContext; +struct subtitle; + +void set_osd_subtitle(struct MPContext *mpctx, struct subtitle *subs); #endif /* MPLAYER_MPLAYER_H */ -- cgit v1.2.3 From adedee42851d413de87b479340eb015ee33b497b Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Wed, 12 Jan 2011 15:15:02 +0200 Subject: subtitles: move global ass_track to struct osd_state --- command.c | 25 +++++++++++-------------- libmpcodecs/vf.h | 4 ++-- libmpcodecs/vf_ass.c | 12 ++++++++---- libmpcodecs/vf_vo.c | 14 ++++++++------ libvo/sub.h | 1 + mpcommon.h | 2 -- mplayer.c | 15 ++++++--------- 7 files changed, 36 insertions(+), 37 deletions(-) diff --git a/command.c b/command.c index cab0c0b87f..5474b92fed 100644 --- a/command.c +++ b/command.c @@ -1523,7 +1523,6 @@ static int mp_property_sub(m_option_t *prop, int action, void *arg, demux_stream_t *const d_sub = mpctx->d_sub; int source = -1, reset_spu = 0; int source_pos = -1; - char *sub_name; update_global_sub_size(mpctx); const int global_sub_size = mpctx->global_sub_size; @@ -1542,13 +1541,15 @@ static int mp_property_sub(m_option_t *prop, int action, void *arg, return M_PROPERTY_ERROR; *(char **) arg = malloc(64); (*(char **) arg)[63] = 0; - sub_name = 0; + char *sub_name = NULL; if (mpctx->subdata) sub_name = mpctx->subdata->filename; #ifdef CONFIG_ASS - if (ass_track && ass_track->name) - sub_name = ass_track->name; + if (mpctx->osd->ass_track) + sub_name = mpctx->osd->ass_track->name; #endif + if (!sub_name && mpctx->subdata) + sub_name = mpctx->subdata->filename; if (sub_name) { const char *tmp = mp_basename(sub_name); @@ -1654,9 +1655,7 @@ static int mp_property_sub(m_option_t *prop, int action, void *arg, reset_spu = 1; d_sub->id = -2; } -#ifdef CONFIG_ASS - ass_track = 0; -#endif + mpctx->osd->ass_track = NULL; if (source == SUB_SOURCE_VOBSUB) { vobsub_id = vobsub_get_id_by_index(vo_vobsub, source_pos); @@ -1664,7 +1663,7 @@ static int mp_property_sub(m_option_t *prop, int action, void *arg, mpctx->set_of_sub_pos = source_pos; #ifdef CONFIG_ASS if (opts->ass_enabled && mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos]) - ass_track = mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos]; + mpctx->osd->ass_track = mpctx->set_of_ass_tracks[mpctx->set_of_sub_pos]; else #endif { @@ -1693,7 +1692,7 @@ static int mp_property_sub(m_option_t *prop, int action, void *arg, init_vo_spudec(mpctx); #ifdef CONFIG_ASS else if (opts->ass_enabled) - ass_track = sh->ass_track; + mpctx->osd->ass_track = sh->ass_track; #endif } else { d_sub->id = -2; @@ -2694,9 +2693,7 @@ static void remove_subtitle_range(MPContext *mpctx, int start, int count) if (mpctx->set_of_sub_pos >= start && mpctx->set_of_sub_pos < end) { mpctx->global_sub_pos = -2; mpctx->subdata = NULL; -#ifdef CONFIG_ASS - ass_track = NULL; -#endif + mpctx->osd->ass_track = NULL; mp_input_queue_cmd(mpctx->input, mp_input_parse_cmd("sub_select")); } else if (mpctx->set_of_sub_pos >= end) { mpctx->set_of_sub_pos -= count; @@ -2934,9 +2931,9 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd) int movement = cmd->args[0].v.i; step_sub(mpctx->subdata, mpctx->video_pts, movement); #ifdef CONFIG_ASS - if (ass_track) + if (mpctx->osd->ass_track) sub_delay += - ass_step_sub(ass_track, + ass_step_sub(mpctx->osd->ass_track, (mpctx->video_pts + sub_delay) * 1000 + .5, movement) / 1000.; #endif diff --git a/libmpcodecs/vf.h b/libmpcodecs/vf.h index 0d10abd6c6..8814ffe11a 100644 --- a/libmpcodecs/vf.h +++ b/libmpcodecs/vf.h @@ -107,8 +107,8 @@ typedef struct vf_seteq_s #define VFCTRL_DRAW_EOSD 16 /* Render EOSD */ #define VFCTRL_SET_DEINTERLACE 18 /* Set deinterlacing status */ #define VFCTRL_GET_DEINTERLACE 19 /* Get deinterlacing status */ -/* Hack to make the OSD state object available to vf_expand which accesses - * the OSD state outside of normal OSD draw time. */ +/* Hack to make the OSD state object available to vf_expand and vf_ass which + * access OSD/subtitle state outside of normal OSD draw time. */ #define VFCTRL_SET_OSD_OBJ 20 #define VFCTRL_REDRAW_OSD 21 /* Change user-visible OSD immediately */ #define VFCTRL_SET_YUV_COLORSPACE 22 diff --git a/libmpcodecs/vf_ass.c b/libmpcodecs/vf_ass.c index 2678986025..f1a43b52bd 100644 --- a/libmpcodecs/vf_ass.c +++ b/libmpcodecs/vf_ass.c @@ -33,6 +33,7 @@ #include "img_format.h" #include "mp_image.h" #include "vf.h" +#include "libvo/sub.h" #include "libvo/fastmemcpy.h" @@ -59,6 +60,7 @@ static const struct vf_priv_s { // 0 = insert always int auto_insert; + struct osd_state *osd; ASS_Renderer *ass_priv; unsigned char *planes[3]; @@ -68,9 +70,7 @@ static const struct vf_priv_s { } *line_limits; } vf_priv_dflt; -extern ASS_Track *ass_track; extern float sub_delay; -extern int sub_visibility; static int config(struct vf_instance *vf, int width, int height, int d_width, int d_height, @@ -351,9 +351,10 @@ static int render_frame(struct vf_instance *vf, mp_image_t *mpi, static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts) { ASS_Image *images = 0; - if (sub_visibility && vf->priv->ass_priv && ass_track + if (sub_visibility && vf->priv->ass_priv && vf->priv->osd->ass_track && (pts != MP_NOPTS_VALUE)) - images = ass_mp_render_frame(vf->priv->ass_priv, ass_track, + images = ass_mp_render_frame(vf->priv->ass_priv, + vf->priv->osd->ass_track, (pts + sub_delay) * 1000 + .5, NULL); prepare_image(vf, mpi); @@ -377,6 +378,9 @@ static int query_format(struct vf_instance *vf, unsigned int fmt) static int control(vf_instance_t *vf, int request, void *data) { switch (request) { + case VFCTRL_SET_OSD_OBJ: + vf->priv->osd = data; + break; case VFCTRL_INIT_EOSD: vf->priv->ass_priv = ass_renderer_init((ASS_Library *)data); if (!vf->priv->ass_priv) diff --git a/libmpcodecs/vf_vo.c b/libmpcodecs/vf_vo.c index 0e8563d5a6..81dff4cea9 100644 --- a/libmpcodecs/vf_vo.c +++ b/libmpcodecs/vf_vo.c @@ -29,14 +29,11 @@ #include "libvo/video_out.h" -#ifdef CONFIG_ASS #include "ass_mp.h" -extern ASS_Track *ass_track; -#endif +#include "libvo/sub.h" //===========================================================================// -extern int sub_visibility; extern float sub_delay; struct vf_priv_s { @@ -141,10 +138,12 @@ static int control(struct vf_instance *vf, int request, void* data) } case VFCTRL_DRAW_EOSD: { + struct osd_state *osd = data; mp_eosd_images_t images = {NULL, 2}; double pts = video_out->next_pts; if (!video_out->config_ok || !vf->priv->ass_priv) return CONTROL_FALSE; - if (sub_visibility && vf->priv->ass_priv && ass_track && (pts != MP_NOPTS_VALUE)) { + if (sub_visibility && vf->priv->ass_priv && osd->ass_track + && (pts != MP_NOPTS_VALUE)) { mp_eosd_res_t res; memset(&res, 0, sizeof(res)); if (vo_control(video_out, VOCTRL_GET_EOSD_RES, &res) == VO_TRUE) { @@ -153,7 +152,10 @@ static int control(struct vf_instance *vf, int request, void* data) ass_set_aspect_ratio(vf->priv->ass_priv, vf->priv->scale_ratio, 1); } - images.imgs = ass_mp_render_frame(vf->priv->ass_priv, ass_track, (pts+sub_delay) * 1000 + .5, &images.changed); + images.imgs = ass_mp_render_frame(vf->priv->ass_priv, + osd->ass_track, + (pts+sub_delay) * 1000 + .5, + &images.changed); if (!vf->priv->prev_visibility) images.changed = 2; vf->priv->prev_visibility = 1; diff --git a/libvo/sub.h b/libvo/sub.h index f3a6f072c2..12d5474e5f 100644 --- a/libvo/sub.h +++ b/libvo/sub.h @@ -69,6 +69,7 @@ typedef struct mp_osd_obj_s { struct osd_state { unsigned char osd_text[128]; struct font_desc *sub_font; + struct ass_track *ass_track; }; #include "subreader.h" diff --git a/mpcommon.h b/mpcommon.h index 8a55d33a9f..ac57ae9d02 100644 --- a/mpcommon.h +++ b/mpcommon.h @@ -19,8 +19,6 @@ #ifndef MPLAYER_MPCOMMON_H #define MPLAYER_MPCOMMON_H -extern struct ass_track *ass_track; - extern const char *mplayer_version; #endif /* MPLAYER_MPCOMMON_H */ diff --git a/mplayer.c b/mplayer.c index 091287c1fd..f36bb2788f 100644 --- a/mplayer.c +++ b/mplayer.c @@ -335,9 +335,6 @@ int subcc_enabled=0; int suboverlap_enabled = 1; #include "ass_mp.h" -#ifdef CONFIG_ASS -ASS_Track *ass_track = 0; // current track to render -#endif char* current_module=NULL; // for debugging @@ -1949,10 +1946,10 @@ void update_subtitles(struct MPContext *mpctx, double refpts, #ifdef CONFIG_ASS if (opts->ass_enabled) { sh_sub_t* sh = d_sub->sh; - ass_track = sh ? sh->ass_track : NULL; - if (!ass_track) continue; + mpctx->osd->ass_track = sh ? sh->ass_track : NULL; + if (!mpctx->osd->ass_track) continue; if (type == 'a') { // ssa/ass subs with libass - ass_process_chunk(ass_track, packet, len, + ass_process_chunk(mpctx->osd->ass_track, packet, len, (long long)(subpts*1000 + 0.5), (long long)((endpts-subpts)*1000 + 0.5)); } else { // plaintext subs with libass @@ -1962,7 +1959,7 @@ void update_subtitles(struct MPContext *mpctx, double refpts, sub_add_text(&tmp_subs, packet, len, endpts); tmp_subs.start = subpts * 100; tmp_subs.end = endpts * 100; - ass_process_subtitle(ass_track, &tmp_subs); + ass_process_subtitle(mpctx->osd->ass_track, &tmp_subs); sub_clear_text(&tmp_subs, MP_NOPTS_VALUE); } } @@ -3416,7 +3413,7 @@ static void run_playloop(struct MPContext *mpctx) update_teletext(sh_video, mpctx->demuxer, 0); update_osd_msg(mpctx); struct vf_instance *vf = sh_video->vfilter; - vf->control(vf, VFCTRL_DRAW_EOSD, NULL); + vf->control(vf, VFCTRL_DRAW_EOSD, mpctx->osd); vf->control(vf, VFCTRL_DRAW_OSD, mpctx->osd); vo_osd_changed(0); @@ -4944,7 +4941,7 @@ if(mpctx->set_of_sub_size > 0) { mpctx->vo_sub_last = vo_sub=NULL; mpctx->subdata=NULL; #ifdef CONFIG_ASS -ass_track = NULL; +mpctx->osd->ass_track = NULL; if(ass_library) ass_clear_fonts(ass_library); #endif -- cgit v1.2.3 From e9022ec470e9334a6d0f3cb044027964ac4f63f6 Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Wed, 12 Jan 2011 15:29:31 +0200 Subject: cleanup: move MP_NOPTS_VALUE definition to mpcommon.h --- libmpcodecs/vf.h | 5 +---- libmpdemux/demuxer.h | 4 +--- libvo/video_out.h | 5 +---- mpcommon.h | 3 +++ spudec.c | 3 +-- subreader.c | 2 +- 6 files changed, 8 insertions(+), 14 deletions(-) diff --git a/libmpcodecs/vf.h b/libmpcodecs/vf.h index 8814ffe11a..58cfaaf787 100644 --- a/libmpcodecs/vf.h +++ b/libmpcodecs/vf.h @@ -20,6 +20,7 @@ #define MPLAYER_VF_H #include "mp_image.h" +#include "mpcommon.h" struct MPOpts; struct vf_instance; @@ -116,10 +117,6 @@ typedef struct vf_seteq_s #include "vfcap.h" -//FIXME this should be in a common header, but i dunno which -#define MP_NOPTS_VALUE (-1LL<<63) //both int64_t and double should be able to represent this exactly - - // functions: void vf_mpi_clear(mp_image_t* mpi,int x0,int y0,int w,int h); mp_image_t* vf_get_image(vf_instance_t* vf, unsigned int outfmt, int mp_imgtype, int mp_imgflag, int w, int h); diff --git a/libmpdemux/demuxer.h b/libmpdemux/demuxer.h index 9b66e27910..df0fdaa9bb 100644 --- a/libmpdemux/demuxer.h +++ b/libmpdemux/demuxer.h @@ -27,6 +27,7 @@ #include "stream/stream.h" #include "bstr.h" +#include "mpcommon.h" struct MPOpts; @@ -96,9 +97,6 @@ struct MPOpts; // A virtual demuxer type for the network code #define DEMUXER_TYPE_PLAYLIST (2<<16) - -#define MP_NOPTS_VALUE (-1LL<<63) //both int64_t and double should be able to represent this exactly - enum timestamp_type { TIMESTAMP_TYPE_PTS, TIMESTAMP_TYPE_SORT, diff --git a/libvo/video_out.h b/libvo/video_out.h index 36a161aaf5..0630aee9ca 100644 --- a/libvo/video_out.h +++ b/libvo/video_out.h @@ -26,11 +26,8 @@ #include #include -//#include "font_load.h" #include "libmpcodecs/img_format.h" -//#include "vidix/vidix.h" - -#define MP_NOPTS_VALUE (-1LL<<63) +#include "mpcommon.h" #define VO_EVENT_EXPOSE 1 #define VO_EVENT_RESIZE 2 diff --git a/mpcommon.h b/mpcommon.h index ac57ae9d02..82b860bd87 100644 --- a/mpcommon.h +++ b/mpcommon.h @@ -19,6 +19,9 @@ #ifndef MPLAYER_MPCOMMON_H #define MPLAYER_MPCOMMON_H +// both int64_t and double should be able to represent this exactly +#define MP_NOPTS_VALUE (-1LL<<63) + extern const char *mplayer_version; #endif /* MPLAYER_MPCOMMON_H */ diff --git a/spudec.c b/spudec.c index de7d443ffc..f48d47fd2a 100644 --- a/spudec.c +++ b/spudec.c @@ -43,6 +43,7 @@ #include "libavutil/avutil.h" #include "ffmpeg_files/intreadwrite.h" #include "libswscale/swscale.h" +#include "mpcommon.h" /* Valid values for spu_aamode: 0: none (fastest, most ugly) @@ -1336,8 +1337,6 @@ void spudec_set_hw_spu(void *this, struct vo *hw_spu) vo_control(hw_spu, VOCTRL_SET_SPU_PALETTE, spu->global_palette); } -#define MP_NOPTS_VALUE (-1LL<<63) //both int64_t and double should be able to represent this exactly - /** * palette must contain at least 256 32-bit entries, otherwise crashes * are possible diff --git a/subreader.c b/subreader.c index 3d422ddbdf..c9b3261c0e 100644 --- a/subreader.c +++ b/subreader.c @@ -32,6 +32,7 @@ #include "config.h" #include "mp_msg.h" #include "subreader.h" +#include "mpcommon.h" #include "stream/stream.h" #include "libavutil/common.h" #include "libavutil/avstring.h" @@ -2359,7 +2360,6 @@ void sub_add_text(subtitle *sub, const char *txt, int len, double endpts) { #endif } -#define MP_NOPTS_VALUE (-1LL<<63) /** * \brief remove outdated subtitle lines. * \param sub subtitle struct to modify -- cgit v1.2.3 From ac79632ded16b62e0abf10f1cd319fba20bc0024 Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Fri, 14 Jan 2011 14:05:22 +0200 Subject: subtitles: remove code trying to handle text subs with libavcodec The avsub implementation tries to fall back to MPlayer's other text subtitle decoding if libavcodec returns text as the 'decoded' subtitle. The code implementing this is buggy, and as far as I can see it should not be triggered normally (libavcodec decoding is only used for xvid, pgs and dvb subtitles, and for those libavcodec should return bitmaps). Remove the buggy code (don't try to support non-bitmap results) and simplify things a bit. --- av_sub.c | 42 ++++++++++++++++++------------------------ av_sub.h | 4 ++-- mplayer.c | 7 ++----- 3 files changed, 22 insertions(+), 31 deletions(-) diff --git a/av_sub.c b/av_sub.c index e850e2ffa2..3f926c8fef 100644 --- a/av_sub.c +++ b/av_sub.c @@ -35,12 +35,11 @@ void reset_avsub(struct sh_sub *sh) * Decode a subtitle packet via libavcodec. * \return < 0 on error, > 0 if further processing is needed */ -int decode_avsub(struct sh_sub *sh, uint8_t **data, int *size, - double *pts, double *endpts) +int decode_avsub(struct sh_sub *sh, uint8_t *data, int size, + double pts, double endpts) { AVCodecContext *ctx = sh->context; enum CodecID cid = CODEC_ID_NONE; - int new_type = 0; int res; int got_sub; AVSubtitle sub; @@ -56,11 +55,11 @@ int decode_avsub(struct sh_sub *sh, uint8_t **data, int *size, } av_init_packet(&pkt); - pkt.data = *data; - pkt.size = *size; - pkt.pts = *pts * 1000; - if (*pts != MP_NOPTS_VALUE && *endpts != MP_NOPTS_VALUE) - pkt.convergence_duration = (*endpts - *pts) * 1000; + pkt.data = data; + pkt.size = size; + pkt.pts = pts * 1000; + if (pts != MP_NOPTS_VALUE && endpts != MP_NOPTS_VALUE) + pkt.convergence_duration = (endpts - pts) * 1000; if (!ctx) { AVCodec *sub_codec; avcodec_init(); @@ -78,13 +77,13 @@ int decode_avsub(struct sh_sub *sh, uint8_t **data, int *size, res = avcodec_decode_subtitle2(ctx, &sub, &got_sub, &pkt); if (res < 0) return res; - if (*pts != MP_NOPTS_VALUE) { + if (pts != MP_NOPTS_VALUE) { if (sub.end_display_time > sub.start_display_time) - *endpts = *pts + sub.end_display_time / 1000.0; - *pts += sub.start_display_time / 1000.0; + endpts = pts + sub.end_display_time / 1000.0; + pts += sub.start_display_time / 1000.0; } if (got_sub && vo_spudec && sub.num_rects == 0) - spudec_set_paletted(vo_spudec, NULL, 0, NULL, 0, 0, 0, 0, *pts, *endpts); + spudec_set_paletted(vo_spudec, NULL, 0, NULL, 0, 0, 0, 0, pts, endpts); if (got_sub && sub.num_rects > 0) { switch (sub.rects[0]->type) { case SUBTITLE_BITMAP: @@ -98,19 +97,14 @@ int decode_avsub(struct sh_sub *sh, uint8_t **data, int *size, sub.rects[0]->y, sub.rects[0]->w, sub.rects[0]->h, - *pts, - *endpts); + pts, + endpts); vo_osd_changed(OSDTYPE_SPU); break; - case SUBTITLE_TEXT: - *data = strdup(sub.rects[0]->text); - *size = strlen(*data); - new_type = 't'; - break; - case SUBTITLE_ASS: - *data = strdup(sub.rects[0]->ass); - *size = strlen(*data); - new_type = 'a'; + default: + mp_msg(MSGT_SUBREADER, MSGL_ERR, "sd_avsub: unsupported subtitle " + "type from libavcodec\n"); + res = -1; break; } } @@ -118,5 +112,5 @@ int decode_avsub(struct sh_sub *sh, uint8_t **data, int *size, if (got_sub) avsubtitle_free(&sub); #endif - return new_type; + return res; } diff --git a/av_sub.h b/av_sub.h index 690ed6c1f1..af3edc4d34 100644 --- a/av_sub.h +++ b/av_sub.h @@ -24,7 +24,7 @@ struct sh_sub; void reset_avsub(struct sh_sub *sh); -int decode_avsub(struct sh_sub *sh, uint8_t **data, int *size, - double *pts, double *endpts); +int decode_avsub(struct sh_sub *sh, uint8_t *data, int size, + double pts, double endpts); #endif /* MPLAYER_AV_SUB_H */ diff --git a/mplayer.c b/mplayer.c index f36bb2788f..382fe2a6f5 100644 --- a/mplayer.c +++ b/mplayer.c @@ -1901,10 +1901,8 @@ void update_subtitles(struct MPContext *mpctx, double refpts, if (d_sub->non_interleaved) ds_get_next_pts(d_sub); - int orig_type = type; while (d_sub->first) { double subpts = ds_get_next_pts(d_sub) + sub_offset; - type = orig_type; if (subpts > curpts) { // Libass handled subs can be fed to it in advance if (!opts->ass_enabled || !is_text_sub(type)) @@ -1917,10 +1915,9 @@ void update_subtitles(struct MPContext *mpctx, double refpts, len = ds_get_packet_sub(d_sub, &packet); if (is_av_sub(type)) { #ifdef CONFIG_FFMPEG - type = decode_avsub(d_sub->sh, &packet, &len, &subpts, &endpts); - if (type <= 0) + decode_avsub(d_sub->sh, packet, len, subpts, endpts); #endif - continue; + continue; } if (type == 'm') { if (len < 2) continue; -- cgit v1.2.3 From 8636eb77c5f9f1e49a12e3e1653fe4c2e8e0bfc3 Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Sat, 15 Jan 2011 22:26:27 +0200 Subject: options: add special -leak-report option Add a special option "-leak-report" that enables talloc leak reporting. It only works if it's given as the first argument. The code abuses the CONF_TYPE_PRINT option type to make main option parsing ignore the option. The parser incorrectly consumed the following commandline argument as a "parameter" for options of this type when they had the flag to not exit after printing the message. Fix this. It makes no difference for any previously existing option I think. --- cfg-mplayer.h | 1 + m_option.c | 2 +- mplayer.c | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cfg-mplayer.h b/cfg-mplayer.h index 7f0ee1f729..8b69908c7f 100644 --- a/cfg-mplayer.h +++ b/cfg-mplayer.h @@ -296,6 +296,7 @@ const m_option_t mplayer_opts[]={ {"lircconf", &lirc_configfile, CONF_TYPE_STRING, CONF_GLOBAL, 0, 0, NULL}, #endif + {"leak-report", "", CONF_TYPE_PRINT, 0, 0, 0, (void*)1}, // these should be removed when gmplayer is forgotten