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 19 #include <cstdint> 20 #include <iostream> 21 #include <refbase.h> 22 23 #include "camera_metadata_info.h" 24 #include "hstream_common.h" 25 #include "hstream_repeat_stub.h" 26 #include "istream_repeat_callback.h" 27 #include "v1_0/istream_operator.h" 28 29 namespace OHOS { 30 namespace CameraStandard { 31 enum class RepeatStreamType { 32 PREVIEW, 33 VIDEO, 34 SKETCH 35 }; 36 37 class HStreamRepeat : public HStreamRepeatStub, public HStreamCommon { 38 public: 39 HStreamRepeat( 40 sptr<OHOS::IBufferProducer> producer, int32_t format, int32_t width, int32_t height, RepeatStreamType type); 41 ~HStreamRepeat(); 42 43 int32_t LinkInput(sptr<OHOS::HDI::Camera::V1_0::IStreamOperator> streamOperator, 44 std::shared_ptr<OHOS::Camera::CameraMetadata> cameraAbility) override; 45 void SetStreamInfo(StreamInfo_V1_1& streamInfo) override; 46 int32_t ReleaseStream(bool isDelay) override; 47 int32_t Release() override; 48 int32_t Start() override; 49 int32_t Start(std::shared_ptr<OHOS::Camera::CameraMetadata> settings); 50 int32_t Stop() override; 51 int32_t SetCallback(sptr<IStreamRepeatCallback>& callback) override; 52 int32_t OnFrameStarted(); 53 int32_t OnFrameEnded(int32_t frameCount); 54 int32_t OnFrameError(int32_t errorType); 55 int32_t OnSketchStatusChanged(SketchStatus status); 56 int32_t AddDeferredSurface(const sptr<OHOS::IBufferProducer>& producer) override; 57 int32_t ForkSketchStreamRepeat( 58 int32_t width, int32_t height, sptr<IStreamRepeat>& sketchStream, float sketchRatio) override; 59 int32_t RemoveSketchStreamRepeat() override; 60 int32_t UpdateSketchRatio(float sketchRatio) override; 61 sptr<HStreamRepeat> GetSketchStream(); 62 RepeatStreamType GetRepeatStreamType(); 63 void DumpStreamInfo(std::string& dumpString) override; 64 65 int32_t OperatePermissionCheck(uint32_t interfaceCode) override; 66 67 private: 68 void SetStreamTransform(); 69 void StartSketchStream(std::shared_ptr<OHOS::Camera::CameraMetadata> settings); 70 void UpdateSketchStatus(SketchStatus status); 71 RepeatStreamType repeatStreamType_; 72 sptr<IStreamRepeatCallback> streamRepeatCallback_; 73 std::mutex callbackLock_; 74 std::mutex sketchStreamLock_; // Guard sketchStreamRepeat_ 75 sptr<HStreamRepeat> sketchStreamRepeat_; 76 wptr<HStreamRepeat> parentStreamRepeat_; 77 float sketchRatio_ = -1.0f; 78 SketchStatus sketchStatus_ = SketchStatus::STOPED; 79 }; 80 } // namespace CameraStandard 81 } // namespace OHOS 82 #endif // OHOS_CAMERA_H_STREAM_REPEAT_H 83