Skip to content

Commit

Permalink
Merge pull request #125 from yultide/master
Browse files Browse the repository at this point in the history
Janus build fixes for OSX
  • Loading branch information
lminiero committed Jan 27, 2015
2 parents 5236fc7 + b1c60d3 commit 33b7583
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ docs/html/

Makefile
Makefile.in
/build
/configure
/autom4te.cache
/aclocal.m4
Expand Down
9 changes: 2 additions & 7 deletions Makefile.am
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
ACLOCAL_AMFLAGS = -I m4

# FIXME: These flags should be produced in configure.ac using AX_APPEND_COMPILE_FLAGS
AM_CFLAGS = \
-Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations \
Expand Down Expand Up @@ -123,13 +125,6 @@ plugins_libadd = \
$(PLUGINS_LIBS) \
$(NULL)

plugins_ldflags = \
-export-dynamic \
-no-undefined \
-avoid-version \
-module \
$(NULL)

if ENABLE_PLUGIN_AUDIOBRIDGE
plugin_LTLIBRARIES += plugins/libjanus_audiobridge.la
plugins_libjanus_audiobridge_la_SOURCES = plugins/janus_audiobridge.c
Expand Down
11 changes: 11 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ AC_PROG_CC
LT_PREREQ([2.2])
LT_INIT

case "$host_os" in
darwin*)
LDFLAGS="$LDFLAGS -L/usr/local/lib -L/usr/local/opt/openssl/lib"
AM_CONDITIONAL([DARWIN_OS], true)
AM_CONDITIONAL([HAS_DTLS_WINDOW_SIZE], false)
;;
*)
AM_CONDITIONAL([DARWIN_OS], false)
AM_CONDITIONAL([HAS_DTLS_WINDOW_SIZE], true)
esac

glib_version=2.32
ssl_version=1.0.1

Expand Down
4 changes: 4 additions & 0 deletions dtls.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,10 @@ void janus_dtls_srtp_incoming_msg(janus_dtls_srtp *dtls, char *buf, uint16_t len
dtls->remote_policy.key = (unsigned char *)&remote_policy_key;
memcpy(dtls->remote_policy.key, remote_key, SRTP_MASTER_KEY_LENGTH);
memcpy(dtls->remote_policy.key + SRTP_MASTER_KEY_LENGTH, remote_salt, SRTP_MASTER_SALT_LENGTH);
#if HAS_DTLS_WINDOW_SIZE
dtls->remote_policy.window_size = 128;
dtls->remote_policy.allow_repeat_tx = 0;
#endif
dtls->remote_policy.next = NULL;
/* Local (outbound) */
crypto_policy_set_rtp_default(&(dtls->local_policy.rtp));
Expand All @@ -415,8 +417,10 @@ void janus_dtls_srtp_incoming_msg(janus_dtls_srtp *dtls, char *buf, uint16_t len
dtls->local_policy.key = (unsigned char *)&local_policy_key;
memcpy(dtls->local_policy.key, local_key, SRTP_MASTER_KEY_LENGTH);
memcpy(dtls->local_policy.key + SRTP_MASTER_KEY_LENGTH, local_salt, SRTP_MASTER_SALT_LENGTH);
#if HAS_DTLS_WINDOW_SIZE
dtls->local_policy.window_size = 128;
dtls->local_policy.allow_repeat_tx = 0;
#endif
dtls->local_policy.next = NULL;
/* Create SRTP sessions */
err_status_t res = srtp_create(&(dtls->srtp_in), &(dtls->remote_policy));
Expand Down
8 changes: 7 additions & 1 deletion janus.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
#define JANUS_VERSION 7
#define JANUS_VERSION_STRING "0.0.7"

#ifdef __MACH__
#define SHLIB_EXT "0.dylib"
#else
#define SHLIB_EXT ".so"
#endif


static janus_config *config = NULL;
static char *config_file = NULL;
Expand Down Expand Up @@ -3997,7 +4003,7 @@ gint main(int argc, char *argv[])
if (len < 4) {
continue;
}
if (strcasecmp(pluginent->d_name+len-3, ".so")) {
if (strcasecmp(pluginent->d_name+len-strlen(SHLIB_EXT), SHLIB_EXT)) {
continue;
}
JANUS_LOG(LOG_INFO, "Loading plugin '%s'...\n", pluginent->d_name);
Expand Down
69 changes: 69 additions & 0 deletions mach_gettime.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#ifndef MACH_GETTIME_H
#define MACH_GETTIME_H

#include <sys/types.h>
#include <sys/_types/_timespec.h>
#include <mach/mach.h>
#include <mach/clock.h>
#include <mach/mach_time.h>

/* The opengroup spec isn't clear on the mapping from REALTIME to CALENDAR
being appropriate or not.
http://pubs.opengroup.org/onlinepubs/009695299/basedefs/time.h.html */

// XXX only supports a single timer
#define TIMER_ABSTIME -1
#define CLOCK_REALTIME CALENDAR_CLOCK
#define CLOCK_MONOTONIC SYSTEM_CLOCK

typedef int clockid_t;

/* the mach kernel uses struct mach_timespec, so struct timespec
is loaded from <sys/_types/_timespec.h> for compatability */
// struct timespec { time_t tv_sec; long tv_nsec; };

int clock_gettime(clockid_t clk_id, struct timespec *tp);

#include <mach/mach_time.h>

#define MT_NANO (+1.0E-9)
#define MT_GIGA UINT64_C(1000000000)

// TODO create a list of timers,
static double mt_timebase = 0.0;
static uint64_t mt_timestart = 0;

// TODO be more careful in a multithreaded environement
int clock_gettime(clockid_t clk_id, struct timespec *tp)
{
kern_return_t retval = KERN_SUCCESS;
if( clk_id == TIMER_ABSTIME)
{
if (!mt_timestart) { // only one timer, initilized on the first call to the TIMER
mach_timebase_info_data_t tb = { 0 };
mach_timebase_info(&tb);
mt_timebase = tb.numer;
mt_timebase /= tb.denom;
mt_timestart = mach_absolute_time();
}

double diff = (mach_absolute_time() - mt_timestart) * mt_timebase;
tp->tv_sec = diff * MT_NANO;
tp->tv_nsec = diff - (tp->tv_sec * MT_GIGA);
}
else // other clk_ids are mapped to the coresponding mach clock_service
{
clock_serv_t cclock;
mach_timespec_t mts;

host_get_clock_service(mach_host_self(), clk_id, &cclock);
retval = clock_get_time(cclock, &mts);
mach_port_deallocate(mach_task_self(), cclock);

tp->tv_sec = mts.tv_sec;
tp->tv_nsec = mts.tv_nsec;
}

return retval;
}
#endif
4 changes: 4 additions & 0 deletions rtcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
#define _JANUS_RTCP_H

#include <arpa/inet.h>
#ifdef __MACH__
#include <machine/endian.h>
#else
#include <endian.h>
#endif
#include <inttypes.h>
#include <string.h>

Expand Down
4 changes: 4 additions & 0 deletions rtp.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
#define _JANUS_RTP_H

#include <arpa/inet.h>
#ifdef __MACH__
#include <machine/endian.h>
#else
#include <endian.h>
#endif
#include <inttypes.h>
#include <string.h>

Expand Down
4 changes: 4 additions & 0 deletions utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
#include "utils.h"
#include "debug.h"

#if __MACH__
#include "mach_gettime.h"
#endif

gint64 janus_get_monotonic_time(void) {
struct timespec ts;
clock_gettime (CLOCK_MONOTONIC, &ts);
Expand Down

0 comments on commit 33b7583

Please sign in to comment.