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

📄 db_parse.txt

📁 数字电视数据广播规范系统中关于DSM-CC的解析的关键代码
💻 TXT
📖 第 1 页 / 共 2 页
字号:
		return NULL;
	}

	//---objectInfo_length(2 byte) 
	//*---需要计算
	pch_temp = pch_temp + 8 + i_obj_length;
	unsigned __int32 i_objInfo_length = 0;
	memcpy( (char*)&i_objInfo_length , pch_temp + 1, 1 );
	memcpy( (char*)&i_objInfo_length + 1, pch_temp, 1 );

	//---Content_length(4 byte)
	pch_temp = pch_temp + 15;
	unsigned __int32 i_Content_length = 0; //Content_length
	memcpy( (char*)&i_Content_length, pch_temp + 3, 1 );
	memcpy( (char*)&i_Content_length + 1, pch_temp + 2, 1 );
	memcpy( (char*)&i_Content_length + 2, pch_temp + 1, 1 );
	memcpy( (char*)&i_Content_length + 3, pch_temp, 1 );
	//---以上用了63 + i_objInfo_length + i_obj_length个字节	

	//---保存数据的buffer
	char *ch_data = (char*)malloc(i_Content_length);
	char *ch_data_temp = ch_data;

	pch_temp = pch_temp + 4;
	//---计算当前段有多少块和最后块有多少数据
	unsigned __int32 i_pack_sum = 0;  //一共有多少包
	__int32 i_fill = 0;  //最后一个包的数据
	
	if ( i_dsmcc_section_length > 180 )
	{
		i_fill = (i_dsmcc_section_length + 3 - 183) % 184 - 4;  //减去4字节CRC
		
		if ( 0 < i_fill )
		{
			i_pack_sum = (i_dsmcc_section_length + 3 - 183) / 184 + 2;
		}
		else
		{
			i_pack_sum = (i_dsmcc_section_length + 3 - 183) / 184 + 1;
			i_fill = 184 - (4 + i_fill);   //i_fill 是负数
		}
	}
	else
	{//---一个段只有一个包
		i_pack_sum = 1;
		i_fill = i_dsmcc_section_length - 23 - 4;
	}

	//---获取数据
	if ( i_pack_sum < 3 )
	{
		if (1 == i_pack_sum)
		{//---只有一个数据包
			memcpy( ch_data_temp, pch_temp, i_fill );  
		}
		else
		{//---有两个数据包
			memcpy( ch_data_temp, pch_temp, 188 - (63 + i_objInfo_length + i_obj_length) );  //第一个包

			ch_data_temp = ch_data_temp + 188 - (63 + i_objInfo_length + i_obj_length);
			pch_temp = pch_temp + 188 - (63 + i_objInfo_length + i_obj_length);

			memcpy( ch_data_temp, pch_temp, i_fill );   //第二个
		}
	}
	else
	{//---超过3个包的情况
		memcpy( ch_data_temp, pch_temp, 188 - (63 + i_objInfo_length + i_obj_length) );  //第一个包

		ch_data_temp = ch_data_temp + 188 - (63 + i_objInfo_length + i_obj_length);
		pch_temp = pch_temp + 188 - (63 + i_objInfo_length + i_obj_length);
		for (unsigned __int32 i = 0; i < i_pack_sum - 2; ++i)
		{
			memcpy(ch_data_temp, pch_temp, 184);
			ch_data_temp = ch_data_temp + 184;
			pch_temp = pch_temp + 184;
		}
		
		memcpy( ch_data_temp, pch_temp, i_fill );  //最后一个包
		pch_temp = pch_temp + i_fill;
		ch_data_temp = ch_data_temp + i_fill;
	}

	if (i_section_sum > 1)
	{//---如果分段
		for (unsigned __int32 i = 0; i < i_section_sum - 1; ++i)
		{
			pch_temp = pch_temp + 4; //CRC
			pch_temp = pch_temp + 1;
			unsigned __int32 i_dsmcc_section_length = 0;
			memcpy( (char*)&i_dsmcc_section_length, pch_temp + 1, 1 );
			memcpy( (char*)&i_dsmcc_section_length + 1, pch_temp, 1 );
			//---dsmcc_section_length
			i_dsmcc_section_length = i_dsmcc_section_length & 0xfff;  //后12位为长度

			//---将指针移动到数据的地方
			pch_temp = pch_temp + 25;

			//---计算当前段有多少块和最后块有多少数据
			unsigned __int32 i_pack_sum = 0;  //一共有多少包
			unsigned __int32 i_fill = 0;  //最后一个包的数据
			
			if ( i_dsmcc_section_length > 180 )
			{
				i_fill = (i_dsmcc_section_length + 3 - 183) % 184 - 4;  //减去4字节CRC
				
				if ( 0 != i_fill )
				{
					i_pack_sum = (i_dsmcc_section_length + 3 - 183) / 184 + 2;
				}
				else
				{
					i_pack_sum = (i_dsmcc_section_length + 3 - 183) / 184 + 1;
					i_fill = 184 - (4 + i_fill);   //i_fill 是负数
				}
			}
			else
			{//---一个段只有一个包
				i_pack_sum = 1;
				i_fill = i_dsmcc_section_length - 23 - 4;
			}
			
			//---获取数据
			if ( i_pack_sum < 3 )
			{
				if (1 == i_pack_sum)
				{//---只有一个数据包
					memcpy( ch_data_temp, pch_temp, i_fill );  
				}
				else
				{//---有两个数据包
					memcpy( ch_data_temp, pch_temp, 188 - (63 + i_objInfo_length + i_obj_length) );  //第一个包
					
					ch_data_temp = ch_data_temp + 188 - (63 + i_objInfo_length + i_obj_length);
					pch_temp = pch_temp + 188 - (63 + i_objInfo_length + i_obj_length) + 4;
					
					memcpy( ch_data_temp, pch_temp, i_fill );   //第二个
				}
			}
			else
			{//---超过3个包的情况
				memcpy( ch_data_temp, pch_temp, 188 - 31 );  //第一个包
				
				ch_data_temp = ch_data_temp + 188 - 31;
				pch_temp = pch_temp + 188 - 31;
				for (unsigned __int32 i = 0; i < i_pack_sum - 2; ++i)
				{
					memcpy(ch_data_temp, pch_temp, 184);
					ch_data_temp = ch_data_temp + 184;
					pch_temp = pch_temp + 184;
				}
				
				memcpy( ch_data_temp, pch_temp, i_fill );  //最后一个包
				ch_data_temp = ch_data_temp + i_fill;
				pch_temp = pch_temp + i_fill;
			}

		}  //end of for
	}  //end of if


    FILE *pw = fopen("1.bmp", "wb+");
	unsigned __int32 i__ = sizeof(ch_data);
 	fwrite(ch_data, i_Content_length, 1, pw);
 	fclose(pw);

	return ch_data;
}

