On 01/13/2015 01:15 PM, Clément Bœsch wrote:
On Tue, Jan 13, 2015 at 08:12:10AM +0100, Clément Bœsch wrote:
On Tue, Jan 13, 2015 at 11:26:06AM +0530, Anshul Maheshwari wrote:
[...]
Also added roll-up functionality.

patch is attached.
Thanks
Anshul

Attaching patch
 From ca66e917f45bd47dd797930423d488fa9c781c4c Mon Sep 17 00:00:00 2001
From: Anshul Maheshwari <anshul.ffm...@gmail.com>
Date: Mon, 12 Jan 2015 06:21:18 -0800
Subject: [PATCH] Addig Rollup functionality

Signed-off-by: Anshul Maheshwari <anshul.ffm...@gmail.com>
---
  libavcodec/ccaption_dec.c | 222 +++++++++++++++++++++++++++++-----------------
  1 file changed, 140 insertions(+), 82 deletions(-)

Please split your changes.

One patch for the cosmetics
One patch for the CHAR_DEBUG/av_dlog
One patch for the addition of av_log
One patch for the reflow of init_decoder()
One patch for the roll-up functionality
One patchset to rule them all.

Thank you.

hint: git add -p is your friend


Thanks still learning it, most of the time git say patch cant be applied.



Attached all patch.

-Anshul
>From 9c0e055165988ce3d5dfe4734d3736ec01da7b1c Mon Sep 17 00:00:00 2001
From: Anshul Maheshwari <er.anshul.maheshw...@gmail.com>
Date: Tue, 20 Jan 2015 15:51:23 +0530
Subject: [PATCH 1/8] Cosmetic changes in cc_caption

Signed-off-by: Anshul Maheshwari <er.anshul.maheshw...@gmail.com>
---
 libavcodec/ccaption_dec.c | 88 ++++++++++++++++++++++++++---------------------
 1 file changed, 49 insertions(+), 39 deletions(-)

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index e05468f..1f2dfe6 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -27,9 +27,9 @@
 #define SCREEN_ROWS 15
 #define SCREEN_COLUMNS 32
 
