[FFmpeg-devel] [PATCH] Using struct for StyleRecords and implementing support for large boxes(>32 bit) for 3gpp timed text

Niklesh Lalwani niklesh.lalwani at iitb.ac.in
Sun Apr 26 02:01:21 CEST 2015


From: Niklesh <niklesh.lalwani at iitb.ac.in>

This patch uses struct for the Style Records. The pointer to this struct is updated to point to the start of style records in the TextStyleModifierBox. However, in doing this, I get a warning for incompatible pointer type assignment. How to get over this? The patch gives proper outputs though.

Also, I have added support for large boxes(>32 bit) as per the ISO base media file format. Please let me know if I am doing it wrong.

Signed-off-by: Niklesh <niklesh.lalwani at iitb.ac.in>
---
 libavcodec/movtextdec.c | 83 ++++++++++++++++++++-----------------------------
 1 file changed, 33 insertions(+), 50 deletions(-)

diff --git a/libavcodec/movtextdec.c b/libavcodec/movtextdec.c
index ab4efdb..7eb41b8 100644
--- a/libavcodec/movtextdec.c
+++ b/libavcodec/movtextdec.c
@@ -31,20 +31,28 @@
 #define STYLE_FLAG_ITALIC       2
 #define STYLE_FLAG_UNDERLINE    4
 
+struct __attribute__((__packed__)) StyleRecord {
+    uint16_t startChar;
+    uint16_t endChar;
+    uint16_t font_ID;
+    uint8_t face_style_flags;
+    uint8_t font_size;
+    uint8_t text_color_rgba[4];
+};
+
 static int text_to_ass(AVBPrint *buf, const char *text, const char *text_end,
-                        int **style_start, int **style_end,
-                        int **style_flags, int style_entries)
+                        struct StyleRecord *text_style, int entry_count)
 {
     int i = 0;
     int style_pos = 0;
     while (text < text_end) {
-        for (i = 0; i < style_entries; i++) {
-            if (*style_flags[i] && style_pos == *style_start[i]) {
-                if (*style_flags[i] & STYLE_FLAG_BOLD)
+        for (i = 0; i < entry_count; i++) {
+            if ((text_style + i)->face_style_flags && style_pos == AV_RB16(&((text_style + i)->startChar))) {
+                if ((text_style + i)->face_style_flags & STYLE_FLAG_BOLD)
                     av_bprintf(buf, "{\\b1}");
-                if (*style_flags[i] & STYLE_FLAG_ITALIC)
+                if ((text_style + i)->face_style_flags & STYLE_FLAG_ITALIC)
                     av_bprintf(buf, "{\\i1}");
-                if (*style_flags[i] & STYLE_FLAG_UNDERLINE)
+                if ((text_style + i)->face_style_flags & STYLE_FLAG_UNDERLINE)
                     av_bprintf(buf, "{\\u1}");
             }
         }
@@ -60,13 +68,13 @@ static int text_to_ass(AVBPrint *buf, const char *text, const char *text_end,
             break;
         }
 
-        for (i = 0; i < style_entries; i++) {
-            if (*style_flags[i] && style_pos == *style_end[i]) {
-                if (*style_flags[i] & STYLE_FLAG_BOLD)
+        for (i = 0; i < entry_count; i++) {
+            if ((text_style + i)->face_style_flags && style_pos == AV_RB16(&((text_style + i)->endChar))) {
+                if ((text_style + i)->face_style_flags & STYLE_FLAG_BOLD)
                     av_bprintf(buf, "{\\b0}");
-                if (*style_flags[i] & STYLE_FLAG_ITALIC)
+                if ((text_style + i)->face_style_flags & STYLE_FLAG_ITALIC)
                     av_bprintf(buf, "{\\i0}");
-                if (*style_flags[i] & STYLE_FLAG_UNDERLINE)
+                if ((text_style + i)->face_style_flags & STYLE_FLAG_UNDERLINE)
                     av_bprintf(buf, "{\\u0}");
             }
         }
@@ -95,15 +103,10 @@ static int mov_text_decode_frame(AVCodecContext *avctx,
     AVBPrint buf;
     char *ptr = avpkt->data;
     char *end;
-    //char *ptr_temp;
-    int text_length, tsmb_type, style_entries, tsmb_size;
-    int **style_start = {0,};
-    int **style_end = {0,};
-    int **style_flags = {0,};
-    const uint8_t *tsmb;
-    int index, i;
-    int *flag;
-    int *style_pos;
+    int text_length, tsmb_type, entry_count;
+    long tsmb_size;
+    uint8_t *tsmb;
+    struct StyleRecord *text_style;
 
     if (!ptr || avpkt->size < 2)
         return AVERROR_INVALIDDATA;
@@ -145,40 +148,20 @@ static int mov_text_decode_frame(AVCodecContext *avctx,
             tsmb_type = AV_RB32(tsmb);
             tsmb += 4;
 
+            if (tsmb_size == 1) {
+                tsmb_size = AV_RB64(tsmb);
+                tsmb += 8;
+            }
+
             if (tsmb_type == MKBETAG('s','t','y','l')) {
-                style_entries = AV_RB16(tsmb);
+                entry_count = AV_RB16(tsmb);
                 tsmb += 2;
-
-                for(i = 0; i < style_entries; i++) {
-                    style_pos = av_malloc(4);
-                    *style_pos = AV_RB16(tsmb);
-                    index = i;
-                    av_dynarray_add(&style_start, &index, style_pos);
-                    tsmb += 2;
-                    style_pos = av_malloc(4);
-                    *style_pos = AV_RB16(tsmb);
-                    index = i;
-                    av_dynarray_add(&style_end, &index, style_pos);
-                    tsmb += 2;
-                    // fontID = AV_RB16(tsmb);
-                    tsmb += 2;
-                    flag = av_malloc(4);
-                    *flag = AV_RB8(tsmb);
-                    index = i;
-                    av_dynarray_add(&style_flags, &index, flag);
-                    //fontsize = AV_RB8(tsmb);
-                    tsmb += 2;
-                    // text-color-rgba
-                    tsmb += 4;
-                }
-                text_to_ass(&buf, ptr, end, style_start, style_end, style_flags, style_entries);
-                av_freep(&style_start);
-                av_freep(&style_end);
-                av_freep(&style_flags);
+                text_style = tsmb;
+                text_to_ass(&buf, ptr, end, text_style, entry_count);
             }
         }
     } else
-        text_to_ass(&buf, ptr, end, NULL, NULL, 0, 0);
+        text_to_ass(&buf, ptr, end, NULL, 0);
 
     ret = ff_ass_add_rect_bprint(sub, &buf, ts_start, ts_end - ts_start);
     av_bprint_finalize(&buf, NULL);
-- 
1.9.1



More information about the ffmpeg-devel mailing list