| 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" |
| 11 #include "media/formats/mp4/rcheck.h" | 11 #include "media/formats/mp4/rcheck.h" |
| 12 #include "media/formats/mpeg/adts_constants.h" | 12 #include "media/formats/mpeg/adts_constants.h" |
| 13 | 13 |
| 14 namespace media { | 14 namespace media { |
| 15 namespace mp4 { | 15 namespace mp4 { |
| 16 | 16 |
| 17 AAC::AAC() | 17 AAC::AAC() |
| 18 : profile_(0), frequency_index_(0), channel_config_(0), frequency_(0), | 18 : profile_(0), frequency_index_(0), channel_config_(0), frequency_(0), |
| 19 extension_frequency_(0), channel_layout_(CHANNEL_LAYOUT_UNSUPPORTED) { | 19 extension_frequency_(0), channel_layout_(CHANNEL_LAYOUT_UNSUPPORTED) { |
| 20 } | 20 } |
| 21 | 21 |
| 22 AAC::~AAC() { | 22 AAC::~AAC() { |
| 23 } | 23 } |
| 24 | 24 |
| 25 bool AAC::Parse(const std::vector<uint8>& data, | 25 bool AAC::Parse(const std::vector<uint8_t>& data, |
| 26 const scoped_refptr<MediaLog>& media_log) { | 26 const scoped_refptr<MediaLog>& media_log) { |
| 27 #if defined(OS_ANDROID) | 27 #if defined(OS_ANDROID) |
| 28 codec_specific_data_ = data; | 28 codec_specific_data_ = data; |
| 29 #endif | 29 #endif |
| 30 if (data.empty()) | 30 if (data.empty()) |
| 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_t extension_type = 0; |
| 35 bool ps_present = false; | 35 bool ps_present = false; |
| 36 uint8 extension_frequency_index = 0xff; | 36 uint8_t 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 consider whether ISO 14496-3:2009 needs | 41 // TODO(msu.koo): Need to consider whether ISO 14496-3:2009 needs |
| 42 // to be reflected instead of ISO 14496-3:2005. | 42 // to be reflected instead of ISO 14496-3:2005. |
| 43 // https://crbug.com/532281 | 43 // https://crbug.com/532281 |
| 44 | 44 |
| 45 // The following code is written according to ISO 14496-3:2005 Table 1.13 - | 45 // The following code is written according to ISO 14496-3:2005 Table 1.13 - |
| 46 // Syntax of AudioSpecificConfig. | 46 // Syntax of AudioSpecificConfig. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 61 RCHECK(reader.ReadBits(24, &extension_frequency_)); | 61 RCHECK(reader.ReadBits(24, &extension_frequency_)); |
| 62 RCHECK(reader.ReadBits(5, &profile_)); | 62 RCHECK(reader.ReadBits(5, &profile_)); |
| 63 } | 63 } |
| 64 | 64 |
| 65 RCHECK(SkipDecoderGASpecificConfig(&reader)); | 65 RCHECK(SkipDecoderGASpecificConfig(&reader)); |
| 66 RCHECK(SkipErrorSpecificConfig()); | 66 RCHECK(SkipErrorSpecificConfig()); |
| 67 | 67 |
| 68 // Read extension configuration again | 68 // Read extension configuration again |
| 69 // Note: The check for 16 available bits comes from the AAC spec. | 69 // Note: The check for 16 available bits comes from the AAC spec. |
| 70 if (extension_type != 5 && reader.bits_available() >= 16) { | 70 if (extension_type != 5 && reader.bits_available() >= 16) { |
| 71 uint16 sync_extension_type; | 71 uint16_t sync_extension_type; |
| 72 uint8 sbr_present_flag; | 72 uint8_t sbr_present_flag; |
| 73 uint8 ps_present_flag; | 73 uint8_t ps_present_flag; |
| 74 | 74 |
| 75 if (reader.ReadBits(11, &sync_extension_type) && | 75 if (reader.ReadBits(11, &sync_extension_type) && |
| 76 sync_extension_type == 0x2b7) { | 76 sync_extension_type == 0x2b7) { |
| 77 if (reader.ReadBits(5, &extension_type) && extension_type == 5) { | 77 if (reader.ReadBits(5, &extension_type) && extension_type == 5) { |
| 78 RCHECK(reader.ReadBits(1, &sbr_present_flag)); | 78 RCHECK(reader.ReadBits(1, &sbr_present_flag)); |
| 79 | 79 |
| 80 if (sbr_present_flag) { | 80 if (sbr_present_flag) { |
| 81 RCHECK(reader.ReadBits(4, &extension_frequency_index)); | 81 RCHECK(reader.ReadBits(4, &extension_frequency_index)); |
| 82 | 82 |
| 83 if (extension_frequency_index == 0xf) | 83 if (extension_frequency_index == 0xf) |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 ChannelLayout AAC::GetChannelLayout(bool sbr_in_mimetype) const { | 171 ChannelLayout AAC::GetChannelLayout(bool sbr_in_mimetype) const { |
| 172 // Check for implicit signalling of HE-AAC and indicate stereo output | 172 // Check for implicit signalling of HE-AAC and indicate stereo output |
| 173 // if the mono channel configuration is signalled. | 173 // if the mono channel configuration is signalled. |
| 174 // See ISO 14496-3:2005 Section 1.6.5.3 for details about this special casing. | 174 // See ISO 14496-3:2005 Section 1.6.5.3 for details about this special casing. |
| 175 if (sbr_in_mimetype && channel_config_ == 1) | 175 if (sbr_in_mimetype && channel_config_ == 1) |
| 176 return CHANNEL_LAYOUT_STEREO; | 176 return CHANNEL_LAYOUT_STEREO; |
| 177 | 177 |
| 178 return channel_layout_; | 178 return channel_layout_; |
| 179 } | 179 } |
| 180 | 180 |
| 181 bool AAC::ConvertEsdsToADTS(std::vector<uint8>* buffer) const { | 181 bool AAC::ConvertEsdsToADTS(std::vector<uint8_t>* buffer) const { |
| 182 size_t size = buffer->size() + kADTSHeaderMinSize; | 182 size_t size = buffer->size() + kADTSHeaderMinSize; |
| 183 | 183 |
| 184 DCHECK(profile_ >= 1 && profile_ <= 4 && frequency_index_ != 0xf && | 184 DCHECK(profile_ >= 1 && profile_ <= 4 && frequency_index_ != 0xf && |
| 185 channel_config_ <= 7); | 185 channel_config_ <= 7); |
| 186 | 186 |
| 187 // ADTS header uses 13 bits for packet size. | 187 // ADTS header uses 13 bits for packet size. |
| 188 if (size >= (1 << 13)) | 188 if (size >= (1 << 13)) |
| 189 return false; | 189 return false; |
| 190 | 190 |
| 191 std::vector<uint8>& adts = *buffer; | 191 std::vector<uint8_t>& adts = *buffer; |
| 192 | 192 |
| 193 adts.insert(buffer->begin(), kADTSHeaderMinSize, 0); | 193 adts.insert(buffer->begin(), kADTSHeaderMinSize, 0); |
| 194 adts[0] = 0xff; | 194 adts[0] = 0xff; |
| 195 adts[1] = 0xf1; | 195 adts[1] = 0xf1; |
| 196 adts[2] = ((profile_ - 1) << 6) + (frequency_index_ << 2) + | 196 adts[2] = ((profile_ - 1) << 6) + (frequency_index_ << 2) + |
| 197 (channel_config_ >> 2); | 197 (channel_config_ >> 2); |
| 198 adts[3] = static_cast<uint8>(((channel_config_ & 0x3) << 6) + (size >> 11)); | 198 adts[3] = static_cast<uint8_t>(((channel_config_ & 0x3) << 6) + (size >> 11)); |
| 199 adts[4] = static_cast<uint8>((size & 0x7ff) >> 3); | 199 adts[4] = static_cast<uint8_t>((size & 0x7ff) >> 3); |
| 200 adts[5] = ((size & 7) << 5) + 0x1f; | 200 adts[5] = ((size & 7) << 5) + 0x1f; |
| 201 adts[6] = 0xfc; | 201 adts[6] = 0xfc; |
| 202 | 202 |
| 203 return true; | 203 return true; |
| 204 } | 204 } |
| 205 | 205 |
| 206 // Currently this function only support GASpecificConfig defined in | 206 // Currently this function only support GASpecificConfig defined in |
| 207 // ISO 14496-3:2005 Table 4.1 - Syntax of GASpecificConfig() | 207 // ISO 14496-3:2005 Table 4.1 - Syntax of GASpecificConfig() |
| 208 bool AAC::SkipDecoderGASpecificConfig(BitReader* bit_reader) const { | 208 bool AAC::SkipDecoderGASpecificConfig(BitReader* bit_reader) const { |
| 209 switch (profile_) { | 209 switch (profile_) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 default: | 243 default: |
| 244 break; | 244 break; |
| 245 } | 245 } |
| 246 | 246 |
| 247 return true; | 247 return true; |
| 248 } | 248 } |
| 249 | 249 |
| 250 // The following code is written according to ISO 14496-3:2005 Table 4.1 - | 250 // The following code is written according to ISO 14496-3:2005 Table 4.1 - |
| 251 // GASpecificConfig. | 251 // GASpecificConfig. |
| 252 bool AAC::SkipGASpecificConfig(BitReader* bit_reader) const { | 252 bool AAC::SkipGASpecificConfig(BitReader* bit_reader) const { |
| 253 uint8 extension_flag = 0; | 253 uint8_t extension_flag = 0; |
| 254 uint8 depends_on_core_coder; | 254 uint8_t depends_on_core_coder; |
| 255 uint16 dummy; | 255 uint16_t dummy; |
| 256 | 256 |
| 257 RCHECK(bit_reader->ReadBits(1, &dummy)); // frameLengthFlag | 257 RCHECK(bit_reader->ReadBits(1, &dummy)); // frameLengthFlag |
| 258 RCHECK(bit_reader->ReadBits(1, &depends_on_core_coder)); | 258 RCHECK(bit_reader->ReadBits(1, &depends_on_core_coder)); |
| 259 if (depends_on_core_coder == 1) | 259 if (depends_on_core_coder == 1) |
| 260 RCHECK(bit_reader->ReadBits(14, &dummy)); // coreCoderDelay | 260 RCHECK(bit_reader->ReadBits(14, &dummy)); // coreCoderDelay |
| 261 | 261 |
| 262 RCHECK(bit_reader->ReadBits(1, &extension_flag)); | 262 RCHECK(bit_reader->ReadBits(1, &extension_flag)); |
| 263 RCHECK(channel_config_ != 0); | 263 RCHECK(channel_config_ != 0); |
| 264 | 264 |
| 265 if (profile_ == 6 || profile_ == 20) | 265 if (profile_ == 6 || profile_ == 20) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 277 | 277 |
| 278 RCHECK(bit_reader->ReadBits(1, &dummy)); // extensionFlag3 | 278 RCHECK(bit_reader->ReadBits(1, &dummy)); // extensionFlag3 |
| 279 } | 279 } |
| 280 | 280 |
| 281 return true; | 281 return true; |
| 282 } | 282 } |
| 283 | 283 |
| 284 } // namespace mp4 | 284 } // namespace mp4 |
| 285 | 285 |
| 286 } // namespace media | 286 } // namespace media |
| OLD | NEW |