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 | Plog::log(Plog::LogPriority::INFO, TAG, "IN AVFRAMESUBJECT"); |
| 46 | std::ostringstream oss; |
| 47 | std::string direction = data.direction ? "Receive" : "Preview"; |
| 48 | oss << "NEW SUBJECT: [" << data.id << "," << direction << "]" << std::endl; |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 49 | |
agsantos | ac1940d | 2020-09-17 10:18:40 -0400 | [diff] [blame] | 50 | bool preferredStreamDirection = false; |
| 51 | if (!ppm_.empty() && ppm_.find("streamslist") != ppm_.end()) { |
| 52 | Plog::log(Plog::LogPriority::INFO, TAG, "SET PARAMETERS"); |
| 53 | preferredStreamDirection = ppm_.at("streamslist") == "in" ? true : false; |
| 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; |
| 60 | } else if (data.type == StreamType::video && data.direction |
| 61 | && data.direction == preferredStreamDirection) |
| 62 | subject->attach(mVS.get()); // the image I receive from the others on the call |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 63 | |
agsantos | ac1940d | 2020-09-17 10:18:40 -0400 | [diff] [blame] | 64 | Plog::log(Plog::LogPriority::INFO, TAG, oss.str()); |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | std::map<std::string, std::string> |
| 68 | PluginMediaHandler::getCallMediaHandlerDetails() |
| 69 | { |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 70 | return {{"name", NAME}, {"iconPath", datapath_ + sep + "icon.png"}, {"pluginId", id()}}; |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | void |
| 74 | PluginMediaHandler::setPreferenceAttribute(const std::string& key, const std::string& value) |
| 75 | { |
agsantos | ac1940d | 2020-09-17 10:18:40 -0400 | [diff] [blame] | 76 | auto it = ppm_.find(key); |
| 77 | if (it != ppm_.end()) { |
| 78 | if (ppm_[key] != value) { |
| 79 | ppm_[key] = value; |
| 80 | if (key == "background") { |
| 81 | mVS->setBackground(value); |
| 82 | } |
| 83 | } |
| 84 | } |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | bool |
| 88 | PluginMediaHandler::preferenceMapHasKey(const std::string& key) |
| 89 | { |
agsantos | ac1940d | 2020-09-17 10:18:40 -0400 | [diff] [blame] | 90 | if (key == "background") { |
| 91 | return true; |
| 92 | } |
| 93 | return false; |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | void |
| 97 | PluginMediaHandler::detach() |
| 98 | { |
agsantos | ac1940d | 2020-09-17 10:18:40 -0400 | [diff] [blame] | 99 | mVS->detach(); |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | PluginMediaHandler::~PluginMediaHandler() |
| 103 | { |
agsantos | ac1940d | 2020-09-17 10:18:40 -0400 | [diff] [blame] | 104 | std::ostringstream oss; |
| 105 | oss << " ~FORESEG Plugin" << std::endl; |
| 106 | Plog::log(Plog::LogPriority::INFO, TAG, oss.str()); |
| 107 | detach(); |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 108 | } |
agsantos | ac1940d | 2020-09-17 10:18:40 -0400 | [diff] [blame] | 109 | } // namespace jami |