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

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

Issue 2378443002: Fix MSE ADTS parsing on Android. (Closed)
Patch Set: Address comments. Created 4 years, 2 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
« no previous file with comments | « media/formats/mpeg/adts_header_parser.h ('k') | media/formats/mpeg/adts_stream_parser.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "media/formats/mpeg/adts_header_parser.h"
6
7 #include <algorithm>
8 #include <vector>
9 #include "base/logging.h"
10 #include "media/base/audio_codecs.h"
11 #include "media/base/audio_decoder_config.h"
12 #include "media/base/media_util.h"
13 #include "media/base/sample_format.h"
14 #include "media/formats/mpeg/adts_constants.h"
15
16 namespace media {
17
18 namespace {
19
20 size_t ExtractAdtsFrequencyIndex(const uint8_t* adts_header) {
21 return ((adts_header[2] >> 2) & 0xf);
22 }
23
24 size_t ExtractAdtsChannelConfig(const uint8_t* adts_header) {
25 return (((adts_header[3] >> 6) & 0x3) | ((adts_header[2] & 0x1) << 2));
26 }
27
28 } // namespace (anonymous)
29
30 bool ParseAdtsHeader(const uint8_t* adts_header,
31 bool is_sbr,
32 AudioDecoderConfig* config,
33 size_t* orig_sample_freq) {
34 DCHECK(adts_header);
35 DCHECK(orig_sample_freq);
36
37 size_t frequency_index = ExtractAdtsFrequencyIndex(adts_header);
38 if (frequency_index >= kADTSFrequencyTableSize) {
39 // Frequency index 13 & 14 are reserved
40 // while 15 means that the frequency is explicitly written
41 // (not supported).
42 return false;
43 }
44
45 size_t channel_configuration = ExtractAdtsChannelConfig(adts_header);
46 if (channel_configuration == 0 ||
47 channel_configuration >= kADTSChannelLayoutTableSize) {
48 // TODO(damienv): Add support for inband channel configuration.
49 return false;
50 }
51
52 // TODO(damienv): support HE-AAC frequency doubling (SBR)
53 // based on the incoming ADTS profile.
54 int samples_per_second = kADTSFrequencyTable[frequency_index];
55 int adts_profile = (adts_header[2] >> 6) & 0x3;
56
57 // The following code is written according to ISO 14496 Part 3 Table 1.11 and
58 // Table 1.22. (Table 1.11 refers to the capping to 48000, Table 1.22 refers
59 // to SBR doubling the AAC sample rate.)
60 // TODO(damienv) : Extend sample rate cap to 96kHz for Level 5 content.
61 int extended_samples_per_second =
62 is_sbr ? std::min(2 * samples_per_second, 48000) : samples_per_second;
63 *orig_sample_freq = samples_per_second;
64
65 // The following code is written according to ISO 14496 Part 3 Table 1.13 -
66 // Syntax of AudioSpecificConfig.
67 uint16_t extra_data_int = static_cast<uint16_t>(
68 // Note: adts_profile is in the range [0,3], since the ADTS header only
69 // allows two bits for its value.
70 ((adts_profile + 1) << 11) +
71 // frequency_index is [0..13], per early out above.
72 (frequency_index << 7) +
73 // channel_configuration is [0..7], per early out above.
74 (channel_configuration << 3));
75 std::vector<uint8_t> extra_data;
76 extra_data.push_back(static_cast<uint8_t>(extra_data_int >> 8));
77 extra_data.push_back(static_cast<uint8_t>(extra_data_int & 0xff));
78
79 DCHECK(config);
80 *config = AudioDecoderConfig(kCodecAAC, kSampleFormatS16,
81 kADTSChannelLayoutTable[channel_configuration],
82 extended_samples_per_second, extra_data,
83 Unencrypted());
84
85 return true;
86 }
87
88 } // namespace media
OLDNEW
« no previous file with comments | « media/formats/mpeg/adts_header_parser.h ('k') | media/formats/mpeg/adts_stream_parser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698