mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-03 04:52:28 +00:00
h265parser: Add helper macro for nal type classification
Add some macros to remove code duplication and to make it more readable
This commit is contained in:
parent
924006279a
commit
959320264a
4 changed files with 142 additions and 15 deletions
|
@ -2269,8 +2269,7 @@ gst_h265_parser_parse_slice_hdr (GstH265Parser * parser,
|
||||||
|
|
||||||
READ_UINT8 (&nr, slice->first_slice_segment_in_pic_flag, 1);
|
READ_UINT8 (&nr, slice->first_slice_segment_in_pic_flag, 1);
|
||||||
|
|
||||||
if (nalu->type >= GST_H265_NAL_SLICE_BLA_W_LP
|
if (GST_H265_IS_NAL_TYPE_IRAP (nalu->type))
|
||||||
&& nalu->type <= RESERVED_IRAP_NAL_TYPE_MAX)
|
|
||||||
READ_UINT8 (&nr, slice->no_output_of_prior_pics_flag, 1);
|
READ_UINT8 (&nr, slice->no_output_of_prior_pics_flag, 1);
|
||||||
|
|
||||||
READ_UE_MAX (&nr, pps_id, GST_H265_MAX_PPS_COUNT - 1);
|
READ_UE_MAX (&nr, pps_id, GST_H265_MAX_PPS_COUNT - 1);
|
||||||
|
@ -2321,8 +2320,7 @@ gst_h265_parser_parse_slice_hdr (GstH265Parser * parser,
|
||||||
if (sps->separate_colour_plane_flag == 1)
|
if (sps->separate_colour_plane_flag == 1)
|
||||||
READ_UINT8 (&nr, slice->colour_plane_id, 2);
|
READ_UINT8 (&nr, slice->colour_plane_id, 2);
|
||||||
|
|
||||||
if ((nalu->type != GST_H265_NAL_SLICE_IDR_W_RADL)
|
if (!GST_H265_IS_NAL_TYPE_IDR (nalu->type)) {
|
||||||
&& (nalu->type != GST_H265_NAL_SLICE_IDR_N_LP)) {
|
|
||||||
READ_UINT16 (&nr, slice->pic_order_cnt_lsb,
|
READ_UINT16 (&nr, slice->pic_order_cnt_lsb,
|
||||||
(sps->log2_max_pic_order_cnt_lsb_minus4 + 4));
|
(sps->log2_max_pic_order_cnt_lsb_minus4 + 4));
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,72 @@ G_BEGIN_DECLS
|
||||||
#define GST_H265_IS_P_SLICE(slice) ((slice)->type == GST_H265_P_SLICE)
|
#define GST_H265_IS_P_SLICE(slice) ((slice)->type == GST_H265_P_SLICE)
|
||||||
#define GST_H265_IS_I_SLICE(slice) ((slice)->type == GST_H265_I_SLICE)
|
#define GST_H265_IS_I_SLICE(slice) ((slice)->type == GST_H265_I_SLICE)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GST_H265_IS_NAL_TYPE_IDR:
|
||||||
|
* @nal_type: a #GstH265NalUnitType
|
||||||
|
*
|
||||||
|
* Check whether @nal_type is IDR or not
|
||||||
|
*
|
||||||
|
* Since: 1.18
|
||||||
|
*/
|
||||||
|
#define GST_H265_IS_NAL_TYPE_IDR(nal_type) \
|
||||||
|
((nal_type) == GST_H265_NAL_SLICE_IDR_W_RADL || (nal_type) == GST_H265_NAL_SLICE_IDR_N_LP)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GST_H265_IS_NAL_TYPE_IRAP:
|
||||||
|
* @nal_type: a #GstH265NalUnitType
|
||||||
|
*
|
||||||
|
* Check whether @nal_type is IRAP or not
|
||||||
|
*
|
||||||
|
* Since: 1.18
|
||||||
|
*/
|
||||||
|
#define GST_H265_IS_NAL_TYPE_IRAP(nal_type) \
|
||||||
|
((nal_type) >= GST_H265_NAL_SLICE_BLA_W_LP && (nal_type) <= RESERVED_IRAP_NAL_TYPE_MAX)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GST_H265_IS_NAL_TYPE_BLA:
|
||||||
|
* @nal_type: a #GstH265NalUnitType
|
||||||
|
*
|
||||||
|
* Check whether @nal_type is BLA or not
|
||||||
|
*
|
||||||
|
* Since: 1.18
|
||||||
|
*/
|
||||||
|
#define GST_H265_IS_NAL_TYPE_BLA(nal_type) \
|
||||||
|
((nal_type) >= GST_H265_NAL_SLICE_BLA_W_LP && (nal_type) <= GST_H265_NAL_SLICE_BLA_N_LP)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GST_H265_IS_NAL_TYPE_CRA:
|
||||||
|
* @nal_type: a #GstH265NalUnitType
|
||||||
|
*
|
||||||
|
* Check whether @nal_type is CRA or not
|
||||||
|
*
|
||||||
|
* Since: 1.18
|
||||||
|
*/
|
||||||
|
#define GST_H265_IS_NAL_TYPE_CRA(nal_type) \
|
||||||
|
((nal_type) == GST_H265_NAL_SLICE_CRA_NUT)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GST_H265_IS_NAL_TYPE_RADL:
|
||||||
|
* @nal_type: a #GstH265NalUnitType
|
||||||
|
*
|
||||||
|
* Check whether @nal_type is RADL or not
|
||||||
|
*
|
||||||
|
* Since: 1.18
|
||||||
|
*/
|
||||||
|
#define GST_H265_IS_NAL_TYPE_RADL(nal_type) \
|
||||||
|
((nal_type) == GST_H265_NAL_SLICE_RADL_N || (nal_type) == GST_H265_NAL_SLICE_RADL_R)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GST_H265_IS_NAL_TYPE_RASL:
|
||||||
|
* @nal_type: a #GstH265NalUnitType
|
||||||
|
*
|
||||||
|
* Check whether @nal_type is RASL or not
|
||||||
|
*
|
||||||
|
* Since: 1.18
|
||||||
|
*/
|
||||||
|
#define GST_H265_IS_NAL_TYPE_RASL(nal_type) \
|
||||||
|
((nal_type) == GST_H265_NAL_SLICE_RASL_N || (nal_type) == GST_H265_NAL_SLICE_RASL_R)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GstH265Profile:
|
* GstH265Profile:
|
||||||
* @GST_H265_PROFILE_MAIN: Main profile (A.3.2)
|
* @GST_H265_PROFILE_MAIN: Main profile (A.3.2)
|
||||||
|
|
|
@ -907,19 +907,15 @@ gst_h265_parse_process_nal (GstH265Parse * h265parse, GstH265NalUnit * nalu)
|
||||||
* 1) the first AU in bitstream is CRA
|
* 1) the first AU in bitstream is CRA
|
||||||
* 2) or the first AU following EOS nal is CRA
|
* 2) or the first AU following EOS nal is CRA
|
||||||
* 3) or it has HandleCraAsBlaFlag equal to 1 */
|
* 3) or it has HandleCraAsBlaFlag equal to 1 */
|
||||||
if (nal_type == GST_H265_NAL_SLICE_IDR_W_RADL ||
|
if (GST_H265_IS_NAL_TYPE_IDR (nal_type)) {
|
||||||
nal_type == GST_H265_NAL_SLICE_IDR_N_LP) {
|
|
||||||
/* NoRaslOutputFlag is equal to 1 for each IDR */
|
/* NoRaslOutputFlag is equal to 1 for each IDR */
|
||||||
no_rasl_output_flag = TRUE;
|
no_rasl_output_flag = TRUE;
|
||||||
} else if (nal_type == GST_H265_NAL_SLICE_BLA_W_LP ||
|
} else if (GST_H265_IS_NAL_TYPE_BLA (nal_type)) {
|
||||||
nal_type == GST_H265_NAL_SLICE_BLA_W_RADL ||
|
|
||||||
nal_type == GST_H265_NAL_SLICE_BLA_N_LP) {
|
|
||||||
/* NoRaslOutputFlag is equal to 1 for each BLA */
|
/* NoRaslOutputFlag is equal to 1 for each BLA */
|
||||||
no_rasl_output_flag = TRUE;
|
no_rasl_output_flag = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
is_irap = ((nal_type >= GST_H265_NAL_SLICE_BLA_W_LP)
|
is_irap = GST_H265_IS_NAL_TYPE_IRAP (nal_type);
|
||||||
&& (nal_type <= GST_H265_NAL_SLICE_CRA_NUT)) ? TRUE : FALSE;
|
|
||||||
|
|
||||||
if (no_rasl_output_flag && is_irap
|
if (no_rasl_output_flag && is_irap
|
||||||
&& slice.first_slice_segment_in_pic_flag == 1) {
|
&& slice.first_slice_segment_in_pic_flag == 1) {
|
||||||
|
@ -1015,8 +1011,7 @@ gst_h265_parse_collect_nal (GstH265Parse * h265parse, const guint8 * data,
|
||||||
* i.e. other types become aggregated in front of it */
|
* i.e. other types become aggregated in front of it */
|
||||||
h265parse->picture_start |= ((nal_type >= GST_H265_NAL_SLICE_TRAIL_N
|
h265parse->picture_start |= ((nal_type >= GST_H265_NAL_SLICE_TRAIL_N
|
||||||
&& nal_type <= GST_H265_NAL_SLICE_RASL_R)
|
&& nal_type <= GST_H265_NAL_SLICE_RASL_R)
|
||||||
|| (nal_type >= GST_H265_NAL_SLICE_BLA_W_LP
|
|| GST_H265_IS_NAL_TYPE_IRAP (nal_type));
|
||||||
&& nal_type <= RESERVED_IRAP_NAL_TYPE_MAX));
|
|
||||||
|
|
||||||
/* consider a coded slices (IRAP or not) to start a picture,
|
/* consider a coded slices (IRAP or not) to start a picture,
|
||||||
* (so ending the previous one) if first_slice_segment_in_pic_flag == 1*/
|
* (so ending the previous one) if first_slice_segment_in_pic_flag == 1*/
|
||||||
|
@ -1033,8 +1028,7 @@ gst_h265_parse_collect_nal (GstH265Parse * h265parse, const guint8 * data,
|
||||||
complete |= h265parse->picture_start
|
complete |= h265parse->picture_start
|
||||||
&& (((nal_type >= GST_H265_NAL_SLICE_TRAIL_N
|
&& (((nal_type >= GST_H265_NAL_SLICE_TRAIL_N
|
||||||
&& nal_type <= GST_H265_NAL_SLICE_RASL_R)
|
&& nal_type <= GST_H265_NAL_SLICE_RASL_R)
|
||||||
|| (nal_type >= GST_H265_NAL_SLICE_BLA_W_LP
|
|| GST_H265_IS_NAL_TYPE_IRAP (nal_type))
|
||||||
&& nal_type <= RESERVED_IRAP_NAL_TYPE_MAX))
|
|
||||||
&& (nnalu.data[nnalu.offset + 2] & 0x80));
|
&& (nnalu.data[nnalu.offset + 2] & 0x80));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -524,6 +524,74 @@ GST_START_TEST (test_h265_parse_pps)
|
||||||
|
|
||||||
GST_END_TEST;
|
GST_END_TEST;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
GstH265NalUnitType type;
|
||||||
|
gboolean is_idr;
|
||||||
|
gboolean is_irap;
|
||||||
|
gboolean is_bla;
|
||||||
|
gboolean is_cra;
|
||||||
|
gboolean is_radl;
|
||||||
|
gboolean is_rasl;
|
||||||
|
} H265NalTypeTestVector;
|
||||||
|
|
||||||
|
GST_START_TEST (test_h265_nal_type_classification)
|
||||||
|
{
|
||||||
|
gint i;
|
||||||
|
/* *INDENT-OFF* */
|
||||||
|
H265NalTypeTestVector test_vector[] = {
|
||||||
|
/* NAL-TYPE IDR IRAP BLA CRA RADL RASL */
|
||||||
|
{GST_H265_NAL_SLICE_TRAIL_N, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE},
|
||||||
|
{GST_H265_NAL_SLICE_TRAIL_R, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE},
|
||||||
|
{GST_H265_NAL_SLICE_TSA_N, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE},
|
||||||
|
{GST_H265_NAL_SLICE_TSA_R, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE},
|
||||||
|
{GST_H265_NAL_SLICE_STSA_N, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE},
|
||||||
|
{GST_H265_NAL_SLICE_STSA_R, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE},
|
||||||
|
{GST_H265_NAL_SLICE_RADL_N, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE},
|
||||||
|
{GST_H265_NAL_SLICE_RADL_R, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE},
|
||||||
|
{GST_H265_NAL_SLICE_RASL_N, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE },
|
||||||
|
{GST_H265_NAL_SLICE_RASL_R, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE },
|
||||||
|
/* 10 ~ 15: reserved non-irap sublayer nal */
|
||||||
|
{GST_H265_NAL_SLICE_BLA_W_LP, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE},
|
||||||
|
{GST_H265_NAL_SLICE_BLA_W_RADL, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE},
|
||||||
|
{GST_H265_NAL_SLICE_BLA_N_LP, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE},
|
||||||
|
{GST_H265_NAL_SLICE_IDR_W_RADL, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE},
|
||||||
|
{GST_H265_NAL_SLICE_IDR_N_LP, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE},
|
||||||
|
{GST_H265_NAL_SLICE_CRA_NUT, FALSE, TRUE, FALSE, TRUE, FALSE, FALSE},
|
||||||
|
/* 22 ~ 23: reserved irap nal */
|
||||||
|
{(GstH265NalUnitType) 22, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE},
|
||||||
|
{(GstH265NalUnitType) 23, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE},
|
||||||
|
};
|
||||||
|
/* *INDENT-ON* */
|
||||||
|
|
||||||
|
for (i = 0; i < G_N_ELEMENTS (test_vector); i++) {
|
||||||
|
assert_equals_int (GST_H265_IS_NAL_TYPE_IDR (test_vector[i].type),
|
||||||
|
test_vector[i].is_idr);
|
||||||
|
assert_equals_int (GST_H265_IS_NAL_TYPE_IRAP (test_vector[i].type),
|
||||||
|
test_vector[i].is_irap);
|
||||||
|
assert_equals_int (GST_H265_IS_NAL_TYPE_BLA (test_vector[i].type),
|
||||||
|
test_vector[i].is_bla);
|
||||||
|
assert_equals_int (GST_H265_IS_NAL_TYPE_CRA (test_vector[i].type),
|
||||||
|
test_vector[i].is_cra);
|
||||||
|
assert_equals_int (GST_H265_IS_NAL_TYPE_RADL (test_vector[i].type),
|
||||||
|
test_vector[i].is_radl);
|
||||||
|
assert_equals_int (GST_H265_IS_NAL_TYPE_RASL (test_vector[i].type),
|
||||||
|
test_vector[i].is_rasl);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = RESERVED_NON_IRAP_NAL_TYPE_MIN;
|
||||||
|
i <= UNSPECIFIED_NON_VCL_NAL_TYPE_MAX; i++) {
|
||||||
|
assert_equals_int (GST_H265_IS_NAL_TYPE_IDR (i), FALSE);
|
||||||
|
assert_equals_int (GST_H265_IS_NAL_TYPE_IRAP (i), FALSE);
|
||||||
|
assert_equals_int (GST_H265_IS_NAL_TYPE_BLA (i), FALSE);
|
||||||
|
assert_equals_int (GST_H265_IS_NAL_TYPE_CRA (i), FALSE);
|
||||||
|
assert_equals_int (GST_H265_IS_NAL_TYPE_RADL (i), FALSE);
|
||||||
|
assert_equals_int (GST_H265_IS_NAL_TYPE_RASL (i), FALSE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GST_END_TEST;
|
||||||
|
|
||||||
static Suite *
|
static Suite *
|
||||||
h265parser_suite (void)
|
h265parser_suite (void)
|
||||||
{
|
{
|
||||||
|
@ -541,6 +609,7 @@ h265parser_suite (void)
|
||||||
tcase_add_test (tc_chain, test_h265_format_range_profiles_partial_match);
|
tcase_add_test (tc_chain, test_h265_format_range_profiles_partial_match);
|
||||||
tcase_add_test (tc_chain, test_h265_parse_vps);
|
tcase_add_test (tc_chain, test_h265_parse_vps);
|
||||||
tcase_add_test (tc_chain, test_h265_parse_pps);
|
tcase_add_test (tc_chain, test_h265_parse_pps);
|
||||||
|
tcase_add_test (tc_chain, test_h265_nal_type_classification);
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue