1 /*
2  * Copyright (c) 2023-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 OHOS_CAMERA_DPS_SHARED_BUFFER_H
17 #define OHOS_CAMERA_DPS_SHARED_BUFFER_H
18 
19 #include <ashmem.h>
20 
21 #include "ibuffer.h"
22 
23 namespace OHOS {
24 namespace CameraStandard {
25 namespace DeferredProcessing {
26 class SharedBuffer : public IBuffer {
27 public:
28     explicit SharedBuffer(int64_t capacity);
29     ~SharedBuffer();
30 
31     int32_t Initialize();
32     int64_t GetSize() override;
33     int32_t CopyFrom(uint8_t* address, int64_t bytes) override;
34     void Reset() override;
35     int GetFd() const override;
36 
37 private:
38     int32_t AllocateAshmemUnlocked();
39     void DeallocAshmem();
40 
41     const int64_t capacity_;
42     sptr<Ashmem> ashmem_ {nullptr};
43 };
44 } // namespace DeferredProcessing
45 } // namespace CameraStandard
46 } // namespace OHOS
47 #endif // OHOS_CAMERA_DPS_SHARED_BUFFER_H
48