1fa7767c5Sopenharmony_ci/*
2fa7767c5Sopenharmony_ci * Copyright (C) 2023 Huawei Device Co., Ltd.
3fa7767c5Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4fa7767c5Sopenharmony_ci * you may not use this file except in compliance with the License.
5fa7767c5Sopenharmony_ci * You may obtain a copy of the License at
6fa7767c5Sopenharmony_ci *
7fa7767c5Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8fa7767c5Sopenharmony_ci *
9fa7767c5Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10fa7767c5Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11fa7767c5Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12fa7767c5Sopenharmony_ci * See the License for the specific language governing permissions and
13fa7767c5Sopenharmony_ci * limitations under the License.
14fa7767c5Sopenharmony_ci */
15fa7767c5Sopenharmony_ci
16fa7767c5Sopenharmony_ci#ifndef AVBUFFER_COMMON_H
17fa7767c5Sopenharmony_ci#define AVBUFFER_COMMON_H
18fa7767c5Sopenharmony_ci
19fa7767c5Sopenharmony_ci#ifndef MEDIA_NO_OHOS
20fa7767c5Sopenharmony_ci#ifndef MEDIA_OHOS
21fa7767c5Sopenharmony_ci#define MEDIA_OHOS
22fa7767c5Sopenharmony_ci#endif
23fa7767c5Sopenharmony_ci#else
24fa7767c5Sopenharmony_ci#ifdef MEDIA_OHOS
25fa7767c5Sopenharmony_ci#undef MEDIA_OHOS
26fa7767c5Sopenharmony_ci#endif
27fa7767c5Sopenharmony_ci#endif
28fa7767c5Sopenharmony_ci
29fa7767c5Sopenharmony_ci#include <memory>
30fa7767c5Sopenharmony_ci#include <string>
31fa7767c5Sopenharmony_ci#include "meta/meta.h"
32fa7767c5Sopenharmony_ci
33fa7767c5Sopenharmony_cinamespace OHOS {
34fa7767c5Sopenharmony_ciclass SurfaceBuffer;
35fa7767c5Sopenharmony_ciclass MessageParcel;
36fa7767c5Sopenharmony_cistruct BufferRequestConfig;
37fa7767c5Sopenharmony_ci} // namespace OHOS
38fa7767c5Sopenharmony_ci
39fa7767c5Sopenharmony_cinamespace OHOS {
40fa7767c5Sopenharmony_cinamespace Media {
41fa7767c5Sopenharmony_ciclass AVMemory;
42fa7767c5Sopenharmony_ciconstexpr int32_t INVALID_POSITION = -1;
43fa7767c5Sopenharmony_ci
44fa7767c5Sopenharmony_ci/**
45fa7767c5Sopenharmony_ci * @enum MemoryType
46fa7767c5Sopenharmony_ci * @brief For platforms that support multiple processes, this flag bit indicates the types of data storage, refer to
47fa7767c5Sopenharmony_ci * {@link AVAllocator}.
48fa7767c5Sopenharmony_ci * @since 4.1
49fa7767c5Sopenharmony_ci * @version 1.0
50fa7767c5Sopenharmony_ci */
51fa7767c5Sopenharmony_cienum struct MemoryType : uint8_t {
52fa7767c5Sopenharmony_ci    /**
53fa7767c5Sopenharmony_ci     * If this type is not set, the allocator will be initialized by the current type by default. This type of memory is
54fa7767c5Sopenharmony_ci     * created through malloc() and can only be used by the current process.
55fa7767c5Sopenharmony_ci     */
56fa7767c5Sopenharmony_ci    VIRTUAL_MEMORY = 0,
57fa7767c5Sopenharmony_ci    /**
58fa7767c5Sopenharmony_ci     * A memory type that implements a convenient memory sharing mechanism. For platforms that do not support
59fa7767c5Sopenharmony_ci     * multiprocessing, it may only encapsulate ordinary memory blocks rather than truly multiprocess shared memory
60fa7767c5Sopenharmony_ci     */
61fa7767c5Sopenharmony_ci    SHARED_MEMORY,
62fa7767c5Sopenharmony_ci    /**
63fa7767c5Sopenharmony_ci     * A memory type that provides surface buffer for sharing multi process data.
64fa7767c5Sopenharmony_ci     */
65fa7767c5Sopenharmony_ci    SURFACE_MEMORY,
66fa7767c5Sopenharmony_ci    /**
67fa7767c5Sopenharmony_ci     * A memory type that provides DMA method for sharing multi process data. If the hardware does not support it, it
68fa7767c5Sopenharmony_ci     * will be invalid when initializing AVAlocator.
69fa7767c5Sopenharmony_ci     */
70fa7767c5Sopenharmony_ci    HARDWARE_MEMORY,
71fa7767c5Sopenharmony_ci    /**
72fa7767c5Sopenharmony_ci     * The identifier for buffer queue, representing any type of memory can be allocated.
73fa7767c5Sopenharmony_ci     */
74fa7767c5Sopenharmony_ci    UNKNOWN_MEMORY
75fa7767c5Sopenharmony_ci};
76fa7767c5Sopenharmony_ci
77fa7767c5Sopenharmony_ci/**
78fa7767c5Sopenharmony_ci * @brief Enumerates the flag bits used to create a new shared memory.
79fa7767c5Sopenharmony_ci */
80fa7767c5Sopenharmony_cienum MemoryFlag : uint8_t {
81fa7767c5Sopenharmony_ci    /**
82fa7767c5Sopenharmony_ci     * For platforms that support multiple processes, this flag bit indicates that the remote process can only read data
83fa7767c5Sopenharmony_ci     * in the shared memory. If this flag is not set, the remote process has both read and write permissions by default.
84fa7767c5Sopenharmony_ci     * Adding this flag does not affect the process that creates the memory, which always has the read and write
85fa7767c5Sopenharmony_ci     * permission on the shared memory. For platforms that do not support multi-processes, the memory read and write
86fa7767c5Sopenharmony_ci     * permission control capability may not be available. In this case, this flag is invalid.
87fa7767c5Sopenharmony_ci     */
88fa7767c5Sopenharmony_ci    MEMORY_READ_ONLY = 0x1 << 0,
89fa7767c5Sopenharmony_ci    /**
90fa7767c5Sopenharmony_ci     * For platforms that support multiple processes, this flag bit indicates that the remote process can only write
91fa7767c5Sopenharmony_ci     * data in the shared memory.
92fa7767c5Sopenharmony_ci     */
93fa7767c5Sopenharmony_ci    MEMORY_WRITE_ONLY = 0x1 << 1,
94fa7767c5Sopenharmony_ci    /**
95fa7767c5Sopenharmony_ci     * This flag bit indicates that the remote process is allowed to read and write the shared memory. If no flags are
96fa7767c5Sopenharmony_ci     * specified, this is the default memory sharing policy. If the FLAGS_READ_ONLY bit is set, this flag bit is
97fa7767c5Sopenharmony_ci     * ignored.
98fa7767c5Sopenharmony_ci     */
99fa7767c5Sopenharmony_ci    MEMORY_READ_WRITE = MEMORY_READ_ONLY | MEMORY_WRITE_ONLY,
100fa7767c5Sopenharmony_ci};
101fa7767c5Sopenharmony_ci
102fa7767c5Sopenharmony_ci/**
103fa7767c5Sopenharmony_ci * @brief Struct that encapsulates some info of media buffer.
104fa7767c5Sopenharmony_ci */
105fa7767c5Sopenharmony_ciusing AVBufferConfig = struct AVBufferConfig {
106fa7767c5Sopenharmony_ci    int32_t size = 0;
107fa7767c5Sopenharmony_ci    int32_t align = 0;
108fa7767c5Sopenharmony_ci    MemoryType memoryType = MemoryType::UNKNOWN_MEMORY;
109fa7767c5Sopenharmony_ci    MemoryFlag memoryFlag = MemoryFlag::MEMORY_READ_WRITE;
110fa7767c5Sopenharmony_ci    std::unique_ptr<struct BufferRequestConfig> surfaceBufferConfig;
111fa7767c5Sopenharmony_ci    int32_t dmaFd = -1;   // to create dma buffer
112fa7767c5Sopenharmony_ci    int32_t capacity = 0; // get from buffer
113fa7767c5Sopenharmony_ci
114fa7767c5Sopenharmony_ci    AVBufferConfig();
115fa7767c5Sopenharmony_ci    AVBufferConfig(const AVBufferConfig &rhs);
116fa7767c5Sopenharmony_ci    AVBufferConfig(AVBufferConfig &&rhs) noexcept;
117fa7767c5Sopenharmony_ci    AVBufferConfig &operator=(const AVBufferConfig &rhs);
118fa7767c5Sopenharmony_ci    AVBufferConfig &operator=(AVBufferConfig &&rhs) noexcept;
119fa7767c5Sopenharmony_ci    bool operator<=(const struct AVBufferConfig &rhs) const;
120fa7767c5Sopenharmony_ci};
121fa7767c5Sopenharmony_ci} // namespace Media
122fa7767c5Sopenharmony_ci} // namespace OHOS
123fa7767c5Sopenharmony_ci#endif // AVBUFFER_COMMON_H