agsantos | d09cc6d | 2020-11-06 17:34:46 -0500 | [diff] [blame] | 1 | /** |
Sébastien Blin | cb783e3 | 2021-02-12 11:34:10 -0500 | [diff] [blame] | 2 | * Copyright (C) 2020-2021 Savoir-faire Linux Inc. |
agsantos | d09cc6d | 2020-11-06 17:34:46 -0500 | [diff] [blame] | 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 "CoinCircleMediaHandler.h" |
agsantos | d09cc6d | 2020-11-06 17:34:46 -0500 | [diff] [blame] | 22 | #include "pluglog.h" |
agsantos | 82678f3 | 2020-12-09 15:03:24 -0500 | [diff] [blame] | 23 | #include <string_view> |
agsantos | c9181b4 | 2020-11-26 12:03:04 -0500 | [diff] [blame] | 24 | |
agsantos | d09cc6d | 2020-11-06 17:34:46 -0500 | [diff] [blame] | 25 | const char sep = separator(); |
| 26 | const std::string TAG = "CoinCircle"; |
| 27 | |
| 28 | #define NAME "CoinCircle" |
| 29 | |
| 30 | namespace jami { |
| 31 | |
agsantos | 82678f3 | 2020-12-09 15:03:24 -0500 | [diff] [blame] | 32 | CoinCircleMediaHandler::CoinCircleMediaHandler(std::map<std::string, std::string>&& preferences, |
agsantos | d09cc6d | 2020-11-06 17:34:46 -0500 | [diff] [blame] | 33 | std::string&& datapath) |
| 34 | : datapath_ {datapath} |
agsantos | 82678f3 | 2020-12-09 15:03:24 -0500 | [diff] [blame] | 35 | , preferences_ {preferences} |
agsantos | d09cc6d | 2020-11-06 17:34:46 -0500 | [diff] [blame] | 36 | { |
| 37 | setId(datapath_); |
| 38 | mVS = std::make_shared<CoinCircleVideoSubscriber>(datapath_); |
agsantos | 82678f3 | 2020-12-09 15:03:24 -0500 | [diff] [blame] | 39 | auto it = preferences_.find("color"); |
| 40 | if (it != preferences_.end()) { |
agsantos | d09cc6d | 2020-11-06 17:34:46 -0500 | [diff] [blame] | 41 | mVS->setColor(it->second); |
| 42 | } else { |
| 43 | mVS->setColor("#0000FF"); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | void |
| 48 | CoinCircleMediaHandler::notifyAVFrameSubject(const StreamData& data, jami::avSubjectPtr subject) |
| 49 | { |
agsantos | d09cc6d | 2020-11-06 17:34:46 -0500 | [diff] [blame] | 50 | std::ostringstream oss; |
agsantos | 82678f3 | 2020-12-09 15:03:24 -0500 | [diff] [blame] | 51 | std::string_view direction = data.direction ? "Receive" : "Preview"; |
agsantos | d09cc6d | 2020-11-06 17:34:46 -0500 | [diff] [blame] | 52 | oss << "NEW SUBJECT: [" << data.id << "," << direction << "]" << std::endl; |
| 53 | |
| 54 | bool preferredStreamDirection = false; // false for output; true for input |
agsantos | 82678f3 | 2020-12-09 15:03:24 -0500 | [diff] [blame] | 55 | auto it = preferences_.find("videostream"); |
| 56 | if (it != preferences_.end()) { |
agsantos | d09cc6d | 2020-11-06 17:34:46 -0500 | [diff] [blame] | 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; |
agsantos | c9181b4 | 2020-11-26 12:03:04 -0500 | [diff] [blame] | 64 | attached_ = "1"; |
agsantos | d09cc6d | 2020-11-06 17:34:46 -0500 | [diff] [blame] | 65 | } 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; |
agsantos | c9181b4 | 2020-11-26 12:03:04 -0500 | [diff] [blame] | 69 | attached_ = "1"; |
agsantos | d09cc6d | 2020-11-06 17:34:46 -0500 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | Plog::log(Plog::LogPriority::INFO, TAG, oss.str()); |
| 73 | } |
| 74 | |
| 75 | std::map<std::string, std::string> |
| 76 | CoinCircleMediaHandler::getCallMediaHandlerDetails() |
| 77 | { |
agsantos | c9181b4 | 2020-11-26 12:03:04 -0500 | [diff] [blame] | 78 | return {{"name", NAME}, |
agsantos | d00bf41 | 2021-01-26 13:43:33 -0500 | [diff] [blame] | 79 | {"iconPath", datapath_ + sep + "icon.svg"}, |
agsantos | c9181b4 | 2020-11-26 12:03:04 -0500 | [diff] [blame] | 80 | {"pluginId", id()}, |
| 81 | {"attached", attached_}, |
| 82 | {"dataType", "1"}}; |
agsantos | d09cc6d | 2020-11-06 17:34:46 -0500 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | void |
| 86 | CoinCircleMediaHandler::setPreferenceAttribute(const std::string& key, const std::string& value) |
| 87 | { |
agsantos | 82678f3 | 2020-12-09 15:03:24 -0500 | [diff] [blame] | 88 | auto it = preferences_.find(key); |
| 89 | if (it != preferences_.end() && it->second != value) { |
agsantos | d09cc6d | 2020-11-06 17:34:46 -0500 | [diff] [blame] | 90 | it->second = value; |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | bool |
| 95 | CoinCircleMediaHandler::preferenceMapHasKey(const std::string& key) |
| 96 | { |
| 97 | return false; |
| 98 | } |
| 99 | |
| 100 | void |
| 101 | CoinCircleMediaHandler::detach() |
| 102 | { |
agsantos | c9181b4 | 2020-11-26 12:03:04 -0500 | [diff] [blame] | 103 | attached_ = "0"; |
agsantos | d09cc6d | 2020-11-06 17:34:46 -0500 | [diff] [blame] | 104 | mVS->detach(); |
| 105 | } |
| 106 | |
| 107 | CoinCircleMediaHandler::~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 |