blob: acc3118738531e0513f408d79d34374bf039eb30 [file] [log] [blame]
agsantosd09cc6d2020-11-06 17:34:46 -05001/**
Sébastien Blincb783e32021-02-12 11:34:10 -05002 * Copyright (C) 2020-2021 Savoir-faire Linux Inc.
agsantosd09cc6d2020-11-06 17:34:46 -05003 *
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 "CoinCircleMediaHandler.h"
agsantosd09cc6d2020-11-06 17:34:46 -050022#include "pluglog.h"
agsantos82678f32020-12-09 15:03:24 -050023#include <string_view>
agsantosc9181b42020-11-26 12:03:04 -050024
agsantosd09cc6d2020-11-06 17:34:46 -050025const char sep = separator();
26const std::string TAG = "CoinCircle";
27
28#define NAME "CoinCircle"
29
30namespace jami {
31
agsantos82678f32020-12-09 15:03:24 -050032CoinCircleMediaHandler::CoinCircleMediaHandler(std::map<std::string, std::string>&& preferences,
agsantosd09cc6d2020-11-06 17:34:46 -050033 std::string&& datapath)
34 : datapath_ {datapath}
agsantos82678f32020-12-09 15:03:24 -050035 , preferences_ {preferences}
agsantosd09cc6d2020-11-06 17:34:46 -050036{
37 setId(datapath_);
38 mVS = std::make_shared<CoinCircleVideoSubscriber>(datapath_);
agsantos82678f32020-12-09 15:03:24 -050039 auto it = preferences_.find("color");
40 if (it != preferences_.end()) {
agsantosd09cc6d2020-11-06 17:34:46 -050041 mVS->setColor(it->second);
42 } else {
43 mVS->setColor("#0000FF");
44 }
45}
46
47void
48CoinCircleMediaHandler::notifyAVFrameSubject(const StreamData& data, jami::avSubjectPtr subject)
49{
agsantosd09cc6d2020-11-06 17:34:46 -050050 std::ostringstream oss;
agsantos82678f32020-12-09 15:03:24 -050051 std::string_view direction = data.direction ? "Receive" : "Preview";
agsantosd09cc6d2020-11-06 17:34:46 -050052 oss << "NEW SUBJECT: [" << data.id << "," << direction << "]" << std::endl;
53
54 bool preferredStreamDirection = false; // false for output; true for input
agsantos82678f32020-12-09 15:03:24 -050055 auto it = preferences_.find("videostream");
56 if (it != preferences_.end()) {
agsantosd09cc6d2020-11-06 17:34:46 -050057 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>
76CoinCircleMediaHandler::getCallMediaHandlerDetails()
77{
agsantosc9181b42020-11-26 12:03:04 -050078 return {{"name", NAME},
agsantosd00bf412021-01-26 13:43:33 -050079 {"iconPath", datapath_ + sep + "icon.svg"},
agsantosc9181b42020-11-26 12:03:04 -050080 {"pluginId", id()},
81 {"attached", attached_},
82 {"dataType", "1"}};
agsantosd09cc6d2020-11-06 17:34:46 -050083}
84
85void
86CoinCircleMediaHandler::setPreferenceAttribute(const std::string& key, const std::string& value)
87{
agsantos82678f32020-12-09 15:03:24 -050088 auto it = preferences_.find(key);
89 if (it != preferences_.end() && it->second != value) {
agsantosd09cc6d2020-11-06 17:34:46 -050090 it->second = value;
91 }
92}
93
94bool
95CoinCircleMediaHandler::preferenceMapHasKey(const std::string& key)
96{
97 return false;
98}
99
100void
101CoinCircleMediaHandler::detach()
102{
agsantosc9181b42020-11-26 12:03:04 -0500103 attached_ = "0";
agsantosd09cc6d2020-11-06 17:34:46 -0500104 mVS->detach();
105}
106
107CoinCircleMediaHandler::~CoinCircleMediaHandler()
108{
109 std::ostringstream oss;
110 oss << " ~CoinCircleMediaHandler from HelloWorld Plugin" << std::endl;
111 Plog::log(Plog::LogPriority::INFO, TAG, oss.str());
112 detach();
113}
114} // namespace jami