]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/samidec.c
Merge commit '7bb1c1bfd22de2200743af04ebd0c7c775f56f7e'
[ffmpeg] / libavcodec / samidec.c
index 47850e2126608d5ef53b80fcfe7f033eb5c39793..95f35abd42ffb63551bd4864339d68398f956bc5 100644 (file)
 #include "ass.h"
 #include "libavutil/avstring.h"
 #include "libavutil/bprint.h"
+#include "htmlsubtitles.h"
 
 typedef struct {
     AVBPrint source;
     AVBPrint content;
+    AVBPrint encoded_source;
+    AVBPrint encoded_content;
     AVBPrint full;
 } SAMIContext;
 
@@ -41,8 +44,12 @@ static int sami_paragraph_to_ass(AVCodecContext *avctx, const char *src)
     char *tag = NULL;
     char *dupsrc = av_strdup(src);
     char *p = dupsrc;
+    AVBPrint *dst_content = &sami->encoded_content;
+    AVBPrint *dst_source = &sami->encoded_source;
 
+    av_bprint_clear(&sami->encoded_content);
     av_bprint_clear(&sami->content);
+    av_bprint_clear(&sami->encoded_source);
     for (;;) {
         char *saveptr = NULL;
         int prev_chr_is_space = 0;
@@ -82,8 +89,9 @@ static int sami_paragraph_to_ass(AVCodecContext *avctx, const char *src)
             if (*p == '<') {
                 if (!av_strncasecmp(p, "<P", 2) && (p[2] == '>' || av_isspace(p[2])))
                     break;
-                if (!av_strncasecmp(p, "<BR", 3))
-                    av_bprintf(dst, "\\N");
+            }
+            if (!av_strncasecmp(p, "<BR", 3)) {
+                av_bprintf(dst, "\\N");
                 p++;
                 while (*p && *p != '>')
                     p++;
@@ -103,9 +111,12 @@ static int sami_paragraph_to_ass(AVCodecContext *avctx, const char *src)
     }
 
     av_bprint_clear(&sami->full);
-    if (sami->source.len)
-        av_bprintf(&sami->full, "{\\i1}%s{\\i0}\\N", sami->source.str);
-    av_bprintf(&sami->full, "%s", sami->content.str);
+    if (sami->source.len) {
+        ff_htmlmarkup_to_ass(avctx, dst_source, sami->source.str);
+        av_bprintf(&sami->full, "{\\i1}%s{\\i0}\\N", sami->encoded_source.str);
+    }
+    ff_htmlmarkup_to_ass(avctx, dst_content, sami->content.str);
+    av_bprintf(&sami->full, "%s", sami->encoded_content.str);
 
 end:
     av_free(dupsrc);
@@ -136,6 +147,8 @@ static av_cold int sami_init(AVCodecContext *avctx)
     SAMIContext *sami = avctx->priv_data;
     av_bprint_init(&sami->source,  0, 2048);
     av_bprint_init(&sami->content, 0, 2048);
+    av_bprint_init(&sami->encoded_source,  0, 2048);
+    av_bprint_init(&sami->encoded_content, 0, 2048);
     av_bprint_init(&sami->full,    0, 2048);
     return ff_ass_subtitle_header_default(avctx);
 }
@@ -145,6 +158,8 @@ static av_cold int sami_close(AVCodecContext *avctx)
     SAMIContext *sami = avctx->priv_data;
     av_bprint_finalize(&sami->source,  NULL);
     av_bprint_finalize(&sami->content, NULL);
+    av_bprint_finalize(&sami->encoded_source,  NULL);
+    av_bprint_finalize(&sami->encoded_content, NULL);
     av_bprint_finalize(&sami->full,    NULL);
     return 0;
 }