blob: cc241f4c065c7f02bcbe09ca09981f2d7fdd150f [file] [log] [blame]
Ray Essick970f1c82021-03-25 13:37:45 -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//#define LOG_NDEBUG 0
18#define LOG_TAG "CodecSeeding"
19#include <utils/Log.h>
20
21#include <string>
22
Ray Essick7b4e9d92021-04-20 16:48:00 -070023#include "CodecProperties.h"
Ray Essick970f1c82021-03-25 13:37:45 -070024
25namespace android {
26namespace mediaformatshaper {
27
28/*
Ray Essicka727ef92021-03-29 13:35:02 -070029 * a block of pre-loaded tunings for codecs.
30 *
31 * things the library seeds into the codecproperties based
Ray Essick970f1c82021-03-25 13:37:45 -070032 * on the mediaType.
33 * XXX: parsing from a file is likely better than embedding in code.
34 */
35typedef struct {
Ray Essicka727ef92021-03-29 13:35:02 -070036 bool overrideable;
Ray Essick970f1c82021-03-25 13:37:45 -070037 const char *key;
Ray Essicka727ef92021-03-29 13:35:02 -070038 const char *value;
39} preloadTuning_t;
Ray Essick970f1c82021-03-25 13:37:45 -070040
41typedef struct {
42 const char *mediaType;
Ray Essicka727ef92021-03-29 13:35:02 -070043 preloadTuning_t *features;
44} preloadTunings_t;
Ray Essick970f1c82021-03-25 13:37:45 -070045
46/*
Ray Essick8d9abe52021-05-05 15:38:55 -070047 * bpp == bits per pixel per second, for 30fps.
Ray Essick970f1c82021-03-25 13:37:45 -070048 */
49
Ray Essicka727ef92021-03-29 13:35:02 -070050static preloadTuning_t featuresAvc[] = {
Ray Essick981ddf82021-05-03 13:33:09 -070051 {true, "vq-target-bpp", "0"},
Ray Essick614d8da2021-04-27 11:35:00 -070052 {true, "vq-target-bpp-1080p", "1.90"},
53 {true, "vq-target-bpp-720p", "2.25"},
54 {true, "vq-target-bpp-540p", "2.65"},
Ray Essick244aaa52021-04-05 14:47:02 -070055 {true, "vq-target-bpp-480p", "3.00"},
Ray Essick981ddf82021-05-03 13:33:09 -070056 {true, "vq-target-qpmax", "-1"},
57 {true, "vq-target-qpmax-1080p", "45"},
58 {true, "vq-target-qpmax-720p", "43"},
59 {true, "vq-target-qpmax-540p", "42"},
60 {true, "vq-target-qpmax-480p", "38"},
Ray Essick614d8da2021-04-27 11:35:00 -070061 {true, "vq-bitrate-phaseout", "1.75"},
62 {true, "vq-boost-missing-qp", "0.20"},
Ray Essicka727ef92021-03-29 13:35:02 -070063 {true, nullptr, 0}
Ray Essick970f1c82021-03-25 13:37:45 -070064};
65
Ray Essicka727ef92021-03-29 13:35:02 -070066static preloadTuning_t featuresHevc[] = {
Ray Essick981ddf82021-05-03 13:33:09 -070067 {true, "vq-target-bpp", "0"},
Ray Essick7b4e9d92021-04-20 16:48:00 -070068 {true, "vq-target-bpp-1080p", "1.50"},
69 {true, "vq-target-bpp-720p", "1.80"},
70 {true, "vq-target-bpp-540p", "2.10"},
Ray Essick8d9abe52021-05-05 15:38:55 -070071 {true, "vq-target-bpp-480p", "2.30"},
Ray Essick981ddf82021-05-03 13:33:09 -070072 {true, "vq-target-qpmax", "-1"},
73 {true, "vq-target-qpmax-1080p", "45"},
Ray Essick8d9abe52021-05-05 15:38:55 -070074 {true, "vq-target-qpmax-720p", "44"},
75 {true, "vq-target-qpmax-540p", "43"},
76 {true, "vq-target-qpmax-480p", "42"},
Ray Essick614d8da2021-04-27 11:35:00 -070077 {true, "vq-bitrate-phaseout", "1.75"},
78 {true, "vq-boost-missing-qp", "0.20"},
Ray Essicka727ef92021-03-29 13:35:02 -070079 {true, nullptr, 0}
Ray Essick970f1c82021-03-25 13:37:45 -070080};
81
Ray Essicka727ef92021-03-29 13:35:02 -070082static preloadTuning_t featuresGenericVideo[] = {
Ray Essick981ddf82021-05-03 13:33:09 -070083 // 0 == off
84 {true, "vq-target-bpp", "0"},
Ray Essicka727ef92021-03-29 13:35:02 -070085 {true, nullptr, 0}
Ray Essick970f1c82021-03-25 13:37:45 -070086};
87
Ray Essicka727ef92021-03-29 13:35:02 -070088static preloadTunings_t preloadTunings[] = {
Ray Essick970f1c82021-03-25 13:37:45 -070089 { "video/avc", featuresAvc},
90 { "video/hevc", &featuresHevc[0]},
91
92 // wildcard for any video format not already captured
93 { "video/*", &featuresGenericVideo[0]},
Ray Essicka727ef92021-03-29 13:35:02 -070094
Ray Essick970f1c82021-03-25 13:37:45 -070095 { nullptr, nullptr}
96};
97
Ray Essicka727ef92021-03-29 13:35:02 -070098void CodecProperties::addMediaDefaults(bool overrideable) {
99 ALOGD("Seed: codec %s, mediatype %s, overrideable %d",
100 mName.c_str(), mMediaType.c_str(), overrideable);
Ray Essick970f1c82021-03-25 13:37:45 -0700101
102 // load me up with initial configuration data
103 int count = 0;
Ray Essicka727ef92021-03-29 13:35:02 -0700104 for (int i = 0; ; i++) {
105 preloadTunings_t *p = &preloadTunings[i];
Ray Essick970f1c82021-03-25 13:37:45 -0700106 if (p->mediaType == nullptr) {
107 break;
108 }
109 bool found = false;
110 if (strcmp(p->mediaType, mMediaType.c_str()) == 0) {
111 found = true;
112 }
113 const char *r;
114 if (!found && (r = strchr(p->mediaType, '*')) != NULL) {
115 // wildcard; check the prefix
116 size_t len = r - p->mediaType;
117 if (strncmp(p->mediaType, mMediaType.c_str(), len) == 0) {
118 found = true;
119 }
120 }
121
122 if (!found) {
123 continue;
124 }
125 ALOGV("seeding from mediaType '%s'", p->mediaType);
126
127 // walk through, filling things
128 if (p->features != nullptr) {
129 for (int j=0;; j++) {
Ray Essicka727ef92021-03-29 13:35:02 -0700130 preloadTuning_t *q = &p->features[j];
Ray Essick970f1c82021-03-25 13:37:45 -0700131 if (q->key == nullptr) {
132 break;
133 }
Ray Essicka727ef92021-03-29 13:35:02 -0700134 if (q->overrideable != overrideable) {
135 continue;
136 }
137 setTuningValue(q->key, q->value);
Ray Essick970f1c82021-03-25 13:37:45 -0700138 count++;
139 }
140 break;
141 }
142 }
143 ALOGV("loaded %d preset values", count);
144}
145
Ray Essicka727ef92021-03-29 13:35:02 -0700146// a chance, as we create the codec to inject any default behaviors we want.
147// XXX: consider whether we need pre/post or just post. it affects what can be
148// overridden by way of the codec XML
Ray Essick970f1c82021-03-25 13:37:45 -0700149//
Ray Essicka727ef92021-03-29 13:35:02 -0700150void CodecProperties::Seed() {
151 ALOGV("Seed: for codec %s, mediatype %s", mName.c_str(), mMediaType.c_str());
152 addMediaDefaults(true);
153}
154
Ray Essick970f1c82021-03-25 13:37:45 -0700155void CodecProperties::Finish() {
156 ALOGV("Finish: for codec %s, mediatype %s", mName.c_str(), mMediaType.c_str());
Ray Essicka727ef92021-03-29 13:35:02 -0700157 addMediaDefaults(false);
Ray Essick970f1c82021-03-25 13:37:45 -0700158}
159
160} // namespace mediaformatshaper
161} // namespace android
162