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_API_VERSION_BASE 14 46 class EXPORT_API HStreamRepeat : public HStreamRepeatStub, public HStreamCommon { 47 public: 48 HStreamRepeat( 49 sptr<OHOS::IBufferProducer> producer, int32_t format, int32_t width, int32_t height, RepeatStreamType type); 50 ~HStreamRepeat(); 51 52 int32_t LinkInput(wptr<OHOS::HDI::Camera::V1_0::IStreamOperator> streamOperator, 53 std::shared_ptr<OHOS::Camera::CameraMetadata> cameraAbility) override; 54 void SetStreamInfo(StreamInfo_V1_1& streamInfo) override; 55 void SetVideoStreamInfo(StreamInfo_V1_1& streamInfo); 56 int32_t ReleaseStream(bool isDelay) override; 57 int32_t Release() override; 58 int32_t Start() override; 59 int32_t Start(std::shared_ptr<OHOS::Camera::CameraMetadata> settings, bool isUpdateSeetings = false); 60 int32_t Stop() override; 61 int32_t SetCallback(sptr<IStreamRepeatCallback>& callback) override; 62 int32_t UnSetCallback() override; 63 64 int32_t OnFrameStarted(); 65 int32_t OnFrameEnded(int32_t frameCount); 66 int32_t OnFrameError(int32_t errorType); 67 int32_t OnSketchStatusChanged(SketchStatus status); 68 int32_t OnDeferredVideoEnhancementInfo(CaptureEndedInfoExt captureEndedInfo); 69 int32_t AddDeferredSurface(const sptr<OHOS::IBufferProducer>& producer) override; 70 int32_t ForkSketchStreamRepeat( 71 int32_t width, int32_t height, sptr<IStreamRepeat>& sketchStream, float sketchRatio) override; 72 int32_t RemoveSketchStreamRepeat() override; 73 int32_t EnableSecure(bool isEnable = false) override; 74 int32_t UpdateSketchRatio(float sketchRatio) override; 75 sptr<HStreamRepeat> GetSketchStream(); 76 RepeatStreamType GetRepeatStreamType(); 77 void SetMetaProducer(sptr<OHOS::IBufferProducer> metaProducer); 78 void SetMovingPhotoStartCallback(std::function<void()> callback); 79 void DumpStreamInfo(CameraInfoDumper& infoDumper) override; 80 int32_t OperatePermissionCheck(uint32_t interfaceCode) override; 81 int32_t SetFrameRate(int32_t minFrameRate, int32_t maxFrameRate) override; 82 int32_t SetMirror(bool isEnable) override; 83 int32_t GetMirror(bool& isEnable) override; 84 bool SetMirrorForLivePhoto(bool isEnable, int32_t mode); 85 int32_t SetPreviewRotation(std::string &deviceClass); 86 void SetStreamTransform(int disPlayRotation = -1); 87 void SetUsedAsPosition(camera_position_enum_t cameraPosition); 88 int32_t AttachMetaSurface(const sptr<OHOS::IBufferProducer>& producer, int32_t videoMetaType) override; 89 int32_t SetCameraRotation(bool isEnable, int32_t rotation) override; 90 int32_t SetCameraApi(uint32_t apiCompatibleVersion) override; 91 int32_t ToggleAutoVideoFrameRate(bool isEnable) override; 92 std::vector<int32_t> GetFrameRateRange(); 93 94 private: 95 void OpenVideoDfxSwitch(std::shared_ptr<OHOS::Camera::CameraMetadata> settings); 96 void StartSketchStream(std::shared_ptr<OHOS::Camera::CameraMetadata> settings); 97 void UpdateSketchStatus(SketchStatus status); 98 void ProcessVerticalCameraPosition(int32_t& sensorOrientation, camera_position_enum_t& cameraPosition); 99 void ProcessFixedTransform(int32_t& sensorOrientation, camera_position_enum_t& cameraPosition); 100 void ProcessFixedDiffDeviceTransform(camera_position_enum_t& cameraPosition); 101 void ProcessCameraPosition(int32_t& streamRotation, camera_position_enum_t& cameraPosition); 102 void ProcessCameraSetRotation(int32_t& streamRotation, camera_position_enum_t& cameraPosition); 103 void UpdateVideoSettings(std::shared_ptr<OHOS::Camera::CameraMetadata> settings); 104 void UpdateFrameRateSettings(std::shared_ptr<OHOS::Camera::CameraMetadata> settings); 105 void UpdateFrameMuteSettings(std::shared_ptr<OHOS::Camera::CameraMetadata> &settings, 106 std::shared_ptr<OHOS::Camera::CameraMetadata> &dynamicSetting); 107 void SyncTransformToSketch(); 108 void UpdateAutoFrameRateSettings(std::shared_ptr<OHOS::Camera::CameraMetadata> settings); 109 #ifdef NOTIFICATION_ENABLE 110 void UpdateBeautySettings(std::shared_ptr<OHOS::Camera::CameraMetadata> &settings); 111 void CancelNotification(); 112 bool IsNeedBeautyNotification(); 113 #endif 114 115 RepeatStreamType repeatStreamType_; 116 sptr<IStreamRepeatCallback> streamRepeatCallback_; 117 std::mutex callbackLock_; 118 std::mutex sketchStreamLock_; // Guard sketchStreamRepeat_ 119 std::mutex streamStartStopLock_; 120 sptr<HStreamRepeat> sketchStreamRepeat_; 121 wptr<HStreamRepeat> parentStreamRepeat_; 122 float sketchRatio_ = -1.0f; 123 SketchStatus sketchStatus_ = SketchStatus::STOPED; 124 RepeatStreamStatus repeatStreamStatus_ = RepeatStreamStatus::STOPED; 125 bool mEnableSecure = false; 126 bool enableMirror_ = false; 127 bool enableStreamRotate_ = false; 128 bool enableCameraRotation_ = false; 129 bool enableAutoFrameRate_ = false; 130 int32_t setCameraRotation_ = 0; 131 uint32_t apiCompatibleVersion_ = 0; 132 std::string deviceClass_ = "phone"; 133 sptr<OHOS::IBufferProducer> metaProducer_; 134 std::mutex movingPhotoCallbackLock_; 135 std::function<void()> startMovingPhotoCallback_; 136 std::vector<int32_t> streamFrameRateRange_ = {}; 137 sptr<BufferProducerSequenceable> metaSurfaceBufferQueue_; 138 camera_position_enum_t cameraUsedAsPosition_ = OHOS_CAMERA_POSITION_OTHER; 139 }; 140 } // namespace CameraStandard 141 } // namespace OHOS 142 #endif // OHOS_CAMERA_H_STREAM_REPEAT_H 143