agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 1 | /** |
Sébastien Blin | cb783e3 | 2021-02-12 11:34:10 -0500 | [diff] [blame] | 2 | * Copyright (C) 2020-2021 Savoir-faire Linux Inc. |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 3 | * |
| 4 | * Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | */ |
| 20 | |
| 21 | #include <iostream> |
| 22 | #include <string.h> |
| 23 | #include <thread> |
| 24 | #include <memory> |
agsantos | c9181b4 | 2020-11-26 12:03:04 -0500 | [diff] [blame] | 25 | |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 26 | #include <plugin/jamiplugin.h> |
| 27 | #include "pluginMediaHandler.h" |
| 28 | |
Aline Gondim Santos | 506a693 | 2022-08-25 18:42:32 -0300 | [diff] [blame] | 29 | #ifdef __DEBUG__ |
| 30 | #include <assert.h> |
| 31 | #include <yaml-cpp/yaml.h> |
| 32 | #include <fstream> |
| 33 | #include <AVFrameIO.h> |
| 34 | #include <common.h> |
| 35 | #endif |
| 36 | |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 37 | #ifdef WIN32 |
agsantos | ac1940d | 2020-09-17 10:18:40 -0400 | [diff] [blame] | 38 | #define EXPORT_PLUGIN __declspec(dllexport) |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 39 | #else |
| 40 | #define EXPORT_PLUGIN |
| 41 | #endif |
| 42 | |
agsantos | dd6a62a | 2021-03-29 17:13:27 -0400 | [diff] [blame] | 43 | #define GreenScreen_VERSION_MAJOR 2 |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 44 | #define GreenScreen_VERSION_MINOR 0 |
agsantos | dd6a62a | 2021-03-29 17:13:27 -0400 | [diff] [blame] | 45 | #define GreenScreen_VERSION_PATCH 0 |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 46 | |
agsantos | ac1940d | 2020-09-17 10:18:40 -0400 | [diff] [blame] | 47 | extern "C" { |
| 48 | void |
| 49 | pluginExit(void) |
| 50 | {} |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 51 | |
| 52 | EXPORT_PLUGIN JAMI_PluginExitFunc |
| 53 | JAMI_dynPluginInit(const JAMI_PluginAPI* api) |
| 54 | { |
agsantos | dd6a62a | 2021-03-29 17:13:27 -0400 | [diff] [blame] | 55 | std::cout << "*******************" << std::endl; |
Aline Gondim Santos | 506a693 | 2022-08-25 18:42:32 -0300 | [diff] [blame] | 56 | std::cout << "** GreenScreen **" << std::endl; |
agsantos | dd6a62a | 2021-03-29 17:13:27 -0400 | [diff] [blame] | 57 | std::cout << "*******************" << std::endl << std::endl; |
agsantos | 4bb4bc5 | 2021-03-08 14:21:45 -0500 | [diff] [blame] | 58 | std::cout << "Version " << GreenScreen_VERSION_MAJOR << "." << GreenScreen_VERSION_MINOR << "." |
agsantos | c9181b4 | 2020-11-26 12:03:04 -0500 | [diff] [blame] | 59 | << GreenScreen_VERSION_PATCH << std::endl; |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 60 | |
| 61 | // If invokeService doesn't return an error |
agsantos | ac1940d | 2020-09-17 10:18:40 -0400 | [diff] [blame] | 62 | if (api) { |
agsantos | 82678f3 | 2020-12-09 15:03:24 -0500 | [diff] [blame] | 63 | std::map<std::string, std::string> preferences; |
| 64 | api->invokeService(api, "getPluginPreferences", &preferences); |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 65 | std::string dataPath; |
| 66 | api->invokeService(api, "getPluginDataPath", &dataPath); |
agsantos | 4bb4bc5 | 2021-03-08 14:21:45 -0500 | [diff] [blame] | 67 | auto fmp = std::make_unique<jami::PluginMediaHandler>(std::move(preferences), |
| 68 | std::move(dataPath)); |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 69 | |
agsantos | ac1940d | 2020-09-17 10:18:40 -0400 | [diff] [blame] | 70 | if (!api->manageComponent(api, "CallMediaHandlerManager", fmp.release())) { |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 71 | return pluginExit; |
| 72 | } |
| 73 | } |
| 74 | return nullptr; |
| 75 | } |
| 76 | } |
Aline Gondim Santos | 506a693 | 2022-08-25 18:42:32 -0300 | [diff] [blame] | 77 | |
| 78 | #ifdef __DEBUG__ |
| 79 | |
| 80 | int |
| 81 | main () |
| 82 | { |
| 83 | std::cout << "*********************************" << std::endl; |
| 84 | std::cout << "** GreenScreen Debug Version **" << std::endl; |
| 85 | std::cout << "*********************************" << std::endl; |
| 86 | std::cout << "Version " << GreenScreen_VERSION_MAJOR << "." << GreenScreen_VERSION_MINOR << "." |
| 87 | << GreenScreen_VERSION_PATCH << std::endl << std::endl; |
| 88 | |
| 89 | std::ifstream file; |
| 90 | file_utils::openStream(file, "testPreferences.yml"); |
| 91 | |
| 92 | assert(file.is_open()); |
| 93 | YAML::Node node = YAML::Load(file); |
| 94 | |
| 95 | assert(node.IsMap()); |
| 96 | std::map<std::string, std::string> preferences; |
| 97 | for (const auto& kv : node) { |
| 98 | preferences[kv.first.as<std::string>()] = kv.second.as<std::string>(); |
| 99 | std::cout << "Key: " << kv.first.as<std::string>() << "; Value: " << kv.second.as<std::string>() << std::endl; |
| 100 | } |
| 101 | |
| 102 | #ifdef _WIN32 |
| 103 | std::string dataPath = "../data"; |
| 104 | #else |
| 105 | std::string dataPath = "data"; |
| 106 | #endif |
| 107 | preferences["background"] = dataPath + separator() + preferences["background"]; |
| 108 | |
| 109 | auto fmp = std::make_unique<jami::PluginMediaHandler>(std::move(preferences), std::move(dataPath)); |
| 110 | |
| 111 | auto subject = std::make_shared<jami::PublishObservable<AVFrame*>>(); |
| 112 | |
| 113 | // Valid Read frames from sample file and send to subscriber |
| 114 | std::cout << "Test 1" << std::endl << "Sent video: " << preferences["sample"] << std::endl; |
| 115 | fmp->notifyAVFrameSubject(StreamData("testCall", false, StreamType::video, "origin", "destiny"), subject); |
| 116 | av_utils::readAndNotifyAVFrame(preferences["sample"], subject.get(), preferences["output"], AVMEDIA_TYPE_VIDEO); |
| 117 | |
| 118 | return 0; |
| 119 | } |
| 120 | #endif |