gstreamer/ext/dash/gstmpdparser.h

493 lines
15 KiB
C
Raw Normal View History

2013-05-08 14:13:32 +00:00
/*
* DASH MPD parsing library
2013-05-08 14:13:32 +00:00
*
* gstmpdparser.h
2013-05-08 14:13:32 +00:00
*
* Copyright (C) 2012 STMicroelectronics
2013-05-08 14:13:32 +00:00
*
* Authors:
* Gianluca Gennari <gennarone@gmail.com>
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.
2013-05-08 14:13:32 +00:00
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library (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.
*/
#ifndef __GST_MPDPARSER_H__
#define __GST_MPDPARSER_H__
#include <gst/gst.h>
#include <gst/uridownloader/gsturidownloader.h>
#include <gst/base/gstadapter.h>
#include "gstmpdhelper.h"
2013-05-08 14:13:32 +00:00
G_BEGIN_DECLS
typedef struct _GstActiveStream GstActiveStream;
typedef struct _GstStreamPeriod GstStreamPeriod;
typedef struct _GstMediaFragmentInfo GstMediaFragmentInfo;
2013-05-08 14:13:32 +00:00
typedef struct _GstMediaSegment GstMediaSegment;
typedef struct _GstMPDNode GstMPDNode;
typedef struct _GstPeriodNode GstPeriodNode;
typedef struct _GstRepresentationBaseType GstRepresentationBaseType;
typedef struct _GstDescriptorType GstDescriptorType;
typedef struct _GstContentComponentNode GstContentComponentNode;
typedef struct _GstAdaptationSetNode GstAdaptationSetNode;
typedef struct _GstRepresentationNode GstRepresentationNode;
typedef struct _GstSubRepresentationNode GstSubRepresentationNode;
typedef struct _GstSegmentListNode GstSegmentListNode;
typedef struct _GstSegmentTemplateNode GstSegmentTemplateNode;
typedef struct _GstSegmentURLNode GstSegmentURLNode;
typedef struct _GstBaseURL GstBaseURL;
2013-05-08 14:13:32 +00:00
typedef struct _GstSubsetNode GstSubsetNode;
typedef struct _GstProgramInformationNode GstProgramInformationNode;
typedef struct _GstMetricsRangeNode GstMetricsRangeNode;
typedef struct _GstMetricsNode GstMetricsNode;
dashdemux: add support for UTCTiming elements for clock drift compensation Unless the DASH client can compensate for the difference between its clock and the clock used by the server, the client might request fragments that either not yet on the server or fragments that have already been expired from the server. This is an issue because these requests can propagate all the way back to the origin ISO/IEC 23009-1:2014/Amd 1 [PDAM1] defines a new UTCTiming element to allow a DASH client to track the clock used by the server generating the DASH stream. Multiple UTCTiming elements might be present, to indicate support for multiple methods of UTC time gathering. Each element can contain a white space separated list of URLs that can be contacted to discover the UTC time from the server's perspective. This commit provides parsing of UTCTiming elements, unit tests of this parsing and a function to poll a time server. This function supports the following methods: urn:mpeg:dash:utc:ntp:2014 urn:mpeg:dash:utc:http-xsdate:2014 urn:mpeg:dash:utc:http-iso:2014 urn:mpeg:dash:utc:http-ntp:2014 The manifest update task is used to poll the clock time server, to save having to create a new thread. When choosing the starting fragment number and when waiting for a fragment to become available, the difference between the server's idea of UTC and the client's idea of UTC is taken into account. For example, if the server's time is behind the client's idea of UTC, we wait for longer before requesting a fragment [PDAM1]: http://www.iso.org/iso/home/store/catalogue_tc/catalogue_detail.htm?csnumber=66068 dashdemux: support NTP time servers in UTCTiming elements Use the gst_ntp_clock to support the use of an NTP server. https://bugzilla.gnome.org/show_bug.cgi?id=752413
2015-07-15 10:56:13 +00:00
typedef struct _GstUTCTimingNode GstUTCTimingNode;
2013-05-08 14:13:32 +00:00
typedef struct _GstSNode GstSNode;
typedef struct _GstSegmentTimelineNode GstSegmentTimelineNode;
typedef struct _GstSegmentBaseType GstSegmentBaseType;
typedef struct _GstURLType GstURLType;
typedef struct _GstMultSegmentBaseType GstMultSegmentBaseType;
#define GST_MPD_DURATION_NONE ((guint64)-1)
2013-05-08 14:13:32 +00:00
typedef enum
{
GST_STREAM_UNKNOWN,
2013-05-08 14:13:32 +00:00
GST_STREAM_VIDEO, /* video stream (the main one) */
GST_STREAM_AUDIO, /* audio stream (optional) */
GST_STREAM_APPLICATION /* application stream (optional): for timed text/subtitles */
} GstStreamMimeType;
typedef enum
{
GST_XLINK_ACTUATE_ON_REQUEST,
GST_XLINK_ACTUATE_ON_LOAD
} GstXLinkActuate;
dashdemux: add support for UTCTiming elements for clock drift compensation Unless the DASH client can compensate for the difference between its clock and the clock used by the server, the client might request fragments that either not yet on the server or fragments that have already been expired from the server. This is an issue because these requests can propagate all the way back to the origin ISO/IEC 23009-1:2014/Amd 1 [PDAM1] defines a new UTCTiming element to allow a DASH client to track the clock used by the server generating the DASH stream. Multiple UTCTiming elements might be present, to indicate support for multiple methods of UTC time gathering. Each element can contain a white space separated list of URLs that can be contacted to discover the UTC time from the server's perspective. This commit provides parsing of UTCTiming elements, unit tests of this parsing and a function to poll a time server. This function supports the following methods: urn:mpeg:dash:utc:ntp:2014 urn:mpeg:dash:utc:http-xsdate:2014 urn:mpeg:dash:utc:http-iso:2014 urn:mpeg:dash:utc:http-ntp:2014 The manifest update task is used to poll the clock time server, to save having to create a new thread. When choosing the starting fragment number and when waiting for a fragment to become available, the difference between the server's idea of UTC and the client's idea of UTC is taken into account. For example, if the server's time is behind the client's idea of UTC, we wait for longer before requesting a fragment [PDAM1]: http://www.iso.org/iso/home/store/catalogue_tc/catalogue_detail.htm?csnumber=66068 dashdemux: support NTP time servers in UTCTiming elements Use the gst_ntp_clock to support the use of an NTP server. https://bugzilla.gnome.org/show_bug.cgi?id=752413
2015-07-15 10:56:13 +00:00
typedef enum
{
GST_MPD_UTCTIMING_TYPE_UNKNOWN = 0x00,
GST_MPD_UTCTIMING_TYPE_NTP = 0x01,
GST_MPD_UTCTIMING_TYPE_SNTP = 0x02,
GST_MPD_UTCTIMING_TYPE_HTTP_HEAD = 0x04,
GST_MPD_UTCTIMING_TYPE_HTTP_XSDATE = 0x08,
GST_MPD_UTCTIMING_TYPE_HTTP_ISO = 0x10,
GST_MPD_UTCTIMING_TYPE_HTTP_NTP = 0x20,
GST_MPD_UTCTIMING_TYPE_DIRECT = 0x40
} GstMPDUTCTimingType;
2013-05-08 14:13:32 +00:00
struct _GstBaseURL
{
gchar *baseURL;
gchar *serviceLocation;
gchar *byteRange;
};
struct _GstSNode
{
guint64 t;
guint64 d;
gint r;
2013-05-08 14:13:32 +00:00
};
struct _GstSegmentTimelineNode
{
/* list of S nodes */
GQueue S;
2013-05-08 14:13:32 +00:00
};
struct _GstURLType
{
gchar *sourceURL;
GstXMLRange *range;
2013-05-08 14:13:32 +00:00
};
struct _GstSegmentBaseType
{
guint timescale;
guint64 presentationTimeOffset;
GstXMLRange *indexRange;
2013-05-08 14:13:32 +00:00
gboolean indexRangeExact;
/* Initialization node */
GstURLType *Initialization;
/* RepresentationIndex node */
GstURLType *RepresentationIndex;
};
struct _GstMultSegmentBaseType
{
guint duration; /* in seconds */
guint startNumber;
/* SegmentBaseType extension */
GstSegmentBaseType *SegBaseType;
/* SegmentTimeline node */
GstSegmentTimelineNode *SegmentTimeline;
/* BitstreamSwitching node */
GstURLType *BitstreamSwitching;
};
struct _GstSegmentListNode
{
/* extension */
GstMultSegmentBaseType *MultSegBaseType;
/* list of SegmentURL nodes */
GList *SegmentURL;
gchar *xlink_href;
GstXLinkActuate actuate;
2013-05-08 14:13:32 +00:00
};
struct _GstSegmentTemplateNode
{
/* extension */
GstMultSegmentBaseType *MultSegBaseType;
gchar *media;
gchar *index;
gchar *initialization;
gchar *bitstreamSwitching;
};
struct _GstSegmentURLNode
{
gchar *media;
GstXMLRange *mediaRange;
2013-05-08 14:13:32 +00:00
gchar *index;
GstXMLRange *indexRange;
2013-05-08 14:13:32 +00:00
};
struct _GstRepresentationBaseType
{
gchar *profiles;
guint width;
guint height;
GstXMLRatio *sar;
GstXMLFrameRate *minFrameRate;
GstXMLFrameRate *maxFrameRate;
GstXMLFrameRate *frameRate;
2013-05-08 14:13:32 +00:00
gchar *audioSamplingRate;
gchar *mimeType;
gchar *segmentProfiles;
gchar *codecs;
gdouble maximumSAPPeriod;
GstMPDSAPType startWithSAP;
2013-05-08 14:13:32 +00:00
gdouble maxPlayoutRate;
gboolean codingDependency;
gchar *scanType;
/* list of FramePacking DescriptorType nodes */
GList *FramePacking;
/* list of AudioChannelConfiguration DescriptorType nodes */
GList *AudioChannelConfiguration;
/* list of ContentProtection DescriptorType nodes */
GList *ContentProtection;
};
struct _GstSubRepresentationNode
{
/* RepresentationBase extension */
GstRepresentationBaseType *RepresentationBase;
guint level;
guint *dependencyLevel; /* UIntVectorType */
guint size; /* size of "dependencyLevel" array */
guint bandwidth;
gchar **contentComponent; /* StringVectorType */
};
struct _GstRepresentationNode
{
gchar *id;
guint bandwidth;
guint qualityRanking;
gchar **dependencyId; /* StringVectorType */
gchar **mediaStreamStructureId; /* StringVectorType */
/* RepresentationBase extension */
GstRepresentationBaseType *RepresentationBase;
/* list of BaseURL nodes */
GList *BaseURLs;
/* list of SubRepresentation nodes */
GList *SubRepresentations;
/* SegmentBase node */
GstSegmentBaseType *SegmentBase;
/* SegmentTemplate node */
GstSegmentTemplateNode *SegmentTemplate;
/* SegmentList node */
GstSegmentListNode *SegmentList;
2013-05-08 14:13:32 +00:00
};
struct _GstDescriptorType
{
gchar *schemeIdUri;
gchar *value;
};
struct _GstContentComponentNode
{
guint id;
gchar *lang; /* LangVectorType RFC 5646 */
gchar *contentType;
GstXMLRatio *par;
2013-05-08 14:13:32 +00:00
/* list of Accessibility DescriptorType nodes */
GList *Accessibility;
/* list of Role DescriptorType nodes */
GList *Role;
/* list of Rating DescriptorType nodes */
GList *Rating;
/* list of Viewpoint DescriptorType nodes */
GList *Viewpoint;
};
struct _GstAdaptationSetNode
{
guint id;
guint group;
gchar *lang; /* LangVectorType RFC 5646 */
gchar *contentType;
GstXMLRatio *par;
2013-05-08 14:13:32 +00:00
guint minBandwidth;
guint maxBandwidth;
guint minWidth;
guint maxWidth;
guint minHeight;
guint maxHeight;
GstXMLConditionalUintType *segmentAlignment;
GstXMLConditionalUintType *subsegmentAlignment;
GstMPDSAPType subsegmentStartsWithSAP;
2013-05-08 14:13:32 +00:00
gboolean bitstreamSwitching;
/* list of Accessibility DescriptorType nodes */
GList *Accessibility;
/* list of Role DescriptorType nodes */
GList *Role;
/* list of Rating DescriptorType nodes */
GList *Rating;
/* list of Viewpoint DescriptorType nodes */
GList *Viewpoint;
2013-05-08 14:13:32 +00:00
/* RepresentationBase extension */
GstRepresentationBaseType *RepresentationBase;
/* SegmentBase node */
GstSegmentBaseType *SegmentBase;
/* SegmentList node */
GstSegmentListNode *SegmentList;
2013-05-08 14:13:32 +00:00
/* SegmentTemplate node */
GstSegmentTemplateNode *SegmentTemplate;
/* list of BaseURL nodes */
GList *BaseURLs;
/* list of Representation nodes */
GList *Representations;
/* list of ContentComponent nodes */
GList *ContentComponents;
gchar *xlink_href;
GstXLinkActuate actuate;
2013-05-08 14:13:32 +00:00
};
struct _GstSubsetNode
{
guint *contains; /* UIntVectorType */
guint size; /* size of the "contains" array */
};
struct _GstPeriodNode
{
gchar *id;
guint64 start; /* [ms] */
guint64 duration; /* [ms] */
2013-05-08 14:13:32 +00:00
gboolean bitstreamSwitching;
/* SegmentBase node */
GstSegmentBaseType *SegmentBase;
/* SegmentList node */
GstSegmentListNode *SegmentList;
2013-05-08 14:13:32 +00:00
/* SegmentTemplate node */
GstSegmentTemplateNode *SegmentTemplate;
/* list of Adaptation Set nodes */
GList *AdaptationSets;
/* list of Representation nodes */
GList *Subsets;
/* list of BaseURL nodes */
GList *BaseURLs;
gchar *xlink_href;
GstXLinkActuate actuate;
2013-05-08 14:13:32 +00:00
};
struct _GstProgramInformationNode
{
gchar *lang; /* LangVectorType RFC 5646 */
2013-05-08 14:13:32 +00:00
gchar *moreInformationURL;
/* children nodes */
gchar *Title;
gchar *Source;
gchar *Copyright;
};
struct _GstMetricsRangeNode
{
guint64 starttime; /* [ms] */
guint64 duration; /* [ms] */
2013-05-08 14:13:32 +00:00
};
struct _GstMetricsNode
{
gchar *metrics;
/* list of Metrics Range nodes */
GList *MetricsRanges;
/* list of Reporting nodes */
GList *Reportings;
};
dashdemux: add support for UTCTiming elements for clock drift compensation Unless the DASH client can compensate for the difference between its clock and the clock used by the server, the client might request fragments that either not yet on the server or fragments that have already been expired from the server. This is an issue because these requests can propagate all the way back to the origin ISO/IEC 23009-1:2014/Amd 1 [PDAM1] defines a new UTCTiming element to allow a DASH client to track the clock used by the server generating the DASH stream. Multiple UTCTiming elements might be present, to indicate support for multiple methods of UTC time gathering. Each element can contain a white space separated list of URLs that can be contacted to discover the UTC time from the server's perspective. This commit provides parsing of UTCTiming elements, unit tests of this parsing and a function to poll a time server. This function supports the following methods: urn:mpeg:dash:utc:ntp:2014 urn:mpeg:dash:utc:http-xsdate:2014 urn:mpeg:dash:utc:http-iso:2014 urn:mpeg:dash:utc:http-ntp:2014 The manifest update task is used to poll the clock time server, to save having to create a new thread. When choosing the starting fragment number and when waiting for a fragment to become available, the difference between the server's idea of UTC and the client's idea of UTC is taken into account. For example, if the server's time is behind the client's idea of UTC, we wait for longer before requesting a fragment [PDAM1]: http://www.iso.org/iso/home/store/catalogue_tc/catalogue_detail.htm?csnumber=66068 dashdemux: support NTP time servers in UTCTiming elements Use the gst_ntp_clock to support the use of an NTP server. https://bugzilla.gnome.org/show_bug.cgi?id=752413
2015-07-15 10:56:13 +00:00
struct _GstUTCTimingNode {
GstMPDUTCTimingType method;
/* NULL terminated array of strings */
gchar **urls;
};
2013-05-08 14:13:32 +00:00
struct _GstMPDNode
{
gchar *default_namespace;
gchar *namespace_xsi;
gchar *namespace_ext;
gchar *schemaLocation;
gchar *id;
gchar *profiles;
GstMPDFileType type;
GstDateTime *availabilityStartTime;
GstDateTime *availabilityEndTime;
guint64 mediaPresentationDuration; /* [ms] */
guint64 minimumUpdatePeriod; /* [ms] */
guint64 minBufferTime; /* [ms] */
guint64 timeShiftBufferDepth; /* [ms] */
guint64 suggestedPresentationDelay; /* [ms] */
guint64 maxSegmentDuration; /* [ms] */
guint64 maxSubsegmentDuration; /* [ms] */
2013-05-08 14:13:32 +00:00
/* list of BaseURL nodes */
GList *BaseURLs;
/* list of Location nodes */
GList *Locations;
/* List of ProgramInformation nodes */
GList *ProgramInfo;
2013-05-08 14:13:32 +00:00
/* list of Periods nodes */
GList *Periods;
/* list of Metrics nodes */
GList *Metrics;
dashdemux: add support for UTCTiming elements for clock drift compensation Unless the DASH client can compensate for the difference between its clock and the clock used by the server, the client might request fragments that either not yet on the server or fragments that have already been expired from the server. This is an issue because these requests can propagate all the way back to the origin ISO/IEC 23009-1:2014/Amd 1 [PDAM1] defines a new UTCTiming element to allow a DASH client to track the clock used by the server generating the DASH stream. Multiple UTCTiming elements might be present, to indicate support for multiple methods of UTC time gathering. Each element can contain a white space separated list of URLs that can be contacted to discover the UTC time from the server's perspective. This commit provides parsing of UTCTiming elements, unit tests of this parsing and a function to poll a time server. This function supports the following methods: urn:mpeg:dash:utc:ntp:2014 urn:mpeg:dash:utc:http-xsdate:2014 urn:mpeg:dash:utc:http-iso:2014 urn:mpeg:dash:utc:http-ntp:2014 The manifest update task is used to poll the clock time server, to save having to create a new thread. When choosing the starting fragment number and when waiting for a fragment to become available, the difference between the server's idea of UTC and the client's idea of UTC is taken into account. For example, if the server's time is behind the client's idea of UTC, we wait for longer before requesting a fragment [PDAM1]: http://www.iso.org/iso/home/store/catalogue_tc/catalogue_detail.htm?csnumber=66068 dashdemux: support NTP time servers in UTCTiming elements Use the gst_ntp_clock to support the use of an NTP server. https://bugzilla.gnome.org/show_bug.cgi?id=752413
2015-07-15 10:56:13 +00:00
/* list of GstUTCTimingNode nodes */
GList *UTCTiming;
2013-05-08 14:13:32 +00:00
};
/**
* GstStreamPeriod:
*
* Stream period data structure
*/
struct _GstStreamPeriod
{
GstPeriodNode *period; /* Stream period */
guint number; /* Period number */
GstClockTime start; /* Period start time */
GstClockTime duration; /* Period duration */
};
2013-05-08 14:13:32 +00:00
/**
* GstMediaSegment:
*
* Media segment data structure
*/
struct _GstMediaSegment
{
GstSegmentURLNode *SegmentURL; /* this is NULL when using a SegmentTemplate */
guint number; /* segment number */
gint repeat; /* number of extra repetitions (0 = played only once) */
guint64 scale_start; /* start time in timescale units */
guint64 scale_duration; /* duration in timescale units */
GstClockTime start; /* segment start time */
2013-05-08 14:13:32 +00:00
GstClockTime duration; /* segment duration */
};
struct _GstMediaFragmentInfo
{
gchar *uri;
gint64 range_start;
gint64 range_end;
gchar *index_uri;
gint64 index_range_start;
gint64 index_range_end;
gboolean discontinuity;
GstClockTime timestamp;
GstClockTime duration;
};
2013-05-08 14:13:32 +00:00
/**
* GstActiveStream:
*
* Active stream data structure
*/
struct _GstActiveStream
{
GstStreamMimeType mimeType; /* video/audio/application */
guint baseURL_idx; /* index of the baseURL used for last request */
gchar *baseURL; /* active baseURL used for last request */
gchar *queryURL; /* active queryURL used for last request */
2013-05-08 14:13:32 +00:00
guint max_bandwidth; /* max bandwidth allowed for this mimeType */
GstAdaptationSetNode *cur_adapt_set; /* active adaptation set */
gint representation_idx; /* index of current representation */
GstRepresentationNode *cur_representation; /* active representation */
GstSegmentBaseType *cur_segment_base; /* active segment base */
GstSegmentListNode *cur_segment_list; /* active segment list */
GstSegmentTemplateNode *cur_seg_template; /* active segment template */
gint segment_index; /* index of next sequence chunk */
guint segment_repeat_index; /* index of the repeat count of a segment */
GPtrArray *segments; /* array of GstMediaSegment */
GstClockTime presentationTimeOffset; /* presentation time offset of the current segment */
2013-05-08 14:13:32 +00:00
};
/* MPD file parsing */
gboolean gst_mpdparser_get_mpd_node (GstMPDNode ** mpd_node, const gchar * data, gint size);
GstSegmentListNode * gst_mpdparser_get_external_segment_list (const gchar * data, gint size, GstSegmentListNode * parent);
GList * gst_mpdparser_get_external_periods (const gchar * data, gint size);
GList * gst_mpdparser_get_external_adaptation_sets (const gchar * data, gint size, GstPeriodNode* period);
/* navigation functions */
GstStreamMimeType gst_mpdparser_representation_get_mimetype (GstAdaptationSetNode * adapt_set, GstRepresentationNode * rep);
/* Memory management */
void gst_mpdparser_free_mpd_node (GstMPDNode * mpd_node);
void gst_mpdparser_free_period_node (GstPeriodNode * period_node);
void gst_mpdparser_free_adaptation_set_node (GstAdaptationSetNode * adaptation_set_node);
void gst_mpdparser_free_segment_list_node (GstSegmentListNode * segment_list_node);
void gst_mpdparser_free_stream_period (GstStreamPeriod * stream_period);
void gst_mpdparser_free_media_segment (GstMediaSegment * media_segment);
void gst_mpdparser_free_active_stream (GstActiveStream * active_stream);
void gst_mpdparser_free_base_url_node (GstBaseURL * base_url_node);
/* Active stream methods*/
void gst_mpdparser_init_active_stream_segments (GstActiveStream * stream);
gchar *gst_mpdparser_get_mediaURL (GstActiveStream * stream, GstSegmentURLNode * segmentURL);
const gchar *gst_mpdparser_get_initializationURL (GstActiveStream * stream, GstURLType * InitializationURL);
/*Helper methods */
gchar *gst_mpdparser_build_URL_from_template (const gchar * url_template, const gchar * id, guint number, guint bandwidth, guint64 time);
const gchar *gst_mpdparser_mimetype_to_caps (const gchar * mimeType);
GstUri *combine_urls (GstUri * base, GList * list, gchar ** query, guint idx);
int strncmp_ext (const char *s1, const char *s2);
2013-05-08 14:13:32 +00:00
G_END_DECLS
#endif /* __GST_MPDPARSER_H__ */