1 /* 2 * Copyright (c) 2021-2022 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 OHOS_CAMERA_OUTPUT_CAPABILITY_H 17 #define OHOS_CAMERA_OUTPUT_CAPABILITY_H 18 19 #include <cstdint> 20 #include <iostream> 21 #include <refbase.h> 22 #include <stdint.h> 23 #include <vector> 24 25 #include "istream_repeat_callback.h" 26 #include "istream_metadata.h" 27 28 namespace OHOS { 29 namespace CameraStandard { 30 static constexpr float RATIO_VALUE_1_1 = 1.0f; 31 static constexpr float RATIO_VALUE_4_3 = 4.0f / 3; 32 static constexpr float RATIO_VALUE_16_9 = 16.0f / 9; 33 typedef struct { 34 uint32_t width; 35 uint32_t height; 36 } Size; 37 38 typedef struct { 39 uint32_t fixedFps; 40 uint32_t minFps; 41 uint32_t maxFps; 42 } Fps; 43 44 enum CameraFormat : int32_t { 45 CAMERA_FORMAT_INVALID = -1, 46 CAMERA_FORMAT_YCBCR_420_888 = 2, 47 CAMERA_FORMAT_RGBA_8888 = 3, 48 CAMERA_FORMAT_DNG = 4, 49 CAMERA_FORMAT_DNG_XDRAW = 5, 50 CAMERA_FORMAT_YUV_420_SP = 1003, 51 CAMERA_FORMAT_NV12 = 1004, 52 CAMERA_FORMAT_YUV_422_YUYV = 1005, 53 CAMERA_FORMAT_YUV_422_UYVY = 1006, 54 CAMERA_FORMAT_JPEG = 2000, 55 CAMERA_FORMAT_YCBCR_P010 = 2001, 56 CAMERA_FORMAT_YCRCB_P010 = 2002, 57 CAMERA_FORMAT_HEIC = 2003, 58 CAMERA_FORMAT_DEPTH_16 = 3000, 59 CAMERA_FORMAT_DEPTH_32 = 3001, 60 CAMERA_FORMAT_MJPEG = 3002, 61 }; 62 63 enum DepthDataAccuracy { 64 DEPTH_DATA_ACCURACY_INVALID = -1, 65 DEPTH_DATA_ACCURACY_RELATIVE = 0, 66 DEPTH_DATA_ACCURACY_ABSOLUTE = 1, 67 }; 68 69 enum ProfileSizeRatio : int32_t { 70 UNSPECIFIED = -1, 71 RATIO_1_1 = 0, 72 RATIO_4_3 = 1, 73 RATIO_16_9 = 2, 74 }; 75 76 class Profile { 77 public: 78 Profile(CameraFormat format, Size size); 79 Profile(CameraFormat format, Size size, int32_t specId); 80 Profile(CameraFormat format, Size size, Fps fps, std::vector<uint32_t> abilityId); 81 Profile(CameraFormat format, Size size, Fps fps, std::vector<uint32_t> abilityId, int32_t specId); 82 Profile() = default; 83 Profile& operator=(const Profile& profile) 84 { 85 if (this != &profile) { 86 this->format_ = profile.format_; 87 this->size_ = profile.size_; 88 this->fps_ = profile.fps_; 89 this->abilityId_ = profile.abilityId_; 90 } 91 return *this; 92 } 93 bool operator==(const Profile& profile) 94 { 95 return this->format_ == profile.format_ && this->size_.width == profile.size_.width && 96 this->size_.height == profile.size_.height; 97 } 98 virtual ~Profile() = default; 99 100 /** 101 * @brief Get camera format of the profile. 102 * 103 * @return camera format of the profile. 104 */ 105 CameraFormat GetCameraFormat(); 106 107 /** 108 * @brief Get resolution of the profile. 109 * 110 * @return resolution of the profile. 111 */ 112 Size GetSize(); 113 114 Fps GetFps(); 115 116 std::vector<uint32_t> GetAbilityId(); 117 118 int32_t GetSpecId(); 119 120 void DumpProfile(std::string name) const; 121 122 CameraFormat format_ = CAMERA_FORMAT_INVALID; 123 Size size_ = { 0, 0 }; 124 bool sizeFollowSensorMax_ = false; 125 ProfileSizeRatio sizeRatio_ = UNSPECIFIED; 126 Fps fps_ = { 0, 0, 0 }; 127 std::vector<uint32_t> abilityId_ = {}; 128 int32_t specId_; 129 }; 130 131 class VideoProfile : public Profile { 132 public: 133 VideoProfile(CameraFormat format, Size size, std::vector<int32_t> framerates); 134 VideoProfile(CameraFormat format, Size size, std::vector<int32_t> framerates, int32_t specId); 135 VideoProfile() = default; 136 virtual ~VideoProfile() = default; 137 VideoProfile& operator=(const VideoProfile& rhs) 138 { 139 Profile::operator=(rhs); 140 this->framerates_ = rhs.framerates_; 141 return *this; 142 } 143 144 bool operator==(const VideoProfile& profile) 145 { 146 return this->format_ == profile.format_ && this->size_.width == profile.size_.width && 147 this->size_.height == profile.size_.height && this->framerates_[0] == profile.framerates_[0] && 148 this->framerates_[1] == profile.framerates_[1]; 149 } 150 151 bool IsContains(const VideoProfile& videoProfile); 152 153 /** 154 * @brief Get supported framerates of the profile. 155 * 156 * @return vector of supported framerate. 157 */ 158 std::vector<int32_t> GetFrameRates(); 159 160 std::vector<int32_t> framerates_ = {}; 161 162 void DumpVideoProfile(std::string name) const; 163 }; 164 165 class DepthProfile : public Profile { 166 public: 167 DepthProfile(CameraFormat format, DepthDataAccuracy dataAccuracy, Size size); 168 DepthProfile() = default; 169 virtual ~DepthProfile() = default; 170 DepthProfile& operator=(const DepthProfile& rhs) 171 { 172 Profile::operator=(rhs); 173 this->dataAccuracy_ = rhs.dataAccuracy_; 174 return *this; 175 } 176 DepthDataAccuracy GetDataAccuracy(); 177 DepthDataAccuracy dataAccuracy_; 178 }; 179 180 float GetTargetRatio(ProfileSizeRatio sizeRatio, float unspecifiedValue); 181 bool IsProfileSameRatio(Profile& srcProfile, ProfileSizeRatio sizeRatio, float unspecifiedValue); 182 183 class CameraOutputCapability : public RefBase { 184 public: 185 CameraOutputCapability() = default; 186 virtual ~CameraOutputCapability() = default; 187 188 /** 189 * @brief Get Photo profiles. 190 * 191 * @return vector of supported photo profiles. 192 */ 193 std::vector<Profile> GetPhotoProfiles(); 194 195 /** 196 * @brief Set Photo profiles. 197 * 198 * @param vector of photo profiles. 199 */ 200 void SetPhotoProfiles(std::vector<Profile> photoProfiles); 201 202 /** 203 * @brief Get Preview profiles. 204 * 205 * @return vector of supported preview profiles. 206 */ 207 std::vector<Profile> GetPreviewProfiles(); 208 209 /** 210 * @brief Set preview profiles. 211 * 212 * @param vector of preview profiles. 213 */ 214 void SetPreviewProfiles(std::vector<Profile> previewProfiles); 215 216 /** 217 * @brief Get video profiles. 218 * 219 * @return vector of supported video profiles. 220 */ 221 std::vector<VideoProfile> GetVideoProfiles(); 222 223 /** 224 * @brief Set video profiles. 225 * 226 * @param vector of video profiles. 227 */ 228 void SetVideoProfiles(std::vector<VideoProfile> videoProfiles); 229 230 /** 231 * @brief Get Depth profiles. 232 * 233 * @return vector of supported depth profiles. 234 */ 235 std::vector<DepthProfile> GetDepthProfiles(); 236 237 /** 238 * @brief Set depth profiles. 239 * 240 * @param vector of depth profiles. 241 */ 242 void SetDepthProfiles(std::vector<DepthProfile> depthProfiles); 243 244 /** 245 * @brief Get supported meta object types. 246 * 247 * @return vector of supported metadata object types. 248 */ 249 std::vector<MetadataObjectType> GetSupportedMetadataObjectType(); 250 251 /** 252 * @brief Get supported meta object types. 253 * 254 * @return vector of supported metadata object types. 255 */ 256 void SetSupportedMetadataObjectType(std::vector<MetadataObjectType> metadataObjTypes); 257 258 int32_t specId_ = -1; 259 260 bool IsMatchPreviewProfiles(std::vector<Profile>& previewProfiles); 261 bool IsMatchPhotoProfiles(std::vector<Profile>& photoProfiles); 262 bool IsMatchVideoProfiles(std::vector<VideoProfile>& videoProfiles); 263 void RemoveDuplicatesProfiles(); 264 private: 265 std::vector<Profile> photoProfiles_ = {}; 266 std::vector<Profile> previewProfiles_ = {}; 267 std::vector<VideoProfile> videoProfiles_ = {}; 268 std::vector<DepthProfile> depthProfiles_ = {}; 269 std::vector<MetadataObjectType> metadataObjTypes_ = {}; 270 271 template <typename T> 272 void RemoveDuplicatesProfile(std::vector<T>& profiles); 273 }; 274 } // namespace CameraStandard 275 } // namespace OHOS 276 #endif // OHOS_CAMERA_OUTPUT_CAPABILITY_H 277