• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_CAMERA_LARGE_SYSTEM_CAMERA_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_CAMERA_LARGE_SYSTEM_CAMERA_H
18 
19 #include <list>
20 
21 #include "core/components/camera/camera_component.h"
22 #include "core/components/common/layout/constants.h"
23 #include "core/components/video/resource/resource.h"
24 #include "core/components/video/resource/texture.h"
25 
26 namespace OHOS::Ace {
27 
28 class Camera : public Resource {
29     DECLARE_ACE_TYPE(Camera, Resource);
30 
31 public:
32     using TakePhotoListener = std::function<void(const std::map<std::string, std::string>&)>;
33     using ErrorListener = std::function<void(const std::string&, const std::string&)>;
34     using SizeChangeListener = std::function<void(int32_t, int32_t)>;
35     using PrepareEventListener = std::function<void()>;
36 
Camera(int64_t textureId,const WeakPtr<PipelineContext> & context,ErrorCallback && onError,DevicePosition devicePosition)37     Camera(int64_t textureId, const WeakPtr<PipelineContext>& context, ErrorCallback&& onError,
38         DevicePosition devicePosition) : Resource("camera", context, std::move(onError)),
39         textureId_(textureId), devicePosition_(devicePosition) {}
40     ~Camera() override = default;
41 
42     void Release(const std::function<void(bool)>& onRelease = nullptr) override;
43     void Create(const std::function<void(int64_t)>& onCreate);
44     void CreateCamera(const std::function<void(int64_t)>& onCreate);
45     void OpenCamera();
46 
47     void TakePhoto(int32_t quality);
48     void SetFlashMode(FlashType flash);
49     void SetPreViewSize(int32_t width, int32_t height);
50     void AddTakePhotoListener(TakePhotoListener&& listener);
51     void AddErrorListener(ErrorListener&& listener);
52     void AddPreViewSizeChang(SizeChangeListener&& listener);
53     void AddPrepareEventListener(PrepareEventListener&& listener);
54 
SetBufferSize(Size bufferSize)55     void SetBufferSize(Size bufferSize)
56     {
57         bufferSize_ = bufferSize;
58     }
59 
SetDeviceOrientation(bool isPortrait)60     void SetDeviceOrientation(bool isPortrait)
61     {
62         isPortrait_ = isPortrait;
63     }
64 
65     void ChangeCameraComponentId(bool changType, std::string id);
66 
67 private:
68     void OnAddTakePhotoListener(TakePhotoListener&& listener);
69     void OnAddErrorListener(ErrorListener&& listener);
70     void UnRegisterEvent();
71 
72     void OnTakePhoto(const std::string& param);
73     void OnError(const std::string& param);
74     void OnPreViewSizeChang(const std::string& param);
75     void OnPrepare(const std::string& param);
76 
77     int64_t textureId_ = INVALID_ID;
78     bool isPortrait_ = true;
79 
80     TakePhotoListener takePhotoListener_;
81     ErrorListener onErrorListener_;
82     SizeChangeListener onSizeChangeListener_;
83     PrepareEventListener prepareEventListener_;
84 
85     DevicePosition devicePosition_ = DevicePosition::CAMERA_FACING_FRONT;
86     Size bufferSize_; // default buffer size
87 };
88 
89 } // namespace OHOS::Ace
90 
91 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_CAMERA_LARGE_SYSTEM_CAMERA_H
92