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