History

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.

Devin Heitmueller committed 3 years ago

Commit 4fd729a1 parent 4373dad3 files · +133 −125Browse files

Showing the changes to libavdevice/decklink_common.cpp (1 of 3 files). Show all

Unified · Split

libavdevice/decklink_common.cpp+115−0
@@ -390,6 +390,121 @@ int ff_decklink_set_format(AVFormatContext *avctx, decklink_direction_t directio · 389 unmodified lines
390390 return ff_decklink_set_format(avctx, 0, 0, 0, 0, AV_FIELD_UNKNOWN, direction);
391391 }
392392
393+void ff_decklink_packet_queue_init(AVFormatContext *avctx, DecklinkPacketQueue *q)
394+{
395+ struct decklink_cctx *ctx = (struct decklink_cctx *)avctx->priv_data;
396+ memset(q, 0, sizeof(DecklinkPacketQueue));
397+ pthread_mutex_init(&q->mutex, NULL);
398+ pthread_cond_init(&q->cond, NULL);
399+ q->avctx = avctx;
400+ q->max_q_size = ctx->queue_size;
401+}
402+
403+void ff_decklink_packet_queue_flush(DecklinkPacketQueue *q)
404+{
405+ PacketListEntry *pkt, *pkt1;
406+
407+ pthread_mutex_lock(&q->mutex);
408+ for (pkt = q->pkt_list.head; pkt != NULL; pkt = pkt1) {
409+ pkt1 = pkt->next;
410+ av_packet_unref(&pkt->pkt);
411+ av_freep(&pkt);
412+ }
413+ q->pkt_list.head = NULL;
414+ q->pkt_list.tail = NULL;
415+ q->nb_packets = 0;
416+ q->size = 0;
417+ pthread_mutex_unlock(&q->mutex);
418+}
419+
420+void ff_decklink_packet_queue_end(DecklinkPacketQueue *q)
421+{
422+ ff_decklink_packet_queue_flush(q);
423+ pthread_mutex_destroy(&q->mutex);
424+ pthread_cond_destroy(&q->cond);
425+}
426+
427+unsigned long long ff_decklink_packet_queue_size(DecklinkPacketQueue *q)
428+{
429+ unsigned long long size;
430+ pthread_mutex_lock(&q->mutex);
431+ size = q->size;
432+ pthread_mutex_unlock(&q->mutex);
433+ return size;
434+}
435+
436+int ff_decklink_packet_queue_put(DecklinkPacketQueue *q, AVPacket *pkt)
437+{
438+ PacketListEntry *pkt1;
439+
440+ // Drop Packet if queue size is > maximum queue size
441+ if (ff_decklink_packet_queue_size(q) > (uint64_t)q->max_q_size) {
442+ av_packet_unref(pkt);
443+ av_log(q->avctx, AV_LOG_WARNING, "Decklink input buffer overrun!\n");
444+ return -1;
445+ }
446+ /* ensure the packet is reference counted */
447+ if (av_packet_make_refcounted(pkt) < 0) {
448+ av_packet_unref(pkt);
449+ return -1;
450+ }
451+
452+ pkt1 = (PacketListEntry *)av_malloc(sizeof(*pkt1));
453+ if (!pkt1) {
454+ av_packet_unref(pkt);
455+ return -1;
456+ }
457+ av_packet_move_ref(&pkt1->pkt, pkt);
458+ pkt1->next = NULL;
459+
460+ pthread_mutex_lock(&q->mutex);
461+
462+ if (!q->pkt_list.tail) {
463+ q->pkt_list.head = pkt1;
464+ } else {
465+ q->pkt_list.tail->next = pkt1;
466+ }
467+
468+ q->pkt_list.tail = pkt1;
469+ q->nb_packets++;
470+ q->size += pkt1->pkt.size + sizeof(*pkt1);
471+
472+ pthread_cond_signal(&q->cond);
473+
474+ pthread_mutex_unlock(&q->mutex);
475+ return 0;
476+}
477+
478+int ff_decklink_packet_queue_get(DecklinkPacketQueue *q, AVPacket *pkt, int block)
479+{
480+ int ret;
481+
482+ pthread_mutex_lock(&q->mutex);
483+
484+ for (;; ) {
485+ PacketListEntry *pkt1 = q->pkt_list.head;
486+ if (pkt1) {
487+ q->pkt_list.head = pkt1->next;
488+ if (!q->pkt_list.head) {
489+ q->pkt_list.tail = NULL;
490+ }
491+ q->nb_packets--;
492+ q->size -= pkt1->pkt.size + sizeof(*pkt1);
493+ *pkt = pkt1->pkt;
494+ av_free(pkt1);
495+ ret = 1;
496+ break;
497+ } else if (!block) {
498+ ret = 0;
499+ break;
500+ } else {
501+ pthread_cond_wait(&q->cond, &q->mutex);
502+ }
503+ }
504+ pthread_mutex_unlock(&q->mutex);
505+ return ret;
506+}
507+
393508 int ff_decklink_list_devices(AVFormatContext *avctx,
394509 struct AVDeviceInfoList *device_list,
395510 int show_inputs, int show_outputs)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t