blob: 903f96f596920c288633c45e992d934809617b33 [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"
24const char sep = separator();
25const std::string TAG = "CenterCircle";
26
27#define NAME "CenterCircle"
28
29namespace jami {
30
31CenterCircleMediaHandler::CenterCircleMediaHandler(std::map<std::string, std::string>&& ppm,
32 std::string&& datapath)
33 : datapath_ {datapath}
34 , ppm_ {ppm}
35{
36 setId(datapath_);
37 mVS = std::make_shared<CenterCircleVideoSubscriber>(datapath_);
38 auto it = ppm_.find("color");
39 if (it != ppm_.end()) {
40 mVS->setColor(it->second);
41 } else {
42 mVS->setColor("#0000FF");
43 }
44}
45
46void
47CenterCircleMediaHandler::notifyAVFrameSubject(const StreamData& data, jami::avSubjectPtr subject)
48{
49 Plog::log(Plog::LogPriority::INFO, TAG, "IN AVFRAMESUBJECT");
50 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;
64 } else if (data.type == StreamType::video && data.direction
65 && data.direction == preferredStreamDirection) {
66 subject->attach(mVS.get()); // the image you receive from others on the call
67 oss << "got received image attached" << std::endl;
68 }
69
70 Plog::log(Plog::LogPriority::INFO, TAG, oss.str());
71}
72
73std::map<std::string, std::string>
74CenterCircleMediaHandler::getCallMediaHandlerDetails()
75{
76 return {{"name", NAME}, {"iconPath", datapath_ + sep + "icon.png"}, {"pluginId", id()}};
77}
78
79void
80CenterCircleMediaHandler::setPreferenceAttribute(const std::string& key, const std::string& value)
81{
82 auto it = ppm_.find(key);
83 if (it != ppm_.end() && it->second != value) {
84 it->second = value;
85
86 if (key == "color") {
87 mVS->setColor(value);
88 return;
89 }
90 }
91}
92
93bool
94CenterCircleMediaHandler::preferenceMapHasKey(const std::string& key)
95{
96 if (key == "color") {
97 return true;
98 }
99
100 return false;
101}
102
103void
104CenterCircleMediaHandler::detach()
105{
106 mVS->detach();
107}
108
109CenterCircleMediaHandler::~CenterCircleMediaHandler()
110{
111 std::ostringstream oss;
112 oss << " ~CenterCircleMediaHandler from HelloWorld Plugin" << std::endl;
113 Plog::log(Plog::LogPriority::INFO, TAG, oss.str());
114 detach();
115}
116} // namespace jami