示例#1
0
static void TagMainTrack( TS_CHANNEL_PARSER *pTSChannelParser )
{
	int i, video_main = -1, audio_main = -1;
	uint32_t bit_rate = 0;
	for ( i = 0; i<pTSChannelParser->ts_streams.num_stream; i++ )
	{
		if ( pTSChannelParser->av_streams.av_element[i].content_type == VIDEO_DATA )
		{
			if ( video_main == -1 ) 
				video_main = i;
			else
			if ( pTSChannelParser->es_buffer[i].input_bytes > pTSChannelParser->es_buffer[video_main].input_bytes )
				video_main = i;
			bit_rate += GetAudioRate( &pTSChannelParser->av_streams.av_element[i]  );
		}
		else
		if ( pTSChannelParser->av_streams.av_element[i].content_type == AUDIO_DATA )
		{
			if ( audio_main == -1 ) 
				audio_main = i;
			else
			if ( pTSChannelParser->es_buffer[i].input_bytes > pTSChannelParser->es_buffer[audio_main].input_bytes )
				audio_main = i;
			bit_rate += GetAudioRate( &pTSChannelParser->av_streams.av_element[i]  );
		}
	}
	if ( video_main >= 0 )
		pTSChannelParser->es_buffer[video_main].main_track = 1;
	if ( audio_main >= 0 )
		pTSChannelParser->es_buffer[audio_main].main_track = 1;

	pTSChannelParser->bit_rate = bit_rate;
}
示例#2
0
static void TagMainTrack( TS_INFO_PARSER *pTSInfoParser )
{
	int i, video_main = -1, audio_main = -1;
	unsigned long bit_rate = 0;
	int weights[32]={0};
	for ( i = 0; i<pTSInfoParser->ts_streams.num_stream && i<32; i++ )
	{
		pTSInfoParser->es_buffer[i].main_track = 0;
		if ( pTSInfoParser->av_streams.av_element[i].content_type == VIDEO_DATA )
		{
			if ( video_main == -1 ) 
				video_main = i;
			else
			if ( pTSInfoParser->es_buffer[i].input_bytes > pTSInfoParser->es_buffer[video_main].input_bytes )
				video_main = i;
			bit_rate += GetAudioRate( &pTSInfoParser->av_streams.av_element[i]  );
		}
		else
		if ( pTSInfoParser->av_streams.av_element[i].content_type == AUDIO_DATA )
		{
			weights[i] = GetAudioSoundChannelNum( &pTSInfoParser->av_streams.av_element[i] )*100;
			weights[i] += GetAudioSoundBitRate( &pTSInfoParser->av_streams.av_element[i] ) / 10000; /* range 1-100 */
			if ( audio_main == -1 ) 
				audio_main = i;
			else
			{
				if ( weights[i] > weights[audio_main] )
					audio_main = i;
				bit_rate += GetAudioRate( &pTSInfoParser->av_streams.av_element[i]  );
			}
		}
	}
	if ( video_main >= 0 )
		pTSInfoParser->es_buffer[video_main].main_track = 1;
	if ( audio_main >= 0 )
		pTSInfoParser->es_buffer[audio_main].main_track = 1;

	pTSInfoParser->bit_rate = bit_rate;
}
示例#3
0
文件: AVTrack.c 项目: neurocis/sagetv
int TracksInfo( TRACKS* pTracks, char* pBuffer, int nSize )
{
	int i, pos = 0, video_num=0, audio_num=0;
	int h_264_present=0, video_data_present=0, audio_data_present=0;
	char *p = pBuffer;
	ES_ELEMENT *pESElmnt; 

	unsigned long bit_rate = 0;

	if ( IS_TS_TYPE( pTracks->track_type ) )
	{
		if ( !(pTracks->track_attr & (ATTR_VIDEO_PRESENT|ATTR_AUDIO_PRESENT)) )
		{
			if ( ( pTracks->track_attr & ATTR_ENCRYPTED_FLAG ) )
			{
				pos += snprintf( pBuffer, nSize-pos, "ENCRYPTED-TS;" );
				return pos;
			}
			pos += snprintf( pBuffer, nSize-pos, "NO-AV-TS;" );
			return pos;
		}

		if ( pTracks->main_video_index != 0xffff )
			pESElmnt = pTracks->track[pTracks->main_video_index].es_elmnt;
		else
		if ( pTracks->main_audio_index != 0xffff )
			pESElmnt = pTracks->track[pTracks->main_audio_index].es_elmnt;
		else
		{
			pos += snprintf( p+pos, nSize-pos, "Error: no main video and audio specified."  );
			return 0;  //no main track found;
		}
		if ( pESElmnt->es_type == ES_MPEG1 )
			pos += snprintf( pBuffer, nSize-pos, "MPEG1-TS;" );
		else
		if ( pESElmnt->es_type == ES_MPEG2 )
			pos += snprintf( pBuffer, nSize-pos, "MPEG2-TS;" );
		else
		{
			if ( ( pTracks->track_attr & ATTR_ENCRYPTED_FLAG ) )
				pos += snprintf( pBuffer, nSize-pos, "ENCRYPTED-TS;" );
			else
				pos += snprintf( pBuffer, nSize-pos, "UNKNOWN-TS;" );
		}

	} else
	{
		if ( pTracks->main_video_index != 0xffff )
			pESElmnt = pTracks->track[pTracks->main_video_index].es_elmnt;
		else
		if ( pTracks->main_audio_index != 0xffff )
			pESElmnt = pTracks->track[pTracks->main_audio_index].es_elmnt;
		else
		{
			pos += snprintf( p+pos, nSize-pos, "Error: no main video and audio specified."  );
			return 0; //no main track found;
		}
		if ( pESElmnt->es_type == ES_MPEG1 )
			pos += snprintf( p, nSize-pos, "MPEG1-PS;" );
		else
		if ( pESElmnt->es_type == ES_MPEG2 )
			pos += snprintf( p, nSize-pos, "MPEG2-PS;" );
		else
			pos += snprintf( p, nSize-pos, "UNKNOWN-PS;" );
	}

	for ( i = 0; i<pTracks->number_track; i++ )
	{
		if ( pTracks->track[i].ts_elmnt && 
			 pTracks->track[i].ts_elmnt->content_type == VIDEO_DATA &&
			 pTracks->track[i].ts_packets_counter > 2 )
		{
			 video_data_present = 1;
			 if ( pTracks->track[i].ts_elmnt->format_fourcc == SAGE_FOURCC( "H264" ) )
				h_264_present=1;
		}
		if ( pTracks->track[i].ts_elmnt && 
			 pTracks->track[i].ts_elmnt->content_type == AUDIO_DATA &&
			 pTracks->track[i].ts_packets_counter > 2 )
		{
			 audio_data_present = 1;
		}
		if ( pTracks->track[i].av_elmnt->content_type == VIDEO_DATA )
		{
			bit_rate += GetVideoRate( pTracks->track[i].av_elmnt  );
			video_num++;
		}
		if ( pTracks->track[i].av_elmnt->content_type == AUDIO_DATA )
		{
			bit_rate += GetAudioRate( pTracks->track[i].av_elmnt  );
			audio_num++;
		}
	}

	if ( nSize > pos && bit_rate > 0 )
		pos += snprintf( p+pos, nSize-pos, "br=%ld;", bit_rate );

	if ( IS_TS_TYPE( pTracks->track_type ) )
	{
		pos += snprintf( p+pos, nSize-pos, "%s", 
			 pTracks->track_type==MPEG_M2TS?"ps=192;":pTracks->track_type==MPEG_ASI?"ps=208;":"" );
	}

	if ( video_num == 0 )
	{
		if ( IS_TS_TYPE( pTracks->track_type ) )
		{
			if ( !video_data_present && audio_num > 0) //R5000 recording live tv has enough data to parse out video AV info,  
				pos += snprintf( p+pos, nSize-pos, "audioonly=1;" );

		} else
		{
			pos += snprintf( p+pos, nSize-pos, "audioonly=1;" );
		}

	}

	if ( audio_num == 0 )
	{
		if ( IS_TS_TYPE( pTracks->track_type ) )
		{
			if ( !audio_data_present && video_num > 0 ) //R5000 recording live tv has enough data to parse out video AV info,  
				pos += snprintf( p+pos, nSize-pos, "videoonly=1;" );

		} else
		{
			pos += snprintf( p+pos, nSize-pos, "videoonly=1;"  );
		}
	}

	for ( i = 0; i<pTracks->number_track  ; i++ )
	{
		if ( pTracks->track[i].av_elmnt->content_type == VIDEO_DATA )
		{
			if ( nSize > pos ) pos += snprintf( p+pos, nSize-pos, "[" );
			pos += AVElmntInfo( pTracks->track[i].av_elmnt, p+pos, nSize-pos );
			if ( i == pTracks->main_video_index )
				if ( nSize > pos )	pos += snprintf( p+pos, nSize-pos, "main=yes;"  );
			pos += TagInfo( pTracks->track_type, pTracks->track[i].ts_elmnt, 
				                    pTracks->track[i].es_elmnt, p+pos, nSize-pos );
			if ( nSize > pos )	pos += snprintf( p+pos, nSize-pos, "index=%d;", pTracks->track[i].av_elmnt->stream_index );
			if ( nSize > pos+2 ) { p[pos++] = ']'; p[pos++] = ';';  } //terminator
		}
	}

	for ( i = 0; i<pTracks->number_track  ; i++ )
	{
		if ( pTracks->track[i].av_elmnt->content_type == AUDIO_DATA )
		{
			char tmp[16];
			unsigned long language_code;
			unsigned char audio_type;
			if ( nSize > pos )	pos += snprintf( p+pos, nSize-pos, "[" );
			pos += AVElmntInfo( pTracks->track[i].av_elmnt, p+pos, nSize-pos );
			if ( i == pTracks->main_audio_index )
				if ( nSize > pos )	pos += snprintf( p+pos, nSize-pos, "main=yes;"  );
			if ( pTracks->track[i].ts_elmnt != NULL && pTracks->track[i].ts_elmnt->language_code )
			{
				language_code = pTracks->track[i].ts_elmnt->language_code;
				audio_type = pTracks->track[i].ts_elmnt->audio_type;
			}
			else
			{
				language_code = pTracks->track[i].es_elmnt->language_code;
				audio_type = pTracks->track[i].es_elmnt->audio_type;
			}
			if ( language_code )
			{
				if ( language_code == LanguageCode( (unsigned char*)"qaa" ) )
					strncpy( tmp, "original", sizeof(tmp) );
				else
					Language(language_code, tmp );
				if ( nSize > pos )	pos += snprintf( p+pos, nSize-pos, "lang=%s;", tmp );
			}
			if ( audio_type )
				if ( nSize > pos )	pos += snprintf( p+pos, nSize-pos, "ty=%s;",AudioType(audio_type) );
			pos += TagInfo( pTracks->track_type, pTracks->track[i].ts_elmnt, 
				                   pTracks->track[i].es_elmnt, p+pos, nSize-pos );
			if ( nSize > pos )	pos += snprintf( p+pos, nSize-pos, "index=%d;", pTracks->track[i].av_elmnt->stream_index );
			if ( nSize > pos+3 ) { p[pos++] = ']'; p[pos++] = ';';  } //terminator
		}
	}
	for ( i = 0; i<pTracks->number_track  ; i++ )
	{
		if ( pTracks->track[i].av_elmnt->content_type == SUBTITLE_DATA )
		{
			char tmp[16];
			unsigned long language_code;
			if ( nSize > pos ) pos += snprintf( p+pos, nSize-pos, "[" );
			pos += AVElmntInfo( pTracks->track[i].av_elmnt, p+pos, nSize-pos );
			if ( pTracks->track[i].ts_elmnt != NULL && pTracks->track[i].ts_elmnt->language_code )
				language_code = pTracks->track[i].ts_elmnt->language_code;
			else
				language_code = pTracks->track[i].es_elmnt->language_code;
			if ( language_code )
			{
				Language(language_code, tmp );
				if ( nSize > pos )	pos += snprintf( p+pos, nSize-pos, "lang=%s;", tmp );
			}
			pos += TagInfo( pTracks->track_type, pTracks->track[i].ts_elmnt, 
				                    pTracks->track[i].es_elmnt, p+pos, nSize-pos );
			if ( nSize > pos )	pos += snprintf( p+pos, nSize-pos, "index=%d;", pTracks->track[i].av_elmnt->stream_index );
			if ( nSize > pos+2 ) { p[pos++] = ']'; p[pos++] = ';';  } //terminator
		}
	}
	if ( pos < nSize ) p[pos]= 0x0;
	return pos;
}