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>
|
|
|
|
*
|
|
|
|
* gsthlsdemux.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 __GST_HLS_DEMUX_H__
|
|
|
|
#define __GST_HLS_DEMUX_H__
|
|
|
|
|
|
|
|
#include <gst/gst.h>
|
2011-04-01 23:08:02 +00:00
|
|
|
#include <gst/base/gstadapter.h>
|
2011-02-14 17:51:32 +00:00
|
|
|
#include "m3u8.h"
|
2012-03-15 18:42:44 +00:00
|
|
|
#include "gstfragmented.h"
|
2013-05-15 07:20:45 +00:00
|
|
|
#include <gst/uridownloader/gsturidownloader.h>
|
2014-08-22 21:18:59 +00:00
|
|
|
#if defined(HAVE_OPENSSL)
|
|
|
|
#include <openssl/evp.h>
|
|
|
|
#elif defined(HAVE_NETTLE)
|
2014-04-08 20:31:32 +00:00
|
|
|
#include <nettle/aes.h>
|
|
|
|
#include <nettle/cbc.h>
|
|
|
|
#else
|
|
|
|
#include <gcrypt.h>
|
|
|
|
#endif
|
2011-02-14 17:51:32 +00:00
|
|
|
|
|
|
|
G_BEGIN_DECLS
|
|
|
|
#define GST_TYPE_HLS_DEMUX \
|
|
|
|
(gst_hls_demux_get_type())
|
|
|
|
#define GST_HLS_DEMUX(obj) \
|
|
|
|
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_HLS_DEMUX,GstHLSDemux))
|
|
|
|
#define GST_HLS_DEMUX_CLASS(klass) \
|
|
|
|
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_HLS_DEMUX,GstHLSDemuxClass))
|
|
|
|
#define GST_IS_HLS_DEMUX(obj) \
|
|
|
|
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_HLS_DEMUX))
|
|
|
|
#define GST_IS_HLS_DEMUX_CLASS(klass) \
|
|
|
|
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_HLS_DEMUX))
|
2012-04-12 12:17:14 +00:00
|
|
|
#define GST_HLS_DEMUX_GET_CLASS(obj) \
|
|
|
|
(G_TYPE_INSTANCE_GET_CLASS ((obj),GST_TYPE_HLS_DEMUX,GstHLSDemuxClass))
|
2014-04-29 18:19:51 +00:00
|
|
|
#define GST_HLS_DEMUX_CAST(obj) \
|
|
|
|
((GstHLSDemux *)obj)
|
2011-02-14 17:51:32 +00:00
|
|
|
typedef struct _GstHLSDemux GstHLSDemux;
|
|
|
|
typedef struct _GstHLSDemuxClass GstHLSDemuxClass;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GstHLSDemux:
|
|
|
|
*
|
|
|
|
* Opaque #GstHLSDemux data structure.
|
|
|
|
*/
|
|
|
|
struct _GstHLSDemux
|
|
|
|
{
|
2014-04-07 16:57:26 +00:00
|
|
|
GstBin parent;
|
2011-02-14 17:51:32 +00:00
|
|
|
|
|
|
|
GstPad *sinkpad;
|
2014-02-12 17:27:21 +00:00
|
|
|
GstPad *srcpad;
|
|
|
|
gint srcpad_counter;
|
2012-03-15 18:42:44 +00:00
|
|
|
|
2013-07-23 08:07:24 +00:00
|
|
|
gboolean have_group_id;
|
|
|
|
guint group_id;
|
|
|
|
|
2011-02-14 17:51:32 +00:00
|
|
|
GstBuffer *playlist;
|
2011-02-15 20:49:20 +00:00
|
|
|
GstCaps *input_caps;
|
2012-03-15 18:42:44 +00:00
|
|
|
GstUriDownloader *downloader;
|
2014-04-28 07:32:54 +00:00
|
|
|
gchar *uri; /* Original playlist URI */
|
2011-02-14 17:51:32 +00:00
|
|
|
GstM3U8Client *client; /* M3U8 client */
|
2012-05-10 14:11:18 +00:00
|
|
|
gboolean do_typefind; /* Whether we need to typefind the next buffer */
|
2014-04-29 18:17:00 +00:00
|
|
|
gboolean new_playlist; /* Whether a new playlist is about to start and pads should be switched */
|
2011-02-14 17:51:32 +00:00
|
|
|
|
|
|
|
/* Properties */
|
|
|
|
guint fragments_cache; /* number of fragments needed to be cached to start playing */
|
2012-05-10 14:11:18 +00:00
|
|
|
gfloat bitrate_limit; /* limit of the available bitrate to use */
|
|
|
|
guint connection_speed; /* Network connection speed in kbps (0 = unknown) */
|
2011-02-14 17:51:32 +00:00
|
|
|
|
2012-03-15 22:21:58 +00:00
|
|
|
/* Streaming task */
|
|
|
|
GstTask *stream_task;
|
2012-04-12 12:17:14 +00:00
|
|
|
GRecMutex stream_lock;
|
2012-03-15 22:21:58 +00:00
|
|
|
gboolean stop_stream_task;
|
2014-02-17 08:19:32 +00:00
|
|
|
GMutex download_lock; /* Used for protecting queue and the two conds */
|
|
|
|
GCond download_cond; /* Signalled when something is added to the queue */
|
|
|
|
gboolean end_of_playlist;
|
|
|
|
gint download_failed_count;
|
|
|
|
gint64 next_download;
|
2011-02-14 17:51:32 +00:00
|
|
|
|
2012-03-15 22:21:58 +00:00
|
|
|
/* Updates task */
|
|
|
|
GstTask *updates_task;
|
2012-04-12 12:17:14 +00:00
|
|
|
GRecMutex updates_lock;
|
2014-02-17 08:19:32 +00:00
|
|
|
gint64 next_update; /* Time of the next update */
|
|
|
|
gboolean stop_updates_task;
|
2012-04-12 12:17:14 +00:00
|
|
|
GMutex updates_timed_lock;
|
2014-02-17 08:19:32 +00:00
|
|
|
GCond updates_timed_cond; /* Signalled when the playlist should be updated */
|
2012-03-15 22:21:58 +00:00
|
|
|
|
2011-08-01 16:48:03 +00:00
|
|
|
/* Position in the stream */
|
2014-03-06 22:14:10 +00:00
|
|
|
GstSegment segment;
|
2011-08-16 19:46:49 +00:00
|
|
|
gboolean need_segment;
|
2014-03-01 16:13:58 +00:00
|
|
|
gboolean discont;
|
2014-02-12 09:59:38 +00:00
|
|
|
|
|
|
|
/* Cache for the last key */
|
|
|
|
gchar *key_url;
|
|
|
|
GstFragment *key_fragment;
|
2014-03-09 17:41:28 +00:00
|
|
|
|
|
|
|
/* Current download rate (bps) */
|
|
|
|
gint current_download_rate;
|
2014-04-07 16:57:26 +00:00
|
|
|
|
|
|
|
/* fragment download tooling */
|
|
|
|
GstElement *src;
|
2014-04-30 20:59:28 +00:00
|
|
|
GstPad *src_srcpad; /* handy link to src's src pad */
|
2014-04-07 16:57:26 +00:00
|
|
|
GMutex fragment_download_lock;
|
2014-09-12 05:35:44 +00:00
|
|
|
gboolean download_finished;
|
2014-04-07 16:57:26 +00:00
|
|
|
GCond fragment_download_cond;
|
|
|
|
GstClockTime current_timestamp;
|
2014-04-28 22:10:02 +00:00
|
|
|
GstClockTime current_duration;
|
2014-04-07 16:57:26 +00:00
|
|
|
gboolean starting_fragment;
|
2014-06-20 14:20:55 +00:00
|
|
|
gboolean reset_crypto;
|
2014-04-16 09:12:42 +00:00
|
|
|
gint64 download_start_time;
|
|
|
|
gint64 download_total_time;
|
|
|
|
gint64 download_total_bytes;
|
2014-04-29 18:19:51 +00:00
|
|
|
GstFlowReturn last_ret;
|
2014-06-19 07:53:00 +00:00
|
|
|
GError *last_error;
|
2014-04-08 20:31:32 +00:00
|
|
|
|
|
|
|
/* decryption tooling */
|
2014-08-22 21:18:59 +00:00
|
|
|
#if defined(HAVE_OPENSSL)
|
|
|
|
EVP_CIPHER_CTX aes_ctx;
|
|
|
|
#elif defined(HAVE_NETTLE)
|
2014-04-08 20:31:32 +00:00
|
|
|
struct CBC_CTX (struct aes_ctx, AES_BLOCK_SIZE) aes_ctx;
|
|
|
|
#else
|
|
|
|
gcry_cipher_hd_t aes_ctx;
|
|
|
|
#endif
|
2014-10-02 16:37:57 +00:00
|
|
|
gchar *current_key;
|
|
|
|
guint8 *current_iv;
|
2014-04-08 20:31:32 +00:00
|
|
|
GstAdapter *adapter; /* used to accumulate 16 bytes multiple chunks */
|
|
|
|
GstBuffer *pending_buffer; /* decryption scenario:
|
|
|
|
* the last buffer can only be pushed when
|
|
|
|
* resized, so need to store and wait for
|
|
|
|
* EOS to know it is the last */
|
2011-02-14 17:51:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _GstHLSDemuxClass
|
|
|
|
{
|
2014-04-07 16:57:26 +00:00
|
|
|
GstBinClass parent_class;
|
2011-02-14 17:51:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
GType gst_hls_demux_get_type (void);
|
|
|
|
|
|
|
|
G_END_DECLS
|
|
|
|
#endif /* __GST_HLS_DEMUX_H__ */
|