From 28116b8a799078b3c6b3b559ed4463669c79cf0e Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 29 Apr 2013 01:49:20 +0200 Subject: sub: remove some global variables --- sub/ass_mp.c | 4 +- sub/find_subfiles.c | 9 ++-- sub/osd_libass.c | 2 +- sub/sub.c | 19 ++------ sub/sub.h | 9 +--- sub/subreader.c | 134 +++++++++++++++++++++++++--------------------------- sub/subreader.h | 17 ------- 7 files changed, 76 insertions(+), 118 deletions(-) (limited to 'sub') 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); diff --git a/sub/sub.c b/sub/sub.c index d26ce17551..9dc5722469 100644 --- a/sub/sub.c +++ b/sub/sub.c @@ -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); } diff --git a/sub/sub.h b/sub/sub.h index 6b15cf90c0..fae7202ed5 100644 --- a/sub/sub.h +++ b/sub/sub.h @@ -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 #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 */ -- cgit v1.2.3