* [FFmpeg-devel] [PATCH v2 0/4] Implement SMPTE 2038 output support over Decklink SDI
@ 2023-04-28 18:40 Devin Heitmueller
2023-04-28 18:40 ` [FFmpeg-devel] [PATCH v2 1/4] decklink: Move AVPacketQueue into decklink_common Devin Heitmueller
` (4 more replies)
0 siblings, 5 replies; 12+ messages in thread
From: Devin Heitmueller @ 2023-04-28 18:40 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Devin Heitmueller
This patch series implements output of SMPTE 2038 VANC over SDI, building
on the prior patch series which added it in the TS domain. Note that
we moved the AVPacketQueue to be common code within libavdevice so it
can be shared by both the decklink input and output.
This latest revision of the patch series includes some refactoring
for the decklink queue requested by Marton Balint.
Devin
Devin Heitmueller (4):
decklink: Move AVPacketQueue into decklink_common
decklink: rename AVPacketQueue to DecklinkPacketQueue
decklink: Convert to using avpriv_packet_list functions
decklink_enc: add support for SMPTE 2038 VANC packet output
libavdevice/decklink_common.cpp | 110 ++++++++++++++++++++++++++++++++++
libavdevice/decklink_common.h | 17 +++++-
libavdevice/decklink_dec.cpp | 130 +++-------------------------------------
libavdevice/decklink_enc.cpp | 99 +++++++++++++++++++++++++++++-
libavdevice/decklink_enc_c.c | 1 +
5 files changed, 231 insertions(+), 126 deletions(-)
--
1.8.3.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 12+ messages in thread
* [FFmpeg-devel] [PATCH v2 1/4] decklink: Move AVPacketQueue into decklink_common
2023-04-28 18:40 [FFmpeg-devel] [PATCH v2 0/4] Implement SMPTE 2038 output support over Decklink SDI Devin Heitmueller
@ 2023-04-28 18:40 ` Devin Heitmueller
2023-04-28 18:40 ` [FFmpeg-devel] [PATCH v2 2/4] decklink: rename AVPacketQueue to DecklinkPacketQueue Devin Heitmueller
` (3 subsequent siblings)
4 siblings, 0 replies; 12+ messages in thread
From: Devin Heitmueller @ 2023-04-28 18:40 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Devin Heitmueller
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).
Signed-off-by: Devin Heitmueller <dheitmueller@ltnglobal.com>
---
libavdevice/decklink_common.cpp | 115 ++++++++++++++++++++++++++++++++++++++++
libavdevice/decklink_common.h | 7 +++
libavdevice/decklink_dec.cpp | 114 ---------------------------------------
3 files changed, 122 insertions(+), 114 deletions(-)
diff --git a/libavdevice/decklink_common.cpp b/libavdevice/decklink_common.cpp
index acd1f77..31ab249 100644
--- a/libavdevice/decklink_common.cpp
+++ b/libavdevice/decklink_common.cpp
@@ -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 avpacket_queue_init(AVFormatContext *avctx, AVPacketQueue *q)
+{
+ struct decklink_cctx *ctx = (struct decklink_cctx *)avctx->priv_data;
+ memset(q, 0, sizeof(AVPacketQueue));
+ pthread_mutex_init(&q->mutex, NULL);
+ pthread_cond_init(&q->cond, NULL);
+ q->avctx = avctx;
+ q->max_q_size = ctx->queue_size;
+}
+
+void avpacket_queue_flush(AVPacketQueue *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 avpacket_queue_end(AVPacketQueue *q)
+{
+ avpacket_queue_flush(q);
+ pthread_mutex_destroy(&q->mutex);
+ pthread_cond_destroy(&q->cond);
+}
+
+unsigned long long avpacket_queue_size(AVPacketQueue *q)
+{
+ unsigned long long size;
+ pthread_mutex_lock(&q->mutex);
+ size = q->size;
+ pthread_mutex_unlock(&q->mutex);
+ return size;
+}
+
+int avpacket_queue_put(AVPacketQueue *q, AVPacket *pkt)
+{
+ PacketListEntry *pkt1;
+
+ // Drop Packet if queue size is > maximum queue size
+ if (avpacket_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 avpacket_queue_get(AVPacketQueue *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)
diff --git a/libavdevice/decklink_common.h b/libavdevice/decklink_common.h
index 0d33f94..56cc759 100644
--- a/libavdevice/decklink_common.h
+++ b/libavdevice/decklink_common.h
@@ -235,4 +235,11 @@ int ff_decklink_list_formats(AVFormatContext *avctx, decklink_direction_t direct
void ff_decklink_cleanup(AVFormatContext *avctx);
int ff_decklink_init_device(AVFormatContext *avctx, const char* name);
+void avpacket_queue_init(AVFormatContext *avctx, AVPacketQueue *q);
+void avpacket_queue_flush(AVPacketQueue *q);
+void avpacket_queue_end(AVPacketQueue *q);
+unsigned long long avpacket_queue_size(AVPacketQueue *q);
+int avpacket_queue_put(AVPacketQueue *q, AVPacket *pkt);
+int avpacket_queue_get(AVPacketQueue *q, AVPacket *pkt, int block);
+
#endif /* AVDEVICE_DECKLINK_COMMON_H */
diff --git a/libavdevice/decklink_dec.cpp b/libavdevice/decklink_dec.cpp
index 7bf5e37..b3ff2b0 100644
--- a/libavdevice/decklink_dec.cpp
+++ b/libavdevice/decklink_dec.cpp
@@ -471,120 +471,6 @@ skip_packet:
return tgt;
}
-static void avpacket_queue_init(AVFormatContext *avctx, AVPacketQueue *q)
-{
- struct decklink_cctx *ctx = (struct decklink_cctx *)avctx->priv_data;
- memset(q, 0, sizeof(AVPacketQueue));
- pthread_mutex_init(&q->mutex, NULL);
- pthread_cond_init(&q->cond, NULL);
- q->avctx = avctx;
- q->max_q_size = ctx->queue_size;
-}
-
-static void avpacket_queue_flush(AVPacketQueue *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);
-}
-
-static void avpacket_queue_end(AVPacketQueue *q)
-{
- avpacket_queue_flush(q);
- pthread_mutex_destroy(&q->mutex);
- pthread_cond_destroy(&q->cond);
-}
-
-static unsigned long long avpacket_queue_size(AVPacketQueue *q)
-{
- unsigned long long size;
- pthread_mutex_lock(&q->mutex);
- size = q->size;
- pthread_mutex_unlock(&q->mutex);
- return size;
-}
-
-static int avpacket_queue_put(AVPacketQueue *q, AVPacket *pkt)
-{
- PacketListEntry *pkt1;
-
- // Drop Packet if queue size is > maximum queue size
- if (avpacket_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;
-}
-
-static int avpacket_queue_get(AVPacketQueue *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;
-}
static void handle_klv(AVFormatContext *avctx, decklink_ctx *ctx, IDeckLinkVideoInputFrame *videoFrame, int64_t pts)
{
--
1.8.3.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 12+ messages in thread
* [FFmpeg-devel] [PATCH v2 2/4] decklink: rename AVPacketQueue to DecklinkPacketQueue
2023-04-28 18:40 [FFmpeg-devel] [PATCH v2 0/4] Implement SMPTE 2038 output support over Decklink SDI Devin Heitmueller
2023-04-28 18:40 ` [FFmpeg-devel] [PATCH v2 1/4] decklink: Move AVPacketQueue into decklink_common Devin Heitmueller
@ 2023-04-28 18:40 ` Devin Heitmueller
2023-04-28 18:40 ` [FFmpeg-devel] [PATCH v2 3/4] decklink: Convert to using avpriv_packet_list functions Devin Heitmueller
` (2 subsequent siblings)
4 siblings, 0 replies; 12+ messages in thread
From: Devin Heitmueller @ 2023-04-28 18:40 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Devin Heitmueller
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>
---
libavdevice/decklink_common.cpp | 18 +++++++++---------
libavdevice/decklink_common.h | 18 +++++++++---------
libavdevice/decklink_dec.cpp | 16 ++++++++--------
3 files changed, 26 insertions(+), 26 deletions(-)
diff --git a/libavdevice/decklink_common.cpp b/libavdevice/decklink_common.cpp
index 31ab249..74e26e9 100644
--- a/libavdevice/decklink_common.cpp
+++ b/libavdevice/decklink_common.cpp
@@ -390,17 +390,17 @@ 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 avpacket_queue_init(AVFormatContext *avctx, AVPacketQueue *q)
+void ff_decklink_packet_queue_init(AVFormatContext *avctx, DecklinkPacketQueue *q)
{
struct decklink_cctx *ctx = (struct decklink_cctx *)avctx->priv_data;
- memset(q, 0, sizeof(AVPacketQueue));
+ 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 avpacket_queue_flush(AVPacketQueue *q)
+void ff_decklink_packet_queue_flush(DecklinkPacketQueue *q)
{
PacketListEntry *pkt, *pkt1;
@@ -417,14 +417,14 @@ void avpacket_queue_flush(AVPacketQueue *q)
pthread_mutex_unlock(&q->mutex);
}
-void avpacket_queue_end(AVPacketQueue *q)
+void ff_decklink_packet_queue_end(DecklinkPacketQueue *q)
{
- avpacket_queue_flush(q);
+ ff_decklink_packet_queue_flush(q);
pthread_mutex_destroy(&q->mutex);
pthread_cond_destroy(&q->cond);
}
-unsigned long long avpacket_queue_size(AVPacketQueue *q)
+unsigned long long ff_decklink_packet_queue_size(DecklinkPacketQueue *q)
{
unsigned long long size;
pthread_mutex_lock(&q->mutex);
@@ -433,12 +433,12 @@ unsigned long long avpacket_queue_size(AVPacketQueue *q)
return size;
}
-int avpacket_queue_put(AVPacketQueue *q, AVPacket *pkt)
+int ff_decklink_packet_queue_put(DecklinkPacketQueue *q, AVPacket *pkt)
{
PacketListEntry *pkt1;
// Drop Packet if queue size is > maximum queue size
- if (avpacket_queue_size(q) > (uint64_t)q->max_q_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;
@@ -475,7 +475,7 @@ int avpacket_queue_put(AVPacketQueue *q, AVPacket *pkt)
return 0;
}
-int avpacket_queue_get(AVPacketQueue *q, AVPacket *pkt, int block)
+int ff_decklink_packet_queue_get(DecklinkPacketQueue *q, AVPacket *pkt, int block)
{
int ret;
diff --git a/libavdevice/decklink_common.h b/libavdevice/decklink_common.h
index 56cc759..1cc6d9c 100644
--- a/libavdevice/decklink_common.h
+++ b/libavdevice/decklink_common.h
@@ -78,7 +78,7 @@ static char *dup_cfstring_to_utf8(CFStringRef w)
class decklink_output_callback;
class decklink_input_callback;
-typedef struct AVPacketQueue {
+typedef struct DecklinkPacketQueue {
PacketList pkt_list;
int nb_packets;
unsigned long long size;
@@ -87,7 +87,7 @@ typedef struct AVPacketQueue {
pthread_cond_t cond;
AVFormatContext *avctx;
int64_t max_q_size;
-} AVPacketQueue;
+} DecklinkPacketQueue;
struct decklink_ctx {
/* DeckLink SDK interfaces */
@@ -111,7 +111,7 @@ struct decklink_ctx {
int supports_vanc;
/* Capture buffer queue */
- AVPacketQueue queue;
+ DecklinkPacketQueue queue;
AVCCFifo *cc_fifo; ///< closed captions
@@ -235,11 +235,11 @@ int ff_decklink_list_formats(AVFormatContext *avctx, decklink_direction_t direct
void ff_decklink_cleanup(AVFormatContext *avctx);
int ff_decklink_init_device(AVFormatContext *avctx, const char* name);
-void avpacket_queue_init(AVFormatContext *avctx, AVPacketQueue *q);
-void avpacket_queue_flush(AVPacketQueue *q);
-void avpacket_queue_end(AVPacketQueue *q);
-unsigned long long avpacket_queue_size(AVPacketQueue *q);
-int avpacket_queue_put(AVPacketQueue *q, AVPacket *pkt);
-int avpacket_queue_get(AVPacketQueue *q, AVPacket *pkt, int block);
+void ff_decklink_packet_queue_init(AVFormatContext *avctx, DecklinkPacketQueue *q);
+void ff_decklink_packet_queue_flush(DecklinkPacketQueue *q);
+void ff_decklink_packet_queue_end(DecklinkPacketQueue *q);
+unsigned long long ff_decklink_packet_queue_size(DecklinkPacketQueue *q);
+int ff_decklink_packet_queue_put(DecklinkPacketQueue *q, AVPacket *pkt);
+int ff_decklink_packet_queue_get(DecklinkPacketQueue *q, AVPacket *pkt, int block);
#endif /* AVDEVICE_DECKLINK_COMMON_H */
diff --git a/libavdevice/decklink_dec.cpp b/libavdevice/decklink_dec.cpp
index b3ff2b0..66abee1 100644
--- a/libavdevice/decklink_dec.cpp
+++ b/libavdevice/decklink_dec.cpp
@@ -568,7 +568,7 @@ static void handle_klv(AVFormatContext *avctx, decklink_ctx *ctx, IDeckLinkVideo
klv_packet.data = klv.data();
klv_packet.size = klv.size();
- if (avpacket_queue_put(&ctx->queue, &klv_packet) < 0) {
+ if (ff_decklink_packet_queue_put(&ctx->queue, &klv_packet) < 0) {
++ctx->dropped;
}
}
@@ -760,7 +760,7 @@ HRESULT decklink_input_callback::VideoInputFrameArrived(
if (videoFrame) {
AVPacket pkt = { 0 };
if (ctx->frameCount % 25 == 0) {
- unsigned long long qsize = avpacket_queue_size(&ctx->queue);
+ unsigned long long qsize = ff_decklink_packet_queue_size(&ctx->queue);
av_log(avctx, AV_LOG_DEBUG,
"Frame received (#%lu) - Valid (%liB) - QSize %fMB\n",
ctx->frameCount,
@@ -924,7 +924,7 @@ HRESULT decklink_input_callback::VideoInputFrameArrived(
txt_pkt.stream_index = ctx->teletext_st->index;
txt_pkt.data = txt_buf0;
txt_pkt.size = txt_buf - txt_buf0;
- if (avpacket_queue_put(&ctx->queue, &txt_pkt) < 0) {
+ if (ff_decklink_packet_queue_put(&ctx->queue, &txt_pkt) < 0) {
++ctx->dropped;
}
}
@@ -935,7 +935,7 @@ HRESULT decklink_input_callback::VideoInputFrameArrived(
if (pkt.buf)
videoFrame->AddRef();
- if (avpacket_queue_put(&ctx->queue, &pkt) < 0) {
+ if (ff_decklink_packet_queue_put(&ctx->queue, &pkt) < 0) {
++ctx->dropped;
}
}
@@ -957,7 +957,7 @@ HRESULT decklink_input_callback::VideoInputFrameArrived(
pkt.stream_index = ctx->audio_st->index;
pkt.data = (uint8_t *)audioFrameBytes;
- if (avpacket_queue_put(&ctx->queue, &pkt) < 0) {
+ if (ff_decklink_packet_queue_put(&ctx->queue, &pkt) < 0) {
++ctx->dropped;
}
}
@@ -1039,7 +1039,7 @@ av_cold int ff_decklink_read_close(AVFormatContext *avctx)
}
ff_decklink_cleanup(avctx);
- avpacket_queue_end(&ctx->queue);
+ ff_decklink_packet_queue_end(&ctx->queue);
av_freep(&cctx->ctx);
@@ -1297,7 +1297,7 @@ av_cold int ff_decklink_read_header(AVFormatContext *avctx)
goto error;
}
- avpacket_queue_init (avctx, &ctx->queue);
+ ff_decklink_packet_queue_init(avctx, &ctx->queue);
if (ctx->dli->StartStreams() != S_OK) {
av_log(avctx, AV_LOG_ERROR, "Cannot start input stream\n");
@@ -1317,7 +1317,7 @@ int ff_decklink_read_packet(AVFormatContext *avctx, AVPacket *pkt)
struct decklink_cctx *cctx = (struct decklink_cctx *)avctx->priv_data;
struct decklink_ctx *ctx = (struct decklink_ctx *)cctx->ctx;
- avpacket_queue_get(&ctx->queue, pkt, 1);
+ ff_decklink_packet_queue_get(&ctx->queue, pkt, 1);
if (ctx->tc_format && !(av_dict_get(ctx->video_st->metadata, "timecode", NULL, 0))) {
size_t size;
--
1.8.3.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 12+ messages in thread
* [FFmpeg-devel] [PATCH v2 3/4] decklink: Convert to using avpriv_packet_list functions
2023-04-28 18:40 [FFmpeg-devel] [PATCH v2 0/4] Implement SMPTE 2038 output support over Decklink SDI Devin Heitmueller
2023-04-28 18:40 ` [FFmpeg-devel] [PATCH v2 1/4] decklink: Move AVPacketQueue into decklink_common Devin Heitmueller
2023-04-28 18:40 ` [FFmpeg-devel] [PATCH v2 2/4] decklink: rename AVPacketQueue to DecklinkPacketQueue Devin Heitmueller
@ 2023-04-28 18:40 ` Devin Heitmueller
2023-05-11 21:34 ` Marton Balint
2023-04-28 18:40 ` [FFmpeg-devel] [PATCH v2 4/4] decklink_enc: add support for SMPTE 2038 VANC packet output Devin Heitmueller
2023-05-11 14:36 ` [FFmpeg-devel] [PATCH v2 0/4] Implement SMPTE 2038 output support over Decklink SDI Devin Heitmueller
4 siblings, 1 reply; 12+ messages in thread
From: Devin Heitmueller @ 2023-04-28 18:40 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Devin Heitmueller
The existing DecklinkQueue implementation was using the PacketList
structure but wasn't using the standard avpriv_packet_list_get and
avpriv_packet_list_put functions. Convert to using them so we
eliminate the duplicate logic, per Marton Balint's suggestion.
Signed-off-by: Devin Heitmueller <dheitmueller@ltnglobal.com>
---
libavdevice/decklink_common.cpp | 45 +++++++++++------------------------------
1 file changed, 12 insertions(+), 33 deletions(-)
diff --git a/libavdevice/decklink_common.cpp b/libavdevice/decklink_common.cpp
index 74e26e9..af1b731 100644
--- a/libavdevice/decklink_common.cpp
+++ b/libavdevice/decklink_common.cpp
@@ -402,16 +402,12 @@ void ff_decklink_packet_queue_init(AVFormatContext *avctx, DecklinkPacketQueue *
void ff_decklink_packet_queue_flush(DecklinkPacketQueue *q)
{
- PacketListEntry *pkt, *pkt1;
+ AVPacket pkt;
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);
+ while (avpriv_packet_list_get(&q->pkt_list, &pkt) == 0) {
+ av_packet_unref(&pkt);
}
- q->pkt_list.head = NULL;
- q->pkt_list.tail = NULL;
q->nb_packets = 0;
q->size = 0;
pthread_mutex_unlock(&q->mutex);
@@ -435,7 +431,8 @@ unsigned long long ff_decklink_packet_queue_size(DecklinkPacketQueue *q)
int ff_decklink_packet_queue_put(DecklinkPacketQueue *q, AVPacket *pkt)
{
- PacketListEntry *pkt1;
+ size_t pkt_size = pkt->size;
+ int ret;
// Drop Packet if queue size is > maximum queue size
if (ff_decklink_packet_queue_size(q) > (uint64_t)q->max_q_size) {
@@ -449,26 +446,14 @@ int ff_decklink_packet_queue_put(DecklinkPacketQueue *q, AVPacket *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;
+ ret = avpriv_packet_list_put(&q->pkt_list, pkt, NULL, 0);
+ if (ret == 0) {
+ q->nb_packets++;
+ q->size += pkt_size + sizeof(AVPacket);
}
- 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);
@@ -482,16 +467,10 @@ int ff_decklink_packet_queue_get(DecklinkPacketQueue *q, AVPacket *pkt, int bloc
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;
- }
+ ret = avpriv_packet_list_get(&q->pkt_list, pkt);
+ if (ret == 0) {
q->nb_packets--;
- q->size -= pkt1->pkt.size + sizeof(*pkt1);
- *pkt = pkt1->pkt;
- av_free(pkt1);
+ q->size -= pkt->size + sizeof(AVPacket);
ret = 1;
break;
} else if (!block) {
--
1.8.3.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 12+ messages in thread
* [FFmpeg-devel] [PATCH v2 4/4] decklink_enc: add support for SMPTE 2038 VANC packet output
2023-04-28 18:40 [FFmpeg-devel] [PATCH v2 0/4] Implement SMPTE 2038 output support over Decklink SDI Devin Heitmueller
` (2 preceding siblings ...)
2023-04-28 18:40 ` [FFmpeg-devel] [PATCH v2 3/4] decklink: Convert to using avpriv_packet_list functions Devin Heitmueller
@ 2023-04-28 18:40 ` Devin Heitmueller
2023-06-06 18:56 ` Devin Heitmueller
2023-05-11 14:36 ` [FFmpeg-devel] [PATCH v2 0/4] Implement SMPTE 2038 output support over Decklink SDI Devin Heitmueller
4 siblings, 1 reply; 12+ messages in thread
From: Devin Heitmueller @ 2023-04-28 18:40 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Devin Heitmueller
Support decoding and embedding VANC packets delivered via SMPTE 2038
into the SDI output. We leverage an intermediate queue because
data packets are announced separately from video but we need to embed
the data into the video frame when it is output.
Note that this patch has some additional abstraction for data
streams in general as opposed to just SMPTE 2038 packets. This is
because subsequent patches will introduce support for other
data codecs.
Signed-off-by: Devin Heitmueller <dheitmueller@ltnglobal.com>
---
libavdevice/decklink_common.cpp | 16 +++++++
libavdevice/decklink_common.h | 4 ++
libavdevice/decklink_enc.cpp | 99 ++++++++++++++++++++++++++++++++++++++++-
libavdevice/decklink_enc_c.c | 1 +
4 files changed, 119 insertions(+), 1 deletion(-)
diff --git a/libavdevice/decklink_common.cpp b/libavdevice/decklink_common.cpp
index af1b731..427751c 100644
--- a/libavdevice/decklink_common.cpp
+++ b/libavdevice/decklink_common.cpp
@@ -484,6 +484,22 @@ int ff_decklink_packet_queue_get(DecklinkPacketQueue *q, AVPacket *pkt, int bloc
return ret;
}
+int64_t ff_decklink_packet_queue_peekpts(DecklinkPacketQueue *q)
+{
+ PacketListEntry *pkt1;
+ int64_t pts = -1;
+
+ pthread_mutex_lock(&q->mutex);
+ pkt1 = q->pkt_list.head;
+ if (pkt1) {
+ pts = pkt1->pkt.pts;
+ }
+ pthread_mutex_unlock(&q->mutex);
+
+ return pts;
+}
+
+
int ff_decklink_list_devices(AVFormatContext *avctx,
struct AVDeviceInfoList *device_list,
int show_inputs, int show_outputs)
diff --git a/libavdevice/decklink_common.h b/libavdevice/decklink_common.h
index 1cc6d9c..6762607 100644
--- a/libavdevice/decklink_common.h
+++ b/libavdevice/decklink_common.h
@@ -115,6 +115,9 @@ struct decklink_ctx {
AVCCFifo *cc_fifo; ///< closed captions
+ /* Output VANC queue */
+ DecklinkPacketQueue vanc_queue;
+
/* Streams present */
int audio;
int video;
@@ -241,5 +244,6 @@ void ff_decklink_packet_queue_end(DecklinkPacketQueue *q);
unsigned long long ff_decklink_packet_queue_size(DecklinkPacketQueue *q);
int ff_decklink_packet_queue_put(DecklinkPacketQueue *q, AVPacket *pkt);
int ff_decklink_packet_queue_get(DecklinkPacketQueue *q, AVPacket *pkt, int block);
+int64_t ff_decklink_packet_queue_peekpts(DecklinkPacketQueue *q);
#endif /* AVDEVICE_DECKLINK_COMMON_H */
diff --git a/libavdevice/decklink_enc.cpp b/libavdevice/decklink_enc.cpp
index 616e9c7..82e5ed1 100644
--- a/libavdevice/decklink_enc.cpp
+++ b/libavdevice/decklink_enc.cpp
@@ -345,6 +345,25 @@ static int decklink_setup_subtitle(AVFormatContext *avctx, AVStream *st)
return ret;
}
+static int decklink_setup_data(AVFormatContext *avctx, AVStream *st)
+{
+ int ret = -1;
+
+ switch(st->codecpar->codec_id) {
+#if CONFIG_LIBKLVANC
+ case AV_CODEC_ID_SMPTE_2038:
+ /* No specific setup required */
+ ret = 0;
+ break;
+#endif
+ default:
+ av_log(avctx, AV_LOG_ERROR, "Unsupported data codec specified\n");
+ break;
+ }
+
+ return ret;
+}
+
av_cold int ff_decklink_write_trailer(AVFormatContext *avctx)
{
struct decklink_cctx *cctx = (struct decklink_cctx *)avctx->priv_data;
@@ -370,6 +389,7 @@ av_cold int ff_decklink_write_trailer(AVFormatContext *avctx)
#if CONFIG_LIBKLVANC
klvanc_context_destroy(ctx->vanc_ctx);
#endif
+ ff_decklink_packet_queue_end(&ctx->vanc_queue);
ff_ccfifo_freep(&ctx->cc_fifo);
av_freep(&cctx->ctx);
@@ -554,6 +574,58 @@ static int decklink_construct_vanc(AVFormatContext *avctx, struct decklink_ctx *
construct_cc(avctx, ctx, pkt, &vanc_lines);
construct_afd(avctx, ctx, pkt, &vanc_lines, st);
+ /* See if there any pending data packets to process */
+ while (ff_decklink_packet_queue_size(&ctx->vanc_queue) > 0) {
+ AVStream *vanc_st;
+ AVPacket vanc_pkt;
+ int64_t pts;
+
+ pts = ff_decklink_packet_queue_peekpts(&ctx->vanc_queue);
+ if (pts > ctx->last_pts) {
+ /* We haven't gotten to the video frame we are supposed to inject
+ the oldest VANC packet into yet, so leave it on the queue... */
+ break;
+ }
+
+ ret = ff_decklink_packet_queue_get(&ctx->vanc_queue, &vanc_pkt, 1);
+ if (vanc_pkt.pts + 1 < ctx->last_pts) {
+ av_log(avctx, AV_LOG_WARNING, "VANC packet too old, throwing away\n");
+ av_packet_unref(&vanc_pkt);
+ continue;
+ }
+
+ vanc_st = avctx->streams[vanc_pkt.stream_index];
+ if (vanc_st->codecpar->codec_id == AV_CODEC_ID_SMPTE_2038) {
+ struct klvanc_smpte2038_anc_data_packet_s *pkt_2038 = 0;
+
+ klvanc_smpte2038_parse_pes_payload(vanc_pkt.data, vanc_pkt.size, &pkt_2038);
+ if (pkt_2038 == NULL) {
+ av_log(avctx, AV_LOG_ERROR, "failed to decode SMPTE 2038 PES packet");
+ av_packet_unref(&vanc_pkt);
+ continue;
+ }
+ for (int i = 0; i < pkt_2038->lineCount; i++) {
+ struct klvanc_smpte2038_anc_data_line_s *l = &pkt_2038->lines[i];
+ uint16_t *vancWords = NULL;
+ uint16_t vancWordCount;
+
+ if (klvanc_smpte2038_convert_line_to_words(l, &vancWords,
+ &vancWordCount) < 0)
+ break;
+
+ ret = klvanc_line_insert(ctx->vanc_ctx, &vanc_lines, vancWords,
+ vancWordCount, l->line_number, 0);
+ free(vancWords);
+ if (ret != 0) {
+ av_log(avctx, AV_LOG_ERROR, "VANC line insertion failed\n");
+ break;
+ }
+ }
+ klvanc_smpte2038_anc_data_packet_free(pkt_2038);
+ }
+ av_packet_unref(&vanc_pkt);
+ }
+
IDeckLinkVideoFrameAncillary *vanc;
int result = ctx->dlo->CreateAncillaryData(bmdFormat10BitYUV, &vanc);
if (result != S_OK) {
@@ -752,6 +824,23 @@ static int decklink_write_subtitle_packet(AVFormatContext *avctx, AVPacket *pkt)
return 0;
}
+static int decklink_write_data_packet(AVFormatContext *avctx, AVPacket *pkt)
+{
+ struct decklink_cctx *cctx = (struct decklink_cctx *)avctx->priv_data;
+ struct decklink_ctx *ctx = (struct decklink_ctx *)cctx->ctx;
+
+ AVPacket *avpacket = av_packet_clone(pkt);
+ if (!avpacket) {
+ av_log(avctx, AV_LOG_ERROR, "Could not clone data packet.\n");
+ return AVERROR(EIO);
+ }
+ if (ff_decklink_packet_queue_put(&ctx->vanc_queue, avpacket) < 0) {
+ av_log(avctx, AV_LOG_WARNING, "Failed to queue DATA packet\n");
+ }
+
+ return 0;
+}
+
extern "C" {
av_cold int ff_decklink_write_header(AVFormatContext *avctx)
@@ -817,6 +906,9 @@ av_cold int ff_decklink_write_header(AVFormatContext *avctx)
} else if (c->codec_type == AVMEDIA_TYPE_VIDEO) {
if (decklink_setup_video(avctx, st))
goto error;
+ } else if (c->codec_type == AVMEDIA_TYPE_DATA) {
+ if (decklink_setup_data(avctx, st))
+ goto error;
} else if (c->codec_type == AVMEDIA_TYPE_SUBTITLE) {
if (decklink_setup_subtitle(avctx, st))
goto error;
@@ -826,13 +918,16 @@ av_cold int ff_decklink_write_header(AVFormatContext *avctx)
}
}
+ /* Reconfigure the data/subtitle stream clocks to match the video */
for (n = 0; n < avctx->nb_streams; n++) {
AVStream *st = avctx->streams[n];
AVCodecParameters *c = st->codecpar;
- if(c->codec_type == AVMEDIA_TYPE_SUBTITLE)
+ if(c->codec_type == AVMEDIA_TYPE_DATA ||
+ c->codec_type == AVMEDIA_TYPE_SUBTITLE)
avpriv_set_pts_info(st, 64, ctx->bmd_tb_num, ctx->bmd_tb_den);
}
+ ff_decklink_packet_queue_init(avctx, &ctx->vanc_queue);
frame_rate = av_make_q(ctx->bmd_tb_den, ctx->bmd_tb_num);
if (!(ctx->cc_fifo = ff_ccfifo_alloc(&frame_rate, ctx)))
@@ -853,6 +948,8 @@ int ff_decklink_write_packet(AVFormatContext *avctx, AVPacket *pkt)
return decklink_write_video_packet(avctx, pkt);
else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
return decklink_write_audio_packet(avctx, pkt);
+ else if (st->codecpar->codec_type == AVMEDIA_TYPE_DATA)
+ return decklink_write_data_packet(avctx, pkt);
else if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE)
return decklink_write_subtitle_packet(avctx, pkt);
diff --git a/libavdevice/decklink_enc_c.c b/libavdevice/decklink_enc_c.c
index 0a3984b..d593cca 100644
--- a/libavdevice/decklink_enc_c.c
+++ b/libavdevice/decklink_enc_c.c
@@ -32,6 +32,7 @@ static const AVOption options[] = {
{ "list_devices", "use ffmpeg -sinks decklink instead", OFFSET(list_devices), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, ENC | AV_OPT_FLAG_DEPRECATED},
{ "list_formats", "list supported formats" , OFFSET(list_formats), AV_OPT_TYPE_INT , { .i64 = 0 }, 0, 1, ENC },
{ "preroll" , "video preroll in seconds", OFFSET(preroll ), AV_OPT_TYPE_DOUBLE, { .dbl = 0.5 }, 0, 5, ENC },
+ { "queue_size", "output queue buffer size", OFFSET(queue_size ), AV_OPT_TYPE_INT64, { .i64 = (1024 * 1024)}, 0, INT64_MAX, ENC },
#if BLACKMAGIC_DECKLINK_API_VERSION >= 0x0b000000
{ "duplex_mode" , "duplex mode" , OFFSET(duplex_mode ), AV_OPT_TYPE_INT , { .i64 = 0 }, 0, 5, ENC, "duplex_mode"},
#else
--
1.8.3.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2 0/4] Implement SMPTE 2038 output support over Decklink SDI
2023-04-28 18:40 [FFmpeg-devel] [PATCH v2 0/4] Implement SMPTE 2038 output support over Decklink SDI Devin Heitmueller
` (3 preceding siblings ...)
2023-04-28 18:40 ` [FFmpeg-devel] [PATCH v2 4/4] decklink_enc: add support for SMPTE 2038 VANC packet output Devin Heitmueller
@ 2023-05-11 14:36 ` Devin Heitmueller
2023-05-11 21:18 ` Marton Balint
4 siblings, 1 reply; 12+ messages in thread
From: Devin Heitmueller @ 2023-05-11 14:36 UTC (permalink / raw)
To: ffmpeg-devel, Marton Balint; +Cc: Devin Heitmueller
Hi Marton,
On Fri, Apr 28, 2023 at 1:45 PM Devin Heitmueller
<devin.heitmueller@ltnglobal.com> wrote:
>
> This patch series implements output of SMPTE 2038 VANC over SDI, building
> on the prior patch series which added it in the TS domain. Note that
> we moved the AVPacketQueue to be common code within libavdevice so it
> can be shared by both the decklink input and output.
>
> This latest revision of the patch series includes some refactoring
> for the decklink queue requested by Marton Balint.
>
> Devin
>
> Devin Heitmueller (4):
> decklink: Move AVPacketQueue into decklink_common
> decklink: rename AVPacketQueue to DecklinkPacketQueue
> decklink: Convert to using avpriv_packet_list functions
> decklink_enc: add support for SMPTE 2038 VANC packet output
>
> libavdevice/decklink_common.cpp | 110 ++++++++++++++++++++++++++++++++++
> libavdevice/decklink_common.h | 17 +++++-
> libavdevice/decklink_dec.cpp | 130 +++-------------------------------------
> libavdevice/decklink_enc.cpp | 99 +++++++++++++++++++++++++++++-
> libavdevice/decklink_enc_c.c | 1 +
> 5 files changed, 231 insertions(+), 126 deletions(-)
Do you have any further comments regarding this patch series? It
includes the renaming changes you specifically requested, so even if
you have some concerns about patch 4/4 could you please merge 1-3 (as
I have other changes pending which can't be submitted until those are
in)?
Regards,
Devin
--
Devin Heitmueller, Senior Software Engineer
LTN Global Communications
o: +1 (301) 363-1001
w: https://ltnglobal.com e: devin.heitmueller@ltnglobal.com
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2 0/4] Implement SMPTE 2038 output support over Decklink SDI
2023-05-11 14:36 ` [FFmpeg-devel] [PATCH v2 0/4] Implement SMPTE 2038 output support over Decklink SDI Devin Heitmueller
@ 2023-05-11 21:18 ` Marton Balint
2023-05-11 21:26 ` Devin Heitmueller
0 siblings, 1 reply; 12+ messages in thread
From: Marton Balint @ 2023-05-11 21:18 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Thu, 11 May 2023, Devin Heitmueller wrote:
> Hi Marton,
>
> On Fri, Apr 28, 2023 at 1:45 PM Devin Heitmueller
> <devin.heitmueller@ltnglobal.com> wrote:
>>
>> This patch series implements output of SMPTE 2038 VANC over SDI, building
>> on the prior patch series which added it in the TS domain. Note that
>> we moved the AVPacketQueue to be common code within libavdevice so it
>> can be shared by both the decklink input and output.
>>
>> This latest revision of the patch series includes some refactoring
>> for the decklink queue requested by Marton Balint.
>>
>> Devin
>>
>> Devin Heitmueller (4):
>> decklink: Move AVPacketQueue into decklink_common
>> decklink: rename AVPacketQueue to DecklinkPacketQueue
>> decklink: Convert to using avpriv_packet_list functions
>> decklink_enc: add support for SMPTE 2038 VANC packet output
>>
>> libavdevice/decklink_common.cpp | 110 ++++++++++++++++++++++++++++++++++
>> libavdevice/decklink_common.h | 17 +++++-
>> libavdevice/decklink_dec.cpp | 130 +++-------------------------------------
>> libavdevice/decklink_enc.cpp | 99 +++++++++++++++++++++++++++++-
>> libavdevice/decklink_enc_c.c | 1 +
>> 5 files changed, 231 insertions(+), 126 deletions(-)
>
> Do you have any further comments regarding this patch series? It
> includes the renaming changes you specifically requested, so even if
> you have some concerns about patch 4/4 could you please merge 1-3 (as
> I have other changes pending which can't be submitted until those are
> in)?
Will apply patches 1 and 2. I will squash them as I am not sure if it is
good idea to have av* non-static functions even temporarily.
I will post some comments for patch 3. I will need a bit more time to
think about patch 4. :)
Thanks,
Marton
>
> Regards,
>
> Devin
>
> --
> Devin Heitmueller, Senior Software Engineer
> LTN Global Communications
> o: +1 (301) 363-1001
> w: https://ltnglobal.com e: devin.heitmueller@ltnglobal.com
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2 0/4] Implement SMPTE 2038 output support over Decklink SDI
2023-05-11 21:18 ` Marton Balint
@ 2023-05-11 21:26 ` Devin Heitmueller
0 siblings, 0 replies; 12+ messages in thread
From: Devin Heitmueller @ 2023-05-11 21:26 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Thu, May 11, 2023 at 5:19 PM Marton Balint <cus@passwd.hu> wrote:
> Will apply patches 1 and 2. I will squash them as I am not sure if it is
> good idea to have av* non-static functions even temporarily.
No objection. I did it that way just to make it easier to review.
> I will post some comments for patch 3. I will need a bit more time to
> think about patch 4. :)
Sounds good.
Thanks
Devin
--
Devin Heitmueller, Senior Software Engineer
LTN Global Communications
o: +1 (301) 363-1001
w: https://ltnglobal.com e: devin.heitmueller@ltnglobal.com
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2 3/4] decklink: Convert to using avpriv_packet_list functions
2023-04-28 18:40 ` [FFmpeg-devel] [PATCH v2 3/4] decklink: Convert to using avpriv_packet_list functions Devin Heitmueller
@ 2023-05-11 21:34 ` Marton Balint
0 siblings, 0 replies; 12+ messages in thread
From: Marton Balint @ 2023-05-11 21:34 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Fri, 28 Apr 2023, Devin Heitmueller wrote:
> The existing DecklinkQueue implementation was using the PacketList
> structure but wasn't using the standard avpriv_packet_list_get and
> avpriv_packet_list_put functions. Convert to using them so we
> eliminate the duplicate logic, per Marton Balint's suggestion.
>
> Signed-off-by: Devin Heitmueller <dheitmueller@ltnglobal.com>
> ---
> libavdevice/decklink_common.cpp | 45 +++++++++++------------------------------
> 1 file changed, 12 insertions(+), 33 deletions(-)
>
> diff --git a/libavdevice/decklink_common.cpp b/libavdevice/decklink_common.cpp
> index 74e26e9..af1b731 100644
> --- a/libavdevice/decklink_common.cpp
> +++ b/libavdevice/decklink_common.cpp
> @@ -402,16 +402,12 @@ void ff_decklink_packet_queue_init(AVFormatContext *avctx, DecklinkPacketQueue *
>
> void ff_decklink_packet_queue_flush(DecklinkPacketQueue *q)
> {
> - PacketListEntry *pkt, *pkt1;
> + AVPacket pkt;
>
> 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);
> + while (avpriv_packet_list_get(&q->pkt_list, &pkt) == 0) {
> + av_packet_unref(&pkt);
> }
> - q->pkt_list.head = NULL;
> - q->pkt_list.tail = NULL;
> q->nb_packets = 0;
> q->size = 0;
> pthread_mutex_unlock(&q->mutex);
> @@ -435,7 +431,8 @@ unsigned long long ff_decklink_packet_queue_size(DecklinkPacketQueue *q)
>
> int ff_decklink_packet_queue_put(DecklinkPacketQueue *q, AVPacket *pkt)
> {
> - PacketListEntry *pkt1;
> + size_t pkt_size = pkt->size;
AVPacket->size is int so size_t is a bit strange here.
> + int ret;
>
> // Drop Packet if queue size is > maximum queue size
> if (ff_decklink_packet_queue_size(q) > (uint64_t)q->max_q_size) {
> @@ -449,26 +446,14 @@ int ff_decklink_packet_queue_put(DecklinkPacketQueue *q, AVPacket *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;
> + ret = avpriv_packet_list_put(&q->pkt_list, pkt, NULL, 0);
> + if (ret == 0) {
> + q->nb_packets++;
> + q->size += pkt_size + sizeof(AVPacket);
> }
else av_packet_unref() to not leak packet data in case of failure?
>
> - q->pkt_list.tail = pkt1;
> - q->nb_packets++;
> - q->size += pkt1->pkt.size + sizeof(*pkt1);
> -
> pthread_cond_signal(&q->cond);
Maybe only cond_signal if avpriv_packet_list_put was successful?
>
> pthread_mutex_unlock(&q->mutex);
You have to return the ret code, not 0 in the end of the function in
order to propagate avpriv_packet_list_put failure.
> @@ -482,16 +467,10 @@ int ff_decklink_packet_queue_get(DecklinkPacketQueue *q, AVPacket *pkt, int bloc
> 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;
> - }
> + ret = avpriv_packet_list_get(&q->pkt_list, pkt);
> + if (ret == 0) {
> q->nb_packets--;
> - q->size -= pkt1->pkt.size + sizeof(*pkt1);
> - *pkt = pkt1->pkt;
> - av_free(pkt1);
> + q->size -= pkt->size + sizeof(AVPacket);
> ret = 1;
> break;
> } else if (!block) {
Thanks,
Marton
> --
> 1.8.3.1
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2 4/4] decklink_enc: add support for SMPTE 2038 VANC packet output
2023-04-28 18:40 ` [FFmpeg-devel] [PATCH v2 4/4] decklink_enc: add support for SMPTE 2038 VANC packet output Devin Heitmueller
@ 2023-06-06 18:56 ` Devin Heitmueller
2023-06-22 11:54 ` Devin Heitmueller
0 siblings, 1 reply; 12+ messages in thread
From: Devin Heitmueller @ 2023-06-06 18:56 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Devin Heitmueller
Hello Marton,
On Fri, Apr 28, 2023 at 1:45 PM Devin Heitmueller
<devin.heitmueller@ltnglobal.com> wrote:
>
> Support decoding and embedding VANC packets delivered via SMPTE 2038
> into the SDI output. We leverage an intermediate queue because
> data packets are announced separately from video but we need to embed
> the data into the video frame when it is output.
>
> Note that this patch has some additional abstraction for data
> streams in general as opposed to just SMPTE 2038 packets. This is
> because subsequent patches will introduce support for other
> data codecs.
>
> Signed-off-by: Devin Heitmueller <dheitmueller@ltnglobal.com>
You indicated in patch 0/4 that you had some additional
feedback/comments on this patch series. Could you please provide
them? I've got other data formats I'm working on support for (i.e.
SCTE-104) which depend on the common changes in this patch.
Regards
Devin
--
Devin Heitmueller, Senior Software Engineer
LTN Global Communications
o: +1 (301) 363-1001
w: https://ltnglobal.com e: devin.heitmueller@ltnglobal.com
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2 4/4] decklink_enc: add support for SMPTE 2038 VANC packet output
2023-06-06 18:56 ` Devin Heitmueller
@ 2023-06-22 11:54 ` Devin Heitmueller
2023-06-26 7:07 ` Marton Balint
0 siblings, 1 reply; 12+ messages in thread
From: Devin Heitmueller @ 2023-06-22 11:54 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Devin Heitmueller
On Tue, Jun 6, 2023 at 2:56 PM Devin Heitmueller
<devin.heitmueller@ltnglobal.com> wrote:
> You indicated in patch 0/4 that you had some additional
> feedback/comments on this patch series. Could you please provide
> them? I've got other data formats I'm working on support for (i.e.
> SCTE-104) which depend on the common changes in this patch.
<ping>
--
Devin Heitmueller, Senior Software Engineer
LTN Global Communications
o: +1 (301) 363-1001
w: https://ltnglobal.com e: devin.heitmueller@ltnglobal.com
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2 4/4] decklink_enc: add support for SMPTE 2038 VANC packet output
2023-06-22 11:54 ` Devin Heitmueller
@ 2023-06-26 7:07 ` Marton Balint
0 siblings, 0 replies; 12+ messages in thread
From: Marton Balint @ 2023-06-26 7:07 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Thu, 22 Jun 2023, Devin Heitmueller wrote:
> On Tue, Jun 6, 2023 at 2:56 PM Devin Heitmueller
> <devin.heitmueller@ltnglobal.com> wrote:
>> You indicated in patch 0/4 that you had some additional
>> feedback/comments on this patch series. Could you please provide
>> them? I've got other data formats I'm working on support for (i.e.
>> SCTE-104) which depend on the common changes in this patch.
>
> <ping>
Sorry for the delay. Could you please rebase the patch on current master?
Also two comments:
- I don't think you need av_packet_clone() before putting the packet into
the queue. Yes, audio and video use it, but only because only a single
pointer can be stored in the decklink frame. But the avpacket queue you
are using stores whole packet structs, and the muxer is
allowed to unref the packet it gets in write_packet() as far as I
know.
- Could you use a more specific name for the queue size? Like
"vanc_queue_size", not to be confused with audio/video. And please add
documentation for it in docs/outdev.texi.
Thanks,
Marton
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2023-06-26 7:10 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-28 18:40 [FFmpeg-devel] [PATCH v2 0/4] Implement SMPTE 2038 output support over Decklink SDI Devin Heitmueller
2023-04-28 18:40 ` [FFmpeg-devel] [PATCH v2 1/4] decklink: Move AVPacketQueue into decklink_common Devin Heitmueller
2023-04-28 18:40 ` [FFmpeg-devel] [PATCH v2 2/4] decklink: rename AVPacketQueue to DecklinkPacketQueue Devin Heitmueller
2023-04-28 18:40 ` [FFmpeg-devel] [PATCH v2 3/4] decklink: Convert to using avpriv_packet_list functions Devin Heitmueller
2023-05-11 21:34 ` Marton Balint
2023-04-28 18:40 ` [FFmpeg-devel] [PATCH v2 4/4] decklink_enc: add support for SMPTE 2038 VANC packet output Devin Heitmueller
2023-06-06 18:56 ` Devin Heitmueller
2023-06-22 11:54 ` Devin Heitmueller
2023-06-26 7:07 ` Marton Balint
2023-05-11 14:36 ` [FFmpeg-devel] [PATCH v2 0/4] Implement SMPTE 2038 output support over Decklink SDI Devin Heitmueller
2023-05-11 21:18 ` Marton Balint
2023-05-11 21:26 ` Devin Heitmueller
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git