From 9b3f67c5b0d4533da74066512bc23613bbd00a71 Mon Sep 17 00:00:00 2001 From: Thiago Santos Date: Fri, 4 Jan 2013 15:49:02 -0300 Subject: [PATCH] mssdemux: set timestamp and duration to fragment buffers We can get those from the manifest and helps downstream to know the fragment start time after a seeking operation --- ext/smoothstreaming/gstmssdemux.c | 6 +++++ ext/smoothstreaming/gstmssmanifest.c | 36 ++++++++++++++++++++++++++++ ext/smoothstreaming/gstmssmanifest.h | 2 ++ 3 files changed, 44 insertions(+) diff --git a/ext/smoothstreaming/gstmssdemux.c b/ext/smoothstreaming/gstmssdemux.c index 75a9804511..ac4a2a4210 100644 --- a/ext/smoothstreaming/gstmssdemux.c +++ b/ext/smoothstreaming/gstmssdemux.c @@ -646,12 +646,18 @@ gst_mss_demux_stream_loop (GstMssDemuxStream * stream) buffer = gst_fragment_get_buffer (fragment); buffer = gst_buffer_make_metadata_writable (buffer); gst_buffer_set_caps (buffer, GST_PAD_CAPS (stream->pad)); + GST_BUFFER_TIMESTAMP (buffer) = + gst_mss_stream_get_fragment_gst_timestamp (stream->manifest_stream); + GST_BUFFER_DURATION (buffer) = + gst_mss_stream_get_fragment_gst_duration (stream->manifest_stream); if (G_UNLIKELY (stream->pending_newsegment)) { gst_pad_push_event (stream->pad, stream->pending_newsegment); stream->pending_newsegment = NULL; } + GST_DEBUG_OBJECT (mssdemux, "Pushing buffer of size %u on pad %s", + GST_BUFFER_SIZE (buffer), GST_PAD_NAME (stream->pad)); ret = gst_pad_push (stream->pad, buffer); switch (ret) { case GST_FLOW_UNEXPECTED: diff --git a/ext/smoothstreaming/gstmssmanifest.c b/ext/smoothstreaming/gstmssmanifest.c index 2184bd7eb4..2eb187cb45 100644 --- a/ext/smoothstreaming/gstmssmanifest.c +++ b/ext/smoothstreaming/gstmssmanifest.c @@ -562,6 +562,42 @@ gst_mss_stream_get_fragment_url (GstMssStream * stream, gchar ** url) return GST_FLOW_OK; } +GstClockTime +gst_mss_stream_get_fragment_gst_timestamp (GstMssStream * stream) +{ + guint64 time; + guint64 timescale; + GstMssStreamFragment *fragment; + + if (!stream->current_fragment) + return GST_CLOCK_TIME_NONE; + + fragment = stream->current_fragment->data; + + time = fragment->time; + timescale = gst_mss_stream_get_timescale (stream); + return (GstClockTime) gst_util_uint64_scale_round (time, GST_SECOND, + timescale); +} + +GstClockTime +gst_mss_stream_get_fragment_gst_duration (GstMssStream * stream) +{ + guint64 dur; + guint64 timescale; + GstMssStreamFragment *fragment; + + if (!stream->current_fragment) + return GST_CLOCK_TIME_NONE; + + fragment = stream->current_fragment->data; + + dur = fragment->duration; + timescale = gst_mss_stream_get_timescale (stream); + return (GstClockTime) gst_util_uint64_scale_round (dur, GST_SECOND, + timescale); +} + GstFlowReturn gst_mss_stream_advance_fragment (GstMssStream * stream) { diff --git a/ext/smoothstreaming/gstmssmanifest.h b/ext/smoothstreaming/gstmssmanifest.h index b75b60e1ae..29741a314c 100644 --- a/ext/smoothstreaming/gstmssmanifest.h +++ b/ext/smoothstreaming/gstmssmanifest.h @@ -50,6 +50,8 @@ GstMssStreamType gst_mss_stream_get_type (GstMssStream *stream); GstCaps * gst_mss_stream_get_caps (GstMssStream * stream); guint64 gst_mss_stream_get_timescale (GstMssStream * stream); GstFlowReturn gst_mss_stream_get_fragment_url (GstMssStream * stream, gchar ** url); +GstClockTime gst_mss_stream_get_fragment_gst_timestamp (GstMssStream * stream); +GstClockTime gst_mss_stream_get_fragment_gst_duration (GstMssStream * stream); GstFlowReturn gst_mss_stream_advance_fragment (GstMssStream * stream); gboolean gst_mss_stream_seek (GstMssStream * stream, guint64 time);