codecparsers: bitwriter: Calculate PicSizeInCtbsY when writing slice header.

The slice->pps->PicWidthInCtbsY/PicHeightInCtbsY values are calculated when
 we parse the slice header. But they are not calculated in bitwriter and so
 may not have valid value when writing slice header.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2287>
This commit is contained in:
He Junyan 2022-04-26 22:35:30 +08:00 committed by GStreamer Marge Bot
parent abf19020a4
commit 9ec4041a51

View file

@ -25,6 +25,7 @@
#include "gsth265bitwriter.h"
#include <gst/codecparsers/nalutils.h>
#include <gst/base/gstbitwriter.h>
#include <math.h>
/******************************** Utils ********************************/
#define SIGNED(val) (2 * ABS(val) - ((val) > 0))
@ -1532,8 +1533,25 @@ _h265_bit_writer_slice_header (const GstH265SliceHdr * slice,
WRITE_UE_MAX (bw, slice->pps->id, GST_H265_MAX_PPS_COUNT - 1);
if (!slice->first_slice_segment_in_pic_flag) {
const guint n =
ceil_log2 (slice->pps->PicWidthInCtbsY * slice->pps->PicHeightInCtbsY);
guint32 PicSizeInCtbsY;
guint32 PicWidthInCtbsY;
guint32 PicHeightInCtbsY;
guint32 CtbSizeY, MinCbLog2SizeY, CtbLog2SizeY;
guint n;
/* We can not directly use slice->pps->PicWidthInCtbsY/PicHeightInCtbsY,
they are calculated value when parsing but may not have value here. */
MinCbLog2SizeY = sps->log2_min_luma_coding_block_size_minus3 + 3;
CtbLog2SizeY =
MinCbLog2SizeY + sps->log2_diff_max_min_luma_coding_block_size;
CtbSizeY = 1 << CtbLog2SizeY;
PicHeightInCtbsY =
ceil ((gdouble) sps->pic_height_in_luma_samples / (gdouble) CtbSizeY);
PicWidthInCtbsY =
ceil ((gdouble) sps->pic_width_in_luma_samples / (gdouble) CtbSizeY);
PicSizeInCtbsY = PicWidthInCtbsY * PicHeightInCtbsY;
n = ceil_log2 (PicSizeInCtbsY);
if (slice->pps->dependent_slice_segments_enabled_flag)
WRITE_BITS (bw, slice->dependent_slice_segment_flag, 1);