diff options
-rw-r--r-- | TOOLS/old-makefile | 3 | ||||
-rw-r--r-- | demux/demux.c | 4 | ||||
-rw-r--r-- | demux/demux_libass.c | 111 | ||||
-rw-r--r-- | misc/charset_conv.c | 18 | ||||
-rw-r--r-- | misc/charset_conv.h | 2 | ||||
-rw-r--r-- | wscript_build.py | 1 |
6 files changed, 1 insertions, 138 deletions
diff --git a/TOOLS/old-makefile b/TOOLS/old-makefile index 5db558b815..29d9b73eed 100644 --- a/TOOLS/old-makefile +++ b/TOOLS/old-makefile @@ -36,8 +36,7 @@ SOURCES-$(DVDNAV) += stream/stream_dvdnav.c \ stream/stream_dvd_common.c SOURCES-$(RUBBERBAND) += audio/filter/af_rubberband.c -SOURCES-$(LIBASS) += sub/ass_mp.c sub/sd_ass.c \ - demux/demux_libass.c +SOURCES-$(LIBASS) += sub/ass_mp.c sub/sd_ass.c SOURCES-$(LIBBLURAY) += stream/stream_bluray.c diff --git a/demux/demux.c b/demux/demux.c index 3233541be2..a00a3617cc 100644 --- a/demux/demux.c +++ b/demux/demux.c @@ -48,7 +48,6 @@ extern const demuxer_desc_t demuxer_desc_tv; extern const demuxer_desc_t demuxer_desc_mf; extern const demuxer_desc_t demuxer_desc_matroska; extern const demuxer_desc_t demuxer_desc_lavf; -extern const demuxer_desc_t demuxer_desc_libass; extern const demuxer_desc_t demuxer_desc_subreader; extern const demuxer_desc_t demuxer_desc_playlist; extern const demuxer_desc_t demuxer_desc_disc; @@ -68,9 +67,6 @@ const demuxer_desc_t *const demuxer_list[] = { #if HAVE_TV &demuxer_desc_tv, #endif -#if HAVE_LIBASS - &demuxer_desc_libass, -#endif &demuxer_desc_matroska, #if HAVE_LIBARCHIVE &demuxer_desc_libarchive, diff --git a/demux/demux_libass.c b/demux/demux_libass.c deleted file mode 100644 index ef09f042ed..0000000000 --- a/demux/demux_libass.c +++ /dev/null @@ -1,111 +0,0 @@ -/* - * This file is part of mpv. - * - * mpv is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * mpv is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with mpv. If not, see <http://www.gnu.org/licenses/>. - */ - -// Note: just wraps libass, and makes the subtitle track available though -// sh_sub->track. It doesn't produce packets and doesn't support seeking. - -#include <ass/ass.h> -#include <ass/ass_types.h> - -#include "options/options.h" -#include "common/msg.h" -#include "misc/charset_conv.h" -#include "stream/stream.h" -#include "demux.h" - -#define PROBE_SIZE (8 * 1024) - -static void message_callback(int level, const char *format, va_list va, void *ctx) -{ - // ignore -} - -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; - struct mp_log *log = demuxer->log; - - if (!demuxer->params || !demuxer->params->expect_subtitle) - return -1; - - if (check >= DEMUX_CHECK_UNSAFE) { - ASS_Library *lib = ass_library_init(); - if (!lib) - return -1; - ass_set_message_cb(lib, message_callback, NULL); - - // 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(log, 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); - bool ok = !!track; - if (cbuf.start != buf.start) - talloc_free(cbuf.start); - talloc_free(buf.start); - if (track) - ass_free_track(track); - ass_library_done(lib); - if (!ok) - return -1; - } - - // Actually load the full thing. - - bstr buf = stream_read_complete(s, NULL, 100000000); - if (!buf.start) { - MP_ERR(demuxer, "Refusing to load subtitle file " - "larger than 100 MB: %s\n", demuxer->filename); - return -1; - } - bstr cbuf = mp_charset_guess_and_conv_to_utf8(log, buf, user_cp, - MP_ICONV_VERBOSE); - if (cbuf.start == NULL) - cbuf = buf; - if (cbuf.start != buf.start) - talloc_free(buf.start); - talloc_steal(demuxer, cbuf.start); - - struct sh_stream *sh = new_sh_stream(demuxer, STREAM_SUB); - sh->codec = "ass"; - sh->extradata = cbuf.start; - sh->extradata_size = cbuf.len; - - demuxer->seekable = true; - demuxer->fully_read = true; - - return 0; -} - -const struct demuxer_desc demuxer_desc_libass = { - .name = "libass", - .desc = "ASS/SSA subtitles (libass)", - .open = d_check_file, -}; diff --git a/misc/charset_conv.c b/misc/charset_conv.c index bceb52aa58..3e7e47cc58 100644 --- a/misc/charset_conv.c +++ b/misc/charset_conv.c @@ -259,24 +259,6 @@ const char *mp_charset_guess(void *talloc_ctx, struct mp_log *log, bstr buf, return res; } -// Convert the data in buf to UTF-8. The charset argument can be an iconv -// codepage, a value returned by mp_charset_conv_guess(), or a special value -// that triggers autodetection of the charset (e.g. using ENCA). -// The auto-detection is the only difference to mp_iconv_to_utf8(). -// buf: same as mp_iconv_to_utf8() -// user_cp: iconv codepage, special value, NULL -// flags: same as mp_iconv_to_utf8() -// returns: same as mp_iconv_to_utf8() -bstr mp_charset_guess_and_conv_to_utf8(struct mp_log *log, bstr buf, - const char *user_cp, int flags) -{ - void *tmp = talloc_new(NULL); - const char *cp = mp_charset_guess(tmp, log, buf, user_cp, flags); - bstr res = mp_iconv_to_utf8(log, buf, cp, flags); - talloc_free(tmp); - return res; -} - // Use iconv to convert buf to UTF-8. // Returns buf.start==NULL on error. Returns buf if cp is NULL, or if there is // obviously no conversion required (e.g. if cp is "UTF-8"). diff --git a/misc/charset_conv.h b/misc/charset_conv.h index bd76ae007a..3d3520fb2b 100644 --- a/misc/charset_conv.h +++ b/misc/charset_conv.h @@ -16,8 +16,6 @@ bool mp_charset_is_utf8(const char *user_cp); bool mp_charset_requires_guess(const char *user_cp); const char *mp_charset_guess(void *talloc_ctx, struct mp_log *log, bstr buf, const char *user_cp, int flags); -bstr mp_charset_guess_and_conv_to_utf8(struct mp_log *log, bstr buf, - const char *user_cp, int flags); bstr mp_iconv_to_utf8(struct mp_log *log, bstr buf, const char *cp, int flags); #endif diff --git a/wscript_build.py b/wscript_build.py index 4e654eee99..76b3929c95 100644 --- a/wscript_build.py +++ b/wscript_build.py @@ -162,7 +162,6 @@ def build(ctx): ( "demux/demux_edl.c" ), ( "demux/demux_lavf.c" ), ( "demux/demux_libarchive.c", "libarchive" ), - ( "demux/demux_libass.c", "libass"), ( "demux/demux_mf.c" ), ( "demux/demux_mkv.c" ), ( "demux/demux_mkv_timeline.c" ), |