| 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-stream.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 |
#ifndef __GST_HLS_DEMUX_STREAM_H__ |
| 24 |
#define __GST_HLS_DEMUX_STREAM_H__ |
| 25 |
|
| 26 |
#include <gst/gst.h> |
| 27 |
#include <gst/base/gstadapter.h> |
| 28 |
#include "m3u8.h" |
| 29 |
#include "gstisoff.h" |
| 30 |
#include <gstadaptivedemux.h> |
| 31 |
#include "gsthlsdemux.h" |
| 32 |
#include "gsthlsdemux-preloader.h" |
| 33 |
#include "gsthlsdemux-playlist-loader.h" |
| 34 |
|
| 35 |
#if defined(HAVE_OPENSSL) |
| 36 |
#include <openssl/evp.h> |
| 37 |
#elif defined(HAVE_NETTLE) |
| 38 |
#include <nettle/aes.h> |
| 39 |
#include <nettle/cbc.h> |
| 40 |
#elif defined(HAVE_LIBGCRYPT) |
| 41 |
#include <gcrypt.h> |
| 42 |
#endif |
| 43 |
|
| 44 |
G_BEGIN_DECLS |
| 45 |
|
| 46 |
#define GST_TYPE_HLS_DEMUX_STREAM \ |
| 47 |
(gst_hls_demux_stream_get_type()) |
| 48 |
#define GST_HLS_DEMUX_STREAM(obj) \ |
| 49 |
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_HLS_DEMUX_STREAM,GstHLSDemuxStream)) |
| 50 |
#define GST_HLS_DEMUX_STREAM_CAST(obj) ((GstHLSDemuxStream *)obj) |
| 51 |
|
| 52 |
#define GST_HLS_DEMUX_STREAM_GET_DEMUX(obj) (GST_HLS_DEMUX_CAST(GST_ADAPTIVE_DEMUX2_STREAM((obj))->demux)) |
| 53 |
|
| 54 |
typedef struct _GstHLSDemuxStream GstHLSDemuxStream; |
| 55 |
typedef GstAdaptiveDemux2StreamClass GstHLSDemuxStreamClass; |
| 56 |
|
| 57 |
typedef enum { |
| 58 |
GST_HLS_PARSER_NONE, |
| 59 |
GST_HLS_PARSER_MPEGTS, |
| 60 |
GST_HLS_PARSER_ID3, |
| 61 |
GST_HLS_PARSER_WEBVTT, |
| 62 |
GST_HLS_PARSER_ISOBMFF |
| 63 |
} GstHLSParserType; |
| 64 |
|
| 65 |
struct _GstHLSDemuxStream |
| 66 |
{ |
| 67 |
GstAdaptiveDemux2Stream adaptive_demux_stream; |
| 68 |
|
| 69 |
/* A stream either variants or renditions */ |
| 70 |
gboolean is_variant; |
| 71 |
|
| 72 |
/* Rendition-specific fields */ |
| 73 |
GstStreamType rendition_type; /* FIXME: Also used by variant streams */ |
| 74 |
gchar *lang; |
| 75 |
gchar *name; |
| 76 |
GstHLSRenditionStream *current_rendition; |
| 77 |
/* rendition to switch to */ |
| 78 |
GstHLSRenditionStream *pending_rendition; |
| 79 |
/* End of Rendition-specific fields */ |
| 80 |
|
| 81 |
/* Whether the underlying playlist was fetched on creation */ |
| 82 |
gboolean playlist_fetched; |
| 83 |
GstClockTime playlist_last_update_time; |
| 84 |
|
| 85 |
/* Playlist loading helper */ |
| 86 |
GstHLSDemuxPlaylistLoader *playlistloader; |
| 87 |
|
| 88 |
/* The media playlist currently used */ |
| 89 |
GstHLSMediaPlaylist *playlist; |
| 90 |
|
| 91 |
/* The current header / init_file data */ |
| 92 |
GstM3U8InitFile *init_file; |
| 93 |
|
| 94 |
/* The segment (from the above playlist) currently being used */ |
| 95 |
GstM3U8MediaSegment *current_segment; |
| 96 |
/* When playing partial segments in LL-HLS, in_partial_segments is TRUE, |
| 97 |
* and part_no is the current part index in the current_segment */ |
| 98 |
gboolean in_partial_segments; |
| 99 |
guint part_idx; |
| 100 |
|
| 101 |
/* Preload helper, that manages blocking preload downloads */ |
| 102 |
GstHLSDemuxPreloader *preloader; |
| 103 |
|
| 104 |
/* Whether we need to typefind the next buffer */ |
| 105 |
gboolean do_typefind; |
| 106 |
|
| 107 |
/* for collecting data until typefind succeeds */ |
| 108 |
GstBuffer *pending_typefind_buffer; |
| 109 |
|
| 110 |
/* for chunking data into 16 byte multiples for decryption */ |
| 111 |
GstAdapter *pending_encrypted_data; |
| 112 |
|
| 113 |
/* last decrypted buffer for pkcs7 unpadding. We only know that it is the last |
| 114 |
* on ::finish_fragment() */ |
| 115 |
GstBuffer *pending_decrypted_buffer; |
| 116 |
|
| 117 |
/* Current offset (in bytes) in fragment data we pushed downstream. Resets to |
| 118 |
* -1 at every fragment start */ |
| 119 |
guint64 current_offset; |
| 120 |
|
| 121 |
gboolean reset_pts; |
| 122 |
|
| 123 |
/* decryption tooling */ |
| 124 |
#if defined(HAVE_OPENSSL) |
| 125 |
# if OPENSSL_VERSION_NUMBER < 0x10100000L |
| 126 |
EVP_CIPHER_CTX aes_ctx; |
| 127 |
# else |
| 128 |
EVP_CIPHER_CTX *aes_ctx; |
| 129 |
# endif |
| 130 |
#elif defined(HAVE_NETTLE) |
| 131 |
struct CBC_CTX (struct aes128_ctx, AES_BLOCK_SIZE) aes_ctx; |
| 132 |
#elif defined(HAVE_LIBGCRYPT) |
| 133 |
gcry_cipher_hd_t aes_ctx; |
| 134 |
#endif |
| 135 |
|
| 136 |
gchar *current_key; |
| 137 |
guint8 *current_iv; |
| 138 |
|
| 139 |
/* The type of parser used for data handling */ |
| 140 |
GstHLSParserType parser_type; |
| 141 |
|
| 142 |
/* Is content processing required ? */ |
| 143 |
gboolean process_buffer_content; |
| 144 |
/* Data to be analyzed by */ |
| 145 |
GstBuffer *pending_segment_data; |
| 146 |
/* TRUE if pending_segment_data contains data from a header/index */ |
| 147 |
gboolean pending_data_is_header; |
| 148 |
|
| 149 |
/* ISOBMFF */ |
| 150 |
GstMoovBox *moov; |
| 151 |
|
| 152 |
/* Presentation offset to use and report. This value will be appended to all |
| 153 |
* "output" stream times. Not enabled (i.e 0) if variant is ISOBMFF |
| 154 |
*/ |
| 155 |
GstClockTime presentation_offset; |
| 156 |
|
| 157 |
gboolean pdt_tag_sent; |
| 158 |
|
| 159 |
/* The next segment needs to have the discont flag set on it. This is set when |
| 160 |
* a playlist update was detected as not being continuous/contiguous with the |
| 161 |
* previous one. */ |
| 162 |
gboolean pending_discont; |
| 163 |
}; |
| 164 |
|
| 165 |
GstFlowReturn |
| 166 |
gst_hls_demux_stream_seek (GstAdaptiveDemux2Stream * stream, gboolean forward, |
| 167 |
GstSeekFlags flags, GstClockTimeDiff ts, GstClockTimeDiff * final_ts); |
| 168 |
|
| 169 |
void |
| 170 |
gst_hls_demux_stream_set_playlist_uri (GstHLSDemuxStream * stream, gchar * uri); |
| 171 |
|
| 172 |
void |
| 173 |
gst_hls_demux_stream_start_playlist_loading (GstHLSDemuxStream * stream); |
| 174 |
|
| 175 |
GstFlowReturn gst_hls_demux_stream_check_current_playlist_uri (GstHLSDemuxStream * stream, gchar *uri); |
| 176 |
|
| 177 |
void |
| 178 |
gst_hls_demux_stream_clear_pending_data (GstHLSDemuxStream * hls_stream, |
| 179 |
gboolean force); |
| 180 |
|
| 181 |
GstHLSParserResult gst_hlsdemux_stream_handle_internal_time ( |
| 182 |
GstHLSDemuxStream *hls_stream, |
| 183 |
GstClockTime internal_time); |
| 184 |
|
| 185 |
G_END_DECLS |
| 186 |
#endif /* __GST_HLS_DEMUX_STREAM_H__ */ |