From patchwork Wed Feb 24 10:04:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 25942 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 3D45044B9E9 for ; Wed, 24 Feb 2021 12:04:14 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2D8F768A8E2; Wed, 24 Feb 2021 12:04:14 +0200 (EET) 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 B812868A646 for ; Wed, 24 Feb 2021 12:04:05 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 42F66240693 for ; Wed, 24 Feb 2021 11:04:05 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id njWC4_tsE0Je for ; Wed, 24 Feb 2021 11:04:04 +0100 (CET) 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 6A153240684 for ; Wed, 24 Feb 2021 11:04:04 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id 2F0043A01F3; Wed, 24 Feb 2021 11:04:04 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 24 Feb 2021 11:04:00 +0100 Message-Id: <20210224100402.22300-3-anton@khirnov.net> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20210224100402.22300-1-anton@khirnov.net> References: <20210224100402.22300-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/5] tests/api-flac-test: convert to new encoding/decoding API 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" --- tests/api/api-flac-test.c | 40 +++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/tests/api/api-flac-test.c b/tests/api/api-flac-test.c index 7c96a4d99e..3d83c56987 100644 --- a/tests/api/api-flac-test.c +++ b/tests/api/api-flac-test.c @@ -113,7 +113,6 @@ static int run_test(AVCodec *enc, AVCodec *dec, AVCodecContext *enc_ctx, uint8_t *raw_in = NULL, *raw_out = NULL; int in_offset = 0, out_offset = 0; int result = 0; - int got_output = 0; int i = 0; int in_frame_bytes, out_frame_bytes; @@ -167,25 +166,40 @@ static int run_test(AVCodec *enc, AVCodec *dec, AVCodecContext *enc_ctx, } memcpy(raw_in + in_offset, in_frame->data[0], in_frame_bytes); in_offset += in_frame_bytes; - result = avcodec_encode_audio2(enc_ctx, &enc_pkt, in_frame, &got_output); + result = avcodec_send_frame(enc_ctx, in_frame); if (result < 0) { - av_log(NULL, AV_LOG_ERROR, "Error encoding audio frame\n"); + av_log(NULL, AV_LOG_ERROR, "Error submitting a frame for encoding\n"); return result; } - /* if we get an encoded packet, feed it straight to the decoder */ - if (got_output) { - result = avcodec_decode_audio4(dec_ctx, out_frame, &got_output, &enc_pkt); + while (result >= 0) { + result = avcodec_receive_packet(enc_ctx, &enc_pkt); + if (result == AVERROR(EAGAIN)) + break; + else if (result < 0 && result != AVERROR_EOF) { + av_log(NULL, AV_LOG_ERROR, "Error encoding audio frame\n"); + return result; + } + + /* if we get an encoded packet, feed it straight to the decoder */ + result = avcodec_send_packet(dec_ctx, &enc_pkt); + av_packet_unref(&enc_pkt); if (result < 0) { - av_log(NULL, AV_LOG_ERROR, "Error decoding audio packet\n"); + av_log(NULL, AV_LOG_ERROR, "Error submitting a packet for decoding\n"); return result; } - if (got_output) { - if (result != enc_pkt.size) { - av_log(NULL, AV_LOG_INFO, "Decoder consumed only part of a packet, it is allowed to do so -- need to update this test\n"); - return AVERROR_UNKNOWN; - } + result = avcodec_receive_frame(dec_ctx, out_frame); + if (result == AVERROR(EAGAIN)) { + result = 0; + continue; + } else if (result == AVERROR(EOF)) { + result = 0; + break; + } else if (result < 0) { + av_log(NULL, AV_LOG_ERROR, "Error decoding audio packet\n"); + return result; + } if (in_frame->nb_samples != out_frame->nb_samples) { av_log(NULL, AV_LOG_ERROR, "Error frames before and after decoding has different number of samples\n"); @@ -208,9 +222,7 @@ static int run_test(AVCodec *enc, AVCodec *dec, AVCodecContext *enc_ctx, } memcpy(raw_out + out_offset, out_frame->data[0], out_frame_bytes); out_offset += out_frame_bytes; - } } - av_packet_unref(&enc_pkt); } if (memcmp(raw_in, raw_out, out_frame_bytes * NUMBER_OF_AUDIO_FRAMES) != 0) {