summaryrefslogtreecommitdiff
path: root/libavcodec/h264dec.h
diff options
context:
space:
mode:
authorNiklas Haas <git@haasn.dev>2021-08-17 21:54:56 +0200
committerJames Almer <jamrial@gmail.com>2021-08-24 09:58:52 -0300
commit66845cffc3bbb17f91294d15cd6f57f3df3bce97 (patch)
tree413847a6a899872e940d88fd1ad1c34e91631794 /libavcodec/h264dec.h
parent6bc29a6b571c83058d04dc7b8b0f827dfee31b2c (diff)
avcodec/h264dec: apply H.274 film grain
Because we need access to ref frames without film grain applied, we have to add an extra AVFrame to H264Picture to avoid messing with the original. This requires some amount of overhead to make the reference moves work out, but it allows us to benefit from frame multithreading for film grain application "for free". Unfortunately, this approach requires twice as much RAM to be constantly allocated for ref frames, due to the need for an extra buffer per H264Picture. In theory, we could get away with freeing up this memory as soon as it's no longer needed (since ref frames do not need film grain buffers any longer), but trying to call ff_thread_release_buffer() from output_frame() conflicts with possible later accesses to that same frame and I'm not sure how to synchronize that well. Tested on all three cases of (no fg), (fg present but exported) and (fg present and not exported), with and without threading. Co-authored-by: James Almer <jamrial@gmail.com> Signed-off-by: Niklas Haas <git@haasn.dev> Signed-off-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'libavcodec/h264dec.h')
-rw-r--r--libavcodec/h264dec.h6
1 files changed, 6 insertions, 0 deletions
diff --git a/libavcodec/h264dec.h b/libavcodec/h264dec.h
index 7c419de051..87c4e4e539 100644
--- a/libavcodec/h264dec.h
+++ b/libavcodec/h264dec.h
@@ -43,6 +43,7 @@
#include "h264dsp.h"
#include "h264pred.h"
#include "h264qpel.h"
+#include "h274.h"
#include "internal.h"
#include "mpegutils.h"
#include "parser.h"
@@ -130,6 +131,9 @@ typedef struct H264Picture {
AVFrame *f;
ThreadFrame tf;
+ AVFrame *f_grain;
+ ThreadFrame tf_grain;
+
AVBufferRef *qscale_table_buf;
int8_t *qscale_table;
@@ -162,6 +166,7 @@ typedef struct H264Picture {
int recovered; ///< picture at IDR or recovery point + recovery count
int invalid_gap;
int sei_recovery_frame_cnt;
+ int needs_fg; ///< whether picture needs film grain synthesis (see `f_grain`)
AVBufferRef *pps_buf;
const PPS *pps;
@@ -349,6 +354,7 @@ typedef struct H264Context {
H264DSPContext h264dsp;
H264ChromaContext h264chroma;
H264QpelContext h264qpel;
+ H274FilmGrainDatabase h274db;
H264Picture DPB[H264_MAX_PICTURE_COUNT];
H264Picture *cur_pic_ptr;