• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 #ifndef AUDIO_CAPABILITIES_H_
18 
19 #define AUDIO_CAPABILITIES_H_
20 
21 #include <media/CodecCapabilitiesUtils.h>
22 #include <media/stagefright/foundation/AMessage.h>
23 
24 #include <system/audio.h>
25 
26 #include <utils/StrongPointer.h>
27 
28 namespace android {
29 
30 struct AudioCapabilities {
31     /**
32      * Create AudioCapabilities.
33      */
34     static std::shared_ptr<AudioCapabilities> Create(std::string mediaType,
35             std::vector<ProfileLevel> profLevs, const sp<AMessage> &format);
36 
37     /**
38      * Returns the range of supported bitrates in bits/second.
39      */
40     const Range<int32_t>& getBitrateRange() const;
41 
42     /**
43      * Returns the array of supported sample rates if the codec
44      * supports only discrete values. Otherwise, it returns an empty array.
45      * The array is sorted in ascending order.
46      */
47     const std::vector<int32_t>& getSupportedSampleRates() const;
48 
49     /**
50      * Returns the array of supported sample rate ranges.  The
51      * array is sorted in ascending order, and the ranges are
52      * distinct.
53      */
54     const std::vector<Range<int32_t>>& getSupportedSampleRateRanges() const;
55 
56     /**
57      * Returns the maximum number of input channels supported.
58      * The returned value should be between 1 and 255.
59      *
60      * Through {@link android.os.Build.VERSION_CODES#R}, this method indicated support
61      * for any number of input channels between 1 and this maximum value.
62      *
63      * As of {@link android.os.Build.VERSION_CODES#S},
64      * the implied lower limit of 1 channel is no longer valid.
65      * As of {@link android.os.Build.VERSION_CODES#S}, {@link #getMaxInputChannelCount} is
66      * superseded by {@link #getInputChannelCountRanges},
67      * which returns an array of ranges of channels.
68      * The {@link #getMaxInputChannelCount} method will return the highest value
69      * in the ranges returned by {@link #getInputChannelCountRanges}
70      */
71     int32_t getMaxInputChannelCount() const;
72 
73     /**
74      * Returns the minimum number of input channels supported.
75      * This is often 1, but does vary for certain mime types.
76      *
77      * This returns the lowest channel count in the ranges returned by
78      * {@link #getInputChannelCountRanges}.
79      */
80     int32_t getMinInputChannelCount() const;
81 
82     /**
83      * Returns an array of ranges representing the number of input channels supported.
84      * The codec supports any number of input channels within this range.
85      *
86      * This supersedes the {@link #getMaxInputChannelCount} method.
87      *
88      * For many codecs, this will be a single range [1..N], for some N.
89      *
90      * The returned array cannot be empty.
91      */
92     const std::vector<Range<int32_t>>& getInputChannelCountRanges() const;
93 
94     /**
95      * Query whether the sample rate is supported by the codec.
96      */
97     bool isSampleRateSupported(int32_t sampleRate);
98 
99     /* For internal use only. Not exposed as a public API */
100     void getDefaultFormat(sp<AMessage> &format);
101 
102     /* For internal use only. Not exposed as a public API */
103     bool supportsFormat(const sp<AMessage> &format);
104 
105 private:
106     static constexpr int32_t MAX_INPUT_CHANNEL_COUNT = 30;
107     static constexpr uint32_t MAX_NUM_CHANNELS = FCC_LIMIT;
108 
109     int mError;
110     std::string mMediaType;
111     std::vector<ProfileLevel> mProfileLevels;
112 
113     Range<int32_t> mBitrateRange;
114 
115     std::vector<int32_t> mSampleRates;
116     std::vector<Range<int32_t>> mSampleRateRanges;
117     std::vector<Range<int32_t>> mInputChannelRanges;
118 
119     /* no public constructor */
AudioCapabilitiesAudioCapabilities120     AudioCapabilities() {}
121     void init(std::string mediaType, std::vector<ProfileLevel> profLevs,
122             const sp<AMessage> &format);
123     void initWithPlatformLimits();
124     bool supports(std::optional<int32_t> sampleRate, std::optional<int32_t> inputChannels);
125     void limitSampleRates(std::vector<int32_t> rates);
126     void createDiscreteSampleRates();
127     void limitSampleRates(std::vector<Range<int32_t>> rateRanges);
128     void applyLevelLimits();
129     void applyLimits(const std::vector<Range<int32_t>> &inputChannels,
130             const std::optional<Range<int32_t>> &bitRates);
131     void parseFromInfo(const sp<AMessage> &format);
132 
133     friend struct CodecCapabilities;
134 };
135 
136 }  // namespace android
137 
138 #endif // AUDIO_CAPABILITIES_H_