-#define SET_FLAG(var, val) ( var |= ( 1 << (val) ) )
-#define UNSET_FLAG(var, val) ( var &=  ~( 1 << (val)) )
-#define CHECK_FLAG(var, val) ( (var) & (1 << (val) ) )
+#define SET_FLAG(var, val)   ( (var) |=   ( 1 << (val)) )
+#define UNSET_FLAG(var, val) ( (var) &=  ~( 1 << (val)) )
+#define CHECK_FLAG(var, val) ( (var) &    ( 1 << (val)) )
 
 /*
  * TODO list
@@ -44,8 +44,7 @@ enum cc_mode {
     CCMODE_TEXT,
 };
 
-enum cc_color_code
-{
+enum cc_color_code {
     CCCOL_WHITE,
     CCCOL_GREEN,
     CCCOL_BLUE,
@@ -58,8 +57,7 @@ enum cc_color_code
     CCCOL_TRANSPARENT,
 };
 
-enum cc_font
-{
+enum cc_font {
     CCFONT_REGULAR,
     CCFONT_ITALICS,
     CCFONT_UNDERLINED,
@@ -68,40 +66,41 @@ enum cc_font
 
 static const unsigned char pac2_attribs[][3] = // Color, font, ident
 {
-    { CCCOL_WHITE, CCFONT_REGULAR, 0 },  // 0x40 || 0x60
-    { CCCOL_WHITE, CCFONT_UNDERLINED, 0 },  // 0x41 || 0x61
-    { CCCOL_GREEN, CCFONT_REGULAR, 0 },  // 0x42 || 0x62
-    { CCCOL_GREEN, CCFONT_UNDERLINED, 0 },  // 0x43 || 0x63
-    { CCCOL_BLUE, CCFONT_REGULAR, 0 },  // 0x44 || 0x64
-    { CCCOL_BLUE, CCFONT_UNDERLINED, 0 },  // 0x45 || 0x65
-    { CCCOL_CYAN, CCFONT_REGULAR, 0 },  // 0x46 || 0x66
-    { CCCOL_CYAN, CCFONT_UNDERLINED, 0 },  // 0x47 || 0x67
-    { CCCOL_RED, CCFONT_REGULAR, 0 },  // 0x48 || 0x68
-    { CCCOL_RED, CCFONT_UNDERLINED, 0 },  // 0x49 || 0x69
-    { CCCOL_YELLOW, CCFONT_REGULAR, 0 },  // 0x4a || 0x6a
-    { CCCOL_YELLOW, CCFONT_UNDERLINED, 0 },  // 0x4b || 0x6b
-    { CCCOL_MAGENTA, CCFONT_REGULAR, 0 },  // 0x4c || 0x6c
-    { CCCOL_MAGENTA, CCFONT_UNDERLINED, 0 },  // 0x4d || 0x6d
-    { CCCOL_WHITE, CCFONT_ITALICS, 0 },  // 0x4e || 0x6e
-    { CCCOL_WHITE, CCFONT_UNDERLINED_ITALICS, 0 },  // 0x4f || 0x6f
-    { CCCOL_WHITE, CCFONT_REGULAR, 0 },  // 0x50 || 0x70
-    { CCCOL_WHITE, CCFONT_UNDERLINED, 0 },  // 0x51 || 0x71
-    { CCCOL_WHITE, CCFONT_REGULAR, 4 },  // 0x52 || 0x72
-    { CCCOL_WHITE, CCFONT_UNDERLINED, 4 },  // 0x53 || 0x73
-    { CCCOL_WHITE, CCFONT_REGULAR, 8 },  // 0x54 || 0x74
-    { CCCOL_WHITE, CCFONT_UNDERLINED, 8 },  // 0x55 || 0x75
-    { CCCOL_WHITE, CCFONT_REGULAR, 12 }, // 0x56 || 0x76
-    { CCCOL_WHITE, CCFONT_UNDERLINED, 12 }, // 0x57 || 0x77
-    { CCCOL_WHITE, CCFONT_REGULAR, 16 }, // 0x58 || 0x78
-    { CCCOL_WHITE, CCFONT_UNDERLINED, 16 }, // 0x59 || 0x79
-    { CCCOL_WHITE, CCFONT_REGULAR, 20 }, // 0x5a || 0x7a
-    { CCCOL_WHITE, CCFONT_UNDERLINED, 20 }, // 0x5b || 0x7b
-    { CCCOL_WHITE, CCFONT_REGULAR, 24 }, // 0x5c || 0x7c
-    { CCCOL_WHITE, CCFONT_UNDERLINED, 24 }, // 0x5d || 0x7d
-    { CCCOL_WHITE, CCFONT_REGULAR, 28 }, // 0x5e || 0x7e
-    { CCCOL_WHITE, CCFONT_UNDERLINED, 28 }  // 0x5f || 0x7f
+    { CCCOL_WHITE,   CCFONT_REGULAR,            0 },  // 0x40 || 0x60
+    { CCCOL_WHITE,   CCFONT_UNDERLINED,         0 },  // 0x41 || 0x61
+    { CCCOL_GREEN,   CCFONT_REGULAR,            0 },  // 0x42 || 0x62
+    { CCCOL_GREEN,   CCFONT_UNDERLINED,         0 },  // 0x43 || 0x63
+    { CCCOL_BLUE,    CCFONT_REGULAR,            0 },  // 0x44 || 0x64
+    { CCCOL_BLUE,    CCFONT_UNDERLINED,         0 },  // 0x45 || 0x65
+    { CCCOL_CYAN,    CCFONT_REGULAR,            0 },  // 0x46 || 0x66
+    { CCCOL_CYAN,    CCFONT_UNDERLINED,         0 },  // 0x47 || 0x67
+    { CCCOL_RED,     CCFONT_REGULAR,            0 },  // 0x48 || 0x68
+    { CCCOL_RED,     CCFONT_UNDERLINED,         0 },  // 0x49 || 0x69
+    { CCCOL_YELLOW,  CCFONT_REGULAR,            0 },  // 0x4a || 0x6a
+    { CCCOL_YELLOW,  CCFONT_UNDERLINED,         0 },  // 0x4b || 0x6b
+    { CCCOL_MAGENTA, CCFONT_REGULAR,            0 },  // 0x4c || 0x6c
+    { CCCOL_MAGENTA, CCFONT_UNDERLINED,         0 },  // 0x4d || 0x6d
+    { CCCOL_WHITE,   CCFONT_ITALICS,            0 },  // 0x4e || 0x6e
+    { CCCOL_WHITE,   CCFONT_UNDERLINED_ITALICS, 0 },  // 0x4f || 0x6f
+    { CCCOL_WHITE,   CCFONT_REGULAR,            0 },  // 0x50 || 0x70
+    { CCCOL_WHITE,   CCFONT_UNDERLINED,         0 },  // 0x51 || 0x71
+    { CCCOL_WHITE,   CCFONT_REGULAR,            4 },  // 0x52 || 0x72
+    { CCCOL_WHITE,   CCFONT_UNDERLINED,         4 },  // 0x53 || 0x73
+    { CCCOL_WHITE,   CCFONT_REGULAR,            8 },  // 0x54 || 0x74
+    { CCCOL_WHITE,   CCFONT_UNDERLINED,         8 },  // 0x55 || 0x75
+    { CCCOL_WHITE,   CCFONT_REGULAR,           12 },  // 0x56 || 0x76
+    { CCCOL_WHITE,   CCFONT_UNDERLINED,        12 },  // 0x57 || 0x77
+    { CCCOL_WHITE,   CCFONT_REGULAR,           16 },  // 0x58 || 0x78
+    { CCCOL_WHITE,   CCFONT_UNDERLINED,        16 },  // 0x59 || 0x79
+    { CCCOL_WHITE,   CCFONT_REGULAR,           20 },  // 0x5a || 0x7a
+    { CCCOL_WHITE,   CCFONT_UNDERLINED,        20 },  // 0x5b || 0x7b
+    { CCCOL_WHITE,   CCFONT_REGULAR,           24 },  // 0x5c || 0x7c
+    { CCCOL_WHITE,   CCFONT_UNDERLINED,        24 },  // 0x5d || 0x7d
+    { CCCOL_WHITE,   CCFONT_REGULAR,           28 },  // 0x5e || 0x7e
+    { CCCOL_WHITE,   CCFONT_UNDERLINED,        28 }   // 0x5f || 0x7f
     /* total 32 entries */
 };
