diff options
-rw-r--r-- | libavcodec/avpacket.c | 36 | ||||
-rw-r--r-- | libavcodec/packet_internal.h | 25 | ||||
-rw-r--r-- | libavdevice/decklink_common.h | 5 | ||||
-rw-r--r-- | libavdevice/decklink_dec.cpp | 29 | ||||
-rw-r--r-- | libavdevice/dshow.c | 10 | ||||
-rw-r--r-- | libavdevice/dshow_capture.h | 2 | ||||
-rw-r--r-- | libavdevice/vfwcap.c | 12 | ||||
-rw-r--r-- | libavformat/aiffenc.c | 17 | ||||
-rw-r--r-- | libavformat/demux.c | 54 | ||||
-rw-r--r-- | libavformat/flacenc.c | 10 | ||||
-rw-r--r-- | libavformat/internal.h | 12 | ||||
-rw-r--r-- | libavformat/matroskadec.c | 19 | ||||
-rw-r--r-- | libavformat/movenc.c | 6 | ||||
-rw-r--r-- | libavformat/movenc.h | 2 | ||||
-rw-r--r-- | libavformat/movenc_ttml.c | 6 | ||||
-rw-r--r-- | libavformat/mp3enc.c | 11 | ||||
-rw-r--r-- | libavformat/mux.c | 38 | ||||
-rw-r--r-- | libavformat/mxfenc.c | 14 | ||||
-rw-r--r-- | libavformat/ttaenc.c | 13 | ||||
-rw-r--r-- | libavformat/utils.c | 7 |
20 files changed, 153 insertions, 175 deletions
diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c index a0134e405c..4f7a6b255c 100644 --- a/libavcodec/avpacket.c +++ b/libavcodec/avpacket.c @@ -535,13 +535,12 @@ void av_packet_rescale_ts(AVPacket *pkt, AVRational src_tb, AVRational dst_tb) pkt->duration = av_rescale_q(pkt->duration, src_tb, dst_tb); } -int avpriv_packet_list_put(PacketList **packet_buffer, - PacketList **plast_pktl, +int avpriv_packet_list_put(PacketList *packet_buffer, AVPacket *pkt, int (*copy)(AVPacket *dst, const AVPacket *src), int flags) { - PacketList *pktl = av_malloc(sizeof(PacketList)); + PacketListEntry *pktl = av_malloc(sizeof(*pktl)); int ret; if (!pktl) @@ -565,44 +564,41 @@ int avpriv_packet_list_put(PacketList **packet_buffer, pktl->next = NULL; - if (*packet_buffer) - (*plast_pktl)->next = pktl; + if (packet_buffer->head) + packet_buffer->tail->next = pktl; else - *packet_buffer = pktl; + packet_buffer->head = pktl; /* Add the packet in the buffered packet list. */ - *plast_pktl = pktl; + packet_buffer->tail = pktl; return 0; } -int avpriv_packet_list_get(PacketList **pkt_buffer, - PacketList **pkt_buffer_end, +int avpriv_packet_list_get(PacketList *pkt_buffer, AVPacket *pkt) { - PacketList *pktl; - if (!*pkt_buffer) + PacketListEntry *pktl = pkt_buffer->head; + if (!pktl) return AVERROR(EAGAIN); - pktl = *pkt_buffer; *pkt = pktl->pkt; - *pkt_buffer = pktl->next; - if (!pktl->next) - *pkt_buffer_end = NULL; + pkt_buffer->head = pktl->next; + if (!pkt_buffer->head) + pkt_buffer->tail = NULL; av_freep(&pktl); return 0; } -void avpriv_packet_list_free(PacketList **pkt_buf, PacketList **pkt_buf_end) +void avpriv_packet_list_free(PacketList *pkt_buf) { - PacketList *tmp = *pkt_buf; + PacketListEntry *tmp = pkt_buf->head; while (tmp) { - PacketList *pktl = tmp; + PacketListEntry *pktl = tmp; tmp = pktl->next; av_packet_unref(&pktl->pkt); av_freep(&pktl); } - *pkt_buf = NULL; - *pkt_buf_end = NULL; + pkt_buf->head = pkt_buf->tail = NULL; } int ff_side_data_set_encoder_stats(AVPacket *pkt, int quality, int64_t *error, int error_count, int pict_type) diff --git a/libavcodec/packet_internal.h b/libavcodec/packet_internal.h index a10931c106..92a0d4e6d5 100644 --- a/libavcodec/packet_internal.h +++ b/libavcodec/packet_internal.h @@ -23,16 +23,19 @@ #include "packet.h" -typedef struct PacketList { - struct PacketList *next; +typedef struct PacketListEntry { + struct PacketListEntry *next; AVPacket pkt; +} PacketListEntry; + +typedef struct PacketList { + PacketListEntry *head, *tail; } PacketList; /** * Append an AVPacket to the list. * - * @param head List head element - * @param tail List tail element + * @param list A PacketList * @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. @@ -41,8 +44,7 @@ typedef struct PacketList { * @return 0 on success, negative AVERROR value on failure. On failure, the packet and the list are unchanged. */ -int avpriv_packet_list_put(PacketList **head, PacketList **tail, - AVPacket *pkt, +int avpriv_packet_list_put(PacketList *list, AVPacket *pkt, int (*copy)(AVPacket *dst, const AVPacket *src), int flags); @@ -52,22 +54,17 @@ int avpriv_packet_list_put(PacketList **head, PacketList **tail, * @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 head A pointer to a PacketList struct * @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(PacketList **head, PacketList **tail, - AVPacket *pkt); +int avpriv_packet_list_get(PacketList *list, 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(PacketList **head, PacketList **tail); +void avpriv_packet_list_free(PacketList *list); int ff_side_data_set_encoder_stats(AVPacket *pkt, int quality, int64_t *error, int error_count, int pict_type); diff --git a/libavdevice/decklink_common.h b/libavdevice/decklink_common.h index 5b11dcd46d..79d6ac5b38 100644 --- a/libavdevice/decklink_common.h +++ b/libavdevice/decklink_common.h @@ -29,6 +29,9 @@ #define IDeckLinkProfileAttributes IDeckLinkAttributes #endif +extern "C" { +#include "libavcodec/packet_internal.h" +} #include "libavutil/thread.h" #include "decklink_common_c.h" #if CONFIG_LIBKLVANC @@ -75,7 +78,7 @@ class decklink_output_callback; class decklink_input_callback; typedef struct AVPacketQueue { - PacketList *first_pkt, *last_pkt; + PacketList pkt_list; int nb_packets; unsigned long long size; int abort_request; diff --git a/libavdevice/decklink_dec.cpp b/libavdevice/decklink_dec.cpp index 491fe4be3d..c97a72d93d 100644 --- a/libavdevice/decklink_dec.cpp +++ b/libavdevice/decklink_dec.cpp @@ -483,16 +483,16 @@ static void avpacket_queue_init(AVFormatContext *avctx, AVPacketQueue *q) static void avpacket_queue_flush(AVPacketQueue *q) { - PacketList *pkt, *pkt1; + PacketListEntry *pkt, *pkt1; pthread_mutex_lock(&q->mutex); - for (pkt = q->first_pkt; pkt != NULL; pkt = pkt1) { + for (pkt = q->pkt_list.head; pkt != NULL; pkt = pkt1) { pkt1 = pkt->next; av_packet_unref(&pkt->pkt); av_freep(&pkt); } - q->last_pkt = NULL; - q->first_pkt = NULL; + q->pkt_list.head = NULL; + q->pkt_list.tail = NULL; q->nb_packets = 0; q->size = 0; pthread_mutex_unlock(&q->mutex); @@ -516,7 +516,7 @@ static unsigned long long avpacket_queue_size(AVPacketQueue *q) static int avpacket_queue_put(AVPacketQueue *q, AVPacket *pkt) { - PacketList *pkt1; + PacketListEntry *pkt1; // Drop Packet if queue size is > maximum queue size if (avpacket_queue_size(q) > (uint64_t)q->max_q_size) { @@ -530,7 +530,7 @@ static int avpacket_queue_put(AVPacketQueue *q, AVPacket *pkt) return -1; } - pkt1 = (PacketList *)av_malloc(sizeof(PacketList)); + pkt1 = (PacketListEntry *)av_malloc(sizeof(*pkt1)); if (!pkt1) { av_packet_unref(pkt); return -1; @@ -540,13 +540,13 @@ static int avpacket_queue_put(AVPacketQueue *q, AVPacket *pkt) pthread_mutex_lock(&q->mutex); - if (!q->last_pkt) { - q->first_pkt = pkt1; + if (!q->pkt_list.tail) { + q->pkt_list.head = pkt1; } else { - q->last_pkt->next = pkt1; + q->pkt_list.tail->next = pkt1; } - q->last_pkt = pkt1; + q->pkt_list.tail = pkt1; q->nb_packets++; q->size += pkt1->pkt.size + sizeof(*pkt1); @@ -558,17 +558,16 @@ static int avpacket_queue_put(AVPacketQueue *q, AVPacket *pkt) static int avpacket_queue_get(AVPacketQueue *q, AVPacket *pkt, int block) { - PacketList *pkt1; int ret; pthread_mutex_lock(&q->mutex); for (;; ) { - pkt1 = q->first_pkt; + PacketListEntry *pkt1 = q->pkt_list.head; if (pkt1) { - q->first_pkt = pkt1->next; - if (!q->first_pkt) { - q->last_pkt = NULL; + q->pkt_list.head = pkt1->next; + if (!q->pkt_list.head) { + q->pkt_list.tail = NULL; } q->nb_packets--; q->size -= pkt1->pkt.size + sizeof(*pkt1); diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c index 7e04880b38..3a16f3720f 100644 --- a/libavdevice/dshow.c +++ b/libavdevice/dshow.c @@ -238,7 +238,7 @@ static int dshow_read_close(AVFormatContext *s) { struct dshow_ctx *ctx = s->priv_data; - PacketList *pktl; + PacketListEntry *pktl; if (ctx->control) { IMediaControl_Stop(ctx->control); @@ -298,7 +298,7 @@ dshow_read_close(AVFormatContext *s) pktl = ctx->pktl; while (pktl) { - PacketList *next = pktl->next; + PacketListEntry *next = pktl->next; av_packet_unref(&pktl->pkt); av_free(pktl); pktl = next; @@ -342,7 +342,7 @@ callback(void *priv_data, int index, uint8_t *buf, int buf_size, int64_t time, e { AVFormatContext *s = priv_data; struct dshow_ctx *ctx = s->priv_data; - PacketList **ppktl, *pktl_next; + PacketListEntry **ppktl, *pktl_next; // dump_videohdr(s, vdhdr); @@ -351,7 +351,7 @@ callback(void *priv_data, int index, uint8_t *buf, int buf_size, int64_t time, e if(shall_we_drop(s, index, devtype)) goto fail; - pktl_next = av_mallocz(sizeof(PacketList)); + pktl_next = av_mallocz(sizeof(*pktl_next)); if(!pktl_next) goto fail; @@ -1868,7 +1868,7 @@ static int dshow_check_event_queue(IMediaEvent *media_event) static int dshow_read_packet(AVFormatContext *s, AVPacket *pkt) { struct dshow_ctx *ctx = s->priv_data; - PacketList *pktl = NULL; + PacketListEntry *pktl = NULL; while (!ctx->eof && !pktl) { WaitForSingleObject(ctx->mutex, INFINITE); diff --git a/libavdevice/dshow_capture.h b/libavdevice/dshow_capture.h index 21f5cf7e83..b548cd7afc 100644 --- a/libavdevice/dshow_capture.h +++ b/libavdevice/dshow_capture.h @@ -322,7 +322,7 @@ struct dshow_ctx { HANDLE mutex; HANDLE event[2]; /* event[0] is set by DirectShow * event[1] is set by callback() */ - PacketList *pktl; + PacketListEntry *pktl; int eof; diff --git a/libavdevice/vfwcap.c b/libavdevice/vfwcap.c index 6fad466f8a..86a40b4af4 100644 --- a/libavdevice/vfwcap.c +++ b/libavdevice/vfwcap.c @@ -45,7 +45,7 @@ struct vfw_ctx { HWND hwnd; HANDLE mutex; HANDLE event; - PacketList *pktl; + PacketListEntry *pktl; unsigned int curbufsize; unsigned int frame_num; char *video_size; /**< A string describing video size, set by a private option. */ @@ -179,7 +179,7 @@ static LRESULT CALLBACK videostream_cb(HWND hwnd, LPVIDEOHDR vdhdr) { AVFormatContext *s; struct vfw_ctx *ctx; - PacketList **ppktl, *pktl_next; + PacketListEntry **ppktl, *pktl_next; s = (AVFormatContext *) GetWindowLongPtr(hwnd, GWLP_USERDATA); ctx = s->priv_data; @@ -191,7 +191,7 @@ static LRESULT CALLBACK videostream_cb(HWND hwnd, LPVIDEOHDR vdhdr) WaitForSingleObject(ctx->mutex, INFINITE); - pktl_next = av_mallocz(sizeof(PacketList)); + pktl_next = av_mallocz(sizeof(*pktl_next)); if(!pktl_next) goto fail; @@ -220,7 +220,7 @@ fail: static int vfw_read_close(AVFormatContext *s) { struct vfw_ctx *ctx = s->priv_data; - PacketList *pktl; + PacketListEntry *pktl; if(ctx->hwnd) { SendMessage(ctx->hwnd, WM_CAP_SET_CALLBACK_VIDEOSTREAM, 0, 0); @@ -234,7 +234,7 @@ static int vfw_read_close(AVFormatContext *s) pktl = ctx->pktl; while (pktl) { - PacketList *next = pktl->next; + PacketListEntry *next = pktl->next; av_packet_unref(&pktl->pkt); av_free(pktl); pktl = next; @@ -440,7 +440,7 @@ fail: static int vfw_read_packet(AVFormatContext *s, AVPacket *pkt) { struct vfw_ctx *ctx = s->priv_data; - PacketList *pktl = NULL; + PacketListEntry *pktl = NULL; while(!pktl) { WaitForSingleObject(ctx->mutex, INFINITE); diff --git a/libavformat/aiffenc.c b/libavformat/aiffenc.c index 7bb0978a53..1fd6b8a70b 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; - PacketList *pict_list, *pict_list_end; + PacketList pict_list; int write_id3v2; int id3v2_version; } AIFFOutputContext; @@ -48,9 +48,9 @@ static int put_id3v2_tags(AVFormatContext *s, AIFFOutputContext *aiff) uint64_t pos, end, size; ID3v2EncContext id3v2 = { 0 }; AVIOContext *pb = s->pb; - PacketList *pict_list = aiff->pict_list; + PacketListEntry *list_entry = aiff->pict_list.head; - if (!s->metadata && !s->nb_chapters && !aiff->pict_list) + if (!s->metadata && !s->nb_chapters && !list_entry) return 0; avio_wl32(pb, MKTAG('I', 'D', '3', ' ')); @@ -59,10 +59,10 @@ 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 (list_entry) { + if ((ret = ff_id3v2_write_apic(s, &id3v2, &list_entry->pkt)) < 0) return ret; - pict_list = pict_list->next; + list_entry = list_entry->next; } ff_id3v2_finish(&id3v2, pb, s->metadata_header_padding); @@ -218,8 +218,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, NULL, 0); + return avpriv_packet_list_put(&aiff->pict_list, pkt, NULL, 0); } return 0; @@ -265,7 +264,7 @@ static void aiff_deinit(AVFormatContext *s) { AIFFOutputContext *aiff = s->priv_data; - avpriv_packet_list_free(&aiff->pict_list, &aiff->pict_list_end); + avpriv_packet_list_free(&aiff->pict_list); } #define OFFSET(x) offsetof(AIFFOutputContext, x) diff --git a/libavformat/demux.c b/libavformat/demux.c index 4770e5517f..f895f0ba85 100644 --- a/libavformat/demux.c +++ b/libavformat/demux.c @@ -537,7 +537,7 @@ FF_ENABLE_DEPRECATION_WARNINGS #endif for (;;) { - PacketList *pktl = si->raw_packet_buffer; + PacketListEntry *pktl = si->raw_packet_buffer.head; AVStream *st; FFStream *sti; const AVPacket *pkt1; @@ -548,8 +548,7 @@ FF_ENABLE_DEPRECATION_WARNINGS if ((err = probe_codec(s, st, NULL)) < 0) return err; if (ffstream(st)->request_probe <= 0) { - avpriv_packet_list_get(&si->raw_packet_buffer, - &si->raw_packet_buffer_end, pkt); + avpriv_packet_list_get(&si->raw_packet_buffer, pkt); si->raw_packet_buffer_size -= pkt->size; return 0; } @@ -624,13 +623,12 @@ FF_ENABLE_DEPRECATION_WARNINGS return 0; err = avpriv_packet_list_put(&si->raw_packet_buffer, - &si->raw_packet_buffer_end, pkt, NULL, 0); if (err < 0) { av_packet_unref(pkt); return err; } - pkt1 = &si->raw_packet_buffer_end->pkt; + pkt1 = &si->raw_packet_buffer.tail->pkt; si->raw_packet_buffer_size += pkt1->size; if ((err = probe_codec(s, st, pkt1)) < 0) @@ -716,13 +714,14 @@ static int has_decode_delay_been_guessed(AVStream *st) return sti->nb_decoded_frames >= 20; } -static PacketList *get_next_pkt(AVFormatContext *s, AVStream *st, PacketList *pktl) +static PacketListEntry *get_next_pkt(AVFormatContext *s, AVStream *st, + PacketListEntry *pktl) { FFFormatContext *const si = ffformatcontext(s); if (pktl->next) return pktl->next; - if (pktl == si->packet_buffer_end) - return si->parse_queue; + if (pktl == si->packet_buffer.tail) + return si->parse_queue.head; return NULL; } @@ -774,7 +773,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, - PacketList *pkt_buffer) + PacketListEntry *pkt_buffer) { AVStream *const st = s->streams[stream_index]; int delay = ffstream(st)->avctx->has_b_frames; @@ -804,7 +803,7 @@ static void update_initial_timestamps(AVFormatContext *s, int stream_index, FFFormatContext *const si = ffformatcontext(s); AVStream *const st = s->streams[stream_index]; FFStream *const sti = ffstream(st); - PacketList *pktl = si->packet_buffer ? si->packet_buffer : si->parse_queue; + PacketListEntry *pktl = si->packet_buffer.head ? si->packet_buffer.head : si->parse_queue.head; uint64_t shift; @@ -823,7 +822,7 @@ static void update_initial_timestamps(AVFormatContext *s, int stream_index, if (is_relative(pts)) pts += shift; - for (PacketList *pktl_it = pktl; pktl_it; pktl_it = get_next_pkt(s, st, pktl_it)) { + for (PacketListEntry *pktl_it = pktl; pktl_it; pktl_it = get_next_pkt(s, st, pktl_it)) { if (pktl_it->pkt.stream_index != stream_index) continue; if (is_relative(pktl_it->pkt.pts)) @@ -856,7 +855,7 @@ static void update_initial_durations(AVFormatContext *s, AVStream *st, { FFFormatContext *const si = ffformatcontext(s); FFStream *const sti = ffstream(st); - PacketList *pktl = si->packet_buffer ? si->packet_buffer : si->parse_queue; + PacketListEntry *pktl = si->packet_buffer.head ? si->packet_buffer.head : si->parse_queue.head; int64_t cur_dts = RELATIVE_TS_BASE; if (sti->first_dts != AV_NOPTS_VALUE) { @@ -882,7 +881,7 @@ 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(sti->first_dts)); return; } - pktl = si->packet_buffer ? si->packet_buffer : si->parse_queue; + pktl = si->packet_buffer.head ? si->packet_buffer.head : si->parse_queue.head; sti->first_dts = cur_dts; } else if (sti->cur_dts != RELATIVE_TS_BASE) return; @@ -998,7 +997,7 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st, } } - if (pkt->duration > 0 && (si->packet_buffer || si->parse_queue)) + if (pkt->duration > 0 && (si->packet_buffer.head || si->parse_queue.head)) update_initial_durations(s, st, pkt->stream_index, pkt->duration); /* Correct timestamps with byte offset if demuxers only have timestamps @@ -1195,7 +1194,6 @@ static int parse_packet(AVFormatContext *s, AVPacket *pkt, compute_pkt_fields(s, st, sti->parser, out_pkt, next_dts, next_pts); ret = avpriv_packet_list_put(&si->parse_queue, - &si->parse_queue_end, out_pkt, NULL, 0); if (ret < 0) goto fail; @@ -1225,7 +1223,7 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) int ret, got_packet = 0; AVDictionary *metadata = NULL; - while (!got_packet && !si->parse_queue) { + while (!got_packet && !si->parse_queue.head) { AVStream *st; FFStream *sti; @@ -1338,8 +1336,8 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) } } - if (!got_packet && si->parse_queue) - ret = avpriv_packet_list_get(&si->parse_queue, &si->parse_queue_end, pkt); + if (!got_packet && si->parse_queue.head) + ret = avpriv_packet_list_get(&si->parse_queue, pkt); if (ret >= 0) { AVStream *const st = s->streams[pkt->stream_index]; @@ -1420,9 +1418,8 @@ int av_read_frame(AVFormatContext *s, AVPacket *pkt) AVStream *st; if (!genpts) { - ret = si->packet_buffer - ? avpriv_packet_list_get(&si->packet_buffer, - &si->packet_buffer_end, pkt) + ret = si->packet_buffer.head + ? avpriv_packet_list_get(&si->packet_buffer, pkt) : read_frame_internal(s, pkt); if (ret < 0) return ret; @@ -1430,7 +1427,7 @@ int av_read_frame(AVFormatContext *s, AVPacket *pkt) } for (;;) { - PacketList *pktl = si->packet_buffer; + PacketListEntry *pktl = si->packet_buffer.head; if (pktl) { AVPacket *next_pkt = &pktl->pkt; @@ -1463,15 +1460,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 = si->packet_buffer; + pktl = si->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(&si->packet_buffer, - &si->packet_buffer_end, pkt); + ret = avpriv_packet_list_get(&si->packet_buffer, pkt); goto return_packet; } } @@ -1486,7 +1482,6 @@ int av_read_frame(AVFormatContext *s, AVPacket *pkt) } ret = avpriv_packet_list_put(&si->packet_buffer, - &si->packet_buffer_end, pkt, NULL, 0); if (ret < 0) { av_packet_unref(pkt); @@ -2598,12 +2593,11 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) if (!(ic->flags & AVFMT_FLAG_NOBUFFER)) { ret = avpriv_packet_list_put(&si->packet_buffer, - &si->packet_buffer_end, pkt1, NULL, 0); if (ret < 0) goto unref_then_goto_end; - pkt = &si->packet_buffer_end->pkt; + pkt = &si->packet_buffer.tail->pkt; } else { pkt = pkt1; } @@ -2751,8 +2745,8 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) // EOF already reached while reading the stream above. // So continue with reoordering DTS with whatever delay we have. - if (si->packet_buffer && !has_decode_delay_been_guessed(st)) { - update_dts_from_pts(ic, stream_index, si->packet_buffer); + if (si->packet_buffer.head && !has_decode_delay_been_guessed(st)) { + update_dts_from_pts(ic, stream_index, si->packet_buffer.head); } } } diff --git a/libavformat/flacenc.c b/libavformat/flacenc.c index e8f043729e..b267197ccc 100644 --- a/libavformat/flacenc.c +++ b/libavformat/flacenc.c @@ -40,7 +40,7 @@ typedef struct FlacMuxerContext { int audio_stream_idx; int waiting_pics; /* audio packets are queued here until we get all the attached pictures */ - PacketList *queue, *queue_end; + PacketList queue; /* updated streaminfo sent by the encoder at the end */ uint8_t streaminfo[FLAC_STREAMINFO_SIZE]; @@ -306,8 +306,8 @@ 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 (c->queue.head) { + avpriv_packet_list_get(&c->queue, pkt); if (write && (ret = flac_write_audio_packet(s, pkt)) < 0) write = 0; av_packet_unref(pkt); @@ -347,7 +347,7 @@ static void flac_deinit(struct AVFormatContext *s) { FlacMuxerContext *c = s->priv_data; - avpriv_packet_list_free(&c->queue, &c->queue_end); + avpriv_packet_list_free(&c->queue); for (unsigned i = 0; i < s->nb_streams; i++) av_packet_free((AVPacket **)&s->streams[i]->priv_data); } @@ -360,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, NULL, 0); + ret = avpriv_packet_list_put(&c->queue, pkt, NULL, 0); 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 63235ce5cf..bffb8e66ff 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -25,6 +25,7 @@ #include "libavcodec/avcodec.h" #include "libavcodec/bsf.h" +#include "libavcodec/packet_internal.h" #include "avformat.h" #include "os_support.h" @@ -92,8 +93,7 @@ typedef struct FFFormatContext { * not decoded, for example to get the codec parameters in MPEG * streams. */ - struct PacketList *packet_buffer; - struct PacketList *packet_buffer_end; + PacketList packet_buffer; /* av_seek_frame() support */ int64_t data_offset; /**< offset of the first packet */ @@ -104,13 +104,11 @@ typedef struct FFFormatContext { * be identified, as parsing cannot be done without knowing the * codec. */ - struct PacketList *raw_packet_buffer; - struct PacketList *raw_packet_buffer_end; + PacketList raw_packet_buffer; /** * Packets split by the parser get queued here. */ - struct PacketList *parse_queue; - struct PacketList *parse_queue_end; + PacketList parse_queue; /** * The generic code uses this as a temporary packet * to parse packets or for muxing, especially flushing. @@ -393,7 +391,7 @@ typedef struct FFStream { /** * last packet in packet_buffer for this stream when muxing. */ - struct PacketList *last_in_packet_buffer; + PacketListEntry *last_in_packet_buffer; int64_t last_IP_pts; int last_IP_duration; diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index e271916bf1..78e5a4a203 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -396,8 +396,7 @@ typedef struct MatroskaDemuxContext { AVPacket *pkt; /* the packet queue */ - PacketList *queue; - PacketList *queue_end; + PacketList queue; int done; @@ -3112,11 +3111,11 @@ static int matroska_read_header(AVFormatContext *s) static int matroska_deliver_packet(MatroskaDemuxContext *matroska, AVPacket *pkt) { - if (matroska->queue) { + if (matroska->queue.head) { MatroskaTrack *tracks = matroska->tracks.elem; MatroskaTrack *track; - avpriv_packet_list_get(&matroska->queue, &matroska->queue_end, pkt); + avpriv_packet_list_get(&matroska->queue, 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); @@ -3138,7 +3137,7 @@ static int matroska_deliver_packet(MatroskaDemuxContext *matroska, */ static void matroska_clear_queue(MatroskaDemuxContext *matroska) { - avpriv_packet_list_free(&matroska->queue, &matroska->queue_end); + avpriv_packet_list_free(&matroska->queue); } static int matroska_parse_laces(MatroskaDemuxContext *matroska, uint8_t **buf, @@ -3304,7 +3303,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 = avpriv_packet_list_put(&matroska->queue, pkt, NULL, 0); if (ret < 0) { av_packet_unref(pkt); return AVERROR(ENOMEM); @@ -3526,7 +3525,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 = avpriv_packet_list_put(&matroska->queue, pkt, NULL, 0); if (err < 0) { av_packet_unref(pkt); return AVERROR(ENOMEM); @@ -3628,7 +3627,7 @@ static int matroska_parse_frame(MatroskaDemuxContext *matroska, pkt->pos = pos; pkt->duration = lace_duration; - res = avpriv_packet_list_put(&matroska->queue, &matroska->queue_end, pkt, NULL, 0); + res = avpriv_packet_list_put(&matroska->queue, pkt, NULL, 0); if (res < 0) { av_packet_unref(pkt); return AVERROR(ENOMEM); @@ -4030,10 +4029,10 @@ 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) { + !matroska->queue.head) { break; } - pkt = &matroska->queue->pkt; + pkt = &matroska->queue.head->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)) { diff --git a/libavformat/movenc.c b/libavformat/movenc.c index 5d4429b82e..ab33371296 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -5339,7 +5339,7 @@ static int mov_write_squashed_packet(AVFormatContext *s, MOVTrack *track) switch (track->st->codecpar->codec_id) { case AV_CODEC_ID_TTML: { - int had_packets = !!track->squashed_packet_queue; + int had_packets = !!track->squashed_packet_queue.head; if ((ret = ff_mov_generate_squashed_ttml_packet(s, track, squashed_packet)) < 0) { goto finish_squash; @@ -6190,7 +6190,6 @@ static int mov_write_packet(AVFormatContext *s, AVPacket *pkt) /* The following will reset pkt and is only allowed to be used * because we return immediately. afterwards. */ if ((ret = avpriv_packet_list_put(&trk->squashed_packet_queue, - &trk->squashed_packet_queue_end, pkt, NULL, 0)) < 0) { return ret; } @@ -6478,8 +6477,7 @@ static void mov_free(AVFormatContext *s) ff_mov_cenc_free(&track->cenc); ffio_free_dyn_buf(&track->mdat_buf); - avpriv_packet_list_free(&track->squashed_packet_queue, - &track->squashed_packet_queue_end); + avpriv_packet_list_free(&track->squashed_packet_queue); } av_freep(&mov->tracks); diff --git a/libavformat/movenc.h b/libavformat/movenc.h index 40077b1afe..2ac84ed070 100644 --- a/libavformat/movenc.h +++ b/libavformat/movenc.h @@ -167,7 +167,7 @@ typedef struct MOVTrack { unsigned int squash_fragment_samples_to_one; //< flag to note formats where all samples for a fragment are to be squashed - PacketList *squashed_packet_queue, *squashed_packet_queue_end; + PacketList squashed_packet_queue; } MOVTrack; typedef enum { diff --git a/libavformat/movenc_ttml.c b/libavformat/movenc_ttml.c index 472572b45a..6deae49657 100644 --- a/libavformat/movenc_ttml.c +++ b/libavformat/movenc_ttml.c @@ -70,9 +70,7 @@ static int mov_write_ttml_document_from_queue(AVFormatContext *s, return ret; } - while (!avpriv_packet_list_get(&track->squashed_packet_queue, - &track->squashed_packet_queue_end, - pkt)) { + while (!avpriv_packet_list_get(&track->squashed_packet_queue, pkt)) { end_ts = FFMAX(end_ts, pkt->pts + pkt->duration); // in case of the 'dfxp' muxing mode, each written document is offset @@ -121,7 +119,7 @@ int ff_mov_generate_squashed_ttml_packet(AVFormatContext *s, goto cleanup; } - if (!track->squashed_packet_queue) { + if (!track->squashed_packet_queue.head) { // empty queue, write minimal empty document with zero duration avio_write(ttml_ctx->pb, empty_ttml_document, sizeof(empty_ttml_document) - 1); diff --git a/libavformat/mp3enc.c b/libavformat/mp3enc.c index 0ffc79c025..3ff19da274 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 */ - PacketList *queue, *queue_end; + PacketList queue; } MP3Context; static const uint8_t xing_offtbl[2][2] = {{32, 17}, {17, 9}}; @@ -387,8 +387,8 @@ 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 (mp3->queue.head) { + avpriv_packet_list_get(&mp3->queue, pkt); if (write && (ret = mp3_write_audio_packet(s, pkt)) < 0) write = 0; av_packet_unref(pkt); @@ -524,8 +524,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, NULL, 0); + int ret = avpriv_packet_list_put(&mp3->queue, pkt, NULL, 0); if (ret < 0) { av_log(s, AV_LOG_WARNING, "Not enough memory to buffer audio. Skipping picture streams\n"); @@ -633,7 +632,7 @@ static void mp3_deinit(struct AVFormatContext *s) { MP3Context *mp3 = s->priv_data; - avpriv_packet_list_free(&mp3->queue, &mp3->queue_end); + avpriv_packet_list_free(&mp3->queue); av_freep(&mp3->xing_frame); } diff --git a/libavformat/mux.c b/libavformat/mux.c index 0500f636de..c387f8ec6e 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -809,12 +809,12 @@ int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, { int ret; FFFormatContext *const si = ffformatcontext(s); - PacketList **next_point, *this_pktl; + PacketListEntry **next_point, *this_pktl; AVStream *st = s->streams[pkt->stream_index]; FFStream *const sti = ffstream(st); int chunked = s->max_chunk_size || s->max_chunk_duration; - this_pktl = av_malloc(sizeof(PacketList)); + this_pktl = av_malloc(sizeof(*this_pktl)); if (!this_pktl) { av_packet_unref(pkt); return AVERROR(ENOMEM); @@ -831,7 +831,7 @@ int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, if (sti->last_in_packet_buffer) { next_point = &(sti->last_in_packet_buffer->next); } else { - next_point = &si->packet_buffer; + next_point = &si->packet_buffer.head; } if (chunked) { @@ -855,7 +855,7 @@ int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, if (chunked && !(pkt->flags & CHUNK_START)) goto next_non_null; - if (compare(s, &si->packet_buffer_end->pkt, pkt)) { + if (compare(s, &si->packet_buffer.tail->pkt, pkt)) { while ( *next_point && ((chunked && !((*next_point)->pkt.flags&CHUNK_START)) || !compare(s, &(*next_point)->pkt, pkt))) @@ -863,12 +863,12 @@ int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, if (*next_point) goto next_non_null; } else { - next_point = &(si->packet_buffer_end->next); + next_point = &(si->packet_buffer.tail->next); } } av_assert1(!*next_point); - si->packet_buffer_end = this_pktl; + si->packet_buffer.tail = this_pktl; next_non_null: this_pktl->next = *next_point; @@ -939,11 +939,11 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *pkt, flush = 1; if (s->max_interleave_delta > 0 && - si->packet_buffer && + si->packet_buffer.head && !flush && si->nb_interleaved_streams == stream_count+noninterleaved_count ) { - AVPacket *const top_pkt = &si->packet_buffer->pkt; + AVPacket *const top_pkt = &si->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, @@ -952,7 +952,7 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *pkt, for (unsigned i = 0; i < s->nb_streams; i++) { const AVStream *const st = s->streams[i]; const FFStream *const sti = cffstream(st); - const PacketList *last = sti->last_in_packet_buffer; + const PacketListEntry *const last = sti->last_in_packet_buffer; int64_t last_dts; if (!last) @@ -973,11 +973,11 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *pkt, } } - if (si->packet_buffer && + if (si->packet_buffer.head && eof && (s->flags & AVFMT_FLAG_SHORTEST) && si->shortest_end == AV_NOPTS_VALUE) { - AVPacket *const top_pkt = &si->packet_buffer->pkt; + AVPacket *const top_pkt = &si->packet_buffer.head->pkt; si->shortest_end = av_rescale_q(top_pkt->dts, s->streams[top_pkt->stream_index]->time_base, @@ -985,8 +985,8 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *pkt, } if (si->shortest_end != AV_NOPTS_VALUE) { - while (si->packet_buffer) { - PacketList *pktl = si->packet_buffer; + while (si->packet_buffer.head) { + PacketListEntry *pktl = si->packet_buffer.head; AVPacket *const top_pkt = &pktl->pkt; AVStream *const st = s->streams[top_pkt->stream_index]; FFStream *const sti = ffstream(st); @@ -996,9 +996,9 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *pkt, if (si->shortest_end + 1 >= top_dts) break; - si->packet_buffer = pktl->next; - if (!si->packet_buffer) - si->packet_buffer_end = NULL; + si->packet_buffer.head = pktl->next; + if (!si->packet_buffer.head) + si->packet_buffer.tail = NULL; if (sti->last_in_packet_buffer == pktl) sti->last_in_packet_buffer = NULL; @@ -1010,13 +1010,13 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *pkt, } if (stream_count && flush) { - PacketList *pktl = si->packet_buffer; + PacketListEntry *pktl = si->packet_buffer.head; AVStream *const st = s->streams[pktl->pkt.stream_index]; FFStream *const sti = ffstream(st); if (sti->last_in_packet_buffer == pktl) sti->last_in_packet_buffer = NULL; - avpriv_packet_list_get(&si->packet_buffer, &si->packet_buffer_end, pkt); + avpriv_packet_list_get(&si->packet_buffer, pkt); return 1; } else { @@ -1049,7 +1049,7 @@ int ff_get_muxer_ts_offset(AVFormatContext *s, int stream_index, int64_t *offset const AVPacket *ff_interleaved_peek(AVFormatContext *s, int stream) { FFFormatContext *const si = ffformatcontext(s); - PacketList *pktl = si->packet_buffer; + PacketListEntry *pktl = si->packet_buffer.head; while (pktl) { if (pktl->pkt.stream_index == stream) { return &pktl->pkt; diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c index 4c02e3e264..5e068c8220 100644 --- a/libavformat/mxfenc.c +++ b/libavformat/mxfenc.c @@ -3097,9 +3097,9 @@ static int mxf_interleave_get_packet(AVFormatContext *s, AVPacket *out, int flus stream_count += !!ffstream(s->streams[i])->last_in_packet_buffer; if (stream_count && (s->nb_streams == stream_count || flush)) { - PacketList *pktl = si->packet_buffer; + PacketListEntry *pktl = si->packet_buffer.head; if (s->nb_streams != stream_count) { - PacketList *last = NULL; + PacketListEntry *last = NULL; // find last packet in edit unit while (pktl) { if (!stream_count || pktl->pkt.stream_index == 0) @@ -3113,7 +3113,7 @@ static int mxf_interleave_get_packet(AVFormatContext *s, AVPacket *out, int flus } // purge packet queue while (pktl) { - PacketList *next = pktl->next; + PacketListEntry *next = pktl->next; av_packet_unref(&pktl->pkt); av_freep(&pktl); pktl = next; @@ -3121,16 +3121,16 @@ static int mxf_interleave_get_packet(AVFormatContext *s, AVPacket *out, int flus if (last) last->next = NULL; else { - si->packet_buffer = NULL; - si->packet_buffer_end = NULL; + si->packet_buffer.head = NULL; + si->packet_buffer.tail = NULL; goto out; } - pktl = si->packet_buffer; + pktl = si->packet_buffer.head; } if (ffstream(s->streams[pktl->pkt.stream_index])->last_in_packet_buffer == pktl) ffstream(s->streams[pktl->pkt.stream_index])->last_in_packet_buffer = NULL; - avpriv_packet_list_get(&si->packet_buffer, &si->packet_buffer_end, out); + avpriv_packet_list_get(&si->packet_buffer, out); av_log(s, AV_LOG_TRACE, "out st:%d dts:%"PRId64"\n", out->stream_index, out->dts); return 1; } else { diff --git a/libavformat/ttaenc.c b/libavformat/ttaenc.c index 5f21fdc144..486f8bdd10 100644 --- a/libavformat/ttaenc.c +++ b/libavformat/ttaenc.c @@ -30,7 +30,7 @@ typedef struct TTAMuxContext { AVIOContext *seek_table; - PacketList *queue, *queue_end; + PacketList queue; uint32_t nb_samples; int frame_size; int last_frame; @@ -94,12 +94,11 @@ 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, - NULL, 0); + ret = avpriv_packet_list_put(&tta->queue, pkt, NULL, 0); if (ret < 0) { return ret; } - pkt = &tta->queue_end->pkt; + pkt = &tta->queue.tail->pkt; avio_wl32(tta->seek_table, pkt->size); tta->nb_samples += pkt->duration; @@ -126,8 +125,8 @@ static void tta_queue_flush(AVFormatContext *s) TTAMuxContext *tta = s->priv_data; AVPacket *const pkt = ffformatcontext(s)->pkt; - while (tta->queue) { - avpriv_packet_list_get(&tta->queue, &tta->queue_end, pkt); + while (tta->queue.head) { + avpriv_packet_list_get(&tta->queue, pkt); avio_write(s->pb, pkt->data, pkt->size); av_packet_unref(pkt); } @@ -163,7 +162,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); + avpriv_packet_list_free(&tta->queue); } const AVOutputFormat ff_tta_muxer = { diff --git a/libavformat/utils.c b/libavformat/utils.c index ca6185b5c3..e643821fc9 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -239,7 +239,6 @@ int avformat_queue_attached_pictures(AVFormatContext *s) } ret = avpriv_packet_list_put(&si->raw_packet_buffer, - &si->raw_packet_buffer_end, &s->streams[i]->attached_pic, av_packet_ref, 0); if (ret < 0) @@ -300,9 +299,9 @@ int ff_is_intra_only(enum AVCodecID id) void ff_flush_packet_queue(AVFormatContext *s) { FFFormatContext *const si = ffformatcontext(s); - avpriv_packet_list_free(&si->parse_queue, &si->parse_queue_end); - avpriv_packet_list_free(&si->packet_buffer, &si->packet_buffer_end); - avpriv_packet_list_free(&si->raw_packet_buffer, &si->raw_packet_buffer_end); + avpriv_packet_list_free(&si->parse_queue); + avpriv_packet_list_free(&si->packet_buffer); + avpriv_packet_list_free(&si->raw_packet_buffer); si->raw_packet_buffer_size = 0; } |