xref: /aosp_15_r20/frameworks/av/media/libmedia/include/media/EncoderCapabilities.h (revision ec779b8e0859a360c3d303172224686826e6e0e1)
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 ENCODER_CAPABILITIES_H_
18 
19 #define ENCODER_CAPABILITIES_H_
20 
21 #include <media/CodecCapabilitiesUtils.h>
22 #include <media/stagefright/foundation/AMessage.h>
23 
24 #include <utils/StrongPointer.h>
25 
26 namespace android {
27 
28 /**
29  * A class that supports querying the encoding capabilities of a codec.
30  */
31 struct EncoderCapabilities {
32     /**
33     * Returns the supported range of quality values.
34     *
35     * Quality is implementation-specific. As a general rule, a higher quality
36     * setting results in a better image quality and a lower compression ratio.
37     */
38     const Range<int>& getQualityRange();
39 
40     /**
41      * Returns the supported range of encoder complexity values.
42      * <p>
43      * Some codecs may support multiple complexity levels, where higher
44      * complexity values use more encoder tools (e.g. perform more
45      * intensive calculations) to improve the quality or the compression
46      * ratio.  Use a lower value to save power and/or time.
47      */
48     const Range<int>& getComplexityRange();
49 
50     /** Constant quality mode */
51     inline static constexpr int BITRATE_MODE_CQ = 0;
52     /** Variable bitrate mode */
53     inline static constexpr int BITRATE_MODE_VBR = 1;
54     /** Constant bitrate mode */
55     inline static constexpr int BITRATE_MODE_CBR = 2;
56     /** Constant bitrate mode with frame drops */
57     inline static constexpr int BITRATE_MODE_CBR_FD =  3;
58 
59     /**
60      * Query whether a bitrate mode is supported.
61      */
62     bool isBitrateModeSupported(int mode);
63 
64     /** @hide */
65     static std::shared_ptr<EncoderCapabilities> Create(std::string mediaType,
66             std::vector<ProfileLevel> profLevs, const sp<AMessage> &format);
67 
68     /** @hide */
69     void getDefaultFormat(sp<AMessage> &format);
70 
71     /** @hide */
72     bool supportsFormat(const sp<AMessage> &format);
73 
74 private:
75     inline static const Feature sBitrateModes[] = {
76         Feature("VBR", BITRATE_MODE_VBR, true),
77         Feature("CBR", BITRATE_MODE_CBR, false),
78         Feature("CQ",  BITRATE_MODE_CQ,  false),
79         Feature("CBR-FD", BITRATE_MODE_CBR_FD, false)
80     };
81     static int ParseBitrateMode(std::string mode);
82 
83     std::string mMediaType;
84     std::vector<ProfileLevel> mProfileLevels;
85 
86     Range<int> mQualityRange;
87     Range<int> mComplexityRange;
88     int mBitControl;
89     int mDefaultComplexity;
90     int mDefaultQuality;
91     std::string mQualityScale;
92 
93     /* no public constructor */
EncoderCapabilitiesEncoderCapabilities94     EncoderCapabilities() {}
95     void init(std::string mediaType, std::vector<ProfileLevel> profLevs,
96             const sp<AMessage> &format);
97     void applyLevelLimits();
98     void parseFromInfo(const sp<AMessage> &format);
99     bool supports(std::optional<int> complexity, std::optional<int> quality,
100             std::optional<int> profile);
101 };
102 
103 }  // namespace android
104 
105 #endif // ENCODER_CAPABILITIES_H_