• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 
29 namespace OHOS {
30 namespace DistributedHardware {
31 using namespace OHOS::HDI::DistributedCamera::V1_0;
32 class DBufferManager {
33 public:
34     DBufferManager() = default;
35     virtual ~DBufferManager() = default;
36     DBufferManager(const DBufferManager &other) = delete;
37     DBufferManager(DBufferManager &&other) = delete;
38     DBufferManager& operator=(const DBufferManager &other) = delete;
39     DBufferManager& operator=(DBufferManager &&other) = delete;
40 
41 public:
42     std::shared_ptr<DImageBuffer> AcquireBuffer();
43     RetCode AddBuffer(std::shared_ptr<DImageBuffer>& buffer);
44     RetCode RemoveBuffer(std::shared_ptr<DImageBuffer>& buffer);
45     void NotifyStop(bool state);
46     static RetCode SurfaceBufferToDImageBuffer(const OHOS::sptr<OHOS::SurfaceBuffer> &surfaceBuffer,
47         const std::shared_ptr<DImageBuffer> &buffer);
48     static RetCode DImageBufferToDCameraBuffer(const std::shared_ptr<DImageBuffer> &imageBuffer,
49         DCameraBuffer &buffer);
50     static uint64_t CameraUsageToGrallocUsage(const uint64_t cameraUsage);
51     static uint32_t PixelFormatToDCameraFormat(const PixelFormat format);
52 
53 private:
54     std::mutex lock_;
55     std::atomic_bool streamStop_ = false;
56     std::list<std::shared_ptr<DImageBuffer>> idleList_ = {};
57     std::list<std::shared_ptr<DImageBuffer>> busyList_ = {};
58 };
59 } // namespace DistributedHardware
60 } // namespace OHOS
61 #endif // DISTRIBUTED_CAMERA_BUFFER_MANAGER_H