codecs: h264: Change the low_latency to an enum for dpb_needs_bump().

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>
This commit is contained in:
He Junyan 2021-07-28 22:48:21 +08:00 committed by Víctor Manuel Jáquez Leal
parent 3c975ed918
commit 56269d127f
2 changed files with 34 additions and 19 deletions

View file

@ -698,7 +698,7 @@ gst_h264_dpb_get_lowest_output_needed_picture (GstH264Dpb * dpb,
* gst_h264_dpb_needs_bump: * gst_h264_dpb_needs_bump:
* @dpb: a #GstH264Dpb * @dpb: a #GstH264Dpb
* @to_insert: the current #GstH264Picture to insert to dpb. * @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 * Returns: %TRUE if bumping is required
* *
@ -706,7 +706,7 @@ gst_h264_dpb_get_lowest_output_needed_picture (GstH264Dpb * dpb,
*/ */
gboolean gboolean
gst_h264_dpb_needs_bump (GstH264Dpb * dpb, GstH264Picture * to_insert, gst_h264_dpb_needs_bump (GstH264Dpb * dpb, GstH264Picture * to_insert,
gboolean low_latency) GstH264DpbBumpMode latency_mode)
{ {
GstH264Picture *picture = NULL; GstH264Picture *picture = NULL;
gint32 lowest_poc; gint32 lowest_poc;
@ -727,7 +727,7 @@ gst_h264_dpb_needs_bump (GstH264Dpb * dpb, GstH264Picture * to_insert,
goto normal_bump; 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. /* If low latency, we should not wait for the DPB becoming full.
We try to bump the picture as soon as possible without the We try to bump the picture as soon as possible without the
frames disorder. The policy is from the safe to some risk. */ 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; return TRUE;
} }
/* PicOrderCnt increment by <=2. Not all streams meet this, but in if (latency_mode >= GST_H264_DPB_BUMP_VERY_LOW_LATENCY) {
practice this condition can be used. /* PicOrderCnt increment by <=2. Not all streams meet this, but in
For stream with 2 poc increment like: practice this condition can be used.
0(IDR), 2(P), 4(P), 6(P), 12(P), 8(B), 10(B).... For stream with 2 poc increment like:
This can work well, but for streams with 1 poc increment like: 0(IDR), 2(P), 4(P), 6(P), 12(P), 8(B), 10(B)....
0(IDR), 2(P), 4(P), 1(B), 3(B) ... This can work well, but for streams with 1 poc increment like:
This can cause picture disorder. Most stream in practice has the 0(IDR), 2(P), 4(P), 1(B), 3(B) ...
2 poc increment, but this may have risk and be careful. */ This can cause picture disorder. Most stream in practice has the
#if 0 2 poc increment, but this may have risk and be careful. */
if (lowest_poc > dpb->last_output_poc if (lowest_poc > dpb->last_output_poc
&& lowest_poc - dpb->last_output_poc <= 2) { && lowest_poc - dpb->last_output_poc <= 2) {
GST_TRACE ("lowest-poc: %d, last-output-poc: %d, bumping for" GST_TRACE ("lowest-poc: %d, last-output-poc: %d, diff <= 2, "
" low-latency", lowest_poc, dpb->last_output_poc); "bumping for very-low-latency", lowest_poc, dpb->last_output_poc);
return TRUE; return TRUE;
}
} }
#endif
} }
normal_bump: normal_bump:

View file

@ -164,6 +164,21 @@ struct _GstH264Picture
GDestroyNotify notify; 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 GST_CODECS_API
GType gst_h264_picture_get_type (void); GType gst_h264_picture_get_type (void);
@ -290,7 +305,7 @@ gboolean gst_h264_dpb_has_empty_frame_buffer (GstH264Dpb * dpb);
GST_CODECS_API GST_CODECS_API
gboolean gst_h264_dpb_needs_bump (GstH264Dpb * dpb, gboolean gst_h264_dpb_needs_bump (GstH264Dpb * dpb,
GstH264Picture * to_insert, GstH264Picture * to_insert,
gboolean low_latency); GstH264DpbBumpMode latency_mode);
GST_CODECS_API GST_CODECS_API
GstH264Picture * gst_h264_dpb_bump (GstH264Dpb * dpb, GstH264Picture * gst_h264_dpb_bump (GstH264Dpb * dpb,