From patchwork Wed Nov 18 16:52:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 23716 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 873AA44BBEA for ; Wed, 18 Nov 2020 19:01:05 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7259968B65F; Wed, 18 Nov 2020 19:01:05 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f195.google.com (mail-qk1-f195.google.com [209.85.222.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 92BE368B61C for ; Wed, 18 Nov 2020 19:01:04 +0200 (EET) Received: by mail-qk1-f195.google.com with SMTP id 199so2443992qkg.9 for ; Wed, 18 Nov 2020 09:01: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=ECWo6Rxzf486R9YVpnnvK4aIevaBTCqT/rQpTKdo1r8=; b=nI4TFFl0SXdonvAaNeiA/XT8KFxSBfm1GV8UWBkccNcJvhOSvTE5o8GooLqszsHoGY Kds80OiG8kC7aTGM97mG/n9nYE7Asmt4DMg0zn9VzV88GNPvG3Vn5fNs9VMvW9H/DtXT YHJMAMAs/RCiVETzpgKxFEHcOkoWshZdE1NtsVZzHM6hhb9HG5CEwVg/AVpjJWVFIPqR ZZXZN/NrMgZg1mC0xxCTeCkQwmJu1bcr6mESgeNGD98f4gIMu7DFoEF3A4e2kPAiTflf jOrvFTE77nUwCzT6kknCQIBGS0FjB5uFoKJHCZpN2N29VifYuPdrMDTcDOjKMjsxUFbo mZsg== 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=ECWo6Rxzf486R9YVpnnvK4aIevaBTCqT/rQpTKdo1r8=; b=qWtZnVUAA50nD4DuUJ7imjPSJ63PFZWAv7kjCfOYK+RgUXcFXQV1XrYbRO5xtUUrDu 6flDh9AAnrQ1w9ORkrIYNAfxyb/gOHq6pER7TcTw8osFq7j7VKOta9cB5GsTHyMBPGJK EqjeeuOcOBoqx+O24juhXz4E1y52cOrM+jjvUtd9Wtvkr+3GH1aHUgRVL8EKjSElebNn dlOnBuKYz3qNyfmBbbFv8eH1ptPsjAV5W11L32BVi3noys7CkSLzGql09isG8RYeL2X5 3TbkX6Zf+jf0BxJYFDrJ02bo3vmRX2Qrm4DWMpnWQwDOMqAERsYTQEZ/Y1PSYDZCH6L1 7tAg== X-Gm-Message-State: AOAM533KMw8ARsG4F/JTktaB6uyq44A9N+f9cPoyPCyJJxuriIZqAeKP BLYIrwADbctes/Xg8dNN/No0ZcqT58s9+w== X-Google-Smtp-Source: ABdhPJzLoZzA4VMwhHCuwn9aLB+XpB9ZrKOQSzlckKzzp4WVtJ6OUh+kkJVIxeiCiNRhRAKvVKeX8g== X-Received: by 2002:ac8:5059:: with SMTP id h25mr5295686qtm.283.1605718388850; Wed, 18 Nov 2020 08:53:08 -0800 (PST) Received: from localhost.localdomain ([181.23.91.217]) by smtp.gmail.com with ESMTPSA id f14sm4863788qkk.89.2020.11.18.08.53.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2020 08:53:08 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 18 Nov 2020 13:52:30 -0300 Message-Id: <20201118165247.4130-2-jamrial@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201118165247.4130-1-jamrial@gmail.com> References: <20201118165247.4130-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 01/18] avcodec/packet_internal: add a PacketListEntry 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" This will functionally replace AVPacketList as it currently stands, and is the first step in preparation for a new public AVPacketList API Signed-off-by: James Almer --- libavcodec/packet_internal.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libavcodec/packet_internal.h b/libavcodec/packet_internal.h index 832ddb4a61..9b9bef94f0 100644 --- a/libavcodec/packet_internal.h +++ b/libavcodec/packet_internal.h @@ -23,6 +23,10 @@ #include "packet.h" +typedef struct PacketListEntry { + AVPacket pkt; + struct PacketListEntry *next; +} PacketListEntry; /** * Append an AVPacket to the list. From patchwork Wed Nov 18 16:52:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 23719 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 54BEB448EF5 for ; Wed, 18 Nov 2020 19:23:41 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4E96368B647; Wed, 18 Nov 2020 19:23:40 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-io1-f68.google.com (mail-io1-f68.google.com [209.85.166.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E3821689D14 for ; Wed, 18 Nov 2020 19:23:32 +0200 (EET) Received: by mail-io1-f68.google.com with SMTP id o11so2822006ioo.11 for ; Wed, 18 Nov 2020 09:23: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=QRUIEhhCvf6YTxjyWsGO4/+mjBKvoqSNqnK1ngP9Ae8=; b=dR1KSdRTsBTay0F0DUlpT4Cay18DzKLgWhvs4BBK0a1Rrrn/BbY8295yRKSBmxDb8c tYNvUWTFOXV/eS/2HDDizjss8UYMjzRYOxuz1mD5LdwEg9MUY9O26uz4mm+Gjlhtpr/2 zk5cVpKKXc205vd7oBke0vlT+zR+NW2ioPolzo2Ihk+h+qyTowWnwpyBwp7jm9EvyNS5 aHbD2uuK2dl+bfNHSicxbO6pcbq55Z+JOFClDAIlA8isgfzrb6227cdR3v/YNXrXH1iH 9duMqboSW4Em4oKwGQ56cY5LOYcsJ2kGVlWBvacxEG2+FY3Nz+1piWKRA2cSU6Ka6DK5 kipQ== 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=QRUIEhhCvf6YTxjyWsGO4/+mjBKvoqSNqnK1ngP9Ae8=; b=LRQtFVjnH0Q5WGkj37g/hQ/8KrqhgFoinUeZpMCwypLnyBybuW9INNrcNs49c+5Kfe HWjTx3SWuMsa+Nwwv4OB5fW4x/puJh7YkEJAEpYXgliZIa2y/BLFhbL3lO72VXvQ9VnB HpyXhxWUX3KxrV6J0PEl7exoaaBTNDKY+DTB6E1QsznNNPa9sftqJhyHRT2Faz5F/LPv GaUb8W4E276UjEwH9xhYdJIYkMgpLMPFgWnu9bGvLHrFGnu6ERnX95bI8V8nXb2Z+tPZ 0hNilmlZDvqmPgjncZlxfiPU098W/FHa4sneBwfwTMXLGMCNXt3otLLX7Zk1NyAFu5Mz gqpg== X-Gm-Message-State: AOAM531HS8e9eHy6aofh431vINPtsMsk1pfvOyFd40/KouTXdCp1zzBj 2xYm8Wmsb7s+AQMs87tbqJz6LFndFzaOyQ== X-Google-Smtp-Source: ABdhPJy2MxhshhqjE96HCMcHDfqjTAVXbfbAEsRL+iwMHDz5ckun6DiZDmgnuUdtBuYjFFHHHBTdbQ== X-Received: by 2002:ac8:7395:: with SMTP id t21mr5054504qtp.358.1605718390355; Wed, 18 Nov 2020 08:53:10 -0800 (PST) Received: from localhost.localdomain ([181.23.91.217]) by smtp.gmail.com with ESMTPSA id f14sm4863788qkk.89.2020.11.18.08.53.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2020 08:53:09 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 18 Nov 2020 13:52:31 -0300 Message-Id: <20201118165247.4130-3-jamrial@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201118165247.4130-1-jamrial@gmail.com> References: <20201118165247.4130-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 02/18] avformat/internal: make last_in_packet_buffer of type PacketListEntry 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 | 3 ++- libavformat/mux.c | 11 ++++++----- libavformat/mxfenc.c | 6 +++--- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/libavformat/internal.h b/libavformat/internal.h index 49e82bfbca..c29c7deec7 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -26,6 +26,7 @@ #include "libavutil/bprint.h" #include "avformat.h" #include "os_support.h" +#include "libavcodec/packet_internal.h" #define MAX_URL_SIZE 4096 @@ -342,7 +343,7 @@ struct AVStreamInternal { /** * last packet in packet_buffer for this stream when muxing. */ - struct AVPacketList *last_in_packet_buffer; + struct PacketListEntry *last_in_packet_buffer; }; #ifdef __GNUC__ diff --git a/libavformat/mux.c b/libavformat/mux.c index d2a56d216b..d60bf2218b 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -832,7 +832,7 @@ int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, pkt = &this_pktl->pkt; if (st->internal->last_in_packet_buffer) { - next_point = &(st->internal->last_in_packet_buffer->next); + next_point = (AVPacketList **)&(st->internal->last_in_packet_buffer->next); } else { next_point = &s->internal->packet_buffer; } @@ -876,7 +876,8 @@ next_non_null: this_pktl->next = *next_point; - st->internal->last_in_packet_buffer = *next_point = this_pktl; + *next_point = this_pktl; + st->internal->last_in_packet_buffer = (PacketListEntry *)this_pktl; return 0; } @@ -951,7 +952,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 PacketListEntry *last = s->streams[i]->internal->last_in_packet_buffer; if (!last) continue; @@ -1000,7 +1001,7 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, if (!s->internal->packet_buffer) s->internal->packet_buffer_end = NULL; - if (st->internal->last_in_packet_buffer == pktl) + if (st->internal->last_in_packet_buffer == (PacketListEntry *)pktl) st->internal->last_in_packet_buffer = NULL; av_packet_unref(&pktl->pkt); @@ -1019,7 +1020,7 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, if (!s->internal->packet_buffer) s->internal->packet_buffer_end = NULL; - if (st->internal->last_in_packet_buffer == pktl) + if (st->internal->last_in_packet_buffer == (PacketListEntry *)pktl) st->internal->last_in_packet_buffer = NULL; av_freep(&pktl); diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c index d8678c9d25..c7f98ac257 100644 --- a/libavformat/mxfenc.c +++ b/libavformat/mxfenc.c @@ -3061,8 +3061,8 @@ static int mxf_interleave_get_packet(AVFormatContext *s, AVPacket *out, AVPacket if (!stream_count || pktl->pkt.stream_index == 0) break; // update last packet in packet buffer - if (s->streams[pktl->pkt.stream_index]->internal->last_in_packet_buffer != pktl) - s->streams[pktl->pkt.stream_index]->internal->last_in_packet_buffer = pktl; + if (s->streams[pktl->pkt.stream_index]->internal->last_in_packet_buffer != (PacketListEntry *)pktl) + s->streams[pktl->pkt.stream_index]->internal->last_in_packet_buffer = (PacketListEntry *)pktl; last = pktl; pktl = pktl->next; stream_count--; @@ -3087,7 +3087,7 @@ static int mxf_interleave_get_packet(AVFormatContext *s, AVPacket *out, AVPacket *out = pktl->pkt; av_log(s, AV_LOG_TRACE, "out st:%d dts:%"PRId64"\n", (*out).stream_index, (*out).dts); s->internal->packet_buffer = pktl->next; - if(s->streams[pktl->pkt.stream_index]->internal->last_in_packet_buffer == pktl) + if(s->streams[pktl->pkt.stream_index]->internal->last_in_packet_buffer == (PacketListEntry *)pktl) s->streams[pktl->pkt.stream_index]->internal->last_in_packet_buffer= NULL; if(!s->internal->packet_buffer) s->internal->packet_buffer_end= NULL; From patchwork Wed Nov 18 16:52:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 23711 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 2FD08449CB7 for ; Wed, 18 Nov 2020 18:59:02 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 165CA68B61C; Wed, 18 Nov 2020 18:59:02 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f193.google.com (mail-qt1-f193.google.com [209.85.160.193]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4A0F968B5BA for ; Wed, 18 Nov 2020 18:58:55 +0200 (EET) Received: by mail-qt1-f193.google.com with SMTP id p12so2108407qtp.7 for ; Wed, 18 Nov 2020 08:58: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=GLL4q1gyISXSKjMhnurxnPJ11py9FUOsHFQPppayiBc=; b=Y79MQ1Hpc/XR8NdQR6UBYG4Nmo++kmvXrxl7zNOPz7S/kla6I0nU0UMlraf2inH1YZ mmfX1Ud2XsB8GBYIU4buNIVEwS0QZ8SMtc0fqZ6AcdyUQHFibJx6hlN4GJSVlA+xnUyF eknmGtWf73ztl3xw/l6uoK3+bQaV8VKF7/XihglZh1YVEXMo6K9Efd/2SltzTHM6nM+u 6wXWR7P6M780jjN2URYqy/jJtkSP1ywy92tKquYe4+uIJpSyG3vPaE9qWCo2upKKNE82 Br4mZWfFrAm5loz+S6NWv6e0CfOBi4k2l+CsDgFsBYVK2uVNFiujVUqLYRANjecGPrN3 08Cg== 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=GLL4q1gyISXSKjMhnurxnPJ11py9FUOsHFQPppayiBc=; b=GH6deNvOT426fzQKpDoE68K7RP2lZzuvEQHXBISKwC0U+5m7GxP2PzFE1Dhc98DjVU rWN5srpllsvIm49F54gvKSdPi0Yak7wD06sRh8XfHirTXhS25q4wnMu8P9J0sJYtYfIs XpJ6Uth528ODcv56tuFmzf2sN5wBUoxai+igqAw1wsI1lZwqXT5AExcpHRfxkmN1kkW6 nF0VH/v19svS6IJy0uUFxGNAGxJEl1hXSGfx7osaqW79hWPDMvqovIFNVEMo/jZx5flU K31dXT9YchMng0gHZM/DJUGUwzO7b1eJXXoq4Eo+kBQxk9xN+nnQR3ylTj/UU3WB0pVB drxA== X-Gm-Message-State: AOAM530ubnNDgan/inQ06hTQ7OvKQnZxS8jQ0BKuAAuh7XL9gwb4FcJq ftJtu+IGXHuYv7vDnQLbNhKMXT0rbFSM9g== X-Google-Smtp-Source: ABdhPJy0AagmxVem+ndX72Of/QK9blhg1ABUvE7+fU6aQtvcSWYrL3ofenBSjuWmOK4co+BbRxLiKA== X-Received: by 2002:ac8:70cd:: with SMTP id g13mr5002793qtp.345.1605718392063; Wed, 18 Nov 2020 08:53:12 -0800 (PST) Received: from localhost.localdomain ([181.23.91.217]) by smtp.gmail.com with ESMTPSA id f14sm4863788qkk.89.2020.11.18.08.53.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2020 08:53:11 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 18 Nov 2020 13:52:32 -0300 Message-Id: <20201118165247.4130-4-jamrial@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201118165247.4130-1-jamrial@gmail.com> References: <20201118165247.4130-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 03/18] avcodec/avpacket: make avpriv_packet_* use PacketListEntry 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/avpacket.c | 18 +++++++++--------- libavcodec/internal.h | 5 +++-- libavcodec/packet_internal.h | 6 +++--- libavformat/aiffenc.c | 4 ++-- libavformat/flacenc.c | 2 +- libavformat/internal.h | 12 ++++++------ libavformat/matroskadec.c | 4 ++-- libavformat/mp3enc.c | 2 +- libavformat/mux.c | 16 ++++++++-------- libavformat/mxfenc.c | 12 ++++++------ libavformat/ttaenc.c | 2 +- libavformat/utils.c | 14 +++++++------- 12 files changed, 49 insertions(+), 48 deletions(-) diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c index e4ba403cf6..c12515cf05 100644 --- a/libavcodec/avpacket.c +++ b/libavcodec/avpacket.c @@ -726,13 +726,13 @@ FF_ENABLE_DEPRECATION_WARNINGS #endif } -int avpriv_packet_list_put(AVPacketList **packet_buffer, - AVPacketList **plast_pktl, +int avpriv_packet_list_put(PacketListEntry **packet_buffer, + PacketListEntry **plast_pktl, AVPacket *pkt, int (*copy)(AVPacket *dst, const AVPacket *src), int flags) { - AVPacketList *pktl = av_mallocz(sizeof(AVPacketList)); + PacketListEntry *pktl = av_mallocz(sizeof(PacketListEntry)); int ret; if (!pktl) @@ -763,11 +763,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(PacketListEntry **pkt_buffer, + PacketListEntry **pkt_buffer_end, AVPacket *pkt) { - AVPacketList *pktl; + PacketListEntry *pktl; if (!*pkt_buffer) return AVERROR(EAGAIN); pktl = *pkt_buffer; @@ -779,12 +779,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(PacketListEntry **pkt_buf, PacketListEntry **pkt_buf_end) { - AVPacketList *tmp = *pkt_buf; + PacketListEntry *tmp = *pkt_buf; while (tmp) { - AVPacketList *pktl = tmp; + PacketListEntry *pktl = tmp; tmp = pktl->next; av_packet_unref(&pktl->pkt); av_freep(&pktl); diff --git a/libavcodec/internal.h b/libavcodec/internal.h index 17defb9b50..c72cce869e 100644 --- a/libavcodec/internal.h +++ b/libavcodec/internal.h @@ -31,6 +31,7 @@ #include "libavutil/mathematics.h" #include "libavutil/pixfmt.h" #include "avcodec.h" +#include "packet_internal.h" #include "config.h" /** @@ -145,8 +146,8 @@ typedef struct AVCodecInternal { * for decoding. */ AVPacket *last_pkt_props; - AVPacketList *pkt_props; - AVPacketList *pkt_props_tail; + PacketListEntry *pkt_props; + PacketListEntry *pkt_props_tail; /** * temporary buffer used for encoders to store their bitstream diff --git a/libavcodec/packet_internal.h b/libavcodec/packet_internal.h index 9b9bef94f0..33c9513f16 100644 --- a/libavcodec/packet_internal.h +++ b/libavcodec/packet_internal.h @@ -41,7 +41,7 @@ typedef struct PacketListEntry { * @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(PacketListEntry **head, PacketListEntry **tail, AVPacket *pkt, int (*copy)(AVPacket *dst, const AVPacket *src), int flags); @@ -58,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(PacketListEntry **head, PacketListEntry **tail, AVPacket *pkt); /** @@ -67,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(PacketListEntry **head, PacketListEntry **tail); int ff_side_data_set_encoder_stats(AVPacket *pkt, int quality, int64_t *error, int error_count, int pict_type); diff --git a/libavformat/aiffenc.c b/libavformat/aiffenc.c index c4ffe9f6d0..7c28109814 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; + PacketListEntry *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; + PacketListEntry *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 6b8ce8d7ee..a24d3be85d 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; + PacketListEntry *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 c29c7deec7..d366bdc452 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -74,8 +74,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 PacketListEntry *packet_buffer; + struct PacketListEntry *packet_buffer_end; /* av_seek_frame() support */ int64_t data_offset; /**< offset of the first packet */ @@ -86,13 +86,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 PacketListEntry *raw_packet_buffer; + struct PacketListEntry *raw_packet_buffer_end; /** * Packets split by the parser get queued here. */ - struct AVPacketList *parse_queue; - struct AVPacketList *parse_queue_end; + struct PacketListEntry *parse_queue; + struct PacketListEntry *parse_queue_end; /** * Remaining size available for raw_packet_buffer, in bytes. */ diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 981e044263..0970e1d1ef 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -366,8 +366,8 @@ typedef struct MatroskaDemuxContext { int64_t segment_start; /* the packet queue */ - AVPacketList *queue; - AVPacketList *queue_end; + PacketListEntry *queue; + PacketListEntry *queue_end; int done; diff --git a/libavformat/mp3enc.c b/libavformat/mp3enc.c index 4f91c4f1c3..fddde33400 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; + PacketListEntry *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 d60bf2218b..cf52de5366 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -813,11 +813,11 @@ int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, int (*compare)(AVFormatContext *, const AVPacket *, const AVPacket *)) { int ret; - AVPacketList **next_point, *this_pktl; + PacketListEntry **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(PacketListEntry)); if (!this_pktl) { av_packet_unref(pkt); return AVERROR(ENOMEM); @@ -832,7 +832,7 @@ int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, pkt = &this_pktl->pkt; if (st->internal->last_in_packet_buffer) { - next_point = (AVPacketList **)&(st->internal->last_in_packet_buffer->next); + next_point = &(st->internal->last_in_packet_buffer->next); } else { next_point = &s->internal->packet_buffer; } @@ -877,7 +877,7 @@ next_non_null: this_pktl->next = *next_point; *next_point = this_pktl; - st->internal->last_in_packet_buffer = (PacketListEntry *)this_pktl; + st->internal->last_in_packet_buffer = this_pktl; return 0; } @@ -915,7 +915,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; + PacketListEntry *pktl; int stream_count = 0; int noninterleaved_count = 0; int i, ret; @@ -1001,7 +1001,7 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, if (!s->internal->packet_buffer) s->internal->packet_buffer_end = NULL; - if (st->internal->last_in_packet_buffer == (PacketListEntry *)pktl) + if (st->internal->last_in_packet_buffer == pktl) st->internal->last_in_packet_buffer = NULL; av_packet_unref(&pktl->pkt); @@ -1020,7 +1020,7 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, if (!s->internal->packet_buffer) s->internal->packet_buffer_end = NULL; - if (st->internal->last_in_packet_buffer == (PacketListEntry *)pktl) + if (st->internal->last_in_packet_buffer == pktl) st->internal->last_in_packet_buffer = NULL; av_freep(&pktl); @@ -1033,7 +1033,7 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, int ff_interleaved_peek(AVFormatContext *s, int stream, AVPacket *pkt, int add_offset) { - AVPacketList *pktl = s->internal->packet_buffer; + PacketListEntry *pktl = s->internal->packet_buffer; while (pktl) { if (pktl->pkt.stream_index == stream) { *pkt = pktl->pkt; diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c index c7f98ac257..8f2649c31f 100644 --- a/libavformat/mxfenc.c +++ b/libavformat/mxfenc.c @@ -3053,23 +3053,23 @@ 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; + PacketListEntry *pktl = s->internal->packet_buffer; if (s->nb_streams != stream_count) { - AVPacketList *last = NULL; + PacketListEntry *last = NULL; // find last packet in edit unit while (pktl) { if (!stream_count || pktl->pkt.stream_index == 0) break; // update last packet in packet buffer - if (s->streams[pktl->pkt.stream_index]->internal->last_in_packet_buffer != (PacketListEntry *)pktl) - s->streams[pktl->pkt.stream_index]->internal->last_in_packet_buffer = (PacketListEntry *)pktl; + if (s->streams[pktl->pkt.stream_index]->internal->last_in_packet_buffer != pktl) + s->streams[pktl->pkt.stream_index]->internal->last_in_packet_buffer = pktl; last = pktl; pktl = pktl->next; stream_count--; } // purge packet queue while (pktl) { - AVPacketList *next = pktl->next; + PacketListEntry *next = pktl->next; av_packet_unref(&pktl->pkt); av_freep(&pktl); pktl = next; @@ -3087,7 +3087,7 @@ static int mxf_interleave_get_packet(AVFormatContext *s, AVPacket *out, AVPacket *out = pktl->pkt; av_log(s, AV_LOG_TRACE, "out st:%d dts:%"PRId64"\n", (*out).stream_index, (*out).dts); s->internal->packet_buffer = pktl->next; - if(s->streams[pktl->pkt.stream_index]->internal->last_in_packet_buffer == (PacketListEntry *)pktl) + if(s->streams[pktl->pkt.stream_index]->internal->last_in_packet_buffer == pktl) s->streams[pktl->pkt.stream_index]->internal->last_in_packet_buffer= NULL; if(!s->internal->packet_buffer) s->internal->packet_buffer_end= NULL; diff --git a/libavformat/ttaenc.c b/libavformat/ttaenc.c index 92f5053d52..39d9034f68 100644 --- a/libavformat/ttaenc.c +++ b/libavformat/ttaenc.c @@ -30,7 +30,7 @@ typedef struct TTAMuxContext { AVIOContext *seek_table; - AVPacketList *queue, *queue_end; + PacketListEntry *queue, *queue_end; uint32_t nb_samples; int frame_size; int last_frame; diff --git a/libavformat/utils.c b/libavformat/utils.c index 0391e0da13..20bf723a55 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -799,7 +799,7 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt) av_init_packet(pkt); for (;;) { - AVPacketList *pktl = s->internal->raw_packet_buffer; + PacketListEntry *pktl = s->internal->raw_packet_buffer; const AVPacket *pkt1; if (pktl) { @@ -1007,7 +1007,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 PacketListEntry *get_next_pkt(AVFormatContext *s, AVStream *st, PacketListEntry *pktl) { if (pktl->next) return pktl->next; @@ -1063,7 +1063,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) + PacketListEntry *pkt_buffer) { AVStream *st = s->streams[stream_index]; int delay = st->internal->avctx->has_b_frames; @@ -1092,8 +1092,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; + PacketListEntry *pktl = s->internal->packet_buffer ? s->internal->packet_buffer : s->internal->parse_queue; + PacketListEntry *pktl_it; uint64_t shift; @@ -1143,7 +1143,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; + PacketListEntry *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) { @@ -1727,7 +1727,7 @@ int av_read_frame(AVFormatContext *s, AVPacket *pkt) } for (;;) { - AVPacketList *pktl = s->internal->packet_buffer; + PacketListEntry *pktl = s->internal->packet_buffer; if (pktl) { AVPacket *next_pkt = &pktl->pkt; From patchwork Wed Nov 18 16:52:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 23717 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 DA30F44BBEA for ; Wed, 18 Nov 2020 19:01:39 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BD7B768B60D; Wed, 18 Nov 2020 19:01:39 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f194.google.com (mail-qt1-f194.google.com [209.85.160.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1245E6881FE for ; Wed, 18 Nov 2020 19:01:38 +0200 (EET) Received: by mail-qt1-f194.google.com with SMTP id v11so2076462qtq.12 for ; Wed, 18 Nov 2020 09:01: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=UROlOu+LPzbGbxfBVoSIXYr2xYxrFKclT7cnpuyfuP0=; b=ICkzBh1CXrfoZspTDq1+wDl8OoWUmDTfN7fgBoFE4nJVoZKaFdyxDrNV+SjvVD/cbu 89hJYRfcqY6JpKnf2Z/umSdL1h3xcBQcX8sCG5CMyWh79JqHoRjX2zPnQD403WMTouAq ldsJJmPPIbbW9Os14QHSvmqoIXiAP3t4txmQ9eAAY9pRoeqOMUgCdY80H6j3KpKbozbF JMNB6KPB2c9pIGjsLD0k471wcqZUOgFnEnOTvSurBkvkHCKArOgQpCAbSfQOOz1CDKtf xYsKfXEQ4kNttiTW4PhhRighJqAXf0ctyaOKBgWlidjSWwRHi6qQ7Ih/7Pt1m/lHGbFS /fww== 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=UROlOu+LPzbGbxfBVoSIXYr2xYxrFKclT7cnpuyfuP0=; b=ob9FJiOTjNcmgzNfk/Mupi/n7tnTq5uZD9RPJSVv73YlV4lrO47pakAzxroaVDmFNM WeyeDju8zCQurI9VKPEHZ8AlC9WqKv8jiL0JJxorUNrbQcj93vISlfqza2j8uBYgfmXK /+v9GplVDBf2wGBYCurXvaNIz4WdOAa4PB3VPBGut3sjZrs5Dpokj47RxLLJE6KJhwpF D+/oXXkD67A5XL40aJGaZthadjYFI4lMkVDo+nNr/hMbN7SfmWFZpCesRoDEzddThh2E OJQdysDfZMPspcTRYcwsd1XcXE1Jj0TahWrH2YrbHX6NY8C8BI4wH/KEs0nP8wPqAfB1 gAfQ== X-Gm-Message-State: AOAM531ZpV64szGCm1gM3w3hHrZTD2JAJQy7J2YEVjlNAuHi7gFzdCrd 7E/hAnNcMpXPWFhpedp/PLrPPXNtOYulXw== X-Google-Smtp-Source: ABdhPJyT+dGGrm7m6IslcmZUVSXcVQ+zV0OQs5wwGPiTcvwtEWcY30fM260l7vpn503DXQgABjD+jw== X-Received: by 2002:a37:9dd8:: with SMTP id g207mr5594891qke.294.1605718394317; Wed, 18 Nov 2020 08:53:14 -0800 (PST) Received: from localhost.localdomain ([181.23.91.217]) by smtp.gmail.com with ESMTPSA id f14sm4863788qkk.89.2020.11.18.08.53.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2020 08:53:13 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 18 Nov 2020 13:52:33 -0300 Message-Id: <20201118165247.4130-5-jamrial@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201118165247.4130-1-jamrial@gmail.com> References: <20201118165247.4130-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 04/18] avcodec/avpacket: add a new public AVPacketList API 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" This implements a FIFO packet buffering API. All existing fields in the AVPacketList struct are deprecated, and will be removed eventually. After that, AVPacketList will become an opaque struct. Signed-off-by: James Almer --- The most important thing is getting the function signatures right. The internal implementation can always be changed since AVPacketList will not be publicly exposed. I've allowed the pkt parameter in av_packet_list_peek() to be NULL, in which case the function will behave like an is_empty() function of sorts. I've also added a flags parameter to put(), get() and peek() for future extensions. For example, we may want to make them append a packet at the beginning of the list, and return the one at the end. libavcodec/avpacket.c | 141 +++++++++++++++++++++++++++++++++++ libavcodec/packet.h | 88 +++++++++++++++++++++- libavcodec/packet_internal.h | 10 +++ libavcodec/version.h | 3 + 4 files changed, 240 insertions(+), 2 deletions(-) diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c index c12515cf05..c79200b63b 100644 --- a/libavcodec/avpacket.c +++ b/libavcodec/avpacket.c @@ -793,6 +793,147 @@ void avpriv_packet_list_free(PacketListEntry **pkt_buf, PacketListEntry **pkt_bu *pkt_buf_end = NULL; } +AVPacketList *av_packet_list_alloc(void) +{ +#if FF_API_PACKET_LIST + struct PacketList *pktl; +#else + AVPacketList *pktl; +#endif + pktl = av_mallocz(sizeof(*pktl)); + + if (!pktl) + return NULL; + + return (AVPacketList *)pktl; +} + +int av_packet_list_put(AVPacketList *list, AVPacket *pkt, + int (*copy)(AVPacket *dst, const AVPacket *src), + int flags) +{ + PacketListEntry *pktle = av_mallocz(sizeof(PacketListEntry)); +#if FF_API_PACKET_LIST + struct PacketList *pktl = (struct PacketList *)list; +#else + AVPacketList *pktl = list; +#endif + int ret; + + if (!pktle) + return AVERROR(ENOMEM); + + if (copy) { + ret = copy(&pktle->pkt, pkt); + if (ret < 0) { + av_free(pktle); + return ret; + } + } else { + ret = av_packet_make_refcounted(pkt); + if (ret < 0) { + av_free(pktle); + return ret; + } + av_packet_move_ref(&pktle->pkt, pkt); + } + + if (pktl->head) + pktl->tail->next = pktle; + else + pktl->head = pktle; + + /* Add the packet in the buffered packet list. */ + pktl->tail = pktle; + + return 0; +} + +int av_packet_list_get(AVPacketList *list, AVPacket *pkt, + int flags) +{ + PacketListEntry *pktle; +#if FF_API_PACKET_LIST + struct PacketList *pktl = (struct PacketList *)list; +#else + AVPacketList *pktl = list; +#endif + + if (!pktl->head) + return AVERROR(EAGAIN); + + pktle = pktl->head; + if (pkt) + *pkt = pktle->pkt; + else + av_packet_unref(&pktle->pkt); + pktl->head = pktle->next; + + if (!pktle->next) + pktl->tail = NULL; + + av_freep(&pktle); + + return 0; +} + +int av_packet_list_peek(AVPacketList *list, AVPacket *pkt, + int flags) +{ + PacketListEntry *pktle; +#if FF_API_PACKET_LIST + struct PacketList *pktl = (struct PacketList *)list; +#else + AVPacketList *pktl = list; +#endif + AVPacket tmp = { 0 }; + int ret; + + if (!pktl->head) + return AVERROR(EAGAIN); + + if (!pkt) + return 0; + + pktle = pktl->head; + ret = av_packet_ref(&tmp, &pktle->pkt); + if (ret < 0) + return ret; + + *pkt = tmp; + + return 0; +} + +void av_packet_list_flush(AVPacketList *list) +{ +#if FF_API_PACKET_LIST + struct PacketList *pktl = (struct PacketList *)list; +#else + AVPacketList *pktl = list; +#endif + + while (pktl->head) { + PacketListEntry *pktle = pktl->head; + pktl->head = pktle->next; + av_packet_unref(&pktle->pkt); + av_freep(&pktle); + } + + pktl->tail = NULL; +} + +void av_packet_list_free(AVPacketList **plist) +{ + AVPacketList *list = *plist; + + if (!list) + return; + + av_packet_list_flush(list); + av_freep(plist); +} + int ff_side_data_set_encoder_stats(AVPacket *pkt, int quality, int64_t *error, int error_count, int pict_type) { uint8_t *side_data; diff --git a/libavcodec/packet.h b/libavcodec/packet.h index b9d4c9c2c8..d3c8ba40b5 100644 --- a/libavcodec/packet.h +++ b/libavcodec/packet.h @@ -393,10 +393,94 @@ typedef struct AVPacket { #endif } AVPacket; -typedef struct AVPacketList { +typedef struct AVPacketList +#if FF_API_PACKET_LIST +{ + /** + * @deprecated This field is unused + */ + attribute_deprecated AVPacket pkt; + /** + * @deprecated This field is unused + */ + attribute_deprecated struct AVPacketList *next; -} AVPacketList; +} +#endif +AVPacketList; + +/** + * Allocate an AVPacketList struct. + * + * @note The allocated struct must be freed with av_packet_list_free() + * + * @return A freshly allocated AVPacketList on success, NULL otherwise. + */ +AVPacketList *av_packet_list_alloc(void); + +/** + * Append an AVPacket to an AVPacketList. + * + * @param ptkl The list where the packet should be appended. + * @param pkt The packet being appended. + * @param copy A callback to copy the contents of the packet to the list. + * May be null, in which case the packet's reference will be + * moved to the list. + * @param flags Currently unused. Must be set to 0. + * + * @return 0 on success, negative AVERROR value on failure. On failure, + * the packet and the list are unchanged. + */ +int av_packet_list_put(AVPacketList *list, AVPacket *pkt, + int (*copy)(AVPacket *dst, const AVPacket *src), + int flags); + +/** + * Remove the oldest AVPacket in an AVPacketList and return it. + * + * @param pktl The list where to fetch a packet from. + * @param pkt Pointer to an AVPacket struct. May be NULL, in which case + * the packet is freed after being removed from the list. + * @param flags Currently unused. Must be set to 0. + * + * @note pkt, if not NULL, will be overwritten completely on success. The + * caller owns the packet and must unref it by itself. + * + * @return 0 on success. AVERROR(EAGAIN) if the list was empty. + */ +int av_packet_list_get(AVPacketList *pktl, AVPacket *pkt, int flags); + +/** + * Create a new reference to the oldest AVPacket in an AVPacketList and + * return it. The list will remain unchanged. + * + * @param pktl The list where to fetch a packet from. + * @param pkt Pointer to an AVPacket struct. May be NULL, in which case + * nothing is returned. + * @param flags Currently unused. Must be set to 0. + * + * @note pkt, if not NULL, will be overwritten completely on success. The + * caller owns the packet and must unref it by itself. + * + * @return 0 on success. AVERROR(EAGAIN) if the list was empty. Another + AVERROR code on error. + */ +int av_packet_list_peek(AVPacketList *pktl, AVPacket *pkt, int flags); + +/** + * Empty an AVPacketList, freeing all the packets contained in it. + * + * @param pktl The AVPacketList to flush. + */ +void av_packet_list_flush(AVPacketList *pktl); + +/** + * Free a previously allocated AVPacketList struct, and everything in it. + * + * @param pktl Pointer to the AVPacketList to free. + */ +void av_packet_list_free(AVPacketList **pktl); #define AV_PKT_FLAG_KEY 0x0001 ///< The packet contains a keyframe #define AV_PKT_FLAG_CORRUPT 0x0002 ///< The packet content is corrupted diff --git a/libavcodec/packet_internal.h b/libavcodec/packet_internal.h index 33c9513f16..2774d75a7e 100644 --- a/libavcodec/packet_internal.h +++ b/libavcodec/packet_internal.h @@ -28,6 +28,16 @@ typedef struct PacketListEntry { struct PacketListEntry *next; } PacketListEntry; +#if FF_API_PACKET_LIST +struct PacketList { + AVPacketList dummy; +#else +struct AVPacketList { +#endif + PacketListEntry *head; + PacketListEntry *tail; +}; + /** * Append an AVPacket to the list. * diff --git a/libavcodec/version.h b/libavcodec/version.h index 1585d95777..191206500c 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -147,5 +147,8 @@ #ifndef FF_API_AVPRIV_PUT_BITS #define FF_API_AVPRIV_PUT_BITS (LIBAVCODEC_VERSION_MAJOR < 59) #endif +#ifndef FF_API_PACKET_LIST +#define FF_API_PACKET_LIST (LIBAVCODEC_VERSION_MAJOR < 60) +#endif #endif /* AVCODEC_VERSION_H */ From patchwork Wed Nov 18 16:52:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 23700 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 EC2B644B913 for ; Wed, 18 Nov 2020 18:53:23 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C10DA68B5D6; Wed, 18 Nov 2020 18:53:23 +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 C92C56805BE for ; Wed, 18 Nov 2020 18:53:17 +0200 (EET) Received: by mail-qk1-f178.google.com with SMTP id 199so2414702qkg.9 for ; Wed, 18 Nov 2020 08:53: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=LwRE02dZGBlcPFOhnEsPfllyRvMltHozYMAy78jx7RI=; b=Ncr+Age7OWjotgdfZUqS6T7OrD+rO8jQeFpYa0L2sY06bU2wx/oTMuRi4/up5PFpwh R0VcTVq+eDtb8uH2kK5U5nBRCmj8fij4E7hPOLIltnW2XYvCqTCWKpjs/l5yYWg91rJk 1HbV5auBmizW4JssooIrPcDktaNWlewXmitjmUKIp8TKQ0pr1a1BItMkC4+45MbT8UNg gN5Ifa/gAd38ZvcgimCcB5ScdMomxKc76MAbduFQEpAO000G6/IMRO9iG3EuGjX6v84Y MRdYkRHYZbl7YNeIcRRb7xfS3IyzHUEXvzhFfeB1kuZNl/mnw7n1wBE0sK0in+K0m9fu UCfw== 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=LwRE02dZGBlcPFOhnEsPfllyRvMltHozYMAy78jx7RI=; b=DDrOLtNAHbnD+/IDrGZmIrf6qrLJqbOydZKyGbb8ZVnY3mLTR+FjEN21g9c1jzVBIN GW9V4AHbbpbSnzfxXxVNufEbi+VtIC3lGTSfdvPtlZrcSFv8FMyWzr2i6Ei0MnHwp6tS 2Bdu9clCAGSEF2a0YFXk9brhH10ydbb4iEQO1+mcb3iT6xV1AMe0v8wYAmLtP9QR3yYR ObBqhguw14f8prJ270hWmbS4xgjI+VyxD2dMr5olX/PEbVMHMDdU/7jfss/t8rnFqbaX P+6qk94/XEB+2cMDcDYBzsB1fFsZr7xmLg3flPO9/5lEq3O9AD1leK35A6hx+mX7lnp9 J5dw== X-Gm-Message-State: AOAM530Gvw3KpPdSk4t1vFlB0a96MP1Yd1++tdEfoC/Ziembkdpe17KB ZVaM4xObLkZRH92N6EAOLVzEJtiOp6aiMQ== X-Google-Smtp-Source: ABdhPJwEOhJdKT+1XUsmkjBOc2AbVgpoNQNNMwX1NrVv41IBHoEDfzip5tAnsr6UgzWCS+KGMT1mkg== X-Received: by 2002:a37:b642:: with SMTP id g63mr5518101qkf.460.1605718395817; Wed, 18 Nov 2020 08:53:15 -0800 (PST) Received: from localhost.localdomain ([181.23.91.217]) by smtp.gmail.com with ESMTPSA id f14sm4863788qkk.89.2020.11.18.08.53.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2020 08:53:15 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 18 Nov 2020 13:52:34 -0300 Message-Id: <20201118165247.4130-6-jamrial@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201118165247.4130-1-jamrial@gmail.com> References: <20201118165247.4130-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 05/18] avcodec/decode: port to the new packet list API 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/decode.c | 20 ++++++++++---------- libavcodec/internal.h | 4 +--- libavcodec/utils.c | 11 ++++++----- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 5a1849f944..8a81280e7c 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -147,19 +147,21 @@ fail2: static int extract_packet_props(AVCodecInternal *avci, AVPacket *pkt) { +#if FF_API_PACKET_LIST + struct PacketList *pkt_props = (struct PacketList *)avci->pkt_props; +#else + AVPacketList *pkt_props = avci->pkt_props; +#endif int ret = 0; - ret = avpriv_packet_list_put(&avci->pkt_props, &avci->pkt_props_tail, pkt, - av_packet_copy_props, 0); + ret = av_packet_list_put(avci->pkt_props, pkt, av_packet_copy_props, 0); if (ret < 0) return ret; - avci->pkt_props_tail->pkt.size = pkt->size; // HACK: Needed for ff_decode_frame_props(). - avci->pkt_props_tail->pkt.data = (void*)1; // HACK: Needed for IS_EMPTY(). + pkt_props->tail->pkt.size = pkt->size; // HACK: Needed for ff_decode_frame_props(). + pkt_props->tail->pkt.data = (void*)1; // HACK: Needed for IS_EMPTY(). if (IS_EMPTY(avci->last_pkt_props)) { - ret = avpriv_packet_list_get(&avci->pkt_props, - &avci->pkt_props_tail, - avci->last_pkt_props); + ret = av_packet_list_get(avci->pkt_props, avci->last_pkt_props, 0); av_assert0(ret != AVERROR(EAGAIN)); } return ret; @@ -1722,9 +1724,7 @@ int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame) }; if (IS_EMPTY(pkt)) - avpriv_packet_list_get(&avctx->internal->pkt_props, - &avctx->internal->pkt_props_tail, - pkt); + av_packet_list_get(avctx->internal->pkt_props, pkt, 0); if (pkt) { frame->pts = pkt->pts; diff --git a/libavcodec/internal.h b/libavcodec/internal.h index c72cce869e..e7d1d9ccb5 100644 --- a/libavcodec/internal.h +++ b/libavcodec/internal.h @@ -31,7 +31,6 @@ #include "libavutil/mathematics.h" #include "libavutil/pixfmt.h" #include "avcodec.h" -#include "packet_internal.h" #include "config.h" /** @@ -146,8 +145,7 @@ typedef struct AVCodecInternal { * for decoding. */ AVPacket *last_pkt_props; - PacketListEntry *pkt_props; - PacketListEntry *pkt_props_tail; + AVPacketList *pkt_props; /** * temporary buffer used for encoders to store their bitstream diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 9b074e2dda..42e6850169 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -593,10 +593,12 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code avci->es.in_frame = av_frame_alloc(); avci->ds.in_pkt = av_packet_alloc(); avci->last_pkt_props = av_packet_alloc(); + avci->pkt_props = av_packet_list_alloc(); if (!avci->compat_decode_frame || !avci->compat_encode_packet || !avci->buffer_frame || !avci->buffer_pkt || !avci->es.in_frame || !avci->ds.in_pkt || - !avci->to_free || !avci->last_pkt_props) { + !avci->to_free || !avci->last_pkt_props || + !avci->pkt_props) { ret = AVERROR(ENOMEM); goto free_and_end; } @@ -1054,6 +1056,7 @@ FF_ENABLE_DEPRECATION_WARNINGS av_packet_free(&avci->compat_encode_packet); av_packet_free(&avci->buffer_pkt); av_packet_free(&avci->last_pkt_props); + av_packet_list_free(&avci->pkt_props); av_packet_free(&avci->ds.in_pkt); av_frame_free(&avci->es.in_frame); @@ -1094,8 +1097,7 @@ void avcodec_flush_buffers(AVCodecContext *avctx) av_packet_unref(avci->buffer_pkt); av_packet_unref(avci->last_pkt_props); - avpriv_packet_list_free(&avci->pkt_props, - &avci->pkt_props_tail); + av_packet_list_flush(avci->pkt_props); av_frame_unref(avci->es.in_frame); av_packet_unref(avci->ds.in_pkt); @@ -1158,8 +1160,7 @@ av_cold int avcodec_close(AVCodecContext *avctx) av_packet_free(&avctx->internal->compat_encode_packet); av_packet_free(&avctx->internal->buffer_pkt); av_packet_free(&avctx->internal->last_pkt_props); - avpriv_packet_list_free(&avctx->internal->pkt_props, - &avctx->internal->pkt_props_tail); + av_packet_list_free(&avctx->internal->pkt_props); av_packet_free(&avctx->internal->ds.in_pkt); av_frame_free(&avctx->internal->es.in_frame); From patchwork Wed Nov 18 16:52:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 23712 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 28DF644A205 for ; Wed, 18 Nov 2020 18:59:12 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0C02468B662; Wed, 18 Nov 2020 18:59:12 +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 DE3C968B5BA for ; Wed, 18 Nov 2020 18:59:05 +0200 (EET) Received: by mail-qk1-f182.google.com with SMTP id n132so2490912qke.1 for ; Wed, 18 Nov 2020 08:59: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=q/2CgIKhnN9QMSwB0xugrQzinG9sKNr7DFDj593abdg=; b=u4s7h9tcXgLTd8a+mBSrJ2xi0SqJQmHO8cwYzJW3aIcIPQn0JyS0+GEdSduRmCE1fz +Cp+I3j6wga/jcDC9Va4SgruXHs1Tnjm5ZGiVpRiHRv6pzMiGfgJubMb4hVzX9L0AXVi zj24cWnDcOUJEQv5zfiMLwSi+yesUyDWjmCS+E/xYJiyFnk7syjN5gxWPIvdzGRJt8km Edkn4LoEHYsMANILteqUIxC068KcEvK6b8TPCwhhFIUyby+RTKpz7xgsGZf7ya0ryf6F qulXxnXvGiUhpfNPGhCi15EFQh70KZ5Q8yfMlf7GRWxr7/pOt7+b1LsA920u3FjnQYo3 hO9Q== 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=q/2CgIKhnN9QMSwB0xugrQzinG9sKNr7DFDj593abdg=; b=eN95HKidvFbHhLpipgvXrFtaXkrwEN/SXgyh8pedNinWMBJ7oAY14hMW4Fr6UfgYOO +mwmzeRUHWzwDFOEIKEDtgtUs9yxqONme/rC+lSnmbbBfB3IoXjyhRlXK9jrSIPWyX3P CSLwgyNFU0qQ/r29Y7BtyeNU86UAvfTxegXSswzzmxumo82UdaKXg19fIBD186YPYjjg mChwt4h9kj7ncDpOUyrw+vjwNwcIQq2qrOuZM5vNz5N96s9BwqH3ZIZCPhizFTS8GPjZ hUBnFHqOtzgz3AKPvRS4fJP/OycwsKM79R/PF/QGEW2rZayLeYfNTvnAFOFfe7SQge0j h7Yw== X-Gm-Message-State: AOAM5311nHxDtxTik8g2doFOm3WwSxed4fL07iYsmFqaTe6GTHubLvWt G43Gd4v/bCJItFIPXKojAC6eZRb200QO7Q== X-Google-Smtp-Source: ABdhPJwZxu/9gdMmOGdcjLkcPjxADXKKNu3E7pV0/44x2SHF76GBB4/DydVm/q8+8hiDigCxx9O5eg== X-Received: by 2002:a37:c82:: with SMTP id 124mr5522897qkm.360.1605718397812; Wed, 18 Nov 2020 08:53:17 -0800 (PST) Received: from localhost.localdomain ([181.23.91.217]) by smtp.gmail.com with ESMTPSA id f14sm4863788qkk.89.2020.11.18.08.53.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2020 08:53:17 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 18 Nov 2020 13:52:35 -0300 Message-Id: <20201118165247.4130-7-jamrial@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201118165247.4130-1-jamrial@gmail.com> References: <20201118165247.4130-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 06/18] avformat: port AVFormatInternal->packet_buffer to the new packet list API 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 | 3 +- libavformat/mux.c | 53 +++++++++++++++++++----------- libavformat/mxfenc.c | 19 +++++++---- libavformat/options.c | 6 ++++ libavformat/utils.c | 74 ++++++++++++++++++++++++++++++------------ 5 files changed, 107 insertions(+), 48 deletions(-) diff --git a/libavformat/internal.h b/libavformat/internal.h index d366bdc452..3182409dfb 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -74,8 +74,7 @@ struct AVFormatInternal { * not decoded, for example to get the codec parameters in MPEG * streams. */ - struct PacketListEntry *packet_buffer; - struct PacketListEntry *packet_buffer_end; + struct AVPacketList *packet_buffer; /* av_seek_frame() support */ int64_t data_offset; /**< offset of the first packet */ diff --git a/libavformat/mux.c b/libavformat/mux.c index cf52de5366..6991f81f9f 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -816,6 +816,11 @@ int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, PacketListEntry **next_point, *this_pktl; AVStream *st = s->streams[pkt->stream_index]; int chunked = s->max_chunk_size || s->max_chunk_duration; +#if FF_API_PACKET_LIST + struct PacketList *packet_buffer = (struct PacketList *)s->internal->packet_buffer; +#else + AVPacketList *packet_buffer = s->internal->packet_buffer; +#endif this_pktl = av_malloc(sizeof(PacketListEntry)); if (!this_pktl) { @@ -834,7 +839,7 @@ int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, if (st->internal->last_in_packet_buffer) { next_point = &(st->internal->last_in_packet_buffer->next); } else { - next_point = &s->internal->packet_buffer; + next_point = &packet_buffer->head; } if (chunked) { @@ -858,7 +863,7 @@ int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, if (chunked && !(pkt->flags & CHUNK_START)) goto next_non_null; - if (compare(s, &s->internal->packet_buffer_end->pkt, pkt)) { + if (compare(s, &packet_buffer->tail->pkt, pkt)) { while ( *next_point && ((chunked && !((*next_point)->pkt.flags&CHUNK_START)) || !compare(s, &(*next_point)->pkt, pkt))) @@ -866,12 +871,12 @@ int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, if (*next_point) goto next_non_null; } else { - next_point = &(s->internal->packet_buffer_end->next); + next_point = &(packet_buffer->tail->next); } } av_assert1(!*next_point); - s->internal->packet_buffer_end = this_pktl; + packet_buffer->tail = this_pktl; next_non_null: this_pktl->next = *next_point; @@ -920,6 +925,11 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, int noninterleaved_count = 0; int i, ret; int eof = flush; +#if FF_API_PACKET_LIST + struct PacketList *packet_buffer = (struct PacketList *)s->internal->packet_buffer; +#else + AVPacketList *packet_buffer = s->internal->packet_buffer; +#endif if (pkt) { if ((ret = ff_interleave_add_packet(s, pkt, interleave_compare_dts)) < 0) @@ -940,11 +950,11 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, flush = 1; if (s->max_interleave_delta > 0 && - s->internal->packet_buffer && + packet_buffer->head && !flush && s->internal->nb_interleaved_streams == stream_count+noninterleaved_count ) { - AVPacket *top_pkt = &s->internal->packet_buffer->pkt; + AVPacket *top_pkt = &packet_buffer->head->pkt; int64_t delta_dts = INT64_MIN; int64_t top_dts = av_rescale_q(top_pkt->dts, s->streams[top_pkt->stream_index]->time_base, @@ -972,11 +982,11 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, } } - if (s->internal->packet_buffer && + if (packet_buffer->head && eof && (s->flags & AVFMT_FLAG_SHORTEST) && s->internal->shortest_end == AV_NOPTS_VALUE) { - AVPacket *top_pkt = &s->internal->packet_buffer->pkt; + AVPacket *top_pkt = &packet_buffer->head->pkt; s->internal->shortest_end = av_rescale_q(top_pkt->dts, s->streams[top_pkt->stream_index]->time_base, @@ -984,8 +994,8 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, } if (s->internal->shortest_end != AV_NOPTS_VALUE) { - while (s->internal->packet_buffer) { - AVPacket *top_pkt = &s->internal->packet_buffer->pkt; + while (packet_buffer->head) { + AVPacket *top_pkt = &packet_buffer->head->pkt; AVStream *st; int64_t top_dts = av_rescale_q(top_pkt->dts, s->streams[top_pkt->stream_index]->time_base, @@ -994,12 +1004,12 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, if (s->internal->shortest_end + 1 >= top_dts) break; - pktl = s->internal->packet_buffer; + pktl = packet_buffer->head; st = s->streams[pktl->pkt.stream_index]; - s->internal->packet_buffer = pktl->next; - if (!s->internal->packet_buffer) - s->internal->packet_buffer_end = NULL; + packet_buffer->head = pktl->next; + if (!packet_buffer->head) + packet_buffer->tail = NULL; if (st->internal->last_in_packet_buffer == pktl) st->internal->last_in_packet_buffer = NULL; @@ -1012,13 +1022,13 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, if (stream_count && flush) { AVStream *st; - pktl = s->internal->packet_buffer; + pktl = packet_buffer->head; *out = pktl->pkt; st = s->streams[out->stream_index]; - s->internal->packet_buffer = pktl->next; - if (!s->internal->packet_buffer) - s->internal->packet_buffer_end = NULL; + packet_buffer->head = pktl->next; + if (!packet_buffer->head) + packet_buffer->tail = NULL; if (st->internal->last_in_packet_buffer == pktl) st->internal->last_in_packet_buffer = NULL; @@ -1033,7 +1043,12 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, int ff_interleaved_peek(AVFormatContext *s, int stream, AVPacket *pkt, int add_offset) { - PacketListEntry *pktl = s->internal->packet_buffer; +#if FF_API_PACKET_LIST + struct PacketList *packet_buffer = (struct PacketList *)s->internal->packet_buffer; +#else + AVPacketList *packet_buffer = s->internal->packet_buffer; +#endif + PacketListEntry *pktl = packet_buffer->head; while (pktl) { if (pktl->pkt.stream_index == stream) { *pkt = pktl->pkt; diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c index 8f2649c31f..55a53af5e8 100644 --- a/libavformat/mxfenc.c +++ b/libavformat/mxfenc.c @@ -3053,7 +3053,12 @@ 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)) { - PacketListEntry *pktl = s->internal->packet_buffer; +#if FF_API_PACKET_LIST + struct PacketList *packet_buffer = (struct PacketList *)s->internal->packet_buffer; +#else + AVPacketList *packet_buffer = s->internal->packet_buffer; +#endif + PacketListEntry *pktl = packet_buffer->head; if (s->nb_streams != stream_count) { PacketListEntry *last = NULL; // find last packet in edit unit @@ -3077,20 +3082,20 @@ static int mxf_interleave_get_packet(AVFormatContext *s, AVPacket *out, AVPacket if (last) last->next = NULL; else { - s->internal->packet_buffer = NULL; - s->internal->packet_buffer_end= NULL; + packet_buffer->head = NULL; + packet_buffer->tail= NULL; goto out; } - pktl = s->internal->packet_buffer; + pktl = packet_buffer->head; } *out = pktl->pkt; av_log(s, AV_LOG_TRACE, "out st:%d dts:%"PRId64"\n", (*out).stream_index, (*out).dts); - s->internal->packet_buffer = pktl->next; + packet_buffer->head = pktl->next; if(s->streams[pktl->pkt.stream_index]->internal->last_in_packet_buffer == pktl) s->streams[pktl->pkt.stream_index]->internal->last_in_packet_buffer= NULL; - if(!s->internal->packet_buffer) - s->internal->packet_buffer_end= NULL; + if(!packet_buffer->head) + packet_buffer->tail = NULL; av_freep(&pktl); return 1; } else { diff --git a/libavformat/options.c b/libavformat/options.c index 59e0389815..9fe1500cee 100644 --- a/libavformat/options.c +++ b/libavformat/options.c @@ -220,6 +220,12 @@ AVFormatContext *avformat_alloc_context(void) av_free(ic); return NULL; } + internal->packet_buffer = av_packet_list_alloc(); + if (!internal->packet_buffer) { + 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 20bf723a55..88ce64496d 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -1009,9 +1009,15 @@ static int has_decode_delay_been_guessed(AVStream *st) static PacketListEntry *get_next_pkt(AVFormatContext *s, AVStream *st, PacketListEntry *pktl) { +#if FF_API_PACKET_LIST + struct PacketList *packet_buffer = (struct PacketList *)s->internal->packet_buffer; +#else + AVPacketList *packet_buffer = s->internal->packet_buffer; +#endif + if (pktl->next) return pktl->next; - if (pktl == s->internal->packet_buffer_end) + if (pktl == packet_buffer->tail) return s->internal->parse_queue; return NULL; } @@ -1092,7 +1098,14 @@ static void update_initial_timestamps(AVFormatContext *s, int stream_index, int64_t dts, int64_t pts, AVPacket *pkt) { AVStream *st = s->streams[stream_index]; - PacketListEntry *pktl = s->internal->packet_buffer ? s->internal->packet_buffer : s->internal->parse_queue; +#if FF_API_PACKET_LIST + struct PacketList *packet_buffer = (struct PacketList *)s->internal->packet_buffer; +#else + AVPacketList *packet_buffer = s->internal->packet_buffer; +#endif + PacketListEntry *pktl = packet_buffer->head ? + packet_buffer->head : + s->internal->parse_queue; PacketListEntry *pktl_it; uint64_t shift; @@ -1143,7 +1156,14 @@ 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) { - PacketListEntry *pktl = s->internal->packet_buffer ? s->internal->packet_buffer : s->internal->parse_queue; +#if FF_API_PACKET_LIST + struct PacketList *packet_buffer = (struct PacketList *)s->internal->packet_buffer; +#else + AVPacketList *packet_buffer = s->internal->packet_buffer; +#endif + PacketListEntry *pktl = packet_buffer->head ? + packet_buffer->head : + s->internal->parse_queue; int64_t cur_dts = RELATIVE_TS_BASE; if (st->first_dts != AV_NOPTS_VALUE) { @@ -1169,7 +1189,9 @@ static void update_initial_durations(AVFormatContext *s, AVStream *st, av_log(s, AV_LOG_DEBUG, "first_dts %s but no packet with dts in the queue\n", av_ts2str(st->first_dts)); return; } - pktl = s->internal->packet_buffer ? s->internal->packet_buffer : s->internal->parse_queue; + pktl = packet_buffer->head ? + packet_buffer->head : + s->internal->parse_queue; st->first_dts = cur_dts; } else if (st->cur_dts != RELATIVE_TS_BASE) return; @@ -1204,6 +1226,11 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st, AVRational duration; int onein_oneout = st->codecpar->codec_id != AV_CODEC_ID_H264 && st->codecpar->codec_id != AV_CODEC_ID_HEVC; +#if FF_API_PACKET_LIST + struct PacketList *packet_buffer = (struct PacketList *)s->internal->packet_buffer; +#else + AVPacketList *packet_buffer = s->internal->packet_buffer; +#endif if (s->flags & AVFMT_FLAG_NOFILLIN) return; @@ -1281,7 +1308,7 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st, } } - if (pkt->duration > 0 && (s->internal->packet_buffer || s->internal->parse_queue)) + if (pkt->duration > 0 && (packet_buffer->head || s->internal->parse_queue)) update_initial_durations(s, st, pkt->stream_index, pkt->duration); /* Correct timestamps with byte offset if demuxers only have timestamps @@ -1715,11 +1742,15 @@ int av_read_frame(AVFormatContext *s, AVPacket *pkt) int eof = 0; int ret; AVStream *st; +#if FF_API_PACKET_LIST + struct PacketList *packet_buffer = (struct PacketList *)s->internal->packet_buffer; +#else + AVPacketList *packet_buffer = s->internal->packet_buffer; +#endif if (!genpts) { - ret = s->internal->packet_buffer - ? avpriv_packet_list_get(&s->internal->packet_buffer, - &s->internal->packet_buffer_end, pkt) + ret = packet_buffer->head + ? av_packet_list_get(s->internal->packet_buffer, pkt, 0) : read_frame_internal(s, pkt); if (ret < 0) return ret; @@ -1727,7 +1758,7 @@ int av_read_frame(AVFormatContext *s, AVPacket *pkt) } for (;;) { - PacketListEntry *pktl = s->internal->packet_buffer; + PacketListEntry *pktl = packet_buffer->head; if (pktl) { AVPacket *next_pkt = &pktl->pkt; @@ -1760,15 +1791,14 @@ int av_read_frame(AVFormatContext *s, AVPacket *pkt) // 3. the packets for this stream at the end of the files had valid dts. next_pkt->pts = last_dts + next_pkt->duration; } - pktl = s->internal->packet_buffer; + pktl = packet_buffer->head; } /* read packet from packet buffer, if there is data */ st = s->streams[next_pkt->stream_index]; if (!(next_pkt->pts == AV_NOPTS_VALUE && st->discard < AVDISCARD_ALL && next_pkt->dts != AV_NOPTS_VALUE && !eof)) { - ret = avpriv_packet_list_get(&s->internal->packet_buffer, - &s->internal->packet_buffer_end, pkt); + ret = av_packet_list_get(s->internal->packet_buffer, pkt, 0); goto return_packet; } } @@ -1782,8 +1812,7 @@ int av_read_frame(AVFormatContext *s, AVPacket *pkt) return ret; } - ret = avpriv_packet_list_put(&s->internal->packet_buffer, - &s->internal->packet_buffer_end, + ret = av_packet_list_put(s->internal->packet_buffer, pkt, NULL, 0); if (ret < 0) { av_packet_unref(pkt); @@ -1813,7 +1842,7 @@ static void flush_packet_queue(AVFormatContext *s) if (!s->internal) return; avpriv_packet_list_free(&s->internal->parse_queue, &s->internal->parse_queue_end); - avpriv_packet_list_free(&s->internal->packet_buffer, &s->internal->packet_buffer_end); + av_packet_list_flush(s->internal->packet_buffer); avpriv_packet_list_free(&s->internal->raw_packet_buffer, &s->internal->raw_packet_buffer_end); s->internal->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE; @@ -3581,6 +3610,11 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) int64_t probesize = ic->probesize; int eof_reached = 0; int *missing_streams = av_opt_ptr(ic->iformat->priv_class, ic->priv_data, "missing_streams"); +#if FF_API_PACKET_LIST + struct PacketList *packet_buffer = (struct PacketList *)ic->internal->packet_buffer; +#else + AVPacketList *packet_buffer = ic->internal->packet_buffer; +#endif flush_codecs = probesize > 0; @@ -3784,13 +3818,12 @@ FF_ENABLE_DEPRECATION_WARNINGS } if (!(ic->flags & AVFMT_FLAG_NOBUFFER)) { - ret = avpriv_packet_list_put(&ic->internal->packet_buffer, - &ic->internal->packet_buffer_end, + ret = av_packet_list_put(ic->internal->packet_buffer, &pkt1, NULL, 0); if (ret < 0) goto unref_then_goto_end; - pkt = &ic->internal->packet_buffer_end->pkt; + pkt = &packet_buffer->tail->pkt; } else { pkt = &pkt1; } @@ -3933,8 +3966,8 @@ FF_ENABLE_DEPRECATION_WARNINGS // EOF already reached while reading the stream above. // So continue with reoordering DTS with whatever delay we have. - if (ic->internal->packet_buffer && !has_decode_delay_been_guessed(st)) { - update_dts_from_pts(ic, stream_index, ic->internal->packet_buffer); + if (packet_buffer->head && !has_decode_delay_been_guessed(st)) { + update_dts_from_pts(ic, stream_index, packet_buffer->head); } } } @@ -4437,6 +4470,7 @@ void avformat_free_context(AVFormatContext *s) av_dict_free(&s->internal->id3v2_meta); av_freep(&s->streams); flush_packet_queue(s); + av_packet_list_free(&s->internal->packet_buffer); av_freep(&s->internal); av_freep(&s->url); av_free(s); From patchwork Wed Nov 18 16:52:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 23713 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 5F7C344A205 for ; Wed, 18 Nov 2020 18:59:29 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4C64268B65F; Wed, 18 Nov 2020 18:59:29 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f193.google.com (mail-qk1-f193.google.com [209.85.222.193]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7923168B664 for ; Wed, 18 Nov 2020 18:59:27 +0200 (EET) Received: by mail-qk1-f193.google.com with SMTP id 199so2437691qkg.9 for ; Wed, 18 Nov 2020 08:59:27 -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=34ax9eFbfLPz+WB15z89Us2pjyTNO1OC7kH5ugsNg3Y=; b=ZHpODfhEPhVMZs41rOVCCpRMVIoCHPPReLFIyXXXiWV4Y+v/JWIfgQYsO+/rZtRxhB kFMMGAuTFri6p3qBPi1FjP5IQ5/kzzRTo7qVfd5TwVgKpWp916EJshRXZ8fpba31pzh0 kUnfSi5uRAFgoTyvakUphTp3NPcF2jsm66tcFUfNh2qIftz7WLt+/ZhJPXANdtvyrEDV fKLujIxrle+I1Zo/dhYOmieY+V7o6cBi319/QyCVCTV617jXgw95qdIW4Z6rYFMkBDfL 4r2eJSLBH8aIik983apz0oU6wE25YM4uDPTHZCZl6qpwVoSRu7op7uVgELvuFUM3xfus CX1g== 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=34ax9eFbfLPz+WB15z89Us2pjyTNO1OC7kH5ugsNg3Y=; b=c3w4GbJVzDYBJlQ09nb0JCACAtfIrHZtsHLbStlIYqpZ2rLQE0/WIa9X6Q3EpUSIwf JXurM356kFZ7Izwrki5vrWrsjHe9goGQBwKFXDZ1faW79bOcRxUvpHgNfsRrjTzGxGb/ ydTs2/3/cunx7y8LCknvEVBLy+LpkvFUMsS/nglIcR+HRUYjy5k1U1Zh00GeFUypXmUE 65w55NK3p6KgvSk8NHDxKvzzjFffex71T+Gpp8dLZ/b+dCk9VHkDVJHAlnuasgPEXKgy GzeIoYusbOaH1jTlE31V++sN1WjoPm9wpwQQNt9J8miCROtgqJlqqpAqRfUchTfox0MD EVcQ== X-Gm-Message-State: AOAM531TZgEWomZWivc9AIk6Lh0tKQAttPyRJ/81AmzW3daAiHhdRkcN 5luMkg38pw0jIZx1n6374mLUOikwhgeo2g== X-Google-Smtp-Source: ABdhPJwJbyUfBoqN5yEq584Nfe7lN5Oul+3ElfVjyfOfx970bxPtq9g4cMPlwYUnxiCdsMLZIokDWQ== X-Received: by 2002:a37:415:: with SMTP id 21mr5786150qke.42.1605718399399; Wed, 18 Nov 2020 08:53:19 -0800 (PST) Received: from localhost.localdomain ([181.23.91.217]) by smtp.gmail.com with ESMTPSA id f14sm4863788qkk.89.2020.11.18.08.53.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2020 08:53:18 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 18 Nov 2020 13:52:36 -0300 Message-Id: <20201118165247.4130-8-jamrial@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201118165247.4130-1-jamrial@gmail.com> References: <20201118165247.4130-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 07/18] avformat: port AVFormatInternal->raw_packet_buffer to the new packet list API 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 | 3 +-- libavformat/options.c | 6 +++++- libavformat/utils.c | 21 ++++++++++++--------- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/libavformat/internal.h b/libavformat/internal.h index 3182409dfb..a0649956e8 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -85,8 +85,7 @@ struct AVFormatInternal { * be identified, as parsing cannot be done without knowing the * codec. */ - struct PacketListEntry *raw_packet_buffer; - struct PacketListEntry *raw_packet_buffer_end; + struct AVPacketList *raw_packet_buffer; /** * Packets split by the parser get queued here. */ diff --git a/libavformat/options.c b/libavformat/options.c index 9fe1500cee..ee7a533aa0 100644 --- a/libavformat/options.c +++ b/libavformat/options.c @@ -221,7 +221,11 @@ AVFormatContext *avformat_alloc_context(void) return NULL; } internal->packet_buffer = av_packet_list_alloc(); - if (!internal->packet_buffer) { + internal->raw_packet_buffer = av_packet_list_alloc(); + if (!internal->packet_buffer || + !internal->raw_packet_buffer) { + av_packet_list_free(&internal->packet_buffer); + av_packet_list_free(&internal->raw_packet_buffer); av_free(internal); av_free(ic); return NULL; diff --git a/libavformat/utils.c b/libavformat/utils.c index 88ce64496d..02c0ead44b 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -452,8 +452,7 @@ int avformat_queue_attached_pictures(AVFormatContext *s) continue; } - ret = avpriv_packet_list_put(&s->internal->raw_packet_buffer, - &s->internal->raw_packet_buffer_end, + ret = av_packet_list_put(s->internal->raw_packet_buffer, &s->streams[i]->attached_pic, av_packet_ref, 0); if (ret < 0) @@ -793,13 +792,18 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt) { int ret, i, err; AVStream *st; +#if FF_API_PACKET_LIST + struct PacketList *raw_packet_buffer = (struct PacketList *)s->internal->raw_packet_buffer; +#else + AVPacketList *raw_packet_buffer = s->internal->raw_packet_buffer; +#endif pkt->data = NULL; pkt->size = 0; av_init_packet(pkt); for (;;) { - PacketListEntry *pktl = s->internal->raw_packet_buffer; + PacketListEntry *pktl = raw_packet_buffer->head; const AVPacket *pkt1; if (pktl) { @@ -808,8 +812,7 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt) if ((err = probe_codec(s, st, NULL)) < 0) return err; if (st->internal->request_probe <= 0) { - avpriv_packet_list_get(&s->internal->raw_packet_buffer, - &s->internal->raw_packet_buffer_end, pkt); + av_packet_list_get(s->internal->raw_packet_buffer, pkt, 0); s->internal->raw_packet_buffer_remaining_size += pkt->size; return 0; } @@ -881,14 +884,13 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt) if (!pktl && st->internal->request_probe <= 0) return ret; - err = avpriv_packet_list_put(&s->internal->raw_packet_buffer, - &s->internal->raw_packet_buffer_end, + err = av_packet_list_put(s->internal->raw_packet_buffer, pkt, NULL, 0); if (err < 0) { av_packet_unref(pkt); return err; } - pkt1 = &s->internal->raw_packet_buffer_end->pkt; + pkt1 = &raw_packet_buffer->tail->pkt; s->internal->raw_packet_buffer_remaining_size -= pkt1->size; if ((err = probe_codec(s, st, pkt1)) < 0) @@ -1843,7 +1845,7 @@ static void flush_packet_queue(AVFormatContext *s) return; avpriv_packet_list_free(&s->internal->parse_queue, &s->internal->parse_queue_end); av_packet_list_flush(s->internal->packet_buffer); - avpriv_packet_list_free(&s->internal->raw_packet_buffer, &s->internal->raw_packet_buffer_end); + av_packet_list_flush(s->internal->raw_packet_buffer); s->internal->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE; } @@ -4471,6 +4473,7 @@ void avformat_free_context(AVFormatContext *s) av_freep(&s->streams); flush_packet_queue(s); av_packet_list_free(&s->internal->packet_buffer); + av_packet_list_free(&s->internal->raw_packet_buffer); av_freep(&s->internal); av_freep(&s->url); av_free(s); From patchwork Wed Nov 18 16:52:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 23709 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 26047449CB7 for ; Wed, 18 Nov 2020 18:58:54 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E999168B5F8; Wed, 18 Nov 2020 18:58:53 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f193.google.com (mail-qk1-f193.google.com [209.85.222.193]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A4EE768807B for ; Wed, 18 Nov 2020 18:58:47 +0200 (EET) Received: by mail-qk1-f193.google.com with SMTP id d9so2436451qke.8 for ; Wed, 18 Nov 2020 08:58: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=gAvGsgZZ1dHhUV4EaGaw7fccXkxAdXEnmLCyLcUfy6I=; b=emSXSvDt7+An1UvWpPuq7qDw3Jl2Czb0Eu6xeTXIiL8dxm1pjzdKd+t/Kc8ngSEr6o SWlP7IwWk1NMgAcWuxL3bTv/47+OC6zhny0TT+PYws0S2OHhYfo0rzweGTA6s5c+n08A hy/KyQV/dBLVEAcPiHcPtfP6lWn/DP4S5yv2t/P2LrOQPCBaAovpgeCPxBUY+UVR2z7d sg8DvqZUwvaM0OB+o7YwhGFfo0sDOZs0fz98ljUHiATv89i34o3nqjik66i+drIFjtt4 aM63OiX6EF77jQUov9AEbm0Tc2cCFhol3veEZB8eOhK+mZ3VgrFqR4niqxj+0N2sZ/AA 0SHw== 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=gAvGsgZZ1dHhUV4EaGaw7fccXkxAdXEnmLCyLcUfy6I=; b=UQXsLhP0Lp++tukMTkS4Jq2HyEBNseS34bI3Ns7iIGEEc/CYXalWxQinDIDqD4OvOZ fnpu8YSYTm/IT9FlDBfjI/f48IWjiKC2w0DXoNACuCWZwk/rAYD/tr6pKz8meyWxpUDh /dAGijPwFI2dMIMdV8nmghkmXAtQSoEH/m53zpHYQozK+3PLeqZwZkCYxKYMkAsXw9hQ w06zp/GxCsevlGl5sMaaT6gNx+qKOCGjCl3MDlyM49fKBRnrLDgf7hs2gdKmt/6Z8QXK D9RFOwsaZy/U94fG4v4s8ujgEM3gRj3N2WFsWoTHI94pWEoS990Os12vAeKjw0kfNWEr KBuQ== X-Gm-Message-State: AOAM532WsZnZS9N7DvTmF+ffsnjOTBs5e+NLIgVQiIUpWVfck+rN6fuC e9/uCFG1LU4ekB52ExA44HZw/Z5ZZ0KdZw== X-Google-Smtp-Source: ABdhPJwyXdlc8LqbSnwABsxvbKb7CLPmXTl7gqe8/kElr/93B4ffSLkr2185wT23KUrpmb6w4MgVbA== X-Received: by 2002:a05:620a:228f:: with SMTP id o15mr5933818qkh.206.1605718401709; Wed, 18 Nov 2020 08:53:21 -0800 (PST) Received: from localhost.localdomain ([181.23.91.217]) by smtp.gmail.com with ESMTPSA id f14sm4863788qkk.89.2020.11.18.08.53.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2020 08:53:20 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 18 Nov 2020 13:52:37 -0300 Message-Id: <20201118165247.4130-9-jamrial@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201118165247.4130-1-jamrial@gmail.com> References: <20201118165247.4130-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 08/18] avformat: port AVFormatInternal->parse_queue to the new packet list API 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 | 3 +-- libavformat/options.c | 5 ++++- libavformat/utils.c | 35 ++++++++++++++++++++++++----------- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/libavformat/internal.h b/libavformat/internal.h index a0649956e8..749e387931 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -89,8 +89,7 @@ struct AVFormatInternal { /** * Packets split by the parser get queued here. */ - struct PacketListEntry *parse_queue; - struct PacketListEntry *parse_queue_end; + struct AVPacketList *parse_queue; /** * Remaining size available for raw_packet_buffer, in bytes. */ diff --git a/libavformat/options.c b/libavformat/options.c index ee7a533aa0..a400419917 100644 --- a/libavformat/options.c +++ b/libavformat/options.c @@ -220,10 +220,13 @@ AVFormatContext *avformat_alloc_context(void) av_free(ic); return NULL; } + internal->parse_queue = av_packet_list_alloc(); internal->packet_buffer = av_packet_list_alloc(); internal->raw_packet_buffer = av_packet_list_alloc(); - if (!internal->packet_buffer || + if (!internal->parse_queue || + !internal->packet_buffer || !internal->raw_packet_buffer) { + av_packet_list_free(&internal->parse_queue); av_packet_list_free(&internal->packet_buffer); av_packet_list_free(&internal->raw_packet_buffer); av_free(internal); diff --git a/libavformat/utils.c b/libavformat/utils.c index 02c0ead44b..59979fb469 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -1013,14 +1013,16 @@ static PacketListEntry *get_next_pkt(AVFormatContext *s, AVStream *st, PacketLis { #if FF_API_PACKET_LIST struct PacketList *packet_buffer = (struct PacketList *)s->internal->packet_buffer; + struct PacketList *parse_queue = (struct PacketList *)s->internal->parse_queue; #else AVPacketList *packet_buffer = s->internal->packet_buffer; + AVPacketList *parse_queue = s->internal->parse_queue; #endif if (pktl->next) return pktl->next; if (pktl == packet_buffer->tail) - return s->internal->parse_queue; + return parse_queue->head; return NULL; } @@ -1102,12 +1104,14 @@ static void update_initial_timestamps(AVFormatContext *s, int stream_index, AVStream *st = s->streams[stream_index]; #if FF_API_PACKET_LIST struct PacketList *packet_buffer = (struct PacketList *)s->internal->packet_buffer; + struct PacketList *parse_queue = (struct PacketList *)s->internal->parse_queue; #else AVPacketList *packet_buffer = s->internal->packet_buffer; + AVPacketList *parse_queue = s->internal->parse_queue; #endif PacketListEntry *pktl = packet_buffer->head ? packet_buffer->head : - s->internal->parse_queue; + parse_queue->head; PacketListEntry *pktl_it; uint64_t shift; @@ -1160,12 +1164,14 @@ static void update_initial_durations(AVFormatContext *s, AVStream *st, { #if FF_API_PACKET_LIST struct PacketList *packet_buffer = (struct PacketList *)s->internal->packet_buffer; + struct PacketList *parse_queue = (struct PacketList *)s->internal->parse_queue; #else AVPacketList *packet_buffer = s->internal->packet_buffer; + AVPacketList *parse_queue = s->internal->parse_queue; #endif PacketListEntry *pktl = packet_buffer->head ? packet_buffer->head : - s->internal->parse_queue; + parse_queue->head; int64_t cur_dts = RELATIVE_TS_BASE; if (st->first_dts != AV_NOPTS_VALUE) { @@ -1193,7 +1199,7 @@ static void update_initial_durations(AVFormatContext *s, AVStream *st, } pktl = packet_buffer->head ? packet_buffer->head : - s->internal->parse_queue; + parse_queue->head; st->first_dts = cur_dts; } else if (st->cur_dts != RELATIVE_TS_BASE) return; @@ -1230,8 +1236,10 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st, st->codecpar->codec_id != AV_CODEC_ID_HEVC; #if FF_API_PACKET_LIST struct PacketList *packet_buffer = (struct PacketList *)s->internal->packet_buffer; + struct PacketList *parse_queue = (struct PacketList *)s->internal->parse_queue; #else AVPacketList *packet_buffer = s->internal->packet_buffer; + AVPacketList *parse_queue = s->internal->parse_queue; #endif if (s->flags & AVFMT_FLAG_NOFILLIN) @@ -1310,7 +1318,7 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st, } } - if (pkt->duration > 0 && (packet_buffer->head || s->internal->parse_queue)) + if (pkt->duration > 0 && (packet_buffer->head || parse_queue->head)) update_initial_durations(s, st, pkt->stream_index, pkt->duration); /* Correct timestamps with byte offset if demuxers only have timestamps @@ -1511,8 +1519,7 @@ static int parse_packet(AVFormatContext *s, AVPacket *pkt, 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, + ret = av_packet_list_put(s->internal->parse_queue, &out_pkt, NULL, 0); if (ret < 0) { av_packet_unref(&out_pkt); @@ -1540,8 +1547,13 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) { int ret, i, got_packet = 0; AVDictionary *metadata = NULL; +#if FF_API_PACKET_LIST + struct PacketList *parse_queue = (struct PacketList *)s->internal->parse_queue; +#else + AVPacketList *parse_queue = s->internal->parse_queue; +#endif - while (!got_packet && !s->internal->parse_queue) { + while (!got_packet && !parse_queue->head) { AVStream *st; /* read next packet */ @@ -1662,8 +1674,8 @@ FF_ENABLE_DEPRECATION_WARNINGS } } - if (!got_packet && s->internal->parse_queue) - ret = avpriv_packet_list_get(&s->internal->parse_queue, &s->internal->parse_queue_end, pkt); + if (!got_packet && parse_queue->head) + ret = av_packet_list_get(s->internal->parse_queue, pkt, 0); if (ret >= 0) { AVStream *st = s->streams[pkt->stream_index]; @@ -1843,7 +1855,7 @@ static void flush_packet_queue(AVFormatContext *s) { if (!s->internal) return; - avpriv_packet_list_free(&s->internal->parse_queue, &s->internal->parse_queue_end); + av_packet_list_flush(s->internal->parse_queue); av_packet_list_flush(s->internal->packet_buffer); av_packet_list_flush(s->internal->raw_packet_buffer); @@ -4472,6 +4484,7 @@ void avformat_free_context(AVFormatContext *s) av_dict_free(&s->internal->id3v2_meta); av_freep(&s->streams); flush_packet_queue(s); + av_packet_list_free(&s->internal->parse_queue); av_packet_list_free(&s->internal->packet_buffer); av_packet_list_free(&s->internal->raw_packet_buffer); av_freep(&s->internal); From patchwork Wed Nov 18 16:52:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 23701 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 D6A4544B913 for ; Wed, 18 Nov 2020 18:53:26 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B64E068B5CC; Wed, 18 Nov 2020 18:53:26 +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 4BE686805BE for ; Wed, 18 Nov 2020 18:53:25 +0200 (EET) Received: by mail-qv1-f47.google.com with SMTP id u23so1356101qvf.1 for ; Wed, 18 Nov 2020 08:53: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=s5UPeErhSU+E+N5dmv+G6AgkJY6RFRlvp2Dplm0zGrQ=; b=S1QFtpw/3cr5r6DP2SslL/GZP0izn/Ebmxr/D35bMGVJipa+RMpAXkAANJp9HgBvKd cTmYOXl2eBCg28o0l4zRYfCNS4NoenfFJJj4eQi8054ochb24sAfL/e9AvFpwXIh0t8y eTmpZ3mW1k37IwGqWc5JNsQY8dsQ7+ruj9bJjg+H+wMckhteiJQMuGLZkD2GSqOWAxoe 1qCd9ZJ/LHuPy74JiO5vI2kKo1H7KBudfYiozlY3XNyZCk3tCWuTbpZABCkoCrKXknWa muS8uXhxcdWwqV5gxjibEhVg9JQklgNdr+6/BqzTIU5DMsswThglK1OgmK/E+U43Hgp3 nIzw== 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=s5UPeErhSU+E+N5dmv+G6AgkJY6RFRlvp2Dplm0zGrQ=; b=L7ZnC4VOpdVh5Y/UDK8G59x3ffxcRQwSZr7isSP7k2H9rJskqBHYdUU7SqrgSbh5hO vBSF8YeaMZ3L4Iw5uwcEL2RmxWbjUorL8NElSdggbxCNLUSTYgZX+NBi5sDA266JUUFz 940MUx6LhA4TlXCrafNRjpeQMiu+j6KQ6i0Vmg+Ad7CdB24/t2nu6e1++X0rajmAKIin ehzLj9rR00oZ3H+RZ9J3jIkt8bB1y7Kp3M4ZCBfuclULOGIqrSkVsnqxLfBOiDtpGrdf KjDIkzm0CsCifWpiLCqWoXIJvVUr2jdTK1Aazvj3cx0XOLlA+5AO//8bMi2tId1VMOCn Vv7A== X-Gm-Message-State: AOAM531mWiCT95nfG0r+oRhTmCTwopTMTMcyhaKkwCVz4PODD2oqHc3/ rPqbL8RuJoHDhvQ8uLKSkJEqHy81IXBV1A== X-Google-Smtp-Source: ABdhPJxIXLjKfsrZ1J3s7cfQ7fW6ECKyQ9JT3Y+UKEa4M2+l3LnjOeZp3o4992VlX9Rmsn1DaeoHtQ== X-Received: by 2002:a0c:9b82:: with SMTP id o2mr5635686qve.44.1605718403427; Wed, 18 Nov 2020 08:53:23 -0800 (PST) Received: from localhost.localdomain ([181.23.91.217]) by smtp.gmail.com with ESMTPSA id f14sm4863788qkk.89.2020.11.18.08.53.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2020 08:53:22 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 18 Nov 2020 13:52:38 -0300 Message-Id: <20201118165247.4130-10-jamrial@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201118165247.4130-1-jamrial@gmail.com> References: <20201118165247.4130-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 09/18] avdevice/dshow: port to the new packet list API 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/dshow.c | 52 +++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c index d7f5bd7069..ab158b13b6 100644 --- a/libavdevice/dshow.c +++ b/libavdevice/dshow.c @@ -58,7 +58,6 @@ static int dshow_read_close(AVFormatContext *s) { struct dshow_ctx *ctx = s->priv_data; - AVPacketList *pktl; if (ctx->control) { IMediaControl_Stop(ctx->control); @@ -116,13 +115,7 @@ dshow_read_close(AVFormatContext *s) if(ctx->event[1]) CloseHandle(ctx->event[1]); - pktl = ctx->pktl; - while (pktl) { - AVPacketList *next = pktl->next; - av_packet_unref(&pktl->pkt); - av_free(pktl); - pktl = next; - } + av_packet_list_free(&ctx->pktl); CoUninitialize(); @@ -162,7 +155,8 @@ 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; + AVPacket pkt = { 0 }; + int ret; // dump_videohdr(s, vdhdr); @@ -171,21 +165,19 @@ 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)); - if(!pktl_next) + if (av_new_packet(&pkt, buf_size) < 0) goto fail; - if(av_new_packet(&pktl_next->pkt, buf_size) < 0) { - av_free(pktl_next); + pkt.stream_index = index; + pkt.pts = time; + memcpy(pkt.data, buf, buf_size); + + ret = av_packet_list_put(ctx->pktl, &pkt, NULL, 0); + if (ret < 0) { + av_packet_unref(&pkt); goto fail; } - pktl_next->pkt.stream_index = index; - pktl_next->pkt.pts = time; - memcpy(pktl_next->pkt.data, buf, buf_size); - - for(ppktl = &ctx->pktl ; *ppktl ; ppktl = &(*ppktl)->next); - *ppktl = pktl_next; ctx->curbufsize[index] += buf_size; SetEvent(ctx->event[1]); @@ -1113,6 +1105,12 @@ static int dshow_read_header(AVFormatContext *avctx) } } + ctx->pktl = av_packet_list_alloc(); + if (!ctx->pktl) { + ret = AVERROR(ENOMEM); + goto error; + } + r = CoCreateInstance(&CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, &IID_IGraphBuilder, (void **) &graph); if (r != S_OK) { @@ -1262,20 +1260,18 @@ 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; + int ret = AVERROR(EAGAIN); - while (!ctx->eof && !pktl) { + while (!ctx->eof && ret) { WaitForSingleObject(ctx->mutex, INFINITE); - pktl = ctx->pktl; - if (pktl) { - *pkt = pktl->pkt; - ctx->pktl = ctx->pktl->next; - av_free(pktl); + + ret = av_packet_list_get(ctx->pktl, pkt, 0); + if (!ret) ctx->curbufsize[pkt->stream_index] -= pkt->size; - } + ResetEvent(ctx->event[1]); ReleaseMutex(ctx->mutex); - if (!pktl) { + if (ret) { if (dshow_check_event_queue(ctx->media_event) < 0) { ctx->eof = 1; } else if (s->flags & AVFMT_FLAG_NONBLOCK) { From patchwork Wed Nov 18 16:52:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 23715 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 8162444BB34 for ; Wed, 18 Nov 2020 19:00:48 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6DE7A68B641; Wed, 18 Nov 2020 19:00:48 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-io1-f44.google.com (mail-io1-f44.google.com [209.85.166.44]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1EE3868A477 for ; Wed, 18 Nov 2020 19:00:42 +0200 (EET) Received: by mail-io1-f44.google.com with SMTP id i9so2765672ioo.2 for ; Wed, 18 Nov 2020 09:00: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=Ama8Nl0sL9LV1Ssi2HezJfavtCUQbce61Ia54nBFLiI=; b=XvjlqccxsA6CaskbGWsRb3H56MaIKbsRN+RGTyBThPQVNyUPRdWU7ts98Yn/brCERy WjQurugoKzS/ME6WVBAD3Cf8almDJTq954Wqqc0v9VA8d75RSiSNjEN8zPYchbCMzJYA Mx0Lvo9pxZqRVvyaLAoa5nvFfltrEndHUfvBzsO536cDX5ec9GMu5o+OefBpZHuqCxXm GOYaeoM08BT8mw8pb3dMNHaQLb16uYx2uIH7EzivFfCsc3GUERvyKZSf++D63z3JCS+S MLnDAQkLtqObzcqRHSwBLiVVJjFgqFa7MPnxL/3WY92LqMsUhGkC7YzC3/VIL6hDvDnR uRug== 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=Ama8Nl0sL9LV1Ssi2HezJfavtCUQbce61Ia54nBFLiI=; b=UNpFynvsD1gtPGC/hajBWL0RT46MHyTG9yOGt0PQPpix9VARxR+oDX7hdZcxEKp3b4 lovK/SCG+UXSApGFH85Goigawn+qZFe9CqeIevbB0H611rBUpENej8mP2cDOsfbqoegB 9ldIPBDpO2OPgQsXKvJc1nxYKC8mSynp90vWl0cLY67VK7Uy+uyxKn3Da2h+UJVOBZRW sFlIaSaCJ8Xr6zd2culxtinL4USk/1fOADcBEERj39U39OuowX0gvCfVP6tyjeS0HX9e IIbG5StOjPlthtZ9vyqlEIe8B6I8jPPPooQIBQel+tukHnZmif1wCaJ9gM0BA2UAbE5D 1ZiQ== X-Gm-Message-State: AOAM531roAuxNQ1iWW1woNLtSdKMX4sO5uNIYDLesYZcialt2jEKrqj2 pgMQYkIy3Q1dFPZEM5g6rGDRQnOhtN0pIg== X-Google-Smtp-Source: ABdhPJxNQOhbhE6Yb2FXxXVxYCCli6flvqiGQG8sb8Nhu0fAR/kirQRqbEEFJt5DXBVHmJAMMEAHag== X-Received: by 2002:a37:d08:: with SMTP id 8mr5472484qkn.306.1605718405098; Wed, 18 Nov 2020 08:53:25 -0800 (PST) Received: from localhost.localdomain ([181.23.91.217]) by smtp.gmail.com with ESMTPSA id f14sm4863788qkk.89.2020.11.18.08.53.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2020 08:53:24 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 18 Nov 2020 13:52:39 -0300 Message-Id: <20201118165247.4130-11-jamrial@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201118165247.4130-1-jamrial@gmail.com> References: <20201118165247.4130-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 10/18] avdevice/decklink_dec: port to the new packet list API 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_common.h | 2 +- libavdevice/decklink_dec.cpp | 53 +++++++++++++---------------------- 2 files changed, 20 insertions(+), 35 deletions(-) diff --git a/libavdevice/decklink_common.h b/libavdevice/decklink_common.h index f35bd9ae6f..9ee877f349 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; + AVPacketList *pktl; int nb_packets; unsigned long long size; int abort_request; diff --git a/libavdevice/decklink_dec.cpp b/libavdevice/decklink_dec.cpp index 6517b9df13..1115c5af79 100644 --- a/libavdevice/decklink_dec.cpp +++ b/libavdevice/decklink_dec.cpp @@ -469,10 +469,13 @@ skip_packet: return tgt; } -static void avpacket_queue_init(AVFormatContext *avctx, AVPacketQueue *q) +static int avpacket_queue_init(AVFormatContext *avctx, AVPacketQueue *q) { struct decklink_cctx *ctx = (struct decklink_cctx *)avctx->priv_data; memset(q, 0, sizeof(AVPacketQueue)); + q->pktl = av_packet_list_alloc(); + if (!q->pktl) + return AVERROR(ENOMEM); pthread_mutex_init(&q->mutex, NULL); pthread_cond_init(&q->cond, NULL); q->avctx = avctx; @@ -484,13 +487,7 @@ static void avpacket_queue_flush(AVPacketQueue *q) AVPacketList *pkt, *pkt1; pthread_mutex_lock(&q->mutex); - for (pkt = q->first_pkt; pkt != NULL; pkt = pkt1) { - pkt1 = pkt->next; - av_packet_unref(&pkt->pkt); - av_freep(&pkt); - } - q->last_pkt = NULL; - q->first_pkt = NULL; + av_packet_list_flush(q->pktl); q->nb_packets = 0; q->size = 0; pthread_mutex_unlock(&q->mutex); @@ -499,6 +496,7 @@ static void avpacket_queue_flush(AVPacketQueue *q) static void avpacket_queue_end(AVPacketQueue *q) { avpacket_queue_flush(q); + av_packet_list_free(&q->pktl); pthread_mutex_destroy(&q->mutex); pthread_cond_destroy(&q->cond); } @@ -514,7 +512,7 @@ static unsigned long long avpacket_queue_size(AVPacketQueue *q) static int avpacket_queue_put(AVPacketQueue *q, AVPacket *pkt) { - AVPacketList *pkt1; + int size; // Drop Packet if queue size is > maximum queue size if (avpacket_queue_size(q) > (uint64_t)q->max_q_size) { @@ -528,25 +526,16 @@ static int avpacket_queue_put(AVPacketQueue *q, AVPacket *pkt) return -1; } - pkt1 = (AVPacketList *)av_malloc(sizeof(AVPacketList)); - if (!pkt1) { - av_packet_unref(pkt); - return -1; - } - av_packet_move_ref(&pkt1->pkt, pkt); - pkt1->next = NULL; - pthread_mutex_lock(&q->mutex); - if (!q->last_pkt) { - q->first_pkt = pkt1; - } else { - q->last_pkt->next = pkt1; - } + size = pkt->size; + + ret = av_packet_list_put(q->pktl, pkt, 0); + if (ret < 0) + return 0; - q->last_pkt = pkt1; q->nb_packets++; - q->size += pkt1->pkt.size + sizeof(*pkt1); + q->size += size; pthread_cond_signal(&q->cond); @@ -562,16 +551,10 @@ static int avpacket_queue_get(AVPacketQueue *q, AVPacket *pkt, int block) pthread_mutex_lock(&q->mutex); for (;; ) { - pkt1 = q->first_pkt; - if (pkt1) { - q->first_pkt = pkt1->next; - if (!q->first_pkt) { - q->last_pkt = NULL; - } + ret = av_packet_list_get(q->pktl, pkt, 0); + if (!ret) { q->nb_packets--; - q->size -= pkt1->pkt.size + sizeof(*pkt1); - *pkt = pkt1->pkt; - av_free(pkt1); + q->size -= pkt.size; ret = 1; break; } else if (!block) { @@ -1382,7 +1365,9 @@ av_cold int ff_decklink_read_header(AVFormatContext *avctx) goto error; } - avpacket_queue_init (avctx, &ctx->queue); + ret = avpacket_queue_init(avctx, &ctx->queue); + if (ret < 0) + goto error; if (ctx->dli->StartStreams() != S_OK) { av_log(avctx, AV_LOG_ERROR, "Cannot start input stream\n"); From patchwork Wed Nov 18 16:52:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 23702 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 08ED244B913 for ; Wed, 18 Nov 2020 18:53:30 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D1B8C68B5F7; Wed, 18 Nov 2020 18:53:29 +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 AA8BA68B5F8 for ; Wed, 18 Nov 2020 18:53:28 +0200 (EET) Received: by mail-qt1-f178.google.com with SMTP id t5so2124779qtp.2 for ; Wed, 18 Nov 2020 08:53: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=82lTAhRfc4TxDFoDV/6130CUrfmoiGKitLUCZ/dJQ1E=; b=DLHZ/ynKJhpPSJKahyBibDLMzupLyXWGYddvBa5/YyhmokixdeKaK/rx+1910mPbrp 7vVjRBUwAlKQCYeAGVMRFYI0/BHpUSTZBi/0/tchBOgQvSmbvj9wlZH43+vkOf9HyYHE 0eKDO0IriotDais9RuiH2c83M1oR237BtHMHEwu68O0dEGxfTdOk8n/TUA+Ijo29RBcF iOqERZCWNYGFOlXsNPrAggU8fchrgxSIRSOEe8xXgA0/akivM/2g9RrXYKa5leyC/+8P Pt5/VI4mrBXO2bJXKCJXXiGH1bNyEkjHR7lA86NafMw9h3O5n4wfEISM/P1dHYPb10y4 rLXw== 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=82lTAhRfc4TxDFoDV/6130CUrfmoiGKitLUCZ/dJQ1E=; b=hkwArWu9wKVxbvtsuoOjxIcV2OxYNesWrlc0D7EKDc5ZYMp5R9s7TSZptYhRBXL8XE enE4aB5MM989aBHjPavQJdft/VAeHifYmJHSYOOrM0YImfPmyUaAaZ1S61M3SJrjsAlb GZYuE7grBkkZnViJd54cz1IhDj0eaKWi+6u8Qevw693P8dafMovXBQOdCL/4sCXSH3fF ZyGBKTI70TZKSgjTj90XUttSnNhSIKkUNjw3hP6Yv6uDYtMEQfRg2+i1KoGAz6ngHKdy 6GXRhQR85uEnQOk9vXZK0WTh+qxHAnOyOS8vHKGIK79EEyxQp3hoijDRBfpkzhmOS7WK /vtA== X-Gm-Message-State: AOAM5330B8jxe8O+QGKif+3kYx/3saLfIArtE/BO0zKPcUfFur7xClqF QoMS1Z9RY1m7AHwdGtmc5UG/FCvyMRv+/Q== X-Google-Smtp-Source: ABdhPJyOvcz7E2rmFu1AhwwpaIbRWTHPriGsVI6VYYdTPBz6cObTc2DBHlExaOq41ZC+5N2j/viStw== X-Received: by 2002:ac8:4a99:: with SMTP id l25mr5416825qtq.27.1605718406808; Wed, 18 Nov 2020 08:53:26 -0800 (PST) Received: from localhost.localdomain ([181.23.91.217]) by smtp.gmail.com with ESMTPSA id f14sm4863788qkk.89.2020.11.18.08.53.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2020 08:53:26 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 18 Nov 2020 13:52:40 -0300 Message-Id: <20201118165247.4130-12-jamrial@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201118165247.4130-1-jamrial@gmail.com> References: <20201118165247.4130-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 11/18] avdevice/vfwcap: port to the new packet list API 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/vfwcap.c | 49 +++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 28 deletions(-) diff --git a/libavdevice/vfwcap.c b/libavdevice/vfwcap.c index e2ab276c2e..eb5c29923f 100644 --- a/libavdevice/vfwcap.c +++ b/libavdevice/vfwcap.c @@ -178,7 +178,8 @@ static LRESULT CALLBACK videostream_cb(HWND hwnd, LPVIDEOHDR vdhdr) { AVFormatContext *s; struct vfw_ctx *ctx; - AVPacketList **ppktl, *pktl_next; + AVPacket pkt = { 0 }; + int ret; s = (AVFormatContext *) GetWindowLongPtr(hwnd, GWLP_USERDATA); ctx = s->priv_data; @@ -190,21 +191,18 @@ static LRESULT CALLBACK videostream_cb(HWND hwnd, LPVIDEOHDR vdhdr) WaitForSingleObject(ctx->mutex, INFINITE); - pktl_next = av_mallocz(sizeof(AVPacketList)); - if(!pktl_next) + if (av_new_packet(&pkt, vdhdr->dwBytesUsed) < 0) goto fail; - if(av_new_packet(&pktl_next->pkt, vdhdr->dwBytesUsed) < 0) { - av_free(pktl_next); + pkt.pts = vdhdr->dwTimeCaptured; + memcpy(pkt.data, vdhdr->lpData, vdhdr->dwBytesUsed); + + ret = av_packet_list_put(ctx->pktl, &pkt, NULL, 0); + if (ret < 0) { + av_packet_unref(&pkt); goto fail; } - pktl_next->pkt.pts = vdhdr->dwTimeCaptured; - memcpy(pktl_next->pkt.data, vdhdr->lpData, vdhdr->dwBytesUsed); - - for(ppktl = &ctx->pktl ; *ppktl ; ppktl = &(*ppktl)->next); - *ppktl = pktl_next; - ctx->curbufsize += vdhdr->dwBytesUsed; SetEvent(ctx->event); @@ -219,7 +217,6 @@ fail: static int vfw_read_close(AVFormatContext *s) { struct vfw_ctx *ctx = s->priv_data; - AVPacketList *pktl; if(ctx->hwnd) { SendMessage(ctx->hwnd, WM_CAP_SET_CALLBACK_VIDEOSTREAM, 0, 0); @@ -231,13 +228,7 @@ static int vfw_read_close(AVFormatContext *s) if(ctx->event) CloseHandle(ctx->event); - pktl = ctx->pktl; - while (pktl) { - AVPacketList *next = pktl->next; - av_packet_unref(&pktl->pkt); - av_free(pktl); - pktl = next; - } + av_packet_list_free(&ctx->pktl); return 0; } @@ -300,6 +291,13 @@ static int vfw_read_header(AVFormatContext *s) SetWindowLongPtr(ctx->hwnd, GWLP_USERDATA, (LONG_PTR) s); + + ctx->pktl = av_packet_list_alloc(); + if (!ctx->pktl) { + vfw_read_close(s); + return AVERROR(ENOMEM); + } + st = avformat_new_stream(s, NULL); if(!st) { vfw_read_close(s); @@ -439,19 +437,14 @@ fail: static int vfw_read_packet(AVFormatContext *s, AVPacket *pkt) { struct vfw_ctx *ctx = s->priv_data; - AVPacketList *pktl = NULL; + int ret = AVERROR(EAGAIN); - while(!pktl) { + while (ret) { WaitForSingleObject(ctx->mutex, INFINITE); - pktl = ctx->pktl; - if(ctx->pktl) { - *pkt = ctx->pktl->pkt; - ctx->pktl = ctx->pktl->next; - av_free(pktl); - } + ret = av_packet_list_get(ctx->pktl, pkt, 0); ResetEvent(ctx->event); ReleaseMutex(ctx->mutex); - if(!pktl) { + if (ret) { if(s->flags & AVFMT_FLAG_NONBLOCK) { return AVERROR(EAGAIN); } else { From patchwork Wed Nov 18 16:52:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 23703 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 DB82444B913 for ; Wed, 18 Nov 2020 18:53:31 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C4FAE68B606; Wed, 18 Nov 2020 18:53:31 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f194.google.com (mail-qt1-f194.google.com [209.85.160.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5279468B615 for ; Wed, 18 Nov 2020 18:53:30 +0200 (EET) Received: by mail-qt1-f194.google.com with SMTP id b16so2104473qtb.6 for ; Wed, 18 Nov 2020 08:53: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=QRzQDTGHsUDcFB8a3oQ9mBn5fV4MT7Z3HXTz6kcsHn4=; b=WDaEZUBWkDN/+ChHi/Le/1t4xfT4zisHzQ9byAU9iL+HBNZRFrtQ6ZMFaN71I4Bucb HkvKJdNv8jeQkrpKxTVre2zZGPnSTKlAqtNnLTMfNEoFPEhkeYMwj+oaOZZZAqkZvFcP 2nCWEkZL68rpv/8LFnmiraK2l2H4hiV9R1U0a12Z0heJBD9qQ3rA1WHy/zFtuz8/bAHo ZrGV8BMGMMvZLi/Ek/rDVCNBzDG2gprA/V2EFzkI7aCc4mbfib7tkCxBc18r4TurGrpZ 0tx7obKMnyKaHvjDN+esQ+bJl6Rp0fbEjSroHXNAu6z3FwewsTTcaaPj+EHg27Kjx+Q5 U+Lw== 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=QRzQDTGHsUDcFB8a3oQ9mBn5fV4MT7Z3HXTz6kcsHn4=; b=TyV7M9JCO7m7WIMHHTtO1D96KOpVaijtdV6rTJDTsUO9U1uNrg+kXxcskQkfkwsiHd h9bn7ySP0110Z5UwwURNt4kjBU5Uc2+dWbSnkZUC0t0yMkw1xWELXAySg6uET6g6G0rd arILznXur+FdTR2dEHTOxmDlOQSpGsHNNXR0VbJOIi6PGzHJuPn8NEfXLVkRoqKt7byy S5BOMDAtIU9GSW0HvZzidmiJ9kZsoS8fCtPqVnFtkAl2U9AyWGxy/B52z/iqh3knvklG KoVwlX9Oh7yhJFrtPrMmZXQdwVCSm9SJqofLjoDa7tw2eW3u8sGGxt+EATMpDJ1NsNiD iMhw== X-Gm-Message-State: AOAM5306GFdEwbA/xNTxVTH1vigak53uUALXiUNZyHv4G0pG50/YnRPv SVfWY79sLEt8G3IEaLYJQfTdsKk8v86r2Q== X-Google-Smtp-Source: ABdhPJxg51LjBCLmhAZ/NkS0FOzQiB1u711NwvULuNF1+Zi53tTSs0DLRPgGOxdMFuOT/N+GXZbPzg== X-Received: by 2002:ac8:6619:: with SMTP id c25mr5139569qtp.343.1605718408460; Wed, 18 Nov 2020 08:53:28 -0800 (PST) Received: from localhost.localdomain ([181.23.91.217]) by smtp.gmail.com with ESMTPSA id f14sm4863788qkk.89.2020.11.18.08.53.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2020 08:53:27 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 18 Nov 2020 13:52:41 -0300 Message-Id: <20201118165247.4130-13-jamrial@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201118165247.4130-1-jamrial@gmail.com> References: <20201118165247.4130-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 12/18] avformat/ttaenc: port to the new packet list API 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/ttaenc.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/libavformat/ttaenc.c b/libavformat/ttaenc.c index 39d9034f68..8abba11aed 100644 --- a/libavformat/ttaenc.c +++ b/libavformat/ttaenc.c @@ -30,7 +30,7 @@ typedef struct TTAMuxContext { AVIOContext *seek_table; - PacketListEntry *queue, *queue_end; + AVPacketList *queue; uint32_t nb_samples; int frame_size; int last_frame; @@ -64,6 +64,10 @@ static int tta_init(AVFormatContext *s) tta->frame_size = par->sample_rate * 256 / 245; avpriv_set_pts_info(s->streams[0], 64, 1, par->sample_rate); + tta->queue = av_packet_list_alloc(); + if (!tta->queue) + return AVERROR(ENOMEM); + return 0; } @@ -94,8 +98,7 @@ static int tta_write_packet(AVFormatContext *s, AVPacket *pkt) TTAMuxContext *tta = s->priv_data; int ret; - ret = avpriv_packet_list_put(&tta->queue, &tta->queue_end, pkt, - av_packet_ref, 0); + ret = av_packet_list_put(tta->queue, pkt, av_packet_ref, 0); if (ret < 0) { return ret; } @@ -125,8 +128,7 @@ static void tta_queue_flush(AVFormatContext *s) TTAMuxContext *tta = s->priv_data; AVPacket pkt; - while (tta->queue) { - avpriv_packet_list_get(&tta->queue, &tta->queue_end, &pkt); + while (!av_packet_list_get(tta->queue, &pkt, 0)) { avio_write(s->pb, pkt.data, pkt.size); av_packet_unref(&pkt); } @@ -162,7 +164,7 @@ static void tta_deinit(AVFormatContext *s) TTAMuxContext *tta = s->priv_data; ffio_free_dyn_buf(&tta->seek_table); - avpriv_packet_list_free(&tta->queue, &tta->queue_end); + av_packet_list_free(&tta->queue); } AVOutputFormat ff_tta_muxer = { From patchwork Wed Nov 18 16:52:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 23704 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 E96BD44B913 for ; Wed, 18 Nov 2020 18:53:32 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DA4A168B638; Wed, 18 Nov 2020 18:53:32 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f194.google.com (mail-qt1-f194.google.com [209.85.160.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A255468B60C for ; Wed, 18 Nov 2020 18:53:31 +0200 (EET) Received: by mail-qt1-f194.google.com with SMTP id m65so2062107qte.11 for ; Wed, 18 Nov 2020 08:53: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=aslzv6SNw7FmmtcWgHztT2Z/wEd/9ROYy1XUB/J/Yy0=; b=uMVlGdL2KQgVfT8e1XNt1XvS0V9ZaTn2wqUOp8P/FxtWnUNI0yVOULjIuPvK8Ns0Nj ojhRQK+UXUPFO9Vl8pTfPcH/ObcUGRhgNGj3P1W+qburnmkqgiwawuIfHpd/kFC11JV+ 4BXHMsjU4L/KRXfqLs8xaPI/Sggz5h2eqB3TZk+x2SpM+dqYNA13HzUN2KZMaqPnxxmz 8MGV+IFsfHzEYWIFoZ/AOLWuP2p8E1DgTeUietA9kLaKDPO8DhU2BA2Eo/pclyS+EzBz mpDL0z2vrX1Yo7FqXc0J7nYFka8ZrMOCrXdge6xq8BbWTEWPK/howi3s4n+TkOL1xDx0 pumg== 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=aslzv6SNw7FmmtcWgHztT2Z/wEd/9ROYy1XUB/J/Yy0=; b=MzObxxwwtBF8kkdSuwoGB0uOC4S1L3HbF1i6xa/8dM7bxjAhoMu+1UEAn3SF3AqdoW EuHK+C+V9GIapcT+16TImPDWIIUmd5uzDGrQsHi1vDrwMK7rjBlJrRFPqecGRPtmWEA5 HH8Fc1BwppxZf4mOFo/aslfugRUNu016/xY9v8paQcsjfutiUYMdCU3waT0xNTywknt0 wUJTA3L+gNr18Gq7p3UNhozAoGeuXu9vTJYqjFshpv78aIoQqhdQMg3gxU9TwG3LKw3w TznFSqc4d9JxlHqKWqkBfGhcUXYayuoABEK73ytpWZ+b+VxtVT7eOjIqHG7Lcebjmfdy ENuQ== X-Gm-Message-State: AOAM531/7tugFUD/SjNBW8Wl1hFxr1JORtnbL6n4W6eu686oaPChjMBD L2MTuGFkJCLSpYaMOXi0fg1enTKSKNlNQg== X-Google-Smtp-Source: ABdhPJycrmkmEXrKocFdKwt44WsI/TFtp8O0aOq3RYz40NWNv6LqNq2oo8oeFBQHhsXoFh8QkMleJg== X-Received: by 2002:ac8:43d3:: with SMTP id w19mr4892805qtn.331.1605718410062; Wed, 18 Nov 2020 08:53:30 -0800 (PST) Received: from localhost.localdomain ([181.23.91.217]) by smtp.gmail.com with ESMTPSA id f14sm4863788qkk.89.2020.11.18.08.53.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2020 08:53:29 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 18 Nov 2020 13:52:42 -0300 Message-Id: <20201118165247.4130-14-jamrial@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201118165247.4130-1-jamrial@gmail.com> References: <20201118165247.4130-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 13/18] avformat/mp3enc: port to the new packet list API 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/mp3enc.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/libavformat/mp3enc.c b/libavformat/mp3enc.c index fddde33400..ed585c3976 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 */ - PacketListEntry *queue, *queue_end; + AVPacketList *queue; } MP3Context; static const uint8_t xing_offtbl[2][2] = {{32, 17}, {17, 9}}; @@ -387,8 +387,7 @@ static int mp3_queue_flush(AVFormatContext *s) ff_id3v2_finish(&mp3->id3, s->pb, s->metadata_header_padding); mp3_write_xing(s); - while (mp3->queue) { - avpriv_packet_list_get(&mp3->queue, &mp3->queue_end, &pkt); + while (!av_packet_list_get(mp3->queue, &pkt, 0)) { if (write && (ret = mp3_write_audio_packet(s, &pkt)) < 0) write = 0; av_packet_unref(&pkt); @@ -523,7 +522,7 @@ static int mp3_write_packet(AVFormatContext *s, AVPacket *pkt) if (pkt->stream_index == mp3->audio_stream_idx) { if (mp3->pics_to_write) { /* buffer audio packets until we get all the pictures */ - int ret = avpriv_packet_list_put(&mp3->queue, &mp3->queue_end, pkt, av_packet_ref, 0); + int ret = av_packet_list_put(mp3->queue, pkt, av_packet_ref, 0); if (ret < 0) { av_log(s, AV_LOG_WARNING, "Not enough memory to buffer audio. Skipping picture streams\n"); @@ -603,6 +602,10 @@ static int mp3_init(struct AVFormatContext *s) return AVERROR(EINVAL); } + mp3->queue = av_packet_list_alloc(); + if (!mp3->queue) + return AVERROR(ENOMEM); + return 0; } @@ -631,7 +634,7 @@ static void mp3_deinit(struct AVFormatContext *s) { MP3Context *mp3 = s->priv_data; - avpriv_packet_list_free(&mp3->queue, &mp3->queue_end); + av_packet_list_free(&mp3->queue); av_freep(&mp3->xing_frame); } From patchwork Wed Nov 18 16:52:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 23718 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 913F244B653 for ; Wed, 18 Nov 2020 19:21:30 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 64B7B68B5B2; Wed, 18 Nov 2020 19:21:30 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qv1-f66.google.com (mail-qv1-f66.google.com [209.85.219.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AF64F6800D2 for ; Wed, 18 Nov 2020 19:21:23 +0200 (EET) Received: by mail-qv1-f66.google.com with SMTP id z17so1375537qvy.11 for ; Wed, 18 Nov 2020 09:21: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=gkBYuX4WdPbRRIe5jq19EwKDD9omoLCAki1FP3Ppuwk=; b=XhiEryLooqabNSXrnLh5FmWLPvwERkkAsxfN3EluV0unslOq5Gw4V0jW5jtFhLhQC8 mnAyHuwWKEhrAijBrlfUx48NDQ7mhoofbf9i49X+jtGv01ouhs4W4CS6ia/7CPu1JnjQ 3AQDsuv9LmX1S3nqWnvWyOO9J7YLaqlV/LnI6uALX4XFm23E1mYW951NwM3tqVHQ8HAj nya9KAqlA9EG7LbgoxaHedUJDxC1XVrqTNJDb59GqDLj5VilvF6blylIDZ9BGLGB6ITK LGssYI1ovV5o/Y7dfv9oTLOd3VPGqD+zIFTSarjOLEwFw7n+8uNDJp7+laGz8BJS3xt3 rLlQ== 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=gkBYuX4WdPbRRIe5jq19EwKDD9omoLCAki1FP3Ppuwk=; b=knKDg9MIBtSxDXToV9RljMYEzXMNDAtONAQl1ecgEscC8SxuPFvcwyXTK275WvZbX7 6OSsDanJC4e+Grgc5lPjCEE6oGJS/pLZvZ7+d5tBE2fy4D6cZq4hOd9Xk3P486Q29lOl OxPnm/sayqMkikGNphuXWX83vAfCEE549u41199OCrNVkix7iy8Zp+Fc6Zv6A8NwiC+y 1anxW2KhtSnONAEkjh2trzNCoBp+vg6wIQmZJTWUqfCblXQkS1bddNyUlQzZlIDQRYry FytJPMTG+bjzFL1jaZTF7PBbBdiBN+wHcdpFnQi+Jz5UZ7lDyF30iUtsBW8y9bQwf8cx OJOg== X-Gm-Message-State: AOAM5331OgIXjgAbT1sHMbRw0LMVCro05xLuRW/LjSh3fip0ylNR+pIA foTEg5z6AVVpAIfx5Pjccudq0ePVQqj7sw== X-Google-Smtp-Source: ABdhPJz6EPDP+P+S8shKCW0Vyv99fp7W2OIy4KzYzi8V6435Ki32z2H1QIXfJhcEEQkQPVwiizEezg== X-Received: by 2002:a0c:ab8f:: with SMTP id j15mr5586731qvb.54.1605718411650; Wed, 18 Nov 2020 08:53:31 -0800 (PST) Received: from localhost.localdomain ([181.23.91.217]) by smtp.gmail.com with ESMTPSA id f14sm4863788qkk.89.2020.11.18.08.53.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2020 08:53:30 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 18 Nov 2020 13:52:43 -0300 Message-Id: <20201118165247.4130-15-jamrial@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201118165247.4130-1-jamrial@gmail.com> References: <20201118165247.4130-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 14/18] avformat/flacenc: port to the new packet list API 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/flacenc.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/libavformat/flacenc.c b/libavformat/flacenc.c index a24d3be85d..6fb5e59be0 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 */ - PacketListEntry *queue, *queue_end; + AVPacketList *queue; /* updated streaminfo sent by the encoder at the end */ uint8_t streaminfo[FLAC_STREAMINFO_SIZE]; @@ -253,6 +253,10 @@ static int flac_init(struct AVFormatContext *s) } } + c->queue = av_packet_list_alloc(); + if (!c->queue) + return AVERROR(ENOMEM); + return 0; } @@ -305,8 +309,7 @@ static int flac_queue_flush(AVFormatContext *s) if (ret < 0) write = 0; - while (c->queue) { - avpriv_packet_list_get(&c->queue, &c->queue_end, &pkt); + while (av_packet_list_get(c->queue, &pkt, 0)) { if (write && (ret = flac_write_audio_packet(s, &pkt)) < 0) write = 0; av_packet_unref(&pkt); @@ -346,7 +349,7 @@ static void flac_deinit(struct AVFormatContext *s) { FlacMuxerContext *c = s->priv_data; - avpriv_packet_list_free(&c->queue, &c->queue_end); + av_packet_list_free(&c->queue); } static int flac_write_packet(struct AVFormatContext *s, AVPacket *pkt) @@ -357,7 +360,7 @@ static int flac_write_packet(struct AVFormatContext *s, AVPacket *pkt) if (pkt->stream_index == c->audio_stream_idx) { if (c->waiting_pics) { /* buffer audio packets until we get all the pictures */ - ret = avpriv_packet_list_put(&c->queue, &c->queue_end, pkt, av_packet_ref, 0); + ret = av_packet_list_put(c->queue, pkt, av_packet_ref, 0); if (ret < 0) { av_log(s, AV_LOG_ERROR, "Out of memory in packet queue; skipping attached pictures\n"); c->waiting_pics = 0; From patchwork Wed Nov 18 16:52:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 23705 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 DFA4344B913 for ; Wed, 18 Nov 2020 18:53:36 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C295468B654; Wed, 18 Nov 2020 18:53:36 +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 05D0D68B648 for ; Wed, 18 Nov 2020 18:53:34 +0200 (EET) Received: by mail-qt1-f176.google.com with SMTP id p12so2092809qtp.7 for ; Wed, 18 Nov 2020 08:53: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=87OOKTza1oeGUdny26yfnYs8QB66fuF/qI/SPFM+vuI=; b=oXeUHrjANA08ylUzPoI/zQmgIlPn4iNfm8FDzwiPYRJ/51vI9U+INWFluuMIJkjEth rLlRpZ23qg/dO1By5ssMpDaak9REhhjhhXq0gC7Kj5+27Bb7EUqPmBuvVrhgQ/Tdo6Fv Ow4k/BSnX/owjYcZdixWHBa9e7S6nWZtK3q6oLTVBNlfWk4lm6cds+C2AEqpXseQL58J ewJQSNyNvM9wUsUEd2E1hLxF5ZXernluVvT1JMavnfXGPBsuSr+VRVXvskYqNqvp2j/o Ly/s2ZXvEyFsn18bQSDtVfok3Jk+81Ubam0+ZNrPHU0lkLmhaBDrt/oWrDAbf/wK8ply d5BQ== 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=87OOKTza1oeGUdny26yfnYs8QB66fuF/qI/SPFM+vuI=; b=VB7OVzcyvlPVrLDGWHgafNDeuE4FETW/t4R3daoCEss14OGXZvsScWpZ5AiyaVQQgw m3BRVtnZxNeEV8jEFvjY9KfVBxq0gWmFwPfMfsrMSUm3zCU8qg5ghxIs2pfVblng5nQm 8yVlUUH9s+kmNbdph7R/kozMdKjJqPN1NrVgHUlsoD/5QALHCNNnI+VHiwaf76JqGCwC ZZeUZGnjOngzlSuKDfpbfOZnubnQK5gf1Ef0CLw69s+QEJgfAxnhmYRPGpCDU1yOa4Bk ab98aXUQ3GiNMX3To1a36yQreMfYeOywWDkZNLDEFe4NHWFiThY7oN1xxbuFv83Vp7TL la3Q== X-Gm-Message-State: AOAM532rl1ZMosClMuJOmA3rT6bbO/n07choTC+kXu/35gN4C02ulGHP eahmWljYBF2IHOs3Emz1PAR/hygIeFPAIw== X-Google-Smtp-Source: ABdhPJxsIQir530rJiWvBTihfS/NHnt6CRhyW9HGGrOs/xX30o1E+O23sNikBhzLeAAJycs651ELlA== X-Received: by 2002:aed:31c5:: with SMTP id 63mr5698874qth.367.1605718413262; Wed, 18 Nov 2020 08:53:33 -0800 (PST) Received: from localhost.localdomain ([181.23.91.217]) by smtp.gmail.com with ESMTPSA id f14sm4863788qkk.89.2020.11.18.08.53.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2020 08:53:32 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 18 Nov 2020 13:52:44 -0300 Message-Id: <20201118165247.4130-16-jamrial@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201118165247.4130-1-jamrial@gmail.com> References: <20201118165247.4130-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 15/18] avformat/aiffenc: port to the new packet list API 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/aiffenc.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/libavformat/aiffenc.c b/libavformat/aiffenc.c index 7c28109814..4fa77c21bf 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; - PacketListEntry *pict_list, *pict_list_end; + AVPacketList *pict_list; int write_id3v2; int id3v2_version; } AIFFOutputContext; @@ -47,10 +47,10 @@ static int put_id3v2_tags(AVFormatContext *s, AIFFOutputContext *aiff) int ret; uint64_t pos, end, size; ID3v2EncContext id3v2 = { 0 }; + AVPacket pkt; AVIOContext *pb = s->pb; - PacketListEntry *pict_list = aiff->pict_list; - if (!s->metadata && !s->nb_chapters && !aiff->pict_list) + if (!s->metadata && !s->nb_chapters && av_packet_list_peek(aiff->pict_list, NULL, 0)) return 0; avio_wl32(pb, MKTAG('I', 'D', '3', ' ')); @@ -59,10 +59,11 @@ static int put_id3v2_tags(AVFormatContext *s, AIFFOutputContext *aiff) ff_id3v2_start(&id3v2, pb, aiff->id3v2_version, ID3v2_DEFAULT_MAGIC); ff_id3v2_write_metadata(s, &id3v2); - while (pict_list) { - if ((ret = ff_id3v2_write_apic(s, &id3v2, &pict_list->pkt)) < 0) + while (!av_packet_list_get(aiff->pict_list, &pkt, 0)) { + ret = ff_id3v2_write_apic(s, &id3v2, &pkt); + av_packet_unref(&pkt); + if (ret < 0) return ret; - pict_list = pict_list->next; } ff_id3v2_finish(&id3v2, pb, s->metadata_header_padding); @@ -119,6 +120,10 @@ static int aiff_write_header(AVFormatContext *s) return AVERROR(EINVAL); } + aiff->pict_list = av_packet_list_alloc(); + if (!aiff->pict_list) + return AVERROR(ENOMEM); + par = s->streams[aiff->audio_stream_idx]->codecpar; /* First verify if format is ok */ @@ -221,8 +226,7 @@ static int aiff_write_packet(AVFormatContext *s, AVPacket *pkt) if (s->streams[pkt->stream_index]->nb_frames >= 1) return 0; - return avpriv_packet_list_put(&aiff->pict_list, &aiff->pict_list_end, - pkt, av_packet_ref, 0); + return av_packet_list_put(aiff->pict_list, pkt, av_packet_ref, 0); } return 0; @@ -273,7 +277,7 @@ static void aiff_deinit(AVFormatContext *s) { AIFFOutputContext *aiff = s->priv_data; - avpriv_packet_list_free(&aiff->pict_list, &aiff->pict_list_end); + av_packet_list_free(&aiff->pict_list); } #define OFFSET(x) offsetof(AIFFOutputContext, x) From patchwork Wed Nov 18 16:52:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 23706 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 3A3B044B913 for ; Wed, 18 Nov 2020 18:53:39 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2272B68B67A; Wed, 18 Nov 2020 18:53:39 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f193.google.com (mail-qt1-f193.google.com [209.85.160.193]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EBFC168B66D for ; Wed, 18 Nov 2020 18:53:36 +0200 (EET) Received: by mail-qt1-f193.google.com with SMTP id b16so2104851qtb.6 for ; Wed, 18 Nov 2020 08:53: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=PgAmTJdYDU9yglJqXR+4JTmF+e0fx30ZuCm3NQabw2w=; b=VfRyCksN//ClN5yyuXWn0EAExyeoqzNVqzWrGOFDlVtdfj4bwWkcZgE9xLfxx2eCN1 5hAtg9FKqJn+2lFOb3n6iKDRDm4F/vjnjurFoI0KG6l3FS/RCGBnoqS5ZfMjvvRx0N06 ROg7mogJOXPNb4dkuVBm824TF6MyebXmLeAn0Q9r9gimEF+yRD/cFdGCf6XuD6iVOh9n TJq0Kf58Ro2xEm2Is6uivqf+xDMoZZlj0jp8m7T08Mo4eovgV9lANpzIZEgqeSeBbzK2 wjOxwDkmZWnIBECJ7Osv/5GRUkJnR+XfUBx2EU0A7cx/3ocHB3vxi/OAk4Y6TZfHFnCq /SCw== 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=PgAmTJdYDU9yglJqXR+4JTmF+e0fx30ZuCm3NQabw2w=; b=h5gFrqggcVyI8BjlDxN2n1ALaitdIOJOnfdDSIJQ0SARr00jHsSa5oLlZ1pLfs/Mod 2kw8yyaA2Z/aXw9L/vBwPKCIyyd7ybwBgh5UXTCmWCk0Z6jt74w4Kux144Avqkr3vKk3 wvUluNnvQoMSZYlk7xMwO7r7+QDn0HD04WSS1k+tI5/HkmmbmDYs8ppWfTM0gKWUa6jA 8FNCUm7pVZagm5WuWOZHvFblyDgM5Usf2ieLYSCk7UhP8hX0XVYY1BQ8ZOeriMHx1Kiu cTQ/rGvBl6E1AK4eTe0IROiG1DrtCN7U9x2ZhzbwSKslt7ayagSczRpx2zcK0YzhEg9F vN/A== X-Gm-Message-State: AOAM5305eYhIAHYuADpF7upYhsKC5or6T7nWXMbLeBKjo48yWaQWZQES 7DvWPjs7OWOVWp2vnQ6VoTJp3m8q1FY5HQ== X-Google-Smtp-Source: ABdhPJyJbfLBc3W5D7xoe8rvVnk2ZJoEvB9WP8tQ2c4w9lVQ0SfbqhCU9dRW9cIe9rhoPgPZpIdkcA== X-Received: by 2002:aed:2726:: with SMTP id n35mr5097220qtd.254.1605718414968; Wed, 18 Nov 2020 08:53:34 -0800 (PST) Received: from localhost.localdomain ([181.23.91.217]) by smtp.gmail.com with ESMTPSA id f14sm4863788qkk.89.2020.11.18.08.53.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2020 08:53:34 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 18 Nov 2020 13:52:45 -0300 Message-Id: <20201118165247.4130-17-jamrial@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201118165247.4130-1-jamrial@gmail.com> References: <20201118165247.4130-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 16/18] avformat/matroskadec: port to the new packet list API 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 | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 0970e1d1ef..4be31daa93 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -366,8 +366,7 @@ typedef struct MatroskaDemuxContext { int64_t segment_start; /* the packet queue */ - PacketListEntry *queue; - PacketListEntry *queue_end; + AVPacketList *queue; int done; @@ -2872,6 +2871,10 @@ static int matroska_read_header(AVFormatContext *s) } ebml_free(ebml_syntax, &ebml); + matroska->queue = av_packet_list_alloc(); + if (!matroska->queue) + return AVERROR(ENOMEM); + /* The next thing is a segment. */ pos = avio_tell(matroska->ctx->pb); res = ebml_parse(matroska, matroska_segments, matroska); @@ -2988,11 +2991,10 @@ fail: static int matroska_deliver_packet(MatroskaDemuxContext *matroska, AVPacket *pkt) { - if (matroska->queue) { + if (!av_packet_list_get(matroska->queue, pkt, 0)) { MatroskaTrack *tracks = matroska->tracks.elem; MatroskaTrack *track; - avpriv_packet_list_get(&matroska->queue, &matroska->queue_end, pkt); track = &tracks[pkt->stream_index]; if (track->has_palette) { uint8_t *pal = av_packet_new_side_data(pkt, AV_PKT_DATA_PALETTE, AVPALETTE_SIZE); @@ -3014,7 +3016,7 @@ static int matroska_deliver_packet(MatroskaDemuxContext *matroska, */ static void matroska_clear_queue(MatroskaDemuxContext *matroska) { - avpriv_packet_list_free(&matroska->queue, &matroska->queue_end); + av_packet_list_flush(matroska->queue); } static int matroska_parse_laces(MatroskaDemuxContext *matroska, uint8_t **buf, @@ -3180,7 +3182,7 @@ static int matroska_parse_rm_audio(MatroskaDemuxContext *matroska, track->audio.buf_timecode = AV_NOPTS_VALUE; pkt->pos = pos; pkt->stream_index = st->index; - ret = avpriv_packet_list_put(&matroska->queue, &matroska->queue_end, pkt, NULL, 0); + ret = av_packet_list_put(matroska->queue, pkt, NULL, 0); if (ret < 0) { av_packet_unref(pkt); return AVERROR(ENOMEM); @@ -3402,7 +3404,7 @@ static int matroska_parse_webvtt(MatroskaDemuxContext *matroska, pkt->duration = duration; pkt->pos = pos; - err = avpriv_packet_list_put(&matroska->queue, &matroska->queue_end, pkt, NULL, 0); + err = av_packet_list_put(matroska->queue, pkt, NULL, 0); if (err < 0) { av_packet_unref(pkt); return AVERROR(ENOMEM); @@ -3513,7 +3515,7 @@ FF_DISABLE_DEPRECATION_WARNINGS FF_ENABLE_DEPRECATION_WARNINGS #endif - res = avpriv_packet_list_put(&matroska->queue, &matroska->queue_end, pkt, NULL, 0); + res = av_packet_list_put(matroska->queue, pkt, NULL, 0); if (res < 0) { av_packet_unref(pkt); return AVERROR(ENOMEM); @@ -3823,6 +3825,7 @@ static int matroska_read_close(AVFormatContext *s) int n; matroska_clear_queue(matroska); + av_packet_list_free(&matroska->queue); for (n = 0; n < matroska->tracks.nb_elem; n++) if (tracks[n].type == MATROSKA_TRACK_TYPE_AUDIO) @@ -3886,8 +3889,8 @@ static int webm_clusters_start_with_keyframe(AVFormatContext *s) before_pos = avio_tell(s->pb); while (1) { uint64_t cluster_id, cluster_length; - int read; - AVPacket *pkt; + int read, flags; + AVPacket pkt; avio_seek(s->pb, cluster_pos, SEEK_SET); // read cluster id and length read = ebml_read_num(matroska, matroska->ctx->pb, 4, &cluster_id, 1); @@ -3900,13 +3903,15 @@ static int webm_clusters_start_with_keyframe(AVFormatContext *s) matroska_reset_status(matroska, 0, cluster_pos); matroska_clear_queue(matroska); if (matroska_parse_cluster(matroska) < 0 || - !matroska->queue) { + av_packet_list_peek(matroska->queue, NULL, 0)) { break; } - pkt = &matroska->queue->pkt; + av_packet_list_peek(matroska->queue, &pkt, 0); + flags = pkt.flags; + av_packet_unref(&pkt); // 4 + read is the length of the cluster id and the cluster length field. cluster_pos += 4 + read + cluster_length; - if (!(pkt->flags & AV_PKT_FLAG_KEY)) { + if (!(flags & AV_PKT_FLAG_KEY)) { rv = 0; break; } From patchwork Wed Nov 18 16:52:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 23707 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 75D9944B913 for ; Wed, 18 Nov 2020 18:53:40 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 309D168B698; Wed, 18 Nov 2020 18:53:40 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f194.google.com (mail-qt1-f194.google.com [209.85.160.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3964768B650 for ; Wed, 18 Nov 2020 18:53:38 +0200 (EET) Received: by mail-qt1-f194.google.com with SMTP id v11so2053758qtq.12 for ; Wed, 18 Nov 2020 08:53: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=epLr6oxZNma5+M6zGWHtVRcGA963cxte5SR4NPnTGx4=; b=filWaetyRN+bzYho96ZSHKYJPv++p3MGjzCvpdidmACTCKW07aA2NSrJSHo5K42ua6 KasEHerWqKmnZjvBUk6+m+azM9NmShW9M+KAzScTNd8ejfYJYbNt6qu2INr068aXKEO5 ftLVYNSYqF+iTtBzXjF6P0DNyOAU6EXzdRd/YPBhLllfMSCXaA+qdITNL9JhPCcsasXV hOReXcGAcYlL5qz/WH+wa3NVg3QxzfYsPpKq9eTgw32X+9oprcVRDKCCKowotFTZZJhh +2y/XVA7m5DstN0L4Z6vIN38prRCCKXauk76HsaoZooXvMA/dM3qTPGQJ9Yj+tjJm8Zp iOSA== 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=epLr6oxZNma5+M6zGWHtVRcGA963cxte5SR4NPnTGx4=; b=EWkgyWh6oRCpodzlQslI822N3h52T57qeM0RfbSfIBACAbffCPFQ02EGTm3yl4GvYo Pkc7ODgM8s52eA7TiRqjARlEfJu336TomnSzY4UDTb8qp5N+i5Q4Az/OPi1BZeJPKkju vZnDQAwYab0RFtS2v286KUqDTirFhF96kLwj3K6WfF3vvDMEhya1BIjGoYhpcXH33Ykb peow6R1YONkSR5XK+PM0/9cXjo51Tl81KZarugUGW3cxPKNsKucx9ZkzM6xOqQAvFEed sd+HlnahKy+N9ndwsa3EspgO0CCpoxf9oxx7WCf4gOX5BNNaGW/YuDU3x1caW2mGeWgB IyCw== X-Gm-Message-State: AOAM533oz5PvsT0yhzv3bjqmWMNaePc3dEWYGNnVlmX/PhKOa8amlmAQ yzk2QOMYMiwoGrRueFgS+hoZMIchNvYRyA== X-Google-Smtp-Source: ABdhPJwiZeXRdSD1Pavep94UoPMFRRwbObC4lZWtKBrxEqtu73XBk92VikxEePMrewxkDVIOShuoUQ== X-Received: by 2002:ac8:5553:: with SMTP id o19mr5430449qtr.32.1605718416575; Wed, 18 Nov 2020 08:53:36 -0800 (PST) Received: from localhost.localdomain ([181.23.91.217]) by smtp.gmail.com with ESMTPSA id f14sm4863788qkk.89.2020.11.18.08.53.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2020 08:53:35 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 18 Nov 2020 13:52:46 -0300 Message-Id: <20201118165247.4130-18-jamrial@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201118165247.4130-1-jamrial@gmail.com> References: <20201118165247.4130-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 17/18] avcodec/avpacket: schedule the removal of avpriv_packet_list_* 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 --- Maybe we can remove this right away? It's not in any release. libavcodec/avpacket.c | 2 ++ libavcodec/packet_internal.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c index c79200b63b..0db47c1d62 100644 --- a/libavcodec/avpacket.c +++ b/libavcodec/avpacket.c @@ -726,6 +726,7 @@ FF_ENABLE_DEPRECATION_WARNINGS #endif } +#if LIBAVCODEC_VERSION_MAJOR < 59 int avpriv_packet_list_put(PacketListEntry **packet_buffer, PacketListEntry **plast_pktl, AVPacket *pkt, @@ -792,6 +793,7 @@ void avpriv_packet_list_free(PacketListEntry **pkt_buf, PacketListEntry **pkt_bu *pkt_buf = NULL; *pkt_buf_end = NULL; } +#endif AVPacketList *av_packet_list_alloc(void) { diff --git a/libavcodec/packet_internal.h b/libavcodec/packet_internal.h index 2774d75a7e..fd9637bc44 100644 --- a/libavcodec/packet_internal.h +++ b/libavcodec/packet_internal.h @@ -38,6 +38,7 @@ struct AVPacketList { PacketListEntry *tail; }; +#if LIBAVCODEC_VERSION_MAJOR < 59 /** * Append an AVPacket to the list. * @@ -78,6 +79,7 @@ int avpriv_packet_list_get(PacketListEntry **head, PacketListEntry **tail, * @param tail List tail element */ void avpriv_packet_list_free(PacketListEntry **head, PacketListEntry **tail); +#endif int ff_side_data_set_encoder_stats(AVPacket *pkt, int quality, int64_t *error, int error_count, int pict_type); From patchwork Wed Nov 18 16:52:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 23708 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 839E944B913 for ; Wed, 18 Nov 2020 18:53:44 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6B90068B6C5; Wed, 18 Nov 2020 18:53:44 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f194.google.com (mail-qt1-f194.google.com [209.85.160.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C519668B6BF for ; Wed, 18 Nov 2020 18:53:39 +0200 (EET) Received: by mail-qt1-f194.google.com with SMTP id p12so2093020qtp.7 for ; Wed, 18 Nov 2020 08:53:39 -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=w4kIUalymEnBJIIrazpA6T2V6yHg+vZ0BwAdNP/VbCI=; b=K/c+Zw3MLJQDo0GzP2Vrc6VdyZEXyBJAXiFx/JvdYVOSu1UOqH0q742NtrriMZkfDt AJtT8TzKrIfJy5np5yumCtJlAIjaCtIzhrHGoOCc2Jpr9b42gcZxHPgr0SgLSyBg8iLi Q7hgDgbdVPYSltjOLzGD0pvXQhOAzIlmvZkmxYUMgOIspguGBug0nXl48JD/+1xAn99l 908W8nC1a6rXNtmSXTnSSpaz2O2JhE9o6mVt8BZFXzOijc4vh67THj+Jb/aSHLOsnlPu pbSXlvcEbak2tvBAtWm59Zr1dQG4+rBFc+Sc6t8ZyzygC5TEBoHcaw1+oETjo5yT1VF4 dITg== 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=w4kIUalymEnBJIIrazpA6T2V6yHg+vZ0BwAdNP/VbCI=; b=Wo0Ug0XMHK+wOs16kbMPwZAOx9z5PSWFs0RyockMVPL6TkcAXTtRjr7kC6xLXR/+Sw +pFNQHgSfia/qC4kClyZxLRsVODBnghhxTQIiIR87mXpO3x6FE3aMnZn7Fx77hXE1RzN vhdFmlN2VxGn1YjnFyoYLXOeZkeuAcu9mDiCnwoftgfRolBv5XuwXMH48Av6gKAi9aYg SoAyHTetYoZWeV82wZiK9y6C7KXEPPN8pxpXb4lTsHuxbhqzh9eNdaU4rtWr4Qz6gRWz fiapZNr3JXcdaqQTQvM2zzaaNR0vHyU5G/E7+Kc6i2WZZKzT2zPXhwexsRCB5Xtznxs2 kYCA== X-Gm-Message-State: AOAM530JxBVeni7lzauVAvBCzuSITa2OXHAgqDOS4lpKlbYn14D9X7nz +KfupJrjjhnuWiV9qwfXGU7TKys0Tw/rEQ== X-Google-Smtp-Source: ABdhPJxQ9zxHehp21Ci0UwIQete/cdvoHvrLwnAzc4dzYzO1PbYRYvKooIVs/0jaYLn11xCS6tsp5g== X-Received: by 2002:ac8:5351:: with SMTP id d17mr5627775qto.235.1605718418136; Wed, 18 Nov 2020 08:53:38 -0800 (PST) Received: from localhost.localdomain ([181.23.91.217]) by smtp.gmail.com with ESMTPSA id f14sm4863788qkk.89.2020.11.18.08.53.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2020 08:53:37 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 18 Nov 2020 13:52:47 -0300 Message-Id: <20201118165247.4130-19-jamrial@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201118165247.4130-1-jamrial@gmail.com> References: <20201118165247.4130-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [RFC][PATCH 18/18] avcodec/avpacket: make the AVPacketList API thread safe 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 --- I don't know if this is necessary, so i'm sending it as an RFC. libavcodec/avpacket.c | 34 +++++++++++++++++++++++++++++++--- libavcodec/packet_internal.h | 2 ++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c index 0db47c1d62..a8e934913e 100644 --- a/libavcodec/avpacket.c +++ b/libavcodec/avpacket.c @@ -807,6 +807,8 @@ AVPacketList *av_packet_list_alloc(void) if (!pktl) return NULL; + ff_mutex_init(&pktl->mutex, NULL); + return (AVPacketList *)pktl; } @@ -840,6 +842,7 @@ int av_packet_list_put(AVPacketList *list, AVPacket *pkt, av_packet_move_ref(&pktle->pkt, pkt); } + ff_mutex_lock(&pktl->mutex); if (pktl->head) pktl->tail->next = pktle; else @@ -847,6 +850,7 @@ int av_packet_list_put(AVPacketList *list, AVPacket *pkt, /* Add the packet in the buffered packet list. */ pktl->tail = pktle; + ff_mutex_unlock(&pktl->mutex); return 0; } @@ -861,8 +865,11 @@ int av_packet_list_get(AVPacketList *list, AVPacket *pkt, AVPacketList *pktl = list; #endif - if (!pktl->head) + ff_mutex_lock(&pktl->mutex); + if (!pktl->head) { + ff_mutex_unlock(&pktl->mutex); return AVERROR(EAGAIN); + } pktle = pktl->head; if (pkt) @@ -873,6 +880,7 @@ int av_packet_list_get(AVPacketList *list, AVPacket *pkt, if (!pktle->next) pktl->tail = NULL; + ff_mutex_unlock(&pktl->mutex); av_freep(&pktle); @@ -891,14 +899,20 @@ int av_packet_list_peek(AVPacketList *list, AVPacket *pkt, AVPacket tmp = { 0 }; int ret; - if (!pktl->head) + ff_mutex_lock(&pktl->mutex); + if (!pktl->head) { + ff_mutex_unlock(&pktl->mutex); return AVERROR(EAGAIN); + } - if (!pkt) + if (!pkt) { + ff_mutex_unlock(&pktl->mutex); return 0; + } pktle = pktl->head; ret = av_packet_ref(&tmp, &pktle->pkt); + ff_mutex_unlock(&pktl->mutex); if (ret < 0) return ret; @@ -915,6 +929,7 @@ void av_packet_list_flush(AVPacketList *list) AVPacketList *pktl = list; #endif + ff_mutex_lock(&pktl->mutex); while (pktl->head) { PacketListEntry *pktle = pktl->head; pktl->head = pktle->next; @@ -923,16 +938,29 @@ void av_packet_list_flush(AVPacketList *list) } pktl->tail = NULL; + ff_mutex_unlock(&pktl->mutex); } void av_packet_list_free(AVPacketList **plist) { AVPacketList *list = *plist; +#if FF_API_PACKET_LIST + struct PacketList *pktl; +#else + AVPacketList *pktl; +#endif if (!list) return; +#if FF_API_PACKET_LIST + pktl = (struct PacketList *)list; +#else + pktl = list; +#endif + av_packet_list_flush(list); + ff_mutex_destroy(&pktl->mutex); av_freep(plist); } diff --git a/libavcodec/packet_internal.h b/libavcodec/packet_internal.h index fd9637bc44..4cb3fb4bbd 100644 --- a/libavcodec/packet_internal.h +++ b/libavcodec/packet_internal.h @@ -21,6 +21,7 @@ #include +#include "libavutil/thread.h" #include "packet.h" typedef struct PacketListEntry { @@ -36,6 +37,7 @@ struct AVPacketList { #endif PacketListEntry *head; PacketListEntry *tail; + AVMutex mutex; }; #if LIBAVCODEC_VERSION_MAJOR < 59