summaryrefslogtreecommitdiff
path: root/audio
diff options
context:
space:
mode:
authornia <nia@pkgsrc.org>2021-09-08 19:19:19 +0000
committernia <nia@pkgsrc.org>2021-09-08 19:19:19 +0000
commit5ef883b430438995418969417f6fe5bc4f0cbe48 (patch)
treea3fc6a285362c8e9885ad3bb78dc166b0340661f /audio
parentb158c084faaa76611622bfb4429d8dcb2cacfa48 (diff)
downloadpkgsrc-5ef883b430438995418969417f6fe5bc4f0cbe48.tar.gz
jack: Update to 1.9.19
This switches us to jack2, the latest rewrite of the JACK audio server, with support for Solaris, Linux, macOS, and NetBSD (support for NetBSD added by me in a series of patches...) My primary motivation for this update is to avoid jack1's unpleasant abuse of unix domain sockets such that it no longer works in NetBSD 9.99.x (see PR kern/56113)
Diffstat (limited to 'audio')
-rw-r--r--audio/jack/DESCR13
-rw-r--r--audio/jack/MESSAGE.NetBSD12
-rw-r--r--audio/jack/Makefile141
-rw-r--r--audio/jack/PLIST55
-rw-r--r--audio/jack/buildlink3.mk18
-rw-r--r--audio/jack/distinfo44
-rw-r--r--audio/jack/files/atomicity.h24
-rw-r--r--audio/jack/patches/patch-common_JackAudioAdapterFactory.cpp18
-rw-r--r--audio/jack/patches/patch-common_memops.c20
-rw-r--r--audio/jack/patches/patch-common_wscript117
-rw-r--r--audio/jack/patches/patch-config_sysdeps_atomicity.h28
-rw-r--r--audio/jack/patches/patch-config_sysdeps_cycles.h17
-rw-r--r--audio/jack/patches/patch-configure37
-rw-r--r--audio/jack/patches/patch-drivers_coreaudio_Makefile.in15
-rw-r--r--audio/jack/patches/patch-drivers_netjack_netjack__packet.c15
-rw-r--r--audio/jack/patches/patch-drivers_oss_oss__driver.c15
-rw-r--r--audio/jack/patches/patch-drivers_oss_oss__driver.h18
-rw-r--r--audio/jack/patches/patch-drivers_sun_sun__driver.c80
-rw-r--r--audio/jack/patches/patch-example-clients_wscript33
-rw-r--r--audio/jack/patches/patch-include_engine.h19
-rw-r--r--audio/jack/patches/patch-jack_control.h16
-rw-r--r--audio/jack/patches/patch-jack_types.h15
-rw-r--r--audio/jack/patches/patch-jackd_engine.c16
-rw-r--r--audio/jack/patches/patch-libjack_unlock.c28
-rw-r--r--audio/jack/patches/patch-netbsd_JackAtomic__os.h39
-rw-r--r--audio/jack/patches/patch-netbsd_JackNetBSDTime.c97
-rw-r--r--audio/jack/patches/patch-netbsd_JackPlatformPlug__os.h91
-rw-r--r--audio/jack/patches/patch-netbsd_sun_JackSunAdapter.cpp485
-rw-r--r--audio/jack/patches/patch-netbsd_sun_JackSunAdapter.h120
-rw-r--r--audio/jack/patches/patch-netbsd_sun_JackSunDriver.cpp564
-rw-r--r--audio/jack/patches/patch-netbsd_sun_JackSunDriver.h120
-rw-r--r--audio/jack/patches/patch-posix_JackNetUnixSocket.cpp69
-rw-r--r--audio/jack/patches/patch-posix_JackNetUnixSocket.h15
-rw-r--r--audio/jack/patches/patch-posix_JackPosixSemaphore.cpp24
-rw-r--r--audio/jack/patches/patch-posix_JackSocket.cpp33
-rw-r--r--audio/jack/patches/patch-tests_wscript15
-rw-r--r--audio/jack/patches/patch-tools_netsource.c17
-rw-r--r--audio/jack/patches/patch-tools_session__notify.c16
-rw-r--r--audio/jack/patches/patch-tools_transport.c15
-rw-r--r--audio/jack/patches/patch-tools_wscript15
-rw-r--r--audio/jack/patches/patch-wscript49
41 files changed, 2039 insertions, 559 deletions
diff --git a/audio/jack/DESCR b/audio/jack/DESCR
index f3b11443581..d4e17479cc6 100644
--- a/audio/jack/DESCR
+++ b/audio/jack/DESCR
@@ -1,6 +1,7 @@
-JACK is a low-latency audio server, written for POSIX conformant
-operating systems such as GNU/Linux and Apple's OS X. It can connect a
-number of different applications to an audio device, as well as allowing
-them to share audio between themselves. Its clients can run in their own
-processes (ie. as normal applications), or can they can run within the
-JACK server (ie. as a "plugin").
+JACK (JACK Audio Connection Kit) provides a basic infrastructure for audio
+applications to communicate with each other and with audio hardware. Through
+JACK, users are enabled to build powerful systems for signal processing and
+music production.
+
+JACK2 aka jackdmp is a C++ version of the JACK low-latency audio server for
+multi-processor machines.
diff --git a/audio/jack/MESSAGE.NetBSD b/audio/jack/MESSAGE.NetBSD
index 641f8d74975..97d136d0a15 100644
--- a/audio/jack/MESSAGE.NetBSD
+++ b/audio/jack/MESSAGE.NetBSD
@@ -1,16 +1,12 @@
===========================================================================
-$NetBSD: MESSAGE.NetBSD,v 1.2 2019/12/02 11:48:38 nia Exp $
+$NetBSD: MESSAGE.NetBSD,v 1.3 2021/09/08 19:19:19 nia Exp $
-Realtime support is currently problematic.
-You need to pass -r to disable it, e.g:
+To start JACK on NetBSD:
-$ jackd -r -d sun
+$ jackd -Sr -d sun
If you have an external USB mic:
-$ jackd -r -d sun -P /dev/audio -C /dev/audio1
-
-Note that to use JACK on NetBSD you need procfs mounted.
-This should be done by default.
+$ jackd -Sr -d sun -P /dev/audio -C /dev/audio1 -i 1
===========================================================================
diff --git a/audio/jack/Makefile b/audio/jack/Makefile
index e1834ffe34b..7d1c430ea83 100644
--- a/audio/jack/Makefile
+++ b/audio/jack/Makefile
@@ -1,127 +1,54 @@
-# $NetBSD: Makefile,v 1.41 2021/05/24 19:49:05 wiz Exp $
+# $NetBSD: Makefile,v 1.42 2021/09/08 19:19:19 nia Exp $
-DISTNAME= jack-audio-connection-kit-0.125.0
-PKGREVISION= 4
-PKGNAME= ${DISTNAME:S/audio-connection-kit-//}
+DISTNAME= jack2-1.9.19
+PKGNAME= ${DISTNAME:S/jack2/jack/1}
CATEGORIES= audio
-MASTER_SITES= http://jackaudio.org/downloads/
+MASTER_SITES= ${MASTER_SITE_GITHUB:=jackaudio/}
+GITHUB_PROJECT= jack2
+GITHUB_TAG= v${PKGVERSION_NOREV}
-MAINTAINER= pkgsrc-users@NetBSD.org
-HOMEPAGE= http://www.jackaudio.org/
-COMMENT= JACK audio connection kit
-LICENSE= gnu-gpl-v2 AND gnu-lgpl-v2.1
+MAINTAINER= nia@NetBSD.org
+HOMEPAGE= https://jackaudio.org/
+COMMENT= Low-latency audio server
+LICENSE= gnu-gpl-v2
-BUILD_DEFS+= JACKD_DEFAULT_TMPDIR
-BUILD_DEFS+= JACKD_PROCFS_PATH
+USE_LANGUAGES= c c++
+USE_TOOLS+= pkg-config bash
-SET_LIBDIR= yes
-USE_TOOLS+= pkg-config
-USE_LIBTOOL= yes
-GNU_CONFIGURE= yes
-CONFIGURE_ARGS+= --disable-alsa
-CONFIGURE_ARGS+= --disable-firewire
-CONFIGURE_ARGS+= --disable-freebob
-CONFIGURE_ARGS+= --disable-optimize
-CONFIGURE_ARGS+= --enable-timestamps
-CONFIGURE_ARGS+= --enable-resize
-CONFIGURE_ENV+= HAVE_DOXYGEN=no
-CONFIGURE_ENV+= ac_cv_header_readline_chardefs_h=yes
-PKGCONFIG_OVERRIDE+= jack.pc.in
-
-PTHREAD_OPTS+= require native
-
-CFLAGS.NetBSD+= -D_NETBSD_SOURCE -lossaudio
-CFLAGS.Linux+= -D_GNU_SOURCE
-CFLAGS.SunOS+= -std=c99 -D_XOPEN_SOURCE=600 -D__EXTENSIONS__
-
-JACKD_DEFAULT_TMPDIR?= /tmp
+WAF_ARGS+= --systemd=no
.include "../../mk/bsd.prefs.mk"
-.if !empty(OPSYS:M*BSD) || ${OPSYS} == "DragonFly" || ${OPSYS} == "Darwin"
-CFLAGS+= -DJACK_HOST_HAS_BSD_POLL
-.endif
-###
-### XXX Is there a way to properly use the emulation framework
-### for this?
-###
-.if exists(${PREFIX}/emul/linux/proc) && ${OPSYS} != "Linux"
-JACKD_PROCFS_PATH?= ${PREFIX}/emul/linux/proc
-.else
-JACKD_PROCFS_PATH?= /proc
-.endif
-
-.if exists(/dev/shm) && ${OPSYS} == "Linux"
-CONFIGURE_ARGS+= --with-default-tmpdir=/dev/shm
-.else
-CONFIGURE_ARGS+= --with-default-tmpdir=${JACKD_DEFAULT_TMPDIR:Q}
+PLIST_VARS+= alsa
+.if ${OPSYS} == "Linux"
+PLIST.alsa= yes
.endif
-PLIST_VARS= coreaudio oss sunaudio
-###
-### XXX This is untested. Please file a PR and/or commit a fix should
-### any problems arise.
-###
-.if ${OPSYS} == "Darwin"
-CONFIGURE_ARGS+= --enable-coreaudio
-PLIST.coreaudio= yes
-.else
-CONFIGURE_ARGS+= --disable-coreaudio
+PLIST_VARS+= boomer oss
+.if ${OPSYS} == "SunOS"
+PLIST.boomer= yes
+PLIST.oss= yes
.endif
-.if ${OPSYS} == "NetBSD" || ${OPSYS} == "OpenBSD" || ${OPSYS} == "SunOS" || \
- exists(/usr/include/sys/audioio.h)
-CONFIGURE_ARGS+= --enable-sun
-PLIST.sunaudio= yes
-.else
-CONFIGURE_ARGS+= --disable-sun
+PLIST_VARS+= sun
+.if ${OPSYS} == "NetBSD"
+PLIST.sun= yes
.endif
-.include "../../mk/oss.buildlink3.mk"
+REPLACE_PYTHON+= waf
+REPLACE_PYTHON+= tools/jack_control
+REPLACE_BASH+= svnversion_regenerate.sh
-.if ${OSS_TYPE} != "none" && ${OPSYS} != "NetBSD" && ${OPSYS} != "SunOS"
-CONFIGURE_ARGS+= --enable-oss
-PLIST.oss= yes
-MAKE_ENV+= LIBOSSAUDIO=${LIBOSSAUDIO}
-CFLAGS+= -DDEVOSSAUDIO=\"${DEVOSSAUDIO:U/dev/dsp}\"
-.else
-CONFIGURE_ARGS+= --disable-oss
-.endif
-
-SUBST_CLASSES+= jacksrc
-SUBST_FILES.jacksrc= libjack/unlock.c
-SUBST_MESSAGE.jacksrc= Peforming substitutions in JACK sources.
-SUBST_STAGE.jacksrc= pre-build
-SUBST_VARS.jacksrc= PREFIX JACKD_PROCFS_PATH X11BASE
-
-.if ${MACHINE_ARCH} == "i386" || ${MACHINE_ARCH} == "x86_64"
-PKG_OPTIONS_VAR= PKG_OPTIONS.jack
-PKG_SUPPORTED_OPTIONS= simd
-# on 7.99.26/amd64:
-# ./simd.c: In function 'x86_3dnow_add2f':
-# ./simd.c:211:3: error: impossible constraint in 'asm'
-# asm volatile (
-#PKG_SUGGESTED_OPTIONS= simd
+PYTHON_VERSIONS_INCOMPATIBLE= 27
-. include "../../mk/bsd.options.mk"
+PKGCONFIG_OVERRIDE+= jack.pc.in
-. if !empty(PKG_OPTIONS:Msimd)
-CONFIGURE_ARGS+= --enable-dynsimd
-. else
-CONFIGURE_ARGS+= --disable-dynsimd
-. endif
+.include "../../lang/python/application.mk"
+.include "../../devel/waf/waf.mk"
+.if ${OPSYS} == "Linux"
+. include "../../audio/alsa-lib/buildlink3.mk"
.endif
-
-BDB_ACCEPTED= db4 db5
-BUILDLINK_TRANSFORM+= l:db:${BDB_TYPE}
-
-post-extract:
- ${MKDIR} ${WRKSRC}/config/os/netbsd
- ${CP} ${FILESDIR}/atomicity.h ${WRKSRC}/config/os/netbsd
-
+.include "../../audio/libopus/buildlink3.mk"
.include "../../audio/libsamplerate/buildlink3.mk"
-.include "../../mk/bdb.buildlink3.mk"
-.include "../../mk/dlopen.buildlink3.mk"
-.include "../../mk/pthread.buildlink3.mk"
-.include "../../mk/readline.buildlink3.mk"
+.include "../../audio/libsndfile/buildlink3.mk"
.include "../../mk/bsd.pkg.mk"
diff --git a/audio/jack/PLIST b/audio/jack/PLIST
index 6bea7d6c594..c0431de46a3 100644
--- a/audio/jack/PLIST
+++ b/audio/jack/PLIST
@@ -1,34 +1,40 @@
-@comment $NetBSD: PLIST,v 1.10 2018/01/01 22:29:17 rillig Exp $
+@comment $NetBSD: PLIST,v 1.11 2021/09/08 19:19:19 nia Exp $
bin/jack_alias
bin/jack_bufsize
bin/jack_connect
+bin/jack_control
+bin/jack_cpu
+bin/jack_cpu_load
bin/jack_disconnect
bin/jack_evmon
bin/jack_freewheel
-bin/jack_impulse_grabber
bin/jack_iodelay
bin/jack_latent_client
bin/jack_load
-bin/jack_load_test
bin/jack_lsp
bin/jack_metro
bin/jack_midi_dump
+bin/jack_midi_latency_test
bin/jack_midiseq
bin/jack_midisine
bin/jack_monitor_client
-bin/jack_netsource
+bin/jack_multiple_metro
+bin/jack_net_master
+bin/jack_net_slave
bin/jack_property
bin/jack_rec
bin/jack_samplerate
bin/jack_server_control
bin/jack_session_notify
bin/jack_showtime
+bin/jack_simdtests
bin/jack_simple_client
bin/jack_simple_session_client
-bin/jack_transport
-bin/jack_transport_client
+bin/jack_test
+bin/jack_thru
bin/jack_unload
bin/jack_wait
+bin/jack_zombie
bin/jackd
include/jack/control.h
include/jack/intclient.h
@@ -36,24 +42,39 @@ include/jack/jack.h
include/jack/jslist.h
include/jack/metadata.h
include/jack/midiport.h
+include/jack/net.h
include/jack/ringbuffer.h
include/jack/session.h
include/jack/statistics.h
+include/jack/systemdeps.h
include/jack/thread.h
include/jack/transport.h
include/jack/types.h
include/jack/uuid.h
include/jack/weakjack.h
include/jack/weakmacros.h
-lib/jack/inprocess.la
-lib/jack/intime.la
-${PLIST.coreaudio}lib/jack/jack_coreaudio.la
-lib/jack/jack_dummy.la
-lib/jack/jack_net.la
-${PLIST.oss}lib/jack/jack_oss.la
-${PLIST.sunaudio}lib/jack/jack_sun.la
-lib/libjack.la
-lib/libjackserver.la
+lib/jack/audioadapter.so
+lib/jack/inprocess.so
+${PLIST.alsa}lib/jack/jack_alsa.so
+${PLIST.alsa}lib/jack/jack_alsarawmidi.so
+${PLIST.boomer}lib/jack/jack_boomer.so
+lib/jack/jack_dummy.so
+lib/jack/jack_loopback.so
+lib/jack/jack_net.so
+lib/jack/jack_netone.so
+${PLIST.oss}lib/jack/jack_oss.so
+lib/jack/jack_proxy.so
+${PLIST.sun}lib/jack/jack_sun.so
+lib/jack/netadapter.so
+lib/jack/netmanager.so
+lib/jack/profiler.so
+lib/libjack.so
+lib/libjack.so.0
+lib/libjack.so.0.1.0
+lib/libjacknet.so
+lib/libjacknet.so.0
+lib/libjacknet.so.0.1.0
+lib/libjackserver.so
+lib/libjackserver.so.0
+lib/libjackserver.so.0.1.0
lib/pkgconfig/jack.pc
-man/man1/jackd.1
-man/man1/jackstart.1
diff --git a/audio/jack/buildlink3.mk b/audio/jack/buildlink3.mk
index 7b7f8ae4ee0..d2dcf08fdfb 100644
--- a/audio/jack/buildlink3.mk
+++ b/audio/jack/buildlink3.mk
@@ -1,21 +1,21 @@
-# $NetBSD: buildlink3.mk,v 1.13 2020/08/18 17:57:24 leot Exp $
+# $NetBSD: buildlink3.mk,v 1.14 2021/09/08 19:19:19 nia Exp $
BUILDLINK_TREE+= jack
.if !defined(JACK_BUILDLINK3_MK)
JACK_BUILDLINK3_MK:=
-BUILDLINK_API_DEPENDS.jack+= jack>=0.121.3
-BUILDLINK_ABI_DEPENDS.jack?= jack>=0.125.0nb3
+BUILDLINK_API_DEPENDS.jack+= jack>=1.9.19
+BUILDLINK_ABI_DEPENDS.jack?= jack>=1.9.19
BUILDLINK_PKGSRCDIR.jack?= ../../audio/jack
-BDB_ACCEPTED= db4 db5
-
+.include "../../mk/bsd.fast.prefs.mk"
+.if ${OPSYS} == "Linux"
+. include "../../audio/alsa-lib/buildlink3.mk"
+.endif
+.include "../../audio/libopus/buildlink3.mk"
.include "../../audio/libsamplerate/buildlink3.mk"
-.include "../../mk/bdb.buildlink3.mk"
-# for DLOPEN_REQUIRE_PTHREADS
-.include "../../mk/dlopen.buildlink3.mk"
-.include "../../mk/pthread.buildlink3.mk"
+.include "../../audio/libsndfile/buildlink3.mk"
.endif # JACK_BUILDLINK3_MK
BUILDLINK_TREE+= -jack
diff --git a/audio/jack/distinfo b/audio/jack/distinfo
index c2478d14f4e..b7d5a50b6cf 100644
--- a/audio/jack/distinfo
+++ b/audio/jack/distinfo
@@ -1,22 +1,24 @@
-$NetBSD: distinfo,v 1.22 2019/12/02 11:46:08 nia Exp $
+$NetBSD: distinfo,v 1.23 2021/09/08 19:19:19 nia Exp $
-SHA1 (jack-audio-connection-kit-0.125.0.tar.gz) = 6b7516b442878ffd1ca875310084b33d0edee400
-RMD160 (jack-audio-connection-kit-0.125.0.tar.gz) = 25f1baa1d8f03f0bbfc0b48c300b63d89d4e881b
-SHA512 (jack-audio-connection-kit-0.125.0.tar.gz) = acdac0588c8a6b79763177677885b6e7bfa8ee3cd9556b33bfe09512bc1191414bb4f97eed62c3c71567b13b4eb69d95ec6b438e5a9d2e22a956c073d500c46f
-Size (jack-audio-connection-kit-0.125.0.tar.gz) = 1217977 bytes
-SHA1 (patch-config_sysdeps_atomicity.h) = f2346262d7590491f005af1c450f4436ec60c58e
-SHA1 (patch-config_sysdeps_cycles.h) = cbaefbefd0758625210c94bcba008b22c2c3a9d4
-SHA1 (patch-configure) = 79abcf4d7514cb4e66e3246fcd897f82c6d75e78
-SHA1 (patch-drivers_coreaudio_Makefile.in) = 13f5e5914ae0304c93dca54518fecb19f5ecdec5
-SHA1 (patch-drivers_netjack_netjack__packet.c) = eb70ec5644e960e0cf0258a15d763be31c11bb02
-SHA1 (patch-drivers_oss_oss__driver.c) = 302f20e82abde4a5b1678d2c3e9cbc8a63fad5ad
-SHA1 (patch-drivers_oss_oss__driver.h) = f23595db3fe80cae36ce222d89cdfbc37916e325
-SHA1 (patch-drivers_sun_sun__driver.c) = 0842e34e6190b8877ab7ac3d4d764a0de4cbfca8
-SHA1 (patch-include_engine.h) = c58651bccc910131ffc9b263a75fa732a7a2b168
-SHA1 (patch-jack_control.h) = 8d6f07fd226b68cacf170501f557503cd674249a
-SHA1 (patch-jack_types.h) = a58fcdafab7e014760287d763c944c8a77281f7f
-SHA1 (patch-jackd_engine.c) = 703242e74bb6d0cae1274b5e4f2c477a689432d9
-SHA1 (patch-libjack_unlock.c) = 4e346eb5dc2bce74968b894158cb3871d5076149
-SHA1 (patch-tools_netsource.c) = 9eb526fbcb020ce8262883e685f57b627a7621cb
-SHA1 (patch-tools_session__notify.c) = 6ab077be462993a054289803ffc3e8a6654c533e
-SHA1 (patch-tools_transport.c) = 2a40f3a51a088e62352d7cdcc27eb41f3064ae7e
+SHA1 (jack2-1.9.19.tar.gz) = 3182304c0a3ecd911775fb46088f0df79ee9015f
+RMD160 (jack2-1.9.19.tar.gz) = da6ed4db02dfc856c477d76a73fe22157b6f7df8
+SHA512 (jack2-1.9.19.tar.gz) = d8d5fe17e2984959546af3c53f044aa4648860e19ff8ffd54452e87fa6cdfd111f825c57e3df17cb8ed95de8392b6f354b12ded41e3e021a37f07b99a89ba18d
+Size (jack2-1.9.19.tar.gz) = 988780 bytes
+SHA1 (patch-common_JackAudioAdapterFactory.cpp) = 8292a8c88c673136f52a007133278f9b4403839c
+SHA1 (patch-common_memops.c) = 468476c6067595524f492d37f3b761af48e78585
+SHA1 (patch-common_wscript) = a86ba367fcb4892b3a34f395840ecbd1c5358005
+SHA1 (patch-example-clients_wscript) = 9db0899e797acbc416bfd9e6aba50c70bd5ff0ab
+SHA1 (patch-netbsd_JackAtomic__os.h) = cd9cc4bf9913b3dedfbb8a2ea34077277e17f85d
+SHA1 (patch-netbsd_JackNetBSDTime.c) = 7cc2504bbd452b703dd062ac5d35f68ffe7e3b0a
+SHA1 (patch-netbsd_JackPlatformPlug__os.h) = f17b0daf4d8a4ef1001b35e6ea1411cfb1b981c2
+SHA1 (patch-netbsd_sun_JackSunAdapter.cpp) = e6c02653840ad02fdee9168796d129504ca29f92
+SHA1 (patch-netbsd_sun_JackSunAdapter.h) = 740b36c69d02742eceeb724ba18796664fb1bc2d
+SHA1 (patch-netbsd_sun_JackSunDriver.cpp) = 43a7126b68076f45292df67f59239c9febf014ff
+SHA1 (patch-netbsd_sun_JackSunDriver.h) = 9da5fbec2216081876174057f831da4c54e3029e
+SHA1 (patch-posix_JackNetUnixSocket.cpp) = 562242daf7c0f296bfcd03f468518aaf18d995d9
+SHA1 (patch-posix_JackNetUnixSocket.h) = ce9a9255dc0dd423562b94b0fcc1012c8ba3a37e
+SHA1 (patch-posix_JackPosixSemaphore.cpp) = 59425ada11a5cab83159691ae10a23c0d36750ef
+SHA1 (patch-posix_JackSocket.cpp) = 88ae18c3d2cc31a43355ff9b0c78ab13b83bd314
+SHA1 (patch-tests_wscript) = e0bf616175a116df489808cda8cb8c70890d4da0
+SHA1 (patch-tools_wscript) = c990639f5c1a998dd02d12eb345e78b0a91a1c6f
+SHA1 (patch-wscript) = 6514e2e7d10f096deb99effa35974e9253599f74
diff --git a/audio/jack/files/atomicity.h b/audio/jack/files/atomicity.h
deleted file mode 100644
index b63af9d4b7b..00000000000
--- a/audio/jack/files/atomicity.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/* $NetBSD: atomicity.h,v 1.1 2008/07/31 03:58:05 bjs Exp $ */
-
-#ifndef _NETBSD_ATOMICITY_H
-#define _NETBSD_ATOMICITY_H 1
-
-#include <sys/atomic.h>
-
-typedef unsigned int _Atomic_word;
-
-static inline _Atomic_word
-__attribute__ ((__unused__))
-__exchange_and_add(volatile _Atomic_word* __mem, int __val)
-{
- return atomic_add_int_nv(__mem, __val);
-}
-
-static inline void
-__attribute__ ((__unused__))
-__atomic_add(volatile _Atomic_word* __mem, int __val)
-{
- atomic_add_int(__mem, __val);
-}
-
-#endif /* atomicity.h */
diff --git a/audio/jack/patches/patch-common_JackAudioAdapterFactory.cpp b/audio/jack/patches/patch-common_JackAudioAdapterFactory.cpp
new file mode 100644
index 00000000000..8f6f428cd18
--- /dev/null
+++ b/audio/jack/patches/patch-common_JackAudioAdapterFactory.cpp
@@ -0,0 +1,18 @@
+$NetBSD: patch-common_JackAudioAdapterFactory.cpp,v 1.1 2021/09/08 19:19:20 nia Exp $
+
+Add NetBSD support.
+
+--- common/JackAudioAdapterFactory.cpp.orig 2021-07-15 06:18:26.000000000 +0000
++++ common/JackAudioAdapterFactory.cpp
+@@ -35,6 +35,11 @@ Foundation, Inc., 675 Mass Ave, Cambridg
+ #define JackPlatformAdapter JackAlsaAdapter
+ #endif
+
++#ifdef __NetBSD__
++#include "JackSunAdapter.h"
++#define JackPlatformAdapter JackSunAdapter
++#endif
++
+ #if defined(__sun__) || defined(sun)
+ #include "JackOSSAdapter.h"
+ #define JackPlatformAdapter JackOSSAdapter
diff --git a/audio/jack/patches/patch-common_memops.c b/audio/jack/patches/patch-common_memops.c
new file mode 100644
index 00000000000..3eff6604789
--- /dev/null
+++ b/audio/jack/patches/patch-common_memops.c
@@ -0,0 +1,20 @@
+$NetBSD: patch-common_memops.c,v 1.1 2021/09/08 19:19:20 nia Exp $
+
+Add NetBSD support.
+
+--- common/memops.c.orig 2021-07-15 06:18:26.000000000 +0000
++++ common/memops.c
+@@ -35,6 +35,13 @@
+ #endif
+ #include "memops.h"
+
++#ifdef __NetBSD__
++#include <sys/endian.h>
++#define __BYTE_ORDER BYTE_ORDER
++#define __LITTLE_ENDIAN LITTLE_ENDIAN
++#define __BIG_ENDIAN BIG_ENDIAN
++#endif
++
+ #if defined (__SSE2__) && !defined (__sun__)
+ #include <emmintrin.h>
+ #ifdef __SSE4_1__
diff --git a/audio/jack/patches/patch-common_wscript b/audio/jack/patches/patch-common_wscript
new file mode 100644
index 00000000000..b6a10954846
--- /dev/null
+++ b/audio/jack/patches/patch-common_wscript
@@ -0,0 +1,117 @@
+$NetBSD: patch-common_wscript,v 1.1 2021/09/08 19:19:20 nia Exp $
+
+Add NetBSD support.
+
+--- common/wscript.orig 2021-07-15 06:18:26.000000000 +0000
++++ common/wscript
+@@ -28,6 +28,8 @@ def create_jack_process_obj(bld, target,
+ env_includes = ['../macosx', '../posix', '../macosx/coreaudio']
+ if bld.env['IS_LINUX']:
+ env_includes = ['../linux', '../posix', '../linux/alsa']
++ if bld.env['IS_NETBSD']:
++ env_includes = ['../netbsd', '../posix', '../netbsd/sun']
+ if bld.env['IS_SUN']:
+ env_includes = ['../solaris', '../posix', '../solaris/oss']
+ if bld.env['IS_WINDOWS']:
+@@ -36,7 +38,7 @@ def create_jack_process_obj(bld, target,
+ process.name = target
+ process.target = target
+ process.source = sources
+- if bld.env['IS_LINUX'] or bld.env['IS_MACOSX']:
++ if bld.env['IS_LINUX'] or bld.env['IS_NETBSD'] or bld.env['IS_MACOSX']:
+ process.env.append_value('CPPFLAGS', '-fvisibility=hidden')
+ process.install_path = '${ADDON_DIR}/'
+ process.use = [uselib.name]
+@@ -92,6 +94,21 @@ def build(bld):
+ uselib.append('RT')
+ uselib.append('DL')
+
++ if bld.env['IS_NETBSD']:
++ common_libsources += [
++ 'JackDebugClient.cpp',
++ 'timestamps.c',
++ 'promiscuous.c',
++ '../posix/JackPosixThread.cpp',
++ '../posix/JackPosixSemaphore.cpp',
++ '../posix/JackPosixProcessSync.cpp',
++ '../posix/JackPosixMutex.cpp',
++ '../posix/JackSocket.cpp',
++ '../netbsd/JackNetBSDTime.c',
++ ]
++ includes = ['../netbsd', '../posix'] + includes
++ uselib.append('RT')
++
+ if bld.env['IS_SUN']:
+ common_libsources += [
+ 'JackDebugClient.cpp',
+@@ -176,6 +193,12 @@ def build(bld):
+ '../posix/JackPosixServerLaunch.cpp',
+ ]
+
++ if bld.env['IS_NETBSD']:
++ clientlib.source += [
++ '../posix/JackSocketClientChannel.cpp',
++ '../posix/JackPosixServerLaunch.cpp',
++ ]
++
+ if bld.env['IS_SUN']:
+ clientlib.source += [
+ '../posix/JackSocketClientChannel.cpp',
+@@ -205,6 +228,9 @@ def build(bld):
+ if bld.env['IS_LINUX']:
+ clientlib.env.append_value('CPPFLAGS', '-fvisibility=hidden')
+
++ if bld.env['IS_NETBSD']:
++ clientlib.env.append_value('CPPFLAGS', '-fvisibility=hidden')
++
+ if bld.env['IS_MACOSX']:
+ clientlib.env.append_value('CPPFLAGS', '-fvisibility=hidden')
+ clientlib.env.append_value('LINKFLAGS', '-single_module')
+@@ -281,6 +307,14 @@ def build(bld):
+ '../posix/JackNetUnixSocket.cpp',
+ ]
+
++ if bld.env['IS_NETBSD']:
++ serverlib.source += [
++ '../posix/JackSocketServerChannel.cpp',
++ '../posix/JackSocketNotifyChannel.cpp',
++ '../posix/JackSocketServerNotifyChannel.cpp',
++ '../posix/JackNetUnixSocket.cpp',
++ ]
++
+ if bld.env['IS_SUN']:
+ serverlib.source += [
+ '../posix/JackSocketServerChannel.cpp',
+@@ -316,6 +350,9 @@ def build(bld):
+ if bld.env['IS_LINUX']:
+ serverlib.env.append_value('CPPFLAGS', '-fvisibility=hidden')
+
++ if bld.env['IS_NETBSD']:
++ serverlib.env.append_value('CPPFLAGS', '-fvisibility=hidden')
++
+ if bld.env['IS_MACOSX']:
+ serverlib.env.append_value('CPPFLAGS', '-fvisibility=hidden')
+ serverlib.env.append_value('LINKFLAGS', '-single_module')
+@@ -360,6 +397,10 @@ def build(bld):
+ netlib.source += ['../posix/JackNetUnixSocket.cpp','../posix/JackPosixThread.cpp', '../posix/JackPosixMutex.cpp', '../linux/JackLinuxTime.c']
+ netlib.env.append_value('CPPFLAGS', '-fvisibility=hidden')
+
++ if bld.env['IS_NETBSD']:
++ netlib.source += ['../posix/JackNetUnixSocket.cpp','../posix/JackPosixThread.cpp', '../posix/JackPosixMutex.cpp', '../netbsd/JackNetBSDTime.c']
++ netlib.env.append_value('CPPFLAGS', '-fvisibility=hidden')
++
+ if bld.env['IS_SUN']:
+ netlib.source += ['../posix/JackNetUnixSocket.cpp','../posix/JackPosixThread.cpp', '../posix/JackPosixMutex.cpp', '../solaris/JackSolarisTime.c']
+ netlib.env.append_value('CPPFLAGS', '-fvisibility=hidden')
+@@ -422,6 +463,11 @@ def build(bld):
+ process = create_jack_process_obj(bld, 'audioadapter', audio_adapter_sources, serverlib)
+ process.use += ['ALSA', 'SAMPLERATE']
+
++ if bld.env['BUILD_ADAPTER'] and bld.env['IS_NETBSD']:
++ audio_adapter_sources += ['../netbsd/sun/JackSunAdapter.cpp']
++ process = create_jack_process_obj(bld, 'audioadapter', audio_adapter_sources, serverlib)
++ process.use += 'SAMPLERATE'
++
+ if bld.env['BUILD_ADAPTER'] and bld.env['IS_SUN']:
+ audio_adapter_sources += ['../solaris/oss/JackOSSAdapter.cpp', 'memops.c']
+ process = create_jack_process_obj(bld, 'audioadapter', audio_adapter_sources, serverlib)
diff --git a/audio/jack/patches/patch-config_sysdeps_atomicity.h b/audio/jack/patches/patch-config_sysdeps_atomicity.h
deleted file mode 100644
index 626ab35253e..00000000000
--- a/audio/jack/patches/patch-config_sysdeps_atomicity.h
+++ /dev/null
@@ -1,28 +0,0 @@
-$NetBSD: patch-config_sysdeps_atomicity.h,v 1.1 2019/06/15 08:21:32 adam Exp $
-
---- config/sysdeps/atomicity.h.orig 2008-11-11 17:36:35.000000000 -0500
-+++ config/sysdeps/atomicity.h
-@@ -1,7 +1,11 @@
- #ifndef _jack_sysdep_atomicity_h_
- #define _jack_sysdep_atomicity_h_
-
--#if defined(__i386__)
-+#if defined(HAVE_NETBSD_ATOMIC_OPS)
-+
-+#include <config/os/netbsd/atomicity.h>
-+
-+#elif defined(__i386__)
-
- #include <config/cpu/i386/atomicity.h>
-
-@@ -15,6 +19,10 @@
-
- #include <config/cpu/powerpc/atomicity.h>
-
-+#elif defined(__mips__) || defined(__mips64__)
-+
-+#include <config/cpu/mips/atomicity.h>
-+
- #else
-
- #include <config/cpu/generic/atomicity.h>
diff --git a/audio/jack/patches/patch-config_sysdeps_cycles.h b/audio/jack/patches/patch-config_sysdeps_cycles.h
deleted file mode 100644
index 94822294882..00000000000
--- a/audio/jack/patches/patch-config_sysdeps_cycles.h
+++ /dev/null
@@ -1,17 +0,0 @@
-$NetBSD: patch-config_sysdeps_cycles.h,v 1.1 2019/06/15 08:21:32 adam Exp $
-
-Add support for Alpha.
-
---- config/sysdeps/cycles.h.orig 2016-02-23 15:13:53.000000000 +0000
-+++ config/sysdeps/cycles.h
-@@ -19,6 +19,10 @@
-
- #include <config/cpu/powerpc/cycles.h>
-
-+#elif defined(__alpha__)
-+
-+#include <config/cpu/alpha/cycles.h>
-+
- #else
-
- #include <config/cpu/generic/cycles.h>
diff --git a/audio/jack/patches/patch-configure b/audio/jack/patches/patch-configure
deleted file mode 100644
index b87188691f7..00000000000
--- a/audio/jack/patches/patch-configure
+++ /dev/null
@@ -1,37 +0,0 @@
-$NetBSD: patch-configure,v 1.1 2019/06/15 08:21:32 adam Exp $
-
-Do not set -mmacosx-version-min.
-Kill all of the overzealous optimization; if the user wants this,
-there is devel/cpuflags and mk.conf.
-
---- configure.orig 2016-09-14 22:02:13.000000000 +0000
-+++ configure
-@@ -16589,10 +16589,6 @@ fi
-
- JACK_CORE_CFLAGS="$JACK_CORE_CFLAGS $JACK_LIBC_HELPER_FLAGS"
-
--case $build_os in
-- # we need weak linkage which appeared in 10.2, but lets ask for 10.4 anyway
-- darwin*) JACK_CORE_CFLAGS="$JACK_CORE_CFLAGS -mmacosx-version-min=10.4" ;;
--esac
-
-
- # Check whether --with-cpu-target was given.
-@@ -16759,7 +16755,7 @@ rm -f core conftest.err conftest.$ac_obj
-
- $as_echo "#define x86 1" >>confdefs.h
-
-- COMMON_X86_OPT_FLAGS="-O3 -fomit-frame-pointer -ffast-math -funroll-loops"
-+ COMMON_X86_OPT_FLAGS="-fomit-frame-pointer"
-
-
- if test x$with_cpu_target != x ; then
-@@ -16794,7 +16790,7 @@ if test "x$enable_dynsimd" = xyes; then
-
- $as_echo "#define USE_DYNSIMD 1" >>confdefs.h
-
-- SIMD_CFLAGS="-O -msse -msse2 -m3dnow"
-+ SIMD_CFLAGS=""
-
- fi
-
diff --git a/audio/jack/patches/patch-drivers_coreaudio_Makefile.in b/audio/jack/patches/patch-drivers_coreaudio_Makefile.in
deleted file mode 100644
index aab4817d757..00000000000
--- a/audio/jack/patches/patch-drivers_coreaudio_Makefile.in
+++ /dev/null
@@ -1,15 +0,0 @@
-$NetBSD: patch-drivers_coreaudio_Makefile.in,v 1.1 2015/01/27 04:37:53 dbj Exp $
-
-Avoid hard coding header path on Darwin
-
---- drivers/coreaudio/Makefile.in.orig 2011-09-28 13:10:12.000000000 +0000
-+++ drivers/coreaudio/Makefile.in
-@@ -249,7 +249,7 @@ top_build_prefix = @top_build_prefix@
- top_builddir = @top_builddir@
- top_srcdir = @top_srcdir@
- MAINTAINERCLEANFILES = Makefile.in
--AM_CFLAGS = $(JACK_CFLAGS) -include /System/Library/Frameworks/Carbon.framework/Headers/Carbon.h
-+AM_CFLAGS = $(JACK_CFLAGS) -framework Carbon -include Carbon/Carbon.h
- plugindir = $(ADDON_DIR)
- plugin_LTLIBRARIES = jack_coreaudio.la
- jack_coreaudio_la_LDFLAGS = -module -avoid-version @OS_LDFLAGS@
diff --git a/audio/jack/patches/patch-drivers_netjack_netjack__packet.c b/audio/jack/patches/patch-drivers_netjack_netjack__packet.c
deleted file mode 100644
index 8b266af09e8..00000000000
--- a/audio/jack/patches/patch-drivers_netjack_netjack__packet.c
+++ /dev/null
@@ -1,15 +0,0 @@
-$NetBSD: patch-drivers_netjack_netjack__packet.c,v 1.2 2013/02/09 19:59:45 ryoon Exp $
-
---- drivers/netjack/netjack_packet.c.orig 2011-06-08 23:54:48.000000000 +0000
-+++ drivers/netjack/netjack_packet.c
-@@ -44,6 +44,10 @@
- #include <errno.h>
- #include <stdarg.h>
-
-+#ifdef __sun
-+#include <alloca.h>
-+#endif
-+
- #include <jack/types.h>
-
- // for jack_error in jack1
diff --git a/audio/jack/patches/patch-drivers_oss_oss__driver.c b/audio/jack/patches/patch-drivers_oss_oss__driver.c
deleted file mode 100644
index 0eabd3663ea..00000000000
--- a/audio/jack/patches/patch-drivers_oss_oss__driver.c
+++ /dev/null
@@ -1,15 +0,0 @@
-$NetBSD: patch-drivers_oss_oss__driver.c,v 1.1 2019/06/15 08:21:32 adam Exp $
-
-We want to make sure there's no garbage in the output buffer, otherwise
-untoward stuff can happen.
-
---- drivers/oss/oss_driver.c.orig 2016-02-23 15:13:53.000000000 +0000
-+++ drivers/oss/oss_driver.c
-@@ -949,6 +949,7 @@ static void *io_thread (void *param)
- while (driver->run) {
- pthread_mutex_lock (&driver->mutex_out);
- memcpy (localbuf, driver->outdevbuf, localsize);
-+ memset(driver->outdevbuf, 0, driver->outdevbufsize);
- pthread_mutex_unlock (&driver->mutex_out);
-
- io_res = write (driver->outfd, localbuf, localsize);
diff --git a/audio/jack/patches/patch-drivers_oss_oss__driver.h b/audio/jack/patches/patch-drivers_oss_oss__driver.h
deleted file mode 100644
index 6ed437f99cc..00000000000
--- a/audio/jack/patches/patch-drivers_oss_oss__driver.h
+++ /dev/null
@@ -1,18 +0,0 @@
-$NetBSD: patch-drivers_oss_oss__driver.h,v 1.1 2019/06/15 08:21:33 adam Exp $
-
-Use proper OSS device.
-
---- drivers/oss/oss_driver.h.orig 2016-02-23 15:13:53.000000000 +0000
-+++ drivers/oss/oss_driver.h
-@@ -35,7 +35,11 @@
- #include "driver.h"
-
-
-+#if defined(DEVOSSAUDIO)
-+#define OSS_DRIVER_DEF_DEV DEVOSSAUDIO
-+#else
- #define OSS_DRIVER_DEF_DEV "/dev/dsp"
-+#endif
- #define OSS_DRIVER_DEF_FS 48000
- #define OSS_DRIVER_DEF_BLKSIZE 1024
- #define OSS_DRIVER_DEF_NPERIODS 2
diff --git a/audio/jack/patches/patch-drivers_sun_sun__driver.c b/audio/jack/patches/patch-drivers_sun_sun__driver.c
deleted file mode 100644
index 374cdfbdafa..00000000000
--- a/audio/jack/patches/patch-drivers_sun_sun__driver.c
+++ /dev/null
@@ -1,80 +0,0 @@
-$NetBSD: patch-drivers_sun_sun__driver.c,v 1.1 2019/12/02 11:46:08 nia Exp $
-
-NetBSD support changes:
-
-- Don't try to poll() /dev/audio
-- Don't write silence to "prime" the driver
-- Block size does not relate to period
-- AUDIO_SETFD is deprecated
-
---- drivers/sun/sun_driver.c.orig 2016-02-23 15:13:53.000000000 +0000
-+++ drivers/sun/sun_driver.c
-@@ -383,7 +383,12 @@ sun_driver_run_cycle (sun_driver_t *driv
- int wait_status;
- float iodelay;
-
-+#ifdef __NetBSD__
-+ wait_status = 0;
-+ nframes = driver->period_size;
-+#else
- nframes = sun_driver_wait (driver, &wait_status, &iodelay);
-+#endif
-
- if (wait_status < 0) {
- switch (wait_status) {
-@@ -650,8 +655,10 @@ sun_driver_start (sun_driver_t *driver)
- * be available to read before we can write. also helps to
- * keep constant latency from the beginning.
- */
-+#ifndef __NetBSD__
- sun_driver_write_silence (driver,
- driver->nperiods * driver->period_size);
-+#endif
- }
-
- if (driver->infd >= 0) {
-@@ -732,7 +739,7 @@ sun_driver_set_parameters (sun_driver_t
- __FILE__, __LINE__);
- return -1;
- }
--#if defined(AUDIO_SETFD)
-+#if defined(AUDIO_SETFD) && !defined(__NetBSD__)
- if (ioctl (infd, AUDIO_SETFD, &s) < 0) {
- jack_error ("sun_driver: failed to enable full duplex: "
- "%s: %s@%i", strerror (errno),
-@@ -797,15 +804,6 @@ sun_driver_set_parameters (sun_driver_t
- audio_if_out.play.block_size = driver->playback_channels *
- driver->period_size * driver->sample_bytes;
- }
--#else
-- if (driver->infd >= 0) {
-- audio_if_in.blocksize = driver->capture_channels *
-- driver->period_size * driver->sample_bytes;
-- }
-- if (driver->outfd >= 0) {
-- audio_if_out.blocksize = driver->playback_channels *
-- driver->period_size * driver->sample_bytes;
-- }
- #endif
- if (infd == outfd) {
- audio_if_in.play = audio_if_out.play;
-@@ -871,9 +869,6 @@ sun_driver_set_parameters (sun_driver_t
- #if defined(__OpenBSD__)
- cap_period = audio_if_in.record.block_size /
- driver->capture_channels / driver->sample_bytes;
--#elif defined(__NetBSD__)
-- cap_period = audio_if_in.blocksize /
-- driver->capture_channels / driver->sample_bytes;
- #else
- /* how is this done on Solaris? */
- cap_period = driver->period_size;
-@@ -903,9 +898,6 @@ sun_driver_set_parameters (sun_driver_t
- #if defined(__OpenBSD__)
- play_period = audio_if_out.play.block_size /
- driver->playback_channels / driver->sample_bytes;
--#elif defined(__NetBSD__)
-- play_period = audio_if_out.blocksize /
-- driver->playback_channels / driver->sample_bytes;
- #else
- /* how is this done on Solaris? */
- play_period = driver->period_size;
diff --git a/audio/jack/patches/patch-example-clients_wscript b/audio/jack/patches/patch-example-clients_wscript
new file mode 100644
index 00000000000..0b79cdaf743
--- /dev/null
+++ b/audio/jack/patches/patch-example-clients_wscript
@@ -0,0 +1,33 @@
+$NetBSD: patch-example-clients_wscript,v 1.1 2021/09/08 19:19:20 nia Exp $
+
+Add NetBSD support.
+
+--- example-clients/wscript.orig 2021-07-15 06:18:26.000000000 +0000
++++ example-clients/wscript
+@@ -33,6 +33,8 @@ def build(bld):
+ os_incdir = ['../macosx', '../posix']
+ if bld.env['IS_SUN']:
+ os_incdir = ['../solaris', '../posix']
++ if bld.env['IS_NETBSD']:
++ os_incdir = ['../netbsd', '../posix']
+ if bld.env['IS_WINDOWS']:
+ os_incdir = ['../windows']
+ for example_program, example_program_source in list(example_programs.items()):
+@@ -58,6 +60,8 @@ def build(bld):
+ prog.use = use
+ if bld.env['IS_LINUX']:
+ prog.use += ['RT', 'M']
++ if bld.env['IS_NETBSD']:
++ prog.use += ['RT', 'M']
+ if bld.env['IS_SUN']:
+ prog.use += ['M']
+ if bld.env['IS_WINDOWS'] and bld.env['BUILD_STATIC']:
+@@ -76,6 +80,8 @@ def build(bld):
+ prog.use += ['SNDFILE']
+ if bld.env['IS_LINUX']:
+ prog.use += ['RT', 'SNDFILE']
++ if bld.env['IS_NETBSD']:
++ prog.use += ['RT', 'SNDFILE']
+ if bld.env['IS_SUN']:
+ prog.use += ['RT', 'SNDFILE']
+ if bld.env['IS_WINDOWS']:
diff --git a/audio/jack/patches/patch-include_engine.h b/audio/jack/patches/patch-include_engine.h
deleted file mode 100644
index 37407b6c14d..00000000000
--- a/audio/jack/patches/patch-include_engine.h
+++ /dev/null
@@ -1,19 +0,0 @@
-$NetBSD: patch-include_engine.h,v 1.1 2019/06/15 08:21:33 adam Exp $
-
-Allow overriding the watchdog timeout.
-
---- include/engine.h.orig 2016-03-02 22:50:14.000000000 +0000
-+++ include/engine.h
-@@ -56,8 +56,12 @@ typedef struct _jack_reserved_name {
- char name[JACK_CLIENT_NAME_SIZE];
- } jack_reserved_name_t;
-
-+#ifndef JACKD_WATCHDOG_TIMEOUT
- #define JACKD_WATCHDOG_TIMEOUT 10000
-+#endif
-+#ifndef JACKD_CLIENT_EVENT_TIMEOUT
- #define JACKD_CLIENT_EVENT_TIMEOUT 2000
-+#endif
-
- /* The main engine structure in local memory. */
- struct _jack_engine {
diff --git a/audio/jack/patches/patch-jack_control.h b/audio/jack/patches/patch-jack_control.h
deleted file mode 100644
index 6d11ea7e6fa..00000000000
--- a/audio/jack/patches/patch-jack_control.h
+++ /dev/null
@@ -1,16 +0,0 @@
-$NetBSD: patch-jack_control.h,v 1.1 2013/02/27 17:49:14 jperkin Exp $
-
-Remove obsolete __sun__ barrier, SunOS has stdbool.h now.
-
---- jack/control.h.orig 2011-06-23 15:09:05.000000000 +0000
-+++ jack/control.h
-@@ -31,9 +31,7 @@
-
- #include <jack/jslist.h>
-
--#if !defined (__sun__)
- #include <stdbool.h>
--#endif
-
- /** Parameter types, intentionally similar to jack_driver_param_type_t */
- typedef enum
diff --git a/audio/jack/patches/patch-jack_types.h b/audio/jack/patches/patch-jack_types.h
deleted file mode 100644
index f4e41a0c39b..00000000000
--- a/audio/jack/patches/patch-jack_types.h
+++ /dev/null
@@ -1,15 +0,0 @@
-$NetBSD: patch-jack_types.h,v 1.1 2019/06/15 08:21:33 adam Exp $
-
-size_t is more suitable for jack_shmsize_t.
-
---- jack/types.h.orig 2016-09-14 22:01:23.000000000 +0000
-+++ jack/types.h
-@@ -26,7 +26,7 @@
-
- typedef uint64_t jack_uuid_t;
-
--typedef int32_t jack_shmsize_t;
-+typedef size_t jack_shmsize_t;
-
- #ifndef POST_PACKED_STRUCTURE
- #ifdef __GNUC__
diff --git a/audio/jack/patches/patch-jackd_engine.c b/audio/jack/patches/patch-jackd_engine.c
deleted file mode 100644
index cd71d6c024c..00000000000
--- a/audio/jack/patches/patch-jackd_engine.c
+++ /dev/null
@@ -1,16 +0,0 @@
-$NetBSD: patch-jackd_engine.c,v 1.1 2019/06/15 08:21:33 adam Exp $
-
-BSD poll returns POLLIN, not POLLHUP, when the socket is closed,
-as does Darwin.
-
---- jackd/engine.c.orig 2016-09-14 17:41:53.000000000 +0000
-+++ jackd/engine.c
-@@ -1435,7 +1435,7 @@ handle_external_client_request (jack_eng
- if ((r = read (client->request_fd, &req, sizeof(req)))
- < (ssize_t)sizeof(req)) {
- if (r == 0) {
--#if defined(JACK_USE_MACH_THREADS) || defined(__OpenBSD__)
-+#if defined(JACK_HOST_HAS_BSD_POLL) || defined(JACK_USE_MACH_THREADS)
- /* poll is implemented using
- select (see the macosx/fakepoll
- code). When the socket is closed
diff --git a/audio/jack/patches/patch-libjack_unlock.c b/audio/jack/patches/patch-libjack_unlock.c
deleted file mode 100644
index 9f201cb4b80..00000000000
--- a/audio/jack/patches/patch-libjack_unlock.c
+++ /dev/null
@@ -1,28 +0,0 @@
-$NetBSD: patch-libjack_unlock.c,v 1.1 2019/06/15 08:21:33 adam Exp $
-
-Yuck. At least let's attempt to make this somewhat sane.
-When I have the time and figure out the Right Thing(tm)
-to do, perhaps I'll rewrite some of the shm code.
-
---- libjack/unlock.c.orig 2016-02-23 15:13:53.000000000 +0000
-+++ libjack/unlock.c
-@@ -44,8 +44,8 @@ static char* whitelist[] = {
- static char* library_roots[] = {
- "/lib",
- "/usr/lib",
-- "/usr/local/lib",
-- "/usr/X11R6/lib",
-+ "@PREFIX@/lib",
-+ "@X11BASE@/lib",
- "/opt/lib", /* solaris-y */
- "/opt/local/lib", /* common on OS X */
- NULL
-@@ -63,7 +63,7 @@ cleanup_mlock ()
- int whoknows;
- int looks_like_library;
-
-- snprintf (path, sizeof(path), "/proc/%d/maps", getpid ());
-+ snprintf (path, sizeof(path), "@JACKD_PROCFS_PATH@/%d/maps", getpid ());
-
- if ((map = fopen (path, "r")) == NULL) {
- jack_error ("can't open map file");
diff --git a/audio/jack/patches/patch-netbsd_JackAtomic__os.h b/audio/jack/patches/patch-netbsd_JackAtomic__os.h
new file mode 100644
index 00000000000..9855f48fe34
--- /dev/null
+++ b/audio/jack/patches/patch-netbsd_JackAtomic__os.h
@@ -0,0 +1,39 @@
+$NetBSD: patch-netbsd_JackAtomic__os.h,v 1.1 2021/09/08 19:19:20 nia Exp $
+
+Add NetBSD support.
+
+--- netbsd/JackAtomic_os.h.orig 2021-09-08 13:51:19.683563214 +0000
++++ netbsd/JackAtomic_os.h
+@@ -0,0 +1,32 @@
++/*
++Copyright (C) 2004-2008 Grame
++
++This program is free software; you can redistribute it and/or modify
++it under the terms of the GNU Lesser General Public License as published by
++the Free Software Foundation; either version 2.1 of the License, or
++(at your option) any later version.
++
++This program is distributed in the hope that it will be useful,
++but WITHOUT ANY WARRANTY; without even the implied warranty of
++MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
++GNU Lesser General Public License for more details.
++
++You should have received a copy of the GNU Lesser General Public License
++along with this program; if not, write to the Free Software
++Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
++
++*/
++
++#ifndef __JackAtomic_netbsd__
++#define __JackAtomic_netbsd__
++
++#include "JackTypes.h"
++#include <atomic.h>
++
++static inline char CAS(volatile UInt32 value, UInt32 newvalue, volatile void* addr)
++{
++ return (atomic_cas_32((uint32_t*)addr, value, newvalue) == value);
++}
++
++#endif
++
diff --git a/audio/jack/patches/patch-netbsd_JackNetBSDTime.c b/audio/jack/patches/patch-netbsd_JackNetBSDTime.c
new file mode 100644
index 00000000000..7be45d94067
--- /dev/null
+++ b/audio/jack/patches/patch-netbsd_JackNetBSDTime.c
@@ -0,0 +1,97 @@
+$NetBSD: patch-netbsd_JackNetBSDTime.c,v 1.1 2021/09/08 19:19:20 nia Exp $
+
+Add NetBSD support.
+
+--- netbsd/JackNetBSDTime.c.orig 2021-09-08 13:51:19.683998596 +0000
++++ netbsd/JackNetBSDTime.c
+@@ -0,0 +1,90 @@
++/*
++Copyright (C) 2001-2003 Paul Davis
++Copyright (C) 2005 Jussi Laako
++Copyright (C) 2004-2008 Grame
++Copyright (C) 2018 Greg V
++
++This program is free software; you can redistribute it and/or modify
++it under the terms of the GNU Lesser General Public License as published by
++the Free Software Foundation; either version 2.1 of the License, or
++(at your option) any later version.
++
++This program is distributed in the hope that it will be useful,
++but WITHOUT ANY WARRANTY; without even the implied warranty of
++MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
++GNU Lesser General Public License for more details.
++
++You should have received a copy of the GNU Lesser General Public License
++along with this program; if not, write to the Free Software
++Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
++
++*/
++
++#include "JackConstants.h"
++#include "JackTime.h"
++#include "JackTypes.h"
++#include "JackError.h"
++
++#include <time.h>
++#include <unistd.h>
++
++jack_time_t (*_jack_get_microseconds)(void) = 0;
++
++static jack_time_t jack_get_microseconds_from_system (void)
++{
++ jack_time_t jackTime;
++ struct timespec time;
++
++ clock_gettime(CLOCK_MONOTONIC, &time);
++ jackTime = (jack_time_t) time.tv_sec * 1e6 +
++ (jack_time_t) time.tv_nsec / 1e3;
++ return jackTime;
++}
++
++
++SERVER_EXPORT void JackSleep(long usec)
++{
++ usleep(usec);
++}
++
++SERVER_EXPORT void InitTime()
++{
++ /* nothing to do on a generic system - we use the system clock */
++}
++
++SERVER_EXPORT void EndTime()
++{}
++
++void SetClockSource(jack_timer_type_t source)
++{
++ jack_log("Clock source : %s", ClockSourceName(source));
++
++ switch (source)
++ {
++ case JACK_TIMER_SYSTEM_CLOCK:
++ default:
++ _jack_get_microseconds = jack_get_microseconds_from_system;
++ break;
++ }
++}
++
++const char* ClockSourceName(jack_timer_type_t source)
++{
++ switch (source) {
++ case JACK_TIMER_SYSTEM_CLOCK:
++ return "system clock via clock_gettime";
++ }
++
++ return "unknown";
++}
++
++SERVER_EXPORT jack_time_t GetMicroSeconds()
++{
++ return _jack_get_microseconds();
++}
++
++SERVER_EXPORT jack_time_t jack_get_microseconds()
++{
++ return _jack_get_microseconds();
++}
++
diff --git a/audio/jack/patches/patch-netbsd_JackPlatformPlug__os.h b/audio/jack/patches/patch-netbsd_JackPlatformPlug__os.h
new file mode 100644
index 00000000000..3f673f06e09
--- /dev/null
+++ b/audio/jack/patches/patch-netbsd_JackPlatformPlug__os.h
@@ -0,0 +1,91 @@
+$NetBSD: patch-netbsd_JackPlatformPlug__os.h,v 1.1 2021/09/08 19:19:20 nia Exp $
+
+Add NetBSD support.
+
+--- netbsd/JackPlatformPlug_os.h.orig 2021-09-08 13:51:19.684677877 +0000
++++ netbsd/JackPlatformPlug_os.h
+@@ -0,0 +1,84 @@
++/*
++Copyright (C) 2004-2008 Grame
++
++This program is free software; you can redistribute it and/or modify
++it under the terms of the GNU Lesser General Public License as published by
++the Free Software Foundation; either version 2.1 of the License, or
++(at your option) any later version.
++
++This program is distributed in the hope that it will be useful,
++but WITHOUT ANY WARRANTY; without even the implied warranty of
++MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
++GNU Lesser General Public License for more details.
++
++You should have received a copy of the GNU Lesser General Public License
++along with this program; if not, write to the Free Software
++Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
++
++*/
++
++#ifndef __JackPlatformPlug_netbsd__
++#define __JackPlatformPlug_netbsd__
++
++#define jack_server_dir "/tmp"
++#define jack_client_dir "/tmp"
++#define JACK_DEFAULT_DRIVER "sun"
++
++namespace Jack
++{
++ struct JackRequest;
++ struct JackResult;
++
++ class JackPosixMutex;
++ class JackPosixThread;
++ class JackPosixSemaphore;
++
++ class JackSocketServerChannel;
++ class JackSocketClientChannel;
++ class JackSocketServerNotifyChannel;
++ class JackSocketNotifyChannel;
++ class JackClientSocket;
++ class JackNetUnixSocket;
++}
++
++/* __JackPlatformMutex__ */
++#include "JackPosixMutex.h"
++namespace Jack {typedef JackPosixMutex JackMutex; }
++
++/* __JackPlatformThread__ */
++#include "JackPosixThread.h"
++namespace Jack { typedef JackPosixThread JackThread; }
++
++/* __JackPlatformSynchro__ client activation */
++#include "JackPosixSemaphore.h"
++namespace Jack { typedef JackPosixSemaphore JackSynchro; }
++
++/* __JackPlatformChannelTransaction__ */
++#include "JackSocket.h"
++namespace Jack { typedef JackClientSocket JackChannelTransaction; }
++
++/* __JackPlatformProcessSync__ */
++#include "JackPosixProcessSync.h"
++namespace Jack { typedef JackPosixProcessSync JackProcessSync; }
++
++/* __JackPlatformServerChannel__ */
++#include "JackSocketServerChannel.h"
++namespace Jack { typedef JackSocketServerChannel JackServerChannel; }
++
++/* __JackPlatformClientChannel__ */
++#include "JackSocketClientChannel.h"
++namespace Jack { typedef JackSocketClientChannel JackClientChannel; }
++
++/* __JackPlatformServerNotifyChannel__ */
++#include "JackSocketServerNotifyChannel.h"
++namespace Jack { typedef JackSocketServerNotifyChannel JackServerNotifyChannel; }
++
++/* __JackPlatformNotifyChannel__ */
++#include "JackSocketNotifyChannel.h"
++namespace Jack { typedef JackSocketNotifyChannel JackNotifyChannel; }
++
++/* __JackPlatformNetSocket__ */
++#include "JackNetUnixSocket.h"
++namespace Jack { typedef JackNetUnixSocket JackNetSocket; }
++
++#endif
diff --git a/audio/jack/patches/patch-netbsd_sun_JackSunAdapter.cpp b/audio/jack/patches/patch-netbsd_sun_JackSunAdapter.cpp
new file mode 100644
index 00000000000..724b04f9fb6
--- /dev/null
+++ b/audio/jack/patches/patch-netbsd_sun_JackSunAdapter.cpp
@@ -0,0 +1,485 @@
+$NetBSD: patch-netbsd_sun_JackSunAdapter.cpp,v 1.1 2021/09/08 19:19:20 nia Exp $
+
+Add NetBSD support.
+
+--- netbsd/sun/JackSunAdapter.cpp.orig 2021-09-08 13:51:19.685213690 +0000
++++ netbsd/sun/JackSunAdapter.cpp
+@@ -0,0 +1,478 @@
++/*
++Copyright (C) 2008 Grame & RTL 2008
++
++This program is free software; you can redistribute it and/or modify
++it under the terms of the GNU General Public License as published by
++the Free Software Foundation; either version 2 of the License, or
++(at your option) any later version.
++
++This program is distributed in the hope that it will be useful,
++but WITHOUT ANY WARRANTY; without even the implied warranty of
++MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
++GNU General Public License for more details.
++
++You should have received a copy of the GNU General Public License
++along with this program; if not, write to the Free Software
++Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
++
++*/
++
++#include "JackSunAdapter.h"
++#include "JackServerGlobals.h"
++#include "JackEngineControl.h"
++#include "memops.h"
++
++#include <sys/ioctl.h>
++#include <sys/audioio.h>
++#include <fcntl.h>
++#include <iostream>
++#include <assert.h>
++
++namespace Jack
++{
++
++inline int int2pow2(int x) { int r = 0; while ((1 << r) < x) r++; return r; }
++
++static inline void CopyAndConvertIn(jack_sample_t *dst, void *src, size_t nframes, int channel, int chcount, int bits)
++{
++#if 0
++ switch (bits) {
++
++ case 16: {
++ signed short *s16src = (signed short*)src;
++ s16src += channel;
++ sample_move_dS_s16(dst, (char*)s16src, nframes, chcount<<1);
++ break;
++ }
++ case 24: {
++ signed int *s32src = (signed int*)src;
++ s32src += channel;
++ sample_move_dS_s24(dst, (char*)s32src, nframes, chcount<<2);
++ break;
++ }
++ case 32: {
++ signed int *s32src = (signed int*)src;
++ s32src += channel;
++ sample_move_dS_s32u24(dst, (char*)s32src, nframes, chcount<<2);
++ break;
++ }
++ }
++#endif
++}
++
++static inline void CopyAndConvertOut(void *dst, jack_sample_t *src, size_t nframes, int channel, int chcount, int bits)
++{
++#if 0
++ switch (bits) {
++
++ case 16: {
++ signed short *s16dst = (signed short*)dst;
++ s16dst += channel;
++ sample_move_d16_sS((char*)s16dst, src, nframes, chcount<<1, NULL); // No dithering for now...
++ break;
++ }
++ case 24: {
++ signed int *s32dst = (signed int*)dst;
++ s32dst += channel;
++ sample_move_d24_sS((char*)s32dst, src, nframes, chcount<<2, NULL); // No dithering for now...
++ break;
++ }
++ case 32: {
++ signed int *s32dst = (signed int*)dst;
++ s32dst += channel;
++ sample_move_d32u24_sS((char*)s32dst, src, nframes, chcount<<2, NULL);
++ break;
++ }
++ }
++#endif
++}
++
++JackSunAdapter::JackSunAdapter(jack_nframes_t buffer_size, jack_nframes_t sample_rate, const JSList* params)
++ :JackAudioAdapterInterface(buffer_size, sample_rate)
++ ,fThread(this),
++ fInFD(-1), fOutFD(-1), fPrecision(SUN_DRIVER_DEF_BITS),
++ fRWMode(0),
++ fInputBufferSize(0), fOutputBufferSize(0),
++ fInputBuffer(NULL), fOutputBuffer(NULL)
++{
++ const JSList* node;
++ const jack_driver_param_t* param;
++
++ fCaptureChannels = 2;
++ fPlaybackChannels = 2;
++
++ strcpy(fCaptureDriverName, SUN_DRIVER_DEF_DEV);
++ strcpy(fPlaybackDriverName, SUN_DRIVER_DEF_DEV);
++
++ for (node = params; node; node = jack_slist_next(node)) {
++ param = (const jack_driver_param_t*) node->data;
++
++ switch (param->character) {
++
++ case 'r':
++ SetAdaptedSampleRate(param->value.ui);
++ break;
++
++ case 'p':
++ SetAdaptedBufferSize(param->value.ui);
++ break;
++
++ case 'w':
++ fPrecision = param->value.i;
++ break;
++
++ case 'i':
++ fCaptureChannels = param->value.ui;
++ break;
++
++ case 'o':
++ fPlaybackChannels = param->value.ui;
++ break;
++
++ case 'C':
++ fRWMode |= kRead;
++ if (strcmp(param->value.str, "none") != 0) {
++ strcpy(fCaptureDriverName, param->value.str);
++ }
++ break;
++
++ case 'P':
++ fRWMode |= kWrite;
++ if (strcmp(param->value.str, "none") != 0) {
++ strcpy(fPlaybackDriverName, param->value.str);
++ }
++ break;
++
++ case 'd':
++ fRWMode |= kRead;
++ fRWMode |= kWrite;
++ strcpy(fCaptureDriverName, param->value.str);
++ strcpy(fPlaybackDriverName, param->value.str);
++ break;
++
++ case 'q':
++ fQuality = param->value.ui;
++ break;
++
++ case 'g':
++ fRingbufferCurSize = param->value.ui;
++ fAdaptative = false;
++ break;
++
++ }
++ }
++
++ fRWMode |= kRead;
++ fRWMode |= kWrite;
++}
++
++void JackSunAdapter::DisplayDeviceInfo()
++{
++}
++
++int JackSunAdapter::OpenInput()
++{
++ struct audio_info info;
++
++ if ((fInFD = open(fCaptureDriverName, O_RDONLY)) < 0) {
++ jack_error("JackSunAdapter::OpenInput failed to open device : %s@%i, errno = %d", __FILE__, __LINE__, errno);
++ return -1;
++ }
++
++ if (fCaptureChannels == 0) {
++ if (ioctl(fInFD, AUDIO_GETFORMAT, &info) != -1) {
++ fCaptureChannels = info.record.channels;
++ }
++ }
++
++ jack_log("JackSunAdapter::OpenInput input fInFD = %d", fInFD);
++
++ AUDIO_INITINFO(&info);
++ info.record.encoding = AUDIO_ENCODING_SLINEAR;
++ info.record.precision = fPrecision;
++ info.record.channels = fCaptureChannels;
++ info.record.sample_rate = fAdaptedSampleRate;
++
++ if (ioctl(fInFD, AUDIO_SETINFO, &info) == -1) {
++ jack_error("JackSunAdapter::OpenInput failed to set device parameters : %s@%i, errno = %d", __FILE__, __LINE__, errno);
++ goto error;
++ }
++
++ if (ioctl(fInFD, AUDIO_GETINFO, &info) == -1) {
++ jack_error("JackSunAdapter::OpenInput failed to get device paramters : %s@%i, errno = %d", __FILE__, __LINE__, errno);
++ goto error;
++ }
++
++ if (info.record.channels != fCaptureChannels) {
++ jack_info("JackSunAdapter::OpenInput driver forced the number of capture channels %u", info.record.channels);
++ goto error;
++ }
++
++ if (info.record.sample_rate != fAdaptedSampleRate) {
++ jack_info("JackSunAdapter::OpenInput driver forced the sample rate %u", info.record.sample_rate);
++ }
++
++ fInputBufferSize = info.blocksize;
++ fInputBuffer = (void*)calloc(fInputBufferSize, 1);
++ assert(fInputBuffer);
++
++ fInputSampleBuffer = (float**)malloc(fCaptureChannels * sizeof(float*));
++ assert(fInputSampleBuffer);
++
++ for (int i = 0; i < fCaptureChannels; i++) {
++ fInputSampleBuffer[i] = (float*)malloc(fAdaptedBufferSize * sizeof(float));
++ assert(fInputSampleBuffer[i]);
++ }
++ return 0;
++
++error:
++ ::close(fInFD);
++ return -1;
++}
++
++int JackSunAdapter::OpenOutput()
++{
++ struct audio_info info;
++
++ if ((fOutFD = open(fPlaybackDriverName, O_WRONLY)) < 0) {
++ jack_error("JackSunAdapter::OpenOutput failed to open device : %s@%i, errno = %d", __FILE__, __LINE__, errno);
++ return -1;
++ }
++
++ if (fPlaybackChannels == 0) {
++ if (ioctl(fOutFD, AUDIO_GETFORMAT, &info) == 0) {
++ fPlaybackChannels = info.play.channels;
++ }
++ }
++
++ jack_log("JackSunAdapter::OpenOutput input fOutFD = %d", fOutFD);
++
++ AUDIO_INITINFO(&info);
++ info.hiwat = 2;
++ info.play.encoding = AUDIO_ENCODING_SLINEAR;
++ info.play.precision = fPrecision;
++ info.play.channels = fPlaybackChannels;
++ info.play.sample_rate = fAdaptedSampleRate;
++
++ if (ioctl(fOutFD, AUDIO_SETINFO, &info) == -1) {
++ jack_error("JackSunAdapter::OpenOutput failed to set device parameters : %s@%i, errno = %d", __FILE__, __LINE__, errno);
++ goto error;
++ }
++
++ if (ioctl(fOutFD, AUDIO_GETINFO, &info) == -1) {
++ jack_error("JackSunAdapter::OpenOutput failed to get device paramters : %s@%i, errno = %d", __FILE__, __LINE__, errno);
++ goto error;
++ }
++
++ if (info.play.precision != fPrecision) {
++ jack_info("JackSunAdapter::OpenOutput driver forced the precision %u", info.play.precision);
++ goto error;
++ }
++
++ if (info.play.channels != fPlaybackChannels) {
++ jack_info("JackSunAdapter::OpenOutput driver forced the number of capture channels %u", info.play.channels);
++ goto error;
++ }
++
++ if (info.play.sample_rate != fAdaptedSampleRate) {
++ jack_info("JackSunAdapter::OpenOutput driver forced the sample rate %u", info.play.sample_rate);
++ }
++
++ fOutputBufferSize = info.blocksize;
++ fOutputBuffer = (void*)calloc(fOutputBufferSize, 1);
++ assert(fOutputBuffer);
++
++ fOutputSampleBuffer = (float**)malloc(fPlaybackChannels * sizeof(float*));
++ assert(fOutputSampleBuffer);
++
++ for (int i = 0; i < fPlaybackChannels; i++) {
++ fOutputSampleBuffer[i] = (float*)malloc(fAdaptedBufferSize * sizeof(float));
++ assert(fOutputSampleBuffer[i]);
++ }
++
++ return 0;
++
++error:
++ ::close(fOutFD);
++ return -1;
++}
++
++int JackSunAdapter::Open()
++{
++ if ((fRWMode & kRead) && (OpenInput() < 0)) {
++ return -1;
++ }
++
++ if ((fRWMode & kWrite) && (OpenOutput() < 0)) {
++ return -1;
++ }
++
++ // In duplex mode, check that input and output use the same buffer size
++ if ((fRWMode & kRead) && (fRWMode & kWrite) && (fInputBufferSize != fOutputBufferSize)) {
++ jack_error("JackSunAdapter::OpenAux input and output buffer size are not the same!!");
++ goto error;
++ }
++
++ DisplayDeviceInfo();
++
++ //start adapter thread
++ if (fThread.StartSync() < 0) {
++ jack_error ( "Cannot start audioadapter thread" );
++ return -1;
++ }
++
++ //turn the thread realtime
++ fThread.AcquireRealTime(JackServerGlobals::fInstance->GetEngineControl()->fClientPriority);
++ return 0;
++
++error:
++ CloseAux();
++ return -1;
++}
++
++
++int JackSunAdapter::Close()
++{
++#ifdef JACK_MONITOR
++ fTable.Save(fHostBufferSize, fHostSampleRate, fAdaptedSampleRate, fAdaptedBufferSize);
++#endif
++ fThread.Stop();
++ CloseAux();
++ return 0;
++}
++
++void JackSunAdapter::CloseAux()
++{
++ if (fRWMode & kRead) {
++ close(fInFD);
++ fInFD = -1;
++ }
++
++ if (fRWMode & kWrite) {
++ close(fOutFD);
++ fOutFD = -1;
++ }
++
++ free(fInputBuffer);
++ fInputBuffer = NULL;
++
++ free(fOutputBuffer);
++ fOutputBuffer = NULL;
++
++ for (int i = 0; i < fCaptureChannels; i++) {
++ free(fInputSampleBuffer[i]);
++ }
++ free(fInputSampleBuffer);
++
++ for (int i = 0; i < fPlaybackChannels; i++) {
++ free(fOutputSampleBuffer[i]);
++ }
++ free(fOutputSampleBuffer);
++ }
++
++int JackSunAdapter::Read()
++{
++ ssize_t count = ::read(fInFD, fInputBuffer, fInputBufferSize);
++
++ if (count < fInputBufferSize) {
++ jack_error("JackSunAdapter::Read error bytes read = %ld", count);
++ return -1;
++ } else {
++ for (int i = 0; i < fCaptureChannels; i++) {
++ CopyAndConvertIn(fInputSampleBuffer[i], fInputBuffer, fAdaptedBufferSize, i, fCaptureChannels, fPrecision);
++ }
++ return 0;
++ }
++}
++
++int JackSunAdapter::Write()
++{
++ ssize_t count;
++
++ for (int i = 0; i < fPlaybackChannels; i++) {
++ CopyAndConvertOut(fOutputBuffer, fOutputSampleBuffer[i], fAdaptedBufferSize, i, fCaptureChannels, fPrecision);
++ }
++
++ count = ::write(fOutFD, fOutputBuffer, fOutputBufferSize);
++
++ if (count < fOutputBufferSize) {
++ jack_error("JackSunAdapter::Write error bytes written = %ld", count);
++ return -1;
++ } else {
++ return 0;
++ }
++}
++
++bool JackSunAdapter::Execute()
++{
++ //read data from audio interface
++ if (Read() < 0)
++ return false;
++
++ PushAndPull(fInputSampleBuffer, fOutputSampleBuffer, fAdaptedBufferSize);
++
++ //write data to audio interface
++ if (Write() < 0)
++ return false;
++
++ return true;
++}
++
++int JackSunAdapter::SetBufferSize(jack_nframes_t buffer_size)
++{
++ JackAudioAdapterInterface::SetBufferSize(buffer_size);
++ Close();
++ return Open();
++}
++
++} // namespace
++
++#ifdef __cplusplus
++extern "C"
++{
++#endif
++
++ SERVER_EXPORT jack_driver_desc_t* jack_get_descriptor()
++ {
++ jack_driver_desc_t * desc;
++ jack_driver_desc_filler_t filler;
++ jack_driver_param_value_t value;
++
++ desc = jack_driver_descriptor_construct("audioadapter", JackDriverNone, "netjack audio <==> net backend adapter", &filler);
++
++ value.ui = SUN_DRIVER_DEF_FS;
++ jack_driver_descriptor_add_parameter(desc, &filler, "rate", 'r', JackDriverParamUInt, &value, NULL, "Sample rate", NULL);
++
++ value.ui = SUN_DRIVER_DEF_BLKSIZE;
++ jack_driver_descriptor_add_parameter(desc, &filler, "period", 'p', JackDriverParamUInt, &value, NULL, "Frames per period", NULL);
++
++ value.i = SUN_DRIVER_DEF_BITS;
++ jack_driver_descriptor_add_parameter(desc, &filler, "wordlength", 'w', JackDriverParamInt, &value, NULL, "Word length", NULL);
++
++ value.ui = SUN_DRIVER_DEF_INS;
++ jack_driver_descriptor_add_parameter(desc, &filler, "in-channels", 'i', JackDriverParamUInt, &value, NULL, "Capture channels", NULL);
++
++ value.ui = SUN_DRIVER_DEF_OUTS;
++ jack_driver_descriptor_add_parameter(desc, &filler, "out-channels", 'o', JackDriverParamUInt, &value, NULL, "Playback channels", NULL);
++
++ strcpy(value.str, SUN_DRIVER_DEF_DEV);
++ jack_driver_descriptor_add_parameter(desc, &filler, "capture", 'C', JackDriverParamString, &value, NULL, "Input device", NULL);
++ jack_driver_descriptor_add_parameter(desc, &filler, "playback", 'P', JackDriverParamString, &value, NULL, "Output device", NULL);
++ jack_driver_descriptor_add_parameter(desc, &filler, "device", 'd', JackDriverParamString, &value, NULL, "Audio device name", NULL);
++
++ value.i = true;
++ jack_driver_descriptor_add_parameter(desc, &filler, "ignorehwbuf", 'b', JackDriverParamBool, &value, NULL, "Ignore hardware period size", NULL);
++
++ value.ui = 0;
++ jack_driver_descriptor_add_parameter(desc, &filler, "quality", 'q', JackDriverParamInt, &value, NULL, "Resample algorithm quality (0 - 4)", NULL);
++
++ value.i = 32768;
++ jack_driver_descriptor_add_parameter(desc, &filler, "ring-buffer", 'g', JackDriverParamInt, &value, NULL, "Fixed ringbuffer size", "Fixed ringbuffer size (if not set => automatic adaptative)");
++
++ return desc;
++ }
++
++#ifdef __cplusplus
++}
++#endif
++
diff --git a/audio/jack/patches/patch-netbsd_sun_JackSunAdapter.h b/audio/jack/patches/patch-netbsd_sun_JackSunAdapter.h
new file mode 100644
index 00000000000..430462a7f07
--- /dev/null
+++ b/audio/jack/patches/patch-netbsd_sun_JackSunAdapter.h
@@ -0,0 +1,120 @@
+$NetBSD: patch-netbsd_sun_JackSunAdapter.h,v 1.1 2021/09/08 19:19:20 nia Exp $
+
+Add NetBSD support.
+
+--- netbsd/sun/JackSunAdapter.h.orig 2021-09-08 13:51:19.686313010 +0000
++++ netbsd/sun/JackSunAdapter.h
+@@ -0,0 +1,113 @@
++/*
++Copyright (C) 2008 Grame & RTL 2008
++
++This program is free software; you can redistribute it and/or modify
++it under the terms of the GNU General Public License as published by
++the Free Software Foundation; either version 2 of the License, or
++(at your option) any later version.
++
++This program is distributed in the hope that it will be useful,
++but WITHOUT ANY WARRANTY; without even the implied warranty of
++MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
++GNU General Public License for more details.
++
++You should have received a copy of the GNU General Public License
++along with this program; if not, write to the Free Software
++Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
++
++*/
++
++#ifndef __JackSunAdapter__
++#define __JackSunAdapter__
++
++#include <math.h>
++#include <limits.h>
++#include <assert.h>
++#include "JackAudioAdapterInterface.h"
++#include "JackPlatformPlug.h"
++#include "JackError.h"
++#include "jack.h"
++#include "jslist.h"
++
++namespace Jack
++{
++
++typedef jack_default_audio_sample_t jack_sample_t;
++
++#define SUN_DRIVER_DEF_DEV "/dev/audio"
++#define SUN_DRIVER_DEF_FS 48000
++#define SUN_DRIVER_DEF_BLKSIZE 1024
++#define SUN_DRIVER_DEF_BITS 16
++#define SUN_DRIVER_DEF_INS 2
++#define SUN_DRIVER_DEF_OUTS 2
++
++/*!
++\brief The Sun adapter.
++*/
++
++class JackSunAdapter : public JackAudioAdapterInterface, public JackRunnableInterface
++{
++
++ enum { kRead = 1, kWrite = 2, kReadWrite = 3 };
++
++ private:
++
++ JackThread fThread;
++
++ char fCaptureDriverName[JACK_CLIENT_NAME_SIZE+1];
++ char fPlaybackDriverName[JACK_CLIENT_NAME_SIZE+1];
++
++ int fInFD;
++ int fOutFD;
++
++ int fPrecision;
++ int fRWMode;
++
++ unsigned int fInputBufferSize;
++ unsigned int fOutputBufferSize;
++
++ void* fInputBuffer;
++ void* fOutputBuffer;
++
++ float** fInputSampleBuffer;
++ float** fOutputSampleBuffer;
++
++ int OpenInput();
++ int OpenOutput();
++ void CloseAux();
++ void DisplayDeviceInfo();
++
++ public:
++
++ JackSunAdapter(jack_nframes_t buffer_size, jack_nframes_t sample_rate, const JSList* params);
++ ~JackSunAdapter()
++ {}
++
++ int Open();
++ int Close();
++
++ int Read();
++ int Write();
++
++ int SetBufferSize(jack_nframes_t buffer_size);
++
++ bool Execute();
++};
++
++}
++
++#ifdef __cplusplus
++extern "C"
++{
++#endif
++
++#include "JackCompilerDeps.h"
++#include "driver_interface.h"
++
++SERVER_EXPORT jack_driver_desc_t* jack_get_descriptor();
++
++#ifdef __cplusplus
++}
++#endif
++
++#endif
diff --git a/audio/jack/patches/patch-netbsd_sun_JackSunDriver.cpp b/audio/jack/patches/patch-netbsd_sun_JackSunDriver.cpp
new file mode 100644
index 00000000000..201093d1dcc
--- /dev/null
+++ b/audio/jack/patches/patch-netbsd_sun_JackSunDriver.cpp
@@ -0,0 +1,564 @@
+$NetBSD: patch-netbsd_sun_JackSunDriver.cpp,v 1.1 2021/09/08 19:19:20 nia Exp $
+
+Add NetBSD support.
+
+--- netbsd/sun/JackSunDriver.cpp.orig 2021-09-08 13:51:19.686819398 +0000
++++ netbsd/sun/JackSunDriver.cpp
+@@ -0,0 +1,557 @@
++/*
++Copyright (C) 2003-2007 Jussi Laako <jussi@sonarnerd.net>
++Copyright (C) 2008 Grame & RTL 2008
++
++This program is free software; you can redistribute it and/or modify
++it under the terms of the GNU General Public License as published by
++the Free Software Foundation; either version 2 of the License, or
++(at your option) any later version.
++
++This program is distributed in the hope that it will be useful,
++but WITHOUT ANY WARRANTY; without even the implied warranty of
++MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
++GNU General Public License for more details.
++
++You should have received a copy of the GNU General Public License
++along with this program; if not, write to the Free Software
++Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
++
++*/
++
++#include "driver_interface.h"
++#include "JackThreadedDriver.h"
++#include "JackDriverLoader.h"
++#include "JackSunDriver.h"
++#include "JackEngineControl.h"
++#include "JackGraphManager.h"
++#include "JackError.h"
++#include "JackTime.h"
++#include "JackShmMem.h"
++#include "memops.h"
++
++#include <sys/ioctl.h>
++#include <sys/audioio.h>
++#include <errno.h>
++#include <fcntl.h>
++#include <unistd.h>
++
++#include <iostream>
++#include <assert.h>
++#include <stdio.h>
++#include <stdlib.h>
++
++using namespace std;
++
++namespace Jack
++{
++
++inline int int2pow2(int x) { int r = 0; while ((1 << r) < x) r++; return r; }
++
++static inline void CopyAndConvertIn(jack_sample_t *dst, void *src, size_t nframes, int channel, int chcount, int bits)
++{
++ switch (bits) {
++
++ case 16: {
++ signed short *s16src = (signed short*)src;
++ s16src += channel;
++ sample_move_dS_s16(dst, (char*)s16src, nframes, chcount<<1);
++ break;
++ }
++ case 24: {
++ signed int *s32src = (signed int*)src;
++ s32src += channel;
++ sample_move_dS_s24(dst, (char*)s32src, nframes, chcount<<2);
++ break;
++ }
++ case 32: {
++ signed int *s32src = (signed int*)src;
++ s32src += channel;
++ sample_move_dS_s32u24(dst, (char*)s32src, nframes, chcount<<2);
++ break;
++ }
++ }
++}
++
++static inline void CopyAndConvertOut(void *dst, jack_sample_t *src, size_t nframes, int channel, int chcount, int bits)
++{
++ switch (bits) {
++
++ case 16: {
++ signed short *s16dst = (signed short*)dst;
++ s16dst += channel;
++ sample_move_d16_sS((char*)s16dst, src, nframes, chcount<<1, NULL); // No dithering for now...
++ break;
++ }
++ case 24: {
++ signed int *s32dst = (signed int*)dst;
++ s32dst += channel;
++ sample_move_d24_sS((char*)s32dst, src, nframes, chcount<<2, NULL); // No dithering for now...
++ break;
++ }
++ case 32: {
++ signed int *s32dst = (signed int*)dst;
++ s32dst += channel;
++ sample_move_d32u24_sS((char*)s32dst, src, nframes, chcount<<2, NULL);
++ break;
++ }
++ }
++}
++
++int JackSunDriver::OpenInput()
++{
++ struct audio_info info;
++ int new_buffer_size;
++
++ if ((fInFD = open(fCaptureDriverName, O_RDONLY)) < 0) {
++ jack_error("JackSunDriver::OpenInput failed to open device : %s@%i, errno = %d", __FILE__, __LINE__, errno);
++ return -1;
++ }
++
++ if (fCaptureChannels == 0) {
++ if (ioctl(fInFD, AUDIO_GETFORMAT, &info) == 0) {
++ fCaptureChannels = info.record.channels;
++ }
++ }
++
++ jack_log("JackSunDriver::OpenInput input fInFD = %d", fInFD);
++
++ AUDIO_INITINFO(&info);
++ info.record.encoding = AUDIO_ENCODING_SLINEAR;
++ info.record.precision = fPrecision;
++ info.record.channels = fCaptureChannels;
++ info.record.sample_rate = fEngineControl->fSampleRate;
++
++ if (ioctl(fInFD, AUDIO_SETINFO, &info) == -1) {
++ jack_error("JackSunDriver::OpenInput failed to set device parameters : %s@%i, errno = %d", __FILE__, __LINE__, errno);
++ goto error;
++ }
++
++ if (ioctl(fInFD, AUDIO_GETINFO, &info) == -1) {
++ jack_error("JackSunDriver::OpenInput failed to get device paramters : %s@%i, errno = %d", __FILE__, __LINE__, errno);
++ goto error;
++ }
++
++ if (info.record.channels != fCaptureChannels) {
++ jack_info("JackSunDriver::OpenInput driver forced the number of capture channels %u", info.record.channels);
++ goto error;
++ }
++
++ if (info.record.sample_rate != fEngineControl->fSampleRate) {
++ jack_info("JackSunDriver::OpenInput driver forced the sample rate %u", info.record.sample_rate);
++ }
++
++ fInputBufferSize = info.blocksize;
++
++ new_buffer_size = fInputBufferSize / ((info.record.precision / NBBY) * fCaptureChannels);
++
++ JackAudioDriver::SetBufferSize(new_buffer_size); // never fails
++
++ fInputBuffer = (void*)calloc(fInputBufferSize, 1);
++ assert(fInputBuffer);
++ return 0;
++
++error:
++ ::close(fInFD);
++ return -1;
++}
++
++int JackSunDriver::OpenOutput()
++{
++ struct audio_info info;
++ int new_buffer_size;
++
++ if ((fOutFD = open(fPlaybackDriverName, O_WRONLY)) < 0) {
++ jack_error("JackSunDriver::OpenOutput failed to open device : %s@%i, errno = %d", __FILE__, __LINE__, errno);
++ return -1;
++ }
++
++ if (fPlaybackChannels == 0) {
++ if (ioctl(fOutFD, AUDIO_GETFORMAT, &info) == 0) {
++ fPlaybackChannels = info.play.channels;
++ }
++ }
++
++ jack_log("JackSunDriver::OpenOutput input fOutFD = %d", fOutFD);
++
++ AUDIO_INITINFO(&info);
++ info.hiwat = 2;
++ info.play.encoding = AUDIO_ENCODING_SLINEAR;
++ info.play.precision = fPrecision;
++ info.play.channels = fPlaybackChannels;
++ info.play.sample_rate = fEngineControl->fSampleRate;
++
++ if (ioctl(fOutFD, AUDIO_SETINFO, &info) == -1) {
++ jack_error("JackSunDriver::OpenOutput failed to set device parameters : %s@%i, errno = %d", __FILE__, __LINE__, errno);
++ goto error;
++ }
++
++ if (ioctl(fOutFD, AUDIO_GETINFO, &info) == -1) {
++ jack_error("JackSunDriver::OpenOutput failed to get device paramters : %s@%i, errno = %d", __FILE__, __LINE__, errno);
++ goto error;
++ }
++
++ if (info.play.precision != fPrecision) {
++ jack_info("JackSunDriver::OpenOutput driver forced the precision %u", info.play.precision);
++ goto error;
++ }
++
++ if (info.play.channels != fPlaybackChannels) {
++ jack_info("JackSunDriver::OpenOutput driver forced the number of capture channels %u", info.play.channels);
++ goto error;
++ }
++
++ if (info.play.sample_rate != fEngineControl->fSampleRate) {
++ jack_info("JackSunDriver::OpenOutput driver forced the sample rate %u", info.play.sample_rate);
++ }
++
++ fOutputBufferSize = info.blocksize;
++
++ new_buffer_size = fOutputBufferSize / ((info.play.precision / NBBY) * fPlaybackChannels);
++
++ JackAudioDriver::SetBufferSize(new_buffer_size); // never fails
++
++ fOutputBuffer = (void*)calloc(fOutputBufferSize, 1);
++ assert(fOutputBuffer);
++ return 0;
++
++error:
++ ::close(fOutFD);
++ return -1;
++}
++
++int JackSunDriver::Open(jack_nframes_t nframes,
++ jack_nframes_t samplerate,
++ bool capturing,
++ bool playing,
++ int inchannels,
++ int outchannels,
++ bool excl,
++ bool monitor,
++ const char* capture_driver_uid,
++ const char* playback_driver_uid,
++ jack_nframes_t capture_latency,
++ jack_nframes_t playback_latency,
++ int bits)
++{
++ // Generic JackAudioDriver Open
++ if (JackAudioDriver::Open(nframes, samplerate, capturing, playing, inchannels, outchannels, monitor,
++ capture_driver_uid, playback_driver_uid, capture_latency, playback_latency) != 0) {
++ return -1;
++ } else {
++
++ if (!fEngineControl->fSyncMode) {
++ jack_error("Cannot run in asynchronous mode, use the -S parameter for jackd");
++ return -1;
++ }
++
++ fRWMode |= ((capturing) ? kRead : 0);
++ fRWMode |= ((playing) ? kWrite : 0);
++ fPrecision = bits;
++
++ if (OpenAux() < 0) {
++ Close();
++ return -1;
++ } else {
++ return 0;
++ }
++ }
++}
++
++int JackSunDriver::Close()
++{
++ int res = JackAudioDriver::Close();
++ CloseAux();
++ return res;
++}
++
++
++int JackSunDriver::OpenAux()
++{
++ if ((fRWMode & kRead) && (OpenInput() < 0)) {
++ return -1;
++ }
++
++ if ((fRWMode & kWrite) && (OpenOutput() < 0)) {
++ return -1;
++ }
++
++ return 0;
++}
++
++void JackSunDriver::CloseAux()
++{
++ if (fRWMode & kRead && fInFD > 0) {
++ close(fInFD);
++ fInFD = -1;
++ }
++
++ if (fRWMode & kWrite && fOutFD > 0) {
++ close(fOutFD);
++ fOutFD = -1;
++ }
++
++ if (fInputBuffer)
++ free(fInputBuffer);
++ fInputBuffer = NULL;
++
++ if (fOutputBuffer)
++ free(fOutputBuffer);
++ fOutputBuffer = NULL;
++}
++
++int JackSunDriver::Read()
++{
++ if (fInFD < 0) {
++ // Keep begin cycle time
++ JackDriver::CycleTakeBeginTime();
++ return 0;
++ }
++
++ ssize_t count;
++
++ count = ::read(fInFD, fInputBuffer, fInputBufferSize);
++
++ struct audio_info info;
++
++#if 0
++ // XRun detection
++ if (ioctl(fInFD, AUDIO_GETBUFINFO, &info) != -1) {
++ if (info.record.error > 0) {
++ jack_error("JackSunDriver::Read overruns");
++ jack_time_t cur_time = GetMicroSeconds();
++ NotifyXRun(cur_time, float(cur_time - fBeginDateUst)); // Better this value than nothing...
++ }
++ }
++#endif
++
++ if (count < 0) {
++ jack_log("JackSunDriver::Read error = %s", strerror(errno));
++ return -1;
++ } else if (count < (int)fInputBufferSize) {
++ jack_error("JackSunDriver::Read error bytes read = %ld", count);
++ return -1;
++ } else {
++
++ // Keep begin cycle time
++ JackDriver::CycleTakeBeginTime();
++ for (int i = 0; i < fCaptureChannels; i++) {
++ if (fGraphManager->GetConnectionsNum(fCapturePortList[i]) > 0) {
++ CopyAndConvertIn(GetInputBuffer(i), fInputBuffer, fEngineControl->fBufferSize, i, fCaptureChannels, fPrecision);
++ }
++ }
++
++ return 0;
++ }
++}
++
++int JackSunDriver::Write()
++{
++ if (fOutFD < 0) {
++ // Keep end cycle time
++ JackDriver::CycleTakeEndTime();
++ return 0;
++ }
++
++ ssize_t count;
++
++ memset(fOutputBuffer, 0, fOutputBufferSize);
++ for (int i = 0; i < fPlaybackChannels; i++) {
++ if (fGraphManager->GetConnectionsNum(fPlaybackPortList[i]) > 0) {
++ CopyAndConvertOut(fOutputBuffer, GetOutputBuffer(i), fEngineControl->fBufferSize, i, fPlaybackChannels, fPrecision);
++ }
++ }
++
++ // Keep end cycle time
++ JackDriver::CycleTakeEndTime();
++ count = ::write(fOutFD, fOutputBuffer, fOutputBufferSize);
++
++ struct audio_info info;
++
++ // XRun detection
++ if (ioctl(fOutFD, AUDIO_GETBUFINFO, &info) != -1) {
++
++ if (info.play.error > 0) {
++ jack_error("JackSunDriver::Write underruns");
++ jack_time_t cur_time = GetMicroSeconds();
++ NotifyXRun(cur_time, float(cur_time - fBeginDateUst)); // Better this value than nothing...
++ }
++ }
++
++ if (count < 0) {
++ jack_log("JackSunDriver::Write error = %s", strerror(errno));
++ return -1;
++ } else if (count < (int)fOutputBufferSize) {
++ jack_error("JackSunDriver::Write error bytes written = %ld", count);
++ return -1;
++ } else {
++ return 0;
++ }
++}
++
++int JackSunDriver::SetBufferSize(jack_nframes_t buffer_size)
++{
++ CloseAux();
++ JackAudioDriver::SetBufferSize(buffer_size); // Generic change, never fails
++ return OpenAux();
++}
++
++int JackSunDriver::ProcessSync()
++{
++ // Read input buffers for the current cycle
++ if (Read() < 0) {
++ jack_error("ProcessSync: read error, skip cycle");
++ return 0; // Non fatal error here, skip cycle, but continue processing...
++ }
++
++ if (fIsMaster) {
++ ProcessGraphSync();
++ } else {
++ ResumeRefNum();
++ }
++
++ // Write output buffers for the current cycle
++ if (Write() < 0) {
++ jack_error("JackAudioDriver::ProcessSync: write error, skip cycle");
++ return 0; // Non fatal error here, skip cycle, but continue processing...
++ }
++
++ return 0;
++}
++
++} // end of namespace
++
++#ifdef __cplusplus
++extern "C"
++{
++#endif
++
++SERVER_EXPORT jack_driver_desc_t* driver_get_descriptor()
++{
++ jack_driver_desc_t * desc;
++ jack_driver_desc_filler_t filler;
++ jack_driver_param_value_t value;
++
++ desc = jack_driver_descriptor_construct("sun", JackDriverMaster, "Sun API based audio backend", &filler);
++
++ value.ui = SUN_DRIVER_DEF_FS;
++ jack_driver_descriptor_add_parameter(desc, &filler, "rate", 'r', JackDriverParamUInt, &value, NULL, "Sample rate", NULL);
++
++ value.ui = SUN_DRIVER_DEF_BLKSIZE;
++ jack_driver_descriptor_add_parameter(desc, &filler, "period", 'p', JackDriverParamUInt, &value, NULL, "Frames per period", NULL);
++
++ value.i = SUN_DRIVER_DEF_BITS;
++ jack_driver_descriptor_add_parameter(desc, &filler, "wordlength", 'w', JackDriverParamInt, &value, NULL, "Word length", NULL);
++
++ value.ui = SUN_DRIVER_DEF_INS;
++ jack_driver_descriptor_add_parameter(desc, &filler, "inchannels", 'i', JackDriverParamUInt, &value, NULL, "Capture channels", NULL);
++
++ value.ui = SUN_DRIVER_DEF_OUTS;
++ jack_driver_descriptor_add_parameter(desc, &filler, "outchannels", 'o', JackDriverParamUInt, &value, NULL, "Playback channels", NULL);
++
++ strcpy(value.str, SUN_DRIVER_DEF_DEV);
++ jack_driver_descriptor_add_parameter(desc, &filler, "capture", 'C', JackDriverParamString, &value, NULL, "Input device", NULL);
++ jack_driver_descriptor_add_parameter(desc, &filler, "playback", 'P', JackDriverParamString, &value, NULL, "Output device", NULL);
++ jack_driver_descriptor_add_parameter(desc, &filler, "device", 'd', JackDriverParamString, &value, NULL, "Audio device name", NULL);
++
++ value.ui = 0;
++ jack_driver_descriptor_add_parameter(desc, &filler, "input-latency", 'I', JackDriverParamUInt, &value, NULL, "Extra input latency", NULL);
++ jack_driver_descriptor_add_parameter(desc, &filler, "output-latency", 'O', JackDriverParamUInt, &value, NULL, "Extra output latency", NULL);
++
++ return desc;
++}
++
++SERVER_EXPORT Jack::JackDriverClientInterface* driver_initialize(Jack::JackLockedEngine* engine, Jack::JackSynchro* table, const JSList* params)
++{
++ int bits = SUN_DRIVER_DEF_BITS;
++ jack_nframes_t srate = SUN_DRIVER_DEF_FS;
++ jack_nframes_t frames_per_interrupt = SUN_DRIVER_DEF_BLKSIZE;
++ const char* capture_pcm_name = SUN_DRIVER_DEF_DEV;
++ const char* playback_pcm_name = SUN_DRIVER_DEF_DEV;
++ bool capture = false;
++ bool playback = false;
++ int chan_in = 0;
++ int chan_out = 0;
++ bool monitor = false;
++ bool excl = false;
++ const JSList *node;
++ const jack_driver_param_t *param;
++ jack_nframes_t systemic_input_latency = 0;
++ jack_nframes_t systemic_output_latency = 0;
++
++ for (node = params; node; node = jack_slist_next(node)) {
++
++ param = (const jack_driver_param_t *)node->data;
++
++ switch (param->character) {
++
++ case 'r':
++ srate = param->value.ui;
++ break;
++
++ case 'p':
++ frames_per_interrupt = (unsigned int)param->value.ui;
++ break;
++
++ case 'w':
++ bits = param->value.i;
++ break;
++
++ case 'i':
++ chan_in = (int)param->value.ui;
++ break;
++
++ case 'o':
++ chan_out = (int)param->value.ui;
++ break;
++
++ case 'C':
++ capture = true;
++ if (strcmp(param->value.str, "none") != 0) {
++ capture_pcm_name = param->value.str;
++ }
++ break;
++
++ case 'P':
++ playback = true;
++ if (strcmp(param->value.str, "none") != 0) {
++ playback_pcm_name = param->value.str;
++ }
++ break;
++
++ case 'd':
++ playback_pcm_name = param->value.str;
++ capture_pcm_name = param->value.str;
++ break;
++
++ case 'I':
++ systemic_input_latency = param->value.ui;
++ break;
++
++ case 'O':
++ systemic_output_latency = param->value.ui;
++ break;
++ }
++ }
++
++ // duplex is the default
++ if (!capture && !playback) {
++ capture = true;
++ playback = true;
++ }
++
++ Jack::JackSunDriver* sun_driver = new Jack::JackSunDriver("system", "sun", engine, table);
++ Jack::JackDriverClientInterface* threaded_driver = new Jack::JackThreadedDriver(sun_driver);
++
++ // Special open for Sun driver...
++ if (sun_driver->Open(frames_per_interrupt, srate, capture, playback, chan_in, chan_out,
++ excl, monitor, capture_pcm_name, playback_pcm_name, systemic_input_latency, systemic_output_latency, bits) == 0) {
++ return threaded_driver;
++ } else {
++ delete threaded_driver; // Delete the decorated driver
++ return NULL;
++ }
++}
++
++#ifdef __cplusplus
++}
++#endif
diff --git a/audio/jack/patches/patch-netbsd_sun_JackSunDriver.h b/audio/jack/patches/patch-netbsd_sun_JackSunDriver.h
new file mode 100644
index 00000000000..9879cad644c
--- /dev/null
+++ b/audio/jack/patches/patch-netbsd_sun_JackSunDriver.h
@@ -0,0 +1,120 @@
+$NetBSD: patch-netbsd_sun_JackSunDriver.h,v 1.1 2021/09/08 19:19:20 nia Exp $
+
+Add NetBSD support.
+
+--- netbsd/sun/JackSunDriver.h.orig 2021-09-08 13:51:19.687983014 +0000
++++ netbsd/sun/JackSunDriver.h
+@@ -0,0 +1,113 @@
++/*
++Copyright (C) 2003-2007 Jussi Laako <jussi@sonarnerd.net>
++Copyright (C) 2008 Grame & RTL 2008
++
++This program is free software; you can redistribute it and/or modify
++it under the terms of the GNU General Public License as published by
++the Free Software Foundation; either version 2 of the License, or
++(at your option) any later version.
++
++This program is distributed in the hope that it will be useful,
++but WITHOUT ANY WARRANTY; without even the implied warranty of
++MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
++GNU General Public License for more details.
++
++You should have received a copy of the GNU General Public License
++along with this program; if not, write to the Free Software
++Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
++
++*/
++
++#ifndef __JackSunDriver__
++#define __JackSunDriver__
++
++#include "JackAudioDriver.h"
++
++namespace Jack
++{
++
++typedef jack_default_audio_sample_t jack_sample_t;
++
++#define SUN_DRIVER_DEF_DEV "/dev/audio"
++#define SUN_DRIVER_DEF_FS 48000
++#define SUN_DRIVER_DEF_BLKSIZE 1024
++#define SUN_DRIVER_DEF_BITS 16
++#define SUN_DRIVER_DEF_INS 2
++#define SUN_DRIVER_DEF_OUTS 2
++
++/*!
++\brief The Sun driver.
++*/
++
++class JackSunDriver : public JackAudioDriver
++{
++
++ enum { kRead = 1, kWrite = 2, kReadWrite = 3 };
++
++ private:
++
++ int fInFD;
++ int fOutFD;
++
++ int fPrecision;
++ int fRWMode;
++
++ unsigned int fInputBufferSize;
++ unsigned int fOutputBufferSize;
++
++ void* fInputBuffer;
++ void* fOutputBuffer;
++
++ int OpenInput();
++ int OpenOutput();
++ int OpenAux();
++ void CloseAux();
++ void DisplayDeviceInfo();
++
++ // Redefining since timing for CPU load is specific
++ int ProcessSync();
++
++ public:
++
++ JackSunDriver(const char* name, const char* alias, JackLockedEngine* engine, JackSynchro* table)
++ : JackAudioDriver(name, alias, engine, table),
++ fInFD(-1), fOutFD(-1), fPrecision(0),
++ fRWMode(0),
++ fInputBufferSize(0), fOutputBufferSize(0),
++ fInputBuffer(NULL), fOutputBuffer(NULL)
++ {}
++
++ virtual ~JackSunDriver()
++ {}
++
++ int Open(jack_nframes_t frames_per_cycle,
++ jack_nframes_t rate,
++ bool capturing,
++ bool playing,
++ int chan_in,
++ int chan_out,
++ bool vmix,
++ bool monitor,
++ const char* capture_driver_name,
++ const char* playback_driver_name,
++ jack_nframes_t capture_latency,
++ jack_nframes_t playback_latency,
++ int bits);
++
++ int Close();
++
++ int Read();
++ int Write();
++
++ bool IsFixedBufferSize()
++ {
++ return true;
++ }
++
++ int SetBufferSize(jack_nframes_t buffer_size);
++
++};
++
++} // end of namespace
++
++#endif
diff --git a/audio/jack/patches/patch-posix_JackNetUnixSocket.cpp b/audio/jack/patches/patch-posix_JackNetUnixSocket.cpp
new file mode 100644
index 00000000000..2ccde8acf8c
--- /dev/null
+++ b/audio/jack/patches/patch-posix_JackNetUnixSocket.cpp
@@ -0,0 +1,69 @@
+$NetBSD: patch-posix_JackNetUnixSocket.cpp,v 1.1 2021/09/08 19:19:20 nia Exp $
+
+Add NetBSD support.
+
+--- posix/JackNetUnixSocket.cpp.orig 2021-07-15 06:18:26.000000000 +0000
++++ posix/JackNetUnixSocket.cpp
+@@ -280,7 +280,7 @@ namespace Jack
+
+ //timeout************************************************************************************************************
+
+-#if defined(__sun__) || defined(sun)
++#if defined(__sun__) || defined(sun) || defined(__NetBSD__)
+ int JackNetUnixSocket::SetTimeOut(int us)
+ {
+ int flags;
+@@ -389,7 +389,7 @@ namespace Jack
+ //network operations**************************************************************************************************
+ int JackNetUnixSocket::SendTo(const void* buffer, size_t nbytes, int flags)
+ {
+- #if defined(__sun__) || defined(sun)
++ #if defined(__sun__) || defined(sun) || defined(__NetBSD__)
+ if (WaitWrite() < 0) {
+ return -1;
+ }
+@@ -408,7 +408,7 @@ namespace Jack
+ return addr_conv;
+ }
+ fSendAddr.sin_port = htons(fPort);
+- #if defined(__sun__) || defined(sun)
++ #if defined(__sun__) || defined(sun) || defined(__NetBSD__)
+ if (WaitWrite() < 0) {
+ return -1;
+ }
+@@ -418,7 +418,7 @@ namespace Jack
+
+ int JackNetUnixSocket::Send(const void* buffer, size_t nbytes, int flags)
+ {
+- #if defined(__sun__) || defined(sun)
++ #if defined(__sun__) || defined(sun) || defined(__NetBSD__)
+ if (WaitWrite() < 0) {
+ return -1;
+ }
+@@ -433,7 +433,7 @@ namespace Jack
+ int JackNetUnixSocket::RecvFrom(void* buffer, size_t nbytes, int flags)
+ {
+ socklen_t addr_len = sizeof(socket_address_t);
+- #if defined(__sun__) || defined(sun)
++ #if defined(__sun__) || defined(sun) || defined(__NetBSD__)
+ if (WaitRead() < 0) {
+ return -1;
+ }
+@@ -447,7 +447,7 @@ namespace Jack
+
+ int JackNetUnixSocket::Recv(void* buffer, size_t nbytes, int flags)
+ {
+- #if defined(__sun__) || defined(sun)
++ #if defined(__sun__) || defined(sun) || defined(__NetBSD__)
+ if (WaitRead() < 0) {
+ return -1;
+ }
+@@ -462,7 +462,7 @@ namespace Jack
+ int JackNetUnixSocket::CatchHost(void* buffer, size_t nbytes, int flags)
+ {
+ socklen_t addr_len = sizeof(socket_address_t);
+- #if defined(__sun__) || defined(sun)
++ #if defined(__sun__) || defined(sun) || defined(__NetBSD__)
+ if (WaitRead() < 0) {
+ return -1;
+ }
diff --git a/audio/jack/patches/patch-posix_JackNetUnixSocket.h b/audio/jack/patches/patch-posix_JackNetUnixSocket.h
new file mode 100644
index 00000000000..0178aa56d0b
--- /dev/null
+++ b/audio/jack/patches/patch-posix_JackNetUnixSocket.h
@@ -0,0 +1,15 @@
+$NetBSD: patch-posix_JackNetUnixSocket.h,v 1.1 2021/09/08 19:19:20 nia Exp $
+
+Add NetBSD support.
+
+--- posix/JackNetUnixSocket.h.orig 2021-07-15 06:18:26.000000000 +0000
++++ posix/JackNetUnixSocket.h
+@@ -47,7 +47,7 @@ namespace Jack
+
+ struct sockaddr_in fSendAddr;
+ struct sockaddr_in fRecvAddr;
+- #if defined(__sun__) || defined(sun)
++ #if defined(__sun__) || defined(sun) || defined(__NetBSD__)
+ int WaitRead();
+ int WaitWrite();
+ #endif
diff --git a/audio/jack/patches/patch-posix_JackPosixSemaphore.cpp b/audio/jack/patches/patch-posix_JackPosixSemaphore.cpp
new file mode 100644
index 00000000000..70be079de34
--- /dev/null
+++ b/audio/jack/patches/patch-posix_JackPosixSemaphore.cpp
@@ -0,0 +1,24 @@
+$NetBSD: patch-posix_JackPosixSemaphore.cpp,v 1.1 2021/09/08 19:19:20 nia Exp $
+
+NetBSD requires POSIX semaphores to be prefixed with
+a slash, see sem_open(3).
+
+--- posix/JackPosixSemaphore.cpp.orig 2021-07-15 06:18:26.000000000 +0000
++++ posix/JackPosixSemaphore.cpp
+@@ -46,13 +46,13 @@ void JackPosixSemaphore::BuildName(const
+ {
+ char ext_client_name[SYNC_MAX_NAME_SIZE + 1];
+ JackTools::RewriteName(client_name, ext_client_name);
+-#if __APPLE__ // POSIX semaphore names are limited to 32 characters...
++#if __APPLE__ // POSIX semaphore names are limited to 32 characters...
+ snprintf(res, 32, "js_%s", ext_client_name);
+ #else
+ if (fPromiscuous) {
+- snprintf(res, size, "jack_sem.%s_%s", server_name, ext_client_name);
++ snprintf(res, size, "/jack_sem.%s_%s", server_name, ext_client_name);
+ } else {
+- snprintf(res, size, "jack_sem.%d_%s_%s", JackTools::GetUID(), server_name, ext_client_name);
++ snprintf(res, size, "/jack_sem.%d_%s_%s", JackTools::GetUID(), server_name, ext_client_name);
+ }
+ #endif
+ }
diff --git a/audio/jack/patches/patch-posix_JackSocket.cpp b/audio/jack/patches/patch-posix_JackSocket.cpp
new file mode 100644
index 00000000000..e6a42d33656
--- /dev/null
+++ b/audio/jack/patches/patch-posix_JackSocket.cpp
@@ -0,0 +1,33 @@
+$NetBSD: patch-posix_JackSocket.cpp,v 1.1 2021/09/08 19:19:20 nia Exp $
+
+Add NetBSD support.
+
+--- posix/JackSocket.cpp.orig 2021-07-15 06:18:26.000000000 +0000
++++ posix/JackSocket.cpp
+@@ -51,7 +51,7 @@ JackClientSocket::JackClientSocket(): Ja
+ JackClientSocket::JackClientSocket(int socket): JackClientRequestInterface(), fSocket(socket),fTimeOut(0), fPromiscuous(false), fPromiscuousGid(-1)
+ {}
+
+-#if defined(__sun__) || defined(sun)
++#if defined(__sun__) || defined(sun) || defined(__NetBSD__)
+
+ void JackClientSocket::SetReadTimeOut(long sec)
+ {
+@@ -168,7 +168,7 @@ int JackClientSocket::Read(void* data, i
+ {
+ int res;
+
+-#if defined(__sun__) || defined(sun)
++#if defined(__sun__) || defined(sun) || defined(__NetBSD__)
+ if (fTimeOut > 0) {
+
+ struct timeval tv;
+@@ -214,7 +214,7 @@ int JackClientSocket::Write(void* data,
+ {
+ int res;
+
+-#if defined(__sun__) || defined(sun)
++#if defined(__sun__) || defined(sun) || defined(__NetBSD__)
+ if (fTimeOut > 0) {
+
+ struct timeval tv;
diff --git a/audio/jack/patches/patch-tests_wscript b/audio/jack/patches/patch-tests_wscript
new file mode 100644
index 00000000000..c849c28e1cf
--- /dev/null
+++ b/audio/jack/patches/patch-tests_wscript
@@ -0,0 +1,15 @@
+$NetBSD: patch-tests_wscript,v 1.1 2021/09/08 19:19:20 nia Exp $
+
+Add NetBSD support.
+
+--- tests/wscript.orig 2021-07-15 06:18:26.000000000 +0000
++++ tests/wscript
+@@ -20,6 +20,8 @@ def build(bld):
+ prog.includes = ['..','../macosx', '../posix', '../common/jack', '../common']
+ if bld.env['IS_LINUX']:
+ prog.includes = ['..','../linux', '../posix', '../common/jack', '../common']
++ if bld.env['IS_NETBSD']:
++ prog.includes = ['..','../netbsd', '../posix', '../common/jack', '../common']
+ if bld.env['IS_SUN']:
+ prog.includes = ['..','../solaris', '../posix', '../common/jack', '../common']
+ prog.source = test_program_sources
diff --git a/audio/jack/patches/patch-tools_netsource.c b/audio/jack/patches/patch-tools_netsource.c
deleted file mode 100644
index dd743de1a75..00000000000
--- a/audio/jack/patches/patch-tools_netsource.c
+++ /dev/null
@@ -1,17 +0,0 @@
-$NetBSD: patch-tools_netsource.c,v 1.2 2019/06/19 11:43:04 jperkin Exp $
-
-Include alloca.h if required.
-
---- tools/netsource.c.orig 2016-09-14 22:01:23.000000000 +0000
-+++ tools/netsource.c
-@@ -28,6 +28,10 @@ Foundation, Inc., 675 Mass Ave, Cambridg
-
- #include "config.h"
-
-+#ifdef __sun
-+#include <alloca.h>
-+#endif
-+
- #include <stdio.h>
- #include <errno.h>
- #include <unistd.h>
diff --git a/audio/jack/patches/patch-tools_session__notify.c b/audio/jack/patches/patch-tools_session__notify.c
deleted file mode 100644
index e3fef008509..00000000000
--- a/audio/jack/patches/patch-tools_session__notify.c
+++ /dev/null
@@ -1,16 +0,0 @@
-$NetBSD: patch-tools_session__notify.c,v 1.1 2013/02/27 17:49:15 jperkin Exp $
-
-Need alloca.h on SunOS.
-
---- tools/session_notify.c.orig 2010-04-13 19:27:48.000000000 +0000
-+++ tools/session_notify.c
-@@ -18,6 +18,9 @@
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-+#ifdef __sun
-+#include <alloca.h>
-+#endif
- #include <stdio.h>
- #include <errno.h>
- #include <unistd.h>
diff --git a/audio/jack/patches/patch-tools_transport.c b/audio/jack/patches/patch-tools_transport.c
deleted file mode 100644
index 09fd426d64d..00000000000
--- a/audio/jack/patches/patch-tools_transport.c
+++ /dev/null
@@ -1,15 +0,0 @@
-$NetBSD: patch-tools_transport.c,v 1.1 2019/06/15 08:21:33 adam Exp $
-
---- tools/transport.c.orig 2008-11-11 17:36:30.000000000 -0500
-+++ tools/transport.c
-@@ -29,6 +29,10 @@
- #include <jack/jack.h>
- #include <jack/transport.h>
-
-+#ifndef whitespace
-+#define whitespace(c) (((c) == ' ') || ((c) == '\t'))
-+#endif
-+
- char *package; /* program name */
- int done = 0;
- jack_client_t *client;
diff --git a/audio/jack/patches/patch-tools_wscript b/audio/jack/patches/patch-tools_wscript
new file mode 100644
index 00000000000..9a6a62170b6
--- /dev/null
+++ b/audio/jack/patches/patch-tools_wscript
@@ -0,0 +1,15 @@
+$NetBSD: patch-tools_wscript,v 1.1 2021/09/08 19:19:20 nia Exp $
+
+Add NetBSD support.
+
+--- tools/wscript.orig 2021-07-15 06:18:26.000000000 +0000
++++ tools/wscript
+@@ -30,6 +30,8 @@ def build(bld):
+ os_incdir = ['../macosx', '../posix']
+ if bld.env['IS_SUN']:
+ os_incdir = ['../solaris', '../posix']
++ if bld.env['IS_NETBSD']:
++ os_incdir = ['../netbsd', '../posix']
+ if bld.env['IS_WINDOWS']:
+ os_incdir = ['../windows']
+ for example_tool, example_tool_source in list(example_tools.items()):
diff --git a/audio/jack/patches/patch-wscript b/audio/jack/patches/patch-wscript
new file mode 100644
index 00000000000..cf4a6838364
--- /dev/null
+++ b/audio/jack/patches/patch-wscript
@@ -0,0 +1,49 @@
+$NetBSD: patch-wscript,v 1.1 2021/09/08 19:19:20 nia Exp $
+
+Add NetBSD support.
+
+--- wscript.orig 2021-07-15 06:18:26.000000000 +0000
++++ wscript
+@@ -192,6 +192,7 @@ def detect_platform(conf):
+ # ('KEY, 'Human readable name', ['strings', 'to', 'check', 'for'])
+ ('IS_LINUX', 'Linux', ['gnu0', 'gnukfreebsd', 'linux', 'posix']),
+ ('IS_MACOSX', 'MacOS X', ['darwin']),
++ ('IS_NETBSD', 'NetBSD', ['netbsd']),
+ ('IS_SUN', 'SunOS', ['sunos']),
+ ('IS_WINDOWS', 'Windows', ['cygwin', 'msys', 'win32'])
+ ]
+@@ -531,6 +532,9 @@ def obj_add_includes(bld, obj):
+ if bld.env['IS_SUN']:
+ obj.includes += ['posix', 'solaris']
+
++ if bld.env['IS_NETBSD']:
++ obj.includes += ['posix', 'netbsd']
++
+ if bld.env['IS_WINDOWS']:
+ obj.includes += ['windows']
+
+@@ -678,6 +682,11 @@ def build_drivers(bld):
+ 'windows/portaudio/JackPortAudioDriver.cpp',
+ ]
+
++ sun_src = [
++ 'common/memops.c',
++ 'netbsd/sun/JackSunDriver.cpp'
++ ]
++
+ winmme_src = [
+ 'windows/winmme/JackWinMMEDriver.cpp',
+ 'windows/winmme/JackWinMMEInputPort.cpp',
+@@ -779,6 +788,12 @@ def build_drivers(bld):
+ target = 'oss',
+ source = oss_src)
+
++ if bld.env['IS_NETBSD']:
++ create_driver_obj(
++ bld,
++ target = 'sun',
++ source = sun_src)
++
+ def build(bld):
+ if not bld.variant and bld.env['BUILD_WITH_32_64']:
+ Options.commands.append(bld.cmd + '_' + lib32)