char *ParseTS(char *p, char *pch_table_id, char *message_id)
{//---解析TS流数据 参数:p(in) 数据流 pch_table_id(in) 返回:查找到的数据流
	//*---要进行分包合并处理
	char *pch_temp = p;

	char *ch_temp = (char*)malloc(5);
	ch_temp[0] = 0x00;
	sscanf(pch_table_id, "%02x", ch_temp + 1);
	while (1)
	{//*---循环条件要进行判断
		if ( !memcmp(ch_temp, pch_temp + 4, 1) && !memcmp(ch_temp + 1, pch_temp + 5, 1)  )
		{//---判断是否包头和table_id

			char *pch_temp_msgId = pch_temp + 13 + 2;  //有TS头

			char *ch_temp_message_id = (char*)malloc(5);
			sscanf(message_id, "%02x", ch_temp_message_id);
			sscanf(message_id + 2, "%02x", ch_temp_message_id + 1);

			unsigned __int32 i = memcmp(ch_temp_message_id, pch_temp_msgId, 2);
			free(ch_temp_message_id);

			if ( 0 == i )
			{//---如果messageId匹配
				free(ch_temp);
				return pch_temp;
			}
		}
		pch_temp = pch_temp + 188;
	}

}

char *OpenFile(char *ch_file)
{
	FILE *pfile = fopen(/*"./mem_block3b_00.dat"*/ch_file, "rb");

	fseek(pfile, 0, SEEK_END);
	unsigned __int32 i_len = ftell(pfile);
	fseek(pfile, 0, SEEK_SET);
	
	char *p = (char*)malloc(i_len);
	memset( (char*)p, 0, i_len );
	fread( (char*)p, 1, i_len, pfile );
	
	fclose(pfile);

	return p;
}

