blob: 47a61fae9fe7364f19a1b47d0db86954bfcd8a26 [file] [log] [blame]
agsantos4bb4bc52021-03-08 14:21:45 -05001/**
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
agsantos3fcc6212021-08-18 17:11:29 -030023#include "PluginPreferenceHandler.h"
agsantos4bb4bc52021-03-08 14:21:45 -050024#include "pluglog.h"
25#include <string_view>
26
27const char sep = separator();
28const std::string TAG = "Watermark";
29
30#define NAME "Watermark"
31
32namespace jami {
33
agsantos3fcc6212021-08-18 17:11:29 -030034WatermarkMediaHandler::WatermarkMediaHandler(std::string&& dataPath,
35 PluginPreferenceHandler* prefHandler)
36 : datapath_ {dataPath}
agsantos4bb4bc52021-03-08 14:21:45 -050037{
agsantos3fcc6212021-08-18 17:11:29 -030038 aph_ = prefHandler;
agsantos4bb4bc52021-03-08 14:21:45 -050039 setId(datapath_);
agsantos3fcc6212021-08-18 17:11:29 -030040 mediaSubscriber_ = std::make_shared<WatermarkVideoSubscriber>(datapath_);
41 setParameters("default");
agsantos4bb4bc52021-03-08 14:21:45 -050042}
43
44void
45WatermarkMediaHandler::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
agsantos3fcc6212021-08-18 17:11:29 -030051 accountId_ = data.source;
52 auto preferences = aph_->getPreferences(accountId_);
53
agsantos4bb4bc52021-03-08 14:21:45 -050054 bool preferredStreamDirection {false}; // false for output; true for input
agsantos3fcc6212021-08-18 17:11:29 -030055 auto it = preferences.find("videostream");
56 if (it != preferences.end()) {
agsantos4bb4bc52021-03-08 14:21:45 -050057 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();
agsantos3fcc6212021-08-18 17:11:29 -030064
65 setParameters(data.source);
agsantos4bb4bc52021-03-08 14:21:45 -050066 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();
agsantos3fcc6212021-08-18 17:11:29 -030073 setParameters(data.source);
agsantos4bb4bc52021-03-08 14:21:45 -050074 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
agsantos3fcc6212021-08-18 17:11:29 -030082void
83WatermarkMediaHandler::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
agsantos4bb4bc52021-03-08 14:21:45 -0500108std::map<std::string, std::string>
109WatermarkMediaHandler::getCallMediaHandlerDetails()
110{
111 return {{"name", NAME},
112 {"iconPath", datapath_ + sep + "icon.svg"},
113 {"pluginId", id()},
114 {"attached", attached_},
115 {"dataType", "1"}};
116}
117
118void
agsantos4bb4bc52021-03-08 14:21:45 -0500119WatermarkMediaHandler::detach()
120{
121 attached_ = "0";
122 mediaSubscriber_->detach();
123}
124
125WatermarkMediaHandler::~WatermarkMediaHandler()
126{
agsantos3fcc6212021-08-18 17:11:29 -0300127 Plog::log(Plog::LogPriority::INFO, TAG, "~WatermarkMediaHandler from WaterMark Plugin");
agsantos4bb4bc52021-03-08 14:21:45 -0500128 detach();
129}
130} // namespace jami