jami-docs/technical/7.-Jami-plugins.md

279 lines
14 KiB
Markdown
Raw Normal View History

**NOTE: this page describes what is a Jami Plugin and how to install and use them.**
# Jami Plugins
2020-10-08 23:08:56 +08:00
As from September of 2020, Jami team has added plugins as a call feature for Linux, Windows, and Android users.
2020-07-20 20:45:41 +08:00
This meaning that now you can personalize your call experience by using one of our available plugins.
But that is not all, you can also transform your awesome ideas into a brand new plugin!
2020-10-14 00:08:17 +08:00
* To properly setup a plugin you must follow the steps in [#How to use it?](#how-to-use-it).
* To build a available plugin, please refer to [#How to build?](#how-to-build) instructions.
2020-11-07 02:00:29 +08:00
* To create your own plugin, please refer to [Create Plugin](http://git.jami.net/savoirfairelinux/ring-project/wikis/technical/Create_Plugin) instructions.
2020-07-18 04:11:57 +08:00
2020-07-20 21:41:33 +08:00
## How it works?
Jami can be break down to three main components that interact together: Daemon, LRC and clients.
Daemon is the core of Jami, and although it does not interact with users, it is involved in every
command. Therefore, Daemon has a `JamiPluginManager` class that among other actions perfoms install/uninstall, load/unload, edit preferences and control plugins' usage.
Despite Daemon importance, what a plugin effectivelly does to a call video is unknown to it the same way Daemon does not know what is effectivelly done by LRC or the clients interfaces.
Plugins then can be seen as a forth interacting component in Jami.
2020-07-18 04:11:57 +08:00
2020-10-08 23:08:56 +08:00
The plugin system inside Jami exposes different APIs that can be used by the plugins. For instance, the Media Handler API enables the plugins to modify audio and video streams from Jami calls. This API is used by our GreenScreen plugin but could also be used to build a YouTube streaming system, various instagram-style filters, a real time translation service, etc.
2020-07-20 21:41:33 +08:00
2020-10-08 23:08:56 +08:00
Plugins can be composed by one or multiple media handlers that are responsible for attaching/detaching a media stream from Jami and a data process. Each media handler represent a functionality that can be totally different between them or can be a modified versions of the same core process. In our example, we have only one functionality, it being, the GreenScreen plugin has one media handler wich data process is responsible for segmenting the foreground from a video frame and applying another image to the background, just like it is done with the green screens in movies!
To use one custom functionality, it is necessary that Jami knows all plugins' media handlers, wich one is going to be used and the data that should be processed. Plugin's media handlers are created once a plugin is loaded and are shared with Daemon's Plugin Manager. The data is inside Jami flow (for a call plugin, in the event of a new call, Jami creates and stores the corresponding media stream subjects). Finally, once a user puts a plugin functionality in action Jami tells this media handler to attach the available data. When deactivated, Jami tells the media handler to dettach.
## How to use it?
2020-07-18 04:11:57 +08:00
### Setup
2020-07-20 20:45:41 +08:00
A Jami plugin is a `pluginname.jpl` file, and it must be installed to your Jami.
Once installed, Jami will add your new plugin to the available plugins list but they will not be ready for use yet. Plugins are libraries and must be loaded if you want to expose them.
2020-10-08 23:08:56 +08:00
Moreover, plugin may have preferences and besides install/uninstall and load/unload actions, it is possible to modify those preferences. For example, our GreenScreen plugin allows the user to change the background image displayed.
2020-07-18 04:11:57 +08:00
#### Android
2020-07-20 20:45:41 +08:00
To setup a plugin for Android you must go under Setting, enable plugins if they are disabled, and select a plugin file from your phone.
2020-07-18 04:11:57 +08:00
After installed it is automaticaly loaded.
2020-07-20 20:45:41 +08:00
Optionally, you can manually perform load/unload using the checkbox button on the plugin list.
2020-10-08 23:25:23 +08:00
![androidInstall](uploads/e4d021a3fb82b603b1da34d5f47badc7/androidInstall.gif)
2020-07-20 20:45:41 +08:00
For Android uninstall, you must click on the plugin and a uninstall option will appear allong with the preferences and a reset preferences option.
2020-07-18 04:11:57 +08:00
In order to a preference modification can take effect the plugin has to be reloaded.
2020-10-08 23:25:23 +08:00
![androidPrefs](uploads/4c35a7b270064ca21228f063e12f97a2/androidPrefs.gif)
2020-10-08 23:08:56 +08:00
#### Linux/Windows
Similarly, for the client-qt available on Linux and Windows and for the client-gnome available only on Linux, you must go to Prefences, enable plugins if it is disabled, and select a plugins file from your computer.
Each plugin in the shown list is linked to two buttons beeing:
- Client-qt: a load/unload button and a preferences button;
- Client-gnome: a load/unload button and a uninstall button;
For client-gnome it is not possible to change plugin's preferences.
2020-10-08 23:25:23 +08:00
![clientqtInstall](uploads/bfb5d4bd9f03b427227465d08bd2f1d0/clientqtInstall.gif)
![clientqtPrefs](uploads/be8787b0f0a1424c423b976723a6f2ba/clientqtPrefs.gif)
### Use!
2020-07-20 20:45:41 +08:00
A plugins only takes place if you turn them on during a call.
2020-10-08 23:08:56 +08:00
For either Android, Linux or Windows you can do so by clicking on the plugins icon on your call screen.
2020-07-18 04:11:57 +08:00
2020-10-08 23:25:23 +08:00
![androidCall](uploads/8c36a7b5a3bb9e729e1b046ce0b32465/androidCall.gif)
![clienqtCall](uploads/34f4e5c4f04d80ab3a48072d3f470cfa/clienqtCall.gif)
## How to build?
2020-07-18 04:11:57 +08:00
If you want to make something with your video call, it is possible that you will do so with OpenCV and/or Tensorflow.
So, before going to the plugin, it is necessary to build plugin's dependencies.
### Dependencies
2020-07-18 04:11:57 +08:00
Here we give you the steps to build OpenCV and Tensorflow but do not feel limited to these libraries.
Other ones should work as long they and the plugin are correctly built!
#### OpenCV 4.1.1
2020-07-18 04:11:57 +08:00
We kindly added OpenCV 4.1.1 as a contrib in [daemon](https://git.jami.net/savoirfairelinux/ring-daemon/tree/master/contrib).
2020-10-08 23:08:56 +08:00
This way you can easily build OpenCV for Android, Linux, and Windows. You only have to follow the corresponding instructions.
##### Windows
```bash
set DAEMON=<path/to/daemon>
cd ${DAEMON}/compat/msvc
python3 winmake.py -fb opencv
```
2020-07-18 04:11:57 +08:00
##### Linux
2020-10-08 23:08:56 +08:00
With Docker (recommended):
```bash
export DAEMON=<path/to/daemon>
cd ${DAEMON}/../
docker build -f plugins/docker/Dockerfile_ubuntu_20.04 -t plugins-validation .
docker run --rm -it -v ${DAEMON}/../:/home/plugins/jami:rw plugins-validation:latest /bin/bash
cd jami/plugins/contrib
tar -xf libs.tar.gz
cd ../../daemon/contrib
mkdir native
cd native
../bootstrap --disable-argon2 --disable-asio --disable-fmt --disable-gcrypt --disable-gmp --disable-gnutls --disable-gpg-error --disable-gsm --disable-http_parser --disable-iconv --disable-jack --disable-jsoncpp --disable-libarchive --disable-libressl --disable-msgpack --disable-natpmp --disable-nettle --enable-opencv --disable-opendht --disable-pjproject --disable-portaudio --disable-restinio --disable-secp256k1 --disable-speexdsp --disable-upnp --disable-uuid --disable-yaml-cpp --disable-zlib
make list
make fetch opencv opencv_contrib
make
```
Using your own system:
2020-07-18 04:11:57 +08:00
```bash
2020-10-08 23:08:56 +08:00
export DAEMON=<path/to/daemon>
2020-07-18 04:11:57 +08:00
cd ${DAEMON}/contrib/native
2020-11-10 23:20:40 +08:00
../bootstrap --enable-ffmpeg --disable-argon2 --disable-asio --disable-fmt --disable-gcrypt --disable-gmp --disable-gnutls --disable-gpg-error --disable-gsm --disable-http_parser --disable-iconv --disable-jack --disable-jsoncpp --disable-libarchive --disable-libressl --disable-msgpack --disable-natpmp --disable-nettle --enable-opencv --disable-opendht --disable-pjproject --disable-portaudio --disable-restinio --disable-secp256k1 --disable-speexdsp --disable-upnp --disable-uuid --disable-yaml-cpp --disable-zlib
2020-10-08 23:08:56 +08:00
make list
make fetch opencv opencv_contrib
2020-07-18 04:11:57 +08:00
make
```
##### Android
2020-10-08 23:08:56 +08:00
Using Docker (recommended):
```bash
2020-10-08 23:08:56 +08:00
export DAEMON=<path/to/daemon>
cd ${DAEMON}/../
docker build -f plugins/docker/Dockerfile_android -t plugins-validation .
docker run --rm -it ${DAEMON}/:/home/gradle/src:rw plugins-validation:latest /bin/bash
cd plugins/contrib
tar -xf libs.tar.gz
ANDROID_ABI="arm64-v8a" sh build-dependencies.sh
```
Using your own system:
```bash
export DAEMON=<path/to/daemon>
cd ${DAEMON}
export ANDROID_NDK=<NDK>
export ANDROID_ABI=arm64-v8a
export ANDROID_API=29
export TOOLCHAIN=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64
export TARGET=aarch64-linux-android
export CC=$TOOLCHAIN/bin/$TARGET$ANDROID_API-clang
export CXX=$TOOLCHAIN/bin/$TARGET$ANDROID_API-clang++
export AR=$TOOLCHAIN/bin/$TARGET-ar
export LD=$TOOLCHAIN/bin/$TARGET-ld
export RANLIB=$TOOLCHAIN/bin/$TARGET-ranlib
export STRIP=$TOOLCHAIN/bin/$TARGET-strip
export PATH=$PATH:$TOOLCHAIN/bin
cd contrib
mkdir native-${TARGET}
2020-07-18 04:11:57 +08:00
cd native-${TARGET}
../bootstrap --build=x86_64-pc-linux-gnu --host=$TARGET$ANDROID_API --enable-opencv --enable-opencv_contrib
make
```
2020-07-18 04:11:57 +08:00
#### Tensorflow 2.1.0
2020-10-08 23:08:56 +08:00
A difficulty for a lot of people working with tensorflow is how to properly build it.
2020-11-07 01:24:55 +08:00
With that in mind we created docker images with cuda and tensorflow libraries available for GNU/Linux builds [here](https://hub.docker.com/repository/docker/sflagsantos/tensorflow-cuda) and for Android builds [here](https://hub.docker.com/repository/docker/sflagsantos/tensorflowlite). These docker can be used to build plugins for Linux and Android, however they cannot handle Windows.
2020-10-08 23:08:56 +08:00
Here we carefully guide you through the proper build of tensorflow LITE Native and Tensorflow C++ API for our three supported platforms.
2020-07-18 04:11:57 +08:00
You will need:
* Python 3
* Bazel 0.29.1
2020-07-18 04:11:57 +08:00
* Tensorflow 2.1.0 repository:
2020-07-18 04:11:57 +08:00
```bash
git clone https://github.com/tensorflow/tensorflow.git
cd tensorflow
2020-11-11 00:44:11 +08:00
git checkout v2.1.0
2020-07-18 04:11:57 +08:00
```
2020-10-08 23:08:56 +08:00
We assembled Tensorflow headers needed to build plugins, to access them you only have to extract `libs.tar.gz` file found under `jami-project/plugins/contrib`. However, if you are using another tensorflow version or you want to do it by yourself, you can follow the assemble instructions for Tensorflow LITE Native and C++ API are available under [jami-plugins](https://git.jami.net/savoirfairelinux/jami-plugins) README_ASSEMBLE file.
#### Linux
2020-07-18 04:11:57 +08:00
Tensorflow LITE does not support desktops GPU. If you want to use them, please consider using C++ API
If you want to build Tensorflow C++ API with GPU suport, be sure to have a CUDA capable GPU and that you have
followed all installation steps for the Nvidia drivers, CUDA Toolkit, CUDNN, Tensor RT, that their versions
matches and that they are correct for the Tensorflow version you want to build.
The following links may be very helpfull:
* https://www.tensorflow.org/install/source
* https://developer.nvidia.com/cuda-gpus
* https://developer.nvidia.com/cuda-toolkit-archive
* https://developer.nvidia.com/cudnn
2020-07-18 04:11:57 +08:00
Setup your build options with `./configure`.
2020-07-18 04:11:57 +08:00
* Tensorflow LITE Native
```bash
bazel build //tensorflow/lite:libtensorflowlite.so
```
* Tensorflow C++ API
```bash
2020-10-08 23:08:56 +08:00
bazel build --config=v1 --define framework_shared_object=false --define=no_tensorflow_py_deps=true //tensorflow:libtensorflow_cc.so
2020-07-18 04:11:57 +08:00
```
2020-10-08 23:08:56 +08:00
#### Windows
Tensorflow LITE does not support desktops GPU. If you want to use them, please consider using C++ API
If you want to build Tensorflow C++ API with GPU suport, be sure to have a CUDA capable GPU and that you have
followed all installation steps for the Nvidia drivers, CUDA Toolkit, CUDNN, Tensor RT, that their versions
matches and that they are correct for the Tensorflow version you want to build.
The following links may be very helpfull:
* https://www.tensorflow.org/install/source
* https://developer.nvidia.com/cuda-gpus
* https://developer.nvidia.com/cuda-toolkit-archive
* https://developer.nvidia.com/cudnn
Setup your build options with `python3 configure.py`.
* Tensorflow LITE Native
```bash
bazel build //tensorflow/lite:tensorflowlite.dll
```
* Tensorflow C++ API
```bash
bazel build --config=v1 --define framework_shared_object=false --config=cuda --define=no_tensorflow_py_deps=true //tensorflow:tensorflow_cc.dll
```
There may be some missign references while compilling a plugin with Tensorflow C++ API. If that happens you have to rebuild you tensorflow and explicitly export the missing symbols. Fortunatelly Tensorflow now has a easy workaround to do so, you only have to feed [this]("https://github.com/tensorflow/tensorflow/blob/v2.2.0/tensorflow/tools/def_file_filter/def_file_filter.py.tpl") file with the desired symbols.
2020-07-18 04:11:57 +08:00
#### Android - Tensorflow LITE Native
For mobile applications Tensorflow LITE is the only option you want to consider and to succesfully build it you will also need:
* Android NDK 18r
2020-07-18 04:11:57 +08:00
Setup your build options with:
```bash
./configure
>> Do you wish to build TensorFlow with XLA JIT support? [Y/n]: n
>> Do you wish to download a fresh release of clang? (Experimental) [y/N]: y
>> Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]: y
>> Please specify the home path of the Android NDK to use. [Default is /home/<username>/Android/Sdk/ndk-bundle]: put the right path to ndk 18r
```
2020-07-18 04:11:57 +08:00
And build as desired:
2020-07-18 04:11:57 +08:00
* armeabi-v7a
```bash
bazel build //tensorflow/lite:libtensorflowlite.so --crosstool_top=//external:android/crosstool --cpu=armeabi-v7a --host_crosstool_top=@bazel_tools//tools/cpp:toolchain --cxxopt="-std=c++11"
```
* arm64-v8a
```bash
bazel build //tensorflow/lite:libtensorflowlite.so --crosstool_top=//external:android/crosstool --cpu=arm64-v8a --host_crosstool_top=@bazel_tools//tools/cpp:toolchain --cxxopt="-std=c++11"
```
### Plugin
2020-10-08 23:08:56 +08:00
To exemplify a plugin build, we will use the GreenScreen plugin available [here](https://git.jami.net/savoirfairelinux/jami-plugins).
2020-07-18 04:11:57 +08:00
2020-10-08 23:08:56 +08:00
#### Windows
Windows build of plugins are linked with the daemon repository and its build scripts. So to build our example plugins you have to:
```bash
2020-10-08 23:08:56 +08:00
cd <ring-project>/daemon/compat/msvc
python3 winmake.py -fb GreenScreen
```
2020-10-08 23:08:56 +08:00
The GreenScreen.jpl file will be available under `<ring-project/plugins/build/>`.
2020-07-18 04:11:57 +08:00
2020-10-08 23:08:56 +08:00
#### Linux/Android
First you need to go to the plugins repository in your cloned ring-project:
2020-07-18 04:11:57 +08:00
2020-10-08 23:08:56 +08:00
```bash
cd <ring-project>/plugins
```
2020-07-18 04:11:57 +08:00
2020-10-08 23:08:56 +08:00
- Linux - TF C++ API + GPU
2020-10-09 01:42:43 +08:00
`python3 build-plugin.py --projects=GreenScreen`
2020-10-08 23:08:56 +08:00
- Linux - TF C++ API + CPU
2020-10-10 01:19:10 +08:00
`python3 build-plugin.py --projects=GreenScreen --processor=CPU`
2020-10-08 23:08:56 +08:00
- Linux - TF LITE
2020-10-10 01:19:10 +08:00
`TF="_tensorflowLite" python3 build-plugin.py --projects=GreenScreen`
2020-10-08 23:08:56 +08:00
- Android
2020-10-10 01:19:10 +08:00
`ANDROID_ABI="arm64-v8a armeabi-v7a x86_64" python3 build-plugin.py --projects=GreenScreen --distribution=android`
2020-07-18 04:11:57 +08:00
2020-10-08 23:08:56 +08:00
The GreenScreen.jpl file will be available under `<ring-project/plugins/build/>`.
2020-07-18 04:11:57 +08:00
Related articles:
2020-07-18 04:11:57 +08:00
- [ ] https://jami.net/jami-plugins-foreground-segmentation-artificial-inteligence/