[FFmpeg-devel,4/5] decode: add a mechanism for performing delayed processing on the decoded frames

Submitted by wm4 on Oct. 13, 2017, 4:59 p.m.

Details

Message ID 20171013165919.7642-5-nfxjfg@googlemail.com
State New
Headers show

Commit Message

wm4 Oct. 13, 2017, 4:59 p.m.
From: Anton Khirnov <anton@khirnov.net>

This will be useful in the CUVID hwaccel.

Merges Libav commit badf0951f54c1332e77455dc40398f3512540c1b.
---
 libavcodec/decode.c | 11 +++++++++++
 libavcodec/decode.h | 15 +++++++++++++++
 2 files changed, 26 insertions(+)

Patch hide | download patch | download mbox

diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 9395cfc43b..9878950c82 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -653,6 +653,14 @@  static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
 
             fdd = (FrameDecodeData*)frame->opaque_ref->data;
 
+            if (fdd->post_process) {
+                ret = fdd->post_process(avctx, frame);
+                if (ret < 0) {
+                    av_frame_unref(frame);
+                    return ret;
+                }
+            }
+
             user_opaque_ref = fdd->user_opaque_ref;
             fdd->user_opaque_ref = NULL;
             av_buffer_unref(&frame->opaque_ref);
@@ -1638,6 +1646,9 @@  static void decode_data_free(void *opaque, uint8_t *data)
 
     av_buffer_unref(&fdd->user_opaque_ref);
 
+    if (fdd->post_process_opaque_free)
+        fdd->post_process_opaque_free(fdd->post_process_opaque);
+
     av_freep(&fdd);
 }
 
diff --git a/libavcodec/decode.h b/libavcodec/decode.h
index 9326f1d952..dcfc830296 100644
--- a/libavcodec/decode.h
+++ b/libavcodec/decode.h
@@ -22,6 +22,7 @@ 
 #define AVCODEC_DECODE_H
 
 #include "libavutil/buffer.h"
+#include "libavutil/frame.h"
 
 #include "avcodec.h"
 
@@ -34,6 +35,20 @@  typedef struct FrameDecodeData {
      * The original user-set opaque_ref.
      */
     AVBufferRef *user_opaque_ref;
+
+    /**
+     * The callback to perform some delayed processing on the frame right
+     * before it is returned to the caller.
+     *
+     * @note This code is called at some unspecified point after the frame is
+     * returned from the decoder's decode/receive_frame call. Therefore it cannot rely
+     * on AVCodecContext being in any specific state, so it does not get to
+     * access AVCodecContext directly at all. All the state it needs must be
+     * stored in the post_process_opaque object.
+     */
+    int (*post_process)(void *logctx, AVFrame *frame);
+    void *post_process_opaque;
+    void (*post_process_opaque_free)(void *opaque);
 } FrameDecodeData;
 
 /**