blob: fde7833bf9658066f01bcda8eae6d78a50a5de29 [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
23#include <media/formatshaper/CodecProperties.h>
24
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/*
47 * 240 = 2.4 bits per pixel-per-second == 5mbps@1080, 2.3mbps@720p, which is about where
48 * we want our initial floor for now.
49 */
50
Ray Essicka727ef92021-03-29 13:35:02 -070051static preloadTuning_t featuresAvc[] = {
52 {true, "vq-target-bpp", "2.45"},
53 {true, "vq-target-qpmax", "41"},
54 {true, nullptr, 0}
Ray Essick970f1c82021-03-25 13:37:45 -070055};
56
Ray Essicka727ef92021-03-29 13:35:02 -070057static preloadTuning_t featuresHevc[] = {
58 {true, "vq-target-bpp", "2.30"},
59 {true, "vq-target-qpmax", "42"}, // nop, since hevc codecs don't declare qp support
60 {true, nullptr, 0}
Ray Essick970f1c82021-03-25 13:37:45 -070061};
62
Ray Essicka727ef92021-03-29 13:35:02 -070063static preloadTuning_t featuresGenericVideo[] = {
64 {true, "vq-target-bpp", "2.40"},
65 {true, nullptr, 0}
Ray Essick970f1c82021-03-25 13:37:45 -070066};
67
Ray Essicka727ef92021-03-29 13:35:02 -070068static preloadTunings_t preloadTunings[] = {
Ray Essick970f1c82021-03-25 13:37:45 -070069 { "video/avc", featuresAvc},
70 { "video/hevc", &featuresHevc[0]},
71
72 // wildcard for any video format not already captured
73 { "video/*", &featuresGenericVideo[0]},
Ray Essicka727ef92021-03-29 13:35:02 -070074
Ray Essick970f1c82021-03-25 13:37:45 -070075 { nullptr, nullptr}
76};
77
Ray Essicka727ef92021-03-29 13:35:02 -070078void CodecProperties::addMediaDefaults(bool overrideable) {
79 ALOGD("Seed: codec %s, mediatype %s, overrideable %d",
80 mName.c_str(), mMediaType.c_str(), overrideable);
Ray Essick970f1c82021-03-25 13:37:45 -070081
82 // load me up with initial configuration data
83 int count = 0;
Ray Essicka727ef92021-03-29 13:35:02 -070084 for (int i = 0; ; i++) {
85 preloadTunings_t *p = &preloadTunings[i];
Ray Essick970f1c82021-03-25 13:37:45 -070086 if (p->mediaType == nullptr) {
87 break;
88 }
89 bool found = false;
90 if (strcmp(p->mediaType, mMediaType.c_str()) == 0) {
91 found = true;
92 }
93 const char *r;
94 if (!found && (r = strchr(p->mediaType, '*')) != NULL) {
95 // wildcard; check the prefix
96 size_t len = r - p->mediaType;
97 if (strncmp(p->mediaType, mMediaType.c_str(), len) == 0) {
98 found = true;
99 }
100 }
101
102 if (!found) {
103 continue;
104 }
105 ALOGV("seeding from mediaType '%s'", p->mediaType);
106
107 // walk through, filling things
108 if (p->features != nullptr) {
109 for (int j=0;; j++) {
Ray Essicka727ef92021-03-29 13:35:02 -0700110 preloadTuning_t *q = &p->features[j];
Ray Essick970f1c82021-03-25 13:37:45 -0700111 if (q->key == nullptr) {
112 break;
113 }
Ray Essicka727ef92021-03-29 13:35:02 -0700114 if (q->overrideable != overrideable) {
115 continue;
116 }
117 setTuningValue(q->key, q->value);
Ray Essick970f1c82021-03-25 13:37:45 -0700118 count++;
119 }
120 break;
121 }
122 }
123 ALOGV("loaded %d preset values", count);
124}
125
Ray Essicka727ef92021-03-29 13:35:02 -0700126// a chance, as we create the codec to inject any default behaviors we want.
127// XXX: consider whether we need pre/post or just post. it affects what can be
128// overridden by way of the codec XML
Ray Essick970f1c82021-03-25 13:37:45 -0700129//
Ray Essicka727ef92021-03-29 13:35:02 -0700130void CodecProperties::Seed() {
131 ALOGV("Seed: for codec %s, mediatype %s", mName.c_str(), mMediaType.c_str());
132 addMediaDefaults(true);
133}
134
Ray Essick970f1c82021-03-25 13:37:45 -0700135void CodecProperties::Finish() {
136 ALOGV("Finish: for codec %s, mediatype %s", mName.c_str(), mMediaType.c_str());
Ray Essicka727ef92021-03-29 13:35:02 -0700137 addMediaDefaults(false);
Ray Essick970f1c82021-03-25 13:37:45 -0700138}
139
140} // namespace mediaformatshaper
141} // namespace android
142