2013-05-08 14:13:32 +00:00
|
|
|
/*
|
|
|
|
* DASH demux plugin for GStreamer
|
|
|
|
*
|
|
|
|
* gstdashdemux.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Orange
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* David Corvoysier <david.corvoysier@orange.com>
|
|
|
|
* Hamid Zakari <hamid.zakari@gmail.com>
|
|
|
|
*
|
2013-01-25 15:45:18 +00:00
|
|
|
* Copyright (C) 2013 Smart TV Alliance
|
|
|
|
* Author: Thiago Sousa Santos <thiago.sousa.santos@collabora.com>, Collabora Ltd.
|
|
|
|
*
|
2013-05-08 14:13:32 +00:00
|
|
|
* 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.1 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
|
2012-09-28 10:55:27 +00:00
|
|
|
* License along with this library (COPYING); if not, write to the
|
2013-05-08 14:13:32 +00:00
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* SECTION:element-dashdemux
|
|
|
|
*
|
|
|
|
* DASH demuxer element.
|
|
|
|
* <title>Example launch line</title>
|
|
|
|
* |[
|
|
|
|
* gst-launch playbin2 uri="http://www-itec.uni-klu.ac.at/ftp/datasets/mmsys12/RedBullPlayStreets/redbull_4s/RedBullPlayStreets_4s_isoffmain_DIS_23009_1_v_2_1c2_2011_08_30.mpd"
|
|
|
|
* ]|
|
|
|
|
*/
|
|
|
|
|
2012-10-15 11:09:49 +00:00
|
|
|
/* Implementation notes:
|
|
|
|
*
|
|
|
|
* The following section describes how dashdemux works internally.
|
|
|
|
*
|
2012-10-15 12:14:53 +00:00
|
|
|
* Introduction:
|
|
|
|
*
|
|
|
|
* dashdemux is a "fake" demux, as unlike traditional demux elements, it
|
|
|
|
* doesn't split data streams contained in an enveloppe to expose them
|
|
|
|
* to downstream decoding elements.
|
|
|
|
*
|
|
|
|
* Instead, it parses an XML file called a manifest to identify a set of
|
|
|
|
* individual stream fragments it needs to fetch and expose to the actual
|
|
|
|
* demux elements that will handle them (this behavior is sometimes
|
|
|
|
* referred as the "demux after a demux" scenario).
|
|
|
|
*
|
|
|
|
* For a given section of content, several representations corresponding
|
|
|
|
* to different bitrates may be available: dashdemux will select the most
|
|
|
|
* appropriate representation based on local conditions (typically the
|
|
|
|
* available bandwidth and the amount of buffering available, capped by
|
|
|
|
* a maximum allowed bitrate).
|
|
|
|
*
|
|
|
|
* The representation selection algorithm can be configured using
|
|
|
|
* specific properties: max bitrate, min/max buffering, bandwidth ratio.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* General Design:
|
|
|
|
*
|
|
|
|
* dashdemux has a single sink pad that accepts the data corresponding
|
|
|
|
* to the manifest, typically fetched from an HTTP or file source.
|
|
|
|
*
|
|
|
|
* dashdemux exposes the streams it recreates based on the fragments it
|
|
|
|
* fetches through dedicated src pads corresponding to the caps of the
|
|
|
|
* fragments container (ISOBMFF/MP4 or MPEG2TS).
|
|
|
|
*
|
|
|
|
* During playback, new representations will typically be exposed as a
|
|
|
|
* new set of pads (see 'Switching between representations' below).
|
|
|
|
*
|
|
|
|
* Fragments downloading is performed using a dedicated task that fills
|
|
|
|
* an internal queue. Another task is in charge of popping fragments
|
|
|
|
* from the queue and pushing them downstream.
|
|
|
|
*
|
2012-10-15 11:09:49 +00:00
|
|
|
* Switching between representations:
|
|
|
|
*
|
|
|
|
* Decodebin supports scenarios allowing to seamlessly switch from one
|
|
|
|
* stream to another inside the same "decoding chain".
|
|
|
|
*
|
|
|
|
* To achieve that, it combines the elements it autoplugged in chains
|
|
|
|
* and groups, allowing only one decoding group to be active at a given
|
|
|
|
* time for a given chain.
|
|
|
|
*
|
|
|
|
* A chain can signal decodebin that it is complete by sending a
|
|
|
|
* no-more-pads event, but even after that new pads can be added to
|
|
|
|
* create new subgroups, providing that a new no-more-pads event is sent.
|
|
|
|
*
|
|
|
|
* We take advantage of that to dynamically create a new decoding group
|
|
|
|
* in order to select a different representation during playback.
|
|
|
|
*
|
|
|
|
* Typically, assuming that each fragment contains both audio and video,
|
|
|
|
* the following tree would be created:
|
|
|
|
*
|
|
|
|
* chain "DASH Demux"
|
2012-10-15 13:08:53 +00:00
|
|
|
* |_ group "Representation set 1"
|
2012-10-15 11:09:49 +00:00
|
|
|
* | |_ chain "Qt Demux 0"
|
|
|
|
* | |_ group "Stream 0"
|
|
|
|
* | |_ chain "H264"
|
|
|
|
* | |_ chain "AAC"
|
2012-10-15 13:08:53 +00:00
|
|
|
* |_ group "Representation set 2"
|
2012-10-15 11:09:49 +00:00
|
|
|
* |_ chain "Qt Demux 1"
|
|
|
|
* |_ group "Stream 1"
|
|
|
|
* |_ chain "H264"
|
|
|
|
* |_ chain "AAC"
|
|
|
|
*
|
|
|
|
* Or, if audio and video are contained in separate fragments:
|
|
|
|
*
|
|
|
|
* chain "DASH Demux"
|
2012-10-15 13:08:53 +00:00
|
|
|
* |_ group "Representation set 1"
|
2012-10-15 11:09:49 +00:00
|
|
|
* | |_ chain "Qt Demux 0"
|
|
|
|
* | | |_ group "Stream 0"
|
|
|
|
* | | |_ chain "H264"
|
|
|
|
* | |_ chain "Qt Demux 1"
|
|
|
|
* | |_ group "Stream 1"
|
|
|
|
* | |_ chain "AAC"
|
2012-10-15 13:08:53 +00:00
|
|
|
* |_ group "Representation set 2"
|
2012-10-15 11:09:49 +00:00
|
|
|
* |_ chain "Qt Demux 3"
|
|
|
|
* | |_ group "Stream 2"
|
|
|
|
* | |_ chain "H264"
|
|
|
|
* |_ chain "Qt Demux 4"
|
|
|
|
* |_ group "Stream 3"
|
|
|
|
* |_ chain "AAC"
|
|
|
|
*
|
2012-10-15 13:08:53 +00:00
|
|
|
* In both cases, when switching from Set 1 to Set 2 an EOS is sent on
|
|
|
|
* each end pad corresponding to Rep 0, triggering the "drain" state to
|
2012-10-15 11:09:49 +00:00
|
|
|
* propagate upstream.
|
2012-10-15 13:08:53 +00:00
|
|
|
* Once both EOS have been processed, the "Set 1" group is completely
|
|
|
|
* drained, and decodebin2 will switch to the "Set 2" group.
|
2012-10-15 11:09:49 +00:00
|
|
|
*
|
|
|
|
* Note: nothing can be pushed to the new decoding group before the
|
|
|
|
* old one has been drained, which means that in order to be able to
|
|
|
|
* adapt quickly to bandwidth changes, we will not be able to rely
|
|
|
|
* on downstream buffering, and will instead manage an internal queue.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2013-05-08 14:13:32 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <string.h>
|
2012-10-25 15:15:09 +00:00
|
|
|
#include <inttypes.h>
|
2013-05-08 14:13:32 +00:00
|
|
|
#include <gst/base/gsttypefindhelper.h>
|
|
|
|
#include "gstdashdemux.h"
|
2013-06-25 21:34:13 +00:00
|
|
|
#include "gstdash_debug.h"
|
2013-05-08 14:13:32 +00:00
|
|
|
|
2013-05-08 22:17:08 +00:00
|
|
|
static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src_%u",
|
2013-05-08 14:13:32 +00:00
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_SOMETIMES,
|
|
|
|
GST_STATIC_CAPS_ANY);
|
|
|
|
|
|
|
|
static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
2012-10-17 13:52:19 +00:00
|
|
|
GST_STATIC_CAPS ("application/dash+xml"));
|
2013-05-08 14:13:32 +00:00
|
|
|
|
2013-06-25 21:34:13 +00:00
|
|
|
GST_DEBUG_CATEGORY (gst_dash_demux_debug);
|
2013-05-08 14:13:32 +00:00
|
|
|
#define GST_CAT_DEFAULT gst_dash_demux_debug
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
|
|
|
|
PROP_MAX_BUFFERING_TIME,
|
|
|
|
PROP_BANDWIDTH_USAGE,
|
|
|
|
PROP_MAX_BITRATE,
|
|
|
|
PROP_LAST
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Default values for properties */
|
2012-11-21 13:14:34 +00:00
|
|
|
#define DEFAULT_MAX_BUFFERING_TIME 30 /* in seconds */
|
|
|
|
#define DEFAULT_BANDWIDTH_USAGE 0.8 /* 0 to 1 */
|
|
|
|
#define DEFAULT_MAX_BITRATE 24000000 /* in bit/s */
|
2013-05-08 14:13:32 +00:00
|
|
|
|
|
|
|
#define DEFAULT_FAILED_COUNT 3
|
2013-02-05 20:38:06 +00:00
|
|
|
#define DOWNLOAD_RATE_HISTORY_MAX 3
|
2013-05-08 14:13:32 +00:00
|
|
|
|
2013-01-29 18:58:50 +00:00
|
|
|
/* Custom internal event to signal end of period */
|
|
|
|
#define GST_EVENT_DASH_EOP GST_EVENT_MAKE_TYPE(81, GST_EVENT_TYPE_DOWNSTREAM | GST_EVENT_TYPE_SERIALIZED)
|
|
|
|
static GstEvent *
|
|
|
|
gst_event_new_dash_eop (void)
|
|
|
|
{
|
|
|
|
return gst_event_new_custom (GST_EVENT_DASH_EOP, NULL);
|
|
|
|
}
|
|
|
|
|
2013-05-08 14:13:32 +00:00
|
|
|
/* GObject */
|
|
|
|
static void gst_dash_demux_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_dash_demux_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_dash_demux_dispose (GObject * obj);
|
|
|
|
|
|
|
|
/* GstElement */
|
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_dash_demux_change_state (GstElement * element, GstStateChange transition);
|
|
|
|
|
|
|
|
/* GstDashDemux */
|
2013-04-18 10:41:09 +00:00
|
|
|
static GstFlowReturn gst_dash_demux_pad (GstPad * pad, GstObject * parent,
|
|
|
|
GstBuffer * buf);
|
|
|
|
static gboolean gst_dash_demux_sink_event (GstPad * pad, GstObject * parent,
|
|
|
|
GstEvent * event);
|
|
|
|
static gboolean gst_dash_demux_src_event (GstPad * pad, GstObject * parent,
|
|
|
|
GstEvent * event);
|
|
|
|
static gboolean gst_dash_demux_src_query (GstPad * pad, GstObject * parent,
|
|
|
|
GstQuery * query);
|
2013-05-08 14:13:32 +00:00
|
|
|
static void gst_dash_demux_stream_loop (GstDashDemux * demux);
|
|
|
|
static void gst_dash_demux_download_loop (GstDashDemux * demux);
|
|
|
|
static void gst_dash_demux_stop (GstDashDemux * demux);
|
|
|
|
static void gst_dash_demux_resume_stream_task (GstDashDemux * demux);
|
|
|
|
static void gst_dash_demux_resume_download_task (GstDashDemux * demux);
|
2012-12-20 08:04:28 +00:00
|
|
|
static gboolean gst_dash_demux_setup_all_streams (GstDashDemux * demux);
|
2013-02-05 17:22:51 +00:00
|
|
|
static gboolean gst_dash_demux_select_representations (GstDashDemux * demux);
|
2013-07-09 02:24:28 +00:00
|
|
|
static gboolean gst_dash_demux_get_next_fragment (GstDashDemux * demux,
|
|
|
|
GstActiveStream ** stream, GstClockTime * next_ts);
|
2013-02-13 04:13:23 +00:00
|
|
|
static gboolean gst_dash_demux_advance_period (GstDashDemux * demux);
|
2013-07-09 02:24:28 +00:00
|
|
|
static void gst_dash_demux_download_wait (GstDashDemux * demux,
|
|
|
|
GstClockTime time_diff);
|
2013-05-08 14:13:32 +00:00
|
|
|
|
2013-02-13 04:13:23 +00:00
|
|
|
static void gst_dash_demux_expose_streams (GstDashDemux * demux);
|
|
|
|
static void gst_dash_demux_remove_streams (GstDashDemux * demux,
|
|
|
|
GSList * streams);
|
|
|
|
static void gst_dash_demux_stream_free (GstDashDemuxStream * stream);
|
2013-05-08 14:13:32 +00:00
|
|
|
static void gst_dash_demux_reset (GstDashDemux * demux, gboolean dispose);
|
2013-07-29 07:35:08 +00:00
|
|
|
#ifndef GST_DISABLE_GST_DEBUG
|
2013-05-08 14:13:32 +00:00
|
|
|
static GstClockTime gst_dash_demux_get_buffering_time (GstDashDemux * demux);
|
2013-01-28 15:28:29 +00:00
|
|
|
static GstClockTime gst_dash_demux_stream_get_buffering_time (GstDashDemuxStream
|
|
|
|
* stream);
|
2013-07-29 07:35:08 +00:00
|
|
|
#endif
|
|
|
|
static GstCaps *gst_dash_demux_get_input_caps (GstDashDemux * demux,
|
|
|
|
GstActiveStream * stream);
|
2013-02-13 04:13:23 +00:00
|
|
|
static GstPad *gst_dash_demux_create_pad (GstDashDemux * demux);
|
2013-05-08 14:13:32 +00:00
|
|
|
|
2013-04-18 10:41:09 +00:00
|
|
|
#define gst_dash_demux_parent_class parent_class
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GstDashDemux, gst_dash_demux, GST_TYPE_ELEMENT,
|
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_dash_demux_debug, "dashdemux", 0,
|
|
|
|
"dashdemux element"););
|
2013-05-08 14:13:32 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gst_dash_demux_dispose (GObject * obj)
|
|
|
|
{
|
|
|
|
GstDashDemux *demux = GST_DASH_DEMUX (obj);
|
|
|
|
|
2013-02-05 00:58:32 +00:00
|
|
|
gst_dash_demux_reset (demux, TRUE);
|
|
|
|
|
2013-05-08 14:13:32 +00:00
|
|
|
if (demux->stream_task) {
|
|
|
|
gst_object_unref (demux->stream_task);
|
2013-04-18 10:41:09 +00:00
|
|
|
g_rec_mutex_clear (&demux->stream_task_lock);
|
2013-05-08 14:13:32 +00:00
|
|
|
demux->stream_task = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (demux->download_task) {
|
|
|
|
gst_object_unref (demux->download_task);
|
2013-04-18 10:41:09 +00:00
|
|
|
g_rec_mutex_clear (&demux->download_task_lock);
|
2013-05-08 14:13:32 +00:00
|
|
|
demux->download_task = NULL;
|
|
|
|
}
|
2013-07-09 02:24:28 +00:00
|
|
|
g_cond_clear (&demux->download_cond);
|
|
|
|
g_mutex_clear (&demux->download_mutex);
|
2013-05-08 14:13:32 +00:00
|
|
|
|
|
|
|
if (demux->downloader != NULL) {
|
|
|
|
g_object_unref (demux->downloader);
|
|
|
|
demux->downloader = NULL;
|
|
|
|
}
|
|
|
|
|
2013-04-18 10:41:09 +00:00
|
|
|
g_mutex_clear (&demux->streams_lock);
|
2013-02-18 17:02:48 +00:00
|
|
|
|
2013-05-08 14:13:32 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_dash_demux_class_init (GstDashDemuxClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gstelement_class = (GstElementClass *) klass;
|
|
|
|
|
|
|
|
gobject_class->set_property = gst_dash_demux_set_property;
|
|
|
|
gobject_class->get_property = gst_dash_demux_get_property;
|
|
|
|
gobject_class->dispose = gst_dash_demux_dispose;
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_MAX_BUFFERING_TIME,
|
|
|
|
g_param_spec_uint ("max-buffering-time", "Maximum buffering time",
|
|
|
|
"Maximum number of seconds of buffer accumulated during playback",
|
|
|
|
2, G_MAXUINT, DEFAULT_MAX_BUFFERING_TIME,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_BANDWIDTH_USAGE,
|
|
|
|
g_param_spec_float ("bandwidth-usage",
|
|
|
|
"Bandwidth usage [0..1]",
|
|
|
|
"Percentage of the available bandwidth to use when selecting representations",
|
|
|
|
0, 1, DEFAULT_BANDWIDTH_USAGE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_MAX_BITRATE,
|
|
|
|
g_param_spec_uint ("max-bitrate", "Max bitrate",
|
|
|
|
"Max of bitrate supported by target decoder",
|
|
|
|
1000, G_MAXUINT, DEFAULT_MAX_BITRATE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
gstelement_class->change_state =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_dash_demux_change_state);
|
2013-04-18 10:41:09 +00:00
|
|
|
|
|
|
|
gst_element_class_add_pad_template (gstelement_class,
|
|
|
|
gst_static_pad_template_get (&srctemplate));
|
|
|
|
|
|
|
|
gst_element_class_add_pad_template (gstelement_class,
|
|
|
|
gst_static_pad_template_get (&sinktemplate));
|
|
|
|
|
|
|
|
gst_element_class_set_static_metadata (gstelement_class,
|
|
|
|
"DASH Demuxer",
|
|
|
|
"Codec/Demuxer",
|
|
|
|
"Dynamic Adaptive Streaming over HTTP demuxer",
|
|
|
|
"David Corvoysier <david.corvoysier@orange.com>\n\
|
|
|
|
Hamid Zakari <hamid.zakari@gmail.com>\n\
|
|
|
|
Gianluca Gennari <gennarone@gmail.com>");
|
2013-05-08 14:13:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-04-18 10:41:09 +00:00
|
|
|
gst_dash_demux_init (GstDashDemux * demux)
|
2013-05-08 14:13:32 +00:00
|
|
|
{
|
|
|
|
/* sink pad */
|
|
|
|
demux->sinkpad = gst_pad_new_from_static_template (&sinktemplate, "sink");
|
|
|
|
gst_pad_set_chain_function (demux->sinkpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_dash_demux_pad));
|
|
|
|
gst_pad_set_event_function (demux->sinkpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_dash_demux_sink_event));
|
|
|
|
gst_element_add_pad (GST_ELEMENT (demux), demux->sinkpad);
|
|
|
|
|
2013-02-01 03:37:33 +00:00
|
|
|
gst_segment_init (&demux->segment, GST_FORMAT_TIME);
|
|
|
|
|
2013-05-08 14:13:32 +00:00
|
|
|
/* Downloader */
|
|
|
|
demux->downloader = gst_uri_downloader_new ();
|
|
|
|
|
|
|
|
/* Properties */
|
|
|
|
demux->max_buffering_time = DEFAULT_MAX_BUFFERING_TIME * GST_SECOND;
|
|
|
|
demux->bandwidth_usage = DEFAULT_BANDWIDTH_USAGE;
|
|
|
|
demux->max_bitrate = DEFAULT_MAX_BITRATE;
|
|
|
|
|
|
|
|
/* Updates task */
|
2013-04-18 10:41:09 +00:00
|
|
|
g_rec_mutex_init (&demux->download_task_lock);
|
2013-05-08 14:13:32 +00:00
|
|
|
demux->download_task =
|
2013-04-18 10:41:09 +00:00
|
|
|
gst_task_new ((GstTaskFunction) gst_dash_demux_download_loop, demux,
|
|
|
|
NULL);
|
2013-02-13 04:13:23 +00:00
|
|
|
gst_task_set_lock (demux->download_task, &demux->download_task_lock);
|
2013-07-09 02:24:28 +00:00
|
|
|
g_cond_init (&demux->download_cond);
|
|
|
|
g_mutex_init (&demux->download_mutex);
|
2013-05-08 14:13:32 +00:00
|
|
|
|
|
|
|
/* Streaming task */
|
2013-04-18 10:41:09 +00:00
|
|
|
g_rec_mutex_init (&demux->stream_task_lock);
|
2013-05-08 14:13:32 +00:00
|
|
|
demux->stream_task =
|
2013-04-18 10:41:09 +00:00
|
|
|
gst_task_new ((GstTaskFunction) gst_dash_demux_stream_loop, demux, NULL);
|
2013-02-13 04:13:23 +00:00
|
|
|
gst_task_set_lock (demux->stream_task, &demux->stream_task_lock);
|
|
|
|
|
2013-04-18 10:41:09 +00:00
|
|
|
g_mutex_init (&demux->streams_lock);
|
2013-05-08 14:13:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_dash_demux_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstDashDemux *demux = GST_DASH_DEMUX (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_MAX_BUFFERING_TIME:
|
|
|
|
demux->max_buffering_time = g_value_get_uint (value) * GST_SECOND;
|
|
|
|
break;
|
|
|
|
case PROP_BANDWIDTH_USAGE:
|
|
|
|
demux->bandwidth_usage = g_value_get_float (value);
|
|
|
|
break;
|
|
|
|
case PROP_MAX_BITRATE:
|
|
|
|
demux->max_bitrate = g_value_get_uint (value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_dash_demux_get_property (GObject * object, guint prop_id, GValue * value,
|
|
|
|
GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstDashDemux *demux = GST_DASH_DEMUX (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_MAX_BUFFERING_TIME:
|
2013-05-06 20:56:01 +00:00
|
|
|
g_value_set_uint (value, demux->max_buffering_time / GST_SECOND);
|
2013-05-08 14:13:32 +00:00
|
|
|
break;
|
|
|
|
case PROP_BANDWIDTH_USAGE:
|
|
|
|
g_value_set_float (value, demux->bandwidth_usage);
|
|
|
|
break;
|
|
|
|
case PROP_MAX_BITRATE:
|
|
|
|
g_value_set_uint (value, demux->max_bitrate);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_dash_demux_change_state (GstElement * element, GstStateChange transition)
|
|
|
|
{
|
|
|
|
GstStateChangeReturn ret;
|
|
|
|
GstDashDemux *demux = GST_DASH_DEMUX (element);
|
|
|
|
|
|
|
|
switch (transition) {
|
2013-02-05 00:58:32 +00:00
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
2013-05-08 14:13:32 +00:00
|
|
|
gst_dash_demux_reset (demux, FALSE);
|
|
|
|
break;
|
2013-02-05 00:58:32 +00:00
|
|
|
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
|
|
|
break;
|
2013-05-08 14:13:32 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-01-28 21:52:04 +00:00
|
|
|
static gboolean
|
|
|
|
_check_queue_full (GstDataQueue * q, guint visible, guint bytes, guint64 time,
|
2013-07-03 19:38:33 +00:00
|
|
|
GstDashDemux * demux)
|
2013-01-28 21:52:04 +00:00
|
|
|
{
|
2013-07-09 15:49:55 +00:00
|
|
|
return time >= demux->max_buffering_time;
|
2013-01-28 21:52:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_data_queue_item_destroy (GstDataQueueItem * item)
|
|
|
|
{
|
|
|
|
gst_mini_object_unref (item->object);
|
|
|
|
g_free (item);
|
|
|
|
}
|
|
|
|
|
2013-01-29 18:58:50 +00:00
|
|
|
static void
|
|
|
|
gst_dash_demux_stream_push_event (GstDashDemuxStream * stream, GstEvent * event)
|
|
|
|
{
|
|
|
|
GstDataQueueItem *item = g_new0 (GstDataQueueItem, 1);
|
|
|
|
|
|
|
|
item->object = GST_MINI_OBJECT_CAST (event);
|
|
|
|
item->destroy = (GDestroyNotify) _data_queue_item_destroy;
|
|
|
|
|
|
|
|
gst_data_queue_push (stream->queue, item);
|
|
|
|
}
|
|
|
|
|
2013-01-28 21:52:04 +00:00
|
|
|
static void
|
|
|
|
gst_dash_demux_stream_push_data (GstDashDemuxStream * stream,
|
|
|
|
GstBuffer * fragment)
|
|
|
|
{
|
2013-01-29 18:58:50 +00:00
|
|
|
GstDataQueueItem *item = g_new (GstDataQueueItem, 1);
|
2013-01-28 21:52:04 +00:00
|
|
|
|
|
|
|
item->object = GST_MINI_OBJECT_CAST (fragment);
|
|
|
|
item->duration = GST_BUFFER_DURATION (fragment);
|
|
|
|
item->visible = TRUE;
|
2013-04-18 10:41:09 +00:00
|
|
|
item->size = gst_buffer_get_size (fragment);
|
2013-01-28 21:52:04 +00:00
|
|
|
|
|
|
|
item->destroy = (GDestroyNotify) _data_queue_item_destroy;
|
|
|
|
|
|
|
|
gst_data_queue_push (stream->queue, item);
|
|
|
|
}
|
|
|
|
|
2013-05-08 14:13:32 +00:00
|
|
|
static gboolean
|
2013-04-18 10:41:09 +00:00
|
|
|
gst_dash_demux_src_event (GstPad * pad, GstObject * parent, GstEvent * event)
|
2013-05-08 14:13:32 +00:00
|
|
|
{
|
|
|
|
GstDashDemux *demux;
|
|
|
|
|
2013-04-18 10:41:09 +00:00
|
|
|
demux = GST_DASH_DEMUX (parent);
|
2013-05-08 14:13:32 +00:00
|
|
|
|
|
|
|
switch (event->type) {
|
|
|
|
case GST_EVENT_SEEK:
|
|
|
|
{
|
|
|
|
gdouble rate;
|
|
|
|
GstFormat format;
|
|
|
|
GstSeekFlags flags;
|
|
|
|
GstSeekType start_type, stop_type;
|
|
|
|
gint64 start, stop;
|
2012-12-17 13:54:42 +00:00
|
|
|
GList *list;
|
2013-05-08 14:13:32 +00:00
|
|
|
GstClockTime current_pos, target_pos;
|
2012-12-17 13:54:42 +00:00
|
|
|
guint current_sequence, current_period;
|
2013-01-28 22:43:46 +00:00
|
|
|
GstActiveStream *active_stream;
|
2013-05-08 14:13:32 +00:00
|
|
|
GstMediaSegment *chunk;
|
2012-12-17 13:54:42 +00:00
|
|
|
GstStreamPeriod *period;
|
2013-01-28 13:46:27 +00:00
|
|
|
GSList *iter;
|
2013-02-01 03:37:33 +00:00
|
|
|
gboolean update;
|
2013-05-08 14:13:32 +00:00
|
|
|
|
2013-07-03 15:30:28 +00:00
|
|
|
GST_INFO_OBJECT (demux, "Received seek event");
|
2013-01-16 18:58:52 +00:00
|
|
|
|
2013-05-08 14:13:32 +00:00
|
|
|
if (gst_mpd_client_is_live (demux->client)) {
|
|
|
|
GST_WARNING_OBJECT (demux, "Received seek event for live stream");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_event_parse_seek (event, &rate, &format, &flags, &start_type, &start,
|
|
|
|
&stop_type, &stop);
|
|
|
|
|
|
|
|
if (format != GST_FORMAT_TIME)
|
|
|
|
return FALSE;
|
|
|
|
|
2012-10-19 08:43:49 +00:00
|
|
|
GST_DEBUG_OBJECT (demux,
|
|
|
|
"seek event, rate: %f type: %d start: %" GST_TIME_FORMAT " stop: %"
|
|
|
|
GST_TIME_FORMAT, rate, start_type, GST_TIME_ARGS (start),
|
2013-05-08 14:13:32 +00:00
|
|
|
GST_TIME_ARGS (stop));
|
|
|
|
|
2013-04-18 10:41:09 +00:00
|
|
|
gst_segment_do_seek (&demux->segment, rate, format, flags, start_type,
|
2013-02-01 03:37:33 +00:00
|
|
|
start, stop_type, stop, &update);
|
2013-01-28 22:43:46 +00:00
|
|
|
|
2013-02-01 03:37:33 +00:00
|
|
|
if (update) {
|
|
|
|
if (flags & GST_SEEK_FLAG_FLUSH) {
|
|
|
|
GST_DEBUG_OBJECT (demux, "sending flush start");
|
|
|
|
for (iter = demux->streams; iter; iter = g_slist_next (iter)) {
|
|
|
|
GstDashDemuxStream *stream;
|
|
|
|
stream = iter->data;
|
|
|
|
gst_pad_push_event (stream->pad, gst_event_new_flush_start ());
|
|
|
|
}
|
2012-12-17 13:54:42 +00:00
|
|
|
}
|
|
|
|
|
2013-02-01 03:37:33 +00:00
|
|
|
/* Stop the demux */
|
|
|
|
demux->cancelled = TRUE;
|
2013-02-05 00:58:32 +00:00
|
|
|
/* Stop the demux, also clears the buffering queue */
|
2013-02-01 03:37:33 +00:00
|
|
|
gst_dash_demux_stop (demux);
|
2013-05-08 14:13:32 +00:00
|
|
|
|
2013-02-01 03:37:33 +00:00
|
|
|
/* Wait for streaming to finish */
|
2013-04-18 10:41:09 +00:00
|
|
|
g_rec_mutex_lock (&demux->stream_task_lock);
|
2013-02-01 03:37:33 +00:00
|
|
|
|
|
|
|
/* select the requested Period in the Media Presentation */
|
|
|
|
target_pos = (GstClockTime) demux->segment.start;
|
2013-03-13 14:55:03 +00:00
|
|
|
GST_DEBUG_OBJECT (demux, "Seeking to target %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (target_pos));
|
2013-02-01 03:37:33 +00:00
|
|
|
current_period = 0;
|
|
|
|
for (list = g_list_first (demux->client->periods); list;
|
2013-01-28 22:43:46 +00:00
|
|
|
list = g_list_next (list)) {
|
2013-02-01 03:37:33 +00:00
|
|
|
period = list->data;
|
|
|
|
current_pos = period->start;
|
|
|
|
current_period = period->number;
|
2013-03-13 14:55:03 +00:00
|
|
|
GST_DEBUG_OBJECT (demux, "Looking at period %u pos %" GST_TIME_FORMAT,
|
|
|
|
current_period, GST_TIME_ARGS (current_pos));
|
2013-01-28 22:43:46 +00:00
|
|
|
if (current_pos <= target_pos
|
2013-02-01 03:37:33 +00:00
|
|
|
&& target_pos < current_pos + period->duration) {
|
2013-01-28 22:43:46 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-05-08 14:13:32 +00:00
|
|
|
}
|
2013-02-01 03:37:33 +00:00
|
|
|
if (list == NULL) {
|
|
|
|
GST_WARNING_OBJECT (demux, "Could not find seeked Period");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (current_period != gst_mpd_client_get_period_index (demux->client)) {
|
2013-02-13 04:13:23 +00:00
|
|
|
GSList *streams = NULL;
|
|
|
|
|
2013-02-01 03:37:33 +00:00
|
|
|
GST_DEBUG_OBJECT (demux, "Seeking to Period %d", current_period);
|
2013-02-13 04:13:23 +00:00
|
|
|
streams = demux->streams;
|
|
|
|
demux->streams = NULL;
|
|
|
|
/* clean old active stream list, if any */
|
|
|
|
gst_active_streams_free (demux->client);
|
|
|
|
|
2013-02-01 03:37:33 +00:00
|
|
|
/* setup video, audio and subtitle streams, starting from the new Period */
|
|
|
|
if (!gst_mpd_client_set_period_index (demux->client, current_period)
|
|
|
|
|| !gst_dash_demux_setup_all_streams (demux))
|
|
|
|
return FALSE;
|
2013-02-13 04:13:23 +00:00
|
|
|
|
|
|
|
gst_dash_demux_expose_streams (demux);
|
|
|
|
|
|
|
|
gst_dash_demux_remove_streams (demux, streams);
|
2013-02-01 03:37:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Update the current sequence on all streams */
|
2013-01-28 13:46:27 +00:00
|
|
|
for (iter = demux->streams; iter; iter = g_slist_next (iter)) {
|
2013-02-01 03:37:33 +00:00
|
|
|
GstDashDemuxStream *stream = iter->data;
|
2013-07-05 02:42:23 +00:00
|
|
|
gint seg_i;
|
2013-01-28 13:46:27 +00:00
|
|
|
|
2013-02-01 03:37:33 +00:00
|
|
|
active_stream =
|
|
|
|
gst_mpdparser_get_active_stream_by_index (demux->client,
|
|
|
|
stream->index);
|
|
|
|
current_pos = 0;
|
|
|
|
current_sequence = 0;
|
2013-07-05 02:42:23 +00:00
|
|
|
for (seg_i = 0; seg_i < active_stream->segments->len; seg_i++) {
|
|
|
|
chunk = g_ptr_array_index (active_stream->segments, seg_i);
|
2013-02-01 03:37:33 +00:00
|
|
|
current_pos = chunk->start_time;
|
2013-07-03 15:30:28 +00:00
|
|
|
/* current_sequence = chunk->number; */
|
|
|
|
GST_DEBUG_OBJECT (demux, "current_pos:%" GST_TIME_FORMAT
|
2013-02-07 16:09:44 +00:00
|
|
|
" <= target_pos:%" GST_TIME_FORMAT " duration:%"
|
|
|
|
GST_TIME_FORMAT, GST_TIME_ARGS (current_pos),
|
|
|
|
GST_TIME_ARGS (target_pos), GST_TIME_ARGS (chunk->duration));
|
2013-02-01 03:37:33 +00:00
|
|
|
if (current_pos <= target_pos
|
|
|
|
&& target_pos < current_pos + chunk->duration) {
|
2013-02-07 16:09:44 +00:00
|
|
|
GST_DEBUG_OBJECT (demux,
|
|
|
|
"selecting sequence %d for stream %" GST_PTR_FORMAT,
|
|
|
|
current_sequence, stream);
|
2013-02-01 03:37:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
current_sequence++;
|
|
|
|
}
|
|
|
|
gst_mpd_client_set_segment_index (active_stream, current_sequence);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & GST_SEEK_FLAG_FLUSH) {
|
|
|
|
GST_DEBUG_OBJECT (demux, "Sending flush stop on all pad");
|
|
|
|
for (iter = demux->streams; iter; iter = g_slist_next (iter)) {
|
|
|
|
GstDashDemuxStream *stream;
|
|
|
|
|
|
|
|
stream = iter->data;
|
2013-02-14 20:39:35 +00:00
|
|
|
stream->has_data_queued = FALSE;
|
2013-02-07 16:09:44 +00:00
|
|
|
stream->need_header = TRUE;
|
2013-02-14 20:39:35 +00:00
|
|
|
stream->download_end_of_period = FALSE;
|
|
|
|
stream->stream_end_of_period = FALSE;
|
|
|
|
stream->stream_eos = FALSE;
|
2013-04-18 10:41:09 +00:00
|
|
|
gst_pad_push_event (stream->pad, gst_event_new_flush_stop (TRUE));
|
2013-02-01 03:37:33 +00:00
|
|
|
}
|
2013-05-08 14:13:32 +00:00
|
|
|
}
|
|
|
|
|
2013-02-01 03:37:33 +00:00
|
|
|
/* Restart the demux */
|
|
|
|
demux->cancelled = FALSE;
|
|
|
|
demux->end_of_manifest = FALSE;
|
|
|
|
for (iter = demux->streams; iter; iter = g_slist_next (iter)) {
|
|
|
|
GstDashDemuxStream *stream = iter->data;
|
|
|
|
gst_data_queue_set_flushing (stream->queue, FALSE);
|
|
|
|
}
|
2013-03-13 14:55:03 +00:00
|
|
|
demux->timestamp_offset = 0;
|
2013-02-12 20:50:51 +00:00
|
|
|
demux->need_segment = TRUE;
|
2013-02-05 00:58:32 +00:00
|
|
|
gst_uri_downloader_reset (demux->downloader);
|
2013-02-14 20:39:35 +00:00
|
|
|
GST_DEBUG_OBJECT (demux, "Resuming tasks after seeking");
|
2013-02-01 03:37:33 +00:00
|
|
|
gst_dash_demux_resume_download_task (demux);
|
|
|
|
gst_dash_demux_resume_stream_task (demux);
|
2013-04-18 10:41:09 +00:00
|
|
|
g_rec_mutex_unlock (&demux->stream_task_lock);
|
2013-01-28 21:52:04 +00:00
|
|
|
}
|
2013-05-08 14:13:32 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-04-18 10:41:09 +00:00
|
|
|
return gst_pad_event_default (pad, parent, event);
|
2013-05-08 14:13:32 +00:00
|
|
|
}
|
|
|
|
|
2013-07-31 01:06:38 +00:00
|
|
|
static gboolean
|
2013-02-22 19:40:36 +00:00
|
|
|
gst_dash_demux_setup_mpdparser_streams (GstDashDemux * demux,
|
|
|
|
GstMpdClient * client)
|
2012-10-24 09:49:51 +00:00
|
|
|
{
|
|
|
|
GList *listLang = NULL;
|
|
|
|
guint i, nb_audio;
|
|
|
|
gchar *lang;
|
2013-07-31 01:06:38 +00:00
|
|
|
gboolean has_streams = FALSE;
|
2012-10-24 09:49:51 +00:00
|
|
|
|
2013-02-22 19:40:36 +00:00
|
|
|
if (!gst_mpd_client_setup_streaming (client, GST_STREAM_VIDEO, ""))
|
2012-10-24 09:49:51 +00:00
|
|
|
GST_INFO_OBJECT (demux, "No video adaptation set found");
|
2013-07-31 01:06:38 +00:00
|
|
|
else
|
|
|
|
has_streams = TRUE;
|
2012-10-24 09:49:51 +00:00
|
|
|
|
2012-11-21 13:14:34 +00:00
|
|
|
nb_audio =
|
2013-02-22 19:40:36 +00:00
|
|
|
gst_mpdparser_get_list_and_nb_of_audio_language (client, &listLang);
|
2012-10-24 09:49:51 +00:00
|
|
|
if (nb_audio == 0)
|
|
|
|
nb_audio = 1;
|
2013-02-13 04:13:23 +00:00
|
|
|
GST_INFO_OBJECT (demux, "Number of languages is=%d", nb_audio);
|
2012-10-24 09:49:51 +00:00
|
|
|
|
|
|
|
for (i = 0; i < nb_audio; i++) {
|
|
|
|
lang = (gchar *) g_list_nth_data (listLang, i);
|
2013-01-25 12:36:35 +00:00
|
|
|
GST_INFO ("nb adaptation set: %i",
|
2013-02-22 19:40:36 +00:00
|
|
|
gst_mpdparser_get_nb_adaptationSet (client));
|
|
|
|
if (!gst_mpd_client_setup_streaming (client, GST_STREAM_AUDIO, lang))
|
2013-01-16 18:58:52 +00:00
|
|
|
GST_INFO_OBJECT (demux, "No audio adaptation set found");
|
2013-07-31 01:06:38 +00:00
|
|
|
else
|
|
|
|
has_streams = TRUE;
|
2012-10-24 09:49:51 +00:00
|
|
|
|
2013-07-31 01:06:38 +00:00
|
|
|
if (gst_mpdparser_get_nb_adaptationSet (client) > nb_audio) {
|
2013-02-22 19:40:36 +00:00
|
|
|
if (!gst_mpd_client_setup_streaming (client,
|
2013-07-31 01:06:38 +00:00
|
|
|
GST_STREAM_APPLICATION, lang)) {
|
2012-10-24 09:49:51 +00:00
|
|
|
GST_INFO_OBJECT (demux, "No application adaptation set found");
|
2013-07-31 01:06:38 +00:00
|
|
|
} else {
|
|
|
|
has_streams = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!has_streams) {
|
|
|
|
GST_ELEMENT_ERROR (demux, STREAM, DEMUX, ("Manifest has no playable "
|
|
|
|
"streams"), ("No streams could be activated from the manifest"));
|
2012-10-24 09:49:51 +00:00
|
|
|
}
|
2013-07-31 01:06:38 +00:00
|
|
|
return has_streams;
|
2013-02-22 19:40:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_dash_demux_setup_all_streams (GstDashDemux * demux)
|
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
GSList *streams = NULL;
|
|
|
|
|
|
|
|
GST_MPD_CLIENT_LOCK (demux->client);
|
|
|
|
/* clean old active stream list, if any */
|
|
|
|
gst_active_streams_free (demux->client);
|
2013-01-28 13:46:27 +00:00
|
|
|
|
2013-07-31 01:06:38 +00:00
|
|
|
if (!gst_dash_demux_setup_mpdparser_streams (demux, demux->client)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2013-01-28 13:46:27 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (demux, "Creating stream objects");
|
|
|
|
for (i = 0; i < gst_mpdparser_get_nb_active_stream (demux->client); i++) {
|
|
|
|
GstDashDemuxStream *stream;
|
|
|
|
GstActiveStream *active_stream;
|
|
|
|
GstCaps *caps;
|
2013-07-23 08:04:42 +00:00
|
|
|
GstEvent *event;
|
2013-05-18 00:23:55 +00:00
|
|
|
gchar *stream_id;
|
2013-01-28 13:46:27 +00:00
|
|
|
|
|
|
|
active_stream = gst_mpdparser_get_active_stream_by_index (demux->client, i);
|
|
|
|
if (active_stream == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
stream = g_new0 (GstDashDemuxStream, 1);
|
|
|
|
caps = gst_dash_demux_get_input_caps (demux, active_stream);
|
2013-01-28 21:52:04 +00:00
|
|
|
stream->queue =
|
|
|
|
gst_data_queue_new ((GstDataQueueCheckFullFunction) _check_queue_full,
|
2013-07-03 19:38:33 +00:00
|
|
|
NULL, NULL, demux);
|
2013-01-28 13:46:27 +00:00
|
|
|
|
|
|
|
stream->index = i;
|
|
|
|
stream->input_caps = caps;
|
2013-02-07 23:58:37 +00:00
|
|
|
stream->need_header = TRUE;
|
|
|
|
stream->has_data_queued = FALSE;
|
2013-02-05 20:38:06 +00:00
|
|
|
gst_download_rate_init (&stream->dnl_rate);
|
|
|
|
gst_download_rate_set_max_length (&stream->dnl_rate,
|
|
|
|
DOWNLOAD_RATE_HISTORY_MAX);
|
2013-01-28 13:46:27 +00:00
|
|
|
|
|
|
|
GST_LOG_OBJECT (demux, "Creating stream %d %" GST_PTR_FORMAT, i, caps);
|
2013-02-13 04:13:23 +00:00
|
|
|
streams = g_slist_prepend (streams, stream);
|
|
|
|
stream->pad = gst_dash_demux_create_pad (demux);
|
2013-05-18 00:23:55 +00:00
|
|
|
|
|
|
|
stream_id =
|
|
|
|
gst_pad_create_stream_id_printf (stream->pad,
|
2013-06-10 22:00:13 +00:00
|
|
|
GST_ELEMENT_CAST (demux), "%d", i);
|
2013-07-23 08:04:42 +00:00
|
|
|
|
|
|
|
event =
|
|
|
|
gst_pad_get_sticky_event (demux->sinkpad, GST_EVENT_STREAM_START, 0);
|
|
|
|
if (event) {
|
|
|
|
if (gst_event_parse_group_id (event, &demux->group_id))
|
|
|
|
demux->have_group_id = TRUE;
|
|
|
|
else
|
|
|
|
demux->have_group_id = FALSE;
|
|
|
|
gst_event_unref (event);
|
|
|
|
} else if (!demux->have_group_id) {
|
|
|
|
demux->have_group_id = TRUE;
|
|
|
|
demux->group_id = gst_util_group_id_next ();
|
|
|
|
}
|
|
|
|
event = gst_event_new_stream_start (stream_id);
|
|
|
|
if (demux->have_group_id)
|
|
|
|
gst_event_set_group_id (event, demux->group_id);
|
|
|
|
|
|
|
|
gst_pad_push_event (stream->pad, event);
|
2013-05-18 00:23:55 +00:00
|
|
|
g_free (stream_id);
|
|
|
|
|
2013-04-18 10:41:09 +00:00
|
|
|
gst_dash_demux_stream_push_event (stream, gst_event_new_caps (caps));
|
2013-01-28 13:46:27 +00:00
|
|
|
}
|
2013-02-13 04:13:23 +00:00
|
|
|
streams = g_slist_reverse (streams);
|
2013-02-07 23:58:37 +00:00
|
|
|
|
2013-02-13 04:13:23 +00:00
|
|
|
demux->next_periods = g_slist_append (demux->next_periods, streams);
|
2012-12-17 14:19:33 +00:00
|
|
|
GST_MPD_CLIENT_UNLOCK (demux->client);
|
2012-10-24 09:49:51 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-05-08 14:13:32 +00:00
|
|
|
static gboolean
|
2013-04-18 10:41:09 +00:00
|
|
|
gst_dash_demux_sink_event (GstPad * pad, GstObject * parent, GstEvent * event)
|
2013-05-08 14:13:32 +00:00
|
|
|
{
|
2013-04-18 10:41:09 +00:00
|
|
|
GstDashDemux *demux = GST_DASH_DEMUX (parent);
|
2013-05-08 14:13:32 +00:00
|
|
|
|
|
|
|
switch (event->type) {
|
2013-02-05 00:58:32 +00:00
|
|
|
case GST_EVENT_FLUSH_STOP:
|
|
|
|
gst_dash_demux_reset (demux, FALSE);
|
|
|
|
break;
|
2013-05-08 14:13:32 +00:00
|
|
|
case GST_EVENT_EOS:{
|
2012-10-15 09:40:55 +00:00
|
|
|
gchar *manifest;
|
2013-05-08 14:13:32 +00:00
|
|
|
GstQuery *query;
|
2013-07-03 22:11:11 +00:00
|
|
|
gboolean query_res;
|
|
|
|
gboolean ret = TRUE;
|
2013-04-18 10:41:09 +00:00
|
|
|
GstMapInfo mapinfo;
|
2013-05-08 14:13:32 +00:00
|
|
|
|
2012-10-15 09:40:55 +00:00
|
|
|
if (demux->manifest == NULL) {
|
|
|
|
GST_WARNING_OBJECT (demux, "Received EOS without a manifest.");
|
2013-05-08 14:13:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-10-15 11:09:49 +00:00
|
|
|
GST_DEBUG_OBJECT (demux, "Got EOS on the sink pad: manifest fetched");
|
2013-05-08 14:13:32 +00:00
|
|
|
|
|
|
|
if (demux->client)
|
|
|
|
gst_mpd_client_free (demux->client);
|
|
|
|
demux->client = gst_mpd_client_new ();
|
|
|
|
|
|
|
|
query = gst_query_new_uri ();
|
2013-07-03 22:11:11 +00:00
|
|
|
query_res = gst_pad_peer_query (pad, query);
|
|
|
|
if (query_res) {
|
2013-05-08 14:13:32 +00:00
|
|
|
gst_query_parse_uri (query, &demux->client->mpd_uri);
|
|
|
|
GST_DEBUG_OBJECT (demux, "Fetched MPD file at URI: %s",
|
|
|
|
demux->client->mpd_uri);
|
|
|
|
} else {
|
|
|
|
GST_WARNING_OBJECT (demux, "MPD URI query failed.");
|
|
|
|
}
|
|
|
|
gst_query_unref (query);
|
|
|
|
|
2013-07-03 22:11:11 +00:00
|
|
|
if (gst_buffer_map (demux->manifest, &mapinfo, GST_MAP_READ)) {
|
|
|
|
manifest = (gchar *) mapinfo.data;
|
|
|
|
if (!gst_mpd_parse (demux->client, manifest, mapinfo.size)) {
|
|
|
|
/* In most cases, this will happen if we set a wrong url in the
|
|
|
|
* source element and we have received the 404 HTML response instead of
|
|
|
|
* the manifest */
|
|
|
|
GST_ELEMENT_ERROR (demux, STREAM, DECODE, ("Invalid manifest."),
|
|
|
|
(NULL));
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
gst_buffer_unmap (demux->manifest, &mapinfo);
|
|
|
|
} else {
|
2012-10-15 09:40:55 +00:00
|
|
|
GST_WARNING_OBJECT (demux, "Error validating the manifest.");
|
2013-07-03 22:11:11 +00:00
|
|
|
ret = FALSE;
|
2013-05-08 14:13:32 +00:00
|
|
|
}
|
2012-10-15 09:40:55 +00:00
|
|
|
gst_buffer_unref (demux->manifest);
|
|
|
|
demux->manifest = NULL;
|
2013-05-08 14:13:32 +00:00
|
|
|
|
2013-07-03 22:11:11 +00:00
|
|
|
if (!ret)
|
|
|
|
goto seek_quit;
|
|
|
|
|
2012-10-22 16:12:30 +00:00
|
|
|
if (!gst_mpd_client_setup_media_presentation (demux->client)) {
|
|
|
|
GST_ELEMENT_ERROR (demux, STREAM, DECODE,
|
|
|
|
("Incompatible manifest file."), (NULL));
|
2013-07-03 22:11:11 +00:00
|
|
|
ret = FALSE;
|
|
|
|
goto seek_quit;
|
2012-10-22 16:12:30 +00:00
|
|
|
}
|
2012-12-17 14:00:52 +00:00
|
|
|
|
|
|
|
/* setup video, audio and subtitle streams, starting from first Period */
|
2012-12-17 14:04:45 +00:00
|
|
|
if (!gst_mpd_client_set_period_index (demux->client, 0) ||
|
2013-07-03 22:11:11 +00:00
|
|
|
!gst_dash_demux_setup_all_streams (demux)) {
|
|
|
|
ret = FALSE;
|
|
|
|
goto seek_quit;
|
|
|
|
}
|
2012-12-17 14:00:52 +00:00
|
|
|
|
2013-02-13 04:13:23 +00:00
|
|
|
gst_dash_demux_advance_period (demux);
|
|
|
|
|
2013-06-11 13:28:53 +00:00
|
|
|
/* If stream is live, try to find the segment that is closest to current time */
|
|
|
|
if (gst_mpd_client_is_live (demux->client)) {
|
|
|
|
GSList *iter;
|
|
|
|
GstDateTime *now = gst_date_time_new_now_utc ();
|
|
|
|
gint seg_idx;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (demux,
|
|
|
|
"Seeking to current time of day for live stream ");
|
|
|
|
if (demux->client->mpd_node->suggestedPresentationDelay != -1) {
|
|
|
|
GstDateTime *target = gst_mpd_client_add_time_difference (now,
|
|
|
|
demux->client->mpd_node->suggestedPresentationDelay * -1000);
|
|
|
|
gst_date_time_unref (now);
|
|
|
|
now = target;
|
|
|
|
}
|
|
|
|
for (iter = demux->streams; iter; iter = g_slist_next (iter)) {
|
|
|
|
GstDashDemuxStream *stream = iter->data;
|
|
|
|
GstActiveStream *active_stream;
|
|
|
|
|
|
|
|
active_stream =
|
|
|
|
gst_mpdparser_get_active_stream_by_index (demux->client,
|
|
|
|
stream->index);
|
|
|
|
|
|
|
|
/* Get segment index corresponding to current time. */
|
|
|
|
seg_idx =
|
|
|
|
gst_mpd_client_get_segment_index_at_time (demux->client,
|
|
|
|
active_stream, now);
|
|
|
|
if (seg_idx < 0) {
|
|
|
|
GST_WARNING_OBJECT (demux,
|
|
|
|
"Failed to find a segment that is available "
|
|
|
|
"at this point in time for stream %d.", stream->index);
|
|
|
|
seg_idx = 0;
|
|
|
|
}
|
|
|
|
GST_INFO_OBJECT (demux,
|
|
|
|
"Segment index corresponding to current time for stream "
|
|
|
|
"%d is %d.", stream->index, seg_idx);
|
|
|
|
gst_mpd_client_set_segment_index (active_stream, seg_idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_date_time_unref (now);
|
|
|
|
} else {
|
|
|
|
GST_DEBUG_OBJECT (demux,
|
|
|
|
"Seeking to first segment for on-demand stream ");
|
|
|
|
|
|
|
|
/* start playing from the first segment */
|
|
|
|
gst_mpd_client_set_segment_index_for_all_streams (demux->client, 0);
|
|
|
|
}
|
2012-12-17 14:19:33 +00:00
|
|
|
|
2013-05-08 14:13:32 +00:00
|
|
|
/* Send duration message */
|
|
|
|
if (!gst_mpd_client_is_live (demux->client)) {
|
2012-11-21 13:14:34 +00:00
|
|
|
GstClockTime duration =
|
|
|
|
gst_mpd_client_get_media_presentation_duration (demux->client);
|
2013-05-08 14:13:32 +00:00
|
|
|
|
2012-10-19 17:03:41 +00:00
|
|
|
if (duration != GST_CLOCK_TIME_NONE) {
|
2012-11-21 13:14:34 +00:00
|
|
|
GST_DEBUG_OBJECT (demux,
|
|
|
|
"Sending duration message : %" GST_TIME_FORMAT,
|
2012-10-19 17:03:41 +00:00
|
|
|
GST_TIME_ARGS (duration));
|
2013-05-08 14:13:32 +00:00
|
|
|
gst_element_post_message (GST_ELEMENT (demux),
|
2013-04-18 10:41:09 +00:00
|
|
|
gst_message_new_duration_changed (GST_OBJECT (demux)));
|
2012-10-19 17:03:41 +00:00
|
|
|
} else {
|
2012-11-21 13:14:34 +00:00
|
|
|
GST_DEBUG_OBJECT (demux,
|
|
|
|
"mediaPresentationDuration unknown, can not send the duration message");
|
2012-10-19 17:03:41 +00:00
|
|
|
}
|
2013-05-08 14:13:32 +00:00
|
|
|
}
|
2013-03-13 14:55:03 +00:00
|
|
|
demux->timestamp_offset = -1;
|
2013-03-08 13:59:59 +00:00
|
|
|
demux->need_segment = TRUE;
|
2013-05-08 14:13:32 +00:00
|
|
|
gst_dash_demux_resume_download_task (demux);
|
|
|
|
gst_dash_demux_resume_stream_task (demux);
|
2013-07-03 22:11:11 +00:00
|
|
|
|
2013-07-23 08:04:42 +00:00
|
|
|
seek_quit:
|
2013-05-08 14:13:32 +00:00
|
|
|
gst_event_unref (event);
|
2013-07-03 22:11:11 +00:00
|
|
|
return ret;
|
2013-05-08 14:13:32 +00:00
|
|
|
}
|
2013-04-18 10:41:09 +00:00
|
|
|
case GST_EVENT_SEGMENT:
|
2013-05-08 14:13:32 +00:00
|
|
|
/* Swallow newsegments, we'll push our own */
|
|
|
|
gst_event_unref (event);
|
|
|
|
return TRUE;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-04-18 10:41:09 +00:00
|
|
|
return gst_pad_event_default (pad, parent, event);
|
2013-05-08 14:13:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2013-04-18 10:41:09 +00:00
|
|
|
gst_dash_demux_src_query (GstPad * pad, GstObject * parent, GstQuery * query)
|
2013-05-08 14:13:32 +00:00
|
|
|
{
|
|
|
|
GstDashDemux *dashdemux;
|
|
|
|
gboolean ret = FALSE;
|
|
|
|
|
|
|
|
if (query == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
2013-04-18 10:41:09 +00:00
|
|
|
dashdemux = GST_DASH_DEMUX (parent);
|
2013-05-08 14:13:32 +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) {
|
2012-11-21 13:14:34 +00:00
|
|
|
duration =
|
|
|
|
gst_mpd_client_get_media_presentation_duration (dashdemux->client);
|
2013-05-08 14:13:32 +00:00
|
|
|
if (GST_CLOCK_TIME_IS_VALID (duration) && duration > 0) {
|
|
|
|
gst_query_set_duration (query, GST_FORMAT_TIME, duration);
|
|
|
|
ret = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
GST_DEBUG_OBJECT (dashdemux,
|
|
|
|
"GST_QUERY_DURATION returns %s with duration %" GST_TIME_FORMAT,
|
|
|
|
ret ? "TRUE" : "FALSE", GST_TIME_ARGS (duration));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_QUERY_SEEKING:{
|
|
|
|
GstFormat fmt;
|
2013-01-16 18:58:52 +00:00
|
|
|
gint64 start;
|
|
|
|
gint64 end;
|
2013-05-08 14:13:32 +00:00
|
|
|
gint64 stop = -1;
|
|
|
|
|
2013-01-16 18:58:52 +00:00
|
|
|
gst_query_parse_seeking (query, &fmt, NULL, &start, &end);
|
2013-01-25 12:36:35 +00:00
|
|
|
GST_DEBUG_OBJECT (dashdemux,
|
2013-04-23 15:08:07 +00:00
|
|
|
"Received GST_QUERY_SEEKING with format %d - %" G_GINT64_FORMAT
|
|
|
|
" %" G_GINT64_FORMAT, fmt, start, end);
|
2013-05-08 14:13:32 +00:00
|
|
|
if (fmt == GST_FORMAT_TIME) {
|
|
|
|
GstClockTime duration;
|
|
|
|
|
2012-11-21 13:14:34 +00:00
|
|
|
duration =
|
|
|
|
gst_mpd_client_get_media_presentation_duration (dashdemux->client);
|
2013-05-08 14:13:32 +00:00
|
|
|
if (GST_CLOCK_TIME_IS_VALID (duration) && duration > 0)
|
|
|
|
stop = duration;
|
|
|
|
|
|
|
|
gst_query_set_seeking (query, fmt,
|
|
|
|
!gst_mpd_client_is_live (dashdemux->client), 0, stop);
|
|
|
|
ret = TRUE;
|
2013-02-13 04:13:23 +00:00
|
|
|
|
2013-05-08 14:13:32 +00:00
|
|
|
GST_DEBUG_OBJECT (dashdemux, "GST_QUERY_SEEKING returning with stop : %"
|
|
|
|
GST_TIME_FORMAT, GST_TIME_ARGS (stop));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2013-07-04 18:14:00 +00:00
|
|
|
case GST_QUERY_LATENCY:
|
|
|
|
{
|
|
|
|
gboolean live;
|
|
|
|
GstClockTime min, max;
|
|
|
|
|
|
|
|
gst_query_parse_latency (query, &live, &min, &max);
|
|
|
|
|
|
|
|
if (dashdemux->client && gst_mpd_client_is_live (dashdemux->client))
|
|
|
|
live = TRUE;
|
|
|
|
|
|
|
|
if (dashdemux->max_buffering_time > 0)
|
|
|
|
max += dashdemux->max_buffering_time;
|
|
|
|
|
|
|
|
gst_query_set_latency (query, live, min, max);
|
|
|
|
break;
|
|
|
|
}
|
2012-10-16 09:39:18 +00:00
|
|
|
default:{
|
2013-07-03 15:30:28 +00:00
|
|
|
/* By default, do not forward queries upstream */
|
2013-05-08 14:13:32 +00:00
|
|
|
break;
|
2012-10-16 09:39:18 +00:00
|
|
|
}
|
2013-05-08 14:13:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
2013-04-18 10:41:09 +00:00
|
|
|
gst_dash_demux_pad (GstPad * pad, GstObject * parent, GstBuffer * buf)
|
2013-05-08 14:13:32 +00:00
|
|
|
{
|
2013-04-18 10:41:09 +00:00
|
|
|
GstDashDemux *demux = GST_DASH_DEMUX (parent);
|
2013-05-08 14:13:32 +00:00
|
|
|
|
2012-10-15 09:40:55 +00:00
|
|
|
if (demux->manifest == NULL)
|
|
|
|
demux->manifest = buf;
|
2013-05-08 14:13:32 +00:00
|
|
|
else
|
2013-04-18 10:41:09 +00:00
|
|
|
demux->manifest = gst_buffer_append (demux->manifest, buf);
|
2013-05-08 14:13:32 +00:00
|
|
|
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_dash_demux_stop (GstDashDemux * demux)
|
|
|
|
{
|
2013-01-28 21:52:04 +00:00
|
|
|
GSList *iter;
|
|
|
|
|
2013-02-05 17:24:45 +00:00
|
|
|
GST_DEBUG_OBJECT (demux, "Stopping demux");
|
|
|
|
|
2013-02-05 00:58:32 +00:00
|
|
|
if (demux->downloader)
|
|
|
|
gst_uri_downloader_cancel (demux->downloader);
|
|
|
|
|
2013-01-28 21:52:04 +00:00
|
|
|
for (iter = demux->streams; iter; iter = g_slist_next (iter)) {
|
|
|
|
GstDashDemuxStream *stream = iter->data;
|
|
|
|
|
|
|
|
gst_data_queue_set_flushing (stream->queue, TRUE);
|
|
|
|
}
|
2013-05-08 14:13:32 +00:00
|
|
|
|
|
|
|
if (GST_TASK_STATE (demux->download_task) != GST_TASK_STOPPED) {
|
|
|
|
GST_TASK_SIGNAL (demux->download_task);
|
2012-10-17 08:02:39 +00:00
|
|
|
gst_task_stop (demux->download_task);
|
2013-07-09 02:24:28 +00:00
|
|
|
g_mutex_lock (&demux->download_mutex);
|
|
|
|
g_cond_signal (&demux->download_cond);
|
|
|
|
g_mutex_unlock (&demux->download_mutex);
|
2013-04-18 10:41:09 +00:00
|
|
|
g_rec_mutex_lock (&demux->download_task_lock);
|
|
|
|
g_rec_mutex_unlock (&demux->download_task_lock);
|
2013-02-05 00:58:32 +00:00
|
|
|
gst_task_join (demux->download_task);
|
2013-05-08 14:13:32 +00:00
|
|
|
}
|
2012-10-16 11:43:39 +00:00
|
|
|
if (GST_TASK_STATE (demux->stream_task) != GST_TASK_STOPPED) {
|
|
|
|
GST_TASK_SIGNAL (demux->stream_task);
|
2012-10-17 08:02:39 +00:00
|
|
|
gst_task_stop (demux->stream_task);
|
2013-04-18 10:41:09 +00:00
|
|
|
g_rec_mutex_lock (&demux->stream_task_lock);
|
|
|
|
g_rec_mutex_unlock (&demux->stream_task_lock);
|
2013-02-05 00:58:32 +00:00
|
|
|
gst_task_join (demux->stream_task);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (iter = demux->streams; iter; iter = g_slist_next (iter)) {
|
|
|
|
GstDashDemuxStream *stream = iter->data;
|
|
|
|
|
|
|
|
gst_data_queue_flush (stream->queue);
|
2013-02-07 16:09:44 +00:00
|
|
|
stream->has_data_queued = FALSE;
|
2012-10-16 11:43:39 +00:00
|
|
|
}
|
2013-05-08 14:13:32 +00:00
|
|
|
}
|
|
|
|
|
2013-02-13 04:13:23 +00:00
|
|
|
static GstPad *
|
|
|
|
gst_dash_demux_create_pad (GstDashDemux * demux)
|
|
|
|
{
|
|
|
|
GstPad *pad;
|
|
|
|
|
|
|
|
/* Create and activate new pads */
|
|
|
|
pad = gst_pad_new_from_static_template (&srctemplate, NULL);
|
|
|
|
gst_pad_set_event_function (pad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_dash_demux_src_event));
|
|
|
|
gst_pad_set_query_function (pad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_dash_demux_src_query));
|
|
|
|
gst_pad_set_element_private (pad, demux);
|
|
|
|
gst_pad_set_active (pad, TRUE);
|
|
|
|
GST_INFO_OBJECT (demux, "Creating srcpad %s:%s", GST_DEBUG_PAD_NAME (pad));
|
|
|
|
return pad;
|
|
|
|
}
|
|
|
|
|
2013-05-08 14:13:32 +00:00
|
|
|
static void
|
2013-02-13 04:13:23 +00:00
|
|
|
gst_dash_demux_expose_streams (GstDashDemux * demux)
|
2013-05-08 14:13:32 +00:00
|
|
|
{
|
2013-01-28 13:46:27 +00:00
|
|
|
GSList *iter;
|
2013-01-30 20:27:47 +00:00
|
|
|
|
2013-01-28 13:46:27 +00:00
|
|
|
for (iter = demux->streams; iter; iter = g_slist_next (iter)) {
|
|
|
|
GstDashDemuxStream *stream = iter->data;
|
2013-01-30 20:27:47 +00:00
|
|
|
|
2013-02-13 04:13:23 +00:00
|
|
|
GST_LOG_OBJECT (demux, "Exposing stream %d %" GST_PTR_FORMAT, stream->index,
|
|
|
|
stream->input_caps);
|
2013-01-28 15:28:29 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (demux), gst_object_ref (stream->pad));
|
2013-05-08 14:13:32 +00:00
|
|
|
}
|
2013-02-07 23:58:37 +00:00
|
|
|
gst_element_no_more_pads (GST_ELEMENT_CAST (demux));
|
2013-05-08 14:13:32 +00:00
|
|
|
}
|
|
|
|
|
2013-02-13 04:13:23 +00:00
|
|
|
static void
|
|
|
|
gst_dash_demux_remove_streams (GstDashDemux * demux, GSList * streams)
|
|
|
|
{
|
|
|
|
GSList *iter;
|
|
|
|
GstEvent *eos = gst_event_new_eos ();
|
|
|
|
|
|
|
|
for (iter = streams; iter; iter = g_slist_next (iter)) {
|
|
|
|
GstDashDemuxStream *stream = iter->data;;
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (demux, "Removing stream %d %" GST_PTR_FORMAT, stream->index,
|
|
|
|
stream->input_caps);
|
|
|
|
gst_pad_push_event (stream->pad, gst_event_ref (eos));
|
|
|
|
gst_pad_set_active (stream->pad, FALSE);
|
|
|
|
gst_element_remove_pad (GST_ELEMENT (demux), stream->pad);
|
|
|
|
gst_dash_demux_stream_free (stream);
|
|
|
|
}
|
|
|
|
gst_event_unref (eos);
|
|
|
|
g_slist_free (streams);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_dash_demux_advance_period (GstDashDemux * demux)
|
|
|
|
{
|
|
|
|
GSList *old_period = NULL;
|
2013-04-18 10:41:09 +00:00
|
|
|
g_mutex_lock (&demux->streams_lock);
|
2013-02-13 04:13:23 +00:00
|
|
|
|
2013-04-11 12:12:26 +00:00
|
|
|
GST_DEBUG_OBJECT (demux, "Advancing period from %p", demux->streams);
|
|
|
|
|
2013-02-13 04:13:23 +00:00
|
|
|
if (demux->streams) {
|
|
|
|
g_assert (demux->streams == demux->next_periods->data);
|
|
|
|
|
|
|
|
demux->next_periods = g_slist_remove (demux->next_periods, demux->streams);
|
|
|
|
old_period = demux->streams;
|
|
|
|
demux->streams = NULL;
|
|
|
|
}
|
|
|
|
|
2013-04-11 12:12:26 +00:00
|
|
|
GST_DEBUG_OBJECT (demux, "Next period %p", demux->next_periods);
|
|
|
|
|
2013-02-13 04:13:23 +00:00
|
|
|
if (demux->next_periods) {
|
|
|
|
demux->streams = demux->next_periods->data;
|
|
|
|
} else {
|
|
|
|
GST_DEBUG_OBJECT (demux, "No next periods, return FALSE");
|
2013-04-18 10:41:09 +00:00
|
|
|
g_mutex_unlock (&demux->streams_lock);
|
2013-02-13 04:13:23 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_dash_demux_expose_streams (demux);
|
|
|
|
gst_dash_demux_remove_streams (demux, old_period);
|
|
|
|
|
2013-04-18 10:41:09 +00:00
|
|
|
g_mutex_unlock (&demux->streams_lock);
|
2013-02-13 04:13:23 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-10-15 11:35:15 +00:00
|
|
|
/* gst_dash_demux_stream_loop:
|
|
|
|
*
|
|
|
|
* Loop for the "stream' task that pushes fragments to the src pads.
|
|
|
|
*
|
|
|
|
* Startup:
|
|
|
|
* The task is started as soon as we have received the manifest and
|
|
|
|
* waits for the first fragment to be downloaded and pushed in the
|
|
|
|
* queue. Once this fragment has been pushed, the task pauses itself
|
|
|
|
* until actual playback begins.
|
|
|
|
*
|
|
|
|
* During playback:
|
|
|
|
* The task pushes fragments downstream at regular intervals based on
|
|
|
|
* the fragment duration. If it detects a queue underrun, it sends
|
|
|
|
* a buffering event to tell the main application to pause.
|
|
|
|
*
|
|
|
|
* Teardown:
|
2012-10-15 11:54:17 +00:00
|
|
|
* The task is stopped when we have reached the end of the manifest
|
|
|
|
* and emptied our queue.
|
|
|
|
*
|
2012-10-15 11:35:15 +00:00
|
|
|
*/
|
2013-05-08 14:13:32 +00:00
|
|
|
static void
|
|
|
|
gst_dash_demux_stream_loop (GstDashDemux * demux)
|
|
|
|
{
|
|
|
|
GstFlowReturn ret;
|
2013-01-28 13:46:27 +00:00
|
|
|
GstActiveStream *active_stream;
|
|
|
|
GSList *iter;
|
2013-01-29 04:06:52 +00:00
|
|
|
GstClockTime best_time;
|
|
|
|
GstDashDemuxStream *selected_stream;
|
2013-01-29 18:58:50 +00:00
|
|
|
gboolean eos = TRUE;
|
|
|
|
gboolean eop = TRUE;
|
2013-05-08 14:13:32 +00:00
|
|
|
|
2013-01-28 15:28:29 +00:00
|
|
|
GST_LOG_OBJECT (demux, "Starting stream loop");
|
|
|
|
|
2013-01-29 04:06:52 +00:00
|
|
|
best_time = GST_CLOCK_TIME_NONE;
|
|
|
|
selected_stream = NULL;
|
2013-02-13 04:13:23 +00:00
|
|
|
|
|
|
|
for (iter = demux->streams; iter; iter = g_slist_next (iter)) {
|
2013-01-28 13:46:27 +00:00
|
|
|
GstDashDemuxStream *stream = iter->data;
|
2013-01-29 04:06:52 +00:00
|
|
|
GstDataQueueItem *item;
|
|
|
|
|
2013-02-05 17:24:45 +00:00
|
|
|
GST_DEBUG_OBJECT (demux, "Peeking stream %d", stream->index);
|
|
|
|
|
|
|
|
if (stream->stream_eos) {
|
|
|
|
GST_DEBUG_OBJECT (demux, "Stream %d is eos, skipping", stream->index);
|
2013-01-29 18:58:50 +00:00
|
|
|
continue;
|
2013-02-05 17:24:45 +00:00
|
|
|
}
|
2013-01-29 18:58:50 +00:00
|
|
|
|
|
|
|
if (stream->stream_end_of_period) {
|
2013-02-05 17:24:45 +00:00
|
|
|
GST_DEBUG_OBJECT (demux, "Stream %d is eop, skipping", stream->index);
|
2013-01-29 18:58:50 +00:00
|
|
|
eos = FALSE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
eos = FALSE;
|
|
|
|
eop = FALSE;
|
|
|
|
|
2013-02-05 17:24:45 +00:00
|
|
|
GST_DEBUG_OBJECT (demux, "peeking at the queue for stream %d",
|
|
|
|
stream->index);
|
2013-02-05 00:58:32 +00:00
|
|
|
if (!gst_data_queue_peek (stream->queue, &item)) {
|
|
|
|
/* flushing */
|
|
|
|
goto flushing;
|
|
|
|
}
|
2013-01-28 15:28:29 +00:00
|
|
|
|
2013-01-29 18:58:50 +00:00
|
|
|
if (G_LIKELY (GST_IS_BUFFER (item->object))) {
|
2013-03-08 13:57:39 +00:00
|
|
|
GstBuffer *buffer;
|
|
|
|
GstClockTime timestamp;
|
|
|
|
|
|
|
|
buffer = GST_BUFFER_CAST (item->object);
|
|
|
|
timestamp = GST_BUFFER_TIMESTAMP (buffer);
|
|
|
|
|
2013-02-22 19:40:36 +00:00
|
|
|
GST_LOG_OBJECT (demux, "Buffer with time %" GST_TIME_FORMAT,
|
2013-03-08 13:57:39 +00:00
|
|
|
GST_TIME_ARGS (timestamp));
|
|
|
|
|
|
|
|
if (timestamp < best_time) {
|
2013-02-22 19:40:36 +00:00
|
|
|
GST_DEBUG_OBJECT (demux, "Found new best time: %" GST_TIME_FORMAT " %p",
|
2013-03-08 13:57:39 +00:00
|
|
|
GST_TIME_ARGS (timestamp), buffer);
|
|
|
|
best_time = timestamp;
|
2013-01-29 04:06:52 +00:00
|
|
|
selected_stream = stream;
|
2013-03-08 13:57:39 +00:00
|
|
|
} else if (!GST_CLOCK_TIME_IS_VALID (timestamp)) {
|
2013-01-29 04:06:52 +00:00
|
|
|
selected_stream = stream;
|
2013-02-22 19:40:36 +00:00
|
|
|
GST_DEBUG_OBJECT (demux, "Buffer without timestamp selected %p",
|
2013-03-08 13:57:39 +00:00
|
|
|
buffer);
|
2013-01-29 04:06:52 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
2013-07-31 01:06:38 +00:00
|
|
|
GST_DEBUG_OBJECT (demux, "Non buffers have preference %" GST_PTR_FORMAT, item->object);
|
2013-01-29 04:06:52 +00:00
|
|
|
selected_stream = stream;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (selected_stream) {
|
|
|
|
GstDataQueueItem *item;
|
2013-02-05 17:24:45 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (demux, "Selected stream %p %d", selected_stream,
|
|
|
|
selected_stream->index);
|
|
|
|
|
2013-01-29 04:06:52 +00:00
|
|
|
if (!gst_data_queue_pop (selected_stream->queue, &item))
|
|
|
|
goto end;
|
2013-01-28 21:52:04 +00:00
|
|
|
|
2013-01-29 18:58:50 +00:00
|
|
|
if (G_LIKELY (GST_IS_BUFFER (item->object))) {
|
2013-03-08 14:04:48 +00:00
|
|
|
GstBuffer *buffer;
|
|
|
|
GstClockTime timestamp;
|
|
|
|
|
2013-01-29 18:58:50 +00:00
|
|
|
buffer = GST_BUFFER_CAST (item->object);
|
|
|
|
active_stream =
|
|
|
|
gst_mpdparser_get_active_stream_by_index (demux->client,
|
|
|
|
selected_stream->index);
|
2013-03-08 14:04:48 +00:00
|
|
|
|
|
|
|
timestamp = GST_BUFFER_TIMESTAMP (buffer);
|
|
|
|
|
2013-02-12 20:50:51 +00:00
|
|
|
if (demux->need_segment) {
|
2013-03-13 14:55:03 +00:00
|
|
|
if (demux->timestamp_offset == -1)
|
|
|
|
demux->timestamp_offset = timestamp;
|
2013-03-08 14:04:48 +00:00
|
|
|
|
2013-01-29 18:58:50 +00:00
|
|
|
/* And send a newsegment */
|
2013-02-13 04:13:23 +00:00
|
|
|
for (iter = demux->streams; iter; iter = g_slist_next (iter)) {
|
2013-01-29 18:58:50 +00:00
|
|
|
GstDashDemuxStream *stream = iter->data;
|
|
|
|
gst_pad_push_event (stream->pad,
|
2013-04-18 10:41:09 +00:00
|
|
|
gst_event_new_segment (&demux->segment));
|
2013-01-29 18:58:50 +00:00
|
|
|
}
|
2013-02-12 20:50:51 +00:00
|
|
|
demux->need_segment = FALSE;
|
2013-01-29 18:58:50 +00:00
|
|
|
}
|
2013-03-08 14:04:48 +00:00
|
|
|
/* make timestamp start from 0 by subtracting the offset */
|
|
|
|
timestamp -= demux->timestamp_offset;
|
|
|
|
|
|
|
|
GST_BUFFER_TIMESTAMP (buffer) = timestamp;
|
2013-01-29 18:58:50 +00:00
|
|
|
|
2013-02-22 20:00:27 +00:00
|
|
|
GST_DEBUG_OBJECT (demux,
|
|
|
|
"Pushing fragment ts: %" GST_TIME_FORMAT " at pad %s",
|
2013-03-08 14:04:48 +00:00
|
|
|
GST_TIME_ARGS (timestamp), GST_PAD_NAME (selected_stream->pad));
|
2013-02-22 20:00:27 +00:00
|
|
|
#if 0
|
2013-01-29 18:58:50 +00:00
|
|
|
GST_DEBUG_OBJECT (demux,
|
|
|
|
"Pushing fragment %p #%d (stream %i) ts:%" GST_TIME_FORMAT " dur:%"
|
2013-02-13 04:13:23 +00:00
|
|
|
GST_TIME_FORMAT " at pad: %s:%s", buffer, GST_BUFFER_OFFSET (buffer),
|
2013-01-29 18:58:50 +00:00
|
|
|
selected_stream->index, GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)),
|
2013-02-13 04:13:23 +00:00
|
|
|
GST_TIME_ARGS (GST_BUFFER_DURATION (buffer)),
|
|
|
|
GST_DEBUG_PAD_NAME (selected_stream->pad));
|
2013-02-22 20:00:27 +00:00
|
|
|
#endif
|
2013-01-29 18:58:50 +00:00
|
|
|
ret = gst_pad_push (selected_stream->pad, gst_buffer_ref (buffer));
|
2013-04-18 10:41:09 +00:00
|
|
|
demux->segment.position = timestamp;
|
2013-03-08 14:04:48 +00:00
|
|
|
|
2013-01-29 18:58:50 +00:00
|
|
|
item->destroy (item);
|
|
|
|
if ((ret != GST_FLOW_OK) && (active_stream
|
|
|
|
&& active_stream->mimeType == GST_STREAM_VIDEO))
|
|
|
|
goto error_pushing;
|
|
|
|
} else {
|
|
|
|
/* a GstEvent */
|
|
|
|
if (GST_EVENT_TYPE (item->object) == GST_EVENT_EOS) {
|
|
|
|
selected_stream->stream_end_of_period = TRUE;
|
|
|
|
selected_stream->stream_eos = TRUE;
|
|
|
|
} else if (GST_EVENT_TYPE (item->object) == GST_EVENT_DASH_EOP) {
|
|
|
|
selected_stream->stream_end_of_period = TRUE;
|
2013-01-29 04:06:52 +00:00
|
|
|
}
|
2013-05-08 14:13:32 +00:00
|
|
|
|
2013-01-29 18:58:50 +00:00
|
|
|
if (GST_EVENT_TYPE (item->object) != GST_EVENT_DASH_EOP) {
|
|
|
|
gst_pad_push_event (selected_stream->pad,
|
|
|
|
gst_event_ref (GST_EVENT_CAST (item->object)));
|
|
|
|
}
|
|
|
|
item->destroy (item);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (eos) {
|
|
|
|
goto end_of_manifest;
|
|
|
|
} else if (eop) {
|
2013-02-13 04:13:23 +00:00
|
|
|
gst_dash_demux_advance_period (demux);
|
2013-01-29 18:58:50 +00:00
|
|
|
}
|
2013-05-08 14:13:32 +00:00
|
|
|
}
|
|
|
|
|
2013-01-29 04:06:52 +00:00
|
|
|
end:
|
2013-02-05 00:58:32 +00:00
|
|
|
GST_INFO_OBJECT (demux, "Leaving streaming task");
|
2013-01-25 15:45:18 +00:00
|
|
|
return;
|
2013-05-08 14:13:32 +00:00
|
|
|
|
2013-02-05 00:58:32 +00:00
|
|
|
flushing:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (demux, "Flushing, leaving streaming task");
|
|
|
|
gst_task_stop (demux->stream_task);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-15 09:40:55 +00:00
|
|
|
end_of_manifest:
|
2013-05-08 14:13:32 +00:00
|
|
|
{
|
2012-10-15 14:41:28 +00:00
|
|
|
GST_INFO_OBJECT (demux, "Reached end of manifest, sending EOS");
|
2013-01-28 13:46:27 +00:00
|
|
|
for (iter = demux->streams; iter; iter = g_slist_next (iter)) {
|
|
|
|
GstDashDemuxStream *stream = iter->data;
|
|
|
|
gst_pad_push_event (stream->pad, gst_event_new_eos ());
|
2013-05-08 14:13:32 +00:00
|
|
|
}
|
2012-10-16 11:43:39 +00:00
|
|
|
GST_INFO_OBJECT (demux, "Stopped streaming task");
|
|
|
|
gst_task_stop (demux->stream_task);
|
2013-05-08 14:13:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
error_pushing:
|
|
|
|
{
|
|
|
|
/* FIXME: handle error */
|
2012-10-16 11:43:39 +00:00
|
|
|
GST_ERROR_OBJECT (demux,
|
|
|
|
"Error pushing buffer: %s... terminating the demux",
|
2013-05-08 14:13:32 +00:00
|
|
|
gst_flow_get_name (ret));
|
2013-02-05 00:58:32 +00:00
|
|
|
gst_task_stop (demux->stream_task);
|
2013-05-08 14:13:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-28 15:28:29 +00:00
|
|
|
static void
|
|
|
|
gst_dash_demux_stream_free (GstDashDemuxStream * stream)
|
|
|
|
{
|
2013-02-05 20:38:06 +00:00
|
|
|
gst_download_rate_deinit (&stream->dnl_rate);
|
2013-02-05 00:58:32 +00:00
|
|
|
if (stream->input_caps) {
|
2013-01-28 15:28:29 +00:00
|
|
|
gst_caps_unref (stream->input_caps);
|
2013-02-05 00:58:32 +00:00
|
|
|
stream->input_caps = NULL;
|
|
|
|
}
|
|
|
|
if (stream->pad) {
|
2013-01-28 15:28:29 +00:00
|
|
|
gst_object_unref (stream->pad);
|
2013-02-05 00:58:32 +00:00
|
|
|
stream->pad = NULL;
|
|
|
|
}
|
|
|
|
if (stream->queue) {
|
|
|
|
g_object_unref (stream->queue);
|
|
|
|
stream->queue = NULL;
|
|
|
|
}
|
2013-01-28 15:28:29 +00:00
|
|
|
|
|
|
|
g_free (stream);
|
|
|
|
}
|
|
|
|
|
2013-05-08 14:13:32 +00:00
|
|
|
static void
|
|
|
|
gst_dash_demux_reset (GstDashDemux * demux, gboolean dispose)
|
|
|
|
{
|
2013-01-28 13:46:27 +00:00
|
|
|
GSList *iter;
|
2013-01-25 12:36:35 +00:00
|
|
|
|
2013-02-05 17:24:45 +00:00
|
|
|
GST_DEBUG_OBJECT (demux, "Resetting demux");
|
|
|
|
|
2012-10-24 09:49:51 +00:00
|
|
|
demux->end_of_period = FALSE;
|
2012-10-15 09:40:55 +00:00
|
|
|
demux->end_of_manifest = FALSE;
|
2013-05-08 14:13:32 +00:00
|
|
|
|
2013-02-05 00:58:32 +00:00
|
|
|
demux->cancelled = TRUE;
|
|
|
|
gst_dash_demux_stop (demux);
|
|
|
|
if (demux->downloader)
|
|
|
|
gst_uri_downloader_reset (demux->downloader);
|
2013-01-28 15:28:29 +00:00
|
|
|
|
2013-02-18 17:02:48 +00:00
|
|
|
if (demux->next_periods) {
|
2013-04-11 12:12:26 +00:00
|
|
|
g_assert (demux->next_periods->data == demux->streams);
|
2013-02-18 17:02:48 +00:00
|
|
|
demux->next_periods =
|
|
|
|
g_slist_delete_link (demux->next_periods, demux->next_periods);
|
|
|
|
}
|
|
|
|
|
2013-01-28 13:46:27 +00:00
|
|
|
for (iter = demux->streams; iter; iter = g_slist_next (iter)) {
|
|
|
|
GstDashDemuxStream *stream = iter->data;
|
2013-02-05 03:29:28 +00:00
|
|
|
if (stream->pad) {
|
|
|
|
GST_INFO_OBJECT (demux, "Removing stream pad %s:%s",
|
|
|
|
GST_DEBUG_PAD_NAME (stream->pad));
|
2013-02-05 00:58:32 +00:00
|
|
|
gst_element_remove_pad (GST_ELEMENT (demux), stream->pad);
|
2013-02-05 03:29:28 +00:00
|
|
|
}
|
2013-01-28 15:28:29 +00:00
|
|
|
gst_dash_demux_stream_free (stream);
|
2013-01-28 13:46:27 +00:00
|
|
|
}
|
2013-01-28 15:28:29 +00:00
|
|
|
g_slist_free (demux->streams);
|
|
|
|
demux->streams = NULL;
|
2013-05-08 14:13:32 +00:00
|
|
|
|
2013-02-18 17:02:48 +00:00
|
|
|
for (iter = demux->next_periods; iter; iter = g_slist_next (iter)) {
|
|
|
|
GSList *streams = iter->data;
|
|
|
|
g_slist_free_full (streams, (GDestroyNotify) gst_dash_demux_stream_free);
|
|
|
|
}
|
|
|
|
g_slist_free (demux->next_periods);
|
|
|
|
demux->next_periods = NULL;
|
|
|
|
|
2012-10-15 09:40:55 +00:00
|
|
|
if (demux->manifest) {
|
|
|
|
gst_buffer_unref (demux->manifest);
|
|
|
|
demux->manifest = NULL;
|
2013-05-08 14:13:32 +00:00
|
|
|
}
|
|
|
|
if (demux->client) {
|
|
|
|
gst_mpd_client_free (demux->client);
|
|
|
|
demux->client = NULL;
|
|
|
|
}
|
|
|
|
if (!dispose) {
|
|
|
|
demux->client = gst_mpd_client_new ();
|
|
|
|
}
|
|
|
|
|
2013-02-01 03:37:33 +00:00
|
|
|
gst_segment_init (&demux->segment, GST_FORMAT_TIME);
|
2012-12-17 14:12:58 +00:00
|
|
|
demux->last_manifest_update = GST_CLOCK_TIME_NONE;
|
2013-02-05 00:58:32 +00:00
|
|
|
demux->cancelled = FALSE;
|
2013-05-08 14:13:32 +00:00
|
|
|
}
|
|
|
|
|
2013-07-29 07:35:08 +00:00
|
|
|
#ifndef GST_DISABLE_GST_DEBUG
|
2013-05-08 14:13:32 +00:00
|
|
|
static GstClockTime
|
|
|
|
gst_dash_demux_get_buffering_time (GstDashDemux * demux)
|
|
|
|
{
|
2013-01-29 16:04:01 +00:00
|
|
|
GstClockTime buffer_time = GST_CLOCK_TIME_NONE;
|
2013-01-28 15:28:29 +00:00
|
|
|
GSList *iter;
|
2012-10-24 12:24:05 +00:00
|
|
|
|
2013-01-28 15:28:29 +00:00
|
|
|
for (iter = demux->streams; iter; iter = g_slist_next (iter)) {
|
2013-01-29 16:04:01 +00:00
|
|
|
GstClockTime btime = gst_dash_demux_stream_get_buffering_time (iter->data);
|
2013-01-28 15:28:29 +00:00
|
|
|
|
2013-01-29 16:04:01 +00:00
|
|
|
if (!GST_CLOCK_TIME_IS_VALID (buffer_time) || buffer_time > btime)
|
|
|
|
buffer_time = btime;
|
2013-01-28 15:28:29 +00:00
|
|
|
}
|
|
|
|
|
2013-01-29 16:04:01 +00:00
|
|
|
if (!GST_CLOCK_TIME_IS_VALID (buffer_time))
|
|
|
|
buffer_time = 0;
|
|
|
|
return buffer_time;
|
2013-01-28 15:28:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstClockTime
|
|
|
|
gst_dash_demux_stream_get_buffering_time (GstDashDemuxStream * stream)
|
|
|
|
{
|
2013-01-28 21:52:04 +00:00
|
|
|
GstDataQueueSize level;
|
2012-10-24 12:24:05 +00:00
|
|
|
|
2013-01-28 21:52:04 +00:00
|
|
|
gst_data_queue_get_level (stream->queue, &level);
|
2012-10-24 12:24:05 +00:00
|
|
|
|
2013-01-28 21:52:04 +00:00
|
|
|
return (GstClockTime) level.time;
|
2013-05-08 14:13:32 +00:00
|
|
|
}
|
2013-07-29 07:35:08 +00:00
|
|
|
#endif
|
2013-05-08 14:13:32 +00:00
|
|
|
|
2013-02-01 05:10:15 +00:00
|
|
|
static gboolean
|
|
|
|
gst_dash_demux_all_streams_have_data (GstDashDemux * demux)
|
|
|
|
{
|
|
|
|
GSList *iter;
|
|
|
|
|
|
|
|
for (iter = demux->streams; iter; iter = g_slist_next (iter)) {
|
|
|
|
GstDashDemuxStream *stream = iter->data;
|
|
|
|
|
|
|
|
if (!stream->has_data_queued)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-07-09 03:47:07 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
gst_dash_demux_refresh_mpd (GstDashDemux * demux)
|
|
|
|
{
|
|
|
|
GstFragment *download;
|
|
|
|
GstBuffer *buffer;
|
|
|
|
GstClockTime duration, now = gst_util_get_timestamp ();
|
|
|
|
gint64 update_period = demux->client->mpd_node->minimumUpdatePeriod;
|
|
|
|
|
|
|
|
if (update_period == -1) {
|
|
|
|
GST_DEBUG_OBJECT (demux, "minimumUpdatePeriod unspecified, "
|
|
|
|
"will not update MPD");
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* init reference time for manifest file updates */
|
|
|
|
if (!GST_CLOCK_TIME_IS_VALID (demux->last_manifest_update))
|
|
|
|
demux->last_manifest_update = now;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (demux,
|
|
|
|
"Next update: %" GST_TIME_FORMAT " now: %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS ((demux->last_manifest_update +
|
|
|
|
update_period * GST_MSECOND)), GST_TIME_ARGS (now));
|
|
|
|
|
|
|
|
/* update the manifest file */
|
|
|
|
if (now >= demux->last_manifest_update + update_period * GST_MSECOND) {
|
|
|
|
GST_DEBUG_OBJECT (demux, "Updating manifest file from URL %s",
|
|
|
|
demux->client->mpd_uri);
|
|
|
|
download = gst_uri_downloader_fetch_uri (demux->downloader,
|
|
|
|
demux->client->mpd_uri);
|
|
|
|
if (download) {
|
|
|
|
GstMpdClient *new_client = NULL;
|
|
|
|
|
|
|
|
buffer = gst_fragment_get_buffer (download);
|
|
|
|
g_object_unref (download);
|
|
|
|
/* parse the manifest file */
|
|
|
|
if (buffer != NULL) {
|
|
|
|
GstMapInfo mapinfo;
|
|
|
|
|
|
|
|
new_client = gst_mpd_client_new ();
|
|
|
|
new_client->mpd_uri = g_strdup (demux->client->mpd_uri);
|
|
|
|
|
|
|
|
gst_buffer_map (buffer, &mapinfo, GST_MAP_READ);
|
|
|
|
|
|
|
|
if (gst_mpd_parse (new_client, (gchar *) mapinfo.data, mapinfo.size)) {
|
|
|
|
const gchar *period_id;
|
|
|
|
guint period_idx;
|
|
|
|
GSList *iter;
|
|
|
|
|
|
|
|
/* prepare the new manifest and try to transfer the stream position
|
|
|
|
* status from the old manifest client */
|
|
|
|
|
|
|
|
gst_buffer_unmap (buffer, &mapinfo);
|
|
|
|
gst_buffer_unref (buffer);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (demux, "Updating manifest");
|
|
|
|
|
|
|
|
period_id = gst_mpd_client_get_period_id (demux->client);
|
|
|
|
period_idx = gst_mpd_client_get_period_index (demux->client);
|
|
|
|
|
|
|
|
/* setup video, audio and subtitle streams, starting from current Period */
|
|
|
|
if (!gst_mpd_client_setup_media_presentation (new_client)) {
|
|
|
|
/* TODO */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (period_idx) {
|
|
|
|
if (!gst_mpd_client_set_period_id (new_client, period_id)) {
|
|
|
|
GST_DEBUG_OBJECT (demux,
|
|
|
|
"Error setting up the updated manifest file");
|
|
|
|
return GST_FLOW_EOS;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!gst_mpd_client_set_period_index (new_client, period_idx)) {
|
|
|
|
GST_DEBUG_OBJECT (demux,
|
|
|
|
"Error setting up the updated manifest file");
|
|
|
|
return GST_FLOW_EOS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-31 01:06:38 +00:00
|
|
|
if (!gst_dash_demux_setup_mpdparser_streams (demux, new_client)) {
|
|
|
|
GST_ERROR_OBJECT (demux, "Failed to setup streams on manifest "
|
|
|
|
"update");
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
2013-07-09 03:47:07 +00:00
|
|
|
|
|
|
|
/* update the streams to play from the next segment */
|
|
|
|
for (iter = demux->streams; iter; iter = g_slist_next (iter)) {
|
|
|
|
GstDashDemuxStream *demux_stream = iter->data;
|
|
|
|
GstActiveStream *new_stream;
|
|
|
|
GstClockTime ts;
|
|
|
|
|
|
|
|
new_stream =
|
|
|
|
gst_mpdparser_get_active_stream_by_index (new_client,
|
|
|
|
demux_stream->index);
|
|
|
|
|
|
|
|
if (!new_stream) {
|
|
|
|
GST_DEBUG_OBJECT (demux,
|
2013-07-23 08:04:42 +00:00
|
|
|
"Stream of index %d is missing from manifest update",
|
2013-07-09 03:47:07 +00:00
|
|
|
demux_stream->index);
|
|
|
|
return GST_FLOW_EOS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gst_mpd_client_get_next_fragment_timestamp (demux->client,
|
|
|
|
demux_stream->index, &ts)) {
|
|
|
|
gst_mpd_client_stream_seek (new_client, new_stream, ts);
|
|
|
|
} else
|
|
|
|
if (gst_mpd_client_get_last_fragment_timestamp (demux->client,
|
|
|
|
demux_stream->index, &ts)) {
|
|
|
|
/* try to set to the old timestamp + 1 */
|
|
|
|
gst_mpd_client_stream_seek (new_client, new_stream, ts + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_mpd_client_free (demux->client);
|
|
|
|
demux->client = new_client;
|
|
|
|
|
|
|
|
/* Send an updated duration message */
|
|
|
|
duration =
|
|
|
|
gst_mpd_client_get_media_presentation_duration (demux->client);
|
|
|
|
|
|
|
|
if (duration != GST_CLOCK_TIME_NONE) {
|
|
|
|
GST_DEBUG_OBJECT (demux,
|
|
|
|
"Sending duration message : %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (duration));
|
|
|
|
gst_element_post_message (GST_ELEMENT (demux),
|
|
|
|
gst_message_new_duration_changed (GST_OBJECT (demux)));
|
|
|
|
} else {
|
|
|
|
GST_DEBUG_OBJECT (demux,
|
|
|
|
"mediaPresentationDuration unknown, can not send the duration message");
|
|
|
|
}
|
|
|
|
demux->last_manifest_update = gst_util_get_timestamp ();
|
|
|
|
GST_DEBUG_OBJECT (demux, "Manifest file successfully updated");
|
|
|
|
} else {
|
|
|
|
/* In most cases, this will happen if we set a wrong url in the
|
|
|
|
* source element and we have received the 404 HTML response instead of
|
|
|
|
* the manifest */
|
|
|
|
GST_WARNING_OBJECT (demux, "Error parsing the manifest.");
|
|
|
|
gst_buffer_unmap (buffer, &mapinfo);
|
|
|
|
gst_buffer_unref (buffer);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* download suceeded, but resulting buffer is NULL */
|
|
|
|
GST_WARNING_OBJECT (demux, "Error validating the manifest.");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* download failed */
|
|
|
|
GST_WARNING_OBJECT (demux,
|
|
|
|
"Failed to update the manifest file from URL %s",
|
|
|
|
demux->client->mpd_uri);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
2012-10-15 11:52:31 +00:00
|
|
|
/* gst_dash_demux_download_loop:
|
|
|
|
*
|
|
|
|
* Loop for the "download' task that fetches fragments based on the
|
2012-10-15 13:08:53 +00:00
|
|
|
* selected representations.
|
2012-10-15 11:52:31 +00:00
|
|
|
*
|
|
|
|
* Startup:
|
|
|
|
*
|
|
|
|
* The task is started from the stream loop.
|
|
|
|
*
|
|
|
|
* During playback:
|
|
|
|
*
|
|
|
|
* It sequentially fetches fragments corresponding to the current
|
2012-10-15 13:08:53 +00:00
|
|
|
* representations and pushes them into a queue.
|
2012-10-15 11:52:31 +00:00
|
|
|
*
|
|
|
|
* It tries to maintain the number of queued items within a predefined
|
|
|
|
* range: if the queue is full, it will pause, checking every 100 ms if
|
|
|
|
* it needs to restart downloading fragments.
|
|
|
|
*
|
|
|
|
* When a new set of fragments has been downloaded, it evaluates the
|
|
|
|
* download time to check if we can or should switch to a different
|
2012-10-15 13:08:53 +00:00
|
|
|
* set of representations.
|
2012-10-15 11:52:31 +00:00
|
|
|
*
|
|
|
|
* Teardown:
|
|
|
|
*
|
2012-10-16 11:43:39 +00:00
|
|
|
* The task will exit when it encounters an error or when the end of the
|
|
|
|
* manifest has been reached.
|
2012-10-15 11:52:31 +00:00
|
|
|
*
|
|
|
|
*/
|
2013-05-08 14:13:32 +00:00
|
|
|
void
|
|
|
|
gst_dash_demux_download_loop (GstDashDemux * demux)
|
|
|
|
{
|
2013-07-09 02:24:28 +00:00
|
|
|
GstClockTime fragment_ts = GST_CLOCK_TIME_NONE;
|
|
|
|
GstActiveStream *fragment_stream = NULL;
|
2012-12-17 14:12:58 +00:00
|
|
|
|
2013-02-07 16:09:44 +00:00
|
|
|
GST_LOG_OBJECT (demux, "Starting download loop");
|
|
|
|
|
2013-02-22 19:40:36 +00:00
|
|
|
if (gst_mpd_client_is_live (demux->client)
|
2013-07-09 03:47:07 +00:00
|
|
|
&& demux->client->mpd_uri != NULL) {
|
|
|
|
switch (gst_dash_demux_refresh_mpd (demux)) {
|
|
|
|
case GST_FLOW_EOS:
|
|
|
|
goto end_of_manifest;
|
|
|
|
default:
|
|
|
|
break;
|
2012-12-17 14:12:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-16 18:58:52 +00:00
|
|
|
GST_DEBUG_OBJECT (demux, "download loop %i", demux->end_of_manifest);
|
2013-05-08 14:13:32 +00:00
|
|
|
|
2013-02-01 03:33:00 +00:00
|
|
|
/* try to switch to another set of representations if needed */
|
2013-02-01 05:10:15 +00:00
|
|
|
if (gst_dash_demux_all_streams_have_data (demux)) {
|
2013-02-05 17:22:51 +00:00
|
|
|
gst_dash_demux_select_representations (demux);
|
2013-02-01 05:10:15 +00:00
|
|
|
}
|
2013-02-01 03:33:00 +00:00
|
|
|
|
|
|
|
/* fetch the next fragment */
|
2013-07-09 02:24:28 +00:00
|
|
|
while (!gst_dash_demux_get_next_fragment (demux, &fragment_stream,
|
|
|
|
&fragment_ts)) {
|
2013-02-01 03:33:00 +00:00
|
|
|
if (demux->end_of_period) {
|
|
|
|
GST_INFO_OBJECT (demux, "Reached the end of the Period");
|
|
|
|
/* setup video, audio and subtitle streams, starting from the next Period */
|
|
|
|
if (!gst_mpd_client_set_period_index (demux->client,
|
|
|
|
gst_mpd_client_get_period_index (demux->client) + 1)
|
|
|
|
|| !gst_dash_demux_setup_all_streams (demux)) {
|
|
|
|
GST_INFO_OBJECT (demux, "Reached the end of the manifest file");
|
|
|
|
demux->end_of_manifest = TRUE;
|
|
|
|
gst_task_start (demux->stream_task);
|
|
|
|
goto end_of_manifest;
|
|
|
|
}
|
|
|
|
/* start playing from the first segment of the new period */
|
|
|
|
gst_mpd_client_set_segment_index_for_all_streams (demux->client, 0);
|
|
|
|
demux->end_of_period = FALSE;
|
2013-07-09 03:47:07 +00:00
|
|
|
|
2013-02-01 03:33:00 +00:00
|
|
|
} else if (!demux->cancelled) {
|
2013-07-09 03:47:07 +00:00
|
|
|
/* Download failed 'by itself'
|
|
|
|
* in case this is live, we might be ahead or before playback, where
|
|
|
|
* segments don't exist (are still being created or were already deleted)
|
|
|
|
* so we either wait or jump ahead */
|
2013-07-09 02:24:28 +00:00
|
|
|
if (gst_mpd_client_is_live (demux->client)) {
|
|
|
|
gint64 time_diff;
|
|
|
|
gint pos;
|
|
|
|
|
|
|
|
pos =
|
|
|
|
gst_mpd_client_check_time_position (demux->client, fragment_stream,
|
|
|
|
fragment_ts, &time_diff);
|
|
|
|
GST_DEBUG_OBJECT (demux,
|
|
|
|
"Checked position for fragment ts %" GST_TIME_FORMAT
|
|
|
|
", res: %d, diff: %" G_GINT64_FORMAT, GST_TIME_ARGS (fragment_ts),
|
|
|
|
pos, time_diff);
|
|
|
|
|
|
|
|
time_diff *= GST_USECOND;
|
|
|
|
if (pos < 0) {
|
|
|
|
/* we're behind, try moving to the 'present' */
|
|
|
|
GDateTime *now = g_date_time_new_now_utc ();
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (demux,
|
|
|
|
"Falling behind live stream, moving forward");
|
|
|
|
gst_mpd_client_seek_to_time (demux->client, now);
|
|
|
|
g_date_time_unref (now);
|
|
|
|
|
|
|
|
} else if (pos > 0) {
|
|
|
|
/* we're ahead, wait a little */
|
2013-07-09 03:47:07 +00:00
|
|
|
|
2013-07-23 08:04:42 +00:00
|
|
|
GST_DEBUG_OBJECT (demux, "Waiting for next segment to be created");
|
2013-07-09 02:24:28 +00:00
|
|
|
gst_mpd_client_set_segment_index (fragment_stream,
|
|
|
|
fragment_stream->segment_idx - 1);
|
|
|
|
gst_dash_demux_download_wait (demux, time_diff);
|
|
|
|
} else {
|
|
|
|
gst_mpd_client_set_segment_index (fragment_stream,
|
|
|
|
fragment_stream->segment_idx - 1);
|
|
|
|
demux->client->update_failed_count++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
demux->client->update_failed_count++;
|
|
|
|
}
|
2013-07-09 03:47:07 +00:00
|
|
|
|
2013-02-01 03:33:00 +00:00
|
|
|
if (demux->client->update_failed_count < DEFAULT_FAILED_COUNT) {
|
|
|
|
GST_WARNING_OBJECT (demux, "Could not fetch the next fragment");
|
2012-10-24 09:49:51 +00:00
|
|
|
goto quit;
|
2013-02-01 03:33:00 +00:00
|
|
|
} else {
|
|
|
|
goto error_downloading;
|
2013-05-08 14:13:32 +00:00
|
|
|
}
|
2013-02-05 00:58:32 +00:00
|
|
|
} else if (demux->cancelled) {
|
|
|
|
goto cancelled;
|
2013-05-08 14:13:32 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-09 03:47:07 +00:00
|
|
|
|
2013-02-01 03:33:00 +00:00
|
|
|
GST_INFO_OBJECT (demux, "Internal buffering : %" PRIu64 " s",
|
|
|
|
gst_dash_demux_get_buffering_time (demux) / GST_SECOND);
|
|
|
|
demux->client->update_failed_count = 0;
|
2012-10-17 08:02:39 +00:00
|
|
|
|
|
|
|
quit:
|
2013-07-31 01:06:38 +00:00
|
|
|
GST_DEBUG_OBJECT (demux, "Finishing download loop");
|
2013-02-05 00:58:32 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
cancelled:
|
2012-10-17 08:02:39 +00:00
|
|
|
{
|
2013-02-05 00:58:32 +00:00
|
|
|
GST_WARNING_OBJECT (demux, "Cancelled, leaving download task");
|
|
|
|
gst_task_stop (demux->download_task);
|
2012-10-17 08:02:39 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-16 11:43:39 +00:00
|
|
|
end_of_manifest:
|
2013-05-08 14:13:32 +00:00
|
|
|
{
|
2013-02-05 00:58:32 +00:00
|
|
|
GST_INFO_OBJECT (demux, "End of manifest, leaving download task");
|
2012-10-16 11:43:39 +00:00
|
|
|
gst_task_stop (demux->download_task);
|
|
|
|
return;
|
|
|
|
}
|
2012-10-17 08:02:39 +00:00
|
|
|
|
2012-10-16 11:43:39 +00:00
|
|
|
error_downloading:
|
|
|
|
{
|
2012-10-17 08:02:39 +00:00
|
|
|
GST_ELEMENT_ERROR (demux, RESOURCE, NOT_FOUND,
|
2013-02-05 00:58:32 +00:00
|
|
|
("Could not fetch the next fragment, leaving download task"), (NULL));
|
|
|
|
gst_task_stop (demux->download_task);
|
2012-10-16 11:43:39 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-05-08 14:13:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_dash_demux_resume_stream_task (GstDashDemux * demux)
|
|
|
|
{
|
|
|
|
gst_task_start (demux->stream_task);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_dash_demux_resume_download_task (GstDashDemux * demux)
|
|
|
|
{
|
|
|
|
gst_task_start (demux->download_task);
|
|
|
|
}
|
|
|
|
|
2012-10-15 13:08:53 +00:00
|
|
|
/* gst_dash_demux_select_representations:
|
2012-10-15 09:33:58 +00:00
|
|
|
*
|
2013-02-05 17:22:51 +00:00
|
|
|
* Select the most appropriate media representations based on current target
|
2012-10-15 09:33:58 +00:00
|
|
|
* bitrate.
|
|
|
|
*
|
2012-10-15 13:08:53 +00:00
|
|
|
* FIXME: all representations are selected against the same bitrate, but
|
|
|
|
* they will share the same bandwidth. This only works today because the
|
|
|
|
* audio representations bitrate usage is negligible as compared to the
|
|
|
|
* video representation one.
|
|
|
|
*
|
|
|
|
* Returns TRUE if a new set of representations has been selected
|
2012-10-15 09:33:58 +00:00
|
|
|
*/
|
2013-05-08 14:13:32 +00:00
|
|
|
static gboolean
|
2013-02-05 17:22:51 +00:00
|
|
|
gst_dash_demux_select_representations (GstDashDemux * demux)
|
2013-05-08 14:13:32 +00:00
|
|
|
{
|
2013-01-30 20:27:47 +00:00
|
|
|
GstActiveStream *active_stream = NULL;
|
2012-10-08 09:16:09 +00:00
|
|
|
GList *rep_list = NULL;
|
2013-05-08 14:13:32 +00:00
|
|
|
gint new_index;
|
|
|
|
gboolean ret = FALSE;
|
2013-01-30 20:27:47 +00:00
|
|
|
GSList *iter;
|
|
|
|
GstDashDemuxStream *stream;
|
2013-05-08 14:13:32 +00:00
|
|
|
|
|
|
|
guint i = 0;
|
2013-01-30 20:27:47 +00:00
|
|
|
|
2013-02-05 17:22:51 +00:00
|
|
|
|
2013-01-30 20:27:47 +00:00
|
|
|
GST_MPD_CLIENT_LOCK (demux->client);
|
|
|
|
for (iter = demux->streams; iter; iter = g_slist_next (iter)) {
|
2013-02-05 17:22:51 +00:00
|
|
|
guint64 bitrate;
|
2013-01-30 20:27:47 +00:00
|
|
|
stream = iter->data;
|
|
|
|
active_stream =
|
|
|
|
gst_mpdparser_get_active_stream_by_index (demux->client, stream->index);
|
|
|
|
if (!active_stream)
|
2013-05-08 14:13:32 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* retrieve representation list */
|
2013-01-30 20:27:47 +00:00
|
|
|
if (active_stream->cur_adapt_set)
|
|
|
|
rep_list = active_stream->cur_adapt_set->Representations;
|
2012-10-08 09:16:09 +00:00
|
|
|
if (!rep_list)
|
|
|
|
return FALSE;
|
2013-05-08 14:13:32 +00:00
|
|
|
|
2013-02-05 20:38:06 +00:00
|
|
|
bitrate =
|
|
|
|
gst_download_rate_get_current_rate (&stream->dnl_rate) *
|
|
|
|
demux->bandwidth_usage;
|
2013-04-23 15:08:07 +00:00
|
|
|
GST_DEBUG_OBJECT (demux, "Trying to change to bitrate: %" G_GUINT64_FORMAT,
|
|
|
|
bitrate);
|
2013-02-05 17:22:51 +00:00
|
|
|
|
2013-05-08 14:13:32 +00:00
|
|
|
/* get representation index with current max_bandwidth */
|
|
|
|
new_index =
|
|
|
|
gst_mpdparser_get_rep_idx_with_max_bandwidth (rep_list, bitrate);
|
|
|
|
|
2012-10-15 09:33:58 +00:00
|
|
|
/* if no representation has the required bandwidth, take the lowest one */
|
2013-05-08 14:13:32 +00:00
|
|
|
if (new_index == -1)
|
2013-01-16 18:58:52 +00:00
|
|
|
new_index = gst_mpdparser_get_rep_idx_with_min_bandwidth (rep_list);
|
2013-05-08 14:13:32 +00:00
|
|
|
|
2013-01-30 20:27:47 +00:00
|
|
|
if (new_index != active_stream->representation_idx) {
|
2013-02-05 17:22:51 +00:00
|
|
|
GstRepresentationNode *rep = g_list_nth_data (rep_list, new_index);
|
|
|
|
GST_INFO_OBJECT (demux, "Changing representation idx: %d %d %u",
|
|
|
|
stream->index, new_index, rep->bandwidth);
|
2013-01-30 20:27:47 +00:00
|
|
|
if (gst_mpd_client_setup_representation (demux->client, active_stream,
|
2013-02-05 17:22:51 +00:00
|
|
|
rep)) {
|
2013-01-30 20:27:47 +00:00
|
|
|
ret = TRUE;
|
2013-02-07 23:58:37 +00:00
|
|
|
stream->need_header = TRUE;
|
|
|
|
stream->has_data_queued = FALSE;
|
2013-05-08 14:13:32 +00:00
|
|
|
GST_INFO_OBJECT (demux, "Switching bitrate to %d",
|
2013-01-30 20:27:47 +00:00
|
|
|
active_stream->cur_representation->bandwidth);
|
2013-02-07 23:58:37 +00:00
|
|
|
gst_caps_unref (stream->input_caps);
|
|
|
|
stream->input_caps =
|
|
|
|
gst_dash_demux_get_input_caps (demux, active_stream);
|
2013-04-18 10:41:09 +00:00
|
|
|
gst_dash_demux_stream_push_event (stream,
|
|
|
|
gst_event_new_caps (stream->input_caps));
|
2013-05-08 14:13:32 +00:00
|
|
|
} else {
|
|
|
|
GST_WARNING_OBJECT (demux,
|
|
|
|
"Can not switch representation, aborting...");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
2013-01-30 20:27:47 +00:00
|
|
|
GST_MPD_CLIENT_UNLOCK (demux->client);
|
2013-05-08 14:13:32 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-07-01 16:19:15 +00:00
|
|
|
static GstBuffer *
|
|
|
|
gst_dash_demux_download_header_fragment (GstDashDemux * demux, guint stream_idx,
|
|
|
|
gchar * path, gint64 range_start, gint64 range_end)
|
2013-05-08 14:13:32 +00:00
|
|
|
{
|
2013-07-02 19:04:45 +00:00
|
|
|
GstBuffer *buffer = NULL;
|
2012-10-17 16:40:02 +00:00
|
|
|
gchar *next_header_uri;
|
|
|
|
GstFragment *fragment;
|
2013-05-08 14:13:32 +00:00
|
|
|
|
2013-07-01 16:19:15 +00:00
|
|
|
if (strncmp (path, "http://", 7) != 0) {
|
2013-05-08 14:13:32 +00:00
|
|
|
next_header_uri =
|
2013-01-16 18:58:52 +00:00
|
|
|
g_strconcat (gst_mpdparser_get_baseURL (demux->client, stream_idx),
|
2013-07-01 16:19:15 +00:00
|
|
|
path, NULL);
|
|
|
|
g_free (path);
|
2013-05-08 14:13:32 +00:00
|
|
|
} else {
|
2013-07-01 16:19:15 +00:00
|
|
|
next_header_uri = path;
|
2013-05-08 14:13:32 +00:00
|
|
|
}
|
|
|
|
|
2013-06-20 06:52:31 +00:00
|
|
|
fragment = gst_uri_downloader_fetch_uri_with_range (demux->downloader,
|
|
|
|
next_header_uri, range_start, range_end);
|
2012-10-17 16:40:02 +00:00
|
|
|
g_free (next_header_uri);
|
2013-07-02 19:04:45 +00:00
|
|
|
if (fragment) {
|
|
|
|
buffer = gst_fragment_get_buffer (fragment);
|
|
|
|
g_object_unref (fragment);
|
|
|
|
}
|
2013-07-01 16:19:15 +00:00
|
|
|
return buffer;
|
|
|
|
}
|
2012-10-17 16:40:02 +00:00
|
|
|
|
2013-07-01 16:19:15 +00:00
|
|
|
static GstBuffer *
|
|
|
|
gst_dash_demux_get_next_header (GstDashDemux * demux, guint stream_idx)
|
|
|
|
{
|
|
|
|
gchar *initializationURL;
|
|
|
|
GstBuffer *header_buffer, *index_buffer = NULL;
|
|
|
|
gint64 range_start, range_end;
|
|
|
|
|
|
|
|
if (!gst_mpd_client_get_next_header (demux->client, &initializationURL,
|
|
|
|
stream_idx, &range_start, &range_end))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
GST_INFO_OBJECT (demux, "Fetching header %s %" G_GINT64_FORMAT "-%"
|
|
|
|
G_GINT64_FORMAT, initializationURL, range_start, range_end);
|
|
|
|
header_buffer = gst_dash_demux_download_header_fragment (demux, stream_idx,
|
|
|
|
initializationURL, range_start, range_end);
|
|
|
|
|
|
|
|
/* check if we have an index */
|
2013-06-10 22:01:14 +00:00
|
|
|
if (header_buffer
|
|
|
|
&& gst_mpd_client_get_next_header_index (demux->client,
|
|
|
|
&initializationURL, stream_idx, &range_start, &range_end)) {
|
|
|
|
GST_INFO_OBJECT (demux,
|
|
|
|
"Fetching index %s %" G_GINT64_FORMAT "-%" G_GINT64_FORMAT,
|
|
|
|
initializationURL, range_start, range_end);
|
|
|
|
index_buffer =
|
|
|
|
gst_dash_demux_download_header_fragment (demux, stream_idx,
|
2013-07-01 16:19:15 +00:00
|
|
|
initializationURL, range_start, range_end);
|
|
|
|
}
|
|
|
|
|
2013-06-10 22:01:14 +00:00
|
|
|
if (header_buffer == NULL) {
|
|
|
|
GST_WARNING_OBJECT (demux, "Unable to fetch header");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (index_buffer) {
|
2013-07-01 16:19:15 +00:00
|
|
|
header_buffer = gst_buffer_append (header_buffer, index_buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
return header_buffer;
|
2013-05-08 14:13:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstCaps *
|
|
|
|
gst_dash_demux_get_video_input_caps (GstDashDemux * demux,
|
|
|
|
GstActiveStream * stream)
|
|
|
|
{
|
2012-12-17 14:39:10 +00:00
|
|
|
guint width = 0, height = 0;
|
2012-10-19 18:12:09 +00:00
|
|
|
const gchar *mimeType = NULL;
|
2013-05-08 14:13:32 +00:00
|
|
|
GstCaps *caps = NULL;
|
2012-10-19 18:12:09 +00:00
|
|
|
|
2013-05-08 14:13:32 +00:00
|
|
|
if (stream == NULL)
|
|
|
|
return NULL;
|
2012-10-08 15:43:14 +00:00
|
|
|
|
2012-12-17 14:39:10 +00:00
|
|
|
/* if bitstreamSwitching is true we dont need to swich pads on resolution change */
|
|
|
|
if (!gst_mpd_client_get_bitstream_switching_flag (stream)) {
|
|
|
|
width = gst_mpd_client_get_video_stream_width (stream);
|
|
|
|
height = gst_mpd_client_get_video_stream_height (stream);
|
|
|
|
}
|
2012-10-19 18:12:09 +00:00
|
|
|
mimeType = gst_mpd_client_get_stream_mimeType (stream);
|
|
|
|
if (mimeType == NULL)
|
2012-10-08 15:43:14 +00:00
|
|
|
return NULL;
|
|
|
|
|
2013-05-16 02:24:29 +00:00
|
|
|
caps = gst_caps_from_string (mimeType);
|
2012-10-19 18:12:09 +00:00
|
|
|
if (width > 0 && height > 0) {
|
|
|
|
gst_caps_set_simple (caps, "width", G_TYPE_INT, width, "height",
|
|
|
|
G_TYPE_INT, height, NULL);
|
|
|
|
}
|
|
|
|
|
2013-05-08 14:13:32 +00:00
|
|
|
return caps;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstCaps *
|
|
|
|
gst_dash_demux_get_audio_input_caps (GstDashDemux * demux,
|
|
|
|
GstActiveStream * stream)
|
|
|
|
{
|
2012-12-17 14:39:10 +00:00
|
|
|
guint rate = 0, channels = 0;
|
2013-05-08 14:13:32 +00:00
|
|
|
const gchar *mimeType;
|
|
|
|
GstCaps *caps = NULL;
|
2012-10-19 18:12:09 +00:00
|
|
|
|
2012-10-08 15:43:14 +00:00
|
|
|
if (stream == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2012-12-17 14:39:10 +00:00
|
|
|
/* if bitstreamSwitching is true we dont need to swich pads on rate/channels change */
|
|
|
|
if (!gst_mpd_client_get_bitstream_switching_flag (stream)) {
|
|
|
|
channels = gst_mpd_client_get_audio_stream_num_channels (stream);
|
|
|
|
rate = gst_mpd_client_get_audio_stream_rate (stream);
|
|
|
|
}
|
2012-10-19 18:12:09 +00:00
|
|
|
mimeType = gst_mpd_client_get_stream_mimeType (stream);
|
|
|
|
if (mimeType == NULL)
|
2012-10-08 15:43:14 +00:00
|
|
|
return NULL;
|
|
|
|
|
2013-05-16 02:24:29 +00:00
|
|
|
caps = gst_caps_from_string (mimeType);
|
2012-10-19 18:12:09 +00:00
|
|
|
if (rate > 0) {
|
|
|
|
gst_caps_set_simple (caps, "rate", G_TYPE_INT, rate, NULL);
|
|
|
|
}
|
|
|
|
if (channels > 0) {
|
|
|
|
gst_caps_set_simple (caps, "channels", G_TYPE_INT, channels, NULL);
|
|
|
|
}
|
|
|
|
|
2013-05-08 14:13:32 +00:00
|
|
|
return caps;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstCaps *
|
|
|
|
gst_dash_demux_get_application_input_caps (GstDashDemux * demux,
|
|
|
|
GstActiveStream * stream)
|
|
|
|
{
|
|
|
|
const gchar *mimeType;
|
|
|
|
GstCaps *caps = NULL;
|
2012-10-19 18:12:09 +00:00
|
|
|
|
2012-10-08 15:43:14 +00:00
|
|
|
if (stream == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2012-10-19 18:12:09 +00:00
|
|
|
mimeType = gst_mpd_client_get_stream_mimeType (stream);
|
|
|
|
if (mimeType == NULL)
|
2012-10-08 15:43:14 +00:00
|
|
|
return NULL;
|
|
|
|
|
2013-05-16 02:24:29 +00:00
|
|
|
caps = gst_caps_from_string (mimeType);
|
2012-10-19 18:12:09 +00:00
|
|
|
|
2013-05-08 14:13:32 +00:00
|
|
|
return caps;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstCaps *
|
|
|
|
gst_dash_demux_get_input_caps (GstDashDemux * demux, GstActiveStream * stream)
|
|
|
|
{
|
|
|
|
switch (stream->mimeType) {
|
|
|
|
case GST_STREAM_VIDEO:
|
|
|
|
return gst_dash_demux_get_video_input_caps (demux, stream);
|
|
|
|
case GST_STREAM_AUDIO:
|
|
|
|
return gst_dash_demux_get_audio_input_caps (demux, stream);
|
|
|
|
case GST_STREAM_APPLICATION:
|
|
|
|
return gst_dash_demux_get_application_input_caps (demux, stream);
|
|
|
|
default:
|
|
|
|
return GST_CAPS_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-01 05:10:15 +00:00
|
|
|
/* gst_dash_demux_get_next_fragment:
|
2012-10-15 13:08:53 +00:00
|
|
|
*
|
2013-02-01 05:10:15 +00:00
|
|
|
* Get the next fragments for the stream with the earlier timestamp.
|
2013-07-09 02:24:28 +00:00
|
|
|
* It returns the selected timestamp so the caller can deal with
|
|
|
|
* sync issues in case the stream is live.
|
2012-10-15 13:08:53 +00:00
|
|
|
*
|
|
|
|
* This function uses the generic URI downloader API.
|
|
|
|
*
|
|
|
|
* Returns FALSE if an error occured while downloading fragments
|
|
|
|
*
|
|
|
|
*/
|
2013-05-08 14:13:32 +00:00
|
|
|
static gboolean
|
2013-07-09 02:24:28 +00:00
|
|
|
gst_dash_demux_get_next_fragment (GstDashDemux * demux,
|
|
|
|
GstActiveStream ** stream, GstClockTime * selected_ts)
|
2013-05-08 14:13:32 +00:00
|
|
|
{
|
2013-01-28 13:46:27 +00:00
|
|
|
GstActiveStream *active_stream;
|
2013-07-01 16:19:15 +00:00
|
|
|
GstFragment *download;
|
|
|
|
GstBuffer *header_buffer;
|
2013-05-08 14:13:32 +00:00
|
|
|
GTimeVal now;
|
|
|
|
GTimeVal start;
|
|
|
|
GstClockTime diff;
|
|
|
|
guint64 size_buffer = 0;
|
2013-01-28 13:46:27 +00:00
|
|
|
GSList *iter;
|
2013-01-29 16:08:27 +00:00
|
|
|
gboolean end_of_period = TRUE;
|
2013-02-01 05:10:15 +00:00
|
|
|
GstDashDemuxStream *selected_stream = NULL;
|
|
|
|
GstClockTime best_time = GST_CLOCK_TIME_NONE;
|
2013-02-13 04:13:23 +00:00
|
|
|
GSList *streams;
|
2013-05-08 14:13:32 +00:00
|
|
|
|
2013-04-18 10:41:09 +00:00
|
|
|
g_mutex_lock (&demux->streams_lock);
|
2013-02-13 04:13:23 +00:00
|
|
|
/* TODO add check */
|
|
|
|
streams = g_slist_last (demux->next_periods)->data;
|
2013-04-18 10:41:09 +00:00
|
|
|
g_mutex_unlock (&demux->streams_lock);
|
2013-02-13 04:13:23 +00:00
|
|
|
|
|
|
|
for (iter = streams; iter; iter = g_slist_next (iter)) {
|
2013-01-28 13:46:27 +00:00
|
|
|
GstDashDemuxStream *stream = iter->data;
|
2013-02-01 05:10:15 +00:00
|
|
|
GstClockTime ts;
|
2013-01-25 12:36:35 +00:00
|
|
|
|
2013-01-29 18:58:50 +00:00
|
|
|
if (stream->download_end_of_period)
|
|
|
|
continue;
|
|
|
|
|
2013-02-01 05:10:15 +00:00
|
|
|
if (gst_mpd_client_get_next_fragment_timestamp (demux->client,
|
|
|
|
stream->index, &ts)) {
|
|
|
|
if (ts < best_time || !GST_CLOCK_TIME_IS_VALID (best_time)) {
|
|
|
|
selected_stream = stream;
|
|
|
|
best_time = ts;
|
|
|
|
}
|
|
|
|
} else {
|
2013-01-29 18:58:50 +00:00
|
|
|
GstEvent *event = NULL;
|
|
|
|
|
2013-01-29 16:08:27 +00:00
|
|
|
GST_INFO_OBJECT (demux,
|
|
|
|
"This Period doesn't contain more fragments for stream %u",
|
2013-02-01 05:10:15 +00:00
|
|
|
stream->index);
|
2013-02-22 19:40:36 +00:00
|
|
|
|
|
|
|
/* check if this is live and we should wait for more data */
|
|
|
|
if (gst_mpd_client_is_live (demux->client)
|
|
|
|
&& demux->client->mpd_node->minimumUpdatePeriod != -1) {
|
|
|
|
end_of_period = FALSE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-01-29 18:58:50 +00:00
|
|
|
if (gst_mpd_client_has_next_period (demux->client)) {
|
|
|
|
event = gst_event_new_dash_eop ();
|
|
|
|
} else {
|
2013-02-13 04:13:23 +00:00
|
|
|
GST_DEBUG_OBJECT (demux,
|
|
|
|
"No more fragments or periods for this stream, setting EOS");
|
2013-01-29 18:58:50 +00:00
|
|
|
event = gst_event_new_eos ();
|
|
|
|
}
|
|
|
|
stream->download_end_of_period = TRUE;
|
|
|
|
gst_dash_demux_stream_push_event (stream, event);
|
2013-05-08 14:13:32 +00:00
|
|
|
}
|
2013-02-01 05:10:15 +00:00
|
|
|
}
|
2013-07-09 02:24:28 +00:00
|
|
|
if (selected_ts)
|
|
|
|
*selected_ts = best_time;
|
|
|
|
if (stream && selected_stream)
|
|
|
|
*stream =
|
|
|
|
gst_mpdparser_get_active_stream_by_index (demux->client,
|
|
|
|
selected_stream->index);
|
2013-05-08 14:13:32 +00:00
|
|
|
|
2013-02-01 05:10:15 +00:00
|
|
|
/* Get the fragment corresponding to each stream index */
|
|
|
|
if (selected_stream) {
|
|
|
|
guint stream_idx = selected_stream->index;
|
|
|
|
GstBuffer *buffer;
|
2013-07-01 20:50:37 +00:00
|
|
|
GstMediaFragmentInfo fragment;
|
2013-05-08 14:13:32 +00:00
|
|
|
|
2013-07-03 15:30:28 +00:00
|
|
|
if (gst_mpd_client_get_next_fragment (demux->client, stream_idx, &fragment)) {
|
2013-01-29 16:08:27 +00:00
|
|
|
|
2013-02-05 17:22:51 +00:00
|
|
|
g_get_current_time (&start);
|
2013-02-01 05:10:15 +00:00
|
|
|
GST_INFO_OBJECT (demux, "Next fragment for stream #%i", stream_idx);
|
|
|
|
GST_INFO_OBJECT (demux,
|
|
|
|
"Fetching next fragment %s ts:%" GST_TIME_FORMAT " dur:%"
|
2013-06-20 06:52:31 +00:00
|
|
|
GST_TIME_FORMAT " Range:%" G_GINT64_FORMAT "-%" G_GINT64_FORMAT,
|
2013-07-01 20:50:37 +00:00
|
|
|
fragment.uri, GST_TIME_ARGS (fragment.timestamp),
|
|
|
|
GST_TIME_ARGS (fragment.duration),
|
|
|
|
fragment.range_start, fragment.range_end);
|
2013-05-08 14:13:32 +00:00
|
|
|
|
2013-02-01 05:10:15 +00:00
|
|
|
/* got a fragment to fetch, no end of period */
|
|
|
|
end_of_period = FALSE;
|
2013-05-08 14:13:32 +00:00
|
|
|
|
2013-06-20 06:52:31 +00:00
|
|
|
download = gst_uri_downloader_fetch_uri_with_range (demux->downloader,
|
2013-07-01 20:50:37 +00:00
|
|
|
fragment.uri, fragment.range_start, fragment.range_end);
|
2013-05-08 14:13:32 +00:00
|
|
|
|
2013-07-01 20:50:37 +00:00
|
|
|
if (download == NULL) {
|
|
|
|
gst_media_fragment_info_clear (&fragment);
|
2013-02-01 05:10:15 +00:00
|
|
|
return FALSE;
|
2013-07-01 20:50:37 +00:00
|
|
|
}
|
2012-12-17 14:04:45 +00:00
|
|
|
|
2013-02-01 05:10:15 +00:00
|
|
|
active_stream =
|
|
|
|
gst_mpdparser_get_active_stream_by_index (demux->client, stream_idx);
|
2013-02-18 17:02:48 +00:00
|
|
|
if (active_stream == NULL) {
|
2013-07-01 20:50:37 +00:00
|
|
|
gst_media_fragment_info_clear (&fragment);
|
2013-02-18 17:02:48 +00:00
|
|
|
g_object_unref (download);
|
2013-02-01 05:10:15 +00:00
|
|
|
return FALSE;
|
2013-02-18 17:02:48 +00:00
|
|
|
}
|
2013-02-01 05:10:15 +00:00
|
|
|
|
2013-02-05 00:58:32 +00:00
|
|
|
buffer = gst_fragment_get_buffer (download);
|
2013-02-18 17:02:48 +00:00
|
|
|
g_object_unref (download);
|
2013-02-05 00:58:32 +00:00
|
|
|
|
2013-07-01 20:50:37 +00:00
|
|
|
/* it is possible to have an index per fragment, so check and download */
|
|
|
|
if (fragment.index_uri || fragment.index_range_start
|
|
|
|
|| fragment.index_range_end != -1) {
|
|
|
|
const gchar *uri = fragment.index_uri;
|
|
|
|
GstBuffer *index_buffer;
|
|
|
|
|
|
|
|
if (!uri) /* fallback to default media uri */
|
|
|
|
uri = fragment.uri;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (demux,
|
|
|
|
"Fragment index download: %s %" G_GINT64_FORMAT "-%"
|
|
|
|
G_GINT64_FORMAT, uri, fragment.index_range_start,
|
|
|
|
fragment.index_range_end);
|
|
|
|
download =
|
|
|
|
gst_uri_downloader_fetch_uri_with_range (demux->downloader, uri,
|
|
|
|
fragment.index_range_start, fragment.index_range_end);
|
|
|
|
if (download) {
|
|
|
|
index_buffer = gst_fragment_get_buffer (download);
|
|
|
|
if (index_buffer)
|
|
|
|
buffer = gst_buffer_append (index_buffer, buffer);
|
|
|
|
g_object_unref (download);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-01 05:10:15 +00:00
|
|
|
if (selected_stream->need_header) {
|
|
|
|
/* We need to fetch a new header */
|
2013-07-01 16:19:15 +00:00
|
|
|
if ((header_buffer =
|
2013-06-10 22:01:14 +00:00
|
|
|
gst_dash_demux_get_next_header (demux, stream_idx)) != NULL) {
|
2013-04-18 10:41:09 +00:00
|
|
|
buffer = gst_buffer_append (header_buffer, buffer);
|
2013-02-01 05:10:15 +00:00
|
|
|
}
|
|
|
|
selected_stream->need_header = FALSE;
|
2013-05-08 14:13:32 +00:00
|
|
|
}
|
2013-02-05 17:22:51 +00:00
|
|
|
g_get_current_time (&now);
|
2013-05-08 14:13:32 +00:00
|
|
|
|
2013-04-18 10:41:09 +00:00
|
|
|
buffer = gst_buffer_make_writable (buffer);
|
2013-01-28 21:52:04 +00:00
|
|
|
|
2013-07-01 20:50:37 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (buffer) = fragment.timestamp;
|
|
|
|
GST_BUFFER_DURATION (buffer) = fragment.duration;
|
2013-02-01 05:10:15 +00:00
|
|
|
GST_BUFFER_OFFSET (buffer) =
|
|
|
|
gst_mpd_client_get_segment_index (active_stream) - 1;
|
2013-01-28 21:52:04 +00:00
|
|
|
|
2013-07-01 20:50:37 +00:00
|
|
|
gst_media_fragment_info_clear (&fragment);
|
|
|
|
|
2013-02-01 05:10:15 +00:00
|
|
|
gst_dash_demux_stream_push_data (selected_stream, buffer);
|
|
|
|
selected_stream->has_data_queued = TRUE;
|
2013-04-18 10:41:09 +00:00
|
|
|
size_buffer += gst_buffer_get_size (buffer);
|
2013-02-01 05:10:15 +00:00
|
|
|
} else {
|
|
|
|
GST_WARNING_OBJECT (demux, "Failed to download fragment for stream %p %d",
|
|
|
|
selected_stream, selected_stream->index);
|
|
|
|
}
|
2013-05-08 14:13:32 +00:00
|
|
|
}
|
2013-01-28 15:28:29 +00:00
|
|
|
|
2013-01-29 16:08:27 +00:00
|
|
|
demux->end_of_period = end_of_period;
|
|
|
|
if (end_of_period)
|
|
|
|
return FALSE;
|
|
|
|
|
2012-10-15 13:08:53 +00:00
|
|
|
/* Wake the download task up */
|
|
|
|
GST_TASK_SIGNAL (demux->download_task);
|
2013-02-05 17:22:51 +00:00
|
|
|
if (selected_stream) {
|
2013-07-29 07:35:08 +00:00
|
|
|
#ifndef GST_DISABLE_GST_DEBUG
|
2013-02-05 20:38:06 +00:00
|
|
|
guint64 brate;
|
2013-07-29 07:35:08 +00:00
|
|
|
#endif
|
2013-02-05 20:38:06 +00:00
|
|
|
|
2013-02-05 17:22:51 +00:00
|
|
|
diff = (GST_TIMEVAL_TO_TIME (now) - GST_TIMEVAL_TO_TIME (start));
|
2013-02-05 20:38:06 +00:00
|
|
|
gst_download_rate_add_rate (&selected_stream->dnl_rate, size_buffer, diff);
|
|
|
|
|
2013-07-29 07:35:08 +00:00
|
|
|
#ifndef GST_DISABLE_GST_DEBUG
|
2013-02-05 20:38:06 +00:00
|
|
|
brate = (size_buffer * 8) / ((double) diff / GST_SECOND);
|
2013-07-29 07:35:08 +00:00
|
|
|
#endif
|
2013-02-05 17:22:51 +00:00
|
|
|
GST_INFO_OBJECT (demux,
|
|
|
|
"Stream: %d Download rate = %" PRIu64 " Kbits/s (%" PRIu64
|
|
|
|
" Ko in %.2f s)", selected_stream->index,
|
2013-02-05 20:38:06 +00:00
|
|
|
brate / 1000, size_buffer / 1024, ((double) diff / GST_SECOND));
|
2013-02-05 17:22:51 +00:00
|
|
|
}
|
2013-05-08 14:13:32 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2013-07-09 02:24:28 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gst_dash_demux_download_wait (GstDashDemux * demux, GstClockTime time_diff)
|
|
|
|
{
|
|
|
|
gint64 end_time = g_get_monotonic_time () + time_diff / GST_USECOND;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (demux, "Download waiting for %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (time_diff));
|
|
|
|
g_cond_wait_until (&demux->download_cond, &demux->download_mutex, end_time);
|
|
|
|
GST_DEBUG_OBJECT (demux, "Download finished waiting");
|
|
|
|
}
|