Aline Gondim Santos | 329f862 | 2022-11-08 08:04:22 -0300 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (C) 2022 Savoir-faire Linux Inc. |
| 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> |
| 25 | #include <plugin/jamiplugin.h> |
| 26 | |
| 27 | #include "TranscriptMediaHandler.h" |
| 28 | #include "PluginPreferenceHandler.h" |
| 29 | |
| 30 | #ifdef __DEBUG__ |
| 31 | #include <common.h> |
| 32 | #include <assert.h> |
| 33 | #include <yaml-cpp/yaml.h> |
| 34 | #include <fstream> |
| 35 | #include <AVFrameIO.h> |
| 36 | #endif |
| 37 | |
| 38 | #ifdef WIN32 |
| 39 | #define EXPORT_PLUGIN __declspec(dllexport) |
| 40 | #else |
| 41 | #define EXPORT_PLUGIN |
| 42 | #endif |
| 43 | |
| 44 | #define WhisperTranscript_VERSION_MAJOR 0 |
| 45 | #define WhisperTranscript_VERSION_MINOR 0 |
| 46 | #define WhisperTranscript_VERSION_PATCH 0 |
| 47 | |
| 48 | extern "C" { |
| 49 | |
| 50 | void |
| 51 | pluginExit(void) |
| 52 | {} |
| 53 | |
| 54 | EXPORT_PLUGIN JAMI_PluginExitFunc |
| 55 | JAMI_dynPluginInit(const JAMI_PluginAPI* api) |
| 56 | { |
| 57 | std::cout << "**************************" << std::endl; |
| 58 | std::cout << "** WhisperTranscript **" << std::endl; |
| 59 | std::cout << "**************************" << std::endl << std::endl; |
| 60 | std::cout << "Version " << WhisperTranscript_VERSION_MAJOR << "." << WhisperTranscript_VERSION_MINOR << "." |
| 61 | << WhisperTranscript_VERSION_PATCH << std::endl; |
| 62 | |
| 63 | // If invokeService doesn't return an error |
| 64 | if (api) { |
| 65 | if (api->version.api < JAMI_PLUGIN_API_VERSION) |
| 66 | return nullptr; |
| 67 | |
| 68 | std::map<std::string, std::map<std::string, std::string>> preferences; |
| 69 | api->invokeService(api, "getPluginAccPreferences", &preferences); |
| 70 | std::string dataPath; |
| 71 | api->invokeService(api, "getPluginDataPath", &dataPath); |
| 72 | |
| 73 | auto fmpPluginPreferenceHandler |
| 74 | = std::make_unique<jami::PluginPreferenceHandler>(api, |
| 75 | std::move(preferences), |
| 76 | dataPath); |
| 77 | |
| 78 | auto fmpTranscriptMediaHandler |
| 79 | = std::make_unique<jami::TranscriptMediaHandler>(std::move(dataPath), |
| 80 | fmpPluginPreferenceHandler.get()); |
| 81 | |
| 82 | fmpPluginPreferenceHandler->setTranscriptHandler(fmpTranscriptMediaHandler.get()); |
| 83 | |
| 84 | if (api->manageComponent(api, |
| 85 | "CallMediaHandlerManager", |
| 86 | fmpTranscriptMediaHandler.release())) { |
| 87 | return nullptr; |
| 88 | } |
| 89 | if (api->manageComponent(api, |
| 90 | "PreferenceHandlerManager", |
| 91 | fmpPluginPreferenceHandler.release())) { |
| 92 | return nullptr; |
| 93 | } |
| 94 | } |
| 95 | return pluginExit; |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | #ifdef __DEBUG__ |
| 100 | |
| 101 | int |
| 102 | main () |
| 103 | { |
| 104 | std::cout << "***************************************" << std::endl; |
| 105 | std::cout << "** WhisperTranscript Debug Version **" << std::endl; |
| 106 | std::cout << "***************************************" << std::endl; |
| 107 | std::cout << "Version " << WhisperTranscript_VERSION_MAJOR << "." << WhisperTranscript_VERSION_MINOR << "." |
| 108 | << WhisperTranscript_VERSION_PATCH << std::endl; |
| 109 | |
| 110 | std::ifstream file; |
| 111 | file_utils::openStream(file, "testPreferences.yml"); |
| 112 | |
| 113 | assert(file.is_open()); |
| 114 | YAML::Node node = YAML::Load(file); |
| 115 | |
| 116 | assert(node.IsMap()); |
| 117 | std::map<std::string, std::map<std::string, std::string>> preferences; |
| 118 | preferences["default"] = {}; |
| 119 | for (const auto& kv : node) { |
| 120 | preferences["default"][kv.first.as<std::string>()] = kv.second.as<std::string>(); |
| 121 | std::cout << "Key: " << kv.first.as<std::string>() << "; Value: " << kv.second.as<std::string>() << std::endl; |
| 122 | } |
| 123 | |
| 124 | #ifdef _WIN32 |
| 125 | std::string dataPath = "../data"; |
| 126 | #else |
| 127 | std::string dataPath = "data"; |
| 128 | #endif |
| 129 | |
| 130 | auto fmpPluginPreferenceHandler |
| 131 | = std::make_unique<jami::PluginPreferenceHandler>(nullptr, std::move(preferences), dataPath); |
| 132 | auto fmpTranscriptMediaHandler |
| 133 | = std::make_unique<jami::TranscriptMediaHandler>(std::move(dataPath), |
| 134 | fmpPluginPreferenceHandler.get()); |
| 135 | fmpPluginPreferenceHandler->setTranscriptHandler(fmpTranscriptMediaHandler.get()); |
| 136 | |
| 137 | auto subject = std::make_shared<jami::PublishObservable<AVFrame*>>(); |
| 138 | |
| 139 | // Valid Read frames from audio sample file and send to subscriber |
| 140 | fmpTranscriptMediaHandler->notifyAVFrameSubject(StreamData("testCall", |
| 141 | true, |
| 142 | StreamType::audio, |
| 143 | "origin", |
| 144 | "destiny"), |
| 145 | subject); |
| 146 | av_utils::readAndNotifyAVFrame(preferences["default"]["audiosample"], |
| 147 | subject.get(), |
| 148 | preferences["default"]["audiooutput"], |
| 149 | AVMEDIA_TYPE_AUDIO); |
| 150 | |
| 151 | // Valid Read frames from video sample file and send to subscriber |
| 152 | fmpTranscriptMediaHandler->notifyAVFrameSubject(StreamData("testCall", |
| 153 | true, |
| 154 | StreamType::video, |
| 155 | "origin", |
| 156 | "destiny"), |
| 157 | subject); |
| 158 | av_utils::readAndNotifyAVFrame(preferences["default"]["videosample"], |
| 159 | subject.get(), |
| 160 | preferences["default"]["videooutput"], |
| 161 | AVMEDIA_TYPE_VIDEO); |
| 162 | |
| 163 | return 0; |
| 164 | } |
| 165 | |
| 166 | #endif |