From patchwork Fri Feb 19 07:50:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 25788 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 4CA87447D4B for ; Fri, 19 Feb 2021 09:51:01 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 216A768A2B9; Fri, 19 Feb 2021 09:51:01 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5CF1168A27A for ; Fri, 19 Feb 2021 09:50:53 +0200 (EET) Received: by mail-wr1-f53.google.com with SMTP id n4so6637385wrx.1 for ; Thu, 18 Feb 2021 23:50:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=h/9BcAw8G9/jO31K9ZJiJ2hBWMSx/oYqL69Srqg7WPI=; b=XcOrm1/3KWu0STu4T7j+ris/zXT1HOj93cVhDZ10LmQALVWPT/pi69ka+o/gUZyOsC ZgL/yTEWnfX3FH3PlZvMjxCR7DlQqKMRG8ia6ddeX3eayPLcWHVLDtUEDT5KNKQfoFUB yRQ5d2Nbkxm3E2CxxeLdRygUsNMH84AJ/esjSdJKXZniG7tmrv4N/5uRCzmFjLrXng8W o7d6vL8Dh0IOiMEf74QzAOkNBbdadB+7fn4TppkHWdykpmXqxgSHotBDZVKPjisWdUAG cXtv3tQQrDuf5n97zaPpJQ+9qcElTgFVcfKdc4eOHWik3pWBFY2XNso4gFVgmkUbdniQ qsQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=h/9BcAw8G9/jO31K9ZJiJ2hBWMSx/oYqL69Srqg7WPI=; b=oGkTSrU5OTQcAn6p27q1itJv1sIGIXdwmYdzF4Ir4i1615ZEbKnWvzkW6zez3Dd5VV SlbeqMxjuFKNquctzLt5uhiRWU6lDZhJ1PPh2ukQzlL1je1DqZEc4qERJIy3gHEQ5moK jMYXO7FiGRZ0zoOj6uuFPsBMHM+jFfPfEPs5ii94sygbgwwsIaTntkDivyQlSnnyrrT/ ehvLfCgoz553xx5rxdHqy++cSVE8eAkg3MjUUoxFnzieQrgaTqyZ4v9Xea0GFhbya9aA WPWr1hUINBm4A6QXqWLcTcnaV2/zHABodbL4Kte71QjvVUBn4/U5mJ3rUezGJ3IZKMTO qlDw== X-Gm-Message-State: AOAM533tagp+hywg34ZNiMI7kbyVSd8KieIQWoVY7XBSWz8gG6I3yT9x E+QXeY5Q8pEWi7g58qGOyDDl5qHidkw= X-Google-Smtp-Source: ABdhPJx82W+SdQ3PJwyVPDDLYFVsiAQ+ymTPqawziOjU44wfz2l1nJqINsihiyjeD6dAfbFv4GpFJA== X-Received: by 2002:a5d:4a0b:: with SMTP id m11mr7985013wrq.51.1613721052719; Thu, 18 Feb 2021 23:50:52 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id z190sm6130795wme.15.2021.02.18.23.50.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Feb 2021 23:50:52 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 19 Feb 2021 08:50:11 +0100 Message-Id: <20210219075022.2445161-4-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210219075022.2445161-1-andreas.rheinhardt@gmail.com> References: <20210219075022.2445161-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 04/15] avcodec/rangecoder: Move ff_rac_check_termination to tests/rangecoder.c 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" It is only used there. Signed-off-by: Andreas Rheinhardt --- libavcodec/rangecoder.c | 19 ------------------- libavcodec/rangecoder.h | 9 --------- libavcodec/tests/rangecoder.c | 28 +++++++++++++++++++++++++++- 3 files changed, 27 insertions(+), 29 deletions(-) diff --git a/libavcodec/rangecoder.c b/libavcodec/rangecoder.c index a6a3f082ef..fa7d5526d1 100644 --- a/libavcodec/rangecoder.c +++ b/libavcodec/rangecoder.c @@ -121,22 +121,3 @@ int ff_rac_terminate(RangeCoder *c, int version) return c->bytestream - c->bytestream_start; } - -int ff_rac_check_termination(RangeCoder *c, int version) -{ - if (version == 1) { - RangeCoder tmp = *c; - get_rac(c, (uint8_t[]) { 129 }); - - if (c->bytestream == tmp.bytestream && c->bytestream > c->bytestream_start) - tmp.low -= *--tmp.bytestream; - tmp.bytestream_end = tmp.bytestream; - - if (get_rac(&tmp, (uint8_t[]) { 129 })) - return AVERROR_INVALIDDATA; - } else { - if (c->bytestream_end != c->bytestream) - return AVERROR_INVALIDDATA; - } - return 0; -} diff --git a/libavcodec/rangecoder.h b/libavcodec/rangecoder.h index 4d4ca4d526..4495f6df1a 100644 --- a/libavcodec/rangecoder.h +++ b/libavcodec/rangecoder.h @@ -57,15 +57,6 @@ void ff_init_range_decoder(RangeCoder *c, const uint8_t *buf, int buf_size); */ int ff_rac_terminate(RangeCoder *c, int version); -/** - * Check if at the current position there is a valid looking termination - * @param version version 0 requires the decoder to know the data size in bytes - * version 1 needs about 1 bit more space but does not need to - * carry the size from encoder to decoder - * @returns negative AVERROR code on error or non negative. - */ -int ff_rac_check_termination(RangeCoder *c, int version); - void ff_build_rac_states(RangeCoder *c, int factor, int max_p); static inline void renorm_encoder(RangeCoder *c) diff --git a/libavcodec/tests/rangecoder.c b/libavcodec/tests/rangecoder.c index d6cf9ec380..ca96e13c99 100644 --- a/libavcodec/tests/rangecoder.c +++ b/libavcodec/tests/rangecoder.c @@ -26,6 +26,32 @@ #define SIZE 1240 +/** + * Check if at the current position there is a valid looking termination + * @param version version 0 requires the decoder to know the data size in bytes + * version 1 needs about 1 bit more space but does not need to + * carry the size from encoder to decoder + * @returns negative AVERROR code on error or non negative. + */ +static int rac_check_termination(RangeCoder *c, int version) +{ + if (version == 1) { + RangeCoder tmp = *c; + get_rac(c, (uint8_t[]) { 129 }); + + if (c->bytestream == tmp.bytestream && c->bytestream > c->bytestream_start) + tmp.low -= *--tmp.bytestream; + tmp.bytestream_end = tmp.bytestream; + + if (get_rac(&tmp, (uint8_t[]) { 129 })) + return AVERROR_INVALIDDATA; + } else { + if (c->bytestream_end != c->bytestream) + return AVERROR_INVALIDDATA; + } + return 0; +} + int main(void) { RangeCoder c; @@ -61,7 +87,7 @@ int main(void) return 1; } - if (ff_rac_check_termination(&c, version) < 0) { + if (rac_check_termination(&c, version) < 0) { av_log(NULL, AV_LOG_ERROR, "rac failure at termination pass %d version %d\n", p, version); return 1; }