Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Side by Side Diff: media/formats/mpeg/adts_header_parser.cc

Issue 2063443002: Return parsed sample frequency of ADTS header (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: SBR Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/mpeg/adts_header_parser.h" 5 #include "media/formats/mpeg/adts_header_parser.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "media/base/audio_codecs.h" 10 #include "media/base/audio_codecs.h"
(...skipping 11 matching lines...) Expand all
22 } 22 }
23 23
24 size_t ExtractAdtsChannelConfig(const uint8_t* adts_header) { 24 size_t ExtractAdtsChannelConfig(const uint8_t* adts_header) {
25 return (((adts_header[3] >> 6) & 0x3) | ((adts_header[2] & 0x1) << 2)); 25 return (((adts_header[3] >> 6) & 0x3) | ((adts_header[2] & 0x1) << 2));
26 } 26 }
27 27
28 } // namespace (anonymous) 28 } // namespace (anonymous)
29 29
30 bool ParseAdtsHeader(const uint8_t* adts_header, 30 bool ParseAdtsHeader(const uint8_t* adts_header,
31 bool is_sbr, 31 bool is_sbr,
32 AudioDecoderConfig* config) { 32 AudioDecoderConfig* config,
33 size_t* orig_sample_freq) {
33 DCHECK(adts_header); 34 DCHECK(adts_header);
35 DCHECK(orig_sample_freq);
34 36
35 size_t frequency_index = ExtractAdtsFrequencyIndex(adts_header); 37 size_t frequency_index = ExtractAdtsFrequencyIndex(adts_header);
36 if (frequency_index >= kADTSFrequencyTableSize) { 38 if (frequency_index >= kADTSFrequencyTableSize) {
37 // Frequency index 13 & 14 are reserved 39 // Frequency index 13 & 14 are reserved
38 // while 15 means that the frequency is explicitly written 40 // while 15 means that the frequency is explicitly written
39 // (not supported). 41 // (not supported).
40 return false; 42 return false;
41 } 43 }
42 44
43 size_t channel_configuration = ExtractAdtsChannelConfig(adts_header); 45 size_t channel_configuration = ExtractAdtsChannelConfig(adts_header);
44 if (channel_configuration == 0 || 46 if (channel_configuration == 0 ||
45 channel_configuration >= kADTSChannelLayoutTableSize) { 47 channel_configuration >= kADTSChannelLayoutTableSize) {
46 // TODO(damienv): Add support for inband channel configuration. 48 // TODO(damienv): Add support for inband channel configuration.
47 return false; 49 return false;
48 } 50 }
49 51
50 // TODO(damienv): support HE-AAC frequency doubling (SBR) 52 // TODO(damienv): support HE-AAC frequency doubling (SBR)
51 // based on the incoming ADTS profile. 53 // based on the incoming ADTS profile.
52 int samples_per_second = kADTSFrequencyTable[frequency_index]; 54 int samples_per_second = kADTSFrequencyTable[frequency_index];
53 int adts_profile = (adts_header[2] >> 6) & 0x3; 55 int adts_profile = (adts_header[2] >> 6) & 0x3;
54 56
55 // The following code is written according to ISO 14496 Part 3 Table 1.11 and 57 // The following code is written according to ISO 14496 Part 3 Table 1.11 and
56 // Table 1.22. (Table 1.11 refers to the capping to 48000, Table 1.22 refers 58 // Table 1.22. (Table 1.11 refers to the capping to 48000, Table 1.22 refers
57 // to SBR doubling the AAC sample rate.) 59 // to SBR doubling the AAC sample rate.)
58 // TODO(damienv) : Extend sample rate cap to 96kHz for Level 5 content. 60 // TODO(damienv) : Extend sample rate cap to 96kHz for Level 5 content.
59 int extended_samples_per_second = 61 int extended_samples_per_second =
60 is_sbr ? std::min(2 * samples_per_second, 48000) : samples_per_second; 62 is_sbr ? std::min(2 * samples_per_second, 48000) : samples_per_second;
63 *orig_sample_freq = samples_per_second;
61 64
62 // The following code is written according to ISO 14496 Part 3 Table 1.13 - 65 // The following code is written according to ISO 14496 Part 3 Table 1.13 -
63 // Syntax of AudioSpecificConfig. 66 // Syntax of AudioSpecificConfig.
64 uint16_t extra_data_int = static_cast<uint16_t>( 67 uint16_t extra_data_int = static_cast<uint16_t>(
65 // Note: adts_profile is in the range [0,3], since the ADTS header only 68 // Note: adts_profile is in the range [0,3], since the ADTS header only
66 // allows two bits for its value. 69 // allows two bits for its value.
67 ((adts_profile + 1) << 11) + 70 ((adts_profile + 1) << 11) +
68 // frequency_index is [0..13], per early out above. 71 // frequency_index is [0..13], per early out above.
69 (frequency_index << 7) + 72 (frequency_index << 7) +
70 // channel_configuration is [0..7], per early out above. 73 // channel_configuration is [0..7], per early out above.
71 (channel_configuration << 3)); 74 (channel_configuration << 3));
72 std::vector<uint8_t> extra_data; 75 std::vector<uint8_t> extra_data;
73 extra_data.push_back(static_cast<uint8_t>(extra_data_int >> 8)); 76 extra_data.push_back(static_cast<uint8_t>(extra_data_int >> 8));
74 extra_data.push_back(static_cast<uint8_t>(extra_data_int & 0xff)); 77 extra_data.push_back(static_cast<uint8_t>(extra_data_int & 0xff));
75 78
76 DCHECK(config); 79 DCHECK(config);
77 *config = AudioDecoderConfig(kCodecAAC, kSampleFormatS16, 80 *config = AudioDecoderConfig(kCodecAAC, kSampleFormatS16,
78 kADTSChannelLayoutTable[channel_configuration], 81 kADTSChannelLayoutTable[channel_configuration],
79 extended_samples_per_second, extra_data, 82 extended_samples_per_second, extra_data,
80 Unencrypted()); 83 Unencrypted());
81 84
82 return true; 85 return true;
83 } 86 }
84 87
85 } // namespace media 88 } // namespace media
OLDNEW
« media/formats/mp2t/es_parser_adts_unittest.cc ('K') | « media/formats/mpeg/adts_header_parser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698