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.
25 #ifndef __GST_HLS_DEMUX_H__
26 #define __GST_HLS_DEMUX_H__
31 #include <gst/adaptivedemux/gstadaptivedemux.h>
32 #if defined(HAVE_OPENSSL)
33 #include <openssl/evp.h>
34 #elif defined(HAVE_NETTLE)
35 #include <nettle/aes.h>
36 #include <nettle/cbc.h>
43 #define GST_TYPE_HLS_DEMUX \
44 (gst_hls_demux_get_type())
45 #define GST_HLS_DEMUX(obj) \
46 (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_HLS_DEMUX,GstHLSDemux))
47 #define GST_HLS_DEMUX_CLASS(klass) \
48 (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_HLS_DEMUX,GstHLSDemuxClass))
49 #define GST_IS_HLS_DEMUX(obj) \
50 (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_HLS_DEMUX))
51 #define GST_IS_HLS_DEMUX_CLASS(klass) \
52 (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_HLS_DEMUX))
53 #define GST_HLS_DEMUX_GET_CLASS(obj) \
54 (G_TYPE_INSTANCE_GET_CLASS ((obj),GST_TYPE_HLS_DEMUX,GstHLSDemuxClass))
55 #define GST_HLS_DEMUX_CAST(obj) \
58 typedef struct _GstHLSDemux GstHLSDemux;
59 typedef struct _GstHLSDemuxClass GstHLSDemuxClass;
60 typedef struct _GstHLSDemuxStream GstHLSDemuxStream;
62 #define GST_HLS_DEMUX_STREAM_CAST(stream) ((GstHLSDemuxStream *)(stream))
64 struct _GstHLSDemuxStream
66 GstAdaptiveDemux adaptive_demux_stream;
70 gboolean do_typefind; /* Whether we need to typefind the next buffer */
71 GstBuffer *pending_typefind_buffer; /* for collecting data until typefind succeeds */
73 GstAdapter *pending_encrypted_data; /* for chunking data into 16 byte multiples for decryption */
74 GstBuffer *pending_decrypted_buffer; /* last decrypted buffer for pkcs7 unpadding.
75 We only know that it is the last at EOS */
76 guint64 current_offset; /* offset we're currently at */
79 /* decryption tooling */
80 #if defined(HAVE_OPENSSL)
81 EVP_CIPHER_CTX aes_ctx;
82 #elif defined(HAVE_NETTLE)
83 struct CBC_CTX (struct aes_ctx, AES_BLOCK_SIZE) aes_ctx;
85 gcry_cipher_hd_t aes_ctx;
91 GstBuffer *pending_buffer; /* decryption scenario:
92 * the last buffer can only be pushed when
93 * resized, so need to store and wait for
94 * EOS to know it is the last */
104 * Opaque #GstHLSDemux data structure.
108 GstAdaptiveDemux parent;
112 /* Decryption key cache: url => GstHLSKey */
116 /* FIXME: check locking, protected automatically by manifest_lock already? */
117 /* The master playlist with the available variant streams */
118 GstHLSMasterPlaylist *master;
120 GstHLSVariantStream *current_variant;
123 struct _GstHLSDemuxClass
125 GstAdaptiveDemuxClass parent_class;
128 GType gst_hls_demux_get_type (void);
131 #endif /* __GST_HLS_DEMUX_H__ */