[FFmpeg-cvslog] avcodec/ffv1: Implement CRC with non zero initial and final value
Michael Niedermayer
git at videolan.org
Thu Oct 10 20:36:16 EEST 2024
ffmpeg | branch: master | Michael Niedermayer <michael at niedermayer.cc> | Wed Sep 25 09:46:17 2024 +0200| [7bb283aa7bdc96c475086a0769fe228bddd34db1] | committer: Michael Niedermayer
avcodec/ffv1: Implement CRC with non zero initial and final value
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=7bb283aa7bdc96c475086a0769fe228bddd34db1
---
libavcodec/ffv1.h | 1 +
libavcodec/ffv1dec.c | 10 ++++++----
libavcodec/ffv1enc.c | 12 +++++++++---
3 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index e19c0df014..b98f0b3685 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -119,6 +119,7 @@ typedef struct FFV1Context {
int64_t picture_number;
int key_frame;
ProgressFrame picture, last_picture;
+ uint32_t crcref;
const AVFrame *cur_enc_frame;
int plane_count;
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index 0afdeabd91..b4d719a7ee 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -502,15 +502,17 @@ static int read_extra_header(FFV1Context *f)
if (f->version > 2) {
f->ec = get_symbol(&c, state, 0);
+ if (f->ec >= 2)
+ f->crcref = 0x7a8c4079;
if (f->micro_version > 2)
f->intra = get_symbol(&c, state, 0);
}
if (f->version > 2) {
unsigned v;
- v = av_crc(av_crc_get_table(AV_CRC_32_IEEE), 0,
+ v = av_crc(av_crc_get_table(AV_CRC_32_IEEE), f->crcref,
f->avctx->extradata, f->avctx->extradata_size);
- if (v || f->avctx->extradata_size < 4) {
+ if (v != f->crcref || f->avctx->extradata_size < 4) {
av_log(f->avctx, AV_LOG_ERROR, "CRC mismatch %X!\n", v);
return AVERROR_INVALIDDATA;
}
@@ -948,8 +950,8 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *rframe,
buf_p -= v;
if (f->ec) {
- unsigned crc = av_crc(av_crc_get_table(AV_CRC_32_IEEE), 0, buf_p, v);
- if (crc) {
+ unsigned crc = av_crc(av_crc_get_table(AV_CRC_32_IEEE), f->crcref, buf_p, v);
+ if (crc != f->crcref) {
int64_t ts = avpkt->pts != AV_NOPTS_VALUE ? avpkt->pts : avpkt->dts;
av_log(f->avctx, AV_LOG_ERROR, "slice CRC mismatch %X!", crc);
if (ts != AV_NOPTS_VALUE && avctx->pkt_timebase.num) {
diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c
index 56af7dc427..b9ee5b629a 100644
--- a/libavcodec/ffv1enc.c
+++ b/libavcodec/ffv1enc.c
@@ -458,7 +458,7 @@ static int write_extradata(FFV1Context *f)
}
f->avctx->extradata_size = ff_rac_terminate(&c, 0);
- 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), f->crcref, f->avctx->extradata, f->avctx->extradata_size) ^ (f->crcref ? 0x8CD88196 : 0);
AV_WL32(f->avctx->extradata + f->avctx->extradata_size, v);
f->avctx->extradata_size += 4;
@@ -549,7 +549,13 @@ static av_cold int encode_init(AVCodecContext *avctx)
}
if (s->ec < 0) {
- s->ec = (s->version >= 3);
+ if (s->version >= 4) {
+ s->ec = 2;
+ s->crcref = 0x7a8c4079;
+ } else if (s->version >= 3) {
+ s->ec = 1;
+ } else
+ s->ec = 0;
}
// CRC requires version 3+
@@ -1239,7 +1245,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
if (f->ec) {
unsigned v;
buf_p[bytes++] = 0;
- v = av_crc(av_crc_get_table(AV_CRC_32_IEEE), 0, buf_p, bytes);
+ v = av_crc(av_crc_get_table(AV_CRC_32_IEEE), f->crcref, buf_p, bytes) ^ (f->crcref ? 0x8CD88196 : 0);
AV_WL32(buf_p + bytes, v);
bytes += 4;
}
More information about the ffmpeg-cvslog
mailing list