tizen 2.3.1 release
[framework/multimedia/gst-plugins-ext0.10.git] / hlsdemux2 / src / m3u8.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  * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * m3u8.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., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23
24 #ifndef __M3U8_H__
25 #define __M3U8_H__
26
27 #include <glib.h>
28 #include <openssl/evp.h>
29 #include <gst/gst.h>
30
31 G_BEGIN_DECLS typedef struct _GstM3U8 GstM3U8;
32 typedef struct _GstM3U8MediaFile GstM3U8MediaFile;
33 typedef struct _GstM3U8Key GstM3U8Key;
34 typedef struct _GstM3U8Client GstM3U8Client;
35
36 #define GST_M3U8(m) ((GstM3U8*)m)
37 #define GST_M3U8_KEY(k) ((GstM3U8Key*)k)
38 #define GST_M3U8_MEDIA_FILE(f) ((GstM3U8MediaFile*)f)
39
40 #define GST_M3U8_CLIENT_LOCK(c) g_mutex_lock (c->lock);
41 #define GST_M3U8_CLIENT_UNLOCK(c) g_mutex_unlock (c->lock);
42
43 #define GST_M3U8_IV_LEN 16
44
45 GST_DEBUG_CATEGORY_EXTERN (hlsdemux2_m3u8_debug);
46
47 typedef enum {
48   GST_M3U8_ENCRYPTED_NONE,
49   GST_M3U8_ENCRYPTED_AES_128,
50 } GstM3U8EncryptionMethod;
51
52 struct _GstM3U8
53 {
54   gchar *uri;
55
56   gboolean endlist;             /* if ENDLIST has been reached */
57   gint version;                 /* last EXT-X-VERSION */
58   GstClockTime targetduration;  /* last EXT-X-TARGETDURATION */
59   gchar *allowcache;            /* last EXT-X-ALLOWCACHE */
60
61   gint bandwidth;
62   gint program_id;
63   gchar *codecs;
64   gint width;
65   gint height;
66   GList *files;
67
68   /*< private > */
69   gchar *last_data;
70   GList *lists;                 /* list of GstM3U8 from the main playlist */
71   GList *current_variant;       /* Current variant playlist used */
72   GstM3U8 *parent;              /* main playlist (if any) */
73   guint mediasequence;          /* EXT-X-MEDIA-SEQUENCE & increased with new media file */
74 };
75
76 struct _GstM3U8MediaFile
77 {
78   gchar *title;
79   GstClockTime duration;
80   gchar *uri;
81   guint sequence;               /* the sequence nb of this file */
82   gchar *key_url;
83   unsigned char *key;
84   unsigned char *iv;
85 };
86
87 struct _GstM3U8Key
88 {
89   GstM3U8EncryptionMethod method;
90   gchar *uri;
91   guint8 *iv;
92   guint sequence;
93   guint8 *data;
94 };
95
96 struct _GstM3U8Client
97 {
98   GstM3U8 *main;                /* main playlist */
99   GstM3U8 *current;
100   guint update_failed_count;
101   gint sequence;                /* the next sequence for this client */
102   GMutex *lock;
103   EVP_CIPHER_CTX cipher_ctx;
104 };
105
106
107 GstM3U8Client *gst_m3u8_client_new (const gchar * uri);
108 void gst_m3u8_client_free (GstM3U8Client * client);
109 gboolean gst_m3u8_client_update (GstM3U8Client * client, gchar * data);
110 void gst_m3u8_client_set_current (GstM3U8Client * client, GstM3U8 * m3u8);
111 gboolean gst_m3u8_client_get_next_fragment (GstM3U8Client * client, GstClockTime cur_running_time,
112     gboolean * discontinuity, const gchar ** uri, GstClockTime * duration,
113     GstClockTime * timestamp, gchar **key_uri, gchar **iv);
114 void gst_m3u8_client_get_current_position (GstM3U8Client * client,
115     GstClockTime * timestamp);
116 GstClockTime gst_m3u8_client_get_duration (GstM3U8Client * client);
117 GstClockTime gst_m3u8_client_get_target_duration (GstM3U8Client * client);
118 const gchar *gst_m3u8_client_get_uri(GstM3U8Client * client);
119 const gchar *gst_m3u8_client_get_current_uri(GstM3U8Client * client);
120 gboolean gst_m3u8_client_has_variant_playlist(GstM3U8Client * client);
121 gboolean gst_m3u8_client_is_live(GstM3U8Client * client);
122 GList * gst_m3u8_client_get_playlist_for_bitrate (GstM3U8Client * client,
123     guint bitrate);
124 gboolean gst_m3u8_client_decrypt_init (GstM3U8Client * client, unsigned char *key, gchar *iv);
125 gboolean gst_m3u8_client_decrypt_update (GstM3U8Client * client,
126     guint8 * out_data, gint * out_size, guint8 * in_data, gint in_size);
127 gboolean gst_m3u8_client_is_playlist_download_needed (GstM3U8Client * self);
128 GstClockTime gst_m3u8_client_get_last_fragment_duration (GstM3U8Client * client);
129 gint gst_m3u8_client_get_current_bandwidth (GstM3U8Client * client);
130 gboolean gst_m3u8_client_decrypt_final (GstM3U8Client * client, guint8 * out_data, gint * out_size);
131 gboolean gst_m3u8_client_decrypt_deinit (GstM3U8Client * client);
132 void gst_m3u8_client_decrement_sequence (GstM3U8Client * client);
133 GList *gst_m3u8_client_get_next_higher_bw_playlist (GstM3U8Client * client);
134 GList *gst_m3u8_client_get_next_lower_bw_playlist (GstM3U8Client * client);
135
136 G_END_DECLS
137 #endif /* __M3U8_H__ */