2011-02-14 17:51:32 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2010 Marc-Andre Lureau <marcandre.lureau@gmail.com>
|
|
|
|
* Copyright (C) 2010 Andoni Morales Alastruey <ylatuya@gmail.com>
|
2015-12-05 11:12:33 +00:00
|
|
|
* Copyright (C) 2015 Tim-Philipp Müller <tim@centricular.com>
|
2011-02-14 17:51:32 +00:00
|
|
|
*
|
|
|
|
* m3u8.h:
|
|
|
|
*
|
|
|
|
* 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 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
|
|
|
|
* License along with this library; if not, write to the
|
2012-11-03 20:38:00 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2011-02-14 17:51:32 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __M3U8_H__
|
|
|
|
#define __M3U8_H__
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
2015-08-30 16:22:19 +00:00
|
|
|
G_BEGIN_DECLS
|
|
|
|
|
|
|
|
typedef struct _GstM3U8 GstM3U8;
|
2011-02-14 17:51:32 +00:00
|
|
|
typedef struct _GstM3U8MediaFile GstM3U8MediaFile;
|
2015-12-05 11:12:33 +00:00
|
|
|
typedef struct _GstHLSMedia GstHLSMedia;
|
2011-02-14 17:51:32 +00:00
|
|
|
typedef struct _GstM3U8Client GstM3U8Client;
|
2015-12-05 11:12:33 +00:00
|
|
|
typedef struct _GstHLSVariantStream GstHLSVariantStream;
|
|
|
|
typedef struct _GstHLSMasterPlaylist GstHLSMasterPlaylist;
|
2011-02-14 17:51:32 +00:00
|
|
|
|
2011-08-18 23:54:59 +00:00
|
|
|
#define GST_M3U8(m) ((GstM3U8*)m)
|
2011-02-14 17:51:32 +00:00
|
|
|
#define GST_M3U8_MEDIA_FILE(f) ((GstM3U8MediaFile*)f)
|
|
|
|
|
2015-11-27 19:26:02 +00:00
|
|
|
#define GST_M3U8_LOCK(m) g_mutex_lock (&m->lock);
|
|
|
|
#define GST_M3U8_UNLOCK(m) g_mutex_unlock (&m->lock);
|
2011-09-02 23:48:03 +00:00
|
|
|
|
2015-11-27 19:26:02 +00:00
|
|
|
#define GST_M3U8_IS_LIVE(m) ((m)->endlist == FALSE)
|
2014-10-02 16:37:57 +00:00
|
|
|
|
2015-02-20 13:55:05 +00:00
|
|
|
/* hlsdemux must not get closer to the end of a live stream than
|
|
|
|
GST_M3U8_LIVE_MIN_FRAGMENT_DISTANCE fragments. Section 6.3.3
|
|
|
|
"Playing the Playlist file" of the HLS draft states that this
|
|
|
|
value is three fragments */
|
|
|
|
#define GST_M3U8_LIVE_MIN_FRAGMENT_DISTANCE 3
|
|
|
|
|
2011-02-14 17:51:32 +00:00
|
|
|
struct _GstM3U8
|
|
|
|
{
|
2014-05-28 08:19:40 +00:00
|
|
|
gchar *uri; /* actually downloaded URI */
|
|
|
|
gchar *base_uri; /* URI to use as base for resolving relative URIs.
|
|
|
|
* This will be different to uri in case of redirects */
|
2014-05-30 22:34:18 +00:00
|
|
|
gchar *name; /* This will be the "name" of the playlist, the original
|
|
|
|
* relative/absolute uri in a variant playlist */
|
2011-02-14 17:51:32 +00:00
|
|
|
|
2015-11-27 19:26:02 +00:00
|
|
|
/* parsed info */
|
2011-02-14 17:51:32 +00:00
|
|
|
gboolean endlist; /* if ENDLIST has been reached */
|
|
|
|
gint version; /* last EXT-X-VERSION */
|
2012-02-28 15:40:31 +00:00
|
|
|
GstClockTime targetduration; /* last EXT-X-TARGETDURATION */
|
2014-05-05 07:34:56 +00:00
|
|
|
gboolean allowcache; /* last EXT-X-ALLOWCACHE */
|
2011-02-14 17:51:32 +00:00
|
|
|
|
|
|
|
GList *files;
|
|
|
|
|
2015-11-27 19:26:02 +00:00
|
|
|
/* state */
|
|
|
|
GList *current_file;
|
|
|
|
GstClockTime current_file_duration; /* Duration of current fragment */
|
|
|
|
gint64 sequence; /* the next sequence for this client */
|
|
|
|
GstClockTime sequence_position; /* position of this sequence */
|
|
|
|
gint64 highest_sequence_number; /* largest seen sequence number */
|
|
|
|
GstClockTime first_file_start; /* timecode of the start of the first fragment in the current media playlist */
|
|
|
|
GstClockTime last_file_end; /* timecode of the end of the last fragment in the current media playlist */
|
|
|
|
GstClockTime duration; /* cached total duration */
|
2016-10-10 22:41:15 +00:00
|
|
|
gint discont_sequence; /* currently expected EXT-X-DISCONTINUITY-SEQUENCE */
|
2015-11-27 19:26:02 +00:00
|
|
|
|
2011-02-14 17:51:32 +00:00
|
|
|
/*< private > */
|
|
|
|
gchar *last_data;
|
2015-11-27 19:26:02 +00:00
|
|
|
GMutex lock;
|
|
|
|
|
|
|
|
gint ref_count; /* ATOMIC */
|
2011-02-14 17:51:32 +00:00
|
|
|
};
|
|
|
|
|
2015-11-27 19:26:02 +00:00
|
|
|
GstM3U8 * gst_m3u8_ref (GstM3U8 * m3u8);
|
|
|
|
|
|
|
|
void gst_m3u8_unref (GstM3U8 * m3u8);
|
|
|
|
|
|
|
|
|
2011-02-14 17:51:32 +00:00
|
|
|
struct _GstM3U8MediaFile
|
|
|
|
{
|
|
|
|
gchar *title;
|
2012-02-28 15:40:31 +00:00
|
|
|
GstClockTime duration;
|
2011-02-14 17:51:32 +00:00
|
|
|
gchar *uri;
|
2014-03-09 18:31:31 +00:00
|
|
|
gint64 sequence; /* the sequence nb of this file */
|
2014-03-01 16:13:58 +00:00
|
|
|
gboolean discont; /* this file marks a discontinuity */
|
2013-03-19 07:49:21 +00:00
|
|
|
gchar *key;
|
|
|
|
guint8 iv[16];
|
2014-03-05 09:47:01 +00:00
|
|
|
gint64 offset, size;
|
2015-11-27 19:26:02 +00:00
|
|
|
gint ref_count; /* ATOMIC */
|
2011-02-14 17:51:32 +00:00
|
|
|
};
|
|
|
|
|
2015-11-27 19:26:02 +00:00
|
|
|
GstM3U8MediaFile * gst_m3u8_media_file_ref (GstM3U8MediaFile * mfile);
|
2015-08-30 16:22:19 +00:00
|
|
|
|
2015-11-27 19:26:02 +00:00
|
|
|
void gst_m3u8_media_file_unref (GstM3U8MediaFile * mfile);
|
2015-08-30 16:22:19 +00:00
|
|
|
|
2015-11-27 19:26:02 +00:00
|
|
|
GstM3U8 * gst_m3u8_new (void);
|
2015-08-30 16:22:19 +00:00
|
|
|
|
2015-11-27 19:26:02 +00:00
|
|
|
gboolean gst_m3u8_update (GstM3U8 * m3u8,
|
|
|
|
gchar * data);
|
2015-08-30 16:22:19 +00:00
|
|
|
|
2015-11-27 19:26:02 +00:00
|
|
|
void gst_m3u8_set_uri (GstM3U8 * m3u8,
|
|
|
|
const gchar * uri,
|
|
|
|
const gchar * base_uri,
|
|
|
|
const gchar * name);
|
2015-08-30 16:22:19 +00:00
|
|
|
|
2015-11-27 19:26:02 +00:00
|
|
|
GstM3U8MediaFile * gst_m3u8_get_next_fragment (GstM3U8 * m3u8,
|
|
|
|
gboolean forward,
|
|
|
|
GstClockTime * sequence_position,
|
|
|
|
gboolean * discont);
|
2015-08-30 16:22:19 +00:00
|
|
|
|
2015-11-27 19:26:02 +00:00
|
|
|
gboolean gst_m3u8_has_next_fragment (GstM3U8 * m3u8,
|
|
|
|
gboolean forward);
|
2015-08-30 16:22:19 +00:00
|
|
|
|
2015-11-27 19:26:02 +00:00
|
|
|
void gst_m3u8_advance_fragment (GstM3U8 * m3u8,
|
|
|
|
gboolean forward);
|
2015-08-30 16:22:19 +00:00
|
|
|
|
2015-11-27 19:26:02 +00:00
|
|
|
GstClockTime gst_m3u8_get_duration (GstM3U8 * m3u8);
|
2015-08-30 16:22:19 +00:00
|
|
|
|
2015-11-27 19:26:02 +00:00
|
|
|
GstClockTime gst_m3u8_get_target_duration (GstM3U8 * m3u8);
|
2015-08-30 16:22:19 +00:00
|
|
|
|
2015-11-27 19:26:02 +00:00
|
|
|
gchar * gst_m3u8_get_uri (GstM3U8 * m3u8);
|
2015-08-30 16:22:19 +00:00
|
|
|
|
2015-11-27 19:26:02 +00:00
|
|
|
gboolean gst_m3u8_is_live (GstM3U8 * m3u8);
|
2015-08-30 16:22:19 +00:00
|
|
|
|
2015-11-27 19:26:02 +00:00
|
|
|
gboolean gst_m3u8_get_seek_range (GstM3U8 * m3u8,
|
|
|
|
gint64 * start,
|
|
|
|
gint64 * stop);
|
2015-08-30 16:22:19 +00:00
|
|
|
|
2015-12-05 11:12:33 +00:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
GST_HLS_MEDIA_TYPE_INVALID = -1,
|
|
|
|
GST_HLS_MEDIA_TYPE_AUDIO,
|
|
|
|
GST_HLS_MEDIA_TYPE_VIDEO,
|
|
|
|
GST_HLS_MEDIA_TYPE_SUBTITLES,
|
|
|
|
GST_HLS_MEDIA_TYPE_CLOSED_CAPTIONS,
|
|
|
|
GST_HLS_N_MEDIA_TYPES
|
|
|
|
} GstHLSMediaType;
|
|
|
|
|
|
|
|
struct _GstHLSMedia {
|
|
|
|
GstHLSMediaType mtype;
|
|
|
|
gchar *group_id;
|
|
|
|
gchar *name;
|
|
|
|
gchar *lang;
|
|
|
|
gchar *uri;
|
|
|
|
gboolean is_default;
|
|
|
|
gboolean autoselect;
|
|
|
|
gboolean forced;
|
|
|
|
|
|
|
|
GstM3U8 *playlist; /* media playlist */
|
|
|
|
|
|
|
|
gint ref_count; /* ATOMIC */
|
|
|
|
};
|
|
|
|
|
|
|
|
GstHLSMedia * gst_hls_media_ref (GstHLSMedia * media);
|
|
|
|
|
|
|
|
void gst_hls_media_unref (GstHLSMedia * media);
|
|
|
|
|
|
|
|
|
|
|
|
struct _GstHLSVariantStream {
|
|
|
|
gchar *name; /* This will be the "name" of the playlist, the original
|
|
|
|
* relative/absolute uri in a variant playlist */
|
|
|
|
gchar *uri;
|
|
|
|
gchar *codecs;
|
|
|
|
gint bandwidth;
|
|
|
|
gint program_id;
|
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
gboolean iframe;
|
|
|
|
|
|
|
|
gint refcount; /* ATOMIC */
|
|
|
|
|
|
|
|
GstM3U8 *m3u8; /* media playlist */
|
|
|
|
|
|
|
|
/* alternative renditions */
|
|
|
|
gchar *media_groups[GST_HLS_N_MEDIA_TYPES];
|
|
|
|
GList *media[GST_HLS_N_MEDIA_TYPES];
|
|
|
|
};
|
|
|
|
|
|
|
|
GstHLSVariantStream * gst_hls_variant_stream_ref (GstHLSVariantStream * stream);
|
|
|
|
|
|
|
|
void gst_hls_variant_stream_unref (GstHLSVariantStream * stream);
|
|
|
|
|
|
|
|
gboolean gst_hls_variant_stream_is_live (GstHLSVariantStream * stream);
|
|
|
|
|
2016-03-08 16:07:22 +00:00
|
|
|
GstHLSMedia * gst_hls_variant_find_matching_media (GstHLSVariantStream * stream,
|
|
|
|
GstHLSMedia *media);
|
|
|
|
|
2015-12-05 11:12:33 +00:00
|
|
|
|
|
|
|
struct _GstHLSMasterPlaylist
|
|
|
|
{
|
|
|
|
/* Available variant streams, sorted by bitrate (low -> high) */
|
|
|
|
GList *variants;
|
|
|
|
GList *iframe_variants;
|
|
|
|
|
|
|
|
GstHLSVariantStream *default_variant; /* first in the list */
|
|
|
|
|
|
|
|
gint version; /* EXT-X-VERSION */
|
|
|
|
|
|
|
|
gint refcount; /* ATOMIC */
|
|
|
|
|
|
|
|
gboolean is_simple; /* TRUE if simple main media playlist,
|
|
|
|
* FALSE if variant playlist (either
|
|
|
|
* way the variants list will be set) */
|
|
|
|
|
|
|
|
/*< private > */
|
|
|
|
gchar *last_data;
|
|
|
|
};
|
|
|
|
|
|
|
|
GstHLSMasterPlaylist * gst_hls_master_playlist_new_from_data (gchar * data,
|
|
|
|
const gchar * base_uri);
|
|
|
|
|
|
|
|
GstHLSVariantStream * gst_hls_master_playlist_get_variant_for_bitrate (GstHLSMasterPlaylist * playlist,
|
|
|
|
GstHLSVariantStream * current_variant,
|
|
|
|
guint bitrate);
|
2016-03-08 16:07:22 +00:00
|
|
|
GstHLSVariantStream * gst_hls_master_playlist_get_matching_variant (GstHLSMasterPlaylist * playlist,
|
|
|
|
GstHLSVariantStream * current_variant);
|
2015-12-05 11:12:33 +00:00
|
|
|
|
|
|
|
void gst_hls_master_playlist_unref (GstHLSMasterPlaylist * playlist);
|
2014-04-04 15:45:51 +00:00
|
|
|
|
2011-02-14 17:51:32 +00:00
|
|
|
G_END_DECLS
|
2015-08-30 16:22:19 +00:00
|
|
|
|
2011-02-14 17:51:32 +00:00
|
|
|
#endif /* __M3U8_H__ */
|