From patchwork Fri Mar 5 16:33:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26150 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 048AE44AB0A for ; Fri, 5 Mar 2021 18:41:58 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5327D68ACF4; Fri, 5 Mar 2021 18:36:11 +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 C818468ACC9 for ; Fri, 5 Mar 2021 18:36:07 +0200 (EET) Received: by mail-qt1-f181.google.com with SMTP id v64so2169285qtd.5 for ; Fri, 05 Mar 2021 08:36:07 -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=5UXyPuTQBom6JYQZ4TQrKUZ5zB06Xd5Rt2QshgaALPE=; b=Cd2iU/w6Dr3VopSTQll8VclkkhomMwAsJBIIIPXrUw3AYhhglyHQUy0aFoAEsnZwSY mUoQ2/faPoGIgUWGW8Gh/P053gx5ebYaSBtei+HYZcYK9gp0hCsLaWZu5mf27O4piT5k 92I3bLcovW6fbrwM5P/kN+92hVX92GxcDdds46d8qVYDA/WOsGDUfL2v8b+y49u08/hp /x/avmxniEngO2f/HttuG5LMugHqcFUTAQ2Ivxj6/9npcvEQv18nkZJOXjPP5OnMQLyc V5yr4MoCIgimd5pM9wxYeWHVgIpfGRUFSV3ZErVMhVKklfM7f6jAfdc4rq4IOitLfAse sa+Q== 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=5UXyPuTQBom6JYQZ4TQrKUZ5zB06Xd5Rt2QshgaALPE=; b=aey309sesgzg0xYkOD2Q7+nkjANnK20bNElP89buU9vMHfP3sMUn1iIVsUs0nym+bZ TJq/HMqtvlcPAlQQbgccscvONkzImbAHjhsCQlk1UEXIWzZR2EJ60xieyQdunCVdyTdD FyMX3ThCsK0oaKUoM8XqV8vZOy3yaS+LFNFSQbdm1xwSHxyiQJ7K6ceIhcE646m2x3EO bG3EI6j9nU0ykNpNcx/R9qEt2cbyi/cHpPlkml2wMwU4otZzsW/bvNXM4egdTJcC2eBT 0GDJlVjjBj9uQf8oM4TFWHimiIMLgXjsLbkhRyR7jeyIup63c0aU2RJ8qrsA7ahPQvQM eDww== X-Gm-Message-State: AOAM532P0oq7SbIb1IGO2/BQX6pPXtFPeiQS9Eq6eyOLYFYbnZzAQBt2 BRK7O0XsH9a6Qc33yFgJQfmzQpM3XYqY1A== X-Google-Smtp-Source: ABdhPJz6ziVVqgD/kzWnO1oKb3MpO+NQFhStPeY8lc7AaDKwG0nd7V5M17eLQv/Wx17tWA/I4Eyb7A== X-Received: by 2002:ac8:a8f:: with SMTP id d15mr1987241qti.115.1614962166300; Fri, 05 Mar 2021 08:36:06 -0800 (PST) Received: from localhost.localdomain ([181.23.89.132]) by smtp.gmail.com with ESMTPSA id b10sm2168494qtt.23.2021.03.05.08.36.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 08:36:05 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Mar 2021 13:33:23 -0300 Message-Id: <20210305163339.63164-33-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 32/48] avformat/tests/movenc: 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 --- libavformat/tests/movenc.c | 81 ++++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 39 deletions(-) diff --git a/libavformat/tests/movenc.c b/libavformat/tests/movenc.c index 1d15d97ad9..04155dde76 100644 --- a/libavformat/tests/movenc.c +++ b/libavformat/tests/movenc.c @@ -56,6 +56,7 @@ int out_size; struct AVMD5* md5; uint8_t hash[HASH_SIZE]; +AVPacket *pkt; AVStream *video_st, *audio_st; int64_t audio_dts, video_dts; @@ -248,68 +249,67 @@ static void mux_frames(int n, int c) { int end_frames = frames + n; while (1) { - AVPacket pkt; uint8_t pktdata[8] = { 0 }; - av_init_packet(&pkt); + av_packet_unref(pkt); if (av_compare_ts(audio_dts, audio_st->time_base, video_dts, video_st->time_base) < 0) { - pkt.dts = pkt.pts = audio_dts; - pkt.stream_index = 1; - pkt.duration = audio_duration; + pkt->dts = pkt->pts = audio_dts; + pkt->stream_index = 1; + pkt->duration = audio_duration; audio_dts += audio_duration; } else { if (frames == end_frames) break; - pkt.dts = video_dts; - pkt.stream_index = 0; - pkt.duration = duration; + pkt->dts = video_dts; + pkt->stream_index = 0; + pkt->duration = duration; if ((frames % gop_size) == 0) { - pkt.flags |= AV_PKT_FLAG_KEY; + pkt->flags |= AV_PKT_FLAG_KEY; last_picture = AV_PICTURE_TYPE_I; - pkt.pts = pkt.dts + duration; - video_dts = pkt.pts; + pkt->pts = pkt->dts + duration; + video_dts = pkt->pts; } else { if (last_picture == AV_PICTURE_TYPE_P) { last_picture = AV_PICTURE_TYPE_B; - pkt.pts = pkt.dts; + pkt->pts = pkt->dts; video_dts = next_p_pts; } else { last_picture = AV_PICTURE_TYPE_P; if (((frames + 1) % gop_size) == 0) { - pkt.pts = pkt.dts + duration; - video_dts = pkt.pts; + pkt->pts = pkt->dts + duration; + video_dts = pkt->pts; } else { - next_p_pts = pkt.pts = pkt.dts + 2 * duration; + next_p_pts = pkt->pts = pkt->dts + 2 * duration; video_dts += duration; } } } if (!bframes) - pkt.pts = pkt.dts; + pkt->pts = pkt->dts; if (fake_pkt_duration) - pkt.duration = fake_pkt_duration; + pkt->duration = fake_pkt_duration; frames++; } if (clear_duration) - pkt.duration = 0; - AV_WB32(pktdata + 4, pkt.pts); - pkt.data = pktdata; - pkt.size = 8; + pkt->duration = 0; + AV_WB32(pktdata + 4, pkt->pts); + pkt->data = pktdata; + pkt->size = 8; if (skip_write) continue; - if (skip_write_audio && pkt.stream_index == 1) + if (skip_write_audio && pkt->stream_index == 1) continue; if (c) { - pkt.pts += (1LL<<32); - pkt.dts += (1LL<<32); + pkt->pts += (1LL<<32); + pkt->dts += (1LL<<32); } if (do_interleave) - av_interleaved_write_frame(ctx, &pkt); + av_interleaved_write_frame(ctx, pkt); else - av_write_frame(ctx, &pkt); + av_write_frame(ctx, pkt); } } @@ -327,19 +327,16 @@ static void skip_gops(int n) static void signal_init_ts(void) { - AVPacket pkt; - av_init_packet(&pkt); - pkt.size = 0; - pkt.data = NULL; - - pkt.stream_index = 0; - pkt.dts = video_dts; - pkt.pts = 0; - av_write_frame(ctx, &pkt); - - pkt.stream_index = 1; - pkt.dts = pkt.pts = audio_dts; - av_write_frame(ctx, &pkt); + av_packet_unref(pkt); + + pkt->stream_index = 0; + pkt->dts = video_dts; + pkt->pts = 0; + av_write_frame(ctx, pkt); + + pkt->stream_index = 1; + pkt->dts = pkt->pts = audio_dts; + av_write_frame(ctx, pkt); } static void finish(void) @@ -382,6 +379,11 @@ int main(int argc, char **argv) md5 = av_md5_alloc(); if (!md5) return 1; + pkt = av_packet_alloc(); + if (!pkt) { + av_free(md5); + return 1; + } // Write a fragmented file with an initial moov that actually contains some // samples. One moov+mdat with 1 second of data and one moof+mdat with 1 @@ -786,6 +788,7 @@ int main(int argc, char **argv) close_out(); av_free(md5); + av_packet_free(&pkt); return check_faults > 0 ? 1 : 0; }