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