blob: d2ad7acd5e2cefa0f0e96fe4130ac06db8cb07c7 [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 Essickddcc6402021-06-17 16:49:13 -070056 {true, "vq-target-bpp-320x240", "0"},
Ray Essick981ddf82021-05-03 13:33:09 -070057 {true, "vq-target-qpmax", "-1"},
58 {true, "vq-target-qpmax-1080p", "45"},
59 {true, "vq-target-qpmax-720p", "43"},
60 {true, "vq-target-qpmax-540p", "42"},
61 {true, "vq-target-qpmax-480p", "38"},
Ray Essick614d8da2021-04-27 11:35:00 -070062 {true, "vq-bitrate-phaseout", "1.75"},
63 {true, "vq-boost-missing-qp", "0.20"},
Ray Essicka727ef92021-03-29 13:35:02 -070064 {true, nullptr, 0}
Ray Essick970f1c82021-03-25 13:37:45 -070065};
66
Ray Essicka727ef92021-03-29 13:35:02 -070067static preloadTuning_t featuresHevc[] = {
Ray Essick981ddf82021-05-03 13:33:09 -070068 {true, "vq-target-bpp", "0"},
Ray Essick7b4e9d92021-04-20 16:48:00 -070069 {true, "vq-target-bpp-1080p", "1.50"},
70 {true, "vq-target-bpp-720p", "1.80"},
71 {true, "vq-target-bpp-540p", "2.10"},
Ray Essick8d9abe52021-05-05 15:38:55 -070072 {true, "vq-target-bpp-480p", "2.30"},
Ray Essickddcc6402021-06-17 16:49:13 -070073 {true, "vq-target-bpp-320x240", "0"},
Ray Essick981ddf82021-05-03 13:33:09 -070074 {true, "vq-target-qpmax", "-1"},
75 {true, "vq-target-qpmax-1080p", "45"},
Ray Essick8d9abe52021-05-05 15:38:55 -070076 {true, "vq-target-qpmax-720p", "44"},
77 {true, "vq-target-qpmax-540p", "43"},
78 {true, "vq-target-qpmax-480p", "42"},
Ray Essick614d8da2021-04-27 11:35:00 -070079 {true, "vq-bitrate-phaseout", "1.75"},
80 {true, "vq-boost-missing-qp", "0.20"},
Ray Essicka727ef92021-03-29 13:35:02 -070081 {true, nullptr, 0}
Ray Essick970f1c82021-03-25 13:37:45 -070082};
83
Ray Essicka727ef92021-03-29 13:35:02 -070084static preloadTuning_t featuresGenericVideo[] = {
Ray Essick981ddf82021-05-03 13:33:09 -070085 // 0 == off
86 {true, "vq-target-bpp", "0"},
Ray Essicka727ef92021-03-29 13:35:02 -070087 {true, nullptr, 0}
Ray Essick970f1c82021-03-25 13:37:45 -070088};
89
Ray Essicka727ef92021-03-29 13:35:02 -070090static preloadTunings_t preloadTunings[] = {
Ray Essick970f1c82021-03-25 13:37:45 -070091 { "video/avc", featuresAvc},
92 { "video/hevc", &featuresHevc[0]},
93
94 // wildcard for any video format not already captured
95 { "video/*", &featuresGenericVideo[0]},
Ray Essicka727ef92021-03-29 13:35:02 -070096
Ray Essick970f1c82021-03-25 13:37:45 -070097 { nullptr, nullptr}
98};
99
Ray Essicka727ef92021-03-29 13:35:02 -0700100void CodecProperties::addMediaDefaults(bool overrideable) {
101 ALOGD("Seed: codec %s, mediatype %s, overrideable %d",
102 mName.c_str(), mMediaType.c_str(), overrideable);
Ray Essick970f1c82021-03-25 13:37:45 -0700103
104 // load me up with initial configuration data
105 int count = 0;
Ray Essicka727ef92021-03-29 13:35:02 -0700106 for (int i = 0; ; i++) {
107 preloadTunings_t *p = &preloadTunings[i];
Ray Essick970f1c82021-03-25 13:37:45 -0700108 if (p->mediaType == nullptr) {
109 break;
110 }
111 bool found = false;
112 if (strcmp(p->mediaType, mMediaType.c_str()) == 0) {
113 found = true;
114 }
115 const char *r;
116 if (!found && (r = strchr(p->mediaType, '*')) != NULL) {
117 // wildcard; check the prefix
118 size_t len = r - p->mediaType;
119 if (strncmp(p->mediaType, mMediaType.c_str(), len) == 0) {
120 found = true;
121 }
122 }
123
124 if (!found) {
125 continue;
126 }
127 ALOGV("seeding from mediaType '%s'", p->mediaType);
128
129 // walk through, filling things
130 if (p->features != nullptr) {
131 for (int j=0;; j++) {
Ray Essicka727ef92021-03-29 13:35:02 -0700132 preloadTuning_t *q = &p->features[j];
Ray Essick970f1c82021-03-25 13:37:45 -0700133 if (q->key == nullptr) {
134 break;
135 }
Ray Essicka727ef92021-03-29 13:35:02 -0700136 if (q->overrideable != overrideable) {
137 continue;
138 }
139 setTuningValue(q->key, q->value);
Ray Essick970f1c82021-03-25 13:37:45 -0700140 count++;
141 }
142 break;
143 }
144 }
145 ALOGV("loaded %d preset values", count);
146}
147
Ray Essicka727ef92021-03-29 13:35:02 -0700148// a chance, as we create the codec to inject any default behaviors we want.
149// XXX: consider whether we need pre/post or just post. it affects what can be
150// overridden by way of the codec XML
Ray Essick970f1c82021-03-25 13:37:45 -0700151//
Ray Essicka727ef92021-03-29 13:35:02 -0700152void CodecProperties::Seed() {
153 ALOGV("Seed: for codec %s, mediatype %s", mName.c_str(), mMediaType.c_str());
154 addMediaDefaults(true);
155}
156
Ray Essick970f1c82021-03-25 13:37:45 -0700157void CodecProperties::Finish() {
158 ALOGV("Finish: for codec %s, mediatype %s", mName.c_str(), mMediaType.c_str());
Ray Essicka727ef92021-03-29 13:35:02 -0700159 addMediaDefaults(false);
Ray Essick970f1c82021-03-25 13:37:45 -0700160}
161
162} // namespace mediaformatshaper
163} // namespace android
164