From patchwork Fri Mar 5 16:33:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26158 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 22BB544B46F for ; Fri, 5 Mar 2021 18:43:47 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4C27968AD97; Fri, 5 Mar 2021 18:36:22 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f180.google.com (mail-qt1-f180.google.com [209.85.160.180]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 02C7968AD86 for ; Fri, 5 Mar 2021 18:36:19 +0200 (EET) Received: by mail-qt1-f180.google.com with SMTP id j3so2125816qtj.12 for ; Fri, 05 Mar 2021 08:36:19 -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=Haz5vSSfsnBDPERI0LeFwXMwMbXEw1BHt8PPTj/1dko=; b=vJF7iWwuke88HYlfM4Xv0PAog96fCcIx9F3vU2M4EcSW4qHAp+iCz4kLB6BfC07KOE kPcgegFDdocE9B2jgohTF95TtwcK6jW0e76j6UxV30ki1CdR6RAsbcx5ouPs6R4HErv7 MrSimVc/e9j0EPP/GYUtHFnF5zLH5NMClwQzV+MhuiSAP/BNNcuUMPqSyhuNbeFG+TfX IQvQfSEm+OMtCuE9WLrpIAgipLxbbuv75gMvxi7/6luviL2V7tCHJunT55yaalx3XG2E +Azky1gz/rEonVx2xmG0p3L3H4csCjdDrLPeFJ3Z5bE3ycR9jE+vPFRb58twIG/c4w41 HPaA== 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=Haz5vSSfsnBDPERI0LeFwXMwMbXEw1BHt8PPTj/1dko=; b=M77XkEqXNnruNiAMHI028ufUaboxvxwzKOVhhfmL/2uTSUMWV6YkZzASh84AIlriuA EsZrnTKIWS6iI8o6+ByIOMEZuxJcda37QtxHUsotVntbbLBQtwAz3qrDh80audgskTDr yiKt8jlcU97tcWhaOWYnq93Q25nbkDVXgc9fSBUU+4geiHil4DI+n7A4evW7Q20MnsTY HQlv0qffiTa8YCJNDSVbj3fBY/1Xl3v0fCNVTCjBbZ1NV6+Sfrv+Vux3I5iPG+NiVK+n +j5qFHUSa4ch8Yy0dOCrDmdMwWgIFBcJrqeKq/5rN6lJk7jzLES6cGjXpTQXNQfFT6M3 ny0g== X-Gm-Message-State: AOAM531IhsHZ9c2LbkSsciqTCo5h7NgcCRX9p93zo++V8Hc4kgOVLVBU PESPSRjYWdGA1OKgZb7i8cmk9/IcOKjcYg== X-Google-Smtp-Source: ABdhPJxpVFZtpm5KVuuGRH157FBjF6ZLbL+t9sAub0B89CWqP/SFq2BtxowpPnycMmObstvwyNZwhg== X-Received: by 2002:ac8:578f:: with SMTP id v15mr9275813qta.172.1614962178617; Fri, 05 Mar 2021 08:36:18 -0800 (PST) Received: from localhost.localdomain ([181.23.89.132]) by smtp.gmail.com with ESMTPSA id b10sm2168494qtt.23.2021.03.05.08.36.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 08:36:18 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Mar 2021 13:33:33 -0300 Message-Id: <20210305163339.63164-43-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 42/48] doc/examples/demuxing_decoding: 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 --- doc/examples/demuxing_decoding.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/doc/examples/demuxing_decoding.c b/doc/examples/demuxing_decoding.c index 803e35d25c..db5e0cb951 100644 --- a/doc/examples/demuxing_decoding.c +++ b/doc/examples/demuxing_decoding.c @@ -51,7 +51,7 @@ static int video_dst_bufsize; static int video_stream_idx = -1, audio_stream_idx = -1; static AVFrame *frame = NULL; -static AVPacket pkt; +static AVPacket *pkt = NULL; static int video_frame_count = 0; static int audio_frame_count = 0; @@ -303,10 +303,12 @@ int main (int argc, char **argv) goto end; } - /* initialize packet, set data to NULL, let the demuxer fill it */ - av_init_packet(&pkt); - pkt.data = NULL; - pkt.size = 0; + pkt = av_packet_alloc(); + if (!pkt) { + fprintf(stderr, "Could not allocate packet\n"); + ret = AVERROR(ENOMEM); + goto end; + } if (video_stream) printf("Demuxing video from file '%s' into '%s'\n", src_filename, video_dst_filename); @@ -314,14 +316,14 @@ int main (int argc, char **argv) printf("Demuxing audio from file '%s' into '%s'\n", src_filename, audio_dst_filename); /* read frames from the file */ - while (av_read_frame(fmt_ctx, &pkt) >= 0) { + while (av_read_frame(fmt_ctx, pkt) >= 0) { // check if the packet belongs to a stream we are interested in, otherwise // skip it - if (pkt.stream_index == video_stream_idx) - ret = decode_packet(video_dec_ctx, &pkt); - else if (pkt.stream_index == audio_stream_idx) - ret = decode_packet(audio_dec_ctx, &pkt); - av_packet_unref(&pkt); + if (pkt->stream_index == video_stream_idx) + ret = decode_packet(video_dec_ctx, pkt); + else if (pkt->stream_index == audio_stream_idx) + ret = decode_packet(audio_dec_ctx, pkt); + av_packet_unref(pkt); if (ret < 0) break; } @@ -372,6 +374,7 @@ end: fclose(video_dst_file); if (audio_dst_file) fclose(audio_dst_file); + av_packet_free(&pkt); av_frame_free(&frame); av_free(video_dst_data[0]);