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