From patchwork Thu Feb 4 19:09:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 25428 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 6F8FF44A4AF for ; Thu, 4 Feb 2021 21:15:31 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EA3C1689D60; Thu, 4 Feb 2021 21:11:39 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8904468A9A1 for ; Thu, 4 Feb 2021 21:11:38 +0200 (EET) Received: by mail-qk1-f178.google.com with SMTP id 19so4466458qkh.3 for ; Thu, 04 Feb 2021 11:11:38 -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=3Sa4oN/lUQjwFNToLZERY0aef8jbU+Rjp7d2vFNYXao=; b=FoQc5QdjVPkphYpKt5lLqx/4YaLIKfinhdP8jKKZK0ylytFZduXGq0SQAiSOBqC3B+ 9CsaRqJZ0JBZ8bFDiE5HHTxaGuDkr6ylzH1bY84c/Qt1ZLIJ8r2NJpQ6fsBXbcizROyH nvWPOjwspumapdnK9OZ6rSWdgQ8O3t6I0mytqZHqNwWrgJFAqBvy8kZJdeBJ40m+dYgV kIXgQt8he+oKBVdTrW6D9+tt5K0ym91+VUC/gXnvdUfqBrAaeJvrBaJ9rpgpwVhAet0T zwU+3cycnLds/T6S0OssUQSdM+o3rA1Df7uVM4bxuPCSkvzkEMpLrhEf0LlySvjfpWts IBbQ== 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=3Sa4oN/lUQjwFNToLZERY0aef8jbU+Rjp7d2vFNYXao=; b=EqCcDtwDnLS5SADni5y3SdAVybM0YB9taQt+MqUyIZ0mYq5hiD4aO0gPCjPDAgrfAU LPrnggg/wX2DMgtzCacc646AhCqp0iUN3VOHYuy35CuE+rsCO4O7eQ7U37nWqSEoulX3 TiPzNtb95yI1NK64WjgUE4filSLNnDR/CuqXQA8guzHjpNON6xSya1mFa6hediyEJobm 9j1XH0oKS7CHz/xiqVKmJbkSXPLRowYj2FUjLpWvUOkAJ5R1BJ38DC/vwGPJI439SkBq CTtkQcv/okT3lT9oVzZ0JiSyZAieJw6/MUPr+xXQB7AtnlriMwnBuSenCKhkKzrCDbHz aufw== X-Gm-Message-State: AOAM53230bRIRwgeDQRzCry3Y9I8ax1AIJAKxjEVl07fXSnF3jLSy67o z2JkrxaR+KbjVYBW3dLtsrnLx0sSlnc= X-Google-Smtp-Source: ABdhPJw3Av4mLTBZZKAO6n11Z9qGUnOuRktxv8nbti6KqwP++0bclqkdDsa62oAhpWofaMmGsoC6og== X-Received: by 2002:a05:620a:12dc:: with SMTP id e28mr629568qkl.151.1612465897024; Thu, 04 Feb 2021 11:11:37 -0800 (PST) Received: from localhost.localdomain ([181.23.64.183]) by smtp.gmail.com with ESMTPSA id t14sm5889291qkt.50.2021.02.04.11.11.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Feb 2021 11:11:36 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Thu, 4 Feb 2021 16:09:48 -0300 Message-Id: <20210204191005.48190-34-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 33/50] 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; }