summaryrefslogtreecommitdiffstats
path: root/gst/flv/gstflvdemux.c
diff options
context:
space:
mode:
authorSebastian Dröge <slomo@circular-chaos.org>2008-10-27 09:25:11 +0000
committerSebastian Dröge <slomo@circular-chaos.org>2008-10-27 09:25:11 +0000
commit2dadd8a0cccf3655ef327f4b897f19d75c176e17 (patch)
treeb9c7347854f4dc0b59368c26a9c037d26ff4eee8 /gst/flv/gstflvdemux.c
parent04795346c5da5f10dcb013d89ca4b799497e89f2 (diff)
downloadgst-plugins-bad-2dadd8a0cccf3655ef327f4b897f19d75c176e17.tar.gz
gst-plugins-bad-2dadd8a0cccf3655ef327f4b897f19d75c176e17.tar.bz2
gst-plugins-bad-2dadd8a0cccf3655ef327f4b897f19d75c176e17.zip
gst/flv/: In pull mode we create our own index before doing anything else and don't use the index provided by some fi...
Original commit message from CVS: * gst/flv/gstflvdemux.c: (gst_flv_demux_create_index), (gst_flv_demux_loop): * gst/flv/gstflvparse.c: (gst_flv_parse_tag_script), (gst_flv_parse_tag_audio), (gst_flv_parse_tag_video), (gst_flv_parse_tag_timestamp): * gst/flv/gstflvparse.h: In pull mode we create our own index before doing anything else and don't use the index provided by some files (which are more than often incorrect and cause failed seeks). For push mode we still use the index provided by the file and extend it while doing the playback.
Diffstat (limited to 'gst/flv/gstflvdemux.c')
-rw-r--r--gst/flv/gstflvdemux.c63
1 files changed, 32 insertions, 31 deletions
diff --git a/gst/flv/gstflvdemux.c b/gst/flv/gstflvdemux.c
index 8f13ef0b..6448d6a5 100644
--- a/gst/flv/gstflvdemux.c
+++ b/gst/flv/gstflvdemux.c
@@ -449,6 +449,34 @@ gst_flv_demux_push_src_event (GstFLVDemux * demux, GstEvent * event)
}
static void
+gst_flv_demux_create_index (GstFLVDemux * demux)
+{
+ gint64 size;
+ GstFormat fmt = GST_FORMAT_BYTES;
+ size_t tag_size;
+ guint64 old_offset;
+ GstBuffer *buffer;
+ GstFlowReturn ret;
+
+ if (!gst_pad_query_peer_duration (demux->sinkpad, &fmt, &size) ||
+ fmt != GST_FORMAT_BYTES)
+ return;
+
+ old_offset = demux->offset;
+
+ while ((ret =
+ gst_flv_demux_pull_range (demux, demux->sinkpad, demux->offset, 12,
+ &buffer)) == GST_FLOW_OK) {
+ if (gst_flv_parse_tag_timestamp (demux, GST_BUFFER_DATA (buffer),
+ GST_BUFFER_SIZE (buffer), &tag_size) == GST_CLOCK_TIME_NONE)
+ break;
+ demux->offset += tag_size;
+ }
+
+ demux->offset = old_offset;
+}
+
+static void
gst_flv_demux_loop (GstPad * pad)
{
GstFLVDemux *demux = NULL;
@@ -467,38 +495,9 @@ gst_flv_demux_loop (GstPad * pad)
break;
default:
ret = gst_flv_demux_pull_header (pad, demux);
+ if (ret == GST_FLOW_OK)
+ gst_flv_demux_create_index (demux);
- /* If we parsed the header successfully try to get an
- * approximate duration by looking at the last tag's timestamp */
- if (ret == GST_FLOW_OK) {
- gint64 size;
- GstFormat fmt = GST_FORMAT_BYTES;
-
- if (gst_pad_query_peer_duration (pad, &fmt, &size) &&
- fmt == GST_FORMAT_BYTES && size != -1 && size > FLV_HEADER_SIZE) {
- GstBuffer *buffer;
-
- if (gst_flv_demux_pull_range (demux, pad, size - 4, 4,
- &buffer) == GST_FLOW_OK) {
- guint32 prev_tag_size =
- GST_READ_UINT32_BE (GST_BUFFER_DATA (buffer));
-
- gst_buffer_unref (buffer);
-
- if (size - 4 - prev_tag_size > FLV_HEADER_SIZE &&
- prev_tag_size >= 8 &&
- gst_flv_demux_pull_range (demux, pad,
- size - prev_tag_size - 4, prev_tag_size,
- &buffer) == GST_FLOW_OK) {
- demux->duration =
- gst_flv_parse_tag_timestamp (demux,
- GST_BUFFER_DATA (buffer), GST_BUFFER_SIZE (buffer));
-
- gst_buffer_unref (buffer);
- }
- }
- }
- }
}
/* pause if something went wrong */
@@ -527,6 +526,8 @@ gst_flv_demux_loop (GstPad * pad)
break;
default:
ret = gst_flv_demux_pull_header (pad, demux);
+ if (ret == GST_FLOW_OK)
+ gst_flv_demux_create_index (demux);
}
/* pause if something went wrong */