blob: ff7051f17b6192ebdaaede9155949beb427cc261 [file] [log] [blame]
Ray Essick1831f7b2021-03-15 16:10:51 -07001/*
2 * Copyright 2021, 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 _LIBMEDIAFORMATSHAPER_CODECPROPERTIES_H_
18#define _LIBMEDIAFORMATSHAPER_CODECPROPERTIES_H_
19
20#include <map>
21#include <mutex>
22#include <string>
23
Ray Essick244aaa52021-04-05 14:47:02 -070024#include <inttypes.h>
25
Ray Essick1831f7b2021-03-15 16:10:51 -070026#include <utils/RefBase.h>
27
28namespace android {
29namespace mediaformatshaper {
30
31class CodecProperties {
32
33 public:
34 CodecProperties(std::string name, std::string mediaType);
35
Ray Essick970f1c82021-03-25 13:37:45 -070036 // seed the codec with some preconfigured values
37 // (e.g. mediaType-granularity defaults)
38 // runs from the constructor
39 void Seed();
40 void Finish();
41
Ray Essick1831f7b2021-03-15 16:10:51 -070042 std::string getName();
43 std::string getMediaType();
44
45 // establish a mapping from standard 'key' to non-standard 'value' in the namespace 'kind'
46 void setMapping(std::string kind, std::string key, std::string value);
47
48 // translate from from standard key to non-standard key
49 // return original standard key if there is no mapping
50 std::string getMapping(std::string key, std::string kind);
51
52 // returns an array of char *, which are paired "from" and "to" values
53 // for mapping (or unmapping). it's always expressed as from->to
54 // and 'reverse' describes which strings are to be on which side.
55 const char **getMappings(std::string kind, bool reverse);
56
Ray Essick970f1c82021-03-25 13:37:45 -070057 // keep a map of all features and their parameters
58 void setFeatureValue(std::string key, int32_t value);
59 bool getFeatureValue(std::string key, int32_t *valuep);
Ray Essick1831f7b2021-03-15 16:10:51 -070060
Ray Essicka727ef92021-03-29 13:35:02 -070061 // keep a map of all tunings and their parameters
62 void setTuningValue(std::string key, std::string value);
63 bool getTuningValue(std::string key, std::string &value);
64
Ray Essick1831f7b2021-03-15 16:10:51 -070065 // does the codec support the Android S minimum quality rules
66 void setSupportedMinimumQuality(int vmaf);
67 int supportedMinimumQuality();
68
69 // qp max bound used to compensate when SupportedMinimumQuality == 0
70 // 0 == let a system default handle it
71 void setTargetQpMax(int qpmax);
72 int targetQpMax();
73
74 // target bits-per-pixel (per second) for encoding operations.
75 // This is used to calculate a minimum bitrate for any particular resolution.
76 // A 1080p (1920*1080 = 2073600 pixels) to be encoded at 5Mbps has a bpp == 2.41
77 void setBpp(double bpp) { mBpp = bpp;}
Ray Essick244aaa52021-04-05 14:47:02 -070078 double getBpp(int32_t width, int32_t height);
Ray Essick1831f7b2021-03-15 16:10:51 -070079
80 // Does this codec support QP bounding
81 // The getMapping() methods provide any needed mapping to non-standard keys.
82 void setSupportsQp(bool supported) { mSupportsQp = supported;}
83 bool supportsQp() { return mSupportsQp;}
84
85 int supportedApi();
86
87 // a codec is not usable until it has been registered with its
88 // name/mediaType.
89 bool isRegistered() { return mIsRegistered;}
90 void setRegistered(bool registered) { mIsRegistered = registered;}
91
92 private:
93 std::string mName;
94 std::string mMediaType;
95 int mApi = 0;
96 int mMinimumQuality = 0;
Ray Essick244aaa52021-04-05 14:47:02 -070097 int mTargetQpMax = INT32_MAX;
Ray Essick1831f7b2021-03-15 16:10:51 -070098 bool mSupportsQp = false;
99 double mBpp = 0.0;
100
Ray Essick244aaa52021-04-05 14:47:02 -0700101 // allow different target bits-per-pixel based on resolution
102 // similar to codec 'performance points'
103 // uses 'next largest' (by pixel count) point as minimum bpp
104 struct bpp_point {
105 struct bpp_point *next;
106 int32_t pixels;
107 int32_t width, height;
108 double bpp;
109 };
110 struct bpp_point *mBppPoints = nullptr;
111 bool bppPoint(std::string resolution, std::string value);
112
Ray Essick1831f7b2021-03-15 16:10:51 -0700113 std::mutex mMappingLock;
114 // XXX figure out why I'm having problems getting compiler to like GUARDED_BY
115 std::map<std::string, std::string> mMappings /*GUARDED_BY(mMappingLock)*/ ;
Ray Essick970f1c82021-03-25 13:37:45 -0700116
117 std::map<std::string, int32_t> mFeatures /*GUARDED_BY(mMappingLock)*/ ;
Ray Essicka727ef92021-03-29 13:35:02 -0700118 std::map<std::string, std::string> mTunings /*GUARDED_BY(mMappingLock)*/ ;
119
120 // Seed() and Finish() use this as the underlying implementation
121 void addMediaDefaults(bool overrideable);
Ray Essick1831f7b2021-03-15 16:10:51 -0700122
123 bool mIsRegistered = false;
124
Ray Essick970f1c82021-03-25 13:37:45 -0700125 // debugging of what's in the mapping dictionary
126 void showMappings();
127
Ray Essick1831f7b2021-03-15 16:10:51 -0700128 // DISALLOW_EVIL_CONSTRUCTORS(CodecProperties);
129};
130
131extern CodecProperties *findCodec(const char *codecName, const char *mediaType);
132extern CodecProperties *registerCodec(CodecProperties *codec, const char *codecName,
133 const char *mediaType);
134
135
136} // namespace mediaformatshaper
137} // namespace android
138
139#endif // _LIBMEDIAFORMATSHAPER_CODECPROPERTIES_H_