From d17d2fdc7c536821b3fea8c4a37c0ad09fc487db Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 11 Jul 2013 20:08:12 +0200 Subject: demux: change signature of open functions, cleanups Preparation for redoing the open functions. --- demux/demux_libass.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'demux/demux_libass.c') diff --git a/demux/demux_libass.c b/demux/demux_libass.c index cbc85b3abe..4dadb42b89 100644 --- a/demux/demux_libass.c +++ b/demux/demux_libass.c @@ -41,7 +41,7 @@ static int d_check_file(struct demuxer *demuxer) // library handles mismatch, so make sure everything uses a global handle. ASS_Library *lib = demuxer->params ? demuxer->params->ass_library : NULL; if (!lib) - return 0; + return -1; // Probe by loading a part of the beginning of the file with libass. // Incomplete scripts are usually ok, and we hope libass is not verbose @@ -64,7 +64,7 @@ static int d_check_file(struct demuxer *demuxer) talloc_free(cbuf.start); talloc_free(buf.start); if (!track) - return 0; + return -1; ass_free_track(track); // Actually load the full thing. @@ -73,7 +73,7 @@ static int d_check_file(struct demuxer *demuxer) if (!buf.start) { mp_tmsg(MSGT_ASS, MSGL_ERR, "Refusing to load subtitle file " "larger than 100 MB: %s\n", demuxer->filename); - return 0; + return -1; } cbuf = mp_charset_guess_and_conv_to_utf8(buf, user_cp, MP_ICONV_VERBOSE); if (cbuf.start == NULL) @@ -83,7 +83,7 @@ static int d_check_file(struct demuxer *demuxer) talloc_free(cbuf.start); talloc_free(buf.start); if (!track) - return 0; + return -1; track->name = strdup(demuxer->filename); @@ -96,7 +96,7 @@ static int d_check_file(struct demuxer *demuxer) sh->sub->track = track; sh->codec = "ass"; - return DEMUXER_TYPE_LIBASS; + return 0; } static void d_close(struct demuxer *demuxer) -- cgit v1.2.3 From 3269bd178020c5d821e8b2d1fd807a38d63e93ce Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 12 Jul 2013 21:58:11 +0200 Subject: demux: rewrite probing and demuxer initialization Get rid of the strange and messy reliance on DEMUXER_TYPE_ constants. Instead of having two open functions for the demuxer callbacks (which somehow are both optional, but you can also decide to implement both...), just have one function. This function takes a parameter that tells the demuxer how strictly it should check for the file headers. This is a nice simplification and allows more flexibility. Remove the file extension code. This literally did nothing (anymore). Change demux_lavf so that we check our other builtin demuxers first before libavformat tries to guess by file extension. --- demux/demux_libass.c | 61 ++++++++++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 30 deletions(-) (limited to 'demux/demux_libass.c') diff --git a/demux/demux_libass.c b/demux/demux_libass.c index 4dadb42b89..24e1b9e114 100644 --- a/demux/demux_libass.c +++ b/demux/demux_libass.c @@ -33,7 +33,7 @@ struct priv { ASS_Track *track; }; -static int d_check_file(struct demuxer *demuxer) +static int d_check_file(struct demuxer *demuxer, enum demux_check check) { const char *user_cp = demuxer->opts->sub_cp; struct stream *s = demuxer->stream; @@ -43,42 +43,45 @@ static int d_check_file(struct demuxer *demuxer) if (!lib) return -1; - // Probe by loading a part of the beginning of the file with libass. - // Incomplete scripts are usually ok, and we hope libass is not verbose - // when dealing with (from its perspective) completely broken binary - // garbage. - - bstr buf = stream_peek(s, PROBE_SIZE); - // Older versions of libass will overwrite the input buffer, and despite - // passing length, expect a 0 termination. - void *tmp = talloc_size(NULL, buf.len + 1); - memcpy(tmp, buf.start, buf.len); - buf.start = tmp; - buf.start[buf.len] = '\0'; - bstr cbuf = - mp_charset_guess_and_conv_to_utf8(buf, user_cp, MP_ICONV_ALLOW_CUTOFF); - if (cbuf.start == NULL) - cbuf = buf; - ASS_Track *track = ass_read_memory(lib, cbuf.start, cbuf.len, NULL); - if (cbuf.start != buf.start) - talloc_free(cbuf.start); - talloc_free(buf.start); - if (!track) - return -1; - ass_free_track(track); + if (check >= DEMUX_CHECK_UNSAFE) { + // Probe by loading a part of the beginning of the file with libass. + // Incomplete scripts are usually ok, and we hope libass is not verbose + // when dealing with (from its perspective) completely broken binary + // garbage. + + bstr buf = stream_peek(s, PROBE_SIZE); + // Older versions of libass will overwrite the input buffer, and despite + // passing length, expect a 0 termination. + void *tmp = talloc_size(NULL, buf.len + 1); + memcpy(tmp, buf.start, buf.len); + buf.start = tmp; + buf.start[buf.len] = '\0'; + bstr cbuf = mp_charset_guess_and_conv_to_utf8(buf, user_cp, + MP_ICONV_ALLOW_CUTOFF); + if (cbuf.start == NULL) + cbuf = buf; + ASS_Track *track = ass_read_memory(lib, cbuf.start, cbuf.len, NULL); + if (cbuf.start != buf.start) + talloc_free(cbuf.start); + talloc_free(buf.start); + if (!track) + return -1; + ass_free_track(track); + } // Actually load the full thing. - buf = stream_read_complete(s, NULL, 100000000); + bstr buf = stream_read_complete(s, NULL, 100000000); if (!buf.start) { mp_tmsg(MSGT_ASS, MSGL_ERR, "Refusing to load subtitle file " "larger than 100 MB: %s\n", demuxer->filename); return -1; } - cbuf = mp_charset_guess_and_conv_to_utf8(buf, user_cp, MP_ICONV_VERBOSE); + bstr cbuf = mp_charset_guess_and_conv_to_utf8(buf, user_cp, + MP_ICONV_VERBOSE); if (cbuf.start == NULL) cbuf = buf; - track = ass_read_memory(lib, cbuf.start, cbuf.len, NULL); + ASS_Track *track = ass_read_memory(lib, cbuf.start, cbuf.len, NULL); if (cbuf.start != buf.start) talloc_free(cbuf.start); talloc_free(buf.start); @@ -114,8 +117,6 @@ const struct demuxer_desc demuxer_desc_libass = { .shortdesc = "ASS/SSA subtitles (libass)", .author = "", .comment = "", - .safe_check = 1, - .type = DEMUXER_TYPE_LIBASS, - .check_file = d_check_file, + .open = d_check_file, .close = d_close, }; -- cgit v1.2.3 From 6c414f8c7a66ce3bb0c2446cb7fb0fb802a9e98b Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 12 Jul 2013 22:12:02 +0200 Subject: demux: remove useless author/comment fields Same deal as with previous commit. --- demux/demux_libass.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'demux/demux_libass.c') diff --git a/demux/demux_libass.c b/demux/demux_libass.c index 24e1b9e114..1dc8e92eb0 100644 --- a/demux/demux_libass.c +++ b/demux/demux_libass.c @@ -112,11 +112,8 @@ static void d_close(struct demuxer *demuxer) } const struct demuxer_desc demuxer_desc_libass = { - .info = "Read subtitles with libass", .name = "libass", - .shortdesc = "ASS/SSA subtitles (libass)", - .author = "", - .comment = "", + .desc = "ASS/SSA subtitles (libass)", .open = d_check_file, .close = d_close, }; -- cgit v1.2.3