2013-05-08 14:13:32 +00:00
|
|
|
/*
|
|
|
|
* DASH demux plugin for GStreamer
|
|
|
|
*
|
|
|
|
* gstdashdemux.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Orange
|
2014-08-26 19:45:46 +00:00
|
|
|
*
|
2013-05-08 14:13:32 +00:00
|
|
|
* 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>
|
|
|
|
* |[
|
2015-05-25 01:30:55 +00:00
|
|
|
* gst-launch-1.0 playbin 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"
|
2013-05-08 14:13:32 +00:00
|
|
|
* ]|
|
|
|
|
*/
|
|
|
|
|
2012-10-15 11:09:49 +00:00
|
|
|
/* Implementation notes:
|
2014-08-26 19:45:46 +00:00
|
|
|
*
|
2012-10-15 11:09:49 +00:00
|
|
|
* The following section describes how dashdemux works internally.
|
2014-08-26 19:45:46 +00:00
|
|
|
*
|
2012-10-15 12:14:53 +00:00
|
|
|
* Introduction:
|
2014-08-26 19:45:46 +00:00
|
|
|
*
|
2012-10-15 12:14:53 +00:00
|
|
|
* 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.
|
2014-08-26 19:45:46 +00:00
|
|
|
*
|
2012-10-15 12:14:53 +00:00
|
|
|
* 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
|
2014-08-26 19:45:46 +00:00
|
|
|
* demux elements that will handle them (this behavior is sometimes
|
2012-10-15 12:14:53 +00:00
|
|
|
* referred as the "demux after a demux" scenario).
|
2014-08-26 19:45:46 +00:00
|
|
|
*
|
2012-10-15 12:14:53 +00:00
|
|
|
* For a given section of content, several representations corresponding
|
|
|
|
* to different bitrates may be available: dashdemux will select the most
|
2014-08-26 19:45:46 +00:00
|
|
|
* appropriate representation based on local conditions (typically the
|
2012-10-15 12:14:53 +00:00
|
|
|
* available bandwidth and the amount of buffering available, capped by
|
2014-08-26 19:45:46 +00:00
|
|
|
* a maximum allowed bitrate).
|
|
|
|
*
|
2012-10-15 12:14:53 +00:00
|
|
|
* The representation selection algorithm can be configured using
|
|
|
|
* specific properties: max bitrate, min/max buffering, bandwidth ratio.
|
2014-08-26 19:45:46 +00:00
|
|
|
*
|
|
|
|
*
|
2012-10-15 12:14:53 +00:00
|
|
|
* General Design:
|
2014-08-26 19:45:46 +00:00
|
|
|
*
|
|
|
|
* dashdemux has a single sink pad that accepts the data corresponding
|
2012-10-15 12:14:53 +00:00
|
|
|
* to the manifest, typically fetched from an HTTP or file source.
|
2014-08-26 19:45:46 +00:00
|
|
|
*
|
2012-10-15 12:14:53 +00:00
|
|
|
* 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).
|
2014-08-26 19:45:46 +00:00
|
|
|
*
|
2012-10-15 12:14:53 +00:00
|
|
|
* During playback, new representations will typically be exposed as a
|
|
|
|
* new set of pads (see 'Switching between representations' below).
|
2014-08-26 19:45:46 +00:00
|
|
|
*
|
2012-10-15 12:14:53 +00:00
|
|
|
* 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.
|
2014-08-26 19:45:46 +00:00
|
|
|
*
|
2012-10-15 11:09:49 +00:00
|
|
|
* Switching between representations:
|
2014-08-26 19:45:46 +00:00
|
|
|
*
|
|
|
|
* Decodebin supports scenarios allowing to seamlessly switch from one
|
2012-10-15 11:09:49 +00:00
|
|
|
* stream to another inside the same "decoding chain".
|
2014-08-26 19:45:46 +00:00
|
|
|
*
|
2012-10-15 11:09:49 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2014-08-26 19:45:46 +00:00
|
|
|
* A chain can signal decodebin that it is complete by sending a
|
2012-10-15 11:09:49 +00:00
|
|
|
* 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:
|
2014-08-26 19:45:46 +00:00
|
|
|
*
|
2012-10-15 11:09:49 +00:00
|
|
|
* 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"
|
2014-08-26 19:45:46 +00:00
|
|
|
* | |_ 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"
|
2014-08-26 19:45:46 +00:00
|
|
|
* |_ chain "AAC"
|
2012-10-15 11:09:49 +00:00
|
|
|
*
|
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.
|
2014-08-26 19:45:46 +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
|
2012-10-15 11:09:49 +00:00
|
|
|
* adapt quickly to bandwidth changes, we will not be able to rely
|
|
|
|
* on downstream buffering, and will instead manage an internal queue.
|
2014-08-26 19:45:46 +00:00
|
|
|
*
|
2012-10-15 11:09:49 +00:00
|
|
|
*/
|
|
|
|
|
2013-05-08 14:13:32 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <string.h>
|
2015-08-14 08:44:24 +00:00
|
|
|
#include <stdio.h>
|
2015-07-07 14:38:08 +00:00
|
|
|
#include <stdlib.h>
|
2012-10-25 15:15:09 +00:00
|
|
|
#include <inttypes.h>
|
2015-07-15 10:56:13 +00:00
|
|
|
#include <gio/gio.h>
|
2013-05-08 14:13:32 +00:00
|
|
|
#include <gst/base/gsttypefindhelper.h>
|
2014-08-26 19:45:46 +00:00
|
|
|
#include <gst/tag/tag.h>
|
2015-07-15 10:56:13 +00:00
|
|
|
#include <gst/net/gstnet.h>
|
2013-12-20 13:05:22 +00:00
|
|
|
#include "gst/gst-i18n-plugin.h"
|
2013-05-08 14:13:32 +00:00
|
|
|
#include "gstdashdemux.h"
|
2013-06-25 21:34:13 +00:00
|
|
|
#include "gstdash_debug.h"
|
2013-05-08 14:13:32 +00:00
|
|
|
|
2015-01-26 20:51:22 +00:00
|
|
|
static GstStaticPadTemplate gst_dash_demux_videosrc_template =
|
|
|
|
GST_STATIC_PAD_TEMPLATE ("video_%02u",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_SOMETIMES,
|
|
|
|
GST_STATIC_CAPS_ANY);
|
|
|
|
|
|
|
|
static GstStaticPadTemplate gst_dash_demux_audiosrc_template =
|
|
|
|
GST_STATIC_PAD_TEMPLATE ("audio_%02u",
|
2013-05-08 14:13:32 +00:00
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_SOMETIMES,
|
|
|
|
GST_STATIC_CAPS_ANY);
|
|
|
|
|
2015-08-18 13:16:11 +00:00
|
|
|
static GstStaticPadTemplate gst_dash_demux_subtitlesrc_template =
|
|
|
|
GST_STATIC_PAD_TEMPLATE ("subtitle_%02u",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_SOMETIMES,
|
|
|
|
GST_STATIC_CAPS_ANY);
|
|
|
|
|
2013-05-08 14:13:32 +00:00
|
|
|
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,
|
2015-07-07 14:38:08 +00:00
|
|
|
PROP_PRESENTATION_DELAY,
|
2013-05-08 14:13:32 +00:00
|
|
|
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 */
|
2015-07-07 14:38:08 +00:00
|
|
|
#define DEFAULT_PRESENTATION_DELAY NULL /* zero */
|
2013-05-08 14:13:32 +00:00
|
|
|
|
2015-07-15 10:56:13 +00:00
|
|
|
/* Clock drift compensation for live streams */
|
|
|
|
#define SLOW_CLOCK_UPDATE_INTERVAL (1000000 * 30 * 60) /* 30 minutes */
|
|
|
|
#define FAST_CLOCK_UPDATE_INTERVAL (1000000 * 30) /* 30 seconds */
|
2015-08-14 08:44:24 +00:00
|
|
|
#define SUPPORTED_CLOCK_FORMATS (GST_MPD_UTCTIMING_TYPE_NTP | GST_MPD_UTCTIMING_TYPE_HTTP_HEAD | GST_MPD_UTCTIMING_TYPE_HTTP_XSDATE | GST_MPD_UTCTIMING_TYPE_HTTP_ISO | GST_MPD_UTCTIMING_TYPE_HTTP_NTP)
|
2015-08-13 17:21:29 +00:00
|
|
|
#define NTP_TO_UNIX_EPOCH G_GUINT64_CONSTANT(2208988800) /* difference (in seconds) between NTP epoch and Unix epoch */
|
2015-07-15 10:56:13 +00:00
|
|
|
|
|
|
|
struct _GstDashDemuxClockDrift
|
|
|
|
{
|
|
|
|
GMutex clock_lock; /* used to protect access to struct */
|
|
|
|
guint selected_url;
|
|
|
|
gint64 next_update;
|
|
|
|
/* @clock_compensation: amount (in usecs) to add to client's idea of
|
|
|
|
now to map it to the server's idea of now */
|
|
|
|
GTimeSpan clock_compensation;
|
|
|
|
GstClock *ntp_clock;
|
|
|
|
};
|
|
|
|
|
2016-05-30 08:15:03 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
guint64 start_offset, end_offset;
|
|
|
|
/* TODO: Timestamp and duration */
|
|
|
|
} GstDashStreamSyncSample;
|
|
|
|
|
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);
|
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
/* GstAdaptiveDemux */
|
|
|
|
static GstClockTime gst_dash_demux_get_duration (GstAdaptiveDemux * ademux);
|
|
|
|
static gboolean gst_dash_demux_is_live (GstAdaptiveDemux * ademux);
|
|
|
|
static void gst_dash_demux_reset (GstAdaptiveDemux * ademux);
|
|
|
|
static gboolean gst_dash_demux_process_manifest (GstAdaptiveDemux * ademux,
|
|
|
|
GstBuffer * buf);
|
|
|
|
static gboolean gst_dash_demux_seek (GstAdaptiveDemux * demux, GstEvent * seek);
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_dash_demux_stream_update_fragment_info (GstAdaptiveDemuxStream * stream);
|
|
|
|
static GstFlowReturn gst_dash_demux_stream_seek (GstAdaptiveDemuxStream *
|
2016-01-27 16:31:10 +00:00
|
|
|
stream, gboolean forward, GstSeekFlags flags, GstClockTime ts,
|
|
|
|
GstClockTime * final_ts);
|
|
|
|
static gboolean gst_dash_demux_stream_has_next_fragment (GstAdaptiveDemuxStream
|
|
|
|
* stream);
|
2014-08-26 19:45:46 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
gst_dash_demux_stream_advance_fragment (GstAdaptiveDemuxStream * stream);
|
2015-01-15 20:44:45 +00:00
|
|
|
static gboolean
|
2015-01-12 20:40:47 +00:00
|
|
|
gst_dash_demux_stream_advance_subfragment (GstAdaptiveDemuxStream * stream);
|
2014-08-26 19:45:46 +00:00
|
|
|
static gboolean gst_dash_demux_stream_select_bitrate (GstAdaptiveDemuxStream *
|
|
|
|
stream, guint64 bitrate);
|
2016-01-27 16:31:10 +00:00
|
|
|
static gint64 gst_dash_demux_get_manifest_update_interval (GstAdaptiveDemux *
|
|
|
|
demux);
|
|
|
|
static GstFlowReturn gst_dash_demux_update_manifest_data (GstAdaptiveDemux *
|
|
|
|
demux, GstBuffer * buf);
|
2014-08-26 19:45:46 +00:00
|
|
|
static gint64
|
|
|
|
gst_dash_demux_stream_get_fragment_waiting_time (GstAdaptiveDemuxStream *
|
|
|
|
stream);
|
|
|
|
static void gst_dash_demux_advance_period (GstAdaptiveDemux * demux);
|
|
|
|
static gboolean gst_dash_demux_has_next_period (GstAdaptiveDemux * demux);
|
2015-01-15 20:44:45 +00:00
|
|
|
static GstFlowReturn gst_dash_demux_data_received (GstAdaptiveDemux * demux,
|
2016-03-28 10:45:36 +00:00
|
|
|
GstAdaptiveDemuxStream * stream, GstBuffer * buffer);
|
2016-03-31 10:39:59 +00:00
|
|
|
static gboolean
|
|
|
|
gst_dash_demux_stream_fragment_start (GstAdaptiveDemux * demux,
|
|
|
|
GstAdaptiveDemuxStream * stream);
|
2015-01-15 20:44:45 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
gst_dash_demux_stream_fragment_finished (GstAdaptiveDemux * demux,
|
|
|
|
GstAdaptiveDemuxStream * stream);
|
2016-07-12 17:09:52 +00:00
|
|
|
static gboolean gst_dash_demux_need_another_chunk (GstAdaptiveDemuxStream *
|
|
|
|
stream);
|
2014-05-02 21:30:05 +00:00
|
|
|
|
2013-05-08 14:13:32 +00:00
|
|
|
/* GstDashDemux */
|
2012-12-20 08:04:28 +00:00
|
|
|
static gboolean gst_dash_demux_setup_all_streams (GstDashDemux * demux);
|
2015-01-12 14:57:02 +00:00
|
|
|
static void gst_dash_demux_stream_free (GstAdaptiveDemuxStream * stream);
|
2014-08-26 19:45:46 +00:00
|
|
|
|
2013-07-29 07:35:08 +00:00
|
|
|
static GstCaps *gst_dash_demux_get_input_caps (GstDashDemux * demux,
|
|
|
|
GstActiveStream * stream);
|
2015-01-26 20:51:22 +00:00
|
|
|
static GstPad *gst_dash_demux_create_pad (GstDashDemux * demux,
|
|
|
|
GstActiveStream * stream);
|
2016-02-16 14:44:10 +00:00
|
|
|
static GstDashDemuxClockDrift *gst_dash_demux_clock_drift_new (GstDashDemux *
|
|
|
|
demux);
|
2015-07-15 10:56:13 +00:00
|
|
|
static void gst_dash_demux_clock_drift_free (GstDashDemuxClockDrift *);
|
|
|
|
static gboolean gst_dash_demux_poll_clock_drift (GstDashDemux * demux);
|
|
|
|
static GTimeSpan gst_dash_demux_get_clock_compensation (GstDashDemux * demux);
|
|
|
|
static GDateTime *gst_dash_demux_get_server_now_utc (GstDashDemux * demux);
|
2013-05-08 14:13:32 +00:00
|
|
|
|
2015-01-12 20:40:47 +00:00
|
|
|
#define SIDX(s) (&(s)->sidx_parser.sidx)
|
|
|
|
#define SIDX_ENTRY(s,i) (&(SIDX(s)->entries[(i)]))
|
|
|
|
#define SIDX_CURRENT_ENTRY(s) SIDX_ENTRY(s, SIDX(s)->entry_index)
|
|
|
|
|
2015-02-06 13:22:14 +00:00
|
|
|
static void gst_dash_demux_send_content_protection_event (gpointer cp_data,
|
|
|
|
gpointer stream);
|
|
|
|
|
2013-04-18 10:41:09 +00:00
|
|
|
#define gst_dash_demux_parent_class parent_class
|
2014-08-26 19:45:46 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GstDashDemux, gst_dash_demux, GST_TYPE_ADAPTIVE_DEMUX,
|
2013-04-18 10:41:09 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_dash_demux_debug, "dashdemux", 0,
|
2015-05-21 17:40:37 +00:00
|
|
|
"dashdemux element")
|
2014-08-26 19:45:46 +00:00
|
|
|
);
|
2013-05-08 14:13:32 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gst_dash_demux_dispose (GObject * obj)
|
|
|
|
{
|
|
|
|
GstDashDemux *demux = GST_DASH_DEMUX (obj);
|
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
gst_dash_demux_reset (GST_ADAPTIVE_DEMUX_CAST (demux));
|
2013-02-05 00:58:32 +00:00
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
if (demux->client) {
|
|
|
|
gst_mpd_client_free (demux->client);
|
|
|
|
demux->client = NULL;
|
2013-05-08 14:13:32 +00:00
|
|
|
}
|
|
|
|
|
2013-12-04 14:30:22 +00:00
|
|
|
g_mutex_clear (&demux->client_lock);
|
2013-02-18 17:02:48 +00:00
|
|
|
|
2015-07-15 10:56:13 +00:00
|
|
|
gst_dash_demux_clock_drift_free (demux->clock_drift);
|
|
|
|
demux->clock_drift = NULL;
|
2015-07-07 14:38:08 +00:00
|
|
|
g_free (demux->default_presentation_delay);
|
2013-05-08 14:13:32 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (obj);
|
|
|
|
}
|
|
|
|
|
2015-02-12 21:06:17 +00:00
|
|
|
static gboolean
|
|
|
|
gst_dash_demux_get_live_seek_range (GstAdaptiveDemux * demux, gint64 * start,
|
|
|
|
gint64 * stop)
|
|
|
|
{
|
|
|
|
GstDashDemux *self = GST_DASH_DEMUX (demux);
|
2015-11-20 19:38:03 +00:00
|
|
|
GDateTime *now;
|
|
|
|
GDateTime *mstart;
|
2015-02-12 21:06:17 +00:00
|
|
|
GTimeSpan stream_now;
|
2016-02-24 15:54:54 +00:00
|
|
|
GstClockTime seg_duration;
|
2015-02-12 21:06:17 +00:00
|
|
|
|
2015-11-20 19:38:03 +00:00
|
|
|
if (self->client->mpd_node->availabilityStartTime == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
2016-02-24 15:54:54 +00:00
|
|
|
seg_duration = gst_mpd_client_get_maximum_segment_duration (self->client);
|
2015-11-20 19:38:03 +00:00
|
|
|
now = gst_dash_demux_get_server_now_utc (self);
|
|
|
|
mstart =
|
|
|
|
gst_date_time_to_g_date_time (self->client->
|
|
|
|
mpd_node->availabilityStartTime);
|
2015-02-12 21:06:17 +00:00
|
|
|
stream_now = g_date_time_difference (now, mstart);
|
|
|
|
g_date_time_unref (now);
|
|
|
|
g_date_time_unref (mstart);
|
|
|
|
|
2015-11-20 19:38:03 +00:00
|
|
|
if (stream_now <= 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
*stop = stream_now * GST_USECOND;
|
|
|
|
if (self->client->mpd_node->timeShiftBufferDepth == GST_MPD_DURATION_NONE) {
|
|
|
|
*start = 0;
|
|
|
|
} else {
|
|
|
|
*start =
|
|
|
|
*stop - (self->client->mpd_node->timeShiftBufferDepth * GST_MSECOND);
|
|
|
|
if (*start < 0)
|
|
|
|
*start = 0;
|
|
|
|
}
|
2016-02-24 15:54:54 +00:00
|
|
|
|
|
|
|
/* As defined in 5.3.9.5.3 of the DASH specification, a segment does
|
|
|
|
not become available until the sum of:
|
|
|
|
* the value of the MPD@availabilityStartTime,
|
|
|
|
* the PeriodStart time of the containing Period
|
|
|
|
* the MPD start time of the Media Segment, and
|
|
|
|
* the MPD duration of the Media Segment.
|
|
|
|
Therefore we need to subtract the media segment duration from the stop
|
|
|
|
time.
|
|
|
|
*/
|
|
|
|
*stop -= seg_duration;
|
2015-02-12 21:06:17 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-03-02 13:00:03 +00:00
|
|
|
static GstClockTime
|
|
|
|
gst_dash_demux_get_presentation_offset (GstAdaptiveDemux * demux,
|
|
|
|
GstAdaptiveDemuxStream * stream)
|
|
|
|
{
|
|
|
|
GstDashDemuxStream *dashstream = (GstDashDemuxStream *) stream;
|
|
|
|
GstDashDemux *dashdemux = GST_DASH_DEMUX_CAST (demux);
|
|
|
|
|
|
|
|
return gst_mpd_parser_get_stream_presentation_offset (dashdemux->client,
|
|
|
|
dashstream->index);
|
|
|
|
}
|
|
|
|
|
2015-09-02 15:33:51 +00:00
|
|
|
static GstClockTime
|
|
|
|
gst_dash_demux_get_period_start_time (GstAdaptiveDemux * demux)
|
|
|
|
{
|
|
|
|
GstDashDemux *dashdemux = GST_DASH_DEMUX_CAST (demux);
|
|
|
|
|
|
|
|
return gst_mpd_parser_get_period_start_time (dashdemux->client);
|
|
|
|
}
|
|
|
|
|
2013-05-08 14:13:32 +00:00
|
|
|
static void
|
|
|
|
gst_dash_demux_class_init (GstDashDemuxClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
2014-08-26 19:45:46 +00:00
|
|
|
GstAdaptiveDemuxClass *gstadaptivedemux_class;
|
2013-05-08 14:13:32 +00:00
|
|
|
|
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gstelement_class = (GstElementClass *) klass;
|
2014-08-26 19:45:46 +00:00
|
|
|
gstadaptivedemux_class = (GstAdaptiveDemuxClass *) klass;
|
2013-05-08 14:13:32 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2014-11-02 17:18:12 +00:00
|
|
|
#ifndef GST_REMOVE_DEPRECATED
|
2013-05-08 14:13:32 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_MAX_BUFFERING_TIME,
|
|
|
|
g_param_spec_uint ("max-buffering-time", "Maximum buffering time",
|
2014-05-06 11:52:27 +00:00
|
|
|
"Maximum number of seconds of buffer accumulated during playback"
|
|
|
|
"(deprecated)",
|
2013-05-08 14:13:32 +00:00
|
|
|
2, G_MAXUINT, DEFAULT_MAX_BUFFERING_TIME,
|
2014-11-02 17:18:12 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_DEPRECATED));
|
2013-05-08 14:13:32 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_BANDWIDTH_USAGE,
|
|
|
|
g_param_spec_float ("bandwidth-usage",
|
|
|
|
"Bandwidth usage [0..1]",
|
2015-02-17 13:50:59 +00:00
|
|
|
"Percentage of the available bandwidth to use when "
|
|
|
|
"selecting representations (deprecated)",
|
2013-05-08 14:13:32 +00:00
|
|
|
0, 1, DEFAULT_BANDWIDTH_USAGE,
|
2015-08-20 17:14:36 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_DEPRECATED));
|
2015-02-17 13:50:59 +00:00
|
|
|
#endif
|
2013-05-08 14:13:32 +00:00
|
|
|
|
|
|
|
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));
|
|
|
|
|
2015-07-07 14:38:08 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_PRESENTATION_DELAY,
|
|
|
|
g_param_spec_string ("presentation-delay", "Presentation delay",
|
|
|
|
"Default presentation delay (in seconds, milliseconds or fragments) (e.g. 12s, 2500ms, 3f)",
|
|
|
|
DEFAULT_PRESENTATION_DELAY,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2016-03-04 06:50:26 +00:00
|
|
|
gst_element_class_add_static_pad_template (gstelement_class,
|
|
|
|
&gst_dash_demux_audiosrc_template);
|
|
|
|
gst_element_class_add_static_pad_template (gstelement_class,
|
|
|
|
&gst_dash_demux_videosrc_template);
|
|
|
|
gst_element_class_add_static_pad_template (gstelement_class,
|
|
|
|
&gst_dash_demux_subtitlesrc_template);
|
|
|
|
|
|
|
|
gst_element_class_add_static_pad_template (gstelement_class, &sinktemplate);
|
2013-04-18 10:41:09 +00:00
|
|
|
|
|
|
|
gst_element_class_set_static_metadata (gstelement_class,
|
|
|
|
"DASH Demuxer",
|
2014-02-20 14:09:36 +00:00
|
|
|
"Codec/Demuxer/Adaptive",
|
2013-04-18 10:41:09 +00:00
|
|
|
"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>");
|
2014-05-02 21:30:05 +00:00
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
|
|
|
|
gstadaptivedemux_class->get_duration = gst_dash_demux_get_duration;
|
|
|
|
gstadaptivedemux_class->is_live = gst_dash_demux_is_live;
|
|
|
|
gstadaptivedemux_class->reset = gst_dash_demux_reset;
|
|
|
|
gstadaptivedemux_class->seek = gst_dash_demux_seek;
|
|
|
|
|
|
|
|
gstadaptivedemux_class->process_manifest = gst_dash_demux_process_manifest;
|
2015-04-23 15:22:11 +00:00
|
|
|
gstadaptivedemux_class->update_manifest_data =
|
|
|
|
gst_dash_demux_update_manifest_data;
|
2014-08-26 19:45:46 +00:00
|
|
|
gstadaptivedemux_class->get_manifest_update_interval =
|
|
|
|
gst_dash_demux_get_manifest_update_interval;
|
|
|
|
|
|
|
|
gstadaptivedemux_class->has_next_period = gst_dash_demux_has_next_period;
|
|
|
|
gstadaptivedemux_class->advance_period = gst_dash_demux_advance_period;
|
2015-05-12 16:41:19 +00:00
|
|
|
gstadaptivedemux_class->stream_has_next_fragment =
|
|
|
|
gst_dash_demux_stream_has_next_fragment;
|
2014-08-26 19:45:46 +00:00
|
|
|
gstadaptivedemux_class->stream_advance_fragment =
|
|
|
|
gst_dash_demux_stream_advance_fragment;
|
|
|
|
gstadaptivedemux_class->stream_get_fragment_waiting_time =
|
|
|
|
gst_dash_demux_stream_get_fragment_waiting_time;
|
|
|
|
gstadaptivedemux_class->stream_seek = gst_dash_demux_stream_seek;
|
|
|
|
gstadaptivedemux_class->stream_select_bitrate =
|
|
|
|
gst_dash_demux_stream_select_bitrate;
|
|
|
|
gstadaptivedemux_class->stream_update_fragment_info =
|
|
|
|
gst_dash_demux_stream_update_fragment_info;
|
2015-01-12 14:57:02 +00:00
|
|
|
gstadaptivedemux_class->stream_free = gst_dash_demux_stream_free;
|
2015-02-16 02:16:52 +00:00
|
|
|
gstadaptivedemux_class->get_live_seek_range =
|
|
|
|
gst_dash_demux_get_live_seek_range;
|
2015-03-02 13:00:03 +00:00
|
|
|
gstadaptivedemux_class->get_presentation_offset =
|
|
|
|
gst_dash_demux_get_presentation_offset;
|
2015-09-02 15:33:51 +00:00
|
|
|
gstadaptivedemux_class->get_period_start_time =
|
|
|
|
gst_dash_demux_get_period_start_time;
|
2015-08-21 15:13:43 +00:00
|
|
|
|
2016-03-31 10:39:59 +00:00
|
|
|
gstadaptivedemux_class->start_fragment = gst_dash_demux_stream_fragment_start;
|
2015-08-21 15:13:43 +00:00
|
|
|
gstadaptivedemux_class->finish_fragment =
|
|
|
|
gst_dash_demux_stream_fragment_finished;
|
|
|
|
gstadaptivedemux_class->data_received = gst_dash_demux_data_received;
|
2016-07-12 17:09:52 +00:00
|
|
|
gstadaptivedemux_class->need_another_chunk =
|
|
|
|
gst_dash_demux_need_another_chunk;
|
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
|
|
|
{
|
|
|
|
/* Properties */
|
|
|
|
demux->max_buffering_time = DEFAULT_MAX_BUFFERING_TIME * GST_SECOND;
|
|
|
|
demux->max_bitrate = DEFAULT_MAX_BITRATE;
|
2015-07-07 14:38:08 +00:00
|
|
|
demux->default_presentation_delay = DEFAULT_PRESENTATION_DELAY;
|
2013-05-08 14:13:32 +00:00
|
|
|
|
2013-12-04 14:30:22 +00:00
|
|
|
g_mutex_init (&demux->client_lock);
|
2014-08-26 19:45:46 +00:00
|
|
|
|
|
|
|
gst_adaptive_demux_set_stream_struct_size (GST_ADAPTIVE_DEMUX_CAST (demux),
|
|
|
|
sizeof (GstDashDemuxStream));
|
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)
|
|
|
|
{
|
2015-02-17 13:50:59 +00:00
|
|
|
GstAdaptiveDemux *adaptivedemux = GST_ADAPTIVE_DEMUX_CAST (object);
|
2013-05-08 14:13:32 +00:00
|
|
|
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:
|
2015-02-17 13:50:59 +00:00
|
|
|
adaptivedemux->bitrate_limit = g_value_get_float (value);
|
2013-05-08 14:13:32 +00:00
|
|
|
break;
|
|
|
|
case PROP_MAX_BITRATE:
|
|
|
|
demux->max_bitrate = g_value_get_uint (value);
|
|
|
|
break;
|
2015-07-07 14:38:08 +00:00
|
|
|
case PROP_PRESENTATION_DELAY:
|
|
|
|
g_free (demux->default_presentation_delay);
|
|
|
|
demux->default_presentation_delay = g_value_dup_string (value);
|
|
|
|
break;
|
2013-05-08 14:13:32 +00:00
|
|
|
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)
|
|
|
|
{
|
2015-02-17 13:50:59 +00:00
|
|
|
GstAdaptiveDemux *adaptivedemux = GST_ADAPTIVE_DEMUX_CAST (object);
|
2013-05-08 14:13:32 +00:00
|
|
|
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:
|
2015-02-17 13:50:59 +00:00
|
|
|
g_value_set_float (value, adaptivedemux->bitrate_limit);
|
2013-05-08 14:13:32 +00:00
|
|
|
break;
|
|
|
|
case PROP_MAX_BITRATE:
|
|
|
|
g_value_set_uint (value, demux->max_bitrate);
|
|
|
|
break;
|
2015-07-07 14:38:08 +00:00
|
|
|
case PROP_PRESENTATION_DELAY:
|
|
|
|
if (demux->default_presentation_delay == NULL)
|
|
|
|
g_value_set_static_string (value, "");
|
|
|
|
else
|
|
|
|
g_value_set_string (value, demux->default_presentation_delay);
|
|
|
|
break;
|
2013-05-08 14:13:32 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2013-07-31 01:06:38 +00:00
|
|
|
gboolean has_streams = FALSE;
|
2013-12-02 20:31:41 +00:00
|
|
|
GList *adapt_sets, *iter;
|
2012-10-24 09:49:51 +00:00
|
|
|
|
2013-12-02 20:31:41 +00:00
|
|
|
adapt_sets = gst_mpd_client_get_adaptation_sets (client);
|
|
|
|
for (iter = adapt_sets; iter; iter = g_list_next (iter)) {
|
|
|
|
GstAdaptationSetNode *adapt_set_node = iter->data;
|
2012-10-24 09:49:51 +00:00
|
|
|
|
2013-12-02 20:31:41 +00:00
|
|
|
gst_mpd_client_setup_streaming (client, adapt_set_node);
|
|
|
|
has_streams = TRUE;
|
2013-07-31 01:06:38 +00:00
|
|
|
}
|
2013-12-02 20:31:41 +00:00
|
|
|
|
2013-07-31 01:06:38 +00:00
|
|
|
if (!has_streams) {
|
|
|
|
GST_ELEMENT_ERROR (demux, STREAM, DEMUX, ("Manifest has no playable "
|
2013-12-02 20:31:41 +00:00
|
|
|
"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;
|
|
|
|
|
2013-12-09 14:28:25 +00:00
|
|
|
GST_DEBUG_OBJECT (demux, "Setting up streams for period %d",
|
|
|
|
gst_mpd_client_get_period_index (demux->client));
|
|
|
|
|
2013-02-22 19:40:36 +00:00
|
|
|
/* 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;
|
2016-03-28 10:45:36 +00:00
|
|
|
GstStructure *s;
|
2014-08-26 19:45:46 +00:00
|
|
|
GstPad *srcpad;
|
2014-06-25 13:55:32 +00:00
|
|
|
gchar *lang = NULL;
|
2014-08-26 19:45:46 +00:00
|
|
|
GstTagList *tags = NULL;
|
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;
|
|
|
|
|
2016-07-28 08:27:29 +00:00
|
|
|
if (demux->trickmode_no_audio
|
|
|
|
&& active_stream->mimeType == GST_STREAM_AUDIO) {
|
|
|
|
GST_DEBUG_OBJECT (demux,
|
|
|
|
"Skipping audio stream %d because of TRICKMODE_NO_AUDIO flag", i);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-01-26 20:51:22 +00:00
|
|
|
srcpad = gst_dash_demux_create_pad (demux, active_stream);
|
2015-08-18 13:16:11 +00:00
|
|
|
if (srcpad == NULL)
|
|
|
|
continue;
|
|
|
|
|
2013-01-28 13:46:27 +00:00
|
|
|
caps = gst_dash_demux_get_input_caps (demux, active_stream);
|
|
|
|
GST_LOG_OBJECT (demux, "Creating stream %d %" GST_PTR_FORMAT, i, caps);
|
2014-06-25 13:55:32 +00:00
|
|
|
|
|
|
|
if (active_stream->cur_adapt_set) {
|
2014-08-19 19:01:58 +00:00
|
|
|
GstAdaptationSetNode *adp_set = active_stream->cur_adapt_set;
|
|
|
|
lang = adp_set->lang;
|
|
|
|
|
|
|
|
/* Fallback to the language in ContentComponent node */
|
2015-09-09 13:09:43 +00:00
|
|
|
if (lang == NULL) {
|
|
|
|
GList *it;
|
|
|
|
|
|
|
|
for (it = adp_set->ContentComponents; it; it = it->next) {
|
|
|
|
GstContentComponentNode *cc_node = it->data;
|
|
|
|
if (cc_node->lang) {
|
|
|
|
lang = cc_node->lang;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-08-19 19:01:58 +00:00
|
|
|
}
|
2014-06-25 13:55:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (lang) {
|
|
|
|
if (gst_tag_check_language_code (lang))
|
|
|
|
tags = gst_tag_list_new (GST_TAG_LANGUAGE_CODE, lang, NULL);
|
|
|
|
else
|
|
|
|
tags = gst_tag_list_new (GST_TAG_LANGUAGE_NAME, lang, NULL);
|
|
|
|
}
|
2013-02-07 23:58:37 +00:00
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
stream = (GstDashDemuxStream *)
|
|
|
|
gst_adaptive_demux_stream_new (GST_ADAPTIVE_DEMUX_CAST (demux), srcpad);
|
|
|
|
stream->active_stream = active_stream;
|
2016-03-28 10:45:36 +00:00
|
|
|
s = gst_caps_get_structure (caps, 0);
|
|
|
|
stream->is_isobmff = gst_structure_has_name (s, "video/quicktime");
|
2016-08-02 05:35:26 +00:00
|
|
|
stream->first_sync_sample_always_after_moof = TRUE;
|
2016-03-28 10:45:36 +00:00
|
|
|
if (stream->is_isobmff)
|
|
|
|
stream->isobmff_adapter = gst_adapter_new ();
|
2014-08-26 19:45:46 +00:00
|
|
|
gst_adaptive_demux_stream_set_caps (GST_ADAPTIVE_DEMUX_STREAM_CAST (stream),
|
|
|
|
caps);
|
|
|
|
if (tags)
|
|
|
|
gst_adaptive_demux_stream_set_tags (GST_ADAPTIVE_DEMUX_STREAM_CAST
|
|
|
|
(stream), tags);
|
|
|
|
stream->index = i;
|
2015-01-12 20:40:47 +00:00
|
|
|
stream->pending_seek_ts = GST_CLOCK_TIME_NONE;
|
2015-02-06 13:22:14 +00:00
|
|
|
if (active_stream->cur_adapt_set &&
|
|
|
|
active_stream->cur_adapt_set->RepresentationBase &&
|
|
|
|
active_stream->cur_adapt_set->RepresentationBase->ContentProtection) {
|
|
|
|
GST_DEBUG_OBJECT (demux, "Adding ContentProtection events to source pad");
|
2015-07-29 13:31:30 +00:00
|
|
|
g_list_foreach (active_stream->cur_adapt_set->RepresentationBase->
|
|
|
|
ContentProtection, gst_dash_demux_send_content_protection_event,
|
|
|
|
stream);
|
2015-02-06 13:22:14 +00:00
|
|
|
}
|
|
|
|
|
2015-01-12 14:57:02 +00:00
|
|
|
gst_isoff_sidx_parser_init (&stream->sidx_parser);
|
2016-03-28 10:45:36 +00:00
|
|
|
if (gst_mpd_client_has_isoff_ondemand_profile (demux->client))
|
|
|
|
stream->sidx_adapter = gst_adapter_new ();
|
2014-08-26 19:45:46 +00:00
|
|
|
}
|
2012-10-24 09:49:51 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-02-06 13:22:14 +00:00
|
|
|
static void
|
|
|
|
gst_dash_demux_send_content_protection_event (gpointer data, gpointer userdata)
|
|
|
|
{
|
|
|
|
GstDescriptorType *cp = (GstDescriptorType *) data;
|
|
|
|
GstDashDemuxStream *stream = (GstDashDemuxStream *) userdata;
|
|
|
|
GstEvent *event;
|
|
|
|
GstBuffer *pssi;
|
|
|
|
glong pssi_len;
|
|
|
|
gchar *schemeIdUri;
|
|
|
|
|
|
|
|
if (cp->schemeIdUri == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
GST_TRACE_OBJECT (stream, "check schemeIdUri %s", cp->schemeIdUri);
|
|
|
|
/* RFC 2141 states: The leading "urn:" sequence is case-insensitive */
|
|
|
|
schemeIdUri = g_ascii_strdown (cp->schemeIdUri, -1);
|
|
|
|
if (g_str_has_prefix (schemeIdUri, "urn:uuid:")) {
|
|
|
|
pssi_len = strlen (cp->value);
|
|
|
|
pssi = gst_buffer_new_wrapped (g_memdup (cp->value, pssi_len), pssi_len);
|
|
|
|
GST_LOG_OBJECT (stream, "Queuing Protection event on source pad");
|
|
|
|
/* RFC 4122 states that the hex part of a UUID is in lower case,
|
|
|
|
* but some streams seem to ignore this and use upper case for the
|
|
|
|
* protection system ID */
|
|
|
|
event = gst_event_new_protection (cp->schemeIdUri + 9, pssi, "dash/mpd");
|
|
|
|
gst_adaptive_demux_stream_queue_event ((GstAdaptiveDemuxStream *) stream,
|
|
|
|
event);
|
|
|
|
gst_buffer_unref (pssi);
|
|
|
|
}
|
|
|
|
g_free (schemeIdUri);
|
|
|
|
}
|
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
static GstClockTime
|
|
|
|
gst_dash_demux_get_duration (GstAdaptiveDemux * ademux)
|
2013-05-08 14:13:32 +00:00
|
|
|
{
|
2014-08-26 19:45:46 +00:00
|
|
|
GstDashDemux *demux = GST_DASH_DEMUX_CAST (ademux);
|
2012-12-17 14:00:52 +00:00
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
g_return_val_if_fail (demux->client != NULL, GST_CLOCK_TIME_NONE);
|
2013-06-11 13:28:53 +00:00
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
return gst_mpd_client_get_media_presentation_duration (demux->client);
|
|
|
|
}
|
2012-12-17 14:19:33 +00:00
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
static gboolean
|
|
|
|
gst_dash_demux_is_live (GstAdaptiveDemux * ademux)
|
|
|
|
{
|
|
|
|
GstDashDemux *demux = GST_DASH_DEMUX_CAST (ademux);
|
2013-07-03 22:11:11 +00:00
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
g_return_val_if_fail (demux->client != NULL, FALSE);
|
2013-05-08 14:13:32 +00:00
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
return gst_mpd_client_is_live (demux->client);
|
2013-05-08 14:13:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2014-08-26 19:45:46 +00:00
|
|
|
gst_dash_demux_setup_streams (GstAdaptiveDemux * demux)
|
2013-05-08 14:13:32 +00:00
|
|
|
{
|
2014-08-26 19:45:46 +00:00
|
|
|
GstDashDemux *dashdemux = GST_DASH_DEMUX_CAST (demux);
|
|
|
|
gboolean ret = TRUE;
|
2014-10-10 10:24:08 +00:00
|
|
|
GstDateTime *now = NULL;
|
|
|
|
guint period_idx;
|
2014-08-26 19:45:46 +00:00
|
|
|
|
2014-10-10 10:24:08 +00:00
|
|
|
/* setup video, audio and subtitle streams, starting from first Period if
|
|
|
|
* non-live */
|
|
|
|
period_idx = 0;
|
|
|
|
if (gst_mpd_client_is_live (dashdemux->client)) {
|
2015-07-15 10:56:13 +00:00
|
|
|
GDateTime *g_now;
|
2016-01-08 11:04:13 +00:00
|
|
|
if (dashdemux->client->mpd_node->availabilityStartTime == NULL) {
|
|
|
|
ret = FALSE;
|
|
|
|
GST_ERROR_OBJECT (demux, "MPD does not have availabilityStartTime");
|
|
|
|
goto done;
|
|
|
|
}
|
2015-07-15 10:56:13 +00:00
|
|
|
if (dashdemux->clock_drift == NULL) {
|
|
|
|
gchar **urls;
|
|
|
|
urls =
|
|
|
|
gst_mpd_client_get_utc_timing_sources (dashdemux->client,
|
|
|
|
SUPPORTED_CLOCK_FORMATS, NULL);
|
|
|
|
if (urls) {
|
|
|
|
GST_DEBUG_OBJECT (dashdemux, "Found a supported UTCTiming element");
|
2016-02-16 14:44:10 +00:00
|
|
|
dashdemux->clock_drift = gst_dash_demux_clock_drift_new (dashdemux);
|
2015-07-15 10:56:13 +00:00
|
|
|
gst_dash_demux_poll_clock_drift (dashdemux);
|
|
|
|
}
|
|
|
|
}
|
2014-10-10 10:24:08 +00:00
|
|
|
/* get period index for period encompassing the current time */
|
2015-07-15 10:56:13 +00:00
|
|
|
g_now = gst_dash_demux_get_server_now_utc (dashdemux);
|
|
|
|
now = gst_date_time_new_from_g_date_time (g_now);
|
2014-10-10 10:24:08 +00:00
|
|
|
if (dashdemux->client->mpd_node->suggestedPresentationDelay != -1) {
|
|
|
|
GstDateTime *target = gst_mpd_client_add_time_difference (now,
|
|
|
|
dashdemux->client->mpd_node->suggestedPresentationDelay * -1000);
|
|
|
|
gst_date_time_unref (now);
|
|
|
|
now = target;
|
2015-07-07 14:38:08 +00:00
|
|
|
} else if (dashdemux->default_presentation_delay) {
|
|
|
|
gint64 dfp =
|
|
|
|
gst_mpd_client_parse_default_presentation_delay (dashdemux->client,
|
|
|
|
dashdemux->default_presentation_delay);
|
|
|
|
GstDateTime *target = gst_mpd_client_add_time_difference (now, dfp);
|
|
|
|
gst_date_time_unref (now);
|
|
|
|
now = target;
|
2014-10-10 10:24:08 +00:00
|
|
|
}
|
|
|
|
period_idx =
|
|
|
|
gst_mpd_client_get_period_index_at_time (dashdemux->client, now);
|
|
|
|
if (period_idx == G_MAXUINT) {
|
|
|
|
#ifndef GST_DISABLE_GST_DEBUG
|
|
|
|
gchar *date_str = gst_date_time_to_iso8601_string (now);
|
|
|
|
GST_DEBUG_OBJECT (demux, "Unable to find live period active at %s",
|
|
|
|
date_str);
|
|
|
|
g_free (date_str);
|
|
|
|
#endif
|
|
|
|
ret = FALSE;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gst_mpd_client_set_period_index (dashdemux->client, period_idx) ||
|
2014-08-26 19:45:46 +00:00
|
|
|
!gst_dash_demux_setup_all_streams (dashdemux)) {
|
|
|
|
ret = FALSE;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If stream is live, try to find the segment that
|
|
|
|
* is closest to current time */
|
|
|
|
if (gst_mpd_client_is_live (dashdemux->client)) {
|
2015-05-08 19:49:02 +00:00
|
|
|
GDateTime *gnow;
|
2014-08-26 19:45:46 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (demux, "Seeking to current time of day for live stream ");
|
2013-07-04 18:14:00 +00:00
|
|
|
|
2015-05-08 19:49:02 +00:00
|
|
|
gnow = gst_date_time_to_g_date_time (now);
|
|
|
|
gst_mpd_client_seek_to_time (dashdemux->client, gnow);
|
|
|
|
g_date_time_unref (gnow);
|
2014-08-26 19:45:46 +00:00
|
|
|
} else {
|
|
|
|
GST_DEBUG_OBJECT (demux, "Seeking to first segment for on-demand stream ");
|
2013-07-04 18:14:00 +00:00
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
/* start playing from the first segment */
|
2015-05-08 19:31:44 +00:00
|
|
|
gst_mpd_client_seek_to_first_segment (dashdemux->client);
|
2013-05-08 14:13:32 +00:00
|
|
|
}
|
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
done:
|
2014-10-10 10:24:08 +00:00
|
|
|
if (now != NULL)
|
|
|
|
gst_date_time_unref (now);
|
2013-05-08 14:13:32 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
static gboolean
|
|
|
|
gst_dash_demux_process_manifest (GstAdaptiveDemux * demux, GstBuffer * buf)
|
2013-05-08 14:13:32 +00:00
|
|
|
{
|
2014-08-26 19:45:46 +00:00
|
|
|
GstDashDemux *dashdemux = GST_DASH_DEMUX_CAST (demux);
|
|
|
|
gboolean ret = FALSE;
|
|
|
|
gchar *manifest;
|
|
|
|
GstMapInfo mapinfo;
|
2013-05-08 14:13:32 +00:00
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
if (dashdemux->client)
|
|
|
|
gst_mpd_client_free (dashdemux->client);
|
|
|
|
dashdemux->client = gst_mpd_client_new ();
|
2015-08-21 09:06:07 +00:00
|
|
|
gst_mpd_client_set_uri_downloader (dashdemux->client, demux->downloader);
|
2013-05-08 14:13:32 +00:00
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
dashdemux->client->mpd_uri = g_strdup (demux->manifest_uri);
|
|
|
|
dashdemux->client->mpd_base_uri = g_strdup (demux->manifest_base_uri);
|
2013-01-28 21:52:04 +00:00
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
GST_DEBUG_OBJECT (demux, "Fetched MPD file at URI: %s (base: %s)",
|
|
|
|
dashdemux->client->mpd_uri,
|
|
|
|
GST_STR_NULL (dashdemux->client->mpd_base_uri));
|
2013-01-28 21:52:04 +00:00
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
if (gst_buffer_map (buf, &mapinfo, GST_MAP_READ)) {
|
|
|
|
manifest = (gchar *) mapinfo.data;
|
|
|
|
if (gst_mpd_parse (dashdemux->client, manifest, mapinfo.size)) {
|
2015-09-22 14:17:38 +00:00
|
|
|
if (gst_mpd_client_setup_media_presentation (dashdemux->client, 0, 0,
|
|
|
|
NULL)) {
|
2014-08-26 19:45:46 +00:00
|
|
|
ret = TRUE;
|
|
|
|
} else {
|
|
|
|
GST_ELEMENT_ERROR (demux, STREAM, DECODE,
|
|
|
|
("Incompatible manifest file."), (NULL));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gst_buffer_unmap (buf, &mapinfo);
|
|
|
|
} else {
|
|
|
|
GST_WARNING_OBJECT (demux, "Failed to map manifest buffer");
|
2013-01-28 21:52:04 +00:00
|
|
|
}
|
2013-05-08 14:13:32 +00:00
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
if (ret)
|
|
|
|
ret = gst_dash_demux_setup_streams (demux);
|
|
|
|
|
|
|
|
return ret;
|
2013-05-08 14:13:32 +00:00
|
|
|
}
|
|
|
|
|
2013-02-13 04:13:23 +00:00
|
|
|
static GstPad *
|
2015-01-26 20:51:22 +00:00
|
|
|
gst_dash_demux_create_pad (GstDashDemux * demux, GstActiveStream * stream)
|
2013-02-13 04:13:23 +00:00
|
|
|
{
|
|
|
|
GstPad *pad;
|
2014-04-25 11:50:18 +00:00
|
|
|
GstPadTemplate *tmpl;
|
2015-01-26 20:51:22 +00:00
|
|
|
gchar *name;
|
2014-04-25 11:50:18 +00:00
|
|
|
|
2015-01-26 20:51:22 +00:00
|
|
|
switch (stream->mimeType) {
|
|
|
|
case GST_STREAM_AUDIO:
|
|
|
|
name = g_strdup_printf ("audio_%02u", demux->n_audio_streams++);
|
|
|
|
tmpl = gst_static_pad_template_get (&gst_dash_demux_audiosrc_template);
|
|
|
|
break;
|
|
|
|
case GST_STREAM_VIDEO:
|
|
|
|
name = g_strdup_printf ("video_%02u", demux->n_video_streams++);
|
|
|
|
tmpl = gst_static_pad_template_get (&gst_dash_demux_videosrc_template);
|
|
|
|
break;
|
2015-08-18 13:16:11 +00:00
|
|
|
case GST_STREAM_APPLICATION:
|
|
|
|
if (gst_mpd_client_active_stream_contains_subtitles (stream)) {
|
|
|
|
name = g_strdup_printf ("subtitle_%02u", demux->n_subtitle_streams++);
|
|
|
|
tmpl =
|
|
|
|
gst_static_pad_template_get (&gst_dash_demux_subtitlesrc_template);
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
break;
|
2015-01-26 20:51:22 +00:00
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-02-13 04:13:23 +00:00
|
|
|
|
|
|
|
/* Create and activate new pads */
|
2016-01-13 12:51:20 +00:00
|
|
|
pad = gst_pad_new_from_template (tmpl, name);
|
2015-01-26 20:51:22 +00:00
|
|
|
g_free (name);
|
2014-04-25 11:50:18 +00:00
|
|
|
gst_object_unref (tmpl);
|
|
|
|
|
2013-02-13 04:13:23 +00:00
|
|
|
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
|
2014-08-26 19:45:46 +00:00
|
|
|
gst_dash_demux_reset (GstAdaptiveDemux * ademux)
|
2013-05-08 14:13:32 +00:00
|
|
|
{
|
2014-08-26 19:45:46 +00:00
|
|
|
GstDashDemux *demux = GST_DASH_DEMUX_CAST (ademux);
|
2013-01-30 20:27:47 +00:00
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
GST_DEBUG_OBJECT (demux, "Resetting demux");
|
2013-01-30 20:27:47 +00:00
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
demux->end_of_period = FALSE;
|
|
|
|
demux->end_of_manifest = FALSE;
|
2013-12-20 13:05:22 +00:00
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
if (demux->client) {
|
|
|
|
gst_mpd_client_free (demux->client);
|
|
|
|
demux->client = NULL;
|
2013-05-08 14:13:32 +00:00
|
|
|
}
|
2015-07-15 10:56:13 +00:00
|
|
|
gst_dash_demux_clock_drift_free (demux->clock_drift);
|
|
|
|
demux->clock_drift = NULL;
|
2014-08-26 19:45:46 +00:00
|
|
|
demux->client = gst_mpd_client_new ();
|
2015-08-21 09:06:07 +00:00
|
|
|
gst_mpd_client_set_uri_downloader (demux->client, ademux->downloader);
|
2015-01-26 20:51:22 +00:00
|
|
|
|
|
|
|
demux->n_audio_streams = 0;
|
|
|
|
demux->n_video_streams = 0;
|
2016-07-28 08:16:24 +00:00
|
|
|
demux->n_subtitle_streams = 0;
|
2016-07-28 08:27:29 +00:00
|
|
|
|
|
|
|
demux->trickmode_no_audio = FALSE;
|
2016-07-29 09:32:50 +00:00
|
|
|
demux->allow_trickmode_key_units = TRUE;
|
2013-02-13 04:13:23 +00:00
|
|
|
}
|
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
static GstCaps *
|
|
|
|
gst_dash_demux_get_video_input_caps (GstDashDemux * demux,
|
|
|
|
GstActiveStream * stream)
|
2013-02-13 04:13:23 +00:00
|
|
|
{
|
2014-08-26 19:45:46 +00:00
|
|
|
guint width = 0, height = 0;
|
2015-12-08 00:33:39 +00:00
|
|
|
gint fps_num = 0, fps_den = 1;
|
|
|
|
gboolean have_fps = FALSE;
|
2014-08-26 19:45:46 +00:00
|
|
|
GstCaps *caps = NULL;
|
2013-02-13 04:13:23 +00:00
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
if (stream == NULL)
|
|
|
|
return NULL;
|
2013-04-11 12:12:26 +00:00
|
|
|
|
2014-08-26 19:45:46 +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);
|
2015-12-08 00:33:39 +00:00
|
|
|
have_fps =
|
|
|
|
gst_mpd_client_get_video_stream_framerate (stream, &fps_num, &fps_den);
|
2013-02-13 04:13:23 +00:00
|
|
|
}
|
2015-08-18 13:16:11 +00:00
|
|
|
caps = gst_mpd_client_get_stream_caps (stream);
|
|
|
|
if (caps == NULL)
|
2014-08-26 19:45:46 +00:00
|
|
|
return NULL;
|
2013-02-13 04:13:23 +00:00
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
if (width > 0 && height > 0) {
|
|
|
|
gst_caps_set_simple (caps, "width", G_TYPE_INT, width, "height",
|
|
|
|
G_TYPE_INT, height, NULL);
|
2013-12-05 05:53:18 +00:00
|
|
|
}
|
|
|
|
|
2015-12-08 00:33:39 +00:00
|
|
|
if (have_fps) {
|
|
|
|
gst_caps_set_simple (caps, "framerate", GST_TYPE_FRACTION, fps_num,
|
|
|
|
fps_den, NULL);
|
|
|
|
}
|
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
return caps;
|
2013-12-20 13:05:22 +00:00
|
|
|
}
|
2013-12-05 05:53:18 +00:00
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
static GstCaps *
|
|
|
|
gst_dash_demux_get_audio_input_caps (GstDashDemux * demux,
|
|
|
|
GstActiveStream * stream)
|
2013-01-28 15:28:29 +00:00
|
|
|
{
|
2014-08-26 19:45:46 +00:00
|
|
|
guint rate = 0, channels = 0;
|
|
|
|
GstCaps *caps = NULL;
|
2013-01-28 15:28:29 +00:00
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
if (stream == NULL)
|
|
|
|
return NULL;
|
2014-04-25 11:50:18 +00:00
|
|
|
|
2014-08-26 19:45:46 +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);
|
2014-04-25 11:50:18 +00:00
|
|
|
}
|
2015-08-18 13:16:11 +00:00
|
|
|
caps = gst_mpd_client_get_stream_caps (stream);
|
|
|
|
if (caps == NULL)
|
2014-08-26 19:45:46 +00:00
|
|
|
return NULL;
|
2014-04-25 11:50:18 +00:00
|
|
|
|
2014-08-26 19:45:46 +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);
|
|
|
|
}
|
2014-04-25 11:50:18 +00:00
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
return caps;
|
2013-01-28 15:28:29 +00:00
|
|
|
}
|
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
static GstCaps *
|
|
|
|
gst_dash_demux_get_application_input_caps (GstDashDemux * demux,
|
|
|
|
GstActiveStream * stream)
|
|
|
|
{
|
|
|
|
GstCaps *caps = NULL;
|
2013-02-18 17:02:48 +00:00
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
if (stream == NULL)
|
|
|
|
return NULL;
|
2013-05-08 14:13:32 +00:00
|
|
|
|
2015-08-18 13:16:11 +00:00
|
|
|
caps = gst_mpd_client_get_stream_caps (stream);
|
|
|
|
if (caps == NULL)
|
2014-08-26 19:45:46 +00:00
|
|
|
return NULL;
|
2013-02-18 17:02:48 +00:00
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
return caps;
|
2013-05-08 14:13:32 +00:00
|
|
|
}
|
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
static GstCaps *
|
|
|
|
gst_dash_demux_get_input_caps (GstDashDemux * demux, GstActiveStream * stream)
|
2013-07-09 03:47:07 +00:00
|
|
|
{
|
2014-08-26 19:45:46 +00:00
|
|
|
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-07-09 03:47:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-12 20:40:47 +00:00
|
|
|
static void
|
|
|
|
gst_dash_demux_stream_update_headers_info (GstAdaptiveDemuxStream * stream)
|
|
|
|
{
|
|
|
|
GstDashDemuxStream *dashstream = (GstDashDemuxStream *) stream;
|
|
|
|
GstDashDemux *dashdemux = GST_DASH_DEMUX_CAST (stream->demux);
|
|
|
|
gchar *path = NULL;
|
|
|
|
|
|
|
|
gst_mpd_client_get_next_header (dashdemux->client,
|
|
|
|
&path, dashstream->index,
|
|
|
|
&stream->fragment.header_range_start, &stream->fragment.header_range_end);
|
|
|
|
|
2015-09-16 21:38:24 +00:00
|
|
|
if (path != NULL) {
|
2015-01-12 20:40:47 +00:00
|
|
|
stream->fragment.header_uri =
|
|
|
|
gst_uri_join_strings (gst_mpdparser_get_baseURL (dashdemux->client,
|
|
|
|
dashstream->index), path);
|
|
|
|
g_free (path);
|
2015-09-16 21:38:24 +00:00
|
|
|
path = NULL;
|
2015-01-12 20:40:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gst_mpd_client_get_next_header_index (dashdemux->client,
|
|
|
|
&path, dashstream->index,
|
|
|
|
&stream->fragment.index_range_start, &stream->fragment.index_range_end);
|
|
|
|
|
2015-09-16 21:38:24 +00:00
|
|
|
if (path != NULL) {
|
2015-01-12 20:40:47 +00:00
|
|
|
stream->fragment.index_uri =
|
|
|
|
gst_uri_join_strings (gst_mpdparser_get_baseURL (dashdemux->client,
|
|
|
|
dashstream->index), path);
|
|
|
|
g_free (path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-20 13:05:22 +00:00
|
|
|
static GstFlowReturn
|
2014-08-26 19:45:46 +00:00
|
|
|
gst_dash_demux_stream_update_fragment_info (GstAdaptiveDemuxStream * stream)
|
2013-12-20 13:05:22 +00:00
|
|
|
{
|
2014-08-26 19:45:46 +00:00
|
|
|
GstDashDemuxStream *dashstream = (GstDashDemuxStream *) stream;
|
|
|
|
GstDashDemux *dashdemux = GST_DASH_DEMUX_CAST (stream->demux);
|
|
|
|
GstClockTime ts;
|
|
|
|
GstMediaFragmentInfo fragment;
|
2015-01-12 20:40:47 +00:00
|
|
|
gboolean isombff;
|
2014-08-26 19:45:46 +00:00
|
|
|
|
|
|
|
gst_adaptive_demux_stream_fragment_clear (&stream->fragment);
|
|
|
|
|
2015-01-12 20:40:47 +00:00
|
|
|
isombff = gst_mpd_client_has_isoff_ondemand_profile (dashdemux->client);
|
|
|
|
|
2016-07-12 17:09:52 +00:00
|
|
|
/* Reset chunk size if any */
|
|
|
|
stream->fragment.chunk_size = 0;
|
|
|
|
|
2015-01-12 20:40:47 +00:00
|
|
|
if (GST_ADAPTIVE_DEMUX_STREAM_NEED_HEADER (stream) && isombff) {
|
|
|
|
gst_dash_demux_stream_update_headers_info (stream);
|
|
|
|
dashstream->sidx_base_offset = stream->fragment.index_range_end + 1;
|
|
|
|
if (dashstream->sidx_index != 0) {
|
|
|
|
/* request only the index to be downloaded as we need to reposition the
|
|
|
|
* stream to a subsegment */
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-31 12:12:49 +00:00
|
|
|
if (dashstream->moof_sync_samples
|
|
|
|
&& GST_ADAPTIVE_DEMUX (dashdemux)->
|
|
|
|
segment.flags & GST_SEGMENT_FLAG_TRICKMODE_KEY_UNITS) {
|
2016-05-30 09:09:34 +00:00
|
|
|
GstDashStreamSyncSample *sync_sample =
|
|
|
|
&g_array_index (dashstream->moof_sync_samples, GstDashStreamSyncSample,
|
|
|
|
dashstream->current_sync_sample);
|
|
|
|
|
|
|
|
gst_mpd_client_get_next_fragment (dashdemux->client, dashstream->index,
|
|
|
|
&fragment);
|
|
|
|
stream->fragment.uri = fragment.uri;
|
|
|
|
stream->fragment.timestamp = GST_CLOCK_TIME_NONE;
|
|
|
|
stream->fragment.duration = GST_CLOCK_TIME_NONE;
|
|
|
|
stream->fragment.range_start = sync_sample->start_offset;
|
|
|
|
stream->fragment.range_end = sync_sample->end_offset;
|
|
|
|
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
if (gst_mpd_client_get_next_fragment_timestamp (dashdemux->client,
|
|
|
|
dashstream->index, &ts)) {
|
|
|
|
if (GST_ADAPTIVE_DEMUX_STREAM_NEED_HEADER (stream)) {
|
2015-08-03 15:57:31 +00:00
|
|
|
gst_adaptive_demux_stream_fragment_clear (&stream->fragment);
|
2015-01-12 20:40:47 +00:00
|
|
|
gst_dash_demux_stream_update_headers_info (stream);
|
2014-08-26 19:45:46 +00:00
|
|
|
}
|
2013-12-03 19:16:09 +00:00
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
gst_mpd_client_get_next_fragment (dashdemux->client, dashstream->index,
|
|
|
|
&fragment);
|
2012-10-17 08:02:39 +00:00
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
stream->fragment.uri = fragment.uri;
|
2015-01-12 20:40:47 +00:00
|
|
|
if (isombff && dashstream->sidx_index != 0) {
|
|
|
|
GstSidxBoxEntry *entry = SIDX_CURRENT_ENTRY (dashstream);
|
|
|
|
stream->fragment.range_start =
|
|
|
|
dashstream->sidx_base_offset + entry->offset;
|
|
|
|
stream->fragment.timestamp = entry->pts;
|
|
|
|
stream->fragment.duration = entry->duration;
|
|
|
|
if (stream->demux->segment.rate < 0.0) {
|
|
|
|
stream->fragment.range_end =
|
|
|
|
stream->fragment.range_start + entry->size - 1;
|
|
|
|
} else {
|
|
|
|
stream->fragment.range_end = fragment.range_end;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
stream->fragment.timestamp = fragment.timestamp;
|
|
|
|
stream->fragment.duration = fragment.duration;
|
|
|
|
stream->fragment.range_start =
|
|
|
|
MAX (fragment.range_start, dashstream->sidx_base_offset);
|
|
|
|
stream->fragment.range_end = fragment.range_end;
|
|
|
|
}
|
2013-12-20 13:05:22 +00:00
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
return GST_FLOW_OK;
|
2013-12-20 13:05:22 +00:00
|
|
|
}
|
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
return GST_FLOW_EOS;
|
|
|
|
}
|
2012-10-17 08:02:39 +00:00
|
|
|
|
2015-07-29 13:31:30 +00:00
|
|
|
static gint
|
|
|
|
gst_dash_demux_index_entry_search (GstSidxBoxEntry * entry, GstClockTime * ts,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GstClockTime entry_ts = entry->pts + entry->duration;
|
|
|
|
if (entry_ts < *ts)
|
|
|
|
return -1;
|
|
|
|
else if (entry->pts > *ts)
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-01-12 20:40:47 +00:00
|
|
|
static void
|
|
|
|
gst_dash_demux_stream_sidx_seek (GstDashDemuxStream * dashstream,
|
2016-02-01 13:49:23 +00:00
|
|
|
gboolean forward, GstSeekFlags flags, GstClockTime ts,
|
|
|
|
GstClockTime * final_ts)
|
2015-01-12 20:40:47 +00:00
|
|
|
{
|
|
|
|
GstSidxBox *sidx = SIDX (dashstream);
|
2015-07-29 13:31:30 +00:00
|
|
|
GstSidxBoxEntry *entry;
|
|
|
|
gint idx = sidx->entries_count;
|
2015-01-12 20:40:47 +00:00
|
|
|
|
2015-07-29 13:31:30 +00:00
|
|
|
/* check whether ts is already past the last element or not */
|
2016-05-27 13:08:09 +00:00
|
|
|
if (sidx->entries[idx - 1].pts + sidx->entries[idx - 1].duration >= ts) {
|
2016-02-01 13:49:23 +00:00
|
|
|
GstSearchMode mode = GST_SEARCH_MODE_BEFORE;
|
|
|
|
|
|
|
|
if ((flags & GST_SEEK_FLAG_SNAP_NEAREST) == GST_SEEK_FLAG_SNAP_NEAREST) {
|
|
|
|
mode = GST_SEARCH_MODE_BEFORE;
|
|
|
|
} else if ((forward && (flags & GST_SEEK_FLAG_SNAP_AFTER)) ||
|
|
|
|
(!forward && (flags & GST_SEEK_FLAG_SNAP_BEFORE))) {
|
|
|
|
mode = GST_SEARCH_MODE_AFTER;
|
|
|
|
} else {
|
|
|
|
mode = GST_SEARCH_MODE_BEFORE;
|
|
|
|
}
|
|
|
|
|
2015-07-29 13:31:30 +00:00
|
|
|
entry =
|
|
|
|
gst_util_array_binary_search (sidx->entries, sidx->entries_count,
|
|
|
|
sizeof (GstSidxBoxEntry),
|
2016-02-01 13:49:23 +00:00
|
|
|
(GCompareDataFunc) gst_dash_demux_index_entry_search, mode, &ts, NULL);
|
2015-07-29 13:31:30 +00:00
|
|
|
|
|
|
|
idx = entry - sidx->entries;
|
2016-02-01 13:49:23 +00:00
|
|
|
|
|
|
|
/* FIXME in reverse mode, if we are exactly at a fragment start it makes more
|
|
|
|
* sense to start from the end of the previous fragment */
|
|
|
|
/* FIXME we should have a GST_SEARCH_MODE_NEAREST */
|
|
|
|
if ((flags & GST_SEEK_FLAG_SNAP_NEAREST) == GST_SEEK_FLAG_SNAP_NEAREST &&
|
|
|
|
idx + 1 < sidx->entries_count) {
|
|
|
|
if (ABS (sidx->entries[idx + 1].pts - ts) <
|
|
|
|
ABS (sidx->entries[idx].pts - ts))
|
|
|
|
idx += 1;
|
|
|
|
}
|
2015-07-29 13:31:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sidx->entry_index = idx;
|
|
|
|
dashstream->sidx_index = idx;
|
2016-01-27 16:31:10 +00:00
|
|
|
|
|
|
|
if (final_ts) {
|
|
|
|
if (idx == sidx->entries_count)
|
|
|
|
*final_ts = sidx->entries[idx].pts + sidx->entries[idx].duration;
|
|
|
|
else
|
|
|
|
*final_ts = sidx->entries[idx].pts;
|
|
|
|
}
|
2015-01-12 20:40:47 +00:00
|
|
|
}
|
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
static GstFlowReturn
|
2016-01-27 16:31:10 +00:00
|
|
|
gst_dash_demux_stream_seek (GstAdaptiveDemuxStream * stream, gboolean forward,
|
|
|
|
GstSeekFlags flags, GstClockTime ts, GstClockTime * final_ts)
|
2014-08-26 19:45:46 +00:00
|
|
|
{
|
|
|
|
GstDashDemuxStream *dashstream = (GstDashDemuxStream *) stream;
|
|
|
|
GstDashDemux *dashdemux = GST_DASH_DEMUX_CAST (stream->demux);
|
2012-10-17 08:02:39 +00:00
|
|
|
|
2016-05-30 08:15:03 +00:00
|
|
|
if (dashstream->moof)
|
|
|
|
gst_isoff_moof_box_free (dashstream->moof);
|
|
|
|
dashstream->moof = NULL;
|
|
|
|
if (dashstream->moof_sync_samples)
|
|
|
|
g_array_free (dashstream->moof_sync_samples, TRUE);
|
|
|
|
dashstream->moof_sync_samples = NULL;
|
2016-05-30 09:09:34 +00:00
|
|
|
dashstream->current_sync_sample = -1;
|
2016-05-30 08:15:03 +00:00
|
|
|
|
2015-01-12 20:40:47 +00:00
|
|
|
if (gst_mpd_client_has_isoff_ondemand_profile (dashdemux->client)) {
|
|
|
|
if (dashstream->sidx_parser.status == GST_ISOFF_SIDX_PARSER_FINISHED) {
|
2016-02-01 13:49:23 +00:00
|
|
|
gst_dash_demux_stream_sidx_seek (dashstream, forward, flags, ts,
|
|
|
|
final_ts);
|
2015-01-12 20:40:47 +00:00
|
|
|
} else {
|
|
|
|
/* no index yet, seek when we have it */
|
2016-01-27 16:31:10 +00:00
|
|
|
/* FIXME - the final_ts won't be correct here */
|
2015-01-12 20:40:47 +00:00
|
|
|
dashstream->pending_seek_ts = ts;
|
|
|
|
}
|
2016-08-11 10:11:22 +00:00
|
|
|
|
|
|
|
return GST_FLOW_OK;
|
2015-01-12 20:40:47 +00:00
|
|
|
}
|
|
|
|
|
2016-01-27 16:31:10 +00:00
|
|
|
gst_mpd_client_stream_seek (dashdemux->client, dashstream->active_stream,
|
|
|
|
forward, flags, ts, final_ts);
|
2014-08-26 19:45:46 +00:00
|
|
|
return GST_FLOW_OK;
|
2013-05-08 14:13:32 +00:00
|
|
|
}
|
|
|
|
|
2016-05-30 09:09:34 +00:00
|
|
|
static gboolean
|
|
|
|
gst_dash_demux_stream_has_next_sync_sample (GstAdaptiveDemuxStream * stream)
|
|
|
|
{
|
|
|
|
GstDashDemuxStream *dashstream = (GstDashDemuxStream *) stream;
|
|
|
|
|
2016-05-31 12:12:49 +00:00
|
|
|
if (dashstream->moof_sync_samples
|
|
|
|
&& GST_ADAPTIVE_DEMUX (stream->demux)->
|
|
|
|
segment.flags & GST_SEGMENT_FLAG_TRICKMODE_KEY_UNITS) {
|
2016-05-30 09:09:34 +00:00
|
|
|
if (stream->demux->segment.rate > 0.0) {
|
|
|
|
if (dashstream->current_sync_sample + 1 <
|
|
|
|
dashstream->moof_sync_samples->len)
|
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
if (dashstream->current_sync_sample >= 1)
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2015-09-14 16:56:10 +00:00
|
|
|
static gboolean
|
|
|
|
gst_dash_demux_stream_has_next_subfragment (GstAdaptiveDemuxStream * stream)
|
|
|
|
{
|
|
|
|
GstDashDemuxStream *dashstream = (GstDashDemuxStream *) stream;
|
|
|
|
GstSidxBox *sidx = SIDX (dashstream);
|
|
|
|
|
|
|
|
if (dashstream->sidx_parser.status == GST_ISOFF_SIDX_PARSER_FINISHED) {
|
|
|
|
if (stream->demux->segment.rate > 0.0) {
|
|
|
|
if (sidx->entry_index + 1 < sidx->entries_count)
|
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
if (sidx->entry_index >= 1)
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2016-05-30 09:09:34 +00:00
|
|
|
static gboolean
|
|
|
|
gst_dash_demux_stream_advance_sync_sample (GstAdaptiveDemuxStream * stream)
|
|
|
|
{
|
|
|
|
GstDashDemuxStream *dashstream = (GstDashDemuxStream *) stream;
|
|
|
|
gboolean fragment_finished = FALSE;
|
|
|
|
|
2016-05-31 12:12:49 +00:00
|
|
|
if (dashstream->moof_sync_samples
|
|
|
|
&& GST_ADAPTIVE_DEMUX (stream->demux)->
|
|
|
|
segment.flags & GST_SEGMENT_FLAG_TRICKMODE_KEY_UNITS) {
|
2016-05-30 09:09:34 +00:00
|
|
|
if (stream->demux->segment.rate > 0.0) {
|
|
|
|
dashstream->current_sync_sample++;
|
|
|
|
if (dashstream->current_sync_sample >= dashstream->moof_sync_samples->len) {
|
|
|
|
fragment_finished = TRUE;
|
|
|
|
}
|
|
|
|
} else {
|
2016-07-12 17:09:52 +00:00
|
|
|
if (dashstream->current_sync_sample == -1) {
|
2016-05-30 09:09:34 +00:00
|
|
|
dashstream->current_sync_sample =
|
|
|
|
dashstream->moof_sync_samples->len - 1;
|
2016-07-12 17:09:52 +00:00
|
|
|
} else if (dashstream->current_sync_sample == 0) {
|
2016-05-30 09:09:34 +00:00
|
|
|
dashstream->current_sync_sample = -1;
|
|
|
|
fragment_finished = TRUE;
|
2016-08-18 10:21:54 +00:00
|
|
|
} else {
|
2016-05-30 09:09:34 +00:00
|
|
|
dashstream->current_sync_sample--;
|
2016-08-18 10:21:54 +00:00
|
|
|
}
|
2016-05-30 09:09:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (stream->pad,
|
|
|
|
"Advancing sync sample #%d fragment_finished:%d",
|
|
|
|
dashstream->current_sync_sample, fragment_finished);
|
|
|
|
|
|
|
|
if (!fragment_finished)
|
|
|
|
stream->discont = TRUE;
|
|
|
|
|
|
|
|
return !fragment_finished;
|
|
|
|
}
|
|
|
|
|
2015-01-15 20:44:45 +00:00
|
|
|
static gboolean
|
2015-01-12 20:40:47 +00:00
|
|
|
gst_dash_demux_stream_advance_subfragment (GstAdaptiveDemuxStream * stream)
|
|
|
|
{
|
|
|
|
GstDashDemuxStream *dashstream = (GstDashDemuxStream *) stream;
|
|
|
|
|
|
|
|
GstSidxBox *sidx = SIDX (dashstream);
|
|
|
|
gboolean fragment_finished = TRUE;
|
|
|
|
|
2015-02-16 02:16:52 +00:00
|
|
|
if (dashstream->sidx_parser.status == GST_ISOFF_SIDX_PARSER_FINISHED) {
|
|
|
|
if (stream->demux->segment.rate > 0.0) {
|
|
|
|
sidx->entry_index++;
|
|
|
|
if (sidx->entry_index < sidx->entries_count) {
|
|
|
|
fragment_finished = FALSE;
|
|
|
|
}
|
2016-08-02 05:35:26 +00:00
|
|
|
dashstream->sidx_index++;
|
2015-02-16 02:16:52 +00:00
|
|
|
} else {
|
|
|
|
sidx->entry_index--;
|
2016-08-02 05:35:26 +00:00
|
|
|
dashstream->sidx_index--;
|
2015-02-16 02:16:52 +00:00
|
|
|
if (sidx->entry_index >= 0) {
|
|
|
|
fragment_finished = FALSE;
|
|
|
|
}
|
2015-01-12 20:40:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-16 02:16:52 +00:00
|
|
|
GST_DEBUG_OBJECT (stream->pad, "New sidx index: %d / %d. "
|
|
|
|
"Finished fragment: %d", sidx->entry_index, sidx->entries_count,
|
|
|
|
fragment_finished);
|
|
|
|
|
2015-01-15 20:44:45 +00:00
|
|
|
return !fragment_finished;
|
2015-01-12 20:40:47 +00:00
|
|
|
}
|
|
|
|
|
2015-05-12 16:41:19 +00:00
|
|
|
static gboolean
|
|
|
|
gst_dash_demux_stream_has_next_fragment (GstAdaptiveDemuxStream * stream)
|
|
|
|
{
|
|
|
|
GstDashDemux *dashdemux = GST_DASH_DEMUX_CAST (stream->demux);
|
|
|
|
GstDashDemuxStream *dashstream = (GstDashDemuxStream *) stream;
|
|
|
|
|
2016-05-30 09:09:34 +00:00
|
|
|
if (dashstream->moof_sync_samples
|
2016-05-31 12:12:49 +00:00
|
|
|
&& GST_ADAPTIVE_DEMUX (dashdemux)->
|
|
|
|
segment.flags & GST_SEGMENT_FLAG_TRICKMODE_KEY_UNITS) {
|
2016-05-30 09:09:34 +00:00
|
|
|
if (gst_dash_demux_stream_has_next_sync_sample (stream))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-09-14 16:56:10 +00:00
|
|
|
if (gst_mpd_client_has_isoff_ondemand_profile (dashdemux->client)) {
|
|
|
|
if (gst_dash_demux_stream_has_next_subfragment (stream))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-05-12 16:41:19 +00:00
|
|
|
return gst_mpd_client_has_next_segment (dashdemux->client,
|
|
|
|
dashstream->active_stream, stream->demux->segment.rate > 0.0);
|
|
|
|
}
|
|
|
|
|
2016-03-31 10:39:59 +00:00
|
|
|
static void
|
|
|
|
gst_dash_demux_clear_pending_stream_data (GstDashDemux * dashdemux,
|
|
|
|
GstDashDemuxStream * dashstream)
|
|
|
|
{
|
|
|
|
gst_isoff_sidx_parser_clear (&dashstream->sidx_parser);
|
|
|
|
gst_isoff_sidx_parser_init (&dashstream->sidx_parser);
|
|
|
|
if (dashstream->sidx_adapter)
|
|
|
|
gst_adapter_clear (dashstream->sidx_adapter);
|
2016-03-28 10:45:36 +00:00
|
|
|
|
|
|
|
/* Reset ISOBMFF box parsing state */
|
|
|
|
if (dashstream->isobmff_adapter)
|
|
|
|
gst_adapter_clear (dashstream->isobmff_adapter);
|
|
|
|
dashstream->isobmff_parser.current_fourcc = 0;
|
|
|
|
dashstream->isobmff_parser.current_start_offset = 0;
|
|
|
|
dashstream->isobmff_parser.current_offset = 0;
|
|
|
|
dashstream->isobmff_parser.current_size = 0;
|
2016-05-30 08:15:03 +00:00
|
|
|
|
|
|
|
if (dashstream->moof)
|
|
|
|
gst_isoff_moof_box_free (dashstream->moof);
|
|
|
|
dashstream->moof = NULL;
|
|
|
|
if (dashstream->moof_sync_samples)
|
|
|
|
g_array_free (dashstream->moof_sync_samples, TRUE);
|
|
|
|
dashstream->moof_sync_samples = NULL;
|
2016-05-30 09:09:34 +00:00
|
|
|
dashstream->current_sync_sample = -1;
|
2016-03-31 10:39:59 +00:00
|
|
|
}
|
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
gst_dash_demux_stream_advance_fragment (GstAdaptiveDemuxStream * stream)
|
2013-05-08 14:13:32 +00:00
|
|
|
{
|
2014-08-26 19:45:46 +00:00
|
|
|
GstDashDemuxStream *dashstream = (GstDashDemuxStream *) stream;
|
|
|
|
GstDashDemux *dashdemux = GST_DASH_DEMUX_CAST (stream->demux);
|
2013-12-03 19:16:09 +00:00
|
|
|
|
2015-02-16 02:16:52 +00:00
|
|
|
GST_DEBUG_OBJECT (stream->pad, "Advance fragment");
|
|
|
|
|
2016-05-30 09:09:34 +00:00
|
|
|
/* If downloading only keyframes, switch to the next one or fall through */
|
|
|
|
if (dashstream->moof_sync_samples
|
2016-05-31 12:12:49 +00:00
|
|
|
&& GST_ADAPTIVE_DEMUX (dashdemux)->
|
|
|
|
segment.flags & GST_SEGMENT_FLAG_TRICKMODE_KEY_UNITS) {
|
2016-05-30 09:09:34 +00:00
|
|
|
if (gst_dash_demux_stream_advance_sync_sample (stream))
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
2016-05-30 08:15:03 +00:00
|
|
|
if (dashstream->isobmff_adapter)
|
|
|
|
gst_adapter_clear (dashstream->isobmff_adapter);
|
|
|
|
dashstream->isobmff_parser.current_fourcc = 0;
|
|
|
|
dashstream->isobmff_parser.current_start_offset = 0;
|
|
|
|
dashstream->isobmff_parser.current_offset = 0;
|
|
|
|
dashstream->isobmff_parser.current_size = 0;
|
|
|
|
|
|
|
|
if (dashstream->moof)
|
|
|
|
gst_isoff_moof_box_free (dashstream->moof);
|
|
|
|
dashstream->moof = NULL;
|
|
|
|
if (dashstream->moof_sync_samples)
|
|
|
|
g_array_free (dashstream->moof_sync_samples, TRUE);
|
|
|
|
dashstream->moof_sync_samples = NULL;
|
2016-05-30 09:09:34 +00:00
|
|
|
dashstream->current_sync_sample = -1;
|
2016-05-30 08:15:03 +00:00
|
|
|
|
2015-01-12 20:40:47 +00:00
|
|
|
if (gst_mpd_client_has_isoff_ondemand_profile (dashdemux->client)) {
|
2015-01-15 20:44:45 +00:00
|
|
|
if (gst_dash_demux_stream_advance_subfragment (stream))
|
|
|
|
return GST_FLOW_OK;
|
2015-01-12 20:40:47 +00:00
|
|
|
}
|
|
|
|
|
2016-05-30 08:15:03 +00:00
|
|
|
gst_isoff_sidx_parser_clear (&dashstream->sidx_parser);
|
|
|
|
gst_isoff_sidx_parser_init (&dashstream->sidx_parser);
|
|
|
|
if (dashstream->sidx_adapter)
|
|
|
|
gst_adapter_clear (dashstream->sidx_adapter);
|
2016-03-31 10:39:59 +00:00
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
return gst_mpd_client_advance_segment (dashdemux->client,
|
|
|
|
dashstream->active_stream, stream->demux->segment.rate > 0.0);
|
2013-05-08 14:13:32 +00:00
|
|
|
}
|
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
static gboolean
|
|
|
|
gst_dash_demux_stream_select_bitrate (GstAdaptiveDemuxStream * stream,
|
|
|
|
guint64 bitrate)
|
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;
|
2014-08-26 19:45:46 +00:00
|
|
|
GstDashDemux *demux = GST_DASH_DEMUX_CAST (stream->demux);
|
|
|
|
GstDashDemuxStream *dashstream = (GstDashDemuxStream *) stream;
|
|
|
|
gboolean ret = FALSE;
|
2013-05-08 14:13:32 +00:00
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
active_stream = dashstream->active_stream;
|
|
|
|
if (active_stream == NULL) {
|
|
|
|
goto end;
|
|
|
|
}
|
2013-01-30 20:27:47 +00:00
|
|
|
|
2013-12-03 19:16:09 +00:00
|
|
|
/* retrieve representation list */
|
|
|
|
if (active_stream->cur_adapt_set)
|
|
|
|
rep_list = active_stream->cur_adapt_set->Representations;
|
2014-08-26 19:45:46 +00:00
|
|
|
if (!rep_list) {
|
|
|
|
goto end;
|
|
|
|
}
|
2014-05-01 15:04:51 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (stream->pad,
|
|
|
|
"Trying to change to bitrate: %" G_GUINT64_FORMAT, bitrate);
|
2013-12-03 19:16:09 +00:00
|
|
|
|
|
|
|
/* get representation index with current max_bandwidth */
|
|
|
|
new_index = gst_mpdparser_get_rep_idx_with_max_bandwidth (rep_list, bitrate);
|
|
|
|
|
|
|
|
/* if no representation has the required bandwidth, take the lowest one */
|
|
|
|
if (new_index == -1)
|
|
|
|
new_index = gst_mpdparser_get_rep_idx_with_min_bandwidth (rep_list);
|
|
|
|
|
|
|
|
if (new_index != active_stream->representation_idx) {
|
|
|
|
GstRepresentationNode *rep = g_list_nth_data (rep_list, new_index);
|
|
|
|
GST_INFO_OBJECT (demux, "Changing representation idx: %d %d %u",
|
2014-08-26 19:45:46 +00:00
|
|
|
dashstream->index, new_index, rep->bandwidth);
|
2013-12-03 19:16:09 +00:00
|
|
|
if (gst_mpd_client_setup_representation (demux->client, active_stream, rep)) {
|
2014-08-26 19:45:46 +00:00
|
|
|
GstCaps *caps;
|
|
|
|
|
2013-12-03 19:16:09 +00:00
|
|
|
GST_INFO_OBJECT (demux, "Switching bitrate to %d",
|
|
|
|
active_stream->cur_representation->bandwidth);
|
2014-08-26 19:45:46 +00:00
|
|
|
caps = gst_dash_demux_get_input_caps (demux, active_stream);
|
|
|
|
gst_adaptive_demux_stream_set_caps (stream, caps);
|
|
|
|
ret = TRUE;
|
2015-01-12 20:40:47 +00:00
|
|
|
|
2013-12-03 19:16:09 +00:00
|
|
|
} else {
|
|
|
|
GST_WARNING_OBJECT (demux, "Can not switch representation, aborting...");
|
2013-05-08 14:13:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-31 10:39:59 +00:00
|
|
|
if (ret) {
|
|
|
|
gst_dash_demux_clear_pending_stream_data (demux, dashstream);
|
|
|
|
|
|
|
|
if (gst_mpd_client_has_isoff_ondemand_profile (demux->client)) {
|
|
|
|
/* store our current position to change to the same one in a different
|
|
|
|
* representation if needed */
|
|
|
|
dashstream->sidx_index = SIDX (dashstream)->entry_index;
|
2015-01-12 20:40:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
end:
|
2014-08-29 10:38:12 +00:00
|
|
|
return ret;
|
2013-07-01 16:19:15 +00:00
|
|
|
}
|
2012-10-17 16:40:02 +00:00
|
|
|
|
2016-02-01 12:48:33 +00:00
|
|
|
#define SEEK_UPDATES_PLAY_POSITION(r, start_type, stop_type) \
|
|
|
|
((r >= 0 && start_type != GST_SEEK_TYPE_NONE) || \
|
|
|
|
(r < 0 && stop_type != GST_SEEK_TYPE_NONE))
|
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
static gboolean
|
|
|
|
gst_dash_demux_seek (GstAdaptiveDemux * demux, GstEvent * seek)
|
2013-05-08 14:13:32 +00:00
|
|
|
{
|
2014-08-26 19:45:46 +00:00
|
|
|
gdouble rate;
|
|
|
|
GstFormat format;
|
|
|
|
GstSeekFlags flags;
|
|
|
|
GstSeekType start_type, stop_type;
|
|
|
|
gint64 start, stop;
|
|
|
|
GList *list;
|
|
|
|
GstClockTime current_pos, target_pos;
|
|
|
|
guint current_period;
|
|
|
|
GstStreamPeriod *period;
|
2016-07-28 08:27:29 +00:00
|
|
|
GList *iter, *streams = NULL;
|
2014-08-26 19:45:46 +00:00
|
|
|
GstDashDemux *dashdemux = GST_DASH_DEMUX_CAST (demux);
|
2016-07-28 08:27:29 +00:00
|
|
|
gboolean trickmode_no_audio;
|
2014-08-26 19:45:46 +00:00
|
|
|
|
|
|
|
gst_event_parse_seek (seek, &rate, &format, &flags, &start_type, &start,
|
|
|
|
&stop_type, &stop);
|
|
|
|
|
2016-02-01 12:48:33 +00:00
|
|
|
if (!SEEK_UPDATES_PLAY_POSITION (rate, start_type, stop_type)) {
|
|
|
|
/* nothing to do if we don't have to update the current position */
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (demux->segment.rate > 0.0) {
|
2016-01-29 23:34:42 +00:00
|
|
|
target_pos = (GstClockTime) start;
|
2016-02-01 12:48:33 +00:00
|
|
|
} else {
|
2016-01-29 23:34:42 +00:00
|
|
|
target_pos = (GstClockTime) stop;
|
2016-02-01 12:48:33 +00:00
|
|
|
}
|
2014-08-26 19:45:46 +00:00
|
|
|
|
|
|
|
/* select the requested Period in the Media Presentation */
|
2015-09-22 14:17:38 +00:00
|
|
|
if (!gst_mpd_client_setup_media_presentation (dashdemux->client, target_pos,
|
|
|
|
-1, NULL))
|
|
|
|
return FALSE;
|
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
current_period = 0;
|
|
|
|
for (list = g_list_first (dashdemux->client->periods); list;
|
|
|
|
list = g_list_next (list)) {
|
|
|
|
period = list->data;
|
|
|
|
current_pos = period->start;
|
|
|
|
current_period = period->number;
|
2015-08-16 11:49:35 +00:00
|
|
|
GST_DEBUG_OBJECT (demux, "Looking at period %u) start:%"
|
|
|
|
GST_TIME_FORMAT " - duration:%"
|
|
|
|
GST_TIME_FORMAT ") for position %" GST_TIME_FORMAT,
|
|
|
|
current_period, GST_TIME_ARGS (current_pos),
|
|
|
|
GST_TIME_ARGS (period->duration), GST_TIME_ARGS (target_pos));
|
2014-08-26 19:45:46 +00:00
|
|
|
if (current_pos <= target_pos
|
2015-08-16 11:49:35 +00:00
|
|
|
&& target_pos <= current_pos + period->duration) {
|
2014-08-26 19:45:46 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-12-17 14:39:10 +00:00
|
|
|
}
|
2014-08-26 19:45:46 +00:00
|
|
|
if (list == NULL) {
|
|
|
|
GST_WARNING_OBJECT (demux, "Could not find seeked Period");
|
|
|
|
return FALSE;
|
2012-10-19 18:12:09 +00:00
|
|
|
}
|
2016-07-28 08:27:29 +00:00
|
|
|
|
|
|
|
trickmode_no_audio = ! !(flags & GST_SEEK_FLAG_TRICKMODE_NO_AUDIO);
|
|
|
|
|
|
|
|
streams = demux->streams;
|
2014-08-26 19:45:46 +00:00
|
|
|
if (current_period != gst_mpd_client_get_period_index (dashdemux->client)) {
|
|
|
|
GST_DEBUG_OBJECT (demux, "Seeking to Period %d", current_period);
|
2012-10-19 18:12:09 +00:00
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
/* clean old active stream list, if any */
|
|
|
|
gst_active_streams_free (dashdemux->client);
|
2016-07-28 08:27:29 +00:00
|
|
|
dashdemux->trickmode_no_audio = trickmode_no_audio;
|
2012-10-19 18:12:09 +00:00
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
/* setup video, audio and subtitle streams, starting from the new Period */
|
|
|
|
if (!gst_mpd_client_set_period_index (dashdemux->client, current_period)
|
|
|
|
|| !gst_dash_demux_setup_all_streams (dashdemux))
|
|
|
|
return FALSE;
|
2016-07-28 08:27:29 +00:00
|
|
|
streams = demux->next_streams;
|
|
|
|
} else if (dashdemux->trickmode_no_audio != trickmode_no_audio) {
|
|
|
|
/* clean old active stream list, if any */
|
|
|
|
gst_active_streams_free (dashdemux->client);
|
|
|
|
dashdemux->trickmode_no_audio = trickmode_no_audio;
|
|
|
|
|
|
|
|
/* setup video, audio and subtitle streams, starting from the new Period */
|
|
|
|
if (!gst_dash_demux_setup_all_streams (dashdemux))
|
|
|
|
return FALSE;
|
|
|
|
streams = demux->next_streams;
|
2012-12-17 14:39:10 +00:00
|
|
|
}
|
2012-10-08 15:43:14 +00:00
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
/* Update the current sequence on all streams */
|
2016-07-28 08:27:29 +00:00
|
|
|
for (iter = streams; iter; iter = g_list_next (iter)) {
|
2014-08-26 19:45:46 +00:00
|
|
|
GstDashDemuxStream *dashstream = iter->data;
|
2015-01-12 20:40:47 +00:00
|
|
|
|
|
|
|
if (flags & GST_SEEK_FLAG_FLUSH) {
|
2016-03-31 10:39:59 +00:00
|
|
|
gst_dash_demux_clear_pending_stream_data (dashdemux, dashstream);
|
2015-01-12 20:40:47 +00:00
|
|
|
}
|
2016-01-27 16:31:10 +00:00
|
|
|
gst_dash_demux_stream_seek (iter->data, rate >= 0, 0, target_pos, NULL);
|
2013-05-08 14:13:32 +00:00
|
|
|
}
|
2014-08-26 19:45:46 +00:00
|
|
|
return TRUE;
|
2013-05-08 14:13:32 +00:00
|
|
|
}
|
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
static gint64
|
|
|
|
gst_dash_demux_get_manifest_update_interval (GstAdaptiveDemux * demux)
|
2013-12-03 03:12:08 +00:00
|
|
|
{
|
2014-08-26 19:45:46 +00:00
|
|
|
GstDashDemux *dashdemux = GST_DASH_DEMUX_CAST (demux);
|
2015-07-15 10:56:13 +00:00
|
|
|
return MIN (dashdemux->client->mpd_node->minimumUpdatePeriod * 1000,
|
|
|
|
SLOW_CLOCK_UPDATE_INTERVAL);
|
2013-12-03 03:12:08 +00:00
|
|
|
}
|
|
|
|
|
2014-04-25 11:50:18 +00:00
|
|
|
static GstFlowReturn
|
2015-04-23 15:22:11 +00:00
|
|
|
gst_dash_demux_update_manifest_data (GstAdaptiveDemux * demux,
|
|
|
|
GstBuffer * buffer)
|
2014-04-25 11:50:18 +00:00
|
|
|
{
|
2014-08-26 19:45:46 +00:00
|
|
|
GstDashDemux *dashdemux = GST_DASH_DEMUX_CAST (demux);
|
|
|
|
GstMpdClient *new_client = NULL;
|
|
|
|
GstMapInfo mapinfo;
|
2014-05-02 21:32:56 +00:00
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
GST_DEBUG_OBJECT (demux, "Updating manifest file from URL");
|
2014-05-02 21:32:56 +00:00
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
/* parse the manifest file */
|
|
|
|
new_client = gst_mpd_client_new ();
|
2015-08-21 09:06:07 +00:00
|
|
|
gst_mpd_client_set_uri_downloader (new_client, demux->downloader);
|
2014-11-29 13:25:45 +00:00
|
|
|
new_client->mpd_uri = g_strdup (demux->manifest_uri);
|
|
|
|
new_client->mpd_base_uri = g_strdup (demux->manifest_base_uri);
|
2014-08-26 19:45:46 +00:00
|
|
|
gst_buffer_map (buffer, &mapinfo, GST_MAP_READ);
|
2014-05-02 21:32:56 +00:00
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
if (gst_mpd_parse (new_client, (gchar *) mapinfo.data, mapinfo.size)) {
|
|
|
|
const gchar *period_id;
|
|
|
|
guint period_idx;
|
|
|
|
GList *iter;
|
2014-11-29 13:26:31 +00:00
|
|
|
GList *streams_iter;
|
2014-05-02 21:32:56 +00:00
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
/* prepare the new manifest and try to transfer the stream position
|
|
|
|
* status from the old manifest client */
|
2014-04-25 11:50:18 +00:00
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
GST_DEBUG_OBJECT (demux, "Updating manifest");
|
2014-09-09 11:12:31 +00:00
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
period_id = gst_mpd_client_get_period_id (dashdemux->client);
|
|
|
|
period_idx = gst_mpd_client_get_period_index (dashdemux->client);
|
2014-04-25 11:50:18 +00:00
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
/* setup video, audio and subtitle streams, starting from current Period */
|
2015-09-22 14:17:38 +00:00
|
|
|
if (!gst_mpd_client_setup_media_presentation (new_client, -1,
|
|
|
|
(period_id ? -1 : period_idx), period_id)) {
|
2014-08-26 19:45:46 +00:00
|
|
|
/* TODO */
|
2014-04-25 11:50:18 +00:00
|
|
|
}
|
|
|
|
|
2014-12-02 10:06:00 +00:00
|
|
|
if (period_id) {
|
2014-08-26 19:45:46 +00:00
|
|
|
if (!gst_mpd_client_set_period_id (new_client, period_id)) {
|
|
|
|
GST_DEBUG_OBJECT (demux, "Error setting up the updated manifest file");
|
2016-01-04 12:12:45 +00:00
|
|
|
gst_mpd_client_free (new_client);
|
|
|
|
gst_buffer_unmap (buffer, &mapinfo);
|
2014-08-26 19:45:46 +00:00
|
|
|
return GST_FLOW_EOS;
|
|
|
|
}
|
2014-04-25 11:50:18 +00:00
|
|
|
} else {
|
2014-08-26 19:45:46 +00:00
|
|
|
if (!gst_mpd_client_set_period_index (new_client, period_idx)) {
|
|
|
|
GST_DEBUG_OBJECT (demux, "Error setting up the updated manifest file");
|
2016-01-04 12:12:45 +00:00
|
|
|
gst_mpd_client_free (new_client);
|
|
|
|
gst_buffer_unmap (buffer, &mapinfo);
|
2014-08-26 19:45:46 +00:00
|
|
|
return GST_FLOW_EOS;
|
2014-04-25 11:50:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
if (!gst_dash_demux_setup_mpdparser_streams (dashdemux, new_client)) {
|
|
|
|
GST_ERROR_OBJECT (demux, "Failed to setup streams on manifest " "update");
|
2016-01-04 12:12:45 +00:00
|
|
|
gst_mpd_client_free (new_client);
|
|
|
|
gst_buffer_unmap (buffer, &mapinfo);
|
2014-08-26 19:45:46 +00:00
|
|
|
return GST_FLOW_ERROR;
|
2014-04-25 11:50:18 +00:00
|
|
|
}
|
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
/* update the streams to play from the next segment */
|
2014-11-29 13:26:31 +00:00
|
|
|
for (iter = demux->streams, streams_iter = new_client->active_streams;
|
|
|
|
iter && streams_iter;
|
|
|
|
iter = g_list_next (iter), streams_iter = g_list_next (streams_iter)) {
|
2014-08-26 19:45:46 +00:00
|
|
|
GstDashDemuxStream *demux_stream = iter->data;
|
2014-11-29 13:26:31 +00:00
|
|
|
GstActiveStream *new_stream = streams_iter->data;
|
2014-08-26 19:45:46 +00:00
|
|
|
GstClockTime ts;
|
2014-04-25 11:50:18 +00:00
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
if (!new_stream) {
|
|
|
|
GST_DEBUG_OBJECT (demux,
|
|
|
|
"Stream of index %d is missing from manifest update",
|
|
|
|
demux_stream->index);
|
2016-01-04 12:12:45 +00:00
|
|
|
gst_mpd_client_free (new_client);
|
|
|
|
gst_buffer_unmap (buffer, &mapinfo);
|
2014-08-26 19:45:46 +00:00
|
|
|
return GST_FLOW_EOS;
|
2014-04-25 11:50:18 +00:00
|
|
|
}
|
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
if (gst_mpd_client_get_next_fragment_timestamp (dashdemux->client,
|
2015-05-11 17:19:20 +00:00
|
|
|
demux_stream->index, &ts)
|
|
|
|
|| gst_mpd_client_get_last_fragment_timestamp_end (dashdemux->client,
|
2014-08-26 19:45:46 +00:00
|
|
|
demux_stream->index, &ts)) {
|
2015-05-11 17:19:20 +00:00
|
|
|
|
|
|
|
/* Due to rounding when doing the timescale conversions it might happen
|
|
|
|
* that the ts falls back to a previous segment, leading the same data
|
|
|
|
* to be downloaded twice. We try to work around this by always adding
|
|
|
|
* 10 microseconds to get back to the correct segment. The errors are
|
|
|
|
* usually on the order of nanoseconds so it should be enough.
|
|
|
|
*/
|
|
|
|
GST_DEBUG_OBJECT (GST_ADAPTIVE_DEMUX_STREAM_PAD (demux_stream),
|
|
|
|
"Current position: %" GST_TIME_FORMAT ", updating to %"
|
|
|
|
GST_TIME_FORMAT, GST_TIME_ARGS (ts),
|
|
|
|
GST_TIME_ARGS (ts + (10 * GST_USECOND)));
|
|
|
|
ts += 10 * GST_USECOND;
|
2016-01-27 16:31:10 +00:00
|
|
|
gst_mpd_client_stream_seek (new_client, new_stream,
|
|
|
|
demux->segment.rate >= 0, 0, ts, NULL);
|
2014-04-25 11:50:18 +00:00
|
|
|
}
|
2015-05-11 17:19:20 +00:00
|
|
|
|
2014-11-29 13:26:31 +00:00
|
|
|
demux_stream->active_stream = new_stream;
|
2014-04-25 11:50:18 +00:00
|
|
|
}
|
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
gst_mpd_client_free (dashdemux->client);
|
|
|
|
dashdemux->client = new_client;
|
2014-08-29 10:38:12 +00:00
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
GST_DEBUG_OBJECT (demux, "Manifest file successfully updated");
|
2015-07-15 10:56:13 +00:00
|
|
|
if (dashdemux->clock_drift) {
|
|
|
|
gst_dash_demux_poll_clock_drift (dashdemux);
|
|
|
|
}
|
2014-04-25 11:50:18 +00:00
|
|
|
} else {
|
2014-08-26 19:45:46 +00:00
|
|
|
/* 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.");
|
2016-02-09 20:24:50 +00:00
|
|
|
gst_mpd_client_free (new_client);
|
2014-08-26 19:45:46 +00:00
|
|
|
gst_buffer_unmap (buffer, &mapinfo);
|
2014-12-02 10:06:00 +00:00
|
|
|
return GST_FLOW_ERROR;
|
2014-04-25 11:50:18 +00:00
|
|
|
}
|
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
gst_buffer_unmap (buffer, &mapinfo);
|
2014-08-29 10:38:12 +00:00
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
return GST_FLOW_OK;
|
2014-04-25 11:50:18 +00:00
|
|
|
}
|
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
static gint64
|
|
|
|
gst_dash_demux_stream_get_fragment_waiting_time (GstAdaptiveDemuxStream *
|
|
|
|
stream)
|
2013-12-03 03:12:08 +00:00
|
|
|
{
|
2014-08-26 19:45:46 +00:00
|
|
|
GstDashDemux *dashdemux = GST_DASH_DEMUX_CAST (stream->demux);
|
|
|
|
GstDashDemuxStream *dashstream = (GstDashDemuxStream *) stream;
|
2015-11-10 22:01:38 +00:00
|
|
|
GstDateTime *segmentAvailability;
|
2014-08-26 19:45:46 +00:00
|
|
|
GstActiveStream *active_stream = dashstream->active_stream;
|
2013-12-03 03:12:08 +00:00
|
|
|
|
2015-11-10 22:01:38 +00:00
|
|
|
segmentAvailability =
|
|
|
|
gst_mpd_client_get_next_segment_availability_start_time
|
|
|
|
(dashdemux->client, active_stream);
|
2013-12-03 03:12:08 +00:00
|
|
|
|
2015-11-10 22:01:38 +00:00
|
|
|
if (segmentAvailability) {
|
2014-08-26 19:45:46 +00:00
|
|
|
gint64 diff;
|
|
|
|
GstDateTime *cur_time;
|
2013-12-03 03:12:08 +00:00
|
|
|
|
2016-02-16 14:44:10 +00:00
|
|
|
cur_time =
|
|
|
|
gst_date_time_new_from_g_date_time
|
|
|
|
(gst_adaptive_demux_get_client_now_utc (GST_ADAPTIVE_DEMUX_CAST
|
|
|
|
(dashdemux)));
|
|
|
|
diff =
|
|
|
|
gst_mpd_client_calculate_time_difference (cur_time,
|
2015-11-10 22:01:38 +00:00
|
|
|
segmentAvailability);
|
|
|
|
gst_date_time_unref (segmentAvailability);
|
2014-08-26 19:45:46 +00:00
|
|
|
gst_date_time_unref (cur_time);
|
2015-07-15 10:56:13 +00:00
|
|
|
/* subtract the server's clock drift, so that if the server's
|
|
|
|
time is behind our idea of UTC, we need to sleep for longer
|
|
|
|
before requesting a fragment */
|
2015-12-16 10:23:23 +00:00
|
|
|
return diff -
|
|
|
|
gst_dash_demux_get_clock_compensation (dashdemux) * GST_USECOND;
|
2013-12-03 03:12:08 +00:00
|
|
|
}
|
2014-08-26 19:45:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2014-04-25 11:50:18 +00:00
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
static gboolean
|
|
|
|
gst_dash_demux_has_next_period (GstAdaptiveDemux * demux)
|
|
|
|
{
|
|
|
|
GstDashDemux *dashdemux = GST_DASH_DEMUX_CAST (demux);
|
2014-04-25 11:50:18 +00:00
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
if (demux->segment.rate >= 0)
|
|
|
|
return gst_mpd_client_has_next_period (dashdemux->client);
|
2014-05-02 21:34:04 +00:00
|
|
|
else
|
2014-08-26 19:45:46 +00:00
|
|
|
return gst_mpd_client_has_previous_period (dashdemux->client);
|
2013-12-03 03:12:08 +00:00
|
|
|
}
|
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
static void
|
|
|
|
gst_dash_demux_advance_period (GstAdaptiveDemux * demux)
|
2013-05-08 14:13:32 +00:00
|
|
|
{
|
2014-08-26 19:45:46 +00:00
|
|
|
GstDashDemux *dashdemux = GST_DASH_DEMUX_CAST (demux);
|
2013-01-29 18:58:50 +00:00
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
g_return_if_fail (gst_mpd_client_has_next_period (dashdemux->client));
|
2013-02-22 19:40:36 +00:00
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
if (demux->segment.rate >= 0) {
|
|
|
|
if (!gst_mpd_client_set_period_index (dashdemux->client,
|
|
|
|
gst_mpd_client_get_period_index (dashdemux->client) + 1)) {
|
|
|
|
/* TODO error */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!gst_mpd_client_set_period_index (dashdemux->client,
|
|
|
|
gst_mpd_client_get_period_index (dashdemux->client) - 1)) {
|
|
|
|
/* TODO error */
|
|
|
|
return;
|
2013-12-03 19:16:09 +00:00
|
|
|
}
|
2013-12-20 13:05:22 +00:00
|
|
|
}
|
2013-07-09 02:24:28 +00:00
|
|
|
|
2014-08-26 19:45:46 +00:00
|
|
|
gst_dash_demux_setup_all_streams (dashdemux);
|
2015-05-08 19:31:44 +00:00
|
|
|
gst_mpd_client_seek_to_first_segment (dashdemux->client);
|
2013-07-09 02:24:28 +00:00
|
|
|
}
|
2015-01-12 14:57:02 +00:00
|
|
|
|
2015-01-12 20:40:47 +00:00
|
|
|
static GstBuffer *
|
2015-01-15 20:44:45 +00:00
|
|
|
_gst_buffer_split (GstBuffer * buffer, gint offset, gsize size)
|
2015-01-12 20:40:47 +00:00
|
|
|
{
|
2015-01-15 20:44:45 +00:00
|
|
|
GstBuffer *newbuf = gst_buffer_copy_region (buffer,
|
2015-01-12 20:40:47 +00:00
|
|
|
GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS | GST_BUFFER_COPY_META
|
2015-05-29 12:01:29 +00:00
|
|
|
| GST_BUFFER_COPY_MEMORY, offset, size == -1 ? size : size - offset);
|
2015-01-12 20:40:47 +00:00
|
|
|
|
2015-01-15 20:44:45 +00:00
|
|
|
gst_buffer_resize (buffer, 0, offset);
|
2015-01-12 20:40:47 +00:00
|
|
|
|
|
|
|
return newbuf;
|
|
|
|
}
|
|
|
|
|
2016-03-31 10:39:59 +00:00
|
|
|
static gboolean
|
|
|
|
gst_dash_demux_stream_fragment_start (GstAdaptiveDemux * demux,
|
|
|
|
GstAdaptiveDemuxStream * stream)
|
|
|
|
{
|
2016-06-01 11:02:11 +00:00
|
|
|
GstDashDemux *dashdemux = GST_DASH_DEMUX_CAST (demux);
|
2016-03-31 10:39:59 +00:00
|
|
|
GstDashDemuxStream *dashstream = (GstDashDemuxStream *) stream;
|
|
|
|
|
|
|
|
dashstream->sidx_index_header_or_data = 0;
|
|
|
|
dashstream->sidx_current_offset = -1;
|
|
|
|
|
2016-03-28 10:45:36 +00:00
|
|
|
dashstream->isobmff_parser.index_header_or_data = 0;
|
2016-05-30 09:09:34 +00:00
|
|
|
dashstream->isobmff_parser.current_offset = -1;
|
|
|
|
|
2016-06-01 11:02:11 +00:00
|
|
|
/* We need to mark every first buffer of a key unit as discont,
|
|
|
|
* and also every first buffer of a moov and moof. This ensures
|
|
|
|
* that qtdemux takes note of our buffer offsets for each of those
|
|
|
|
* buffers instead of keeping track of them itself from the first
|
|
|
|
* buffer. We need offsets to be consistent between moof and mdat
|
|
|
|
*/
|
|
|
|
if (dashstream->is_isobmff && dashdemux->allow_trickmode_key_units
|
|
|
|
&& (demux->segment.flags & GST_SEGMENT_FLAG_TRICKMODE_KEY_UNITS)
|
|
|
|
&& dashstream->active_stream->mimeType == GST_STREAM_VIDEO)
|
2016-05-30 09:09:34 +00:00
|
|
|
stream->discont = TRUE;
|
2016-03-28 10:45:36 +00:00
|
|
|
|
2016-03-31 10:39:59 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-01-12 14:57:02 +00:00
|
|
|
static GstFlowReturn
|
2015-01-15 20:44:45 +00:00
|
|
|
gst_dash_demux_stream_fragment_finished (GstAdaptiveDemux * demux,
|
|
|
|
GstAdaptiveDemuxStream * stream)
|
2015-01-12 14:57:02 +00:00
|
|
|
{
|
2015-01-15 20:44:45 +00:00
|
|
|
GstDashDemux *dashdemux = GST_DASH_DEMUX_CAST (demux);
|
2015-02-16 02:16:52 +00:00
|
|
|
GstDashDemuxStream *dashstream = (GstDashDemuxStream *) stream;
|
2015-01-12 20:40:47 +00:00
|
|
|
|
2016-06-01 11:02:11 +00:00
|
|
|
/* We need to mark every first buffer of a key unit as discont,
|
|
|
|
* and also every first buffer of a moov and moof. This ensures
|
|
|
|
* that qtdemux takes note of our buffer offsets for each of those
|
|
|
|
* buffers instead of keeping track of them itself from the first
|
|
|
|
* buffer. We need offsets to be consistent between moof and mdat
|
|
|
|
*/
|
|
|
|
if (dashstream->is_isobmff && dashdemux->allow_trickmode_key_units
|
|
|
|
&& (demux->segment.flags & GST_SEGMENT_FLAG_TRICKMODE_KEY_UNITS)
|
|
|
|
&& dashstream->active_stream->mimeType == GST_STREAM_VIDEO)
|
2016-05-30 09:09:34 +00:00
|
|
|
stream->discont = TRUE;
|
|
|
|
|
2016-08-02 05:35:26 +00:00
|
|
|
/* Only handle fragment advancing specifically for SIDX if we're not
|
|
|
|
* in key unit mode */
|
|
|
|
if (!(dashstream->moof_sync_samples
|
|
|
|
&& GST_ADAPTIVE_DEMUX (dashdemux)->
|
|
|
|
segment.flags & GST_SEGMENT_FLAG_TRICKMODE_KEY_UNITS)
|
|
|
|
&& gst_mpd_client_has_isoff_ondemand_profile (dashdemux->client)
|
2016-05-30 09:09:34 +00:00
|
|
|
&& dashstream->sidx_parser.status == GST_ISOFF_SIDX_PARSER_FINISHED) {
|
2015-01-15 20:44:45 +00:00
|
|
|
/* fragment is advanced on data_received when byte limits are reached */
|
2015-09-15 12:58:20 +00:00
|
|
|
if (gst_dash_demux_stream_has_next_fragment (stream))
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
return GST_FLOW_EOS;
|
|
|
|
}
|
2015-08-21 15:13:43 +00:00
|
|
|
|
2015-07-08 10:32:58 +00:00
|
|
|
if (G_UNLIKELY (stream->downloading_header || stream->downloading_index))
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
|
|
|
|
return gst_adaptive_demux_stream_advance_fragment (demux, stream,
|
|
|
|
stream->fragment.duration);
|
2015-01-15 20:44:45 +00:00
|
|
|
}
|
2015-01-12 20:40:47 +00:00
|
|
|
|
2016-07-12 17:09:52 +00:00
|
|
|
static gboolean
|
|
|
|
gst_dash_demux_need_another_chunk (GstAdaptiveDemuxStream * stream)
|
|
|
|
{
|
2016-07-29 09:32:50 +00:00
|
|
|
GstDashDemux *dashdemux = (GstDashDemux *) stream->demux;
|
2016-07-12 17:09:52 +00:00
|
|
|
GstDashDemuxStream *dashstream = (GstDashDemuxStream *) stream;
|
|
|
|
|
|
|
|
/* We're chunked downloading for ISOBMFF in KEY_UNITS mode for the actual
|
|
|
|
* fragment until we parsed the moof and arrived at the mdat. 8192 is a
|
|
|
|
* random guess for the moof size
|
2016-08-02 05:35:26 +00:00
|
|
|
*/
|
2016-07-12 17:09:52 +00:00
|
|
|
if (dashstream->is_isobmff
|
|
|
|
&& (GST_ADAPTIVE_DEMUX (stream->demux)->
|
|
|
|
segment.flags & GST_SEGMENT_FLAG_TRICKMODE_KEY_UNITS)
|
|
|
|
&& dashstream->active_stream->mimeType == GST_STREAM_VIDEO
|
2016-07-29 09:32:50 +00:00
|
|
|
&& !stream->downloading_header && !stream->downloading_index
|
|
|
|
&& dashdemux->allow_trickmode_key_units) {
|
2016-07-12 17:09:52 +00:00
|
|
|
if (dashstream->isobmff_parser.current_fourcc != GST_ISOFF_FOURCC_MDAT) {
|
2016-08-02 05:35:26 +00:00
|
|
|
/* Need to download the moof first to know anything */
|
2016-08-02 05:47:55 +00:00
|
|
|
|
2016-07-12 17:09:52 +00:00
|
|
|
stream->fragment.chunk_size = 8192;
|
2016-08-02 05:47:55 +00:00
|
|
|
/* Do we have the first fourcc already or are we in the middle */
|
|
|
|
if (dashstream->isobmff_parser.current_fourcc == 0) {
|
|
|
|
stream->fragment.chunk_size += dashstream->moof_average_size;
|
|
|
|
if (dashstream->first_sync_sample_always_after_moof)
|
|
|
|
stream->fragment.chunk_size +=
|
|
|
|
dashstream->first_sync_sample_average_size;
|
|
|
|
}
|
|
|
|
|
2016-08-04 11:47:41 +00:00
|
|
|
if (gst_mpd_client_has_isoff_ondemand_profile (dashdemux->client) &&
|
|
|
|
dashstream->sidx_parser.sidx.entries) {
|
|
|
|
guint64 sidx_end_offset =
|
|
|
|
dashstream->sidx_base_offset +
|
|
|
|
SIDX_CURRENT_ENTRY (dashstream)->offset +
|
|
|
|
SIDX_CURRENT_ENTRY (dashstream)->size;
|
|
|
|
|
|
|
|
if (stream->fragment.chunk_size +
|
|
|
|
dashstream->isobmff_parser.current_offset > sidx_end_offset) {
|
|
|
|
stream->fragment.chunk_size =
|
|
|
|
sidx_end_offset - dashstream->isobmff_parser.current_offset;
|
|
|
|
}
|
|
|
|
}
|
2016-07-12 17:09:52 +00:00
|
|
|
} else if (dashstream->moof && dashstream->moof_sync_samples) {
|
2016-08-02 05:35:26 +00:00
|
|
|
/* Have the moof, either we're done now or we want to download the
|
|
|
|
* directly following sync sample */
|
|
|
|
if (dashstream->first_sync_sample_after_moof
|
|
|
|
&& dashstream->current_sync_sample == 0) {
|
|
|
|
GstDashStreamSyncSample *sync_sample =
|
|
|
|
&g_array_index (dashstream->moof_sync_samples,
|
|
|
|
GstDashStreamSyncSample, 0);
|
2016-08-04 11:47:41 +00:00
|
|
|
guint64 end_offset = sync_sample->end_offset + 1;
|
|
|
|
|
|
|
|
if (gst_mpd_client_has_isoff_ondemand_profile (dashdemux->client) &&
|
|
|
|
dashstream->sidx_parser.sidx.entries) {
|
|
|
|
guint64 sidx_end_offset =
|
|
|
|
dashstream->sidx_base_offset +
|
|
|
|
SIDX_CURRENT_ENTRY (dashstream)->offset +
|
|
|
|
SIDX_CURRENT_ENTRY (dashstream)->size;
|
|
|
|
|
|
|
|
if (end_offset > sidx_end_offset) {
|
|
|
|
end_offset = sidx_end_offset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dashstream->isobmff_parser.current_offset < end_offset) {
|
2016-08-02 05:35:26 +00:00
|
|
|
stream->fragment.chunk_size =
|
2016-08-04 11:47:41 +00:00
|
|
|
end_offset - dashstream->isobmff_parser.current_offset;
|
2016-08-02 05:35:26 +00:00
|
|
|
} else {
|
|
|
|
stream->fragment.chunk_size = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
stream->fragment.chunk_size = 0;
|
|
|
|
}
|
2016-07-12 17:09:52 +00:00
|
|
|
} else {
|
2016-08-02 05:35:26 +00:00
|
|
|
/* Have moof but can't do key-units mode, just download until the end */
|
2016-07-12 17:09:52 +00:00
|
|
|
stream->fragment.chunk_size = -1;
|
|
|
|
}
|
2016-07-29 09:32:50 +00:00
|
|
|
} else {
|
|
|
|
/* We might've decided that we can't allow key-unit only
|
|
|
|
* trickmodes while doing chunked downloading. In that case
|
|
|
|
* just download from here to the end now */
|
2016-08-02 05:47:55 +00:00
|
|
|
if (dashstream->moof
|
|
|
|
&& (GST_ADAPTIVE_DEMUX (stream->demux)->
|
|
|
|
segment.flags & GST_SEGMENT_FLAG_TRICKMODE_KEY_UNITS))
|
2016-07-29 09:32:50 +00:00
|
|
|
stream->fragment.chunk_size = -1;
|
|
|
|
else
|
|
|
|
stream->fragment.chunk_size = 0;
|
2016-07-12 17:09:52 +00:00
|
|
|
}
|
|
|
|
|
2016-07-29 09:32:50 +00:00
|
|
|
return stream->fragment.chunk_size != 0;
|
2016-07-12 17:09:52 +00:00
|
|
|
}
|
|
|
|
|
2016-03-28 10:45:36 +00:00
|
|
|
static GstBuffer *
|
|
|
|
gst_dash_demux_parse_isobmff (GstAdaptiveDemux * demux,
|
|
|
|
GstDashDemuxStream * dash_stream, GstBuffer * buffer)
|
|
|
|
{
|
|
|
|
GstAdaptiveDemuxStream *stream = (GstAdaptiveDemuxStream *) dash_stream;
|
|
|
|
gsize available;
|
|
|
|
guint index_header_or_data;
|
2016-04-07 18:33:51 +00:00
|
|
|
GstMapInfo map;
|
|
|
|
GstByteReader reader;
|
|
|
|
guint32 fourcc;
|
|
|
|
guint header_size;
|
|
|
|
guint64 size, buffer_offset;
|
|
|
|
|
|
|
|
/* This must not be called when we're in the mdat. We only look at the mdat
|
|
|
|
* header and then stop parsing the boxes as we're only interested in the
|
|
|
|
* metadata! Handling mdat is the job of the surrounding code, as well as
|
|
|
|
* stopping or starting the next fragment when mdat is over (=> sidx)
|
|
|
|
*/
|
|
|
|
g_assert (dash_stream->isobmff_parser.current_fourcc !=
|
|
|
|
GST_ISOFF_FOURCC_MDAT);
|
2016-03-28 10:45:36 +00:00
|
|
|
|
|
|
|
if (stream->downloading_index)
|
|
|
|
index_header_or_data = 1;
|
|
|
|
else if (stream->downloading_header)
|
|
|
|
index_header_or_data = 2;
|
|
|
|
else
|
|
|
|
index_header_or_data = 3;
|
|
|
|
|
|
|
|
if (dash_stream->isobmff_parser.index_header_or_data != index_header_or_data) {
|
|
|
|
/* Clear pending data */
|
|
|
|
if (gst_adapter_available (dash_stream->isobmff_adapter) != 0)
|
|
|
|
GST_ERROR_OBJECT (stream->pad,
|
|
|
|
"Had pending ISOBMFF data after switch between index/header/data");
|
|
|
|
gst_adapter_clear (dash_stream->isobmff_adapter);
|
|
|
|
dash_stream->isobmff_parser.current_fourcc = 0;
|
|
|
|
dash_stream->isobmff_parser.current_start_offset = 0;
|
|
|
|
dash_stream->isobmff_parser.current_offset = -1;
|
|
|
|
dash_stream->isobmff_parser.current_size = 0;
|
|
|
|
dash_stream->isobmff_parser.index_header_or_data = index_header_or_data;
|
|
|
|
}
|
|
|
|
|
2016-07-12 17:09:52 +00:00
|
|
|
if (dash_stream->isobmff_parser.current_offset == -1) {
|
2016-03-28 10:45:36 +00:00
|
|
|
dash_stream->isobmff_parser.current_offset =
|
|
|
|
GST_BUFFER_OFFSET_IS_VALID (buffer) ? GST_BUFFER_OFFSET (buffer) : 0;
|
2016-07-12 17:09:52 +00:00
|
|
|
}
|
2016-03-28 10:45:36 +00:00
|
|
|
|
|
|
|
gst_adapter_push (dash_stream->isobmff_adapter, buffer);
|
|
|
|
|
|
|
|
available = gst_adapter_available (dash_stream->isobmff_adapter);
|
|
|
|
buffer = gst_adapter_take_buffer (dash_stream->isobmff_adapter, available);
|
|
|
|
buffer_offset = dash_stream->isobmff_parser.current_offset;
|
|
|
|
|
2016-04-07 18:33:51 +00:00
|
|
|
/* Always at the start of a box here */
|
|
|
|
g_assert (dash_stream->isobmff_parser.current_size == 0);
|
|
|
|
|
|
|
|
/* At the start of a box => Parse it */
|
|
|
|
gst_buffer_map (buffer, &map, GST_MAP_READ);
|
|
|
|
gst_byte_reader_init (&reader, map.data, map.size);
|
|
|
|
|
|
|
|
/* While there are more boxes left to parse ... */
|
|
|
|
dash_stream->isobmff_parser.current_start_offset =
|
|
|
|
dash_stream->isobmff_parser.current_offset;
|
|
|
|
do {
|
2016-03-28 10:45:36 +00:00
|
|
|
dash_stream->isobmff_parser.current_fourcc = 0;
|
|
|
|
dash_stream->isobmff_parser.current_size = 0;
|
|
|
|
|
2016-04-07 18:33:51 +00:00
|
|
|
if (!gst_isoff_parse_box_header (&reader, &fourcc, NULL, &header_size,
|
|
|
|
&size)) {
|
|
|
|
break;
|
|
|
|
}
|
2016-03-28 10:45:36 +00:00
|
|
|
|
2016-04-07 18:33:51 +00:00
|
|
|
dash_stream->isobmff_parser.current_fourcc = fourcc;
|
|
|
|
if (size == 0) {
|
|
|
|
/* We assume this is mdat, anything else with "size until end"
|
|
|
|
* does not seem to make sense */
|
|
|
|
g_assert (dash_stream->isobmff_parser.current_fourcc ==
|
|
|
|
GST_ISOFF_FOURCC_MDAT);
|
|
|
|
dash_stream->isobmff_parser.current_size = -1;
|
|
|
|
break;
|
|
|
|
}
|
2016-03-28 10:45:36 +00:00
|
|
|
|
2016-04-07 18:33:51 +00:00
|
|
|
dash_stream->isobmff_parser.current_size = size;
|
2016-03-28 10:45:36 +00:00
|
|
|
|
2016-04-07 18:33:51 +00:00
|
|
|
/* Do we have the complete box or are at MDAT */
|
|
|
|
if (gst_byte_reader_get_remaining (&reader) < size - header_size ||
|
|
|
|
dash_stream->isobmff_parser.current_fourcc == GST_ISOFF_FOURCC_MDAT) {
|
|
|
|
/* Reset byte reader to the beginning of the box */
|
|
|
|
gst_byte_reader_set_pos (&reader,
|
|
|
|
gst_byte_reader_get_pos (&reader) - header_size);
|
|
|
|
break;
|
|
|
|
}
|
2016-03-28 10:45:36 +00:00
|
|
|
|
2016-04-07 18:33:51 +00:00
|
|
|
GST_LOG_OBJECT (stream->pad,
|
|
|
|
"box %" GST_FOURCC_FORMAT " at offset %" G_GUINT64_FORMAT " size %"
|
|
|
|
G_GUINT64_FORMAT, GST_FOURCC_ARGS (fourcc),
|
|
|
|
dash_stream->isobmff_parser.current_offset +
|
|
|
|
gst_byte_reader_get_pos (&reader) - header_size, size);
|
2016-03-28 10:45:36 +00:00
|
|
|
|
2016-04-07 18:33:51 +00:00
|
|
|
if (dash_stream->isobmff_parser.current_fourcc == GST_ISOFF_FOURCC_MOOF) {
|
|
|
|
GstByteReader sub_reader;
|
2016-03-28 10:45:36 +00:00
|
|
|
|
2016-05-30 08:15:03 +00:00
|
|
|
g_assert (dash_stream->moof == NULL);
|
|
|
|
g_assert (dash_stream->moof_sync_samples == NULL);
|
2016-04-07 18:33:51 +00:00
|
|
|
gst_byte_reader_get_sub_reader (&reader, &sub_reader, size - header_size);
|
2016-05-30 08:15:03 +00:00
|
|
|
dash_stream->moof = gst_isoff_moof_box_parse (&sub_reader);
|
|
|
|
dash_stream->moof_offset =
|
|
|
|
dash_stream->isobmff_parser.current_start_offset;
|
2016-08-02 05:35:26 +00:00
|
|
|
dash_stream->moof_size = size;
|
2016-05-30 09:09:34 +00:00
|
|
|
dash_stream->current_sync_sample = -1;
|
2016-08-02 05:47:55 +00:00
|
|
|
|
|
|
|
if (dash_stream->moof_average_size) {
|
|
|
|
if (dash_stream->moof_average_size < size)
|
|
|
|
dash_stream->moof_average_size =
|
|
|
|
(size * 3 + dash_stream->moof_average_size) / 4;
|
|
|
|
else
|
|
|
|
dash_stream->moof_average_size =
|
|
|
|
(size + dash_stream->moof_average_size + 3) / 4;
|
|
|
|
} else {
|
|
|
|
dash_stream->moof_average_size = size;
|
|
|
|
}
|
2016-03-28 10:45:36 +00:00
|
|
|
} else {
|
2016-04-07 18:33:51 +00:00
|
|
|
gst_byte_reader_skip (&reader, size - header_size);
|
|
|
|
}
|
2016-03-28 10:45:36 +00:00
|
|
|
|
2016-04-07 18:33:51 +00:00
|
|
|
dash_stream->isobmff_parser.current_fourcc = 0;
|
|
|
|
dash_stream->isobmff_parser.current_start_offset += size;
|
|
|
|
dash_stream->isobmff_parser.current_size = 0;
|
|
|
|
} while (gst_byte_reader_get_remaining (&reader) > 0);
|
|
|
|
|
|
|
|
gst_buffer_unmap (buffer, &map);
|
|
|
|
|
|
|
|
/* mdat? Push all we have and wait for it to be over */
|
|
|
|
if (dash_stream->isobmff_parser.current_fourcc == GST_ISOFF_FOURCC_MDAT) {
|
|
|
|
GstBuffer *pending;
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (stream->pad,
|
|
|
|
"box %" GST_FOURCC_FORMAT " at offset %" G_GUINT64_FORMAT " size %"
|
|
|
|
G_GUINT64_FORMAT, GST_FOURCC_ARGS (fourcc),
|
|
|
|
dash_stream->isobmff_parser.current_offset +
|
|
|
|
gst_byte_reader_get_pos (&reader) - header_size,
|
|
|
|
dash_stream->isobmff_parser.current_size);
|
|
|
|
|
|
|
|
/* At mdat. Move the start of the mdat to the adapter and have everything
|
|
|
|
* else be pushed. We parsed all header boxes at this point and are not
|
|
|
|
* supposed to be called again until the next moof */
|
|
|
|
pending = _gst_buffer_split (buffer, gst_byte_reader_get_pos (&reader), -1);
|
|
|
|
gst_adapter_push (dash_stream->isobmff_adapter, pending);
|
|
|
|
dash_stream->isobmff_parser.current_offset +=
|
|
|
|
gst_byte_reader_get_pos (&reader);
|
|
|
|
dash_stream->isobmff_parser.current_size = 0;
|
2016-03-28 10:45:36 +00:00
|
|
|
|
2016-04-07 18:33:51 +00:00
|
|
|
GST_BUFFER_OFFSET (buffer) = buffer_offset;
|
|
|
|
GST_BUFFER_OFFSET_END (buffer) =
|
|
|
|
buffer_offset + gst_buffer_get_size (buffer);
|
|
|
|
return buffer;
|
|
|
|
} else if (gst_byte_reader_get_pos (&reader) != 0) {
|
|
|
|
GstBuffer *pending;
|
|
|
|
|
|
|
|
/* Multiple complete boxes and no mdat? Push them and keep the remainder,
|
|
|
|
* which is the start of the next box if any remainder */
|
|
|
|
|
|
|
|
pending = _gst_buffer_split (buffer, gst_byte_reader_get_pos (&reader), -1);
|
|
|
|
gst_adapter_push (dash_stream->isobmff_adapter, pending);
|
|
|
|
dash_stream->isobmff_parser.current_offset +=
|
|
|
|
gst_byte_reader_get_pos (&reader);
|
|
|
|
dash_stream->isobmff_parser.current_size = 0;
|
2016-03-28 10:45:36 +00:00
|
|
|
|
2016-04-07 18:33:51 +00:00
|
|
|
GST_BUFFER_OFFSET (buffer) = buffer_offset;
|
|
|
|
GST_BUFFER_OFFSET_END (buffer) =
|
|
|
|
buffer_offset + gst_buffer_get_size (buffer);
|
|
|
|
return buffer;
|
2016-03-28 10:45:36 +00:00
|
|
|
}
|
|
|
|
|
2016-04-07 18:33:51 +00:00
|
|
|
/* Not even a single complete, non-mdat box, wait */
|
|
|
|
dash_stream->isobmff_parser.current_size = 0;
|
|
|
|
gst_adapter_push (dash_stream->isobmff_adapter, buffer);
|
2016-03-28 10:45:36 +00:00
|
|
|
|
2016-04-07 18:33:51 +00:00
|
|
|
return NULL;
|
2016-03-28 10:45:36 +00:00
|
|
|
}
|
|
|
|
|
2016-05-30 08:15:03 +00:00
|
|
|
static gboolean
|
|
|
|
gst_dash_demux_find_sync_samples (GstAdaptiveDemux * demux,
|
|
|
|
GstAdaptiveDemuxStream * stream)
|
|
|
|
{
|
2016-07-29 09:32:50 +00:00
|
|
|
GstDashDemux *dashdemux = (GstDashDemux *) stream->demux;
|
2016-05-30 08:15:03 +00:00
|
|
|
GstDashDemuxStream *dash_stream = (GstDashDemuxStream *) stream;
|
|
|
|
guint i;
|
|
|
|
guint32 track_id = 0;
|
|
|
|
guint64 prev_traf_end;
|
2016-07-29 08:54:21 +00:00
|
|
|
gboolean trex_sample_flags = FALSE;
|
2016-05-30 08:15:03 +00:00
|
|
|
|
2016-07-29 09:32:50 +00:00
|
|
|
if (!dash_stream->moof) {
|
|
|
|
dashdemux->allow_trickmode_key_units = FALSE;
|
2016-05-30 08:15:03 +00:00
|
|
|
return FALSE;
|
2016-07-29 09:32:50 +00:00
|
|
|
}
|
2016-05-30 08:15:03 +00:00
|
|
|
|
2016-05-30 09:09:34 +00:00
|
|
|
dash_stream->current_sync_sample = -1;
|
2016-05-30 08:15:03 +00:00
|
|
|
dash_stream->moof_sync_samples =
|
|
|
|
g_array_new (FALSE, FALSE, sizeof (GstDashStreamSyncSample));
|
|
|
|
|
|
|
|
prev_traf_end = dash_stream->moof_offset;
|
|
|
|
|
|
|
|
/* generate table of keyframes and offsets */
|
|
|
|
for (i = 0; i < dash_stream->moof->traf->len; i++) {
|
|
|
|
GstTrafBox *traf = &g_array_index (dash_stream->moof->traf, GstTrafBox, i);
|
|
|
|
guint64 traf_offset = 0, prev_trun_end;
|
|
|
|
guint j;
|
|
|
|
|
|
|
|
if (i == 0) {
|
|
|
|
track_id = traf->tfhd.track_id;
|
|
|
|
} else if (track_id != traf->tfhd.track_id) {
|
|
|
|
GST_ERROR_OBJECT (stream->pad,
|
|
|
|
"moof with trafs of different track ids (%u != %u)", track_id,
|
|
|
|
traf->tfhd.track_id);
|
|
|
|
g_array_free (dash_stream->moof_sync_samples, TRUE);
|
|
|
|
dash_stream->moof_sync_samples = NULL;
|
2016-07-29 09:32:50 +00:00
|
|
|
dashdemux->allow_trickmode_key_units = FALSE;
|
2016-05-30 08:15:03 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (traf->tfhd.flags & GST_TFHD_FLAGS_BASE_DATA_OFFSET_PRESENT) {
|
|
|
|
traf_offset = traf->tfhd.base_data_offset;
|
|
|
|
} else if (traf->tfhd.flags & GST_TFHD_FLAGS_DEFAULT_BASE_IS_MOOF) {
|
|
|
|
traf_offset = dash_stream->moof_offset;
|
|
|
|
} else {
|
|
|
|
traf_offset = prev_traf_end;
|
|
|
|
}
|
|
|
|
|
|
|
|
prev_trun_end = traf_offset;
|
|
|
|
|
|
|
|
for (j = 0; j < traf->trun->len; j++) {
|
|
|
|
GstTrunBox *trun = &g_array_index (traf->trun, GstTrunBox, j);
|
|
|
|
guint64 trun_offset, prev_sample_end;
|
|
|
|
guint k;
|
|
|
|
|
|
|
|
if (trun->flags & GST_TRUN_FLAGS_DATA_OFFSET_PRESENT) {
|
|
|
|
trun_offset = traf_offset + trun->data_offset;
|
|
|
|
} else {
|
|
|
|
trun_offset = prev_trun_end;
|
|
|
|
}
|
|
|
|
|
|
|
|
prev_sample_end = trun_offset;
|
|
|
|
for (k = 0; k < trun->samples->len; k++) {
|
|
|
|
GstTrunSample *sample =
|
|
|
|
&g_array_index (trun->samples, GstTrunSample, k);
|
|
|
|
guint64 sample_offset;
|
|
|
|
guint32 sample_flags;
|
|
|
|
#if 0
|
|
|
|
guint32 sample_duration;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
sample_offset = prev_sample_end;
|
|
|
|
|
|
|
|
if (trun->flags & GST_TRUN_FLAGS_SAMPLE_FLAGS_PRESENT) {
|
|
|
|
sample_flags = sample->sample_flags;
|
|
|
|
} else if ((trun->flags & GST_TRUN_FLAGS_FIRST_SAMPLE_FLAGS_PRESENT)
|
|
|
|
&& k == 0) {
|
|
|
|
sample_flags = trun->first_sample_flags;
|
|
|
|
} else if (traf->
|
|
|
|
tfhd.flags & GST_TFHD_FLAGS_DEFAULT_SAMPLE_FLAGS_PRESENT) {
|
|
|
|
sample_flags = traf->tfhd.default_sample_flags;
|
|
|
|
} else {
|
2016-07-29 08:54:21 +00:00
|
|
|
trex_sample_flags = TRUE;
|
|
|
|
continue;
|
2016-05-30 08:15:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
if (trun->flags & GST_TRUN_FLAGS_SAMPLE_DURATION_PRESENT) {
|
|
|
|
sample_duration = sample->sample_duration;
|
|
|
|
} else if (traf->
|
|
|
|
tfhd.flags & GST_TFHD_FLAGS_DEFAULT_SAMPLE_DURATION_PRESENT) {
|
|
|
|
sample_duration = traf->tfhd.default_sample_duration;
|
|
|
|
} else {
|
2016-05-30 09:09:34 +00:00
|
|
|
GST_FIXME_OBJECT (stream->pad,
|
|
|
|
"Sample duration given by trex - can't download only keyframes");
|
2016-05-30 08:15:03 +00:00
|
|
|
g_array_free (dash_stream->moof_sync_samples, TRUE);
|
|
|
|
dash_stream->moof_sync_samples = NULL;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (trun->flags & GST_TRUN_FLAGS_SAMPLE_SIZE_PRESENT) {
|
|
|
|
prev_sample_end += sample->sample_size;
|
|
|
|
} else if (traf->
|
|
|
|
tfhd.flags & GST_TFHD_FLAGS_DEFAULT_SAMPLE_SIZE_PRESENT) {
|
|
|
|
prev_sample_end += traf->tfhd.default_sample_size;
|
|
|
|
} else {
|
2016-05-30 09:09:34 +00:00
|
|
|
GST_FIXME_OBJECT (stream->pad,
|
|
|
|
"Sample size given by trex - can't download only keyframes");
|
2016-05-30 08:15:03 +00:00
|
|
|
g_array_free (dash_stream->moof_sync_samples, TRUE);
|
|
|
|
dash_stream->moof_sync_samples = NULL;
|
2016-07-29 09:32:50 +00:00
|
|
|
dashdemux->allow_trickmode_key_units = FALSE;
|
2016-05-30 08:15:03 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Non-non-sync sample aka sync sample */
|
2016-08-18 10:21:54 +00:00
|
|
|
if (!GST_ISOFF_SAMPLE_FLAGS_SAMPLE_IS_NON_SYNC_SAMPLE (sample_flags) ||
|
|
|
|
GST_ISOFF_SAMPLE_FLAGS_SAMPLE_DEPENDS_ON (sample_flags) == 2) {
|
2016-05-30 08:15:03 +00:00
|
|
|
GstDashStreamSyncSample sync_sample =
|
|
|
|
{ sample_offset, prev_sample_end - 1 };
|
|
|
|
/* TODO: need timestamps so we can decide to download or not */
|
|
|
|
g_array_append_val (dash_stream->moof_sync_samples, sync_sample);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
prev_trun_end = prev_sample_end;
|
|
|
|
}
|
|
|
|
|
|
|
|
prev_traf_end = prev_trun_end;
|
|
|
|
}
|
|
|
|
|
2016-07-29 08:54:21 +00:00
|
|
|
if (trex_sample_flags) {
|
|
|
|
if (dash_stream->moof_sync_samples->len > 0) {
|
|
|
|
GST_LOG_OBJECT (stream->pad,
|
|
|
|
"Some sample flags given by trex but still found sync samples");
|
|
|
|
} else {
|
|
|
|
GST_FIXME_OBJECT (stream->pad,
|
|
|
|
"Sample flags given by trex - can't download only keyframes");
|
|
|
|
g_array_free (dash_stream->moof_sync_samples, TRUE);
|
|
|
|
dash_stream->moof_sync_samples = NULL;
|
2016-07-29 09:32:50 +00:00
|
|
|
dashdemux->allow_trickmode_key_units = FALSE;
|
2016-07-29 08:54:21 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-29 09:50:58 +00:00
|
|
|
if (dash_stream->moof_sync_samples->len == 0) {
|
|
|
|
GST_LOG_OBJECT (stream->pad, "No sync samples found in fragment");
|
|
|
|
g_array_free (dash_stream->moof_sync_samples, TRUE);
|
|
|
|
dash_stream->moof_sync_samples = NULL;
|
|
|
|
dashdemux->allow_trickmode_key_units = FALSE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2016-08-02 05:35:26 +00:00
|
|
|
{
|
|
|
|
GstDashStreamSyncSample *sync_sample =
|
|
|
|
&g_array_index (dash_stream->moof_sync_samples, GstDashStreamSyncSample,
|
|
|
|
0);
|
2016-08-02 05:47:55 +00:00
|
|
|
guint size = sync_sample->end_offset + 1 - sync_sample->start_offset;
|
|
|
|
|
|
|
|
if (dash_stream->first_sync_sample_average_size) {
|
|
|
|
if (dash_stream->first_sync_sample_average_size < size)
|
|
|
|
dash_stream->first_sync_sample_average_size =
|
|
|
|
(size * 3 + dash_stream->first_sync_sample_average_size) / 4;
|
|
|
|
else
|
|
|
|
dash_stream->first_sync_sample_average_size =
|
|
|
|
(size + dash_stream->first_sync_sample_average_size * 3) / 4;
|
|
|
|
} else {
|
|
|
|
dash_stream->first_sync_sample_average_size = size;
|
|
|
|
}
|
2016-08-02 05:35:26 +00:00
|
|
|
|
|
|
|
if (dash_stream->moof_offset + dash_stream->moof_size + 8 <
|
|
|
|
sync_sample->start_offset) {
|
|
|
|
dash_stream->first_sync_sample_after_moof = FALSE;
|
|
|
|
dash_stream->first_sync_sample_always_after_moof = FALSE;
|
|
|
|
} else {
|
2016-08-18 10:21:54 +00:00
|
|
|
dash_stream->first_sync_sample_after_moof =
|
|
|
|
(dash_stream->moof_sync_samples->len == 1
|
|
|
|
|| demux->segment.rate > 0.0);
|
2016-08-02 05:35:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-30 08:15:03 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2016-08-02 05:35:26 +00:00
|
|
|
|
2015-01-15 20:44:45 +00:00
|
|
|
static GstFlowReturn
|
2016-08-02 05:35:26 +00:00
|
|
|
gst_dash_demux_handle_isobmff_buffer (GstAdaptiveDemux * demux,
|
2016-03-28 10:45:36 +00:00
|
|
|
GstAdaptiveDemuxStream * stream, GstBuffer * buffer)
|
2015-01-15 20:44:45 +00:00
|
|
|
{
|
|
|
|
GstDashDemuxStream *dash_stream = (GstDashDemuxStream *) stream;
|
2015-08-21 15:13:43 +00:00
|
|
|
GstDashDemux *dashdemux = GST_DASH_DEMUX_CAST (demux);
|
2015-01-15 20:44:45 +00:00
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
2015-01-12 20:40:47 +00:00
|
|
|
|
2016-08-02 05:35:26 +00:00
|
|
|
if (dashdemux->allow_trickmode_key_units) {
|
|
|
|
if (dash_stream->isobmff_parser.current_fourcc != GST_ISOFF_FOURCC_MDAT) {
|
|
|
|
buffer = gst_dash_demux_parse_isobmff (demux, dash_stream, buffer);
|
2016-05-30 09:09:34 +00:00
|
|
|
|
2016-08-02 05:35:26 +00:00
|
|
|
if (buffer
|
|
|
|
&& (ret =
|
|
|
|
gst_adaptive_demux_stream_push_buffer (stream,
|
|
|
|
buffer)) != GST_FLOW_OK)
|
|
|
|
return ret;
|
|
|
|
if (dash_stream->isobmff_parser.current_fourcc != GST_ISOFF_FOURCC_MDAT)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* Jump to the next sync sample. As we're doing chunked downloading
|
|
|
|
* here, just drop data until our chunk is over so we can reuse the
|
|
|
|
* HTTP connection instead of having to create a new one or
|
|
|
|
* reuse the data if the sync sample follows the moof */
|
|
|
|
if (dash_stream->active_stream->mimeType == GST_STREAM_VIDEO
|
|
|
|
&& gst_dash_demux_find_sync_samples (demux, stream) &&
|
|
|
|
GST_ADAPTIVE_DEMUX (stream->demux)->
|
|
|
|
segment.flags & GST_SEGMENT_FLAG_TRICKMODE_KEY_UNITS) {
|
|
|
|
|
|
|
|
if (dash_stream->first_sync_sample_after_moof) {
|
|
|
|
/* If we're here, don't throw away data but collect sync
|
|
|
|
* sample while we're at it below. We're doing chunked
|
|
|
|
* downloading so might need to adjust the next chunk size for
|
|
|
|
* the remainder */
|
|
|
|
dash_stream->current_sync_sample = 0;
|
|
|
|
} else {
|
|
|
|
gst_adapter_clear (dash_stream->isobmff_adapter);
|
2016-04-07 18:33:51 +00:00
|
|
|
}
|
2016-08-02 05:35:26 +00:00
|
|
|
}
|
2016-04-07 18:33:51 +00:00
|
|
|
|
2016-08-02 05:35:26 +00:00
|
|
|
if (gst_adapter_available (dash_stream->isobmff_adapter) == 0)
|
2016-04-07 18:33:51 +00:00
|
|
|
return ret;
|
2016-08-02 05:35:26 +00:00
|
|
|
|
|
|
|
/* We have some data from the mdat available in the adapter, handle it
|
|
|
|
* below in the push code */
|
|
|
|
buffer =
|
|
|
|
gst_adapter_take_buffer (dash_stream->isobmff_adapter,
|
|
|
|
gst_adapter_available (dash_stream->isobmff_adapter));
|
|
|
|
} else {
|
|
|
|
if (dash_stream->isobmff_parser.current_offset == -1) {
|
|
|
|
dash_stream->isobmff_parser.current_offset =
|
|
|
|
GST_BUFFER_OFFSET_IS_VALID (buffer) ? GST_BUFFER_OFFSET (buffer) :
|
|
|
|
0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* At mdat and isobmff and trick modes are allowed */
|
|
|
|
|
|
|
|
/* We're actually running in key-units trick mode */
|
|
|
|
if (dash_stream->active_stream->mimeType == GST_STREAM_VIDEO
|
|
|
|
&& dash_stream->moof_sync_samples
|
|
|
|
&& GST_ADAPTIVE_DEMUX (stream->demux)->
|
|
|
|
segment.flags & GST_SEGMENT_FLAG_TRICKMODE_KEY_UNITS) {
|
|
|
|
|
|
|
|
if (dash_stream->current_sync_sample == -1) {
|
2016-07-12 17:09:52 +00:00
|
|
|
/* We're doing chunked downloading and wait for finishing the current
|
|
|
|
* chunk so we can jump to the first keyframe */
|
|
|
|
gst_buffer_unref (buffer);
|
|
|
|
return GST_FLOW_OK;
|
2016-08-02 05:35:26 +00:00
|
|
|
} else if (dash_stream->first_sync_sample_after_moof
|
|
|
|
&& dash_stream->current_sync_sample == 0) {
|
|
|
|
GstDashStreamSyncSample *sync_sample =
|
|
|
|
&g_array_index (dash_stream->moof_sync_samples,
|
|
|
|
GstDashStreamSyncSample, 0);
|
|
|
|
guint64 end_offset =
|
|
|
|
dash_stream->isobmff_parser.current_offset +
|
|
|
|
gst_buffer_get_size (buffer);
|
|
|
|
|
|
|
|
/* If the first keyframe follows directly the moof and we're
|
|
|
|
* downloading it here, make sure to not download too much */
|
|
|
|
|
|
|
|
if (end_offset > sync_sample->end_offset + 1) {
|
|
|
|
guint64 remaining =
|
|
|
|
sync_sample->end_offset + 1 -
|
|
|
|
dash_stream->isobmff_parser.current_offset;
|
|
|
|
|
|
|
|
if (remaining) {
|
|
|
|
GstBuffer *sub =
|
|
|
|
gst_buffer_copy_region (buffer, GST_BUFFER_COPY_ALL, 0,
|
|
|
|
remaining);
|
|
|
|
gst_buffer_unref (buffer);
|
|
|
|
buffer = sub;
|
|
|
|
} else {
|
|
|
|
gst_buffer_unref (buffer);
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
}
|
2016-04-07 18:33:51 +00:00
|
|
|
}
|
2016-03-28 10:45:36 +00:00
|
|
|
}
|
|
|
|
|
2016-08-02 05:35:26 +00:00
|
|
|
GST_BUFFER_OFFSET (buffer) = dash_stream->isobmff_parser.current_offset;
|
|
|
|
dash_stream->isobmff_parser.current_offset += gst_buffer_get_size (buffer);
|
|
|
|
GST_BUFFER_OFFSET_END (buffer) = dash_stream->isobmff_parser.current_offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
return gst_adaptive_demux_stream_push_buffer (stream, buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_dash_demux_data_received (GstAdaptiveDemux * demux,
|
|
|
|
GstAdaptiveDemuxStream * stream, GstBuffer * buffer)
|
|
|
|
{
|
|
|
|
GstDashDemuxStream *dash_stream = (GstDashDemuxStream *) stream;
|
|
|
|
GstDashDemux *dashdemux = GST_DASH_DEMUX_CAST (demux);
|
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
|
|
|
guint index_header_or_data;
|
|
|
|
|
|
|
|
if (!gst_mpd_client_has_isoff_ondemand_profile (dashdemux->client)) {
|
|
|
|
if (dash_stream->is_isobmff)
|
|
|
|
return gst_dash_demux_handle_isobmff_buffer (demux, stream, buffer);
|
|
|
|
else
|
|
|
|
return gst_adaptive_demux_stream_push_buffer (stream, buffer);
|
2016-03-28 10:45:36 +00:00
|
|
|
}
|
2016-03-28 10:45:36 +00:00
|
|
|
|
2016-03-31 10:39:59 +00:00
|
|
|
if (stream->downloading_index)
|
|
|
|
index_header_or_data = 1;
|
|
|
|
else if (stream->downloading_header)
|
|
|
|
index_header_or_data = 2;
|
|
|
|
else
|
|
|
|
index_header_or_data = 3;
|
|
|
|
|
|
|
|
if (dash_stream->sidx_index_header_or_data != index_header_or_data) {
|
|
|
|
/* Clear pending data */
|
|
|
|
if (gst_adapter_available (dash_stream->sidx_adapter) != 0)
|
|
|
|
GST_ERROR_OBJECT (stream->pad,
|
|
|
|
"Had pending SIDX data after switch between index/header/data");
|
|
|
|
gst_adapter_clear (dash_stream->sidx_adapter);
|
|
|
|
dash_stream->sidx_index_header_or_data = index_header_or_data;
|
|
|
|
dash_stream->sidx_current_offset = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dash_stream->sidx_current_offset == -1)
|
|
|
|
dash_stream->sidx_current_offset =
|
|
|
|
GST_BUFFER_OFFSET_IS_VALID (buffer) ? GST_BUFFER_OFFSET (buffer) : 0;
|
|
|
|
|
2016-03-28 10:45:36 +00:00
|
|
|
gst_adapter_push (dash_stream->sidx_adapter, buffer);
|
|
|
|
buffer = NULL;
|
2015-08-21 15:13:43 +00:00
|
|
|
|
2015-01-15 20:44:45 +00:00
|
|
|
if (stream->downloading_index) {
|
2015-01-12 20:40:47 +00:00
|
|
|
GstIsoffParserResult res;
|
|
|
|
guint consumed;
|
2016-03-28 10:45:36 +00:00
|
|
|
gsize available;
|
2015-01-12 20:40:47 +00:00
|
|
|
|
2016-03-28 10:45:36 +00:00
|
|
|
available = gst_adapter_available (dash_stream->sidx_adapter);
|
|
|
|
buffer = gst_adapter_take_buffer (dash_stream->sidx_adapter, available);
|
2015-01-12 20:40:47 +00:00
|
|
|
|
2015-01-15 20:44:45 +00:00
|
|
|
if (dash_stream->sidx_parser.status != GST_ISOFF_SIDX_PARSER_FINISHED) {
|
|
|
|
res =
|
|
|
|
gst_isoff_sidx_parser_add_buffer (&dash_stream->sidx_parser, buffer,
|
|
|
|
&consumed);
|
|
|
|
|
|
|
|
if (res == GST_ISOFF_PARSER_ERROR) {
|
|
|
|
} else if (res == GST_ISOFF_PARSER_UNEXPECTED) {
|
|
|
|
/* this is not a 'sidx' index, just skip it and continue playback */
|
|
|
|
} else {
|
|
|
|
/* when finished, prepare for real data streaming */
|
|
|
|
if (dash_stream->sidx_parser.status == GST_ISOFF_SIDX_PARSER_FINISHED) {
|
|
|
|
if (GST_CLOCK_TIME_IS_VALID (dash_stream->pending_seek_ts)) {
|
2016-01-27 16:31:10 +00:00
|
|
|
/* FIXME, preserve seek flags */
|
2016-02-01 13:49:23 +00:00
|
|
|
gst_dash_demux_stream_sidx_seek (dash_stream,
|
|
|
|
demux->segment.rate >= 0, 0, dash_stream->pending_seek_ts,
|
|
|
|
NULL);
|
2015-01-15 20:44:45 +00:00
|
|
|
dash_stream->pending_seek_ts = GST_CLOCK_TIME_NONE;
|
|
|
|
} else {
|
|
|
|
SIDX (dash_stream)->entry_index = dash_stream->sidx_index;
|
|
|
|
}
|
|
|
|
} else if (consumed < available) {
|
|
|
|
GstBuffer *pending;
|
|
|
|
/* we still need to keep some data around for the next parsing round
|
|
|
|
* so just push what was already processed by the parser */
|
|
|
|
pending = _gst_buffer_split (buffer, consumed, -1);
|
2016-03-28 10:45:36 +00:00
|
|
|
gst_adapter_push (dash_stream->sidx_adapter, pending);
|
2015-01-12 20:40:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-03-31 10:39:59 +00:00
|
|
|
GST_BUFFER_OFFSET (buffer) = dash_stream->sidx_current_offset;
|
|
|
|
GST_BUFFER_OFFSET_END (buffer) =
|
|
|
|
GST_BUFFER_OFFSET (buffer) + gst_buffer_get_size (buffer);
|
|
|
|
dash_stream->sidx_current_offset = GST_BUFFER_OFFSET_END (buffer);
|
2015-01-15 20:44:45 +00:00
|
|
|
ret = gst_adaptive_demux_stream_push_buffer (stream, buffer);
|
|
|
|
} else if (dash_stream->sidx_parser.status == GST_ISOFF_SIDX_PARSER_FINISHED) {
|
2016-03-28 10:45:36 +00:00
|
|
|
gsize available;
|
2015-01-12 20:40:47 +00:00
|
|
|
|
2015-01-15 20:44:45 +00:00
|
|
|
while (ret == GST_FLOW_OK
|
2016-03-31 10:39:59 +00:00
|
|
|
&& ((available =
|
|
|
|
gst_adapter_available (dash_stream->sidx_adapter)) > 0)) {
|
2015-01-15 20:44:45 +00:00
|
|
|
gboolean advance = FALSE;
|
2016-05-27 13:08:09 +00:00
|
|
|
guint64 sidx_end_offset =
|
|
|
|
dash_stream->sidx_base_offset +
|
|
|
|
SIDX_CURRENT_ENTRY (dash_stream)->offset +
|
|
|
|
SIDX_CURRENT_ENTRY (dash_stream)->size;
|
2015-01-12 20:40:47 +00:00
|
|
|
|
2016-05-27 13:08:09 +00:00
|
|
|
if (dash_stream->sidx_current_offset + available < sidx_end_offset) {
|
2016-03-28 10:45:36 +00:00
|
|
|
buffer = gst_adapter_take_buffer (dash_stream->sidx_adapter, available);
|
2015-01-15 20:44:45 +00:00
|
|
|
} else {
|
2016-08-02 05:35:26 +00:00
|
|
|
/* In key-units mode, we advance the fragments manually once the
|
|
|
|
* current key-unit is over but throw away all data that is after
|
|
|
|
* the current sidx entry end */
|
|
|
|
if (dash_stream->moof_sync_samples
|
|
|
|
&& (GST_ADAPTIVE_DEMUX (stream->demux)->
|
|
|
|
segment.flags & GST_SEGMENT_FLAG_TRICKMODE_KEY_UNITS)) {
|
|
|
|
if (sidx_end_offset <= dash_stream->sidx_current_offset) {
|
|
|
|
buffer = NULL;
|
|
|
|
gst_adapter_clear (dash_stream->sidx_adapter);
|
|
|
|
} else {
|
|
|
|
buffer =
|
|
|
|
gst_adapter_take_buffer (dash_stream->sidx_adapter,
|
|
|
|
sidx_end_offset - dash_stream->sidx_current_offset);
|
2016-04-07 18:33:51 +00:00
|
|
|
}
|
2016-08-02 05:35:26 +00:00
|
|
|
} else {
|
|
|
|
buffer =
|
|
|
|
gst_adapter_take_buffer (dash_stream->sidx_adapter,
|
|
|
|
sidx_end_offset - dash_stream->sidx_current_offset);
|
|
|
|
advance = TRUE;
|
2016-04-07 18:33:51 +00:00
|
|
|
}
|
2016-03-28 10:45:36 +00:00
|
|
|
}
|
|
|
|
|
2016-08-02 05:35:26 +00:00
|
|
|
if (buffer != NULL) {
|
|
|
|
GST_BUFFER_OFFSET (buffer) = dash_stream->sidx_current_offset;
|
|
|
|
GST_BUFFER_OFFSET_END (buffer) =
|
|
|
|
GST_BUFFER_OFFSET (buffer) + gst_buffer_get_size (buffer);
|
|
|
|
dash_stream->sidx_current_offset = GST_BUFFER_OFFSET_END (buffer);
|
|
|
|
|
|
|
|
if (dash_stream->is_isobmff)
|
|
|
|
ret = gst_dash_demux_handle_isobmff_buffer (demux, stream, buffer);
|
|
|
|
else
|
|
|
|
ret = gst_adaptive_demux_stream_push_buffer (stream, buffer);
|
|
|
|
|
|
|
|
if (!(dash_stream->moof_sync_samples
|
|
|
|
&& (GST_ADAPTIVE_DEMUX (stream->demux)->
|
|
|
|
segment.flags & GST_SEGMENT_FLAG_TRICKMODE_KEY_UNITS))
|
|
|
|
&& advance) {
|
2016-03-28 10:45:36 +00:00
|
|
|
GstFlowReturn new_ret;
|
|
|
|
new_ret =
|
|
|
|
gst_adaptive_demux_stream_advance_fragment (demux, stream,
|
|
|
|
SIDX_CURRENT_ENTRY (dash_stream)->duration);
|
|
|
|
|
|
|
|
/* only overwrite if it was OK before */
|
|
|
|
if (ret == GST_FLOW_OK)
|
|
|
|
ret = new_ret;
|
|
|
|
}
|
2015-01-15 20:44:45 +00:00
|
|
|
}
|
2015-01-12 20:40:47 +00:00
|
|
|
}
|
2015-01-15 20:44:45 +00:00
|
|
|
} else {
|
|
|
|
/* this should be the main header, just push it all */
|
2016-03-31 10:39:59 +00:00
|
|
|
buffer = gst_adapter_take_buffer (dash_stream->sidx_adapter,
|
|
|
|
gst_adapter_available (dash_stream->sidx_adapter));
|
|
|
|
|
|
|
|
GST_BUFFER_OFFSET (buffer) = dash_stream->sidx_current_offset;
|
|
|
|
GST_BUFFER_OFFSET_END (buffer) =
|
|
|
|
GST_BUFFER_OFFSET (buffer) + gst_buffer_get_size (buffer);
|
|
|
|
dash_stream->sidx_current_offset = GST_BUFFER_OFFSET_END (buffer);
|
|
|
|
|
2016-08-02 05:35:26 +00:00
|
|
|
if (dash_stream->is_isobmff)
|
|
|
|
return gst_dash_demux_handle_isobmff_buffer (demux, stream, buffer);
|
|
|
|
else
|
|
|
|
return gst_adaptive_demux_stream_push_buffer (stream, buffer);
|
2015-01-12 20:40:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2015-01-12 14:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_dash_demux_stream_free (GstAdaptiveDemuxStream * stream)
|
|
|
|
{
|
|
|
|
GstDashDemuxStream *dash_stream = (GstDashDemuxStream *) stream;
|
|
|
|
|
|
|
|
gst_isoff_sidx_parser_clear (&dash_stream->sidx_parser);
|
2016-03-28 10:45:36 +00:00
|
|
|
if (dash_stream->sidx_adapter)
|
|
|
|
g_object_unref (dash_stream->sidx_adapter);
|
2016-03-28 10:45:36 +00:00
|
|
|
if (dash_stream->isobmff_adapter)
|
|
|
|
g_object_unref (dash_stream->isobmff_adapter);
|
2015-01-12 14:57:02 +00:00
|
|
|
}
|
2015-07-15 10:56:13 +00:00
|
|
|
|
|
|
|
static GstDashDemuxClockDrift *
|
2016-02-16 14:44:10 +00:00
|
|
|
gst_dash_demux_clock_drift_new (GstDashDemux * demux)
|
2015-07-15 10:56:13 +00:00
|
|
|
{
|
|
|
|
GstDashDemuxClockDrift *clock_drift;
|
|
|
|
|
|
|
|
clock_drift = g_slice_new0 (GstDashDemuxClockDrift);
|
|
|
|
g_mutex_init (&clock_drift->clock_lock);
|
2016-02-16 14:44:10 +00:00
|
|
|
clock_drift->next_update =
|
|
|
|
GST_TIME_AS_USECONDS (gst_adaptive_demux_get_monotonic_time
|
|
|
|
(GST_ADAPTIVE_DEMUX_CAST (demux)));
|
2015-07-15 10:56:13 +00:00
|
|
|
return clock_drift;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_dash_demux_clock_drift_free (GstDashDemuxClockDrift * clock_drift)
|
|
|
|
{
|
|
|
|
if (clock_drift) {
|
|
|
|
g_mutex_lock (&clock_drift->clock_lock);
|
|
|
|
if (clock_drift->ntp_clock)
|
|
|
|
g_object_unref (clock_drift->ntp_clock);
|
|
|
|
g_mutex_unlock (&clock_drift->clock_lock);
|
|
|
|
g_mutex_clear (&clock_drift->clock_lock);
|
|
|
|
g_slice_free (GstDashDemuxClockDrift, clock_drift);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-13 17:21:29 +00:00
|
|
|
/*
|
|
|
|
* The value attribute of the UTCTiming element contains a white-space
|
|
|
|
* separated list of servers that are recommended to be used in
|
|
|
|
* combination with the NTP protocol as defined in IETF RFC 5905 for
|
|
|
|
* getting the appropriate time.
|
|
|
|
*
|
|
|
|
* The DASH standard does not specify which version of NTP. This
|
|
|
|
* function only works with NTPv4 servers.
|
|
|
|
*/
|
2015-07-15 10:56:13 +00:00
|
|
|
static GstDateTime *
|
|
|
|
gst_dash_demux_poll_ntp_server (GstDashDemuxClockDrift * clock_drift,
|
|
|
|
gchar ** urls)
|
|
|
|
{
|
|
|
|
GstClockTime ntp_clock_time;
|
|
|
|
GDateTime *dt, *dt2;
|
|
|
|
|
|
|
|
if (!clock_drift->ntp_clock) {
|
|
|
|
GResolver *resolver;
|
|
|
|
GList *inet_addrs;
|
|
|
|
GError *err;
|
|
|
|
gchar *ip_addr;
|
|
|
|
|
|
|
|
resolver = g_resolver_get_default ();
|
|
|
|
/* We don't round-robin NTP servers. If the manifest specifies multiple
|
|
|
|
NTP time servers, select one at random */
|
|
|
|
clock_drift->selected_url = g_random_int_range (0, g_strv_length (urls));
|
|
|
|
GST_DEBUG ("Connecting to NTP time server %s",
|
|
|
|
urls[clock_drift->selected_url]);
|
|
|
|
inet_addrs = g_resolver_lookup_by_name (resolver,
|
|
|
|
urls[clock_drift->selected_url], NULL, &err);
|
|
|
|
g_object_unref (resolver);
|
|
|
|
if (!inet_addrs || g_list_length (inet_addrs) == 0) {
|
2015-08-13 17:21:29 +00:00
|
|
|
GST_ERROR ("Failed to resolve hostname of NTP server: %s",
|
|
|
|
err ? (err->message) : "unknown error");
|
2015-07-15 10:56:13 +00:00
|
|
|
if (inet_addrs)
|
|
|
|
g_resolver_free_addresses (inet_addrs);
|
2015-08-13 17:21:29 +00:00
|
|
|
if (err)
|
|
|
|
g_error_free (err);
|
2015-07-15 10:56:13 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
ip_addr =
|
|
|
|
g_inet_address_to_string ((GInetAddress
|
|
|
|
*) (g_list_first (inet_addrs)->data));
|
|
|
|
clock_drift->ntp_clock = gst_ntp_clock_new ("dashntp", ip_addr, 123, 0);
|
|
|
|
g_free (ip_addr);
|
|
|
|
g_resolver_free_addresses (inet_addrs);
|
|
|
|
if (!clock_drift->ntp_clock) {
|
|
|
|
GST_ERROR ("Failed to create NTP clock");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (!gst_clock_wait_for_sync (clock_drift->ntp_clock, 5 * GST_SECOND)) {
|
|
|
|
g_object_unref (clock_drift->ntp_clock);
|
|
|
|
clock_drift->ntp_clock = NULL;
|
|
|
|
GST_ERROR ("Failed to lock to NTP clock");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ntp_clock_time = gst_clock_get_time (clock_drift->ntp_clock);
|
|
|
|
if (ntp_clock_time == GST_CLOCK_TIME_NONE) {
|
|
|
|
GST_ERROR ("Failed to get time from NTP clock");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
ntp_clock_time -= NTP_TO_UNIX_EPOCH * GST_SECOND;
|
|
|
|
dt = g_date_time_new_from_unix_utc (ntp_clock_time / GST_SECOND);
|
|
|
|
if (!dt) {
|
|
|
|
GST_ERROR ("Failed to create GstDateTime");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
ntp_clock_time =
|
|
|
|
gst_util_uint64_scale (ntp_clock_time % GST_SECOND, 1000000, GST_SECOND);
|
|
|
|
dt2 = g_date_time_add (dt, ntp_clock_time);
|
|
|
|
g_date_time_unref (dt);
|
|
|
|
return gst_date_time_new_from_g_date_time (dt2);
|
|
|
|
}
|
|
|
|
|
2015-12-21 14:50:15 +00:00
|
|
|
struct Rfc5322TimeZone
|
2015-08-14 08:44:24 +00:00
|
|
|
{
|
|
|
|
const gchar *name;
|
|
|
|
gfloat tzoffset;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
2015-12-21 14:50:15 +00:00
|
|
|
Parse an RFC5322 (section 3.3) date-time from the Date: field in the
|
2015-08-14 08:44:24 +00:00
|
|
|
HTTP response.
|
2015-12-21 14:50:15 +00:00
|
|
|
See https://tools.ietf.org/html/rfc5322#section-3.3
|
2015-08-14 08:44:24 +00:00
|
|
|
*/
|
|
|
|
static GstDateTime *
|
|
|
|
gst_dash_demux_parse_http_head (GstDashDemuxClockDrift * clock_drift,
|
|
|
|
GstFragment * download)
|
|
|
|
{
|
|
|
|
static const gchar *months[] = { NULL, "Jan", "Feb", "Mar", "Apr",
|
|
|
|
"May", "Jun", "Jul", "Aug",
|
|
|
|
"Sep", "Oct", "Nov", "Dec", NULL
|
|
|
|
};
|
2015-12-21 14:50:15 +00:00
|
|
|
static const struct Rfc5322TimeZone timezones[] = {
|
2015-08-14 08:44:24 +00:00
|
|
|
{"Z", 0},
|
|
|
|
{"UT", 0},
|
|
|
|
{"GMT", 0},
|
|
|
|
{"BST", 1},
|
|
|
|
{"EST", -5},
|
|
|
|
{"EDT", -4},
|
|
|
|
{"CST", -6},
|
|
|
|
{"CDT", -5},
|
|
|
|
{"MST", -7},
|
|
|
|
{"MDT", -6},
|
|
|
|
{"PST", -8},
|
|
|
|
{"PDT", -7},
|
|
|
|
{NULL, 0}
|
|
|
|
};
|
|
|
|
GstDateTime *value = NULL;
|
|
|
|
const GstStructure *response_headers;
|
|
|
|
const gchar *http_date;
|
|
|
|
const GValue *val;
|
|
|
|
gint ret;
|
|
|
|
const gchar *pos;
|
|
|
|
gint year = -1, month = -1, day = -1, hour = -1, minute = -1, second = -1;
|
|
|
|
gchar zone[6];
|
|
|
|
gchar monthstr[4];
|
|
|
|
gfloat tzoffset = 0;
|
|
|
|
gboolean parsed_tz = FALSE;
|
|
|
|
|
|
|
|
g_return_val_if_fail (download != NULL, NULL);
|
|
|
|
g_return_val_if_fail (download->headers != NULL, NULL);
|
|
|
|
|
|
|
|
val = gst_structure_get_value (download->headers, "response-headers");
|
|
|
|
if (!val) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
response_headers = gst_value_get_structure (val);
|
|
|
|
http_date = gst_structure_get_string (response_headers, "Date");
|
|
|
|
if (!http_date) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* skip optional text version of day of the week */
|
|
|
|
pos = strchr (http_date, ',');
|
|
|
|
if (pos)
|
|
|
|
pos++;
|
|
|
|
else
|
|
|
|
pos = http_date;
|
|
|
|
ret =
|
|
|
|
sscanf (pos, "%02d %3s %04d %02d:%02d:%02d %5s", &day, monthstr, &year,
|
|
|
|
&hour, &minute, &second, zone);
|
|
|
|
if (ret == 7) {
|
|
|
|
gchar *z = zone;
|
|
|
|
for (int i = 1; months[i]; ++i) {
|
|
|
|
if (g_ascii_strncasecmp (months[i], monthstr, strlen (months[i])) == 0) {
|
|
|
|
month = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (int i = 0; timezones[i].name && !parsed_tz; ++i) {
|
|
|
|
if (g_ascii_strncasecmp (timezones[i].name, z,
|
|
|
|
strlen (timezones[i].name)) == 0) {
|
|
|
|
tzoffset = timezones[i].tzoffset;
|
|
|
|
parsed_tz = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!parsed_tz) {
|
|
|
|
gint hh, mm;
|
|
|
|
gboolean neg = FALSE;
|
|
|
|
/* check if it is in the form +-HHMM */
|
|
|
|
if (*z == '+' || *z == '-') {
|
|
|
|
if (*z == '+')
|
|
|
|
++z;
|
|
|
|
else if (*z == '-') {
|
|
|
|
++z;
|
|
|
|
neg = TRUE;
|
|
|
|
}
|
|
|
|
ret = sscanf (z, "%02d%02d", &hh, &mm);
|
|
|
|
if (ret == 2) {
|
|
|
|
tzoffset = hh;
|
|
|
|
tzoffset += mm / 60.0;
|
|
|
|
if (neg)
|
|
|
|
tzoffset = -tzoffset;
|
|
|
|
parsed_tz = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-12-21 14:50:15 +00:00
|
|
|
/* Accept year in both 2 digit or 4 digit format */
|
|
|
|
if (year < 100)
|
|
|
|
year += 2000;
|
2015-08-14 08:44:24 +00:00
|
|
|
}
|
|
|
|
if (month > 0 && parsed_tz) {
|
|
|
|
value = gst_date_time_new (tzoffset,
|
|
|
|
year, month, day, hour, minute, second);
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2015-08-13 17:21:29 +00:00
|
|
|
/*
|
|
|
|
The timing information is contained in the message body of the HTTP
|
|
|
|
response and contains a time value formatted according to NTP timestamp
|
|
|
|
format in IETF RFC 5905.
|
|
|
|
|
|
|
|
0 1 2 3
|
|
|
|
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
| Seconds |
|
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
| Fraction |
|
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
|
|
|
|
NTP Timestamp Format
|
|
|
|
*/
|
2015-07-15 10:56:13 +00:00
|
|
|
static GstDateTime *
|
|
|
|
gst_dash_demux_parse_http_ntp (GstDashDemuxClockDrift * clock_drift,
|
|
|
|
GstBuffer * buffer)
|
|
|
|
{
|
|
|
|
gint64 seconds;
|
|
|
|
guint64 fraction;
|
|
|
|
GDateTime *dt, *dt2;
|
|
|
|
GstMapInfo mapinfo;
|
|
|
|
|
|
|
|
/* See https://tools.ietf.org/html/rfc5905#page-12 for details of
|
|
|
|
the NTP Timestamp Format */
|
|
|
|
gst_buffer_map (buffer, &mapinfo, GST_MAP_READ);
|
|
|
|
if (mapinfo.size != 8) {
|
|
|
|
gst_buffer_unmap (buffer, &mapinfo);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
seconds = GST_READ_UINT32_BE (mapinfo.data);
|
|
|
|
fraction = GST_READ_UINT32_BE (mapinfo.data + 4);
|
|
|
|
gst_buffer_unmap (buffer, &mapinfo);
|
|
|
|
fraction = gst_util_uint64_scale (fraction, 1000000,
|
|
|
|
G_GUINT64_CONSTANT (1) << 32);
|
|
|
|
/* subtract constant to convert from 1900 based time to 1970 based time */
|
|
|
|
seconds -= NTP_TO_UNIX_EPOCH;
|
|
|
|
dt = g_date_time_new_from_unix_utc (seconds);
|
|
|
|
dt2 = g_date_time_add (dt, fraction);
|
|
|
|
g_date_time_unref (dt);
|
|
|
|
return gst_date_time_new_from_g_date_time (dt2);
|
|
|
|
}
|
|
|
|
|
2015-08-13 17:21:29 +00:00
|
|
|
/*
|
|
|
|
The timing information is contained in the message body of the
|
|
|
|
HTTP response and contains a time value formatted according to
|
|
|
|
xs:dateTime as defined in W3C XML Schema Part 2: Datatypes specification.
|
|
|
|
*/
|
2015-07-15 10:56:13 +00:00
|
|
|
static GstDateTime *
|
|
|
|
gst_dash_demux_parse_http_xsdate (GstDashDemuxClockDrift * clock_drift,
|
|
|
|
GstBuffer * buffer)
|
|
|
|
{
|
2016-02-23 10:49:40 +00:00
|
|
|
GstDateTime *value = NULL;
|
2015-07-15 10:56:13 +00:00
|
|
|
GstMapInfo mapinfo;
|
|
|
|
|
|
|
|
/* the string from the server might not be zero terminated */
|
2016-02-23 10:49:40 +00:00
|
|
|
if (gst_buffer_map (buffer, &mapinfo, GST_MAP_READ)) {
|
|
|
|
gchar *str;
|
|
|
|
str = g_strndup ((const gchar *) mapinfo.data, mapinfo.size);
|
|
|
|
gst_buffer_unmap (buffer, &mapinfo);
|
|
|
|
value = gst_date_time_new_from_iso8601_string (str);
|
|
|
|
g_free (str);
|
|
|
|
}
|
2015-07-15 10:56:13 +00:00
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_dash_demux_poll_clock_drift (GstDashDemux * demux)
|
|
|
|
{
|
|
|
|
GstDashDemuxClockDrift *clock_drift;
|
|
|
|
GDateTime *start = NULL, *end;
|
|
|
|
GstBuffer *buffer = NULL;
|
|
|
|
GstDateTime *value = NULL;
|
|
|
|
gboolean ret = FALSE;
|
|
|
|
gint64 now;
|
|
|
|
GstMPDUTCTimingType method;
|
|
|
|
gchar **urls;
|
|
|
|
|
|
|
|
g_return_val_if_fail (demux != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (demux->clock_drift != NULL, FALSE);
|
|
|
|
clock_drift = demux->clock_drift;
|
2016-02-16 14:44:10 +00:00
|
|
|
now =
|
|
|
|
GST_TIME_AS_USECONDS (gst_adaptive_demux_get_monotonic_time
|
|
|
|
(GST_ADAPTIVE_DEMUX_CAST (demux)));
|
2015-07-15 10:56:13 +00:00
|
|
|
if (now < clock_drift->next_update) {
|
|
|
|
/*TODO: If a fragment fails to download in adaptivedemux, it waits
|
|
|
|
for a manifest reload before another attempt to fetch a fragment.
|
|
|
|
Section 10.8.6 of the DVB-DASH standard states that the DASH client
|
|
|
|
shall refresh the manifest and resynchronise to one of the time sources.
|
|
|
|
|
|
|
|
Currently the fact that the manifest refresh follows a download failure
|
|
|
|
does not make it into dashdemux. */
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
urls = gst_mpd_client_get_utc_timing_sources (demux->client,
|
|
|
|
SUPPORTED_CLOCK_FORMATS, &method);
|
|
|
|
if (!urls) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
/* Update selected_url just in case the number of URLs in the UTCTiming
|
|
|
|
element has shrunk since the last poll */
|
|
|
|
clock_drift->selected_url = clock_drift->selected_url % g_strv_length (urls);
|
|
|
|
g_mutex_lock (&clock_drift->clock_lock);
|
|
|
|
|
|
|
|
if (method == GST_MPD_UTCTIMING_TYPE_NTP) {
|
|
|
|
value = gst_dash_demux_poll_ntp_server (clock_drift, urls);
|
|
|
|
if (!value) {
|
|
|
|
GST_ERROR_OBJECT (demux, "Failed to fetch time from NTP server %s",
|
|
|
|
urls[clock_drift->selected_url]);
|
|
|
|
g_mutex_unlock (&clock_drift->clock_lock);
|
|
|
|
goto quit;
|
|
|
|
}
|
|
|
|
}
|
2016-02-16 14:44:10 +00:00
|
|
|
start =
|
|
|
|
gst_adaptive_demux_get_client_now_utc (GST_ADAPTIVE_DEMUX_CAST (demux));
|
2015-07-15 10:56:13 +00:00
|
|
|
if (!value) {
|
|
|
|
GstFragment *download;
|
2015-08-14 08:44:24 +00:00
|
|
|
gint64 range_start = 0, range_end = -1;
|
2015-07-15 10:56:13 +00:00
|
|
|
GST_DEBUG_OBJECT (demux, "Fetching current time from %s",
|
|
|
|
urls[clock_drift->selected_url]);
|
2015-08-14 08:44:24 +00:00
|
|
|
if (method == GST_MPD_UTCTIMING_TYPE_HTTP_HEAD) {
|
|
|
|
range_start = -1;
|
|
|
|
}
|
2015-07-15 10:56:13 +00:00
|
|
|
download =
|
2015-08-14 08:44:24 +00:00
|
|
|
gst_uri_downloader_fetch_uri_with_range (GST_ADAPTIVE_DEMUX_CAST
|
2015-07-15 10:56:13 +00:00
|
|
|
(demux)->downloader, urls[clock_drift->selected_url], NULL, TRUE, TRUE,
|
2015-08-14 08:44:24 +00:00
|
|
|
TRUE, range_start, range_end, NULL);
|
|
|
|
if (download) {
|
|
|
|
if (method == GST_MPD_UTCTIMING_TYPE_HTTP_HEAD && download->headers) {
|
|
|
|
value = gst_dash_demux_parse_http_head (clock_drift, download);
|
|
|
|
} else {
|
|
|
|
buffer = gst_fragment_get_buffer (download);
|
|
|
|
}
|
|
|
|
g_object_unref (download);
|
|
|
|
}
|
2015-07-15 10:56:13 +00:00
|
|
|
}
|
|
|
|
g_mutex_unlock (&clock_drift->clock_lock);
|
|
|
|
if (!value && !buffer) {
|
|
|
|
GST_ERROR_OBJECT (demux, "Failed to fetch time from %s",
|
|
|
|
urls[clock_drift->selected_url]);
|
|
|
|
goto quit;
|
|
|
|
}
|
2016-02-16 14:44:10 +00:00
|
|
|
end = gst_adaptive_demux_get_client_now_utc (GST_ADAPTIVE_DEMUX_CAST (demux));
|
2015-07-15 10:56:13 +00:00
|
|
|
if (!value && method == GST_MPD_UTCTIMING_TYPE_HTTP_NTP) {
|
|
|
|
value = gst_dash_demux_parse_http_ntp (clock_drift, buffer);
|
|
|
|
} else if (!value) {
|
|
|
|
/* GST_MPD_UTCTIMING_TYPE_HTTP_XSDATE or GST_MPD_UTCTIMING_TYPE_HTTP_ISO */
|
|
|
|
value = gst_dash_demux_parse_http_xsdate (clock_drift, buffer);
|
|
|
|
}
|
|
|
|
if (buffer)
|
|
|
|
gst_buffer_unref (buffer);
|
|
|
|
if (value) {
|
|
|
|
GTimeSpan download_duration = g_date_time_difference (end, start);
|
|
|
|
GDateTime *client_now, *server_now;
|
|
|
|
/* We don't know when the server sampled its clock, but we know
|
|
|
|
it must have been before "end" and probably after "start".
|
|
|
|
A reasonable estimate is to use (start+end)/2
|
|
|
|
*/
|
|
|
|
client_now = g_date_time_add (start, download_duration / 2);
|
|
|
|
server_now = gst_date_time_to_g_date_time (value);
|
|
|
|
/* If gst_date_time_new_from_iso8601_string is given an unsupported
|
|
|
|
ISO 8601 format, it can return a GstDateTime that is not valid,
|
|
|
|
which causes gst_date_time_to_g_date_time to return NULL */
|
|
|
|
if (server_now) {
|
|
|
|
g_mutex_lock (&clock_drift->clock_lock);
|
|
|
|
clock_drift->clock_compensation =
|
|
|
|
g_date_time_difference (server_now, client_now);
|
|
|
|
g_mutex_unlock (&clock_drift->clock_lock);
|
|
|
|
GST_DEBUG_OBJECT (demux,
|
|
|
|
"Difference between client and server clocks is %lfs",
|
|
|
|
((double) clock_drift->clock_compensation) / 1000000.0);
|
|
|
|
g_date_time_unref (server_now);
|
|
|
|
ret = TRUE;
|
|
|
|
} else {
|
|
|
|
GST_ERROR_OBJECT (demux, "Failed to parse DateTime from server");
|
|
|
|
}
|
|
|
|
g_date_time_unref (client_now);
|
|
|
|
gst_date_time_unref (value);
|
|
|
|
} else {
|
|
|
|
GST_ERROR_OBJECT (demux, "Failed to parse DateTime from server");
|
|
|
|
}
|
|
|
|
g_date_time_unref (end);
|
|
|
|
quit:
|
|
|
|
if (start)
|
|
|
|
g_date_time_unref (start);
|
|
|
|
/* if multiple URLs were specified, use a simple round-robin to
|
|
|
|
poll each server */
|
|
|
|
g_mutex_lock (&clock_drift->clock_lock);
|
|
|
|
if (method == GST_MPD_UTCTIMING_TYPE_NTP) {
|
|
|
|
clock_drift->next_update = now + FAST_CLOCK_UPDATE_INTERVAL;
|
|
|
|
} else {
|
|
|
|
clock_drift->selected_url =
|
|
|
|
(1 + clock_drift->selected_url) % g_strv_length (urls);
|
|
|
|
if (ret) {
|
|
|
|
clock_drift->next_update = now + SLOW_CLOCK_UPDATE_INTERVAL;
|
|
|
|
} else {
|
|
|
|
clock_drift->next_update = now + FAST_CLOCK_UPDATE_INTERVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_mutex_unlock (&clock_drift->clock_lock);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GTimeSpan
|
|
|
|
gst_dash_demux_get_clock_compensation (GstDashDemux * demux)
|
|
|
|
{
|
|
|
|
GTimeSpan rv = 0;
|
|
|
|
if (demux->clock_drift) {
|
|
|
|
g_mutex_lock (&demux->clock_drift->clock_lock);
|
|
|
|
rv = demux->clock_drift->clock_compensation;
|
|
|
|
g_mutex_unlock (&demux->clock_drift->clock_lock);
|
|
|
|
}
|
|
|
|
GST_LOG_OBJECT (demux, "Clock drift %" GST_STIME_FORMAT, GST_STIME_ARGS (rv));
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GDateTime *
|
|
|
|
gst_dash_demux_get_server_now_utc (GstDashDemux * demux)
|
|
|
|
{
|
2016-02-16 14:44:10 +00:00
|
|
|
GDateTime *client_now;
|
|
|
|
GDateTime *server_now;
|
|
|
|
|
|
|
|
client_now =
|
|
|
|
gst_adaptive_demux_get_client_now_utc (GST_ADAPTIVE_DEMUX_CAST (demux));
|
|
|
|
server_now =
|
|
|
|
g_date_time_add (client_now,
|
2015-07-15 10:56:13 +00:00
|
|
|
gst_dash_demux_get_clock_compensation (demux));
|
|
|
|
g_date_time_unref (client_now);
|
|
|
|
return server_now;
|
|
|
|
}
|