/// <summary> /// Initializes a new instance of the <see cref="AudioTrackCodecData"/> class. /// </summary> /// <param name="esds">The esds box.</param> public AudioTrackCodecData(AudioSampleEntryBox ase, ElementaryStreamDescriptorFullBox esds) { if (esds != null && esds.StreamDescriptor != null) { var decoderConfiguration = esds.StreamDescriptor.SubDescriptors.SingleOrDefault(d => d.Tag == DescriptorTag.DECODER_CONFIG) as DecoderConfigurationDescriptor; if (decoderConfiguration != null) { var decoderSpecificInformation = decoderConfiguration.SubDescriptors.SingleOrDefault(d => d.Tag == DescriptorTag.DECODER_SPECIFIC_INFO) as DecoderSpecificInformationDescriptor; switch (decoderConfiguration.ObjectTypeIndication) { case DecoderConfigurationDescriptor.DecoderObjectTypes.MPEG1_AUDIO: this.PacketSize = 1; this.AudioTag = 0x55; break; case DecoderConfigurationDescriptor.DecoderObjectTypes.MPEG2_AAC_AUDIO_SSRP: case DecoderConfigurationDescriptor.DecoderObjectTypes.MPEG2_AAC_AUDIO_LC: case DecoderConfigurationDescriptor.DecoderObjectTypes.MPEG2_AAC_AUDIO_MAIN: case DecoderConfigurationDescriptor.DecoderObjectTypes.MPEG4_AUDIO: case DecoderConfigurationDescriptor.DecoderObjectTypes.MPEG2_PART3_AUDIO: this.PacketSize = 4; if (decoderSpecificInformation != null && (decoderSpecificInformation.Information[0] == 0x05 || decoderSpecificInformation.Information[0] == 0x1D)) { this.AudioTag = 0x1610; //HE-AAC } else { this.AudioTag = 0xFF; //AAC-LC } break; default: break; } this.FourCodecCode = MapAudioTagToFourCodecCode(this.AudioTag); WaveFormatEx = new WaveFormatEx(); WaveFormatEx.FormatTag = (short)this.AudioTag; WaveFormatEx.Channels = (short)ase.ChannelCount; WaveFormatEx.SamplesPerSec = (int)ase.SampleRate; WaveFormatEx.BitsPerSample = (short)ase.SampleSize; WaveFormatEx.BlockAlign = 8; WaveFormatEx.AvgBytesPerSec = WaveFormatEx.SamplesPerSec * WaveFormatEx.Channels * WaveFormatEx.BitsPerSample / WaveFormatEx.BlockAlign; if (decoderSpecificInformation != null) { WaveFormatEx.Size = (short)decoderSpecificInformation.Information.Length; WaveFormatEx.ExtendedData = decoderSpecificInformation.Information; } } } }
/// <summary> /// Initializes a new instance of the <see cref="AudioTrackCodecData"/> class. /// </summary> /// <param name="esds">The esds box.</param> public AudioTrackCodecData(AudioSampleEntryBox ase, ElementaryStreamDescriptorFullBox esds) { if (esds != null && esds.StreamDescriptor != null) { var decoderConfiguration = esds.StreamDescriptor.SubDescriptors.SingleOrDefault(d => d.Tag == DescriptorTag.DECODER_CONFIG) as DecoderConfigurationDescriptor; if (decoderConfiguration != null) { var decoderSpecificInformation = decoderConfiguration.SubDescriptors.SingleOrDefault(d => d.Tag == DescriptorTag.DECODER_SPECIFIC_INFO) as DecoderSpecificInformationDescriptor; switch (decoderConfiguration.ObjectTypeIndication) { case DecoderConfigurationDescriptor.DecoderObjectTypes.MPEG1_AUDIO: this.PacketSize = 1; this.AudioTag = 0x55; break; case DecoderConfigurationDescriptor.DecoderObjectTypes.MPEG2_AAC_AUDIO_SSRP: case DecoderConfigurationDescriptor.DecoderObjectTypes.MPEG2_AAC_AUDIO_LC: case DecoderConfigurationDescriptor.DecoderObjectTypes.MPEG2_AAC_AUDIO_MAIN: case DecoderConfigurationDescriptor.DecoderObjectTypes.MPEG4_AUDIO: case DecoderConfigurationDescriptor.DecoderObjectTypes.MPEG2_PART3_AUDIO: this.PacketSize = 4; if (decoderSpecificInformation != null && (decoderSpecificInformation.Information[0] == 0x05 || decoderSpecificInformation.Information[0] == 0x1D)) this.AudioTag = 0x1610; //HE-AAC else this.AudioTag = 0xFF; //AAC-LC break; default: break; } this.FourCodecCode = MapAudioTagToFourCodecCode(this.AudioTag); WaveFormatEx = new WaveFormatEx(); WaveFormatEx.FormatTag = (short)this.AudioTag; WaveFormatEx.Channels = (short)ase.ChannelCount; WaveFormatEx.SamplesPerSec = (int)ase.SampleRate; WaveFormatEx.BitsPerSample = (short)ase.SampleSize; WaveFormatEx.BlockAlign = 8; WaveFormatEx.AvgBytesPerSec = WaveFormatEx.SamplesPerSec * WaveFormatEx.Channels * WaveFormatEx.BitsPerSample / WaveFormatEx.BlockAlign; if (decoderSpecificInformation != null) { WaveFormatEx.Size = (short)decoderSpecificInformation.Information.Length; WaveFormatEx.ExtendedData = decoderSpecificInformation.Information; } } } }