[FFmpeg-cvslog] ffv1: add optional per slice CRCs to detect undamaged slices.

Michael Niedermayer git at videolan.org
Fri Apr 20 15:43:16 CEST 2012


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Fri Apr 20 15:08:28 2012 +0200| [044f7275d3461d30787f067d7671af9b79da28c0] | committer: Michael Niedermayer

ffv1: add optional per slice CRCs to detect undamaged slices.

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=044f7275d3461d30787f067d7671af9b79da28c0
---

 libavcodec/ffv1.c |   23 ++++++++++++++++++++++-
 1 files changed, 22 insertions(+), 1 deletions(-)

diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c
index 8db6253..491b3f5 100644
--- a/libavcodec/ffv1.c
+++ b/libavcodec/ffv1.c
@@ -192,6 +192,7 @@ typedef struct FFV1Context{
     int16_t *sample_buffer;
     int gob_count;
     int packed_at_lsb;
+    int ec;
 
     int quant_table_count;
 
@@ -833,6 +834,10 @@ static int write_extra_header(FFV1Context *f){
         }
     }
 
+    if(f->version > 2){
+        put_symbol(c, state, f->ec, 0);
+    }
+
     f->avctx->extradata_size= ff_rac_terminate(c);
     v = av_crc(av_crc_get_table(AV_CRC_32_IEEE), 0, f->avctx->extradata, f->avctx->extradata_size);
     AV_WL32(f->avctx->extradata + f->avctx->extradata_size, v);
@@ -1290,6 +1295,10 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
             AV_WB24(buf_p+bytes, bytes);
             bytes+=3;
         }
+        if(f->ec){
+            unsigned v = av_crc(av_crc_get_table(AV_CRC_32_IEEE), 0, buf_p, bytes);
+            AV_WL32(buf_p + bytes, v); bytes += 4;
+        }
         buf_p += bytes;
     }
 
@@ -1727,6 +1736,10 @@ static int read_extra_header(FFV1Context *f){
     }
 
     if(f->version > 2){
+        f->ec = get_symbol(c, state, 0);
+    }
+
+    if(f->version > 2){
         unsigned v;
         v = av_crc(av_crc_get_table(AV_CRC_32_IEEE), 0, f->avctx->extradata, f->avctx->extradata_size);
         if(v){
@@ -1959,9 +1972,10 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac
     buf_p= buf + buf_size;
     for(i=f->slice_count-1; i>=0; i--){
         FFV1Context *fs= f->slice_context[i];
+        int trailer = 3 + 4*!!f->ec;
         int v;
 
-        if(i) v = AV_RB24(buf_p-3)+3;
+        if(i) v = AV_RB24(buf_p-trailer)+trailer;
         else  v = buf_p - c->bytestream_start;
         if(buf_p - c->bytestream_start < v){
             av_log(avctx, AV_LOG_ERROR, "Slice pointer chain broken\n");
@@ -1969,6 +1983,13 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac
         }
         buf_p -= v;
 
+        if(f->ec){
+            unsigned crc = av_crc(av_crc_get_table(AV_CRC_32_IEEE), 0, buf_p, v);
+            if(crc){
+                av_log(f->avctx, AV_LOG_ERROR, "CRC mismatch %X!\n", crc);
+            }
+        }
+
         if(i){
             if(fs->ac){
                 ff_init_range_decoder(&fs->c, buf_p, v);



More information about the ffmpeg-cvslog mailing list