1 /*
2  * Copyright (c) 2024 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 IE_PIPELINE_CORE_TRANSFER_H
17 #define IE_PIPELINE_CORE_TRANSFER_H
18 
19 #include <map>
20 #include <string>
21 #include <vector>
22 
23 #include "any.h"
24 #include "effect_buffer.h"
25 #include "effect_type.h"
26 #include "error_code.h"
27 #include "capability.h"
28 
29 
30 namespace OHOS {
31 namespace Media {
32 namespace Effect {
33 // 各个组件向Pipeline报告的事件类型
34 enum struct EventType : uint32_t {
35     EVENT_READY = 0,
36     EVENT_START,
37     EVENT_COMPLETE,
38     EVENT_ERROR
39 };
40 
41 struct Event {
42     std::string srcFilter;
43     EventType type;
44     Media::Plugin::Any param;
45 };
46 
47 /**
48  * EventReceiver:
49  * 1. Port使用此接口传递事件给Filter
50  * 2. Filter使用此接口传递事件给Pipeline
51  * 3. Sub Filter使用此接口传递事件给 Parent Filter
52  */
53 class EventReceiver {
54 public:
55     virtual ~EventReceiver() = default;
56 
57     virtual void OnEvent(const Event &event) = 0;
58 };
59 
60 enum class WorkMode {
61     PUSH,
62     PULL
63 };
64 
65 /**
66  * Port使用此接口从Filter获取信息,或传递信息给Filter.
67  */
68 class InfoTransfer : public EventReceiver {
69 public:
70     virtual const std::string &GetName() = 0;
71 
72     // OutPort调用
73     virtual std::vector<WorkMode> GetWorkModes() = 0;
74 
75     virtual void Negotiate(const std::string& inPort, const std::shared_ptr<Capability> &capability,
76         std::shared_ptr<EffectContext> &context) = 0;
77 
78     // InPort调用
79     virtual ErrorCode PushData(const std::string &inPort, const std::shared_ptr<EffectBuffer> &buffer,
80         std::shared_ptr<EffectContext> &context) = 0;
81 
82     // OutPort调用
83     virtual ErrorCode PullData(const std::string &outPort, std::shared_ptr<EffectBuffer> &data) = 0;
84 
85     virtual const EventReceiver *GetOwnerPipeline() const = 0;
86 };
87 } // namespace Effect
88 } // namespace Media
89 } // namespace OHOS
90 #endif
91