From patchwork Mon Jul 12 11:07:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 28910 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a25:bbc9:0:0:0:0:0 with SMTP id c9csp2811703ybk; Mon, 12 Jul 2021 04:08:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx3yVtPFDuHi3C8q80HYKmD+dpNQbcme7zC8EvTRFYXI7GlmqoIasr/B9CQIySJsFrvmBqr X-Received: by 2002:a17:906:190c:: with SMTP id a12mr26803236eje.37.1626088092813; Mon, 12 Jul 2021 04:08:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626088092; cv=none; d=google.com; s=arc-20160816; b=p6LmvazgyVv0TP2jHPnh8jUf2kgJkki4qPhMnphMxaBqX7QaqS7o+e6ICpF2RiZQwU zv0ldOStl3wq52DZcZBEFrizilw4YcFWl1TYHE8s1z+k3ZEmkxFVaY3gsLV7L3dcJrEQ +beO/cBQhIxan89SFZOuF0+rQ3VJBCWhSCn2fnIZxC+l3uZdxEMdDuOfjEEkLHnN/5kl 6h1wLD7VAlcMP5naQlHDhFp5IyxcKeMLr+PulhMGX7PfOUbZgmCRXRYYI3i8OMVLXoS6 N/xidFQ6OLRbcEy1TKy/9YK+WB+EO8qVWDujz+ASrGzlYYtzmMOptWIXBtfXesdFXNR2 jY2w== 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=ZkciRnzpVANEQu7RCtT/zCVe/0l6Vd/uroXrvkc9hHo=; b=DsVojzXIPn+qepWWvIHzAMlZLroXa0p4K49s6Ud3XSQRJnet3QRf3AI2zuO8wHjzCe duF7UBAcqzPDfxMa8SuxiCQ2tEm9f3TCJrBGhKWBoO47fijooy+Wnd/7QFkJ/wRzH1UZ jMNO+wKCiJgekWLIY4lRBoBAJcIOQxykYcinSDrb88z9DGIGY2PAtWemwk+MqN7/oTpT I/uULQnDJvKeCMcpmrxdciEW6nvohzxIoVVkHeqrrM9LurDEwYcBqHdI9EaP8jFMV5XM gUAKaHilWfq+eC3qJ+VvWUFez+WZWuETKl2TY4uGTkcV3GCyIZpIekdF3q4w1ounwMWf xSkg== 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 r14si14216586edw.524.2021.07.12.04.08.12; Mon, 12 Jul 2021 04:08:12 -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 E9EA468A938; Mon, 12 Jul 2021 14:08:01 +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 C91B76898E4 for ; Mon, 12 Jul 2021 14:07:54 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 8303E240693 for ; Mon, 12 Jul 2021 13:07:54 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id TwwtOugf8l7K for ; Mon, 12 Jul 2021 13:07:53 +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 651B72404B2 for ; Mon, 12 Jul 2021 13:07:52 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id 9CC253A0909; Mon, 12 Jul 2021 13:07:50 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Mon, 12 Jul 2021 13:07:03 +0200 Message-Id: <20210712110709.15532-3-anton@khirnov.net> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210712110709.15532-1-anton@khirnov.net> References: <20210712110709.15532-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/8] FATE: add a test for sliced scaling 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: Ks5kxNiNuTds Content-Length: 9267 --- Makefile | 2 + tests/Makefile | 1 + tests/fate/libswscale.mak | 11 +++ tools/Makefile | 3 +- tools/scale_slice_test.c | 190 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 206 insertions(+), 1 deletion(-) create mode 100644 tools/scale_slice_test.c diff --git a/Makefile b/Makefile index 1e3da6271b..26c9107237 100644 --- a/Makefile +++ b/Makefile @@ -64,6 +64,8 @@ tools/target_io_dem_fuzzer$(EXESUF): tools/target_io_dem_fuzzer.o $(FF_DEP_LIBS) tools/enum_options$(EXESUF): ELIBS = $(FF_EXTRALIBS) tools/enum_options$(EXESUF): $(FF_DEP_LIBS) +tools/scale_slice_test$(EXESUF): $(FF_DEP_LIBS) +tools/scale_slice_test$(EXESUF): ELIBS = $(FF_EXTRALIBS) tools/sofa2wavs$(EXESUF): ELIBS = $(FF_EXTRALIBS) tools/uncoded_frame$(EXESUF): $(FF_DEP_LIBS) tools/uncoded_frame$(EXESUF): ELIBS = $(FF_EXTRALIBS) diff --git a/tests/Makefile b/tests/Makefile index d726484b3a..e42e66d81b 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -221,6 +221,7 @@ $(FATE_FFPROBE) $(FATE_FFMPEG_FFPROBE) $(FATE_SAMPLES_FFPROBE) $(FATE_SAMPLES_FF $(FATE_SAMPLES_FASTSTART): tools/qt-faststart$(EXESUF) $(FATE_SAMPLES_DUMP_DATA): tools/venc_data_dump$(EXESUF) +$(FATE_SAMPLES_SCALE_SLICE): tools/scale_slice_test$(EXESUF) ifdef SAMPLES FATE += $(FATE_EXTERN) diff --git a/tests/fate/libswscale.mak b/tests/fate/libswscale.mak index 5ec5f34cc4..599d27b0a5 100644 --- a/tests/fate/libswscale.mak +++ b/tests/fate/libswscale.mak @@ -6,6 +6,17 @@ FATE_LIBSWSCALE += fate-sws-floatimg-cmp fate-sws-floatimg-cmp: libswscale/tests/floatimg_cmp$(EXESUF) fate-sws-floatimg-cmp: CMD = run libswscale/tests/floatimg_cmp$(EXESUF) +SWS_SLICE_TEST-$(call DEMDEC, MATROSKA, VP9) += fate-sws-slice-yuv422-12bit-rgb48 +fate-sws-slice-yuv422-12bit-rgb48: CMD = run tools/scale_slice_test$(EXESUF) $(TARGET_SAMPLES)/vp9-test-vectors/vp93-2-20-12bit-yuv422.webm 150 100 rgb48 + +SWS_SLICE_TEST-$(call DEMDEC, IMAGE_BMP_PIPE, BMP) += fate-sws-slice-bgr0-nv12 +fate-sws-slice-bgr0-nv12: CMD = run tools/scale_slice_test$(EXESUF) $(TARGET_SAMPLES)/bmp/test32bf.bmp 32 64 nv12 + +fate-sws-slice: $(SWS_SLICE_TEST-yes) +$(SWS_SLICE_TEST-yes): tools/scale_slice_test$(EXESUF) +$(SWS_SLICE_TEST-yes): REF = /dev/null +FATE_LIBSWSCALE += $(SWS_SLICE_TEST-yes) + FATE_LIBSWSCALE += $(FATE_LIBSWSCALE-yes) FATE-$(CONFIG_SWSCALE) += $(FATE_LIBSWSCALE) fate-libswscale: $(FATE_LIBSWSCALE) diff --git a/tools/Makefile b/tools/Makefile index ec260f254e..f4d1327b9f 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -1,4 +1,4 @@ -TOOLS = enum_options qt-faststart trasher uncoded_frame +TOOLS = enum_options qt-faststart scale_slice_test trasher uncoded_frame TOOLS-$(CONFIG_LIBMYSOFA) += sofa2wavs TOOLS-$(CONFIG_ZLIB) += cws2fws @@ -18,6 +18,7 @@ tools/target_io_dem_fuzzer.o: tools/target_dem_fuzzer.c $(COMPILE_C) -DIO_FLAT=0 tools/venc_data_dump$(EXESUF): tools/decode_simple.o +tools/scale_slice_test$(EXESUF): tools/decode_simple.o OUTDIRS += tools diff --git a/tools/scale_slice_test.c b/tools/scale_slice_test.c new file mode 100644 index 0000000000..d869eaae74 --- /dev/null +++ b/tools/scale_slice_test.c @@ -0,0 +1,190 @@ +/* + * 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 +#include +#include + +#include "decode_simple.h" + +#include "libavutil/common.h" +#include "libavutil/pixdesc.h" +#include "libavutil/error.h" +#include "libavutil/lfg.h" +#include "libavutil/random_seed.h" +#include "libavutil/video_enc_params.h" + +#include "libavformat/avformat.h" + +#include "libavcodec/avcodec.h" + +#include "libswscale/swscale.h" + +typedef struct PrivData { + unsigned int random_seed; + AVLFG lfg; + + struct SwsContext *scaler; + + int v_shift_dst, h_shift_dst; + int v_shift_src, h_shift_src; + + AVFrame *frame_ref; + AVFrame *frame_dst; +} PrivData; + +static int process_frame(DecodeContext *dc, AVFrame *frame) +{ + PrivData *pd = dc->opaque; + int slice_start = 0; + int ret; + + if (!frame) + return 0; + + if (!pd->scaler) { + pd->scaler = sws_getContext(frame->width, frame->height, frame->format, + pd->frame_ref->width, pd->frame_ref->height, + pd->frame_ref->format, 0, NULL, NULL, NULL); + if (!pd->scaler) + return AVERROR(ENOMEM); + + av_pix_fmt_get_chroma_sub_sample(frame->format, &pd->h_shift_src, &pd->v_shift_src); + } + + /* scale the whole input frame as reference */ + ret = sws_scale(pd->scaler, (const uint8_t **)frame->data, frame->linesize, 0, frame->height, + pd->frame_ref->data, pd->frame_ref->linesize); + if (ret < 0) + return ret; + + /* scale slices with randomly generated heights */ + while (slice_start < frame->height) { + int slice_height; + const uint8_t *src[4]; + + slice_height = av_lfg_get(&pd->lfg) % (frame->height - slice_start); + slice_height = FFALIGN(FFMAX(1, slice_height), 1 << pd->v_shift_src); + + for (int j = 0; j < FF_ARRAY_ELEMS(src) && frame->data[j]; j++) { + int shift = (j == 1 || j == 2) ? pd->v_shift_src : 0; + src[j] = frame->data[j] + frame->linesize[j] * (slice_start >> shift); + } + + ret = sws_scale(pd->scaler, src, frame->linesize, slice_start, slice_height, + pd->frame_dst->data, pd->frame_dst->linesize); + if (ret < 0) + return ret; + + slice_start += slice_height; + } + + /* compare the two results */ + for (int i = 0; i < 4 && pd->frame_ref->data[i]; i++) { + int shift = (i == 1 || i == 2) ? pd->v_shift_dst : 0; + + if (memcmp(pd->frame_ref->data[i], pd->frame_dst->data[i], + pd->frame_ref->linesize[i] * (pd->frame_ref->height >> shift))) { + fprintf(stderr, "mismatch frame %d seed %u\n", + dc->decoder->frame_number - 1, pd->random_seed); + return AVERROR(EINVAL); + } + } + + return 0; +} + +int main(int argc, char **argv) +{ + PrivData pd; + DecodeContext dc; + + int width, height; + enum AVPixelFormat pix_fmt; + const char *filename; + int ret = 0; + + if (argc <= 4) { + fprintf(stderr, + "Usage: %s [] \n", + argv[0]); + return 0; + } + + memset(&pd, 0, sizeof(pd)); + + filename = argv[1]; + width = strtol(argv[2], NULL, 0); + height = strtol(argv[3], NULL, 0); + pix_fmt = av_get_pix_fmt(argv[4]); + + /* init RNG for generating slice sizes */ + if (argc >= 6) + pd.random_seed = strtoul(argv[5], NULL, 0); + else + pd.random_seed = av_get_random_seed(); + + av_lfg_init(&pd.lfg, pd.random_seed); + + av_pix_fmt_get_chroma_sub_sample(pix_fmt, &pd.h_shift_dst, &pd.v_shift_dst); + + /* allocate the frames for scaler output */ + for (int i = 0; i < 2; i++) { + AVFrame *frame = av_frame_alloc(); + if (!frame) { + fprintf(stderr, "Error allocating frames\n"); + return AVERROR(ENOMEM); + } + + frame->width = width; + frame->height = height; + frame->format = pix_fmt; + + ret = av_frame_get_buffer(frame, 0); + if (ret < 0) { + fprintf(stderr, "Error allocating frame data\n"); + return ret; + } + + /* make sure the padding is zeroed */ + for (int j = 0; j < 4 && frame->data[j]; j++) { + int shift = (j == 1 || j == 2) ? pd.v_shift_dst : 0; + memset(frame->data[j], 0, + frame->linesize[j] * (height >> shift)); + } + if (i) pd.frame_ref = frame; + else pd.frame_dst = frame; + } + + ret = ds_open(&dc, filename, 0); + if (ret < 0) { + fprintf(stderr, "Error opening the file\n"); + return ret; + } + + dc.process_frame = process_frame; + dc.opaque = &pd; + + ret = ds_run(&dc); + + av_frame_free(&pd.frame_dst); + av_frame_free(&pd.frame_ref); + sws_freeContext(pd.scaler); + ds_free(&dc); + return ret; +}