1 /*
2  * Copyright (c) TELECOM ParisTech 2011
3  */
4 
5 #ifndef _GF_AIT_H_
6 #define _GF_AIT_H_
7 
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11 
12 /*!
13 \file <gpac/ait.h>
14 \brief Specific extensions for handling AIT in MPEG-2 TS.
15  */
16 
17 #include <gpac/mpegts.h>
18 #include <gpac/dsmcc.h>
19 #include <string.h>
20 #include <gpac/bitstream.h>
21 
22 
23 #ifndef GPAC_DISABLE_MPEG2TS
24 
25 
26 #define AIT_SECTION_LENGTH_MAX 1021
27 #define APPLICATION_TYPE_HTTP_APPLICATION 16
28 #define DSMCC_SECTION_LENGTH_MAX 4093
29 
30 /*! AIT descriptor tags*/
31 typedef enum {
32 	APPLICATION_DESCRIPTOR = 0x00,
33 	APPLICATION_NAME_DESCRIPTOR = 0x01,
34 	TRANSPORT_PROTOCOL_DESCRIPTOR = 0x02,
35 	SIMPLE_APPLICATION_LOCATION_DESCRIPTOR = 0x15,
36 	APPLICATION_USAGE_DESCRIPTOR = 0x16,
37 	APPLICATION_BOUNDARY_DESCRIPTOR = 0x17,
38 } DESCRIPTOR_TAG;
39 
40 /*! AIT Application Control Code*/
41 enum ApplicationControlCode {
42 	AUTOSTART =				0x01,
43 	PRESENT = 				0x02,
44 	DESTROY =				0x03,
45 	KILL =					0x04,
46 	PREFETCH =				0x05,
47 	REMOTE = 				0x06,
48 	DISABLED =				0x07,
49 	PLAYBACK_AUTOSTART =	0x08
50 };
51 
52 /*! AIT Transport Type*/
53 enum TransportType {
54 	BROADCAST =		0x01,
55 	BROADBAND = 	0x03
56 };
57 
58 /*! AIT table*/
59 typedef struct
60 {
61 	u32 pid;
62 	u32 service_id;
63 	u8 table_id;
64 	Bool section_syntax_indicator;
65 	u16 section_length;
66 	Bool test_application_flag;
67 	u16 application_type;
68 	u8 version_number;
69 	Bool current_next_indicator;
70 	u8 section_number;
71 	u8 last_section_number;
72 	u16 common_descriptors_length;
73 	GF_List * common_descriptors;
74 	u16 application_loop_length;
75 	GF_List * application_decoded;
76 	u32 CRC_32;
77 
78 } GF_M2TS_AIT;
79 
80 /*! AIT elementary stream / section filter*/
81 typedef struct
82 {
83 	ABSTRACT_ES
84 	GF_M2TS_SectionFilter *sec;
85 
86 } GF_M2TS_AIT_CARRY;
87 
88 
89 /*! AIT single application descriptor*/
90 typedef struct
91 {
92 	u32 organisation_id;
93 	u16 application_id;
94 	u8 application_control_code;
95 	u16 application_descriptors_loop_length;
96 	GF_List * application_descriptors;
97 	u8 application_descriptors_id[50];
98 	u8 index_app_desc_id;
99 
100 } GF_M2TS_AIT_APPLICATION_DECODE;
101 
102 
103 /*! AIT protocol identifier*/
104 typedef enum {
105 	FUTURE_USE = 0x00,
106 	CAROUSEL = 0x01,
107 	RESERVED = 0x02,
108 	TRANSPORT_HTTP = 0x03,
109 	DVB_USE = 0x04,
110 	TO_REGISTER = 0x100,
111 } PROTOCOL_ID;
112 
113 /*! Application descriptor*/
114 typedef struct
115 {
116 	u8 descriptor_tag;
117 	u8 descriptor_length;
118 	u8 application_profiles_length;
119 	u16 application_profile;
120 	u8 version_major;
121 	u8 version_minor;
122 	u8 version_micro;
123 	Bool service_bound_flag;
124 	u8 visibility;
125 	u8 application_priority;
126 	u8 transport_protocol_label[5];
127 
128 } GF_M2TS_APPLICATION_DESCRIPTOR;
129 
130 /*! Application usage descriptor*/
131 typedef struct
132 {
133 	u8 descriptor_tag;
134 	u8 descriptor_length;
135 	u8 usage_type;
136 
137 } GF_M2TS_APPLICATION_USAGE;
138 
139 /*! Application location descriptor*/
140 typedef struct
141 {
142 	u8 descriptor_tag;
143 	u8 descriptor_length;
144 	char* initial_path_bytes;
145 
146 } GF_M2TS_SIMPLE_APPLICATION_LOCATION;
147 
148 /*! Application object carousel selector*/
149 typedef struct
150 {
151 	Bool remote_connection;
152 	u16 original_network_id;
153 	u16 transport_stream_id;
154 	u16 service_id;
155 	u8 component_tag;
156 
157 } GF_M2TS_OBJECT_CAROUSEL_SELECTOR_BYTE;
158 
159 /*! Application HTTP transport descriptor*/
160 typedef struct {
161 	u8 URL_extension_length;
162 	char* URL_extension_byte;
163 
164 } GF_M2TS_TRANSPORT_HTTP_URL_EXTENTION;
165 
166 /*! Application HTTP selector*/
167 typedef struct
168 {
169 	u8 URL_base_length;
170 	char* URL_base_byte;
171 	u8 URL_extension_count;
172 	GF_M2TS_TRANSPORT_HTTP_URL_EXTENTION* URL_extentions;
173 
174 } GF_M2TS_TRANSPORT_HTTP_SELECTOR_BYTE;
175 
176 /*! Transport Protocol descriptor*/
177 typedef struct
178 {
179 	u8 descriptor_tag;
180 	u8 descriptor_length;
181 	u16 protocol_id;
182 	u8 transport_protocol_label;
183 	void* selector_byte;
184 
185 } GF_M2TS_TRANSPORT_PROTOCOL_DESCRIPTOR;
186 
187 /*! Application Name descriptor*/
188 typedef struct
189 {
190 	u8 descriptor_tag;
191 	u8 descriptor_length;
192 	u32 ISO_639_language_code;
193 	u8 application_name_length;
194 	char* application_name_char;
195 
196 } GF_M2TS_APPLICATION_NAME_DESCRIPTOR;
197 
198 /*! Application boundary extension info */
199 typedef struct
200 {
201 	u8 boundary_extension_length;
202 	char* boundary_extension_byte;
203 
204 } GF_M2TS_APPLICATION_BOUNDARY_EXTENSION_INFO;
205 
206 /*! Application boundary descriptor*/
207 typedef struct
208 {
209 	u8 descriptor_tag;
210 	u8 descriptor_length;
211 	u8 boundary_extension_count;
212 	GF_M2TS_APPLICATION_BOUNDARY_EXTENSION_INFO* boundary_extension_info;
213 
214 } GF_M2TS_APPLICATION_BOUNDARY_DESCRIPTOR;
215 
216 /*! AIT implementation object*/
217 typedef struct
218 {
219 	u32 application_id;
220 	u8 application_control_code;
221 
222 	u8 priority;
223 	u16 application_profile;
224 
225 	/* Transport mode - 1 Broadcast - 3 Broadband */
226 	Bool broadcast;
227 	Bool broadband;
228 	char* http_url;
229 	char* carousel_url;
230 	Bool url_received;
231 
232 	/* Carousel */
233 	u32 carousel_pid;
234 	u32 component_tag;
235 
236 
237 	char* appli_name;
238 
239 } GF_M2TS_AIT_APPLICATION;
240 
241 /*! AIT Channel Info object*/
242 typedef struct
243 {
244 	u32 service_id;
245 	u32 version_number;
246 	u32 ait_pid;
247 	u32 nb_application;
248 	GF_List *Application;
249 
250 } GF_M2TS_CHANNEL_APPLICATION_INFO;
251 
252 /*! AIT section callback used by MPEG-2 TS parser*/
253 void on_ait_section(GF_M2TS_Demuxer *ts, u32 evt_type, void *par);
254 /*! creates a new AIT section*/
255 GF_M2TS_ES *gf_ait_section_new(u32 service_id);
256 /*! gets the application info for the given service ID*/
257 GF_M2TS_CHANNEL_APPLICATION_INFO* gf_m2ts_get_channel_application_info(GF_List* ChannelAppList, u32 ait_service_id);
258 /*! frees the given application info*/
259 void  gf_m2ts_delete_channel_application_info(GF_M2TS_CHANNEL_APPLICATION_INFO* ChannelApp);
260 
261 #endif /*GPAC_DISABLE_MPEG2TS*/
262 
263 
264 #ifdef __cplusplus
265 }
266 #endif
267 
268 #endif	//_GF_AIT_H_
269 
270