| Ray Essick | 970f1c8 | 2021-03-25 13:37:45 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 25 | namespace android { |
| 26 | namespace mediaformatshaper { |
| 27 | |
| 28 | /* |
| 29 | * a block of pre-loads; things the library seeds into the codecproperties based |
| 30 | * on the mediaType. |
| 31 | * XXX: parsing from a file is likely better than embedding in code. |
| 32 | */ |
| 33 | typedef struct { |
| 34 | const char *key; |
| 35 | int32_t value; |
| 36 | } preloadFeature_t; |
| 37 | |
| 38 | typedef struct { |
| 39 | const char *mediaType; |
| 40 | preloadFeature_t *features; |
| 41 | } preloadProperties_t; |
| 42 | |
| 43 | /* |
| 44 | * 240 = 2.4 bits per pixel-per-second == 5mbps@1080, 2.3mbps@720p, which is about where |
| 45 | * we want our initial floor for now. |
| 46 | */ |
| 47 | |
| 48 | static preloadFeature_t featuresAvc[] = { |
| 49 | {"vq-target-bppx100", 240}, |
| 50 | {nullptr, 0} |
| 51 | }; |
| 52 | |
| 53 | static preloadFeature_t featuresHevc[] = { |
| 54 | {"vq-target-bppx100", 240}, |
| 55 | {nullptr, 0} |
| 56 | }; |
| 57 | |
| 58 | static preloadFeature_t featuresGenericVideo[] = { |
| 59 | {"vq-target-bppx100", 240}, |
| 60 | {nullptr, 0} |
| 61 | }; |
| 62 | |
| 63 | static preloadProperties_t preloadProperties[] = { |
| 64 | { "video/avc", featuresAvc}, |
| 65 | { "video/hevc", &featuresHevc[0]}, |
| 66 | |
| 67 | // wildcard for any video format not already captured |
| 68 | { "video/*", &featuresGenericVideo[0]}, |
| 69 | { nullptr, nullptr} |
| 70 | }; |
| 71 | |
| 72 | void CodecProperties::Seed() { |
| 73 | ALOGV("Seed: for codec %s, mediatype %s", mName.c_str(), mMediaType.c_str()); |
| 74 | |
| 75 | // load me up with initial configuration data |
| 76 | int count = 0; |
| 77 | for (int i=0;; i++) { |
| 78 | preloadProperties_t *p = &preloadProperties[i]; |
| 79 | if (p->mediaType == nullptr) { |
| 80 | break; |
| 81 | } |
| 82 | bool found = false; |
| 83 | if (strcmp(p->mediaType, mMediaType.c_str()) == 0) { |
| 84 | found = true; |
| 85 | } |
| 86 | const char *r; |
| 87 | if (!found && (r = strchr(p->mediaType, '*')) != NULL) { |
| 88 | // wildcard; check the prefix |
| 89 | size_t len = r - p->mediaType; |
| 90 | if (strncmp(p->mediaType, mMediaType.c_str(), len) == 0) { |
| 91 | found = true; |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | if (!found) { |
| 96 | continue; |
| 97 | } |
| 98 | ALOGV("seeding from mediaType '%s'", p->mediaType); |
| 99 | |
| 100 | // walk through, filling things |
| 101 | if (p->features != nullptr) { |
| 102 | for (int j=0;; j++) { |
| 103 | preloadFeature_t *q = &p->features[j]; |
| 104 | if (q->key == nullptr) { |
| 105 | break; |
| 106 | } |
| 107 | setFeatureValue(q->key, q->value); |
| 108 | count++; |
| 109 | } |
| 110 | break; |
| 111 | } |
| 112 | } |
| 113 | ALOGV("loaded %d preset values", count); |
| 114 | } |
| 115 | |
| 116 | // a chance, as we register the codec and accept no further updates, to |
| 117 | // override any poor configuration that arrived from the device's XML files. |
| 118 | // |
| 119 | void CodecProperties::Finish() { |
| 120 | ALOGV("Finish: for codec %s, mediatype %s", mName.c_str(), mMediaType.c_str()); |
| 121 | |
| 122 | // currently a no-op |
| 123 | } |
| 124 | |
| 125 | } // namespace mediaformatshaper |
| 126 | } // namespace android |
| 127 | |