2012-11-08 19:06:44 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2012 Smart TV Alliance
|
|
|
|
* Author: Thiago Sousa Santos <thiago.sousa.santos@collabora.com>, Collabora Ltd.
|
|
|
|
*
|
|
|
|
* gstmssdemux.c:
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:element-mssdemux
|
|
|
|
*
|
|
|
|
* Demuxes a Microsoft's Smooth Streaming manifest into its audio and/or video streams.
|
|
|
|
*
|
2013-01-26 00:24:56 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* == Internals
|
|
|
|
*
|
|
|
|
* = Smooth streaming in a few lines
|
|
|
|
* A SS stream is defined by a xml manifest file. This file has a list of
|
|
|
|
* tracks (StreamIndex), each one can have multiple QualityLevels, that define
|
|
|
|
* different encoding/bitrates. When playing a track, only one of those
|
|
|
|
* QualityLevels can be active at a time (per stream).
|
|
|
|
*
|
|
|
|
* The StreamIndex defines a URL with {time} and {bitrate} tags that are
|
|
|
|
* replaced by values indicated by the fragment start times and the selected
|
|
|
|
* QualityLevel, that generates the fragments URLs.
|
|
|
|
*
|
|
|
|
* Another relevant detail is that the Isomedia fragments for smoothstreaming
|
|
|
|
* won't contains a 'moov' atom, nor a 'stsd', so there is no information
|
|
|
|
* about the media type/configuration on the fragments, it must be extracted
|
|
|
|
* from the Manifest and passed downstream. mssdemux does this via GstCaps.
|
|
|
|
*
|
|
|
|
* = How mssdemux works
|
|
|
|
* There is a gstmssmanifest.c utility that holds the manifest and parses
|
|
|
|
* and has functions to extract information from it. mssdemux received the
|
|
|
|
* manifest from its sink pad and starts processing it when it gets EOS.
|
|
|
|
*
|
|
|
|
* The Manifest is parsed and the streams are exposed, 1 pad for each, with
|
|
|
|
* a initially selected QualityLevel. Each stream starts its own GstTaks that
|
2013-12-20 03:39:34 +00:00
|
|
|
* is responsible for downloading fragments and pushing them downstream.
|
2013-01-26 00:24:56 +00:00
|
|
|
*
|
|
|
|
* When a new connection-speed is set, mssdemux evaluates the available
|
|
|
|
* QualityLevels and might decide to switch to another one. In this case it
|
2013-12-20 03:39:34 +00:00
|
|
|
* pushes a new GstCaps event indicating the new caps on the pads.
|
|
|
|
*
|
|
|
|
* All operations that intend to update the GstTasks state should be protected
|
|
|
|
* with the GST_OBJECT_LOCK.
|
2012-11-08 19:06:44 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "gst/gst-i18n-plugin.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "gstmssdemux.h"
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY (mssdemux_debug);
|
|
|
|
|
2013-01-08 21:01:17 +00:00
|
|
|
#define DEFAULT_CONNECTION_SPEED 0
|
2013-01-22 20:33:41 +00:00
|
|
|
#define DEFAULT_MAX_QUEUE_SIZE_BUFFERS 0
|
2013-02-05 03:28:19 +00:00
|
|
|
#define DEFAULT_BITRATE_LIMIT 0.8
|
2013-01-08 21:01:17 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
|
|
|
|
PROP_CONNECTION_SPEED,
|
2013-01-22 20:33:41 +00:00
|
|
|
PROP_MAX_QUEUE_SIZE_BUFFERS,
|
2013-02-05 03:28:19 +00:00
|
|
|
PROP_BITRATE_LIMIT,
|
2013-01-08 21:01:17 +00:00
|
|
|
PROP_LAST
|
|
|
|
};
|
|
|
|
|
2012-11-08 19:06:44 +00:00
|
|
|
static GstStaticPadTemplate gst_mss_demux_sink_template =
|
|
|
|
GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("application/vnd.ms-sstr+xml")
|
|
|
|
);
|
|
|
|
|
|
|
|
static GstStaticPadTemplate gst_mss_demux_videosrc_template =
|
|
|
|
GST_STATIC_PAD_TEMPLATE ("video_%02u",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_SOMETIMES,
|
|
|
|
GST_STATIC_CAPS_ANY);
|
|
|
|
|
|
|
|
static GstStaticPadTemplate gst_mss_demux_audiosrc_template =
|
|
|
|
GST_STATIC_PAD_TEMPLATE ("audio_%02u",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_SOMETIMES,
|
|
|
|
GST_STATIC_CAPS_ANY);
|
|
|
|
|
2013-04-16 22:35:03 +00:00
|
|
|
#define gst_mss_demux_parent_class parent_class
|
2014-11-22 04:01:50 +00:00
|
|
|
G_DEFINE_TYPE (GstMssDemux, gst_mss_demux, GST_TYPE_ADAPTIVE_DEMUX);
|
2012-11-08 19:06:44 +00:00
|
|
|
|
|
|
|
static void gst_mss_demux_dispose (GObject * object);
|
2013-01-08 21:01:17 +00:00
|
|
|
static void gst_mss_demux_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_mss_demux_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
2012-12-26 19:19:14 +00:00
|
|
|
|
2014-11-22 04:01:50 +00:00
|
|
|
static gboolean gst_mss_demux_is_live (GstAdaptiveDemux * demux);
|
|
|
|
static gboolean gst_mss_demux_process_manifest (GstAdaptiveDemux * demux,
|
|
|
|
GstBuffer * buffer);
|
|
|
|
static GstClockTime gst_mss_demux_get_duration (GstAdaptiveDemux * demux);
|
|
|
|
static void gst_mss_demux_reset (GstAdaptiveDemux * demux);
|
|
|
|
static GstFlowReturn gst_mss_demux_stream_seek (GstAdaptiveDemuxStream * stream,
|
|
|
|
GstClockTime ts);
|
2014-12-04 04:46:43 +00:00
|
|
|
static gboolean
|
|
|
|
gst_mss_demux_stream_has_next_fragment (GstAdaptiveDemuxStream * stream);
|
2014-11-22 04:01:50 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
gst_mss_demux_stream_advance_fragment (GstAdaptiveDemuxStream * stream);
|
|
|
|
static gboolean gst_mss_demux_stream_select_bitrate (GstAdaptiveDemuxStream *
|
|
|
|
stream, guint64 bitrate);
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_mss_demux_stream_update_fragment_info (GstAdaptiveDemuxStream * stream);
|
|
|
|
static gboolean gst_mss_demux_seek (GstAdaptiveDemux * demux, GstEvent * seek);
|
2014-12-04 04:46:43 +00:00
|
|
|
static gint64
|
|
|
|
gst_mss_demux_get_manifest_update_interval (GstAdaptiveDemux * demux);
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_mss_demux_update_manifest (GstAdaptiveDemux * demux, GstBuffer * buffer);
|
2012-11-08 19:06:44 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gst_mss_demux_class_init (GstMssDemuxClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
2014-11-22 04:01:50 +00:00
|
|
|
GstAdaptiveDemuxClass *gstadaptivedemux_class;
|
2012-11-08 19:06:44 +00:00
|
|
|
|
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gstelement_class = (GstElementClass *) klass;
|
2014-11-22 04:01:50 +00:00
|
|
|
gstadaptivedemux_class = (GstAdaptiveDemuxClass *) klass;
|
2012-11-08 19:06:44 +00:00
|
|
|
|
2013-04-16 22:35:03 +00:00
|
|
|
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,
|
2014-02-20 14:09:36 +00:00
|
|
|
"Smooth Streaming demuxer", "Codec/Demuxer/Adaptive",
|
2013-04-16 22:35:03 +00:00
|
|
|
"Parse and demultiplex a Smooth Streaming manifest into audio and video "
|
|
|
|
"streams", "Thiago Santos <thiago.sousa.santos@collabora.com>");
|
|
|
|
|
2012-11-08 19:06:44 +00:00
|
|
|
gobject_class->dispose = gst_mss_demux_dispose;
|
2013-01-08 21:01:17 +00:00
|
|
|
gobject_class->set_property = gst_mss_demux_set_property;
|
|
|
|
gobject_class->get_property = gst_mss_demux_get_property;
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_CONNECTION_SPEED,
|
2013-01-10 18:16:36 +00:00
|
|
|
g_param_spec_uint ("connection-speed", "Connection Speed",
|
2013-01-08 21:01:17 +00:00
|
|
|
"Network connection speed in kbps (0 = unknown)",
|
2013-01-10 18:16:36 +00:00
|
|
|
0, G_MAXUINT / 1000, DEFAULT_CONNECTION_SPEED,
|
2013-01-08 21:01:17 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2012-11-08 19:06:44 +00:00
|
|
|
|
2014-11-02 17:18:12 +00:00
|
|
|
#ifndef GST_REMOVE_DEPRECATED
|
2013-01-22 20:33:41 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_MAX_QUEUE_SIZE_BUFFERS,
|
|
|
|
g_param_spec_uint ("max-queue-size-buffers", "Max queue size in buffers",
|
|
|
|
"Maximum buffers that can be stored in each internal stream queue "
|
2014-05-12 17:23:15 +00:00
|
|
|
"(0 = infinite) (deprecated)", 0, G_MAXUINT,
|
|
|
|
DEFAULT_MAX_QUEUE_SIZE_BUFFERS,
|
2014-11-02 17:18:12 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_DEPRECATED));
|
|
|
|
#endif
|
2013-01-22 20:33:41 +00:00
|
|
|
|
2013-02-05 03:28:19 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_BITRATE_LIMIT,
|
|
|
|
g_param_spec_float ("bitrate-limit",
|
|
|
|
"Bitrate limit in %",
|
|
|
|
"Limit of the available bitrate to use when switching to alternates.",
|
|
|
|
0, 1, DEFAULT_BITRATE_LIMIT,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2014-11-22 04:01:50 +00:00
|
|
|
gstadaptivedemux_class->process_manifest = gst_mss_demux_process_manifest;
|
|
|
|
gstadaptivedemux_class->is_live = gst_mss_demux_is_live;
|
|
|
|
gstadaptivedemux_class->get_duration = gst_mss_demux_get_duration;
|
2014-12-04 04:46:43 +00:00
|
|
|
gstadaptivedemux_class->get_manifest_update_interval =
|
|
|
|
gst_mss_demux_get_manifest_update_interval;
|
2014-11-22 04:01:50 +00:00
|
|
|
gstadaptivedemux_class->reset = gst_mss_demux_reset;
|
|
|
|
gstadaptivedemux_class->seek = gst_mss_demux_seek;
|
|
|
|
gstadaptivedemux_class->stream_seek = gst_mss_demux_stream_seek;
|
|
|
|
gstadaptivedemux_class->stream_advance_fragment =
|
|
|
|
gst_mss_demux_stream_advance_fragment;
|
2014-12-04 04:46:43 +00:00
|
|
|
gstadaptivedemux_class->stream_has_next_fragment =
|
|
|
|
gst_mss_demux_stream_has_next_fragment;
|
2014-11-22 04:01:50 +00:00
|
|
|
gstadaptivedemux_class->stream_select_bitrate =
|
|
|
|
gst_mss_demux_stream_select_bitrate;
|
|
|
|
gstadaptivedemux_class->stream_update_fragment_info =
|
|
|
|
gst_mss_demux_stream_update_fragment_info;
|
2014-12-04 04:46:43 +00:00
|
|
|
gstadaptivedemux_class->update_manifest = gst_mss_demux_update_manifest;
|
2014-05-12 18:43:05 +00:00
|
|
|
|
2013-04-16 22:35:03 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (mssdemux_debug, "mssdemux", 0, "mssdemux plugin");
|
2012-11-08 19:06:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-04-16 22:35:03 +00:00
|
|
|
gst_mss_demux_init (GstMssDemux * mssdemux)
|
2012-11-08 19:06:44 +00:00
|
|
|
{
|
2013-01-22 20:33:41 +00:00
|
|
|
mssdemux->data_queue_max_size = DEFAULT_MAX_QUEUE_SIZE_BUFFERS;
|
2013-02-05 03:28:19 +00:00
|
|
|
mssdemux->bitrate_limit = DEFAULT_BITRATE_LIMIT;
|
2013-07-23 08:11:49 +00:00
|
|
|
|
2014-11-22 04:01:50 +00:00
|
|
|
gst_adaptive_demux_set_stream_struct_size (GST_ADAPTIVE_DEMUX_CAST (mssdemux),
|
|
|
|
sizeof (GstMssDemuxStream));
|
2012-11-16 20:30:12 +00:00
|
|
|
}
|
|
|
|
|
2012-11-08 19:06:44 +00:00
|
|
|
static void
|
2014-11-22 04:01:50 +00:00
|
|
|
gst_mss_demux_reset (GstAdaptiveDemux * demux)
|
2012-11-08 19:06:44 +00:00
|
|
|
{
|
2014-11-22 04:01:50 +00:00
|
|
|
GstMssDemux *mssdemux = GST_MSS_DEMUX_CAST (demux);
|
2012-11-14 20:19:35 +00:00
|
|
|
|
2012-11-08 19:06:44 +00:00
|
|
|
if (mssdemux->manifest) {
|
|
|
|
gst_mss_manifest_free (mssdemux->manifest);
|
2012-11-14 20:19:35 +00:00
|
|
|
mssdemux->manifest = NULL;
|
2012-11-08 19:06:44 +00:00
|
|
|
}
|
2012-11-19 20:53:16 +00:00
|
|
|
g_free (mssdemux->base_url);
|
|
|
|
mssdemux->base_url = NULL;
|
2013-07-23 08:11:49 +00:00
|
|
|
|
2014-11-22 04:01:50 +00:00
|
|
|
mssdemux->n_videos = mssdemux->n_audios = 0;
|
|
|
|
|
2012-11-08 19:06:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_mss_demux_dispose (GObject * object)
|
|
|
|
{
|
2014-11-22 04:01:50 +00:00
|
|
|
gst_mss_demux_reset (GST_ADAPTIVE_DEMUX_CAST (object));
|
2013-02-04 04:20:51 +00:00
|
|
|
|
2012-11-08 19:06:44 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
2013-01-08 21:01:17 +00:00
|
|
|
static void
|
|
|
|
gst_mss_demux_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstMssDemux *mssdemux = GST_MSS_DEMUX (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_CONNECTION_SPEED:
|
2013-01-10 18:16:36 +00:00
|
|
|
GST_OBJECT_LOCK (mssdemux);
|
2013-01-08 21:01:17 +00:00
|
|
|
mssdemux->connection_speed = g_value_get_uint (value) * 1000;
|
2013-01-10 18:16:36 +00:00
|
|
|
mssdemux->update_bitrates = TRUE;
|
2013-04-23 15:08:38 +00:00
|
|
|
GST_DEBUG_OBJECT (mssdemux, "Connection speed set to %" G_GUINT64_FORMAT,
|
2013-01-10 18:16:36 +00:00
|
|
|
mssdemux->connection_speed);
|
|
|
|
GST_OBJECT_UNLOCK (mssdemux);
|
2013-01-08 21:01:17 +00:00
|
|
|
break;
|
2013-01-22 20:33:41 +00:00
|
|
|
case PROP_MAX_QUEUE_SIZE_BUFFERS:
|
|
|
|
mssdemux->data_queue_max_size = g_value_get_uint (value);
|
|
|
|
break;
|
2013-02-05 03:28:19 +00:00
|
|
|
case PROP_BITRATE_LIMIT:
|
|
|
|
mssdemux->bitrate_limit = g_value_get_float (value);
|
|
|
|
break;
|
2013-01-08 21:01:17 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_mss_demux_get_property (GObject * object, guint prop_id, GValue * value,
|
|
|
|
GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstMssDemux *mssdemux = GST_MSS_DEMUX (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_CONNECTION_SPEED:
|
|
|
|
g_value_set_uint (value, mssdemux->connection_speed / 1000);
|
|
|
|
break;
|
2013-01-22 20:33:41 +00:00
|
|
|
case PROP_MAX_QUEUE_SIZE_BUFFERS:
|
|
|
|
g_value_set_uint (value, mssdemux->data_queue_max_size);
|
|
|
|
break;
|
2013-02-05 03:28:19 +00:00
|
|
|
case PROP_BITRATE_LIMIT:
|
|
|
|
g_value_set_float (value, mssdemux->bitrate_limit);
|
|
|
|
break;
|
2013-01-08 21:01:17 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-22 04:01:50 +00:00
|
|
|
static gboolean
|
|
|
|
gst_mss_demux_is_live (GstAdaptiveDemux * demux)
|
2012-11-08 19:06:44 +00:00
|
|
|
{
|
2014-11-22 04:01:50 +00:00
|
|
|
GstMssDemux *mssdemux = GST_MSS_DEMUX_CAST (demux);
|
2012-11-08 19:06:44 +00:00
|
|
|
|
2014-11-22 04:01:50 +00:00
|
|
|
g_return_val_if_fail (mssdemux->manifest != NULL, FALSE);
|
2014-05-12 18:43:05 +00:00
|
|
|
|
2014-11-22 04:01:50 +00:00
|
|
|
return gst_mss_manifest_is_live (mssdemux->manifest);
|
2014-05-12 18:43:05 +00:00
|
|
|
}
|
|
|
|
|
2014-11-22 04:01:50 +00:00
|
|
|
static GstClockTime
|
|
|
|
gst_mss_demux_get_duration (GstAdaptiveDemux * demux)
|
2012-11-08 19:06:44 +00:00
|
|
|
{
|
2014-11-22 04:01:50 +00:00
|
|
|
GstMssDemux *mssdemux = GST_MSS_DEMUX_CAST (demux);
|
2012-11-08 19:06:44 +00:00
|
|
|
|
2014-11-22 04:01:50 +00:00
|
|
|
g_return_val_if_fail (mssdemux->manifest != NULL, FALSE);
|
2013-01-31 21:14:37 +00:00
|
|
|
|
2014-11-22 04:01:50 +00:00
|
|
|
return gst_mss_manifest_get_gst_duration (mssdemux->manifest);
|
2012-11-08 19:06:44 +00:00
|
|
|
}
|
|
|
|
|
2014-11-22 04:01:50 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
gst_mss_demux_stream_update_fragment_info (GstAdaptiveDemuxStream * stream)
|
2012-12-28 03:48:33 +00:00
|
|
|
{
|
2014-11-22 04:01:50 +00:00
|
|
|
GstMssDemuxStream *mssstream = (GstMssDemuxStream *) stream;
|
|
|
|
GstMssDemux *mssdemux = GST_MSS_DEMUX_CAST (stream->demux);
|
|
|
|
GstFlowReturn ret;
|
|
|
|
gchar *path = NULL;
|
2012-12-28 03:48:33 +00:00
|
|
|
|
2014-11-22 04:01:50 +00:00
|
|
|
g_free (stream->fragment.uri);
|
|
|
|
stream->fragment.uri = NULL;
|
2012-11-08 19:06:44 +00:00
|
|
|
|
2014-11-22 04:01:50 +00:00
|
|
|
ret = gst_mss_stream_get_fragment_url (mssstream->manifest_stream, &path);
|
2012-11-08 19:06:44 +00:00
|
|
|
|
2014-11-22 04:01:50 +00:00
|
|
|
if (ret == GST_FLOW_OK) {
|
|
|
|
stream->fragment.uri = g_strdup_printf ("%s/%s", mssdemux->base_url, path);
|
|
|
|
stream->fragment.timestamp =
|
|
|
|
gst_mss_stream_get_fragment_gst_timestamp (mssstream->manifest_stream);
|
|
|
|
stream->fragment.duration =
|
|
|
|
gst_mss_stream_get_fragment_gst_duration (mssstream->manifest_stream);
|
2012-11-08 19:06:44 +00:00
|
|
|
}
|
2014-11-22 04:01:50 +00:00
|
|
|
g_free (path);
|
2012-11-08 19:06:44 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-11-22 04:01:50 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
gst_mss_demux_stream_seek (GstAdaptiveDemuxStream * stream, GstClockTime ts)
|
2012-12-28 03:48:33 +00:00
|
|
|
{
|
2014-11-22 04:01:50 +00:00
|
|
|
GstMssDemuxStream *mssstream = (GstMssDemuxStream *) stream;
|
2012-12-28 03:48:33 +00:00
|
|
|
|
2014-11-22 04:01:50 +00:00
|
|
|
gst_mss_stream_seek (mssstream->manifest_stream, ts);
|
|
|
|
return GST_FLOW_OK;
|
2012-12-28 03:48:33 +00:00
|
|
|
}
|
|
|
|
|
2014-11-22 04:01:50 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
gst_mss_demux_stream_advance_fragment (GstAdaptiveDemuxStream * stream)
|
2012-12-26 19:19:14 +00:00
|
|
|
{
|
2014-11-22 04:01:50 +00:00
|
|
|
GstMssDemuxStream *mssstream = (GstMssDemuxStream *) stream;
|
2013-01-17 19:20:10 +00:00
|
|
|
|
2014-11-22 04:01:50 +00:00
|
|
|
if (stream->demux->segment.rate >= 0)
|
|
|
|
return gst_mss_stream_advance_fragment (mssstream->manifest_stream);
|
|
|
|
else
|
|
|
|
return gst_mss_stream_regress_fragment (mssstream->manifest_stream);
|
2012-12-26 19:19:14 +00:00
|
|
|
}
|
|
|
|
|
2014-11-22 04:01:50 +00:00
|
|
|
static GstCaps *
|
|
|
|
create_mss_caps (GstMssDemuxStream * stream, GstCaps * caps)
|
2012-12-26 19:19:14 +00:00
|
|
|
{
|
2014-11-22 04:01:50 +00:00
|
|
|
return gst_caps_new_simple ("video/quicktime", "variant", G_TYPE_STRING,
|
|
|
|
"mss-fragmented", "timescale", G_TYPE_UINT64,
|
|
|
|
gst_mss_stream_get_timescale (stream->manifest_stream), "media-caps",
|
|
|
|
GST_TYPE_CAPS, caps, NULL);
|
2012-12-26 19:19:14 +00:00
|
|
|
}
|
|
|
|
|
2013-01-10 18:16:36 +00:00
|
|
|
static GstPad *
|
|
|
|
_create_pad (GstMssDemux * mssdemux, GstMssStream * manifeststream)
|
|
|
|
{
|
2014-05-12 16:40:19 +00:00
|
|
|
gchar *name = NULL;
|
2013-01-10 18:16:36 +00:00
|
|
|
GstPad *srcpad = NULL;
|
|
|
|
GstMssStreamType streamtype;
|
2014-05-12 16:40:19 +00:00
|
|
|
GstPadTemplate *tmpl = NULL;
|
2013-01-10 18:16:36 +00:00
|
|
|
|
|
|
|
streamtype = gst_mss_stream_get_type (manifeststream);
|
|
|
|
GST_DEBUG_OBJECT (mssdemux, "Found stream of type: %s",
|
|
|
|
gst_mss_stream_type_name (streamtype));
|
|
|
|
|
|
|
|
/* TODO use stream's name/bitrate/index as the pad name? */
|
|
|
|
if (streamtype == MSS_STREAM_TYPE_VIDEO) {
|
|
|
|
name = g_strdup_printf ("video_%02u", mssdemux->n_videos++);
|
2014-05-12 16:40:19 +00:00
|
|
|
tmpl = gst_static_pad_template_get (&gst_mss_demux_videosrc_template);
|
2013-01-10 18:16:36 +00:00
|
|
|
} else if (streamtype == MSS_STREAM_TYPE_AUDIO) {
|
|
|
|
name = g_strdup_printf ("audio_%02u", mssdemux->n_audios++);
|
2014-05-12 16:40:19 +00:00
|
|
|
tmpl = gst_static_pad_template_get (&gst_mss_demux_audiosrc_template);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tmpl != NULL) {
|
2013-01-10 18:16:36 +00:00
|
|
|
srcpad =
|
2014-05-12 16:40:19 +00:00
|
|
|
GST_PAD_CAST (gst_ghost_pad_new_no_target_from_template (name, tmpl));
|
2013-01-10 18:16:36 +00:00
|
|
|
g_free (name);
|
2014-05-12 16:40:19 +00:00
|
|
|
gst_object_unref (tmpl);
|
2013-01-10 18:16:36 +00:00
|
|
|
}
|
|
|
|
if (!srcpad) {
|
|
|
|
GST_WARNING_OBJECT (mssdemux, "Ignoring unknown type stream");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return srcpad;
|
|
|
|
}
|
|
|
|
|
2014-11-22 04:01:50 +00:00
|
|
|
static gboolean
|
|
|
|
gst_mss_demux_setup_streams (GstAdaptiveDemux * demux)
|
2012-11-09 19:47:54 +00:00
|
|
|
{
|
2014-11-22 04:01:50 +00:00
|
|
|
GstMssDemux *mssdemux = GST_MSS_DEMUX_CAST (demux);
|
2012-11-09 19:47:54 +00:00
|
|
|
GSList *streams = gst_mss_manifest_get_streams (mssdemux->manifest);
|
|
|
|
GSList *iter;
|
|
|
|
|
|
|
|
if (streams == NULL) {
|
|
|
|
GST_INFO_OBJECT (mssdemux, "No streams found in the manifest");
|
2012-12-21 19:42:11 +00:00
|
|
|
GST_ELEMENT_ERROR (mssdemux, STREAM, DEMUX,
|
|
|
|
(_("This file contains no playable streams.")),
|
|
|
|
("no streams found at the Manifest"));
|
2014-11-22 04:01:50 +00:00
|
|
|
return FALSE;
|
2012-11-09 19:47:54 +00:00
|
|
|
}
|
|
|
|
|
2014-11-22 04:01:50 +00:00
|
|
|
GST_INFO_OBJECT (mssdemux, "Changing max bitrate to %" G_GUINT64_FORMAT,
|
|
|
|
mssdemux->connection_speed);
|
|
|
|
gst_mss_manifest_change_bitrate (mssdemux->manifest,
|
|
|
|
mssdemux->connection_speed);
|
|
|
|
mssdemux->update_bitrates = FALSE;
|
|
|
|
|
2012-11-09 19:47:54 +00:00
|
|
|
for (iter = streams; iter; iter = g_slist_next (iter)) {
|
2012-11-14 20:19:35 +00:00
|
|
|
GstPad *srcpad = NULL;
|
|
|
|
GstMssDemuxStream *stream = NULL;
|
2012-11-19 20:53:16 +00:00
|
|
|
GstMssStream *manifeststream = iter->data;
|
2014-11-22 04:01:50 +00:00
|
|
|
GstCaps *caps;
|
|
|
|
const gchar *lang;
|
2013-01-10 18:16:36 +00:00
|
|
|
|
|
|
|
srcpad = _create_pad (mssdemux, manifeststream);
|
2012-11-14 20:19:35 +00:00
|
|
|
|
|
|
|
if (!srcpad) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-11-22 04:01:50 +00:00
|
|
|
stream = (GstMssDemuxStream *)
|
|
|
|
gst_adaptive_demux_stream_new (GST_ADAPTIVE_DEMUX_CAST (mssdemux),
|
|
|
|
srcpad);
|
|
|
|
stream->manifest_stream = manifeststream;
|
2013-01-08 20:55:49 +00:00
|
|
|
gst_mss_stream_set_active (manifeststream, TRUE);
|
2014-11-22 04:01:50 +00:00
|
|
|
caps = gst_mss_stream_get_caps (stream->manifest_stream);
|
|
|
|
gst_adaptive_demux_stream_set_caps (GST_ADAPTIVE_DEMUX_STREAM_CAST (stream),
|
|
|
|
create_mss_caps (stream, caps));
|
|
|
|
gst_caps_unref (caps);
|
2012-11-14 20:19:35 +00:00
|
|
|
|
2013-11-14 14:23:42 +00:00
|
|
|
lang = gst_mss_stream_get_lang (stream->manifest_stream);
|
|
|
|
if (lang != NULL) {
|
|
|
|
GstTagList *tags;
|
|
|
|
|
|
|
|
tags = gst_tag_list_new (GST_TAG_LANGUAGE_CODE, lang, NULL);
|
2014-11-22 04:01:50 +00:00
|
|
|
gst_adaptive_demux_stream_set_tags (GST_ADAPTIVE_DEMUX_STREAM_CAST
|
|
|
|
(stream), tags);
|
2013-11-14 14:23:42 +00:00
|
|
|
}
|
2012-11-09 19:47:54 +00:00
|
|
|
}
|
2014-11-22 04:01:50 +00:00
|
|
|
|
2013-01-04 20:00:34 +00:00
|
|
|
return TRUE;
|
2012-11-09 19:47:54 +00:00
|
|
|
}
|
|
|
|
|
2014-12-04 04:46:43 +00:00
|
|
|
static void
|
|
|
|
gst_mss_demux_update_base_url (GstMssDemux * mssdemux)
|
2012-11-08 19:06:44 +00:00
|
|
|
{
|
2014-12-04 04:46:43 +00:00
|
|
|
GstAdaptiveDemux *demux = GST_ADAPTIVE_DEMUX_CAST (mssdemux);
|
2014-11-22 04:01:50 +00:00
|
|
|
gchar *baseurl_end;
|
2012-11-09 19:47:54 +00:00
|
|
|
|
2014-12-04 04:46:43 +00:00
|
|
|
g_free (mssdemux->base_url);
|
2013-01-16 18:28:19 +00:00
|
|
|
|
2014-11-22 04:01:50 +00:00
|
|
|
mssdemux->base_url =
|
|
|
|
g_strdup (demux->manifest_base_uri ? demux->manifest_base_uri : demux->
|
|
|
|
manifest_uri);
|
|
|
|
baseurl_end = g_strrstr (mssdemux->base_url, "/Manifest");
|
|
|
|
if (baseurl_end == NULL) {
|
|
|
|
/* second try */
|
|
|
|
baseurl_end = g_strrstr (mssdemux->base_url, "/manifest");
|
|
|
|
}
|
|
|
|
if (baseurl_end) {
|
|
|
|
/* set the new end of the string */
|
|
|
|
baseurl_end[0] = '\0';
|
|
|
|
} else {
|
|
|
|
GST_WARNING_OBJECT (mssdemux, "Stream's URI didn't end with /manifest");
|
|
|
|
}
|
2013-01-31 21:14:37 +00:00
|
|
|
|
2014-12-04 04:46:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_mss_demux_process_manifest (GstAdaptiveDemux * demux, GstBuffer * buf)
|
|
|
|
{
|
|
|
|
GstMssDemux *mssdemux = GST_MSS_DEMUX_CAST (demux);
|
|
|
|
|
|
|
|
gst_mss_demux_update_base_url (mssdemux);
|
|
|
|
|
2014-11-22 04:01:50 +00:00
|
|
|
mssdemux->manifest = gst_mss_manifest_new (buf);
|
2012-11-09 19:47:54 +00:00
|
|
|
if (!mssdemux->manifest) {
|
|
|
|
GST_ELEMENT_ERROR (mssdemux, STREAM, FORMAT, ("Bad manifest file"),
|
|
|
|
("Xml manifest file couldn't be parsed"));
|
2013-01-16 18:28:19 +00:00
|
|
|
return FALSE;
|
2012-11-09 19:47:54 +00:00
|
|
|
}
|
2014-11-22 04:01:50 +00:00
|
|
|
return gst_mss_demux_setup_streams (demux);
|
2012-11-08 19:06:44 +00:00
|
|
|
}
|
2012-11-16 20:30:12 +00:00
|
|
|
|
2014-11-22 04:01:50 +00:00
|
|
|
static gboolean
|
|
|
|
gst_mss_demux_stream_select_bitrate (GstAdaptiveDemuxStream * stream,
|
|
|
|
guint64 bitrate)
|
2013-02-08 03:51:30 +00:00
|
|
|
{
|
2014-11-22 04:01:50 +00:00
|
|
|
GstMssDemux *mssdemux = GST_MSS_DEMUX_CAST (stream->demux);
|
|
|
|
GstMssDemuxStream *mssstream = (GstMssDemuxStream *) stream;
|
|
|
|
gboolean ret = FALSE;
|
2013-02-08 03:51:30 +00:00
|
|
|
|
2014-11-22 04:01:50 +00:00
|
|
|
bitrate *= mssdemux->bitrate_limit;
|
2013-02-08 03:51:30 +00:00
|
|
|
if (mssdemux->connection_speed) {
|
2014-05-12 17:18:13 +00:00
|
|
|
bitrate = MIN (mssdemux->connection_speed, bitrate);
|
2013-02-08 03:51:30 +00:00
|
|
|
}
|
|
|
|
|
2013-12-13 20:31:11 +00:00
|
|
|
GST_DEBUG_OBJECT (stream->pad,
|
2014-11-22 04:01:50 +00:00
|
|
|
"Using stream download bitrate %" G_GUINT64_FORMAT, bitrate);
|
2013-02-08 03:51:30 +00:00
|
|
|
|
2014-11-22 04:01:50 +00:00
|
|
|
if (gst_mss_stream_select_bitrate (mssstream->manifest_stream, bitrate)) {
|
2013-02-08 03:51:30 +00:00
|
|
|
GstCaps *caps;
|
2014-11-22 04:01:50 +00:00
|
|
|
GstCaps *msscaps;
|
|
|
|
caps = gst_mss_stream_get_caps (mssstream->manifest_stream);
|
2013-02-08 03:51:30 +00:00
|
|
|
|
2013-12-13 20:31:11 +00:00
|
|
|
GST_DEBUG_OBJECT (stream->pad,
|
|
|
|
"Starting streams reconfiguration due to bitrate changes");
|
2014-11-22 04:01:50 +00:00
|
|
|
msscaps = create_mss_caps (mssstream, caps);
|
2013-02-08 03:51:30 +00:00
|
|
|
|
2013-12-13 20:31:11 +00:00
|
|
|
GST_DEBUG_OBJECT (stream->pad,
|
|
|
|
"Stream changed bitrate to %" G_GUINT64_FORMAT " caps: %"
|
|
|
|
GST_PTR_FORMAT,
|
2014-11-22 04:01:50 +00:00
|
|
|
gst_mss_stream_get_current_bitrate (mssstream->manifest_stream), caps);
|
2013-04-16 22:35:03 +00:00
|
|
|
|
2014-05-12 16:40:19 +00:00
|
|
|
gst_caps_unref (caps);
|
|
|
|
|
2014-11-22 04:01:50 +00:00
|
|
|
gst_adaptive_demux_stream_set_caps (stream, msscaps);
|
|
|
|
ret = TRUE;
|
2013-12-13 20:31:11 +00:00
|
|
|
GST_DEBUG_OBJECT (stream->pad, "Finished streams reconfiguration");
|
2013-02-08 03:51:30 +00:00
|
|
|
}
|
2014-05-12 16:40:19 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2014-11-22 04:01:50 +00:00
|
|
|
gst_mss_demux_seek (GstAdaptiveDemux * demux, GstEvent * seek)
|
2014-05-12 16:40:19 +00:00
|
|
|
{
|
2014-11-22 04:01:50 +00:00
|
|
|
gdouble rate;
|
|
|
|
GstFormat format;
|
|
|
|
GstSeekFlags flags;
|
|
|
|
GstSeekType start_type, stop_type;
|
|
|
|
gint64 start, stop;
|
|
|
|
GstMssDemux *mssdemux = GST_MSS_DEMUX_CAST (demux);
|
2014-05-12 16:40:19 +00:00
|
|
|
|
2014-11-22 04:01:50 +00:00
|
|
|
gst_event_parse_seek (seek, &rate, &format, &flags, &start_type, &start,
|
|
|
|
&stop_type, &stop);
|
2014-05-12 16:40:19 +00:00
|
|
|
|
2014-11-22 04:01:50 +00:00
|
|
|
GST_DEBUG_OBJECT (mssdemux,
|
|
|
|
"seek event, rate: %f start: %" GST_TIME_FORMAT " stop: %"
|
|
|
|
GST_TIME_FORMAT, rate, GST_TIME_ARGS (start), GST_TIME_ARGS (stop));
|
2014-05-12 16:40:19 +00:00
|
|
|
|
2014-11-22 04:01:50 +00:00
|
|
|
gst_mss_manifest_seek (mssdemux->manifest, start);
|
2014-05-12 16:40:19 +00:00
|
|
|
|
2014-09-17 20:27:53 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2014-12-04 04:46:43 +00:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_mss_demux_stream_has_next_fragment (GstAdaptiveDemuxStream * stream)
|
|
|
|
{
|
|
|
|
GstMssDemuxStream *mssstream = (GstMssDemuxStream *) stream;
|
|
|
|
|
|
|
|
return gst_mss_stream_has_next_fragment (mssstream->manifest_stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint64
|
|
|
|
gst_mss_demux_get_manifest_update_interval (GstAdaptiveDemux * demux)
|
|
|
|
{
|
|
|
|
GstMssDemux *mssdemux = GST_MSS_DEMUX_CAST (demux);
|
|
|
|
GstClockTime interval;
|
|
|
|
|
|
|
|
/* Not much information about this in the MSS spec. It seems that
|
|
|
|
* the fragments contain an UUID box that should tell the next
|
|
|
|
* fragments time and duration so one wouldn't need to fetch
|
|
|
|
* the Manifest again, but we need a fallback here. So use 2 times
|
|
|
|
* the current fragment duration */
|
|
|
|
|
|
|
|
interval = gst_mss_manifest_get_min_fragment_duration (mssdemux->manifest);
|
|
|
|
if (!GST_CLOCK_TIME_IS_VALID (interval))
|
|
|
|
interval = 2 * GST_SECOND; /* default to 2 seconds */
|
|
|
|
|
|
|
|
interval = 2 * (interval / GST_USECOND);
|
|
|
|
|
|
|
|
return interval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_mss_demux_update_manifest (GstAdaptiveDemux * demux, GstBuffer * buffer)
|
|
|
|
{
|
|
|
|
GstMssDemux *mssdemux = GST_MSS_DEMUX_CAST (demux);
|
|
|
|
|
|
|
|
gst_mss_demux_update_base_url (mssdemux);
|
|
|
|
|
|
|
|
gst_mss_manifest_reload_fragments (mssdemux->manifest, buffer);
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|