agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 1 | HEADER |
| 2 | |
| 3 | #include "GENERICMediaHandler.h" |
agsantos | c9181b4 | 2020-11-26 12:03:04 -0500 | [diff] [blame^] | 4 | |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 5 | #include "pluglog.h" |
agsantos | c9181b4 | 2020-11-26 12:03:04 -0500 | [diff] [blame^] | 6 | |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 7 | const char sep = separator(); |
| 8 | const std::string TAG = "GENERIC"; |
| 9 | |
| 10 | #define NAME "GENERIC" |
| 11 | |
| 12 | namespace jami { |
| 13 | |
| 14 | GENERICMediaHandler::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 | |
| 23 | void |
| 24 | GENERICMediaHandler::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; |
agsantos | c9181b4 | 2020-11-26 12:03:04 -0500 | [diff] [blame^] | 37 | attached_ = "1"; |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 38 | } 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; |
agsantos | c9181b4 | 2020-11-26 12:03:04 -0500 | [diff] [blame^] | 42 | attached_ = "1"; |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | Plog::log(Plog::LogPriority::INFO, TAG, oss.str()); |
| 46 | } |
| 47 | |
| 48 | std::map<std::string, std::string> |
| 49 | GENERICMediaHandler::getCallMediaHandlerDetails() |
| 50 | { |
agsantos | c9181b4 | 2020-11-26 12:03:04 -0500 | [diff] [blame^] | 51 | return {{"name", NAME}, |
| 52 | {"iconPath", datapath_ + sep + "icon.png"}, |
| 53 | {"pluginId", id()}, |
| 54 | {"attached", attached_}, |
| 55 | {"dataType", "1"}}; |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | void |
| 59 | GENERICMediaHandler::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 | |
| 71 | bool |
| 72 | GENERICMediaHandler::preferenceMapHasKey(const std::string& key) |
agsantos | c9181b4 | 2020-11-26 12:03:04 -0500 | [diff] [blame^] | 73 | { |
| 74 | ----------------if (key == "PREFERENCE2") { return true; } |
| 75 | ----------------return false; |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | void |
| 79 | GENERICMediaHandler::detach() |
| 80 | { |
agsantos | c9181b4 | 2020-11-26 12:03:04 -0500 | [diff] [blame^] | 81 | attached_ = "0"; |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 82 | mVS->detach(); |
| 83 | } |
| 84 | |
| 85 | GENERICMediaHandler::~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 |