[FFmpeg-devel,3/6] avcodec: Add ff_setup_buffered_frame_for_return()

Submitted by Michael Niedermayer on Aug. 24, 2019, 6:18 p.m.

Details

Message ID 20190824181829.25724-3-michael@niedermayer.cc
State New
Headers show

Commit Message

Michael Niedermayer Aug. 24, 2019, 6:18 p.m.
Suggested-by: James Almer <jamrial@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavcodec/decode.c   | 17 +++++++++++++++++
 libavcodec/internal.h |  5 +++++
 2 files changed, 22 insertions(+)

Patch hide | download patch | download mbox

diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 5976da78c8..72482e2168 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -2015,6 +2015,23 @@  int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame)
     return ret;
 }
 
+int ff_setup_buffered_frame_for_return(AVCodecContext *avctx, AVFrame *out, AVFrame *frame, AVPacket *pkt)
+{
+    int ret;
+
+    if ((ret = ff_reget_buffer(avctx, frame)) < 0)
+        return ret;
+    frame->pkt_pos      = pkt->pos;
+    frame->pkt_duration = pkt->duration;
+    frame->pkt_dts      = pkt->dts;
+    frame->pkt_pts      =
+    frame->pts          = pkt->pts;
+    if ((ret = av_frame_ref(out, frame)) < 0)
+        return ret;
+
+    return 0;
+}
+
 static void bsfs_flush(AVCodecContext *avctx)
 {
     DecodeFilterContext *s = &avctx->internal->filter;
diff --git a/libavcodec/internal.h b/libavcodec/internal.h
index f9e87eacc6..15ef0bbefc 100644
--- a/libavcodec/internal.h
+++ b/libavcodec/internal.h
@@ -337,6 +337,11 @@  int ff_thread_can_start_frame(AVCodecContext *avctx);
 
 int avpriv_h264_has_num_reorder_frames(AVCodecContext *avctx);
 
+/**
+ * sets up frame to be returned based on fields from pkt.
+ */
+int ff_setup_buffered_frame_for_return(AVCodecContext *avctx, AVFrame *out, AVFrame *frame, AVPacket *pkt);
+
 /**
  * Call avcodec_open2 recursively by decrementing counter, unlocking mutex,
  * calling the function and then restoring again. Assumes the mutex is