⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mosaic_parse.c

📁 c语言编的
💻 C
📖 第 1 页 / 共 4 页
字号:
			     
			    /* here the mosaic_des_length is transport the section_number of the EIT P/F section */    
			   	memset ( ( char * ) ms_eitpf_event [ mosaic_des_length ] . event_name, 0, /*30*/MS_MAX_EVENT_NAME_LENGTH + 1 );
			   	no_of_bytes_parsed = event_length > /*30*/MS_MAX_EVENT_NAME_LENGTH ? /*30*/MS_MAX_EVENT_NAME_LENGTH : event_length;
			   	memcpy ( ( char * ) ms_eitpf_event [ mosaic_des_length ] . event_name , ( char * ) mosaic_des_data , no_of_bytes_parsed );	                
                                
			   	mosaic_des_data += event_length;
			   	
			   	APP_TRACE("\nevent name=%s\n",ms_eitpf_event [ mosaic_des_length ].event_name );
			}
			iNoOfBytesParsed =  desc_length + 2; 
			break;  	   		   	                  
        	   		   	        
	    default:/*iNoOfBytesParsed = mosaic_des_length;*/
	    	desc_length = mosaic_des_data[ 1 ];
	  	  
	        iNoOfBytesParsed = desc_length + 2;	    
	    	break;
	     
	}
    return ( iNoOfBytesParsed );
}


#if 0
error_t ms_parse_nit ( uint8_t *section )
{
	uint8_t 	section_number,last_section_number;
	/*uint8_t		*nit_section_data;*/
	int16_t 	network_descriptors_length;
	int16_t		no_of_bytes_parsed;
	int16_t 	no_of_data_bytes;
	int16_t		transport_stream_loop_length;    
	int16_t		transport_descriptors_length;
	int16_t     i;
	
	DBG_ASSERT( section != NULL );
	
	last_section_number = section [ 7 ];
	APP_TRACE ("\n last_section_number = %d\n", last_section_number );
	
	for(i=0;i<last_section_number;i++)
	{
		/*
		 * read network_id (16)
		 
		ms_network_data.on_id = section [ 3 ] << 8 | section [ 4 ];*/
		
		/*
		 * read version_number (16)
		 
		network_data -> version_number = section [ 5 ] & 0x3e; 
		 */
	
		section_number = section [ 6 ];
		APP_TRACE ("\n section_number = %d\n", section_number );				
	
		/*
		 * read the network_descriptors_length (12)
		 */
		network_descriptors_length = ( ( section [ 8 ] & 0x0F ) << 8 ) | section [ 9 ];
		
		
		section = section + 10 + network_descriptors_length;
		
		/*
		 * read the transport_stream_loop_length (12)
		 */
		transport_stream_loop_length =( ( section [ 0 ] & 0x0F ) << 8 ) | section [ 1 ];
		section += 2;
		
		/*
		 * parse the actual information
		 */
		while ( transport_stream_loop_length > 0 )
		{
			/*
			 * read transport_stream_id (16)
			 */
			ms_network_data.ts_id = section [ 0 ] << 8 | section [ 1 ];
			/*if(ms_network_data.ts_id==10)
			APP_TRACE ("\nmosaic transport_stream_id = %d\n", ms_network_data.ts_id );*/
					
			/*
			 * read original_network_id (16)
			 */
			ms_network_data.on_id = section [ 2 ] << 8 | section [ 3 ];
			/*APP_TRACE ("\nmosaic original_network_id = %d\n", ms_network_data.on_id );*/
			
			/*
			 * read transport_descriptors_length (12)
			 */
			transport_descriptors_length = ( section [ 4 ]& 0x0F) << 8 | section [ 5 ];
			section += 6;
			
			if ( transport_descriptors_length )
			{
				no_of_bytes_parsed = 0;
				while ( no_of_bytes_parsed < transport_descriptors_length )
				{
					no_of_data_bytes = parse_mosaic_descriptor ( section,
					                                             DVB_DEFINE_DATA,
					                                             transport_descriptors_length );
					if(no_of_data_bytes == -1)
						return SUCCESS;
					
					section += no_of_data_bytes;
					no_of_bytes_parsed += no_of_data_bytes;
				}
			}
		/*
		 * constant '6' includes the transport_stream_id (16), network_id (16)
		 * & transport_descriptors_length (12)
		 */
		transport_stream_loop_length = transport_stream_loop_length - transport_descriptors_length - 6;		
		}
		return ERROR_MOSAIC_NO_SIGNAL;
	}		
}


