Mercurial > mplayer.hg
changeset 30473:7446f58b6899
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]
author | reimar |
---|---|
date | Fri, 05 Feb 2010 17:13:47 +0000 |
parents | ddce1a6f3c59 |
children | 31a00b2a621f |
files | help/help_mp-cs.h help/help_mp-de.h help/help_mp-en.h help/help_mp-es.h help/help_mp-fr.h help/help_mp-hu.h help/help_mp-it.h help/help_mp-ru.h help/help_mp-tr.h help/help_mp-zh_CN.h help/help_mp-zh_TW.h libass/ass_mp.c libass/ass_mp.h mplayer.c |
diffstat | 14 files changed, 61 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/help/help_mp-cs.h Fri Feb 05 16:42:13 2010 +0000 +++ b/help/help_mp-cs.h Fri Feb 05 17:13:47 2010 +0000 @@ -1713,7 +1713,7 @@ #define MSGTR_LIBASS_ErrorRecodingFile "[ass] chyba překódování souboru.\n" #define MSGTR_LIBASS_FopenFailed "[ass] ass_read_file(%s): fopen selhalo\n" #define MSGTR_LIBASS_FseekFailed "[ass] ass_read_file(%s): fseek selhalo\n" -#define MSGTR_LIBASS_RefusingToLoadSubtitlesLargerThan10M "[ass] ass_read_file(%s): Odmítám nahrát titulky delší než 10M\n" +#define MSGTR_LIBASS_RefusingToLoadSubtitlesLargerThan100M "[ass] ass_read_file(%s): Odmítám nahrát titulky delší než 100M\n" #define MSGTR_LIBASS_ReadFailed "Čtení selhalo, %d: %s\n" #define MSGTR_LIBASS_AddedSubtitleFileMemory "[ass] Přidán soubos s titulky: <memory> (%d stylů, %d událostí)\n" #define MSGTR_LIBASS_AddedSubtitleFileFname "[ass] Přidán soubos s titulky: %s (%d stylů, %d událostí)\n"
--- a/help/help_mp-de.h Fri Feb 05 16:42:13 2010 +0000 +++ b/help/help_mp-de.h Fri Feb 05 17:13:47 2010 +0000 @@ -2042,7 +2042,7 @@ #define MSGTR_LIBASS_ErrorRecodingFile "[ass] Fehler bei Recodierung der Datei.\n" #define MSGTR_LIBASS_FopenFailed "[ass] ass_read_file(%s): fopen fehlgeschlagen\n" #define MSGTR_LIBASS_FseekFailed "[ass] ass_read_file(%s): fseek fehlgeschlagen\n" -#define MSGTR_LIBASS_RefusingToLoadSubtitlesLargerThan10M "[ass] ass_read_file(%s): Laden von Untertiteln größer als 10M verweigert.\n" +#define MSGTR_LIBASS_RefusingToLoadSubtitlesLargerThan100M "[ass] ass_read_file(%s): Laden von Untertiteln größer als 100M verweigert.\n" #define MSGTR_LIBASS_ReadFailed "Lesen fehlgeschlagen, %d: %s\n" #define MSGTR_LIBASS_AddedSubtitleFileMemory "[ass] Hinzugefügte Untertiteldatei: <Speicher> (%d Styles, %d Ereignisse)\n" #define MSGTR_LIBASS_AddedSubtitleFileFname "[ass] Hinzugefügte Untertiteldatei: %s (%d Styles, %d Ereignisse)\n"
--- a/help/help_mp-en.h Fri Feb 05 16:42:13 2010 +0000 +++ b/help/help_mp-en.h Fri Feb 05 17:13:47 2010 +0000 @@ -1719,7 +1719,7 @@ #define MSGTR_LIBASS_ErrorRecodingFile "[ass] error recoding file.\n" #define MSGTR_LIBASS_FopenFailed "[ass] ass_read_file(%s): fopen failed\n" #define MSGTR_LIBASS_FseekFailed "[ass] ass_read_file(%s): fseek failed\n" -#define MSGTR_LIBASS_RefusingToLoadSubtitlesLargerThan10M "[ass] ass_read_file(%s): Refusing to load subtitles larger than 10M\n" +#define MSGTR_LIBASS_RefusingToLoadSubtitlesLargerThan100M "[ass] ass_read_file(%s): Refusing to load subtitles larger than 100M\n" #define MSGTR_LIBASS_ReadFailed "Read failed, %d: %s\n" #define MSGTR_LIBASS_AddedSubtitleFileMemory "[ass] Added subtitle file: <memory> (%d styles, %d events)\n" #define MSGTR_LIBASS_AddedSubtitleFileFname "[ass] Added subtitle file: %s (%d styles, %d events)\n"
--- a/help/help_mp-es.h Fri Feb 05 16:42:13 2010 +0000 +++ b/help/help_mp-es.h Fri Feb 05 17:13:47 2010 +0000 @@ -2080,7 +2080,7 @@ #define MSGTR_LIBASS_ErrorRecodingFile "[ass] error recodificando el fichero.\n" #define MSGTR_LIBASS_FopenFailed "[ass] ass_read_file(%s): fopen ha fallado\n" #define MSGTR_LIBASS_FseekFailed "[ass] ass_read_file(%s): fseek ha fallado\n" -#define MSGTR_LIBASS_RefusingToLoadSubtitlesLargerThan10M "[ass] ass_read_file(%s): No se pueden cargar ficheros de subtítulos mayores de 10M\n" +#define MSGTR_LIBASS_RefusingToLoadSubtitlesLargerThan100M "[ass] ass_read_file(%s): No se pueden cargar ficheros de subtítulos mayores de 100M\n" #define MSGTR_LIBASS_ReadFailed "La lectura ha fallado, %d: %s\n" #define MSGTR_LIBASS_AddedSubtitleFileMemory "[ass] Añadido fichero de subtítulos: <memoria> (%d estilos, %d eventos)\n" #define MSGTR_LIBASS_AddedSubtitleFileFname "[ass] Añadido fichero de subtítulos: %s (%d estilos, %d eventos)\n"
--- a/help/help_mp-fr.h Fri Feb 05 16:42:13 2010 +0000 +++ b/help/help_mp-fr.h Fri Feb 05 17:13:47 2010 +0000 @@ -2008,7 +2008,7 @@ #define MSGTR_LIBASS_ErrorRecodingFile "[ass] erreur lors de l'enregistrement du fichier.\n" #define MSGTR_LIBASS_FopenFailed "[ass] ass_read_file(%s) : fopen a échoué\n" #define MSGTR_LIBASS_FseekFailed "[ass] ass_read_file(%s) : fseek à échoué\n" -#define MSGTR_LIBASS_RefusingToLoadSubtitlesLargerThan10M "[ass] ass_read_file(%s) : Chargement des fichiers plus grands que 10Mo refusé\n" +#define MSGTR_LIBASS_RefusingToLoadSubtitlesLargerThan100M "[ass] ass_read_file(%s) : Chargement des fichiers plus grands que 100Mo refusé\n" #define MSGTR_LIBASS_ReadFailed "Lecture impossible, %d: %s\n" #define MSGTR_LIBASS_AddedSubtitleFileMemory "[ass] Ajout d'un fichier de sous-titres : <memory> (%d styles, %d évènements)\n" #define MSGTR_LIBASS_AddedSubtitleFileFname "[ass] Ajout d'un fichier de sous-titres : %s (%d styles, %d events)\n"
--- a/help/help_mp-hu.h Fri Feb 05 16:42:13 2010 +0000 +++ b/help/help_mp-hu.h Fri Feb 05 17:13:47 2010 +0000 @@ -1718,7 +1718,7 @@ #define MSGTR_LIBASS_ErrorRecodingFile "[ass] hiba a fájl rögzítésekor.\n" #define MSGTR_LIBASS_FopenFailed "[ass] ass_read_file(%s): fopen sikertelen\n" #define MSGTR_LIBASS_FseekFailed "[ass] ass_read_file(%s): fseek sikertelen\n" -#define MSGTR_LIBASS_RefusingToLoadSubtitlesLargerThan10M "[ass] ass_read_file(%s): 10M-nél nagyobb felirat fájl betöltése visszautasítva\n" +#define MSGTR_LIBASS_RefusingToLoadSubtitlesLargerThan100M "[ass] ass_read_file(%s): 100M-nél nagyobb felirat fájl betöltése visszautasítva\n" #define MSGTR_LIBASS_ReadFailed "Olvasás sikertelen, %d: %s\n" #define MSGTR_LIBASS_AddedSubtitleFileMemory "[ass] Felirat fájl hozzáadása: <memória> (%d stílus, %d esemény)\n" #define MSGTR_LIBASS_AddedSubtitleFileFname "[ass] Felirat fájl hozzáadása: %s (%d stílus, %d esemény)\n"
--- a/help/help_mp-it.h Fri Feb 05 16:42:13 2010 +0000 +++ b/help/help_mp-it.h Fri Feb 05 17:13:47 2010 +0000 @@ -1713,7 +1713,7 @@ #define MSGTR_LIBASS_ErrorRecodingFile "[ass] errore ricodificando il file.\n" #define MSGTR_LIBASS_FopenFailed "[ass] ass_read_file(%s): fopen fallita\n" #define MSGTR_LIBASS_FseekFailed "[ass] ass_read_file(%s): fseek fallita\n" -#define MSGTR_LIBASS_RefusingToLoadSubtitlesLargerThan10M "[ass] ass_read_file(%s): Mi rifiuto di caricare sottotitoli più grandi di 10M\n" +#define MSGTR_LIBASS_RefusingToLoadSubtitlesLargerThan100M "[ass] ass_read_file(%s): Mi rifiuto di caricare sottotitoli più grandi di 100M\n" #define MSGTR_LIBASS_ReadFailed "Lettura fallita, %d: %s\n" #define MSGTR_LIBASS_AddedSubtitleFileMemory "[ass] Aggiunto file sottotitoli: <memoria> (%d stili, %d eventi)\n" #define MSGTR_LIBASS_AddedSubtitleFileFname "[ass] Added subtitle file: %s (%d stili, %d eventi)\n"
--- a/help/help_mp-ru.h Fri Feb 05 16:42:13 2010 +0000 +++ b/help/help_mp-ru.h Fri Feb 05 17:13:47 2010 +0000 @@ -1753,7 +1753,7 @@ #define MSGTR_LIBASS_ErrorRecodingFile "[ass] ошибка записи файла.\n" #define MSGTR_LIBASS_FopenFailed "[ass] ass_read_file(%s): сбой fopen\n" #define MSGTR_LIBASS_FseekFailed "[ass] ass_read_file(%s): сбой fseek\n" -#define MSGTR_LIBASS_RefusingToLoadSubtitlesLargerThan10M "[ass] ass_read_file(%s): Отклонение загрузки субтитров больше 10M\n" +#define MSGTR_LIBASS_RefusingToLoadSubtitlesLargerThan100M "[ass] ass_read_file(%s): Отклонение загрузки субтитров больше 100M\n" #define MSGTR_LIBASS_ReadFailed "Ошибка чтения, %d: %s\n" #define MSGTR_LIBASS_AddedSubtitleFileMemory "[ass] Добавлен файл субтитров: <память> (стилей: %d, событий: %d)\n" #define MSGTR_LIBASS_AddedSubtitleFileFname "[ass] Добавлен файл субтитров: %s (стилей: %d, событий: %d)\n"
--- a/help/help_mp-tr.h Fri Feb 05 16:42:13 2010 +0000 +++ b/help/help_mp-tr.h Fri Feb 05 17:13:47 2010 +0000 @@ -2017,7 +2017,7 @@ #define MSGTR_LIBASS_ErrorRecodingFile "[ass] Dosyayı tekrar kodlamada hata.\n" #define MSGTR_LIBASS_FopenFailed "[ass] ass_read_file(%s): fopen başarısız\n" #define MSGTR_LIBASS_FseekFailed "[ass] ass_read_file(%s): fseek başarısız\n" -#define MSGTR_LIBASS_RefusingToLoadSubtitlesLargerThan10M "[ass] ass_read_file(%s): 10 megabayttan büyük altyazıları yüklemeyi reddediyor\n" +#define MSGTR_LIBASS_RefusingToLoadSubtitlesLargerThan100M "[ass] ass_read_file(%s): 100 megabayttan büyük altyazıları yüklemeyi reddediyor\n" #define MSGTR_LIBASS_ReadFailed "Okuma başarısız, %d: %s\n" #define MSGTR_LIBASS_AddedSubtitleFileMemory "[ass] Altyazı dosyasını ekledi: <bellek> (%d tarz, %d olay)\n" #define MSGTR_LIBASS_AddedSubtitleFileFname "[ass] Altyazı dosyasını ekledi: %s (%d tarz, %d olay)\n"
--- a/help/help_mp-zh_CN.h Fri Feb 05 16:42:13 2010 +0000 +++ b/help/help_mp-zh_CN.h Fri Feb 05 17:13:47 2010 +0000 @@ -1701,7 +1701,7 @@ #define MSGTR_LIBASS_ErrorRecodingFile "[ass] 记录到文件出错。\n" #define MSGTR_LIBASS_FopenFailed "[ass] ass_read_file(%s): 文件打开(fopen)失败\n" #define MSGTR_LIBASS_FseekFailed "[ass] ass_read_file(%s): 文件定位(fseek)失败\n" -#define MSGTR_LIBASS_RefusingToLoadSubtitlesLargerThan10M "[ass] ass_read_file(%s): 拒绝装入大于10M的字幕\n" +#define MSGTR_LIBASS_RefusingToLoadSubtitlesLargerThan100M "[ass] ass_read_file(%s): 拒绝装入大于100M的字幕\n" #define MSGTR_LIBASS_ReadFailed "读失败, %d: %s\n" #define MSGTR_LIBASS_AddedSubtitleFileMemory "[ass] 已加入字幕文件: <内存> (%d styles, %d events)\n" #define MSGTR_LIBASS_AddedSubtitleFileFname "[ass] 已加入字幕文件: %s (%d styles, %d events)\n"
--- a/help/help_mp-zh_TW.h Fri Feb 05 16:42:13 2010 +0000 +++ b/help/help_mp-zh_TW.h Fri Feb 05 17:13:47 2010 +0000 @@ -1968,7 +1968,7 @@ #define MSGTR_LIBASS_ErrorRecodingFile "[ass] 記録到文件出錯。\n" #define MSGTR_LIBASS_FopenFailed "[ass] ass_read_file(%s): 文件打開(fopen)失敗\n" #define MSGTR_LIBASS_FseekFailed "[ass] ass_read_file(%s): 文件定位(fseek)失敗\n" -#define MSGTR_LIBASS_RefusingToLoadSubtitlesLargerThan10M "[ass] ass_read_file(%s): 拒絶裝入大于10M的字幕\n" +#define MSGTR_LIBASS_RefusingToLoadSubtitlesLargerThan100M "[ass] ass_read_file(%s): 拒絶裝入大于100M的字幕\n" #define MSGTR_LIBASS_ReadFailed "讀失敗, %d: %s\n" #define MSGTR_LIBASS_AddedSubtitleFileMemory "[ass] 已加入字幕文件: <内存> (%d styles, %d events)\n" #define MSGTR_LIBASS_AddedSubtitleFileFname "[ass] 已加入字幕文件: %s (%d styles, %d events)\n"
--- a/libass/ass_mp.c Fri Feb 05 16:42:13 2010 +0000 +++ b/libass/ass_mp.c Fri Feb 05 17:13:47 2010 +0000 @@ -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 @@ 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);
--- a/libass/ass_mp.h Fri Feb 05 16:42:13 2010 +0000 +++ b/libass/ass_mp.h Fri Feb 05 17:13:47 2010 +0000 @@ -59,6 +59,7 @@ 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);
--- a/mplayer.c Fri Feb 05 16:42:13 2010 +0000 +++ b/mplayer.c Fri Feb 05 17:13:47 2010 +0000 @@ -1082,9 +1082,9 @@ #ifdef CONFIG_ASS if (ass_enabled) #ifdef CONFIG_ICONV - asst = ass_read_file(ass_library, filename, sub_cp); + asst = ass_read_stream(ass_library, filename, sub_cp); #else - asst = ass_read_file(ass_library, filename, 0); + asst = ass_read_stream(ass_library, filename, 0); #endif if (ass_enabled && subd && !asst) asst = ass_read_subdata(ass_library, subd, fps);