From c5546d476a0f33166ce5d8ff8c15ec40b701cd33 Mon Sep 17 00:00:00 2001 From: He Junyan Date: Sun, 10 Apr 2022 17:28:03 +0800 Subject: [PATCH] va: h264enc: Correct the hierarchical level name for pyramid-b frames. The current way names the level by the number of B frames it contains, the less it contains, the higher level it is. So the non ref B frames are in the lowest layer and the B frames in the highest level refer to I/P frames. But the widely used way is just the opposite, the ref B frames are in the lower level and non ref B frames are at the highest level. The is just a terminology change, and does not have any effect for compression result and quality. Part-of: --- .../gst-plugins-bad/sys/va/gstvah264enc.c | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/subprojects/gst-plugins-bad/sys/va/gstvah264enc.c b/subprojects/gst-plugins-bad/sys/va/gstvah264enc.c index b514c3b12e..4f53eeddb2 100644 --- a/subprojects/gst-plugins-bad/sys/va/gstvah264enc.c +++ b/subprojects/gst-plugins-bad/sys/va/gstvah264enc.c @@ -913,15 +913,16 @@ struct PyramidInfo }; static void -_set_pyramid_info (struct PyramidInfo *info, guint len, guint level) +_set_pyramid_info (struct PyramidInfo *info, guint len, + guint current_level, guint highest_level) { guint index; g_assert (len >= 1); - if (level == 0 || len == 1) { + if (current_level == highest_level || len == 1) { for (index = 0; index < len; index++) { - info[index].level = level; + info[index].level = current_level; info[index].left_ref_poc_diff = (index + 1) * -2; info[index].right_ref_poc_diff = (len - index) * 2; } @@ -930,17 +931,18 @@ _set_pyramid_info (struct PyramidInfo *info, guint len, guint level) } index = len / 2; - info[index].level = level; + info[index].level = current_level; info[index].left_ref_poc_diff = (index + 1) * -2; info[index].right_ref_poc_diff = (len - index) * 2; - level--; + current_level++; if (index > 0) - _set_pyramid_info (info, index, level); + _set_pyramid_info (info, index, current_level, highest_level); if (index + 1 < len) - _set_pyramid_info (&info[index + 1], len - (index + 1), level); + _set_pyramid_info (&info[index + 1], len - (index + 1), + current_level, highest_level); } static void @@ -953,7 +955,7 @@ _create_gop_frame_types (GstVaH264Enc * self) if (self->gop.highest_pyramid_level > 0) { g_assert (self->gop.num_bframes > 0); _set_pyramid_info (pyramid_info, self->gop.num_bframes, - self->gop.highest_pyramid_level); + 0, self->gop.highest_pyramid_level); } g_assert (self->gop.idr_period <= MAX_GOP_SIZE); @@ -979,7 +981,8 @@ _create_gop_frame_types (GstVaH264Enc * self) self->gop.frame_types[i].pyramid_level = pyramid_info[pyramid_index].level; self->gop.frame_types[i].is_ref = - (self->gop.frame_types[i].pyramid_level > 0); + (self->gop.frame_types[i].pyramid_level < + self->gop.highest_pyramid_level); self->gop.frame_types[i].left_ref_poc_diff = pyramid_info[pyramid_index].left_ref_poc_diff; self->gop.frame_types[i].right_ref_poc_diff = @@ -1779,7 +1782,7 @@ _pop_pyramid_b_frame (GstVaH264Enc * self) } vaf = _enc_frame (f); - if (b_vaframe->pyramid_level > vaf->pyramid_level) { + if (b_vaframe->pyramid_level < vaf->pyramid_level) { b_frame = f; b_vaframe = vaf; index = i;