smoothstreaming: port to 1.0

This commit is contained in:
Thiago Santos 2013-04-16 19:35:03 -03:00
parent 001da5a239
commit 4545f4bf4e
8 changed files with 164 additions and 119 deletions

View file

@ -3,13 +3,13 @@ plugin_LTLIBRARIES = libgstsmoothstreaming.la
libgstsmoothstreaming_la_CFLAGS = $(GST_PLUGINS_BAD_CFLAGS) \ libgstsmoothstreaming_la_CFLAGS = $(GST_PLUGINS_BAD_CFLAGS) \
$(GST_PLUGINS_BASE_CFLAGS) $(GST_BASE_CFLAGS) $(GST_CFLAGS) \ $(GST_PLUGINS_BASE_CFLAGS) $(GST_BASE_CFLAGS) $(GST_CFLAGS) \
-DGST_USE_UNSTABLE_API -DGST_USE_UNSTABLE_API $(LIBXML2_CFLAGS)
libgstsmoothstreaming_la_LIBADD = \ libgstsmoothstreaming_la_LIBADD = \
$(top_builddir)/gst-libs/gst/codecparsers/libgstcodecparsers-$(GST_MAJORMINOR).la \ $(top_builddir)/gst-libs/gst/codecparsers/libgstcodecparsers-$(GST_API_VERSION).la \
$(top_builddir)/gst-libs/gst/uridownloader/libgsturidownloader-$(GST_MAJORMINOR).la \ $(top_builddir)/gst-libs/gst/uridownloader/libgsturidownloader-$(GST_API_VERSION).la \
$(GST_PLUGINS_BASE_LIBS) \ $(GST_PLUGINS_BASE_LIBS) \
-lgsttag-@GST_MAJORMINOR@ \ -lgsttag-$(GST_API_VERSION) \
$(GST_BASE_LIBS) $(GST_LIBS) $(ZLIB_LIBS) $(GST_BASE_LIBS) $(GST_LIBS) $(ZLIB_LIBS) $(LIBXML2_LIBS)
libgstsmoothstreaming_la_LDFLAGS = ${GST_PLUGIN_LDFLAGS} libgstsmoothstreaming_la_LDFLAGS = ${GST_PLUGIN_LDFLAGS}
libgstsmoothstreaming_la_SOURCES = gstsmoothstreaming-plugin.c \ libgstsmoothstreaming_la_SOURCES = gstsmoothstreaming-plugin.c \
gstmssdemux.c \ gstmssdemux.c \

View file

@ -41,7 +41,7 @@ void
gst_download_rate_init (GstDownloadRate * rate) gst_download_rate_init (GstDownloadRate * rate)
{ {
g_queue_init (&rate->queue); g_queue_init (&rate->queue);
g_static_mutex_init (&rate->mutex); g_mutex_init (&rate->mutex);
rate->total = 0; rate->total = 0;
rate->max_length = 0; rate->max_length = 0;
} }
@ -50,25 +50,25 @@ void
gst_download_rate_deinit (GstDownloadRate * rate) gst_download_rate_deinit (GstDownloadRate * rate)
{ {
gst_download_rate_clear (rate); gst_download_rate_clear (rate);
g_static_mutex_free (&rate->mutex); g_mutex_clear (&rate->mutex);
} }
void void
gst_download_rate_set_max_length (GstDownloadRate * rate, gint max_length) gst_download_rate_set_max_length (GstDownloadRate * rate, gint max_length)
{ {
g_static_mutex_lock (&rate->mutex); g_mutex_lock (&rate->mutex);
rate->max_length = max_length; rate->max_length = max_length;
_gst_download_rate_check_remove_rates (rate); _gst_download_rate_check_remove_rates (rate);
g_static_mutex_unlock (&rate->mutex); g_mutex_unlock (&rate->mutex);
} }
gint gint
gst_download_rate_get_max_length (GstDownloadRate * rate) gst_download_rate_get_max_length (GstDownloadRate * rate)
{ {
guint ret; guint ret;
g_static_mutex_lock (&rate->mutex); g_mutex_lock (&rate->mutex);
ret = rate->max_length; ret = rate->max_length;
g_static_mutex_unlock (&rate->mutex); g_mutex_unlock (&rate->mutex);
return ret; return ret;
} }
@ -76,17 +76,17 @@ gst_download_rate_get_max_length (GstDownloadRate * rate)
void void
gst_download_rate_clear (GstDownloadRate * rate) gst_download_rate_clear (GstDownloadRate * rate)
{ {
g_static_mutex_lock (&rate->mutex); g_mutex_lock (&rate->mutex);
g_queue_clear (&rate->queue); g_queue_clear (&rate->queue);
rate->total = 0; rate->total = 0;
g_static_mutex_unlock (&rate->mutex); g_mutex_unlock (&rate->mutex);
} }
void void
gst_download_rate_add_rate (GstDownloadRate * rate, guint bytes, guint64 time) gst_download_rate_add_rate (GstDownloadRate * rate, guint bytes, guint64 time)
{ {
guint64 bitrate; guint64 bitrate;
g_static_mutex_lock (&rate->mutex); g_mutex_lock (&rate->mutex);
/* convert from bytes / nanoseconds to bits per second */ /* convert from bytes / nanoseconds to bits per second */
bitrate = G_GUINT64_CONSTANT (8000000000) * bytes / time; bitrate = G_GUINT64_CONSTANT (8000000000) * bytes / time;
@ -95,19 +95,19 @@ gst_download_rate_add_rate (GstDownloadRate * rate, guint bytes, guint64 time)
rate->total += bitrate; rate->total += bitrate;
_gst_download_rate_check_remove_rates (rate); _gst_download_rate_check_remove_rates (rate);
g_static_mutex_unlock (&rate->mutex); g_mutex_unlock (&rate->mutex);
} }
guint guint
gst_download_rate_get_current_rate (GstDownloadRate * rate) gst_download_rate_get_current_rate (GstDownloadRate * rate)
{ {
guint ret; guint ret;
g_static_mutex_lock (&rate->mutex); g_mutex_lock (&rate->mutex);
if (g_queue_get_length (&rate->queue)) if (g_queue_get_length (&rate->queue))
ret = rate->total / g_queue_get_length (&rate->queue); ret = rate->total / g_queue_get_length (&rate->queue);
else else
ret = G_MAXUINT; ret = G_MAXUINT;
g_static_mutex_unlock (&rate->mutex); g_mutex_unlock (&rate->mutex);
return ret; return ret;
} }

