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>
This commit is contained in:
Andreas Rheinhardt 2021-12-16 01:49:39 +01:00
parent b74e47c4ff
commit d61240f8c9
20 changed files with 153 additions and 175 deletions

View File

@ -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); pkt->duration = av_rescale_q(pkt->duration, src_tb, dst_tb);
} }
int avpriv_packet_list_put(PacketList **packet_buffer, int avpriv_packet_list_put(PacketList *packet_buffer,
PacketList **plast_pktl,
AVPacket *pkt, AVPacket *pkt,
int (*copy)(AVPacket *dst, const AVPacket *src), int (*copy)(AVPacket *dst, const AVPacket *src),
int flags) int flags)
{ {
PacketList *pktl = av_malloc(sizeof(PacketList)); PacketListEntry *pktl = av_malloc(sizeof(*pktl));
int ret; int ret;
if (!pktl) if (!pktl)
@ -565,44 +564,41 @@ int avpriv_packet_list_put(PacketList **packet_buffer,
pktl->next = NULL; pktl->next = NULL;
if (*packet_buffer) if (packet_buffer->head)
(*plast_pktl)->next = pktl; packet_buffer->tail->next = pktl;
else else
*packet_buffer = pktl; packet_buffer->head = pktl;
/* Add the packet in the buffered packet list. */ /* Add the packet in the buffered packet list. */
*plast_pktl = pktl; packet_buffer->tail = pktl;
return 0; return 0;
} }
int avpriv_packet_list_get(PacketList **pkt_buffer, int avpriv_packet_list_get(PacketList *pkt_buffer,
PacketList **pkt_buffer_end,
AVPacket *pkt) AVPacket *pkt)
{ {
PacketList *pktl; PacketListEntry *pktl = pkt_buffer->head;
if (!*pkt_buffer) if (!pktl)
return AVERROR(EAGAIN); return AVERROR(EAGAIN);
pktl = *pkt_buffer;
*pkt = pktl->pkt; *pkt = pktl->pkt;
*pkt_buffer = pktl->next; pkt_buffer->head = pktl->next;
if (!pktl->next) if (!pkt_buffer->head)
*pkt_buffer_end = NULL; pkt_buffer->tail = NULL;
av_freep(&pktl); av_freep(&pktl);
return 0; 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) { while (tmp) {
PacketList *pktl = tmp; PacketListEntry *pktl = tmp;
tmp = pktl->next; tmp = pktl->next;
av_packet_unref(&pktl->pkt); av_packet_unref(&pktl->pkt);
av_freep(&pktl); av_freep(&pktl);
} }
*pkt_buf = NULL; pkt_buf->head = pkt_buf->tail = 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) int ff_side_data_set_encoder_stats(AVPacket *pkt, int quality, int64_t *error, int error_count, int pict_type)

View File

@ -23,16 +23,19 @@
#include "packet.h" #include "packet.h"
typedef struct PacketList { typedef struct PacketListEntry {
struct PacketList *next; struct PacketListEntry *next;
AVPacket pkt; AVPacket pkt;
} PacketListEntry;
typedef struct PacketList {
PacketListEntry *head, *tail;
} PacketList; } PacketList;
/** /**
* Append an AVPacket to the list. * Append an AVPacket to the list.
* *
* @param head List head element * @param list A PacketList
* @param tail List tail element
* @param pkt The packet being appended. The data described in it will * @param pkt The packet being appended. The data described in it will
* be made reference counted if it isn't already. * be made reference counted if it isn't already.
* @param copy A callback to copy the contents of the packet to the list. * @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, * @return 0 on success, negative AVERROR value on failure. On failure,
the packet and the list are unchanged. the packet and the list are unchanged.
*/ */
int avpriv_packet_list_put(PacketList **head, PacketList **tail, int avpriv_packet_list_put(PacketList *list, AVPacket *pkt,
AVPacket *pkt,
int (*copy)(AVPacket *dst, const AVPacket *src), int (*copy)(AVPacket *dst, const AVPacket *src),
int flags); 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 * @note The pkt will be overwritten completely on success. The caller
* owns the packet and must unref it by itself. * owns the packet and must unref it by itself.
* *
* @param head List head element * @param head A pointer to a PacketList struct
* @param tail List tail element
* @param pkt Pointer to an AVPacket struct * @param pkt Pointer to an AVPacket struct
* @return 0 on success, and a packet is returned. AVERROR(EAGAIN) if * @return 0 on success, and a packet is returned. AVERROR(EAGAIN) if
* the list was empty. * the list was empty.
*/ */
int avpriv_packet_list_get(PacketList **head, PacketList **tail, int avpriv_packet_list_get(PacketList *list, AVPacket *pkt);
AVPacket *pkt);
/** /**
* Wipe the list and unref all the packets in it. * 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); int ff_side_data_set_encoder_stats(AVPacket *pkt, int quality, int64_t *error, int error_count, int pict_type);

View File

@ -29,6 +29,9 @@
#define IDeckLinkProfileAttributes IDeckLinkAttributes #define IDeckLinkProfileAttributes IDeckLinkAttributes
#endif #endif
extern "C" {
#include "libavcodec/packet_internal.h"
}
#include "libavutil/thread.h" #include "libavutil/thread.h"
#include "decklink_common_c.h" #include "decklink_common_c.h"
#if CONFIG_LIBKLVANC #if CONFIG_LIBKLVANC
@ -75,7 +78,7 @@ class decklink_output_callback;
class decklink_input_callback; class decklink_input_callback;
typedef struct AVPacketQueue { typedef struct AVPacketQueue {
PacketList *first_pkt, *last_pkt; PacketList pkt_list;
int nb_packets; int nb_packets;
unsigned long long size; unsigned long long size;
int abort_request; int abort_request;

View File

@ -483,16 +483,16 @@ static void avpacket_queue_init(AVFormatContext *avctx, AVPacketQueue *q)
static void avpacket_queue_flush(AVPacketQueue *q) static void avpacket_queue_flush(AVPacketQueue *q)
{ {
PacketList *pkt, *pkt1; PacketListEntry *pkt, *pkt1;
pthread_mutex_lock(&q->mutex); 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; pkt1 = pkt->next;
av_packet_unref(&pkt->pkt); av_packet_unref(&pkt->pkt);
av_freep(&pkt); av_freep(&pkt);
} }
q->last_pkt = NULL; q->pkt_list.head = NULL;
q->first_pkt = NULL; q->pkt_list.tail = NULL;
q->nb_packets = 0; q->nb_packets = 0;
q->size = 0; q->size = 0;
pthread_mutex_unlock(&q->mutex); 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) static int avpacket_queue_put(AVPacketQueue *q, AVPacket *pkt)
{ {
PacketList *pkt1; PacketListEntry *pkt1;
// Drop Packet if queue size is > maximum queue size // Drop Packet if queue size is > maximum queue size
if (avpacket_queue_size(q) > (uint64_t)q->max_q_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; return -1;
} }
pkt1 = (PacketList *)av_malloc(sizeof(PacketList)); pkt1 = (PacketListEntry *)av_malloc(sizeof(*pkt1));
if (!pkt1) { if (!pkt1) {
av_packet_unref(pkt); av_packet_unref(pkt);
return -1; return -1;
@ -540,13 +540,13 @@ static int avpacket_queue_put(AVPacketQueue *q, AVPacket *pkt)
pthread_mutex_lock(&q->mutex); pthread_mutex_lock(&q->mutex);
if (!q->last_pkt) { if (!q->pkt_list.tail) {
q->first_pkt = pkt1; q->pkt_list.head = pkt1;
} else { } 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->nb_packets++;
q->size += pkt1->pkt.size + sizeof(*pkt1); 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) static int avpacket_queue_get(AVPacketQueue *q, AVPacket *pkt, int block)
{ {
PacketList *pkt1;
int ret; int ret;
pthread_mutex_lock(&q->mutex); pthread_mutex_lock(&q->mutex);
for (;; ) { for (;; ) {
pkt1 = q->first_pkt; PacketListEntry *pkt1 = q->pkt_list.head;
if (pkt1) { if (pkt1) {
q->first_pkt = pkt1->next; q->pkt_list.head = pkt1->next;
if (!q->first_pkt) { if (!q->pkt_list.head) {
q->last_pkt = NULL; q->pkt_list.tail = NULL;
} }
q->nb_packets--; q->nb_packets--;
q->size -= pkt1->pkt.size + sizeof(*pkt1); q->size -= pkt1->pkt.size + sizeof(*pkt1);

View File

@ -238,7 +238,7 @@ static int
dshow_read_close(AVFormatContext *s) dshow_read_close(AVFormatContext *s)
{ {
struct dshow_ctx *ctx = s->priv_data; struct dshow_ctx *ctx = s->priv_data;
PacketList *pktl; PacketListEntry *pktl;
if (ctx->control) { if (ctx->control) {
IMediaControl_Stop(ctx->control); IMediaControl_Stop(ctx->control);
@ -298,7 +298,7 @@ dshow_read_close(AVFormatContext *s)
pktl = ctx->pktl; pktl = ctx->pktl;
while (pktl) { while (pktl) {
PacketList *next = pktl->next; PacketListEntry *next = pktl->next;
av_packet_unref(&pktl->pkt); av_packet_unref(&pktl->pkt);
av_free(pktl); av_free(pktl);
pktl = next; 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; AVFormatContext *s = priv_data;
struct dshow_ctx *ctx = s->priv_data; struct dshow_ctx *ctx = s->priv_data;
PacketList **ppktl, *pktl_next; PacketListEntry **ppktl, *pktl_next;
// dump_videohdr(s, vdhdr); // 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)) if(shall_we_drop(s, index, devtype))
goto fail; goto fail;
pktl_next = av_mallocz(sizeof(PacketList)); pktl_next = av_mallocz(sizeof(*pktl_next));
if(!pktl_next) if(!pktl_next)
goto fail; goto fail;
@ -1868,7 +1868,7 @@ static int dshow_check_event_queue(IMediaEvent *media_event)
static int dshow_read_packet(AVFormatContext *s, AVPacket *pkt) static int dshow_read_packet(AVFormatContext *s, AVPacket *pkt)
{ {
struct dshow_ctx *ctx = s->priv_data; struct dshow_ctx *ctx = s->priv_data;
PacketList *pktl = NULL; PacketListEntry *pktl = NULL;
while (!ctx->eof && !pktl) { while (!ctx->eof && !pktl) {
WaitForSingleObject(ctx->mutex, INFINITE); WaitForSingleObject(ctx->mutex, INFINITE);

View File

@ -322,7 +322,7 @@ struct dshow_ctx {
HANDLE mutex; HANDLE mutex;
HANDLE event[2]; /* event[0] is set by DirectShow HANDLE event[2]; /* event[0] is set by DirectShow
* event[1] is set by callback() */ * event[1] is set by callback() */
PacketList *pktl; PacketListEntry *pktl;
int eof; int eof;

View File

@ -45,7 +45,7 @@ struct vfw_ctx {
HWND hwnd; HWND hwnd;
HANDLE mutex; HANDLE mutex;
HANDLE event; HANDLE event;
PacketList *pktl; PacketListEntry *pktl;
unsigned int curbufsize; unsigned int curbufsize;
unsigned int frame_num; unsigned int frame_num;
char *video_size; /**< A string describing video size, set by a private option. */ 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; AVFormatContext *s;
struct vfw_ctx *ctx; struct vfw_ctx *ctx;
PacketList **ppktl, *pktl_next; PacketListEntry **ppktl, *pktl_next;
s = (AVFormatContext *) GetWindowLongPtr(hwnd, GWLP_USERDATA); s = (AVFormatContext *) GetWindowLongPtr(hwnd, GWLP_USERDATA);
ctx = s->priv_data; ctx = s->priv_data;
@ -191,7 +191,7 @@ static LRESULT CALLBACK videostream_cb(HWND hwnd, LPVIDEOHDR vdhdr)
WaitForSingleObject(ctx->mutex, INFINITE); WaitForSingleObject(ctx->mutex, INFINITE);
pktl_next = av_mallocz(sizeof(PacketList)); pktl_next = av_mallocz(sizeof(*pktl_next));
if(!pktl_next) if(!pktl_next)
goto fail; goto fail;
@ -220,7 +220,7 @@ fail:
static int vfw_read_close(AVFormatContext *s) static int vfw_read_close(AVFormatContext *s)
{ {
struct vfw_ctx *ctx = s->priv_data; struct vfw_ctx *ctx = s->priv_data;
PacketList *pktl; PacketListEntry *pktl;
if(ctx->hwnd) { if(ctx->hwnd) {
SendMessage(ctx->hwnd, WM_CAP_SET_CALLBACK_VIDEOSTREAM, 0, 0); SendMessage(ctx->hwnd, WM_CAP_SET_CALLBACK_VIDEOSTREAM, 0, 0);
@ -234,7 +234,7 @@ static int vfw_read_close(AVFormatContext *s)
pktl = ctx->pktl; pktl = ctx->pktl;
while (pktl) { while (pktl) {
PacketList *next = pktl->next; PacketListEntry *next = pktl->next;
av_packet_unref(&pktl->pkt); av_packet_unref(&pktl->pkt);
av_free(pktl); av_free(pktl);
pktl = next; pktl = next;
@ -440,7 +440,7 @@ fail:
static int vfw_read_packet(AVFormatContext *s, AVPacket *pkt) static int vfw_read_packet(AVFormatContext *s, AVPacket *pkt)
{ {
struct vfw_ctx *ctx = s->priv_data; struct vfw_ctx *ctx = s->priv_data;
PacketList *pktl = NULL; PacketListEntry *pktl = NULL;
while(!pktl) { while(!pktl) {
WaitForSingleObject(ctx->mutex, INFINITE); WaitForSingleObject(ctx->mutex, INFINITE);

View File

@ -37,7 +37,7 @@ typedef struct AIFFOutputContext {
int64_t frames; int64_t frames;
int64_t ssnd; int64_t ssnd;
int audio_stream_idx; int audio_stream_idx;
PacketList *pict_list, *pict_list_end; PacketList pict_list;
int write_id3v2; int write_id3v2;
int id3v2_version; int id3v2_version;
} AIFFOutputContext; } AIFFOutputContext;
@ -48,9 +48,9 @@ static int put_id3v2_tags(AVFormatContext *s, AIFFOutputContext *aiff)
uint64_t pos, end, size; uint64_t pos, end, size;
ID3v2EncContext id3v2 = { 0 }; ID3v2EncContext id3v2 = { 0 };
AVIOContext *pb = s->pb; 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; return 0;
avio_wl32(pb, MKTAG('I', 'D', '3', ' ')); 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_start(&id3v2, pb, aiff->id3v2_version, ID3v2_DEFAULT_MAGIC);
ff_id3v2_write_metadata(s, &id3v2); ff_id3v2_write_metadata(s, &id3v2);
while (pict_list) { while (list_entry) {
if ((ret = ff_id3v2_write_apic(s, &id3v2, &pict_list->pkt)) < 0) if ((ret = ff_id3v2_write_apic(s, &id3v2, &list_entry->pkt)) < 0)
return ret; return ret;
pict_list = pict_list->next; list_entry = list_entry->next;
} }
ff_id3v2_finish(&id3v2, pb, s->metadata_header_padding); 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) if (s->streams[pkt->stream_index]->nb_frames >= 1)
return 0; return 0;
return avpriv_packet_list_put(&aiff->pict_list, &aiff->pict_list_end, return avpriv_packet_list_put(&aiff->pict_list, pkt, NULL, 0);
pkt, NULL, 0);
} }
return 0; return 0;
@ -265,7 +264,7 @@ static void aiff_deinit(AVFormatContext *s)
{ {
AIFFOutputContext *aiff = s->priv_data; 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) #define OFFSET(x) offsetof(AIFFOutputContext, x)

View File

@ -537,7 +537,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
#endif #endif
for (;;) { for (;;) {
PacketList *pktl = si->raw_packet_buffer; PacketListEntry *pktl = si->raw_packet_buffer.head;
AVStream *st; AVStream *st;
FFStream *sti; FFStream *sti;
const AVPacket *pkt1; const AVPacket *pkt1;
@ -548,8 +548,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
if ((err = probe_codec(s, st, NULL)) < 0) if ((err = probe_codec(s, st, NULL)) < 0)
return err; return err;
if (ffstream(st)->request_probe <= 0) { if (ffstream(st)->request_probe <= 0) {
avpriv_packet_list_get(&si->raw_packet_buffer, avpriv_packet_list_get(&si->raw_packet_buffer, pkt);
&si->raw_packet_buffer_end, pkt);
si->raw_packet_buffer_size -= pkt->size; si->raw_packet_buffer_size -= pkt->size;
return 0; return 0;
} }
@ -624,13 +623,12 @@ FF_ENABLE_DEPRECATION_WARNINGS
return 0; return 0;
err = avpriv_packet_list_put(&si->raw_packet_buffer, err = avpriv_packet_list_put(&si->raw_packet_buffer,
&si->raw_packet_buffer_end,
pkt, NULL, 0); pkt, NULL, 0);
if (err < 0) { if (err < 0) {
av_packet_unref(pkt); av_packet_unref(pkt);
return err; return err;
} }
pkt1 = &si->raw_packet_buffer_end->pkt; pkt1 = &si->raw_packet_buffer.tail->pkt;
si->raw_packet_buffer_size += pkt1->size; si->raw_packet_buffer_size += pkt1->size;
if ((err = probe_codec(s, st, pkt1)) < 0) 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; 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); FFFormatContext *const si = ffformatcontext(s);
if (pktl->next) if (pktl->next)
return pktl->next; return pktl->next;
if (pktl == si->packet_buffer_end) if (pktl == si->packet_buffer.tail)
return si->parse_queue; return si->parse_queue.head;
return NULL; 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. * of the packets in a window.
*/ */
static void update_dts_from_pts(AVFormatContext *s, int stream_index, static void update_dts_from_pts(AVFormatContext *s, int stream_index,
PacketList *pkt_buffer) PacketListEntry *pkt_buffer)
{ {
AVStream *const st = s->streams[stream_index]; AVStream *const st = s->streams[stream_index];
int delay = ffstream(st)->avctx->has_b_frames; 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); FFFormatContext *const si = ffformatcontext(s);
AVStream *const st = s->streams[stream_index]; AVStream *const st = s->streams[stream_index];
FFStream *const sti = ffstream(st); 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; uint64_t shift;
@ -823,7 +822,7 @@ static void update_initial_timestamps(AVFormatContext *s, int stream_index,
if (is_relative(pts)) if (is_relative(pts))
pts += shift; 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) if (pktl_it->pkt.stream_index != stream_index)
continue; continue;
if (is_relative(pktl_it->pkt.pts)) 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); FFFormatContext *const si = ffformatcontext(s);
FFStream *const sti = ffstream(st); 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; int64_t cur_dts = RELATIVE_TS_BASE;
if (sti->first_dts != AV_NOPTS_VALUE) { 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)); av_log(s, AV_LOG_DEBUG, "first_dts %s but no packet with dts in the queue\n", av_ts2str(sti->first_dts));
return; 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; sti->first_dts = cur_dts;
} else if (sti->cur_dts != RELATIVE_TS_BASE) } else if (sti->cur_dts != RELATIVE_TS_BASE)
return; 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); update_initial_durations(s, st, pkt->stream_index, pkt->duration);
/* Correct timestamps with byte offset if demuxers only have timestamps /* 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); compute_pkt_fields(s, st, sti->parser, out_pkt, next_dts, next_pts);
ret = avpriv_packet_list_put(&si->parse_queue, ret = avpriv_packet_list_put(&si->parse_queue,
&si->parse_queue_end,
out_pkt, NULL, 0); out_pkt, NULL, 0);
if (ret < 0) if (ret < 0)
goto fail; goto fail;
@ -1225,7 +1223,7 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt)
int ret, got_packet = 0; int ret, got_packet = 0;
AVDictionary *metadata = NULL; AVDictionary *metadata = NULL;
while (!got_packet && !si->parse_queue) { while (!got_packet && !si->parse_queue.head) {
AVStream *st; AVStream *st;
FFStream *sti; FFStream *sti;
@ -1338,8 +1336,8 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt)
} }
} }
if (!got_packet && si->parse_queue) if (!got_packet && si->parse_queue.head)
ret = avpriv_packet_list_get(&si->parse_queue, &si->parse_queue_end, pkt); ret = avpriv_packet_list_get(&si->parse_queue, pkt);
if (ret >= 0) { if (ret >= 0) {
AVStream *const st = s->streams[pkt->stream_index]; AVStream *const st = s->streams[pkt->stream_index];
@ -1420,9 +1418,8 @@ int av_read_frame(AVFormatContext *s, AVPacket *pkt)
AVStream *st; AVStream *st;
if (!genpts) { if (!genpts) {
ret = si->packet_buffer ret = si->packet_buffer.head
? avpriv_packet_list_get(&si->packet_buffer, ? avpriv_packet_list_get(&si->packet_buffer, pkt)
&si->packet_buffer_end, pkt)
: read_frame_internal(s, pkt); : read_frame_internal(s, pkt);
if (ret < 0) if (ret < 0)
return ret; return ret;
@ -1430,7 +1427,7 @@ int av_read_frame(AVFormatContext *s, AVPacket *pkt)
} }
for (;;) { for (;;) {
PacketList *pktl = si->packet_buffer; PacketListEntry *pktl = si->packet_buffer.head;
if (pktl) { if (pktl) {
AVPacket *next_pkt = &pktl->pkt; 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. // 3. the packets for this stream at the end of the files had valid dts.
next_pkt->pts = last_dts + next_pkt->duration; 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 */ /* read packet from packet buffer, if there is data */
st = s->streams[next_pkt->stream_index]; st = s->streams[next_pkt->stream_index];
if (!(next_pkt->pts == AV_NOPTS_VALUE && st->discard < AVDISCARD_ALL && if (!(next_pkt->pts == AV_NOPTS_VALUE && st->discard < AVDISCARD_ALL &&
next_pkt->dts != AV_NOPTS_VALUE && !eof)) { next_pkt->dts != AV_NOPTS_VALUE && !eof)) {
ret = avpriv_packet_list_get(&si->packet_buffer, ret = avpriv_packet_list_get(&si->packet_buffer, pkt);
&si->packet_buffer_end, pkt);
goto return_packet; goto return_packet;
} }
} }
@ -1486,7 +1482,6 @@ int av_read_frame(AVFormatContext *s, AVPacket *pkt)
} }
ret = avpriv_packet_list_put(&si->packet_buffer, ret = avpriv_packet_list_put(&si->packet_buffer,
&si->packet_buffer_end,
pkt, NULL, 0); pkt, NULL, 0);
if (ret < 0) { if (ret < 0) {
av_packet_unref(pkt); av_packet_unref(pkt);
@ -2598,12 +2593,11 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
if (!(ic->flags & AVFMT_FLAG_NOBUFFER)) { if (!(ic->flags & AVFMT_FLAG_NOBUFFER)) {
ret = avpriv_packet_list_put(&si->packet_buffer, ret = avpriv_packet_list_put(&si->packet_buffer,
&si->packet_buffer_end,
pkt1, NULL, 0); pkt1, NULL, 0);
if (ret < 0) if (ret < 0)
goto unref_then_goto_end; goto unref_then_goto_end;
pkt = &si->packet_buffer_end->pkt; pkt = &si->packet_buffer.tail->pkt;
} else { } else {
pkt = pkt1; pkt = pkt1;
} }
@ -2751,8 +2745,8 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
// EOF already reached while reading the stream above. // EOF already reached while reading the stream above.
// So continue with reoordering DTS with whatever delay we have. // So continue with reoordering DTS with whatever delay we have.
if (si->packet_buffer && !has_decode_delay_been_guessed(st)) { if (si->packet_buffer.head && !has_decode_delay_been_guessed(st)) {
update_dts_from_pts(ic, stream_index, si->packet_buffer); update_dts_from_pts(ic, stream_index, si->packet_buffer.head);
} }
} }
} }

View File

@ -40,7 +40,7 @@ typedef struct FlacMuxerContext {
int audio_stream_idx; int audio_stream_idx;
int waiting_pics; int waiting_pics;
/* audio packets are queued here until we get all the attached pictures */ /* 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 */ /* updated streaminfo sent by the encoder at the end */
uint8_t streaminfo[FLAC_STREAMINFO_SIZE]; uint8_t streaminfo[FLAC_STREAMINFO_SIZE];
@ -306,8 +306,8 @@ static int flac_queue_flush(AVFormatContext *s)
if (ret < 0) if (ret < 0)
write = 0; write = 0;
while (c->queue) { while (c->queue.head) {
avpriv_packet_list_get(&c->queue, &c->queue_end, pkt); avpriv_packet_list_get(&c->queue, pkt);
if (write && (ret = flac_write_audio_packet(s, pkt)) < 0) if (write && (ret = flac_write_audio_packet(s, pkt)) < 0)
write = 0; write = 0;
av_packet_unref(pkt); av_packet_unref(pkt);
@ -347,7 +347,7 @@ static void flac_deinit(struct AVFormatContext *s)
{ {
FlacMuxerContext *c = s->priv_data; 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++) for (unsigned i = 0; i < s->nb_streams; i++)
av_packet_free((AVPacket **)&s->streams[i]->priv_data); 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 (pkt->stream_index == c->audio_stream_idx) {
if (c->waiting_pics) { if (c->waiting_pics) {
/* buffer audio packets until we get all the pictures */ /* 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) { if (ret < 0) {
av_log(s, AV_LOG_ERROR, "Out of memory in packet queue; skipping attached pictures\n"); av_log(s, AV_LOG_ERROR, "Out of memory in packet queue; skipping attached pictures\n");
c->waiting_pics = 0; c->waiting_pics = 0;

View File

@ -25,6 +25,7 @@
#include "libavcodec/avcodec.h" #include "libavcodec/avcodec.h"
#include "libavcodec/bsf.h" #include "libavcodec/bsf.h"
#include "libavcodec/packet_internal.h"
#include "avformat.h" #include "avformat.h"
#include "os_support.h" #include "os_support.h"
@ -92,8 +93,7 @@ typedef struct FFFormatContext {
* not decoded, for example to get the codec parameters in MPEG * not decoded, for example to get the codec parameters in MPEG
* streams. * streams.
*/ */
struct PacketList *packet_buffer; PacketList packet_buffer;
struct PacketList *packet_buffer_end;
/* av_seek_frame() support */ /* av_seek_frame() support */
int64_t data_offset; /**< offset of the first packet */ 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 * be identified, as parsing cannot be done without knowing the
* codec. * codec.
*/ */
struct PacketList *raw_packet_buffer; PacketList raw_packet_buffer;
struct PacketList *raw_packet_buffer_end;
/** /**
* Packets split by the parser get queued here. * Packets split by the parser get queued here.
*/ */
struct PacketList *parse_queue; PacketList parse_queue;
struct PacketList *parse_queue_end;
/** /**
* The generic code uses this as a temporary packet * The generic code uses this as a temporary packet
* to parse packets or for muxing, especially flushing. * 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. * 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; int64_t last_IP_pts;
int last_IP_duration; int last_IP_duration;

View File

@ -396,8 +396,7 @@ typedef struct MatroskaDemuxContext {
AVPacket *pkt; AVPacket *pkt;
/* the packet queue */ /* the packet queue */
PacketList *queue; PacketList queue;
PacketList *queue_end;
int done; int done;
@ -3112,11 +3111,11 @@ static int matroska_read_header(AVFormatContext *s)
static int matroska_deliver_packet(MatroskaDemuxContext *matroska, static int matroska_deliver_packet(MatroskaDemuxContext *matroska,
AVPacket *pkt) AVPacket *pkt)
{ {
if (matroska->queue) { if (matroska->queue.head) {
MatroskaTrack *tracks = matroska->tracks.elem; MatroskaTrack *tracks = matroska->tracks.elem;
MatroskaTrack *track; MatroskaTrack *track;
avpriv_packet_list_get(&matroska->queue, &matroska->queue_end, pkt); avpriv_packet_list_get(&matroska->queue, pkt);
track = &tracks[pkt->stream_index]; track = &tracks[pkt->stream_index];
if (track->has_palette) { if (track->has_palette) {
uint8_t *pal = av_packet_new_side_data(pkt, AV_PKT_DATA_PALETTE, AVPALETTE_SIZE); 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) 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, 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; track->audio.buf_timecode = AV_NOPTS_VALUE;
pkt->pos = pos; pkt->pos = pos;
pkt->stream_index = st->index; 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) { if (ret < 0) {
av_packet_unref(pkt); av_packet_unref(pkt);
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
@ -3526,7 +3525,7 @@ static int matroska_parse_webvtt(MatroskaDemuxContext *matroska,
pkt->duration = duration; pkt->duration = duration;
pkt->pos = pos; 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) { if (err < 0) {
av_packet_unref(pkt); av_packet_unref(pkt);
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
@ -3628,7 +3627,7 @@ static int matroska_parse_frame(MatroskaDemuxContext *matroska,
pkt->pos = pos; pkt->pos = pos;
pkt->duration = lace_duration; 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) { if (res < 0) {
av_packet_unref(pkt); av_packet_unref(pkt);
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
@ -4030,10 +4029,10 @@ static int webm_clusters_start_with_keyframe(AVFormatContext *s)
matroska_reset_status(matroska, 0, cluster_pos); matroska_reset_status(matroska, 0, cluster_pos);
matroska_clear_queue(matroska); matroska_clear_queue(matroska);
if (matroska_parse_cluster(matroska) < 0 || if (matroska_parse_cluster(matroska) < 0 ||
!matroska->queue) { !matroska->queue.head) {
break; break;
} }
pkt = &matroska->queue->pkt; pkt = &matroska->queue.head->pkt;
// 4 + read is the length of the cluster id and the cluster length field. // 4 + read is the length of the cluster id and the cluster length field.
cluster_pos += 4 + read + cluster_length; cluster_pos += 4 + read + cluster_length;
if (!(pkt->flags & AV_PKT_FLAG_KEY)) { if (!(pkt->flags & AV_PKT_FLAG_KEY)) {

View File

@ -5339,7 +5339,7 @@ static int mov_write_squashed_packet(AVFormatContext *s, MOVTrack *track)
switch (track->st->codecpar->codec_id) { switch (track->st->codecpar->codec_id) {
case AV_CODEC_ID_TTML: { 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) { if ((ret = ff_mov_generate_squashed_ttml_packet(s, track, squashed_packet)) < 0) {
goto finish_squash; 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 /* The following will reset pkt and is only allowed to be used
* because we return immediately. afterwards. */ * because we return immediately. afterwards. */
if ((ret = avpriv_packet_list_put(&trk->squashed_packet_queue, if ((ret = avpriv_packet_list_put(&trk->squashed_packet_queue,
&trk->squashed_packet_queue_end,
pkt, NULL, 0)) < 0) { pkt, NULL, 0)) < 0) {
return ret; return ret;
} }
@ -6478,8 +6477,7 @@ static void mov_free(AVFormatContext *s)
ff_mov_cenc_free(&track->cenc); ff_mov_cenc_free(&track->cenc);
ffio_free_dyn_buf(&track->mdat_buf); ffio_free_dyn_buf(&track->mdat_buf);
avpriv_packet_list_free(&track->squashed_packet_queue, avpriv_packet_list_free(&track->squashed_packet_queue);
&track->squashed_packet_queue_end);
} }
av_freep(&mov->tracks); av_freep(&mov->tracks);

View File

@ -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 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; } MOVTrack;
typedef enum { typedef enum {

View File

@ -70,9 +70,7 @@ static int mov_write_ttml_document_from_queue(AVFormatContext *s,
return ret; return ret;
} }
while (!avpriv_packet_list_get(&track->squashed_packet_queue, while (!avpriv_packet_list_get(&track->squashed_packet_queue, pkt)) {
&track->squashed_packet_queue_end,
pkt)) {
end_ts = FFMAX(end_ts, pkt->pts + pkt->duration); end_ts = FFMAX(end_ts, pkt->pts + pkt->duration);
// in case of the 'dfxp' muxing mode, each written document is offset // 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; goto cleanup;
} }
if (!track->squashed_packet_queue) { if (!track->squashed_packet_queue.head) {
// empty queue, write minimal empty document with zero duration // empty queue, write minimal empty document with zero duration
avio_write(ttml_ctx->pb, empty_ttml_document, avio_write(ttml_ctx->pb, empty_ttml_document,
sizeof(empty_ttml_document) - 1); sizeof(empty_ttml_document) - 1);

View File

@ -132,7 +132,7 @@ typedef struct MP3Context {
int pics_to_write; int pics_to_write;
/* audio packets are queued here until we get all the attached pictures */ /* audio packets are queued here until we get all the attached pictures */
PacketList *queue, *queue_end; PacketList queue;
} MP3Context; } MP3Context;
static const uint8_t xing_offtbl[2][2] = {{32, 17}, {17, 9}}; 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); ff_id3v2_finish(&mp3->id3, s->pb, s->metadata_header_padding);
mp3_write_xing(s); mp3_write_xing(s);
while (mp3->queue) { while (mp3->queue.head) {
avpriv_packet_list_get(&mp3->queue, &mp3->queue_end, pkt); avpriv_packet_list_get(&mp3->queue, pkt);
if (write && (ret = mp3_write_audio_packet(s, pkt)) < 0) if (write && (ret = mp3_write_audio_packet(s, pkt)) < 0)
write = 0; write = 0;
av_packet_unref(pkt); 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 (pkt->stream_index == mp3->audio_stream_idx) {
if (mp3->pics_to_write) { if (mp3->pics_to_write) {
/* buffer audio packets until we get all the pictures */ /* buffer audio packets until we get all the pictures */
int ret = avpriv_packet_list_put(&mp3->queue, &mp3->queue_end, int ret = avpriv_packet_list_put(&mp3->queue, pkt, NULL, 0);
pkt, NULL, 0);
if (ret < 0) { if (ret < 0) {
av_log(s, AV_LOG_WARNING, "Not enough memory to buffer audio. Skipping picture streams\n"); 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; 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); av_freep(&mp3->xing_frame);
} }

View File

@ -809,12 +809,12 @@ int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt,
{ {
int ret; int ret;
FFFormatContext *const si = ffformatcontext(s); FFFormatContext *const si = ffformatcontext(s);
PacketList **next_point, *this_pktl; PacketListEntry **next_point, *this_pktl;
AVStream *st = s->streams[pkt->stream_index]; AVStream *st = s->streams[pkt->stream_index];
FFStream *const sti = ffstream(st); FFStream *const sti = ffstream(st);
int chunked = s->max_chunk_size || s->max_chunk_duration; 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) { if (!this_pktl) {
av_packet_unref(pkt); av_packet_unref(pkt);
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
@ -831,7 +831,7 @@ int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt,
if (sti->last_in_packet_buffer) { if (sti->last_in_packet_buffer) {
next_point = &(sti->last_in_packet_buffer->next); next_point = &(sti->last_in_packet_buffer->next);
} else { } else {
next_point = &si->packet_buffer; next_point = &si->packet_buffer.head;
} }
if (chunked) { if (chunked) {
@ -855,7 +855,7 @@ int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt,
if (chunked && !(pkt->flags & CHUNK_START)) if (chunked && !(pkt->flags & CHUNK_START))
goto next_non_null; 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 while ( *next_point
&& ((chunked && !((*next_point)->pkt.flags&CHUNK_START)) && ((chunked && !((*next_point)->pkt.flags&CHUNK_START))
|| !compare(s, &(*next_point)->pkt, pkt))) || !compare(s, &(*next_point)->pkt, pkt)))
@ -863,12 +863,12 @@ int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt,
if (*next_point) if (*next_point)
goto next_non_null; goto next_non_null;
} else { } else {
next_point = &(si->packet_buffer_end->next); next_point = &(si->packet_buffer.tail->next);
} }
} }
av_assert1(!*next_point); av_assert1(!*next_point);
si->packet_buffer_end = this_pktl; si->packet_buffer.tail = this_pktl;
next_non_null: next_non_null:
this_pktl->next = *next_point; this_pktl->next = *next_point;
@ -939,11 +939,11 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *pkt,
flush = 1; flush = 1;
if (s->max_interleave_delta > 0 && if (s->max_interleave_delta > 0 &&
si->packet_buffer && si->packet_buffer.head &&
!flush && !flush &&
si->nb_interleaved_streams == stream_count+noninterleaved_count 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 delta_dts = INT64_MIN;
int64_t top_dts = av_rescale_q(top_pkt->dts, int64_t top_dts = av_rescale_q(top_pkt->dts,
s->streams[top_pkt->stream_index]->time_base, 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++) { for (unsigned i = 0; i < s->nb_streams; i++) {
const AVStream *const st = s->streams[i]; const AVStream *const st = s->streams[i];
const FFStream *const sti = cffstream(st); 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; int64_t last_dts;
if (!last) 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 && eof &&
(s->flags & AVFMT_FLAG_SHORTEST) && (s->flags & AVFMT_FLAG_SHORTEST) &&
si->shortest_end == AV_NOPTS_VALUE) { 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, si->shortest_end = av_rescale_q(top_pkt->dts,
s->streams[top_pkt->stream_index]->time_base, 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) { if (si->shortest_end != AV_NOPTS_VALUE) {
while (si->packet_buffer) { while (si->packet_buffer.head) {
PacketList *pktl = si->packet_buffer; PacketListEntry *pktl = si->packet_buffer.head;
AVPacket *const top_pkt = &pktl->pkt; AVPacket *const top_pkt = &pktl->pkt;
AVStream *const st = s->streams[top_pkt->stream_index]; AVStream *const st = s->streams[top_pkt->stream_index];
FFStream *const sti = ffstream(st); 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) if (si->shortest_end + 1 >= top_dts)
break; break;
si->packet_buffer = pktl->next; si->packet_buffer.head = pktl->next;
if (!si->packet_buffer) if (!si->packet_buffer.head)
si->packet_buffer_end = NULL; si->packet_buffer.tail = NULL;
if (sti->last_in_packet_buffer == pktl) if (sti->last_in_packet_buffer == pktl)
sti->last_in_packet_buffer = NULL; sti->last_in_packet_buffer = NULL;
@ -1010,13 +1010,13 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *pkt,
} }
if (stream_count && flush) { if (stream_count && flush) {
PacketList *pktl = si->packet_buffer; PacketListEntry *pktl = si->packet_buffer.head;
AVStream *const st = s->streams[pktl->pkt.stream_index]; AVStream *const st = s->streams[pktl->pkt.stream_index];
FFStream *const sti = ffstream(st); FFStream *const sti = ffstream(st);
if (sti->last_in_packet_buffer == pktl) if (sti->last_in_packet_buffer == pktl)
sti->last_in_packet_buffer = NULL; 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; return 1;
} else { } 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) const AVPacket *ff_interleaved_peek(AVFormatContext *s, int stream)
{ {
FFFormatContext *const si = ffformatcontext(s); FFFormatContext *const si = ffformatcontext(s);
PacketList *pktl = si->packet_buffer; PacketListEntry *pktl = si->packet_buffer.head;
while (pktl) { while (pktl) {
if (pktl->pkt.stream_index == stream) { if (pktl->pkt.stream_index == stream) {
return &pktl->pkt; return &pktl->pkt;

View File

@ -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; stream_count += !!ffstream(s->streams[i])->last_in_packet_buffer;
if (stream_count && (s->nb_streams == stream_count || flush)) { 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) { if (s->nb_streams != stream_count) {
PacketList *last = NULL; PacketListEntry *last = NULL;
// find last packet in edit unit // find last packet in edit unit
while (pktl) { while (pktl) {
if (!stream_count || pktl->pkt.stream_index == 0) 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 // purge packet queue
while (pktl) { while (pktl) {
PacketList *next = pktl->next; PacketListEntry *next = pktl->next;
av_packet_unref(&pktl->pkt); av_packet_unref(&pktl->pkt);
av_freep(&pktl); av_freep(&pktl);
pktl = next; pktl = next;
@ -3121,16 +3121,16 @@ static int mxf_interleave_get_packet(AVFormatContext *s, AVPacket *out, int flus
if (last) if (last)
last->next = NULL; last->next = NULL;
else { else {
si->packet_buffer = NULL; si->packet_buffer.head = NULL;
si->packet_buffer_end = NULL; si->packet_buffer.tail = NULL;
goto out; goto out;
} }
pktl = si->packet_buffer; pktl = si->packet_buffer.head;
} }
if (ffstream(s->streams[pktl->pkt.stream_index])->last_in_packet_buffer == pktl) 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; 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); av_log(s, AV_LOG_TRACE, "out st:%d dts:%"PRId64"\n", out->stream_index, out->dts);
return 1; return 1;
} else { } else {

View File

@ -30,7 +30,7 @@
typedef struct TTAMuxContext { typedef struct TTAMuxContext {
AVIOContext *seek_table; AVIOContext *seek_table;
PacketList *queue, *queue_end; PacketList queue;
uint32_t nb_samples; uint32_t nb_samples;
int frame_size; int frame_size;
int last_frame; int last_frame;
@ -94,12 +94,11 @@ static int tta_write_packet(AVFormatContext *s, AVPacket *pkt)
TTAMuxContext *tta = s->priv_data; TTAMuxContext *tta = s->priv_data;
int ret; int ret;
ret = avpriv_packet_list_put(&tta->queue, &tta->queue_end, pkt, ret = avpriv_packet_list_put(&tta->queue, pkt, NULL, 0);
NULL, 0);
if (ret < 0) { if (ret < 0) {
return ret; return ret;
} }
pkt = &tta->queue_end->pkt; pkt = &tta->queue.tail->pkt;
avio_wl32(tta->seek_table, pkt->size); avio_wl32(tta->seek_table, pkt->size);
tta->nb_samples += pkt->duration; tta->nb_samples += pkt->duration;
@ -126,8 +125,8 @@ static void tta_queue_flush(AVFormatContext *s)
TTAMuxContext *tta = s->priv_data; TTAMuxContext *tta = s->priv_data;
AVPacket *const pkt = ffformatcontext(s)->pkt; AVPacket *const pkt = ffformatcontext(s)->pkt;
while (tta->queue) { while (tta->queue.head) {
avpriv_packet_list_get(&tta->queue, &tta->queue_end, pkt); avpriv_packet_list_get(&tta->queue, pkt);
avio_write(s->pb, pkt->data, pkt->size); avio_write(s->pb, pkt->data, pkt->size);
av_packet_unref(pkt); av_packet_unref(pkt);
} }
@ -163,7 +162,7 @@ static void tta_deinit(AVFormatContext *s)
TTAMuxContext *tta = s->priv_data; TTAMuxContext *tta = s->priv_data;
ffio_free_dyn_buf(&tta->seek_table); 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 = { const AVOutputFormat ff_tta_muxer = {

View File

@ -239,7 +239,6 @@ int avformat_queue_attached_pictures(AVFormatContext *s)
} }
ret = avpriv_packet_list_put(&si->raw_packet_buffer, ret = avpriv_packet_list_put(&si->raw_packet_buffer,
&si->raw_packet_buffer_end,
&s->streams[i]->attached_pic, &s->streams[i]->attached_pic,
av_packet_ref, 0); av_packet_ref, 0);
if (ret < 0) if (ret < 0)
@ -300,9 +299,9 @@ int ff_is_intra_only(enum AVCodecID id)
void ff_flush_packet_queue(AVFormatContext *s) void ff_flush_packet_queue(AVFormatContext *s)
{ {
FFFormatContext *const si = ffformatcontext(s); FFFormatContext *const si = ffformatcontext(s);
avpriv_packet_list_free(&si->parse_queue, &si->parse_queue_end); avpriv_packet_list_free(&si->parse_queue);
avpriv_packet_list_free(&si->packet_buffer, &si->packet_buffer_end); avpriv_packet_list_free(&si->packet_buffer);
avpriv_packet_list_free(&si->raw_packet_buffer, &si->raw_packet_buffer_end); avpriv_packet_list_free(&si->raw_packet_buffer);
si->raw_packet_buffer_size = 0; si->raw_packet_buffer_size = 0;
} }