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