summaryrefslogtreecommitdiff
path: root/libavcodec/ass.c
diff options
context:
space:
mode:
authorMarton Balint <cus@passwd.hu>2013-10-23 20:03:17 +0200
committerMarton Balint <cus@passwd.hu>2013-11-10 18:57:52 +0100
commitb96325e023cfe9fed5a17009b2ef23797caab906 (patch)
treefab9083fa9d4f6a35f26e63a56eb5c6b45f007db /libavcodec/ass.c
parent0f0a8d9859c3ac2a05b0a794197b240b00f3501f (diff)
ass: move text_event_to_ass from textdec.c to ass.c and export it
Signed-off-by: Marton Balint <cus@passwd.hu>
Diffstat (limited to 'libavcodec/ass.c')
-rw-r--r--libavcodec/ass.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/libavcodec/ass.c b/libavcodec/ass.c
index ef64b1ecd6..ccc9570650 100644
--- a/libavcodec/ass.c
+++ b/libavcodec/ass.c
@@ -148,3 +148,42 @@ err:
av_bprint_finalize(&buf, NULL);
return ret;
}
+
+void ff_ass_bprint_text_event(AVBPrint *buf, const char *p, int size,
+ const char *linebreaks, int keep_ass_markup)
+{
+ const char *p_end = p + size;
+
+ for (; p < p_end && *p; p++) {
+
+ /* forced custom line breaks, not accounted as "normal" EOL */
+ if (linebreaks && strchr(linebreaks, *p)) {
+ av_bprintf(buf, "\\N");
+
+ /* standard ASS escaping so random characters don't get mis-interpreted
+ * as ASS */
+ } else if (!keep_ass_markup && strchr("{}\\", *p)) {
+ av_bprintf(buf, "\\%c", *p);
+
+ /* some packets might end abruptly (no \0 at the end, like for example
+ * in some cases of demuxing from a classic video container), some
+ * might be terminated with \n or \r\n which we have to remove (for
+ * consistency with those who haven't), and we also have to deal with
+ * evil cases such as \r at the end of the buffer (and no \0 terminated
+ * character) */
+ } else if (p[0] == '\n') {
+ /* some stuff left so we can insert a line break */
+ if (p < p_end - 1)
+ av_bprintf(buf, "\\N");
+ } else if (p[0] == '\r' && p < p_end - 1 && p[1] == '\n') {
+ /* \r followed by a \n, we can skip it. We don't insert the \N yet
+ * because we don't know if it is followed by more text */
+ continue;
+
+ /* finally, a sane character */
+ } else {
+ av_bprint_chars(buf, *p, 1);
+ }
+ }
+ av_bprintf(buf, "\r\n");
+}