]> git.sesse.net Git - ffmpeg/commitdiff
decode: add a mechanism for performing delayed processing on the decoded frames
authorAnton Khirnov <anton@khirnov.net>
Fri, 10 Nov 2017 15:07:44 +0000 (16:07 +0100)
committerTimo Rothenpieler <timo@rothenpieler.org>
Fri, 10 Nov 2017 18:48:05 +0000 (19:48 +0100)
This will be useful in the CUVID hwaccel.

Merges Libav commit badf0951f54c1332e77455dc40398f3512540c1b.

libavcodec/decode.c
libavcodec/decode.h

index 0f215d691552687c2a13b289d8cabf77fc937d66..8b03f61a22b5a27425c6d4111b00b2ec78e9894a 100644 (file)
@@ -620,6 +620,18 @@ static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
         av_assert0((frame->private_ref && frame->private_ref->size == sizeof(FrameDecodeData)) ||
                    !(avctx->codec->capabilities & AV_CODEC_CAP_DR1));
 
+        if (frame->private_ref) {
+            FrameDecodeData *fdd = (FrameDecodeData*)frame->private_ref->data;
+
+            if (fdd->post_process) {
+                ret = fdd->post_process(avctx, frame);
+                if (ret < 0) {
+                    av_frame_unref(frame);
+                    return ret;
+                }
+            }
+        }
+
         av_buffer_unref(&frame->private_ref);
     }
 
@@ -1566,6 +1578,9 @@ static void decode_data_free(void *opaque, uint8_t *data)
 {
     FrameDecodeData *fdd = (FrameDecodeData*)data;
 
+    if (fdd->post_process_opaque_free)
+        fdd->post_process_opaque_free(fdd->post_process_opaque);
+
     av_freep(&fdd);
 }
 
index 519f875c985d3380b526a680293b786922e0b9e9..51947b9ec08ca986396175f5ed06df73867dcf7f 100644 (file)
@@ -22,6 +22,7 @@
 #define AVCODEC_DECODE_H
 
 #include "libavutil/buffer.h"
+#include "libavutil/frame.h"
 
 #include "avcodec.h"
 
  * private_ref.
  */
 typedef struct FrameDecodeData {
+    /**
+     * 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;
 
 /**