[FFmpeg-devel] [PATCH] Using size_t* instead of int** for dynarrays and add support for large boxes

Niklesh Lalwani niklesh.lalwani at iitb.ac.in
Mon Apr 27 06:28:58 CEST 2015


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

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

diff --git a/libavcodec/movtextdec.c b/libavcodec/movtextdec.c
index 3059599..b134ac5 100644
--- a/libavcodec/movtextdec.c
+++ b/libavcodec/movtextdec.c
@@ -32,19 +32,19 @@
 #define STYLE_FLAG_UNDERLINE    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)
+                        size_t *style_start, size_t *style_end,
+                        size_t *style_flags, int style_entries)
 {
     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)
+            if (style_flags[i] && style_pos == style_start[i]) {
+                if (style_flags[i] & STYLE_FLAG_BOLD)
                     av_bprintf(buf, "{\\b1}");
-                if (*style_flags[i] & STYLE_FLAG_ITALIC)
+                if (style_flags[i] & STYLE_FLAG_ITALIC)
                     av_bprintf(buf, "{\\i1}");
-                if (*style_flags[i] & STYLE_FLAG_UNDERLINE)
+                if (style_flags[i] & STYLE_FLAG_UNDERLINE)
                     av_bprintf(buf, "{\\u1}");
             }
         }
@@ -61,12 +61,12 @@ static int text_to_ass(AVBPrint *buf, const char *text, const char *text_end,
         }
 
         for (i = 0; i < style_entries; i++) {
-            if (*style_flags[i] && style_pos == *style_end[i]) {
-                if (*style_flags[i] & STYLE_FLAG_BOLD)
+            if (style_flags[i] && style_pos == style_end[i]) {
+                if (style_flags[i] & STYLE_FLAG_BOLD)
                     av_bprintf(buf, "{\\b0}");
-                if (*style_flags[i] & STYLE_FLAG_ITALIC)
+                if (style_flags[i] & STYLE_FLAG_ITALIC)
                     av_bprintf(buf, "{\\i0}");
-                if (*style_flags[i] & STYLE_FLAG_UNDERLINE)
+                if (style_flags[i] & STYLE_FLAG_UNDERLINE)
                     av_bprintf(buf, "{\\u0}");
             }
         }
@@ -95,15 +95,15 @@ 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,};
+    int text_length, style_entries;
+    uint32_t tsmb_type;
+    uint64_t tsmb_size;
+    size_t *style_start = { 0, };
+    size_t *style_end = { 0, };
+    size_t *style_flags = { 0, };
     const uint8_t *tsmb;
     int index, i;
-    int *flag;
-    int *style_pos;
+    int flag, style_pos;
 
     if (!ptr || avpkt->size < 2)
         return AVERROR_INVALIDDATA;
@@ -145,27 +145,29 @@ static int mov_text_decode_frame(AVCodecContext *avctx,
             tsmb_type = AV_RB32(tsmb);
             tsmb += 4;
 
+            if (tsmb_size == 0xFFFFFFFF) {
+                tsmb_size = AV_RB64(tsmb);
+                tsmb += 8;
+            }
+
             if (tsmb_type == MKBETAG('s','t','y','l')) {
                 style_entries = AV_RB16(tsmb);
                 tsmb += 2;
 
                 for(i = 0; i < style_entries; i++) {
-                    style_pos = av_malloc(4);
-                    *style_pos = AV_RB16(tsmb);
+                    style_pos = AV_RB16(tsmb);
                     index = i;
-                    av_dynarray_add(&style_start, &index, style_pos);
+                    av_dynarray_add(&style_start, &index, (void*)(size_t)style_pos);
                     tsmb += 2;
-                    style_pos = av_malloc(4);
-                    *style_pos = AV_RB16(tsmb);
+                    style_pos = AV_RB16(tsmb);
                     index = i;
-                    av_dynarray_add(&style_end, &index, style_pos);
+                    av_dynarray_add(&style_end, &index, (void*)(size_t)style_pos);
                     tsmb += 2;
                     // fontID = AV_RB16(tsmb);
                     tsmb += 2;
-                    flag = av_malloc(4);
-                    *flag = AV_RB8(tsmb);
+                    flag = AV_RB8(tsmb);
                     index = i;
-                    av_dynarray_add(&style_flags, &index, flag);
+                    av_dynarray_add(&style_flags, &index, (void*)(size_t)flag);
                     //fontsize=AV_RB8(tsmb);
                     tsmb += 2;
                     // text-color-rgba
-- 
1.9.1



More information about the ffmpeg-devel mailing list