Ejemplo n.º 1
0
 void Handle(char c)
 {
     switch(state)
     {
     case State::Default:
         ReadDefault(c);
         break;
     case State::ReadTagName:
         ReadTagName(c);
         break;
     case State::SkipTag:
         SkipTag(c);
         break;
     case State::ReadTag:
         ReadTag(c);
         break;
     case State::ReadAttribute:
         ReadAttribute(c);
         break;
     case State::SkipAttribute:
         SkipAttribute(c);
         break;
     case State::SkipComment:
         SkipComment(c);
         break;
     }
 }
Ejemplo n.º 2
0
void
ESDSAtom::OnOverrideAudioDescription(AudioDescription *pAudioDescription)
{
	// decode for aac and check for HE-AAC which uses a framesize of 2048
	// also check for MP3 which has an ESDS
	uint32 offset = 0;
	BitParser parser;

	if (SkipTag(pAudioDescription->theDecoderConfig, 0x03, &offset)) {
		offset += 3;
	} else {
		offset += 2;
	}

	if (SkipTag(pAudioDescription->theDecoderConfig, 0x04, &offset)) {
		parser.Init(&pAudioDescription->theDecoderConfig[offset],
			(pAudioDescription->DecoderConfigSize - offset) * 8);

		ESDSType = parser.GetValue(8);
		StreamType = parser.GetValue(6);
		parser.Skip(2);
		NeededBufferSize = parser.GetValue(24);
		MaxBitRate = parser.GetValue(32);
		AvgBitRate = parser.GetValue(32);
		
		pAudioDescription->BitRate = AvgBitRate;
		
		offset+=13;
	}

	// Find Tag 0x05 that describes the audio format
	SkipTag(pAudioDescription->theDecoderConfig, 0x05, &offset);
	bool smallFrameSize;
	uint32 SampleRate;

	// remember where the tag 5 starts
	uint32 extendedAudioConfig = offset;

	switch (ESDSType) {
		case 64:	// AAC so use AAC Header details to override ESDS values
			parser.Init(&pAudioDescription->theDecoderConfig[offset],
				(pAudioDescription->DecoderConfigSize - offset) * 8);

			// 5 bits are decoder type
			theAACHeader.objTypeIndex = parser.GetValue(5);
			if (theAACHeader.objTypeIndex == 31) {
				theAACHeader.objTypeIndex = 32 + parser.GetValue(6);
			}
			// 4 bits are frequency index
			theAACHeader.sampleRateIndex = parser.GetValue(4);
			if (theAACHeader.sampleRateIndex == 15) {
				// Direct encoding of SampleRate
				SampleRate = parser.GetValue(24);
			} else {
				SampleRate = aac_sampling_rate[theAACHeader.sampleRateIndex];
			}

			// 4 bits are channels
			theAACHeader.totalChannels = parser.GetValue(4);
			// 1 bit determines small frame size
			smallFrameSize = (parser.GetValue(1) == 1);
		
			if (theAACHeader.objTypeIndex < 3) {
				pAudioDescription->codecSubType = 'mp4a';
				pAudioDescription->FrameSize = 1024;
				if (smallFrameSize) {
					pAudioDescription->FrameSize = 960;
				}
			} else {
				pAudioDescription->codecSubType = 'haac';
				pAudioDescription->FrameSize = 2048;
			}
	
			// Override STSD
			pAudioDescription->theAudioSampleEntry.SampleRate = SampleRate;
			pAudioDescription->theAudioSampleEntry.ChannelCount =
				theAACHeader.totalChannels;
		
			// Reset decoder Config memory
			memcpy(pAudioDescription->theDecoderConfig,
				&pAudioDescription->theDecoderConfig[extendedAudioConfig],
				pAudioDescription->DecoderConfigSize - extendedAudioConfig + 1);
		
			break;
		
		case 107:	// MP3
			pAudioDescription->codecSubType = '.mp3';
			
			// Only set this for mp3, we calc it normally
			if (NeededBufferSize > pAudioDescription->BufferSize) {
				pAudioDescription->BufferSize = NeededBufferSize;
			}

			break;
	}
}