blob: fe6ab4616b31de4da60432d4f12784ee25542794 [file] [log] [blame]
agsantos5aa39652020-08-11 18:18:04 -04001/**
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
agsantosac1940d2020-09-17 10:18:40 -040018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 * USA.
agsantos5aa39652020-08-11 18:18:04 -040020 */
21
22#include "pluginMediaHandler.h"
23// Logger
24#include "pluglog.h"
25const char sep = separator();
26const std::string TAG = "FORESEG";
27
28#define NAME "Foreground Segmentation"
29
30namespace jami {
31
agsantosac1940d2020-09-17 10:18:40 -040032PluginMediaHandler::PluginMediaHandler(std::map<std::string, std::string>&& ppm,
33 std::string&& datapath)
34 : datapath_ {datapath}
35 , ppm_ {ppm}
agsantos5aa39652020-08-11 18:18:04 -040036{
agsantosac1940d2020-09-17 10:18:40 -040037 setGlobalPluginParameters(ppm_);
38 setId(datapath_);
39 mVS = std::make_shared<VideoSubscriber>(datapath_);
agsantos5aa39652020-08-11 18:18:04 -040040}
41
42void
43PluginMediaHandler::notifyAVFrameSubject(const StreamData& data, jami::avSubjectPtr subject)
44{
agsantosac1940d2020-09-17 10:18:40 -040045 std::ostringstream oss;
46 std::string direction = data.direction ? "Receive" : "Preview";
47 oss << "NEW SUBJECT: [" << data.id << "," << direction << "]" << std::endl;
agsantos5aa39652020-08-11 18:18:04 -040048
agsantosac1940d2020-09-17 10:18:40 -040049 bool preferredStreamDirection = false;
agsantosc9181b42020-11-26 12:03:04 -050050 auto it = ppm_.find("streamslist");
51 if (it != ppm_.end()) {
agsantosac1940d2020-09-17 10:18:40 -040052 Plog::log(Plog::LogPriority::INFO, TAG, "SET PARAMETERS");
agsantosc9181b42020-11-26 12:03:04 -050053 preferredStreamDirection = it->second == "in";
agsantosac1940d2020-09-17 10:18:40 -040054 }
55 oss << "preferredStreamDirection " << preferredStreamDirection << std::endl;
56 if (data.type == StreamType::video && !data.direction
57 && data.direction == preferredStreamDirection) {
58 subject->attach(mVS.get()); // my image
59 oss << "got my sent image attached" << std::endl;
agsantosc9181b42020-11-26 12:03:04 -050060 attached_ = '1';
agsantosac1940d2020-09-17 10:18:40 -040061 } else if (data.type == StreamType::video && data.direction
agsantosc9181b42020-11-26 12:03:04 -050062 && data.direction == preferredStreamDirection) {
agsantosac1940d2020-09-17 10:18:40 -040063 subject->attach(mVS.get()); // the image I receive from the others on the call
agsantosc9181b42020-11-26 12:03:04 -050064 attached_ = '1';
65 }
agsantos5aa39652020-08-11 18:18:04 -040066
agsantosac1940d2020-09-17 10:18:40 -040067 Plog::log(Plog::LogPriority::INFO, TAG, oss.str());
agsantos5aa39652020-08-11 18:18:04 -040068}
69
70std::map<std::string, std::string>
71PluginMediaHandler::getCallMediaHandlerDetails()
72{
agsantosc9181b42020-11-26 12:03:04 -050073 return {{"name", NAME},
74 {"iconPath", datapath_ + sep + "icon.png"},
75 {"pluginId", id()},
76 {"attached", attached_},
77 {"dataType", "1"}};
agsantos5aa39652020-08-11 18:18:04 -040078}
79
80void
81PluginMediaHandler::setPreferenceAttribute(const std::string& key, const std::string& value)
82{
agsantosac1940d2020-09-17 10:18:40 -040083 auto it = ppm_.find(key);
agsantosc9181b42020-11-26 12:03:04 -050084 if (it != ppm_.end() && it->second != value) {
85 it->second = value;
86 if (key == "background") {
87 mVS->setBackground(value);
agsantosac1940d2020-09-17 10:18:40 -040088 }
89 }
agsantos5aa39652020-08-11 18:18:04 -040090}
91
92bool
93PluginMediaHandler::preferenceMapHasKey(const std::string& key)
94{
agsantosac1940d2020-09-17 10:18:40 -040095 if (key == "background") {
96 return true;
97 }
98 return false;
agsantos5aa39652020-08-11 18:18:04 -040099}
100
101void
102PluginMediaHandler::detach()
103{
agsantosc9181b42020-11-26 12:03:04 -0500104 attached_ = '0';
agsantosac1940d2020-09-17 10:18:40 -0400105 mVS->detach();
agsantos5aa39652020-08-11 18:18:04 -0400106}
107
108PluginMediaHandler::~PluginMediaHandler()
109{
agsantosac1940d2020-09-17 10:18:40 -0400110 std::ostringstream oss;
111 oss << " ~FORESEG Plugin" << std::endl;
112 Plog::log(Plog::LogPriority::INFO, TAG, oss.str());
113 detach();
agsantos5aa39652020-08-11 18:18:04 -0400114}
agsantosac1940d2020-09-17 10:18:40 -0400115} // namespace jami