aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2021-12-16 01:49:39 +0100
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2022-01-04 13:16:50 +0100
commitd61240f8c95e9cf7a0aaef2bb4495960d3fec62c (patch)
tree52398ddaec0cbe4e02d0db54669ecd1532f1569e /libavformat
parentb74e47c4ff5bca998936c0d8b9a0892104a7403d (diff)
downloadffmpeg-d61240f8c95e9cf7a0aaef2bb4495960d3fec62c.tar.gz
avcodec/packet_internal: Add proper PacketList struct
Up until now, we had a PacketList structure which is actually a PacketListEntry; a proper PacketList did not exist and all the related functions just passed pointers to pointers to the head and tail elements around. All these pointers were actually consecutive elements of their containing structs, i.e. the users already treated them as if they were a struct. So add a proper PacketList struct and rename the current PacketList to PacketListEntry; also make the functions use this structure instead of the pair of pointers. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavformat')
-rw-r--r--libavformat/aiffenc.c17
-rw-r--r--libavformat/demux.c54
-rw-r--r--libavformat/flacenc.c10
-rw-r--r--libavformat/internal.h12
-rw-r--r--libavformat/matroskadec.c19
-rw-r--r--libavformat/movenc.c6
-rw-r--r--libavformat/movenc.h2
-rw-r--r--libavformat/movenc_ttml.c6
-rw-r--r--libavformat/mp3enc.c11
-rw-r--r--libavformat/mux.c38
-rw-r--r--libavformat/mxfenc.c14
-rw-r--r--libavformat/ttaenc.c13
-rw-r--r--libavformat/utils.c7
13 files changed, 96 insertions, 113 deletions
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;
}