1 /**
2  *			GPAC - Multimedia Framework C SDK
3  *
4  *					Authors: Pierre Souchay - Jean Le Feuvre - Romain Bouqueau
5  *			Copyright (c) Telecom ParisTech 2010-2012, Romain Bouqueau
6  *					All rights reserved
7  *
8  *  This file is part of GPAC
9  *
10  *  GPAC is free software; you can redistribute it and/or modify
11  *  it under the terms of the GNU Lesser General Public License as published by
12  *  the Free Software Foundation; either version 2, or (at your option)
13  *  any later version.
14  *
15  *  GPAC is distributed in the hope that it will be useful,
16  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *  GNU Lesser General Public License for more details.
19  *
20  *  You should have received a copy of the GNU Lesser General Public
21  *  License along with this library; see the file COPYING.  If not, write to
22  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23  *
24  */
25 #ifndef M3U8_PLAYLIST_H
26 #define M3U8_PLAYLIST_H
27 
28 #include <gpac/tools.h>
29 #include <gpac/list.h>
30 
31 
32 #define M3U8_UNKNOWN_MIME_TYPE "unknown"
33 
34 /**
35  * Basic Media structure
36  */
37 typedef struct s_media {
38 	int i; //unused: C requires that a struct or union has at least one member
39 } Media;
40 
41 /**
42  * The playlist contains a list of elements to play
43  */
44 struct s_playList {
45 	int current_media_seq;
46 	int media_seq_min;
47 	int media_seq_max;
48 	double target_duration;
49 	double computed_duration;
50 	Bool is_ended;
51 	GF_List *elements; /*PlaylistElement*/
52 };
53 typedef struct s_playList Playlist;
54 
55 typedef enum e_playlistElementType  { TYPE_PLAYLIST, TYPE_MEDIA, TYPE_UNKNOWN } PlaylistElementType;
56 
57 typedef enum e_playlistElementDRMMethod { DRM_NONE, DRM_AES_128 } PlaylistElementDRMMethod;
58 
59 typedef enum _e_MediaType {
60 	MEDIA_TYPE_UNKNOWN         = 0,
61 	MEDIA_TYPE_AUDIO           = 0x100000,
62 	MEDIA_TYPE_VIDEO           = 0x200000,
63 	MEDIA_TYPE_SUBTITLES       = 0x300000,
64 	MEDIA_TYPE_CLOSED_CAPTIONS = 0x400000
65 } MediaType;
66 
67 /**
68  * The Structure containing the playlist element
69  */
70 struct s_playlistElement {
71 	MediaType media_type;
72 	double duration_info;
73 	u64 byte_range_start, byte_range_end;
74 	int bandwidth, width, height;
75 	char *title;
76 	char *codecs;
77 	char *language;
78 	char *audio_group;
79 	char *video_group;
80 	char *url;
81 	char *init_segment_url;
82 	u64 init_byte_range_start, init_byte_range_end;
83 	u64 utc_start_time;
84 
85 	PlaylistElementDRMMethod drm_method;
86 	char *key_uri;
87 	bin128 key_iv;
88 	GF_Err load_error;
89 	PlaylistElementType element_type;
90 	union {
91 		Playlist playlist;
92 		Media media;
93 	} element;
94 };
95 typedef struct s_playlistElement PlaylistElement;
96 
97 struct s_stream {
98 	int stream_id; //may be a real PROGRAM_ID, or a converted GROUP_ID with GROUP_ID_TO_PROGRAM_ID
99 	GF_List *variants; /*PlaylistElement*/
100 	double computed_duration;
101 };
102 typedef struct s_stream Stream;
103 
104 /**
105  * The root playlist, can contains several PlaylistElements structures
106  */
107 struct s_masterPlaylist {
108 	GF_List *streams; /*Stream*/
109 	int current_stream;
110 	Bool playlist_needs_refresh;
111 	Bool independent_segments;
112 };
113 typedef struct s_masterPlaylist MasterPlaylist;
114 
115 
116 /**
117  * Parse the given m3u8 playlist file
118 \param file The file from cache to parse
119 \param playlist The playlist to fill. If argument is null, and file is valid, playlist will be allocated
120 \param baseURL The base URL of the playlist
121 \param GF_OK if playlist valid
122  */
123 GF_Err gf_m3u8_parse_master_playlist(const char *file, MasterPlaylist **playlist, const char *baseURL);
124 
125 /**
126  * Parse the given playlist file as a subplaylist of an existing playlist
127 \param file The file from cache to parse
128 \param playlist The playlist to fill.
129 \param baseURL base URL of the playlist
130 \param in_program in which the playlist is parsed
131 \param sub_playlist existing subplaylist element in the playlist in which the playlist is parsed
132 \param GF_OK if playlist valid
133  */
134 GF_Err gf_m3u8_parse_sub_playlist(const char *file, MasterPlaylist **playlist, const char *baseURL, Stream *in_program, PlaylistElement *sub_playlist);
135 
136 /**
137  * Deletes the given MasterPlaylist and all of its sub elements
138  */
139 GF_Err gf_m3u8_master_playlist_del(MasterPlaylist **playlist);
140 
141 #endif /* M3U8_PLAYLIST_H */
142