dashdemux: Preserve current representation on live manifest updates
[platform/upstream/gstreamer.git] / subprojects / gst-plugins-bad / ext / dash / gstmpdclient.h
1 /* GStreamer
2  *
3  * Copyright (C) 2019 Collabora Ltd.
4  *   Author: Stéphane Cerveau <scerveau@collabora.com>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library (COPYING); if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 #ifndef __GST_MPDCLIENT_H__
22 #define __GST_MPDCLIENT_H__
23
24 #include "gstmpdparser.h"
25
26 G_BEGIN_DECLS
27
28 #define GST_TYPE_MPD_CLIENT gst_mpd_client_get_type ()
29 G_DECLARE_FINAL_TYPE (GstMPDClient, gst_mpd_client, GST, MPD_CLIENT, GstObject)
30
31 struct _GstMPDClient
32 {
33   GstObject     parent_instance;
34   GstMPDRootNode *mpd_root_node;              /* mpd root node */
35
36   GList *periods;                             /* list of GstStreamPeriod */
37   guint period_idx;                           /* index of current Period */
38
39   GList *active_streams;                      /* list of GstActiveStream */
40
41   guint update_failed_count;
42   gchar *mpd_uri;                             /* manifest file URI */
43   gchar *mpd_base_uri;                        /* base URI for resolving relative URIs.
44                                                * this will be different for redirects */
45
46   /* profiles */
47   gboolean profile_isoff_ondemand;
48
49   GstUriDownloader * downloader;
50 };
51
52 /* Basic initialization/deinitialization functions */
53
54 GstMPDClient *gst_mpd_client_new (void);
55 GstMPDClient *gst_mpd_client_new_static (void);
56
57 void gst_mpd_client_active_streams_free (GstMPDClient * client);
58 void gst_mpd_client_free (GstMPDClient * client);
59
60 /* main mpd parsing methods from xml data */
61 gboolean gst_mpd_client_parse (GstMPDClient * client, const gchar * data, gint size);
62
63 /* xml generator */
64 gboolean gst_mpd_client_get_xml_content (GstMPDClient * client, gchar ** data, gint * size);
65
66 void gst_mpd_client_set_uri_downloader (GstMPDClient * client, GstUriDownloader * download);
67 void  gst_mpd_client_check_profiles (GstMPDClient * client);
68 void gst_mpd_client_fetch_on_load_external_resources (GstMPDClient * client);
69
70 /* Streaming management */
71 gboolean gst_mpd_client_setup_media_presentation (GstMPDClient *client, GstClockTime time, gint period_index, const gchar *period_id);
72 gboolean gst_mpd_client_setup_streaming (GstMPDClient * client, GstMPDAdaptationSetNode * adapt_set);
73 gboolean gst_mpd_client_setup_representation (GstMPDClient *client, GstActiveStream *stream, GstMPDRepresentationNode *representation);
74
75 GstClockTime gst_mpd_client_get_next_fragment_duration (GstMPDClient * client, GstActiveStream * stream);
76 GstClockTime gst_mpd_client_get_media_presentation_duration (GstMPDClient *client);
77 GstClockTime gst_mpd_client_get_maximum_segment_duration (GstMPDClient * client);
78 gboolean gst_mpd_client_get_last_fragment_timestamp_end (GstMPDClient * client, guint stream_idx, GstClockTime * ts);
79 gboolean gst_mpd_client_get_next_fragment_timestamp (GstMPDClient * client, guint stream_idx, GstClockTime * ts);
80 gboolean gst_mpd_client_get_next_fragment (GstMPDClient *client, guint indexStream, GstMediaFragmentInfo * fragment);
81 gboolean gst_mpd_client_get_next_header (GstMPDClient *client, gchar **uri, guint stream_idx, gint64 * range_start, gint64 * range_end);
82 gboolean gst_mpd_client_get_next_header_index (GstMPDClient *client, gchar **uri, guint stream_idx, gint64 * range_start, gint64 * range_end);
83 gboolean gst_mpd_client_is_live (GstMPDClient * client);
84 gboolean gst_mpd_client_stream_seek (GstMPDClient * client, GstActiveStream * stream, gboolean forward, GstSeekFlags flags, GstClockTime ts, GstClockTime * final_ts);
85 gboolean gst_mpd_client_seek_to_time (GstMPDClient * client, GDateTime * time);
86 GstClockTime gst_mpd_client_get_stream_presentation_offset (GstMPDClient *client, guint stream_idx);
87 gchar** gst_mpd_client_get_utc_timing_sources (GstMPDClient *client, guint methods, GstMPDUTCTimingType *selected_method);
88 GstClockTime gst_mpd_client_get_period_start_time (GstMPDClient *client);
89
90 /* Period selection */
91 guint gst_mpd_client_get_period_index_at_time (GstMPDClient * client, GstDateTime * time);
92 gboolean gst_mpd_client_set_period_index (GstMPDClient *client, guint period_idx);
93 gboolean gst_mpd_client_set_period_id (GstMPDClient *client, const gchar * period_id);
94 guint gst_mpd_client_get_period_index (GstMPDClient *client);
95 const gchar *gst_mpd_client_get_period_id (GstMPDClient *client);
96 gboolean gst_mpd_client_has_next_period (GstMPDClient *client);
97 gboolean gst_mpd_client_has_previous_period (GstMPDClient * client);
98
99 /* Representation selection */
100 gint gst_mpd_client_get_rep_idx_with_max_bandwidth (GList *Representations, gint64 max_bandwidth, gint max_video_width, gint max_video_height, gint max_video_framerate_n, gint max_video_framerate_d);
101 gint gst_mpd_client_get_rep_idx_with_min_bandwidth (GList * Representations);
102 GstMPDRepresentationNode* gst_mpd_client_get_representation_with_id (GList * representations, gchar * rep_id);
103
104
105 GstDateTime *
106 gst_mpd_client_get_availability_start_time (GstMPDClient * client);
107
108 /* URL management */
109 const gchar *gst_mpd_client_get_baseURL (GstMPDClient *client, guint indexStream);
110 gchar *gst_mpd_client_parse_baseURL (GstMPDClient * client, GstActiveStream * stream, gchar ** query);
111
112 /* Active stream */
113 guint gst_mpd_client_get_nb_active_stream (GstMPDClient *client);
114 GstActiveStream *gst_mpd_client_get_active_stream_by_index (GstMPDClient *client, guint stream_idx);
115 gboolean gst_mpd_client_active_stream_contains_subtitles (GstActiveStream * stream);
116
117 /* AdaptationSet */
118 guint gst_mpd_client_get_nb_adaptationSet (GstMPDClient *client);
119 GList * gst_mpd_client_get_adaptation_sets (GstMPDClient * client);
120
121 /* Segment */
122 gboolean gst_mpd_client_has_next_segment (GstMPDClient * client, GstActiveStream * stream, gboolean forward);
123 GstFlowReturn gst_mpd_client_advance_segment (GstMPDClient * client, GstActiveStream * stream, gboolean forward);
124 void gst_mpd_client_seek_to_first_segment (GstMPDClient * client);
125 GstDateTime *gst_mpd_client_get_next_segment_availability_start_time (GstMPDClient * client, GstActiveStream * stream);
126
127 /* Get audio/video stream parameters (caps, width, height, rate, number of channels) */
128 GstCaps * gst_mpd_client_get_stream_caps (GstActiveStream * stream);
129 gboolean gst_mpd_client_get_bitstream_switching_flag (GstActiveStream * stream);
130 guint gst_mpd_client_get_video_stream_width (GstActiveStream * stream);
131 guint gst_mpd_client_get_video_stream_height (GstActiveStream * stream);
132 gboolean gst_mpd_client_get_video_stream_framerate (GstActiveStream * stream, gint * fps_num, gint * fps_den);
133 guint gst_mpd_client_get_audio_stream_rate (GstActiveStream * stream);
134 guint gst_mpd_client_get_audio_stream_num_channels (GstActiveStream * stream);
135
136 /* Support multi language */
137 guint gst_mpd_client_get_list_and_nb_of_audio_language (GstMPDClient *client, GList **lang);
138
139 gint64 gst_mpd_client_calculate_time_difference (const GstDateTime * t1, const GstDateTime * t2);
140 GstDateTime *gst_mpd_client_add_time_difference (GstDateTime * t1, gint64 usecs);
141 gint64 gst_mpd_client_parse_default_presentation_delay(GstMPDClient * client, const gchar * default_presentation_delay);
142
143 /* profiles */
144 gboolean gst_mpd_client_has_isoff_ondemand_profile (GstMPDClient *client);
145
146 /* add/set node methods */
147 gboolean gst_mpd_client_set_root_node (GstMPDClient * client,
148                                        const gchar * property_name,
149                                        ...);
150 gchar * gst_mpd_client_set_period_node (GstMPDClient * client,
151                                         gchar * period_id,
152                                         const gchar * property_name,
153                                         ...);
154 guint gst_mpd_client_set_adaptation_set_node (GstMPDClient * client,
155                                               gchar * period_id,
156                                               guint adap_set_id,
157                                               const gchar * property_name,
158                                               ...);
159 gchar * gst_mpd_client_set_representation_node (GstMPDClient * client,
160                                                 gchar * period_id,
161                                                 guint adap_set_id,
162                                                 gchar * rep_id,
163                                                 const gchar * property_name,
164                                                 ...);
165 gboolean gst_mpd_client_set_segment_list (GstMPDClient * client,
166                                           gchar * period_id,
167                                           guint adap_set_id,
168                                           gchar * rep_id,
169                                           const gchar * property_name,
170                                           ...);
171 gboolean gst_mpd_client_set_segment_template (GstMPDClient * client,
172                                               gchar * period_id,
173                                               guint adap_set_id,
174                                               gchar * rep_id,
175                                               const gchar * property_name,
176                                               ...);
177
178 /* create a new node */
179 gboolean gst_mpd_client_add_baseurl_node (GstMPDClient * client,
180                                           const gchar * property_name,
181                                           ...);
182 gboolean gst_mpd_client_add_segment_url (GstMPDClient * client,
183                                          gchar * period_id,
184                                          guint adap_set_id,
185                                          gchar * rep_id,
186                                          const gchar * property_name,
187                                          ...);
188 G_END_DECLS
189
190 #endif /* __GST_MPDCLIENT_H__ */