1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "video_processing_capi_capability.h"
17
18 #include <cstdio>
19 #include <iostream>
20 #include <string>
21 #include <unordered_set>
22
23 #include "vpe_log.h"
24
25 using namespace OHOS::Media::VideoProcessingEngine;
26 using namespace OHOS::HDI::Display::Graphic::Common::V1_0;
27
28 struct MetaSupportKey {
29 int32_t metadata;
30 int32_t colorSpace;
31 int32_t format;
32
operator <MetaSupportKey33 bool operator<(const MetaSupportKey& k) const
34 {
35 return metadata < k.metadata ||
36 (metadata == k.metadata && colorSpace < k.colorSpace) ||
37 (metadata == k.metadata && colorSpace == k.colorSpace && format < k.format);
38 }
39
operator ==MetaSupportKey40 bool operator==(const MetaSupportKey& k) const
41 {
42 return metadata == k.metadata && colorSpace == k.colorSpace && format == k.format;
43 }
44 };
45 template<> struct std::hash<MetaSupportKey> {
operator ()std::hash46 std::size_t operator()(const MetaSupportKey& k) const
47 {
48 return std::hash<uint32_t>()(k.metadata) ^ std::hash<uint32_t>()(k.colorSpace) ^
49 std::hash<uint32_t>()(k.format);
50 }
51 };
52
53 struct CscvSupportKey {
54 int32_t metadataIn;
55 int32_t colorSpaceIn;
56 int32_t formatIn;
57 int32_t metadataOut;
58 int32_t colorSpaceOut;
59 int32_t formatOut;
60
operator <CscvSupportKey61 bool operator<(const CscvSupportKey& k) const
62 {
63 return metadataIn < k.metadataIn ||
64 (metadataIn == k.metadataIn && colorSpaceIn < k.colorSpaceIn) ||
65 (metadataIn == k.metadataIn && colorSpaceIn == k.colorSpaceIn && formatIn < k.formatIn) ||
66 (metadataIn == k.metadataIn && colorSpaceIn == k.colorSpaceIn && formatIn == k.formatIn &&
67 metadataOut < k.metadataOut) ||
68 (metadataIn == k.metadataIn && colorSpaceIn == k.colorSpaceIn && formatIn == k.formatIn &&
69 metadataOut == k.metadataOut && colorSpaceOut < k.colorSpaceOut) ||
70 (metadataIn == k.metadataIn && colorSpaceIn == k.colorSpaceIn && formatIn == k.formatIn &&
71 metadataOut == k.metadataOut && colorSpaceOut == k.colorSpaceOut && formatOut < k.formatOut);
72 }
73
operator ==CscvSupportKey74 bool operator==(const CscvSupportKey& k) const
75 {
76 return metadataIn == k.metadataIn && colorSpaceIn == k.colorSpaceIn && formatIn == k.formatIn &&
77 metadataOut == k.metadataOut && colorSpaceOut == k.colorSpaceOut && formatOut == k.formatOut;
78 }
79 };
80 template<> struct std::hash<CscvSupportKey> {
operator ()std::hash81 std::size_t operator()(const CscvSupportKey& k) const
82 {
83 return std::hash<uint32_t>()(k.metadataIn) ^ std::hash<uint32_t>()(k.colorSpaceIn) ^
84 std::hash<uint32_t>()(k.formatIn) ^ std::hash<uint32_t>()(k.metadataOut) ^
85 std::hash<uint32_t>()(k.colorSpaceOut) ^ std::hash<uint32_t>()(k.formatOut);
86 }
87 };
88
89 namespace {
90 const std::unordered_set<MetaSupportKey> VIDEO_META_SUPPORT_MAP = {
91 { CM_VIDEO_HDR10, CM_BT2020_PQ_LIMIT, GRAPHIC_PIXEL_FMT_YCBCR_P010 },
92 { CM_VIDEO_HDR_VIVID, CM_BT2020_PQ_LIMIT, GRAPHIC_PIXEL_FMT_YCBCR_P010 },
93 { CM_VIDEO_HLG, CM_BT2020_HLG_LIMIT, GRAPHIC_PIXEL_FMT_YCBCR_P010 },
94 { CM_VIDEO_HDR_VIVID, CM_BT2020_HLG_LIMIT, GRAPHIC_PIXEL_FMT_YCBCR_P010 },
95 { CM_VIDEO_HDR10, CM_BT2020_PQ_LIMIT, GRAPHIC_PIXEL_FMT_YCRCB_P010 },
96 { CM_VIDEO_HDR_VIVID, CM_BT2020_PQ_LIMIT, GRAPHIC_PIXEL_FMT_YCRCB_P010 },
97 { CM_VIDEO_HLG, CM_BT2020_HLG_LIMIT, GRAPHIC_PIXEL_FMT_YCRCB_P010 },
98 { CM_VIDEO_HDR_VIVID, CM_BT2020_HLG_LIMIT, GRAPHIC_PIXEL_FMT_YCRCB_P010 },
99 { CM_VIDEO_HDR10, CM_BT2020_PQ_LIMIT, GRAPHIC_PIXEL_FMT_RGBA_1010102 },
100 { CM_VIDEO_HDR_VIVID, CM_BT2020_PQ_LIMIT, GRAPHIC_PIXEL_FMT_RGBA_1010102 },
101 { CM_VIDEO_HLG, CM_BT2020_HLG_LIMIT, GRAPHIC_PIXEL_FMT_RGBA_1010102 },
102 { CM_VIDEO_HDR_VIVID, CM_BT2020_HLG_LIMIT, GRAPHIC_PIXEL_FMT_RGBA_1010102 },
103 };
104 const std::unordered_set<CscvSupportKey> VIDEO_COLORSPACE_CONVERTER_SUPPORT_SDRTOSDR_MAP = {
105 { CM_METADATA_NONE, CM_BT601_EBU_LIMIT, GRAPHIC_PIXEL_FMT_YCBCR_420_SP,
106 CM_METADATA_NONE, CM_BT709_LIMIT, GRAPHIC_PIXEL_FMT_YCBCR_420_SP },
107 { CM_METADATA_NONE, CM_BT601_SMPTE_C_LIMIT, GRAPHIC_PIXEL_FMT_YCBCR_420_SP,
108 CM_METADATA_NONE, CM_BT709_LIMIT, GRAPHIC_PIXEL_FMT_YCBCR_420_SP },
109 { CM_METADATA_NONE, CM_BT601_EBU_LIMIT, GRAPHIC_PIXEL_FMT_YCBCR_420_SP,
110 CM_METADATA_NONE, CM_BT709_LIMIT, GRAPHIC_PIXEL_FMT_YCRCB_420_SP },
111 { CM_METADATA_NONE, CM_BT601_SMPTE_C_LIMIT, GRAPHIC_PIXEL_FMT_YCBCR_420_SP,
112 CM_METADATA_NONE, CM_BT709_LIMIT, GRAPHIC_PIXEL_FMT_YCRCB_420_SP },
113 { CM_METADATA_NONE, CM_BT601_EBU_LIMIT, GRAPHIC_PIXEL_FMT_YCBCR_420_SP,
114 CM_METADATA_NONE, CM_BT709_LIMIT, GRAPHIC_PIXEL_FMT_RGBA_8888 },
115 { CM_METADATA_NONE, CM_BT601_SMPTE_C_LIMIT, GRAPHIC_PIXEL_FMT_YCBCR_420_SP,
116 CM_METADATA_NONE, CM_BT709_LIMIT, GRAPHIC_PIXEL_FMT_RGBA_8888 },
117 { CM_METADATA_NONE, CM_BT601_EBU_LIMIT, GRAPHIC_PIXEL_FMT_YCRCB_420_SP,
118 CM_METADATA_NONE, CM_BT709_LIMIT, GRAPHIC_PIXEL_FMT_YCBCR_420_SP },
119 { CM_METADATA_NONE, CM_BT601_SMPTE_C_LIMIT, GRAPHIC_PIXEL_FMT_YCRCB_420_SP,
120 CM_METADATA_NONE, CM_BT709_LIMIT, GRAPHIC_PIXEL_FMT_YCBCR_420_SP },
121 { CM_METADATA_NONE, CM_BT601_EBU_LIMIT, GRAPHIC_PIXEL_FMT_YCRCB_420_SP,
122 CM_METADATA_NONE, CM_BT709_LIMIT, GRAPHIC_PIXEL_FMT_YCRCB_420_SP },
123 { CM_METADATA_NONE, CM_BT601_SMPTE_C_LIMIT, GRAPHIC_PIXEL_FMT_YCRCB_420_SP,
124 CM_METADATA_NONE, CM_BT709_LIMIT, GRAPHIC_PIXEL_FMT_YCRCB_420_SP },
125 { CM_METADATA_NONE, CM_BT601_EBU_LIMIT, GRAPHIC_PIXEL_FMT_YCRCB_420_SP,
126 CM_METADATA_NONE, CM_BT709_LIMIT, GRAPHIC_PIXEL_FMT_RGBA_8888 },
127 { CM_METADATA_NONE, CM_BT601_SMPTE_C_LIMIT, GRAPHIC_PIXEL_FMT_YCRCB_420_SP,
128 CM_METADATA_NONE, CM_BT709_LIMIT, GRAPHIC_PIXEL_FMT_RGBA_8888 },
129 { CM_METADATA_NONE, CM_BT601_EBU_LIMIT, GRAPHIC_PIXEL_FMT_RGBA_8888,
130 CM_METADATA_NONE, CM_BT709_LIMIT, GRAPHIC_PIXEL_FMT_YCBCR_420_SP },
131 { CM_METADATA_NONE, CM_BT601_SMPTE_C_LIMIT, GRAPHIC_PIXEL_FMT_RGBA_8888,
132 CM_METADATA_NONE, CM_BT709_LIMIT, GRAPHIC_PIXEL_FMT_YCBCR_420_SP },
133 { CM_METADATA_NONE, CM_BT601_EBU_LIMIT, GRAPHIC_PIXEL_FMT_RGBA_8888,
134 CM_METADATA_NONE, CM_BT709_LIMIT, GRAPHIC_PIXEL_FMT_YCRCB_420_SP },
135 { CM_METADATA_NONE, CM_BT601_SMPTE_C_LIMIT, GRAPHIC_PIXEL_FMT_RGBA_8888,
136 CM_METADATA_NONE, CM_BT709_LIMIT, GRAPHIC_PIXEL_FMT_YCRCB_420_SP },
137 { CM_METADATA_NONE, CM_BT601_EBU_LIMIT, GRAPHIC_PIXEL_FMT_RGBA_8888,
138 CM_METADATA_NONE, CM_BT709_LIMIT, GRAPHIC_PIXEL_FMT_RGBA_8888 },
139 { CM_METADATA_NONE, CM_BT601_SMPTE_C_LIMIT, GRAPHIC_PIXEL_FMT_RGBA_8888,
140 CM_METADATA_NONE, CM_BT709_LIMIT, GRAPHIC_PIXEL_FMT_RGBA_8888 },
141 };
142 const std::unordered_set<CscvSupportKey> VIDEO_COLORSPACE_CONVERTER_SUPPORT_HDRTOSDR_MAP = {
143 { CM_VIDEO_HDR_VIVID, CM_BT2020_PQ_LIMIT, GRAPHIC_PIXEL_FMT_YCBCR_P010,
144 CM_METADATA_NONE, CM_BT709_LIMIT, GRAPHIC_PIXEL_FMT_YCBCR_420_SP },
145 { CM_VIDEO_HDR_VIVID, CM_BT2020_HLG_LIMIT, GRAPHIC_PIXEL_FMT_YCBCR_P010,
146 CM_METADATA_NONE, CM_BT709_LIMIT, GRAPHIC_PIXEL_FMT_YCBCR_420_SP },
147 { CM_VIDEO_HDR_VIVID, CM_BT2020_PQ_LIMIT, GRAPHIC_PIXEL_FMT_YCBCR_P010,
148 CM_METADATA_NONE, CM_BT709_LIMIT, GRAPHIC_PIXEL_FMT_YCRCB_420_SP },
149 { CM_VIDEO_HDR_VIVID, CM_BT2020_HLG_LIMIT, GRAPHIC_PIXEL_FMT_YCBCR_P010,
150 CM_METADATA_NONE, CM_BT709_LIMIT, GRAPHIC_PIXEL_FMT_YCRCB_420_SP },
151 { CM_VIDEO_HDR_VIVID, CM_BT2020_PQ_LIMIT, GRAPHIC_PIXEL_FMT_YCBCR_P010,
152 CM_METADATA_NONE, CM_BT709_LIMIT, GRAPHIC_PIXEL_FMT_RGBA_8888 },
153 { CM_VIDEO_HDR_VIVID, CM_BT2020_HLG_LIMIT, GRAPHIC_PIXEL_FMT_YCBCR_P010,
154 CM_METADATA_NONE, CM_BT709_LIMIT, GRAPHIC_PIXEL_FMT_RGBA_8888 },
155 { CM_VIDEO_HDR_VIVID, CM_BT2020_PQ_LIMIT, GRAPHIC_PIXEL_FMT_YCRCB_P010,
156 CM_METADATA_NONE, CM_BT709_LIMIT, GRAPHIC_PIXEL_FMT_YCBCR_420_SP },
157 { CM_VIDEO_HDR_VIVID, CM_BT2020_HLG_LIMIT, GRAPHIC_PIXEL_FMT_YCRCB_P010,
158 CM_METADATA_NONE, CM_BT709_LIMIT, GRAPHIC_PIXEL_FMT_YCBCR_420_SP },
159 { CM_VIDEO_HDR_VIVID, CM_BT2020_PQ_LIMIT, GRAPHIC_PIXEL_FMT_YCRCB_P010,
160 CM_METADATA_NONE, CM_BT709_LIMIT, GRAPHIC_PIXEL_FMT_YCRCB_420_SP },
161 { CM_VIDEO_HDR_VIVID, CM_BT2020_HLG_LIMIT, GRAPHIC_PIXEL_FMT_YCRCB_P010,
162 CM_METADATA_NONE, CM_BT709_LIMIT, GRAPHIC_PIXEL_FMT_YCRCB_420_SP },
163 { CM_VIDEO_HDR_VIVID, CM_BT2020_PQ_LIMIT, GRAPHIC_PIXEL_FMT_YCRCB_P010,
164 CM_METADATA_NONE, CM_BT709_LIMIT, GRAPHIC_PIXEL_FMT_RGBA_8888 },
165 { CM_VIDEO_HDR_VIVID, CM_BT2020_HLG_LIMIT, GRAPHIC_PIXEL_FMT_YCRCB_P010,
166 CM_METADATA_NONE, CM_BT709_LIMIT, GRAPHIC_PIXEL_FMT_RGBA_8888 },
167 { CM_VIDEO_HDR_VIVID, CM_BT2020_PQ_LIMIT, GRAPHIC_PIXEL_FMT_RGBA_1010102,
168 CM_METADATA_NONE, CM_BT709_LIMIT, GRAPHIC_PIXEL_FMT_YCBCR_420_SP },
169 { CM_VIDEO_HDR_VIVID, CM_BT2020_HLG_LIMIT, GRAPHIC_PIXEL_FMT_RGBA_1010102,
170 CM_METADATA_NONE, CM_BT709_LIMIT, GRAPHIC_PIXEL_FMT_YCBCR_420_SP },
171 { CM_VIDEO_HDR_VIVID, CM_BT2020_PQ_LIMIT, GRAPHIC_PIXEL_FMT_RGBA_1010102,
172 CM_METADATA_NONE, CM_BT709_LIMIT, GRAPHIC_PIXEL_FMT_YCRCB_420_SP },
173 { CM_VIDEO_HDR_VIVID, CM_BT2020_HLG_LIMIT, GRAPHIC_PIXEL_FMT_RGBA_1010102,
174 CM_METADATA_NONE, CM_BT709_LIMIT, GRAPHIC_PIXEL_FMT_YCRCB_420_SP },
175 { CM_VIDEO_HDR_VIVID, CM_BT2020_PQ_LIMIT, GRAPHIC_PIXEL_FMT_RGBA_1010102,
176 CM_METADATA_NONE, CM_BT709_LIMIT, GRAPHIC_PIXEL_FMT_RGBA_8888 },
177 { CM_VIDEO_HDR_VIVID, CM_BT2020_HLG_LIMIT, GRAPHIC_PIXEL_FMT_RGBA_1010102,
178 CM_METADATA_NONE, CM_BT709_LIMIT, GRAPHIC_PIXEL_FMT_RGBA_8888 },
179 };
180 const std::unordered_set<CscvSupportKey> VIDEO_COLORSPACE_CONVERTER_SUPPORT_HDRTOHDR_MAP = {
181 { CM_VIDEO_HDR_VIVID, CM_BT2020_PQ_LIMIT, GRAPHIC_PIXEL_FMT_YCBCR_P010,
182 CM_VIDEO_HDR_VIVID, CM_BT2020_HLG_LIMIT, GRAPHIC_PIXEL_FMT_YCBCR_P010 },
183 { CM_VIDEO_HDR10, CM_BT2020_PQ_LIMIT, GRAPHIC_PIXEL_FMT_YCBCR_P010,
184 CM_VIDEO_HLG, CM_BT2020_HLG_LIMIT, GRAPHIC_PIXEL_FMT_YCBCR_P010 },
185 { CM_VIDEO_HDR_VIVID, CM_BT2020_PQ_LIMIT, GRAPHIC_PIXEL_FMT_YCBCR_P010,
186 CM_VIDEO_HLG, CM_BT2020_HLG_LIMIT, GRAPHIC_PIXEL_FMT_YCBCR_P010 },
187 { CM_VIDEO_HDR_VIVID, CM_BT2020_HLG_LIMIT, GRAPHIC_PIXEL_FMT_YCBCR_P010,
188 CM_VIDEO_HDR_VIVID, CM_BT2020_PQ_LIMIT, GRAPHIC_PIXEL_FMT_YCBCR_P010 },
189 { CM_VIDEO_HDR_VIVID, CM_BT2020_PQ_LIMIT, GRAPHIC_PIXEL_FMT_YCBCR_P010,
190 CM_VIDEO_HDR_VIVID, CM_BT2020_HLG_LIMIT, GRAPHIC_PIXEL_FMT_YCRCB_P010 },
191 { CM_VIDEO_HDR10, CM_BT2020_PQ_LIMIT, GRAPHIC_PIXEL_FMT_YCBCR_P010,
192 CM_VIDEO_HLG, CM_BT2020_HLG_LIMIT, GRAPHIC_PIXEL_FMT_YCRCB_P010 },
193 { CM_VIDEO_HDR_VIVID, CM_BT2020_PQ_LIMIT, GRAPHIC_PIXEL_FMT_YCBCR_P010,
194 CM_VIDEO_HLG, CM_BT2020_HLG_LIMIT, GRAPHIC_PIXEL_FMT_YCRCB_P010 },
195 { CM_VIDEO_HDR_VIVID, CM_BT2020_HLG_LIMIT, GRAPHIC_PIXEL_FMT_YCBCR_P010,
196 CM_VIDEO_HDR_VIVID, CM_BT2020_PQ_LIMIT, GRAPHIC_PIXEL_FMT_YCRCB_P010 },
197 { CM_VIDEO_HDR_VIVID, CM_BT2020_PQ_LIMIT, GRAPHIC_PIXEL_FMT_YCBCR_P010,
198 CM_VIDEO_HDR_VIVID, CM_BT2020_HLG_LIMIT, GRAPHIC_PIXEL_FMT_RGBA_1010102 },
199 { CM_VIDEO_HDR10, CM_BT2020_PQ_LIMIT, GRAPHIC_PIXEL_FMT_YCBCR_P010,
200 CM_VIDEO_HLG, CM_BT2020_HLG_LIMIT, GRAPHIC_PIXEL_FMT_RGBA_1010102 },
201 { CM_VIDEO_HDR_VIVID, CM_BT2020_PQ_LIMIT, GRAPHIC_PIXEL_FMT_YCBCR_P010,
202 CM_VIDEO_HLG, CM_BT2020_HLG_LIMIT, GRAPHIC_PIXEL_FMT_RGBA_1010102 },
203 { CM_VIDEO_HDR_VIVID, CM_BT2020_HLG_LIMIT, GRAPHIC_PIXEL_FMT_YCBCR_P010,
204 CM_VIDEO_HDR_VIVID, CM_BT2020_PQ_LIMIT, GRAPHIC_PIXEL_FMT_RGBA_1010102 },
205 { CM_VIDEO_HDR_VIVID, CM_BT2020_PQ_LIMIT, GRAPHIC_PIXEL_FMT_YCRCB_P010,
206 CM_VIDEO_HDR_VIVID, CM_BT2020_HLG_LIMIT, GRAPHIC_PIXEL_FMT_YCBCR_P010 },
207 { CM_VIDEO_HDR10, CM_BT2020_PQ_LIMIT, GRAPHIC_PIXEL_FMT_YCRCB_P010,
208 CM_VIDEO_HLG, CM_BT2020_HLG_LIMIT, GRAPHIC_PIXEL_FMT_YCBCR_P010 },
209 { CM_VIDEO_HDR_VIVID, CM_BT2020_PQ_LIMIT, GRAPHIC_PIXEL_FMT_YCRCB_P010,
210 CM_VIDEO_HLG, CM_BT2020_HLG_LIMIT, GRAPHIC_PIXEL_FMT_YCBCR_P010 },
211 { CM_VIDEO_HDR_VIVID, CM_BT2020_HLG_LIMIT, GRAPHIC_PIXEL_FMT_YCRCB_P010,
212 CM_VIDEO_HDR_VIVID, CM_BT2020_PQ_LIMIT, GRAPHIC_PIXEL_FMT_YCBCR_P010 },
213 { CM_VIDEO_HDR_VIVID, CM_BT2020_PQ_LIMIT, GRAPHIC_PIXEL_FMT_YCRCB_P010,
214 CM_VIDEO_HDR_VIVID, CM_BT2020_HLG_LIMIT, GRAPHIC_PIXEL_FMT_YCRCB_P010 },
215 { CM_VIDEO_HDR10, CM_BT2020_PQ_LIMIT, GRAPHIC_PIXEL_FMT_YCRCB_P010,
216 CM_VIDEO_HLG, CM_BT2020_HLG_LIMIT, GRAPHIC_PIXEL_FMT_YCRCB_P010 },
217 { CM_VIDEO_HDR_VIVID, CM_BT2020_PQ_LIMIT, GRAPHIC_PIXEL_FMT_YCRCB_P010,
218 CM_VIDEO_HLG, CM_BT2020_HLG_LIMIT, GRAPHIC_PIXEL_FMT_YCRCB_P010 },
219 { CM_VIDEO_HDR_VIVID, CM_BT2020_HLG_LIMIT, GRAPHIC_PIXEL_FMT_YCRCB_P010,
220 CM_VIDEO_HDR_VIVID, CM_BT2020_PQ_LIMIT, GRAPHIC_PIXEL_FMT_YCRCB_P010 },
221 { CM_VIDEO_HDR_VIVID, CM_BT2020_PQ_LIMIT, GRAPHIC_PIXEL_FMT_YCRCB_P010,
222 CM_VIDEO_HDR_VIVID, CM_BT2020_HLG_LIMIT, GRAPHIC_PIXEL_FMT_RGBA_1010102 },
223 { CM_VIDEO_HDR10, CM_BT2020_PQ_LIMIT, GRAPHIC_PIXEL_FMT_YCRCB_P010,
224 CM_VIDEO_HLG, CM_BT2020_HLG_LIMIT, GRAPHIC_PIXEL_FMT_RGBA_1010102 },
225 { CM_VIDEO_HDR_VIVID, CM_BT2020_PQ_LIMIT, GRAPHIC_PIXEL_FMT_YCRCB_P010,
226 CM_VIDEO_HLG, CM_BT2020_HLG_LIMIT, GRAPHIC_PIXEL_FMT_RGBA_1010102 },
227 { CM_VIDEO_HDR_VIVID, CM_BT2020_HLG_LIMIT, GRAPHIC_PIXEL_FMT_YCRCB_P010,
228 CM_VIDEO_HDR_VIVID, CM_BT2020_PQ_LIMIT, GRAPHIC_PIXEL_FMT_RGBA_1010102 },
229 { CM_VIDEO_HDR_VIVID, CM_BT2020_PQ_LIMIT, GRAPHIC_PIXEL_FMT_RGBA_1010102,
230 CM_VIDEO_HDR_VIVID, CM_BT2020_HLG_LIMIT, GRAPHIC_PIXEL_FMT_YCBCR_P010 },
231 { CM_VIDEO_HDR10, CM_BT2020_PQ_LIMIT, GRAPHIC_PIXEL_FMT_RGBA_1010102,
232 CM_VIDEO_HLG, CM_BT2020_HLG_LIMIT, GRAPHIC_PIXEL_FMT_YCBCR_P010 },
233 { CM_VIDEO_HDR_VIVID, CM_BT2020_PQ_LIMIT, GRAPHIC_PIXEL_FMT_RGBA_1010102,
234 CM_VIDEO_HLG, CM_BT2020_HLG_LIMIT, GRAPHIC_PIXEL_FMT_YCBCR_P010 },
235 { CM_VIDEO_HDR_VIVID, CM_BT2020_HLG_LIMIT, GRAPHIC_PIXEL_FMT_RGBA_1010102,
236 CM_VIDEO_HDR_VIVID, CM_BT2020_PQ_LIMIT, GRAPHIC_PIXEL_FMT_YCBCR_P010 },
237 { CM_VIDEO_HDR_VIVID, CM_BT2020_PQ_LIMIT, GRAPHIC_PIXEL_FMT_RGBA_1010102,
238 CM_VIDEO_HDR_VIVID, CM_BT2020_HLG_LIMIT, GRAPHIC_PIXEL_FMT_YCRCB_P010 },
239 { CM_VIDEO_HDR10, CM_BT2020_PQ_LIMIT, GRAPHIC_PIXEL_FMT_RGBA_1010102,
240 CM_VIDEO_HLG, CM_BT2020_HLG_LIMIT, GRAPHIC_PIXEL_FMT_YCRCB_P010 },
241 { CM_VIDEO_HDR_VIVID, CM_BT2020_PQ_LIMIT, GRAPHIC_PIXEL_FMT_RGBA_1010102,
242 CM_VIDEO_HLG, CM_BT2020_HLG_LIMIT, GRAPHIC_PIXEL_FMT_YCRCB_P010 },
243 { CM_VIDEO_HDR_VIVID, CM_BT2020_HLG_LIMIT, GRAPHIC_PIXEL_FMT_RGBA_1010102,
244 CM_VIDEO_HDR_VIVID, CM_BT2020_PQ_LIMIT, GRAPHIC_PIXEL_FMT_YCRCB_P010 },
245 { CM_VIDEO_HDR_VIVID, CM_BT2020_PQ_LIMIT, GRAPHIC_PIXEL_FMT_RGBA_1010102,
246 CM_VIDEO_HDR_VIVID, CM_BT2020_HLG_LIMIT, GRAPHIC_PIXEL_FMT_RGBA_1010102 },
247 { CM_VIDEO_HDR10, CM_BT2020_PQ_LIMIT, GRAPHIC_PIXEL_FMT_RGBA_1010102,
248 CM_VIDEO_HLG, CM_BT2020_HLG_LIMIT, GRAPHIC_PIXEL_FMT_RGBA_1010102 },
249 { CM_VIDEO_HDR_VIVID, CM_BT2020_PQ_LIMIT, GRAPHIC_PIXEL_FMT_RGBA_1010102,
250 CM_VIDEO_HLG, CM_BT2020_HLG_LIMIT, GRAPHIC_PIXEL_FMT_RGBA_1010102 },
251 { CM_VIDEO_HDR_VIVID, CM_BT2020_HLG_LIMIT, GRAPHIC_PIXEL_FMT_RGBA_1010102,
252 CM_VIDEO_HDR_VIVID, CM_BT2020_PQ_LIMIT, GRAPHIC_PIXEL_FMT_RGBA_1010102 },
253 };
254 }
255
VideoColorSpaceInfoToCscvKey(const VideoProcessing_ColorSpaceInfo * sourceVideoInfo,const VideoProcessing_ColorSpaceInfo * destinationVideoInfo)256 CscvSupportKey VideoColorSpaceInfoToCscvKey(const VideoProcessing_ColorSpaceInfo* sourceVideoInfo,
257 const VideoProcessing_ColorSpaceInfo* destinationVideoInfo)
258 {
259 int32_t metadataValeSrc = static_cast<int32_t>(CM_METADATA_NONE);
260 int32_t colorSpaceValeSrc = static_cast<int32_t>(OH_COLORSPACE_NONE);
261 int32_t formatValeSrc = static_cast<int32_t>(NATIVEBUFFER_PIXEL_FMT_BUTT);
262 int32_t metadataValeDst = static_cast<int32_t>(CM_METADATA_NONE);
263 int32_t colorSpaceValeDst = static_cast<int32_t>(OH_COLORSPACE_NONE);
264 int32_t formatValeDst = static_cast<int32_t>(NATIVEBUFFER_PIXEL_FMT_BUTT);
265 OH_NativeBuffer_Format formatIn = static_cast<OH_NativeBuffer_Format>(sourceVideoInfo->pixelFormat);
266 auto itInFormat = NATIVE_FORMAT_TO_GRAPHIC_MAP.find(formatIn);
267 if (itInFormat != NATIVE_FORMAT_TO_GRAPHIC_MAP.end()) {
268 formatValeSrc = static_cast<int32_t>(itInFormat->second);
269 }
270 OH_NativeBuffer_Format formatOut = static_cast<OH_NativeBuffer_Format>(destinationVideoInfo->pixelFormat);
271 auto itOutFormat = NATIVE_FORMAT_TO_GRAPHIC_MAP.find(formatOut);
272 if (itOutFormat != NATIVE_FORMAT_TO_GRAPHIC_MAP.end()) {
273 formatValeDst = static_cast<int32_t>(itOutFormat->second);
274 }
275 OH_NativeBuffer_ColorSpace colorIn = static_cast<OH_NativeBuffer_ColorSpace>(sourceVideoInfo->colorSpace);
276 auto itInColorSpace = NATIVE_COLORSPACE_TO_CM_MAP.find(colorIn);
277 if (itInColorSpace != NATIVE_COLORSPACE_TO_CM_MAP.end()) {
278 colorSpaceValeSrc = static_cast<int32_t>(itInColorSpace->second);
279 }
280 OH_NativeBuffer_ColorSpace colorOut = static_cast<OH_NativeBuffer_ColorSpace>(destinationVideoInfo->colorSpace);
281 auto itOutColorSpace = NATIVE_COLORSPACE_TO_CM_MAP.find(colorOut);
282 if (itOutColorSpace != NATIVE_COLORSPACE_TO_CM_MAP.end()) {
283 colorSpaceValeDst = static_cast<int32_t>(itOutColorSpace->second);
284 }
285 OH_NativeBuffer_MetadataType metaIn = static_cast<OH_NativeBuffer_MetadataType>(sourceVideoInfo->metadataType);
286 auto itInMetadata = NATIVE_METADATATYPE_TO_CM_MAP.find(metaIn);
287 if (itInMetadata != NATIVE_METADATATYPE_TO_CM_MAP.end()) {
288 metadataValeSrc = static_cast<int32_t>(itInMetadata->second);
289 }
290 OH_NativeBuffer_MetadataType metaOut = static_cast<OH_NativeBuffer_MetadataType>(
291 destinationVideoInfo->metadataType);
292 auto itOutMetadata = NATIVE_METADATATYPE_TO_CM_MAP.find(metaOut);
293 if (itOutMetadata != NATIVE_METADATATYPE_TO_CM_MAP.end()) {
294 metadataValeDst = static_cast<int32_t>(itOutMetadata->second);
295 }
296 CscvSupportKey keyReturn{ metadataValeSrc, colorSpaceValeSrc, formatValeSrc,
297 metadataValeDst, colorSpaceValeDst, formatValeDst };
298 return keyReturn;
299 }
IsColorSpaceConversionSupported(const VideoProcessing_ColorSpaceInfo * sourceVideoInfo,const VideoProcessing_ColorSpaceInfo * destinationVideoInfo)300 bool VideoProcessingCapiCapability::IsColorSpaceConversionSupported(
301 const VideoProcessing_ColorSpaceInfo* sourceVideoInfo,
302 const VideoProcessing_ColorSpaceInfo* destinationVideoInfo)
303 {
304 if (access("/system/lib64/libvideoprocessingengine_ext.z.so", 0)) {
305 return false;
306 }
307 CHECK_AND_RETURN_RET_LOG(sourceVideoInfo != nullptr, false, "sourceVideoInfo is null!");
308 CHECK_AND_RETURN_RET_LOG(destinationVideoInfo != nullptr, false, "destinationVideoInfo is null!");
309 CscvSupportKey keySource = VideoColorSpaceInfoToCscvKey(sourceVideoInfo, destinationVideoInfo);
310 auto it = VIDEO_COLORSPACE_CONVERTER_SUPPORT_SDRTOSDR_MAP.find(keySource);
311 if (it != VIDEO_COLORSPACE_CONVERTER_SUPPORT_SDRTOSDR_MAP.end()) {
312 return true;
313 }
314 it = VIDEO_COLORSPACE_CONVERTER_SUPPORT_HDRTOSDR_MAP.find(keySource);
315 if (it != VIDEO_COLORSPACE_CONVERTER_SUPPORT_HDRTOSDR_MAP.end()) {
316 return true;
317 }
318 it = VIDEO_COLORSPACE_CONVERTER_SUPPORT_HDRTOHDR_MAP.find(keySource);
319 if (it != VIDEO_COLORSPACE_CONVERTER_SUPPORT_HDRTOHDR_MAP.end()) {
320 return true;
321 }
322 VPE_LOGE("IsColorSpaceConversionSupported false (FormatIn:%{public}d, ColorIn:%{public}d, MetaIn:%{public}d, \
323 FormatOut:%{public}d, ColorOut:%{public}d, MetaOut:%{public}d) !",
324 sourceVideoInfo->pixelFormat, sourceVideoInfo->colorSpace, sourceVideoInfo->metadataType,
325 destinationVideoInfo->pixelFormat, destinationVideoInfo->colorSpace, destinationVideoInfo->metadataType);
326 return false;
327 }
328
VideoColorSpaceInfoToMetaKey(const VideoProcessing_ColorSpaceInfo * sourceVideoInfo)329 MetaSupportKey VideoColorSpaceInfoToMetaKey(const VideoProcessing_ColorSpaceInfo* sourceVideoInfo)
330 {
331 int32_t metadataVale = static_cast<int32_t>(CM_METADATA_NONE);
332 int32_t colorSpaceVale = static_cast<int32_t>(OH_COLORSPACE_NONE);
333 int32_t formatVale = static_cast<int32_t>(NATIVEBUFFER_PIXEL_FMT_BUTT);
334 OH_NativeBuffer_Format formatIn = static_cast<OH_NativeBuffer_Format>(sourceVideoInfo->pixelFormat);
335 auto itInFormat = NATIVE_FORMAT_TO_GRAPHIC_MAP.find(formatIn);
336 if (itInFormat != NATIVE_FORMAT_TO_GRAPHIC_MAP.end()) {
337 formatVale = static_cast<int32_t>(itInFormat->second);
338 }
339 OH_NativeBuffer_ColorSpace colorIn = static_cast<OH_NativeBuffer_ColorSpace>(sourceVideoInfo->colorSpace);
340 auto itInColorSpace = NATIVE_COLORSPACE_TO_CM_MAP.find(colorIn);
341 if (itInColorSpace != NATIVE_COLORSPACE_TO_CM_MAP.end()) {
342 colorSpaceVale = static_cast<int32_t>(itInColorSpace->second);
343 }
344 OH_NativeBuffer_MetadataType metaIn = static_cast<OH_NativeBuffer_MetadataType>(sourceVideoInfo->metadataType);
345 auto itInMetadata = NATIVE_METADATATYPE_TO_CM_MAP.find(metaIn);
346 if (itInMetadata != NATIVE_METADATATYPE_TO_CM_MAP.end()) {
347 metadataVale = static_cast<int32_t>(itInMetadata->second);
348 }
349 MetaSupportKey keyReturn{ metadataVale, colorSpaceVale, formatVale };
350 return keyReturn;
351 }
IsMetadataGenerationSupported(const VideoProcessing_ColorSpaceInfo * sourceVideoInfo)352 bool VideoProcessingCapiCapability::IsMetadataGenerationSupported(
353 const VideoProcessing_ColorSpaceInfo* sourceVideoInfo)
354 {
355 if (access("/system/lib64/libvideoprocessingengine_ext.z.so", 0)) {
356 return false;
357 }
358 CHECK_AND_RETURN_RET_LOG(sourceVideoInfo != nullptr, false, "sourceVideoInfo is null!");
359 MetaSupportKey keySource = VideoColorSpaceInfoToMetaKey(sourceVideoInfo);
360 auto it = VIDEO_META_SUPPORT_MAP.find(keySource);
361 if (it != VIDEO_META_SUPPORT_MAP.end()) {
362 return true;
363 }
364 VPE_LOGE("IsMetadataGenerationSupported false (Format:%{public}d, Color:%{public}d, Meta:%{public}d) !",
365 sourceVideoInfo->pixelFormat, sourceVideoInfo->colorSpace, sourceVideoInfo->metadataType);
366 return false;
367 }
368
369 std::shared_ptr<OpenGLContext> VideoProcessingCapiCapability::openglContext_ = nullptr;
370
OpenGLInit()371 VideoProcessing_ErrorCode VideoProcessingCapiCapability::OpenGLInit()
372 {
373 auto status = SetupOpengl(openglContext_);
374 CHECK_AND_RETURN_RET_LOG(status == static_cast<int>(VIDEO_PROCESSING_SUCCESS),
375 VIDEO_PROCESSING_ERROR_OPERATION_NOT_PERMITTED,
376 "OpenGLInit SetupOpengl fail!");
377 return VIDEO_PROCESSING_SUCCESS;
378 }
379
GetOpenGLContext()380 std::shared_ptr<OpenGLContext> VideoProcessingCapiCapability::GetOpenGLContext()
381 {
382 return openglContext_;
383 }
384