mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-23 00:36:51 +00:00
h265parse: Use gst_h265_parser_parse_decoder_config_record()
Stop duplicating code and use newly added parsing method instead Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2759>
This commit is contained in:
parent
5227b3c9a6
commit
8c596aeb5b
1 changed files with 19 additions and 44 deletions
|
@ -3113,12 +3113,10 @@ gst_h265_parse_set_caps (GstBaseParse * parse, GstCaps * caps)
|
||||||
GstStructure *str;
|
GstStructure *str;
|
||||||
const GValue *value;
|
const GValue *value;
|
||||||
GstBuffer *codec_data = NULL;
|
GstBuffer *codec_data = NULL;
|
||||||
gsize off, size;
|
|
||||||
guint format, align;
|
guint format, align;
|
||||||
guint num_nals, i, j;
|
|
||||||
GstH265NalUnit nalu;
|
|
||||||
GstH265ParserResult parseres;
|
GstH265ParserResult parseres;
|
||||||
GstCaps *old_caps;
|
GstCaps *old_caps;
|
||||||
|
GstH265DecoderConfigRecord *config = NULL;
|
||||||
|
|
||||||
h265parse = GST_H265_PARSE (parse);
|
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 &&
|
if (format != GST_H265_PARSE_FORMAT_BYTE &&
|
||||||
(value = gst_structure_get_value (str, "codec_data"))) {
|
(value = gst_structure_get_value (str, "codec_data"))) {
|
||||||
GstMapInfo map;
|
GstMapInfo map;
|
||||||
guint8 *data;
|
guint i, j;
|
||||||
guint num_nal_arrays;
|
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (h265parse, "have packetized h265");
|
GST_DEBUG_OBJECT (h265parse, "have packetized h265");
|
||||||
/* make note for optional split processing */
|
/* make note for optional split processing */
|
||||||
|
@ -3160,49 +3157,32 @@ gst_h265_parse_set_caps (GstBaseParse * parse, GstCaps * caps)
|
||||||
if (!codec_data)
|
if (!codec_data)
|
||||||
goto wrong_type;
|
goto wrong_type;
|
||||||
gst_buffer_map (codec_data, &map, GST_MAP_READ);
|
gst_buffer_map (codec_data, &map, GST_MAP_READ);
|
||||||
data = map.data;
|
|
||||||
size = map.size;
|
|
||||||
|
|
||||||
/* parse the hvcC data */
|
parseres =
|
||||||
if (size < 23) {
|
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);
|
gst_buffer_unmap (codec_data, &map);
|
||||||
goto hvcc_too_small;
|
goto hvcc_failed;
|
||||||
}
|
|
||||||
/* 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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",
|
GST_DEBUG_OBJECT (h265parse, "nal length size %u",
|
||||||
h265parse->nal_length_size);
|
h265parse->nal_length_size);
|
||||||
|
|
||||||
num_nal_arrays = data[22];
|
for (i = 0; i < config->nalu_array->len; i++) {
|
||||||
off = 23;
|
GstH265DecoderConfigRecordNalUnitArray *array =
|
||||||
|
&g_array_index (config->nalu_array,
|
||||||
|
GstH265DecoderConfigRecordNalUnitArray, i);
|
||||||
|
|
||||||
for (i = 0; i < num_nal_arrays; i++) {
|
for (j = 0; j < array->nalu->len; j++) {
|
||||||
if (off + 3 >= size) {
|
GstH265NalUnit *nalu = &g_array_index (array->nalu, GstH265NalUnit, j);
|
||||||
gst_buffer_unmap (codec_data, &map);
|
|
||||||
goto hvcc_too_small;
|
|
||||||
}
|
|
||||||
|
|
||||||
num_nals = GST_READ_UINT16_BE (data + off + 1);
|
gst_h265_parse_process_nal (h265parse, nalu);
|
||||||
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_decoder_config_record_free (config);
|
||||||
gst_buffer_unmap (codec_data, &map);
|
gst_buffer_unmap (codec_data, &map);
|
||||||
|
|
||||||
/* don't confuse codec_data with inband vps/sps/pps */
|
/* 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;
|
return TRUE;
|
||||||
|
|
||||||
/* ERRORS */
|
/* ERRORS */
|
||||||
hvcc_too_small:
|
hvcc_failed:
|
||||||
{
|
{
|
||||||
GST_DEBUG_OBJECT (h265parse, "hvcC size %" G_GSIZE_FORMAT " < 23", size);
|
GST_DEBUG_OBJECT (h265parse, "Failed to parse hvcC data");
|
||||||
goto refuse_caps;
|
|
||||||
}
|
|
||||||
wrong_version:
|
|
||||||
{
|
|
||||||
GST_DEBUG_OBJECT (h265parse, "wrong hvcC version");
|
|
||||||
goto refuse_caps;
|
goto refuse_caps;
|
||||||
}
|
}
|
||||||
wrong_type:
|
wrong_type:
|
||||||
|
|
Loading…
Reference in a new issue