diff mbox

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

Message ID 20171002025152.5648-1-jamrial@gmail.com
State Withdrawn
Headers show

Commit Message

James Almer Oct. 2, 2017, 2:51 a.m. UTC
As a side effect, the packets will now be refcounted.

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

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

Comments

James Almer Oct. 2, 2017, 4:19 p.m. UTC | #1
On 10/1/2017 11:51 PM, James Almer wrote:
> As a side effect, the packets will now be refcounted.
> 
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
> Untested

Actually, i think this is wrong. Will send a (hopefully) working and
simpler version in a bit.
diff mbox

Patch

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;
         }
     }