codecparsers: avoid libc math library

Instead of the libc ceil() and pow() machinery for double types, since the
library uses it for unsigned integers use a simple math function for for ceil
division and bit left shift for integer power of two.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/7869>
This commit is contained in:
Víctor Manuel Jáquez Leal 2024-11-11 17:47:48 +01:00 committed by GStreamer Marge Bot
parent ff9100eb4d
commit e60efa4b9a
4 changed files with 15 additions and 15 deletions

View file

@ -25,7 +25,6 @@
#include "gsth265bitwriter.h"
#include "nalutils.h"
#include <gst/base/gstbitwriter.h>
#include <math.h>
#ifndef GST_DISABLE_GST_DEBUG
#define GST_CAT_DEFAULT gst_h265_debug_category_get()
@ -1566,10 +1565,8 @@ _h265_bit_writer_slice_header (const GstH265SliceHdr * slice,
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);
PicHeightInCtbsY = div_ceil (sps->pic_height_in_luma_samples, CtbSizeY);
PicWidthInCtbsY = div_ceil (sps->pic_width_in_luma_samples, CtbSizeY);
PicSizeInCtbsY = PicWidthInCtbsY * PicHeightInCtbsY;
n = gst_util_ceil_log2 (PicSizeInCtbsY);

View file

@ -70,7 +70,6 @@
#include <gst/base/gstbytereader.h>
#include <gst/base/gstbitreader.h>
#include <string.h>
#include <math.h>
#ifndef GST_DISABLE_GST_DEBUG
#define GST_CAT_DEFAULT gst_h265_debug_category_get()
@ -1180,7 +1179,7 @@ gst_h265_parser_parse_recovery_point (GstH265Parser * parser,
goto error;
}
max_pic_order_cnt_lsb = pow (2, (sps->log2_max_pic_order_cnt_lsb_minus4 + 4));
max_pic_order_cnt_lsb = 1 << (sps->log2_max_pic_order_cnt_lsb_minus4 + 4);
READ_SE_ALLOWED (nr, rp->recovery_poc_cnt, -max_pic_order_cnt_lsb / 2,
max_pic_order_cnt_lsb - 1);
READ_UINT8 (nr, rp->exact_match_flag, 1);
@ -2375,9 +2374,8 @@ gst_h265_parse_pps (GstH265Parser * parser, GstH265NalUnit * nalu,
MinCbLog2SizeY + sps->log2_diff_max_min_luma_coding_block_size;
CtbSizeY = 1 << CtbLog2SizeY;
pps->PicHeightInCtbsY =
ceil ((gdouble) sps->pic_height_in_luma_samples / (gdouble) CtbSizeY);
pps->PicWidthInCtbsY =
ceil ((gdouble) sps->pic_width_in_luma_samples / (gdouble) CtbSizeY);
div_ceil (sps->pic_height_in_luma_samples, CtbSizeY);
pps->PicWidthInCtbsY = div_ceil (sps->pic_width_in_luma_samples, CtbSizeY);
READ_UE_ALLOWED (&nr,
pps->num_tile_columns_minus1, 0, pps->PicWidthInCtbsY - 1);
@ -2698,10 +2696,8 @@ gst_h265_parser_fill_pps (GstH265Parser * parser, GstH265PPS * pps)
MinCbLog2SizeY = sps->log2_min_luma_coding_block_size_minus3 + 3;
CtbLog2SizeY = MinCbLog2SizeY + sps->log2_diff_max_min_luma_coding_block_size;
CtbSizeY = 1 << CtbLog2SizeY;
pps->PicHeightInCtbsY =
ceil ((gdouble) sps->pic_height_in_luma_samples / (gdouble) CtbSizeY);
pps->PicWidthInCtbsY =
ceil ((gdouble) sps->pic_width_in_luma_samples / (gdouble) CtbSizeY);
pps->PicHeightInCtbsY = div_ceil (sps->pic_height_in_luma_samples, CtbSizeY);
pps->PicWidthInCtbsY = div_ceil (sps->pic_width_in_luma_samples, CtbSizeY);
if (pps->init_qp_minus26 < -(26 + qp_bd_offset))
return GST_H265_PARSER_BROKEN_LINK;

View file

@ -58,7 +58,7 @@ gstcodecparsers = library('gstcodecparsers-' + api_version,
soversion : soversion,
darwin_versions : osxversion,
install : true,
dependencies : [gstbase_dep, libm],
dependencies : [gstbase_dep],
)
pkg_name = 'gstreamer-codecparsers-1.0'

View file

@ -261,3 +261,10 @@ gboolean count_exp_golomb_bits (guint32 value, guint * leading_zeros, guint * re
goto error; \
} \
}
static inline guint32 div_ceil (guint32 a, guint32 b)
{
/* http://blog.pkh.me/p/36-figuring-out-round%2C-floor-and-ceil-with-integer-division.html */
g_assert (b > 0);
return a / b + (a % b > 0);
}