1fa7767c5Sopenharmony_ci/* 2fa7767c5Sopenharmony_ci * Copyright (c) 2022-2022 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 HISTREAMER_PLUGIN_COMMON_SHARE_MEMORY_H 17fa7767c5Sopenharmony_ci#define HISTREAMER_PLUGIN_COMMON_SHARE_MEMORY_H 18fa7767c5Sopenharmony_ci 19fa7767c5Sopenharmony_ci#if !defined(OHOS_LITE) && defined(VIDEO_SUPPORT) 20fa7767c5Sopenharmony_ci 21fa7767c5Sopenharmony_ci#include "plugin/plugin_buffer.h" 22fa7767c5Sopenharmony_ci#include "share_allocator.h" 23fa7767c5Sopenharmony_ci 24fa7767c5Sopenharmony_cinamespace OHOS { 25fa7767c5Sopenharmony_cinamespace Media { 26fa7767c5Sopenharmony_cinamespace Plugins { 27fa7767c5Sopenharmony_ciclass ShareMemory : public Memory { 28fa7767c5Sopenharmony_cipublic: 29fa7767c5Sopenharmony_ci ~ShareMemory() override; 30fa7767c5Sopenharmony_ci 31fa7767c5Sopenharmony_ci explicit ShareMemory(size_t capacity, std::shared_ptr<Allocator> allocator = nullptr, size_t align = 1); 32fa7767c5Sopenharmony_ci 33fa7767c5Sopenharmony_ci size_t Write(const uint8_t* in, size_t writeSize, size_t position) override; 34fa7767c5Sopenharmony_ci 35fa7767c5Sopenharmony_ci size_t Read(uint8_t* out, size_t readSize, size_t position) override; 36fa7767c5Sopenharmony_ci 37fa7767c5Sopenharmony_ci int GetShareMemoryFd(); 38fa7767c5Sopenharmony_ci 39fa7767c5Sopenharmony_ciprotected: 40fa7767c5Sopenharmony_ci uint8_t* GetRealAddr() const override; 41fa7767c5Sopenharmony_ci 42fa7767c5Sopenharmony_ciprivate: 43fa7767c5Sopenharmony_ci void InitShareMemory(ShareMemType type); 44fa7767c5Sopenharmony_ci 45fa7767c5Sopenharmony_ci /// share buffer 46fa7767c5Sopenharmony_ci std::shared_ptr<Ashmem> sharedMem_ {nullptr}; 47fa7767c5Sopenharmony_ci 48fa7767c5Sopenharmony_ci std::shared_ptr<ShareAllocator> shareAllocator_ {nullptr}; 49fa7767c5Sopenharmony_ci 50fa7767c5Sopenharmony_ci int fd_; 51fa7767c5Sopenharmony_ci}; 52fa7767c5Sopenharmony_ci} // namespace Plugins 53fa7767c5Sopenharmony_ci} // namespace Media 54fa7767c5Sopenharmony_ci} // namespace OHOS 55fa7767c5Sopenharmony_ci 56fa7767c5Sopenharmony_ci#endif 57fa7767c5Sopenharmony_ci#endif // HISTREAMER_PLUGIN_COMMON_SHARE_MEMORY_H 58