blob: 32549257981c7f3a31111d5285dfa6c1e1fdda20 [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"
agsantosc9181b42020-11-26 12:03:04 -05006
agsantos1e7736c2020-10-28 14:39:13 -04007const char sep = separator();
8const std::string TAG = "GENERIC";
9
10#define NAME "GENERIC"
11
12namespace jami {
13
14GENERICMediaHandler::GENERICMediaHandler(std::map<std::string, std::string>&& ppm,
15 std::string&& datapath)
16 : datapath_ {datapath}
17 , ppm_ {ppm}
18{
19 setId(datapath_);
agsantosf499e072020-11-26 16:30:57 -050020 mediaSubscriber_ = std::make_shared<GENERICDATATYPESubscriber>(datapath_);
agsantos1e7736c2020-10-28 14:39:13 -040021}
22
23void
24GENERICMediaHandler::notifyAVFrameSubject(const StreamData& data, jami::avSubjectPtr subject)
25{
agsantos1e7736c2020-10-28 14:39:13 -040026 std::ostringstream oss;
27 std::string direction = data.direction ? "Receive" : "Preview";
28 oss << "NEW SUBJECT: [" << data.id << "," << direction << "]" << std::endl;
29
30 bool preferredStreamDirection = false; // false for output; true for input
31 oss << "preferredStreamDirection " << preferredStreamDirection << std::endl;
agsantosf499e072020-11-26 16:30:57 -050032 if (data.type == StreamType::DataType && !data.direction
agsantos1e7736c2020-10-28 14:39:13 -040033 && data.direction == preferredStreamDirection) {
agsantosf499e072020-11-26 16:30:57 -050034 subject->attach(mediaSubscriber_.get()); // your image
agsantos1e7736c2020-10-28 14:39:13 -040035 oss << "got my sent image attached" << std::endl;
agsantosc9181b42020-11-26 12:03:04 -050036 attached_ = "1";
agsantosf499e072020-11-26 16:30:57 -050037 } else if (data.type == StreamType::DataType && data.direction
agsantos1e7736c2020-10-28 14:39:13 -040038 && data.direction == preferredStreamDirection) {
agsantosf499e072020-11-26 16:30:57 -050039 subject->attach(mediaSubscriber_.get()); // the image you receive from others on the call
agsantos1e7736c2020-10-28 14:39:13 -040040 oss << "got received image attached" << std::endl;
agsantosc9181b42020-11-26 12:03:04 -050041 attached_ = "1";
agsantos1e7736c2020-10-28 14:39:13 -040042 }
43
44 Plog::log(Plog::LogPriority::INFO, TAG, oss.str());
45}
46
47std::map<std::string, std::string>
48GENERICMediaHandler::getCallMediaHandlerDetails()
49{
agsantosc9181b42020-11-26 12:03:04 -050050 return {{"name", NAME},
51 {"iconPath", datapath_ + sep + "icon.png"},
52 {"pluginId", id()},
53 {"attached", attached_},
54 {"dataType", "1"}};
agsantos1e7736c2020-10-28 14:39:13 -040055}
56
57void
58GENERICMediaHandler::setPreferenceAttribute(const std::string& key, const std::string& value)
59{
60 auto it = ppm_.find(key);
61 if (it != ppm_.end() && it->second != value) {
62 it->second = value;----------------
63 if (key == "PREFERENCE1") {
64 // use preference
65 return;
66 }----------------
67 }
68}
69
70bool
71GENERICMediaHandler::preferenceMapHasKey(const std::string& key)
agsantosc9181b42020-11-26 12:03:04 -050072{
73 ----------------if (key == "PREFERENCE2") { return true; }
74 ----------------return false;
agsantos1e7736c2020-10-28 14:39:13 -040075}
76
77void
78GENERICMediaHandler::detach()
79{
agsantosc9181b42020-11-26 12:03:04 -050080 attached_ = "0";
agsantosf499e072020-11-26 16:30:57 -050081 mediaSubscriber_->detach();
agsantos1e7736c2020-10-28 14:39:13 -040082}
83
84GENERICMediaHandler::~GENERICMediaHandler()
85{
86 std::ostringstream oss;
87 oss << " ~GENERICMediaHandler from PLUGINNAME Plugin" << std::endl;
88 Plog::log(Plog::LogPriority::INFO, TAG, oss.str());
89 detach();
90}
91} // namespace jami