From patchwork Fri Mar 5 16:33:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26157 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 D7F9F44B46F for ; Fri, 5 Mar 2021 18:43:37 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A633368AD83; Fri, 5 Mar 2021 18:36:21 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f181.google.com (mail-qt1-f181.google.com [209.85.160.181]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E246E68AD65 for ; Fri, 5 Mar 2021 18:36:18 +0200 (EET) Received: by mail-qt1-f181.google.com with SMTP id b3so2141801qtj.10 for ; Fri, 05 Mar 2021 08:36:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=Rb7b0ojh0yLYaEyk9SeoeGO16M8ha4DCfuB50WnfIy8=; b=YWNf23EUcmQbbTRMDvIHSwATGsV1TXCha9gx1U4+RXxXMxWXeoNstMxyz9Tp3g9b5I GhkkjXMPXKJGTBhLAw76Rx/rljZex2cciIfKgtjpTi8cKorH/dSnZfZ7+UIwpU1x1Aqj gTmniMOyTdOZCxyNB36yagKdzBLE0Kiu0LKdX7XJPDWH5GiwCcVptrk3gz0mEfU+SAzw 7eYmMFKJjnnVQRobeW2WGxMT6agBdYTrS6ang8LFSqsSPcJeeGaHwyiF3QFGWxWCAkjf C18yWkFwT/1rRUz2Zm8c2nfZZUiAwxa6IoKQd5nlMajWeMw/renz+8Uf1rA5yqWDQ1v6 bUhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Rb7b0ojh0yLYaEyk9SeoeGO16M8ha4DCfuB50WnfIy8=; b=lSDgNTYeYJjwet3wDA5IMwwuET4/cpeEbigPLQEXqK0iQ1UNsKpk9jgkXMsDx/KNNJ KSZSYAb6Ahfc2CeClB9b+1YDOWyDmbhKZYiYrOB779JVovVh5zmdvgKn+8feT/GZvi0g PI8rTxX3R8bFO4mP1MznTxVJ8KxPRxlEEHvgLjU6TF0+nsuoKfUbQWNa5Xxw+xQahw3G KO4+DOv0Tok5uX5Ql2wDbv/HH83kB7wZjsFDvSnr7LPYy+Pvw7hhpZx+Miaeov8+v3KS r2yT8wdU4u7vfjnXwa7kMpsTzZlIzmgrak6v9s9VbUDROtKXcHyNQL/QPHWzxvUbCH67 /IQQ== X-Gm-Message-State: AOAM532VURkKibWsH9V9zL29lNMTSapjuzE6gm55FLI4o1rg4+Nb2Aqx JzGu5/qWuoqKUkiqv/WAQB7lyaa1pG2BIw== X-Google-Smtp-Source: ABdhPJxWaoeKvTrqc6BD0gSN0pYt/kngTZiRgYQEQlagUeNNOpwTgeZY+G79IS3cNl/2isaqUsJ95Q== X-Received: by 2002:ac8:7656:: with SMTP id i22mr9898057qtr.39.1614962177446; Fri, 05 Mar 2021 08:36:17 -0800 (PST) Received: from localhost.localdomain ([181.23.89.132]) by smtp.gmail.com with ESMTPSA id b10sm2168494qtt.23.2021.03.05.08.36.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 08:36:17 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Mar 2021 13:33:32 -0300 Message-Id: <20210305163339.63164-42-jamrial@gmail.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210305163339.63164-1-jamrial@gmail.com> References: <20210305163339.63164-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 41/48] tests/api/api-flac-test: use av_packet_alloc() to allocate packets 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" Signed-off-by: James Almer --- This patch conflicts with one by Anton, so i'll adapt it after he pushes his. tests/api/api-flac-test.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/tests/api/api-flac-test.c b/tests/api/api-flac-test.c index 3fea3258f3..4ce62ed8ba 100644 --- a/tests/api/api-flac-test.c +++ b/tests/api/api-flac-test.c @@ -108,7 +108,7 @@ static int init_decoder(AVCodec *dec, AVCodecContext **dec_ctx, static int run_test(AVCodec *enc, AVCodec *dec, AVCodecContext *enc_ctx, AVCodecContext *dec_ctx) { - AVPacket enc_pkt; + AVPacket *enc_pkt; AVFrame *in_frame, *out_frame; uint8_t *raw_in = NULL, *raw_out = NULL; int in_offset = 0, out_offset = 0; @@ -117,6 +117,12 @@ static int run_test(AVCodec *enc, AVCodec *dec, AVCodecContext *enc_ctx, int i = 0; int in_frame_bytes, out_frame_bytes; + enc_pkt = av_packet_alloc(); + if (!enc_pkt) { + av_log(NULL, AV_LOG_ERROR, "Can't allocate output packet\n"); + return AVERROR(ENOMEM); + } + in_frame = av_frame_alloc(); if (!in_frame) { av_log(NULL, AV_LOG_ERROR, "Can't allocate input frame\n"); @@ -150,10 +156,6 @@ static int run_test(AVCodec *enc, AVCodec *dec, AVCodecContext *enc_ctx, } for (i = 0; i < NUMBER_OF_AUDIO_FRAMES; i++) { - av_init_packet(&enc_pkt); - enc_pkt.data = NULL; - enc_pkt.size = 0; - generate_raw_frame((uint16_t*)(in_frame->data[0]), i, enc_ctx->sample_rate, enc_ctx->channels, enc_ctx->frame_size); in_frame_bytes = in_frame->nb_samples * in_frame->channels * sizeof(uint16_t); @@ -163,7 +165,7 @@ 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_encode_audio2(enc_ctx, enc_pkt, in_frame, &got_output); if (result < 0) { av_log(NULL, AV_LOG_ERROR, "Error encoding audio frame\n"); return result; @@ -171,14 +173,14 @@ static int run_test(AVCodec *enc, AVCodec *dec, AVCodecContext *enc_ctx, /* 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); + result = avcodec_decode_audio4(dec_ctx, out_frame, &got_output, enc_pkt); if (result < 0) { av_log(NULL, AV_LOG_ERROR, "Error decoding audio packet\n"); return result; } if (got_output) { - if (result != enc_pkt.size) { + 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; } @@ -206,7 +208,7 @@ static int run_test(AVCodec *enc, AVCodec *dec, AVCodecContext *enc_ctx, out_offset += out_frame_bytes; } } - av_packet_unref(&enc_pkt); + av_packet_unref(enc_pkt); } if (memcmp(raw_in, raw_out, out_frame_bytes * NUMBER_OF_AUDIO_FRAMES) != 0) { @@ -218,6 +220,7 @@ static int run_test(AVCodec *enc, AVCodec *dec, AVCodecContext *enc_ctx, av_freep(&raw_in); av_freep(&raw_out); + av_packet_free(&enc_pkt); av_frame_free(&in_frame); av_frame_free(&out_frame); return 0;