Exemplo n.º 1
0
static int PMTDumper( void* pContext, uint8_t* pData, int nSize )
{
	TS_CHANNEL_PARSER *pTSChannelParser = (TS_CHANNEL_PARSER*)pContext;
	PMT_DATA  *pPmtData  = (PMT_DATA*)pData;
	TS_PMT    *pPmt      = (TS_PMT*)pPmtData->pmt_table;
	//TS_SECTION *pPmtSection = pPmtData->pmt_section;
	int channel = pPmtData->channel;
	//int channel_num = pPmtData->total_channel_num;
	int stream_num  = pPmt->total_stream_number;
	int i, encrypted = 0, valid_stream = 0;

	ASSERT( pContext != NULL );
	ASSERT( (nSize == sizeof(PMT_DATA)) );

	if ( stream_num == 0 )		return 1;

	if ( (pPmtData->update_flag & PMT_UPDATED) ) //skip unchanged PMT
	{
		SageLog(( _LOG_TRACE, 3, TEXT("\tChannel:%d (tsid:%d) PMT pid:0x%04x Program:%04d PCR pid:0x%04x %s."),  channel, 
			pPmtData->tsid, pPmtData->pid, pPmt->program_number, pPmt->pcr_pid, pPmt->ca_pid ? CAInfo( pPmt->ca_pid, pPmt->ca_id) :"" ));
		for ( i = 0; i< stream_num; i++ )
		{	
			int has_ca_desc = HasCADesc( pPmt->stream_desc[i].desc_ptr, pPmt->stream_desc[i].desc_bytes )? 1 : 0;
			if ( has_ca_desc ) 
				encrypted++;
			if ( IsVideoType( pPmt->stream_type[i] ) || IsAudioType( pPmt->stream_type[i] ) ) 
				valid_stream++;
			SageLog(( _LOG_TRACE, 3,  TEXT("\t\tType:0x%02x Pid:0x%03x  %s"), pPmt->stream_type[i], pPmt->stream_pid[i], has_ca_desc?"encrypted":" " ));
		}

		//PMT updated and repersent, we need reselect channel to change filter
		if ( ( pPmtData->update_flag & PMT_REPEAT ))
		{
			SageLog(( _LOG_TRACE, 3,  TEXT("PMT Updated, reselect channel" ) ));
		}
	}
	
	if ( pPmt->ca_pid == 0 && encrypted == 0 && valid_stream > 0 )
	{
		if ( AddProgrmToList( &pTSChannelParser->program_list, pPmtData->tsid, pPmt->program_number, pPmtData->channel, 1 ) >= 0 )
		{
			SageLog(( _LOG_TRACE, 3, TEXT("Uncrypted channel is found (channel:%d program:%d tsid:%d)."), pPmtData->channel, pPmt->program_number, pPmtData->tsid ));
		} 
	}

	return 1;
}
Exemplo n.º 2
0
static int PMTDumper( void* pContext, unsigned char* pData, int nSize )
{
	TS_INFO_PARSER *pTSInfoParser = (TS_INFO_PARSER*)pContext;
	PMT_DATA  *pPmtData  = (PMT_DATA*)pData;
	TS_PMT    *pPmt      = (TS_PMT*)pPmtData->pmt_table;
	//TS_SECTION *pPmtSection = pPmtData->pmt_section;
	int channel = pPmtData->channel;
	//int channel_num = pPmtData->total_channel_num;
	int stream_num  = pPmt->total_stream_number;
	int i;

	ASSERT( pContext != NULL );
	ASSERT( (nSize == sizeof(PMT_DATA)) );

	if ( stream_num == 0 )		return 1;

	if ( (pPmtData->update_flag & PMT_UPDATED) ) //skip unchanged PMT
	{
		SageLog(( _LOG_TRACE, 3, TEXT("\tChannel:%d (tsid:%d) PMT pid:0x%04x Program:%04d PCR pid:0x%04x %s."),  channel, 
			pPmtData->tsid, pPmtData->pid, pPmt->program_number, pPmt->pcr_pid, pPmt->ca_pid ? CAInfo( pPmt->ca_pid, pPmt->ca_id) :"" ));
		for ( i = 0; i< stream_num; i++ )
		{
			SageLog(( _LOG_TRACE, 3,  TEXT("\t\tType:0x%02x Pid:0x%03x"), pPmt->stream_type[i], pPmt->stream_pid[i] ));
		}

		//PMT updated and repersent, we need reselect channel to change filter
		if ( ( pPmtData->update_flag & PMT_REPEAT ))
		{
			SageLog(( _LOG_TRACE, 3,  TEXT("PMT Updated, reselect channel" )));
		}
	}

	if ( (pTSInfoParser->state & PROGRAM_FOUND) && 
		 (pTSInfoParser->state & CHANNEL_FOUND) == 0 ) 
	{
		if ( CheckProgramId( pTSInfoParser, pPmt->program_number, pPmtData->tsid )>0 ) 
		{
			PID_ITEM pid_inf;
			int len;
			pTSInfoParser->ts_streams.num_stream = 0;
			for ( i = 0; i< stream_num ; i++ )
			{
				if ( IsVideoType( pPmt->stream_type[i] ) || pPmt->stream_type[i] == PRIVATE_0x80_STREAM_TYPE  )  //QAM stream has DC-II video that uses 0x80 for video
				{
					pTSInfoParser->ts_streams.ts_element[pTSInfoParser->ts_streams.num_stream].pid = pPmt->stream_pid[i];
					pTSInfoParser->ts_streams.ts_element[pTSInfoParser->ts_streams.num_stream].type =  pPmt->stream_type[i];
					pTSInfoParser->ts_streams.ts_element[pTSInfoParser->ts_streams.num_stream].content_type = VIDEO_DATA;
					pTSInfoParser->ts_streams.ts_element[pTSInfoParser->ts_streams.num_stream].channel_index = 
						                                 (unsigned char)pTSInfoParser->ts_streams.num_stream;
					pTSInfoParser->ts_streams.ts_element[pTSInfoParser->ts_streams.num_stream].format_fourcc = 
											TVVideoFormat( pPmt->stream_type[i],
														 pPmt->stream_desc[i].desc_ptr, 
														 pPmt->stream_desc[i].desc_bytes  );
					len = pPmt->stream_desc[i].desc_bytes;
					if ( len > sizeof(pTSInfoParser->ts_streams.ts_element[0].desc) )
						len = sizeof(pTSInfoParser->ts_streams.ts_element[0].desc);
					memcpy( pTSInfoParser->ts_streams.ts_element[pTSInfoParser->ts_streams.num_stream].desc, 
						pPmt->stream_desc[i].desc_ptr, len );
					pTSInfoParser->ts_streams.ts_element[pTSInfoParser->ts_streams.num_stream].desc_len = len;
					_print_es_descriptor_( pPmt->stream_pid[i], 
						                   pPmt->stream_desc[i].desc_ptr, 
							               pPmt->stream_desc[i].desc_bytes   ); //ZQ Debug
					pTSInfoParser->total_video_num++;

					if ( pTSInfoParser->dumper.pid_dumper )
					{
						pid_inf.pid = pPmt->stream_pid[i];
						pid_inf.type = PID_TYPE_VIDEO;
						pid_inf.service = pPmt->stream_type[i];
						pid_inf.data = 0;
						pTSInfoParser->dumper.pid_dumper( pTSInfoParser->dumper.pid_dumper_context, &pid_inf, sizeof(pid_inf) );
					}
					
					if ( ++pTSInfoParser->ts_streams.num_stream >= pTSInfoParser->ts_streams.total_streams-1 )
						break;

				} else
				if ( IsAudioType( pPmt->stream_type[i] ) )
				{
					pTSInfoParser->ts_streams.ts_element[pTSInfoParser->ts_streams.num_stream].pid = pPmt->stream_pid[i];
					pTSInfoParser->ts_streams.ts_element[pTSInfoParser->ts_streams.num_stream].type =  pPmt->stream_type[i];
					pTSInfoParser->ts_streams.ts_element[pTSInfoParser->ts_streams.num_stream].content_type = AUDIO_DATA;
					pTSInfoParser->ts_streams.ts_element[pTSInfoParser->ts_streams.num_stream].channel_index = 
						                                  (unsigned char)pTSInfoParser->ts_streams.num_stream;
					pTSInfoParser->ts_streams.ts_element[pTSInfoParser->ts_streams.num_stream].format_fourcc =     
										AudioFormatByStreamType( pTSInfoParser->ts_streams.ts_element[pTSInfoParser->ts_streams.num_stream].type );   
					if ( pTSInfoParser->ts_streams.ts_element[pTSInfoParser->ts_streams.num_stream].format_fourcc == 0 )                    
						pTSInfoParser->ts_streams.ts_element[pTSInfoParser->ts_streams.num_stream].format_fourcc = 
										HasAudioDesc(	pPmt->stream_desc[i].desc_ptr, 
														pPmt->stream_desc[i].desc_bytes  );
				
														 
					len = pPmt->stream_desc[i].desc_bytes;
					if ( len > sizeof(pTSInfoParser->ts_streams.ts_element[0].desc) )
						len = sizeof(pTSInfoParser->ts_streams.ts_element[0].desc);
					memcpy( pTSInfoParser->ts_streams.ts_element[pTSInfoParser->ts_streams.num_stream].desc, 
						pPmt->stream_desc[i].desc_ptr, len );
					pTSInfoParser->ts_streams.ts_element[pTSInfoParser->ts_streams.num_stream].desc_len = len;
					_print_es_descriptor_( pPmt->stream_pid[i], 
						                   pPmt->stream_desc[i].desc_ptr, 
							               pPmt->stream_desc[i].desc_bytes   ); //ZQ Debug
					pTSInfoParser->total_audio_num++;

					if ( pTSInfoParser->dumper.pid_dumper )
					{
						pid_inf.pid = pPmt->stream_pid[i];
						pid_inf.type = PID_TYPE_AUDIO;
						pid_inf.service = pPmt->stream_type[i];
						pid_inf.data = 0;
						pTSInfoParser->dumper.pid_dumper( pTSInfoParser->dumper.pid_dumper_context, &pid_inf, sizeof(pid_inf) );
					}

					if ( ++pTSInfoParser->ts_streams.num_stream >= pTSInfoParser->ts_streams.total_streams-1 )
						break;
				} 
			}
			if ( pTSInfoParser->dumper.pid_dumper )
			{
				
				pTSInfoParser->ts_streams.pcr_pid = pPmt->pcr_pid;				
				pid_inf.pid = pPmt->pcr_pid;
				pid_inf.type = PID_TYPE_PCR;
				pid_inf.service = 0;
				pid_inf.data = 0;
				pTSInfoParser->dumper.pid_dumper( pTSInfoParser->dumper.pid_dumper_context, &pid_inf, sizeof(pid_inf) );
			
				/*
				pTSInfoParser->ts_streams.ca_pid = pPmt->ca_pid;
				pid_inf.pid = pPmt->pcr_pid;
				pid_inf.type = PID_TYPE_CA;
				pid_inf.service = 0;
				pid_inf.data = 0;
				pTSInfoParser->dumper.pid_dumper( pTSInfoParser->dumper.pid_dumper_context, &pid_inf, sizeof(pid_inf) );
				*/
				
			}
			SetupChannelFilter( pTSInfoParser->ts_filter, &pTSInfoParser->ts_streams  );

			pTSInfoParser->state |= CHANNEL_FOUND;
		}
	}
	return 1;
}