From patchwork Tue Oct 18 11:51:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 38775 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4a86:b0:9d:28a3:170e with SMTP id fn6csp2063304pzb; Tue, 18 Oct 2022 04:52:34 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6NPCxKsXgX7xi/c7fkFbKrF98FMWh9BbCeIW7O9bz2oaTz71WqrEFFgkc24UR2Wr2aJZtj X-Received: by 2002:a17:906:9bf8:b0:78d:41aa:5eea with SMTP id de56-20020a1709069bf800b0078d41aa5eeamr2005607ejc.137.1666093953464; Tue, 18 Oct 2022 04:52:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666093953; cv=none; d=google.com; s=arc-20160816; b=UTd2Yq5h+YB0BQUXfE9+0uGCp8E+mhewdqm7/NRJxXzuSVb18pYVc3AE67T1CEYbDI i0PbLzEw17mbccoqObYUNq21EO5sTza3HGi8BKm2St6q8SZgKzqwQFcRZ2iC1Yn/g+xB 7/IMpjda48sJhPbHgDnPUXnQElObk+2Zn1CnVeZy7jlsZwm4t4y5bgGzhtKYu5yBoF+T MtR+BONWb815zvKuaAA40MVg0IIDwlJf9WTCMwug597LXnZbqGlNP/xP7UdKuBWdy7NS o0X7WOkLMdoWjBWnJXf0gA1xD4bVvKiAcoiCXUCZQli1mlk8EAN5emVQe7j47VSRgVxR qBag== 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:message-id:date:to:from :delivered-to; bh=w5oJfcIHLhE5ZkU7ILhddUpvK9Y0TzdX//DaI7NkPmY=; b=jvlVXeSBG41SHm8O3SBmEhOZ8HHUVe6nmqVavRNJPBlLjfaGl4cYoukNPe6vy1DYlb +EYRd5Jnj1s4UFTRLxH02tIxqwcmbkjw8YLlv2eshaTizMh+K+uVDpLlW45wAJklt3zu cwwkXyXnR7ZxCkL1fJOYtugpIz4uI77GQ8Fc45UXRSoinCZokq7qfJrpeNMOjQKwFUMq 59Uz9VFbzSmmdhlA5YGN4fbELbTaLi/Pr7ryZ59sLhafymMgtzWYTc2zzPqpWVlR6bz5 J13ZJOmhLqwmx6D9qPpqJdGShBz4ncPQHFrcTNwbIZkDs/f1r2eGP6/q4NWy9zUyeDHA dxwQ== 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 t22-20020a1709067c1600b0078a76811e33si10018284ejo.408.2022.10.18.04.52.32; Tue, 18 Oct 2022 04:52:33 -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 3A42568BAFB; Tue, 18 Oct 2022 14:52:19 +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 1A17D68BBBF for ; Tue, 18 Oct 2022 14:52:11 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 2186D2404F7 for ; Tue, 18 Oct 2022 13:52:10 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id bM-5hqyPauW2 for ; Tue, 18 Oct 2022 13:52:09 +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 8B9652400F4 for ; Tue, 18 Oct 2022 13:52:09 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 7B4073A0212 for ; Tue, 18 Oct 2022 13:52:03 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 18 Oct 2022 13:51:57 +0200 Message-Id: <20221018115159.17780-1-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/3] tools/decode_simple: always call process_frame(NULL) at the end 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: WFymT5g6OOcf Currently this would not be done if max_frames is triggered. Makes no difference in either of the tools currently using decode_simple, but may be important in future tools. --- tools/decode_simple.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/decode_simple.c b/tools/decode_simple.c index b679fd7ce6..8dc3bd2054 100644 --- a/tools/decode_simple.c +++ b/tools/decode_simple.c @@ -73,7 +73,7 @@ int ds_run(DecodeContext *dc) while (ret >= 0) { ret = av_read_frame(dc->demuxer, dc->pkt); if (ret < 0) - goto flush; + break; if (dc->pkt->stream_index != dc->stream->index) { av_packet_unref(dc->pkt); continue; @@ -91,10 +91,9 @@ int ds_run(DecodeContext *dc) fprintf(stderr, "Error decoding: %d\n", ret); return ret; } else if (ret > 0) - return 0; + goto finish; } -flush: avcodec_send_packet(dc->decoder, NULL); ret = decode_read(dc, 1); if (ret < 0) { @@ -102,7 +101,8 @@ flush: return ret; } - return 0; +finish: + return dc->process_frame(dc, NULL); } void ds_free(DecodeContext *dc) From patchwork Tue Oct 18 11:51:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 38774 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4a86:b0:9d:28a3:170e with SMTP id fn6csp2063268pzb; Tue, 18 Oct 2022 04:52:23 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4APEW/wpD5lyAHSW+uQZrp6zBH6vDJINJu5OOWk65NtFEpc3Ee5wFTX/LR1UG4j5GDTsMC X-Received: by 2002:a05:6402:401e:b0:45c:a1ce:94bf with SMTP id d30-20020a056402401e00b0045ca1ce94bfmr2196058eda.177.1666093942837; Tue, 18 Oct 2022 04:52:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666093942; cv=none; d=google.com; s=arc-20160816; b=r+7z9jUCID/5ds59PNEY0TSmMFuk+Gai+8Jq28q5mAGmY/v7ye+VLsXgSNNwFEnU+W CVZMF1YqcwrZxoCL7daTU6wQhfLMn/iRGO+NbWWHAdYPppdsysueRo2D0iIwxcTCLlLz mTWoiHvoB5EfJ+zZFjmvhKSS5mq/xz2in1vrmg5mpDU8Z/n2JoLiLyqo+C0yr1XoIIjE RcVUYR0NZRPtsjj0BHVedCsPneg1ZkQoyqflHTYLpcSFUGBg+wBxHDisG/NFb/AYvjkf 5M8nnfz8jf6+M/yyLj6dL2kBvB8RCmCva0r5SLzqs5jD5x3BEOZwJmmLLim5ebRbG7y5 3szw== 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=vUBXyzrFhJKFNTD+0audQWLN4RyQvydHVBO5+91Ry1A=; b=npxhOFsD0NCvW7hV8+TYIBCYFzx7Zh6sFluLunIeUlq9KLTn5CMnRBuphVACoOKukU FNvBf/kvEBck6fKOUHP2ofaauu8+eqRkDmIq5e4gyqSbrQKJBOtKcHuU66qLVs8vMUi6 ZDCRrXKXvd8uWAHyuSh95+//1wv1d4rjzAloGwWe3GDHm4esHnSyXZ2IKQ8UikCFLkf/ ULrtI3QOICG01OThDdTdMR0tMr/A9V9BqvWr7tlfex6VqWxuxr04lLr5BDvBqdBezzLA VD16kfYV7K24NKgASW2D5HGy+ITcE2HNLgKgJEda9CeXWL44x+UCZSwT7EglTGA0hKPY ULRg== 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 e3-20020a17090658c300b0073d5a794b43si12404750ejs.985.2022.10.18.04.52.22; Tue, 18 Oct 2022 04:52:22 -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 2D9B568BD00; Tue, 18 Oct 2022 14:52:18 +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 1124668BB29 for ; Tue, 18 Oct 2022 14:52:11 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 3D2FD2400F4 for ; Tue, 18 Oct 2022 13:52:10 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id yS2FJLAw3OWh for ; Tue, 18 Oct 2022 13:52:09 +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 C84442404E4 for ; Tue, 18 Oct 2022 13:52:09 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 7CB833A0922 for ; Tue, 18 Oct 2022 13:52:03 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 18 Oct 2022 13:51:58 +0200 Message-Id: <20221018115159.17780-2-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221018115159.17780-1-anton@khirnov.net> References: <20221018115159.17780-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/3] tools/decode_simple: initialize decoder parameters with container info 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: zF00Ae6yUOgQ --- tools/decode_simple.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/decode_simple.c b/tools/decode_simple.c index 8dc3bd2054..cd81d53168 100644 --- a/tools/decode_simple.c +++ b/tools/decode_simple.c @@ -149,6 +149,10 @@ int ds_open(DecodeContext *dc, const char *url, int stream_idx) if (!dc->decoder) return AVERROR(ENOMEM); + ret = avcodec_parameters_to_context(dc->decoder, dc->stream->codecpar); + if (ret < 0) + goto fail; + return 0; fail: From patchwork Tue Oct 18 11:51:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 38776 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4a86:b0:9d:28a3:170e with SMTP id fn6csp2063365pzb; Tue, 18 Oct 2022 04:52:41 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5pQiaQutyh+jIoZiWmjcm5TxKlTOvFNJxp5I658uqJEILKThggMdfDCy549N4f5eioCNOY X-Received: by 2002:a17:907:8a09:b0:78d:b81e:f92f with SMTP id sc9-20020a1709078a0900b0078db81ef92fmr2184147ejc.620.1666093960898; Tue, 18 Oct 2022 04:52:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666093960; cv=none; d=google.com; s=arc-20160816; b=ZP8cXhwiOC8IERLa87ezRN9P0sJ1OeoGnQ/Cz3wNy+AHPOqzphpOZGVg2ZAv6qjSjc cxVfVNR5sIhbpSirA7dgwVC8HYn9BjZNzr5Q537QYQIuPq+orMdr0EDyQwBQhkO6linv wFFoI/xvGJ9A67wXdu2yTbbjfuVGqG0cqdcye62SteiAm+rBYZrqjNwuLu5cwR7wLhqA y5cy+udjc34pzbmYGSatmiqexnypKEZDSZjL6gleEdgppWjVEuAzBgLO5Ji5eyzxIOVc w14uSetryhTXB5YvFCsXgLgfJFGeNwwROMuvsF28h8t2aBlkFSS1qY/yFpLt0g7tBVQ6 YogA== 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=v55bp1q75dRvyL2HPT0coU6dIvSgGAc1XEvofCf5xAI=; b=IJC4XzjSRLKZEk4ZDq69np4ih4L24aCNWdMFnOIJAeSXcMilOH/LBNpOG03/SCa6Qm xcFEGRt4x/jK2UT5o6269EYQeVQq4Ki+YMWx+9ZM4O2rKP8eRFwiOgPZWathaAdNas9l 39+3O7pOkqaIH9un+22PEc/1o88GKd6N4E1CExKVKspc9CtzeH6Ou1o5a0bwITpUfi0Z 4VGBZbtw6/7JOJQjyVJs9a2T1+s1HroL0oCcHyQlvawCLD/KHfKt6QjUQMeqWKP/FTPS Or8wtsqxl0dCqxNeEovzKs/dBLcY1E4tJE+Q5zi4yuQudJdNbLqXErfI0GSGupq98OSq Snkg== 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 cs20-20020a170906dc9400b0078d9db99a6bsi9837472ejc.444.2022.10.18.04.52.40; Tue, 18 Oct 2022 04:52:40 -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 2C9F468BD1E; Tue, 18 Oct 2022 14:52:20 +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 8707E68BBBF for ; Tue, 18 Oct 2022 14:52:11 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 1ED6F2404E4 for ; Tue, 18 Oct 2022 13:52:11 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id QMaqT15xSr3P for ; Tue, 18 Oct 2022 13:52:10 +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 CAB862404F5 for ; Tue, 18 Oct 2022 13:52:09 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 7E53C3A13D9 for ; Tue, 18 Oct 2022 13:52:03 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 18 Oct 2022 13:51:59 +0200 Message-Id: <20221018115159.17780-3-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221018115159.17780-1-anton@khirnov.net> References: <20221018115159.17780-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/3] tools: add an AV_CODEC_CAP_ENCODER_RECON_FRAME test tool 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: SZNMCZSakPno --- Makefile | 2 + tools/Makefile | 3 +- tools/enc_recon_frame_test.c | 388 +++++++++++++++++++++++++++++++++++ 3 files changed, 392 insertions(+), 1 deletion(-) create mode 100644 tools/enc_recon_frame_test.c diff --git a/Makefile b/Makefile index 1fb742f390..bf1b69f96b 100644 --- a/Makefile +++ b/Makefile @@ -67,6 +67,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/enc_recon_frame_test$(EXESUF): $(FF_DEP_LIBS) +tools/enc_recon_frame_test$(EXESUF): ELIBS = $(FF_EXTRALIBS) tools/scale_slice_test$(EXESUF): $(FF_DEP_LIBS) tools/scale_slice_test$(EXESUF): ELIBS = $(FF_EXTRALIBS) tools/sofa2wavs$(EXESUF): ELIBS = $(FF_EXTRALIBS) diff --git a/tools/Makefile b/tools/Makefile index 4afa23342d..dee6a41668 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -1,4 +1,4 @@ -TOOLS = enum_options qt-faststart scale_slice_test trasher uncoded_frame +TOOLS = enc_recon_frame_test enum_options qt-faststart scale_slice_test trasher uncoded_frame TOOLS-$(CONFIG_LIBMYSOFA) += sofa2wavs TOOLS-$(CONFIG_ZLIB) += cws2fws @@ -17,6 +17,7 @@ tools/target_dem_fuzzer.o: tools/target_dem_fuzzer.c tools/target_io_dem_fuzzer.o: tools/target_dem_fuzzer.c $(COMPILE_C) -DIO_FLAT=0 +tools/enc_recon_frame_test$(EXESUF): tools/decode_simple.o tools/venc_data_dump$(EXESUF): tools/decode_simple.o tools/scale_slice_test$(EXESUF): tools/decode_simple.o diff --git a/tools/enc_recon_frame_test.c b/tools/enc_recon_frame_test.c new file mode 100644 index 0000000000..0d3b8e88e3 --- /dev/null +++ b/tools/enc_recon_frame_test.c @@ -0,0 +1,388 @@ +/* + * copyright (c) 2022 Anton Khirnov + * + * 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 + */ + +/* A test for AV_CODEC_FLAG_RECON_FRAME + * TODO: dump reconstructed frames to disk */ + +#include +#include +#include + +#include "decode_simple.h" + +#include "libavutil/adler32.h" +#include "libavutil/common.h" +#include "libavutil/error.h" +#include "libavutil/frame.h" +#include "libavutil/imgutils.h" +#include "libavutil/opt.h" + +#include "libavformat/avformat.h" + +#include "libavcodec/avcodec.h" +#include "libavcodec/codec.h" + +#include "libswscale/swscale.h" + +typedef struct FrameChecksum { + int64_t ts; + uint32_t checksum[4]; +} FrameChecksum; + +typedef struct PrivData { + AVCodecContext *enc; + AVCodecContext *dec; + + AVPacket *pkt; + AVFrame *frame, *frame_recon; + + struct SwsContext *scaler; + + FrameChecksum *checksums_decoded; + size_t nb_checksums_decoded; + FrameChecksum *checksums_recon; + size_t nb_checksums_recon; + + int dump; +} PrivData; + +static int frame_hash(FrameChecksum **pc, size_t *nb_c, int64_t ts, + const AVFrame *frame) +{ + FrameChecksum *c; + int shift_h, shift_v; + + c = av_realloc_array(*pc, *nb_c + 1, sizeof(*c)); + if (!c) + return AVERROR(ENOMEM); + *pc = c; + (*nb_c)++; + + c += *nb_c - 1; + memset(c, 0, sizeof(*c)); + + av_pix_fmt_get_chroma_sub_sample(frame->format, &shift_h, &shift_v); + + c->ts = ts; + for (int p = 0; frame->data[p]; p++) { + const uint8_t *data = frame->data[p]; + int linesize = av_image_get_linesize(frame->format, frame->width, p); + uint32_t checksum = 0; + + for (int j = 0; j < frame->height >> shift_v; j++) { + checksum = av_adler32_update(checksum, data, linesize); + data += frame->linesize[p]; + } + + c->checksum[p] = checksum; + } + + return 0; +} + +static int recon_frame_process(PrivData *pd, const AVPacket *pkt) +{ + AVFrame *f = pd->frame_recon; + int ret; + + ret = avcodec_receive_frame(pd->enc, f); + if (ret < 0) { + fprintf(stderr, "Error retrieving a reconstructed frame\n"); + return ret; + } + + if (pd->dump) { + } + + // the encoder's internal format (in which the reconsturcted frames are + // exported) may be different from the user-facing pixel format + if (f->format != pd->enc->pix_fmt) { + if (!pd->scaler) { + pd->scaler = sws_getContext(f->width, f->height, f->format, + f->width, f->height, pd->enc->pix_fmt, + SWS_BITEXACT, NULL, NULL, NULL); + if (!pd->scaler) + return AVERROR(ENOMEM); + } + + ret = sws_scale_frame(pd->scaler, pd->frame, f); + if (ret < 0) { + fprintf(stderr, "Error converting pixel formats\n"); + return ret; + } + + av_frame_unref(f); + f = pd->frame; + } + + ret = frame_hash(&pd->checksums_recon, &pd->nb_checksums_recon, + pkt->pts, f); + av_frame_unref(f); + + return 0; +} + +static int process_frame(DecodeContext *dc, AVFrame *frame) +{ + PrivData *pd = dc->opaque; + int ret; + + if (!avcodec_is_open(pd->enc)) { + if (!frame) { + fprintf(stderr, "No frames were decoded\n"); + return AVERROR_INVALIDDATA; + } + + pd->enc->width = frame->width; + pd->enc->height = frame->height; + pd->enc->pix_fmt = frame->format; + pd->enc->time_base = dc->stream->time_base; + pd->enc->thread_count = dc->decoder->thread_count; + pd->enc->thread_type = dc->decoder->thread_type; + + ret = avcodec_open2(pd->enc, NULL, NULL); + if (ret < 0) { + fprintf(stderr, "Error opening the encoder\n"); + return ret; + } + } + + if (frame) + frame->pict_type = AV_PICTURE_TYPE_NONE; + + ret = avcodec_send_frame(pd->enc, frame); + if (ret < 0) { + fprintf(stderr, "Error submitting a frame for encoding\n"); + return ret; + } + + while (1) { + AVPacket *pkt = pd->pkt; + + ret = avcodec_receive_packet(pd->enc, pkt); + if (ret == AVERROR(EAGAIN)) + break; + else if (ret == AVERROR_EOF) + pkt = NULL; + else if (ret < 0 && ret != AVERROR_EOF) { + fprintf(stderr, "Error receiving a frame from the encoder\n"); + return ret; + } + + if (pkt) { + ret = recon_frame_process(pd, pkt); + if (ret < 0) + return ret; + } + + if (!avcodec_is_open(pd->dec)) { + if (!pkt) { + fprintf(stderr, "No packets were received from the encoder\n"); + return AVERROR(EINVAL); + } + + pd->dec->width = pd->enc->width; + pd->dec->height = pd->enc->height; + pd->dec->pix_fmt = pd->enc->pix_fmt; + pd->dec->thread_count = dc->decoder->thread_count; + pd->dec->thread_type = dc->decoder->thread_type; + if (pd->enc->extradata_size) { + pd->dec->extradata = av_memdup(pd->enc->extradata, + pd->enc->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE); + if (!pd->dec->extradata) + return AVERROR(ENOMEM); + } + + ret = avcodec_open2(pd->dec, NULL, NULL); + if (ret < 0) { + fprintf(stderr, "Error opening the decoder\n"); + return ret; + } + } + + ret = avcodec_send_packet(pd->dec, pkt); + if (ret < 0) { + fprintf(stderr, "Error sending a frame to decoder\n"); + return ret; + } + + while (1) { + ret = avcodec_receive_frame(pd->dec, pd->frame); + if (ret == AVERROR(EAGAIN)) + break; + else if (ret == AVERROR_EOF) + return 0; + else if (ret < 0) { + fprintf(stderr, "Error receving a frame from decoder\n"); + return ret; + } + + ret = frame_hash(&pd->checksums_decoded, &pd->nb_checksums_decoded, + pd->frame->pts, pd->frame); + av_frame_unref(pd->frame); + if (ret < 0) + return ret; + } + + } + + return 0; +} + +static int frame_checksum_compare(const void *a, const void *b) +{ + const FrameChecksum *ca = a; + const FrameChecksum *cb = b; + if (ca->ts == cb->ts) + return 0; + return FFSIGN(ca->ts - cb->ts); +} + +int main(int argc, char **argv) +{ + PrivData pd; + DecodeContext dc; + + const char *filename, *enc_name, *enc_opts, *thread_type = NULL, *nb_threads = NULL; + const AVCodec *enc, *dec; + int ret = 0, max_frames = 0, dump = 0; + + if (argc <= 4) { + fprintf(stderr, + "Usage: %s " + "[ ]\n", argv[0]); + return 0; + } + + filename = argv[1]; + enc_name = argv[2]; + enc_opts = argv[3]; + max_frames = strtol(argv[4], NULL, 0); + if (argc >= 6) + nb_threads = argv[5]; + if (argc >= 7) + thread_type = argv[6]; + if (argc >= 8) + dump = strtol(argv[7], NULL, 0); + + memset(&dc, 0, sizeof(dc)); + memset(&pd, 0, sizeof(pd)); + + pd.dump = dump; + + enc = avcodec_find_encoder_by_name(enc_name); + if (!enc) { + fprintf(stderr, "No such encoder: %s\n", enc_name); + return 1; + } + if (!(enc->capabilities & AV_CODEC_CAP_ENCODER_RECON_FRAME)) { + fprintf(stderr, "Encoder '%s' cannot ouput reconstructed frames\n", + enc->name); + return 1; + } + + dec = avcodec_find_decoder(enc->id); + if (!dec) { + fprintf(stderr, "No decoder for: %s\n", avcodec_get_name(enc->id)); + return 1; + } + + pd.enc = avcodec_alloc_context3(enc); + if (!pd.enc) { + fprintf(stderr, "Error allocating encoder\n"); + return 1; + } + + ret = av_set_options_string(pd.enc, enc_opts, "=", ","); + if (ret < 0) { + fprintf(stderr, "Error setting encoder options\n"); + goto fail; + } + pd.enc->flags |= AV_CODEC_FLAG_RECON_FRAME | AV_CODEC_FLAG_BITEXACT; + + pd.dec = avcodec_alloc_context3(dec); + if (!pd.dec) { + fprintf(stderr, "Error allocating decoder\n"); + goto fail; + } + + pd.dec->flags |= AV_CODEC_FLAG_BITEXACT; + + pd.frame = av_frame_alloc(); + pd.frame_recon = av_frame_alloc(); + pd.pkt = av_packet_alloc(); + if (!pd.frame ||!pd.frame_recon || !pd.pkt) { + ret = 1; + goto fail; + } + + ret = ds_open(&dc, filename, 0); + if (ret < 0) { + fprintf(stderr, "Error opening the file\n"); + goto fail; + } + + dc.process_frame = process_frame; + dc.opaque = &pd; + dc.max_frames = max_frames; + + ret = av_dict_set(&dc.decoder_opts, "threads", nb_threads, 0); + ret |= av_dict_set(&dc.decoder_opts, "thread_type", thread_type, 0); + + ret = ds_run(&dc); + if (ret < 0) + goto fail; + + if (pd.nb_checksums_decoded != pd.nb_checksums_recon) { + fprintf(stderr, "Mismatching frame counts: recon=%zu decoded=%zu\n", + pd.nb_checksums_recon, pd.nb_checksums_decoded); + ret = 1; + goto fail; + } + + // reconstructed frames are in coded order, sort them by pts into presentation order + qsort(pd.checksums_recon, pd.nb_checksums_recon, sizeof(*pd.checksums_recon), + frame_checksum_compare); + + for (size_t i = 0; i < pd.nb_checksums_decoded; i++) { + const FrameChecksum *d = &pd.checksums_decoded[i]; + const FrameChecksum *r = &pd.checksums_recon[i]; + + for (int p = 0; p < FF_ARRAY_ELEMS(d->checksum); p++) + if (d->checksum[p] != r->checksum[p]) { + fprintf(stderr, "Checksum mismatch in frame ts=%"PRId64", plane %d\n", + d->ts, p); + ret = 1; + goto fail; + } + } + fprintf(stderr, "All %zu encoded frames match\n", pd.nb_checksums_decoded); + +fail: + avcodec_free_context(&pd.enc); + avcodec_free_context(&pd.dec); + av_freep(&pd.checksums_decoded); + av_freep(&pd.checksums_recon); + av_frame_free(&pd.frame); + av_frame_free(&pd.frame_recon); + av_packet_free(&pd.pkt); + ds_free(&dc); + return !!ret; +}