+
 /* 0-255 needs 256 spaces */
 static const uint8_t parity_table[256] = { 0, 1, 1, 0, 1, 0, 0, 1,
                                            1, 0, 0, 1, 0, 1, 1, 0,
@@ -135,6 +134,7 @@ static const uint8_t parity_table[256] = { 0, 1, 1, 0, 1, 0, 0, 1,
                                            0, 1, 1, 0, 1, 0, 0, 1,
                                            0, 1, 1, 0, 1, 0, 0, 1,
                                            1, 0, 0, 1, 0, 1, 1, 0 };
+
 struct Screen {
     /* +1 is used to compensate null character of string */
     uint8_t characters[SCREEN_ROWS][SCREEN_COLUMNS+1];
@@ -197,6 +197,7 @@ static av_cold int close_decoder(AVCodecContext *avctx)
     av_buffer_unref(&ctx->pktbuf);
     return 0;
 }
+
 /**
  * @param ctx closed caption context just to print log
  */
@@ -216,6 +217,7 @@ static int write_char (CCaptionSubContext *ctx, char *row,uint8_t col, char ch)
         return AVERROR_INVALIDDATA;
     }
 }
+
 /**
  * This function after validating parity bit, also remove it from data pair.
  * The first byte doesn't pass parity, we replace it with a solid blank
@@ -295,6 +297,7 @@ static void handle_textattr( CCaptionSubContext *ctx, uint8_t hi, uint8_t lo )
     if(ret == 0)
         ctx->cursor_column++;
 }
+
 static void handle_pac( CCaptionSubContext *ctx, uint8_t hi, uint8_t lo )
 {
     static const int8_t row_map[] = {
@@ -357,6 +360,7 @@ static int handle_edm(CCaptionSubContext *ctx,int64_t pts)
     ctx->end_time = pts;
     return ret;
 }
+
 static int handle_eoc(CCaptionSubContext *ctx, int64_t pts)
 {
     int ret;
@@ -365,6 +369,7 @@ static int handle_eoc(CCaptionSubContext *ctx, int64_t pts)
     ctx->cursor_column = 0;
     return ret;
 }
+
 static void handle_delete_end_of_row( CCaptionSubContext *ctx, char hi, char lo)
 {
     struct Screen *screen = get_writing_screen(ctx);
@@ -372,6 +377,7 @@ static void handle_delete_end_of_row( CCaptionSubContext *ctx, char hi, char lo)
     write_char(ctx, row, ctx->cursor_column, 0);
 
 }
+
 static void handle_char(CCaptionSubContext *ctx, char hi, char lo, int64_t pts)
 {
     struct Screen *screen = get_writing_screen(ctx);
@@ -398,6 +404,7 @@ static void handle_char(CCaptionSubContext *ctx, char hi, char lo, int64_t pts)
     av_log(ctx, AV_LOG_DEBUG,"(%c,%c)\n",hi,lo);
 #endif
 }
+
 static int process_cc608(CCaptionSubContext *ctx, int64_t pts, uint8_t hi, uint8_t lo)
 {
     int ret = 0;
@@ -457,6 +464,7 @@ static int process_cc608(CCaptionSubContext *ctx, int64_t pts, uint8_t hi, uint8
     return ret;
 
 }
+
 static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avpkt)
 {
     CCaptionSubContext *ctx = avctx->priv_data;
@@ -506,9 +514,11 @@ static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avp
     *got_sub = sub->num_rects > 0;
     return ret;
 }
+
 static const AVOption options[] = {
     {NULL}
 };
+
 static const AVClass ccaption_dec_class = {
     .class_name = "Closed caption Decoder",
     .item_name  = av_default_item_name,
-- 
2.1.2

>From f7f5962b513720df0bdab66f0f5f2acaedb251ea Mon Sep 17 00:00:00 2001
From: Anshul Maheshwari <er.anshul.maheshw...@gmail.com>
Date: Tue, 20 Jan 2015 15:54:58 +0530
Subject: [PATCH 2/8] CHAR_DEBUG to av_dlog

Signed-off-by: Anshul Maheshwari <er.anshul.maheshw...@gmail.com>
---
 libavcodec/ccaption_dec.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index 1f2dfe6..3498d09 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -23,7 +23,6 @@
 #include "ass.h"
 #include "libavutil/opt.h"
 
-#define CHAR_DEBUG
 #define SCREEN_ROWS 15
 #define SCREEN_COLUMNS 32
 
@@ -400,9 +399,10 @@ static void handle_char(CCaptionSubContext *ctx, char hi, char lo, int64_t pts)
     /* reset prev command since character can repeat */
     ctx->prev_cmd[0] = 0;
     ctx->prev_cmd[1] = 0;
-#ifdef CHAR_DEBUG
-    av_log(ctx, AV_LOG_DEBUG,"(%c,%c)\n",hi,lo);
-#endif
+    if (lo)
+       av_dlog(ctx, "(%c,%c)\n",hi,lo);
+    else
+       av_dlog(ctx, "(%c)\n",hi);
 }
 
 static int process_cc608(CCaptionSubContext *ctx, int64_t pts, uint8_t hi, uint8_t lo)
@@ -499,9 +499,7 @@ static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avp
         {
             int start_time = av_rescale_q(ctx->start_time, avctx->time_base, (AVRational){ 1, 100 });
             int end_time = av_rescale_q(ctx->end_time, avctx->time_base, (AVRational){ 1, 100 });
-#ifdef CHAR_DEBUG
-            av_log(ctx, AV_LOG_DEBUG,"cdp writing data (%s)\n",ctx->buffer.str);
-#endif
+            av_dlog(ctx, "cdp writing data (%s)\n",ctx->buffer.str);
             ret = ff_ass_add_rect(sub, ctx->buffer.str, start_time, end_time - start_time , 0);
             if (ret < 0)
                 return ret;
-- 
2.1.2

>From b92d4a373da3846aae9648746fb43adc6231bea8 Mon Sep 17 00:00:00 2001
From: Anshul Maheshwari <er.anshul.maheshw...@gmail.com>
Date: Tue, 20 Jan 2015 15:59:48 +0530
Subject: [PATCH 3/8] Initilaize array to known size

Signed-off-by: Anshul Maheshwari <er.anshul.maheshw...@gmail.com>
---
 libavcodec/ccaption_dec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index 3498d09..686cba3 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -63,7 +63,7 @@ enum cc_font {
     CCFONT_UNDERLINED_ITALICS,
 };
 
-static const unsigned char pac2_attribs[][3] = // Color, font, ident
+static const unsigned char pac2_attribs[32][3] = // Color, font, ident
 {
     { CCCOL_WHITE,   CCFONT_REGULAR,            0 },  // 0x40 || 0x60
     { CCCOL_WHITE,   CCFONT_UNDERLINED,         0 },  // 0x41 || 0x61
-- 
2.1.2

>From 90915dfc6fecb57787b3aad228781ed04f3e7cb9 Mon Sep 17 00:00:00 2001
From: Anshul Maheshwari <er.anshul.maheshw...@gmail.com>
Date: Tue, 20 Jan 2015 16:02:29 +0530
Subject: [PATCH 4/8] Adding color and fonts for future use in screen

Signed-off-by: Anshul Maheshwari <er.anshul.maheshw...@gmail.com>
---
 libavcodec/ccaption_dec.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index 686cba3..430c5f1 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -137,6 +137,8 @@ static const uint8_t parity_table[256] = { 0, 1, 1, 0, 1, 0, 0, 1,
 struct Screen {
     /* +1 is used to compensate null character of string */
     uint8_t characters[SCREEN_ROWS][SCREEN_COLUMNS+1];
+    uint8_t colors[SCREEN_ROWS][SCREEN_COLUMNS+1];
+    uint8_t fonts[SCREEN_ROWS][SCREEN_COLUMNS+1];
     /*
      * Bitmask of used rows; if a bit is not set, the
      * corresponding row is not used.
-- 
2.1.2

>From a0f68c392f13f5780ecae80cacf9a0d1ea4d0866 Mon Sep 17 00:00:00 2001
From: Anshul Maheshwari <er.anshul.maheshw...@gmail.com>
Date: Tue, 20 Jan 2015 16:10:36 +0530
Subject: [PATCH 5/8] changed name of erase_display_memory to screen_changed

Signed-off-by: Anshul Maheshwari <er.anshul.maheshw...@gmail.com>
---
 libavcodec/ccaption_dec.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index 430c5f1..9e78ee5 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -159,7 +159,7 @@ typedef struct CCaptionSubContext {
     uint8_t cursor_color;
     uint8_t cursor_font;
     AVBPrint buffer;
-    int erase_display_memory;
+    int screen_changed;
     int rollup;
     enum  cc_mode mode;
     int64_t start_time;
@@ -357,7 +357,7 @@ static int handle_edm(CCaptionSubContext *ctx,int64_t pts)
 
     }
     ctx->startv_time = pts;
-    ctx->erase_display_memory = 1;
+    ctx->screen_changed = 1;
     ctx->end_time = pts;
     return ret;
 }
@@ -497,7 +497,7 @@ static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avp
             continue;
         else
             process_cc608(ctx, avpkt->pts, *(bptr + i + 1) & 0x7f, *(bptr + i + 2) & 0x7f);
-        if(ctx->erase_display_memory && *ctx->buffer.str)
+        if(ctx->screen_changed && *ctx->buffer.str)
         {
             int start_time = av_rescale_q(ctx->start_time, avctx->time_base, (AVRational){ 1, 100 });
             int end_time = av_rescale_q(ctx->end_time, avctx->time_base, (AVRational){ 1, 100 });
@@ -506,7 +506,7 @@ static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avp
             if (ret < 0)
                 return ret;
             sub->pts = av_rescale_q(ctx->start_time, avctx->time_base, AV_TIME_BASE_Q);
-            ctx->erase_display_memory = 0;
+            ctx->screen_changed = 0;
             av_bprint_clear(&ctx->buffer);
         }
     }
-- 
2.1.2

>From d2450967092e41a740c16ecd83271823dc086b5e Mon Sep 17 00:00:00 2001
From: Anshul Maheshwari <er.anshul.maheshw...@gmail.com>
Date: Tue, 20 Jan 2015 16:15:32 +0530
Subject: [PATCH 6/8] roll up functionality of Closed caption

Signed-off-by: Anshul Maheshwari <er.anshul.maheshw...@gmail.com>
---
 libavcodec/ccaption_dec.c | 98 +++++++++++++++++++++++++++++++++--------------
 1 file changed, 69 insertions(+), 29 deletions(-)

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index 9e78ee5..efa5592 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -151,7 +151,6 @@ struct Screen {
 
 typedef struct CCaptionSubContext {
     AVClass *class;
-    int row_cnt;
     struct Screen screen[2];
     int active_screen;
     uint8_t cursor_row;
@@ -179,6 +178,7 @@ static av_cold int init_decoder(AVCodecContext *avctx)
 
     av_bprint_init(&ctx->buffer, 0, AV_BPRINT_SIZE_UNLIMITED);
     /* taking by default roll up to 2 */
+    ctx->mode = CCMODE_ROLLUP_2;
     ctx->rollup = 2;
     ret = ff_ass_subtitle_header_default(avctx);
     /* allocate pkt buffer */
@@ -280,6 +280,66 @@ static struct Screen *get_writing_screen(CCaptionSubContext *ctx)
     return NULL;
 }
 
+static void roll_up(CCaptionSubContext *ctx)
+{
+    struct Screen *screen;
+    int i, keep_lines;
+
+    if(ctx->mode == CCMODE_TEXT)
+        return;
+
+    screen = get_writing_screen(ctx);
+
+    /* +1 signify cursor_row starts from 0
+     * Can't keep lines less then row cursor pos
+     */
+    keep_lines = FFMIN(ctx->cursor_row + 1, ctx->rollup);
+
+    for( i = 0; i < ctx->cursor_row - keep_lines; i++ )
+        UNSET_FLAG(screen->row_used, i);
+
+    for( i = 0; i < keep_lines - 1; i++ ) {
+        const int i_row = ctx->cursor_row - keep_lines + i + 1;
+
+        memcpy( screen->characters[i_row], screen->characters[i_row+1], SCREEN_COLUMNS );
+        memcpy( screen->colors[i_row], screen->colors[i_row+1], SCREEN_COLUMNS);
+        memcpy( screen->fonts[i_row], screen->fonts[i_row+1], SCREEN_COLUMNS);
+        if(CHECK_FLAG(screen->row_used, i_row + 1))
+            SET_FLAG(screen->row_used, i_row);
+    }
+    UNSET_FLAG(screen->row_used, ctx->cursor_row);
+
+}
+
+static int reap_screen(CCaptionSubContext *ctx, int64_t pts)
+{
+    int i;
+    int ret = 0;
+    struct Screen *screen = ctx->screen + ctx->active_screen;
+    ctx->start_time = ctx->startv_time;
+
+    for( i = 0; screen->row_used && i < SCREEN_ROWS; i++)
+    {
+        if(CHECK_FLAG(screen->row_used,i)) {
+            char *str = screen->characters[i];
+            /* skip space */
+            while (*str == ' ')
+                str++;
+
+            av_bprintf(&ctx->buffer, "%s\\N", str);
+            ret = av_bprint_is_complete(&ctx->buffer);
+            if( ret == 0) {
+                ret = AVERROR(ENOMEM);
+                break;
+            }
+        }
+
+    }
+    ctx->startv_time = pts;
+    ctx->end_time = pts;
+    return ret;
+}
+
 static void handle_textattr( CCaptionSubContext *ctx, uint8_t hi, uint8_t lo )
 {
     int i = lo - 0x20;
@@ -333,32 +393,12 @@ static void handle_pac( CCaptionSubContext *ctx, uint8_t hi, uint8_t lo )
  */
 static int handle_edm(CCaptionSubContext *ctx,int64_t pts)
 {
-    int i;
     int ret = 0;
     struct Screen *screen = ctx->screen + ctx->active_screen;
 
-    ctx->start_time = ctx->startv_time;
-    for( i = 0; screen->row_used && i < SCREEN_ROWS; i++)
-    {
-        if(CHECK_FLAG(screen->row_used,i)) {
-            char *str = screen->characters[i];
-            /* skip space */
-            while (*str == ' ')
-                str++;
-            av_bprint_append_data(&ctx->buffer, str, strlen(str));
-            av_bprint_append_data(&ctx->buffer, "\\N",2);
-            UNSET_FLAG(screen->row_used, i);
-            ret = av_bprint_is_complete(&ctx->buffer);
-            if( ret == 0) {
-                ret = AVERROR(ENOMEM);
-                break;
-            }
-        }
-
-    }
-    ctx->startv_time = pts;
+    reap_screen(ctx, pts);
+    screen->row_used = 0;
     ctx->screen_changed = 1;
-    ctx->end_time = pts;
     return ret;
 }
 
@@ -426,10 +466,13 @@ static int process_cc608(CCaptionSubContext *ctx, int64_t pts, uint8_t hi, uint8
         handle_delete_end_of_row(ctx, hi, lo);
     } else if ( COR3(hi, 0x14, 0x15, 0x1C) && lo == 0x25 ) {
         ctx->rollup = 2;
+        ctx->mode = CCMODE_ROLLUP_2;
     } else if ( COR3(hi, 0x14, 0x15, 0x1C) && lo == 0x26 ) {
         ctx->rollup = 3;
+        ctx->mode = CCMODE_ROLLUP_3;
     } else if ( COR3(hi, 0x14, 0x15, 0x1C) && lo == 0x27 ) {
         ctx->rollup = 4;
+        ctx->mode = CCMODE_ROLLUP_3;
     } else if ( COR3(hi, 0x14, 0x15, 0x1C) && lo == 0x29 ) {
     /* resume direct captioning */
         ctx->mode = CCMODE_PAINTON;
@@ -441,12 +484,9 @@ static int process_cc608(CCaptionSubContext *ctx, int64_t pts, uint8_t hi, uint8
         ret = handle_edm(ctx, pts);
     } else if ( COR3(hi, 0x14, 0x15, 0x1C) && lo == 0x2D ) {
     /* carriage return */
-        ctx->row_cnt++;
-        if(ctx->row_cnt >= ctx->rollup) {
-            ctx->row_cnt = 0;
-            ret = handle_edm(ctx, pts);
-            ctx->active_screen = !ctx->active_screen;
-        }
+        roll_up(ctx);
+        reap_screen(ctx, pts);
+        ctx->screen_changed = 1;
         ctx->cursor_column = 0;
     } else if ( COR3(hi, 0x14, 0x15, 0x1C) && lo == 0x2F ) {
     /* end of caption */
-- 
2.1.2

>From 49608e2a66bcd04ed3c6fd68dddfd7796390e1ee Mon Sep 17 00:00:00 2001
From: Anshul Maheshwari <er.anshul.maheshw...@gmail.com>
Date: Tue, 20 Jan 2015 16:17:13 +0530
Subject: [PATCH 7/8] Added error concealment

Signed-off-by: Anshul Maheshwari <er.anshul.maheshw...@gmail.com>
---
 libavcodec/ccaption_dec.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index efa5592..f6508b3 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -181,13 +181,16 @@ static av_cold int init_decoder(AVCodecContext *avctx)
     ctx->mode = CCMODE_ROLLUP_2;
     ctx->rollup = 2;
     ret = ff_ass_subtitle_header_default(avctx);
+    if(ret < 0) {
+        goto fail;
+    }
     /* allocate pkt buffer */
     ctx->pktbuf = av_buffer_alloc(128);
     if( !ctx->pktbuf) {
         ret = AVERROR(ENOMEM);
     }
 
-
+fail:
     return ret;
 }
 
@@ -369,8 +372,10 @@ static void handle_pac( CCaptionSubContext *ctx, uint8_t hi, uint8_t lo )
     char *row;
     int indent,i,ret;
 
-    if( row_map[index] <= 0 )
+    if( row_map[index] <= 0 ) {
+        av_log(ctx, AV_LOG_DEBUG,"Invalid pac index encountered\n");
         return;
+    }
 
     lo &= 0x1f;
 
-- 
2.1.2

>From 03c8a130c6b6f3018a791b902d05678d2b8574d4 Mon Sep 17 00:00:00 2001
From: Anshul Maheshwari <er.anshul.maheshw...@gmail.com>
Date: Tue, 20 Jan 2015 16:35:04 +0530
Subject: [PATCH 8/8] Closed caption extra debug log

Signed-off-by: Anshul Maheshwari <er.anshul.maheshw...@gmail.com>
---
 libavcodec/ccaption_dec.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index f6508b3..f89ef21 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -489,18 +489,21 @@ static int process_cc608(CCaptionSubContext *ctx, int64_t pts, uint8_t hi, uint8
         ret = handle_edm(ctx, pts);
     } else if ( COR3(hi, 0x14, 0x15, 0x1C) && lo == 0x2D ) {
     /* carriage return */
+        av_dlog(ctx, "carriage return\n");
         roll_up(ctx);
         reap_screen(ctx, pts);
         ctx->screen_changed = 1;
         ctx->cursor_column = 0;
     } else if ( COR3(hi, 0x14, 0x15, 0x1C) && lo == 0x2F ) {
     /* end of caption */
+        av_dlog(ctx, "handle_eoc\n");
         ret = handle_eoc(ctx, pts);
     } else if (hi>=0x20) {
     /* Standard characters (always in pairs) */
         handle_char(ctx, hi, lo, pts);
     } else {
     /* Ignoring all other non data code */
+        av_dlog(ctx, "Unknown command 0x%hhx 0x%hhx\n", hi, lo);
     }
 
     /* set prev command */
-- 
2.1.2

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Reply via email to