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
|
|
|
|
2013-02-07 06:10:46 +00:00
|
|
|
#define MAX_DOWNLOAD_ERROR_COUNT 3
|
2013-02-05 20:48:42 +00:00
|
|
|
|
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-05-12 16:40:19 +00:00
|
|
|
G_DEFINE_TYPE (GstMssDemux, gst_mss_demux, GST_TYPE_BIN);
|
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);
|
|
|
|
static GstStateChangeReturn gst_mss_demux_change_state (GstElement * element,
|
|
|
|
GstStateChange transition);
|
2013-04-16 22:35:03 +00:00
|
|
|
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);
|
2012-12-26 19:19:14 +00:00
|
|
|
|
2013-01-14 16:21:10 +00:00
|
|
|
static void gst_mss_demux_download_loop (GstMssDemuxStream * stream);
|
2013-12-16 19:14:24 +00:00
|
|
|
static GstFlowReturn gst_mss_demux_stream_push_event (GstMssDemuxStream *
|
|
|
|
stream, GstEvent * event);
|
|
|
|
static GstFlowReturn gst_mss_demux_combine_flows (GstMssDemux * mssdemux);
|
2012-11-16 20:30:12 +00:00
|
|
|
|
2013-01-16 18:28:19 +00:00
|
|
|
static gboolean gst_mss_demux_process_manifest (GstMssDemux * mssdemux);
|
2013-12-17 19:31:52 +00:00
|
|
|
static void
|
|
|
|
gst_mss_demux_stop_tasks (GstMssDemux * mssdemux, gboolean immediate);
|
2012-11-08 19:06:44 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gst_mss_demux_class_init (GstMssDemuxClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gstelement_class = (GstElementClass *) klass;
|
|
|
|
|
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
|
|
|
|
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 "
|
|
|
|
"(0 = infinite)", 0, G_MAXUINT, DEFAULT_MAX_QUEUE_SIZE_BUFFERS,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
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));
|
|
|
|
|
2012-11-08 19:06:44 +00:00
|
|
|
gstelement_class->change_state =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_mss_demux_change_state);
|
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
|
|
|
{
|
|
|
|
mssdemux->sinkpad =
|
|
|
|
gst_pad_new_from_static_template (&gst_mss_demux_sink_template, "sink");
|
|
|
|
gst_pad_set_chain_function (mssdemux->sinkpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_mss_demux_chain));
|
|
|
|
gst_pad_set_event_function (mssdemux->sinkpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_mss_demux_event));
|
|
|
|
gst_element_add_pad (GST_ELEMENT_CAST (mssdemux), mssdemux->sinkpad);
|
2013-01-14 16:21:10 +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
|
|
|
|
|
|
|
mssdemux->have_group_id = FALSE;
|
|
|
|
mssdemux->group_id = G_MAXUINT;
|
2013-01-14 16:21:10 +00:00
|
|
|
}
|
|
|
|
|
2012-11-16 20:30:12 +00:00
|
|
|
static GstMssDemuxStream *
|
|
|
|
gst_mss_demux_stream_new (GstMssDemux * mssdemux,
|
2012-11-19 20:53:16 +00:00
|
|
|
GstMssStream * manifeststream, GstPad * srcpad)
|
2012-11-16 20:30:12 +00:00
|
|
|
{
|
|
|
|
GstMssDemuxStream *stream;
|
|
|
|
|
|
|
|
stream = g_new0 (GstMssDemuxStream, 1);
|
|
|
|
|
2013-01-14 16:21:10 +00:00
|
|
|
/* Downloading task */
|
2013-04-16 22:35:03 +00:00
|
|
|
g_rec_mutex_init (&stream->download_lock);
|
2013-01-14 16:21:10 +00:00
|
|
|
stream->download_task =
|
2013-04-16 22:35:03 +00:00
|
|
|
gst_task_new ((GstTaskFunction) gst_mss_demux_download_loop, stream,
|
|
|
|
NULL);
|
2013-01-14 16:21:10 +00:00
|
|
|
gst_task_set_lock (stream->download_task, &stream->download_lock);
|
2012-11-16 20:30:12 +00:00
|
|
|
|
|
|
|
stream->pad = srcpad;
|
|
|
|
stream->manifest_stream = manifeststream;
|
|
|
|
stream->parent = mssdemux;
|
|
|
|
|
2013-12-17 16:16:58 +00:00
|
|
|
gst_segment_init (&stream->segment, GST_FORMAT_TIME);
|
2014-05-12 16:40:19 +00:00
|
|
|
g_cond_init (&stream->fragment_download_cond);
|
|
|
|
g_mutex_init (&stream->fragment_download_lock);
|
2013-12-17 16:16:58 +00:00
|
|
|
|
2012-11-16 20:30:12 +00:00
|
|
|
return stream;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_mss_demux_stream_free (GstMssDemuxStream * stream)
|
|
|
|
{
|
2013-01-14 16:21:10 +00:00
|
|
|
if (stream->download_task) {
|
|
|
|
if (GST_TASK_STATE (stream->download_task) != GST_TASK_STOPPED) {
|
2012-11-16 20:30:12 +00:00
|
|
|
GST_DEBUG_OBJECT (stream->parent, "Leaving streaming task %s:%s",
|
|
|
|
GST_DEBUG_PAD_NAME (stream->pad));
|
2014-05-12 16:40:19 +00:00
|
|
|
g_cond_signal (&stream->fragment_download_cond);
|
2013-02-04 04:20:51 +00:00
|
|
|
gst_task_stop (stream->download_task);
|
2012-11-22 16:01:09 +00:00
|
|
|
GST_LOG_OBJECT (stream->parent, "Waiting for task to finish");
|
2013-01-14 16:21:10 +00:00
|
|
|
gst_task_join (stream->download_task);
|
2012-11-22 16:01:09 +00:00
|
|
|
GST_LOG_OBJECT (stream->parent, "Finished");
|
2012-11-16 20:30:12 +00:00
|
|
|
}
|
2013-01-14 16:21:10 +00:00
|
|
|
gst_object_unref (stream->download_task);
|
2013-04-16 22:35:03 +00:00
|
|
|
g_rec_mutex_clear (&stream->download_lock);
|
2013-01-14 16:21:10 +00:00
|
|
|
stream->download_task = NULL;
|
2012-11-16 20:30:12 +00:00
|
|
|
}
|
|
|
|
|
2014-05-12 16:40:19 +00:00
|
|
|
if (stream->pending_segment) {
|
|
|
|
gst_event_unref (stream->pending_segment);
|
|
|
|
stream->pending_segment = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stream->src_srcpad) {
|
|
|
|
gst_object_unref (stream->src_srcpad);
|
|
|
|
stream->src_srcpad = NULL;
|
2012-12-28 03:48:33 +00:00
|
|
|
}
|
|
|
|
|
2014-05-12 16:40:19 +00:00
|
|
|
if (stream->src) {
|
|
|
|
gst_element_set_state (stream->src, GST_STATE_NULL);
|
|
|
|
gst_bin_remove (GST_BIN_CAST (stream->parent), stream->src);
|
|
|
|
stream->src = NULL;
|
2012-11-16 20:30:12 +00:00
|
|
|
}
|
2014-05-12 16:40:19 +00:00
|
|
|
|
|
|
|
g_cond_clear (&stream->fragment_download_cond);
|
|
|
|
g_mutex_clear (&stream->fragment_download_lock);
|
|
|
|
|
2012-11-22 16:01:09 +00:00
|
|
|
if (stream->pad) {
|
|
|
|
gst_object_unref (stream->pad);
|
|
|
|
stream->pad = NULL;
|
|
|
|
}
|
2013-05-17 14:37:30 +00:00
|
|
|
if (stream->caps)
|
|
|
|
gst_caps_unref (stream->caps);
|
2012-11-16 20:30:12 +00:00
|
|
|
g_free (stream);
|
|
|
|
}
|
|
|
|
|
2012-11-08 19:06:44 +00:00
|
|
|
static void
|
|
|
|
gst_mss_demux_reset (GstMssDemux * mssdemux)
|
|
|
|
{
|
2012-11-14 20:19:35 +00:00
|
|
|
GSList *iter;
|
2013-01-14 16:21:10 +00:00
|
|
|
|
2013-12-17 19:31:52 +00:00
|
|
|
gst_mss_demux_stop_tasks (mssdemux, TRUE);
|
2013-01-14 16:21:10 +00:00
|
|
|
|
2012-11-08 19:06:44 +00:00
|
|
|
if (mssdemux->manifest_buffer) {
|
|
|
|
gst_buffer_unref (mssdemux->manifest_buffer);
|
2012-11-14 20:19:35 +00:00
|
|
|
mssdemux->manifest_buffer = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (iter = mssdemux->streams; iter; iter = g_slist_next (iter)) {
|
|
|
|
GstMssDemuxStream *stream = iter->data;
|
2013-02-07 18:26:46 +00:00
|
|
|
if (stream->pad)
|
|
|
|
gst_element_remove_pad (GST_ELEMENT_CAST (mssdemux), stream->pad);
|
2012-11-16 20:30:12 +00:00
|
|
|
gst_mss_demux_stream_free (stream);
|
2012-11-08 19:06:44 +00:00
|
|
|
}
|
2012-11-14 20:19:35 +00:00
|
|
|
g_slist_free (mssdemux->streams);
|
|
|
|
mssdemux->streams = NULL;
|
|
|
|
|
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-14 20:19:35 +00:00
|
|
|
|
|
|
|
mssdemux->n_videos = mssdemux->n_audios = 0;
|
2012-11-19 20:53:16 +00:00
|
|
|
g_free (mssdemux->base_url);
|
|
|
|
mssdemux->base_url = NULL;
|
2013-02-04 04:20:51 +00:00
|
|
|
g_free (mssdemux->manifest_uri);
|
|
|
|
mssdemux->manifest_uri = NULL;
|
2013-07-23 08:11:49 +00:00
|
|
|
|
|
|
|
mssdemux->have_group_id = FALSE;
|
|
|
|
mssdemux->group_id = G_MAXUINT;
|
2012-11-08 19:06:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_mss_demux_dispose (GObject * object)
|
|
|
|
{
|
2013-01-14 16:21:10 +00:00
|
|
|
GstMssDemux *mssdemux = GST_MSS_DEMUX_CAST (object);
|
|
|
|
|
2013-02-04 04:20:51 +00:00
|
|
|
gst_mss_demux_reset (mssdemux);
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-08 19:06:44 +00:00
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_mss_demux_change_state (GstElement * element, GstStateChange transition)
|
|
|
|
{
|
|
|
|
GstMssDemux *mssdemux = GST_MSS_DEMUX_CAST (element);
|
|
|
|
GstStateChangeReturn result = GST_STATE_CHANGE_FAILURE;
|
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
2012-11-22 16:01:09 +00:00
|
|
|
gst_mss_demux_reset (mssdemux);
|
2012-11-08 19:06:44 +00:00
|
|
|
break;
|
|
|
|
case GST_STATE_CHANGE_READY_TO_NULL:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
2013-04-16 22:35:03 +00:00
|
|
|
gst_mss_demux_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
|
2012-11-08 19:06:44 +00:00
|
|
|
{
|
2013-04-16 22:35:03 +00:00
|
|
|
GstMssDemux *mssdemux = GST_MSS_DEMUX_CAST (parent);
|
2012-11-08 19:06:44 +00:00
|
|
|
if (mssdemux->manifest_buffer == NULL)
|
|
|
|
mssdemux->manifest_buffer = buffer;
|
|
|
|
else
|
|
|
|
mssdemux->manifest_buffer =
|
2013-04-16 22:35:03 +00:00
|
|
|
gst_buffer_append (mssdemux->manifest_buffer, buffer);
|
2012-11-08 19:06:44 +00:00
|
|
|
|
2013-01-31 21:14:37 +00:00
|
|
|
GST_INFO_OBJECT (mssdemux, "Received manifest buffer, total size is %i bytes",
|
2013-04-23 15:08:38 +00:00
|
|
|
(gint) gst_buffer_get_size (mssdemux->manifest_buffer));
|
2013-01-31 21:14:37 +00:00
|
|
|
|
2012-11-08 19:06:44 +00:00
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
2012-11-19 20:53:16 +00:00
|
|
|
static void
|
|
|
|
gst_mss_demux_start (GstMssDemux * mssdemux)
|
|
|
|
{
|
|
|
|
GSList *iter;
|
|
|
|
|
|
|
|
GST_INFO_OBJECT (mssdemux, "Starting streams' tasks");
|
|
|
|
for (iter = mssdemux->streams; iter; iter = g_slist_next (iter)) {
|
|
|
|
GstMssDemuxStream *stream = iter->data;
|
2013-01-14 16:21:10 +00:00
|
|
|
gst_task_start (stream->download_task);
|
2012-11-19 20:53:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-28 03:48:33 +00:00
|
|
|
static gboolean
|
|
|
|
gst_mss_demux_push_src_event (GstMssDemux * mssdemux, GstEvent * event)
|
|
|
|
{
|
|
|
|
GSList *iter;
|
|
|
|
gboolean ret = TRUE;
|
|
|
|
|
|
|
|
for (iter = mssdemux->streams; iter; iter = g_slist_next (iter)) {
|
|
|
|
GstMssDemuxStream *stream = iter->data;
|
|
|
|
gst_event_ref (event);
|
|
|
|
ret = ret & gst_pad_push_event (stream->pad, event);
|
|
|
|
}
|
2013-02-01 22:27:19 +00:00
|
|
|
gst_event_unref (event);
|
2012-12-28 03:48:33 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-11-08 19:06:44 +00:00
|
|
|
static gboolean
|
2013-04-16 22:35:03 +00:00
|
|
|
gst_mss_demux_event (GstPad * pad, GstObject * parent, GstEvent * event)
|
2012-11-08 19:06:44 +00:00
|
|
|
{
|
2013-04-16 22:35:03 +00:00
|
|
|
GstMssDemux *mssdemux = GST_MSS_DEMUX_CAST (parent);
|
2012-11-08 19:06:44 +00:00
|
|
|
gboolean forward = TRUE;
|
|
|
|
gboolean ret = TRUE;
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
2013-02-01 22:44:04 +00:00
|
|
|
case GST_EVENT_FLUSH_STOP:
|
|
|
|
gst_mss_demux_reset (mssdemux);
|
|
|
|
break;
|
2012-11-08 19:06:44 +00:00
|
|
|
case GST_EVENT_EOS:
|
|
|
|
if (mssdemux->manifest_buffer == NULL) {
|
|
|
|
GST_WARNING_OBJECT (mssdemux, "Received EOS without a manifest.");
|
|
|
|
break;
|
|
|
|
}
|
2013-01-31 21:14:37 +00:00
|
|
|
GST_INFO_OBJECT (mssdemux, "Received EOS");
|
2012-11-08 19:06:44 +00:00
|
|
|
|
2013-01-16 18:28:19 +00:00
|
|
|
if (gst_mss_demux_process_manifest (mssdemux))
|
|
|
|
gst_mss_demux_start (mssdemux);
|
2012-11-08 19:06:44 +00:00
|
|
|
forward = FALSE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (forward) {
|
2013-04-16 22:35:03 +00:00
|
|
|
ret = gst_pad_event_default (pad, parent, event);
|
2012-11-08 19:06:44 +00:00
|
|
|
} else {
|
|
|
|
gst_event_unref (event);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-01-10 18:16:36 +00:00
|
|
|
static void
|
|
|
|
gst_mss_demux_stop_tasks (GstMssDemux * mssdemux, gboolean immediate)
|
|
|
|
{
|
|
|
|
GSList *iter;
|
2013-01-14 16:21:10 +00:00
|
|
|
|
2013-12-19 17:29:42 +00:00
|
|
|
GST_OBJECT_LOCK (mssdemux);
|
2013-01-10 18:16:36 +00:00
|
|
|
for (iter = mssdemux->streams; iter; iter = g_slist_next (iter)) {
|
|
|
|
GstMssDemuxStream *stream = iter->data;
|
|
|
|
|
2013-12-17 19:31:52 +00:00
|
|
|
gst_task_stop (stream->download_task);
|
2013-02-19 18:17:53 +00:00
|
|
|
stream->cancelled = TRUE;
|
2013-01-10 18:16:36 +00:00
|
|
|
if (immediate)
|
2014-05-12 16:40:19 +00:00
|
|
|
g_cond_signal (&stream->fragment_download_cond);
|
2013-01-10 18:16:36 +00:00
|
|
|
}
|
2013-12-19 17:29:42 +00:00
|
|
|
GST_OBJECT_UNLOCK (mssdemux);
|
2013-01-14 16:21:10 +00:00
|
|
|
|
2013-01-10 18:16:36 +00:00
|
|
|
for (iter = mssdemux->streams; iter; iter = g_slist_next (iter)) {
|
|
|
|
GstMssDemuxStream *stream = iter->data;
|
2013-12-17 19:31:52 +00:00
|
|
|
|
|
|
|
gst_task_join (stream->download_task);
|
2013-02-19 18:17:53 +00:00
|
|
|
stream->download_error_count = 0;
|
2013-01-10 18:16:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_mss_demux_restart_tasks (GstMssDemux * mssdemux)
|
|
|
|
{
|
|
|
|
GSList *iter;
|
|
|
|
for (iter = mssdemux->streams; iter; iter = g_slist_next (iter)) {
|
|
|
|
GstMssDemuxStream *stream = iter->data;
|
2013-12-17 19:31:52 +00:00
|
|
|
stream->cancelled = FALSE;
|
2013-01-14 16:21:10 +00:00
|
|
|
gst_task_start (stream->download_task);
|
2013-01-10 18:16:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-28 03:48:33 +00:00
|
|
|
static gboolean
|
2013-04-16 22:35:03 +00:00
|
|
|
gst_mss_demux_src_event (GstPad * pad, GstObject * parent, GstEvent * event)
|
2012-12-28 03:48:33 +00:00
|
|
|
{
|
|
|
|
GstMssDemux *mssdemux;
|
|
|
|
|
2013-04-16 22:35:03 +00:00
|
|
|
mssdemux = GST_MSS_DEMUX_CAST (parent);
|
2012-12-28 03:48:33 +00:00
|
|
|
|
|
|
|
switch (event->type) {
|
|
|
|
case GST_EVENT_SEEK:
|
|
|
|
{
|
|
|
|
gdouble rate;
|
|
|
|
GstFormat format;
|
|
|
|
GstSeekFlags flags;
|
|
|
|
GstSeekType start_type, stop_type;
|
|
|
|
gint64 start, stop;
|
|
|
|
GstEvent *newsegment;
|
|
|
|
GSList *iter;
|
2013-04-16 22:35:03 +00:00
|
|
|
gboolean update;
|
2012-12-28 03:48:33 +00:00
|
|
|
|
|
|
|
GST_INFO_OBJECT (mssdemux, "Received GST_EVENT_SEEK");
|
|
|
|
|
|
|
|
gst_event_parse_seek (event, &rate, &format, &flags, &start_type, &start,
|
|
|
|
&stop_type, &stop);
|
|
|
|
|
|
|
|
if (format != GST_FORMAT_TIME)
|
2013-02-01 22:27:19 +00:00
|
|
|
goto not_supported;
|
2012-12-28 03:48:33 +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));
|
|
|
|
|
|
|
|
if (flags & GST_SEEK_FLAG_FLUSH) {
|
|
|
|
GstEvent *flush = gst_event_new_flush_start ();
|
|
|
|
GST_DEBUG_OBJECT (mssdemux, "sending flush start");
|
|
|
|
|
|
|
|
gst_event_set_seqnum (flush, gst_event_get_seqnum (event));
|
|
|
|
gst_mss_demux_push_src_event (mssdemux, flush);
|
|
|
|
}
|
|
|
|
|
2013-01-10 18:16:36 +00:00
|
|
|
gst_mss_demux_stop_tasks (mssdemux, TRUE);
|
2012-12-28 03:48:33 +00:00
|
|
|
|
|
|
|
if (!gst_mss_manifest_seek (mssdemux->manifest, start)) {;
|
|
|
|
GST_WARNING_OBJECT (mssdemux, "Could not find seeked fragment");
|
2013-02-01 22:27:19 +00:00
|
|
|
goto not_supported;
|
2012-12-28 03:48:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (iter = mssdemux->streams; iter; iter = g_slist_next (iter)) {
|
|
|
|
GstMssDemuxStream *stream = iter->data;
|
|
|
|
|
2013-01-14 16:21:10 +00:00
|
|
|
stream->eos = FALSE;
|
2013-11-12 12:58:31 +00:00
|
|
|
if (flags & GST_SEEK_FLAG_FLUSH) {
|
|
|
|
stream->last_ret = GST_FLOW_OK;
|
|
|
|
}
|
2013-12-17 16:16:58 +00:00
|
|
|
|
|
|
|
gst_segment_do_seek (&stream->segment, rate, format, flags,
|
|
|
|
start_type, start, stop_type, stop, &update);
|
|
|
|
|
|
|
|
newsegment = gst_event_new_segment (&stream->segment);
|
|
|
|
gst_event_set_seqnum (newsegment, gst_event_get_seqnum (event));
|
2014-05-12 16:40:19 +00:00
|
|
|
if (stream->pending_segment)
|
|
|
|
gst_event_unref (stream->pending_segment);
|
|
|
|
stream->pending_segment = newsegment;
|
2012-12-28 03:48:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & GST_SEEK_FLAG_FLUSH) {
|
2013-04-16 22:35:03 +00:00
|
|
|
GstEvent *flush = gst_event_new_flush_stop (TRUE);
|
2012-12-28 03:48:33 +00:00
|
|
|
GST_DEBUG_OBJECT (mssdemux, "sending flush stop");
|
|
|
|
|
|
|
|
gst_event_set_seqnum (flush, gst_event_get_seqnum (event));
|
|
|
|
gst_mss_demux_push_src_event (mssdemux, flush);
|
|
|
|
}
|
|
|
|
|
2013-01-10 18:16:36 +00:00
|
|
|
gst_mss_demux_restart_tasks (mssdemux);
|
2012-12-28 03:48:33 +00:00
|
|
|
|
2013-02-01 22:27:19 +00:00
|
|
|
gst_event_unref (event);
|
2012-12-28 03:48:33 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2013-11-12 12:58:31 +00:00
|
|
|
case GST_EVENT_RECONFIGURE:{
|
|
|
|
GSList *iter;
|
|
|
|
|
|
|
|
for (iter = mssdemux->streams; iter; iter = g_slist_next (iter)) {
|
|
|
|
GstMssDemuxStream *stream = iter->data;
|
|
|
|
|
|
|
|
if (stream->pad == pad) {
|
2013-12-10 18:41:00 +00:00
|
|
|
GST_OBJECT_LOCK (mssdemux);
|
2013-12-16 19:14:24 +00:00
|
|
|
|
|
|
|
if (stream->last_ret == GST_FLOW_NOT_LINKED) {
|
2013-12-13 20:31:11 +00:00
|
|
|
GST_DEBUG_OBJECT (stream->pad, "Received reconfigure");
|
2013-11-12 12:58:31 +00:00
|
|
|
stream->restart_download = TRUE;
|
|
|
|
gst_task_start (stream->download_task);
|
|
|
|
}
|
2013-12-10 18:41:00 +00:00
|
|
|
GST_OBJECT_UNLOCK (mssdemux);
|
2013-11-12 12:58:31 +00:00
|
|
|
gst_event_unref (event);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2012-12-28 03:48:33 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-04-16 22:35:03 +00:00
|
|
|
return gst_pad_event_default (pad, parent, event);
|
2013-02-01 22:27:19 +00:00
|
|
|
|
|
|
|
not_supported:
|
|
|
|
gst_event_unref (event);
|
|
|
|
return FALSE;
|
2012-12-28 03:48:33 +00:00
|
|
|
}
|
|
|
|
|
2012-12-26 19:19:14 +00:00
|
|
|
static gboolean
|
2013-04-16 22:35:03 +00:00
|
|
|
gst_mss_demux_src_query (GstPad * pad, GstObject * parent, GstQuery * query)
|
2012-12-26 19:19:14 +00:00
|
|
|
{
|
|
|
|
GstMssDemux *mssdemux;
|
|
|
|
gboolean ret = FALSE;
|
|
|
|
|
|
|
|
if (query == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
2013-04-16 22:35:03 +00:00
|
|
|
mssdemux = GST_MSS_DEMUX (parent);
|
2012-12-26 19:19:14 +00:00
|
|
|
|
|
|
|
switch (query->type) {
|
|
|
|
case GST_QUERY_DURATION:{
|
|
|
|
GstClockTime duration = -1;
|
|
|
|
GstFormat fmt;
|
|
|
|
|
|
|
|
gst_query_parse_duration (query, &fmt, NULL);
|
|
|
|
if (fmt == GST_FORMAT_TIME && mssdemux->manifest) {
|
2012-12-28 03:48:33 +00:00
|
|
|
/* TODO should we use the streams accumulated duration or the main manifest duration? */
|
|
|
|
duration = gst_mss_manifest_get_gst_duration (mssdemux->manifest);
|
2012-12-26 19:19:14 +00:00
|
|
|
|
|
|
|
if (GST_CLOCK_TIME_IS_VALID (duration) && duration > 0) {
|
|
|
|
gst_query_set_duration (query, GST_FORMAT_TIME, duration);
|
|
|
|
ret = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
GST_INFO_OBJECT (mssdemux, "GST_QUERY_DURATION returns %s with duration %"
|
|
|
|
GST_TIME_FORMAT, ret ? "TRUE" : "FALSE", GST_TIME_ARGS (duration));
|
|
|
|
break;
|
|
|
|
}
|
2013-01-17 19:20:10 +00:00
|
|
|
case GST_QUERY_LATENCY:{
|
|
|
|
gboolean live = FALSE;
|
|
|
|
|
|
|
|
live = mssdemux->manifest
|
|
|
|
&& gst_mss_manifest_is_live (mssdemux->manifest);
|
|
|
|
|
|
|
|
gst_query_set_latency (query, live, 0, -1);
|
2012-12-26 19:19:14 +00:00
|
|
|
ret = TRUE;
|
|
|
|
break;
|
2013-01-17 19:20:10 +00:00
|
|
|
}
|
2012-12-28 03:48:33 +00:00
|
|
|
case GST_QUERY_SEEKING:{
|
|
|
|
GstFormat fmt;
|
|
|
|
gint64 stop = -1;
|
|
|
|
|
2014-04-09 16:28:49 +00:00
|
|
|
if (!mssdemux->manifest) {
|
|
|
|
return FALSE; /* no seeking without manifest */
|
|
|
|
} else if (gst_mss_manifest_is_live (mssdemux->manifest)) {
|
2013-01-17 19:20:10 +00:00
|
|
|
return FALSE; /* no live seeking */
|
|
|
|
}
|
|
|
|
|
2012-12-28 03:48:33 +00:00
|
|
|
gst_query_parse_seeking (query, &fmt, NULL, NULL, NULL);
|
|
|
|
GST_INFO_OBJECT (mssdemux, "Received GST_QUERY_SEEKING with format %d",
|
|
|
|
fmt);
|
|
|
|
if (fmt == GST_FORMAT_TIME) {
|
|
|
|
GstClockTime duration;
|
|
|
|
duration = gst_mss_manifest_get_gst_duration (mssdemux->manifest);
|
|
|
|
if (GST_CLOCK_TIME_IS_VALID (duration) && duration > 0)
|
|
|
|
stop = duration;
|
|
|
|
gst_query_set_seeking (query, fmt, TRUE, 0, stop);
|
|
|
|
ret = TRUE;
|
|
|
|
GST_INFO_OBJECT (mssdemux, "GST_QUERY_SEEKING returning with stop : %"
|
|
|
|
GST_TIME_FORMAT, GST_TIME_ARGS (stop));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2012-12-26 19:19:14 +00:00
|
|
|
default:
|
|
|
|
/* Don't fordward queries upstream because of the special nature of this
|
|
|
|
* "demuxer", which relies on the upstream element only to be fed
|
|
|
|
* the Manifest
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_set_src_pad_functions (GstPad * pad)
|
|
|
|
{
|
|
|
|
gst_pad_set_query_function (pad, GST_DEBUG_FUNCPTR (gst_mss_demux_src_query));
|
2012-12-28 03:48:33 +00:00
|
|
|
gst_pad_set_event_function (pad, GST_DEBUG_FUNCPTR (gst_mss_demux_src_event));
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
_set_src_pad_functions (srcpad);
|
|
|
|
return srcpad;
|
|
|
|
}
|
|
|
|
|
2012-11-09 19:47:54 +00:00
|
|
|
static void
|
|
|
|
gst_mss_demux_create_streams (GstMssDemux * mssdemux)
|
|
|
|
{
|
|
|
|
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"));
|
|
|
|
return;
|
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;
|
2013-01-10 18:16:36 +00:00
|
|
|
|
|
|
|
srcpad = _create_pad (mssdemux, manifeststream);
|
2012-11-14 20:19:35 +00:00
|
|
|
|
|
|
|
if (!srcpad) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-11-16 20:30:12 +00:00
|
|
|
stream = gst_mss_demux_stream_new (mssdemux, manifeststream, srcpad);
|
2014-05-12 16:40:19 +00:00
|
|
|
gst_pad_set_element_private (srcpad, stream);
|
2013-01-08 20:55:49 +00:00
|
|
|
gst_mss_stream_set_active (manifeststream, TRUE);
|
2012-11-14 20:19:35 +00:00
|
|
|
mssdemux->streams = g_slist_append (mssdemux->streams, stream);
|
|
|
|
}
|
2013-01-08 21:01:17 +00:00
|
|
|
|
|
|
|
/* select initial bitrates */
|
2013-01-10 18:16:36 +00:00
|
|
|
GST_OBJECT_LOCK (mssdemux);
|
2013-04-23 15:08:38 +00:00
|
|
|
GST_INFO_OBJECT (mssdemux, "Changing max bitrate to %" G_GUINT64_FORMAT,
|
2013-01-10 18:16:36 +00:00
|
|
|
mssdemux->connection_speed);
|
2013-01-08 21:01:17 +00:00
|
|
|
gst_mss_manifest_change_bitrate (mssdemux->manifest,
|
|
|
|
mssdemux->connection_speed);
|
2013-01-10 18:16:36 +00:00
|
|
|
mssdemux->update_bitrates = FALSE;
|
|
|
|
GST_OBJECT_UNLOCK (mssdemux);
|
2012-11-14 20:19:35 +00:00
|
|
|
}
|
|
|
|
|
2013-02-08 03:51:30 +00:00
|
|
|
static GstCaps *
|
|
|
|
create_mss_caps (GstMssDemuxStream * stream, GstCaps * caps)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2013-01-04 20:00:34 +00:00
|
|
|
static gboolean
|
2012-11-14 20:19:35 +00:00
|
|
|
gst_mss_demux_expose_stream (GstMssDemux * mssdemux, GstMssDemuxStream * stream)
|
|
|
|
{
|
|
|
|
GstCaps *caps;
|
2012-12-20 04:07:18 +00:00
|
|
|
GstCaps *media_caps;
|
2012-11-14 20:19:35 +00:00
|
|
|
GstPad *pad = stream->pad;
|
|
|
|
|
2012-12-20 04:07:18 +00:00
|
|
|
media_caps = gst_mss_stream_get_caps (stream->manifest_stream);
|
2012-11-14 20:19:35 +00:00
|
|
|
|
2013-01-04 20:00:34 +00:00
|
|
|
if (media_caps) {
|
2013-05-14 19:37:16 +00:00
|
|
|
gchar *name = gst_pad_get_name (pad);
|
2013-11-14 14:23:42 +00:00
|
|
|
const gchar *lang;
|
2013-07-23 08:11:49 +00:00
|
|
|
GstEvent *event;
|
2013-05-14 19:37:16 +00:00
|
|
|
gchar *stream_id;
|
2013-04-16 22:35:03 +00:00
|
|
|
gst_pad_set_active (pad, TRUE);
|
|
|
|
|
2013-02-08 03:51:30 +00:00
|
|
|
caps = create_mss_caps (stream, media_caps);
|
2013-01-04 20:00:34 +00:00
|
|
|
gst_caps_unref (media_caps);
|
2013-05-14 19:37:16 +00:00
|
|
|
|
|
|
|
stream_id =
|
|
|
|
gst_pad_create_stream_id (pad, GST_ELEMENT_CAST (mssdemux), name);
|
2013-07-23 08:11:49 +00:00
|
|
|
|
|
|
|
event =
|
|
|
|
gst_pad_get_sticky_event (mssdemux->sinkpad, GST_EVENT_STREAM_START, 0);
|
|
|
|
if (event) {
|
|
|
|
if (gst_event_parse_group_id (event, &mssdemux->group_id))
|
|
|
|
mssdemux->have_group_id = TRUE;
|
|
|
|
else
|
|
|
|
mssdemux->have_group_id = FALSE;
|
|
|
|
gst_event_unref (event);
|
|
|
|
} else if (!mssdemux->have_group_id) {
|
|
|
|
mssdemux->have_group_id = TRUE;
|
|
|
|
mssdemux->group_id = gst_util_group_id_next ();
|
|
|
|
}
|
|
|
|
event = gst_event_new_stream_start (stream_id);
|
|
|
|
if (mssdemux->have_group_id)
|
|
|
|
gst_event_set_group_id (event, mssdemux->group_id);
|
|
|
|
|
|
|
|
gst_pad_push_event (pad, event);
|
2013-05-14 19:37:16 +00:00
|
|
|
g_free (stream_id);
|
|
|
|
g_free (name);
|
|
|
|
|
2012-11-14 20:19:35 +00:00
|
|
|
gst_pad_set_caps (pad, caps);
|
2013-02-08 03:51:30 +00:00
|
|
|
stream->caps = 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);
|
|
|
|
gst_pad_push_event (stream->pad, gst_event_new_tag (tags));
|
|
|
|
}
|
|
|
|
|
2013-12-17 16:16:58 +00:00
|
|
|
gst_pad_push_event (stream->pad, gst_event_new_segment (&stream->segment));
|
|
|
|
|
2012-11-14 20:19:35 +00:00
|
|
|
GST_INFO_OBJECT (mssdemux, "Adding srcpad %s:%s with caps %" GST_PTR_FORMAT,
|
|
|
|
GST_DEBUG_PAD_NAME (pad), caps);
|
2012-11-22 16:01:09 +00:00
|
|
|
gst_object_ref (pad);
|
2013-05-14 19:37:16 +00:00
|
|
|
|
2012-11-14 20:19:35 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT_CAST (mssdemux), pad);
|
|
|
|
} else {
|
2013-01-04 20:00:34 +00:00
|
|
|
GST_WARNING_OBJECT (mssdemux,
|
|
|
|
"Couldn't get caps from manifest stream %p %s, not exposing it", stream,
|
|
|
|
GST_PAD_NAME (stream->pad));
|
|
|
|
return FALSE;
|
2012-11-09 19:47:54 +00:00
|
|
|
}
|
2013-01-04 20:00:34 +00:00
|
|
|
return TRUE;
|
2012-11-09 19:47:54 +00:00
|
|
|
}
|
|
|
|
|
2013-01-16 18:28:19 +00:00
|
|
|
static gboolean
|
2012-11-08 19:06:44 +00:00
|
|
|
gst_mss_demux_process_manifest (GstMssDemux * mssdemux)
|
|
|
|
{
|
2012-11-09 19:47:54 +00:00
|
|
|
GstQuery *query;
|
|
|
|
gchar *uri = NULL;
|
|
|
|
gboolean ret;
|
2012-11-14 20:19:35 +00:00
|
|
|
GSList *iter;
|
2012-11-09 19:47:54 +00:00
|
|
|
|
2013-01-16 18:28:19 +00:00
|
|
|
g_return_val_if_fail (mssdemux->manifest_buffer != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (mssdemux->manifest == NULL, FALSE);
|
2012-11-08 19:06:44 +00:00
|
|
|
|
2012-11-09 19:47:54 +00:00
|
|
|
query = gst_query_new_uri ();
|
|
|
|
ret = gst_pad_peer_query (mssdemux->sinkpad, query);
|
|
|
|
if (ret) {
|
2012-11-19 20:53:16 +00:00
|
|
|
gchar *baseurl_end;
|
2012-11-09 19:47:54 +00:00
|
|
|
gst_query_parse_uri (query, &uri);
|
2012-11-19 20:53:16 +00:00
|
|
|
GST_INFO_OBJECT (mssdemux, "Upstream is using URI: %s", uri);
|
|
|
|
|
2013-01-17 19:20:10 +00:00
|
|
|
mssdemux->manifest_uri = g_strdup (uri);
|
2012-11-19 20:53:16 +00:00
|
|
|
baseurl_end = g_strrstr (uri, "/Manifest");
|
2013-11-11 19:35:35 +00:00
|
|
|
if (baseurl_end == NULL) {
|
|
|
|
/* second try */
|
|
|
|
baseurl_end = g_strrstr (uri, "/manifest");
|
|
|
|
}
|
|
|
|
|
2012-11-19 20:53:16 +00:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
|
|
|
mssdemux->base_url = uri;
|
2012-11-09 19:47:54 +00:00
|
|
|
}
|
|
|
|
gst_query_unref (query);
|
|
|
|
|
2013-01-16 18:28:19 +00:00
|
|
|
if (mssdemux->base_url == NULL) {
|
|
|
|
GST_ELEMENT_ERROR (mssdemux, RESOURCE, NOT_FOUND,
|
|
|
|
(_("Couldn't get the Manifest's URI")),
|
|
|
|
("need to get the manifest's URI from upstream elements"));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-01-31 21:14:37 +00:00
|
|
|
GST_INFO_OBJECT (mssdemux, "Received manifest: %i bytes",
|
2013-04-23 15:08:38 +00:00
|
|
|
(gint) gst_buffer_get_size (mssdemux->manifest_buffer));
|
2013-01-31 21:14:37 +00:00
|
|
|
|
2012-11-08 19:06:44 +00:00
|
|
|
mssdemux->manifest = gst_mss_manifest_new (mssdemux->manifest_buffer);
|
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
|
|
|
}
|
|
|
|
|
2013-01-17 19:20:10 +00:00
|
|
|
GST_INFO_OBJECT (mssdemux, "Live stream: %d",
|
|
|
|
gst_mss_manifest_is_live (mssdemux->manifest));
|
|
|
|
|
2012-11-09 19:47:54 +00:00
|
|
|
gst_mss_demux_create_streams (mssdemux);
|
2013-01-04 20:00:34 +00:00
|
|
|
for (iter = mssdemux->streams; iter;) {
|
|
|
|
GSList *current = iter;
|
|
|
|
GstMssDemuxStream *stream = iter->data;
|
|
|
|
iter = g_slist_next (iter); /* do it ourselves as we want it done in the beginning of the loop */
|
|
|
|
if (!gst_mss_demux_expose_stream (mssdemux, stream)) {
|
|
|
|
gst_mss_demux_stream_free (stream);
|
|
|
|
mssdemux->streams = g_slist_delete_link (mssdemux->streams, current);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mssdemux->streams) {
|
|
|
|
/* no streams */
|
|
|
|
GST_WARNING_OBJECT (mssdemux, "Couldn't identify the caps for any of the "
|
|
|
|
"streams found in the manifest");
|
|
|
|
GST_ELEMENT_ERROR (mssdemux, STREAM, DEMUX,
|
|
|
|
(_("This file contains no playable streams.")),
|
|
|
|
("No known stream formats found at the Manifest"));
|
2013-01-16 18:28:19 +00:00
|
|
|
return FALSE;
|
2012-11-14 20:19:35 +00:00
|
|
|
}
|
2013-01-08 20:54:57 +00:00
|
|
|
|
|
|
|
gst_element_no_more_pads (GST_ELEMENT_CAST (mssdemux));
|
2013-01-16 18:28:19 +00:00
|
|
|
return TRUE;
|
2012-11-08 19:06:44 +00:00
|
|
|
}
|
2012-11-16 20:30:12 +00:00
|
|
|
|
2013-01-17 19:20:10 +00:00
|
|
|
static void
|
|
|
|
gst_mss_demux_reload_manifest (GstMssDemux * mssdemux)
|
|
|
|
{
|
|
|
|
GstUriDownloader *downloader;
|
|
|
|
GstFragment *manifest_data;
|
|
|
|
GstBuffer *manifest_buffer;
|
|
|
|
|
|
|
|
downloader = gst_uri_downloader_new ();
|
|
|
|
|
|
|
|
manifest_data =
|
2014-05-02 08:43:06 +00:00
|
|
|
gst_uri_downloader_fetch_uri (downloader, mssdemux->manifest_uri, NULL,
|
2014-05-05 07:38:14 +00:00
|
|
|
TRUE, TRUE, TRUE, NULL);
|
2013-01-17 19:20:10 +00:00
|
|
|
manifest_buffer = gst_fragment_get_buffer (manifest_data);
|
|
|
|
g_object_unref (manifest_data);
|
|
|
|
|
|
|
|
gst_mss_manifest_reload_fragments (mssdemux->manifest, manifest_buffer);
|
|
|
|
gst_buffer_replace (&mssdemux->manifest_buffer, manifest_buffer);
|
|
|
|
gst_buffer_unref (manifest_buffer);
|
|
|
|
|
|
|
|
g_object_unref (downloader);
|
|
|
|
}
|
|
|
|
|
2013-12-16 19:14:24 +00:00
|
|
|
static GstEvent *
|
2013-02-08 03:51:30 +00:00
|
|
|
gst_mss_demux_reconfigure_stream (GstMssDemuxStream * stream)
|
|
|
|
{
|
2013-12-16 19:14:24 +00:00
|
|
|
GstEvent *capsevent = NULL;
|
2013-02-08 03:51:30 +00:00
|
|
|
GstMssDemux *mssdemux = stream->parent;
|
2014-05-12 17:18:13 +00:00
|
|
|
guint64 bitrate = 0;
|
|
|
|
|
|
|
|
if (stream->download_total_time)
|
|
|
|
bitrate =
|
|
|
|
(stream->download_total_bytes * 8) /
|
|
|
|
((double) stream->download_total_time / G_GUINT64_CONSTANT (1000000));
|
|
|
|
|
|
|
|
if (stream->current_download_rate != -1)
|
|
|
|
bitrate = (stream->current_download_rate + bitrate * 3) / 4;
|
|
|
|
if (bitrate > G_MAXINT)
|
|
|
|
bitrate = G_MAXINT;
|
|
|
|
stream->current_download_rate = bitrate;
|
|
|
|
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-05-12 17:18:13 +00:00
|
|
|
"Current stream download bitrate %" G_GUINT64_FORMAT, bitrate);
|
2013-02-08 03:51:30 +00:00
|
|
|
|
2014-05-12 17:18:13 +00:00
|
|
|
if (gst_mss_stream_select_bitrate (stream->manifest_stream, bitrate)) {
|
2013-02-08 03:51:30 +00:00
|
|
|
GstCaps *caps;
|
|
|
|
caps = gst_mss_stream_get_caps (stream->manifest_stream);
|
|
|
|
|
2013-12-13 20:31:11 +00:00
|
|
|
GST_DEBUG_OBJECT (stream->pad,
|
|
|
|
"Starting streams reconfiguration due to bitrate changes");
|
2013-02-08 03:51:30 +00:00
|
|
|
if (stream->caps)
|
|
|
|
gst_caps_unref (stream->caps);
|
|
|
|
stream->caps = create_mss_caps (stream, caps);
|
|
|
|
|
2013-12-13 20:31:11 +00:00
|
|
|
GST_DEBUG_OBJECT (stream->pad,
|
|
|
|
"Stream changed bitrate to %" G_GUINT64_FORMAT " caps: %"
|
|
|
|
GST_PTR_FORMAT,
|
2013-02-08 03:51:30 +00:00
|
|
|
gst_mss_stream_get_current_bitrate (stream->manifest_stream), caps);
|
2013-04-16 22:35:03 +00:00
|
|
|
|
2014-05-12 16:40:19 +00:00
|
|
|
gst_caps_unref (caps);
|
|
|
|
|
2013-04-16 22:35:03 +00:00
|
|
|
capsevent = gst_event_new_caps (stream->caps);
|
2013-12-13 20:31:11 +00:00
|
|
|
GST_DEBUG_OBJECT (stream->pad, "Finished streams reconfiguration");
|
2013-02-08 03:51:30 +00:00
|
|
|
}
|
2013-12-16 19:14:24 +00:00
|
|
|
return capsevent;
|
2013-01-14 16:21:10 +00:00
|
|
|
}
|
|
|
|
|
2013-01-10 19:26:48 +00:00
|
|
|
static GstFlowReturn
|
2014-05-12 16:40:19 +00:00
|
|
|
_src_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
|
|
|
|
{
|
|
|
|
GstPad *srcpad = (GstPad *) parent;
|
|
|
|
GstMssDemux *demux = (GstMssDemux *) GST_PAD_PARENT (srcpad);
|
|
|
|
GstMssDemuxStream *stream = gst_pad_get_element_private (srcpad);
|
|
|
|
GstFlowReturn ret;
|
|
|
|
gboolean discont = FALSE;
|
|
|
|
|
|
|
|
if (stream->starting_fragment) {
|
|
|
|
#if 0
|
|
|
|
if (demux->segment.rate < 0)
|
|
|
|
/* Set DISCONT flag for every first buffer in reverse playback mode
|
|
|
|
* as each fragment for its own has to be reversed */
|
|
|
|
discont = TRUE;
|
|
|
|
#endif
|
|
|
|
stream->starting_fragment = FALSE;
|
|
|
|
|
|
|
|
GST_BUFFER_PTS (buffer) =
|
|
|
|
gst_mss_stream_get_fragment_gst_timestamp (stream->manifest_stream);
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (stream->pad, "set fragment pts=%" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (GST_BUFFER_PTS (buffer)));
|
|
|
|
|
|
|
|
if (stream->pending_segment) {
|
|
|
|
/* And send a newsegment */
|
|
|
|
gst_pad_push_event (stream->pad, stream->pending_segment);
|
|
|
|
stream->pending_segment = NULL;
|
|
|
|
}
|
|
|
|
#if 0
|
|
|
|
stream->position = demux->segment.position = GST_BUFFER_PTS (buffer);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
} else {
|
|
|
|
GST_BUFFER_PTS (buffer) = GST_CLOCK_TIME_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (discont) {
|
|
|
|
GST_DEBUG_OBJECT (stream->pad, "Marking fragment as discontinuous");
|
|
|
|
GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_DISCONT);
|
|
|
|
} else {
|
|
|
|
GST_BUFFER_FLAG_UNSET (buffer, GST_BUFFER_FLAG_DISCONT);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
GST_BUFFER_DURATION (buffer) =
|
|
|
|
gst_mss_stream_get_fragment_gst_duration (stream->manifest_stream);
|
|
|
|
#endif
|
|
|
|
GST_BUFFER_DURATION (buffer) = GST_CLOCK_TIME_NONE;
|
|
|
|
GST_BUFFER_DTS (buffer) = GST_CLOCK_TIME_NONE;
|
|
|
|
|
|
|
|
/* accumulate time and size to get this chunk */
|
|
|
|
stream->download_total_time +=
|
|
|
|
g_get_monotonic_time () - stream->download_start_time;
|
|
|
|
stream->download_total_bytes += gst_buffer_get_size (buffer);
|
|
|
|
|
|
|
|
ret = gst_proxy_pad_chain_default (pad, parent, buffer);
|
|
|
|
stream->download_start_time = g_get_monotonic_time ();
|
|
|
|
GST_LOG_OBJECT (pad, "Chain res: %d %s", ret, gst_flow_get_name (ret));
|
|
|
|
|
|
|
|
if (ret != GST_FLOW_OK) {
|
|
|
|
if (ret < GST_FLOW_EOS) {
|
|
|
|
GST_ELEMENT_ERROR (demux, STREAM, FAILED, (NULL),
|
|
|
|
("stream stopped, reason %s", gst_flow_get_name (ret)));
|
|
|
|
|
|
|
|
/* TODO push this on all pads */
|
|
|
|
gst_pad_push_event (stream->pad, gst_event_new_eos ());
|
|
|
|
} else {
|
|
|
|
GST_DEBUG_OBJECT (stream->pad, "stream stopped, reason %s",
|
|
|
|
gst_flow_get_name (ret));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO properly stop tasks */
|
|
|
|
/* gst_hls_demux_pause_tasks (demux); */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* avoid having the source handle the same error again */
|
|
|
|
stream->last_ret = ret;
|
|
|
|
ret = GST_FLOW_OK;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
_src_event (GstPad * pad, GstObject * parent, GstEvent * event)
|
|
|
|
{
|
|
|
|
GstPad *srcpad = GST_PAD_CAST (parent);
|
|
|
|
GstMssDemuxStream *stream = gst_pad_get_element_private (srcpad);
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_EOS:
|
|
|
|
g_cond_signal (&stream->fragment_download_cond);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_event_unref (event);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
_src_query (GstPad * pad, GstObject * parent, GstQuery * query)
|
|
|
|
{
|
|
|
|
switch (GST_QUERY_TYPE (query)) {
|
|
|
|
case GST_QUERY_ALLOCATION:
|
|
|
|
return FALSE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return gst_pad_query_default (pad, parent, query);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_mss_demux_stream_update_source (GstMssDemuxStream * stream,
|
|
|
|
const gchar * uri, const gchar * referer, gboolean refresh,
|
|
|
|
gboolean allow_cache)
|
|
|
|
{
|
|
|
|
GstMssDemux *demux = stream->parent;
|
|
|
|
|
|
|
|
if (!gst_uri_is_valid (uri)) {
|
|
|
|
GST_WARNING_OBJECT (stream->pad, "Invalid URI: %s", uri);
|
|
|
|
stream->last_ret = GST_FLOW_ERROR;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stream->src != NULL) {
|
|
|
|
gchar *old_protocol, *new_protocol;
|
|
|
|
gchar *old_uri;
|
|
|
|
|
|
|
|
old_uri = gst_uri_handler_get_uri (GST_URI_HANDLER (stream->src));
|
|
|
|
old_protocol = gst_uri_get_protocol (old_uri);
|
|
|
|
new_protocol = gst_uri_get_protocol (uri);
|
|
|
|
|
|
|
|
if (!g_str_equal (old_protocol, new_protocol)) {
|
|
|
|
gst_object_unref (stream->src_srcpad);
|
|
|
|
gst_element_set_state (stream->src, GST_STATE_NULL);
|
|
|
|
gst_bin_remove (GST_BIN_CAST (demux), stream->src);
|
|
|
|
stream->src = NULL;
|
|
|
|
stream->src_srcpad = NULL;
|
|
|
|
GST_DEBUG_OBJECT (demux, "Can't re-use old source element");
|
|
|
|
} else {
|
|
|
|
GError *err = NULL;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (demux, "Re-using old source element");
|
|
|
|
if (!gst_uri_handler_set_uri (GST_URI_HANDLER (stream->src), uri, &err)) {
|
|
|
|
GST_DEBUG_OBJECT (demux, "Failed to re-use old source element: %s",
|
|
|
|
err->message);
|
|
|
|
g_clear_error (&err);
|
|
|
|
gst_element_set_state (stream->src, GST_STATE_NULL);
|
|
|
|
gst_bin_remove (GST_BIN_CAST (demux), stream->src);
|
|
|
|
stream->src = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_free (old_uri);
|
|
|
|
g_free (old_protocol);
|
|
|
|
g_free (new_protocol);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stream->src == NULL) {
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstPad *internal_pad;
|
|
|
|
|
|
|
|
stream->src = gst_element_make_from_uri (GST_URI_SRC, uri, NULL, NULL);
|
|
|
|
if (stream->src == NULL) {
|
|
|
|
GST_ELEMENT_ERROR (demux, CORE, MISSING_PLUGIN,
|
|
|
|
("Missing plugin to handle URI: '%s'", uri), (NULL));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gobject_class = G_OBJECT_GET_CLASS (stream->src);
|
|
|
|
|
|
|
|
if (g_object_class_find_property (gobject_class, "compress"))
|
|
|
|
g_object_set (stream->src, "compress", FALSE, NULL);
|
|
|
|
if (g_object_class_find_property (gobject_class, "keep-alive"))
|
|
|
|
g_object_set (stream->src, "keep-alive", TRUE, NULL);
|
|
|
|
if (g_object_class_find_property (gobject_class, "extra-headers")) {
|
|
|
|
if (referer || refresh || !allow_cache) {
|
|
|
|
GstStructure *extra_headers = gst_structure_new_empty ("headers");
|
|
|
|
|
|
|
|
if (referer)
|
|
|
|
gst_structure_set (extra_headers, "Referer", G_TYPE_STRING, referer,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (!allow_cache)
|
|
|
|
gst_structure_set (extra_headers, "Cache-Control", G_TYPE_STRING,
|
|
|
|
"no-cache", NULL);
|
|
|
|
else if (refresh)
|
|
|
|
gst_structure_set (extra_headers, "Cache-Control", G_TYPE_STRING,
|
|
|
|
"max-age=0", NULL);
|
|
|
|
|
|
|
|
g_object_set (stream->src, "extra-headers", extra_headers, NULL);
|
|
|
|
|
|
|
|
gst_structure_free (extra_headers);
|
|
|
|
} else {
|
|
|
|
g_object_set (stream->src, "extra-headers", NULL, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_element_set_locked_state (stream->src, TRUE);
|
|
|
|
gst_bin_add (GST_BIN_CAST (demux), stream->src);
|
|
|
|
stream->src_srcpad = gst_element_get_static_pad (stream->src, "src");
|
|
|
|
|
|
|
|
gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (stream->pad),
|
|
|
|
stream->src_srcpad);
|
|
|
|
|
|
|
|
/* set up our internal pad to drop all events from
|
|
|
|
* the http src we don't care about. On the chain function
|
|
|
|
* we just push the buffer forward, but this way dash can get
|
|
|
|
* the flow return from downstream */
|
|
|
|
internal_pad =
|
|
|
|
GST_PAD_CAST (gst_proxy_pad_get_internal (GST_PROXY_PAD (stream->pad)));
|
|
|
|
gst_pad_set_chain_function (GST_PAD_CAST (internal_pad), _src_chain);
|
|
|
|
gst_pad_set_event_function (GST_PAD_CAST (internal_pad), _src_event);
|
|
|
|
/* need to set query otherwise deadlocks happen with allocation queries */
|
|
|
|
gst_pad_set_query_function (GST_PAD_CAST (internal_pad), _src_query);
|
|
|
|
gst_object_unref (internal_pad);
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* must be called with the stream's fragment_download_lock */
|
|
|
|
static void
|
|
|
|
gst_mss_demux_stream_download_uri (GstMssDemux * demux,
|
|
|
|
GstMssDemuxStream * stream, const gchar * uri, gint64 start, gint64 end)
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (stream->pad, "Downloading uri: %s, range:%" G_GINT64_FORMAT
|
|
|
|
" - %" G_GINT64_FORMAT, uri, start, end);
|
|
|
|
|
|
|
|
if (!gst_mss_demux_stream_update_source (stream, uri, NULL, FALSE, TRUE)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gst_element_set_state (stream->src,
|
|
|
|
GST_STATE_READY) != GST_STATE_CHANGE_FAILURE) {
|
|
|
|
if (start != 0 || end != -1) {
|
|
|
|
if (!gst_element_send_event (stream->src, gst_event_new_seek (1.0,
|
|
|
|
GST_FORMAT_BYTES, (GstSeekFlags) GST_SEEK_FLAG_FLUSH,
|
|
|
|
GST_SEEK_TYPE_SET, start, GST_SEEK_TYPE_SET, end))) {
|
|
|
|
|
|
|
|
/* looks like the source can't handle seeks in READY */
|
|
|
|
/*
|
|
|
|
*err = g_error_new (GST_CORE_ERROR, GST_CORE_ERROR_NOT_IMPLEMENTED,
|
|
|
|
"Source element can't handle range requests");
|
|
|
|
*/
|
|
|
|
stream->last_ret = GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (G_LIKELY (stream->last_ret == GST_FLOW_OK)) {
|
|
|
|
/* flush the proxypads so that the EOS state is reset */
|
|
|
|
gst_pad_push_event (stream->src_srcpad, gst_event_new_flush_start ());
|
|
|
|
gst_pad_push_event (stream->src_srcpad, gst_event_new_flush_stop (TRUE));
|
|
|
|
|
|
|
|
stream->download_start_time = g_get_monotonic_time ();
|
|
|
|
gst_element_sync_state_with_parent (stream->src);
|
|
|
|
|
|
|
|
/* wait for the fragment to be completely downloaded */
|
|
|
|
GST_DEBUG_OBJECT (stream->pad,
|
|
|
|
"Waiting for fragment download to finish: %s", uri);
|
|
|
|
g_cond_wait (&stream->fragment_download_cond,
|
|
|
|
&stream->fragment_download_lock);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
stream->last_ret = GST_FLOW_CUSTOM_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_element_set_state (stream->src, GST_STATE_READY);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_mss_demux_stream_download_fragment (GstMssDemuxStream * stream)
|
2012-11-16 20:30:12 +00:00
|
|
|
{
|
2012-11-19 20:53:16 +00:00
|
|
|
GstMssDemux *mssdemux = stream->parent;
|
2014-05-12 16:40:19 +00:00
|
|
|
gchar *path = NULL;
|
|
|
|
gchar *url = NULL;
|
2013-01-10 19:26:48 +00:00
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
2013-02-05 03:28:19 +00:00
|
|
|
|
2013-11-12 12:58:31 +00:00
|
|
|
/* special case for not-linked streams */
|
|
|
|
if (stream->last_ret == GST_FLOW_NOT_LINKED) {
|
2013-12-16 19:14:24 +00:00
|
|
|
GST_DEBUG_OBJECT (stream->pad, "Skipping download for not-linked stream %p",
|
2013-11-12 12:58:31 +00:00
|
|
|
stream);
|
|
|
|
return GST_FLOW_NOT_LINKED;
|
|
|
|
}
|
2013-01-10 18:16:36 +00:00
|
|
|
|
2014-05-12 16:40:19 +00:00
|
|
|
g_mutex_lock (&stream->fragment_download_lock);
|
2013-12-16 19:14:24 +00:00
|
|
|
GST_DEBUG_OBJECT (stream->pad, "Getting url for stream");
|
2012-11-19 20:53:16 +00:00
|
|
|
ret = gst_mss_stream_get_fragment_url (stream->manifest_stream, &path);
|
2012-11-16 20:30:12 +00:00
|
|
|
switch (ret) {
|
2012-11-22 15:28:56 +00:00
|
|
|
case GST_FLOW_OK:
|
|
|
|
break; /* all is good, let's go */
|
2013-04-16 22:35:03 +00:00
|
|
|
case GST_FLOW_EOS:
|
2014-05-12 16:40:19 +00:00
|
|
|
g_free (path);
|
|
|
|
g_free (url);
|
2013-01-30 03:57:36 +00:00
|
|
|
if (gst_mss_manifest_is_live (mssdemux->manifest)) {
|
|
|
|
gst_mss_demux_reload_manifest (mssdemux);
|
2014-05-12 16:40:19 +00:00
|
|
|
g_mutex_unlock (&stream->fragment_download_lock);
|
2013-01-30 03:57:36 +00:00
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
2014-05-12 16:40:19 +00:00
|
|
|
g_mutex_unlock (&stream->fragment_download_lock);
|
2013-04-16 22:35:03 +00:00
|
|
|
return GST_FLOW_EOS;
|
2012-11-22 15:28:56 +00:00
|
|
|
case GST_FLOW_ERROR:
|
2014-05-12 16:40:19 +00:00
|
|
|
g_mutex_unlock (&stream->fragment_download_lock);
|
|
|
|
g_free (path);
|
|
|
|
g_free (url);
|
2012-11-22 15:28:56 +00:00
|
|
|
goto error;
|
2012-11-16 20:30:12 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2012-11-19 20:53:16 +00:00
|
|
|
if (!path) {
|
2012-12-21 19:42:11 +00:00
|
|
|
goto no_url_error;
|
2012-11-16 20:30:12 +00:00
|
|
|
}
|
2012-11-19 20:53:16 +00:00
|
|
|
GST_DEBUG_OBJECT (mssdemux, "Got url path '%s' for stream %p", path, stream);
|
|
|
|
|
|
|
|
url = g_strdup_printf ("%s/%s", mssdemux->base_url, path);
|
2012-11-16 20:30:12 +00:00
|
|
|
|
2013-01-17 19:20:10 +00:00
|
|
|
GST_DEBUG_OBJECT (mssdemux, "Got url '%s' for stream %p", url, stream);
|
|
|
|
|
2014-05-12 16:40:19 +00:00
|
|
|
stream->starting_fragment = TRUE;
|
|
|
|
|
|
|
|
gst_mss_demux_stream_download_uri (mssdemux, stream, url, 0, -1);
|
|
|
|
|
2012-11-19 20:53:16 +00:00
|
|
|
g_free (path);
|
2012-11-16 20:30:12 +00:00
|
|
|
g_free (url);
|
2014-05-12 16:40:19 +00:00
|
|
|
g_mutex_unlock (&stream->fragment_download_lock);
|
2012-11-16 20:30:12 +00:00
|
|
|
|
2014-05-12 16:40:19 +00:00
|
|
|
if (stream->last_ret != GST_FLOW_OK) {
|
2012-12-28 03:48:33 +00:00
|
|
|
GST_INFO_OBJECT (mssdemux, "No fragment downloaded");
|
|
|
|
/* TODO check if we are truly stoping */
|
2014-05-12 16:40:19 +00:00
|
|
|
if (stream->last_ret != GST_FLOW_ERROR
|
|
|
|
&& gst_mss_manifest_is_live (mssdemux->manifest)) {
|
2013-01-17 19:20:10 +00:00
|
|
|
/* looks like there is no way of knowing when a live stream has ended
|
|
|
|
* Have to assume we are falling behind and cause a manifest reload */
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
2014-05-12 16:40:19 +00:00
|
|
|
return stream->last_ret;
|
2012-12-28 03:48:33 +00:00
|
|
|
}
|
2013-01-14 16:21:10 +00:00
|
|
|
|
2014-05-12 16:40:19 +00:00
|
|
|
return stream->last_ret;
|
2013-01-10 19:26:48 +00:00
|
|
|
|
|
|
|
no_url_error:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (mssdemux, STREAM, DEMUX,
|
|
|
|
(_("Failed to get fragment URL.")),
|
|
|
|
("An error happened when getting fragment URL"));
|
2013-02-01 22:12:41 +00:00
|
|
|
gst_task_pause (stream->download_task);
|
2013-01-10 19:26:48 +00:00
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
error:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (mssdemux, "Error while pushing fragment");
|
2013-02-01 22:12:41 +00:00
|
|
|
gst_task_pause (stream->download_task);
|
2013-01-10 19:26:48 +00:00
|
|
|
return GST_FLOW_ERROR;
|
2013-01-10 18:16:36 +00:00
|
|
|
}
|
2013-01-10 19:26:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-01-14 16:21:10 +00:00
|
|
|
gst_mss_demux_download_loop (GstMssDemuxStream * stream)
|
2013-01-10 19:26:48 +00:00
|
|
|
{
|
|
|
|
GstMssDemux *mssdemux = stream->parent;
|
|
|
|
GstFlowReturn ret;
|
2013-11-12 12:58:31 +00:00
|
|
|
GstEvent *gap = NULL;
|
2013-12-16 19:14:24 +00:00
|
|
|
GstEvent *capsevent = NULL;
|
2013-01-10 19:26:48 +00:00
|
|
|
|
2013-12-13 20:31:11 +00:00
|
|
|
GST_LOG_OBJECT (stream->pad, "download loop start");
|
2013-01-14 16:21:10 +00:00
|
|
|
|
2013-02-08 03:51:30 +00:00
|
|
|
GST_OBJECT_LOCK (mssdemux);
|
2013-11-12 12:58:31 +00:00
|
|
|
if (G_UNLIKELY (stream->restart_download)) {
|
|
|
|
GstClockTime cur, ts;
|
|
|
|
gint64 pos;
|
|
|
|
|
2013-12-13 20:31:11 +00:00
|
|
|
GST_DEBUG_OBJECT (stream->pad,
|
|
|
|
"Activating stream due to reconfigure event");
|
2013-11-12 12:58:31 +00:00
|
|
|
|
|
|
|
cur = GST_CLOCK_TIME_IS_VALID (stream->next_timestamp) ?
|
|
|
|
stream->next_timestamp : 0;
|
|
|
|
|
|
|
|
if (gst_pad_peer_query_position (stream->pad, GST_FORMAT_TIME, &pos)) {
|
|
|
|
ts = (GstClockTime) pos;
|
|
|
|
GST_DEBUG_OBJECT (mssdemux, "Downstream position: %"
|
|
|
|
GST_TIME_FORMAT, GST_TIME_ARGS (ts));
|
|
|
|
} else {
|
|
|
|
GST_DEBUG_OBJECT (mssdemux, "Downstream position query failed, "
|
|
|
|
"failling back to segment position");
|
2013-12-17 16:16:58 +00:00
|
|
|
ts = stream->segment.position;
|
2013-11-12 12:58:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* we might have already pushed this data */
|
|
|
|
ts = MAX (ts, stream->next_timestamp);
|
|
|
|
|
2013-12-13 20:31:11 +00:00
|
|
|
GST_DEBUG_OBJECT (stream->pad, "Restarting stream at "
|
2013-12-16 19:14:24 +00:00
|
|
|
"position %" GST_TIME_FORMAT, GST_TIME_ARGS (ts));
|
2013-11-12 12:58:31 +00:00
|
|
|
|
|
|
|
if (GST_CLOCK_TIME_IS_VALID (ts)) {
|
|
|
|
gst_mss_stream_seek (stream->manifest_stream, ts);
|
|
|
|
|
|
|
|
if (cur < ts) {
|
|
|
|
gap = gst_event_new_gap (cur, ts - cur);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stream->restart_download = FALSE;
|
2013-12-16 19:14:24 +00:00
|
|
|
stream->last_ret = GST_FLOW_OK;
|
2013-11-12 12:58:31 +00:00
|
|
|
}
|
2013-12-16 19:14:24 +00:00
|
|
|
capsevent = gst_mss_demux_reconfigure_stream (stream);
|
2013-02-08 03:51:30 +00:00
|
|
|
GST_OBJECT_UNLOCK (mssdemux);
|
|
|
|
|
2013-12-16 19:14:24 +00:00
|
|
|
if (G_UNLIKELY (gap != NULL))
|
2013-11-12 12:58:31 +00:00
|
|
|
gst_pad_push_event (stream->pad, gap);
|
2013-12-16 19:14:24 +00:00
|
|
|
if (G_UNLIKELY (capsevent != NULL))
|
|
|
|
gst_pad_push_event (stream->pad, capsevent);
|
2013-11-12 12:58:31 +00:00
|
|
|
|
2014-05-12 16:40:19 +00:00
|
|
|
ret = gst_mss_demux_stream_download_fragment (stream);
|
2013-02-19 18:17:53 +00:00
|
|
|
|
2013-12-19 17:29:42 +00:00
|
|
|
GST_OBJECT_LOCK (mssdemux);
|
2013-11-12 12:58:31 +00:00
|
|
|
if (stream->cancelled) {
|
2013-12-19 17:29:42 +00:00
|
|
|
GST_OBJECT_UNLOCK (mssdemux);
|
2013-02-19 18:17:53 +00:00
|
|
|
goto cancelled;
|
2013-11-12 12:58:31 +00:00
|
|
|
}
|
2013-12-16 19:14:24 +00:00
|
|
|
stream->last_ret = ret;
|
2013-12-19 17:29:42 +00:00
|
|
|
|
|
|
|
if (stream->cancelled) {
|
|
|
|
GST_OBJECT_UNLOCK (mssdemux);
|
|
|
|
goto cancelled;
|
|
|
|
}
|
|
|
|
|
2013-01-14 16:21:10 +00:00
|
|
|
switch (ret) {
|
|
|
|
case GST_FLOW_OK:
|
2014-05-12 16:40:19 +00:00
|
|
|
stream->download_error_count = 0;
|
|
|
|
gst_mss_stream_advance_fragment (stream->manifest_stream);
|
2013-01-14 16:21:10 +00:00
|
|
|
break; /* all is good, let's go */
|
2013-12-16 19:14:24 +00:00
|
|
|
|
2013-04-16 22:35:03 +00:00
|
|
|
case GST_FLOW_EOS:
|
2013-12-16 19:14:24 +00:00
|
|
|
GST_DEBUG_OBJECT (stream->pad, "EOS, stopping download loop");
|
2013-12-19 17:30:13 +00:00
|
|
|
/* we push the EOS after releasing the object lock */
|
2013-12-16 19:14:24 +00:00
|
|
|
gst_task_pause (stream->download_task);
|
|
|
|
break;
|
|
|
|
|
2013-11-12 12:58:31 +00:00
|
|
|
case GST_FLOW_NOT_LINKED:
|
2013-12-16 19:14:24 +00:00
|
|
|
gst_task_pause (stream->download_task);
|
|
|
|
if (gst_mss_demux_combine_flows (mssdemux) == GST_FLOW_NOT_LINKED) {
|
|
|
|
GST_ELEMENT_ERROR (mssdemux, STREAM, FAILED,
|
|
|
|
(_("Internal data stream error.")),
|
|
|
|
("stream stopped, reason %s",
|
|
|
|
gst_flow_get_name (GST_FLOW_NOT_LINKED)));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GST_FLOW_FLUSHING:{
|
|
|
|
GSList *iter;
|
|
|
|
|
|
|
|
for (iter = mssdemux->streams; iter; iter = g_slist_next (iter)) {
|
|
|
|
GstMssDemuxStream *other;
|
|
|
|
|
|
|
|
other = iter->data;
|
|
|
|
gst_task_pause (other->download_task);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-01-14 16:21:10 +00:00
|
|
|
default:
|
2013-12-16 19:14:24 +00:00
|
|
|
if (ret <= GST_FLOW_ERROR) {
|
2014-05-12 16:40:19 +00:00
|
|
|
GST_WARNING_OBJECT (mssdemux, "Error while downloading fragment");
|
2014-05-12 17:18:13 +00:00
|
|
|
if (++stream->download_error_count >= MAX_DOWNLOAD_ERROR_COUNT) {
|
2014-05-12 16:40:19 +00:00
|
|
|
GST_ELEMENT_ERROR (mssdemux, RESOURCE, NOT_FOUND,
|
|
|
|
(_("Couldn't download fragments")),
|
|
|
|
("fragment downloading has failed too much consecutive times"));
|
2013-12-16 19:14:24 +00:00
|
|
|
}
|
|
|
|
}
|
2013-01-14 16:21:10 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-12-16 19:14:24 +00:00
|
|
|
GST_OBJECT_UNLOCK (mssdemux);
|
2013-02-07 06:10:46 +00:00
|
|
|
|
2013-12-19 17:30:13 +00:00
|
|
|
if (G_UNLIKELY (ret == GST_FLOW_EOS)) {
|
|
|
|
gst_mss_demux_stream_push_event (stream, gst_event_new_eos ());
|
|
|
|
}
|
|
|
|
|
2013-12-13 20:31:11 +00:00
|
|
|
GST_LOG_OBJECT (stream->pad, "download loop end");
|
2013-01-14 16:21:10 +00:00
|
|
|
return;
|
|
|
|
|
2013-02-19 18:17:53 +00:00
|
|
|
cancelled:
|
|
|
|
{
|
2013-12-19 17:29:42 +00:00
|
|
|
GST_DEBUG_OBJECT (stream->pad, "Stream has been cancelled");
|
2013-02-19 18:17:53 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-01-14 16:21:10 +00:00
|
|
|
}
|
|
|
|
|
2013-11-12 12:58:31 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
gst_mss_demux_combine_flows (GstMssDemux * mssdemux)
|
|
|
|
{
|
|
|
|
gboolean all_notlinked = TRUE;
|
|
|
|
GSList *iter;
|
|
|
|
|
|
|
|
for (iter = mssdemux->streams; iter; iter = g_slist_next (iter)) {
|
|
|
|
GstMssDemuxStream *stream = iter->data;
|
|
|
|
|
|
|
|
if (stream->last_ret != GST_FLOW_NOT_LINKED)
|
|
|
|
all_notlinked = FALSE;
|
|
|
|
|
|
|
|
if (stream->last_ret <= GST_FLOW_NOT_NEGOTIATED
|
|
|
|
|| stream->last_ret == GST_FLOW_FLUSHING)
|
|
|
|
return stream->last_ret;
|
|
|
|
}
|
|
|
|
if (all_notlinked)
|
|
|
|
return GST_FLOW_NOT_LINKED;
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
2014-05-12 16:40:19 +00:00
|
|
|
#if 0
|
2013-12-16 19:14:24 +00:00
|
|
|
static gboolean
|
|
|
|
gst_mss_demux_stream_push (GstMssDemuxStream * stream, GstBuffer * buf)
|
2013-01-14 16:21:10 +00:00
|
|
|
{
|
|
|
|
GstFlowReturn ret;
|
2013-01-10 18:16:36 +00:00
|
|
|
|
2014-05-12 16:40:19 +00:00
|
|
|
if (G_UNLIKELY (stream->pending_segment)) {
|
|
|
|
gst_pad_push_event (stream->pad, stream->pending_segment);
|
|
|
|
stream->pending_segment = NULL;
|
2012-12-28 03:48:33 +00:00
|
|
|
}
|
|
|
|
|
2013-12-16 19:14:24 +00:00
|
|
|
if (GST_BUFFER_TIMESTAMP (buf) != stream->next_timestamp) {
|
|
|
|
GST_DEBUG_OBJECT (stream->pad, "Marking buffer %p as discont buffer:%"
|
|
|
|
GST_TIME_FORMAT " != expected:%" GST_TIME_FORMAT, buf,
|
|
|
|
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)),
|
|
|
|
GST_TIME_ARGS (stream->next_timestamp));
|
|
|
|
GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DISCONT);
|
2013-01-14 16:21:10 +00:00
|
|
|
}
|
|
|
|
|
2013-12-16 19:14:24 +00:00
|
|
|
GST_DEBUG_OBJECT (stream->pad,
|
|
|
|
"Pushing buffer %p %" GST_TIME_FORMAT ", duration %" GST_TIME_FORMAT
|
|
|
|
" discont:%d", buf,
|
|
|
|
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)),
|
|
|
|
GST_TIME_ARGS (GST_BUFFER_DURATION (buf)),
|
|
|
|
GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_DISCONT));
|
2012-11-22 15:28:56 +00:00
|
|
|
|
2013-12-16 19:14:24 +00:00
|
|
|
stream->next_timestamp =
|
|
|
|
GST_BUFFER_TIMESTAMP (buf) + GST_BUFFER_DURATION (buf);
|
2012-11-16 20:30:12 +00:00
|
|
|
|
2013-12-16 19:14:24 +00:00
|
|
|
stream->have_data = TRUE;
|
2013-12-17 16:16:58 +00:00
|
|
|
stream->segment.position = GST_BUFFER_TIMESTAMP (buf);
|
2013-12-16 19:14:24 +00:00
|
|
|
|
|
|
|
ret = gst_pad_push (stream->pad, GST_BUFFER_CAST (buf));
|
|
|
|
GST_DEBUG_OBJECT (stream->pad, "Pushed. result: %d (%s)",
|
|
|
|
ret, gst_flow_get_name (ret));
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2014-05-12 16:40:19 +00:00
|
|
|
#endif
|
2013-12-16 19:14:24 +00:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_mss_demux_stream_push_event (GstMssDemuxStream * stream, GstEvent * event)
|
|
|
|
{
|
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
if (GST_EVENT_TYPE (event) == GST_EVENT_EOS) {
|
|
|
|
stream->eos = TRUE;
|
2012-11-22 15:28:56 +00:00
|
|
|
}
|
2013-12-16 19:14:24 +00:00
|
|
|
GST_DEBUG_OBJECT (stream->pad, "Pushing event %" GST_PTR_FORMAT, event);
|
|
|
|
ret = gst_pad_push_event (stream->pad, event);
|
|
|
|
return ret;
|
2012-11-16 20:30:12 +00:00
|
|
|
}
|