blob: a55a9642ce30a5e3f78e39101837f0222fede9c6 [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_);
20 mVS = std::make_shared<GENERICVideoSubscriber>(datapath_);
21}
22
23void
24GENERICMediaHandler::notifyAVFrameSubject(const StreamData& data, jami::avSubjectPtr subject)
25{
26 Plog::log(Plog::LogPriority::INFO, TAG, "IN AVFRAMESUBJECT");
27 std::ostringstream oss;
28 std::string direction = data.direction ? "Receive" : "Preview";
29 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;
33 if (data.type == StreamType::video && !data.direction
34 && data.direction == preferredStreamDirection) {
35 subject->attach(mVS.get()); // your image
36 oss << "got my sent image attached" << std::endl;
agsantosc9181b42020-11-26 12:03:04 -050037 attached_ = "1";
agsantos1e7736c2020-10-28 14:39:13 -040038 } else if (data.type == StreamType::video && data.direction
39 && data.direction == preferredStreamDirection) {
40 subject->attach(mVS.get()); // the image you receive from others on the call
41 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},
52 {"iconPath", datapath_ + sep + "icon.png"},
53 {"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{
61 auto it = ppm_.find(key);
62 if (it != ppm_.end() && it->second != value) {
63 it->second = value;----------------
64 if (key == "PREFERENCE1") {
65 // use preference
66 return;
67 }----------------
68 }
69}
70
71bool
72GENERICMediaHandler::preferenceMapHasKey(const std::string& key)
agsantosc9181b42020-11-26 12:03:04 -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";
agsantos1e7736c2020-10-28 14:39:13 -040082 mVS->detach();
83}
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