codecs: h264: Fix DPB size calculation
authorNicolas Dufresne <nicolas.dufresne@collabora.com>
Mon, 6 Apr 2020 19:06:01 +0000 (15:06 -0400)
committerGStreamer Merge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Tue, 7 Apr 2020 07:53:27 +0000 (07:53 +0000)
As per specification in A.3.1 h) and A.3.2 f), the maximum size of the DPB is
16. Fix the maximum in the fine and fix the formula to use MIN instead of MAX
so that we no longer always use the maximum for the profile/level.

gst-libs/gst/codecs/gsth264decoder.c
gst-libs/gst/codecs/gsth264picture.h

index 456b8fd..26127f5 100644 (file)
@@ -1684,9 +1684,12 @@ gst_h264_decoder_process_sps (GstH264Decoder * self, GstH264SPS * sps)
   max_dpb_frames = MIN (max_dpb_mbs / (width_mb * height_mb),
       GST_H264_DPB_MAX_SIZE);
 
-  max_dpb_size = MAX (max_dpb_frames,
+  max_dpb_size = MIN (max_dpb_frames,
       MAX (sps->num_ref_frames, sps->vui_parameters.max_dec_frame_buffering));
 
+  /* Safety, so that subclass don't need bound checking */
+  g_return_val_if_fail (max_dpb_size <= GST_H264_DPB_MAX_SIZE, FALSE);
+
   prev_max_dpb_size = gst_h264_dpb_get_max_num_pics (priv->dpb);
   if (priv->width != sps->width || priv->height != sps->height ||
       prev_max_dpb_size != max_dpb_size) {
index 73cad13..44db365 100644 (file)
@@ -34,7 +34,8 @@ G_BEGIN_DECLS
 typedef struct _GstH264Slice GstH264Slice;
 typedef struct _GstH264Picture GstH264Picture;
 
-#define GST_H264_DPB_MAX_SIZE 32
+/* As specified in A.3.1 h) and A.3.2 f) */
+#define GST_H264_DPB_MAX_SIZE 16
 
 struct _GstH264Slice
 {