blob: 904a589f6eaefad382581df42cff1ec9b6e5db29 [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
23#include "pluglog.h"
24#include <string_view>
25
26const char sep = separator();
27const std::string TAG = "Watermark";
28
29#define NAME "Watermark"
30
31namespace jami {
32
33WatermarkMediaHandler::WatermarkMediaHandler(std::map<std::string, std::string>&& preferences,
34 std::string&& datapath)
35 : datapath_ {datapath}
36 , preferences_ {preferences}
37{
38 setId(datapath_);
39 mediaSubscriber_ = std::make_shared<WatermarkVideoSubscriber>(datapath_, preferences_);
40}
41
42void
43WatermarkMediaHandler::notifyAVFrameSubject(const StreamData& data, jami::avSubjectPtr subject)
44{
45 std::ostringstream oss;
46 std::string_view direction = data.direction ? "Receive" : "Preview";
47 oss << "NEW SUBJECT: [" << data.id << "," << direction << "]" << std::endl;
48
49 bool preferredStreamDirection {false}; // false for output; true for input
50 auto it = preferences_.find("videostream");
51 if (it != preferences_.end()) {
52 preferredStreamDirection = it->second == "1";
53 }
54 oss << "preferredStreamDirection " << preferredStreamDirection << std::endl;
55 if (data.type == StreamType::video && !data.direction
56 && data.direction == preferredStreamDirection) {
57 if (attached_ == "1")
58 detach();
59 subject->attach(mediaSubscriber_.get()); // your image
60 oss << "got my sent image attached" << std::endl;
61 attached_ = "1";
62 } else if (data.type == StreamType::video && data.direction
63 && data.direction == preferredStreamDirection) {
64 if (attached_ == "1")
65 detach();
66 subject->attach(mediaSubscriber_.get()); // the image you receive from others on the call
67 oss << "got received image attached" << std::endl;
68 attached_ = "1";
69 }
70
71 Plog::log(Plog::LogPriority::INFO, TAG, oss.str());
72}
73
74std::map<std::string, std::string>
75WatermarkMediaHandler::getCallMediaHandlerDetails()
76{
77 return {{"name", NAME},
78 {"iconPath", datapath_ + sep + "icon.svg"},
79 {"pluginId", id()},
80 {"attached", attached_},
81 {"dataType", "1"}};
82}
83
84void
85WatermarkMediaHandler::setPreferenceAttribute(const std::string& key, const std::string& value)
86{
87 auto it = preferences_.find(key);
88 if (it != preferences_.end() && it->second != value) {
89 it->second = value;
90 if (key == "showlogo") {
91 mediaSubscriber_->setParameter(it->second, Parameter::SHOWLOGO);
92 return;
93 }
94 if (key == "mark") {
95 mediaSubscriber_->setParameter(it->second, Parameter::LOGOPATH);
96 return;
97 }
98 if (key == "markbackground") {
99 mediaSubscriber_->setParameter(it->second, Parameter::LOGOBACKGROUND);
100 return;
101 }
102 if (key == "location") {
103 mediaSubscriber_->setParameter(it->second, Parameter::LOCATION);
104 return;
105 }
106 if (key == "date") {
107 mediaSubscriber_->setParameter(it->second, Parameter::DATE);
108 return;
109 }
110 if (key == "time") {
111 mediaSubscriber_->setParameter(it->second, Parameter::TIME);
112 return;
113 }
114 if (key == "logoposition") {
115 mediaSubscriber_->setParameter(it->second, Parameter::LOGOPOSITION);
116 return;
117 }
118 if (key == "infosposition") {
119 mediaSubscriber_->setParameter(it->second, Parameter::INFOSPOSITION);
120 return;
121 }
122 if (key == "timeformat") {
123 mediaSubscriber_->setParameter(it->second, Parameter::TIMEFORMAT);
124 return;
125 }
126 if (key == "timezone") {
127 mediaSubscriber_->setParameter(it->second, Parameter::TIMEZONE);
128 mediaSubscriber_->setParameter(preferences_["timeformat"], Parameter::TIMEFORMAT);
129 return;
130 }
131 if (key == "dateformat") {
132 mediaSubscriber_->setParameter(it->second, Parameter::DATEFORMAT);
133 return;
134 }
135 if (key == "fontsize") {
136 mediaSubscriber_->setParameter(it->second, Parameter::FONTSIZE);
137 return;
138 }
139 if (key == "logosize") {
140 mediaSubscriber_->setParameter(it->second, Parameter::LOGOSIZE);
141 return;
142 }
143 if (key == "showinfos") {
144 mediaSubscriber_->setParameter(it->second, Parameter::SHOWINFOS);
145 return;
146 }
147 }
148}
149
150bool
151WatermarkMediaHandler::preferenceMapHasKey(const std::string& key)
152{
153 return (key == "showlogo" || key == "mark" || key == "markbackground" || key == "logosize"
154 || key == "showinfos" || key == "location" || key == "date" || key == "time"
155 || key == "infosposition" || key == "logoposition" || key == "timeformat"
156 || key == "timezone" || key == "dateformat" || key == "fontsize");
157}
158
159void
160WatermarkMediaHandler::detach()
161{
162 attached_ = "0";
163 mediaSubscriber_->detach();
164}
165
166WatermarkMediaHandler::~WatermarkMediaHandler()
167{
168 std::ostringstream oss;
169 oss << " ~WatermarkMediaHandler from WaterMark Plugin" << std::endl;
170 Plog::log(Plog::LogPriority::INFO, TAG, oss.str());
171 detach();
172}
173} // namespace jami