diff options
author | wm4 <wm4@nowhere> | 2013-07-14 17:59:26 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2013-07-14 17:59:26 +0200 |
commit | e18ffd6b998858ca0797cb0ce4aabd4a509655dd (patch) | |
tree | 199bddd30923db1175a1331191eb86ba684e9e41 /demux/demux_libass.c | |
parent | 3e7d483ac89289f613138002be2043ec5f479bb0 (diff) | |
parent | 5ead20bdb3328d199dad693039d18e7a05eb2465 (diff) | |
download | mpv-e18ffd6b998858ca0797cb0ce4aabd4a509655dd.tar.bz2 mpv-e18ffd6b998858ca0797cb0ce4aabd4a509655dd.tar.xz |
Merge branch 'remove_old_demuxers'
The merged branch doesn't actually just remove old demuxers, but also
includes a branch of cleanups and some refactoring.
Conflicts:
stream/stream.c
Diffstat (limited to 'demux/demux_libass.c')
-rw-r--r-- | demux/demux_libass.c | 76 |
1 files changed, 37 insertions, 39 deletions
diff --git a/demux/demux_libass.c b/demux/demux_libass.c index cbc85b3abe..1dc8e92eb0 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; @@ -41,49 +41,52 @@ 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; - - // 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 0; - ass_free_track(track); + return -1; + + 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 0; + 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); if (!track) - return 0; + return -1; track->name = strdup(demuxer->filename); @@ -96,7 +99,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) @@ -109,13 +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 = "", - .safe_check = 1, - .type = DEMUXER_TYPE_LIBASS, - .check_file = d_check_file, + .desc = "ASS/SSA subtitles (libass)", + .open = d_check_file, .close = d_close, }; |