/// <summary>
 /// Initializes a new instance of the <see cref="AudioTrackCodecData"/> class.
 /// </summary>
 /// <param name="waveFormatEx">The wave format ex.</param>
 public AudioTrackCodecData(WaveFormatEx waveFormatEx)
 {
     if (waveFormatEx != null)
     {
         this.PacketSize = (ushort)waveFormatEx.BlockAlign;
         this.AudioTag = (ushort)waveFormatEx.FormatTag;
         this.FourCodecCode = MapAudioTagToFourCodecCode(this.AudioTag);
         WaveFormatEx = waveFormatEx;
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AudioTrackCodecData"/> class.
 /// </summary>
 /// <param name="waveFormatEx">The wave format ex.</param>
 public AudioTrackCodecData(WaveFormatEx waveFormatEx)
 {
     if (waveFormatEx != null)
     {
         this.PacketSize    = (ushort)waveFormatEx.BlockAlign;
         this.AudioTag      = (ushort)waveFormatEx.FormatTag;
         this.FourCodecCode = MapAudioTagToFourCodecCode(this.AudioTag);
         WaveFormatEx       = waveFormatEx;
     }
 }
Esempio n. 3
0
        /// <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>
        /// Reads the sample entry properties from stream.
        /// </summary>
        /// <param name="reader">The stream reader.</param>
        internal override void ReadSampleEntryPropertiesFromStream(BoxBinaryReader reader)
        {
            this.reserved1 = reader.ReadUInt16();
            this.reserved2 = reader.ReadUInt16();
            this.reserved3 = reader.ReadUInt32();
            this.ChannelCount = reader.ReadUInt16();
            this.SampleSize = reader.ReadUInt16();
            this.predefined = reader.ReadUInt16();
            this.reserved4 = reader.ReadUInt16();
            this.SampleRate = reader.ReadUInt32();

            if (reader.PeekNextBoxType() != BoxType.Null)
            {
                ReadInnerBoxes(reader, BoxType.Esds, BoxType.Wfex, BoxType.Sinf, BoxType.Dec3, BoxType.Dac3, BoxType.Dmlp, BoxType.Ddts);
                this.AudioCodecData = GetAudioCodecDataFromInnerBoxes();
            }
            else
            {
                var waveFormatEx = new WaveFormatEx(reader);
                this.AudioCodecData = new AudioTrackCodecData(waveFormatEx);
            }
        }
        /// <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;
                    }
                }
            }
        }