• 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 AVSHAREDMEMORY_H
17 #define AVSHAREDMEMORY_H
18 
19 #include <cstdint>
20 #include <memory>
21 #include <string>
22 
23 namespace OHOS {
24 namespace Media {
25 /**
26  * @brief Provides a unified interface to implement convenient memory sharing
27  * mechanism. For those platforms that do not support multi-process, it may
28  * simply encapsulate ordinary memory blocks, not really multi-process shareable memory.
29  */
30 class __attribute__((visibility("default"))) AVSharedMemory {
31 public:
32     virtual ~AVSharedMemory() = default;
33 
34     /**
35      * @brief Enumerates the flag bits used to create a new shared memory.
36      */
37     enum Flags : uint32_t {
38         /**
39          * This flag bit indicates that the remote process is allowed to read and write
40          * the shared memory. If no flags are specified, this is the default memory
41          * sharing policy. If the FLAGS_READ_ONLY bit is set, this flag bit is ignored.
42          */
43         FLAGS_READ_WRITE = 0x1,
44         /**
45          * For platforms that support multiple processes, this flag bit indicates that the
46          * remote process can only read data in the shared memory. If this flag is not set,
47          * the remote process has both read and write permissions by default. Adding this
48          * flag does not affect the process that creates the memory, which always has the
49          * read and write permission on the shared memory. For platforms that do not support
50          * multi-processes, the memory read and write permission control capability may
51          * not be available. In this case, this flag is invalid.
52          */
53         FLAGS_READ_ONLY = 0x2,
54     };
55 
56     /**
57      * @brief Get the memory's virtual address
58      * @return the memory's virtual address if the memory is valid, otherwise nullptr.
59      */
60     virtual uint8_t *GetBase() const = 0;
61 
62     /**
63      * @brief Get the memory's size
64      * @return the memory's size if the memory is valid, otherwise -1.
65      */
66     virtual int32_t GetSize() const = 0;
67 
68     /**
69      * @brief Get the memory's flags set by the creator, refer to {@Flags}
70      * @return the memory's flags if the memory is valid, otherwise 0.
71      */
72     virtual uint32_t GetFlags() const = 0;
73 };
74 } // namespace Media
75 } // namespace OHOS
76 #endif // AVSHAREDMEMORY_H