Commit c4d987b6 authored by Edward Hervey's avatar Edward Hervey

codecparsers: Variant of _identify_nalu without checks

This is useful for cases where the caller *knows* that the provided
input contains a whole NALU and can therefore avoid:
* the expensive checks for the next start code (which won't be present)
* delaying the input parsing (since we would need the next incoming NALU
  in order for the parsing code to detect the next start code)

https://bugzilla.gnome.org/show_bug.cgi?id=665584
parent 9604342a
...@@ -1150,22 +1150,28 @@ gst_h264_nal_parser_free (GstH264NalParser * nalparser) ...@@ -1150,22 +1150,28 @@ gst_h264_nal_parser_free (GstH264NalParser * nalparser)
} }
/** /**
* gst_h264_parser_identify_nalu: * gst_h264_parser_identify_nalu_unchecked:
* @nalparser: a #GstH264NalParser * @nalparser: a #GstH264NalParser
* @data: The data to parse * @data: The data to parse
* @offset: the offset from which to parse @data * @offset: the offset from which to parse @data
* @size: the size of @data * @size: the size of @data
* @nalu: The #GstH264NalUnit where to store parsed nal headers * @nalu: The #GstH264NalUnit where to store parsed nal headers
* *
* Parses @data and fills @nalu from the next nalu data from @data * Parses @data and fills @nalu from the next nalu data from @data.
*
* This differs from @gst_h264_parser_identify_nalu in that it doesn't
* check whether the packet is complete or not.
*
* Note: Only use this function if you already know the provided @data
* is a complete NALU, else use @gst_h264_parser_identify_nalu.
* *
* Returns: a #GstH264ParserResult * Returns: a #GstH264ParserResult
*/ */
GstH264ParserResult GstH264ParserResult
gst_h264_parser_identify_nalu (GstH264NalParser * nalparser, gst_h264_parser_identify_nalu_unchecked (GstH264NalParser * nalparser,
const guint8 * data, guint offset, gsize size, GstH264NalUnit * nalu) const guint8 * data, guint offset, gsize size, GstH264NalUnit * nalu)
{ {
gint off1, off2; gint off1;
if (size < offset + 4) { if (size < offset + 4) {
GST_DEBUG ("Can't parse, buffer has too small size %" G_GSIZE_FORMAT GST_DEBUG ("Can't parse, buffer has too small size %" G_GSIZE_FORMAT
...@@ -1188,12 +1194,14 @@ gst_h264_parser_identify_nalu (GstH264NalParser * nalparser, ...@@ -1188,12 +1194,14 @@ gst_h264_parser_identify_nalu (GstH264NalParser * nalparser,
nalu->valid = TRUE; nalu->valid = TRUE;
nalu->sc_offset = offset + off1; nalu->sc_offset = offset + off1;
/* 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)
nalu->sc_offset--; nalu->sc_offset--;
nalu->offset = offset + off1 + 3; nalu->offset = offset + off1 + 3;
nalu->data = (guint8 *) data; nalu->data = (guint8 *) data;
set_nalu_datas (nalu); set_nalu_datas (nalu);
if (nalu->type == GST_H264_NAL_SEQ_END || if (nalu->type == GST_H264_NAL_SEQ_END ||
...@@ -1203,6 +1211,37 @@ gst_h264_parser_identify_nalu (GstH264NalParser * nalparser, ...@@ -1203,6 +1211,37 @@ gst_h264_parser_identify_nalu (GstH264NalParser * nalparser,
return GST_H264_PARSER_OK; return GST_H264_PARSER_OK;
} }
nalu->size = size - nalu->offset;
return GST_H264_PARSER_OK;
}
/**
* gst_h264_parser_identify_nalu:
* @nalparser: a #GstH264NalParser
* @data: The data to parse
* @offset: the offset from which to parse @data
* @size: the size of @data
* @nalu: The #GstH264NalUnit where to store parsed nal headers
*
* Parses @data and fills @nalu from the next nalu data from @data
*
* Returns: a #GstH264ParserResult
*/
GstH264ParserResult
gst_h264_parser_identify_nalu (GstH264NalParser * nalparser,
const guint8 * data, guint offset, gsize size, GstH264NalUnit * nalu)
{
GstH264ParserResult res;
gint off2;
res =
gst_h264_parser_identify_nalu_unchecked (nalparser, data, offset, size,
nalu);
if (res != GST_H264_PARSER_OK || nalu->size == 0)
goto beach;
off2 = scan_for_start_codes (data + nalu->offset, size - nalu->offset); off2 = scan_for_start_codes (data + nalu->offset, size - nalu->offset);
if (off2 < 0) { if (off2 < 0) {
GST_DEBUG ("Nal start %d, No end found", nalu->offset); GST_DEBUG ("Nal start %d, No end found", nalu->offset);
...@@ -1218,9 +1257,12 @@ gst_h264_parser_identify_nalu (GstH264NalParser * nalparser, ...@@ -1218,9 +1257,12 @@ gst_h264_parser_identify_nalu (GstH264NalParser * nalparser,
return GST_H264_PARSER_BROKEN_DATA; return GST_H264_PARSER_BROKEN_DATA;
GST_DEBUG ("Complete nal found. Off: %d, Size: %d", nalu->offset, nalu->size); GST_DEBUG ("Complete nal found. Off: %d, Size: %d", nalu->offset, nalu->size);
return GST_H264_PARSER_OK;
beach:
return res;
} }
/** /**
* gst_h264_parser_identify_nalu_avc: * gst_h264_parser_identify_nalu_avc:
* @nalparser: a #GstH264NalParser * @nalparser: a #GstH264NalParser
......
...@@ -678,6 +678,10 @@ GstH264ParserResult gst_h264_parser_identify_nalu (GstH264NalParser *nalpars ...@@ -678,6 +678,10 @@ GstH264ParserResult gst_h264_parser_identify_nalu (GstH264NalParser *nalpars
const guint8 *data, guint offset, const guint8 *data, guint offset,
gsize size, GstH264NalUnit *nalu); gsize size, GstH264NalUnit *nalu);
GstH264ParserResult gst_h264_parser_identify_nalu_unchecked (GstH264NalParser *nalparser,
const guint8 *data, guint offset,
gsize size, GstH264NalUnit *nalu);
GstH264ParserResult gst_h264_parser_identify_nalu_avc (GstH264NalParser *nalparser, const guint8 *data, GstH264ParserResult gst_h264_parser_identify_nalu_avc (GstH264NalParser *nalparser, const guint8 *data,
guint offset, gsize size, guint8 nal_length_size, guint offset, gsize size, guint8 nal_length_size,
GstH264NalUnit *nalu); GstH264NalUnit *nalu);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment