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

📄 mosaic_data.c

📁 c语言编的
💻 C
📖 第 1 页 / 共 2 页
字号:
/* 
 * File: datamosaic.c
 * Contains:
 *      the file of mosaic application.
 *
 * Author:
 *      stone
 *
 * CVS control words:
 *
 * $Id: mosaic_data.c,v 1.3 2005/12/20 09:03:00 hwxiao Exp $ 
 *
 * Last checked in:
 * $Date: 2005/12/20 09:03:00 $ 
 *
 * History:
 *      $Log: mosaic_data.c,v $
 *      Revision 1.3  2005/12/20 09:03:00  hwxiao
 *      no message
 *
 *      Revision 1.2  2005/07/04 07:03:09  hwxiao
 *      no message
 *
 *      Revision 1.1.1.1  2005/06/28 08:52:23  wjbai
 *      no message
 *
 *      Revision 1.25  2005/03/29 05:13:04  syan
 *      no message
 *
 *      Revision 1.24  2005/03/17 01:46:16  syan
 *      no message
 *
 *      Revision 1.23  2005/02/28 03:37:52  syan
 *      delete the ss_send_pin().
 *
 *      Revision 1.22  2005/01/27 14:19:55  syan
 *      modify enter page and play audio when no PMT.
 *
 *      Revision 1.21  2004/12/29 05:53:26  syan
 *      modify a bug of exit the mosaic app.
 *
 *      Revision 1.20  2004/12/15 08:32:37  syan
 *      modify the new entry info page.
 *
 *      Revision 1.19  2004/11/05 01:19:50  syan
 *      modify lock cell.entry background.
 *
 *      Revision 1.18  2004/11/03 06:02:19  syan
 *      modify some mem_deallocate. add the pic of different language.
 *
 *      Revision 1.17  2004/11/01 05:16:30  syan
 *      add the error notify.modify the lock window.
 *
 *      Revision 1.16  2004/11/01 02:24:56  syan
 *      modify the lock mask of a cell, play audio.
 *
 *      Revision 1.15  2004/10/26 13:22:25  syan
 *      modify about when background pis is NULL, delete audio,vol rect,
 *      get PMT...
 *
 *      Revision 1.14  2004/07/26 11:07:49  syan
 *      add the ss_connect_app.
 *
 *      Revision 1.13  2004/07/21 12:46:51  syan
 *      support the AIT.
 *
 *      Revision 1.12  2004/07/09 11:16:05  syan
 *      modify the cell navigation , geo mask.
 *
 *      Revision 1.11  2004/07/01 08:52:26  syan
 *      CA mask and modify some color.
 *
 *      Revision 1.10  2004/06/18 05:31:47  syan
 *      support multilingual info area display in a page.
 *
 *      Revision 1.9  2004/06/16 11:40:09  syan
 *      modify multilingual text display in mask and page.
 *
 *      Revision 1.8  2004/06/16 05:52:54  syan
 *      modify multilingual text display in page.
 *
 *      Revision 1.7  2004/06/03 01:41:07  syan
 *      modify some data structure and VK in MOSAIC.
 *
 *      Revision 1.6  2004/05/25 01:00:34  syan
 *      modify page display function to display the test page correctly.
 *
 *      Revision 1.5  2004/05/11 08:17:23  syan
 *      add mask and color_index from the stream.
 *
 *      Revision 1.4  2004/04/16 09:17:39  syan
 *      SDT info and supporting multi-net had been modified.
 *
 *      Revision 1.3  2004/03/29 09:47:36  syan
 *      no message
 *
 *      Revision 1.2  2004/02/04 08:54:01  dsqu
 *      no message
 *
 *      Revision 1.1  2004/01/07 12:46:51  dsqu
 *      Initial creation
 *
 *      Revision 1.1.1.1  2003/12/29 09:18:01  stone
 *      no message
 *
 *
 */
#include <stdio.h>
#include <string.h>
#include "stddefs.h"
#include "stcommon.h"
#include "modules.h"
#include "mosaic.h"



mosaic_node_t *mosaic_tree_data_t;
mosaic_data_t *mosaic_node_data = NULL;

page_data_t *page_node_data;
cell_data_t *cell_node_data;

cell_data_t *current_active_cell_info;

component_t ms_audio_component;
service_t   ms_service;

ms_network_data_t ms_network_data;

void get_cell_data_tree( uint8_t *mosaic_parse_data,
                         page_node_ident_t page_node_identify )
{
	uint8_t     current_cell_id;
	int16_t     cell_loop_length,cell_parse_desc_length;
	int16_t     iNoOfBytesParsedSoFar,iNoOfDataBytes;
    
    /*
     *cell data loop
     *
	 * parse all descriptor in the cell layer
	 */
	cell_loop_length = ( mosaic_parse_data [0] & 0x7f )<<8 | mosaic_parse_data [1];
    /*APP_TRACE("\n cell loop length=%d\n",cell_loop_length);*/
    mosaic_parse_data += 2;	 		    
         
    while( cell_loop_length )
    { 
    	/*mosaic_parse_data [0] is the length of cell_identifier(current_cell_id) ,always set to 0x01*/
       	
        current_cell_id = mosaic_parse_data [1];
        /*if(current_cell_id == 3)
        	APP_TRACE("\n current_cell_id = [%d]\n",current_cell_id);*/
        
        cell_node_data = app_mem_allocate ( sizeof( cell_data_t ) );
        
        /*init the mask*/
        cell_node_data->activation_mask = 0;
        cell_node_data->offers_data = NULL;
        cell_node_data->geo_zones_data = NULL;
        cell_node_data->country_data = NULL;
        
        /*
	     * parse the cell layer long descriptor
	 	 */	                                                                   
        cell_parse_desc_length = ( mosaic_parse_data [2] & 0x7f )<<8 | mosaic_parse_data [3];
        /*APP_TRACE("\n cell layer long descriptor length=%d\n",cell_parse_desc_length);*/
        
        mosaic_parse_data += 4;
        iNoOfBytesParsedSoFar = 0;	
		while( iNoOfBytesParsedSoFar < cell_parse_desc_length )
	  	{

	    	iNoOfDataBytes = parse_mosaic_descriptor( mosaic_parse_data,
	      	                                          CELL_LAYER_DATA,
	                                                  cell_parse_desc_length ); 

	   		mosaic_parse_data += iNoOfDataBytes;
	
	   		/*the current pointer of data that had not be parsed*/
	   		iNoOfBytesParsedSoFar += iNoOfDataBytes;

        }/* end of while-loop */
        
        cell_loop_length = cell_loop_length - cell_parse_desc_length - 4;
        /*
	     * parse the cell layer normal descriptor
	 	 */
        cell_parse_desc_length = ( mosaic_parse_data [0] & 0x7f )<<8 | mosaic_parse_data [1];
        /*APP_TRACE("\n cell layer normal descriptor length=%d\n",cell_parse_desc_length);*/
        
        mosaic_parse_data += 2;
        
        iNoOfBytesParsedSoFar = 0;	
		while( iNoOfBytesParsedSoFar < cell_parse_desc_length )
	 	{

	    	iNoOfDataBytes = parse_mosaic_descriptor( mosaic_parse_data,
	       		                                      CELL_LAYER_DATA,
	            	                                  cell_parse_desc_length ); 	
	   	
	   		mosaic_parse_data += iNoOfDataBytes;
	
	   		/*the current pointer of data that had not be parsed*/
	   		iNoOfBytesParsedSoFar += iNoOfDataBytes;

        }/* end of while-loop */
        
        cell_node_data->cell_id = current_cell_id; 
        cell_node_data->page_id = page_node_identify.page_id;
        
        mosaic_add_cell_node ( mosaic_tree_data_t,
                               cell_node_data, 
                               page_node_identify );
                                        
        cell_loop_length = cell_loop_length - cell_parse_desc_length - 2;
        
        /*APP_TRACE("\n cell loop length=%d\n",cell_loop_length);*/
        
	}/*end of while-loop*/
         
}

