[PATCH 1/2] avdevice/decklink_dec: do not copy video data
Create a buffer from the data instead and use the buffer destructor to free the DeckLink frame. This avoids a memcpy of the frame data. Signed-off-by: Marton Balint <cus@passwd.hu> --- libavdevice/decklink_dec.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libavdevice/decklink_dec.cpp b/libavdevice/decklink_dec.cpp index e97a4402ea..10535dc388 100644 --- a/libavdevice/decklink_dec.cpp +++ b/libavdevice/decklink_dec.cpp @@ -98,6 +98,14 @@ static VANCLineNumber vanc_line_numbers[] = { {bmdModeUnknown, 0, -1, -1, -1} }; +extern "C" { +static void decklink_object_free(void *opaque, uint8_t *data) +{ + IUnknown *obj = (class IUnknown *)opaque; + obj->Release(); +} +} + static int get_vanc_line_idx(BMDDisplayMode mode) { unsigned int i; @@ -797,6 +805,10 @@ HRESULT decklink_input_callback::VideoInputFrameArrived( } } + pkt.buf = av_buffer_create(pkt.data, pkt.size, decklink_object_free, videoFrame, 0); + if (pkt.buf) + videoFrame->AddRef(); + if (avpacket_queue_put(&ctx->queue, &pkt) < 0) { ++ctx->dropped; } -- 2.13.6
Signed-off-by: Marton Balint <cus@passwd.hu> --- libavdevice/decklink_dec.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libavdevice/decklink_dec.cpp b/libavdevice/decklink_dec.cpp index 10535dc388..510637676c 100644 --- a/libavdevice/decklink_dec.cpp +++ b/libavdevice/decklink_dec.cpp @@ -475,16 +475,19 @@ static int avpacket_queue_put(AVPacketQueue *q, AVPacket *pkt) // 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 = (AVPacketList *)av_malloc(sizeof(AVPacketList)); if (!pkt1) { + av_packet_unref(pkt); return -1; } av_packet_move_ref(&pkt1->pkt, pkt); -- 2.13.6
On 4/22/2018 6:18 PM, Marton Balint wrote:
Signed-off-by: Marton Balint <cus@passwd.hu> --- libavdevice/decklink_dec.cpp | 3 +++ 1 file changed, 3 insertions(+)
diff --git a/libavdevice/decklink_dec.cpp b/libavdevice/decklink_dec.cpp index 10535dc388..510637676c 100644 --- a/libavdevice/decklink_dec.cpp +++ b/libavdevice/decklink_dec.cpp @@ -475,16 +475,19 @@ static int avpacket_queue_put(AVPacketQueue *q, AVPacket *pkt)
// 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 = (AVPacketList *)av_malloc(sizeof(AVPacketList)); if (!pkt1) { + av_packet_unref(pkt); return -1; } av_packet_move_ref(&pkt1->pkt, pkt);
This should be backported. Strictly speaking the last unref(), since pkt will always be reference counted at this point even before patch 1/2 of this series because of the make_refcounted() call above.
On Mon, 30 Apr 2018, James Almer wrote:
On 4/22/2018 6:18 PM, Marton Balint wrote:
Signed-off-by: Marton Balint <cus@passwd.hu> --- libavdevice/decklink_dec.cpp | 3 +++ 1 file changed, 3 insertions(+)
diff --git a/libavdevice/decklink_dec.cpp b/libavdevice/decklink_dec.cpp index 10535dc388..510637676c 100644 --- a/libavdevice/decklink_dec.cpp +++ b/libavdevice/decklink_dec.cpp @@ -475,16 +475,19 @@ static int avpacket_queue_put(AVPacketQueue *q, AVPacket *pkt)
// 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 = (AVPacketList *)av_malloc(sizeof(AVPacketList)); if (!pkt1) { + av_packet_unref(pkt); return -1; } av_packet_move_ref(&pkt1->pkt, pkt);
This should be backported. Strictly speaking the last unref(), since pkt will always be reference counted at this point even before patch 1/2 of this series because of the make_refcounted() call above.
Indeed, backported. Thanks, Marton
On Sun, 22 Apr 2018, Marton Balint wrote:
Create a buffer from the data instead and use the buffer destructor to free the DeckLink frame. This avoids a memcpy of the frame data.
Signed-off-by: Marton Balint <cus@passwd.hu> --- libavdevice/decklink_dec.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+)
Pushed the series. Regards, Marton
participants (2)
-
James Almer -
Marton Balint