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