blob: e04a6035b86abc0c27d743c37473ea9aa975ec3f [file] [log] [blame]
agsantosc9181b42020-11-26 12:03:04 -05001/**
Sébastien Blincb783e32021-02-12 11:34:10 -05002 * Copyright (C) 2020-2021 Savoir-faire Linux Inc.
agsantosc9181b42020-11-26 12:03:04 -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
agsantos82678f32020-12-09 15:03:24 -050021#include "FilterMediaHandler.h"
agsantosc9181b42020-11-26 12:03:04 -050022
23#include "pluglog.h"
agsantos82678f32020-12-09 15:03:24 -050024#include <string_view>
agsantosc9181b42020-11-26 12:03:04 -050025
26const char sep = separator();
agsantosb3c90842020-12-10 14:19:41 -050027const std::string TAG = "Filter";
agsantosc9181b42020-11-26 12:03:04 -050028
agsantosb3c90842020-12-10 14:19:41 -050029#define NAME "Filter"
agsantosc9181b42020-11-26 12:03:04 -050030
31namespace jami {
32
agsantos82678f32020-12-09 15:03:24 -050033FilterMediaHandler::FilterMediaHandler(std::map<std::string, std::string>&& preferences,
agsantosc9181b42020-11-26 12:03:04 -050034 std::string&& datapath)
35 : datapath_ {datapath}
agsantos82678f32020-12-09 15:03:24 -050036 , preferences_ {preferences}
agsantosc9181b42020-11-26 12:03:04 -050037{
38 setId(datapath_);
agsantos82678f32020-12-09 15:03:24 -050039 auto it = preferences_.find("irFile");
40 if (it != preferences_.end())
agsantosc9181b42020-11-26 12:03:04 -050041 mAS = std::make_shared<FilterAudioSubscriber>(datapath_, it->second);
42}
43
44void
agsantos82678f32020-12-09 15:03:24 -050045FilterMediaHandler::notifyAVFrameSubject(const StreamData& data, jami::avSubjectPtr subject)
agsantosc9181b42020-11-26 12:03:04 -050046{
47 if (!mAS)
48 return;
49 std::ostringstream oss;
agsantos82678f32020-12-09 15:03:24 -050050 std::string_view direction = data.direction ? "Receive" : "Preview";
agsantosc9181b42020-11-26 12:03:04 -050051 oss << "NEW SUBJECT: [" << data.id << "," << direction << "]" << std::endl;
52 bool preferredStreamDirection = false; // false for output; true for input
agsantos82678f32020-12-09 15:03:24 -050053 auto it = preferences_.find("streamlist");
54 if (it != preferences_.end()) {
agsantosc9181b42020-11-26 12:03:04 -050055 preferredStreamDirection = it->second == "in";
56 }
57 oss << "preferredStreamDirection " << preferredStreamDirection << std::endl;
58 if (data.type == StreamType::audio && !data.direction
59 && data.direction == preferredStreamDirection) {
60 subject->attach(mAS.get()); // your image
61 oss << "got my sent audio attached" << std::endl;
62 attached_ = '1';
63 } else if (data.type == StreamType::audio && data.direction
64 && data.direction == preferredStreamDirection) {
65 subject->attach(mAS.get()); // the image you receive from others on the call
66 oss << "got received audio attached" << std::endl;
67 attached_ = '1';
68 }
69
70 Plog::log(Plog::LogPriority::INFO, TAG, oss.str());
71}
72
73std::map<std::string, std::string>
agsantos82678f32020-12-09 15:03:24 -050074FilterMediaHandler::getCallMediaHandlerDetails()
agsantosc9181b42020-11-26 12:03:04 -050075{
76 return {{"name", NAME},
agsantosd00bf412021-01-26 13:43:33 -050077 {"iconPath", datapath_ + sep + "icon.svg"},
agsantosc9181b42020-11-26 12:03:04 -050078 {"pluginId", id()},
79 {"attached", attached_},
80 {"dataType", "0"}};
81}
82
83void
agsantos82678f32020-12-09 15:03:24 -050084FilterMediaHandler::setPreferenceAttribute(const std::string& key, const std::string& value)
agsantosc9181b42020-11-26 12:03:04 -050085{
agsantos82678f32020-12-09 15:03:24 -050086 auto it = preferences_.find(key);
87 if (it != preferences_.end() && it->second != value) {
agsantosc9181b42020-11-26 12:03:04 -050088 it->second = value;
89 if (key == "irFile")
90 mAS->setIRFile(value);
91 }
92}
93
94bool
agsantos82678f32020-12-09 15:03:24 -050095FilterMediaHandler::preferenceMapHasKey(const std::string& key)
agsantosc9181b42020-11-26 12:03:04 -050096{
97 if (key == "irFile")
98 return true;
99 return false;
100}
101
102void
agsantos82678f32020-12-09 15:03:24 -0500103FilterMediaHandler::detach()
agsantosc9181b42020-11-26 12:03:04 -0500104{
105 attached_ = '0';
106 mAS->detach();
107}
108
agsantos82678f32020-12-09 15:03:24 -0500109FilterMediaHandler::~FilterMediaHandler()
agsantosc9181b42020-11-26 12:03:04 -0500110{
111 std::ostringstream oss;
agsantos82678f32020-12-09 15:03:24 -0500112 oss << " ~FilterMediaHandler from AudioFilter Plugin" << std::endl;
agsantosc9181b42020-11-26 12:03:04 -0500113 Plog::log(Plog::LogPriority::INFO, TAG, oss.str());
114 detach();
115}
116} // namespace jami