Skip to content

Commit badf095

Browse files
committed
decode: add a mechanism for performing delayed processing on the decoded frames
This will be useful in the CUVID hwaccel.
1 parent 359a8a3 commit badf095

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

libavcodec/decode.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,14 @@ static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
419419

420420
fdd = (FrameDecodeData*)frame->opaque_ref->data;
421421

422+
if (fdd->post_process) {
423+
ret = fdd->post_process(avctx, frame);
424+
if (ret < 0) {
425+
av_frame_unref(frame);
426+
return ret;
427+
}
428+
}
429+
422430
user_opaque_ref = fdd->user_opaque_ref;
423431
fdd->user_opaque_ref = NULL;
424432
av_buffer_unref(&frame->opaque_ref);
@@ -1014,6 +1022,9 @@ static void decode_data_free(void *opaque, uint8_t *data)
10141022

10151023
av_buffer_unref(&fdd->user_opaque_ref);
10161024

1025+
if (fdd->post_process_opaque_free)
1026+
fdd->post_process_opaque_free(fdd->post_process_opaque);
1027+
10171028
av_freep(&fdd);
10181029
}
10191030

libavcodec/decode.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#define AVCODEC_DECODE_H
2323

2424
#include "libavutil/buffer.h"
25+
#include "libavutil/frame.h"
2526

2627
#include "avcodec.h"
2728

@@ -34,6 +35,20 @@ typedef struct FrameDecodeData {
3435
* The original user-set opaque_ref.
3536
*/
3637
AVBufferRef *user_opaque_ref;
38+
39+
/**
40+
* The callback to perform some delayed processing on the frame right
41+
* before it is returned to the caller.
42+
*
43+
* @note This code is called at some unspecified point after the frame is
44+
* returned from the decoder's decode/receive_frame call. Therefore it cannot rely
45+
* on AVCodecContext being in any specific state, so it does not get to
46+
* access AVCodecContext directly at all. All the state it needs must be
47+
* stored in the post_process_opaque object.
48+
*/
49+
int (*post_process)(void *logctx, AVFrame *frame);
50+
void *post_process_opaque;
51+
void (*post_process_opaque_free)(void *opaque);
3752
} FrameDecodeData;
3853

3954
/**

0 commit comments

Comments
 (0)