blob: 2a48e7aa1704ec29497231216d610394c9463bc1 [file] [log] [blame]
/**
* Copyright (C) 2020 Savoir-faire Linux Inc.
*
* Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "filterMediaHandler.h"
#include "pluglog.h"
const char sep = separator();
const std::string TAG = "filter";
#define NAME "filter"
namespace jami {
filterMediaHandler::filterMediaHandler(std::map<std::string, std::string>&& ppm,
std::string&& datapath)
: datapath_ {datapath}
, ppm_ {ppm}
{
setId(datapath_);
auto it = ppm_.find("irFile");
if (it != ppm_.end())
mAS = std::make_shared<FilterAudioSubscriber>(datapath_, it->second);
}
void
filterMediaHandler::notifyAVFrameSubject(const StreamData& data, jami::avSubjectPtr subject)
{
if (!mAS)
return;
std::ostringstream oss;
std::string direction = data.direction ? "Receive" : "Preview";
oss << "NEW SUBJECT: [" << data.id << "," << direction << "]" << std::endl;
bool preferredStreamDirection = false; // false for output; true for input
auto it = ppm_.find("streamlist");
if (it != ppm_.end()) {
preferredStreamDirection = it->second == "in";
}
oss << "preferredStreamDirection " << preferredStreamDirection << std::endl;
if (data.type == StreamType::audio && !data.direction
&& data.direction == preferredStreamDirection) {
subject->attach(mAS.get()); // your image
oss << "got my sent audio attached" << std::endl;
attached_ = '1';
} else if (data.type == StreamType::audio && data.direction
&& data.direction == preferredStreamDirection) {
subject->attach(mAS.get()); // the image you receive from others on the call
oss << "got received audio attached" << std::endl;
attached_ = '1';
}
Plog::log(Plog::LogPriority::INFO, TAG, oss.str());
}
std::map<std::string, std::string>
filterMediaHandler::getCallMediaHandlerDetails()
{
return {{"name", NAME},
{"iconPath", datapath_ + sep + "icon.png"},
{"pluginId", id()},
{"attached", attached_},
{"dataType", "0"}};
}
void
filterMediaHandler::setPreferenceAttribute(const std::string& key, const std::string& value)
{
auto it = ppm_.find(key);
if (it != ppm_.end() && it->second != value) {
it->second = value;
if (key == "irFile")
mAS->setIRFile(value);
}
}
bool
filterMediaHandler::preferenceMapHasKey(const std::string& key)
{
if (key == "irFile")
return true;
return false;
}
void
filterMediaHandler::detach()
{
attached_ = '0';
mAS->detach();
}
filterMediaHandler::~filterMediaHandler()
{
std::ostringstream oss;
oss << " ~filterMediaHandler from AudioFilter Plugin" << std::endl;
Plog::log(Plog::LogPriority::INFO, TAG, oss.str());
detach();
}
} // namespace jami