diff mbox series

[FFmpeg-devel,2/3] avcodec/h264_redundant_pps_bsf: Support multiple input PPS

Message ID AM7PR03MB6660670B070597D96C364D018F679@AM7PR03MB6660.eurprd03.prod.outlook.com
State Accepted
Commit 5892a55d55dcb17702eff35717ca7cafcd4dc658
Headers show
Series [FFmpeg-devel,1/3] avcodec/h264_redundant_pps_bsf: Remove flush callback | expand


Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Andreas Rheinhardt Nov. 30, 2021, 6:29 p.m. UTC
Up until now, the h264_redundant_pps_bsf stored the initial value
of pic_init_qp_minus26 of the most recently encountered PPS;
it also modified the slices based upon to assumption that
the most recent PPS is the PPS the slice belongs to.
Yet this assumption is flawed, as there can be several PPS
with different IDs that are visible at any given time.
If these have different pic_init_qp_minus26 values,
the output can be invalid.

Fix this by directly using the pic_init_qp_minus26 value of
the input PPS.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This BSF is of course still dangerous as long as it deletes certain
PPS without checking whether it is really redundant.

 libavcodec/h264_redundant_pps_bsf.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
diff mbox series


diff --git a/libavcodec/h264_redundant_pps_bsf.c b/libavcodec/h264_redundant_pps_bsf.c
index 4b2831fb04..5efcf5ea5d 100644
--- a/libavcodec/h264_redundant_pps_bsf.c
+++ b/libavcodec/h264_redundant_pps_bsf.c
@@ -32,7 +32,6 @@  typedef struct H264RedundantPPSContext {
     CBSBSFContext common;
     int global_pic_init_qp;
-    int current_pic_init_qp;
 } H264RedundantPPSContext;
@@ -50,9 +49,7 @@  static int h264_redundant_pps_fixup_pps(H264RedundantPPSContext *ctx,
         return err;
     pps = unit->content;
-    // Record the current value of pic_init_qp in order to fix up
-    // following slices, then overwrite with the global value.
-    ctx->current_pic_init_qp = pps->pic_init_qp_minus26 + 26;
+    // Overwrite pic_init_qp with the global value.
     pps->pic_init_qp_minus26 = ctx->global_pic_init_qp - 26;
     // Some PPSs have this set, so it must be set in all of them.
@@ -66,10 +63,13 @@  static int h264_redundant_pps_fixup_pps(H264RedundantPPSContext *ctx,
 static int h264_redundant_pps_fixup_slice(H264RedundantPPSContext *ctx,
                                           H264RawSliceHeader *slice)
-    int qp;
+    const CodedBitstreamH264Context *const in = ctx->common.input->priv_data;
+    const H264RawPPS *const pps = in->pps[slice->pic_parameter_set_id];
-    qp = ctx->current_pic_init_qp + slice->slice_qp_delta;
-    slice->slice_qp_delta = qp - ctx->global_pic_init_qp;
+    // We modified the PPS's qp value, now offset this by applying
+    // the negative offset to the slices.
+    slice->slice_qp_delta += pps->pic_init_qp_minus26
+                             - (ctx->global_pic_init_qp - 26);
     return 0;