2 * Copyright (C) 2010 Marc-Andre Lureau <marcandre.lureau@gmail.com>
3 * Copyright (C) 2010 Andoni Morales Alastruey <ylatuya@gmail.com>
4 * Copyright (C) 2015 Tim-Philipp Müller <tim@centricular.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
31 typedef struct _GstM3U8 GstM3U8;
32 typedef struct _GstM3U8MediaFile GstM3U8MediaFile;
33 typedef struct _GstHLSMedia GstHLSMedia;
34 typedef struct _GstM3U8Client GstM3U8Client;
35 typedef struct _GstHLSVariantStream GstHLSVariantStream;
36 typedef struct _GstHLSMasterPlaylist GstHLSMasterPlaylist;
38 #define GST_M3U8(m) ((GstM3U8*)m)
39 #define GST_M3U8_MEDIA_FILE(f) ((GstM3U8MediaFile*)f)
41 #define GST_M3U8_LOCK(m) g_mutex_lock (&m->lock);
42 #define GST_M3U8_UNLOCK(m) g_mutex_unlock (&m->lock);
44 #define GST_M3U8_IS_LIVE(m) ((m)->endlist == FALSE)
46 /* hlsdemux must not get closer to the end of a live stream than
47 GST_M3U8_LIVE_MIN_FRAGMENT_DISTANCE fragments. Section 6.3.3
48 "Playing the Playlist file" of the HLS draft states that this
49 value is three fragments */
50 #define GST_M3U8_LIVE_MIN_FRAGMENT_DISTANCE 3
54 gchar *uri; /* actually downloaded URI */
55 gchar *base_uri; /* URI to use as base for resolving relative URIs.
56 * This will be different to uri in case of redirects */
57 gchar *name; /* This will be the "name" of the playlist, the original
58 * relative/absolute uri in a variant playlist */
61 gboolean endlist; /* if ENDLIST has been reached */
62 gint version; /* last EXT-X-VERSION */
63 GstClockTime targetduration; /* last EXT-X-TARGETDURATION */
64 gboolean allowcache; /* last EXT-X-ALLOWCACHE */
70 GstClockTime current_file_duration; /* Duration of current fragment */
71 gint64 sequence; /* the next sequence for this client */
72 GstClockTime sequence_position; /* position of this sequence */
73 gint64 highest_sequence_number; /* largest seen sequence number */
74 GstClockTime first_file_start; /* timecode of the start of the first fragment in the current media playlist */
75 GstClockTime last_file_end; /* timecode of the end of the last fragment in the current media playlist */
76 GstClockTime duration; /* cached total duration */
77 gint discont_sequence; /* currently expected EXT-X-DISCONTINUITY-SEQUENCE */
83 gint ref_count; /* ATOMIC */
86 GstM3U8 * gst_m3u8_ref (GstM3U8 * m3u8);
88 void gst_m3u8_unref (GstM3U8 * m3u8);
91 struct _GstM3U8MediaFile
94 GstClockTime duration;
96 gint64 sequence; /* the sequence nb of this file */
97 gboolean discont; /* this file marks a discontinuity */
101 gint ref_count; /* ATOMIC */
104 GstM3U8MediaFile * gst_m3u8_media_file_ref (GstM3U8MediaFile * mfile);
106 void gst_m3u8_media_file_unref (GstM3U8MediaFile * mfile);
108 GstM3U8 * gst_m3u8_new (void);
110 gboolean gst_m3u8_update (GstM3U8 * m3u8,
113 void gst_m3u8_set_uri (GstM3U8 * m3u8,
115 const gchar * base_uri,
118 GstM3U8MediaFile * gst_m3u8_get_next_fragment (GstM3U8 * m3u8,
120 GstClockTime * sequence_position,
123 gboolean gst_m3u8_has_next_fragment (GstM3U8 * m3u8,
126 void gst_m3u8_advance_fragment (GstM3U8 * m3u8,
129 GstClockTime gst_m3u8_get_duration (GstM3U8 * m3u8);
131 GstClockTime gst_m3u8_get_target_duration (GstM3U8 * m3u8);
133 gchar * gst_m3u8_get_uri (GstM3U8 * m3u8);
135 gboolean gst_m3u8_is_live (GstM3U8 * m3u8);
137 gboolean gst_m3u8_get_seek_range (GstM3U8 * m3u8,
143 GST_HLS_MEDIA_TYPE_INVALID = -1,
144 GST_HLS_MEDIA_TYPE_AUDIO,
145 GST_HLS_MEDIA_TYPE_VIDEO,
146 GST_HLS_MEDIA_TYPE_SUBTITLES,
147 GST_HLS_MEDIA_TYPE_CLOSED_CAPTIONS,
148 GST_HLS_N_MEDIA_TYPES
151 struct _GstHLSMedia {
152 GstHLSMediaType mtype;
161 GstM3U8 *playlist; /* media playlist */
163 gint ref_count; /* ATOMIC */
166 GstHLSMedia * gst_hls_media_ref (GstHLSMedia * media);
168 void gst_hls_media_unref (GstHLSMedia * media);
171 struct _GstHLSVariantStream {
172 gchar *name; /* This will be the "name" of the playlist, the original
173 * relative/absolute uri in a variant playlist */
182 gint refcount; /* ATOMIC */
184 GstM3U8 *m3u8; /* media playlist */
186 /* alternative renditions */
187 gchar *media_groups[GST_HLS_N_MEDIA_TYPES];
188 GList *media[GST_HLS_N_MEDIA_TYPES];
191 #ifdef TIZEN_FEATURE_ADAPTIVE_MODIFICATION
197 } GstM3U8VideoVariantInfo;
200 GstHLSVariantStream * gst_hls_variant_stream_ref (GstHLSVariantStream * stream);
202 void gst_hls_variant_stream_unref (GstHLSVariantStream * stream);
204 gboolean gst_hls_variant_stream_is_live (GstHLSVariantStream * stream);
206 GstHLSMedia * gst_hls_variant_find_matching_media (GstHLSVariantStream * stream,
210 struct _GstHLSMasterPlaylist
212 /* Available variant streams, sorted by bitrate (low -> high) */
214 GList *iframe_variants;
215 #ifdef TIZEN_FEATURE_ADAPTIVE_MODIFICATION
216 GList *variant_info; /* stream variant info */
218 GstHLSVariantStream *default_variant; /* first in the list */
220 gint version; /* EXT-X-VERSION */
222 gint refcount; /* ATOMIC */
224 gboolean is_simple; /* TRUE if simple main media playlist,
225 * FALSE if variant playlist (either
226 * way the variants list will be set) */
232 GstHLSMasterPlaylist * gst_hls_master_playlist_new_from_data (gchar * data,
233 const gchar * base_uri);
234 #ifdef TIZEN_FEATURE_ADAPTIVE_MODIFICATION
235 GstHLSVariantStream * gst_hls_master_playlist_get_variant_for_max_limit (GstHLSMasterPlaylist *playlist,
236 GstHLSVariantStream * current_variant,
237 guint bitrate, gint bandwidth,
238 gint width, gint height);
240 GstHLSVariantStream * gst_hls_master_playlist_get_variant_for_bitrate (GstHLSMasterPlaylist * playlist,
241 GstHLSVariantStream * current_variant,
244 GstHLSVariantStream * gst_hls_master_playlist_get_matching_variant (GstHLSMasterPlaylist * playlist,
245 GstHLSVariantStream * current_variant);
247 void gst_hls_master_playlist_unref (GstHLSMasterPlaylist * playlist);
251 #endif /* __M3U8_H__ */