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 "hstream_repeat_stub.h" 28 #include "istream_repeat_callback.h" 29 #include "v1_0/istream_operator.h" 30 31 namespace OHOS { 32 namespace CameraStandard { 33 using OHOS::HDI::Camera::V1_0::BufferProducerSequenceable; 34 enum class RepeatStreamType { 35 PREVIEW, 36 VIDEO, 37 SKETCH, 38 LIVEPHOTO 39 }; 40 41 enum class RepeatStreamStatus { 42 STOPED, 43 STARTED 44 }; 45 #define CAMERA_ROTATION_TYPE_BASE 4 46 #define CAMERA_API_VERSION_BASE 14 47 class EXPORT_API HStreamRepeat : public HStreamRepeatStub, public HStreamCommon { 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(sptr<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(sptr<IStreamRepeatCallback>& callback) override; 63 int32_t OnFrameStarted(); 64 int32_t OnFrameEnded(int32_t frameCount); 65 int32_t OnFrameError(int32_t errorType); 66 int32_t OnSketchStatusChanged(SketchStatus status); 67 int32_t OnDeferredVideoEnhancementInfo(CaptureEndedInfoExt captureEndedInfo); 68 int32_t AddDeferredSurface(const sptr<OHOS::IBufferProducer>& producer) override; 69 int32_t ForkSketchStreamRepeat( 70 int32_t width, int32_t height, sptr<IStreamRepeat>& sketchStream, float sketchRatio) override; 71 int32_t RemoveSketchStreamRepeat() override; 72 int32_t EnableSecure(bool isEnable = false) override; 73 int32_t UpdateSketchRatio(float sketchRatio) override; 74 sptr<HStreamRepeat> GetSketchStream(); 75 RepeatStreamType GetRepeatStreamType(); 76 void SetMetaProducer(sptr<OHOS::IBufferProducer> metaProducer); 77 void SetMovingPhotoStartCallback(std::function<void()> callback); 78 void DumpStreamInfo(CameraInfoDumper& infoDumper) override; 79 int32_t OperatePermissionCheck(uint32_t interfaceCode) override; 80 int32_t SetFrameRate(int32_t minFrameRate, int32_t maxFrameRate) override; 81 int32_t SetMirror(bool isEnable) override; 82 int32_t GetMirror(bool& isEnable) override; 83 int32_t SetPreviewRotation(std::string &deviceClass); 84 bool SetMirrorForLivePhoto(bool isEnable, int32_t mode); 85 void SetStreamTransform(int disPlayRotation = -1); 86 void SetUsedAsPosition(camera_position_enum_t cameraPosition); 87 int32_t AttachMetaSurface(const sptr<OHOS::IBufferProducer>& producer, int32_t videoMetaType) override; 88 int32_t SetCameraRotation(bool isEnable, int32_t rotation) override; 89 int32_t SetCameraApi(uint32_t apiCompatibleVersion) override; 90 private: 91 void OpenVideoDfxSwitch(std::shared_ptr<OHOS::Camera::CameraMetadata> settings); 92 void StartSketchStream(std::shared_ptr<OHOS::Camera::CameraMetadata> settings); 93 void UpdateSketchStatus(SketchStatus status); 94 void ProcessFixedTransform(int32_t& sensorOrientation, camera_position_enum_t& cameraPosition); 95 void ProcessCameraSetRotation(int32_t& sensorOrientation, camera_position_enum_t& cameraPosition); 96 void ProcessVerticalCameraPosition(int32_t& sensorOrientation, camera_position_enum_t& cameraPosition); 97 void ProcessFixedDiffDeviceTransform(camera_position_enum_t& cameraPosition); 98 void ProcessCameraPosition(int32_t& streamRotation, camera_position_enum_t& cameraPosition); 99 void UpdateVideoSettings(std::shared_ptr<OHOS::Camera::CameraMetadata> settings); 100 void UpdateFrameRateSettings(std::shared_ptr<OHOS::Camera::CameraMetadata> settings); 101 void UpdateFrameMuteSettings(std::shared_ptr<OHOS::Camera::CameraMetadata> &settings, 102 std::shared_ptr<OHOS::Camera::CameraMetadata> &dynamicSetting); 103 #ifdef NOTIFICATION_ENABLE 104 void UpdateBeautySettings(std::shared_ptr<OHOS::Camera::CameraMetadata> &settings); 105 void CancelNotification(); 106 bool IsNeedBeautyNotification(); 107 #endif 108 109 RepeatStreamType repeatStreamType_; 110 sptr<IStreamRepeatCallback> streamRepeatCallback_; 111 std::mutex callbackLock_; 112 std::mutex sketchStreamLock_; // Guard sketchStreamRepeat_ 113 std::mutex streamStartStopLock_; 114 sptr<HStreamRepeat> sketchStreamRepeat_; 115 wptr<HStreamRepeat> parentStreamRepeat_; 116 float sketchRatio_ = -1.0f; 117 SketchStatus sketchStatus_ = SketchStatus::STOPED; 118 RepeatStreamStatus repeatStreamStatus_ = RepeatStreamStatus::STOPED; 119 bool mEnableSecure = false; 120 bool enableMirror_ = false; 121 bool enableStreamRotate_ = false; 122 bool enableCameraRotation_ = false; 123 int32_t setCameraRotation_ = 0; 124 uint32_t apiCompatibleVersion_ = 0; 125 std::string deviceClass_ = "phone"; 126 sptr<OHOS::IBufferProducer> metaProducer_; 127 std::mutex movingPhotoCallbackLock_; 128 std::function<void()> startMovingPhotoCallback_; 129 std::vector<int32_t> streamFrameRateRange_ = {}; 130 sptr<BufferProducerSequenceable> metaSurfaceBufferQueue_; 131 camera_position_enum_t cameraUsedAsPosition_ = OHOS_CAMERA_POSITION_OTHER; 132 }; 133 } // namespace CameraStandard 134 } // namespace OHOS 135 #endif // OHOS_CAMERA_H_STREAM_REPEAT_H 136