View file

@ -33,7 +33,7 @@ typedef struct _GstDownloadRate GstDownloadRate;
struct _GstDownloadRate struct _GstDownloadRate
{ {
GQueue queue; GQueue queue;
GStaticMutex mutex; GMutex mutex;
gint max_length; gint max_length;

View file

@ -115,7 +115,8 @@ GST_STATIC_PAD_TEMPLATE ("audio_%02u",
GST_PAD_SOMETIMES, GST_PAD_SOMETIMES,
GST_STATIC_CAPS_ANY); GST_STATIC_CAPS_ANY);
GST_BOILERPLATE (GstMssDemux, gst_mss_demux, GstMssDemux, GST_TYPE_ELEMENT); #define gst_mss_demux_parent_class parent_class
G_DEFINE_TYPE (GstMssDemux, gst_mss_demux, GST_TYPE_ELEMENT);
static void gst_mss_demux_dispose (GObject * object); static void gst_mss_demux_dispose (GObject * object);
static void gst_mss_demux_set_property (GObject * object, guint prop_id, static void gst_mss_demux_set_property (GObject * object, guint prop_id,
@ -124,35 +125,20 @@ static void gst_mss_demux_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec); GValue * value, GParamSpec * pspec);
static GstStateChangeReturn gst_mss_demux_change_state (GstElement * element, static GstStateChangeReturn gst_mss_demux_change_state (GstElement * element,
GstStateChange transition); GstStateChange transition);
static GstFlowReturn gst_mss_demux_chain (GstPad * pad, GstBuffer * buffer); static GstFlowReturn gst_mss_demux_chain (GstPad * pad, GstObject * parent,
static GstFlowReturn gst_mss_demux_event (GstPad * pad, GstEvent * event); GstBuffer * buffer);
static GstFlowReturn gst_mss_demux_event (GstPad * pad, GstObject * parent,
static gboolean gst_mss_demux_src_query (GstPad * pad, GstQuery * query); GstEvent * event);
static gboolean gst_mss_demux_src_query (GstPad * pad, GstObject * parent,
GstQuery * query);
static void gst_mss_demux_download_loop (GstMssDemuxStream * stream); static void gst_mss_demux_download_loop (GstMssDemuxStream * stream);
static void gst_mss_demux_stream_loop (GstMssDemux * mssdemux); static void gst_mss_demux_stream_loop (GstMssDemux * mssdemux);
static void gst_mss_demux_stream_store_object (GstMssDemuxStream * stream,
GstMiniObject * obj);
static gboolean gst_mss_demux_process_manifest (GstMssDemux * mssdemux); static gboolean gst_mss_demux_process_manifest (GstMssDemux * mssdemux);
static void
gst_mss_demux_base_init (gpointer klass)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
gst_element_class_add_static_pad_template (element_class,
&gst_mss_demux_sink_template);
gst_element_class_add_static_pad_template (element_class,
&gst_mss_demux_videosrc_template);
gst_element_class_add_static_pad_template (element_class,
&gst_mss_demux_audiosrc_template);
gst_element_class_set_details_simple (element_class, "Smooth Streaming "
"demuxer", "Demuxer",
"Parse and demultiplex a Smooth Streaming manifest into audio and video "
"streams", "Thiago Santos <thiago.sousa.santos@collabora.com>");
GST_DEBUG_CATEGORY_INIT (mssdemux_debug, "mssdemux", 0, "mssdemux plugin");
}
static void static void
gst_mss_demux_class_init (GstMssDemuxClass * klass) gst_mss_demux_class_init (GstMssDemuxClass * klass)
{ {
@ -162,6 +148,17 @@ gst_mss_demux_class_init (GstMssDemuxClass * klass)
gobject_class = (GObjectClass *) klass; gobject_class = (GObjectClass *) klass;
gstelement_class = (GstElementClass *) klass; gstelement_class = (GstElementClass *) klass;
gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&gst_mss_demux_sink_template));
gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&gst_mss_demux_videosrc_template));
gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&gst_mss_demux_audiosrc_template));
gst_element_class_set_static_metadata (gstelement_class,
"Smooth Streaming demuxer", "Demuxer",
"Parse and demultiplex a Smooth Streaming manifest into audio and video "
"streams", "Thiago Santos <thiago.sousa.santos@collabora.com>");
gobject_class->dispose = gst_mss_demux_dispose; gobject_class->dispose = gst_mss_demux_dispose;
gobject_class->set_property = gst_mss_demux_set_property; gobject_class->set_property = gst_mss_demux_set_property;
gobject_class->get_property = gst_mss_demux_get_property; gobject_class->get_property = gst_mss_demux_get_property;
@ -187,10 +184,12 @@ gst_mss_demux_class_init (GstMssDemuxClass * klass)
gstelement_class->change_state = gstelement_class->change_state =
GST_DEBUG_FUNCPTR (gst_mss_demux_change_state); GST_DEBUG_FUNCPTR (gst_mss_demux_change_state);
GST_DEBUG_CATEGORY_INIT (mssdemux_debug, "mssdemux", 0, "mssdemux plugin");
} }
static void static void
gst_mss_demux_init (GstMssDemux * mssdemux, GstMssDemuxClass * klass) gst_mss_demux_init (GstMssDemux * mssdemux)
{ {
mssdemux->sinkpad = mssdemux->sinkpad =
gst_pad_new_from_static_template (&gst_mss_demux_sink_template, "sink"); gst_pad_new_from_static_template (&gst_mss_demux_sink_template, "sink");
@ -200,9 +199,10 @@ gst_mss_demux_init (GstMssDemux * mssdemux, GstMssDemuxClass * klass)
GST_DEBUG_FUNCPTR (gst_mss_demux_event)); GST_DEBUG_FUNCPTR (gst_mss_demux_event));
gst_element_add_pad (GST_ELEMENT_CAST (mssdemux), mssdemux->sinkpad); gst_element_add_pad (GST_ELEMENT_CAST (mssdemux), mssdemux->sinkpad);
g_static_rec_mutex_init (&mssdemux->stream_lock); g_rec_mutex_init (&mssdemux->stream_lock);
mssdemux->stream_task = mssdemux->stream_task =
gst_task_create ((GstTaskFunction) gst_mss_demux_stream_loop, mssdemux); gst_task_new ((GstTaskFunction) gst_mss_demux_stream_loop, mssdemux,
NULL);
gst_task_set_lock (mssdemux->stream_task, &mssdemux->stream_lock); gst_task_set_lock (mssdemux->stream_task, &mssdemux->stream_lock);
mssdemux->data_queue_max_size = DEFAULT_MAX_QUEUE_SIZE_BUFFERS; mssdemux->data_queue_max_size = DEFAULT_MAX_QUEUE_SIZE_BUFFERS;
@ -229,12 +229,14 @@ gst_mss_demux_stream_new (GstMssDemux * mssdemux,
stream = g_new0 (GstMssDemuxStream, 1); stream = g_new0 (GstMssDemuxStream, 1);
stream->downloader = gst_uri_downloader_new (); stream->downloader = gst_uri_downloader_new ();
stream->dataqueue = gst_data_queue_new (_data_queue_check_full, stream); stream->dataqueue =
gst_data_queue_new (_data_queue_check_full, NULL, NULL, stream);
/* Downloading task */ /* Downloading task */
g_static_rec_mutex_init (&stream->download_lock); g_rec_mutex_init (&stream->download_lock);
stream->download_task = stream->download_task =
gst_task_create ((GstTaskFunction) gst_mss_demux_download_loop, stream); gst_task_new ((GstTaskFunction) gst_mss_demux_download_loop, stream,
NULL);
gst_task_set_lock (stream->download_task, &stream->download_lock); gst_task_set_lock (stream->download_task, &stream->download_lock);
stream->pad = srcpad; stream->pad = srcpad;
@ -257,14 +259,14 @@ gst_mss_demux_stream_free (GstMssDemuxStream * stream)
GST_DEBUG_PAD_NAME (stream->pad)); GST_DEBUG_PAD_NAME (stream->pad));
gst_uri_downloader_cancel (stream->downloader); gst_uri_downloader_cancel (stream->downloader);
gst_task_stop (stream->download_task); gst_task_stop (stream->download_task);
g_static_rec_mutex_lock (&stream->download_lock); g_rec_mutex_lock (&stream->download_lock);
g_static_rec_mutex_unlock (&stream->download_lock); g_rec_mutex_unlock (&stream->download_lock);
GST_LOG_OBJECT (stream->parent, "Waiting for task to finish"); GST_LOG_OBJECT (stream->parent, "Waiting for task to finish");
gst_task_join (stream->download_task); gst_task_join (stream->download_task);
GST_LOG_OBJECT (stream->parent, "Finished"); GST_LOG_OBJECT (stream->parent, "Finished");
} }
gst_object_unref (stream->download_task); gst_object_unref (stream->download_task);
g_static_rec_mutex_free (&stream->download_lock); g_rec_mutex_clear (&stream->download_lock);
stream->download_task = NULL; stream->download_task = NULL;
} }
@ -305,8 +307,8 @@ gst_mss_demux_reset (GstMssDemux * mssdemux)
if (GST_TASK_STATE (mssdemux->stream_task) != GST_TASK_STOPPED) { if (GST_TASK_STATE (mssdemux->stream_task) != GST_TASK_STOPPED) {
gst_task_stop (mssdemux->stream_task); gst_task_stop (mssdemux->stream_task);
g_static_rec_mutex_lock (&mssdemux->stream_lock); g_rec_mutex_lock (&mssdemux->stream_lock);
g_static_rec_mutex_unlock (&mssdemux->stream_lock); g_rec_mutex_unlock (&mssdemux->stream_lock);
gst_task_join (mssdemux->stream_task); gst_task_join (mssdemux->stream_task);
} }
@ -345,7 +347,7 @@ gst_mss_demux_dispose (GObject * object)
if (mssdemux->stream_task) { if (mssdemux->stream_task) {
gst_object_unref (mssdemux->stream_task); gst_object_unref (mssdemux->stream_task);
g_static_rec_mutex_free (&mssdemux->stream_lock); g_rec_mutex_clear (&mssdemux->stream_lock);
mssdemux->stream_task = NULL; mssdemux->stream_task = NULL;
} }
@ -420,7 +422,8 @@ gst_mss_demux_change_state (GstElement * element, GstStateChange transition)
result = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition); result = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
switch (transition) { switch (transition) {
case GST_STATE_CHANGE_PAUSED_TO_READY:{ case GST_STATE_CHANGE_READY_TO_PAUSED:{
gst_segment_init (&mssdemux->segment, GST_FORMAT_TIME);
break; break;
} }
default: default:
@ -431,17 +434,17 @@ gst_mss_demux_change_state (GstElement * element, GstStateChange transition)
} }
static GstFlowReturn static GstFlowReturn
gst_mss_demux_chain (GstPad * pad, GstBuffer * buffer) gst_mss_demux_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
{ {
GstMssDemux *mssdemux = GST_MSS_DEMUX_CAST (GST_PAD_PARENT (pad)); GstMssDemux *mssdemux = GST_MSS_DEMUX_CAST (parent);
if (mssdemux->manifest_buffer == NULL) if (mssdemux->manifest_buffer == NULL)
mssdemux->manifest_buffer = buffer; mssdemux->manifest_buffer = buffer;
else else
mssdemux->manifest_buffer = mssdemux->manifest_buffer =
gst_buffer_join (mssdemux->manifest_buffer, buffer); gst_buffer_append (mssdemux->manifest_buffer, buffer);
GST_INFO_OBJECT (mssdemux, "Received manifest buffer, total size is %i bytes", GST_INFO_OBJECT (mssdemux, "Received manifest buffer, total size is %i bytes",
GST_BUFFER_SIZE (mssdemux->manifest_buffer)); gst_buffer_get_size (mssdemux->manifest_buffer));
return GST_FLOW_OK; return GST_FLOW_OK;
} }
@ -476,9 +479,9 @@ gst_mss_demux_push_src_event (GstMssDemux * mssdemux, GstEvent * event)
} }
static gboolean static gboolean
gst_mss_demux_event (GstPad * pad, GstEvent * event) gst_mss_demux_event (GstPad * pad, GstObject * parent, GstEvent * event)
{ {
GstMssDemux *mssdemux = GST_MSS_DEMUX_CAST (GST_PAD_PARENT (pad)); GstMssDemux *mssdemux = GST_MSS_DEMUX_CAST (parent);
gboolean forward = TRUE; gboolean forward = TRUE;
gboolean ret = TRUE; gboolean ret = TRUE;
@ -502,7 +505,7 @@ gst_mss_demux_event (GstPad * pad, GstEvent * event)
} }
if (forward) { if (forward) {
ret = gst_pad_event_default (pad, event); ret = gst_pad_event_default (pad, parent, event);
} else { } else {
gst_event_unref (event); gst_event_unref (event);
} }
@ -529,11 +532,11 @@ gst_mss_demux_stop_tasks (GstMssDemux * mssdemux, gboolean immediate)
for (iter = mssdemux->streams; iter; iter = g_slist_next (iter)) { for (iter = mssdemux->streams; iter; iter = g_slist_next (iter)) {
GstMssDemuxStream *stream = iter->data; GstMssDemuxStream *stream = iter->data;
g_static_rec_mutex_lock (&stream->download_lock); g_rec_mutex_lock (&stream->download_lock);
stream->cancelled = FALSE; stream->cancelled = FALSE;
stream->download_error_count = 0; stream->download_error_count = 0;
} }
g_static_rec_mutex_lock (&mssdemux->stream_lock); g_rec_mutex_lock (&mssdemux->stream_lock);
} }
static void static void
@ -543,9 +546,9 @@ gst_mss_demux_restart_tasks (GstMssDemux * mssdemux)
for (iter = mssdemux->streams; iter; iter = g_slist_next (iter)) { for (iter = mssdemux->streams; iter; iter = g_slist_next (iter)) {
GstMssDemuxStream *stream = iter->data; GstMssDemuxStream *stream = iter->data;
gst_uri_downloader_reset (stream->downloader); gst_uri_downloader_reset (stream->downloader);
g_static_rec_mutex_unlock (&stream->download_lock); g_rec_mutex_unlock (&stream->download_lock);
} }
g_static_rec_mutex_unlock (&mssdemux->stream_lock); g_rec_mutex_unlock (&mssdemux->stream_lock);
for (iter = mssdemux->streams; iter; iter = g_slist_next (iter)) { for (iter = mssdemux->streams; iter; iter = g_slist_next (iter)) {
GstMssDemuxStream *stream = iter->data; GstMssDemuxStream *stream = iter->data;
@ -556,11 +559,11 @@ gst_mss_demux_restart_tasks (GstMssDemux * mssdemux)
} }
static gboolean static gboolean
gst_mss_demux_src_event (GstPad * pad, GstEvent * event) gst_mss_demux_src_event (GstPad * pad, GstObject * parent, GstEvent * event)
{ {
GstMssDemux *mssdemux; GstMssDemux *mssdemux;
mssdemux = GST_MSS_DEMUX (GST_PAD_PARENT (pad)); mssdemux = GST_MSS_DEMUX_CAST (parent);
switch (event->type) { switch (event->type) {
case GST_EVENT_SEEK: case GST_EVENT_SEEK:
@ -572,6 +575,7 @@ gst_mss_demux_src_event (GstPad * pad, GstEvent * event)
gint64 start, stop; gint64 start, stop;
GstEvent *newsegment; GstEvent *newsegment;
GSList *iter; GSList *iter;
gboolean update;
GST_INFO_OBJECT (mssdemux, "Received GST_EVENT_SEEK"); GST_INFO_OBJECT (mssdemux, "Received GST_EVENT_SEEK");
@ -600,8 +604,10 @@ gst_mss_demux_src_event (GstPad * pad, GstEvent * event)
goto not_supported; goto not_supported;
} }
newsegment = gst_segment_do_seek (&mssdemux->segment, rate, format, flags,
gst_event_new_new_segment (FALSE, rate, format, start, stop, start); start_type, start, stop_type, stop, &update);
newsegment = gst_event_new_segment (&mssdemux->segment);
gst_event_set_seqnum (newsegment, gst_event_get_seqnum (event)); gst_event_set_seqnum (newsegment, gst_event_get_seqnum (event));
for (iter = mssdemux->streams; iter; iter = g_slist_next (iter)) { for (iter = mssdemux->streams; iter; iter = g_slist_next (iter)) {
GstMssDemuxStream *stream = iter->data; GstMssDemuxStream *stream = iter->data;
@ -613,7 +619,7 @@ gst_mss_demux_src_event (GstPad * pad, GstEvent * event)
gst_event_unref (newsegment); gst_event_unref (newsegment);
if (flags & GST_SEEK_FLAG_FLUSH) { if (flags & GST_SEEK_FLAG_FLUSH) {
GstEvent *flush = gst_event_new_flush_stop (); GstEvent *flush = gst_event_new_flush_stop (TRUE);
GST_DEBUG_OBJECT (mssdemux, "sending flush stop"); GST_DEBUG_OBJECT (mssdemux, "sending flush stop");
gst_event_set_seqnum (flush, gst_event_get_seqnum (event)); gst_event_set_seqnum (flush, gst_event_get_seqnum (event));
@ -629,7 +635,7 @@ gst_mss_demux_src_event (GstPad * pad, GstEvent * event)
break; break;
} }
return gst_pad_event_default (pad, event); return gst_pad_event_default (pad, parent, event);
not_supported: not_supported:
gst_event_unref (event); gst_event_unref (event);
@ -637,7 +643,7 @@ not_supported:
} }
static gboolean static gboolean
gst_mss_demux_src_query (GstPad * pad, GstQuery * query) gst_mss_demux_src_query (GstPad * pad, GstObject * parent, GstQuery * query)
{ {
GstMssDemux *mssdemux; GstMssDemux *mssdemux;
gboolean ret = FALSE; gboolean ret = FALSE;
@ -645,7 +651,7 @@ gst_mss_demux_src_query (GstPad * pad, GstQuery * query)
if (query == NULL) if (query == NULL)
return FALSE; return FALSE;
mssdemux = GST_MSS_DEMUX (GST_PAD_PARENT (pad)); mssdemux = GST_MSS_DEMUX (parent);
switch (query->type) { switch (query->type) {
case GST_QUERY_DURATION:{ case GST_QUERY_DURATION:{
@ -811,12 +817,13 @@ gst_mss_demux_expose_stream (GstMssDemux * mssdemux, GstMssDemuxStream * stream)
media_caps = gst_mss_stream_get_caps (stream->manifest_stream); media_caps = gst_mss_stream_get_caps (stream->manifest_stream);
if (media_caps) { if (media_caps) {
gst_pad_set_active (pad, TRUE);
caps = create_mss_caps (stream, media_caps); caps = create_mss_caps (stream, media_caps);
gst_caps_unref (media_caps); gst_caps_unref (media_caps);
gst_pad_set_caps (pad, caps); gst_pad_set_caps (pad, caps);
stream->caps = caps; stream->caps = caps;
gst_pad_set_active (pad, TRUE);
GST_INFO_OBJECT (mssdemux, "Adding srcpad %s:%s with caps %" GST_PTR_FORMAT, GST_INFO_OBJECT (mssdemux, "Adding srcpad %s:%s with caps %" GST_PTR_FORMAT,
GST_DEBUG_PAD_NAME (pad), caps); GST_DEBUG_PAD_NAME (pad), caps);
gst_object_ref (pad); gst_object_ref (pad);
@ -869,7 +876,7 @@ gst_mss_demux_process_manifest (GstMssDemux * mssdemux)
} }
GST_INFO_OBJECT (mssdemux, "Received manifest: %i bytes", GST_INFO_OBJECT (mssdemux, "Received manifest: %i bytes",
GST_BUFFER_SIZE (mssdemux->manifest_buffer)); gst_buffer_get_size (mssdemux->manifest_buffer));
mssdemux->manifest = gst_mss_manifest_new (mssdemux->manifest_buffer); mssdemux->manifest = gst_mss_manifest_new (mssdemux->manifest_buffer);
if (!mssdemux->manifest) { if (!mssdemux->manifest) {
@ -946,6 +953,7 @@ gst_mss_demux_reconfigure_stream (GstMssDemuxStream * stream)
GST_PAD_NAME (stream->pad), new_bitrate); GST_PAD_NAME (stream->pad), new_bitrate);
if (gst_mss_stream_select_bitrate (stream->manifest_stream, new_bitrate)) { if (gst_mss_stream_select_bitrate (stream->manifest_stream, new_bitrate)) {
GstEvent *capsevent;
GstCaps *caps; GstCaps *caps;
caps = gst_mss_stream_get_caps (stream->manifest_stream); caps = gst_mss_stream_get_caps (stream->manifest_stream);
@ -958,6 +966,10 @@ gst_mss_demux_reconfigure_stream (GstMssDemuxStream * stream)
"Stream %s changed bitrate to %llu caps: %" GST_PTR_FORMAT, "Stream %s changed bitrate to %llu caps: %" GST_PTR_FORMAT,
GST_PAD_NAME (stream->pad), GST_PAD_NAME (stream->pad),
gst_mss_stream_get_current_bitrate (stream->manifest_stream), caps); gst_mss_stream_get_current_bitrate (stream->manifest_stream), caps);
capsevent = gst_event_new_caps (stream->caps);
gst_mss_demux_stream_store_object (stream,
GST_MINI_OBJECT_CAST (capsevent));
} }
} }
@ -1010,12 +1022,12 @@ gst_mss_demux_stream_download_fragment (GstMssDemuxStream * stream,
switch (ret) { switch (ret) {
case GST_FLOW_OK: case GST_FLOW_OK:
break; /* all is good, let's go */ break; /* all is good, let's go */
case GST_FLOW_UNEXPECTED: /* EOS */ case GST_FLOW_EOS:
if (gst_mss_manifest_is_live (mssdemux->manifest)) { if (gst_mss_manifest_is_live (mssdemux->manifest)) {
gst_mss_demux_reload_manifest (mssdemux); gst_mss_demux_reload_manifest (mssdemux);
return GST_FLOW_OK; return GST_FLOW_OK;
} }
return GST_FLOW_UNEXPECTED; return GST_FLOW_EOS;
case GST_FLOW_ERROR: case GST_FLOW_ERROR:
goto error; goto error;
default: default:
@ -1046,8 +1058,7 @@ gst_mss_demux_stream_download_fragment (GstMssDemuxStream * stream,
} }
_buffer = gst_fragment_get_buffer (fragment); _buffer = gst_fragment_get_buffer (fragment);
_buffer = gst_buffer_make_metadata_writable (_buffer); _buffer = gst_buffer_make_writable (_buffer);
gst_buffer_set_caps (_buffer, stream->caps);
GST_BUFFER_TIMESTAMP (_buffer) = GST_BUFFER_TIMESTAMP (_buffer) =
gst_mss_stream_get_fragment_gst_timestamp (stream->manifest_stream); gst_mss_stream_get_fragment_gst_timestamp (stream->manifest_stream);
GST_BUFFER_DURATION (_buffer) = GST_BUFFER_DURATION (_buffer) =
@ -1060,13 +1071,14 @@ gst_mss_demux_stream_download_fragment (GstMssDemuxStream * stream,
after_download = g_get_real_time (); after_download = g_get_real_time ();
if (_buffer) { if (_buffer) {
guint64 bitrate = (8 * GST_BUFFER_SIZE (_buffer) * 1000000LLU) / guint64 bitrate = (8 * gst_buffer_get_size (_buffer) * 1000000LLU) /
(after_download - before_download); (after_download - before_download);
GST_DEBUG_OBJECT (mssdemux, "Measured download bitrate: %s %llu bps", GST_DEBUG_OBJECT (mssdemux, "Measured download bitrate: %s %llu bps",
GST_PAD_NAME (stream->pad), bitrate); GST_PAD_NAME (stream->pad), bitrate);
gst_download_rate_add_rate (&stream->download_rate, gst_download_rate_add_rate (&stream->download_rate,
GST_BUFFER_SIZE (_buffer), 1000 * (after_download - before_download)); gst_buffer_get_size (_buffer),
1000 * (after_download - before_download));
GST_DEBUG_OBJECT (mssdemux, GST_DEBUG_OBJECT (mssdemux,
"Storing buffer for stream %p - %s. Timestamp: %" GST_TIME_FORMAT "Storing buffer for stream %p - %s. Timestamp: %" GST_TIME_FORMAT
@ -1119,7 +1131,7 @@ gst_mss_demux_download_loop (GstMssDemuxStream * stream)
switch (ret) { switch (ret) {
case GST_FLOW_OK: case GST_FLOW_OK:
break; /* all is good, let's go */ break; /* all is good, let's go */
case GST_FLOW_UNEXPECTED: /* EOS */ case GST_FLOW_EOS:
goto eos; goto eos;
case GST_FLOW_ERROR: case GST_FLOW_ERROR:
goto error; goto error;
@ -1187,7 +1199,7 @@ gst_mss_demux_select_latest_stream (GstMssDemux * mssdemux,
if (!gst_data_queue_peek (other->dataqueue, &item)) { if (!gst_data_queue_peek (other->dataqueue, &item)) {
/* flushing */ /* flushing */
return GST_FLOW_WRONG_STATE; return GST_FLOW_FLUSHING;
} }
if (GST_IS_EVENT (item->object)) { if (GST_IS_EVENT (item->object)) {
@ -1204,7 +1216,7 @@ gst_mss_demux_select_latest_stream (GstMssDemux * mssdemux,
*stream = current; *stream = current;
if (current == NULL) if (current == NULL)
ret = GST_FLOW_UNEXPECTED; ret = GST_FLOW_EOS;
return ret; return ret;
} }
@ -1218,7 +1230,6 @@ gst_mss_demux_stream_loop (GstMssDemux * mssdemux)
GST_LOG_OBJECT (mssdemux, "Starting stream loop"); GST_LOG_OBJECT (mssdemux, "Starting stream loop");
ret = gst_mss_demux_select_latest_stream (mssdemux, &stream); ret = gst_mss_demux_select_latest_stream (mssdemux, &stream);
if (stream) if (stream)
@ -1234,9 +1245,9 @@ gst_mss_demux_stream_loop (GstMssDemux * mssdemux)
break; break;
case GST_FLOW_ERROR: case GST_FLOW_ERROR:
goto error; goto error;
case GST_FLOW_UNEXPECTED: case GST_FLOW_EOS:
goto eos; goto eos;
case GST_FLOW_WRONG_STATE: case GST_FLOW_FLUSHING:
GST_DEBUG_OBJECT (mssdemux, "Wrong state, stopping task"); GST_DEBUG_OBJECT (mssdemux, "Wrong state, stopping task");
goto stop; goto stop;
default: default:
@ -1295,7 +1306,7 @@ gst_mss_demux_stream_loop (GstMssDemux * mssdemux)
} }
switch (ret) { switch (ret) {
case GST_FLOW_UNEXPECTED: case GST_FLOW_EOS:
goto eos; /* EOS ? */ goto eos; /* EOS ? */
case GST_FLOW_ERROR: case GST_FLOW_ERROR:
goto error; goto error;

View file

@ -70,7 +70,7 @@ struct _GstMssDemuxStream {
/* Downloading task */ /* Downloading task */
GstTask *download_task; GstTask *download_task;
GStaticRecMutex download_lock; GRecMutex download_lock;
gboolean eos; gboolean eos;
gboolean have_data; gboolean have_data;
@ -93,6 +93,8 @@ struct _GstMssDemux {
gchar *base_url; gchar *base_url;
gchar *manifest_uri; gchar *manifest_uri;
GstSegment segment;
GSList *streams; GSList *streams;
guint n_videos; guint n_videos;
guint n_audios; guint n_audios;
@ -101,7 +103,7 @@ struct _GstMssDemux {
/* Streaming task */ /* Streaming task */
GstTask *stream_task; GstTask *stream_task;
GStaticRecMutex stream_lock; GRecMutex stream_lock;
/* properties */ /* properties */
guint64 connection_speed; /* in bps */ guint64 connection_speed; /* in bps */

View file

@ -216,17 +216,22 @@ _gst_mss_stream_init (GstMssStream * stream, xmlNodePtr node)
} }
GstMssManifest * GstMssManifest *
gst_mss_manifest_new (const GstBuffer * data) gst_mss_manifest_new (GstBuffer * data)
{ {
GstMssManifest *manifest; GstMssManifest *manifest;
xmlNodePtr root; xmlNodePtr root;
xmlNodePtr nodeiter; xmlNodePtr nodeiter;
gchar *live_str; gchar *live_str;
GstMapInfo mapinfo;
if (!gst_buffer_map (data, &mapinfo, GST_MAP_READ)) {
return NULL;
}
manifest = g_malloc0 (sizeof (GstMssManifest)); manifest = g_malloc0 (sizeof (GstMssManifest));
manifest->xml = xmlReadMemory ((const gchar *) GST_BUFFER_DATA (data), manifest->xml = xmlReadMemory ((const gchar *) mapinfo.data,
GST_BUFFER_SIZE (data), "manifest", NULL, 0); mapinfo.size, "manifest", NULL, 0);
root = manifest->xmlrootnode = xmlDocGetRootElement (manifest->xml); root = manifest->xmlrootnode = xmlDocGetRootElement (manifest->xml);
live_str = (gchar *) xmlGetProp (root, (xmlChar *) "IsLive"); live_str = (gchar *) xmlGetProp (root, (xmlChar *) "IsLive");
@ -245,6 +250,8 @@ gst_mss_manifest_new (const GstBuffer * data)
} }
} }
gst_buffer_unmap (data, &mapinfo);
return manifest; return manifest;
} }
@ -336,21 +343,26 @@ _make_h264_codec_data (GstBuffer * sps, GstBuffer * pps)
guint8 profile_idc = 0, profile_comp = 0, level_idc = 0; guint8 profile_idc = 0, profile_comp = 0, level_idc = 0;
guint8 *data; guint8 *data;
gint nl; gint nl;
GstMapInfo spsinfo, ppsinfo, codecdatainfo;
if (GST_BUFFER_SIZE (sps) < 4) if (gst_buffer_get_size (sps) < 4)
return NULL; return NULL;
sps_size += GST_BUFFER_SIZE (sps) + 2; gst_buffer_map (sps, &spsinfo, GST_MAP_READ);
profile_idc = GST_BUFFER_DATA (sps)[1]; gst_buffer_map (pps, &ppsinfo, GST_MAP_READ);
profile_comp = GST_BUFFER_DATA (sps)[2];
level_idc = GST_BUFFER_DATA (sps)[3]; sps_size += spsinfo.size + 2;
profile_idc = spsinfo.data[1];
profile_comp = spsinfo.data[2];
level_idc = spsinfo.data[3];
num_sps = 1; num_sps = 1;
pps_size += GST_BUFFER_SIZE (pps) + 2; pps_size += ppsinfo.size + 2;
num_pps = 1; num_pps = 1;
buf = gst_buffer_new_and_alloc (5 + 1 + sps_size + 1 + pps_size); buf = gst_buffer_new_and_alloc (5 + 1 + sps_size + 1 + pps_size);
data = GST_BUFFER_DATA (buf); gst_buffer_map (buf, &codecdatainfo, GST_MAP_WRITE);
data = codecdatainfo.data;
nl = 4; nl = 4;
data[0] = 1; /* AVC Decoder Configuration Record ver. 1 */ data[0] = 1; /* AVC Decoder Configuration Record ver. 1 */
@ -361,15 +373,19 @@ _make_h264_codec_data (GstBuffer * sps, GstBuffer * pps)
data[5] = 0xe0 | num_sps; /* number of SPSs */ data[5] = 0xe0 | num_sps; /* number of SPSs */
data += 6; data += 6;
GST_WRITE_UINT16_BE (data, GST_BUFFER_SIZE (sps)); GST_WRITE_UINT16_BE (data, spsinfo.size);
memcpy (data + 2, GST_BUFFER_DATA (sps), GST_BUFFER_SIZE (sps)); memcpy (data + 2, spsinfo.data, spsinfo.size);
data += 2 + GST_BUFFER_SIZE (sps); data += 2 + spsinfo.size;
data[0] = num_pps; data[0] = num_pps;
data++; data++;
GST_WRITE_UINT16_BE (data, GST_BUFFER_SIZE (pps)); GST_WRITE_UINT16_BE (data, ppsinfo.size);
memcpy (data + 2, GST_BUFFER_DATA (pps), GST_BUFFER_SIZE (pps)); memcpy (data + 2, ppsinfo.data, ppsinfo.size);
data += 2 + GST_BUFFER_SIZE (pps); data += 2 + ppsinfo.size;
gst_buffer_unmap (sps, &spsinfo);
gst_buffer_unmap (pps, &ppsinfo);
gst_buffer_unmap (buf, &codecdatainfo);
return buf; return buf;
} }
@ -385,6 +401,7 @@ _gst_mss_stream_add_h264_codec_data (GstCaps * caps, const gchar * codecdatastr)
GstH264NalUnit nalu; GstH264NalUnit nalu;
GstH264SPS sps_struct; GstH264SPS sps_struct;
GstH264ParserResult parseres; GstH264ParserResult parseres;
GstMapInfo spsinfo;
/* search for the sps start */ /* search for the sps start */
if (g_str_has_prefix (codecdatastr, "00000001")) { if (g_str_has_prefix (codecdatastr, "00000001")) {
@ -406,10 +423,12 @@ _gst_mss_stream_add_h264_codec_data (GstCaps * caps, const gchar * codecdatastr)
pps_str = pps_str + 8; pps_str = pps_str + 8;
pps = gst_buffer_from_hex_string (pps_str); pps = gst_buffer_from_hex_string (pps_str);
nalu.ref_idc = (GST_BUFFER_DATA (sps)[0] & 0x60) >> 5; gst_buffer_map (sps, &spsinfo, GST_MAP_READ);
nalu.ref_idc = (spsinfo.data[0] & 0x60) >> 5;
nalu.type = GST_H264_NAL_SPS; nalu.type = GST_H264_NAL_SPS;
nalu.size = GST_BUFFER_SIZE (sps); nalu.size = spsinfo.size;
nalu.data = GST_BUFFER_DATA (sps); nalu.data = spsinfo.data;
nalu.offset = 0; nalu.offset = 0;
nalu.sc_offset = 0; nalu.sc_offset = 0;
nalu.valid = TRUE; nalu.valid = TRUE;
@ -421,6 +440,7 @@ _gst_mss_stream_add_h264_codec_data (GstCaps * caps, const gchar * codecdatastr)
} }
buffer = _make_h264_codec_data (sps, pps); buffer = _make_h264_codec_data (sps, pps);
gst_buffer_unmap (sps, &spsinfo);
gst_buffer_unref (sps); gst_buffer_unref (sps);
gst_buffer_unref (pps); gst_buffer_unref (pps);
@ -502,6 +522,7 @@ _make_aacl_codec_data (guint64 sampling_rate, guint64 channels)
guint8 *data; guint8 *data;
guint8 frequency_index; guint8 frequency_index;
guint8 buf_size; guint8 buf_size;
GstMapInfo info;
buf_size = 2; buf_size = 2;
frequency_index = _frequency_index_from_sampling_rate (sampling_rate); frequency_index = _frequency_index_from_sampling_rate (sampling_rate);
@ -509,7 +530,8 @@ _make_aacl_codec_data (guint64 sampling_rate, guint64 channels)
buf_size += 3; buf_size += 3;
buf = gst_buffer_new_and_alloc (buf_size); buf = gst_buffer_new_and_alloc (buf_size);
data = GST_BUFFER_DATA (buf); gst_buffer_map (buf, &info, GST_MAP_WRITE);
data = info.data;
data[0] = 2 << 3; /* AAC-LC object type is 2 */ data[0] = 2 << 3; /* AAC-LC object type is 2 */
data[0] += frequency_index >> 1; data[0] += frequency_index >> 1;
@ -526,6 +548,8 @@ _make_aacl_codec_data (guint64 sampling_rate, guint64 channels)
data[1] += (channels & 0x0F) << 3; data[1] += (channels & 0x0F) << 3;
gst_buffer_unmap (buf, &info);
return buf; return buf;
} }
@ -690,7 +714,7 @@ gst_mss_stream_get_fragment_url (GstMssStream * stream, gchar ** url)
g_return_val_if_fail (stream->active, GST_FLOW_ERROR); g_return_val_if_fail (stream->active, GST_FLOW_ERROR);
if (stream->current_fragment == NULL) /* stream is over */ if (stream->current_fragment == NULL) /* stream is over */
return GST_FLOW_UNEXPECTED; return GST_FLOW_EOS;
fragment = stream->current_fragment->data; fragment = stream->current_fragment->data;
@ -756,11 +780,11 @@ gst_mss_stream_advance_fragment (GstMssStream * stream)
g_return_val_if_fail (stream->active, GST_FLOW_ERROR); g_return_val_if_fail (stream->active, GST_FLOW_ERROR);
if (stream->current_fragment == NULL) if (stream->current_fragment == NULL)
return GST_FLOW_UNEXPECTED; return GST_FLOW_EOS;
stream->current_fragment = g_list_next (stream->current_fragment); stream->current_fragment = g_list_next (stream->current_fragment);
if (stream->current_fragment == NULL) if (stream->current_fragment == NULL)
return GST_FLOW_UNEXPECTED; return GST_FLOW_EOS;
return GST_FLOW_OK; return GST_FLOW_OK;
} }
@ -972,16 +996,21 @@ gst_mss_manifest_reload_fragments (GstMssManifest * manifest, GstBuffer * data)
{ {
xmlDocPtr xml; xmlDocPtr xml;
xmlNodePtr root; xmlNodePtr root;
GstMapInfo info;
g_return_if_fail (manifest->is_live); g_return_if_fail (manifest->is_live);
xml = xmlReadMemory ((const gchar *) GST_BUFFER_DATA (data), gst_buffer_map (data, &info, GST_MAP_READ);
GST_BUFFER_SIZE (data), "manifest", NULL, 0);
xml = xmlReadMemory ((const gchar *) info.data,
info.size, "manifest", NULL, 0);
root = xmlDocGetRootElement (xml); root = xmlDocGetRootElement (xml);
gst_mss_manifest_reload_fragments_from_xml (manifest, root); gst_mss_manifest_reload_fragments_from_xml (manifest, root);
xmlFreeDoc (xml); xmlFreeDoc (xml);
gst_buffer_unmap (data, &info);
} }
gboolean gboolean
@ -1079,13 +1108,15 @@ gst_buffer_from_hex_string (const gchar * s)
gchar ts[3]; gchar ts[3];
guint8 *data; guint8 *data;
gint i; gint i;
GstMapInfo info;
len = strlen (s); len = strlen (s);
if (len & 1) if (len & 1)
return NULL; return NULL;
buffer = gst_buffer_new_and_alloc (len / 2); buffer = gst_buffer_new_and_alloc (len / 2);
data = GST_BUFFER_DATA (buffer); gst_buffer_map (buffer, &info, GST_MAP_WRITE);
data = info.data;
for (i = 0; i < len / 2; i++) { for (i = 0; i < len / 2; i++) {
if (!isxdigit ((int) s[i * 2]) || !isxdigit ((int) s[i * 2 + 1])) { if (!isxdigit ((int) s[i * 2]) || !isxdigit ((int) s[i * 2 + 1])) {
gst_buffer_unref (buffer); gst_buffer_unref (buffer);
@ -1099,5 +1130,6 @@ gst_buffer_from_hex_string (const gchar * s)
data[i] = (guint8) strtoul (ts, NULL, 16); data[i] = (guint8) strtoul (ts, NULL, 16);
} }
gst_buffer_unmap (buffer, &info);
return buffer; return buffer;
} }

View file

@ -38,7 +38,7 @@ typedef enum _GstMssStreamType {
MSS_STREAM_TYPE_AUDIO = 2 MSS_STREAM_TYPE_AUDIO = 2
} GstMssStreamType; } GstMssStreamType;
GstMssManifest * gst_mss_manifest_new (const GstBuffer * data); GstMssManifest * gst_mss_manifest_new (GstBuffer * data);
void gst_mss_manifest_free (GstMssManifest * manifest); void gst_mss_manifest_free (GstMssManifest * manifest);
GSList * gst_mss_manifest_get_streams (GstMssManifest * manifest); GSList * gst_mss_manifest_get_streams (GstMssManifest * manifest);
guint64 gst_mss_manifest_get_timescale (GstMssManifest * manifest); guint64 gst_mss_manifest_get_timescale (GstMssManifest * manifest);

View file

@ -43,6 +43,6 @@ plugin_init (GstPlugin * plugin)
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
GST_VERSION_MINOR, GST_VERSION_MINOR,
"smoothstreaming", smoothstreaming,
"Microsoft's Smooth Streaming format support ", "Microsoft's Smooth Streaming format support ",
plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN); plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN);