summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2017-07-01 12:09:58 +0200
committerAnton Khirnov <anton@khirnov.net>2017-07-24 11:45:24 +0200
commit15887857eeda7761fb8086d9e9da9912134502d9 (patch)
treee8f34acba9658e581622780175b36e5bf93f70c4
parent2d7747c706b26567a5dcfc1d9b7a460ea46c4f96 (diff)
decode: add a mechanism for performing delayed processing on the decoded frames
This will be useful in the CUVID hwaccel.
-rw-r--r--libavcodec/decode.c11
-rw-r--r--libavcodec/decode.h15
2 files changed, 26 insertions, 0 deletions
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 9cd3081079..01e4dd260a 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -419,6 +419,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);
@@ -1099,6 +1107,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 61b53b2445..72052f1de5 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;
/**