error_t ms_parse_pat(uint8_t *section)
{
	int16_t section_length;
	int16_t program_number;
	uint8_t last_section_number=1;
	int16_t i;
	
	DBG_ASSERT( section != NULL );
	while(last_section_number>0)
	{
		section_length = (section[ 1 ] & 0x0F)<<8 | section[ 2 ];
		APP_TRACE ("\nmosaic pat section length = %d\n", section_length);
		
		last_section_number = section[ 7 ];
		section = section + 8;
	
		for(i=0;i<((section_length-5)/4 -1);i++)
		{
			program_number = section[ 0+4*i ]<<8 | section[ 1+4*i ];	
			ms_network_data.mosaic_pmt_pid = (section[ 2+4*i ] & 0x1F)<<8 | section[ 3+4*i ];/*program_map_PID*/
			if(program_number == ms_network_data.service_id)
				return SUCCESS;
		}
		last_section_number = last_section_number - 1;
	}
}

error_t ms_parse_pmt(uint8_t *section)
{
	int16_t section_length, program_info_length, ES_info_length;
	uint8_t last_section_number=1;
	
	DBG_ASSERT( section != NULL );
	while(last_section_number)
	{
		section_length = (section[ 1 ] & 0x0F)<<8 | section[ 2 ];
		
		last_section_number = section[ 7 ];
		program_info_length = (section[ 10 ] & 0x0F)<<8 | section[ 11 ];
		section =section + program_info_length + 12;
		
		/*the constant 12 is the bytes num before the program_info_length
		 *the constant 32 is the num of CRC 
		 */
		section_length = section_length - program_info_length - 12 - 32;
		while(section_length>0)
		{
			ms_network_data.mosaic_table_pid = (section[ 1 ] & 0x1F)<<8 | section[ 2 ];/*elementary_PID*/
			if(section[ 0 ] == 0xC1)
				return SUCCESS;
			ES_info_length = (section[ 3 ] & 0x0F)<<8 | section[ 4 ];
			section_length = section_length - ES_info_length - 5;
		}
		
		last_section_number = last_section_number - 1;
	}
	return FALSE;
}
#endif


