blob: f772a66a531936ad7a8172f5977202c09f459d19 [file] [log] [blame]
Ray Essick1831f7b2021-03-15 16:10:51 -07001/*
2 * Copyright (C) 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 "VideoShaper"
19#include <utils/Log.h>
20
21#include <string>
22#include <inttypes.h>
23
24#include <media/NdkMediaFormat.h>
25
26#include <media/formatshaper/VQops.h>
27#include <media/formatshaper/CodecProperties.h>
28#include <media/formatshaper/VideoShaper.h>
29
30namespace android {
31namespace mediaformatshaper {
32
33// mediatype-specific operations
34
35vqOps_t mediaInfo[] = {
36 {
37 .mediaType = "video/avc",
38 .qpMin = 0,
39 .qpMax = 51,
40 .qpDelta = 3,
41 },
42 {
43 .mediaType = "video/hevc",
44 .qpMin = 0,
45 .qpMax = 51,
46 .qpDelta = 3,
47 },
48 {
49 .mediaType = NULL, // matches everything, it must come last
50 .qpMin = INT32_MIN,
51 .qpMax = INT32_MAX,
52 .qpDelta = 3,
53 }
54};
55int nMediaInfos = sizeof(mediaInfo) / sizeof(mediaInfo[0]);
56
57//
58// Caller retains ownership of and responsibility for inFormat
59//
60
61int videoShaper(CodecProperties *codec, AMediaFormat* inFormat, int flags) {
62 if (codec == nullptr) {
63 return -1;
64 }
65 ALOGV("codec %s inFormat %p flags x%x", codec->getName().c_str(), inFormat, flags);
66
67 int ix;
68
69 std::string mediaType = codec->getMediaType();
70 // we should always come out of this with a selection, because the final entry
71 // is deliberaly a NULL -- so that it will act as a default
72 for(ix = 0; mediaInfo[ix].mediaType != NULL; ix++) {
73 if (strcmp(mediaType.c_str(), mediaInfo[ix].mediaType) == 0) {
74 break;
75 }
76 }
77 if (ix >= nMediaInfos) {
78 // shouldn't happen, but if it does .....
79 }
80
81 vqOps_t *info = &mediaInfo[ix];
82
83 // apply any quality transforms in here..
84 (void) VQApply(codec, info, inFormat, flags);
85
Ray Essick970f1c82021-03-25 13:37:45 -070086 // We must always spread any QP parameters.
Ray Essick1831f7b2021-03-15 16:10:51 -070087 // Sometimes it's something we inserted here, sometimes it's a value that the user injected.
88 //
89 qpSpreadPerFrameType(inFormat, info->qpDelta, info->qpMin, info->qpMax, /* override */ false);
90
91 //
92 return 0;
93
94}
95
96} // namespace mediaformatshaper
97} // namespace android
98