mirror of
https://github.com/nyanmisaka/ffmpeg-rockchip.git
synced 2025-11-01 04:53:04 +08:00
avdevice/decklink: move AVPacketQueue into decklink_common and rename it to DecklinkPacketQueue
Move the AVPacketQueue functionality that is currently only used for the decklink decode module into decklink_common, so it can be shared by the decklink encoder (i.e. for VANC insertion when we receive data packets separate from video). The threadsafe queue used within the decklink module was named "AVPacketQueue" which implies that it is part of the public API, which it is not. Rename the functions and the name of the queue struct to make clear it is used exclusively by decklink, per Marton Balint's suggestion. Signed-off-by: Devin Heitmueller <dheitmueller@ltnglobal.com> Signed-off-by: Marton Balint <cus@passwd.hu>
This commit is contained in:
committed by
Marton Balint
parent
4373dadc39
commit
4fd729a1f8
@@ -390,6 +390,121 @@ int ff_decklink_set_format(AVFormatContext *avctx, decklink_direction_t directio
|
||||
return ff_decklink_set_format(avctx, 0, 0, 0, 0, AV_FIELD_UNKNOWN, direction);
|
||||
}
|
||||
|
||||
void ff_decklink_packet_queue_init(AVFormatContext *avctx, DecklinkPacketQueue *q)
|
||||
{
|
||||
struct decklink_cctx *ctx = (struct decklink_cctx *)avctx->priv_data;
|
||||
memset(q, 0, sizeof(DecklinkPacketQueue));
|
||||
pthread_mutex_init(&q->mutex, NULL);
|
||||
pthread_cond_init(&q->cond, NULL);
|
||||
q->avctx = avctx;
|
||||
q->max_q_size = ctx->queue_size;
|
||||
}
|
||||
|
||||
void ff_decklink_packet_queue_flush(DecklinkPacketQueue *q)
|
||||
{
|
||||
PacketListEntry *pkt, *pkt1;
|
||||
|
||||
pthread_mutex_lock(&q->mutex);
|
||||
for (pkt = q->pkt_list.head; pkt != NULL; pkt = pkt1) {
|
||||
pkt1 = pkt->next;
|
||||
av_packet_unref(&pkt->pkt);
|
||||
av_freep(&pkt);
|
||||
}
|
||||
q->pkt_list.head = NULL;
|
||||
q->pkt_list.tail = NULL;
|
||||
q->nb_packets = 0;
|
||||
q->size = 0;
|
||||
pthread_mutex_unlock(&q->mutex);
|
||||
}
|
||||
|
||||
void ff_decklink_packet_queue_end(DecklinkPacketQueue *q)
|
||||
{
|
||||
ff_decklink_packet_queue_flush(q);
|
||||
pthread_mutex_destroy(&q->mutex);
|
||||
pthread_cond_destroy(&q->cond);
|
||||
}
|
||||
|
||||
unsigned long long ff_decklink_packet_queue_size(DecklinkPacketQueue *q)
|
||||
{
|
||||
unsigned long long size;
|
||||
pthread_mutex_lock(&q->mutex);
|
||||
size = q->size;
|
||||
pthread_mutex_unlock(&q->mutex);
|
||||
return size;
|
||||
}
|
||||
|
||||
int ff_decklink_packet_queue_put(DecklinkPacketQueue *q, AVPacket *pkt)
|
||||
{
|
||||
PacketListEntry *pkt1;
|
||||
|
||||
// Drop Packet if queue size is > maximum queue size
|
||||
if (ff_decklink_packet_queue_size(q) > (uint64_t)q->max_q_size) {
|
||||
av_packet_unref(pkt);
|
||||
av_log(q->avctx, AV_LOG_WARNING, "Decklink input buffer overrun!\n");
|
||||
return -1;
|
||||
}
|
||||
/* ensure the packet is reference counted */
|
||||
if (av_packet_make_refcounted(pkt) < 0) {
|
||||
av_packet_unref(pkt);
|
||||
return -1;
|
||||
}
|
||||
|
||||
pkt1 = (PacketListEntry *)av_malloc(sizeof(*pkt1));
|
||||
if (!pkt1) {
|
||||
av_packet_unref(pkt);
|
||||
return -1;
|
||||
}
|
||||
av_packet_move_ref(&pkt1->pkt, pkt);
|
||||
pkt1->next = NULL;
|
||||
|
||||
pthread_mutex_lock(&q->mutex);
|
||||
|
||||
if (!q->pkt_list.tail) {
|
||||
q->pkt_list.head = pkt1;
|
||||
} else {
|
||||
q->pkt_list.tail->next = pkt1;
|
||||
}
|
||||
|
||||
q->pkt_list.tail = pkt1;
|
||||
q->nb_packets++;
|
||||
q->size += pkt1->pkt.size + sizeof(*pkt1);
|
||||
|
||||
pthread_cond_signal(&q->cond);
|
||||
|
||||
pthread_mutex_unlock(&q->mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ff_decklink_packet_queue_get(DecklinkPacketQueue *q, AVPacket *pkt, int block)
|
||||
{
|
||||
int ret;
|
||||
|
||||
pthread_mutex_lock(&q->mutex);
|
||||
|
||||
for (;; ) {
|
||||
PacketListEntry *pkt1 = q->pkt_list.head;
|
||||
if (pkt1) {
|
||||
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);
|
||||
*pkt = pkt1->pkt;
|
||||
av_free(pkt1);
|
||||
ret = 1;
|
||||
break;
|
||||
} else if (!block) {
|
||||
ret = 0;
|
||||
break;
|
||||
} else {
|
||||
pthread_cond_wait(&q->cond, &q->mutex);
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&q->mutex);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ff_decklink_list_devices(AVFormatContext *avctx,
|
||||
struct AVDeviceInfoList *device_list,
|
||||
int show_inputs, int show_outputs)
|
||||
|
||||
Reference in New Issue
Block a user