From patchwork Fri Mar 5 16:33:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26145 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 C47FE44BC31 for ; Fri, 5 Mar 2021 18:40:08 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3BB1368AC35; Fri, 5 Mar 2021 18:36:02 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.171]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5ACAB68AC14 for ; Fri, 5 Mar 2021 18:35:56 +0200 (EET) Received: by mail-qk1-f171.google.com with SMTP id t4so2584478qkp.1 for ; Fri, 05 Mar 2021 08:35:56 -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=DEs7rCCtQyBrvQhHReMK8Zml37Wb0Xs8mzdo4X8oH0g=; b=Qz76VanZWYPPnWWZOy2702azPk4ac55/MU77l9z2ybV55+tN6czqM6iHq0swt3DXLK GvegL0L9L7NSDuquH1EZHpKJcYd0PfKAhnheOAn1qkVH0euig8zniHgj+7J0tJ5O+5P4 Bk8yQdp1MVc+jlqGa7qE/AfZYvr9RCTef+I/oaiyekUnz1SuM/ECNjOOCOMyoE1tCH3k t1hCND3kWwchi/H+KLhXN9iaamIF1R1gTLbizcCMtpB+KvwnjdCNNOCjeXgj0vbGCFc3 7qiAv5BTSHK87yHdCEUhveEVak6F6cCNrP3ByX8zDXN8DKbT7bmqlI8bNWWCD06osqxH eHIw== 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=DEs7rCCtQyBrvQhHReMK8Zml37Wb0Xs8mzdo4X8oH0g=; b=VjM6orbNpAe2A5ky0zK7Lzu2mG60xDmHohpQ9UDfI8wGfB9Ain2F/iMzWwnV8zvibl UPxej2twIKFXg/s61LYAhav1m4xdMxbvDhyXLrudKPLPXgp97IpLMp0f4SbMF0sN71KS FPcfbGqjS0xQtR6lPnjIK5G6LIhliJ2uTYiExo1128nzmDKovCHVvUbfnhwoZum0ZUqf fn+xp7k/AjeE74A+GQ9hlbUJtoUdEooWpi14DAA6aG9Eeur6eZZOTjZDqzie1FniZmG+ fQvE0PlRI8EAiYrg8+O8imwuJFktQTbieaDT3HleLFx3jZZO6p+TfxmBhDcYwwyrDzXO XHwQ== X-Gm-Message-State: AOAM530ApufzuYBGA/D+WeYUu4DHBDmejujmz7gF/+9j8QFoUR0yUA3H HF8n8t2Jmk4IcVcKgsd290GHDFt4ZAG8sw== X-Google-Smtp-Source: ABdhPJybi7yaEQcBKocgJnI3LRBi2oTN18UqT4hTOhOb+WOxjHeo6p/fThlZudujLvTh8BS6afakMw== X-Received: by 2002:a37:8544:: with SMTP id h65mr9723599qkd.200.1614962154911; Fri, 05 Mar 2021 08:35:54 -0800 (PST) Received: from localhost.localdomain ([181.23.89.132]) by smtp.gmail.com with ESMTPSA id b10sm2168494qtt.23.2021.03.05.08.35.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 08:35:54 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Mar 2021 13:33:14 -0300 Message-Id: <20210305163339.63164-24-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 23/48] avformat/matroskaenc: 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/matroskaenc.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 367e05b36b..68e1426d00 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -137,7 +137,7 @@ typedef struct MatroskaMuxContext { mkv_cues cues; int64_t cues_pos; - AVPacket cur_audio_pkt; + AVPacket *cur_audio_pkt; unsigned nb_attachments; int have_video; @@ -451,7 +451,7 @@ static void mkv_deinit(AVFormatContext *s) { MatroskaMuxContext *mkv = s->priv_data; - av_packet_unref(&mkv->cur_audio_pkt); + av_packet_free(&mkv->cur_audio_pkt); ffio_free_dyn_buf(&mkv->cluster_bc); ffio_free_dyn_buf(&mkv->info.bc); @@ -1933,8 +1933,6 @@ static int mkv_write_header(AVFormatContext *s) mkv->reserve_cues_space = -1; } - av_init_packet(&mkv->cur_audio_pkt); - mkv->cur_audio_pkt.size = 0; mkv->cluster_pos = -1; // start a new cluster every 5 MB or 5 sec, or 32k / 1 sec for streaming or @@ -2428,9 +2426,9 @@ static int mkv_write_packet(AVFormatContext *s, const AVPacket *pkt) keyframe && (mkv->have_video ? codec_type == AVMEDIA_TYPE_VIDEO : 1) ? AVIO_DATA_MARKER_SYNC_POINT : AVIO_DATA_MARKER_BOUNDARY_POINT); // check if we have an audio packet cached - if (mkv->cur_audio_pkt.size > 0) { - ret = mkv_write_packet_internal(s, &mkv->cur_audio_pkt); - av_packet_unref(&mkv->cur_audio_pkt); + if (mkv->cur_audio_pkt->size > 0) { + ret = mkv_write_packet_internal(s, mkv->cur_audio_pkt); + av_packet_unref(mkv->cur_audio_pkt); if (ret < 0) { av_log(s, AV_LOG_ERROR, "Could not write cached audio packet ret:%d\n", ret); @@ -2442,7 +2440,7 @@ static int mkv_write_packet(AVFormatContext *s, const AVPacket *pkt) // keyframe's timecode is contained in the same cluster for WebM if (codec_type == AVMEDIA_TYPE_AUDIO) { if (pkt->size > 0) - ret = av_packet_ref(&mkv->cur_audio_pkt, pkt); + ret = av_packet_ref(mkv->cur_audio_pkt, pkt); } else ret = mkv_write_packet_internal(s, pkt); return ret; @@ -2474,8 +2472,8 @@ static int mkv_write_trailer(AVFormatContext *s) int ret, ret2 = 0; // check if we have an audio packet cached - if (mkv->cur_audio_pkt.size > 0) { - ret = mkv_write_packet_internal(s, &mkv->cur_audio_pkt); + if (mkv->cur_audio_pkt->size > 0) { + ret = mkv_write_packet_internal(s, mkv->cur_audio_pkt); if (ret < 0) { av_log(s, AV_LOG_ERROR, "Could not write cached audio packet ret:%d\n", ret); @@ -2699,6 +2697,9 @@ static int mkv_init(struct AVFormatContext *s) } else mkv->mode = MODE_MATROSKAv2; + mkv->cur_audio_pkt = av_packet_alloc(); + if (!mkv->cur_audio_pkt) + return AVERROR(ENOMEM); mkv->tracks = av_mallocz_array(s->nb_streams, sizeof(*mkv->tracks)); if (!mkv->tracks) return AVERROR(ENOMEM);