2 * Copyright (C) 2010 Marc-Andre Lureau <marcandre.lureau@gmail.com>
3 * Copyright (C) 2010 Andoni Morales Alastruey <ylatuya@gmail.com>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
24 #ifndef __GST_HLS_DEMUX_H__
25 #define __GST_HLS_DEMUX_H__
28 #include <gst/base/gstadapter.h>
30 #include "gstfragmented.h"
31 #include <gst/uridownloader/gsturidownloader.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>
42 #define GST_TYPE_HLS_DEMUX \
43 (gst_hls_demux_get_type())
44 #define GST_HLS_DEMUX(obj) \
45 (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_HLS_DEMUX,GstHLSDemux))
46 #define GST_HLS_DEMUX_CLASS(klass) \
47 (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_HLS_DEMUX,GstHLSDemuxClass))
48 #define GST_IS_HLS_DEMUX(obj) \
49 (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_HLS_DEMUX))
50 #define GST_IS_HLS_DEMUX_CLASS(klass) \
51 (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_HLS_DEMUX))
52 #define GST_HLS_DEMUX_GET_CLASS(obj) \
53 (G_TYPE_INSTANCE_GET_CLASS ((obj),GST_TYPE_HLS_DEMUX,GstHLSDemuxClass))
54 #define GST_HLS_DEMUX_CAST(obj) \
56 typedef struct _GstHLSDemux GstHLSDemux;
57 typedef struct _GstHLSDemuxClass GstHLSDemuxClass;
62 * Opaque #GstHLSDemux data structure.
72 gboolean have_group_id;
77 GstUriDownloader *downloader;
78 gchar *uri; /* Original playlist URI */
79 GstM3U8Client *client; /* M3U8 client */
80 gboolean do_typefind; /* Whether we need to typefind the next buffer */
81 gboolean new_playlist; /* Whether a new playlist is about to start and pads should be switched */
84 guint fragments_cache; /* number of fragments needed to be cached to start playing */
85 gfloat bitrate_limit; /* limit of the available bitrate to use */
86 guint connection_speed; /* Network connection speed in kbps (0 = unknown) */
90 GRecMutex stream_lock;
91 gboolean stop_stream_task;
92 GMutex download_lock; /* Used for protecting queue and the two conds */
93 GCond download_cond; /* Signalled when something is added to the queue */
94 gboolean end_of_playlist;
95 gint download_failed_count;
99 GstTask *updates_task;
100 GRecMutex updates_lock;
101 gint64 next_update; /* Time of the next update */
102 gboolean stop_updates_task;
103 GMutex updates_timed_lock;
104 GCond updates_timed_cond; /* Signalled when the playlist should be updated */
106 /* Position in the stream */
108 gboolean need_segment;
111 /* Cache for the last key */
113 GstFragment *key_fragment;
115 /* Current download rate (bps) */
116 gint current_download_rate;
118 /* fragment download tooling */
120 GstPad *src_srcpad; /* handy link to src's src pad */
121 GMutex fragment_download_lock;
122 gboolean download_finished;
123 GCond fragment_download_cond;
124 GstClockTime current_timestamp;
125 GstClockTime current_duration;
126 gboolean starting_fragment;
127 gboolean reset_crypto;
128 gint64 download_start_time;
129 gint64 download_total_time;
130 gint64 download_total_bytes;
131 GstFlowReturn last_ret;
134 /* decryption tooling */
135 #if defined(HAVE_OPENSSL)
136 EVP_CIPHER_CTX aes_ctx;
137 #elif defined(HAVE_NETTLE)
138 struct CBC_CTX (struct aes_ctx, AES_BLOCK_SIZE) aes_ctx;
140 gcry_cipher_hd_t aes_ctx;
144 GstAdapter *adapter; /* used to accumulate 16 bytes multiple chunks */
145 GstBuffer *pending_buffer; /* decryption scenario:
146 * the last buffer can only be pushed when
147 * resized, so need to store and wait for
148 * EOS to know it is the last */
151 struct _GstHLSDemuxClass
153 GstBinClass parent_class;
156 GType gst_hls_demux_get_type (void);
159 #endif /* __GST_HLS_DEMUX_H__ */