1 /* 2 * Copyright (c) 2021-2023 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 DISTRIBUTED_CAMERA_BUFFER_MANAGER_H 17 #define DISTRIBUTED_CAMERA_BUFFER_MANAGER_H 18 19 #include <list> 20 #include <mutex> 21 22 #include "constants.h" 23 #include "dimage_buffer.h" 24 #include "surface.h" 25 #include "surface_buffer.h" 26 27 #include "v1_0/dcamera_types.h" 28 #include "v1_0/display_composer_type.h" 29 30 namespace OHOS { 31 namespace DistributedHardware { 32 using namespace OHOS::HDI::DistributedCamera::V1_0; 33 using namespace OHOS::HDI::Display::Composer::V1_0; 34 class DBufferManager { 35 public: 36 DBufferManager() = default; 37 virtual ~DBufferManager() = default; 38 DBufferManager(const DBufferManager &other) = delete; 39 DBufferManager(DBufferManager &&other) = delete; 40 DBufferManager& operator=(const DBufferManager &other) = delete; 41 DBufferManager& operator=(DBufferManager &&other) = delete; 42 43 public: 44 std::shared_ptr<DImageBuffer> AcquireBuffer(); 45 RetCode AddBuffer(std::shared_ptr<DImageBuffer>& buffer); 46 RetCode RemoveBuffer(std::shared_ptr<DImageBuffer>& buffer); 47 void NotifyStop(bool state); 48 static RetCode SurfaceBufferToDImageBuffer(const OHOS::sptr<OHOS::SurfaceBuffer> &surfaceBuffer, 49 const std::shared_ptr<DImageBuffer> &buffer); 50 static RetCode DImageBufferToDCameraBuffer(const std::shared_ptr<DImageBuffer> &imageBuffer, 51 DCameraBuffer &buffer); 52 static uint64_t CameraUsageToGrallocUsage(const uint64_t cameraUsage); 53 static uint32_t PixelFormatToDCameraFormat(const PixelFormat format); 54 55 private: 56 std::mutex lock_; 57 std::atomic_bool streamStop_ = false; 58 std::list<std::shared_ptr<DImageBuffer>> idleList_ = {}; 59 std::list<std::shared_ptr<DImageBuffer>> busyList_ = {}; 60 }; 61 } // namespace DistributedHardware 62 } // namespace OHOS 63 #endif // DISTRIBUTED_CAMERA_BUFFER_MANAGER_H