From patchwork Sun Jul 3 10:26:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 36629 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:8b27:b0:88:1bbf:7fd2 with SMTP id l39csp2138960pzh; Sun, 3 Jul 2022 03:28:38 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s8nzIRG+4j8CtQbRnKKvWTD1MapyPmnPV5LqCtjuKmwDk/uStIQghWp3uyk+/rZVeNwW7K X-Received: by 2002:a17:907:ea5:b0:726:2c1c:312f with SMTP id ho37-20020a1709070ea500b007262c1c312fmr22691833ejc.248.1656844117907; Sun, 03 Jul 2022 03:28:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656844117; cv=none; d=google.com; s=arc-20160816; b=uCVq+iwLiA36MhMwpzaUDSgyu816S9iEC6S3KrYGCPPCWiTA5bK+aBodS5hCQDzu6B T79QVz3V/VksoP7XTooiwLNkxlzcU25Edr10oBsaZ6eck3cK5CBkMZ1+448CNBQ646HH vzFd/DbaF47kDY3KSxXnnWy86i/L/oZV7wc+NGu/NN2PnvrE/pmRmE/K6KzolJ0H/Ebp 4U9wb0/nZV3mLlXLTEfHKbv4W2z3eWC4G7iCqTW40qilT4wj/xNELEdMvHD1y7e7Sp2o rvMTfE6eJYTcqUcTKFRZQz6mz2V003qLjg9qiD9SQdlaWMtS0mN75cSffngzsn25L0qB JCJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=kin57EYFyD1vXWcBZe+1SsBQn+wz+FJffcpIvsEj9Lk=; b=BZNaMtbCAqdWfmg7f/TGw+oyE8SaXPn3N5STyeGyoMj7e4ozDeeCJ+5LZCSqTRzD9s s7nscZkZjLTkbTV2zhXLs1i7niDkL6B5ZZw8Y1hyQjEWoPnR4Pm6bDQVsHL5ml9rREgV R/5dWcKbr3/QlHGIEdV8qKr0o5drzK5PXaaEMFxVFK4d8pHAYfUfVXe/NynsY3Sk2PGa mLacJTll3gO+TuPWluwWlImwH5S04oPDFJGNcZidTaWh3xLlDLU5CX/Bvz8hM+buy9X9 r8ptDwdL8rCUVLO4uF5pF2/Hq6EK8BfU7jVBJkoCi+DECPCL6S2VofC/LE+JPgXYzEgU ORNg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id cy20-20020a0564021c9400b0043a2cd05f6csi944332edb.178.2022.07.03.03.28.37; Sun, 03 Jul 2022 03:28:37 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 97DC668B987; Sun, 3 Jul 2022 13:28:21 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 823A068B98E for ; Sun, 3 Jul 2022 13:28:13 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id D54DC240179 for ; Sun, 3 Jul 2022 12:28:12 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id LBWJ9PylkATR for ; Sun, 3 Jul 2022 12:28:12 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id A673C24017C for ; Sun, 3 Jul 2022 12:28:10 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id CE34E3A09CF; Sun, 3 Jul 2022 12:28:10 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 3 Jul 2022 12:26:36 +0200 Message-Id: <20220703102636.32523-3-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220703102636.32523-1-anton@khirnov.net> References: <20220703102636.32523-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/3] lavc/tests: add a cached bitstream reader test X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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" X-TUID: 2V+0SUcA7tQp --- libavcodec/Makefile | 2 + libavcodec/tests/bitstream_be.c | 19 ++++ libavcodec/tests/bitstream_le.c | 20 ++++ libavcodec/tests/bitstream_template.c | 153 ++++++++++++++++++++++++++ tests/fate/libavcodec.mak | 10 ++ 5 files changed, 204 insertions(+) create mode 100644 libavcodec/tests/bitstream_be.c create mode 100644 libavcodec/tests/bitstream_le.c create mode 100644 libavcodec/tests/bitstream_template.c diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 050934101c..0457f6d0fd 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -1252,6 +1252,8 @@ SKIPHEADERS-$(CONFIG_V4L2_M2M) += v4l2_buffers.h v4l2_context.h v4l2_m2m TESTPROGS = avcodec \ avpacket \ + bitstream_be \ + bitstream_le \ celp_math \ codec_desc \ htmlsubtitles \ diff --git a/libavcodec/tests/bitstream_be.c b/libavcodec/tests/bitstream_be.c new file mode 100644 index 0000000000..bc562ed3b1 --- /dev/null +++ b/libavcodec/tests/bitstream_be.c @@ -0,0 +1,19 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "bitstream_template.c" diff --git a/libavcodec/tests/bitstream_le.c b/libavcodec/tests/bitstream_le.c new file mode 100644 index 0000000000..a907676438 --- /dev/null +++ b/libavcodec/tests/bitstream_le.c @@ -0,0 +1,20 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#define BITSTREAM_READER_LE +#include "bitstream_template.c" diff --git a/libavcodec/tests/bitstream_template.c b/libavcodec/tests/bitstream_template.c new file mode 100644 index 0000000000..8685f27b0c --- /dev/null +++ b/libavcodec/tests/bitstream_template.c @@ -0,0 +1,153 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#define ASSERT_LEVEL 2 + +#include "libavutil/avassert.h" +#include "libavutil/lfg.h" +#include "libavutil/random_seed.h" + +#include "libavcodec/bitstream.h" +#include "libavcodec/defs.h" + +#ifdef BITSTREAM_READER_LE +#define BITSTREAM_WRITER_LE +#endif +#include "libavcodec/put_bits.h" + +#define SIZE 157 + +enum Op { + OP_READ, + OP_READ_NZ, + OP_READ_BIT, + OP_READ_63, + OP_READ_64, + OP_READ_SIGNED, + OP_UNGET, + OP_NB, +}; + +int main(int argc, char **argv) +{ + BitstreamContext bc; + PutBitContext pb; + AVLFG lfg; + + uint8_t buf[SIZE + AV_INPUT_BUFFER_PADDING_SIZE]; + uint8_t dst[SIZE + AV_INPUT_BUFFER_PADDING_SIZE]; + + uint32_t random_seed; + uint64_t val; + int32_t sval; + unsigned count; + + /* generate random input, using a given or random seed */ + if (argc > 1) + random_seed = strtoul(argv[1], NULL, 0); + else + random_seed = av_get_random_seed(); + + fprintf(stderr, "Testing with LFG seed: %"PRIu32"\n", random_seed); + av_lfg_init(&lfg, random_seed); + + for (unsigned i = 0; i < SIZE; i++) + buf[i] = av_lfg_get(&lfg); + + bits_init8 (&bc, buf, SIZE); + init_put_bits(&pb, dst, SIZE); + + /* use a random sequence of bitreading operations to transfer data + * from BitstreamContext to PutBitContext */ + while (bits_left(&bc) > 0) { + enum Op op = av_lfg_get(&lfg) % OP_NB; + + switch (op) { + case OP_READ: + count = av_lfg_get(&lfg) % FFMIN(33, bits_left(&bc) + 1); + val = bits_read(&bc, count); + + fprintf(stderr, "%d read %u: %"PRIu64"\n", bits_tell(&bc) - count, count, val); + + put_bits64(&pb, count, val); + break; + case OP_READ_NZ: + count = av_lfg_get(&lfg) % FFMIN(33, bits_left(&bc) + 1); + count = FFMAX(count, 1); + val = bits_read_nz(&bc, count); + + fprintf(stderr, "%d read_nz %u: %"PRIu64"\n", bits_tell(&bc) - count, count, val); + + put_bits64(&pb, count, val); + break; + case OP_READ_BIT: + val = bits_read_bit(&bc); + + fprintf(stderr, "%d read_bit: %"PRIu64"\n", bits_tell(&bc) - 1, val); + + put_bits(&pb, 1, val); + break; + case OP_READ_63: + count = av_lfg_get(&lfg) % FFMIN(64, bits_left(&bc) + 1); + val = bits_read_63(&bc, count); + + fprintf(stderr, "%d read_63 %u: %"PRIu64"\n", bits_tell(&bc) - count, count, val); + + put_bits64(&pb, count, val); + break; + case OP_READ_64: + count = av_lfg_get(&lfg) % FFMIN(65, bits_left(&bc) + 1); + val = bits_read_64(&bc, count); + + fprintf(stderr, "%d read_64 %u: %"PRIu64"\n", bits_tell(&bc) - count, count, val); + + put_bits64(&pb, count, val); + break; + case OP_READ_SIGNED: + count = av_lfg_get(&lfg) % FFMIN(33, bits_left(&bc) + 1); + sval = bits_read_signed(&bc, count); + + fprintf(stderr, "%d read_signed %u: %"PRId32"\n", bits_tell(&bc) - count, count, sval); + + if (count == 32) put_bits32(&pb, sval); + else put_sbits(&pb, count, sval); + break; + case OP_UNGET: + count = av_lfg_get(&lfg) % FFMIN(33, bits_left(&bc) + 1); + val = bits_read(&bc, count); + bits_unget(&bc, val, count); + + fprintf(stderr, "%d unget %u: %"PRIu64"\n", bits_tell(&bc), count, val); + + break; + default: + av_assert0(0); + } + } + + flush_put_bits(&pb); + + for (unsigned i = 0; i < SIZE; i++) + if (buf[i] != dst[i]) { + fprintf(stderr, "Mismatch at byte %u: %hhu %hhu; seed %"PRIu32"\n", + i, buf[i], dst[i], random_seed); + return 1; + } + + return 0; +} diff --git a/tests/fate/libavcodec.mak b/tests/fate/libavcodec.mak index aa199e0308..8f56fae3a8 100644 --- a/tests/fate/libavcodec.mak +++ b/tests/fate/libavcodec.mak @@ -3,6 +3,16 @@ fate-avpacket: libavcodec/tests/avpacket$(EXESUF) fate-avpacket: CMD = run libavcodec/tests/avpacket$(EXESUF) fate-avpacket: CMP = null +FATE_LIBAVCODEC-yes += fate-bitstream-be +fate-bitstream-be: libavcodec/tests/bitstream_be$(EXESUF) +fate-bitstream-be: CMD = run libavcodec/tests/bitstream_be$(EXESUF) +fate-bitstream-be: CMP = null + +FATE_LIBAVCODEC-yes += fate-bitstream-le +fate-bitstream-le: libavcodec/tests/bitstream_le$(EXESUF) +fate-bitstream-le: CMD = run libavcodec/tests/bitstream_le$(EXESUF) +fate-bitstream-le: CMP = null + FATE_LIBAVCODEC-$(CONFIG_CABAC) += fate-cabac fate-cabac: libavcodec/tests/cabac$(EXESUF) fate-cabac: CMD = run libavcodec/tests/cabac$(EXESUF)