diff --git a/AudioFilter/ffmpeg/rules.mak b/AudioFilter/ffmpeg/rules.mak index 7a8eb4f6796a3ad2b542a5eacbf9fec45c47fb7d..b411d7f87261baa0d719f94a57ed27c8882275b0 100644 --- a/AudioFilter/ffmpeg/rules.mak +++ b/AudioFilter/ffmpeg/rules.mak @@ -1,13 +1,8 @@ FFMPEG_HASH := n4.4 - FFMPEG_URL := https://git.ffmpeg.org/gitweb/ffmpeg.git/snapshot/$(FFMPEG_HASH).tar.gz PKGS+=ffmpeg -ifeq ($(call need_pkg,"libavutil >= 55.75.100 libavcodec >= 57.106.101 libavformat >= 57.82.100 libavdevice >= 57.8.101 libavfilter >= 6.105.100 libswscale >= 4.7.103 libswresample >= 2.9.100"),) -PKGS_FOUND += ffmpeg -endif - DEPS_ffmpeg = iconv zlib vpx opus speex x264 FFMPEGCONF = \ diff --git a/AutoAnswer/BotChatHandler.cpp b/AutoAnswer/BotChatHandler.cpp index 39240aebb60bd5fe6ef9a4125d51540354255cc6..6a031792a737d70bdf1fe64c116a4ac3d42aa345 100644 --- a/AutoAnswer/BotChatHandler.cpp +++ b/AutoAnswer/BotChatHandler.cpp @@ -30,19 +30,14 @@ const std::string TAG = "Bot"; namespace jami { BotChatHandler::BotChatHandler(const JAMI_PluginAPI* api, - std::map<std::string, std::string>&& preferences, - std::string&& dataPath) + std::string&& dataPath, + PluginPreferenceHandler* prefHandler) : api_ {api} , datapath_ {dataPath} { - preferences_ = preferences; setId(datapath_); - auto answerIt = preferences_.find("answer"); - auto inTextIt = preferences_.find("inText"); - if (answerIt != preferences_.end() && inTextIt != preferences_.end()) - peerChatSubscriber_ = std::make_shared<BotPeerChatSubscriber>(api_, - answerIt->second, - inTextIt->second); + aph_ = prefHandler; + peerChatSubscriber_ = std::make_shared<BotPeerChatSubscriber>(api_, aph_); }; void @@ -65,27 +60,6 @@ BotChatHandler::getChatHandlerDetails() return {{"name", NAME}, {"iconPath", datapath_ + sep + "icon.svg"}, {"pluginId", id()}}; } -void -BotChatHandler::setPreferenceAttribute(const std::string& key, const std::string& value) -{ - if (peerChatSubscriber_) { - auto it = preferences_.find(key); - if (it != preferences_.end() && it->second != value) { - it->second = value; - if (key == "answer") - peerChatSubscriber_->setAnswer(value); - if (key == "inText") - peerChatSubscriber_->setInText(value); - } - } -} - -bool -BotChatHandler::preferenceMapHasKey(const std::string& key) -{ - return key == "answer" || key == "inText"; -} - void BotChatHandler::detach(chatSubjectPtr subject) { diff --git a/AutoAnswer/BotChatHandler.h b/AutoAnswer/BotChatHandler.h index c74d4c1b951c5abfa449956512321d34b88b6e8f..e32c709d8832cbe6cf5fdcdcc9505a695a501c03 100644 --- a/AutoAnswer/BotChatHandler.h +++ b/AutoAnswer/BotChatHandler.h @@ -38,23 +38,23 @@ class BotChatHandler : public jami::ChatHandler { public: BotChatHandler(const JAMI_PluginAPI* api, - std::map<std::string, std::string>&& preferences, - std::string&& dataPath); + std::string&& dataPath, + PluginPreferenceHandler* prefHandler); ~BotChatHandler(); virtual void notifyChatSubject(std::pair<std::string, std::string>& subjectConnection, chatSubjectPtr subject) override; virtual std::map<std::string, std::string> getChatHandlerDetails() override; virtual void detach(chatSubjectPtr subject) override; - virtual void setPreferenceAttribute(const std::string& key, const std::string& value) override; - virtual bool preferenceMapHasKey(const std::string& key) override; + virtual void setPreferenceAttribute(const std::string& key, const std::string& value) {} + virtual bool preferenceMapHasKey(const std::string& key) { return false; } - std::shared_ptr<BotPeerChatSubscriber> peerChatSubscriber_{}; + std::shared_ptr<BotPeerChatSubscriber> peerChatSubscriber_ {}; private: const JAMI_PluginAPI* api_; const std::string datapath_; - std::map<std::string, std::string> preferences_; + PluginPreferenceHandler* aph_; std::set<chatSubjectPtr> subjects; }; } // namespace jami diff --git a/AutoAnswer/BotPeerChatSubscriber.cpp b/AutoAnswer/BotPeerChatSubscriber.cpp index c1e6761b1fff2a0a56e894500ccfe739edee2fe8..19760f5a7dfc0ee2a1c6fd6767251b4c1a135d50 100644 --- a/AutoAnswer/BotPeerChatSubscriber.cpp +++ b/AutoAnswer/BotPeerChatSubscriber.cpp @@ -26,12 +26,10 @@ const std::string TAG = "bot"; namespace jami { BotPeerChatSubscriber::BotPeerChatSubscriber(const JAMI_PluginAPI* api, - const std::string& textAnswer, - const std::string& inText) + PluginPreferenceHandler* prefHandler) : api_ {api} { - setAnswer(textAnswer); - setInText(inText); + aph_ = prefHandler; } BotPeerChatSubscriber::~BotPeerChatSubscriber() @@ -41,21 +39,13 @@ BotPeerChatSubscriber::~BotPeerChatSubscriber() Plog::log(Plog::LogPriority::INFO, TAG, oss.str()); } -void -BotPeerChatSubscriber::setAnswer(const std::string& textAnswer) -{ - textAnswer_ = textAnswer; -} - -void -BotPeerChatSubscriber::setInText(const std::string& inText) -{ - inText_ = inText; -} - void BotPeerChatSubscriber::update(Observable<pluginMessagePtr>*, const pluginMessagePtr& message) { + if (!aph_) + return; + std::string input = aph_->getPreferences(message->accountId, "inText"); + std::string answer = aph_->getPreferences(message->accountId, "answer"); if (isAttached) { if (message->direction) { std::map<std::string, std::string> sendMsg; @@ -63,14 +53,13 @@ BotPeerChatSubscriber::update(Observable<pluginMessagePtr>*, const pluginMessage return; if (!message->isSwarm) for (auto& pair : message->data) { - if (pair.first == "text/plain" && pair.second == inText_) { - sendMsg[pair.first] = textAnswer_; + if (pair.first == "text/plain" && pair.second == input) { + sendMsg[pair.first] = answer; } } - else if (message->data.at("type") == "text/plain" - && message->data.at("body") == inText_) { + else if (message->data.at("type") == "text/plain" && message->data.at("body") == input) { sendMsg["type"] = "text/plain"; - sendMsg["body"] = textAnswer_; + sendMsg["body"] = answer; } if (!sendMsg.empty()) { sendText(message->accountId, message->peerId, sendMsg, message->isSwarm); diff --git a/AutoAnswer/BotPeerChatSubscriber.h b/AutoAnswer/BotPeerChatSubscriber.h index 26b7a276ebc10de7b32fb2c6562279ce8534b22c..cac463b953e2a4a84e4a7f2540c568b0f985f2a6 100644 --- a/AutoAnswer/BotPeerChatSubscriber.h +++ b/AutoAnswer/BotPeerChatSubscriber.h @@ -25,6 +25,7 @@ #include "plugin/streamdata.h" #include "plugin/jamiplugin.h" #include "plugin/chathandler.h" +#include "PluginPreferenceHandler.h" #include <map> #include <set> @@ -35,8 +36,7 @@ class BotPeerChatSubscriber : public Observer<pluginMessagePtr> { public: BotPeerChatSubscriber(const JAMI_PluginAPI* api, - const std::string& textAnswer, - const std::string& inText); + PluginPreferenceHandler* prefHandler); ~BotPeerChatSubscriber(); virtual void update(Observable<pluginMessagePtr>*, pluginMessagePtr const&) override; virtual void attached(Observable<pluginMessagePtr>*) override; @@ -54,7 +54,6 @@ protected: std::set<Observable<pluginMessagePtr>*> observables_; bool isAttached {false}; const JAMI_PluginAPI* api_; - std::string textAnswer_ {}; - std::string inText_ {}; + PluginPreferenceHandler* aph_; }; } // namespace jami diff --git a/AutoAnswer/CMakeLists.txt b/AutoAnswer/CMakeLists.txt index 8e0144600995b434a748d213027a9c796e4c68be..de54ba4644a85ff0620e0af388bc9956ad38d710 100644 --- a/AutoAnswer/CMakeLists.txt +++ b/AutoAnswer/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.10) # set the project name set (ProjectName AutoAnswer) -set (Version 1.0.0) +set (Version 2.0.0) project(${ProjectName} VERSION ${Version}) @@ -38,11 +38,13 @@ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd") set(plugin_SRC BotChatHandler.cpp BotPeerChatSubscriber.cpp + PluginPreferenceHandler.cpp main.cpp ) set(plugin_HDR BotChatHandler.h BotPeerChatSubscriber.h + PluginPreferenceHandler.h ./../lib/pluglog.h ) @@ -59,8 +61,6 @@ target_include_directories(${ProjectName} PUBLIC ${PROJECT_BINARY_DIR} target_link_directories(${ProjectName} PUBLIC ${CONTRIB_PATH} ) -# target_link_libraries(${ProjectName} PUBLIC ) - add_custom_command( TARGET ${ProjectName} PRE_BUILD diff --git a/AutoAnswer/PluginPreferenceHandler.cpp b/AutoAnswer/PluginPreferenceHandler.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0690932134b89e5060d15ad984d53b2bdd39a37d --- /dev/null +++ b/AutoAnswer/PluginPreferenceHandler.cpp @@ -0,0 +1,97 @@ +/** + * Copyright (C) 2021 Savoir-faire Linux Inc. + * + * Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "PluginPreferenceHandler.h" + +#include "pluglog.h" + +const char sep = separator(); +const std::string TAG = "BotAcc"; + +#define NAME "BotAcc" + +namespace jami { + +PluginPreferenceHandler::PluginPreferenceHandler( + const JAMI_PluginAPI* api, + std::map<std::string, std::map<std::string, std::string>>&& preferences, + const std::string& dataPath) + : api_ {api} + , datapath_ {dataPath} +{ + preferences_ = preferences; + setId(datapath_); +}; + +std::map<std::string, std::string> +PluginPreferenceHandler::getHandlerDetails() +{ + return {{"name", NAME}, {"iconPath", datapath_ + sep + "icon.svg"}, {"pluginId", id()}}; +} + +void +PluginPreferenceHandler::setPreferenceAttribute(const std::string& accountId, + const std::string& key, + const std::string& value) +{ + auto accIt = preferences_.find("default"); + if (!accountId.empty()) + accIt = preferences_.emplace(accountId, preferences_["default"]).first; + + auto it = accIt->second.find(key); + if (it != accIt->second.end() && it->second != value) { + it->second = value; + } +} + +void +PluginPreferenceHandler::resetPreferenceAttributes(const std::string& accountId) +{ + std::lock_guard<std::mutex> lk(mtx_); + if (accountId.empty()) { + preferences_.clear(); + api_->invokeService(api_, "getPluginAccPreferences", &preferences_); + } else + preferences_[accountId] = preferences_["default"]; +} + +bool +PluginPreferenceHandler::preferenceMapHasKey(const std::string& key) +{ + return key == "answer" || key == "inText"; +} + +std::string +PluginPreferenceHandler::getPreferences(const std::string& accountId, const std::string& key) +{ + std::lock_guard<std::mutex> lk(mtx_); + auto accIt = preferences_.emplace(accountId, preferences_["default"]).first; + auto valueIt = accIt->second.find(key); + if (valueIt != accIt->second.end()) { + return valueIt->second; + } + return ""; +} + +PluginPreferenceHandler::~PluginPreferenceHandler() +{ + preferences_.clear(); +} +} // namespace jami diff --git a/AutoAnswer/PluginPreferenceHandler.h b/AutoAnswer/PluginPreferenceHandler.h new file mode 100644 index 0000000000000000000000000000000000000000..3e1fac048ce6f4c73c211329cdebd44741955c1a --- /dev/null +++ b/AutoAnswer/PluginPreferenceHandler.h @@ -0,0 +1,57 @@ +/** + * Copyright (C) 2021 Savoir-faire Linux Inc. + * + * Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#pragma once + +#include "plugin/jamiplugin.h" +#include "plugin/preferencehandler.h" + +#include <string> +#include <map> +#include <memory> +#include <set> +#include <mutex> + +namespace jami { + +class PluginPreferenceHandler : public jami::PreferenceHandler +{ +public: + PluginPreferenceHandler(const JAMI_PluginAPI* api, + std::map<std::string, std::map<std::string, std::string>>&& preferences, + const std::string& dataPath); + ~PluginPreferenceHandler(); + + virtual std::map<std::string, std::string> getHandlerDetails() override; + virtual bool preferenceMapHasKey(const std::string& key) override; + virtual void setPreferenceAttribute(const std::string& accountId, + const std::string& key, + const std::string& value) override; + virtual void resetPreferenceAttributes(const std::string& accountId) override; + + std::string getPreferences(const std::string& accountId, const std::string& key); + +private: + const JAMI_PluginAPI* api_; + const std::string datapath_; + std::map<std::string, std::map<std::string, std::string>> preferences_; + std::mutex mtx_; +}; +} // namespace jami diff --git a/AutoAnswer/build.sh b/AutoAnswer/build.sh index c46b2270607d76639fbabc355bb806a17e172480..5af8d2143e91134e9a077de5439113a5735e979e 100755 --- a/AutoAnswer/build.sh +++ b/AutoAnswer/build.sh @@ -73,6 +73,7 @@ then -I"${DAEMON_SRC}" \ -I"${CONTRIB_PATH}/${CONTRIB_PLATFORM}/include" \ -I"${PLUGINS_LIB}" \ + PluginPreferenceHandler.cpp \ BotChatHandler.cpp \ BotPeerChatSubscriber.cpp \ main.cpp \ @@ -205,6 +206,7 @@ then -I"${DAEMON_SRC}" \ -I"${CONTRIB_PATH}/${CONTRIB_PLATFORM}/include" \ -I"${PLUGINS_LIB}" \ + PluginPreferenceHandler.cpp \ BotChatHandler.cpp \ BotPeerChatSubscriber.cpp \ main.cpp \ diff --git a/AutoAnswer/data/accountpreferences.json b/AutoAnswer/data/accountpreferences.json new file mode 100644 index 0000000000000000000000000000000000000000..05b693d1257b6c15308203aef1f1c40fe655a569 --- /dev/null +++ b/AutoAnswer/data/accountpreferences.json @@ -0,0 +1,18 @@ +[ + { + "type": "EditText", + "key": "inText", + "title": "Bot trigger", + "summary": "Text that bot will answer to", + "defaultValue": "Hi", + "scope": "account,Bot" + }, + { + "type": "EditText", + "key": "answer", + "title": "Bot answer", + "summary": "Set bot text", + "defaultValue": "Hello World from bot preference", + "scope": "account,Bot" + } +] \ No newline at end of file diff --git a/AutoAnswer/data/preferences.json b/AutoAnswer/data/preferences.json index db5a25972de19e2b0d4fe63eba77209f8dbaf132..0637a088a01e8ddab3bf3fa98dbe804cbde1a0dc 100644 --- a/AutoAnswer/data/preferences.json +++ b/AutoAnswer/data/preferences.json @@ -1,18 +1 @@ -[ - { - "type": "EditText", - "key": "inText", - "title": "Bot trigger", - "summary": "Text that bot will answer to", - "defaultValue": "Hi", - "scope": "plugin,Bot" - }, - { - "type": "EditText", - "key": "answer", - "title": "Bot answer", - "summary": "Set bot text", - "defaultValue": "Hello World from bot preference", - "scope": "plugin,Bot" - } -] \ No newline at end of file +[] \ No newline at end of file diff --git a/AutoAnswer/main.cpp b/AutoAnswer/main.cpp index 7d90bbacd1294b8ec0079f3ff037bb90bae8e260..ff4d180d035c3ca602cf297abb64fe6d82f9a30e 100644 --- a/AutoAnswer/main.cpp +++ b/AutoAnswer/main.cpp @@ -32,7 +32,7 @@ #define EXPORT_PLUGIN #endif -#define AutoAnswer_VERSION_MAJOR 1 +#define AutoAnswer_VERSION_MAJOR 2 #define AutoAnswer_VERSION_MINOR 0 #define AutoAnswer_VERSION_PATCH 0 @@ -53,17 +53,28 @@ JAMI_dynPluginInit(const JAMI_PluginAPI* api) // If invokeService doesn't return an error if (api) { - std::map<std::string, std::string> preferences; - api->invokeService(api, "getPluginPreferences", &preferences); + if (api->version.api < JAMI_PLUGIN_API_VERSION) + return nullptr; + + std::map<std::string, std::map<std::string, std::string>> preferences; + api->invokeService(api, "getPluginAccPreferences", &preferences); std::string dataPath; api->invokeService(api, "getPluginDataPath", &dataPath); - auto fmpBotChatHandler = std::make_unique<jami::BotChatHandler>(api, - std::move(preferences), - std::move(dataPath)); + auto fmpPluginPreferenceHandler + = std::make_unique<jami::PluginPreferenceHandler>(api, std::move(preferences), dataPath); + auto fmpBotChatHandler + = std::make_unique<jami::BotChatHandler>(api, + std::move(dataPath), + fmpPluginPreferenceHandler.get()); if (api->manageComponent(api, "ChatHandlerManager", fmpBotChatHandler.release())) { return nullptr; } + if (api->manageComponent(api, + "PreferenceHandlerManager", + fmpPluginPreferenceHandler.release())) { + return nullptr; + } } return pluginExit; diff --git a/AutoAnswer/manifest.json b/AutoAnswer/manifest.json index 2cb02f9758fe0a19405f48a8ceef772542803ae0..d0492be873f2ee1a3ea63f5e38a4766bdd6a4e46 100644 --- a/AutoAnswer/manifest.json +++ b/AutoAnswer/manifest.json @@ -1,6 +1,6 @@ { "name": "AutoAnswer", "description": "A plugin that automatically answers with given text", - "version": "1.0.0", + "version": "2.0.0", "iconPath": "icon.svg" } \ No newline at end of file diff --git a/AutoAnswer/package.json b/AutoAnswer/package.json index 25df3169858c81b7fcc31b1bda098e62bc4542cf..d4b4f16a91ac1ac184834694ae14df6a4c93eb83 100644 --- a/AutoAnswer/package.json +++ b/AutoAnswer/package.json @@ -1,6 +1,6 @@ { "name": "AutoAnswer", - "version": "1.0.0", + "version": "2.0.0", "extractLibs": false, "deps": [], "defines": [], diff --git a/GreenScreen/ffmpeg/rules.mak b/GreenScreen/ffmpeg/rules.mak index 399033222c16042eaa1fc80c118a2ef123730f64..ee69f582c8c6f4aadd1f5466d8230c4b5ae00041 100644 --- a/GreenScreen/ffmpeg/rules.mak +++ b/GreenScreen/ffmpeg/rules.mak @@ -3,10 +3,6 @@ FFMPEG_URL := https://git.ffmpeg.org/gitweb/ffmpeg.git/snapshot/$(FFMPEG_HASH).t PKGS+=ffmpeg -ifeq ($(call need_pkg,"libavutil >= 55.75.100 libavcodec >= 57.106.101 libavformat >= 57.82.100 libavdevice >= 57.8.101 libavfilter >= 6.105.100 libswscale >= 4.7.103 libswresample >= 2.9.100"),) -PKGS_FOUND += ffmpeg -endif - DEPS_ffmpeg = iconv zlib vpx opus speex x264 FFMPEGCONF = \ diff --git a/WaterMark/CMakeLists.txt b/WaterMark/CMakeLists.txt index 8b8fae5e15cb64d532513d49e5d9e499e3263978..11bd26be772544d787b8cf7f37fb673bf1130fa9 100644 --- a/WaterMark/CMakeLists.txt +++ b/WaterMark/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.10) # set the project name set (ProjectName WaterMark) -set (Version 1.0.0) +set (Version 2.0.0) project(${ProjectName} VERSION ${Version}) @@ -40,6 +40,7 @@ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MDd") set(plugin_SRC WatermarkVideoSubscriber.cpp main.cpp WatermarkMediaHandler.cpp + PluginPreferenceHandler.cpp ./../lib/accel.cpp ./../lib/frameUtils.cpp ./../lib/frameFilter.cpp @@ -47,6 +48,7 @@ set(plugin_SRC WatermarkVideoSubscriber.cpp set(plugin_HDR WatermarkVideoSubscriber.h WatermarkMediaHandler.h + PluginPreferenceHandler.h ./../lib/accel.h ./../lib/frameUtils.h ./../lib/pluglog.h @@ -77,6 +79,12 @@ target_link_libraries(${ProjectName} PUBLIC libavfilter libswscale libavformat l add_custom_command( TARGET ${ProjectName} PRE_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/zlib ${CONTRIB_PATH}/src/zlib + COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/../contrib/freetype ${CONTRIB_PATH}/src/freetype + COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/ffmpeg/ ${CONTRIB_PATH}/src/ffmpeg + COMMAND python ${DAEMON}/compat/msvc/winmake.py -fb zlib + COMMAND python ${DAEMON}/compat/msvc/winmake.py -fb freetype + COMMAND python ${DAEMON}/compat/msvc/winmake.py -fb ffmpeg COMMAND python ${PROJECT_SOURCE_DIR}/../SDK/jplManipulation.py --preassemble --plugin=${ProjectName} COMMENT "Assembling Plugin files" ) @@ -89,5 +97,7 @@ add_custom_command( COMMAND python ${PROJECT_SOURCE_DIR}/../SDK/jplManipulation.py --assemble --plugin=${ProjectName} COMMAND cd ${CONTRIB_PATH}/src/ffmpeg/ COMMAND git checkout * + COMMAND cd ${CONTRIB_PATH}/src/zlib/ + COMMAND git checkout * COMMENT "Generating JPL archive" ) diff --git a/WaterMark/PluginPreferenceHandler.cpp b/WaterMark/PluginPreferenceHandler.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b9dcdc8382743d0dbc49afb50e4e83ecbc475bed --- /dev/null +++ b/WaterMark/PluginPreferenceHandler.cpp @@ -0,0 +1,104 @@ +/** + * Copyright (C) 2021 Savoir-faire Linux Inc. + * + * Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "PluginPreferenceHandler.h" + +#include "WatermarkMediaHandler.h" +#include "pluglog.h" + +const char sep = separator(); +const std::string TAG = "WaterMarkAcc"; + +#define NAME "WaterMarkAcc" + +namespace jami { + +PluginPreferenceHandler::PluginPreferenceHandler( + const JAMI_PluginAPI* api, + std::map<std::string, std::map<std::string, std::string>>&& preferences, + const std::string& dataPath) + : api_ {api} + , datapath_ {dataPath} +{ + preferences_ = preferences; + setId(datapath_); +}; + +std::map<std::string, std::string> +PluginPreferenceHandler::getHandlerDetails() +{ + return {{"name", NAME}, {"iconPath", datapath_ + sep + "icon.svg"}, {"pluginId", id()}}; +} + +void +PluginPreferenceHandler::setPreferenceAttribute(const std::string& accountId, + const std::string& key, + const std::string& value) +{ + auto accIt = preferences_.find("default"); + if (!accountId.empty()) + accIt = preferences_.emplace(accountId, preferences_["default"]).first; + + auto it = accIt->second.find(key); + if (it != accIt->second.end() && it->second != value) { + it->second = value; + } + wmh_->setParameters(accountId); +} + +void +PluginPreferenceHandler::resetPreferenceAttributes(const std::string& accountId) +{ + std::lock_guard<std::mutex> lk(mtx_); + if (accountId.empty()) { + preferences_.clear(); + api_->invokeService(api_, "getPluginAccPreferences", &preferences_); + } else + preferences_[accountId] = preferences_["default"]; + wmh_->setParameters(accountId); +} + +bool +PluginPreferenceHandler::preferenceMapHasKey(const std::string& key) +{ + return (key == "showlogo" || key == "mark" || key == "markbackground" || key == "logosize" + || key == "showinfos" || key == "location" || key == "date" || key == "time" + || key == "infosposition" || key == "logoposition" || key == "timeformat" + || key == "timezone" || key == "dateformat" || key == "fontsize"); +} + +std::map<std::string, std::string> +PluginPreferenceHandler::getPreferences(const std::string& accountId) +{ + std::lock_guard<std::mutex> lk(mtx_); + return preferences_.emplace(accountId, preferences_["default"]).first->second; +} + +PluginPreferenceHandler::~PluginPreferenceHandler() +{ + preferences_.clear(); +} + +void +PluginPreferenceHandler::setWaterMarkHandler(WatermarkMediaHandler* handler) +{ + wmh_ = handler; +} +} // namespace jami diff --git a/WaterMark/PluginPreferenceHandler.h b/WaterMark/PluginPreferenceHandler.h new file mode 100644 index 0000000000000000000000000000000000000000..98571fc5a3082f39620cf611382cc52c25915729 --- /dev/null +++ b/WaterMark/PluginPreferenceHandler.h @@ -0,0 +1,60 @@ +/** + * Copyright (C) 2021 Savoir-faire Linux Inc. + * + * Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#pragma once + +#include "plugin/jamiplugin.h" +#include "plugin/preferencehandler.h" + +#include <string> +#include <map> +#include <memory> +#include <set> +#include <mutex> + +namespace jami { +class WatermarkMediaHandler; + +class PluginPreferenceHandler : public jami::PreferenceHandler +{ +public: + PluginPreferenceHandler(const JAMI_PluginAPI* api, + std::map<std::string, std::map<std::string, std::string>>&& preferences, + const std::string& dataPath); + ~PluginPreferenceHandler(); + + virtual std::map<std::string, std::string> getHandlerDetails() override; + virtual bool preferenceMapHasKey(const std::string& key) override; + virtual void setPreferenceAttribute(const std::string& accountId, + const std::string& key, + const std::string& value) override; + virtual void resetPreferenceAttributes(const std::string& accountId) override; + + std::map<std::string, std::string> getPreferences(const std::string& accountId); + void setWaterMarkHandler(WatermarkMediaHandler* handler); + +private: + const JAMI_PluginAPI* api_; + WatermarkMediaHandler* wmh_; + const std::string datapath_; + std::map<std::string, std::map<std::string, std::string>> preferences_; + std::mutex mtx_; +}; +} // namespace jami diff --git a/WaterMark/WatermarkMediaHandler.cpp b/WaterMark/WatermarkMediaHandler.cpp index 904a589f6eaefad382581df42cff1ec9b6e5db29..47a61fae9fe7364f19a1b47d0db86954bfcd8a26 100644 --- a/WaterMark/WatermarkMediaHandler.cpp +++ b/WaterMark/WatermarkMediaHandler.cpp @@ -20,6 +20,7 @@ #include "WatermarkMediaHandler.h" +#include "PluginPreferenceHandler.h" #include "pluglog.h" #include <string_view> @@ -30,13 +31,14 @@ const std::string TAG = "Watermark"; namespace jami { -WatermarkMediaHandler::WatermarkMediaHandler(std::map<std::string, std::string>&& preferences, - std::string&& datapath) - : datapath_ {datapath} - , preferences_ {preferences} +WatermarkMediaHandler::WatermarkMediaHandler(std::string&& dataPath, + PluginPreferenceHandler* prefHandler) + : datapath_ {dataPath} { + aph_ = prefHandler; setId(datapath_); - mediaSubscriber_ = std::make_shared<WatermarkVideoSubscriber>(datapath_, preferences_); + mediaSubscriber_ = std::make_shared<WatermarkVideoSubscriber>(datapath_); + setParameters("default"); } void @@ -46,9 +48,12 @@ WatermarkMediaHandler::notifyAVFrameSubject(const StreamData& data, jami::avSubj std::string_view direction = data.direction ? "Receive" : "Preview"; oss << "NEW SUBJECT: [" << data.id << "," << direction << "]" << std::endl; + accountId_ = data.source; + auto preferences = aph_->getPreferences(accountId_); + bool preferredStreamDirection {false}; // false for output; true for input - auto it = preferences_.find("videostream"); - if (it != preferences_.end()) { + auto it = preferences.find("videostream"); + if (it != preferences.end()) { preferredStreamDirection = it->second == "1"; } oss << "preferredStreamDirection " << preferredStreamDirection << std::endl; @@ -56,6 +61,8 @@ WatermarkMediaHandler::notifyAVFrameSubject(const StreamData& data, jami::avSubj && data.direction == preferredStreamDirection) { if (attached_ == "1") detach(); + + setParameters(data.source); subject->attach(mediaSubscriber_.get()); // your image oss << "got my sent image attached" << std::endl; attached_ = "1"; @@ -63,6 +70,7 @@ WatermarkMediaHandler::notifyAVFrameSubject(const StreamData& data, jami::avSubj && data.direction == preferredStreamDirection) { if (attached_ == "1") detach(); + setParameters(data.source); subject->attach(mediaSubscriber_.get()); // the image you receive from others on the call oss << "got received image attached" << std::endl; attached_ = "1"; @@ -71,6 +79,32 @@ WatermarkMediaHandler::notifyAVFrameSubject(const StreamData& data, jami::avSubj Plog::log(Plog::LogPriority::INFO, TAG, oss.str()); } +void +WatermarkMediaHandler::setParameters(const std::string& accountId) +{ + if (accountId != accountId_) + return; + auto preferences = aph_->getPreferences(accountId); + try { + mediaSubscriber_->setParameter(preferences["fontsize"], Parameter::FONTSIZE); + mediaSubscriber_->setParameter(preferences["logosize"], Parameter::LOGOSIZE); + mediaSubscriber_->setParameter(preferences["markbackground"], Parameter::LOGOBACKGROUND); + mediaSubscriber_->setParameter(preferences["showinfos"], Parameter::SHOWINFOS); + mediaSubscriber_->setParameter(preferences["showlogo"], Parameter::SHOWLOGO); + mediaSubscriber_->setParameter(preferences["mark"], Parameter::LOGOPATH); + mediaSubscriber_->setParameter(preferences["date"], Parameter::DATE); + mediaSubscriber_->setParameter(preferences["dateformat"], Parameter::DATEFORMAT); + mediaSubscriber_->setParameter(preferences["time"], Parameter::TIME); + mediaSubscriber_->setParameter(preferences["timezone"], Parameter::TIMEZONE); + mediaSubscriber_->setParameter(preferences["timeformat"], Parameter::TIMEFORMAT); + mediaSubscriber_->setParameter(preferences["location"], Parameter::LOCATION); + mediaSubscriber_->setParameter(preferences["infosposition"], Parameter::INFOSPOSITION); + mediaSubscriber_->setParameter(preferences["logoposition"], Parameter::LOGOPOSITION); + } catch (std::exception e) { + Plog::log(Plog::LogPriority::ERR, TAG, e.what()); + } +} + std::map<std::string, std::string> WatermarkMediaHandler::getCallMediaHandlerDetails() { @@ -81,81 +115,6 @@ WatermarkMediaHandler::getCallMediaHandlerDetails() {"dataType", "1"}}; } -void -WatermarkMediaHandler::setPreferenceAttribute(const std::string& key, const std::string& value) -{ - auto it = preferences_.find(key); - if (it != preferences_.end() && it->second != value) { - it->second = value; - if (key == "showlogo") { - mediaSubscriber_->setParameter(it->second, Parameter::SHOWLOGO); - return; - } - if (key == "mark") { - mediaSubscriber_->setParameter(it->second, Parameter::LOGOPATH); - return; - } - if (key == "markbackground") { - mediaSubscriber_->setParameter(it->second, Parameter::LOGOBACKGROUND); - return; - } - if (key == "location") { - mediaSubscriber_->setParameter(it->second, Parameter::LOCATION); - return; - } - if (key == "date") { - mediaSubscriber_->setParameter(it->second, Parameter::DATE); - return; - } - if (key == "time") { - mediaSubscriber_->setParameter(it->second, Parameter::TIME); - return; - } - if (key == "logoposition") { - mediaSubscriber_->setParameter(it->second, Parameter::LOGOPOSITION); - return; - } - if (key == "infosposition") { - mediaSubscriber_->setParameter(it->second, Parameter::INFOSPOSITION); - return; - } - if (key == "timeformat") { - mediaSubscriber_->setParameter(it->second, Parameter::TIMEFORMAT); - return; - } - if (key == "timezone") { - mediaSubscriber_->setParameter(it->second, Parameter::TIMEZONE); - mediaSubscriber_->setParameter(preferences_["timeformat"], Parameter::TIMEFORMAT); - return; - } - if (key == "dateformat") { - mediaSubscriber_->setParameter(it->second, Parameter::DATEFORMAT); - return; - } - if (key == "fontsize") { - mediaSubscriber_->setParameter(it->second, Parameter::FONTSIZE); - return; - } - if (key == "logosize") { - mediaSubscriber_->setParameter(it->second, Parameter::LOGOSIZE); - return; - } - if (key == "showinfos") { - mediaSubscriber_->setParameter(it->second, Parameter::SHOWINFOS); - return; - } - } -} - -bool -WatermarkMediaHandler::preferenceMapHasKey(const std::string& key) -{ - return (key == "showlogo" || key == "mark" || key == "markbackground" || key == "logosize" - || key == "showinfos" || key == "location" || key == "date" || key == "time" - || key == "infosposition" || key == "logoposition" || key == "timeformat" - || key == "timezone" || key == "dateformat" || key == "fontsize"); -} - void WatermarkMediaHandler::detach() { @@ -165,9 +124,7 @@ WatermarkMediaHandler::detach() WatermarkMediaHandler::~WatermarkMediaHandler() { - std::ostringstream oss; - oss << " ~WatermarkMediaHandler from WaterMark Plugin" << std::endl; - Plog::log(Plog::LogPriority::INFO, TAG, oss.str()); + Plog::log(Plog::LogPriority::INFO, TAG, "~WatermarkMediaHandler from WaterMark Plugin"); detach(); } } // namespace jami diff --git a/WaterMark/WatermarkMediaHandler.h b/WaterMark/WatermarkMediaHandler.h index 8e618bb1dd99991dd04cd31ac717d99f330c25b7..2844b7b9cad30d1b10f57d131053f509c4d032c8 100644 --- a/WaterMark/WatermarkMediaHandler.h +++ b/WaterMark/WatermarkMediaHandler.h @@ -28,25 +28,28 @@ using avSubjectPtr = std::weak_ptr<jami::Observable<AVFrame*>>; namespace jami { +class PluginPreferenceHandler; class WatermarkMediaHandler : public jami::CallMediaHandler { public: - WatermarkMediaHandler(std::map<std::string, std::string>&& preferences, std::string&& dataPath); + WatermarkMediaHandler(std::string&& dataPath, PluginPreferenceHandler* prefHandler); ~WatermarkMediaHandler(); virtual void notifyAVFrameSubject(const StreamData& data, avSubjectPtr subject) override; virtual std::map<std::string, std::string> getCallMediaHandlerDetails() override; virtual void detach() override; - virtual void setPreferenceAttribute(const std::string& key, const std::string& value) override; - virtual bool preferenceMapHasKey(const std::string& key) override; + virtual void setPreferenceAttribute(const std::string& key, const std::string& value) {} + virtual bool preferenceMapHasKey(const std::string& key) { return false; } std::shared_ptr<WatermarkVideoSubscriber> mediaSubscriber_; + void setParameters(const std::string& accountId); private: + std::string accountId_ {"default"}; const std::string datapath_; - std::map<std::string, std::string> preferences_; + PluginPreferenceHandler* aph_; std::string attached_ {'0'}; }; } // namespace jami diff --git a/WaterMark/WatermarkVideoSubscriber.cpp b/WaterMark/WatermarkVideoSubscriber.cpp index 5296b002793e11e90392c44b91c2985fa736bd2b..ace33b9d600a18bd1b3a442a804679b19cefa04c 100644 --- a/WaterMark/WatermarkVideoSubscriber.cpp +++ b/WaterMark/WatermarkVideoSubscriber.cpp @@ -37,8 +37,7 @@ const char sep = separator(); namespace jami { -WatermarkVideoSubscriber::WatermarkVideoSubscriber(const std::string& dataPath, - std::map<std::string, std::string>& preferences) +WatermarkVideoSubscriber::WatermarkVideoSubscriber(const std::string& dataPath) { if (std::setlocale(LC_TIME, std::locale("").name().c_str()) == NULL) { Plog::log(Plog::LogPriority::INFO, TAG, "error while setting locale"); @@ -52,24 +51,6 @@ WatermarkVideoSubscriber::WatermarkVideoSubscriber(const std::string& dataPath, fontFile_.insert(i, "\\"); fontFile_.insert(1, "\\"); #endif - try { - setParameter(preferences["fontsize"], Parameter::FONTSIZE); - setParameter(preferences["logosize"], Parameter::LOGOSIZE); - setParameter(preferences["markbackground"], Parameter::LOGOBACKGROUND); - setParameter(preferences["showinfos"], Parameter::SHOWINFOS); - setParameter(preferences["showlogo"], Parameter::SHOWLOGO); - setParameter(preferences["mark"], Parameter::LOGOPATH); - setParameter(preferences["date"], Parameter::DATE); - setParameter(preferences["dateformat"], Parameter::DATEFORMAT); - setParameter(preferences["time"], Parameter::TIME); - setParameter(preferences["timezone"], Parameter::TIMEZONE); - setParameter(preferences["timeformat"], Parameter::TIMEFORMAT); - setParameter(preferences["location"], Parameter::LOCATION); - setParameter(preferences["infosposition"], Parameter::INFOSPOSITION); - setParameter(preferences["logoposition"], Parameter::LOGOPOSITION); - } catch (std::exception e) { - Plog::log(Plog::LogPriority::ERR, TAG, e.what()); - } } WatermarkVideoSubscriber::~WatermarkVideoSubscriber() diff --git a/WaterMark/WatermarkVideoSubscriber.h b/WaterMark/WatermarkVideoSubscriber.h index 5e26f5c35de6616d6aaa93dee1c45de5567b7118..4ec39e08234ea65170dffc5265e2543396cecdf9 100644 --- a/WaterMark/WatermarkVideoSubscriber.h +++ b/WaterMark/WatermarkVideoSubscriber.h @@ -51,8 +51,7 @@ enum Parameter { class WatermarkVideoSubscriber : public jami::Observer<AVFrame*> { public: - WatermarkVideoSubscriber(const std::string& dataPath, - std::map<std::string, std::string>& preferences); + WatermarkVideoSubscriber(const std::string& dataPath); ~WatermarkVideoSubscriber(); virtual void update(jami::Observable<AVFrame*>*, AVFrame* const&) override; diff --git a/WaterMark/build.sh b/WaterMark/build.sh index 3cc3abf9842d8bd48659b34baf381c29b98940a3..2cbd013b885c88b4fcb033fb4e5f034f263ba6d5 100755 --- a/WaterMark/build.sh +++ b/WaterMark/build.sh @@ -88,6 +88,7 @@ then WatermarkVideoSubscriber.cpp \ main.cpp \ WatermarkMediaHandler.cpp \ + PluginPreferenceHandler.cpp \ -L"${CONTRIB_PATH}/${CONTRIB_PLATFORM}/lib/" \ -l:libavfilter.a \ -l:libswscale.a \ @@ -135,6 +136,7 @@ then WatermarkVideoSubscriber.cpp \ main.cpp \ WatermarkMediaHandler.cpp \ + PluginPreferenceHandler.cpp \ -L"${CONTRIB_PATH}/${CONTRIB_PLATFORM}${CONTRIB_PLATFORM_EXTRA}/lib/" \ -lavfilter \ -lswscale \ @@ -288,6 +290,7 @@ then WatermarkVideoSubscriber.cpp \ main.cpp \ WatermarkMediaHandler.cpp \ + PluginPreferenceHandler.cpp \ -L"${CONTRIB_PATH}/${CONTRIB_PLATFORM}/lib/" \ -lavfilter \ -lswscale \ diff --git a/WaterMark/data/accountpreferences.json b/WaterMark/data/accountpreferences.json new file mode 100644 index 0000000000000000000000000000000000000000..0a025c6211fca2953b33e4f7ec5966b7907f4f12 --- /dev/null +++ b/WaterMark/data/accountpreferences.json @@ -0,0 +1,259 @@ +[ + { + "category": "Set a logo image", + "type": "Switch", + "key": "showlogo", + "title": "Use a logo image", + "summary": "Do you want to display a logo image?", + "defaultValue": "1", + "scope": "plugin,Watermark" + }, + { + "category": "Set a logo image", + "type": "List", + "key": "logoposition", + "title": "WaterMark position", + "summary": "Where display the logo?", + "defaultValue": "3", + "scope": "plugin,Watermark", + "dependsOn": "showlogo", + "entryValues": [ + "1", + "2", + "3", + "4" + ], + "entries": [ + "TopRight", + "TopLeft", + "BottomLeft", + "BottomRight" + ] + }, + { + "category": "Set a logo image", + "type": "Path", + "key": "mark", + "title": "Choose a WaterMark logo image", + "summary": "Choose an image file", + "defaultValue": "data/defaultWM.png", + "scope": "plugin,Watermark", + "dependsOn": "showlogo", + "mimeType": "*/png,*/jpg,*/jpeg" + }, + { + "category": "Set a logo image", + "type": "List", + "key": "markbackground", + "title": "Add a background color", + "summary": "If you cannot see properly your logo, adding a background may be helpful", + "defaultValue": "black@0.0", + "scope": "plugin,Watermark", + "dependsOn": "showlogo", + "entryValues": [ + "black@0.0", + "black@0.5", + "white@0.5" + ], + "entries": [ + "None", + "Black", + "White" + ] + }, + { + "category": "Set a logo image", + "type": "List", + "key": "logosize", + "title": "Logo size", + "summary": "set a logo size", + "defaultValue": "0.1", + "scope": "plugin,Watermark", + "dependsOn": "showlogo", + "entryValues": [ + "0.1", + "0.15", + "0.2", + "0.25", + "0.4", + "0.6", + "0.8", + "1.0" + ], + "entries": [ + "10%", + "15%", + "20%", + "25%", + "40%", + "60%", + "80%", + "100%" + ] + }, + { + "category": "Set a text", + "type": "Switch", + "key": "showinfos", + "title": "Use informations", + "summary": "Do you want to display informations?", + "defaultValue": "1", + "scope": "plugin,Watermark" + }, + { + "category": "Set a text", + "type": "List", + "key": "infosposition", + "title": "Text position", + "summary": "Where display text?", + "defaultValue": "3", + "scope": "plugin,Watermark", + "dependsOn": "showinfos", + "entryValues": [ + "1", + "2", + "3", + "4" + ], + "entries": [ + "TopRight", + "TopLeft", + "BottomLeft", + "BottomRight" + ] + }, + { + "category": "Set a text", + "type": "EditText", + "key": "location", + "title": "Information to be displayed", + "summary": "Write any information you want to display, like city or project name", + "defaultValue": "", + "scope": "plugin,Watermark", + "dependsOn": "showinfos" + }, + { + "category": "Set a text", + "type": "Switch", + "key": "date", + "title": "Date", + "summary": "Do you want to display the date?", + "defaultValue": "1", + "scope": "plugin,Watermark", + "dependsOn": "showinfos" + }, + { + "category": "Set a text", + "type": "List", + "key": "dateformat", + "title": "Date format", + "summary": "Choose date format", + "defaultValue": "%x", + "scope": "plugin,Watermark", + "dependsOn": "showinfos", + "entryValues": [ + "%x", + "%a %Y/%m/%d", + "%a %m/%d/%Y", + "%a %d/%m/%Y", + "%Y/%m/%d", + "%m/%d/%Y", + "%d/%m/%Y", + "%b %d %Y", + "%d %b %Y " + ], + "entries": [ + "Language pattern", + "WeekDay YYYY/MM/DD", + "WeekDay MM/DD/YYYY", + "WeekDay DD/MM/YYYY", + "YYYY/MM/DD", + "MM/DD/YYYY", + "DD/MM/YYYY", + "Month DD YYYY", + "DD Month YYYY" + ] + }, + { + "category": "Set a text", + "type": "Switch", + "key": "time", + "title": "Time", + "summary": "Do you want to display the time?", + "defaultValue": "1", + "scope": "plugin,Watermark", + "dependsOn": "showinfos" + }, + { + "category": "Set a text", + "type": "List", + "key": "timeformat", + "title": "Time Format", + "summary": "Choose time format", + "defaultValue": "%X", + "scope": "plugin,Watermark", + "dependsOn": "showinfos", + "entryValues": [ + "%X", + "%R", + "%T", + "%I\\\\\\\\\\\\:%M %p", + "%r" + ], + "entries": [ + "Language pattern", + "HH:MM (24H)", + "HH:MM:SS (24H)", + "HH:MM (12H)", + "HH:MM:SS (12H)" + ] + }, + { + "category": "Set a text", + "type": "Switch", + "key": "timezone", + "title": "Time Zone", + "summary": "Display time zone?", + "defaultValue": "1", + "scope": "plugin,Watermark", + "dependsOn": "showinfos" + }, + { + "category": "Set a text", + "type": "List", + "key": "fontsize", + "title": "Font size", + "summary": "Choose font size", + "defaultValue": "14", + "scope": "plugin,Watermark", + "dependsOn": "showinfos", + "entryValues": [ + "10", + "12", + "14", + "16", + "18", + "24", + "36", + "72" + ], + "entries": [ + "10", + "12", + "14", + "16", + "18", + "24", + "36", + "72" + ] + }, + { + "type": "Switch", + "key": "WatermarkAlways", + "title": "Use WaterMark as default", + "summary": "Do you want to always turn WaterMark on?", + "defaultValue": "1", + "scope": "plugin" + } +] \ No newline at end of file diff --git a/WaterMark/data/preferences.json b/WaterMark/data/preferences.json index daa581b5776ab0f4f1eb2549c819e47afdb4fefb..c99ee4834f117ff736e7cc4cf25508d0388f1cbb 100644 --- a/WaterMark/data/preferences.json +++ b/WaterMark/data/preferences.json @@ -14,262 +14,5 @@ "Sent", "Received" ] - }, - { - "category": "Set a logo image", - "type": "Switch", - "key": "showlogo", - "title": "Use a logo image", - "summary": "Do you want to display a logo image?", - "defaultValue": "1", - "scope": "plugin,Watermark" - }, - { - "category": "Set a logo image", - "type": "List", - "key": "logoposition", - "title": "WaterMark position", - "summary": "Where display the logo?", - "defaultValue": "3", - "scope": "plugin,Watermark", - "dependsOn": "showlogo", - "entryValues": [ - "1", - "2", - "3", - "4" - ], - "entries": [ - "TopRight", - "TopLeft", - "BottomLeft", - "BottomRight" - ] - }, - { - "category": "Set a logo image", - "type": "Path", - "key": "mark", - "title": "Choose a WaterMark logo image", - "summary": "Choose an image file", - "defaultValue": "data/defaultWM.png", - "scope": "plugin,Watermark", - "dependsOn": "showlogo", - "mimeType": "*/png,*/jpg,*/jpeg" - }, - { - "category": "Set a logo image", - "type": "List", - "key": "markbackground", - "title": "Add a background color", - "summary": "If you cannot see properly your logo, adding a background may be helpful", - "defaultValue": "black@0.0", - "scope": "plugin,Watermark", - "dependsOn": "showlogo", - "entryValues": [ - "black@0.0", - "black@0.5", - "white@0.5" - ], - "entries": [ - "None", - "Black", - "White" - ] - }, - { - "category": "Set a logo image", - "type": "List", - "key": "logosize", - "title": "Logo size", - "summary": "set a logo size", - "defaultValue": "0.1", - "scope": "plugin,Watermark", - "dependsOn": "showlogo", - "entryValues": [ - "0.1", - "0.15", - "0.2", - "0.25", - "0.4", - "0.6", - "0.8", - "1.0" - ], - "entries": [ - "10%", - "15%", - "20%", - "25%", - "40%", - "60%", - "80%", - "100%" - ] - }, - { - "category": "Set a text", - "type": "Switch", - "key": "showinfos", - "title": "Use informations", - "summary": "Do you want to display informations?", - "defaultValue": "1", - "scope": "plugin,Watermark" - }, - { - "category": "Set a text", - "type": "List", - "key": "infosposition", - "title": "Text position", - "summary": "Where display text?", - "defaultValue": "3", - "scope": "plugin,Watermark", - "dependsOn": "showinfos", - "entryValues": [ - "1", - "2", - "3", - "4" - ], - "entries": [ - "TopRight", - "TopLeft", - "BottomLeft", - "BottomRight" - ] - }, - { - "category": "Set a text", - "type": "EditText", - "key": "location", - "title": "Information to be displayed", - "summary": "Write any information you want to display, like city or project name", - "defaultValue": "", - "scope": "plugin,Watermark", - "dependsOn": "showinfos" - }, - { - "category": "Set a text", - "type": "Switch", - "key": "date", - "title": "Date", - "summary": "Do you want to display the date?", - "defaultValue": "1", - "scope": "plugin,Watermark", - "dependsOn": "showinfos" - }, - { - "category": "Set a text", - "type": "List", - "key": "dateformat", - "title": "Date format", - "summary": "Choose date format", - "defaultValue": "%x", - "scope": "plugin,Watermark", - "dependsOn": "showinfos", - "entryValues": [ - "%x", - "%a %Y/%m/%d", - "%a %m/%d/%Y", - "%a %d/%m/%Y", - "%Y/%m/%d", - "%m/%d/%Y", - "%d/%m/%Y", - "%b %d %Y", - "%d %b %Y " - ], - "entries": [ - "Language pattern", - "WeekDay YYYY/MM/DD", - "WeekDay MM/DD/YYYY", - "WeekDay DD/MM/YYYY", - "YYYY/MM/DD", - "MM/DD/YYYY", - "DD/MM/YYYY", - "Month DD YYYY", - "DD Month YYYY" - ] - }, - { - "category": "Set a text", - "type": "Switch", - "key": "time", - "title": "Time", - "summary": "Do you want to display the time?", - "defaultValue": "1", - "scope": "plugin,Watermark", - "dependsOn": "showinfos" - }, - { - "category": "Set a text", - "type": "List", - "key": "timeformat", - "title": "Time Format", - "summary": "Choose time format", - "defaultValue": "%X", - "scope": "plugin,Watermark", - "dependsOn": "showinfos", - "entryValues": [ - "%X", - "%R", - "%T", - "%I\\\\\\\\\\\\:%M %p", - "%r" - ], - "entries": [ - "Language pattern", - "HH:MM (24H)", - "HH:MM:SS (24H)", - "HH:MM (12H)", - "HH:MM:SS (12H)" - ] - }, - { - "category": "Set a text", - "type": "Switch", - "key": "timezone", - "title": "Time Zone", - "summary": "Display time zone?", - "defaultValue": "1", - "scope": "plugin,Watermark", - "dependsOn": "showinfos" - }, - { - "category": "Set a text", - "type": "List", - "key": "fontsize", - "title": "Font size", - "summary": "Choose font size", - "defaultValue": "14", - "scope": "plugin,Watermark", - "dependsOn": "showinfos", - "entryValues": [ - "10", - "12", - "14", - "16", - "18", - "24", - "36", - "72" - ], - "entries": [ - "10", - "12", - "14", - "16", - "18", - "24", - "36", - "72" - ] - }, - { - "type": "Switch", - "key": "WatermarkAlways", - "title": "Use WaterMark as default", - "summary": "Do you want to always turn WaterMark on?", - "defaultValue": "1", - "scope": "plugin" } ] \ No newline at end of file diff --git a/WaterMark/ffmpeg/rules.mak b/WaterMark/ffmpeg/rules.mak index a27dd9cbcec5a33e298c1fa25091aa63471ea7b9..b8735e8e616641e7d91d79dd799eb04c9d0b62c2 100644 --- a/WaterMark/ffmpeg/rules.mak +++ b/WaterMark/ffmpeg/rules.mak @@ -3,10 +3,6 @@ FFMPEG_URL := https://git.ffmpeg.org/gitweb/ffmpeg.git/snapshot/$(FFMPEG_HASH).t PKGS+=ffmpeg -ifeq ($(call need_pkg,"libavutil >= 55.75.100 libavcodec >= 57.106.101 libavformat >= 57.82.100 libavdevice >= 57.8.101 libavfilter >= 6.105.100 libswscale >= 4.7.103 libswresample >= 2.9.100"),) -PKGS_FOUND += ffmpeg -endif - ifdef HAVE_ANDROID DEPS_ffmpeg = iconv zlib vpx opus speex x264 freetype else diff --git a/WaterMark/main.cpp b/WaterMark/main.cpp index 7971c3ea0a650c2ed9b1dbdf9e46601563ca5ff3..b8113e3f63d19f9a395619fd073e1ddeb9ab98a1 100644 --- a/WaterMark/main.cpp +++ b/WaterMark/main.cpp @@ -25,6 +25,7 @@ #include <plugin/jamiplugin.h> #include "WatermarkMediaHandler.h" +#include "PluginPreferenceHandler.h" #ifdef WIN32 #define EXPORT_PLUGIN __declspec(dllexport) @@ -32,7 +33,7 @@ #define EXPORT_PLUGIN #endif -#define WaterMark_VERSION_MAJOR 1 +#define WaterMark_VERSION_MAJOR 2 #define WaterMark_VERSION_MINOR 0 #define WaterMark_VERSION_PATCH 0 @@ -51,21 +52,31 @@ JAMI_dynPluginInit(const JAMI_PluginAPI* api) std::cout << "Version " << WaterMark_VERSION_MAJOR << "." << WaterMark_VERSION_MINOR << "." << WaterMark_VERSION_PATCH << std::endl; - // If invokeService doesn't return an error if (api) { - std::map<std::string, std::string> preferences; - api->invokeService(api, "getPluginPreferences", &preferences); + if (api->version.api < JAMI_PLUGIN_API_VERSION) + return nullptr; + + std::map<std::string, std::map<std::string, std::string>> preferences; + api->invokeService(api, "getPluginAccPreferences", &preferences); std::string dataPath; api->invokeService(api, "getPluginDataPath", &dataPath); + auto fmpPluginPreferenceHandler + = std::make_unique<jami::PluginPreferenceHandler>(api, std::move(preferences), dataPath); auto fmpWatermarkMediaHandler - = std::make_unique<jami::WatermarkMediaHandler>(std::move(preferences), - std::move(dataPath)); + = std::make_unique<jami::WatermarkMediaHandler>(std::move(dataPath), + fmpPluginPreferenceHandler.get()); + fmpPluginPreferenceHandler->setWaterMarkHandler(fmpWatermarkMediaHandler.get()); if (api->manageComponent(api, "CallMediaHandlerManager", fmpWatermarkMediaHandler.release())) { return nullptr; } + if (api->manageComponent(api, + "PreferenceHandlerManager", + fmpPluginPreferenceHandler.release())) { + return nullptr; + } } return pluginExit; } diff --git a/WaterMark/manifest.json b/WaterMark/manifest.json index a512d1b9d82834f3f4fd11e1a312becb34bc5345..0dcca7942a81cda89a0a7e9f228e756138c21a62 100644 --- a/WaterMark/manifest.json +++ b/WaterMark/manifest.json @@ -1,5 +1,5 @@ { "name": "WaterMark", "description": "With this plugin you'll be able to add a water mark to a call video. This water mark is basically an image but can also contain location, day and time.", - "version": "1.0.0" + "version": "2.0.0" } \ No newline at end of file diff --git a/WaterMark/package.json b/WaterMark/package.json index 3d8de780135a8870c6707f3a20bb6436d9e50288..bd307508b41dcedc7b62946c41d9cb1588f3345d 100644 --- a/WaterMark/package.json +++ b/WaterMark/package.json @@ -1,10 +1,8 @@ { "name": "WaterMark", - "version": "1.0.0", + "version": "2.0.0", "extractLibs": false, - "deps": [ - "ffmpeg" - ], + "deps": [], "defines": [], "custom_scripts": { "pre_build": [