codecs: h264: Change the low_latency to an enum for dpb_needs_bump().
authorHe Junyan <junyan.he@intel.com>
Wed, 28 Jul 2021 14:48:21 +0000 (22:48 +0800)
committerVíctor Manuel Jáquez Leal <vjaquez@igalia.com>
Mon, 13 Sep 2021 06:37:28 +0000 (06:37 +0000)
The bool parameter of low_latency is not enough. We have multi policies for
low latency bumping, from the safest to something radical. So we need an enum
to represent the proper latency requirement.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2432>

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

index 544e1d21962e4dd8f0c2e5a14e946fc2df6bbd32..a687e338ec2183e904868afd24ab0ac666d8b74d 100644 (file)
@@ -698,7 +698,7 @@ gst_h264_dpb_get_lowest_output_needed_picture (GstH264Dpb * dpb,
  * gst_h264_dpb_needs_bump:
  * @dpb: a #GstH264Dpb
  * @to_insert: the current #GstH264Picture to insert to dpb.
- * @low_latency: %TRUE if low-latency bumping is required
+ * @latency_mode: The required #GstH264DpbBumpMode for bumping.
  *
  * Returns: %TRUE if bumping is required
  *
@@ -706,7 +706,7 @@ gst_h264_dpb_get_lowest_output_needed_picture (GstH264Dpb * dpb,
  */
 gboolean
 gst_h264_dpb_needs_bump (GstH264Dpb * dpb, GstH264Picture * to_insert,
-    gboolean low_latency)
+    GstH264DpbBumpMode latency_mode)
 {
   GstH264Picture *picture = NULL;
   gint32 lowest_poc;
@@ -727,7 +727,7 @@ gst_h264_dpb_needs_bump (GstH264Dpb * dpb, GstH264Picture * to_insert,
     goto normal_bump;
   }
 
-  if (low_latency) {
+  if (latency_mode >= GST_H264_DPB_BUMP_LOW_LATENCY) {
     /* If low latency, we should not wait for the DPB becoming full.
        We try to bump the picture as soon as possible without the
        frames disorder. The policy is from the safe to some risk. */
@@ -809,22 +809,22 @@ gst_h264_dpb_needs_bump (GstH264Dpb * dpb, GstH264Picture * to_insert,
       return TRUE;
     }
 
-    /* PicOrderCnt increment by <=2. Not all streams meet this, but in
-       practice this condition can be used.
-       For stream with 2 poc increment like:
-       0(IDR), 2(P), 4(P), 6(P), 12(P), 8(B), 10(B)....
-       This can work well, but for streams with 1 poc increment like:
-       0(IDR), 2(P), 4(P), 1(B), 3(B) ...
-       This can cause picture disorder. Most stream in practice has the
-       2 poc increment, but this may have risk and be careful. */
-#if 0
-    if (lowest_poc > dpb->last_output_poc
-        && lowest_poc - dpb->last_output_poc <= 2) {
-      GST_TRACE ("lowest-poc: %d, last-output-poc: %d, bumping for"
-          " low-latency", lowest_poc, dpb->last_output_poc);
-      return TRUE;
+    if (latency_mode >= GST_H264_DPB_BUMP_VERY_LOW_LATENCY) {
+      /* PicOrderCnt increment by <=2. Not all streams meet this, but in
+         practice this condition can be used.
+         For stream with 2 poc increment like:
+         0(IDR), 2(P), 4(P), 6(P), 12(P), 8(B), 10(B)....
+         This can work well, but for streams with 1 poc increment like:
+         0(IDR), 2(P), 4(P), 1(B), 3(B) ...
+         This can cause picture disorder. Most stream in practice has the
+         2 poc increment, but this may have risk and be careful. */
+      if (lowest_poc > dpb->last_output_poc
+          && lowest_poc - dpb->last_output_poc <= 2) {
+        GST_TRACE ("lowest-poc: %d, last-output-poc: %d, diff <= 2, "
+            "bumping for very-low-latency", lowest_poc, dpb->last_output_poc);
+        return TRUE;
+      }
     }
-#endif
   }
 
 normal_bump:
index d0b914f2ce04ff61b6e65d94b15c685d48fd8eb1..a028c00b158713376e2ea8f7e9f443bcba0f3759 100644 (file)
@@ -164,6 +164,21 @@ struct _GstH264Picture
   GDestroyNotify notify;
 };
 
+/**
+ * GstH264DpbBumpMode:
+ * @GST_H264_DPB_BUMP_NORMAL_LATENCY: No latency requirement for DBP bumping.
+ * @GST_H264_DPB_BUMP_LOW_LATENCY: Low-latency requirement for DBP bumping.
+ * @GST_H264_DPB_BUMP_VERY_LOW_LATENCY: Very low-latency requirement for DBP bumping.
+ *
+ * Since: 1.20
+ */
+typedef enum
+{
+  GST_H264_DPB_BUMP_NORMAL_LATENCY,
+  GST_H264_DPB_BUMP_LOW_LATENCY,
+  GST_H264_DPB_BUMP_VERY_LOW_LATENCY
+} GstH264DpbBumpMode;
+
 GST_CODECS_API
 GType gst_h264_picture_get_type (void);
 
@@ -290,7 +305,7 @@ gboolean gst_h264_dpb_has_empty_frame_buffer   (GstH264Dpb * dpb);
 GST_CODECS_API
 gboolean gst_h264_dpb_needs_bump (GstH264Dpb * dpb,
                                   GstH264Picture * to_insert,
-                                  gboolean low_latency);
+                                  GstH264DpbBumpMode latency_mode);
 
 GST_CODECS_API
 GstH264Picture * gst_h264_dpb_bump (GstH264Dpb * dpb,