1 /* 2 * Copyright (c) 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_COMMON_H 17 #define OHOS_CAMERA_H_STREAM_COMMON_H 18 19 #include <atomic> 20 #include <cstdint> 21 #include <iostream> 22 #include <mutex> 23 #include <refbase.h> 24 25 #include "camera/v1_2/types.h" 26 #include "camera_metadata_info.h" 27 #include "icapture_session.h" 28 #include "istream_common.h" 29 #include "v1_0/istream_operator.h" 30 #include "v1_1/istream_operator.h" 31 #include "v1_2/istream_operator.h" 32 33 namespace OHOS { 34 namespace CameraStandard { 35 using OHOS::HDI::Camera::V1_0::IStreamOperator; 36 using OHOS::HDI::Camera::V1_1::StreamInfo_V1_1; 37 constexpr int32_t CAPTURE_ID_UNSET = 0; 38 constexpr int32_t STREAM_ID_UNSET = 0; 39 40 class HStreamCommon : virtual public RefBase { 41 public: 42 HStreamCommon( 43 StreamType streamType, sptr<OHOS::IBufferProducer> producer, int32_t format, int32_t width, int32_t height); 44 virtual ~HStreamCommon(); 45 virtual int32_t LinkInput(sptr<OHOS::HDI::Camera::V1_0::IStreamOperator> streamOperator, 46 std::shared_ptr<OHOS::Camera::CameraMetadata> cameraAbility); 47 virtual int32_t UnlinkInput(); 48 virtual void SetStreamInfo(StreamInfo_V1_1& streamInfo) = 0; 49 virtual int32_t ReleaseStream(bool isDelay) = 0; 50 virtual void DumpStreamInfo(std::string& dumpString) = 0; 51 52 virtual void SetColorSpace(ColorSpace colorSpace) final; 53 virtual int32_t StopStream() final; 54 55 virtual int32_t GetPreparedCaptureId() final; 56 GetStreamId()57 inline int32_t GetStreamId() 58 { 59 return streamId_; 60 } 61 GetStreamType()62 inline StreamType GetStreamType() 63 { 64 return streamType_; 65 } 66 67 int32_t format_; 68 int32_t width_; 69 int32_t height_; 70 int32_t dataSpace_; 71 sptr<OHOS::IBufferProducer> producer_; 72 73 std::shared_ptr<OHOS::Camera::CameraMetadata> cameraAbility_; 74 75 protected: 76 /* 77 * Prepare a capture id, return CAMERA_OK or CAMERA_CAPTURE_LIMIT_EXCEED 78 */ 79 virtual int32_t PrepareCaptureId() final; 80 virtual void ResetCaptureId() final; 81 GetStreamOperator()82 inline sptr<OHOS::HDI::Camera::V1_0::IStreamOperator> GetStreamOperator() 83 { 84 std::lock_guard<std::mutex> lock(streamOperatorLock_); 85 return streamOperator_; 86 } 87 SetStreamOperator(sptr<OHOS::HDI::Camera::V1_0::IStreamOperator> streamOperator)88 inline void SetStreamOperator(sptr<OHOS::HDI::Camera::V1_0::IStreamOperator> streamOperator) 89 { 90 std::lock_guard<std::mutex> lock(streamOperatorLock_); 91 streamOperator_ = streamOperator; 92 } 93 94 std::mutex producerLock_; 95 std::mutex cameraAbilityLock_; 96 uint32_t callerToken_; 97 98 std::mutex streamOperatorLock_; 99 sptr<OHOS::HDI::Camera::V1_0::IStreamOperator> streamOperator_; 100 101 private: 102 StreamType streamType_; 103 int32_t streamId_; 104 int32_t curCaptureID_; 105 }; 106 } // namespace CameraStandard 107 } // namespace OHOS 108 #endif // OHOS_CAMERA_H_STREAM_COMMON_H 109