mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-23 06:26:23 +00:00
codecparsers: h264: add gst_h264_parse_nalu_header() helper.
Add helper to parse the NALU header. Move bounds checking to there. https://bugzilla.gnome.org/show_bug.cgi?id=685215 Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
This commit is contained in:
parent
e61ae7ffa2
commit
8dc7ab49fe
1 changed files with 18 additions and 9 deletions
|
@ -200,16 +200,20 @@ gst_h264_parser_get_pps (GstH264NalParser * nalparser, guint8 pps_id)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static gboolean
|
||||||
set_nalu_datas (GstH264NalUnit * nalu)
|
gst_h264_parse_nalu_header (GstH264NalUnit * nalu)
|
||||||
{
|
{
|
||||||
guint8 *data = nalu->data + nalu->offset;
|
guint8 *data = nalu->data + nalu->offset;
|
||||||
|
|
||||||
|
if (nalu->size < 1)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
nalu->type = (data[0] & 0x1f);
|
nalu->type = (data[0] & 0x1f);
|
||||||
nalu->ref_idc = (data[0] & 0x60) >> 5;
|
nalu->ref_idc = (data[0] & 0x60) >> 5;
|
||||||
nalu->idr_pic_flag = (nalu->type == 5 ? 1 : 0);
|
nalu->idr_pic_flag = (nalu->type == 5 ? 1 : 0);
|
||||||
|
|
||||||
GST_DEBUG ("Nal type %u, ref_idc %u", nalu->type, nalu->ref_idc);
|
GST_DEBUG ("Nal type %u, ref_idc %u", nalu->type, nalu->ref_idc);
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****** Parsing functions *****/
|
/****** Parsing functions *****/
|
||||||
|
@ -996,14 +1000,20 @@ gst_h264_parser_identify_nalu_unchecked (GstH264NalParser * nalparser,
|
||||||
return GST_H264_PARSER_ERROR;
|
return GST_H264_PARSER_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
nalu->valid = TRUE;
|
|
||||||
nalu->sc_offset = offset + off1;
|
nalu->sc_offset = offset + off1;
|
||||||
|
|
||||||
|
|
||||||
nalu->offset = offset + off1 + 3;
|
nalu->offset = offset + off1 + 3;
|
||||||
nalu->data = (guint8 *) data;
|
nalu->data = (guint8 *) data;
|
||||||
|
nalu->size = size - nalu->offset;
|
||||||
|
|
||||||
set_nalu_datas (nalu);
|
if (!gst_h264_parse_nalu_header (nalu)) {
|
||||||
|
GST_WARNING ("error parsing \"NAL unit header\"");
|
||||||
|
nalu->size = 0;
|
||||||
|
return GST_H264_PARSER_BROKEN_DATA;
|
||||||
|
}
|
||||||
|
|
||||||
|
nalu->valid = TRUE;
|
||||||
|
|
||||||
/* sc might have 2 or 3 0-bytes */
|
/* sc might have 2 or 3 0-bytes */
|
||||||
if (nalu->sc_offset > 0 && data[nalu->sc_offset - 1] == 00
|
if (nalu->sc_offset > 0 && data[nalu->sc_offset - 1] == 00
|
||||||
|
@ -1018,8 +1028,6 @@ gst_h264_parser_identify_nalu_unchecked (GstH264NalParser * nalparser,
|
||||||
return GST_H264_PARSER_OK;
|
return GST_H264_PARSER_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
nalu->size = size - nalu->offset;
|
|
||||||
|
|
||||||
return GST_H264_PARSER_OK;
|
return GST_H264_PARSER_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1115,10 +1123,11 @@ gst_h264_parser_identify_nalu_avc (GstH264NalParser * nalparser,
|
||||||
|
|
||||||
nalu->data = (guint8 *) data;
|
nalu->data = (guint8 *) data;
|
||||||
|
|
||||||
set_nalu_datas (nalu);
|
if (!gst_h264_parse_nalu_header (nalu)) {
|
||||||
|
GST_WARNING ("error parsing \"NAL unit header\"");
|
||||||
if (nalu->size < 2)
|
nalu->size = 0;
|
||||||
return GST_H264_PARSER_BROKEN_DATA;
|
return GST_H264_PARSER_BROKEN_DATA;
|
||||||
|
}
|
||||||
|
|
||||||
nalu->valid = TRUE;
|
nalu->valid = TRUE;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue