Skip to content

Instantly share code, notes, and snippets.

Created February 18, 2016 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/4c96f7d6d1777793bdd4 to your computer and use it in GitHub Desktop.
Save anonymous/4c96f7d6d1777793bdd4 to your computer and use it in GitHub Desktop.
diff --git a/configure b/configure
index fb81a19..5a98b0d 100755
--- a/configure
+++ b/configure
@@ -1765,6 +1765,7 @@ BUILTIN_LIST="
mm_empty
rdtsc
sarestart
+ sem_timedwait
sync_val_compare_and_swap
"
HAVE_LIST_CMDLINE="
@@ -1791,6 +1792,7 @@ HEADERS_LIST="
dev_ic_bt8xx_h
dev_video_bktr_ioctl_bt848_h
dev_video_meteor_ioctl_meteor_h
+ dispatch_dispatch_h
direct_h
dirent_h
dlfcn_h
@@ -2790,7 +2792,7 @@ gdigrab_indev_deps="CreateDIBSection"
gdigrab_indev_extralibs="-lgdi32"
gdigrab_indev_select="bmp_decoder"
iec61883_indev_deps="libiec61883"
-jack_indev_deps="jack_jack_h sem_timedwait"
+jack_indev_deps="jack_jack_h"
lavfi_indev_deps="avfilter"
libcdio_indev_deps="libcdio"
libdc1394_indev_deps="libdc1394"
@@ -5353,6 +5355,7 @@ check_func mprotect
check_func_headers time.h nanosleep || { check_func_headers time.h nanosleep -lrt && add_extralibs -lrt && LIBRT="-lrt"; }
check_func sched_getaffinity
check_func setrlimit
+check_func sem_timedwait
check_struct "sys/stat.h" "struct stat" st_mtim.tv_nsec -D_BSD_SOURCE
check_func strerror_r
check_func sysconf
@@ -5380,6 +5383,7 @@ check_func_headers glob.h glob
enabled xlib &&
check_func_headers "X11/Xlib.h X11/extensions/Xvlib.h" XvGetPortAttribute -lXv -lX11 -lXext
+check_header dispatch/dispatch.h
check_header direct.h
check_header dirent.h
check_header dlfcn.h
@@ -5752,7 +5756,8 @@ check_header soundcard.h
enabled_any alsa_indev alsa_outdev &&
check_lib2 alsa/asoundlib.h snd_pcm_htimestamp -lasound
-enabled jack_indev && check_lib2 jack/jack.h jack_client_open -ljack && check_func sem_timedwait &&
+enabled jack_indev && check_lib2 jack/jack.h jack_client_open -ljack &&
+ ( enabled sem_timedwait || enabled dispatch_dispatch_h ) &&
check_func jack_port_get_latency_range -ljack
enabled_any sndio_indev sndio_outdev && check_lib2 sndio.h sio_open -lsndio
diff --git a/libavdevice/jack.c b/libavdevice/jack.c
index 9ecbf9e..b5b8666 100644
--- a/libavdevice/jack.c
+++ b/libavdevice/jack.c
@@ -35,6 +35,18 @@
#include "timefilter.h"
#include "avdevice.h"
+#if HAVE_DISPATCH_DISPATCH_H
+
+#include <dispatch/dispatch.h>
+#define sem_t dispatch_semaphore_t
+#define sem_init(psem,x,val) *psem = dispatch_semaphore_create(val)
+#define sem_post(psem) dispatch_semaphore_signal(*psem)
+#define sem_wait(psem) dispatch_semaphore_wait(*psem, DISPATCH_TIME_FOREVER)
+#define sem_timedwait(psem, val) dispatch_semaphore_wait(*psem, dispatch_walltime(val, 0))
+#define sem_destroy(psem) dispatch_release(*psem)
+
+#endif /* HAVE_DISPATCH_DISPATCH_H */
+
/**
* Size of the internal FIFO buffers as a number of audio packets
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment