From patchwork Mon Sep 7 14:31: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: 22160 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 8414144B0D8 for ; Mon, 7 Sep 2020 17:32:34 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 625606881C6; Mon, 7 Sep 2020 17:32:34 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f194.google.com (mail-qk1-f194.google.com [209.85.222.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3611B6881C6 for ; Mon, 7 Sep 2020 17:32:27 +0300 (EEST) Received: by mail-qk1-f194.google.com with SMTP id d20so12799806qka.5 for ; Mon, 07 Sep 2020 07:32:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=3VMEgqRBob491HYZmrHj5ufd1ExCYhSP3uY6Tn/wBZk=; b=c2Kw3iYDzSieJUcyG/BsVEPuioqpThR3riKY1QITgwzEiRibXO+2eEDIhU81343pFs 3wPipkSeFsW2qMvs78W6jodVq8ADjy3QLFx2dKLOvf+jVPZf/91zms3iG2zj7Yf1ijkp 8ckqoX1sUHhCA7J04jD4fKKBbml8elbmfdOZonpVTYl/mh5XJJZw+ShvZ6TWo8HDZKG3 7v+bgmYG/3eDfmxRc0ij0th9b6a/YTe7F1bQVcaVUSc8fqxJFwNndwpYRw19XtcHyRxI FA6NPVkSAQDlhOlnLWHzTen+u1/UUoUqGpXKfgDtN5m6ZJRW8/82Q3ujPXZsadfoXRXq ZXeA== 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:mime-version :content-transfer-encoding; bh=3VMEgqRBob491HYZmrHj5ufd1ExCYhSP3uY6Tn/wBZk=; b=Fpl+NJ4fu91HNOD6k9+jucmWBkeo2IFhSEZAGC0EVjSy4Lhz7lBs+UNTWDkCGAeBMR Ph5DQiBB31/P3HApWPTRXfG3KXJmPCTrEEypHXQWhHitc6an2Zj9t9ze1ECVwSa2zGV6 g5hmfjtvfEtJp0Yn+1OmOv4XdQL8/7Ihkyq+usMIOfI3mSRnhJtp82B1Fb5i/r/u/ByV D6HA1qJZ/IAT315i20UY6W2K/6UGfuFnFLybxxm1LB3UmrCkGf3q0AbV/l4LlzQySgDd L0DB6Sqr7sgJHVZV2aw/UL8kOfdzH5rhsZcorK74NiZLZBCft6tn3PPNFf7oKibgr6Sq //dg== X-Gm-Message-State: AOAM5325RcCPJabefNyJxdWqp0urvue2SUmyWAKi+N9I6sgTwEAR3k/n nfElejE6cbeczlagOipvdXnULbuKuUk= X-Google-Smtp-Source: ABdhPJziUN4haNZib/1iuYJ/EzuSNMQAjivFvA2bTOdS8dVRvCElHUbPKdxTbiaJyvACA+d4tqc2FA== X-Received: by 2002:a05:620a:64b:: with SMTP id a11mr19097208qka.313.1599489144874; Mon, 07 Sep 2020 07:32:24 -0700 (PDT) Received: from localhost.localdomain ([191.83.213.149]) by smtp.gmail.com with ESMTPSA id z19sm11856245qtb.37.2020.09.07.07.32.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 07:32:24 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Mon, 7 Sep 2020 11:31:47 -0300 Message-Id: <20200907143148.25152-1-jamrial@gmail.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2 v3] avcodec/packet: move AVPacketList definition and function helpers over from libavformat 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" And replace the flags parameter with a function callback that can be used to copy the contents of the packet (e.g, av_packet_ref and av_packet_copy_props). Signed-off-by: James Almer --- This version achieves the same effect as v2 while being cleaner. I could leave the flags parameter, too, for the sake of keeping the function easily extensible without having to wait for a major bump. libavcodec/avpacket.c | 66 ++++++++++++++++++++++++ libavcodec/packet.h | 5 ++ libavcodec/packet_internal.h | 41 +++++++++++++++ libavformat/aiffenc.c | 7 +-- libavformat/avformat.h | 6 --- libavformat/flacenc.c | 7 +-- libavformat/internal.h | 42 ---------------- libavformat/matroskadec.c | 11 ++-- libavformat/mp3enc.c | 7 +-- libavformat/ttaenc.c | 9 ++-- libavformat/utils.c | 98 +++++++----------------------------- 11 files changed, 153 insertions(+), 146 deletions(-) diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c index 4801163227..e4e35900f2 100644 --- a/libavcodec/avpacket.c +++ b/libavcodec/avpacket.c @@ -726,6 +726,72 @@ FF_ENABLE_DEPRECATION_WARNINGS #endif } +int avpriv_packet_list_put(AVPacketList **packet_buffer, + AVPacketList **plast_pktl, + AVPacket *pkt, + int (*copy)(AVPacket *dst, const AVPacket *src)) +{ + AVPacketList *pktl = av_mallocz(sizeof(AVPacketList)); + int ret; + + if (!pktl) + return AVERROR(ENOMEM); + + if (copy) { + ret = copy(&pktl->pkt, pkt); + if (ret < 0) { + av_free(pktl); + return ret; + } + } else { + ret = av_packet_make_refcounted(pkt); + if (ret < 0) { + av_free(pktl); + return ret; + } + av_packet_move_ref(&pktl->pkt, pkt); + } + + if (*packet_buffer) + (*plast_pktl)->next = pktl; + else + *packet_buffer = pktl; + + /* Add the packet in the buffered packet list. */ + *plast_pktl = pktl; + return 0; +} + +int avpriv_packet_list_get(AVPacketList **pkt_buffer, + AVPacketList **pkt_buffer_end, + AVPacket *pkt) +{ + AVPacketList *pktl; + if (!*pkt_buffer) + return AVERROR(EAGAIN); + pktl = *pkt_buffer; + *pkt = pktl->pkt; + *pkt_buffer = pktl->next; + if (!pktl->next) + *pkt_buffer_end = NULL; + av_freep(&pktl); + return 0; +} + +void avpriv_packet_list_free(AVPacketList **pkt_buf, AVPacketList **pkt_buf_end) +{ + AVPacketList *tmp = *pkt_buf; + + while (tmp) { + AVPacketList *pktl = tmp; + tmp = pktl->next; + av_packet_unref(&pktl->pkt); + av_freep(&pktl); + } + *pkt_buf = NULL; + *pkt_buf_end = NULL; +} + 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 0a19a0eff3..b9d4c9c2c8 100644 --- a/libavcodec/packet.h +++ b/libavcodec/packet.h @@ -393,6 +393,11 @@ typedef struct AVPacket { #endif } AVPacket; +typedef struct AVPacketList { + AVPacket pkt; + struct AVPacketList *next; +} AVPacketList; + #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 cdb9a27f2f..f2b058e669 100644 --- a/libavcodec/packet_internal.h +++ b/libavcodec/packet_internal.h @@ -23,6 +23,47 @@ #include "packet.h" + +/** + * Append an AVPacket to the list. + * + * @param head List head element + * @param tail List tail element + * @param pkt The packet being appended. The data described in it will + * be made reference counted if it isn't already. + * @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. + * @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, + AVPacket *pkt, + int (*copy)(AVPacket *dst, const AVPacket *src)); + +/** + * Remove the oldest AVPacket in the list and return it. + * + * @note The pkt will be overwritten completely on success. The caller + * owns the packet and must unref it by itself. + * + * @param head List head element + * @param tail List tail element + * @param pkt Pointer to an AVPacket struct + * @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, + AVPacket *pkt); + +/** + * Wipe the list and unref all the packets in it. + * + * @param head List head element + * @param tail List tail element + */ +void avpriv_packet_list_free(AVPacketList **head, AVPacketList **tail); + int ff_side_data_set_encoder_stats(AVPacket *pkt, int quality, int64_t *error, int error_count, int pict_type); int ff_side_data_set_prft(AVPacket *pkt, int64_t timestamp); diff --git a/libavformat/aiffenc.c b/libavformat/aiffenc.c index 88c45df334..6ac4d98024 100644 --- a/libavformat/aiffenc.c +++ b/libavformat/aiffenc.c @@ -23,6 +23,7 @@ #include "libavutil/intfloat.h" #include "libavutil/opt.h" +#include "libavcodec/packet_internal.h" #include "avformat.h" #include "internal.h" #include "aiff.h" @@ -220,8 +221,8 @@ static int aiff_write_packet(AVFormatContext *s, AVPacket *pkt) if (s->streams[pkt->stream_index]->nb_frames >= 1) return 0; - return ff_packet_list_put(&aiff->pict_list, &aiff->pict_list_end, - pkt, FF_PACKETLIST_FLAG_REF_PACKET); + return avpriv_packet_list_put(&aiff->pict_list, &aiff->pict_list_end, + pkt, av_packet_ref); } return 0; @@ -272,7 +273,7 @@ static void aiff_deinit(AVFormatContext *s) { AIFFOutputContext *aiff = s->priv_data; - ff_packet_list_free(&aiff->pict_list, &aiff->pict_list_end); + avpriv_packet_list_free(&aiff->pict_list, &aiff->pict_list_end); } #define OFFSET(x) offsetof(AIFFOutputContext, x) diff --git a/libavformat/avformat.h b/libavformat/avformat.h index e91e7f1d33..c8c0b6c08d 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -2007,12 +2007,6 @@ void av_format_inject_global_side_data(AVFormatContext *s); */ enum AVDurationEstimationMethod av_fmt_ctx_get_duration_estimation_method(const AVFormatContext* ctx); -typedef struct AVPacketList { - AVPacket pkt; - struct AVPacketList *next; -} AVPacketList; - - /** * @defgroup lavf_core Core functions * @ingroup libavf diff --git a/libavformat/flacenc.c b/libavformat/flacenc.c index b947a3b067..e68e4f0b9d 100644 --- a/libavformat/flacenc.c +++ b/libavformat/flacenc.c @@ -23,6 +23,7 @@ #include "libavutil/opt.h" #include "libavutil/pixdesc.h" #include "libavcodec/flac.h" +#include "libavcodec/packet_internal.h" #include "avformat.h" #include "avio_internal.h" #include "flacenc.h" @@ -305,7 +306,7 @@ static int flac_queue_flush(AVFormatContext *s) write = 0; while (c->queue) { - ff_packet_list_get(&c->queue, &c->queue_end, &pkt); + avpriv_packet_list_get(&c->queue, &c->queue_end, &pkt); if (write && (ret = flac_write_audio_packet(s, &pkt)) < 0) write = 0; av_packet_unref(&pkt); @@ -345,7 +346,7 @@ static void flac_deinit(struct AVFormatContext *s) { FlacMuxerContext *c = s->priv_data; - ff_packet_list_free(&c->queue, &c->queue_end); + avpriv_packet_list_free(&c->queue, &c->queue_end); } static int flac_write_packet(struct AVFormatContext *s, AVPacket *pkt) @@ -356,7 +357,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 = ff_packet_list_put(&c->queue, &c->queue_end, pkt, FF_PACKETLIST_FLAG_REF_PACKET); + ret = avpriv_packet_list_put(&c->queue, &c->queue_end, pkt, av_packet_ref); if (ret < 0) { av_log(s, AV_LOG_ERROR, "Out of memory in packet queue; skipping attached pictures\n"); c->waiting_pics = 0; diff --git a/libavformat/internal.h b/libavformat/internal.h index 17a6ab07d3..f4174628e0 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -730,48 +730,6 @@ int ff_unlock_avformat(void); */ void ff_format_set_url(AVFormatContext *s, char *url); -#define FF_PACKETLIST_FLAG_REF_PACKET (1 << 0) /**< Create a new reference for the packet instead of - transferring the ownership of the existing one to the - list. */ - -/** - * Append an AVPacket to the list. - * - * @param head List head element - * @param tail List tail element - * @param pkt The packet being appended. The data described in it will - * be made reference counted if it isn't already. - * @param flags Any combination of FF_PACKETLIST_FLAG_* flags - * @return 0 on success, negative AVERROR value on failure. On failure, - the list is unchanged - */ -int ff_packet_list_put(AVPacketList **head, AVPacketList **tail, - AVPacket *pkt, int flags); - -/** - * Remove the oldest AVPacket in the list and return it. - * The behaviour is undefined if the packet list is empty. - * - * @note The pkt will be overwritten completely. The caller owns the - * packet and must unref it by itself. - * - * @param head List head element - * @param tail List tail element - * @param pkt Pointer to an AVPacket struct - * @return 0 on success. Success is guaranteed - * if the packet list is not empty. - */ -int ff_packet_list_get(AVPacketList **head, AVPacketList **tail, - AVPacket *pkt); - -/** - * Wipe the list and unref all the packets in it. - * - * @param head List head element - * @param tail List tail element - */ -void ff_packet_list_free(AVPacketList **head, AVPacketList **tail); - void avpriv_register_devices(const AVOutputFormat * const o[], const AVInputFormat * const i[]); #endif /* AVFORMAT_INTERNAL_H */ diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index b1ef344aa7..b9f47961ec 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -48,6 +48,7 @@ #include "libavcodec/bytestream.h" #include "libavcodec/flac.h" #include "libavcodec/mpeg4audio.h" +#include "libavcodec/packet_internal.h" #include "avformat.h" #include "avio_internal.h" @@ -2991,7 +2992,7 @@ static int matroska_deliver_packet(MatroskaDemuxContext *matroska, MatroskaTrack *tracks = matroska->tracks.elem; MatroskaTrack *track; - ff_packet_list_get(&matroska->queue, &matroska->queue_end, pkt); + 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); @@ -3013,7 +3014,7 @@ static int matroska_deliver_packet(MatroskaDemuxContext *matroska, */ static void matroska_clear_queue(MatroskaDemuxContext *matroska) { - ff_packet_list_free(&matroska->queue, &matroska->queue_end); + avpriv_packet_list_free(&matroska->queue, &matroska->queue_end); } static int matroska_parse_laces(MatroskaDemuxContext *matroska, uint8_t **buf, @@ -3179,7 +3180,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 = ff_packet_list_put(&matroska->queue, &matroska->queue_end, pkt, 0); + ret = avpriv_packet_list_put(&matroska->queue, &matroska->queue_end, pkt, NULL); if (ret < 0) { av_packet_unref(pkt); return AVERROR(ENOMEM); @@ -3401,7 +3402,7 @@ static int matroska_parse_webvtt(MatroskaDemuxContext *matroska, pkt->duration = duration; pkt->pos = pos; - err = ff_packet_list_put(&matroska->queue, &matroska->queue_end, pkt, 0); + err = avpriv_packet_list_put(&matroska->queue, &matroska->queue_end, pkt, NULL); if (err < 0) { av_packet_unref(pkt); return AVERROR(ENOMEM); @@ -3512,7 +3513,7 @@ FF_DISABLE_DEPRECATION_WARNINGS FF_ENABLE_DEPRECATION_WARNINGS #endif - res = ff_packet_list_put(&matroska->queue, &matroska->queue_end, pkt, 0); + res = avpriv_packet_list_put(&matroska->queue, &matroska->queue_end, pkt, NULL); if (res < 0) { av_packet_unref(pkt); return AVERROR(ENOMEM); diff --git a/libavformat/mp3enc.c b/libavformat/mp3enc.c index a3586e1f86..fc8101b30b 100644 --- a/libavformat/mp3enc.c +++ b/libavformat/mp3enc.c @@ -28,6 +28,7 @@ #include "libavcodec/mpegaudio.h" #include "libavcodec/mpegaudiodata.h" #include "libavcodec/mpegaudiodecheader.h" +#include "libavcodec/packet_internal.h" #include "libavutil/intreadwrite.h" #include "libavutil/opt.h" #include "libavutil/dict.h" @@ -387,7 +388,7 @@ static int mp3_queue_flush(AVFormatContext *s) mp3_write_xing(s); while (mp3->queue) { - ff_packet_list_get(&mp3->queue, &mp3->queue_end, &pkt); + avpriv_packet_list_get(&mp3->queue, &mp3->queue_end, &pkt); if (write && (ret = mp3_write_audio_packet(s, &pkt)) < 0) write = 0; av_packet_unref(&pkt); @@ -522,7 +523,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 = ff_packet_list_put(&mp3->queue, &mp3->queue_end, pkt, FF_PACKETLIST_FLAG_REF_PACKET); + int ret = avpriv_packet_list_put(&mp3->queue, &mp3->queue_end, pkt, av_packet_ref); if (ret < 0) { av_log(s, AV_LOG_WARNING, "Not enough memory to buffer audio. Skipping picture streams\n"); @@ -630,7 +631,7 @@ static void mp3_deinit(struct AVFormatContext *s) { MP3Context *mp3 = s->priv_data; - ff_packet_list_free(&mp3->queue, &mp3->queue_end); + avpriv_packet_list_free(&mp3->queue, &mp3->queue_end); av_freep(&mp3->xing_frame); } diff --git a/libavformat/ttaenc.c b/libavformat/ttaenc.c index becd3e7153..871e2530b9 100644 --- a/libavformat/ttaenc.c +++ b/libavformat/ttaenc.c @@ -22,6 +22,7 @@ #include "libavutil/crc.h" #include "libavutil/intreadwrite.h" +#include "libavcodec/packet_internal.h" #include "apetag.h" #include "avformat.h" #include "avio_internal.h" @@ -93,8 +94,8 @@ static int tta_write_packet(AVFormatContext *s, AVPacket *pkt) TTAMuxContext *tta = s->priv_data; int ret; - ret = ff_packet_list_put(&tta->queue, &tta->queue_end, pkt, - FF_PACKETLIST_FLAG_REF_PACKET); + ret = avpriv_packet_list_put(&tta->queue, &tta->queue_end, pkt, + av_packet_ref); if (ret < 0) { return ret; } @@ -125,7 +126,7 @@ static void tta_queue_flush(AVFormatContext *s) AVPacket pkt; while (tta->queue) { - ff_packet_list_get(&tta->queue, &tta->queue_end, &pkt); + avpriv_packet_list_get(&tta->queue, &tta->queue_end, &pkt); avio_write(s->pb, pkt.data, pkt.size); av_packet_unref(&pkt); } @@ -161,7 +162,7 @@ static void tta_deinit(AVFormatContext *s) TTAMuxContext *tta = s->priv_data; ffio_free_dyn_buf(&tta->seek_table); - ff_packet_list_free(&tta->queue, &tta->queue_end); + avpriv_packet_list_free(&tta->queue, &tta->queue_end); } AVOutputFormat ff_tta_muxer = { diff --git a/libavformat/utils.c b/libavformat/utils.c index 807d9f10cb..ad3f7a2a08 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -37,6 +37,7 @@ #include "libavcodec/bytestream.h" #include "libavcodec/internal.h" +#include "libavcodec/packet_internal.h" #include "libavcodec/raw.h" #include "avformat.h" @@ -438,40 +439,6 @@ static int init_input(AVFormatContext *s, const char *filename, s, 0, s->format_probesize); } -int ff_packet_list_put(AVPacketList **packet_buffer, - AVPacketList **plast_pktl, - AVPacket *pkt, int flags) -{ - AVPacketList *pktl = av_mallocz(sizeof(AVPacketList)); - int ret; - - if (!pktl) - return AVERROR(ENOMEM); - - if (flags & FF_PACKETLIST_FLAG_REF_PACKET) { - if ((ret = av_packet_ref(&pktl->pkt, pkt)) < 0) { - av_free(pktl); - return ret; - } - } else { - ret = av_packet_make_refcounted(pkt); - if (ret < 0) { - av_free(pktl); - return ret; - } - av_packet_move_ref(&pktl->pkt, pkt); - } - - if (*packet_buffer) - (*plast_pktl)->next = pktl; - else - *packet_buffer = pktl; - - /* Add the packet in the buffered packet list. */ - *plast_pktl = pktl; - return 0; -} - int avformat_queue_attached_pictures(AVFormatContext *s) { int i, ret; @@ -485,10 +452,10 @@ int avformat_queue_attached_pictures(AVFormatContext *s) continue; } - ret = ff_packet_list_put(&s->internal->raw_packet_buffer, + ret = avpriv_packet_list_put(&s->internal->raw_packet_buffer, &s->internal->raw_packet_buffer_end, &s->streams[i]->attached_pic, - FF_PACKETLIST_FLAG_REF_PACKET); + av_packet_ref); if (ret < 0) return ret; } @@ -841,7 +808,7 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt) if ((err = probe_codec(s, st, NULL)) < 0) return err; if (st->request_probe <= 0) { - ff_packet_list_get(&s->internal->raw_packet_buffer, + avpriv_packet_list_get(&s->internal->raw_packet_buffer, &s->internal->raw_packet_buffer_end, pkt); s->internal->raw_packet_buffer_remaining_size += pkt->size; return 0; @@ -914,9 +881,9 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt) if (!pktl && st->request_probe <= 0) return ret; - err = ff_packet_list_put(&s->internal->raw_packet_buffer, + err = avpriv_packet_list_put(&s->internal->raw_packet_buffer, &s->internal->raw_packet_buffer_end, - pkt, 0); + pkt, NULL); if (err < 0) { av_packet_unref(pkt); return err; @@ -1420,20 +1387,6 @@ FF_ENABLE_DEPRECATION_WARNINGS #endif } -void ff_packet_list_free(AVPacketList **pkt_buf, AVPacketList **pkt_buf_end) -{ - AVPacketList *tmp = *pkt_buf; - - while (tmp) { - AVPacketList *pktl = tmp; - tmp = pktl->next; - av_packet_unref(&pktl->pkt); - av_freep(&pktl); - } - *pkt_buf = NULL; - *pkt_buf_end = NULL; -} - /** * Parse a packet, add all split parts to parse_queue. * @@ -1530,9 +1483,9 @@ static int parse_packet(AVFormatContext *s, AVPacket *pkt, compute_pkt_fields(s, st, st->parser, &out_pkt, next_dts, next_pts); - ret = ff_packet_list_put(&s->internal->parse_queue, + ret = avpriv_packet_list_put(&s->internal->parse_queue, &s->internal->parse_queue_end, - &out_pkt, 0); + &out_pkt, NULL); if (ret < 0) { av_packet_unref(&out_pkt); goto fail; @@ -1550,21 +1503,6 @@ fail: return ret; } -int ff_packet_list_get(AVPacketList **pkt_buffer, - AVPacketList **pkt_buffer_end, - AVPacket *pkt) -{ - AVPacketList *pktl; - av_assert0(*pkt_buffer); - pktl = *pkt_buffer; - *pkt = pktl->pkt; - *pkt_buffer = pktl->next; - if (!pktl->next) - *pkt_buffer_end = NULL; - av_freep(&pktl); - return 0; -} - static int64_t ts_to_samples(AVStream *st, int64_t ts) { return av_rescale(ts, st->time_base.num * st->codecpar->sample_rate, st->time_base.den); @@ -1695,7 +1633,7 @@ FF_ENABLE_DEPRECATION_WARNINGS } if (!got_packet && s->internal->parse_queue) - ret = ff_packet_list_get(&s->internal->parse_queue, &s->internal->parse_queue_end, pkt); + ret = avpriv_packet_list_get(&s->internal->parse_queue, &s->internal->parse_queue_end, pkt); if (ret >= 0) { AVStream *st = s->streams[pkt->stream_index]; @@ -1779,7 +1717,7 @@ int av_read_frame(AVFormatContext *s, AVPacket *pkt) if (!genpts) { ret = s->internal->packet_buffer - ? ff_packet_list_get(&s->internal->packet_buffer, + ? avpriv_packet_list_get(&s->internal->packet_buffer, &s->internal->packet_buffer_end, pkt) : read_frame_internal(s, pkt); if (ret < 0) @@ -1828,7 +1766,7 @@ int av_read_frame(AVFormatContext *s, AVPacket *pkt) 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 = ff_packet_list_get(&s->internal->packet_buffer, + ret = avpriv_packet_list_get(&s->internal->packet_buffer, &s->internal->packet_buffer_end, pkt); goto return_packet; } @@ -1843,9 +1781,9 @@ int av_read_frame(AVFormatContext *s, AVPacket *pkt) return ret; } - ret = ff_packet_list_put(&s->internal->packet_buffer, + ret = avpriv_packet_list_put(&s->internal->packet_buffer, &s->internal->packet_buffer_end, - pkt, 0); + pkt, NULL); if (ret < 0) { av_packet_unref(pkt); return ret; @@ -1873,9 +1811,9 @@ static void flush_packet_queue(AVFormatContext *s) { if (!s->internal) return; - ff_packet_list_free(&s->internal->parse_queue, &s->internal->parse_queue_end); - ff_packet_list_free(&s->internal->packet_buffer, &s->internal->packet_buffer_end); - ff_packet_list_free(&s->internal->raw_packet_buffer, &s->internal->raw_packet_buffer_end); + 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); + 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; } @@ -3832,9 +3770,9 @@ FF_ENABLE_DEPRECATION_WARNINGS } if (!(ic->flags & AVFMT_FLAG_NOBUFFER)) { - ret = ff_packet_list_put(&ic->internal->packet_buffer, + ret = avpriv_packet_list_put(&ic->internal->packet_buffer, &ic->internal->packet_buffer_end, - &pkt1, 0); + &pkt1, NULL); if (ret < 0) goto unref_then_goto_end;