[FFmpeg-devel] [PATCH 1/3] avcodec/decklink_dec: use av_packet_from_data() to create packets from an already allocated buffer

James Almer jamrial at gmail.com
Mon Oct 2 05:51:50 EEST 2017


As a side effect, the packets will now be refcounted.

Signed-off-by: James Almer <jamrial at gmail.com>
---
Untested

 libavdevice/decklink_dec.cpp | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/libavdevice/decklink_dec.cpp b/libavdevice/decklink_dec.cpp
index 8a14094474..b0c2fb8791 100644
--- a/libavdevice/decklink_dec.cpp
+++ b/libavdevice/decklink_dec.cpp
@@ -689,7 +689,6 @@ HRESULT decklink_input_callback::VideoInputFrameArrived(
         //To be made sure it still applies
         pkt.flags       |= AV_PKT_FLAG_KEY;
         pkt.stream_index = ctx->video_st->index;
-        pkt.data         = (uint8_t *)frameBytes;
         pkt.size         = videoFrame->GetRowBytes() *
                            videoFrame->GetHeight();
         //fprintf(stderr,"Video Frame size %d ts %d\n", pkt.size, pkt.pts);
@@ -749,16 +748,16 @@ HRESULT decklink_input_callback::VideoInputFrameArrived(
                     txt_pkt.pts = pkt.pts;
                     txt_pkt.dts = pkt.dts;
                     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 (av_packet_from_data(&txt_pkt, txt_buf0, txt_buf - txt_buf0) < 0 ||
+                        avpacket_queue_put(&ctx->queue, &txt_pkt) < 0) {
                         ++ctx->dropped;
                     }
                 }
             }
         }
 
-        if (avpacket_queue_put(&ctx->queue, &pkt) < 0) {
+        if (av_packet_from_data(&pkt, (uint8_t *)frameBytes, pkt.size) < 0 ||
+            avpacket_queue_put(&ctx->queue, &pkt) < 0) {
             ++ctx->dropped;
         }
     }
@@ -779,9 +778,9 @@ HRESULT decklink_input_callback::VideoInputFrameArrived(
         //fprintf(stderr,"Audio Frame size %d ts %d\n", pkt.size, pkt.pts);
         pkt.flags       |= AV_PKT_FLAG_KEY;
         pkt.stream_index = ctx->audio_st->index;
-        pkt.data         = (uint8_t *)audioFrameBytes;
 
-        if (avpacket_queue_put(&ctx->queue, &pkt) < 0) {
+        if (av_packet_from_data(&pkt, (uint8_t *)audioFrameBytes, pkt.size) < 0 ||
+            avpacket_queue_put(&ctx->queue, &pkt) < 0) {
             ++ctx->dropped;
         }
     }
-- 
2.14.1



More information about the ffmpeg-devel mailing list