summaryrefslogtreecommitdiffstats
path: root/sub/subreader.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-04-28 21:12:11 +0200
committerwm4 <wm4@nowhere>2013-05-30 22:20:02 +0200
commitb44202b69fc4a1dd1659f7940c5f8846d316e0ff (patch)
treecba363991fc52000ec3f02b9ade2d94e56af873e /sub/subreader.c
parentf7ad81c0f5905637c16480b2e44dd41f2839293a (diff)
downloadmpv-b44202b69fc4a1dd1659f7940c5f8846d316e0ff.tar.bz2
mpv-b44202b69fc4a1dd1659f7940c5f8846d316e0ff.tar.xz
sub: redo how -no-ass is handled
The -no-ass switch used to disable any use of libass for text subtitles. This is not really the case anymore, because libass is now always involved when rendering text. The only remaining use of -no-ass is disabling styling or showing subtitles on the terminal. On the other hand, the old subtitle rendering path is a big reason why the subtitle code is still a big mess with an awful number of obscure special cases. In order to simplify it, remove the old subtitle rendering code, and always go through sd_ass.c. Basically, we use ASS_Track as central data structure for storing text subtitles instead of struct sub_data. This also makes libass mandatory for all text subs, even if they are printed to the terminal in -no-video mode. (We could add something like sd_text to avoid this, but it's not worth the trouble.) struct sub_data and subreader.c are still around, even its ASS/SSA reader. But struct sub_data is freed right after converting it to ASS_Track. The internal ASS reader actually can handle some obscure cases libass can't, like files encoded in UTF-16.
Diffstat (limited to 'sub/subreader.c')
-rw-r--r--sub/subreader.c102
1 files changed, 1 insertions, 101 deletions
diff --git a/sub/subreader.c b/sub/subreader.c
index 090cd0a8b4..365f8aa532 100644
--- a/sub/subreader.c
+++ b/sub/subreader.c
@@ -1684,7 +1684,7 @@ if ((suboverlap_enabled == 2) ||
if (return_sub == NULL) return NULL;
subt_data = talloc_zero(NULL, sub_data);
talloc_set_destructor(subt_data, sub_destroy);
- subt_data->codec = srp->name;
+ subt_data->codec = "text"; //srp->name;
subt_data->filename = strdup(filename);
subt_data->sub_uses_time = uses_time;
subt_data->sub_num = sub_num;
@@ -1704,103 +1704,3 @@ static int sub_destroy(void *ptr)
free( subd->filename );
return 0;
}
-
-#define MAX_SUBLINE 512
-/**
- * \brief parse text and append it to subtitle in sub
- * \param sub subtitle struct to add text to
- * \param txt text to parse
- * \param len length of text in txt
- * \param endpts pts at which this subtitle text should be removed again
- *
- * <> and {} are interpreted as comment delimiters, "\n", "\N", '\n', '\r'
- * and '\0' are interpreted as newlines, duplicate, leading and trailing
- * newlines are ignored.
- */
-void sub_add_text(subtitle *sub, const char *txt, int len, double endpts) {
- int comment = 0;
- int double_newline = 1; // ignore newlines at the beginning
- int i, pos;
- char *buf;
- if (sub->lines >= SUB_MAX_TEXT) return;
- pos = 0;
- buf = malloc(MAX_SUBLINE + 1);
- sub->text[sub->lines] = buf;
- sub->endpts[sub->lines] = endpts;
- for (i = 0; i < len && pos < MAX_SUBLINE; i++) {
- char c = txt[i];
- if (c == '<') comment |= 1;
- if (c == '{') comment |= 2;
- if (comment) {
- if (c == '}') comment &= ~2;
- if (c == '>') comment &= ~1;
- continue;
- }
- if (pos == MAX_SUBLINE - 1) {
- i--;
- c = 0;
- }
- if (c == '\\' && i + 1 < len) {
- c = txt[++i];
- if (c == 'n' || c == 'N') c = 0;
- }
- if (c == '\n' || c == '\r') c = 0;
- if (c) {
- double_newline = 0;
- buf[pos++] = c;
- } else if (!double_newline) {
- if (sub->lines >= SUB_MAX_TEXT - 1) {
- mp_msg(MSGT_VO, MSGL_WARN, "Too many subtitle lines\n");
- break;
- }
- double_newline = 1;
- buf[pos] = 0;
- sub->lines++;
- pos = 0;
- buf = malloc(MAX_SUBLINE + 1);
- sub->text[sub->lines] = buf;
- sub->endpts[sub->lines] = endpts;
- }
- }
- buf[pos] = 0;
- if (sub->lines < SUB_MAX_TEXT &&
- strlen(sub->text[sub->lines]))
- sub->lines++;
- if (sub->lines > 1 &&
- strcmp(sub->text[sub->lines-1], sub->text[sub->lines-2]) == 0) {
- // remove duplicate lines. These can happen with some
- // "clever" ASS effects.
- sub->lines--;
- sub->endpts[sub->lines-1] =
- FFMAX(sub->endpts[sub->lines-1],
- sub->endpts[sub->lines]);
- free(sub->text[sub->lines]);
- }
-}
-
-/**
- * \brief remove outdated subtitle lines.
- * \param sub subtitle struct to modify
- * \param pts current pts. All lines with endpts <= this will be removed.
- * Use MP_NOPTS_VALUE to remove all lines
- * \return 1 if sub was modified, 0 otherwise.
- */
-int sub_clear_text(subtitle *sub, double pts) {
- int i = 0;
- int changed = 0;
- while (i < sub->lines) {
- double endpts = sub->endpts[i];
- if (pts == MP_NOPTS_VALUE || (endpts != MP_NOPTS_VALUE && pts >= endpts)) {
- int j;
- free(sub->text[i]);
- for (j = i + 1; j < sub->lines; j++) {
- sub->text[j - 1] = sub->text[j];
- sub->endpts[j - 1] = sub->endpts[j];
- }
- sub->lines--;
- changed = 1;
- } else
- i++;
- }
- return changed;
-}