openwebrtc icon indicating copy to clipboard operation
openwebrtc copied to clipboard

Java bindings for Linux

Open scttnlsn opened this issue 10 years ago • 15 comments

I noticed you don't provide binary releases for this use case but is there any reason why the Java bindings can't be used on Linux or Mac OS X?

scttnlsn avatar Sep 27 '15 17:09 scttnlsn

The bridge (openwebrtc-daemon + user script to inject some JS into a browser page) can be built and used on Linux.

The only reason there are no binaries for Linux in the 0.3.0 release was because we didn't get to it. We will with the next release and perhaps RPi binaries too.

We don't have any Java bindings though unless they exist for GObject Introspection.

superdump avatar Sep 27 '15 20:09 superdump

I was referring to these Java bindings: https://github.com/EricssonResearch/openwebrtc-examples/blob/master/android/Native/app/src/main/java/com/ericsson/research/owr/examples/natiev/NativeExampleActivity.java#L37-L42 but perhaps I'm misunderstanding something. Are these Java libraries enough to build a WebRTC peer?

scttnlsn avatar Sep 27 '15 21:09 scttnlsn

:+1: I also do not really get the answer. I think what we are looking for is a possibility to participate in a WebRTC peer connection from an arbitrary jvm process. :confused:

danielwegener avatar Nov 14 '15 01:11 danielwegener

@Rugvip : could the Android Java bindings be used on other platforms?

superdump avatar Nov 14 '15 08:11 superdump

Yep. There are some Android specific bits at the moment though, like https://github.com/EricssonResearch/openwebrtc/blob/b05d861b2dca146180ed01ab5ea3a753b18c3eb3/bindings/java/gen_jni.py#L121, and https://github.com/EricssonResearch/openwebrtc/blob/9118464b65465343ac38160a32aa0e449b96597a/bindings/java/c_generator.py#L685

Afaik the main think to solve is how to get a window handle for video rendering, that might requires changes to owr/gst.

Rugvip avatar Nov 14 '15 11:11 Rugvip

I actually could need some help here (disclaimer: I do not really now what I am doing) :) I do not really care about audio/video stuff because I just need the DataChannels. I'd preferrably create a static linked version of openwebrtc that can be bundled into a jar-with-natives.

So what I tried so far:

  • following the build instructions https://github.com/EricssonResearch/openwebrtc/wiki/Building-OpenWebRTC up to step ./cerbero-uninstalled -c config/linux.cbc bootstrap
  • applying the following patch to cerbero
Index: recipes/openwebrtc.recipe
<+>UTF-8
===================================================================
--- recipes/openwebrtc.recipe   (revision 8bc45a5452515c956090f0f9d1007bb57234b6c4)
+++ recipes/openwebrtc.recipe   (revision )
@@ -149,6 +149,7 @@
                     'lib/jni/openwebrtc_bridge-javadoc.jar',
                 ]
         elif self.config.target_platform in (Platform.DARWIN, Platform.LINUX):
+            self.configure_options += ' --enable-owr-java'
             self.configure_options += ' --enable-gtk-doc --disable-static \
                 --disable-owr-static --enable-shared --enable-tests'
             if self.config.target_platform == Platform.LINUX:
Index: config/linux.config
<+>UTF-8
===================================================================
--- config/linux.config (revision 8bc45a5452515c956090f0f9d1007bb57234b6c4)
+++ config/linux.config (revision )
@@ -26,6 +26,8 @@
     variants.append('gtk3')
 if 'nogi' not in variants:
     variants.append('gi')
+if 'owr_bridge' not in variants:
+    variants.append('owr_bridge')

 for f in ['CPPFLAGS', 'CFLAGS', 'CCASFLAGS', 'CXXFLAGS', 'LDFLAGS',
           'OBJCFLAGS']:

(Just by applying the patch to config/linux.config and building then, the extracted (dpkg-deb -x openwebrtc-openwebrtc-base_0.3.0-1_amd64.deb openwebrtc-openwebrtc-base_0.3.0-1_amd64) contains a ~/cerbero/openwebrtc-openwebrtc-base_0.3.0-1_amd64/opt/openwebrtc-0.3/lib/libopenwebrtc_bridge.so.0 which is good)

  • applying the following patch to openwebrtc (in the fetched source folder)
Index: configure.ac
<+>UTF-8
===================================================================
--- configure.ac    (revision 736aa5ac0deb562aa4add1608ad91fdad6cce75f)
+++ configure.ac    (revision )
@@ -196,9 +196,6 @@
 esac],[enable_owr_java=no])
 AC_MSG_RESULT([$enable_owr_java])
 if test "x$enable_owr_java" = xyes; then
-  if test "x$is_android" != xyes; then
-    AC_MSG_ERROR([--enable-owr-java is only valid when building for Android])
-  fi
   if test "x$enable_shared" != xyes; then
     AC_MSG_ERROR([--enable-owr-java needs --enabled-shared])
   fi
@@ -242,7 +239,7 @@
             AS_HELP_STRING([--with-android-sdk],
                            [path to the Android SDK]),
             androidsdkdir=${withval}, androidsdkdir=)
-if test "x$enable_owr_java" = xyes; then
+if test "x$is_android" = xyes; then
   AC_MSG_CHECKING([for android.jar])
   if test "x$androidsdkdir" = x; then
     AC_MSG_ERROR([Need path to the Android SDK when building Android bindings])
  • running ./cerbero-uninstalled -c config/linux.cbc package -f openwebrtc stops at the following error. I see that the jni java files are now created (and I could try to continue from this point by putting together my own jar with natives) but I'd like to have a reproducible build process to regenerate a proper bindings jar.
