mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-23 14:36:24 +00:00
matroskademux: add support for skipping invalid data in push mode
https://bugzilla.gnome.org/show_bug.cgi?id=774566
This commit is contained in:
parent
20ed9e8237
commit
0ef3a71b89
1 changed files with 40 additions and 5 deletions
|
@ -87,6 +87,7 @@ enum
|
|||
};
|
||||
|
||||
#define DEFAULT_MAX_GAP_TIME (2 * GST_SECOND)
|
||||
#define INVALID_DATA_THRESHOLD (2 * 1024 * 1024)
|
||||
|
||||
static GstStaticPadTemplate sink_templ = GST_STATIC_PAD_TEMPLATE ("sink",
|
||||
GST_PAD_SINK,
|
||||
|
@ -4375,8 +4376,21 @@ gst_matroska_demux_parse_id (GstMatroskaDemux * demux, guint32 id,
|
|||
break;
|
||||
case GST_MATROSKA_READ_STATE_SCANNING:
|
||||
if (id != GST_MATROSKA_ID_CLUSTER &&
|
||||
id != GST_MATROSKA_ID_CLUSTERTIMECODE)
|
||||
id != GST_MATROSKA_ID_CLUSTERTIMECODE) {
|
||||
if (demux->common.start_resync_offset != -1) {
|
||||
/* we need to skip byte per byte if we are scanning for a new cluster
|
||||
* after invalid data is found
|
||||
*/
|
||||
read = 1;
|
||||
}
|
||||
goto skip;
|
||||
} else {
|
||||
if (demux->common.start_resync_offset != -1) {
|
||||
GST_LOG_OBJECT (demux, "Resync done, new cluster found!");
|
||||
demux->common.start_resync_offset = -1;
|
||||
demux->common.state = demux->common.state_to_restore;
|
||||
}
|
||||
}
|
||||
/* fall-through */
|
||||
case GST_MATROSKA_READ_STATE_HEADER:
|
||||
case GST_MATROSKA_READ_STATE_DATA:
|
||||
|
@ -4831,10 +4845,30 @@ next:
|
|||
if (G_UNLIKELY (ret != GST_FLOW_OK && ret != GST_FLOW_EOS)) {
|
||||
if (demux->common.ebml_segment_length != G_MAXUINT64
|
||||
&& demux->common.offset >=
|
||||
demux->common.ebml_segment_start + demux->common.ebml_segment_length)
|
||||
ret = GST_FLOW_EOS;
|
||||
demux->common.ebml_segment_start + demux->common.ebml_segment_length) {
|
||||
return GST_FLOW_OK;
|
||||
} else {
|
||||
gint64 bytes_scanned;
|
||||
if (demux->common.start_resync_offset == -1) {
|
||||
demux->common.start_resync_offset = demux->common.offset;
|
||||
demux->common.state_to_restore = demux->common.state;
|
||||
}
|
||||
bytes_scanned = demux->common.offset - demux->common.start_resync_offset;
|
||||
if (bytes_scanned <= INVALID_DATA_THRESHOLD) {
|
||||
GST_WARNING_OBJECT (demux,
|
||||
"parse error, looking for next cluster, actual offset %"
|
||||
G_GUINT64_FORMAT ", start resync offset %" G_GUINT64_FORMAT,
|
||||
demux->common.offset, demux->common.start_resync_offset);
|
||||
demux->common.state = GST_MATROSKA_READ_STATE_SCANNING;
|
||||
ret = GST_FLOW_OK;
|
||||
} else {
|
||||
GST_WARNING_OBJECT (demux,
|
||||
"unrecoverable parse error, next cluster not found and threshold "
|
||||
"exceeded, bytes scanned %" G_GINT64_FORMAT, bytes_scanned);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GST_LOG_OBJECT (demux, "Offset %" G_GUINT64_FORMAT ", Element id 0x%x, "
|
||||
"size %" G_GUINT64_FORMAT ", needed %d, available %d",
|
||||
|
@ -4927,7 +4961,8 @@ gst_matroska_demux_handle_sink_event (GstPad * pad, GstObject * parent,
|
|||
}
|
||||
case GST_EVENT_EOS:
|
||||
{
|
||||
if (demux->common.state != GST_MATROSKA_READ_STATE_DATA) {
|
||||
if (demux->common.state != GST_MATROSKA_READ_STATE_DATA
|
||||
&& demux->common.state != GST_MATROSKA_READ_STATE_SCANNING) {
|
||||
gst_event_unref (event);
|
||||
GST_ELEMENT_ERROR (demux, STREAM, DEMUX,
|
||||
(NULL), ("got eos and didn't receive a complete header object"));
|
||||
|
|
Loading…
Reference in a new issue