blob: 44d68c75b63cf0e0ff9b6f3f57ec2bdcf3f2c38c [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"
agsantos82678f32020-12-09 15:03:24 -050025#include <string_view>
agsantos5aa39652020-08-11 18:18:04 -040026const char sep = separator();
27const std::string TAG = "FORESEG";
28
29#define NAME "Foreground Segmentation"
30
31namespace jami {
32
agsantos82678f32020-12-09 15:03:24 -050033PluginMediaHandler::PluginMediaHandler(std::map<std::string, std::string>&& preferences,
agsantosac1940d2020-09-17 10:18:40 -040034 std::string&& datapath)
35 : datapath_ {datapath}
agsantos82678f32020-12-09 15:03:24 -050036 , preferences_ {preferences}
agsantos5aa39652020-08-11 18:18:04 -040037{
agsantos82678f32020-12-09 15:03:24 -050038 setGlobalPluginParameters(preferences_);
agsantosac1940d2020-09-17 10:18:40 -040039 setId(datapath_);
40 mVS = std::make_shared<VideoSubscriber>(datapath_);
agsantos5aa39652020-08-11 18:18:04 -040041}
42
43void
44PluginMediaHandler::notifyAVFrameSubject(const StreamData& data, jami::avSubjectPtr subject)
45{
agsantosac1940d2020-09-17 10:18:40 -040046 std::ostringstream oss;
agsantos82678f32020-12-09 15:03:24 -050047 std::string_view direction = data.direction ? "Receive" : "Preview";
agsantosac1940d2020-09-17 10:18:40 -040048 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;
agsantos82678f32020-12-09 15:03:24 -050051 auto it = preferences_.find("streamslist");
52 if (it != preferences_.end()) {
agsantosac1940d2020-09-17 10:18:40 -040053 Plog::log(Plog::LogPriority::INFO, TAG, "SET PARAMETERS");
agsantosc9181b42020-11-26 12:03:04 -050054 preferredStreamDirection = it->second == "in";
agsantosac1940d2020-09-17 10:18:40 -040055 }
56 oss << "preferredStreamDirection " << preferredStreamDirection << std::endl;
57 if (data.type == StreamType::video && !data.direction
58 && data.direction == preferredStreamDirection) {
59 subject->attach(mVS.get()); // my image
60 oss << "got my sent image attached" << std::endl;
agsantosc9181b42020-11-26 12:03:04 -050061 attached_ = '1';
agsantosac1940d2020-09-17 10:18:40 -040062 } else if (data.type == StreamType::video && data.direction
agsantosc9181b42020-11-26 12:03:04 -050063 && data.direction == preferredStreamDirection) {
agsantosac1940d2020-09-17 10:18:40 -040064 subject->attach(mVS.get()); // the image I receive from the others on the call
agsantosc9181b42020-11-26 12:03:04 -050065 attached_ = '1';
66 }
agsantos5aa39652020-08-11 18:18:04 -040067
agsantosac1940d2020-09-17 10:18:40 -040068 Plog::log(Plog::LogPriority::INFO, TAG, oss.str());
agsantos5aa39652020-08-11 18:18:04 -040069}
70
71std::map<std::string, std::string>
72PluginMediaHandler::getCallMediaHandlerDetails()
73{
agsantosc9181b42020-11-26 12:03:04 -050074 return {{"name", NAME},
75 {"iconPath", datapath_ + sep + "icon.png"},
76 {"pluginId", id()},
77 {"attached", attached_},
78 {"dataType", "1"}};
agsantos5aa39652020-08-11 18:18:04 -040079}
80
81void
82PluginMediaHandler::setPreferenceAttribute(const std::string& key, const std::string& value)
83{
agsantos82678f32020-12-09 15:03:24 -050084 auto it = preferences_.find(key);
85 if (it != preferences_.end() && it->second != value) {
agsantosc9181b42020-11-26 12:03:04 -050086 it->second = value;
87 if (key == "background") {
88 mVS->setBackground(value);
agsantosac1940d2020-09-17 10:18:40 -040089 }
90 }
agsantos5aa39652020-08-11 18:18:04 -040091}
92
93bool
94PluginMediaHandler::preferenceMapHasKey(const std::string& key)
95{
agsantosac1940d2020-09-17 10:18:40 -040096 if (key == "background") {
97 return true;
98 }
99 return false;
agsantos5aa39652020-08-11 18:18:04 -0400100}
101
102void
103PluginMediaHandler::detach()
104{
agsantosc9181b42020-11-26 12:03:04 -0500105 attached_ = '0';
agsantosac1940d2020-09-17 10:18:40 -0400106 mVS->detach();
agsantos5aa39652020-08-11 18:18:04 -0400107}
108
109PluginMediaHandler::~PluginMediaHandler()
110{
agsantosac1940d2020-09-17 10:18:40 -0400111 std::ostringstream oss;
112 oss << " ~FORESEG Plugin" << std::endl;
113 Plog::log(Plog::LogPriority::INFO, TAG, oss.str());
114 detach();
agsantos5aa39652020-08-11 18:18:04 -0400115}
agsantosac1940d2020-09-17 10:18:40 -0400116} // namespace jami