diff options
author | wm4 <wm4@nowhere> | 2013-04-29 01:49:20 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2013-05-30 22:44:18 +0200 |
commit | 28116b8a799078b3c6b3b559ed4463669c79cf0e (patch) | |
tree | 43e78d552443e08d5250774c01a5da245cd2b50f | |
parent | fd02f0f4d88371c728aff3b4487974118ba4d014 (diff) | |
download | mpv-28116b8a799078b3c6b3b559ed4463669c79cf0e.tar.bz2 mpv-28116b8a799078b3c6b3b559ed4463669c79cf0e.tar.xz |
sub: remove some global variables
-rw-r--r-- | core/cfg-mplayer.h | 16 | ||||
-rw-r--r-- | core/command.c | 12 | ||||
-rw-r--r-- | core/defaultopts.c | 2 | ||||
-rw-r--r-- | core/mplayer.c | 11 | ||||
-rw-r--r-- | core/options.h | 10 | ||||
-rw-r--r-- | sub/ass_mp.c | 4 | ||||
-rw-r--r-- | sub/find_subfiles.c | 9 | ||||
-rw-r--r-- | sub/osd_libass.c | 2 | ||||
-rw-r--r-- | sub/sub.c | 19 | ||||
-rw-r--r-- | sub/sub.h | 9 | ||||
-rw-r--r-- | sub/subreader.c | 134 | ||||
-rw-r--r-- | sub/subreader.h | 17 |
12 files changed, 108 insertions, 137 deletions
diff --git a/core/cfg-mplayer.h b/core/cfg-mplayer.h index 529972766b..c29d4c4060 100644 --- a/core/cfg-mplayer.h +++ b/core/cfg-mplayer.h @@ -472,18 +472,18 @@ const m_option_t common_opts[] = { OPT_STRINGLIST("sub", sub_name, 0), OPT_PATHLIST("sub-paths", sub_paths, 0), - {"subcp", &sub_cp, CONF_TYPE_STRING, 0, 0, 0, NULL}, - {"sub-delay", &sub_delay, CONF_TYPE_FLOAT, 0, 0.0, 10.0, NULL}, - {"subfps", &sub_fps, CONF_TYPE_FLOAT, 0, 0.0, 10.0, NULL}, + OPT_STRING("subcp", sub_cp, 0), + OPT_FLOAT("sub-delay", sub_delay, 0), + OPT_FLOAT("subfps", sub_fps, 0), OPT_FLAG("autosub", sub_auto, 0), OPT_FLAG("sub-visibility", sub_visibility, 0), OPT_FLAG("sub-forced-only", forced_subs_only, 0), // enable Closed Captioning display - {"overlapsub", &suboverlap_enabled, CONF_TYPE_FLAG, 0, 0, 2, NULL}, - {"sub-no-text-pp", &sub_no_text_pp, CONF_TYPE_FLAG, 0, 0, 1, NULL}, - {"autosub-match", &sub_match_fuzziness, CONF_TYPE_CHOICE, 0, - M_CHOICES(({"exact", 0}, {"fuzzy", 1}, {"all", 2}))}, - {"sub-pos", &sub_pos, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL}, + OPT_FLAG_CONSTANTS("overlapsub", suboverlap_enabled, 0, 0, 2), + OPT_FLAG_STORE("sub-no-text-pp", sub_no_text_pp, 0, 1), + OPT_CHOICE("autosub-match", sub_match_fuzziness, 0, + ({"exact", 0}, {"fuzzy", 1}, {"all", 2})), + OPT_INTRANGE("sub-pos", sub_pos, 0, 0, 100), OPT_FLOATRANGE("sub-gauss", sub_gauss, 0, 0.0, 3.0), OPT_FLAG("sub-gray", sub_gray, 0), OPT_FLAG("ass", ass_enabled, 0), diff --git a/core/command.c b/core/command.c index 5fa914fdf7..7971180553 100644 --- a/core/command.c +++ b/core/command.c @@ -1272,11 +1272,12 @@ static int mp_property_sub(m_option_t *prop, int action, void *arg, static int mp_property_sub_delay(m_option_t *prop, int action, void *arg, MPContext *mpctx) { + struct MPOpts *opts = &mpctx->opts; if (!mpctx->sh_video) return M_PROPERTY_UNAVAILABLE; switch (action) { case M_PROPERTY_PRINT: - *(char **)arg = format_delay(sub_delay); + *(char **)arg = format_delay(opts->sub_delay); return M_PROPERTY_OK; } return mp_property_generic_option(prop, action, arg, mpctx); @@ -1285,10 +1286,11 @@ static int mp_property_sub_delay(m_option_t *prop, int action, void *arg, static int mp_property_sub_pos(m_option_t *prop, int action, void *arg, MPContext *mpctx) { + struct MPOpts *opts = &mpctx->opts; if (!mpctx->sh_video) return M_PROPERTY_UNAVAILABLE; if (action == M_PROPERTY_PRINT) { - *(char **)arg = talloc_asprintf(NULL, "%d/100", sub_pos); + *(char **)arg = talloc_asprintf(NULL, "%d/100", opts->sub_pos); return M_PROPERTY_OK; } return property_osd_helper(prop, action, arg, mpctx); @@ -1954,9 +1956,9 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd) struct ass_track *ass_track = sub_get_ass_track(mpctx->osd); if (ass_track) { set_osd_tmsg(mpctx, OSD_MSG_SUB_DELAY, osdl, osd_duration, - "Sub delay: %d ms", ROUND(sub_delay * 1000)); - sub_delay += ass_step_sub(ass_track, - (mpctx->video_pts + sub_delay) * 1000 + .5, movement) / 1000.; + "Sub delay: %d ms", ROUND(opts->sub_delay * 1000)); + double cur = (mpctx->video_pts + opts->sub_delay) * 1000 + .5; + opts->sub_delay += ass_step_sub(ass_track, cur, movement) / 1000.; } } #endif diff --git a/core/defaultopts.c b/core/defaultopts.c index c4e2a0fa98..93dad1e624 100644 --- a/core/defaultopts.c +++ b/core/defaultopts.c @@ -74,6 +74,7 @@ void set_default_mplayer_options(struct MPOpts *opts) .sub_id = -1, .audio_display = 1, .sub_visibility = 1, + .sub_pos = 100, .extension_parsing = 1, .audio_output_channels = MP_CHMAP_INIT_STEREO, .audio_output_format = -1, // AF_FORMAT_UNKNOWN @@ -89,6 +90,7 @@ void set_default_mplayer_options(struct MPOpts *opts) .ass_vsfilter_aspect_compat = 1, .ass_style_override = 1, .use_embedded_fonts = 1, + .suboverlap_enabled = 1, .hwdec_codecs = "all", diff --git a/core/mplayer.c b/core/mplayer.c index c596aa8504..c832aa1fcb 100644 --- a/core/mplayer.c +++ b/core/mplayer.c @@ -1056,7 +1056,7 @@ struct track *mp_add_subtitles(struct MPContext *mpctx, char *filename, // the weird special-cases. #ifdef CONFIG_ASS if (opts->ass_enabled) { - asst = mp_ass_read_stream(mpctx->ass_library, filename, sub_cp); + asst = mp_ass_read_stream(mpctx->ass_library, filename, opts->sub_cp); codec = "ass"; } if (!asst) { @@ -1389,7 +1389,7 @@ static mp_osd_msg_t *get_osd_msg(struct MPContext *mpctx) if (mpctx->osd_visible && now >= mpctx->osd_visible) { mpctx->osd_visible = 0; mpctx->osd->progbar_type = -1; // disable - vo_osd_changed(OSDTYPE_PROGBAR); + osd_changed(mpctx->osd, OSDTYPE_PROGBAR); } if (mpctx->osd_function_visible && now >= mpctx->osd_function_visible) { mpctx->osd_function_visible = 0; @@ -1448,7 +1448,7 @@ void set_osd_bar(struct MPContext *mpctx, int type, const char *name, mpctx->osd->progbar_type = type; mpctx->osd->progbar_value = (val - min) / (max - min); mpctx->osd->progbar_num_stops = 0; - vo_osd_changed(OSDTYPE_PROGBAR); + osd_changed(mpctx->osd, OSDTYPE_PROGBAR); return; } @@ -1465,7 +1465,7 @@ static void update_osd_bar(struct MPContext *mpctx, int type, float new_value = (val - min) / (max - min); if (new_value != mpctx->osd->progbar_value) { mpctx->osd->progbar_value = new_value; - vo_osd_changed(OSDTYPE_PROGBAR); + osd_changed(mpctx->osd, OSDTYPE_PROGBAR); } } } @@ -1831,6 +1831,7 @@ static void reset_subtitles(struct MPContext *mpctx) static void update_subtitles(struct MPContext *mpctx, double refpts_tl) { + struct MPOpts *opts = &mpctx->opts; struct sh_sub *sh_sub = mpctx->sh_sub; struct demux_stream *d_sub = sh_sub ? sh_sub->ds : NULL; unsigned char *packet = NULL; @@ -1843,7 +1844,7 @@ static void update_subtitles(struct MPContext *mpctx, double refpts_tl) double video_offset = track->under_timeline ? mpctx->video_offset : 0; - mpctx->osd->sub_offset = video_offset - sub_delay; + mpctx->osd->sub_offset = video_offset - opts->sub_delay; double curpts_s = refpts_tl - mpctx->osd->sub_offset; double refpts_s = refpts_tl - video_offset; diff --git a/core/options.h b/core/options.h index d870ab9677..31b4bc9136 100644 --- a/core/options.h +++ b/core/options.h @@ -83,7 +83,6 @@ typedef struct MPOpts { int osd_level; int osd_duration; int osd_fractions; - char *vobsub_name; int untimed; char *stream_capture; char *stream_dump; @@ -140,9 +139,17 @@ typedef struct MPOpts { char **sub_lang; int audio_display; int sub_visibility; + int sub_pos; + float sub_delay; + float sub_fps; int forced_subs_only; char *quvi_format; + // subreader.c + int suboverlap_enabled; + char *sub_cp; + int sub_no_text_pp; + char *audio_stream; int audio_stream_cache; char *sub_stream; @@ -170,6 +177,7 @@ typedef struct MPOpts { char **sub_name; char **sub_paths; int sub_auto; + int sub_match_fuzziness; int osd_bar_visible; float osd_bar_align_x; float osd_bar_align_y; diff --git a/sub/ass_mp.c b/sub/ass_mp.c index f00bf22428..4be89fb004 100644 --- a/sub/ass_mp.c +++ b/sub/ass_mp.c @@ -84,7 +84,7 @@ ASS_Track *mp_ass_default_track(ASS_Library *library, struct MPOpts *opts) track->WrapStyle = 0; if (opts->ass_styles_file && opts->ass_style_override) - ass_read_styles(track, opts->ass_styles_file, sub_cp); + ass_read_styles(track, opts->ass_styles_file, opts->sub_cp); if (track->n_styles == 0) { track->Kerning = true; @@ -225,7 +225,7 @@ void mp_ass_configure(ASS_Renderer *priv, struct MPOpts *opts, if (opts->ass_style_override) { set_use_margins = opts->ass_use_margins; #if LIBASS_VERSION >= 0x01010000 - set_sub_pos = 100 - sub_pos; + set_sub_pos = 100 - opts->sub_pos; #endif set_line_spacing = opts->ass_line_spacing; set_font_scale = opts->sub_scale; diff --git a/sub/find_subfiles.c b/sub/find_subfiles.c index e77015114b..3519e5c386 100644 --- a/sub/find_subfiles.c +++ b/sub/find_subfiles.c @@ -12,7 +12,6 @@ #include "core/mp_common.h" #include "sub/find_subfiles.h" #include "sub/sub.h" -#include "sub/subreader.h" static struct bstr strip_ext(struct bstr str) { @@ -119,9 +118,9 @@ static void append_dir_subtitles(struct MPOpts *opts, // does it end with a subtitle extension? #ifdef CONFIG_ICONV #ifdef CONFIG_ENCA - int i = (sub_cp && strncasecmp(sub_cp, "enca", 4) != 0) ? 3 : 0; + int i = (opts->sub_cp && strncasecmp(opts->sub_cp, "enca", 4) != 0) ? 3 : 0; #else - int i = sub_cp ? 3 : 0; + int i = opts->sub_cp ? 3 : 0; #endif #else int i = 0; @@ -153,12 +152,12 @@ static void append_dir_subtitles(struct MPOpts *opts, if (!prio && bstrcmp(tmp_fname_trim, f_fname_trim) == 0) prio = 3; // matches the movie name if (!prio && bstr_find(tmp_fname_trim, f_fname_trim) >= 0 - && sub_match_fuzziness >= 1) + && opts->sub_match_fuzziness >= 1) prio = 2; // contains the movie name if (!prio) { // doesn't contain the movie name // don't try in the mplayer subtitle directory - if (!limit_fuzziness && sub_match_fuzziness >= 2) { + if (!limit_fuzziness && opts->sub_match_fuzziness >= 2) { prio = 1; } } diff --git a/sub/osd_libass.c b/sub/osd_libass.c index d8496c2f3b..6733b9b6c2 100644 --- a/sub/osd_libass.c +++ b/sub/osd_libass.c @@ -367,7 +367,7 @@ static void update_sub(struct osd_state *osd, struct osd_object *obj) mp_ass_set_style(style, &font); #if LIBASS_VERSION >= 0x01010000 - ass_set_line_position(osd->osd_render, 100 - sub_pos); + ass_set_line_position(osd->osd_render, 100 - opts->sub_pos); #endif char *escaped_text = mangle_ass(osd->sub_text); @@ -41,12 +41,6 @@ #include "video/mp_image.h" #include "video/mp_image_pool.h" -int sub_pos=100; -int sub_visibility=1; - -float sub_delay = 0; -float sub_fps = 0; - static const struct osd_style_opts osd_style_opts_def = { .font = "Sans", .font_size = 45, @@ -80,8 +74,6 @@ const struct m_sub_options osd_style_conf = { .defaults = &osd_style_opts_def, }; -static struct osd_state *global_osd; - static bool osd_res_equals(struct mp_osd_res a, struct mp_osd_res b) { return a.w == b.w && a.h == b.h && a.ml == b.ml && a.mt == b.mt @@ -114,7 +106,6 @@ struct osd_state *osd_create(struct MPOpts *opts, struct ass_library *asslib) osd->objs[OSDTYPE_SUBTEXT]->is_sub = true; // osd_libass.c osd_init_backend(osd); - global_osd = osd; return osd; } @@ -124,7 +115,6 @@ void osd_free(struct osd_state *osd) return; osd_destroy_backend(osd); talloc_free(osd); - global_osd = NULL; } static bool set_text(void *talloc_ctx, char **var, const char *text) @@ -141,13 +131,13 @@ static bool set_text(void *talloc_ctx, char **var, const char *text) void osd_set_text(struct osd_state *osd, const char *text) { if (!set_text(osd, &osd->osd_text, text)) - vo_osd_changed(OSDTYPE_OSD); + osd_changed(osd, OSDTYPE_OSD); } void osd_set_sub(struct osd_state *osd, const char *text) { if (!set_text(osd, &osd->sub_text, text)) - vo_osd_changed(OSDTYPE_SUBTEXT); + osd_changed(osd, OSDTYPE_SUBTEXT); } static void render_object(struct osd_state *osd, struct osd_object *obj, @@ -302,9 +292,8 @@ void osd_draw_on_image_p(struct osd_state *osd, struct mp_osd_res res, &draw_on_image, &closure); } -void vo_osd_changed(int new_value) +void osd_changed(struct osd_state *osd, int new_value) { - struct osd_state *osd = global_osd; for (int n = 0; n < MAX_OSD_PARTS; n++) { if (osd->objs[n]->type == new_value) osd->objs[n]->force_redraw = true; @@ -315,5 +304,5 @@ void vo_osd_changed(int new_value) void osd_changed_all(struct osd_state *osd) { for (int n = 0; n < MAX_OSD_PARTS; n++) - vo_osd_changed(n); + osd_changed(osd, n); } @@ -198,17 +198,10 @@ struct osd_style_opts { extern const struct m_sub_options osd_style_conf; -extern char *sub_cp; -extern int sub_pos; - -extern float sub_delay; -extern float sub_fps; - - struct osd_state *osd_create(struct MPOpts *opts, struct ass_library *asslib); void osd_set_text(struct osd_state *osd, const char *text); void osd_set_sub(struct osd_state *osd, const char *text); -void vo_osd_changed(int new_value); +void osd_changed(struct osd_state *osd, int new_value); void osd_changed_all(struct osd_state *osd); void osd_free(struct osd_state *osd); diff --git a/sub/subreader.c b/sub/subreader.c index 365f8aa532..12da7d8f3b 100644 --- a/sub/subreader.c +++ b/sub/subreader.c @@ -48,42 +48,33 @@ #include <iconv.h> #endif -char *sub_cp=NULL; - - -int suboverlap_enabled = 1; - // Parameter struct for the format-specific readline functions struct readline_args { int utf16; struct MPOpts *opts; + + // subtitle reader state used by some formats + + float mpsub_multiplier; + float mpsub_position; + int sub_slacktime; + + /* + Some subtitling formats, namely AQT and Subrip09, define the end of a + subtitle as the beginning of the following. Since currently we read one + subtitle at time, for these format we keep two global *subtitle, + previous_aqt_sub and previous_subrip09_sub, pointing to previous subtitle, + so we can change its end when we read current subtitle starting time. + We use a single global unsigned long, + previous_sub_end, for both (and even future) formats, to store the end of + the previous sub: it is initialized to 0 in sub_read_file and eventually + modified by sub_read_aqt_line or sub_read_subrip09_line. + */ + unsigned long previous_sub_end; }; /* Maximal length of line of a subtitle */ #define LINE_LEN 1000 -static float mpsub_position=0; -static float mpsub_multiplier=1.; -static int sub_slacktime = 20000; //20 sec - -int sub_no_text_pp=0; // 1 => do not apply text post-processing - // like {\...} elimination in SSA format. - -int sub_match_fuzziness=0; // level of sub name matching fuzziness - -/* Use the SUB_* constant defined in the header file */ -int sub_format=SUB_INVALID; -/* - Some subtitling formats, namely AQT and Subrip09, define the end of a - subtitle as the beginning of the following. Since currently we read one - subtitle at time, for these format we keep two global *subtitle, - previous_aqt_sub and previous_subrip09_sub, pointing to previous subtitle, - so we can change its end when we read current subtitle starting time. - We use a single global unsigned long, - previous_sub_end, for both (and even future) formats, to store the end of - the previous sub: it is initialized to 0 in sub_read_file and eventually - modified by sub_read_aqt_line or sub_read_subrip09_line. - */ -unsigned long previous_sub_end; static int eol(char p) { return p=='\r' || p=='\n' || p=='\0'; @@ -145,7 +136,7 @@ static subtitle *sub_read_line_sami(stream_t* st, subtitle *current, case 0: /* find "START=" or "Slacktime:" */ slacktime_s = stristr (s, "Slacktime:"); if (slacktime_s) - sub_slacktime = strtol (slacktime_s+10, NULL, 0) / 10; + args->sub_slacktime = strtol (slacktime_s+10, NULL, 0) / 10; s = stristr (s, "Start="); if (s) { @@ -181,7 +172,7 @@ static subtitle *sub_read_line_sami(stream_t* st, subtitle *current, sami_add_line(current, text, &p); s += 4; } - else if ((*s == '{') && !sub_no_text_pp) { state = 5; ++s; continue; } + else if ((*s == '{') && !args->opts->sub_no_text_pp) { state = 5; ++s; continue; } else if (*s == '<') { state = 4; } else if (!strncasecmp (s, " ", 6)) { *p++ = ' '; s += 6; } else if (*s == '\t') { *p++ = ' '; s++; } @@ -207,7 +198,7 @@ static subtitle *sub_read_line_sami(stream_t* st, subtitle *current, if (s) { s++; state = 3; continue; } break; case 5: /* get rid of {...} text, but read the alignment code */ - if ((*s == '\\') && (*(s + 1) == 'a') && !sub_no_text_pp) { + if ((*s == '\\') && (*(s + 1) == 'a') && !args->opts->sub_no_text_pp) { if (stristr(s, "\\a1") != NULL) { current->alignment = SUB_ALIGNMENT_BOTTOMLEFT; s = s + 3; @@ -256,7 +247,7 @@ static subtitle *sub_read_line_sami(stream_t* st, subtitle *current, // For the last subtitle if (current->end <= 0) { - current->end = current->start + sub_slacktime; + current->end = current->start + args->sub_slacktime; sami_add_line(current, text, &p); } @@ -761,10 +752,10 @@ static subtitle *sub_read_line_mpsub(stream_t *st, subtitle *current, if (!stream_read_line(st, line, LINE_LEN, utf16)) return NULL; } while (sscanf (line, "%f %f", &a, &b) !=2); - mpsub_position += a*mpsub_multiplier; - current->start=(int) mpsub_position; - mpsub_position += b*mpsub_multiplier; - current->end=(int) mpsub_position; + args->mpsub_position += a*args->mpsub_multiplier; + current->start=(int) args->mpsub_position; + args->mpsub_position += b*args->mpsub_multiplier; + current->end=(int) args->mpsub_position; while (num < SUB_MAX_TEXT) { if (!stream_read_line (st, line, LINE_LEN, utf16)) { @@ -805,8 +796,8 @@ retry: break; } - if (!previous_sub_end) - previous_sub_end = (current->start) ? current->start - 1 : 0; + if (!args->previous_sub_end) + args->previous_sub_end = (current->start) ? current->start - 1 : 0; if (!stream_read_line (st, line, LINE_LEN, utf16)) return NULL; @@ -846,8 +837,8 @@ retry: current->start = a1*360000+a2*6000+a3*100; - if (!previous_sub_end) - previous_sub_end = (current->start) ? current->start - 1 : 0; + if (!args->previous_sub_end) + args->previous_sub_end = (current->start) ? current->start - 1 : 0; if (!stream_read_line (st, line, LINE_LEN, utf16)) return NULL; @@ -1109,14 +1100,12 @@ static int sub_autodetect (stream_t* st, int *uses_time, int utf16) { return SUB_INVALID; // too many bad lines } -extern float sub_delay; -extern float sub_fps; - #ifdef CONFIG_ICONV -static iconv_t icdsc = (iconv_t)(-1); +static const char* guess_cp(stream_t *st, const char *preferred_language, const char *fallback); -void subcp_open (stream_t *st) +static iconv_t subcp_open (stream_t *st, const char *sub_cp) { + iconv_t icdsc = (iconv_t)(-1); char *tocp = "UTF-8"; if (sub_cp){ @@ -1139,18 +1128,18 @@ void subcp_open (stream_t *st) } else mp_msg(MSGT_SUBREADER,MSGL_ERR,"SUB: error opening iconv descriptor.\n"); } + return icdsc; } -void subcp_close (void) +static void subcp_close (iconv_t icdsc) { if (icdsc != (iconv_t)(-1)){ (void) iconv_close (icdsc); - icdsc = (iconv_t)(-1); mp_msg(MSGT_SUBREADER,MSGL_V,"SUB: closed iconv descriptor.\n"); } } -subtitle* subcp_recode (subtitle *sub) +static subtitle* subcp_recode (iconv_t icdsc, subtitle *sub) { int l=sub->lines; size_t ileft, oleft; @@ -1184,7 +1173,8 @@ subtitle* subcp_recode (subtitle *sub) } #endif -static void adjust_subs_time(subtitle* sub, float subtime, float fps, int block, +static void adjust_subs_time(subtitle* sub, float subtime, float fps, + float sub_fps, int block, int sub_num, int sub_uses_time) { int n,m; subtitle* nextsub; @@ -1251,7 +1241,7 @@ struct subreader { }; #ifdef CONFIG_ENCA -const char* guess_buffer_cp(unsigned char* buffer, int buflen, const char *preferred_language, const char *fallback) +static const char* guess_buffer_cp(unsigned char* buffer, int buflen, const char *preferred_language, const char *fallback) { const char **languages; size_t langcnt; @@ -1291,7 +1281,7 @@ const char* guess_buffer_cp(unsigned char* buffer, int buflen, const char *prefe } #define MAX_GUESS_BUFFER_SIZE (256*1024) -const char* guess_cp(stream_t *st, const char *preferred_language, const char *fallback) +static const char* guess_cp(stream_t *st, const char *preferred_language, const char *fallback) { size_t buflen; unsigned char *buffer; @@ -1343,7 +1333,7 @@ sub_data* sub_read_file(char *filename, float fps, struct MPOpts *opts) if(filename==NULL) return NULL; //qnx segfault fd=open_stream (filename, NULL, NULL); if (!fd) return NULL; - sub_format = SUB_INVALID; + int sub_format = SUB_INVALID; for (utf16 = 0; sub_format == SUB_INVALID && utf16 < 3; utf16++) { sub_format=sub_autodetect (fd, &uses_time, utf16); stream_reset(fd); @@ -1351,7 +1341,10 @@ sub_data* sub_read_file(char *filename, float fps, struct MPOpts *opts) } utf16--; - mpsub_multiplier = (uses_time ? 100.0 : 1.0); + struct readline_args args = {utf16, opts}; + args.sub_slacktime = 20000; //20 sec + args.mpsub_multiplier = (uses_time ? 100.0 : 1.0); + if (sub_format==SUB_INVALID) { mp_msg(MSGT_SUBREADER,MSGL_WARN,"SUB: Could not determine file format\n"); free_stream(fd); @@ -1361,6 +1354,7 @@ sub_data* sub_read_file(char *filename, float fps, struct MPOpts *opts) mp_msg(MSGT_SUBREADER, MSGL_V, "SUB: Detected subtitle file format: %s\n", srp->name); #ifdef CONFIG_ICONV + iconv_t icdsc = (iconv_t)(-1); { int l,k; k = -1; @@ -1371,7 +1365,7 @@ sub_data* sub_read_file(char *filename, float fps, struct MPOpts *opts) break; } } - if (k<0) subcp_open(fd); + if (k<0) icdsc = subcp_open(fd, opts->sub_cp); } #endif @@ -1384,22 +1378,22 @@ sub_data* sub_read_file(char *filename, float fps, struct MPOpts *opts) sub = malloc(sizeof(subtitle)); //This is to deal with those formats (AQT & Subrip) which define the end of a subtitle //as the beginning of the following - previous_sub_end = 0; + args.previous_sub_end = 0; while(1){ if(sub_num>=n_max){ n_max+=16; first=realloc(first,n_max*sizeof(subtitle)); } memset(sub, '\0', sizeof(subtitle)); - sub=srp->read(fd, sub, &(struct readline_args){utf16, opts}); + sub=srp->read(fd, sub, &args); if(!sub) break; // EOF #ifdef CONFIG_ICONV - if (sub!=ERR) sub=subcp_recode(sub); + if (sub!=ERR) sub=subcp_recode(icdsc, sub); #endif if ( sub == ERR ) { #ifdef CONFIG_ICONV - subcp_close(); + subcp_close(icdsc); #endif free(first); free(alloced_sub); @@ -1407,7 +1401,7 @@ sub_data* sub_read_file(char *filename, float fps, struct MPOpts *opts) return NULL; } // Apply any post processing that needs recoding first - if ((sub!=ERR) && !sub_no_text_pp && srp->post) srp->post(sub); + if ((sub!=ERR) && !args.opts->sub_no_text_pp && srp->post) srp->post(sub); if(!sub_num || (first[sub_num - 1].start <= sub->start)){ first[sub_num].start = sub->start; first[sub_num].end = sub->end; @@ -1416,9 +1410,9 @@ sub_data* sub_read_file(char *filename, float fps, struct MPOpts *opts) for(i = 0; i < sub->lines; ++i){ first[sub_num].text[i] = sub->text[i]; } - if (previous_sub_end){ - first[sub_num - 1].end = previous_sub_end; - previous_sub_end = 0; + if (args.previous_sub_end){ + first[sub_num - 1].end = args.previous_sub_end; + args.previous_sub_end = 0; } } else { for(j = sub_num - 1; j >= 0; --j){ @@ -1437,10 +1431,10 @@ sub_data* sub_read_file(char *filename, float fps, struct MPOpts *opts) for(i = 0; i < SUB_MAX_TEXT; ++i){ first[j].text[i] = sub->text[i]; } - if (previous_sub_end){ + if (args.previous_sub_end){ first[j].end = first[j - 1].end; - first[j - 1].end = previous_sub_end; - previous_sub_end = 0; + first[j - 1].end = args.previous_sub_end; + args.previous_sub_end = 0; } break; } @@ -1452,7 +1446,7 @@ sub_data* sub_read_file(char *filename, float fps, struct MPOpts *opts) free_stream(fd); #ifdef CONFIG_ICONV - subcp_close(); + subcp_close(icdsc); #endif free(alloced_sub); @@ -1469,9 +1463,9 @@ sub_data* sub_read_file(char *filename, float fps, struct MPOpts *opts) // the user didn't forced no-overlapsub and the format is Jacosub or Ssa. // this is because usually overlapping subtitles are found in these formats, // while in others they are probably result of bad timing -if ((suboverlap_enabled == 2) || - ((suboverlap_enabled) && ((sub_format == SUB_JACOSUB) || (sub_format == SUB_SSA)))) { - adjust_subs_time(first, 6.0, fps, 0, sub_num, uses_time);/*~6 secs AST*/ +if ((opts->suboverlap_enabled == 2) || + ((opts->suboverlap_enabled) && ((sub_format == SUB_JACOSUB) || (sub_format == SUB_SSA)))) { + adjust_subs_time(first, 6.0, fps, opts->sub_fps, 0, sub_num, uses_time);/*~6 secs AST*/ // here we manage overlapping subtitles sub_orig = sub_num; n_first = sub_num; @@ -1678,7 +1672,7 @@ if ((suboverlap_enabled == 2) || return_sub = second; } else { //if(suboverlap_enabled) - adjust_subs_time(first, 6.0, fps, 1, sub_num, uses_time);/*~6 secs AST*/ + adjust_subs_time(first, 6.0, fps, opts->sub_fps, 1, sub_num, uses_time);/*~6 secs AST*/ return_sub = first; } if (return_sub == NULL) return NULL; diff --git a/sub/subreader.h b/sub/subreader.h index ab4763cefe..c62dd5ddd2 100644 --- a/sub/subreader.h +++ b/sub/subreader.h @@ -24,10 +24,6 @@ #include "config.h" -extern int suboverlap_enabled; -extern int sub_no_text_pp; // disable text post-processing -extern int sub_match_fuzziness; - // subtitle formats #define SUB_INVALID -1 #define SUB_MICRODVD 0 @@ -45,9 +41,6 @@ extern int sub_match_fuzziness; #define SUB_JACOSUB 12 #define SUB_MPL2 13 -// One of the SUB_* constant above -extern int sub_format; - #define SUB_MAX_TEXT 12 #define SUB_ALIGNMENT_BOTTOMLEFT 1 #define SUB_ALIGNMENT_BOTTOMCENTER 2 @@ -81,15 +74,5 @@ typedef struct sub_data { struct MPOpts; sub_data* sub_read_file (char *filename, float pts, struct MPOpts *opts); -subtitle* subcp_recode (subtitle *sub); -// enca_fd is the file enca uses to determine the codepage. -// setting to NULL disables enca. -struct stream; -void subcp_open (struct stream *st); /* for demux_ogg.c */ -void subcp_close (void); /* for demux_ogg.c */ -#ifdef CONFIG_ENCA -const char* guess_buffer_cp(unsigned char* buffer, int buflen, const char *preferred_language, const char *fallback); -const char* guess_cp(struct stream *st, const char *preferred_language, const char *fallback); -#endif #endif /* MPLAYER_SUBREADER_H */ |