2525#include <gpac/carousel.h>
2626
2727
28- GF_M2TS_ES * gf_ait_section_new ()
28+ GF_M2TS_ES * gf_ait_section_new (u32 service_id )
2929{
3030 GF_M2TS_ES * es ;
3131
3232 GF_M2TS_AIT * ses ;
3333 GF_SAFEALLOC (ses , GF_M2TS_AIT );
3434 es = (GF_M2TS_ES * )ses ;
3535 es -> flags = GF_M2TS_ES_IS_SECTION ;
36+ ses -> service_id = service_id ;
3637 return es ;
3738}
3839
@@ -59,16 +60,17 @@ GF_Err gf_m2ts_process_ait(GF_M2TS_Demuxer *ts, GF_M2TS_AIT *ait, char *data, u
5960
6061 GF_BitStream * bs ;
6162 u8 temp_descriptor_tag ;
62- u32 data_shift , app_desc_data_shift ;
63+ u32 data_shift , app_desc_data_shift , ait_app_data_shift ;
6364 u32 nb_of_ait ;
6465
6566 data_shift = 0 ;
6667 temp_descriptor_tag = 0 ;
6768 nb_of_ait = 0 ;
69+ ait_app_data_shift = 0 ;
6870 bs = gf_bs_new (data ,data_size ,GF_BITSTREAM_READ );
6971
7072 ait -> common_descriptors = gf_list_new ();
71- ait -> application_descriptors = gf_list_new ();
73+ ait -> application = gf_list_new ();
7274
7375
7476 ait -> table_id = gf_bs_read_int (bs ,8 );
@@ -99,21 +101,28 @@ GF_Err gf_m2ts_process_ait(GF_M2TS_Demuxer *ts, GF_M2TS_AIT *ait, char *data, u
99101 gf_bs_read_int (bs ,(unsigned int )ait -> common_descriptors_length /8 );
100102 gf_bs_read_int (bs ,4 );/* bit shifting */
101103 ait -> application_loop_length = gf_bs_read_int (bs ,12 );
102-
103- /* application loop */
104- ait -> organisation_id = gf_bs_read_int (bs ,32 );
105- ait -> application_id = gf_bs_read_int (bs ,16 );
106- ait -> application_control_code = gf_bs_read_int (bs ,8 );
107- gf_bs_read_int (bs ,4 );/* bit shifting */
108- ait -> application_descriptors_loop_length = gf_bs_read_int (bs ,12 );
109104
110105 data_shift = (u32 )(gf_bs_get_position (bs )) + ait -> common_descriptors_length /8 ;
111106
112- app_desc_data_shift = 0 ;
107+ while (ait_app_data_shift < ait -> application_loop_length ){
108+
109+ GF_M2TS_AIT_APPLICATION * application ;
110+ GF_SAFEALLOC (application ,GF_M2TS_AIT_APPLICATION );
111+ application -> application_descriptors = gf_list_new ();
113112
114- while (app_desc_data_shift < ait -> application_descriptors_loop_length ){
115- temp_descriptor_tag = gf_bs_read_int (bs ,8 );
116- switch (temp_descriptor_tag ){
113+ /* application loop */
114+ application -> organisation_id = gf_bs_read_int (bs ,32 );
115+ application -> application_id = gf_bs_read_int (bs ,16 );
116+ application -> application_control_code = gf_bs_read_int (bs ,8 );
117+ gf_bs_read_int (bs ,4 );/* bit shifting */
118+ application -> application_descriptors_loop_length = gf_bs_read_int (bs ,12 );
119+
120+ ait_app_data_shift += 9 ;
121+ app_desc_data_shift = 0 ;
122+
123+ while (app_desc_data_shift < application -> application_descriptors_loop_length ){
124+ temp_descriptor_tag = gf_bs_read_int (bs ,8 );
125+ switch (temp_descriptor_tag ){
117126 case APPLICATION_DESCRIPTOR :
118127 {
119128 u64 pre_processing_pos ;
@@ -135,7 +144,7 @@ GF_Err gf_m2ts_process_ait(GF_M2TS_Demuxer *ts, GF_M2TS_AIT *ait, char *data, u
135144 if (pre_processing_pos + application_descriptor -> descriptor_length != gf_bs_get_position (bs )){
136145 GF_LOG (GF_LOG_INFO , GF_LOG_CONTAINER , ("[Process AIT] Descriptor data processed length error. Difference between byte shifting %d and descriptor length %d \n" ,(gf_bs_get_position (bs ) - pre_processing_pos ),application_descriptor -> descriptor_length ));
137146 }
138- gf_list_add (ait -> application_descriptors ,application_descriptor );
147+ gf_list_add (application -> application_descriptors ,application_descriptor );
139148 app_desc_data_shift += (2 + application_descriptor -> descriptor_length );
140149 break ;
141150 }
@@ -155,7 +164,7 @@ GF_Err gf_m2ts_process_ait(GF_M2TS_Demuxer *ts, GF_M2TS_AIT *ait, char *data, u
155164 if (pre_processing_pos + name_descriptor -> descriptor_length != gf_bs_get_position (bs )){
156165 GF_LOG (GF_LOG_INFO , GF_LOG_CONTAINER , ("[Process AIT] Descriptor data processed length error. Difference between byte shifting %d and descriptor length %d \n" ,(gf_bs_get_position (bs ) - pre_processing_pos ),name_descriptor -> descriptor_length ));
157166 }
158- gf_list_add (ait -> application_descriptors ,name_descriptor );
167+ gf_list_add (application -> application_descriptors ,name_descriptor );
159168 app_desc_data_shift += (2 + name_descriptor -> descriptor_length );
160169 break ;
161170 }
@@ -170,61 +179,61 @@ GF_Err gf_m2ts_process_ait(GF_M2TS_Demuxer *ts, GF_M2TS_AIT *ait, char *data, u
170179 protocol_descriptor -> protocol_id = gf_bs_read_int (bs ,16 );
171180 protocol_descriptor -> transport_protocol_label = gf_bs_read_int (bs ,8 );
172181 printf ("protocol_descriptor->protocol_id %d \n" ,protocol_descriptor -> protocol_id );
173-
182+
174183 switch (protocol_descriptor -> protocol_id ){
175- case CAROUSEL :
176- {
177-
178- GF_M2TS_OBJECT_CAROUSEL_SELECTOR_BYTE * Carousel_selector_byte ;
179- GF_SAFEALLOC (Carousel_selector_byte , GF_M2TS_OBJECT_CAROUSEL_SELECTOR_BYTE );
180- Carousel_selector_byte -> remote_connection = gf_bs_read_int (bs ,1 );
181- gf_bs_read_int (bs ,7 ); /* bit shifting */
182- if (Carousel_selector_byte -> remote_connection ){
183- Carousel_selector_byte -> original_network_id = gf_bs_read_int (bs ,16 );
184- Carousel_selector_byte -> transport_stream_id = gf_bs_read_int (bs ,16 );
185- Carousel_selector_byte -> service_id = gf_bs_read_int (bs ,16 );
186- }
187- Carousel_selector_byte -> component_tag = gf_bs_read_int (bs ,8 );
188- protocol_descriptor -> selector_byte = Carousel_selector_byte ;
189- break ;
190- }
191- case TRANSPORT_HTTP :
192- {
193- u32 i ;
194- GF_M2TS_TRANSPORT_HTTP_SELECTOR_BYTE * Transport_http_selector_byte ;
195- GF_SAFEALLOC (Transport_http_selector_byte , GF_M2TS_TRANSPORT_HTTP_SELECTOR_BYTE );
196- Transport_http_selector_byte -> URL_base_length = gf_bs_read_int (bs ,8 );
197- //printf("Transport_http_selector_byte->URL_base_length %d \n",Transport_http_selector_byte->URL_base_length);
198- Transport_http_selector_byte -> URL_base_byte = (char * )gf_calloc (Transport_http_selector_byte -> URL_base_length ,sizeof (char ));
199- gf_bs_read_data (bs ,Transport_http_selector_byte -> URL_base_byte ,(u32 )(Transport_http_selector_byte -> URL_base_length ));
200- Transport_http_selector_byte -> URL_base_byte [Transport_http_selector_byte -> URL_base_length ] = 0 ;
201- Transport_http_selector_byte -> URL_extension_count = gf_bs_read_int (bs ,8 );
202- if (Transport_http_selector_byte -> URL_extension_count ){
203- Transport_http_selector_byte -> URL_extentions = (GF_M2TS_TRANSPORT_HTTP_URL_EXTENTION * ) gf_calloc (Transport_http_selector_byte -> URL_extension_count ,sizeof (GF_M2TS_TRANSPORT_HTTP_URL_EXTENTION ));
204- for (i = 0 ; i < Transport_http_selector_byte -> URL_extension_count ;i ++ ){
205- Transport_http_selector_byte -> URL_extentions [i ].URL_extension_length = gf_bs_read_int (bs ,8 );
206- Transport_http_selector_byte -> URL_extentions [i ].URL_extension_byte = (char * )gf_calloc (Transport_http_selector_byte -> URL_extentions [i ].URL_extension_length ,sizeof (char ));
207- gf_bs_read_data (bs ,Transport_http_selector_byte -> URL_extentions [i ].URL_extension_byte ,(u32 )(Transport_http_selector_byte -> URL_extentions [i ].URL_extension_length ));
208- Transport_http_selector_byte -> URL_extentions [i ].URL_extension_byte [Transport_http_selector_byte -> URL_extentions [i ].URL_extension_length ] = 0 ;
209- }
210- }
211- protocol_descriptor -> selector_byte = Transport_http_selector_byte ;
212- break ;
213- }
214- default :
215- {
216- GF_LOG (GF_LOG_INFO , GF_LOG_CONTAINER , ("[Process AIT] Protocol ID %d unsupported, ignoring the selector byte \n" ,protocol_descriptor -> protocol_id ));
217- }
184+ case CAROUSEL :
185+ {
186+
187+ GF_M2TS_OBJECT_CAROUSEL_SELECTOR_BYTE * Carousel_selector_byte ;
188+ GF_SAFEALLOC (Carousel_selector_byte , GF_M2TS_OBJECT_CAROUSEL_SELECTOR_BYTE );
189+ Carousel_selector_byte -> remote_connection = gf_bs_read_int (bs ,1 );
190+ gf_bs_read_int (bs ,7 ); /* bit shifting */
191+ if (Carousel_selector_byte -> remote_connection ){
192+ Carousel_selector_byte -> original_network_id = gf_bs_read_int (bs ,16 );
193+ Carousel_selector_byte -> transport_stream_id = gf_bs_read_int (bs ,16 );
194+ Carousel_selector_byte -> service_id = gf_bs_read_int (bs ,16 );
195+ }
196+ Carousel_selector_byte -> component_tag = gf_bs_read_int (bs ,8 );
197+ protocol_descriptor -> selector_byte = Carousel_selector_byte ;
198+ break ;
199+ }
200+ case TRANSPORT_HTTP :
201+ {
202+ u32 i ;
203+ GF_M2TS_TRANSPORT_HTTP_SELECTOR_BYTE * Transport_http_selector_byte ;
204+ GF_SAFEALLOC (Transport_http_selector_byte , GF_M2TS_TRANSPORT_HTTP_SELECTOR_BYTE );
205+ Transport_http_selector_byte -> URL_base_length = gf_bs_read_int (bs ,8 );
206+ //printf("Transport_http_selector_byte->URL_base_length %d \n",Transport_http_selector_byte->URL_base_length);
207+ Transport_http_selector_byte -> URL_base_byte = (char * )gf_calloc (Transport_http_selector_byte -> URL_base_length ,sizeof (char ));
208+ gf_bs_read_data (bs ,Transport_http_selector_byte -> URL_base_byte ,(u32 )(Transport_http_selector_byte -> URL_base_length ));
209+ Transport_http_selector_byte -> URL_base_byte [Transport_http_selector_byte -> URL_base_length ] = 0 ;
210+ Transport_http_selector_byte -> URL_extension_count = gf_bs_read_int (bs ,8 );
211+ if (Transport_http_selector_byte -> URL_extension_count ){
212+ Transport_http_selector_byte -> URL_extentions = (GF_M2TS_TRANSPORT_HTTP_URL_EXTENTION * ) gf_calloc (Transport_http_selector_byte -> URL_extension_count ,sizeof (GF_M2TS_TRANSPORT_HTTP_URL_EXTENTION ));
213+ for (i = 0 ; i < Transport_http_selector_byte -> URL_extension_count ;i ++ ){
214+ Transport_http_selector_byte -> URL_extentions [i ].URL_extension_length = gf_bs_read_int (bs ,8 );
215+ Transport_http_selector_byte -> URL_extentions [i ].URL_extension_byte = (char * )gf_calloc (Transport_http_selector_byte -> URL_extentions [i ].URL_extension_length ,sizeof (char ));
216+ gf_bs_read_data (bs ,Transport_http_selector_byte -> URL_extentions [i ].URL_extension_byte ,(u32 )(Transport_http_selector_byte -> URL_extentions [i ].URL_extension_length ));
217+ Transport_http_selector_byte -> URL_extentions [i ].URL_extension_byte [Transport_http_selector_byte -> URL_extentions [i ].URL_extension_length ] = 0 ;
218+ }
219+ }
220+ protocol_descriptor -> selector_byte = Transport_http_selector_byte ;
221+ break ;
222+ }
223+ default :
224+ {
225+ GF_LOG (GF_LOG_INFO , GF_LOG_CONTAINER , ("[Process AIT] Protocol ID %d unsupported, ignoring the selector byte \n" ,protocol_descriptor -> protocol_id ));
226+ }
218227 }
219228 if (pre_processing_pos + protocol_descriptor -> descriptor_length != gf_bs_get_position (bs )){
220229 GF_LOG (GF_LOG_INFO , GF_LOG_CONTAINER , ("[Process AIT] Descriptor data processed length error. Difference between byte shifting %d and descriptor length %d \n" ,(gf_bs_get_position (bs ) - pre_processing_pos ),protocol_descriptor -> descriptor_length ));
221230 }
222- gf_list_add (ait -> application_descriptors ,protocol_descriptor );
231+ gf_list_add (application -> application_descriptors ,protocol_descriptor );
223232 app_desc_data_shift += (2 + protocol_descriptor -> descriptor_length );
224233 break ;
225234 }
226235 case SIMPLE_APPLICATION_LOCATION_DESCRIPTOR :
227- {
236+ {
228237 u64 pre_processing_pos ;
229238 GF_M2TS_SIMPLE_APPLICATION_LOCATION * Simple_application_location ;
230239 GF_SAFEALLOC (Simple_application_location , GF_M2TS_SIMPLE_APPLICATION_LOCATION );
@@ -237,7 +246,7 @@ GF_Err gf_m2ts_process_ait(GF_M2TS_Demuxer *ts, GF_M2TS_AIT *ait, char *data, u
237246 if (pre_processing_pos + Simple_application_location -> descriptor_length != gf_bs_get_position (bs )){
238247 GF_LOG (GF_LOG_INFO , GF_LOG_CONTAINER , ("[Process AIT] Descriptor data processed length error. Difference between byte shifting %d and descriptor length %d \n" ,(gf_bs_get_position (bs ) - pre_processing_pos ),Simple_application_location -> descriptor_length ));
239248 }
240- gf_list_add (ait -> application_descriptors ,Simple_application_location );
249+ gf_list_add (application -> application_descriptors ,Simple_application_location );
241250 app_desc_data_shift += (2 + Simple_application_location -> descriptor_length );
242251 break ;
243252 }
@@ -253,22 +262,25 @@ GF_Err gf_m2ts_process_ait(GF_M2TS_Demuxer *ts, GF_M2TS_AIT *ait, char *data, u
253262 if (pre_processing_pos + Application_usage -> descriptor_length != gf_bs_get_position (bs )){
254263 GF_LOG (GF_LOG_INFO , GF_LOG_CONTAINER , ("[Process AIT] Descriptor data processed length error. Difference between byte shifting %d and descriptor length %d \n" ,(gf_bs_get_position (bs ) - pre_processing_pos ),Application_usage -> descriptor_length ));
255264 }
256- gf_list_add (ait -> application_descriptors ,Application_usage );
265+ gf_list_add (application -> application_descriptors ,Application_usage );
257266 app_desc_data_shift += (2 + Application_usage -> descriptor_length );
258267 break ;
259268 }
260-
261269
262- default :
263- {
264- GF_LOG (GF_LOG_INFO , GF_LOG_CONTAINER , ("[Process AIT] Descriptor tag %d unknown, ignoring the descriptor \n" ,temp_descriptor_tag ));
270+
271+ default :
272+ {
273+ GF_LOG (GF_LOG_INFO , GF_LOG_CONTAINER , ("[Process AIT] Descriptor tag %d unknown, ignoring the descriptor \n" ,temp_descriptor_tag ));
274+ }
275+
265276 }
266277
267278 }
268-
279+ ait_app_data_shift += application -> application_descriptors_loop_length ;
280+ gf_list_add (ait -> application ,application );
269281 }
270282
271- data_shift += ait -> application_descriptors_loop_length ;
283+ data_shift += ait -> application_loop_length ;
272284 ait -> CRC_32 = gf_bs_read_int (bs ,32 );
273285 data_shift += 4 ;
274286
0 commit comments