mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-24 01:00:37 +00:00
gstutils: add gst_util_ceil_log2
Move ceil_log2 from nalutils.* to gstutils.* Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5888>
This commit is contained in:
parent
a242b93f33
commit
97ebaa0bc1
8 changed files with 63 additions and 34 deletions
|
@ -54222,6 +54222,20 @@ element or %NULL if nothing was found</doc>
|
||||||
</parameter>
|
</parameter>
|
||||||
</parameters>
|
</parameters>
|
||||||
</function>
|
</function>
|
||||||
|
<function name="util_ceil_log2" c:identifier="gst_util_ceil_log2" version="1.24">
|
||||||
|
<doc xml:space="preserve" filename="../subprojects/gstreamer/gst/gstutils.c">Return a max num of log2.</doc>
|
||||||
|
<source-position filename="../subprojects/gstreamer/gst/gstutils.h"/>
|
||||||
|
<return-value transfer-ownership="none">
|
||||||
|
<doc xml:space="preserve" filename="../subprojects/gstreamer/gst/gstutils.c">a computed #guint val.</doc>
|
||||||
|
<type name="guint" c:type="guint"/>
|
||||||
|
</return-value>
|
||||||
|
<parameters>
|
||||||
|
<parameter name="v" transfer-ownership="none">
|
||||||
|
<doc xml:space="preserve" filename="../subprojects/gstreamer/gst/gstutils.c">a #guint32 value.</doc>
|
||||||
|
<type name="guint32" c:type="guint32"/>
|
||||||
|
</parameter>
|
||||||
|
</parameters>
|
||||||
|
</function>
|
||||||
<function name="util_double_to_fraction" c:identifier="gst_util_double_to_fraction">
|
<function name="util_double_to_fraction" c:identifier="gst_util_double_to_fraction">
|
||||||
<doc xml:space="preserve" filename="../subprojects/gstreamer/gst/gstutils.c">Transforms a #gdouble to a fraction and simplifies
|
<doc xml:space="preserve" filename="../subprojects/gstreamer/gst/gstutils.c">Transforms a #gdouble to a fraction and simplifies
|
||||||
the result.</doc>
|
the result.</doc>
|
||||||
|
|
|
@ -2432,7 +2432,8 @@ gst_h264_parser_parse_slice_hdr (GstH264NalParser * nalparser,
|
||||||
guint32 PicHeightInMapUnits = sps->pic_height_in_map_units_minus1 + 1;
|
guint32 PicHeightInMapUnits = sps->pic_height_in_map_units_minus1 + 1;
|
||||||
guint32 PicSizeInMapUnits = PicWidthInMbs * PicHeightInMapUnits;
|
guint32 PicSizeInMapUnits = PicWidthInMbs * PicHeightInMapUnits;
|
||||||
guint32 SliceGroupChangeRate = pps->slice_group_change_rate_minus1 + 1;
|
guint32 SliceGroupChangeRate = pps->slice_group_change_rate_minus1 + 1;
|
||||||
const guint n = ceil_log2 (PicSizeInMapUnits / SliceGroupChangeRate + 1);
|
const guint n =
|
||||||
|
gst_util_ceil_log2 (PicSizeInMapUnits / SliceGroupChangeRate + 1);
|
||||||
READ_UINT16 (&nr, slice->slice_group_change_cycle, n);
|
READ_UINT16 (&nr, slice->slice_group_change_cycle, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1411,7 +1411,7 @@ _h265_slice_bit_writer_ref_pic_list_modification (const GstH265SliceHdr *
|
||||||
guint i;
|
guint i;
|
||||||
const GstH265RefPicListModification *rpl_mod =
|
const GstH265RefPicListModification *rpl_mod =
|
||||||
&slice->ref_pic_list_modification;
|
&slice->ref_pic_list_modification;
|
||||||
const guint n = ceil_log2 (NumPocTotalCurr);
|
const guint n = gst_util_ceil_log2 (NumPocTotalCurr);
|
||||||
|
|
||||||
WRITE_BITS (bw, rpl_mod->ref_pic_list_modification_flag_l0, 1);
|
WRITE_BITS (bw, rpl_mod->ref_pic_list_modification_flag_l0, 1);
|
||||||
|
|
||||||
|
@ -1551,7 +1551,7 @@ _h265_bit_writer_slice_header (const GstH265SliceHdr * slice,
|
||||||
ceil ((gdouble) sps->pic_width_in_luma_samples / (gdouble) CtbSizeY);
|
ceil ((gdouble) sps->pic_width_in_luma_samples / (gdouble) CtbSizeY);
|
||||||
PicSizeInCtbsY = PicWidthInCtbsY * PicHeightInCtbsY;
|
PicSizeInCtbsY = PicWidthInCtbsY * PicHeightInCtbsY;
|
||||||
|
|
||||||
n = ceil_log2 (PicSizeInCtbsY);
|
n = gst_util_ceil_log2 (PicSizeInCtbsY);
|
||||||
|
|
||||||
if (slice->pps->dependent_slice_segments_enabled_flag)
|
if (slice->pps->dependent_slice_segments_enabled_flag)
|
||||||
WRITE_BITS (bw, slice->dependent_slice_segment_flag, 1);
|
WRITE_BITS (bw, slice->dependent_slice_segment_flag, 1);
|
||||||
|
@ -1584,7 +1584,7 @@ _h265_bit_writer_slice_header (const GstH265SliceHdr * slice,
|
||||||
slice->pps->sps, bw, &have_space))
|
slice->pps->sps, bw, &have_space))
|
||||||
goto error;
|
goto error;
|
||||||
} else if (sps->num_short_term_ref_pic_sets > 1) {
|
} else if (sps->num_short_term_ref_pic_sets > 1) {
|
||||||
const guint n = ceil_log2 (sps->num_short_term_ref_pic_sets);
|
const guint n = gst_util_ceil_log2 (sps->num_short_term_ref_pic_sets);
|
||||||
|
|
||||||
if (slice->short_term_ref_pic_set_idx >
|
if (slice->short_term_ref_pic_set_idx >
|
||||||
sps->num_short_term_ref_pic_sets - 1)
|
sps->num_short_term_ref_pic_sets - 1)
|
||||||
|
@ -1605,7 +1605,8 @@ _h265_bit_writer_slice_header (const GstH265SliceHdr * slice,
|
||||||
for (i = 0; i < limit; i++) {
|
for (i = 0; i < limit; i++) {
|
||||||
if (i < slice->num_long_term_sps) {
|
if (i < slice->num_long_term_sps) {
|
||||||
if (sps->num_long_term_ref_pics_sps > 1) {
|
if (sps->num_long_term_ref_pics_sps > 1) {
|
||||||
const guint n = ceil_log2 (sps->num_long_term_ref_pics_sps);
|
const guint n =
|
||||||
|
gst_util_ceil_log2 (sps->num_long_term_ref_pics_sps);
|
||||||
WRITE_BITS (bw, slice->lt_idx_sps[i], n);
|
WRITE_BITS (bw, slice->lt_idx_sps[i], n);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -920,7 +920,7 @@ gst_h265_slice_parse_ref_pic_list_modification (GstH265SliceHdr * slice,
|
||||||
{
|
{
|
||||||
guint i;
|
guint i;
|
||||||
GstH265RefPicListModification *rpl_mod = &slice->ref_pic_list_modification;
|
GstH265RefPicListModification *rpl_mod = &slice->ref_pic_list_modification;
|
||||||
const guint n = ceil_log2 (NumPocTotalCurr);
|
const guint n = gst_util_ceil_log2 (NumPocTotalCurr);
|
||||||
|
|
||||||
READ_UINT8 (nr, rpl_mod->ref_pic_list_modification_flag_l0, 1);
|
READ_UINT8 (nr, rpl_mod->ref_pic_list_modification_flag_l0, 1);
|
||||||
|
|
||||||
|
@ -2797,7 +2797,7 @@ gst_h265_parser_parse_slice_hdr (GstH265Parser * parser,
|
||||||
pps->loop_filter_across_slices_enabled_flag;
|
pps->loop_filter_across_slices_enabled_flag;
|
||||||
|
|
||||||
if (!slice->first_slice_segment_in_pic_flag) {
|
if (!slice->first_slice_segment_in_pic_flag) {
|
||||||
const guint n = ceil_log2 (PicSizeInCtbsY);
|
const guint n = gst_util_ceil_log2 (PicSizeInCtbsY);
|
||||||
|
|
||||||
if (pps->dependent_slice_segments_enabled_flag)
|
if (pps->dependent_slice_segments_enabled_flag)
|
||||||
READ_UINT8 (&nr, slice->dependent_slice_segment_flag, 1);
|
READ_UINT8 (&nr, slice->dependent_slice_segment_flag, 1);
|
||||||
|
@ -2835,7 +2835,7 @@ gst_h265_parser_parse_slice_hdr (GstH265Parser * parser,
|
||||||
(nal_reader_get_pos (&nr) - pos) -
|
(nal_reader_get_pos (&nr) - pos) -
|
||||||
(8 * (nal_reader_get_epb_count (&nr) - epb_pos));
|
(8 * (nal_reader_get_epb_count (&nr) - epb_pos));
|
||||||
} else if (sps->num_short_term_ref_pic_sets > 1) {
|
} else if (sps->num_short_term_ref_pic_sets > 1) {
|
||||||
const guint n = ceil_log2 (sps->num_short_term_ref_pic_sets);
|
const guint n = gst_util_ceil_log2 (sps->num_short_term_ref_pic_sets);
|
||||||
READ_UINT8 (&nr, slice->short_term_ref_pic_set_idx, n);
|
READ_UINT8 (&nr, slice->short_term_ref_pic_set_idx, n);
|
||||||
CHECK_ALLOWED_MAX (slice->short_term_ref_pic_set_idx,
|
CHECK_ALLOWED_MAX (slice->short_term_ref_pic_set_idx,
|
||||||
sps->num_short_term_ref_pic_sets - 1);
|
sps->num_short_term_ref_pic_sets - 1);
|
||||||
|
@ -2855,7 +2855,8 @@ gst_h265_parser_parse_slice_hdr (GstH265Parser * parser,
|
||||||
for (i = 0; i < limit; i++) {
|
for (i = 0; i < limit; i++) {
|
||||||
if (i < slice->num_long_term_sps) {
|
if (i < slice->num_long_term_sps) {
|
||||||
if (sps->num_long_term_ref_pics_sps > 1) {
|
if (sps->num_long_term_ref_pics_sps > 1) {
|
||||||
const guint n = ceil_log2 (sps->num_long_term_ref_pics_sps);
|
const guint n =
|
||||||
|
gst_util_ceil_log2 (sps->num_long_term_ref_pics_sps);
|
||||||
READ_UINT8 (&nr, slice->lt_idx_sps[i], n);
|
READ_UINT8 (&nr, slice->lt_idx_sps[i], n);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -38,29 +38,6 @@
|
||||||
#include "nalutils.h"
|
#include "nalutils.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* Compute Ceil(Log2(v)) */
|
|
||||||
/* Derived from branchless code for integer log2(v) from:
|
|
||||||
<http://graphics.stanford.edu/~seander/bithacks.html#IntegerLog> */
|
|
||||||
guint
|
|
||||||
ceil_log2 (guint32 v)
|
|
||||||
{
|
|
||||||
guint r, shift;
|
|
||||||
|
|
||||||
v--;
|
|
||||||
r = (v > 0xFFFF) << 4;
|
|
||||||
v >>= r;
|
|
||||||
shift = (v > 0xFF) << 3;
|
|
||||||
v >>= shift;
|
|
||||||
r |= shift;
|
|
||||||
shift = (v > 0xF) << 2;
|
|
||||||
v >>= shift;
|
|
||||||
r |= shift;
|
|
||||||
shift = (v > 0x3) << 1;
|
|
||||||
v >>= shift;
|
|
||||||
r |= shift;
|
|
||||||
r |= (v >> 1);
|
|
||||||
return r + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/****** Nal parser ******/
|
/****** Nal parser ******/
|
||||||
|
|
||||||
|
|
|
@ -40,8 +40,6 @@
|
||||||
#include <gst/base/gstbitwriter.h>
|
#include <gst/base/gstbitwriter.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
guint ceil_log2 (guint32 v);
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
const guint8 *data;
|
const guint8 *data;
|
||||||
|
|
|
@ -4473,6 +4473,40 @@ gst_log2 (GstClockTime in)
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gst_util_ceil_log2:
|
||||||
|
* @v: a #guint32 value.
|
||||||
|
*
|
||||||
|
* Return a max num of log2.
|
||||||
|
*
|
||||||
|
* Returns: a computed #guint val.
|
||||||
|
*
|
||||||
|
* Since: 1.24
|
||||||
|
*/
|
||||||
|
guint
|
||||||
|
gst_util_ceil_log2 (guint32 v)
|
||||||
|
{
|
||||||
|
/* Compute Ceil(Log2(v)) */
|
||||||
|
/* Derived from branchless code for integer log2(v) from:
|
||||||
|
<http://graphics.stanford.edu/~seander/bithacks.html#IntegerLog> */
|
||||||
|
guint r, shift;
|
||||||
|
|
||||||
|
v--;
|
||||||
|
r = (v > 0xFFFF) << 4;
|
||||||
|
v >>= r;
|
||||||
|
shift = (v > 0xFF) << 3;
|
||||||
|
v >>= shift;
|
||||||
|
r |= shift;
|
||||||
|
shift = (v > 0xF) << 2;
|
||||||
|
v >>= shift;
|
||||||
|
r |= shift;
|
||||||
|
shift = (v > 0x3) << 1;
|
||||||
|
v >>= shift;
|
||||||
|
r |= shift;
|
||||||
|
r |= (v >> 1);
|
||||||
|
return r + 1;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gst_calculate_linear_regression: (skip)
|
* gst_calculate_linear_regression: (skip)
|
||||||
* @xy: Pairs of (x,y) values
|
* @xy: Pairs of (x,y) values
|
||||||
|
|
|
@ -1240,6 +1240,9 @@ void gst_type_mark_as_plugin_api (GType type, GstPluginAPIFlags f
|
||||||
GST_API
|
GST_API
|
||||||
gboolean gst_type_is_plugin_api (GType type, GstPluginAPIFlags *flags);
|
gboolean gst_type_is_plugin_api (GType type, GstPluginAPIFlags *flags);
|
||||||
|
|
||||||
|
GST_API
|
||||||
|
guint gst_util_ceil_log2 (guint32 v);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* __GST_UTILS_H__ */
|
#endif /* __GST_UTILS_H__ */
|
||||||
|
|
Loading…
Reference in a new issue