blob: dbbe9e81a5e3a3f2d53af6b37f6b811d2894fad1 [file] [log] [blame]
Songyue Han73d6d112024-06-05 17:39:06 +00001/*
2 * Copyright 2024, The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17//#define LOG_NDEBUG 0
18#define LOG_TAG "AudioCapabilities"
19
20#include <android-base/strings.h>
21#include <android-base/properties.h>
22
23#include <media/AudioCapabilities.h>
24#include <media/CodecCapabilities.h>
25#include <media/stagefright/MediaCodecConstants.h>
26
27namespace android {
28
Songyue Hanad936af2024-10-14 23:53:58 +000029const Range<int32_t>& AudioCapabilities::getBitrateRange() const {
Songyue Han73d6d112024-06-05 17:39:06 +000030 return mBitrateRange;
31}
32
Songyue Hanc07437e2024-11-08 07:43:06 +000033const std::vector<int32_t>& AudioCapabilities::getSupportedSampleRates() const {
Songyue Han73d6d112024-06-05 17:39:06 +000034 return mSampleRates;
35}
36
Songyue Hanc07437e2024-11-08 07:43:06 +000037const std::vector<Range<int32_t>>&
Songyue Han73d6d112024-06-05 17:39:06 +000038 AudioCapabilities::getSupportedSampleRateRanges() const {
39 return mSampleRateRanges;
40}
41
Songyue Hanc07437e2024-11-08 07:43:06 +000042int32_t AudioCapabilities::getMaxInputChannelCount() const {
43 int32_t overallMax = 0;
Songyue Han73d6d112024-06-05 17:39:06 +000044 for (int i = mInputChannelRanges.size() - 1; i >= 0; i--) {
Songyue Hanc07437e2024-11-08 07:43:06 +000045 int32_t lmax = mInputChannelRanges[i].upper();
Songyue Han73d6d112024-06-05 17:39:06 +000046 if (lmax > overallMax) {
47 overallMax = lmax;
48 }
49 }
50 return overallMax;
51}
52
Songyue Hanc07437e2024-11-08 07:43:06 +000053int32_t AudioCapabilities::getMinInputChannelCount() const {
54 int32_t overallMin = MAX_INPUT_CHANNEL_COUNT;
Songyue Han73d6d112024-06-05 17:39:06 +000055 for (int i = mInputChannelRanges.size() - 1; i >= 0; i--) {
Songyue Hanc07437e2024-11-08 07:43:06 +000056 int32_t lmin = mInputChannelRanges[i].lower();
Songyue Han73d6d112024-06-05 17:39:06 +000057 if (lmin < overallMin) {
58 overallMin = lmin;
59 }
60 }
61 return overallMin;
62}
63
Songyue Hanc07437e2024-11-08 07:43:06 +000064const std::vector<Range<int32_t>>&
Songyue Han73d6d112024-06-05 17:39:06 +000065 AudioCapabilities::getInputChannelCountRanges() const {
66 return mInputChannelRanges;
67}
68
69// static
70std::shared_ptr<AudioCapabilities> AudioCapabilities::Create(std::string mediaType,
71 std::vector<ProfileLevel> profLevs, const sp<AMessage> &format) {
72 std::shared_ptr<AudioCapabilities> caps(new AudioCapabilities());
73 caps->init(mediaType, profLevs, format);
74 return caps;
75}
76
77void AudioCapabilities::init(std::string mediaType, std::vector<ProfileLevel> profLevs,
78 const sp<AMessage> &format) {
79 mMediaType = mediaType;
80 mProfileLevels = profLevs;
Songyue Han1f93c942024-07-30 19:15:13 +000081 mError = 0;
Songyue Han73d6d112024-06-05 17:39:06 +000082
83 initWithPlatformLimits();
84 applyLevelLimits();
85 parseFromInfo(format);
86}
87
88void AudioCapabilities::initWithPlatformLimits() {
Songyue Hanc07437e2024-11-08 07:43:06 +000089 mBitrateRange = Range<int32_t>(0, INT32_MAX);
90 mInputChannelRanges.push_back(Range<int32_t>(1, MAX_INPUT_CHANNEL_COUNT));
Songyue Han73d6d112024-06-05 17:39:06 +000091
Songyue Hanc07437e2024-11-08 07:43:06 +000092 const int32_t minSampleRate = base::GetIntProperty("ro.mediacodec.min_sample_rate", 7350);
93 const int32_t maxSampleRate = base::GetIntProperty("ro.mediacodec.max_sample_rate", 192000);
94 mSampleRateRanges.push_back(Range<int32_t>(minSampleRate, maxSampleRate));
Songyue Han73d6d112024-06-05 17:39:06 +000095}
96
Songyue Hanc07437e2024-11-08 07:43:06 +000097bool AudioCapabilities::supports(std::optional<int32_t> sampleRate,
98 std::optional<int32_t> inputChannels) {
Songyue Han73d6d112024-06-05 17:39:06 +000099 // channels and sample rates are checked orthogonally
Songyue Han84ad37f2024-10-08 20:24:26 +0000100 if (inputChannels
Songyue Han73d6d112024-06-05 17:39:06 +0000101 && !std::any_of(mInputChannelRanges.begin(), mInputChannelRanges.end(),
Songyue Hanc07437e2024-11-08 07:43:06 +0000102 [inputChannels](const Range<int32_t> &a) {
103 return a.contains(inputChannels.value()); })) {
Songyue Han73d6d112024-06-05 17:39:06 +0000104 return false;
105 }
Songyue Han84ad37f2024-10-08 20:24:26 +0000106 if (sampleRate
Songyue Han73d6d112024-06-05 17:39:06 +0000107 && !std::any_of(mSampleRateRanges.begin(), mSampleRateRanges.end(),
Songyue Hanc07437e2024-11-08 07:43:06 +0000108 [sampleRate](const Range<int32_t> &a) { return a.contains(sampleRate.value()); })) {
Songyue Han73d6d112024-06-05 17:39:06 +0000109 return false;
110 }
111 return true;
112}
113
Songyue Hanc07437e2024-11-08 07:43:06 +0000114bool AudioCapabilities::isSampleRateSupported(int32_t sampleRate) {
115 return supports(std::make_optional<int32_t>(sampleRate), std::nullopt);
Songyue Han73d6d112024-06-05 17:39:06 +0000116}
117
Songyue Hanc07437e2024-11-08 07:43:06 +0000118void AudioCapabilities::limitSampleRates(std::vector<int32_t> rates) {
119 std::vector<Range<int32_t>> sampleRateRanges;
Songyue Han73d6d112024-06-05 17:39:06 +0000120 std::sort(rates.begin(), rates.end());
Songyue Hanc07437e2024-11-08 07:43:06 +0000121 for (int32_t rate : rates) {
122 if (supports(std::make_optional<int32_t>(rate), std::nullopt /* channels */)) {
123 sampleRateRanges.push_back(Range<int32_t>(rate, rate));
Songyue Han73d6d112024-06-05 17:39:06 +0000124 }
125 }
126 mSampleRateRanges = intersectSortedDistinctRanges(mSampleRateRanges, sampleRateRanges);
127 createDiscreteSampleRates();
128}
129
130void AudioCapabilities::createDiscreteSampleRates() {
131 mSampleRates.clear();
132 for (int i = 0; i < mSampleRateRanges.size(); i++) {
133 mSampleRates.push_back(mSampleRateRanges[i].lower());
134 }
135}
136
Songyue Hanc07437e2024-11-08 07:43:06 +0000137void AudioCapabilities::limitSampleRates(std::vector<Range<int32_t>> rateRanges) {
Songyue Han73d6d112024-06-05 17:39:06 +0000138 sortDistinctRanges(&rateRanges);
139 mSampleRateRanges = intersectSortedDistinctRanges(mSampleRateRanges, rateRanges);
140 // check if all values are discrete
Songyue Hanc07437e2024-11-08 07:43:06 +0000141 for (Range<int32_t> range: mSampleRateRanges) {
Songyue Han73d6d112024-06-05 17:39:06 +0000142 if (range.lower() != range.upper()) {
143 mSampleRates.clear();
144 return;
145 }
146 }
147 createDiscreteSampleRates();
148}
149
150void AudioCapabilities::applyLevelLimits() {
Songyue Hanc07437e2024-11-08 07:43:06 +0000151 std::vector<int32_t> sampleRates;
152 std::optional<Range<int32_t>> sampleRateRange;
153 std::optional<Range<int32_t>> bitRates;
154 int32_t maxChannels = MAX_INPUT_CHANNEL_COUNT;
Songyue Han73d6d112024-06-05 17:39:06 +0000155
156 // const char *mediaType = mMediaType.c_str();
157 if (base::EqualsIgnoreCase(mMediaType, MIMETYPE_AUDIO_MPEG)) {
158 sampleRates = {
159 8000, 11025, 12000,
160 16000, 22050, 24000,
161 32000, 44100, 48000 };
Songyue Hanc07437e2024-11-08 07:43:06 +0000162 bitRates = Range<int32_t>(8000, 320000);
Songyue Han73d6d112024-06-05 17:39:06 +0000163 maxChannels = 2;
164 } else if (base::EqualsIgnoreCase(mMediaType, MIMETYPE_AUDIO_AMR_NB)) {
165 sampleRates = { 8000 };
Songyue Hanc07437e2024-11-08 07:43:06 +0000166 bitRates = Range<int32_t>(4750, 12200);
Songyue Han73d6d112024-06-05 17:39:06 +0000167 maxChannels = 1;
168 } else if (base::EqualsIgnoreCase(mMediaType, MIMETYPE_AUDIO_AMR_WB)) {
169 sampleRates = { 16000 };
Songyue Hanc07437e2024-11-08 07:43:06 +0000170 bitRates = Range<int32_t>(6600, 23850);
Songyue Han73d6d112024-06-05 17:39:06 +0000171 maxChannels = 1;
172 } else if (base::EqualsIgnoreCase(mMediaType, MIMETYPE_AUDIO_AAC)) {
173 sampleRates = {
174 7350, 8000,
175 11025, 12000, 16000,
176 22050, 24000, 32000,
177 44100, 48000, 64000,
178 88200, 96000 };
Songyue Hanc07437e2024-11-08 07:43:06 +0000179 bitRates = Range<int32_t>(8000, 510000);
Songyue Han73d6d112024-06-05 17:39:06 +0000180 maxChannels = 48;
181 } else if (base::EqualsIgnoreCase(mMediaType, MIMETYPE_AUDIO_VORBIS)) {
Songyue Hanc07437e2024-11-08 07:43:06 +0000182 bitRates = Range<int32_t>(32000, 500000);
183 sampleRateRange = Range<int32_t>(8000, 192000);
Songyue Han73d6d112024-06-05 17:39:06 +0000184 maxChannels = 255;
185 } else if (base::EqualsIgnoreCase(mMediaType, MIMETYPE_AUDIO_OPUS)) {
Songyue Hanc07437e2024-11-08 07:43:06 +0000186 bitRates = Range<int32_t>(6000, 510000);
Songyue Han73d6d112024-06-05 17:39:06 +0000187 sampleRates = { 8000, 12000, 16000, 24000, 48000 };
188 maxChannels = 255;
189 } else if (base::EqualsIgnoreCase(mMediaType, MIMETYPE_AUDIO_RAW)) {
Songyue Hanc07437e2024-11-08 07:43:06 +0000190 sampleRateRange = Range<int32_t>(1, 192000);
191 bitRates = Range<int32_t>(1, 10000000);
Songyue Han73d6d112024-06-05 17:39:06 +0000192 maxChannels = MAX_NUM_CHANNELS;
193 } else if (base::EqualsIgnoreCase(mMediaType, MIMETYPE_AUDIO_FLAC)) {
Songyue Hanc07437e2024-11-08 07:43:06 +0000194 sampleRateRange = Range<int32_t>(1, 655350);
Songyue Han73d6d112024-06-05 17:39:06 +0000195 // lossless codec, so bitrate is ignored
196 maxChannels = 255;
197 } else if (base::EqualsIgnoreCase(mMediaType, MIMETYPE_AUDIO_G711_ALAW)
198 || base::EqualsIgnoreCase(mMediaType, MIMETYPE_AUDIO_G711_MLAW)) {
199 sampleRates = { 8000 };
Songyue Hanc07437e2024-11-08 07:43:06 +0000200 bitRates = Range<int32_t>(64000, 64000);
Songyue Han73d6d112024-06-05 17:39:06 +0000201 // platform allows multiple channels for this format
202 } else if (base::EqualsIgnoreCase(mMediaType, MIMETYPE_AUDIO_MSGSM)) {
203 sampleRates = { 8000 };
Songyue Hanc07437e2024-11-08 07:43:06 +0000204 bitRates = Range<int32_t>(13000, 13000);
Songyue Han73d6d112024-06-05 17:39:06 +0000205 maxChannels = 1;
206 } else if (base::EqualsIgnoreCase(mMediaType, MIMETYPE_AUDIO_AC3)) {
207 maxChannels = 6;
208 } else if (base::EqualsIgnoreCase(mMediaType, MIMETYPE_AUDIO_EAC3)) {
209 maxChannels = 16;
210 } else if (base::EqualsIgnoreCase(mMediaType, MIMETYPE_AUDIO_EAC3_JOC)) {
211 sampleRates = { 48000 };
Songyue Hanc07437e2024-11-08 07:43:06 +0000212 bitRates = Range<int32_t>(32000, 6144000);
Songyue Han73d6d112024-06-05 17:39:06 +0000213 maxChannels = 16;
214 } else if (base::EqualsIgnoreCase(mMediaType, MIMETYPE_AUDIO_AC4)) {
215 sampleRates = { 44100, 48000, 96000, 192000 };
Songyue Hanc07437e2024-11-08 07:43:06 +0000216 bitRates = Range<int32_t>(16000, 2688000);
Songyue Han73d6d112024-06-05 17:39:06 +0000217 maxChannels = 24;
218 } else if (base::EqualsIgnoreCase(mMediaType, MIMETYPE_AUDIO_DTS)) {
219 sampleRates = { 44100, 48000 };
Songyue Hanc07437e2024-11-08 07:43:06 +0000220 bitRates = Range<int32_t>(96000, 1524000);
Songyue Han73d6d112024-06-05 17:39:06 +0000221 maxChannels = 6;
222 } else if (base::EqualsIgnoreCase(mMediaType, MIMETYPE_AUDIO_DTS_HD)) {
223 for (ProfileLevel profileLevel: mProfileLevels) {
224 switch (profileLevel.mProfile) {
225 case DTS_HDProfileLBR:
226 sampleRates = { 22050, 24000, 44100, 48000 };
Songyue Hanc07437e2024-11-08 07:43:06 +0000227 bitRates = Range<int32_t>(32000, 768000);
Songyue Han73d6d112024-06-05 17:39:06 +0000228 break;
229 case DTS_HDProfileHRA:
230 case DTS_HDProfileMA:
231 sampleRates = { 44100, 48000, 88200, 96000, 176400, 192000 };
Songyue Hanc07437e2024-11-08 07:43:06 +0000232 bitRates = Range<int32_t>(96000, 24500000);
Songyue Han73d6d112024-06-05 17:39:06 +0000233 break;
234 default:
235 ALOGW("Unrecognized profile %d for %s", profileLevel.mProfile,
236 mMediaType.c_str());
237 mError |= ERROR_CAPABILITIES_UNRECOGNIZED;
238 sampleRates = { 44100, 48000, 88200, 96000, 176400, 192000 };
Songyue Hanc07437e2024-11-08 07:43:06 +0000239 bitRates = Range<int32_t>(96000, 24500000);
Songyue Han73d6d112024-06-05 17:39:06 +0000240 }
241 }
242 maxChannels = 8;
243 } else if (base::EqualsIgnoreCase(mMediaType, MIMETYPE_AUDIO_DTS_UHD)) {
244 for (ProfileLevel profileLevel: mProfileLevels) {
245 switch (profileLevel.mProfile) {
246 case DTS_UHDProfileP2:
247 sampleRates = { 48000 };
Songyue Hanc07437e2024-11-08 07:43:06 +0000248 bitRates = Range<int32_t>(96000, 768000);
Songyue Han73d6d112024-06-05 17:39:06 +0000249 maxChannels = 10;
250 break;
251 case DTS_UHDProfileP1:
252 sampleRates = { 44100, 48000, 88200, 96000, 176400, 192000 };
Songyue Hanc07437e2024-11-08 07:43:06 +0000253 bitRates = Range<int32_t>(96000, 24500000);
Songyue Han73d6d112024-06-05 17:39:06 +0000254 maxChannels = 32;
255 break;
256 default:
257 ALOGW("Unrecognized profile %d for %s", profileLevel.mProfile,
258 mMediaType.c_str());
259 mError |= ERROR_CAPABILITIES_UNRECOGNIZED;
260 sampleRates = { 44100, 48000, 88200, 96000, 176400, 192000 };
Songyue Hanc07437e2024-11-08 07:43:06 +0000261 bitRates = Range<int32_t>(96000, 24500000);
Songyue Han73d6d112024-06-05 17:39:06 +0000262 maxChannels = 32;
263 }
264 }
265 } else {
266 ALOGW("Unsupported mediaType %s", mMediaType.c_str());
267 mError |= ERROR_CAPABILITIES_UNSUPPORTED;
268 }
269
270 // restrict ranges
271 if (!sampleRates.empty()) {
272 limitSampleRates(sampleRates);
273 } else if (sampleRateRange) {
Songyue Hanc07437e2024-11-08 07:43:06 +0000274 std::vector<Range<int32_t>> rateRanges = { sampleRateRange.value() };
Songyue Han73d6d112024-06-05 17:39:06 +0000275 limitSampleRates(rateRanges);
276 }
277
Songyue Hanc07437e2024-11-08 07:43:06 +0000278 Range<int32_t> channelRange = Range<int32_t>(1, maxChannels);
279 std::vector<Range<int32_t>> inputChannels = { channelRange };
Songyue Han73d6d112024-06-05 17:39:06 +0000280 applyLimits(inputChannels, bitRates);
281}
282
283void AudioCapabilities::applyLimits(
Songyue Hanc07437e2024-11-08 07:43:06 +0000284 const std::vector<Range<int32_t>> &inputChannels,
Songyue Hanad936af2024-10-14 23:53:58 +0000285 const std::optional<Range<int32_t>> &bitRates) {
Songyue Han73d6d112024-06-05 17:39:06 +0000286 // clamp & make a local copy
Songyue Hanc07437e2024-11-08 07:43:06 +0000287 std::vector<Range<int32_t>> inputChannelsCopy(inputChannels.size());
Songyue Han73d6d112024-06-05 17:39:06 +0000288 for (int i = 0; i < inputChannels.size(); i++) {
Songyue Hanc07437e2024-11-08 07:43:06 +0000289 int32_t lower = inputChannels[i].clamp(1);
290 int32_t upper = inputChannels[i].clamp(MAX_INPUT_CHANNEL_COUNT);
291 inputChannelsCopy[i] = Range<int32_t>(lower, upper);
Songyue Han73d6d112024-06-05 17:39:06 +0000292 }
293
294 // sort, intersect with existing, & save channel list
295 sortDistinctRanges(&inputChannelsCopy);
296 mInputChannelRanges = intersectSortedDistinctRanges(inputChannelsCopy, mInputChannelRanges);
297
298 if (bitRates) {
299 mBitrateRange = mBitrateRange.intersect(bitRates.value());
300 }
301}
302
303void AudioCapabilities::parseFromInfo(const sp<AMessage> &format) {
Songyue Hanc07437e2024-11-08 07:43:06 +0000304 int32_t maxInputChannels = MAX_INPUT_CHANNEL_COUNT;
305 std::vector<Range<int32_t>> channels = { Range<int32_t>(1, maxInputChannels) };
Songyue Hanad936af2024-10-14 23:53:58 +0000306 std::optional<Range<int32_t>> bitRates = POSITIVE_INT32;
Songyue Han73d6d112024-06-05 17:39:06 +0000307
308 AString rateAString;
309 if (format->findString("sample-rate-ranges", &rateAString)) {
310 std::vector<std::string> rateStrings = base::Split(std::string(rateAString.c_str()), ",");
Songyue Hanc07437e2024-11-08 07:43:06 +0000311 std::vector<Range<int32_t>> rateRanges;
Songyue Han73d6d112024-06-05 17:39:06 +0000312 for (std::string rateString : rateStrings) {
Songyue Hanc07437e2024-11-08 07:43:06 +0000313 std::optional<Range<int32_t>> rateRange = Range<int32_t>::Parse(rateString);
Songyue Han73d6d112024-06-05 17:39:06 +0000314 if (!rateRange) {
315 continue;
316 }
317 rateRanges.push_back(rateRange.value());
318 }
319 limitSampleRates(rateRanges);
320 }
321
322 // we will prefer channel-ranges over max-channel-count
323 AString valueStr;
324 if (format->findString("channel-ranges", &valueStr)) {
325 std::vector<std::string> channelStrings = base::Split(std::string(valueStr.c_str()), ",");
Songyue Hanc07437e2024-11-08 07:43:06 +0000326 std::vector<Range<int32_t>> channelRanges;
Songyue Han73d6d112024-06-05 17:39:06 +0000327 for (std::string channelString : channelStrings) {
Songyue Hanc07437e2024-11-08 07:43:06 +0000328 std::optional<Range<int32_t>> channelRange = Range<int32_t>::Parse(channelString);
Songyue Han73d6d112024-06-05 17:39:06 +0000329 if (!channelRange) {
330 continue;
331 }
332 channelRanges.push_back(channelRange.value());
333 }
334 channels = channelRanges;
335 } else if (format->findString("channel-range", &valueStr)) {
Songyue Hanc07437e2024-11-08 07:43:06 +0000336 std::optional<Range<int32_t>> oneRange
337 = Range<int32_t>::Parse(std::string(valueStr.c_str()));
Songyue Han73d6d112024-06-05 17:39:06 +0000338 if (oneRange) {
339 channels = { oneRange.value() };
340 }
341 } else if (format->findString("max-channel-count", &valueStr)) {
342 maxInputChannels = std::atoi(valueStr.c_str());
343 if (maxInputChannels == 0) {
Songyue Hanc07437e2024-11-08 07:43:06 +0000344 channels = { Range<int32_t>(0, 0) };
Songyue Han73d6d112024-06-05 17:39:06 +0000345 } else {
Songyue Hanc07437e2024-11-08 07:43:06 +0000346 channels = { Range<int32_t>(1, maxInputChannels) };
Songyue Han73d6d112024-06-05 17:39:06 +0000347 }
348 } else if ((mError & ERROR_CAPABILITIES_UNSUPPORTED) != 0) {
349 maxInputChannels = 0;
Songyue Hanc07437e2024-11-08 07:43:06 +0000350 channels = { Range<int32_t>(0, 0) };
Songyue Han73d6d112024-06-05 17:39:06 +0000351 }
352
353 if (format->findString("bitrate-range", &valueStr)) {
Songyue Hanc07437e2024-11-08 07:43:06 +0000354 std::optional<Range<int32_t>> parsedBitrate = Range<int32_t>::Parse(valueStr.c_str());
Songyue Han73d6d112024-06-05 17:39:06 +0000355 if (parsedBitrate) {
356 bitRates = bitRates.value().intersect(parsedBitrate.value());
357 }
358 }
359
360 applyLimits(channels, bitRates);
361}
362
363void AudioCapabilities::getDefaultFormat(sp<AMessage> &format) {
364 // report settings that have only a single choice
365 if (mBitrateRange.lower() == mBitrateRange.upper()) {
366 format->setInt32(KEY_BIT_RATE, mBitrateRange.lower());
367 }
368 if (getMaxInputChannelCount() == 1) {
369 // mono-only format
370 format->setInt32(KEY_CHANNEL_COUNT, 1);
371 }
372 if (!mSampleRates.empty() && mSampleRates.size() == 1) {
373 format->setInt32(KEY_SAMPLE_RATE, mSampleRates[0]);
374 }
375}
376
377bool AudioCapabilities::supportsFormat(const sp<AMessage> &format) {
Songyue Han84ad37f2024-10-08 20:24:26 +0000378 int32_t sampleRateValue;
Songyue Hanc07437e2024-11-08 07:43:06 +0000379 std::optional<int32_t> sampleRate = format->findInt32(KEY_SAMPLE_RATE, &sampleRateValue)
380 ? std::make_optional<int32_t>(sampleRateValue) : std::nullopt;
Songyue Han84ad37f2024-10-08 20:24:26 +0000381 int32_t channelsValue;
Songyue Hanc07437e2024-11-08 07:43:06 +0000382 std::optional<int32_t> channels = format->findInt32(KEY_CHANNEL_COUNT, &channelsValue)
383 ? std::make_optional<int32_t>(channelsValue) : std::nullopt;
Songyue Han73d6d112024-06-05 17:39:06 +0000384
385 if (!supports(sampleRate, channels)) {
386 return false;
387 }
388
389 if (!CodecCapabilities::SupportsBitrate(mBitrateRange, format)) {
390 return false;
391 }
392
393 // nothing to do for:
394 // KEY_CHANNEL_MASK: codecs don't get this
395 // KEY_IS_ADTS: required feature for all AAC decoders
396 return true;
397}
398
399} // namespace android