Line data Source code
1 : /*
2 : * Copyright (C) 2004-2026 Savoir-faire Linux Inc.
3 : *
4 : * This program is free software: you can redistribute it and/or modify
5 : * it under the terms of the GNU General Public License as published by
6 : * the Free Software Foundation, either version 3 of the License, or
7 : * (at your option) any later version.
8 : *
9 : * This program is distributed in the hope that it will be useful,
10 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 : * GNU General Public License for more details.
13 : *
14 : * You should have received a copy of the GNU General Public License
15 : * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 : */
17 : #pragma once
18 :
19 : #include "streamdata.h"
20 : #include "observer.h"
21 :
22 : #include <string>
23 : #include <memory>
24 : #include <map>
25 :
26 : extern "C" {
27 : struct AVFrame;
28 : }
29 :
30 : namespace jami {
31 :
32 : using avSubjectPtr = std::shared_ptr<Observable<AVFrame*>>;
33 :
34 : /**
35 : * @class MediaHandler
36 : * @brief It's the base object of the CallMediaHandler
37 : */
38 : class MediaHandler
39 : {
40 : public:
41 : virtual ~MediaHandler() = default;
42 :
43 : /**
44 : * @brief Returns the dataPath of the plugin that created this MediaHandler.
45 : */
46 0 : std::string id() const { return id_; }
47 :
48 : /**
49 : * @brief Should be called by the MediaHandler creator to set the plugins id_ variable
50 : * with dataPath.
51 : */
52 : virtual void setId(const std::string& id) final { id_ = id; }
53 :
54 : private:
55 : // Must be set with plugin's dataPath.
56 : std::string id_;
57 : };
58 :
59 : /**
60 : * @class CallMediaHandler
61 : * @brief This abstract class is an API we need to implement from plugin side.
62 : * In other words, a plugin functionality that plays with audio or video, must start
63 : * from the implementation of this class.
64 : */
65 : class CallMediaHandler : public MediaHandler
66 : {
67 : public:
68 : /**
69 : * @brief Should attach a AVSubject (Observable) to the plugin data process (Observer).
70 : * @param data
71 : * @param subject
72 : */
73 : virtual void notifyAVFrameSubject(const StreamData& data, avSubjectPtr subject) = 0;
74 :
75 : /**
76 : * @brief Should return a map with handler's name, iconPath, pluginId, attached, and dataType.
77 : * Daemon expects:
78 : * "attached" -> 1 if handler is attached;
79 : * "dataType" -> 1 if data processed is video;
80 : * "dataType" -> 0 if data processed is audio;
81 : * @return Map with CallMediaHandler details.
82 : */
83 : virtual std::map<std::string, std::string> getCallMediaHandlerDetails() = 0;
84 :
85 : /**
86 : * @brief Should detach the plugin data process (Observer).
87 : */
88 : virtual void detach() = 0;
89 :
90 : /**
91 : * @brief If a preference can be changed without the need to reload the plugin, it
92 : * should be done through this function.
93 : * @param key
94 : * @param value
95 : */
96 : virtual void setPreferenceAttribute(const std::string& key, const std::string& value) = 0;
97 :
98 : /**
99 : * @brief If a preference can be changed without the need to reload the plugin, this function
100 : * should return True.
101 : * @param key
102 : * @return True if preference can be changed through setPreferenceAttribute method.
103 : */
104 : virtual bool preferenceMapHasKey(const std::string& key) = 0;
105 : };
106 : } // namespace jami
|