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_PHOTO_OUTPUT_H 17 #define OHOS_CAMERA_PHOTO_OUTPUT_H 18 19 #include <iostream> 20 #include "camera_metadata_info.h" 21 #include "capture_output.h" 22 #include "istream_capture.h" 23 24 namespace OHOS { 25 namespace CameraStandard { 26 class PhotoStateCallback { 27 public: 28 PhotoStateCallback() = default; 29 virtual ~PhotoStateCallback() = default; 30 31 /** 32 * @brief Called when camera capture started. 33 * 34 * @param captureID Obtain the constant capture id for the photo capture callback. 35 */ 36 virtual void OnCaptureStarted(const int32_t captureID) const = 0; 37 38 /** 39 * @brief Called when camera capture ended. 40 * 41 * @param captureID Obtain the constant capture id for the photo capture callback. 42 * @param frameCount Obtain the constant number of frames for the photo capture callback. 43 */ 44 virtual void OnCaptureEnded(const int32_t captureID, const int32_t frameCount) const = 0; 45 46 /** 47 * @brief Called when camera capture ended. 48 * 49 * @param captureId Obtain the constant capture id for the photo capture callback. 50 * @param timestamp Represents timestamp information for the photo capture callback 51 */ 52 virtual void OnFrameShutter(const int32_t captureId, const uint64_t timestamp) const = 0; 53 54 /** 55 * @brief Called when error occured during camera capture. 56 * 57 * @param captureId Indicates the pointer in which captureId will be requested. 58 * @param errorCode Indicates a {@link ErrorCode} which will give information for photo capture callback error 59 */ 60 virtual void OnCaptureError(const int32_t captureId, const int32_t errorCode) const = 0; 61 }; 62 63 class [[deprecated]] PhotoCallback { 64 public: 65 PhotoCallback() = default; 66 virtual ~PhotoCallback() = default; 67 68 /** 69 * @brief Called when camera capture started. 70 * 71 * @param captureID Obtain the constant capture id for the photo capture callback. 72 */ 73 virtual void OnCaptureStarted(const int32_t captureID) const = 0; 74 75 /** 76 * @brief Called when camera capture ended. 77 * 78 * @param captureID Obtain the constant capture id for the photo capture callback. 79 * @param frameCount Obtain the constant number of frames for the photo capture callback. 80 */ 81 virtual void OnCaptureEnded(const int32_t captureID, const int32_t frameCount) const = 0; 82 83 /** 84 * @brief Called when camera capture ended. 85 * 86 * @param captureId Obtain the constant capture id for the photo capture callback. 87 * @param timestamp Represents timestamp information for the photo capture callback 88 */ 89 virtual void OnFrameShutter(const int32_t captureId, const uint64_t timestamp) const = 0; 90 91 /** 92 * @brief Called when error occured during camera capture. 93 * 94 * @param captureId Indicates the pointer in which captureId will be requested. 95 * @param errorCode Indicates a {@link ErrorCode} which will give information for photo capture callback error 96 */ 97 virtual void OnCaptureError(const int32_t captureId, const int32_t errorCode) const = 0; 98 }; 99 100 typedef struct { 101 /** 102 * Latitude. 103 */ 104 double latitude; 105 /** 106 * Longitude. 107 */ 108 double longitude; 109 /** 110 * Altitude. 111 */ 112 double altitude; 113 } Location; 114 115 class PhotoCaptureSetting { 116 public: 117 enum QualityLevel { 118 QUALITY_LEVEL_LOW = 0, 119 QUALITY_LEVEL_MEDIUM, 120 QUALITY_LEVEL_HIGH, 121 HIGH_QUALITY [[deprecated]] = 0, 122 NORMAL_QUALITY [[deprecated]], 123 LOW_QUALITY [[deprecated]] 124 }; 125 enum RotationConfig { 126 Rotation_0 = 0, 127 Rotation_90 = 90, 128 Rotation_180 = 180, 129 Rotation_270 = 270 130 }; 131 PhotoCaptureSetting(); 132 virtual ~PhotoCaptureSetting() = default; 133 134 /** 135 * @brief Get the quality level for the photo capture settings. 136 * 137 * @return Returns the quality level. 138 */ 139 QualityLevel GetQuality(); 140 141 /** 142 * @brief Set the quality level for the photo capture settings. 143 * 144 * @param qualityLevel to be set. 145 */ 146 void SetQuality(QualityLevel qualityLevel); 147 148 /** 149 * @brief Get rotation information for the photo capture settings. 150 * 151 * @return Returns the RotationConfig. 152 */ 153 RotationConfig GetRotation(); 154 155 /** 156 * @brief Set the Rotation for the photo capture settings. 157 * 158 * @param rotationvalue to be set. 159 */ 160 void SetRotation(RotationConfig rotationvalue); 161 162 /** 163 * @brief Set the GPS Location for the photo capture settings. 164 * 165 * @param latitude value to be set. 166 * @param longitude value to be set. 167 */ 168 void SetGpsLocation(double latitude, double longitude); 169 170 /** 171 * @brief Set the GPS Location for the photo capture settings. 172 * 173 * @param location value to be set. 174 */ 175 void SetLocation(std::unique_ptr<Location> &location); 176 177 /** 178 * @brief Set the mirror option for the photo capture. 179 * 180 * @param boolean true/false to set/unset mirror respectively. 181 */ 182 void SetMirror(bool enable); 183 184 /** 185 * @brief Get the photo capture settings metadata information. 186 * 187 * @return Returns the pointer where CameraMetadata information is present. 188 */ 189 std::shared_ptr<OHOS::Camera::CameraMetadata> GetCaptureMetadataSetting(); 190 191 private: 192 std::shared_ptr<OHOS::Camera::CameraMetadata> captureMetadataSetting_; 193 }; 194 195 class PhotoOutput : public CaptureOutput { 196 public: 197 explicit PhotoOutput(sptr<IStreamCapture> &streamCapture); 198 virtual ~PhotoOutput(); 199 200 /** 201 * @brief Set the photo callback. 202 * 203 * @param callback Requested for the pointer where photo callback is present. 204 */ 205 void SetCallback(std::shared_ptr<PhotoStateCallback> callback); 206 207 /** 208 * @brief Set the photo callback. 209 * 210 * @param callback Requested for the pointer where photo callback is present. 211 */ 212 [[deprecated]] void SetCallback(std::shared_ptr<PhotoCallback> callback); 213 214 /** 215 * @brief Photo capture request using photocapturesettings. 216 * 217 * @param photoCaptureSettings Requested for the photoCaptureSettings object which has metadata 218 * information such as: Rotation, Location, Mirror & Quality. 219 */ 220 int32_t Capture(std::shared_ptr<PhotoCaptureSetting> photoCaptureSettings); 221 222 /** 223 * @brief Initiate for the photo capture. 224 */ 225 int32_t Capture(); 226 227 /** 228 * @brief cancelling the photo capture. Applicable only for burst/ continuous capture. 229 */ 230 int32_t CancelCapture(); 231 232 /** 233 * @brief Releases the instance of PhotoOutput. 234 */ 235 int32_t Release() override; 236 237 /** 238 * @brief Get the application callback information. 239 * 240 * @return Returns the pointer to PhotoStateCallback. 241 */ 242 std::shared_ptr<PhotoStateCallback> GetApplicationCallback(); 243 244 /** 245 * @brief To check the photo capture is mirrored or not. 246 * 247 * @return Returns true/false if the photo capture is mirrored/not-mirrored respectively. 248 */ 249 bool IsMirrorSupported(); 250 251 /** 252 * @brief Get default photo capture setting. 253 * 254 * @return default photo capture setting. 255 */ 256 std::shared_ptr<PhotoCaptureSetting> GetDefaultCaptureSetting(); 257 258 private: 259 std::shared_ptr<PhotoStateCallback> appCallback_; 260 sptr<IStreamCaptureCallback> cameraSvcCallback_; 261 std::shared_ptr<PhotoCaptureSetting> defaultCaptureSetting_; 262 }; 263 } // namespace CameraStandard 264 } // namespace OHOS 265 #endif // OHOS_CAMERA_PHOTO_OUTPUT_H 266