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