WaterMark: create water mark plugin
GitLab: #13
Change-Id: Idab3d0b8fdfe6af2b481ac483a5b7ff423bec418
diff --git a/WaterMark/WatermarkMediaHandler.cpp b/WaterMark/WatermarkMediaHandler.cpp
new file mode 100644
index 0000000..904a589
--- /dev/null
+++ b/WaterMark/WatermarkMediaHandler.cpp
@@ -0,0 +1,173 @@
+/**
+ * Copyright (C) 2021 Savoir-faire Linux Inc.
+ *
+ * Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "WatermarkMediaHandler.h"
+
+#include "pluglog.h"
+#include <string_view>
+
+const char sep = separator();
+const std::string TAG = "Watermark";
+
+#define NAME "Watermark"
+
+namespace jami {
+
+WatermarkMediaHandler::WatermarkMediaHandler(std::map<std::string, std::string>&& preferences,
+ std::string&& datapath)
+ : datapath_ {datapath}
+ , preferences_ {preferences}
+{
+ setId(datapath_);
+ mediaSubscriber_ = std::make_shared<WatermarkVideoSubscriber>(datapath_, preferences_);
+}
+
+void
+WatermarkMediaHandler::notifyAVFrameSubject(const StreamData& data, jami::avSubjectPtr subject)
+{
+ std::ostringstream oss;
+ std::string_view direction = data.direction ? "Receive" : "Preview";
+ oss << "NEW SUBJECT: [" << data.id << "," << direction << "]" << std::endl;
+
+ bool preferredStreamDirection {false}; // false for output; true for input
+ auto it = preferences_.find("videostream");
+ if (it != preferences_.end()) {
+ preferredStreamDirection = it->second == "1";
+ }
+ oss << "preferredStreamDirection " << preferredStreamDirection << std::endl;
+ if (data.type == StreamType::video && !data.direction
+ && data.direction == preferredStreamDirection) {
+ if (attached_ == "1")
+ detach();
+ subject->attach(mediaSubscriber_.get()); // your image
+ oss << "got my sent image attached" << std::endl;
+ attached_ = "1";
+ } else if (data.type == StreamType::video && data.direction
+ && data.direction == preferredStreamDirection) {
+ if (attached_ == "1")
+ detach();
+ subject->attach(mediaSubscriber_.get()); // the image you receive from others on the call
+ oss << "got received image attached" << std::endl;
+ attached_ = "1";
+ }
+
+ Plog::log(Plog::LogPriority::INFO, TAG, oss.str());
+}
+
+std::map<std::string, std::string>
+WatermarkMediaHandler::getCallMediaHandlerDetails()
+{
+ return {{"name", NAME},
+ {"iconPath", datapath_ + sep + "icon.svg"},
+ {"pluginId", id()},
+ {"attached", attached_},
+ {"dataType", "1"}};
+}
+
+void
+WatermarkMediaHandler::setPreferenceAttribute(const std::string& key, const std::string& value)
+{
+ auto it = preferences_.find(key);
+ if (it != preferences_.end() && it->second != value) {
+ it->second = value;
+ if (key == "showlogo") {
+ mediaSubscriber_->setParameter(it->second, Parameter::SHOWLOGO);
+ return;
+ }
+ if (key == "mark") {
+ mediaSubscriber_->setParameter(it->second, Parameter::LOGOPATH);
+ return;
+ }
+ if (key == "markbackground") {
+ mediaSubscriber_->setParameter(it->second, Parameter::LOGOBACKGROUND);
+ return;
+ }
+ if (key == "location") {
+ mediaSubscriber_->setParameter(it->second, Parameter::LOCATION);
+ return;
+ }
+ if (key == "date") {
+ mediaSubscriber_->setParameter(it->second, Parameter::DATE);
+ return;
+ }
+ if (key == "time") {
+ mediaSubscriber_->setParameter(it->second, Parameter::TIME);
+ return;
+ }
+ if (key == "logoposition") {
+ mediaSubscriber_->setParameter(it->second, Parameter::LOGOPOSITION);
+ return;
+ }
+ if (key == "infosposition") {
+ mediaSubscriber_->setParameter(it->second, Parameter::INFOSPOSITION);
+ return;
+ }
+ if (key == "timeformat") {
+ mediaSubscriber_->setParameter(it->second, Parameter::TIMEFORMAT);
+ return;
+ }
+ if (key == "timezone") {
+ mediaSubscriber_->setParameter(it->second, Parameter::TIMEZONE);
+ mediaSubscriber_->setParameter(preferences_["timeformat"], Parameter::TIMEFORMAT);
+ return;
+ }
+ if (key == "dateformat") {
+ mediaSubscriber_->setParameter(it->second, Parameter::DATEFORMAT);
+ return;
+ }
+ if (key == "fontsize") {
+ mediaSubscriber_->setParameter(it->second, Parameter::FONTSIZE);
+ return;
+ }
+ if (key == "logosize") {
+ mediaSubscriber_->setParameter(it->second, Parameter::LOGOSIZE);
+ return;
+ }
+ if (key == "showinfos") {
+ mediaSubscriber_->setParameter(it->second, Parameter::SHOWINFOS);
+ return;
+ }
+ }
+}
+
+bool
+WatermarkMediaHandler::preferenceMapHasKey(const std::string& key)
+{
+ return (key == "showlogo" || key == "mark" || key == "markbackground" || key == "logosize"
+ || key == "showinfos" || key == "location" || key == "date" || key == "time"
+ || key == "infosposition" || key == "logoposition" || key == "timeformat"
+ || key == "timezone" || key == "dateformat" || key == "fontsize");
+}
+
+void
+WatermarkMediaHandler::detach()
+{
+ attached_ = "0";
+ mediaSubscriber_->detach();
+}
+
+WatermarkMediaHandler::~WatermarkMediaHandler()
+{
+ std::ostringstream oss;
+ oss << " ~WatermarkMediaHandler from WaterMark Plugin" << std::endl;
+ Plog::log(Plog::LogPriority::INFO, TAG, oss.str());
+ detach();
+}
+} // namespace jami