blob: 9aae38bee439b8f58be95ad7777d94b96aa2af8b [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 Plog::log(Plog::LogPriority::INFO, TAG, "IN AVFRAMESUBJECT");
46 std::ostringstream oss;
47 std::string direction = data.direction ? "Receive" : "Preview";
48 oss << "NEW SUBJECT: [" << data.id << "," << direction << "]" << std::endl;
agsantos5aa39652020-08-11 18:18:04 -040049
agsantosac1940d2020-09-17 10:18:40 -040050 bool preferredStreamDirection = false;
51 if (!ppm_.empty() && ppm_.find("streamslist") != ppm_.end()) {
52 Plog::log(Plog::LogPriority::INFO, TAG, "SET PARAMETERS");
53 preferredStreamDirection = ppm_.at("streamslist") == "in" ? true : false;
54 }
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;
60 } else if (data.type == StreamType::video && data.direction
61 && data.direction == preferredStreamDirection)
62 subject->attach(mVS.get()); // the image I receive from the others on the call
agsantos5aa39652020-08-11 18:18:04 -040063
agsantosac1940d2020-09-17 10:18:40 -040064 Plog::log(Plog::LogPriority::INFO, TAG, oss.str());
agsantos5aa39652020-08-11 18:18:04 -040065}
66
67std::map<std::string, std::string>
68PluginMediaHandler::getCallMediaHandlerDetails()
69{
agsantos1e7736c2020-10-28 14:39:13 -040070 return {{"name", NAME}, {"iconPath", datapath_ + sep + "icon.png"}, {"pluginId", id()}};
agsantos5aa39652020-08-11 18:18:04 -040071}
72
73void
74PluginMediaHandler::setPreferenceAttribute(const std::string& key, const std::string& value)
75{
agsantosac1940d2020-09-17 10:18:40 -040076 auto it = ppm_.find(key);
77 if (it != ppm_.end()) {
78 if (ppm_[key] != value) {
79 ppm_[key] = value;
80 if (key == "background") {
81 mVS->setBackground(value);
82 }
83 }
84 }
agsantos5aa39652020-08-11 18:18:04 -040085}
86
87bool
88PluginMediaHandler::preferenceMapHasKey(const std::string& key)
89{
agsantosac1940d2020-09-17 10:18:40 -040090 if (key == "background") {
91 return true;
92 }
93 return false;
agsantos5aa39652020-08-11 18:18:04 -040094}
95
96void
97PluginMediaHandler::detach()
98{
agsantosac1940d2020-09-17 10:18:40 -040099 mVS->detach();
agsantos5aa39652020-08-11 18:18:04 -0400100}
101
102PluginMediaHandler::~PluginMediaHandler()
103{
agsantosac1940d2020-09-17 10:18:40 -0400104 std::ostringstream oss;
105 oss << " ~FORESEG Plugin" << std::endl;
106 Plog::log(Plog::LogPriority::INFO, TAG, oss.str());
107 detach();
agsantos5aa39652020-08-11 18:18:04 -0400108}
agsantosac1940d2020-09-17 10:18:40 -0400109} // namespace jami