mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-23 16:50:47 +00:00
smoothstreaming: port to 1.0
This commit is contained in:
parent
001da5a239
commit
4545f4bf4e
8 changed files with 164 additions and 119 deletions
|
@ -3,13 +3,13 @@ plugin_LTLIBRARIES = libgstsmoothstreaming.la
|
|||
|
||||
libgstsmoothstreaming_la_CFLAGS = $(GST_PLUGINS_BAD_CFLAGS) \
|
||||
$(GST_PLUGINS_BASE_CFLAGS) $(GST_BASE_CFLAGS) $(GST_CFLAGS) \
|
||||
-DGST_USE_UNSTABLE_API
|
||||
-DGST_USE_UNSTABLE_API $(LIBXML2_CFLAGS)
|
||||
libgstsmoothstreaming_la_LIBADD = \
|
||||
$(top_builddir)/gst-libs/gst/codecparsers/libgstcodecparsers-$(GST_MAJORMINOR).la \
|
||||
$(top_builddir)/gst-libs/gst/uridownloader/libgsturidownloader-$(GST_MAJORMINOR).la \
|
||||
$(top_builddir)/gst-libs/gst/codecparsers/libgstcodecparsers-$(GST_API_VERSION).la \
|
||||
$(top_builddir)/gst-libs/gst/uridownloader/libgsturidownloader-$(GST_API_VERSION).la \
|
||||
$(GST_PLUGINS_BASE_LIBS) \
|
||||
-lgsttag-@GST_MAJORMINOR@ \
|
||||
$(GST_BASE_LIBS) $(GST_LIBS) $(ZLIB_LIBS)
|
||||
-lgsttag-$(GST_API_VERSION) \
|
||||
$(GST_BASE_LIBS) $(GST_LIBS) $(ZLIB_LIBS) $(LIBXML2_LIBS)
|
||||
libgstsmoothstreaming_la_LDFLAGS = ${GST_PLUGIN_LDFLAGS}
|
||||
libgstsmoothstreaming_la_SOURCES = gstsmoothstreaming-plugin.c \
|
||||
gstmssdemux.c \
|
||||
|
|
|
@ -41,7 +41,7 @@ void
|
|||
gst_download_rate_init (GstDownloadRate * rate)
|
||||
{
|
||||
g_queue_init (&rate->queue);
|
||||
g_static_mutex_init (&rate->mutex);
|
||||
g_mutex_init (&rate->mutex);
|
||||
rate->total = 0;
|
||||
rate->max_length = 0;
|
||||
}
|
||||
|
@ -50,25 +50,25 @@ void
|
|||
gst_download_rate_deinit (GstDownloadRate * rate)
|
||||
{
|
||||
gst_download_rate_clear (rate);
|
||||
g_static_mutex_free (&rate->mutex);
|
||||
g_mutex_clear (&rate->mutex);
|
||||
}
|
||||
|
||||
void
|
||||
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;
|
||||
_gst_download_rate_check_remove_rates (rate);
|
||||
g_static_mutex_unlock (&rate->mutex);
|
||||
g_mutex_unlock (&rate->mutex);
|
||||
}
|
||||
|
||||
gint
|
||||
gst_download_rate_get_max_length (GstDownloadRate * rate)
|
||||
{
|
||||
guint ret;
|
||||
g_static_mutex_lock (&rate->mutex);
|
||||
g_mutex_lock (&rate->mutex);
|
||||
ret = rate->max_length;
|
||||
g_static_mutex_unlock (&rate->mutex);
|
||||
g_mutex_unlock (&rate->mutex);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -76,17 +76,17 @@ gst_download_rate_get_max_length (GstDownloadRate * rate)
|
|||
void
|
||||
gst_download_rate_clear (GstDownloadRate * rate)
|
||||
{
|
||||
g_static_mutex_lock (&rate->mutex);
|
||||
g_mutex_lock (&rate->mutex);
|
||||
g_queue_clear (&rate->queue);
|
||||
rate->total = 0;
|
||||
g_static_mutex_unlock (&rate->mutex);
|
||||
g_mutex_unlock (&rate->mutex);
|
||||
}
|
||||
|
||||
void
|
||||
gst_download_rate_add_rate (GstDownloadRate * rate, guint bytes, guint64 time)
|
||||
{
|
||||
guint64 bitrate;
|
||||
g_static_mutex_lock (&rate->mutex);
|
||||
g_mutex_lock (&rate->mutex);
|
||||
|
||||
/* convert from bytes / nanoseconds to bits per second */
|
||||
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;
|
||||
|
||||
_gst_download_rate_check_remove_rates (rate);
|
||||
g_static_mutex_unlock (&rate->mutex);
|
||||
g_mutex_unlock (&rate->mutex);
|
||||
}
|
||||
|
||||
guint
|
||||
gst_download_rate_get_current_rate (GstDownloadRate * rate)
|
||||
{
|
||||
guint ret;
|
||||
g_static_mutex_lock (&rate->mutex);
|
||||
g_mutex_lock (&rate->mutex);
|
||||
if (g_queue_get_length (&rate->queue))
|
||||
ret = rate->total / g_queue_get_length (&rate->queue);
|
||||
else
|
||||
ret = G_MAXUINT;
|
||||
g_static_mutex_unlock (&rate->mutex);
|
||||
g_mutex_unlock (&rate->mutex);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ typedef struct _GstDownloadRate GstDownloadRate;
|
|||
struct _GstDownloadRate
|
||||
{
|
||||
GQueue queue;
|
||||
GStaticMutex mutex;
|
||||
GMutex mutex;
|
||||
|
||||
gint max_length;
|
||||
|
||||
|
|
|
@ -115,7 +115,8 @@ GST_STATIC_PAD_TEMPLATE ("audio_%02u",
|
|||
GST_PAD_SOMETIMES,
|
||||
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_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);
|
||||
static GstStateChangeReturn gst_mss_demux_change_state (GstElement * element,
|
||||
GstStateChange transition);
|
||||
static GstFlowReturn gst_mss_demux_chain (GstPad * pad, GstBuffer * buffer);
|
||||
static GstFlowReturn gst_mss_demux_event (GstPad * pad, GstEvent * event);
|
||||
|
||||
static gboolean gst_mss_demux_src_query (GstPad * pad, GstQuery * query);
|
||||
static GstFlowReturn gst_mss_demux_chain (GstPad * pad, GstObject * parent,
|
||||
GstBuffer * buffer);
|
||||
static GstFlowReturn gst_mss_demux_event (GstPad * pad, GstObject * parent,
|
||||
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_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 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
|
||||
gst_mss_demux_class_init (GstMssDemuxClass * klass)
|
||||
{
|
||||
|
@ -162,6 +148,17 @@ gst_mss_demux_class_init (GstMssDemuxClass * klass)
|
|||
gobject_class = (GObjectClass *) 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->set_property = gst_mss_demux_set_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 =
|
||||
GST_DEBUG_FUNCPTR (gst_mss_demux_change_state);
|
||||
|
||||
GST_DEBUG_CATEGORY_INIT (mssdemux_debug, "mssdemux", 0, "mssdemux plugin");
|
||||
}
|
||||
|
||||
static void
|
||||
gst_mss_demux_init (GstMssDemux * mssdemux, GstMssDemuxClass * klass)
|
||||
gst_mss_demux_init (GstMssDemux * mssdemux)
|
||||
{
|
||||
mssdemux->sinkpad =
|
||||
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_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 =
|
||||
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);
|
||||
|
||||
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->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 */
|
||||
g_static_rec_mutex_init (&stream->download_lock);
|
||||
g_rec_mutex_init (&stream->download_lock);
|
||||
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);
|
||||
|
||||
stream->pad = srcpad;
|
||||
|
@ -257,14 +259,14 @@ gst_mss_demux_stream_free (GstMssDemuxStream * stream)
|
|||
GST_DEBUG_PAD_NAME (stream->pad));
|
||||
gst_uri_downloader_cancel (stream->downloader);
|
||||
gst_task_stop (stream->download_task);
|
||||
g_static_rec_mutex_lock (&stream->download_lock);
|
||||
g_static_rec_mutex_unlock (&stream->download_lock);
|
||||
g_rec_mutex_lock (&stream->download_lock);
|
||||
g_rec_mutex_unlock (&stream->download_lock);
|
||||
GST_LOG_OBJECT (stream->parent, "Waiting for task to finish");
|
||||
gst_task_join (stream->download_task);
|
||||
GST_LOG_OBJECT (stream->parent, "Finished");
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -305,8 +307,8 @@ gst_mss_demux_reset (GstMssDemux * mssdemux)
|
|||
|
||||
if (GST_TASK_STATE (mssdemux->stream_task) != GST_TASK_STOPPED) {
|
||||
gst_task_stop (mssdemux->stream_task);
|
||||
g_static_rec_mutex_lock (&mssdemux->stream_lock);
|
||||
g_static_rec_mutex_unlock (&mssdemux->stream_lock);
|
||||
g_rec_mutex_lock (&mssdemux->stream_lock);
|
||||
g_rec_mutex_unlock (&mssdemux->stream_lock);
|
||||
gst_task_join (mssdemux->stream_task);
|
||||
}
|
||||
|
||||
|
@ -345,7 +347,7 @@ gst_mss_demux_dispose (GObject * object)
|
|||
|
||||
if (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;
|
||||
}
|
||||
|
||||
|
@ -420,7 +422,8 @@ gst_mss_demux_change_state (GstElement * element, GstStateChange transition)
|
|||
result = GST_ELEMENT_CLASS (parent_class)->change_state (element, 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;
|
||||
}
|
||||
default:
|
||||
|
@ -431,17 +434,17 @@ gst_mss_demux_change_state (GstElement * element, GstStateChange transition)
|
|||
}
|
||||
|
||||
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)
|
||||
mssdemux->manifest_buffer = buffer;
|
||||
else
|
||||
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_BUFFER_SIZE (mssdemux->manifest_buffer));
|
||||
gst_buffer_get_size (mssdemux->manifest_buffer));
|
||||
|
||||
return GST_FLOW_OK;
|
||||
}
|
||||
|
@ -476,9 +479,9 @@ gst_mss_demux_push_src_event (GstMssDemux * mssdemux, GstEvent * event)
|
|||
}
|
||||
|
||||
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 ret = TRUE;
|
||||
|
||||
|
@ -502,7 +505,7 @@ gst_mss_demux_event (GstPad * pad, GstEvent * event)
|
|||
}
|
||||
|
||||
if (forward) {
|
||||
ret = gst_pad_event_default (pad, event);
|
||||
ret = gst_pad_event_default (pad, parent, event);
|
||||
} else {
|
||||
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)) {
|
||||
GstMssDemuxStream *stream = iter->data;
|
||||
g_static_rec_mutex_lock (&stream->download_lock);
|
||||
g_rec_mutex_lock (&stream->download_lock);
|
||||
stream->cancelled = FALSE;
|
||||
stream->download_error_count = 0;
|
||||
}
|
||||
g_static_rec_mutex_lock (&mssdemux->stream_lock);
|
||||
g_rec_mutex_lock (&mssdemux->stream_lock);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -543,9 +546,9 @@ gst_mss_demux_restart_tasks (GstMssDemux * mssdemux)
|
|||
for (iter = mssdemux->streams; iter; iter = g_slist_next (iter)) {
|
||||
GstMssDemuxStream *stream = iter->data;
|
||||
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)) {
|
||||
GstMssDemuxStream *stream = iter->data;
|
||||
|
||||
|
@ -556,11 +559,11 @@ gst_mss_demux_restart_tasks (GstMssDemux * mssdemux)
|
|||
}
|
||||
|
||||
static gboolean
|
||||
gst_mss_demux_src_event (GstPad * pad, GstEvent * event)
|
||||
gst_mss_demux_src_event (GstPad * pad, GstObject * parent, GstEvent * event)
|
||||
{
|
||||
GstMssDemux *mssdemux;
|
||||
|
||||
mssdemux = GST_MSS_DEMUX (GST_PAD_PARENT (pad));
|
||||
mssdemux = GST_MSS_DEMUX_CAST (parent);
|
||||
|
||||
switch (event->type) {
|
||||
case GST_EVENT_SEEK:
|
||||
|
@ -572,6 +575,7 @@ gst_mss_demux_src_event (GstPad * pad, GstEvent * event)
|
|||
gint64 start, stop;
|
||||
GstEvent *newsegment;
|
||||
GSList *iter;
|
||||
gboolean update;
|
||||
|
||||
GST_INFO_OBJECT (mssdemux, "Received GST_EVENT_SEEK");
|
||||
|
||||
|
@ -600,8 +604,10 @@ gst_mss_demux_src_event (GstPad * pad, GstEvent * event)
|
|||
goto not_supported;
|
||||
}
|
||||
|
||||
newsegment =
|
||||
gst_event_new_new_segment (FALSE, rate, format, start, stop, start);
|
||||
gst_segment_do_seek (&mssdemux->segment, rate, format, flags,
|
||||
start_type, start, stop_type, stop, &update);
|
||||
|
||||
newsegment = gst_event_new_segment (&mssdemux->segment);
|
||||
gst_event_set_seqnum (newsegment, gst_event_get_seqnum (event));
|
||||
for (iter = mssdemux->streams; iter; iter = g_slist_next (iter)) {
|
||||
GstMssDemuxStream *stream = iter->data;
|
||||
|
@ -613,7 +619,7 @@ gst_mss_demux_src_event (GstPad * pad, GstEvent * event)
|
|||
gst_event_unref (newsegment);
|
||||
|
||||
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_event_set_seqnum (flush, gst_event_get_seqnum (event));
|
||||
|
@ -629,7 +635,7 @@ gst_mss_demux_src_event (GstPad * pad, GstEvent * event)
|
|||
break;
|
||||
}
|
||||
|
||||
return gst_pad_event_default (pad, event);
|
||||
return gst_pad_event_default (pad, parent, event);
|
||||
|
||||
not_supported:
|
||||
gst_event_unref (event);
|
||||
|
@ -637,7 +643,7 @@ not_supported:
|
|||
}
|
||||
|
||||
static gboolean
|
||||
gst_mss_demux_src_query (GstPad * pad, GstQuery * query)
|
||||
gst_mss_demux_src_query (GstPad * pad, GstObject * parent, GstQuery * query)
|
||||
{
|
||||
GstMssDemux *mssdemux;
|
||||
gboolean ret = FALSE;
|
||||
|
@ -645,7 +651,7 @@ gst_mss_demux_src_query (GstPad * pad, GstQuery * query)
|
|||
if (query == NULL)
|
||||
return FALSE;
|
||||
|
||||
mssdemux = GST_MSS_DEMUX (GST_PAD_PARENT (pad));
|
||||
mssdemux = GST_MSS_DEMUX (parent);
|
||||
|
||||
switch (query->type) {
|
||||
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);
|
||||
|
||||
if (media_caps) {
|
||||
gst_pad_set_active (pad, TRUE);
|
||||
|
||||
caps = create_mss_caps (stream, media_caps);
|
||||
gst_caps_unref (media_caps);
|
||||
gst_pad_set_caps (pad, caps);
|
||||
stream->caps = caps;
|
||||
|
||||
gst_pad_set_active (pad, TRUE);
|
||||
GST_INFO_OBJECT (mssdemux, "Adding srcpad %s:%s with caps %" GST_PTR_FORMAT,
|
||||
GST_DEBUG_PAD_NAME (pad), caps);
|
||||
gst_object_ref (pad);
|
||||
|
@ -869,7 +876,7 @@ gst_mss_demux_process_manifest (GstMssDemux * mssdemux)
|
|||
}
|
||||
|
||||
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);
|
||||
if (!mssdemux->manifest) {
|
||||
|
@ -946,6 +953,7 @@ gst_mss_demux_reconfigure_stream (GstMssDemuxStream * stream)
|
|||
GST_PAD_NAME (stream->pad), new_bitrate);
|
||||
|
||||
if (gst_mss_stream_select_bitrate (stream->manifest_stream, new_bitrate)) {
|
||||
GstEvent *capsevent;
|
||||
GstCaps *caps;
|
||||
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,
|
||||
GST_PAD_NAME (stream->pad),
|
||||
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) {
|
||||
case GST_FLOW_OK:
|
||||
break; /* all is good, let's go */
|
||||
case GST_FLOW_UNEXPECTED: /* EOS */
|
||||
case GST_FLOW_EOS:
|
||||
if (gst_mss_manifest_is_live (mssdemux->manifest)) {
|
||||
gst_mss_demux_reload_manifest (mssdemux);
|
||||
return GST_FLOW_OK;
|
||||
}
|
||||
return GST_FLOW_UNEXPECTED;
|
||||
return GST_FLOW_EOS;
|
||||
case GST_FLOW_ERROR:
|
||||
goto error;
|
||||
default:
|
||||
|
@ -1046,8 +1058,7 @@ gst_mss_demux_stream_download_fragment (GstMssDemuxStream * stream,
|
|||
}
|
||||
|
||||
_buffer = gst_fragment_get_buffer (fragment);
|
||||
_buffer = gst_buffer_make_metadata_writable (_buffer);
|
||||
gst_buffer_set_caps (_buffer, stream->caps);
|
||||
_buffer = gst_buffer_make_writable (_buffer);
|
||||
GST_BUFFER_TIMESTAMP (_buffer) =
|
||||
gst_mss_stream_get_fragment_gst_timestamp (stream->manifest_stream);
|
||||
GST_BUFFER_DURATION (_buffer) =
|
||||
|
@ -1060,13 +1071,14 @@ gst_mss_demux_stream_download_fragment (GstMssDemuxStream * stream,
|
|||
|
||||
after_download = g_get_real_time ();
|
||||
if (_buffer) {
|
||||
guint64 bitrate = (8 * GST_BUFFER_SIZE (_buffer) * 1000000LLU) /
|
||||
guint64 bitrate = (8 * gst_buffer_get_size (_buffer) * 1000000LLU) /
|
||||
(after_download - before_download);
|
||||
|
||||
GST_DEBUG_OBJECT (mssdemux, "Measured download bitrate: %s %llu bps",
|
||||
GST_PAD_NAME (stream->pad), bitrate);
|
||||
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,
|
||||
"Storing buffer for stream %p - %s. Timestamp: %" GST_TIME_FORMAT
|
||||
|
@ -1119,7 +1131,7 @@ gst_mss_demux_download_loop (GstMssDemuxStream * stream)
|
|||
switch (ret) {
|
||||
case GST_FLOW_OK:
|
||||
break; /* all is good, let's go */
|
||||
case GST_FLOW_UNEXPECTED: /* EOS */
|
||||
case GST_FLOW_EOS:
|
||||
goto eos;
|
||||
case GST_FLOW_ERROR:
|
||||
goto error;
|
||||
|
@ -1187,7 +1199,7 @@ gst_mss_demux_select_latest_stream (GstMssDemux * mssdemux,
|
|||
|
||||
if (!gst_data_queue_peek (other->dataqueue, &item)) {
|
||||
/* flushing */
|
||||
return GST_FLOW_WRONG_STATE;
|
||||
return GST_FLOW_FLUSHING;
|
||||
}
|
||||
|
||||
if (GST_IS_EVENT (item->object)) {
|
||||
|
@ -1204,7 +1216,7 @@ gst_mss_demux_select_latest_stream (GstMssDemux * mssdemux,
|
|||
|
||||
*stream = current;
|
||||
if (current == NULL)
|
||||
ret = GST_FLOW_UNEXPECTED;
|
||||
ret = GST_FLOW_EOS;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -1218,7 +1230,6 @@ gst_mss_demux_stream_loop (GstMssDemux * mssdemux)
|
|||
|
||||
GST_LOG_OBJECT (mssdemux, "Starting stream loop");
|
||||
|
||||
|
||||
ret = gst_mss_demux_select_latest_stream (mssdemux, &stream);
|
||||
|
||||
if (stream)
|
||||
|
@ -1234,9 +1245,9 @@ gst_mss_demux_stream_loop (GstMssDemux * mssdemux)
|
|||
break;
|
||||
case GST_FLOW_ERROR:
|
||||
goto error;
|
||||
case GST_FLOW_UNEXPECTED:
|
||||
case GST_FLOW_EOS:
|
||||
goto eos;
|
||||
case GST_FLOW_WRONG_STATE:
|
||||
case GST_FLOW_FLUSHING:
|
||||
GST_DEBUG_OBJECT (mssdemux, "Wrong state, stopping task");
|
||||
goto stop;
|
||||
default:
|
||||
|
@ -1295,7 +1306,7 @@ gst_mss_demux_stream_loop (GstMssDemux * mssdemux)
|
|||
}
|
||||
|
||||
switch (ret) {
|
||||
case GST_FLOW_UNEXPECTED:
|
||||
case GST_FLOW_EOS:
|
||||
goto eos; /* EOS ? */
|
||||
case GST_FLOW_ERROR:
|
||||
goto error;
|
||||
|
|
|
@ -70,7 +70,7 @@ struct _GstMssDemuxStream {
|
|||
|
||||
/* Downloading task */
|
||||
GstTask *download_task;
|
||||
GStaticRecMutex download_lock;
|
||||
GRecMutex download_lock;
|
||||
|
||||
gboolean eos;
|
||||
gboolean have_data;
|
||||
|
@ -93,6 +93,8 @@ struct _GstMssDemux {
|
|||
gchar *base_url;
|
||||
gchar *manifest_uri;
|
||||
|
||||
GstSegment segment;
|
||||
|
||||
GSList *streams;
|
||||
guint n_videos;
|
||||
guint n_audios;
|
||||
|
@ -101,7 +103,7 @@ struct _GstMssDemux {
|
|||
|
||||
/* Streaming task */
|
||||
GstTask *stream_task;
|
||||
GStaticRecMutex stream_lock;
|
||||
GRecMutex stream_lock;
|
||||
|
||||
/* properties */
|
||||
guint64 connection_speed; /* in bps */
|
||||
|
|
|
@ -216,17 +216,22 @@ _gst_mss_stream_init (GstMssStream * stream, xmlNodePtr node)
|
|||
}
|
||||
|
||||
GstMssManifest *
|
||||
gst_mss_manifest_new (const GstBuffer * data)
|
||||
gst_mss_manifest_new (GstBuffer * data)
|
||||
{
|
||||
GstMssManifest *manifest;
|
||||
xmlNodePtr root;
|
||||
xmlNodePtr nodeiter;
|
||||
gchar *live_str;
|
||||
GstMapInfo mapinfo;
|
||||
|
||||
if (!gst_buffer_map (data, &mapinfo, GST_MAP_READ)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
manifest = g_malloc0 (sizeof (GstMssManifest));
|
||||
|
||||
manifest->xml = xmlReadMemory ((const gchar *) GST_BUFFER_DATA (data),
|
||||
GST_BUFFER_SIZE (data), "manifest", NULL, 0);
|
||||
manifest->xml = xmlReadMemory ((const gchar *) mapinfo.data,
|
||||
mapinfo.size, "manifest", NULL, 0);
|
||||
root = manifest->xmlrootnode = xmlDocGetRootElement (manifest->xml);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -336,21 +343,26 @@ _make_h264_codec_data (GstBuffer * sps, GstBuffer * pps)
|
|||
guint8 profile_idc = 0, profile_comp = 0, level_idc = 0;
|
||||
guint8 *data;
|
||||
gint nl;
|
||||
GstMapInfo spsinfo, ppsinfo, codecdatainfo;
|
||||
|
||||
if (GST_BUFFER_SIZE (sps) < 4)
|
||||
if (gst_buffer_get_size (sps) < 4)
|
||||
return NULL;
|
||||
|
||||
sps_size += GST_BUFFER_SIZE (sps) + 2;
|
||||
profile_idc = GST_BUFFER_DATA (sps)[1];
|
||||
profile_comp = GST_BUFFER_DATA (sps)[2];
|
||||
level_idc = GST_BUFFER_DATA (sps)[3];
|
||||
gst_buffer_map (sps, &spsinfo, GST_MAP_READ);
|
||||
gst_buffer_map (pps, &ppsinfo, GST_MAP_READ);
|
||||
|
||||
sps_size += spsinfo.size + 2;
|
||||
profile_idc = spsinfo.data[1];
|
||||
profile_comp = spsinfo.data[2];
|
||||
level_idc = spsinfo.data[3];
|
||||
num_sps = 1;
|
||||
|
||||
pps_size += GST_BUFFER_SIZE (pps) + 2;
|
||||
pps_size += ppsinfo.size + 2;
|
||||
num_pps = 1;
|
||||
|
||||
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;
|
||||
|
||||
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 += 6;
|
||||
GST_WRITE_UINT16_BE (data, GST_BUFFER_SIZE (sps));
|
||||
memcpy (data + 2, GST_BUFFER_DATA (sps), GST_BUFFER_SIZE (sps));
|
||||
data += 2 + GST_BUFFER_SIZE (sps);
|
||||
GST_WRITE_UINT16_BE (data, spsinfo.size);
|
||||
memcpy (data + 2, spsinfo.data, spsinfo.size);
|
||||
data += 2 + spsinfo.size;
|
||||
|
||||
data[0] = num_pps;
|
||||
data++;
|
||||
GST_WRITE_UINT16_BE (data, GST_BUFFER_SIZE (pps));
|
||||
memcpy (data + 2, GST_BUFFER_DATA (pps), GST_BUFFER_SIZE (pps));
|
||||
data += 2 + GST_BUFFER_SIZE (pps);
|
||||
GST_WRITE_UINT16_BE (data, ppsinfo.size);
|
||||
memcpy (data + 2, ppsinfo.data, ppsinfo.size);
|
||||
data += 2 + ppsinfo.size;
|
||||
|
||||
gst_buffer_unmap (sps, &spsinfo);
|
||||
gst_buffer_unmap (pps, &ppsinfo);
|
||||
gst_buffer_unmap (buf, &codecdatainfo);
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
@ -385,6 +401,7 @@ _gst_mss_stream_add_h264_codec_data (GstCaps * caps, const gchar * codecdatastr)
|
|||
GstH264NalUnit nalu;
|
||||
GstH264SPS sps_struct;
|
||||
GstH264ParserResult parseres;
|
||||
GstMapInfo spsinfo;
|
||||
|
||||
/* search for the sps start */
|
||||
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 = 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.size = GST_BUFFER_SIZE (sps);
|
||||
nalu.data = GST_BUFFER_DATA (sps);
|
||||
nalu.size = spsinfo.size;
|
||||
nalu.data = spsinfo.data;
|
||||
nalu.offset = 0;
|
||||
nalu.sc_offset = 0;
|
||||
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);
|
||||
gst_buffer_unmap (sps, &spsinfo);
|
||||
gst_buffer_unref (sps);
|
||||
gst_buffer_unref (pps);
|
||||
|
||||
|
@ -502,6 +522,7 @@ _make_aacl_codec_data (guint64 sampling_rate, guint64 channels)
|
|||
guint8 *data;
|
||||
guint8 frequency_index;
|
||||
guint8 buf_size;
|
||||
GstMapInfo info;
|
||||
|
||||
buf_size = 2;
|
||||
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 = 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] += frequency_index >> 1;
|
||||
|
@ -526,6 +548,8 @@ _make_aacl_codec_data (guint64 sampling_rate, guint64 channels)
|
|||
|
||||
data[1] += (channels & 0x0F) << 3;
|
||||
|
||||
gst_buffer_unmap (buf, &info);
|
||||
|
||||
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);
|
||||
|
||||
if (stream->current_fragment == NULL) /* stream is over */
|
||||
return GST_FLOW_UNEXPECTED;
|
||||
return GST_FLOW_EOS;
|
||||
|
||||
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);
|
||||
|
||||
if (stream->current_fragment == NULL)
|
||||
return GST_FLOW_UNEXPECTED;
|
||||
return GST_FLOW_EOS;
|
||||
|
||||
stream->current_fragment = g_list_next (stream->current_fragment);
|
||||
if (stream->current_fragment == NULL)
|
||||
return GST_FLOW_UNEXPECTED;
|
||||
return GST_FLOW_EOS;
|
||||
return GST_FLOW_OK;
|
||||
}
|
||||
|
||||
|
@ -972,16 +996,21 @@ gst_mss_manifest_reload_fragments (GstMssManifest * manifest, GstBuffer * data)
|
|||
{
|
||||
xmlDocPtr xml;
|
||||
xmlNodePtr root;
|
||||
GstMapInfo info;
|
||||
|
||||
g_return_if_fail (manifest->is_live);
|
||||
|
||||
xml = xmlReadMemory ((const gchar *) GST_BUFFER_DATA (data),
|
||||
GST_BUFFER_SIZE (data), "manifest", NULL, 0);
|
||||
gst_buffer_map (data, &info, GST_MAP_READ);
|
||||
|
||||
xml = xmlReadMemory ((const gchar *) info.data,
|
||||
info.size, "manifest", NULL, 0);
|
||||
root = xmlDocGetRootElement (xml);
|
||||
|
||||
gst_mss_manifest_reload_fragments_from_xml (manifest, root);
|
||||
|
||||
xmlFreeDoc (xml);
|
||||
|
||||
gst_buffer_unmap (data, &info);
|
||||
}
|
||||
|
||||
gboolean
|
||||
|
@ -1079,13 +1108,15 @@ gst_buffer_from_hex_string (const gchar * s)
|
|||
gchar ts[3];
|
||||
guint8 *data;
|
||||
gint i;
|
||||
GstMapInfo info;
|
||||
|
||||
len = strlen (s);
|
||||
if (len & 1)
|
||||
return NULL;
|
||||
|
||||
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++) {
|
||||
if (!isxdigit ((int) s[i * 2]) || !isxdigit ((int) s[i * 2 + 1])) {
|
||||
gst_buffer_unref (buffer);
|
||||
|
@ -1099,5 +1130,6 @@ gst_buffer_from_hex_string (const gchar * s)
|
|||
data[i] = (guint8) strtoul (ts, NULL, 16);
|
||||
}
|
||||
|
||||
gst_buffer_unmap (buffer, &info);
|
||||
return buffer;
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ typedef enum _GstMssStreamType {
|
|||
MSS_STREAM_TYPE_AUDIO = 2
|
||||
} GstMssStreamType;
|
||||
|
||||
GstMssManifest * gst_mss_manifest_new (const GstBuffer * data);
|
||||
GstMssManifest * gst_mss_manifest_new (GstBuffer * data);
|
||||
void gst_mss_manifest_free (GstMssManifest * manifest);
|
||||
GSList * gst_mss_manifest_get_streams (GstMssManifest * manifest);
|
||||
guint64 gst_mss_manifest_get_timescale (GstMssManifest * manifest);
|
||||
|
|
|
@ -43,6 +43,6 @@ plugin_init (GstPlugin * plugin)
|
|||
|
||||
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
||||
GST_VERSION_MINOR,
|
||||
"smoothstreaming",
|
||||
smoothstreaming,
|
||||
"Microsoft's Smooth Streaming format support ",
|
||||
plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN);
|
||||
|
|
Loading…
Reference in a new issue