[FFmpeg-devel] [PATCH 1/2] lavc/ccaption_dec: do not ignore repeated character commands

Aman Gupta ffmpeg at tmm1.net
Thu Feb 11 07:21:09 CET 2016


From: Aman Gupta <aman at tmm1.net>

control codes in a cc stream can be repeated, and must be ignored.
however, repeated characters must not be ignored. the code attempted to
wipe prev_cmd in handle_char to allow repeated characters to be
processed, but prev_cmd would previously get reset _after_ handle_char()

i also moved the prev_cmd reset out from handle_char() so it can be
re-used for special character sets, which _must_ be ignored when
repeated.
---
 libavcodec/ccaption_dec.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index 790f071..5fb2ec6 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -484,9 +484,6 @@ static void handle_char(CCaptionSubContext *ctx, char hi, char lo, int64_t pts)
     if (ctx->mode != CCMODE_POPON)
         ctx->screen_touched = 1;
 
-    /* reset prev command since character can repeat */
-    ctx->prev_cmd[0] = 0;
-    ctx->prev_cmd[1] = 0;
     if (lo)
        ff_dlog(ctx, "(%c,%c)\n", hi, lo);
     else
@@ -497,8 +494,15 @@ static void process_cc608(CCaptionSubContext *ctx, int64_t pts, uint8_t hi, uint
 {
     if (hi == ctx->prev_cmd[0] && lo == ctx->prev_cmd[1]) {
         /* ignore redundant command */
-    } else if ( (hi == 0x10 && (lo >= 0x40 && lo <= 0x5f)) ||
-              ( (hi >= 0x11 && hi <= 0x17) && (lo >= 0x40 && lo <= 0x7f) ) ) {
+        return;
+    }
+
+    /* set prev command */
+    ctx->prev_cmd[0] = hi;
+    ctx->prev_cmd[1] = lo;
+
+    if ( (hi == 0x10 && (lo >= 0x40 && lo <= 0x5f)) ||
+       ( (hi >= 0x11 && hi <= 0x17) && (lo >= 0x40 && lo <= 0x7f) ) ) {
         handle_pac(ctx, hi, lo);
     } else if ( ( hi == 0x11 && lo >= 0x20 && lo <= 0x2f ) ||
                 ( hi == 0x17 && lo >= 0x2e && lo <= 0x2f) ) {
@@ -559,14 +563,11 @@ static void process_cc608(CCaptionSubContext *ctx, int64_t pts, uint8_t hi, uint
     } else if (hi >= 0x20) {
         /* Standard characters (always in pairs) */
         handle_char(ctx, hi, lo, pts);
+        ctx->prev_cmd[0] = ctx->prev_cmd[1] = 0;
     } else {
         /* Ignoring all other non data code */
         ff_dlog(ctx, "Unknown command 0x%hhx 0x%hhx\n", hi, lo);
     }
-
-    /* set prev command */
-    ctx->prev_cmd[0] = hi;
-    ctx->prev_cmd[1] = lo;
 }
 
 static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avpkt)
-- 
2.5.3



More information about the ffmpeg-devel mailing list