dash: Split gst_isoff_sidx_parser_add_buffer() function

To parsing sidx box itself with isobmff parser,
split gst_isoff_sidx_parser_add_buffer() into two parts.

https://bugzilla.gnome.org/show_bug.cgi?id=776200
This commit is contained in:
Seungha Yang 2016-12-17 15:56:07 +09:00 committed by Sebastian Dröge
parent ee647ca4be
commit dfa300cb6d
2 changed files with 66 additions and 45 deletions

View file

@ -379,74 +379,47 @@ gst_isoff_parse_sidx_entry (GstSidxBoxEntry * entry, GstByteReader * reader)
} }
GstIsoffParserResult GstIsoffParserResult
gst_isoff_sidx_parser_add_buffer (GstSidxParser * parser, GstBuffer * buffer, gst_isoff_sidx_parser_parse (GstSidxParser * parser,
guint * consumed) GstByteReader * reader, guint * consumed)
{ {
GstIsoffParserResult res = GST_ISOFF_PARSER_OK; GstIsoffParserResult res = GST_ISOFF_PARSER_OK;
GstByteReader reader;
GstMapInfo info;
gsize remaining; gsize remaining;
guint32 fourcc;
if (!gst_buffer_map (buffer, &info, GST_MAP_READ)) {
*consumed = 0;
return GST_ISOFF_PARSER_ERROR;
}
gst_byte_reader_init (&reader, info.data, info.size);
switch (parser->status) { switch (parser->status) {
case GST_ISOFF_SIDX_PARSER_INIT: case GST_ISOFF_SIDX_PARSER_INIT:
if (!gst_isoff_parse_box_header (&reader, &fourcc, NULL, NULL,
&parser->size))
break;
if (fourcc != GST_ISOFF_FOURCC_SIDX) {
res = GST_ISOFF_PARSER_UNEXPECTED;
gst_byte_reader_set_pos (&reader, 0);
break;
}
if (parser->size == 0) {
res = GST_ISOFF_PARSER_ERROR;
gst_byte_reader_set_pos (&reader, 0);
break;
}
/* Try again once we have enough data for the FullBox header */ /* Try again once we have enough data for the FullBox header */
if (gst_byte_reader_get_remaining (&reader) < 4) { if (gst_byte_reader_get_remaining (reader) < 4) {
gst_byte_reader_set_pos (&reader, 0); gst_byte_reader_set_pos (reader, 0);
break; break;
} }
parser->sidx.version = gst_byte_reader_get_uint8_unchecked (&reader); parser->sidx.version = gst_byte_reader_get_uint8_unchecked (reader);
parser->sidx.flags = gst_byte_reader_get_uint24_le_unchecked (&reader); parser->sidx.flags = gst_byte_reader_get_uint24_le_unchecked (reader);
parser->status = GST_ISOFF_SIDX_PARSER_HEADER; parser->status = GST_ISOFF_SIDX_PARSER_HEADER;
case GST_ISOFF_SIDX_PARSER_HEADER: case GST_ISOFF_SIDX_PARSER_HEADER:
remaining = gst_byte_reader_get_remaining (&reader); remaining = gst_byte_reader_get_remaining (reader);
if (remaining < 12 + (parser->sidx.version == 0 ? 8 : 16)) { if (remaining < 12 + (parser->sidx.version == 0 ? 8 : 16)) {
break; break;
} }
parser->sidx.ref_id = gst_byte_reader_get_uint32_be_unchecked (&reader); parser->sidx.ref_id = gst_byte_reader_get_uint32_be_unchecked (reader);
parser->sidx.timescale = parser->sidx.timescale = gst_byte_reader_get_uint32_be_unchecked (reader);
gst_byte_reader_get_uint32_be_unchecked (&reader);
if (parser->sidx.version == 0) { if (parser->sidx.version == 0) {
parser->sidx.earliest_pts = parser->sidx.earliest_pts =
gst_byte_reader_get_uint32_be_unchecked (&reader); gst_byte_reader_get_uint32_be_unchecked (reader);
parser->sidx.first_offset = parser->sidx.first_offset =
gst_byte_reader_get_uint32_be_unchecked (&reader); gst_byte_reader_get_uint32_be_unchecked (reader);
} else { } else {
parser->sidx.earliest_pts = parser->sidx.earliest_pts =
gst_byte_reader_get_uint64_be_unchecked (&reader); gst_byte_reader_get_uint64_be_unchecked (reader);
parser->sidx.first_offset = parser->sidx.first_offset =
gst_byte_reader_get_uint64_be_unchecked (&reader); gst_byte_reader_get_uint64_be_unchecked (reader);
} }
/* skip 2 reserved bytes */ /* skip 2 reserved bytes */
gst_byte_reader_skip_unchecked (&reader, 2); gst_byte_reader_skip_unchecked (reader, 2);
parser->sidx.entries_count = parser->sidx.entries_count =
gst_byte_reader_get_uint16_be_unchecked (&reader); gst_byte_reader_get_uint16_be_unchecked (reader);
GST_LOG ("Timescale: %" G_GUINT32_FORMAT, parser->sidx.timescale); GST_LOG ("Timescale: %" G_GUINT32_FORMAT, parser->sidx.timescale);
GST_LOG ("Earliest pts: %" G_GUINT64_FORMAT, parser->sidx.earliest_pts); GST_LOG ("Earliest pts: %" G_GUINT64_FORMAT, parser->sidx.earliest_pts);
@ -469,13 +442,13 @@ gst_isoff_sidx_parser_add_buffer (GstSidxParser * parser, GstBuffer * buffer,
GstSidxBoxEntry *entry = GstSidxBoxEntry *entry =
&parser->sidx.entries[parser->sidx.entry_index]; &parser->sidx.entries[parser->sidx.entry_index];
remaining = gst_byte_reader_get_remaining (&reader); remaining = gst_byte_reader_get_remaining (reader);
if (remaining < 12) if (remaining < 12)
break; break;
entry->offset = parser->cumulative_entry_size; entry->offset = parser->cumulative_entry_size;
entry->pts = parser->cumulative_pts; entry->pts = parser->cumulative_pts;
gst_isoff_parse_sidx_entry (entry, &reader); gst_isoff_parse_sidx_entry (entry, reader);
entry->duration = gst_util_uint64_scale_int_round (entry->duration, entry->duration = gst_util_uint64_scale_int_round (entry->duration,
GST_SECOND, parser->sidx.timescale); GST_SECOND, parser->sidx.timescale);
parser->cumulative_entry_size += entry->size; parser->cumulative_entry_size += entry->size;
@ -500,7 +473,54 @@ gst_isoff_sidx_parser_add_buffer (GstSidxParser * parser, GstBuffer * buffer,
break; break;
} }
*consumed = gst_byte_reader_get_pos (&reader); *consumed = gst_byte_reader_get_pos (reader);
return res;
}
GstIsoffParserResult
gst_isoff_sidx_parser_add_buffer (GstSidxParser * parser, GstBuffer * buffer,
guint * consumed)
{
GstIsoffParserResult res = GST_ISOFF_PARSER_OK;
GstByteReader reader;
GstMapInfo info;
guint32 fourcc;
if (!gst_buffer_map (buffer, &info, GST_MAP_READ)) {
*consumed = 0;
return GST_ISOFF_PARSER_ERROR;
}
gst_byte_reader_init (&reader, info.data, info.size);
if (parser->status == GST_ISOFF_SIDX_PARSER_INIT) {
if (!gst_isoff_parse_box_header (&reader, &fourcc, NULL, NULL,
&parser->size))
goto done;
if (fourcc != GST_ISOFF_FOURCC_SIDX) {
res = GST_ISOFF_PARSER_UNEXPECTED;
gst_byte_reader_set_pos (&reader, 0);
goto done;
}
if (parser->size == 0) {
res = GST_ISOFF_PARSER_ERROR;
gst_byte_reader_set_pos (&reader, 0);
goto done;
}
/* Try again once we have enough data for the FullBox header */
if (gst_byte_reader_get_remaining (&reader) < 4) {
gst_byte_reader_set_pos (&reader, 0);
goto done;
}
}
res = gst_isoff_sidx_parser_parse (parser, &reader, consumed);
done:
gst_buffer_unmap (buffer, &info); gst_buffer_unmap (buffer, &info);
return res; return res;
} }

View file

@ -187,6 +187,7 @@ typedef struct _GstSidxParser
void gst_isoff_sidx_parser_init (GstSidxParser * parser); void gst_isoff_sidx_parser_init (GstSidxParser * parser);
void gst_isoff_sidx_parser_clear (GstSidxParser * parser); void gst_isoff_sidx_parser_clear (GstSidxParser * parser);
GstIsoffParserResult gst_isoff_sidx_parser_parse (GstSidxParser * parser, GstByteReader * reader, guint * consumed);
GstIsoffParserResult gst_isoff_sidx_parser_add_buffer (GstSidxParser * parser, GstBuffer * buf, guint * consumed); GstIsoffParserResult gst_isoff_sidx_parser_add_buffer (GstSidxParser * parser, GstBuffer * buf, guint * consumed);
G_END_DECLS G_END_DECLS