summaryrefslogtreecommitdiffstats
path: root/ass_mp.c
diff options
context:
space:
mode:
authorUoti Urpala <uau@glyph.nonexistent.invalid>2010-03-09 22:35:53 +0200
committerUoti Urpala <uau@glyph.nonexistent.invalid>2010-03-09 22:35:53 +0200
commit9786d386679e814f814fc0eb2426086c1f3fd16e (patch)
treeb9d2be371df5e65859127b70fb3b95f26f7003af /ass_mp.c
parent173beb5608d893c0d9b42c1043f1dfa2db2e4df2 (diff)
downloadmpv-9786d386679e814f814fc0eb2426086c1f3fd16e.tar.bz2
mpv-9786d386679e814f814fc0eb2426086c1f3fd16e.tar.xz
subs: support loading external ASS subtitles via stream layer
Previously the argument of the "-sub" option was always interpreted as a local filename when trying to read it as a libass file. Use the stream layer to read it instead, so that protocols like 'http://' are also supported like they are for the main video/audio file. Based on patch by Yuriy Kaminskiy <yumkam@mail.ru>
Diffstat (limited to 'ass_mp.c')
-rw-r--r--ass_mp.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/ass_mp.c b/ass_mp.c
index 959f985446..67e1dcf21e 100644
--- a/ass_mp.c
+++ b/ass_mp.c
@@ -26,10 +26,13 @@
#include <ass/ass.h>
#include <ass/ass_types.h>
+#include <libavutil/common.h>
+
#include "mp_msg.h"
#include "get_path.h"
#include "ass_mp.h"
#include "subreader.h"
+#include "stream/stream.h"
#ifdef CONFIG_FONTCONFIG
#include <fontconfig/fontconfig.h>
@@ -227,6 +230,55 @@ ASS_Track *ass_read_subdata(ASS_Library *library, sub_data *subdata,
return track;
}
+ASS_Track *ass_read_stream(ASS_Library *library, char *fname, char *charset)
+{
+ int i;
+ char *buf = NULL;
+ ASS_Track *track;
+ size_t sz = 0;
+ size_t buf_alloc = 0;
+ stream_t *fd;
+
+ fd = open_stream(fname, NULL, &i);
+ if (!fd)
+ // Stream code should have printed an error already
+ return NULL;
+ if (fd->end_pos > STREAM_BUFFER_SIZE)
+ /* read entire file if size is known */
+ buf_alloc = fd->end_pos;
+ else
+ buf_alloc = 1000;
+ for (;;) {
+ if (sz > 100000000) {
+ mp_tmsg(MSGT_ASS, MSGL_ERR, "Refusing to load subtitle file "
+ "larger than 100 MB: %s\n", fname);
+ sz = 0;
+ break;
+ }
+ buf_alloc = FFMAX(buf_alloc, sz + (sz >> 1));
+ buf_alloc = FFMIN(buf_alloc, 100000001);
+ buf = realloc(buf, buf_alloc + 1);
+ i = stream_read(fd, buf + sz, buf_alloc - sz);
+ if (i <= 0)
+ break;
+ sz += i;
+ }
+ free_stream(fd);
+ if (!sz) {
+ free(buf);
+ return NULL;
+ }
+ buf[sz] = 0;
+ buf = realloc(buf, sz + 1);
+ track = ass_read_memory(library, buf, sz, charset);
+ if (track) {
+ free(track->name);
+ track->name = strdup(fname);
+ }
+ free(buf);
+ return track;
+}
+
void ass_configure(ASS_Renderer *priv, int w, int h, int unscaled)
{
int hinting;