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

📄 tsdlg.cpp

📁 DVB的TS流解析
💻 CPP
📖 第 1 页 / 共 3 页
字号:
void descriptorDVB_MultilingComponent (byte* p_descriptor)
{	TRACE("descriptorDVB_MultilingComponent\n");
}
void descriptorDVB_PrivateDataSpecifier (byte* p_descriptor)
{	TRACE("PrivateDataSpecifier\n");
}
void descriptorDVB_ServiceMove (byte* p_descriptor)
{	TRACE("descriptorDVB_ServiceMove\n");
}
void descriptorDVB_ShortSmoothingBuffer (byte* p_descriptor)
{	TRACE("ShortSmoothingBuffer\n");
}
void descriptorDVB_FrequencyList (byte* p_descriptor)
{	TRACE("FrequencyList\n");
}
void descriptorDVB_PartialTransportStream(byte* p_descriptor)
{	TRACE("descriptorDVB_PartialTransportStrea\n");
}
void descriptorDVB_DataBroadcast(byte* p_descriptor)
{	TRACE("descriptorDVB_DataBroadcas\n");
}
void descriptorDVB_Scrambling(byte* p_descriptor)
{	TRACE("descriptorDVB_Scramblin\n");
}
void descriptorDVB_DataBroadcastID(byte* p_descriptor)
{	TRACE("descriptorDVB_DataBroadcastI\n");
}
void descriptorDVB_TransportStream(byte* p_descriptor)
{	TRACE("descriptorDVB_TransportStrea\n");
}
void descriptorDVB_DSNG(byte* p_descriptor)
{	TRACE("descriptorDVB_DSN\n");
}
void descriptorDVB_PDC(byte* p_descriptor)
{	TRACE("descriptorDVB_PD\n");
}
void descriptorDVB_AC3(byte* p_descriptor)
{	TRACE("descriptorDVB_AC\n");
}
void descriptorDVB_AncillaryData(byte* p_descriptor)
{	TRACE("descriptorDVB_AncillaryDat\n");
}
void descriptorDVB_CellList(byte* p_descriptor)
{	TRACE("CellLis\n");
}
void descriptorDVB_CellFrequencyLink(byte* p_descriptor)
{	TRACE("descriptorDVB_CellFrequencyLin\n");
}
void descriptorDVB_AnnouncementSupport(byte* p_descriptor)
{	TRACE("descriptorDVB_AnnouncementSuppor\n");
}
void descriptorDVB_ApplicationSignalling(byte* p_descriptor)
{	TRACE("descriptorDVB_ApplicationSignallin\n");
}
void descriptorDVB_AdaptationFieldData(byte* p_descriptor)
{	TRACE("descriptorDVB_AdaptationFieldDat\n");
}
void descriptorDVB_ServiceIdentifier(byte* p_descriptor)
{	TRACE("descriptorDVB_ServiceIdentifie\n");
}
void descriptorDVB_ServiceAvailability(byte* p_descriptor)
{	TRACE("descriptorDVB_ServiceAvailabilit\n");
}
		 // TV ANYTIME  TS 102 323
void descriptorDVB_DefaultAuthority(byte* p_descriptor)
{	TRACE("DefaultAuthorit\n");
}
void descriptorDVB_RelatedContent(byte* p_descriptor)
{	TRACE("descriptorDVB_RelatedConten\n");
}
void descriptorDVB_TVA_ID(byte* p_descriptor)
{	TRACE("descriptorDVB_TVA_I\n");
}
void descriptorDVB_ContentIdentifier(byte* p_descriptor)
{	TRACE("descriptorDVB_ContentIdentifie\n");
}
		 // EN 301 192 v1.4.1  MPE_FEC
void descriptorDVB_TimesliceFecIdentifier(byte* p_descriptor)
{	TRACE("descriptorDVB_TimesliceFecIdentifie\n");
}
void descriptorDVB_ECM_RepetitionRate(byte* p_descriptor)
{	TRACE("descriptorDVB_ECM_RepetitionRat\n");
}
		 // EN 300 468 v1.7.1
