Commit 044f7275 authored by Michael Niedermayer's avatar Michael Niedermayer

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

Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent b4fc5385
...@@ -192,6 +192,7 @@ typedef struct FFV1Context{ ...@@ -192,6 +192,7 @@ typedef struct FFV1Context{
int16_t *sample_buffer; int16_t *sample_buffer;
int gob_count; int gob_count;
int packed_at_lsb; int packed_at_lsb;
int ec;
int quant_table_count; int quant_table_count;
...@@ -833,6 +834,10 @@ static int write_extra_header(FFV1Context *f){ ...@@ -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); 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); 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); AV_WL32(f->avctx->extradata + f->avctx->extradata_size, v);
...@@ -1290,6 +1295,10 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, ...@@ -1290,6 +1295,10 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
AV_WB24(buf_p+bytes, bytes); AV_WB24(buf_p+bytes, bytes);
bytes+=3; 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; buf_p += bytes;
} }
...@@ -1726,6 +1735,10 @@ static int read_extra_header(FFV1Context *f){ ...@@ -1726,6 +1735,10 @@ static int read_extra_header(FFV1Context *f){
} }
} }
if(f->version > 2){
f->ec = get_symbol(c, state, 0);
}
if(f->version > 2){ if(f->version > 2){
unsigned v; unsigned v;
v = av_crc(av_crc_get_table(AV_CRC_32_IEEE), 0, f->avctx->extradata, f->avctx->extradata_size); v = av_crc(av_crc_get_table(AV_CRC_32_IEEE), 0, f->avctx->extradata, f->avctx->extradata_size);
...@@ -1959,9 +1972,10 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac ...@@ -1959,9 +1972,10 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac
buf_p= buf + buf_size; buf_p= buf + buf_size;
for(i=f->slice_count-1; i>=0; i--){ for(i=f->slice_count-1; i>=0; i--){
FFV1Context *fs= f->slice_context[i]; FFV1Context *fs= f->slice_context[i];
int trailer = 3 + 4*!!f->ec;
int v; 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; else v = buf_p - c->bytestream_start;
if(buf_p - c->bytestream_start < v){ if(buf_p - c->bytestream_start < v){
av_log(avctx, AV_LOG_ERROR, "Slice pointer chain broken\n"); 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 ...@@ -1969,6 +1983,13 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac
} }
buf_p -= v; 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(i){
if(fs->ac){ if(fs->ac){
ff_init_range_decoder(&fs->c, buf_p, v); ff_init_range_decoder(&fs->c, buf_p, v);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment