Skip to content

Commit

Permalink
FreeBSD support (#2508)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsm222 committed Mar 25, 2021
1 parent e935cdc commit 7c9d522
Show file tree
Hide file tree
Showing 19 changed files with 114 additions and 20 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,17 @@ If Doxygen and graphviz are available, the process can also build the documentat

You can also selectively enable/disable other features (e.g., specific plugins you don't care about, or whether or not you want to build the recordings post-processor). Use the --help option when configuring for more info.

### Building on FreeBSD
* *Note*: rtp_forward of streams only works streaming to IPv6,
because of #2051 and thus the feature is not supported on FreeBSD at the moment.

When building on FreeBSD you can install the depencencies from ports or packages, here only pkg method is used. You also need to use `gmake` instead of `make`,
since it is a GNU makefile. `./configure` can be run without arguments since the default prefix is `/usr/local` which is your default `LOCALBASE`.
Note that the `configure.ac` is coded to use openssl in base. If you wish to use openssl from ports or any other ssl you must change `configure.ac` accordingly.

pkg install libsrtp2 libusrsctp jansson libnice libmicrohttpd libwebsockets curl opus sofia-sip libogg jansson libnice libconfig \
libtool gmake autoconf autoconf-wrapper glib gengetopt


### Building on MacOS
While most of the above instructions will work when compiling Janus on MacOS as well, there are a few aspects to highlight when doing that.
Expand Down
31 changes: 26 additions & 5 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ clang*)
-Wno-cast-align \
-Wno-initializer-overrides"
;;
cc*)
CFLAGS="$CFLAGS \
-Wno-cast-align \
-Wno-initializer-overrides"
;;
*)
# Specific gcc flags
CFLAGS="$CFLAGS \
Expand All @@ -83,6 +88,12 @@ darwin*)
LDFLAGS="$LDFLAGS -L/usr/local/lib -L/usr/local/opt/openssl/lib -L/opt/local/lib -L/usr/local/libsrtp/lib"
AM_CONDITIONAL([DARWIN_OS], true)
;;
freebsd*)
CFLAGS="$CFLAGS -I/usr/include/openssl"
LDFLAGS="$LDFLAGS -Xlinker --export-dynamic"
LDFLAGS="$LDFLAGS -L/usr/lib/openssl -lcrypto -lssl -L/usr/local/lib"
AM_CONDITIONAL([DARWIN_OS], false)
;;
*)
LDFLAGS="$LDFLAGS -Wl,--export-dynamic"
AM_CONDITIONAL([DARWIN_OS], false)
Expand Down Expand Up @@ -337,17 +348,27 @@ AC_ARG_ENABLE([systemd-sockets],
[],
[enable_systemd_sockets=no])

PKG_CHECK_MODULES([JANUS],
[
glib-2.0 >= $glib_version
case "$host_os" in
freebsd*)
PKGCHECKMODULES="glib-2.0 >= $glib_version
gio-2.0 >= $glib_version
libconfig
nice
jansson >= $jansson_version
zlib"
;;
*)
PKGCHECKMODULES="glib-2.0 >= $glib_version
gio-2.0 >= $glib_version
libconfig
nice
jansson >= $jansson_version
libssl >= $ssl_version
libcrypto
zlib
])
zlib"
esac
PKG_CHECK_MODULES([JANUS],"$PKGCHECKMODULES")

JANUS_MANUAL_LIBS="${JANUS_MANUAL_LIBS} -lm"
AC_SUBST(JANUS_MANUAL_LIBS)

