hlsdemux: Fix accessing invalidated memory
[platform/upstream/gstreamer.git] / ext / hls / 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  *
5  * m3u8.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 #ifndef __M3U8_H__
24 #define __M3U8_H__
25
26 #include <glib.h>
27
28 G_BEGIN_DECLS typedef struct _GstM3U8 GstM3U8;
29 typedef struct _GstM3U8MediaFile GstM3U8MediaFile;
30 typedef struct _GstM3U8Client GstM3U8Client;
31
32 #define GST_M3U8(m) ((GstM3U8*)m)
33 #define GST_M3U8_MEDIA_FILE(f) ((GstM3U8MediaFile*)f)
34
35 #define GST_M3U8_CLIENT_LOCK(c) g_mutex_lock (&c->lock);
36 #define GST_M3U8_CLIENT_UNLOCK(c) g_mutex_unlock (&c->lock);
37
38 #define GST_M3U8_CLIENT_IS_LIVE(c) ((!(c)->current || (c)->current->endlist) ? FALSE : TRUE)
39
40 struct _GstM3U8
41 {
42   gchar *uri;                   /* actually downloaded URI */
43   gchar *base_uri;              /* URI to use as base for resolving relative URIs.
44                                  * This will be different to uri in case of redirects */
45   gchar *name;                  /* This will be the "name" of the playlist, the original
46                                  * relative/absolute uri in a variant playlist */
47
48   gboolean endlist;             /* if ENDLIST has been reached */
49   gint version;                 /* last EXT-X-VERSION */
50   GstClockTime targetduration;  /* last EXT-X-TARGETDURATION */
51   gboolean allowcache;          /* last EXT-X-ALLOWCACHE */
52
53   gint bandwidth;
54   gint program_id;
55   gchar *codecs;
56   gint width;
57   gint height;
58   gboolean iframe;
59   GList *files;
60
61   /*< private > */
62   gchar *last_data;
63   GList *lists;                 /* list of GstM3U8 from the main playlist */
64   GList *iframe_lists;          /* I-frame lists from the main playlist */
65   GList *current_variant;       /* Current variant playlist used */
66   GstM3U8 *parent;              /* main playlist (if any) */
67   gint64 mediasequence;          /* EXT-X-MEDIA-SEQUENCE & increased with new media file */
68 };
69
70 struct _GstM3U8MediaFile
71 {
72   gchar *title;
73   GstClockTime duration;
74   gchar *uri;
75   gint64 sequence;               /* the sequence nb of this file */
76   gboolean discont;             /* this file marks a discontinuity */
77   gchar *key;
78   guint8 iv[16];
79   gint64 offset, size;
80 };
81
82 struct _GstM3U8Client
83 {
84   GstM3U8 *main;                /* main playlist */
85   GstM3U8 *current;
86   guint update_failed_count;
87   gint64 sequence;              /* the next sequence for this client */
88   GstClockTime sequence_position; /* position of this sequence */
89   GMutex lock;
90 };
91
92
93 GstM3U8Client *gst_m3u8_client_new (const gchar * uri, const gchar * base_uri);
94 void gst_m3u8_client_free (GstM3U8Client * client);
95 gboolean gst_m3u8_client_update (GstM3U8Client * client, gchar * data);
96 gboolean gst_m3u8_client_update_variant_playlist (GstM3U8Client * client, gchar * data, const gchar * uri, const gchar * base_uri);
97 void gst_m3u8_client_set_current (GstM3U8Client * client, GstM3U8 * m3u8);
98 gboolean gst_m3u8_client_get_next_fragment (GstM3U8Client * client,
99     gboolean * discontinuity, gchar ** uri, GstClockTime * duration,
100     GstClockTime * timestamp, gint64 * range_start, gint64 * range_end,
101     gchar ** key, guint8 ** iv, gboolean forward);
102 void gst_m3u8_client_advance_fragment (GstM3U8Client * client, gboolean forward);
103 GstClockTime gst_m3u8_client_get_duration (GstM3U8Client * client);
104 GstClockTime gst_m3u8_client_get_target_duration (GstM3U8Client * client);
105 gchar *gst_m3u8_client_get_uri(GstM3U8Client * client);
106 gchar *gst_m3u8_client_get_current_uri(GstM3U8Client * client);
107 gboolean gst_m3u8_client_has_main(GstM3U8Client * client);
108 gboolean gst_m3u8_client_has_variant_playlist(GstM3U8Client * client);
109 gboolean gst_m3u8_client_is_live(GstM3U8Client * client);
110 GList * gst_m3u8_client_get_playlist_for_bitrate (GstM3U8Client * client,
111     guint bitrate);
112
113 guint64 gst_m3u8_client_get_current_fragment_duration (GstM3U8Client * client);
114
115 G_END_DECLS
116 #endif /* __M3U8_H__ */