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