Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FreeBSD support #2508

Merged
merged 13 commits into from
Mar 25, 2021
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,30 @@ 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add some more descriptive description here too, as we do for MacOs. The pkg line should be "compacted" a bit too (like what we do above for yum and apt-get), as there's too many lines now I believe.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

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

sh autogen.sh
./configure
gmake
gmake install
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is there a gmake here? I don't think the lines from autogen.sh on are needed at all, as they're shared for all systems (they're not there for the MacOS instructions for instance).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gmake is for GNU make. BSDs has its own make


### 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
35 changes: 28 additions & 7 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ clang*)
-Wno-cast-align \
-Wno-initializer-overrides"
;;
cc*)
CFLAGS="$CFLAGS \
-Wno-cast-align \
-Wno-initializer-overrides"
;;
*)
# Specific gcc flags
CFLAGS="$CFLAGS \
Expand All @@ -68,7 +73,6 @@ clang*)
-Wunsafe-loop-optimizations \
-Wunused-but-set-variable"
esac

atoppi marked this conversation as resolved.
Show resolved Hide resolved
JANUS_VERSION=110
AC_SUBST(JANUS_VERSION)
JANUS_VERSION_STRING="0.10.10"
Expand All @@ -82,6 +86,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 -I/usr/local/lib/include/nice"
atoppi marked this conversation as resolved.
Show resolved Hide resolved
LDFLAGS="$LDFLAGS -Xlinker --export-dynamic"
LDFLAGS="$LDFLAGS -L/usr/lib/openssl -lcrypto -lssl -L/usr/local/lib -lnice"
AM_CONDITIONAL([DARWIN_OS], false)
;;
*)
LDFLAGS="$LDFLAGS -Wl,--export-dynamic"
AM_CONDITIONAL([DARWIN_OS], false)
Expand Down Expand Up @@ -335,18 +345,29 @@ AC_ARG_ENABLE([systemd-sockets],
[Enable Systemd Unix Sockets management])],
[],
[enable_systemd_sockets=no])

atoppi marked this conversation as resolved.
Show resolved Hide resolved
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"

atoppi marked this conversation as resolved.
Show resolved Hide resolved
esac
PKG_CHECK_MODULES([JANUS],"$PKGCHECKMODULES")


atoppi marked this conversation as resolved.
Show resolved Hide resolved
JANUS_MANUAL_LIBS="${JANUS_MANUAL_LIBS} -lm"
AC_SUBST(JANUS_MANUAL_LIBS)

Expand Down
1 change: 1 addition & 0 deletions janus.c
Original file line number Diff line number Diff line change
Expand Up @@ -5333,6 +5333,7 @@ gint main(int argc, char *argv[])
if (!transport) {
JANUS_LOG(LOG_ERR, "\tCouldn't load transport plugin '%s': %s\n", transportent->d_name, dlerror());
} else {
dlerror();//clear errors
atoppi marked this conversation as resolved.
Show resolved Hide resolved
create_t *create = (create_t*) dlsym(transport, "create");
const char *dlsym_error = dlerror();
if (dlsym_error) {
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: 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__)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have the same definition in pp-rtp.h, which is in the post-processor code. Have you checked if postprocessing MJR recordings does indeed work as expected on FreeBSD?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay, I could not find the docs to acutally do a test, but I did change pp-rtp.h

#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
31 changes: 21 additions & 10 deletions transports/janus_websockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ static const char *janus_websockets_reason_string(enum lws_callback_reasons reas
#if (LWS_LIBRARY_VERSION_MAJOR >= 4)
static lws_retry_bo_t pingpong = { 0 };
#endif

struct in_addr addr;
atoppi marked this conversation as resolved.
Show resolved Hide resolved
/* Helper method to return the interface associated with a local IP address */
static char *janus_websockets_get_interface_name(const char *ip) {
struct ifaddrs *addrs = NULL, *iap = NULL;
Expand Down Expand Up @@ -591,13 +591,6 @@ int janus_websockets_init(janus_transport_callbacks *callback, const char *confi
/* Force single-thread server */
wscinfo.count_threads = 1;

atoppi marked this conversation as resolved.
Show resolved Hide resolved
/* Create the base context */
wsc = lws_create_context(&wscinfo);
if(wsc == NULL) {
JANUS_LOG(LOG_ERR, "Error creating libwebsockets context...\n");
janus_config_destroy(config);
return -1; /* No point in keeping the plugin loaded */
}

/* Setup the Janus API WebSockets server(s) */
item = janus_config_get(config, config_general, janus_config_type_item, "ws");
Expand All @@ -618,12 +611,22 @@ 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;
if(inet_net_pton(AF_INET, ip, &addr, sizeof(addr))>0) {
atoppi marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code style: there should be spaces before and after the > comparator.
Besides, since the action is simple, I don't think it's needed to wrap it in curly brackets.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

wscinfo.options |= LWS_SERVER_OPTION_DISABLE_IPV6;
}
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);
}
ip = iface;
//ip = iface;
atoppi marked this conversation as resolved.
Show resolved Hide resolved
}
/* Create the base context */
wsc = lws_create_context(&wscinfo);
if(wsc == NULL) {
JANUS_LOG(LOG_ERR, "Error creating libwebsockets context...\n");
janus_config_destroy(config);
return -1; /* No point in keeping the plugin loaded */
}
/* Prepare context */
struct lws_context_creation_info info;
memset(&info, 0, sizeof info);
Expand Down Expand Up @@ -656,19 +659,24 @@ int janus_websockets_init(janus_transport_callbacks *callback, const char *confi
JANUS_LOG(LOG_ERR, "Invalid port (%s), falling back to default\n", item->value);
wsport = 8989;
}
int ipv4_only = 0;
char *interface = NULL;
item = janus_config_get(config, config_general, janus_config_type_item, "wss_interface");
if(item && item->value)
interface = (char *)item->value;
char *ip = NULL;
item = janus_config_get(config, config_general, janus_config_type_item, "wss_ip");

atoppi marked this conversation as resolved.
Show resolved Hide resolved
if(item && item->value) {
ip = (char *)item->value;
if(inet_net_pton(AF_INET, ip, &addr, sizeof(addr))>0) {
ipv4_only = 1;
}
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);
}
ip = iface;
//ip = iface;
}
item = janus_config_get(config, config_certs, janus_config_type_item, "cert_pem");
if(!item || !item->value) {
Expand Down Expand Up @@ -706,6 +714,9 @@ int janus_websockets_init(janus_transport_callbacks *callback, const char *confi
#else
info.options = 0;
#endif
if(ipv4_only) {
info.options |= LWS_SERVER_OPTION_DISABLE_IPV6;
}
/* Create the secure WebSocket context */
swss = lws_create_vhost(wsc, &info);
if(swss == NULL) {
Expand Down