void descriptorDVB_S2SatelliteDeliverySystem(byte* p_descriptor)
{	TRACE("descriptorDVB_S2SatelliteDeliverySyste\n");
}
void descriptorDVB_Enhanced_AC3(byte* p_descriptor)
{	TRACE("descriptorDVB_Enhanced_AC\n");
}
void descriptorDVB_DTS_Audio(byte* p_descriptor)
{	TRACE("descriptorDVB_DTS_Audi\n");
}
void descriptorDVB_AAC(byte* p_descriptor)
{	TRACE("descriptorDVB_AA\n");
}
void descriptor_any(byte* p_descriptor)// $$$ TODO:
{	TRACE("descriptor_an\n");
}
void descriptorDVB_Extension(byte* p_descriptor)
{	TRACE("descriptorDVB_Extensio\n");
}

unsigned short descriptor(byte *p_descriptor)
{
  byte tag = *p_descriptor;
  byte len = *(p_descriptor + 1);

  // empty ??
  if (len == 0) return 2;

  switch (tag) {
     case 0x40:  descriptorDVB_NetName (p_descriptor);					break;
     case 0x41:  descriptorDVB_ServList (p_descriptor);					break;
     case 0x42:  descriptorDVB_Stuffing (p_descriptor);					break;
     case 0x43:  descriptorDVB_SatDelivSys (p_descriptor);				break;
     case 0x44:  descriptorDVB_CableDelivSys (p_descriptor);			break;
     case 0x45:  descriptorDVB_VBI_Data (p_descriptor);					break;
     case 0x46:  descriptorDVB_VBI_Teletext (p_descriptor);				break;
     case 0x47:  descriptorDVB_BouquetName (p_descriptor);				break;
     case 0x48:  descriptorDVB_Service (p_descriptor);					break;
     case 0x49:  descriptorDVB_CountryAvail (p_descriptor);				break;
     case 0x4A:  descriptorDVB_Linkage (p_descriptor);					break;
     case 0x4B:  descriptorDVB_NVOD_Reference (p_descriptor);			break;
     case 0x4C:  descriptorDVB_TimeShiftedService (p_descriptor);		break;
     case 0x4D:  descriptorDVB_ShortEvent (p_descriptor);				break;
     case 0x4E:  descriptorDVB_ExtendedEvent (p_descriptor);			break;
     case 0x4F:  descriptorDVB_TimeShiftedEvent(p_descriptor);			break;
     case 0x50:  descriptorDVB_Component(p_descriptor);					break;
     case 0x51:  descriptorDVB_Mosaic(p_descriptor);					break;
     case 0x52:  descriptorDVB_StreamIdent (p_descriptor);				break;
     case 0x53:  descriptorDVB_CAIdentifier (p_descriptor);				break;
     case 0x54:  descriptorDVB_Content (p_descriptor);					break;
     case 0x55:  descriptorDVB_ParentalRating(p_descriptor);			break;
     case 0x56:  descriptorDVB_Teletext (p_descriptor);					break;
     case 0x57:  descriptorDVB_Telephone (p_descriptor);				break;
     case 0x58:  descriptorDVB_LocalTimeOffset (p_descriptor);			break;
     case 0x59:  descriptorDVB_Subtitling (p_descriptor);				break;
     case 0x5A:  descriptorDVB_TerrestDelivSys (p_descriptor);			break;
     case 0x5B:  descriptorDVB_MultilingNetworkName (p_descriptor);		break;
     case 0x5C:  descriptorDVB_MultilingBouquetName (p_descriptor);		break;
     case 0x5D:  descriptorDVB_MultilingServiceName (p_descriptor);		break;
     case 0x5E:  descriptorDVB_MultilingComponent (p_descriptor);		break;
     case 0x5F:  descriptorDVB_PrivateDataSpecifier (p_descriptor);		break;
     case 0x60:  descriptorDVB_ServiceMove (p_descriptor);				break;
     case 0x61:  descriptorDVB_ShortSmoothingBuffer (p_descriptor);		break;
     case 0x62:  descriptorDVB_FrequencyList (p_descriptor);			break;
     case 0x63:  descriptorDVB_PartialTransportStream(p_descriptor);	break;
     case 0x64:  descriptorDVB_DataBroadcast(p_descriptor);				break;
     case 0x65:  descriptorDVB_Scrambling(p_descriptor);				break;
     case 0x66:  descriptorDVB_DataBroadcastID(p_descriptor);			break;
     case 0x67:  descriptorDVB_TransportStream(p_descriptor);			break;
     case 0x68:  descriptorDVB_DSNG(p_descriptor);						break;
     case 0x69:  descriptorDVB_PDC(p_descriptor);						break;
     case 0x6A:  descriptorDVB_AC3(p_descriptor);						break;
     case 0x6B:  descriptorDVB_AncillaryData(p_descriptor);				break;
     case 0x6C:  descriptorDVB_CellList(p_descriptor);					break;
     case 0x6D:  descriptorDVB_CellFrequencyLink(p_descriptor);			break;
     case 0x6E:  descriptorDVB_AnnouncementSupport(p_descriptor);		break;
     case 0x6F:  descriptorDVB_ApplicationSignalling(p_descriptor);		break;
     case 0x70:  descriptorDVB_AdaptationFieldData(p_descriptor);		break;
     case 0x71:  descriptorDVB_ServiceIdentifier(p_descriptor);			break;
     case 0x72:  descriptorDVB_ServiceAvailability(p_descriptor);		break;
		 // TV ANYTIME  TS 102 323
     case 0x73:  descriptorDVB_DefaultAuthority(p_descriptor);			break;
     case 0x74:  descriptorDVB_RelatedContent(p_descriptor);			break;
     case 0x75:  descriptorDVB_TVA_ID(p_descriptor);					break;
     case 0x76:  descriptorDVB_ContentIdentifier(p_descriptor);			break;
		 // EN 301 192 v1.4.1  MPE_FEC
     case 0x77:  descriptorDVB_TimesliceFecIdentifier(p_descriptor);	break;
     case 0x78:  descriptorDVB_ECM_RepetitionRate(p_descriptor);		break;
		 // EN 300 468 v1.7.1
     case 0x79:  descriptorDVB_S2SatelliteDeliverySystem(p_descriptor);	break;
     case 0x7A:  descriptorDVB_Enhanced_AC3(p_descriptor);				break;
     case 0x7B:  descriptorDVB_DTS_Audio(p_descriptor);					break;
     case 0x7C:  descriptorDVB_AAC(p_descriptor);						break;
     case 0x7D:  descriptor_any(p_descriptor);							break;	// $$$ TODO: currently reserved
     case 0x7E:  descriptor_any(p_descriptor);							break;	// $$$ TODO: currently reserved
     case 0x7F:  descriptorDVB_Extension(p_descriptor);					break;

     default: 
	if (tag < 0x80) {
	    //  ----> ERROR: unimplemented descriptor (dvb context), Report!
	}
	//descriptor_PRIVATE (p_descriptor, DVB_SI);
	break;
  } 

  return len+2;   // (descriptor total length)
}


