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_); |
agsantos | f499e07 | 2020-11-26 16:30:57 -0500 | [diff] [blame] | 20 | mediaSubscriber_ = std::make_shared<GENERICDATATYPESubscriber>(datapath_); |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 21 | } |
| 22 | |
| 23 | void |
| 24 | GENERICMediaHandler::notifyAVFrameSubject(const StreamData& data, jami::avSubjectPtr subject) |
| 25 | { |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 26 | 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; |
agsantos | f499e07 | 2020-11-26 16:30:57 -0500 | [diff] [blame] | 32 | if (data.type == StreamType::DataType && !data.direction |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 33 | && data.direction == preferredStreamDirection) { |
agsantos | f499e07 | 2020-11-26 16:30:57 -0500 | [diff] [blame] | 34 | subject->attach(mediaSubscriber_.get()); // your image |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 35 | oss << "got my sent image attached" << std::endl; |
agsantos | c9181b4 | 2020-11-26 12:03:04 -0500 | [diff] [blame] | 36 | attached_ = "1"; |
agsantos | f499e07 | 2020-11-26 16:30:57 -0500 | [diff] [blame] | 37 | } else if (data.type == StreamType::DataType && data.direction |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 38 | && data.direction == preferredStreamDirection) { |
agsantos | f499e07 | 2020-11-26 16:30:57 -0500 | [diff] [blame] | 39 | subject->attach(mediaSubscriber_.get()); // the image you receive from others on the call |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 40 | oss << "got received image attached" << std::endl; |
agsantos | c9181b4 | 2020-11-26 12:03:04 -0500 | [diff] [blame] | 41 | attached_ = "1"; |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | Plog::log(Plog::LogPriority::INFO, TAG, oss.str()); |
| 45 | } |
| 46 | |
| 47 | std::map<std::string, std::string> |
| 48 | GENERICMediaHandler::getCallMediaHandlerDetails() |
| 49 | { |
agsantos | c9181b4 | 2020-11-26 12:03:04 -0500 | [diff] [blame] | 50 | return {{"name", NAME}, |
| 51 | {"iconPath", datapath_ + sep + "icon.png"}, |
| 52 | {"pluginId", id()}, |
| 53 | {"attached", attached_}, |
| 54 | {"dataType", "1"}}; |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | void |
| 58 | GENERICMediaHandler::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 | |
| 70 | bool |
| 71 | GENERICMediaHandler::preferenceMapHasKey(const std::string& key) |
agsantos | c9181b4 | 2020-11-26 12:03:04 -0500 | [diff] [blame] | 72 | { |
| 73 | ----------------if (key == "PREFERENCE2") { return true; } |
| 74 | ----------------return false; |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | void |
| 78 | GENERICMediaHandler::detach() |
| 79 | { |
agsantos | c9181b4 | 2020-11-26 12:03:04 -0500 | [diff] [blame] | 80 | attached_ = "0"; |
agsantos | f499e07 | 2020-11-26 16:30:57 -0500 | [diff] [blame] | 81 | mediaSubscriber_->detach(); |
agsantos | 1e7736c | 2020-10-28 14:39:13 -0400 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | GENERICMediaHandler::~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 |