blob: 109ec71d05bf5d632c22a56ee38058345deb6f79 [file] [log] [blame]
agsantos1e7736c2020-10-28 14:39:13 -04001HEADER
2
3#include "GENERICMediaHandler.h"
agsantosc9181b42020-11-26 12:03:04 -05004
agsantos1e7736c2020-10-28 14:39:13 -04005#include "pluglog.h"
agsantos82678f32020-12-09 15:03:24 -05006#include <string_view>
agsantosc9181b42020-11-26 12:03:04 -05007
agsantos1e7736c2020-10-28 14:39:13 -04008const char sep = separator();
9const std::string TAG = "GENERIC";
10
11#define NAME "GENERIC"
12
13namespace jami {
14
agsantos82678f32020-12-09 15:03:24 -050015GENERICMediaHandler::GENERICMediaHandler(std::map<std::string, std::string>&& preferences,
agsantos1e7736c2020-10-28 14:39:13 -040016 std::string&& datapath)
17 : datapath_ {datapath}
agsantos82678f32020-12-09 15:03:24 -050018 , preferences_ {preferences}
agsantos1e7736c2020-10-28 14:39:13 -040019{
20 setId(datapath_);
agsantosf499e072020-11-26 16:30:57 -050021 mediaSubscriber_ = std::make_shared<GENERICDATATYPESubscriber>(datapath_);
agsantos1e7736c2020-10-28 14:39:13 -040022}
23
24void
25GENERICMediaHandler::notifyAVFrameSubject(const StreamData& data, jami::avSubjectPtr subject)
26{
agsantos1e7736c2020-10-28 14:39:13 -040027 std::ostringstream oss;
agsantos82678f32020-12-09 15:03:24 -050028 std::string_view direction = data.direction ? "Receive" : "Preview";
agsantos1e7736c2020-10-28 14:39:13 -040029 oss << "NEW SUBJECT: [" << data.id << "," << direction << "]" << std::endl;
30
31 bool preferredStreamDirection = false; // false for output; true for input
32 oss << "preferredStreamDirection " << preferredStreamDirection << std::endl;
agsantosf499e072020-11-26 16:30:57 -050033 if (data.type == StreamType::DataType && !data.direction
agsantos1e7736c2020-10-28 14:39:13 -040034 && data.direction == preferredStreamDirection) {
agsantosf499e072020-11-26 16:30:57 -050035 subject->attach(mediaSubscriber_.get()); // your image
agsantos1e7736c2020-10-28 14:39:13 -040036 oss << "got my sent image attached" << std::endl;
agsantosc9181b42020-11-26 12:03:04 -050037 attached_ = "1";
agsantosf499e072020-11-26 16:30:57 -050038 } else if (data.type == StreamType::DataType && data.direction
agsantos1e7736c2020-10-28 14:39:13 -040039 && data.direction == preferredStreamDirection) {
agsantosf499e072020-11-26 16:30:57 -050040 subject->attach(mediaSubscriber_.get()); // the image you receive from others on the call
agsantos1e7736c2020-10-28 14:39:13 -040041 oss << "got received image attached" << std::endl;
agsantosc9181b42020-11-26 12:03:04 -050042 attached_ = "1";
agsantos1e7736c2020-10-28 14:39:13 -040043 }
44
45 Plog::log(Plog::LogPriority::INFO, TAG, oss.str());
46}
47
48std::map<std::string, std::string>
49GENERICMediaHandler::getCallMediaHandlerDetails()
50{
agsantosc9181b42020-11-26 12:03:04 -050051 return {{"name", NAME},
agsantosd00bf412021-01-26 13:43:33 -050052 {"iconPath", datapath_ + sep + "icon.svg"},
agsantosc9181b42020-11-26 12:03:04 -050053 {"pluginId", id()},
54 {"attached", attached_},
55 {"dataType", "1"}};
agsantos1e7736c2020-10-28 14:39:13 -040056}
57
58void
59GENERICMediaHandler::setPreferenceAttribute(const std::string& key, const std::string& value)
60{
agsantos82678f32020-12-09 15:03:24 -050061 auto it = preferences_.find(key);
62 if (it != preferences_.end() && it->second != value) {
agsantos1e7736c2020-10-28 14:39:13 -040063 it->second = value;----------------
64 if (key == "PREFERENCE1") {
65 // use preference
66 return;
67 }----------------
68 }
69}
70
71bool
72GENERICMediaHandler::preferenceMapHasKey(const std::string& key)
agsantos82678f32020-12-09 15:03:24 -050073{----------------
74 if (key == "PREFERENCE2") { return true; }----------------
75 return false;
agsantos1e7736c2020-10-28 14:39:13 -040076}
77
78void
79GENERICMediaHandler::detach()
80{
agsantosc9181b42020-11-26 12:03:04 -050081 attached_ = "0";
agsantosf499e072020-11-26 16:30:57 -050082 mediaSubscriber_->detach();
agsantos1e7736c2020-10-28 14:39:13 -040083}
84
85GENERICMediaHandler::~GENERICMediaHandler()
86{
87 std::ostringstream oss;
88 oss << " ~GENERICMediaHandler from PLUGINNAME Plugin" << std::endl;
89 Plog::log(Plog::LogPriority::INFO, TAG, oss.str());
90 detach();
91}
92} // namespace jami