error_t ms_parse_eitpf ( uint8_t *section )
{
	
	uint8_t     section_number;
	uint8_t	    *eitpf_section_data;
	int16_t     descriptor_loop_length;
	int32_t     ts_info_length;
	int16_t     section_length;
	
    uint32_t    start_year;     
    uint32_t    start_month; 
    uint32_t    start_day;
    uint32_t    start_date;
        
    uint8_t     start_time[3];
    uint8_t     during_time[3];
    uint8_t     time_temp1, time_temp2, time_temp3;
        
	uint32_t    no_of_bytes_parsed;
	uint32_t    no_of_data_bytes;
	
	DBG_ASSERT ( section != NULL);

	/*
	 * read section_length
	 */
	section_length =( ( section [ 1 ] & 0x0f ) << 8 )| section [ 2 ];
	
	
	/*
	 * read section_number
	 */
	section_number = section [ 6 ];
	
	APP_TRACE("\nsection_number=%d\n",section_number);

	/*
	 * read version_number
	 */
	ms_pre_eitpf_version_number = ms_eitpf_event [ section_number ]. version_number;
	ms_eitpf_event [ section_number ]. version_number = ( section [ 5 ] >> 1 ) & 0x1f;	
	if(ms_pre_eitpf_version_number == -1)
	{
		APP_TRACE(" the first time parse the EIT P/F cache ");
		ms_pre_eitpf_version_number = ( section [ 5 ] >> 1 ) & 0x1f;
	}
	
	APP_TRACE("\nversion_number=%d\n",ms_eitpf_event [ section_number ]. version_number);
	
	/*
	 * position the first byte of the EIT structure (ie) the byte just after
	 * last_table_id
	 */
	eitpf_section_data = section + 14;

	/*
	 * setup the info loop length based on the section length
	 * the constant '11' is to account the no of data bytes starting
 	 * just after the section length till last_table_id field.
 	 *
 	 *the constant 4 is the CRC bytes num
	 */
	ts_info_length = section_length - 4 - 11;

	/*
	 * parse the actual information
	 */
	while ( ts_info_length > 0 )
	{
		
		int k = 0;
		
		/*
		 * read event id (16 bit)
		 */
		ms_eitpf_event [ section_number ]. event_id  = ( eitpf_section_data [ 0 ] << 8 ) | eitpf_section_data [ 1 ];	     		
		
		APP_TRACE("\nevent_id=%d\n",ms_eitpf_event [ section_number ]. event_id );
		
		/*
		 * calculate start date 
		 */
		start_date  = ( eitpf_section_data [ 2 ] << 8 ) | eitpf_section_data [ 3 ];	  /* MJD */        	
		start_year  = (UINT)(( start_date - 15078.2 )/365.25 );	     	     	
		start_month = (UINT)(( start_date - 14956.1 - (UINT)( start_year * 365.25 ))/30.6001 ) ;
		start_day   = start_date - 14956 - (UINT)( start_year * 365.25 ) - (UINT)( start_month * 30.6001 );
		if (( start_month == 14 ) || ( start_month == 15 ))
		{
		      k = 1;	
		}
		else
		{
		      k = 0;
		}
		start_year  = start_year + k;
		start_month = start_month -1 -k*12;
		
		start_year = start_year + 1900;
		ms_eitpf_event [ section_number ]. start_year = start_year;
		ms_eitpf_event [ section_number ]. start_month = start_month;
		ms_eitpf_event [ section_number ]. start_day = start_day;
		
		APP_TRACE("\nyear=%d,month=%d,day=%d\n",start_year,start_month,start_day );
			
		/*
		 * calculate start time 
		 */								
		for ( k=0; k<3; k++ )
		{
		    start_time [ k ] = eitpf_section_data [ k+4 ];
		}
		
		for ( k=0; k<3; k++ )
		{
		    during_time [ k ] = eitpf_section_data [ k+7 ];
		}
                
                
        time_temp1 = start_time [ 2 ] & 0x0f;
        time_temp2 = ( start_time [ 2 ] >> 4 ) & 0x0f;
        time_temp3 = time_temp2*10 + time_temp1;
                
        ms_eitpf_event [ section_number ]. start_time [ 2 ] = time_temp3%60;
        time_temp3 = time_temp3/60;
                
                
        time_temp1 = start_time [ 1 ] & 0x0f;
        time_temp2 = ( start_time [ 1 ] >> 4 ) & 0x0f;
        time_temp3 = time_temp2*10 + time_temp1 + time_temp3;
                
        ms_eitpf_event [ section_number ]. start_time [ 1 ] = time_temp3%60;
        time_temp3 = time_temp3/60;
                
                
        time_temp1 = start_time [ 0 ] & 0x0f;
        time_temp2 = ( start_time [ 0 ] >> 4 ) & 0x0f;
        time_temp3 = time_temp2*10 + time_temp1 + time_temp3;
                
        ms_eitpf_event [ section_number ]. start_time [ 0 ] =( time_temp3 + 8 )%24;
                
        APP_TRACE("\nstart_time=%2d:%2d:%2d\n",ms_eitpf_event [ section_number ]. start_time [ 0 ],
            		ms_eitpf_event [ section_number ]. start_time [ 1 ],
               		ms_eitpf_event [ section_number ]. start_time [ 2 ]);
   
   		/*
		 * calculate end date 
		 */
   		time_temp1 = during_time [ 2 ] & 0x0f;
        time_temp2 = ( during_time [ 2 ] >> 4 ) & 0x0f;
        time_temp3 = time_temp2*10 + time_temp1;
                
        ms_eitpf_event [ section_number ]. end_time [ 2 ] =( time_temp3 + ms_eitpf_event [ section_number ]. start_time [ 2 ] )%60;
        time_temp3 =( time_temp3 + ms_eitpf_event [ section_number ]. end_time [ 2 ] )/60;
                
                
        time_temp1 = during_time [ 1 ] & 0x0f;
        time_temp2 = ( during_time [ 1 ] >> 4 ) & 0x0f;
        time_temp3 = time_temp2*10 + time_temp1;
                
        ms_eitpf_event [ section_number ]. end_time [ 1 ] =( time_temp3 + ms_eitpf_event [ section_number ]. start_time [ 1 ] )%60;
        time_temp3 =( time_temp3 + ms_eitpf_event [ section_number ]. start_time [ 1 ] )/60;
                
                
        time_temp1 = during_time [ 0 ] & 0x0f;
        time_temp2 = ( during_time [ 0 ] >> 4 ) & 0x0f;
        time_temp3 = time_temp2*10 + time_temp1 + time_temp3;
                
        ms_eitpf_event [ section_number ]. end_time [ 0 ] =( time_temp3 + ms_eitpf_event [ section_number ]. start_time [ 0 ] )%24;
                
        APP_TRACE("\nend_time=%2d:%2d:%2d\n",ms_eitpf_event [ section_number ]. end_time [ 0 ],
              		ms_eitpf_event [ section_number ]. end_time [ 1 ],
               		ms_eitpf_event [ section_number ]. end_time [ 2 ]);
                
                 
		descriptor_loop_length = ( eitpf_section_data [ 10 ] << 8 ) & 0xF00 | eitpf_section_data [ 11 ];

		if ( descriptor_loop_length )
		{

			uint8_t	*decriptor_data_buffer; 

			decriptor_data_buffer = eitpf_section_data + 12;
			
			no_of_bytes_parsed = 0;
			while ( no_of_bytes_parsed < descriptor_loop_length )
			{
				no_of_data_bytes = parse_mosaic_descriptor (decriptor_data_buffer , DVB_DEFINE_DATA, section_number);
				decriptor_data_buffer += no_of_data_bytes;
				no_of_bytes_parsed += no_of_data_bytes;
			}
		}

		ts_info_length = ts_info_length - descriptor_loop_length - 12;
		eitpf_section_data += ( descriptor_loop_length + 12 );

	}			
}



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -