From patchwork Thu Oct 17 22:25:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 15832 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 285D444A117 for ; Fri, 18 Oct 2019 01:33:17 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0BDDA68ABD0; Fri, 18 Oct 2019 01:33:17 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe03-2.mx.upcmail.net (vie01a-dmta-pe03-2.mx.upcmail.net [62.179.121.161]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7406F68A938 for ; Fri, 18 Oct 2019 01:33:10 +0300 (EEST) Received: from [172.31.216.235] (helo=vie01a-pemc-psmtp-pe12.mail.upcmail.net) by vie01a-dmta-pe03.mx.upcmail.net with esmtp (Exim 4.92) (envelope-from ) id 1iLEEh-0009Yq-0N for ffmpeg-devel@ffmpeg.org; Fri, 18 Oct 2019 00:27:11 +0200 Received: from localhost ([213.47.68.29]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id LEDjivldNwlysLEDjiR6JU; Fri, 18 Oct 2019 00:26:11 +0200 X-Env-Mailfrom: michael@niedermayer.cc X-Env-Rcptto: ffmpeg-devel@ffmpeg.org X-SourceIP: 213.47.68.29 X-CNFS-Analysis: v=2.3 cv=E5OzWpVl c=1 sm=1 tr=0 a=2hcxjKEKjp0CzLx6oWAm4g==:117 a=2hcxjKEKjp0CzLx6oWAm4g==:17 a=jpOVt7BSZ2e4Z31A5e1TngXxSK0=:19 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=GEAsPZ9sns4A:10 a=ZZnuYtJkoWoA:10 a=c4JsnF95T8fn_LbgezEA:9 a=pHzHmUro8NiASowvMSCR:22 a=Ew2E2A-JSTLzCXPT_086:22 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Fri, 18 Oct 2019 00:25:12 +0200 Message-Id: <20191017222515.21382-2-michael@niedermayer.cc> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191017222515.21382-1-michael@niedermayer.cc> References: <20191017222515.21382-1-michael@niedermayer.cc> MIME-Version: 1.0 X-CMAE-Envelope: MS4wfGNqNwbOcTG4pMZmdi+JDXUVIFLunOBg8pVtnmJk/iF9B7X9VvcyOSpSHs6kKWJtd4ljcorT6XRzETMRC3r8SXeRnhDABtqCRENg49Hplhu0CBw55g0H bOlPx1GLkRhEDbEq86m3Xs3xF/mWQ6FQci71lZOsRJ5Xhk2Dt7PUEYsv Subject: [FFmpeg-devel] [PATCH 2/4] avcodec/ffv1: Implementation of the CRC proposal for v4 X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Michael Niedermayer Signed-off-by: Michael Niedermayer --- libavcodec/ffv1.h | 1 + libavcodec/ffv1dec.c | 10 +++++++--- libavcodec/ffv1enc.c | 10 +++++++--- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h index f0bb19350a..3edf9dfca3 100644 --- a/libavcodec/ffv1.h +++ b/libavcodec/ffv1.h @@ -114,6 +114,7 @@ typedef struct FFV1Context { int use32bit; int ec; + unsigned crc_flip; int intra; int slice_damaged; int key_frame_ok; diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index 261e0cf70c..bc2b776754 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -500,8 +500,12 @@ static int read_extra_header(FFV1Context *f) 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 (f->version > 4 || (f->version == 4 && f->micro_version >= 3)) + f->crc_flip = 0xFFFFFFFF; + + v = av_crc(av_crc_get_table(AV_CRC_32_IEEE), f->crc_flip, + f->avctx->extradata, f->avctx->extradata_size) ^ f->crc_flip; if (v || f->avctx->extradata_size < 4) { av_log(f->avctx, AV_LOG_ERROR, "CRC mismatch %X!\n", v); return AVERROR_INVALIDDATA; @@ -903,7 +907,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac buf_p -= v; if (f->ec) { - unsigned crc = av_crc(av_crc_get_table(AV_CRC_32_IEEE), 0, buf_p, v); + unsigned crc = av_crc(av_crc_get_table(AV_CRC_32_IEEE), f->crc_flip, buf_p, v) ^ f->crc_flip; if (crc) { int64_t ts = avpkt->pts != AV_NOPTS_VALUE ? avpkt->pts : avpkt->dts; av_log(f->avctx, AV_LOG_ERROR, "CRC mismatch %X!", crc); diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c index c521b7d445..4beb8fde35 100644 --- a/libavcodec/ffv1enc.c +++ b/libavcodec/ffv1enc.c @@ -417,7 +417,7 @@ static int write_extradata(FFV1Context *f) if (f->version == 3) { f->micro_version = 4; } else if (f->version == 4) - f->micro_version = 2; + f->micro_version = 3; put_symbol(c, state, f->micro_version, 0); } @@ -459,7 +459,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->crc_flip, f->avctx->extradata, f->avctx->extradata_size) ^ (f->crc_flip & 0x4964AF46); AV_WL32(f->avctx->extradata + f->avctx->extradata_size, v); f->avctx->extradata_size += 4; @@ -898,6 +898,10 @@ FF_ENABLE_DEPRECATION_WARNINGS avctx->slices); return AVERROR(ENOSYS); slices_ok: + + if (s->version > 3) + s->crc_flip = 0xFFFFFFFF; + if ((ret = write_extradata(s)) < 0) return ret; } @@ -1254,7 +1258,7 @@ FF_ENABLE_DEPRECATION_WARNINGS 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->crc_flip, buf_p, bytes) ^ (f->crc_flip & 0x4964AF46); AV_WL32(buf_p + bytes, v); bytes += 4; }