/*
 *	ISO/IEC 13818-1: 1994(E) 2.4.4.3 Program association table
 */

void program_association_section(byte *buff, int leng)
{
	struct _ //defined in reverse order
	{
		unsigned __int64 last_section_number		:8;
		unsigned __int64 section_number				:8;
		unsigned __int64 current_next_indicator		:1;
		unsigned __int64 version_number				:5;
		unsigned __int64 reserved					:2;
		unsigned __int64 transport_stream_id		:16;
		unsigned __int64 section_length				:12;
		unsigned __int64 reserved_2					:2;
		unsigned __int64 zero_bit					:1;
		unsigned __int64 section_syntax_indicator	:1;
		unsigned __int64 table_id					:8;
	}INIT_STRUCT(PAT_data, buff);

	struct __ 
	{
		unsigned long PID							:13;
		unsigned long reserved						:3;
		unsigned long program_number				:16;
	}Unit;

	CString str;
	int N = (int(PAT_data.section_length) - 5 - cnCRC32Size) >> 2;
	for (int i = 0; i < N; i ++) 
	{
		EVALUATE(Unit, buff);
		if (Unit.program_number) 
		{
			if (DB_service_count < MAX_SERV_COUNT) 
			{
				DB_service_list[DB_service_count].program_number = Unit.program_number;
				DB_service_list[DB_service_count].PID = Unit.PID;

				DB_service_count ++;
			}
			else
			{
				break;
			}
		//	str.Format("program_number: %04X; program_map_PID: %04X", Unit.program_number, Unit.PID);
		}
		else
		{
		//	str.Format("network_PID: %04X", Unit.PID);
		}
	//	log(str);
	}
}

