Beispiel #1
0
//ZQ 1.
static int StreamDumper( void* pContext, uint8_t* pData, int nSize )
{
	TS_CHANNEL_PARSER *pTSChannelParser = (TS_CHANNEL_PARSER*)pContext;
	STREAM_DATA   *stream_data   = (STREAM_DATA *)pData;
	TS_ELEMENT    *ts_elment     = stream_data->ts_elment;
	int index = stream_data->ts_elment->channel_index;
	ES_BUFFER_ *pESBuffer = &pTSChannelParser->es_buffer[index];
	int			  in_bytes;
	uint8_t *in_ptr;

	//fill data to send into dumper
	in_bytes = stream_data->bytes;
	in_ptr   = stream_data->data_ptr;

	pESBuffer->input_bytes += in_bytes;
	pTSChannelParser->total_bytes += in_bytes;

	if ( pTSChannelParser->av_streams.av_element[index].format_fourcc )
		return 1;

	if (  stream_data->group_start )
	{   
		PES pes={0};
		if ( IsPESHeaderOfTS( (uint8_t)pESBuffer->stream_id, in_ptr, in_bytes ) && //start a new es block
			 ReadPESHeader( in_ptr, in_bytes, &pes ) > 0 )
		{
			if ( pESBuffer->bytes > 0 )
			{
				int ret = AnylyzeAVElement( &pTSChannelParser->av_streams.av_element[index], &pTSChannelParser->es_streams.es_element[index],
										ts_elment, pESBuffer->buffer, pESBuffer->bytes, SAGETV_TV_RECORDING );
				if ( ret )
				{
					pESBuffer->stream_id = pes.stream_id;
					pESBuffer->pes = pes;
					_prints_av_elmnt( &pTSChannelParser->av_streams.av_element[index], index, pTSChannelParser->total_bytes );
					if ( pTSChannelParser->av_streams.av_element[index].content_type == VIDEO_DATA ) 
						pTSChannelParser->found_video_num++;
					else
					if ( pTSChannelParser->av_streams.av_element[index].content_type == AUDIO_DATA ) 
						pTSChannelParser->found_audio_num++;

					if ( CheckChannelTrackAVInfRead( pTSChannelParser ) )
					{
						pTSChannelParser->state |= AVINF_READY;
						pTSChannelParser->avinf_size =
							GetChannelAVInf( pTSChannelParser, pTSChannelParser->avinf, sizeof(pTSChannelParser->avinf) );
						if ( 0 && pTSChannelParser->dumper.avinf_dumper )
							pTSChannelParser->dumper.avinf_dumper( pTSChannelParser->dumper.avinf_dumper_context,
															pTSChannelParser->avinf, pTSChannelParser->avinf_size );
						SageLog(( _LOG_TRACE, 3, TEXT("AVINF IS READY, Message posted\r\n. %s."), pTSChannelParser->avinf ));
					}

					return 1;
				}
			}
			pESBuffer->pes = pes;
			pESBuffer->bytes = 0;
			memcpy( pESBuffer->buffer+pESBuffer->bytes, in_ptr, in_bytes );
			pESBuffer->bytes += in_bytes;
		} 
	} else
	{
		if ( pESBuffer->bytes + in_bytes >= pESBuffer->buffer_size )
		{

			int ret = AnylyzeAVElement( &pTSChannelParser->av_streams.av_element[index], &pTSChannelParser->es_streams.es_element[index],
									ts_elment, pESBuffer->buffer, pESBuffer->bytes, SAGETV_TV_RECORDING );
			if ( ret )
			{
				_prints_av_elmnt( &pTSChannelParser->av_streams.av_element[index], index, pTSChannelParser->total_bytes );
				if ( pTSChannelParser->av_streams.av_element[index].content_type == VIDEO_DATA ) 
					pTSChannelParser->found_video_num++;
				else
				if ( pTSChannelParser->av_streams.av_element[index].content_type == AUDIO_DATA ) 
					pTSChannelParser->found_audio_num++;

				if ( CheckChannelTrackAVInfRead( pTSChannelParser ) )
				{
					pTSChannelParser->state |= AVINF_READY;
					pTSChannelParser->avinf_size =
						GetChannelAVInf( pTSChannelParser, pTSChannelParser->avinf, sizeof(pTSChannelParser->avinf) );
					if ( 0 && pTSChannelParser->dumper.avinf_dumper )
						pTSChannelParser->dumper.avinf_dumper( pTSChannelParser->dumper.avinf_dumper_context,
															pTSChannelParser->avinf, pTSChannelParser->avinf_size );
					SageLog(( _LOG_TRACE, 3, TEXT("AVINF IS READY, Message posted.\r\n %s."), pTSChannelParser->avinf ));
				}

				return 1;
			}
			pESBuffer->bytes = 0;
		}
		memcpy( pESBuffer->buffer+pESBuffer->bytes, in_ptr, in_bytes );
		pESBuffer->bytes += in_bytes;
	}

	return 1;
}
Beispiel #2
0
//ZQ 1.
static int StreamDumper( void* pContext, unsigned char* pData, int nSize )
{
	TS_INFO_PARSER *pTSInfoParser = (TS_INFO_PARSER*)pContext;
	STREAM_DATA   *stream_data   = (STREAM_DATA *)pData;
	TS_ELEMENT    *ts_elment     = stream_data->ts_elment;
	int index = stream_data->ts_elment->channel_index;
	ES_BUFFER *pESBuffer = &pTSInfoParser->es_buffer[index];
	int			  in_bytes;
	unsigned char *in_ptr;

	//fill data to send into dumper
	in_bytes = stream_data->bytes;
	in_ptr   = stream_data->data_ptr;

	pESBuffer->input_bytes += in_bytes;
	pTSInfoParser->total_bytes += in_bytes;

	if ( CheckTrackAVInfRead( pTSInfoParser ) )
	{
		int VideoIndex, AudioIndex;
		pTSInfoParser->state |= AVINF_READY;
		pTSInfoParser->avinf_size =
		GetAVInfo( pTSInfoParser, pTSInfoParser->avinf, sizeof(pTSInfoParser->avinf) );
		if ( pTSInfoParser->dumper.pid_dumper && GetMainAVIndex( pTSInfoParser, &VideoIndex, &AudioIndex ) )
		{
			PID_ITEM pid_inf;
			if ( pTSInfoParser->av_streams.av_element[VideoIndex].content_type == VIDEO_DATA )
			{
				pid_inf.pid = pTSInfoParser->ts_streams.ts_element[VideoIndex].pid;
				pid_inf.type = PID_TYPE_VIDEO;
				pid_inf.data = 1;  //mark it's main video
				pid_inf.service = pTSInfoParser->ts_streams.ts_element[VideoIndex].type;
				pTSInfoParser->dumper.pid_dumper( pTSInfoParser->dumper.pid_dumper_context, &pid_inf, sizeof(pid_inf) );
			}
			if ( pTSInfoParser->av_streams.av_element[AudioIndex].content_type == AUDIO_DATA )
			{
				pid_inf.pid = pTSInfoParser->ts_streams.ts_element[AudioIndex].pid;
				pid_inf.type = PID_TYPE_AUDIO;
				pid_inf.data = 1;  //mark it's main video
				pid_inf.service = pTSInfoParser->ts_streams.ts_element[AudioIndex].type;
				pTSInfoParser->dumper.pid_dumper( pTSInfoParser->dumper.pid_dumper_context, &pid_inf, sizeof(pid_inf) );
			}
		}
		if ( pTSInfoParser->dumper.avinf_dumper )
		{
			SageLog(( _LOG_TRACE, 3, TEXT("AVINF is ready, Post message (%d)."), pTSInfoParser->avinf_size ));
			pTSInfoParser->dumper.avinf_dumper( pTSInfoParser->dumper.avinf_dumper_context,
												pTSInfoParser->avinf, pTSInfoParser->avinf_size );

		}
	}

	if ( pTSInfoParser->av_streams.av_element[index].format_fourcc )
		return 1;

	if (  stream_data->group_start )
	{   
		PES pes={0};
		if ( IsPESHeaderOfTS( (unsigned char)pESBuffer->stream_id, in_ptr, in_bytes ) && //start a new es block
			 ReadPESHeader( in_ptr, in_bytes, &pes ) > 0 )
		{
			if ( pESBuffer->bytes > 0 )
			{
				int ret = AnylyzeAVElement( &pTSInfoParser->av_streams.av_element[index], &pTSInfoParser->es_streams.es_element[index],
										ts_elment, pESBuffer->buffer, pESBuffer->bytes, SAGETV_TV_RECORDING );
				if ( ret )
				{
					pESBuffer->stream_id = pes.stream_id;
					pESBuffer->pes = pes;
					_prints_av_elmnt( &pTSInfoParser->av_streams.av_element[index], index, pTSInfoParser->total_bytes );
					if ( pTSInfoParser->av_streams.av_element[index].content_type == VIDEO_DATA ) 
						pTSInfoParser->found_video_num++;
					else
					if ( pTSInfoParser->av_streams.av_element[index].content_type == AUDIO_DATA ) 
						pTSInfoParser->found_audio_num++;
			
					return 1;
				}
			}
			pESBuffer->pes = pes;
			pESBuffer->bytes = 0;
			memcpy( pESBuffer->buffer+pESBuffer->bytes, in_ptr, in_bytes );
			pESBuffer->bytes += in_bytes;
		} 
	} else
	{
		if ( pESBuffer->bytes + in_bytes >= pESBuffer->buffer_size )
		{

			int ret = AnylyzeAVElement( &pTSInfoParser->av_streams.av_element[index], &pTSInfoParser->es_streams.es_element[index],
									ts_elment, pESBuffer->buffer, pESBuffer->bytes, SAGETV_TV_RECORDING );
			if ( ret )
			{
				_prints_av_elmnt( &pTSInfoParser->av_streams.av_element[index], index, pTSInfoParser->total_bytes );
				if ( pTSInfoParser->av_streams.av_element[index].content_type == VIDEO_DATA ) 
					pTSInfoParser->found_video_num++;
				else
				if ( pTSInfoParser->av_streams.av_element[index].content_type == AUDIO_DATA ) 
					pTSInfoParser->found_audio_num++;

				return 1;
			}
			pESBuffer->bytes = 0;
		}
		memcpy( pESBuffer->buffer+pESBuffer->bytes, in_ptr, in_bytes );
		pESBuffer->bytes += in_bytes;
	}

	return 1;
}