From patchwork Thu Feb 4 19:09:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 25433 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 D90B444A960 for ; Thu, 4 Feb 2021 21:17:10 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0FF6B68AA0D; Thu, 4 Feb 2021 21:11:53 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f178.google.com (mail-qt1-f178.google.com [209.85.160.178]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8A0CB68A9F0 for ; Thu, 4 Feb 2021 21:11:51 +0200 (EET) Received: by mail-qt1-f178.google.com with SMTP id x3so1325464qti.5 for ; Thu, 04 Feb 2021 11:11:51 -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=FugIgpisWWsFQKvL7hllFdazFwnGGyNzeyNhq1BRXiI=; b=hDxeVljaknpnkah8i+5BILPYwXXTua7V5nGisG1Cs2h+mwZKAPdoG2f8K727XOB+ME vzbqVS3Sp8otCjIDkKoG0s/gGvo81EvUzk+XHdZI+aVUga2va3W4uh/iKvxuFbhc3tgr IJH8LOWYeQxddAq48pD6k04DdBZ8lH5Q/AcwhT0OwbcTrBXpM2fGawCxICMafmxNbEEg 4ToDh6HW83ljQf9W10SyWfVWK2NgJ9DIS5PvM7eHgrAHx8iczqaoIQkCa+47opZpZoJ2 biDfEQbqBrGtgPM15UClzH1hp1uJ3CPRH3zdpyf9tpTX7I+1A6IUWxpP4mPW8FVMbxzS vyNg== 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=FugIgpisWWsFQKvL7hllFdazFwnGGyNzeyNhq1BRXiI=; b=iylCiKCJZ5F7pB3ggJXFB+K42sIkOrVlRpR7GApIWkJ1dk0YtPwJpMohn+/K1CMkLD F7v6pypCYxyHwDSuDEeCgE7GyL739cAJUAmn4ZXQVvadn4X/SKF6fdM8Lpjrz+GEs+ou OKnhpB7ygL3TQDTtz8lRpDqsra2AnlICYli/f7a+qZ2uAvL/wAxsVWXzc23sdEKWRouB 9l4AzV600Fg+Td5und+VaXHhZdTbwQdjyFqpT4QjZX1U2Mrgwax8r1Yz6FB20pnnDqZo p15mC/Iq8+Oi2eQxFskeWX6evjXelTUJwE03ZnOhTYdDcPV6mlwO7Jvwxv8DBUCcP5Eo F33A== X-Gm-Message-State: AOAM530Yzqiu9h13ysrKqkVluBJMLbkGTzIKqf1tS+CC3XWGw0RJo70w gd2zSdhDxTBVwxCd+uHSZIFPBYtghzQ= X-Google-Smtp-Source: ABdhPJz6+OsTtD22Vy8312Gkmu89oKCxpRWf5JkIowFaFI7eA7U7eRkba50FiOw9AkMPC9zcuajoQQ== X-Received: by 2002:aed:2802:: with SMTP id r2mr1112309qtd.76.1612465910067; Thu, 04 Feb 2021 11:11:50 -0800 (PST) Received: from localhost.localdomain ([181.23.64.183]) by smtp.gmail.com with ESMTPSA id t14sm5889291qkt.50.2021.02.04.11.11.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Feb 2021 11:11:49 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Thu, 4 Feb 2021 16:09:57 -0300 Message-Id: <20210204191005.48190-43-jamrial@gmail.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210204191005.48190-1-jamrial@gmail.com> References: <20210204191005.48190-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 42/50] 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 --- 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;