/*
 *	ISO/IEC 13818-1: 1994(E) 2.4.4.8 Program Map Table
 */
void program_map_section(byte* buff, int leng)
{
	static int section_mask = 0;
	struct _ 
	{
		unsigned __int64 last_section_number		:8;
		unsigned __int64 section_number				:8;
		unsigned __int64 current_next_indicator		:1;
		unsigned __int64 version_number				:5;
		unsigned __int64 reserved_2					:2;
		unsigned __int64 program_number				:16;
		unsigned __int64 section_length				:12;
		unsigned __int64 reserved_1					:2;
		unsigned __int64 zero_bit					:1;
		unsigned __int64 section_syntax_indicator	:1;
		unsigned __int64 table_id					:8;
	}INIT_STRUCT(PMT_data1, buff);

	struct __ 
	{
		unsigned __int32 program_info_length		:12;
		unsigned __int32 reserved_2					:4;
		unsigned __int32 PCR_PID					:13;
		unsigned __int32 reserved_1					:3;
	}INIT_STRUCT(PMT_data2, buff);

	struct ___ 
	{
		unsigned __int32 ES_info_length	:12;
		unsigned __int32 reserved2		:4;
		unsigned __int32 elementary_PID	:13;
		unsigned __int32 reserved		:3;
	}PMT_data3;

	for (int i = 0; i < DB_service_count; i++) 
	{
		if (DB_service_list[i].program_number == PMT_data1.program_number) 
		{
			unsigned short info_leng, desc_leng;

			DB_service_list[i].PCR_PID = PMT_data2.PCR_PID;
			info_leng = PMT_data2.program_info_length;
			while (info_leng) 
			{
				desc_leng = descriptor(buff);
				buff += desc_leng;
				info_leng -= desc_leng;
			}
			
			unsigned short strm_info_leng = PMT_data1.section_length - 9 - PMT_data2.program_info_length - cnCRC32Size;
			while (strm_info_leng) 
			{
				byte stream_type = *buff;
				buff ++;
				EVALUATE(PMT_data3, buff);
				strm_info_leng -= 5;
				
				info_leng = PMT_data3.ES_info_length;
				while (info_leng) 
				{
					desc_leng = descriptor(buff);
					buff += desc_leng;
					info_leng -= desc_leng;
					strm_info_leng -= desc_leng;
				}
			}

			break;
		}
	}
}

/*
 *	ETSI EN 300 468 V1.7.1 (2006-22 05) 5.2.3 Service Description Table (SDT)
 */
