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