diff options
author | Sebastian Dröge <slomo@circular-chaos.org> | 2008-10-09 16:20:26 +0000 |
---|---|---|
committer | Sebastian Dröge <slomo@circular-chaos.org> | 2008-10-09 16:20:26 +0000 |
commit | 1f6ba1d28011929789612b51ddb888ca8353ceb7 (patch) | |
tree | 019b1f1d06f2b4cc0b096bd7f73f80b0a6123e2c /gst/flv/gstflvdemux.c | |
parent | d411f8d1d7d5d5da9e1213ddc9387cba88768abb (diff) | |
download | gst-plugins-bad-1f6ba1d28011929789612b51ddb888ca8353ceb7.tar.gz gst-plugins-bad-1f6ba1d28011929789612b51ddb888ca8353ceb7.tar.bz2 gst-plugins-bad-1f6ba1d28011929789612b51ddb888ca8353ceb7.zip |
gst/flv/: Get an approximate duration of the file by looking at the timestamp of the last tag in pull mode. If we get...
Original commit message from CVS:
* gst/flv/gstflvdemux.c: (gst_flv_demux_loop):
* gst/flv/gstflvparse.c: (gst_flv_parse_tag_timestamp):
* gst/flv/gstflvparse.h:
Get an approximate duration of the file by looking at the timestamp
of the last tag in pull mode. If we get (maybe better) duration from
metadata later we'll use that instead.
Diffstat (limited to 'gst/flv/gstflvdemux.c')
-rw-r--r-- | gst/flv/gstflvdemux.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/gst/flv/gstflvdemux.c b/gst/flv/gstflvdemux.c index dc148507..8cc74f1d 100644 --- a/gst/flv/gstflvdemux.c +++ b/gst/flv/gstflvdemux.c @@ -443,6 +443,38 @@ gst_flv_demux_loop (GstPad * pad) break; default: ret = gst_flv_demux_pull_header (pad, 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 */ |