void get_page_data_tree( uint8_t *mosaic_parse_data )
{
	int16_t     page_loop_length,page_parse_desc_length;
	int16_t     cell_loop_length;
	int16_t     iNoOfBytesParsedSoFar,iNoOfDataBytes;
	uint8_t     i, j;
	page_node_ident_t page_node_identify;
	
	error_t     error;
	/*
     *get the data of every page
     */  
    page_loop_length = ( mosaic_parse_data [0] & 0x7f )<<8 | mosaic_parse_data [1];
    /*APP_TRACE("\n page loop length=%d\n",page_loop_length);*/
         
    mosaic_parse_data += 2; 
    for( i=0;i<mosaic_node_data->total_page_number;i++ )
    { 
    	/*mosaic_parse_data [0] is the length of page_identifier(page_node_identify.page_id) ,always set to 0x01*/	
        page_node_identify.page_id = mosaic_parse_data [1];
        APP_TRACE("\n ***current page id =%d***\n",page_node_identify.page_id);
                                      	 
        page_node_data = app_mem_allocate ( sizeof( page_data_t ) ); 
        
        /*init the info_dis_area_num in this page, page_texts_list*/
    	page_node_data->info_dis_area_num = 0;
    	page_node_data->page_texts_list = NULL;    	
    	for(j=0;j<7;j++)
    	{
    		page_node_data->info_position[j].data_list = NULL;
    	}
        /*
	 	 * parse the page layer long descriptor
	 	 */
        page_parse_desc_length = ( mosaic_parse_data [2] & 0x7f )<<8 | mosaic_parse_data [3];
        /*APP_TRACE("\n page layer long descriptor length=%d\n",page_parse_desc_length);*/
        
        mosaic_parse_data = mosaic_parse_data+4;
        iNoOfBytesParsedSoFar = 0;	
		while( iNoOfBytesParsedSoFar < page_parse_desc_length )
	  	{

	    	iNoOfDataBytes = parse_mosaic_descriptor( mosaic_parse_data,
	        	                                     PAGE_LAYER_DATA,
	            	                                 page_parse_desc_length ); 

	   		mosaic_parse_data += iNoOfDataBytes;
	
	   		/*the current pointer of data that had not be parsed*/
	   		iNoOfBytesParsedSoFar += iNoOfDataBytes;

        }/* end of while-loop */
		/*
	 	 * parse the page layer normal descriptor
	 	 */
		page_parse_desc_length = ( mosaic_parse_data [0] & 0x7f )<<8 | mosaic_parse_data [1];
    	/*APP_TRACE("\n page layer normal descriptor length=%d\n",page_parse_desc_length);*/
        
    	mosaic_parse_data = mosaic_parse_data+2;
        
    	iNoOfBytesParsedSoFar = 0;	
		while( iNoOfBytesParsedSoFar < page_parse_desc_length )
		{

			iNoOfDataBytes = parse_mosaic_descriptor( mosaic_parse_data,
		                                              PAGE_LAYER_DATA,
	    	                                          page_parse_desc_length ); 	
	   	
			mosaic_parse_data += iNoOfDataBytes;
	
		   	/*the current pointer of data that had not be parsed*/
	   		iNoOfBytesParsedSoFar += iNoOfDataBytes;
	
    	}/* end of while-loop */
        
     	page_node_data->page_id = page_node_identify.page_id; 
        
     	error =  mosaic_add_page_node ( mosaic_tree_data_t,
                                        page_node_data );
        
        /*
     	*cell data loop
     	*
	 	* parse all descriptor in the cell layer
	 	*/
		cell_loop_length = ( mosaic_parse_data [0] & 0x7f )<<8 | mosaic_parse_data [1];            	                         
        /*APP_TRACE(" cell_loop descriptor length=%d\n",cell_loop_length);*/
             
     	get_cell_data_tree( mosaic_parse_data,
                            page_node_identify );
                            
        mosaic_parse_data = mosaic_parse_data + cell_loop_length + 2;
        
	}/* end of for-loop */	 
}


