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