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 | 82678f3 | 2020-12-09 15:03:24 -0500 | [diff] [blame] | 6 | #include <string_view> |
agsantos | c9181b4 | 2020-11-26 12:03:04 -0500 | [diff] [blame] | 7 | |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 8 | const char sep = separator(); |
| 9 | const std::string TAG = "GENERIC"; |
| 10 | |
| 11 | #define NAME "GENERIC" |
| 12 | |
| 13 | namespace jami { |
| 14 | |
agsantos | 82678f3 | 2020-12-09 15:03:24 -0500 | [diff] [blame] | 15 | GENERICMediaHandler::GENERICMediaHandler(std::map<std::string, std::string>&& preferences, |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 16 | std::string&& datapath) |
| 17 | : datapath_ {datapath} |
agsantos | 82678f3 | 2020-12-09 15:03:24 -0500 | [diff] [blame] | 18 | , preferences_ {preferences} |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 19 | { |
| 20 | setId(datapath_); |
agsantos | f499e07 | 2020-11-26 16:30:57 -0500 | [diff] [blame] | 21 | mediaSubscriber_ = std::make_shared<GENERICDATATYPESubscriber>(datapath_); |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 22 | } |
| 23 | |
| 24 | void |
| 25 | GENERICMediaHandler::notifyAVFrameSubject(const StreamData& data, jami::avSubjectPtr subject) |
| 26 | { |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 27 | std::ostringstream oss; |
agsantos | 82678f3 | 2020-12-09 15:03:24 -0500 | [diff] [blame] | 28 | std::string_view direction = data.direction ? "Receive" : "Preview"; |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 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; |
agsantos | f499e07 | 2020-11-26 16:30:57 -0500 | [diff] [blame] | 33 | if (data.type == StreamType::DataType && !data.direction |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 34 | && data.direction == preferredStreamDirection) { |
agsantos | f499e07 | 2020-11-26 16:30:57 -0500 | [diff] [blame] | 35 | subject->attach(mediaSubscriber_.get()); // your image |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 36 | oss << "got my sent image attached" << std::endl; |
agsantos | c9181b4 | 2020-11-26 12:03:04 -0500 | [diff] [blame] | 37 | attached_ = "1"; |
agsantos | f499e07 | 2020-11-26 16:30:57 -0500 | [diff] [blame] | 38 | } else if (data.type == StreamType::DataType && data.direction |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 39 | && data.direction == preferredStreamDirection) { |
agsantos | f499e07 | 2020-11-26 16:30:57 -0500 | [diff] [blame] | 40 | subject->attach(mediaSubscriber_.get()); // the image you receive from others on the call |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 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}, |
agsantos | d00bf41 | 2021-01-26 13:43:33 -0500 | [diff] [blame^] | 52 | {"iconPath", datapath_ + sep + "icon.svg"}, |
agsantos | c9181b4 | 2020-11-26 12:03:04 -0500 | [diff] [blame] | 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 | { |
agsantos | 82678f3 | 2020-12-09 15:03:24 -0500 | [diff] [blame] | 61 | auto it = preferences_.find(key); |
| 62 | if (it != preferences_.end() && it->second != value) { |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 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 | 82678f3 | 2020-12-09 15:03:24 -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 | f499e07 | 2020-11-26 16:30:57 -0500 | [diff] [blame] | 82 | mediaSubscriber_->detach(); |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 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 |