void main_parse_mosaic ( uint8_t *mosaic_parse_data, int32_t size)
{

	int16_t     mosaic_parse_desc_length;
	int16_t     iNoOfBytesParsedSoFar,iNoOfDataBytes;
	
	/*
	 * position the first byte of the mosaic layer long descriptor structure 
	 * the byte just after Data_Parsing_Format
	 *
	mosaic_parse_data = section + 11;
	
	 */
	mosaic_tree_data_t = mosaic_init_data_tree();
	
	
	/*
	 * parse the mosaic layer long descriptor
	 *	 
	 * read the length of all mosaic layer long descriptor
	 */
	mosaic_parse_desc_length = ( mosaic_parse_data [0] & 0x7f )<<8 | mosaic_parse_data [1];	                    
    APP_TRACE("\n mosaic layer long descriptor=%d\n",mosaic_parse_desc_length);
        
    mosaic_parse_data = mosaic_parse_data + 2;   
        
    mosaic_node_data = app_mem_allocate ( sizeof( mosaic_data_t ) );
    mosaic_tree_data_t->mosaic_data = mosaic_node_data;    
        
    iNoOfBytesParsedSoFar = 0;	
	while( iNoOfBytesParsedSoFar < mosaic_parse_desc_length )
	{
		iNoOfDataBytes = parse_mosaic_descriptor( mosaic_parse_data, 
	                                              MOSAIC_LAYER_DATA,
	                                              mosaic_parse_desc_length ); 
		mosaic_parse_data += iNoOfDataBytes;
	
		/*the current pointer of data that had not be parsed*/
		iNoOfBytesParsedSoFar += iNoOfDataBytes;

	}/* end of while-loop */
	
	/*
	 * parse the mosaic layer normal descriptor
	 */
	mosaic_parse_desc_length = ( mosaic_parse_data [0] & 0x7f )<<8 | mosaic_parse_data [1];	                    
    APP_TRACE("\n mosaic layer normal descriptor=%d\n",mosaic_parse_desc_length);
         
    mosaic_parse_data = mosaic_parse_data + 2;        
        
    iNoOfBytesParsedSoFar = 0;	
	while( iNoOfBytesParsedSoFar < mosaic_parse_desc_length )
	{

		iNoOfDataBytes = parse_mosaic_descriptor( mosaic_parse_data,
		                                          MOSAIC_LAYER_DATA, 
	    	                                      mosaic_parse_desc_length ); 	
	

		mosaic_parse_data += iNoOfDataBytes;
	
		/*the current pointer of data that had not be parsed*/
		iNoOfBytesParsedSoFar += iNoOfDataBytes;

    }/* end of while-loop */

     APP_TRACE("\n total_page_number=%d\n",mosaic_node_data->total_page_number);

     get_page_data_tree( mosaic_parse_data ); 
                                                  	
}

/*next -------------------------*/

uint8_t *receive_mosaic_table(service_t *service, 
								uint16_t pid, 
								uint8_t table_id,
								int32_t *size)
{
	si_filter_t filter;
	uint8_t *table;
	
	si_cache_control(MOSAIC_CACHE, SI_CACHE_STOP);
	
	memset(filter.filter_data, 0, SI_CACHE_MAX_FILTER_SIZE);
	memset(filter.filter_mask, 0, SI_CACHE_MAX_FILTER_SIZE);
	filter.filter_data[0] = table_id;
	filter.filter_mask[0] = 0xf0;
	si_cache_configure(MOSAIC_CACHE, pid, &filter, 1);
	si_cache_change_service(MOSAIC_CACHE, service);
	si_cache_control(MOSAIC_CACHE, SI_CACHE_START);
	
	if(si_cache_request_table(MOSAIC_CACHE, table_id, 0xff, service, false, 
							  &table, size, 10000) != SUCCESS)
	{
		APP_TRACE("mosaic table timeout\n");
		return NULL;
	}
	else
	{
		APP_TRACE("mosaic table OK, size %d\n", *size);
		return table;
	}
}

semaphore_t *connect_ok = NULL;
uint8_t mosaic_pmt[1024];
void mosaic_ss_callback(uint32_t event, void *context)
{
	ss_ev_service_connect_t *svn = context;
	if(event == SS_EV_SERVICE_CONNECTED)
	{
		memcpy(mosaic_pmt, svn->pmt_table, svn->pmt_size);
		semaphore_signal(connect_ok);/**/
	}
}

uint16_t mosaic_get_component_pid(uint8_t *pmt, uint8_t component_tag)
{
	/* A question: how to select video/audio track? */
	uint8_t *p, *q;
	int32_t slength, pl, el, parsed_size, desc_size;
	/*int32_t track = 0;*/
	uint16_t component_pid;

	component_pid = SS_DEMUX_INVALID_PID;

	p = pmt;
	DBG_ASSERT(p[0] == 0x02);

	slength = ((p[1] << 8) | p[2]) & 0xfff;
	slength += 3;

	/* read program_info_length */
	pl = ((p[10] << 8) | p[11]) & 0xfff;

	slength -= (pl + 12 + 4);
	p += (12 + pl);

	while(slength > 0)
	{
		component_pid = ((p[1] << 8) | p[2]) & 0x1fff;
		q = p + 5;
		el = ((p[3] << 8) | p[4]) & 0xfff;
		p += (el + 5);

⌨️ 快捷键说明

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