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