blob: 156bf692669636b029f2703be75e4ddec624586b [file] [log] [blame]
agsantos5aa39652020-08-11 18:18:04 -04001/**
Sébastien Blincb783e32021-02-12 11:34:10 -05002 * Copyright (C) 2020-2021 Savoir-faire Linux Inc.
agsantos5aa39652020-08-11 18:18:04 -04003 *
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>
agsantosc9181b42020-11-26 12:03:04 -050025
agsantos5aa39652020-08-11 18:18:04 -040026#include <plugin/jamiplugin.h>
27#include "pluginMediaHandler.h"
28
Aline Gondim Santos506a6932022-08-25 18:42:32 -030029#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
agsantos5aa39652020-08-11 18:18:04 -040037#ifdef WIN32
agsantosac1940d2020-09-17 10:18:40 -040038#define EXPORT_PLUGIN __declspec(dllexport)
agsantos5aa39652020-08-11 18:18:04 -040039#else
40#define EXPORT_PLUGIN
41#endif
42
agsantosdd6a62a2021-03-29 17:13:27 -040043#define GreenScreen_VERSION_MAJOR 2
agsantos5aa39652020-08-11 18:18:04 -040044#define GreenScreen_VERSION_MINOR 0
agsantosdd6a62a2021-03-29 17:13:27 -040045#define GreenScreen_VERSION_PATCH 0
agsantos5aa39652020-08-11 18:18:04 -040046
agsantosac1940d2020-09-17 10:18:40 -040047extern "C" {
48void
49pluginExit(void)
50{}
agsantos5aa39652020-08-11 18:18:04 -040051
52EXPORT_PLUGIN JAMI_PluginExitFunc
53JAMI_dynPluginInit(const JAMI_PluginAPI* api)
54{
agsantosdd6a62a2021-03-29 17:13:27 -040055 std::cout << "*******************" << std::endl;
Aline Gondim Santos506a6932022-08-25 18:42:32 -030056 std::cout << "** GreenScreen **" << std::endl;
agsantosdd6a62a2021-03-29 17:13:27 -040057 std::cout << "*******************" << std::endl << std::endl;
agsantos4bb4bc52021-03-08 14:21:45 -050058 std::cout << "Version " << GreenScreen_VERSION_MAJOR << "." << GreenScreen_VERSION_MINOR << "."
agsantosc9181b42020-11-26 12:03:04 -050059 << GreenScreen_VERSION_PATCH << std::endl;
agsantos5aa39652020-08-11 18:18:04 -040060
61 // If invokeService doesn't return an error
agsantosac1940d2020-09-17 10:18:40 -040062 if (api) {
agsantos82678f32020-12-09 15:03:24 -050063 std::map<std::string, std::string> preferences;
64 api->invokeService(api, "getPluginPreferences", &preferences);
agsantos5aa39652020-08-11 18:18:04 -040065 std::string dataPath;
66 api->invokeService(api, "getPluginDataPath", &dataPath);
agsantos4bb4bc52021-03-08 14:21:45 -050067 auto fmp = std::make_unique<jami::PluginMediaHandler>(std::move(preferences),
68 std::move(dataPath));
agsantos5aa39652020-08-11 18:18:04 -040069
agsantosac1940d2020-09-17 10:18:40 -040070 if (!api->manageComponent(api, "CallMediaHandlerManager", fmp.release())) {
agsantos5aa39652020-08-11 18:18:04 -040071 return pluginExit;
72 }
73 }
74 return nullptr;
75}
76}
Aline Gondim Santos506a6932022-08-25 18:42:32 -030077
78#ifdef __DEBUG__
79
80int
81main ()
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