From patchwork Fri Mar 5 16:32:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26117 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 BB20744B9E2 for ; Fri, 5 Mar 2021 18:35:37 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A52A568A9F0; Fri, 5 Mar 2021 18:35:37 +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 C79C46880A8 for ; Fri, 5 Mar 2021 18:35:28 +0200 (EET) Received: by mail-qt1-f181.google.com with SMTP id h9so2154891qtq.7 for ; Fri, 05 Mar 2021 08:35:28 -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=KPCAzCv7CX18gECXmxph2zbITxYeZBapZ0ohO9NmAu0=; b=Tnyhns1O3yy8Eh/eCNJ2wrZrW3+5Vi/SOyoiLZ7hVWudSniIfUDqnpLo0ML9xudP3+ QOiyMXxkQ4kM1ROHF3mI5x1fEPMdnP+tblP79StYtbMh+ES9XPOtLp0Fgy6mKyWBJI3L c6bw4Ro1gFlb8+sVae0U5qEoUU1ecSS+AZkxu/o3XLeAn22LPcaXnNyJDYuqj8fixtky etIfI9nLbTZX2fh2etnBGrOY2oZiDD8B/jbHsstIXz28JCOpl1TAqrAJ4z1oKprssQEa 1ve3zVJVLCGHRvJOnfdmh3l843MAVO0L70nwwa/MUQ5PDQBPepBz/ngohHBNK1AtN4Jc TDaQ== 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=KPCAzCv7CX18gECXmxph2zbITxYeZBapZ0ohO9NmAu0=; b=STPxg7qx0Q5ZwaXOaMUsBg7CMWH8uXn19O1eyNx9TjwI2MjG+sdQXpMClUHkLWTCpE Mn87k0Iyt+jAeO+w5fzVl4fcKlZRZXgFxI/0GuCErniSRnQVMhkw+YqsCEemhocp7vPt pHmpzdcAdoGNmWk67vyBUsVdwWAVfI8Te8LPy28c+lnIgBeSUhyJKll+sOrL5NWDat3F yKBt2ce6R6CXxmw3Aw7f+mhjVFq/B8LLdPMnaCKLgG1SZUg9wzNx9DZz0HXSAeccmrlk xkcgHWgAOORLjCgVhI16/GntH8GhbMioy/I1e1TgCjSw27ni+DpHtD7gEdcx2HMgda2D tQ2w== X-Gm-Message-State: AOAM532R0P01/rmBNkpJZrvvY1C5GiKon8wA36nWPAEu+TDresb3NCmA kdK7XBq6RXuR639wFrmJFAVuX04HhXq09A== X-Google-Smtp-Source: ABdhPJz446LQBwzYWOiLNgAoCmdau5Gk1V9ZKJqq661JYk4Ub2OOas4hSrcDheMeasMEUoM1EL5wLw== X-Received: by 2002:aed:3165:: with SMTP id 92mr9661294qtg.233.1614962127166; Fri, 05 Mar 2021 08:35:27 -0800 (PST) Received: from localhost.localdomain ([181.23.89.132]) by smtp.gmail.com with ESMTPSA id b10sm2168494qtt.23.2021.03.05.08.35.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 08:35:26 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Mar 2021 13:32:52 -0300 Message-Id: <20210305163339.63164-2-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 01/48] avcodec/packet: deprecate av_init_packet() 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" Once removed, sizeof(AVPacket) will stop being a part of the public ABI. Signed-off-by: James Almer --- libavcodec/avpacket.c | 23 +++++++++++++++-------- libavcodec/packet.h | 22 ++++++++++++++++++---- libavcodec/version.h | 5 ++++- libavformat/avformat.h | 4 ++++ 4 files changed, 41 insertions(+), 13 deletions(-) diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c index e4ba403cf6..ae0cbfb9f9 100644 --- a/libavcodec/avpacket.c +++ b/libavcodec/avpacket.c @@ -32,6 +32,7 @@ #include "packet.h" #include "packet_internal.h" +#if FF_API_INIT_PACKET void av_init_packet(AVPacket *pkt) { pkt->pts = AV_NOPTS_VALUE; @@ -49,6 +50,16 @@ FF_ENABLE_DEPRECATION_WARNINGS pkt->side_data = NULL; pkt->side_data_elems = 0; } +#endif + +static void get_packet_defaults(AVPacket *pkt) +{ + memset(pkt, 0, sizeof(*pkt)); + + pkt->pts = AV_NOPTS_VALUE; + pkt->dts = AV_NOPTS_VALUE; + pkt->pos = -1; +} AVPacket *av_packet_alloc(void) { @@ -56,7 +67,7 @@ AVPacket *av_packet_alloc(void) if (!pkt) return pkt; - av_init_packet(pkt); + get_packet_defaults(pkt); return pkt; } @@ -92,7 +103,7 @@ int av_new_packet(AVPacket *pkt, int size) if (ret < 0) return ret; - av_init_packet(pkt); + get_packet_defaults(pkt); pkt->buf = buf; pkt->data = buf->data; pkt->size = size; @@ -607,9 +618,7 @@ void av_packet_unref(AVPacket *pkt) { av_packet_free_side_data(pkt); av_buffer_unref(&pkt->buf); - av_init_packet(pkt); - pkt->data = NULL; - pkt->size = 0; + get_packet_defaults(pkt); } int av_packet_ref(AVPacket *dst, const AVPacket *src) @@ -664,9 +673,7 @@ AVPacket *av_packet_clone(const AVPacket *src) void av_packet_move_ref(AVPacket *dst, AVPacket *src) { *dst = *src; - av_init_packet(src); - src->data = NULL; - src->size = 0; + get_packet_defaults(src); } int av_packet_make_refcounted(AVPacket *pkt) diff --git a/libavcodec/packet.h b/libavcodec/packet.h index b9d4c9c2c8..f07ca4936c 100644 --- a/libavcodec/packet.h +++ b/libavcodec/packet.h @@ -319,10 +319,6 @@ typedef struct AVPacketSideData { * packets, with no compressed data, containing only side data * (e.g. to update some stream parameters at the end of encoding). * - * AVPacket is one of the few structs in FFmpeg, whose size is a part of public - * ABI. Thus it may be allocated on stack and no new fields can be added to it - * without libavcodec and libavformat major bump. - * * The semantics of data ownership depends on the buf field. * If it is set, the packet data is dynamically allocated and is * valid indefinitely until a call to av_packet_unref() reduces the @@ -334,6 +330,12 @@ typedef struct AVPacketSideData { * The side data is always allocated with av_malloc(), copied by * av_packet_ref() and freed by av_packet_unref(). * + * sizeof(AVPacket) being a part of the public ABI is deprecated. once + * av_init_packet() is removed, new packets will only be able to be allocated + * with av_packet_alloc(), and new fields may be added to the end of the struct + * with a minor bump. + * + * @see av_packet_alloc * @see av_packet_ref * @see av_packet_unref */ @@ -393,10 +395,13 @@ typedef struct AVPacket { #endif } AVPacket; +#if FF_API_INIT_PACKET +attribute_deprecated typedef struct AVPacketList { AVPacket pkt; struct AVPacketList *next; } AVPacketList; +#endif #define AV_PKT_FLAG_KEY 0x0001 ///< The packet contains a keyframe #define AV_PKT_FLAG_CORRUPT 0x0002 ///< The packet content is corrupted @@ -460,6 +465,7 @@ AVPacket *av_packet_clone(const AVPacket *src); */ void av_packet_free(AVPacket **pkt); +#if FF_API_INIT_PACKET /** * Initialize optional fields of a packet with default values. * @@ -467,8 +473,16 @@ void av_packet_free(AVPacket **pkt); * initialized separately. * * @param pkt packet + * + * @see av_packet_alloc + * @see av_packet_unref + * + * @deprecated This function is deprecated. Once it's removed, + sizeof(AVPacket) will not be a part of the ABI anymore. */ +attribute_deprecated void av_init_packet(AVPacket *pkt); +#endif /** * Allocate the payload of a packet and initialize its fields with diff --git a/libavcodec/version.h b/libavcodec/version.h index 2b3757fa07..163dbc1cbf 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -28,7 +28,7 @@ #include "libavutil/version.h" #define LIBAVCODEC_VERSION_MAJOR 58 -#define LIBAVCODEC_VERSION_MINOR 128 +#define LIBAVCODEC_VERSION_MINOR 129 #define LIBAVCODEC_VERSION_MICRO 100 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ @@ -159,5 +159,8 @@ #ifndef FF_API_GET_FRAME_CLASS #define FF_API_GET_FRAME_CLASS (LIBAVCODEC_VERSION_MAJOR < 60) #endif +#ifndef FF_API_INIT_PACKET +#define FF_API_INIT_PACKET (LIBAVCODEC_VERSION_MAJOR < 60) +#endif #endif /* AVCODEC_VERSION_H */ diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 7da2f3d98e..783cc1b591 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -954,7 +954,11 @@ typedef struct AVStream { * decoding: set by libavformat, must not be modified by the caller. * encoding: unused */ +#if FF_API_INIT_PACKET AVPacket attached_pic; +#else + AVPacket *attached_pic; +#endif /** * An array of side data that applies to the whole stream (i.e. the From patchwork Fri Mar 5 16:32:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26118 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 DB07444B9E2 for ; Fri, 5 Mar 2021 18:35:38 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BC21568AA26; Fri, 5 Mar 2021 18:35:38 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f179.google.com (mail-qt1-f179.google.com [209.85.160.179]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8624068A7E9 for ; Fri, 5 Mar 2021 18:35:30 +0200 (EET) Received: by mail-qt1-f179.google.com with SMTP id r24so2145079qtt.8 for ; Fri, 05 Mar 2021 08:35:30 -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=5L6f8dtPEMJFLlaWo0t3pXue7S4NMLl4gqgygATw7Xo=; b=FupyJGV1YS1kuILObFtJZAIGVSvjKxj6H80l4S1Az6m5RVlIa2L38yIZgQznXeQSJQ c21DxrPP3kEn2iD69OarHzaYzDYCW+YUA/U1AYlO7OudVPodk1cbDLQEgisD0ocBNB/k jG8UYtXU7qlJZDeSL7Thva78XA1IbVPSjViTRsF1WH2+y7IhMejgaMASjvKZdAwRoq6c 3i4scE+MQ4uhIQf/VSt5bBI64tLOH1lQ6ayqbGi89uoQx2o5sa0tkgiFDCBimqaNpmPZ H52u1u31qRGvejPyOR8LzVcdmt2BxNwlI2DJc3F+uDbiSUj81sRgFUJPEqmzNN5H2VKh FCvQ== 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=5L6f8dtPEMJFLlaWo0t3pXue7S4NMLl4gqgygATw7Xo=; b=B7Di2xK48Y7qRwFJy0kl4wJpELVHAe61q01ok/Oa8fZP16tFuefmOGIiFRyW/PQvF/ OnRp+a20E0Dt2muWfsD6Ok/2il19fOmHslIfxQHBeIT1Xx8DM6LUN85O2VqXfQhPkn08 uQUqjiiOsjwGOVh6psJcFUk/tIRbl7+tVlL0ChO64C6Jfch9IxEpZgEBWCK/J1WgHt5R qOzzMaF8AVbi8Aj78xknW+KR2/tNR+wT50HbCns17XhhF38wNK7c7NB+/jq5xxFv8Bu+ v8q6N3Jyi0kBdBf0PaU+sklsmwzbeaURgcQKpi2zwaqhB31CU7+jyn4ZFBdee9XfK4XT RZwA== X-Gm-Message-State: AOAM531fu1FYaXaJLknZ3zdrexieu/acChe66YlsT28uBltNuKBjyfvK NhxI6NnGS+CDsZBBcxHq1r2qnjZ/U4EP8A== X-Google-Smtp-Source: ABdhPJy6sLEytw+N/S5sK66wdePd61E4nPn/amsnnSiw762VVwMjz/mVgeEGFOKTDoUxe0ZQS65xBA== X-Received: by 2002:a05:622a:552:: with SMTP id m18mr9793837qtx.207.1614962128526; Fri, 05 Mar 2021 08:35:28 -0800 (PST) Received: from localhost.localdomain ([181.23.89.132]) by smtp.gmail.com with ESMTPSA id b10sm2168494qtt.23.2021.03.05.08.35.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 08:35:28 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Mar 2021 13:32:53 -0300 Message-Id: <20210305163339.63164-3-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 02/48] avcodec/packet_internal: make avpriv_packet_list_* functions use an internal struct 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" The next pointer is kept at the end for backwards compatibility until the major bump, when it should be moved at the front. Signed-off-by: James Almer --- libavcodec/avpacket.c | 18 +++++++++--------- libavcodec/packet_internal.h | 10 +++++++--- libavdevice/decklink_common.h | 2 +- libavdevice/decklink_dec.cpp | 9 +++++---- libavdevice/dshow.c | 10 +++++----- libavdevice/dshow_capture.h | 3 ++- libavdevice/vfwcap.c | 13 +++++++------ libavformat/aiffenc.c | 4 ++-- libavformat/flacenc.c | 2 +- libavformat/internal.h | 14 +++++++------- libavformat/matroskadec.c | 4 ++-- libavformat/mp3enc.c | 2 +- libavformat/mux.c | 11 ++++++----- libavformat/mxfenc.c | 7 ++++--- libavformat/ttaenc.c | 2 +- libavformat/utils.c | 14 +++++++------- 16 files changed, 67 insertions(+), 58 deletions(-) diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c index ae0cbfb9f9..8c75c75f7b 100644 --- a/libavcodec/avpacket.c +++ b/libavcodec/avpacket.c @@ -733,13 +733,13 @@ FF_ENABLE_DEPRECATION_WARNINGS #endif } -int avpriv_packet_list_put(AVPacketList **packet_buffer, - AVPacketList **plast_pktl, +int avpriv_packet_list_put(PacketList **packet_buffer, + PacketList **plast_pktl, AVPacket *pkt, int (*copy)(AVPacket *dst, const AVPacket *src), int flags) { - AVPacketList *pktl = av_mallocz(sizeof(AVPacketList)); + PacketList *pktl = av_mallocz(sizeof(PacketList)); int ret; if (!pktl) @@ -770,11 +770,11 @@ int avpriv_packet_list_put(AVPacketList **packet_buffer, return 0; } -int avpriv_packet_list_get(AVPacketList **pkt_buffer, - AVPacketList **pkt_buffer_end, +int avpriv_packet_list_get(PacketList **pkt_buffer, + PacketList **pkt_buffer_end, AVPacket *pkt) { - AVPacketList *pktl; + PacketList *pktl; if (!*pkt_buffer) return AVERROR(EAGAIN); pktl = *pkt_buffer; @@ -786,12 +786,12 @@ int avpriv_packet_list_get(AVPacketList **pkt_buffer, return 0; } -void avpriv_packet_list_free(AVPacketList **pkt_buf, AVPacketList **pkt_buf_end) +void avpriv_packet_list_free(PacketList **pkt_buf, PacketList **pkt_buf_end) { - AVPacketList *tmp = *pkt_buf; + PacketList *tmp = *pkt_buf; while (tmp) { - AVPacketList *pktl = tmp; + PacketList *pktl = tmp; tmp = pktl->next; av_packet_unref(&pktl->pkt); av_freep(&pktl); diff --git a/libavcodec/packet_internal.h b/libavcodec/packet_internal.h index 832ddb4a61..b1d91f6347 100644 --- a/libavcodec/packet_internal.h +++ b/libavcodec/packet_internal.h @@ -23,6 +23,10 @@ #include "packet.h" +typedef struct PacketList { + AVPacket pkt; + struct PacketList *next; +} PacketList; /** * Append an AVPacket to the list. @@ -37,7 +41,7 @@ * @return 0 on success, negative AVERROR value on failure. On failure, the packet and the list are unchanged. */ -int avpriv_packet_list_put(AVPacketList **head, AVPacketList **tail, +int avpriv_packet_list_put(PacketList **head, PacketList **tail, AVPacket *pkt, int (*copy)(AVPacket *dst, const AVPacket *src), int flags); @@ -54,7 +58,7 @@ int avpriv_packet_list_put(AVPacketList **head, AVPacketList **tail, * @return 0 on success, and a packet is returned. AVERROR(EAGAIN) if * the list was empty. */ -int avpriv_packet_list_get(AVPacketList **head, AVPacketList **tail, +int avpriv_packet_list_get(PacketList **head, PacketList **tail, AVPacket *pkt); /** @@ -63,7 +67,7 @@ int avpriv_packet_list_get(AVPacketList **head, AVPacketList **tail, * @param head List head element * @param tail List tail element */ -void avpriv_packet_list_free(AVPacketList **head, AVPacketList **tail); +void avpriv_packet_list_free(PacketList **head, PacketList **tail); int ff_side_data_set_encoder_stats(AVPacket *pkt, int quality, int64_t *error, int error_count, int pict_type); diff --git a/libavdevice/decklink_common.h b/libavdevice/decklink_common.h index e49d9d54ad..6e032956a8 100644 --- a/libavdevice/decklink_common.h +++ b/libavdevice/decklink_common.h @@ -75,7 +75,7 @@ class decklink_output_callback; class decklink_input_callback; typedef struct AVPacketQueue { - AVPacketList *first_pkt, *last_pkt; + PacketList *first_pkt, *last_pkt; int nb_packets; unsigned long long size; int abort_request; diff --git a/libavdevice/decklink_dec.cpp b/libavdevice/decklink_dec.cpp index 4f8103e614..5acb2e8fbb 100644 --- a/libavdevice/decklink_dec.cpp +++ b/libavdevice/decklink_dec.cpp @@ -35,6 +35,7 @@ extern "C" { extern "C" { #include "config.h" +#include "libavcodec/packet_internal.h" #include "libavformat/avformat.h" #include "libavutil/avassert.h" #include "libavutil/avutil.h" @@ -481,7 +482,7 @@ static void avpacket_queue_init(AVFormatContext *avctx, AVPacketQueue *q) static void avpacket_queue_flush(AVPacketQueue *q) { - AVPacketList *pkt, *pkt1; + PacketList *pkt, *pkt1; pthread_mutex_lock(&q->mutex); for (pkt = q->first_pkt; pkt != NULL; pkt = pkt1) { @@ -514,7 +515,7 @@ static unsigned long long avpacket_queue_size(AVPacketQueue *q) static int avpacket_queue_put(AVPacketQueue *q, AVPacket *pkt) { - AVPacketList *pkt1; + PacketList *pkt1; // Drop Packet if queue size is > maximum queue size if (avpacket_queue_size(q) > (uint64_t)q->max_q_size) { @@ -528,7 +529,7 @@ static int avpacket_queue_put(AVPacketQueue *q, AVPacket *pkt) return -1; } - pkt1 = (AVPacketList *)av_malloc(sizeof(AVPacketList)); + pkt1 = (PacketList *)av_malloc(sizeof(PacketList)); if (!pkt1) { av_packet_unref(pkt); return -1; @@ -556,7 +557,7 @@ static int avpacket_queue_put(AVPacketQueue *q, AVPacket *pkt) static int avpacket_queue_get(AVPacketQueue *q, AVPacket *pkt, int block) { - AVPacketList *pkt1; + PacketList *pkt1; int ret; pthread_mutex_lock(&q->mutex); diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c index a16764d74c..73a9a48b20 100644 --- a/libavdevice/dshow.c +++ b/libavdevice/dshow.c @@ -58,7 +58,7 @@ static int dshow_read_close(AVFormatContext *s) { struct dshow_ctx *ctx = s->priv_data; - AVPacketList *pktl; + PacketList *pktl; if (ctx->control) { IMediaControl_Stop(ctx->control); @@ -118,7 +118,7 @@ dshow_read_close(AVFormatContext *s) pktl = ctx->pktl; while (pktl) { - AVPacketList *next = pktl->next; + PacketList *next = pktl->next; av_packet_unref(&pktl->pkt); av_free(pktl); pktl = next; @@ -162,7 +162,7 @@ callback(void *priv_data, int index, uint8_t *buf, int buf_size, int64_t time, e { AVFormatContext *s = priv_data; struct dshow_ctx *ctx = s->priv_data; - AVPacketList **ppktl, *pktl_next; + PacketList **ppktl, *pktl_next; // dump_videohdr(s, vdhdr); @@ -171,7 +171,7 @@ callback(void *priv_data, int index, uint8_t *buf, int buf_size, int64_t time, e if(shall_we_drop(s, index, devtype)) goto fail; - pktl_next = av_mallocz(sizeof(AVPacketList)); + pktl_next = av_mallocz(sizeof(PacketList)); if(!pktl_next) goto fail; @@ -1262,7 +1262,7 @@ static int dshow_check_event_queue(IMediaEvent *media_event) static int dshow_read_packet(AVFormatContext *s, AVPacket *pkt) { struct dshow_ctx *ctx = s->priv_data; - AVPacketList *pktl = NULL; + PacketList *pktl = NULL; while (!ctx->eof && !pktl) { WaitForSingleObject(ctx->mutex, INFINITE); diff --git a/libavdevice/dshow_capture.h b/libavdevice/dshow_capture.h index 710b65cc85..06ded2ba96 100644 --- a/libavdevice/dshow_capture.h +++ b/libavdevice/dshow_capture.h @@ -34,6 +34,7 @@ #include #include "libavcodec/internal.h" +#include "libavcodec/packet_internal.h" /* EC_DEVICE_LOST is not defined in MinGW dshow headers. */ #ifndef EC_DEVICE_LOST @@ -320,7 +321,7 @@ struct dshow_ctx { HANDLE mutex; HANDLE event[2]; /* event[0] is set by DirectShow * event[1] is set by callback() */ - AVPacketList *pktl; + PacketList *pktl; int eof; diff --git a/libavdevice/vfwcap.c b/libavdevice/vfwcap.c index e2ab276c2e..b3ef5f3448 100644 --- a/libavdevice/vfwcap.c +++ b/libavdevice/vfwcap.c @@ -24,6 +24,7 @@ #include "libavutil/opt.h" #include "libavutil/parseutils.h" +#include "libavcodec/packet_internal.h" #include "libavformat/internal.h" // windows.h must no be included before winsock2.h, and libavformat internal @@ -44,7 +45,7 @@ struct vfw_ctx { HWND hwnd; HANDLE mutex; HANDLE event; - AVPacketList *pktl; + PacketList *pktl; unsigned int curbufsize; unsigned int frame_num; char *video_size; /**< A string describing video size, set by a private option. */ @@ -178,7 +179,7 @@ static LRESULT CALLBACK videostream_cb(HWND hwnd, LPVIDEOHDR vdhdr) { AVFormatContext *s; struct vfw_ctx *ctx; - AVPacketList **ppktl, *pktl_next; + PacketList **ppktl, *pktl_next; s = (AVFormatContext *) GetWindowLongPtr(hwnd, GWLP_USERDATA); ctx = s->priv_data; @@ -190,7 +191,7 @@ static LRESULT CALLBACK videostream_cb(HWND hwnd, LPVIDEOHDR vdhdr) WaitForSingleObject(ctx->mutex, INFINITE); - pktl_next = av_mallocz(sizeof(AVPacketList)); + pktl_next = av_mallocz(sizeof(PacketList)); if(!pktl_next) goto fail; @@ -219,7 +220,7 @@ fail: static int vfw_read_close(AVFormatContext *s) { struct vfw_ctx *ctx = s->priv_data; - AVPacketList *pktl; + PacketList *pktl; if(ctx->hwnd) { SendMessage(ctx->hwnd, WM_CAP_SET_CALLBACK_VIDEOSTREAM, 0, 0); @@ -233,7 +234,7 @@ static int vfw_read_close(AVFormatContext *s) pktl = ctx->pktl; while (pktl) { - AVPacketList *next = pktl->next; + PacketList *next = pktl->next; av_packet_unref(&pktl->pkt); av_free(pktl); pktl = next; @@ -439,7 +440,7 @@ fail: static int vfw_read_packet(AVFormatContext *s, AVPacket *pkt) { struct vfw_ctx *ctx = s->priv_data; - AVPacketList *pktl = NULL; + PacketList *pktl = NULL; while(!pktl) { WaitForSingleObject(ctx->mutex, INFINITE); diff --git a/libavformat/aiffenc.c b/libavformat/aiffenc.c index 53a2f97e22..06e475cddb 100644 --- a/libavformat/aiffenc.c +++ b/libavformat/aiffenc.c @@ -37,7 +37,7 @@ typedef struct AIFFOutputContext { int64_t frames; int64_t ssnd; int audio_stream_idx; - AVPacketList *pict_list, *pict_list_end; + PacketList *pict_list, *pict_list_end; int write_id3v2; int id3v2_version; } AIFFOutputContext; @@ -48,7 +48,7 @@ static int put_id3v2_tags(AVFormatContext *s, AIFFOutputContext *aiff) uint64_t pos, end, size; ID3v2EncContext id3v2 = { 0 }; AVIOContext *pb = s->pb; - AVPacketList *pict_list = aiff->pict_list; + PacketList *pict_list = aiff->pict_list; if (!s->metadata && !s->nb_chapters && !aiff->pict_list) return 0; diff --git a/libavformat/flacenc.c b/libavformat/flacenc.c index 1c983486aa..ec9f4ab43e 100644 --- a/libavformat/flacenc.c +++ b/libavformat/flacenc.c @@ -39,7 +39,7 @@ typedef struct FlacMuxerContext { int audio_stream_idx; int waiting_pics; /* audio packets are queued here until we get all the attached pictures */ - AVPacketList *queue, *queue_end; + PacketList *queue, *queue_end; /* updated streaminfo sent by the encoder at the end */ uint8_t streaminfo[FLAC_STREAMINFO_SIZE]; diff --git a/libavformat/internal.h b/libavformat/internal.h index 0ffdc87b6a..e913d958fc 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -73,8 +73,8 @@ struct AVFormatInternal { * not decoded, for example to get the codec parameters in MPEG * streams. */ - struct AVPacketList *packet_buffer; - struct AVPacketList *packet_buffer_end; + struct PacketList *packet_buffer; + struct PacketList *packet_buffer_end; /* av_seek_frame() support */ int64_t data_offset; /**< offset of the first packet */ @@ -85,13 +85,13 @@ struct AVFormatInternal { * be identified, as parsing cannot be done without knowing the * codec. */ - struct AVPacketList *raw_packet_buffer; - struct AVPacketList *raw_packet_buffer_end; + struct PacketList *raw_packet_buffer; + struct PacketList *raw_packet_buffer_end; /** * Packets split by the parser get queued here. */ - struct AVPacketList *parse_queue; - struct AVPacketList *parse_queue_end; + struct PacketList *parse_queue; + struct PacketList *parse_queue_end; /** * Remaining size available for raw_packet_buffer, in bytes. */ @@ -347,7 +347,7 @@ struct AVStreamInternal { /** * last packet in packet_buffer for this stream when muxing. */ - struct AVPacketList *last_in_packet_buffer; + struct PacketList *last_in_packet_buffer; }; #ifdef __GNUC__ diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 25eca5825e..9a65774464 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -382,8 +382,8 @@ typedef struct MatroskaDemuxContext { int64_t segment_start; /* the packet queue */ - AVPacketList *queue; - AVPacketList *queue_end; + PacketList *queue; + PacketList *queue_end; int done; diff --git a/libavformat/mp3enc.c b/libavformat/mp3enc.c index 4f91c4f1c3..e939eb752f 100644 --- a/libavformat/mp3enc.c +++ b/libavformat/mp3enc.c @@ -132,7 +132,7 @@ typedef struct MP3Context { int pics_to_write; /* audio packets are queued here until we get all the attached pictures */ - AVPacketList *queue, *queue_end; + PacketList *queue, *queue_end; } MP3Context; static const uint8_t xing_offtbl[2][2] = {{32, 17}, {17, 9}}; diff --git a/libavformat/mux.c b/libavformat/mux.c index 062ba8d789..440113b149 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -22,6 +22,7 @@ #include "avformat.h" #include "internal.h" #include "libavcodec/internal.h" +#include "libavcodec/packet_internal.h" #include "libavutil/opt.h" #include "libavutil/dict.h" #include "libavutil/pixdesc.h" @@ -830,11 +831,11 @@ int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, int (*compare)(AVFormatContext *, const AVPacket *, const AVPacket *)) { int ret; - AVPacketList **next_point, *this_pktl; + PacketList **next_point, *this_pktl; AVStream *st = s->streams[pkt->stream_index]; int chunked = s->max_chunk_size || s->max_chunk_duration; - this_pktl = av_malloc(sizeof(AVPacketList)); + this_pktl = av_malloc(sizeof(PacketList)); if (!this_pktl) { av_packet_unref(pkt); return AVERROR(ENOMEM); @@ -931,7 +932,7 @@ static int interleave_compare_dts(AVFormatContext *s, const AVPacket *next, int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush) { - AVPacketList *pktl; + PacketList *pktl; int stream_count = 0; int noninterleaved_count = 0; int i, ret; @@ -968,7 +969,7 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, for (i = 0; i < s->nb_streams; i++) { int64_t last_dts; - const AVPacketList *last = s->streams[i]->internal->last_in_packet_buffer; + const PacketList *last = s->streams[i]->internal->last_in_packet_buffer; if (!last) continue; @@ -1064,7 +1065,7 @@ int ff_get_muxer_ts_offset(AVFormatContext *s, int stream_index, int64_t *offset const AVPacket *ff_interleaved_peek(AVFormatContext *s, int stream) { - AVPacketList *pktl = s->internal->packet_buffer; + PacketList *pktl = s->internal->packet_buffer; while (pktl) { if (pktl->pkt.stream_index == stream) { return &pktl->pkt; diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c index 1c668998e2..7a16bf9155 100644 --- a/libavformat/mxfenc.c +++ b/libavformat/mxfenc.c @@ -53,6 +53,7 @@ #include "libavcodec/h264_ps.h" #include "libavcodec/golomb.h" #include "libavcodec/internal.h" +#include "libavcodec/packet_internal.h" #include "avformat.h" #include "avio_internal.h" #include "internal.h" @@ -3104,9 +3105,9 @@ static int mxf_interleave_get_packet(AVFormatContext *s, AVPacket *out, AVPacket stream_count += !!s->streams[i]->internal->last_in_packet_buffer; if (stream_count && (s->nb_streams == stream_count || flush)) { - AVPacketList *pktl = s->internal->packet_buffer; + PacketList *pktl = s->internal->packet_buffer; if (s->nb_streams != stream_count) { - AVPacketList *last = NULL; + PacketList *last = NULL; // find last packet in edit unit while (pktl) { if (!stream_count || pktl->pkt.stream_index == 0) @@ -3120,7 +3121,7 @@ static int mxf_interleave_get_packet(AVFormatContext *s, AVPacket *out, AVPacket } // purge packet queue while (pktl) { - AVPacketList *next = pktl->next; + PacketList *next = pktl->next; av_packet_unref(&pktl->pkt); av_freep(&pktl); pktl = next; diff --git a/libavformat/ttaenc.c b/libavformat/ttaenc.c index 92f5053d52..32eb269040 100644 --- a/libavformat/ttaenc.c +++ b/libavformat/ttaenc.c @@ -30,7 +30,7 @@ typedef struct TTAMuxContext { AVIOContext *seek_table; - AVPacketList *queue, *queue_end; + PacketList *queue, *queue_end; uint32_t nb_samples; int frame_size; int last_frame; diff --git a/libavformat/utils.c b/libavformat/utils.c index 36164e0f0d..73b1a9b52c 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -812,7 +812,7 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt) av_init_packet(pkt); for (;;) { - AVPacketList *pktl = s->internal->raw_packet_buffer; + PacketList *pktl = s->internal->raw_packet_buffer; const AVPacket *pkt1; if (pktl) { @@ -1020,7 +1020,7 @@ static int has_decode_delay_been_guessed(AVStream *st) return st->internal->nb_decoded_frames >= 20; } -static AVPacketList *get_next_pkt(AVFormatContext *s, AVStream *st, AVPacketList *pktl) +static PacketList *get_next_pkt(AVFormatContext *s, AVStream *st, PacketList *pktl) { if (pktl->next) return pktl->next; @@ -1076,7 +1076,7 @@ static int64_t select_from_pts_buffer(AVStream *st, int64_t *pts_buffer, int64_t * of the packets in a window. */ static void update_dts_from_pts(AVFormatContext *s, int stream_index, - AVPacketList *pkt_buffer) + PacketList *pkt_buffer) { AVStream *st = s->streams[stream_index]; int delay = st->internal->avctx->has_b_frames; @@ -1105,8 +1105,8 @@ static void update_initial_timestamps(AVFormatContext *s, int stream_index, int64_t dts, int64_t pts, AVPacket *pkt) { AVStream *st = s->streams[stream_index]; - AVPacketList *pktl = s->internal->packet_buffer ? s->internal->packet_buffer : s->internal->parse_queue; - AVPacketList *pktl_it; + PacketList *pktl = s->internal->packet_buffer ? s->internal->packet_buffer : s->internal->parse_queue; + PacketList *pktl_it; uint64_t shift; @@ -1157,7 +1157,7 @@ static void update_initial_timestamps(AVFormatContext *s, int stream_index, static void update_initial_durations(AVFormatContext *s, AVStream *st, int stream_index, int64_t duration) { - AVPacketList *pktl = s->internal->packet_buffer ? s->internal->packet_buffer : s->internal->parse_queue; + PacketList *pktl = s->internal->packet_buffer ? s->internal->packet_buffer : s->internal->parse_queue; int64_t cur_dts = RELATIVE_TS_BASE; if (st->first_dts != AV_NOPTS_VALUE) { @@ -1742,7 +1742,7 @@ int av_read_frame(AVFormatContext *s, AVPacket *pkt) } for (;;) { - AVPacketList *pktl = s->internal->packet_buffer; + PacketList *pktl = s->internal->packet_buffer; if (pktl) { AVPacket *next_pkt = &pktl->pkt; From patchwork Fri Mar 5 16:32:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26119 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 1ACB344B9E2 for ; Fri, 5 Mar 2021 18:35:40 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F22FA68AA90; Fri, 5 Mar 2021 18:35:39 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qv1-f53.google.com (mail-qv1-f53.google.com [209.85.219.53]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 693E968A7E9 for ; Fri, 5 Mar 2021 18:35:31 +0200 (EET) Received: by mail-qv1-f53.google.com with SMTP id t1so1267528qvj.8 for ; Fri, 05 Mar 2021 08:35:31 -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=3DptBbuAl+WhhFwFgAbpEV/0NE7/PDxUNbZYZv326VM=; b=ckD5H5x7A1pPunRrfZZUq0bRVZELBV5ywBKeTMsy5Af2ha/vJB8eacbB3l3HJRfeIb HduvorFl/zTXucJlTk8Y8ht5YcYXrctGvWXcWhxC/Z6XBvykVbUcoOuORxzYSk8vbSUZ HufvM7eeZzrjvD4xUbzHp9blvCLOIPwtcwOXJBDk0I5QW4hk8nRdD5K6Z5kFAwy5yuxL MmQH5gfVc40n6daUwte1wVMdtKFatuz6l3XE/9USLhfLAR/OnceKRwlQQUjjwjAFbGYW kPz9yR4WIc7AKJGm7+J9uAengvgIpfUXyxUUON1mofJhgLcQoJPmr0KHt0pxOvlHEdD0 PZXg== 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=3DptBbuAl+WhhFwFgAbpEV/0NE7/PDxUNbZYZv326VM=; b=pdxFYQLj3GX7we+mRLg6UbeVEzj6PlRQ8zyr492p0K4seyW8p1h829mYvppjNZ/K4A ICWGob85/17GUZuxyShW/pb+O9zubPjJgZDaXa7BPeVli4mttAGwJ+lJR37hMsivyYkR KW/nJgcxjC01uZdVUzXAdxXmwqJQ/GsVBDIittmLU6kwGcmYwLleej6m9/JJszKayMyQ 91mdCJpDpQgH2eTRR/VHw5E8OVCRWo74bJG6PH0RM5xYfUEiiX73vUgX0+5kdrof1JRA IxV99oHt1qPxlgbNlZ3BqqRnwg07j8/xKhTxrx66woUBDBsxcFRwO7S0bQZhAeZW5/r0 NP/w== X-Gm-Message-State: AOAM532zqVacO9TbflOjf44QUC4TGSR4QIAAd40zDIFnPvU6NOJ69G9e mOg7uYc2jCFytwKlJrXshV7plik/YEKQ5A== X-Google-Smtp-Source: ABdhPJy68dmmViUAqVWe1CaHDhdtMpeo2+6qvvdUqKBI/CC6WfFOQbEg6R37aiG6J4JQDOBdkzlj7Q== X-Received: by 2002:a0c:b49f:: with SMTP id c31mr9686285qve.35.1614962129755; Fri, 05 Mar 2021 08:35:29 -0800 (PST) Received: from localhost.localdomain ([181.23.89.132]) by smtp.gmail.com with ESMTPSA id b10sm2168494qtt.23.2021.03.05.08.35.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 08:35:29 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Mar 2021 13:32:54 -0300 Message-Id: <20210305163339.63164-4-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 03/48] avcodec/cri: 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 --- libavcodec/cri.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/libavcodec/cri.c b/libavcodec/cri.c index 3312606b75..0558d0c8dd 100644 --- a/libavcodec/cri.c +++ b/libavcodec/cri.c @@ -37,6 +37,7 @@ typedef struct CRIContext { AVCodecContext *jpeg_avctx; // wrapper context for MJPEG + AVPacket *jpkt; // encoded JPEG tile AVFrame *jpgframe; // decoded JPEG tile GetByteContext gb; @@ -56,6 +57,10 @@ static av_cold int cri_decode_init(AVCodecContext *avctx) if (!s->jpgframe) return AVERROR(ENOMEM); + s->jpkt = av_packet_alloc(); + if (!s->jpkt) + return AVERROR(ENOMEM); + codec = avcodec_find_decoder(AV_CODEC_ID_MJPEG); if (!codec) return AVERROR_BUG; @@ -345,13 +350,11 @@ skip: unsigned offset = 0; for (int tile = 0; tile < 4; tile++) { - AVPacket jpkt; - - av_init_packet(&jpkt); - jpkt.data = (uint8_t *)s->data + offset; - jpkt.size = s->tile_size[tile]; + av_packet_unref(s->jpkt); + s->jpkt->data = (uint8_t *)s->data + offset; + s->jpkt->size = s->tile_size[tile]; - ret = avcodec_send_packet(s->jpeg_avctx, &jpkt); + ret = avcodec_send_packet(s->jpeg_avctx, s->jpkt); if (ret < 0) { av_log(avctx, AV_LOG_ERROR, "Error submitting a packet for decoding\n"); return ret; @@ -415,6 +418,7 @@ static av_cold int cri_decode_close(AVCodecContext *avctx) CRIContext *s = avctx->priv_data; av_frame_free(&s->jpgframe); + av_packet_free(&s->jpkt); avcodec_free_context(&s->jpeg_avctx); return 0; From patchwork Fri Mar 5 16:32:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26120 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 57D5644B9E2 for ; Fri, 5 Mar 2021 18:35:41 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 318D768AABC; Fri, 5 Mar 2021 18:35:41 +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 BE18068AA1F for ; Fri, 5 Mar 2021 18:35:32 +0200 (EET) Received: by mail-qk1-f178.google.com with SMTP id x10so2529580qkm.8 for ; Fri, 05 Mar 2021 08:35:32 -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=z4DjEnltZhekfX5ivbBKYJZqGUL/kJgSo/hDsV794js=; b=IYzILEJwj8ELo6BYtJqwT6uc2hwxvOnLqkqGh16ZPCnGb7uMED9RsGS5xE99ZoMbjl 3L+WPBXyZmx0OWb+gfuGHNuqbZSiW6ZWRqSdXc/8D0NlEtdVk81vNSF00OCecuiyEJIT X2cQQULqcmko4iyNxbmOECdHcMmD1sAmxCFki45exHOqP+l88oYi4IjAAvclyCLINv6i G315F3ReTcCuAk1jkJjBPMHPMyoOVcsVH8S5HBFFahMtXH+XoTNOjfhtMS0gEWu3UDoF 4pwHK2q+xvXG5EOykUsZ7ieLKODIeExCQoWdZ2LHKuMladoxgws47AotTEJincr3GWM1 AKbg== 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=z4DjEnltZhekfX5ivbBKYJZqGUL/kJgSo/hDsV794js=; b=XwZpq2IF0+OKnulWWCQyUqIOcJEmgqRHtL8VLWP4M0iMpGtc4mMeqkSzjG4xfI3Xoh oroAzK3nJZH0KQicwTsoSGT8LpKMvS8XwEfJW+d1tA6GfySvgg7xHFRI9awqjfrRdtUt vW1O6rIAujX8T8RyeHFirlS5XHCg8R+GSswSyEhQQRlLQwwYoe4gkXXqpvCe05yC5PXm Zsl/IrPuMxvuzwX/MXI47JZFhS2rqZj2kU6RiIKPSJbnX3+myevS/n8UHKV5eQVxSlkc ft4NODXkzS0Oh87xDZO7C3LHlNtqoLiBx14qKWqBW5++TtF+wfbou02p7KbK2pFQONc3 OyXw== X-Gm-Message-State: AOAM532MkKAumilKc69gviiCWfUH+yugZSWR/l5EO+VXe8q64oj6aUgF 7wiCqycY8DlINg+BTkps9yRNRi488cnMlw== X-Google-Smtp-Source: ABdhPJwX3eDc/A05/s7EkZSTceb2Pf0V/gHHsuaYIuyTBMks9RyCv708zYtN/IgAoJPEjg/XlcTxiA== X-Received: by 2002:a05:620a:4445:: with SMTP id w5mr9893102qkp.330.1614962131058; Fri, 05 Mar 2021 08:35:31 -0800 (PST) Received: from localhost.localdomain ([181.23.89.132]) by smtp.gmail.com with ESMTPSA id b10sm2168494qtt.23.2021.03.05.08.35.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 08:35:30 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Mar 2021 13:32:55 -0300 Message-Id: <20210305163339.63164-5-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 04/48] avcodec/mmal: 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 --- libavcodec/mmaldec.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/libavcodec/mmaldec.c b/libavcodec/mmaldec.c index cb15ac072a..ed51d74de5 100644 --- a/libavcodec/mmaldec.c +++ b/libavcodec/mmaldec.c @@ -776,12 +776,17 @@ static int ffmmal_decode(AVCodecContext *avctx, void *data, int *got_frame, int ret = 0; if (avctx->extradata_size && !ctx->extradata_sent) { - AVPacket pkt = {0}; - av_init_packet(&pkt); - pkt.data = avctx->extradata; - pkt.size = avctx->extradata_size; + AVPacket *pkt; + + pkt = av_packet_alloc(); + if (!pkt) + return AVERROR(ENOMEM); + pkt->data = avctx->extradata; + pkt->size = avctx->extradata_size; ctx->extradata_sent = 1; - if ((ret = ffmmal_add_packet(avctx, &pkt, 1)) < 0) + ret = ffmmal_add_packet(avctx, pkt, 1); + av_packet_free(&pkt); + if (ret < 0) return ret; } From patchwork Fri Mar 5 16:32:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26121 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 9FBD044B9E2 for ; Fri, 5 Mar 2021 18:35:42 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8294668AAC1; Fri, 5 Mar 2021 18:35:42 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.172]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C57EB68AA2A for ; Fri, 5 Mar 2021 18:35:33 +0200 (EET) Received: by mail-qk1-f172.google.com with SMTP id f124so2550327qkj.5 for ; Fri, 05 Mar 2021 08:35:33 -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=yd2rh/Xu/+D6Bkm1/8f2oUZwVVjkT/rfijYOe6IX8kw=; b=NYwbAGhia//g6RQON3SgZyPqcBznXwel//bbzg6YmTIJBJ7r2Dy5NmjeiGEeWSbTAK Osr0Jl3i4svwir5ipE5HQVttwXhNjYwtkD3VJCKGDb6rasrkSwP6sCR/Q54XsX2gRPEI JiBQQAAWw8aE++E8bfsMdgKQFZm0lZf1h6HzV2CqaG0Kwa5c+1gN6yb7rcA3p8KfLqik Toqb99YhghqhF7qWRgZ9JoGjKtw8mlUQDPC1NEXYsW9rLd2yA15Bjy9oNO/HTya3lxL0 LXSdigR1LjZeJKfqfDMOzYPG/lwszcw9odqBmCHdYT4QKct/2tetw7Q2gUBPPzLX2GjH weZw== 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=yd2rh/Xu/+D6Bkm1/8f2oUZwVVjkT/rfijYOe6IX8kw=; b=kPu8tJGvQ/krQzAQ8PVzmG21AfoclrnGr+V19t3GLU0WnLhh5fC/Q9m53nfgg+r3CS 0c7AWa6flXsla62IIbFbpske9juVGPbPP7uZ8bmT5I+oa1DVox69vE+ebQXWwlWz6wBq kHTUOPfTeDyHzW0cNwFnxhcZkxPG6ZEdKUPT7rct2lspzzuBunkfJKfG+gH1kSfxHOiv Mhr7cCBZuS2P4lQt/qbb0s/KbxSHDpnKL9uvHDY4Y+DvCHKLF6pAxOML6gXTlTCZKuhh qdfdg7BDFSj+Ra32lw9eI9h+jCRoS8ZvAqmRpz16FGwMCQUkx9koVaAoeXcjWEhnsKBx w/UA== X-Gm-Message-State: AOAM530AYUKnlwKV+y65U1CiCaIqxMp/Nw/QTq1Ig+0ZWdhaKmEf+hkW vwHLvuUfat/FlmCftt68dKvvqIJDjtnb5A== X-Google-Smtp-Source: ABdhPJwYSmKYOMwdBZp6Y/mJqwis5qvmg/wxXhyhdsWKMnrjFj204+a4efM665o1F8OZfkyLj1a/PQ== X-Received: by 2002:a05:620a:b02:: with SMTP id t2mr10100329qkg.128.1614962132235; Fri, 05 Mar 2021 08:35:32 -0800 (PST) Received: from localhost.localdomain ([181.23.89.132]) by smtp.gmail.com with ESMTPSA id b10sm2168494qtt.23.2021.03.05.08.35.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 08:35:31 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Mar 2021 13:32:56 -0300 Message-Id: <20210305163339.63164-6-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 05/48] avcodec/libxvid: 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 --- libavcodec/libxvid.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/libavcodec/libxvid.c b/libavcodec/libxvid.c index 857077dc3b..d880558893 100644 --- a/libavcodec/libxvid.c +++ b/libavcodec/libxvid.c @@ -685,10 +685,12 @@ FF_ENABLE_DEPRECATION_WARNINGS /* Encode a dummy frame to get the extradata immediately */ if (x->quicktime_format) { AVFrame *picture; - AVPacket packet = {0}; + AVPacket *packet; int size, got_packet, ret; - av_init_packet(&packet); + packet = av_packet_alloc(); + if (!packet) + return AVERROR(ENOMEM); picture = av_frame_alloc(); if (!picture) @@ -696,6 +698,7 @@ FF_ENABLE_DEPRECATION_WARNINGS xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL); if( xerr ) { + av_packet_free(&packet); av_frame_free(&picture); av_log(avctx, AV_LOG_ERROR, "Xvid: Could not create encoder reference\n"); return AVERROR_EXTERNAL; @@ -704,6 +707,7 @@ FF_ENABLE_DEPRECATION_WARNINGS size = ((avctx->width + 1) & ~1) * ((avctx->height + 1) & ~1); picture->data[0] = av_malloc(size + size / 2); if (!picture->data[0]) { + av_packet_free(&packet); av_frame_free(&picture); return AVERROR(ENOMEM); } @@ -711,9 +715,8 @@ FF_ENABLE_DEPRECATION_WARNINGS picture->data[2] = picture->data[1] + size / 4; memset(picture->data[0], 0, size); memset(picture->data[1], 128, size / 2); - ret = xvid_encode_frame(avctx, &packet, picture, &got_packet); - if (!ret && got_packet) - av_packet_unref(&packet); + ret = xvid_encode_frame(avctx, packet, picture, &got_packet); + av_packet_free(&packet); av_free(picture->data[0]); av_frame_free(&picture); xvid_encore(x->encoder_handle, XVID_ENC_DESTROY, NULL, NULL); From patchwork Fri Mar 5 16:32: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: 26123 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 2B12F44B9E2 for ; Fri, 5 Mar 2021 18:35:45 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 09F8268AB25; Fri, 5 Mar 2021 18:35:45 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id F107068AA93 for ; Fri, 5 Mar 2021 18:35:34 +0200 (EET) Received: by mail-qk1-f181.google.com with SMTP id t4so2583378qkp.1 for ; Fri, 05 Mar 2021 08:35:34 -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=MCVrLVkgss5FKW5OwL99Bq1BlLCZ5BiUwVa666Wt11c=; b=LjjIMbTWNrvepyonjsEUEpKippA7+IcF3xPO13IvxvZLplhV9V0srO8LSdb1G+zz7p hf9XO+jZJ5lQXp9ZGUBNm+yBquP3kWVikGD0WxBPb0n1e06jEHXymm8AjrGyowLNgvCy PNCjUAItlxtmkMxrvGWiLauJFb+g2NoukbS/JMlIdYhAHqB03HYT8naPM0G7PG/iB0kx qJEy/6oz6U/ofo8FqN/s3u5nURcLBTIVxtbUHZozSzDQrSj5eGJ80LWacIejFtNCPuUj vi/dWsEmZT5KEV4gxIP9OuZqaaQ4wB/WS6Xrs9PDkKNpIUdd0h+HuLDwbl6OwDC02a4j OZjQ== 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=MCVrLVkgss5FKW5OwL99Bq1BlLCZ5BiUwVa666Wt11c=; b=IVXc3/FrLDj4B3oEz56YapPQlkFhIw498xDm9v9YefdBYEe7LRP7G+rqLQ6NR9Y6X3 hff7BGXqJHGaWtTBB2K2Xl4ZPVUctxMeHUtJAXQ/+7+Kc/Kal0e4c32sJ8LYWZj4FBSf VboMh8K3pL23GNBemFODqg/XZkX1a4vxax4oPLsrWXjMyBM3Iaxnt6MSa0arEYbZmGVZ KrttoeTTL9388fN9YkM2dEZW0Pjc9DM5AeFWU8Fsf2Xzk+lLB2WFXkEQtxpEmXwVuhTF 6gSJdPxsXUfNFCJeYDhdNvz9FBfIXWEoOrKNK86sbiAfF53evpXEOwXwHRdmU4lQtZvm QtCA== X-Gm-Message-State: AOAM531OALChAtBQVLQ/3YSMDWbYYhpRy7OFTf9BXtSGglcb6MuaQ+6J tx9I1QhLHfQRHgUyBJ6WIgKkHF0q7o/P7w== X-Google-Smtp-Source: ABdhPJxd1VzirG7GhhkaIIyTsx0tJW7QfB7MJ30MGdf6XSTuBvGdC+tAY40zrIYZVcAeL0drTUxVXA== X-Received: by 2002:a05:620a:204d:: with SMTP id d13mr9692800qka.347.1614962133455; Fri, 05 Mar 2021 08:35:33 -0800 (PST) Received: from localhost.localdomain ([181.23.89.132]) by smtp.gmail.com with ESMTPSA id b10sm2168494qtt.23.2021.03.05.08.35.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 08:35:33 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Mar 2021 13:32:57 -0300 Message-Id: <20210305163339.63164-7-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 06/48] avcodec/mpegvideo_enc: 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 --- libavcodec/mpegvideo_enc.c | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 34dcf8c313..355e14a71b 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -1366,23 +1366,20 @@ static int skip_check(MpegEncContext *s, Picture *p, Picture *ref) return 0; } -static int encode_frame(AVCodecContext *c, AVFrame *frame) +static int encode_frame(AVCodecContext *c, AVFrame *frame, AVPacket *pkt) { - AVPacket pkt = { 0 }; int ret; int size = 0; - av_init_packet(&pkt); - ret = avcodec_send_frame(c, frame); if (ret < 0) return ret; do { - ret = avcodec_receive_packet(c, &pkt); + ret = avcodec_receive_packet(c, pkt); if (ret >= 0) { - size += pkt.size; - av_packet_unref(&pkt); + size += pkt->size; + av_packet_unref(pkt); } else if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF) return ret; } while (ret >= 0); @@ -1393,6 +1390,7 @@ static int encode_frame(AVCodecContext *c, AVFrame *frame) static int estimate_best_b_count(MpegEncContext *s) { const AVCodec *codec = avcodec_find_encoder(s->avctx->codec_id); + AVPacket *pkt; const int scale = s->brd_scale; int width = s->width >> scale; int height = s->height >> scale; @@ -1403,6 +1401,10 @@ static int estimate_best_b_count(MpegEncContext *s) av_assert0(scale >= 0 && scale <= 3); + pkt = av_packet_alloc(); + if (!pkt) + return AVERROR(ENOMEM); + //emms_c(); //s->next_picture_ptr->quality; p_lambda = s->last_lambda_for[AV_PICTURE_TYPE_P]; @@ -1454,8 +1456,10 @@ static int estimate_best_b_count(MpegEncContext *s) break; c = avcodec_alloc_context3(NULL); - if (!c) - return AVERROR(ENOMEM); + if (!c) { + ret = AVERROR(ENOMEM); + goto fail; + } c->width = width; c->height = height; @@ -1473,10 +1477,11 @@ static int estimate_best_b_count(MpegEncContext *s) if (ret < 0) goto fail; + s->tmp_frames[0]->pict_type = AV_PICTURE_TYPE_I; s->tmp_frames[0]->quality = 1 * FF_QP2LAMBDA; - out_size = encode_frame(c, s->tmp_frames[0]); + out_size = encode_frame(c, s->tmp_frames[0], pkt); if (out_size < 0) { ret = out_size; goto fail; @@ -1491,7 +1496,7 @@ static int estimate_best_b_count(MpegEncContext *s) AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_B; s->tmp_frames[i + 1]->quality = is_p ? p_lambda : b_lambda; - out_size = encode_frame(c, s->tmp_frames[i + 1]); + out_size = encode_frame(c, s->tmp_frames[i + 1], pkt); if (out_size < 0) { ret = out_size; goto fail; @@ -1501,7 +1506,7 @@ static int estimate_best_b_count(MpegEncContext *s) } /* get the delayed frames */ - out_size = encode_frame(c, NULL); + out_size = encode_frame(c, NULL, pkt); if (out_size < 0) { ret = out_size; goto fail; @@ -1517,10 +1522,15 @@ static int estimate_best_b_count(MpegEncContext *s) fail: avcodec_free_context(&c); - if (ret < 0) - return ret; + av_packet_unref(pkt); + if (ret < 0) { + best_b_count = ret; + break; + } } + av_packet_free(&pkt); + return best_b_count; } From patchwork Fri Mar 5 16:32:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26125 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 2E67E44B9E2 for ; Fri, 5 Mar 2021 18:35:47 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1B27768AAE6; Fri, 5 Mar 2021 18:35:47 +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 1790068A9ED for ; Fri, 5 Mar 2021 18:35:36 +0200 (EET) Received: by mail-qt1-f181.google.com with SMTP id v64so2167664qtd.5 for ; Fri, 05 Mar 2021 08:35:36 -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=YyQ/ZQMg+zl2VLpO8Yr0XgMspy/CUhX/qBa32zUvZZQ=; b=MhWoFlLwlWujgIBx5CvCCLfM6hDlmrWHonCWINDSqPX7CBBsW1fb47C4TaKdazZraR jqr+QKsykP9vIQAEgFAtdTUZ7k0WWKiWONEPK3I6uKZhC0Zkpz0yExDi3gdBFOzLXvOs YvnArJlqHonCQuS+SxJ5+idbymMOUS2PyQIuIr9090voWDJkWq/6wDUbeTaNEKUwX5l4 ze2KYo4jYa+Ely/sA37nfVHcc1DU1n0VkLTdHqpDKX4qTpfJBLLAW+yHc311TDUo4JfH K94AdpdZjLzS3pyd/iniV0qez3B8zxzXzp+U3zbTV6zTHzL85DEozIiL14RPi2kLa9lc Mchw== 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=YyQ/ZQMg+zl2VLpO8Yr0XgMspy/CUhX/qBa32zUvZZQ=; b=JoqnMnYuKinX3KU0ZjLstKQgDHW7IxABTcga8IRhcgMjuXwv/4W8xLE4PNAJFfGyBD 6dmGUyMYRWYkPMkYYcVu9LZCPxoUqCZEKH7xuR//XiAjpKGvEhoCJl7NsS8zFgMCuE7O ObGNKdH99zqJRf+k2A2qfU5JBsi7eEMQmP8ryd79V9ExByr6dpUHb4FJhJ94vXhl/raN G/Fwe+DQ79g+4CyOejX7mh/eHrwi3BjulzFHsMDjGOCBUur6BRtJNCn9BHUahQjvx5as xWe/ynYyFCiCZ6IsSb4lt7Sb5JUCl3JBZLZu8uZ7dHBU4Tua64Awd8W2Hf7S2b4+dTCL AV/w== X-Gm-Message-State: AOAM530lT5VQR3s5V6yXrwbW94kiKMEYT/NI5uCZ8dLgXVWl+300Yghc yEsT4hl1dLkvjUhkwcGiNpc8ILBQ6RQPVg== X-Google-Smtp-Source: ABdhPJwXWxyXrDyl0VYXyyenpr03X6H0pO7HntQuGthRQRalG9ZRqYBaaENQpNV6Ph1qbhO/6vMgnQ== X-Received: by 2002:ac8:740a:: with SMTP id p10mr9339012qtq.273.1614962134659; Fri, 05 Mar 2021 08:35:34 -0800 (PST) Received: from localhost.localdomain ([181.23.89.132]) by smtp.gmail.com with ESMTPSA id b10sm2168494qtt.23.2021.03.05.08.35.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 08:35:34 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Mar 2021 13:32:58 -0300 Message-Id: <20210305163339.63164-8-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 07/48] avcodec/pthread_frame: 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 --- libavcodec/pthread_frame.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c index 4429a4d59c..7bcb9a7bcc 100644 --- a/libavcodec/pthread_frame.c +++ b/libavcodec/pthread_frame.c @@ -81,7 +81,7 @@ typedef struct PerThreadContext { AVCodecContext *avctx; ///< Context used to decode packets passed to this thread. - AVPacket avpkt; ///< Input packet (for decoding) or output (for encoding). + AVPacket *avpkt; ///< Input packet (for decoding) or output (for encoding). AVFrame *frame; ///< Output frame (for decoding) or input (for encoding). int got_frame; ///< The output of got_picture_ptr from the last avcodec_decode_video() call. @@ -208,7 +208,7 @@ FF_ENABLE_DEPRECATION_WARNINGS av_frame_unref(p->frame); p->got_frame = 0; - p->result = codec->decode(avctx, p->frame, &p->got_frame, &p->avpkt); + p->result = codec->decode(avctx, p->frame, &p->got_frame, p->avpkt); if ((p->result < 0 || !p->got_frame) && p->frame->buf[0]) { if (avctx->codec->caps_internal & FF_CODEC_CAP_ALLOCATE_PROGRESS) @@ -438,8 +438,8 @@ static int submit_packet(PerThreadContext *p, AVCodecContext *user_avctx, } } - av_packet_unref(&p->avpkt); - ret = av_packet_ref(&p->avpkt, avpkt); + av_packet_unref(p->avpkt); + ret = av_packet_ref(p->avpkt, avpkt); if (ret < 0) { pthread_mutex_unlock(&p->mutex); av_log(p->avctx, AV_LOG_ERROR, "av_packet_ref() failed in submit_packet()\n"); @@ -550,7 +550,7 @@ int ff_thread_decode_frame(AVCodecContext *avctx, av_frame_move_ref(picture, p->frame); *got_picture_ptr = p->got_frame; - picture->pkt_dts = p->avpkt.dts; + picture->pkt_dts = p->avpkt->dts; err = p->result; /* @@ -725,7 +725,7 @@ void ff_frame_thread_free(AVCodecContext *avctx, int thread_count) pthread_cond_destroy(&p->input_cond); pthread_cond_destroy(&p->progress_cond); pthread_cond_destroy(&p->output_cond); - av_packet_unref(&p->avpkt); + av_packet_free(&p->avpkt); #if FF_API_THREAD_SAFE_CALLBACKS for (int j = 0; j < p->released_buffers_allocated; j++) @@ -822,6 +822,12 @@ int ff_frame_thread_init(AVCodecContext *avctx) err = AVERROR(ENOMEM); goto error; } + p->avpkt = av_packet_alloc(); + if (!p->avpkt) { + av_freep(©); + err = AVERROR(ENOMEM); + goto error; + } p->parent = fctx; p->avctx = copy; @@ -841,7 +847,7 @@ int ff_frame_thread_init(AVCodecContext *avctx) } *copy->internal = *src->internal; copy->internal->thread_ctx = p; - copy->internal->last_pkt_props = &p->avpkt; + copy->internal->last_pkt_props = p->avpkt; copy->delay = avctx->delay; From patchwork Fri Mar 5 16:32:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26127 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 0E70F44B9E2 for ; Fri, 5 Mar 2021 18:35:49 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F0BAF68AB90; Fri, 5 Mar 2021 18:35:48 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f176.google.com (mail-qk1-f176.google.com [209.85.222.176]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9314D68AAEA for ; Fri, 5 Mar 2021 18:35:37 +0200 (EET) Received: by mail-qk1-f176.google.com with SMTP id a9so2506290qkn.13 for ; Fri, 05 Mar 2021 08:35:37 -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=kTg7YbFp0VUhWPEZGtOdBrikP5m8fxJ+LBz2gx5mIAA=; b=nYMg3W6RlH1ZEIb+09oGbCPtn2e2vEx4NDtrAC/KjNFfOAzV+Q8mNAVYZChfO7O4Iy ICBmwj65rkWNMzaaXJdKHm+fpV7acsRyAk2tLGBcMtlzoO2OGMRNP8mxpiuwbO+uYSea nXbg9J2XU7WrR8pb6VPEfTCojomrHf3i1gKUfCpdy4NQadF7Q/TK7rhmXl+j/9qvyuRe pB7WNKgwTqXXTsCSbb8W/GiRVXf0sO/KNQFtVNd3P0g5a4i/R0tDY69yTw/CVPd4i6sF LBxoNvcHOqqH4TLcB4CU9DIuuOrEtZh06QfgNkRcZBnXyZN09evZnZv1kHGYnxlpa/WY Ch7g== 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=kTg7YbFp0VUhWPEZGtOdBrikP5m8fxJ+LBz2gx5mIAA=; b=m+CUVN5rubtOFm91l3e3rh1jwifAn5FfDQRepnUQ1TZb/JxJDaOoWxEr7cyMcmub/b 52uJvRjsjuGFmclhVWtKx0fwS4th0fEWnWSvn5Pge0njzgDYzjEPWJB5ZHKN8rugXfyp +qzBPtw+0MuSsOTwo3BJTJIcW9oiyJ8bNwLIvyz12/vKFl+Lh2NWud9Dy06tFN5auICx g0JV2hVeq+S3wDNVpLK7tvo9qCxTeYzTlcJQ4q4b+wo7DeUfDsGR07wvNh+5sgYsStX+ dUBrTS9E2L1lT4ZTyvJZ6DIBUUo6tUIpTvTi7v9nRguCRuoF3Frz/tBbaBytKXk2c7zd E3SQ== X-Gm-Message-State: AOAM531Ra691pLbX0R/vqgEHusTDyLQFRrVnfG8ro8Pmf0n4hfP1aspB 0dkjAAv8dE1sNe2qsk/SJk4wXqSj/dxsTg== X-Google-Smtp-Source: ABdhPJxpdI/lwmINN4kr2v8YtQPhLXxfhT+MGQ3nmSYh3yyhKVAABxKRo5msTk85dnimMwIXL+/pqA== X-Received: by 2002:a37:4e01:: with SMTP id c1mr9885796qkb.16.1614962136139; Fri, 05 Mar 2021 08:35:36 -0800 (PST) Received: from localhost.localdomain ([181.23.89.132]) by smtp.gmail.com with ESMTPSA id b10sm2168494qtt.23.2021.03.05.08.35.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 08:35:35 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Mar 2021 13:32:59 -0300 Message-Id: <20210305163339.63164-9-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 08/48] avcodec/tdsc: 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 --- libavcodec/tdsc.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/libavcodec/tdsc.c b/libavcodec/tdsc.c index 7c888b6ec8..9e7381c2bb 100644 --- a/libavcodec/tdsc.c +++ b/libavcodec/tdsc.c @@ -53,6 +53,7 @@ typedef struct TDSCContext { GetByteContext gbc; AVFrame *refframe; // full decoded frame (without cursor) + AVPacket *jpkt; // encoded JPEG tile AVFrame *jpgframe; // decoded JPEG tile uint8_t *tilebuffer; // buffer containing tile data @@ -80,6 +81,7 @@ static av_cold int tdsc_close(AVCodecContext *avctx) av_frame_free(&ctx->refframe); av_frame_free(&ctx->jpgframe); + av_packet_free(&ctx->jpkt); av_freep(&ctx->deflatebuffer); av_freep(&ctx->tilebuffer); av_freep(&ctx->cursor); @@ -111,7 +113,8 @@ static av_cold int tdsc_init(AVCodecContext *avctx) /* Allocate reference and JPEG frame */ ctx->refframe = av_frame_alloc(); ctx->jpgframe = av_frame_alloc(); - if (!ctx->refframe || !ctx->jpgframe) + ctx->jpkt = av_packet_alloc(); + if (!ctx->refframe || !ctx->jpgframe || !ctx->jpkt) return AVERROR(ENOMEM); /* Prepare everything needed for JPEG decoding */ @@ -342,15 +345,14 @@ static int tdsc_decode_jpeg_tile(AVCodecContext *avctx, int tile_size, int x, int y, int w, int h) { TDSCContext *ctx = avctx->priv_data; - AVPacket jpkt; int ret; /* Prepare a packet and send to the MJPEG decoder */ - av_init_packet(&jpkt); - jpkt.data = ctx->tilebuffer; - jpkt.size = tile_size; + av_packet_unref(ctx->jpkt); + ctx->jpkt->data = ctx->tilebuffer; + ctx->jpkt->size = tile_size; - ret = avcodec_send_packet(ctx->jpeg_avctx, &jpkt); + ret = avcodec_send_packet(ctx->jpeg_avctx, ctx->jpkt); if (ret < 0) { av_log(avctx, AV_LOG_ERROR, "Error submitting a packet for decoding\n"); return ret; From patchwork Fri Mar 5 16:33:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26122 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 E8A1C44B9E2 for ; Fri, 5 Mar 2021 18:35:43 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CFD5B68AA8E; Fri, 5 Mar 2021 18:35:43 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f177.google.com (mail-qt1-f177.google.com [209.85.160.177]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E4B6068AA48 for ; Fri, 5 Mar 2021 18:35:38 +0200 (EET) Received: by mail-qt1-f177.google.com with SMTP id 18so2182001qty.3 for ; Fri, 05 Mar 2021 08:35: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=/apqkQ1LNM+vezThWD9E8qTvOypI1BZrE6LKDqIGEZs=; b=HwnGhgirfuLhaPGxiqOKyUERX0szPjmeEX7FutFP49mYfcWkxeEcbAIrieD80ek6Ry QvN5N0MVxNaWNOh9fEMJ3Z1EVyJlkQ+BACoIrAr+wy7yKtfJr+WXvAkwLU8ADGD9uWvl 48lHXJXT9wbSKXDA6WyfN4F1i5juE+12D5z+rKIO9pCA4twFI37TIQaRvKwlmUVDmgek VO6HBRR4IgMJfPDjoHW846yIqA9oICqv8YymqnkNGtTIWxY9UBJr2lncZZk2i7MrrPWx PsI053+JpIR4IbLwH6icWEjDVK1ncPnL3deMxya0JbI4sTrh1sl4eU9YkVk7H7rO1JoJ ItCA== 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=/apqkQ1LNM+vezThWD9E8qTvOypI1BZrE6LKDqIGEZs=; b=EtzWNeWgHDQg/pHnmzQvXOeV2SM9+RSi4AZTe9ZQfKMdLHwKU4Gqz5W2W1TJZI/dBT YLImSz3IL+dlgIC2Awpc5SMhQ/339zH8Qq4ZxR3zD1D4/5zXR97aJLAaBQMUkRFtifCL X2h4w23sVypxWLh1YlpK+kk1A4VzQGEbUDoNu5ojoQKEY1MOOnzednDLV2UOWM0pAYS7 gSBebslKvygdadRa97g4OTHUN/E3PWipArBIWbXBPGG2jvVvqDu5/kVDiQbCGcZh9CFY m5qEyVolY+N9aJw/zYxHJZLaIKSBckH870hSKYPdigA1xq5PSQnBVAPLuGe+bj8vyqMj 8aJQ== X-Gm-Message-State: AOAM533a8MkSOFpWvvmYm8v0nYlsVURf0pe4saUx5lDCeH6RoBY17q+D ILDdgp102qDD0qjvk/Cobi3Yl1FYjEXrlA== X-Google-Smtp-Source: ABdhPJzpjKlyFIsthxhy7Kf/j0p63SsKzCR78YWOFgU6WIa3B0LAdxWZhZT50txo9nmsQxsAXtmiSw== X-Received: by 2002:ac8:7656:: with SMTP id i22mr9894931qtr.39.1614962137443; Fri, 05 Mar 2021 08:35:37 -0800 (PST) Received: from localhost.localdomain ([181.23.89.132]) by smtp.gmail.com with ESMTPSA id b10sm2168494qtt.23.2021.03.05.08.35.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 08:35:36 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Mar 2021 13:33:00 -0300 Message-Id: <20210305163339.63164-10-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 09/48] avcodec/tiff: use av_packet_alloc() to allocate AVPackets 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 --- libavcodec/tiff.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c index d1e908fd43..17a593e379 100644 --- a/libavcodec/tiff.c +++ b/libavcodec/tiff.c @@ -58,6 +58,7 @@ typedef struct TiffContext { /* JPEG decoding for DNG */ AVCodecContext *avctx_mjpeg; // wrapper context for MJPEG + AVPacket *jpkt; // encoded JPEG tile AVFrame *jpgframe; // decoded JPEG tile int get_subimage; @@ -877,7 +878,6 @@ static int dng_decode_jpeg(AVCodecContext *avctx, AVFrame *frame, int tile_byte_count, int dst_x, int dst_y, int w, int h) { TiffContext *s = avctx->priv_data; - AVPacket jpkt; uint8_t *dst_data, *src_data; uint32_t dst_offset; /* offset from dst buffer in pixels */ int is_single_comp, is_u16, pixel_size; @@ -887,9 +887,9 @@ static int dng_decode_jpeg(AVCodecContext *avctx, AVFrame *frame, return AVERROR_INVALIDDATA; /* Prepare a packet and send to the MJPEG decoder */ - av_init_packet(&jpkt); - jpkt.data = (uint8_t*)s->gb.buffer; - jpkt.size = tile_byte_count; + av_packet_unref(s->jpkt); + s->jpkt->data = (uint8_t*)s->gb.buffer; + s->jpkt->size = tile_byte_count; if (s->is_bayer) { MJpegDecodeContext *mjpegdecctx = s->avctx_mjpeg->priv_data; @@ -898,7 +898,7 @@ static int dng_decode_jpeg(AVCodecContext *avctx, AVFrame *frame, mjpegdecctx->bayer = 1; } - ret = avcodec_send_packet(s->avctx_mjpeg, &jpkt); + ret = avcodec_send_packet(s->avctx_mjpeg, s->jpkt); if (ret < 0) { av_log(avctx, AV_LOG_ERROR, "Error submitting a packet for decoding\n"); return ret; @@ -2157,7 +2157,8 @@ static av_cold int tiff_init(AVCodecContext *avctx) /* Allocate JPEG frame */ s->jpgframe = av_frame_alloc(); - if (!s->jpgframe) + s->jpkt = av_packet_alloc(); + if (!s->jpgframe || !s->jpkt) return AVERROR(ENOMEM); /* Prepare everything needed for JPEG decoding */ @@ -2193,6 +2194,7 @@ static av_cold int tiff_end(AVCodecContext *avctx) av_freep(&s->fax_buffer); s->fax_buffer_size = 0; av_frame_free(&s->jpgframe); + av_packet_free(&s->jpkt); avcodec_free_context(&s->avctx_mjpeg); return 0; } From patchwork Fri Mar 5 16:33:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26124 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 4DB7744B9E2 for ; Fri, 5 Mar 2021 18:35:46 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 37E2568AB48; Fri, 5 Mar 2021 18:35:46 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f180.google.com (mail-qk1-f180.google.com [209.85.222.180]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3E92B68AA67 for ; Fri, 5 Mar 2021 18:35:40 +0200 (EET) Received: by mail-qk1-f180.google.com with SMTP id z128so2504840qkc.12 for ; Fri, 05 Mar 2021 08:35:40 -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=JzPaKNp/C4hrLOQUHfij7tAezD12v5bib+rRrWfU3uI=; b=CU6b4ueSSmvrW/ltVN49bbiEnNXu3Po8arZPFJzTH1TnKV5jVraB81I2+sndiMwnm8 OhD3CM8GzG11b5ORodCbNVrY920NhI+ziD35zeaarix/E9apq798KJ9f/KjhLxt4B3YH eR9gxOI0FWgQOtV0RwvsLyXaV4KjloED+5JpCfEZfpGMn1RnpIlp8hzAhL9PEHJR8g5g TkPHug4aHFSWEXIBcgEkdj3kt3w86r0Uwqgm51QDsRpR7+dxuvf7CUZz+bLIqQm/Bdjl 4hS7taac/f/mPzFG52gj3gkbHC05Zz718K6/Hm0cgfv1WuN9lKBc8At7i4d5aqYPKPRs D83g== 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=JzPaKNp/C4hrLOQUHfij7tAezD12v5bib+rRrWfU3uI=; b=VaPwoZv+sx2YLt3RwWQHSEBqIJIHKljwVcZCiu6gvEE+23YNrimvJgeuqOEIkJ5id3 tLLNtp6qhCnc9cXFeRgwo4wOc9dYG54t9Nez2LNDYXYO4nDwYkJP+K+Op/R7jThV/UzP AGHcfDAyUz9IwYYlhWe+CERVlwrf5GwsuKGGO8rpqdDEGt5vR+bVLvBhhIzGCLbtkYvg ukJTd2zCpWemPbdSJnAe+a4etb9vWPalCcmg8YJHjKgBydymy418lVXoI4/QJ+E8QJfT Gt0DJELPqs5DO3q5z71xcMOp4nn5XdeQRmFbk/xoG2xfEDiIZcn/5x4nk6CLytvP9bUc Kgrw== X-Gm-Message-State: AOAM533xla6yOkwTZcSSeBiJf6bIqpVg9ipOkYGNBmoqCMhUYsxmatNh foRRqRpZrJDWGm9e+ZPRcGX0HGt7cTxtxg== X-Google-Smtp-Source: ABdhPJyVGq7AMfn1xjlkKg17XfawMYr1lNf1XS9Wjtblre2Qd64t2wE2prqDGov37FZOTeUv7d8jsQ== X-Received: by 2002:a37:7006:: with SMTP id l6mr9837249qkc.137.1614962138645; Fri, 05 Mar 2021 08:35:38 -0800 (PST) Received: from localhost.localdomain ([181.23.89.132]) by smtp.gmail.com with ESMTPSA id b10sm2168494qtt.23.2021.03.05.08.35.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 08:35:38 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Mar 2021 13:33:01 -0300 Message-Id: <20210305163339.63164-11-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 10/48] avcodec/webp: 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 --- libavcodec/webp.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/libavcodec/webp.c b/libavcodec/webp.c index 6de6a5c036..5a7aebc587 100644 --- a/libavcodec/webp.c +++ b/libavcodec/webp.c @@ -189,6 +189,7 @@ typedef struct WebPContext { VP8Context v; /* VP8 Context used for lossy decoding */ GetBitContext gb; /* bitstream reader for main image chunk */ AVFrame *alpha_frame; /* AVFrame for alpha data decompressed from VP8L */ + AVPacket *pkt; /* AVPacket to be passed to the underlying VP8 decoder */ AVCodecContext *avctx; /* parent AVCodecContext */ int initialized; /* set once the VP8 context is initialized */ int has_alpha; /* has a separate alpha chunk */ @@ -1290,7 +1291,6 @@ static int vp8_lossy_decode_frame(AVCodecContext *avctx, AVFrame *p, unsigned int data_size) { WebPContext *s = avctx->priv_data; - AVPacket pkt; int ret; if (!s->initialized) { @@ -1306,11 +1306,11 @@ static int vp8_lossy_decode_frame(AVCodecContext *avctx, AVFrame *p, return AVERROR_PATCHWELCOME; } - av_init_packet(&pkt); - pkt.data = data_start; - pkt.size = data_size; + av_packet_unref(s->pkt); + s->pkt->data = data_start; + s->pkt->size = data_size; - ret = ff_vp8_decode_frame(avctx, p, got_frame, &pkt); + ret = ff_vp8_decode_frame(avctx, p, got_frame, s->pkt); if (ret < 0) return ret; @@ -1527,10 +1527,23 @@ exif_end: return avpkt->size; } +static av_cold int webp_decode_init(AVCodecContext *avctx) +{ + WebPContext *s = avctx->priv_data; + + s->pkt = av_packet_alloc(); + if (!s->pkt) + return AVERROR(ENOMEM); + + return 0; +} + static av_cold int webp_decode_close(AVCodecContext *avctx) { WebPContext *s = avctx->priv_data; + av_packet_free(&s->pkt); + if (s->initialized) return ff_vp8_decode_free(avctx); @@ -1543,6 +1556,7 @@ AVCodec ff_webp_decoder = { .type = AVMEDIA_TYPE_VIDEO, .id = AV_CODEC_ID_WEBP, .priv_data_size = sizeof(WebPContext), + .init = webp_decode_init, .decode = webp_decode_frame, .close = webp_decode_close, .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS, From patchwork Fri Mar 5 16:33:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26126 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 08FB144B9E2 for ; Fri, 5 Mar 2021 18:35:48 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E944268AB7A; Fri, 5 Mar 2021 18:35:47 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f174.google.com (mail-qk1-f174.google.com [209.85.222.174]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9982468AA53 for ; Fri, 5 Mar 2021 18:35:41 +0200 (EET) Received: by mail-qk1-f174.google.com with SMTP id z128so2504913qkc.12 for ; Fri, 05 Mar 2021 08:35:41 -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=o+8katGO7NuXsl6UTbu9NA17ZbhkxovP0bw9uqfWbR4=; b=E8nfYj01K6bo9vw+nLzJ/YfCHhG4uPzBRMp087IR5X8FCoN0CXxb5gKUVlkKTmW7Fw IaDo6sVXZT8cc90ARFlMKQ7GwuW5rnI2YmjXLP0/iipH0/MTH1DgA6+wj3/jNEG+0T5W xsppdpV/DNeBk1o/mHv6u/FIla0oi6ua3ogvQRNv1cMbIbq0lHM9Fg8NHuuY5lrmlNDh KcUBzpSolN0aIx4jmh+br6O27Cz8SEjcSGqwM4EZJRcEzyO+zLx3gFTA4G7zpL87k/JM VMflWI0u1Ed6bQVz2HF32598UA0EpOzQM0QqYZ1o5S1OafFzadNOplh5ITyGc975RCWR BN4w== 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=o+8katGO7NuXsl6UTbu9NA17ZbhkxovP0bw9uqfWbR4=; b=XVGt5+AG4cyU+klvsH+BZQuWLmo7eQGoQxYSkLLghENjyN9WzTQFe4rU6Po+58ZssH OCk2cXWpTEFJMgf+MT4VaR21z4Y6fv/oI8c1/hM04dQNm5qiJeEBYT+ElcljXzyybzxJ 136HoTSJFzGoRuCkYgZ4miXAUtUnuJhyrMclQyJ3u6H74mHKoGdxdFU0G9wzaB8vGC+Z Amjt8TbgqjZTE7cYdNwIM76b+bEL62GuMpPolTIJyDl9cKIccGXhIeSaYPkNKH7yQ5Aw 2pv0h5sjlYQI2hntJ2Kz9zRzak5UkLwDXjEidbqnhnnRm+lnX9Y4zFwAkZdUqk7HeK53 06FQ== X-Gm-Message-State: AOAM533Be8MpojhizWUrDNgtodyHWz/k1pzy68NbwjjFCrZv3G5paxNh ywsAipmSr/UImmObtQFrEA+ZdNKdGwmh/A== X-Google-Smtp-Source: ABdhPJzc1+tA80g3GJqqCiuYFkAXi5/e6ydQLQQLOEEV+QmCtguC6CYmBKALCPLo3jr1yVfr7Xm4oA== X-Received: by 2002:a37:8185:: with SMTP id c127mr9870347qkd.275.1614962140066; Fri, 05 Mar 2021 08:35:40 -0800 (PST) Received: from localhost.localdomain ([181.23.89.132]) by smtp.gmail.com with ESMTPSA id b10sm2168494qtt.23.2021.03.05.08.35.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 08:35:39 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Mar 2021 13:33:02 -0300 Message-Id: <20210305163339.63164-12-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 11/48] avcodec/tests/avpacket: 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 --- libavcodec/tests/avpacket.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/libavcodec/tests/avpacket.c b/libavcodec/tests/avpacket.c index 90b72341f4..7a70ade4c3 100644 --- a/libavcodec/tests/avpacket.c +++ b/libavcodec/tests/avpacket.c @@ -63,9 +63,6 @@ static int initializations(AVPacket* avpkt) const static uint8_t* data = "selftest for av_packet_clone(...)"; int ret = 0; - /* initialize avpkt */ - av_init_packet(avpkt); - /* set values for avpkt */ avpkt->pts = 17; avpkt->dts = 2; @@ -82,16 +79,24 @@ static int initializations(AVPacket* avpkt) int main(void) { - AVPacket avpkt; + AVPacket *avpkt = NULL; AVPacket *avpkt_clone = NULL; int ret = 0; - if(initializations(&avpkt) < 0){ + /* test av_packet_alloc */ + avpkt = av_packet_alloc(); + if(!avpkt) { + av_log(NULL, AV_LOG_ERROR, "av_packet_alloc failed to allcoate AVPacket\n"); + return 1; + } + + if (initializations(avpkt) < 0) { printf("failed to initialize variables\n"); + av_packet_free(&avpkt); return 1; } /* test av_packet_clone*/ - avpkt_clone = av_packet_clone(&avpkt); + avpkt_clone = av_packet_clone(avpkt); if(!avpkt_clone) { av_log(NULL, AV_LOG_ERROR,"av_packet_clone failed to clone AVPacket\n"); @@ -121,7 +126,7 @@ int main(void) } /*clean up*/ av_packet_free(&avpkt_clone); - av_packet_unref(&avpkt); + av_packet_free(&avpkt); return ret; From patchwork Fri Mar 5 16:33:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26128 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 446BC44B9E2 for ; Fri, 5 Mar 2021 18:35:50 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 280A168ABB1; Fri, 5 Mar 2021 18:35:50 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.172]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B7ED468AB03 for ; Fri, 5 Mar 2021 18:35:42 +0200 (EET) Received: by mail-qk1-f172.google.com with SMTP id b130so2518144qkc.10 for ; Fri, 05 Mar 2021 08:35:42 -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=zd8/pBoG+2zGiu6X51FFJU0cTU2gFOOoJ3Ztbtt2Csc=; b=uqAqrQ3r0kkLwR8D9i1/Q0/F89XasDt+USifKIoEZz8ZhgQLNWvDjnUeDV0/zFHMzr t7rIpgkR3LX7jMi0dHLXsFOYdQgAC1oTEjIrrZLU0YMx9rMpLO9Wf9BEyhlNGLb2wUsI IIl4M0eWR2T1WWMFbQSPklPY7KUitp9o6t1ejnehF/A7wwAUvggeK10Jettkm0wLij3W PZrB7owahxQY9plbL1cgpqyCq6oPj8jpxm4wZLIgf/ct4VXDr57yy/F/3tBi3bz+0c3O HI72WJf9rv/EAH4iYW7oPf/5fnY5AggVIKJWLlEnTUkbO3fCh1z3J+Xs61cTbWseGmzg T3eQ== 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=zd8/pBoG+2zGiu6X51FFJU0cTU2gFOOoJ3Ztbtt2Csc=; b=Kwv6hqqJBNGofdD7hQtvfb37ZiqQbVg/qQSNmbG/pcNOCfPDklAWcvyJzjwVXUkV8L rfKyd5Z6C5W8Nxneh+OOt+zWiLu8DYx+g8JY0JfAsaRorGqOssPWQnLqqh1vvqerQS1D 0Vg8ZKzMv/ZrlwjntkdTcjxjLR7J5zPb7t19xGnDeN7frS/M8YMAYTZPTqB58OOpNgeb m+74zT3F+LEl1nRFH57zHQwYWZk1uo/VF7+LrhpDQcgo3dkhSXIg1cOZYEouRwYygmvL 6fbdu4Em691MMWKSd2SOBMtID0X88qdnQ5uKTXsh5A00dcmwSQPl0/nlkfgzc9uISH41 CAHQ== X-Gm-Message-State: AOAM531xUfaSs495FCz1wP954DT8joZRy4ReTMhw+1oTJ7IqyPQD25jM 1lxwYI4r8KCiGe2QvAsgoN41UFH75FZv2w== X-Google-Smtp-Source: ABdhPJxtSrjMLdpJVwk29TTTAOira3VWxmMX6cghrYbbmhOGEQ+GG/IV++8hLlL8dLBGQraR/KB+hQ== X-Received: by 2002:a37:a785:: with SMTP id q127mr9499950qke.425.1614962141263; Fri, 05 Mar 2021 08:35:41 -0800 (PST) Received: from localhost.localdomain ([181.23.89.132]) by smtp.gmail.com with ESMTPSA id b10sm2168494qtt.23.2021.03.05.08.35.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 08:35:40 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Mar 2021 13:33:03 -0300 Message-Id: <20210305163339.63164-13-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 12/48] avformat/mux: 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/internal.h | 5 +++++ libavformat/mux.c | 40 ++++++++++++++++++++-------------------- libavformat/options.c | 6 ++++++ libavformat/utils.c | 1 + 4 files changed, 32 insertions(+), 20 deletions(-) diff --git a/libavformat/internal.h b/libavformat/internal.h index e913d958fc..02ff2fd77a 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -92,6 +92,11 @@ struct AVFormatInternal { */ struct PacketList *parse_queue; struct PacketList *parse_queue_end; + + /** + * Used to hold temporary packets. + */ + AVPacket *pkt; /** * Remaining size available for raw_packet_buffer, in bytes. */ diff --git a/libavformat/mux.c b/libavformat/mux.c index 440113b149..e98b86a81e 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -1211,7 +1211,7 @@ static int write_packets_common(AVFormatContext *s, AVPacket *pkt, int interleav int av_write_frame(AVFormatContext *s, AVPacket *in) { - AVPacket local_pkt, *pkt = &local_pkt; + AVPacket *pkt = s->internal->pkt; int ret; if (!in) { @@ -1232,6 +1232,7 @@ int av_write_frame(AVFormatContext *s, AVPacket *in) * The following avoids copying in's data unnecessarily. * Copying side data is unavoidable as a bitstream filter * may change it, e.g. free it on errors. */ + av_packet_unref(pkt); pkt->buf = NULL; pkt->data = in->data; pkt->size = in->size; @@ -1273,14 +1274,14 @@ int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt) int av_write_trailer(AVFormatContext *s) { int i, ret1, ret = 0; - AVPacket pkt = {0}; - av_init_packet(&pkt); + AVPacket *pkt = s->internal->pkt; + av_packet_unref(pkt); for (i = 0; i < s->nb_streams; i++) { if (s->streams[i]->internal->bsfc) { - ret1 = write_packets_from_bsfs(s, s->streams[i], &pkt, 1/*interleaved*/); + ret1 = write_packets_from_bsfs(s, s->streams[i], pkt, 1/*interleaved*/); if (ret1 < 0) - av_packet_unref(&pkt); + av_packet_unref(pkt); if (ret >= 0) ret = ret1; } @@ -1354,7 +1355,7 @@ static void uncoded_frame_free(void *unused, uint8_t *data) static int write_uncoded_frame_internal(AVFormatContext *s, int stream_index, AVFrame *frame, int interleaved) { - AVPacket pkt, *pktp; + AVPacket *pkt = s->internal->pkt; av_assert0(s->oformat); if (!s->oformat->write_uncoded_frame) { @@ -1363,18 +1364,17 @@ static int write_uncoded_frame_internal(AVFormatContext *s, int stream_index, } if (!frame) { - pktp = NULL; + pkt = NULL; } else { size_t bufsize = sizeof(frame) + AV_INPUT_BUFFER_PADDING_SIZE; AVFrame **framep = av_mallocz(bufsize); if (!framep) goto fail; - pktp = &pkt; - av_init_packet(&pkt); - pkt.buf = av_buffer_create((void *)framep, bufsize, + av_packet_unref(pkt); + pkt->buf = av_buffer_create((void *)framep, bufsize, uncoded_frame_free, NULL, 0); - if (!pkt.buf) { + if (!pkt->buf) { av_free(framep); fail: av_frame_free(&frame); @@ -1382,17 +1382,17 @@ static int write_uncoded_frame_internal(AVFormatContext *s, int stream_index, } *framep = frame; - pkt.data = (void *)framep; - pkt.size = sizeof(frame); - pkt.pts = - pkt.dts = frame->pts; - pkt.duration = frame->pkt_duration; - pkt.stream_index = stream_index; - pkt.flags |= AV_PKT_FLAG_UNCODED_FRAME; + pkt->data = (void *)framep; + pkt->size = sizeof(frame); + pkt->pts = + pkt->dts = frame->pts; + pkt->duration = frame->pkt_duration; + pkt->stream_index = stream_index; + pkt->flags |= AV_PKT_FLAG_UNCODED_FRAME; } - return interleaved ? av_interleaved_write_frame(s, pktp) : - av_write_frame(s, pktp); + return interleaved ? av_interleaved_write_frame(s, pkt) : + av_write_frame(s, pkt); } int av_write_uncoded_frame(AVFormatContext *s, int stream_index, diff --git a/libavformat/options.c b/libavformat/options.c index 59e0389815..8d7c4fe4cb 100644 --- a/libavformat/options.c +++ b/libavformat/options.c @@ -220,6 +220,12 @@ AVFormatContext *avformat_alloc_context(void) av_free(ic); return NULL; } + internal->pkt = av_packet_alloc(); + if (!internal->pkt) { + av_free(internal); + av_free(ic); + return NULL; + } avformat_get_context_defaults(ic); ic->internal = internal; ic->internal->offset = AV_NOPTS_VALUE; diff --git a/libavformat/utils.c b/libavformat/utils.c index 73b1a9b52c..192ef51f47 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -4451,6 +4451,7 @@ void avformat_free_context(AVFormatContext *s) av_freep(&s->chapters); av_dict_free(&s->metadata); av_dict_free(&s->internal->id3v2_meta); + av_packet_free(&s->internal->pkt); av_freep(&s->streams); flush_packet_queue(s); av_freep(&s->internal); From patchwork Fri Mar 5 16:33:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26137 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 4AB8A44BAEC for ; Fri, 5 Mar 2021 18:38:11 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2834768ABAC; Fri, 5 Mar 2021 18:35:51 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f171.google.com (mail-qt1-f171.google.com [209.85.160.171]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5922368A9F3 for ; Fri, 5 Mar 2021 18:35:44 +0200 (EET) Received: by mail-qt1-f171.google.com with SMTP id t13so786896qta.11 for ; Fri, 05 Mar 2021 08:35:44 -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=13Y8PM7FmK6DAfo6zkAAvE3yohMSm6e+8dc7O10Yqm8=; b=WtoOYHvAqxEuI4iz0x8jV8UBFxR+E7WifLBwOYRWf05LEPxUdw9XVdDj6WQ8+qdWeu clQJqqi6H52Zk9ryIv/AZS6N0HqWnDF0Bq2udRKgs+ZJpgoM7TpcgyUKJGpQrs+3+uJy eQEQmiQWIejFXC9ZRS4o9NSNQDIF2rd/VgS5//01K68RKAZv42tyGWY6Rfx6JS6jtVhL PANWAU237H1RI2e6Zq24Z7KNdCJleeDti4qKZyL3w0UzYZYCLsQYjs4C1kx4CTQkWL2s ymOnwrR74sJCq1MNVJ0UV/uU/7a44DDWYaDDgONo49PPYr2KoA6Hled+PUn16CcbnYVs YTmA== 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=13Y8PM7FmK6DAfo6zkAAvE3yohMSm6e+8dc7O10Yqm8=; b=ohLLQ98mEI5ZzmA+VwVs/7379fW/VfKzBW+DdxvLvZOhf0AOQqTOEBEaZw3XVxH35e SoZn787aIrYmwiNkOPp6rIHETBMzQZKJ3n79Bwl/1dAE2GPMeFJySyuWBcJU0ijYxd/j 9/3P1rmoVUMO8IgwRXPVaWp1uyYFJVGb5Z5J4l0fIW1dxBW7xDpiIP1YUaLCAYlCGfJc PrJF7CF5JPdcQEBn4FEfGmpQ6FunwXgwZDy84DIyJpo5GJyiMfweZuCHAycjqxZ/8Ghw GNGFn7/U2rknCPYRVF5vty5DcGoH+TsrID2RmFgCNugreO9MWa2df4N9qn3KNf+MNuo+ lVGw== X-Gm-Message-State: AOAM531H7kvJvfA6c/jOlfpNf7LiObURQ+9v6bTkMsdolUvTDAFTq6Ep gasM5YacF16lKu8ftmsKGW8A11OqDdawyw== X-Google-Smtp-Source: ABdhPJy0LUBwkKxpk87+TMa9SYIbkLRve+yWXVxnNzrxlnzEILsPUXzbS8a5d1MnSPAWOMEU6cIzWg== X-Received: by 2002:aed:2b61:: with SMTP id p88mr2388212qtd.360.1614962142580; Fri, 05 Mar 2021 08:35:42 -0800 (PST) Received: from localhost.localdomain ([181.23.89.132]) by smtp.gmail.com with ESMTPSA id b10sm2168494qtt.23.2021.03.05.08.35.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 08:35:42 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Mar 2021 13:33:04 -0300 Message-Id: <20210305163339.63164-14-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 13/48] avformat/utils: 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/internal.h | 1 + libavformat/options.c | 5 ++- libavformat/utils.c | 100 +++++++++++++++++++++++------------------ 3 files changed, 62 insertions(+), 44 deletions(-) diff --git a/libavformat/internal.h b/libavformat/internal.h index 02ff2fd77a..96902b818c 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -90,6 +90,7 @@ struct AVFormatInternal { /** * Packets split by the parser get queued here. */ + AVPacket *parse_pkt; struct PacketList *parse_queue; struct PacketList *parse_queue_end; diff --git a/libavformat/options.c b/libavformat/options.c index 8d7c4fe4cb..07403b533e 100644 --- a/libavformat/options.c +++ b/libavformat/options.c @@ -221,7 +221,10 @@ AVFormatContext *avformat_alloc_context(void) return NULL; } internal->pkt = av_packet_alloc(); - if (!internal->pkt) { + internal->parse_pkt = av_packet_alloc(); + if (!internal->pkt || !internal->parse_pkt) { + av_packet_free(&internal->pkt); + av_packet_free(&internal->parse_pkt); av_free(internal); av_free(ic); return NULL; diff --git a/libavformat/utils.c b/libavformat/utils.c index 192ef51f47..2b17c6174b 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -309,9 +309,15 @@ static int append_packet_chunked(AVIOContext *s, AVPacket *pkt, int size) int av_get_packet(AVIOContext *s, AVPacket *pkt, int size) { +#if FF_API_INIT_PACKET +FF_DISABLE_DEPRECATION_WARNINGS av_init_packet(pkt); pkt->data = NULL; pkt->size = 0; +FF_ENABLE_DEPRECATION_WARNINGS +#else + av_packet_unref(pkt); +#endif pkt->pos = avio_tell(s); return append_packet_chunked(s, pkt, size); @@ -807,9 +813,15 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt) int ret, i, err; AVStream *st; +#if FF_API_INIT_PACKET +FF_DISABLE_DEPRECATION_WARNINGS pkt->data = NULL; pkt->size = 0; av_init_packet(pkt); +FF_ENABLE_DEPRECATION_WARNINGS +#else + av_packet_unref(pkt); +#endif for (;;) { PacketList *pktl = s->internal->raw_packet_buffer; @@ -1409,14 +1421,14 @@ FF_ENABLE_DEPRECATION_WARNINGS static int parse_packet(AVFormatContext *s, AVPacket *pkt, int stream_index, int flush) { - AVPacket out_pkt; + AVPacket *out_pkt = s->internal->parse_pkt; AVStream *st = s->streams[stream_index]; uint8_t *data = pkt->data; int size = pkt->size; int ret = 0, got_output = flush; if (size || flush) { - av_init_packet(&out_pkt); + av_packet_unref(out_pkt); } else if (st->parser->flags & PARSER_FLAG_COMPLETE_FRAMES) { // preserve 0-size sync packets compute_pkt_fields(s, st, st->parser, pkt, AV_NOPTS_VALUE, AV_NOPTS_VALUE); @@ -1428,7 +1440,7 @@ static int parse_packet(AVFormatContext *s, AVPacket *pkt, int64_t next_dts = pkt->dts; len = av_parser_parse2(st->parser, st->internal->avctx, - &out_pkt.data, &out_pkt.size, data, size, + &out_pkt->data, &out_pkt->size, data, size, pkt->pts, pkt->dts, pkt->pos); pkt->pts = pkt->dts = AV_NOPTS_VALUE; @@ -1438,39 +1450,39 @@ static int parse_packet(AVFormatContext *s, AVPacket *pkt, data = len ? data + len : data; size -= len; - got_output = !!out_pkt.size; + got_output = !!out_pkt->size; - if (!out_pkt.size) + if (!out_pkt->size) continue; - if (pkt->buf && out_pkt.data == pkt->data) { - /* reference pkt->buf only when out_pkt.data is guaranteed to point + if (pkt->buf && out_pkt->data == pkt->data) { + /* reference pkt->buf only when out_pkt->data is guaranteed to point * to data in it and not in the parser's internal buffer. */ /* XXX: Ensure this is the case with all parsers when st->parser->flags * is PARSER_FLAG_COMPLETE_FRAMES and check for that instead? */ - out_pkt.buf = av_buffer_ref(pkt->buf); - if (!out_pkt.buf) { + out_pkt->buf = av_buffer_ref(pkt->buf); + if (!out_pkt->buf) { ret = AVERROR(ENOMEM); goto fail; } } else { - ret = av_packet_make_refcounted(&out_pkt); + ret = av_packet_make_refcounted(out_pkt); if (ret < 0) goto fail; } if (pkt->side_data) { - out_pkt.side_data = pkt->side_data; - out_pkt.side_data_elems = pkt->side_data_elems; + out_pkt->side_data = pkt->side_data; + out_pkt->side_data_elems = pkt->side_data_elems; pkt->side_data = NULL; pkt->side_data_elems = 0; } /* set the duration */ - out_pkt.duration = (st->parser->flags & PARSER_FLAG_COMPLETE_FRAMES) ? pkt->duration : 0; + out_pkt->duration = (st->parser->flags & PARSER_FLAG_COMPLETE_FRAMES) ? pkt->duration : 0; if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { if (st->internal->avctx->sample_rate > 0) { - out_pkt.duration = + out_pkt->duration = av_rescale_q_rnd(st->parser->duration, (AVRational) { 1, st->internal->avctx->sample_rate }, st->time_base, @@ -1478,30 +1490,30 @@ static int parse_packet(AVFormatContext *s, AVPacket *pkt, } } - out_pkt.stream_index = st->index; - out_pkt.pts = st->parser->pts; - out_pkt.dts = st->parser->dts; - out_pkt.pos = st->parser->pos; - out_pkt.flags |= pkt->flags & AV_PKT_FLAG_DISCARD; + out_pkt->stream_index = st->index; + out_pkt->pts = st->parser->pts; + out_pkt->dts = st->parser->dts; + out_pkt->pos = st->parser->pos; + out_pkt->flags |= pkt->flags & AV_PKT_FLAG_DISCARD; if (st->need_parsing == AVSTREAM_PARSE_FULL_RAW) - out_pkt.pos = st->parser->frame_offset; + out_pkt->pos = st->parser->frame_offset; if (st->parser->key_frame == 1 || (st->parser->key_frame == -1 && st->parser->pict_type == AV_PICTURE_TYPE_I)) - out_pkt.flags |= AV_PKT_FLAG_KEY; + out_pkt->flags |= AV_PKT_FLAG_KEY; if (st->parser->key_frame == -1 && st->parser->pict_type ==AV_PICTURE_TYPE_NONE && (pkt->flags&AV_PKT_FLAG_KEY)) - out_pkt.flags |= AV_PKT_FLAG_KEY; + out_pkt->flags |= AV_PKT_FLAG_KEY; - compute_pkt_fields(s, st, st->parser, &out_pkt, next_dts, next_pts); + compute_pkt_fields(s, st, st->parser, out_pkt, next_dts, next_pts); ret = avpriv_packet_list_put(&s->internal->parse_queue, &s->internal->parse_queue_end, - &out_pkt, NULL, 0); + out_pkt, NULL, 0); if (ret < 0) { - av_packet_unref(&out_pkt); + av_packet_unref(out_pkt); goto fail; } } @@ -2377,7 +2389,7 @@ static int seek_frame_generic(AVFormatContext *s, int stream_index, return -1; if (index < 0 || index == st->internal->nb_index_entries - 1) { - AVPacket pkt; + AVPacket *pkt = s->internal->pkt; int nonkey = 0; if (st->internal->nb_index_entries) { @@ -2390,25 +2402,26 @@ static int seek_frame_generic(AVFormatContext *s, int stream_index, if ((ret = avio_seek(s->pb, s->internal->data_offset, SEEK_SET)) < 0) return ret; } + av_packet_unref(pkt); for (;;) { int read_status; do { - read_status = av_read_frame(s, &pkt); + read_status = av_read_frame(s, pkt); } while (read_status == AVERROR(EAGAIN)); if (read_status < 0) break; - if (stream_index == pkt.stream_index && pkt.dts > timestamp) { - if (pkt.flags & AV_PKT_FLAG_KEY) { - av_packet_unref(&pkt); + if (stream_index == pkt->stream_index && pkt->dts > timestamp) { + if (pkt->flags & AV_PKT_FLAG_KEY) { + av_packet_unref(pkt); break; } if (nonkey++ > 1000 && st->codecpar->codec_id != AV_CODEC_ID_CDGRAPHICS) { av_log(s, AV_LOG_ERROR,"seek_frame_generic failed as this stream seems to contain no keyframes after the target timestamp, %d non keyframes found\n", nonkey); - av_packet_unref(&pkt); + av_packet_unref(pkt); break; } } - av_packet_unref(&pkt); + av_packet_unref(pkt); } index = av_index_search_timestamp(st, timestamp, flags); } @@ -2756,7 +2769,7 @@ static void estimate_timings_from_bit_rate(AVFormatContext *ic) /* only usable for MPEG-PS streams */ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) { - AVPacket pkt1, *pkt = &pkt1; + AVPacket *pkt = ic->internal->pkt; AVStream *st; int num, den, read_size, i, ret; int found_duration = 0; @@ -3589,7 +3602,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) int64_t read_size; AVStream *st; AVCodecContext *avctx; - AVPacket pkt1; + AVPacket *pkt1 = ic->internal->pkt; int64_t old_offset = avio_tell(ic->pb); // new streams might appear, no options for those int orig_nb_streams = ic->nb_streams; @@ -3796,7 +3809,7 @@ FF_ENABLE_DEPRECATION_WARNINGS /* NOTE: A new stream can be added there if no header in file * (AVFMTCTX_NOHEADER). */ - ret = read_frame_internal(ic, &pkt1); + ret = read_frame_internal(ic, pkt1); if (ret == AVERROR(EAGAIN)) continue; @@ -3809,13 +3822,13 @@ FF_ENABLE_DEPRECATION_WARNINGS if (!(ic->flags & AVFMT_FLAG_NOBUFFER)) { ret = avpriv_packet_list_put(&ic->internal->packet_buffer, &ic->internal->packet_buffer_end, - &pkt1, NULL, 0); + pkt1, NULL, 0); if (ret < 0) goto unref_then_goto_end; pkt = &ic->internal->packet_buffer_end->pkt; } else { - pkt = &pkt1; + pkt = pkt1; } st = ic->streams[pkt->stream_index]; @@ -3895,7 +3908,7 @@ FF_ENABLE_DEPRECATION_WARNINGS limit, t, pkt->stream_index); if (ic->flags & AVFMT_FLAG_NOBUFFER) - av_packet_unref(&pkt1); + av_packet_unref(pkt1); break; } if (pkt->duration) { @@ -3932,7 +3945,7 @@ FF_ENABLE_DEPRECATION_WARNINGS (options && i < orig_nb_streams) ? &options[i] : NULL); if (ic->flags & AVFMT_FLAG_NOBUFFER) - av_packet_unref(&pkt1); + av_packet_unref(pkt1); st->codec_info_nb_frames++; count++; @@ -3965,9 +3978,9 @@ FF_ENABLE_DEPRECATION_WARNINGS } if (flush_codecs) { - AVPacket empty_pkt = { 0 }; + AVPacket *empty_pkt = ic->internal->pkt; int err = 0; - av_init_packet(&empty_pkt); + av_packet_unref(empty_pkt); for (i = 0; i < ic->nb_streams; i++) { @@ -3976,7 +3989,7 @@ FF_ENABLE_DEPRECATION_WARNINGS /* flush the decoders */ if (st->internal->info->found_decoder == 1) { do { - err = try_decode_frame(ic, st, &empty_pkt, + err = try_decode_frame(ic, st, empty_pkt, (options && i < orig_nb_streams) ? &options[i] : NULL); } while (err > 0 && !has_codec_parameters(st, NULL)); @@ -4188,7 +4201,7 @@ find_stream_info_err: return ret; unref_then_goto_end: - av_packet_unref(&pkt1); + av_packet_unref(pkt1); goto find_stream_info_err; } @@ -4452,6 +4465,7 @@ void avformat_free_context(AVFormatContext *s) av_dict_free(&s->metadata); av_dict_free(&s->internal->id3v2_meta); av_packet_free(&s->internal->pkt); + av_packet_free(&s->internal->parse_pkt); av_freep(&s->streams); flush_packet_queue(s); av_freep(&s->internal); From patchwork Fri Mar 5 16:33:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26129 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 1425A44B9E2 for ; Fri, 5 Mar 2021 18:35:52 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F3E7A68ABD8; Fri, 5 Mar 2021 18:35:51 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f182.google.com (mail-qt1-f182.google.com [209.85.160.182]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8463968AB2C for ; Fri, 5 Mar 2021 18:35:45 +0200 (EET) Received: by mail-qt1-f182.google.com with SMTP id t13so786964qta.11 for ; Fri, 05 Mar 2021 08:35:45 -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=Z/4LYWbLhQ6PYpkm6mfHH60WshYTjwMWiiA6dXNCSv0=; b=mj0YS6TDx8Jv12r7d4BgrWCRSGwAg5h7V8OANQKPv/95e47qpzSYSDs54LQRyXkA7z Tq+8XgR5FZgUrGwyeMKo1tOQW03QILlSPG40OF0yHx3xWXt2GU6TVjFFbnAg9eDWOAzo 7YEuu/Lo8n147IOtWm/Tniux2IcHl6YQWn9twj4WjHR+mrjXg6db2CFSJ6LqrPX+PO1Z LyMb0y5+P2UCx0QODYn74qwK8R4QNb003t1vBkBZvatIStvECb/mrGIKkkSyBdHzsCWS TBcUHBrwdi66PfDUYdj+W/7CekBx6Xr0KxTq61BLvLlzVKodxd3Ilu/S0vBDvMP4ihaf TUiw== 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=Z/4LYWbLhQ6PYpkm6mfHH60WshYTjwMWiiA6dXNCSv0=; b=hzEgwFHB6FxDSNwZY9Yx8JkAbno0RHvSoOCDYIdGQ2nspHw1ph+BOtq1CllQ8N5jCs VAoSuaV5rSU2d8NbYML52fdeq41jvTwrsPSljh2O8nnAXRv/KZ96vPPFK5MI8P45xGDv O+hoZ1XkkesQ6utLW6HTk5mJVq7Vwz7+xk5qHLYaGl+40mdrP2TnFdOzepP3hyNxm9cb zsHi6azTxjL1xpTQRZeoNCOvmXodprJMZg/j3Is1kuC2r0wlhF5YH8A7oXWTdMTZXtO9 BXuO2FKisUSIfQ4NL2GoAuP/MAr5zU9IJxZEFbilj7aN1h1eOg7JtTUsNv/+NpA0avsG /d4w== X-Gm-Message-State: AOAM532kMB7SnxL8keXd5Af8b4UkvTErsBK2PkcoSeHtsewb8kbam8SI cXafCDGMS1lIfsJ44NttRy0t3DvVmSc85w== X-Google-Smtp-Source: ABdhPJyqp5HMxrx/IUFAVhEVSYhG1xnyKbFfVJruZpK8Qm2zAp58SQl+QN0u5galQk3FkwrsKfrCwQ== X-Received: by 2002:ac8:4b4e:: with SMTP id e14mr9380943qts.25.1614962143978; Fri, 05 Mar 2021 08:35:43 -0800 (PST) Received: from localhost.localdomain ([181.23.89.132]) by smtp.gmail.com with ESMTPSA id b10sm2168494qtt.23.2021.03.05.08.35.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 08:35:43 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Mar 2021 13:33:05 -0300 Message-Id: <20210305163339.63164-15-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 14/48] avformat/amvenc: 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/amvenc.c | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/libavformat/amvenc.c b/libavformat/amvenc.c index 4d4ec7a2b1..5d13b618f4 100644 --- a/libavformat/amvenc.c +++ b/libavformat/amvenc.c @@ -62,8 +62,8 @@ typedef struct AMVContext int32_t aframe_size; /* Expected audio frame size. */ int32_t ablock_align; /* Expected audio block align. */ - AVPacket apad; /* Dummy audio packet for padding. */ - AVPacket vpad; /* Most recent video frame, for padding. */ + AVPacket *apad; /* Dummy audio packet for padding. */ + AVPacket *vpad; /* Most recent video frame, for padding. */ /* * Cumulative PTS values for each stream, used for the final @@ -183,16 +183,25 @@ static av_cold int amv_init(AVFormatContext *s) } /* Allocate and fill dummy packet so we can pad the audio. */ - if ((ret = av_new_packet(&amv->apad, amv->ablock_align)) < 0) + amv->apad = av_packet_alloc(); + if (!amv->apad) + return AVERROR(ENOMEM); + if ((ret = av_new_packet(amv->apad, amv->ablock_align)) < 0) { + av_packet_free(&amv->apad); return ret; + } - amv->apad.stream_index = AMV_STREAM_AUDIO; - memset(amv->apad.data, 0, amv->ablock_align); - AV_WL32(amv->apad.data + 4, amv->aframe_size); + amv->apad->stream_index = AMV_STREAM_AUDIO; + memset(amv->apad->data, 0, amv->ablock_align); + AV_WL32(amv->apad->data + 4, amv->aframe_size); - av_init_packet(&amv->vpad); - amv->vpad.stream_index = AMV_STREAM_VIDEO; - amv->vpad.duration = 1; + amv->vpad = av_packet_alloc(); + if (!amv->vpad) { + av_packet_free(&amv->apad); + return AVERROR(ENOMEM); + } + amv->vpad->stream_index = AMV_STREAM_VIDEO; + amv->vpad->duration = 1; return 0; } @@ -200,8 +209,8 @@ static void amv_deinit(AVFormatContext *s) { AMVContext *amv = s->priv_data; - av_packet_unref(&amv->apad); - av_packet_unref(&amv->vpad); + av_packet_free(&amv->apad); + av_packet_free(&amv->vpad); } static void amv_write_vlist(AVFormatContext *s, AVCodecParameters *par) @@ -325,9 +334,9 @@ static int amv_pad(AVFormatContext *s, AVPacket *pkt) stream_index = (stream_index + 1) % s->nb_streams; if (stream_index == AMV_STREAM_VIDEO) - return amv_write_packet_internal(s, &amv->vpad); + return amv_write_packet_internal(s, amv->vpad); else if (stream_index == AMV_STREAM_AUDIO) - return amv_write_packet_internal(s, &amv->apad); + return amv_write_packet_internal(s, amv->apad); else av_assert0(0); @@ -348,8 +357,8 @@ static int amv_write_packet(AVFormatContext *s, AVPacket *pkt) if (pkt->stream_index == AMV_STREAM_VIDEO) { /* Save the last packet for padding. */ - av_packet_unref(&amv->vpad); - if ((ret = av_packet_ref(&amv->vpad, pkt)) < 0) + av_packet_unref(amv->vpad); + if ((ret = av_packet_ref(amv->vpad, pkt)) < 0) return ret; } @@ -366,7 +375,7 @@ static int amv_write_trailer(AVFormatContext *s) /* Pad-out one last audio frame if needed. */ if (amv->last_stream == AMV_STREAM_VIDEO) { - if ((ret = amv_write_packet_internal(s, &amv->apad)) < 0) + if ((ret = amv_write_packet_internal(s, amv->apad)) < 0) return ret; } From patchwork Fri Mar 5 16:33:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26130 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 3D28F44B9E2 for ; Fri, 5 Mar 2021 18:35:55 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 23F1E68ABFF; Fri, 5 Mar 2021 18:35:55 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f176.google.com (mail-qt1-f176.google.com [209.85.160.176]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B873568AB77 for ; Fri, 5 Mar 2021 18:35:47 +0200 (EET) Received: by mail-qt1-f176.google.com with SMTP id d11so2146156qtx.9 for ; Fri, 05 Mar 2021 08:35:47 -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=KWxuczEind6TusVcR7SB7Rmg+Pf2eIRkzbJrNHFEUqs=; b=cj4H3R7E7fYPHT9E+nstTmY0rYWdK7C0YYazfCjG6VSHd/O2vBVhaTyCHDgQC3m+Pl fSXjB9v3ODrp8loC5F8Ma+UCts3dBo1OThy73F35k9Sr0YL0mKA0E8U0LkLDsG/1dKfy hQeEEmO9UgoziQ4oXnDnTB5L69ZGn34qrZYioQfp9HaWkZ0yW4FhRI7J90EsFGwJfbUU g9nwinSsmFb2Yl0mIgOwEQSt+qRglYCGosBHznnX+49qz/5rV47fR3M8t8Up3+F6g9iG RgU1MBghlR4TEQb8yn8oA+9POwuX1Mq75I6ObD51QqzLitcvoyk8Rup37x+KkX6SluDj zSPg== 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=KWxuczEind6TusVcR7SB7Rmg+Pf2eIRkzbJrNHFEUqs=; b=GBpy8aqm1xpkzUTS7NSMbO9zG5XQNJfpUUOSYVuRYxtNhxwaMaGWVHjh+xhmfCTtC/ dlURMMIPwxJPbchaiwub4W1QmnV47bq4g627in6Y//7RPWNVAy6D/jPe/VdVbrYLYH9O c1iudDleez2oIZIU84MsjT0Y6yMMU3+d0OySns3vDaA2lOfJfBMk3kohzVpmtHwNcU6y kEqchcZS0IjE0zM4/559Iu0jc00EmUqUrs0QH/ovkaOCHAkXhuz1FpLJUgISEn5bhu4u dGSzHMjuTm6AiiQJqucmkClbdWJdrEPNf5xFRoCEjfSE6kGrc9Klm4YPoNTCAgDyplVI s0xQ== X-Gm-Message-State: AOAM533OigUgXyJMvUAFMG4AHA8w9T+3PQ8aHvjn6ZCGK1eAE/y1HbiE eQ+WfUomRnjur5HUINaMUVuXg+mO3IkTDQ== X-Google-Smtp-Source: ABdhPJxGidc+HVHIU/MeZ7A3XBML6+QdRsUJki/dkosQy2E3t2bYRjZzPe0LjwQIEfoWy5NjwwvCsA== X-Received: by 2002:ac8:4c87:: with SMTP id j7mr9926950qtv.157.1614962145211; Fri, 05 Mar 2021 08:35:45 -0800 (PST) Received: from localhost.localdomain ([181.23.89.132]) by smtp.gmail.com with ESMTPSA id b10sm2168494qtt.23.2021.03.05.08.35.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 08:35:44 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Mar 2021 13:33:06 -0300 Message-Id: <20210305163339.63164-16-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 15/48] avformat/asfdec_o: 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/asfdec_o.c | 63 ++++++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 27 deletions(-) diff --git a/libavformat/asfdec_o.c b/libavformat/asfdec_o.c index c1d90360b4..34ae541934 100644 --- a/libavformat/asfdec_o.c +++ b/libavformat/asfdec_o.c @@ -63,7 +63,7 @@ typedef struct GUIDParseTable { } GUIDParseTable; typedef struct ASFPacket { - AVPacket avpkt; + AVPacket *avpkt; int64_t dts; uint32_t frame_num; // ASF payloads with the same number are parts of the same frame int flags; @@ -781,8 +781,10 @@ static int asf_read_stream_properties(AVFormatContext *s, const GUIDParseTable * asf_st->index = st->index; asf_st->indexed = 0; st->id = flags & ASF_STREAM_NUM; - av_init_packet(&asf_st->pkt.avpkt); asf_st->pkt.data_size = 0; + asf_st->pkt.avpkt = av_packet_alloc(); + if (!asf_st->pkt.avpkt) + return AVERROR(ENOMEM); avio_skip(pb, 4); // skip reserved field switch (type) { @@ -1140,7 +1142,7 @@ static void reset_packet(ASFPacket *asf_pkt) asf_pkt->duration = 0; asf_pkt->flags = 0; asf_pkt->dts = 0; - av_packet_unref(&asf_pkt->avpkt); + av_packet_unref(asf_pkt->avpkt); } static int asf_read_replicated_data(AVFormatContext *s, ASFPacket *asf_pkt) @@ -1153,7 +1155,7 @@ static int asf_read_replicated_data(AVFormatContext *s, ASFPacket *asf_pkt) data_size = avio_rl32(pb); // read media object size if (data_size <= 0) return AVERROR_INVALIDDATA; - if ((ret = av_new_packet(&asf_pkt->avpkt, data_size)) < 0) + if ((ret = av_new_packet(asf_pkt->avpkt, data_size)) < 0) return ret; asf_pkt->data_size = asf_pkt->size_left = data_size; } else @@ -1194,7 +1196,7 @@ static int asf_read_multiple_payload(AVFormatContext *s, AVPacket *pkt, pay_len, asf->packet_size, avio_tell(pb)); return AVERROR_INVALIDDATA; } - p = asf_pkt->avpkt.data + asf_pkt->data_size - asf_pkt->size_left; + p = asf_pkt->avpkt->data + asf_pkt->data_size - asf_pkt->size_left; if (pay_len > asf_pkt->size_left) { av_log(s, AV_LOG_ERROR, "Error: invalid buffer size, pay_len %d, data size left %d.\n", @@ -1229,7 +1231,7 @@ static int asf_read_single_payload(AVFormatContext *s, ASFPacket *asf_pkt) data_size = avio_rl32(pb); // read media object size if (data_size <= 0) return AVERROR_EOF; - if ((ret = av_new_packet(&asf_pkt->avpkt, data_size)) < 0) + if ((ret = av_new_packet(asf_pkt->avpkt, data_size)) < 0) return ret; asf_pkt->data_size = asf_pkt->size_left = data_size; } else @@ -1250,7 +1252,7 @@ static int asf_read_single_payload(AVFormatContext *s, ASFPacket *asf_pkt) avio_tell(pb)); return AVERROR_INVALIDDATA; } - p = asf_pkt->avpkt.data + asf_pkt->data_size - asf_pkt->size_left; + p = asf_pkt->avpkt->data + asf_pkt->data_size - asf_pkt->size_left; if (size > asf_pkt->size_left || asf_pkt->size_left <= 0) return AVERROR_INVALIDDATA; if (asf_pkt->size_left > size) @@ -1387,16 +1389,18 @@ static int asf_deinterleave(AVFormatContext *s, ASFPacket *asf_pkt, int st_num) { ASFContext *asf = s->priv_data; ASFStream *asf_st = asf->asf_st[st_num]; - unsigned char *p = asf_pkt->avpkt.data; + unsigned char *p = asf_pkt->avpkt->data; uint16_t pkt_len = asf->asf_st[st_num]->virtual_pkt_len; uint16_t chunk_len = asf->asf_st[st_num]->virtual_chunk_len; int nchunks = pkt_len / chunk_len; - AVPacket pkt; + uint8_t *data; int pos = 0, j, l, ret; - if ((ret = av_new_packet(&pkt, asf_pkt->data_size)) < 0) - return ret; + data = av_malloc(asf_pkt->data_size + AV_INPUT_BUFFER_PADDING_SIZE); + if (!data) + return AVERROR(ENOMEM); + memset(data + asf_pkt->data_size, 0, AV_INPUT_BUFFER_PADDING_SIZE); while (asf_pkt->data_size >= asf_st->span * pkt_len + pos) { if (pos >= asf_pkt->data_size) { @@ -1409,20 +1413,22 @@ static int asf_deinterleave(AVFormatContext *s, ASFPacket *asf_pkt, int st_num) for (j = 0; j < asf_st->span; j++) { if ((pos + chunk_len) >= asf_pkt->data_size) break; - memcpy(pkt.data + pos, + memcpy(data + pos, p + (j * nchunks + l) * chunk_len, chunk_len); pos += chunk_len; } } p += asf_st->span * pkt_len; - if (p > asf_pkt->avpkt.data + asf_pkt->data_size) + if (p > asf_pkt->avpkt->data + asf_pkt->data_size) break; } - av_packet_unref(&asf_pkt->avpkt); - asf_pkt->avpkt = pkt; + av_packet_unref(asf_pkt->avpkt); + ret = av_packet_from_data(asf_pkt->avpkt, data, asf_pkt->data_size); + if (ret < 0) + av_free(data); - return 0; + return ret; } static int asf_read_packet(AVFormatContext *s, AVPacket *pkt) @@ -1492,7 +1498,7 @@ static int asf_read_packet(AVFormatContext *s, AVPacket *pkt) asf->asf_st[i]->type == AVMEDIA_TYPE_AUDIO) if ((ret = asf_deinterleave(s, asf_pkt, i)) < 0) return ret; - av_packet_move_ref(pkt, &asf_pkt->avpkt); + av_packet_move_ref(pkt, asf_pkt->avpkt); pkt->stream_index = asf->asf_st[i]->index; pkt->flags = asf_pkt->flags; pkt->dts = asf_pkt->dts - asf->preroll; @@ -1517,7 +1523,7 @@ static int asf_read_close(AVFormatContext *s) for (i = 0; i < ASF_MAX_STREAMS; i++) { av_dict_free(&asf->asf_sd[i].asf_met); if (i < asf->nb_streams) { - av_packet_unref(&asf->asf_st[i]->pkt.avpkt); + av_packet_free(&asf->asf_st[i]->pkt.avpkt); av_freep(&asf->asf_st[i]); } } @@ -1567,9 +1573,12 @@ static int64_t asf_read_timestamp(AVFormatContext *s, int stream_index, { ASFContext *asf = s->priv_data; int64_t pkt_pos = *pos, pkt_offset, dts = AV_NOPTS_VALUE, data_end; - AVPacket pkt; + AVPacket *pkt = av_packet_alloc(); int n; + if (!pkt) + return AVERROR(ENOMEM); + data_end = asf->data_offset + asf->data_size; n = (pkt_pos - asf->first_packet_offset + asf->packet_size - 1) / @@ -1585,9 +1594,9 @@ static int64_t asf_read_timestamp(AVFormatContext *s, int stream_index, int i, ret, st_found; - av_init_packet(&pkt); pkt_offset = avio_tell(s->pb); - if ((ret = asf_read_packet(s, &pkt)) < 0) { + if ((ret = asf_read_packet(s, pkt)) < 0) { + av_packet_free(&pkt); dts = AV_NOPTS_VALUE; return ret; } @@ -1599,11 +1608,11 @@ static int64_t asf_read_timestamp(AVFormatContext *s, int stream_index, ASFStream *st = asf->asf_st[i]; st_found = 0; - if (pkt.flags & AV_PKT_FLAG_KEY) { - dts = pkt.dts; + if (pkt->flags & AV_PKT_FLAG_KEY) { + dts = pkt->dts; if (dts) { - av_add_index_entry(s->streams[pkt.stream_index], pkt_pos, - dts, pkt.size, 0, AVINDEX_KEYFRAME); + av_add_index_entry(s->streams[pkt->stream_index], pkt_pos, + dts, pkt->size, 0, AVINDEX_KEYFRAME); if (stream_index == st->index) { st_found = 1; break; @@ -1613,11 +1622,11 @@ static int64_t asf_read_timestamp(AVFormatContext *s, int stream_index, } if (st_found) break; - av_packet_unref(&pkt); + av_packet_unref(pkt); } *pos = pkt_pos; - av_packet_unref(&pkt); + av_packet_free(&pkt); return dts; } From patchwork Fri Mar 5 16:33:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26131 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 1624044B9E2 for ; Fri, 5 Mar 2021 18:35:56 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EF4C368AC11; Fri, 5 Mar 2021 18:35:55 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qv1-f45.google.com (mail-qv1-f45.google.com [209.85.219.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 087D668AB82 for ; Fri, 5 Mar 2021 18:35:47 +0200 (EET) Received: by mail-qv1-f45.google.com with SMTP id h7so1286689qvm.2 for ; Fri, 05 Mar 2021 08:35:47 -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=x+sRhAbd6EvfwnhSWVTvdyw4K1dMoAIfHmwWaw8+ptI=; b=cznKWeOuBr42pky/nWfMgHefyu4W09sWjpMA9CLQZPAOM0FKKBqHQwctFJFqfUKHbl DjNiRAEXmV192r79K8wmeeDOxXoFHHXpWRYKVPiATwtVpbpjKMPwj0DzvUfXBQSgeIZ/ xqHx+1dh9Wn8DdDX+/N7bfH38Dt6J0s+cDDwFLCuzB4pYBXWEfJ908rlcgCzoNIdKAqV +l7FNK5hVr8yFzrFEtLO0P2sko6A2zOkNvxXWLdw075ouSHtTHDf+lgQglFROc91AROR fj5wpQnmd/pb6d5Dlkb9jhNJHWD3JUsg9wS427UG/FYmm6lh1zjF7rMnktnAWD3Ym/em 5Lkw== 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=x+sRhAbd6EvfwnhSWVTvdyw4K1dMoAIfHmwWaw8+ptI=; b=OItZ4OLffMkklvVR7EPenmy2raKbHKqXFTFyFp4zDutd4Ioj7NxWqMXhj8hB24Ityy fJjXS4wyzozLuq15NNhadNOExbwWgC4h87w20m1zybH/LFz997aE8f7BsVFvEUQl7jQu D+qYUv3y32yhEfz3X5ZJvB93LrhwBF0syUNfPuNFB0CyZcew00X4/aEeVmEXPDghydyO j48KH9p7gW3l6Um18zzo04vz0mjalOmZkRezTD79sU/EIu4zVmlUH2rucyMtsQfWAZoX gZUsCQMmKD2YGznjd1Ns9NnUSA4zO9XyK26u55jBLD0o7Stv3AB1fJrculsDl+TUf5v4 QNOw== X-Gm-Message-State: AOAM533g/fKPuO/m4tBY6mDvwk7r65Q7BxZZfsvdJ/0LTr3QmpSJtDgx /wSNCGTTql/m2BABmHnlhKdZdKydM3+3lQ== X-Google-Smtp-Source: ABdhPJwTrEgbioh8AoWXds5YYEtKJngyclJUtJDJXZuaUn7bJij132xHAk6nQOVdD2FEfg57MOvE5Q== X-Received: by 2002:a0c:b752:: with SMTP id q18mr9538387qve.55.1614962146454; Fri, 05 Mar 2021 08:35:46 -0800 (PST) Received: from localhost.localdomain ([181.23.89.132]) by smtp.gmail.com with ESMTPSA id b10sm2168494qtt.23.2021.03.05.08.35.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 08:35:46 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Mar 2021 13:33:07 -0300 Message-Id: <20210305163339.63164-17-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 16/48] avformat/avidec: 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/avidec.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/libavformat/avidec.c b/libavformat/avidec.c index 5ea6160eef..fa0599501a 100644 --- a/libavformat/avidec.c +++ b/libavformat/avidec.c @@ -59,7 +59,7 @@ typedef struct AVIStream { * the MS dshow demuxer */ AVFormatContext *sub_ctx; - AVPacket sub_pkt; + AVPacket *sub_pkt; AVBufferRef *sub_buffer; int64_t seek_pos; @@ -1130,6 +1130,9 @@ static int read_gab2_sub(AVFormatContext *s, AVStream *st, AVPacket *pkt) if (strcmp(sub_demuxer->name, "srt") && strcmp(sub_demuxer->name, "ass")) goto error; + if (!(ast->sub_pkt = av_packet_alloc())) + goto error; + if (!(ast->sub_ctx = avformat_alloc_context())) goto error; @@ -1141,7 +1144,7 @@ static int read_gab2_sub(AVFormatContext *s, AVStream *st, AVPacket *pkt) if (!avformat_open_input(&ast->sub_ctx, "", sub_demuxer, NULL)) { if (ast->sub_ctx->nb_streams != 1) goto error; - ff_read_packet(ast->sub_ctx, &ast->sub_pkt); + ff_read_packet(ast->sub_ctx, ast->sub_pkt); avcodec_parameters_copy(st->codecpar, ast->sub_ctx->streams[0]->codecpar); time_base = ast->sub_ctx->streams[0]->time_base; avpriv_set_pts_info(st, 64, time_base.num, time_base.den); @@ -1152,6 +1155,7 @@ static int read_gab2_sub(AVFormatContext *s, AVStream *st, AVPacket *pkt) return 1; error: + av_packet_free(&ast->sub_pkt); av_freep(&ast->sub_ctx); avio_context_free(&pb); } @@ -1172,8 +1176,8 @@ static AVStream *get_subtitle_pkt(AVFormatContext *s, AVStream *next_st, for (i = 0; i < s->nb_streams; i++) { st = s->streams[i]; ast = st->priv_data; - if (st->discard < AVDISCARD_ALL && ast && ast->sub_pkt.data) { - ts = av_rescale_q(ast->sub_pkt.dts, st->time_base, AV_TIME_BASE_Q); + if (st->discard < AVDISCARD_ALL && ast && ast->sub_pkt && ast->sub_pkt->data) { + ts = av_rescale_q(ast->sub_pkt->dts, st->time_base, AV_TIME_BASE_Q); if (ts <= next_ts && ts < ts_min) { ts_min = ts; sub_st = st; @@ -1183,11 +1187,11 @@ static AVStream *get_subtitle_pkt(AVFormatContext *s, AVStream *next_st, if (sub_st) { ast = sub_st->priv_data; - *pkt = ast->sub_pkt; + av_packet_move_ref(pkt, ast->sub_pkt); pkt->stream_index = sub_st->index; - if (ff_read_packet(ast->sub_ctx, &ast->sub_pkt) < 0) - ast->sub_pkt.data = NULL; + if (ff_read_packet(ast->sub_ctx, ast->sub_pkt) < 0) + ast->sub_pkt->data = NULL; } return sub_st; } @@ -1806,10 +1810,10 @@ static void seek_subtitle(AVStream *st, AVStream *st2, int64_t timestamp) { AVIStream *ast2 = st2->priv_data; int64_t ts2 = av_rescale_q(timestamp, st->time_base, st2->time_base); - av_packet_unref(&ast2->sub_pkt); + av_packet_unref(ast2->sub_pkt); if (avformat_seek_file(ast2->sub_ctx, 0, INT64_MIN, ts2, ts2, 0) >= 0 || avformat_seek_file(ast2->sub_ctx, 0, ts2, ts2, INT64_MAX, 0) >= 0) - ff_read_packet(ast2->sub_ctx, &ast2->sub_pkt); + ff_read_packet(ast2->sub_ctx, ast2->sub_pkt); } static int avi_read_seek(AVFormatContext *s, int stream_index, @@ -1943,7 +1947,7 @@ static int avi_read_close(AVFormatContext *s) avformat_close_input(&ast->sub_ctx); } av_buffer_unref(&ast->sub_buffer); - av_packet_unref(&ast->sub_pkt); + av_packet_free(&ast->sub_pkt); } } From patchwork Fri Mar 5 16:33:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26138 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 6D2A144BAEC for ; Fri, 5 Mar 2021 18:38:58 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DBD7268AC21; Fri, 5 Mar 2021 18:35:56 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f179.google.com (mail-qt1-f179.google.com [209.85.160.179]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1EE2B68AB99 for ; Fri, 5 Mar 2021 18:35:49 +0200 (EET) Received: by mail-qt1-f179.google.com with SMTP id 18so2182532qty.3 for ; Fri, 05 Mar 2021 08:35:49 -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=ZfY4P8XzchbQTr36MU3lGLT7xvKlAVteopRvXa+PgLo=; b=F177qv60dI4r/USQNiad3q/4XcFeZQkiKtweQapOQgv95GNwmZqdcvB+gWG2Q/UimV T2sXe1pf4XZpB2BpX/g/ZLnnGelh99gw8fuJbTnVbIJdi6BN2vZitnB/Kf3dOWcMl2Wv KFC5Nw5f5bWzT863BgRPX5MWiUTBSqe1JXa0rL0K6WVDE5Hp5OnFxD1K+4sETBTcY4/z bQFL/pmpV7MbHbjNEwxySgwvEpwY6V67ITNMRJlgOn0t/B352soRiL3VOhw2cH8nOJvV 5MWS0vJAG9G9dh7gQWbRHRg4CKqXQhphuD2OwsbpUcfLRE0DJBoTLcaJqrrOZ4b3PxmS 894w== 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=ZfY4P8XzchbQTr36MU3lGLT7xvKlAVteopRvXa+PgLo=; b=YIUgfN/oFJ4Tp5T9/9nk6U9EZ3IKrQe6d7ZaYKSDOadE26obk7vPkuvjYCXFOUDYIo uvpNZRvk4ODFsDGfMl9ldgPqQPvQsK7mfBwAVkbd2OvowjHG0Futo5S+6gow82ddS4pU jNmbGSZAkQjjo93zgDaA8XQsW6QuoFZ8qEYx9uzd11FWsanzQ1YjUTfs+m3KgUI5iCY0 yEIUu2gVD/8MeyyX6qRigmImR4dmdOl/7lFhvCMOGF+yspyyUqoOm4MjYHLOaVtNRTdG 8oPCeYJoTlK9MfNIQ7+Yu2Cle1xFgph3WqBWSEisiwbGTgvpP5CEOQa84P3dRs3wBXZ4 ycgw== X-Gm-Message-State: AOAM530BKeZHM4VV80W/vAKy7IcD5FcOHoN8oqYljsH769yJfigqrQdP 7r5x9h1b0VGMHPKdbXnIINsknD+LUHKArQ== X-Google-Smtp-Source: ABdhPJyUOt59xh+t4/nsKhM4ypyse+fLZULkqctttU7nPiG8oHAvgZR5yAEfEH1sVCbl15Kj/V0bxw== X-Received: by 2002:a05:622a:552:: with SMTP id m18mr9795308qtx.207.1614962147646; Fri, 05 Mar 2021 08:35:47 -0800 (PST) Received: from localhost.localdomain ([181.23.89.132]) by smtp.gmail.com with ESMTPSA id b10sm2168494qtt.23.2021.03.05.08.35.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 08:35:47 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Mar 2021 13:33:08 -0300 Message-Id: <20210305163339.63164-18-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 17/48] avformat/avienc: 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/avienc.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/libavformat/avienc.c b/libavformat/avienc.c index 9cbf3d3349..ac11dd9cb2 100644 --- a/libavformat/avienc.c +++ b/libavformat/avienc.c @@ -66,6 +66,7 @@ typedef struct AVIIndex { typedef struct AVIContext { const AVClass *class; + AVPacket *empty_packet; int64_t riff_start, movi_list, odml_list; int64_t frames_hdr_all; int riff_id; @@ -274,6 +275,10 @@ static int avi_write_header(AVFormatContext *s) return AVERROR(EINVAL); } + avi->empty_packet = av_packet_alloc(); + if (!avi->empty_packet) + return AVERROR(ENOMEM); + for (n = 0; n < s->nb_streams; n++) { s->streams[n]->priv_data = av_mallocz(sizeof(AVIStream)); if (!s->streams[n]->priv_data) @@ -739,24 +744,21 @@ static int avi_write_idx1(AVFormatContext *s) static int write_skip_frames(AVFormatContext *s, int stream_index, int64_t dts) { + AVIContext *avi = s->priv_data; AVIStream *avist = s->streams[stream_index]->priv_data; AVCodecParameters *par = s->streams[stream_index]->codecpar; ff_dlog(s, "dts:%s packet_count:%d stream_index:%d\n", av_ts2str(dts), avist->packet_count, stream_index); while (par->block_align == 0 && dts != AV_NOPTS_VALUE && dts > avist->packet_count && par->codec_id != AV_CODEC_ID_XSUB && avist->packet_count) { - AVPacket empty_packet; if (dts - avist->packet_count > 60000) { av_log(s, AV_LOG_ERROR, "Too large number of skipped frames %"PRId64" > 60000\n", dts - avist->packet_count); return AVERROR(EINVAL); } - av_init_packet(&empty_packet); - empty_packet.size = 0; - empty_packet.data = NULL; - empty_packet.stream_index = stream_index; - avi_write_packet_internal(s, &empty_packet); + avi->empty_packet->stream_index = stream_index; + avi_write_packet_internal(s, avi->empty_packet); ff_dlog(s, "dup dts:%s packet_count:%d\n", av_ts2str(dts), avist->packet_count); } @@ -978,6 +980,10 @@ static int avi_write_trailer(AVFormatContext *s) static void avi_deinit(AVFormatContext *s) { + AVIContext *avi = s->priv_data; + + av_packet_free(&avi->empty_packet); + for (int i = 0; i < s->nb_streams; i++) { AVIStream *avist = s->streams[i]->priv_data; if (!avist) From patchwork Fri Mar 5 16:33:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26140 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 7C6C344BC27 for ; Fri, 5 Mar 2021 18:39:09 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F289A68AB8E; Fri, 5 Mar 2021 18:35:57 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f182.google.com (mail-qk1-f182.google.com [209.85.222.182]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5B02A68ABB7 for ; Fri, 5 Mar 2021 18:35:50 +0200 (EET) Received: by mail-qk1-f182.google.com with SMTP id b130so2518543qkc.10 for ; Fri, 05 Mar 2021 08:35:50 -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=zYZNVZzv3r/6Olcs6nxQC1ysPvOFJT3S18JAxVU6Gxk=; b=XEMkRaakWefugTAx/XVJ/7xL895e6nWb6Z3s2n1DzHe70DvML7Gv9lP+kAyD4RFusn +8f4XXundwswSoKWVLHWRfx4kwWlKpp+0cmdFUuA4ZlzqDnnwJuPbhabFO3X2a2RVfsR d2Eov5NUSjEy1h3kWFtPmaPZxys/7LGRv5q0yiZxgiwUb1KiTjxorJbEoK25wS1caK55 gKZDcVpP4y2JNsD4HR0j4u5w8LrgMdi2kXmhpcORp1KohCUscaKbRB7CsyQm4cfNVL2t IOK1hmZi2t1wtZT+7GVsCiC4joi8y7M+JplNqwOVlrjcOrdmJkfZTs7KuuzYxyWrwo/K hF9Q== 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=zYZNVZzv3r/6Olcs6nxQC1ysPvOFJT3S18JAxVU6Gxk=; b=T9dIbvnNUh25kanowKwneqEoM8VQ6tqNNYQHsI0sIU4ipEp/LkdmW7RczGzfeDeO8A uua1R3PzCreKKFCmMPDzdf+rJpk2LbjJi66bPXMFSSuP+k/z8bwAD65EIdRYZ0MMuY2h Hy4LUcP7VjTNZgtCLw+DOhGu3Yd4LuYbGVscW4sgTiDbs56dEkf94R6NSUZuntCWv/Lf IaFr7CIUw2WmR0FVvIqV+NW4MBgT4xv0lsgxqjQKTuIyBYBgeJYfB/gAHwLEwXC+AnI2 fQ8f17gXdSEY4YvEPgeFQmKUl5OshwPOxL3CQCyYy6+TEbZFdHQa/erZi07W7gCc38yJ BAhg== X-Gm-Message-State: AOAM531aD+sOGcPEnbmo29DMSLGr/M+cuIv6LXlBmCG9XNCSDT3iNFZH 0ZdddMBZSfPY7p2Arcz8DflC/hNPacIvfA== X-Google-Smtp-Source: ABdhPJy1/3P5j1758qPWUIIrFB67Izru49zcLpEiqkgm81D9iJ1DSx/xQ5Q8/1TKIxMs3YQk5mNt9Q== X-Received: by 2002:a37:4986:: with SMTP id w128mr9532069qka.313.1614962148824; Fri, 05 Mar 2021 08:35:48 -0800 (PST) Received: from localhost.localdomain ([181.23.89.132]) by smtp.gmail.com with ESMTPSA id b10sm2168494qtt.23.2021.03.05.08.35.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 08:35:48 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Mar 2021 13:33:09 -0300 Message-Id: <20210305163339.63164-19-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 18/48] avformat/flac_picture: replace call to av_init_packet() 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/flac_picture.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/flac_picture.c b/libavformat/flac_picture.c index 53e24b28b7..f15cfa877a 100644 --- a/libavformat/flac_picture.c +++ b/libavformat/flac_picture.c @@ -165,7 +165,7 @@ int ff_flac_parse_picture(AVFormatContext *s, uint8_t *buf, int buf_size, int tr RETURN_ERROR(AVERROR(ENOMEM)); } - av_init_packet(&st->attached_pic); + av_packet_unref(&st->attached_pic); st->attached_pic.buf = data; st->attached_pic.data = data->data; st->attached_pic.size = len; From patchwork Fri Mar 5 16:33:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26141 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 C2EEA44BC27 for ; Fri, 5 Mar 2021 18:39:21 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BCDA768AC1E; Fri, 5 Mar 2021 18:35:58 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f174.google.com (mail-qk1-f174.google.com [209.85.222.174]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5B6B768ABC8 for ; Fri, 5 Mar 2021 18:35:51 +0200 (EET) Received: by mail-qk1-f174.google.com with SMTP id l4so2581928qkl.0 for ; Fri, 05 Mar 2021 08:35: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=ax/RLOYmxdMScRKnIGHvUqHZ2RZtuUr/JLxYnxoIUHU=; b=nyuVlch7rBRfGZ9HBmL4pKGp9slCbfBNzxpMDnVgdKcvKJXVbksIHl4RjHKlCpb7wt hNRi2W5Lan9pbwKz8yTwjE+boVXkKU+qkbxX41YFk9KGxXLCn9j3W46XSUc9HhR3MIhs cqlN2lk95HAXAir6D8WtFy/+qd1kjkssYQkCe+uUjfb/ndjp4EBVMDcfCa9jEaEStwci rYzGH1XRDb3/5EVZ0qssIrwq+4CBWPzxTCjuuBu1HGObx0uCxsA+JyHHwhJIa7mb3GTQ hRLMm9xidW4PhV4ZqjYei96vkOCXRJ3MMdU4nRYQoEiYoTlhIwmS9fMyVX9NK52IWray ht+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=ax/RLOYmxdMScRKnIGHvUqHZ2RZtuUr/JLxYnxoIUHU=; b=AIGg36DFrcs7KS38RmXupru50EnCfqZ90wSxa/nY1pr8EvkLpgQob/4cOlOA5Ul9SJ XC7lOQrAOk7MKtEYC8EYdBVNkq/JKuCxwGRUsv/CnKOo2kOk7/2B4Im5BzgB7DGFn8iJ /vMu3LJ5k+mEN9Zh3LllMPJhjI5GD2L5+ntBFdmM6J/+UTNCqqZKjiglkYlzD1R9mdqO Rn+Xjss7eUhMtm7eRq11SjDLbSkVWqwvgE8sysIb7dl8FwQT2FuUHlpRVHD9079On5sN JOXlwmqpe2+LMSpDpv+o/KBJ9TgM2IoIqYh9BqDpbP3d/HtUGW/2oALQd3hLSa/h1UbZ 1QqQ== X-Gm-Message-State: AOAM533avYk/YFasLEniTFSlAAoXFFLF83WQLtxMsqLmZnfKugmjtxEt sT2RObqJimaF57mM061ppEeXSkJWXQL7Eg== X-Google-Smtp-Source: ABdhPJyVm/n9jMEcpcPySi2Gr6Q9c8uuO95Ma6d/lbx01hV15VN3KAOjCcI/TYPF+MhaGVByyxe7sA== X-Received: by 2002:a37:4690:: with SMTP id t138mr9945366qka.394.1614962149977; Fri, 05 Mar 2021 08:35:49 -0800 (PST) Received: from localhost.localdomain ([181.23.89.132]) by smtp.gmail.com with ESMTPSA id b10sm2168494qtt.23.2021.03.05.08.35.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 08:35:49 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Mar 2021 13:33:10 -0300 Message-Id: <20210305163339.63164-20-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 19/48] avformat/id3v2: replace call to av_init_packet() 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/id3v2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/id3v2.c b/libavformat/id3v2.c index df11b5450c..f33b7ba93a 100644 --- a/libavformat/id3v2.c +++ b/libavformat/id3v2.c @@ -1162,7 +1162,7 @@ int ff_id3v2_parse_apic(AVFormatContext *s, ID3v2ExtraMeta *extra_meta) av_dict_set(&st->metadata, "comment", apic->type, 0); - av_init_packet(&st->attached_pic); + av_packet_unref(&st->attached_pic); st->attached_pic.buf = apic->buf; st->attached_pic.data = apic->buf->data; st->attached_pic.size = apic->buf->size - AV_INPUT_BUFFER_PADDING_SIZE; From patchwork Fri Mar 5 16:33:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26142 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 4112344BC27 for ; Fri, 5 Mar 2021 18:39:34 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7FC5D68AC1A; Fri, 5 Mar 2021 18:35:59 +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 C375868ABE7 for ; Fri, 5 Mar 2021 18:35:52 +0200 (EET) Received: by mail-qt1-f180.google.com with SMTP id w1so2182759qto.2 for ; Fri, 05 Mar 2021 08:35:52 -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=LF6MHAPVonmICuZKnuz8T4CIlsPCDxtATsSLIY/GrUg=; b=ZvYZVTu0ygmvQIZN0gu/02KCUYEaPWgOldF0Baf80vMsg8UE1XjysDWw0h3WJolN8b ilD9f7blc8idAxzobHrW3ydfO+JKm0vmPNCnjxnsuA/CcJrGJNIpY5UISDbaxq3eWzz0 JGtJUoVPRvTwej0I8hAnieqAbF1sIArqgFI75EXCHA2nZeubNdjMSIexTwYs7OwSlC5Q HEE/o2cTw6b0P1RQ1MPnpxvynvcBKnQhe7/JKKjZyWlYQ8Gz18439au6tQRBbuk1fHtt WTINYwdaf4oB/Ivkv7V6/WVMedz9tf7xCWCyHH1Jkb2orEKd7KVtqrJs0H3lobi9xKW2 TE1g== 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=LF6MHAPVonmICuZKnuz8T4CIlsPCDxtATsSLIY/GrUg=; b=Z/V//7DV5SylR6QA00O6NqLv47XF68j9Q5kY9wGWNarp5/T0N+WNwj9YooGx2mdNcA 4wM46Uilj8MBziYEeFbxerEEdjlOesi6Wwuxosq+/lz6XpDD46jbtzBMoUmJZz7lbVJ8 tbnHL66r3k+/9/ZgeCJDp65Hn0f929fPFmnFsDcs6kdBIxp50fdN3cueZz/Wy7FNq3Fj 8R99AdMmerPWz2RP+ooZCWFKXpl/a93HK4r10X4mCMOOA/iTJHvJXkxk5WvFSbDT0xEK 7XVnYckF6Rj3J9+AGkq3rCBZNwGdNBLtQsoHE5VS5cvPy2lwg5o4QDkRkyikO5PA1rbe oDjw== X-Gm-Message-State: AOAM530rh1+QSdrdQb7XQ9fHdE0nUZtk1ZlyQsqVo1BmM/1cYTaxWa8e tgdKx+sJT1HHgEi7YCzU7Yxvz6qvveA4Zg== X-Google-Smtp-Source: ABdhPJykLzszSnl0pFZmxrwr6Sx55kKq7dodkcx1ynojvzZhYTww5cR5SQDFYAeLIbNOG+OI7mM1AA== X-Received: by 2002:a05:622a:44d:: with SMTP id o13mr9483582qtx.378.1614962151232; Fri, 05 Mar 2021 08:35:51 -0800 (PST) Received: from localhost.localdomain ([181.23.89.132]) by smtp.gmail.com with ESMTPSA id b10sm2168494qtt.23.2021.03.05.08.35.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 08:35:50 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Mar 2021 13:33:11 -0300 Message-Id: <20210305163339.63164-21-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 20/48] avformat/flacdec: 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/flacdec.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/libavformat/flacdec.c b/libavformat/flacdec.c index 6aca4755a1..f7b21986dc 100644 --- a/libavformat/flacdec.c +++ b/libavformat/flacdec.c @@ -259,7 +259,7 @@ static int flac_probe(const AVProbeData *p) static av_unused int64_t flac_read_timestamp(AVFormatContext *s, int stream_index, int64_t *ppos, int64_t pos_limit) { - AVPacket pkt; + AVPacket *pkt = s->internal->parse_pkt; AVStream *st = s->streams[stream_index]; AVCodecParserContext *parser; int ret; @@ -268,7 +268,6 @@ static av_unused int64_t flac_read_timestamp(AVFormatContext *s, int stream_inde if (avio_seek(s->pb, *ppos, SEEK_SET) < 0) return AV_NOPTS_VALUE; - av_init_packet(&pkt); parser = av_parser_init(st->codecpar->codec_id); if (!parser){ return AV_NOPTS_VALUE; @@ -279,20 +278,20 @@ static av_unused int64_t flac_read_timestamp(AVFormatContext *s, int stream_inde uint8_t *data; int size; - ret = ff_raw_read_partial_packet(s, &pkt); + ret = ff_raw_read_partial_packet(s, pkt); if (ret < 0){ if (ret == AVERROR(EAGAIN)) continue; else { - av_packet_unref(&pkt); - av_assert1(!pkt.size); + av_packet_unref(pkt); + av_assert1(!pkt->size); } } av_parser_parse2(parser, st->internal->avctx, - &data, &size, pkt.data, pkt.size, - pkt.pts, pkt.dts, *ppos); + &data, &size, pkt->data, pkt->size, + pkt->pts, pkt->dts, *ppos); - av_packet_unref(&pkt); + av_packet_unref(pkt); if (size) { if (parser->pts != AV_NOPTS_VALUE){ // seeking may not have started from beginning of a frame From patchwork Fri Mar 5 16:33:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26143 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 7BC8144BC27 for ; Fri, 5 Mar 2021 18:39:45 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 64D1668AC3A; Fri, 5 Mar 2021 18:36:00 +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 2D15168AB3B for ; Fri, 5 Mar 2021 18:35:54 +0200 (EET) Received: by mail-qt1-f178.google.com with SMTP id v64so2168629qtd.5 for ; Fri, 05 Mar 2021 08:35:53 -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=MCd5ldjYGtno1aAoY/MnQvAdkHUXhzUEr2DEHTVFIvo=; b=UdnojGks6/hD2GLn+6v8QdL2JMfuI3geY9u+dUNFtBNwfZBkM1OfVbYy3MNKHvx7X8 f2gr3vtkgL5yVOHTZcx0gQ03hwqcJB9cVnX6v3dD0j9Hxa8jAkzLWJ4x0MaRIldvCsmR drzEWPYUGS12KE4PUI55AtwWPcZ4n9cUEhWgkrGLgYs+41pjTVbBXZFFB73MvsS1eNqg +OffMv3q/Vjc+EsQ2KQHl20VHv9GzkNujWr0YEpWBAAu7gPG0NenhYqkBHqTpevdLNlD 9omLxsYfhyi6Jz63nA9vcbyHgq22Mw2Z9ljy2fhg1KxFQenSgbpQ8HftDkGCuBP5ygwU RRvA== 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=MCd5ldjYGtno1aAoY/MnQvAdkHUXhzUEr2DEHTVFIvo=; b=uWGdgbIrwRVFV1DT37ZO9CZWhLK2l5Z0L9WjL9DBpXMA4mVvrJdks9VJbC1V9SY5QI BpbzEFdSFKElHmq/9+gzlS6qZdYYEY5V6b+inahn2eO6RB2rvquFEqAXkUdUdctItxEZ 3uONvVMwPgaSRTctqPBiPuJED1GYKi+G3GiUNGe21z/sOpNHPjrWWvI8DucPgjLNA/pq i9qwhRIp25lq1I8aVd4AIOmNv+orP6mlFL/VYYS/L5aJCaBLmyG4xHtzeEjmLf/iQSBk opK46OOA0Q1itqUDaYMwg2qxKtGtdGNkoqohjegg/+SNmFtSqA/qlDHaDHVComHlB9fh x5gw== X-Gm-Message-State: AOAM532P/tbQXYOwNS2OVwGmUUTPPcDDatNbhsh635BlQuaYjfjyWg93 Hs7Qp/IB/w3H0Zn+fOpzXnVCn3OTTMNhVA== X-Google-Smtp-Source: ABdhPJwm4AUq4by4AM1PUn9xZnTfjX671YZI6Td3IehogETismwtdgriahdaTXh2BKL5jjVevw0Smg== X-Received: by 2002:aed:2b47:: with SMTP id p65mr9379089qtd.284.1614962152458; Fri, 05 Mar 2021 08:35:52 -0800 (PST) Received: from localhost.localdomain ([181.23.89.132]) by smtp.gmail.com with ESMTPSA id b10sm2168494qtt.23.2021.03.05.08.35.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 08:35:52 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Mar 2021 13:33:12 -0300 Message-Id: <20210305163339.63164-22-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 21/48] avformat/hls: 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/hls.c | 73 +++++++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 34 deletions(-) diff --git a/libavformat/hls.c b/libavformat/hls.c index af2468ad9b..dfc91fd5cb 100644 --- a/libavformat/hls.c +++ b/libavformat/hls.c @@ -101,7 +101,7 @@ struct playlist { AVFormatContext *parent; int index; AVFormatContext *ctx; - AVPacket pkt; + AVPacket *pkt; int has_noheader_flag; /* main demuxer streams associated with this playlist @@ -256,7 +256,7 @@ static void free_playlist_list(HLSContext *c) av_dict_free(&pls->id3_initial); ff_id3v2_free_extra_meta(&pls->id3_deferred_extra); av_freep(&pls->init_sec_buf); - av_packet_unref(&pls->pkt); + av_packet_free(&pls->pkt); av_freep(&pls->pb.buffer); ff_format_io_close(c->ctx, &pls->input); pls->input_read_done = 0; @@ -299,12 +299,17 @@ static struct playlist *new_playlist(HLSContext *c, const char *url, struct playlist *pls = av_mallocz(sizeof(struct playlist)); if (!pls) return NULL; + pls->pkt = av_packet_alloc(); + if (!pls->pkt) { + av_free(pls); + return NULL; + } ff_make_absolute_url(pls->url, sizeof(pls->url), base, url); if (!pls->url[0]) { + av_packet_free(&pls->pkt); av_free(pls); return NULL; } - av_init_packet(&pls->pkt); pls->seek_timestamp = AV_NOPTS_VALUE; pls->is_id3_timestamped = -1; @@ -2102,26 +2107,26 @@ static int recheck_discard_flags(AVFormatContext *s, int first) static void fill_timing_for_id3_timestamped_stream(struct playlist *pls) { if (pls->id3_offset >= 0) { - pls->pkt.dts = pls->id3_mpegts_timestamp + + pls->pkt->dts = pls->id3_mpegts_timestamp + av_rescale_q(pls->id3_offset, - pls->ctx->streams[pls->pkt.stream_index]->time_base, + pls->ctx->streams[pls->pkt->stream_index]->time_base, MPEG_TIME_BASE_Q); - if (pls->pkt.duration) - pls->id3_offset += pls->pkt.duration; + if (pls->pkt->duration) + pls->id3_offset += pls->pkt->duration; else pls->id3_offset = -1; } else { /* there have been packets with unknown duration * since the last id3 tag, should not normally happen */ - pls->pkt.dts = AV_NOPTS_VALUE; + pls->pkt->dts = AV_NOPTS_VALUE; } - if (pls->pkt.duration) - pls->pkt.duration = av_rescale_q(pls->pkt.duration, - pls->ctx->streams[pls->pkt.stream_index]->time_base, + if (pls->pkt->duration) + pls->pkt->duration = av_rescale_q(pls->pkt->duration, + pls->ctx->streams[pls->pkt->stream_index]->time_base, MPEG_TIME_BASE_Q); - pls->pkt.pts = AV_NOPTS_VALUE; + pls->pkt->pts = AV_NOPTS_VALUE; } static AVRational get_timebase(struct playlist *pls) @@ -2129,7 +2134,7 @@ static AVRational get_timebase(struct playlist *pls) if (pls->is_id3_timestamped) return MPEG_TIME_BASE_Q; - return pls->ctx->streams[pls->pkt.stream_index]->time_base; + return pls->ctx->streams[pls->pkt->stream_index]->time_base; } static int compare_ts_with_wrapdetect(int64_t ts_a, struct playlist *pls_a, @@ -2153,25 +2158,25 @@ static int hls_read_packet(AVFormatContext *s, AVPacket *pkt) struct playlist *pls = c->playlists[i]; /* Make sure we've got one buffered packet from each open playlist * stream */ - if (pls->needed && !pls->pkt.data) { + if (pls->needed && !pls->pkt->data) { while (1) { int64_t ts_diff; AVRational tb; - ret = av_read_frame(pls->ctx, &pls->pkt); + ret = av_read_frame(pls->ctx, pls->pkt); if (ret < 0) { if (!avio_feof(&pls->pb) && ret != AVERROR_EOF) return ret; break; } else { /* stream_index check prevents matching picture attachments etc. */ - if (pls->is_id3_timestamped && pls->pkt.stream_index == 0) { + if (pls->is_id3_timestamped && pls->pkt->stream_index == 0) { /* audio elementary streams are id3 timestamped */ fill_timing_for_id3_timestamped_stream(pls); } if (c->first_timestamp == AV_NOPTS_VALUE && - pls->pkt.dts != AV_NOPTS_VALUE) - c->first_timestamp = av_rescale_q(pls->pkt.dts, + pls->pkt->dts != AV_NOPTS_VALUE) + c->first_timestamp = av_rescale_q(pls->pkt->dts, get_timebase(pls), AV_TIME_BASE_Q); } @@ -2179,35 +2184,35 @@ static int hls_read_packet(AVFormatContext *s, AVPacket *pkt) break; if (pls->seek_stream_index < 0 || - pls->seek_stream_index == pls->pkt.stream_index) { + pls->seek_stream_index == pls->pkt->stream_index) { - if (pls->pkt.dts == AV_NOPTS_VALUE) { + if (pls->pkt->dts == AV_NOPTS_VALUE) { pls->seek_timestamp = AV_NOPTS_VALUE; break; } tb = get_timebase(pls); - ts_diff = av_rescale_rnd(pls->pkt.dts, AV_TIME_BASE, + ts_diff = av_rescale_rnd(pls->pkt->dts, AV_TIME_BASE, tb.den, AV_ROUND_DOWN) - pls->seek_timestamp; if (ts_diff >= 0 && (pls->seek_flags & AVSEEK_FLAG_ANY || - pls->pkt.flags & AV_PKT_FLAG_KEY)) { + pls->pkt->flags & AV_PKT_FLAG_KEY)) { pls->seek_timestamp = AV_NOPTS_VALUE; break; } } - av_packet_unref(&pls->pkt); + av_packet_unref(pls->pkt); } } /* Check if this stream has the packet with the lowest dts */ - if (pls->pkt.data) { + if (pls->pkt->data) { struct playlist *minpls = minplaylist < 0 ? NULL : c->playlists[minplaylist]; if (minplaylist < 0) { minplaylist = i; } else { - int64_t dts = pls->pkt.dts; - int64_t mindts = minpls->pkt.dts; + int64_t dts = pls->pkt->dts; + int64_t mindts = minpls->pkt->dts; if (dts == AV_NOPTS_VALUE || (mindts != AV_NOPTS_VALUE && compare_ts_with_wrapdetect(dts, pls, mindts, minpls) < 0)) @@ -2224,7 +2229,7 @@ static int hls_read_packet(AVFormatContext *s, AVPacket *pkt) ret = update_streams_from_subdemuxer(s, pls); if (ret < 0) { - av_packet_unref(&pls->pkt); + av_packet_unref(pls->pkt); return ret; } @@ -2245,17 +2250,17 @@ static int hls_read_packet(AVFormatContext *s, AVPacket *pkt) update_noheader_flag(s); } - if (pls->pkt.stream_index >= pls->n_main_streams) { + if (pls->pkt->stream_index >= pls->n_main_streams) { av_log(s, AV_LOG_ERROR, "stream index inconsistency: index %d, %d main streams, %d subdemuxer streams\n", - pls->pkt.stream_index, pls->n_main_streams, pls->ctx->nb_streams); - av_packet_unref(&pls->pkt); + pls->pkt->stream_index, pls->n_main_streams, pls->ctx->nb_streams); + av_packet_unref(pls->pkt); return AVERROR_BUG; } - ist = pls->ctx->streams[pls->pkt.stream_index]; - st = pls->main_streams[pls->pkt.stream_index]; + ist = pls->ctx->streams[pls->pkt->stream_index]; + st = pls->main_streams[pls->pkt->stream_index]; - av_packet_move_ref(pkt, &pls->pkt); + av_packet_move_ref(pkt, pls->pkt); pkt->stream_index = st->index; if (pkt->dts != AV_NOPTS_VALUE) @@ -2331,7 +2336,7 @@ static int hls_read_seek(AVFormatContext *s, int stream_index, pls->input_read_done = 0; ff_format_io_close(pls->parent, &pls->input_next); pls->input_next_requested = 0; - av_packet_unref(&pls->pkt); + av_packet_unref(pls->pkt); pls->pb.eof_reached = 0; /* Clear any buffered data */ pls->pb.buf_end = pls->pb.buf_ptr = pls->pb.buffer; From patchwork Fri Mar 5 16:33:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26144 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 E1FCF44BC27 for ; Fri, 5 Mar 2021 18:39:56 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6696068AC45; Fri, 5 Mar 2021 18:36:01 +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 3817A68ABEF for ; Fri, 5 Mar 2021 18:35:55 +0200 (EET) Received: by mail-qk1-f171.google.com with SMTP id t4so2584417qkp.1 for ; Fri, 05 Mar 2021 08:35:55 -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=zCu922ckKYAY3qQQ28vIPyQejhpN6IID6JWoH+ED5pc=; b=nV1PV903xqvgLj70BMq3Hs24Zkw9NYTQZzwbHq0mMw9vVTA3Rq0YssYGDxVmqOc4xS VCU714Cc0Eci0ONEi0CNdJg4F8eKJPG9GZkLSclbovUo6w9TKcxDWEcDtjYpRHLcPwKL DILcUbKR7fCC+myBpSwA7UnPxBxUn1lrXuCIBQFj1UXGyHD5U9dE00xjX8tkP5DNy257 Rvo2G6VIHlr3OwFXfIgdok0SpZE3R9Hq73ElAMdrwEMIB/xQRSm6sg4ORRALIkJroVhu Xwj6PxtuPE6NZ8gSKiNq3Zjz4bCJFWkLEmg70+JuY3JtVZZJzug0vcud6sf/rhghMyL2 zSgg== 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=zCu922ckKYAY3qQQ28vIPyQejhpN6IID6JWoH+ED5pc=; b=CbFgxlPym1OkAhOYhULliZBet/BtJAmT87qGRvRb83QRTkyrqGpJQWTK4PJ7xJxMfH 6RxKuCNPpp0HJFD9BnpR7EQOKT4C5/ZnTc/ATASFKegAWIp52tHlDPAkL1uTl80yoT2O huZZQdzv4Tt6jqaM76PlBveGWYKGWVk5/JqTatFBCArtlUD8kw9uF3kIG8tny+voMWS4 1T2Ex+U0DueITL6rnNMPvDSRyH+3iNiQlJelr8dYvLfwXwZekjZUYegDYb9f22hc9Q/z d6v1pueqfVsEoLEIzyv67pfn7ueglO57YhL9fLO+S7vKBHV4GyUbeHQqAfA+k+HePU0h xNQQ== X-Gm-Message-State: AOAM5317GEf9xJ0vjjHRq5MyumQxLhjfnO2a0uvDP9ua4pt+59cLnCh0 tv5m72yASJ7HKR+xuNUyq6ylKPAT6H+/Kg== X-Google-Smtp-Source: ABdhPJx8A76aKhlwnShP4leXyrO8JL6WkWsC9YaQw5/82hgNGHjEdgqUwsw5NLoCN1Vgx4CRh0CYPQ== X-Received: by 2002:a05:620a:b02:: with SMTP id t2mr10101974qkg.128.1614962153713; Fri, 05 Mar 2021 08:35:53 -0800 (PST) Received: from localhost.localdomain ([181.23.89.132]) by smtp.gmail.com with ESMTPSA id b10sm2168494qtt.23.2021.03.05.08.35.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 08:35:53 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Mar 2021 13:33:13 -0300 Message-Id: <20210305163339.63164-23-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 22/48] avformat/matroskadec: 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/matroskadec.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 9a65774464..3ee28a447c 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -381,6 +381,8 @@ typedef struct MatroskaDemuxContext { /* byte position of the segment inside the stream */ int64_t segment_start; + AVPacket *pkt; + /* the packet queue */ PacketList *queue; PacketList *queue_end; @@ -2943,6 +2945,10 @@ static int matroska_read_header(AVFormatContext *s) } ebml_free(ebml_syntax, &ebml); + matroska->pkt = av_packet_alloc(); + if (!matroska->pkt) + return AVERROR(ENOMEM); + /* The next thing is a segment. */ pos = avio_tell(matroska->ctx->pb); res = ebml_parse(matroska, matroska_segments, matroska); @@ -3004,7 +3010,7 @@ static int matroska_read_header(AVFormatContext *s) st->disposition |= AV_DISPOSITION_ATTACHED_PIC; st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; - av_init_packet(pkt); + av_packet_unref(pkt); pkt->buf = attachments[j].bin.buf; attachments[j].bin.buf = NULL; pkt->data = attachments[j].bin.data; @@ -3236,7 +3242,7 @@ static int matroska_parse_rm_audio(MatroskaDemuxContext *matroska, while (track->audio.pkt_cnt) { int ret; - AVPacket pktl, *pkt = &pktl; + AVPacket *pkt = matroska->pkt; ret = av_new_packet(pkt, a); if (ret < 0) { @@ -3373,7 +3379,7 @@ static int matroska_parse_webvtt(MatroskaDemuxContext *matroska, uint64_t duration, int64_t pos) { - AVPacket pktl, *pkt = &pktl; + AVPacket *pkt = matroska->pkt; uint8_t *id, *settings, *text, *buf; int id_len, settings_len, text_len; uint8_t *p, *q; @@ -3490,7 +3496,7 @@ static int matroska_parse_frame(MatroskaDemuxContext *matroska, { uint8_t *pkt_data = data; int res = 0; - AVPacket pktl, *pkt = &pktl; + AVPacket *pkt = matroska->pkt; if (st->codecpar->codec_id == AV_CODEC_ID_WAVPACK) { res = matroska_parse_wavpack(track, &pkt_data, &pkt_size); @@ -3520,7 +3526,7 @@ static int matroska_parse_frame(MatroskaDemuxContext *matroska, if (!pkt_size && !additional_size) goto no_output; - av_init_packet(pkt); + av_packet_unref(pkt); if (!buf) pkt->buf = av_buffer_create(pkt_data, pkt_size + AV_INPUT_BUFFER_PADDING_SIZE, NULL, NULL, 0); @@ -3894,6 +3900,7 @@ static int matroska_read_close(AVFormatContext *s) int n; matroska_clear_queue(matroska); + av_packet_free(&matroska->pkt); for (n = 0; n < matroska->tracks.nb_elem; n++) if (tracks[n].type == MATROSKA_TRACK_TYPE_AUDIO) 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); From patchwork Fri Mar 5 16:33:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26168 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a25:6d42:0:0:0:0:0 with SMTP id i63csp529487ybc; Fri, 5 Mar 2021 08:40:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJxahHCkoFeaJdr93+iHDwRjqaYYLfwBvtLRmAMMTW+v8/ljlTLmUgwgRuNUiyMMBRGIhJ2K X-Received: by 2002:a17:906:d71:: with SMTP id s17mr3084918ejh.126.1614962423941; Fri, 05 Mar 2021 08:40:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614962423; cv=none; d=google.com; s=arc-20160816; b=OF9MkhpS3d2qRPEcj3lcOxYrUM1krrBUJkM3MZ4N2Rr4MDo/Rm0yAeVJz9VsM6yF5q UspffDRtMUR3oPSi9+2mSXayJAmqFePMQSUKeT7T+dQouqOH6ijVmeQRyMRaUhyGTPz4 XHtDl+TrBPaIDARL7GcjQqUMuf71JFNUewldWeKiEpE/NSJ11a1yCtqa9LpceF8li9XI r3TVgbNvgs36V2FTLpGS/e9ZOJlmF3DcLo0jAKXFWCu3y6dsg+T2Gt1QTTYOC9MkHUkn EZSAXcUm7CaIV9jP23rrbai4B7Yv3sNQTD5jXuwQTgrRJBsjwTAlPvWgrYNPpweo4Wxo DCgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=cmfxE7na+ciFkn9SBIM6X3XduoDepbhErWPo4+R61Vc=; b=rGT0tDYN9ULDeenGvWHOmo3NtqeilMva6UsAQyHTmy0+i6y/HlOk/Vn4gde2qbqOBu TxZiDZTXpf5q8f4UMhIImlsxlzy9XlgCNnQgKjQ0l9deKh3rWzRBk6t+smCa5h+hoj9I +tAT2dwXZlzkso6SBTUjAC5iOA8NRY5SdH0Qt5LA0VtVmV2e6Z+aeUkWudmpWHaA9p+r Ix5g/B3x0m3WQBXvaHL/zvRCqopRs4SlkCcS5Gf6lJhy9f0iRr71SMGIQBR814hYXNeV Vh5WunEi0ttWnu37ZaYPVmYFt9cqAfuOGBA2gNR1YQlvLZS3RNc267TO6ZS0haAYyqZu 7IGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=J3HH84mB; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id a6si1790214edu.356.2021.03.05.08.40.23; Fri, 05 Mar 2021 08:40:23 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=J3HH84mB; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 36E7D68AC68; Fri, 5 Mar 2021 18:36:03 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f171.google.com (mail-qt1-f171.google.com [209.85.160.171]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C092368AC09 for ; Fri, 5 Mar 2021 18:35:57 +0200 (EET) Received: by mail-qt1-f171.google.com with SMTP id w6so2163835qti.6 for ; Fri, 05 Mar 2021 08:35:57 -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=lIyvb1Leo8aTWKV/U8DIEbuYxoOIAS9O6L5O6bkkk+o=; b=J3HH84mB1zyti94e7Qem3J7BUaMgDH0rdB9Sex9XkbJQPY0f/QLoaJt0WbU7xd6sAS iVEB+DmCQ12e+ijuWvKhGNNCDdcRldo4/OvmK5HyrwcKRI7g8IKUcxu3cDq3MzZbOVlk pJVAFn6EL1iIK2hb+9Bxv0tUxcEQjYuIrngfUmJaWfLu2RkFETNb8ELVAhWxPbb0likG dg+lVqCG7ufBlef+Wrf3XZRZ6aIXUa3jsEBNAagxegSU1B8pCmzPDBno4D59J+sb8aOt uPjfAj8Wgw2sontdR97cfgLve0HFjOkZ/kzjZTdarHMYdiLV3C/PQB7bwGpkcr5ctFtX 4ldA== 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=lIyvb1Leo8aTWKV/U8DIEbuYxoOIAS9O6L5O6bkkk+o=; b=M+mqHuQKsKHK2GvUs6LKlqfrPdYNQsGvsVzOZcLRIiJLvwTMVrNJyjANIPG3XBGLAN N4OSNhH2dgMZ6rXxBuv7PSr+u16ublcKhAI9DnYbZuakl1MfVgTnW39YufCCzLlivQnh vh6IOKhgaOJqPV7a5du5pEbQta7LRxFHMqB2Rv7SUGQxyj7sy8Pwh6aN7ebYmQdyPSFT y0hGNHd2sZEIyr4tzGWA8DjZ5gOMF3lLlXcUBfwa3CfDaoE2sELc7HUNfpJB5jCLkrNp /ns9ew3rk+erQ4+z78m7I8mx+4JxkYZbF4Ok+7nPv/zJBI9VcpN97ZuaYvk0FTSjN0zP R0qA== X-Gm-Message-State: AOAM530pRxb1gJQmyM9u7y/xm6Q28wusp2BygrHOPkJG5qUmotQaBX+T T8w+F0SD8+NuoWJN1hnVK6c7dZaCiMweBQ== X-Received: by 2002:aed:20cb:: with SMTP id 69mr9620924qtb.267.1614962156151; Fri, 05 Mar 2021 08:35:56 -0800 (PST) Received: from localhost.localdomain ([181.23.89.132]) by smtp.gmail.com with ESMTPSA id b10sm2168494qtt.23.2021.03.05.08.35.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 08:35:55 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Mar 2021 13:33:15 -0300 Message-Id: <20210305163339.63164-25-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 24/48] avformat/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" X-TUID: uQ+7Gqs8bZCk Content-Length: 15672 Signed-off-by: James Almer --- libavformat/movenc.c | 101 +++++++++++++++++++++++++-------------- libavformat/movenc.h | 4 +- libavformat/movenchint.c | 19 ++++---- 3 files changed, 77 insertions(+), 47 deletions(-) diff --git a/libavformat/movenc.c b/libavformat/movenc.c index ccb9768564..7aa0a9888a 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -365,7 +365,7 @@ static int mov_write_ac3_tag(AVFormatContext *s, AVIOContext *pb, MOVTrack *trac } struct eac3_info { - AVPacket pkt; + AVPacket *pkt; uint8_t ec3_done; uint8_t num_blocks; @@ -407,6 +407,9 @@ static int handle_eac3(MOVMuxContext *mov, AVPacket *pkt, MOVTrack *track) return AVERROR(ENOMEM); info = track->eac3_priv; + if (!info->pkt && !(info->pkt = av_packet_alloc())) + return AVERROR(ENOMEM); + if (avpriv_ac3_parse_header(&hdr, pkt->data, pkt->size) < 0) { /* drop the packets until we see a good one */ if (!track->entry) { @@ -511,20 +514,20 @@ concatenate: } if (!info->num_blocks) { - ret = av_packet_ref(&info->pkt, pkt); + ret = av_packet_ref(info->pkt, pkt); if (!ret) info->num_blocks = num_blocks; goto end; } else { - if ((ret = av_grow_packet(&info->pkt, pkt->size)) < 0) + if ((ret = av_grow_packet(info->pkt, pkt->size)) < 0) goto end; - memcpy(info->pkt.data + info->pkt.size - pkt->size, pkt->data, pkt->size); + memcpy(info->pkt->data + info->pkt->size - pkt->size, pkt->data, pkt->size); info->num_blocks += num_blocks; - info->pkt.duration += pkt->duration; + info->pkt->duration += pkt->duration; if (info->num_blocks != 6) goto end; av_packet_unref(pkt); - av_packet_move_ref(pkt, &info->pkt); + av_packet_move_ref(pkt, info->pkt); info->num_blocks = 0; } ret = pkt->size; @@ -3732,7 +3735,7 @@ static int mov_write_covr(AVIOContext *pb, AVFormatContext *s) for (i = 0; i < s->nb_streams; i++) { MOVTrack *trk = &mov->tracks[i]; - if (!is_cover_image(trk->st) || trk->cover_image.size <= 0) + if (!is_cover_image(trk->st) || trk->cover_image->size <= 0) continue; if (!pos) { @@ -3740,11 +3743,11 @@ static int mov_write_covr(AVIOContext *pb, AVFormatContext *s) avio_wb32(pb, 0); ffio_wfourcc(pb, "covr"); } - avio_wb32(pb, 16 + trk->cover_image.size); + avio_wb32(pb, 16 + trk->cover_image->size); ffio_wfourcc(pb, "data"); avio_wb32(pb, trk->tag); avio_wb32(pb , 0); - avio_write(pb, trk->cover_image.data, trk->cover_image.size); + avio_write(pb, trk->cover_image->data, trk->cover_image->size); } return pos ? update_size(pb, pos) : 0; @@ -5967,20 +5970,20 @@ static int mov_write_single_packet(AVFormatContext *s, AVPacket *pkt) static int mov_write_subtitle_end_packet(AVFormatContext *s, int stream_index, int64_t dts) { - AVPacket end; + MOVMuxContext *mov = s->priv_data; + AVPacket *end = mov->pkt; uint8_t data[2] = {0}; int ret; - av_init_packet(&end); - end.size = sizeof(data); - end.data = data; - end.pts = dts; - end.dts = dts; - end.duration = 0; - end.stream_index = stream_index; + end->size = sizeof(data); + end->data = data; + end->pts = dts; + end->dts = dts; + end->duration = 0; + end->stream_index = stream_index; - ret = mov_write_single_packet(s, &end); - av_packet_unref(&end); + ret = mov_write_single_packet(s, end); + av_packet_unref(end); return ret; } @@ -6007,7 +6010,7 @@ static int mov_write_packet(AVFormatContext *s, AVPacket *pkt) return 0; } - if ((ret = av_packet_ref(&trk->cover_image, pkt)) < 0) + if ((ret = av_packet_ref(trk->cover_image, pkt)) < 0) return ret; return 0; @@ -6093,7 +6096,7 @@ static int mov_create_chapter_track(AVFormatContext *s, int tracknum) MOVMuxContext *mov = s->priv_data; MOVTrack *track = &mov->tracks[tracknum]; - AVPacket pkt = { .stream_index = tracknum, .flags = AV_PKT_FLAG_KEY }; + AVPacket *pkt = mov->pkt; int i, len; track->mode = mov->mode; @@ -6155,13 +6158,16 @@ static int mov_create_chapter_track(AVFormatContext *s, int tracknum) } #endif + pkt->stream_index = tracknum; + pkt->flags = AV_PKT_FLAG_KEY; + for (i = 0; i < s->nb_chapters; i++) { AVChapter *c = s->chapters[i]; AVDictionaryEntry *t; int64_t end = av_rescale_q(c->end, c->time_base, (AVRational){1,MOV_TIMESCALE}); - pkt.pts = pkt.dts = av_rescale_q(c->start, c->time_base, (AVRational){1,MOV_TIMESCALE}); - pkt.duration = end - pkt.dts; + pkt->pts = pkt->dts = av_rescale_q(c->start, c->time_base, (AVRational){1,MOV_TIMESCALE}); + pkt->duration = end - pkt->dts; if ((t = av_dict_get(c->metadata, "title", NULL, 0))) { static const char encd[12] = { @@ -6169,18 +6175,22 @@ static int mov_create_chapter_track(AVFormatContext *s, int tracknum) 'e', 'n', 'c', 'd', 0x00, 0x00, 0x01, 0x00 }; len = strlen(t->value); - pkt.size = len + 2 + 12; - pkt.data = av_malloc(pkt.size); - if (!pkt.data) + pkt->size = len + 2 + 12; + pkt->data = av_malloc(pkt->size); + if (!pkt->data) { + av_packet_unref(pkt); return AVERROR(ENOMEM); - AV_WB16(pkt.data, len); - memcpy(pkt.data + 2, t->value, len); - memcpy(pkt.data + len + 2, encd, sizeof(encd)); - ff_mov_write_packet(s, &pkt); - av_freep(&pkt.data); + } + AV_WB16(pkt->data, len); + memcpy(pkt->data + 2, t->value, len); + memcpy(pkt->data + len + 2, encd, sizeof(encd)); + ff_mov_write_packet(s, pkt); + av_freep(&pkt->data); } } + av_packet_unref(mov->pkt); + return 0; } @@ -6200,9 +6210,9 @@ static int mov_create_timecode_track(AVFormatContext *s, int index, int src_inde MOVTrack *track = &mov->tracks[index]; AVStream *src_st = s->streams[src_index]; uint8_t data[4]; - AVPacket pkt = { .data = data, .stream_index = index, - .flags = AV_PKT_FLAG_KEY, .size = 4 }; + AVPacket *pkt = mov->pkt; AVRational rate = find_fps(s, src_st); + int ret; /* tmcd track based on video stream */ track->mode = mov->mode; @@ -6224,8 +6234,14 @@ static int mov_create_timecode_track(AVFormatContext *s, int index, int src_inde track->st->avg_frame_rate = av_inv_q(rate); /* the tmcd track just contains one packet with the frame number */ - AV_WB32(pkt.data, tc.start); - return ff_mov_write_packet(s, &pkt); + pkt->data = data; + pkt->stream_index = index; + pkt->flags = AV_PKT_FLAG_KEY; + pkt->size = 4; + AV_WB32(pkt->data, tc.start); + ret = ff_mov_write_packet(s, pkt); + av_packet_unref(pkt); + return ret; } /* @@ -6286,6 +6302,8 @@ static void mov_free(AVFormatContext *s) MOVMuxContext *mov = s->priv_data; int i; + av_packet_free(&mov->pkt); + if (!mov->tracks) return; @@ -6300,11 +6318,11 @@ static void mov_free(AVFormatContext *s) av_freep(&mov->tracks[i].par); av_freep(&mov->tracks[i].cluster); av_freep(&mov->tracks[i].frag_info); - av_packet_unref(&mov->tracks[i].cover_image); + av_packet_free(&mov->tracks[i].cover_image); if (mov->tracks[i].eac3_priv) { struct eac3_info *info = mov->tracks[i].eac3_priv; - av_packet_unref(&info->pkt); + av_packet_free(&info->pkt); av_freep(&mov->tracks[i].eac3_priv); } if (mov->tracks[i].vos_len) @@ -6535,6 +6553,10 @@ static int mov_init(AVFormatContext *s) mov->nb_streams += mov->nb_meta_tmcd; } + mov->pkt = av_packet_alloc(); + if (!mov->pkt) + return AVERROR(ENOMEM); + // Reserve an extra stream for chapters for the case where chapters // are written in the trailer mov->tracks = av_mallocz_array((mov->nb_streams + 1), sizeof(*mov->tracks)); @@ -6642,6 +6664,11 @@ static int mov_init(AVFormatContext *s) av_log(s, AV_LOG_ERROR, "VP8 muxing is currently not supported.\n"); return AVERROR_PATCHWELCOME; } + if (is_cover_image(st)) { + track->cover_image = av_packet_alloc(); + if (!track->cover_image) + return AVERROR(ENOMEM); + } } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { track->timescale = st->codecpar->sample_rate; if (!st->codecpar->frame_size && !av_get_bits_per_sample(st->codecpar->codec_id)) { diff --git a/libavformat/movenc.h b/libavformat/movenc.h index 997b2d61c0..cdbc4074c3 100644 --- a/libavformat/movenc.h +++ b/libavformat/movenc.h @@ -134,7 +134,7 @@ typedef struct MOVTrack { uint32_t default_size; HintSampleQueue sample_queue; - AVPacket cover_image; + AVPacket *cover_image; AVIOContext *mdat_buf; int64_t data_offset; @@ -215,6 +215,8 @@ typedef struct MOVMuxContext { int per_stream_grouping; AVFormatContext *fc; + AVPacket *pkt; + int use_editlist; float gamma; diff --git a/libavformat/movenchint.c b/libavformat/movenchint.c index 964026ec71..47276091f3 100644 --- a/libavformat/movenchint.c +++ b/libavformat/movenchint.c @@ -408,7 +408,7 @@ int ff_mov_add_hinted_packet(AVFormatContext *s, AVPacket *pkt, uint8_t *buf = NULL; int size; AVIOContext *hintbuf = NULL; - AVPacket hint_pkt; + AVPacket *hint_pkt = mov->pkt; int ret = 0, count; if (!rtp_ctx) @@ -437,21 +437,22 @@ int ff_mov_add_hinted_packet(AVFormatContext *s, AVPacket *pkt, /* Open a buffer for writing the hint */ if ((ret = avio_open_dyn_buf(&hintbuf)) < 0) goto done; - av_init_packet(&hint_pkt); - count = write_hint_packets(hintbuf, buf, size, trk, &hint_pkt.dts); + av_packet_unref(hint_pkt); + count = write_hint_packets(hintbuf, buf, size, trk, &hint_pkt->dts); av_freep(&buf); /* Write the hint data into the hint track */ - hint_pkt.size = size = avio_close_dyn_buf(hintbuf, &buf); - hint_pkt.data = buf; - hint_pkt.pts = hint_pkt.dts; - hint_pkt.stream_index = track_index; + hint_pkt->size = size = avio_close_dyn_buf(hintbuf, &buf); + hint_pkt->data = buf; + hint_pkt->pts = hint_pkt->dts; + hint_pkt->stream_index = track_index; if (pkt->flags & AV_PKT_FLAG_KEY) - hint_pkt.flags |= AV_PKT_FLAG_KEY; + hint_pkt->flags |= AV_PKT_FLAG_KEY; if (count > 0) - ff_mov_write_packet(s, &hint_pkt); + ff_mov_write_packet(s, hint_pkt); done: av_free(buf); + av_packet_unref(hint_pkt); sample_queue_retain(&trk->sample_queue); return ret; } From patchwork Fri Mar 5 16:33:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26167 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a25:6d42:0:0:0:0:0 with SMTP id i63csp529676ybc; Fri, 5 Mar 2021 08:40:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJxyPLEW8kY0oRq3II0L3ItX/7QDRvfg0H7KRNEiwGQwgD4f60ifFYpE0h24KscsCnPpF0JA X-Received: by 2002:a17:906:1759:: with SMTP id d25mr2989071eje.524.1614962441052; Fri, 05 Mar 2021 08:40:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614962441; cv=none; d=google.com; s=arc-20160816; b=N7TsUwfrfFhLqnUym0SM0Tuo0vsM2+CeGYiFJev0FwUK2bruy0jwP90t3teOF+gXbN 3vPk104FWcKynzXx1hxHQNT+Em8dCNrBED3eTgA0EFtuAc8QoY3OmZCIzc+AX/JH/j7l R3I0IZET7AnqgtTdpKUSwTYLRkitL2hhL+eBAHD2REnFzWSrLXxrkANlyPhD7aG36l5+ zkdwsjIZ/QI0YfUdwwTQN7xaqNiyoQ/HXSeqyFi2d0NIRERPHmPA+HUNapSjG4Wrm7K+ GcyAR3ibPj2jtkx/eNJ9ZjM5Hpqpbhw2GdetlzackhfdpUPe/nGsJWyKv1HWeLmylPBr 2xIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=fON5NghHTbML9O+hQaJxcXyhcQ4C3KzE987n+P5rApU=; b=UjHEsBOGZJWGRFblsMFu9Gfz+tOHaTck0eIV+ZrVZslRRWwFO4Yc07rvju0JeKM/Cb 7Y/gc6VC4g3uTqBIb63jycajxtm1qDusJOHkNw9++9UqHMv46TgBC0KHTZzaGMUoO0yI C1hv8YDYxpmZgEMRy7eoEWfXUh1+R2f6vDXROoQnTH1utgXJvDJFu0RRgsTbqhkJirI4 50tjVWYqeZcDamxHIt7clBehmqzdUArSKjwdNa4f/x9NGeqFNVPEG/lDrXbei/G2o7Ri hISYv90xNMcBvYQEj9dx5tBDZc5VFYM84z+fIaTv6H3kGml9ZdtNGyj/w2ipNOruURAb aMlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=B6YVLqsc; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id u4si1533858ejc.113.2021.03.05.08.40.40; Fri, 05 Mar 2021 08:40:41 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=B6YVLqsc; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9098C68AC9E; Fri, 5 Mar 2021 18:36:04 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E7DFD68AC09 for ; Fri, 5 Mar 2021 18:35:58 +0200 (EET) Received: by mail-qk1-f181.google.com with SMTP id a9so2507529qkn.13 for ; Fri, 05 Mar 2021 08:35:58 -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=h5jGWYU24ydkE5yPhgf7BkxUWroEF6Toc78A+oGRTSg=; b=B6YVLqscErSrpfcRX8eUzLyOp/ac1LSovjFH3FgKE8N+vwDkEBkzwMyJKJWd51uPRl svFzr77lKWV5c1MQGI5clh8aWaI6C9XU6kgKs8Yu/2HjMg5oNcLW3Ref2ascJN1CAEae joE/FWeWSaGmlHg5w1qPp3HXCHsPWRfhVUVFBT2wLeMHNi/e3WFn57Ft9gMIQyxYafy0 RldigjakvTuXzAwM7idCYa9uMY+4wBB/PtwN2vJHfuve1X7shXXFva3nM1u6LTv6pajw nUQVvMb6mJ5DucqXYqw+flGX/mlEsyLy4F00xLQxDAo4x27T84rn6nVIuAfFWS826ZB8 Q4Vw== 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=h5jGWYU24ydkE5yPhgf7BkxUWroEF6Toc78A+oGRTSg=; b=YT8LIifX0E/Msf+XegOUQskdnHznEJdwN7dW4X/wnPCCK4MBnGIMFpZ2z24OGxQpoB +nUYn2ipJ9pnWvgAVsRL996i8DEGjIVwedH1J6Be4LoR48Uvgx/82jxy7DP321EyEB5l v6czcrXrItAXJkHzggtrVzjJWRH3VBgC7n0708hR3sUiE2Jnn81SRK92pRELqxTV8D1s 0qSd9Jj8+qke9MwFr1gYQ33HN5rESEh9zypJdO0dhB3ewkp/bqtgCk1mtL4OmDmfeBn2 Y2e5kD5p6Xc9nFO8Pox3LD3GXh7SCEcsEWrV8yvVSIKjXkf0OinftSL/BscS2S2X525f 5OAA== X-Gm-Message-State: AOAM531G2VqPKdXiwuS3S1A+UeAWQVQj8r2GuXjBnjV8YSRwRqa5ljni R4jnpz3VYrJfO3wpHrvWntLTktXJcmMrqA== X-Received: by 2002:a05:620a:144a:: with SMTP id i10mr9855519qkl.431.1614962157432; Fri, 05 Mar 2021 08:35:57 -0800 (PST) Received: from localhost.localdomain ([181.23.89.132]) by smtp.gmail.com with ESMTPSA id b10sm2168494qtt.23.2021.03.05.08.35.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 08:35:57 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Mar 2021 13:33:16 -0300 Message-Id: <20210305163339.63164-26-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 25/48] avformat/mpegts: 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" X-TUID: tLPNlFz2NIBr Content-Length: 4126 Signed-off-by: James Almer --- libavformat/mpegts.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index e283ec09d7..6e0d9d7496 100644 --- a/libavformat/mpegts.c +++ b/libavformat/mpegts.c @@ -981,7 +981,7 @@ static void reset_pes_packet_state(PESContext *pes) static void new_data_packet(const uint8_t *buffer, int len, AVPacket *pkt) { - av_init_packet(pkt); + av_packet_unref(pkt); pkt->data = (uint8_t *)buffer; pkt->size = len; } @@ -990,7 +990,7 @@ static int new_pes_packet(PESContext *pes, AVPacket *pkt) { uint8_t *sd; - av_init_packet(pkt); + av_packet_unref(pkt); pkt->buf = pes->buffer; pkt->data = pes->buffer->data; @@ -3298,33 +3298,37 @@ static int64_t mpegts_get_dts(AVFormatContext *s, int stream_index, int64_t *ppos, int64_t pos_limit) { MpegTSContext *ts = s->priv_data; + AVPacket *pkt; int64_t pos; int pos47 = ts->pos47_full % ts->raw_packet_size; pos = ((*ppos + ts->raw_packet_size - 1 - pos47) / ts->raw_packet_size) * ts->raw_packet_size + pos47; ff_read_frame_flush(s); if (avio_seek(s->pb, pos, SEEK_SET) < 0) return AV_NOPTS_VALUE; + pkt = av_packet_alloc(); + if (!pkt) + return AV_NOPTS_VALUE; while(pos < pos_limit) { - int ret; - AVPacket pkt; - av_init_packet(&pkt); - ret = av_read_frame(s, &pkt); - if (ret < 0) + int ret = av_read_frame(s, pkt); + if (ret < 0) { + av_packet_free(&pkt); return AV_NOPTS_VALUE; - if (pkt.dts != AV_NOPTS_VALUE && pkt.pos >= 0) { - ff_reduce_index(s, pkt.stream_index); - av_add_index_entry(s->streams[pkt.stream_index], pkt.pos, pkt.dts, 0, 0, AVINDEX_KEYFRAME /* FIXME keyframe? */); - if (pkt.stream_index == stream_index && pkt.pos >= *ppos) { - int64_t dts = pkt.dts; - *ppos = pkt.pos; - av_packet_unref(&pkt); + } + if (pkt->dts != AV_NOPTS_VALUE && pkt->pos >= 0) { + ff_reduce_index(s, pkt->stream_index); + av_add_index_entry(s->streams[pkt->stream_index], pkt->pos, pkt->dts, 0, 0, AVINDEX_KEYFRAME /* FIXME keyframe? */); + if (pkt->stream_index == stream_index && pkt->pos >= *ppos) { + int64_t dts = pkt->dts; + *ppos = pkt->pos; + av_packet_free(&pkt); return dts; } } - pos = pkt.pos; - av_packet_unref(&pkt); + pos = pkt->pos; + av_packet_unref(pkt); } + av_packet_free(&pkt); return AV_NOPTS_VALUE; } From patchwork Fri Mar 5 16:33:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26146 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 A996244BC3D for ; Fri, 5 Mar 2021 18:40:45 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 050C768ACA6; Fri, 5 Mar 2021 18:36:05 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f172.google.com (mail-qt1-f172.google.com [209.85.160.172]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7EDF268AC42 for ; Fri, 5 Mar 2021 18:36:00 +0200 (EET) Received: by mail-qt1-f172.google.com with SMTP id 18so2183037qty.3 for ; Fri, 05 Mar 2021 08:36:00 -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=IJtjBt/6foeROso7O4j+NHlWbkIDoF+9EIsMwditVcg=; b=taaqBjOBTozxFESzlxjeE/sc8329cph19sc54cQhyyrgfL/K9HTV+RuEQlfRiSlZka MygWlmZC6/BIcTBTULq2pzYGKTQA75ZIZlCScgtTqAnN1mm09LBLQYcXYAO+cH+wu3du emaf9i81w4C8oY8Ocwxdk2T9S67MQunLmzBjHiRuFCVVzf807u95HQk9bXZz20ciZBlR qAOnavx05hZnlGssbG4eHkUsEiYI74wSvzjbq64tD4CV8tM5yXRvvOTBJ3aEbYKVYVPr 6Cy32oXOy07c6rtgsF8CbMsC6CyM/ehwotcEoKDeRM+Vh1SqAkC3HKwbYqBDQuFc1VD7 Rliw== 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=IJtjBt/6foeROso7O4j+NHlWbkIDoF+9EIsMwditVcg=; b=e3743WQBh3R6fgOt18kWB/qGciYX+imOY7TBOUtahQ9f9oP7CJqgvjdoXKFZeKH5gC 421pRPOMrN8xlQwb64u1oxuoI4RuEhw2z5wcirYJGSPelSQc6/zoXWBImIHXe3mLjrbM MwdO/rwwmOP8mIT1PVfmpx8U57e1uSW2e+xoR2nt4/0WZbkiK7mZ+W/oncX40/HYcCg+ aP4sBm+JpWPYDY1ZcQr0p4zPgP85lhOtbsVrZ/COMHF/nCCknBrW5Bb5EfIwDbvkGIzr TD3ss+YTt0uRGt00LJjBj8j5oBD57rZ49FOJRLJS5AK1lZ0q/Mq9zLZs7bMlJbucDh64 zxng== X-Gm-Message-State: AOAM531LahuUuYLI4gHVIOmah5m/5TMZWf/E3p89YDpmB7/FWN9CpuGY 7T9HsvG+aY9vw6+h+TMVCD0Vv0a6J3r1nQ== X-Google-Smtp-Source: ABdhPJxcLmmiA4HqZGji44U0qJnUJkQO/fCTE8L30fHYSSaN8QXw9onAVnsNbaKkQ3HQeT7HIrAtSw== X-Received: by 2002:ac8:578f:: with SMTP id v15mr9274302qta.172.1614962158628; Fri, 05 Mar 2021 08:35:58 -0800 (PST) Received: from localhost.localdomain ([181.23.89.132]) by smtp.gmail.com with ESMTPSA id b10sm2168494qtt.23.2021.03.05.08.35.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 08:35:58 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Mar 2021 13:33:17 -0300 Message-Id: <20210305163339.63164-27-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 26/48] avformat/mpegtsenc: 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/mpegtsenc.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c index 45f8d5f373..baf303dc60 100644 --- a/libavformat/mpegtsenc.c +++ b/libavformat/mpegtsenc.c @@ -77,6 +77,7 @@ typedef struct MpegTSWrite { MpegTSSection pat; /* MPEG-2 PAT table */ MpegTSSection sdt; /* MPEG-2 SDT table context */ MpegTSService **services; + AVPacket *pkt; int64_t sdt_period; /* SDT period in PCR time base */ int64_t pat_period; /* PAT/PMT period in PCR time base */ int nb_services; @@ -1022,6 +1023,10 @@ static int mpegts_init(AVFormatContext *s) ts->sdt.write_packet = section_write_packet; ts->sdt.opaque = s; + ts->pkt = av_packet_alloc(); + if (!ts->pkt) + return AVERROR(ENOMEM); + /* assign pids to each stream */ for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; @@ -1745,23 +1750,23 @@ static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt) } if ((AV_RB16(pkt->data) & 0xfff0) != 0xfff0) { int ret; - AVPacket pkt2; + AVPacket *pkt2 = ts->pkt; if (!ts_st->amux) { av_log(s, AV_LOG_ERROR, "AAC bitstream not in ADTS format " "and extradata missing\n"); } else { - av_init_packet(&pkt2); - pkt2.data = pkt->data; - pkt2.size = pkt->size; + av_packet_unref(pkt2); + pkt2->data = pkt->data; + pkt2->size = pkt->size; av_assert0(pkt->dts != AV_NOPTS_VALUE); - pkt2.dts = av_rescale_q(pkt->dts, st->time_base, ts_st->amux->streams[0]->time_base); + pkt2->dts = av_rescale_q(pkt->dts, st->time_base, ts_st->amux->streams[0]->time_base); ret = avio_open_dyn_buf(&ts_st->amux->pb); if (ret < 0) return ret; - ret = av_write_frame(ts_st->amux, &pkt2); + ret = av_write_frame(ts_st->amux, pkt2); if (ret < 0) { ffio_free_dyn_buf(&ts_st->amux->pb); return ret; @@ -2020,6 +2025,8 @@ static void mpegts_deinit(AVFormatContext *s) MpegTSService *service; int i; + av_packet_free(&ts->pkt); + for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; MpegTSWriteStream *ts_st = st->priv_data; From patchwork Fri Mar 5 16:33:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26169 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a25:6d42:0:0:0:0:0 with SMTP id i63csp529903ybc; Fri, 5 Mar 2021 08:41:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJzo73wM0hmh5iAP1xRS0/4hSuhdm0QgteMfj4oJfFE8rTIsYoLIJmdt10rvUWFn9JukbQh8 X-Received: by 2002:a17:906:6c93:: with SMTP id s19mr2903556ejr.151.1614962463652; Fri, 05 Mar 2021 08:41:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614962463; cv=none; d=google.com; s=arc-20160816; b=Nuw4aKAHSTJFrrXIApFLAWDGuU91Bu91d5pe7UXq+hi3h4Km7SfCAjrIBWrEWBlp1o CtgO/kLkseZWGQbweljyCuzBJJpHOXLCaPXUWc8BKr2M92ScZPXsXJPiqGQTI1eNWESJ X/Vu/22kDPD3SGUUkJLC2z/JbcbLsiWEGYcfzw72UD3rhaXMJ0LC1mrPI5Foc7otXHul UmTANMYLZW5kY0iWyxIZTXOTz6SSkQtqzXqxByks2Tj6wczk3ovv36cMs6oIQjN6x9Qm yI3Zg7GoNSvDkaZK4968i5rpN4dmFsk8EbY2GVKJhrOjgafrqPV881DW4E8o0yZoSDrT yTSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=0Hx6J82pu7L7orpzHBPvECWBAWqlSpToyfaFgloXBck=; b=xTF3+Wn5n8KDhAgQQBWAjjPThMLDO4Uy0hoyVmMu0wAVpnvzVhTHHKDgkJKV6KNLOY TNhyOn1GxfK5DQ+9SgvN8LAhPErs1R1rTCvuJ83kT+D6xHUzuUPKLmHJRPXnw72XVrH+ bV2wiFqsO8qh1Gxy2TMhXmMGjM8L2127j6Bf9ziADq+tR7k6/SKByKE5T5ca+dF0umao /r4FfngNMdAjSOL2JaqShKm2HmHXjglimodoUzSTGFoOEiCFNZsauY+21reGpaoUzv4C oH4YdNHkpx6ht5idKnwvreiIyAO78WtaA02jSkdbBXE3nLQwUy1jlYOKdMY7sGKd1Aac wsqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=rjZ6Htds; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id mp41si1638690ejc.10.2021.03.05.08.41.03; Fri, 05 Mar 2021 08:41:03 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=rjZ6Htds; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 87F3C68ACC4; Fri, 5 Mar 2021 18:36:07 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f175.google.com (mail-qt1-f175.google.com [209.85.160.175]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C55CA68AC35 for ; Fri, 5 Mar 2021 18:36:01 +0200 (EET) Received: by mail-qt1-f175.google.com with SMTP id d11so2146806qtx.9 for ; Fri, 05 Mar 2021 08:36:01 -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=kdOjtR91a7y0nE6hBQ149jg9Uqy4bBbYf35qiq80+fw=; b=rjZ6HtdsJFhBKt8OaQ+B6SOwe6NEvWWsO6GbxwlMh9m5Qzj90MAf5c+3b9Ez57zT8G c+x6nQnmy4TtdFXuY8Zw71GUuclqQVP6Sdr3qDEtzfC4OG14UqvmS/KDavgIUEIHB1rc bNmZVNb/v+JpsjdmYw1QLXRmoRGE3LnuSxcPUx72I6JDx177LCsAC9IWNMn41iLxnJz5 4oqglBHpoBpuFUHamgwnRJTTNs6uI7gZT8588dR0iKoB2KXL0SNagDmfMXPhYCmoo5Xi GqPrIdhHHcOFopxhoaqm7k0NlB6cqf8u19KewrVh8Z1BNcCbuGQG50S/piJ5UHhR/KvE okAw== 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=kdOjtR91a7y0nE6hBQ149jg9Uqy4bBbYf35qiq80+fw=; b=iBz4b7xAfQJpTatH3tKV/vXyv077R0lgIlOSBuTqW9WGDGMbNEmtaAoavr0D6qd3ye GYQt09OxxSvUd+g5DGjFEUhNGip+DzKX6L3ssbdFMq9X18Fs+9JBeSRusbbK5/nd5yc5 pi+WQIJrEB6zzNZd5oUXBsv8mRCPwyLoPKihMpkJ2Q4Kr8ow8K3BSylKPb4/4bCr8b0s elLi+d+o3MLvDfsHxS2Yft/51VuAYTZyn4r+zKDsoLtg7xVFfA4IXUG2yFEB1DQk0l99 7TmNMI3yVRbpcgzyjAcl2hR7YyoBNhuX3qQSRHjRlmRQnpeVLY9UWVgIqsOH9OXFW4xb TNYQ== X-Gm-Message-State: AOAM532e6XFLsq4ZWj4YL3UZq0BY7GAM1l2KVkUs2q9rFikjbr85BONl BcfZvGquzOlNPJsuhLqS3jl7q/KjYWWISg== X-Received: by 2002:ac8:5ec8:: with SMTP id s8mr9513561qtx.256.1614962160015; Fri, 05 Mar 2021 08:36:00 -0800 (PST) Received: from localhost.localdomain ([181.23.89.132]) by smtp.gmail.com with ESMTPSA id b10sm2168494qtt.23.2021.03.05.08.35.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 08:35:59 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Mar 2021 13:33:18 -0300 Message-Id: <20210305163339.63164-28-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 27/48] avformat/rtpdec: 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" X-TUID: Ckx1gKyQYiBu Content-Length: 8584 Signed-off-by: James Almer --- libavformat/rtpdec.c | 2 +- libavformat/rtpdec_qt.c | 63 ++++++++++++++++++++++++----------------- 2 files changed, 38 insertions(+), 27 deletions(-) diff --git a/libavformat/rtpdec.c b/libavformat/rtpdec.c index d592e34893..fd4601e654 100644 --- a/libavformat/rtpdec.c +++ b/libavformat/rtpdec.c @@ -964,7 +964,7 @@ int ff_parse_fmtp(AVFormatContext *s, int ff_rtp_finalize_packet(AVPacket *pkt, AVIOContext **dyn_buf, int stream_idx) { int ret; - av_init_packet(pkt); + av_packet_unref(pkt); pkt->size = avio_close_dyn_buf(*dyn_buf, &pkt->data); pkt->stream_index = stream_idx; diff --git a/libavformat/rtpdec_qt.c b/libavformat/rtpdec_qt.c index 93bf31746b..de6b12fb04 100644 --- a/libavformat/rtpdec_qt.c +++ b/libavformat/rtpdec_qt.c @@ -34,11 +34,21 @@ #include "libavcodec/get_bits.h" struct PayloadContext { - AVPacket pkt; + AVPacket *pkt; int bytes_per_frame, remaining; uint32_t timestamp; }; +static av_cold int qt_rtp_init(AVFormatContext *ctx, int st_index, + PayloadContext *qt) +{ + qt->pkt = av_packet_alloc(); + if (!qt->pkt) + return AVERROR(ENOMEM); + + return 0; +} + static int qt_rtp_parse_packet(AVFormatContext *s, PayloadContext *qt, AVStream *st, AVPacket *pkt, uint32_t *timestamp, const uint8_t *buf, @@ -51,18 +61,18 @@ static int qt_rtp_parse_packet(AVFormatContext *s, PayloadContext *qt, keyframe, ret; if (qt->remaining) { - int num = qt->pkt.size / qt->bytes_per_frame; + int num = qt->pkt->size / qt->bytes_per_frame; if ((ret = av_new_packet(pkt, qt->bytes_per_frame)) < 0) return ret; pkt->stream_index = st->index; - pkt->flags = qt->pkt.flags; + pkt->flags = qt->pkt->flags; memcpy(pkt->data, - &qt->pkt.data[(num - qt->remaining) * qt->bytes_per_frame], + &qt->pkt->data[(num - qt->remaining) * qt->bytes_per_frame], qt->bytes_per_frame); if (--qt->remaining == 0) { - av_freep(&qt->pkt.data); - qt->pkt.size = 0; + av_freep(&qt->pkt->data); + qt->pkt->size = 0; } return qt->remaining > 0; } @@ -171,31 +181,31 @@ static int qt_rtp_parse_packet(AVFormatContext *s, PayloadContext *qt, switch (packing_scheme) { case 3: /* one data packet spread over 1 or multiple RTP packets */ - if (qt->pkt.size > 0 && qt->timestamp == *timestamp) { + if (qt->pkt->size > 0 && qt->timestamp == *timestamp) { int err; - if ((err = av_reallocp(&qt->pkt.data, qt->pkt.size + alen + + if ((err = av_reallocp(&qt->pkt->data, qt->pkt->size + alen + AV_INPUT_BUFFER_PADDING_SIZE)) < 0) { - qt->pkt.size = 0; + qt->pkt->size = 0; return err; } } else { - av_freep(&qt->pkt.data); - av_init_packet(&qt->pkt); - qt->pkt.data = av_realloc(NULL, alen + AV_INPUT_BUFFER_PADDING_SIZE); - if (!qt->pkt.data) + av_freep(&qt->pkt->data); + av_packet_unref(qt->pkt); + qt->pkt->data = av_realloc(NULL, alen + AV_INPUT_BUFFER_PADDING_SIZE); + if (!qt->pkt->data) return AVERROR(ENOMEM); - qt->pkt.size = 0; + qt->pkt->size = 0; qt->timestamp = *timestamp; } - memcpy(qt->pkt.data + qt->pkt.size, buf + avio_tell(&pb), alen); - qt->pkt.size += alen; + memcpy(qt->pkt->data + qt->pkt->size, buf + avio_tell(&pb), alen); + qt->pkt->size += alen; if (has_marker_bit) { - int ret = av_packet_from_data(pkt, qt->pkt.data, qt->pkt.size); + int ret = av_packet_from_data(pkt, qt->pkt->data, qt->pkt->size); if (ret < 0) return ret; - qt->pkt.size = 0; - qt->pkt.data = NULL; + qt->pkt->size = 0; + qt->pkt->data = NULL; pkt->flags = keyframe ? AV_PKT_FLAG_KEY : 0; pkt->stream_index = st->index; memset(pkt->data + pkt->size, 0, AV_INPUT_BUFFER_PADDING_SIZE); @@ -214,17 +224,17 @@ static int qt_rtp_parse_packet(AVFormatContext *s, PayloadContext *qt, pkt->flags = keyframe ? AV_PKT_FLAG_KEY : 0; pkt->stream_index = st->index; if (qt->remaining > 0) { - av_freep(&qt->pkt.data); - qt->pkt.data = av_realloc(NULL, qt->remaining * qt->bytes_per_frame); - if (!qt->pkt.data) { + av_freep(&qt->pkt->data); + qt->pkt->data = av_realloc(NULL, qt->remaining * qt->bytes_per_frame); + if (!qt->pkt->data) { av_packet_unref(pkt); return AVERROR(ENOMEM); } - qt->pkt.size = qt->remaining * qt->bytes_per_frame; - memcpy(qt->pkt.data, + qt->pkt->size = qt->remaining * qt->bytes_per_frame; + memcpy(qt->pkt->data, buf + avio_tell(&pb) + qt->bytes_per_frame, qt->remaining * qt->bytes_per_frame); - qt->pkt.flags = pkt->flags; + qt->pkt->flags = pkt->flags; return 1; } return 0; @@ -237,7 +247,7 @@ static int qt_rtp_parse_packet(AVFormatContext *s, PayloadContext *qt, static void qt_rtp_close(PayloadContext *qt) { - av_freep(&qt->pkt.data); + av_packet_free(&qt->pkt); } #define RTP_QT_HANDLER(m, n, s, t) \ @@ -246,6 +256,7 @@ const RTPDynamicProtocolHandler ff_ ## m ## _rtp_ ## n ## _handler = { \ .codec_type = t, \ .codec_id = AV_CODEC_ID_NONE, \ .priv_data_size = sizeof(PayloadContext), \ + .init = qt_rtp_init, \ .close = qt_rtp_close, \ .parse_packet = qt_rtp_parse_packet, \ } From patchwork Fri Mar 5 16:33:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26201 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a25:6d42:0:0:0:0:0 with SMTP id i63csp530025ybc; Fri, 5 Mar 2021 08:41:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJxBRxDhO2wdiZpdvZOgxYN500G2ufQwjYZ/4g/cx/UiHY49+YaFLqMM7Mq86KBO/2E1opFa X-Received: by 2002:a17:906:b0d8:: with SMTP id bk24mr3060768ejb.252.1614962472125; Fri, 05 Mar 2021 08:41:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614962472; cv=none; d=google.com; s=arc-20160816; b=D/EgLbyUj0yN7o+gfPpohr9GOtMnvnGaSGGg+5VjYD7jVh0gN7wTtFiqxDQ5i3l9pb uYulXZCElqGIDiWg2AhRH8neZ7K9wXiLQsbbh0S5k+nwdvdk7YdRYEz0WIExMY5MXc6v 0kkA0A5f9bmLJ4W0v/UThtlua0LSNrvluH1et7zk9W2k8KVuMa4T/PNNUNQzjkOlmlLH 7qTrF0fK/bA1S+Z271BYGabeBlso9KNP6z/9QCTMN64iNPAOhMHE7AznblOaFTkptYwH dY/LFw3K/wB0LQ9IBPsjBPPsJ0tVMVMLZudfRAJXnnt0aTHJ5l8tAHadSm6IVDT7X5EP 4GEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=pJ4WsMUs1tK84K2v47mlgAy4nzrmnblup9CigOi5QMk=; b=uK/Ul2k+sgwLi2ZXnJaHQBBdXxWQ6tkhJScTKPxQSui23OJdaMTffT9nupT/weF+a2 obcDUgAImY9F6y3S/nvA0OLtRifb+7+pi2xkJmtV8rMOdVH489jaO38/IcKPpEH2Yr4p UT1br0epaeaQhCc9u6uLVzr+StFQF0z4DC1KW7x7uCR7JrDc/LjwGL/do1+1ICzWR6Vb vXvD8E9iNUUiNPLAx1CUqo2SqTX3ncs8RsVada2zRxSP9ds47m2ElT4LAvBDtThTed7v GVA7a/vG6NMOfwis2kzJXCVojKXyLpsZf8VvI7Hi3sNnweUI+DsfOqPTG37MDfAhEcUt bgvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b="UiDZ/sZD"; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id ay21si1576660ejb.527.2021.03.05.08.41.11; Fri, 05 Mar 2021 08:41:12 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b="UiDZ/sZD"; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 23FE168ACD7; Fri, 5 Mar 2021 18:36:08 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f179.google.com (mail-qt1-f179.google.com [209.85.160.179]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AA7CC68AC5F for ; Fri, 5 Mar 2021 18:36:02 +0200 (EET) Received: by mail-qt1-f179.google.com with SMTP id r24so2146559qtt.8 for ; Fri, 05 Mar 2021 08:36:02 -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=3gzFVkfs54kHG2mzYJn5r+2TYpHuqkhhiIJiFD6br6o=; b=UiDZ/sZDW204wyecBxejk7UIEr1TtkiBkhwMcgwUqagTfZW2wFGvFYqiwRueyLKbqo TEB40u44nCzDkiCQ3DYOulm11sKUVG06fWjtYIZg/QMyZZF3XWxJbsL38t0T0JZF11zk zPc2nJdQc1dZAivgB+C67V1bZv+UNuoT9GshwbxyobnfCv/Q1ZYXVBjGMaA2GUHbBVbX iI5lZWzFA0MhSUkxkZrXUbLoTRjpitPy5fLg1sKXBFOSDtAUl6IPzHVMZGLaOVLFvjn1 dTO8OPIQWDZWMS5KVbVw/Yt0Zc05DCAYAt8MRfrzHqCcXBMRJ3FIXKwP1IpMYGOwe6PJ LwJg== 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=3gzFVkfs54kHG2mzYJn5r+2TYpHuqkhhiIJiFD6br6o=; b=Bs3V2rjimsbB3+cUay4R2/nGKM955CQL3KSkUG6IWYx4iliYVXbPopGXa80ItavY02 tAc3d923A/aiVqxczebPhtoK9/56lwzcQo9dVYBRcA+rNRzPJYNK8Pufcv8Da35K3hmj y0DtZYLUbm+z/WYF7xxDIL7HLh0pzUCxs8T4zsgtLIH49h5Ixr+H6D0l9xZ1SZDmWKEe XVw0+miy24fQFahS2ZPF3mU1ajhjZniy3Lzgp0n6DXY9RUnNl9yCZW4wA563zycqSeWf v+X/sPtmHaiZXiD2xAO0mO2Ogk0qVbs8p3ZDpmnankdPf9KRSX7fLKcPoes8TTWyGzbt roOQ== X-Gm-Message-State: AOAM5319zgSqiImgKOimKXGZyhFx45bk4wjXX45R0fPHCYJEJsQtFQ4B 6jhNwbj1/TiYaPbgof55VNfHWJFH8jN0hg== X-Received: by 2002:aed:2b61:: with SMTP id p88mr2389630qtd.360.1614962161275; Fri, 05 Mar 2021 08:36:01 -0800 (PST) Received: from localhost.localdomain ([181.23.89.132]) by smtp.gmail.com with ESMTPSA id b10sm2168494qtt.23.2021.03.05.08.36.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 08:36:00 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Mar 2021 13:33:19 -0300 Message-Id: <20210305163339.63164-29-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 28/48] avformat/rtpenc_mpegts: 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" X-TUID: +QEIDopr6Eml Content-Length: 3919 Signed-off-by: James Almer --- libavformat/rtpenc_mpegts.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/libavformat/rtpenc_mpegts.c b/libavformat/rtpenc_mpegts.c index 7d7377db7a..50cebf68a3 100644 --- a/libavformat/rtpenc_mpegts.c +++ b/libavformat/rtpenc_mpegts.c @@ -26,6 +26,7 @@ struct MuxChain { AVFormatContext *mpegts_ctx; AVFormatContext *rtp_ctx; + AVPacket *pkt; }; static int rtp_mpegts_write_close(AVFormatContext *s) @@ -41,6 +42,9 @@ static int rtp_mpegts_write_close(AVFormatContext *s) av_write_trailer(chain->rtp_ctx); avformat_free_context(chain->rtp_ctx); } + + av_packet_free(&chain->pkt); + return 0; } @@ -58,6 +62,9 @@ static int rtp_mpegts_write_header(AVFormatContext *s) mpegts_ctx = avformat_alloc_context(); if (!mpegts_ctx) return AVERROR(ENOMEM); + chain->pkt = av_packet_alloc(); + if (!chain->pkt) + goto fail; mpegts_ctx->oformat = mpegts_format; mpegts_ctx->max_delay = s->max_delay; av_dict_copy(&mpegts_ctx->metadata, s->metadata, 0); @@ -116,7 +123,7 @@ static int rtp_mpegts_write_packet(AVFormatContext *s, AVPacket *pkt) struct MuxChain *chain = s->priv_data; int ret = 0, size; uint8_t *buf; - AVPacket local_pkt; + AVPacket *local_pkt = chain->pkt; if (!chain->mpegts_ctx->pb) { if ((ret = avio_open_dyn_buf(&chain->mpegts_ctx->pb)) < 0) @@ -130,19 +137,19 @@ static int rtp_mpegts_write_packet(AVFormatContext *s, AVPacket *pkt) av_free(buf); return 0; } - av_init_packet(&local_pkt); - local_pkt.data = buf; - local_pkt.size = size; - local_pkt.stream_index = 0; + av_packet_unref(local_pkt); + local_pkt->data = buf; + local_pkt->size = size; + local_pkt->stream_index = 0; if (pkt->pts != AV_NOPTS_VALUE) - local_pkt.pts = av_rescale_q(pkt->pts, + local_pkt->pts = av_rescale_q(pkt->pts, s->streams[pkt->stream_index]->time_base, chain->rtp_ctx->streams[0]->time_base); if (pkt->dts != AV_NOPTS_VALUE) - local_pkt.dts = av_rescale_q(pkt->dts, + local_pkt->dts = av_rescale_q(pkt->dts, s->streams[pkt->stream_index]->time_base, chain->rtp_ctx->streams[0]->time_base); - ret = av_write_frame(chain->rtp_ctx, &local_pkt); + ret = av_write_frame(chain->rtp_ctx, local_pkt); av_free(buf); return ret; From patchwork Fri Mar 5 16:33:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26147 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 0736444AB0A for ; Fri, 5 Mar 2021 18:41:21 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F24D768ACC9; Fri, 5 Mar 2021 18:36:08 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qv1-f49.google.com (mail-qv1-f49.google.com [209.85.219.49]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5C92D68AC9C for ; Fri, 5 Mar 2021 18:36:04 +0200 (EET) Received: by mail-qv1-f49.google.com with SMTP id bh3so1276890qvb.5 for ; Fri, 05 Mar 2021 08:36:04 -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=XxvhthwhUv6+Kp+SCchpIu7GjJ/0/0oUOM0ILH8JLXw=; b=pH1JsLfTGtmxo+ZBshqwrTXO01Uzus4MpNZP7O9f61FukWeztzngKJ8t8ZEoHRdVi9 ekw/vfiu+SSdPNE95iGtW0VLJDbfHIVX6QuAKhAkz9WzOmkgyrlsZSdb5B2qWUzwW7Ec Two0Szt7YLx7+5hWdpFZ1WqJjDunQylu+MEa4SUKx0GNvWdbKnLkvKmaOTuGCnivgKcr WpGFikIyoD0HqXOk+ipqIab0vQt5wIULupRB05Tm6AHcsHTw5nplpTCuNk9EhpmCNysp QxtLVQrVNHiaKoK5EATozEzrjtqd5eLcrVpXSdcv3nJpPvjmS/ZvhOnS9Huyrk86oqHO arsA== 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=XxvhthwhUv6+Kp+SCchpIu7GjJ/0/0oUOM0ILH8JLXw=; b=MkPhJNJAqx5VAj+1M/YAexa8gIbeCWSSqIUd8NCt6dkVnuy7TTf4qv6iJMh6cWsjYP 3LZFIuFcObnJmWkNG/IbtZFcPteu/UzkUGXxolkVbCNm/3fBjR+MMbOCg8MsVDBcspqi eGNb9awOZg5OaVCzTuCobBkYOeRvs6NppckQKSTuL/MAp17m4gr7nB/jkxE2H8zDKqNv Etj5NjgF92EFfvYhfAvUfKPENWgCda70h5kCYOAtyKUxo39kLGBPCulVgfNIK8ts9M3w 3yGUVfrfWDd2VzHT5ICeFj8CQaFHau11UBRB8ET0gfleMfGNox3t5kZARzAwoH/lTw/l mv7A== X-Gm-Message-State: AOAM533QBk/MVlZE7vxG+GtVudDUjfuKNTW9Qt5k21pXOadSt3FCw+/M yWwyLgc7cen5lozF59E8IudYIVT7PphjRA== X-Google-Smtp-Source: ABdhPJz/2U5OIXEEYuml6tAoCPmSvW4IqGzKh9qMz64GQOhyJDMjfRVucjT3b6C8d/Q3A4eU6Vxe+A== X-Received: by 2002:a0c:aa10:: with SMTP id d16mr9596922qvb.42.1614962162528; Fri, 05 Mar 2021 08:36:02 -0800 (PST) Received: from localhost.localdomain ([181.23.89.132]) by smtp.gmail.com with ESMTPSA id b10sm2168494qtt.23.2021.03.05.08.36.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 08:36:02 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Mar 2021 13:33:20 -0300 Message-Id: <20210305163339.63164-30-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 29/48] avformat/subtitles: 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/jacosubdec.c | 2 +- libavformat/mpeg.c | 4 +-- libavformat/mpsubdec.c | 4 +-- libavformat/subtitles.c | 69 +++++++++++++++++++----------------- libavformat/subtitles.h | 2 +- libavformat/tedcaptionsdec.c | 4 +-- 6 files changed, 45 insertions(+), 40 deletions(-) diff --git a/libavformat/jacosubdec.c b/libavformat/jacosubdec.c index 14221b166c..b44e3b7783 100644 --- a/libavformat/jacosubdec.c +++ b/libavformat/jacosubdec.c @@ -250,7 +250,7 @@ static int jacosub_read_header(AVFormatContext *s) /* SHIFT and TIMERES affect the whole script so packet timing can only be * done in a second pass */ for (i = 0; i < jacosub->q.nb_subs; i++) { - AVPacket *sub = &jacosub->q.subs[i]; + AVPacket *sub = jacosub->q.subs[i]; read_ts(jacosub, sub->data, &sub->pts, &sub->duration); } ff_subtitles_queue_finalize(s, &jacosub->q); diff --git a/libavformat/mpeg.c b/libavformat/mpeg.c index 20d1e10168..79610ec600 100644 --- a/libavformat/mpeg.c +++ b/libavformat/mpeg.c @@ -934,7 +934,7 @@ static int vobsub_read_packet(AVFormatContext *s, AVPacket *pkt) if (tmpq->current_sub_idx >= tmpq->nb_subs) continue; - ts = tmpq->subs[tmpq->current_sub_idx].pts; + ts = tmpq->subs[tmpq->current_sub_idx]->pts; if (ts < min_ts) { min_ts = ts; sid = i; @@ -950,7 +950,7 @@ static int vobsub_read_packet(AVFormatContext *s, AVPacket *pkt) /* compute maximum packet size using the next packet position. This is * useful when the len in the header is non-sense */ if (q->current_sub_idx < q->nb_subs) { - psize = q->subs[q->current_sub_idx].pos - pkt->pos; + psize = q->subs[q->current_sub_idx]->pos - pkt->pos; } else { int64_t fsize = avio_size(pb); psize = fsize < 0 ? 0xffff : fsize - pkt->pos; diff --git a/libavformat/mpsubdec.c b/libavformat/mpsubdec.c index 2e6dc883eb..c113be5eba 100644 --- a/libavformat/mpsubdec.c +++ b/libavformat/mpsubdec.c @@ -147,8 +147,8 @@ static int mpsub_read_header(AVFormatContext *s) if (common_factor > 1) { common_factor = av_gcd(pts_info.num, common_factor); for (i = 0; i < mpsub->q.nb_subs; i++) { - mpsub->q.subs[i].pts /= common_factor; - mpsub->q.subs[i].duration /= common_factor; + mpsub->q.subs[i]->pts /= common_factor; + mpsub->q.subs[i]->duration /= common_factor; } pts_info.num /= common_factor; } diff --git a/libavformat/subtitles.c b/libavformat/subtitles.c index ad7f68938e..05c07cd852 100644 --- a/libavformat/subtitles.c +++ b/libavformat/subtitles.c @@ -111,13 +111,13 @@ int ff_text_peek_r8(FFTextReader *r) AVPacket *ff_subtitles_queue_insert(FFDemuxSubtitlesQueue *q, const uint8_t *event, size_t len, int merge) { - AVPacket *subs, *sub; + AVPacket **subs, *sub; if (merge && q->nb_subs > 0) { /* merge with previous event */ int old_len; - sub = &q->subs[q->nb_subs - 1]; + sub = q->subs[q->nb_subs - 1]; old_len = sub->size; if (av_grow_packet(sub, len) < 0) return NULL; @@ -132,10 +132,14 @@ AVPacket *ff_subtitles_queue_insert(FFDemuxSubtitlesQueue *q, if (!subs) return NULL; q->subs = subs; - sub = &subs[q->nb_subs]; - if (av_new_packet(sub, len) < 0) + sub = av_packet_alloc(); + if (!sub) return NULL; - q->nb_subs++; + if (av_new_packet(sub, len) < 0) { + av_packet_free(&sub); + return NULL; + } + subs[q->nb_subs++] = sub; sub->flags |= AV_PKT_FLAG_KEY; sub->pts = sub->dts = 0; memcpy(sub->data, event, len); @@ -145,8 +149,8 @@ AVPacket *ff_subtitles_queue_insert(FFDemuxSubtitlesQueue *q, static int cmp_pkt_sub_ts_pos(const void *a, const void *b) { - const AVPacket *s1 = a; - const AVPacket *s2 = b; + const AVPacket *s1 = *(const AVPacket **)a; + const AVPacket *s2 = *(const AVPacket **)b; if (s1->pts == s2->pts) return FFDIFFSIGN(s1->pos, s2->pos); return FFDIFFSIGN(s1->pts , s2->pts); @@ -154,8 +158,8 @@ static int cmp_pkt_sub_ts_pos(const void *a, const void *b) static int cmp_pkt_sub_pos_ts(const void *a, const void *b) { - const AVPacket *s1 = a; - const AVPacket *s2 = b; + const AVPacket *s1 = *(const AVPacket **)a; + const AVPacket *s2 = *(const AVPacket **)b; if (s1->pos == s2->pos) { if (s1->pts == s2->pts) return 0; @@ -170,18 +174,18 @@ static void drop_dups(void *log_ctx, FFDemuxSubtitlesQueue *q) for (i = 1; i < q->nb_subs; i++) { const int last_id = i - 1 - drop; - const AVPacket *last = &q->subs[last_id]; + const AVPacket *last = q->subs[last_id]; - if (q->subs[i].pts == last->pts && - q->subs[i].duration == last->duration && - q->subs[i].stream_index == last->stream_index && - !strcmp(q->subs[i].data, last->data)) { + if (q->subs[i]->pts == last->pts && + q->subs[i]->duration == last->duration && + q->subs[i]->stream_index == last->stream_index && + !strcmp(q->subs[i]->data, last->data)) { - av_packet_unref(&q->subs[i]); + av_packet_free(&q->subs[i]); drop++; } else if (drop) { q->subs[last_id + 1] = q->subs[i]; - memset(&q->subs[i], 0, sizeof(q->subs[i])); // for safety + q->subs[i] = NULL; } } @@ -202,8 +206,8 @@ void ff_subtitles_queue_finalize(void *log_ctx, FFDemuxSubtitlesQueue *q) q->sort == SUB_SORT_TS_POS ? cmp_pkt_sub_ts_pos : cmp_pkt_sub_pos_ts); for (i = 0; i < q->nb_subs; i++) - if (q->subs[i].duration < 0 && i < q->nb_subs - 1) - q->subs[i].duration = q->subs[i + 1].pts - q->subs[i].pts; + if (q->subs[i]->duration < 0 && i < q->nb_subs - 1) + q->subs[i]->duration = q->subs[i + 1]->pts - q->subs[i]->pts; if (!q->keep_duplicates) drop_dups(log_ctx, q); @@ -211,11 +215,12 @@ void ff_subtitles_queue_finalize(void *log_ctx, FFDemuxSubtitlesQueue *q) int ff_subtitles_queue_read_packet(FFDemuxSubtitlesQueue *q, AVPacket *pkt) { - AVPacket *sub = q->subs + q->current_sub_idx; + AVPacket *sub; int ret; if (q->current_sub_idx == q->nb_subs) return AVERROR_EOF; + sub = q->subs[q->current_sub_idx]; if ((ret = av_packet_ref(pkt, sub)) < 0) { return ret; } @@ -238,9 +243,9 @@ static int search_sub_ts(const FFDemuxSubtitlesQueue *q, int64_t ts) if (s1 == s2) return s1; if (s1 == s2 - 1) - return q->subs[s1].pts <= q->subs[s2].pts ? s1 : s2; + return q->subs[s1]->pts <= q->subs[s2]->pts ? s1 : s2; mid = (s1 + s2) / 2; - if (q->subs[mid].pts <= ts) + if (q->subs[mid]->pts <= ts) s1 = mid; else s2 = mid; @@ -262,24 +267,24 @@ int ff_subtitles_queue_seek(FFDemuxSubtitlesQueue *q, AVFormatContext *s, int st if (idx < 0) return idx; - for (i = idx; i < q->nb_subs && q->subs[i].pts < min_ts; i++) - if (stream_index == -1 || q->subs[i].stream_index == stream_index) + for (i = idx; i < q->nb_subs && q->subs[i]->pts < min_ts; i++) + if (stream_index == -1 || q->subs[i]->stream_index == stream_index) idx = i; - for (i = idx; i > 0 && q->subs[i].pts > max_ts; i--) - if (stream_index == -1 || q->subs[i].stream_index == stream_index) + for (i = idx; i > 0 && q->subs[i]->pts > max_ts; i--) + if (stream_index == -1 || q->subs[i]->stream_index == stream_index) idx = i; - ts_selected = q->subs[idx].pts; + ts_selected = q->subs[idx]->pts; if (ts_selected < min_ts || ts_selected > max_ts) return AVERROR(ERANGE); /* look back in the latest subtitles for overlapping subtitles */ for (i = idx - 1; i >= 0; i--) { - int64_t pts = q->subs[i].pts; - if (q->subs[i].duration <= 0 || - (stream_index != -1 && q->subs[i].stream_index != stream_index)) + int64_t pts = q->subs[i]->pts; + if (q->subs[i]->duration <= 0 || + (stream_index != -1 && q->subs[i]->stream_index != stream_index)) continue; - if (pts >= min_ts && pts > ts_selected - q->subs[i].duration) + if (pts >= min_ts && pts > ts_selected - q->subs[i]->duration) idx = i; else break; @@ -291,7 +296,7 @@ int ff_subtitles_queue_seek(FFDemuxSubtitlesQueue *q, AVFormatContext *s, int st * queue is ordered by pts and then filepos, so we can take the first * entry for a given timestamp. */ if (stream_index == -1) - while (idx > 0 && q->subs[idx - 1].pts == q->subs[idx].pts) + while (idx > 0 && q->subs[idx - 1]->pts == q->subs[idx]->pts) idx--; q->current_sub_idx = idx; @@ -304,7 +309,7 @@ void ff_subtitles_queue_clean(FFDemuxSubtitlesQueue *q) int i; for (i = 0; i < q->nb_subs; i++) - av_packet_unref(&q->subs[i]); + av_packet_free(&q->subs[i]); av_freep(&q->subs); q->nb_subs = q->allocated_size = q->current_sub_idx = 0; } diff --git a/libavformat/subtitles.h b/libavformat/subtitles.h index 6b418e3621..ca769639be 100644 --- a/libavformat/subtitles.h +++ b/libavformat/subtitles.h @@ -100,7 +100,7 @@ int ff_text_peek_r8(FFTextReader *r); void ff_text_read(FFTextReader *r, char *buf, size_t size); typedef struct { - AVPacket *subs; ///< array of subtitles packets + AVPacket **subs; ///< array of subtitles packets int nb_subs; ///< number of subtitles packets int allocated_size; ///< allocated size for subs int current_sub_idx; ///< current position for the read packet callback diff --git a/libavformat/tedcaptionsdec.c b/libavformat/tedcaptionsdec.c index c15aeea06c..9a882c4d79 100644 --- a/libavformat/tedcaptionsdec.c +++ b/libavformat/tedcaptionsdec.c @@ -293,9 +293,9 @@ static av_cold int tedcaptions_read_header(AVFormatContext *avf) } ff_subtitles_queue_finalize(avf, &tc->subs); for (i = 0; i < tc->subs.nb_subs; i++) - tc->subs.subs[i].pts += tc->start_time; + tc->subs.subs[i]->pts += tc->start_time; - last = &tc->subs.subs[tc->subs.nb_subs - 1]; + last = tc->subs.subs[tc->subs.nb_subs - 1]; st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE; st->codecpar->codec_id = AV_CODEC_ID_TEXT; avpriv_set_pts_info(st, 64, 1, 1000); From patchwork Fri Mar 5 16:33:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26148 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 C868144AB0A for ; Fri, 5 Mar 2021 18:41:33 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C94A668ACE8; Fri, 5 Mar 2021 18:36:09 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qv1-f50.google.com (mail-qv1-f50.google.com [209.85.219.50]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 83D5668AB03 for ; Fri, 5 Mar 2021 18:36:05 +0200 (EET) Received: by mail-qv1-f50.google.com with SMTP id k7so1276675qvo.6 for ; Fri, 05 Mar 2021 08:36:05 -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=MEU+wl3LEtb0dczu8GC4lxh0Gv24GvulayOJmSZ16O0=; b=abPmkh/Fz/4uvhwCNV3DTTGlPjuLPg7rYXSNZ2UB/3IExSFlY249KtI6iqH8QcU663 ea7nIH0+N1lRt+gqB4w49pVewGrURiiI3/z/bdAC7sfq0nOyL0R9tuB1CI2gt08Q1Rsr ZEaVPAF0dzF9XzpCS7k9yJQHGzvgyLLyjn1p7LEZ8h+UmY9G6zRLKMpY+QdJew1+vLFm uyPKTwaQCgeYuD9VJkHEVlPTNgBeAN7Ki0f1olIWXidq0yPDKTNXxUrYDpS93rEygGhx I+QA0vCdhwX3IT9GcdiXsd+cn/W01vP/1zSDADLPP3IRYa8EYPdGZxbtkYvstD4GNylC 60yg== 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=MEU+wl3LEtb0dczu8GC4lxh0Gv24GvulayOJmSZ16O0=; b=bLYj+fmn4yXmk2D0eXQKCSMhzzcXRCtTtsBEq0hPygKZ+C8JJIOQH2cEANUOfI0wLI lYuD7w0GlkdfxDvWwH/8WKdzcx3ctwBpP9u3k3hq2Zf45spBmoIVAAVxSPtsbitFu6pr qanndyqU59/oBLUV4Q5rPz0mr0WyOAIDVCEmP3gh3DHnd9Ya/XwW94rNHFGvsJyNOxbf fa1JeUY3zp+xZyaXpqyVbMs8hgPqpzm0Y06oQtGD00lgyt1vUWgw73GKI+4NewSD3/au QxRmec6IKSDF/jtFRdGiGpnaxPm43hPxuruZPESBAiabuNHk2c50tQv7RGaG2pbmgLFU 9Qnw== X-Gm-Message-State: AOAM5339eGUPqb6X1pVCxCAeD/90HTIcyQddKDSl1XZISUQ/lr4dGfmU In8dROWklozsv628gfIxELj0GkLiOI2wuA== X-Google-Smtp-Source: ABdhPJzlNSLiQfJ9hm/PSI3puiQVb5NlBxACND9L/ajje2i9lCP6EdJIIMiObOnwmzjdb445QcuIFQ== X-Received: by 2002:a0c:a404:: with SMTP id w4mr9829551qvw.22.1614962163759; Fri, 05 Mar 2021 08:36:03 -0800 (PST) Received: from localhost.localdomain ([181.23.89.132]) by smtp.gmail.com with ESMTPSA id b10sm2168494qtt.23.2021.03.05.08.36.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 08:36:03 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Mar 2021 13:33:21 -0300 Message-Id: <20210305163339.63164-31-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 30/48] avformat/wc3movie: 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/wc3movie.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/libavformat/wc3movie.c b/libavformat/wc3movie.c index 76e945d261..cd69931a42 100644 --- a/libavformat/wc3movie.c +++ b/libavformat/wc3movie.c @@ -69,7 +69,7 @@ typedef struct Wc3DemuxContext { int video_stream_index; int audio_stream_index; - AVPacket vpkt; + AVPacket *vpkt; } Wc3DemuxContext; @@ -77,8 +77,7 @@ static int wc3_read_close(AVFormatContext *s) { Wc3DemuxContext *wc3 = s->priv_data; - if (wc3->vpkt.size > 0) - av_packet_unref(&wc3->vpkt); + av_packet_free(&wc3->vpkt); return 0; } @@ -110,8 +109,9 @@ static int wc3_read_header(AVFormatContext *s) wc3->height = WC3_DEFAULT_HEIGHT; wc3->pts = 0; wc3->video_stream_index = wc3->audio_stream_index = 0; - av_init_packet(&wc3->vpkt); - wc3->vpkt.data = NULL; wc3->vpkt.size = 0; + wc3->vpkt = av_packet_alloc(); + if (!wc3->vpkt) + return AVERROR(ENOMEM); /* skip the first 3 32-bit numbers */ avio_skip(pb, 12); @@ -162,7 +162,7 @@ static int wc3_read_header(AVFormatContext *s) case PALT_TAG: /* one of several palettes */ avio_seek(pb, -8, SEEK_CUR); - av_append_packet(pb, &wc3->vpkt, 8 + PALETTE_SIZE); + av_append_packet(pb, wc3->vpkt, 8 + PALETTE_SIZE); break; default: @@ -248,18 +248,17 @@ static int wc3_read_packet(AVFormatContext *s, case SHOT_TAG: /* load up new palette */ avio_seek(pb, -8, SEEK_CUR); - av_append_packet(pb, &wc3->vpkt, 8 + 4); + av_append_packet(pb, wc3->vpkt, 8 + 4); break; case VGA__TAG: /* send out video chunk */ avio_seek(pb, -8, SEEK_CUR); - ret= av_append_packet(pb, &wc3->vpkt, 8 + size); + ret= av_append_packet(pb, wc3->vpkt, 8 + size); // ignore error if we have some data - if (wc3->vpkt.size > 0) + if (wc3->vpkt->size > 0) ret = 0; - *pkt = wc3->vpkt; - wc3->vpkt.data = NULL; wc3->vpkt.size = 0; + av_packet_move_ref(pkt, wc3->vpkt); pkt->stream_index = wc3->video_stream_index; pkt->pts = wc3->pts; packet_read = 1; From patchwork Fri Mar 5 16:33:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26149 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 7B69744AB0A for ; Fri, 5 Mar 2021 18:41:46 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9D12268ACE3; Fri, 5 Mar 2021 18:36:10 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f182.google.com (mail-qk1-f182.google.com [209.85.222.182]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8EC3E68AC53 for ; Fri, 5 Mar 2021 18:36:06 +0200 (EET) Received: by mail-qk1-f182.google.com with SMTP id 130so2512748qkh.11 for ; Fri, 05 Mar 2021 08:36:06 -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=axp7pGQAVpTZGgynpXC5JJd1pLE1RACyv3abDFljkyQ=; b=ofZc/xmY+upCObsm5CVquv0l3aXxMF8D9XVISZ9y/jJyjdckwMHn5LsIVIryeH3QKV aeP+anbDBB1miNMOVbfOh9eVvR2BiVYGObr3VaYZtzFM3lO9ClQBTdsTfUdK2RkIe+Bi 5F78gxpHYxbo2ORkr1l/JJbj4CUvIM+Xdlj4YvKHwwNbAeJsU2eD4xcixlGjSFQyXzqY 4m2NvyBZrI+CWS+zoLW5SahMeiHSpNrXvn5Xj1fPUZ8sL56Uz5QC874+WivqTzY7KGgq d7tHtJulKSWvoWcYS11ABcS0yvtPtH2itC6RTj06TtPZQvmjuo3XISrZEoqvw3lSNOXr NZmg== 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=axp7pGQAVpTZGgynpXC5JJd1pLE1RACyv3abDFljkyQ=; b=fi2QAcg6HZms6qnB1g4nirNGKGMpWsD12NmXQWKlzSYyYtSMxqt39HCo2Yg26WsrX0 0FplafPA/cHoCNzVzsaqySn+1zWue2CY1CA4hhRtWeASuneEhLDtQ/5AR7JPYTA0cUFN D9VdYgpd8mRVxtPwXSo3b+ekWz4oRyAofbXl7GUh6ZmG+rmwIuWeGctM6nTMTbOwwdmG ZqRpm0uOZTXC5T2Q9HhFyqJNdoiG4zjib5aqK0B+yFeAj2yqAnY3+if8/ryWMWKxB8IN aGYuMPbhVky6DWY6KaL0tCzx4JzPNYsciJvdc44CUbMWa3owXQNkIeLXfjfDELk+HQT3 2Gug== X-Gm-Message-State: AOAM531rfo9oret6QlHbcyLYx9VgvAs/1gBkFsMppL75vdpc19GuTpts hFjNfeUl1OpX41Jpw7dF3HffInMF8bx3cA== X-Google-Smtp-Source: ABdhPJzq3gxX4nqk96Gfoymq72RQ3pipQpdtDauka4pxDa/wXMTQ6zUPWwSMulaeRKtU/SWH4A0ErQ== X-Received: by 2002:a37:4986:: with SMTP id w128mr9533241qka.313.1614962165054; Fri, 05 Mar 2021 08:36:05 -0800 (PST) Received: from localhost.localdomain ([181.23.89.132]) by smtp.gmail.com with ESMTPSA id b10sm2168494qtt.23.2021.03.05.08.36.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 08:36:04 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Mar 2021 13:33:22 -0300 Message-Id: <20210305163339.63164-32-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 31/48] avformat/tests/fifo_muxer: 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/fifo_muxer.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/libavformat/tests/fifo_muxer.c b/libavformat/tests/fifo_muxer.c index 5127a8aadb..3458c3eefd 100644 --- a/libavformat/tests/fifo_muxer.c +++ b/libavformat/tests/fifo_muxer.c @@ -81,9 +81,11 @@ static int fifo_basic_test(AVFormatContext *oc, AVDictionary **opts, const FailingMuxerPacketData *pkt_data) { int ret = 0, i; - AVPacket pkt; + AVPacket *pkt; - av_init_packet(&pkt); + pkt = av_packet_alloc(); + if (!pkt) + return AVERROR(ENOMEM); ret = avformat_write_header(oc, opts); @@ -94,20 +96,22 @@ static int fifo_basic_test(AVFormatContext *oc, AVDictionary **opts, } for (i = 0; i < 15; i++ ) { - ret = prepare_packet(&pkt, pkt_data, i); + ret = prepare_packet(pkt, pkt_data, i); if (ret < 0) { fprintf(stderr, "Failed to prepare test packet: %s\n", av_err2str(ret)); goto write_trailer_and_fail; } - ret = av_write_frame(oc, &pkt); - av_packet_unref(&pkt); + ret = av_write_frame(oc, pkt); + av_packet_unref(pkt); if (ret < 0) { fprintf(stderr, "Unexpected write_frame error: %s\n", av_err2str(ret)); + av_packet_free(&pkt); goto write_trailer_and_fail; } } + av_packet_free(&pkt); ret = av_write_frame(oc, NULL); if (ret < 0) { @@ -135,9 +139,11 @@ static int fifo_overflow_drop_test(AVFormatContext *oc, AVDictionary **opts, { int ret = 0, i; int64_t write_pkt_start, write_pkt_end, duration; - AVPacket pkt; + AVPacket *pkt; - av_init_packet(&pkt); + pkt = av_packet_alloc(); + if (!pkt) + return AVERROR(ENOMEM); ret = avformat_write_header(oc, opts); if (ret) { @@ -148,18 +154,20 @@ static int fifo_overflow_drop_test(AVFormatContext *oc, AVDictionary **opts, write_pkt_start = av_gettime_relative(); for (i = 0; i < 6; i++ ) { - ret = prepare_packet(&pkt, data, i); + ret = prepare_packet(pkt, data, i); if (ret < 0) { fprintf(stderr, "Failed to prepare test packet: %s\n", av_err2str(ret)); goto fail; } - ret = av_write_frame(oc, &pkt); - av_packet_unref(&pkt); + ret = av_write_frame(oc, pkt); + av_packet_unref(pkt); if (ret < 0) { break; } } + av_packet_free(&pkt); + write_pkt_end = av_gettime_relative(); duration = write_pkt_end - write_pkt_start; if (duration > (SLEEPTIME_50_MS*6)/2) { 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; } From patchwork Fri Mar 5 16:33:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26152 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 C870344B0AC for ; Fri, 5 Mar 2021 18:42:10 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 24D5C68ACDD; Fri, 5 Mar 2021 18:36:12 +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 0867E68ACDB for ; Fri, 5 Mar 2021 18:36:08 +0200 (EET) Received: by mail-qk1-f171.google.com with SMTP id x10so2531591qkm.8 for ; Fri, 05 Mar 2021 08:36:08 -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=u7+itW9odUSIg7tNx7olb7ETDZgAvz9Tsfqz+SpK4lI=; b=M7Q+UfqtPkzT7dt7pZFOjNIGMswCBicoO/SkRwrceHnCT1A9P//+e+RC1HCMC/bGEY B14CBEbXJOGHxZZcbOGzLJYC1Ul/lqZDDiXrqIq2HrHT0ES7ZQpERvAzG6nbDKCLMybM 14TTHkSk1hV4gaomGXL1VVOhz/VhK3l+CODmfSNBnTvW+a2EM3hJjJW1sakk3iJ/cfQv BFtbsbdPb1Ld6HVkgO+RhK0FYouiB3I4IRPl5ZQVO6w9I2nmFA0besz94KVh/aG90YUC C/UdEd3UXBguVyUPhs19lWr469SJexTTsxDOKP15NjjDYyw0keeZEejMRusLu+C5rLgK LJbg== 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=u7+itW9odUSIg7tNx7olb7ETDZgAvz9Tsfqz+SpK4lI=; b=UoSGrVim8iKvKUD4Gz8+jlXkcqUkWFaw3UxZG5eU9U8QiFnUImEnDrY+60wCUUcuPx BjJkSsE3b4Fs+EhCVjycH/rePfKHdIdrq1Igcy9+fQf4Gs55J59qGHIliVCPnn8G7MZy Rk0BeKCxuVzi6jE/DNUMnHKaEJjM4rANkp4+gW8OVPFwNkoaqmc1w/Cl/NjOE9GSdt2H aJ2WO3TZ/3UzhRGpUvw0cqQh45jxWf+Rc/5TTOnmL9ghSWVgg35lrrCayMae+jRQt1+8 tL4glA7iu0b4Gyx7Btlw/RZyllJ6jsQ4gmAbyVy7O5svYW3im6x+hjGbfNg2ZZmU72QN 7L8Q== X-Gm-Message-State: AOAM533XztgCLMzdX91qxoxA21b/y4e9ctW90yQpJ8qMDZboNyqD4b8g EHtymRH4u0KCQm7ytKyLOGjUt+qi5ii53g== X-Google-Smtp-Source: ABdhPJy+KdsOLJ0/jnS1I0ZTB5H7QRCop+zkPs6VdjqBK5Z0HUPdphTEGnqb8f53p6hswl0AHEqd+g== X-Received: by 2002:a05:620a:4549:: with SMTP id u9mr9474260qkp.113.1614962167627; Fri, 05 Mar 2021 08:36:07 -0800 (PST) Received: from localhost.localdomain ([181.23.89.132]) by smtp.gmail.com with ESMTPSA id b10sm2168494qtt.23.2021.03.05.08.36.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 08:36:07 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Mar 2021 13:33:24 -0300 Message-Id: <20210305163339.63164-34-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 33/48] avdevice/decklink_dec: stop using av_init_packet() 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 --- libavdevice/decklink_dec.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/libavdevice/decklink_dec.cpp b/libavdevice/decklink_dec.cpp index 5acb2e8fbb..c34a69b5de 100644 --- a/libavdevice/decklink_dec.cpp +++ b/libavdevice/decklink_dec.cpp @@ -674,8 +674,7 @@ static void handle_klv(AVFormatContext *avctx, decklink_ctx *ctx, IDeckLinkVideo klv.insert(klv.end(), packet.data.begin(), packet.data.end()); } - AVPacket klv_packet; - av_init_packet(&klv_packet); + AVPacket klv_packet = { 0 }; klv_packet.pts = pts; klv_packet.dts = pts; klv_packet.flags |= AV_PKT_FLAG_KEY; @@ -873,8 +872,7 @@ HRESULT decklink_input_callback::VideoInputFrameArrived( // Handle Video Frame if (videoFrame) { - AVPacket pkt; - av_init_packet(&pkt); + AVPacket pkt = { 0 }; if (ctx->frameCount % 25 == 0) { unsigned long long qsize = avpacket_queue_size(&ctx->queue); av_log(avctx, AV_LOG_DEBUG, @@ -976,7 +974,7 @@ HRESULT decklink_input_callback::VideoInputFrameArrived( if (!no_video) { IDeckLinkVideoFrameAncillary *vanc; - AVPacket txt_pkt; + AVPacket txt_pkt = { 0 }; uint8_t txt_buf0[3531]; // 35 * 46 bytes decoded teletext lines + 1 byte data_identifier + 1920 bytes OP47 decode buffer uint8_t *txt_buf = txt_buf0; @@ -1035,7 +1033,6 @@ HRESULT decklink_input_callback::VideoInputFrameArrived( txt_buf[1] = 0x2c; // data_unit_length txt_buf += 46; } - av_init_packet(&txt_pkt); txt_pkt.pts = pkt.pts; txt_pkt.dts = pkt.dts; txt_pkt.stream_index = ctx->teletext_st->index; @@ -1059,9 +1056,8 @@ HRESULT decklink_input_callback::VideoInputFrameArrived( // Handle Audio Frame if (audioFrame) { - AVPacket pkt; + AVPacket pkt = { 0 }; BMDTimeValue audio_pts; - av_init_packet(&pkt); //hack among hacks pkt.size = audioFrame->GetSampleFrameCount() * ctx->audio_st->codecpar->channels * (ctx->audio_depth / 8); From patchwork Fri Mar 5 16:33:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26153 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 DBB4B44B0AC for ; Fri, 5 Mar 2021 18:42:23 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2D51168AD01; Fri, 5 Mar 2021 18:36:13 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f176.google.com (mail-qk1-f176.google.com [209.85.222.176]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2F5FD68ACCB for ; Fri, 5 Mar 2021 18:36:10 +0200 (EET) Received: by mail-qk1-f176.google.com with SMTP id l4so2583036qkl.0 for ; Fri, 05 Mar 2021 08:36:10 -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=CLJLvGCcYb+NIOcyBN+8Y98Vz+iLKK0xLLjQSlgyLzo=; b=fkRUN9zMYzk6V3SfzBAl9DbwL0mLt6ixIpYjZKQb0BH849kNeOANiLciYIoTBIwFOR j0QNSfqF0nnToTyepO7/sNQ/YMizIwEljPpDxqEp17j9L8ckcIiuMRenn74m30whXPi4 haOARSm6sqe0Cz8sZBLziLtyguAKy8E8q37Ys5H17O25M3D6Yd4WyTKHLQqS2J7oNpez NxVYBFGrjI5fjr7rg09j6DH8gIh9r5AZvWHhDtB9HXPCtTEeOjhmTeKuo9JVAMGc/8A0 yw0SBWaDo9uFG379H+be26wnNf8RLJYV848EU3wWgEMkipU+CYVD+feb5+JVFpASUwNO i3RQ== 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=CLJLvGCcYb+NIOcyBN+8Y98Vz+iLKK0xLLjQSlgyLzo=; b=dNiRZMbgqov0j8tFW8S8MBW51rz8fnEZ92mQuZC5r+tpelSzbT5zBjA8oTPNZY3HrU L756JDetGitMePrOMTVO3sG+7h8QgUnYk9CDichEhuT+DUlNDDjI8HSCqj1Mg7c6BWMN vHsMDMwiwU6BbON1Kwlq9PLQ8xpip/DeX1Z4QmXzyiNw0ZdX6Jqzvd+zHcBMW/WQM7rs UKKcP4lWDUABoGlFB3E+kZ2606TA4H9z1DEprgJ0Q4rT9ctxaA3+V+TBC5D6eBQjMjbw VDFoC5dSWvZLAluOeZ4c0psklAVndWPMeRNvnlCJ5bWcIx2tg12zfNpEuhYDGVLetfm4 makw== X-Gm-Message-State: AOAM5333oKoRinnd6A51imlFHl42gMoN0tFAk9XPKNWpWO0XufWhF3yO rh+4XLlnrrcZl+MkdTX1pOSW7BdfFgrFhw== X-Google-Smtp-Source: ABdhPJxAgtuEXbimtyvXpkv7/OAZ7DNBXsdOFzTOOo2htqUvuvSov5rXJtGwZMq0phWpD6SRh9bVUA== X-Received: by 2002:a37:9fd2:: with SMTP id i201mr9429640qke.435.1614962168806; Fri, 05 Mar 2021 08:36:08 -0800 (PST) Received: from localhost.localdomain ([181.23.89.132]) by smtp.gmail.com with ESMTPSA id b10sm2168494qtt.23.2021.03.05.08.36.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 08:36:08 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Mar 2021 13:33:25 -0300 Message-Id: <20210305163339.63164-35-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 34/48] avdevice/xcbgrab: stop using av_init_packet() 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 --- libavdevice/xcbgrab.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/libavdevice/xcbgrab.c b/libavdevice/xcbgrab.c index 9604a5aaf2..b3c2170112 100644 --- a/libavdevice/xcbgrab.c +++ b/libavdevice/xcbgrab.c @@ -184,8 +184,6 @@ static int xcbgrab_frame(AVFormatContext *s, AVPacket *pkt) data = xcb_get_image_data(img); length = xcb_get_image_data_length(img); - av_init_packet(pkt); - pkt->buf = av_buffer_create(data, length, xcbgrab_image_reply_free, img, 0); if (!pkt->buf) { free(img); @@ -301,8 +299,6 @@ static int xcbgrab_frame_shm(AVFormatContext *s, AVPacket *pkt) free(img); - av_init_packet(pkt); - pkt->buf = buf; pkt->data = buf->data; pkt->size = c->frame_size; From patchwork Fri Mar 5 16:33:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26154 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 1CDE644B0AC for ; Fri, 5 Mar 2021 18:42:35 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D684168AD22; Fri, 5 Mar 2021 18:36:13 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f170.google.com (mail-qt1-f170.google.com [209.85.160.170]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 748E768ACE1 for ; Fri, 5 Mar 2021 18:36:11 +0200 (EET) Received: by mail-qt1-f170.google.com with SMTP id 18so2183547qty.3 for ; Fri, 05 Mar 2021 08:36:11 -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=texb2Ez2JbtwWMJpzIkYDr0TK2twJK1GsbXKWbfg4Zo=; b=gtTT18gBjiEXnM4z744jHoEUuefogXIlS47UKd6y2FRi7HlURNiRb0bCSwLW2Uy/ur sJUTqK1w/8DQNIlT/r4NevMWcubcxfnFPvBTCdmfzkVmYdzD3IlQYRHIe6Ntt1Dggs5p Z5gQ8S/TrCb00p92huInhNdtEE020CF+xSMKCwI7gVCVWRFDoLBj4QdA7PRzGnphwzeP w8x/jhXhYceju+nvC0JfHxrxeRF7J+uc87TqV3yDQY3lqHElYkgSB90/2MsF38tuqHZf FOjqJUwKfppRoxWOPwVmm+RQobfp1AFHzQ5h55Dvtmx4ruDDyxJ0+H9Zd3AFgn5ZnEOm TF/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=texb2Ez2JbtwWMJpzIkYDr0TK2twJK1GsbXKWbfg4Zo=; b=S6rQ+YC+soA7CWEagnf3wiTwizJrK0tdO09IegCups0ir2/iXjbQgZZ7VLt0cq8eaL TXxr+kLG1xkEb0ehXHmOmrQekCqBPKqyvIlFSQuX3x0cN8Qt5vU2/rcoTHeclQRHbsuF B/uE2kxCpAfBfLupIeyJXexvecvBuUnJKI8ORi3nMZG5EGDITLd9sxvC0GOCAbER0b4e UGbGYofLgKfAuDh3d+hQoIi0Ra9a5M54onGwdH+G0JLVPFahrxM43QWTthN4z8STwX3J uwLDfEbO0zQHvH/Zxc0+oUOso7fytR9NRyxP/Dutspeh23W7EQTwHQuRsn5taPI6BeuY PUAg== X-Gm-Message-State: AOAM532GVMf9ugxOZwbiVFIgKNHqB1oEqpFmPJAUEAvpP5rOK0tIv+jh cjmI60gCTRDNPpLbf2jf5hNou6NlxXRwhg== X-Google-Smtp-Source: ABdhPJwg4iwsL/ZOcL8Sl9bsMpqDOusCSvezJ3CFgRLxM5r0v7trb9cj4l8LzPjlOU3K1mZ0IaBGNg== X-Received: by 2002:ac8:4b4e:: with SMTP id e14mr9382886qts.25.1614962170000; Fri, 05 Mar 2021 08:36:10 -0800 (PST) Received: from localhost.localdomain ([181.23.89.132]) by smtp.gmail.com with ESMTPSA id b10sm2168494qtt.23.2021.03.05.08.36.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 08:36:09 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Mar 2021 13:33:26 -0300 Message-Id: <20210305163339.63164-36-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 35/48] avfilter/vf_mcdeint: 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 --- libavfilter/vf_mcdeint.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/libavfilter/vf_mcdeint.c b/libavfilter/vf_mcdeint.c index bc7b3230d3..1cad45cd4e 100644 --- a/libavfilter/vf_mcdeint.c +++ b/libavfilter/vf_mcdeint.c @@ -74,6 +74,7 @@ typedef struct MCDeintContext { int mode; ///< MCDeintMode int parity; ///< MCDeintParity int qp; + AVPacket *pkt; AVCodecContext *enc_ctx; } MCDeintContext; @@ -112,6 +113,9 @@ static int config_props(AVFilterLink *inlink) return AVERROR(EINVAL); } + mcdeint->pkt = av_packet_alloc(); + if (!mcdeint->pkt) + return AVERROR(ENOMEM); mcdeint->enc_ctx = avcodec_alloc_context3(enc); if (!mcdeint->enc_ctx) return AVERROR(ENOMEM); @@ -154,6 +158,7 @@ static av_cold void uninit(AVFilterContext *ctx) { MCDeintContext *mcdeint = ctx->priv; + av_packet_free(&mcdeint->pkt); avcodec_free_context(&mcdeint->enc_ctx); } @@ -173,7 +178,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *inpic) MCDeintContext *mcdeint = inlink->dst->priv; AVFilterLink *outlink = inlink->dst->outputs[0]; AVFrame *outpic, *frame_dec; - AVPacket pkt = {0}; + AVPacket *pkt = mcdeint->pkt; int x, y, i, ret, got_frame = 0; outpic = ff_get_video_buffer(outlink, outlink->w, outlink->h); @@ -184,9 +189,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *inpic) av_frame_copy_props(outpic, inpic); inpic->quality = mcdeint->qp * FF_QP2LAMBDA; - av_init_packet(&pkt); - - ret = avcodec_encode_video2(mcdeint->enc_ctx, &pkt, inpic, &got_frame); + ret = avcodec_encode_video2(mcdeint->enc_ctx, pkt, inpic, &got_frame); if (ret < 0) goto end; @@ -274,7 +277,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *inpic) mcdeint->parity ^= 1; end: - av_packet_unref(&pkt); + av_packet_unref(pkt); av_frame_free(&inpic); if (ret < 0) { av_frame_free(&outpic); From patchwork Fri Mar 5 16:33:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26155 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 871C744B0AC for ; Fri, 5 Mar 2021 18:42:45 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B3B7B68AD3D; Fri, 5 Mar 2021 18:36:14 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f179.google.com (mail-qk1-f179.google.com [209.85.222.179]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CF19D68ACFD for ; Fri, 5 Mar 2021 18:36:12 +0200 (EET) Received: by mail-qk1-f179.google.com with SMTP id 130so2513137qkh.11 for ; Fri, 05 Mar 2021 08:36:12 -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=qXddxSdxnbFRlIeVOtSeVAY15y3sWTU/p9PoqJmDTjA=; b=Jng6GYcIP2qUbF/HO+IyhnT1Ycdh//tPJV0lYbHW6Rqizcj0qot+b4iB42H2cAAbnp sQb29uRw9qMOsFViImYj2M02RBChjdstBHB+tEFZB5Ek/C2/Ew3Z8nTZjxsbi11aUAPt UuTRvFN7AiD2E7aH7+urDDLheZx3tSsVXvmL5O23rf2yVGgU0LuC85ntsBz8ApqWwGh5 KlW9CblFhAtzLhpFnyQGiF0YBxcJNQzSEiwklAYua5lf5zjkYDt8T4jSnjOYH7E44pzS UAD6ILT0UiRKo8W/EyuoiTjhtq4dLCx5ExVhdIG9i0rRlgOE7AIiHevL7qi2XiGFlaa1 aHHg== 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=qXddxSdxnbFRlIeVOtSeVAY15y3sWTU/p9PoqJmDTjA=; b=q5U3UvaEy1y33AL67N/J1rDoBvTTML6YeEejSlV8hOH7JlDbvYZt039J9aK137eaRb hJ+7ANFypjpABuhCj5oelv5FJ8clBRH4rpAow10gznwzZh3yE5kMKMcGvRnh0sLx9MVV ADUyaNrLuC0rIaRJuOzrh7shID7iYnzx0J9WyWHVh2jFU4drusRtBKI6lFOcJ8FQ3Ufv 90uIydLfXznCoAq6djobqiZjwYIu7ImiHpQwn8Af8eGafLIQSYuaWAdRv9kOO0Arj5CY 8a5opVtWmXQWtCrvclAyL7AGytSY4C/JeEJ71jwa5LVi6kTwEsVESa/gTYY/QSl21wHS kbvQ== X-Gm-Message-State: AOAM530Qt6DUmdrXDNSSUv2JmAKFCks26BrBB/DGst6N0fZii/JBWMIp NCFe+DZ13mfrmO8ZjM3u1cAE1beJd4I35g== X-Google-Smtp-Source: ABdhPJxr5jXBDGS9kuPGoVw6yeXoFZySBLX/PRV+NHfinB7WiFsADoqsTpKLZ2RdQXXgZej3rF1Hww== X-Received: by 2002:a37:a785:: with SMTP id q127mr9502126qke.425.1614962171276; Fri, 05 Mar 2021 08:36:11 -0800 (PST) Received: from localhost.localdomain ([181.23.89.132]) by smtp.gmail.com with ESMTPSA id b10sm2168494qtt.23.2021.03.05.08.36.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 08:36:10 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Mar 2021 13:33:27 -0300 Message-Id: <20210305163339.63164-37-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 36/48] avfilter/vf_uspp: 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 --- libavfilter/vf_uspp.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/libavfilter/vf_uspp.c b/libavfilter/vf_uspp.c index 8b39f53c3d..8c75207593 100644 --- a/libavfilter/vf_uspp.c +++ b/libavfilter/vf_uspp.c @@ -51,6 +51,7 @@ typedef struct USPPContext { int outbuf_size; uint8_t *outbuf; AVCodecContext *avctx_enc[BLOCK*BLOCK]; + AVPacket *pkt; AVFrame *frame; AVFrame *frame_dec; int8_t *non_b_qp_table; @@ -240,19 +241,19 @@ static void filter(USPPContext *p, uint8_t *dst[3], uint8_t *src[3], const int y1c = y1 >> p->vsub; const int BLOCKc = BLOCK >> p->hsub; int offset; - AVPacket pkt = {0}; + AVPacket *pkt = p->pkt; int got_pkt_ptr; - av_init_packet(&pkt); - pkt.data = p->outbuf; - pkt.size = p->outbuf_size; + av_packet_unref(pkt); + pkt->data = p->outbuf; + pkt->size = p->outbuf_size; p->frame->data[0] = p->src[0] + x1 + y1 * p->frame->linesize[0]; p->frame->data[1] = p->src[1] + x1c + y1c * p->frame->linesize[1]; p->frame->data[2] = p->src[2] + x1c + y1c * p->frame->linesize[2]; p->frame->format = p->avctx_enc[i]->pix_fmt; - ret = avcodec_encode_video2(p->avctx_enc[i], &pkt, p->frame, &got_pkt_ptr); + ret = avcodec_encode_video2(p->avctx_enc[i], pkt, p->frame, &got_pkt_ptr); if (ret < 0) { av_log(p->avctx_enc[i], AV_LOG_ERROR, "Encoding failed\n"); continue; @@ -373,6 +374,8 @@ static int config_input(AVFilterLink *inlink) uspp->outbuf_size = (width + BLOCK) * (height + BLOCK) * 10; if (!(uspp->frame = av_frame_alloc())) return AVERROR(ENOMEM); + if (!(uspp->pkt = av_packet_alloc())) + return AVERROR(ENOMEM); if (!(uspp->outbuf = av_malloc(uspp->outbuf_size))) return AVERROR(ENOMEM); @@ -465,6 +468,7 @@ static av_cold void uninit(AVFilterContext *ctx) av_freep(&uspp->non_b_qp_table); av_freep(&uspp->outbuf); + av_packet_free(&uspp->pkt); av_frame_free(&uspp->frame); } From patchwork Fri Mar 5 16:33:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26132 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 9090044B231 for ; Fri, 5 Mar 2021 18:36:16 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 79A6168AD38; Fri, 5 Mar 2021 18:36:16 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qv1-f47.google.com (mail-qv1-f47.google.com [209.85.219.47]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1E99568AD0C for ; Fri, 5 Mar 2021 18:36:13 +0200 (EET) Received: by mail-qv1-f47.google.com with SMTP id d9so1284684qvo.3 for ; Fri, 05 Mar 2021 08:36:13 -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=A+6Ny9qMJ+a/uihoaFOosWik5LJodU2HDoIkHII95l8=; b=XDh0WS5CH3XGIMKi2pTJlpc+l1+TxfBLc5hCPvNWJgBK+EA5H7ElnJEKHWuacxCDpt YfI4Mw5FWggCHAu9NLtL71ynSDP3Vlgk/X06+rkkBgKJBpDqU1LhOBf64RNeurUiJTdZ VHVxnTLb69Q//rzBWy7ay2L7QVEr8RPlWpoumb9d1Num2NZUT4k9ngnmbOIwyMG69Qpz Zi9ym0VC8dIiMy8RaNWwYDv/0OWL2zUq93E9S23uRglQj8gUdAvgJ+nxPZvCZUfRdq7+ /lwZLcVpu0X0P0Cnt+ief8lv21Nup6uIExWjX+iH1UNpKwziqB1tWLoB46/ELj4F5dxF c//A== 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=A+6Ny9qMJ+a/uihoaFOosWik5LJodU2HDoIkHII95l8=; b=PrB4aLJ/+J7HUc0rKR9yLQ8atjnKEkFp3IAqrT3LJTFWOtDAgz5v8MPYiYMh1JBMnB cDJIYdXgbunQK7WEu3sgo3uBoPqPpSD3NHh4ckiqmT92f9VasU5WreV2MGPy+EKbXkjR o4T6WRioqsSOk+Wp0HUsRovTmliAoQrpogDk+rFIZbWRCWMmxSohBskci+fFMJXMYPnV aHNGgG5xoOEySawh9Y2gwAlPYmRk7uLO/BmlbcQ6zqZhL1/Tdn/5DfunK/N4I0Fb4kem W14PWR8cy89ftyMuURZDFR9InR9fKTQxLCoIOGHhrRFUdb8xutdT2JY62lGoFvBCzebF BdsA== X-Gm-Message-State: AOAM530OzBZ5echZmPsvVCEXeC2y88vMPzHHG25q5X5F7Uplj6M/+cxw KeG9bSbUbZtTSH1KV3TKeANgejZXrM2nKQ== X-Google-Smtp-Source: ABdhPJyWT3g4p6vb6upwxfwu2ui7rNUEg3vXzIakvIc7r0fhGcp5bYKglWrSa0Id9fu9fBefwHs4jw== X-Received: by 2002:a0c:e38f:: with SMTP id a15mr9924362qvl.18.1614962172489; Fri, 05 Mar 2021 08:36:12 -0800 (PST) Received: from localhost.localdomain ([181.23.89.132]) by smtp.gmail.com with ESMTPSA id b10sm2168494qtt.23.2021.03.05.08.36.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 08:36:12 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Mar 2021 13:33:28 -0300 Message-Id: <20210305163339.63164-38-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 37/48] tools/pktdumper: 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 --- tools/pktdumper.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/tools/pktdumper.c b/tools/pktdumper.c index 16a965b756..c51f5c8922 100644 --- a/tools/pktdumper.c +++ b/tools/pktdumper.c @@ -54,7 +54,7 @@ int main(int argc, char **argv) char fntemplate[FILENAME_BUF_SIZE]; char pktfilename[FILENAME_BUF_SIZE]; AVFormatContext *fctx = NULL; - AVPacket pkt; + AVPacket *pkt; int64_t pktnum = 0; int64_t maxpkts = 0; int donotquit = 0; @@ -101,30 +101,35 @@ int main(int argc, char **argv) return 1; } - av_init_packet(&pkt); + pkt = av_packet_alloc(); + if (!pkt) { + fprintf(stderr, "av_packet_alloc: error %d\n", AVERROR(ENOMEM)); + return 1; + } - while ((err = av_read_frame(fctx, &pkt)) >= 0) { + while ((err = av_read_frame(fctx, pkt)) >= 0) { int fd; snprintf(pktfilename, sizeof(pktfilename), fntemplate, pktnum, - pkt.stream_index, pkt.pts, pkt.size, - (pkt.flags & AV_PKT_FLAG_KEY) ? 'K' : '_'); - printf(PKTFILESUFF "\n", pktnum, pkt.stream_index, pkt.pts, pkt.size, - (pkt.flags & AV_PKT_FLAG_KEY) ? 'K' : '_'); + pkt->stream_index, pkt->pts, pkt->size, + (pkt->flags & AV_PKT_FLAG_KEY) ? 'K' : '_'); + printf(PKTFILESUFF "\n", pktnum, pkt->stream_index, pkt->pts, pkt->size, + (pkt->flags & AV_PKT_FLAG_KEY) ? 'K' : '_'); if (!nowrite) { fd = open(pktfilename, O_WRONLY | O_CREAT, 0644); - err = write(fd, pkt.data, pkt.size); + err = write(fd, pkt->data, pkt->size); if (err < 0) { fprintf(stderr, "write: error %d\n", err); return 1; } close(fd); } - av_packet_unref(&pkt); + av_packet_unref(pkt); pktnum++; if (maxpkts && (pktnum >= maxpkts)) break; } + av_packet_free(&pkt); avformat_close_input(&fctx); while (donotquit) From patchwork Fri Mar 5 16:33:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26133 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 4C04844B231 for ; Fri, 5 Mar 2021 18:36:19 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3485C68AD75; Fri, 5 Mar 2021 18:36:19 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qv1-f48.google.com (mail-qv1-f48.google.com [209.85.219.48]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 68C6568AD2A for ; Fri, 5 Mar 2021 18:36:15 +0200 (EET) Received: by mail-qv1-f48.google.com with SMTP id dj14so1286475qvb.1 for ; Fri, 05 Mar 2021 08:36:15 -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=haAbmU6ieNsSmqHBoBX3U9VfDwEwVCLnYuaFFp/LE7k=; b=BCGtrsj+oSHQ2V5Fw0meQy7bxjbPx6bQ6OB4IqSehNvB3nnOq5i68NCM+Fyk0og7cF +Px+d140wRqeVDIcbILjyKhUEODnmE9phTXsE0PZkWY5omh1bawlVwO2+wiDk9jfaWzS z2pYhxdOuJ+0rGyWtyLufS4r4T+bloKWXkWo8Gb0Nuixb3cKWchpexcWDpTvmxdBJmlU cH8Xe/uCDdHgmJXNbqBW1uAl5sARI7Qky6+XhqCCApwEm9Jj1w2pTi8R+uBdVItCeBaA pMykHWJ4n3+ZPV6VIkd8FaFB7cIwtic3pksKePmC9QPWfxYn2bCOdEDHXLgM+JxcyyJm aRrA== 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=haAbmU6ieNsSmqHBoBX3U9VfDwEwVCLnYuaFFp/LE7k=; b=nANc37yHFBhsjoCziFz1Ab8c1Gff50RrzTLY8rPY9pMZorMVh4vpbZPa51ysVG6PZ0 ZPnSDHMK7iJTK1P+zZXfQ7uJEclT3aS1Ur8nponEg1cr5phLORHuf8GpMFqG6jj4Z1WW U6WEq0X7zwAHx9CmKk4bZ8de48ZsuvRShm6VTs8lYSajdmggisKF2kIiGFzjGYdPVU8h WUw8seOzO5VUMbrjytGNGaudPKNcMuLUHTf58pDjhlUxXOmRL8EypBkaulmBLKlT8pJU 3fNM5gOw+dSu7qfghKLZZggAttdQK1ktJ7sWSWXUv/FQLoxuHNVI3Jv0ZiP8jvYXp1MG VwIg== X-Gm-Message-State: AOAM533CssR/Snc6crCCh40CIrH9/C7p1H/HqekBq0Vp4uWT9tHTEiWu CNmGU9F3Q031TzxQb7mOkXdT7y8+CIEuSA== X-Google-Smtp-Source: ABdhPJzMw9dmF5eZM5czyzS9aYNbE2C3w1DrwNxXlNIOq8vRSTi0WQaZpUVfJzjoLj68l9IP2qjlwg== X-Received: by 2002:ad4:4ab0:: with SMTP id i16mr9497579qvx.1.1614962173825; Fri, 05 Mar 2021 08:36:13 -0800 (PST) Received: from localhost.localdomain ([181.23.89.132]) by smtp.gmail.com with ESMTPSA id b10sm2168494qtt.23.2021.03.05.08.36.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 08:36:13 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Mar 2021 13:33:29 -0300 Message-Id: <20210305163339.63164-39-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 38/48] tools/target_dec_fuzzer: 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 --- tools/target_dec_fuzzer.c | 73 +++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 37 deletions(-) diff --git a/tools/target_dec_fuzzer.c b/tools/target_dec_fuzzer.c index c484dd3e95..bac54d5aaa 100644 --- a/tools/target_dec_fuzzer.c +++ b/tools/target_dec_fuzzer.c @@ -294,13 +294,12 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { int got_frame; AVFrame *frame = av_frame_alloc(); - if (!frame) + AVPacket *avpkt = av_packet_alloc(); + AVPacket *parsepkt = av_packet_alloc(); + if (!frame || !avpkt || !parsepkt) error("Failed memory allocation"); // Read very simple container - AVPacket avpkt, parsepkt; - av_init_packet(&avpkt); - av_init_packet(&parsepkt); while (data < end && it < maxiteration) { // Search for the TAG while (data + sizeof(fuzz_tag) < end) { @@ -311,43 +310,42 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { if (data + sizeof(fuzz_tag) > end) data = end; - res = av_new_packet(&parsepkt, data - last); + res = av_new_packet(parsepkt, data - last); if (res < 0) error("Failed memory allocation"); - memcpy(parsepkt.data, last, data - last); - parsepkt.flags = (keyframes & 1) * AV_PKT_FLAG_DISCARD + (!!(keyframes & 2)) * AV_PKT_FLAG_KEY; + memcpy(parsepkt->data, last, data - last); + parsepkt->flags = (keyframes & 1) * AV_PKT_FLAG_DISCARD + (!!(keyframes & 2)) * AV_PKT_FLAG_KEY; keyframes = (keyframes >> 2) + (keyframes<<62); data += sizeof(fuzz_tag); last = data; - while (parsepkt.size > 0) { + while (parsepkt->size > 0) { int decode_more; if (parser) { - av_init_packet(&avpkt); - int ret = av_parser_parse2(parser, parser_avctx, &avpkt.data, &avpkt.size, - parsepkt.data, parsepkt.size, - parsepkt.pts, parsepkt.dts, parsepkt.pos); - if (avpkt.data == parsepkt.data) { - avpkt.buf = av_buffer_ref(parsepkt.buf); - if (!avpkt.buf) + int ret = av_parser_parse2(parser, parser_avctx, &avpkt->data, &avpkt->size, + parsepkt->data, parsepkt->size, + parsepkt->pts, parsepkt->dts, parsepkt->pos); + if (avpkt->data == parsepkt->data) { + avpkt->buf = av_buffer_ref(parsepkt->buf); + if (!avpkt->buf) error("Failed memory allocation"); } else { - if (av_packet_make_refcounted(&avpkt) < 0) + if (av_packet_make_refcounted(avpkt) < 0) error("Failed memory allocation"); } - parsepkt.data += ret; - parsepkt.size -= ret; - parsepkt.pos += ret; - avpkt.pts = parser->pts; - avpkt.dts = parser->dts; - avpkt.pos = parser->pos; + parsepkt->data += ret; + parsepkt->size -= ret; + parsepkt->pos += ret; + avpkt->pts = parser->pts; + avpkt->dts = parser->dts; + avpkt->pos = parser->pos; if ( parser->key_frame == 1 || (parser->key_frame == -1 && parser->pict_type == AV_PICTURE_TYPE_I)) - avpkt.flags |= AV_PKT_FLAG_KEY; - avpkt.flags |= parsepkt.flags & AV_PKT_FLAG_DISCARD; + avpkt->flags |= AV_PKT_FLAG_KEY; + avpkt->flags |= parsepkt->flags & AV_PKT_FLAG_DISCARD; } else { - av_packet_move_ref(&avpkt, &parsepkt); + av_packet_move_ref(avpkt, parsepkt); } if (!(flushpattern & 7)) @@ -355,7 +353,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { flushpattern = (flushpattern >> 3) + (flushpattern << 61); if (ctx->codec_type != AVMEDIA_TYPE_SUBTITLE) { - int ret = avcodec_send_packet(ctx, &avpkt); + int ret = avcodec_send_packet(ctx, avpkt); decode_more = ret >= 0; if(!decode_more) { ec_pixels += (ctx->width + 32LL) * (ctx->height + 32LL); @@ -370,7 +368,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { // Iterate through all data while (decode_more && it++ < maxiteration) { av_frame_unref(frame); - int ret = decode_handler(ctx, frame, &got_frame, &avpkt); + int ret = decode_handler(ctx, frame, &got_frame, avpkt); ec_pixels += (ctx->width + 32LL) * (ctx->height + 32LL); if (it > 20 || ec_pixels > 4 * ctx->max_pixels) @@ -380,30 +378,30 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { if (ctx->codec_type == AVMEDIA_TYPE_AUDIO && frame->nb_samples == 0 && !got_frame && - (avpkt.flags & AV_PKT_FLAG_DISCARD)) + (avpkt->flags & AV_PKT_FLAG_DISCARD)) nb_samples += ctx->max_samples; nb_samples += frame->nb_samples; if (nb_samples > maxsamples) goto maximums_reached; - if (ret <= 0 || ret > avpkt.size) + if (ret <= 0 || ret > avpkt->size) break; if (ctx->codec_type == AVMEDIA_TYPE_SUBTITLE) { - avpkt.data += ret; - avpkt.size -= ret; - decode_more = avpkt.size > 0; + avpkt->data += ret; + avpkt->size -= ret; + decode_more = avpkt->size > 0; } else decode_more = ret >= 0; } - av_packet_unref(&avpkt); + av_packet_unref(avpkt); } - av_packet_unref(&parsepkt); + av_packet_unref(parsepkt); } maximums_reached: - av_packet_unref(&avpkt); + av_packet_unref(avpkt); if (ctx->codec_type != AVMEDIA_TYPE_SUBTITLE) avcodec_send_packet(ctx, NULL); @@ -411,7 +409,7 @@ maximums_reached: do { got_frame = 0; av_frame_unref(frame); - decode_handler(ctx, frame, &got_frame, &avpkt); + decode_handler(ctx, frame, &got_frame, avpkt); } while (got_frame == 1 && it++ < maxiteration); fprintf(stderr, "pixels decoded: %"PRId64", samples decoded: %"PRId64", iterations: %d\n", ec_pixels, nb_samples, it); @@ -420,7 +418,8 @@ maximums_reached: avcodec_free_context(&ctx); avcodec_free_context(&parser_avctx); av_parser_close(parser); - av_packet_unref(&parsepkt); + av_packet_free(&avpkt); + av_packet_free(&parsepkt); av_dict_free(&opts); return 0; } From patchwork Fri Mar 5 16:33:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26156 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 4506144B46F for ; Fri, 5 Mar 2021 18:43:16 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 12DBD68AD63; Fri, 5 Mar 2021 18:36:20 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qv1-f44.google.com (mail-qv1-f44.google.com [209.85.219.44]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2F55B68AD50 for ; Fri, 5 Mar 2021 18:36:16 +0200 (EET) Received: by mail-qv1-f44.google.com with SMTP id h7so1287583qvm.2 for ; Fri, 05 Mar 2021 08:36:16 -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=krsKrQAPf4f1WsuySgy88zhxvLaj94N8TERqAjngTuw=; b=Zt8AnHwiSzrtHB+paEv7P9bHbU0fdTsiMtp9vZ12mnCyveP9ViPVM6GDKPbjM5e4+v q91iDQ5Xgaqckoc0KCgGQv1ucsXNdVV3LrjBKkoSFgzVNLa6o60NY33dH8UYeRxmhqxD 6SGZxCqNqezQbMsHGQYdrvPi3ZqH/a8WzLifaVGMMl8CHfZ+ROstAAGW7+6DLt+x/wt+ +NsjrHvYxG9xFNKCKWnqKUeNuKSJYs9PAQtImYy847DY3oRRn3U5oXUevYYOFvWKmZMP ASkTllJ+IrIsX2p9PH98hnzL6v+T/sS/jaN/hjvr5mMQ1Wbx5mGbqIrmyvYpzR/nrxNI zCDg== 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=krsKrQAPf4f1WsuySgy88zhxvLaj94N8TERqAjngTuw=; b=Y1nLaKWTz3CQIAGOKM4IEMc1CnB7Tu+FnvaXtaa9f1l6bh2G0kpakkDoH97hRPsXvN Ga3aPyy1St2t50en4zDsGd/1B+EZrOF3Wzonzw0Fk1idcaEBI7yAACO8Nde/DYnl/hU5 J7MtKx+gHceo2NTrjgSRYi93U7LdDT+pekgpsv76dJMG1rWfnKv/h1CkzrYroEtvYbg6 HAudzVjbwah4NStb5bQjyaMzlgksmlv3Q94gtrNG3UXNrJTG0VJXaLL3UR/oe3/BO+1i 4GNA9Wp9fl/ffyZBFjFG0PJvBf9nRYxOaDvM1hifExmMJTd5uzah+tsdh/OaYZMVmz73 7sVQ== X-Gm-Message-State: AOAM531GrZagKGLf5vM99fRy7hWtwMrugeK/+vjmslAfvFvx0ehpKPen 29zOSY5sGEFAK92kNNmeuJvAgIIgotRdBw== X-Google-Smtp-Source: ABdhPJyoIHWAl7IfE1JkGT78tqFSPTASD+JLrn3Jz3Q9ULUkSnc4R7XJsFIVfrC4HI96uLVUQhXJPw== X-Received: by 2002:a0c:c193:: with SMTP id n19mr9540949qvh.3.1614962174970; Fri, 05 Mar 2021 08:36:14 -0800 (PST) Received: from localhost.localdomain ([181.23.89.132]) by smtp.gmail.com with ESMTPSA id b10sm2168494qtt.23.2021.03.05.08.36.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 08:36:14 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Mar 2021 13:33:30 -0300 Message-Id: <20210305163339.63164-40-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 39/48] tools/target_dem_fuzzer: 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 --- tools/target_dem_fuzzer.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tools/target_dem_fuzzer.c b/tools/target_dem_fuzzer.c index 8ff98af945..af1840b359 100644 --- a/tools/target_dem_fuzzer.c +++ b/tools/target_dem_fuzzer.c @@ -96,7 +96,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { const uint64_t fuzz_tag = FUZZ_TAG; uint32_t it = 0; AVFormatContext *avfmt = avformat_alloc_context(); - AVPacket pkt; + AVPacket *pkt; char filename[1025] = {0}; AVIOContext *fuzzed_pb = NULL; uint8_t *io_buffer; @@ -165,6 +165,10 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { if (!io_buffer_size || size / io_buffer_size > maxblocks) io_buffer_size = size; + pkt = av_packet_alloc(); + if (!pkt) + error("Failed to allocate pkt"); + io_buffer = av_malloc(io_buffer_size); if (!io_buffer) error("Failed to allocate io_buffer"); @@ -190,17 +194,16 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { ret = avformat_find_stream_info(avfmt, NULL); - av_init_packet(&pkt); - //TODO, test seeking for(it = 0; it < maxiteration; it++) { - ret = av_read_frame(avfmt, &pkt); + ret = av_read_frame(avfmt, pkt); if (ret < 0) break; - av_packet_unref(&pkt); + av_packet_unref(pkt); } + av_packet_free(&pkt); av_freep(&fuzzed_pb->buffer); avio_context_free(&fuzzed_pb); avformat_close_input(&avfmt); From patchwork Fri Mar 5 16:33:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26134 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 E1D8644B231 for ; Fri, 5 Mar 2021 18:36:20 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C6AFC68AD91; Fri, 5 Mar 2021 18:36:20 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qv1-f47.google.com (mail-qv1-f47.google.com [209.85.219.47]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A5CC268AA1F for ; Fri, 5 Mar 2021 18:36:17 +0200 (EET) Received: by mail-qv1-f47.google.com with SMTP id s17so1259350qvr.12 for ; Fri, 05 Mar 2021 08:36:17 -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=6w4h0sKU3VSDiUQOxVUlr4LDk4pIgqnStBAEvs8qkCs=; b=HXFeSQ9Aw1JtRPVKf1ZJS2MeYVdhizdR+cvEGejA65TRuuY3GefAsDnhQFSR9AbTKf 86pZJk72cZGmP2kZZnMWRXRyHKV/gkHj4kjT30GO7hrXGSkaXuji0TOhWB6GftN1slCQ xZC0oovcP9uAkhn/6x9fIcjMsqkuWQFnbXgNn06KbKb+muDgKjzM1Rs6L0fQv9du5GoC n16bLjNrKXuL0MtaewUUVOnxfl+DhioaSZVXjQ5shOAmvPqu3bZLLkwULiyTkLm1BTKZ jedy5FFPxnGuDJMUUxYszW2LXraaNyv2wMxUe6XIvikefIMZIva+mzPlcZXAtUmIokhf lF1A== 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=6w4h0sKU3VSDiUQOxVUlr4LDk4pIgqnStBAEvs8qkCs=; b=bIa7u+DxSuQUf3FJIagkYwI3R+QjStUnKNB5A+Q/tavTf2fdFCdc3MNgeSV1p+0Ql3 anqOwidIbxGtjjBfJP/QDOsHT0ZHNATleGrqEKhScHVPOhDVn2rW21BpvQRddMEO5brC hSAEg2P0eKZkrBssLUieQkrPtKvjrwjcpsMU3t9bOn+ugERxciK026qAI18tJuVjysg0 ZXe9doyMpeAGluRNU5TAzZviXZyGbtBZttS7r7j1MWEygcLjMnG1+WnOAyESU6xDKekJ DEA4ElFOQV1pLunj8dS1RqwTkwOb7jMfFL80++WWUQbE2MrIzV0DampWmkIBcu6ajjIM U5RQ== X-Gm-Message-State: AOAM5327zqiO5l88THLs4We8DExrZJwTu2gUlGpCiO+4QB5CsxpsVxjx y0wlTdubiabQPyDQ87/LLNVf/3968s0mQw== X-Google-Smtp-Source: ABdhPJxGDBmwsh4L2n7FGg4VMrHHl4IsV/h9gFr80idatU4I6e9u7100Oclr1AAYTdANVXeQkEijew== X-Received: by 2002:a0c:c3cd:: with SMTP id p13mr2220529qvi.4.1614962176287; Fri, 05 Mar 2021 08:36:16 -0800 (PST) Received: from localhost.localdomain ([181.23.89.132]) by smtp.gmail.com with ESMTPSA id b10sm2168494qtt.23.2021.03.05.08.36.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 08:36:15 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Mar 2021 13:33:31 -0300 Message-Id: <20210305163339.63164-41-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 40/48] tools/target_bsf_fuzzer: 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 --- tools/target_bsf_fuzzer.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/tools/target_bsf_fuzzer.c b/tools/target_bsf_fuzzer.c index 8781a93ac3..bab809162a 100644 --- a/tools/target_bsf_fuzzer.c +++ b/tools/target_bsf_fuzzer.c @@ -42,7 +42,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { const uint8_t *last = data; const uint8_t *end = data + size; AVBSFContext *bsf = NULL; - AVPacket in, out; + AVPacket *in, *out; uint64_t keyframes = 0; uint64_t flushpattern = -1; int res; @@ -119,10 +119,11 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { return 0; // Failure of av_bsf_init() does not imply that a issue was found } - av_init_packet(&in); - av_init_packet(&out); - out.data = NULL; - out.size = 0; + in = av_packet_alloc(); + out = av_packet_alloc(); + if (!in || !out) + error("Failed memory allocation"); + while (data < end) { // Search for the TAG while (data + sizeof(fuzz_tag) < end) { @@ -133,11 +134,11 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { if (data + sizeof(fuzz_tag) > end) data = end; - res = av_new_packet(&in, data - last); + res = av_new_packet(in, data - last); if (res < 0) error("Failed memory allocation"); - memcpy(in.data, last, data - last); - in.flags = (keyframes & 1) * AV_PKT_FLAG_DISCARD + (!!(keyframes & 2)) * AV_PKT_FLAG_KEY; + memcpy(in->data, last, data - last); + in->flags = (keyframes & 1) * AV_PKT_FLAG_DISCARD + (!!(keyframes & 2)) * AV_PKT_FLAG_KEY; keyframes = (keyframes >> 2) + (keyframes<<62); data += sizeof(fuzz_tag); last = data; @@ -146,26 +147,28 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { av_bsf_flush(bsf); flushpattern = (flushpattern >> 3) + (flushpattern << 61); - while (in.size) { - res = av_bsf_send_packet(bsf, &in); + while (in->size) { + res = av_bsf_send_packet(bsf, in); if (res < 0 && res != AVERROR(EAGAIN)) break; - res = av_bsf_receive_packet(bsf, &out); + res = av_bsf_receive_packet(bsf, out); if (res < 0) break; - av_packet_unref(&out); + av_packet_unref(out); } - av_packet_unref(&in); + av_packet_unref(in); } res = av_bsf_send_packet(bsf, NULL); while (!res) { - res = av_bsf_receive_packet(bsf, &out); + res = av_bsf_receive_packet(bsf, out); if (res < 0) break; - av_packet_unref(&out); + av_packet_unref(out); } + av_packet_free(&in); + av_packet_free(&out); av_bsf_free(&bsf); return 0; } From patchwork Fri Mar 5 16:33:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26157 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 D7F9F44B46F for ; Fri, 5 Mar 2021 18:43:37 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A633368AD83; Fri, 5 Mar 2021 18:36:21 +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 E246E68AD65 for ; Fri, 5 Mar 2021 18:36:18 +0200 (EET) Received: by mail-qt1-f181.google.com with SMTP id b3so2141801qtj.10 for ; Fri, 05 Mar 2021 08:36:18 -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=Rb7b0ojh0yLYaEyk9SeoeGO16M8ha4DCfuB50WnfIy8=; b=YWNf23EUcmQbbTRMDvIHSwATGsV1TXCha9gx1U4+RXxXMxWXeoNstMxyz9Tp3g9b5I GhkkjXMPXKJGTBhLAw76Rx/rljZex2cciIfKgtjpTi8cKorH/dSnZfZ7+UIwpU1x1Aqj gTmniMOyTdOZCxyNB36yagKdzBLE0Kiu0LKdX7XJPDWH5GiwCcVptrk3gz0mEfU+SAzw 7eYmMFKJjnnVQRobeW2WGxMT6agBdYTrS6ang8LFSqsSPcJeeGaHwyiF3QFGWxWCAkjf C18yWkFwT/1rRUz2Zm8c2nfZZUiAwxa6IoKQd5nlMajWeMw/renz+8Uf1rA5yqWDQ1v6 bUhA== 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=Rb7b0ojh0yLYaEyk9SeoeGO16M8ha4DCfuB50WnfIy8=; b=lSDgNTYeYJjwet3wDA5IMwwuET4/cpeEbigPLQEXqK0iQ1UNsKpk9jgkXMsDx/KNNJ KSZSYAb6Ahfc2CeClB9b+1YDOWyDmbhKZYiYrOB779JVovVh5zmdvgKn+8feT/GZvi0g PI8rTxX3R8bFO4mP1MznTxVJ8KxPRxlEEHvgLjU6TF0+nsuoKfUbQWNa5Xxw+xQahw3G KO4+DOv0Tok5uX5Ql2wDbv/HH83kB7wZjsFDvSnr7LPYy+Pvw7hhpZx+Miaeov8+v3KS r2yT8wdU4u7vfjnXwa7kMpsTzZlIzmgrak6v9s9VbUDROtKXcHyNQL/QPHWzxvUbCH67 /IQQ== X-Gm-Message-State: AOAM532VURkKibWsH9V9zL29lNMTSapjuzE6gm55FLI4o1rg4+Nb2Aqx JzGu5/qWuoqKUkiqv/WAQB7lyaa1pG2BIw== X-Google-Smtp-Source: ABdhPJxWaoeKvTrqc6BD0gSN0pYt/kngTZiRgYQEQlagUeNNOpwTgeZY+G79IS3cNl/2isaqUsJ95Q== X-Received: by 2002:ac8:7656:: with SMTP id i22mr9898057qtr.39.1614962177446; Fri, 05 Mar 2021 08:36:17 -0800 (PST) Received: from localhost.localdomain ([181.23.89.132]) by smtp.gmail.com with ESMTPSA id b10sm2168494qtt.23.2021.03.05.08.36.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 08:36:17 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Mar 2021 13:33:32 -0300 Message-Id: <20210305163339.63164-42-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 41/48] 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 --- This patch conflicts with one by Anton, so i'll adapt it after he pushes his. 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; 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]); From patchwork Fri Mar 5 16:33:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26159 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 69C0F44B46F for ; Fri, 5 Mar 2021 18:43:56 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 228A668ADAD; Fri, 5 Mar 2021 18:36:23 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f170.google.com (mail-qt1-f170.google.com [209.85.160.170]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7285468A980 for ; Fri, 5 Mar 2021 18:36:21 +0200 (EET) Received: by mail-qt1-f170.google.com with SMTP id b3so2141914qtj.10 for ; Fri, 05 Mar 2021 08:36:21 -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=WrEjY+9grZCXdZ7DsUv7LGck09dyNGg9POm8j2ImSmk=; b=ibTeSIUKMA1Kh65JNYG1lDEriHquf/izg8SOARQfei2PjxZ+zg7ktMgV/Ae2IWeC6o 28/5Zdo1fjniQX7TsZLPCJt3mfrmsg8RLjSm++5Se8DSdNzadjU1GXSB3kz7OAeelVrX JZ7fVrxB2RVqsUiS6LSGd3c5kWZVvld8fFm20yAsPjD2ZiAnrSeKdP7I2r7F56sgNTKn KF3G5iwoHi2jjj+1KDWssVW/vWJBu41Eo8xM6z2HK+c9mBVSPlgKHCgGL2NFL0GwknSz 1HqsZsjyi8+Wf5O/J45spEsGArLJg3DXFTkWsR7ZqT9b6tnn4YTqMt8V8tl1Wnl22aP6 VLsQ== 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=WrEjY+9grZCXdZ7DsUv7LGck09dyNGg9POm8j2ImSmk=; b=sb3g/hv3FLIhhnartYis9YGtUNZxnTsPXeRlaVrKYgKdykHNYkXaMACiv/REaVG4/g rpcYO73TDJltAgiJm5ag2LHQkGtEDuMRHtgTax8Y1jPethglRrxmxvQGjmrWZbcR1YSH 49El8c6uNOe84IMGZ9Jg9AQ2C0ptIYkk4B3/OVcdtO9suV7/ubnyOnVCvBKzN6z2O7J4 95XCHdZ0eQ3eYKirXGxmmKf4WPDK0MacJPc4jV6ie1rndzVV4+mRAWzk+yDeOhR7FwfK xJT40T94DWXq1jxSlpsJG+GdeVLn+3+jkdgDxWeQBBilmcEIq3400ZuzjQMcCnj+mVgl dDaA== X-Gm-Message-State: AOAM532jqw9DtxXEzlaq2QA6UMKCu54CTR4ydJebBiwnvMw/ZC1c00bD XBe10g7AKVM5O+7gdBK/KnAR6TpIhSluAQ== X-Google-Smtp-Source: ABdhPJwnP7KNOTRoYcTMIlwbi2Gm8V6VLXsAHFg5Jyvgi5r4ZHAbqlPyf12BSIA9xXe3wGCuffkOCw== X-Received: by 2002:ac8:5ec8:: with SMTP id s8mr9515001qtx.256.1614962179835; Fri, 05 Mar 2021 08:36:19 -0800 (PST) Received: from localhost.localdomain ([181.23.89.132]) by smtp.gmail.com with ESMTPSA id b10sm2168494qtt.23.2021.03.05.08.36.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 08:36:19 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Mar 2021 13:33:34 -0300 Message-Id: <20210305163339.63164-44-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 43/48] doc/examples/transcode_aac: 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/transcode_aac.c | 46 +++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/doc/examples/transcode_aac.c b/doc/examples/transcode_aac.c index e0c76f5b35..73786ab59b 100644 --- a/doc/examples/transcode_aac.c +++ b/doc/examples/transcode_aac.c @@ -245,14 +245,16 @@ cleanup: /** * Initialize one data packet for reading or writing. - * @param packet Packet to be initialized + * @param[out] packet Packet to be initialized + * @return Error code (0 if successful) */ -static void init_packet(AVPacket *packet) +static int init_packet(AVPacket **packet) { - av_init_packet(packet); - /* Set the packet data and size so that it is recognized as being empty. */ - packet->data = NULL; - packet->size = 0; + if (!(*packet = av_packet_alloc())) { + fprintf(stderr, "Could not allocate packet\n"); + return AVERROR(ENOMEM); + } + return 0; } /** @@ -371,28 +373,31 @@ static int decode_audio_frame(AVFrame *frame, int *data_present, int *finished) { /* Packet used for temporary storage. */ - AVPacket input_packet; + AVPacket *input_packet; int error; - init_packet(&input_packet); + + error = init_packet(&input_packet); + if (error < 0) + return error; /* Read one audio frame from the input file into a temporary packet. */ - if ((error = av_read_frame(input_format_context, &input_packet)) < 0) { + if ((error = av_read_frame(input_format_context, input_packet)) < 0) { /* If we are at the end of the file, flush the decoder below. */ if (error == AVERROR_EOF) *finished = 1; else { fprintf(stderr, "Could not read frame (error '%s')\n", av_err2str(error)); - return error; + goto cleanup; } } /* Send the audio frame stored in the temporary packet to the decoder. * The input audio stream decoder is used to do this. */ - if ((error = avcodec_send_packet(input_codec_context, &input_packet)) < 0) { + if ((error = avcodec_send_packet(input_codec_context, input_packet)) < 0) { fprintf(stderr, "Could not send packet for decoding (error '%s')\n", av_err2str(error)); - return error; + goto cleanup; } /* Receive one frame from the decoder. */ @@ -418,7 +423,7 @@ static int decode_audio_frame(AVFrame *frame, } cleanup: - av_packet_unref(&input_packet); + av_packet_free(&input_packet); return error; } @@ -661,9 +666,12 @@ static int encode_audio_frame(AVFrame *frame, int *data_present) { /* Packet used for temporary storage. */ - AVPacket output_packet; + AVPacket *output_packet; int error; - init_packet(&output_packet); + + error = init_packet(&output_packet); + if (error < 0) + return error; /* Set a timestamp based on the sample rate for the container. */ if (frame) { @@ -681,11 +689,11 @@ static int encode_audio_frame(AVFrame *frame, } else if (error < 0) { fprintf(stderr, "Could not send packet for encoding (error '%s')\n", av_err2str(error)); - return error; + goto cleanup; } /* Receive one encoded frame from the encoder. */ - error = avcodec_receive_packet(output_codec_context, &output_packet); + error = avcodec_receive_packet(output_codec_context, output_packet); /* If the encoder asks for more data to be able to provide an * encoded frame, return indicating that no data is present. */ if (error == AVERROR(EAGAIN)) { @@ -706,14 +714,14 @@ static int encode_audio_frame(AVFrame *frame, /* Write one audio frame from the temporary packet to the output file. */ if (*data_present && - (error = av_write_frame(output_format_context, &output_packet)) < 0) { + (error = av_write_frame(output_format_context, output_packet)) < 0) { fprintf(stderr, "Could not write frame (error '%s')\n", av_err2str(error)); goto cleanup; } cleanup: - av_packet_unref(&output_packet); + av_packet_free(&output_packet); return error; } From patchwork Fri Mar 5 16:33:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26160 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 6F22344B46F for ; Fri, 5 Mar 2021 18:44:05 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EE66068ADC4; Fri, 5 Mar 2021 18:36:23 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f172.google.com (mail-qt1-f172.google.com [209.85.160.172]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9D2C968AD99 for ; Fri, 5 Mar 2021 18:36:22 +0200 (EET) Received: by mail-qt1-f172.google.com with SMTP id s15so2199154qtq.0 for ; Fri, 05 Mar 2021 08:36:22 -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=PWXcMBcnjH1eBerazz4Qn2OzyRATjdjV/kIncyX19Lk=; b=vb9WNmZCVuNIbKTTNTzmsnlgi2MiwKeFgSwAHxFbi65o2JybnlLdfS0d76zg/UZpbc tA9eVxdeVqGf1KxqVbQBezjIv0ZB8mC/CiD61Gyl/765fGvgYVnt/SQkryccyhb5o+lZ 3+jB+Ud+SgDPySkv6GNaHswbMEMNsTbnO1rE9qn7POPGN9j3bhREzoB4adEhPaPiDQrA do5jkYYWrV0lRHNpOS/TBGGolDibbsZVpI5tXZ5BgsyHOjWva1SnKyacqxpCtXyFHdon jIfjAaaiRkEkJLKCC69+GoKqF8WdH8Pt3YK5evh0o75+J2OvRmN+ToMxMh6j7fozu6q9 P90Q== 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=PWXcMBcnjH1eBerazz4Qn2OzyRATjdjV/kIncyX19Lk=; b=FcFEhvwxRdOI1jpyhVwg5Tuv/wlG98uo814R7zCbgx9z6xqcFUj4GVbsvCquE/r3fe eEjcfsV5T4ScrcV5CxhTDB3OTviNdv/D24lnNmXqu0mk1oX02lDzmlAZ7QTsd0LPP32Z HMgULJfdRNHy/4jEoBzvwVqpW5cCLJ2b7bHHc40xAVrnpD742y8f87MBEAGmyv7AgmgO vH24Ua3jqL/jhtQz3E3CyPEaatSmDLEehMEZbh+yt6r6ox+SxC3glmE1px8Ih8UC6gBA 8HRY9bateWAa9MDs1JRG5XskjvUa5IqrERbo1a6XzNkLeLbQdZI/W8Z5pKuGcWORgQTM 48rw== X-Gm-Message-State: AOAM530eTjTuUCJowVhyEpiEyldur59znPaU98W2X2K7v364bByBNtow K3jLDsmJTX7AATfeOswyBjhC7+neyK4CzQ== X-Google-Smtp-Source: ABdhPJzTRVaXQn84VWjt/6P/5MC47B92RVqiIsuPMsEgqsWsFNq/uN1uS19GRobJ6pm30J6+BO2x2w== X-Received: by 2002:a05:622a:552:: with SMTP id m18mr9797885qtx.207.1614962181137; Fri, 05 Mar 2021 08:36:21 -0800 (PST) Received: from localhost.localdomain ([181.23.89.132]) by smtp.gmail.com with ESMTPSA id b10sm2168494qtt.23.2021.03.05.08.36.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 08:36:20 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Mar 2021 13:33:35 -0300 Message-Id: <20210305163339.63164-45-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 44/48] doc/examples/transcoding: 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/transcoding.c | 48 ++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/doc/examples/transcoding.c b/doc/examples/transcoding.c index 5aff08c135..6ca3089330 100644 --- a/doc/examples/transcoding.c +++ b/doc/examples/transcoding.c @@ -42,6 +42,7 @@ typedef struct FilteringContext { AVFilterContext *buffersrc_ctx; AVFilterGraph *filter_graph; + AVPacket *enc_pkt; AVFrame *filtered_frame; } FilteringContext; static FilteringContext *filter_ctx; @@ -407,6 +408,10 @@ static int init_filters(void) if (ret) return ret; + filter_ctx[i].enc_pkt = av_packet_alloc(); + if (!filter_ctx[i].enc_pkt) + return AVERROR(ENOMEM); + filter_ctx[i].filtered_frame = av_frame_alloc(); if (!filter_ctx[i].filtered_frame) return AVERROR(ENOMEM); @@ -414,17 +419,17 @@ static int init_filters(void) return 0; } -static int encode_write_frame(AVFrame *filt_frame, unsigned int stream_index) +static int encode_write_frame(unsigned int stream_index, int flush) { StreamContext *stream = &stream_ctx[stream_index]; + FilteringContext *filter = &filter_ctx[stream_index]; + AVFrame *filt_frame = flush ? NULL : filter->filtered_frame; + AVPacket *enc_pkt = filter->enc_pkt; int ret; - AVPacket enc_pkt; av_log(NULL, AV_LOG_INFO, "Encoding frame\n"); /* encode filtered frame */ - enc_pkt.data = NULL; - enc_pkt.size = 0; - av_init_packet(&enc_pkt); + av_packet_unref(enc_pkt); ret = avcodec_send_frame(stream->enc_ctx, filt_frame); @@ -432,20 +437,20 @@ static int encode_write_frame(AVFrame *filt_frame, unsigned int stream_index) return ret; while (ret >= 0) { - ret = avcodec_receive_packet(stream->enc_ctx, &enc_pkt); + ret = avcodec_receive_packet(stream->enc_ctx, enc_pkt); if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) return 0; /* prepare packet for muxing */ - enc_pkt.stream_index = stream_index; - av_packet_rescale_ts(&enc_pkt, + enc_pkt->stream_index = stream_index; + av_packet_rescale_ts(enc_pkt, stream->enc_ctx->time_base, ofmt_ctx->streams[stream_index]->time_base); av_log(NULL, AV_LOG_DEBUG, "Muxing frame\n"); /* mux encoded frame */ - ret = av_interleaved_write_frame(ofmt_ctx, &enc_pkt); + ret = av_interleaved_write_frame(ofmt_ctx, enc_pkt); } return ret; @@ -481,7 +486,7 @@ static int filter_encode_write_frame(AVFrame *frame, unsigned int stream_index) } filter->filtered_frame->pict_type = AV_PICTURE_TYPE_NONE; - ret = encode_write_frame(filter->filtered_frame, stream_index); + ret = encode_write_frame(stream_index, 0); av_frame_unref(filter->filtered_frame); if (ret < 0) break; @@ -497,13 +502,13 @@ static int flush_encoder(unsigned int stream_index) return 0; av_log(NULL, AV_LOG_INFO, "Flushing stream #%u encoder\n", stream_index); - return encode_write_frame(NULL, stream_index); + return encode_write_frame(stream_index, 1); } int main(int argc, char **argv) { int ret; - AVPacket packet = { .data = NULL, .size = 0 }; + AVPacket *packet = NULL; unsigned int stream_index; unsigned int i; @@ -518,12 +523,14 @@ int main(int argc, char **argv) goto end; if ((ret = init_filters()) < 0) goto end; + if (!(packet = av_packet_alloc())) + goto end; /* read all packets */ while (1) { - if ((ret = av_read_frame(ifmt_ctx, &packet)) < 0) + if ((ret = av_read_frame(ifmt_ctx, packet)) < 0) break; - stream_index = packet.stream_index; + stream_index = packet->stream_index; av_log(NULL, AV_LOG_DEBUG, "Demuxer gave frame of stream_index %u\n", stream_index); @@ -532,10 +539,10 @@ int main(int argc, char **argv) av_log(NULL, AV_LOG_DEBUG, "Going to reencode&filter the frame\n"); - av_packet_rescale_ts(&packet, + av_packet_rescale_ts(packet, ifmt_ctx->streams[stream_index]->time_base, stream->dec_ctx->time_base); - ret = avcodec_send_packet(stream->dec_ctx, &packet); + ret = avcodec_send_packet(stream->dec_ctx, packet); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Decoding failed\n"); break; @@ -555,15 +562,15 @@ int main(int argc, char **argv) } } else { /* remux this frame without reencoding */ - av_packet_rescale_ts(&packet, + av_packet_rescale_ts(packet, ifmt_ctx->streams[stream_index]->time_base, ofmt_ctx->streams[stream_index]->time_base); - ret = av_interleaved_write_frame(ofmt_ctx, &packet); + ret = av_interleaved_write_frame(ofmt_ctx, packet); if (ret < 0) goto end; } - av_packet_unref(&packet); + av_packet_unref(packet); } /* flush filters and encoders */ @@ -587,13 +594,14 @@ int main(int argc, char **argv) av_write_trailer(ofmt_ctx); end: - av_packet_unref(&packet); + av_packet_free(&packet); for (i = 0; i < ifmt_ctx->nb_streams; i++) { avcodec_free_context(&stream_ctx[i].dec_ctx); if (ofmt_ctx && ofmt_ctx->nb_streams > i && ofmt_ctx->streams[i] && stream_ctx[i].enc_ctx) avcodec_free_context(&stream_ctx[i].enc_ctx); if (filter_ctx && filter_ctx[i].filter_graph) { avfilter_graph_free(&filter_ctx[i].filter_graph); + av_packet_free(&filter_ctx[i].enc_pkt); av_frame_free(&filter_ctx[i].filtered_frame); } From patchwork Fri Mar 5 16:33:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26135 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 6931B44B9E2 for ; Fri, 5 Mar 2021 18:36:26 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4C53968ADCA; Fri, 5 Mar 2021 18:36:26 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f176.google.com (mail-qt1-f176.google.com [209.85.160.176]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9234D68A97D for ; Fri, 5 Mar 2021 18:36:23 +0200 (EET) Received: by mail-qt1-f176.google.com with SMTP id w6so2165153qti.6 for ; Fri, 05 Mar 2021 08:36:23 -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=MtNfqMSZbJYP/g46VhePhtMkzgSA4e66CD9f+reupX8=; b=VIE19q/FpNN5IBBeEFJHuhsVEH18DIgGol3SsP12Y3sntCT57ZWQ692xXktSPumRVz v9dFJTNnpADU5rxOc74V4CvKoorZ052eKNYa0hKDbzBnPVF3T6qdonE422D/O7MDM3NK +6AFyOKC0pwKW8Qq1Tkc20GoJDlmi7FlVqgwgR25NtydtE5SeySQLp/2ywtutMYdNpE7 7FdpYTx5w+sVkXwQcG/EycGlZt4jfWBClohNb23vKSz7aAbyj+uuyrW/jSep5ASTB+E+ 9GjYhUAxefONRm3j3ksKpE1FVLnJDwB5jaaKH0QZ62ShPcv8ugO0eeDHbJR5/YRhE6MA yCDA== 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=MtNfqMSZbJYP/g46VhePhtMkzgSA4e66CD9f+reupX8=; b=BuPi/Ril2SMK9wjzJ0pXEycovyZZ4Ql1tDwbLNFz5j8mzpymy9OzVU//1L9UDtivMw A8/vbvnAKGf7c5onGqhbbFfUey46lo8hquHZ1oyIywSU3EI9xWQn1SDbvMm2HpG9qW3j rcUcedrtzBr7MiXESZKYA3OboMfDl+1MHBqIsPpTMjSyLCXK+WQh+z5lMvBhxV/BHfTE BlkGeI0kZYYBhBx4ebVtQSfW5E/HYd3AmCFklwfh0gFUqOEFJY2CL1bfTEZWdLo9kiiY 6KbbaunllhTQH9IZlYoZomC6wkmZPGeXAnhaZMOlWuQamsNX+3R47+QCMNFly9ChPHd2 3J4w== X-Gm-Message-State: AOAM530JbYKKRFPJmg3ooWhPTEvqHz7tRRdfNZ6Jc62gUXnZpCNkTEvb Q2QUuIqsTwSFo1Fk5GYK03Ic/2kyQAya0w== X-Google-Smtp-Source: ABdhPJw79XM5LGt5RH7WGnfgduIG9ujIsBFM58M6rf416eMrMH6VL9OzDM9vLGt8jiDnzLhH8i3MMw== X-Received: by 2002:aed:2b61:: with SMTP id p88mr2391154qtd.360.1614962182332; Fri, 05 Mar 2021 08:36:22 -0800 (PST) Received: from localhost.localdomain ([181.23.89.132]) by smtp.gmail.com with ESMTPSA id b10sm2168494qtt.23.2021.03.05.08.36.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 08:36:21 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Mar 2021 13:33:36 -0300 Message-Id: <20210305163339.63164-46-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 45/48] doc/examples/vaapi_encode: 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/vaapi_encode.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/doc/examples/vaapi_encode.c b/doc/examples/vaapi_encode.c index 707939db37..66cb949cdc 100644 --- a/doc/examples/vaapi_encode.c +++ b/doc/examples/vaapi_encode.c @@ -74,27 +74,27 @@ static int set_hwframe_ctx(AVCodecContext *ctx, AVBufferRef *hw_device_ctx) static int encode_write(AVCodecContext *avctx, AVFrame *frame, FILE *fout) { int ret = 0; - AVPacket enc_pkt; + AVPacket *enc_pkt; - av_init_packet(&enc_pkt); - enc_pkt.data = NULL; - enc_pkt.size = 0; + if (!(enc_pkt = av_packet_alloc())) + return AVERROR(ENOMEM); if ((ret = avcodec_send_frame(avctx, frame)) < 0) { fprintf(stderr, "Error code: %s\n", av_err2str(ret)); goto end; } while (1) { - ret = avcodec_receive_packet(avctx, &enc_pkt); + ret = avcodec_receive_packet(avctx, enc_pkt); if (ret) break; - enc_pkt.stream_index = 0; - ret = fwrite(enc_pkt.data, enc_pkt.size, 1, fout); - av_packet_unref(&enc_pkt); + enc_pkt->stream_index = 0; + ret = fwrite(enc_pkt.data, enc_pkt->size, 1, fout); + av_packet_unref(enc_pkt); } end: + av_packet_free(&enc_pkt); ret = ((ret == AVERROR(EAGAIN)) ? 0 : -1); return ret; } From patchwork Fri Mar 5 16:33:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26161 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 43CE544B5D3 for ; Fri, 5 Mar 2021 18:44:25 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2B4CD68ADE6; Fri, 5 Mar 2021 18:36:27 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f173.google.com (mail-qk1-f173.google.com [209.85.222.173]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3A52D68ADC9 for ; Fri, 5 Mar 2021 18:36:25 +0200 (EET) Received: by mail-qk1-f173.google.com with SMTP id 130so2513839qkh.11 for ; Fri, 05 Mar 2021 08:36:25 -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=OmcnHaW2wQSlkjoL/UX7DFv4MG1+wDQgXhAKEPIg0Kw=; b=l7HlYtD6C4kO1Vy6Eh+3SfK0Q6E4Xo/mpkdtlRVGZlJIFJEO8yPt9HKYB4snjnkIU6 6I85FyySaiYm2Zt0RpiybNZx/odiIWdW+8KM1uZWKZl6s2GSchh55J8CVA8hAkpMpGv5 69qmOeUTsLIAgq9OwDhBrEidtj5iHt+Qzya69HDq9RFQwpyeznF8ppnf5T0oDEXSTg7J UwIqvd3UDdVKQlWiX3UcWHn7NZd/6sgt11bGBpSj2ayWsRRV93qxyrTGpPUGvW+n6aem 45KaJnzpkoteHQgy5It6HwMx5WORWvqQrSBqso2e5v1ftUCtSqjn1bUBKHClsWwWcPk9 tJXg== 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=OmcnHaW2wQSlkjoL/UX7DFv4MG1+wDQgXhAKEPIg0Kw=; b=jPlXujCPFSH7NVcrqcZtkz1T/AhuUAZWEKPpncqrjs09/1VYv1NDCMeFmUcEFxbn40 TCBEbwGEB1a8ne99eTZJ7PTWSW01bZpy+YhMm6YqtHi8JZgwo9A8jieJiueczp/KczoS pFKSPCtA3kDzuMZlMLT+hcppS24MDVtwEWgqa070aoAiMrytb+64O2+/+Bf5oFvzbOJA HkhEx+KNByGPKZe+pWm9xdKJ0MWq6Yhe/ceq+NBsn4SHdf8ITobPOhptQGyApwmKeEan 4llZT3neQvHHVPhv0z10Ib6w/+/HPQsd7OMD2P02M51Rccrxd7PULd60aoM9+HBlGBgw nm3A== X-Gm-Message-State: AOAM530RfN+cOlAN/F7ISQlXsqbZQcfYVr4JK1YzZqVQeRIfAVxLgkDd I43EJpvxL5rp5T/1j86JStuRJt0r5E4E0A== X-Google-Smtp-Source: ABdhPJwbaquOZ4sxIiczsfikaee31yARDVD9tsoDvWc6cPBE2Xc62+zIOcNduGgpJS9YV6UaSrTmFQ== X-Received: by 2002:a05:620a:630:: with SMTP id 16mr10580203qkv.304.1614962183595; Fri, 05 Mar 2021 08:36:23 -0800 (PST) Received: from localhost.localdomain ([181.23.89.132]) by smtp.gmail.com with ESMTPSA id b10sm2168494qtt.23.2021.03.05.08.36.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 08:36:23 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Mar 2021 13:33:37 -0300 Message-Id: <20210305163339.63164-47-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 46/48] doc/examples/vaapi_transcode: 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/vaapi_transcode.c | 42 ++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/doc/examples/vaapi_transcode.c b/doc/examples/vaapi_transcode.c index 279d20f636..5a1a704a8e 100644 --- a/doc/examples/vaapi_transcode.c +++ b/doc/examples/vaapi_transcode.c @@ -109,28 +109,25 @@ static int open_input_file(const char *filename) return ret; } -static int encode_write(AVFrame *frame) +static int encode_write(AVPacket *enc_pkt, AVFrame *frame) { int ret = 0; - AVPacket enc_pkt; - av_init_packet(&enc_pkt); - enc_pkt.data = NULL; - enc_pkt.size = 0; + av_packet_unref(enc_pkt); if ((ret = avcodec_send_frame(encoder_ctx, frame)) < 0) { fprintf(stderr, "Error during encoding. Error code: %s\n", av_err2str(ret)); goto end; } while (1) { - ret = avcodec_receive_packet(encoder_ctx, &enc_pkt); + ret = avcodec_receive_packet(encoder_ctx, enc_pkt); if (ret) break; - enc_pkt.stream_index = 0; - av_packet_rescale_ts(&enc_pkt, ifmt_ctx->streams[video_stream]->time_base, + enc_pkt->stream_index = 0; + av_packet_rescale_ts(enc_pkt, ifmt_ctx->streams[video_stream]->time_base, ofmt_ctx->streams[0]->time_base); - ret = av_interleaved_write_frame(ofmt_ctx, &enc_pkt); + ret = av_interleaved_write_frame(ofmt_ctx, enc_pkt); if (ret < 0) { fprintf(stderr, "Error during writing data to output file. " "Error code: %s\n", av_err2str(ret)); @@ -216,7 +213,7 @@ static int dec_enc(AVPacket *pkt, AVCodec *enc_codec) initialized = 1; } - if ((ret = encode_write(frame)) < 0) + if ((ret = encode_write(pkt, frame)) < 0) fprintf(stderr, "Error during encoding and writing.\n"); fail: @@ -230,7 +227,7 @@ fail: int main(int argc, char **argv) { int ret = 0; - AVPacket dec_pkt; + AVPacket *dec_pkt; AVCodec *enc_codec; if (argc != 4) { @@ -246,6 +243,12 @@ int main(int argc, char **argv) return -1; } + dec_pkt = av_packet_alloc(); + if (!dec_pkt) { + fprintf(stderr, "Failed to allocate decode packet\n"); + goto end; + } + if ((ret = open_input_file(argv[1])) < 0) goto end; @@ -275,23 +278,21 @@ int main(int argc, char **argv) /* read all packets and only transcoding video */ while (ret >= 0) { - if ((ret = av_read_frame(ifmt_ctx, &dec_pkt)) < 0) + if ((ret = av_read_frame(ifmt_ctx, dec_pkt)) < 0) break; - if (video_stream == dec_pkt.stream_index) - ret = dec_enc(&dec_pkt, enc_codec); + if (video_stream == dec_pkt->stream_index) + ret = dec_enc(dec_pkt, enc_codec); - av_packet_unref(&dec_pkt); + av_packet_unref(dec_pkt); } /* flush decoder */ - dec_pkt.data = NULL; - dec_pkt.size = 0; - ret = dec_enc(&dec_pkt, enc_codec); - av_packet_unref(&dec_pkt); + av_packet_unref(dec_pkt); + ret = dec_enc(dec_pkt, enc_codec); /* flush encoder */ - ret = encode_write(NULL); + ret = encode_write(dec_pkt, NULL); /* write the trailer for output stream */ av_write_trailer(ofmt_ctx); @@ -302,5 +303,6 @@ end: avcodec_free_context(&decoder_ctx); avcodec_free_context(&encoder_ctx); av_buffer_unref(&hw_device_ctx); + av_packet_free(&dec_pkt); return ret; } From patchwork Fri Mar 5 16:33:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26162 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 A2F6C44B5D3 for ; Fri, 5 Mar 2021 18:44:35 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2519868ADE5; Fri, 5 Mar 2021 18:36:28 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f177.google.com (mail-qk1-f177.google.com [209.85.222.177]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5D53D68ADE5 for ; Fri, 5 Mar 2021 18:36:26 +0200 (EET) Received: by mail-qk1-f177.google.com with SMTP id x10so2532676qkm.8 for ; Fri, 05 Mar 2021 08:36:26 -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=jLppxZy/VWuSJR9EkDo8WhHaz8+M2gJSdBRU6QkpH0s=; b=eWN5Nzk1y2TZlyULn/7yEG6vE0WhzXbOGdsKURvvJLYaD3Z9uREHDeUWn+5uA8iUTi Gomd/91xqHCVPrSPGaKXiYk7w+uD0Y1UiI23zDPngs6t+GrkUFBTEf0X1eEd4upVy5jl dAbc+3nzVo2sTCb37Tw4969zYPjr1LKqi/zBS3sf5OgQna32cLLDbMYkRjtgkgFHv1Ip CGTkQbUm10KdJmh8JZaHPP1w6XsJRUL8lDuOD3wtWDW3aeos6Vj9J33rJkycRuNzFNSH Z8xRGP0z2/obIUnznCn25r8Z0kKPCNM/nuaQjH7/S3CGJ7T3xAC6sOCn3w5p843W+V1O aRYw== 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=jLppxZy/VWuSJR9EkDo8WhHaz8+M2gJSdBRU6QkpH0s=; b=iGCIUxkTNEVg6MzGLBVLGz+zTvXcMjGw3q5MWNfQaXrD4CG9RGNlAItfj7ygal/Dz1 NInYPykD93eF3w33YNB6BaXBRKRI2ecIPQXZqZ+DlYTSrG6cH0rh3zNR6+vceopXFew5 qlTAF0Le6Ybk3Q8n5ZUYNFUW1pg5ppEgmOp4f/oculiJwIDpacfXx+MS/PvKf+ibhms/ JdnM3wrsuhK2wJwkL9TUviHU13wm4vRUoTowtnjigoh8R14fq80LK40Pk3RTZzzvcDg9 g96b5agLrEu9Q98Iw+W4NUmRvXn7EOK62/ijHIDqgVi1RJEMiiTWWzy1eWnxM8o5lZsQ mlRQ== X-Gm-Message-State: AOAM533nsrCdtT3cePTgnyBjKj9h0Ma93OYFkCAxPrNZHa1RO1iFLinx VALDoO21sMnUmd3ce1TiQfgyE8tKZc7lLQ== X-Google-Smtp-Source: ABdhPJx8v0ccNvdjX2J5Fbow7iaa8V76qtA89/RuiTjPCppkU46mT0u7fOeVOK0owFMEaACKWFBfPA== X-Received: by 2002:a37:4690:: with SMTP id t138mr9947891qka.394.1614962184823; Fri, 05 Mar 2021 08:36:24 -0800 (PST) Received: from localhost.localdomain ([181.23.89.132]) by smtp.gmail.com with ESMTPSA id b10sm2168494qtt.23.2021.03.05.08.36.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 08:36:24 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Mar 2021 13:33:38 -0300 Message-Id: <20210305163339.63164-48-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 47/48] fftools/ffprobe: 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 --- fftools/ffprobe.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c index 740e759958..a6735f70c6 100644 --- a/fftools/ffprobe.c +++ b/fftools/ffprobe.c @@ -2463,14 +2463,12 @@ static int read_interval_packets(WriterContext *w, InputFile *ifile, const ReadInterval *interval, int64_t *cur_ts) { AVFormatContext *fmt_ctx = ifile->fmt_ctx; - AVPacket pkt; + AVPacket *pkt = NULL; AVFrame *frame = NULL; int ret = 0, i = 0, frame_count = 0; int64_t start = -INT64_MAX, end = interval->end; int has_start = 0, has_end = interval->has_end && !interval->end_is_offset; - av_init_packet(&pkt); - av_log(NULL, AV_LOG_VERBOSE, "Processing read interval "); log_read_interval(interval, NULL, AV_LOG_VERBOSE); @@ -2503,18 +2501,23 @@ static int read_interval_packets(WriterContext *w, InputFile *ifile, ret = AVERROR(ENOMEM); goto end; } - while (!av_read_frame(fmt_ctx, &pkt)) { + pkt = av_packet_alloc(); + if (!pkt) { + ret = AVERROR(ENOMEM); + goto end; + } + while (!av_read_frame(fmt_ctx, pkt)) { if (fmt_ctx->nb_streams > nb_streams) { REALLOCZ_ARRAY_STREAM(nb_streams_frames, nb_streams, fmt_ctx->nb_streams); REALLOCZ_ARRAY_STREAM(nb_streams_packets, nb_streams, fmt_ctx->nb_streams); REALLOCZ_ARRAY_STREAM(selected_streams, nb_streams, fmt_ctx->nb_streams); nb_streams = fmt_ctx->nb_streams; } - if (selected_streams[pkt.stream_index]) { - AVRational tb = ifile->streams[pkt.stream_index].st->time_base; + if (selected_streams[pkt->stream_index]) { + AVRational tb = ifile->streams[pkt->stream_index].st->time_base; - if (pkt.pts != AV_NOPTS_VALUE) - *cur_ts = av_rescale_q(pkt.pts, tb, AV_TIME_BASE_Q); + if (pkt->pts != AV_NOPTS_VALUE) + *cur_ts = av_rescale_q(pkt->pts, tb, AV_TIME_BASE_Q); if (!has_start && *cur_ts != AV_NOPTS_VALUE) { start = *cur_ts; @@ -2536,26 +2539,27 @@ static int read_interval_packets(WriterContext *w, InputFile *ifile, frame_count++; if (do_read_packets) { if (do_show_packets) - show_packet(w, ifile, &pkt, i++); - nb_streams_packets[pkt.stream_index]++; + show_packet(w, ifile, pkt, i++); + nb_streams_packets[pkt->stream_index]++; } if (do_read_frames) { int packet_new = 1; - while (process_frame(w, ifile, frame, &pkt, &packet_new) > 0); + while (process_frame(w, ifile, frame, pkt, &packet_new) > 0); } } - av_packet_unref(&pkt); + av_packet_unref(pkt); } - av_packet_unref(&pkt); + av_packet_unref(pkt); //Flush remaining frames that are cached in the decoder for (i = 0; i < fmt_ctx->nb_streams; i++) { - pkt.stream_index = i; + pkt->stream_index = i; if (do_read_frames) - while (process_frame(w, ifile, frame, &pkt, &(int){1}) > 0); + while (process_frame(w, ifile, frame, pkt, &(int){1}) > 0); } end: av_frame_free(&frame); + av_packet_free(&pkt); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Could not read packets in interval "); log_read_interval(interval, NULL, AV_LOG_ERROR); From patchwork Fri Mar 5 16:33:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26136 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 277CC44B9E2 for ; Fri, 5 Mar 2021 18:36:30 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0CB0668ADE9; Fri, 5 Mar 2021 18:36:30 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f180.google.com (mail-qk1-f180.google.com [209.85.222.180]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3AABC68ADF3 for ; Fri, 5 Mar 2021 18:36:28 +0200 (EET) Received: by mail-qk1-f180.google.com with SMTP id f124so2553598qkj.5 for ; Fri, 05 Mar 2021 08:36:28 -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=+AHwJpr6FbFgJtXe62HQRvcHPD6Xj4T70GCn8PkdFRw=; b=BvYnRC6a3w9PLGa9adtsVxoUrzm5LomYBS7d4VCC6Jt2Efp34xfIwq7spwzXJ/M9VG iKJEp7wOrL8rnmWK6jNX+PO7nSOkuK7yPG82HBDfWN50DKpVwCG5nhrcFFpk9fbV7M4b OuMRh0hOhCdyOnDi9x7lFRmUrigK3rryU8adqy9f1c5BnsuNDpQjzw4ToW/SOWlRsYVQ kELF/3StSEDPDoDaVuBJy2I09LI8IXHrBmc59RcVCfKKzTwS89snUEAUu37v/R6SQyC/ IjCbwPp9YUvFVVkD4clhV/M4ieQxZWPgMWLzBVZYZumNYr7VqAvLfGs/cG0elP6+EUYL 25qg== 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=+AHwJpr6FbFgJtXe62HQRvcHPD6Xj4T70GCn8PkdFRw=; b=XmJTY2J+S/u78xXm4qFUmY5EXWax523p5XzQek7mKWJ0KRjSqE0GHB/Mr3LoAoL5Cj X2cI2lpO/1kuk1czqFKAlx5TzmqvzsZDm4je/G1WI/9YBkqKJjUydITlxmUF0o3zbm3k xmSRk/uUlkVDScEuk3pXvnB+uXzGrV0NoIBwsDfoLIwEiehaJhRIL3SzVI9LrO+JWGJp rXqPJHoNJ1wr6sJi/qe3jFEIdDlJh7tExc8JszO9LhYYuKKm2lk4BIf7dAraDu+eSjTr 1tRAW774NFUFltlohSdd7rF8WJAu4Ioq55XdnYjl5O4iHikBPOiFg80Jxprf0nwhVolG gAFg== X-Gm-Message-State: AOAM532MJqv8K4CIfCRKhS47znlfny2egRnoazAwWKq+WjZNVzS7BHAo kPDDMRToz68BPw0MYFE5Vu6Sb0fxWE8+RA== X-Google-Smtp-Source: ABdhPJzZp6oHww0Et9L00LWP3wslgzd3q8q9X4YMxKCRgejo9dKI7SavfNioXq4erd8xd3sNX/+ftQ== X-Received: by 2002:a05:620a:7ec:: with SMTP id k12mr10059240qkk.185.1614962186215; Fri, 05 Mar 2021 08:36:26 -0800 (PST) Received: from localhost.localdomain ([181.23.89.132]) by smtp.gmail.com with ESMTPSA id b10sm2168494qtt.23.2021.03.05.08.36.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 08:36:25 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Mar 2021 13:33:39 -0300 Message-Id: <20210305163339.63164-49-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 48/48] fftools/ffmpeg: 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 --- fftools/ffmpeg.c | 318 +++++++++++++++++++++++-------------------- fftools/ffmpeg.h | 4 + fftools/ffmpeg_opt.c | 5 +- 3 files changed, 177 insertions(+), 150 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 2abbc0ff29..46bb014de8 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -592,6 +592,7 @@ static void ffmpeg_cleanup(int ret) av_frame_free(&ost->filtered_frame); av_frame_free(&ost->last_frame); + av_packet_free(&ost->pkt); av_dict_free(&ost->encoder_opts); av_freep(&ost->forced_keyframes); @@ -610,9 +611,9 @@ static void ffmpeg_cleanup(int ret) if (ost->muxing_queue) { while (av_fifo_size(ost->muxing_queue)) { - AVPacket pkt; + AVPacket *pkt; av_fifo_generic_read(ost->muxing_queue, &pkt, sizeof(pkt), NULL); - av_packet_unref(&pkt); + av_packet_free(&pkt); } av_fifo_freep(&ost->muxing_queue); } @@ -624,6 +625,7 @@ static void ffmpeg_cleanup(int ret) #endif for (i = 0; i < nb_input_files; i++) { avformat_close_input(&input_files[i]->ctx); + av_packet_free(&input_files[i]->pkt); av_freep(&input_files[i]); } for (i = 0; i < nb_input_streams; i++) { @@ -631,6 +633,7 @@ static void ffmpeg_cleanup(int ret) av_frame_free(&ist->decoded_frame); av_frame_free(&ist->filter_frame); + av_packet_free(&ist->pkt); av_dict_free(&ist->decoder_opts); avsubtitle_free(&ist->prev_sub.subtitle); av_frame_free(&ist->sub2video.frame); @@ -746,7 +749,7 @@ static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int u } if (!of->header_written) { - AVPacket tmp_pkt = {0}; + AVPacket *tmp_pkt; /* the muxer is not initialized yet, buffer the packet */ if (!av_fifo_space(ost->muxing_queue)) { unsigned int are_we_over_size = @@ -769,8 +772,11 @@ static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int u ret = av_packet_make_refcounted(pkt); if (ret < 0) exit_program(1); - av_packet_move_ref(&tmp_pkt, pkt); - ost->muxing_queue_data_size += tmp_pkt.size; + tmp_pkt = av_packet_alloc(); + if (!tmp_pkt) + exit_program(1); + av_packet_move_ref(tmp_pkt, pkt); + ost->muxing_queue_data_size += tmp_pkt->size; av_fifo_generic_write(ost->muxing_queue, &tmp_pkt, sizeof(tmp_pkt), NULL); return; } @@ -999,13 +1005,9 @@ static void do_audio_out(OutputFile *of, OutputStream *ost, AVFrame *frame) { AVCodecContext *enc = ost->enc_ctx; - AVPacket pkt; + AVPacket *pkt = ost->pkt; int ret; - av_init_packet(&pkt); - pkt.data = NULL; - pkt.size = 0; - adjust_frame_pts_to_encoder_tb(of, ost, frame); if (!check_recording_time(ost)) @@ -1017,7 +1019,6 @@ static void do_audio_out(OutputFile *of, OutputStream *ost, ost->samples_encoded += frame->nb_samples; ost->frames_encoded++; - av_assert0(pkt.size || !pkt.data); update_benchmark(NULL); if (debug_ts) { av_log(NULL, AV_LOG_INFO, "encoder <- type:audio " @@ -1031,7 +1032,8 @@ static void do_audio_out(OutputFile *of, OutputStream *ost, goto error; while (1) { - ret = avcodec_receive_packet(enc, &pkt); + av_packet_unref(pkt); + ret = avcodec_receive_packet(enc, pkt); if (ret == AVERROR(EAGAIN)) break; if (ret < 0) @@ -1039,16 +1041,16 @@ static void do_audio_out(OutputFile *of, OutputStream *ost, update_benchmark("encode_audio %d.%d", ost->file_index, ost->index); - av_packet_rescale_ts(&pkt, enc->time_base, ost->mux_timebase); + av_packet_rescale_ts(pkt, enc->time_base, ost->mux_timebase); if (debug_ts) { av_log(NULL, AV_LOG_INFO, "encoder -> type:audio " "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s\n", - av_ts2str(pkt.pts), av_ts2timestr(pkt.pts, &enc->time_base), - av_ts2str(pkt.dts), av_ts2timestr(pkt.dts, &enc->time_base)); + av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &enc->time_base), + av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &enc->time_base)); } - output_packet(of, &pkt, ost, 0); + output_packet(of, pkt, ost, 0); } return; @@ -1064,7 +1066,7 @@ static void do_subtitle_out(OutputFile *of, int subtitle_out_max_size = 1024 * 1024; int subtitle_out_size, nb, i; AVCodecContext *enc; - AVPacket pkt; + AVPacket *pkt = ost->pkt; int64_t pts; if (sub->pts == AV_NOPTS_VALUE) { @@ -1122,21 +1124,21 @@ static void do_subtitle_out(OutputFile *of, exit_program(1); } - av_init_packet(&pkt); - pkt.data = subtitle_out; - pkt.size = subtitle_out_size; - pkt.pts = av_rescale_q(sub->pts, AV_TIME_BASE_Q, ost->mux_timebase); - pkt.duration = av_rescale_q(sub->end_display_time, (AVRational){ 1, 1000 }, ost->mux_timebase); + av_packet_unref(pkt); + pkt->data = subtitle_out; + pkt->size = subtitle_out_size; + pkt->pts = av_rescale_q(sub->pts, AV_TIME_BASE_Q, ost->mux_timebase); + pkt->duration = av_rescale_q(sub->end_display_time, (AVRational){ 1, 1000 }, ost->mux_timebase); if (enc->codec_id == AV_CODEC_ID_DVB_SUBTITLE) { /* XXX: the pts correction is handled here. Maybe handling it in the codec would be better */ if (i == 0) - pkt.pts += av_rescale_q(sub->start_display_time, (AVRational){ 1, 1000 }, ost->mux_timebase); + pkt->pts += av_rescale_q(sub->start_display_time, (AVRational){ 1, 1000 }, ost->mux_timebase); else - pkt.pts += av_rescale_q(sub->end_display_time, (AVRational){ 1, 1000 }, ost->mux_timebase); + pkt->pts += av_rescale_q(sub->end_display_time, (AVRational){ 1, 1000 }, ost->mux_timebase); } - pkt.dts = pkt.pts; - output_packet(of, &pkt, ost, 0); + pkt->dts = pkt->pts; + output_packet(of, pkt, ost, 0); } } @@ -1145,7 +1147,7 @@ static void do_video_out(OutputFile *of, AVFrame *next_picture) { int ret, format_video_sync; - AVPacket pkt; + AVPacket *pkt = ost->pkt; AVCodecContext *enc = ost->enc_ctx; AVRational frame_rate; int nb_frames, nb0_frames, i; @@ -1291,9 +1293,6 @@ static void do_video_out(OutputFile *of, AVFrame *in_picture; int forced_keyframe = 0; double pts_time; - av_init_packet(&pkt); - pkt.data = NULL; - pkt.size = 0; if (i < nb0_frames && ost->last_frame) { in_picture = ost->last_frame; @@ -1372,7 +1371,8 @@ static void do_video_out(OutputFile *of, av_frame_remove_side_data(in_picture, AV_FRAME_DATA_A53_CC); while (1) { - ret = avcodec_receive_packet(enc, &pkt); + av_packet_unref(pkt); + ret = avcodec_receive_packet(enc, pkt); update_benchmark("encode_video %d.%d", ost->file_index, ost->index); if (ret == AVERROR(EAGAIN)) break; @@ -1382,24 +1382,24 @@ static void do_video_out(OutputFile *of, if (debug_ts) { av_log(NULL, AV_LOG_INFO, "encoder -> type:video " "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s\n", - av_ts2str(pkt.pts), av_ts2timestr(pkt.pts, &enc->time_base), - av_ts2str(pkt.dts), av_ts2timestr(pkt.dts, &enc->time_base)); + av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &enc->time_base), + av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &enc->time_base)); } - if (pkt.pts == AV_NOPTS_VALUE && !(enc->codec->capabilities & AV_CODEC_CAP_DELAY)) - pkt.pts = ost->sync_opts; + if (pkt->pts == AV_NOPTS_VALUE && !(enc->codec->capabilities & AV_CODEC_CAP_DELAY)) + pkt->pts = ost->sync_opts; - av_packet_rescale_ts(&pkt, enc->time_base, ost->mux_timebase); + av_packet_rescale_ts(pkt, enc->time_base, ost->mux_timebase); if (debug_ts) { av_log(NULL, AV_LOG_INFO, "encoder -> type:video " "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s\n", - av_ts2str(pkt.pts), av_ts2timestr(pkt.pts, &ost->mux_timebase), - av_ts2str(pkt.dts), av_ts2timestr(pkt.dts, &ost->mux_timebase)); + av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &ost->mux_timebase), + av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &ost->mux_timebase)); } - frame_size = pkt.size; - output_packet(of, &pkt, ost, 0); + frame_size = pkt->size; + output_packet(of, pkt, ost, 0); /* if two pass, output log */ if (ost->logfile && enc->stats_out) { @@ -1528,6 +1528,9 @@ static int reap_filters(int flush) if (av_buffersink_get_type(filter) == AVMEDIA_TYPE_AUDIO) init_output_stream_wrapper(ost, NULL, 1); + if (!ost->pkt && !(ost->pkt = av_packet_alloc())) { + return AVERROR(ENOMEM); + } if (!ost->filtered_frame && !(ost->filtered_frame = av_frame_alloc())) { return AVERROR(ENOMEM); } @@ -1968,7 +1971,7 @@ static void flush_encoders(void) for (;;) { const char *desc = NULL; - AVPacket pkt; + AVPacket *pkt = ost->pkt; int pkt_size; switch (enc->codec_type) { @@ -1982,13 +1985,10 @@ static void flush_encoders(void) av_assert0(0); } - av_init_packet(&pkt); - pkt.data = NULL; - pkt.size = 0; - update_benchmark(NULL); - while ((ret = avcodec_receive_packet(enc, &pkt)) == AVERROR(EAGAIN)) { + av_packet_unref(pkt); + while ((ret = avcodec_receive_packet(enc, pkt)) == AVERROR(EAGAIN)) { ret = avcodec_send_frame(enc, NULL); if (ret < 0) { av_log(NULL, AV_LOG_FATAL, "%s encoding failed: %s\n", @@ -2009,16 +2009,16 @@ static void flush_encoders(void) fprintf(ost->logfile, "%s", enc->stats_out); } if (ret == AVERROR_EOF) { - output_packet(of, &pkt, ost, 1); + output_packet(of, pkt, ost, 1); break; } if (ost->finished & MUXER_FINISHED) { - av_packet_unref(&pkt); + av_packet_unref(pkt); continue; } - av_packet_rescale_ts(&pkt, enc->time_base, ost->mux_timebase); - pkt_size = pkt.size; - output_packet(of, &pkt, ost, 0); + av_packet_rescale_ts(pkt, enc->time_base, ost->mux_timebase); + pkt_size = pkt->size; + output_packet(of, pkt, ost, 0); if (ost->enc_ctx->codec_type == AVMEDIA_TYPE_VIDEO && vstats_filename) { do_video_stats(ost, pkt_size); } @@ -2052,14 +2052,12 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p InputFile *f = input_files [ist->file_index]; int64_t start_time = (of->start_time == AV_NOPTS_VALUE) ? 0 : of->start_time; int64_t ost_tb_start_time = av_rescale_q(start_time, AV_TIME_BASE_Q, ost->mux_timebase); - AVPacket opkt; + AVPacket *opkt = ost->pkt; + av_packet_unref(opkt); // EOF: flush output bitstream filters. if (!pkt) { - av_init_packet(&opkt); - opkt.data = NULL; - opkt.size = 0; - output_packet(of, &opkt, ost, 1); + output_packet(of, opkt, ost, 1); return; } @@ -2097,30 +2095,30 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p if (ost->enc_ctx->codec_type == AVMEDIA_TYPE_VIDEO) ost->sync_opts++; - if (av_packet_ref(&opkt, pkt) < 0) + if (av_packet_ref(opkt, pkt) < 0) exit_program(1); if (pkt->pts != AV_NOPTS_VALUE) - opkt.pts = av_rescale_q(pkt->pts, ist->st->time_base, ost->mux_timebase) - ost_tb_start_time; + opkt->pts = av_rescale_q(pkt->pts, ist->st->time_base, ost->mux_timebase) - ost_tb_start_time; if (pkt->dts == AV_NOPTS_VALUE) { - opkt.dts = av_rescale_q(ist->dts, AV_TIME_BASE_Q, ost->mux_timebase); + opkt->dts = av_rescale_q(ist->dts, AV_TIME_BASE_Q, ost->mux_timebase); } else if (ost->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { int duration = av_get_audio_frame_duration(ist->dec_ctx, pkt->size); if(!duration) duration = ist->dec_ctx->frame_size; - opkt.dts = av_rescale_delta(ist->st->time_base, pkt->dts, + opkt->dts = av_rescale_delta(ist->st->time_base, pkt->dts, (AVRational){1, ist->dec_ctx->sample_rate}, duration, &ist->filter_in_rescale_delta_last, ost->mux_timebase); /* dts will be set immediately afterwards to what pts is now */ - opkt.pts = opkt.dts - ost_tb_start_time; + opkt->pts = opkt->dts - ost_tb_start_time; } else - opkt.dts = av_rescale_q(pkt->dts, ist->st->time_base, ost->mux_timebase); - opkt.dts -= ost_tb_start_time; + opkt->dts = av_rescale_q(pkt->dts, ist->st->time_base, ost->mux_timebase); + opkt->dts -= ost_tb_start_time; - opkt.duration = av_rescale_q(pkt->duration, ist->st->time_base, ost->mux_timebase); + opkt->duration = av_rescale_q(pkt->duration, ist->st->time_base, ost->mux_timebase); - output_packet(of, &opkt, ost, 0); + output_packet(of, opkt, ost, 0); } int guess_input_channel_layout(InputStream *ist) @@ -2395,7 +2393,6 @@ static int decode_video(InputStream *ist, AVPacket *pkt, int *got_output, int64_ int i, ret = 0, err = 0; int64_t best_effort_timestamp; int64_t dts = AV_NOPTS_VALUE; - AVPacket avpkt; // With fate-indeo3-2, we're getting 0-sized packets before EOF for some // reason. This seems like a semi-critical bug. Don't trigger EOF, and @@ -2411,8 +2408,7 @@ static int decode_video(InputStream *ist, AVPacket *pkt, int *got_output, int64_ if (ist->dts != AV_NOPTS_VALUE) dts = av_rescale_q(ist->dts, AV_TIME_BASE_Q, ist->st->time_base); if (pkt) { - avpkt = *pkt; - avpkt.dts = dts; // ffmpeg.c probably shouldn't do this + pkt->dts = dts; // ffmpeg.c probably shouldn't do this } // The old code used to set dts on the drain packet, which does not work @@ -2426,7 +2422,7 @@ static int decode_video(InputStream *ist, AVPacket *pkt, int *got_output, int64_ } update_benchmark(NULL); - ret = decode(ist->dec_ctx, decoded_frame, got_output, pkt ? &avpkt : NULL); + ret = decode(ist->dec_ctx, decoded_frame, got_output, pkt); update_benchmark("decode_video %d.%d", ist->file_index, ist->st->index); if (ret < 0) *decode_failed = 1; @@ -2585,6 +2581,8 @@ static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int *got_output, for (i = 0; i < nb_output_streams; i++) { OutputStream *ost = output_streams[i]; + if (!ost->pkt && !(ost->pkt = av_packet_alloc())) + exit_program(1); if (!check_output_constraints(ist, ost) || !ost->encoding_needed || ost->enc->type != AVMEDIA_TYPE_SUBTITLE) continue; @@ -2620,7 +2618,12 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo int repeating = 0; int eof_reached = 0; - AVPacket avpkt; + AVPacket *avpkt; + + if (!ist->pkt && !(ist->pkt = av_packet_alloc())) + return AVERROR(ENOMEM); + avpkt = ist->pkt; + if (!ist->saw_first_ts) { ist->dts = ist->st->avg_frame_rate.num ? - ist->dec_ctx->has_b_frames * AV_TIME_BASE / av_q2d(ist->st->avg_frame_rate) : 0; ist->pts = 0; @@ -2636,13 +2639,11 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo if (ist->next_pts == AV_NOPTS_VALUE) ist->next_pts = ist->pts; - if (!pkt) { - /* EOF handling */ - av_init_packet(&avpkt); - avpkt.data = NULL; - avpkt.size = 0; - } else { - avpkt = *pkt; + if (pkt) { + av_packet_unref(avpkt); + ret = av_packet_ref(avpkt, pkt); + if (ret < 0) + return ret; } if (pkt && pkt->dts != AV_NOPTS_VALUE) { @@ -2663,11 +2664,12 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo switch (ist->dec_ctx->codec_type) { case AVMEDIA_TYPE_AUDIO: - ret = decode_audio (ist, repeating ? NULL : &avpkt, &got_output, + ret = decode_audio (ist, repeating ? NULL : avpkt, &got_output, &decode_failed); + av_packet_unref(avpkt); break; case AVMEDIA_TYPE_VIDEO: - ret = decode_video (ist, repeating ? NULL : &avpkt, &got_output, &duration_pts, !pkt, + ret = decode_video (ist, repeating ? NULL : avpkt, &got_output, &duration_pts, !pkt, &decode_failed); if (!repeating || !pkt || got_output) { if (pkt && pkt->duration) { @@ -2692,13 +2694,15 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo ist->next_pts += duration_dts; } } + av_packet_unref(avpkt); break; case AVMEDIA_TYPE_SUBTITLE: if (repeating) break; - ret = transcode_subtitles(ist, &avpkt, &got_output, &decode_failed); + ret = transcode_subtitles(ist, avpkt, &got_output, &decode_failed); if (!pkt && ret >= 0) ret = AVERROR_EOF; + av_packet_unref(avpkt); break; default: return -1; @@ -2787,6 +2791,8 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo for (i = 0; i < nb_output_streams; i++) { OutputStream *ost = output_streams[i]; + if (!ost->pkt && !(ost->pkt = av_packet_alloc())) + exit_program(1); if (!check_output_constraints(ist, ost) || ost->encoding_needed) continue; @@ -3054,10 +3060,11 @@ static int check_init_output_file(OutputFile *of, int file_index) ost->mux_timebase = ost->st->time_base; while (av_fifo_size(ost->muxing_queue)) { - AVPacket pkt; + AVPacket *pkt; av_fifo_generic_read(ost->muxing_queue, &pkt, sizeof(pkt), NULL); - ost->muxing_queue_data_size -= pkt.size; - write_packet(of, &pkt, ost, 1); + ost->muxing_queue_data_size -= pkt->size; + write_packet(of, pkt, ost, 1); + av_packet_free(&pkt); } } @@ -4082,12 +4089,12 @@ static int check_keyboard_interaction(int64_t cur_time) static void *input_thread(void *arg) { InputFile *f = arg; + AVPacket *pkt = f->pkt, *queue_pkt; unsigned flags = f->non_blocking ? AV_THREAD_MESSAGE_NONBLOCK : 0; int ret = 0; while (1) { - AVPacket pkt; - ret = av_read_frame(f->ctx, &pkt); + ret = av_read_frame(f->ctx, pkt); if (ret == AVERROR(EAGAIN)) { av_usleep(10000); @@ -4097,10 +4104,17 @@ static void *input_thread(void *arg) av_thread_message_queue_set_err_recv(f->in_thread_queue, ret); break; } - ret = av_thread_message_queue_send(f->in_thread_queue, &pkt, flags); + queue_pkt = av_packet_alloc(); + if (!queue_pkt) { + av_packet_unref(pkt); + av_thread_message_queue_set_err_recv(f->in_thread_queue, AVERROR(ENOMEM)); + break; + } + av_packet_move_ref(queue_pkt, pkt); + ret = av_thread_message_queue_send(f->in_thread_queue, &queue_pkt, flags); if (flags && ret == AVERROR(EAGAIN)) { flags = 0; - ret = av_thread_message_queue_send(f->in_thread_queue, &pkt, flags); + ret = av_thread_message_queue_send(f->in_thread_queue, &queue_pkt, flags); av_log(f->ctx, AV_LOG_WARNING, "Thread message queue blocking; consider raising the " "thread_queue_size option (current value: %d)\n", @@ -4111,7 +4125,7 @@ static void *input_thread(void *arg) av_log(f->ctx, AV_LOG_ERROR, "Unable to send packet to main thread: %s\n", av_err2str(ret)); - av_packet_unref(&pkt); + av_packet_free(&queue_pkt); av_thread_message_queue_set_err_recv(f->in_thread_queue, ret); break; } @@ -4123,13 +4137,13 @@ static void *input_thread(void *arg) static void free_input_thread(int i) { InputFile *f = input_files[i]; - AVPacket pkt; + AVPacket *pkt; if (!f || !f->in_thread_queue) return; av_thread_message_queue_set_err_send(f->in_thread_queue, AVERROR_EOF); while (av_thread_message_queue_recv(f->in_thread_queue, &pkt, 0) >= 0) - av_packet_unref(&pkt); + av_packet_free(&pkt); pthread_join(f->thread, NULL); f->joined = 1; @@ -4158,7 +4172,7 @@ static int init_input_thread(int i) strcmp(f->ctx->iformat->name, "lavfi")) f->non_blocking = 1; ret = av_thread_message_queue_alloc(&f->in_thread_queue, - f->thread_queue_size, sizeof(AVPacket)); + f->thread_queue_size, sizeof(f->pkt)); if (ret < 0) return ret; @@ -4183,7 +4197,7 @@ static int init_input_threads(void) return 0; } -static int get_input_packet_mt(InputFile *f, AVPacket *pkt) +static int get_input_packet_mt(InputFile *f, AVPacket **pkt) { return av_thread_message_queue_recv(f->in_thread_queue, pkt, f->non_blocking ? @@ -4191,7 +4205,7 @@ static int get_input_packet_mt(InputFile *f, AVPacket *pkt) } #endif -static int get_input_packet(InputFile *f, AVPacket *pkt) +static int get_input_packet(InputFile *f, AVPacket **pkt) { if (f->rate_emu) { int i; @@ -4208,7 +4222,8 @@ static int get_input_packet(InputFile *f, AVPacket *pkt) if (f->thread_queue_size) return get_input_packet_mt(f, pkt); #endif - return av_read_frame(f->ctx, pkt); + *pkt = f->pkt; + return av_read_frame(f->ctx, *pkt); } static int got_eagain(void) @@ -4320,7 +4335,7 @@ static int process_input(int file_index) InputFile *ifile = input_files[file_index]; AVFormatContext *is; InputStream *ist; - AVPacket pkt; + AVPacket *pkt; int ret, thread_ret, i, j; int64_t duration; int64_t pkt_dts; @@ -4395,27 +4410,27 @@ static int process_input(int file_index) reset_eagain(); if (do_pkt_dump) { - av_pkt_dump_log2(NULL, AV_LOG_INFO, &pkt, do_hex_dump, - is->streams[pkt.stream_index]); + av_pkt_dump_log2(NULL, AV_LOG_INFO, pkt, do_hex_dump, + is->streams[pkt->stream_index]); } /* the following test is needed in case new streams appear dynamically in stream : we ignore them */ - if (pkt.stream_index >= ifile->nb_streams) { - report_new_stream(file_index, &pkt); + if (pkt->stream_index >= ifile->nb_streams) { + report_new_stream(file_index, pkt); goto discard_packet; } - ist = input_streams[ifile->ist_index + pkt.stream_index]; + ist = input_streams[ifile->ist_index + pkt->stream_index]; - ist->data_size += pkt.size; + ist->data_size += pkt->size; ist->nb_packets++; if (ist->discard) goto discard_packet; - if (pkt.flags & AV_PKT_FLAG_CORRUPT) { + if (pkt->flags & AV_PKT_FLAG_CORRUPT) { av_log(NULL, exit_on_error ? AV_LOG_FATAL : AV_LOG_WARNING, - "%s: corrupt input packet in stream %d\n", is->url, pkt.stream_index); + "%s: corrupt input packet in stream %d\n", is->url, pkt->stream_index); if (exit_on_error) exit_program(1); } @@ -4423,11 +4438,11 @@ static int process_input(int file_index) if (debug_ts) { av_log(NULL, AV_LOG_INFO, "demuxer -> ist_index:%d type:%s " "next_dts:%s next_dts_time:%s next_pts:%s next_pts_time:%s pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s off:%s off_time:%s\n", - ifile->ist_index + pkt.stream_index, av_get_media_type_string(ist->dec_ctx->codec_type), + ifile->ist_index + pkt->stream_index, av_get_media_type_string(ist->dec_ctx->codec_type), av_ts2str(ist->next_dts), av_ts2timestr(ist->next_dts, &AV_TIME_BASE_Q), av_ts2str(ist->next_pts), av_ts2timestr(ist->next_pts, &AV_TIME_BASE_Q), - av_ts2str(pkt.pts), av_ts2timestr(pkt.pts, &ist->st->time_base), - av_ts2str(pkt.dts), av_ts2timestr(pkt.dts, &ist->st->time_base), + av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &ist->st->time_base), + av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &ist->st->time_base), av_ts2str(input_files[ist->file_index]->ts_offset), av_ts2timestr(input_files[ist->file_index]->ts_offset, &AV_TIME_BASE_Q)); } @@ -4457,12 +4472,12 @@ static int process_input(int file_index) stime2= stime + (1ULL<st->pts_wrap_bits); ist->wrap_correction_done = 1; - if(stime2 > stime && pkt.dts != AV_NOPTS_VALUE && pkt.dts > stime + (1LL<<(ist->st->pts_wrap_bits-1))) { - pkt.dts -= 1ULL<st->pts_wrap_bits; + if(stime2 > stime && pkt->dts != AV_NOPTS_VALUE && pkt->dts > stime + (1LL<<(ist->st->pts_wrap_bits-1))) { + pkt->dts -= 1ULL<st->pts_wrap_bits; ist->wrap_correction_done = 0; } - if(stime2 > stime && pkt.pts != AV_NOPTS_VALUE && pkt.pts > stime + (1LL<<(ist->st->pts_wrap_bits-1))) { - pkt.pts -= 1ULL<st->pts_wrap_bits; + if(stime2 > stime && pkt->pts != AV_NOPTS_VALUE && pkt->pts > stime + (1LL<<(ist->st->pts_wrap_bits-1))) { + pkt->pts -= 1ULL<st->pts_wrap_bits; ist->wrap_correction_done = 0; } } @@ -4476,10 +4491,10 @@ static int process_input(int file_index) if (src_sd->type == AV_PKT_DATA_DISPLAYMATRIX) continue; - if (av_packet_get_side_data(&pkt, src_sd->type, NULL)) + if (av_packet_get_side_data(pkt, src_sd->type, NULL)) continue; - dst_data = av_packet_new_side_data(&pkt, src_sd->type, src_sd->size); + dst_data = av_packet_new_side_data(pkt, src_sd->type, src_sd->size); if (!dst_data) exit_program(1); @@ -4487,17 +4502,17 @@ static int process_input(int file_index) } } - if (pkt.dts != AV_NOPTS_VALUE) - pkt.dts += av_rescale_q(ifile->ts_offset, AV_TIME_BASE_Q, ist->st->time_base); - if (pkt.pts != AV_NOPTS_VALUE) - pkt.pts += av_rescale_q(ifile->ts_offset, AV_TIME_BASE_Q, ist->st->time_base); + if (pkt->dts != AV_NOPTS_VALUE) + pkt->dts += av_rescale_q(ifile->ts_offset, AV_TIME_BASE_Q, ist->st->time_base); + if (pkt->pts != AV_NOPTS_VALUE) + pkt->pts += av_rescale_q(ifile->ts_offset, AV_TIME_BASE_Q, ist->st->time_base); - if (pkt.pts != AV_NOPTS_VALUE) - pkt.pts *= ist->ts_scale; - if (pkt.dts != AV_NOPTS_VALUE) - pkt.dts *= ist->ts_scale; + if (pkt->pts != AV_NOPTS_VALUE) + pkt->pts *= ist->ts_scale; + if (pkt->dts != AV_NOPTS_VALUE) + pkt->dts *= ist->ts_scale; - pkt_dts = av_rescale_q_rnd(pkt.dts, ist->st->time_base, AV_TIME_BASE_Q, AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX); + pkt_dts = av_rescale_q_rnd(pkt->dts, ist->st->time_base, AV_TIME_BASE_Q, AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX); if ((ist->dec_ctx->codec_type == AVMEDIA_TYPE_VIDEO || ist->dec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) && pkt_dts != AV_NOPTS_VALUE && ist->next_dts == AV_NOPTS_VALUE && !copy_ts @@ -4509,27 +4524,27 @@ static int process_input(int file_index) av_log(NULL, AV_LOG_DEBUG, "Inter stream timestamp discontinuity %"PRId64", new offset= %"PRId64"\n", delta, ifile->ts_offset); - pkt.dts -= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base); - if (pkt.pts != AV_NOPTS_VALUE) - pkt.pts -= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base); + pkt->dts -= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base); + if (pkt->pts != AV_NOPTS_VALUE) + pkt->pts -= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base); } } duration = av_rescale_q(ifile->duration, ifile->time_base, ist->st->time_base); - if (pkt.pts != AV_NOPTS_VALUE) { - pkt.pts += duration; - ist->max_pts = FFMAX(pkt.pts, ist->max_pts); - ist->min_pts = FFMIN(pkt.pts, ist->min_pts); + if (pkt->pts != AV_NOPTS_VALUE) { + pkt->pts += duration; + ist->max_pts = FFMAX(pkt->pts, ist->max_pts); + ist->min_pts = FFMIN(pkt->pts, ist->min_pts); } - if (pkt.dts != AV_NOPTS_VALUE) - pkt.dts += duration; + if (pkt->dts != AV_NOPTS_VALUE) + pkt->dts += duration; - pkt_dts = av_rescale_q_rnd(pkt.dts, ist->st->time_base, AV_TIME_BASE_Q, AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX); + pkt_dts = av_rescale_q_rnd(pkt->dts, ist->st->time_base, AV_TIME_BASE_Q, AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX); if (copy_ts && pkt_dts != AV_NOPTS_VALUE && ist->next_dts != AV_NOPTS_VALUE && (is->iformat->flags & AVFMT_TS_DISCONT) && ist->st->pts_wrap_bits < 60) { - int64_t wrap_dts = av_rescale_q_rnd(pkt.dts + (1LL<st->pts_wrap_bits), + int64_t wrap_dts = av_rescale_q_rnd(pkt->dts + (1LL<st->pts_wrap_bits), ist->st->time_base, AV_TIME_BASE_Q, AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX); if (FFABS(wrap_dts - ist->next_dts) < FFABS(pkt_dts - ist->next_dts)/10) @@ -4552,46 +4567,51 @@ static int process_input(int file_index) ist->file_index, ist->st->index, ist->st->id, av_get_media_type_string(ist->dec_ctx->codec_type), delta, ifile->ts_offset); - pkt.dts -= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base); - if (pkt.pts != AV_NOPTS_VALUE) - pkt.pts -= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base); + pkt->dts -= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base); + if (pkt->pts != AV_NOPTS_VALUE) + pkt->pts -= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base); } } else { if ( delta < -1LL*dts_error_threshold*AV_TIME_BASE || delta > 1LL*dts_error_threshold*AV_TIME_BASE) { - av_log(NULL, AV_LOG_WARNING, "DTS %"PRId64", next:%"PRId64" st:%d invalid dropping\n", pkt.dts, ist->next_dts, pkt.stream_index); - pkt.dts = AV_NOPTS_VALUE; + av_log(NULL, AV_LOG_WARNING, "DTS %"PRId64", next:%"PRId64" st:%d invalid dropping\n", pkt->dts, ist->next_dts, pkt->stream_index); + pkt->dts = AV_NOPTS_VALUE; } - if (pkt.pts != AV_NOPTS_VALUE){ - int64_t pkt_pts = av_rescale_q(pkt.pts, ist->st->time_base, AV_TIME_BASE_Q); + if (pkt->pts != AV_NOPTS_VALUE){ + int64_t pkt_pts = av_rescale_q(pkt->pts, ist->st->time_base, AV_TIME_BASE_Q); delta = pkt_pts - ist->next_dts; if ( delta < -1LL*dts_error_threshold*AV_TIME_BASE || delta > 1LL*dts_error_threshold*AV_TIME_BASE) { - av_log(NULL, AV_LOG_WARNING, "PTS %"PRId64", next:%"PRId64" invalid dropping st:%d\n", pkt.pts, ist->next_dts, pkt.stream_index); - pkt.pts = AV_NOPTS_VALUE; + av_log(NULL, AV_LOG_WARNING, "PTS %"PRId64", next:%"PRId64" invalid dropping st:%d\n", pkt->pts, ist->next_dts, pkt->stream_index); + pkt->pts = AV_NOPTS_VALUE; } } } } - if (pkt.dts != AV_NOPTS_VALUE) - ifile->last_ts = av_rescale_q(pkt.dts, ist->st->time_base, AV_TIME_BASE_Q); + if (pkt->dts != AV_NOPTS_VALUE) + ifile->last_ts = av_rescale_q(pkt->dts, ist->st->time_base, AV_TIME_BASE_Q); if (debug_ts) { av_log(NULL, AV_LOG_INFO, "demuxer+ffmpeg -> ist_index:%d type:%s pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s off:%s off_time:%s\n", - ifile->ist_index + pkt.stream_index, av_get_media_type_string(ist->dec_ctx->codec_type), - av_ts2str(pkt.pts), av_ts2timestr(pkt.pts, &ist->st->time_base), - av_ts2str(pkt.dts), av_ts2timestr(pkt.dts, &ist->st->time_base), + ifile->ist_index + pkt->stream_index, av_get_media_type_string(ist->dec_ctx->codec_type), + av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &ist->st->time_base), + av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &ist->st->time_base), av_ts2str(input_files[ist->file_index]->ts_offset), av_ts2timestr(input_files[ist->file_index]->ts_offset, &AV_TIME_BASE_Q)); } - sub2video_heartbeat(ist, pkt.pts); + sub2video_heartbeat(ist, pkt->pts); - process_input_packet(ist, &pkt, 0); + process_input_packet(ist, pkt, 0); discard_packet: - av_packet_unref(&pkt); +#if HAVE_THREADS + if (ifile->thread_queue_size) + av_packet_free(&pkt); + else +#endif + av_packet_unref(pkt); return 0; } diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 8813eaf2e3..606f2afe0c 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -310,6 +310,7 @@ typedef struct InputStream { const AVCodec *dec; AVFrame *decoded_frame; AVFrame *filter_frame; /* a ref of decoded_frame, to be sent to filters */ + AVPacket *pkt; int64_t start; /* time when read started */ /* predicted dts of the next packet read for this stream or (when there are @@ -418,6 +419,8 @@ typedef struct InputFile { int rate_emu; int accurate_seek; + AVPacket *pkt; + #if HAVE_THREADS AVThreadMessageQueue *in_thread_queue; pthread_t thread; /* thread reading from this file */ @@ -474,6 +477,7 @@ typedef struct OutputStream { int64_t max_frames; AVFrame *filtered_frame; AVFrame *last_frame; + AVPacket *pkt; int last_dropped; int last_nb0_frames[3]; diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 85feeb89f2..807e783422 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -1280,6 +1280,9 @@ static int open_input_file(OptionsContext *o, const char *filename) f->loop = o->loop; f->duration = 0; f->time_base = (AVRational){ 1, 1 }; + f->pkt = av_packet_alloc(); + if (!f->pkt) + exit_program(1); #if HAVE_THREADS f->thread_queue_size = o->thread_queue_size; #endif @@ -1571,7 +1574,7 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e ost->max_muxing_queue_size = 128; MATCH_PER_STREAM_OPT(max_muxing_queue_size, i, ost->max_muxing_queue_size, oc, st); - ost->max_muxing_queue_size *= sizeof(AVPacket); + ost->max_muxing_queue_size *= sizeof(ost->pkt); ost->muxing_queue_data_size = 0;