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_CAPTURE_H 17 #define OHOS_CAMERA_H_STREAM_CAPTURE_H 18 #define EXPORT_API __attribute__((visibility("default"))) 19 20 #include <atomic> 21 #include <cstdint> 22 #include <iostream> 23 #include <refbase.h> 24 25 #include "camera_metadata_info.h" 26 #include "hstream_capture_stub.h" 27 #include "hstream_common.h" 28 #include "v1_0/istream_operator.h" 29 #include "v1_2/istream_operator.h" 30 #include "safe_map.h" 31 32 namespace OHOS { 33 namespace CameraStandard { 34 using OHOS::HDI::Camera::V1_0::BufferProducerSequenceable; 35 using namespace OHOS::HDI::Camera::V1_0; 36 constexpr const char* BURST_UUID_UNSET = ""; 37 class EXPORT_API HStreamCapture : public HStreamCaptureStub, public HStreamCommon { 38 public: 39 HStreamCapture(sptr<OHOS::IBufferProducer> producer, int32_t format, int32_t width, int32_t height); 40 ~HStreamCapture(); 41 42 int32_t LinkInput(sptr<OHOS::HDI::Camera::V1_0::IStreamOperator> streamOperator, 43 std::shared_ptr<OHOS::Camera::CameraMetadata> cameraAbility) override; 44 void SetStreamInfo(StreamInfo_V1_1 &streamInfo) override; 45 int32_t SetThumbnail(bool isEnabled, const sptr<OHOS::IBufferProducer> &producer) override; 46 int32_t EnableRawDelivery(bool enabled) override; 47 int32_t SetBufferProducerInfo(const std::string bufName, const sptr<OHOS::IBufferProducer> &producer) override; 48 int32_t DeferImageDeliveryFor(int32_t type) override; 49 int32_t Capture(const std::shared_ptr<OHOS::Camera::CameraMetadata> &captureSettings) override; 50 int32_t CancelCapture() override; 51 int32_t ConfirmCapture() override; 52 int32_t ReleaseStream(bool isDelay) override; 53 int32_t Release() override; 54 int32_t SetCallback(sptr<IStreamCaptureCallback> &callback) override; 55 int32_t OnCaptureStarted(int32_t captureId); 56 int32_t OnCaptureStarted(int32_t captureId, uint32_t exposureTime); 57 int32_t OnCaptureEnded(int32_t captureId, int32_t frameCount); 58 int32_t OnCaptureError(int32_t captureId, int32_t errorType); 59 int32_t OnFrameShutter(int32_t captureId, uint64_t timestamp); 60 int32_t OnFrameShutterEnd(int32_t captureId, uint64_t timestamp); 61 int32_t OnCaptureReady(int32_t captureId, uint64_t timestamp); 62 void DumpStreamInfo(CameraInfoDumper& infoDumper) override; 63 void SetRotation(const std::shared_ptr<OHOS::Camera::CameraMetadata> &captureMetadataSetting_, int32_t captureId); 64 void SetMode(int32_t modeName); 65 int32_t GetMode(); 66 int32_t IsDeferredPhotoEnabled() override; 67 int32_t IsDeferredVideoEnabled() override; 68 int32_t SetMovingPhotoVideoCodecType(int32_t videoCodecType) override; 69 int32_t GetMovingPhotoVideoCodecType(); 70 int32_t OperatePermissionCheck(uint32_t interfaceCode) override; 71 void FullfillPictureExtendStreamInfos(StreamInfo_V1_1 &streamInfo, int32_t format); 72 SafeMap<int32_t, int32_t> rotationMap_ = {}; 73 bool IsBurstCapture(int32_t captureId) const; 74 bool IsBurstCover(int32_t captureId) const; 75 int32_t GetCurBurstSeq(int32_t captureId) const; 76 std::string GetBurstKey(int32_t captureId) const; 77 void SetBurstImages(int32_t captureId, std::string imageId); 78 void CheckResetBurstKey(int32_t captureId); 79 int32_t SetCameraPhotoRotation(bool isEnable) override; 80 int32_t AcquireBufferToPrepareProxy(int32_t captureId) override; 81 82 private: 83 int32_t CheckBurstCapture(const std::shared_ptr<OHOS::Camera::CameraMetadata>& captureSettings, 84 const int32_t &preparedCaptureId); 85 int32_t PrepareBurst(int32_t captureId); 86 void ResetBurst(); 87 void ResetBurstKey(int32_t captureId); 88 void EndBurstCapture(const std::shared_ptr<OHOS::Camera::CameraMetadata>& captureMetadataSetting_); 89 void ProcessCaptureInfoPhoto(CaptureInfo& captureInfoPhoto, 90 const std::shared_ptr<OHOS::Camera::CameraMetadata>& captureSettings, int32_t captureId); 91 sptr<IStreamCaptureCallback> streamCaptureCallback_; 92 std::mutex callbackLock_; 93 int32_t thumbnailSwitch_; 94 int32_t rawDeliverySwitch_; 95 sptr<BufferProducerSequenceable> thumbnailBufferQueue_; 96 sptr<BufferProducerSequenceable> rawBufferQueue_; 97 sptr<BufferProducerSequenceable> gainmapBufferQueue_; 98 sptr<BufferProducerSequenceable> deepBufferQueue_; 99 sptr<BufferProducerSequenceable> exifBufferQueue_; 100 sptr<BufferProducerSequenceable> debugBufferQueue_; 101 int32_t modeName_; 102 int32_t deferredPhotoSwitch_; 103 int32_t deferredVideoSwitch_; 104 bool enableCameraPhotoRotation_ = false; 105 std::atomic<bool> isCaptureReady_ = true; 106 std::string curBurstKey_ = BURST_UUID_UNSET; 107 bool isBursting_ = false; 108 std::map<int32_t, std::vector<std::string>> burstImagesMap_; 109 std::map<int32_t, std::string> burstkeyMap_; 110 std::map<int32_t, int32_t> burstNumMap_; 111 mutable std::mutex burstLock_; 112 int32_t burstNum_; 113 int32_t videoCodecType_ = 0; 114 }; 115 } // namespace CameraStandard 116 } // namespace OHOS 117 #endif // OHOS_CAMERA_H_STREAM_CAPTURE_H 118