• 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_H_STREAM_REPEAT_H
17 #define OHOS_CAMERA_H_STREAM_REPEAT_H
18 #define EXPORT_API __attribute__((visibility("default")))
19 
20 #include <cstdint>
21 #include <functional>
22 #include <iostream>
23 #include <refbase.h>
24 
25 #include "camera_metadata_info.h"
26 #include "hstream_common.h"
27 #include "stream_repeat_stub.h"
28 #include "istream_repeat_callback.h"
29 #include "v1_0/istream_operator.h"
30 #include "icamera_ipc_checker.h"
31 
32 namespace OHOS {
33 namespace CameraStandard {
34 using OHOS::HDI::Camera::V1_0::BufferProducerSequenceable;
35 enum class RepeatStreamType {
36     PREVIEW,
37     VIDEO,
38     SKETCH,
39     LIVEPHOTO
40 };
41 
42 enum class RepeatStreamStatus {
43     STOPED,
44     STARTED
45 };
46 #define CAMERA_API_VERSION_BASE 14
47 class EXPORT_API HStreamRepeat : public StreamRepeatStub, public HStreamCommon, public ICameraIpcChecker {
48 public:
49     HStreamRepeat(
50         sptr<OHOS::IBufferProducer> producer, int32_t format, int32_t width, int32_t height, RepeatStreamType type);
51     ~HStreamRepeat();
52 
53     int32_t LinkInput(wptr<OHOS::HDI::Camera::V1_0::IStreamOperator> streamOperator,
54         std::shared_ptr<OHOS::Camera::CameraMetadata> cameraAbility) override;
55     void SetStreamInfo(StreamInfo_V1_1& streamInfo) override;
56     void SetVideoStreamInfo(StreamInfo_V1_1& streamInfo);
57     int32_t ReleaseStream(bool isDelay) override;
58     int32_t Release() override;
59     int32_t Start() override;
60     int32_t Start(std::shared_ptr<OHOS::Camera::CameraMetadata> settings, bool isUpdateSeetings = false);
61     int32_t Stop() override;
62     int32_t SetCallback(const sptr<IStreamRepeatCallback>& callback) override;
63     int32_t UnSetCallback() override;
64 
65     int32_t OnFrameStarted();
66     int32_t OnFrameEnded(int32_t frameCount);
67     int32_t OnFrameError(int32_t errorType);
68     int32_t OnSketchStatusChanged(SketchStatus status);
69     int32_t OnDeferredVideoEnhancementInfo(CaptureEndedInfoExt captureEndedInfo);
70     int32_t AddDeferredSurface(const sptr<OHOS::IBufferProducer>& producer) override;
71     int32_t ForkSketchStreamRepeat(
72         int32_t width, int32_t height, sptr<IRemoteObject>& sketchStream, float sketchRatio) override;
73     int32_t RemoveSketchStreamRepeat() override;
74     int32_t EnableSecure(bool isEnable = false) override;
75     int32_t UpdateSketchRatio(float sketchRatio) override;
76     sptr<HStreamRepeat> GetSketchStream();
77     RepeatStreamType GetRepeatStreamType();
78     void SetMetaProducer(sptr<OHOS::IBufferProducer> metaProducer);
79     void SetMovingPhotoStartCallback(std::function<void()> callback);
80     void DumpStreamInfo(CameraInfoDumper& infoDumper) override;
81     int32_t OperatePermissionCheck(uint32_t interfaceCode) override;
82     int32_t CallbackEnter([[maybe_unused]] uint32_t code) override;
83     int32_t CallbackExit([[maybe_unused]] uint32_t code, [[maybe_unused]] int32_t result) override;
84     int32_t SetFrameRate(int32_t minFrameRate, int32_t maxFrameRate) override;
85     int32_t SetMirror(bool isEnable) override;
86     int32_t GetMirror(bool& isEnable) override;
87     bool SetMirrorForLivePhoto(bool isEnable, int32_t mode);
88     int32_t SetPreviewRotation(std::string &deviceClass);
89     void SetStreamTransform(int disPlayRotation = -1);
90     void SetUsedAsPosition(camera_position_enum_t cameraPosition);
91     int32_t AttachMetaSurface(const sptr<OHOS::IBufferProducer>& producer, int32_t videoMetaType) override;
92     int32_t SetCameraRotation(bool isEnable, int32_t rotation) override;
93     int32_t SetCameraApi(uint32_t apiCompatibleVersion) override;
94     std::vector<int32_t> GetFrameRateRange();
95     int32_t SetCurrentMode(int32_t mode);
96 
97 private:
98     void OpenVideoDfxSwitch(std::shared_ptr<OHOS::Camera::CameraMetadata> settings);
99     void StartSketchStream(std::shared_ptr<OHOS::Camera::CameraMetadata> settings);
100     void UpdateSketchStatus(SketchStatus status);
101     void ProcessVerticalCameraPosition(int32_t& sensorOrientation, camera_position_enum_t& cameraPosition);
102     void ProcessFixedTransform(int32_t& sensorOrientation, camera_position_enum_t& cameraPosition);
103     void ProcessFixedDiffDeviceTransform(int32_t& sensorOrientation, camera_position_enum_t& cameraPosition);
104     void ProcessCameraPosition(int32_t& streamRotation, camera_position_enum_t& cameraPosition);
105     int32_t HandleCameraTransform(int32_t& streamRotation, bool isFrontCamera);
106     void ProcessCameraSetRotation(int32_t& streamRotation, camera_position_enum_t& cameraPosition);
107     void UpdateVideoSettings(std::shared_ptr<OHOS::Camera::CameraMetadata> settings, uint8_t mirror = 0);
108     void UpdateFrameRateSettings(std::shared_ptr<OHOS::Camera::CameraMetadata> settings);
109     void UpdateFrameMuteSettings(std::shared_ptr<OHOS::Camera::CameraMetadata> &settings,
110                                  std::shared_ptr<OHOS::Camera::CameraMetadata> &dynamicSetting);
111     void UpdateFrameMechSettings(std::shared_ptr<OHOS::Camera::CameraMetadata> &settings,
112                                  std::shared_ptr<OHOS::Camera::CameraMetadata> &dynamicSetting);
113     void SyncTransformToSketch();
114     void UpdateHalRoateSettings(std::shared_ptr<OHOS::Camera::CameraMetadata> settings);
115 #ifdef NOTIFICATION_ENABLE
116     void UpdateBeautySettings(std::shared_ptr<OHOS::Camera::CameraMetadata> &settings);
117     void CancelNotification();
118     bool IsNeedBeautyNotification();
119 #endif
120     void SetSketchStreamInfo(StreamInfo_V1_1& streamInfo);
121     bool CheckVideoModeForSystemApp(int32_t sceneMode);
122 
123     RepeatStreamType repeatStreamType_;
124     sptr<IStreamRepeatCallback> streamRepeatCallback_;
125     std::mutex callbackLock_;
126     std::mutex sketchStreamLock_; // Guard sketchStreamRepeat_
127     std::mutex streamStartStopLock_;
128     sptr<HStreamRepeat> sketchStreamRepeat_;
129     wptr<HStreamRepeat> parentStreamRepeat_;
130     float sketchRatio_ = -1.0f;
131     SketchStatus sketchStatus_ = SketchStatus::STOPED;
132     RepeatStreamStatus repeatStreamStatus_ = RepeatStreamStatus::STOPED;
133     bool mEnableSecure = false;
134     bool enableMirror_ = false;
135     bool enableStreamRotate_ = false;
136     bool enableCameraRotation_ = false;
137     int32_t setCameraRotation_ = 0;
138     uint32_t apiCompatibleVersion_ = 0;
139     std::string deviceClass_ = "phone";
140     sptr<OHOS::IBufferProducer> metaProducer_;
141     std::mutex movingPhotoCallbackLock_;
142     std::function<void()> startMovingPhotoCallback_;
143     std::vector<int32_t> streamFrameRateRange_ = {};
144     sptr<BufferProducerSequenceable> metaSurfaceBufferQueue_;
145     camera_position_enum_t cameraUsedAsPosition_ = OHOS_CAMERA_POSITION_OTHER;
146     int32_t currentMode_ = 0;
147 };
148 } // namespace CameraStandard
149 } // namespace OHOS
150 #endif // OHOS_CAMERA_H_STREAM_REPEAT_H
151