int initDB();

void main()
{
// #ifdef TS
// //	FILE *pfile = fopen("./test.txt", "rb");
// 	FILE *pfile = fopen("./mem_block3b_00.dat", "rb");
// #else
// 	FILE *pfile = fopen("./DSI.txt", "rb");
// #endif
// 
// 	fseek(pfile, 0, SEEK_END);
// 	unsigned __int32 i_len = ftell(pfile);
// 	fseek(pfile, 0, SEEK_SET);
// 
// 	char *p = (char*)malloc(i_len);
// 	memset( (char*)p, 0, i_len );
// 	fread( (char*)p, 1, i_len, pfile );
// 
// 
// 	fclose(pfile);

//	initDB();

	char *p = NULL;

	p = OpenFile("./mem_block3b_00.dat");
 
	//---解析DSI包
	s_sdi *sdi = (s_sdi*)malloc( sizeof(s_sdi) );
	ParseDSI(p, sdi);

	delete p;
	p = OpenFile("./mem_block3c_00.dat");
	//---解析DDB(dir)包
	s_ddbdir *ddbdir = (s_ddbdir*)malloc( sizeof(s_ddbdir) );
	ParseDDBDir(p, sdi, ddbdir);

	ddbdir = ddbdir->linkNext;
//   	ddbdir = ddbdir->linkNext;
//   	ddbdir = ddbdir->linkNext;
//   	ddbdir = ddbdir->linkNext;
//  	ddbdir = ddbdir->linkNext;
	
	
// 	delete p;
// 	p = OpenFile("./mem_block3c_01.dat");
// 	//---解析DDB包
// 	ParseDDBFil(p, ddbdir, 2000);

	delete p;
	p = OpenFile("./mem_block3c_02.dat");
	//---解析DDB包
	ParseDDBFil(p, ddbdir);
	

	char ch_MsgId[3] = {0};
	ParseMsgID(p, ch_MsgId);

	return;
}

////////////////////////////////////////////////////////////////////
void *saft_malloc(int size)
{
	return malloc(size);
}

void saft_free(void *p)
{
	delete p;
}

char *GetDSMCCData(char *ch_table_id, char *table_id_extension)
{
	return NULL;
}

int initDB()
{//---数据广播启动

	//---dsi
	char *ch_sdi = GetDSMCCData("0x3b", "00");
	s_sdi *sdi = (s_sdi*)saft_malloc( sizeof(s_sdi) );

	ParseDSI(ch_sdi, sdi);
	saft_free(ch_sdi);

	//---dirmessage
	char *ch_ddbdir = GetDSMCCData("0x3c", "00");
	s_ddbdir *ddbdir = (s_ddbdir*)saft_malloc( sizeof(s_ddbdir) );
	ddbdir->ch_carouselId = NULL;
	ddbdir->ch_id_data_byte = NULL;
	ddbdir->ch_moduleId = NULL;
	ddbdir->ch_objectKey_data_byte = NULL;
	ddbdir->linkNext = NULL;
	
	while ( NULL == ddbdir->ch_carouselId )
	{
		ch_ddbdir = GetDSMCCData("0x3c", "00");
		ParseDDBDir(ch_ddbdir, sdi, ddbdir);
	}
	
	saft_free(sdi);

	//---filmessage *.xml
	char *ch_ddbfil = GetDSMCCData("0x3c", "01");
	char *ch_xml_fil = ParseDDBFil(ch_ddbfil, ddbdir);

	while ( NULL ==  ch_xml_fil )
	{
		ch_ddbfil = GetDSMCCData("0x3c", "01");
		ch_xml_fil = ParseDDBFil(ch_ddbfil, ddbdir);
	}

	//---解析XML文件

	return 1;
}

⌨️ 快捷键说明

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