1 /* 2 * Copyright (c) 2025 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 #ifndef INTERFACES_INNER_API_ALGORITHM_ALGORITHM_VIDEO_COMMON_H 17 #define INTERFACES_INNER_API_ALGORITHM_ALGORITHM_VIDEO_COMMON_H 18 19 #include <cstdint> 20 #include <memory> 21 #include <string_view> 22 23 #include "meta/format.h" 24 25 #include "algorithm_errors.h" 26 27 namespace OHOS { 28 namespace Media { 29 namespace VideoProcessingEngine { 30 enum class VPEAlgoState : int32_t { 31 UNINITIALIZED, 32 INITIALIZED, 33 CONFIGURING, 34 CONFIGURED, 35 STOPPED, 36 RUNNING, 37 EOS, 38 FLUSHED, 39 ERROR, 40 }; 41 42 /** 43 * @brief Feature type of video processing. 44 * 45 * @since 5.1 46 * @version 5.1 47 */ 48 enum VpeVideoType : uint32_t { 49 /** 50 * @brief Used to create an video processing object of detail enhancement. 51 * 52 * Scale or resize video with the specified quality or just enhance details for rendering without changing its 53 * resolution. 54 * 55 * @since 5.1 56 * @version 5.1 57 */ 58 VIDEO_TYPE_DETAIL_ENHANCER = 0x4, 59 VIDEO_TYPE_AIHDR_ENHANCER = 0x8, 60 }; 61 62 /** 63 * @brief Flag of video processing buffer. 64 * 65 * @since 5.1 66 * @version 5.1 67 */ 68 enum VpeBufferFlag : uint32_t { 69 VPE_BUFFER_FLAG_NONE = 0, 70 /** This signals the end of stream */ 71 VPE_BUFFER_FLAG_EOS = 1 << 0, 72 }; 73 74 /** 75 * @brief Information of video processing buffer. 76 * 77 * @since 5.1 78 * @version 5.1 79 */ 80 struct VpeBufferInfo { 81 /** The flag of the available output buffer. For details, see {@link VpeBufferFlag}. */ 82 VpeBufferFlag flag{VPE_BUFFER_FLAG_NONE}; 83 /** presentationTimestamp The presentation timestamp for the buffer. */ 84 int64_t presentationTimestamp{-1}; 85 }; 86 87 /** 88 * @brief Video processing callback base class, you can inherited it and only override partial methods as needed. 89 * 90 * @since 5.1 91 * @version 5.1 92 */ 93 class __attribute__((visibility("default"))) VpeVideoCallback { 94 public: 95 /** 96 * Called when an error occurred. 97 * 98 * @param errorCode Error code. For details, see {@link VPEAlgoErrCode}. 99 * @since 5.1 100 * @version 5.1 101 */ 102 virtual void OnError(VPEAlgoErrCode errorCode); 103 104 /** 105 * Called when switch new state. 106 * 107 * @param state Current state. For details, see {@link VPEAlgoState}. 108 * @since 5.1 109 * @version 5.1 110 */ 111 virtual void OnState(VPEAlgoState state); 112 113 /** 114 * Called when one of the features enable or disable effect. 115 * 116 * @param type Current enable processing type. For details, see {@link VpeVideoType}. 117 * If type is 0, no effect is enabled now. 118 * @since 5.1 119 * @version 5.1 120 */ 121 virtual void OnEffectChange(uint32_t type); 122 123 /** 124 * Called when an output format changed. 125 * 126 * @param format Output surfacebuffer format. 127 * @since 5.1 128 * @version 5.1 129 */ 130 virtual void OnOutputFormatChanged(const Format& format); 131 132 /** 133 * Called when an output buffer becomes available. 134 * 135 * @param index The index of the available output buffer. 136 * @param flag The flag of the available output buffer. For details, see {@link VpeBufferFlag}. 137 * @since 5.1 138 * @version 5.1 139 */ 140 virtual void OnOutputBufferAvailable(uint32_t index, VpeBufferFlag flag); 141 142 /** 143 * Called when an output buffer becomes available. 144 * 145 * @param index The index of the available output buffer. 146 * @param info The information of the available output buffer. For details, see {@link VpeBufferInfo}. 147 * @since 5.1 148 * @version 5.1 149 */ 150 virtual void OnOutputBufferAvailable(uint32_t index, const VpeBufferInfo& info); 151 152 protected: 153 VpeVideoCallback() = default; 154 virtual ~VpeVideoCallback() = default; 155 VpeVideoCallback(const VpeVideoCallback&) = delete; 156 VpeVideoCallback& operator=(const VpeVideoCallback&) = delete; 157 VpeVideoCallback(VpeVideoCallback&&) = delete; 158 VpeVideoCallback& operator=(VpeVideoCallback&&) = delete; 159 }; 160 161 /** 162 * @brief Width and height of the image buffer. 163 * 164 * It is the value of the key parameter {@link ParameterKey::DETAIL_ENHANCER_TARGET_SIZE}. 165 * 166 * @see VpeVideo::SetParameter 167 * @see VpeVideo::GetParameter 168 * @since 5.1 169 * @version 5.1 170 */ 171 struct VpeBufferSize { 172 int width{}; 173 int height{}; 174 }; 175 176 /** 177 * @brief The quality level is used for detail enhancement. 178 * 179 * It is the value of the key parameter {@link ParameterKey::DETAIL_ENHANCER_QUALITY_LEVEL}. 180 * 181 * @see VpeVideo::SetParameter 182 * @see VpeVideo::GetParameter 183 * @since 5.1 184 * @version 5.1 185 */ 186 enum DetailEnhancerQualityLevel { 187 /** No detail enhancement */ 188 DETAIL_ENHANCER_LEVEL_NONE = 0, 189 /** A low level of detail enhancement quality but with a fast speed. It's the default level */ 190 DETAIL_ENHANCER_LEVEL_LOW, 191 /** A medium level of detail enhancement quality. Its speed is between the low setting and high setting */ 192 DETAIL_ENHANCER_LEVEL_MEDIUM, 193 /** A high level of detail enhancement quality but with a relatively slow speed */ 194 DETAIL_ENHANCER_LEVEL_HIGH, 195 }; 196 197 /** 198 * @brief Contains the key corresponding to each paramter value. 199 * 200 * @see VpeVideo::SetParameter 201 * @see VpeVideo::GetParameter 202 * @since 5.1 203 * @version 5.1 204 */ 205 class ParameterKey { 206 public: 207 /** 208 * @brief The key is used to specify the quality level for video detail enhancement. 209 * 210 * See {@link DetailEnhancerQualityLevel} for its values. 211 * Use {@link VpeVideo::SetParameter} and {@link Format::SetIntValue} to set the quality level. 212 * Use {@link VpeVideo::GetParameter} and {@link Format::GetIntValue} to get the current quality level. 213 * 214 * @since 5.1 215 * @version 5.1 216 */ 217 static constexpr std::string_view DETAIL_ENHANCER_QUALITY_LEVEL{"QualityLevel"}; 218 219 /** 220 * @brief The key is used to specify width and height of the target image. 221 * 222 * See {@link VpeBufferSize} for its values. 223 * Use {@link VpeVideo::SetParameter} and {@link Format::SetBuffer} to set the size of the target image. 224 * Use {@link VpeVideo::GetParameter} and {@link Format::GetBuffer} to get the current size of the target image. 225 * 226 * @since 5.1 227 * @version 5.1 228 */ 229 static constexpr std::string_view DETAIL_ENHANCER_TARGET_SIZE{"TargetSize"}; 230 231 /** 232 * @brief The key is used to specify whether automatically downshift the quality level for detail 233 * enhancement or not. Default value is true. 234 * 235 * Use {@link VpeVideo::SetParameter} and {@link Format::SetIntValue} to set whether automatic downshift or not. 236 * Use {@link VpeVideo::GetParameter} and {@link Format::GetIntValue} to get whether automatic downshift or not. 237 * 238 * @since 5.1 239 * @version 5.1 240 */ 241 static constexpr std::string_view DETAIL_ENHANCER_AUTO_DOWNSHIFT{"AutoDownshift"}; 242 243 /** 244 * @brief The key is used to identifies surface nodeId 245 * 246 * Use {@link VpeVideo::SetParameter} and {@link Format::SetLongValue} to set the client surface nodeId. 247 * Use {@link VpeVideo::GetParameter} and {@link Format::GetLongValue} to get the client surface nodeId. 248 * 249 * @since 6.0 250 */ 251 static constexpr std::string_view DETAIL_ENHANCER_NODE_ID{"NodeId"}; 252 253 private: 254 ParameterKey() = delete; 255 ~ParameterKey() = delete; 256 ParameterKey(const ParameterKey&) = delete; 257 ParameterKey& operator=(const ParameterKey&) = delete; 258 ParameterKey(ParameterKey&&) = delete; 259 ParameterKey& operator=(ParameterKey&&) = delete; 260 }; 261 } // namespace VideoProcessingEngine 262 } // namespace Media 263 } // namespace OHOS 264 265 #endif // INTERFACES_INNER_API_ALGORITHM_ALGORITHM_VIDEO_COMMON_H 266