...
Making all in bindings
make[2]: Entering directory `/home/daniel/cerbero/sources/linux_x86_64/openwebrtc-0.3.0/bindings'
Making all in java
make[3]: Entering directory `/home/daniel/cerbero/sources/linux_x86_64/openwebrtc-0.3.0/bindings/java'
PYTHONDONTWRITEBYTECODE=1 ../../bindings/java/gen_jni.py \
    --gir=../../owr/Owr-0.3.gir \
    --c-out=../../bindings/java/owr_jni.c \
    --j-out=../../bindings/java/owr
reading from gir file "../../owr/Owr-0.3.gir"
saving generated C source to "../../bindings/java/owr_jni.c"
saving generated Java source in "../../bindings/java/owr"
-------- BEGIN ---------
--------  END  ---------
make  all-am
make[4]: Entering directory `/home/daniel/cerbero/sources/linux_x86_64/openwebrtc-0.3.0/bindings/java'
/bin/bash ../../libtool  --tag=CC   --mode=compile gcc -std=gnu99 -DHAVE_CONFIG_H -I. -I../..  -pthread -I/opt/openwebrtc-0.3/include/glib-2.0 -I/opt/openwebrtc-0.3/lib/glib-2.0/include  -I/include -I../../owr -I../../bridge -I../../transport -I../../local  -Wall -Wextra "-g" -Wall -g -O2 -m64  -Wall -g -O2 -m64  -MT owr_jni.lo -MD -MP -MF .deps/owr_jni.Tpo -c -o owr_jni.lo owr_jni.c
libtool: compile:  gcc -std=gnu99 -DHAVE_CONFIG_H -I. -I../.. -pthread -I/opt/openwebrtc-0.3/include/glib-2.0 -I/opt/openwebrtc-0.3/lib/glib-2.0/include -I/include -I../../owr -I../../bridge -I../../transport -I../../local -Wall -Wextra -g -Wall -g -O2 -m64 -Wall -g -O2 -m64 -MT owr_jni.lo -MD -MP -MF .deps/owr_jni.Tpo -c owr_jni.c  -fPIC -DPIC -o .libs/owr_jni.o
owr_jni.c:1:17: fatal error: jni.h: No such file or directory
 #include <jni.h>
                 ^
compilation terminated.
make[4]: *** [owr_jni.lo] Error 1
make[4]: Leaving directory `/home/daniel/cerbero/sources/linux_x86_64/openwebrtc-0.3.0/bindings/java'
make[3]: *** [all] Error 2
make[3]: Leaving directory `/home/daniel/cerbero/sources/linux_x86_64/openwebrtc-0.3.0/bindings/java'
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory `/home/daniel/cerbero/sources/linux_x86_64/openwebrtc-0.3.0/bindings'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/daniel/cerbero/sources/linux_x86_64/openwebrtc-0.3.0'
make: *** [all] Error 2

Does someone know whats happening here?

danielwegener avatar Nov 15 '15 14:11 danielwegener

The build currently uses the Android NDK for Java headers and libs. To build for other targets you will need to use an appropriate JDK.

Rugvip avatar Nov 15 '15 18:11 Rugvip

Cheers, found it in openwebrtc/bindings/java/Makefile.am. I'll dig further :)

danielwegener avatar Nov 15 '15 18:11 danielwegener

Made it. Documented my findings in https://github.com/danielwegener/openwebrtc-java/blob/master/README.md (still need to double-check the diffs in openwebrtc and cerbero fork). This repo also contains a java maven project that demonstrates the basic functionality in junit tests.

Ideally the openwebrtc java build would create a:

  • openwebrtc-VERSION.jar with the generated java classes
  • openwebrtc-natives-VERSION-OS-ARC.jar with all required so libraries

with all required native libraries (like the android build) so they could directly used as maven dependency without further installation of os packages. In a later step, these artifacts also could be released for mac.

danielwegener avatar Nov 20 '15 09:11 danielwegener

Really great work! Looking forward to seeing this integrated in OpenWebRTC so that others can easily pick it up. Thanks.

stefanalund avatar Nov 20 '15 12:11 stefanalund

For anyone interested, I continue the work of @danielwegener here: https://github.com/udevbe/openwebrtc-java

I rebased his changes on the latest openwebrtc master and applied some fixes myself as current upstream is broken in quite some places...

Ideally we should not need to rely on cerbero to build the java bindings. Theoretically at least, we should/could create a separate java bindings project/module/subproject that can link against a vanilla openwebrtc build (eg using cmake).

Alternatively we can use something like jaccall (or jna) and don't need to (cross) compile any native code! That's probably what I will end up doing unless upstream is interested in maintaining a (non android) java bindings (sub)project.

Zubnix avatar Feb 10 '17 21:02 Zubnix

currently java bindings fail because of #648 :(

Zubnix avatar Feb 11 '17 22:02 Zubnix

Java bindings succeed now with a proper fix.

Zubnix avatar Feb 17 '17 14:02 Zubnix

I've created a demo app that people can run as-is without needing to tweak their system. https://github.com/Zubnix/openwebrtc-java-poc

Zubnix avatar Feb 22 '17 13:02 Zubnix

I've updated the above example. It now runs a client-server setup where the server pushes a message over a datachannel to the connected browser. I figured this is a functionality a lot of people are looking for.

I modified the openwebrtc android sdk to make it run on desktop java.

Zubnix avatar Mar 07 '17 15:03 Zubnix