agsantos | 796b5af | 2020-12-22 19:38:27 -0500 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (C) 2020 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 |
| 19 | * USA. |
| 20 | */ |
| 21 | |
| 22 | #include "pluginMediaHandler.h" |
| 23 | // Logger |
| 24 | #include "pluglog.h" |
| 25 | #include <string_view> |
| 26 | const char sep = separator(); |
| 27 | const std::string TAG = "FORESEG"; |
| 28 | |
| 29 | #define NAME "Foreground Segmentation" |
| 30 | |
| 31 | namespace jami { |
| 32 | |
| 33 | PluginMediaHandler::PluginMediaHandler(std::map<std::string, std::string>&& preferences, |
| 34 | std::string&& datapath) |
| 35 | : datapath_ {datapath} |
| 36 | , preferences_ {preferences} |
| 37 | { |
| 38 | setGlobalPluginParameters(preferences_); |
| 39 | setId(datapath_); |
| 40 | mVS = std::make_shared<VideoSubscriber>(datapath_); |
| 41 | } |
| 42 | |
| 43 | void |
| 44 | PluginMediaHandler::notifyAVFrameSubject(const StreamData& data, jami::avSubjectPtr subject) |
| 45 | { |
| 46 | std::ostringstream oss; |
| 47 | std::string_view direction = data.direction ? "Receive" : "Preview"; |
| 48 | oss << "NEW SUBJECT: [" << data.id << "," << direction << "]" << std::endl; |
| 49 | |
| 50 | bool preferredStreamDirection = false; |
| 51 | auto it = preferences_.find("streamslist"); |
| 52 | if (it != preferences_.end()) { |
| 53 | Plog::log(Plog::LogPriority::INFO, TAG, "SET PARAMETERS"); |
| 54 | preferredStreamDirection = it->second == "in"; |
| 55 | } |
| 56 | oss << "preferredStreamDirection " << preferredStreamDirection << std::endl; |
| 57 | if (data.type == StreamType::video && !data.direction |
| 58 | && data.direction == preferredStreamDirection) { |
| 59 | subject->attach(mVS.get()); // my image |
| 60 | oss << "got my sent image attached" << std::endl; |
| 61 | attached_ = '1'; |
| 62 | } else if (data.type == StreamType::video && data.direction |
| 63 | && data.direction == preferredStreamDirection) { |
| 64 | subject->attach(mVS.get()); // the image I receive from the others on the call |
| 65 | attached_ = '1'; |
| 66 | } |
| 67 | |
| 68 | Plog::log(Plog::LogPriority::INFO, TAG, oss.str()); |
| 69 | } |
| 70 | |
| 71 | std::map<std::string, std::string> |
| 72 | PluginMediaHandler::getCallMediaHandlerDetails() |
| 73 | { |
| 74 | return {{"name", NAME}, |
agsantos | d00bf41 | 2021-01-26 13:43:33 -0500 | [diff] [blame^] | 75 | {"iconPath", datapath_ + sep + "icon.svg"}, |
agsantos | 796b5af | 2020-12-22 19:38:27 -0500 | [diff] [blame] | 76 | {"pluginId", id()}, |
| 77 | {"attached", attached_}, |
| 78 | {"dataType", "1"}}; |
| 79 | } |
| 80 | |
| 81 | void |
| 82 | PluginMediaHandler::setPreferenceAttribute(const std::string& key, const std::string& value) |
| 83 | { |
| 84 | auto it = preferences_.find(key); |
| 85 | if (it != preferences_.end() && it->second != value) { |
| 86 | it->second = value; |
| 87 | if (key == "background") { |
| 88 | mVS->setBackground(value); |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | bool |
| 94 | PluginMediaHandler::preferenceMapHasKey(const std::string& key) |
| 95 | { |
| 96 | if (key == "background") { |
| 97 | return true; |
| 98 | } |
| 99 | return false; |
| 100 | } |
| 101 | |
| 102 | void |
| 103 | PluginMediaHandler::detach() |
| 104 | { |
| 105 | attached_ = '0'; |
| 106 | mVS->detach(); |
| 107 | } |
| 108 | |
| 109 | PluginMediaHandler::~PluginMediaHandler() |
| 110 | { |
| 111 | std::ostringstream oss; |
| 112 | oss << " ~FORESEG Plugin" << std::endl; |
| 113 | Plog::log(Plog::LogPriority::INFO, TAG, oss.str()); |
| 114 | detach(); |
| 115 | } |
| 116 | } // namespace jami |