summaryrefslogtreecommitdiff
path: root/libavdevice
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 /libavdevice
parentb74e47c4ff5bca998936c0d8b9a0892104a7403d (diff)
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 'libavdevice')
-rw-r--r--libavdevice/decklink_common.h5
-rw-r--r--libavdevice/decklink_dec.cpp29
-rw-r--r--libavdevice/dshow.c10
-rw-r--r--libavdevice/dshow_capture.h2
-rw-r--r--libavdevice/vfwcap.c12
5 files changed, 30 insertions, 28 deletions
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);