Expand Down
4 changes: 4 additions & 0 deletions plugins/janus_audiobridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,10 @@ room-<unique room ID>: {
*/

#include "plugin.h"
#ifdef __FreeBSD__
#include <sys/socket.h>
#include <netinet/in.h>
#endif

#include <jansson.h>
#include <opus/opus.h>
Expand Down
2 changes: 1 addition & 1 deletion postprocessing/janus-pp-rec.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Usage: janus-pp-rec [OPTIONS] source.mjr [destination.[opus|wav|webm|mp4|srt]]
*/

#include <arpa/inet.h>
#ifdef __MACH__
#if defined(__MACH__) || defined(__FreeBSD__)
#include <machine/endian.h>
#else
#include <endian.h>
Expand Down
2 changes: 1 addition & 1 deletion postprocessing/mjr2pcap.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/

#include <arpa/inet.h>
#ifdef __MACH__
#if defined(__MACH__) || defined(__FreeBSD__)
#include <machine/endian.h>
#else
#include <endian.h>
Expand Down
2 changes: 1 addition & 1 deletion postprocessing/pp-av1.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/

#include <arpa/inet.h>
#ifdef __MACH__
#if defined(__MACH__) || defined(__FreeBSD__)
#include <machine/endian.h>
#else
#include <endian.h>
Expand Down
2 changes: 1 addition & 1 deletion postprocessing/pp-binary.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/

#include <arpa/inet.h>
#ifdef __MACH__
#if defined(__MACH__) || defined(__FreeBSD__)
#include <machine/endian.h>
#else
#include <endian.h>
Expand Down
2 changes: 1 addition & 1 deletion postprocessing/pp-g711.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/

#include <arpa/inet.h>
#ifdef __MACH__
#if defined(__MACH__) || defined(__FreeBSD__)
#include <machine/endian.h>
#else
#include <endian.h>
Expand Down
2 changes: 1 addition & 1 deletion postprocessing/pp-g722.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/

#include <arpa/inet.h>
#ifdef __MACH__
#if defined (__MACH__) || defined(__FreeBSD__)
#include <machine/endian.h>
#else
#include <endian.h>
Expand Down
2 changes: 1 addition & 1 deletion postprocessing/pp-h264.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/

#include <arpa/inet.h>
#ifdef __MACH__
#if defined(__MACH__) || defined(__FreeBSD__)
#include <machine/endian.h>
#else
#include <endian.h>
Expand Down
2 changes: 1 addition & 1 deletion postprocessing/pp-h265.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/

#include <arpa/inet.h>
#ifdef __MACH__
#if defined(__MACH__) || defined(__FreeBSD__)
#include <machine/endian.h>
#else
#include <endian.h>
Expand Down
2 changes: 1 addition & 1 deletion postprocessing/pp-opus.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/

#include <arpa/inet.h>
#ifdef __MACH__
#if defined(__MACH__) || defined(__FreeBSD__)
#include <machine/endian.h>
#else
#include <endian.h>
Expand Down
2 changes: 1 addition & 1 deletion postprocessing/pp-rtp.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#ifndef JANUS_PP_RTP
#define JANUS_PP_RTP

#ifdef __MACH__
#if defined(__MACH__) || defined(__FreeBSD__)
#include <machine/endian.h>
#define __BYTE_ORDER BYTE_ORDER
#define __BIG_ENDIAN BIG_ENDIAN
Expand Down
2 changes: 1 addition & 1 deletion postprocessing/pp-srt.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/

#include <arpa/inet.h>
#ifdef __MACH__
#if defined(__MACH__) || defined(__FreeBSD__)
#include <machine/endian.h>
#else
#include <endian.h>
Expand Down
2 changes: 1 addition & 1 deletion postprocessing/pp-webm.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/

#include <arpa/inet.h>
#ifdef __MACH__
#if defined(__MACH__) || defined(__FreeBSD__)
#include <machine/endian.h>
#else
#include <endian.h>
Expand Down
2 changes: 2 additions & 0 deletions rtcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include <arpa/inet.h>
#ifdef __MACH__
#include <machine/endian.h>
#elif defined(__FreeBSD__)
#include <sys/endian.h>
#else
#include <endian.h>
#endif
Expand Down
2 changes: 1 addition & 1 deletion rtp.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#define JANUS_RTP_H

#include <arpa/inet.h>
#ifdef __MACH__
#if defined (__MACH__) || defined(__FreeBSD__)
#include <machine/endian.h>
#define __BYTE_ORDER BYTE_ORDER
#define __BIG_ENDIAN BIG_ENDIAN
Expand Down
5 changes: 5 additions & 0 deletions text2pcap.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
#define __BYTE_ORDER BYTE_ORDER
#define __BIG_ENDIAN BIG_ENDIAN
#define __LITTLE_ENDIAN LITTLE_ENDIAN
#elif defined(__FreeBSD__)
#include <sys/endian.h>
#define __BYTE_ORDER BYTE_ORDER
#define __BIG_ENDIAN BIG_ENDIAN
#define __LITTLE_ENDIAN LITTLE_ENDIAN
#else
#include <endian.h>
#endif
Expand Down
55 changes: 53 additions & 2 deletions transports/janus_websockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,9 @@ int janus_websockets_init(janus_transport_callbacks *callback, const char *confi
JANUS_LOG(LOG_WARN, "libwebsockets has been built without IPv6 support, will bind to IPv4 only\n");
#endif

#ifdef __FreeBSD__
int ipv4_only = 0;
#endif
/* This is the callback we'll need to invoke to contact the Janus core */
gateway = callback;

Expand Down Expand Up @@ -618,6 +621,11 @@ int janus_websockets_init(janus_transport_callbacks *callback, const char *confi
item = janus_config_get(config, config_general, janus_config_type_item, "ws_ip");
if(item && item->value) {
ip = (char *)item->value;
#ifdef __FreeBSD__
struct in_addr addr;
if(inet_net_pton(AF_INET, ip, &addr, sizeof(addr)) > 0)
ipv4_only = 1;
#endif
char *iface = janus_websockets_get_interface_name(ip);
if(iface == NULL) {
JANUS_LOG(LOG_WARN, "No interface associated with %s? Falling back to no interface...\n", ip);
Expand All @@ -636,8 +644,16 @@ int janus_websockets_init(janus_transport_callbacks *callback, const char *confi
info.ssl_private_key_password = NULL;
info.gid = -1;
info.uid = -1;
info.options = 0;
#ifdef __FreeBSD__
if (ipv4_only) {
info.options |= LWS_SERVER_OPTION_DISABLE_IPV6;
ipv4_only = 0;
}
#endif
#if (LWS_LIBRARY_VERSION_MAJOR == 3 && LWS_LIBRARY_VERSION_MINOR >= 2) || (LWS_LIBRARY_VERSION_MAJOR > 3)
info.options = LWS_SERVER_OPTION_FAIL_UPON_UNABLE_TO_BIND;
info.options |= LWS_SERVER_OPTION_FAIL_UPON_UNABLE_TO_BIND;

#endif
/* Create the WebSocket context */
wss = lws_create_vhost(wsc, &info);
Expand Down Expand Up @@ -666,6 +682,11 @@ int janus_websockets_init(janus_transport_callbacks *callback, const char *confi
item = janus_config_get(config, config_general, janus_config_type_item, "wss_ip");
if(item && item->value) {
ip = (char *)item->value;
#ifdef __FreeBSD__
struct in_addr addr;
if(inet_net_pton(AF_INET, ip, &addr, sizeof(addr)) > 0)
ipv4_only = 1;
#endif
char *iface = janus_websockets_get_interface_name(ip);
if(iface == NULL) {
JANUS_LOG(LOG_WARN, "No interface associated with %s? Falling back to no interface...\n", ip);
Expand Down Expand Up @@ -707,6 +728,12 @@ int janus_websockets_init(janus_transport_callbacks *callback, const char *confi
info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT | LWS_SERVER_OPTION_FAIL_UPON_UNABLE_TO_BIND;
#elif LWS_LIBRARY_VERSION_MAJOR >= 2
info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT;
#endif
#ifdef __FreeBSD__
if(ipv4_only) {
info.options |= LWS_SERVER_OPTION_DISABLE_IPV6;
ipv4_only = 0;
}
#endif
/* Create the secure WebSocket context */
swss = lws_create_vhost(wsc, &info);
Expand Down Expand Up @@ -737,6 +764,11 @@ int janus_websockets_init(janus_transport_callbacks *callback, const char *confi
item = janus_config_get(config, config_admin, janus_config_type_item, "admin_ws_ip");
if(item && item->value) {
ip = (char *)item->value;
#ifdef __FreeBSD__
struct in_addr addr;
if(inet_net_pton(AF_INET, ip, &addr, sizeof(addr)) > 0)
ipv4_only = 1;
#endif
char *iface = janus_websockets_get_interface_name(ip);
if(iface == NULL) {
JANUS_LOG(LOG_WARN, "No interface associated with %s? Falling back to no interface...\n", ip);
Expand All @@ -755,8 +787,16 @@ int janus_websockets_init(janus_transport_callbacks *callback, const char *confi
info.ssl_private_key_password = NULL;
info.gid = -1;
info.uid = -1;
info.options = 0;
#ifdef __FreeBSD__
if (ipv4_only) {
info.options |= LWS_SERVER_OPTION_DISABLE_IPV6;
ipv4_only = 0;
}
#endif
#if (LWS_LIBRARY_VERSION_MAJOR == 3 && LWS_LIBRARY_VERSION_MINOR >= 2) || (LWS_LIBRARY_VERSION_MAJOR > 3)
info.options = LWS_SERVER_OPTION_FAIL_UPON_UNABLE_TO_BIND;
info.options |= LWS_SERVER_OPTION_FAIL_UPON_UNABLE_TO_BIND;

#endif
/* Create the WebSocket context */
admin_wss = lws_create_vhost(wsc, &info);
Expand Down Expand Up @@ -785,6 +825,11 @@ int janus_websockets_init(janus_transport_callbacks *callback, const char *confi
item = janus_config_get(config, config_admin, janus_config_type_item, "admin_wss_ip");
if(item && item->value) {
ip = (char *)item->value;
#ifdef __FreeBSD__
struct in_addr addr;
if(inet_net_pton(AF_INET, ip, &addr, sizeof(addr)) > 0)
ipv4_only = 1;
#endif
char *iface = janus_websockets_get_interface_name(ip);
if(iface == NULL) {
JANUS_LOG(LOG_WARN, "No interface associated with %s? Falling back to no interface...\n", ip);
Expand Down Expand Up @@ -826,6 +871,12 @@ int janus_websockets_init(janus_transport_callbacks *callback, const char *confi
info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT | LWS_SERVER_OPTION_FAIL_UPON_UNABLE_TO_BIND;
#elif LWS_LIBRARY_VERSION_MAJOR >= 2
info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT;
#endif
#ifdef __FreeBSD__
if (ipv4_only) {
info.options |= LWS_SERVER_OPTION_DISABLE_IPV6;
ipv4_only = 0;
}
#endif
/* Create the secure WebSocket context */
admin_swss = lws_create_vhost(wsc, &info);
Expand Down

0 comments on commit 7c9d522

Please sign in to comment.