summaryrefslogtreecommitdiffstats
path: root/libass
diff options
context:
space:
mode:
authorreimar <reimar@b3059339-0415-0410-9bf9-f77b7e298cf2>2010-02-05 17:13:47 +0000
committerreimar <reimar@b3059339-0415-0410-9bf9-f77b7e298cf2>2010-02-05 17:13:47 +0000
commitfc50523f80ae3dafbea61b3af75c4f109e6fb6d8 (patch)
tree0e857027154b24414ed87e0a556ee187e2f21bab /libass
parentc5b0ff1cfacfa502eb0647f329756ddf7c79fcb6 (diff)
downloadmpv-fc50523f80ae3dafbea61b3af75c4f109e6fb6d8.tar.bz2
mpv-fc50523f80ae3dafbea61b3af75c4f109e6fb6d8.tar.xz
Add support for loading ASS subtitles through the stream layer and thus e.g.
from some network location. Patch by Yuriy Kaminskiy [yumkam mail ru] git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@30515 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'libass')
-rw-r--r--libass/ass_mp.c47
-rw-r--r--libass/ass_mp.h1
2 files changed, 48 insertions, 0 deletions
diff --git a/libass/ass_mp.c b/libass/ass_mp.c
index b5f55cc29a..77d1538aa9 100644
--- a/libass/ass_mp.c
+++ b/libass/ass_mp.c
@@ -28,6 +28,8 @@
#include "get_path.h"
#include "ass_mp.h"
+#include "help_mp.h"
+#include "stream/stream.h"
#ifdef CONFIG_FONTCONFIG
#include <fontconfig/fontconfig.h>
@@ -216,6 +218,51 @@ ass_track_t* ass_read_subdata(ass_library_t* library, sub_data* subdata, double
return track;
}
+ass_track_t* ass_read_stream(ass_library_t* library, char *fname, char *charset) {
+ int i;
+ char *buf = NULL;
+ ass_track_t *track;
+ size_t sz = 0;
+ size_t buf_alloc = 0;
+ stream_t *fd;
+
+ fd = open_stream(fname, NULL, &i);
+ if (!fd) {
+ mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_FopenFailed, fname);
+ return NULL;
+ }
+ if (fd->end_pos > STREAM_BUFFER_SIZE)
+ /* read entire file if size is known */
+ buf_alloc = fd->end_pos;
+ for (;;) {
+ if (buf_alloc >= 100*1024*1024) {
+ mp_msg(MSGT_ASS, MSGL_INFO, MSGTR_LIBASS_RefusingToLoadSubtitlesLargerThan100M, fname);
+ sz = 0;
+ break;
+ }
+ if (buf_alloc < sz + STREAM_BUFFER_SIZE)
+ buf_alloc += STREAM_BUFFER_SIZE;
+ 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_t* priv, int w, int h, int unscaled) {
int hinting;
ass_set_frame_size(priv, w, h);
diff --git a/libass/ass_mp.h b/libass/ass_mp.h
index 1584145d1c..5d81b55e4f 100644
--- a/libass/ass_mp.h
+++ b/libass/ass_mp.h
@@ -59,6 +59,7 @@ extern int ass_hinting;
ass_track_t* ass_default_track(ass_library_t* library);
int ass_process_subtitle(ass_track_t* track, subtitle* sub);
ass_track_t* ass_read_subdata(ass_library_t* library, sub_data* subdata, double fps);
+ass_track_t* ass_read_stream(ass_library_t* library, char *fname, char *charset);
void ass_configure(ass_renderer_t* priv, int w, int h, int hinting);
void ass_configure_fonts(ass_renderer_t* priv);