summaryrefslogtreecommitdiff
path: root/include/gpac/internal/m3u8.h
blob: 2a1a2be3318b8fbe10278b24cce772985e9526d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/**
 *			GPAC - Multimedia Framework C SDK
 *
 *					Authors: Pierre Souchay - Jean Le Feuvre - Romain Bouqueau
 *			Copyright (c) Telecom ParisTech 2010-2012, Romain Bouqueau
 *					All rights reserved
 *
 *  This file is part of GPAC
 *
 *  GPAC is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation; either version 2, or (at your option)
 *  any later version.
 *
 *  GPAC 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 Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; see the file COPYING.  If not, write to
 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */
#ifndef M3U8_PLAYLIST_H
#define M3U8_PLAYLIST_H

#include <gpac/tools.h>
#include <gpac/list.h>


#define M3U8_UNKNOWN_MIME_TYPE "unknown"

/**
 * Basic Media structure
 */
typedef struct s_media {
	int i; //unused: C requires that a struct or union has at least one member
} Media;

/**
 * The playlist contains a list of elements to play
 */
struct s_playList {
	int current_media_seq;
	int media_seq_min;
	int media_seq_max;
	double target_duration;
	double computed_duration;
	Bool is_ended;
	GF_List *elements; /*PlaylistElement*/
};
typedef struct s_playList Playlist;

typedef enum e_playlistElementType  { TYPE_PLAYLIST, TYPE_MEDIA, TYPE_UNKNOWN } PlaylistElementType;

typedef enum e_playlistElementDRMMethod { DRM_NONE, DRM_AES_128 } PlaylistElementDRMMethod;

typedef enum _e_MediaType {
	MEDIA_TYPE_UNKNOWN         = 0,
	MEDIA_TYPE_AUDIO           = 0x100000,
	MEDIA_TYPE_VIDEO           = 0x200000,
	MEDIA_TYPE_SUBTITLES       = 0x300000,
	MEDIA_TYPE_CLOSED_CAPTIONS = 0x400000
} MediaType;

/**
 * The Structure containing the playlist element
 */
struct s_playlistElement {
	MediaType media_type;
	double duration_info;
	u64 byte_range_start, byte_range_end;
	int bandwidth, width, height;
	char *title;
	char *codecs;
	char *language;
	char *audio_group;
	char *video_group;
	char *url;
	char *init_segment_url;
	u64 init_byte_range_start, init_byte_range_end;
	u64 utc_start_time;

	PlaylistElementDRMMethod drm_method;
	char *key_uri;
	bin128 key_iv;
	GF_Err load_error;
	PlaylistElementType element_type;
	union {
		Playlist playlist;
		Media media;
	} element;
};
typedef struct s_playlistElement PlaylistElement;

struct s_stream {
	int stream_id; //may be a real PROGRAM_ID, or a converted GROUP_ID with GROUP_ID_TO_PROGRAM_ID
	GF_List *variants; /*PlaylistElement*/
	double computed_duration;
};
typedef struct s_stream Stream;

/**
 * The root playlist, can contains several PlaylistElements structures
 */
struct s_masterPlaylist {
	GF_List *streams; /*Stream*/
	int current_stream;
	Bool playlist_needs_refresh;
	Bool independent_segments;
};
typedef struct s_masterPlaylist MasterPlaylist;


/**
 * Parse the given m3u8 playlist file
 * \param file The file from cache to parse
 * \param playlist The playlist to fill. If argument is null, and file is valid, playlist will be allocated
 * \param baseURL The base URL of the playlist
 * \return GF_OK if playlist valid
 */
GF_Err gf_m3u8_parse_master_playlist(const char *file, MasterPlaylist **playlist, const char *baseURL);

/**
 * Parse the given playlist file as a subplaylist of an existing playlist
 * \param file The file from cache to parse
 * \param playlist The playlist to fill.
 * \param baseURL base URL of the playlist
 * \param in_program in which the playlist is parsed
 * \param sub_playlist existing subplaylist element in the playlist in which the playlist is parsed
 * \return GF_OK if playlist valid
 */
GF_Err gf_m3u8_parse_sub_playlist(const char *file, MasterPlaylist **playlist, const char *baseURL, Stream *in_program, PlaylistElement *sub_playlist);

/**
 * Deletes the given MasterPlaylist and all of its sub elements
 */
GF_Err gf_m3u8_master_playlist_del(MasterPlaylist **playlist);

#endif /* M3U8_PLAYLIST_H */