void service_description_section(byte* buff, int leng)
{
	static int section_mask = 0;
	byte table_id;
	
	table_id = *buff;
	buff += 1;

	struct _ 
	{
		unsigned __int32 transport_stream_id		:16;
		unsigned __int32 section_length				:12;
		unsigned __int32 reserved					:2;
		unsigned __int32 reserved_future_use		:1;
		unsigned __int32 section_syntax_indicator	:1;
	}INIT_STRUCT(SDT_data1, buff);

	struct __ 
	{
		unsigned __int16 section_number				:8;
		unsigned __int16 current_next_indicator		:1;
		unsigned __int16 version_number				:5;
		unsigned __int16 reserved					:2;
	}INIT_STRUCT(SDT_data2, buff);
	
	struct ___ 
	{
		unsigned __int32 reserved_future_use		:8;
		unsigned __int32 original_network_id		:16;
		unsigned __int32 last_section_number		:8;
	}INIT_STRUCT(SDT_data3, buff);

	unsigned __int16 service_id;

	struct ____ 
	{
		unsigned __int8 EIT_present_following_flag	:1;
		unsigned __int8 EIT_schedule_flag			:1;
		unsigned __int8 reserved_future_use			:6;
	}SDT_data4;

	struct _____ 
	{
		unsigned __int16 descriptors_loop_length	:12;
		unsigned __int16 free_CA_mode				:1;
		unsigned __int16 running_status				:3;
	}SDT_data5;

	unsigned __int16 serv_info_leng = SDT_data1.section_length - 8 - cnCRC32Size;
	while (serv_info_leng) 
	{
		EVALUATE(service_id, buff);
		EVALUATE(SDT_data4, buff);
		EVALUATE(SDT_data5, buff);
		serv_info_leng -= 5;

		for (int i = 0; i < DB_service_count; i ++) 
		{
			if (DB_service_list[i].program_number == service_id) 
			{
				DB_service_index = i;
				break;
			}
		}

		unsigned __int16 desc_leng, info_leng = SDT_data5.descriptors_loop_length;
		while (info_leng) 
		{
			desc_leng = descriptor(buff);
			buff += desc_leng;
			info_leng -= desc_leng;
			serv_info_leng -= desc_leng;
		}
	}
}

/*
 *	ETSI EN 300 468 V1.7.1 (2006-18 05) 5.2.1 Network Information Table (NIT)
 */
void network_information_section(byte * buff, int leng)
{
	struct _ 
	{//defined in reverse order
		unsigned __int64 last_section_number		:8;
		unsigned __int64 section_number				:8;
		unsigned __int64 current_next_indicator		:1;
		unsigned __int64 version_number				:5;
		unsigned __int64 reserved					:2;
		unsigned __int64 network_id					:16;
		unsigned __int64 section_length				:12;
		unsigned __int64 reserved_2					:2;
		unsigned __int64 reserved_future_use_2		:1;
		unsigned __int64 section_syntax_indicator	:1;
		unsigned __int64 table_id					:8;
	}INIT_STRUCT(NIT_data1, buff);

	struct __ 
	{//defined in reverse order
		unsigned short network_descriptors_length	:12;
		unsigned short reserved_future_use			:4;
	}INIT_STRUCT(NIT_data2, buff);
}


/*
 *	temp func. collect section. 
 *	buff: payload start pointer
 *	leng: payload size in current packet
 *	return: section buffer when finish
 */
byte* collect_section(byte *buff, int leng, TS_packet_header *p_header)
{
	static __int16 PID;
	static byte continuity_conter;
	static __int16 size = 0;
	static byte sect_buff[1024];
	static __int16 sect_leng = 0;
	static bool accept = false;

	if (!buff || !leng || !p_header)
	{
		return NULL;
	}

	if (/*size + leng > 1024 || */leng <= 0) 
	{
		return NULL;
	}

	if (p_header->payload_unit_start_indicator) 
	{
		if (accept) 
		{
			return NULL;
		}

		sect_leng = ((0x000F & *(buff + 1)) << 8) + *(buff + 2) + 3;//add the 3 bytes that not described by this field, include table_id
		continuity_conter = p_header->continuity_counter;
		PID = p_header->PID;

		if (sect_leng < leng) 
		{
			memcpy(sect_buff, buff, sect_leng);
			size = sect_leng;
		}
		else
		{
			memcpy(sect_buff, buff, leng);
			size = leng;
		}

		accept = true;
	}
	else
	{
		if (!accept) 
		{
			return NULL;

⌨️ 快捷键说明

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