hlsdemux: Properly keep track of current offset
[platform/upstream/gstreamer.git] / ext / hls / gsthlsdemux.h
1 /* GStreamer
2  * Copyright (C) 2010 Marc-Andre Lureau <marcandre.lureau@gmail.com>
3  * Copyright (C) 2010 Andoni Morales Alastruey <ylatuya@gmail.com>
4  *
5  * gsthlsdemux.h:
6  *
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.
11  *
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.
16  *
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.
21  */
22
23
24 #ifndef __GST_HLS_DEMUX_H__
25 #define __GST_HLS_DEMUX_H__
26
27 #include <gst/gst.h>
28 #include "m3u8.h"
29 #include "gsthls.h"
30 #include <gst/adaptivedemux/gstadaptivedemux.h>
31 #if defined(HAVE_OPENSSL)
32 #include <openssl/evp.h>
33 #elif defined(HAVE_NETTLE)
34 #include <nettle/aes.h>
35 #include <nettle/cbc.h>
36 #else
37 #include <gcrypt.h>
38 #endif
39
40 G_BEGIN_DECLS
41 #define GST_TYPE_HLS_DEMUX \
42   (gst_hls_demux_get_type())
43 #define GST_HLS_DEMUX(obj) \
44   (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_HLS_DEMUX,GstHLSDemux))
45 #define GST_HLS_DEMUX_CLASS(klass) \
46   (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_HLS_DEMUX,GstHLSDemuxClass))
47 #define GST_IS_HLS_DEMUX(obj) \
48   (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_HLS_DEMUX))
49 #define GST_IS_HLS_DEMUX_CLASS(klass) \
50   (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_HLS_DEMUX))
51 #define GST_HLS_DEMUX_GET_CLASS(obj) \
52   (G_TYPE_INSTANCE_GET_CLASS ((obj),GST_TYPE_HLS_DEMUX,GstHLSDemuxClass))
53 #define GST_HLS_DEMUX_CAST(obj) \
54   ((GstHLSDemux *)obj)
55 typedef struct _GstHLSDemux GstHLSDemux;
56 typedef struct _GstHLSDemuxClass GstHLSDemuxClass;
57
58 /**
59  * GstHLSDemux:
60  *
61  * Opaque #GstHLSDemux data structure.
62  */
63 struct _GstHLSDemux
64 {
65   GstAdaptiveDemux parent;
66
67   gint srcpad_counter;
68
69   gchar *uri;                   /* Original playlist URI */
70   GstM3U8Client *client;        /* M3U8 client */
71   gboolean do_typefind;         /* Whether we need to typefind the next buffer */
72
73   /* Cache for the last key */
74   gchar *key_url;
75   GstFragment *key_fragment;
76
77   /* decryption tooling */
78 #if defined(HAVE_OPENSSL)
79   EVP_CIPHER_CTX aes_ctx;
80 #elif defined(HAVE_NETTLE)
81   struct CBC_CTX (struct aes_ctx, AES_BLOCK_SIZE) aes_ctx;
82 #else
83   gcry_cipher_hd_t aes_ctx;
84 #endif
85   gchar *current_key;
86   guint8 *current_iv;
87   GstAdapter *pending_encrypted_data;  /* for chunking data into 16 byte multiples for decryption */
88   GstBuffer *pending_decrypted_buffer; /* last decrypted buffer for pkcs7 unpadding.
89                                           We only know that it is the last at EOS */
90   GstBuffer *pending_typefind_buffer;  /* for collecting data until typefind succeeds */
91   guint64 current_offset;              /* offset we're currently at */
92   gboolean reset_pts;
93 };
94
95 struct _GstHLSDemuxClass
96 {
97   GstAdaptiveDemuxClass parent_class;
98 };
99
100 GType gst_hls_demux_get_type (void);
101
102 G_END_DECLS
103 #endif /* __GST_HLS_DEMUX_H__ */