OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "media/formats/mp4/aac.h" | 5 #include "media/formats/mp4/aac.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "media/base/bit_reader.h" | 10 #include "media/base/bit_reader.h" |
(...skipping 20 matching lines...) Expand all Loading... | |
31 return false; | 31 return false; |
32 | 32 |
33 BitReader reader(&data[0], data.size()); | 33 BitReader reader(&data[0], data.size()); |
34 uint8 extension_type = 0; | 34 uint8 extension_type = 0; |
35 bool ps_present = false; | 35 bool ps_present = false; |
36 uint8 extension_frequency_index = 0xff; | 36 uint8 extension_frequency_index = 0xff; |
37 | 37 |
38 frequency_ = 0; | 38 frequency_ = 0; |
39 extension_frequency_ = 0; | 39 extension_frequency_ = 0; |
40 | 40 |
41 // TODO(msu.koo): Need to update comments after checking which version of | |
42 // ISO 14496-3 this implementation is according to. Also need to reflect | |
43 // ISO 14496-3-2009 if ISO 14496-3-2005 was reflected here. | |
44 // http://crbug.com/532281 | |
wolenetz
2015/09/16 19:39:19
nit: s/http:/https:/
msu.koo
2015/09/17 02:49:26
Done.
| |
45 | |
41 // The following code is written according to ISO 14496 Part 3 Table 1.13 - | 46 // The following code is written according to ISO 14496 Part 3 Table 1.13 - |
42 // Syntax of AudioSpecificConfig. | 47 // Syntax of AudioSpecificConfig. |
43 | 48 |
44 // Read base configuration | 49 // Read base configuration |
45 RCHECK(reader.ReadBits(5, &profile_)); | 50 RCHECK(reader.ReadBits(5, &profile_)); |
46 RCHECK(reader.ReadBits(4, &frequency_index_)); | 51 RCHECK(reader.ReadBits(4, &frequency_index_)); |
47 if (frequency_index_ == 0xf) | 52 if (frequency_index_ == 0xf) |
48 RCHECK(reader.ReadBits(24, &frequency_)); | 53 RCHECK(reader.ReadBits(24, &frequency_)); |
49 RCHECK(reader.ReadBits(4, &channel_config_)); | 54 RCHECK(reader.ReadBits(4, &channel_config_)); |
50 | 55 |
51 // Read extension configuration. | 56 // Read extension configuration. |
52 if (profile_ == 5 || profile_ == 29) { | 57 if (profile_ == 5 || profile_ == 29) { |
53 ps_present = (profile_ == 29); | 58 ps_present = (profile_ == 29); |
54 extension_type = 5; | 59 extension_type = 5; |
55 RCHECK(reader.ReadBits(4, &extension_frequency_index)); | 60 RCHECK(reader.ReadBits(4, &extension_frequency_index)); |
56 if (extension_frequency_index == 0xf) | 61 if (extension_frequency_index == 0xf) |
57 RCHECK(reader.ReadBits(24, &extension_frequency_)); | 62 RCHECK(reader.ReadBits(24, &extension_frequency_)); |
58 RCHECK(reader.ReadBits(5, &profile_)); | 63 RCHECK(reader.ReadBits(5, &profile_)); |
59 } | 64 } |
60 | 65 |
61 MEDIA_LOG(INFO, media_log) << "Audio codec: mp4a.40." << std::hex | |
62 << static_cast<int>(profile_); | |
63 | |
64 RCHECK(SkipDecoderGASpecificConfig(&reader)); | 66 RCHECK(SkipDecoderGASpecificConfig(&reader)); |
65 RCHECK(SkipErrorSpecificConfig()); | 67 RCHECK(SkipErrorSpecificConfig()); |
66 | 68 |
67 // Read extension configuration again | 69 // Read extension configuration again |
68 // Note: The check for 16 available bits comes from the AAC spec. | 70 // Note: The check for 16 available bits comes from the AAC spec. |
69 if (extension_type != 5 && reader.bits_available() >= 16) { | 71 if (extension_type != 5 && reader.bits_available() >= 16) { |
70 uint16 sync_extension_type; | 72 uint16 sync_extension_type; |
71 uint8 sbr_present_flag; | 73 uint8 sbr_present_flag; |
72 uint8 ps_present_flag; | 74 uint8 ps_present_flag; |
73 | 75 |
(...skipping 15 matching lines...) Expand all Loading... | |
89 RCHECK(reader.ReadBits(1, &ps_present_flag)); | 91 RCHECK(reader.ReadBits(1, &ps_present_flag)); |
90 ps_present = ps_present_flag != 0; | 92 ps_present = ps_present_flag != 0; |
91 } | 93 } |
92 } | 94 } |
93 } | 95 } |
94 } | 96 } |
95 } | 97 } |
96 } | 98 } |
97 | 99 |
98 if (frequency_ == 0) { | 100 if (frequency_ == 0) { |
99 RCHECK(frequency_index_ < kADTSFrequencyTableSize); | 101 if (frequency_index_ >= kADTSFrequencyTableSize) { |
102 MEDIA_LOG(ERROR, media_log) | |
103 << "Sampling Frequency Index(0x" | |
104 << std::hex << static_cast<int>(frequency_index_) | |
105 << ") is not supported. Please see ISO 14496-3-2005 Table 1.18 " | |
wolenetz
2015/09/16 19:39:19
nit: in 2005 version, it's not 1.18. similar ditto
msu.koo
2015/09/17 02:49:26
Done.
| |
106 << "for supported Sampling Frequencies."; | |
107 return false; | |
108 } | |
100 frequency_ = kADTSFrequencyTable[frequency_index_]; | 109 frequency_ = kADTSFrequencyTable[frequency_index_]; |
101 } | 110 } |
102 | 111 |
103 if (extension_frequency_ == 0 && extension_frequency_index != 0xff) { | 112 if (extension_frequency_ == 0 && extension_frequency_index != 0xff) { |
104 RCHECK(extension_frequency_index < kADTSFrequencyTableSize); | 113 if (extension_frequency_index >= kADTSFrequencyTableSize) { |
114 MEDIA_LOG(ERROR, media_log) | |
115 << "Extension Sampling Frequency Index(0x" | |
116 << std::hex << static_cast<int>(extension_frequency_index) | |
117 << ") is not supported. Please see ISO 14496-3-2005 Table 1.18 " | |
118 << "for supported Sampling Frequencies."; | |
119 return false; | |
120 } | |
105 extension_frequency_ = kADTSFrequencyTable[extension_frequency_index]; | 121 extension_frequency_ = kADTSFrequencyTable[extension_frequency_index]; |
106 } | 122 } |
107 | 123 |
108 // When Parametric Stereo is on, mono will be played as stereo. | 124 // When Parametric Stereo is on, mono will be played as stereo. |
109 if (ps_present && channel_config_ == 1) { | 125 if (ps_present && channel_config_ == 1) { |
110 channel_layout_ = CHANNEL_LAYOUT_STEREO; | 126 channel_layout_ = CHANNEL_LAYOUT_STEREO; |
111 } else { | 127 } else { |
112 RCHECK(channel_config_ < kADTSChannelLayoutTableSize); | 128 if (channel_config_ >= kADTSChannelLayoutTableSize) { |
129 MEDIA_LOG(ERROR, media_log) | |
130 << "Channel Configuration(" | |
131 << static_cast<int>(channel_config_) | |
132 << ") is not supported. Please see ISO 14496-3-2005 Table 1.19 " | |
133 << "for supported Channel Configurations."; | |
134 return false; | |
135 } | |
113 channel_layout_ = kADTSChannelLayoutTable[channel_config_]; | 136 channel_layout_ = kADTSChannelLayoutTable[channel_config_]; |
114 } | 137 } |
115 | 138 |
116 return frequency_ != 0 && channel_layout_ != CHANNEL_LAYOUT_NONE && | 139 if (profile_ < 1 || profile_ > 4) { |
117 profile_ >= 1 && profile_ <= 4; | 140 MEDIA_LOG(ERROR, media_log) |
141 << "Audio codec(mp4a.40." << static_cast<int>(profile_) | |
142 << ") is not supported. Please see ISO 14496-3-2005 Table 1.3 " | |
143 << "for Audio Profile Definitions."; | |
144 return false; | |
145 } | |
146 | |
147 MEDIA_LOG(INFO, media_log) | |
148 << "Audio codec: mp4a.40." << static_cast<int>(profile_) | |
149 << ". Sampling frequency: " << frequency_ << "Hz" | |
150 << ". Sampling frequency(Extension): " << extension_frequency_ << "Hz" | |
151 << ". Channel layout: " << channel_layout_ << "."; | |
152 | |
153 return true; | |
118 } | 154 } |
119 | 155 |
120 int AAC::GetOutputSamplesPerSecond(bool sbr_in_mimetype) const { | 156 int AAC::GetOutputSamplesPerSecond(bool sbr_in_mimetype) const { |
121 if (extension_frequency_ > 0) | 157 if (extension_frequency_ > 0) |
122 return extension_frequency_; | 158 return extension_frequency_; |
123 | 159 |
124 if (!sbr_in_mimetype) | 160 if (!sbr_in_mimetype) |
125 return frequency_; | 161 return frequency_; |
126 | 162 |
127 // The following code is written according to ISO 14496 Part 3 Table 1.11 and | 163 // The following code is written according to ISO 14496 Part 3 Table 1.11 and |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
241 | 277 |
242 RCHECK(bit_reader->ReadBits(1, &dummy)); // extensionFlag3 | 278 RCHECK(bit_reader->ReadBits(1, &dummy)); // extensionFlag3 |
243 } | 279 } |
244 | 280 |
245 return true; | 281 return true; |
246 } | 282 } |
247 | 283 |
248 } // namespace mp4 | 284 } // namespace mp4 |
249 | 285 |
250 } // namespace media | 286 } // namespace media |
OLD | NEW |