aac.h revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
1// Copyright 2014 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef MEDIA_FORMATS_MP4_AAC_H_ 6#define MEDIA_FORMATS_MP4_AAC_H_ 7 8#include <vector> 9 10#include "base/basictypes.h" 11#include "media/base/channel_layout.h" 12#include "media/base/media_export.h" 13 14namespace media { 15 16class BitReader; 17 18namespace mp4 { 19 20// This class parses the AAC information from decoder specific information 21// embedded in the esds box in an ISO BMFF file. 22// Please refer to ISO 14496 Part 3 Table 1.13 - Syntax of AudioSpecificConfig 23// for more details. 24class MEDIA_EXPORT AAC { 25 public: 26 AAC(); 27 ~AAC(); 28 29 // Parse the AAC config from the raw binary data embedded in esds box. 30 // The function will parse the data and get the ElementaryStreamDescriptor, 31 // then it will parse the ElementaryStreamDescriptor to get audio stream 32 // configurations. 33 bool Parse(const std::vector<uint8>& data); 34 35 // Gets the output sample rate for the AAC stream. 36 // |sbr_in_mimetype| should be set to true if the SBR mode is 37 // signalled in the mimetype. (ie mp4a.40.5 in the codecs parameter). 38 // Returns the samples_per_second value that should used in an 39 // AudioDecoderConfig. 40 int GetOutputSamplesPerSecond(bool sbr_in_mimetype) const; 41 42 // Gets the channel layout for the AAC stream. 43 // |sbr_in_mimetype| should be set to true if the SBR mode is 44 // signalled in the mimetype. (ie mp4a.40.5 in the codecs parameter). 45 // Returns the channel_layout value that should used in an 46 // AudioDecoderConfig. 47 ChannelLayout GetChannelLayout(bool sbr_in_mimetype) const; 48 49 // This function converts a raw AAC frame into an AAC frame with an ADTS 50 // header. On success, the function returns true and stores the converted data 51 // in the buffer. The function returns false on failure and leaves the buffer 52 // unchanged. 53 bool ConvertEsdsToADTS(std::vector<uint8>* buffer) const; 54 55#if defined(OS_ANDROID) 56 // Returns the codec specific data needed by android MediaCodec. 57 std::vector<uint8> codec_specific_data() const { 58 return codec_specific_data_; 59 } 60#endif 61 62 private: 63 bool SkipDecoderGASpecificConfig(BitReader* bit_reader) const; 64 bool SkipErrorSpecificConfig() const; 65 bool SkipGASpecificConfig(BitReader* bit_reader) const; 66 67 // The following variables store the AAC specific configuration information 68 // that are used to generate the ADTS header. 69 uint8 profile_; 70 uint8 frequency_index_; 71 uint8 channel_config_; 72 73#if defined(OS_ANDROID) 74 // The codec specific data needed by the android MediaCodec. 75 std::vector<uint8> codec_specific_data_; 76#endif 77 78 // The following variables store audio configuration information that 79 // can be used by Chromium. They are based on the AAC specific 80 // configuration but can be overridden by extensions in elementary 81 // stream descriptor. 82 int frequency_; 83 int extension_frequency_; 84 ChannelLayout channel_layout_; 85}; 86 87} // namespace mp4 88 89} // namespace media 90 91#endif // MEDIA_FORMATS_MP4_AAC_H_ 92