• 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_CAPTURE_OUTPUT_H
17 #define OHOS_CAMERA_CAPTURE_OUTPUT_H
18 
19 #include <cstdint>
20 #include <mutex>
21 #include <refbase.h>
22 #include <set>
23 #include <type_traits>
24 #include <unordered_set>
25 #include <vector>
26 
27 #include "camera_device_ability_items.h"
28 #include "camera_error_code.h"
29 #include "camera_metadata_operator.h"
30 #include "camera_output_capability.h"
31 #include "icamera_util.h"
32 #include "input/camera_death_recipient.h"
33 #include "istream_common.h"
34 
35 namespace OHOS {
36 class IBufferProducer;
37 namespace CameraStandard {
38 enum DeferredDeliveryImageType {
39     DELIVERY_NONE = 0,
40     DELIVERY_PHOTO,
41     DELIVERY_VIDEO,
42 };
43 enum CaptureOutputType {
44     CAPTURE_OUTPUT_TYPE_PREVIEW,
45     CAPTURE_OUTPUT_TYPE_PHOTO,
46     CAPTURE_OUTPUT_TYPE_VIDEO,
47     CAPTURE_OUTPUT_TYPE_METADATA,
48     CAPTURE_OUTPUT_TYPE_DEPTH_DATA,
49     CAPTURE_OUTPUT_TYPE_MAX
50 };
51 
52 class MetadataObserver {
53 public:
54     /**
55      * @brief Get Observed matadata tags
56      *        Register tags into capture session. If the tags data changes,{@link OnControlMetadataChanged} will be
57      *        called.
58      * @return Observed tags
59      */
GetObserverControlTags()60     virtual const std::set<camera_device_metadata_tag_t>& GetObserverControlTags()
61     {
62         // Empty impl
63         const static std::set<camera_device_metadata_tag_t> tags = {};
64         return tags;
65     };
66 
67     /**
68      * @brief Get Observed matadata tags
69      *        Register tags into capture session. If the tags data changes,{@link OnResultMetadataChanged} will be
70      *        called.
71      * @return Observed tags
72      */
GetObserverResultTags()73     virtual const std::set<camera_device_metadata_tag_t>& GetObserverResultTags()
74     {
75         // Empty impl
76         const static std::set<camera_device_metadata_tag_t> tags = {};
77         return tags;
78     };
79 
80     /**
81      * @brief Callback of request metadata change.
82      * @return Operate result
83      */
OnControlMetadataChanged(const camera_device_metadata_tag_t tag,const camera_metadata_item_t & metadataItem)84     virtual int32_t OnControlMetadataChanged(
85         const camera_device_metadata_tag_t tag, const camera_metadata_item_t& metadataItem)
86     {
87         // Empty impl
88         return CAM_META_SUCCESS;
89     };
90 
91     /**
92      * @brief Callback of result metadata change.
93      * @return Operate result
94      */
OnResultMetadataChanged(const camera_device_metadata_tag_t tag,const camera_metadata_item_t & metadataItem)95     virtual int32_t OnResultMetadataChanged(
96         const camera_device_metadata_tag_t tag, const camera_metadata_item_t& metadataItem)
97     {
98         // Empty impl
99         return CAM_META_SUCCESS;
100     };
101 };
102 
103 class CaptureSession;
104 class CaptureOutput : virtual public RefBase, public MetadataObserver {
105 public:
106     enum Tag { DYNAMIC_PROFILE };
107     enum ImageRotation {
108         ROTATION_0 = 0,
109         ROTATION_90 = 90,
110         ROTATION_180 = 180,
111         ROTATION_270 = 270
112     };
113     explicit CaptureOutput(CaptureOutputType outputType, StreamType streamType, sptr<IBufferProducer> bufferProducer,
114         sptr<IStreamCommon> stream);
115     explicit CaptureOutput(CaptureOutputType outputType, StreamType streamType, sptr<IStreamCommon> stream);
116     virtual ~CaptureOutput();
117 
118     /**
119      * @brief Releases the instance of CaptureOutput.
120      */
121     virtual int32_t Release() = 0;
122 
123     CaptureOutputType GetOutputType();
124     const char* GetOutputTypeString();
125     StreamType GetStreamType();
126     sptr<IStreamCommon> GetStream();
127     virtual void SetStream(sptr<IStreamCommon> stream);
128     bool IsStreamCreated();
129     sptr<CaptureSession> GetSession();
130     void SetSession(wptr<CaptureSession> captureSession);
131     std::mutex asyncOpMutex_;
132     std::mutex outputCallbackMutex_;
133     void SetPhotoProfile(Profile& profile);
134     std::shared_ptr<Profile> GetPhotoProfile();
135     void SetPreviewProfile(Profile& profile);
136     std::shared_ptr<Profile> GetPreviewProfile();
137     void SetVideoProfile(VideoProfile& videoProfile);
138     std::shared_ptr<VideoProfile> GetVideoProfile();
139     void SetDepthProfile(DepthProfile& depthProfile);
140     std::shared_ptr<DepthProfile> GetDepthProfile();
141     void ClearProfiles();
142     virtual void CameraServerDied(pid_t pid) = 0;
143 
144     virtual int32_t CreateStream() = 0;
145 
146     bool IsHasEnableOfflinePhoto();
147 
148     virtual void AddTag(Tag tag) final;
149     virtual void RemoveTag(Tag tag) final;
150     virtual bool IsTagSetted(Tag tag) final;
151 
152 protected:
153     virtual sptr<IBufferProducer> GetBufferProducer() final;
154     virtual std::string GetPhotoSurfaceId() final;
155 
156 private:
157     void OnCameraServerDied(pid_t pid);
158     void RegisterStreamBinderDied();
159     void UnregisterStreamBinderDied();
160 
161     std::mutex deathRecipientMutex_;
162     sptr<CameraDeathRecipient> deathRecipient_ = nullptr;
163 
164     CaptureOutputType outputType_;
165     StreamType streamType_;
166     sptr<IStreamCommon> stream_;
167     wptr<CaptureSession> session_;
168     std::mutex sessionMutex_;
169     std::mutex streamMutex_;
170     std::string surfaceId_;
171 
172     // Multithread add same output,set profile may cause problems, let's add mutex guard.
173     std::mutex photoProfileMutex_;
174     std::shared_ptr<Profile> photoProfile_;
175     std::mutex previewProfileMutex_;
176     std::shared_ptr<Profile> previewProfile_;
177     std::mutex videoProfileMutex_;
178     std::shared_ptr<VideoProfile> videoProfile_;
179     std::mutex depthProfileMutex_;
180     std::shared_ptr<DepthProfile> depthProfile_;
181 
182     std::mutex bufferProducerMutex_;
183     sptr<IBufferProducer> bufferProducer_;
184 
185     std::mutex tagsMutex_;
186     std::unordered_set<Tag> tags_;
187     bool mIsHasEnableOfflinePhoto_ = false;
188 };
189 } // namespace CameraStandard
190 } // namespace OHOS
191 #endif // OHOS_CAMERA_CAPTURE_OUTPUT_H
192