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

14 KiB

NOTE: this page describes what is a Jami Plugin and how to install and use them.

Jami Plugins

As from September of 2020, Jami team has added plugins as a call feature for Linux, Windows, and Android users. 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!

  • To properly setup a plugin you must follow the steps in #How to use it?.
  • To build a available plugin, please refer to #How to build? instructions.
  • To create your own plugin, please refer to Create Plugin instructions.

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.

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.

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?

Setup

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. 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.

Android

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. After installed it is automaticaly loaded. Optionally, you can manually perform load/unload using the checkbox button on the plugin list.

androidInstall

For Android uninstall, you must click on the plugin and a uninstall option will appear allong with the preferences and a reset preferences option. In order to a preference modification can take effect the plugin has to be reloaded.

androidPrefs

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.

clientqtInstall clientqtPrefs

Use!

A plugins only takes place if you turn them on during a call. For either Android, Linux or Windows you can do so by clicking on the plugins icon on your call screen.

androidCall clienqtCall

How to build?

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

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

We kindly added OpenCV 4.1.1 as a contrib in daemon. This way you can easily build OpenCV for Android, Linux, and Windows. You only have to follow the corresponding instructions.

Windows
set DAEMON=<path/to/daemon>
cd ${DAEMON}/compat/msvc
python3 winmake.py -fb opencv
Linux

With Docker (recommended):

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:

export DAEMON=<path/to/daemon>
cd ${DAEMON}/contrib/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
Android

Using Docker (recommended):

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:

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}
cd native-${TARGET}
../bootstrap --build=x86_64-pc-linux-gnu --host=$TARGET$ANDROID_API --enable-opencv --enable-opencv_contrib
make

Tensorflow 2.1.0

A difficulty for a lot of people working with tensorflow is how to properly build it. With that in mind we created the docker files available for here and here. These docker can be used to build plugins for Linux and Android, however they cannot handle Windows. Here we carefully guide you through the proper build of tensorflow LITE Native and Tensorflow C++ API for our three supported platforms.

You will need:

  • Python 3

  • Bazel 0.29.1

  • Tensorflow 2.1.0 repository:

    git clone https://github.com/tensorflow/tensorflow.git
    cd tensorflow
    git checkout -b v2.1.0
    

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 README_ASSEMBLE file.

Linux

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:

Setup your build options with ./configure.

  • Tensorflow LITE Native

    bazel build //tensorflow/lite:libtensorflowlite.so
    
  • Tensorflow C++ API

    bazel build --config=v1 --define framework_shared_object=false --define=no_tensorflow_py_deps=true //tensorflow:libtensorflow_cc.so
    

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:

Setup your build options with python3 configure.py.

  • Tensorflow LITE Native

    bazel build //tensorflow/lite:tensorflowlite.dll
    
  • Tensorflow C++ API

    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 file with the desired symbols.

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

Setup your build options with:

./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

And build as desired:

  • armeabi-v7a

    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

    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

To exemplify a plugin build, we will use the GreenScreen plugin available here.

Windows

Windows build of plugins are linked with the daemon repository and its build scripts. So to build our example plugins you have to:

cd <ring-project>/daemon/compat/msvc
python3 winmake.py -fb GreenScreen

The GreenScreen.jpl file will be available under <ring-project/plugins/build/>.

Linux/Android

First you need to go to the plugins repository in your cloned ring-project:

cd <ring-project>/plugins
  • Linux - TF C++ API + GPU python3 build-plugin.py --projects=GreenScreen
  • Linux - TF C++ API + CPU python3 build-plugin.py --projects=GreenScreen --processor=CPU
  • Linux - TF LITE TF="_tensorflowLite" python3 build-plugin.py --projects=GreenScreen
  • Android ANDROID_ABI="arm64-v8a armeabi-v7a x86_64" python3 build-plugin.py --projects=GreenScreen --distribution=android

The GreenScreen.jpl file will be available under <ring-project/plugins/build/>.

Related articles: