| 1 |
/* GStreamer |
| 2 |
* Copyright (C) 2010 Marc-Andre Lureau <[email protected]> |
| 3 |
* Copyright (C) 2010 Andoni Morales Alastruey <[email protected]> |
| 4 |
* Copyright (C) 2015 Tim-Philipp Müller <[email protected]> |
| 5 |
* |
| 6 |
* gsthlsdemux.h: |
| 7 |
* |
| 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. |
| 12 |
* |
| 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. |
| 17 |
* |
| 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. |
| 22 |
*/ |
| 23 |
|
| 24 |
|
| 25 |
#ifndef __GST_HLS_DEMUX_H__ |
| 26 |
#define __GST_HLS_DEMUX_H__ |
| 27 |
|
| 28 |
#include <gst/gst.h> |
| 29 |
#include <gst/base/gstadapter.h> |
| 30 |
#include "m3u8.h" |
| 31 |
#include "gstisoff.h" |
| 32 |
#include "gstadaptivedemux.h" |
| 33 |
|
| 34 |
G_BEGIN_DECLS |
| 35 |
|
| 36 |
#define GST_TYPE_HLS_DEMUX2 \ |
| 37 |
(gst_hls_demux2_get_type()) |
| 38 |
#define GST_HLS_DEMUX(obj) \ |
| 39 |
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_HLS_DEMUX2,GstHLSDemux)) |
| 40 |
#define GST_HLS_DEMUX_CLASS(klass) \ |
| 41 |
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_HLS_DEMUX2,GstHLSDemuxClass)) |
| 42 |
#define GST_IS_HLS_DEMUX(obj) \ |
| 43 |
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_HLS_DEMUX2)) |
| 44 |
#define GST_IS_HLS_DEMUX_CLASS(klass) \ |
| 45 |
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_HLS_DEMUX2)) |
| 46 |
#define GST_HLS_DEMUX_GET_CLASS(obj) \ |
| 47 |
(G_TYPE_INSTANCE_GET_CLASS ((obj),GST_TYPE_HLS_DEMUX2,GstHLSDemuxClass)) |
| 48 |
#define GST_HLS_DEMUX_CAST(obj) \ |
| 49 |
((GstHLSDemux *)obj) |
| 50 |
|
| 51 |
typedef struct _GstHLSDemux2 GstHLSDemux; |
| 52 |
typedef struct _GstHLSDemux2Class GstHLSDemuxClass; |
| 53 |
|
| 54 |
typedef struct _GstHLSDemuxStream GstHLSDemuxStream; |
| 55 |
|
| 56 |
typedef enum { |
| 57 |
/* More data is needed to parse the fragment */ |
| 58 |
GST_HLS_PARSER_RESULT_NEED_MORE_DATA, |
| 59 |
/* An error happened, discard the fragment */ |
| 60 |
GST_HLS_PARSER_RESULT_ERROR, |
| 61 |
/* Parsing suceeded, it no longer needs to be called for the fragment */ |
| 62 |
GST_HLS_PARSER_RESULT_DONE, |
| 63 |
/* The fragment wasn't the expected one. Current data must be dropped and |
| 64 |
* GST_ADAPTIVE_DEMUX_FLOW_RESTART_FRAGMENT returned to the parent class */ |
| 65 |
GST_HLS_PARSER_RESULT_RESYNC |
| 66 |
} GstHLSParserResult; |
| 67 |
|
| 68 |
typedef struct { |
| 69 |
guint8 data[16]; |
| 70 |
} GstHLSKey; |
| 71 |
|
| 72 |
/** |
| 73 |
* GstHLSDemux: |
| 74 |
* |
| 75 |
* Opaque #GstHLSDemux data structure. |
| 76 |
*/ |
| 77 |
struct _GstHLSDemux2 |
| 78 |
{ |
| 79 |
GstAdaptiveDemux parent; |
| 80 |
|
| 81 |
/* Initial bitrate to use before any bandwidth measurement */ |
| 82 |
guint start_bitrate; |
| 83 |
|
| 84 |
/* Decryption key cache: url => GstHLSKey */ |
| 85 |
GHashTable *keys; |
| 86 |
GMutex keys_lock; |
| 87 |
|
| 88 |
/* The master playlist with the available variant streams, |
| 89 |
* created at demuxer start based on the input multivariant playlist */ |
| 90 |
GstHLSMasterPlaylist *master; |
| 91 |
|
| 92 |
/* A ref to the main playlist, for access from external threads */ |
| 93 |
GstHLSMediaPlaylist *main_playlist; |
| 94 |
|
| 95 |
GstHLSVariantStream *current_variant; |
| 96 |
/* The variant we're switching to (currently being loaded by the playlist loader) */ |
| 97 |
GstHLSVariantStream *pending_variant; |
| 98 |
|
| 99 |
/* List of failed variants that should be ignored */ |
| 100 |
GList *failed_variants; |
| 101 |
|
| 102 |
GstHLSDemuxStream *main_stream; |
| 103 |
|
| 104 |
/* Time Mappings (GstHLSTimeMap) */ |
| 105 |
GList *mappings; |
| 106 |
}; |
| 107 |
|
| 108 |
struct _GstHLSDemux2Class |
| 109 |
{ |
| 110 |
GstAdaptiveDemuxClass parent_class; |
| 111 |
}; |
| 112 |
|
| 113 |
GstAdaptiveDemuxTrack * |
| 114 |
gst_hls_demux_new_track_for_rendition (GstHLSDemux * demux, |
| 115 |
GstHLSRenditionStream * rendition, |
| 116 |
GstCaps * caps, GstStreamFlags flags, GstTagList * tags); |
| 117 |
|
| 118 |
void gst_hls_demux_start_rendition_streams (GstHLSDemux * hlsdemux); |
| 119 |
gboolean gst_hls_demux_reset_for_lost_sync (GstHLSDemux * hlsdemux); |
| 120 |
const GstHLSKey *gst_hls_demux_get_key (GstHLSDemux * demux, |
| 121 |
const gchar * key_url, const gchar * referer, gboolean allow_cache); |
| 122 |
|
| 123 |
void gst_hls_demux_handle_variant_playlist_update (GstHLSDemux * demux, |
| 124 |
const gchar *playlist_uri, GstHLSMediaPlaylist * playlist); |
| 125 |
void gst_hls_demux_handle_variant_playlist_update_error (GstHLSDemux * demux, |
| 126 |
const gchar *playlist_uri); |
| 127 |
gboolean gst_hls_demux_change_variant_playlist (GstHLSDemux * demux, |
| 128 |
gboolean iframe_variant, guint max_bitrate, gboolean * changed); |
| 129 |
GstFlowReturn gst_hls_demux_update_variant_playlist (GstHLSDemux * demux, |
| 130 |
GError ** err); |
| 131 |
|
| 132 |
void gst_time_map_set_values (GstHLSTimeMap *map, GstClockTimeDiff stream_time, |
| 133 |
GstClockTime internal_time, GDateTime *pdt); |
| 134 |
void gst_hls_demux_add_time_mapping (GstHLSDemux * demux, gint64 dsn, |
| 135 |
GstClockTimeDiff stream_time, GDateTime * pdt); |
| 136 |
void gst_hls_update_time_mappings (GstHLSDemux * demux, |
| 137 |
GstHLSMediaPlaylist * playlist); |
| 138 |
|
| 139 |
gchar *gst_hls_buf_to_utf8_text (GstBuffer * buf); |
| 140 |
|
| 141 |
/* Private */ |
| 142 |
GstHLSParserResult gst_hlsdemux_handle_content_mpegts (GstHLSDemux *demux, |
| 143 |
GstHLSDemuxStream *hls_stream, |
| 144 |
gboolean draining, |
| 145 |
GstBuffer **buffer); |
| 146 |
|
| 147 |
GstHLSParserResult gst_hlsdemux_handle_content_id3 (GstHLSDemux *demux, |
| 148 |
GstHLSDemuxStream *hls_stream, |
| 149 |
gboolean draining, |
| 150 |
GstBuffer **buffer); |
| 151 |
|
| 152 |
GstHLSParserResult gst_hlsdemux_handle_content_isobmff (GstHLSDemux *demux, |
| 153 |
GstHLSDemuxStream *hls_stream, |
| 154 |
gboolean draining, |
| 155 |
GstBuffer **buffer); |
| 156 |
|
| 157 |
GstHLSParserResult gst_hlsdemux_handle_content_webvtt (GstHLSDemux *demux, |
| 158 |
GstHLSDemuxStream *hls_stream, |
| 159 |
gboolean draining, |
| 160 |
GstBuffer **buffer); |
| 161 |
|
| 162 |
GstClockTimeDiff gst_hls_internal_to_stream_time (GstHLSTimeMap *map, |
| 163 |
GstClockTime internal_time); |
| 164 |
|
| 165 |
GstHLSTimeMap *gst_hls_demux_find_time_map (GstHLSDemux * demux, gint64 dsn); |
| 166 |
|
| 167 |
GType gst_hls_demux2_get_type (void); |
| 168 |
GType gst_hls_demux_stream_get_type (void); |
| 169 |
|
| 170 |
G_END_DECLS |
| 171 |
#endif /* __GST_HLS_DEMUX_H__ */ |