blob: 8f3f1bbbfa7874302b1faf5ab4daaa768bca8161 [file] [log] [blame]
agsantosd09cc6d2020-11-06 17:34:46 -05001/**
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
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21#include "CenterCircleMediaHandler.h"
22
23#include "pluglog.h"
agsantosc9181b42020-11-26 12:03:04 -050024
agsantosd09cc6d2020-11-06 17:34:46 -050025const char sep = separator();
26const std::string TAG = "CenterCircle";
27
28#define NAME "CenterCircle"
29
30namespace jami {
31
32CenterCircleMediaHandler::CenterCircleMediaHandler(std::map<std::string, std::string>&& ppm,
33 std::string&& datapath)
34 : datapath_ {datapath}
35 , ppm_ {ppm}
36{
37 setId(datapath_);
38 mVS = std::make_shared<CenterCircleVideoSubscriber>(datapath_);
39 auto it = ppm_.find("color");
40 if (it != ppm_.end()) {
41 mVS->setColor(it->second);
42 } else {
43 mVS->setColor("#0000FF");
44 }
45}
46
47void
48CenterCircleMediaHandler::notifyAVFrameSubject(const StreamData& data, jami::avSubjectPtr subject)
49{
agsantosd09cc6d2020-11-06 17:34:46 -050050 std::ostringstream oss;
51 std::string direction = data.direction ? "Receive" : "Preview";
52 oss << "NEW SUBJECT: [" << data.id << "," << direction << "]" << std::endl;
53
54 bool preferredStreamDirection = false; // false for output; true for input
55 auto it = ppm_.find("videostream");
56 if (it != ppm_.end()) {
57 preferredStreamDirection = it->second == "1";
58 }
59 oss << "preferredStreamDirection " << preferredStreamDirection << std::endl;
60 if (data.type == StreamType::video && !data.direction
61 && data.direction == preferredStreamDirection) {
62 subject->attach(mVS.get()); // your image
63 oss << "got my sent image attached" << std::endl;
agsantosc9181b42020-11-26 12:03:04 -050064 attached_ = "1";
agsantosd09cc6d2020-11-06 17:34:46 -050065 } else if (data.type == StreamType::video && data.direction
66 && data.direction == preferredStreamDirection) {
67 subject->attach(mVS.get()); // the image you receive from others on the call
68 oss << "got received image attached" << std::endl;
agsantosc9181b42020-11-26 12:03:04 -050069 attached_ = "1";
agsantosd09cc6d2020-11-06 17:34:46 -050070 }
71
72 Plog::log(Plog::LogPriority::INFO, TAG, oss.str());
73}
74
75std::map<std::string, std::string>
76CenterCircleMediaHandler::getCallMediaHandlerDetails()
77{
agsantosc9181b42020-11-26 12:03:04 -050078 return {{"name", NAME},
79 {"iconPath", datapath_ + sep + "icon.png"},
80 {"pluginId", id()},
81 {"attached", attached_},
82 {"dataType", "1"}};
agsantosd09cc6d2020-11-06 17:34:46 -050083}
84
85void
86CenterCircleMediaHandler::setPreferenceAttribute(const std::string& key, const std::string& value)
87{
88 auto it = ppm_.find(key);
89 if (it != ppm_.end() && it->second != value) {
90 it->second = value;
91
92 if (key == "color") {
93 mVS->setColor(value);
94 return;
95 }
96 }
97}
98
99bool
100CenterCircleMediaHandler::preferenceMapHasKey(const std::string& key)
101{
102 if (key == "color") {
103 return true;
104 }
105
106 return false;
107}
108
109void
110CenterCircleMediaHandler::detach()
111{
agsantosc9181b42020-11-26 12:03:04 -0500112 attached_ = "0";
agsantosd09cc6d2020-11-06 17:34:46 -0500113 mVS->detach();
114}
115
116CenterCircleMediaHandler::~CenterCircleMediaHandler()
117{
118 std::ostringstream oss;
119 oss << " ~CenterCircleMediaHandler from HelloWorld Plugin" << std::endl;
120 Plog::log(Plog::LogPriority::INFO, TAG, oss.str());
121 detach();
122}
123} // namespace jami