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