示例#1
0
文件: f4m.c 项目: gorinje/gpac-svn
AdobeMultirate *adobe_alloc_multirate_manifest(char *id)
{
	AdobeMultirate *am = gf_calloc(1, sizeof(AdobeMultirate));
	char filename[GF_MAX_PATH];

	//default init
	am->base_url = "http://localhost/hds/tmp";
	am->id = id;
	sprintf(filename, "%s.f4m", am->id);
	am->f = fopen(filename, "wt");
	if (!am->f) {
		fprintf(stderr, "Couldn't create Adobe multirate manifest file: %s\n", filename);
		assert(0);
		gf_free(am);
		return NULL;
	}
	am->streams = gf_list_new();

	//create a fake stream
	{
		AdobeStream *as = gf_calloc(1, sizeof(AdobeStream));
		as->id = "HD";
		as->bitrate = 100;
		sprintf(filename, "%s_%s_%d.f4m", am->id, as->id, as->bitrate); 
		as->f = fopen(filename, "wt"); 
		if (!as->f) { 
			fprintf(stderr, "Couldn't create Adobe stream manifest file: %s\n", filename); 
			assert(0); 
			gf_list_del(am->streams); 
			gf_free(as); 
			gf_free(am); 
			return NULL; 
		} 
		gf_list_add(am->streams, as);
	}

	return am;
}
示例#2
0
static char* wcs_to_utf8(const wchar_t* str)
{
	size_t source_len;
	char* result;
	if (str == 0) return 0;
	source_len = wcslen(str);
	result = gf_calloc(source_len + 1, UTF8_MAX_BYTES_PER_CHAR);
	if (!result)
		return 0;
	if (gf_utf8_wcstombs(result, source_len * UTF8_MAX_BYTES_PER_CHAR, &str) < 0) {
		gf_free(result);
		return 0;
	}
	return result;
}
示例#3
0
static wchar_t* utf8_to_wcs(const char* str)
{
	size_t source_len;
	wchar_t* result;
	if (str == 0) return 0;
	source_len = strlen(str);
	result = gf_calloc(source_len + 1, sizeof(wchar_t));
	if (!result)
		return 0;
	if (gf_utf8_mbstowcs(result, source_len, &str) < 0) {
		gf_free(result);
		return 0;
	}
	return result;
}
示例#4
0
文件: ait.c 项目: gorinje/gpac-svn
static GF_Err gf_m2ts_decode_ait(GF_M2TS_AIT *ait, char  *data, u32 data_size, u32 table_id)
{

	GF_BitStream *bs;
	u8 temp_descriptor_tag;
	u32 data_shift, app_desc_data_shift, ait_app_data_shift;
	u32 nb_of_protocol;

	data_shift = 0;
	temp_descriptor_tag = 0;
	ait_app_data_shift = 0;
	bs = gf_bs_new(data,data_size,GF_BITSTREAM_READ);

	ait->common_descriptors = gf_list_new();
	if(ait->common_descriptors == NULL){
		GF_LOG(GF_LOG_INFO, GF_LOG_CONTAINER, ("[Process AIT] Error during common_descriptors list initialization, abording processing \n"));
		return GF_CORRUPTED_DATA;
	}
	ait->application_decoded = gf_list_new();
	if(ait->application_decoded == NULL){
		GF_LOG(GF_LOG_INFO, GF_LOG_CONTAINER, ("[Process AIT] Error during application list initialization, abording processing \n"));
		return GF_CORRUPTED_DATA;
	}

	ait->table_id = gf_bs_read_int(bs,8);	
	ait->section_syntax_indicator = gf_bs_read_int(bs,1);
	gf_bs_read_int(bs,3);
	ait->section_length = gf_bs_read_int(bs,12);	
	if( (data[1] & 0x0C) != 0){
		GF_LOG(GF_LOG_INFO, GF_LOG_CONTAINER, ("[Process AIT] section length is not correct abroding \n"));
	}else if( ait->section_length > AIT_SECTION_LENGTH_MAX){
		GF_LOG(GF_LOG_INFO, GF_LOG_CONTAINER, ("[Process AIT] section length should not exceed 1021. Wrong section, abording processing \n"));
	}
	ait->test_application_flag = gf_bs_read_int(bs,1);
	if(ait->test_application_flag == 1){
		GF_LOG(GF_LOG_INFO, GF_LOG_CONTAINER, ("[Process AIT] test application flag is at 1. API transmitted for testing, abording processing \n"));
		return GF_CORRUPTED_DATA;
	}
	ait->application_type = gf_bs_read_int(bs,15);	
	if(ait->application_type != APPLICATION_TYPE_HTTP_APPLICATION){
		GF_LOG(GF_LOG_INFO, GF_LOG_CONTAINER, ("[Process AIT] application type should 0x10. Wrong section, abording processing \n"));
		return GF_CORRUPTED_DATA;
	}
	gf_bs_read_int(bs,2);
	ait->version_number = gf_bs_read_int(bs,5);

	ait->current_next_indicator = gf_bs_read_int(bs,1);	
	if(!ait->current_next_indicator){
		GF_LOG(GF_LOG_INFO, GF_LOG_CONTAINER, ("[Process AIT] current next indicator should be at 1 \n"));
		return GF_CORRUPTED_DATA;
	}
	ait->section_number = gf_bs_read_int(bs,8);
	ait->last_section_number = gf_bs_read_int(bs,8);	
	gf_bs_read_int(bs,4);/* bit shifting */
	ait->common_descriptors_length = gf_bs_read_int(bs,12);	
	gf_bs_read_int(bs,(unsigned int)ait->common_descriptors_length/8);
	gf_bs_read_int(bs,4);/* bit shifting */	
	ait->application_loop_length = gf_bs_read_int(bs,12);

	data_shift = (u32)(gf_bs_get_position(bs)) + ait->common_descriptors_length/8;

	while (ait_app_data_shift < ait->application_loop_length) {

		GF_M2TS_AIT_APPLICATION_DECODE* application;
		GF_SAFEALLOC(application,GF_M2TS_AIT_APPLICATION_DECODE);
		application->application_descriptors = gf_list_new();
		application->index_app_desc_id = 0;

		/* application loop */
		application->organisation_id = gf_bs_read_int(bs,32);	
		application->application_id= gf_bs_read_int(bs,16);
		application->application_control_code= gf_bs_read_int(bs,8);
		gf_bs_read_int(bs,4);/* bit shifting */
		application->application_descriptors_loop_length= gf_bs_read_int(bs,12);		

		ait_app_data_shift += 9;
		app_desc_data_shift = 0;
		nb_of_protocol = 0;

		while (app_desc_data_shift< application->application_descriptors_loop_length) {
			temp_descriptor_tag = gf_bs_read_int(bs,8);
			switch (temp_descriptor_tag) {
				case APPLICATION_DESCRIPTOR:
					{
						u64 pre_processing_pos;
						u8 i;
						GF_M2TS_APPLICATION_DESCRIPTOR *application_descriptor;
						GF_SAFEALLOC(application_descriptor, GF_M2TS_APPLICATION_DESCRIPTOR);
						application_descriptor->descriptor_tag = temp_descriptor_tag;
						application->application_descriptors_id[application->index_app_desc_id] = temp_descriptor_tag;
						application->index_app_desc_id++;
						application_descriptor->descriptor_length = gf_bs_read_int(bs,8);
						pre_processing_pos = gf_bs_get_position(bs);
						application_descriptor->application_profiles_length = gf_bs_read_int(bs,8);
						application_descriptor->application_profile = gf_bs_read_int(bs,16);
						application_descriptor->version_major = gf_bs_read_int(bs,8);
						application_descriptor->version_minor = gf_bs_read_int(bs,8);
						application_descriptor->version_micro = gf_bs_read_int(bs,8);
						application_descriptor->service_bound_flag = gf_bs_read_int(bs,1);
						application_descriptor->visibility = gf_bs_read_int(bs,2);
						gf_bs_read_int(bs,5); /*bit shift*/
						application_descriptor->application_priority = gf_bs_read_int(bs,8);
						if (nb_of_protocol > 0) {
							for (i=0; i<nb_of_protocol; i++) {						
								application_descriptor->transport_protocol_label[i] = gf_bs_read_int(bs,8);
							}
						} else {
							application_descriptor->transport_protocol_label[0] = gf_bs_read_int(bs,8);
						}
						if (pre_processing_pos+application_descriptor->descriptor_length != gf_bs_get_position(bs) || application_descriptor->application_profile == 2 /* PVR feature */) {
							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));
							gf_free(application_descriptor);
							return GF_CORRUPTED_DATA;
						}
						gf_list_add(application->application_descriptors,application_descriptor);
						app_desc_data_shift += (2+ application_descriptor->descriptor_length);
						break;
					}
				case APPLICATION_NAME_DESCRIPTOR:
					{
						u64 pre_processing_pos;
						GF_M2TS_APPLICATION_NAME_DESCRIPTOR* name_descriptor;
						GF_SAFEALLOC(name_descriptor, GF_M2TS_APPLICATION_NAME_DESCRIPTOR);
						application->application_descriptors_id[application->index_app_desc_id] = temp_descriptor_tag;
						application->index_app_desc_id++;
						name_descriptor->descriptor_tag = temp_descriptor_tag;
						name_descriptor->descriptor_length = gf_bs_read_int(bs,8);
						pre_processing_pos = gf_bs_get_position(bs);
						name_descriptor->ISO_639_language_code = gf_bs_read_int(bs,24);
						name_descriptor->application_name_length = gf_bs_read_int(bs,8);
						name_descriptor->application_name_char = (char*) gf_calloc(name_descriptor->application_name_length+1,sizeof(char));
						gf_bs_read_data(bs,name_descriptor->application_name_char,name_descriptor->application_name_length);
						name_descriptor->application_name_char[name_descriptor->application_name_length] = 0 ;
						if (pre_processing_pos+name_descriptor->descriptor_length != gf_bs_get_position(bs)) {
							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));
							gf_free(name_descriptor->application_name_char);
							gf_free(name_descriptor);
							return GF_CORRUPTED_DATA;
						}
						gf_list_add(application->application_descriptors,name_descriptor);
						app_desc_data_shift += (2+ name_descriptor->descriptor_length);
						break;
					}
				case TRANSPORT_PROTOCOL_DESCRIPTOR:
					{
						u64 pre_processing_pos;
						GF_M2TS_TRANSPORT_PROTOCOL_DESCRIPTOR* protocol_descriptor;
						GF_SAFEALLOC(protocol_descriptor, GF_M2TS_TRANSPORT_PROTOCOL_DESCRIPTOR);
						application->application_descriptors_id[application->index_app_desc_id] = temp_descriptor_tag;
						application->index_app_desc_id++;
						nb_of_protocol++;
						protocol_descriptor->descriptor_tag = temp_descriptor_tag;
						protocol_descriptor->descriptor_length = gf_bs_read_int(bs,8);
						pre_processing_pos = gf_bs_get_position(bs);
						protocol_descriptor->protocol_id = gf_bs_read_int(bs,16);
						protocol_descriptor->transport_protocol_label = gf_bs_read_int(bs,8);
						switch (protocol_descriptor->protocol_id) {
				case CAROUSEL:
					{
						GF_M2TS_OBJECT_CAROUSEL_SELECTOR_BYTE* Carousel_selector_byte;
						GF_SAFEALLOC(Carousel_selector_byte, GF_M2TS_OBJECT_CAROUSEL_SELECTOR_BYTE);
						Carousel_selector_byte->remote_connection = gf_bs_read_int(bs,1);
						gf_bs_read_int(bs,7); /* bit shifting */
						if (Carousel_selector_byte->remote_connection) {
							Carousel_selector_byte->original_network_id = gf_bs_read_int(bs,16);
							Carousel_selector_byte->transport_stream_id = gf_bs_read_int(bs,16);
							Carousel_selector_byte->service_id = gf_bs_read_int(bs,16);
						}
						Carousel_selector_byte->component_tag = gf_bs_read_int(bs,8);
						protocol_descriptor->selector_byte = Carousel_selector_byte;
						break;
					}
				case TRANSPORT_HTTP:
					{					
						u32 i;								
						GF_M2TS_TRANSPORT_HTTP_SELECTOR_BYTE* Transport_http_selector_byte;
						GF_SAFEALLOC(Transport_http_selector_byte, GF_M2TS_TRANSPORT_HTTP_SELECTOR_BYTE);					
						Transport_http_selector_byte->URL_base_length = gf_bs_read_int(bs,8);
						//fprintf(stderr, "Transport_http_selector_byte->URL_base_length %d \n",Transport_http_selector_byte->URL_base_length);
						Transport_http_selector_byte->URL_base_byte = (char*)gf_calloc(Transport_http_selector_byte->URL_base_length+1,sizeof(char));
						gf_bs_read_data(bs,Transport_http_selector_byte->URL_base_byte ,(u32)(Transport_http_selector_byte->URL_base_length));
						Transport_http_selector_byte->URL_base_byte[Transport_http_selector_byte->URL_base_length] = 0;
						Transport_http_selector_byte->URL_extension_count = gf_bs_read_int(bs,8);
						if (Transport_http_selector_byte->URL_extension_count) {
							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));
							for (i=0; i < Transport_http_selector_byte->URL_extension_count;i++) {
								Transport_http_selector_byte->URL_extentions[i].URL_extension_length = gf_bs_read_int(bs,8);
								Transport_http_selector_byte->URL_extentions[i].URL_extension_byte = (char*)gf_calloc(Transport_http_selector_byte->URL_extentions[i].URL_extension_length+1,sizeof(char));
								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));
								Transport_http_selector_byte->URL_extentions[i].URL_extension_byte[Transport_http_selector_byte->URL_extentions[i].URL_extension_length] = 0;
							}
						}
						protocol_descriptor->selector_byte = Transport_http_selector_byte;
						break;
					}
				default:
					{
						GF_LOG(GF_LOG_INFO, GF_LOG_CONTAINER, ("[Process AIT] Protocol ID %d unsupported, ignoring the selector byte \n",protocol_descriptor->protocol_id));
					}
						}
						if (pre_processing_pos+protocol_descriptor->descriptor_length != gf_bs_get_position(bs)) {
							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));
							if (protocol_descriptor->protocol_id == CAROUSEL) {						
								GF_M2TS_OBJECT_CAROUSEL_SELECTOR_BYTE* Carousel_selector_byte = (GF_M2TS_OBJECT_CAROUSEL_SELECTOR_BYTE*) protocol_descriptor->selector_byte;								
								gf_free(Carousel_selector_byte);								
							} else if(protocol_descriptor->protocol_id ==TRANSPORT_HTTP) {
								u32 i;
								GF_M2TS_TRANSPORT_HTTP_SELECTOR_BYTE* Transport_http_selector_byte = (GF_M2TS_TRANSPORT_HTTP_SELECTOR_BYTE*) protocol_descriptor->selector_byte;								
								gf_free(Transport_http_selector_byte->URL_base_byte);
								for(i = 0; i < Transport_http_selector_byte->URL_extension_count;i++){										
									gf_free(Transport_http_selector_byte->URL_extentions[i].URL_extension_byte);
								}
								gf_free(Transport_http_selector_byte);						
							}
							gf_free(protocol_descriptor);
							return GF_CORRUPTED_DATA;
						}
						gf_list_add(application->application_descriptors,protocol_descriptor);					
						app_desc_data_shift += (2+ protocol_descriptor->descriptor_length);
						break;
					}
				case SIMPLE_APPLICATION_LOCATION_DESCRIPTOR:
					{
						u64 pre_processing_pos;					
						GF_M2TS_SIMPLE_APPLICATION_LOCATION* Simple_application_location;
						GF_SAFEALLOC(Simple_application_location, GF_M2TS_SIMPLE_APPLICATION_LOCATION);
						application->application_descriptors_id[application->index_app_desc_id] = temp_descriptor_tag;
						application->index_app_desc_id++;
						Simple_application_location->descriptor_tag = temp_descriptor_tag;
						Simple_application_location->descriptor_length = gf_bs_read_int(bs,8);
						pre_processing_pos = gf_bs_get_position(bs);
						Simple_application_location->initial_path_bytes = (char*)gf_calloc(Simple_application_location->descriptor_length+1,sizeof(char));
						gf_bs_read_data(bs,Simple_application_location->initial_path_bytes ,(u32)(Simple_application_location->descriptor_length));
						Simple_application_location->initial_path_bytes[Simple_application_location->descriptor_length] = 0;
						if (pre_processing_pos+Simple_application_location->descriptor_length != gf_bs_get_position(bs)) {
							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));
							gf_free(Simple_application_location->initial_path_bytes);
							gf_free(Simple_application_location);
							return GF_CORRUPTED_DATA;
						}
						gf_list_add(application->application_descriptors,Simple_application_location);
						app_desc_data_shift += (2+ Simple_application_location->descriptor_length);
						break;
					}
				case APPLICATION_USAGE_DESCRIPTOR:
					{
						u64 pre_processing_pos;
						GF_M2TS_APPLICATION_USAGE* Application_usage;
						GF_SAFEALLOC(Application_usage, GF_M2TS_APPLICATION_USAGE);
						application->application_descriptors_id[application->index_app_desc_id] = temp_descriptor_tag;
						application->index_app_desc_id++;
						Application_usage->descriptor_tag = temp_descriptor_tag;
						Application_usage->descriptor_length = gf_bs_read_int(bs,8);
						pre_processing_pos = gf_bs_get_position(bs);
						Application_usage->usage_type = gf_bs_read_int(bs,8);
						if (pre_processing_pos+Application_usage->descriptor_length != gf_bs_get_position(bs)) {
							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));
							gf_free(Application_usage);
							return GF_CORRUPTED_DATA;
						}
						gf_list_add(application->application_descriptors,Application_usage);
						app_desc_data_shift += (2+ Application_usage->descriptor_length);
						break;
					}
				case APPLICATION_BOUNDARY_DESCRIPTOR:
					{
						u64 pre_processing_pos;
						u32 i;
						GF_M2TS_APPLICATION_BOUNDARY_DESCRIPTOR* boundary_descriptor;
						GF_SAFEALLOC(boundary_descriptor, GF_M2TS_APPLICATION_BOUNDARY_DESCRIPTOR);
						application->application_descriptors_id[application->index_app_desc_id] = temp_descriptor_tag;
						application->index_app_desc_id++;
						boundary_descriptor->descriptor_tag = temp_descriptor_tag;
						boundary_descriptor->descriptor_length = gf_bs_read_int(bs,8);
						pre_processing_pos = gf_bs_get_position(bs);
						boundary_descriptor->boundary_extension_count = gf_bs_read_int(bs,8);
						if (boundary_descriptor->boundary_extension_count > 0) {
							boundary_descriptor->boundary_extension_info = (GF_M2TS_APPLICATION_BOUNDARY_EXTENSION_INFO*)gf_calloc(boundary_descriptor->boundary_extension_count,sizeof(GF_M2TS_APPLICATION_BOUNDARY_EXTENSION_INFO));
							for (i=0;i<boundary_descriptor->boundary_extension_count;i++) {
								boundary_descriptor->boundary_extension_info[i].boundary_extension_length = gf_bs_read_int(bs,8);
								if (boundary_descriptor->boundary_extension_info[i].boundary_extension_length > 0) {
									boundary_descriptor->boundary_extension_info[i].boundary_extension_byte = (char*)gf_calloc(boundary_descriptor->boundary_extension_info[i].boundary_extension_length+1,sizeof(char));
									gf_bs_read_data(bs,boundary_descriptor->boundary_extension_info[i].boundary_extension_byte ,(u32)(boundary_descriptor->boundary_extension_info[i].boundary_extension_length));
									boundary_descriptor->boundary_extension_info[i].boundary_extension_byte[boundary_descriptor->boundary_extension_info[i].boundary_extension_length] = 0;
								}
							}
						}
						if (pre_processing_pos+boundary_descriptor->descriptor_length != gf_bs_get_position(bs)) {
							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),boundary_descriptor->descriptor_length));
							if (boundary_descriptor->boundary_extension_count > 0) {
								u32 i;
								for (i=0;i<boundary_descriptor->boundary_extension_count;i++) {
									if (boundary_descriptor->boundary_extension_info[i].boundary_extension_length > 0) {
										gf_free(boundary_descriptor->boundary_extension_info[i].boundary_extension_byte);
									}
								}
								gf_free(boundary_descriptor->boundary_extension_info);
							}
							gf_free(boundary_descriptor);
							return GF_CORRUPTED_DATA;
						}
						gf_list_add(application->application_descriptors,boundary_descriptor);
						app_desc_data_shift += (2+ boundary_descriptor->descriptor_length);
						break;					
					}
				default:
					{
						u8 length;
						GF_LOG(GF_LOG_INFO, GF_LOG_CONTAINER, ("[Process AIT] Descriptor tag %d unknown, ignoring the descriptor \n",temp_descriptor_tag));
						/* get descriptor's length */
						length = gf_bs_read_int(bs,8);
						/* bit shifting (eq descriptor's length)*/
						gf_bs_read_int(bs,8*length);					
					}

			}

		}
		ait_app_data_shift += application->application_descriptors_loop_length; 
		gf_list_add(ait->application_decoded,application);		
	}

	data_shift +=ait->application_loop_length;
	ait->CRC_32 = gf_bs_read_int(bs,32);
	data_shift += 4;


	if (data_shift != data_size) {
		GF_LOG(GF_LOG_INFO, GF_LOG_CONTAINER, ("[Process AIT] AIT processed length error. Difference between byte shifting %d and data size %d \n",data_shift,data_size));
		return GF_CORRUPTED_DATA;
	}

	return GF_OK;
}
示例#5
0
文件: ait.c 项目: gorinje/gpac-svn
static void gf_m2ts_process_ait(GF_M2TS_Demuxer *ts, GF_M2TS_AIT* ait){

	u32 nb_app_desc, k, desc_id, nb_of_app, j;
	GF_M2TS_CHANNEL_APPLICATION_INFO* ChanAppInfo;
	char *url_base, *url_appli_path;

	nb_of_app = gf_list_count(ait->application_decoded);
	url_base = NULL;
	url_appli_path = NULL;
	j=0;

	/* Link the AIT and the channel */
	ChanAppInfo = gf_m2ts_get_channel_application_info(ts->ChannelAppList,ait->service_id);	

	if(!ChanAppInfo){
		GF_SAFEALLOC(ChanAppInfo,GF_M2TS_CHANNEL_APPLICATION_INFO);
		ChanAppInfo->service_id = ait->service_id;
		ChanAppInfo->Application = gf_list_new();
		ChanAppInfo->ait_pid = ait->pid;
		gf_list_add(ts->ChannelAppList,ChanAppInfo);
	}

	ChanAppInfo->nb_application = nb_of_app;

	GF_LOG(GF_LOG_DEBUG, GF_LOG_CONTAINER, ("[DSMCC] ChanAppInfo->nb_application %d \n",ChanAppInfo->nb_application));
	
	for(j=0 ; j<nb_of_app ; j++){
		GF_M2TS_AIT_APPLICATION* Application;
		GF_M2TS_AIT_APPLICATION_DECODE* application_decoded;
		GF_SAFEALLOC(Application,GF_M2TS_AIT_APPLICATION);
		gf_list_add(ChanAppInfo->Application,Application);			
		Application->http_url = NULL;
		Application->carousel_url = NULL;

		application_decoded = (GF_M2TS_AIT_APPLICATION_DECODE*)gf_list_get(ait->application_decoded,j);
		nb_app_desc = gf_list_count(application_decoded->application_descriptors);
		Application->application_control_code = application_decoded->application_control_code;
		Application->application_id = application_decoded->application_id;
		Application->broadband = 0;
		Application->broadcast = 0;
		ChanAppInfo->version_number = ait->version_number;
		
		k=0;
		for(k=0 ; k<nb_app_desc ; k++){
			desc_id = application_decoded->application_descriptors_id[k];
			switch(desc_id){
							case APPLICATION_DESCRIPTOR:
								{
									GF_M2TS_APPLICATION_DESCRIPTOR* application_descriptor = (GF_M2TS_APPLICATION_DESCRIPTOR*)gf_list_get(application_decoded->application_descriptors,k);
									Application->priority = application_descriptor->application_priority;
									Application->application_profile = application_descriptor->application_profile;

									break;
								}
							case APPLICATION_NAME_DESCRIPTOR:
								{
									GF_M2TS_APPLICATION_NAME_DESCRIPTOR* name_descriptor = (GF_M2TS_APPLICATION_NAME_DESCRIPTOR*)gf_list_get(application_decoded->application_descriptors,k);
									Application->appli_name = gf_strdup(name_descriptor->application_name_char);
									break;
								}
							case TRANSPORT_PROTOCOL_DESCRIPTOR:
								{
									GF_M2TS_TRANSPORT_PROTOCOL_DESCRIPTOR* protocol_descriptor = (GF_M2TS_TRANSPORT_PROTOCOL_DESCRIPTOR*)gf_list_get(application_decoded->application_descriptors,k);

									switch(protocol_descriptor->protocol_id){
										case CAROUSEL:
											{									
												GF_Err e;												
												GF_M2TS_OBJECT_CAROUSEL_SELECTOR_BYTE* Carousel_selector_byte = (GF_M2TS_OBJECT_CAROUSEL_SELECTOR_BYTE*)protocol_descriptor->selector_byte;
												if(ts->process_dmscc){
													GF_M2TS_DSMCC_OVERLORD* dsmcc_overlord = gf_m2ts_get_dmscc_overlord(ts->dsmcc_controler,ait->service_id);
													Application->broadcast = 1;
													if(!dsmcc_overlord){
														char app_url[1024], char_service_id[128];
														
														memset(&app_url,0,1024*sizeof(char));
														memset(&char_service_id,0,128*sizeof(char));

														dsmcc_overlord = gf_m2ts_init_dsmcc_overlord(ait->service_id);
														dsmcc_overlord->application_id = Application->application_id;
														sprintf(char_service_id,"%d",dsmcc_overlord->service_id);
														dsmcc_overlord->root_dir = (char*)gf_calloc(strlen(ts->dsmcc_root_dir)+2+strlen(char_service_id),sizeof(char));
														sprintf(dsmcc_overlord->root_dir,"%s%c%s",ts->dsmcc_root_dir,GF_PATH_SEPARATOR,char_service_id);
														e = gf_mkdir(dsmcc_overlord->root_dir);
														if(e){															
															GF_LOG(GF_LOG_INFO, GF_LOG_CONTAINER, ("[Process DSMCC] Error during the creation of the directory %s \n",dsmcc_overlord->root_dir));
															if(e == GF_BAD_PARAM){
																gf_cleanup_dir(dsmcc_overlord->root_dir);
															}
														}
														sprintf(app_url,"%s%cindex.html",dsmcc_overlord->root_dir,GF_PATH_SEPARATOR);
														Application->carousel_url = gf_strdup(app_url);											
														gf_list_add(ts->dsmcc_controler,dsmcc_overlord);
													}
												}
												if(Carousel_selector_byte->remote_connection){
													Application->carousel_pid = Carousel_selector_byte->service_id;
												}
												Application->component_tag = Carousel_selector_byte->component_tag;

												break;
											}
										case TRANSPORT_HTTP:
											{
												GF_M2TS_TRANSPORT_HTTP_SELECTOR_BYTE* Transport_http_selector_byte = (GF_M2TS_TRANSPORT_HTTP_SELECTOR_BYTE*)protocol_descriptor->selector_byte;
												url_base = Transport_http_selector_byte->URL_base_byte;
												Application->broadband = 1;
											}
										default:
											{
											}
									}
									break;
								}
							case SIMPLE_APPLICATION_LOCATION_DESCRIPTOR:
								{
									GF_M2TS_SIMPLE_APPLICATION_LOCATION* Simple_application_location = (GF_M2TS_SIMPLE_APPLICATION_LOCATION*)gf_list_get(application_decoded->application_descriptors,k);
									url_appli_path = Simple_application_location->initial_path_bytes;
									break;
								}
							case APPLICATION_USAGE_DESCRIPTOR:
								{
									break;
								}
							default:
								{
									GF_LOG(GF_LOG_DEBUG, GF_LOG_MODULE, ("[Process AIT] Descriptor tag %d unknown, ignoring the descriptor \n",desc_id));
								}
			}

			if((url_base != NULL) && ( url_appli_path != NULL)){
				u32 url_length = (strlen(url_base)+strlen(url_appli_path));
				Application->http_url = (char*)gf_calloc(url_length + 1,sizeof(char));
				sprintf(Application->http_url,"%s%s",url_base,url_appli_path);
				Application->http_url[url_length]=0;
				Application->url_received = 1;
				url_base = NULL;
				url_appli_path = NULL;
				GF_LOG(GF_LOG_INFO, GF_LOG_MODULE, ("[Process AIT] SERVICE ID %d  URL %s  \n",ChanAppInfo->service_id,Application->http_url));
			}

		}
	}
	if(ts->process_dmscc){
		GF_M2TS_DSMCC_OVERLORD* dsmcc_overlord = gf_m2ts_get_dmscc_overlord(ts->dsmcc_controler,ait->service_id);

		if(dsmcc_overlord && !gf_m2ts_is_dmscc_app(ChanAppInfo)){			
			gf_cleanup_dir(dsmcc_overlord->root_dir);
			gf_rmdir(dsmcc_overlord->root_dir);	
			gf_m2ts_delete_dsmcc_overlord(dsmcc_overlord);

		}
	}
}
示例#6
0
GF_Err adobize_segment(GF_ISOFile *isom_file, AdobeHDSCtx *ctx)
{
	GF_Err e;
	GF_BitStream *bs;

	GF_AdobeFragRandomAccessBox *afra = (GF_AdobeFragRandomAccessBox*)	afra_New();
	GF_AfraEntry *ae                  = (GF_AfraEntry*)					gf_calloc(1, sizeof(GF_AfraEntry));
	GF_AdobeBootstrapInfoBox *abst    = (GF_AdobeBootstrapInfoBox*)		abst_New();
	GF_AdobeSegmentRunTableBox *asrt  = (GF_AdobeSegmentRunTableBox*)	asrt_New();
	GF_AdobeSegmentRunEntry *asre     = (GF_AdobeSegmentRunEntry*)		gf_calloc(1, sizeof(GF_AdobeSegmentRunEntry));
	GF_AdobeFragmentRunTableBox *afrt = (GF_AdobeFragmentRunTableBox*)	afrt_New();
	GF_AdobeFragmentRunEntry *afre    = (GF_AdobeFragmentRunEntry*)		gf_calloc(1, sizeof(GF_AdobeFragmentRunEntry));

	u64 init_seg_time = ctx->curr_time;
	u32 seg_duration = (u32)gf_isom_get_duration(isom_file);

	//update context
	ctx->curr_time += seg_duration;

	//Adobe specific boxes
	//Random Access
	afra->type = GF_4CC('a', 'f', 'r', 'a');
	afra->version = 0;
	afra->flags = 0;
	afra->long_ids = 1;
	afra->long_offsets = 1;
	afra->global_entries = 0;
	afra->time_scale = gf_isom_get_timescale(isom_file);

	afra->entry_count = 1;
	ae->time = init_seg_time;
	ae->offset = 3999;
	gf_list_add(afra->local_access_entries, ae);

	afra->global_entries = 0;
	afra->global_entry_count = 0;

	e = gf_list_add(isom_file->TopBoxes, afra);
	if (e) {
		fprintf(stderr, "Impossible to write AFRA box: %s\n", gf_error_to_string(e));
		assert(0);
		return e;
	}

	//Bootstrap Info
	abst->type = GF_4CC('a', 'b', 's', 't');
	abst->version = 0;
	abst->flags = 0;
	abst->bootstrapinfo_version = 1;
	abst->profile = 0;
	abst->live = 1;
	abst->update = 0;
	abst->time_scale = gf_isom_get_timescale(isom_file);
	abst->current_media_time = init_seg_time+seg_duration;
	abst->smpte_time_code_offset = 0;

	abst->movie_identifier = NULL;
	abst->drm_data = NULL;
	abst->meta_data = NULL;

	abst->server_entry_count = 0;
	abst->quality_entry_count = 0;

	abst->segment_run_table_count = 1;
	{
		//Segment Run
		asrt->type = GF_4CC('a', 's', 'r', 't');
		asrt->version = 0;
		asrt->flags = 0;
		asrt->segment_run_entry_count = 1;
		{
			asre->first_segment = ctx->segnum;
			asre->fragment_per_segment = 1;
		}
		e = gf_list_add(asrt->segment_run_entry_table, asre);
		if (e) {
			fprintf(stderr, "Impossible to write ASR Entry: %s\n", gf_error_to_string(e));
			assert(0);
			return e;
		}
	}
	e = gf_list_add(abst->segment_run_table_entries, asrt);
	if (e) {
		fprintf(stderr, "Impossible to write ASRT box: %s\n", gf_error_to_string(e));
		assert(0);
		return e;
	}

	abst->fragment_run_table_count = 1;
	{
		//Fragment Run
		afrt->type = GF_4CC('a', 'f', 'r', 't');
		afrt->version = 0;
		afrt->flags = 0;
		afrt->timescale = gf_isom_get_timescale(isom_file);
		afrt->fragment_run_entry_count = 1;
		{
			afre->first_fragment = 1;
			afre->first_fragment_timestamp = 0;
			afre->fragment_duration = seg_duration;
		}
		e = gf_list_add(afrt->fragment_run_entry_table, afre);
		if (e) {
			fprintf(stderr, "Impossible to write AFR Entry: %s\n", gf_error_to_string(e));
			assert(0);
			return e;
		}
	}
	e = gf_list_add(abst->fragment_run_table_entries, afrt);
	if (e) {
		fprintf(stderr, "Impossible to write AFRT box: %s\n", gf_error_to_string(e));
		assert(0);
		return e;
	}

	e = gf_list_add(isom_file->TopBoxes, abst);
	if (e) {
		fprintf(stderr, "Impossible to write ABST box: %s\n", gf_error_to_string(e));
		assert(0);
		return e;
	}

	e = abst_Size((GF_Box*)abst);
	if (e) {
		fprintf(stderr, "Impossible to compute ABST box size: %s\n", gf_error_to_string(e));
		assert(0);
		return e;
	}
	ctx->bootstrap_size = (size_t)abst->size;
	ctx->bootstrap = gf_malloc(ctx->bootstrap_size);
	bs = gf_bs_new(ctx->bootstrap, ctx->bootstrap_size, GF_BITSTREAM_WRITE);
	e = abst_Write((GF_Box*)abst, bs);
	if (e) {
		fprintf(stderr, "Impossible to code the ABST box: %s\n", gf_error_to_string(e));
		assert(0);
		gf_bs_del(bs);
		return e;
	}
	gf_bs_del(bs);

	//set brands as reversed engineered from f4v files
	/*e = gf_isom_reset_alt_brands(isom_file);
	if (e) {
		fprintf(stderr, "Warning: couldn't reset ISOM brands: %s\n", gf_error_to_string(e));
		assert(0);
	}*/
	gf_isom_set_brand_info(isom_file, GF_4CC('f','4','v',' '), 1);
	gf_isom_modify_alternate_brand(isom_file, GF_4CC('i','s','o','m'), 1);
	gf_isom_modify_alternate_brand(isom_file, GF_4CC('m','p','4','2'), 1);
	gf_isom_modify_alternate_brand(isom_file, GF_4CC('m','4','v',' '), 1);

	return GF_OK;
}