1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-11-23 21:54:53 +02:00

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

@@ -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;

View File

@@ -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);

View File

@@ -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);

View File

@@ -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;

View File

@@ -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);