1 /* 2 * Copyright (c) 2021-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 HISTREAMER_PLUGIN_CORE_BASE_H 17 #define HISTREAMER_PLUGIN_CORE_BASE_H 18 19 #include <atomic> 20 #include <cstdint> 21 #include <iosfwd> 22 #include <memory> 23 24 #include "foundation/osal/thread/mutex.h" 25 #include "plugin/common/plugin_tags.h" 26 #include "plugin/common/plugin_types.h" 27 #include "plugin/interface/plugin_base.h" 28 29 namespace OHOS { 30 namespace Media { 31 namespace Plugin { 32 struct PluginBase; 33 34 struct CallbackWrap { 35 virtual ~CallbackWrap() = default; 36 37 virtual void OnEvent(const PluginEvent &event) = 0; 38 }; 39 40 class CallbackImpl : public Plugin::Callback { 41 public: OnEvent(const PluginEvent & event)42 void OnEvent(const PluginEvent &event) override 43 { 44 callbackWrap_->OnEvent(event); 45 } 46 SetCallbackWrap(CallbackWrap * callbackWrap)47 void SetCallbackWrap(CallbackWrap* callbackWrap) 48 { 49 callbackWrap_ = callbackWrap; 50 } 51 52 private: 53 CallbackWrap* callbackWrap_ {nullptr}; 54 }; 55 56 class Base { 57 public: 58 Base(const Base &) = delete; 59 60 Base operator=(const Base &) = delete; 61 62 virtual ~Base() = default; 63 64 virtual Status Init(); 65 66 virtual Status Deinit(); 67 68 virtual Status Prepare(); 69 70 virtual Status Reset(); 71 72 virtual Status Start(); 73 74 virtual Status Stop(); 75 76 virtual Status GetParameter(Tag tag, ValueType &value); 77 78 virtual Status SetParameter(Tag tag, const ValueType &value); 79 80 virtual Status GetState(State &state); 81 82 virtual std::shared_ptr<Allocator> GetAllocator(); 83 84 virtual Status SetCallback(CallbackWrap* cb); 85 86 std::string GetName(); 87 88 protected: 89 friend class PluginManager; 90 91 Base(uint32_t pkgVer, uint32_t apiVer, std::shared_ptr<PluginBase> plugin); 92 93 protected: 94 const uint32_t pkgVersion_; 95 96 const uint32_t apiVersion_; 97 98 std::shared_ptr<PluginBase> plugin_; 99 100 OHOS::Media::OSAL::Mutex stateChangeMutex_ {}; 101 std::atomic<State> pluginState_ {State::CREATED}; 102 private: 103 CallbackImpl pluginCallback_ {}; 104 }; 105 } // namespace Plugin 106 } // namespace Media 107 } // namespace OHOS 108 #endif // HISTREAMER_PLUGIN_CORE_BASE_H 109