agsantos | 4bb4bc5 | 2021-03-08 14:21:45 -0500 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (C) 2021 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 | #include "WatermarkMediaHandler.h" |
| 22 | |
agsantos | 3fcc621 | 2021-08-18 17:11:29 -0300 | [diff] [blame] | 23 | #include "PluginPreferenceHandler.h" |
agsantos | 4bb4bc5 | 2021-03-08 14:21:45 -0500 | [diff] [blame] | 24 | #include "pluglog.h" |
| 25 | #include <string_view> |
| 26 | |
| 27 | const char sep = separator(); |
| 28 | const std::string TAG = "Watermark"; |
| 29 | |
| 30 | #define NAME "Watermark" |
| 31 | |
| 32 | namespace jami { |
| 33 | |
agsantos | 3fcc621 | 2021-08-18 17:11:29 -0300 | [diff] [blame] | 34 | WatermarkMediaHandler::WatermarkMediaHandler(std::string&& dataPath, |
| 35 | PluginPreferenceHandler* prefHandler) |
| 36 | : datapath_ {dataPath} |
agsantos | 4bb4bc5 | 2021-03-08 14:21:45 -0500 | [diff] [blame] | 37 | { |
agsantos | 3fcc621 | 2021-08-18 17:11:29 -0300 | [diff] [blame] | 38 | aph_ = prefHandler; |
agsantos | 4bb4bc5 | 2021-03-08 14:21:45 -0500 | [diff] [blame] | 39 | setId(datapath_); |
agsantos | 3fcc621 | 2021-08-18 17:11:29 -0300 | [diff] [blame] | 40 | mediaSubscriber_ = std::make_shared<WatermarkVideoSubscriber>(datapath_); |
| 41 | setParameters("default"); |
agsantos | 4bb4bc5 | 2021-03-08 14:21:45 -0500 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | void |
| 45 | WatermarkMediaHandler::notifyAVFrameSubject(const StreamData& data, jami::avSubjectPtr subject) |
| 46 | { |
| 47 | std::ostringstream oss; |
| 48 | std::string_view direction = data.direction ? "Receive" : "Preview"; |
| 49 | oss << "NEW SUBJECT: [" << data.id << "," << direction << "]" << std::endl; |
| 50 | |
agsantos | 3fcc621 | 2021-08-18 17:11:29 -0300 | [diff] [blame] | 51 | accountId_ = data.source; |
| 52 | auto preferences = aph_->getPreferences(accountId_); |
| 53 | |
agsantos | 4bb4bc5 | 2021-03-08 14:21:45 -0500 | [diff] [blame] | 54 | bool preferredStreamDirection {false}; // false for output; true for input |
agsantos | 3fcc621 | 2021-08-18 17:11:29 -0300 | [diff] [blame] | 55 | auto it = preferences.find("videostream"); |
| 56 | if (it != preferences.end()) { |
agsantos | 4bb4bc5 | 2021-03-08 14:21:45 -0500 | [diff] [blame] | 57 | preferredStreamDirection = it->second == "1"; |
| 58 | } |
| 59 | oss << "preferredStreamDirection " << preferredStreamDirection << std::endl; |
| 60 | if (data.type == StreamType::video && !data.direction |
| 61 | && data.direction == preferredStreamDirection) { |
| 62 | if (attached_ == "1") |
| 63 | detach(); |
agsantos | 3fcc621 | 2021-08-18 17:11:29 -0300 | [diff] [blame] | 64 | |
| 65 | setParameters(data.source); |
agsantos | 4bb4bc5 | 2021-03-08 14:21:45 -0500 | [diff] [blame] | 66 | subject->attach(mediaSubscriber_.get()); // your image |
| 67 | oss << "got my sent image attached" << std::endl; |
| 68 | attached_ = "1"; |
| 69 | } else if (data.type == StreamType::video && data.direction |
| 70 | && data.direction == preferredStreamDirection) { |
| 71 | if (attached_ == "1") |
| 72 | detach(); |
agsantos | 3fcc621 | 2021-08-18 17:11:29 -0300 | [diff] [blame] | 73 | setParameters(data.source); |
agsantos | 4bb4bc5 | 2021-03-08 14:21:45 -0500 | [diff] [blame] | 74 | subject->attach(mediaSubscriber_.get()); // the image you receive from others on the call |
| 75 | oss << "got received image attached" << std::endl; |
| 76 | attached_ = "1"; |
| 77 | } |
| 78 | |
| 79 | Plog::log(Plog::LogPriority::INFO, TAG, oss.str()); |
| 80 | } |
| 81 | |
agsantos | 3fcc621 | 2021-08-18 17:11:29 -0300 | [diff] [blame] | 82 | void |
| 83 | WatermarkMediaHandler::setParameters(const std::string& accountId) |
| 84 | { |
| 85 | if (accountId != accountId_) |
| 86 | return; |
| 87 | auto preferences = aph_->getPreferences(accountId); |
| 88 | try { |
| 89 | mediaSubscriber_->setParameter(preferences["fontsize"], Parameter::FONTSIZE); |
| 90 | mediaSubscriber_->setParameter(preferences["logosize"], Parameter::LOGOSIZE); |
| 91 | mediaSubscriber_->setParameter(preferences["markbackground"], Parameter::LOGOBACKGROUND); |
| 92 | mediaSubscriber_->setParameter(preferences["showinfos"], Parameter::SHOWINFOS); |
| 93 | mediaSubscriber_->setParameter(preferences["showlogo"], Parameter::SHOWLOGO); |
| 94 | mediaSubscriber_->setParameter(preferences["mark"], Parameter::LOGOPATH); |
| 95 | mediaSubscriber_->setParameter(preferences["date"], Parameter::DATE); |
| 96 | mediaSubscriber_->setParameter(preferences["dateformat"], Parameter::DATEFORMAT); |
| 97 | mediaSubscriber_->setParameter(preferences["time"], Parameter::TIME); |
| 98 | mediaSubscriber_->setParameter(preferences["timezone"], Parameter::TIMEZONE); |
| 99 | mediaSubscriber_->setParameter(preferences["timeformat"], Parameter::TIMEFORMAT); |
| 100 | mediaSubscriber_->setParameter(preferences["location"], Parameter::LOCATION); |
| 101 | mediaSubscriber_->setParameter(preferences["infosposition"], Parameter::INFOSPOSITION); |
| 102 | mediaSubscriber_->setParameter(preferences["logoposition"], Parameter::LOGOPOSITION); |
| 103 | } catch (std::exception e) { |
| 104 | Plog::log(Plog::LogPriority::ERR, TAG, e.what()); |
| 105 | } |
| 106 | } |
| 107 | |
agsantos | 4bb4bc5 | 2021-03-08 14:21:45 -0500 | [diff] [blame] | 108 | std::map<std::string, std::string> |
| 109 | WatermarkMediaHandler::getCallMediaHandlerDetails() |
| 110 | { |
| 111 | return {{"name", NAME}, |
| 112 | {"iconPath", datapath_ + sep + "icon.svg"}, |
| 113 | {"pluginId", id()}, |
| 114 | {"attached", attached_}, |
| 115 | {"dataType", "1"}}; |
| 116 | } |
| 117 | |
| 118 | void |
agsantos | 4bb4bc5 | 2021-03-08 14:21:45 -0500 | [diff] [blame] | 119 | WatermarkMediaHandler::detach() |
| 120 | { |
| 121 | attached_ = "0"; |
| 122 | mediaSubscriber_->detach(); |
| 123 | } |
| 124 | |
| 125 | WatermarkMediaHandler::~WatermarkMediaHandler() |
| 126 | { |
agsantos | 3fcc621 | 2021-08-18 17:11:29 -0300 | [diff] [blame] | 127 | Plog::log(Plog::LogPriority::INFO, TAG, "~WatermarkMediaHandler from WaterMark Plugin"); |
agsantos | 4bb4bc5 | 2021-03-08 14:21:45 -0500 | [diff] [blame] | 128 | detach(); |
| 129 | } |
| 130 | } // namespace jami |