diff --git a/subprojects/gst-plugins-bad/gst/videoparsers/gsth265parse.c b/subprojects/gst-plugins-bad/gst/videoparsers/gsth265parse.c index 76f2a5f3a2..b9750f62bb 100644 --- a/subprojects/gst-plugins-bad/gst/videoparsers/gsth265parse.c +++ b/subprojects/gst-plugins-bad/gst/videoparsers/gsth265parse.c @@ -3113,12 +3113,10 @@ gst_h265_parse_set_caps (GstBaseParse * parse, GstCaps * caps) GstStructure *str; const GValue *value; GstBuffer *codec_data = NULL; - gsize off, size; guint format, align; - guint num_nals, i, j; - GstH265NalUnit nalu; GstH265ParserResult parseres; GstCaps *old_caps; + GstH265DecoderConfigRecord *config = NULL; h265parse = GST_H265_PARSE (parse); @@ -3149,8 +3147,7 @@ gst_h265_parse_set_caps (GstBaseParse * parse, GstCaps * caps) if (format != GST_H265_PARSE_FORMAT_BYTE && (value = gst_structure_get_value (str, "codec_data"))) { GstMapInfo map; - guint8 *data; - guint num_nal_arrays; + guint i, j; GST_DEBUG_OBJECT (h265parse, "have packetized h265"); /* make note for optional split processing */ @@ -3160,49 +3157,32 @@ gst_h265_parse_set_caps (GstBaseParse * parse, GstCaps * caps) if (!codec_data) goto wrong_type; gst_buffer_map (codec_data, &map, GST_MAP_READ); - data = map.data; - size = map.size; - /* parse the hvcC data */ - if (size < 23) { + parseres = + gst_h265_parser_parse_decoder_config_record (h265parse->nalparser, + map.data, map.size, &config); + if (parseres != GST_H265_PARSER_OK) { gst_buffer_unmap (codec_data, &map); - goto hvcc_too_small; - } - /* parse the version, this must be one but - * is zero until the spec is finalized */ - if (data[0] != 0 && data[0] != 1) { - gst_buffer_unmap (codec_data, &map); - goto wrong_version; + goto hvcc_failed; } - h265parse->nal_length_size = (data[21] & 0x03) + 1; + h265parse->nal_length_size = config->length_size_minus_one + 1; GST_DEBUG_OBJECT (h265parse, "nal length size %u", h265parse->nal_length_size); - num_nal_arrays = data[22]; - off = 23; + for (i = 0; i < config->nalu_array->len; i++) { + GstH265DecoderConfigRecordNalUnitArray *array = + &g_array_index (config->nalu_array, + GstH265DecoderConfigRecordNalUnitArray, i); - for (i = 0; i < num_nal_arrays; i++) { - if (off + 3 >= size) { - gst_buffer_unmap (codec_data, &map); - goto hvcc_too_small; - } + for (j = 0; j < array->nalu->len; j++) { + GstH265NalUnit *nalu = &g_array_index (array->nalu, GstH265NalUnit, j); - num_nals = GST_READ_UINT16_BE (data + off + 1); - off += 3; - for (j = 0; j < num_nals; j++) { - parseres = gst_h265_parser_identify_nalu_hevc (h265parse->nalparser, - data, off, size, 2, &nalu); - - if (parseres != GST_H265_PARSER_OK) { - gst_buffer_unmap (codec_data, &map); - goto hvcc_too_small; - } - - gst_h265_parse_process_nal (h265parse, &nalu); - off = nalu.offset + nalu.size; + gst_h265_parse_process_nal (h265parse, nalu); } } + + gst_h265_decoder_config_record_free (config); gst_buffer_unmap (codec_data, &map); /* don't confuse codec_data with inband vps/sps/pps */ @@ -3270,14 +3250,9 @@ gst_h265_parse_set_caps (GstBaseParse * parse, GstCaps * caps) return TRUE; /* ERRORS */ -hvcc_too_small: +hvcc_failed: { - GST_DEBUG_OBJECT (h265parse, "hvcC size %" G_GSIZE_FORMAT " < 23", size); - goto refuse_caps; - } -wrong_version: - { - GST_DEBUG_OBJECT (h265parse, "wrong hvcC version"); + GST_DEBUG_OBJECT (h265parse, "Failed to parse hvcC data"); goto refuse_caps; } wrong_type: