summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2016-02-23 10:15:45 -0500
committerPaul Davis <paul@linuxaudiosystems.com>2016-02-23 10:15:45 -0500
commitc758cdf4f6e959b92683f2dba6ce8617ac4f0a83 (patch)
tree36e2664048b4ba9d6925b33281afcab2a0aab53d
parent25786b77b700abbcce664e7e39504a2b0dd1f0c8 (diff)
downloadjack1-c758cdf4f6e959b92683f2dba6ce8617ac4f0a83.tar.gz
uncrustification of jack source code
-rw-r--r--config/cpu/alpha/atomicity.h48
-rw-r--r--config/cpu/alpha/cycles.h7
-rw-r--r--config/cpu/cris/atomicity.h56
-rw-r--r--config/cpu/generic/atomicity.h12
-rw-r--r--config/cpu/generic/cycles.h13
-rw-r--r--config/cpu/i386/atomicity.h23
-rw-r--r--config/cpu/i386/cycles.h7
-rw-r--r--config/cpu/ia64/atomicity.h10
-rw-r--r--config/cpu/ia64/cycles.h7
-rw-r--r--config/cpu/ia64/ia64intrin.h220
-rw-r--r--config/cpu/m68k/atomicity.h109
-rw-r--r--config/cpu/mips/atomicity.h62
-rw-r--r--config/cpu/powerpc/atomicity.h58
-rw-r--r--config/cpu/powerpc/cycles.h22
-rw-r--r--config/cpu/s390/atomicity.h30
-rw-r--r--config/os/generic/ipc.h10
-rw-r--r--config/os/generic/poll.h10
-rw-r--r--config/os/generic/time.c12
-rw-r--r--config/os/generic/time.h17
-rw-r--r--config/os/gnu-linux/sanitycheck.c118
-rw-r--r--config/os/gnu-linux/systemtest.c299
-rw-r--r--config/os/gnu-linux/time.c56
-rw-r--r--config/os/gnu-linux/time.h16
-rw-r--r--config/os/macosx/getopt.h4
-rw-r--r--config/os/macosx/ipc.h232
-rw-r--r--config/os/macosx/mach_port.h12
-rw-r--r--config/os/macosx/pThreadUtilities.h333
-rw-r--r--config/os/macosx/poll.h233
-rw-r--r--config/os/macosx/time.c27
-rw-r--r--config/os/macosx/time.h20
-rw-r--r--config/sysdeps/atomicity.h4
-rw-r--r--config/sysdeps/cycles.h8
-rw-r--r--drivers/alsa/alsa_driver.c1269
-rw-r--r--drivers/alsa/alsa_driver.h269
-rw-r--r--drivers/alsa/generic.h6
-rw-r--r--drivers/alsa/generic_hw.c10
-rw-r--r--drivers/alsa/hammerfall.c58
-rw-r--r--drivers/alsa/hammerfall.h18
-rw-r--r--drivers/alsa/hdsp.c117
-rw-r--r--drivers/alsa/hdsp.h8
-rw-r--r--drivers/alsa/ice1712.c94
-rw-r--r--drivers/alsa/ice1712.h48
-rw-r--r--drivers/alsa/memops.c312
-rw-r--r--drivers/alsa/usx2y.c339
-rw-r--r--drivers/alsa/usx2y.h18
-rw-r--r--drivers/alsa_midi/a2j.h131
-rw-r--r--drivers/alsa_midi/alsa_midi.c1032
-rw-r--r--drivers/alsa_midi/alsa_midi_driver.c26
-rw-r--r--drivers/alsa_midi/list.c261
-rw-r--r--drivers/alsa_midi/list.h563
-rw-r--r--drivers/alsa_midi/midi_pack.h7
-rw-r--r--drivers/alsa_midi/midi_unpack.h87
-rw-r--r--drivers/alsa_midi/port.c56
-rw-r--r--drivers/alsa_midi/port.h6
-rw-r--r--drivers/alsa_midi/port_hash.c43
-rw-r--r--drivers/alsa_midi/port_hash.h8
-rw-r--r--drivers/alsa_midi/port_thread.c138
-rw-r--r--drivers/alsa_midi/port_thread.h12
-rw-r--r--drivers/am/alsa_midi.h6
-rw-r--r--drivers/am/alsa_midi_driver.c70
-rw-r--r--drivers/am/alsa_rawmidi.c704
-rw-r--r--drivers/am/alsa_seqmidi.c609
-rw-r--r--drivers/am/midi_pack.h7
-rw-r--r--drivers/am/midi_unpack.h87
-rw-r--r--[-rwxr-xr-x]drivers/coreaudio/coreaudio_driver.c1535
-rw-r--r--[-rwxr-xr-x]drivers/coreaudio/coreaudio_driver.h50
-rw-r--r--drivers/dummy/dummy_driver.c275
-rw-r--r--drivers/dummy/dummy_driver.h27
-rw-r--r--drivers/firewire/ffado_driver.c676
-rw-r--r--drivers/firewire/ffado_driver.h171
-rw-r--r--drivers/freebob/freebob_driver.c980
-rw-r--r--drivers/freebob/freebob_driver.h139
-rw-r--r--drivers/netjack/net_driver.c1114
-rw-r--r--drivers/netjack/net_driver.h9
-rw-r--r--drivers/netjack/netjack.c1188
-rw-r--r--drivers/netjack/netjack.h160
-rw-r--r--drivers/netjack/netjack_packet.c1979
-rw-r--r--drivers/netjack/netjack_packet.h108
-rw-r--r--drivers/oss/oss_driver.c1426
-rw-r--r--drivers/oss/oss_driver.h51
-rw-r--r--drivers/portaudio/portaudio_driver.c847
-rw-r--r--drivers/portaudio/portaudio_driver.h36
-rw-r--r--drivers/sun/sun_driver.c1326
-rw-r--r--drivers/sun/sun_driver.h53
m---------example-clients0
-rw-r--r--include/atomicity.h4
-rw-r--r--include/bitset.h62
-rw-r--r--include/driver.h178
-rw-r--r--include/driver_interface.h107
-rw-r--r--include/driver_parse.h52
-rw-r--r--include/engine.h320
-rw-r--r--include/hardware.h24
-rw-r--r--include/internal.h600
-rw-r--r--include/intsimd.h44
-rw-r--r--include/memops.h110
-rw-r--r--include/messagebuffer.h18
-rw-r--r--include/pool.h14
-rw-r--r--include/port.h138
-rw-r--r--include/sanitycheck.h4
-rw-r--r--include/shm.h85
-rw-r--r--include/start.h2
-rw-r--r--include/systemtest.h12
-rw-r--r--include/unlock.h12
-rw-r--r--include/varargs.h34
m---------jack0
-rw-r--r--jackd/clientengine.c519
-rw-r--r--jackd/clientengine.h48
-rw-r--r--jackd/controlapi.c2000
-rw-r--r--jackd/engine.c1312
-rw-r--r--jackd/jackd.c670
-rw-r--r--jackd/jackstart.c119
-rw-r--r--jackd/md5.c613
-rw-r--r--jackd/md5.h39
-rw-r--r--jackd/md5_loc.h48
-rw-r--r--jackd/transengine.c108
-rw-r--r--jackd/transengine.h42
-rw-r--r--libjack/client.c1457
-rw-r--r--libjack/driver.c113
-rw-r--r--libjack/intclient.c110
-rw-r--r--libjack/local.h156
-rw-r--r--libjack/messagebuffer.c106
-rw-r--r--libjack/metadata.c1172
-rw-r--r--libjack/midiport.c220
-rw-r--r--libjack/pool.c16
-rw-r--r--libjack/port.c343
-rw-r--r--libjack/ringbuffer.c66
-rw-r--r--libjack/sanitycheck.c12
-rw-r--r--libjack/shm.c205
-rw-r--r--libjack/simd.c195
-rw-r--r--libjack/systemtest.c12
-rw-r--r--libjack/thread.c163
-rw-r--r--libjack/time.c28
-rw-r--r--libjack/transclient.c211
-rw-r--r--libjack/unlock.c30
-rw-r--r--libjack/uuid.c72
m---------tools0
136 files changed, 16396 insertions, 16293 deletions
diff --git a/config/cpu/alpha/atomicity.h b/config/cpu/alpha/atomicity.h
index cb071cd..66bd328 100644
--- a/config/cpu/alpha/atomicity.h
+++ b/config/cpu/alpha/atomicity.h
@@ -28,7 +28,7 @@
// the GNU General Public License.
#ifndef _GLIBCXX_ATOMICITY_H
-#define _GLIBCXX_ATOMICITY_H 1
+#define _GLIBCXX_ATOMICITY_H 1
/* @@@ With gas we can play nice .subsection games to get the
non-predicted branch pointing forward. But Digital assemblers
@@ -39,38 +39,38 @@ typedef int _Atomic_word;
static inline _Atomic_word
__attribute__ ((__unused__))
-__exchange_and_add(volatile _Atomic_word* __mem, int __val)
+__exchange_and_add (volatile _Atomic_word* __mem, int __val)
{
- register int __result, __tmp;
+ register int __result, __tmp;
- __asm__ __volatile__ (
- "\n$Lxadd_%=:\n\t"
- "ldl_l %0,%3\n\t"
- "addl %0,%4,%1\n\t"
- "stl_c %1,%2\n\t"
- "beq %1,$Lxadd_%=\n\t"
- "mb"
- : "=&r"(__result), "=&r"(__tmp), "=m"(*__mem)
- : "m" (*__mem), "r"(__val));
+ __asm__ __volatile__ (
+ "\n$Lxadd_%=:\n\t"
+ "ldl_l %0,%3\n\t"
+ "addl %0,%4,%1\n\t"
+ "stl_c %1,%2\n\t"
+ "beq %1,$Lxadd_%=\n\t"
+ "mb"
+ : "=&r" (__result), "=&r" (__tmp), "=m" (*__mem)
+ : "m" (*__mem), "r" (__val));
- return __result;
+ return __result;
}
static inline void
__attribute__ ((__unused__))
-__atomic_add(volatile _Atomic_word* __mem, int __val)
+__atomic_add (volatile _Atomic_word* __mem, int __val)
{
- register _Atomic_word __result;
+ register _Atomic_word __result;
- __asm__ __volatile__ (
- "\n$Ladd_%=:\n\t"
- "ldl_l %0,%2\n\t"
- "addl %0,%3,%0\n\t"
- "stl_c %0,%1\n\t"
- "beq %0,$Ladd_%=\n\t"
- "mb"
- : "=&r"(__result), "=m"(*__mem)
- : "m" (*__mem), "r"(__val));
+ __asm__ __volatile__ (
+ "\n$Ladd_%=:\n\t"
+ "ldl_l %0,%2\n\t"
+ "addl %0,%3,%0\n\t"
+ "stl_c %0,%1\n\t"
+ "beq %0,$Ladd_%=\n\t"
+ "mb"
+ : "=&r" (__result), "=m" (*__mem)
+ : "m" (*__mem), "r" (__val));
}
#endif /* atomicity.h */
diff --git a/config/cpu/alpha/cycles.h b/config/cpu/alpha/cycles.h
index dccbd04..7e2cf17 100644
--- a/config/cpu/alpha/cycles.h
+++ b/config/cpu/alpha/cycles.h
@@ -1,7 +1,7 @@
/*
Copyright (C) 2001 Paul Davis
Code derived from various headers from the Linux kernel
-
+
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
@@ -16,7 +16,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
+ */
#ifndef __jack_cycles_h__
#define __jack_cycles_h__
@@ -27,7 +27,8 @@ typedef unsigned int cycles_t;
static inline cycles_t get_cycles (void)
{
cycles_t ret;
- __asm__ __volatile__ ("rpcc %0" : "=r"(ret));
+
+ __asm__ __volatile__ ("rpcc %0" : "=r" (ret));
return ret;
}
diff --git a/config/cpu/cris/atomicity.h b/config/cpu/cris/atomicity.h
index fecb9dc..2fc1a8c 100644
--- a/config/cpu/cris/atomicity.h
+++ b/config/cpu/cris/atomicity.h
@@ -28,51 +28,51 @@
// the GNU General Public License.
#ifndef _GLIBCXX_ATOMICITY_H
-#define _GLIBCXX_ATOMICITY_H 1
+#define _GLIBCXX_ATOMICITY_H 1
// This entity must not cross a page boundary.
typedef int _Atomic_word __attribute__ ((__aligned__ (4)));
static inline _Atomic_word
__attribute__ ((__unused__))
-__exchange_and_add(_Atomic_word* __mem, int __val)
+__exchange_and_add (_Atomic_word* __mem, int __val)
{
- int __tmp;
- _Atomic_word __result;
+ int __tmp;
+ _Atomic_word __result;
#if (__CRIS_arch_version >= 10)
- __asm__ __volatile__ (" clearf \n"
- "0: \n"
- " move.d %4,%2 \n"
- " move.d [%3],%0 \n"
- " add.d %0,%2 \n"
- " ax \n"
- " move.d %2,[%3] \n"
- " bwf 0b \n"
- " clearf \n"
- : "=&r" (__result), "=m" (*__mem), "=&r" (__tmp)
- : "r" (__mem), "g" (__val), "m" (*__mem));
+ __asm__ __volatile__ (" clearf \n"
+ "0: \n"
+ " move.d %4,%2 \n"
+ " move.d [%3],%0 \n"
+ " add.d %0,%2 \n"
+ " ax \n"
+ " move.d %2,[%3] \n"
+ " bwf 0b \n"
+ " clearf \n"
+ : "=&r" (__result), "=m" (*__mem), "=&r" (__tmp)
+ : "r" (__mem), "g" (__val), "m" (*__mem));
#else
- __asm__ __volatile__ (" move $ccr,$r9 \n"
- " di \n"
- " move.d %4,%2 \n"
- " move.d [%3],%0 \n"
- " add.d %0,%2 \n"
- " move.d %2,[%3] \n"
- " move $r9,$ccr \n"
- : "=&r" (__result), "=m" (*__mem), "=&r" (__tmp)
- : "r" (__mem), "g" (__val), "m" (*__mem)
- : "r9");
+ __asm__ __volatile__ (" move $ccr,$r9 \n"
+ " di \n"
+ " move.d %4,%2 \n"
+ " move.d [%3],%0 \n"
+ " add.d %0,%2 \n"
+ " move.d %2,[%3] \n"
+ " move $r9,$ccr \n"
+ : "=&r" (__result), "=m" (*__mem), "=&r" (__tmp)
+ : "r" (__mem), "g" (__val), "m" (*__mem)
+ : "r9");
#endif
- return __result;
+ return __result;
}
static inline void
__attribute__ ((__unused__))
-__atomic_add(_Atomic_word* __mem, int __val)
+__atomic_add (_Atomic_word* __mem, int __val)
{
- __exchange_and_add(__mem, __val);
+ __exchange_and_add (__mem, __val);
}
#endif /* atomicity.h */
diff --git a/config/cpu/generic/atomicity.h b/config/cpu/generic/atomicity.h
index 0b25100..b781c44 100644
--- a/config/cpu/generic/atomicity.h
+++ b/config/cpu/generic/atomicity.h
@@ -18,22 +18,22 @@
02111-1307 USA. */
#ifndef _ATOMICITY_H
-#define _ATOMICITY_H 1
+#define _ATOMICITY_H 1
typedef int _Atomic_word;
-static inline _Atomic_word
+static inline _Atomic_word
__attribute__ ((__unused__))
-__exchange_and_add(volatile _Atomic_word* mem, int val)
+__exchange_and_add (volatile _Atomic_word* mem, int val)
{
- return __sync_fetch_and_add(mem, val);
+ return __sync_fetch_and_add (mem, val);
}
static inline void
__attribute__ ((__unused__))
-__atomic_add(volatile _Atomic_word* mem, int val)
+__atomic_add (volatile _Atomic_word* mem, int val)
{
- __sync_add_and_fetch(mem, val);
+ __sync_add_and_fetch (mem, val);
}
#endif /* atomicity.h */
diff --git a/config/cpu/generic/cycles.h b/config/cpu/generic/cycles.h
index b05fb0e..12ccb8f 100644
--- a/config/cpu/generic/cycles.h
+++ b/config/cpu/generic/cycles.h
@@ -1,6 +1,6 @@
/*
Copyright (C) 2001 Paul Davis
-
+
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
@@ -15,7 +15,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
+ */
#ifndef __jack_cycles_h__
#define __jack_cycles_h__
@@ -26,12 +26,13 @@
typedef long cycles_t;
-static inline cycles_t get_cycles(void)
+static inline cycles_t get_cycles (void)
{
- struct timespec time;
- clock_gettime(CLOCK_REALTIME, &time);
+ struct timespec time;
+
+ clock_gettime (CLOCK_REALTIME, &time);
- return ((cycles_t) time.tv_sec * 1000000) + time.tv_nsec*1000;
+ return ((cycles_t)time.tv_sec * 1000000) + time.tv_nsec * 1000;
}
#endif /* __jack_cycles_h__ */
diff --git a/config/cpu/i386/atomicity.h b/config/cpu/i386/atomicity.h
index 73be009..b9cad70 100644
--- a/config/cpu/i386/atomicity.h
+++ b/config/cpu/i386/atomicity.h
@@ -26,27 +26,28 @@
// the GNU General Public License.
#ifndef _GLIBCXX_ATOMICITY_H
-#define _GLIBCXX_ATOMICITY_H 1
+#define _GLIBCXX_ATOMICITY_H 1
typedef int _Atomic_word;
-static inline _Atomic_word
+static inline _Atomic_word
__attribute__ ((__unused__))
-__exchange_and_add(volatile _Atomic_word* __mem, int __val)
+__exchange_and_add (volatile _Atomic_word* __mem, int __val)
{
- register _Atomic_word __result;
- __asm__ __volatile__ ("lock; xaddl %0,%1"
- : "=r" (__result), "=m" (*__mem)
- : "0" (__val), "m" (*__mem));
- return __result;
+ register _Atomic_word __result;
+
+ __asm__ __volatile__ ("lock; xaddl %0,%1"
+ : "=r" (__result), "=m" (*__mem)
+ : "0" (__val), "m" (*__mem));
+ return __result;
}
static inline void
__attribute__ ((__unused__))
-__atomic_add(volatile _Atomic_word* __mem, int __val)
+__atomic_add (volatile _Atomic_word* __mem, int __val)
{
- __asm__ __volatile__ ("lock; addl %1,%0"
- : "=m" (*__mem) : "ir" (__val), "m" (*__mem));
+ __asm__ __volatile__ ("lock; addl %1,%0"
+ : "=m" (*__mem) : "ir" (__val), "m" (*__mem));
}
#endif /* atomicity.h */
diff --git a/config/cpu/i386/cycles.h b/config/cpu/i386/cycles.h
index f90c445..4a26560 100644
--- a/config/cpu/i386/cycles.h
+++ b/config/cpu/i386/cycles.h
@@ -1,7 +1,7 @@
/*
Copyright (C) 2001 Paul Davis
Code derived from various headers from the Linux kernel
-
+
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
@@ -16,7 +16,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
+ */
#ifndef __jack_cycles_h__
#define __jack_cycles_h__
@@ -26,7 +26,8 @@ typedef unsigned long long cycles_t;
static inline cycles_t get_cycles (void)
{
unsigned long long ret;
- __asm__ __volatile__("rdtsc" : "=A" (ret));
+
+ __asm__ __volatile__ ("rdtsc" : "=A" (ret));
return ret;
}
diff --git a/config/cpu/ia64/atomicity.h b/config/cpu/ia64/atomicity.h
index d326a13..8a581f2 100644
--- a/config/cpu/ia64/atomicity.h
+++ b/config/cpu/ia64/atomicity.h
@@ -34,18 +34,18 @@
typedef int _Atomic_word;
-static inline _Atomic_word
+static inline _Atomic_word
__attribute__ ((__unused__))
-__exchange_and_add(volatile _Atomic_word* __mem, int __val)
+__exchange_and_add (volatile _Atomic_word* __mem, int __val)
{
- return __sync_fetch_and_add(__mem, __val);
+ return __sync_fetch_and_add (__mem, __val);
}
static inline void
__attribute__ ((__unused__))
-__atomic_add(volatile _Atomic_word* __mem, int __val)
+__atomic_add (volatile _Atomic_word* __mem, int __val)
{
- __sync_fetch_and_add(__mem, __val);
+ __sync_fetch_and_add (__mem, __val);
}
#endif /* atomicity.h */
diff --git a/config/cpu/ia64/cycles.h b/config/cpu/ia64/cycles.h
index d927cce..4bd19ed 100644
--- a/config/cpu/ia64/cycles.h
+++ b/config/cpu/ia64/cycles.h
@@ -1,7 +1,7 @@
/*
Copyright (C) 2001 Paul Davis
Code derived from various headers from the Linux kernel
-
+
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
@@ -16,7 +16,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
+ */
#ifndef __jack_cycles_h__
#define __jack_cycles_h__
@@ -28,7 +28,8 @@ static inline cycles_t
get_cycles (void)
{
cycles_t ret;
- __asm__ __volatile__ ("mov %0=ar.itc" : "=r"(ret));
+
+ __asm__ __volatile__ ("mov %0=ar.itc" : "=r" (ret));
return ret;
}
diff --git a/config/cpu/ia64/ia64intrin.h b/config/cpu/ia64/ia64intrin.h
index 262dc20..3bdcf9d 100644
--- a/config/cpu/ia64/ia64intrin.h
+++ b/config/cpu/ia64/ia64intrin.h
@@ -7,121 +7,121 @@
extern "C" {
#endif
-extern void __sync_synchronize (void);
+extern void __sync_synchronize(void);
-extern int __sync_val_compare_and_swap_si (int *, int, int);
-extern long __sync_val_compare_and_swap_di (long *, long, long);
+extern int __sync_val_compare_and_swap_si(int *, int, int);
+extern long __sync_val_compare_and_swap_di(long *, long, long);
#define __sync_val_compare_and_swap(PTR, OLD, NEW) \
- ((sizeof (*(PTR)) == sizeof(int)) \
- ? (__typeof__(*(PTR))) \
- __sync_val_compare_and_swap_si((int *)(PTR),(int)(OLD),(int)(NEW)) \
- : (__typeof__(*(PTR))) \
- __sync_val_compare_and_swap_di((long *)(PTR),(long)(OLD),(long)(NEW)))
-
-extern int __sync_bool_compare_and_swap_si (int *, int, int);
-extern int __sync_bool_compare_and_swap_di (long *, long, long);
+ ((sizeof(*(PTR)) == sizeof(int)) \
+ ? (__typeof__(*(PTR))) \
+ __sync_val_compare_and_swap_si ((int*)(PTR), (int)(OLD), (int)(NEW)) \
+ : (__typeof__(*(PTR))) \
+ __sync_val_compare_and_swap_di ((long*)(PTR), (long)(OLD), (long)(NEW)))
+
+extern int __sync_bool_compare_and_swap_si(int *, int, int);
+extern int __sync_bool_compare_and_swap_di(long *, long, long);
#define __sync_bool_compare_and_swap(PTR, OLD, NEW) \
- ((sizeof (*(PTR)) == sizeof(int)) \
- ? __sync_bool_compare_and_swap_si((int *)(PTR),(int)(OLD),(int)(NEW)) \
- : __sync_bool_compare_and_swap_di((long *)(PTR),(long)(OLD),(long)(NEW)))
+ ((sizeof(*(PTR)) == sizeof(int)) \
+ ? __sync_bool_compare_and_swap_si ((int*)(PTR), (int)(OLD), (int)(NEW)) \
+ : __sync_bool_compare_and_swap_di ((long*)(PTR), (long)(OLD), (long)(NEW)))
-extern void __sync_lock_release_si (int *);
-extern void __sync_lock_release_di (long *);
+extern void __sync_lock_release_si(int *);
+extern void __sync_lock_release_di(long *);
#define __sync_lock_release(PTR) \
- ((sizeof (*(PTR)) == sizeof(int)) \
- ? __sync_lock_release_si((int *)(PTR)) \
- : __sync_lock_release_di((long *)(PTR)))
-
-extern int __sync_lock_test_and_set_si (int *, int);
-extern long __sync_lock_test_and_set_di (long *, long);
-#define __sync_lock_test_and_set(PTR,VAL) \
- ((sizeof (*(PTR)) == sizeof(int)) \
- ? (__typeof__(*(PTR))) __sync_lock_test_and_set_si((int *)(PTR),(int)(VAL)) \
- : (__typeof__(*(PTR))) __sync_lock_test_and_set_di((long *)(PTR),(long)(VAL)))
-
-extern int __sync_fetch_and_add_si (int *, int);
-extern long __sync_fetch_and_add_di (long *, long);
-#define __sync_fetch_and_add(PTR,VAL) \
- ((sizeof (*(PTR)) == sizeof(int)) \
- ? (__typeof__(*(PTR))) __sync_fetch_and_add_si((int *)(PTR),(int)(VAL)) \
- : (__typeof__(*(PTR))) __sync_fetch_and_add_di((long *)(PTR),(long)(VAL)))
-
-extern int __sync_fetch_and_sub_si (int *, int);
-extern long __sync_fetch_and_sub_di (long *, long);
-#define __sync_fetch_and_sub(PTR,VAL) \
- ((sizeof (*(PTR)) == sizeof(int)) \
- ? (__typeof__(*(PTR))) __sync_fetch_and_sub_si((int *)(PTR),(int)(VAL)) \
- : (__typeof__(*(PTR))) __sync_fetch_and_sub_di((long *)(PTR),(long)(VAL)))
-
-extern int __sync_fetch_and_and_si (int *, int);
-extern long __sync_fetch_and_and_di (long *, long);
-#define __sync_fetch_and_and(PTR,VAL) \
- ((sizeof (*(PTR)) == sizeof(int)) \
- ? (__typeof__(*(PTR))) __sync_fetch_and_and_si((int *)(PTR),(int)(VAL)) \
- : (__typeof__(*(PTR))) __sync_fetch_and_and_di((long *)(PTR),(long)(VAL)))
-
-extern int __sync_fetch_and_or_si (int *, int);
-extern long __sync_fetch_and_or_di (long *, long);
-#define __sync_fetch_and_or(PTR,VAL) \
- ((sizeof (*(PTR)) == sizeof(int)) \
- ? (__typeof__(*(PTR))) __sync_fetch_and_or_si((int *)(PTR),(int)(VAL)) \
- : (__typeof__(*(PTR))) __sync_fetch_and_or_di((long *)(PTR),(long)(VAL)))
-
-extern int __sync_fetch_and_xor_si (int *, int);
-extern long __sync_fetch_and_xor_di (long *, long);
-#define __sync_fetch_and_xor(PTR,VAL) \
- ((sizeof (*(PTR)) == sizeof(int)) \
- ? (__typeof__(*(PTR))) __sync_fetch_and_xor_si((int *)(PTR),(int)(VAL)) \
- : (__typeof__(*(PTR))) __sync_fetch_and_xor_di((long *)(PTR),(long)(VAL)))
-
-extern int __sync_fetch_and_nand_si (int *, int);
-extern long __sync_fetch_and_nand_di (long *, long);
-#define __sync_fetch_and_nand(PTR,VAL) \
- ((sizeof (*(PTR)) == sizeof(int)) \
- ? (__typeof__(*(PTR))) __sync_fetch_and_nand_si((int *)(PTR),(int)(VAL)) \
- : (__typeof__(*(PTR))) __sync_fetch_and_nand_di((long *)(PTR),(long)(VAL)))
-
-extern int __sync_add_and_fetch_si (int *, int);
-extern long __sync_add_and_fetch_di (long *, long);
-#define __sync_add_and_fetch(PTR,VAL) \
- ((sizeof (*(PTR)) == sizeof(int)) \
- ? (__typeof__(*(PTR))) __sync_add_and_fetch_si((int *)(PTR),(int)(VAL)) \
- : (__typeof__(*(PTR))) __sync_add_and_fetch_di((long *)(PTR),(long)(VAL)))
-
-extern int __sync_sub_and_fetch_si (int *, int);
-extern long __sync_sub_and_fetch_di (long *, long);
-#define __sync_sub_and_fetch(PTR,VAL) \
- ((sizeof (*(PTR)) == sizeof(int)) \
- ? (__typeof__(*(PTR))) __sync_sub_and_fetch_si((int *)(PTR),(int)(VAL)) \
- : (__typeof__(*(PTR))) __sync_sub_and_fetch_di((long *)(PTR),(long)(VAL)))
-
-extern int __sync_and_and_fetch_si (int *, int);
-extern long __sync_and_and_fetch_di (long *, long);
-#define __sync_and_and_fetch(PTR,VAL) \
- ((sizeof (*(PTR)) == sizeof(int)) \
- ? (__typeof__(*(PTR))) __sync_and_and_fetch_si((int *)(PTR),(int)(VAL)) \
- : (__typeof__(*(PTR))) __sync_and_and_fetch_di((long *)(PTR),(long)(VAL)))
-
-extern int __sync_or_and_fetch_si (int *, int);
-extern long __sync_or_and_fetch_di (long *, long);
-#define __sync_or_and_fetch(PTR,VAL) \
- ((sizeof (*(PTR)) == sizeof(int)) \
- ? (__typeof__(*(PTR))) __sync_or_and_fetch_si((int *)(PTR),(int)(VAL)) \
- : (__typeof__(*(PTR))) __sync_or_and_fetch_di((long *)(PTR),(long)(VAL)))
-
-extern int __sync_xor_and_fetch_si (int *, int);
-extern long __sync_xor_and_fetch_di (long *, long);
-#define __sync_xor_and_fetch(PTR,VAL) \
- ((sizeof (*(PTR)) == sizeof(int)) \
- ? (__typeof__(*(PTR))) __sync_xor_and_fetch_si((int *)(PTR),(int)(VAL)) \
- : (__typeof__(*(PTR))) __sync_xor_and_fetch_di((long *)(PTR),(long)(VAL)))
-
-extern int __sync_nand_and_fetch_si (int *, int);
-extern long __sync_nand_and_fetch_di (long *, long);
-#define __sync_nand_and_fetch(PTR,VAL) \
- ((sizeof (*(PTR)) == sizeof(int)) \
- ? (__typeof__(*(PTR))) __sync_nand_and_fetch_si((int *)(PTR),(int)(VAL)) \
- : (__typeof__(*(PTR))) __sync_nand_and_fetch_di((long *)(PTR),(long)(VAL)))
+ ((sizeof(*(PTR)) == sizeof(int)) \
+ ? __sync_lock_release_si ((int*)(PTR)) \
+ : __sync_lock_release_di ((long*)(PTR)))
+
+extern int __sync_lock_test_and_set_si(int *, int);
+extern long __sync_lock_test_and_set_di(long *, long);
+#define __sync_lock_test_and_set(PTR, VAL) \
+ ((sizeof(*(PTR)) == sizeof(int)) \
+ ? (__typeof__(*(PTR)))__sync_lock_test_and_set_si ((int*)(PTR), (int)(VAL)) \
+ : (__typeof__(*(PTR)))__sync_lock_test_and_set_di ((long*)(PTR), (long)(VAL)))
+
+extern int __sync_fetch_and_add_si(int *, int);
+extern long __sync_fetch_and_add_di(long *, long);
+#define __sync_fetch_and_add(PTR, VAL) \
+ ((sizeof(*(PTR)) == sizeof(int)) \
+ ? (__typeof__(*(PTR)))__sync_fetch_and_add_si ((int*)(PTR), (int)(VAL)) \
+ : (__typeof__(*(PTR)))__sync_fetch_and_add_di ((long*)(PTR), (long)(VAL)))
+
+extern int __sync_fetch_and_sub_si(int *, int);
+extern long __sync_fetch_and_sub_di(long *, long);
+#define __sync_fetch_and_sub(PTR, VAL) \
+ ((sizeof(*(PTR)) == sizeof(int)) \
+ ? (__typeof__(*(PTR)))__sync_fetch_and_sub_si ((int*)(PTR), (int)(VAL)) \
+ : (__typeof__(*(PTR)))__sync_fetch_and_sub_di ((long*)(PTR), (long)(VAL)))
+
+extern int __sync_fetch_and_and_si(int *, int);
+extern long __sync_fetch_and_and_di(long *, long);
+#define __sync_fetch_and_and(PTR, VAL) \
+ ((sizeof(*(PTR)) == sizeof(int)) \
+ ? (__typeof__(*(PTR)))__sync_fetch_and_and_si ((int*)(PTR), (int)(VAL)) \
+ : (__typeof__(*(PTR)))__sync_fetch_and_and_di ((long*)(PTR), (long)(VAL)))
+
+extern int __sync_fetch_and_or_si(int *, int);
+extern long __sync_fetch_and_or_di(long *, long);
+#define __sync_fetch_and_or(PTR, VAL) \
+ ((sizeof(*(PTR)) == sizeof(int)) \
+ ? (__typeof__(*(PTR)))__sync_fetch_and_or_si ((int*)(PTR), (int)(VAL)) \
+ : (__typeof__(*(PTR)))__sync_fetch_and_or_di ((long*)(PTR), (long)(VAL)))
+
+extern int __sync_fetch_and_xor_si(int *, int);
+extern long __sync_fetch_and_xor_di(long *, long);
+#define __sync_fetch_and_xor(PTR, VAL) \
+ ((sizeof(*(PTR)) == sizeof(int)) \
+ ? (__typeof__(*(PTR)))__sync_fetch_and_xor_si ((int*)(PTR), (int)(VAL)) \
+ : (__typeof__(*(PTR)))__sync_fetch_and_xor_di ((long*)(PTR), (long)(VAL)))
+
+extern int __sync_fetch_and_nand_si(int *, int);
+extern long __sync_fetch_and_nand_di(long *, long);
+#define __sync_fetch_and_nand(PTR, VAL) \
+ ((sizeof(*(PTR)) == sizeof(int)) \
+ ? (__typeof__(*(PTR)))__sync_fetch_and_nand_si ((int*)(PTR), (int)(VAL)) \
+ : (__typeof__(*(PTR)))__sync_fetch_and_nand_di ((long*)(PTR), (long)(VAL)))
+
+extern int __sync_add_and_fetch_si(int *, int);
+extern long __sync_add_and_fetch_di(long *, long);
+#define __sync_add_and_fetch(PTR, VAL) \
+ ((sizeof(*(PTR)) == sizeof(int)) \
+ ? (__typeof__(*(PTR)))__sync_add_and_fetch_si ((int*)(PTR), (int)(VAL)) \
+ : (__typeof__(*(PTR)))__sync_add_and_fetch_di ((long*)(PTR), (long)(VAL)))
+
+extern int __sync_sub_and_fetch_si(int *, int);
+extern long __sync_sub_and_fetch_di(long *, long);
+#define __sync_sub_and_fetch(PTR, VAL) \
+ ((sizeof(*(PTR)) == sizeof(int)) \
+ ? (__typeof__(*(PTR)))__sync_sub_and_fetch_si ((int*)(PTR), (int)(VAL)) \
+ : (__typeof__(*(PTR)))__sync_sub_and_fetch_di ((long*)(PTR), (long)(VAL)))
+
+extern int __sync_and_and_fetch_si(int *, int);
+extern long __sync_and_and_fetch_di(long *, long);
+#define __sync_and_and_fetch(PTR, VAL) \
+ ((sizeof(*(PTR)) == sizeof(int)) \
+ ? (__typeof__(*(PTR)))__sync_and_and_fetch_si ((int*)(PTR), (int)(VAL)) \
+ : (__typeof__(*(PTR)))__sync_and_and_fetch_di ((long*)(PTR), (long)(VAL)))
+
+extern int __sync_or_and_fetch_si(int *, int);
+extern long __sync_or_and_fetch_di(long *, long);
+#define __sync_or_and_fetch(PTR, VAL) \
+ ((sizeof(*(PTR)) == sizeof(int)) \
+ ? (__typeof__(*(PTR)))__sync_or_and_fetch_si ((int*)(PTR), (int)(VAL)) \
+ : (__typeof__(*(PTR)))__sync_or_and_fetch_di ((long*)(PTR), (long)(VAL)))
+
+extern int __sync_xor_and_fetch_si(int *, int);
+extern long __sync_xor_and_fetch_di(long *, long);
+#define __sync_xor_and_fetch(PTR, VAL) \
+ ((sizeof(*(PTR)) == sizeof(int)) \
+ ? (__typeof__(*(PTR)))__sync_xor_and_fetch_si ((int*)(PTR), (int)(VAL)) \
+ : (__typeof__(*(PTR)))__sync_xor_and_fetch_di ((long*)(PTR), (long)(VAL)))
+
+extern int __sync_nand_and_fetch_si(int *, int);
+extern long __sync_nand_and_fetch_di(long *, long);
+#define __sync_nand_and_fetch(PTR, VAL) \
+ ((sizeof(*(PTR)) == sizeof(int)) \
+ ? (__typeof__(*(PTR)))__sync_nand_and_fetch_si ((int*)(PTR), (int)(VAL)) \
+ : (__typeof__(*(PTR)))__sync_nand_and_fetch_di ((long*)(PTR), (long)(VAL)))
#ifdef __cplusplus
}
diff --git a/config/cpu/m68k/atomicity.h b/config/cpu/m68k/atomicity.h
index eb801de..8b224e2 100644
--- a/config/cpu/m68k/atomicity.h
+++ b/config/cpu/m68k/atomicity.h
@@ -28,112 +28,113 @@
// the GNU General Public License.
#ifndef _GLIBCXX_ATOMICITY_H
-#define _GLIBCXX_ATOMICITY_H 1
+#define _GLIBCXX_ATOMICITY_H 1
typedef int _Atomic_word;
#if ( defined(__mc68020__) || defined(__mc68030__) \
- || defined(__mc68040__) || defined(__mc68060__) ) \
- && !defined(__mcpu32__)
+ || defined(__mc68040__) || defined(__mc68060__) ) \
+ && !defined(__mcpu32__)
// These variants support compare-and-swap.
-static inline _Atomic_word
+static inline _Atomic_word
__attribute__ ((__unused__))
-__exchange_and_add(volatile _Atomic_word* __mem, int __val)
+__exchange_and_add (volatile _Atomic_word* __mem, int __val)
{
- register _Atomic_word __result = *__mem;
- register _Atomic_word __temp;
- __asm__ __volatile__ ("1: move%.l %0,%1\n\t"
- "add%.l %3,%1\n\t"
- "cas%.l %0,%1,%2\n\t"
- "jne 1b"
- : "=d" (__result), "=&d" (__temp), "=m" (*__mem)
- : "d" (__val), "0" (__result), "m" (*__mem));
- return __result;
+ register _Atomic_word __result = *__mem;
+ register _Atomic_word __temp;
+
+ __asm__ __volatile__ ("1: move%.l %0,%1\n\t"
+ "add%.l %3,%1\n\t"
+ "cas%.l %0,%1,%2\n\t"
+ "jne 1b"
+ : "=d" (__result), "=&d" (__temp), "=m" (*__mem)
+ : "d" (__val), "0" (__result), "m" (*__mem));
+ return __result;
}
#elif defined(__rtems__)
- /*
- * TAS/JBNE is unsafe on systems with strict priority-based scheduling.
- * Disable interrupts, which we can do only from supervisor mode.
- */
+/*
+ * TAS/JBNE is unsafe on systems with strict priority-based scheduling.
+ * Disable interrupts, which we can do only from supervisor mode.
+ */
static inline _Atomic_word
__attribute__ ((__unused__))
-__exchange_and_add(volatile _Atomic_word* __mem, int __val)
+__exchange_and_add (volatile _Atomic_word* __mem, int __val)
{
- _Atomic_word __result;
- short __level, __tmpsr;
- __asm__ __volatile__ ("move%.w %%sr,%0\n\tor%.l %0,%1\n\tmove%.w %1,%%sr"
- : "=d"(__level), "=d"(__tmpsr) : "1"(0x700));
+ _Atomic_word __result;
+ short __level, __tmpsr;
+
+ __asm__ __volatile__ ("move%.w %%sr,%0\n\tor%.l %0,%1\n\tmove%.w %1,%%sr"
+ : "=d" (__level), "=d" (__tmpsr) : "1" (0x700));
- __result = *__mem;
- *__mem = __result + __val;
+ __result = *__mem;
+ *__mem = __result + __val;
- __asm__ __volatile__ ("move%.w %0,%%sr" : : "d"(__level));
+ __asm__ __volatile__ ("move%.w %0,%%sr" : : "d" (__level));
- return __result;
+ return __result;
}
#else
template<int __inst>
- struct __Atomicity_lock
- {
- static volatile unsigned char _S_atomicity_lock;
- };
+struct __Atomicity_lock {
+ static volatile unsigned char _S_atomicity_lock;
+};
template<int __inst>
volatile unsigned char __Atomicity_lock<__inst>::_S_atomicity_lock = 0;
template volatile unsigned char __Atomicity_lock<0>::_S_atomicity_lock;
-static inline _Atomic_word
+static inline _Atomic_word
__attribute__ ((__unused__))
-__exchange_and_add(volatile _Atomic_word* __mem, int __val)
+__exchange_and_add (volatile _Atomic_word* __mem, int __val)
{
- _Atomic_word __result;
+ _Atomic_word __result;
// bset with no immediate addressing (not SMP-safe)
#if defined(__mcf5200__) || defined(__mcf5300__)
- __asm__ __volatile__("1: bset.b #7,%0@\n\tjbne 1b"
- : /* no outputs */
- : "a"(&__Atomicity_lock<0>::_S_atomicity_lock)
- : "cc", "memory");
+ __asm__ __volatile__ ("1: bset.b #7,%0@\n\tjbne 1b"
+ : /* no outputs */
+ : "a" (&__Atomicity_lock<0>::_S_atomicity_lock)
+ : "cc", "memory");
// CPU32 and MCF5400 support test-and-set (SMP-safe).
#elif defined(__mcpu32__) || defined(__mcf5400__)
- __asm__ __volatile__("1: tas %0\n\tjbne 1b"
- : "+m"(__Atomicity_lock<0>::_S_atomicity_lock)
- : /* none */
- : "cc");
+ __asm__ __volatile__ ("1: tas %0\n\tjbne 1b"
+ : "+m" (__Atomicity_lock<0>::_S_atomicity_lock)
+ : /* none */
+ : "cc");
// Use bset with immediate addressing for 68000/68010 (not SMP-safe)
// NOTE: TAS is available on the 68000, but unsupported by some Amiga
// memory controllers.
#else
- __asm__ __volatile__("1: bset.b #7,%0\n\tjbne 1b"
- : "+m"(__Atomicity_lock<0>::_S_atomicity_lock)
- : /* none */
- : "cc");
+ __asm__ __volatile__ ("1: bset.b #7,%0\n\tjbne 1b"
+ : "+m" (__Atomicity_lock<0>::_S_atomicity_lock)
+ : /* none */
+ : "cc");
#endif
- __result = *__mem;
- *__mem = __result + __val;
+ __result = *__mem;
+ *__mem = __result + __val;
- __Atomicity_lock<0>::_S_atomicity_lock = 0;
+ __Atomicity_lock<0>::_S_atomicity_lock = 0;
- return __result;
+ return __result;
}
#endif /* TAS / BSET */
static inline void
__attribute__ ((__unused__))
-__atomic_add(volatile _Atomic_word* __mem, int __val)
+__atomic_add (volatile _Atomic_word* __mem, int __val)
{
- // Careful: using add.l with a memory destination is not
- // architecturally guaranteed to be atomic.
- (void) __exchange_and_add(__mem, __val);
+ // Careful: using add.l with a memory destination is not
+ // architecturally guaranteed to be atomic.
+ (void)__exchange_and_add (__mem, __val);
}
#endif /* !_GLIBCXX_ATOMICITY_H */
diff --git a/config/cpu/mips/atomicity.h b/config/cpu/mips/atomicity.h
index 3d0c7a1..be471af 100644
--- a/config/cpu/mips/atomicity.h
+++ b/config/cpu/mips/atomicity.h
@@ -34,50 +34,50 @@ typedef int _Atomic_word;
static inline int
__attribute__ ((__unused__))
-__exchange_and_add(volatile _Atomic_word* __mem, int __val)
+__exchange_and_add (volatile _Atomic_word* __mem, int __val)
{
- int __result, __tmp;
+ int __result, __tmp;
- __asm__ __volatile__
- ("/* Inline exchange & add */\n\t"
- "1:\n\t"
- ".set push\n\t"
+ __asm__ __volatile__
+ ("/* Inline exchange & add */\n\t"
+ "1:\n\t"
+ ".set push\n\t"
#if _MIPS_SIM == _ABIO32
- ".set mips2\n\t"
+ ".set mips2\n\t"
#endif
- "ll %0,%3\n\t"
- "addu %1,%4,%0\n\t"
- "sc %1,%2\n\t"
- ".set pop\n\t"
- "beqz %1,1b\n\t"
- "/* End exchange & add */"
- : "=&r"(__result), "=&r"(__tmp), "=m"(*__mem)
- : "m" (*__mem), "r"(__val));
+ "ll %0,%3\n\t"
+ "addu %1,%4,%0\n\t"
+ "sc %1,%2\n\t"
+ ".set pop\n\t"
+ "beqz %1,1b\n\t"
+ "/* End exchange & add */"
+ : "=&r" (__result), "=&r" (__tmp), "=m" (*__mem)
+ : "m" (*__mem), "r" (__val));
- return __result;
+ return __result;
}
static inline void
__attribute__ ((__unused__))
-__atomic_add(volatile _Atomic_word* __mem, int __val)
+__atomic_add (volatile _Atomic_word* __mem, int __val)
{
- int __result;
+ int __result;
- __asm__ __volatile__
- ("/* Inline atomic add */\n\t"
- "1:\n\t"
- ".set push\n\t"
+ __asm__ __volatile__
+ ("/* Inline atomic add */\n\t"
+ "1:\n\t"
+ ".set push\n\t"
#if _MIPS_SIM == _ABIO32
- ".set mips2\n\t"
+ ".set mips2\n\t"
#endif
- "ll %0,%2\n\t"
- "addu %0,%3,%0\n\t"
- "sc %0,%1\n\t"
- ".set pop\n\t"
- "beqz %0,1b\n\t"
- "/* End atomic add */"
- : "=&r"(__result), "=m"(*__mem)
- : "m" (*__mem), "r"(__val));
+ "ll %0,%2\n\t"
+ "addu %0,%3,%0\n\t"
+ "sc %0,%1\n\t"
+ ".set pop\n\t"
+ "beqz %0,1b\n\t"
+ "/* End atomic add */"
+ : "=&r" (__result), "=m" (*__mem)
+ : "m" (*__mem), "r" (__val));
}
#endif /* atomicity.h */
diff --git a/config/cpu/powerpc/atomicity.h b/config/cpu/powerpc/atomicity.h
index 3b44b7d..5a74a65 100644
--- a/config/cpu/powerpc/atomicity.h
+++ b/config/cpu/powerpc/atomicity.h
@@ -28,7 +28,7 @@
// the GNU General Public License.
#ifndef _GLIBCXX_ATOMICITY_H
-#define _GLIBCXX_ATOMICITY_H 1
+#define _GLIBCXX_ATOMICITY_H 1
#ifdef __PPC405__
#define _STWCX "sync \n\tstwcx. "
@@ -40,39 +40,41 @@ typedef int _Atomic_word;
static inline _Atomic_word
__attribute__ ((__unused__))
-__exchange_and_add(volatile _Atomic_word* __mem, int __val)
+__exchange_and_add (volatile _Atomic_word* __mem, int __val)
{
- _Atomic_word __tmp, __res;
- __asm__ __volatile__ (
- "/* Inline exchange & add */\n"
- "0:\t"
- "lwarx %0,0,%3 \n\t"
- "add%I4 %1,%0,%4 \n\t"
- _STWCX " %1,0,%3 \n\t"
- "bne- 0b \n\t"
- "/* End exchange & add */"
- : "=&b"(__res), "=&r"(__tmp), "=m" (*__mem)
- : "r" (__mem), "Ir"(__val), "m" (*__mem)
- : "cr0");
- return __res;
+ _Atomic_word __tmp, __res;
+
+ __asm__ __volatile__ (
+ "/* Inline exchange & add */\n"
+ "0:\t"
+ "lwarx %0,0,%3 \n\t"
+ "add%I4 %1,%0,%4 \n\t"
+ _STWCX " %1,0,%3 \n\t"
+ "bne- 0b \n\t"
+ "/* End exchange & add */"
+ : "=&b" (__res), "=&r" (__tmp), "=m" (*__mem)
+ : "r" (__mem), "Ir" (__val), "m" (*__mem)
+ : "cr0");
+ return __res;
}
static inline void
__attribute__ ((__unused__))
-__atomic_add(volatile _Atomic_word* __mem, int __val)
+__atomic_add (volatile _Atomic_word* __mem, int __val)
{
- _Atomic_word __tmp;
- __asm__ __volatile__ (
- "/* Inline atomic add */\n"
- "0:\t"
- "lwarx %0,0,%2 \n\t"
- "add%I3 %0,%0,%3 \n\t"
- _STWCX " %0,0,%2 \n\t"
- "bne- 0b \n\t"
- "/* End atomic add */"
- : "=&b"(__tmp), "=m" (*__mem)
- : "r" (__mem), "Ir"(__val), "m" (*__mem)
- : "cr0");
+ _Atomic_word __tmp;
+
+ __asm__ __volatile__ (
+ "/* Inline atomic add */\n"
+ "0:\t"
+ "lwarx %0,0,%2 \n\t"
+ "add%I3 %0,%0,%3 \n\t"
+ _STWCX " %0,0,%2 \n\t"
+ "bne- 0b \n\t"
+ "/* End atomic add */"
+ : "=&b" (__tmp), "=m" (*__mem)
+ : "r" (__mem), "Ir" (__val), "m" (*__mem)
+ : "cr0");
}
#endif /* atomicity.h */
diff --git a/config/cpu/powerpc/cycles.h b/config/cpu/powerpc/cycles.h
index bdf9908..2b9097f 100644
--- a/config/cpu/powerpc/cycles.h
+++ b/config/cpu/powerpc/cycles.h
@@ -1,7 +1,7 @@
/*
Copyright (C) 2001 Paul Davis
Code derived from various headers from the Linux kernel
-
+
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
@@ -16,16 +16,16 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
+ */
#ifndef __jack_cycles_h__
#define __jack_cycles_h__
/* PowerPC */
-#define CPU_FTR_601 0x00000100
+#define CPU_FTR_601 0x00000100
#ifdef __powerpc64__
-#define CPU_FTR_CELL_TB_BUG 0x0000800000000000UL
+#define CPU_FTR_CELL_TB_BUG 0x0000800000000000UL
#endif /* __powerpc64__ */
typedef unsigned long cycles_t;
@@ -34,13 +34,13 @@ typedef unsigned long cycles_t;
extern cycles_t cacheflush_time;
-static inline cycles_t get_cycles(void)
+static inline cycles_t get_cycles (void)
{
cycles_t ret = 0;
#ifdef __powerpc64__
#ifdef ENABLE_CELLBE
- asm volatile( \
+ asm volatile ( \
"90: mftb %0;\n" \
"97: cmpwi %0,0;\n" \
" beq- 90b;\n" \
@@ -54,11 +54,11 @@ static inline cycles_t get_cycles(void)
" .llong 99b-98b\n" \
".previous" \
: "=r" (ret) : "i" (CPU_FTR_CELL_TB_BUG));
-#else /* !ENABLE_CELLBE */
- __asm__ __volatile__("mftb %0" : "=r" (ret));
+#else /* !ENABLE_CELLBE */
+ __asm__ __volatile__ ("mftb %0" : "=r" (ret));
#endif /* !ENABLE_CELLBE */
-#else /* !__powerpc64__ */
- __asm__ __volatile__(
+#else /* !__powerpc64__ */
+ __asm__ __volatile__ (
"98: mftb %0\n"
"99:\n"
".section __ftr_fixup,\"a\"\n"
@@ -68,7 +68,7 @@ static inline cycles_t get_cycles(void)
" .long 99b\n"
".previous"
: "=r" (ret) : "i" (CPU_FTR_601));
-#endif /* !__powerpc64__ */
+#endif /* !__powerpc64__ */
return ret;
}
diff --git a/config/cpu/s390/atomicity.h b/config/cpu/s390/atomicity.h
index 8647c76..5d2b3b9 100644
--- a/config/cpu/s390/atomicity.h
+++ b/config/cpu/s390/atomicity.h
@@ -28,31 +28,31 @@
// the GNU General Public License.
#ifndef _GLIBCXX_ATOMICITY_H
-#define _GLIBCXX_ATOMICITY_H 1
+#define _GLIBCXX_ATOMICITY_H 1
typedef int _Atomic_word;
-static inline _Atomic_word
+static inline _Atomic_word
__attribute__ ((__unused__))
-__exchange_and_add(volatile _Atomic_word* __mem, int __val)
+__exchange_and_add (volatile _Atomic_word* __mem, int __val)
{
- register _Atomic_word __old_val, __new_val;
-
- __asm__ __volatile__ (" l %0,0(%3)\n"
- "0: lr %1,%0\n"
- " ar %1,%4\n"
- " cs %0,%1,0(%3)\n"
- " jl 0b"
- : "=&d" (__old_val), "=&d" (__new_val), "=m" (*__mem)
- : "a" (__mem), "d" (__val), "m" (*__mem) : "cc");
- return __old_val;
+ register _Atomic_word __old_val, __new_val;
+
+ __asm__ __volatile__ (" l %0,0(%3)\n"
+ "0: lr %1,%0\n"
+ " ar %1,%4\n"
+ " cs %0,%1,0(%3)\n"
+ " jl 0b"
+ : "=&d" (__old_val), "=&d" (__new_val), "=m" (*__mem)
+ : "a" (__mem), "d" (__val), "m" (*__mem) : "cc");
+ return __old_val;
}
static inline void
__attribute__ ((__unused__))
-__atomic_add(volatile _Atomic_word* __mem, int __val)
+__atomic_add (volatile _Atomic_word* __mem, int __val)
{
- __exchange_and_add(__mem, __val);
+ __exchange_and_add (__mem, __val);
}
#endif /* atomicity.h */
diff --git a/config/os/generic/ipc.h b/config/os/generic/ipc.h
index 05aeef8..ef945c4 100644
--- a/config/os/generic/ipc.h
+++ b/config/os/generic/ipc.h
@@ -2,22 +2,22 @@
Copyright (C) 2004 Jack O'Quin
Generic version, overridden by OS-specific defines when needed.
-
+
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
+ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
+ */
#ifndef _jack_sys_ipc
#define _jack_sys_ipc 1
diff --git a/config/os/generic/poll.h b/config/os/generic/poll.h
index 5fbc3c6..ae5e145 100644
--- a/config/os/generic/poll.h
+++ b/config/os/generic/poll.h
@@ -2,22 +2,22 @@
Copyright (C) 2004 Jack O'Quin
Generic version, overridden by OS-specific defines when needed.
-
+
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
+ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
+ */
#ifndef _jack_sys_poll
#define _jack_sys_poll 1
diff --git a/config/os/generic/time.c b/config/os/generic/time.c
index 0a6deaa..c2461ff 100644
--- a/config/os/generic/time.c
+++ b/config/os/generic/time.c
@@ -2,28 +2,28 @@
Copyright (C) 2001-2004 Paul Davis, Tilman Linneweh
Generic version, overridden by OS-specific definition when needed.
-
+
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
+ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
+ */
void jack_init_time ()
{
/* nothing to do on a generic system - we use the system clock */
}
-void jack_set_clock_source (jack_timer_type_t clocksrc)
+void jack_set_clock_source (jack_timer_type_t clocksrc)
{
/* only one clock source on a generic system */
}
diff --git a/config/os/generic/time.h b/config/os/generic/time.h
index e57391c..060df61 100644
--- a/config/os/generic/time.h
+++ b/config/os/generic/time.h
@@ -2,36 +2,37 @@
Copyright (C) 2001-2004 Paul Davis, Tilman Linneweh
Generic version, overridden by OS-specific definition when needed.
-
+
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
+ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
+ */
#ifndef __jack_time_h__
#define __jack_time_h__
#include <jack/types.h>
-extern jack_time_t jack_get_microseconds_from_system (void);
+extern jack_time_t jack_get_microseconds_from_system(void);
static inline jack_time_t
-jack_get_microseconds (void) {
+jack_get_microseconds (void)
+{
return jack_get_microseconds_from_system ();
}
typedef jack_time_t (*jack_get_microseconds_t)(void);
-static inline jack_get_microseconds_t jack_get_microseconds_pointer(void)
+static inline jack_get_microseconds_t jack_get_microseconds_pointer (void)
{
return jack_get_microseconds_from_system;
}
diff --git a/config/os/gnu-linux/sanitycheck.c b/config/os/gnu-linux/sanitycheck.c
index 65f962c..f8449f2 100644
--- a/config/os/gnu-linux/sanitycheck.c
+++ b/config/os/gnu-linux/sanitycheck.c
@@ -1,5 +1,5 @@
/**
- *
+ *
* 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
@@ -22,64 +22,64 @@
#include "systemtest.h"
#include "sanitycheck.h"
-int sanitycheck (int care_about_realtime,
- int care_about_freqscaling)
+int sanitycheck (int care_about_realtime,
+ int care_about_freqscaling)
{
- int errors = 0;
- int warnings = 0;
- int relogin = 0;
+ int errors = 0;
+ int warnings = 0;
+ int relogin = 0;
+
+ if (care_about_realtime && !system_user_can_rtprio ()) {
+ errors++;
+ relogin++;
+ fprintf (stderr, "\nJACK is running in realtime mode, but you are not allowed to use realtime scheduling.\n");
+
+ if (!system_has_rtprio_limits_conf ()) {
+ errors++;
+ relogin++;
+ fprintf (stderr, "Please check your /etc/security/limits.conf for the following line\n");
+ fprintf (stderr, "and correct/add it if necessary:\n\n");
+ fprintf (stderr, " @audio - rtprio 99\n");
+ } else if (!system_has_audiogroup ()) {
+ errors++;
+ relogin++;
+ fprintf (stderr, "\nYour system has no audio group. Please add it by executing (as root):\n");
+ fprintf (stderr, " groupadd -r audio\n");
+ fprintf (stderr, " usermod -a -G audio %s\n", system_get_username ());
+ } else if (!system_user_in_audiogroup ()) {
+ errors++;
+ relogin++;
+ fprintf (stderr, "\nYour system has an audio group, but you are not a member of it.\n");
+ fprintf (stderr, "Please add yourself to the audio group by executing (as root):\n");
+ fprintf (stderr, " usermod -a -G audio %s\n", system_get_username ());
+ }
+ }
+ if (care_about_freqscaling && system_has_frequencyscaling () && system_uses_frequencyscaling ()) {
+ warnings++;
+ fprintf (stderr, "\n--------------------------------------------------------------------------------\n");
+ fprintf (stderr, "WARNING: Your system seems to use frequency scaling.\n\n");
+ fprintf (stderr, " This can have a serious impact on audio latency. You have two choices:\n");
+ fprintf (stderr, "\t(1)turn it off, e.g. by chosing the 'performance' governor.\n");
+ fprintf (stderr, "\t(2)Use the HPET clocksource by passing \"-c h\" to JACK\n");
+ fprintf (stderr, "\t (this second option only works on relatively recent computers)\n");
+ fprintf (stderr, "--------------------------------------------------------------------------------\n\n");
+ }
+ if (0 == system_memlock_amount ()) {
+ errors++;
+ relogin++;
+ fprintf (stderr, "\nYou are not allowed to lock memory. Please add a line\n");
+ fprintf (stderr, " @audio - memlock %llu\n", (system_available_physical_mem () * 3) / 4096);
+ fprintf (stderr, "in your /etc/limits.conf.\n");
+ }
+
+ if (0 < relogin) {
+ fprintf (stderr, "\nAfter applying these changes, please re-login in order for them to take effect.\n");
+ }
+
+ if (0 < errors) {
+ fprintf (stderr, "\nYou don't appear to have a sane system configuration. It is very likely that you\n");
+ fprintf (stderr, "encounter xruns. Please apply all the above mentioned changes and start jack again!\n");
+ }
- if (care_about_realtime && !system_user_can_rtprio()) {
- errors++;
- relogin++;
- fprintf(stderr, "\nJACK is running in realtime mode, but you are not allowed to use realtime scheduling.\n");
-
- if (!system_has_rtprio_limits_conf()) {
- errors++;
- relogin++;
- fprintf (stderr, "Please check your /etc/security/limits.conf for the following line\n");
- fprintf (stderr, "and correct/add it if necessary:\n\n");
- fprintf(stderr, " @audio - rtprio 99\n");
- } else if (!system_has_audiogroup()) {
- errors++;
- relogin++;
- fprintf(stderr, "\nYour system has no audio group. Please add it by executing (as root):\n");
- fprintf(stderr, " groupadd -r audio\n");
- fprintf(stderr, " usermod -a -G audio %s\n", system_get_username());
- } else if (!system_user_in_audiogroup()) {
- errors++;
- relogin++;
- fprintf(stderr, "\nYour system has an audio group, but you are not a member of it.\n");
- fprintf(stderr, "Please add yourself to the audio group by executing (as root):\n");
- fprintf(stderr, " usermod -a -G audio %s\n", system_get_username());
- }
- }
- if (care_about_freqscaling && system_has_frequencyscaling() && system_uses_frequencyscaling()) {
- warnings++;
- fprintf(stderr, "\n--------------------------------------------------------------------------------\n");
- fprintf(stderr, "WARNING: Your system seems to use frequency scaling.\n\n");
- fprintf(stderr, " This can have a serious impact on audio latency. You have two choices:\n");
- fprintf(stderr, "\t(1)turn it off, e.g. by chosing the 'performance' governor.\n");
- fprintf(stderr, "\t(2)Use the HPET clocksource by passing \"-c h\" to JACK\n");
- fprintf(stderr, "\t (this second option only works on relatively recent computers)\n");
- fprintf(stderr, "--------------------------------------------------------------------------------\n\n");
- }
- if (0==system_memlock_amount()) {
- errors++;
- relogin++;
- fprintf(stderr, "\nYou are not allowed to lock memory. Please add a line\n");
- fprintf(stderr, " @audio - memlock %llu\n", (system_available_physical_mem()*3)/4096);
- fprintf(stderr, "in your /etc/limits.conf.\n");
- }
-
- if (0<relogin) {
- fprintf(stderr, "\nAfter applying these changes, please re-login in order for them to take effect.\n");
- }
-
- if (0<errors) {
- fprintf(stderr, "\nYou don't appear to have a sane system configuration. It is very likely that you\n");
- fprintf(stderr, "encounter xruns. Please apply all the above mentioned changes and start jack again!\n");
- }
-
- return errors;
+ return errors;
}
diff --git a/config/os/gnu-linux/systemtest.c b/config/os/gnu-linux/systemtest.c
index 3f56982..957abe8 100644
--- a/config/os/gnu-linux/systemtest.c
+++ b/config/os/gnu-linux/systemtest.c
@@ -14,7 +14,7 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Set of functions to gather system information for the jack setup wizard.
- *
+ *
* TODO: Test for rt prio availability
*
* @author Florian Faber, faber@faberman.de
@@ -43,112 +43,117 @@
#include "systemtest.h"
/**
- * This function checks for the existence of known frequency scaling mechanisms
+ * This function checks for the existence of known frequency scaling mechanisms
* in this system by testing for the availability of scaling governors/
*
* @returns 0 if the system has no frequency scaling capabilities non-0 otherwise.
**/
-int system_has_frequencyscaling() {
- int fd;
+int system_has_frequencyscaling ()
+{
+ int fd;
- fd = open("/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors", O_RDONLY);
+ fd = open ("/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors", O_RDONLY);
- if (-1==fd) {
- return 0;
- }
+ if (-1 == fd) {
+ return 0;
+ }
- (void) close(fd);
+ (void)close (fd);
- return 1;
+ return 1;
}
-static int read_string(char* filename, char* buf, size_t buflen) {
- int fd;
- ssize_t r=-1;
-
- memset (buf, 0, buflen);
-
- fd = open (filename, O_RDONLY);
- if (-1<fd) {
- r = read (fd, buf, buflen-1);
- (void) close(fd);
-
- if (-1==r) {
- fprintf(stderr, "Error while reading \"%s\": %s\n", filename, strerror(errno));
- exit(EXIT_FAILURE);
- }
- }
-
- return (int) r;
+static int read_string (char* filename, char* buf, size_t buflen)
+{
+ int fd;
+ ssize_t r = -1;
+
+ memset (buf, 0, buflen);
+
+ fd = open (filename, O_RDONLY);
+ if (-1 < fd) {
+ r = read (fd, buf, buflen - 1);
+ (void)close (fd);
+
+ if (-1 == r) {
+ fprintf (stderr, "Error while reading \"%s\": %s\n", filename, strerror (errno));
+ exit (EXIT_FAILURE);
+ }
+ }
+
+ return (int)r;
}
-static int read_int(char* filename, int* value) {
- char buf[20];
+static int read_int (char* filename, int* value)
+{
+ char buf[20];
- if (0<read_string(filename, buf, 20)) {
- return (1==sscanf(buf, "%d", value));
- }
+ if (0 < read_string (filename, buf, 20)) {
+ return 1 == sscanf (buf, "%d", value);
+ }
- return 0;
+ return 0;
}
/**
- * This function determines wether any CPU core uses a variable clock speed if frequency
+ * This function determines wether any CPU core uses a variable clock speed if frequency
* scaling is available. If the governor for all cores is either "powersave" or
* "performance", the CPU frequency can be assumed to be static. This is also the case
* if scaling_min_freq and scaling_max_freq are set to the same value.
*
* @returns 0 if system doesn't use frequency scaling at the moment, non-0 otherwise
**/
-int system_uses_frequencyscaling() {
- int cpu=0, done=0, min, max;
- char filename[256], buf[256];
-
- while (!done) {
- (void) snprintf(filename, 256, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor", cpu);
- if (0<read_string(filename, buf, 256)) {
- if ((0!=strncmp("performance", buf,11)) &&
- (0!=strncmp("powersafe", buf,9))) {
+int system_uses_frequencyscaling ()
+{
+ int cpu = 0, done = 0, min, max;
+ char filename[256], buf[256];
+
+ while (!done) {
+ (void)snprintf (filename, 256, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor", cpu);
+ if (0 < read_string (filename, buf, 256)) {
+ if ((0 != strncmp ("performance", buf, 11)) &&
+ (0 != strncmp ("powersafe", buf, 9))) {
// So it's neither the "performance" nor the "powersafe" governor
- (void) snprintf(filename, 256, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_min_freq", cpu);
- if (read_int(filename, &min)) {
- (void) snprintf(filename, 256, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_max_freq", cpu);
- if (read_int(filename, &max)) {
- if (min!=max) {
+ (void)snprintf (filename, 256, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_min_freq", cpu);
+ if (read_int (filename, &min)) {
+ (void)snprintf (filename, 256, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_max_freq", cpu);
+ if (read_int (filename, &max)) {
+ if (min != max) {
// wrong governor AND different frequency limits -> scaling
return 1;
}
- }
+ }
}
- }
- } else {
- // couldn't open file -> no more cores
- done = 1;
- }
- cpu++;
- }
-
- // couldn't find anything that points to scaling
- return 0;
+ }
+ } else {
+ // couldn't open file -> no more cores
+ done = 1;
+ }
+ cpu++;
+ }
+
+ // couldn't find anything that points to scaling
+ return 0;
}
-static gid_t get_group_by_name(const char* name) {
- struct group* grp;
+static gid_t get_group_by_name (const char* name)
+{
+ struct group* grp;
gid_t res = 0;
- while ((0==res) && (NULL != (grp = getgrent()))) {
- if (0==strcmp(name, grp->gr_name)) {
- res = grp->gr_gid;
- }
- }
+ while ((0 == res) && (NULL != (grp = getgrent ()))) {
+ if (0 == strcmp (name, grp->gr_name)) {
+ res = grp->gr_gid;
+ }
+ }
- endgrent();
+ endgrent ();
- return res;
+ return res;
}
/***
@@ -162,7 +167,7 @@ int system_has_rtprio_limits_conf ()
const char* limits = "/etc/security/limits.conf";
char cmd[100];
- snprintf (cmd, sizeof (cmd), "grep -q 'rtprio *[0-9][0-9]*' %s", limits);
+ snprintf (cmd, sizeof(cmd), "grep -q 'rtprio *[0-9][0-9]*' %s", limits);
if (system (cmd) == 0) {
return 1;
}
@@ -175,8 +180,9 @@ int system_has_rtprio_limits_conf ()
*
* @returns 0 is there is no 'audio' group, the group id otherwise
**/
-int system_has_audiogroup() {
- return get_group_by_name("audio") || get_group_by_name ("jackuser");
+int system_has_audiogroup ()
+{
+ return get_group_by_name ("audio") || get_group_by_name ("jackuser");
}
@@ -185,36 +191,37 @@ int system_has_audiogroup() {
*
* @returns 0 if the owner of this process is not in the audio group, non-0 otherwise
**/
-int system_user_in_audiogroup() {
- gid_t* list = (gid_t*) malloc(MAX_GROUPS * sizeof(gid_t));
- int num_groups, i=0, found=0;
+int system_user_in_audiogroup ()
+{
+ gid_t* list = (gid_t*)malloc (MAX_GROUPS * sizeof(gid_t));
+ int num_groups, i = 0, found = 0;
unsigned int gid;
- if (NULL==list) {
- perror("Cannot allocate group list structure");
- exit(EXIT_FAILURE);
- }
-
- gid = get_group_by_name("audio");
- if (0==gid) {
- fprintf(stderr, "No audio group found\n");
- exit(EXIT_FAILURE);
- }
-
- num_groups = getgroups(MAX_GROUPS, list);
-
- while (i<num_groups) {
- if (list[i]==gid) {
- found = 1;
- i = num_groups;
- }
-
- i++;
- }
-
- free(list);
-
- return found;
+ if (NULL == list) {
+ perror ("Cannot allocate group list structure");
+ exit (EXIT_FAILURE);
+ }
+
+ gid = get_group_by_name ("audio");
+ if (0 == gid) {
+ fprintf (stderr, "No audio group found\n");
+ exit (EXIT_FAILURE);
+ }
+
+ num_groups = getgroups (MAX_GROUPS, list);
+
+ while (i < num_groups) {
+ if (list[i] == gid) {
+ found = 1;
+ i = num_groups;
+ }
+
+ i++;
+ }
+
+ free (list);
+
+ return found;
}
@@ -223,38 +230,40 @@ int system_user_in_audiogroup() {
*
* @returns 0 if this process can not be switched to rt prio, non-0 otherwise
**/
-int system_user_can_rtprio() {
- int min_prio;
- struct sched_param schparam;
-
- memset(&schparam, 0, sizeof(struct sched_param));
-
- if (-1 == (min_prio = sched_get_priority_min(SCHED_FIFO))) {
- perror("sched_get_priority");
- exit(EXIT_FAILURE);
- }
- schparam.sched_priority = min_prio;
-
- if (0 == sched_setscheduler(0, SCHED_FIFO, &schparam)) {
- // TODO: restore previous state
- schparam.sched_priority = 0;
- if (0 != sched_setscheduler(0, SCHED_OTHER, &schparam)) {
- perror("sched_setscheduler");
- exit(EXIT_FAILURE);
- }
- return 1;
- }
-
- return 0;
+int system_user_can_rtprio ()
+{
+ int min_prio;
+ struct sched_param schparam;
+
+ memset (&schparam, 0, sizeof(struct sched_param));
+
+ if (-1 == (min_prio = sched_get_priority_min (SCHED_FIFO))) {
+ perror ("sched_get_priority");
+ exit (EXIT_FAILURE);
+ }
+ schparam.sched_priority = min_prio;
+
+ if (0 == sched_setscheduler (0, SCHED_FIFO, &schparam)) {
+ // TODO: restore previous state
+ schparam.sched_priority = 0;
+ if (0 != sched_setscheduler (0, SCHED_OTHER, &schparam)) {
+ perror ("sched_setscheduler");
+ exit (EXIT_FAILURE);
+ }
+ return 1;
+ }
+
+ return 0;
}
-long long unsigned int system_memlock_amount() {
+long long unsigned int system_memlock_amount ()
+{
struct rlimit limits;
- if (-1==getrlimit(RLIMIT_MEMLOCK, &limits)) {
- perror("getrlimit on RLIMIT_MEMLOCK");
- exit(EXIT_FAILURE);
+ if (-1 == getrlimit (RLIMIT_MEMLOCK, &limits)) {
+ perror ("getrlimit on RLIMIT_MEMLOCK");
+ exit (EXIT_FAILURE);
}
return limits.rlim_max;
@@ -266,26 +275,28 @@ long long unsigned int system_memlock_amount() {
*
* @returns - 0 if the memlock limit is limited, non-0 otherwise
**/
-int system_memlock_is_unlimited() {
- return ((RLIM_INFINITY==system_memlock_amount())?1:0);
+int system_memlock_is_unlimited ()
+{
+ return (RLIM_INFINITY == system_memlock_amount ()) ? 1 : 0;
}
-long long unsigned int system_available_physical_mem() {
+long long unsigned int system_available_physical_mem ()
+{
char buf[256];
long long unsigned int res = 0;
- if (0<read_string("/proc/meminfo", buf, sizeof (buf))) {
+ if (0 < read_string ("/proc/meminfo", buf, sizeof(buf))) {
if (strncmp (buf, "MemTotal:", 9) == 0) {
if (sscanf (buf, "%*s %llu", &res) != 1) {
perror ("parse error in /proc/meminfo");
- }
+ }
}
} else {
- perror("read from /proc/meminfo");
+ perror ("read from /proc/meminfo");
}
- return res*1024;
+ return res * 1024;
}
@@ -295,19 +306,21 @@ long long unsigned int system_available_physical_mem() {
*
* @returns String with the full version of the kernel
**/
-char* system_kernel_version() {
- return NULL;
+char* system_kernel_version ()
+{
+ return NULL;
}
-char* system_get_username() {
- char* res = NULL;
- char* name = NULL;
+char* system_get_username ()
+{
+ char* res = NULL;
+ char* name = NULL;
- if ((name = getlogin())) {
- res = strdup(name);
- }
+ if ((name = getlogin ())) {
+ res = strdup (name);
+ }
- return res;
+ return res;
}
diff --git a/config/os/gnu-linux/time.c b/config/os/gnu-linux/time.c
index 982a290..9f9c3a4 100644
--- a/config/os/gnu-linux/time.c
+++ b/config/os/gnu-linux/time.c
@@ -2,22 +2,22 @@
/*
Copyright (C) 2001-2003 Paul Davis
Copyright (C) 2005 Jussi Laako
-
+
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
+ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
+ */
#include <config.h>
@@ -27,11 +27,11 @@ jack_time_t (*_jack_get_microseconds)(void) = 0;
#if defined(__gnu_linux__) && (defined(__i386__) || defined(__x86_64__))
#define HPET_SUPPORT
-#define HPET_MMAP_SIZE 1024
-#define HPET_CAPS 0x000
-#define HPET_PERIOD 0x004
-#define HPET_COUNTER 0x0f0
-#define HPET_CAPS_COUNTER_64BIT (1 << 13)
+#define HPET_MMAP_SIZE 1024
+#define HPET_CAPS 0x000
+#define HPET_PERIOD 0x004
+#define HPET_COUNTER 0x0f0
+#define HPET_CAPS_COUNTER_64BIT (1 << 13)
#if defined(__x86_64__)
typedef uint64_t hpet_counter_t;
#else
@@ -51,14 +51,14 @@ jack_hpet_init ()
{
uint32_t hpet_caps;
- hpet_fd = open("/dev/hpet", O_RDONLY);
+ hpet_fd = open ("/dev/hpet", O_RDONLY);
if (hpet_fd < 0) {
jack_error ("This system has no accessible HPET device (%s)", strerror (errno));
return -1;
}
- hpet_ptr = (unsigned char *) mmap(NULL, HPET_MMAP_SIZE,
- PROT_READ, MAP_SHARED, hpet_fd, 0);
+ hpet_ptr = (unsigned char*)mmap (NULL, HPET_MMAP_SIZE,
+ PROT_READ, MAP_SHARED, hpet_fd, 0);
if (hpet_ptr == MAP_FAILED) {
jack_error ("This system has no mappable HPET device (%s)", strerror (errno));
close (hpet_fd);
@@ -66,30 +66,31 @@ jack_hpet_init ()
}
/* this assumes period to be constant. if needed,
- it can be moved to the clock access function
- */
- hpet_period = *((uint32_t *) (hpet_ptr + HPET_PERIOD));
- hpet_caps = *((uint32_t *) (hpet_ptr + HPET_CAPS));
+ it can be moved to the clock access function
+ */
+ hpet_period = *((uint32_t*)(hpet_ptr + HPET_PERIOD));
+ hpet_caps = *((uint32_t*)(hpet_ptr + HPET_CAPS));
hpet_wrap = ((hpet_caps & HPET_CAPS_COUNTER_64BIT) &&
- (sizeof(hpet_counter_t) == sizeof(uint64_t))) ?
- 0 : ((uint64_t) 1 << 32);
+ (sizeof(hpet_counter_t) == sizeof(uint64_t))) ?
+ 0 : ((uint64_t)1 << 32);
return 0;
}
static jack_time_t
-jack_get_microseconds_from_hpet (void)
+jack_get_microseconds_from_hpet (void)
{
hpet_counter_t hpet_counter;
long double hpet_time;
- hpet_counter = *((hpet_counter_t *) (hpet_ptr + HPET_COUNTER));
- if (unlikely(hpet_counter < hpet_previous))
+ hpet_counter = *((hpet_counter_t*)(hpet_ptr + HPET_COUNTER));
+ if (unlikely (hpet_counter < hpet_previous)) {
hpet_offset += hpet_wrap;
+ }
hpet_previous = hpet_counter;
- hpet_time = (long double) (hpet_offset + hpet_counter) *
- (long double) hpet_period * (long double) 1e-9;
- return ((jack_time_t) (hpet_time + 0.5));
+ hpet_time = (long double)(hpet_offset + hpet_counter) *
+ (long double)hpet_period * (long double)1e-9;
+ return (jack_time_t)(hpet_time + 0.5);
}
#else
@@ -103,7 +104,7 @@ jack_hpet_init ()
}
static jack_time_t
-jack_get_microseconds_from_hpet (void)
+jack_get_microseconds_from_hpet (void)
{
/* never called */
return 0;
@@ -121,8 +122,7 @@ jack_init_time ()
void
jack_set_clock_source (jack_timer_type_t clocksrc)
{
- switch (clocksrc)
- {
+ switch (clocksrc) {
case JACK_TIMER_HPET:
if (jack_hpet_init () == 0) {
_jack_get_microseconds = jack_get_microseconds_from_hpet;
diff --git a/config/os/gnu-linux/time.h b/config/os/gnu-linux/time.h
index 16e7e58..c7b7150 100644
--- a/config/os/gnu-linux/time.h
+++ b/config/os/gnu-linux/time.h
@@ -3,22 +3,22 @@
Copyright (C) 2005 Jussi Laako
This is the GNU/Linux version.
-
+
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
+ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
+ */
#ifndef __jack_time_h__
#define __jack_time_h__
@@ -28,15 +28,15 @@
extern jack_time_t (*_jack_get_microseconds)(void);
static inline jack_time_t
-jack_get_microseconds (void)
+jack_get_microseconds (void)
{
return _jack_get_microseconds ();
}
typedef jack_time_t (*jack_get_microseconds_t)(void);
-static inline jack_get_microseconds_t jack_get_microseconds_pointer(void)
+static inline jack_get_microseconds_t jack_get_microseconds_pointer (void)
{
- return _jack_get_microseconds;
+ return _jack_get_microseconds;
}
#endif /* __jack_time_h__ */
diff --git a/config/os/macosx/getopt.h b/config/os/macosx/getopt.h
index 7275c59..02b53e9 100644
--- a/config/os/macosx/getopt.h
+++ b/config/os/macosx/getopt.h
@@ -14,9 +14,9 @@
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.
-
+
Grame Research Laboratory, 9, rue du Garet 69001 Lyon - France
grame@rd.grame.fr
-*/
+ */
#include "/Developer/SDKs/MacOSX10.3.0.sdk/usr/include/getopt.h"
diff --git a/config/os/macosx/ipc.h b/config/os/macosx/ipc.h
index 8c0e546..73825c4 100644
--- a/config/os/macosx/ipc.h
+++ b/config/os/macosx/ipc.h
@@ -14,10 +14,10 @@
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.
-
+
Grame Research Laboratory, 9, rue du Garet 69001 Lyon - France
grame@rd.grame.fr
-*/
+ */
#ifndef __ipc__
#define __ipc__
@@ -26,140 +26,142 @@
#include <servers/bootstrap.h>
#include "internal.h"
#include "engine.h"
-#include "libjack/local.h" /* JOQ: fix me */
+#include "libjack/local.h" /* JOQ: fix me */
/*
RPC without time out can put the jack server in a blocked state
(waiting for the client answer) when a client is killed. The
mach_msg function does not return any error in this case. Using
time out solve the problem but does not seems really satisfactory.
-*/
+ */
#define WAIT 2500 /* in millisecond */
-static inline int
-jack_client_resume(jack_client_internal_t *client)
+static inline int
+jack_client_resume (jack_client_internal_t *client)
{
- mach_msg_header_t *head = &client->message.header;
- int err;
-
- if (!client->running) {
- err = mach_msg (head, MACH_RCV_MSG, 0, sizeof(client->message),
- client->serverport, 0, MACH_PORT_NULL);
- if (err) {
- jack_error("jack_client_resume: priming receive error: %s\n",
- mach_error_string(err));
- return -1;
- }
- client->running = TRUE;
- }else {
- /* remote port is already the send-once he sent us */
- head->msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_MOVE_SEND_ONCE, 0);
- head->msgh_local_port = MACH_PORT_NULL;
- head->msgh_size = sizeof(mach_msg_header_t);
-
- err = mach_msg(head, (MACH_SEND_MSG|MACH_RCV_MSG|
- MACH_SEND_TIMEOUT|MACH_RCV_TIMEOUT),
- sizeof(*head), sizeof(client->message),
- client->serverport, WAIT, MACH_PORT_NULL);
-
- if (err) {
-
- /*
- switch(err) {
- case MACH_SEND_TIMED_OUT:
- jack_error("MACH_SEND_TIMED_OUT %s\n",
- client->control->name);
- break;
-
- case MACH_RCV_TIMED_OUT:
- jack_error("MACH_RCV_TIMED_OUT %s\n",
- client->control->name);
- break;
-
- case MACH_SEND_INVALID_DEST:
- jack_error("MACH_SEND_INVALID_DEST %s\n",
- client->control->name);
- break;
- }
- */
-
- jack_error("jack_client_resume: send error for %s\n",
- mach_error_string(err));
- return err;
- }
- }
-
- return 0;
+ mach_msg_header_t *head = &client->message.header;
+ int err;
+
+ if (!client->running) {
+ err = mach_msg (head, MACH_RCV_MSG, 0, sizeof(client->message),
+ client->serverport, 0, MACH_PORT_NULL);
+ if (err) {
+ jack_error ("jack_client_resume: priming receive error: %s\n",
+ mach_error_string (err));
+ return -1;
+ }
+ client->running = TRUE;
+ } else {
+ /* remote port is already the send-once he sent us */
+ head->msgh_bits = MACH_MSGH_BITS (MACH_MSG_TYPE_MOVE_SEND_ONCE, 0);
+ head->msgh_local_port = MACH_PORT_NULL;
+ head->msgh_size = sizeof(mach_msg_header_t);
+
+ err = mach_msg (head, (MACH_SEND_MSG | MACH_RCV_MSG |
+ MACH_SEND_TIMEOUT | MACH_RCV_TIMEOUT),
+ sizeof(*head), sizeof(client->message),
+ client->serverport, WAIT, MACH_PORT_NULL);
+
+ if (err) {
+
+ /*
+ switch(err) {
+ case MACH_SEND_TIMED_OUT:
+ jack_error("MACH_SEND_TIMED_OUT %s\n",
+ client->control->name);
+ break;
+
+ case MACH_RCV_TIMED_OUT:
+ jack_error("MACH_RCV_TIMED_OUT %s\n",
+ client->control->name);
+ break;
+
+ case MACH_SEND_INVALID_DEST:
+ jack_error("MACH_SEND_INVALID_DEST %s\n",
+ client->control->name);
+ break;
+ }
+ */
+
+ jack_error ("jack_client_resume: send error for %s\n",
+ mach_error_string (err));
+ return err;
+ }
+ }
+
+ return 0;
}
-static inline int
-jack_client_suspend(jack_client_t * client)
+static inline int
+jack_client_suspend (jack_client_t * client)
{
- int err = 0;
- mach_msg_header_t * head = &client->message.header;
-
- head->msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND,
- MACH_MSG_TYPE_MAKE_SEND_ONCE);
- head->msgh_remote_port = client->serverport;
+ int err = 0;
+ mach_msg_header_t * head = &client->message.header;
+
+ head->msgh_bits = MACH_MSGH_BITS (MACH_MSG_TYPE_COPY_SEND,
+ MACH_MSG_TYPE_MAKE_SEND_ONCE);
+ head->msgh_remote_port = client->serverport;
head->msgh_local_port = client->replyport;
head->msgh_size = sizeof(mach_msg_header_t);
-
- err = mach_msg(head, MACH_SEND_MSG|MACH_RCV_MSG|MACH_SEND_TIMEOUT,
- sizeof(mach_msg_header_t), sizeof(client->message),
- client->replyport, WAIT, MACH_PORT_NULL);
-
- if (err) {
- jack_error("jack_client_suspend: RPC error: %s\n",
- mach_error_string(err));
- return -1;
- }
-
- return 0;
+
+ err = mach_msg (head, MACH_SEND_MSG | MACH_RCV_MSG | MACH_SEND_TIMEOUT,
+ sizeof(mach_msg_header_t), sizeof(client->message),
+ client->replyport, WAIT, MACH_PORT_NULL);
+
+ if (err) {
+ jack_error ("jack_client_suspend: RPC error: %s\n",
+ mach_error_string (err));
+ return -1;
+ }
+
+ return 0;
}
-static inline void
-allocate_mach_serverport(jack_engine_t * engine, jack_client_internal_t *client)
+static inline void
+allocate_mach_serverport (jack_engine_t * engine, jack_client_internal_t *client)
{
- char buf[256];
- snprintf(buf, 256, "JackMachPort_%d", engine->portnum);
-
- if (mach_port_allocate(engine->servertask, MACH_PORT_RIGHT_RECEIVE,
- &client->serverport)){
- jack_error("allocate_mach_serverport: can't allocate mach port");
- }
-
- if (mach_port_insert_right(engine->servertask, client->serverport,
- client->serverport, MACH_MSG_TYPE_MAKE_SEND)){
- jack_error("allocate_mach_serverport: error inserting mach rights");
- }
-
- if (bootstrap_register(engine->bp, buf, client->serverport)){
- jack_error("allocate_mach_serverport: can't check in mach port");
- }
-
- client->portnum = engine->portnum;
- engine->portnum++;
+ char buf[256];
+
+ snprintf (buf, 256, "JackMachPort_%d", engine->portnum);
+
+ if (mach_port_allocate (engine->servertask, MACH_PORT_RIGHT_RECEIVE,
+ &client->serverport)) {
+ jack_error ("allocate_mach_serverport: can't allocate mach port");
+ }
+
+ if (mach_port_insert_right (engine->servertask, client->serverport,
+ client->serverport, MACH_MSG_TYPE_MAKE_SEND)) {
+ jack_error ("allocate_mach_serverport: error inserting mach rights");
+ }
+
+ if (bootstrap_register (engine->bp, buf, client->serverport)) {
+ jack_error ("allocate_mach_serverport: can't check in mach port");
+ }
+
+ client->portnum = engine->portnum;
+ engine->portnum++;
}
-static inline int
-allocate_mach_clientport(jack_client_t * client, int portnum)
+static inline int
+allocate_mach_clientport (jack_client_t * client, int portnum)
{
- char buf[256];
- snprintf(buf, 256, "JackMachPort_%d", portnum);
-
- if (bootstrap_look_up(client->bp, buf, &client->serverport)){
- jack_error ("allocate_mach_clientport: can't find mach server port");
- return -1;
- }
-
- if (mach_port_allocate(client->clienttask, MACH_PORT_RIGHT_RECEIVE,
- &client->replyport)){
- jack_error("allocate_mach_clientport: can't allocate mach port");
- return -1;
- }
-
- return 0;
+ char buf[256];
+
+ snprintf (buf, 256, "JackMachPort_%d", portnum);
+
+ if (bootstrap_look_up (client->bp, buf, &client->serverport)) {
+ jack_error ("allocate_mach_clientport: can't find mach server port");
+ return -1;
+ }
+
+ if (mach_port_allocate (client->clienttask, MACH_PORT_RIGHT_RECEIVE,
+ &client->replyport)) {
+ jack_error ("allocate_mach_clientport: can't allocate mach port");
+ return -1;
+ }
+
+ return 0;
}
#endif /* __ipc__ */
diff --git a/config/os/macosx/mach_port.h b/config/os/macosx/mach_port.h
index efa4839..569a9cf 100644
--- a/config/os/macosx/mach_port.h
+++ b/config/os/macosx/mach_port.h
@@ -14,22 +14,22 @@
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.
-
+
Grame Research Laboratory, 9, rue du Garet 69001 Lyon - France
grame@rd.grame.fr
-*/
+ */
#ifndef __mach_port__
#define __mach_port__
-#include <mach/mach.h>
+#include <mach/mach.h>
#include <mach/mach_types.h>
#include <mach/message.h>
-
+
/* specific ressources for server/client real-time thread communication */
typedef struct {
- mach_msg_header_t header;
- mach_msg_trailer_t trailer;
+ mach_msg_header_t header;
+ mach_msg_trailer_t trailer;
} trivial_message;
#endif \ No newline at end of file
diff --git a/config/os/macosx/pThreadUtilities.h b/config/os/macosx/pThreadUtilities.h
index bd1d1e8..a8ed705 100644
--- a/config/os/macosx/pThreadUtilities.h
+++ b/config/os/macosx/pThreadUtilities.h
@@ -1,65 +1,65 @@
/*
- Copyright: © Copyright 2002 Apple Computer, Inc. All rights
- reserved.
-
- Disclaimer: IMPORTANT: This Apple software is supplied to
- you by Apple Computer, Inc. ("Apple") in
- consideration of your agreement to the
- following terms, and your use, installation,
- modification or redistribution of this Apple
- software constitutes acceptance of these
- terms. If you do not agree with these terms,
- please do not use, install, modify or
- redistribute this Apple software.
-
- In consideration of your agreement to abide by
- the following terms, and subject to these
- terms, Apple grants you a personal,
- non-exclusive license, under AppleÕs
- copyrights in this original Apple software
- (the "Apple Software"), to use, reproduce,
- modify and redistribute the Apple Software,
- with or without modifications, in source
- and/or binary forms; provided that if you
- redistribute the Apple Software in its
- entirety and without modifications, you must
- retain this notice and the following text and
- disclaimers in all such redistributions of the
- Apple Software. Neither the name, trademarks,
- service marks or logos of Apple Computer,
- Inc. may be used to endorse or promote
- products derived from the Apple Software
- without specific prior written permission from
- Apple. Except as expressly stated in this
- notice, no other rights or licenses, express
- or implied, are granted by Apple herein,
- including but not limited to any patent rights
- that may be infringed by your derivative works
- or by other works in which the Apple Software
- may be incorporated.
-
- The Apple Software is provided by Apple on an
- "AS IS" basis. APPLE MAKES NO WARRANTIES,
- EXPRESS OR IMPLIED, INCLUDING WITHOUT
- LIMITATION THE IMPLIED WARRANTIES OF
- NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
- FOR A PARTICULAR PURPOSE, REGARDING THE APPLE
- SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
- COMBINATION WITH YOUR PRODUCTS.
-
- IN NO EVENT SHALL APPLE BE LIABLE FOR ANY
- SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL
- DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) ARISING IN ANY WAY OUT OF THE
- USE, REPRODUCTION, MODIFICATION AND/OR
- DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER
- CAUSED AND WHETHER UNDER THEORY OF CONTRACT,
- TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY
- OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED
- OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
+ Copyright: © Copyright 2002 Apple Computer, Inc. All rights
+ reserved.
+
+ Disclaimer: IMPORTANT: This Apple software is supplied to
+ you by Apple Computer, Inc. ("Apple") in
+ consideration of your agreement to the
+ following terms, and your use, installation,
+ modification or redistribution of this Apple
+ software constitutes acceptance of these
+ terms. If you do not agree with these terms,
+ please do not use, install, modify or
+ redistribute this Apple software.
+
+ In consideration of your agreement to abide by
+ the following terms, and subject to these
+ terms, Apple grants you a personal,
+ non-exclusive license, under AppleÕs
+ copyrights in this original Apple software
+ (the "Apple Software"), to use, reproduce,
+ modify and redistribute the Apple Software,
+ with or without modifications, in source
+ and/or binary forms; provided that if you
+ redistribute the Apple Software in its
+ entirety and without modifications, you must
+ retain this notice and the following text and
+ disclaimers in all such redistributions of the
+ Apple Software. Neither the name, trademarks,
+ service marks or logos of Apple Computer,
+ Inc. may be used to endorse or promote
+ products derived from the Apple Software
+ without specific prior written permission from
+ Apple. Except as expressly stated in this
+ notice, no other rights or licenses, express
+ or implied, are granted by Apple herein,
+ including but not limited to any patent rights
+ that may be infringed by your derivative works
+ or by other works in which the Apple Software
+ may be incorporated.
+
+ The Apple Software is provided by Apple on an
+ "AS IS" basis. APPLE MAKES NO WARRANTIES,
+ EXPRESS OR IMPLIED, INCLUDING WITHOUT
+ LIMITATION THE IMPLIED WARRANTIES OF
+ NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
+ FOR A PARTICULAR PURPOSE, REGARDING THE APPLE
+ SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
+ COMBINATION WITH YOUR PRODUCTS.
+
+ IN NO EVENT SHALL APPLE BE LIABLE FOR ANY
+ SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) ARISING IN ANY WAY OUT OF THE
+ USE, REPRODUCTION, MODIFICATION AND/OR
+ DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER
+ CAUSED AND WHETHER UNDER THEORY OF CONTRACT,
+ TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY
+ OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED
+ OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
/* pThreadUtilities.h */
#ifndef __PTHREADUTILITIES_H__
@@ -68,8 +68,8 @@
#import "pthread.h"
#import <CoreServices/../Frameworks/CarbonCore.framework/Headers/MacTypes.h>
-#define THREAD_SET_PRIORITY 0
-#define THREAD_SCHEDULED_PRIORITY 1
+#define THREAD_SET_PRIORITY 0
+#define THREAD_SCHEDULED_PRIORITY 1
#include <mach/mach_error.h>
#include <mach/thread_policy.h>
@@ -77,127 +77,126 @@
#include <CoreAudio/HostTime.h>
static inline UInt32
-_getThreadPriority(pthread_t inThread, int inWhichPriority)
+_getThreadPriority (pthread_t inThread, int inWhichPriority)
{
- thread_basic_info_data_t threadInfo;
- policy_info_data_t thePolicyInfo;
- unsigned int count;
-
- // get basic info
- count = THREAD_BASIC_INFO_COUNT;
- thread_info (pthread_mach_thread_np (inThread), THREAD_BASIC_INFO,
- (thread_info_t)&threadInfo, &count);
-
- switch (threadInfo.policy) {
- case POLICY_TIMESHARE:
- count = POLICY_TIMESHARE_INFO_COUNT;
- thread_info(pthread_mach_thread_np (inThread),
- THREAD_SCHED_TIMESHARE_INFO,
- (thread_info_t)&(thePolicyInfo.ts), &count);
- if (inWhichPriority == THREAD_SCHEDULED_PRIORITY) {
- return thePolicyInfo.ts.cur_priority;
- } else {
- return thePolicyInfo.ts.base_priority;
- }
- break;
-
- case POLICY_FIFO:
- count = POLICY_FIFO_INFO_COUNT;
- thread_info(pthread_mach_thread_np (inThread),
- THREAD_SCHED_FIFO_INFO,
- (thread_info_t)&(thePolicyInfo.fifo), &count);
- if ( (thePolicyInfo.fifo.depressed)
- && (inWhichPriority == THREAD_SCHEDULED_PRIORITY) ) {
- return thePolicyInfo.fifo.depress_priority;
- }
- return thePolicyInfo.fifo.base_priority;
- break;
-
- case POLICY_RR:
- count = POLICY_RR_INFO_COUNT;
- thread_info(pthread_mach_thread_np (inThread),
- THREAD_SCHED_RR_INFO,
- (thread_info_t)&(thePolicyInfo.rr), &count);
- if ( (thePolicyInfo.rr.depressed)
- && (inWhichPriority == THREAD_SCHEDULED_PRIORITY) ) {
- return thePolicyInfo.rr.depress_priority;
- }
- return thePolicyInfo.rr.base_priority;
- break;
- }
-
- return 0;
+ thread_basic_info_data_t threadInfo;
+ policy_info_data_t thePolicyInfo;
+ unsigned int count;
+
+ // get basic info
+ count = THREAD_BASIC_INFO_COUNT;
+ thread_info (pthread_mach_thread_np (inThread), THREAD_BASIC_INFO,
+ (thread_info_t)&threadInfo, &count);
+
+ switch (threadInfo.policy) {
+ case POLICY_TIMESHARE:
+ count = POLICY_TIMESHARE_INFO_COUNT;
+ thread_info (pthread_mach_thread_np (inThread),
+ THREAD_SCHED_TIMESHARE_INFO,
+ (thread_info_t)&(thePolicyInfo.ts), &count);
+ if (inWhichPriority == THREAD_SCHEDULED_PRIORITY) {
+ return thePolicyInfo.ts.cur_priority;
+ } else {
+ return thePolicyInfo.ts.base_priority;
+ }
+ break;
+
+ case POLICY_FIFO:
+ count = POLICY_FIFO_INFO_COUNT;
+ thread_info (pthread_mach_thread_np (inThread),
+ THREAD_SCHED_FIFO_INFO,
+ (thread_info_t)&(thePolicyInfo.fifo), &count);
+ if ( (thePolicyInfo.fifo.depressed)
+ && (inWhichPriority == THREAD_SCHEDULED_PRIORITY) ) {
+ return thePolicyInfo.fifo.depress_priority;
+ }
+ return thePolicyInfo.fifo.base_priority;
+ break;
+
+ case POLICY_RR:
+ count = POLICY_RR_INFO_COUNT;
+ thread_info (pthread_mach_thread_np (inThread),
+ THREAD_SCHED_RR_INFO,
+ (thread_info_t)&(thePolicyInfo.rr), &count);
+ if ( (thePolicyInfo.rr.depressed)
+ && (inWhichPriority == THREAD_SCHEDULED_PRIORITY) ) {
+ return thePolicyInfo.rr.depress_priority;
+ }
+ return thePolicyInfo.rr.base_priority;
+ break;
+ }
+
+ return 0;
}
// returns the thread's priority as it was last set by the API
static inline UInt32
-getThreadSetPriority(pthread_t inThread)
+getThreadSetPriority (pthread_t inThread)
{
- return _getThreadPriority (inThread, THREAD_SET_PRIORITY);
+ return _getThreadPriority (inThread, THREAD_SET_PRIORITY);
}
// returns the thread's priority as it was last scheduled by the Kernel
static inline UInt32
-getThreadScheduledPriority(pthread_t inThread)
+getThreadScheduledPriority (pthread_t inThread)
{
- return _getThreadPriority (inThread, THREAD_SCHEDULED_PRIORITY);
+ return _getThreadPriority (inThread, THREAD_SCHEDULED_PRIORITY);
}
static inline void
-setThreadToPriority(pthread_t inThread, UInt32 inPriority, Boolean inIsFixed,
- UInt64 inHALIOProcCycleDurationInNanoseconds)
+setThreadToPriority (pthread_t inThread, UInt32 inPriority, Boolean inIsFixed,
+ UInt64 inHALIOProcCycleDurationInNanoseconds)
{
- if (inPriority == 96)
- {
- // REAL-TIME / TIME-CONSTRAINT THREAD
- thread_time_constraint_policy_data_t theTCPolicy;
- UInt64 theComputeQuanta;
- UInt64 thePeriod;
- UInt64 thePeriodNanos;
-
- thePeriodNanos = inHALIOProcCycleDurationInNanoseconds;
- theComputeQuanta = AudioConvertNanosToHostTime ( thePeriodNanos * 0.15 );
- thePeriod = AudioConvertNanosToHostTime (thePeriodNanos);
-
- theTCPolicy.period = thePeriod;
- theTCPolicy.computation = theComputeQuanta;
- theTCPolicy.constraint = thePeriod;
- theTCPolicy.preemptible = true;
- thread_policy_set (pthread_mach_thread_np(inThread),
- THREAD_TIME_CONSTRAINT_POLICY,
- (thread_policy_t)&theTCPolicy,
- THREAD_TIME_CONSTRAINT_POLICY_COUNT);
+ if (inPriority == 96) {
+ // REAL-TIME / TIME-CONSTRAINT THREAD
+ thread_time_constraint_policy_data_t theTCPolicy;
+ UInt64 theComputeQuanta;
+ UInt64 thePeriod;
+ UInt64 thePeriodNanos;
+
+ thePeriodNanos = inHALIOProcCycleDurationInNanoseconds;
+ theComputeQuanta = AudioConvertNanosToHostTime ( thePeriodNanos * 0.15 );
+ thePeriod = AudioConvertNanosToHostTime (thePeriodNanos);
+
+ theTCPolicy.period = thePeriod;
+ theTCPolicy.computation = theComputeQuanta;
+ theTCPolicy.constraint = thePeriod;
+ theTCPolicy.preemptible = true;
+ thread_policy_set (pthread_mach_thread_np (inThread),
+ THREAD_TIME_CONSTRAINT_POLICY,
+ (thread_policy_t)&theTCPolicy,
+ THREAD_TIME_CONSTRAINT_POLICY_COUNT);
} else {
- // OTHER THREADS
- thread_extended_policy_data_t theFixedPolicy;
- thread_precedence_policy_data_t thePrecedencePolicy;
- SInt32 relativePriority;
-
- // [1] SET FIXED / NOT FIXED
- theFixedPolicy.timeshare = !inIsFixed;
- thread_policy_set (pthread_mach_thread_np(inThread),
- THREAD_EXTENDED_POLICY,
- (thread_policy_t)&theFixedPolicy,
- THREAD_EXTENDED_POLICY_COUNT);
-
- // [2] SET PRECEDENCE N.B.: We expect that if thread A
- // created thread B, and the program wishes to change the
- // priority of thread B, then the call to change the
- // priority of thread B must be made by thread A. This
- // assumption allows us to use pthread_self() to correctly
- // calculate the priority of the feeder thread (since
- // precedency policy's importance is relative to the
- // spawning thread's priority.)
- relativePriority = inPriority -
- getThreadSetPriority (pthread_self());
-
- thePrecedencePolicy.importance = relativePriority;
- thread_policy_set (pthread_mach_thread_np(inThread),
- THREAD_PRECEDENCE_POLICY,
- (thread_policy_t)&thePrecedencePolicy,
- THREAD_PRECEDENCE_POLICY_COUNT);
+ // OTHER THREADS
+ thread_extended_policy_data_t theFixedPolicy;
+ thread_precedence_policy_data_t thePrecedencePolicy;
+ SInt32 relativePriority;
+
+ // [1] SET FIXED / NOT FIXED
+ theFixedPolicy.timeshare = !inIsFixed;
+ thread_policy_set (pthread_mach_thread_np (inThread),
+ THREAD_EXTENDED_POLICY,
+ (thread_policy_t)&theFixedPolicy,
+ THREAD_EXTENDED_POLICY_COUNT);
+
+ // [2] SET PRECEDENCE N.B.: We expect that if thread A
+ // created thread B, and the program wishes to change the
+ // priority of thread B, then the call to change the
+ // priority of thread B must be made by thread A. This
+ // assumption allows us to use pthread_self() to correctly
+ // calculate the priority of the feeder thread (since
+ // precedency policy's importance is relative to the
+ // spawning thread's priority.)
+ relativePriority = inPriority -
+ getThreadSetPriority (pthread_self ());
+
+ thePrecedencePolicy.importance = relativePriority;
+ thread_policy_set (pthread_mach_thread_np (inThread),
+ THREAD_PRECEDENCE_POLICY,
+ (thread_policy_t)&thePrecedencePolicy,
+ THREAD_PRECEDENCE_POLICY_COUNT);
}
}
-#endif /* __PTHREADUTILITIES_H__ */
+#endif /* __PTHREADUTILITIES_H__ */
diff --git a/config/os/macosx/poll.h b/config/os/macosx/poll.h
index 6a49e0d..d7445c7 100644
--- a/config/os/macosx/poll.h
+++ b/config/os/macosx/poll.h
@@ -4,13 +4,13 @@
// Warning: a call to this poll() takes about 4K of stack space.
// Greg Parker gparker-web@sealiesoftware.com December 2000
-// This code is in the public domain and may be copied or modified without
-// permission.
+// This code is in the public domain and may be copied or modified without
+// permission.
-// Updated May 2002:
+// Updated May 2002:
// * fix crash when an fd is less than 0
// * set errno=EINVAL if an fd is greater or equal to FD_SETSIZE
-// * don't set POLLIN or POLLOUT in revents if it wasn't requested
+// * don't set POLLIN or POLLOUT in revents if it wasn't requested
// in events (only happens when an fd is in the poll set twice)
#ifndef _FAKE_POLL_H
@@ -24,9 +24,9 @@
#include <errno.h>
typedef struct pollfd {
- int fd; /* file desc to poll */
- short events; /* events of interest on fd */
- short revents; /* events that occurred on fd */
+ int fd; /* file desc to poll */
+ short events; /* events of interest on fd */
+ short revents; /* events that occurred on fd */
} pollfd_t;
@@ -47,116 +47,119 @@ typedef struct pollfd {
#define POLLHUP 0x0010
#define POLLNVAL 0x0020
-static inline int
-poll(struct pollfd *pollSet, int pollCount, int pollTimeout)
+static inline int
+poll (struct pollfd *pollSet, int pollCount, int pollTimeout)
{
- struct timeval tv;
- struct timeval *tvp;
- fd_set readFDs, writeFDs, exceptFDs;
- fd_set *readp, *writep, *exceptp;
- struct pollfd *pollEnd, *p;
- int selected;
- int result;
- int maxFD;
-
- if (!pollSet) {
- pollEnd = NULL;
- readp = NULL;
- writep = NULL;
- exceptp = NULL;
- maxFD = 0;
- }
- else {
- pollEnd = pollSet + pollCount;
- readp = &readFDs;
- writep = &writeFDs;
- exceptp = &exceptFDs;
-
- FD_ZERO(readp);
- FD_ZERO(writep);
- FD_ZERO(exceptp);
-
- // Find the biggest fd in the poll set
- maxFD = 0;
- for (p = pollSet; p < pollEnd; p++) {
- if (p->fd > maxFD) maxFD = p->fd;
- }
-
- if (maxFD >= FD_SETSIZE) {
- // At least one fd is too big
- errno = EINVAL;
- return -1;
- }
-
- // Transcribe flags from the poll set to the fd sets
- for (p = pollSet; p < pollEnd; p++) {
- if (p->fd < 0) {
- // Negative fd checks nothing and always reports zero
- } else {
- if (p->events & POLLIN) FD_SET(p->fd, readp);
- if (p->events & POLLOUT) FD_SET(p->fd, writep);
- if (p->events != 0) {
- FD_SET(p->fd, exceptp);
- }
- // POLLERR is never set coming in; poll() always reports errors
- // But don't report if we're not listening to anything at all.
- }
- }
- }
-
- // poll timeout is in milliseconds. Convert to struct timeval.
- // poll timeout == -1 : wait forever : select timeout of NULL
- // poll timeout == 0 : return immediately : select timeout of zero
- if (pollTimeout >= 0) {
- tv.tv_sec = pollTimeout / 1000;
- tv.tv_usec = (pollTimeout % 1000) * 1000;
- tvp = &tv;
- } else {
- tvp = NULL;
- }
-
- selected = select(maxFD+1, readp, writep, exceptp, tvp);
-
- if (selected < 0) {
- // Error during select
- result = -1;
- }
- else if (selected > 0) {
- // Select found something
- // Transcribe result from fd sets to poll set.
- // Also count the number of selected fds. poll returns the
- // number of ready fds; select returns the number of bits set.
- int polled = 0;
- for (p = pollSet; p < pollEnd; p++) {
- p->revents = 0;
- if (p->fd < 0) {
- // Negative fd always reports zero
- } else {
- if ((p->events & POLLIN) && FD_ISSET(p->fd, readp)) {
- p->revents |= POLLIN;
- }
- if ((p->events & POLLOUT) && FD_ISSET(p->fd, writep)) {
- p->revents |= POLLOUT;
- }
- if ((p->events != 0) && FD_ISSET(p->fd, exceptp)) {
- p->revents |= POLLERR;
- }
-
- if (p->revents) polled++;
- }
+ struct timeval tv;
+ struct timeval *tvp;
+ fd_set readFDs, writeFDs, exceptFDs;
+ fd_set *readp, *writep, *exceptp;
+ struct pollfd *pollEnd, *p;
+ int selected;
+ int result;
+ int maxFD;
+
+ if (!pollSet) {
+ pollEnd = NULL;
+ readp = NULL;
+ writep = NULL;
+ exceptp = NULL;
+ maxFD = 0;
+ } else {
+ pollEnd = pollSet + pollCount;
+ readp = &readFDs;
+ writep = &writeFDs;
+ exceptp = &exceptFDs;
+
+ FD_ZERO (readp);
+ FD_ZERO (writep);
+ FD_ZERO (exceptp);
+
+ // Find the biggest fd in the poll set
+ maxFD = 0;
+ for (p = pollSet; p < pollEnd; p++)
+ if (p->fd > maxFD) {
+ maxFD = p->fd;
+ }
+
+ if (maxFD >= FD_SETSIZE) {
+ // At least one fd is too big
+ errno = EINVAL;
+ return -1;
+ }
+
+ // Transcribe flags from the poll set to the fd sets
+ for (p = pollSet; p < pollEnd; p++) {
+ if (p->fd < 0) {
+ // Negative fd checks nothing and always reports zero
+ } else {
+ if (p->events & POLLIN) {
+ FD_SET (p->fd, readp);
+ }
+ if (p->events & POLLOUT) {
+ FD_SET (p->fd, writep);
+ }
+ if (p->events != 0) {
+ FD_SET (p->fd, exceptp);
+ }
+ // POLLERR is never set coming in; poll() always reports errors
+ // But don't report if we're not listening to anything at all.
+ }
+ }
}
- result = polled;
- }
- else {
- // selected == 0, select timed out before anything happened
- // Clear all result bits and return zero.
- for (p = pollSet; p < pollEnd; p++) {
- p->revents = 0;
- }
- result = 0;
- }
-
- return result;
+
+ // poll timeout is in milliseconds. Convert to struct timeval.
+ // poll timeout == -1 : wait forever : select timeout of NULL
+ // poll timeout == 0 : return immediately : select timeout of zero
+ if (pollTimeout >= 0) {
+ tv.tv_sec = pollTimeout / 1000;
+ tv.tv_usec = (pollTimeout % 1000) * 1000;
+ tvp = &tv;
+ } else {
+ tvp = NULL;
+ }
+
+ selected = select (maxFD + 1, readp, writep, exceptp, tvp);
+
+ if (selected < 0) {
+ // Error during select
+ result = -1;
+ } else if (selected > 0) {
+ // Select found something
+ // Transcribe result from fd sets to poll set.
+ // Also count the number of selected fds. poll returns the
+ // number of ready fds; select returns the number of bits set.
+ int polled = 0;
+ for (p = pollSet; p < pollEnd; p++) {
+ p->revents = 0;
+ if (p->fd < 0) {
+ // Negative fd always reports zero
+ } else {
+ if ((p->events & POLLIN) && FD_ISSET (p->fd, readp)) {
+ p->revents |= POLLIN;
+ }
+ if ((p->events & POLLOUT) && FD_ISSET (p->fd, writep)) {
+ p->revents |= POLLOUT;
+ }
+ if ((p->events != 0) && FD_ISSET (p->fd, exceptp)) {
+ p->revents |= POLLERR;
+ }
+
+ if (p->revents) {
+ polled++;
+ }
+ }
+ }
+ result = polled;
+ } else {
+ // selected == 0, select timed out before anything happened
+ // Clear all result bits and return zero.
+ for (p = pollSet; p < pollEnd; p++)
+ p->revents = 0;
+ result = 0;
+ }
+
+ return result;
}
#endif
diff --git a/config/os/macosx/time.c b/config/os/macosx/time.c
index 6f050e3..a703ff5 100644
--- a/config/os/macosx/time.c
+++ b/config/os/macosx/time.c
@@ -1,21 +1,21 @@
/*
Copyright (C) 2001-2003 Paul Davis
-
+
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
+ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
+ */
#ifndef __jack_time_c__
#define __jack_time_c__
@@ -25,12 +25,13 @@
double __jack_time_ratio;
-void
+void
jack_init_time ()
{
- mach_timebase_info_data_t info;
- mach_timebase_info(&info);
- __jack_time_ratio = ((float)info.numer/info.denom) / 1000;
+ mach_timebase_info_data_t info;
+
+ mach_timebase_info (&info);
+ __jack_time_ratio = ((float)info.numer / info.denom) / 1000;
}
void jack_set_clock_source (jack_timer_type_t clocksrc)
@@ -38,9 +39,9 @@ void jack_set_clock_source (jack_timer_type_t clocksrc)
/* only one clock source for os x */
}
-jack_time_t
-jack_get_microseconds_symbol(void)
-{
- return (jack_time_t) mach_absolute_time () * __jack_time_ratio;
+jack_time_t
+jack_get_microseconds_symbol (void)
+{
+ return (jack_time_t)mach_absolute_time () * __jack_time_ratio;
}
#endif /* __jack_time_c__ */
diff --git a/config/os/macosx/time.h b/config/os/macosx/time.h
index 0a47f08..37acf62 100644
--- a/config/os/macosx/time.h
+++ b/config/os/macosx/time.h
@@ -1,21 +1,21 @@
/*
Copyright (C) 2001-2003 Paul Davis
-
+
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
+ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
+ */
#ifndef __jack_time_h__
#define __jack_time_h__
@@ -25,16 +25,16 @@
extern double __jack_time_ratio;
-static inline jack_time_t
-jack_get_microseconds(void)
-{
- return (jack_time_t) mach_absolute_time () * __jack_time_ratio;
+static inline jack_time_t
+jack_get_microseconds (void)
+{
+ return (jack_time_t)mach_absolute_time () * __jack_time_ratio;
}
extern jack_time_t jack_get_microseconds_symbol(void);
typedef jack_time_t (*jack_get_microseconds_t)(void);
-static inline jack_get_microseconds_t jack_get_microseconds_pointer(void)
+static inline jack_get_microseconds_t jack_get_microseconds_pointer (void)
{
return jack_get_microseconds_symbol;
}
diff --git a/config/sysdeps/atomicity.h b/config/sysdeps/atomicity.h
index 94b5e08..ae86b12 100644
--- a/config/sysdeps/atomicity.h
+++ b/config/sysdeps/atomicity.h
@@ -19,6 +19,6 @@
#include <config/cpu/generic/atomicity.h>
-#endif /* processor selection */
+#endif /* processor selection */
-#endif /* _jack_sysdep_atomicity_h_ */
+#endif /* _jack_sysdep_atomicity_h_ */
diff --git a/config/sysdeps/cycles.h b/config/sysdeps/cycles.h
index eac039e..62d86f1 100644
--- a/config/sysdeps/cycles.h
+++ b/config/sysdeps/cycles.h
@@ -2,12 +2,12 @@
#define _jack_sysdep_cycles_h_
#if defined(__i386__)
-
+
/* technically, i386 doesn't have a cycle counter, but
running JACK on a real i386 seems like a ridiculuous
target and gcc defines this for the entire x86 family
including the [456]86 that do have the counter.
-*/
+ */
#include <config/cpu/i386/cycles.h>
@@ -23,6 +23,6 @@
#include <config/cpu/generic/cycles.h>
-#endif /* processor selection */
+#endif /* processor selection */
-#endif /* _jack_sysdep_cycles_h_ */
+#endif /* _jack_sysdep_cycles_h_ */
diff --git a/drivers/alsa/alsa_driver.c b/drivers/alsa/alsa_driver.c
index c7dd724..2f42e31 100644
--- a/drivers/alsa/alsa_driver.c
+++ b/drivers/alsa/alsa_driver.c
@@ -16,7 +16,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
+ */
#include <math.h>
#include <stdio.h>
@@ -44,10 +44,10 @@
#include "usx2y.h"
#include "generic.h"
-extern void store_work_time (int);
-extern void store_wait_time (int);
-extern void show_wait_times ();
-extern void show_work_times ();
+extern void store_work_time(int);
+extern void store_wait_time(int);
+extern void show_wait_times();
+extern void show_work_times();
#undef DEBUG_WAKEUP
@@ -98,34 +98,34 @@ alsa_driver_check_capabilities (alsa_driver_t *driver)
}
static char*
-get_control_device_name(const char * device_name)
+get_control_device_name (const char * device_name)
{
- char * ctl_name;
- const char * comma;
-
- /* the user wants a hw or plughw device, the ctl name
- * should be hw:x where x is the card identification.
- * We skip the subdevice suffix that starts with comma */
-
- if (strncasecmp(device_name, "plughw:", 7) == 0) {
- /* skip the "plug" prefix" */
- device_name += 4;
- }
-
- comma = strchr(device_name, ',');
- if (comma == NULL) {
- ctl_name = strdup(device_name);
- if (ctl_name == NULL) {
- jack_error("strdup(\"%s\") failed.", device_name);
- }
- } else {
- ctl_name = strndup(device_name, comma - device_name);
- if (ctl_name == NULL) {
- jack_error("strndup(\"%s\", %u) failed.", device_name, (unsigned int)(comma - device_name));
- }
- }
-
- return ctl_name;
+ char * ctl_name;
+ const char * comma;
+
+ /* the user wants a hw or plughw device, the ctl name
+ * should be hw:x where x is the card identification.
+ * We skip the subdevice suffix that starts with comma */
+
+ if (strncasecmp (device_name, "plughw:", 7) == 0) {
+ /* skip the "plug" prefix" */
+ device_name += 4;
+ }
+
+ comma = strchr (device_name, ',');
+ if (comma == NULL) {
+ ctl_name = strdup (device_name);
+ if (ctl_name == NULL) {
+ jack_error ("strdup(\"%s\") failed.", device_name);
+ }
+ } else {
+ ctl_name = strndup (device_name, comma - device_name);
+ if (ctl_name == NULL) {
+ jack_error ("strndup(\"%s\", %u) failed.", device_name, (unsigned int)(comma - device_name));
+ }
+ }
+
+ return ctl_name;
}
static int
@@ -137,22 +137,22 @@ alsa_driver_check_card_type (alsa_driver_t *driver)
snd_ctl_card_info_alloca (&card_info);
- ctl_name = get_control_device_name(driver->alsa_name_playback);
+ ctl_name = get_control_device_name (driver->alsa_name_playback);
// XXX: I don't know the "right" way to do this. Which to use
// driver->alsa_name_playback or driver->alsa_name_capture.
if ((err = snd_ctl_open (&driver->ctl_handle, ctl_name, 0)) < 0) {
jack_error ("control open \"%s\" (%s)", ctl_name,
- snd_strerror(err));
- } else if ((err = snd_ctl_card_info(driver->ctl_handle, card_info)) < 0) {
+ snd_strerror (err));
+ } else if ((err = snd_ctl_card_info (driver->ctl_handle, card_info)) < 0) {
jack_error ("control hardware info \"%s\" (%s)",
driver->alsa_name_playback, snd_strerror (err));
snd_ctl_close (driver->ctl_handle);
}
- driver->alsa_driver = strdup(snd_ctl_card_info_get_driver (card_info));
+ driver->alsa_driver = strdup (snd_ctl_card_info_get_driver (card_info));
- free(ctl_name);
+ free (ctl_name);
return alsa_driver_check_capabilities (driver);
}
@@ -174,8 +174,8 @@ alsa_driver_hdsp_hardware (alsa_driver_t *driver)
static int
alsa_driver_ice1712_hardware (alsa_driver_t *driver)
{
- driver->hw = jack_alsa_ice1712_hw_new (driver);
- return 0;
+ driver->hw = jack_alsa_ice1712_hw_new (driver);
+ return 0;
}
static int
@@ -198,24 +198,24 @@ alsa_driver_hw_specific (alsa_driver_t *driver, int hw_monitoring,
{
int err;
- if (!strcmp(driver->alsa_driver, "RME9652")) {
+ if (!strcmp (driver->alsa_driver, "RME9652")) {
if ((err = alsa_driver_hammerfall_hardware (driver)) != 0) {
return err;
}
- } else if (!strcmp(driver->alsa_driver, "H-DSP")) {
- if ((err = alsa_driver_hdsp_hardware (driver)) !=0) {
- return err;
- }
- } else if (!strcmp(driver->alsa_driver, "ICE1712")) {
- if ((err = alsa_driver_ice1712_hardware (driver)) !=0) {
- return err;
- }
- } else if (!strcmp(driver->alsa_driver, "USB US-X2Y")) {
- if ((err = alsa_driver_usx2y_hardware (driver)) !=0) {
- return err;
+ } else if (!strcmp (driver->alsa_driver, "H-DSP")) {
+ if ((err = alsa_driver_hdsp_hardware (driver)) != 0) {
+ return err;
+ }
+ } else if (!strcmp (driver->alsa_driver, "ICE1712")) {
+ if ((err = alsa_driver_ice1712_hardware (driver)) != 0) {
+ return err;
+ }
+ } else if (!strcmp (driver->alsa_driver, "USB US-X2Y")) {
+ if ((err = alsa_driver_usx2y_hardware (driver)) != 0) {
+ return err;
}
} else {
- if ((err = alsa_driver_generic_hardware (driver)) != 0) {
+ if ((err = alsa_driver_generic_hardware (driver)) != 0) {
return err;
}
}
@@ -258,50 +258,50 @@ alsa_driver_setup_io_function_pointers (alsa_driver_t *driver)
case 2:
switch (driver->dither) {
case Rectangular:
- jack_info("Rectangular dithering at 16 bits");
- driver->write_via_copy = driver->quirk_bswap?
- sample_move_dither_rect_d16_sSs:
- sample_move_dither_rect_d16_sS;
+ jack_info ("Rectangular dithering at 16 bits");
+ driver->write_via_copy = driver->quirk_bswap ?
+ sample_move_dither_rect_d16_sSs :
+ sample_move_dither_rect_d16_sS;
break;
case Triangular:
- jack_info("Triangular dithering at 16 bits");
- driver->write_via_copy = driver->quirk_bswap?
- sample_move_dither_tri_d16_sSs:
- sample_move_dither_tri_d16_sS;
+ jack_info ("Triangular dithering at 16 bits");
+ driver->write_via_copy = driver->quirk_bswap ?
+ sample_move_dither_tri_d16_sSs :
+ sample_move_dither_tri_d16_sS;
break;
case Shaped:
- jack_info("Noise-shaped dithering at 16 bits");
- driver->write_via_copy = driver->quirk_bswap?
- sample_move_dither_shaped_d16_sSs:
- sample_move_dither_shaped_d16_sS;
+ jack_info ("Noise-shaped dithering at 16 bits");
+ driver->write_via_copy = driver->quirk_bswap ?
+ sample_move_dither_shaped_d16_sSs :
+ sample_move_dither_shaped_d16_sS;
break;
default:
- driver->write_via_copy = driver->quirk_bswap?
- sample_move_d16_sSs :
- sample_move_d16_sS;
+ driver->write_via_copy = driver->quirk_bswap ?
+ sample_move_d16_sSs :
+ sample_move_d16_sS;
break;
}
break;
case 3: /* NO DITHER */
- driver->write_via_copy = driver->quirk_bswap?
- sample_move_d24_sSs:
- sample_move_d24_sS;
+ driver->write_via_copy = driver->quirk_bswap ?
+ sample_move_d24_sSs :
+ sample_move_d24_sS;
break;
case 4: /* NO DITHER */
- driver->write_via_copy = driver->quirk_bswap?
- sample_move_d32u24_sSs:
- sample_move_d32u24_sS;
+ driver->write_via_copy = driver->quirk_bswap ?
+ sample_move_d32u24_sSs :
+ sample_move_d32u24_sS;
break;
default:
jack_error ("impossible sample width (%d) discovered!",
- driver->playback_sample_bytes);
+ driver->playback_sample_bytes);
exit (1);
}
}
@@ -313,19 +313,19 @@ alsa_driver_setup_io_function_pointers (alsa_driver_t *driver)
} else {
switch (driver->capture_sample_bytes) {
case 2:
- driver->read_via_copy = driver->quirk_bswap?
- sample_move_dS_s16s:
- sample_move_dS_s16;
+ driver->read_via_copy = driver->quirk_bswap ?
+ sample_move_dS_s16s :
+ sample_move_dS_s16;
break;
case 3:
- driver->read_via_copy = driver->quirk_bswap?
- sample_move_dS_s24s:
- sample_move_dS_s24;
+ driver->read_via_copy = driver->quirk_bswap ?
+ sample_move_dS_s24s :
+ sample_move_dS_s24;
break;
case 4:
- driver->read_via_copy = driver->quirk_bswap?
- sample_move_dS_s32u24s:
- sample_move_dS_s32u24;
+ driver->read_via_copy = driver->quirk_bswap ?
+ sample_move_dS_s32u24s :
+ sample_move_dS_s32u24;
break;
}
}
@@ -345,24 +345,25 @@ alsa_driver_configure_stream (alsa_driver_t *driver, char *device_name,
int err, format;
unsigned int frame_rate;
snd_pcm_uframes_t stop_th;
+
static struct {
char Name[40];
snd_pcm_format_t format;
int swapped;
} formats[] = {
- {"32bit float little-endian", SND_PCM_FORMAT_FLOAT_LE, IS_LE},
- {"32bit integer little-endian", SND_PCM_FORMAT_S32_LE, IS_LE},
- {"32bit integer big-endian", SND_PCM_FORMAT_S32_BE, IS_BE},
- {"24bit little-endian in 3bytes format", SND_PCM_FORMAT_S24_3LE, IS_LE},
- {"24bit big-endian in 3bytes format", SND_PCM_FORMAT_S24_3BE, IS_BE},
- {"24bit little-endian", SND_PCM_FORMAT_S24_LE, IS_LE},
- {"24bit big-endian", SND_PCM_FORMAT_S24_BE, IS_BE},
- {"16bit little-endian", SND_PCM_FORMAT_S16_LE, IS_LE},
- {"16bit big-endian", SND_PCM_FORMAT_S16_BE, IS_BE},
+ { "32bit float little-endian", SND_PCM_FORMAT_FLOAT_LE, IS_LE },
+ { "32bit integer little-endian", SND_PCM_FORMAT_S32_LE, IS_LE },
+ { "32bit integer big-endian", SND_PCM_FORMAT_S32_BE, IS_BE },
+ { "24bit little-endian in 3bytes format", SND_PCM_FORMAT_S24_3LE, IS_LE },
+ { "24bit big-endian in 3bytes format", SND_PCM_FORMAT_S24_3BE, IS_BE },
+ { "24bit little-endian", SND_PCM_FORMAT_S24_LE, IS_LE },
+ { "24bit big-endian", SND_PCM_FORMAT_S24_BE, IS_BE },
+ { "16bit little-endian", SND_PCM_FORMAT_S16_LE, IS_LE },
+ { "16bit big-endian", SND_PCM_FORMAT_S16_BE, IS_BE },
};
-#define NUMFORMATS (sizeof(formats)/sizeof(formats[0]))
+#define NUMFORMATS (sizeof(formats) / sizeof(formats[0]))
- if ((err = snd_pcm_hw_params_any (handle, hw_params)) < 0) {
+ if ((err = snd_pcm_hw_params_any (handle, hw_params)) < 0) {
jack_error ("ALSA: no playback configurations available (%s)",
snd_strerror (err));
return -1;
@@ -416,10 +417,10 @@ alsa_driver_configure_stream (alsa_driver_t *driver, char *device_name,
}
}
- frame_rate = driver->frame_rate ;
+ frame_rate = driver->frame_rate;
err = snd_pcm_hw_params_set_rate_near (handle, hw_params,
- &frame_rate, NULL) ;
- driver->frame_rate = frame_rate ;
+ &frame_rate, NULL);
+ driver->frame_rate = frame_rate;
if (err < 0) {
jack_error ("ALSA: cannot set sample/frame rate to %"
PRIu32 " for %s", driver->frame_rate,
@@ -429,10 +430,10 @@ alsa_driver_configure_stream (alsa_driver_t *driver, char *device_name,
if (!*nchns) {
/*if not user-specified, try to find the maximum
* number of channels */
- unsigned int channels_max ;
+ unsigned int channels_max;
err = snd_pcm_hw_params_get_channels_max (hw_params,
&channels_max);
- *nchns = channels_max ;
+ *nchns = channels_max;
if (*nchns > 1024) {
@@ -442,14 +443,14 @@ alsa_driver_configure_stream (alsa_driver_t *driver, char *device_name,
they can't be bothered to set up a proper
default device, limit the number of
channels for them to a sane default.
- */
+ */
jack_error (
-"You appear to be using the ALSA software \"plug\" layer, probably\n"
-"a result of using the \"default\" ALSA device. This is less\n"
-"efficient than it could be. Consider using a hardware device\n"
-"instead rather than using the plug layer. Usually the name of the\n"
-"hardware device that corresponds to the first sound card is hw:0\n"
+ "You appear to be using the ALSA software \"plug\" layer, probably\n"
+ "a result of using the \"default\" ALSA device. This is less\n"
+ "efficient than it could be. Consider using a hardware device\n"
+ "instead rather than using the plug layer. Usually the name of the\n"
+ "hardware device that corresponds to the first sound card is hw:0\n"
);
*nchns = 2;
}
@@ -474,8 +475,9 @@ alsa_driver_configure_stream (alsa_driver_t *driver, char *device_name,
*nperiodsp = driver->user_nperiods;
snd_pcm_hw_params_set_periods_min (handle, hw_params, nperiodsp, NULL);
- if (*nperiodsp < driver->user_nperiods)
+ if (*nperiodsp < driver->user_nperiods) {
*nperiodsp = driver->user_nperiods;
+ }
if (snd_pcm_hw_params_set_periods_near (handle, hw_params,
nperiodsp, NULL) < 0) {
jack_error ("ALSA: cannot set number of periods to %u for %s",
@@ -485,15 +487,15 @@ alsa_driver_configure_stream (alsa_driver_t *driver, char *device_name,
if (*nperiodsp < driver->user_nperiods) {
jack_error ("ALSA: got smaller periods %u than %u for %s",
- *nperiodsp, (unsigned int) driver->user_nperiods,
+ *nperiodsp, (unsigned int)driver->user_nperiods,
stream_name);
return -1;
}
jack_info ("ALSA: use %d periods for %s", *nperiodsp, stream_name);
#if 0
- if (!jack_power_of_two(driver->frames_per_cycle)) {
- jack_error("JACK: frames must be a power of two "
- "(64, 512, 1024, ...)\n");
+ if (!jack_power_of_two (driver->frames_per_cycle)) {
+ jack_error ("JACK: frames must be a power of two "
+ "(64, 512, 1024, ...)\n");
return -1;
}
#endif
@@ -544,8 +546,8 @@ alsa_driver_configure_stream (alsa_driver_t *driver, char *device_name,
#if 0
jack_info ("set silence size to %lu * %lu = %lu",
- driver->frames_per_cycle, *nperiodsp,
- driver->frames_per_cycle * *nperiodsp);
+ driver->frames_per_cycle, *nperiodsp,
+ driver->frames_per_cycle * *nperiodsp);
if ((err = snd_pcm_sw_params_set_silence_size (
handle, sw_params,
@@ -556,14 +558,15 @@ alsa_driver_configure_stream (alsa_driver_t *driver, char *device_name,
}
#endif
- if (handle == driver->playback_handle)
+ if (handle == driver->playback_handle) {
err = snd_pcm_sw_params_set_avail_min (
handle, sw_params,
driver->frames_per_cycle
* (*nperiodsp - driver->user_nperiods + 1));
- else
+ } else {
err = snd_pcm_sw_params_set_avail_min (
handle, sw_params, driver->frames_per_cycle);
+ }
if (err < 0) {
jack_error ("ALSA: cannot set avail min for %s", stream_name);
@@ -601,8 +604,8 @@ alsa_driver_set_parameters (alsa_driver_t *driver,
driver->user_nperiods = user_nperiods;
jack_info ("configuring for %" PRIu32 "Hz, period = %"
- PRIu32 " frames (%.1f ms), buffer = %" PRIu32 " periods",
- rate, frames_per_cycle, (((float)frames_per_cycle / (float) rate) * 1000.0f), user_nperiods);
+ PRIu32 " frames (%.1f ms), buffer = %" PRIu32 " periods",
+ rate, frames_per_cycle, (((float)frames_per_cycle / (float)rate) * 1000.0f), user_nperiods);
if (driver->capture_handle) {
if (alsa_driver_configure_stream (
@@ -666,14 +669,12 @@ alsa_driver_set_parameters (alsa_driver_t *driver,
driver->frame_rate = cr;
}
- }
- else if (driver->capture_handle && cr != driver->frame_rate) {
+ } else if (driver->capture_handle && cr != driver->frame_rate) {
jack_error ("capture sample rate in use (%d Hz) does not "
"match requested rate (%d Hz)",
cr, driver->frame_rate);
driver->frame_rate = cr;
- }
- else if (driver->playback_handle && pr != driver->frame_rate) {
+ } else if (driver->playback_handle && pr != driver->frame_rate) {
jack_error ("playback sample rate in use (%d Hz) does not "
"match requested rate (%d Hz)",
pr, driver->frame_rate);
@@ -684,28 +685,31 @@ alsa_driver_set_parameters (alsa_driver_t *driver,
/* check the fragment size, since thats non-negotiable */
if (driver->playback_handle) {
- snd_pcm_access_t access;
+ snd_pcm_access_t access;
- err = snd_pcm_hw_params_get_period_size (
- driver->playback_hw_params, &p_period_size, &dir);
- if (err != 0)
+ err = snd_pcm_hw_params_get_period_size (
+ driver->playback_hw_params, &p_period_size, &dir);
+ if (err != 0) {
jack_error ("snd_pcm_hw_params_get_period_size (playback) : %s",
- snd_strerror (err));
+ snd_strerror (err));
+ }
- err = snd_pcm_hw_params_get_format (
- driver->playback_hw_params,
+ err = snd_pcm_hw_params_get_format (
+ driver->playback_hw_params,
&(driver->playback_sample_format));
- if (err != 0)
+ if (err != 0) {
jack_error ("snd_pcm_hw_params_get_format (playback) : %s",
- snd_strerror (err));
+ snd_strerror (err));
+ }
- err = snd_pcm_hw_params_get_access (driver->playback_hw_params,
+ err = snd_pcm_hw_params_get_access (driver->playback_hw_params,
&access);
- if (err != 0)
+ if (err != 0) {
jack_error ("snd_pcm_hw_params_get_access (playback) : %s",
- snd_strerror (err));
+ snd_strerror (err));
+ }
- driver->playback_interleaved =
+ driver->playback_interleaved =
(access == SND_PCM_ACCESS_MMAP_INTERLEAVED)
|| (access == SND_PCM_ACCESS_MMAP_COMPLEX);
@@ -719,28 +723,31 @@ alsa_driver_set_parameters (alsa_driver_t *driver,
}
if (driver->capture_handle) {
- snd_pcm_access_t access;
+ snd_pcm_access_t access;
- err = snd_pcm_hw_params_get_period_size (
- driver->capture_hw_params, &c_period_size, &dir);
- if (err != 0)
+ err = snd_pcm_hw_params_get_period_size (
+ driver->capture_hw_params, &c_period_size, &dir);
+ if (err != 0) {
jack_error ("snd_pcm_hw_params_get_period_size (capture): %s",
- snd_strerror (err));
+ snd_strerror (err));
+ }
- err = snd_pcm_hw_params_get_format (
- driver->capture_hw_params,
+ err = snd_pcm_hw_params_get_format (
+ driver->capture_hw_params,
&(driver->capture_sample_format));
- if (err != 0)
+ if (err != 0) {
jack_error ("snd_pcm_hw_params_get_format (capture) : %s",
- snd_strerror (err));
+ snd_strerror (err));
+ }
- err = snd_pcm_hw_params_get_access (driver->capture_hw_params,
+ err = snd_pcm_hw_params_get_access (driver->capture_hw_params,
&access);
- if (err != 0)
+ if (err != 0) {
jack_error ("snd_pcm_hw_params_get_access (capture) : %s",
- snd_strerror (err));
+ snd_strerror (err));
+ }
- driver->capture_interleaved =
+ driver->capture_interleaved =
(access == SND_PCM_ACCESS_MMAP_INTERLEAVED)
|| (access == SND_PCM_ACCESS_MMAP_COMPLEX);
@@ -749,7 +756,7 @@ alsa_driver_set_parameters (alsa_driver_t *driver,
PRIu32
" frames but got %uc frames for capture",
driver->frames_per_cycle, p_period_size);
- goto errout;
+ goto errout;
}
}
@@ -762,7 +769,7 @@ alsa_driver_set_parameters (alsa_driver_t *driver,
if (driver->playback_handle) {
switch (driver->playback_sample_format) {
- case SND_PCM_FORMAT_FLOAT_LE:
+ case SND_PCM_FORMAT_FLOAT_LE:
case SND_PCM_FORMAT_S32_LE:
case SND_PCM_FORMAT_S24_3LE:
case SND_PCM_FORMAT_S24_3BE:
@@ -782,7 +789,7 @@ alsa_driver_set_parameters (alsa_driver_t *driver,
if (driver->capture_handle) {
switch (driver->capture_sample_format) {
- case SND_PCM_FORMAT_FLOAT_LE:
+ case SND_PCM_FORMAT_FLOAT_LE:
case SND_PCM_FORMAT_S32_LE:
case SND_PCM_FORMAT_S24_3LE:
case SND_PCM_FORMAT_S24_3BE:
@@ -803,8 +810,8 @@ alsa_driver_set_parameters (alsa_driver_t *driver,
if (driver->playback_interleaved) {
const snd_pcm_channel_area_t *my_areas;
snd_pcm_uframes_t offset, frames;
- if (snd_pcm_mmap_begin(driver->playback_handle,
- &my_areas, &offset, &frames) < 0) {
+ if (snd_pcm_mmap_begin (driver->playback_handle,
+ &my_areas, &offset, &frames) < 0) {
jack_error ("ALSA: %s: mmap areas info error",
driver->alsa_name_playback);
goto errout;
@@ -819,8 +826,8 @@ alsa_driver_set_parameters (alsa_driver_t *driver,
if (driver->capture_interleaved) {
const snd_pcm_channel_area_t *my_areas;
snd_pcm_uframes_t offset, frames;
- if (snd_pcm_mmap_begin(driver->capture_handle,
- &my_areas, &offset, &frames) < 0) {
+ if (snd_pcm_mmap_begin (driver->capture_handle,
+ &my_areas, &offset, &frames) < 0) {
jack_error ("ALSA: %s: mmap areas info error",
driver->alsa_name_capture);
goto errout;
@@ -844,55 +851,53 @@ alsa_driver_set_parameters (alsa_driver_t *driver,
channels require action on every cycle. any bits that are
not set after the engine's process() call indicate channels
that potentially need to be silenced.
- */
+ */
bitset_create (&driver->channels_done, driver->max_nchannels);
bitset_create (&driver->channels_not_done, driver->max_nchannels);
if (driver->playback_handle) {
- driver->playback_addr = (char **)
- malloc (sizeof (char *) * driver->playback_nchannels);
+ driver->playback_addr = (char**)
+ malloc (sizeof(char *) * driver->playback_nchannels);
memset (driver->playback_addr, 0,
- sizeof (char *) * driver->playback_nchannels);
- driver->playback_interleave_skip = (unsigned long *)
- malloc (sizeof (unsigned long *) * driver->playback_nchannels);
+ sizeof(char *) * driver->playback_nchannels);
+ driver->playback_interleave_skip = (unsigned long*)
+ malloc (sizeof(unsigned long *) * driver->playback_nchannels);
memset (driver->playback_interleave_skip, 0,
- sizeof (unsigned long *) * driver->playback_nchannels);
- driver->silent = (unsigned long *)
- malloc (sizeof (unsigned long)
- * driver->playback_nchannels);
+ sizeof(unsigned long *) * driver->playback_nchannels);
+ driver->silent = (unsigned long*)
+ malloc (sizeof(unsigned long)
+ * driver->playback_nchannels);
- for (chn = 0; chn < driver->playback_nchannels; chn++) {
+ for (chn = 0; chn < driver->playback_nchannels; chn++)
driver->silent[chn] = 0;
- }
- for (chn = 0; chn < driver->playback_nchannels; chn++) {
+ for (chn = 0; chn < driver->playback_nchannels; chn++)
bitset_add (driver->channels_done, chn);
- }
- driver->dither_state = (dither_state_t *)
- calloc ( driver->playback_nchannels,
- sizeof (dither_state_t));
+ driver->dither_state = (dither_state_t*)
+ calloc ( driver->playback_nchannels,
+ sizeof(dither_state_t));
}
if (driver->capture_handle) {
- driver->capture_addr = (char **)
- malloc (sizeof (char *) * driver->capture_nchannels);
+ driver->capture_addr = (char**)
+ malloc (sizeof(char *) * driver->capture_nchannels);
memset (driver->capture_addr, 0,
- sizeof (char *) * driver->capture_nchannels);
- driver->capture_interleave_skip = (unsigned long *)
- malloc (sizeof (unsigned long *) * driver->capture_nchannels);
+ sizeof(char *) * driver->capture_nchannels);
+ driver->capture_interleave_skip = (unsigned long*)
+ malloc (sizeof(unsigned long *) * driver->capture_nchannels);
memset (driver->capture_interleave_skip, 0,
- sizeof (unsigned long *) * driver->capture_nchannels);
+ sizeof(unsigned long *) * driver->capture_nchannels);
}
- driver->clock_sync_data = (ClockSyncStatus *)
- malloc (sizeof (ClockSyncStatus) * driver->max_nchannels);
+ driver->clock_sync_data = (ClockSyncStatus*)
+ malloc (sizeof(ClockSyncStatus) * driver->max_nchannels);
driver->period_usecs =
- (jack_time_t) floor ((((float) driver->frames_per_cycle) /
- driver->frame_rate) * 1000000.0f);
- driver->poll_timeout = (int) floor (1.5f * driver->period_usecs);
+ (jack_time_t)floor ((((float)driver->frames_per_cycle) /
+ driver->frame_rate) * 1000000.0f);
+ driver->poll_timeout = (int)floor (1.5f * driver->period_usecs);
if (driver->engine) {
if (driver->engine->set_buffer_size (driver->engine,
@@ -902,19 +907,19 @@ alsa_driver_set_parameters (alsa_driver_t *driver,
}
}
- driver->previously_successfully_configured = TRUE;
+ driver->previously_successfully_configured = TRUE;
return 0;
- errout:
- if (driver->previously_successfully_configured) {
- /* attempt to restore previous configuration */
- jack_info ("ALSA: falling back to old configuration");
- if (alsa_driver_set_parameters (driver, old_frames_per_cycle, old_user_nperiods, old_rate) == 0) {
- jack_error ("ALSA: reverted to previous parameters after failure");
- return 0;
- }
- }
- return -1;
+errout:
+ if (driver->previously_successfully_configured) {
+ /* attempt to restore previous configuration */
+ jack_info ("ALSA: falling back to old configuration");
+ if (alsa_driver_set_parameters (driver, old_frames_per_cycle, old_user_nperiods, old_rate) == 0) {
+ jack_error ("ALSA: reverted to previous parameters after failure");
+ return 0;
+ }
+ }
+ return -1;
}
static int
@@ -943,8 +948,8 @@ alsa_driver_get_channel_addresses (alsa_driver_t *driver,
if (capture_avail) {
if ((err = snd_pcm_mmap_begin (
driver->capture_handle, &driver->capture_areas,
- (snd_pcm_uframes_t *) capture_offset,
- (snd_pcm_uframes_t *) capture_avail)) < 0) {
+ (snd_pcm_uframes_t*)capture_offset,
+ (snd_pcm_uframes_t*)capture_avail)) < 0) {
jack_error ("ALSA: %s: mmap areas info error",
driver->alsa_name_capture);
return -1;
@@ -953,17 +958,17 @@ alsa_driver_get_channel_addresses (alsa_driver_t *driver,
for (chn = 0; chn < driver->capture_nchannels; chn++) {
const snd_pcm_channel_area_t *a =
&driver->capture_areas[chn];
- driver->capture_addr[chn] = (char *) a->addr
- + ((a->first + a->step * *capture_offset) / 8);
- driver->capture_interleave_skip[chn] = (unsigned long ) (a->step / 8);
+ driver->capture_addr[chn] = (char*)a->addr
+ + ((a->first + a->step * *capture_offset) / 8);
+ driver->capture_interleave_skip[chn] = (unsigned long )(a->step / 8);
}
}
if (playback_avail) {
if ((err = snd_pcm_mmap_begin (
driver->playback_handle, &driver->playback_areas,
- (snd_pcm_uframes_t *) playback_offset,
- (snd_pcm_uframes_t *) playback_avail)) < 0) {
+ (snd_pcm_uframes_t*)playback_offset,
+ (snd_pcm_uframes_t*)playback_avail)) < 0) {
jack_error ("ALSA: %s: mmap areas info error ",
driver->alsa_name_playback);
return -1;
@@ -972,9 +977,9 @@ alsa_driver_get_channel_addresses (alsa_driver_t *driver,
for (chn = 0; chn < driver->playback_nchannels; chn++) {
const snd_pcm_channel_area_t *a =
&driver->playback_areas[chn];
- driver->playback_addr[chn] = (char *) a->addr
- + ((a->first + a->step * *playback_offset) / 8);
- driver->playback_interleave_skip[chn] = (unsigned long ) (a->step / 8);
+ driver->playback_addr[chn] = (char*)a->addr
+ + ((a->first + a->step * *playback_offset) / 8);
+ driver->playback_interleave_skip[chn] = (unsigned long )(a->step / 8);
}
}
@@ -995,7 +1000,7 @@ alsa_driver_start (alsa_driver_t *driver)
if ((err = snd_pcm_prepare (driver->playback_handle)) < 0) {
jack_error ("ALSA: prepare error for playback on "
"\"%s\" (%s)", driver->alsa_name_playback,
- snd_strerror(err));
+ snd_strerror (err));
return -1;
}
}
@@ -1005,7 +1010,7 @@ alsa_driver_start (alsa_driver_t *driver)
if ((err = snd_pcm_prepare (driver->capture_handle)) < 0) {
jack_error ("ALSA: prepare error for capture on \"%s\""
" (%s)", driver->alsa_name_capture,
- snd_strerror(err));
+ snd_strerror (err));
return -1;
}
}
@@ -1042,14 +1047,14 @@ alsa_driver_start (alsa_driver_t *driver)
free (driver->pfd);
}
- driver->pfd = (struct pollfd *)
- malloc (sizeof (struct pollfd) *
- (driver->playback_nfds + driver->capture_nfds + 2));
+ driver->pfd = (struct pollfd*)
+ malloc (sizeof(struct pollfd) *
+ (driver->playback_nfds + driver->capture_nfds + 2));
if (driver->playback_handle) {
/* fill playback buffer with zeroes, and mark
all fragments as having data.
- */
+ */
pavail = snd_pcm_avail_update (driver->playback_handle);
@@ -1060,7 +1065,7 @@ alsa_driver_start (alsa_driver_t *driver)
}
if (alsa_driver_get_channel_addresses (driver,
- 0, &pavail, 0, &poffset)) {
+ 0, &pavail, 0, &poffset)) {
return -1;
}
@@ -1071,7 +1076,7 @@ alsa_driver_start (alsa_driver_t *driver)
alsa-lib may have a better function for doing this
here, where the goal is to silence the entire
buffer.
- */
+ */
for (chn = 0; chn < driver->playback_nchannels; chn++) {
alsa_driver_silence_on_channel (
@@ -1112,7 +1117,7 @@ alsa_driver_stop (alsa_driver_t *driver)
/* silence all capture port buffers, because we might
be entering offline mode.
- */
+ */
for (chn = 0, node = driver->capture_ports; node;
node = jack_slist_next (node), chn++) {
@@ -1121,9 +1126,9 @@ alsa_driver_stop (alsa_driver_t *driver)
char* buf;
jack_nframes_t nframes = driver->engine->control->buffer_size;
- port = (jack_port_t *) node->data;
+ port = (jack_port_t*)node->data;
buf = jack_port_get_buffer (port, nframes);
- memset (buf, 0, sizeof (jack_default_audio_sample_t) * nframes);
+ memset (buf, 0, sizeof(jack_default_audio_sample_t) * nframes);
}
if (driver->playback_handle) {
@@ -1159,8 +1164,9 @@ alsa_driver_restart (alsa_driver_t *driver)
int res;
driver->xrun_recovery = 1;
- if ((res = driver->nt_stop((struct _jack_driver_nt *) driver))==0)
- res = driver->nt_start((struct _jack_driver_nt *) driver);
+ if ((res = driver->nt_stop ((struct _jack_driver_nt*)driver)) == 0) {
+ res = driver->nt_start ((struct _jack_driver_nt*)driver);
+ }
driver->xrun_recovery = 0;
return res;
@@ -1172,47 +1178,46 @@ alsa_driver_xrun_recovery (alsa_driver_t *driver, float *delayed_usecs)
snd_pcm_status_t *status;
int res;
- snd_pcm_status_alloca(&status);
+ snd_pcm_status_alloca (&status);
if (driver->capture_handle) {
- if ((res = snd_pcm_status(driver->capture_handle, status))
+ if ((res = snd_pcm_status (driver->capture_handle, status))
< 0) {
- jack_error("status error: %s", snd_strerror(res));
+ jack_error ("status error: %s", snd_strerror (res));
}
} else {
- if ((res = snd_pcm_status(driver->playback_handle, status))
+ if ((res = snd_pcm_status (driver->playback_handle, status))
< 0) {
- jack_error("status error: %s", snd_strerror(res));
+ jack_error ("status error: %s", snd_strerror (res));
}
}
- if (snd_pcm_status_get_state(status) == SND_PCM_STATE_SUSPENDED)
- {
- MESSAGE("\n\n**** alsa_pcm: pcm in suspended state, resuming it \n\n" );
+ if (snd_pcm_status_get_state (status) == SND_PCM_STATE_SUSPENDED) {
+ MESSAGE ("\n\n**** alsa_pcm: pcm in suspended state, resuming it \n\n" );
if (driver->capture_handle) {
- if ((res = snd_pcm_prepare(driver->capture_handle))
+ if ((res = snd_pcm_prepare (driver->capture_handle))
< 0) {
- jack_error("error preparing after suspend: %s", snd_strerror(res));
+ jack_error ("error preparing after suspend: %s", snd_strerror (res));
}
} else {
- if ((res = snd_pcm_prepare(driver->playback_handle))
+ if ((res = snd_pcm_prepare (driver->playback_handle))
< 0) {
- jack_error("error preparing after suspend: %s", snd_strerror(res));
+ jack_error ("error preparing after suspend: %s", snd_strerror (res));
}
}
}
- if (snd_pcm_status_get_state(status) == SND_PCM_STATE_XRUN
+ if (snd_pcm_status_get_state (status) == SND_PCM_STATE_XRUN
&& driver->process_count > XRUN_REPORT_DELAY) {
struct timeval now, diff, tstamp;
driver->xrun_count++;
- snd_pcm_status_get_tstamp(status,&now);
- snd_pcm_status_get_trigger_tstamp(status, &tstamp);
- timersub(&now, &tstamp, &diff);
+ snd_pcm_status_get_tstamp (status, &now);
+ snd_pcm_status_get_trigger_tstamp (status, &tstamp);
+ timersub (&now, &tstamp, &diff);
*delayed_usecs = diff.tv_sec * 1000000.0 + diff.tv_usec;
- MESSAGE("\n\n**** alsa_pcm: xrun of at least %.3f "
- "msecs\n\n",
- *delayed_usecs / 1000.0);
+ MESSAGE ("\n\n**** alsa_pcm: xrun of at least %.3f "
+ "msecs\n\n",
+ *delayed_usecs / 1000.0);
}
if (alsa_driver_restart (driver)) {
@@ -1275,7 +1280,7 @@ alsa_driver_wait (alsa_driver_t *driver, int extra_fd, int *status, float
need_playback = driver->playback_handle ? 1 : 0;
}
- again:
+again:
while (need_playback || need_capture) {
@@ -1303,14 +1308,13 @@ alsa_driver_wait (alsa_driver_t *driver, int extra_fd, int *status, float
/* ALSA doesn't set POLLERR in some versions of 0.9.X */
- for (i = 0; i < nfds; i++) {
+ for (i = 0; i < nfds; i++)
driver->pfd[i].events |= POLLERR;
- }
if (extra_fd >= 0) {
driver->pfd[nfds].fd = extra_fd;
driver->pfd[nfds].events =
- POLLIN|POLLERR|POLLHUP|POLLNVAL;
+ POLLIN | POLLERR | POLLHUP | POLLNVAL;
nfds++;
}
@@ -1370,7 +1374,7 @@ alsa_driver_wait (alsa_driver_t *driver, int extra_fd, int *status, float
if (extra_fd >= 0) {
- if (driver->pfd[nfds-1].revents == 0) {
+ if (driver->pfd[nfds - 1].revents == 0) {
/* we timed out on the extra fd */
*status = -4;
@@ -1380,13 +1384,13 @@ alsa_driver_wait (alsa_driver_t *driver, int extra_fd, int *status, float
/* if POLLIN was the only bit set, we're OK */
*status = 0;
- return (driver->pfd[nfds-1].revents == POLLIN) ? 0 : -1;
+ return (driver->pfd[nfds - 1].revents == POLLIN) ? 0 : -1;
}
if (need_playback) {
if (snd_pcm_poll_descriptors_revents
- (driver->playback_handle, &driver->pfd[0],
- driver->playback_nfds, &revents) < 0) {
+ (driver->playback_handle, &driver->pfd[0],
+ driver->playback_nfds, &revents) < 0) {
jack_error ("ALSA: playback revents failed");
*status = -6;
return 0;
@@ -1408,8 +1412,8 @@ alsa_driver_wait (alsa_driver_t *driver, int extra_fd, int *status, float
if (need_capture) {
if (snd_pcm_poll_descriptors_revents
- (driver->capture_handle, &driver->pfd[ci],
- driver->capture_nfds, &revents) < 0) {
+ (driver->capture_handle, &driver->pfd[ci],
+ driver->capture_nfds, &revents) < 0) {
jack_error ("ALSA: capture revents failed");
*status = -6;
return 0;
@@ -1491,7 +1495,7 @@ alsa_driver_wait (alsa_driver_t *driver, int extra_fd, int *status, float
/* constrain the available count to the nearest (round down) number of
periods.
- */
+ */
return avail - (avail % driver->frames_per_cycle);
}
@@ -1508,16 +1512,16 @@ alsa_driver_null_cycle (alsa_driver_t* driver, jack_nframes_t nframes)
return -1;
}
- if (driver->capture_handle) {
+ if (driver->capture_handle) {
nf = nframes;
offset = 0;
while (nf) {
contiguous = nf;
- if (alsa_driver_get_channel_addresses (driver,
- &contiguous, 0, &offset, 0)) {
- return -1;
- }
+ if (alsa_driver_get_channel_addresses (driver,
+ &contiguous, 0, &offset, 0)) {
+ return -1;
+ }
if (snd_pcm_mmap_commit (driver->capture_handle,
offset, contiguous) < 0) {
@@ -1534,15 +1538,14 @@ alsa_driver_null_cycle (alsa_driver_t* driver, jack_nframes_t nframes)
while (nf) {
contiguous = nf;
- if (alsa_driver_get_channel_addresses (driver,
- 0, &contiguous, 0, &offset)) {
- return -1;
- }
+ if (alsa_driver_get_channel_addresses (driver,
+ 0, &contiguous, 0, &offset)) {
+ return -1;
+ }
- for (chn = 0; chn < driver->playback_nchannels; chn++) {
+ for (chn = 0; chn < driver->playback_nchannels; chn++)
alsa_driver_silence_on_channel (driver, chn,
contiguous);
- }
if (snd_pcm_mmap_commit (driver->playback_handle,
offset, contiguous) < 0) {
@@ -1570,7 +1573,7 @@ alsa_driver_read (alsa_driver_t *driver, jack_nframes_t nframes)
snd_pcm_sframes_t contiguous;
snd_pcm_sframes_t nread;
snd_pcm_uframes_t offset;
- jack_nframes_t orig_nframes;
+ jack_nframes_t orig_nframes;
jack_default_audio_sample_t* buf;
channel_t chn;
JSList *node;
@@ -1599,8 +1602,8 @@ alsa_driver_read (alsa_driver_t *driver, jack_nframes_t nframes)
if (alsa_driver_get_channel_addresses (
driver,
- (snd_pcm_uframes_t *) &contiguous,
- (snd_pcm_uframes_t *) 0,
+ (snd_pcm_uframes_t*)&contiguous,
+ (snd_pcm_uframes_t*)0,
&offset, 0) < 0) {
return -1;
}
@@ -1608,7 +1611,7 @@ alsa_driver_read (alsa_driver_t *driver, jack_nframes_t nframes)
for (chn = 0, node = driver->capture_ports; node;
node = jack_slist_next (node), chn++) {
- port = (jack_port_t *) node->data;
+ port = (jack_port_t*)node->data;
if (!jack_port_connected (port)) {
/* no-copy optimization */
@@ -1616,13 +1619,13 @@ alsa_driver_read (alsa_driver_t *driver, jack_nframes_t nframes)
}
buf = jack_port_get_buffer (port, orig_nframes);
alsa_driver_read_from_channel (driver, chn,
- buf + nread, contiguous);
+ buf + nread, contiguous);
}
if ((err = snd_pcm_mmap_commit (driver->capture_handle,
- offset, contiguous)) < 0) {
+ offset, contiguous)) < 0) {
jack_error ("ALSA: could not complete read of %"
- PRIu32 " frames: error = %d", contiguous, err);
+ PRIu32 " frames: error = %d", contiguous, err);
return -1;
}
@@ -1667,8 +1670,8 @@ alsa_driver_write (alsa_driver_t* driver, jack_nframes_t nframes)
for (chn = 0, node = driver->capture_ports; node;
node = jack_slist_next (node), chn++) {
- if (((jack_port_t *) node->data)->shared->monitor_requests) {
- driver->input_monitor_mask |= (1<<chn);
+ if (((jack_port_t*)node->data)->shared->monitor_requests) {
+ driver->input_monitor_mask |= (1 << chn);
}
}
@@ -1687,27 +1690,27 @@ alsa_driver_write (alsa_driver_t* driver, jack_nframes_t nframes)
if (alsa_driver_get_channel_addresses (
driver,
- (snd_pcm_uframes_t *) 0,
- (snd_pcm_uframes_t *) &contiguous,
+ (snd_pcm_uframes_t*)0,
+ (snd_pcm_uframes_t*)&contiguous,
0, &offset) < 0) {
return -1;
}
- for (chn = 0, node = driver->playback_ports, mon_node=driver->monitor_ports;
+ for (chn = 0, node = driver->playback_ports, mon_node = driver->monitor_ports;
node;
node = jack_slist_next (node), chn++) {
- port = (jack_port_t *) node->data;
+ port = (jack_port_t*)node->data;
if (!jack_port_connected (port)) {
continue;
}
buf = jack_port_get_buffer (port, orig_nframes);
alsa_driver_write_to_channel (driver, chn,
- buf + nwritten, contiguous);
+ buf + nwritten, contiguous);
if (mon_node) {
- port = (jack_port_t *) mon_node->data;
+ port = (jack_port_t*)mon_node->data;
if (!jack_port_connected (port)) {
continue;
}
@@ -1724,11 +1727,12 @@ alsa_driver_write (alsa_driver_t* driver, jack_nframes_t nframes)
}
if ((err = snd_pcm_mmap_commit (driver->playback_handle,
- offset, contiguous)) < 0) {
+ offset, contiguous)) < 0) {
jack_error ("ALSA: could not complete playback of %"
- PRIu32 " frames: error = %d", contiguous, err);
- if (err != -EPIPE && err != -ESTRPIPE)
+ PRIu32 " frames: error = %d", contiguous, err);
+ if (err != -EPIPE && err != -ESTRPIPE) {
return -1;
+ }
}
nframes -= contiguous;
@@ -1752,10 +1756,11 @@ alsa_driver_run_cycle (alsa_driver_t *driver)
DEBUG ("alsaback from wait, nframes = %lu", nframes);
- if (unlikely(wait_status < 0))
- return -1; /* driver failed */
+ if (unlikely (wait_status < 0)) {
+ return -1; /* driver failed */
- if (unlikely(nframes == 0)) {
+ }
+ if (unlikely (nframes == 0)) {
/* we detected an xrun and restarted: notify
* clients about the delay.
@@ -1770,20 +1775,19 @@ alsa_driver_run_cycle (alsa_driver_t *driver)
static void
alsa_driver_latency_callback (jack_latency_callback_mode_t mode, void* arg)
{
- alsa_driver_t* driver = (alsa_driver_t*) arg;
- jack_client_t* client = driver->client;
- jack_latency_range_t range;
- JSList* node;
-
- if (mode == JackPlaybackLatency) {
- range.min = range.max = driver->frames_per_cycle + driver->playback_frame_latency;
- } else {
- range.min = range.max = driver->frames_per_cycle + driver->capture_frame_latency;
- }
+ alsa_driver_t* driver = (alsa_driver_t*)arg;
+ jack_client_t* client = driver->client;
+ jack_latency_range_t range;
+ JSList* node;
- for (node = client->ports; node; node = jack_slist_next (node)) {
- jack_port_set_latency_range ((jack_port_t*) node->data, mode, &range);
+ if (mode == JackPlaybackLatency) {
+ range.min = range.max = driver->frames_per_cycle + driver->playback_frame_latency;
+ } else {
+ range.min = range.max = driver->frames_per_cycle + driver->capture_frame_latency;
}
+
+ for (node = client->ports; node; node = jack_slist_next (node))
+ jack_port_set_latency_range ((jack_port_t*)node->data, mode, &range);
}
static int
@@ -1801,7 +1805,7 @@ alsa_driver_attach (alsa_driver_t *driver)
}
driver->engine->set_sample_rate (driver->engine, driver->frame_rate);
- port_flags = JackPortIsOutput|JackPortIsPhysical|JackPortIsTerminal;
+ port_flags = JackPortIsOutput | JackPortIsPhysical | JackPortIsTerminal;
if (driver->has_hw_monitoring) {
port_flags |= JackPortCanMonitor;
@@ -1809,7 +1813,7 @@ alsa_driver_attach (alsa_driver_t *driver)
for (chn = 0; chn < driver->capture_nchannels; chn++) {
- snprintf (buf, sizeof(buf), "capture_%lu", chn+1);
+ snprintf (buf, sizeof(buf), "capture_%lu", chn + 1);
if ((port = jack_port_register (driver->client, buf,
JACK_DEFAULT_AUDIO_TYPE,
@@ -1825,12 +1829,12 @@ alsa_driver_attach (alsa_driver_t *driver)
jack_slist_append (driver->capture_ports, port);
}
- port_flags = JackPortIsInput|JackPortIsPhysical|JackPortIsTerminal;
+ port_flags = JackPortIsInput | JackPortIsPhysical | JackPortIsTerminal;
for (chn = 0; chn < driver->playback_nchannels; chn++) {
jack_port_t *monitor_port;
- snprintf (buf, sizeof(buf) - 1, "playback_%lu", chn+1);
+ snprintf (buf, sizeof(buf) - 1, "playback_%lu", chn + 1);
if ((port = jack_port_register (driver->client, buf,
JACK_DEFAULT_AUDIO_TYPE,
@@ -1846,7 +1850,7 @@ alsa_driver_attach (alsa_driver_t *driver)
jack_slist_append (driver->playback_ports, port);
if (driver->with_monitor_ports) {
- snprintf (buf, sizeof(buf) - 1, "monitor_%lu", chn+1);
+ snprintf (buf, sizeof(buf) - 1, "monitor_%lu", chn + 1);
if ((monitor_port = jack_port_register (
driver->client, buf,
@@ -1878,307 +1882,302 @@ alsa_driver_detach (alsa_driver_t *driver)
return 0;
}
- for (node = driver->capture_ports; node;
- node = jack_slist_next (node)) {
- jack_port_unregister (driver->client,
- ((jack_port_t *) node->data));
- }
+ for (node = driver->capture_ports; node;
+ node = jack_slist_next (node))
+ jack_port_unregister (driver->client,
+ ((jack_port_t*)node->data));
- jack_slist_free (driver->capture_ports);
- driver->capture_ports = 0;
+ jack_slist_free (driver->capture_ports);
+ driver->capture_ports = 0;
- for (node = driver->playback_ports; node;
- node = jack_slist_next (node)) {
- jack_port_unregister (driver->client,
- ((jack_port_t *) node->data));
- }
+ for (node = driver->playback_ports; node;
+ node = jack_slist_next (node))
+ jack_port_unregister (driver->client,
+ ((jack_port_t*)node->data));
- jack_slist_free (driver->playback_ports);
- driver->playback_ports = 0;
+ jack_slist_free (driver->playback_ports);
+ driver->playback_ports = 0;
- if (driver->monitor_ports) {
- for (node = driver->monitor_ports; node;
- node = jack_slist_next (node)) {
- jack_port_unregister (driver->client,
- ((jack_port_t *) node->data));
- }
+ if (driver->monitor_ports) {
+ for (node = driver->monitor_ports; node;
+ node = jack_slist_next (node))
+ jack_port_unregister (driver->client,
+ ((jack_port_t*)node->data));
- jack_slist_free (driver->monitor_ports);
- driver->monitor_ports = 0;
- }
+ jack_slist_free (driver->monitor_ports);
+ driver->monitor_ports = 0;
+ }
- return 0;
- }
+ return 0;
+}
#if 0
- static int /* UNUSED */
- alsa_driver_change_sample_clock (alsa_driver_t *driver, SampleClockMode mode)
-
- {
- return driver->hw->change_sample_clock (driver->hw, mode);
- }
-
- static void /* UNUSED */
- alsa_driver_request_all_monitor_input (alsa_driver_t *driver, int yn)
-
- {
- if (driver->hw_monitoring) {
- if (yn) {
- driver->hw->set_input_monitor_mask (driver->hw, ~0U);
- } else {
- driver->hw->set_input_monitor_mask (
- driver->hw, driver->input_monitor_mask);
- }
- }
-
- driver->all_monitor_in = yn;
- }
-
- static void /* UNUSED */
- alsa_driver_set_hw_monitoring (alsa_driver_t *driver, int yn)
- {
- if (yn) {
- driver->hw_monitoring = TRUE;
-
- if (driver->all_monitor_in) {
- driver->hw->set_input_monitor_mask (driver->hw, ~0U);
- } else {
- driver->hw->set_input_monitor_mask (
- driver->hw, driver->input_monitor_mask);
- }
- } else {
- driver->hw_monitoring = FALSE;
- driver->hw->set_input_monitor_mask (driver->hw, 0);
- }
- }
-
- static ClockSyncStatus /* UNUSED */
- alsa_driver_clock_sync_status (channel_t chn)
- {
- return Lock;
- }
+static int /* UNUSED */
+alsa_driver_change_sample_clock (alsa_driver_t *driver, SampleClockMode mode)
+
+{
+ return driver->hw->change_sample_clock (driver->hw, mode);
+}
+
+static void /* UNUSED */
+alsa_driver_request_all_monitor_input (alsa_driver_t *driver, int yn)
+
+{
+ if (driver->hw_monitoring) {
+ if (yn) {
+ driver->hw->set_input_monitor_mask (driver->hw, ~0U);
+ } else {
+ driver->hw->set_input_monitor_mask (
+ driver->hw, driver->input_monitor_mask);
+ }
+ }
+
+ driver->all_monitor_in = yn;
+}
+
+static void /* UNUSED */
+alsa_driver_set_hw_monitoring (alsa_driver_t *driver, int yn)
+{
+ if (yn) {
+ driver->hw_monitoring = TRUE;
+
+ if (driver->all_monitor_in) {
+ driver->hw->set_input_monitor_mask (driver->hw, ~0U);
+ } else {
+ driver->hw->set_input_monitor_mask (
+ driver->hw, driver->input_monitor_mask);
+ }
+ } else {
+ driver->hw_monitoring = FALSE;
+ driver->hw->set_input_monitor_mask (driver->hw, 0);
+ }
+}
+
+static ClockSyncStatus /* UNUSED */
+alsa_driver_clock_sync_status (channel_t chn)
+{
+ return Lock;
+}
#endif
- static void
- alsa_driver_delete (alsa_driver_t *driver)
- {
- JSList *node;
+static void
+alsa_driver_delete (alsa_driver_t *driver)
+{
+ JSList *node;
- /*
- if (driver->midi)
- (driver->midi->destroy)((jack_driver_t*) driver->midi);
- */
+ /*
+ if (driver->midi)
+ (driver->midi->destroy)((jack_driver_t*) driver->midi);
+ */
- for (node = driver->clock_sync_listeners; node;
- node = jack_slist_next (node)) {
- free (node->data);
- }
- jack_slist_free (driver->clock_sync_listeners);
-
- if (driver->ctl_handle) {
- snd_ctl_close (driver->ctl_handle);
- driver->ctl_handle = 0;
- }
-
- if (driver->capture_handle) {
- snd_pcm_close (driver->capture_handle);
- driver->capture_handle = 0;
- }
-
- if (driver->playback_handle) {
- snd_pcm_close (driver->playback_handle);
- driver->capture_handle = 0;
- }
-
- if (driver->capture_hw_params) {
- snd_pcm_hw_params_free (driver->capture_hw_params);
- driver->capture_hw_params = 0;
- }
-
- if (driver->playback_hw_params) {
- snd_pcm_hw_params_free (driver->playback_hw_params);
- driver->playback_hw_params = 0;
- }
-
- if (driver->capture_sw_params) {
- snd_pcm_sw_params_free (driver->capture_sw_params);
- driver->capture_sw_params = 0;
- }
-
- if (driver->playback_sw_params) {
- snd_pcm_sw_params_free (driver->playback_sw_params);
- driver->playback_sw_params = 0;
- }
-
- if (driver->pfd) {
- free (driver->pfd);
- }
-
- if (driver->hw) {
- driver->hw->release (driver->hw);
- driver->hw = 0;
- }
- free(driver->alsa_name_playback);
- free(driver->alsa_name_capture);
- free(driver->alsa_driver);
-
- alsa_driver_release_channel_dependent_memory (driver);
- jack_driver_nt_finish ((jack_driver_nt_t *) driver);
- free (driver);
- }
-
- static char*
- discover_alsa_using_apps ()
- {
- char found[2048];
- char command[5192];
- char* path = getenv ("PATH");
- char* dir;
- size_t flen = 0;
- int card;
- int device;
- size_t cmdlen = 0;
-
- if (!path) {
- return NULL;
- }
-
- /* look for lsof and give up if its not in PATH */
-
- path = strdup (path);
- dir = strtok (path, ":");
- while (dir) {
- char maybe[PATH_MAX+1];
- snprintf (maybe, sizeof(maybe), "%s/lsof", dir);
- if (access (maybe, X_OK) == 0) {
- break;
- }
- dir = strtok (NULL, ":");
- }
- free (path);
-
- if (!dir) {
- return NULL;
- }
-
- snprintf (command, sizeof (command), "lsof -Fc0 ");
- cmdlen = strlen (command);
-
- for (card = 0; card < 8; ++card) {
- for (device = 0; device < 8; ++device) {
- char buf[32];
-
- snprintf (buf, sizeof (buf), "/dev/snd/pcmC%dD%dp", card, device);
- if (access (buf, F_OK) == 0) {
- snprintf (command+cmdlen, sizeof(command)-cmdlen, "%s ", buf);
- }
- cmdlen = strlen (command);
-
- snprintf (buf, sizeof (buf), "/dev/snd/pcmC%dD%dc", card, device);
- if (access (buf, F_OK) == 0) {
- snprintf (command+cmdlen, sizeof(command)-cmdlen, "%s ", buf);
- }
- cmdlen = strlen (command);
- }
- }
-
- FILE* f = popen (command, "r");
-
- if (!f) {
- return NULL;
- }
-
- while (!feof (f)) {
- char buf[1024]; /* lsof doesn't output much */
-
- if (!fgets (buf, sizeof (buf), f)) {
- break;
- }
-
- if (*buf != 'p') {
- return NULL;
- }
-
- /* buf contains NULL as a separator between the process field and the command field */
- char *pid = buf;
- ++pid; /* skip leading 'p' */
- char *cmd = pid;
-
- /* skip to NULL */
- while (*cmd) {
- ++cmd;
- }
- ++cmd; /* skip to 'c' */
- ++cmd; /* skip to first character of command */
-
- snprintf (found+flen, sizeof (found)-flen, "%s (process ID %s)\n", cmd, pid);
- flen = strlen (found);
-
- if (flen >= sizeof (found)) {
- break;
- }
- }
-
- pclose (f);
-
- if (flen) {
- return strdup (found);
- } else {
- return NULL;
- }
- }
-
-
- static jack_driver_t *
- alsa_driver_new (char *name, char *playback_alsa_device,
- char *capture_alsa_device,
- jack_client_t *client,
- jack_nframes_t frames_per_cycle,
- jack_nframes_t user_nperiods,
- jack_nframes_t rate,
- int hw_monitoring,
- int hw_metering,
- int capturing,
- int playing,
- DitherAlgorithm dither,
- int soft_mode,
- int monitor,
- int user_capture_nchnls,
- int user_playback_nchnls,
- int shorts_first,
- jack_nframes_t capture_latency,
- jack_nframes_t playback_latency
+ for (node = driver->clock_sync_listeners; node;
+ node = jack_slist_next (node))
+ free (node->data);
+ jack_slist_free (driver->clock_sync_listeners);
+
+ if (driver->ctl_handle) {
+ snd_ctl_close (driver->ctl_handle);
+ driver->ctl_handle = 0;
+ }
+
+ if (driver->capture_handle) {
+ snd_pcm_close (driver->capture_handle);
+ driver->capture_handle = 0;
+ }
+
+ if (driver->playback_handle) {
+ snd_pcm_close (driver->playback_handle);
+ driver->capture_handle = 0;
+ }
+
+ if (driver->capture_hw_params) {
+ snd_pcm_hw_params_free (driver->capture_hw_params);
+ driver->capture_hw_params = 0;
+ }
+
+ if (driver->playback_hw_params) {
+ snd_pcm_hw_params_free (driver->playback_hw_params);
+ driver->playback_hw_params = 0;
+ }
+
+ if (driver->capture_sw_params) {
+ snd_pcm_sw_params_free (driver->capture_sw_params);
+ driver->capture_sw_params = 0;
+ }
+
+ if (driver->playback_sw_params) {
+ snd_pcm_sw_params_free (driver->playback_sw_params);
+ driver->playback_sw_params = 0;
+ }
+
+ if (driver->pfd) {
+ free (driver->pfd);
+ }
+
+ if (driver->hw) {
+ driver->hw->release (driver->hw);
+ driver->hw = 0;
+ }
+ free (driver->alsa_name_playback);
+ free (driver->alsa_name_capture);
+ free (driver->alsa_driver);
+
+ alsa_driver_release_channel_dependent_memory (driver);
+ jack_driver_nt_finish ((jack_driver_nt_t*)driver);
+ free (driver);
+}
+
+static char*
+discover_alsa_using_apps ()
+{
+ char found[2048];
+ char command[5192];
+ char* path = getenv ("PATH");
+ char* dir;
+ size_t flen = 0;
+ int card;
+ int device;
+ size_t cmdlen = 0;
+
+ if (!path) {
+ return NULL;
+ }
+
+ /* look for lsof and give up if its not in PATH */
+
+ path = strdup (path);
+ dir = strtok (path, ":");
+ while (dir) {
+ char maybe[PATH_MAX + 1];
+ snprintf (maybe, sizeof(maybe), "%s/lsof", dir);
+ if (access (maybe, X_OK) == 0) {
+ break;
+ }
+ dir = strtok (NULL, ":");
+ }
+ free (path);
+
+ if (!dir) {
+ return NULL;
+ }
+
+ snprintf (command, sizeof(command), "lsof -Fc0 ");
+ cmdlen = strlen (command);
+
+ for (card = 0; card < 8; ++card) {
+ for (device = 0; device < 8; ++device) {
+ char buf[32];
+
+ snprintf (buf, sizeof(buf), "/dev/snd/pcmC%dD%dp", card, device);
+ if (access (buf, F_OK) == 0) {
+ snprintf (command + cmdlen, sizeof(command) - cmdlen, "%s ", buf);
+ }
+ cmdlen = strlen (command);
+
+ snprintf (buf, sizeof(buf), "/dev/snd/pcmC%dD%dc", card, device);
+ if (access (buf, F_OK) == 0) {
+ snprintf (command + cmdlen, sizeof(command) - cmdlen, "%s ", buf);
+ }
+ cmdlen = strlen (command);
+ }
+ }
+
+ FILE* f = popen (command, "r");
+
+ if (!f) {
+ return NULL;
+ }
+
+ while (!feof (f)) {
+ char buf[1024]; /* lsof doesn't output much */
+
+ if (!fgets (buf, sizeof(buf), f)) {
+ break;
+ }
+
+ if (*buf != 'p') {
+ return NULL;
+ }
+
+ /* buf contains NULL as a separator between the process field and the command field */
+ char *pid = buf;
+ ++pid; /* skip leading 'p' */
+ char *cmd = pid;
+
+ /* skip to NULL */
+ while (*cmd)
+ ++cmd;
+ ++cmd; /* skip to 'c' */
+ ++cmd; /* skip to first character of command */
+
+ snprintf (found + flen, sizeof(found) - flen, "%s (process ID %s)\n", cmd, pid);
+ flen = strlen (found);
+
+ if (flen >= sizeof(found)) {
+ break;
+ }
+ }
+
+ pclose (f);
+
+ if (flen) {
+ return strdup (found);
+ } else {
+ return NULL;
+ }
+}
+
+
+static jack_driver_t *
+alsa_driver_new (char *name, char *playback_alsa_device,
+ char *capture_alsa_device,
+ jack_client_t *client,
+ jack_nframes_t frames_per_cycle,
+ jack_nframes_t user_nperiods,
+ jack_nframes_t rate,
+ int hw_monitoring,
+ int hw_metering,
+ int capturing,
+ int playing,
+ DitherAlgorithm dither,
+ int soft_mode,
+ int monitor,
+ int user_capture_nchnls,
+ int user_playback_nchnls,
+ int shorts_first,
+ jack_nframes_t capture_latency,
+ jack_nframes_t playback_latency
)
{
int err;
- char* current_apps;
+ char* current_apps;
alsa_driver_t *driver;
jack_info ("creating alsa driver ... %s|%s|%" PRIu32 "|%" PRIu32
- "|%" PRIu32"|%" PRIu32"|%" PRIu32 "|%s|%s|%s|%s",
- playing ? playback_alsa_device : "-",
- capturing ? capture_alsa_device : "-",
- frames_per_cycle, user_nperiods, rate,
- user_capture_nchnls,user_playback_nchnls,
- hw_monitoring ? "hwmon": "nomon",
- hw_metering ? "hwmeter":"swmeter",
- soft_mode ? "soft-mode":"-",
- shorts_first ? "16bit":"32bit");
-
- driver = (alsa_driver_t *) calloc (1, sizeof (alsa_driver_t));
-
- jack_driver_nt_init ((jack_driver_nt_t *) driver);
-
- driver->nt_attach = (JackDriverNTAttachFunction) alsa_driver_attach;
- driver->nt_detach = (JackDriverNTDetachFunction) alsa_driver_detach;
- driver->read = (JackDriverReadFunction) alsa_driver_read;
- driver->write = (JackDriverReadFunction) alsa_driver_write;
+ "|%" PRIu32 "|%" PRIu32 "|%" PRIu32 "|%s|%s|%s|%s",
+ playing ? playback_alsa_device : "-",
+ capturing ? capture_alsa_device : "-",
+ frames_per_cycle, user_nperiods, rate,
+ user_capture_nchnls, user_playback_nchnls,
+ hw_monitoring ? "hwmon" : "nomon",
+ hw_metering ? "hwmeter" : "swmeter",
+ soft_mode ? "soft-mode" : "-",
+ shorts_first ? "16bit" : "32bit");
+
+ driver = (alsa_driver_t*)calloc (1, sizeof(alsa_driver_t));
+
+ jack_driver_nt_init ((jack_driver_nt_t*)driver);
+
+ driver->nt_attach = (JackDriverNTAttachFunction)alsa_driver_attach;
+ driver->nt_detach = (JackDriverNTDetachFunction)alsa_driver_detach;
+ driver->read = (JackDriverReadFunction)alsa_driver_read;
+ driver->write = (JackDriverReadFunction)alsa_driver_write;
driver->null_cycle =
- (JackDriverNullCycleFunction) alsa_driver_null_cycle;
- driver->nt_bufsize = (JackDriverNTBufSizeFunction) alsa_driver_bufsize;
- driver->nt_start = (JackDriverNTStartFunction) alsa_driver_start;
- driver->nt_stop = (JackDriverNTStopFunction) alsa_driver_stop;
- driver->nt_run_cycle = (JackDriverNTRunCycleFunction) alsa_driver_run_cycle;
+ (JackDriverNullCycleFunction)alsa_driver_null_cycle;
+ driver->nt_bufsize = (JackDriverNTBufSizeFunction)alsa_driver_bufsize;
+ driver->nt_start = (JackDriverNTStartFunction)alsa_driver_start;
+ driver->nt_stop = (JackDriverNTStopFunction)alsa_driver_stop;
+ driver->nt_run_cycle = (JackDriverNTRunCycleFunction)alsa_driver_run_cycle;
driver->playback_handle = NULL;
driver->capture_handle = NULL;
@@ -2189,8 +2188,8 @@ alsa_driver_detach (alsa_driver_t *driver)
driver->user_nchannels = 0;
driver->playback_nchannels = user_playback_nchnls;
driver->capture_nchannels = user_capture_nchnls;
- driver->playback_sample_bytes = (shorts_first ? 2:4);
- driver->capture_sample_bytes = (shorts_first ? 2:4);
+ driver->playback_sample_bytes = (shorts_first ? 2 : 4);
+ driver->capture_sample_bytes = (shorts_first ? 2 : 4);
driver->capture_frame_latency = capture_latency;
driver->playback_frame_latency = playback_latency;
@@ -2198,14 +2197,14 @@ alsa_driver_detach (alsa_driver_t *driver)
driver->capture_addr = 0;
driver->playback_interleave_skip = NULL;
driver->capture_interleave_skip = NULL;
- driver->previously_successfully_configured = FALSE;
+ driver->previously_successfully_configured = FALSE;
driver->silent = 0;
driver->all_monitor_in = FALSE;
driver->with_monitor_ports = monitor;
- driver->clock_mode = ClockMaster; /* XXX is it? */
- driver->input_monitor_mask = 0; /* XXX is it? */
+ driver->clock_mode = ClockMaster; /* XXX is it? */
+ driver->input_monitor_mask = 0; /* XXX is it? */
driver->capture_ports = 0;
driver->playback_ports = 0;
@@ -2246,23 +2245,23 @@ alsa_driver_detach (alsa_driver_t *driver)
SND_PCM_NONBLOCK) < 0) {
switch (errno) {
case EBUSY:
- current_apps = discover_alsa_using_apps ();
- if (current_apps) {
- jack_error ("\n\nATTENTION: The playback device \"%s\" is "
- "already in use. The following applications "
- " are using your soundcard(s) so you should "
- " check them and stop them as necessary before "
- " trying to start JACK again:\n\n%s",
- playback_alsa_device,
- current_apps);
- free (current_apps);
- } else {
- jack_error ("\n\nATTENTION: The playback device \"%s\" is "
- "already in use. Please stop the"
- " application using it and "
- "run JACK again",
- playback_alsa_device);
- }
+ current_apps = discover_alsa_using_apps ();
+ if (current_apps) {
+ jack_error ("\n\nATTENTION: The playback device \"%s\" is "
+ "already in use. The following applications "
+ " are using your soundcard(s) so you should "
+ " check them and stop them as necessary before "
+ " trying to start JACK again:\n\n%s",
+ playback_alsa_device,
+ current_apps);
+ free (current_apps);
+ } else {
+ jack_error ("\n\nATTENTION: The playback device \"%s\" is "
+ "already in use. Please stop the"
+ " application using it and "
+ "run JACK again",
+ playback_alsa_device);
+ }
alsa_driver_delete (driver);
return NULL;
break;
@@ -2291,23 +2290,23 @@ alsa_driver_detach (alsa_driver_t *driver)
SND_PCM_NONBLOCK) < 0) {
switch (errno) {
case EBUSY:
- current_apps = discover_alsa_using_apps ();
- if (current_apps) {
- jack_error ("\n\nATTENTION: The capture device \"%s\" is "
- "already in use. The following applications "
- " are using your soundcard(s) so you should "
- " check them and stop them as necessary before "
- " trying to start JACK again:\n\n%s",
- capture_alsa_device,
- current_apps);
- free (current_apps);
- } else {
- jack_error ("\n\nATTENTION: The capture (recording) device \"%s\" is "
- "already in use. Please stop the"
- " application using it and "
- "run JACK again",
- capture_alsa_device);
- }
+ current_apps = discover_alsa_using_apps ();
+ if (current_apps) {
+ jack_error ("\n\nATTENTION: The capture device \"%s\" is "
+ "already in use. The following applications "
+ " are using your soundcard(s) so you should "
+ " check them and stop them as necessary before "
+ " trying to start JACK again:\n\n%s",
+ capture_alsa_device,
+ current_apps);
+ free (current_apps);
+ } else {
+ jack_error ("\n\nATTENTION: The capture (recording) device \"%s\" is "
+ "already in use. Please stop the"
+ " application using it and "
+ "run JACK again",
+ capture_alsa_device);
+ }
alsa_driver_delete (driver);
return NULL;
break;
@@ -2423,11 +2422,11 @@ alsa_driver_detach (alsa_driver_t *driver)
}
}
- jack_set_latency_callback (client, alsa_driver_latency_callback, driver);
+ jack_set_latency_callback (client, alsa_driver_latency_callback, driver);
driver->client = client;
- return (jack_driver_t *) driver;
+ return (jack_driver_t*)driver;
}
int
@@ -2437,7 +2436,7 @@ alsa_driver_listen_for_clock_sync_status (alsa_driver_t *driver,
{
ClockSyncListener *csl;
- csl = (ClockSyncListener *) malloc (sizeof (ClockSyncListener));
+ csl = (ClockSyncListener*)malloc (sizeof(ClockSyncListener));
csl->function = func;
csl->arg = arg;
csl->id = driver->next_clock_sync_listener_id++;
@@ -2456,10 +2455,11 @@ alsa_driver_stop_listening_to_clock_sync_status (alsa_driver_t *driver,
{
JSList *node;
int ret = -1;
+
pthread_mutex_lock (&driver->clock_sync_lock);
for (node = driver->clock_sync_listeners; node;
node = jack_slist_next (node)) {
- if (((ClockSyncListener *) node->data)->id == which) {
+ if (((ClockSyncListener*)node->data)->id == which) {
driver->clock_sync_listeners =
jack_slist_remove_link (
driver->clock_sync_listeners, node);
@@ -2482,7 +2482,7 @@ alsa_driver_clock_sync_notify (alsa_driver_t *driver, channel_t chn,
pthread_mutex_lock (&driver->clock_sync_lock);
for (node = driver->clock_sync_listeners; node;
node = jack_slist_next (node)) {
- ClockSyncListener *csl = (ClockSyncListener *) node->data;
+ ClockSyncListener *csl = (ClockSyncListener*)node->data;
csl->function (chn, status, csl->arg);
}
pthread_mutex_unlock (&driver->clock_sync_lock);
@@ -2529,12 +2529,12 @@ driver_get_descriptor ()
jack_driver_param_desc_t * params;
unsigned int i;
- desc = calloc (1, sizeof (jack_driver_desc_t));
+ desc = calloc (1, sizeof(jack_driver_desc_t));
- strcpy (desc->name,"alsa");
+ strcpy (desc->name, "alsa");
desc->nparams = 18;
- params = calloc (desc->nparams, sizeof (jack_driver_param_desc_t));
+ params = calloc (desc->nparams, sizeof(jack_driver_param_desc_t));
i = 0;
strcpy (params[i].name, "capture");
@@ -2591,7 +2591,7 @@ driver_get_descriptor ()
params[i].character = 'H';
params[i].type = JackDriverParamBool;
params[i].value.i = 0;
- strcpy (params[i].short_desc,"Hardware monitoring, if available");
+ strcpy (params[i].short_desc, "Hardware monitoring, if available");
strcpy (params[i].long_desc, params[i].short_desc);
i++;
@@ -2614,7 +2614,7 @@ driver_get_descriptor ()
i++;
strcpy (params[i].name, "softmode");
params[i].character = 's';
- params[i].type = JackDriverParamBool;
+ params[i].type = JackDriverParamBool;
params[i].value.i = 0;
strcpy (params[i].short_desc, "Soft-mode, no xrun handling");
strcpy (params[i].long_desc, params[i].short_desc);
@@ -2699,7 +2699,7 @@ driver_get_descriptor ()
jack_driver_t *
driver_initialize (jack_client_t *client, const JSList * params)
{
- jack_nframes_t srate = 48000;
+ jack_nframes_t srate = 48000;
jack_nframes_t frames_per_interrupt = 1024;
unsigned long user_nperiods = 2;
char *playback_pcm_name = "hw:0";
@@ -2720,7 +2720,7 @@ driver_initialize (jack_client_t *client, const JSList * params)
const jack_driver_param_t * param;
for (node = params; node; node = jack_slist_next (node)) {
- param = (const jack_driver_param_t *) node->data;
+ param = (const jack_driver_param_t*)node->data;
switch (param->character) {
@@ -2761,9 +2761,9 @@ driver_initialize (jack_client_t *client, const JSList * params)
break;
case 'r':
- srate = param->value.ui;
+ srate = param->value.ui;
jack_info ("apparent rate = %d", srate);
- break;
+ break;
case 'p':
frames_per_interrupt = param->value.ui;
@@ -2771,8 +2771,9 @@ driver_initialize (jack_client_t *client, const JSList * params)
case 'n':
user_nperiods = param->value.ui;
- if (user_nperiods < 2) /* enforce minimum value */
+ if (user_nperiods < 2) { /* enforce minimum value */
user_nperiods = 2;
+ }
break;
case 's':
@@ -2781,7 +2782,7 @@ driver_initialize (jack_client_t *client, const JSList * params)
case 'z':
if (dither_opt (param->value.c, &dither)) {
- return NULL;
+ return NULL;
}
break;
@@ -2789,7 +2790,7 @@ driver_initialize (jack_client_t *client, const JSList * params)
user_capture_nchnls = param->value.ui;
break;
case 'o':
- user_playback_nchnls = param->value.ui;
+ user_playback_nchnls = param->value.ui;
break;
case 'S':
@@ -2805,7 +2806,7 @@ driver_initialize (jack_client_t *client, const JSList * params)
break;
case 'X':
- /* ignored, legacy option */
+ /* ignored, legacy option */
break;
}
@@ -2832,5 +2833,5 @@ driver_initialize (jack_client_t *client, const JSList * params)
void
driver_finish (jack_driver_t *driver)
{
- alsa_driver_delete ((alsa_driver_t *) driver);
+ alsa_driver_delete ((alsa_driver_t*)driver);
}
diff --git a/drivers/alsa/alsa_driver.h b/drivers/alsa/alsa_driver.h
index 074ac69..5066bcc 100644
--- a/drivers/alsa/alsa_driver.h
+++ b/drivers/alsa/alsa_driver.h
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2001 Paul Davis
+ Copyright (C) 2001 Paul Davis
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
@@ -15,7 +15,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
+ */
#ifndef __jack_alsa_driver_h__
#define __jack_alsa_driver_h__
@@ -38,180 +38,183 @@
#include "driver.h"
#include "memops.h"
-typedef void (*ReadCopyFunction) (jack_default_audio_sample_t *dst, char *src,
- unsigned long src_bytes,
- unsigned long src_skip_bytes);
-typedef void (*WriteCopyFunction) (char *dst, jack_default_audio_sample_t *src,
- unsigned long src_bytes,
- unsigned long dst_skip_bytes,
- dither_state_t *state);
+typedef void (*ReadCopyFunction)(jack_default_audio_sample_t *dst, char *src,
+ unsigned long src_bytes,
+ unsigned long src_skip_bytes);
+typedef void (*WriteCopyFunction)(char *dst, jack_default_audio_sample_t *src,
+ unsigned long src_bytes,
+ unsigned long dst_skip_bytes,
+ dither_state_t *state);
typedef struct _alsa_driver {
- JACK_DRIVER_NT_DECL
-
- int poll_timeout;
- jack_time_t poll_last;
- jack_time_t poll_next;
- char **playback_addr;
- char **capture_addr;
- const snd_pcm_channel_area_t *capture_areas;
- const snd_pcm_channel_area_t *playback_areas;
- struct pollfd *pfd;
- unsigned int playback_nfds;
- unsigned int capture_nfds;
- unsigned long interleave_unit;
- unsigned long *capture_interleave_skip;
- unsigned long *playback_interleave_skip;
- channel_t max_nchannels;
- channel_t user_nchannels;
- channel_t playback_nchannels;
- channel_t capture_nchannels;
- unsigned long playback_sample_bytes;
- unsigned long capture_sample_bytes;
-
- jack_nframes_t frame_rate;
- jack_nframes_t frames_per_cycle;
- jack_nframes_t capture_frame_latency;
- jack_nframes_t playback_frame_latency;
-
- unsigned long *silent;
- char *alsa_name_playback;
- char *alsa_name_capture;
- char *alsa_driver;
- bitset_t channels_not_done;
- bitset_t channels_done;
- snd_pcm_format_t playback_sample_format;
- snd_pcm_format_t capture_sample_format;
- float max_sample_val;
- unsigned long user_nperiods;
- unsigned int playback_nperiods;
- unsigned int capture_nperiods;
- unsigned long last_mask;
- snd_ctl_t *ctl_handle;
- snd_pcm_t *playback_handle;
- snd_pcm_t *capture_handle;
- snd_pcm_hw_params_t *playback_hw_params;
- snd_pcm_sw_params_t *playback_sw_params;
- snd_pcm_hw_params_t *capture_hw_params;
- snd_pcm_sw_params_t *capture_sw_params;
- jack_hardware_t *hw;
- ClockSyncStatus *clock_sync_data;
- jack_client_t *client;
- JSList *capture_ports;
- JSList *playback_ports;
- JSList *monitor_ports;
-
- unsigned long input_monitor_mask;
-
- char soft_mode;
- char hw_monitoring;
- char hw_metering;
- char all_monitor_in;
- char capture_and_playback_not_synced;
- char playback_interleaved;
- char capture_interleaved;
- char with_monitor_ports;
- char has_clock_sync_reporting;
- char has_hw_monitoring;
- char has_hw_metering;
- char quirk_bswap;
-
- ReadCopyFunction read_via_copy;
- WriteCopyFunction write_via_copy;
-
- int dither;
- dither_state_t *dither_state;
-
- SampleClockMode clock_mode;
- JSList *clock_sync_listeners;
- pthread_mutex_t clock_sync_lock;
- unsigned long next_clock_sync_listener_id;
-
- int running;
- int run;
-
- int poll_late;
- int xrun_count;
- int process_count;
-
- int xrun_recovery;
- int previously_successfully_configured;
+ JACK_DRIVER_NT_DECL
+
+ int poll_timeout;
+ jack_time_t poll_last;
+ jack_time_t poll_next;
+ char **playback_addr;
+ char **capture_addr;
+ const snd_pcm_channel_area_t *capture_areas;
+ const snd_pcm_channel_area_t *playback_areas;
+ struct pollfd *pfd;
+ unsigned int playback_nfds;
+ unsigned int capture_nfds;
+ unsigned long interleave_unit;
+ unsigned long *capture_interleave_skip;
+ unsigned long *playback_interleave_skip;
+ channel_t max_nchannels;
+ channel_t user_nchannels;
+ channel_t playback_nchannels;
+ channel_t capture_nchannels;
+ unsigned long playback_sample_bytes;
+ unsigned long capture_sample_bytes;
+
+ jack_nframes_t frame_rate;
+ jack_nframes_t frames_per_cycle;
+ jack_nframes_t capture_frame_latency;
+ jack_nframes_t playback_frame_latency;
+
+ unsigned long *silent;
+ char *alsa_name_playback;
+ char *alsa_name_capture;
+ char *alsa_driver;
+ bitset_t channels_not_done;
+ bitset_t channels_done;
+ snd_pcm_format_t playback_sample_format;
+ snd_pcm_format_t capture_sample_format;
+ float max_sample_val;
+ unsigned long user_nperiods;
+ unsigned int playback_nperiods;
+ unsigned int capture_nperiods;
+ unsigned long last_mask;
+ snd_ctl_t *ctl_handle;
+ snd_pcm_t *playback_handle;
+ snd_pcm_t *capture_handle;
+ snd_pcm_hw_params_t *playback_hw_params;
+ snd_pcm_sw_params_t *playback_sw_params;
+ snd_pcm_hw_params_t *capture_hw_params;
+ snd_pcm_sw_params_t *capture_sw_params;
+ jack_hardware_t *hw;
+ ClockSyncStatus *clock_sync_data;
+ jack_client_t *client;
+ JSList *capture_ports;
+ JSList *playback_ports;
+ JSList *monitor_ports;
+
+ unsigned long input_monitor_mask;
+
+ char soft_mode;
+ char hw_monitoring;
+ char hw_metering;
+ char all_monitor_in;
+ char capture_and_playback_not_synced;
+ char playback_interleaved;
+ char capture_interleaved;
+ char with_monitor_ports;
+ char has_clock_sync_reporting;
+ char has_hw_monitoring;
+ char has_hw_metering;
+ char quirk_bswap;
+
+ ReadCopyFunction read_via_copy;
+ WriteCopyFunction write_via_copy;
+
+ int dither;
+ dither_state_t *dither_state;
+
+ SampleClockMode clock_mode;
+ JSList *clock_sync_listeners;
+ pthread_mutex_t clock_sync_lock;
+ unsigned long next_clock_sync_listener_id;
+
+ int running;
+ int run;
+
+ int poll_late;
+ int xrun_count;
+ int process_count;
+
+ int xrun_recovery;
+ int previously_successfully_configured;
} alsa_driver_t;
-static inline void
-alsa_driver_mark_channel_done (alsa_driver_t *driver, channel_t chn) {
+static inline void
+alsa_driver_mark_channel_done (alsa_driver_t *driver, channel_t chn)
+{
bitset_remove (driver->channels_not_done, chn);
driver->silent[chn] = 0;
}
-static inline void
+static inline void
alsa_driver_silence_on_channel (alsa_driver_t *driver, channel_t chn,
- jack_nframes_t nframes) {
+ jack_nframes_t nframes)
+{
if (driver->playback_interleaved) {
- memset_interleave
+ memset_interleave
(driver->playback_addr[chn],
- 0, nframes * driver->playback_sample_bytes,
- driver->interleave_unit,
- driver->playback_interleave_skip[chn]);
+ 0, nframes * driver->playback_sample_bytes,
+ driver->interleave_unit,
+ driver->playback_interleave_skip[chn]);
} else {
memset (driver->playback_addr[chn], 0,
nframes * driver->playback_sample_bytes);
}
- alsa_driver_mark_channel_done (driver,chn);
+ alsa_driver_mark_channel_done (driver, chn);
}
-static inline void
+static inline void
alsa_driver_silence_on_channel_no_mark (alsa_driver_t *driver, channel_t chn,
- jack_nframes_t nframes) {
+ jack_nframes_t nframes)
+{
if (driver->playback_interleaved) {
- memset_interleave
+ memset_interleave
(driver->playback_addr[chn],
- 0, nframes * driver->playback_sample_bytes,
- driver->interleave_unit,
- driver->playback_interleave_skip[chn]);
+ 0, nframes * driver->playback_sample_bytes,
+ driver->interleave_unit,
+ driver->playback_interleave_skip[chn]);
} else {
memset (driver->playback_addr[chn], 0,
nframes * driver->playback_sample_bytes);
}
}
-static inline void
+static inline void
alsa_driver_read_from_channel (alsa_driver_t *driver,
channel_t channel,
jack_default_audio_sample_t *buf,
jack_nframes_t nsamples)
{
- driver->read_via_copy (buf,
+ driver->read_via_copy (buf,
driver->capture_addr[channel],
- nsamples,
+ nsamples,
driver->capture_interleave_skip[channel]);
}
-static inline void
+static inline void
alsa_driver_write_to_channel (alsa_driver_t *driver,
- channel_t channel,
- jack_default_audio_sample_t *buf,
+ channel_t channel,
+ jack_default_audio_sample_t *buf,
jack_nframes_t nsamples)
{
driver->write_via_copy (driver->playback_addr[channel],
- buf,
- nsamples,
+ buf,
+ nsamples,
driver->playback_interleave_skip[channel],
- driver->dither_state+channel);
+ driver->dither_state + channel);
alsa_driver_mark_channel_done (driver, channel);
}
-void alsa_driver_silence_untouched_channels (alsa_driver_t *driver,
- jack_nframes_t nframes);
-void alsa_driver_set_clock_sync_status (alsa_driver_t *driver, channel_t chn,
- ClockSyncStatus status);
-int alsa_driver_listen_for_clock_sync_status (alsa_driver_t *,
- ClockSyncListenerFunction,
- void *arg);
-int alsa_driver_stop_listen_for_clock_sync_status (alsa_driver_t *,
- unsigned int);
-void alsa_driver_clock_sync_notify (alsa_driver_t *, channel_t chn,
- ClockSyncStatus);
+void alsa_driver_silence_untouched_channels(alsa_driver_t *driver,
+ jack_nframes_t nframes);
+void alsa_driver_set_clock_sync_status(alsa_driver_t *driver, channel_t chn,
+ ClockSyncStatus status);
+int alsa_driver_listen_for_clock_sync_status (alsa_driver_t *,
+ ClockSyncListenerFunction,
+ void *arg);
+int alsa_driver_stop_listen_for_clock_sync_status(alsa_driver_t *,
+ unsigned int);
+void alsa_driver_clock_sync_notify (alsa_driver_t *, channel_t chn,
+ ClockSyncStatus);
#endif /* __jack_alsa_driver_h__ */
diff --git a/drivers/alsa/generic.h b/drivers/alsa/generic.h
index 73dc593..434e610 100644
--- a/drivers/alsa/generic.h
+++ b/drivers/alsa/generic.h
@@ -1,6 +1,6 @@
/*
Copyright (C) 2001 Paul Davis
-
+
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
@@ -15,12 +15,12 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
+ */
#ifndef __jack_generic_h__
#define __jack_generic_h__
jack_hardware_t *
-jack_alsa_generic_hw_new (alsa_driver_t *driver);
+jack_alsa_generic_hw_new(alsa_driver_t *driver);
#endif /* __jack_generic_h__*/
diff --git a/drivers/alsa/generic_hw.c b/drivers/alsa/generic_hw.c
index 69457e2..f65f00d 100644
--- a/drivers/alsa/generic_hw.c
+++ b/drivers/alsa/generic_hw.c
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2001 Paul Davis
+ Copyright (C) 2001 Paul Davis
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
@@ -15,7 +15,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
+ */
#include "hardware.h"
#include "alsa_driver.h"
@@ -25,7 +25,7 @@ static int generic_set_input_monitor_mask (jack_hardware_t *hw, unsigned long ma
return -1;
}
-static int generic_change_sample_clock (jack_hardware_t *hw, SampleClockMode mode)
+static int generic_change_sample_clock (jack_hardware_t *hw, SampleClockMode mode)
{
return -1;
}
@@ -42,11 +42,11 @@ jack_alsa_generic_hw_new (alsa_driver_t *driver)
{
jack_hardware_t *hw;
- hw = (jack_hardware_t *) malloc (sizeof (jack_hardware_t));
+ hw = (jack_hardware_t*)malloc (sizeof(jack_hardware_t));
hw->capabilities = 0;
hw->input_monitor_mask = 0;
-
+
hw->set_input_monitor_mask = generic_set_input_monitor_mask;
hw->change_sample_clock = generic_change_sample_clock;
hw->release = generic_release;
diff --git a/drivers/alsa/hammerfall.c b/drivers/alsa/hammerfall.c
index fcb9add..531d73a 100644
--- a/drivers/alsa/hammerfall.c
+++ b/drivers/alsa/hammerfall.c
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2001 Paul Davis
+ Copyright (C) 2001 Paul Davis
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
@@ -15,7 +15,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
+ */
#include "hardware.h"
#include "alsa_driver.h"
@@ -26,7 +26,7 @@
* warning: `hammerfall_monitor_controls' defined but not used */
#define HAMMERFALL_MONITOR_CONTROLS 0
-static void
+static void
set_control_id (snd_ctl_elem_id_t *ctl, const char *name)
{
snd_ctl_elem_id_set_name (ctl, name);
@@ -57,9 +57,8 @@ hammerfall_broadcast_channel_status_change (hammerfall_t *h, int lock, int sync,
status |= NoSync;
}
- for (chn = lowchn; chn < highchn; chn++) {
+ for (chn = lowchn; chn < highchn; chn++)
alsa_driver_set_clock_sync_status (h->driver, chn, status);
- }
}
static void
@@ -74,12 +73,12 @@ hammerfall_check_sync_state (hammerfall_t *h, int val, int adat_id)
XXX - maybe need to make sure that the rate matches our
idea of the current rate ?
- */
+ */
if (!h->said_that_spdif_is_fine) {
ClockSyncStatus status;
-
- status = Lock|Sync;
+
+ status = Lock | Sync;
/* XXX broken! fix for hammerfall light ! */
@@ -91,10 +90,10 @@ hammerfall_check_sync_state (hammerfall_t *h, int val, int adat_id)
lock = (val & 0x1) ? TRUE : FALSE;
sync = (val & 0x2) ? TRUE : FALSE;
-
+
if (h->lock_status[adat_id] != lock ||
h->sync_status[adat_id] != sync) {
- hammerfall_broadcast_channel_status_change (h, lock, sync, adat_id*8, (adat_id*8)+8);
+ hammerfall_broadcast_channel_status_change (h, lock, sync, adat_id * 8, (adat_id * 8) + 8);
}
h->lock_status[adat_id] = lock;
@@ -108,7 +107,7 @@ hammerfall_check_sync (hammerfall_t *h, snd_ctl_elem_value_t *ctl)
const char *name;
int val;
snd_ctl_elem_id_t *ctl_id;
-
+
jack_info ("check sync");
snd_ctl_elem_id_alloca (&ctl_id);
@@ -131,38 +130,37 @@ hammerfall_check_sync (hammerfall_t *h, snd_ctl_elem_value_t *ctl)
}
#endif /* HAMMERFALL_MONITOR_CONTROLS */
-static int
+static int
hammerfall_set_input_monitor_mask (jack_hardware_t *hw, unsigned long mask)
{
- hammerfall_t *h = (hammerfall_t *) hw->private;
+ hammerfall_t *h = (hammerfall_t*)hw->private;
snd_ctl_elem_value_t *ctl;
snd_ctl_elem_id_t *ctl_id;
int err;
int i;
-
+
snd_ctl_elem_value_alloca (&ctl);
snd_ctl_elem_id_alloca (&ctl_id);
set_control_id (ctl_id, "Channels Thru");
snd_ctl_elem_value_set_id (ctl, ctl_id);
-
- for (i = 0; i < 26; i++) {
- snd_ctl_elem_value_set_integer (ctl, i, (mask & (1<<i)) ? 1 : 0);
- }
-
+
+ for (i = 0; i < 26; i++)
+ snd_ctl_elem_value_set_integer (ctl, i, (mask & (1 << i)) ? 1 : 0);
+
if ((err = snd_ctl_elem_write (h->driver->ctl_handle, ctl)) != 0) {
jack_error ("ALSA/Hammerfall: cannot set input monitoring (%s)", snd_strerror (err));
return -1;
}
-
+
hw->input_monitor_mask = mask;
return 0;
}
-static int
-hammerfall_change_sample_clock (jack_hardware_t *hw, SampleClockMode mode)
+static int
+hammerfall_change_sample_clock (jack_hardware_t *hw, SampleClockMode mode)
{
- hammerfall_t *h = (hammerfall_t *) hw->private;
+ hammerfall_t *h = (hammerfall_t*)hw->private;
snd_ctl_elem_value_t *ctl;
snd_ctl_elem_id_t *ctl_id;
int err;
@@ -195,7 +193,7 @@ static void
hammerfall_release (jack_hardware_t *hw)
{
- hammerfall_t *h = (hammerfall_t *) hw->private;
+ hammerfall_t *h = (hammerfall_t*)hw->private;
void *status;
if (h == 0) {
@@ -212,8 +210,8 @@ hammerfall_release (jack_hardware_t *hw)
static void *
hammerfall_monitor_controls (void *arg)
{
- jack_hardware_t *hw = (jack_hardware_t *) arg;
- hammerfall_t *h = (hammerfall_t *) hw->private;
+ jack_hardware_t *hw = (jack_hardware_t*)arg;
+ hammerfall_t *h = (hammerfall_t*)hw->private;
snd_ctl_elem_id_t *switch_id[3];
snd_ctl_elem_value_t *sw[3];
@@ -250,7 +248,7 @@ hammerfall_monitor_controls (void *arg)
jack_error ("cannot read control switch 0 ...");
}
hammerfall_check_sync (h, sw[2]);
-
+
if (nanosleep (&h->monitor_interval, 0)) {
break;
}
@@ -267,9 +265,9 @@ jack_alsa_hammerfall_hw_new (alsa_driver_t *driver)
jack_hardware_t *hw;
hammerfall_t *h;
- hw = (jack_hardware_t *) malloc (sizeof (jack_hardware_t));
+ hw = (jack_hardware_t*)malloc (sizeof(jack_hardware_t));
- hw->capabilities = Cap_HardwareMonitoring|Cap_AutoSync|Cap_WordClock|Cap_ClockMaster|Cap_ClockLockReporting;
+ hw->capabilities = Cap_HardwareMonitoring | Cap_AutoSync | Cap_WordClock | Cap_ClockMaster | Cap_ClockLockReporting;
hw->input_monitor_mask = 0;
hw->private = 0;
@@ -277,7 +275,7 @@ jack_alsa_hammerfall_hw_new (alsa_driver_t *driver)
hw->change_sample_clock = hammerfall_change_sample_clock;
hw->release = hammerfall_release;
- h = (hammerfall_t *) malloc (sizeof (hammerfall_t));
+ h = (hammerfall_t*)malloc (sizeof(hammerfall_t));
h->lock_status[0] = FALSE;
h->sync_status[0] = FALSE;
diff --git a/drivers/alsa/hammerfall.h b/drivers/alsa/hammerfall.h
index b10ce6a..9077114 100644
--- a/drivers/alsa/hammerfall.h
+++ b/drivers/alsa/hammerfall.h
@@ -1,6 +1,6 @@
/*
Copyright (C) 2001 Paul Davis
-
+
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
@@ -15,7 +15,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
+ */
#ifndef __jack_hammerfall_h__
#define __jack_hammerfall_h__
@@ -23,14 +23,14 @@
#include <sys/time.h>
typedef struct {
- int lock_status[3];
- int sync_status[3];
- int said_that_spdif_is_fine;
- pthread_t monitor_thread;
- alsa_driver_t *driver;
- struct timespec monitor_interval;
+ int lock_status[3];
+ int sync_status[3];
+ int said_that_spdif_is_fine;
+ pthread_t monitor_thread;
+ alsa_driver_t *driver;
+ struct timespec monitor_interval;
} hammerfall_t;
-jack_hardware_t *jack_alsa_hammerfall_hw_new (alsa_driver_t *driver);
+jack_hardware_t *jack_alsa_hammerfall_hw_new(alsa_driver_t *driver);
#endif /* __jack_hammerfall_h__*/
diff --git a/drivers/alsa/hdsp.c b/drivers/alsa/hdsp.c
index cf28a91..bea357b 100644
--- a/drivers/alsa/hdsp.c
+++ b/drivers/alsa/hdsp.c
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2001 Paul Davis
+ Copyright (C) 2001 Paul Davis
Copyright (C) 2002 Dave LaRose
This program is free software; you can redistribute it and/or modify
@@ -16,7 +16,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
+ */
#include "hardware.h"
#include "alsa_driver.h"
@@ -29,45 +29,48 @@ static const int HDSP_UNITY_GAIN = 32768;
static const int HDSP_MAX_GAIN = 65535;
/*
- * Use these two arrays to choose the value of the input_channel
- * argument to hsdp_set_mixer_gain(). hdsp_physical_input_index[n]
- * selects the nth optical/analog input. audio_stream_index[n]
+ * Use these two arrays to choose the value of the input_channel
+ * argument to hsdp_set_mixer_gain(). hdsp_physical_input_index[n]
+ * selects the nth optical/analog input. audio_stream_index[n]
* selects the nth channel being received from the host via pci/pccard.
*/
static const int hdsp_num_input_channels = 52;
static const int hdsp_physical_input_index[] = {
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
- 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25};
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
+ 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,24, 25
+};
static const int hdsp_audio_stream_index[] = {
- 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
- 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51};
+ 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
+ 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49,50, 51
+};
/*
- * Use this array to choose the value of the output_channel
+ * Use this array to choose the value of the output_channel
* argument to hsdp_set_mixer_gain(). hdsp_physical_output_index[26]
* and hdsp_physical_output_index[27] refer to the two "line out"
* channels (1/4" phone jack on the front of digiface/multiface).
*/
static const int hdsp_num_output_channels = 28;
static const int hdsp_physical_output_index[] = {
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
- 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27};
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
+ 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,24, 25, 26, 27
+};
/* Function for checking argument values */
-static int clamp_int(int value, int lower_bound, int upper_bound)
+static int clamp_int (int value, int lower_bound, int upper_bound)
{
- if(value < lower_bound) {
- return lower_bound;
- }
- if(value > upper_bound) {
- return upper_bound;
- }
- return value;
+ if (value < lower_bound) {
+ return lower_bound;
+ }
+ if (value > upper_bound) {
+ return upper_bound;
+ }
+ return value;
}
/* Note(XXX): Maybe should share this code with hammerfall.c? */
-static void
+static void
set_control_id (snd_ctl_elem_id_t *ctl, const char *name)
{
snd_ctl_elem_id_set_name (ctl, name);
@@ -86,18 +89,18 @@ set_control_id (snd_ctl_elem_id_t *ctl, const char *name)
/* gain is an int from 0 to 65535, with 0 being -inf gain, and */
/* 65535 being about +2dB. */
-static int hdsp_set_mixer_gain(jack_hardware_t *hw, int input_channel,
- int output_channel, int gain)
+static int hdsp_set_mixer_gain (jack_hardware_t *hw, int input_channel,
+ int output_channel, int gain)
{
- hdsp_t *h = (hdsp_t *) hw->private;
+ hdsp_t *h = (hdsp_t*)hw->private;
snd_ctl_elem_value_t *ctl;
snd_ctl_elem_id_t *ctl_id;
int err;
/* Check args */
- input_channel = clamp_int(input_channel, 0, hdsp_num_input_channels);
- output_channel = clamp_int(output_channel, 0, hdsp_num_output_channels);
- gain = clamp_int(gain, HDSP_MINUS_INFINITY_GAIN, HDSP_MAX_GAIN);
+ input_channel = clamp_int (input_channel, 0, hdsp_num_input_channels);
+ output_channel = clamp_int (output_channel, 0, hdsp_num_output_channels);
+ gain = clamp_int (gain, HDSP_MINUS_INFINITY_GAIN, HDSP_MAX_GAIN);
/* Allocate control element and select "Mixer" control */
snd_ctl_elem_value_alloca (&ctl);
@@ -106,15 +109,15 @@ static int hdsp_set_mixer_gain(jack_hardware_t *hw, int input_channel,
snd_ctl_elem_value_set_id (ctl, ctl_id);
/* Apparently non-standard and unstable interface for the */
- /* mixer control. */
+ /* mixer control. */
snd_ctl_elem_value_set_integer (ctl, 0, input_channel);
snd_ctl_elem_value_set_integer (ctl, 1, output_channel);
snd_ctl_elem_value_set_integer (ctl, 2, gain);
/* Commit the mixer value and check for errors */
if ((err = snd_ctl_elem_write (h->driver->ctl_handle, ctl)) != 0) {
- jack_error ("ALSA/HDSP: cannot set mixer gain (%s)", snd_strerror (err));
- return -1;
+ jack_error ("ALSA/HDSP: cannot set mixer gain (%s)", snd_strerror (err));
+ return -1;
}
/* Note (XXX): Perhaps we should maintain a cache of the current */
@@ -122,7 +125,7 @@ static int hdsp_set_mixer_gain(jack_hardware_t *hw, int input_channel,
/* hdsp hardware. We'll leave this out until a little later. */
return 0;
}
-
+
static int hdsp_set_input_monitor_mask (jack_hardware_t *hw, unsigned long mask)
{
int i;
@@ -130,40 +133,40 @@ static int hdsp_set_input_monitor_mask (jack_hardware_t *hw, unsigned long mask)
/* For each input channel */
for (i = 0; i < 26; i++) {
/* Monitoring requested for this channel? */
- if(mask & (1<<i)) {
+ if (mask & (1 << i)) {
/* Yes. Connect physical input to output */
- if(hdsp_set_mixer_gain (hw, hdsp_physical_input_index[i],
- hdsp_physical_output_index[i],
- HDSP_UNITY_GAIN) != 0) {
- return -1;
+ if (hdsp_set_mixer_gain (hw, hdsp_physical_input_index[i],
+ hdsp_physical_output_index[i],
+ HDSP_UNITY_GAIN) != 0) {
+ return -1;
}
#ifdef CANNOT_HEAR_SOFTWARE_STREAM_WHEN_MONITORING
/* ...and disconnect the corresponding software */
/* channel */
- if(hdsp_set_mixer_gain (hw, hdsp_audio_stream_index[i],
- hdsp_physical_output_index[i],
- HDSP_MINUS_INFINITY_GAIN) != 0) {
- return -1;
+ if (hdsp_set_mixer_gain (hw, hdsp_audio_stream_index[i],
+ hdsp_physical_output_index[i],
+ HDSP_MINUS_INFINITY_GAIN) != 0) {
+ return -1;
}
#endif
} else {
/* No. Disconnect physical input from output */
- if(hdsp_set_mixer_gain (hw, hdsp_physical_input_index[i],
- hdsp_physical_output_index[i],
- HDSP_MINUS_INFINITY_GAIN) != 0) {
- return -1;
+ if (hdsp_set_mixer_gain (hw, hdsp_physical_input_index[i],
+ hdsp_physical_output_index[i],
+ HDSP_MINUS_INFINITY_GAIN) != 0) {
+ return -1;
}
#ifdef CANNOT_HEAR_SOFTWARE_STREAM_WHEN_MONITORING
/* ...and connect the corresponding software */
/* channel */
- if(hdsp_set_mixer_gain (hw, hdsp_audio_stream_index[i],
- hdsp_physical_output_index[i],
- HDSP_UNITY_GAIN) != 0) {
- return -1;
+ if (hdsp_set_mixer_gain (hw, hdsp_audio_stream_index[i],
+ hdsp_physical_output_index[i],
+ HDSP_UNITY_GAIN) != 0) {
+ return -1;
}
#endif
}
@@ -174,11 +177,11 @@ static int hdsp_set_input_monitor_mask (jack_hardware_t *hw, unsigned long mask)
}
-static int hdsp_change_sample_clock (jack_hardware_t *hw, SampleClockMode mode)
+static int hdsp_change_sample_clock (jack_hardware_t *hw, SampleClockMode mode)
{
- // Empty for now, until Dave understands more about clock sync so
- // he can test.
- return -1;
+ // Empty for now, until Dave understands more about clock sync so
+ // he can test.
+ return -1;
}
static double hdsp_get_hardware_peak (jack_port_t *port, jack_nframes_t frame)
@@ -194,10 +197,10 @@ static double hdsp_get_hardware_power (jack_port_t *port, jack_nframes_t frame)
static void
hdsp_release (jack_hardware_t *hw)
{
- hdsp_t *h = (hdsp_t *) hw->private;
+ hdsp_t *h = (hdsp_t*)hw->private;
if (h != 0) {
- free (h);
+ free (h);
}
}
@@ -209,7 +212,7 @@ jack_alsa_hdsp_hw_new (alsa_driver_t *driver)
jack_hardware_t *hw;
hdsp_t *h;
- hw = (jack_hardware_t *) malloc (sizeof (jack_hardware_t));
+ hw = (jack_hardware_t*)malloc (sizeof(jack_hardware_t));
/* Not using clock lock-sync-whatever in home hardware setup */
/* yet. Will write this code when can test it. */
@@ -223,8 +226,8 @@ jack_alsa_hdsp_hw_new (alsa_driver_t *driver)
hw->release = hdsp_release;
hw->get_hardware_peak = hdsp_get_hardware_peak;
hw->get_hardware_power = hdsp_get_hardware_power;
-
- h = (hdsp_t *) malloc (sizeof (hdsp_t));
+
+ h = (hdsp_t*)malloc (sizeof(hdsp_t));
h->driver = driver;
hw->private = h;
diff --git a/drivers/alsa/hdsp.h b/drivers/alsa/hdsp.h
index cc2ad04..f62ac7d 100644
--- a/drivers/alsa/hdsp.h
+++ b/drivers/alsa/hdsp.h
@@ -1,6 +1,6 @@
/*
Copyright (C) 2001 Paul Davis
-
+
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
@@ -15,7 +15,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
+ */
#ifndef __jack_hdsp_h__
#define __jack_hdsp_h__
@@ -23,10 +23,10 @@
#include <sys/time.h>
typedef struct {
- alsa_driver_t *driver;
+ alsa_driver_t *driver;
} hdsp_t;
jack_hardware_t *
-jack_alsa_hdsp_hw_new (alsa_driver_t *driver);
+jack_alsa_hdsp_hw_new(alsa_driver_t *driver);
#endif /* __jack_hdsp_h__*/
diff --git a/drivers/alsa/ice1712.c b/drivers/alsa/ice1712.c
index 6c38364..9c96f96 100644
--- a/drivers/alsa/ice1712.c
+++ b/drivers/alsa/ice1712.c
@@ -1,7 +1,7 @@
/*
Copyright (C) 2002 Anthony Van Groningen
- Parts based on source code taken from the
+ Parts based on source code taken from the
"Env24 chipset (ICE1712) control utility" that is
Copyright (C) 2000 by Jaroslav Kysela <perex@suse.cz>
@@ -19,7 +19,7 @@
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 "hardware.h"
#include "alsa_driver.h"
@@ -27,13 +27,13 @@
#include "internal.h"
static int
-ice1712_hw_monitor_toggle(jack_hardware_t *hw, int idx, int onoff)
+ice1712_hw_monitor_toggle (jack_hardware_t *hw, int idx, int onoff)
{
- ice1712_t *h = (ice1712_t *) hw->private;
+ ice1712_t *h = (ice1712_t*)hw->private;
snd_ctl_elem_value_t *val;
int err;
-
+
snd_ctl_elem_value_alloca (&val);
snd_ctl_elem_value_set_interface (val, SND_CTL_ELEM_IFACE_MIXER);
if (idx >= 8) {
@@ -50,33 +50,33 @@ ice1712_hw_monitor_toggle(jack_hardware_t *hw, int idx, int onoff)
}
if ((err = snd_ctl_elem_write (h->driver->ctl_handle, val)) != 0) {
jack_error ("ALSA/ICE1712: (%d) cannot set input monitoring (%s)",
- idx,snd_strerror (err));
+ idx, snd_strerror (err));
return -1;
}
return 0;
}
-static int
+static int
ice1712_set_input_monitor_mask (jack_hardware_t *hw, unsigned long mask)
-
+
{
int idx;
- ice1712_t *h = (ice1712_t *) hw->private;
-
+ ice1712_t *h = (ice1712_t*)hw->private;
+
for (idx = 0; idx < 10; idx++) {
- if (h->active_channels & (1<<idx)) {
- ice1712_hw_monitor_toggle (hw, idx, mask & (1<<idx) ? 1 : 0);
+ if (h->active_channels & (1 << idx)) {
+ ice1712_hw_monitor_toggle (hw, idx, mask & (1 << idx) ? 1 : 0);
}
}
hw->input_monitor_mask = mask;
-
+
return 0;
}
-static int
-ice1712_change_sample_clock (jack_hardware_t *hw, SampleClockMode mode)
-
+static int
+ice1712_change_sample_clock (jack_hardware_t *hw, SampleClockMode mode)
+
{
return -1;
}
@@ -84,15 +84,17 @@ ice1712_change_sample_clock (jack_hardware_t *hw, SampleClockMode mode)
static void
ice1712_release (jack_hardware_t *hw)
{
- ice1712_t *h = (ice1712_t *) hw->private;
-
- if (h == 0)
- return;
+ ice1712_t *h = (ice1712_t*)hw->private;
- if (h->eeprom)
- free(h->eeprom);
+ if (h == 0) {
+ return;
+ }
+
+ if (h->eeprom) {
+ free (h->eeprom);
+ }
- free(h);
+ free (h);
}
@@ -102,10 +104,10 @@ jack_alsa_ice1712_hw_new (alsa_driver_t *driver)
{
jack_hardware_t *hw;
ice1712_t *h;
- snd_ctl_elem_value_t *val;
+ snd_ctl_elem_value_t *val;
int err;
- hw = (jack_hardware_t *) malloc (sizeof (jack_hardware_t));
+ hw = (jack_hardware_t*)malloc (sizeof(jack_hardware_t));
hw->capabilities = Cap_HardwareMonitoring;
hw->input_monitor_mask = 0;
@@ -115,42 +117,42 @@ jack_alsa_ice1712_hw_new (alsa_driver_t *driver)
hw->change_sample_clock = ice1712_change_sample_clock;
hw->release = ice1712_release;
- h = (ice1712_t *) malloc (sizeof (ice1712_t));
+ h = (ice1712_t*)malloc (sizeof(ice1712_t));
h->driver = driver;
/* Get the EEPROM (adopted from envy24control) */
- h->eeprom = (ice1712_eeprom_t *) malloc (sizeof (ice1712_eeprom_t));
+ h->eeprom = (ice1712_eeprom_t*)malloc (sizeof(ice1712_eeprom_t));
snd_ctl_elem_value_alloca (&val);
snd_ctl_elem_value_set_interface (val, SND_CTL_ELEM_IFACE_CARD);
- snd_ctl_elem_value_set_name (val, "ICE1712 EEPROM");
- if ((err = snd_ctl_elem_read (driver->ctl_handle, val)) < 0) {
- jack_error( "ALSA/ICE1712: Unable to read EEPROM contents (%s)\n", snd_strerror (err));
- /* Recover? */
- }
- memcpy(h->eeprom, snd_ctl_elem_value_get_bytes(val), 32);
-
- /* determine number of pro ADC's. We're asumming that there is at least one stereo pair.
+ snd_ctl_elem_value_set_name (val, "ICE1712 EEPROM");
+ if ((err = snd_ctl_elem_read (driver->ctl_handle, val)) < 0) {
+ jack_error ( "ALSA/ICE1712: Unable to read EEPROM contents (%s)\n", snd_strerror (err));
+ /* Recover? */
+ }
+ memcpy (h->eeprom, snd_ctl_elem_value_get_bytes (val), 32);
+
+ /* determine number of pro ADC's. We're asumming that there is at least one stereo pair.
Should check this first, but how? */
- switch((h->eeprom->codec & 0xCU) >> 2) {
+ switch ((h->eeprom->codec & 0xCU) >> 2) {
case 0:
- h->active_channels = 0x3U;
- break;
+ h->active_channels = 0x3U;
+ break;
case 1:
- h->active_channels = 0xfU;
- break;
+ h->active_channels = 0xfU;
+ break;
case 2:
- h->active_channels = 0x3fU;
- break;
+ h->active_channels = 0x3fU;
+ break;
case 3:
- h->active_channels = 0xffU;
- break;
+ h->active_channels = 0xffU;
+ break;
}
/* check for SPDIF In's */
if (h->eeprom->spdif & 0x1U) {
- h->active_channels |= 0x300U;
+ h->active_channels |= 0x300U;
}
-
+
hw->private = h;
return hw;
diff --git a/drivers/alsa/ice1712.h b/drivers/alsa/ice1712.h
index 8dab29f..f68df57 100644
--- a/drivers/alsa/ice1712.h
+++ b/drivers/alsa/ice1712.h
@@ -1,11 +1,11 @@
/*
Copyright (C) 2002 Anthony Van Groningen
- Parts based on source code taken from the
+ Parts based on source code taken from the
"Env24 chipset (ICE1712) control utility" that is
Copyright (C) 2000 by Jaroslav Kysela <perex@suse.cz>
-
+
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
@@ -20,7 +20,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
+ */
#ifndef __jack_ice1712_h__
#define __jack_ice1712_h__
@@ -36,31 +36,31 @@
#define MULTITRACK_PEAK_NAME "Multi Track Peak"
typedef struct {
- unsigned int subvendor; /* PCI[2c-2f] */
- unsigned char size; /* size of EEPROM image in bytes */
- unsigned char version; /* must be 1 */
- unsigned char codec; /* codec configuration PCI[60] */
- unsigned char aclink; /* ACLink configuration PCI[61] */
- unsigned char i2sID; /* PCI[62] */
- unsigned char spdif; /* S/PDIF configuration PCI[63] */
- unsigned char gpiomask; /* GPIO initial mask, 0 = write, 1 = don't */
- unsigned char gpiostate; /* GPIO initial state */
- unsigned char gpiodir; /* GPIO direction state */
- unsigned short ac97main;
- unsigned short ac97pcm;
- unsigned short ac97rec;
- unsigned char ac97recsrc;
- unsigned char dacID[4]; /* I2S IDs for DACs */
- unsigned char adcID[4]; /* I2S IDs for ADCs */
- unsigned char extra[4];
+ unsigned int subvendor; /* PCI[2c-2f] */
+ unsigned char size; /* size of EEPROM image in bytes */
+ unsigned char version; /* must be 1 */
+ unsigned char codec; /* codec configuration PCI[60] */
+ unsigned char aclink; /* ACLink configuration PCI[61] */
+ unsigned char i2sID; /* PCI[62] */
+ unsigned char spdif; /* S/PDIF configuration PCI[63] */
+ unsigned char gpiomask; /* GPIO initial mask, 0 = write, 1 = don't */
+ unsigned char gpiostate; /* GPIO initial state */
+ unsigned char gpiodir; /* GPIO direction state */
+ unsigned short ac97main;
+ unsigned short ac97pcm;
+ unsigned short ac97rec;
+ unsigned char ac97recsrc;
+ unsigned char dacID[4]; /* I2S IDs for DACs */
+ unsigned char adcID[4]; /* I2S IDs for ADCs */
+ unsigned char extra[4];
} ice1712_eeprom_t;
typedef struct {
- alsa_driver_t *driver;
- ice1712_eeprom_t *eeprom;
- unsigned long active_channels;
+ alsa_driver_t *driver;
+ ice1712_eeprom_t *eeprom;
+ unsigned long active_channels;
} ice1712_t;
-jack_hardware_t *jack_alsa_ice1712_hw_new (alsa_driver_t *driver);
+jack_hardware_t *jack_alsa_ice1712_hw_new(alsa_driver_t *driver);
#endif /* __jack_ice1712_h__*/
diff --git a/drivers/alsa/memops.c b/drivers/alsa/memops.c
index 090d7f4..24fd67b 100644
--- a/drivers/alsa/memops.c
+++ b/drivers/alsa/memops.c
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2000 Paul Davis
+ Copyright (C) 2000 Paul Davis
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
@@ -15,7 +15,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
+ */
#define _ISOC9X_SOURCE 1
#define _ISOC99_SOURCE 1
@@ -39,7 +39,7 @@
the MAX_<N>BIT values are floating point. when multiplied by
a full-scale normalized floating point sample value (-1.0..+1.0)
they should give the maxium value representable with an integer
- sample type of N bits. Note that this is asymmetric. Sample ranges
+ sample type of N bits. Note that this is asymmetric. Sample ranges
for signed integer, 2's complement values are -(2^(N-1) to +(2^(N-1)-1)
Complications
@@ -59,20 +59,20 @@
use the right factor).
So, for now (October 2008) we use 2^(N-1)-1 as the scaling factor.
-*/
+ */
#define SAMPLE_24BIT_SCALING 8388607.0f
#define SAMPLE_16BIT_SCALING 32767.0f
/* these are just values to use if the floating point value was out of range
-
+
advice from Fons Adriaensen: make the limits symmetrical
*/
-#define SAMPLE_24BIT_MAX 8388607
-#define SAMPLE_24BIT_MIN -8388607
-#define SAMPLE_24BIT_MAX_F 8388607.0f
-#define SAMPLE_24BIT_MIN_F -8388607.0f
+#define SAMPLE_24BIT_MAX 8388607
+#define SAMPLE_24BIT_MIN -8388607
+#define SAMPLE_24BIT_MAX_F 8388607.0f
+#define SAMPLE_24BIT_MIN_F -8388607.0f
#define SAMPLE_16BIT_MAX 32767
#define SAMPLE_16BIT_MIN -32767
@@ -80,91 +80,93 @@
#define SAMPLE_16BIT_MIN_F -32767.0f
/* these mark the outer edges of the range considered "within" range
- for a floating point sample value. values outside (and on the boundaries)
- of this range will be clipped before conversion; values within this
+ for a floating point sample value. values outside (and on the boundaries)
+ of this range will be clipped before conversion; values within this
range will be scaled to appropriate values for the target sample
type.
-*/
+ */
#define NORMALIZED_FLOAT_MIN -1.0f
#define NORMALIZED_FLOAT_MAX 1.0f
/* define this in case we end up on a platform that is missing
the real lrintf functions
-*/
+ */
-#define f_round(f) lrintf(f)
+#define f_round(f) lrintf (f)
-#define float_16(s, d)\
- if ((s) <= NORMALIZED_FLOAT_MIN) {\
- (d) = SAMPLE_16BIT_MIN;\
- } else if ((s) >= NORMALIZED_FLOAT_MAX) {\
- (d) = SAMPLE_16BIT_MAX;\
- } else {\
- (d) = f_round ((s) * SAMPLE_16BIT_SCALING);\
+#define float_16(s, d) \
+ if ((s) <= NORMALIZED_FLOAT_MIN) { \
+ (d) = SAMPLE_16BIT_MIN; \
+ } else if ((s) >= NORMALIZED_FLOAT_MAX) { \
+ (d) = SAMPLE_16BIT_MAX; \
+ } else { \
+ (d) = f_round ((s) * SAMPLE_16BIT_SCALING); \
}
/* call this when "s" has already been scaled (e.g. when dithering)
*/
-#define float_16_scaled(s, d)\
- if ((s) <= SAMPLE_16BIT_MIN_F) {\
- (d) = SAMPLE_16BIT_MIN_F;\
+#define float_16_scaled(s, d) \
+ if ((s) <= SAMPLE_16BIT_MIN_F) { \
+ (d) = SAMPLE_16BIT_MIN_F; \
} else if ((s) >= SAMPLE_16BIT_MAX_F) { \
- (d) = SAMPLE_16BIT_MAX;\
- } else {\
- (d) = f_round ((s));\
+ (d) = SAMPLE_16BIT_MAX; \
+ } else { \
+ (d) = f_round ((s)); \
}
#define float_24u32(s, d) \
- if ((s) <= NORMALIZED_FLOAT_MIN) {\
- (d) = SAMPLE_24BIT_MIN << 8;\
- } else if ((s) >= NORMALIZED_FLOAT_MAX) {\
- (d) = SAMPLE_24BIT_MAX << 8;\
- } else {\
- (d) = f_round ((s) * SAMPLE_24BIT_SCALING) << 8;\
+ if ((s) <= NORMALIZED_FLOAT_MIN) { \
+ (d) = SAMPLE_24BIT_MIN << 8; \
+ } else if ((s) >= NORMALIZED_FLOAT_MAX) { \
+ (d) = SAMPLE_24BIT_MAX << 8; \
+ } else { \
+ (d) = f_round ((s) * SAMPLE_24BIT_SCALING) << 8; \
}
/* call this when "s" has already been scaled (e.g. when dithering)
*/
-#define float_24u32_scaled(s, d)\
- if ((s) <= SAMPLE_24BIT_MIN_F) {\
- (d) = SAMPLE_24BIT_MIN << 8;\
+#define float_24u32_scaled(s, d) \
+ if ((s) <= SAMPLE_24BIT_MIN_F) { \
+ (d) = SAMPLE_24BIT_MIN << 8; \
} else if ((s) >= SAMPLE_24BIT_MAX_F) { \
(d) = SAMPLE_24BIT_MAX << 8; \
- } else {\
+ } else { \
(d) = f_round ((s)) << 8; \
}
#define float_24(s, d) \
- if ((s) <= NORMALIZED_FLOAT_MIN) {\
- (d) = SAMPLE_24BIT_MIN;\
- } else if ((s) >= NORMALIZED_FLOAT_MAX) {\
- (d) = SAMPLE_24BIT_MAX;\
- } else {\
- (d) = f_round ((s) * SAMPLE_24BIT_SCALING);\
+ if ((s) <= NORMALIZED_FLOAT_MIN) { \
+ (d) = SAMPLE_24BIT_MIN; \
+ } else if ((s) >= NORMALIZED_FLOAT_MAX) { \
+ (d) = SAMPLE_24BIT_MAX; \
+ } else { \
+ (d) = f_round ((s) * SAMPLE_24BIT_SCALING); \
}
/* call this when "s" has already been scaled (e.g. when dithering)
*/
-#define float_24_scaled(s, d)\
- if ((s) <= SAMPLE_24BIT_MIN_F) {\
- (d) = SAMPLE_24BIT_MIN;\
+#define float_24_scaled(s, d) \
+ if ((s) <= SAMPLE_24BIT_MIN_F) { \
+ (d) = SAMPLE_24BIT_MIN; \
} else if ((s) >= SAMPLE_24BIT_MAX_F) { \
(d) = SAMPLE_24BIT_MAX; \
- } else {\
+ } else { \
(d) = f_round ((s)); \
}
/* Linear Congruential noise generator. From the music-dsp list
- * less random than rand(), but good enough and 10x faster
+ * less random than rand(), but good enough and 10x faster
*/
-static inline unsigned int fast_rand() {
+static inline unsigned int fast_rand ()
+{
static unsigned int seed = 22222;
+
seed = (seed * 96314165) + 907633515;
return seed;
@@ -173,17 +175,19 @@ static inline unsigned int fast_rand() {
/* functions for native float sample data */
-void sample_move_floatLE_sSs (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip) {
+void sample_move_floatLE_sSs (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip)
+{
while (nsamples--) {
- *dst = *((float *) src);
+ *dst = *((float*)src);
dst++;
src += src_skip;
}
}
-void sample_move_dS_floatLE (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state) {
+void sample_move_dS_floatLE (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
+{
while (nsamples--) {
- *((float *) dst) = *src;
+ *((float*)dst) = *src;
dst += dst_skip;
src++;
}
@@ -197,7 +201,7 @@ void sample_move_dS_floatLE (char *dst, jack_default_audio_sample_t *src, unsign
the "s<TYPE>" component defines the source type for the operation
TYPE can be one of:
-
+
S - sample is a jack_default_audio_sample_t, currently (October 2008) a 32 bit floating point value
Ss - like S but reverse endian from the host CPU
32u24 - sample is an signed 32 bit integer value, but data is in upper 24 bits only
@@ -210,7 +214,7 @@ void sample_move_dS_floatLE (char *dst, jack_default_audio_sample_t *src, unsign
For obvious reasons, the reverse endian versions only show as source types.
This covers all known sample formats at 16 bits or larger.
-*/
+ */
/* functions for native integer sample data */
@@ -224,29 +228,29 @@ void sample_move_d32u24_sSs (char *dst, jack_default_audio_sample_t *src, unsign
#if __BYTE_ORDER == __LITTLE_ENDIAN
- dst[0]=(char)(z>>24);
- dst[1]=(char)(z>>16);
- dst[2]=(char)(z>>8);
- dst[3]=(char)(z);
+ dst[0] = (char)(z >> 24);
+ dst[1] = (char)(z >> 16);
+ dst[2] = (char)(z >> 8);
+ dst[3] = (char)(z);
#elif __BYTE_ORDER == __BIG_ENDIAN
- dst[0]=(char)(z);
- dst[1]=(char)(z>>8);
- dst[2]=(char)(z>>16);
- dst[3]=(char)(z>>24);
+ dst[0] = (char)(z);
+ dst[1] = (char)(z >> 8);
+ dst[2] = (char)(z >> 16);
+ dst[3] = (char)(z >> 24);
#endif
dst += dst_skip;
src++;
}
-}
+}
void sample_move_d32u24_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
{
while (nsamples--) {
- float_24u32 (*src, *((int32_t*) dst));
+ float_24u32 (*src, *((int32_t*)dst));
dst += dst_skip;
src++;
}
-}
+}
void sample_move_dS_s32u24s (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip)
{
@@ -275,18 +279,18 @@ void sample_move_dS_s32u24s (jack_default_audio_sample_t *dst, char *src, unsign
dst++;
src += src_skip;
}
-}
+}
void sample_move_dS_s32u24 (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip)
{
/* ALERT: signed sign-extension portability !!! */
while (nsamples--) {
- *dst = (*((int *) src) >> 8) / SAMPLE_24BIT_SCALING;
+ *dst = (*((int*)src) >> 8) / SAMPLE_24BIT_SCALING;
dst++;
src += src_skip;
}
-}
+}
void sample_move_d24_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
{
@@ -295,34 +299,34 @@ void sample_move_d24_sSs (char *dst, jack_default_audio_sample_t *src, unsigned
while (nsamples--) {
float_24 (*src, z);
#if __BYTE_ORDER == __LITTLE_ENDIAN
- dst[0]=(char)(z>>16);
- dst[1]=(char)(z>>8);
- dst[2]=(char)(z);
+ dst[0] = (char)(z >> 16);
+ dst[1] = (char)(z >> 8);
+ dst[2] = (char)(z);
#elif __BYTE_ORDER == __BIG_ENDIAN
- dst[0]=(char)(z);
- dst[1]=(char)(z>>8);
- dst[2]=(char)(z>>16);
+ dst[0] = (char)(z);
+ dst[1] = (char)(z >> 8);
+ dst[2] = (char)(z >> 16);
#endif
dst += dst_skip;
src++;
}
-}
+}
void sample_move_d24_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
{
- int32_t z;
-
+ int32_t z;
+
while (nsamples--) {
float_24 (*src, z);
#if __BYTE_ORDER == __LITTLE_ENDIAN
memcpy (dst, &z, 3);
#elif __BYTE_ORDER == __BIG_ENDIAN
- memcpy (dst, (char *)&z + 1, 3);
+ memcpy (dst, (char*)&z + 1, 3);
#endif
dst += dst_skip;
src++;
}
-}
+}
void sample_move_dS_s24s (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip)
{
@@ -355,7 +359,7 @@ void sample_move_dS_s24s (jack_default_audio_sample_t *dst, char *src, unsigned
dst++;
src += src_skip;
}
-}
+}
void sample_move_dS_s24 (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip)
{
@@ -364,19 +368,19 @@ void sample_move_dS_s24 (jack_default_audio_sample_t *dst, char *src, unsigned l
while (nsamples--) {
int x;
#if __BYTE_ORDER == __LITTLE_ENDIAN
- memcpy((char*)&x + 1, src, 3);
+ memcpy ((char*)&x + 1, src, 3);
#elif __BYTE_ORDER == __BIG_ENDIAN
- memcpy(&x, src, 3);
+ memcpy (&x, src, 3);
#endif
x >>= 8;
*dst = x / SAMPLE_24BIT_SCALING;
dst++;
src += src_skip;
}
-}
+}
-void sample_move_d16_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
+void sample_move_d16_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
{
int16_t tmp;
@@ -388,108 +392,108 @@ void sample_move_d16_sSs (char *dst, jack_default_audio_sample_t *src, unsigned
} else if (*src >= NORMALIZED_FLOAT_MAX) {
tmp = SAMPLE_16BIT_MAX;
} else {
- tmp = (int16_t) f_round (*src * SAMPLE_16BIT_SCALING);
+ tmp = (int16_t)f_round (*src * SAMPLE_16BIT_SCALING);
}
#if __BYTE_ORDER == __LITTLE_ENDIAN
- dst[0]=(char)(tmp>>8);
- dst[1]=(char)(tmp);
+ dst[0] = (char)(tmp >> 8);
+ dst[1] = (char)(tmp);
#elif __BYTE_ORDER == __BIG_ENDIAN
- dst[0]=(char)(tmp);
- dst[1]=(char)(tmp>>8);
+ dst[0] = (char)(tmp);
+ dst[1] = (char)(tmp >> 8);
#endif
dst += dst_skip;
src++;
}
}
-void sample_move_d16_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
+void sample_move_d16_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
{
while (nsamples--) {
- float_16 (*src, *((int16_t*) dst));
+ float_16 (*src, *((int16_t*)dst));
dst += dst_skip;
src++;
}
}
-void sample_move_dither_rect_d16_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
+void sample_move_dither_rect_d16_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
{
jack_default_audio_sample_t val;
- int16_t tmp;
+ int16_t tmp;
while (nsamples--) {
- val = (*src * SAMPLE_16BIT_SCALING) + fast_rand() / (float) UINT_MAX - 0.5f;
+ val = (*src * SAMPLE_16BIT_SCALING) + fast_rand () / (float)UINT_MAX - 0.5f;
float_16_scaled (val, tmp);
#if __BYTE_ORDER == __LITTLE_ENDIAN
- dst[0]=(char)(tmp>>8);
- dst[1]=(char)(tmp);
+ dst[0] = (char)(tmp >> 8);
+ dst[1] = (char)(tmp);
#elif __BYTE_ORDER == __BIG_ENDIAN
- dst[0]=(char)(tmp);
- dst[1]=(char)(tmp>>8);
+ dst[0] = (char)(tmp);
+ dst[1] = (char)(tmp >> 8);
#endif
dst += dst_skip;
src++;
}
}
-void sample_move_dither_rect_d16_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
+void sample_move_dither_rect_d16_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
{
jack_default_audio_sample_t val;
while (nsamples--) {
- val = (*src * SAMPLE_16BIT_SCALING) + fast_rand() / (float)UINT_MAX - 0.5f;
- float_16_scaled (val, *((int16_t*) dst));
+ val = (*src * SAMPLE_16BIT_SCALING) + fast_rand () / (float)UINT_MAX - 0.5f;
+ float_16_scaled (val, *((int16_t*)dst));
dst += dst_skip;
src++;
}
}
-void sample_move_dither_tri_d16_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
+void sample_move_dither_tri_d16_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
{
jack_default_audio_sample_t val;
- int16_t tmp;
+ int16_t tmp;
while (nsamples--) {
- val = (*src * SAMPLE_16BIT_SCALING) + ((float)fast_rand() + (float)fast_rand()) / (float)UINT_MAX - 1.0f;
+ val = (*src * SAMPLE_16BIT_SCALING) + ((float)fast_rand () + (float)fast_rand ()) / (float)UINT_MAX - 1.0f;
float_16_scaled (val, tmp);
#if __BYTE_ORDER == __LITTLE_ENDIAN
- dst[0]=(char)(tmp>>8);
- dst[1]=(char)(tmp);
+ dst[0] = (char)(tmp >> 8);
+ dst[1] = (char)(tmp);
#elif __BYTE_ORDER == __BIG_ENDIAN
- dst[0]=(char)(tmp);
- dst[1]=(char)(tmp>>8);
+ dst[0] = (char)(tmp);
+ dst[1] = (char)(tmp >> 8);
#endif
dst += dst_skip;
src++;
}
}
-void sample_move_dither_tri_d16_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
+void sample_move_dither_tri_d16_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
{
jack_default_audio_sample_t val;
while (nsamples--) {
- val = (*src * SAMPLE_16BIT_SCALING) + ((float)fast_rand() + (float)fast_rand()) / (float)UINT_MAX - 1.0f;
- float_16_scaled (val, *((int16_t*) dst));
+ val = (*src * SAMPLE_16BIT_SCALING) + ((float)fast_rand () + (float)fast_rand ()) / (float)UINT_MAX - 1.0f;
+ float_16_scaled (val, *((int16_t*)dst));
dst += dst_skip;
src++;
}
}
-void sample_move_dither_shaped_d16_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
+void sample_move_dither_shaped_d16_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
{
- jack_default_audio_sample_t x;
- jack_default_audio_sample_t xe; /* the innput sample - filtered error */
- jack_default_audio_sample_t xp; /* x' */
- float r;
- float rm1 = state->rm1;
+ jack_default_audio_sample_t x;
+ jack_default_audio_sample_t xe; /* the innput sample - filtered error */
+ jack_default_audio_sample_t xp; /* x' */
+ float r;
+ float rm1 = state->rm1;
unsigned int idx = state->idx;
- int16_t tmp;
+ int16_t tmp;
while (nsamples--) {
x = *src * SAMPLE_16BIT_SCALING;
- r = ((float)fast_rand() + (float)fast_rand()) / (float)UINT_MAX - 1.0f;
+ r = ((float)fast_rand () + (float)fast_rand ()) / (float)UINT_MAX - 1.0f;
/* Filter the error with Lipshitz's minimally audible FIR:
[2.033 -2.165 1.959 -1.590 0.6149] */
xe = x
@@ -508,11 +512,11 @@ void sample_move_dither_shaped_d16_sSs (char *dst, jack_default_audio_sample_t
state->e[idx] = xp - xe;
#if __BYTE_ORDER == __LITTLE_ENDIAN
- dst[0]=(char)(tmp>>8);
- dst[1]=(char)(tmp);
+ dst[0] = (char)(tmp >> 8);
+ dst[1] = (char)(tmp);
#elif __BYTE_ORDER == __BIG_ENDIAN
- dst[0]=(char)(tmp);
- dst[1]=(char)(tmp>>8);
+ dst[0] = (char)(tmp);
+ dst[1] = (char)(tmp >> 8);
#endif
dst += dst_skip;
src++;
@@ -521,18 +525,18 @@ void sample_move_dither_shaped_d16_sSs (char *dst, jack_default_audio_sample_t
state->idx = idx;
}
-void sample_move_dither_shaped_d16_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
+void sample_move_dither_shaped_d16_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state)
{
- jack_default_audio_sample_t x;
- jack_default_audio_sample_t xe; /* the innput sample - filtered error */
- jack_default_audio_sample_t xp; /* x' */
- float r;
- float rm1 = state->rm1;
+ jack_default_audio_sample_t x;
+ jack_default_audio_sample_t xe; /* the innput sample - filtered error */
+ jack_default_audio_sample_t xp; /* x' */
+ float r;
+ float rm1 = state->rm1;
unsigned int idx = state->idx;
while (nsamples--) {
x = *src * SAMPLE_16BIT_SCALING;
- r = ((float)fast_rand() + (float)fast_rand()) / (float)UINT_MAX - 1.0f;
+ r = ((float)fast_rand () + (float)fast_rand ()) / (float)UINT_MAX - 1.0f;
/* Filter the error with Lipshitz's minimally audible FIR:
[2.033 -2.165 1.959 -1.590 0.6149] */
xe = x
@@ -544,11 +548,11 @@ void sample_move_dither_shaped_d16_sS (char *dst, jack_default_audio_sample_t *
xp = xe + r - rm1;
rm1 = r;
- float_16_scaled (xp, *((int16_t*) dst));
+ float_16_scaled (xp, *((int16_t*)dst));
/* Intrinsic z^-1 delay */
idx = (idx + 1) & DITHER_BUF_MASK;
- state->e[idx] = *((int16_t*) dst) - xe;
+ state->e[idx] = *((int16_t*)dst) - xe;
dst += dst_skip;
src++;
@@ -557,7 +561,7 @@ void sample_move_dither_shaped_d16_sS (char *dst, jack_default_audio_sample_t *
state->idx = idx;
}
-void sample_move_dS_s16s (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip)
+void sample_move_dS_s16s (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip)
{
short z;
@@ -576,22 +580,22 @@ void sample_move_dS_s16s (jack_default_audio_sample_t *dst, char *src, unsigned
dst++;
src += src_skip;
}
-}
+}
+
+void sample_move_dS_s16 (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip)
-void sample_move_dS_s16 (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip)
-
{
/* ALERT: signed sign-extension portability !!! */
while (nsamples--) {
- *dst = (*((short *) src)) / SAMPLE_16BIT_SCALING;
+ *dst = (*((short*)src)) / SAMPLE_16BIT_SCALING;
dst++;
src += src_skip;
}
-}
+}
-void memset_interleave (char *dst, char val, unsigned long bytes,
- unsigned long unit_bytes,
- unsigned long skip_bytes)
+void memset_interleave (char *dst, char val, unsigned long bytes,
+ unsigned long unit_bytes,
+ unsigned long skip_bytes)
{
switch (unit_bytes) {
case 1:
@@ -602,21 +606,21 @@ void memset_interleave (char *dst, char val, unsigned long bytes,
break;
case 2:
while (bytes) {
- *((short *) dst) = (short) val;
+ *((short*)dst) = (short)val;
dst += skip_bytes;
bytes -= 2;
}
break;
- case 4:
+ case 4:
while (bytes) {
- *((int *) dst) = (int) val;
+ *((int*)dst) = (int)val;
dst += skip_bytes;
bytes -= 4;
}
break;
default:
while (bytes) {
- memset(dst, val, unit_bytes);
+ memset (dst, val, unit_bytes);
dst += skip_bytes;
bytes -= unit_bytes;
}
@@ -629,46 +633,46 @@ void memset_interleave (char *dst, char val, unsigned long bytes,
is the same for both channels. This is completely fine
unless the input and output were on different audio interfaces that
were interleaved differently. We don't try to handle that.
-*/
+ */
-void
+void
memcpy_fake (char *dst, char *src, unsigned long src_bytes, unsigned long foo, unsigned long bar)
{
memcpy (dst, src, src_bytes);
}
-void
+void
memcpy_interleave_d16_s16 (char *dst, char *src, unsigned long src_bytes,
unsigned long dst_skip_bytes, unsigned long src_skip_bytes)
{
while (src_bytes) {
- *((short *) dst) = *((short *) src);
+ *((short*)dst) = *((short*)src);
dst += dst_skip_bytes;
src += src_skip_bytes;
src_bytes -= 2;
}
}
-void
+void
memcpy_interleave_d24_s24 (char *dst, char *src, unsigned long src_bytes,
unsigned long dst_skip_bytes, unsigned long src_skip_bytes)
{
while (src_bytes) {
- memcpy(dst, src, 3);
+ memcpy (dst, src, 3);
dst += dst_skip_bytes;
src += src_skip_bytes;
src_bytes -= 3;
}
}
-void
+void
memcpy_interleave_d32_s32 (char *dst, char *src, unsigned long src_bytes,
unsigned long dst_skip_bytes, unsigned long src_skip_bytes)
{
while (src_bytes) {
- *((int *) dst) = *((int *) src);
+ *((int*)dst) = *((int*)src);
dst += dst_skip_bytes;
src += src_skip_bytes;
src_bytes -= 4;
diff --git a/drivers/alsa/usx2y.c b/drivers/alsa/usx2y.c
index 23efeb3..b0a6d12 100644
--- a/drivers/alsa/usx2y.c
+++ b/drivers/alsa/usx2y.c
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2001 Paul Davis
+ Copyright (C) 2001 Paul Davis
Copyright (C) 2005 Karsten Wiese, Rui Nuno Capela
This program is free software; you can redistribute it and/or modify
@@ -16,7 +16,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
+ */
#include "hardware.h"
#include "alsa_driver.h"
@@ -36,14 +36,14 @@
int dbg_offset;
char dbg_buffer[8096];
#endif
-static
+static
int usx2y_set_input_monitor_mask (jack_hardware_t *hw, unsigned long mask)
{
return -1;
}
static
-int usx2y_change_sample_clock (jack_hardware_t *hw, SampleClockMode mode)
+int usx2y_change_sample_clock (jack_hardware_t *hw, SampleClockMode mode)
{
return -1;
}
@@ -51,78 +51,85 @@ int usx2y_change_sample_clock (jack_hardware_t *hw, SampleClockMode mode)
static void
usx2y_release (jack_hardware_t *hw)
{
- usx2y_t *h = (usx2y_t *) hw->private;
+ usx2y_t *h = (usx2y_t*)hw->private;
- if (h == 0)
+ if (h == 0) {
return;
-
- if (h->hwdep_handle)
- snd_hwdep_close(h->hwdep_handle);
+ }
+
+ if (h->hwdep_handle) {
+ snd_hwdep_close (h->hwdep_handle);
+ }
- free(h);
+ free (h);
}
static int
usx2y_driver_get_channel_addresses_playback (alsa_driver_t *driver,
- snd_pcm_uframes_t *playback_avail)
+ snd_pcm_uframes_t *playback_avail)
{
channel_t chn;
int iso;
snd_pcm_uframes_t playback_iso_avail;
char *playback;
- usx2y_t *h = (usx2y_t *) driver->hw->private;
+ usx2y_t *h = (usx2y_t*)driver->hw->private;
if (0 > h->playback_iso_start) {
int bytes = driver->playback_sample_bytes * 2 * driver->frames_per_cycle *
- driver->user_nperiods;
+ driver->user_nperiods;
iso = h->hwdep_pcm_shm->playback_iso_start;
- if (0 > iso)
+ if (0 > iso) {
return 0; /* FIXME: return -1; */
- if (++iso >= ARRAY_SIZE(h->hwdep_pcm_shm->captured_iso))
+ }
+ if (++iso >= ARRAY_SIZE (h->hwdep_pcm_shm->captured_iso)) {
iso = 0;
- while((bytes -= h->hwdep_pcm_shm->captured_iso[iso].length) > 0)
- if (++iso >= ARRAY_SIZE(h->hwdep_pcm_shm->captured_iso))
+ }
+ while ((bytes -= h->hwdep_pcm_shm->captured_iso[iso].length) > 0)
+ if (++iso >= ARRAY_SIZE (h->hwdep_pcm_shm->captured_iso)) {
iso = 0;
+ }
h->playback_iso_bytes_done = h->hwdep_pcm_shm->captured_iso[iso].length + bytes;
#ifdef DBGHWDEP
- dbg_offset = sprintf(dbg_buffer, "first iso = %i %i@%p:%i\n",
- iso, h->hwdep_pcm_shm->captured_iso[iso].length,
- h->hwdep_pcm_shm->playback,
- h->hwdep_pcm_shm->captured_iso[iso].offset);
+ dbg_offset = sprintf (dbg_buffer, "first iso = %i %i@%p:%i\n",
+ iso, h->hwdep_pcm_shm->captured_iso[iso].length,
+ h->hwdep_pcm_shm->playback,
+ h->hwdep_pcm_shm->captured_iso[iso].offset);
#endif
} else {
iso = h->playback_iso_start;
}
#ifdef DBGHWDEP
- dbg_offset += sprintf(dbg_buffer + dbg_offset, "iso = %i(%i;%i); ", iso,
- h->hwdep_pcm_shm->captured_iso[iso].offset,
- h->hwdep_pcm_shm->captured_iso[iso].frame);
+ dbg_offset += sprintf (dbg_buffer + dbg_offset, "iso = %i(%i;%i); ", iso,
+ h->hwdep_pcm_shm->captured_iso[iso].offset,
+ h->hwdep_pcm_shm->captured_iso[iso].frame);
#endif
playback = h->hwdep_pcm_shm->playback +
- h->hwdep_pcm_shm->captured_iso[iso].offset +
- h->playback_iso_bytes_done;
+ h->hwdep_pcm_shm->captured_iso[iso].offset +
+ h->playback_iso_bytes_done;
playback_iso_avail = (h->hwdep_pcm_shm->captured_iso[iso].length -
- h->playback_iso_bytes_done) /
- (driver->playback_sample_bytes * 2);
+ h->playback_iso_bytes_done) /
+ (driver->playback_sample_bytes * 2);
if (*playback_avail >= playback_iso_avail) {
*playback_avail = playback_iso_avail;
- if (++iso >= ARRAY_SIZE(h->hwdep_pcm_shm->captured_iso))
+ if (++iso >= ARRAY_SIZE (h->hwdep_pcm_shm->captured_iso)) {
iso = 0;
+ }
h->playback_iso_bytes_done = 0;
- } else
+ } else {
h->playback_iso_bytes_done =
*playback_avail * (driver->playback_sample_bytes * 2);
+ }
h->playback_iso_start = iso;
for (chn = 0; chn < driver->playback_nchannels; chn++) {
const snd_pcm_channel_area_t *a = &driver->playback_areas[chn];
driver->playback_addr[chn] = playback + a->first / 8;
}
#ifdef DBGHWDEP
- if (dbg_offset < (sizeof(dbg_buffer) - 256))
- dbg_offset += sprintf(dbg_buffer + dbg_offset, "avail %li@%p\n", *playback_avail, driver->playback_addr[0]);
- else {
- printf(dbg_buffer);
+ if (dbg_offset < (sizeof(dbg_buffer) - 256)) {
+ dbg_offset += sprintf (dbg_buffer + dbg_offset, "avail %li@%p\n", *playback_avail, driver->playback_addr[0]);
+ } else {
+ printf (dbg_buffer);
return -1;
}
#endif
@@ -132,48 +139,51 @@ usx2y_driver_get_channel_addresses_playback (alsa_driver_t *driver,
static int
usx2y_driver_get_channel_addresses_capture (alsa_driver_t *driver,
- snd_pcm_uframes_t *capture_avail)
+ snd_pcm_uframes_t *capture_avail)
{
channel_t chn;
int iso;
snd_pcm_uframes_t capture_iso_avail;
int capture_offset;
- usx2y_t *h = (usx2y_t *) driver->hw->private;
+ usx2y_t *h = (usx2y_t*)driver->hw->private;
if (0 > h->capture_iso_start) {
iso = h->hwdep_pcm_shm->capture_iso_start;
- if (0 > iso)
+ if (0 > iso) {
return 0; /* FIXME: return -1; */
+ }
h->capture_iso_bytes_done = 0;
#ifdef DBGHWDEP
- dbg_offset = sprintf(dbg_buffer, "cfirst iso = %i %i@%p:%i\n",
- iso, h->hwdep_pcm_shm->captured_iso[iso].length,
- h->hwdep_pcm_shm->capture0x8,
- h->hwdep_pcm_shm->captured_iso[iso].offset);
+ dbg_offset = sprintf (dbg_buffer, "cfirst iso = %i %i@%p:%i\n",
+ iso, h->hwdep_pcm_shm->captured_iso[iso].length,
+ h->hwdep_pcm_shm->capture0x8,
+ h->hwdep_pcm_shm->captured_iso[iso].offset);
#endif
} else {
iso = h->capture_iso_start;
}
#ifdef DBGHWDEP
- dbg_offset += sprintf(dbg_buffer + dbg_offset, "ciso = %i(%i;%i); ", iso,
- h->hwdep_pcm_shm->captured_iso[iso].offset,
- h->hwdep_pcm_shm->captured_iso[iso].frame);
+ dbg_offset += sprintf (dbg_buffer + dbg_offset, "ciso = %i(%i;%i); ", iso,
+ h->hwdep_pcm_shm->captured_iso[iso].offset,
+ h->hwdep_pcm_shm->captured_iso[iso].frame);
#endif
capture_offset =
h->hwdep_pcm_shm->captured_iso[iso].offset +
- h->capture_iso_bytes_done;
+ h->capture_iso_bytes_done;
capture_iso_avail = (h->hwdep_pcm_shm->captured_iso[iso].length -
- h->capture_iso_bytes_done) /
- (driver->capture_sample_bytes * 2);
+ h->capture_iso_bytes_done) /
+ (driver->capture_sample_bytes * 2);
if (*capture_avail >= capture_iso_avail) {
*capture_avail = capture_iso_avail;
- if (++iso >= ARRAY_SIZE(h->hwdep_pcm_shm->captured_iso))
+ if (++iso >= ARRAY_SIZE (h->hwdep_pcm_shm->captured_iso)) {
iso = 0;
+ }
h->capture_iso_bytes_done = 0;
- } else
+ } else {
h->capture_iso_bytes_done =
*capture_avail * (driver->capture_sample_bytes * 2);
+ }
h->capture_iso_start = iso;
for (chn = 0; chn < driver->capture_nchannels; chn++) {
driver->capture_addr[chn] =
@@ -182,21 +192,22 @@ usx2y_driver_get_channel_addresses_capture (alsa_driver_t *driver,
((chn & 1) ? driver->capture_sample_bytes : 0);
}
#ifdef DBGHWDEP
- {
- int f = 0;
- unsigned *u = driver->capture_addr[0];
- static unsigned last;
- dbg_offset += sprintf(dbg_buffer + dbg_offset, "\nvon %6u bis %6u\n", last, u[0]);
- while (f < *capture_avail && dbg_offset < (sizeof(dbg_buffer) - 256)) {
- if (u[f] != last + 1)
- dbg_offset += sprintf(dbg_buffer + dbg_offset, "\nooops %6u %6u\n", last, u[f]);
- last = u[f++];
- }
- }
- if (dbg_offset < (sizeof(dbg_buffer) - 256))
- dbg_offset += sprintf(dbg_buffer + dbg_offset, "avail %li@%p\n", *capture_avail, driver->capture_addr[0]);
- else {
- printf(dbg_buffer);
+ {
+ int f = 0;
+ unsigned *u = driver->capture_addr[0];
+ static unsigned last;
+ dbg_offset += sprintf (dbg_buffer + dbg_offset, "\nvon %6u bis %6u\n", last, u[0]);
+ while (f < *capture_avail && dbg_offset < (sizeof(dbg_buffer) - 256)) {
+ if (u[f] != last + 1) {
+ dbg_offset += sprintf (dbg_buffer + dbg_offset, "\nooops %6u %6u\n", last, u[f]);
+ }
+ last = u[f++];
+ }
+ }
+ if (dbg_offset < (sizeof(dbg_buffer) - 256)) {
+ dbg_offset += sprintf (dbg_buffer + dbg_offset, "avail %li@%p\n", *capture_avail, driver->capture_addr[0]);
+ } else {
+ printf (dbg_buffer);
return -1;
}
#endif
@@ -210,7 +221,7 @@ usx2y_driver_start (alsa_driver_t *driver)
int err, i;
snd_pcm_uframes_t poffset, pavail;
- usx2y_t *h = (usx2y_t *) driver->hw->private;
+ usx2y_t *h = (usx2y_t*)driver->hw->private;
for (i = 0; i < driver->capture_nchannels; i++)
// US428 channels 3+4 are on a seperate 2 channel stream.
@@ -225,40 +236,40 @@ usx2y_driver_start (alsa_driver_t *driver)
driver->poll_next = 0;
if ((err = snd_pcm_prepare (driver->playback_handle)) < 0) {
- jack_error ("ALSA/USX2Y: prepare error for playback: %s", snd_strerror(err));
+ jack_error ("ALSA/USX2Y: prepare error for playback: %s", snd_strerror (err));
return -1;
}
if (driver->playback_handle) {
-/* int i, j; */
-/* char buffer[2000]; */
+/* int i, j; */
+/* char buffer[2000]; */
h->playback_iso_start =
h->capture_iso_start = -1;
- snd_hwdep_poll_descriptors(h->hwdep_handle, &h->pfds, 1);
+ snd_hwdep_poll_descriptors (h->hwdep_handle, &h->pfds, 1);
h->hwdep_pcm_shm = (snd_usX2Y_hwdep_pcm_shm_t*)
- mmap(NULL, sizeof(snd_usX2Y_hwdep_pcm_shm_t),
- PROT_READ,
- MAP_SHARED, h->pfds.fd,
- 0);
+ mmap (NULL, sizeof(snd_usX2Y_hwdep_pcm_shm_t),
+ PROT_READ,
+ MAP_SHARED, h->pfds.fd,
+ 0);
if (MAP_FAILED == h->hwdep_pcm_shm) {
- perror("ALSA/USX2Y: mmap");
+ perror ("ALSA/USX2Y: mmap");
return -1;
}
- if (mprotect(h->hwdep_pcm_shm->playback,
- sizeof(h->hwdep_pcm_shm->playback),
- PROT_READ|PROT_WRITE)) {
- perror("ALSA/USX2Y: mprotect");
+ if (mprotect (h->hwdep_pcm_shm->playback,
+ sizeof(h->hwdep_pcm_shm->playback),
+ PROT_READ | PROT_WRITE)) {
+ perror ("ALSA/USX2Y: mprotect");
return -1;
}
- memset(h->hwdep_pcm_shm->playback, 0, sizeof(h->hwdep_pcm_shm->playback));
-/* for (i = 0, j = 0; i < 2000;) { */
-/* j += sprintf(buffer + j, "%04hX ", */
-/* *(unsigned short*)(h->hwdep_pcm_shm->capture + i)); */
-/* if (((i += 2) % 32) == 0) { */
-/* jack_error(buffer); */
-/* j = 0; */
-/* } */
-/* } */
+ memset (h->hwdep_pcm_shm->playback, 0, sizeof(h->hwdep_pcm_shm->playback));
+/* for (i = 0, j = 0; i < 2000;) { */
+/* j += sprintf(buffer + j, "%04hX ", */
+/* *(unsigned short*)(h->hwdep_pcm_shm->capture + i)); */
+/* if (((i += 2) % 32) == 0) { */
+/* jack_error(buffer); */
+/* j = 0; */
+/* } */
+/* } */
}
if (driver->hw_monitoring) {
@@ -269,7 +280,7 @@ usx2y_driver_start (alsa_driver_t *driver)
if (driver->playback_handle) {
/* fill playback buffer with zeroes, and mark
all fragments as having data.
- */
+ */
pavail = snd_pcm_avail_update (driver->playback_handle);
@@ -278,10 +289,10 @@ usx2y_driver_start (alsa_driver_t *driver)
return -1;
}
- if (snd_pcm_mmap_begin(
- driver->playback_handle,
- &driver->playback_areas,
- &poffset, &pavail) < 0) {
+ if (snd_pcm_mmap_begin (
+ driver->playback_handle,
+ &driver->playback_areas,
+ &poffset, &pavail) < 0) {
return -1;
}
@@ -292,22 +303,22 @@ usx2y_driver_start (alsa_driver_t *driver)
alsa-lib may have a better function for doing this
here, where the goal is to silence the entire
buffer.
- */
+ */
{
-/* snd_pcm_uframes_t frag, nframes = driver->buffer_frames; */
-/* while (nframes) { */
-/* frag = nframes; */
-/* if (usx2y_driver_get_channel_addresses_playback(driver, &frag) < 0) */
-/* return -1; */
-
-/* for (chn = 0; chn < driver->playback_nchannels; chn++) */
-/* alsa_driver_silence_on_channel (driver, chn, frag); */
-/* nframes -= frag; */
-/* } */
+/* snd_pcm_uframes_t frag, nframes = driver->buffer_frames; */
+/* while (nframes) { */
+/* frag = nframes; */
+/* if (usx2y_driver_get_channel_addresses_playback(driver, &frag) < 0) */
+/* return -1; */
+
+/* for (chn = 0; chn < driver->playback_nchannels; chn++) */
+/* alsa_driver_silence_on_channel (driver, chn, frag); */
+/* nframes -= frag; */
+/* } */
}
snd_pcm_mmap_commit (driver->playback_handle, poffset,
- driver->user_nperiods * driver->frames_per_cycle);
+ driver->user_nperiods * driver->frames_per_cycle);
if ((err = snd_pcm_start (driver->playback_handle)) < 0) {
jack_error ("ALSA/USX2Y: could not start playback (%s)",
@@ -326,16 +337,16 @@ usx2y_driver_start (alsa_driver_t *driver)
}
}
- driver->playback_nfds = snd_pcm_poll_descriptors_count (driver->playback_handle);
+ driver->playback_nfds = snd_pcm_poll_descriptors_count (driver->playback_handle);
driver->capture_nfds = snd_pcm_poll_descriptors_count (driver->capture_handle);
if (driver->pfd) {
free (driver->pfd);
}
- driver->pfd = (struct pollfd *)
- malloc (sizeof (struct pollfd) *
- (driver->playback_nfds + driver->capture_nfds + 2));
+ driver->pfd = (struct pollfd*)
+ malloc (sizeof(struct pollfd) *
+ (driver->playback_nfds + driver->capture_nfds + 2));
return 0;
}
@@ -347,28 +358,28 @@ usx2y_driver_stop (alsa_driver_t *driver)
JSList* node;
int chn;
- usx2y_t *h = (usx2y_t *) driver->hw->private;
+ usx2y_t *h = (usx2y_t*)driver->hw->private;
/* silence all capture port buffers, because we might
be entering offline mode.
- */
+ */
for (chn = 0, node = driver->capture_ports; node;
- node = jack_slist_next (node), chn++) {
+ node = jack_slist_next (node), chn++) {
jack_port_t* port;
char* buf;
jack_nframes_t nframes = driver->engine->control->buffer_size;
- port = (jack_port_t *) node->data;
+ port = (jack_port_t*)node->data;
buf = jack_port_get_buffer (port, nframes);
- memset (buf, 0, sizeof (jack_default_audio_sample_t) * nframes);
+ memset (buf, 0, sizeof(jack_default_audio_sample_t) * nframes);
}
if (driver->playback_handle) {
if ((err = snd_pcm_drop (driver->playback_handle)) < 0) {
jack_error ("ALSA/USX2Y: channel flush for playback "
- "failed (%s)", snd_strerror (err));
+ "failed (%s)", snd_strerror (err));
return -1;
}
}
@@ -377,7 +388,7 @@ usx2y_driver_stop (alsa_driver_t *driver)
driver->hw->set_input_monitor_mask (driver->hw, 0);
}
- munmap(h->hwdep_pcm_shm, sizeof(snd_usX2Y_hwdep_pcm_shm_t));
+ munmap (h->hwdep_pcm_shm, sizeof(snd_usX2Y_hwdep_pcm_shm_t));
return 0;
}
@@ -390,8 +401,8 @@ usx2y_driver_null_cycle (alsa_driver_t* driver, jack_nframes_t nframes)
snd_pcm_uframes_t contiguous, contiguous_;
int chn;
- VERBOSE(driver->engine,
- "usx2y_driver_null_cycle (%p, %i)", driver, nframes);
+ VERBOSE (driver->engine,
+ "usx2y_driver_null_cycle (%p, %i)", driver, nframes);
if (driver->capture_handle) {
nf = nframes;
@@ -399,25 +410,26 @@ usx2y_driver_null_cycle (alsa_driver_t* driver, jack_nframes_t nframes)
while (nf) {
contiguous = (nf > driver->frames_per_cycle) ?
- driver->frames_per_cycle : nf;
+ driver->frames_per_cycle : nf;
if (snd_pcm_mmap_begin (
- driver->capture_handle,
- &driver->capture_areas,
- (snd_pcm_uframes_t *) &offset,
- (snd_pcm_uframes_t *) &contiguous)) {
+ driver->capture_handle,
+ &driver->capture_areas,
+ (snd_pcm_uframes_t*)&offset,
+ (snd_pcm_uframes_t*)&contiguous)) {
return -1;
}
contiguous_ = contiguous;
while (contiguous_) {
snd_pcm_uframes_t frag = contiguous_;
- if (usx2y_driver_get_channel_addresses_capture(driver, &frag) < 0)
+ if (usx2y_driver_get_channel_addresses_capture (driver, &frag) < 0) {
return -1;
+ }
contiguous_ -= frag;
}
if (snd_pcm_mmap_commit (driver->capture_handle,
- offset, contiguous) < 0) {
+ offset, contiguous) < 0) {
return -1;
}
@@ -430,13 +442,13 @@ usx2y_driver_null_cycle (alsa_driver_t* driver, jack_nframes_t nframes)
offset = 0;
while (nf) {
contiguous = (nf > driver->frames_per_cycle) ?
- driver->frames_per_cycle : nf;
+ driver->frames_per_cycle : nf;
if (snd_pcm_mmap_begin (
driver->playback_handle,
&driver->playback_areas,
- (snd_pcm_uframes_t *) &offset,
- (snd_pcm_uframes_t *) &contiguous)) {
+ (snd_pcm_uframes_t*)&offset,
+ (snd_pcm_uframes_t*)&contiguous)) {
return -1;
}
@@ -444,8 +456,9 @@ usx2y_driver_null_cycle (alsa_driver_t* driver, jack_nframes_t nframes)
snd_pcm_uframes_t frag, nframes = contiguous;
while (nframes) {
frag = nframes;
- if (usx2y_driver_get_channel_addresses_playback(driver, &frag) < 0)
+ if (usx2y_driver_get_channel_addresses_playback (driver, &frag) < 0) {
return -1;
+ }
for (chn = 0; chn < driver->playback_nchannels; chn++)
alsa_driver_silence_on_channel (driver, chn, frag);
nframes -= frag;
@@ -453,7 +466,7 @@ usx2y_driver_null_cycle (alsa_driver_t* driver, jack_nframes_t nframes)
}
if (snd_pcm_mmap_commit (driver->playback_handle,
- offset, contiguous) < 0) {
+ offset, contiguous) < 0) {
return -1;
}
@@ -493,7 +506,7 @@ usx2y_driver_read (alsa_driver_t *driver, jack_nframes_t nframes)
for (chn = 0, node = driver->capture_ports;
node; node = jack_slist_next (node), chn++) {
- port = (jack_port_t *) node->data;
+ port = (jack_port_t*)node->data;
if (!jack_port_connected (port)) {
continue;
}
@@ -509,7 +522,7 @@ usx2y_driver_read (alsa_driver_t *driver, jack_nframes_t nframes)
}
for (chn = 0, node = driver->capture_ports;
node; node = jack_slist_next (node), chn++) {
- port = (jack_port_t *) node->data;
+ port = (jack_port_t*)node->data;
if (!jack_port_connected (port)) {
/* no-copy optimization */
continue;
@@ -517,10 +530,10 @@ usx2y_driver_read (alsa_driver_t *driver, jack_nframes_t nframes)
alsa_driver_read_from_channel (driver, chn,
buf[chn] + nread,
contiguous);
-/* sample_move_dS_s24(buf[chn] + nread, */
-/* driver->capture_addr[chn], */
-/* contiguous, */
-/* driver->capture_interleave_skip); */
+/* sample_move_dS_s24(buf[chn] + nread, */
+/* driver->capture_addr[chn], */
+/* contiguous, */
+/* driver->capture_interleave_skip); */
}
nread += contiguous;
nframes -= contiguous;
@@ -562,24 +575,24 @@ usx2y_driver_write (alsa_driver_t* driver, jack_nframes_t nframes)
driver->input_monitor_mask = 0;
for (chn = 0, node = driver->capture_ports; node;
- node = jack_slist_next (node), chn++) {
- if (((jack_port_t *) node->data)->shared->monitor_requests) {
- driver->input_monitor_mask |= (1<<chn);
+ node = jack_slist_next (node), chn++) {
+ if (((jack_port_t*)node->data)->shared->monitor_requests) {
+ driver->input_monitor_mask |= (1 << chn);
}
}
if (driver->hw_monitoring) {
if ((driver->hw->input_monitor_mask
- != driver->input_monitor_mask)
- && !driver->all_monitor_in) {
+ != driver->input_monitor_mask)
+ && !driver->all_monitor_in) {
driver->hw->set_input_monitor_mask (
driver->hw, driver->input_monitor_mask);
}
}
- if (snd_pcm_mmap_begin(driver->playback_handle,
- &driver->playback_areas,
- &offset, &nframes_) < 0) {
+ if (snd_pcm_mmap_begin (driver->playback_handle,
+ &driver->playback_areas,
+ &offset, &nframes_) < 0) {
jack_error ("ALSA/USX2Y: %s: mmap areas info error",
driver->alsa_name_capture);
return -1;
@@ -587,7 +600,7 @@ usx2y_driver_write (alsa_driver_t* driver, jack_nframes_t nframes)
for (chn = 0, node = driver->playback_ports;
node; node = jack_slist_next (node), chn++) {
- port = (jack_port_t *) node->data;
+ port = (jack_port_t*)node->data;
buf[chn] = jack_port_get_buffer (port, nframes_);
}
@@ -600,7 +613,7 @@ usx2y_driver_write (alsa_driver_t* driver, jack_nframes_t nframes)
}
for (chn = 0, node = driver->playback_ports;
node; node = jack_slist_next (node), chn++) {
- port = (jack_port_t *) node->data;
+ port = (jack_port_t*)node->data;
alsa_driver_write_to_channel (driver, chn,
buf[chn] + nwritten,
contiguous);
@@ -613,8 +626,9 @@ usx2y_driver_write (alsa_driver_t* driver, jack_nframes_t nframes)
offset, nframes_)) < 0) {
jack_error ("ALSA/USX2Y: could not complete playback of %"
PRIu32 " frames: error = %d", nframes_, err);
- if (err != EPIPE && err != ESTRPIPE)
+ if (err != EPIPE && err != ESTRPIPE) {
return -1;
+ }
}
return 0;
@@ -623,12 +637,12 @@ usx2y_driver_write (alsa_driver_t* driver, jack_nframes_t nframes)
static void
usx2y_driver_setup (alsa_driver_t *driver)
{
- driver->nt_start = (JackDriverNTStartFunction) usx2y_driver_start;
- driver->nt_stop = (JackDriverNTStopFunction) usx2y_driver_stop;
- driver->read = (JackDriverReadFunction) usx2y_driver_read;
- driver->write = (JackDriverReadFunction) usx2y_driver_write;
+ driver->nt_start = (JackDriverNTStartFunction)usx2y_driver_start;
+ driver->nt_stop = (JackDriverNTStopFunction)usx2y_driver_stop;
+ driver->read = (JackDriverReadFunction)usx2y_driver_read;
+ driver->write = (JackDriverReadFunction)usx2y_driver_write;
driver->null_cycle =
- (JackDriverNullCycleFunction) usx2y_driver_null_cycle;
+ (JackDriverNullCycleFunction)usx2y_driver_null_cycle;
}
@@ -638,13 +652,13 @@ jack_alsa_usx2y_hw_new (alsa_driver_t *driver)
jack_hardware_t *hw;
usx2y_t *h;
- int hwdep_cardno;
- int hwdep_devno;
+ int hwdep_cardno;
+ int hwdep_devno;
char *hwdep_colon;
- char hwdep_name[9];
+ char hwdep_name[9];
snd_hwdep_t *hwdep_handle;
- hw = (jack_hardware_t *) malloc (sizeof (jack_hardware_t));
+ hw = (jack_hardware_t*)malloc (sizeof(jack_hardware_t));
hw->capabilities = 0;
hw->input_monitor_mask = 0;
@@ -661,22 +675,23 @@ jack_alsa_usx2y_hw_new (alsa_driver_t *driver)
*/
hwdep_handle = NULL;
hwdep_cardno = hwdep_devno = 0;
- if ((hwdep_colon = strrchr(driver->alsa_name_playback, ':')) != NULL)
- sscanf(hwdep_colon, ":%d,%d", &hwdep_cardno, &hwdep_devno);
+ if ((hwdep_colon = strrchr (driver->alsa_name_playback, ':')) != NULL) {
+ sscanf (hwdep_colon, ":%d,%d", &hwdep_cardno, &hwdep_devno);
+ }
if (hwdep_devno == 2) {
- snprintf(hwdep_name, sizeof(hwdep_name), "hw:%d,1", hwdep_cardno);
+ snprintf (hwdep_name, sizeof(hwdep_name), "hw:%d,1", hwdep_cardno);
if (snd_hwdep_open (&hwdep_handle, hwdep_name, O_RDWR) < 0) {
jack_error ("ALSA/USX2Y: Cannot open hwdep device \"%s\"", hwdep_name);
} else {
/* Allocate specific USX2Y hwdep pcm struct. */
- h = (usx2y_t *) malloc (sizeof (usx2y_t));
+ h = (usx2y_t*)malloc (sizeof(usx2y_t));
h->driver = driver;
h->hwdep_handle = hwdep_handle;
hw->private = h;
/* Set our own operational function pointers. */
- usx2y_driver_setup(driver);
- jack_info("ALSA/USX2Y: EXPERIMENTAL hwdep pcm device %s"
- " (aka \"rawusb\")", driver->alsa_name_playback);
+ usx2y_driver_setup (driver);
+ jack_info ("ALSA/USX2Y: EXPERIMENTAL hwdep pcm device %s"
+ " (aka \"rawusb\")", driver->alsa_name_playback);
}
}
diff --git a/drivers/alsa/usx2y.h b/drivers/alsa/usx2y.h
index 8876d94..853f307 100644
--- a/drivers/alsa/usx2y.h
+++ b/drivers/alsa/usx2y.h
@@ -1,7 +1,7 @@
/*
Copyright (C) 2001 Paul Davis
Copyright (C) 2004 Karsten Wiese, Rui Nuno Capela
-
+
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
@@ -16,14 +16,14 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
+ */
#ifndef __jack_usx2y_h__
#define __jack_usx2y_h__
-#define USX2Y_MAXPACK 50
-#define USX2Y_MAXBUFFERMS 100
-#define USX2Y_MAXSTRIDE 3
+#define USX2Y_MAXPACK 50
+#define USX2Y_MAXBUFFERMS 100
+#define USX2Y_MAXSTRIDE 3
#define USX2Y_SSS (((USX2Y_MAXPACK * USX2Y_MAXBUFFERMS * USX2Y_MAXSTRIDE + 4096) / 4096) * 4096)
@@ -34,9 +34,9 @@ struct snd_usX2Y_hwdep_pcm_shm {
volatile int playback_iso_head;
int playback_iso_start;
struct {
- int frame,
- offset,
- length;
+ int frame,
+ offset,
+ length;
} captured_iso[128];
volatile int captured_iso_head;
volatile unsigned captured_iso_frames;
@@ -56,6 +56,6 @@ typedef struct {
} usx2y_t;
jack_hardware_t *
-jack_alsa_usx2y_hw_new (alsa_driver_t *driver);
+jack_alsa_usx2y_hw_new(alsa_driver_t *driver);
#endif /* __jack_usx2y_h__*/
diff --git a/drivers/alsa_midi/a2j.h b/drivers/alsa_midi/a2j.h
index e8145b3..c536448 100644
--- a/drivers/alsa_midi/a2j.h
+++ b/drivers/alsa_midi/a2j.h
@@ -39,100 +39,95 @@
#define PORT_HASH_SIZE (1 << PORT_HASH_BITS)
/* Beside enum use, these are indeces for (struct a2j).stream array */
-#define A2J_PORT_CAPTURE 0 // ALSA playback port -> JACK capture port
-#define A2J_PORT_PLAYBACK 1 // JACK playback port -> ALSA capture port
+#define A2J_PORT_CAPTURE 0 // ALSA playback port -> JACK capture port
+#define A2J_PORT_PLAYBACK 1 // JACK playback port -> ALSA capture port
typedef struct a2j_port * a2j_port_hash_t[PORT_HASH_SIZE];
struct alsa_midi_driver;
-struct a2j_port
-{
- struct a2j_port * next; /* hash - jack */
- struct list_head siblings; /* list - main loop */
- struct alsa_midi_driver * driver_ptr;
- bool is_dead;
- char name[64];
- snd_seq_addr_t remote;
- jack_port_t * jack_port;
-
- jack_ringbuffer_t * inbound_events; // alsa_midi_event_t + data
- int64_t last_out_time;
-
- void * jack_buf;
+struct a2j_port {
+ struct a2j_port * next; /* hash - jack */
+ struct list_head siblings; /* list - main loop */
+ struct alsa_midi_driver * driver_ptr;
+ bool is_dead;
+ char name[64];
+ snd_seq_addr_t remote;
+ jack_port_t * jack_port;
+
+ jack_ringbuffer_t * inbound_events; // alsa_midi_event_t + data
+ int64_t last_out_time;
+
+ void * jack_buf;
};
-struct a2j_stream
-{
- snd_midi_event_t *codec;
-
- jack_ringbuffer_t *new_ports;
-
- a2j_port_hash_t port_hash;
- struct list_head list;
+struct a2j_stream {
+ snd_midi_event_t *codec;
+
+ jack_ringbuffer_t *new_ports;
+
+ a2j_port_hash_t port_hash;
+ struct list_head list;
};
-typedef struct alsa_midi_driver
-{
- JACK_DRIVER_DECL;
-
- jack_client_t * jack_client;
-
- snd_seq_t *seq;
- pthread_t alsa_input_thread;
- pthread_t alsa_output_thread;
- int client_id;
- int port_id;
- int queue;
- bool freewheeling;
- bool running;
- bool finishing;
-
- jack_ringbuffer_t* port_del; // struct a2j_port*
- jack_ringbuffer_t* outbound_events; // struct a2j_delivery_event
- jack_nframes_t cycle_start;
-
- sem_t output_semaphore;
-
- struct a2j_stream stream[2];
+typedef struct alsa_midi_driver {
+ JACK_DRIVER_DECL;
+
+ jack_client_t * jack_client;
+
+ snd_seq_t *seq;
+ pthread_t alsa_input_thread;
+ pthread_t alsa_output_thread;
+ int client_id;
+ int port_id;
+ int queue;
+ bool freewheeling;
+ bool running;
+ bool finishing;
+
+ jack_ringbuffer_t* port_del; // struct a2j_port*
+ jack_ringbuffer_t* outbound_events; // struct a2j_delivery_event
+ jack_nframes_t cycle_start;
+
+ sem_t output_semaphore;
+
+ struct a2j_stream stream[2];
} alsa_midi_driver_t;
-#define NSEC_PER_SEC ((int64_t)1000*1000*1000)
+#define NSEC_PER_SEC ((int64_t)1000 * 1000 * 1000)
-struct a2j_alsa_midi_event
-{
- int64_t time;
- int size;
+struct a2j_alsa_midi_event {
+ int64_t time;
+ int size;
};
#define MAX_JACKMIDI_EV_SIZE 64
-struct a2j_delivery_event
-{
- struct list_head siblings;
-
- /* a jack MIDI event, plus the port its destined for: everything
- the ALSA output thread needs to deliver the event. time is
- part of the jack_event.
- */
- jack_midi_event_t jack_event;
- jack_nframes_t time; /* realtime, not offset time */
- struct a2j_port* port;
- char midistring[MAX_JACKMIDI_EV_SIZE];
+struct a2j_delivery_event {
+ struct list_head siblings;
+
+ /* a jack MIDI event, plus the port its destined for: everything
+ the ALSA output thread needs to deliver the event. time is
+ part of the jack_event.
+ */
+ jack_midi_event_t jack_event;
+ jack_nframes_t time; /* realtime, not offset time */
+ struct a2j_port* port;
+ char midistring[MAX_JACKMIDI_EV_SIZE];
};
-void a2j_error (const char* fmt, ...);
+void a2j_error(const char* fmt, ...);
#define A2J_DEBUG
/*#undef A2J_DEBUG*/
#ifdef A2J_DEBUG
extern bool a2j_do_debug;
-extern void _a2j_debug (const char* fmt, ...);
-#define a2j_debug(fmt, ...) if (a2j_do_debug) { _a2j_debug ((fmt), ##__VA_ARGS__); }
+extern void _a2j_debug(const char* fmt, ...);
+#define a2j_debug(fmt, ...) if (a2j_do_debug) { _a2j_debug ((fmt), ## __VA_ARGS__); }
#else
-#define a2j_debug(fmt,...)
+#define a2j_debug(fmt, ...)
#endif
#endif /* __jack_alsa_midi_h__ */
diff --git a/drivers/alsa_midi/alsa_midi.c b/drivers/alsa_midi/alsa_midi.c
index a4542b4..28a00cd 100644
--- a/drivers/alsa_midi/alsa_midi.c
+++ b/drivers/alsa_midi/alsa_midi.c
@@ -42,6 +42,7 @@ void
_a2j_debug (const char* fmt, ...)
{
va_list ap;
+
va_start (ap, fmt);
vfprintf (stderr, fmt, ap);
fputc ('\n', stderr);
@@ -52,25 +53,26 @@ void
a2j_error (const char* fmt, ...)
{
va_list ap;
+
va_start (ap, fmt);
vfprintf (stdout, fmt, ap);
fputc ('\n', stdout);
}
static bool
-a2j_stream_init(alsa_midi_driver_t* driver, int which)
+a2j_stream_init (alsa_midi_driver_t* driver, int which)
{
- struct a2j_stream *str = &driver->stream[which];
-
- str->new_ports = jack_ringbuffer_create (MAX_PORTS * sizeof(struct a2j_port *));
- if (str->new_ports == NULL) {
- return false;
- }
-
- snd_midi_event_new (MAX_EVENT_SIZE, &str->codec);
- INIT_LIST_HEAD (&str->list);
-
- return true;
+ struct a2j_stream *str = &driver->stream[which];
+
+ str->new_ports = jack_ringbuffer_create (MAX_PORTS * sizeof(struct a2j_port *));
+ if (str->new_ports == NULL) {
+ return false;
+ }
+
+ snd_midi_event_new (MAX_EVENT_SIZE, &str->codec);
+ INIT_LIST_HEAD (&str->list);
+
+ return true;
}
static void
@@ -78,10 +80,10 @@ a2j_stream_detach (struct a2j_stream * stream_ptr)
{
struct a2j_port * port_ptr;
struct list_head * node_ptr;
-
- if (!stream_ptr) {
- return;
- }
+
+ if (!stream_ptr) {
+ return;
+ }
while (!list_empty (&stream_ptr->list)) {
node_ptr = stream_ptr->list.next;
@@ -98,34 +100,36 @@ a2j_stream_close (alsa_midi_driver_t* driver, int which)
{
struct a2j_stream *str = &driver->stream[which];
- if (!str) {
- return;
- }
+ if (!str) {
+ return;
+ }
- if (str->codec)
+ if (str->codec) {
snd_midi_event_free (str->codec);
- if (str->new_ports)
+ }
+ if (str->new_ports) {
jack_ringbuffer_free (str->new_ports);
+ }
}
static void
stop_threads (alsa_midi_driver_t* driver)
{
- if (driver->running) {
- void* thread_status;
-
- driver->running = false; /* tell alsa io thread to stop, whenever they wake up */
- /* do something that we need to do anyway and will wake the io thread, then join */
- snd_seq_disconnect_from (driver->seq, driver->port_id, SND_SEQ_CLIENT_SYSTEM, SND_SEQ_PORT_SYSTEM_ANNOUNCE);
- a2j_debug ("wait for ALSA input thread\n");
- pthread_join (driver->alsa_input_thread, &thread_status);
- a2j_debug ("input thread done\n");
-
- /* wake output thread and join */
- sem_post (&driver->output_semaphore);
- pthread_join (driver->alsa_output_thread, &thread_status);
- a2j_debug ("output thread done\n");
- }
+ if (driver->running) {
+ void* thread_status;
+
+ driver->running = false; /* tell alsa io thread to stop, whenever they wake up */
+ /* do something that we need to do anyway and will wake the io thread, then join */
+ snd_seq_disconnect_from (driver->seq, driver->port_id, SND_SEQ_CLIENT_SYSTEM, SND_SEQ_PORT_SYSTEM_ANNOUNCE);
+ a2j_debug ("wait for ALSA input thread\n");
+ pthread_join (driver->alsa_input_thread, &thread_status);
+ a2j_debug ("input thread done\n");
+
+ /* wake output thread and join */
+ sem_post (&driver->output_semaphore);
+ pthread_join (driver->alsa_output_thread, &thread_status);
+ a2j_debug ("output thread done\n");
+ }
}
/*
@@ -135,8 +139,9 @@ stop_threads (alsa_midi_driver_t* driver)
void a2j_add_ports (struct a2j_stream * str)
{
struct a2j_port * port_ptr;
- while (jack_ringbuffer_read (str->new_ports, (char *)&port_ptr, sizeof(port_ptr))) {
- a2j_debug("jack: inserted port %s", port_ptr->name);
+
+ while (jack_ringbuffer_read (str->new_ports, (char*)&port_ptr, sizeof(port_ptr))) {
+ a2j_debug ("jack: inserted port %s", port_ptr->name);
a2j_port_insert (str->port_hash, port_ptr);
}
}
@@ -147,19 +152,20 @@ a2j_port_event (alsa_midi_driver_t* driver, snd_seq_event_t * ev)
{
const snd_seq_addr_t addr = ev->data.addr;
- if (addr.client == driver->client_id)
+ if (addr.client == driver->client_id) {
return;
+ }
if (ev->type == SND_SEQ_EVENT_PORT_START) {
- a2j_debug("port_event: add %d:%d", addr.client, addr.port);
+ a2j_debug ("port_event: add %d:%d", addr.client, addr.port);
a2j_new_ports (driver, addr);
} else if (ev->type == SND_SEQ_EVENT_PORT_CHANGE) {
- a2j_debug("port_event: change %d:%d", addr.client, addr.port);
+ a2j_debug ("port_event: change %d:%d", addr.client, addr.port);
a2j_update_ports (driver, addr);
} else if (ev->type == SND_SEQ_EVENT_PORT_EXIT) {
- a2j_debug("port_event: del %d:%d", addr.client, addr.port);
- a2j_port_setdead(driver->stream[A2J_PORT_CAPTURE].port_hash, addr);
- a2j_port_setdead(driver->stream[A2J_PORT_PLAYBACK].port_hash, addr);
+ a2j_debug ("port_event: del %d:%d", addr.client, addr.port);
+ a2j_port_setdead (driver->stream[A2J_PORT_CAPTURE].port_hash, addr);
+ a2j_port_setdead (driver->stream[A2J_PORT_PLAYBACK].port_hash, addr);
}
}
@@ -175,8 +181,8 @@ a2j_input_event (alsa_midi_driver_t* driver, snd_seq_event_t * alsa_event)
jack_nframes_t now;
now = jack_frame_time (driver->jack_client);
-
- if ((port = a2j_port_get(str->port_hash, alsa_event->source)) == NULL) {
+
+ if ((port = a2j_port_get (str->port_hash, alsa_event->source)) == NULL) {
return;
}
@@ -184,8 +190,8 @@ a2j_input_event (alsa_midi_driver_t* driver, snd_seq_event_t * alsa_event)
* RPNs, NRPNs, Bank Change, etc. need special handling
* but seems, ALSA does it for us already.
*/
- snd_midi_event_reset_decode(str->codec);
- if ((size = snd_midi_event_decode(str->codec, data, sizeof(data), alsa_event))<0) {
+ snd_midi_event_reset_decode (str->codec);
+ if ((size = snd_midi_event_decode (str->codec, data, sizeof(data), alsa_event)) < 0) {
return;
}
@@ -195,47 +201,47 @@ a2j_input_event (alsa_midi_driver_t* driver, snd_seq_event_t * alsa_event)
data[2] = 0x40;
}
- a2j_debug("input: %d bytes at event_frame=%u", (int)size, now);
+ a2j_debug ("input: %d bytes at event_frame=%u", (int)size, now);
- if (jack_ringbuffer_write_space(port->inbound_events) >= (sizeof(struct a2j_alsa_midi_event) + size)) {
+ if (jack_ringbuffer_write_space (port->inbound_events) >= (sizeof(struct a2j_alsa_midi_event) + size)) {
struct a2j_alsa_midi_event ev;
- char *ev_charp = (char*) &ev;
+ char *ev_charp = (char*)&ev;
size_t limit;
size_t to_write = sizeof(ev);
jack_ringbuffer_data_t vec[2];
- jack_ringbuffer_get_write_vector( port->inbound_events, vec );
+ jack_ringbuffer_get_write_vector ( port->inbound_events, vec );
ev.time = now;
ev.size = size;
-
+
limit = (to_write > vec[0].len ? vec[0].len : to_write);
if (limit) {
- memcpy( vec[0].buf, ev_charp, limit );
- to_write -= limit;
- ev_charp += limit;
- vec[0].buf += limit;
- vec[0].len -= limit;
+ memcpy ( vec[0].buf, ev_charp, limit );
+ to_write -= limit;
+ ev_charp += limit;
+ vec[0].buf += limit;
+ vec[0].len -= limit;
}
if (to_write) {
- memcpy( vec[1].buf, ev_charp, to_write );
- vec[1].buf += to_write;
- vec[1].len -= to_write;
+ memcpy ( vec[1].buf, ev_charp, to_write );
+ vec[1].buf += to_write;
+ vec[1].len -= to_write;
}
to_write = size;
- ev_charp = (char *)data;
+ ev_charp = (char*)data;
limit = (to_write > vec[0].len ? vec[0].len : to_write);
if (limit) {
memcpy (vec[0].buf, ev_charp, limit);
- }
+ }
to_write -= limit;
ev_charp += limit;
if (to_write) {
memcpy (vec[1].buf, ev_charp, to_write);
- }
+ }
- jack_ringbuffer_write_advance( port->inbound_events, sizeof(ev) + size );
+ jack_ringbuffer_write_advance ( port->inbound_events, sizeof(ev) + size );
} else {
a2j_error ("MIDI data lost (incoming event buffer full): %ld bytes lost", size);
}
@@ -245,74 +251,74 @@ a2j_input_event (alsa_midi_driver_t* driver, snd_seq_event_t * alsa_event)
static int
a2j_process_incoming (alsa_midi_driver_t* driver, struct a2j_port* port, jack_nframes_t nframes)
{
- jack_nframes_t one_period;
- struct a2j_alsa_midi_event ev;
- char *ev_buf;
-
- /* grab data queued by the ALSA input thread and write it into the JACK
- port buffer. it will delivered during the JACK period that this
- function is called from.
- */
-
- /* first clear the JACK port buffer in preparation for new data
- */
-
- a2j_debug ("PORT: %s process input", jack_port_name (port->jack_port));
-
- jack_midi_clear_buffer (port->jack_buf);
-
- one_period = jack_get_buffer_size (driver->jack_client);
-
- while (jack_ringbuffer_peek (port->inbound_events, (char*)&ev, sizeof(ev) ) == sizeof(ev) ) {
-
- jack_midi_data_t* buf;
- jack_nframes_t offset;
-
- a2j_debug ("Seen inbound event from read callback\n");
-
- if (ev.time >= driver->cycle_start) {
- a2j_debug ("event is too late\n");
- break;
- }
-
- //jack_ringbuffer_read_advance (port->inbound_events, sizeof (ev));
- ev_buf = (char *) alloca( sizeof(ev) + ev.size );
-
- if (jack_ringbuffer_peek (port->inbound_events, ev_buf, sizeof(ev) + ev.size ) != sizeof(ev) + ev.size) {
- break;
- }
-
- offset = driver->cycle_start - ev.time;
- if (offset > one_period) {
- /* from a previous cycle, somehow. cram it in at the front */
- offset = 0;
- } else {
- /* offset from start of the current cycle */
- offset = one_period - offset;
- }
-
- a2j_debug ("event at %d offset %d", ev.time, offset);
-
- /* make sure there is space for it */
-
- buf = jack_midi_event_reserve (port->jack_buf, offset, ev.size);
-
- if (buf) {
- /* grab the event */
- memcpy( buf, ev_buf + sizeof(ev), ev.size );
- } else {
- /* throw it away (no space) */
- a2j_error ("threw away MIDI event - not reserved at time %d", ev.time);
- }
- jack_ringbuffer_read_advance (port->inbound_events, sizeof(ev) + ev.size);
-
- a2j_debug("input on %s: sucked %d bytes from inbound at %d", jack_port_name (port->jack_port), ev.size, ev.time);
- }
-
- return 0;
+ jack_nframes_t one_period;
+ struct a2j_alsa_midi_event ev;
+ char *ev_buf;
+
+ /* grab data queued by the ALSA input thread and write it into the JACK
+ port buffer. it will delivered during the JACK period that this
+ function is called from.
+ */
+
+ /* first clear the JACK port buffer in preparation for new data
+ */
+
+ a2j_debug ("PORT: %s process input", jack_port_name (port->jack_port));
+
+ jack_midi_clear_buffer (port->jack_buf);
+
+ one_period = jack_get_buffer_size (driver->jack_client);
+
+ while (jack_ringbuffer_peek (port->inbound_events, (char*)&ev, sizeof(ev) ) == sizeof(ev) ) {
+
+ jack_midi_data_t* buf;
+ jack_nframes_t offset;
+
+ a2j_debug ("Seen inbound event from read callback\n");
+
+ if (ev.time >= driver->cycle_start) {
+ a2j_debug ("event is too late\n");
+ break;
+ }
+
+ //jack_ringbuffer_read_advance (port->inbound_events, sizeof (ev));
+ ev_buf = (char*)alloca ( sizeof(ev) + ev.size );
+
+ if (jack_ringbuffer_peek (port->inbound_events, ev_buf, sizeof(ev) + ev.size ) != sizeof(ev) + ev.size) {
+ break;
+ }
+
+ offset = driver->cycle_start - ev.time;
+ if (offset > one_period) {
+ /* from a previous cycle, somehow. cram it in at the front */
+ offset = 0;
+ } else {
+ /* offset from start of the current cycle */
+ offset = one_period - offset;
+ }
+
+ a2j_debug ("event at %d offset %d", ev.time, offset);
+
+ /* make sure there is space for it */
+
+ buf = jack_midi_event_reserve (port->jack_buf, offset, ev.size);
+
+ if (buf) {
+ /* grab the event */
+ memcpy ( buf, ev_buf + sizeof(ev), ev.size );
+ } else {
+ /* throw it away (no space) */
+ a2j_error ("threw away MIDI event - not reserved at time %d", ev.time);
+ }
+ jack_ringbuffer_read_advance (port->inbound_events, sizeof(ev) + ev.size);
+
+ a2j_debug ("input on %s: sucked %d bytes from inbound at %d", jack_port_name (port->jack_port), ev.size, ev.time);
+ }
+
+ return 0;
}
-void*
+void*
alsa_input_thread (void* arg)
{
alsa_midi_driver_t* driver = arg;
@@ -324,25 +330,25 @@ alsa_input_thread (void* arg)
snd_seq_event_t * event;
int ret;
- npfd = snd_seq_poll_descriptors_count(driver->seq, POLLIN);
- pfd = (struct pollfd *)alloca(npfd * sizeof(struct pollfd));
- snd_seq_poll_descriptors(driver->seq, pfd, npfd, POLLIN);
+ npfd = snd_seq_poll_descriptors_count (driver->seq, POLLIN);
+ pfd = (struct pollfd*)alloca (npfd * sizeof(struct pollfd));
+ snd_seq_poll_descriptors (driver->seq, pfd, npfd, POLLIN);
initial = true;
while (driver->running) {
- if ((ret = poll(pfd, npfd, 1000)) > 0) {
+ if ((ret = poll (pfd, npfd, 1000)) > 0) {
while (snd_seq_event_input (driver->seq, &event) > 0) {
if (initial) {
- snd_seq_client_info_alloca(&client_info);
- snd_seq_client_info_set_client(client_info, -1);
- while (snd_seq_query_next_client(driver->seq, client_info) >= 0) {
- addr.client = snd_seq_client_info_get_client(client_info);
+ snd_seq_client_info_alloca (&client_info);
+ snd_seq_client_info_set_client (client_info, -1);
+ while (snd_seq_query_next_client (driver->seq, client_info) >= 0) {
+ addr.client = snd_seq_client_info_get_client (client_info);
if (addr.client == SND_SEQ_CLIENT_SYSTEM || addr.client == driver->client_id) {
continue;
}
-
+
a2j_new_ports (driver, addr);
}
@@ -350,9 +356,9 @@ alsa_input_thread (void* arg)
}
if (event->source.client == SND_SEQ_CLIENT_SYSTEM) {
- a2j_port_event(driver, event);
+ a2j_port_event (driver, event);
} else {
- a2j_input_event(driver, event);
+ a2j_input_event (driver, event);
}
snd_seq_free_event (event);
@@ -360,214 +366,207 @@ alsa_input_thread (void* arg)
}
}
- return (void*) 0;
+ return (void*)0;
}
/* --- OUTBOUND FROM JACK TO ALSA ---- */
int
a2j_process_outgoing (
- alsa_midi_driver_t* driver,
- struct a2j_port * port)
+ alsa_midi_driver_t* driver,
+ struct a2j_port * port)
{
- /* collect data from JACK port buffer and queue it for delivery by ALSA output thread */
-
- int nevents;
- jack_ringbuffer_data_t vec[2];
- int i;
- int written = 0;
- size_t limit;
- struct a2j_delivery_event* dev;
- size_t gap = 0;
-
- jack_ringbuffer_get_write_vector (driver->outbound_events, vec);
-
- dev = (struct a2j_delivery_event*) vec[0].buf;
- limit = vec[0].len / sizeof (struct a2j_delivery_event);
- nevents = jack_midi_get_event_count (port->jack_buf);
-
- a2j_debug ("alsa_out: port has %d events for delivery\n", nevents);
-
- for (i = 0; (i < nevents) && (written < limit); ++i) {
-
- jack_midi_event_get (&dev->jack_event, port->jack_buf, i);
- if (dev->jack_event.size <= MAX_JACKMIDI_EV_SIZE)
- {
- dev->time = dev->jack_event.time;
- dev->port = port;
- memcpy( dev->midistring, dev->jack_event.buffer, dev->jack_event.size );
- written++;
- ++dev;
- }
- }
-
- /* anything left? use the second part of the vector, as much as possible */
-
- if (i < nevents)
- {
- if (vec[0].len)
- {
- gap = vec[0].len - written * sizeof(struct a2j_delivery_event);
- }
-
- dev = (struct a2j_delivery_event*) vec[1].buf;
-
- limit += (vec[1].len / sizeof (struct a2j_delivery_event));
-
- while ((i < nevents) && (written < limit))
- {
- jack_midi_event_get(&dev->jack_event, port->jack_buf, i);
- if (dev->jack_event.size <= MAX_JACKMIDI_EV_SIZE)
- {
- dev->time = dev->jack_event.time;
- dev->port = port;
- memcpy(dev->midistring, dev->jack_event.buffer, dev->jack_event.size);
- written++;
- ++dev;
- }
- ++i;
- }
- }
-
- a2j_debug( "done pushing events: %d ... gap: %d ", (int)written, (int)gap );
- /* clear JACK port buffer; advance ring buffer ptr */
-
- jack_ringbuffer_write_advance (driver->outbound_events, written * sizeof (struct a2j_delivery_event) + gap);
-
- return nevents;
+ /* collect data from JACK port buffer and queue it for delivery by ALSA output thread */
+
+ int nevents;
+ jack_ringbuffer_data_t vec[2];
+ int i;
+ int written = 0;
+ size_t limit;
+ struct a2j_delivery_event* dev;
+ size_t gap = 0;
+
+ jack_ringbuffer_get_write_vector (driver->outbound_events, vec);
+
+ dev = (struct a2j_delivery_event*)vec[0].buf;
+ limit = vec[0].len / sizeof(struct a2j_delivery_event);
+ nevents = jack_midi_get_event_count (port->jack_buf);
+
+ a2j_debug ("alsa_out: port has %d events for delivery\n", nevents);
+
+ for (i = 0; (i < nevents) && (written < limit); ++i) {
+
+ jack_midi_event_get (&dev->jack_event, port->jack_buf, i);
+ if (dev->jack_event.size <= MAX_JACKMIDI_EV_SIZE) {
+ dev->time = dev->jack_event.time;
+ dev->port = port;
+ memcpy ( dev->midistring, dev->jack_event.buffer, dev->jack_event.size );
+ written++;
+ ++dev;
+ }
+ }
+
+ /* anything left? use the second part of the vector, as much as possible */
+
+ if (i < nevents) {
+ if (vec[0].len) {
+ gap = vec[0].len - written * sizeof(struct a2j_delivery_event);
+ }
+
+ dev = (struct a2j_delivery_event*)vec[1].buf;
+
+ limit += (vec[1].len / sizeof(struct a2j_delivery_event));
+
+ while ((i < nevents) && (written < limit)) {
+ jack_midi_event_get (&dev->jack_event, port->jack_buf, i);
+ if (dev->jack_event.size <= MAX_JACKMIDI_EV_SIZE) {
+ dev->time = dev->jack_event.time;
+ dev->port = port;
+ memcpy (dev->midistring, dev->jack_event.buffer, dev->jack_event.size);
+ written++;
+ ++dev;
+ }
+ ++i;
+ }
+ }
+
+ a2j_debug ( "done pushing events: %d ... gap: %d ", (int)written, (int)gap );
+ /* clear JACK port buffer; advance ring buffer ptr */
+
+ jack_ringbuffer_write_advance (driver->outbound_events, written * sizeof(struct a2j_delivery_event) + gap);
+
+ return nevents;
}
static int
time_sorter (struct a2j_delivery_event * a, struct a2j_delivery_event * b)
{
- if (a->time < b->time) {
- return -1;
- } else if (a->time > b->time) {
- return 1;
- }
- return 0;
+ if (a->time < b->time) {
+ return -1;
+ } else if (a->time > b->time) {
+ return 1;
+ }
+ return 0;
}
-static void*
-alsa_output_thread(void * arg)
+static void*
+alsa_output_thread (void * arg)
{
- alsa_midi_driver_t * driver = (alsa_midi_driver_t*) arg;
- struct a2j_stream *str = &driver->stream[A2J_PORT_PLAYBACK];
- int i;
- struct list_head evlist;
- struct list_head * node_ptr;
- jack_ringbuffer_data_t vec[2];
- snd_seq_event_t alsa_event;
- struct a2j_delivery_event* ev;
- float sr;
- jack_nframes_t now;
- int limit;
-
- while (driver->running) {
- /* pre-first, handle port deletion requests */
-
- a2j_free_ports(driver);
-
- /* first, make a list of all events in the outbound_events FIFO */
-
- INIT_LIST_HEAD(&evlist);
-
- jack_ringbuffer_get_read_vector (driver->outbound_events, vec);
-
- a2j_debug ("alsa_out: output thread: got %d+%d events",
- (vec[0].len / sizeof (struct a2j_delivery_event)),
- (vec[1].len / sizeof (struct a2j_delivery_event)));
-
- ev = (struct a2j_delivery_event*) vec[0].buf;
- limit = vec[0].len / sizeof (struct a2j_delivery_event);
- for (i = 0; i < limit; ++i) {
- list_add_tail(&ev->siblings, &evlist);
- ev++;
- }
-
- ev = (struct a2j_delivery_event*) vec[1].buf;
- limit = vec[1].len / sizeof (struct a2j_delivery_event);
- for (i = 0; i < limit; ++i) {
- list_add_tail(&ev->siblings, &evlist);
- ev++;
- }
-
- if (vec[0].len < sizeof(struct a2j_delivery_event) && (vec[1].len == 0)) {
- /* no events: wait for some */
- a2j_debug ("alsa_out: output thread: wait for events");
- sem_wait (&driver->output_semaphore);
- a2j_debug ("alsa_out: output thread: AWAKE ... loop back for events");
- continue;
- }
-
- /* now sort this list by time */
-
- list_sort(&evlist, struct a2j_delivery_event, siblings, time_sorter);
-
- /* now deliver */
-
- sr = jack_get_sample_rate (driver->jack_client);
-
- list_for_each(node_ptr, &evlist)
- {
- ev = list_entry(node_ptr, struct a2j_delivery_event, siblings);
-
- snd_seq_ev_clear(&alsa_event);
- snd_midi_event_reset_encode(str->codec);
- if (!snd_midi_event_encode(str->codec, (const unsigned char *)ev->midistring, ev->jack_event.size, &alsa_event))
- {
- a2j_debug ("alsa_out: invalid event of size %d, ignored\n", ev->jack_event.size);
- continue; // invalid event
- }
-
- snd_seq_ev_set_source(&alsa_event, driver->port_id);
- snd_seq_ev_set_dest(&alsa_event, ev->port->remote.client, ev->port->remote.port);
- snd_seq_ev_set_direct (&alsa_event);
-
- now = jack_frame_time (driver->jack_client);
-
- ev->time += driver->cycle_start;
-
- a2j_debug ("alsa_out:@ %d, next event @ %d", now, ev->time);
-
- /* do we need to wait a while before delivering? */
-
- if (ev->time > now) {
- struct timespec nanoseconds;
- jack_nframes_t sleep_frames = ev->time - now;
- float seconds = sleep_frames / sr;
-
- /* if the gap is long enough, sleep */
-
- if (seconds > 0.001) {
- nanoseconds.tv_sec = (time_t) seconds;
- nanoseconds.tv_nsec = (long) NSEC_PER_SEC * (seconds - nanoseconds.tv_sec);
-
- a2j_debug ("alsa_out: output thread sleeps for %.2f msec", ((double) nanoseconds.tv_nsec / NSEC_PER_SEC) * 1000.0);
-
- if (nanosleep (&nanoseconds, NULL) < 0) {
- fprintf (stderr, "BAD SLEEP\n");
- /* do something ? */
- }
- }
- }
-
- /* its time to deliver */
- snd_seq_event_output(driver->seq, &alsa_event);
- snd_seq_drain_output (driver->seq);
- now = jack_frame_time (driver->jack_client);
- a2j_debug("alsa_out: written %d bytes to %s at %d, DELTA = %d", ev->jack_event.size, ev->port->name, now,
- (int32_t) (now - ev->time));
- }
-
- /* free up space in the FIFO */
-
- jack_ringbuffer_read_advance (driver->outbound_events, vec[0].len + vec[1].len);
-
- /* and head back for more */
- }
-
- return (void*) 0;
+ alsa_midi_driver_t * driver = (alsa_midi_driver_t*)arg;
+ struct a2j_stream *str = &driver->stream[A2J_PORT_PLAYBACK];
+ int i;
+ struct list_head evlist;
+ struct list_head * node_ptr;
+ jack_ringbuffer_data_t vec[2];
+ snd_seq_event_t alsa_event;
+ struct a2j_delivery_event* ev;
+ float sr;
+ jack_nframes_t now;
+ int limit;
+
+ while (driver->running) {
+ /* pre-first, handle port deletion requests */
+
+ a2j_free_ports (driver);
+
+ /* first, make a list of all events in the outbound_events FIFO */
+
+ INIT_LIST_HEAD (&evlist);
+
+ jack_ringbuffer_get_read_vector (driver->outbound_events, vec);
+
+ a2j_debug ("alsa_out: output thread: got %d+%d events",
+ (vec[0].len / sizeof(struct a2j_delivery_event)),
+ (vec[1].len / sizeof(struct a2j_delivery_event)));
+
+ ev = (struct a2j_delivery_event*)vec[0].buf;
+ limit = vec[0].len / sizeof(struct a2j_delivery_event);
+ for (i = 0; i < limit; ++i) {
+ list_add_tail (&ev->siblings, &evlist);
+ ev++;
+ }
+
+ ev = (struct a2j_delivery_event*)vec[1].buf;
+ limit = vec[1].len / sizeof(struct a2j_delivery_event);
+ for (i = 0; i < limit; ++i) {
+ list_add_tail (&ev->siblings, &evlist);
+ ev++;
+ }
+
+ if (vec[0].len < sizeof(struct a2j_delivery_event) && (vec[1].len == 0)) {
+ /* no events: wait for some */
+ a2j_debug ("alsa_out: output thread: wait for events");
+ sem_wait (&driver->output_semaphore);
+ a2j_debug ("alsa_out: output thread: AWAKE ... loop back for events");
+ continue;
+ }
+
+ /* now sort this list by time */
+
+ list_sort (&evlist, struct a2j_delivery_event, siblings, time_sorter);
+
+ /* now deliver */
+
+ sr = jack_get_sample_rate (driver->jack_client);
+
+ list_for_each (node_ptr, &evlist){
+ ev = list_entry (node_ptr, struct a2j_delivery_event, siblings);
+
+ snd_seq_ev_clear (&alsa_event);
+ snd_midi_event_reset_encode (str->codec);
+ if (!snd_midi_event_encode (str->codec, (const unsigned char*)ev->midistring, ev->jack_event.size, &alsa_event)) {
+ a2j_debug ("alsa_out: invalid event of size %d, ignored\n", ev->jack_event.size);
+ continue; // invalid event
+ }
+
+ snd_seq_ev_set_source (&alsa_event, driver->port_id);
+ snd_seq_ev_set_dest (&alsa_event, ev->port->remote.client, ev->port->remote.port);
+ snd_seq_ev_set_direct (&alsa_event);
+
+ now = jack_frame_time (driver->jack_client);
+
+ ev->time += driver->cycle_start;
+
+ a2j_debug ("alsa_out:@ %d, next event @ %d", now, ev->time);
+
+ /* do we need to wait a while before delivering? */
+
+ if (ev->time > now) {
+ struct timespec nanoseconds;
+ jack_nframes_t sleep_frames = ev->time - now;
+ float seconds = sleep_frames / sr;
+
+ /* if the gap is long enough, sleep */
+
+ if (seconds > 0.001) {
+ nanoseconds.tv_sec = (time_t)seconds;
+ nanoseconds.tv_nsec = (long)NSEC_PER_SEC * (seconds - nanoseconds.tv_sec);
+
+ a2j_debug ("alsa_out: output thread sleeps for %.2f msec", ((double)nanoseconds.tv_nsec / NSEC_PER_SEC) * 1000.0);
+
+ if (nanosleep (&nanoseconds, NULL) < 0) {
+ fprintf (stderr, "BAD SLEEP\n");
+ /* do something ? */
+ }
+ }
+ }
+
+ /* its time to deliver */
+ snd_seq_event_output (driver->seq, &alsa_event);
+ snd_seq_drain_output (driver->seq);
+ now = jack_frame_time (driver->jack_client);
+ a2j_debug ("alsa_out: written %d bytes to %s at %d, DELTA = %d", ev->jack_event.size, ev->port->name, now,
+ (int32_t)(now - ev->time));
+ }
+
+ /* free up space in the FIFO */
+
+ jack_ringbuffer_read_advance (driver->outbound_events, vec[0].len + vec[1].len);
+
+ /* and head back for more */
+ }
+
+ return (void*)0;
}
/** CORE JACK PROCESSING */
@@ -578,56 +577,54 @@ alsa_output_thread(void * arg)
static void
a2j_jack_process_internal (alsa_midi_driver_t* driver, int dir, jack_nframes_t nframes)
{
- struct a2j_stream * stream_ptr;
- int i;
- struct a2j_port ** port_ptr_ptr;
- struct a2j_port * port_ptr;
- int nevents = 0;
-
- stream_ptr = &driver->stream[dir];
- a2j_add_ports(stream_ptr);
-
- // process ports
- for (i = 0 ; i < PORT_HASH_SIZE ; i++)
- {
- port_ptr_ptr = &stream_ptr->port_hash[i];
- while (*port_ptr_ptr != NULL)
- {
- port_ptr = *port_ptr_ptr;
-
- if (!port_ptr->is_dead) {
- port_ptr->jack_buf = jack_port_get_buffer(port_ptr->jack_port, nframes);
-
- if (dir == A2J_PORT_CAPTURE) {
- a2j_process_incoming (driver, port_ptr, nframes);
- } else {
- nevents += a2j_process_outgoing (driver, port_ptr);
- }
-
- } else if (jack_ringbuffer_write_space (driver->port_del) >= sizeof(port_ptr)) {
-
- a2j_debug("jack: removed port %s", port_ptr->name);
- *port_ptr_ptr = port_ptr->next;
- jack_ringbuffer_write(driver->port_del, (char*)&port_ptr, sizeof(port_ptr));
- nevents += 1; /* wake up output thread, see: a2j_free_ports */
- continue;
-
- }
-
- port_ptr_ptr = &port_ptr->next;
- }
- }
-
- if (dir == A2J_PORT_PLAYBACK && nevents > 0) {
- int sv;
-
- /* if we queued up anything for output, tell the output thread in
- case its waiting for us.
- */
-
- sem_getvalue (&driver->output_semaphore, &sv);
- sem_post (&driver->output_semaphore);
- }
+ struct a2j_stream * stream_ptr;
+ int i;
+ struct a2j_port ** port_ptr_ptr;
+ struct a2j_port * port_ptr;
+ int nevents = 0;
+
+ stream_ptr = &driver->stream[dir];
+ a2j_add_ports (stream_ptr);
+
+ // process ports
+ for (i = 0; i < PORT_HASH_SIZE; i++) {
+ port_ptr_ptr = &stream_ptr->port_hash[i];
+ while (*port_ptr_ptr != NULL) {
+ port_ptr = *port_ptr_ptr;
+
+ if (!port_ptr->is_dead) {
+ port_ptr->jack_buf = jack_port_get_buffer (port_ptr->jack_port, nframes);
+
+ if (dir == A2J_PORT_CAPTURE) {
+ a2j_process_incoming (driver, port_ptr, nframes);
+ } else {
+ nevents += a2j_process_outgoing (driver, port_ptr);
+ }
+
+ } else if (jack_ringbuffer_write_space (driver->port_del) >= sizeof(port_ptr)) {
+
+ a2j_debug ("jack: removed port %s", port_ptr->name);
+ *port_ptr_ptr = port_ptr->next;
+ jack_ringbuffer_write (driver->port_del, (char*)&port_ptr, sizeof(port_ptr));
+ nevents += 1; /* wake up output thread, see: a2j_free_ports */
+ continue;
+
+ }
+
+ port_ptr_ptr = &port_ptr->next;
+ }
+ }
+
+ if (dir == A2J_PORT_PLAYBACK && nevents > 0) {
+ int sv;
+
+ /* if we queued up anything for output, tell the output thread in
+ case its waiting for us.
+ */
+
+ sem_getvalue (&driver->output_semaphore, &sv);
+ sem_post (&driver->output_semaphore);
+ }
}
/* JACK DRIVER FUNCTIONS */
@@ -635,178 +632,178 @@ a2j_jack_process_internal (alsa_midi_driver_t* driver, int dir, jack_nframes_t n
static int
alsa_midi_read (alsa_midi_driver_t* driver, jack_nframes_t nframes)
{
- driver->cycle_start = jack_last_frame_time (driver->jack_client);
- a2j_jack_process_internal (driver, A2J_PORT_CAPTURE, nframes);
- return 0;
+ driver->cycle_start = jack_last_frame_time (driver->jack_client);
+ a2j_jack_process_internal (driver, A2J_PORT_CAPTURE, nframes);
+ return 0;
}
static int
alsa_midi_write (alsa_midi_driver_t* driver, jack_nframes_t nframes)
{
- driver->cycle_start = jack_last_frame_time (driver->jack_client);
- a2j_jack_process_internal (driver, A2J_PORT_PLAYBACK, nframes);
- return 0;
+ driver->cycle_start = jack_last_frame_time (driver->jack_client);
+ a2j_jack_process_internal (driver, A2J_PORT_PLAYBACK, nframes);
+ return 0;
}
-static int
+static int
alsa_midi_start (alsa_midi_driver_t* driver)
{
- int error;
-
- snd_seq_start_queue (driver->seq, driver->queue, 0);
- snd_seq_drop_input (driver->seq);
-
- a2j_add_ports(&driver->stream[A2J_PORT_CAPTURE]);
- a2j_add_ports(&driver->stream[A2J_PORT_PLAYBACK]);
-
- driver->running = true;
-
- if (pthread_create(&driver->alsa_input_thread, NULL, alsa_input_thread, driver) < 0) {
- a2j_error("cannot start ALSA input thread");
- return -1;
- }
-
- /* wake the poll loop in the alsa input thread so initial ports are fetched */
- if ((error = snd_seq_connect_from (driver->seq, driver->port_id, SND_SEQ_CLIENT_SYSTEM, SND_SEQ_PORT_SYSTEM_ANNOUNCE)) < 0) {
- a2j_error("snd_seq_connect_from() failed");
- return -1;
- }
-
- if (pthread_create(&driver->alsa_output_thread, NULL, alsa_output_thread, driver) < 0) {
- a2j_error("cannot start ALSA output thread");
- return -1;
- }
-
- return 0;
+ int error;
+
+ snd_seq_start_queue (driver->seq, driver->queue, 0);
+ snd_seq_drop_input (driver->seq);
+
+ a2j_add_ports (&driver->stream[A2J_PORT_CAPTURE]);
+ a2j_add_ports (&driver->stream[A2J_PORT_PLAYBACK]);
+
+ driver->running = true;
+
+ if (pthread_create (&driver->alsa_input_thread, NULL, alsa_input_thread, driver) < 0) {
+ a2j_error ("cannot start ALSA input thread");
+ return -1;
+ }
+
+ /* wake the poll loop in the alsa input thread so initial ports are fetched */
+ if ((error = snd_seq_connect_from (driver->seq, driver->port_id, SND_SEQ_CLIENT_SYSTEM, SND_SEQ_PORT_SYSTEM_ANNOUNCE)) < 0) {
+ a2j_error ("snd_seq_connect_from() failed");
+ return -1;
+ }
+
+ if (pthread_create (&driver->alsa_output_thread, NULL, alsa_output_thread, driver) < 0) {
+ a2j_error ("cannot start ALSA output thread");
+ return -1;
+ }
+
+ return 0;
}
static int
alsa_midi_stop (alsa_midi_driver_t* driver)
{
- stop_threads (driver);
+ stop_threads (driver);
- (void) snd_seq_stop_queue (driver->seq, driver->queue, 0);
- return 0;
+ (void)snd_seq_stop_queue (driver->seq, driver->queue, 0);
+ return 0;
}
static int
alsa_midi_attach (alsa_midi_driver_t* driver, jack_engine_t* engine)
{
- int error;
-
- driver->port_del = jack_ringbuffer_create(2 * MAX_PORTS * sizeof(struct a2j_port *));
- if (driver->port_del == NULL) {
- return -1;
- }
-
- driver->outbound_events = jack_ringbuffer_create (MAX_EVENT_SIZE * 16 * sizeof(struct a2j_delivery_event));
- if (driver->outbound_events == NULL) {
- return -1;
- }
-
- if (!a2j_stream_init (driver, A2J_PORT_CAPTURE)) {
- return -1;
- }
-
- if (!a2j_stream_init (driver, A2J_PORT_PLAYBACK)) {
- return -1;
- }
-
- if ((error = snd_seq_open(&driver->seq, "hw", SND_SEQ_OPEN_DUPLEX, 0)) < 0) {
- a2j_error("failed to open alsa seq");
- return -1;
- }
-
- if ((error = snd_seq_set_client_name(driver->seq, "jackmidi")) < 0) {
- a2j_error("snd_seq_set_client_name() failed");
- return -1;
- }
-
- if ((driver->port_id = snd_seq_create_simple_port(
- driver->seq,
- "port",
- SND_SEQ_PORT_CAP_READ|SND_SEQ_PORT_CAP_WRITE
+ int error;
+
+ driver->port_del = jack_ringbuffer_create (2 * MAX_PORTS * sizeof(struct a2j_port *));
+ if (driver->port_del == NULL) {
+ return -1;
+ }
+
+ driver->outbound_events = jack_ringbuffer_create (MAX_EVENT_SIZE * 16 * sizeof(struct a2j_delivery_event));
+ if (driver->outbound_events == NULL) {
+ return -1;
+ }
+
+ if (!a2j_stream_init (driver, A2J_PORT_CAPTURE)) {
+ return -1;
+ }
+
+ if (!a2j_stream_init (driver, A2J_PORT_PLAYBACK)) {
+ return -1;
+ }
+
+ if ((error = snd_seq_open (&driver->seq, "hw", SND_SEQ_OPEN_DUPLEX, 0)) < 0) {
+ a2j_error ("failed to open alsa seq");
+ return -1;
+ }
+
+ if ((error = snd_seq_set_client_name (driver->seq, "jackmidi")) < 0) {
+ a2j_error ("snd_seq_set_client_name() failed");
+ return -1;
+ }
+
+ if ((driver->port_id = snd_seq_create_simple_port (
+ driver->seq,
+ "port",
+ SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_WRITE
#ifndef DEBUG
- |SND_SEQ_PORT_CAP_NO_EXPORT
+ | SND_SEQ_PORT_CAP_NO_EXPORT
#endif
- ,SND_SEQ_PORT_TYPE_APPLICATION)) < 0) {
-
- a2j_error("snd_seq_create_simple_port() failed");
- return -1;
- }
-
- if ((driver->client_id = snd_seq_client_id(driver->seq)) < 0) {
- a2j_error("snd_seq_client_id() failed");
- return -1;
- }
-
- if ((driver->queue = snd_seq_alloc_queue(driver->seq)) < 0) {
- a2j_error("snd_seq_alloc_queue() failed");
- return -1;
- }
-
- if ((error = snd_seq_nonblock(driver->seq, 1)) < 0) {
- a2j_error("snd_seq_nonblock() failed");
- return -1;
- }
-
- return jack_activate (driver->jack_client);
+ , SND_SEQ_PORT_TYPE_APPLICATION)) < 0) {
+
+ a2j_error ("snd_seq_create_simple_port() failed");
+ return -1;
+ }
+
+ if ((driver->client_id = snd_seq_client_id (driver->seq)) < 0) {
+ a2j_error ("snd_seq_client_id() failed");
+ return -1;
+ }
+
+ if ((driver->queue = snd_seq_alloc_queue (driver->seq)) < 0) {
+ a2j_error ("snd_seq_alloc_queue() failed");
+ return -1;
+ }
+
+ if ((error = snd_seq_nonblock (driver->seq, 1)) < 0) {
+ a2j_error ("snd_seq_nonblock() failed");
+ return -1;
+ }
+
+ return jack_activate (driver->jack_client);
}
static int
alsa_midi_detach (alsa_midi_driver_t* driver, jack_engine_t* engine)
{
- driver->finishing = true;
-
- snd_seq_close (driver->seq);
- driver->seq = NULL;
- return 0;
+ driver->finishing = true;
+
+ snd_seq_close (driver->seq);
+ driver->seq = NULL;
+ return 0;
}
static jack_driver_t *
alsa_midi_driver_new (jack_client_t *client, const char *name)
{
- alsa_midi_driver_t* driver = calloc(1, sizeof(alsa_midi_driver_t));
+ alsa_midi_driver_t* driver = calloc (1, sizeof(alsa_midi_driver_t));
- jack_info ("creating alsa_midi driver ...");
+ jack_info ("creating alsa_midi driver ...");
if (!driver) {
return NULL;
}
- jack_driver_init ((jack_driver_t *) driver);
+ jack_driver_init ((jack_driver_t*)driver);
- driver->attach = (JackDriverAttachFunction) alsa_midi_attach;
- driver->detach = (JackDriverDetachFunction) alsa_midi_detach;
- driver->read = (JackDriverReadFunction) alsa_midi_read;
- driver->write = (JackDriverWriteFunction) alsa_midi_write;
- driver->start = (JackDriverStartFunction) alsa_midi_start;
- driver->stop = (JackDriverStartFunction) alsa_midi_stop;
+ driver->attach = (JackDriverAttachFunction)alsa_midi_attach;
+ driver->detach = (JackDriverDetachFunction)alsa_midi_detach;
+ driver->read = (JackDriverReadFunction)alsa_midi_read;
+ driver->write = (JackDriverWriteFunction)alsa_midi_write;
+ driver->start = (JackDriverStartFunction)alsa_midi_start;
+ driver->stop = (JackDriverStartFunction)alsa_midi_stop;
driver->jack_client = client;
- if (sem_init(&driver->output_semaphore, 0, 0) < 0) {
- a2j_error ("can't create IO semaphore");
- free (driver);
- return NULL;
- }
+ if (sem_init (&driver->output_semaphore, 0, 0) < 0) {
+ a2j_error ("can't create IO semaphore");
+ free (driver);
+ return NULL;
+ }
- return (jack_driver_t *) driver;
+ return (jack_driver_t*)driver;
}
static void
alsa_midi_driver_delete (alsa_midi_driver_t* driver)
{
- a2j_stream_detach (&driver->stream[A2J_PORT_CAPTURE]);
- a2j_stream_detach (&driver->stream[A2J_PORT_PLAYBACK]);
- a2j_stream_close (driver, A2J_PORT_CAPTURE);
- a2j_stream_close (driver, A2J_PORT_PLAYBACK);
-
- sem_destroy (&driver->output_semaphore);
-
- jack_ringbuffer_free (driver->outbound_events);
- jack_ringbuffer_free (driver->port_del);
+ a2j_stream_detach (&driver->stream[A2J_PORT_CAPTURE]);
+ a2j_stream_detach (&driver->stream[A2J_PORT_PLAYBACK]);
+ a2j_stream_close (driver, A2J_PORT_CAPTURE);
+ a2j_stream_close (driver, A2J_PORT_PLAYBACK);
+
+ sem_destroy (&driver->output_semaphore);
+
+ jack_ringbuffer_free (driver->outbound_events);
+ jack_ringbuffer_free (driver->port_del);
}
/* DRIVER "PLUGIN" INTERFACE */
@@ -818,14 +815,15 @@ driver_get_descriptor ()
{
jack_driver_desc_t * desc;
jack_driver_param_desc_t * params;
+
//unsigned int i;
- desc = calloc (1, sizeof (jack_driver_desc_t));
+ desc = calloc (1, sizeof(jack_driver_desc_t));
- strcpy (desc->name,"alsa_midi");
+ strcpy (desc->name, "alsa_midi");
desc->nparams = 0;
-
- params = calloc (desc->nparams, sizeof (jack_driver_param_desc_t));
+
+ params = calloc (desc->nparams, sizeof(jack_driver_param_desc_t));
desc->params = params;
@@ -839,19 +837,19 @@ driver_initialize (jack_client_t *client, const JSList * params)
const jack_driver_param_t * param;
for (node = params; node; node = jack_slist_next (node)) {
- param = (const jack_driver_param_t *) node->data;
+ param = (const jack_driver_param_t*)node->data;
switch (param->character) {
- default:
- break;
+ default:
+ break;
}
}
-
+
return alsa_midi_driver_new (client, NULL);
}
void
driver_finish (jack_driver_t *driver)
{
- alsa_midi_driver_delete ((alsa_midi_driver_t *) driver);
+ alsa_midi_driver_delete ((alsa_midi_driver_t*)driver);
}
diff --git a/drivers/alsa_midi/alsa_midi_driver.c b/drivers/alsa_midi/alsa_midi_driver.c
index e25479f..92aaccd 100644
--- a/drivers/alsa_midi/alsa_midi_driver.c
+++ b/drivers/alsa_midi/alsa_midi_driver.c
@@ -3,45 +3,45 @@
#include <string.h>
static int
-alsa_midi_driver_attach( alsa_midi_driver_t *driver, jack_engine_t *engine )
+alsa_midi_driver_attach ( alsa_midi_driver_t *driver, jack_engine_t *engine )
{
- return driver->midi->attach(driver->midi);
+ return driver->midi->attach (driver->midi);
}
static int
-alsa_midi_driver_detach( alsa_midi_driver_t *driver, jack_engine_t *engine )
+alsa_midi_driver_detach ( alsa_midi_driver_t *driver, jack_engine_t *engine )
{
- return driver->midi->detach(driver->midi);
+ return driver->midi->detach (driver->midi);
}
static int
-alsa_midi_driver_read( alsa_midi_driver_t *driver, jack_nframes_t nframes )
+alsa_midi_driver_read ( alsa_midi_driver_t *driver, jack_nframes_t nframes )
{
- driver->midi->read(driver->midi, nframes);
+ driver->midi->read (driver->midi, nframes);
return 0;
}
static int
-alsa_midi_driver_write( alsa_midi_driver_t *driver, jack_nframes_t nframes )
+alsa_midi_driver_write ( alsa_midi_driver_t *driver, jack_nframes_t nframes )
{
- driver->midi->write(driver->midi, nframes);
+ driver->midi->write (driver->midi, nframes);
return 0;
}
static int
-alsa_midi_driver_start( alsa_midi_driver_t *driver )
+alsa_midi_driver_start ( alsa_midi_driver_t *driver )
{
- return driver->midi->start(driver->midi);
+ return driver->midi->start (driver->midi);
}
static int
-alsa_midi_driver_stop( alsa_midi_driver_t *driver )
+alsa_midi_driver_stop ( alsa_midi_driver_t *driver )
{
- return driver->midi->stop(driver->midi);
+ return driver->midi->stop (driver->midi);
}
static void
-alsa_midi_driver_delete( alsa_midi_driver_t *driver )
+alsa_midi_driver_delete ( alsa_midi_driver_t *driver )
{
}
diff --git a/drivers/alsa_midi/list.c b/drivers/alsa_midi/list.c
index 438066c..d646878 100644
--- a/drivers/alsa_midi/list.c
+++ b/drivers/alsa_midi/list.c
@@ -1,22 +1,22 @@
/* -*- Mode: C ; c-basic-offset: 2 -*- */
/*****************************************************************************
- *
- * list_sort() adapted from linux kernel.
- *
- * 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; version 2 of the License
- *
- * 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- *****************************************************************************/
+*
+* list_sort() adapted from linux kernel.
+*
+* 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; version 2 of the License
+*
+* 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+*
+*****************************************************************************/
#include <assert.h>
@@ -24,124 +24,131 @@
/* list sort from Mark J Roberts (mjr@znex.org) */
void
-__list_sort(
- struct list_head *head,
- int member_offset,
- int (*cmp)(void * a, void * b))
+__list_sort (
+ struct list_head *head,
+ int member_offset,
+ int (*cmp)(void * a, void * b))
{
- struct list_head *p, *q, *e, *list, *tail, *oldhead;
- int insize, nmerges, psize, qsize, i;
-
- list = head->next;
- list_del(head);
- insize = 1;
- for (;;) {
- p = oldhead = list;
- list = tail = NULL;
- nmerges = 0;
-
- while (p) {
- nmerges++;
- q = p;
- psize = 0;
- for (i = 0; i < insize; i++) {
- psize++;
- q = q->next == oldhead ? NULL : q->next;
- if (!q)
- break;
- }
-
- qsize = insize;
- while (psize > 0 || (qsize > 0 && q)) {
- if (!psize) {
- e = q;
- q = q->next;
- qsize--;
- if (q == oldhead)
- q = NULL;
- } else if (!qsize || !q) {
- e = p;
- p = p->next;
- psize--;
- if (p == oldhead)
- p = NULL;
- } else if (cmp((void *)p - member_offset, (void *)q - member_offset) <= 0) {
- e = p;
- p = p->next;
- psize--;
- if (p == oldhead)
- p = NULL;
- } else {
- e = q;
- q = q->next;
- qsize--;
- if (q == oldhead)
- q = NULL;
- }
- if (tail)
- tail->next = e;
- else
- list = e;
- e->prev = tail;
- tail = e;
- }
- p = q;
- }
-
- tail->next = list;
- list->prev = tail;
-
- if (nmerges <= 1)
- break;
-
- insize *= 2;
- }
-
- head->next = list;
- head->prev = list->prev;
- list->prev->next = head;
- list->prev = head;
+ struct list_head *p, *q, *e, *list, *tail, *oldhead;
+ int insize, nmerges, psize, qsize, i;
+
+ list = head->next;
+ list_del (head);
+ insize = 1;
+ for (;; ) {
+ p = oldhead = list;
+ list = tail = NULL;
+ nmerges = 0;
+
+ while (p) {
+ nmerges++;
+ q = p;
+ psize = 0;
+ for (i = 0; i < insize; i++) {
+ psize++;
+ q = q->next == oldhead ? NULL : q->next;
+ if (!q) {
+ break;
+ }
+ }
+
+ qsize = insize;
+ while (psize > 0 || (qsize > 0 && q)) {
+ if (!psize) {
+ e = q;
+ q = q->next;
+ qsize--;
+ if (q == oldhead) {
+ q = NULL;
+ }
+ } else if (!qsize || !q) {
+ e = p;
+ p = p->next;
+ psize--;
+ if (p == oldhead) {
+ p = NULL;
+ }
+ } else if (cmp ((void*)p - member_offset, (void*)q - member_offset) <= 0) {
+ e = p;
+ p = p->next;
+ psize--;
+ if (p == oldhead) {
+ p = NULL;
+ }
+ } else {
+ e = q;
+ q = q->next;
+ qsize--;
+ if (q == oldhead) {
+ q = NULL;
+ }
+ }
+ if (tail) {
+ tail->next = e;
+ } else {
+ list = e;
+ }
+ e->prev = tail;
+ tail = e;
+ }
+ p = q;
+ }
+
+ tail->next = list;
+ list->prev = tail;
+
+ if (nmerges <= 1) {
+ break;
+ }
+
+ insize *= 2;
+ }
+
+ head->next = list;
+ head->prev = list->prev;
+ list->prev->next = head;
+ list->prev = head;
}
struct test_list_el {
- int value;
- struct list_head test_list_node;
+ int value;
+ struct list_head test_list_node;
};
-int test_list_sort_comparator(struct test_list_el * e1, struct test_list_el * e2)
+int test_list_sort_comparator (struct test_list_el * e1, struct test_list_el * e2)
{
- return e1->value - e2->value;
+ return e1->value - e2->value;
}
-void test_list_sort(void)
+void test_list_sort (void)
{
- struct list_head test_list;
- struct test_list_el *el, *next;
- struct test_list_el te1 = {.value = 1};
- struct test_list_el te2 = {.value = 2};
- struct test_list_el te3 = {.value = 3};
- struct test_list_el te4 = {.value = 4};
- struct test_list_el te5 = {.value = 5};
- struct test_list_el te6 = {.value = 6};
- struct test_list_el te7 = {.value = 7};
-
- const int expected[] = {1, 2, 3, 4, 5, 6, 7};
- int i;
-
- INIT_LIST_HEAD(&test_list);
- list_add_tail(&te2.test_list_node, &test_list);
- list_add_tail(&te6.test_list_node, &test_list);
- list_add_tail(&te4.test_list_node, &test_list);
- list_add_tail(&te5.test_list_node, &test_list);
- list_add_tail(&te7.test_list_node, &test_list);
- list_add_tail(&te1.test_list_node, &test_list);
- list_add_tail(&te3.test_list_node, &test_list);
-
- list_sort(&test_list, struct test_list_el, test_list_node, test_list_sort_comparator);
-
- i = 0;
- list_for_each_entry_safe(el, next, &test_list, test_list_node) {
- assert(el->value == expected[i]);
- i++;
- }
+ struct list_head test_list;
+ struct test_list_el *el, *next;
+ struct test_list_el te1 = { .value = 1 };
+ struct test_list_el te2 = { .value = 2 };
+ struct test_list_el te3 = { .value = 3 };
+ struct test_list_el te4 = { .value = 4 };
+ struct test_list_el te5 = { .value = 5 };
+ struct test_list_el te6 = { .value = 6 };
+ struct test_list_el te7 = { .value = 7 };
+
+ const int expected[] = { 1, 2, 3, 4, 5, 6, 7 };
+ int i;
+
+ INIT_LIST_HEAD (&test_list);
+ list_add_tail (&te2.test_list_node, &test_list);
+ list_add_tail (&te6.test_list_node, &test_list);
+ list_add_tail (&te4.test_list_node, &test_list);
+ list_add_tail (&te5.test_list_node, &test_list);
+ list_add_tail (&te7.test_list_node, &test_list);
+ list_add_tail (&te1.test_list_node, &test_list);
+ list_add_tail (&te3.test_list_node, &test_list);
+
+ list_sort (&test_list, struct test_list_el, test_list_node, test_list_sort_comparator);
+
+ i = 0;
+ list_for_each_entry_safe (el, next, &test_list, test_list_node) {
+ assert (el->value == expected[i]);
+ i++;
+ }
}
diff --git a/drivers/alsa_midi/list.h b/drivers/alsa_midi/list.h
index 5b7f4d4..6e933b9 100644
--- a/drivers/alsa_midi/list.h
+++ b/drivers/alsa_midi/list.h
@@ -1,26 +1,26 @@
/* -*- Mode: C ; c-basic-offset: 2 -*- */
/*****************************************************************************
- *
- * Linux kernel header adapted for user-mode
- * The 2.6.17-rt1 version was used.
- *
- * Original copyright holders of this code are unknown, they were not
- * mentioned in the original file.
- *
- * 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; version 2 of the License
- *
- * 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- *****************************************************************************/
+*
+* Linux kernel header adapted for user-mode
+* The 2.6.17-rt1 version was used.
+*
+* Original copyright holders of this code are unknown, they were not
+* mentioned in the original file.
+*
+* 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; version 2 of the License
+*
+* 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+*
+*****************************************************************************/
#ifndef _LINUX_LIST_H
#define _LINUX_LIST_H
@@ -28,7 +28,7 @@
#include <stddef.h>
#if !defined(offsetof)
-#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
+#define offsetof(TYPE, MEMBER) ((size_t)&((TYPE*)0)->MEMBER)
#endif
/**
@@ -39,8 +39,8 @@
*
*/
#define container_of(ptr, type, member) ({ \
- const typeof( ((type *)0)->member ) *__mptr = (ptr); \
- (type *)( (char *)__mptr - offsetof(type,member) );})
+ const typeof( ((type*)0)->member ) * __mptr = (ptr); \
+ (type*)( (char*)__mptr - offsetof (type, member) ); })
#define prefetch(x) (x = x)
@@ -49,8 +49,8 @@
* under normal circumstances, used to verify that nobody uses
* non-initialized list entries.
*/
-#define LIST_POISON1 ((void *) 0x00100100)
-#define LIST_POISON2 ((void *) 0x00200200)
+#define LIST_POISON1 ((void*)0x00100100)
+#define LIST_POISON2 ((void*)0x00200200)
/*
* Simple doubly linked list implementation.
@@ -63,18 +63,18 @@
*/
struct list_head {
- struct list_head *next, *prev;
+ struct list_head *next, *prev;
};
#define LIST_HEAD_INIT(name) { &(name), &(name) }
-#define LIST_HEAD(name) \
- struct list_head name = LIST_HEAD_INIT(name)
+#define LIST_HEAD(name) \
+ struct list_head name = LIST_HEAD_INIT (name)
-static inline void INIT_LIST_HEAD(struct list_head *list)
+static inline void INIT_LIST_HEAD (struct list_head *list)
{
- list->next = list;
- list->prev = list;
+ list->next = list;
+ list->prev = list;
}
/*
@@ -83,14 +83,14 @@ static inline void INIT_LIST_HEAD(struct list_head *list)
* This is only for internal list manipulation where we know
* the prev/next entries already!
*/
-static inline void __list_add(struct list_head *new,
- struct list_head *prev,
- struct list_head *next)
+static inline void __list_add (struct list_head *new,
+ struct list_head *prev,
+ struct list_head *next)
{
- next->prev = new;
- new->next = next;
- new->prev = prev;
- prev->next = new;
+ next->prev = new;
+ new->next = next;
+ new->prev = prev;
+ prev->next = new;
}
/**
@@ -101,9 +101,9 @@ static inline void __list_add(struct list_head *new,
* Insert a new entry after the specified head.
* This is good for implementing stacks.
*/
-static inline void list_add(struct list_head *new, struct list_head *head)
+static inline void list_add (struct list_head *new, struct list_head *head)
{
- __list_add(new, head, head->next);
+ __list_add (new, head, head->next);
}
/**
@@ -114,9 +114,9 @@ static inline void list_add(struct list_head *new, struct list_head *head)
* Insert a new entry before the specified head.
* This is useful for implementing queues.
*/
-static inline void list_add_tail(struct list_head *new, struct list_head *head)
+static inline void list_add_tail (struct list_head *new, struct list_head *head)
{
- __list_add(new, head->prev, head);
+ __list_add (new, head->prev, head);
}
/*
@@ -125,14 +125,14 @@ static inline void list_add_tail(struct list_head *new, struct list_head *head)
* This is only for internal list manipulation where we know
* the prev/next entries already!
*/
-static inline void __list_add_rcu(struct list_head * new,
- struct list_head * prev, struct list_head * next)
+static inline void __list_add_rcu (struct list_head * new,
+ struct list_head * prev, struct list_head * next)
{
- new->next = next;
- new->prev = prev;
+ new->next = next;
+ new->prev = prev;
// smp_wmb();
- next->prev = new;
- prev->next = new;
+ next->prev = new;
+ prev->next = new;
}
/**
@@ -151,9 +151,9 @@ static inline void __list_add_rcu(struct list_head * new,
* the _rcu list-traversal primitives, such as
* list_for_each_entry_rcu().
*/
-static inline void list_add_rcu(struct list_head *new, struct list_head *head)
+static inline void list_add_rcu (struct list_head *new, struct list_head *head)
{
- __list_add_rcu(new, head, head->next);
+ __list_add_rcu (new, head, head->next);
}
/**
@@ -172,10 +172,10 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
* the _rcu list-traversal primitives, such as
* list_for_each_entry_rcu().
*/
-static inline void list_add_tail_rcu(struct list_head *new,
- struct list_head *head)
+static inline void list_add_tail_rcu (struct list_head *new,
+ struct list_head *head)
{
- __list_add_rcu(new, head->prev, head);
+ __list_add_rcu (new, head->prev, head);
}
/*
@@ -185,10 +185,10 @@ static inline void list_add_tail_rcu(struct list_head *new,
* This is only for internal list manipulation where we know
* the prev/next entries already!
*/
-static inline void __list_del(struct list_head * prev, struct list_head * next)
+static inline void __list_del (struct list_head * prev, struct list_head * next)
{
- next->prev = prev;
- prev->next = next;
+ next->prev = prev;
+ prev->next = next;
}
/**
@@ -197,11 +197,11 @@ static inline void __list_del(struct list_head * prev, struct list_head * next)
* Note: list_empty on entry does not return true after this, the entry is
* in an undefined state.
*/
-static inline void list_del(struct list_head *entry)
+static inline void list_del (struct list_head *entry)
{
- __list_del(entry->prev, entry->next);
- entry->next = LIST_POISON1;
- entry->prev = LIST_POISON2;
+ __list_del (entry->prev, entry->next);
+ entry->next = LIST_POISON1;
+ entry->prev = LIST_POISON2;
}
/**
@@ -228,10 +228,10 @@ static inline void list_del(struct list_head *entry)
* or call_rcu() must be used to defer freeing until an RCU
* grace period has elapsed.
*/
-static inline void list_del_rcu(struct list_head *entry)
+static inline void list_del_rcu (struct list_head *entry)
{
- __list_del(entry->prev, entry->next);
- entry->prev = LIST_POISON2;
+ __list_del (entry->prev, entry->next);
+ entry->prev = LIST_POISON2;
}
/*
@@ -241,25 +241,25 @@ static inline void list_del_rcu(struct list_head *entry)
*
* The old entry will be replaced with the new entry atomically.
*/
-static inline void list_replace_rcu(struct list_head *old,
- struct list_head *new)
+static inline void list_replace_rcu (struct list_head *old,
+ struct list_head *new)
{
- new->next = old->next;
- new->prev = old->prev;
+ new->next = old->next;
+ new->prev = old->prev;
// smp_wmb();
- new->next->prev = new;
- new->prev->next = new;
- old->prev = LIST_POISON2;
+ new->next->prev = new;
+ new->prev->next = new;
+ old->prev = LIST_POISON2;
}
/**
* list_del_init - deletes entry from list and reinitialize it.
* @entry: the element to delete from the list.
*/
-static inline void list_del_init(struct list_head *entry)
+static inline void list_del_init (struct list_head *entry)
{
- __list_del(entry->prev, entry->next);
- INIT_LIST_HEAD(entry);
+ __list_del (entry->prev, entry->next);
+ INIT_LIST_HEAD (entry);
}
/**
@@ -267,10 +267,10 @@ static inline void list_del_init(struct list_head *entry)
* @list: the entry to move
* @head: the head that will precede our entry
*/
-static inline void list_move(struct list_head *list, struct list_head *head)
+static inline void list_move (struct list_head *list, struct list_head *head)
{
- __list_del(list->prev, list->next);
- list_add(list, head);
+ __list_del (list->prev, list->next);
+ list_add (list, head);
}
/**
@@ -278,20 +278,20 @@ static inline void list_move(struct list_head *list, struct list_head *head)
* @list: the entry to move
* @head: the head that will follow our entry
*/
-static inline void list_move_tail(struct list_head *list,
- struct list_head *head)
+static inline void list_move_tail (struct list_head *list,
+ struct list_head *head)
{
- __list_del(list->prev, list->next);
- list_add_tail(list, head);
+ __list_del (list->prev, list->next);
+ list_add_tail (list, head);
}
/**
* list_empty - tests whether a list is empty
* @head: the list to test.
*/
-static inline int list_empty(const struct list_head *head)
+static inline int list_empty (const struct list_head *head)
{
- return head->next == head;
+ return head->next == head;
}
/**
@@ -306,24 +306,25 @@ static inline int list_empty(const struct list_head *head)
*
* @head: the list to test.
*/
-static inline int list_empty_careful(const struct list_head *head)
+static inline int list_empty_careful (const struct list_head *head)
{
- struct list_head *next = head->next;
- return (next == head) && (next == head->prev);
+ struct list_head *next = head->next;
+
+ return (next == head) && (next == head->prev);
}
-static inline void __list_splice(struct list_head *list,
- struct list_head *head)
+static inline void __list_splice (struct list_head *list,
+ struct list_head *head)
{
- struct list_head *first = list->next;
- struct list_head *last = list->prev;
- struct list_head *at = head->next;
+ struct list_head *first = list->next;
+ struct list_head *last = list->prev;
+ struct list_head *at = head->next;
- first->prev = head;
- head->next = first;
+ first->prev = head;
+ head->next = first;
- last->next = at;
- at->prev = last;
+ last->next = at;
+ at->prev = last;
}
/**
@@ -331,10 +332,11 @@ static inline void __list_splice(struct list_head *list,
* @list: the new list to add.
* @head: the place to add it in the first list.
*/
-static inline void list_splice(struct list_head *list, struct list_head *head)
+static inline void list_splice (struct list_head *list, struct list_head *head)
{
- if (!list_empty(list))
- __list_splice(list, head);
+ if (!list_empty (list)) {
+ __list_splice (list, head);
+ }
}
/**
@@ -344,13 +346,13 @@ static inline void list_splice(struct list_head *list, struct list_head *head)
*
* The list at @list is reinitialised
*/
-static inline void list_splice_init(struct list_head *list,
- struct list_head *head)
+static inline void list_splice_init (struct list_head *list,
+ struct list_head *head)
{
- if (!list_empty(list)) {
- __list_splice(list, head);
- INIT_LIST_HEAD(list);
- }
+ if (!list_empty (list)) {
+ __list_splice (list, head);
+ INIT_LIST_HEAD (list);
+ }
}
/**
@@ -360,7 +362,7 @@ static inline void list_splice_init(struct list_head *list,
* @member: the name of the list_struct within the struct.
*/
#define list_entry(ptr, type, member) \
- container_of(ptr, type, member)
+ container_of (ptr, type, member)
/**
* list_for_each - iterate over a list
@@ -368,8 +370,8 @@ static inline void list_splice_init(struct list_head *list,
* @head: the head for your list.
*/
#define list_for_each(pos, head) \
- for (pos = (head)->next; prefetch(pos->next), pos != (head); \
- pos = pos->next)
+ for (pos = (head)->next; prefetch (pos->next), pos != (head); \
+ pos = pos->next)
/**
* __list_for_each - iterate over a list
@@ -382,7 +384,7 @@ static inline void list_splice_init(struct list_head *list,
* or 1 entry) most of the time.
*/
#define __list_for_each(pos, head) \
- for (pos = (head)->next; pos != (head); pos = pos->next)
+ for (pos = (head)->next; pos != (head); pos = pos->next)
/**
* list_for_each_prev - iterate over a list backwards
@@ -390,8 +392,8 @@ static inline void list_splice_init(struct list_head *list,
* @head: the head for your list.
*/
#define list_for_each_prev(pos, head) \
- for (pos = (head)->prev; prefetch(pos->prev), pos != (head); \
- pos = pos->prev)
+ for (pos = (head)->prev; prefetch (pos->prev), pos != (head); \
+ pos = pos->prev)
/**
* list_for_each_safe - iterate over a list safe against removal of list entry
@@ -400,8 +402,8 @@ static inline void list_splice_init(struct list_head *list,
* @head: the head for your list.
*/
#define list_for_each_safe(pos, n, head) \
- for (pos = (head)->next, n = pos->next; pos != (head); \
- pos = n, n = pos->next)
+ for (pos = (head)->next, n = pos->next; pos != (head); \
+ pos = n, n = pos->next)
/**
* list_for_each_entry - iterate over list of given type
@@ -409,10 +411,10 @@ static inline void list_splice_init(struct list_head *list,
* @head: the head for your list.
* @member: the name of the list_struct within the struct.
*/
-#define list_for_each_entry(pos, head, member) \
- for (pos = list_entry((head)->next, typeof(*pos), member); \
- prefetch(pos->member.next), &pos->member != (head); \
- pos = list_entry(pos->member.next, typeof(*pos), member))
+#define list_for_each_entry(pos, head, member) \
+ for (pos = list_entry ((head)->next, typeof(*pos), member); \
+ prefetch (pos->member.next), &pos->member != (head); \
+ pos = list_entry (pos->member.next, typeof(*pos), member))
/**
* list_for_each_entry_reverse - iterate backwards over list of given type.
@@ -420,10 +422,10 @@ static inline void list_splice_init(struct list_head *list,
* @head: the head for your list.
* @member: the name of the list_struct within the struct.
*/
-#define list_for_each_entry_reverse(pos, head, member) \
- for (pos = list_entry((head)->prev, typeof(*pos), member); \
- prefetch(pos->member.prev), &pos->member != (head); \
- pos = list_entry(pos->member.prev, typeof(*pos), member))
+#define list_for_each_entry_reverse(pos, head, member) \
+ for (pos = list_entry ((head)->prev, typeof(*pos), member); \
+ prefetch (pos->member.prev), &pos->member != (head); \
+ pos = list_entry (pos->member.prev, typeof(*pos), member))
/**
* list_prepare_entry - prepare a pos entry for use as a start point in
@@ -433,7 +435,7 @@ static inline void list_splice_init(struct list_head *list,
* @member: the name of the list_struct within the struct.
*/
#define list_prepare_entry(pos, head, member) \
- ((pos) ? : list_entry(head, typeof(*pos), member))
+ ((pos) ? : list_entry (head, typeof(*pos), member))
/**
* list_for_each_entry_continue - iterate over list of given type
@@ -442,10 +444,10 @@ static inline void list_splice_init(struct list_head *list,
* @head: the head for your list.
* @member: the name of the list_struct within the struct.
*/
-#define list_for_each_entry_continue(pos, head, member) \
- for (pos = list_entry(pos->member.next, typeof(*pos), member); \
- prefetch(pos->member.next), &pos->member != (head); \
- pos = list_entry(pos->member.next, typeof(*pos), member))
+#define list_for_each_entry_continue(pos, head, member) \
+ for (pos = list_entry (pos->member.next, typeof(*pos), member); \
+ prefetch (pos->member.next), &pos->member != (head); \
+ pos = list_entry (pos->member.next, typeof(*pos), member))
/**
* list_for_each_entry_from - iterate over list of given type
@@ -454,9 +456,9 @@ static inline void list_splice_init(struct list_head *list,
* @head: the head for your list.
* @member: the name of the list_struct within the struct.
*/
-#define list_for_each_entry_from(pos, head, member) \
- for (; prefetch(pos->member.next), &pos->member != (head); \
- pos = list_entry(pos->member.next, typeof(*pos), member))
+#define list_for_each_entry_from(pos, head, member) \
+ for (; prefetch (pos->member.next), &pos->member != (head); \
+ pos = list_entry (pos->member.next, typeof(*pos), member))
/**
* list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
@@ -465,11 +467,11 @@ static inline void list_splice_init(struct list_head *list,
* @head: the head for your list.
* @member: the name of the list_struct within the struct.
*/
-#define list_for_each_entry_safe(pos, n, head, member) \
- for (pos = list_entry((head)->next, typeof(*pos), member), \
- n = list_entry(pos->member.next, typeof(*pos), member); \
- &pos->member != (head); \
- pos = n, n = list_entry(n->member.next, typeof(*n), member))
+#define list_for_each_entry_safe(pos, n, head, member) \
+ for (pos = list_entry ((head)->next, typeof(*pos), member), \
+ n = list_entry (pos->member.next, typeof(*pos), member); \
+ &pos->member != (head); \
+ pos = n, n = list_entry (n->member.next, typeof(*n), member))
/**
* list_for_each_entry_safe_continue - iterate over list of given type
@@ -479,11 +481,11 @@ static inline void list_splice_init(struct list_head *list,
* @head: the head for your list.
* @member: the name of the list_struct within the struct.
*/
-#define list_for_each_entry_safe_continue(pos, n, head, member) \
- for (pos = list_entry(pos->member.next, typeof(*pos), member), \
- n = list_entry(pos->member.next, typeof(*pos), member); \
- &pos->member != (head); \
- pos = n, n = list_entry(n->member.next, typeof(*n), member))
+#define list_for_each_entry_safe_continue(pos, n, head, member) \
+ for (pos = list_entry (pos->member.next, typeof(*pos), member), \
+ n = list_entry (pos->member.next, typeof(*pos), member); \
+ &pos->member != (head); \
+ pos = n, n = list_entry (n->member.next, typeof(*n), member))
/**
* list_for_each_entry_safe_from - iterate over list of given type
@@ -493,10 +495,10 @@ static inline void list_splice_init(struct list_head *list,
* @head: the head for your list.
* @member: the name of the list_struct within the struct.
*/
-#define list_for_each_entry_safe_from(pos, n, head, member) \
- for (n = list_entry(pos->member.next, typeof(*pos), member); \
- &pos->member != (head); \
- pos = n, n = list_entry(n->member.next, typeof(*n), member))
+#define list_for_each_entry_safe_from(pos, n, head, member) \
+ for (n = list_entry (pos->member.next, typeof(*pos), member); \
+ &pos->member != (head); \
+ pos = n, n = list_entry (n->member.next, typeof(*n), member))
/**
* list_for_each_entry_safe_reverse - iterate backwards over list of given type safe against
@@ -506,11 +508,11 @@ static inline void list_splice_init(struct list_head *list,
* @head: the head for your list.
* @member: the name of the list_struct within the struct.
*/
-#define list_for_each_entry_safe_reverse(pos, n, head, member) \
- for (pos = list_entry((head)->prev, typeof(*pos), member), \
- n = list_entry(pos->member.prev, typeof(*pos), member); \
- &pos->member != (head); \
- pos = n, n = list_entry(n->member.prev, typeof(*n), member))
+#define list_for_each_entry_safe_reverse(pos, n, head, member) \
+ for (pos = list_entry ((head)->prev, typeof(*pos), member), \
+ n = list_entry (pos->member.prev, typeof(*pos), member); \
+ &pos->member != (head); \
+ pos = n, n = list_entry (n->member.prev, typeof(*n), member))
/**
* list_for_each_rcu - iterate over an rcu-protected list
@@ -522,14 +524,14 @@ static inline void list_splice_init(struct list_head *list,
* as long as the traversal is guarded by rcu_read_lock().
*/
#define list_for_each_rcu(pos, head) \
- for (pos = (head)->next; \
- prefetch(rcu_dereference(pos)->next), pos != (head); \
- pos = pos->next)
+ for (pos = (head)->next; \
+ prefetch (rcu_dereference (pos)->next), pos != (head); \
+ pos = pos->next)
#define __list_for_each_rcu(pos, head) \
- for (pos = (head)->next; \
- rcu_dereference(pos) != (head); \
- pos = pos->next)
+ for (pos = (head)->next; \
+ rcu_dereference (pos) != (head); \
+ pos = pos->next)
/**
* list_for_each_safe_rcu - iterate over an rcu-protected list safe
@@ -543,9 +545,9 @@ static inline void list_splice_init(struct list_head *list,
* as long as the traversal is guarded by rcu_read_lock().
*/
#define list_for_each_safe_rcu(pos, n, head) \
- for (pos = (head)->next; \
- n = rcu_dereference(pos)->next, pos != (head); \
- pos = n)
+ for (pos = (head)->next; \
+ n = rcu_dereference (pos)->next, pos != (head); \
+ pos = n)
/**
* list_for_each_entry_rcu - iterate over rcu list of given type
@@ -558,10 +560,10 @@ static inline void list_splice_init(struct list_head *list,
* as long as the traversal is guarded by rcu_read_lock().
*/
#define list_for_each_entry_rcu(pos, head, member) \
- for (pos = list_entry((head)->next, typeof(*pos), member); \
- prefetch(rcu_dereference(pos)->member.next), \
- &pos->member != (head); \
- pos = list_entry(pos->member.next, typeof(*pos), member))
+ for (pos = list_entry ((head)->next, typeof(*pos), member); \
+ prefetch (rcu_dereference (pos)->member.next), \
+ &pos->member != (head); \
+ pos = list_entry (pos->member.next, typeof(*pos), member))
/**
@@ -575,9 +577,9 @@ static inline void list_splice_init(struct list_head *list,
* as long as the traversal is guarded by rcu_read_lock().
*/
#define list_for_each_continue_rcu(pos, head) \
- for ((pos) = (pos)->next; \
- prefetch(rcu_dereference((pos))->next), (pos) != (head); \
- (pos) = (pos)->next)
+ for ((pos) = (pos)->next; \
+ prefetch (rcu_dereference ((pos))->next), (pos) != (head); \
+ (pos) = (pos)->next)
/*
* Double linked lists with a single pointer list head.
@@ -587,46 +589,48 @@ static inline void list_splice_init(struct list_head *list,
*/
struct hlist_head {
- struct hlist_node *first;
+ struct hlist_node *first;
};
struct hlist_node {
- struct hlist_node *next, **pprev;
+ struct hlist_node *next, **pprev;
};
#define HLIST_HEAD_INIT { .first = NULL }
-#define HLIST_HEAD(name) struct hlist_head name = { .first = NULL }
+#define HLIST_HEAD(name) struct hlist_head name = { .first = NULL }
#define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL)
-static inline void INIT_HLIST_NODE(struct hlist_node *h)
+static inline void INIT_HLIST_NODE (struct hlist_node *h)
{
- h->next = NULL;
- h->pprev = NULL;
+ h->next = NULL;
+ h->pprev = NULL;
}
-static inline int hlist_unhashed(const struct hlist_node *h)
+static inline int hlist_unhashed (const struct hlist_node *h)
{
- return !h->pprev;
+ return !h->pprev;
}
-static inline int hlist_empty(const struct hlist_head *h)
+static inline int hlist_empty (const struct hlist_head *h)
{
- return !h->first;
+ return !h->first;
}
-static inline void __hlist_del(struct hlist_node *n)
+static inline void __hlist_del (struct hlist_node *n)
{
- struct hlist_node *next = n->next;
- struct hlist_node **pprev = n->pprev;
- *pprev = next;
- if (next)
- next->pprev = pprev;
+ struct hlist_node *next = n->next;
+ struct hlist_node **pprev = n->pprev;
+
+ *pprev = next;
+ if (next) {
+ next->pprev = pprev;
+ }
}
-static inline void hlist_del(struct hlist_node *n)
+static inline void hlist_del (struct hlist_node *n)
{
- __hlist_del(n);
- n->next = LIST_POISON1;
- n->pprev = LIST_POISON2;
+ __hlist_del (n);
+ n->next = LIST_POISON1;
+ n->pprev = LIST_POISON2;
}
/**
@@ -648,18 +652,18 @@ static inline void hlist_del(struct hlist_node *n)
* the _rcu list-traversal primitives, such as
* hlist_for_each_entry().
*/
-static inline void hlist_del_rcu(struct hlist_node *n)
+static inline void hlist_del_rcu (struct hlist_node *n)
{
- __hlist_del(n);
- n->pprev = LIST_POISON2;
+ __hlist_del (n);
+ n->pprev = LIST_POISON2;
}
-static inline void hlist_del_init(struct hlist_node *n)
+static inline void hlist_del_init (struct hlist_node *n)
{
- if (!hlist_unhashed(n)) {
- __hlist_del(n);
- INIT_HLIST_NODE(n);
- }
+ if (!hlist_unhashed (n)) {
+ __hlist_del (n);
+ INIT_HLIST_NODE (n);
+ }
}
/*
@@ -669,28 +673,31 @@ static inline void hlist_del_init(struct hlist_node *n)
*
* The old entry will be replaced with the new entry atomically.
*/
-static inline void hlist_replace_rcu(struct hlist_node *old,
- struct hlist_node *new)
+static inline void hlist_replace_rcu (struct hlist_node *old,
+ struct hlist_node *new)
{
- struct hlist_node *next = old->next;
+ struct hlist_node *next = old->next;
- new->next = next;
- new->pprev = old->pprev;
+ new->next = next;
+ new->pprev = old->pprev;
// smp_wmb();
- if (next)
- new->next->pprev = &new->next;
- *new->pprev = new;
- old->pprev = LIST_POISON2;
+ if (next) {
+ new->next->pprev = &new->next;
+ }
+ *new->pprev = new;
+ old->pprev = LIST_POISON2;
}
-static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
+static inline void hlist_add_head (struct hlist_node *n, struct hlist_head *h)
{
- struct hlist_node *first = h->first;
- n->next = first;
- if (first)
- first->pprev = &n->next;
- h->first = n;
- n->pprev = &h->first;
+ struct hlist_node *first = h->first;
+
+ n->next = first;
+ if (first) {
+ first->pprev = &n->next;
+ }
+ h->first = n;
+ n->pprev = &h->first;
}
@@ -710,37 +717,40 @@ static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
* problems on Alpha CPUs. Regardless of the type of CPU, the
* list-traversal primitive must be guarded by rcu_read_lock().
*/
-static inline void hlist_add_head_rcu(struct hlist_node *n,
- struct hlist_head *h)
+static inline void hlist_add_head_rcu (struct hlist_node *n,
+ struct hlist_head *h)
{
- struct hlist_node *first = h->first;
- n->next = first;
- n->pprev = &h->first;
+ struct hlist_node *first = h->first;
+
+ n->next = first;
+ n->pprev = &h->first;
// smp_wmb();
- if (first)
- first->pprev = &n->next;
- h->first = n;
+ if (first) {
+ first->pprev = &n->next;
+ }
+ h->first = n;
}
/* next must be != NULL */
-static inline void hlist_add_before(struct hlist_node *n,
- struct hlist_node *next)
+static inline void hlist_add_before (struct hlist_node *n,
+ struct hlist_node *next)
{
- n->pprev = next->pprev;
- n->next = next;
- next->pprev = &n->next;
- *(n->pprev) = n;
+ n->pprev = next->pprev;
+ n->next = next;
+ next->pprev = &n->next;
+ *(n->pprev) = n;
}
-static inline void hlist_add_after(struct hlist_node *n,
- struct hlist_node *next)
+static inline void hlist_add_after (struct hlist_node *n,
+ struct hlist_node *next)
{
- next->next = n->next;
- n->next = next;
- next->pprev = &n->next;
+ next->next = n->next;
+ n->next = next;
+ next->pprev = &n->next;
- if(next->next)
- next->next->pprev = &next->next;
+ if (next->next) {
+ next->next->pprev = &next->next;
+ }
}
/**
@@ -758,14 +768,14 @@ static inline void hlist_add_after(struct hlist_node *n,
* hlist_for_each_entry_rcu(), used to prevent memory-consistency
* problems on Alpha CPUs.
*/
-static inline void hlist_add_before_rcu(struct hlist_node *n,
- struct hlist_node *next)
+static inline void hlist_add_before_rcu (struct hlist_node *n,
+ struct hlist_node *next)
{
- n->pprev = next->pprev;
- n->next = next;
+ n->pprev = next->pprev;
+ n->next = next;
// smp_wmb();
- next->pprev = &n->next;
- *(n->pprev) = n;
+ next->pprev = &n->next;
+ *(n->pprev) = n;
}
/**
@@ -783,26 +793,27 @@ static inline void hlist_add_before_rcu(struct hlist_node *n,
* hlist_for_each_entry_rcu(), used to prevent memory-consistency
* problems on Alpha CPUs.
*/
-static inline void hlist_add_after_rcu(struct hlist_node *prev,
- struct hlist_node *n)
+static inline void hlist_add_after_rcu (struct hlist_node *prev,
+ struct hlist_node *n)
{
- n->next = prev->next;
- n->pprev = &prev->next;
+ n->next = prev->next;
+ n->pprev = &prev->next;
// smp_wmb();
- prev->next = n;
- if (n->next)
- n->next->pprev = &n->next;
+ prev->next = n;
+ if (n->next) {
+ n->next->pprev = &n->next;
+ }
}
-#define hlist_entry(ptr, type, member) container_of(ptr,type,member)
+#define hlist_entry(ptr, type, member) container_of (ptr, type, member)
#define hlist_for_each(pos, head) \
- for (pos = (head)->first; pos && ({ prefetch(pos->next); 1; }); \
- pos = pos->next)
+ for (pos = (head)->first; pos && ({ prefetch (pos->next); 1; }); \
+ pos = pos->next)
#define hlist_for_each_safe(pos, n, head) \
- for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \
- pos = n)
+ for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \
+ pos = n)
/**
* hlist_for_each_entry - iterate over list of given type
@@ -811,11 +822,11 @@ static inline void hlist_add_after_rcu(struct hlist_node *prev,
* @head: the head for your list.
* @member: the name of the hlist_node within the struct.
*/
-#define hlist_for_each_entry(tpos, pos, head, member) \
- for (pos = (head)->first; \
- pos && ({ prefetch(pos->next); 1;}) && \
- ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
- pos = pos->next)
+#define hlist_for_each_entry(tpos, pos, head, member) \
+ for (pos = (head)->first; \
+ pos && ({ prefetch (pos->next); 1; }) && \
+ ({ tpos = hlist_entry (pos, typeof(*tpos), member); 1; }); \
+ pos = pos->next)
/**
* hlist_for_each_entry_continue - iterate over a hlist continuing after existing point
@@ -824,10 +835,10 @@ static inline void hlist_add_after_rcu(struct hlist_node *prev,
* @member: the name of the hlist_node within the struct.
*/
#define hlist_for_each_entry_continue(tpos, pos, member) \
- for (pos = (pos)->next; \
- pos && ({ prefetch(pos->next); 1;}) && \
- ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
- pos = pos->next)
+ for (pos = (pos)->next; \
+ pos && ({ prefetch (pos->next); 1; }) && \
+ ({ tpos = hlist_entry (pos, typeof(*tpos), member); 1; }); \
+ pos = pos->next)
/**
* hlist_for_each_entry_from - iterate over a hlist continuing from existing point
@@ -835,10 +846,10 @@ static inline void hlist_add_after_rcu(struct hlist_node *prev,
* @pos: the &struct hlist_node to use as a loop counter.
* @member: the name of the hlist_node within the struct.
*/
-#define hlist_for_each_entry_from(tpos, pos, member) \
- for (; pos && ({ prefetch(pos->next); 1;}) && \
- ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
- pos = pos->next)
+#define hlist_for_each_entry_from(tpos, pos, member) \
+ for (; pos && ({ prefetch (pos->next); 1; }) && \
+ ({ tpos = hlist_entry (pos, typeof(*tpos), member); 1; }); \
+ pos = pos->next)
/**
* hlist_for_each_entry_safe - iterate over list of given type safe against removal of list entry
@@ -848,11 +859,11 @@ static inline void hlist_add_after_rcu(struct hlist_node *prev,
* @head: the head for your list.
* @member: the name of the hlist_node within the struct.
*/
-#define hlist_for_each_entry_safe(tpos, pos, n, head, member) \
- for (pos = (head)->first; \
- pos && ({ n = pos->next; 1; }) && \
- ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
- pos = n)
+#define hlist_for_each_entry_safe(tpos, pos, n, head, member) \
+ for (pos = (head)->first; \
+ pos && ({ n = pos->next; 1; }) && \
+ ({ tpos = hlist_entry (pos, typeof(*tpos), member); 1; }); \
+ pos = n)
/**
* hlist_for_each_entry_rcu - iterate over rcu list of given type
@@ -866,10 +877,10 @@ static inline void hlist_add_after_rcu(struct hlist_node *prev,
* as long as the traversal is guarded by rcu_read_lock().
*/
#define hlist_for_each_entry_rcu(tpos, pos, head, member) \
- for (pos = (head)->first; \
- rcu_dereference(pos) && ({ prefetch(pos->next); 1;}) && \
- ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
- pos = pos->next)
+ for (pos = (head)->first; \
+ rcu_dereference (pos) && ({ prefetch (pos->next); 1; }) && \
+ ({ tpos = hlist_entry (pos, typeof(*tpos), member); 1; }); \
+ pos = pos->next)
#endif
@@ -881,8 +892,8 @@ static inline void hlist_add_after_rcu(struct hlist_node *prev,
* the list.
*/
extern void __list_sort(struct list_head * head,
- int member_offset,
- int (*comparator)(void*,void*));
+ int member_offset,
+ int (*comparator)(void*, void*));
/**
* list_sort - wrapper for __list_sort
@@ -893,11 +904,11 @@ extern void __list_sort(struct list_head * head,
* @comaprator: function comparing two entries, should return value lesser
* than 0 when the first argument is lesser than the second one.
*/
-#define list_sort(head,type,member,comparator) \
- ({ \
- __list_sort(head, \
- offsetof(type, member), \
- (int (*)(void*, void*)) comparator); \
- })
+#define list_sort(head, type, member, comparator) \
+ ({ \
+ __list_sort (head, \
+ offsetof (type, member), \
+ (int (*)(void*, void*))comparator); \
+ })
void test_list_sort(void);
diff --git a/drivers/alsa_midi/midi_pack.h b/drivers/alsa_midi/midi_pack.h
index 6fb704b..d75c18e 100644
--- a/drivers/alsa_midi/midi_pack.h
+++ b/drivers/alsa_midi/midi_pack.h
@@ -27,20 +27,21 @@ typedef struct {
} midi_pack_t;
static inline
-void midi_pack_reset(midi_pack_t *p)
+void midi_pack_reset (midi_pack_t *p)
{
p->running_status = 0;
}
static
-void midi_pack_event(midi_pack_t *p, jack_midi_event_t *e)
+void midi_pack_event (midi_pack_t *p, jack_midi_event_t *e)
{
if (e->buffer[0] >= 0x80 && e->buffer[0] < 0xF0) { // Voice Message
if (e->buffer[0] == p->running_status) {
e->buffer++;
e->size--;
- } else
+ } else {
p->running_status = e->buffer[0];
+ }
} else if (e->buffer[0] < 0xF8) { // not System Realtime
p->running_status = 0;
}
diff --git a/drivers/alsa_midi/midi_unpack.h b/drivers/alsa_midi/midi_unpack.h
index c917f4d..7573a54 100644
--- a/drivers/alsa_midi/midi_unpack.h
+++ b/drivers/alsa_midi/midi_unpack.h
@@ -32,7 +32,7 @@ typedef struct {
} midi_unpack_t;
static inline
-void midi_unpack_init(midi_unpack_t *u)
+void midi_unpack_init (midi_unpack_t *u)
{
u->pos = 0;
u->size = sizeof(u->data);
@@ -40,102 +40,93 @@ void midi_unpack_init(midi_unpack_t *u)
}
static inline
-void midi_unpack_reset(midi_unpack_t *u)
+void midi_unpack_reset (midi_unpack_t *u)
{
u->pos = 0;
u->need = u->size;
}
static const unsigned char midi_voice_len[] = {
- 3, /*0x80 Note Off*/
- 3, /*0x90 Note On*/
- 3, /*0xA0 Aftertouch*/
- 3, /*0xB0 Control Change*/
- 2, /*0xC0 Program Change*/
- 2, /*0xD0 Channel Pressure*/
- 3, /*0xE0 Pitch Wheel*/
- 1 /*0xF0 System*/
+ 3, /*0x80 Note Off*/
+ 3, /*0x90 Note On*/
+ 3, /*0xA0 Aftertouch*/
+ 3, /*0xB0 Control Change*/
+ 2, /*0xC0 Program Change*/
+ 2, /*0xD0 Channel Pressure*/
+ 3, /*0xE0 Pitch Wheel*/
+ 1 /*0xF0 System*/
};
static const unsigned char midi_system_len[] = {
- 0, /*0xF0 System Exclusive Start*/
- 2, /*0xF1 MTC Quarter Frame*/
- 3, /*0xF2 Song Postion*/
- 2, /*0xF3 Song Select*/
- 0, /*0xF4 undefined*/
- 0, /*0xF5 undefined*/
- 1, /*0xF6 Tune Request*/
- 1 /*0xF7 System Exlusive End*/
+ 0, /*0xF0 System Exclusive Start*/
+ 2, /*0xF1 MTC Quarter Frame*/
+ 3, /*0xF2 Song Postion*/
+ 2, /*0xF3 Song Select*/
+ 0, /*0xF4 undefined*/
+ 0, /*0xF5 undefined*/
+ 1, /*0xF6 Tune Request*/
+ 1 /*0xF7 System Exlusive End*/
};
static
-int midi_unpack_buf(midi_unpack_t *buf, const unsigned char *data, int len, void *jack_port_buf, jack_nframes_t time)
+int midi_unpack_buf (midi_unpack_t *buf, const unsigned char *data, int len, void *jack_port_buf, jack_nframes_t time)
{
int i;
- for (i=0; i<len; ++i)
- {
+
+ for (i = 0; i < len; ++i) {
const unsigned char byte = data[i];
- if (byte >= 0xF8) // system realtime
- {
- jack_midi_event_write(jack_port_buf, time, &data[i], 1);
+ if (byte >= 0xF8) { // system realtime
+ jack_midi_event_write (jack_port_buf, time, &data[i], 1);
//jack_error("midi_unpack: written system relatime event\n");
//midi_input_write(in, &data[i], 1);
- }
- else if (byte < 0x80) // data
- {
+ } else if (byte < 0x80) { // data
assert (buf->pos < buf->size);
buf->data[buf->pos++] = byte;
- }
- else if (byte < 0xF0) // voice
- {
+ } else if (byte < 0xF0) { // voice
assert (byte >= 0x80 && byte < 0xF0);
//buf->need = ((byte|0x0F) == 0xCF || (byte|0x0F)==0xDF) ? 2 : 3;
- buf->need = midi_voice_len[(byte-0x80)>>4];
+ buf->need = midi_voice_len[(byte - 0x80) >> 4];
buf->data[0] = byte;
buf->pos = 1;
- }
- else if (byte == 0xF7) // sysex end
- {
+ } else if (byte == 0xF7) { // sysex end
assert (buf->pos < buf->size);
buf->data[buf->pos++] = byte;
buf->need = buf->pos;
- }
- else
- {
+ } else {
assert (byte >= 0xF0 && byte < 0xF8);
buf->pos = 1;
buf->data[0] = byte;
buf->need = midi_system_len[byte - 0xF0];
- if (!buf->need)
+ if (!buf->need) {
buf->need = buf->size;
+ }
}
- if (buf->pos == buf->need)
- {
+ if (buf->pos == buf->need) {
// TODO: deal with big sysex'es (they are silently dropped for now)
- if (buf->data[0] >= 0x80 || (buf->data[0]==0xF0 && buf->data[buf->pos-1] == 0xF7)) {
+ if (buf->data[0] >= 0x80 || (buf->data[0] == 0xF0 && buf->data[buf->pos - 1] == 0xF7)) {
/* convert Note On with velocity 0 to Note Off */
if ((buf->data[0] & 0xF0) == 0x90 && buf->data[2] == 0) {
// we use temp array here to keep running status in sync
jack_midi_data_t temp[3] = { 0x80, 0, 0x40 };
temp[0] |= buf->data[0] & 0x0F;
temp[1] = buf->data[1];
- jack_midi_event_write(jack_port_buf, time, temp, 3);
- } else
- jack_midi_event_write(jack_port_buf, time, &buf->data[0], buf->pos);
+ jack_midi_event_write (jack_port_buf, time, temp, 3);
+ } else {
+ jack_midi_event_write (jack_port_buf, time, &buf->data[0], buf->pos);
+ }
//jack_error("midi_unpack: written %d-byte event\n", buf->pos);
//midi_input_write(in, &buf->data[0], buf->pos);
}
/* keep running status */
- if (buf->data[0] >= 0x80 && buf->data[0] < 0xF0)
+ if (buf->data[0] >= 0x80 && buf->data[0] < 0xF0) {
buf->pos = 1;
- else
- {
+ } else {
buf->pos = 0;
buf->need = buf->size;
}
}
}
- assert (i==len);
+ assert (i == len);
return i;
}
diff --git a/drivers/alsa_midi/port.c b/drivers/alsa_midi/port.c
index fac5eee..ee88273 100644
--- a/drivers/alsa_midi/port.c
+++ b/drivers/alsa_midi/port.c
@@ -32,8 +32,8 @@
#include "port.h"
/* This should be part of JACK API */
-#define JACK_IS_VALID_PORT_NAME_CHAR(c) \
- (isalnum(c) || \
+#define JACK_IS_VALID_PORT_NAME_CHAR(c) \
+ (isalnum (c) || \
(c) == '/' || \
(c) == '_' || \
(c) == '(' || \
@@ -63,7 +63,7 @@ a2j_alsa_connect_from (alsa_midi_driver_t * driver, int client, int port)
snd_seq_port_subscribe_set_time_real (sub, 1);
if ((err = snd_seq_subscribe_port (driver->seq, sub))) {
- a2j_error ("can't subscribe to %d:%d - %s", client, port, snd_strerror(err));
+ a2j_error ("can't subscribe to %d:%d - %s", client, port, snd_strerror (err));
}
return err;
@@ -72,12 +72,12 @@ a2j_alsa_connect_from (alsa_midi_driver_t * driver, int client, int port)
void
a2j_port_setdead (a2j_port_hash_t hash, snd_seq_addr_t addr)
{
- struct a2j_port *port = a2j_port_get(hash, addr);
+ struct a2j_port *port = a2j_port_get (hash, addr);
if (port) {
port->is_dead = true; // see jack_process_internal
} else {
- a2j_debug("port_setdead: not found (%d:%d)", addr.client, addr.port);
+ a2j_debug ("port_setdead: not found (%d:%d)", addr.client, addr.port);
}
}
@@ -108,22 +108,22 @@ a2j_port_fill_name (struct a2j_port * port_ptr, int dir, snd_seq_client_info_t *
snprintf (port_ptr->name,
sizeof(port_ptr->name),
"%s [%d] %s %s",
- snd_seq_client_info_get_name(client_info_ptr),
- snd_seq_client_info_get_client(client_info_ptr),
- snd_seq_port_info_get_name(port_info_ptr),
- (dir == A2J_PORT_CAPTURE ? "in" : "out"));
+ snd_seq_client_info_get_name (client_info_ptr),
+ snd_seq_client_info_get_client (client_info_ptr),
+ snd_seq_port_info_get_name (port_info_ptr),
+ (dir == A2J_PORT_CAPTURE ? "in" : "out"));
} else {
snprintf (port_ptr->name,
sizeof(port_ptr->name),
"%s %s %s",
- snd_seq_client_info_get_name(client_info_ptr),
- snd_seq_port_info_get_name(port_info_ptr),
- (dir == A2J_PORT_CAPTURE ? "in" : "out"));
+ snd_seq_client_info_get_name (client_info_ptr),
+ snd_seq_port_info_get_name (port_info_ptr),
+ (dir == A2J_PORT_CAPTURE ? "in" : "out"));
}
-
+
// replace all offending characters with ' '
for (c = port_ptr->name; *c; ++c) {
- if (!JACK_IS_VALID_PORT_NAME_CHAR(*c)) {
+ if (!JACK_IS_VALID_PORT_NAME_CHAR (*c)) {
*c = ' ';
}
}
@@ -142,7 +142,7 @@ a2j_port_create (alsa_midi_driver_t * driver, int dir, snd_seq_addr_t addr, cons
stream_ptr = &driver->stream[dir];
if ((err = snd_seq_client_info_malloc (&client_info_ptr)) != 0) {
- a2j_error("Failed to allocate client info");
+ a2j_error ("Failed to allocate client info");
goto fail;
}
@@ -150,12 +150,12 @@ a2j_port_create (alsa_midi_driver_t * driver, int dir, snd_seq_addr_t addr, cons
err = snd_seq_get_any_client_info (driver->seq, client, client_info_ptr);
if (err != 0) {
- a2j_error("Failed to get client info");
+ a2j_error ("Failed to get client info");
goto fail_free_client_info;
}
- a2j_debug ("client name: '%s'", snd_seq_client_info_get_name(client_info_ptr));
- a2j_debug ("port name: '%s'", snd_seq_port_info_get_name(info));
+ a2j_debug ("client name: '%s'", snd_seq_client_info_get_name (client_info_ptr));
+ a2j_debug ("port name: '%s'", snd_seq_port_info_get_name (info));
port = calloc (1, sizeof(struct a2j_port));
if (!port) {
@@ -170,7 +170,7 @@ a2j_port_create (alsa_midi_driver_t * driver, int dir, snd_seq_addr_t addr, cons
/* Add port to list early, before registering to JACK, so map functionality is guaranteed to work during port registration */
list_add_tail (&port->siblings, &stream_ptr->list);
-
+
if (dir == A2J_PORT_CAPTURE) {
jack_caps = JackPortIsOutput;
} else {
@@ -178,13 +178,13 @@ a2j_port_create (alsa_midi_driver_t * driver, int dir, snd_seq_addr_t addr, cons
}
/* mark anything that looks like a hardware port as physical&terminal */
- if (snd_seq_port_info_get_type (info) & (SND_SEQ_PORT_TYPE_HARDWARE|SND_SEQ_PORT_TYPE_PORT|SND_SEQ_PORT_TYPE_SPECIFIC)) {
- jack_caps |= JackPortIsPhysical|JackPortIsTerminal;
+ if (snd_seq_port_info_get_type (info) & (SND_SEQ_PORT_TYPE_HARDWARE | SND_SEQ_PORT_TYPE_PORT | SND_SEQ_PORT_TYPE_SPECIFIC)) {
+ jack_caps |= JackPortIsPhysical | JackPortIsTerminal;
}
port->jack_port = jack_port_register (driver->jack_client, port->name, JACK_DEFAULT_MIDI_TYPE, jack_caps, 0);
if (port->jack_port == JACK_INVALID_PORT) {
- a2j_error("jack_port_register() failed for '%s'", port->name);
+ a2j_error ("jack_port_register() failed for '%s'", port->name);
goto fail_free_port;
}
@@ -195,23 +195,23 @@ a2j_port_create (alsa_midi_driver_t * driver, int dir, snd_seq_addr_t addr, cons
}
if (err) {
- a2j_debug("port skipped: %s", port->name);
+ a2j_debug ("port skipped: %s", port->name);
goto fail_free_port;
}
- port->inbound_events = jack_ringbuffer_create(MAX_EVENT_SIZE*16);
+ port->inbound_events = jack_ringbuffer_create (MAX_EVENT_SIZE * 16);
- a2j_debug("port created: %s", port->name);
+ a2j_debug ("port created: %s", port->name);
return port;
- fail_free_port:
+fail_free_port:
list_del (&port->siblings);
a2j_port_free (port);
- fail_free_client_info:
+fail_free_client_info:
snd_seq_client_info_free (client_info_ptr);
- fail:
+fail:
return NULL;
}
diff --git a/drivers/alsa_midi/port.h b/drivers/alsa_midi/port.h
index 2c8daf4..8be9ac6 100644
--- a/drivers/alsa_midi/port.h
+++ b/drivers/alsa_midi/port.h
@@ -22,8 +22,8 @@
#ifndef PORT_H__757ADD0F_5E53_41F7_8B7F_8119C5E8A9F1__INCLUDED
#define PORT_H__757ADD0F_5E53_41F7_8B7F_8119C5E8A9F1__INCLUDED
-struct a2j_port* a2j_port_create (alsa_midi_driver_t* driver, int dir, snd_seq_addr_t addr, const snd_seq_port_info_t * info);
-void a2j_port_setdead (a2j_port_hash_t hash, snd_seq_addr_t addr);
-void a2j_port_free (struct a2j_port * port);
+struct a2j_port* a2j_port_create(alsa_midi_driver_t* driver, int dir, snd_seq_addr_t addr, const snd_seq_port_info_t * info);
+void a2j_port_setdead(a2j_port_hash_t hash, snd_seq_addr_t addr);
+void a2j_port_free(struct a2j_port * port);
#endif /* #ifndef PORT_H__757ADD0F_5E53_41F7_8B7F_8119C5E8A9F1__INCLUDED */
diff --git a/drivers/alsa_midi/port_hash.c b/drivers/alsa_midi/port_hash.c
index cc9c5c6..1a3dec2 100644
--- a/drivers/alsa_midi/port_hash.c
+++ b/drivers/alsa_midi/port_hash.c
@@ -31,33 +31,36 @@
static inline
int
-a2j_port_hash(
- snd_seq_addr_t addr)
+a2j_port_hash (
+ snd_seq_addr_t addr)
{
- return (addr.client + addr.port) % PORT_HASH_SIZE;
+ return (addr.client + addr.port) % PORT_HASH_SIZE;
}
struct a2j_port *
-a2j_port_get(
- a2j_port_hash_t hash,
- snd_seq_addr_t addr)
+a2j_port_get (
+ a2j_port_hash_t hash,
+ snd_seq_addr_t addr)
{
- struct a2j_port **pport = &hash[a2j_port_hash(addr)];
- while (*pport) {
- struct a2j_port *port = *pport;
- if (port->remote.client == addr.client && port->remote.port == addr.port)
- return port;
- pport = &port->next;
- }
- return NULL;
+ struct a2j_port **pport = &hash[a2j_port_hash (addr)];
+
+ while (*pport) {
+ struct a2j_port *port = *pport;
+ if (port->remote.client == addr.client && port->remote.port == addr.port) {
+ return port;
+ }
+ pport = &port->next;
+ }
+ return NULL;
}
void
-a2j_port_insert(
- a2j_port_hash_t hash,
- struct a2j_port * port)
+a2j_port_insert (
+ a2j_port_hash_t hash,
+ struct a2j_port * port)
{
- struct a2j_port **pport = &hash[a2j_port_hash(port->remote)];
- port->next = *pport;
- *pport = port;
+ struct a2j_port **pport = &hash[a2j_port_hash (port->remote)];
+
+ port->next = *pport;
+ *pport = port;
}
diff --git a/drivers/alsa_midi/port_hash.h b/drivers/alsa_midi/port_hash.h
index ec21f11..ebd86e1 100644
--- a/drivers/alsa_midi/port_hash.h
+++ b/drivers/alsa_midi/port_hash.h
@@ -24,12 +24,12 @@
void
a2j_port_insert(
- a2j_port_hash_t hash,
- struct a2j_port * port);
+ a2j_port_hash_t hash,
+ struct a2j_port * port);
struct a2j_port *
a2j_port_get(
- a2j_port_hash_t hash,
- snd_seq_addr_t addr);
+ a2j_port_hash_t hash,
+ snd_seq_addr_t addr);
#endif /* #ifndef PORT_HASH_H__A44CBCD6_E075_49CB_8F73_DF9772511D55__INCLUDED */
diff --git a/drivers/alsa_midi/port_thread.c b/drivers/alsa_midi/port_thread.c
index c6741fd..a8ced8d 100644
--- a/drivers/alsa_midi/port_thread.c
+++ b/drivers/alsa_midi/port_thread.c
@@ -32,18 +32,16 @@
#include "port_thread.h"
struct a2j_port *
-a2j_find_port_by_addr(
+a2j_find_port_by_addr (
struct a2j_stream * stream_ptr,
snd_seq_addr_t addr)
{
struct list_head * node_ptr;
struct a2j_port * port_ptr;
- list_for_each(node_ptr, &stream_ptr->list)
- {
- port_ptr = list_entry(node_ptr, struct a2j_port, siblings);
- if (port_ptr->remote.client == addr.client && port_ptr->remote.port == addr.port)
- {
+ list_for_each (node_ptr, &stream_ptr->list){
+ port_ptr = list_entry (node_ptr, struct a2j_port, siblings);
+ if (port_ptr->remote.client == addr.client && port_ptr->remote.port == addr.port) {
return port_ptr;
}
}
@@ -52,18 +50,16 @@ a2j_find_port_by_addr(
}
struct a2j_port *
-a2j_find_port_by_jack_port_name(
+a2j_find_port_by_jack_port_name (
struct a2j_stream * stream_ptr,
const char * jack_port)
{
struct list_head * node_ptr;
struct a2j_port * port_ptr;
- list_for_each(node_ptr, &stream_ptr->list)
- {
- port_ptr = list_entry(node_ptr, struct a2j_port, siblings);
- if (strcmp(port_ptr->name, jack_port) == 0)
- {
+ list_for_each (node_ptr, &stream_ptr->list){
+ port_ptr = list_entry (node_ptr, struct a2j_port, siblings);
+ if (strcmp (port_ptr->name, jack_port) == 0) {
return port_ptr;
}
}
@@ -83,10 +79,10 @@ a2j_update_port_type (alsa_midi_driver_t * driver, int dir, snd_seq_addr_t addr,
int alsa_mask;
struct a2j_port * port_ptr;
- a2j_debug("update_port_type(%d:%d)", addr.client, addr.port);
+ a2j_debug ("update_port_type(%d:%d)", addr.client, addr.port);
stream_ptr = &driver->stream[dir];
- port_ptr = a2j_find_port_by_addr(stream_ptr, addr);
+ port_ptr = a2j_find_port_by_addr (stream_ptr, addr);
if (dir == A2J_PORT_CAPTURE) {
alsa_mask = SND_SEQ_PORT_CAP_SUBS_READ;
@@ -95,18 +91,18 @@ a2j_update_port_type (alsa_midi_driver_t * driver, int dir, snd_seq_addr_t addr,
}
if (port_ptr != NULL && (caps & alsa_mask) != alsa_mask) {
- a2j_debug("setdead: %s", port_ptr->name);
+ a2j_debug ("setdead: %s", port_ptr->name);
port_ptr->is_dead = true;
}
if (port_ptr == NULL && (caps & alsa_mask) == alsa_mask) {
- if(jack_ringbuffer_write_space(stream_ptr->new_ports) >= sizeof(port_ptr)) {
- port_ptr = a2j_port_create (driver, dir, addr, info);
+ if (jack_ringbuffer_write_space (stream_ptr->new_ports) >= sizeof(port_ptr)) {
+ port_ptr = a2j_port_create (driver, dir, addr, info);
if (port_ptr != NULL) {
- jack_ringbuffer_write(stream_ptr->new_ports, (char *)&port_ptr, sizeof(port_ptr));
+ jack_ringbuffer_write (stream_ptr->new_ports, (char*)&port_ptr, sizeof(port_ptr));
}
} else {
- a2j_error( "dropping new port event... increase MAX_PORTS" );
+ a2j_error ( "dropping new port event... increase MAX_PORTS" );
}
}
}
@@ -114,85 +110,85 @@ a2j_update_port_type (alsa_midi_driver_t * driver, int dir, snd_seq_addr_t addr,
void
a2j_update_port (alsa_midi_driver_t * driver, snd_seq_addr_t addr, const snd_seq_port_info_t * info)
{
- unsigned int port_caps = snd_seq_port_info_get_capability(info);
- unsigned int port_type = snd_seq_port_info_get_type(info);
+ unsigned int port_caps = snd_seq_port_info_get_capability (info);
+ unsigned int port_type = snd_seq_port_info_get_type (info);
- a2j_debug("port %u:%u", addr.client, addr.port);
- a2j_debug("port type: 0x%08X", port_type);
- a2j_debug("port caps: 0x%08X", port_caps);
+ a2j_debug ("port %u:%u", addr.client, addr.port);
+ a2j_debug ("port type: 0x%08X", port_type);
+ a2j_debug ("port caps: 0x%08X", port_caps);
if (port_type & SND_SEQ_PORT_TYPE_SPECIFIC) {
- a2j_debug("SPECIFIC");
+ a2j_debug ("SPECIFIC");
}
if (port_type & SND_SEQ_PORT_TYPE_MIDI_GENERIC) {
- a2j_debug("MIDI_GENERIC");
+ a2j_debug ("MIDI_GENERIC");
}
if (port_type & SND_SEQ_PORT_TYPE_MIDI_GM) {
- a2j_debug("MIDI_GM");
+ a2j_debug ("MIDI_GM");
}
if (port_type & SND_SEQ_PORT_TYPE_MIDI_GS) {
- a2j_debug("MIDI_GS");
+ a2j_debug ("MIDI_GS");
}
if (port_type & SND_SEQ_PORT_TYPE_MIDI_XG) {
- a2j_debug("MIDI_XG");
+ a2j_debug ("MIDI_XG");
}
if (port_type & SND_SEQ_PORT_TYPE_MIDI_MT32) {
- a2j_debug("MIDI_MT32");
+ a2j_debug ("MIDI_MT32");
}
if (port_type & SND_SEQ_PORT_TYPE_MIDI_GM2) {
- a2j_debug("MIDI_GM2");
+ a2j_debug ("MIDI_GM2");
}
if (port_type & SND_SEQ_PORT_TYPE_SYNTH) {
- a2j_debug("SYNTH");
+ a2j_debug ("SYNTH");
}
if (port_type & SND_SEQ_PORT_TYPE_DIRECT_SAMPLE) {
- a2j_debug("DIRECT_SAMPLE");
+ a2j_debug ("DIRECT_SAMPLE");
}
if (port_type & SND_SEQ_PORT_TYPE_SAMPLE) {
- a2j_debug("SAMPLE");
+ a2j_debug ("SAMPLE");
}
if (port_type & SND_SEQ_PORT_TYPE_HARDWARE) {
- a2j_debug("HARDWARE");
+ a2j_debug ("HARDWARE");
}
if (port_type & SND_SEQ_PORT_TYPE_SOFTWARE) {
- a2j_debug("SOFTWARE");
+ a2j_debug ("SOFTWARE");
}
if (port_type & SND_SEQ_PORT_TYPE_SYNTHESIZER) {
- a2j_debug("SYNTHESIZER");
+ a2j_debug ("SYNTHESIZER");
}
if (port_type & SND_SEQ_PORT_TYPE_PORT) {
- a2j_debug("PORT");
+ a2j_debug ("PORT");
}
if (port_type & SND_SEQ_PORT_TYPE_APPLICATION) {
- a2j_debug("APPLICATION");
+ a2j_debug ("APPLICATION");
}
if (port_type == 0) {
- a2j_debug("Ignoring port of type 0");
+ a2j_debug ("Ignoring port of type 0");
return;
}
if (port_caps & SND_SEQ_PORT_CAP_NO_EXPORT) {
- a2j_debug("Ignoring no-export port");
+ a2j_debug ("Ignoring no-export port");
return;
}
- a2j_update_port_type (driver, A2J_PORT_CAPTURE, addr, port_caps, info);
- a2j_update_port_type (driver, A2J_PORT_PLAYBACK, addr, port_caps, info);
+ a2j_update_port_type (driver, A2J_PORT_CAPTURE, addr, port_caps, info);
+ a2j_update_port_type (driver, A2J_PORT_PLAYBACK, addr, port_caps, info);
}
void
@@ -202,47 +198,47 @@ a2j_free_ports (alsa_midi_driver_t * driver)
int sz;
while ((sz = jack_ringbuffer_read (driver->port_del, (char*)&port, sizeof(port)))) {
- assert (sz == sizeof(port));
- a2j_debug("port deleted: %s", port->name);
- list_del (&port->siblings);
- a2j_port_free(port);
+ assert (sz == sizeof(port));
+ a2j_debug ("port deleted: %s", port->name);
+ list_del (&port->siblings);
+ a2j_port_free (port);
}
}
void
a2j_update_ports (alsa_midi_driver_t * driver, snd_seq_addr_t addr)
{
- snd_seq_port_info_t * info;
- int err;
-
- assert (addr.client != driver->client_id);
-
- snd_seq_port_info_alloca(&info);
-
- if ((err = snd_seq_get_any_port_info(driver->seq, addr.client, addr.port, info)) >= 0) {
- a2j_debug("updating: %d:%d", addr.client, addr.port);
- a2j_update_port(driver, addr, info);
- } else {
- a2j_debug("setting dead: %d:%d", addr.client, addr.port);
- a2j_port_setdead(driver->stream[A2J_PORT_CAPTURE].port_hash, addr);
- a2j_port_setdead(driver->stream[A2J_PORT_PLAYBACK].port_hash, addr);
- }
+ snd_seq_port_info_t * info;
+ int err;
+
+ assert (addr.client != driver->client_id);
+
+ snd_seq_port_info_alloca (&info);
+
+ if ((err = snd_seq_get_any_port_info (driver->seq, addr.client, addr.port, info)) >= 0) {
+ a2j_debug ("updating: %d:%d", addr.client, addr.port);
+ a2j_update_port (driver, addr, info);
+ } else {
+ a2j_debug ("setting dead: %d:%d", addr.client, addr.port);
+ a2j_port_setdead (driver->stream[A2J_PORT_CAPTURE].port_hash, addr);
+ a2j_port_setdead (driver->stream[A2J_PORT_PLAYBACK].port_hash, addr);
+ }
}
void
a2j_new_ports (alsa_midi_driver_t * driver, snd_seq_addr_t addr)
{
- snd_seq_port_info_t * port_info;
+ snd_seq_port_info_t * port_info;
assert (addr.client != driver->client_id);
- snd_seq_port_info_alloca(&port_info);
+ snd_seq_port_info_alloca (&port_info);
- a2j_debug("adding new port: %d:%d", addr.client, addr.port);
- snd_seq_port_info_set_client(port_info, addr.client);
- snd_seq_port_info_set_port(port_info, -1);
- while (snd_seq_query_next_port(driver->seq, port_info) >= 0) {
- addr.port = snd_seq_port_info_get_port(port_info);
- a2j_update_port(driver, addr, port_info);
- }
+ a2j_debug ("adding new port: %d:%d", addr.client, addr.port);
+ snd_seq_port_info_set_client (port_info, addr.client);
+ snd_seq_port_info_set_port (port_info, -1);
+ while (snd_seq_query_next_port (driver->seq, port_info) >= 0) {
+ addr.port = snd_seq_port_info_get_port (port_info);
+ a2j_update_port (driver, addr, port_info);
+ }
}
diff --git a/drivers/alsa_midi/port_thread.h b/drivers/alsa_midi/port_thread.h
index 51b5fc2..1ce33ae 100644
--- a/drivers/alsa_midi/port_thread.h
+++ b/drivers/alsa_midi/port_thread.h
@@ -22,11 +22,11 @@
#ifndef PORT_THREAD_H__1C6B5065_5556_4AC6_AA9F_44C32A9648C6__INCLUDED
#define PORT_THREAD_H__1C6B5065_5556_4AC6_AA9F_44C32A9648C6__INCLUDED
-void a2j_update_port (alsa_midi_driver_t* driver, snd_seq_addr_t addr, const snd_seq_port_info_t* info);
-void a2j_update_ports (alsa_midi_driver_t* driver, snd_seq_addr_t addr);
-void a2j_new_ports (alsa_midi_driver_t* driver, snd_seq_addr_t addr);
-void a2j_free_ports (alsa_midi_driver_t* driver);
-struct a2j_port * a2j_find_port_by_addr (struct a2j_stream * stream_ptr, snd_seq_addr_t addr);
-struct a2j_port * a2j_find_port_by_jack_port_name (struct a2j_stream * stream_ptr, const char * jack_port);
+void a2j_update_port(alsa_midi_driver_t* driver, snd_seq_addr_t addr, const snd_seq_port_info_t* info);
+void a2j_update_ports(alsa_midi_driver_t* driver, snd_seq_addr_t addr);
+void a2j_new_ports(alsa_midi_driver_t* driver, snd_seq_addr_t addr);
+void a2j_free_ports(alsa_midi_driver_t* driver);
+struct a2j_port * a2j_find_port_by_addr(struct a2j_stream * stream_ptr, snd_seq_addr_t addr);
+struct a2j_port * a2j_find_port_by_jack_port_name(struct a2j_stream * stream_ptr, const char * jack_port);
#endif /* #ifndef PORT_THREAD_H__1C6B5065_5556_4AC6_AA9F_44C32A9648C6__INCLUDED */
diff --git a/drivers/am/alsa_midi.h b/drivers/am/alsa_midi.h
index b49228a..d0cf258 100644
--- a/drivers/am/alsa_midi.h
+++ b/drivers/am/alsa_midi.h
@@ -38,10 +38,10 @@ alsa_midi_t* alsa_seqmidi_new(jack_client_t *jack, const char* alsa_name);
typedef struct _alsa_midi_driver {
- JACK_DRIVER_DECL;
+ JACK_DRIVER_DECL;
- alsa_midi_t *midi;
- jack_client_t *client;
+ alsa_midi_t *midi;
+ jack_client_t *client;
} alsa_midi_driver_t;
diff --git a/drivers/am/alsa_midi_driver.c b/drivers/am/alsa_midi_driver.c
index b27f03c..4da85ed 100644
--- a/drivers/am/alsa_midi_driver.c
+++ b/drivers/am/alsa_midi_driver.c
@@ -3,48 +3,49 @@
#include <string.h>
static int
-alsa_midi_driver_attach( alsa_midi_driver_t *driver, jack_engine_t *engine )
+alsa_midi_driver_attach ( alsa_midi_driver_t *driver, jack_engine_t *engine )
{
- return driver->midi->attach(driver->midi);
+ return driver->midi->attach (driver->midi);
}
static int
-alsa_midi_driver_detach( alsa_midi_driver_t *driver, jack_engine_t *engine )
+alsa_midi_driver_detach ( alsa_midi_driver_t *driver, jack_engine_t *engine )
{
- return driver->midi->detach(driver->midi);
+ return driver->midi->detach (driver->midi);
}
static int
-alsa_midi_driver_read( alsa_midi_driver_t *driver, jack_nframes_t nframes )
+alsa_midi_driver_read ( alsa_midi_driver_t *driver, jack_nframes_t nframes )
{
- driver->midi->read(driver->midi, nframes);
+ driver->midi->read (driver->midi, nframes);
return 0;
}
static int
-alsa_midi_driver_write( alsa_midi_driver_t *driver, jack_nframes_t nframes )
+alsa_midi_driver_write ( alsa_midi_driver_t *driver, jack_nframes_t nframes )
{
- driver->midi->write(driver->midi, nframes);
+ driver->midi->write (driver->midi, nframes);
return 0;
}
static int
-alsa_midi_driver_start( alsa_midi_driver_t *driver )
+alsa_midi_driver_start ( alsa_midi_driver_t *driver )
{
- return driver->midi->start(driver->midi);
+ return driver->midi->start (driver->midi);
}
static int
-alsa_midi_driver_stop( alsa_midi_driver_t *driver )
+alsa_midi_driver_stop ( alsa_midi_driver_t *driver )
{
- return driver->midi->stop(driver->midi);
+ return driver->midi->stop (driver->midi);
}
static void
-alsa_midi_driver_delete( alsa_midi_driver_t *driver )
+alsa_midi_driver_delete ( alsa_midi_driver_t *driver )
{
- if (driver->midi)
+ if (driver->midi) {
(driver->midi->destroy)(driver->midi);
+ }
free (driver);
}
@@ -54,24 +55,24 @@ alsa_midi_driver_new (jack_client_t *client, const char *name)
{
alsa_midi_driver_t *driver;
- jack_info ("creating alsa_midi driver ...");
+ jack_info ("creating alsa_midi driver ...");
- driver = (alsa_midi_driver_t *) calloc (1, sizeof (alsa_midi_driver_t));
+ driver = (alsa_midi_driver_t*)calloc (1, sizeof(alsa_midi_driver_t));
- jack_driver_init ((jack_driver_t *) driver);
+ jack_driver_init ((jack_driver_t*)driver);
- driver->attach = (JackDriverAttachFunction) alsa_midi_driver_attach;
- driver->detach = (JackDriverDetachFunction) alsa_midi_driver_detach;
- driver->read = (JackDriverReadFunction) alsa_midi_driver_read;
- driver->write = (JackDriverWriteFunction) alsa_midi_driver_write;
- driver->start = (JackDriverStartFunction) alsa_midi_driver_start;
- driver->stop = (JackDriverStartFunction) alsa_midi_driver_stop;
+ driver->attach = (JackDriverAttachFunction)alsa_midi_driver_attach;
+ driver->detach = (JackDriverDetachFunction)alsa_midi_driver_detach;
+ driver->read = (JackDriverReadFunction)alsa_midi_driver_read;
+ driver->write = (JackDriverWriteFunction)alsa_midi_driver_write;
+ driver->start = (JackDriverStartFunction)alsa_midi_driver_start;
+ driver->stop = (JackDriverStartFunction)alsa_midi_driver_stop;
- driver->midi = alsa_seqmidi_new(client, NULL);
+ driver->midi = alsa_seqmidi_new (client, NULL);
driver->client = client;
- return (jack_driver_t *) driver;
+ return (jack_driver_t*)driver;
}
/* DRIVER "PLUGIN" INTERFACE */
@@ -83,14 +84,15 @@ driver_get_descriptor ()
{
jack_driver_desc_t * desc;
jack_driver_param_desc_t * params;
+
//unsigned int i;
- desc = calloc (1, sizeof (jack_driver_desc_t));
+ desc = calloc (1, sizeof(jack_driver_desc_t));
- strcpy (desc->name,"alsa_midi");
+ strcpy (desc->name, "alsa_midi");
desc->nparams = 0;
-
- params = calloc (desc->nparams, sizeof (jack_driver_param_desc_t));
+
+ params = calloc (desc->nparams, sizeof(jack_driver_param_desc_t));
desc->params = params;
@@ -104,19 +106,19 @@ driver_initialize (jack_client_t *client, const JSList * params)
const jack_driver_param_t * param;
for (node = params; node; node = jack_slist_next (node)) {
- param = (const jack_driver_param_t *) node->data;
+ param = (const jack_driver_param_t*)node->data;
switch (param->character) {
- default:
- break;
+ default:
+ break;
}
}
-
+
return alsa_midi_driver_new (client, NULL);
}
void
driver_finish (jack_driver_t *driver)
{
- alsa_midi_driver_delete ((alsa_midi_driver_t *) driver);
+ alsa_midi_driver_delete ((alsa_midi_driver_t*)driver);
}
diff --git a/drivers/am/alsa_rawmidi.c b/drivers/am/alsa_rawmidi.c
index 9db97fb..ba73561 100644
--- a/drivers/am/alsa_rawmidi.c
+++ b/drivers/am/alsa_rawmidi.c
@@ -38,16 +38,16 @@
#ifdef STANDALONE
-#define MESSAGE(...) fprintf(stderr, __VA_ARGS__)
+#define MESSAGE(...) fprintf (stderr, __VA_ARGS__)
#else
#include "messagebuffer.h"
#endif
-#define info_log(...) MESSAGE(__VA_ARGS__)
-#define error_log(...) MESSAGE(__VA_ARGS__)
+#define info_log(...) MESSAGE (__VA_ARGS__)
+#define error_log(...) MESSAGE (__VA_ARGS__)
#ifdef JACK_MIDI_DEBUG
-#define debug_log(...) MESSAGE(__VA_ARGS__)
+#define debug_log(...) MESSAGE (__VA_ARGS__)
#else
#define debug_log(...)
#endif
@@ -62,13 +62,13 @@ enum {
enum {
#ifndef JACK_MIDI_DEBUG
MAX_PFDS = 64,
- MAX_PORTS = MAX_PFDS-1,
+ MAX_PORTS = MAX_PFDS - 1,
MAX_EVENTS = 4096,
- MAX_DATA = 64*1024,
+ MAX_DATA = 64 * 1024,
MIDI_THREAD_PRIO = 80
#else
MAX_PFDS = 6,
- MAX_PORTS = MAX_PFDS-1,
+ MAX_PORTS = MAX_PFDS - 1,
MAX_EVENTS = 16,
MAX_DATA = 64,
MIDI_THREAD_PRIO = 80
@@ -122,7 +122,7 @@ typedef struct input_port_t {
// jack
midi_unpack_t unpack;
-
+
// midi
int overruns;
} input_port_t;
@@ -132,7 +132,7 @@ typedef struct output_port_t {
// jack
midi_pack_t packer;
-
+
// midi
event_head_t next_event;
int todo;
@@ -212,33 +212,36 @@ static int do_midi_output(process_midi_t *m);
static
-int stream_init(midi_stream_t *s, alsa_rawmidi_t *midi, const char *name)
+int stream_init (midi_stream_t *s, alsa_rawmidi_t *midi, const char *name)
{
s->owner = midi;
s->name = name;
- if (pipe(s->wake_pipe)==-1) {
+ if (pipe (s->wake_pipe) == -1) {
s->wake_pipe[0] = -1;
- error_log("pipe() in stream_init(%s) failed: %s", name, strerror(errno));
+ error_log ("pipe() in stream_init(%s) failed: %s", name, strerror (errno));
return -errno;
}
- s->jack.new_ports = jack_ringbuffer_create(sizeof(midi_port_t*)*MAX_PORTS);
- s->midi.new_ports = jack_ringbuffer_create(sizeof(midi_port_t*)*MAX_PORTS);
- if (!s->jack.new_ports || !s->midi.new_ports)
+ s->jack.new_ports = jack_ringbuffer_create (sizeof(midi_port_t*) * MAX_PORTS);
+ s->midi.new_ports = jack_ringbuffer_create (sizeof(midi_port_t*) * MAX_PORTS);
+ if (!s->jack.new_ports || !s->midi.new_ports) {
return -ENOMEM;
+ }
return 0;
}
static
-void stream_close(midi_stream_t *s)
+void stream_close (midi_stream_t *s)
{
if (s->wake_pipe[0] != -1) {
- close(s->wake_pipe[0]);
- close(s->wake_pipe[1]);
+ close (s->wake_pipe[0]);
+ close (s->wake_pipe[1]);
+ }
+ if (s->jack.new_ports) {
+ jack_ringbuffer_free (s->jack.new_ports);
+ }
+ if (s->midi.new_ports) {
+ jack_ringbuffer_free (s->midi.new_ports);
}
- if (s->jack.new_ports)
- jack_ringbuffer_free(s->jack.new_ports);
- if (s->midi.new_ports)
- jack_ringbuffer_free(s->midi.new_ports);
}
static void alsa_rawmidi_delete(alsa_midi_t *m);
@@ -249,19 +252,22 @@ static int alsa_rawmidi_stop(alsa_midi_t *m);
static void alsa_rawmidi_read(alsa_midi_t *m, jack_nframes_t nframes);
static void alsa_rawmidi_write(alsa_midi_t *m, jack_nframes_t nframes);
-alsa_midi_t* alsa_rawmidi_new(jack_client_t *jack)
+alsa_midi_t* alsa_rawmidi_new (jack_client_t *jack)
{
- alsa_rawmidi_t *midi = calloc(1, sizeof(alsa_rawmidi_t));
- if (!midi)
+ alsa_rawmidi_t *midi = calloc (1, sizeof(alsa_rawmidi_t));
+
+ if (!midi) {
goto fail_0;
+ }
midi->client = jack;
- if (pipe(midi->scan.wake_pipe)==-1) {
- error_log("pipe() in alsa_midi_new failed: %s", strerror(errno));
+ if (pipe (midi->scan.wake_pipe) == -1) {
+ error_log ("pipe() in alsa_midi_new failed: %s", strerror (errno));
goto fail_1;
}
- if (stream_init(&midi->in, midi, "in"))
+ if (stream_init (&midi->in, midi, "in")) {
goto fail_2;
+ }
midi->in.mode = POLLIN;
midi->in.port_size = sizeof(input_port_t);
midi->in.port_init = input_port_init;
@@ -269,8 +275,9 @@ alsa_midi_t* alsa_rawmidi_new(jack_client_t *jack)
midi->in.process_jack = do_jack_input;
midi->in.process_midi = do_midi_input;
- if (stream_init(&midi->out, midi, "out"))
+ if (stream_init (&midi->out, midi, "out")) {
goto fail_3;
+ }
midi->out.mode = POLLOUT;
midi->out.port_size = sizeof(output_port_t);
midi->out.port_init = output_port_init;
@@ -287,15 +294,15 @@ alsa_midi_t* alsa_rawmidi_new(jack_client_t *jack)
midi->ops.write = alsa_rawmidi_write;
return &midi->ops;
- fail_3:
- stream_close(&midi->out);
- fail_2:
- stream_close(&midi->in);
- close(midi->scan.wake_pipe[1]);
- close(midi->scan.wake_pipe[0]);
- fail_1:
- free(midi);
- fail_0:
+fail_3:
+ stream_close (&midi->out);
+fail_2:
+ stream_close (&midi->in);
+ close (midi->scan.wake_pipe[1]);
+ close (midi->scan.wake_pipe[0]);
+fail_1:
+ free (midi);
+fail_0:
return NULL;
}
@@ -303,90 +310,94 @@ static
midi_port_t** scan_port_del(alsa_rawmidi_t *midi, midi_port_t **list);
static
-void alsa_rawmidi_delete(alsa_midi_t *m)
+void alsa_rawmidi_delete (alsa_midi_t *m)
{
alsa_rawmidi_t *midi = (alsa_rawmidi_t*)m;
- alsa_rawmidi_detach(m);
+ alsa_rawmidi_detach (m);
- stream_close(&midi->out);
- stream_close(&midi->in);
- close(midi->scan.wake_pipe[0]);
- close(midi->scan.wake_pipe[1]);
+ stream_close (&midi->out);
+ stream_close (&midi->in);
+ close (midi->scan.wake_pipe[0]);
+ close (midi->scan.wake_pipe[1]);
- free(midi);
+ free (midi);
}
static void* scan_thread(void *);
static void *midi_thread(void *arg);
static
-int alsa_rawmidi_attach(alsa_midi_t *m)
+int alsa_rawmidi_attach (alsa_midi_t *m)
{
return 0;
}
static
-int alsa_rawmidi_detach(alsa_midi_t *m)
+int alsa_rawmidi_detach (alsa_midi_t *m)
{
alsa_rawmidi_t *midi = (alsa_rawmidi_t*)m;
midi_port_t **list;
- alsa_rawmidi_stop(m);
+ alsa_rawmidi_stop (m);
list = &midi->scan.ports;
while (*list) {
(*list)->state = PORT_REMOVED_FROM_JACK;
- list = scan_port_del(midi, list);
+ list = scan_port_del (midi, list);
}
return 0;
}
static
-int alsa_rawmidi_start(alsa_midi_t *m)
+int alsa_rawmidi_start (alsa_midi_t *m)
{
alsa_rawmidi_t *midi = (alsa_rawmidi_t*)m;
int err;
char c = 'q';
- if (midi->keep_walking == 1)
+
+ if (midi->keep_walking == 1) {
return -EALREADY;
+ }
midi->keep_walking = 1;
- if ((err = jack_client_create_thread(midi->client, &midi->in.thread, MIDI_THREAD_PRIO, jack_is_realtime(midi->client), midi_thread, &midi->in))) {
+ if ((err = jack_client_create_thread (midi->client, &midi->in.thread, MIDI_THREAD_PRIO, jack_is_realtime (midi->client), midi_thread, &midi->in))) {
midi->keep_walking = 0;
return err;
}
- if ((err = jack_client_create_thread(midi->client, &midi->out.thread, MIDI_THREAD_PRIO, jack_is_realtime(midi->client), midi_thread, &midi->out))) {
+ if ((err = jack_client_create_thread (midi->client, &midi->out.thread, MIDI_THREAD_PRIO, jack_is_realtime (midi->client), midi_thread, &midi->out))) {
midi->keep_walking = 0;
- write(midi->in.wake_pipe[1], &c, 1);
- pthread_join(midi->in.thread, NULL);
+ write (midi->in.wake_pipe[1], &c, 1);
+ pthread_join (midi->in.thread, NULL);
return err;
}
- if ((err = jack_client_create_thread(midi->client, &midi->scan.thread, 0, 0, scan_thread, midi))) {
+ if ((err = jack_client_create_thread (midi->client, &midi->scan.thread, 0, 0, scan_thread, midi))) {
midi->keep_walking = 0;
- write(midi->in.wake_pipe[1], &c, 1);
- write(midi->out.wake_pipe[1], &c, 1);
- pthread_join(midi->in.thread, NULL);
- pthread_join(midi->out.thread, NULL);
+ write (midi->in.wake_pipe[1], &c, 1);
+ write (midi->out.wake_pipe[1], &c, 1);
+ pthread_join (midi->in.thread, NULL);
+ pthread_join (midi->out.thread, NULL);
return err;
}
return 0;
}
static
-int alsa_rawmidi_stop(alsa_midi_t *m)
+int alsa_rawmidi_stop (alsa_midi_t *m)
{
alsa_rawmidi_t *midi = (alsa_rawmidi_t*)m;
char c = 'q';
- if (midi->keep_walking == 0)
+
+ if (midi->keep_walking == 0) {
return -EALREADY;
+ }
midi->keep_walking = 0;
- write(midi->in.wake_pipe[1], &c, 1);
- write(midi->out.wake_pipe[1], &c, 1);
- write(midi->scan.wake_pipe[1], &c, 1);
- pthread_join(midi->in.thread, NULL);
- pthread_join(midi->out.thread, NULL);
- pthread_join(midi->scan.thread, NULL);
+ write (midi->in.wake_pipe[1], &c, 1);
+ write (midi->out.wake_pipe[1], &c, 1);
+ write (midi->scan.wake_pipe[1], &c, 1);
+ pthread_join (midi->in.thread, NULL);
+ pthread_join (midi->out.thread, NULL);
+ pthread_join (midi->scan.thread, NULL);
// ports are freed in alsa_midi_detach()
return 0;
}
@@ -394,59 +405,63 @@ int alsa_rawmidi_stop(alsa_midi_t *m)
static void jack_process(midi_stream_t *str, jack_nframes_t nframes);
static
-void alsa_rawmidi_read(alsa_midi_t *m, jack_nframes_t nframes)
+void alsa_rawmidi_read (alsa_midi_t *m, jack_nframes_t nframes)
{
alsa_rawmidi_t *midi = (alsa_rawmidi_t*)m;
- jack_process(&midi->in, nframes);
+
+ jack_process (&midi->in, nframes);
}
static
-void alsa_rawmidi_write(alsa_midi_t *m, jack_nframes_t nframes)
+void alsa_rawmidi_write (alsa_midi_t *m, jack_nframes_t nframes)
{
alsa_rawmidi_t *midi = (alsa_rawmidi_t*)m;
- jack_process(&midi->out, nframes);
+
+ jack_process (&midi->out, nframes);
}
/*
* -----------------------------------------------------------------------------
*/
static inline
-int can_pass(size_t sz, jack_ringbuffer_t *in, jack_ringbuffer_t *out)
+int can_pass (size_t sz, jack_ringbuffer_t *in, jack_ringbuffer_t *out)
{
- return jack_ringbuffer_read_space(in) >= sz && jack_ringbuffer_write_space(out) >= sz;
+ return jack_ringbuffer_read_space (in) >= sz && jack_ringbuffer_write_space (out) >= sz;
}
static
-void midi_port_init(const alsa_rawmidi_t *midi, midi_port_t *port, snd_rawmidi_info_t *info, const alsa_id_t *id)
+void midi_port_init (const alsa_rawmidi_t *midi, midi_port_t *port, snd_rawmidi_info_t *info, const alsa_id_t *id)
{
const char *name;
char *c;
port->id = *id;
- snprintf(port->dev, sizeof(port->dev), "hw:%d,%d,%d", id->id[0], id->id[1], id->id[3]);
- name = snd_rawmidi_info_get_subdevice_name(info);
- if (!strlen(name))
- name = snd_rawmidi_info_get_name(info);
- snprintf(port->name, sizeof(port->name), "%s %s %s", port->id.id[2] ? "out":"in", port->dev, name);
+ snprintf (port->dev, sizeof(port->dev), "hw:%d,%d,%d", id->id[0], id->id[1], id->id[3]);
+ name = snd_rawmidi_info_get_subdevice_name (info);
+ if (!strlen (name)) {
+ name = snd_rawmidi_info_get_name (info);
+ }
+ snprintf (port->name, sizeof(port->name), "%s %s %s", port->id.id[2] ? "out" : "in", port->dev, name);
// replace all offending characters with '-'
- for (c=port->name; *c; ++c)
- if (!isalnum(*c))
+ for (c = port->name; *c; ++c)
+ if (!isalnum (*c)) {
*c = '-';
+ }
port->state = PORT_CREATED;
}
static
-inline int midi_port_open_jack(const alsa_rawmidi_t *midi, midi_port_t *port, int type, const char *name)
+inline int midi_port_open_jack (const alsa_rawmidi_t *midi, midi_port_t *port, int type, const char *name)
{
- port->jack = jack_port_register(midi->client, name, JACK_DEFAULT_MIDI_TYPE,
- type | JackPortIsPhysical|JackPortIsTerminal, 0);
+ port->jack = jack_port_register (midi->client, name, JACK_DEFAULT_MIDI_TYPE,
+ type | JackPortIsPhysical | JackPortIsTerminal, 0);
return port->jack == NULL;
}
static
-int midi_port_open(const alsa_rawmidi_t *midi, midi_port_t *port)
+int midi_port_open (const alsa_rawmidi_t *midi, midi_port_t *port)
{
int err;
int type;
@@ -461,45 +476,49 @@ int midi_port_open(const alsa_rawmidi_t *midi, midi_port_t *port)
out = &port->rawmidi;
type = JackPortIsInput;
}
-
- if ((err = snd_rawmidi_open(in, out, port->dev, SND_RAWMIDI_NONBLOCK))<0)
+
+ if ((err = snd_rawmidi_open (in, out, port->dev, SND_RAWMIDI_NONBLOCK)) < 0) {
return err;
+ }
/* Some devices (emu10k1) have subdevs with the same name,
* and we need to generate unique port name for jack */
- snprintf(name, sizeof(name), "%s", port->name);
- if (midi_port_open_jack(midi, port, type, name)) {
+ snprintf (name, sizeof(name), "%s", port->name);
+ if (midi_port_open_jack (midi, port, type, name)) {
int num;
num = port->id.id[3] ? port->id.id[3] : port->id.id[1];
- snprintf(name, sizeof(name), "%s %d", port->name, num);
- if (midi_port_open_jack(midi, port, type, name))
+ snprintf (name, sizeof(name), "%s %d", port->name, num);
+ if (midi_port_open_jack (midi, port, type, name)) {
return 2;
+ }
}
- if ((port->event_ring = jack_ringbuffer_create(MAX_EVENTS*sizeof(event_head_t)))==NULL)
+ if ((port->event_ring = jack_ringbuffer_create (MAX_EVENTS * sizeof(event_head_t))) == NULL) {
return 3;
- if ((port->data_ring = jack_ringbuffer_create(MAX_DATA))==NULL)
+ }
+ if ((port->data_ring = jack_ringbuffer_create (MAX_DATA)) == NULL) {
return 4;
+ }
return 0;
}
static
-void midi_port_close(const alsa_rawmidi_t *midi, midi_port_t *port)
+void midi_port_close (const alsa_rawmidi_t *midi, midi_port_t *port)
{
if (port->data_ring) {
- jack_ringbuffer_free(port->data_ring);
+ jack_ringbuffer_free (port->data_ring);
port->data_ring = NULL;
}
if (port->event_ring) {
- jack_ringbuffer_free(port->event_ring);
+ jack_ringbuffer_free (port->event_ring);
port->event_ring = NULL;
}
if (port->jack) {
- jack_port_unregister(midi->client, port->jack);
+ jack_port_unregister (midi->client, port->jack);
port->jack = NULL;
}
if (port->rawmidi) {
- snd_rawmidi_close(port->rawmidi);
+ snd_rawmidi_close (port->rawmidi);
port->rawmidi = NULL;
}
}
@@ -509,31 +528,33 @@ void midi_port_close(const alsa_rawmidi_t *midi, midi_port_t *port)
*/
static
-int alsa_id_before(const alsa_id_t *p1, const alsa_id_t *p2)
+int alsa_id_before (const alsa_id_t *p1, const alsa_id_t *p2)
{
int i;
- for (i=0; i<4; ++i) {
- if (p1->id[i] < p2->id[i])
+
+ for (i = 0; i < 4; ++i) {
+ if (p1->id[i] < p2->id[i]) {
return 1;
- else if (p1->id[i] > p2->id[i])
+ } else if (p1->id[i] > p2->id[i]) {
return 0;
+ }
}
return 0;
}
static
-void alsa_get_id(alsa_id_t *id, snd_rawmidi_info_t *info)
+void alsa_get_id (alsa_id_t *id, snd_rawmidi_info_t *info)
{
- id->id[0] = snd_rawmidi_info_get_card(info);
- id->id[1] = snd_rawmidi_info_get_device(info);
- id->id[2] = snd_rawmidi_info_get_stream(info) == SND_RAWMIDI_STREAM_OUTPUT ? 1 : 0;
- id->id[3] = snd_rawmidi_info_get_subdevice(info);
+ id->id[0] = snd_rawmidi_info_get_card (info);
+ id->id[1] = snd_rawmidi_info_get_device (info);
+ id->id[2] = snd_rawmidi_info_get_stream (info) == SND_RAWMIDI_STREAM_OUTPUT ? 1 : 0;
+ id->id[3] = snd_rawmidi_info_get_subdevice (info);
}
static inline
-void alsa_error(const char *func, int err)
+void alsa_error (const char *func, int err)
{
- error_log("%s() failed", snd_strerror(err));
+ error_log ("%s() failed", snd_strerror (err));
}
typedef struct {
@@ -546,136 +567,145 @@ typedef struct {
static midi_port_t** scan_port_del(alsa_rawmidi_t *midi, midi_port_t **list);
static
-void scan_cleanup(alsa_rawmidi_t *midi)
+void scan_cleanup (alsa_rawmidi_t *midi)
{
midi_port_t **list = &midi->scan.ports;
+
while (*list)
- list = scan_port_del(midi, list);
+ list = scan_port_del (midi, list);
}
static void scan_card(scan_t *scan);
static midi_port_t** scan_port_open(alsa_rawmidi_t *midi, midi_port_t **list);
-void scan_cycle(alsa_rawmidi_t *midi)
+void scan_cycle (alsa_rawmidi_t *midi)
{
int card = -1, err;
scan_t scan;
midi_port_t **ports;
//debug_log("scan: cleanup");
- scan_cleanup(midi);
+ scan_cleanup (midi);
scan.midi = midi;
scan.iterator = &midi->scan.ports;
- snd_rawmidi_info_alloca(&scan.info);
+ snd_rawmidi_info_alloca (&scan.info);
//debug_log("scan: rescan");
- while ((err = snd_card_next(&card))>=0 && card>=0) {
+ while ((err = snd_card_next (&card)) >= 0 && card >= 0) {
char name[32];
- snprintf(name, sizeof(name), "hw:%d", card);
- if ((err = snd_ctl_open(&scan.ctl, name, SND_CTL_NONBLOCK))>=0) {
- scan_card(&scan);
- snd_ctl_close(scan.ctl);
- } else
- alsa_error("scan: snd_ctl_open", err);
+ snprintf (name, sizeof(name), "hw:%d", card);
+ if ((err = snd_ctl_open (&scan.ctl, name, SND_CTL_NONBLOCK)) >= 0) {
+ scan_card (&scan);
+ snd_ctl_close (scan.ctl);
+ } else {
+ alsa_error ("scan: snd_ctl_open", err);
+ }
}
// delayed open to workaround alsa<1.0.14 bug (can't open more than 1 subdevice if ctl is opened).
ports = &midi->scan.ports;
while (*ports) {
midi_port_t *port = *ports;
- if (port->state == PORT_CREATED)
- ports = scan_port_open(midi, ports);
- else
+ if (port->state == PORT_CREATED) {
+ ports = scan_port_open (midi, ports);
+ } else {
ports = &port->next;
+ }
}
}
static void scan_device(scan_t *scan);
static
-void scan_card(scan_t *scan)
+void scan_card (scan_t *scan)
{
int device = -1;
int err;
- while ((err = snd_ctl_rawmidi_next_device(scan->ctl, &device))>=0 && device >=0) {
- snd_rawmidi_info_set_device(scan->info, device);
-
- snd_rawmidi_info_set_stream(scan->info, SND_RAWMIDI_STREAM_INPUT);
- snd_rawmidi_info_set_subdevice(scan->info, 0);
- if ((err = snd_ctl_rawmidi_info(scan->ctl, scan->info))>=0)
- scan_device(scan);
- else if (err != -ENOENT)
- alsa_error("scan: snd_ctl_rawmidi_info on device", err);
-
- snd_rawmidi_info_set_stream(scan->info, SND_RAWMIDI_STREAM_OUTPUT);
- snd_rawmidi_info_set_subdevice(scan->info, 0);
- if ((err = snd_ctl_rawmidi_info(scan->ctl, scan->info))>=0)
- scan_device(scan);
- else if (err != -ENOENT)
- alsa_error("scan: snd_ctl_rawmidi_info on device", err);
+ while ((err = snd_ctl_rawmidi_next_device (scan->ctl, &device)) >= 0 && device >= 0) {
+ snd_rawmidi_info_set_device (scan->info, device);
+
+ snd_rawmidi_info_set_stream (scan->info, SND_RAWMIDI_STREAM_INPUT);
+ snd_rawmidi_info_set_subdevice (scan->info, 0);
+ if ((err = snd_ctl_rawmidi_info (scan->ctl, scan->info)) >= 0) {
+ scan_device (scan);
+ } else if (err != -ENOENT) {
+ alsa_error ("scan: snd_ctl_rawmidi_info on device", err);
+ }
+
+ snd_rawmidi_info_set_stream (scan->info, SND_RAWMIDI_STREAM_OUTPUT);
+ snd_rawmidi_info_set_subdevice (scan->info, 0);
+ if ((err = snd_ctl_rawmidi_info (scan->ctl, scan->info)) >= 0) {
+ scan_device (scan);
+ } else if (err != -ENOENT) {
+ alsa_error ("scan: snd_ctl_rawmidi_info on device", err);
+ }
}
}
static void scan_port_update(scan_t *scan);
static
-void scan_device(scan_t *scan)
+void scan_device (scan_t *scan)
{
int err;
int sub, nsubs = 0;
- nsubs = snd_rawmidi_info_get_subdevices_count(scan->info);
- for (sub=0; sub<nsubs; ++sub) {
- snd_rawmidi_info_set_subdevice(scan->info, sub);
- if ((err = snd_ctl_rawmidi_info(scan->ctl, scan->info)) < 0) {
- alsa_error("scan: snd_ctl_rawmidi_info on subdevice", err);
+ nsubs = snd_rawmidi_info_get_subdevices_count (scan->info);
+
+ for (sub = 0; sub < nsubs; ++sub) {
+ snd_rawmidi_info_set_subdevice (scan->info, sub);
+ if ((err = snd_ctl_rawmidi_info (scan->ctl, scan->info)) < 0) {
+ alsa_error ("scan: snd_ctl_rawmidi_info on subdevice", err);
continue;
}
- scan_port_update(scan);
+ scan_port_update (scan);
}
}
static midi_port_t** scan_port_add(scan_t *scan, const alsa_id_t *id, midi_port_t **list);
static
-void scan_port_update(scan_t *scan)
+void scan_port_update (scan_t *scan)
{
midi_port_t **list = scan->iterator;
alsa_id_t id;
- alsa_get_id(&id, scan->info);
- while (*list && alsa_id_before(&(*list)->id, &id))
- list = scan_port_del(scan->midi, list);
+ alsa_get_id (&id, scan->info);
- if (!*list || alsa_id_before(&id, &(*list)->id))
- list = scan_port_add(scan, &id, list);
- else if (*list)
+ while (*list && alsa_id_before (&(*list)->id, &id))
+ list = scan_port_del (scan->midi, list);
+
+ if (!*list || alsa_id_before (&id, &(*list)->id)) {
+ list = scan_port_add (scan, &id, list);
+ } else if (*list) {
list = &(*list)->next;
+ }
scan->iterator = list;
}
static
-midi_port_t** scan_port_add(scan_t *scan, const alsa_id_t *id, midi_port_t **list)
+midi_port_t** scan_port_add (scan_t *scan, const alsa_id_t *id, midi_port_t **list)
{
midi_port_t *port;
midi_stream_t *str = id->id[2] ? &scan->midi->out : &scan->midi->in;
- port = calloc(1, str->port_size);
- if (!port)
+ port = calloc (1, str->port_size);
+ if (!port) {
return list;
- midi_port_init(scan->midi, port, scan->info, id);
+ }
+ midi_port_init (scan->midi, port, scan->info, id);
port->next = *list;
*list = port;
- error_log("scan: added port %s %s", port->dev, port->name);
+ error_log ("scan: added port %s %s", port->dev, port->name);
return &port->next;
}
static
-midi_port_t** scan_port_open(alsa_rawmidi_t *midi, midi_port_t **list)
+midi_port_t** scan_port_open (alsa_rawmidi_t *midi, midi_port_t **list)
{
midi_stream_t *str;
midi_port_t *port;
@@ -683,43 +713,48 @@ midi_port_t** scan_port_open(alsa_rawmidi_t *midi, midi_port_t **list)
port = *list;
str = port->id.id[2] ? &midi->out : &midi->in;
- if (jack_ringbuffer_write_space(str->jack.new_ports) < sizeof(port))
+ if (jack_ringbuffer_write_space (str->jack.new_ports) < sizeof(port)) {
goto fail_0;
+ }
- if (midi_port_open(midi, port))
+ if (midi_port_open (midi, port)) {
goto fail_1;
- if ((str->port_init)(midi, port))
+ }
+ if ((str->port_init)(midi, port)) {
goto fail_2;
+ }
port->state = PORT_ADDED_TO_JACK;
- jack_ringbuffer_write(str->jack.new_ports, (char*) &port, sizeof(port));
+ jack_ringbuffer_write (str->jack.new_ports, (char*)&port, sizeof(port));
- error_log("scan: opened port %s %s", port->dev, port->name);
+ error_log ("scan: opened port %s %s", port->dev, port->name);
return &port->next;
- fail_2:
- (str->port_close)(midi, port);
- fail_1:
- midi_port_close(midi, port);
+fail_2:
+ (str->port_close)(midi, port);
+fail_1:
+ midi_port_close (midi, port);
port->state = PORT_ZOMBIFIED;
- fail_0:
- error_log("scan: can't open port %s %s", port->dev, port->name);
+fail_0:
+ error_log ("scan: can't open port %s %s", port->dev, port->name);
return &port->next;
}
static
-midi_port_t** scan_port_del(alsa_rawmidi_t *midi, midi_port_t **list)
+midi_port_t** scan_port_del (alsa_rawmidi_t *midi, midi_port_t **list)
{
midi_port_t *port = *list;
+
if (port->state == PORT_REMOVED_FROM_JACK) {
- error_log("scan: deleted port %s %s", port->dev, port->name);
+ error_log ("scan: deleted port %s %s", port->dev, port->name);
*list = port->next;
- if (port->id.id[2] )
+ if (port->id.id[2] ) {
(midi->out.port_close)(midi, port);
- else
+ } else {
(midi->in.port_close)(midi, port);
- midi_port_close(midi, port);
- free(port);
+ }
+ midi_port_close (midi, port);
+ free (port);
return list;
} else {
//debug_log("can't delete port %s, wrong state: %d", port->name, (int)port->state);
@@ -727,111 +762,117 @@ midi_port_t** scan_port_del(alsa_rawmidi_t *midi, midi_port_t **list)
}
}
-void* scan_thread(void *arg)
+void* scan_thread (void *arg)
{
alsa_rawmidi_t *midi = arg;
struct pollfd wakeup;
wakeup.fd = midi->scan.wake_pipe[0];
- wakeup.events = POLLIN|POLLERR|POLLNVAL;
+ wakeup.events = POLLIN | POLLERR | POLLNVAL;
while (midi->keep_walking) {
int res;
//error_log("scanning....");
- scan_cycle(midi);
- res = poll(&wakeup, 1, 2000);
- if (res>0) {
+ scan_cycle (midi);
+ res = poll (&wakeup, 1, 2000);
+ if (res > 0) {
char c;
- read(wakeup.fd, &c, 1);
- } else if (res<0 && errno != EINTR)
+ read (wakeup.fd, &c, 1);
+ } else if (res < 0 && errno != EINTR) {
break;
+ }
}
return NULL;
}
-/*
+/*
* ------------------------------- Input/Output ------------------------------
*/
static
-void jack_add_ports(midi_stream_t *str)
+void jack_add_ports (midi_stream_t *str)
{
midi_port_t *port;
- while (can_pass(sizeof(port), str->jack.new_ports, str->midi.new_ports) && str->jack.nports < MAX_PORTS) {
- jack_ringbuffer_read(str->jack.new_ports, (char*)&port, sizeof(port));
+
+ while (can_pass (sizeof(port), str->jack.new_ports, str->midi.new_ports) && str->jack.nports < MAX_PORTS) {
+ jack_ringbuffer_read (str->jack.new_ports, (char*)&port, sizeof(port));
str->jack.ports[str->jack.nports++] = port;
port->state = PORT_ADDED_TO_MIDI;
- jack_ringbuffer_write(str->midi.new_ports, (char*)&port, sizeof(port));
+ jack_ringbuffer_write (str->midi.new_ports, (char*)&port, sizeof(port));
}
}
static
-void jack_process(midi_stream_t *str, jack_nframes_t nframes)
+void jack_process (midi_stream_t *str, jack_nframes_t nframes)
{
int r, w;
process_jack_t proc;
jack_nframes_t cur_frames;
- if (!str->owner->keep_walking)
+ if (!str->owner->keep_walking) {
return;
+ }
proc.midi = str->owner;
proc.nframes = nframes;
- proc.frame_time = jack_last_frame_time(proc.midi->client);
- cur_frames = jack_frame_time(proc.midi->client);
+ proc.frame_time = jack_last_frame_time (proc.midi->client);
+ cur_frames = jack_frame_time (proc.midi->client);
if (proc.frame_time + proc.nframes < cur_frames) {
int periods_lost = (cur_frames - proc.frame_time) / proc.nframes;
proc.frame_time += periods_lost * proc.nframes;
- debug_log("xrun detected: %d periods lost", periods_lost);
+ debug_log ("xrun detected: %d periods lost", periods_lost);
}
// process existing ports
- for (r=0, w=0; r<str->jack.nports; ++r) {
+ for (r = 0, w = 0; r < str->jack.nports; ++r) {
midi_port_t *port = str->jack.ports[r];
proc.port = port;
assert (port->state > PORT_ADDED_TO_JACK && port->state < PORT_REMOVED_FROM_JACK);
- proc.buffer = jack_port_get_buffer(port->jack, nframes);
- if (str->mode == POLLIN)
- jack_midi_clear_buffer(proc.buffer);
+ proc.buffer = jack_port_get_buffer (port->jack, nframes);
+ if (str->mode == POLLIN) {
+ jack_midi_clear_buffer (proc.buffer);
+ }
if (port->state == PORT_REMOVED_FROM_MIDI) {
- port->state = PORT_REMOVED_FROM_JACK; // this signals to scan thread
- continue; // this effectively removes port from the midi->in.jack.ports[]
+ port->state = PORT_REMOVED_FROM_JACK; // this signals to scan thread
+ continue; // this effectively removes port from the midi->in.jack.ports[]
}
(str->process_jack)(&proc);
- if (r != w)
+ if (r != w) {
str->jack.ports[w] = port;
+ }
++w;
}
- if (str->jack.nports != w)
- debug_log("jack_%s: nports %d -> %d", str->name, str->jack.nports, w);
+ if (str->jack.nports != w) {
+ debug_log ("jack_%s: nports %d -> %d", str->name, str->jack.nports, w);
+ }
str->jack.nports = w;
- jack_add_ports(str); // it makes no sense to add them earlier since they have no data yet
+ jack_add_ports (str); // it makes no sense to add them earlier since they have no data yet
// wake midi thread
- write(str->wake_pipe[1], &r, 1);
+ write (str->wake_pipe[1], &r, 1);
}
static
-void *midi_thread(void *arg)
+void *midi_thread (void *arg)
{
midi_stream_t *str = arg;
alsa_rawmidi_t *midi = str->owner;
struct pollfd pfds[MAX_PFDS];
int npfds;
- jack_time_t wait_nsec = 1000*1000*1000; // 1 sec
+ jack_time_t wait_nsec = 1000 * 1000 * 1000; // 1 sec
process_midi_t proc;
proc.midi = midi;
proc.mode = str->mode;
pfds[0].fd = str->wake_pipe[0];
- pfds[0].events = POLLIN|POLLERR|POLLNVAL;
+ pfds[0].events = POLLIN | POLLERR | POLLNVAL;
npfds = 1;
//debug_log("midi_thread(%s): enter", str->name);
@@ -839,47 +880,50 @@ void *midi_thread(void *arg)
while (midi->keep_walking) {
int poll_timeout;
int wait_nanosleep;
- int r=1, w=1; // read,write pos in pfds
- int rp=0, wp=0; // read, write pos in ports
+ int r = 1, w = 1; // read,write pos in pfds
+ int rp = 0, wp = 0; // read, write pos in ports
// sleep
//if (wait_nsec != 1000*1000*1000) {
// debug_log("midi_thread(%s): ", str->name);
// assert (wait_nsec == 1000*1000*1000);
//}
- poll_timeout = wait_nsec / (1000*1000);
- wait_nanosleep = wait_nsec % (1000*1000);
+ poll_timeout = wait_nsec / (1000 * 1000);
+ wait_nanosleep = wait_nsec % (1000 * 1000);
if (wait_nanosleep > NANOSLEEP_RESOLUTION) {
struct timespec ts;
ts.tv_sec = 0;
ts.tv_nsec = wait_nanosleep;
- clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, NULL);
+ clock_nanosleep (CLOCK_MONOTONIC, 0, &ts, NULL);
}
- int res = poll((struct pollfd*)&pfds, npfds, poll_timeout);
+ int res = poll ((struct pollfd*)&pfds, npfds, poll_timeout);
//debug_log("midi_thread(%s): poll exit: %d", str->name, res);
- if (!midi->keep_walking)
+ if (!midi->keep_walking) {
break;
+ }
if (res < 0) {
- if (errno == EINTR)
+ if (errno == EINTR) {
continue;
- error_log("midi_thread(%s) poll failed: %s", str->name, strerror(errno));
+ }
+ error_log ("midi_thread(%s) poll failed: %s", str->name, strerror (errno));
break;
}
// check wakeup pipe
- if (pfds[0].revents & ~POLLIN)
+ if (pfds[0].revents & ~POLLIN) {
break;
+ }
if (pfds[0].revents & POLLIN) {
char c;
- read(pfds[0].fd, &c, 1);
+ read (pfds[0].fd, &c, 1);
}
// add new ports
- while (jack_ringbuffer_read_space(str->midi.new_ports) >= sizeof(midi_port_t*) && str->midi.nports < MAX_PORTS) {
+ while (jack_ringbuffer_read_space (str->midi.new_ports) >= sizeof(midi_port_t*) && str->midi.nports < MAX_PORTS) {
midi_port_t *port;
- jack_ringbuffer_read(str->midi.new_ports, (char*)&port, sizeof(port));
+ jack_ringbuffer_read (str->midi.new_ports, (char*)&port, sizeof(port));
str->midi.ports[str->midi.nports++] = port;
- debug_log("midi_thread(%s): added port %s", str->name, port->name);
+ debug_log ("midi_thread(%s): added port %s", str->name, port->name);
}
// if (res == 0)
@@ -891,26 +935,29 @@ void *midi_thread(void *arg)
for (rp = 0; rp < str->midi.nports; ++rp) {
midi_port_t *port = str->midi.ports[rp];
- proc.cur_time = jack_frame_time(midi->client);
+ proc.cur_time = jack_frame_time (midi->client);
proc.port = port;
proc.rpfds = &pfds[r];
proc.wpfds = &pfds[w];
proc.max_pfds = MAX_PFDS - w;
r += port->npfds;
if (!(str->process_midi)(&proc)) {
- port->state = PORT_REMOVED_FROM_MIDI; // this signals to jack thread
- continue; // this effectively removes port from array
+ port->state = PORT_REMOVED_FROM_MIDI; // this signals to jack thread
+ continue; // this effectively removes port from array
}
w += port->npfds;
- if (rp != wp)
+ if (rp != wp) {
str->midi.ports[wp] = port;
+ }
++wp;
}
- if (str->midi.nports != wp)
- debug_log("midi_%s: nports %d -> %d", str->name, str->midi.nports, wp);
+ if (str->midi.nports != wp) {
+ debug_log ("midi_%s: nports %d -> %d", str->name, str->midi.nports, wp);
+ }
str->midi.nports = wp;
- if (npfds != w)
- debug_log("midi_%s: npfds %d -> %d", str->name, npfds, w);
+ if (npfds != w) {
+ debug_log ("midi_%s: npfds %d -> %d", str->name, npfds, w);
+ }
npfds = w;
/*
@@ -919,75 +966,79 @@ void *midi_thread(void *arg)
* So, zero timeout will not cause busy-looping.
*/
if (proc.next_time < proc.cur_time) {
- debug_log("%s: late: next_time = %d, cur_time = %d", str->name, (int)proc.next_time, (int)proc.cur_time);
+ debug_log ("%s: late: next_time = %d, cur_time = %d", str->name, (int)proc.next_time, (int)proc.cur_time);
wait_nsec = 0; // we are late
} else if (proc.next_time != NFRAMES_INF) {
jack_time_t wait_frames = proc.next_time - proc.cur_time;
- jack_nframes_t rate = jack_get_sample_rate(midi->client);
- wait_nsec = (wait_frames * (1000*1000*1000)) / rate;
- debug_log("midi_%s: timeout = %d", str->name, (int)wait_frames);
- } else
- wait_nsec = 1000*1000*1000;
+ jack_nframes_t rate = jack_get_sample_rate (midi->client);
+ wait_nsec = (wait_frames * (1000 * 1000 * 1000)) / rate;
+ debug_log ("midi_%s: timeout = %d", str->name, (int)wait_frames);
+ } else {
+ wait_nsec = 1000 * 1000 * 1000;
+ }
//debug_log("midi_thread(%s): wait_nsec = %lld", str->name, wait_nsec);
}
return NULL;
}
static
-int midi_is_ready(process_midi_t *proc)
+int midi_is_ready (process_midi_t *proc)
{
midi_port_t *port = proc->port;
+
if (port->npfds) {
unsigned short revents = 0;
- int res = snd_rawmidi_poll_descriptors_revents(port->rawmidi, proc->rpfds, port->npfds, &revents);
+ int res = snd_rawmidi_poll_descriptors_revents (port->rawmidi, proc->rpfds, port->npfds, &revents);
if (res) {
- error_log("snd_rawmidi_poll_descriptors_revents failed on port %s with: %s", port->name, snd_strerror(res));
+ error_log ("snd_rawmidi_poll_descriptors_revents failed on port %s with: %s", port->name, snd_strerror (res));
return 0;
}
if (revents & ~proc->mode) {
- debug_log("midi: port %s failed", port->name);
+ debug_log ("midi: port %s failed", port->name);
return 0;
}
if (revents & proc->mode) {
port->is_ready = 1;
- debug_log("midi: is_ready %s", port->name);
+ debug_log ("midi: is_ready %s", port->name);
}
}
return 1;
}
static
-int midi_update_pfds(process_midi_t *proc)
+int midi_update_pfds (process_midi_t *proc)
{
midi_port_t *port = proc->port;
+
if (port->npfds == 0) {
- port->npfds = snd_rawmidi_poll_descriptors_count(port->rawmidi);
+ port->npfds = snd_rawmidi_poll_descriptors_count (port->rawmidi);
if (port->npfds > proc->max_pfds) {
- debug_log("midi: not enough pfds for port %s", port->name);
+ debug_log ("midi: not enough pfds for port %s", port->name);
return 0;
}
- snd_rawmidi_poll_descriptors(port->rawmidi, proc->wpfds, port->npfds);
+ snd_rawmidi_poll_descriptors (port->rawmidi, proc->wpfds, port->npfds);
} else if (proc->rpfds != proc->wpfds) {
- memmove(proc->wpfds, proc->rpfds, sizeof(struct pollfd) * port->npfds);
+ memmove (proc->wpfds, proc->rpfds, sizeof(struct pollfd) * port->npfds);
}
return 1;
}
-/*
+/*
* ------------------------------------ Input ------------------------------
*/
static
-int input_port_init(alsa_rawmidi_t *midi, midi_port_t *port)
+int input_port_init (alsa_rawmidi_t *midi, midi_port_t *port)
{
input_port_t *in = (input_port_t*)port;
- midi_unpack_init(&in->unpack);
+
+ midi_unpack_init (&in->unpack);
return 0;
}
static
-void input_port_close(alsa_rawmidi_t *midi, midi_port_t *port)
+void input_port_close (alsa_rawmidi_t *midi, midi_port_t *port)
{
}
@@ -996,41 +1047,44 @@ void input_port_close(alsa_rawmidi_t *midi, midi_port_t *port)
*/
static
-void do_jack_input(process_jack_t *p)
+void do_jack_input (process_jack_t *p)
{
- input_port_t *port = (input_port_t*) p->port;
+ input_port_t *port = (input_port_t*)p->port;
event_head_t event;
- while (jack_ringbuffer_read_space(port->base.event_ring) >= sizeof(event)) {
+
+ while (jack_ringbuffer_read_space (port->base.event_ring) >= sizeof(event)) {
jack_ringbuffer_data_t vec[2];
jack_nframes_t time;
int i, todo;
- jack_ringbuffer_read(port->base.event_ring, (char*)&event, sizeof(event));
+ jack_ringbuffer_read (port->base.event_ring, (char*)&event, sizeof(event));
// TODO: take into account possible warping
- if ((event.time + p->nframes) < p->frame_time)
+ if ((event.time + p->nframes) < p->frame_time) {
time = 0;
- else if (event.time >= p->frame_time)
- time = p->nframes -1;
- else
+ } else if (event.time >= p->frame_time) {
+ time = p->nframes - 1;
+ } else {
time = event.time + p->nframes - p->frame_time;
+ }
- jack_ringbuffer_get_read_vector(port->base.data_ring, vec);
+ jack_ringbuffer_get_read_vector (port->base.data_ring, vec);
assert ((vec[0].len + vec[1].len) >= event.size);
- if (event.overruns)
- midi_unpack_reset(&port->unpack);
+ if (event.overruns) {
+ midi_unpack_reset (&port->unpack);
+ }
todo = event.size;
- for (i=0; i<2 && todo>0; ++i) {
+ for (i = 0; i < 2 && todo > 0; ++i) {
int avail = todo < vec[i].len ? todo : vec[i].len;
- int done = midi_unpack_buf(&port->unpack, (unsigned char*)vec[i].buf, avail, p->buffer, time);
+ int done = midi_unpack_buf (&port->unpack, (unsigned char*)vec[i].buf, avail, p->buffer, time);
if (done != avail) {
- debug_log("jack_in: buffer overflow in port %s", port->base.name);
+ debug_log ("jack_in: buffer overflow in port %s", port->base.name);
break;
}
todo -= done;
}
- jack_ringbuffer_read_advance(port->base.data_ring, event.size);
+ jack_ringbuffer_read_advance (port->base.data_ring, event.size);
}
}
@@ -1038,28 +1092,31 @@ void do_jack_input(process_jack_t *p)
* Low level input.
*/
static
-int do_midi_input(process_midi_t *proc)
+int do_midi_input (process_midi_t *proc)
{
- input_port_t *port = (input_port_t*) proc->port;
- if (!midi_is_ready(proc))
+ input_port_t *port = (input_port_t*)proc->port;
+
+ if (!midi_is_ready (proc)) {
return 0;
+ }
if (port->base.is_ready) {
jack_ringbuffer_data_t vec[2];
int res;
- jack_ringbuffer_get_write_vector(port->base.data_ring, vec);
- if (jack_ringbuffer_write_space(port->base.event_ring) < sizeof(event_head_t) || vec[0].len < 1) {
+ jack_ringbuffer_get_write_vector (port->base.data_ring, vec);
+ if (jack_ringbuffer_write_space (port->base.event_ring) < sizeof(event_head_t) || vec[0].len < 1) {
port->overruns++;
- if (port->base.npfds)
- debug_log("midi_in: internal overflow on %s", port->base.name);
+ if (port->base.npfds) {
+ debug_log ("midi_in: internal overflow on %s", port->base.name);
+ }
// remove from poll to prevent busy-looping
port->base.npfds = 0;
return 1;
}
- res = snd_rawmidi_read(port->base.rawmidi, vec[0].buf, vec[0].len);
+ res = snd_rawmidi_read (port->base.rawmidi, vec[0].buf, vec[0].len);
if (res < 0 && res != -EWOULDBLOCK) {
- error_log("midi_in: reading from port %s failed: %s", port->base.name, snd_strerror(res));
+ error_log ("midi_in: reading from port %s failed: %s", port->base.name, snd_strerror (res));
return 0;
} else if (res > 0) {
event_head_t event;
@@ -1067,94 +1124,101 @@ int do_midi_input(process_midi_t *proc)
event.size = res;
event.overruns = port->overruns;
port->overruns = 0;
- debug_log("midi_in: read %d bytes at %d", (int)event.size, (int)event.time);
- jack_ringbuffer_write_advance(port->base.data_ring, event.size);
- jack_ringbuffer_write(port->base.event_ring, (char*)&event, sizeof(event));
+ debug_log ("midi_in: read %d bytes at %d", (int)event.size, (int)event.time);
+ jack_ringbuffer_write_advance (port->base.data_ring, event.size);
+ jack_ringbuffer_write (port->base.event_ring, (char*)&event, sizeof(event));
}
port->base.is_ready = 0;
}
- if (!midi_update_pfds(proc))
+ if (!midi_update_pfds (proc)) {
return 0;
+ }
return 1;
}
-/*
+/*
* ------------------------------------ Output ------------------------------
*/
-static int output_port_init(alsa_rawmidi_t *midi, midi_port_t *port)
+static int output_port_init (alsa_rawmidi_t *midi, midi_port_t *port)
{
output_port_t *out = (output_port_t*)port;
- midi_pack_reset(&out->packer);
+
+ midi_pack_reset (&out->packer);
out->next_event.time = 0;
out->next_event.size = 0;
out->todo = 0;
return 0;
}
-static void output_port_close(alsa_rawmidi_t *midi, midi_port_t *port)
+static void output_port_close (alsa_rawmidi_t *midi, midi_port_t *port)
{
}
static
-void do_jack_output(process_jack_t *proc)
+void do_jack_output (process_jack_t *proc)
{
- output_port_t *port = (output_port_t*) proc->port;
- int nevents = jack_midi_get_event_count(proc->buffer);
+ output_port_t *port = (output_port_t*)proc->port;
+ int nevents = jack_midi_get_event_count (proc->buffer);
int i;
- if (nevents)
- debug_log("jack_out: %d events in %s", nevents, port->base.name);
- for (i=0; i<nevents; ++i) {
+
+ if (nevents) {
+ debug_log ("jack_out: %d events in %s", nevents, port->base.name);
+ }
+ for (i = 0; i < nevents; ++i) {
jack_midi_event_t event;
event_head_t hdr;
- jack_midi_event_get(&event, proc->buffer, i);
+ jack_midi_event_get (&event, proc->buffer, i);
- if (jack_ringbuffer_write_space(port->base.data_ring) < event.size || jack_ringbuffer_write_space(port->base.event_ring) < sizeof(hdr)) {
- debug_log("jack_out: output buffer overflow on %s", port->base.name);
+ if (jack_ringbuffer_write_space (port->base.data_ring) < event.size || jack_ringbuffer_write_space (port->base.event_ring) < sizeof(hdr)) {
+ debug_log ("jack_out: output buffer overflow on %s", port->base.name);
break;
}
- midi_pack_event(&port->packer, &event);
+ midi_pack_event (&port->packer, &event);
- jack_ringbuffer_write(port->base.data_ring, (char*)event.buffer, event.size);
+ jack_ringbuffer_write (port->base.data_ring, (char*)event.buffer, event.size);
hdr.time = proc->frame_time + event.time + proc->nframes;
hdr.size = event.size;
- jack_ringbuffer_write(port->base.event_ring, (char*)&hdr, sizeof(hdr));
- debug_log("jack_out: sent %d-byte event at %ld", (int)event.size, (long)event.time);
+ jack_ringbuffer_write (port->base.event_ring, (char*)&hdr, sizeof(hdr));
+ debug_log ("jack_out: sent %d-byte event at %ld", (int)event.size, (long)event.time);
}
}
static
-int do_midi_output(process_midi_t *proc)
+int do_midi_output (process_midi_t *proc)
{
int worked = 0;
- output_port_t *port = (output_port_t*) proc->port;
+ output_port_t *port = (output_port_t*)proc->port;
- if (!midi_is_ready(proc))
+ if (!midi_is_ready (proc)) {
return 0;
+ }
// eat events
while (port->next_event.time <= proc->cur_time) {
port->todo += port->next_event.size;
- if (jack_ringbuffer_read(port->base.event_ring, (char*)&port->next_event, sizeof(port->next_event))!=sizeof(port->next_event)) {
+ if (jack_ringbuffer_read (port->base.event_ring, (char*)&port->next_event, sizeof(port->next_event)) != sizeof(port->next_event)) {
port->next_event.time = 0;
port->next_event.size = 0;
break;
- } else
- debug_log("midi_out: at %ld got %d bytes for %ld", (long)proc->cur_time, (int)port->next_event.size, (long)port->next_event.time);
+ } else {
+ debug_log ("midi_out: at %ld got %d bytes for %ld", (long)proc->cur_time, (int)port->next_event.size, (long)port->next_event.time);
+ }
+ }
+
+ if (port->todo) {
+ debug_log ("midi_out: todo = %d at %ld", (int)port->todo, (long)proc->cur_time);
}
-
- if (port->todo)
- debug_log("midi_out: todo = %d at %ld", (int)port->todo, (long)proc->cur_time);
// calc next wakeup time
if (!port->todo && port->next_event.time && port->next_event.time < proc->next_time) {
proc->next_time = port->next_event.time;
- debug_log("midi_out: next_time = %ld", (long)proc->next_time);
+ debug_log ("midi_out: next_time = %ld", (long)proc->next_time);
}
if (port->todo && port->base.is_ready) {
@@ -1163,41 +1227,43 @@ int do_midi_output(process_midi_t *proc)
int res;
jack_ringbuffer_data_t vec[2];
- jack_ringbuffer_get_read_vector(port->base.data_ring, vec);
+ jack_ringbuffer_get_read_vector (port->base.data_ring, vec);
if (size > vec[0].len) {
size = vec[0].len;
assert (size > 0);
}
- res = snd_rawmidi_write(port->base.rawmidi, vec[0].buf, size);
+ res = snd_rawmidi_write (port->base.rawmidi, vec[0].buf, size);
if (res > 0) {
- jack_ringbuffer_read_advance(port->base.data_ring, res);
- debug_log("midi_out: written %d bytes to %s", res, port->base.name);
+ jack_ringbuffer_read_advance (port->base.data_ring, res);
+ debug_log ("midi_out: written %d bytes to %s", res, port->base.name);
port->todo -= res;
worked = 1;
} else if (res == -EWOULDBLOCK) {
port->base.is_ready = 0;
- debug_log("midi_out: -EWOULDBLOCK on %s", port->base.name);
+ debug_log ("midi_out: -EWOULDBLOCK on %s", port->base.name);
return 1;
} else {
- error_log("midi_out: writing to port %s failed: %s", port->base.name, snd_strerror(res));
+ error_log ("midi_out: writing to port %s failed: %s", port->base.name, snd_strerror (res));
return 0;
}
- snd_rawmidi_drain(port->base.rawmidi);
+ snd_rawmidi_drain (port->base.rawmidi);
}
// update pfds for this port
- if (!midi_update_pfds(proc))
+ if (!midi_update_pfds (proc)) {
return 0;
+ }
if (!port->todo) {
int i;
- if (worked)
- debug_log("midi_out: relaxing on %s", port->base.name);
- for (i=0; i<port->base.npfds; ++i)
+ if (worked) {
+ debug_log ("midi_out: relaxing on %s", port->base.name);
+ }
+ for (i = 0; i < port->base.npfds; ++i)
proc->wpfds[i].events &= ~POLLOUT;
} else {
int i;
- for (i=0; i<port->base.npfds; ++i)
+ for (i = 0; i < port->base.npfds; ++i)
proc->wpfds[i].events |= POLLOUT;
}
return 1;
diff --git a/drivers/am/alsa_seqmidi.c b/drivers/am/alsa_seqmidi.c
index 3351b36..58db4b2 100644
--- a/drivers/am/alsa_seqmidi.c
+++ b/drivers/am/alsa_seqmidi.c
@@ -21,21 +21,21 @@
/*
* alsa_seqmidi_read:
* add new ports
- * reads queued snd_seq_event's
- * if PORT_EXIT: mark port as dead
- * if PORT_ADD, PORT_CHANGE: send addr to port_thread (it also may mark port as dead)
- * else process input event
- * remove dead ports and send them to port_thread
+ * reads queued snd_seq_event's
+ * if PORT_EXIT: mark port as dead
+ * if PORT_ADD, PORT_CHANGE: send addr to port_thread (it also may mark port as dead)
+ * else process input event
+ * remove dead ports and send them to port_thread
*
* alsa_seqmidi_write:
- * remove dead ports and send them to port_thread
- * add new ports
- * queue output events
+ * remove dead ports and send them to port_thread
+ * add new ports
+ * queue output events
*
* port_thread:
- * wait for port_sem
- * free deleted ports
- * create new ports or mark existing as dead
+ * wait for port_sem
+ * free deleted ports
+ * create new ports or mark existing as dead
*/
#include <alsa/asoundlib.h>
#include <jack/jack.h>
@@ -52,29 +52,29 @@
#include "alsa_midi.h"
#ifndef SND_SEQ_PORT_TYPE_PORT
-#define SND_SEQ_PORT_TYPE_PORT (1<<19) /* Appears in version 1.0.12rc1 */
+#define SND_SEQ_PORT_TYPE_PORT (1 << 19) /* Appears in version 1.0.12rc1 */
#endif
#ifndef SND_SEQ_PORT_TYPE_HARDWARE
-#define SND_SEQ_PORT_TYPE_HARDWARE (1<<16) /* Appears in version 1.0.12rc1 */
+#define SND_SEQ_PORT_TYPE_HARDWARE (1 << 16) /* Appears in version 1.0.12rc1 */
#endif
#ifdef STANDALONE
-#define MESSAGE(...) fprintf(stderr, __VA_ARGS__)
+#define MESSAGE(...) fprintf (stderr, __VA_ARGS__)
#else
#include "messagebuffer.h"
#endif
-#define info_log(...) MESSAGE(__VA_ARGS__)
-#define error_log(...) MESSAGE(__VA_ARGS__)
+#define info_log(...) MESSAGE (__VA_ARGS__)
+#define error_log(...) MESSAGE (__VA_ARGS__)
#ifdef JACK_MIDI_DEBUG
-#define debug_log(...) MESSAGE(__VA_ARGS__)
+#define debug_log(...) MESSAGE (__VA_ARGS__)
#else
#define debug_log(...)
#endif
-#define NSEC_PER_SEC ((int64_t)1000*1000*1000)
+#define NSEC_PER_SEC ((int64_t)1000 * 1000 * 1000)
enum {
MAX_PORTS = 64,
@@ -124,8 +124,8 @@ typedef struct alsa_seqmidi {
pthread_t port_thread;
sem_t port_sem;
- jack_ringbuffer_t *port_add; // snd_seq_addr_t
- jack_ringbuffer_t *port_del; // port_t*
+ jack_ringbuffer_t *port_add; // snd_seq_addr_t
+ jack_ringbuffer_t *port_del; // port_t*
stream_t stream[2];
@@ -150,7 +150,7 @@ struct process_info {
enum PortType { PORT_INPUT = 0, PORT_OUTPUT = 1 };
-typedef void (*port_jack_func)(alsa_seqmidi_t *self, port_t *port,struct process_info* info);
+typedef void (*port_jack_func)(alsa_seqmidi_t *self, port_t *port, struct process_info* info);
static void do_jack_input(alsa_seqmidi_t *self, port_t *port, struct process_info* info);
static void do_jack_output(alsa_seqmidi_t *self, port_t *port, struct process_info* info);
@@ -186,36 +186,36 @@ static void alsa_seqmidi_read(alsa_midi_t *m, jack_nframes_t nframes);
static void alsa_seqmidi_write(alsa_midi_t *m, jack_nframes_t nframes);
static
-void stream_init(alsa_seqmidi_t *self, int dir)
+void stream_init (alsa_seqmidi_t *self, int dir)
{
stream_t *str = &self->stream[dir];
- str->new_ports = jack_ringbuffer_create(MAX_PORTS*sizeof(port_t*));
- snd_midi_event_new(MAX_EVENT_SIZE, &str->codec);
+ str->new_ports = jack_ringbuffer_create (MAX_PORTS * sizeof(port_t*));
+ snd_midi_event_new (MAX_EVENT_SIZE, &str->codec);
}
static void port_free(alsa_seqmidi_t *self, port_t *port);
static void free_ports(alsa_seqmidi_t *self, jack_ringbuffer_t *ports);
static
-void stream_attach(alsa_seqmidi_t *self, int dir)
+void stream_attach (alsa_seqmidi_t *self, int dir)
{
}
static
-void stream_detach(alsa_seqmidi_t *self, int dir)
+void stream_detach (alsa_seqmidi_t *self, int dir)
{
stream_t *str = &self->stream[dir];
int i;
- free_ports(self, str->new_ports);
+ free_ports (self, str->new_ports);
// delete all ports from hash
- for (i=0; i<PORT_HASH_SIZE; ++i) {
+ for (i = 0; i < PORT_HASH_SIZE; ++i) {
port_t *port = str->ports[i];
while (port) {
port_t *next = port->next;
- port_free(self, port);
+ port_free (self, port);
port = next;
}
str->ports[i] = NULL;
@@ -223,33 +223,38 @@ void stream_detach(alsa_seqmidi_t *self, int dir)
}
static
-void stream_close(alsa_seqmidi_t *self, int dir)
+void stream_close (alsa_seqmidi_t *self, int dir)
{
stream_t *str = &self->stream[dir];
- if (str->codec)
- snd_midi_event_free(str->codec);
- if (str->new_ports)
- jack_ringbuffer_free(str->new_ports);
+ if (str->codec) {
+ snd_midi_event_free (str->codec);
+ }
+ if (str->new_ports) {
+ jack_ringbuffer_free (str->new_ports);
+ }
}
-alsa_midi_t* alsa_seqmidi_new(jack_client_t *client, const char* alsa_name)
+alsa_midi_t* alsa_seqmidi_new (jack_client_t *client, const char* alsa_name)
{
- alsa_seqmidi_t *self = calloc(1, sizeof(alsa_seqmidi_t));
- debug_log("midi: new\n");
- if (!self)
+ alsa_seqmidi_t *self = calloc (1, sizeof(alsa_seqmidi_t));
+
+ debug_log ("midi: new\n");
+ if (!self) {
return NULL;
+ }
self->jack = client;
- if (!alsa_name)
+ if (!alsa_name) {
alsa_name = "jack_midi";
- snprintf(self->alsa_name, sizeof(self->alsa_name), "%s", alsa_name);
+ }
+ snprintf (self->alsa_name, sizeof(self->alsa_name), "%s", alsa_name);
- self->port_add = jack_ringbuffer_create(2*MAX_PORTS*sizeof(snd_seq_addr_t));
- self->port_del = jack_ringbuffer_create(2*MAX_PORTS*sizeof(port_t*));
- sem_init(&self->port_sem, 0, 0);
+ self->port_add = jack_ringbuffer_create (2 * MAX_PORTS * sizeof(snd_seq_addr_t));
+ self->port_del = jack_ringbuffer_create (2 * MAX_PORTS * sizeof(port_t*));
+ sem_init (&self->port_sem, 0, 0);
- stream_init(self, PORT_INPUT);
- stream_init(self, PORT_OUTPUT);
+ stream_init (self, PORT_INPUT);
+ stream_init (self, PORT_OUTPUT);
self->ops.destroy = alsa_seqmidi_delete;
self->ops.attach = alsa_seqmidi_attach;
@@ -262,77 +267,79 @@ alsa_midi_t* alsa_seqmidi_new(jack_client_t *client, const char* alsa_name)
}
static
-void alsa_seqmidi_delete(alsa_midi_t *m)
+void alsa_seqmidi_delete (alsa_midi_t *m)
{
- alsa_seqmidi_t *self = (alsa_seqmidi_t*) m;
+ alsa_seqmidi_t *self = (alsa_seqmidi_t*)m;
- debug_log("midi: delete\n");
- alsa_seqmidi_detach(m);
+ debug_log ("midi: delete\n");
+ alsa_seqmidi_detach (m);
- stream_close(self, PORT_OUTPUT);
- stream_close(self, PORT_INPUT);
+ stream_close (self, PORT_OUTPUT);
+ stream_close (self, PORT_INPUT);
- jack_ringbuffer_free(self->port_add);
- jack_ringbuffer_free(self->port_del);
- sem_close(&self->port_sem);
+ jack_ringbuffer_free (self->port_add);
+ jack_ringbuffer_free (self->port_del);
+ sem_close (&self->port_sem);
- free(self);
+ free (self);
}
static
-int alsa_seqmidi_attach(alsa_midi_t *m)
+int alsa_seqmidi_attach (alsa_midi_t *m)
{
- alsa_seqmidi_t *self = (alsa_seqmidi_t*) m;
+ alsa_seqmidi_t *self = (alsa_seqmidi_t*)m;
int err;
- debug_log("midi: attach\n");
+ debug_log ("midi: attach\n");
- if (self->seq)
+ if (self->seq) {
return -EALREADY;
+ }
- if ((err = snd_seq_open(&self->seq, "hw", SND_SEQ_OPEN_DUPLEX, 0)) < 0) {
- error_log("failed to open alsa seq");
+ if ((err = snd_seq_open (&self->seq, "hw", SND_SEQ_OPEN_DUPLEX, 0)) < 0) {
+ error_log ("failed to open alsa seq");
return err;
}
- snd_seq_set_client_name(self->seq, self->alsa_name);
- self->port_id = snd_seq_create_simple_port(self->seq, "port",
- SND_SEQ_PORT_CAP_READ|SND_SEQ_PORT_CAP_WRITE
+ snd_seq_set_client_name (self->seq, self->alsa_name);
+ self->port_id = snd_seq_create_simple_port (self->seq, "port",
+ SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_WRITE
#ifndef JACK_MIDI_DEBUG
- |SND_SEQ_PORT_CAP_NO_EXPORT
+ | SND_SEQ_PORT_CAP_NO_EXPORT
#endif
- ,SND_SEQ_PORT_TYPE_APPLICATION);
- self->client_id = snd_seq_client_id(self->seq);
+ , SND_SEQ_PORT_TYPE_APPLICATION);
+ self->client_id = snd_seq_client_id (self->seq);
- self->queue = snd_seq_alloc_queue(self->seq);
- snd_seq_start_queue(self->seq, self->queue, 0);
+ self->queue = snd_seq_alloc_queue (self->seq);
+ snd_seq_start_queue (self->seq, self->queue, 0);
- stream_attach(self, PORT_INPUT);
- stream_attach(self, PORT_OUTPUT);
+ stream_attach (self, PORT_INPUT);
+ stream_attach (self, PORT_OUTPUT);
- snd_seq_nonblock(self->seq, 1);
+ snd_seq_nonblock (self->seq, 1);
return 0;
}
static
-int alsa_seqmidi_detach(alsa_midi_t *m)
+int alsa_seqmidi_detach (alsa_midi_t *m)
{
- alsa_seqmidi_t *self = (alsa_seqmidi_t*) m;
+ alsa_seqmidi_t *self = (alsa_seqmidi_t*)m;
- debug_log("midi: detach\n");
+ debug_log ("midi: detach\n");
- if (!self->seq)
+ if (!self->seq) {
return -EALREADY;
+ }
- alsa_seqmidi_stop(m);
+ alsa_seqmidi_stop (m);
- jack_ringbuffer_reset(self->port_add);
- free_ports(self, self->port_del);
+ jack_ringbuffer_reset (self->port_add);
+ free_ports (self, self->port_del);
- stream_detach(self, PORT_INPUT);
- stream_detach(self, PORT_OUTPUT);
+ stream_detach (self, PORT_INPUT);
+ stream_detach (self, PORT_OUTPUT);
- snd_seq_close(self->seq);
+ snd_seq_close (self->seq);
self->seq = NULL;
return 0;
@@ -345,30 +352,32 @@ static void update_ports(alsa_seqmidi_t *self);
static void add_ports(stream_t *str);
static
-int alsa_seqmidi_start(alsa_midi_t *m)
+int alsa_seqmidi_start (alsa_midi_t *m)
{
- alsa_seqmidi_t *self = (alsa_seqmidi_t*) m;
+ alsa_seqmidi_t *self = (alsa_seqmidi_t*)m;
int err;
- debug_log("midi: start\n");
+ debug_log ("midi: start\n");
- if (!self->seq)
+ if (!self->seq) {
return -EBADF;
+ }
- if (self->keep_walking)
+ if (self->keep_walking) {
return -EALREADY;
+ }
- snd_seq_connect_from(self->seq, self->port_id, SND_SEQ_CLIENT_SYSTEM, SND_SEQ_PORT_SYSTEM_ANNOUNCE);
- snd_seq_drop_input(self->seq);
+ snd_seq_connect_from (self->seq, self->port_id, SND_SEQ_CLIENT_SYSTEM, SND_SEQ_PORT_SYSTEM_ANNOUNCE);
+ snd_seq_drop_input (self->seq);
- add_existing_ports(self);
- update_ports(self);
- add_ports(&self->stream[PORT_INPUT]);
- add_ports(&self->stream[PORT_OUTPUT]);
+ add_existing_ports (self);
+ update_ports (self);
+ add_ports (&self->stream[PORT_INPUT]);
+ add_ports (&self->stream[PORT_OUTPUT]);
self->keep_walking = 1;
- if ((err = pthread_create(&self->port_thread, NULL, port_thread, self))) {
+ if ((err = pthread_create (&self->port_thread, NULL, port_thread, self))) {
self->keep_walking = 0;
return -errno;
}
@@ -377,47 +386,49 @@ int alsa_seqmidi_start(alsa_midi_t *m)
}
static
-int alsa_seqmidi_stop(alsa_midi_t *m)
+int alsa_seqmidi_stop (alsa_midi_t *m)
{
- alsa_seqmidi_t *self = (alsa_seqmidi_t*) m;
+ alsa_seqmidi_t *self = (alsa_seqmidi_t*)m;
- debug_log("midi: stop\n");
+ debug_log ("midi: stop\n");
- if (!self->keep_walking)
+ if (!self->keep_walking) {
return -EALREADY;
+ }
- snd_seq_disconnect_from(self->seq, self->port_id, SND_SEQ_CLIENT_SYSTEM, SND_SEQ_PORT_SYSTEM_ANNOUNCE);
+ snd_seq_disconnect_from (self->seq, self->port_id, SND_SEQ_CLIENT_SYSTEM, SND_SEQ_PORT_SYSTEM_ANNOUNCE);
self->keep_walking = 0;
- sem_post(&self->port_sem);
- pthread_join(self->port_thread, NULL);
+ sem_post (&self->port_sem);
+ pthread_join (self->port_thread, NULL);
self->port_thread = 0;
return 0;
}
static
-int alsa_connect_from(alsa_seqmidi_t *self, int client, int port)
+int alsa_connect_from (alsa_seqmidi_t *self, int client, int port)
{
snd_seq_port_subscribe_t* sub;
snd_seq_addr_t seq_addr;
int err;
- snd_seq_port_subscribe_alloca(&sub);
+ snd_seq_port_subscribe_alloca (&sub);
seq_addr.client = client;
seq_addr.port = port;
- snd_seq_port_subscribe_set_sender(sub, &seq_addr);
+ snd_seq_port_subscribe_set_sender (sub, &seq_addr);
seq_addr.client = self->client_id;
seq_addr.port = self->port_id;
- snd_seq_port_subscribe_set_dest(sub, &seq_addr);
+ snd_seq_port_subscribe_set_dest (sub, &seq_addr);
- snd_seq_port_subscribe_set_time_update(sub, 1);
- snd_seq_port_subscribe_set_queue(sub, self->queue);
- snd_seq_port_subscribe_set_time_real(sub, 1);
+ snd_seq_port_subscribe_set_time_update (sub, 1);
+ snd_seq_port_subscribe_set_queue (sub, self->queue);
+ snd_seq_port_subscribe_set_time_real (sub, 1);
- if ((err=snd_seq_subscribe_port(self->seq, sub)))
- error_log("can't subscribe to %d:%d - %s\n", client, port, snd_strerror(err));
+ if ((err = snd_seq_subscribe_port (self->seq, sub))) {
+ error_log ("can't subscribe to %d:%d - %s\n", client, port, snd_strerror (err));
+ }
return err;
}
@@ -425,58 +436,65 @@ int alsa_connect_from(alsa_seqmidi_t *self, int client, int port)
* ==================== Port routines =============================
*/
static inline
-int port_hash(snd_seq_addr_t addr)
+int port_hash (snd_seq_addr_t addr)
{
return (addr.client + addr.port) % PORT_HASH_SIZE;
}
static
-port_t* port_get(port_hash_t hash, snd_seq_addr_t addr)
+port_t* port_get (port_hash_t hash, snd_seq_addr_t addr)
{
- port_t **pport = &hash[port_hash(addr)];
+ port_t **pport = &hash[port_hash (addr)];
+
while (*pport) {
port_t *port = *pport;
- if (port->remote.client == addr.client && port->remote.port == addr.port)
+ if (port->remote.client == addr.client && port->remote.port == addr.port) {
return port;
+ }
pport = &port->next;
}
return NULL;
}
static
-void port_insert(port_hash_t hash, port_t *port)
+void port_insert (port_hash_t hash, port_t *port)
{
- port_t **pport = &hash[port_hash(port->remote)];
+ port_t **pport = &hash[port_hash (port->remote)];
+
port->next = *pport;
*pport = port;
}
static
-void port_setdead(port_hash_t hash, snd_seq_addr_t addr)
+void port_setdead (port_hash_t hash, snd_seq_addr_t addr)
{
- port_t *port = port_get(hash, addr);
- if (port)
+ port_t *port = port_get (hash, addr);
+
+ if (port) {
port->is_dead = 1; // see jack_process
- else
- debug_log("port_setdead: not found (%d:%d)\n", addr.client, addr.port);
+ } else {
+ debug_log ("port_setdead: not found (%d:%d)\n", addr.client, addr.port);
+ }
}
static
-void port_free(alsa_seqmidi_t *self, port_t *port)
+void port_free (alsa_seqmidi_t *self, port_t *port)
{
//snd_seq_disconnect_from(self->seq, self->port_id, port->remote.client, port->remote.port);
//snd_seq_disconnect_to(self->seq, self->port_id, port->remote.client, port->remote.port);
- if (port->early_events)
- jack_ringbuffer_free(port->early_events);
- if (port->jack_port)
- jack_port_unregister(self->jack, port->jack_port);
+ if (port->early_events) {
+ jack_ringbuffer_free (port->early_events);
+ }
+ if (port->jack_port) {
+ jack_port_unregister (self->jack, port->jack_port);
+ }
// info_log("port deleted: %s\n", port->name);
- free(port);
+ free (port);
}
static
-port_t* port_create(alsa_seqmidi_t *self, int type, snd_seq_addr_t addr, const snd_seq_port_info_t *info)
+port_t* port_create (alsa_seqmidi_t *self, int type, snd_seq_addr_t addr, const snd_seq_port_info_t *info)
{
snd_seq_client_info_t* client_info;
port_t *port;
@@ -484,62 +502,68 @@ port_t* port_create(alsa_seqmidi_t *self, int type, snd_seq_addr_t addr, const s
int err;
int jack_caps;
- port = calloc(1, sizeof(port_t));
- if (!port)
+ port = calloc (1, sizeof(port_t));
+ if (!port) {
return NULL;
+ }
port->remote = addr;
snd_seq_client_info_alloca (&client_info);
snd_seq_get_any_client_info (self->seq, addr.client, client_info);
- snprintf(port->name, sizeof(port->name), "%s/midi_%s_%d",
- snd_seq_client_info_get_name(client_info), port_type[type].name, addr.port+1);
+ snprintf (port->name, sizeof(port->name), "%s/midi_%s_%d",
+ snd_seq_client_info_get_name (client_info), port_type[type].name, addr.port + 1);
// replace all offending characters by -
for (c = port->name; *c; ++c)
- if (!isalnum(*c) && *c != '/' && *c != '_' && *c != ':' && *c != '(' && *c != ')')
+ if (!isalnum (*c) && *c != '/' && *c != '_' && *c != ':' && *c != '(' && *c != ')') {
*c = '-';
+ }
jack_caps = port_type[type].jack_caps;
/* mark anything that looks like a hardware port as physical&terminal */
- if (snd_seq_port_info_get_type (info) & (SND_SEQ_PORT_TYPE_HARDWARE|SND_SEQ_PORT_TYPE_PORT|SND_SEQ_PORT_TYPE_SPECIFIC)) {
- jack_caps |= (JackPortIsPhysical|JackPortIsTerminal);
+ if (snd_seq_port_info_get_type (info) & (SND_SEQ_PORT_TYPE_HARDWARE | SND_SEQ_PORT_TYPE_PORT | SND_SEQ_PORT_TYPE_SPECIFIC)) {
+ jack_caps |= (JackPortIsPhysical | JackPortIsTerminal);
}
-
- port->jack_port = jack_port_register(self->jack,
- port->name, JACK_DEFAULT_MIDI_TYPE, jack_caps, 0);
- if (!port->jack_port)
+
+ port->jack_port = jack_port_register (self->jack,
+ port->name, JACK_DEFAULT_MIDI_TYPE, jack_caps, 0);
+ if (!port->jack_port) {
goto failed;
+ }
/* generate an alias */
- snprintf(port->name, sizeof(port->name), "%s:midi/%s_%d",
- snd_seq_client_info_get_name (client_info), port_type[type].name, addr.port+1);
+ snprintf (port->name, sizeof(port->name), "%s:midi/%s_%d",
+ snd_seq_client_info_get_name (client_info), port_type[type].name, addr.port + 1);
// replace all offending characters by -
for (c = port->name; *c; ++c)
- if (!isalnum(*c) && *c != '/' && *c != '_' && *c != ':' && *c != '(' && *c != ')')
+ if (!isalnum (*c) && *c != '/' && *c != '_' && *c != ':' && *c != '(' && *c != ')') {
*c = '-';
+ }
jack_port_set_alias (port->jack_port, port->name);
- if (type == PORT_INPUT)
- err = alsa_connect_from(self, port->remote.client, port->remote.port);
- else
- err = snd_seq_connect_to(self->seq, self->port_id, port->remote.client, port->remote.port);
- if (err)
+ if (type == PORT_INPUT) {
+ err = alsa_connect_from (self, port->remote.client, port->remote.port);
+ } else {
+ err = snd_seq_connect_to (self->seq, self->port_id, port->remote.client, port->remote.port);
+ }
+ if (err) {
goto failed;
+ }
- port->early_events = jack_ringbuffer_create(MAX_EVENT_SIZE*16);
+ port->early_events = jack_ringbuffer_create (MAX_EVENT_SIZE * 16);
// info_log("port created: %s\n", port->name);
return port;
- failed:
- port_free(self, port);
+failed:
+ port_free (self, port);
return NULL;
}
@@ -547,65 +571,69 @@ port_t* port_create(alsa_seqmidi_t *self, int type, snd_seq_addr_t addr, const s
* ==================== Port add/del handling thread ==============================
*/
static
-void update_port_type(alsa_seqmidi_t *self, int type, snd_seq_addr_t addr, int caps, const snd_seq_port_info_t *info)
+void update_port_type (alsa_seqmidi_t *self, int type, snd_seq_addr_t addr, int caps, const snd_seq_port_info_t *info)
{
stream_t *str = &self->stream[type];
int alsa_mask = port_type[type].alsa_mask;
- port_t *port = port_get(str->ports, addr);
+ port_t *port = port_get (str->ports, addr);
- debug_log("update_port_type(%d:%d)\n", addr.client, addr.port);
+ debug_log ("update_port_type(%d:%d)\n", addr.client, addr.port);
- if (port && (caps & alsa_mask)!=alsa_mask) {
- debug_log("setdead: %s\n", port->name);
+ if (port && (caps & alsa_mask) != alsa_mask) {
+ debug_log ("setdead: %s\n", port->name);
port->is_dead = 1;
}
- if (!port && (caps & alsa_mask)==alsa_mask) {
- assert (jack_ringbuffer_write_space(str->new_ports) >= sizeof(port));
- port = port_create(self, type, addr, info);
- if (port)
- jack_ringbuffer_write(str->new_ports, (char*)&port, sizeof(port));
+ if (!port && (caps & alsa_mask) == alsa_mask) {
+ assert (jack_ringbuffer_write_space (str->new_ports) >= sizeof(port));
+ port = port_create (self, type, addr, info);
+ if (port) {
+ jack_ringbuffer_write (str->new_ports, (char*)&port, sizeof(port));
+ }
}
}
static
-void update_port(alsa_seqmidi_t *self, snd_seq_addr_t addr, const snd_seq_port_info_t *info)
+void update_port (alsa_seqmidi_t *self, snd_seq_addr_t addr, const snd_seq_port_info_t *info)
{
- unsigned int port_caps = snd_seq_port_info_get_capability(info);
- if (port_caps & SND_SEQ_PORT_CAP_NO_EXPORT)
+ unsigned int port_caps = snd_seq_port_info_get_capability (info);
+
+ if (port_caps & SND_SEQ_PORT_CAP_NO_EXPORT) {
return;
- update_port_type(self, PORT_INPUT, addr, port_caps, info);
- update_port_type(self, PORT_OUTPUT,addr, port_caps, info);
+ }
+ update_port_type (self, PORT_INPUT, addr, port_caps, info);
+ update_port_type (self, PORT_OUTPUT, addr, port_caps, info);
}
static
-void free_ports(alsa_seqmidi_t *self, jack_ringbuffer_t *ports)
+void free_ports (alsa_seqmidi_t *self, jack_ringbuffer_t *ports)
{
port_t *port;
int sz;
- while ((sz = jack_ringbuffer_read(ports, (char*)&port, sizeof(port)))) {
+
+ while ((sz = jack_ringbuffer_read (ports, (char*)&port, sizeof(port)))) {
assert (sz == sizeof(port));
- port_free(self, port);
+ port_free (self, port);
}
}
static
-void update_ports(alsa_seqmidi_t *self)
+void update_ports (alsa_seqmidi_t *self)
{
snd_seq_addr_t addr;
snd_seq_port_info_t *info;
int size;
- snd_seq_port_info_alloca(&info);
+ snd_seq_port_info_alloca (&info);
+
+ while ((size = jack_ringbuffer_read (self->port_add, (char*)&addr, sizeof(addr)))) {
- while ((size = jack_ringbuffer_read(self->port_add, (char*)&addr, sizeof(addr)))) {
-
int err;
assert (size == sizeof(addr));
assert (addr.client != self->client_id);
- if ((err=snd_seq_get_any_port_info(self->seq, addr.client, addr.port, info))>=0) {
- update_port(self, addr, info);
+ if ((err = snd_seq_get_any_port_info (self->seq, addr.client, addr.port, info)) >= 0) {
+ update_port (self, addr, info);
} else {
//port_setdead(self->stream[PORT_INPUT].ports, addr);
//port_setdead(self->stream[PORT_OUTPUT].ports, addr);
@@ -614,40 +642,39 @@ void update_ports(alsa_seqmidi_t *self)
}
static
-void* port_thread(void *arg)
+void* port_thread (void *arg)
{
alsa_seqmidi_t *self = arg;
while (self->keep_walking) {
- sem_wait(&self->port_sem);
- free_ports(self, self->port_del);
- update_ports(self);
+ sem_wait (&self->port_sem);
+ free_ports (self, self->port_del);
+ update_ports (self);
}
- debug_log("port_thread exited\n");
+ debug_log ("port_thread exited\n");
return NULL;
}
static
-void add_existing_ports(alsa_seqmidi_t *self)
+void add_existing_ports (alsa_seqmidi_t *self)
{
snd_seq_addr_t addr;
snd_seq_client_info_t *client_info;
snd_seq_port_info_t *port_info;
- snd_seq_client_info_alloca(&client_info);
- snd_seq_port_info_alloca(&port_info);
- snd_seq_client_info_set_client(client_info, -1);
- while (snd_seq_query_next_client(self->seq, client_info) >= 0)
- {
- addr.client = snd_seq_client_info_get_client(client_info);
- if (addr.client == SND_SEQ_CLIENT_SYSTEM || addr.client == self->client_id)
+ snd_seq_client_info_alloca (&client_info);
+ snd_seq_port_info_alloca (&port_info);
+ snd_seq_client_info_set_client (client_info, -1);
+ while (snd_seq_query_next_client (self->seq, client_info) >= 0) {
+ addr.client = snd_seq_client_info_get_client (client_info);
+ if (addr.client == SND_SEQ_CLIENT_SYSTEM || addr.client == self->client_id) {
continue;
- snd_seq_port_info_set_client(port_info, addr.client);
- snd_seq_port_info_set_port(port_info, -1);
- while (snd_seq_query_next_port(self->seq, port_info) >= 0)
- {
- addr.port = snd_seq_port_info_get_port(port_info);
- update_port(self, addr, port_info);
+ }
+ snd_seq_port_info_set_client (port_info, addr.client);
+ snd_seq_port_info_set_port (port_info, -1);
+ while (snd_seq_query_next_port (self->seq, port_info) >= 0) {
+ addr.port = snd_seq_port_info_get_port (port_info);
+ update_port (self, addr, port_info);
}
}
}
@@ -656,67 +683,69 @@ void add_existing_ports(alsa_seqmidi_t *self)
* =================== Input/output port handling =========================
*/
static
-void set_process_info(struct process_info *info, alsa_seqmidi_t *self, int dir, jack_nframes_t nframes)
+void set_process_info (struct process_info *info, alsa_seqmidi_t *self, int dir, jack_nframes_t nframes)
{
const snd_seq_real_time_t* alsa_time;
snd_seq_queue_status_t *status;
- snd_seq_queue_status_alloca(&status);
+ snd_seq_queue_status_alloca (&status);
info->dir = dir;
- info->period_start = jack_last_frame_time(self->jack);
+ info->period_start = jack_last_frame_time (self->jack);
info->nframes = nframes;
- info->sample_rate = jack_get_sample_rate(self->jack);
+ info->sample_rate = jack_get_sample_rate (self->jack);
- info->cur_frames = jack_frame_time(self->jack);
+ info->cur_frames = jack_frame_time (self->jack);
// immediately get alsa'a real time (uhh, why everybody has their on 'real' time)
- snd_seq_get_queue_status(self->seq, self->queue, status);
- alsa_time = snd_seq_queue_status_get_real_time(status);
+ snd_seq_get_queue_status (self->seq, self->queue, status);
+ alsa_time = snd_seq_queue_status_get_real_time (status);
info->alsa_time = alsa_time->tv_sec * NSEC_PER_SEC + alsa_time->tv_nsec;
if (info->period_start + info->nframes < info->cur_frames) {
- int periods_lost = (info->cur_frames - info->period_start) / info->nframes;
+ int periods_lost = (info->cur_frames - info->period_start) / info->nframes;
info->period_start += periods_lost * info->nframes;
- debug_log("xrun detected: %d periods lost\n", periods_lost);
+ debug_log ("xrun detected: %d periods lost\n", periods_lost);
}
}
static
-void add_ports(stream_t *str)
+void add_ports (stream_t *str)
{
port_t *port;
- while (jack_ringbuffer_read(str->new_ports, (char*)&port, sizeof(port))) {
- debug_log("jack: inserted port %s\n", port->name);
- port_insert(str->ports, port);
+
+ while (jack_ringbuffer_read (str->new_ports, (char*)&port, sizeof(port))) {
+ debug_log ("jack: inserted port %s\n", port->name);
+ port_insert (str->ports, port);
}
}
static
-void jack_process(alsa_seqmidi_t *self, struct process_info *info)
+void jack_process (alsa_seqmidi_t *self, struct process_info *info)
{
stream_t *str = &self->stream[info->dir];
port_jack_func process = port_type[info->dir].jack_func;
- int i, del=0;
+ int i, del = 0;
- add_ports(str);
+ add_ports (str);
// process ports
- for (i=0; i<PORT_HASH_SIZE; ++i) {
+ for (i = 0; i < PORT_HASH_SIZE; ++i) {
port_t **pport = &str->ports[i];
while (*pport) {
port_t *port = *pport;
- port->jack_buf = jack_port_get_buffer(port->jack_port, info->nframes);
- if (info->dir == PORT_INPUT)
- jack_midi_clear_buffer(port->jack_buf);
+ port->jack_buf = jack_port_get_buffer (port->jack_port, info->nframes);
+ if (info->dir == PORT_INPUT) {
+ jack_midi_clear_buffer (port->jack_buf);
+ }
- if (!port->is_dead)
+ if (!port->is_dead) {
(*process)(self, port, info);
- else if (jack_ringbuffer_write_space(self->port_del) >= sizeof(port)) {
- debug_log("jack: removed port %s\n", port->name);
+ } else if (jack_ringbuffer_write_space (self->port_del) >= sizeof(port)) {
+ debug_log ("jack: removed port %s\n", port->name);
*pport = port->next;
- jack_ringbuffer_write(self->port_del, (char*)&port, sizeof(port));
+ jack_ringbuffer_write (self->port_del, (char*)&port, sizeof(port));
del++;
continue;
}
@@ -725,57 +754,62 @@ void jack_process(alsa_seqmidi_t *self, struct process_info *info)
}
}
- if (del)
- sem_post(&self->port_sem);
+ if (del) {
+ sem_post (&self->port_sem);
+ }
}
/*
* ============================ Input ==============================
*/
static
-void do_jack_input(alsa_seqmidi_t *self, port_t *port, struct process_info *info)
+void do_jack_input (alsa_seqmidi_t *self, port_t *port, struct process_info *info)
{
// process port->early_events
alsa_midi_event_t ev;
- while (jack_ringbuffer_read(port->early_events, (char*)&ev, sizeof(ev))) {
+
+ while (jack_ringbuffer_read (port->early_events, (char*)&ev, sizeof(ev))) {
jack_midi_data_t* buf;
jack_nframes_t time = ev.time - info->period_start;
- if (time < 0)
+ if (time < 0) {
time = 0;
- else if (time >= info->nframes)
+ } else if (time >= info->nframes) {
time = info->nframes - 1;
- buf = jack_midi_event_reserve(port->jack_buf, time, ev.size);
- if (buf)
- jack_ringbuffer_read(port->early_events, (char*)buf, ev.size);
- else
- jack_ringbuffer_read_advance(port->early_events, ev.size);
- debug_log("input: it's time for %d bytes at %d\n", ev.size, time);
+ }
+ buf = jack_midi_event_reserve (port->jack_buf, time, ev.size);
+ if (buf) {
+ jack_ringbuffer_read (port->early_events, (char*)buf, ev.size);
+ } else {
+ jack_ringbuffer_read_advance (port->early_events, ev.size);
+ }
+ debug_log ("input: it's time for %d bytes at %d\n", ev.size, time);
}
}
static
-void port_event(alsa_seqmidi_t *self, snd_seq_event_t *ev)
+void port_event (alsa_seqmidi_t *self, snd_seq_event_t *ev)
{
const snd_seq_addr_t addr = ev->data.addr;
- if (addr.client == self->client_id)
+ if (addr.client == self->client_id) {
return;
+ }
if (ev->type == SND_SEQ_EVENT_PORT_START || ev->type == SND_SEQ_EVENT_PORT_CHANGE) {
- assert (jack_ringbuffer_write_space(self->port_add) >= sizeof(addr));
+ assert (jack_ringbuffer_write_space (self->port_add) >= sizeof(addr));
- debug_log("port_event: add/change %d:%d\n", addr.client, addr.port);
- jack_ringbuffer_write(self->port_add, (char*)&addr, sizeof(addr));
- sem_post(&self->port_sem);
+ debug_log ("port_event: add/change %d:%d\n", addr.client, addr.port);
+ jack_ringbuffer_write (self->port_add, (char*)&addr, sizeof(addr));
+ sem_post (&self->port_sem);
} else if (ev->type == SND_SEQ_EVENT_PORT_EXIT) {
- debug_log("port_event: del %d:%d\n", addr.client, addr.port);
- port_setdead(self->stream[PORT_INPUT].ports, addr);
- port_setdead(self->stream[PORT_OUTPUT].ports, addr);
+ debug_log ("port_event: del %d:%d\n", addr.client, addr.port);
+ port_setdead (self->stream[PORT_INPUT].ports, addr);
+ port_setdead (self->stream[PORT_OUTPUT].ports, addr);
}
}
static
-void input_event(alsa_seqmidi_t *self, snd_seq_event_t *alsa_event, struct process_info* info)
+void input_event (alsa_seqmidi_t *self, snd_seq_event_t *alsa_event, struct process_info* info)
{
jack_midi_data_t data[MAX_EVENT_SIZE];
stream_t *str = &self->stream[PORT_INPUT];
@@ -784,17 +818,19 @@ void input_event(alsa_seqmidi_t *self, snd_seq_event_t *alsa_event, struct proce
int64_t frame_offset, event_frame;
port_t *port;
- port = port_get(str->ports, alsa_event->source);
- if (!port)
+ port = port_get (str->ports, alsa_event->source);
+ if (!port) {
return;
+ }
/*
* RPNs, NRPNs, Bank Change, etc. need special handling
* but seems, ALSA does it for us already.
*/
- snd_midi_event_reset_decode(str->codec);
- if ((size = snd_midi_event_decode(str->codec, data, sizeof(data), alsa_event))<0)
+ snd_midi_event_reset_decode (str->codec);
+ if ((size = snd_midi_event_decode (str->codec, data, sizeof(data), alsa_event)) < 0) {
return;
+ }
// fixup NoteOn with vel 0
if ((data[0] & 0xF0) == 0x90 && data[2] == 0x00) {
@@ -807,46 +843,49 @@ void input_event(alsa_seqmidi_t *self, snd_seq_event_t *alsa_event, struct proce
frame_offset = (info->sample_rate * time_offset) / NSEC_PER_SEC;
event_frame = (int64_t)info->cur_frames - info->period_start - frame_offset + info->nframes;
- debug_log("input: %d bytes at event_frame=%d\n", (int)size, (int)event_frame);
+ debug_log ("input: %d bytes at event_frame=%d\n", (int)size, (int)event_frame);
if (event_frame >= info->nframes &&
- jack_ringbuffer_write_space(port->early_events) >= (sizeof(alsa_midi_event_t) + size)) {
+ jack_ringbuffer_write_space (port->early_events) >= (sizeof(alsa_midi_event_t) + size)) {
alsa_midi_event_t ev;
ev.time = event_frame + info->period_start;
ev.size = size;
- jack_ringbuffer_write(port->early_events, (char*)&ev, sizeof(ev));
- jack_ringbuffer_write(port->early_events, (char*)data, size);
- debug_log("postponed to next frame +%d\n", (int) (event_frame - info->nframes));
+ jack_ringbuffer_write (port->early_events, (char*)&ev, sizeof(ev));
+ jack_ringbuffer_write (port->early_events, (char*)data, size);
+ debug_log ("postponed to next frame +%d\n", (int)(event_frame - info->nframes));
return;
}
- if (event_frame < 0)
+ if (event_frame < 0) {
event_frame = 0;
- else if (event_frame >= info->nframes)
+ } else if (event_frame >= info->nframes) {
event_frame = info->nframes - 1;
+ }
- jack_midi_event_write(port->jack_buf, event_frame, data, size);
+ jack_midi_event_write (port->jack_buf, event_frame, data, size);
}
static
-void alsa_seqmidi_read(alsa_midi_t *m, jack_nframes_t nframes)
+void alsa_seqmidi_read (alsa_midi_t *m, jack_nframes_t nframes)
{
- alsa_seqmidi_t *self = (alsa_seqmidi_t*) m;
+ alsa_seqmidi_t *self = (alsa_seqmidi_t*)m;
int res;
snd_seq_event_t *event;
struct process_info info;
- if (!self->keep_walking)
+ if (!self->keep_walking) {
return;
+ }
- set_process_info(&info, self, PORT_INPUT, nframes);
- jack_process(self, &info);
+ set_process_info (&info, self, PORT_INPUT, nframes);
+ jack_process (self, &info);
- while ((res = snd_seq_event_input(self->seq, &event))>0) {
- if (event->source.client == SND_SEQ_CLIENT_SYSTEM)
- port_event(self, event);
- else
- input_event(self, event, &info);
+ while ((res = snd_seq_event_input (self->seq, &event)) > 0) {
+ if (event->source.client == SND_SEQ_CLIENT_SYSTEM) {
+ port_event (self, event);
+ } else {
+ input_event (self, event, &info);
+ }
}
}
@@ -855,12 +894,13 @@ void alsa_seqmidi_read(alsa_midi_t *m, jack_nframes_t nframes)
*/
static
-void do_jack_output(alsa_seqmidi_t *self, port_t *port, struct process_info* info)
+void do_jack_output (alsa_seqmidi_t *self, port_t *port, struct process_info* info)
{
stream_t *str = &self->stream[info->dir];
- int nevents = jack_midi_get_event_count(port->jack_buf);
+ int nevents = jack_midi_get_event_count (port->jack_buf);
int i;
- for (i=0; i<nevents; ++i) {
+
+ for (i = 0; i < nevents; ++i) {
jack_midi_event_t jack_event;
snd_seq_event_t alsa_event;
int64_t frame_offset;
@@ -868,21 +908,22 @@ void do_jack_output(alsa_seqmidi_t *self, port_t *port, struct process_info* inf
snd_seq_real_time_t out_rt;
int err;
- jack_midi_event_get(&jack_event, port->jack_buf, i);
+ jack_midi_event_get (&jack_event, port->jack_buf, i);
- snd_seq_ev_clear(&alsa_event);
- snd_midi_event_reset_encode(str->codec);
- if (!snd_midi_event_encode(str->codec, jack_event.buffer, jack_event.size, &alsa_event))
+ snd_seq_ev_clear (&alsa_event);
+ snd_midi_event_reset_encode (str->codec);
+ if (!snd_midi_event_encode (str->codec, jack_event.buffer, jack_event.size, &alsa_event)) {
continue; // invalid event
- snd_seq_ev_set_source(&alsa_event, self->port_id);
- snd_seq_ev_set_dest(&alsa_event, port->remote.client, port->remote.port);
+ }
+ snd_seq_ev_set_source (&alsa_event, self->port_id);
+ snd_seq_ev_set_dest (&alsa_event, port->remote.client, port->remote.port);
/* NOTE: in case of xrun it could become negative, so it is essential to use signed type! */
frame_offset = (int64_t)jack_event.time + info->period_start + info->nframes - info->cur_frames;
if (frame_offset < 0) {
frame_offset = info->nframes + jack_event.time;
- error_log("internal xrun detected: frame_offset = %"PRId64"\n", frame_offset);
+ error_log ("internal xrun detected: frame_offset = %" PRId64 "\n", frame_offset);
}
/* Ken Ellinwood reported problems with this assert.
* Seems, magic 2 should be replaced with nperiods. */
@@ -894,32 +935,34 @@ void do_jack_output(alsa_seqmidi_t *self, port_t *port, struct process_info* inf
// we should use absolute time to prevent reordering caused by rounding errors
if (out_time < port->last_out_time) {
- debug_log("alsa_out: limiting out_time %lld at %lld\n", out_time, port->last_out_time);
+ debug_log ("alsa_out: limiting out_time %lld at %lld\n", out_time, port->last_out_time);
out_time = port->last_out_time;
- } else
+ } else {
port->last_out_time = out_time;
+ }
out_rt.tv_nsec = out_time % NSEC_PER_SEC;
out_rt.tv_sec = out_time / NSEC_PER_SEC;
- snd_seq_ev_schedule_real(&alsa_event, self->queue, 0, &out_rt);
+ snd_seq_ev_schedule_real (&alsa_event, self->queue, 0, &out_rt);
- err = snd_seq_event_output(self->seq, &alsa_event);
+ err = snd_seq_event_output (self->seq, &alsa_event);
- debug_log("alsa_out: written %d bytes to %s at %d (%lld): %d %s\n",
- jack_event.size, port->name, (int)frame_offset, out_time - info->alsa_time, err, err < 0 ? snd_strerror(err) : "bytes queued");
+ debug_log ("alsa_out: written %d bytes to %s at %d (%lld): %d %s\n",
+ jack_event.size, port->name, (int)frame_offset, out_time - info->alsa_time, err, err < 0 ? snd_strerror (err) : "bytes queued");
}
}
static
-void alsa_seqmidi_write(alsa_midi_t *m, jack_nframes_t nframes)
+void alsa_seqmidi_write (alsa_midi_t *m, jack_nframes_t nframes)
{
- alsa_seqmidi_t *self = (alsa_seqmidi_t*) m;
+ alsa_seqmidi_t *self = (alsa_seqmidi_t*)m;
struct process_info info;
- if (!self->keep_walking)
+ if (!self->keep_walking) {
return;
+ }
- set_process_info(&info, self, PORT_OUTPUT, nframes);
- jack_process(self, &info);
- snd_seq_drain_output(self->seq);
+ set_process_info (&info, self, PORT_OUTPUT, nframes);
+ jack_process (self, &info);
+ snd_seq_drain_output (self->seq);
}
diff --git a/drivers/am/midi_pack.h b/drivers/am/midi_pack.h
index 6fb704b..d75c18e 100644
--- a/drivers/am/midi_pack.h
+++ b/drivers/am/midi_pack.h
@@ -27,20 +27,21 @@ typedef struct {
} midi_pack_t;
static inline
-void midi_pack_reset(midi_pack_t *p)
+void midi_pack_reset (midi_pack_t *p)
{
p->running_status = 0;
}
static
-void midi_pack_event(midi_pack_t *p, jack_midi_event_t *e)
+void midi_pack_event (midi_pack_t *p, jack_midi_event_t *e)
{
if (e->buffer[0] >= 0x80 && e->buffer[0] < 0xF0) { // Voice Message
if (e->buffer[0] == p->running_status) {
e->buffer++;
e->size--;
- } else
+ } else {
p->running_status = e->buffer[0];
+ }
} else if (e->buffer[0] < 0xF8) { // not System Realtime
p->running_status = 0;
}
diff --git a/drivers/am/midi_unpack.h b/drivers/am/midi_unpack.h
index c917f4d..7573a54 100644
--- a/drivers/am/midi_unpack.h
+++ b/drivers/am/midi_unpack.h
@@ -32,7 +32,7 @@ typedef struct {
} midi_unpack_t;
static inline
-void midi_unpack_init(midi_unpack_t *u)
+void midi_unpack_init (midi_unpack_t *u)
{
u->pos = 0;
u->size = sizeof(u->data);
@@ -40,102 +40,93 @@ void midi_unpack_init(midi_unpack_t *u)
}
static inline
-void midi_unpack_reset(midi_unpack_t *u)
+void midi_unpack_reset (midi_unpack_t *u)
{
u->pos = 0;
u->need = u->size;
}
static const unsigned char midi_voice_len[] = {
- 3, /*0x80 Note Off*/
- 3, /*0x90 Note On*/
- 3, /*0xA0 Aftertouch*/
- 3, /*0xB0 Control Change*/
- 2, /*0xC0 Program Change*/
- 2, /*0xD0 Channel Pressure*/
- 3, /*0xE0 Pitch Wheel*/
- 1 /*0xF0 System*/
+ 3, /*0x80 Note Off*/
+ 3, /*0x90 Note On*/
+ 3, /*0xA0 Aftertouch*/
+ 3, /*0xB0 Control Change*/
+ 2, /*0xC0 Program Change*/
+ 2, /*0xD0 Channel Pressure*/
+ 3, /*0xE0 Pitch Wheel*/
+ 1 /*0xF0 System*/
};
static const unsigned char midi_system_len[] = {
- 0, /*0xF0 System Exclusive Start*/
- 2, /*0xF1 MTC Quarter Frame*/
- 3, /*0xF2 Song Postion*/
- 2, /*0xF3 Song Select*/
- 0, /*0xF4 undefined*/
- 0, /*0xF5 undefined*/
- 1, /*0xF6 Tune Request*/
- 1 /*0xF7 System Exlusive End*/
+ 0, /*0xF0 System Exclusive Start*/
+ 2, /*0xF1 MTC Quarter Frame*/
+ 3, /*0xF2 Song Postion*/
+ 2, /*0xF3 Song Select*/
+ 0, /*0xF4 undefined*/
+ 0, /*0xF5 undefined*/
+ 1, /*0xF6 Tune Request*/
+ 1 /*0xF7 System Exlusive End*/
};
static
-int midi_unpack_buf(midi_unpack_t *buf, const unsigned char *data, int len, void *jack_port_buf, jack_nframes_t time)
+int midi_unpack_buf (midi_unpack_t *buf, const unsigned char *data, int len, void *jack_port_buf, jack_nframes_t time)
{
int i;
- for (i=0; i<len; ++i)
- {
+
+ for (i = 0; i < len; ++i) {
const unsigned char byte = data[i];
- if (byte >= 0xF8) // system realtime
- {
- jack_midi_event_write(jack_port_buf, time, &data[i], 1);
+ if (byte >= 0xF8) { // system realtime
+ jack_midi_event_write (jack_port_buf, time, &data[i], 1);
//jack_error("midi_unpack: written system relatime event\n");
//midi_input_write(in, &data[i], 1);
- }
- else if (byte < 0x80) // data
- {
+ } else if (byte < 0x80) { // data
assert (buf->pos < buf->size);
buf->data[buf->pos++] = byte;
- }
- else if (byte < 0xF0) // voice
- {
+ } else if (byte < 0xF0) { // voice
assert (byte >= 0x80 && byte < 0xF0);
//buf->need = ((byte|0x0F) == 0xCF || (byte|0x0F)==0xDF) ? 2 : 3;
- buf->need = midi_voice_len[(byte-0x80)>>4];
+ buf->need = midi_voice_len[(byte - 0x80) >> 4];
buf->data[0] = byte;
buf->pos = 1;
- }
- else if (byte == 0xF7) // sysex end
- {
+ } else if (byte == 0xF7) { // sysex end
assert (buf->pos < buf->size);
buf->data[buf->pos++] = byte;
buf->need = buf->pos;
- }
- else
- {
+ } else {
assert (byte >= 0xF0 && byte < 0xF8);
buf->pos = 1;
buf->data[0] = byte;
buf->need = midi_system_len[byte - 0xF0];
- if (!buf->need)
+ if (!buf->need) {
buf->need = buf->size;
+ }
}
- if (buf->pos == buf->need)
- {
+ if (buf->pos == buf->need) {
// TODO: deal with big sysex'es (they are silently dropped for now)
- if (buf->data[0] >= 0x80 || (buf->data[0]==0xF0 && buf->data[buf->pos-1] == 0xF7)) {
+ if (buf->data[0] >= 0x80 || (buf->data[0] == 0xF0 && buf->data[buf->pos - 1] == 0xF7)) {
/* convert Note On with velocity 0 to Note Off */
if ((buf->data[0] & 0xF0) == 0x90 && buf->data[2] == 0) {
// we use temp array here to keep running status in sync
jack_midi_data_t temp[3] = { 0x80, 0, 0x40 };
temp[0] |= buf->data[0] & 0x0F;
temp[1] = buf->data[1];
- jack_midi_event_write(jack_port_buf, time, temp, 3);
- } else
- jack_midi_event_write(jack_port_buf, time, &buf->data[0], buf->pos);
+ jack_midi_event_write (jack_port_buf, time, temp, 3);
+ } else {
+ jack_midi_event_write (jack_port_buf, time, &buf->data[0], buf->pos);
+ }
//jack_error("midi_unpack: written %d-byte event\n", buf->pos);
//midi_input_write(in, &buf->data[0], buf->pos);
}
/* keep running status */
- if (buf->data[0] >= 0x80 && buf->data[0] < 0xF0)
+ if (buf->data[0] >= 0x80 && buf->data[0] < 0xF0) {
buf->pos = 1;
- else
- {
+ } else {
buf->pos = 0;
buf->need = buf->size;
}
}
}
- assert (i==len);
+ assert (i == len);
return i;
}
diff --git a/drivers/coreaudio/coreaudio_driver.c b/drivers/coreaudio/coreaudio_driver.c
index f343c97..7f16304 100755..100644
--- a/drivers/coreaudio/coreaudio_driver.c
+++ b/drivers/coreaudio/coreaudio_driver.c
@@ -1,52 +1,52 @@
/*
- Copyright � Grame, 2003.
- Copyright � Johnny Petrantoni, 2003.
-
- 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.
-
- Grame Research Laboratory, 9, rue du Garet 69001 Lyon - France
- grame@rd.grame.fr
-
- Johnny Petrantoni, johnny@lato-b.com - Italy, Rome.
-
- Jan 30, 2004: Johnny Petrantoni: first code of the coreaudio driver, based on portaudio driver by Stephane Letz.
- Feb 02, 2004: Johnny Petrantoni: fixed null cycle, removed double copy of buffers in AudioRender, the driver works fine (tested with Built-in Audio and Hammerfall RME), but no cpu load is displayed.
- Feb 03, 2004: Johnny Petrantoni: some little fix.
- Feb 03, 2004: Stephane Letz: some fix in AudioRender.cpp code.
- Feb 03, 2004: Johnny Petrantoni: removed the default device stuff (useless, in jackosx, because JackPilot manages this behavior), the device must be specified. and all parameter must be correct.
- Feb 04, 2004: Johnny Petrantoni: now the driver supports interfaces with multiple interleaved streams (such as the MOTU 828).
- Nov 05, 2004: S.Letz: correct management of -I option for use with JackPilot.
- Nov 15, 2004: S.Letz: Set a default value for deviceID.
- Nov 30, 2004: S.Letz: In coreaudio_driver_write : clear to avoid playing dirty buffers when the client does not produce output anymore.
- Dec 05, 2004: S.Letz: XRun detection
- Dec 09, 2004: S.Letz: Dynamic buffer size change
- Dec 23, 2004: S.Letz: Correct bug in dynamic buffer size change : update period_usecs
- Jan 20, 2005: S.Letz: Almost complete rewrite using AUHAL.
- May 20, 2005: S.Letz: Add "systemic" latencies management.
- Jun 06, 2005: S.Letz: Remove the "-I" parameter, change the semantic of "-n" parameter : -n (driver name) now correctly uses the PropertyDeviceUID
- (persistent accross reboot...) as the identifier for the used coreaudio driver.
- Jun 14, 2005: S.Letz: Since the "-I" parameter is not used anymore, rename the "systemic" latencies management parametes "-I" and "-O" like for the ALSA driver.
- Aug 16, 2005: S.Letz: Remove get_device_id_from_num, use get_default_device instead. If the -n option is not used or the device name cannot
- be found, the default device is used. Note: the default device can be used only if both default input and default output are the same.
- Dec 19, 2005: S.Letz: Add -d option (display_device_names).
- Apri 7, 2006: S.Letz: Synchronization with the jackdmp coreaudio driver version: improve half-duplex management.
- May 17, 2006: S.Letz: Minor fix in driver_initialize.
- May 18, 2006: S.Letz: Document sample rate default value.
- May 31, 2006: S.Letz: Apply Rui patch for more consistent driver parameter naming.
- Dec 04, 2007: S.Letz: Fix a bug in sample rate management (occuring in particular with "aggregate" devices).
- Dec 05, 2007: S.Letz: Correct sample_rate management in Open. Better handling in sample_rate change listener.
+ Copyright � Grame, 2003.
+ Copyright � Johnny Petrantoni, 2003.
+
+ 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.
+
+ Grame Research Laboratory, 9, rue du Garet 69001 Lyon - France
+ grame@rd.grame.fr
+
+ Johnny Petrantoni, johnny@lato-b.com - Italy, Rome.
+
+ Jan 30, 2004: Johnny Petrantoni: first code of the coreaudio driver, based on portaudio driver by Stephane Letz.
+ Feb 02, 2004: Johnny Petrantoni: fixed null cycle, removed double copy of buffers in AudioRender, the driver works fine (tested with Built-in Audio and Hammerfall RME), but no cpu load is displayed.
+ Feb 03, 2004: Johnny Petrantoni: some little fix.
+ Feb 03, 2004: Stephane Letz: some fix in AudioRender.cpp code.
+ Feb 03, 2004: Johnny Petrantoni: removed the default device stuff (useless, in jackosx, because JackPilot manages this behavior), the device must be specified. and all parameter must be correct.
+ Feb 04, 2004: Johnny Petrantoni: now the driver supports interfaces with multiple interleaved streams (such as the MOTU 828).
+ Nov 05, 2004: S.Letz: correct management of -I option for use with JackPilot.
+ Nov 15, 2004: S.Letz: Set a default value for deviceID.
+ Nov 30, 2004: S.Letz: In coreaudio_driver_write : clear to avoid playing dirty buffers when the client does not produce output anymore.
+ Dec 05, 2004: S.Letz: XRun detection
+ Dec 09, 2004: S.Letz: Dynamic buffer size change
+ Dec 23, 2004: S.Letz: Correct bug in dynamic buffer size change : update period_usecs
+ Jan 20, 2005: S.Letz: Almost complete rewrite using AUHAL.
+ May 20, 2005: S.Letz: Add "systemic" latencies management.
+ Jun 06, 2005: S.Letz: Remove the "-I" parameter, change the semantic of "-n" parameter : -n (driver name) now correctly uses the PropertyDeviceUID
+ (persistent accross reboot...) as the identifier for the used coreaudio driver.
+ Jun 14, 2005: S.Letz: Since the "-I" parameter is not used anymore, rename the "systemic" latencies management parametes "-I" and "-O" like for the ALSA driver.
+ Aug 16, 2005: S.Letz: Remove get_device_id_from_num, use get_default_device instead. If the -n option is not used or the device name cannot
+ be found, the default device is used. Note: the default device can be used only if both default input and default output are the same.
+ Dec 19, 2005: S.Letz: Add -d option (display_device_names).
+ Apri 7, 2006: S.Letz: Synchronization with the jackdmp coreaudio driver version: improve half-duplex management.
+ May 17, 2006: S.Letz: Minor fix in driver_initialize.
+ May 18, 2006: S.Letz: Document sample rate default value.
+ May 31, 2006: S.Letz: Apply Rui patch for more consistent driver parameter naming.
+ Dec 04, 2007: S.Letz: Fix a bug in sample rate management (occuring in particular with "aggregate" devices).
+ Dec 05, 2007: S.Letz: Correct sample_rate management in Open. Better handling in sample_rate change listener.
*/
#include <stdio.h>
@@ -59,851 +59,864 @@ const int CAVersion = 3;
//#define PRINTDEBUG 1
-static void JCALog(char *fmt, ...)
+static void JCALog (char *fmt, ...)
{
#ifdef PRINTDEBUG
- va_list ap;
- va_start(ap, fmt);
- fprintf(stderr, "JCA: ");
- vfprintf(stderr, fmt, ap);
- va_end(ap);
+ va_list ap;
+ va_start (ap, fmt);
+ fprintf (stderr, "JCA: ");
+ vfprintf (stderr, fmt, ap);
+ va_end (ap);
#endif
}
-static void printError(OSStatus err)
+static void printError (OSStatus err)
{
#ifdef DEBUG
- switch (err) {
- case kAudioHardwareNoError:
- JCALog("error code : kAudioHardwareNoError\n");
- break;
- case kAudioHardwareNotRunningError:
- JCALog("error code : kAudioHardwareNotRunningError\n");
- break;
- case kAudioHardwareUnspecifiedError:
- JCALog("error code : kAudioHardwareUnspecifiedError\n");
- break;
- case kAudioHardwareUnknownPropertyError:
- JCALog("error code : kAudioHardwareUnknownPropertyError\n");
- break;
- case kAudioHardwareBadPropertySizeError:
- JCALog("error code : kAudioHardwareBadPropertySizeError\n");
- break;
- case kAudioHardwareIllegalOperationError:
- JCALog("error code : kAudioHardwareIllegalOperationError\n");
- break;
- case kAudioHardwareBadDeviceError:
- JCALog("error code : kAudioHardwareBadDeviceError\n");
- break;
- case kAudioHardwareBadStreamError:
- JCALog("error code : kAudioHardwareBadStreamError\n");
- break;
- case kAudioDeviceUnsupportedFormatError:
- JCALog("error code : kAudioDeviceUnsupportedFormatError\n");
- break;
- case kAudioDevicePermissionsError:
- JCALog("error code : kAudioDevicePermissionsError\n");
- break;
- default:
- JCALog("error code : unknown %ld\n", err);
- break;
- }
+ switch (err) {
+ case kAudioHardwareNoError:
+ JCALog ("error code : kAudioHardwareNoError\n");
+ break;
+ case kAudioHardwareNotRunningError:
+ JCALog ("error code : kAudioHardwareNotRunningError\n");
+ break;
+ case kAudioHardwareUnspecifiedError:
+ JCALog ("error code : kAudioHardwareUnspecifiedError\n");
+ break;
+ case kAudioHardwareUnknownPropertyError:
+ JCALog ("error code : kAudioHardwareUnknownPropertyError\n");
+ break;
+ case kAudioHardwareBadPropertySizeError:
+ JCALog ("error code : kAudioHardwareBadPropertySizeError\n");
+ break;
+ case kAudioHardwareIllegalOperationError:
+ JCALog ("error code : kAudioHardwareIllegalOperationError\n");
+ break;
+ case kAudioHardwareBadDeviceError:
+ JCALog ("error code : kAudioHardwareBadDeviceError\n");
+ break;
+ case kAudioHardwareBadStreamError:
+ JCALog ("error code : kAudioHardwareBadStreamError\n");
+ break;
+ case kAudioDeviceUnsupportedFormatError:
+ JCALog ("error code : kAudioDeviceUnsupportedFormatError\n");
+ break;
+ case kAudioDevicePermissionsError:
+ JCALog ("error code : kAudioDevicePermissionsError\n");
+ break;
+ default:
+ JCALog ("error code : unknown %ld\n", err);
+ break;
+ }
#endif
}
-static OSStatus get_device_name_from_id(AudioDeviceID id, char name[256])
+static OSStatus get_device_name_from_id (AudioDeviceID id, char name[256])
{
- UInt32 size = sizeof(char) * 256;
- OSStatus res = AudioDeviceGetProperty(id, 0, false,
- kAudioDevicePropertyDeviceName,
- &size,
- &name[0]);
- return res;
+ UInt32 size = sizeof(char) * 256;
+ OSStatus res = AudioDeviceGetProperty (id, 0, false,
+ kAudioDevicePropertyDeviceName,
+ &size,
+ &name[0]);
+
+ return res;
}
-static OSStatus get_device_id_from_uid(char* UID, AudioDeviceID* id)
+static OSStatus get_device_id_from_uid (char* UID, AudioDeviceID* id)
{
UInt32 size = sizeof(AudioValueTranslation);
- CFStringRef inIUD = CFStringCreateWithCString(NULL, UID, CFStringGetSystemEncoding());
+ CFStringRef inIUD = CFStringCreateWithCString (NULL, UID, CFStringGetSystemEncoding ());
AudioValueTranslation value = { &inIUD, sizeof(CFStringRef), id, sizeof(AudioDeviceID) };
+
if (inIUD == NULL) {
return kAudioHardwareUnspecifiedError;
} else {
- OSStatus res = AudioHardwareGetProperty(kAudioHardwarePropertyDeviceForUID, &size, &value);
- CFRelease(inIUD);
- JCALog("get_device_id_from_uid %s %ld \n", UID, *id);
+ OSStatus res = AudioHardwareGetProperty (kAudioHardwarePropertyDeviceForUID, &size, &value);
+ CFRelease (inIUD);
+ JCALog ("get_device_id_from_uid %s %ld \n", UID, *id);
return (*id == kAudioDeviceUnknown) ? kAudioHardwareBadDeviceError : res;
}
}
-static OSStatus get_default_device(AudioDeviceID * id)
+static OSStatus get_default_device (AudioDeviceID * id)
{
- OSStatus res;
- UInt32 theSize = sizeof(UInt32);
+ OSStatus res;
+ UInt32 theSize = sizeof(UInt32);
AudioDeviceID inDefault;
AudioDeviceID outDefault;
-
- if ((res = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultInputDevice,
- &theSize, &inDefault)) != noErr)
+
+ if ((res = AudioHardwareGetProperty (kAudioHardwarePropertyDefaultInputDevice,
+ &theSize, &inDefault)) != noErr) {
return res;
-
- if ((res = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultOutputDevice,
- &theSize, &outDefault)) != noErr)
+ }
+
+ if ((res = AudioHardwareGetProperty (kAudioHardwarePropertyDefaultOutputDevice,
+ &theSize, &outDefault)) != noErr) {
return res;
-
- JCALog("get_default_device: input %ld output %ld\n", inDefault, outDefault);
-
+ }
+
+ JCALog ("get_default_device: input %ld output %ld\n", inDefault, outDefault);
+
// Get the device only if default input and ouput are the same
if (inDefault == outDefault) {
*id = inDefault;
return noErr;
} else {
- jack_error("Default input and output devices are not the same !!");
+ jack_error ("Default input and output devices are not the same !!");
return kAudioHardwareBadDeviceError;
}
}
-static OSStatus get_default_input_device(AudioDeviceID* id)
+static OSStatus get_default_input_device (AudioDeviceID* id)
{
- OSStatus res;
- UInt32 theSize = sizeof(UInt32);
- AudioDeviceID inDefault;
-
- if ((res = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultInputDevice,
- &theSize, &inDefault)) != noErr)
- return res;
-
- JCALog("get_default_input_device: input = %ld \n", inDefault);
- *id = inDefault;
+ OSStatus res;
+ UInt32 theSize = sizeof(UInt32);
+ AudioDeviceID inDefault;
+
+ if ((res = AudioHardwareGetProperty (kAudioHardwarePropertyDefaultInputDevice,
+ &theSize, &inDefault)) != noErr) {
+ return res;
+ }
+
+ JCALog ("get_default_input_device: input = %ld \n", inDefault);
+ *id = inDefault;
return noErr;
}
-static OSStatus get_default_output_device(AudioDeviceID* id)
+static OSStatus get_default_output_device (AudioDeviceID* id)
{
- OSStatus res;
- UInt32 theSize = sizeof(UInt32);
- AudioDeviceID outDefault;
+ OSStatus res;
+ UInt32 theSize = sizeof(UInt32);
+ AudioDeviceID outDefault;
- if ((res = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultOutputDevice,
- &theSize, &outDefault)) != noErr)
- return res;
+ if ((res = AudioHardwareGetProperty (kAudioHardwarePropertyDefaultOutputDevice,
+ &theSize, &outDefault)) != noErr) {
+ return res;
+ }
- JCALog("get_default_output_device: output = %ld\n", outDefault);
+ JCALog ("get_default_output_device: output = %ld\n", outDefault);
*id = outDefault;
return noErr;
}
-OSStatus get_total_channels(AudioDeviceID device, int* channelCount, bool isInput)
+OSStatus get_total_channels (AudioDeviceID device, int* channelCount, bool isInput)
{
- OSStatus err = noErr;
- UInt32 outSize;
- Boolean outWritable;
- AudioBufferList* bufferList = 0;
- AudioStreamID* streamList = 0;
- int i, numStream;
-
- err = AudioDeviceGetPropertyInfo(device, 0, isInput, kAudioDevicePropertyStreams, &outSize, &outWritable);
+ OSStatus err = noErr;
+ UInt32 outSize;
+ Boolean outWritable;
+ AudioBufferList* bufferList = 0;
+ AudioStreamID* streamList = 0;
+ int i, numStream;
+
+ err = AudioDeviceGetPropertyInfo (device, 0, isInput, kAudioDevicePropertyStreams, &outSize, &outWritable);
if (err == noErr) {
- streamList = (AudioStreamID*)malloc(outSize);
- numStream = outSize/sizeof(AudioStreamID);
- JCALog("get_total_channels device stream number = %ld numStream = %ld\n", device, numStream);
- err = AudioDeviceGetProperty(device, 0, isInput, kAudioDevicePropertyStreams, &outSize, streamList);
+ streamList = (AudioStreamID*)malloc (outSize);
+ numStream = outSize / sizeof(AudioStreamID);
+ JCALog ("get_total_channels device stream number = %ld numStream = %ld\n", device, numStream);
+ err = AudioDeviceGetProperty (device, 0, isInput, kAudioDevicePropertyStreams, &outSize, streamList);
if (err == noErr) {
AudioStreamBasicDescription streamDesc;
outSize = sizeof(AudioStreamBasicDescription);
for (i = 0; i < numStream; i++) {
- err = AudioStreamGetProperty(streamList[i], 0, kAudioDevicePropertyStreamFormat, &outSize, &streamDesc);
- JCALog("get_total_channels streamDesc mFormatFlags = %ld mChannelsPerFrame = %ld\n", streamDesc.mFormatFlags, streamDesc.mChannelsPerFrame);
+ err = AudioStreamGetProperty (streamList[i], 0, kAudioDevicePropertyStreamFormat, &outSize, &streamDesc);
+ JCALog ("get_total_channels streamDesc mFormatFlags = %ld mChannelsPerFrame = %ld\n", streamDesc.mFormatFlags, streamDesc.mChannelsPerFrame);
}
}
}
-
- *channelCount = 0;
- err = AudioDeviceGetPropertyInfo(device, 0, isInput, kAudioDevicePropertyStreamConfiguration, &outSize, &outWritable);
- if (err == noErr) {
- bufferList = (AudioBufferList*)malloc(outSize);
- err = AudioDeviceGetProperty(device, 0, isInput, kAudioDevicePropertyStreamConfiguration, &outSize, bufferList);
- if (err == noErr) {
- for (i = 0; i < bufferList->mNumberBuffers; i++)
- *channelCount += bufferList->mBuffers[i].mNumberChannels;
- }
- }
-
- if (streamList)
- free(streamList);
- if (bufferList)
- free(bufferList);
-
- return err;
+
+ *channelCount = 0;
+ err = AudioDeviceGetPropertyInfo (device, 0, isInput, kAudioDevicePropertyStreamConfiguration, &outSize, &outWritable);
+ if (err == noErr) {
+ bufferList = (AudioBufferList*)malloc (outSize);
+ err = AudioDeviceGetProperty (device, 0, isInput, kAudioDevicePropertyStreamConfiguration, &outSize, bufferList);
+ if (err == noErr) {
+ for (i = 0; i < bufferList->mNumberBuffers; i++)
+ *channelCount += bufferList->mBuffers[i].mNumberChannels;
+ }
+ }
+
+ if (streamList) {
+ free (streamList);
+ }
+ if (bufferList) {
+ free (bufferList);
+ }
+
+ return err;
}
-static OSStatus display_device_names()
+static OSStatus display_device_names ()
{
UInt32 size;
Boolean isWritable;
int i, deviceNum;
OSStatus err;
CFStringRef UIname;
-
- err = AudioHardwareGetPropertyInfo(kAudioHardwarePropertyDevices, &size, &isWritable);
- if (err != noErr)
+
+ err = AudioHardwareGetPropertyInfo (kAudioHardwarePropertyDevices, &size, &isWritable);
+ if (err != noErr) {
return err;
-
- deviceNum = size/sizeof(AudioDeviceID);
+ }
+
+ deviceNum = size / sizeof(AudioDeviceID);
AudioDeviceID devices[deviceNum];
-
- err = AudioHardwareGetProperty(kAudioHardwarePropertyDevices, &size, devices);
- if (err != noErr)
+
+ err = AudioHardwareGetProperty (kAudioHardwarePropertyDevices, &size, devices);
+ if (err != noErr) {
return err;
-
+ }
+
for (i = 0; i < deviceNum; i++) {
- char device_name[256];
+ char device_name[256];
char internal_name[256];
-
+
size = sizeof(CFStringRef);
UIname = NULL;
- err = AudioDeviceGetProperty(devices[i], 0, false, kAudioDevicePropertyDeviceUID, &size, &UIname);
+ err = AudioDeviceGetProperty (devices[i], 0, false, kAudioDevicePropertyDeviceUID, &size, &UIname);
if (err == noErr) {
- CFStringGetCString(UIname, internal_name, 256, CFStringGetSystemEncoding());
+ CFStringGetCString (UIname, internal_name, 256, CFStringGetSystemEncoding ());
} else {
goto error;
}
-
+
size = 256;
- err = AudioDeviceGetProperty(devices[i], 0, false, kAudioDevicePropertyDeviceName, &size, device_name);
- if (err != noErr)
- return err;
- jack_info("ICI");
- jack_info("Device name = \'%s\', internal_name = \'%s\' (to be used as -d parameter)", device_name, internal_name);
+ err = AudioDeviceGetProperty (devices[i], 0, false, kAudioDevicePropertyDeviceName, &size, device_name);
+ if (err != noErr) {
+ return err;
+ }
+ jack_info ("ICI");
+ jack_info ("Device name = \'%s\', internal_name = \'%s\' (to be used as -d parameter)", device_name, internal_name);
}
-
+
return noErr;
error:
- if (UIname != NULL)
- CFRelease(UIname);
+ if (UIname != NULL) {
+ CFRelease (UIname);
+ }
return err;
}
-static OSStatus render(void *inRefCon,
- AudioUnitRenderActionFlags *ioActionFlags,
- const AudioTimeStamp *inTimeStamp,
- UInt32 inBusNumber,
- UInt32 inNumberFrames,
- AudioBufferList *ioData)
+static OSStatus render (void *inRefCon,
+ AudioUnitRenderActionFlags *ioActionFlags,
+ const AudioTimeStamp *inTimeStamp,
+ UInt32 inBusNumber,
+ UInt32 inNumberFrames,
+ AudioBufferList *ioData)
{
int res, i;
JSList *node;
coreaudio_driver_t* ca_driver = (coreaudio_driver_t*)inRefCon;
- AudioUnitRender(ca_driver->au_hal, ioActionFlags, inTimeStamp, 1, inNumberFrames, ca_driver->input_list);
-
+
+ AudioUnitRender (ca_driver->au_hal, ioActionFlags, inTimeStamp, 1, inNumberFrames, ca_driver->input_list);
+
if (ca_driver->xrun_detected > 0) { /* XRun was detected */
- jack_time_t current_time = ca_driver->engine->get_microseconds();
- ca_driver->engine->delay(ca_driver->engine, current_time -
- (ca_driver->last_wait_ust + ca_driver->period_usecs));
+ jack_time_t current_time = ca_driver->engine->get_microseconds ();
+ ca_driver->engine->delay (ca_driver->engine, current_time -
+ (ca_driver->last_wait_ust + ca_driver->period_usecs));
ca_driver->last_wait_ust = current_time;
ca_driver->xrun_detected = 0;
return 0;
- } else {
- ca_driver->last_wait_ust = ca_driver->engine->get_microseconds();
- ca_driver->engine->transport_cycle_start(ca_driver->engine,
- ca_driver->engine->get_microseconds());
- res = ca_driver->engine->run_cycle(ca_driver->engine, inNumberFrames, 0);
+ } else {
+ ca_driver->last_wait_ust = ca_driver->engine->get_microseconds ();
+ ca_driver->engine->transport_cycle_start (ca_driver->engine,
+ ca_driver->engine->get_microseconds ());
+ res = ca_driver->engine->run_cycle (ca_driver->engine, inNumberFrames, 0);
}
-
+
if (ca_driver->null_cycle_occured) {
ca_driver->null_cycle_occured = 0;
- for (i = 0; i < ca_driver->playback_nchannels; i++) {
- memset((float*)ioData->mBuffers[i].mData, 0, sizeof(float) * inNumberFrames);
- }
+ for (i = 0; i < ca_driver->playback_nchannels; i++)
+ memset ((float*)ioData->mBuffers[i].mData, 0, sizeof(float) * inNumberFrames);
} else {
- for (i = 0, node = ca_driver->playback_ports; i < ca_driver->playback_nchannels; i++, node = jack_slist_next(node)) {
- memcpy((float*)ioData->mBuffers[i].mData,
- (jack_default_audio_sample_t*)jack_port_get_buffer(((jack_port_t *) node->data), inNumberFrames),
- sizeof(float) * inNumberFrames);
+ for (i = 0, node = ca_driver->playback_ports; i < ca_driver->playback_nchannels; i++, node = jack_slist_next (node)) {
+ memcpy ((float*)ioData->mBuffers[i].mData,
+ (jack_default_audio_sample_t*)jack_port_get_buffer (((jack_port_t*)node->data), inNumberFrames),
+ sizeof(float) * inNumberFrames);
}
}
-
+
return res;
}
-static OSStatus render_input(void *inRefCon,
- AudioUnitRenderActionFlags *ioActionFlags,
- const AudioTimeStamp *inTimeStamp,
- UInt32 inBusNumber,
- UInt32 inNumberFrames,
- AudioBufferList *ioData)
+static OSStatus render_input (void *inRefCon,
+ AudioUnitRenderActionFlags *ioActionFlags,
+ const AudioTimeStamp *inTimeStamp,
+ UInt32 inBusNumber,
+ UInt32 inNumberFrames,
+ AudioBufferList *ioData)
{
coreaudio_driver_t* ca_driver = (coreaudio_driver_t*)inRefCon;
- AudioUnitRender(ca_driver->au_hal, ioActionFlags, inTimeStamp, 1, inNumberFrames, ca_driver->input_list);
+
+ AudioUnitRender (ca_driver->au_hal, ioActionFlags, inTimeStamp, 1, inNumberFrames, ca_driver->input_list);
if (ca_driver->xrun_detected > 0) { /* XRun was detected */
- jack_time_t current_time = ca_driver->engine->get_microseconds();
- ca_driver->engine->delay(ca_driver->engine, current_time -
- (ca_driver->last_wait_ust + ca_driver->period_usecs));
+ jack_time_t current_time = ca_driver->engine->get_microseconds ();
+ ca_driver->engine->delay (ca_driver->engine, current_time -
+ (ca_driver->last_wait_ust + ca_driver->period_usecs));
ca_driver->last_wait_ust = current_time;
ca_driver->xrun_detected = 0;
return 0;
- } else {
- ca_driver->last_wait_ust = ca_driver->engine->get_microseconds();
- ca_driver->engine->transport_cycle_start(ca_driver->engine,
- ca_driver->engine->get_microseconds());
- return ca_driver->engine->run_cycle(ca_driver->engine, inNumberFrames, 0);
+ } else {
+ ca_driver->last_wait_ust = ca_driver->engine->get_microseconds ();
+ ca_driver->engine->transport_cycle_start (ca_driver->engine,
+ ca_driver->engine->get_microseconds ());
+ return ca_driver->engine->run_cycle (ca_driver->engine, inNumberFrames, 0);
}
}
-static OSStatus sr_notification(AudioDeviceID inDevice,
- UInt32 inChannel,
- Boolean isInput,
- AudioDevicePropertyID inPropertyID,
- void* inClientData)
+static OSStatus sr_notification (AudioDeviceID inDevice,
+ UInt32 inChannel,
+ Boolean isInput,
+ AudioDevicePropertyID inPropertyID,
+ void* inClientData)
{
coreaudio_driver_t* driver = (coreaudio_driver_t*)inClientData;
-
+
switch (inPropertyID) {
- case kAudioDevicePropertyNominalSampleRate: {
- JCALog("JackCoreAudioDriver::SRNotificationCallback kAudioDevicePropertyNominalSampleRate \n");
- driver->state = 1;
- break;
- }
+ case kAudioDevicePropertyNominalSampleRate: {
+ JCALog ("JackCoreAudioDriver::SRNotificationCallback kAudioDevicePropertyNominalSampleRate \n");
+ driver->state = 1;
+ break;
+ }
}
-
+
return noErr;
}
-static OSStatus notification(AudioDeviceID inDevice,
- UInt32 inChannel,
- Boolean isInput,
- AudioDevicePropertyID inPropertyID,
- void* inClientData)
+static OSStatus notification (AudioDeviceID inDevice,
+ UInt32 inChannel,
+ Boolean isInput,
+ AudioDevicePropertyID inPropertyID,
+ void* inClientData)
{
- coreaudio_driver_t* driver = (coreaudio_driver_t*)inClientData;
- switch (inPropertyID) {
-
- case kAudioDeviceProcessorOverload:
- driver->xrun_detected = 1;
- break;
-
- case kAudioDevicePropertyNominalSampleRate: {
- UInt32 outSize = sizeof(Float64);
- Float64 sampleRate;
- AudioStreamBasicDescription srcFormat, dstFormat;
- OSStatus err = AudioDeviceGetProperty(driver->device_id, 0, kAudioDeviceSectionGlobal, kAudioDevicePropertyNominalSampleRate, &outSize, &sampleRate);
- if (err != noErr) {
- jack_error("Cannot get current sample rate");
- return kAudioHardwareUnsupportedOperationError;
- }
- JCALog("JackCoreAudioDriver::NotificationCallback kAudioDevicePropertyNominalSampleRate %ld\n", (long)sampleRate);
- outSize = sizeof(AudioStreamBasicDescription);
-
- // Update SR for input
- err = AudioUnitGetProperty(driver->au_hal, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &srcFormat, &outSize);
- if (err != noErr) {
- jack_error("Error calling AudioUnitSetProperty - kAudioUnitProperty_StreamFormat kAudioUnitScope_Input");
- }
- srcFormat.mSampleRate = sampleRate;
- err = AudioUnitSetProperty(driver->au_hal, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &srcFormat, outSize);
- if (err != noErr) {
- jack_error("Error calling AudioUnitSetProperty - kAudioUnitProperty_StreamFormat kAudioUnitScope_Input");
- }
-
- // Update SR for output
- err = AudioUnitGetProperty(driver->au_hal, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &dstFormat, &outSize);
- if (err != noErr) {
- jack_error("Error calling AudioUnitSetProperty - kAudioUnitProperty_StreamFormat kAudioUnitScope_Output");
- }
- dstFormat.mSampleRate = sampleRate;
- err = AudioUnitSetProperty(driver->au_hal, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &dstFormat, outSize);
- if (err != noErr) {
- jack_error("Error calling AudioUnitSetProperty - kAudioUnitProperty_StreamFormat kAudioUnitScope_Output");
- }
- break;
+ coreaudio_driver_t* driver = (coreaudio_driver_t*)inClientData;
+
+ switch (inPropertyID) {
+
+ case kAudioDeviceProcessorOverload:
+ driver->xrun_detected = 1;
+ break;
+
+ case kAudioDevicePropertyNominalSampleRate: {
+ UInt32 outSize = sizeof(Float64);
+ Float64 sampleRate;
+ AudioStreamBasicDescription srcFormat, dstFormat;
+ OSStatus err = AudioDeviceGetProperty (driver->device_id, 0, kAudioDeviceSectionGlobal, kAudioDevicePropertyNominalSampleRate, &outSize, &sampleRate);
+ if (err != noErr) {
+ jack_error ("Cannot get current sample rate");
+ return kAudioHardwareUnsupportedOperationError;
+ }
+ JCALog ("JackCoreAudioDriver::NotificationCallback kAudioDevicePropertyNominalSampleRate %ld\n", (long)sampleRate);
+ outSize = sizeof(AudioStreamBasicDescription);
+
+ // Update SR for input
+ err = AudioUnitGetProperty (driver->au_hal, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &srcFormat, &outSize);
+ if (err != noErr) {
+ jack_error ("Error calling AudioUnitSetProperty - kAudioUnitProperty_StreamFormat kAudioUnitScope_Input");
+ }
+ srcFormat.mSampleRate = sampleRate;
+ err = AudioUnitSetProperty (driver->au_hal, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &srcFormat, outSize);
+ if (err != noErr) {
+ jack_error ("Error calling AudioUnitSetProperty - kAudioUnitProperty_StreamFormat kAudioUnitScope_Input");
}
- }
- return noErr;
+
+ // Update SR for output
+ err = AudioUnitGetProperty (driver->au_hal, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &dstFormat, &outSize);
+ if (err != noErr) {
+ jack_error ("Error calling AudioUnitSetProperty - kAudioUnitProperty_StreamFormat kAudioUnitScope_Output");
+ }
+ dstFormat.mSampleRate = sampleRate;
+ err = AudioUnitSetProperty (driver->au_hal, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &dstFormat, outSize);
+ if (err != noErr) {
+ jack_error ("Error calling AudioUnitSetProperty - kAudioUnitProperty_StreamFormat kAudioUnitScope_Output");
+ }
+ break;
+ }
+ }
+ return noErr;
}
static int
-coreaudio_driver_attach(coreaudio_driver_t * driver, jack_engine_t * engine)
+coreaudio_driver_attach (coreaudio_driver_t * driver, jack_engine_t * engine)
{
- jack_port_t *port;
+ jack_port_t *port;
JSList *node;
- int port_flags;
- channel_t chn;
- char buf[JACK_PORT_NAME_SIZE];
+ int port_flags;
+ channel_t chn;
+ char buf[JACK_PORT_NAME_SIZE];
char channel_name[64];
OSStatus err;
UInt32 size;
- UInt32 value1,value2;
- Boolean isWritable;
- jack_latency_range_t range;
-
- driver->engine = engine;
-
- if (driver->engine->set_buffer_size(engine, driver->frames_per_cycle)) {
- jack_error ("coreaudio: cannot set engine buffer size to %d (check MIDI)", driver->frames_per_cycle);
- return -1;
- }
- driver->engine->set_sample_rate(engine, driver->frame_rate);
-
- port_flags = JackPortIsOutput | JackPortIsPhysical | JackPortIsTerminal;
-
- /*
- if (driver->has_hw_monitoring) {
- port_flags |= JackPortCanMonitor;
- }
- */
-
- for (chn = 0; chn < driver->capture_nchannels; chn++) {
- err = AudioDeviceGetPropertyInfo(driver->device_id, chn + 1, true, kAudioDevicePropertyChannelName, &size, &isWritable);
- if (err == noErr && size > 0) {
- err = AudioDeviceGetProperty(driver->device_id, chn + 1, true, kAudioDevicePropertyChannelName, &size, channel_name);
- if (err != noErr)
- JCALog("AudioDeviceGetProperty kAudioDevicePropertyChannelName error \n");
- snprintf(buf, sizeof(buf) - 1, "%s:out_%s%lu", driver->capture_driver_name, channel_name, chn + 1);
+ UInt32 value1, value2;
+ Boolean isWritable;
+ jack_latency_range_t range;
+
+ driver->engine = engine;
+
+ if (driver->engine->set_buffer_size (engine, driver->frames_per_cycle)) {
+ jack_error ("coreaudio: cannot set engine buffer size to %d (check MIDI)", driver->frames_per_cycle);
+ return -1;
+ }
+ driver->engine->set_sample_rate (engine, driver->frame_rate);
+
+ port_flags = JackPortIsOutput | JackPortIsPhysical | JackPortIsTerminal;
+
+ /*
+ if (driver->has_hw_monitoring) {
+ port_flags |= JackPortCanMonitor;
+ }
+ */
+
+ for (chn = 0; chn < driver->capture_nchannels; chn++) {
+ err = AudioDeviceGetPropertyInfo (driver->device_id, chn + 1, true, kAudioDevicePropertyChannelName, &size, &isWritable);
+ if (err == noErr && size > 0) {
+ err = AudioDeviceGetProperty (driver->device_id, chn + 1, true, kAudioDevicePropertyChannelName, &size, channel_name);
+ if (err != noErr) {
+ JCALog ("AudioDeviceGetProperty kAudioDevicePropertyChannelName error \n");
+ }
+ snprintf (buf, sizeof(buf) - 1, "%s:out_%s%lu", driver->capture_driver_name, channel_name, chn + 1);
} else {
- snprintf(buf, sizeof(buf) - 1, "%s:out%lu", driver->capture_driver_name, chn + 1);
+ snprintf (buf, sizeof(buf) - 1, "%s:out%lu", driver->capture_driver_name, chn + 1);
}
-
- if ((port = jack_port_register(driver->client, buf,
- JACK_DEFAULT_AUDIO_TYPE, port_flags,
- 0)) == NULL) {
- jack_error("coreaudio: cannot register port for %s", buf);
+
+ if ((port = jack_port_register (driver->client, buf,
+ JACK_DEFAULT_AUDIO_TYPE, port_flags,
+ 0)) == NULL) {
+ jack_error ("coreaudio: cannot register port for %s", buf);
break;
}
size = sizeof(UInt32);
value1 = value2 = 0;
- err = AudioDeviceGetProperty(driver->device_id, 0, true, kAudioDevicePropertyLatency, &size, &value1);
- if (err != noErr)
- JCALog("AudioDeviceGetProperty kAudioDevicePropertyLatency error \n");
- err = AudioDeviceGetProperty(driver->device_id, 0, true, kAudioDevicePropertySafetyOffset, &size, &value2);
- if (err != noErr)
- JCALog("AudioDeviceGetProperty kAudioDevicePropertySafetyOffset error \n");
-
+ err = AudioDeviceGetProperty (driver->device_id, 0, true, kAudioDevicePropertyLatency, &size, &value1);
+ if (err != noErr) {
+ JCALog ("AudioDeviceGetProperty kAudioDevicePropertyLatency error \n");
+ }
+ err = AudioDeviceGetProperty (driver->device_id, 0, true, kAudioDevicePropertySafetyOffset, &size, &value2);
+ if (err != noErr) {
+ JCALog ("AudioDeviceGetProperty kAudioDevicePropertySafetyOffset error \n");
+ }
+
range.min = range.max = driver->frames_per_cycle + value1 + value2 + driver->capture_frame_latency;
- jack_port_set_latency_range(port, JackCaptureLatency, &range);
+ jack_port_set_latency_range (port, JackCaptureLatency, &range);
driver->capture_ports =
- jack_slist_append(driver->capture_ports, port);
- }
+ jack_slist_append (driver->capture_ports, port);
+ }
- port_flags = JackPortIsInput | JackPortIsPhysical | JackPortIsTerminal;
+ port_flags = JackPortIsInput | JackPortIsPhysical | JackPortIsTerminal;
for (chn = 0; chn < driver->playback_nchannels; chn++) {
- err = AudioDeviceGetPropertyInfo(driver->device_id, chn + 1, false, kAudioDevicePropertyChannelName, &size, &isWritable);
- if (err == noErr && size > 0) {
- err = AudioDeviceGetProperty(driver->device_id, chn + 1, false, kAudioDevicePropertyChannelName, &size, channel_name);
- if (err != noErr)
- JCALog("AudioDeviceGetProperty kAudioDevicePropertyChannelName error \n");
- snprintf(buf, sizeof(buf) - 1, "%s:in_%s%lu", driver->playback_driver_name, channel_name, chn + 1);
+ err = AudioDeviceGetPropertyInfo (driver->device_id, chn + 1, false, kAudioDevicePropertyChannelName, &size, &isWritable);
+ if (err == noErr && size > 0) {
+ err = AudioDeviceGetProperty (driver->device_id, chn + 1, false, kAudioDevicePropertyChannelName, &size, channel_name);
+ if (err != noErr) {
+ JCALog ("AudioDeviceGetProperty kAudioDevicePropertyChannelName error \n");
+ }
+ snprintf (buf, sizeof(buf) - 1, "%s:in_%s%lu", driver->playback_driver_name, channel_name, chn + 1);
} else {
- snprintf(buf, sizeof(buf) - 1, "%s:in%lu", driver->playback_driver_name, chn + 1);
+ snprintf (buf, sizeof(buf) - 1, "%s:in%lu", driver->playback_driver_name, chn + 1);
}
- if ((port = jack_port_register(driver->client, buf,
- JACK_DEFAULT_AUDIO_TYPE, port_flags,
- 0)) == NULL) {
- jack_error("coreaudio: cannot register port for %s", buf);
+ if ((port = jack_port_register (driver->client, buf,
+ JACK_DEFAULT_AUDIO_TYPE, port_flags,
+ 0)) == NULL) {
+ jack_error ("coreaudio: cannot register port for %s", buf);
break;
}
size = sizeof(UInt32);
value1 = value2 = 0;
- err = AudioDeviceGetProperty(driver->device_id, 0, false, kAudioDevicePropertyLatency, &size, &value1);
- if (err != noErr)
- JCALog("AudioDeviceGetProperty kAudioDevicePropertyLatency error \n");
- err = AudioDeviceGetProperty(driver->device_id, 0, false, kAudioDevicePropertySafetyOffset, &size, &value2);
- if (err != noErr)
- JCALog("AudioDeviceGetProperty kAudioDevicePropertySafetyOffset error \n");
-
+ err = AudioDeviceGetProperty (driver->device_id, 0, false, kAudioDevicePropertyLatency, &size, &value1);
+ if (err != noErr) {
+ JCALog ("AudioDeviceGetProperty kAudioDevicePropertyLatency error \n");
+ }
+ err = AudioDeviceGetProperty (driver->device_id, 0, false, kAudioDevicePropertySafetyOffset, &size, &value2);
+ if (err != noErr) {
+ JCALog ("AudioDeviceGetProperty kAudioDevicePropertySafetyOffset error \n");
+ }
+
range.min = range.max = driver->frames_per_cycle + value1 + value2 + driver->playback_frame_latency;
- jack_port_set_latency_range(port, JackCaptureLatency, &range);
+ jack_port_set_latency_range (port, JackCaptureLatency, &range);
driver->playback_ports =
- jack_slist_append(driver->playback_ports, port);
+ jack_slist_append (driver->playback_ports, port);
}
-
+
// Input buffers do no change : prepare them only once
- for (chn = 0, node = driver->capture_ports; chn < driver->capture_nchannels; chn++, node = jack_slist_next(node)) {
- driver->input_list->mBuffers[chn].mData
- = (jack_default_audio_sample_t*)jack_port_get_buffer(((jack_port_t *) node->data), driver->frames_per_cycle);
- }
+ for (chn = 0, node = driver->capture_ports; chn < driver->capture_nchannels; chn++, node = jack_slist_next (node))
+ driver->input_list->mBuffers[chn].mData
+ = (jack_default_audio_sample_t*)jack_port_get_buffer (((jack_port_t*)node->data), driver->frames_per_cycle);
- jack_activate(driver->client);
- return 0;
+ jack_activate (driver->client);
+ return 0;
}
static int
-coreaudio_driver_detach(coreaudio_driver_t * driver, jack_engine_t * engine)
+coreaudio_driver_detach (coreaudio_driver_t * driver, jack_engine_t * engine)
{
- JSList *node;
+ JSList *node;
- if (driver->engine == 0) {
+ if (driver->engine == 0) {
return -1;
- }
+ }
- for (node = driver->capture_ports; node; node = jack_slist_next(node)) {
- jack_port_unregister(driver->client, ((jack_port_t *) node->data));
- }
+ for (node = driver->capture_ports; node; node = jack_slist_next (node))
+ jack_port_unregister (driver->client, ((jack_port_t*)node->data));
- jack_slist_free(driver->capture_ports);
- driver->capture_ports = 0;
+ jack_slist_free (driver->capture_ports);
+ driver->capture_ports = 0;
- for (node = driver->playback_ports; node; node = jack_slist_next(node)) {
- jack_port_unregister(driver->client, ((jack_port_t *) node->data));
- }
+ for (node = driver->playback_ports; node; node = jack_slist_next (node))
+ jack_port_unregister (driver->client, ((jack_port_t*)node->data));
- jack_slist_free(driver->playback_ports);
- driver->playback_ports = 0;
+ jack_slist_free (driver->playback_ports);
+ driver->playback_ports = 0;
- driver->engine = 0;
- return 0;
+ driver->engine = 0;
+ return 0;
}
static int
-coreaudio_driver_null_cycle(coreaudio_driver_t * driver, jack_nframes_t nframes)
+coreaudio_driver_null_cycle (coreaudio_driver_t * driver, jack_nframes_t nframes)
{
driver->null_cycle_occured = 1;
- return 0;
+ return 0;
}
static int
-coreaudio_driver_read(coreaudio_driver_t * driver, jack_nframes_t nframes)
+coreaudio_driver_read (coreaudio_driver_t * driver, jack_nframes_t nframes)
{
- return 0;
+ return 0;
}
static int
-coreaudio_driver_write(coreaudio_driver_t * driver, jack_nframes_t nframes)
+coreaudio_driver_write (coreaudio_driver_t * driver, jack_nframes_t nframes)
{
return 0;
}
-static int coreaudio_driver_audio_start(coreaudio_driver_t * driver)
+static int coreaudio_driver_audio_start (coreaudio_driver_t * driver)
{
- return (AudioOutputUnitStart(driver->au_hal) == noErr) ? 0 : -1;
+ return (AudioOutputUnitStart (driver->au_hal) == noErr) ? 0 : -1;
}
-static int coreaudio_driver_audio_stop(coreaudio_driver_t * driver)
+static int coreaudio_driver_audio_stop (coreaudio_driver_t * driver)
{
- return (AudioOutputUnitStop(driver->au_hal) == noErr) ? 0 : -1;
+ return (AudioOutputUnitStop (driver->au_hal) == noErr) ? 0 : -1;
}
static int
-coreaudio_driver_bufsize(coreaudio_driver_t * driver,
- jack_nframes_t nframes)
+coreaudio_driver_bufsize (coreaudio_driver_t * driver,
+ jack_nframes_t nframes)
{
- /* This gets called from the engine server thread, so it must
- * be serialized with the driver thread. Stopping the audio
- * also stops that thread. */
+ /* This gets called from the engine server thread, so it must
+ * be serialized with the driver thread. Stopping the audio
+ * also stops that thread. */
/*
- TO DO
- */
+ TO DO
+ */
return 0;
}
/** create a new driver instance
-*/
-static jack_driver_t *coreaudio_driver_new(char* name,
- jack_client_t* client,
- jack_nframes_t nframes,
- jack_nframes_t samplerate,
- int capturing,
- int playing,
- int inchannels,
- int outchannels,
- char* capture_driver_uid,
- char* playback_driver_uid,
- jack_nframes_t capture_latency,
- jack_nframes_t playback_latency)
+ */
+static jack_driver_t *coreaudio_driver_new (char* name,
+ jack_client_t* client,
+ jack_nframes_t nframes,
+ jack_nframes_t samplerate,
+ int capturing,
+ int playing,
+ int inchannels,
+ int outchannels,
+ char* capture_driver_uid,
+ char* playback_driver_uid,
+ jack_nframes_t capture_latency,
+ jack_nframes_t playback_latency)
{
- coreaudio_driver_t *driver;
+ coreaudio_driver_t *driver;
OSStatus err = noErr;
ComponentResult err1;
- UInt32 outSize;
+ UInt32 outSize;
UInt32 enableIO;
AudioStreamBasicDescription srcFormat, dstFormat;
Float64 sampleRate;
int in_nChannels = 0;
int out_nChannels = 0;
int i;
-
- driver = (coreaudio_driver_t *) calloc(1, sizeof(coreaudio_driver_t));
- jack_driver_init((jack_driver_t *) driver);
- if (!jack_power_of_two(nframes)) {
- jack_error("CA: -p must be a power of two.");
+ driver = (coreaudio_driver_t*)calloc (1, sizeof(coreaudio_driver_t));
+ jack_driver_init ((jack_driver_t*)driver);
+
+ if (!jack_power_of_two (nframes)) {
+ jack_error ("CA: -p must be a power of two.");
goto error;
- }
+ }
driver->state = 0;
- driver->frames_per_cycle = nframes;
- driver->frame_rate = samplerate;
- driver->capturing = capturing;
- driver->playing = playing;
+ driver->frames_per_cycle = nframes;
+ driver->frame_rate = samplerate;
+ driver->capturing = capturing;
+ driver->playing = playing;
driver->xrun_detected = 0;
driver->null_cycle = 0;
- driver->attach = (JackDriverAttachFunction) coreaudio_driver_attach;
- driver->detach = (JackDriverDetachFunction) coreaudio_driver_detach;
- driver->read = (JackDriverReadFunction) coreaudio_driver_read;
- driver->write = (JackDriverReadFunction) coreaudio_driver_write;
- driver->null_cycle =
- (JackDriverNullCycleFunction) coreaudio_driver_null_cycle;
- driver->bufsize = (JackDriverBufSizeFunction) coreaudio_driver_bufsize;
- driver->start = (JackDriverStartFunction) coreaudio_driver_audio_start;
- driver->stop = (JackDriverStopFunction) coreaudio_driver_audio_stop;
+ driver->attach = (JackDriverAttachFunction)coreaudio_driver_attach;
+ driver->detach = (JackDriverDetachFunction)coreaudio_driver_detach;
+ driver->read = (JackDriverReadFunction)coreaudio_driver_read;
+ driver->write = (JackDriverReadFunction)coreaudio_driver_write;
+ driver->null_cycle =
+ (JackDriverNullCycleFunction)coreaudio_driver_null_cycle;
+ driver->bufsize = (JackDriverBufSizeFunction)coreaudio_driver_bufsize;
+ driver->start = (JackDriverStartFunction)coreaudio_driver_audio_start;
+ driver->stop = (JackDriverStopFunction)coreaudio_driver_audio_stop;
driver->capture_frame_latency = capture_latency;
driver->playback_frame_latency = playback_latency;
-
+
// Duplex
- if (strcmp(capture_driver_uid, "") != 0 && strcmp(playback_driver_uid, "") != 0) {
- JCALog("Open duplex \n");
- if (get_device_id_from_uid(playback_driver_uid, &driver->device_id) != noErr) {
- if (get_default_device(&driver->device_id) != noErr) {
- jack_error("Cannot open default device");
+ if (strcmp (capture_driver_uid, "") != 0 && strcmp (playback_driver_uid, "") != 0) {
+ JCALog ("Open duplex \n");
+ if (get_device_id_from_uid (playback_driver_uid, &driver->device_id) != noErr) {
+ if (get_default_device (&driver->device_id) != noErr) {
+ jack_error ("Cannot open default device");
goto error;
}
}
- if (get_device_name_from_id(driver->device_id, driver->capture_driver_name) != noErr || get_device_name_from_id(driver->device_id, driver->playback_driver_name) != noErr) {
- jack_error("Cannot get device name from device ID");
+ if (get_device_name_from_id (driver->device_id, driver->capture_driver_name) != noErr || get_device_name_from_id (driver->device_id, driver->playback_driver_name) != noErr) {
+ jack_error ("Cannot get device name from device ID");
goto error;
}
-
- // Capture only
- } else if (strcmp(capture_driver_uid, "") != 0) {
- JCALog("Open capture only \n");
- if (get_device_id_from_uid(capture_driver_uid, &driver->device_id) != noErr) {
- if (get_default_input_device(&driver->device_id) != noErr) {
- jack_error("Cannot open default device");
- goto error;
+
+ // Capture only
+ } else if (strcmp (capture_driver_uid, "") != 0) {
+ JCALog ("Open capture only \n");
+ if (get_device_id_from_uid (capture_driver_uid, &driver->device_id) != noErr) {
+ if (get_default_input_device (&driver->device_id) != noErr) {
+ jack_error ("Cannot open default device");
+ goto error;
}
}
- if (get_device_name_from_id(driver->device_id, driver->capture_driver_name) != noErr) {
- jack_error("Cannot get device name from device ID");
+ if (get_device_name_from_id (driver->device_id, driver->capture_driver_name) != noErr) {
+ jack_error ("Cannot get device name from device ID");
goto error;
}
-
- // Playback only
+
+ // Playback only
} else if (playback_driver_uid != NULL) {
- JCALog("Open playback only \n");
- if (get_device_id_from_uid(playback_driver_uid, &driver->device_id) != noErr) {
- if (get_default_output_device(&driver->device_id) != noErr) {
- jack_error("Cannot open default device");
- goto error;
+ JCALog ("Open playback only \n");
+ if (get_device_id_from_uid (playback_driver_uid, &driver->device_id) != noErr) {
+ if (get_default_output_device (&driver->device_id) != noErr) {
+ jack_error ("Cannot open default device");
+ goto error;
}
- }
- if (get_device_name_from_id(driver->device_id, driver->playback_driver_name) != noErr) {
- jack_error("Cannot get device name from device ID");
+ }
+ if (get_device_name_from_id (driver->device_id, driver->playback_driver_name) != noErr) {
+ jack_error ("Cannot get device name from device ID");
goto error;
}
-
- // Use default driver in duplex mode
+
+ // Use default driver in duplex mode
} else {
- JCALog("Open default driver \n");
- if (get_default_device(&driver->device_id) != noErr) {
- jack_error("Cannot open default device");
+ JCALog ("Open default driver \n");
+ if (get_default_device (&driver->device_id) != noErr) {
+ jack_error ("Cannot open default device");
goto error;
}
- if (get_device_name_from_id(driver->device_id, driver->capture_driver_name) != noErr || get_device_name_from_id(driver->device_id, driver->playback_driver_name) != noErr) {
- jack_error("Cannot get device name from device ID");
+ if (get_device_name_from_id (driver->device_id, driver->capture_driver_name) != noErr || get_device_name_from_id (driver->device_id, driver->playback_driver_name) != noErr) {
+ jack_error ("Cannot get device name from device ID");
goto error;
}
}
-
+
driver->client = client;
- driver->period_usecs =
- (((float) driver->frames_per_cycle) / driver->frame_rate) *
+ driver->period_usecs =
+ (((float)driver->frames_per_cycle) / driver->frame_rate) *
1000000.0f;
-
+
if (capturing) {
- err = get_total_channels(driver->device_id, &in_nChannels, true);
- if (err != noErr) {
- jack_error("Cannot get input channel number");
- printError(err);
+ err = get_total_channels (driver->device_id, &in_nChannels, true);
+ if (err != noErr) {
+ jack_error ("Cannot get input channel number");
+ printError (err);
goto error;
- }
+ }
}
-
+
if (playing) {
- err = get_total_channels(driver->device_id, &out_nChannels, false);
- if (err != noErr) {
- jack_error("Cannot get output channel number");
- printError(err);
+ err = get_total_channels (driver->device_id, &out_nChannels, false);
+ if (err != noErr) {
+ jack_error ("Cannot get output channel number");
+ printError (err);
goto error;
- }
+ }
}
-
+
if (inchannels > in_nChannels) {
- jack_error("This device hasn't required input channels inchannels = %ld in_nChannels = %ld", inchannels, in_nChannels);
+ jack_error ("This device hasn't required input channels inchannels = %ld in_nChannels = %ld", inchannels, in_nChannels);
goto error;
- }
-
+ }
+
if (outchannels > out_nChannels) {
- jack_error("This device hasn't required output channels outchannels = %ld out_nChannels = %ld", outchannels, out_nChannels);
+ jack_error ("This device hasn't required output channels outchannels = %ld out_nChannels = %ld", outchannels, out_nChannels);
goto error;
- }
+ }
if (inchannels == 0) {
- JCALog("Setup max in channels = %ld\n", in_nChannels);
- inchannels = in_nChannels;
+ JCALog ("Setup max in channels = %ld\n", in_nChannels);
+ inchannels = in_nChannels;
}
-
+
if (outchannels == 0) {
- JCALog("Setup max out channels = %ld\n", out_nChannels);
- outchannels = out_nChannels;
+ JCALog ("Setup max out channels = %ld\n", out_nChannels);
+ outchannels = out_nChannels;
}
- // Setting buffer size
- outSize = sizeof(UInt32);
- err = AudioDeviceSetProperty(driver->device_id, NULL, 0, false, kAudioDevicePropertyBufferFrameSize, outSize, &nframes);
- if (err != noErr) {
- jack_error("Cannot set buffer size %ld", nframes);
- printError(err);
+ // Setting buffer size
+ outSize = sizeof(UInt32);
+ err = AudioDeviceSetProperty (driver->device_id, NULL, 0, false, kAudioDevicePropertyBufferFrameSize, outSize, &nframes);
+ if (err != noErr) {
+ jack_error ("Cannot set buffer size %ld", nframes);
+ printError (err);
goto error;
- }
+ }
// Set sample rate
outSize = sizeof(Float64);
- err = AudioDeviceGetProperty(driver->device_id, 0, kAudioDeviceSectionGlobal, kAudioDevicePropertyNominalSampleRate, &outSize, &sampleRate);
+ err = AudioDeviceGetProperty (driver->device_id, 0, kAudioDeviceSectionGlobal, kAudioDevicePropertyNominalSampleRate, &outSize, &sampleRate);
if (err != noErr) {
- jack_error("Cannot get current sample rate");
- printError(err);
+ jack_error ("Cannot get current sample rate");
+ printError (err);
goto error;
}
if (samplerate != (jack_nframes_t)sampleRate) {
sampleRate = (Float64)samplerate;
-
+
// To get SR change notification
- err = AudioDeviceAddPropertyListener(driver->device_id, 0, true, kAudioDevicePropertyNominalSampleRate, sr_notification, driver);
+ err = AudioDeviceAddPropertyListener (driver->device_id, 0, true, kAudioDevicePropertyNominalSampleRate, sr_notification, driver);
if (err != noErr) {
- jack_error("Error calling AudioDeviceAddPropertyListener with kAudioDevicePropertyNominalSampleRate");
- printError(err);
+ jack_error ("Error calling AudioDeviceAddPropertyListener with kAudioDevicePropertyNominalSampleRate");
+ printError (err);
return -1;
}
- err = AudioDeviceSetProperty(driver->device_id, NULL, 0, kAudioDeviceSectionGlobal, kAudioDevicePropertyNominalSampleRate, outSize, &sampleRate);
+ err = AudioDeviceSetProperty (driver->device_id, NULL, 0, kAudioDeviceSectionGlobal, kAudioDevicePropertyNominalSampleRate, outSize, &sampleRate);
if (err != noErr) {
- jack_error("Cannot set sample rate = %ld", samplerate);
- printError(err);
+ jack_error ("Cannot set sample rate = %ld", samplerate);
+ printError (err);
return -1;
}
-
+
// Waiting for SR change notification
int count = 0;
while (!driver->state && count++ < 100) {
- usleep(100000);
- JCALog("Wait count = %ld\n", count);
+ usleep (100000);
+ JCALog ("Wait count = %ld\n", count);
}
-
+
// Remove SR change notification
- AudioDeviceRemovePropertyListener(driver->device_id, 0, true, kAudioDevicePropertyNominalSampleRate, sr_notification);
+ AudioDeviceRemovePropertyListener (driver->device_id, 0, true, kAudioDevicePropertyNominalSampleRate, sr_notification);
}
- // AUHAL
- ComponentDescription cd = {kAudioUnitType_Output, kAudioUnitSubType_HALOutput, kAudioUnitManufacturer_Apple, 0, 0};
- Component HALOutput = FindNextComponent(NULL, &cd);
+ // AUHAL
+ ComponentDescription cd = { kAudioUnitType_Output, kAudioUnitSubType_HALOutput, kAudioUnitManufacturer_Apple, 0, 0 };
+ Component HALOutput = FindNextComponent (NULL, &cd);
- err1 = OpenAComponent(HALOutput, &driver->au_hal);
- if (err1 != noErr) {
- jack_error("Error calling OpenAComponent");
- printError(err1);
- goto error;
+ err1 = OpenAComponent (HALOutput, &driver->au_hal);
+ if (err1 != noErr) {
+ jack_error ("Error calling OpenAComponent");
+ printError (err1);
+ goto error;
}
- err1 = AudioUnitInitialize(driver->au_hal);
- if (err1 != noErr) {
- jack_error("Cannot initialize AUHAL unit");
- printError(err1);
- goto error;
+ err1 = AudioUnitInitialize (driver->au_hal);
+ if (err1 != noErr) {
+ jack_error ("Cannot initialize AUHAL unit");
+ printError (err1);
+ goto error;
}
- // Start I/O
+ // Start I/O
enableIO = 1;
if (capturing && inchannels > 0) {
- JCALog("Setup AUHAL input\n");
- err1 = AudioUnitSetProperty(driver->au_hal, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, 1, &enableIO, sizeof(enableIO));
- if (err1 != noErr) {
- jack_error("Error calling AudioUnitSetProperty - kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input");
- printError(err1);
- goto error;
- }
- }
-
+ JCALog ("Setup AUHAL input\n");
+ err1 = AudioUnitSetProperty (driver->au_hal, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, 1, &enableIO, sizeof(enableIO));
+ if (err1 != noErr) {
+ jack_error ("Error calling AudioUnitSetProperty - kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input");
+ printError (err1);
+ goto error;
+ }
+ }
+
if (playing && outchannels > 0) {
- JCALog("Setup AUHAL output\n");
- err1 = AudioUnitSetProperty(driver->au_hal, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Output, 0, &enableIO, sizeof(enableIO));
+ JCALog ("Setup AUHAL output\n");
+ err1 = AudioUnitSetProperty (driver->au_hal, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Output, 0, &enableIO, sizeof(enableIO));
if (err1 != noErr) {
- jack_error("Error calling AudioUnitSetProperty - kAudioOutputUnitProperty_EnableIO,kAudioUnitScope_Output");
- printError(err1);
+ jack_error ("Error calling AudioUnitSetProperty - kAudioOutputUnitProperty_EnableIO,kAudioUnitScope_Output");
+ printError (err1);
goto error;
}
}
-
+
// Setup up choosen device, in both input and output cases
- err1 = AudioUnitSetProperty(driver->au_hal, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, 0, &driver->device_id, sizeof(AudioDeviceID));
+ err1 = AudioUnitSetProperty (driver->au_hal, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, 0, &driver->device_id, sizeof(AudioDeviceID));
if (err1 != noErr) {
- jack_error("Error calling AudioUnitSetProperty - kAudioOutputUnitProperty_CurrentDevice");
- printError(err1);
+ jack_error ("Error calling AudioUnitSetProperty - kAudioOutputUnitProperty_CurrentDevice");
+ printError (err1);
goto error;
}
// Set buffer size
if (capturing && inchannels > 0) {
- err1 = AudioUnitSetProperty(driver->au_hal, kAudioUnitProperty_MaximumFramesPerSlice, kAudioUnitScope_Global, 1, (UInt32*)&nframes, sizeof(UInt32));
+ err1 = AudioUnitSetProperty (driver->au_hal, kAudioUnitProperty_MaximumFramesPerSlice, kAudioUnitScope_Global, 1, (UInt32*)&nframes, sizeof(UInt32));
if (err1 != noErr) {
- jack_error("Error calling AudioUnitSetProperty - kAudioUnitProperty_MaximumFramesPerSlice");
- printError(err1);
+ jack_error ("Error calling AudioUnitSetProperty - kAudioUnitProperty_MaximumFramesPerSlice");
+ printError (err1);
goto error;
}
}
-
+
if (playing && outchannels > 0) {
- err1 = AudioUnitSetProperty(driver->au_hal, kAudioUnitProperty_MaximumFramesPerSlice, kAudioUnitScope_Global, 0, (UInt32*)&nframes, sizeof(UInt32));
+ err1 = AudioUnitSetProperty (driver->au_hal, kAudioUnitProperty_MaximumFramesPerSlice, kAudioUnitScope_Global, 0, (UInt32*)&nframes, sizeof(UInt32));
if (err1 != noErr) {
- jack_error("Error calling AudioUnitSetProperty - kAudioUnitProperty_MaximumFramesPerSlice");
- printError(err1);
+ jack_error ("Error calling AudioUnitSetProperty - kAudioUnitProperty_MaximumFramesPerSlice");
+ printError (err1);
goto error;
}
}
// Setup channel map
if (capturing && inchannels > 0 && inchannels < in_nChannels) {
- SInt32 chanArr[in_nChannels];
- for (i = 0; i < in_nChannels; i++) {
- chanArr[i] = -1;
- }
- for (i = 0; i < inchannels; i++) {
- chanArr[i] = i;
- }
- AudioUnitSetProperty(driver->au_hal, kAudioOutputUnitProperty_ChannelMap , kAudioUnitScope_Input, 1, chanArr, sizeof(SInt32) * in_nChannels);
- if (err1 != noErr) {
- jack_error("Error calling AudioUnitSetProperty - kAudioOutputUnitProperty_ChannelMap 1");
- printError(err1);
- }
- }
-
- if (playing && outchannels > 0 && outchannels < out_nChannels) {
- SInt32 chanArr[out_nChannels];
- for (i = 0; i < out_nChannels; i++) {
- chanArr[i] = -1;
- }
- for (i = 0; i < outchannels; i++) {
- chanArr[i] = i;
- }
- err1 = AudioUnitSetProperty(driver->au_hal, kAudioOutputUnitProperty_ChannelMap, kAudioUnitScope_Output, 0, chanArr, sizeof(SInt32) * out_nChannels);
- if (err1 != noErr) {
- jack_error("Error calling AudioUnitSetProperty - kAudioOutputUnitProperty_ChannelMap 0");
- printError(err1);
- }
- }
+ SInt32 chanArr[in_nChannels];
+ for (i = 0; i < in_nChannels; i++)
+ chanArr[i] = -1;
+ for (i = 0; i < inchannels; i++)
+ chanArr[i] = i;
+ AudioUnitSetProperty (driver->au_hal, kAudioOutputUnitProperty_ChannelMap, kAudioUnitScope_Input, 1, chanArr, sizeof(SInt32) * in_nChannels);
+ if (err1 != noErr) {
+ jack_error ("Error calling AudioUnitSetProperty - kAudioOutputUnitProperty_ChannelMap 1");
+ printError (err1);
+ }
+ }
+
+ if (playing && outchannels > 0 && outchannels < out_nChannels) {
+ SInt32 chanArr[out_nChannels];
+ for (i = 0; i < out_nChannels; i++)
+ chanArr[i] = -1;
+ for (i = 0; i < outchannels; i++)
+ chanArr[i] = i;
+ err1 = AudioUnitSetProperty (driver->au_hal, kAudioOutputUnitProperty_ChannelMap, kAudioUnitScope_Output, 0, chanArr, sizeof(SInt32) * out_nChannels);
+ if (err1 != noErr) {
+ jack_error ("Error calling AudioUnitSetProperty - kAudioOutputUnitProperty_ChannelMap 0");
+ printError (err1);
+ }
+ }
// Setup stream converters
- srcFormat.mSampleRate = samplerate;
+ srcFormat.mSampleRate = samplerate;
srcFormat.mFormatID = kAudioFormatLinearPCM;
srcFormat.mFormatFlags = kAudioFormatFlagsNativeFloatPacked | kLinearPCMFormatFlagIsNonInterleaved;
srcFormat.mBytesPerPacket = sizeof(float);
@@ -912,10 +925,10 @@ static jack_driver_t *coreaudio_driver_new(char* name,
srcFormat.mChannelsPerFrame = outchannels;
srcFormat.mBitsPerChannel = 32;
- err1 = AudioUnitSetProperty(driver->au_hal, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &srcFormat, sizeof(AudioStreamBasicDescription));
+ err1 = AudioUnitSetProperty (driver->au_hal, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &srcFormat, sizeof(AudioStreamBasicDescription));
if (err1 != noErr) {
- jack_error("Error calling AudioUnitSetProperty - kAudioUnitProperty_StreamFormat kAudioUnitScope_Input");
- printError(err1);
+ jack_error ("Error calling AudioUnitSetProperty - kAudioUnitProperty_StreamFormat kAudioUnitScope_Input");
+ printError (err1);
}
dstFormat.mSampleRate = samplerate;
@@ -927,41 +940,42 @@ static jack_driver_t *coreaudio_driver_new(char* name,
dstFormat.mChannelsPerFrame = inchannels;
dstFormat.mBitsPerChannel = 32;
- err1 = AudioUnitSetProperty(driver->au_hal, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &dstFormat, sizeof(AudioStreamBasicDescription));
+ err1 = AudioUnitSetProperty (driver->au_hal, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &dstFormat, sizeof(AudioStreamBasicDescription));
if (err1 != noErr) {
- jack_error("Error calling AudioUnitSetProperty - kAudioUnitProperty_StreamFormat kAudioUnitScope_Output");
- printError(err1);
+ jack_error ("Error calling AudioUnitSetProperty - kAudioUnitProperty_StreamFormat kAudioUnitScope_Output");
+ printError (err1);
}
// Setup callbacks
- if (inchannels > 0 && outchannels == 0) {
- AURenderCallbackStruct output;
- output.inputProc = render_input;
- output.inputProcRefCon = driver;
- err1 = AudioUnitSetProperty(driver->au_hal, kAudioOutputUnitProperty_SetInputCallback, kAudioUnitScope_Global, 0, &output, sizeof(output));
- if (err1 != noErr) {
- jack_error("Error calling AudioUnitSetProperty - kAudioUnitProperty_SetRenderCallback 1");
- printError(err1);
- goto error;
- }
- } else {
- AURenderCallbackStruct output;
- output.inputProc = render;
- output.inputProcRefCon = driver;
- err1 = AudioUnitSetProperty(driver->au_hal, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &output, sizeof(output));
- if (err1 != noErr) {
- jack_error("Error calling AudioUnitSetProperty - kAudioUnitProperty_SetRenderCallback 0");
- printError(err1);
- goto error;
- }
- }
+ if (inchannels > 0 && outchannels == 0) {
+ AURenderCallbackStruct output;
+ output.inputProc = render_input;
+ output.inputProcRefCon = driver;
+ err1 = AudioUnitSetProperty (driver->au_hal, kAudioOutputUnitProperty_SetInputCallback, kAudioUnitScope_Global, 0, &output, sizeof(output));
+ if (err1 != noErr) {
+ jack_error ("Error calling AudioUnitSetProperty - kAudioUnitProperty_SetRenderCallback 1");
+ printError (err1);
+ goto error;
+ }
+ } else {
+ AURenderCallbackStruct output;
+ output.inputProc = render;
+ output.inputProcRefCon = driver;
+ err1 = AudioUnitSetProperty (driver->au_hal, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &output, sizeof(output));
+ if (err1 != noErr) {
+ jack_error ("Error calling AudioUnitSetProperty - kAudioUnitProperty_SetRenderCallback 0");
+ printError (err1);
+ goto error;
+ }
+ }
if (capturing && inchannels > 0) {
- driver->input_list = (AudioBufferList*)malloc(sizeof(UInt32) + inchannels * sizeof(AudioBuffer));
- if (driver->input_list == 0)
+ driver->input_list = (AudioBufferList*)malloc (sizeof(UInt32) + inchannels * sizeof(AudioBuffer));
+ if (driver->input_list == 0) {
goto error;
+ }
driver->input_list->mNumberBuffers = inchannels;
-
+
// Prepare buffers
for (i = 0; i < driver->capture_nchannels; i++) {
driver->input_list->mBuffers[i].mNumberChannels = 1;
@@ -969,39 +983,39 @@ static jack_driver_t *coreaudio_driver_new(char* name,
}
}
- err = AudioDeviceAddPropertyListener(driver->device_id, 0, true, kAudioDeviceProcessorOverload, notification, driver);
- if (err != noErr) {
- jack_error("Error calling AudioDeviceAddPropertyListener with kAudioDeviceProcessorOverload");
- goto error;
+ err = AudioDeviceAddPropertyListener (driver->device_id, 0, true, kAudioDeviceProcessorOverload, notification, driver);
+ if (err != noErr) {
+ jack_error ("Error calling AudioDeviceAddPropertyListener with kAudioDeviceProcessorOverload");
+ goto error;
+ }
+
+ err = AudioDeviceAddPropertyListener (driver->device_id, 0, true, kAudioDevicePropertyNominalSampleRate, notification, driver);
+ if (err != noErr) {
+ jack_error ("Error calling AudioDeviceAddPropertyListener with kAudioDevicePropertyNominalSampleRate");
+ goto error;
}
-
- err = AudioDeviceAddPropertyListener(driver->device_id, 0, true, kAudioDevicePropertyNominalSampleRate, notification, driver);
- if (err != noErr) {
- jack_error("Error calling AudioDeviceAddPropertyListener with kAudioDevicePropertyNominalSampleRate");
- goto error;
- }
-
+
driver->playback_nchannels = outchannels;
- driver->capture_nchannels = inchannels;
- return ((jack_driver_t *) driver);
-
- error:
- AudioUnitUninitialize(driver->au_hal);
- CloseComponent(driver->au_hal);
- jack_error("Cannot open the coreaudio driver");
- free(driver);
- return NULL;
+ driver->capture_nchannels = inchannels;
+ return (jack_driver_t*)driver;
+
+error:
+ AudioUnitUninitialize (driver->au_hal);
+ CloseComponent (driver->au_hal);
+ jack_error ("Cannot open the coreaudio driver");
+ free (driver);
+ return NULL;
}
/** free all memory allocated by a driver instance
-*/
-static void coreaudio_driver_delete(coreaudio_driver_t * driver)
+ */
+static void coreaudio_driver_delete (coreaudio_driver_t * driver)
{
- AudioDeviceRemovePropertyListener(driver->device_id, 0, true, kAudioDeviceProcessorOverload, notification);
- free(driver->input_list);
- AudioUnitUninitialize(driver->au_hal);
- CloseComponent(driver->au_hal);
- free(driver);
+ AudioDeviceRemovePropertyListener (driver->device_id, 0, true, kAudioDeviceProcessorOverload, notification);
+ free (driver->input_list);
+ AudioUnitUninitialize (driver->au_hal);
+ CloseComponent (driver->au_hal);
+ free (driver);
}
//== driver "plugin" interface =================================================
@@ -1010,140 +1024,141 @@ static void coreaudio_driver_delete(coreaudio_driver_t * driver)
const char driver_client_name[] = "coreaudio";
-jack_driver_desc_t *driver_get_descriptor()
+jack_driver_desc_t *driver_get_descriptor ()
{
- jack_driver_desc_t *desc;
- unsigned int i;
- desc = calloc(1, sizeof(jack_driver_desc_t));
-
- strcpy(desc->name, "coreaudio");
- desc->nparams = 12;
- desc->params = calloc(desc->nparams, sizeof(jack_driver_param_desc_t));
-
- i = 0;
- strcpy(desc->params[i].name, "channels");
- desc->params[i].character = 'c';
- desc->params[i].type = JackDriverParamInt;
- desc->params[i].value.ui = 2;
- strcpy(desc->params[i].short_desc, "Maximum number of channels");
- strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
-
- i++;
- strcpy(desc->params[i].name, "inchannels");
- desc->params[i].character = 'i';
- desc->params[i].type = JackDriverParamInt;
- desc->params[i].value.ui = 2;
- strcpy(desc->params[i].short_desc, "Maximum number of input channels");
- strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
-
- i++;
- strcpy(desc->params[i].name, "outchannels");
- desc->params[i].character = 'o';
- desc->params[i].type = JackDriverParamInt;
- desc->params[i].value.ui = 2;
- strcpy(desc->params[i].short_desc, "Maximum number of output channels");
- strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
-
- i++;
- strcpy(desc->params[i].name, "capture");
+ jack_driver_desc_t *desc;
+ unsigned int i;
+
+ desc = calloc (1, sizeof(jack_driver_desc_t));
+
+ strcpy (desc->name, "coreaudio");
+ desc->nparams = 12;
+ desc->params = calloc (desc->nparams, sizeof(jack_driver_param_desc_t));
+
+ i = 0;
+ strcpy (desc->params[i].name, "channels");
+ desc->params[i].character = 'c';
+ desc->params[i].type = JackDriverParamInt;
+ desc->params[i].value.ui = 2;
+ strcpy (desc->params[i].short_desc, "Maximum number of channels");
+ strcpy (desc->params[i].long_desc, desc->params[i].short_desc);
+
+ i++;
+ strcpy (desc->params[i].name, "inchannels");
+ desc->params[i].character = 'i';
+ desc->params[i].type = JackDriverParamInt;
+ desc->params[i].value.ui = 2;
+ strcpy (desc->params[i].short_desc, "Maximum number of input channels");
+ strcpy (desc->params[i].long_desc, desc->params[i].short_desc);
+
+ i++;
+ strcpy (desc->params[i].name, "outchannels");
+ desc->params[i].character = 'o';
+ desc->params[i].type = JackDriverParamInt;
+ desc->params[i].value.ui = 2;
+ strcpy (desc->params[i].short_desc, "Maximum number of output channels");
+ strcpy (desc->params[i].long_desc, desc->params[i].short_desc);
+
+ i++;
+ strcpy (desc->params[i].name, "capture");
desc->params[i].character = 'C';
desc->params[i].type = JackDriverParamString;
- strcpy(desc->params[i].value.str, "will take default CoreAudio input device");
- strcpy(desc->params[i].short_desc, "Provide capture ports. Optionally set CoreAudio device name");
- strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
+ strcpy (desc->params[i].value.str, "will take default CoreAudio input device");
+ strcpy (desc->params[i].short_desc, "Provide capture ports. Optionally set CoreAudio device name");
+ strcpy (desc->params[i].long_desc, desc->params[i].short_desc);
i++;
- strcpy(desc->params[i].name, "playback");
+ strcpy (desc->params[i].name, "playback");
desc->params[i].character = 'P';
desc->params[i].type = JackDriverParamString;
- strcpy(desc->params[i].value.str, "will take default CoreAudio output device");
- strcpy(desc->params[i].short_desc, "Provide playback ports. Optionally set CoreAudio device name");
- strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
-
- i++;
- strcpy(desc->params[i].name, "duplex");
- desc->params[i].character = 'D';
- desc->params[i].type = JackDriverParamBool;
- desc->params[i].value.i = TRUE;
- strcpy(desc->params[i].short_desc, "Capture and playback");
- strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
-
- i++;
- strcpy(desc->params[i].name, "rate");
- desc->params[i].character = 'r';
- desc->params[i].type = JackDriverParamUInt;
- desc->params[i].value.ui = 44100U;
- strcpy(desc->params[i].short_desc, "Sample rate");
- strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
-
- i++;
- strcpy(desc->params[i].name, "period");
- desc->params[i].character = 'p';
- desc->params[i].type = JackDriverParamUInt;
- desc->params[i].value.ui = 128U;
- strcpy(desc->params[i].short_desc, "Frames per period");
- strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
-
- i++;
- strcpy(desc->params[i].name, "device");
+ strcpy (desc->params[i].value.str, "will take default CoreAudio output device");
+ strcpy (desc->params[i].short_desc, "Provide playback ports. Optionally set CoreAudio device name");
+ strcpy (desc->params[i].long_desc, desc->params[i].short_desc);
+
+ i++;
+ strcpy (desc->params[i].name, "duplex");
+ desc->params[i].character = 'D';
+ desc->params[i].type = JackDriverParamBool;
+ desc->params[i].value.i = TRUE;
+ strcpy (desc->params[i].short_desc, "Capture and playback");
+ strcpy (desc->params[i].long_desc, desc->params[i].short_desc);
+
+ i++;
+ strcpy (desc->params[i].name, "rate");
+ desc->params[i].character = 'r';
+ desc->params[i].type = JackDriverParamUInt;
+ desc->params[i].value.ui = 44100U;
+ strcpy (desc->params[i].short_desc, "Sample rate");
+ strcpy (desc->params[i].long_desc, desc->params[i].short_desc);
+
+ i++;
+ strcpy (desc->params[i].name, "period");
+ desc->params[i].character = 'p';
+ desc->params[i].type = JackDriverParamUInt;
+ desc->params[i].value.ui = 128U;
+ strcpy (desc->params[i].short_desc, "Frames per period");
+ strcpy (desc->params[i].long_desc, desc->params[i].short_desc);
+
+ i++;
+ strcpy (desc->params[i].name, "device");
desc->params[i].character = 'd';
desc->params[i].type = JackDriverParamString;
desc->params[i].value.ui = 128U;
- strcpy(desc->params[i].value.str, "will take default CoreAudio device name");
- strcpy(desc->params[i].short_desc, "CoreAudio device name");
- strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
+ strcpy (desc->params[i].value.str, "will take default CoreAudio device name");
+ strcpy (desc->params[i].short_desc, "CoreAudio device name");
+ strcpy (desc->params[i].long_desc, desc->params[i].short_desc);
- i++;
- strcpy(desc->params[i].name, "input-latency");
+ i++;
+ strcpy (desc->params[i].name, "input-latency");
desc->params[i].character = 'I';
desc->params[i].type = JackDriverParamUInt;
desc->params[i].value.i = 0;
- strcpy(desc->params[i].short_desc, "Extra input latency");
- strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
+ strcpy (desc->params[i].short_desc, "Extra input latency");
+ strcpy (desc->params[i].long_desc, desc->params[i].short_desc);
i++;
- strcpy(desc->params[i].name, "output-latency");
+ strcpy (desc->params[i].name, "output-latency");
desc->params[i].character = 'O';
desc->params[i].type = JackDriverParamUInt;
desc->params[i].value.i = 0;
- strcpy(desc->params[i].short_desc, "Extra output latency");
- strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
-
+ strcpy (desc->params[i].short_desc, "Extra output latency");
+ strcpy (desc->params[i].long_desc, desc->params[i].short_desc);
+
i++;
- strcpy(desc->params[i].name, "list-devices");
+ strcpy (desc->params[i].name, "list-devices");
desc->params[i].character = 'l';
desc->params[i].type = JackDriverParamBool;
desc->params[i].value.i = FALSE;
- strcpy(desc->params[i].short_desc, "Display available CoreAudio devices");
- strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
-
- return desc;
+ strcpy (desc->params[i].short_desc, "Display available CoreAudio devices");
+ strcpy (desc->params[i].long_desc, desc->params[i].short_desc);
+
+ return desc;
}
-jack_driver_t *driver_initialize(jack_client_t * client,
- const JSList * params)
+jack_driver_t *driver_initialize (jack_client_t * client,
+ const JSList * params)
{
- jack_nframes_t srate = 44100; /* Some older Mac models only support this value */
- jack_nframes_t frames_per_interrupt = 128;
- int capture = FALSE;
- int playback = FALSE;
- int chan_in = 0;
- int chan_out = 0;
- char* capture_pcm_name = "";
+ jack_nframes_t srate = 44100; /* Some older Mac models only support this value */
+ jack_nframes_t frames_per_interrupt = 128;
+ int capture = FALSE;
+ int playback = FALSE;
+ int chan_in = 0;
+ int chan_out = 0;
+ char* capture_pcm_name = "";
char* playback_pcm_name = "";
- const JSList *node;
- const jack_driver_param_t *param;
+ 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;
+ for (node = params; node; node = jack_slist_next (node)) {
+ param = (const jack_driver_param_t*)node->data;
- switch (param->character) {
+ switch (param->character) {
case 'd':
- capture_pcm_name = strdup(param->value.str);
- playback_pcm_name = strdup(param->value.str);
+ capture_pcm_name = strdup (param->value.str);
+ playback_pcm_name = strdup (param->value.str);
break;
case 'D':
@@ -1152,28 +1167,28 @@ jack_driver_t *driver_initialize(jack_client_t * client,
break;
case 'c':
- chan_in = chan_out = (int) param->value.ui;
+ chan_in = chan_out = (int)param->value.ui;
break;
case 'i':
- chan_in = (int) param->value.ui;
+ chan_in = (int)param->value.ui;
break;
case 'o':
- chan_out = (int) param->value.ui;
+ chan_out = (int)param->value.ui;
break;
case 'C':
capture = TRUE;
- if (strcmp(param->value.str, "none") != 0) {
- capture_pcm_name = strdup(param->value.str);
+ if (strcmp (param->value.str, "none") != 0) {
+ capture_pcm_name = strdup (param->value.str);
}
break;
case 'P':
playback = TRUE;
- if (strcmp(param->value.str, "none") != 0) {
- playback_pcm_name = strdup(param->value.str);
+ if (strcmp (param->value.str, "none") != 0) {
+ playback_pcm_name = strdup (param->value.str);
}
break;
@@ -1182,7 +1197,7 @@ jack_driver_t *driver_initialize(jack_client_t * client,
break;
case 'p':
- frames_per_interrupt = (unsigned int) param->value.ui;
+ frames_per_interrupt = (unsigned int)param->value.ui;
break;
case 'I':
@@ -1192,25 +1207,25 @@ jack_driver_t *driver_initialize(jack_client_t * client,
case 'O':
systemic_output_latency = param->value.ui;
break;
-
+
case 'l':
- display_device_names();
+ display_device_names ();
break;
}
- }
+ }
- /* duplex is the default */
- if (!capture && !playback) {
+ /* duplex is the default */
+ if (!capture && !playback) {
capture = TRUE;
playback = TRUE;
- }
-
- return coreaudio_driver_new("coreaudio", client, frames_per_interrupt,
- srate, capture, playback, chan_in,
- chan_out, capture_pcm_name, playback_pcm_name, systemic_input_latency, systemic_output_latency);
+ }
+
+ return coreaudio_driver_new ("coreaudio", client, frames_per_interrupt,
+ srate, capture, playback, chan_in,
+ chan_out, capture_pcm_name, playback_pcm_name, systemic_input_latency, systemic_output_latency);
}
-void driver_finish(jack_driver_t * driver)
+void driver_finish (jack_driver_t * driver)
{
- coreaudio_driver_delete((coreaudio_driver_t *) driver);
+ coreaudio_driver_delete ((coreaudio_driver_t*)driver);
}
diff --git a/drivers/coreaudio/coreaudio_driver.h b/drivers/coreaudio/coreaudio_driver.h
index b08a866..211549e 100755..100644
--- a/drivers/coreaudio/coreaudio_driver.h
+++ b/drivers/coreaudio/coreaudio_driver.h
@@ -18,12 +18,12 @@
Grame Research Laboratory, 9, rue du Garet 69001 Lyon - France
grame@rd.grame.fr
-
- Johnny Petrantoni, johnny@lato-b.com - Italy, Rome.
-
- 30-01-04, Johnny Petrantoni: first code of the coreaudio driver.
-
-*/
+
+ Johnny Petrantoni, johnny@lato-b.com - Italy, Rome.
+
+ 30-01-04, Johnny Petrantoni: first code of the coreaudio driver.
+
+ */
#ifndef __jack_coreaudio_driver_h__
#define __jack_coreaudio_driver_h__
@@ -41,32 +41,32 @@
typedef struct {
- JACK_DRIVER_DECL struct _jack_engine *engine;
+ JACK_DRIVER_DECL struct _jack_engine *engine;
- jack_nframes_t frame_rate;
- jack_nframes_t frames_per_cycle;
- unsigned long user_nperiods;
- int capturing;
- int playing;
+ jack_nframes_t frame_rate;
+ jack_nframes_t frames_per_cycle;
+ unsigned long user_nperiods;
+ int capturing;
+ int playing;
- channel_t playback_nchannels;
- channel_t capture_nchannels;
+ channel_t playback_nchannels;
+ channel_t capture_nchannels;
- jack_client_t *client;
- JSList *capture_ports;
- JSList *playback_ports;
+ jack_client_t *client;
+ JSList *capture_ports;
+ JSList *playback_ports;
char capture_driver_name[256];
char playback_driver_name[256];
-
+
AudioUnit au_hal;
AudioBufferList* input_list;
AudioDeviceID device_id;
int state;
-
+
jack_nframes_t capture_frame_latency;
jack_nframes_t playback_frame_latency;
-
+
int xrun_detected;
int null_cycle_occured;
@@ -74,10 +74,10 @@ typedef struct {
#define kVersion 01
-typedef UInt8 CAAudioHardwareDeviceSectionID;
-#define kAudioDeviceSectionInput ((CAAudioHardwareDeviceSectionID)0x01)
-#define kAudioDeviceSectionOutput ((CAAudioHardwareDeviceSectionID)0x00)
-#define kAudioDeviceSectionGlobal ((CAAudioHardwareDeviceSectionID)0x00)
-#define kAudioDeviceSectionWildcard ((CAAudioHardwareDeviceSectionID)0xFF)
+typedef UInt8 CAAudioHardwareDeviceSectionID;
+#define kAudioDeviceSectionInput ((CAAudioHardwareDeviceSectionID)0x01)
+#define kAudioDeviceSectionOutput ((CAAudioHardwareDeviceSectionID)0x00)
+#define kAudioDeviceSectionGlobal ((CAAudioHardwareDeviceSectionID)0x00)
+#define kAudioDeviceSectionWildcard ((CAAudioHardwareDeviceSectionID)0xFF)
#endif /* __jack_coreaudio_driver_h__ */
diff --git a/drivers/dummy/dummy_driver.c b/drivers/dummy/dummy_driver.c
index 5eab915..d414cb1 100644
--- a/drivers/dummy/dummy_driver.c
+++ b/drivers/dummy/dummy_driver.c
@@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
+ */
#include <math.h>
#include <stdio.h>
@@ -41,69 +41,71 @@
#define PRETEND_BUFFER_SIZE 4096
void
-FakeVideoSync( dummy_driver_t *driver )
+FakeVideoSync ( dummy_driver_t *driver )
{
- #define VIDEO_SYNC_PERIOD (48000 / 30)
- static int vidCounter = VIDEO_SYNC_PERIOD;
-
- int period = driver->period_size;
- jack_position_t *position = &driver->engine->control->current_time;
-
- if ( period >= VIDEO_SYNC_PERIOD ) {
- jack_error("JACK driver period size too large for simple video sync emulation. Halting.");
- exit(0);
- }
-
- //enable video sync, whether it occurs in this period or not
- position->audio_frames_per_video_frame = VIDEO_SYNC_PERIOD;
- position->valid = (jack_position_bits_t) (position->valid | JackAudioVideoRatio);
-
- //no video pulse found in this period, just decrement the counter
- if ( vidCounter > period ) {
- vidCounter -= period;
- }
-
- //video pulse occurs in this period
- if ( vidCounter <= period ) {
- int remainder = period - vidCounter;
- vidCounter = VIDEO_SYNC_PERIOD - remainder;
-
- position->video_offset = vidCounter;
- position->valid = (jack_position_bits_t) (position->valid | JackVideoFrameOffset);
- }
+ #define VIDEO_SYNC_PERIOD (48000 / 30)
+ static int vidCounter = VIDEO_SYNC_PERIOD;
+
+ int period = driver->period_size;
+ jack_position_t *position = &driver->engine->control->current_time;
+
+ if ( period >= VIDEO_SYNC_PERIOD ) {
+ jack_error ("JACK driver period size too large for simple video sync emulation. Halting.");
+ exit (0);
+ }
+
+ //enable video sync, whether it occurs in this period or not
+ position->audio_frames_per_video_frame = VIDEO_SYNC_PERIOD;
+ position->valid = (jack_position_bits_t)(position->valid | JackAudioVideoRatio);
+
+ //no video pulse found in this period, just decrement the counter
+ if ( vidCounter > period ) {
+ vidCounter -= period;
+ }
+
+ //video pulse occurs in this period
+ if ( vidCounter <= period ) {
+ int remainder = period - vidCounter;
+ vidCounter = VIDEO_SYNC_PERIOD - remainder;
+
+ position->video_offset = vidCounter;
+ position->valid = (jack_position_bits_t)(position->valid | JackVideoFrameOffset);
+ }
}
#ifdef HAVE_CLOCK_GETTIME
-static inline unsigned long long ts_to_nsec(struct timespec ts)
+static inline unsigned long long ts_to_nsec (struct timespec ts)
{
- return ts.tv_sec * 1000000000LL + ts.tv_nsec;
+ return ts.tv_sec * 1000000000LL + ts.tv_nsec;
}
-static inline struct timespec nsec_to_ts(unsigned long long nsecs)
+static inline struct timespec nsec_to_ts (unsigned long long nsecs)
{
- struct timespec ts;
- ts.tv_sec = nsecs / (1000000000LL);
- ts.tv_nsec = nsecs % (1000000000LL);
- return ts;
+ struct timespec ts;
+
+ ts.tv_sec = nsecs / (1000000000LL);
+ ts.tv_nsec = nsecs % (1000000000LL);
+ return ts;
}
-static inline struct timespec add_ts(struct timespec ts, unsigned int usecs)
+static inline struct timespec add_ts (struct timespec ts, unsigned int usecs)
{
- unsigned long long nsecs = ts_to_nsec(ts);
- nsecs += usecs * 1000LL;
- return nsec_to_ts(nsecs);
+ unsigned long long nsecs = ts_to_nsec (ts);
+
+ nsecs += usecs * 1000LL;
+ return nsec_to_ts (nsecs);
}
-static inline int cmp_lt_ts(struct timespec ts1, struct timespec ts2)
+static inline int cmp_lt_ts (struct timespec ts1, struct timespec ts2)
{
- if(ts1.tv_sec < ts2.tv_sec) {
- return 1;
- } else if (ts1.tv_sec == ts2.tv_sec && ts1.tv_nsec < ts2.tv_nsec) {
- return 1;
- } else return 0;
+ if (ts1.tv_sec < ts2.tv_sec) {
+ return 1;
+ } else if (ts1.tv_sec == ts2.tv_sec && ts1.tv_nsec < ts2.tv_nsec) {
+ return 1;
+ } else { return 0; }
}
-static jack_nframes_t
+static jack_nframes_t
dummy_driver_wait (dummy_driver_t *driver, int extra_fd, int *status,
float *delayed_usecs)
{
@@ -112,38 +114,38 @@ dummy_driver_wait (dummy_driver_t *driver, int extra_fd, int *status,
*status = 0;
/* this driver doesn't work so well if we report a delay */
- *delayed_usecs = 0; /* lie about it */
+ *delayed_usecs = 0; /* lie about it */
+
+ clock_gettime (CLOCK_REALTIME, &now);
- clock_gettime(CLOCK_REALTIME, &now);
-
- if (cmp_lt_ts(driver->next_wakeup, now)) {
+ if (cmp_lt_ts (driver->next_wakeup, now)) {
if (driver->next_wakeup.tv_sec == 0) {
/* first time through */
- clock_gettime(CLOCK_REALTIME, &driver->next_wakeup);
- } else if ((ts_to_nsec(now) - ts_to_nsec(driver->next_wakeup))/1000LL
- > (PRETEND_BUFFER_SIZE * 1000000LL
- / driver->sample_rate)) {
+ clock_gettime (CLOCK_REALTIME, &driver->next_wakeup);
+ } else if ((ts_to_nsec (now) - ts_to_nsec (driver->next_wakeup)) / 1000LL
+ > (PRETEND_BUFFER_SIZE * 1000000LL
+ / driver->sample_rate)) {
/* xrun */
- jack_error("**** dummy: xrun of %ju usec",
- (uintmax_t)(ts_to_nsec(now) - ts_to_nsec(driver->next_wakeup))/1000LL);
+ jack_error ("**** dummy: xrun of %ju usec",
+ (uintmax_t)(ts_to_nsec (now) - ts_to_nsec (driver->next_wakeup)) / 1000LL);
nframes = 0;
driver->next_wakeup.tv_sec = 0;
} else {
/* late, but handled by our "buffer"; try to
* get back on track */
}
- driver->next_wakeup = add_ts(driver->next_wakeup, driver->wait_time);
+ driver->next_wakeup = add_ts (driver->next_wakeup, driver->wait_time);
} else {
- if(clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &driver->next_wakeup, NULL)) {
- jack_error("error while sleeping");
+ if (clock_nanosleep (CLOCK_REALTIME, TIMER_ABSTIME, &driver->next_wakeup, NULL)) {
+ jack_error ("error while sleeping");
*status = -1;
} else {
- clock_gettime(CLOCK_REALTIME, &now);
+ clock_gettime (CLOCK_REALTIME, &now);
// guaranteed to sleep long enough for this to be correct
- *delayed_usecs = (ts_to_nsec(now) - ts_to_nsec(driver->next_wakeup));
+ *delayed_usecs = (ts_to_nsec (now) - ts_to_nsec (driver->next_wakeup));
*delayed_usecs /= 1000.0;
}
- driver->next_wakeup = add_ts(driver->next_wakeup, driver->wait_time);
+ driver->next_wakeup = add_ts (driver->next_wakeup, driver->wait_time);
}
driver->last_wait_ust = driver->engine->get_microseconds ();
@@ -153,30 +155,30 @@ dummy_driver_wait (dummy_driver_t *driver, int extra_fd, int *status,
return nframes;
}
-static int dummy_driver_nt_start (dummy_driver_t *drv)
+static int dummy_driver_nt_start (dummy_driver_t *drv)
{
drv->next_wakeup.tv_sec = 0;
- return 0;
+ return 0;
}
#else
-static jack_nframes_t
+static jack_nframes_t
dummy_driver_wait (dummy_driver_t *driver, int extra_fd, int *status,
float *delayed_usecs)
{
- jack_time_t now = driver->engine->get_microseconds();
+ jack_time_t now = driver->engine->get_microseconds ();
if (driver->next_time < now) {
if (driver->next_time == 0) {
/* first time through */
driver->next_time = now + driver->wait_time;
- } else if (now - driver->next_time
- > (PRETEND_BUFFER_SIZE * 1000000LL
- / driver->sample_rate)) {
+ } else if (now - driver->next_time
+ > (PRETEND_BUFFER_SIZE * 1000000LL
+ / driver->sample_rate)) {
/* xrun */
- jack_error("**** dummy: xrun of %ju usec",
- (uintmax_t)now - driver->next_time);
+ jack_error ("**** dummy: xrun of %ju usec",
+ (uintmax_t)now - driver->next_time);
driver->next_time = now + driver->wait_time;
} else {
/* late, but handled by our "buffer"; try to
@@ -185,9 +187,9 @@ dummy_driver_wait (dummy_driver_t *driver, int extra_fd, int *status,
}
} else {
jack_time_t wait = driver->next_time - now;
- struct timespec ts = { .tv_sec = wait / 1000000,
+ struct timespec ts = { .tv_sec = wait / 1000000,
.tv_nsec = (wait % 1000000) * 1000 };
- nanosleep(&ts,NULL);
+ nanosleep (&ts, NULL);
driver->next_time += driver->wait_time;
}
@@ -196,15 +198,15 @@ dummy_driver_wait (dummy_driver_t *driver, int extra_fd, int *status,
driver->last_wait_ust);
/* this driver doesn't work so well if we report a delay */
- *delayed_usecs = 0; /* lie about it */
+ *delayed_usecs = 0; /* lie about it */
*status = 0;
return driver->period_size;
}
-static int dummy_driver_nt_start (dummy_driver_t *drv)
+static int dummy_driver_nt_start (dummy_driver_t *drv)
{
drv->next_time = 0;
- return 0;
+ return 0;
}
#endif
@@ -216,23 +218,26 @@ dummy_driver_run_cycle (dummy_driver_t *driver)
float delayed_usecs;
jack_nframes_t nframes = dummy_driver_wait (driver, -1, &wait_status,
- &delayed_usecs);
+ &delayed_usecs);
+
if (nframes == 0) {
/* we detected an xrun and restarted: notify
* clients about the delay. */
engine->delay (engine, delayed_usecs);
return 0;
- }
+ }
// FakeVideoSync (driver);
- if (wait_status == 0)
+ if (wait_status == 0) {
return engine->run_cycle (engine, nframes, delayed_usecs);
+ }
- if (wait_status < 0)
+ if (wait_status < 0) {
return -1;
- else
+ } else {
return 0;
+ }
}
static int
@@ -244,10 +249,10 @@ dummy_driver_null_cycle (dummy_driver_t* driver, jack_nframes_t nframes)
static int
dummy_driver_bufsize (dummy_driver_t* driver, jack_nframes_t nframes)
{
- driver->period_size = nframes;
+ driver->period_size = nframes;
driver->period_usecs = driver->wait_time =
- (jack_time_t) floor ((((float) nframes) / driver->sample_rate)
- * 1000000.0f);
+ (jack_time_t)floor ((((float)nframes) / driver->sample_rate)
+ * 1000000.0f);
/* tell the engine to change its buffer size */
if (driver->engine->set_buffer_size (driver->engine, nframes)) {
@@ -279,17 +284,15 @@ dummy_driver_attach (dummy_driver_t *driver)
}
driver->engine->set_sample_rate (driver->engine, driver->sample_rate);
- port_flags = JackPortIsOutput|JackPortIsPhysical|JackPortIsTerminal;
+ port_flags = JackPortIsOutput | JackPortIsPhysical | JackPortIsTerminal;
- for (chn = 0; chn < driver->capture_channels; chn++)
- {
- snprintf (buf, sizeof(buf) - 1, "capture_%u", chn+1);
+ for (chn = 0; chn < driver->capture_channels; chn++) {
+ snprintf (buf, sizeof(buf) - 1, "capture_%u", chn + 1);
port = jack_port_register (driver->client, buf,
JACK_DEFAULT_AUDIO_TYPE,
port_flags, 0);
- if (!port)
- {
+ if (!port) {
jack_error ("DUMMY: cannot register port for %s", buf);
break;
}
@@ -297,19 +300,17 @@ dummy_driver_attach (dummy_driver_t *driver)
driver->capture_ports =
jack_slist_append (driver->capture_ports, port);
}
-
- port_flags = JackPortIsInput|JackPortIsPhysical|JackPortIsTerminal;
- for (chn = 0; chn < driver->playback_channels; chn++)
- {
- snprintf (buf, sizeof(buf) - 1, "playback_%u", chn+1);
+ port_flags = JackPortIsInput | JackPortIsPhysical | JackPortIsTerminal;
+
+ for (chn = 0; chn < driver->playback_channels; chn++) {
+ snprintf (buf, sizeof(buf) - 1, "playback_%u", chn + 1);
port = jack_port_register (driver->client, buf,
JACK_DEFAULT_AUDIO_TYPE,
port_flags, 0);
- if (!port)
- {
+ if (!port) {
jack_error ("DUMMY: cannot register port for %s", buf);
break;
}
@@ -328,20 +329,21 @@ dummy_driver_detach (dummy_driver_t *driver)
{
JSList * node;
- if (driver->engine == 0)
+ if (driver->engine == 0) {
return 0;
+ }
for (node = driver->capture_ports; node; node = jack_slist_next (node))
jack_port_unregister (driver->client,
- ((jack_port_t *) node->data));
+ ((jack_port_t*)node->data));
jack_slist_free (driver->capture_ports);
driver->capture_ports = NULL;
-
+
for (node = driver->playback_ports; node; node = jack_slist_next (node))
jack_port_unregister (driver->client,
- ((jack_port_t *) node->data));
+ ((jack_port_t*)node->data));
jack_slist_free (driver->playback_ports);
driver->playback_ports = NULL;
@@ -353,7 +355,7 @@ dummy_driver_detach (dummy_driver_t *driver)
static void
dummy_driver_delete (dummy_driver_t *driver)
{
- jack_driver_nt_finish ((jack_driver_nt_t *) driver);
+ jack_driver_nt_finish ((jack_driver_nt_t*)driver);
free (driver);
}
@@ -369,24 +371,24 @@ dummy_driver_new (jack_client_t * client,
dummy_driver_t * driver;
jack_info ("creating dummy driver ... %s|%" PRIu32 "|%" PRIu32
- "|%lu|%u|%u", name, sample_rate, period_size, wait_time,
- capture_ports, playback_ports);
+ "|%lu|%u|%u", name, sample_rate, period_size, wait_time,
+ capture_ports, playback_ports);
- driver = (dummy_driver_t *) calloc (1, sizeof (dummy_driver_t));
+ driver = (dummy_driver_t*)calloc (1, sizeof(dummy_driver_t));
- jack_driver_nt_init ((jack_driver_nt_t *) driver);
+ jack_driver_nt_init ((jack_driver_nt_t*)driver);
- driver->write = (JackDriverReadFunction) dummy_driver_write;
- driver->null_cycle = (JackDriverNullCycleFunction) dummy_driver_null_cycle;
- driver->nt_attach = (JackDriverNTAttachFunction) dummy_driver_attach;
- driver->nt_start = (JackDriverNTStartFunction) dummy_driver_nt_start;
- driver->nt_detach = (JackDriverNTDetachFunction) dummy_driver_detach;
- driver->nt_bufsize = (JackDriverNTBufSizeFunction) dummy_driver_bufsize;
- driver->nt_run_cycle = (JackDriverNTRunCycleFunction) dummy_driver_run_cycle;
+ driver->write = (JackDriverReadFunction)dummy_driver_write;
+ driver->null_cycle = (JackDriverNullCycleFunction)dummy_driver_null_cycle;
+ driver->nt_attach = (JackDriverNTAttachFunction)dummy_driver_attach;
+ driver->nt_start = (JackDriverNTStartFunction)dummy_driver_nt_start;
+ driver->nt_detach = (JackDriverNTDetachFunction)dummy_driver_detach;
+ driver->nt_bufsize = (JackDriverNTBufSizeFunction)dummy_driver_bufsize;
+ driver->nt_run_cycle = (JackDriverNTRunCycleFunction)dummy_driver_run_cycle;
driver->period_usecs =
- (jack_time_t) floor ((((float) period_size) / sample_rate)
- * 1000000.0f);
+ (jack_time_t)floor ((((float)period_size) / sample_rate)
+ * 1000000.0f);
driver->sample_rate = sample_rate;
driver->period_size = period_size;
driver->wait_time = wait_time;
@@ -401,7 +403,7 @@ dummy_driver_new (jack_client_t * client,
driver->client = client;
driver->engine = NULL;
- return (jack_driver_t *) driver;
+ return (jack_driver_t*)driver;
}
@@ -414,11 +416,11 @@ driver_get_descriptor ()
jack_driver_param_desc_t * params;
unsigned int i;
- desc = calloc (1, sizeof (jack_driver_desc_t));
+ desc = calloc (1, sizeof(jack_driver_desc_t));
strcpy (desc->name, "dummy");
desc->nparams = 5;
- params = calloc (desc->nparams, sizeof (jack_driver_param_desc_t));
+ params = calloc (desc->nparams, sizeof(jack_driver_param_desc_t));
i = 0;
strcpy (params[i].name, "capture");
@@ -481,36 +483,37 @@ driver_initialize (jack_client_t *client, const JSList * params)
const jack_driver_param_t * param;
for (node = params; node; node = jack_slist_next (node)) {
- param = (const jack_driver_param_t *) node->data;
+ param = (const jack_driver_param_t*)node->data;
switch (param->character) {
case 'C':
- capture_ports = param->value.ui;
- break;
+ capture_ports = param->value.ui;
+ break;
case 'P':
- playback_ports = param->value.ui;
- break;
+ playback_ports = param->value.ui;
+ break;
case 'r':
- sample_rate = param->value.ui;
- break;
+ sample_rate = param->value.ui;
+ break;
case 'p':
- period_size = param->value.ui;
- break;
+ period_size = param->value.ui;
+ break;
case 'w':
- wait_time = param->value.ui;
- wait_time_set = 1;
- break;
-
+ wait_time = param->value.ui;
+ wait_time_set = 1;
+ break;
+
}
}
- if (!wait_time_set)
- wait_time = (((float)period_size) / ((float)sample_rate)) * 1000000.0;
+ if (!wait_time_set) {
+ wait_time = (((float)period_size) / ((float)sample_rate)) * 1000000.0;
+ }
return dummy_driver_new (client, "dummy_pcm", capture_ports,
playback_ports, sample_rate, period_size,
@@ -520,6 +523,6 @@ driver_initialize (jack_client_t *client, const JSList * params)
void
driver_finish (jack_driver_t *driver)
{
- dummy_driver_delete ((dummy_driver_t *) driver);
+ dummy_driver_delete ((dummy_driver_t*)driver);
}
diff --git a/drivers/dummy/dummy_driver.h b/drivers/dummy/dummy_driver.h
index 9d74cfe..296f027 100644
--- a/drivers/dummy/dummy_driver.h
+++ b/drivers/dummy/dummy_driver.h
@@ -14,7 +14,7 @@
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 __JACK_DUMMY_DRIVER_H__
@@ -36,27 +36,26 @@
typedef struct _dummy_driver dummy_driver_t;
-struct _dummy_driver
-{
- JACK_DRIVER_NT_DECL;
+struct _dummy_driver {
+ JACK_DRIVER_NT_DECL;
- jack_nframes_t sample_rate;
- jack_nframes_t period_size;
- unsigned long wait_time;
+ jack_nframes_t sample_rate;
+ jack_nframes_t period_size;
+ unsigned long wait_time;
#ifdef HAVE_CLOCK_GETTIME
- struct timespec next_wakeup;
+ struct timespec next_wakeup;
#else
- jack_time_t next_time;
+ jack_time_t next_time;
#endif
- unsigned int capture_channels;
- unsigned int playback_channels;
+ unsigned int capture_channels;
+ unsigned int playback_channels;
- JSList *capture_ports;
- JSList *playback_ports;
+ JSList *capture_ports;
+ JSList *playback_ports;
- jack_client_t *client;
+ jack_client_t *client;
};
#endif /* __JACK_DUMMY_DRIVER_H__ */
diff --git a/drivers/firewire/ffado_driver.c b/drivers/firewire/ffado_driver.c
index 54c091a..02ccdf5 100644
--- a/drivers/firewire/ffado_driver.c
+++ b/drivers/firewire/ffado_driver.c
@@ -24,10 +24,10 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-/*
+/*
* Main Jack driver entry routines
*
- */
+ */
#include <math.h>
#include <stdio.h>
@@ -50,7 +50,7 @@
#define SAMPLE_MAX_24BIT 8388608.0f
#define SAMPLE_MAX_16BIT 32768.0f
-static int ffado_driver_stop (ffado_driver_t *driver);
+static int ffado_driver_stop(ffado_driver_t *driver);
// Basic functionality requires API version 8. If version 9 or later
// is present the buffers can be resized at runtime.
@@ -62,30 +62,29 @@ static int ffado_driver_stop (ffado_driver_t *driver);
*/
#ifndef FFADO_API_VERSION
extern int ffado_streaming_set_period_size(ffado_device_t *dev,
- unsigned int period) __attribute__((__weak__));
+ unsigned int period) __attribute__((__weak__));
#endif
// enable verbose messages
-static int g_verbose=0;
+static int g_verbose = 0;
-static void
+static void
ffado_latency_callback (jack_latency_callback_mode_t mode, void* arg)
{
- ffado_driver_t* driver = (ffado_driver_t*) arg;
- jack_client_t* client = driver->client;
- jack_latency_range_t range;
- JSList* node;
-
- if (mode == JackPlaybackLatency) {
- range.min = range.max = (driver->period_size * (driver->device_options.nb_buffers - 1));
- } else {
- range.min = range.max = driver->period_size + driver->capture_frame_latency;
- }
-
- for (node = client->ports; node; node = jack_slist_next (node)) {
- jack_port_set_latency_range ((jack_port_t*) node->data, mode, &range);
+ ffado_driver_t* driver = (ffado_driver_t*)arg;
+ jack_client_t* client = driver->client;
+ jack_latency_range_t range;
+ JSList* node;
+
+ if (mode == JackPlaybackLatency) {
+ range.min = range.max = (driver->period_size * (driver->device_options.nb_buffers - 1));
+ } else {
+ range.min = range.max = driver->period_size + driver->capture_frame_latency;
}
+
+ for (node = client->ports; node; node = jack_slist_next (node))
+ jack_port_set_latency_range ((jack_port_t*)node->data, mode, &range);
}
static int
@@ -94,10 +93,10 @@ ffado_driver_attach (ffado_driver_t *driver)
char buf[64];
char buf2[64];
channel_t chn;
- jack_port_t *port=NULL;
+ jack_port_t *port = NULL;
int port_flags;
- g_verbose=driver->engine->verbose;
+ g_verbose = driver->engine->verbose;
if (driver->engine->set_buffer_size (driver->engine, driver->period_size)) {
jack_error ("FFADO: cannot set engine buffer size to %d (check MIDI)", driver->period_size);
@@ -109,24 +108,24 @@ ffado_driver_attach (ffado_driver_t *driver)
in RT context (or from the stack)
*/
/* the null buffer is a buffer that contains one period of silence */
- driver->nullbuffer = calloc(driver->period_size, sizeof(ffado_sample_t));
- if(driver->nullbuffer == NULL) {
- printError("could not allocate memory for null buffer");
+ driver->nullbuffer = calloc (driver->period_size, sizeof(ffado_sample_t));
+ if (driver->nullbuffer == NULL) {
+ printError ("could not allocate memory for null buffer");
return -1;
}
/* calloc should do this, but it can't hurt to be sure */
- memset(driver->nullbuffer, 0, driver->period_size*sizeof(ffado_sample_t));
-
+ memset (driver->nullbuffer, 0, driver->period_size * sizeof(ffado_sample_t));
+
/* the scratch buffer is a buffer of one period that can be used as dummy memory */
- driver->scratchbuffer = calloc(driver->period_size, sizeof(ffado_sample_t));
- if(driver->scratchbuffer == NULL) {
- printError("could not allocate memory for scratch buffer");
+ driver->scratchbuffer = calloc (driver->period_size, sizeof(ffado_sample_t));
+ if (driver->scratchbuffer == NULL) {
+ printError ("could not allocate memory for scratch buffer");
return -1;
}
-
+
/* packetizer thread options */
- driver->device_options.realtime=(driver->engine->control->real_time? 1 : 0);
-
+ driver->device_options.realtime = (driver->engine->control->real_time ? 1 : 0);
+
driver->device_options.packetizer_priority = driver->engine->rtpriority;
if (driver->device_options.packetizer_priority > 98) {
driver->device_options.packetizer_priority = 98;
@@ -135,38 +134,38 @@ ffado_driver_attach (ffado_driver_t *driver)
driver->device_options.packetizer_priority = 1;
}
- driver->dev = ffado_streaming_init(driver->device_info, driver->device_options);
+ driver->dev = ffado_streaming_init (driver->device_info, driver->device_options);
- if(!driver->dev) {
- printError("Error creating FFADO streaming device");
+ if (!driver->dev) {
+ printError ("Error creating FFADO streaming device");
return -1;
}
if (driver->device_options.realtime) {
- printMessage("Streaming thread running with Realtime scheduling, priority %d",
- driver->device_options.packetizer_priority);
+ printMessage ("Streaming thread running with Realtime scheduling, priority %d",
+ driver->device_options.packetizer_priority);
} else {
- printMessage("Streaming thread running without Realtime scheduling");
+ printMessage ("Streaming thread running without Realtime scheduling");
}
- ffado_streaming_set_audio_datatype(driver->dev, ffado_audio_datatype_float);
-
+ ffado_streaming_set_audio_datatype (driver->dev, ffado_audio_datatype_float);
+
/* ports */
- port_flags = JackPortIsOutput|JackPortIsPhysical|JackPortIsTerminal;
+ port_flags = JackPortIsOutput | JackPortIsPhysical | JackPortIsTerminal;
- driver->capture_nchannels=ffado_streaming_get_nb_capture_streams(driver->dev);
- driver->capture_channels=calloc(driver->capture_nchannels, sizeof(ffado_capture_channel_t));
- if(driver->capture_channels==NULL) {
- printError("could not allocate memory for capture channel list");
+ driver->capture_nchannels = ffado_streaming_get_nb_capture_streams (driver->dev);
+ driver->capture_channels = calloc (driver->capture_nchannels, sizeof(ffado_capture_channel_t));
+ if (driver->capture_channels == NULL) {
+ printError ("could not allocate memory for capture channel list");
return -1;
}
-
+
for (chn = 0; chn < driver->capture_nchannels; chn++) {
- ffado_streaming_get_capture_stream_name(driver->dev, chn, buf, sizeof(buf) - 1);
- driver->capture_channels[chn].stream_type=ffado_streaming_get_capture_stream_type(driver->dev, chn);
+ ffado_streaming_get_capture_stream_name (driver->dev, chn, buf, sizeof(buf) - 1);
+ driver->capture_channels[chn].stream_type = ffado_streaming_get_capture_stream_type (driver->dev, chn);
- if(driver->capture_channels[chn].stream_type == ffado_stream_type_audio) {
- snprintf(buf2, 64, "C%d_%s",(int)chn,buf); // needed to avoid duplicate names
+ if (driver->capture_channels[chn].stream_type == ffado_stream_type_audio) {
+ snprintf (buf2, 64, "C%d_%s", (int)chn, buf); // needed to avoid duplicate names
printMessage ("Registering audio capture port %s", buf2);
if ((port = jack_port_register (driver->client, buf2,
JACK_DEFAULT_AUDIO_TYPE,
@@ -177,14 +176,14 @@ ffado_driver_attach (ffado_driver_t *driver)
driver->capture_ports =
jack_slist_append (driver->capture_ports, port);
// setup port parameters
- if (ffado_streaming_set_capture_stream_buffer(driver->dev, chn, NULL)) {
- printError(" cannot configure initial port buffer for %s", buf2);
+ if (ffado_streaming_set_capture_stream_buffer (driver->dev, chn, NULL)) {
+ printError (" cannot configure initial port buffer for %s", buf2);
}
- if(ffado_streaming_capture_stream_onoff(driver->dev, chn, 1)) {
- printError(" cannot enable port %s", buf2);
+ if (ffado_streaming_capture_stream_onoff (driver->dev, chn, 1)) {
+ printError (" cannot enable port %s", buf2);
}
- } else if(driver->capture_channels[chn].stream_type == ffado_stream_type_midi) {
- snprintf(buf2, 64, "C%d_%s",(int)chn,buf); // needed to avoid duplicate names
+ } else if (driver->capture_channels[chn].stream_type == ffado_stream_type_midi) {
+ snprintf (buf2, 64, "C%d_%s", (int)chn, buf); // needed to avoid duplicate names
printMessage ("Registering midi capture port %s", buf2);
if ((port = jack_port_register (driver->client, buf2,
JACK_DEFAULT_MIDI_TYPE,
@@ -195,17 +194,17 @@ ffado_driver_attach (ffado_driver_t *driver)
driver->capture_ports =
jack_slist_append (driver->capture_ports, port);
// setup port parameters
- if (ffado_streaming_set_capture_stream_buffer(driver->dev, chn, NULL)) {
- printError(" cannot configure initial port buffer for %s", buf2);
+ if (ffado_streaming_set_capture_stream_buffer (driver->dev, chn, NULL)) {
+ printError (" cannot configure initial port buffer for %s", buf2);
}
- if(ffado_streaming_capture_stream_onoff(driver->dev, chn, 1)) {
- printError(" cannot enable port %s", buf2);
+ if (ffado_streaming_capture_stream_onoff (driver->dev, chn, 1)) {
+ printError (" cannot enable port %s", buf2);
}
// setup midi unpacker
- midi_unpack_init(&driver->capture_channels[chn].midi_unpack);
- midi_unpack_reset(&driver->capture_channels[chn].midi_unpack);
+ midi_unpack_init (&driver->capture_channels[chn].midi_unpack);
+ midi_unpack_reset (&driver->capture_channels[chn].midi_unpack);
// setup the midi buffer
- driver->capture_channels[chn].midi_buffer = calloc(driver->period_size, sizeof(uint32_t));
+ driver->capture_channels[chn].midi_buffer = calloc (driver->period_size, sizeof(uint32_t));
} else {
printMessage ("Don't register capture port %s", buf);
@@ -214,62 +213,62 @@ ffado_driver_attach (ffado_driver_t *driver)
jack_slist_append (driver->capture_ports, NULL);
}
}
-
- port_flags = JackPortIsInput|JackPortIsPhysical|JackPortIsTerminal;
- driver->playback_nchannels=ffado_streaming_get_nb_playback_streams(driver->dev);
- driver->playback_channels=calloc(driver->playback_nchannels, sizeof(ffado_playback_channel_t));
- if(driver->playback_channels==NULL) {
- printError("could not allocate memory for playback channel list");
+ port_flags = JackPortIsInput | JackPortIsPhysical | JackPortIsTerminal;
+
+ driver->playback_nchannels = ffado_streaming_get_nb_playback_streams (driver->dev);
+ driver->playback_channels = calloc (driver->playback_nchannels, sizeof(ffado_playback_channel_t));
+ if (driver->playback_channels == NULL) {
+ printError ("could not allocate memory for playback channel list");
return -1;
}
for (chn = 0; chn < driver->playback_nchannels; chn++) {
- ffado_streaming_get_playback_stream_name(driver->dev, chn, buf, sizeof(buf) - 1);
- driver->playback_channels[chn].stream_type=ffado_streaming_get_playback_stream_type(driver->dev, chn);
-
- if(driver->playback_channels[chn].stream_type == ffado_stream_type_audio) {
- snprintf(buf2, 64, "P%d_%s",(int)chn,buf); // needed to avoid duplicate names
+ ffado_streaming_get_playback_stream_name (driver->dev, chn, buf, sizeof(buf) - 1);
+ driver->playback_channels[chn].stream_type = ffado_streaming_get_playback_stream_type (driver->dev, chn);
+
+ if (driver->playback_channels[chn].stream_type == ffado_stream_type_audio) {
+ snprintf (buf2, 64, "P%d_%s", (int)chn, buf); // needed to avoid duplicate names
printMessage ("Registering audio playback port %s", buf2);
if ((port = jack_port_register (driver->client, buf2,
JACK_DEFAULT_AUDIO_TYPE,
port_flags, 0)) == NULL) {
- printError(" cannot register port for %s", buf2);
+ printError (" cannot register port for %s", buf2);
break;
}
driver->playback_ports =
jack_slist_append (driver->playback_ports, port);
// setup port parameters
- if (ffado_streaming_set_playback_stream_buffer(driver->dev, chn, NULL)) {
- printError(" cannot configure initial port buffer for %s", buf2);
+ if (ffado_streaming_set_playback_stream_buffer (driver->dev, chn, NULL)) {
+ printError (" cannot configure initial port buffer for %s", buf2);
}
- if(ffado_streaming_playback_stream_onoff(driver->dev, chn, 1)) {
- printError(" cannot enable port %s", buf2);
+ if (ffado_streaming_playback_stream_onoff (driver->dev, chn, 1)) {
+ printError (" cannot enable port %s", buf2);
}
- } else if(driver->playback_channels[chn].stream_type == ffado_stream_type_midi) {
- snprintf(buf2, 64, "P%d_%s",(int)chn,buf); // needed to avoid duplicate names
+ } else if (driver->playback_channels[chn].stream_type == ffado_stream_type_midi) {
+ snprintf (buf2, 64, "P%d_%s", (int)chn, buf); // needed to avoid duplicate names
printMessage ("Registering midi playback port %s", buf2);
if ((port = jack_port_register (driver->client, buf2,
JACK_DEFAULT_MIDI_TYPE,
port_flags, 0)) == NULL) {
- printError(" cannot register port for %s", buf2);
+ printError (" cannot register port for %s", buf2);
break;
}
driver->playback_ports =
jack_slist_append (driver->playback_ports, port);
// setup port parameters
- if (ffado_streaming_set_playback_stream_buffer(driver->dev, chn, NULL)) {
- printError(" cannot configure initial port buffer for %s", buf2);
+ if (ffado_streaming_set_playback_stream_buffer (driver->dev, chn, NULL)) {
+ printError (" cannot configure initial port buffer for %s", buf2);
}
- if(ffado_streaming_playback_stream_onoff(driver->dev, chn, 1)) {
- printError(" cannot enable port %s", buf2);
+ if (ffado_streaming_playback_stream_onoff (driver->dev, chn, 1)) {
+ printError (" cannot enable port %s", buf2);
}
// setup midi packer
- midi_pack_reset(&driver->playback_channels[chn].midi_pack);
+ midi_pack_reset (&driver->playback_channels[chn].midi_pack);
// setup the midi buffer
- driver->playback_channels[chn].midi_buffer = calloc(driver->period_size, sizeof(uint32_t));
+ driver->playback_channels[chn].midi_buffer = calloc (driver->period_size, sizeof(uint32_t));
} else {
printMessage ("Don't register playback port %s", buf);
@@ -279,15 +278,15 @@ ffado_driver_attach (ffado_driver_t *driver)
}
}
- if(ffado_streaming_prepare(driver->dev)) {
- printError("Could not prepare streaming device!");
+ if (ffado_streaming_prepare (driver->dev)) {
+ printError ("Could not prepare streaming device!");
return -1;
}
return jack_activate (driver->client);
}
-static int
+static int
ffado_driver_detach (ffado_driver_t *driver)
{
JSList *node;
@@ -303,41 +302,41 @@ ffado_driver_detach (ffado_driver_t *driver)
// ffado ports by ffado_driver_attach().
if (node->data != NULL) {
jack_port_unregister (driver->client,
- ((jack_port_t *) node->data));
+ ((jack_port_t*)node->data));
}
}
jack_slist_free (driver->capture_ports);
driver->capture_ports = 0;
-
+
for (node = driver->playback_ports; node;
node = jack_slist_next (node)) {
- if (node->data != NULL) {
- jack_port_unregister (driver->client,
- ((jack_port_t *) node->data));
- }
+ if (node->data != NULL) {
+ jack_port_unregister (driver->client,
+ ((jack_port_t*)node->data));
+ }
}
jack_slist_free (driver->playback_ports);
driver->playback_ports = 0;
- ffado_streaming_finish(driver->dev);
- driver->dev=NULL;
+ ffado_streaming_finish (driver->dev);
+ driver->dev = NULL;
- for (chn = 0; chn < driver->capture_nchannels; chn++) {
- if(driver->capture_channels[chn].midi_buffer)
- free(driver->capture_channels[chn].midi_buffer);
- }
- free(driver->capture_channels);
-
- for (chn = 0; chn < driver->playback_nchannels; chn++) {
- if(driver->playback_channels[chn].midi_buffer)
- free(driver->playback_channels[chn].midi_buffer);
- }
- free(driver->playback_channels);
-
- free(driver->nullbuffer);
- free(driver->scratchbuffer);
+ for (chn = 0; chn < driver->capture_nchannels; chn++)
+ if (driver->capture_channels[chn].midi_buffer) {
+ free (driver->capture_channels[chn].midi_buffer);
+ }
+ free (driver->capture_channels);
+
+ for (chn = 0; chn < driver->playback_nchannels; chn++)
+ if (driver->playback_channels[chn].midi_buffer) {
+ free (driver->playback_channels[chn].midi_buffer);
+ }
+ free (driver->playback_channels);
+
+ free (driver->nullbuffer);
+ free (driver->scratchbuffer);
return 0;
}
@@ -348,40 +347,40 @@ ffado_driver_read (ffado_driver_t * driver, jack_nframes_t nframes)
int nb_connections;
JSList *node;
jack_port_t* port;
-
- printEnter();
+
+ printEnter ();
for (chn = 0, node = driver->capture_ports; node; node = jack_slist_next (node), chn++) {
- if(driver->capture_channels[chn].stream_type == ffado_stream_type_audio) {
- port = (jack_port_t *) node->data;
+ if (driver->capture_channels[chn].stream_type == ffado_stream_type_audio) {
+ port = (jack_port_t*)node->data;
nb_connections = jack_port_connected (port);
/* if there are no connections, use the dummy buffer and disable the stream */
- if(nb_connections) {
- ffado_streaming_capture_stream_onoff(driver->dev, chn, 1);
- ffado_streaming_set_capture_stream_buffer(driver->dev, chn, (char *)(jack_port_get_buffer (port, nframes)));
+ if (nb_connections) {
+ ffado_streaming_capture_stream_onoff (driver->dev, chn, 1);
+ ffado_streaming_set_capture_stream_buffer (driver->dev, chn, (char*)(jack_port_get_buffer (port, nframes)));
} else {
- ffado_streaming_capture_stream_onoff(driver->dev, chn, 0);
- ffado_streaming_set_capture_stream_buffer(driver->dev, chn, (char *)(driver->scratchbuffer));
+ ffado_streaming_capture_stream_onoff (driver->dev, chn, 0);
+ ffado_streaming_set_capture_stream_buffer (driver->dev, chn, (char*)(driver->scratchbuffer));
}
} else if (driver->capture_channels[chn].stream_type == ffado_stream_type_midi) {
- port = (jack_port_t *) node->data;
+ port = (jack_port_t*)node->data;
nb_connections = jack_port_connected (port);
- if(nb_connections) {
- ffado_streaming_capture_stream_onoff(driver->dev, chn, 1);
+ if (nb_connections) {
+ ffado_streaming_capture_stream_onoff (driver->dev, chn, 1);
} else {
- ffado_streaming_capture_stream_onoff(driver->dev, chn, 0);
+ ffado_streaming_capture_stream_onoff (driver->dev, chn, 0);
}
/* always set a buffer */
- ffado_streaming_set_capture_stream_buffer(driver->dev, chn,
- (char *)(driver->capture_channels[chn].midi_buffer));
+ ffado_streaming_set_capture_stream_buffer (driver->dev, chn,
+ (char*)(driver->capture_channels[chn].midi_buffer));
} else { /* ensure a valid buffer */
- ffado_streaming_set_capture_stream_buffer(driver->dev, chn, (char *)(driver->scratchbuffer));
- ffado_streaming_capture_stream_onoff(driver->dev, chn, 0);
+ ffado_streaming_set_capture_stream_buffer (driver->dev, chn, (char*)(driver->scratchbuffer));
+ ffado_streaming_capture_stream_onoff (driver->dev, chn, 0);
}
}
/* now transfer the buffers */
- ffado_streaming_transfer_capture_buffers(driver->dev);
+ ffado_streaming_transfer_capture_buffers (driver->dev);
/* process the midi data */
for (chn = 0, node = driver->capture_ports; node; node = jack_slist_next (node), chn++) {
@@ -391,23 +390,25 @@ ffado_driver_read (ffado_driver_t * driver, jack_nframes_t nframes)
int done;
uint32_t *midi_buffer = driver->capture_channels[chn].midi_buffer;
midi_unpack_t *midi_unpack = &driver->capture_channels[chn].midi_unpack;
- port = (jack_port_t *) node->data;
+ port = (jack_port_t*)node->data;
nb_connections = jack_port_connected (port);
buf = jack_port_get_buffer (port, nframes);
/* if the returned buffer is invalid, discard the midi data */
- jack_midi_clear_buffer(buf);
+ jack_midi_clear_buffer (buf);
/* no connections means no processing */
- if(nb_connections == 0) continue;
+ if (nb_connections == 0) {
+ continue;
+ }
/* else unpack
note that libffado guarantees that midi bytes are on 8-byte aligned indexes */
- for(i = 0; i < nframes; i += 8) {
- if(midi_buffer[i] & 0xFF000000) {
- done = midi_unpack_buf(midi_unpack, (unsigned char *)(midi_buffer+i), 1, buf, i);
+ for (i = 0; i < nframes; i += 8) {
+ if (midi_buffer[i] & 0xFF000000) {
+ done = midi_unpack_buf (midi_unpack, (unsigned char*)(midi_buffer + i), 1, buf, i);
if (done != 1) {
- printError("MIDI buffer overflow in channel %d\n", chn);
+ printError ("MIDI buffer overflow in channel %d\n", chn);
break;
}
}
@@ -415,7 +416,7 @@ ffado_driver_read (ffado_driver_t * driver, jack_nframes_t nframes)
}
}
- printExit();
+ printExit ();
return 0;
}
@@ -426,25 +427,26 @@ ffado_driver_write (ffado_driver_t * driver, jack_nframes_t nframes)
int nb_connections;
JSList *node;
jack_port_t *port;
- printEnter();
-
+
+ printEnter ();
+
driver->process_count++;
if (driver->engine->freewheeling) {
return 0;
}
for (chn = 0, node = driver->playback_ports; node; node = jack_slist_next (node), chn++) {
- if(driver->playback_channels[chn].stream_type == ffado_stream_type_audio) {
- port = (jack_port_t *) node->data;
+ if (driver->playback_channels[chn].stream_type == ffado_stream_type_audio) {
+ port = (jack_port_t*)node->data;
nb_connections = jack_port_connected (port);
/* use the silent buffer + disable if there are no connections */
- if(nb_connections) {
- ffado_streaming_playback_stream_onoff(driver->dev, chn, 1);
- ffado_streaming_set_playback_stream_buffer(driver->dev, chn, (char *)(jack_port_get_buffer (port, nframes)));
+ if (nb_connections) {
+ ffado_streaming_playback_stream_onoff (driver->dev, chn, 1);
+ ffado_streaming_set_playback_stream_buffer (driver->dev, chn, (char*)(jack_port_get_buffer (port, nframes)));
} else {
- ffado_streaming_playback_stream_onoff(driver->dev, chn, 0);
- ffado_streaming_set_playback_stream_buffer(driver->dev, chn, (char *)(driver->nullbuffer));
+ ffado_streaming_playback_stream_onoff (driver->dev, chn, 0);
+ ffado_streaming_set_playback_stream_buffer (driver->dev, chn, (char*)(driver->nullbuffer));
}
} else if (driver->playback_channels[chn].stream_type == ffado_stream_type_midi) {
jack_default_audio_sample_t* buf;
@@ -454,68 +456,66 @@ ffado_driver_write (ffado_driver_t * driver, jack_nframes_t nframes)
uint32_t *midi_buffer = driver->playback_channels[chn].midi_buffer;
int min_next_pos = 0;
- port = (jack_port_t *) node->data;
+ port = (jack_port_t*)node->data;
nb_connections = jack_port_connected (port);
/* skip if no connections */
- if(nb_connections == 0) {
- ffado_streaming_set_playback_stream_buffer(driver->dev, chn, (char *)(driver->nullbuffer));
- ffado_streaming_playback_stream_onoff(driver->dev, chn, 0);
+ if (nb_connections == 0) {
+ ffado_streaming_set_playback_stream_buffer (driver->dev, chn, (char*)(driver->nullbuffer));
+ ffado_streaming_playback_stream_onoff (driver->dev, chn, 0);
continue;
}
- memset(midi_buffer, 0, nframes * sizeof(uint32_t));
- ffado_streaming_set_playback_stream_buffer(driver->dev, chn, (char *)(midi_buffer));
- ffado_streaming_playback_stream_onoff(driver->dev, chn, 1);
+ memset (midi_buffer, 0, nframes * sizeof(uint32_t));
+ ffado_streaming_set_playback_stream_buffer (driver->dev, chn, (char*)(midi_buffer));
+ ffado_streaming_playback_stream_onoff (driver->dev, chn, 1);
/* check if we still have to process bytes from the previous period */
/*
- if(driver->playback_channels[chn].nb_overflow_bytes) {
- printMessage("have to process %d bytes from previous period", driver->playback_channels[chn].nb_overflow_bytes);
- }
- */
- for (i=0; i<driver->playback_channels[chn].nb_overflow_bytes; ++i) {
+ if(driver->playback_channels[chn].nb_overflow_bytes) {
+ printMessage("have to process %d bytes from previous period", driver->playback_channels[chn].nb_overflow_bytes);
+ }
+ */
+ for (i = 0; i < driver->playback_channels[chn].nb_overflow_bytes; ++i) {
midi_buffer[min_next_pos] = 0x01000000 | (driver->playback_channels[chn].overflow_buffer[i] & 0xFF);
min_next_pos += 8;
}
- driver->playback_channels[chn].nb_overflow_bytes=0;
-
+ driver->playback_channels[chn].nb_overflow_bytes = 0;
+
/* process the events in this period */
buf = jack_port_get_buffer (port, nframes);
- nevents = jack_midi_get_event_count(buf);
+ nevents = jack_midi_get_event_count (buf);
- for (i=0; i<nevents; ++i) {
+ for (i = 0; i < nevents; ++i) {
int j;
jack_midi_event_t event;
- jack_midi_event_get(&event, buf, i);
+ jack_midi_event_get (&event, buf, i);
- midi_pack_event(midi_pack, &event);
+ midi_pack_event (midi_pack, &event);
/* floor the initial position to be a multiple of 8 */
int pos = event.time & 0xFFFFFFF8;
- for(j = 0; j < event.size; j++) {
+ for (j = 0; j < event.size; j++) {
/* make sure we don't overwrite a previous byte */
- while(pos < min_next_pos && pos < nframes) {
+ while (pos < min_next_pos && pos < nframes)
/* printMessage("have to correct pos to %d", pos); */
pos += 8;
- }
- if(pos >= nframes) {
+ if (pos >= nframes) {
int f;
/* printMessage("midi message crosses period boundary"); */
driver->playback_channels[chn].nb_overflow_bytes = event.size - j;
- if(driver->playback_channels[chn].nb_overflow_bytes > MIDI_OVERFLOW_BUFFER_SIZE) {
- printError("too much midi bytes cross period boundary");
+ if (driver->playback_channels[chn].nb_overflow_bytes > MIDI_OVERFLOW_BUFFER_SIZE) {
+ printError ("too much midi bytes cross period boundary");
driver->playback_channels[chn].nb_overflow_bytes = MIDI_OVERFLOW_BUFFER_SIZE;
}
/* save the bytes that still have to be transmitted in the next period */
- for(f = 0; f < driver->playback_channels[chn].nb_overflow_bytes; f++) {
- driver->playback_channels[chn].overflow_buffer[f] = event.buffer[j+f];
- }
- /* exit since we can't transmit anything anymore.
- the rate should be controlled */
- if(i < nevents-1) {
- printError("%d midi events lost due to period crossing", nevents-i-1);
+ for (f = 0; f < driver->playback_channels[chn].nb_overflow_bytes; f++)
+ driver->playback_channels[chn].overflow_buffer[f] = event.buffer[j + f];
+ /* exit since we can't transmit anything anymore.
+ the rate should be controlled */
+ if (i < nevents - 1) {
+ printError ("%d midi events lost due to period crossing", nevents - i - 1);
}
break;
} else {
@@ -526,35 +526,35 @@ ffado_driver_write (ffado_driver_t * driver, jack_nframes_t nframes)
}
}
} else { /* ensure a valid buffer */
- ffado_streaming_set_playback_stream_buffer(driver->dev, chn, (char *)(driver->nullbuffer));
- ffado_streaming_playback_stream_onoff(driver->dev, chn, 0);
+ ffado_streaming_set_playback_stream_buffer (driver->dev, chn, (char*)(driver->nullbuffer));
+ ffado_streaming_playback_stream_onoff (driver->dev, chn, 0);
}
}
- ffado_streaming_transfer_playback_buffers(driver->dev);
+ ffado_streaming_transfer_playback_buffers (driver->dev);
- printExit();
+ printExit ();
return 0;
}
-//static inline jack_nframes_t
-static jack_nframes_t
+//static inline jack_nframes_t
+static jack_nframes_t
ffado_driver_wait (ffado_driver_t *driver, int extra_fd, int *status,
float *delayed_usecs)
{
- jack_time_t wait_enter;
- jack_time_t wait_ret;
- ffado_wait_response response;
-
- printEnter();
+ jack_time_t wait_enter;
+ jack_time_t wait_ret;
+ ffado_wait_response response;
+
+ printEnter ();
wait_enter = driver->engine->get_microseconds ();
if (wait_enter > driver->wait_next) {
/*
- * This processing cycle was delayed past the
- * next due interrupt! Do not account this as
- * a wakeup delay:
- */
+ * This processing cycle was delayed past the
+ * next due interrupt! Do not account this as
+ * a wakeup delay:
+ */
driver->wait_next = 0;
driver->wait_late++;
}
@@ -562,10 +562,10 @@ ffado_driver_wait (ffado_driver_t *driver, int extra_fd, int *status,
// *status = -3; timeout
// *status = -4; extra FD
- response = ffado_streaming_wait(driver->dev);
-
+ response = ffado_streaming_wait (driver->dev);
+
wait_ret = driver->engine->get_microseconds ();
-
+
if (driver->wait_next && wait_ret > driver->wait_next) {
*delayed_usecs = wait_ret - driver->wait_next;
}
@@ -574,26 +574,26 @@ ffado_driver_wait (ffado_driver_t *driver, int extra_fd, int *status,
driver->engine->transport_cycle_start (driver->engine, wait_ret);
if (response == ffado_wait_ok) {
// all good
- *status=0;
+ *status = 0;
} else if (response == ffado_wait_xrun) {
// xrun happened, but it's handled
- *status=0;
+ *status = 0;
return 0;
} else if (response == ffado_wait_error) {
// an error happened (unhandled xrun)
// this should be fatal
- *status=-1;
+ *status = -1;
return 0;
} else if (response == ffado_wait_shutdown) {
// we are to shutdown the ffado system
// this should be fatal
- *status=-1;
+ *status = -1;
return 0;
} else {
// we don't know about this response code
- printError("unknown wait response (%d) from ffado", response);
+ printError ("unknown wait response (%d) from ffado", response);
// this should be fatal
- *status=-1;
+ *status = -1;
return 0;
}
@@ -601,8 +601,8 @@ ffado_driver_wait (ffado_driver_t *driver, int extra_fd, int *status,
// FIXME: this should do something more useful
*delayed_usecs = 0;
-
- printExit();
+
+ printExit ();
return driver->period_size;
}
@@ -611,25 +611,25 @@ static int
ffado_driver_run_cycle (ffado_driver_t *driver)
{
jack_engine_t *engine = driver->engine;
- int wait_status=0;
- float delayed_usecs=0.0;
+ int wait_status = 0;
+ float delayed_usecs = 0.0;
jack_nframes_t nframes = ffado_driver_wait (driver, -1,
- &wait_status, &delayed_usecs);
-
+ &wait_status, &delayed_usecs);
+
if ((wait_status < 0)) {
- printError( "wait status < 0! (= %d)",wait_status);
+ printError ( "wait status < 0! (= %d)", wait_status);
return -1;
}
-
+
if ((nframes == 0)) {
/* we detected an xrun and restarted: notify
* clients about the delay. */
- printMessage("xrun detected");
+ printMessage ("xrun detected");
engine->delay (engine, delayed_usecs);
return 0;
- }
-
+ }
+
return engine->run_cycle (engine, nframes, delayed_usecs);
}
@@ -643,42 +643,42 @@ ffado_driver_null_cycle (ffado_driver_t* driver, jack_nframes_t nframes)
JSList *node;
ffado_streaming_stream_type stream_type;
- printEnter();
-
+ printEnter ();
+
if (driver->engine->freewheeling) {
return 0;
}
// write silence to buffer
for (chn = 0, node = driver->playback_ports; node; node = jack_slist_next (node), chn++) {
- stream_type=ffado_streaming_get_playback_stream_type(driver->dev, chn);
+ stream_type = ffado_streaming_get_playback_stream_type (driver->dev, chn);
- if(stream_type == ffado_stream_type_audio) {
- ffado_streaming_set_playback_stream_buffer(driver->dev, chn, (char *)(driver->nullbuffer));
+ if (stream_type == ffado_stream_type_audio) {
+ ffado_streaming_set_playback_stream_buffer (driver->dev, chn, (char*)(driver->nullbuffer));
}
}
- ffado_streaming_transfer_playback_buffers(driver->dev);
-
+ ffado_streaming_transfer_playback_buffers (driver->dev);
+
// read & discard from input ports
for (chn = 0, node = driver->capture_ports; node; node = jack_slist_next (node), chn++) {
- stream_type=ffado_streaming_get_capture_stream_type(driver->dev, chn);
- if(stream_type == ffado_stream_type_audio) {
- ffado_streaming_set_capture_stream_buffer(driver->dev, chn, (char *)(driver->scratchbuffer));
+ stream_type = ffado_streaming_get_capture_stream_type (driver->dev, chn);
+ if (stream_type == ffado_stream_type_audio) {
+ ffado_streaming_set_capture_stream_buffer (driver->dev, chn, (char*)(driver->scratchbuffer));
}
}
- ffado_streaming_transfer_capture_buffers(driver->dev);
+ ffado_streaming_transfer_capture_buffers (driver->dev);
- printExit();
+ printExit ();
return 0;
}
static int
ffado_driver_start (ffado_driver_t *driver)
{
- int retval=0;
+ int retval = 0;
- if((retval=ffado_streaming_start(driver->dev))) {
- printError("Could not start streaming threads: %d", retval);
+ if ((retval = ffado_streaming_start (driver->dev))) {
+ printError ("Could not start streaming threads: %d", retval);
return retval;
}
@@ -689,10 +689,10 @@ ffado_driver_start (ffado_driver_t *driver)
static int
ffado_driver_stop (ffado_driver_t *driver)
{
- int retval=0;
-
- if((retval=ffado_streaming_stop(driver->dev))) {
- printError("Could not stop streaming threads");
+ int retval = 0;
+
+ if ((retval = ffado_streaming_stop (driver->dev))) {
+ printError ("Could not stop streaming threads");
return retval;
}
@@ -706,55 +706,57 @@ ffado_driver_bufsize (ffado_driver_t* driver, jack_nframes_t nframes)
// The speed of this function isn't critical; we can afford the
// time to check the FFADO API version.
- if (ffado_get_api_version() < FIREWIRE_REQUIRED_FFADO_API_VERSION_FOR_SETBUFSIZE ||
- ffado_streaming_set_period_size == NULL) {
- printError("unsupported on current version of FFADO; please upgrade FFADO");
- return -1;
+ if (ffado_get_api_version () < FIREWIRE_REQUIRED_FFADO_API_VERSION_FOR_SETBUFSIZE ||
+ ffado_streaming_set_period_size == NULL) {
+ printError ("unsupported on current version of FFADO; please upgrade FFADO");
+ return -1;
}
driver->period_size = nframes;
driver->period_usecs =
- (jack_time_t) floor ((((float) nframes) / driver->sample_rate)
- * 1000000.0f);
+ (jack_time_t)floor ((((float)nframes) / driver->sample_rate)
+ * 1000000.0f);
// Reallocate the null and scratch buffers.
- driver->nullbuffer = calloc(driver->period_size, sizeof(ffado_sample_t));
- if(driver->nullbuffer == NULL) {
- printError("could not allocate memory for null buffer");
+ driver->nullbuffer = calloc (driver->period_size, sizeof(ffado_sample_t));
+ if (driver->nullbuffer == NULL) {
+ printError ("could not allocate memory for null buffer");
return -1;
}
- driver->scratchbuffer = calloc(driver->period_size, sizeof(ffado_sample_t));
- if(driver->scratchbuffer == NULL) {
- printError("could not allocate memory for scratch buffer");
+ driver->scratchbuffer = calloc (driver->period_size, sizeof(ffado_sample_t));
+ if (driver->scratchbuffer == NULL) {
+ printError ("could not allocate memory for scratch buffer");
return -1;
}
// MIDI buffers need reallocating
for (chn = 0; chn < driver->capture_nchannels; chn++) {
- if(driver->capture_channels[chn].stream_type == ffado_stream_type_midi) {
+ if (driver->capture_channels[chn].stream_type == ffado_stream_type_midi) {
// setup the midi buffer
- if (driver->capture_channels[chn].midi_buffer != NULL)
- free(driver->capture_channels[chn].midi_buffer);
- driver->capture_channels[chn].midi_buffer = calloc(driver->period_size, sizeof(uint32_t));
+ if (driver->capture_channels[chn].midi_buffer != NULL) {
+ free (driver->capture_channels[chn].midi_buffer);
+ }
+ driver->capture_channels[chn].midi_buffer = calloc (driver->period_size, sizeof(uint32_t));
}
}
for (chn = 0; chn < driver->playback_nchannels; chn++) {
- if(driver->playback_channels[chn].stream_type == ffado_stream_type_midi) {
- if (driver->playback_channels[chn].midi_buffer != NULL)
- free(driver->playback_channels[chn].midi_buffer);
- driver->playback_channels[chn].midi_buffer = calloc(driver->period_size, sizeof(uint32_t));
+ if (driver->playback_channels[chn].stream_type == ffado_stream_type_midi) {
+ if (driver->playback_channels[chn].midi_buffer != NULL) {
+ free (driver->playback_channels[chn].midi_buffer);
+ }
+ driver->playback_channels[chn].midi_buffer = calloc (driver->period_size, sizeof(uint32_t));
}
}
// Notify FFADO of the period size change
- if (ffado_streaming_set_period_size(driver->dev, nframes) != 0) {
- printError("could not alter FFADO device period size");
- return -1;
+ if (ffado_streaming_set_period_size (driver->dev, nframes) != 0) {
+ printError ("could not alter FFADO device period size");
+ return -1;
}
// This is needed to give the shadow variables a chance to
// properly update to the changes.
- sleep(1);
+ sleep (1);
/* tell the engine to change its buffer size */
if (driver->engine->set_buffer_size (driver->engine, nframes)) {
@@ -762,10 +764,10 @@ ffado_driver_bufsize (ffado_driver_t* driver, jack_nframes_t nframes)
return -1;
}
- return 0;
+ return 0;
}
-typedef void (*JackDriverFinishFunction) (jack_driver_t *);
+typedef void (*JackDriverFinishFunction)(jack_driver_t *);
ffado_driver_t *
ffado_driver_new (jack_client_t * client,
@@ -774,66 +776,66 @@ ffado_driver_new (jack_client_t * client,
{
ffado_driver_t *driver;
- if(ffado_get_api_version() < FIREWIRE_REQUIRED_FFADO_API_VERSION) {
- printError("Incompatible libffado version! (%s)", ffado_get_version());
+ if (ffado_get_api_version () < FIREWIRE_REQUIRED_FFADO_API_VERSION) {
+ printError ("Incompatible libffado version! (%s)", ffado_get_version ());
return NULL;
}
- printMessage("Starting firewire backend (%s)", ffado_get_version());
+ printMessage ("Starting firewire backend (%s)", ffado_get_version ());
- driver = calloc (1, sizeof (ffado_driver_t));
+ driver = calloc (1, sizeof(ffado_driver_t));
- /* Setup the jack interfaces */
- jack_driver_nt_init ((jack_driver_nt_t *) driver);
+ /* Setup the jack interfaces */
+ jack_driver_nt_init ((jack_driver_nt_t*)driver);
+
+ driver->nt_attach = (JackDriverNTAttachFunction)ffado_driver_attach;
+ driver->nt_detach = (JackDriverNTDetachFunction)ffado_driver_detach;
+ driver->nt_start = (JackDriverNTStartFunction)ffado_driver_start;
+ driver->nt_stop = (JackDriverNTStopFunction)ffado_driver_stop;
+ driver->nt_run_cycle = (JackDriverNTRunCycleFunction)ffado_driver_run_cycle;
+ driver->null_cycle = (JackDriverNullCycleFunction)ffado_driver_null_cycle;
+ driver->write = (JackDriverReadFunction)ffado_driver_write;
+ driver->read = (JackDriverReadFunction)ffado_driver_read;
+ driver->nt_bufsize = (JackDriverNTBufSizeFunction)ffado_driver_bufsize;
- driver->nt_attach = (JackDriverNTAttachFunction) ffado_driver_attach;
- driver->nt_detach = (JackDriverNTDetachFunction) ffado_driver_detach;
- driver->nt_start = (JackDriverNTStartFunction) ffado_driver_start;
- driver->nt_stop = (JackDriverNTStopFunction) ffado_driver_stop;
- driver->nt_run_cycle = (JackDriverNTRunCycleFunction) ffado_driver_run_cycle;
- driver->null_cycle = (JackDriverNullCycleFunction) ffado_driver_null_cycle;
- driver->write = (JackDriverReadFunction) ffado_driver_write;
- driver->read = (JackDriverReadFunction) ffado_driver_read;
- driver->nt_bufsize = (JackDriverNTBufSizeFunction) ffado_driver_bufsize;
-
/* copy command line parameter contents to the driver structure */
- memcpy(&driver->settings,params,sizeof(ffado_jack_settings_t));
-
+ memcpy (&driver->settings, params, sizeof(ffado_jack_settings_t));
+
/* prepare all parameters */
driver->sample_rate = params->sample_rate;
driver->period_size = params->period_size;
driver->last_wait_ust = 0;
-
+
driver->period_usecs =
- (jack_time_t) floor ((((float) driver->period_size) * 1000000.0f) / driver->sample_rate);
+ (jack_time_t)floor ((((float)driver->period_size) * 1000000.0f) / driver->sample_rate);
driver->client = client;
driver->engine = NULL;
- jack_set_latency_callback (client, ffado_latency_callback, driver);
+ jack_set_latency_callback (client, ffado_latency_callback, driver);
- memset(&driver->device_options,0,sizeof(driver->device_options));
- driver->device_options.sample_rate=params->sample_rate;
- driver->device_options.period_size=params->period_size;
- driver->device_options.nb_buffers=params->buffer_size;
+ memset (&driver->device_options, 0, sizeof(driver->device_options));
+ driver->device_options.sample_rate = params->sample_rate;
+ driver->device_options.period_size = params->period_size;
+ driver->device_options.nb_buffers = params->buffer_size;
driver->capture_frame_latency = params->capture_frame_latency;
driver->playback_frame_latency = params->playback_frame_latency;
- driver->device_options.slave_mode=params->slave_mode;
- driver->device_options.snoop_mode=params->snoop_mode;
- driver->device_options.verbose=params->verbose_level;
-
- driver->device_info.nb_device_spec_strings=1;
- driver->device_info.device_spec_strings=calloc(1, sizeof(char *));
- driver->device_info.device_spec_strings[0]=strdup(params->device_info);
-
- debugPrint(DEBUG_LEVEL_STARTUP, " Driver compiled on %s %s for FFADO %s (API version %d)",
- __DATE__, __TIME__, ffado_get_version(), ffado_get_api_version());
- debugPrint(DEBUG_LEVEL_STARTUP, " Created driver %s", name);
- debugPrint(DEBUG_LEVEL_STARTUP, " period_size: %d", driver->period_size);
- debugPrint(DEBUG_LEVEL_STARTUP, " period_usecs: %d", driver->period_usecs);
- debugPrint(DEBUG_LEVEL_STARTUP, " sample rate: %d", driver->sample_rate);
-
- return (ffado_driver_t *) driver;
+ driver->device_options.slave_mode = params->slave_mode;
+ driver->device_options.snoop_mode = params->snoop_mode;
+ driver->device_options.verbose = params->verbose_level;
+
+ driver->device_info.nb_device_spec_strings = 1;
+ driver->device_info.device_spec_strings = calloc (1, sizeof(char *));
+ driver->device_info.device_spec_strings[0] = strdup (params->device_info);
+
+ debugPrint (DEBUG_LEVEL_STARTUP, " Driver compiled on %s %s for FFADO %s (API version %d)",
+ __DATE__, __TIME__, ffado_get_version (), ffado_get_api_version ());
+ debugPrint (DEBUG_LEVEL_STARTUP, " Created driver %s", name);
+ debugPrint (DEBUG_LEVEL_STARTUP, " period_size: %d", driver->period_size);
+ debugPrint (DEBUG_LEVEL_STARTUP, " period_usecs: %d", driver->period_usecs);
+ debugPrint (DEBUG_LEVEL_STARTUP, " sample rate: %d", driver->sample_rate);
+
+ return (ffado_driver_t*)driver;
}
@@ -841,10 +843,10 @@ static void
ffado_driver_delete (ffado_driver_t *driver)
{
unsigned int i;
- jack_driver_nt_finish ((jack_driver_nt_t *) driver);
- for (i=0; i < driver->device_info.nb_device_spec_strings; i++) {
+
+ jack_driver_nt_finish ((jack_driver_nt_t*)driver);
+ for (i = 0; i < driver->device_info.nb_device_spec_strings; i++)
free (driver->device_info.device_spec_strings[i]);
- }
free (driver->device_info.device_spec_strings);
free (driver);
}
@@ -862,12 +864,12 @@ driver_get_descriptor ()
jack_driver_param_desc_t * params;
unsigned int i;
- desc = calloc (1, sizeof (jack_driver_desc_t));
+ desc = calloc (1, sizeof(jack_driver_desc_t));
strcpy (desc->name, "firewire");
desc->nparams = 11;
-
- params = calloc (desc->nparams, sizeof (jack_driver_param_desc_t));
+
+ params = calloc (desc->nparams, sizeof(jack_driver_param_desc_t));
desc->params = params;
i = 0;
@@ -877,7 +879,7 @@ driver_get_descriptor ()
strcpy (params[i].value.str, "hw:0");
strcpy (params[i].short_desc, "The FireWire device to use.");
strcpy (params[i].long_desc, "The FireWire device to use. Please consult the FFADO documentation for more info.");
-
+
i++;
strcpy (params[i].name, "period");
params[i].character = 'p';
@@ -885,7 +887,7 @@ driver_get_descriptor ()
params[i].value.ui = 1024;
strcpy (params[i].short_desc, "Frames per period");
strcpy (params[i].long_desc, params[i].short_desc);
-
+
i++;
strcpy (params[i].name, "nperiods");
params[i].character = 'n';
@@ -949,7 +951,7 @@ driver_get_descriptor ()
params[i].value.ui = 0U;
strcpy (params[i].short_desc, "Operate in snoop mode");
strcpy (params[i].long_desc, params[i].short_desc);
-
+
i++;
strcpy (params[i].name, "verbose");
params[i].character = 'v';
@@ -972,30 +974,28 @@ driver_initialize (jack_client_t *client, JSList * params)
ffado_jack_settings_t cmlparams;
- char *device_name="hw:0";
+ char *device_name = "hw:0";
- cmlparams.period_size_set=0;
- cmlparams.sample_rate_set=0;
- cmlparams.buffer_size_set=0;
+ cmlparams.period_size_set = 0;
+ cmlparams.sample_rate_set = 0;
+ cmlparams.buffer_size_set = 0;
/* default values */
- cmlparams.period_size=1024;
- cmlparams.sample_rate=48000;
- cmlparams.buffer_size=3;
- cmlparams.playback_ports=1;
- cmlparams.capture_ports=1;
- cmlparams.playback_frame_latency=0;
- cmlparams.capture_frame_latency=0;
- cmlparams.slave_mode=0;
- cmlparams.snoop_mode=0;
- cmlparams.verbose_level=0;
-
- for (node = params; node; node = jack_slist_next (node))
- {
- param = (jack_driver_param_t *) node->data;
-
- switch (param->character)
- {
+ cmlparams.period_size = 1024;
+ cmlparams.sample_rate = 48000;
+ cmlparams.buffer_size = 3;
+ cmlparams.playback_ports = 1;
+ cmlparams.capture_ports = 1;
+ cmlparams.playback_frame_latency = 0;
+ cmlparams.capture_frame_latency = 0;
+ cmlparams.slave_mode = 0;
+ cmlparams.snoop_mode = 0;
+ cmlparams.verbose_level = 0;
+
+ for (node = params; node; node = jack_slist_next (node)) {
+ param = (jack_driver_param_t*)node->data;
+
+ switch (param->character) {
case 'd':
device_name = strdup (param->value.str);
break;
@@ -1035,10 +1035,10 @@ driver_initialize (jack_client_t *client, JSList * params)
}
}
- // temporary
- cmlparams.device_info = device_name;
+ // temporary
+ cmlparams.device_info = device_name;
- driver=(jack_driver_t *)ffado_driver_new (client, "ffado_pcm", &cmlparams);
+ driver = (jack_driver_t*)ffado_driver_new (client, "ffado_pcm", &cmlparams);
return driver;
}
@@ -1046,11 +1046,13 @@ driver_initialize (jack_client_t *client, JSList * params)
void
driver_finish (jack_driver_t *driver)
{
- ffado_driver_t *drv=(ffado_driver_t *) driver;
+ ffado_driver_t *drv = (ffado_driver_t*)driver;
+
// If jack hasn't called the detach method, do it now. As of jack 0.101.1
- // the detach method was not being called explicitly on closedown, and
+ // the detach method was not being called explicitly on closedown, and
// we need it to at least deallocate the iso resources.
- if (drv->dev != NULL)
- ffado_driver_detach(drv);
+ if (drv->dev != NULL) {
+ ffado_driver_detach (drv);
+ }
ffado_driver_delete (drv);
}
diff --git a/drivers/firewire/ffado_driver.h b/drivers/firewire/ffado_driver.h
index f26234a..2201f9f 100644
--- a/drivers/firewire/ffado_driver.h
+++ b/drivers/firewire/ffado_driver.h
@@ -23,11 +23,11 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-/*
+/*
* Main Jack driver entry routines
*
- */
-
+ */
+
#ifndef __JACK_FFADO_DRIVER_H__
#define __JACK_FFADO_DRIVER_H__
@@ -59,53 +59,53 @@
#include "../alsa_midi/midi_unpack.h"
// debug print control flags
-#define DEBUG_LEVEL_BUFFERS (1<<0)
-#define DEBUG_LEVEL_HANDLERS (1<<1)
-#define DEBUG_LEVEL_XRUN_RECOVERY (1<<2)
-#define DEBUG_LEVEL_WAIT (1<<3)
+#define DEBUG_LEVEL_BUFFERS (1 << 0)
+#define DEBUG_LEVEL_HANDLERS (1 << 1)
+#define DEBUG_LEVEL_XRUN_RECOVERY (1 << 2)
+#define DEBUG_LEVEL_WAIT (1 << 3)
-#define DEBUG_LEVEL_RUN_CYCLE (1<<8)
+#define DEBUG_LEVEL_RUN_CYCLE (1 << 8)
-#define DEBUG_LEVEL_PACKETCOUNTER (1<<16)
-#define DEBUG_LEVEL_STARTUP (1<<17)
-#define DEBUG_LEVEL_THREADS (1<<18)
+#define DEBUG_LEVEL_PACKETCOUNTER (1 << 16)
+#define DEBUG_LEVEL_STARTUP (1 << 17)
+#define DEBUG_LEVEL_THREADS (1 << 18)
//#define DEBUG_ENABLED
#ifdef DEBUG_ENABLED
- // default debug level
+// default debug level
#define DEBUG_LEVEL ( DEBUG_LEVEL_RUN_CYCLE | \
- (DEBUG_LEVEL_XRUN_RECOVERY)| DEBUG_LEVEL_STARTUP | DEBUG_LEVEL_WAIT | DEBUG_LEVEL_PACKETCOUNTER)
+ (DEBUG_LEVEL_XRUN_RECOVERY) | DEBUG_LEVEL_STARTUP | DEBUG_LEVEL_WAIT | DEBUG_LEVEL_PACKETCOUNTER)
#warning Building debug build!
- #define printMessage(format, args...) jack_error( "firewire MSG: %s:%d (%s): " format, __FILE__, __LINE__, __FUNCTION__, ##args )
- #define printError(format, args...) jack_error( "firewire ERR: %s:%d (%s): " format, __FILE__, __LINE__, __FUNCTION__, ##args )
-
- #define printEnter() jack_error( "FWDRV ENTERS: %s (%s)\n", __FUNCTION__, __FILE__)
- #define printExit() jack_error( "FWDRV EXITS: %s (%s)\n", __FUNCTION__, __FILE__)
- #define printEnter()
- #define printExit()
-
- #define debugError(format, args...) jack_error( "firewire ERR: %s:%d (%s): " format, __FILE__, __LINE__, __FUNCTION__, ##args )
- #define debugPrint(Level, format, args...) if(DEBUG_LEVEL & (Level)) jack_error("DEBUG %s:%d (%s) :" format, __FILE__, __LINE__, __FUNCTION__, ##args );
- #define debugPrintShort(Level, format, args...) if(DEBUG_LEVEL & (Level)) jack_error( format,##args );
- #define debugPrintWithTimeStamp(Level, format, args...) if(DEBUG_LEVEL & (Level)) jack_error( "%16lu: "format, debugGetCurrentUTime(),##args );
- #define SEGFAULT int *test=NULL; *test=1;
+ #define printMessage(format, args ...) jack_error ( "firewire MSG: %s:%d (%s): " format, __FILE__, __LINE__, __FUNCTION__, ## args )
+ #define printError(format, args ...) jack_error ( "firewire ERR: %s:%d (%s): " format, __FILE__, __LINE__, __FUNCTION__, ## args )
+
+ #define printEnter() jack_error ( "FWDRV ENTERS: %s (%s)\n", __FUNCTION__, __FILE__)
+ #define printExit() jack_error ( "FWDRV EXITS: %s (%s)\n", __FUNCTION__, __FILE__)
+ #define printEnter()
+ #define printExit()
+
+ #define debugError(format, args ...) jack_error ( "firewire ERR: %s:%d (%s): " format, __FILE__, __LINE__, __FUNCTION__, ## args )
+ #define debugPrint(Level, format, args ...) if (DEBUG_LEVEL & (Level)) { jack_error ("DEBUG %s:%d (%s) :" format, __FILE__, __LINE__, __FUNCTION__, ## args ); }
+ #define debugPrintShort(Level, format, args ...) if (DEBUG_LEVEL & (Level)) { jack_error ( format, ## args ); }
+ #define debugPrintWithTimeStamp(Level, format, args ...) if (DEBUG_LEVEL & (Level)) { jack_error ( "%16lu: "format, debugGetCurrentUTime (), ## args ); }
+ #define SEGFAULT int *test = NULL; *test = 1;
#else
#define DEBUG_LEVEL
-
- #define printMessage(format, args...) if(g_verbose) \
- jack_error("firewire MSG: " format, ##args )
- #define printError(format, args...) jack_error("firewire ERR: " format, ##args )
-
- #define printEnter()
- #define printExit()
-
- #define debugError(format, args...)
- #define debugPrint(Level, format, args...)
- #define debugPrintShort(Level, format, args...)
- #define debugPrintWithTimeStamp(Level, format, args...)
+
+ #define printMessage(format, args ...) if (g_verbose) \
+ jack_error ("firewire MSG: " format, ## args )
+ #define printError(format, args ...) jack_error ("firewire ERR: " format, ## args )
+
+ #define printEnter()
+ #define printExit()
+
+ #define debugError(format, args ...)
+ #define debugPrint(Level, format, args ...)
+ #define debugPrintShort(Level, format, args ...)
+ #define debugPrintWithTimeStamp(Level, format, args ...)
#endif
typedef struct _ffado_driver ffado_driver_t;
@@ -116,39 +116,37 @@ typedef struct _ffado_driver ffado_driver_t;
typedef struct _ffado_jack_settings ffado_jack_settings_t;
struct _ffado_jack_settings {
- int verbose_level;
-
- int period_size_set;
- jack_nframes_t period_size;
-
- int sample_rate_set;
- int sample_rate;
-
- int buffer_size_set;
- jack_nframes_t buffer_size;
-
- int playback_ports;
- int capture_ports;
-
- jack_nframes_t capture_frame_latency;
- jack_nframes_t playback_frame_latency;
-
- int slave_mode;
- int snoop_mode;
-
- char *device_info;
+ int verbose_level;
+
+ int period_size_set;
+ jack_nframes_t period_size;
+
+ int sample_rate_set;
+ int sample_rate;
+
+ int buffer_size_set;
+ jack_nframes_t buffer_size;
+
+ int playback_ports;
+ int capture_ports;
+
+ jack_nframes_t capture_frame_latency;
+ jack_nframes_t playback_frame_latency;
+
+ int slave_mode;
+ int snoop_mode;
+
+ char *device_info;
};
-typedef struct _ffado_capture_channel
-{
+typedef struct _ffado_capture_channel {
ffado_streaming_stream_type stream_type;
midi_unpack_t midi_unpack;
uint32_t *midi_buffer;
} ffado_capture_channel_t;
#define MIDI_OVERFLOW_BUFFER_SIZE 4
-typedef struct _ffado_playback_channel
-{
+typedef struct _ffado_playback_channel {
ffado_streaming_stream_type stream_type;
midi_pack_t midi_pack;
uint32_t *midi_buffer;
@@ -161,50 +159,49 @@ typedef struct _ffado_playback_channel
/*
* JACK driver structure
*/
-struct _ffado_driver
-{
+struct _ffado_driver {
JACK_DRIVER_NT_DECL;
-
- jack_nframes_t sample_rate;
- jack_nframes_t period_size;
- unsigned long wait_time;
- jack_time_t wait_last;
- jack_time_t wait_next;
+ jack_nframes_t sample_rate;
+ jack_nframes_t period_size;
+ unsigned long wait_time;
+
+ jack_time_t wait_last;
+ jack_time_t wait_next;
int wait_late;
-
+
jack_client_t *client;
-
- int xrun_detected;
- int xrun_count;
-
+
+ int xrun_detected;
+ int xrun_count;
+
int process_count;
-
+
/* settings from the command line */
ffado_jack_settings_t settings;
-
+
/* the firewire virtual device */
ffado_device_t *dev;
ffado_sample_t *nullbuffer;
ffado_sample_t *scratchbuffer;
- JSList *capture_ports;
- JSList *playback_ports;
- JSList *monitor_ports;
- channel_t playback_nchannels;
- channel_t capture_nchannels;
+ JSList *capture_ports;
+ JSList *playback_ports;
+ JSList *monitor_ports;
+ channel_t playback_nchannels;
+ channel_t capture_nchannels;
ffado_playback_channel_t *playback_channels;
ffado_capture_channel_t *capture_channels;
- jack_nframes_t playback_frame_latency;
- jack_nframes_t capture_frame_latency;
-
+ jack_nframes_t playback_frame_latency;
+ jack_nframes_t capture_frame_latency;
+
ffado_device_info_t device_info;
ffado_options_t device_options;
-};
+};
diff --git a/drivers/freebob/freebob_driver.c b/drivers/freebob/freebob_driver.c
index 81ab446..d26e6dd 100644
--- a/drivers/freebob/freebob_driver.c
+++ b/drivers/freebob/freebob_driver.c
@@ -22,10 +22,10 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-/*
+/*
* Main Jack driver entry routines
*
- */
+ */
#include <math.h>
#include <stdio.h>
@@ -49,17 +49,17 @@
#define SAMPLE_MAX_24BIT 8388608.0f
#define SAMPLE_MAX_16BIT 32768.0f
-static int freebob_driver_stop (freebob_driver_t *driver);
+static int freebob_driver_stop(freebob_driver_t *driver);
#ifdef FREEBOB_DRIVER_WITH_ALSA_MIDI
- static freebob_driver_midi_handle_t *freebob_driver_midi_init(freebob_driver_t *driver);
- static void freebob_driver_midi_finish (freebob_driver_midi_handle_t *m);
- static int freebob_driver_midi_start (freebob_driver_midi_handle_t *m);
- static int freebob_driver_midi_stop (freebob_driver_midi_handle_t *m);
+static freebob_driver_midi_handle_t *freebob_driver_midi_init(freebob_driver_t *driver);
+static void freebob_driver_midi_finish(freebob_driver_midi_handle_t *m);
+static int freebob_driver_midi_start(freebob_driver_midi_handle_t *m);
+static int freebob_driver_midi_stop(freebob_driver_midi_handle_t *m);
#endif
// enable verbose messages
-static int g_verbose=0;
+static int g_verbose = 0;
static int
freebob_driver_attach (freebob_driver_t *driver)
@@ -68,13 +68,13 @@ freebob_driver_attach (freebob_driver_t *driver)
char buf2[64];
channel_t chn;
- jack_port_t *port=NULL;
+ jack_port_t *port = NULL;
int port_flags;
- int error=0;
+ int error = 0;
jack_latency_range_t range;
- g_verbose=driver->engine->verbose;
- driver->device_options.verbose=g_verbose;
+ g_verbose = driver->engine->verbose;
+ driver->device_options.verbose = g_verbose;
if (driver->engine->set_buffer_size (driver->engine, driver->period_size)) {
jack_error ("FREEBOB: cannot set engine buffer size to %d (check MIDI)", driver->period_size);
@@ -83,63 +83,65 @@ freebob_driver_attach (freebob_driver_t *driver)
driver->engine->set_sample_rate (driver->engine, driver->sample_rate);
/* packetizer thread options */
- driver->device_options.realtime=(driver->engine->control->real_time? 1 : 0);
-
- driver->device_options.packetizer_priority=driver->engine->control->client_priority +
- FREEBOB_RT_PRIORITY_PACKETIZER_RELATIVE;
- if (driver->device_options.packetizer_priority>98) {
- driver->device_options.packetizer_priority=98;
+ driver->device_options.realtime = (driver->engine->control->real_time ? 1 : 0);
+
+ driver->device_options.packetizer_priority = driver->engine->control->client_priority +
+ FREEBOB_RT_PRIORITY_PACKETIZER_RELATIVE;
+ if (driver->device_options.packetizer_priority > 98) {
+ driver->device_options.packetizer_priority = 98;
}
- driver->dev=freebob_streaming_init(&driver->device_info,driver->device_options);
+ driver->dev = freebob_streaming_init (&driver->device_info, driver->device_options);
- if(!driver->dev) {
- printError("FREEBOB: Error creating virtual device");
+ if (!driver->dev) {
+ printError ("FREEBOB: Error creating virtual device");
return -1;
}
#ifdef FREEBOB_DRIVER_WITH_ALSA_MIDI
- driver->midi_handle=freebob_driver_midi_init(driver);
- if(!driver->midi_handle) {
- printError("-----------------------------------------------------------");
- printError("Error creating midi device!");
- printError("FreeBob will run without MIDI support.");
- printError("Consult the above error messages to solve the problem. ");
- printError("-----------------------------------------------------------\n\n");
+ driver->midi_handle = freebob_driver_midi_init (driver);
+ if (!driver->midi_handle) {
+ printError ("-----------------------------------------------------------");
+ printError ("Error creating midi device!");
+ printError ("FreeBob will run without MIDI support.");
+ printError ("Consult the above error messages to solve the problem. ");
+ printError ("-----------------------------------------------------------\n\n");
}
#endif
if (driver->device_options.realtime) {
- printMessage("Streaming thread running with Realtime scheduling, priority %d",
- driver->device_options.packetizer_priority);
+ printMessage ("Streaming thread running with Realtime scheduling, priority %d",
+ driver->device_options.packetizer_priority);
} else {
- printMessage("Streaming thread running without Realtime scheduling");
+ printMessage ("Streaming thread running without Realtime scheduling");
}
/* ports */
- port_flags = JackPortIsOutput|JackPortIsPhysical|JackPortIsTerminal;
+ port_flags = JackPortIsOutput | JackPortIsPhysical | JackPortIsTerminal;
- driver->capture_nchannels=freebob_streaming_get_nb_capture_streams(driver->dev);
+ driver->capture_nchannels = freebob_streaming_get_nb_capture_streams (driver->dev);
#ifdef FREEBOB_DRIVER_WITH_JACK_MIDI
// allocate midi structures
- driver->midi_in_ports=calloc(driver->capture_nchannels, sizeof(freebob_midi_input_port_t));
- if (driver->midi_in_ports == NULL) return -ENOMEM;
+ driver->midi_in_ports = calloc (driver->capture_nchannels, sizeof(freebob_midi_input_port_t));
+ if (driver->midi_in_ports == NULL) {
+ return -ENOMEM;
+ }
#endif
for (chn = 0; chn < driver->capture_nchannels; chn++) {
- error=0;
+ error = 0;
- freebob_streaming_get_capture_stream_name(driver->dev, chn, buf, sizeof(buf) - 1);
- switch(freebob_streaming_get_capture_stream_type(driver->dev, chn)) {
+ freebob_streaming_get_capture_stream_name (driver->dev, chn, buf, sizeof(buf) - 1);
+ switch (freebob_streaming_get_capture_stream_type (driver->dev, chn)) {
case freebob_stream_type_audio:
- snprintf(buf2, 64, "C%d_%s",(int)chn,buf); // needed to avoid duplicate names
+ snprintf (buf2, 64, "C%d_%s", (int)chn, buf); // needed to avoid duplicate names
printMessage ("Registering audio capture port %s", buf2);
if ((port = jack_port_register (driver->client, buf2,
JACK_DEFAULT_AUDIO_TYPE,
port_flags, 0)) == NULL) {
printError (" cannot register port for %s", buf2);
- error=1;
+ error = 1;
break;
}
driver->capture_ports =
@@ -148,18 +150,18 @@ freebob_driver_attach (freebob_driver_t *driver)
#ifdef FREEBOB_DRIVER_WITH_JACK_MIDI
case freebob_stream_type_midi:
- snprintf(buf2, 64, "CM%d_%s",(int)chn,buf); // needed to avoid duplicate names
+ snprintf (buf2, 64, "CM%d_%s", (int)chn, buf); // needed to avoid duplicate names
printMessage ("Registering midi capture port %s", buf2);
if ((port = jack_port_register (driver->client, buf2,
JACK_DEFAULT_MIDI_TYPE,
port_flags, 0)) == NULL) {
printError (" cannot register port for %s", buf2);
- error=1;
+ error = 1;
break;
}
// init the midi unpacker for this port
- midi_unpack_init(&driver->midi_in_ports[chn].unpack);
+ midi_unpack_init (&driver->midi_in_ports[chn].unpack);
driver->capture_ports =
jack_slist_append (driver->capture_ports, port);
@@ -174,36 +176,40 @@ freebob_driver_attach (freebob_driver_t *driver)
break;
}
- if(error) break;
+ if (error) {
+ break;
+ }
range.min = range.max = driver->period_size + driver->capture_frame_latency;
jack_port_set_latency_range (port, JackCaptureLatency, &range);
}
-
- port_flags = JackPortIsInput|JackPortIsPhysical|JackPortIsTerminal;
- driver->playback_nchannels=freebob_streaming_get_nb_playback_streams(driver->dev);
+ port_flags = JackPortIsInput | JackPortIsPhysical | JackPortIsTerminal;
+
+ driver->playback_nchannels = freebob_streaming_get_nb_playback_streams (driver->dev);
#ifdef FREEBOB_DRIVER_WITH_JACK_MIDI
// allocate midi structures
- driver->midi_out_ports=calloc(driver->playback_nchannels, sizeof(freebob_midi_output_port_t));
- if (driver->midi_out_ports == NULL) return -ENOMEM;
+ driver->midi_out_ports = calloc (driver->playback_nchannels, sizeof(freebob_midi_output_port_t));
+ if (driver->midi_out_ports == NULL) {
+ return -ENOMEM;
+ }
#endif
for (chn = 0; chn < driver->playback_nchannels; chn++) {
- error=0;
+ error = 0;
- freebob_streaming_get_playback_stream_name(driver->dev, chn, buf, sizeof(buf) - 1);
-
- switch(freebob_streaming_get_playback_stream_type(driver->dev, chn)){
+ freebob_streaming_get_playback_stream_name (driver->dev, chn, buf, sizeof(buf) - 1);
+
+ switch (freebob_streaming_get_playback_stream_type (driver->dev, chn)) {
case freebob_stream_type_audio:
- snprintf(buf2, 64, "P%d_%s",(int)chn,buf); // needed to avoid duplicate names
+ snprintf (buf2, 64, "P%d_%s", (int)chn, buf); // needed to avoid duplicate names
printMessage ("Registering playback audio port %s", buf2);
if ((port = jack_port_register (driver->client, buf2,
JACK_DEFAULT_AUDIO_TYPE,
port_flags, 0)) == NULL) {
- printError(" cannot register port for %s", buf2);
- error=1;
+ printError (" cannot register port for %s", buf2);
+ error = 1;
break;
}
driver->playback_ports =
@@ -211,13 +217,13 @@ freebob_driver_attach (freebob_driver_t *driver)
break;
#ifdef FREEBOB_DRIVER_WITH_JACK_MIDI
case freebob_stream_type_midi:
- snprintf(buf2, 64, "PM%d_%s",(int)chn,buf); // needed to avoid duplicate names
+ snprintf (buf2, 64, "PM%d_%s", (int)chn, buf); // needed to avoid duplicate names
printMessage ("Registering playback midi port %s", buf2);
if ((port = jack_port_register (driver->client, buf2,
JACK_DEFAULT_MIDI_TYPE,
port_flags, 0)) == NULL) {
- printError(" cannot register port for %s", buf2);
- error=1;
+ printError (" cannot register port for %s", buf2);
+ error = 1;
break;
}
@@ -232,7 +238,9 @@ freebob_driver_attach (freebob_driver_t *driver)
jack_slist_append (driver->playback_ports, NULL);
}
- if(error) break;
+ if (error) {
+ break;
+ }
range.min = range.max = (driver->period_size * (driver->device_options.nb_buffers - 1)) + driver->playback_frame_latency;
jack_port_set_latency_range (port, JackPlaybackLatency, &range);
@@ -252,39 +260,39 @@ freebob_driver_detach (freebob_driver_t *driver)
for (node = driver->capture_ports; node && node->data;
node = jack_slist_next (node)) {
- if(node->data != NULL) {
+ if (node->data != NULL) {
jack_port_unregister (driver->client,
- ((jack_port_t *) node->data));
+ ((jack_port_t*)node->data));
}
}
jack_slist_free (driver->capture_ports);
driver->capture_ports = 0;
-
+
for (node = driver->playback_ports; node && node->data;
node = jack_slist_next (node)) {
- if(node->data != NULL) {
+ if (node->data != NULL) {
jack_port_unregister (driver->client,
- ((jack_port_t *) node->data));
+ ((jack_port_t*)node->data));
}
}
jack_slist_free (driver->playback_ports);
driver->playback_ports = 0;
- freebob_streaming_finish(driver->dev);
- driver->dev=NULL;
+ freebob_streaming_finish (driver->dev);
+ driver->dev = NULL;
#ifdef FREEBOB_DRIVER_WITH_ALSA_MIDI
- if(driver->midi_handle) {
- freebob_driver_midi_finish(driver->midi_handle);
+ if (driver->midi_handle) {
+ freebob_driver_midi_finish (driver->midi_handle);
}
- driver->midi_handle=NULL;
+ driver->midi_handle = NULL;
#endif
#ifdef FREEBOB_DRIVER_WITH_JACK_MIDI
- free(driver->midi_in_ports);
- free(driver->midi_out_ports);
+ free (driver->midi_in_ports);
+ free (driver->midi_out_ports);
#endif
return 0;
}
@@ -296,66 +304,67 @@ freebob_driver_read (freebob_driver_t * driver, jack_nframes_t nframes)
channel_t chn;
JSList *node;
jack_port_t* port;
-
+
freebob_sample_t nullbuffer[nframes];
- void *addr_of_nullbuffer=(void *)nullbuffer;
+ void *addr_of_nullbuffer = (void*)nullbuffer;
freebob_streaming_stream_type stream_type;
-
- printEnter();
-
+
+ printEnter ();
+
for (chn = 0, node = driver->capture_ports; node; node = jack_slist_next (node), chn++) {
- stream_type = freebob_streaming_get_capture_stream_type(driver->dev, chn);
- if(stream_type == freebob_stream_type_audio) {
- port = (jack_port_t *) node->data;
+ stream_type = freebob_streaming_get_capture_stream_type (driver->dev, chn);
+ if (stream_type == freebob_stream_type_audio) {
+ port = (jack_port_t*)node->data;
buf = jack_port_get_buffer (port, nframes);
- if(!buf) buf=(jack_default_audio_sample_t *)addr_of_nullbuffer;
-
- freebob_streaming_set_capture_stream_buffer(
- driver->dev, chn, (char *)(buf), freebob_buffer_type_float);
+ if (!buf) {
+ buf = (jack_default_audio_sample_t*)addr_of_nullbuffer;
+ }
+
+ freebob_streaming_set_capture_stream_buffer (
+ driver->dev, chn, (char*)(buf), freebob_buffer_type_float);
#ifdef FREEBOB_DRIVER_WITH_JACK_MIDI
- } else if(stream_type == freebob_stream_type_midi) {
+ } else if (stream_type == freebob_stream_type_midi) {
unsigned int midibuff[64];
unsigned char midibuff2[64];
int samples_read;
- port = (jack_port_t *) node->data;
+ port = (jack_port_t*)node->data;
buf = jack_port_get_buffer (port, nframes);
- jack_midi_clear_buffer(buf);
+ jack_midi_clear_buffer (buf);
- samples_read=freebob_streaming_read(
+ samples_read = freebob_streaming_read (
driver->dev, chn, midibuff, 64);
- while(samples_read) {
+ while (samples_read) {
int idx;
int done;
//printMessage("MIDI: ");
- for (idx=0;idx<samples_read;idx++) {
- midibuff2[idx]=(unsigned char)(midibuff[idx] & 0xFF);
+ for (idx = 0; idx < samples_read; idx++)
+ midibuff2[idx] = (unsigned char)(midibuff[idx] & 0xFF);
//printMessage(" %02X", midibuff2[idx]);
- }
- done = midi_unpack_buf(
+ done = midi_unpack_buf (
&driver->midi_in_ports[chn].unpack,
midibuff2, samples_read, buf, 0 /* time */);
- samples_read=freebob_streaming_read(
+ samples_read = freebob_streaming_read (
driver->dev, chn, midibuff, 64);
}
#endif
} else { // empty other buffers without doing something with them
- freebob_streaming_set_capture_stream_buffer(driver->dev, chn, (char *)(nullbuffer), freebob_buffer_type_uint24);
+ freebob_streaming_set_capture_stream_buffer (driver->dev, chn, (char*)(nullbuffer), freebob_buffer_type_uint24);
}
}
// now transfer the buffers
- freebob_streaming_transfer_capture_buffers(driver->dev);
-
- printExit();
-
+ freebob_streaming_transfer_capture_buffers (driver->dev);
+
+ printExit ();
+
return 0;
}
@@ -373,93 +382,95 @@ freebob_driver_write (freebob_driver_t * driver, jack_nframes_t nframes)
freebob_sample_t nullbuffer[nframes];
void *addr_of_nullbuffer = (void*)nullbuffer;
- memset(&nullbuffer,0,nframes*sizeof(freebob_sample_t));
+ memset (&nullbuffer, 0, nframes * sizeof(freebob_sample_t));
- printEnter();
+ printEnter ();
driver->process_count++;
- assert(driver->dev);
+ assert (driver->dev);
- if (driver->engine->freewheeling) {
- return 0;
- }
+ if (driver->engine->freewheeling) {
+ return 0;
+ }
for (chn = 0, node = driver->playback_ports; node; node = jack_slist_next (node), chn++) {
- stream_type=freebob_streaming_get_playback_stream_type(driver->dev, chn);
- if(stream_type == freebob_stream_type_audio) {
- port = (jack_port_t *) node->data;
+ stream_type = freebob_streaming_get_playback_stream_type (driver->dev, chn);
+ if (stream_type == freebob_stream_type_audio) {
+ port = (jack_port_t*)node->data;
buf = jack_port_get_buffer (port, nframes);
- if(!buf) buf=(jack_default_audio_sample_t*)addr_of_nullbuffer;
-
- freebob_streaming_set_playback_stream_buffer(driver->dev, chn, (char *)(buf), freebob_buffer_type_float);
+ if (!buf) {
+ buf = (jack_default_audio_sample_t*)addr_of_nullbuffer;
+ }
+
+ freebob_streaming_set_playback_stream_buffer (driver->dev, chn, (char*)(buf), freebob_buffer_type_float);
#ifdef FREEBOB_DRIVER_WITH_JACK_MIDI
- } else if(stream_type == freebob_stream_type_midi) {
- int i,idx;
+ } else if (stream_type == freebob_stream_type_midi) {
+ int i, idx;
int samples_written;
- port = (jack_port_t *) node->data;
+ port = (jack_port_t*)node->data;
buf = jack_port_get_buffer (port, nframes);
- int nevents = jack_midi_get_event_count(buf);
+ int nevents = jack_midi_get_event_count (buf);
- if (nevents)
- printMessage("jack_out: %d events\n", nevents);
- for (i=0; i<nevents; ++i) {
+ if (nevents) {
+ printMessage ("jack_out: %d events\n", nevents);
+ }
+ for (i = 0; i < nevents; ++i) {
jack_midi_event_t event;
-
- jack_midi_event_get(&event, buf, i);
-
- midi_pack_event(&driver->midi_out_ports[chn].packer, &event);
+
+ jack_midi_event_get (&event, buf, i);
+
+ midi_pack_event (&driver->midi_out_ports[chn].packer, &event);
freebob_sample_t midibuff[event.size];
- for (idx=0;idx<event.size;idx++) {
- midibuff[idx]=(freebob_sample_t)(event.buffer[idx]);
- }
+ for (idx = 0; idx < event.size; idx++)
+ midibuff[idx] = (freebob_sample_t)(event.buffer[idx]);
- samples_written=freebob_streaming_write(
+ samples_written = freebob_streaming_write (
driver->dev, chn, midibuff, event.size);
- if (samples_written!=event.size) {
- printMessage("midi out: buffer overrun\n");
+ if (samples_written != event.size) {
+ printMessage ("midi out: buffer overrun\n");
break;
} else {
- printMessage("midi out: sent %d-byte event at %ld\n", (int)event.size, (long)event.time);
+ printMessage ("midi out: sent %d-byte event at %ld\n", (int)event.size, (long)event.time);
}
}
#endif
} else { // empty other buffers without doing something with them
- freebob_streaming_set_playback_stream_buffer(driver->dev, chn, (char *)(nullbuffer), freebob_buffer_type_uint24);
+ freebob_streaming_set_playback_stream_buffer (driver->dev, chn, (char*)(nullbuffer), freebob_buffer_type_uint24);
}
}
- freebob_streaming_transfer_playback_buffers(driver->dev);
+ freebob_streaming_transfer_playback_buffers (driver->dev);
+
+ printExit ();
- printExit();
-
return 0;
}
-//static inline jack_nframes_t
-static jack_nframes_t
+//static inline jack_nframes_t
+static jack_nframes_t
freebob_driver_wait (freebob_driver_t *driver, int extra_fd, int *status,
- float *delayed_usecs)
+ float *delayed_usecs)
{
int nframes;
- jack_time_t wait_enter;
- jack_time_t wait_ret;
-
- printEnter();
+ jack_time_t wait_enter;
+ jack_time_t wait_ret;
+
+ printEnter ();
wait_enter = driver->engine->get_microseconds ();
if (wait_enter > driver->wait_next) {
/*
- * This processing cycle was delayed past the
- * next due interrupt! Do not account this as
- * a wakeup delay:
- */
+ * This processing cycle was delayed past the
+ * next due interrupt! Do not account this as
+ * a wakeup delay:
+ */
driver->wait_next = 0;
driver->wait_late++;
}
@@ -467,24 +478,24 @@ freebob_driver_wait (freebob_driver_t *driver, int extra_fd, int *status,
// *status = -3; timeout
// *status = -4; extra FD
- nframes=freebob_streaming_wait(driver->dev);
-
+ nframes = freebob_streaming_wait (driver->dev);
+
wait_ret = driver->engine->get_microseconds ();
-
+
if (driver->wait_next && wait_ret > driver->wait_next) {
*delayed_usecs = wait_ret - driver->wait_next;
}
driver->wait_last = wait_ret;
driver->wait_next = wait_ret + driver->period_usecs;
driver->engine->transport_cycle_start (driver->engine, wait_ret);
-
+
// transfer the streaming buffers
// we now do this in the read/write functions
-// freebob_streaming_transfer_buffers(driver->dev);
-
+// freebob_streaming_transfer_buffers(driver->dev);
+
if (nframes < 0) {
- *status=0;
-
+ *status = 0;
+
return 0;
//nframes=driver->period_size; //debug
}
@@ -494,53 +505,52 @@ freebob_driver_wait (freebob_driver_t *driver, int extra_fd, int *status,
// FIXME: this should do something more usefull
*delayed_usecs = 0;
-
- printExit();
+
+ printExit ();
return nframes - nframes % driver->period_size;
-
+
}
static int
freebob_driver_run_cycle (freebob_driver_t *driver)
{
jack_engine_t *engine = driver->engine;
- int wait_status=0;
- float delayed_usecs=0.0;
+ int wait_status = 0;
+ float delayed_usecs = 0.0;
jack_nframes_t nframes = freebob_driver_wait (driver, -1, &wait_status,
- &delayed_usecs);
-
+ &delayed_usecs);
+
if ((wait_status < 0)) {
- printError( "wait status < 0! (= %d)",wait_status);
+ printError ( "wait status < 0! (= %d)", wait_status);
return -1;
}
-
+
if ((nframes == 0)) {
int chn;
- chn=0; // avoid unused variable warning when compiling without jack midi
+ chn = 0; // avoid unused variable warning when compiling without jack midi
/* we detected an xrun and restarted: notify
* clients about the delay. */
- printMessage("xrun detected");
+ printMessage ("xrun detected");
engine->delay (engine, delayed_usecs);
// reset the midi stuff
#ifdef FREEBOB_DRIVER_WITH_JACK_MIDI
- for (chn = 0; chn < driver->capture_nchannels; chn++) {
- // init the midi unpacker for this port
- midi_unpack_reset(&driver->midi_in_ports[chn].unpack);
- }
-
- for (chn = 0; chn < driver->playback_nchannels; chn++) {
- // init the midi unpacker for this port
- midi_pack_reset(&driver->midi_out_ports[chn].packer);
- }
+ for (chn = 0; chn < driver->capture_nchannels; chn++)
+ // init the midi unpacker for this port
+ midi_unpack_reset (&driver->midi_in_ports[chn].unpack);
+
+ for (chn = 0; chn < driver->playback_nchannels; chn++)
+ // init the midi unpacker for this port
+ midi_pack_reset (&driver->midi_out_ports[chn].packer);
+
#endif
return 0;
- }
-
+ }
+
return engine->run_cycle (engine, nframes, delayed_usecs);
}
@@ -557,90 +567,90 @@ freebob_driver_null_cycle (freebob_driver_t* driver, jack_nframes_t nframes)
freebob_streaming_stream_type stream_type;
jack_default_audio_sample_t buff[nframes];
- jack_default_audio_sample_t* buffer=(jack_default_audio_sample_t*)buff;
-
- printEnter();
+ jack_default_audio_sample_t* buffer = (jack_default_audio_sample_t*)buff;
- memset(buffer,0,nframes*sizeof(jack_default_audio_sample_t));
-
- assert(driver->dev);
+ printEnter ();
- if (driver->engine->freewheeling) {
- return 0;
- }
+ memset (buffer, 0, nframes * sizeof(jack_default_audio_sample_t));
+
+ assert (driver->dev);
+
+ if (driver->engine->freewheeling) {
+ return 0;
+ }
// write silence to buffer
nwritten = 0;
for (chn = 0, node = driver->playback_ports; node; node = jack_slist_next (node), chn++) {
- stream_type=freebob_streaming_get_playback_stream_type(driver->dev, chn);
+ stream_type = freebob_streaming_get_playback_stream_type (driver->dev, chn);
- if(stream_type == freebob_stream_type_audio) {
- freebob_streaming_set_playback_stream_buffer(driver->dev, chn, (char *)(buffer), freebob_buffer_type_float);
+ if (stream_type == freebob_stream_type_audio) {
+ freebob_streaming_set_playback_stream_buffer (driver->dev, chn, (char*)(buffer), freebob_buffer_type_float);
- } else if(stream_type == freebob_stream_type_midi) {
+ } else if (stream_type == freebob_stream_type_midi) {
// these should be read/written with the per-stream functions
} else { // empty other buffers without doing something with them
- freebob_streaming_set_playback_stream_buffer(driver->dev, chn, (char *)(buffer), freebob_buffer_type_uint24);
+ freebob_streaming_set_playback_stream_buffer (driver->dev, chn, (char*)(buffer), freebob_buffer_type_uint24);
}
}
- freebob_streaming_transfer_playback_buffers(driver->dev);
-
+ freebob_streaming_transfer_playback_buffers (driver->dev);
+
// read & discard from input ports
for (chn = 0, node = driver->capture_ports; node; node = jack_slist_next (node), chn++) {
- stream_type=freebob_streaming_get_capture_stream_type(driver->dev, chn);
- if(stream_type == freebob_stream_type_audio) {
- freebob_streaming_set_capture_stream_buffer(driver->dev, chn, (char *)(buffer), freebob_buffer_type_float);
+ stream_type = freebob_streaming_get_capture_stream_type (driver->dev, chn);
+ if (stream_type == freebob_stream_type_audio) {
+ freebob_streaming_set_capture_stream_buffer (driver->dev, chn, (char*)(buffer), freebob_buffer_type_float);
- } else if(stream_type == freebob_stream_type_midi) {
+ } else if (stream_type == freebob_stream_type_midi) {
} else { // empty other buffers without doing something with them
}
}
// now transfer the buffers
- freebob_streaming_transfer_capture_buffers(driver->dev);
-
- printExit();
+ freebob_streaming_transfer_capture_buffers (driver->dev);
+
+ printExit ();
return 0;
}
static int
freebob_driver_start (freebob_driver_t *driver)
{
- int retval=0;
+ int retval = 0;
int chn;
- chn=0; // avoid unused variable warning when compiling without jack midi
+
+ chn = 0; // avoid unused variable warning when compiling without jack midi
#ifdef FREEBOB_DRIVER_WITH_ALSA_MIDI
- if(driver->midi_handle) {
- if((retval=freebob_driver_midi_start(driver->midi_handle))) {
- printError("Could not start MIDI threads");
+ if (driver->midi_handle) {
+ if ((retval = freebob_driver_midi_start (driver->midi_handle))) {
+ printError ("Could not start MIDI threads");
return retval;
}
}
-#endif
+#endif
// reset the midi stuff
#ifdef FREEBOB_DRIVER_WITH_JACK_MIDI
- for (chn = 0; chn < driver->capture_nchannels; chn++) {
+ for (chn = 0; chn < driver->capture_nchannels; chn++)
// init the midi unpacker for this port
- midi_unpack_reset(&driver->midi_in_ports[chn].unpack);
- }
-
- for (chn = 0; chn < driver->playback_nchannels; chn++) {
+ midi_unpack_reset (&driver->midi_in_ports[chn].unpack);
+
+ for (chn = 0; chn < driver->playback_nchannels; chn++)
// init the midi unpacker for this port
- midi_pack_reset(&driver->midi_out_ports[chn].packer);
- }
+ midi_pack_reset (&driver->midi_out_ports[chn].packer);
+
#endif
- if((retval=freebob_streaming_start(driver->dev))) {
- printError("Could not start streaming threads");
+ if ((retval = freebob_streaming_start (driver->dev))) {
+ printError ("Could not start streaming threads");
#ifdef FREEBOB_DRIVER_WITH_ALSA_MIDI
- if(driver->midi_handle) {
- freebob_driver_midi_stop(driver->midi_handle);
+ if (driver->midi_handle) {
+ freebob_driver_midi_stop (driver->midi_handle);
}
#endif
return retval;
@@ -653,18 +663,18 @@ freebob_driver_start (freebob_driver_t *driver)
static int
freebob_driver_stop (freebob_driver_t *driver)
{
- int retval=0;
-
+ int retval = 0;
+
#ifdef FREEBOB_DRIVER_WITH_ALSA_MIDI
- if(driver->midi_handle) {
- if((retval=freebob_driver_midi_stop(driver->midi_handle))) {
- printError("Could not stop MIDI threads");
+ if (driver->midi_handle) {
+ if ((retval = freebob_driver_midi_stop (driver->midi_handle))) {
+ printError ("Could not stop MIDI threads");
return retval;
}
}
-#endif
- if((retval=freebob_streaming_stop(driver->dev))) {
- printError("Could not stop streaming threads");
+#endif
+ if ((retval = freebob_streaming_stop (driver->dev))) {
+ printError ("Could not stop streaming threads");
return retval;
}
@@ -675,15 +685,15 @@ freebob_driver_stop (freebob_driver_t *driver)
static int
freebob_driver_bufsize (freebob_driver_t* driver, jack_nframes_t nframes)
{
- printError("Buffer size change requested but not supported!!!");
+ printError ("Buffer size change requested but not supported!!!");
/*
- driver->period_size = nframes;
- driver->period_usecs =
- (jack_time_t) floor ((((float) nframes) / driver->sample_rate)
- * 1000000.0f);
- */
-
+ driver->period_size = nframes;
+ driver->period_usecs =
+ (jack_time_t) floor ((((float) nframes) / driver->sample_rate)
+ * 1000000.0f);
+ */
+
/* tell the engine to change its buffer size */
#if 0
if (driver->engine->set_buffer_size (driver->engine, nframes)) {
@@ -694,275 +704,278 @@ freebob_driver_bufsize (freebob_driver_t* driver, jack_nframes_t nframes)
return -1; // unsupported
}
-typedef void (*JackDriverFinishFunction) (jack_driver_t *);
+typedef void (*JackDriverFinishFunction)(jack_driver_t *);
freebob_driver_t *
freebob_driver_new (jack_client_t * client,
- char *name,
- freebob_jack_settings_t *params)
+ char *name,
+ freebob_jack_settings_t *params)
{
freebob_driver_t *driver;
- assert(params);
+ assert (params);
- if(freebob_get_api_version() != 1) {
- printMessage("Incompatible libfreebob version! (%s)", freebob_get_version());
+ if (freebob_get_api_version () != 1) {
+ printMessage ("Incompatible libfreebob version! (%s)", freebob_get_version ());
return NULL;
}
- printMessage("Starting Freebob backend (%s)", freebob_get_version());
+ printMessage ("Starting Freebob backend (%s)", freebob_get_version ());
- driver = calloc (1, sizeof (freebob_driver_t));
+ driver = calloc (1, sizeof(freebob_driver_t));
- /* Setup the jack interfaces */
- jack_driver_nt_init ((jack_driver_nt_t *) driver);
+ /* Setup the jack interfaces */
+ jack_driver_nt_init ((jack_driver_nt_t*)driver);
+
+ driver->nt_attach = (JackDriverNTAttachFunction)freebob_driver_attach;
+ driver->nt_detach = (JackDriverNTDetachFunction)freebob_driver_detach;
+ driver->nt_start = (JackDriverNTStartFunction)freebob_driver_start;
+ driver->nt_stop = (JackDriverNTStopFunction)freebob_driver_stop;
+ driver->nt_run_cycle = (JackDriverNTRunCycleFunction)freebob_driver_run_cycle;
+ driver->null_cycle = (JackDriverNullCycleFunction)freebob_driver_null_cycle;
+ driver->write = (JackDriverReadFunction)freebob_driver_write;
+ driver->read = (JackDriverReadFunction)freebob_driver_read;
+ driver->nt_bufsize = (JackDriverNTBufSizeFunction)freebob_driver_bufsize;
- driver->nt_attach = (JackDriverNTAttachFunction) freebob_driver_attach;
- driver->nt_detach = (JackDriverNTDetachFunction) freebob_driver_detach;
- driver->nt_start = (JackDriverNTStartFunction) freebob_driver_start;
- driver->nt_stop = (JackDriverNTStopFunction) freebob_driver_stop;
- driver->nt_run_cycle = (JackDriverNTRunCycleFunction) freebob_driver_run_cycle;
- driver->null_cycle = (JackDriverNullCycleFunction) freebob_driver_null_cycle;
- driver->write = (JackDriverReadFunction) freebob_driver_write;
- driver->read = (JackDriverReadFunction) freebob_driver_read;
- driver->nt_bufsize = (JackDriverNTBufSizeFunction) freebob_driver_bufsize;
-
/* copy command line parameter contents to the driver structure */
- memcpy(&driver->settings,params,sizeof(freebob_jack_settings_t));
-
+ memcpy (&driver->settings, params, sizeof(freebob_jack_settings_t));
+
/* prepare all parameters */
driver->sample_rate = params->sample_rate;
driver->period_size = params->period_size;
driver->last_wait_ust = 0;
-
+
driver->period_usecs =
- (jack_time_t) floor ((((float) driver->period_size) * 1000000.0f) / driver->sample_rate);
+ (jack_time_t)floor ((((float)driver->period_size) * 1000000.0f) / driver->sample_rate);
driver->client = client;
driver->engine = NULL;
- memset(&driver->device_options,0,sizeof(driver->device_options));
- driver->device_options.sample_rate=params->sample_rate;
- driver->device_options.period_size=params->period_size;
- driver->device_options.nb_buffers=params->buffer_size;
- driver->device_options.node_id=params->node_id;
- driver->device_options.port=params->port;
+ memset (&driver->device_options, 0, sizeof(driver->device_options));
+ driver->device_options.sample_rate = params->sample_rate;
+ driver->device_options.period_size = params->period_size;
+ driver->device_options.nb_buffers = params->buffer_size;
+ driver->device_options.node_id = params->node_id;
+ driver->device_options.port = params->port;
driver->capture_frame_latency = params->capture_frame_latency;
driver->playback_frame_latency = params->playback_frame_latency;
- if(!params->capture_ports) {
+ if (!params->capture_ports) {
driver->device_options.directions |= FREEBOB_IGNORE_CAPTURE;
}
- if(!params->playback_ports) {
+ if (!params->playback_ports) {
driver->device_options.directions |= FREEBOB_IGNORE_PLAYBACK;
}
- debugPrint(DEBUG_LEVEL_STARTUP, " Driver compiled on %s %s", __DATE__, __TIME__);
- debugPrint(DEBUG_LEVEL_STARTUP, " Created driver %s", name);
- debugPrint(DEBUG_LEVEL_STARTUP, " period_size: %d", driver->period_size);
- debugPrint(DEBUG_LEVEL_STARTUP, " period_usecs: %d", driver->period_usecs);
- debugPrint(DEBUG_LEVEL_STARTUP, " sample rate: %d", driver->sample_rate);
+ debugPrint (DEBUG_LEVEL_STARTUP, " Driver compiled on %s %s", __DATE__, __TIME__);
+ debugPrint (DEBUG_LEVEL_STARTUP, " Created driver %s", name);
+ debugPrint (DEBUG_LEVEL_STARTUP, " period_size: %d", driver->period_size);
+ debugPrint (DEBUG_LEVEL_STARTUP, " period_usecs: %d", driver->period_usecs);
+ debugPrint (DEBUG_LEVEL_STARTUP, " sample rate: %d", driver->sample_rate);
- return (freebob_driver_t *) driver;
+ return (freebob_driver_t*)driver;
}
static void
freebob_driver_delete (freebob_driver_t *driver)
{
- if(driver->dev) {
- freebob_driver_detach(driver);
+ if (driver->dev) {
+ freebob_driver_detach (driver);
}
- jack_driver_nt_finish ((jack_driver_nt_t *) driver);
+ jack_driver_nt_finish ((jack_driver_nt_t*)driver);
free (driver);
}
#ifdef FREEBOB_DRIVER_WITH_ALSA_MIDI
/*
* MIDI support
- */
+ */
// the thread that will queue the midi events from the seq to the stream buffers
-void * freebob_driver_midi_queue_thread(void *arg)
+void * freebob_driver_midi_queue_thread (void *arg)
{
- freebob_driver_midi_handle_t *m=(freebob_driver_midi_handle_t *)arg;
- assert(m);
+ freebob_driver_midi_handle_t *m = (freebob_driver_midi_handle_t*)arg;
+
+ assert (m);
snd_seq_event_t *ev;
unsigned char work_buffer[MIDI_TRANSMIT_BUFFER_SIZE];
int bytes_to_send;
int b;
int i;
- printMessage("MIDI queue thread started");
+ printMessage ("MIDI queue thread started");
- while(1) {
+ while (1) {
// get next event, if one is present
- while ((snd_seq_event_input(m->seq_handle, &ev) > 0)) {
- if (ev->source.client == SND_SEQ_CLIENT_SYSTEM)
+ while ((snd_seq_event_input (m->seq_handle, &ev) > 0)) {
+ if (ev->source.client == SND_SEQ_CLIENT_SYSTEM) {
continue;
+ }
// get the port this event is originated from
- freebob_midi_port_t *port=NULL;
- for (i=0;i<m->nb_output_ports;i++) {
- if(m->output_ports[i]->seq_port_nr == ev->dest.port) {
- port=m->output_ports[i];
+ freebob_midi_port_t *port = NULL;
+ for (i = 0; i < m->nb_output_ports; i++) {
+ if (m->output_ports[i]->seq_port_nr == ev->dest.port) {
+ port = m->output_ports[i];
break;
}
}
-
- if(!port) {
- printError(" Could not find target port for event: dst=%d src=%d", ev->dest.port, ev->source.port);
+
+ if (!port) {
+ printError (" Could not find target port for event: dst=%d src=%d", ev->dest.port, ev->source.port);
break;
}
-
+
// decode it to the work buffer
- if((bytes_to_send = snd_midi_event_decode ( port->parser,
- work_buffer,
- MIDI_TRANSMIT_BUFFER_SIZE,
- ev))<0)
- { // failed
- printError(" Error decoding event for port %d (errcode=%d)", port->seq_port_nr,bytes_to_send);
- bytes_to_send=0;
+ if ((bytes_to_send = snd_midi_event_decode ( port->parser,
+ work_buffer,
+ MIDI_TRANSMIT_BUFFER_SIZE,
+ ev)) < 0) { // failed
+ printError (" Error decoding event for port %d (errcode=%d)", port->seq_port_nr, bytes_to_send);
+ bytes_to_send = 0;
//return -1;
}
-
- for(b=0;b<bytes_to_send;b++) {
- freebob_sample_t tmp_event=work_buffer[b];
- if(freebob_streaming_write(m->dev, port->stream_nr, &tmp_event, 1)<1) {
- printError(" Midi send buffer overrun");
+
+ for (b = 0; b < bytes_to_send; b++) {
+ freebob_sample_t tmp_event = work_buffer[b];
+ if (freebob_streaming_write (m->dev, port->stream_nr, &tmp_event, 1) < 1) {
+ printError (" Midi send buffer overrun");
}
}
-
+
}
// sleep for some time
- usleep(MIDI_THREAD_SLEEP_TIME_USECS);
+ usleep (MIDI_THREAD_SLEEP_TIME_USECS);
}
return NULL;
}
// the dequeue thread (maybe we need one thread per stream)
-void *freebob_driver_midi_dequeue_thread (void *arg) {
- freebob_driver_midi_handle_t *m=(freebob_driver_midi_handle_t *)arg;
+void *freebob_driver_midi_dequeue_thread (void *arg)
+{
+ freebob_driver_midi_handle_t *m = (freebob_driver_midi_handle_t*)arg;
int i;
int s;
-
+
int samples_read;
- assert(m);
+ assert (m);
- while(1) {
+ while (1) {
// read incoming events
-
- for (i=0;i<m->nb_input_ports;i++) {
+
+ for (i = 0; i < m->nb_input_ports; i++) {
unsigned int buff[64];
-
- freebob_midi_port_t *port=m->input_ports[i];
-
- if(!port) {
- printError(" something went wrong when setting up the midi input port map (%d)",i);
+
+ freebob_midi_port_t *port = m->input_ports[i];
+
+ if (!port) {
+ printError (" something went wrong when setting up the midi input port map (%d)", i);
}
-
+
do {
- samples_read=freebob_streaming_read(m->dev, port->stream_nr, buff, 64);
-
- for (s=0;s<samples_read;s++) {
- unsigned int *byte=(buff+s) ;
+ samples_read = freebob_streaming_read (m->dev, port->stream_nr, buff, 64);
+
+ for (s = 0; s < samples_read; s++) {
+ unsigned int *byte = (buff + s);
snd_seq_event_t ev;
- if ((snd_midi_event_encode_byte(port->parser,(*byte) & 0xFF, &ev)) > 0) {
+ if ((snd_midi_event_encode_byte (port->parser, (*byte) & 0xFF, &ev)) > 0) {
// a midi message is complete, send it out to ALSA
- snd_seq_ev_set_subs(&ev);
- snd_seq_ev_set_direct(&ev);
- snd_seq_ev_set_source(&ev, port->seq_port_nr);
- snd_seq_event_output_direct(port->seq_handle, &ev);
+ snd_seq_ev_set_subs (&ev);
+ snd_seq_ev_set_direct (&ev);
+ snd_seq_ev_set_source (&ev, port->seq_port_nr);
+ snd_seq_event_output_direct (port->seq_handle, &ev);
}
}
- } while (samples_read>0);
+ } while (samples_read > 0);
}
// sleep for some time
- usleep(MIDI_THREAD_SLEEP_TIME_USECS);
+ usleep (MIDI_THREAD_SLEEP_TIME_USECS);
}
return NULL;
}
-static freebob_driver_midi_handle_t *freebob_driver_midi_init(freebob_driver_t *driver) {
-// int err;
+static freebob_driver_midi_handle_t *freebob_driver_midi_init (freebob_driver_t *driver)
+{
+// int err;
char buf[256];
channel_t chn;
int nchannels;
- int i=0;
+ int i = 0;
- freebob_device_t *dev=driver->dev;
+ freebob_device_t *dev = driver->dev;
- assert(dev);
+ assert (dev);
- freebob_driver_midi_handle_t *m=calloc(1,sizeof(freebob_driver_midi_handle_t));
+ freebob_driver_midi_handle_t *m = calloc (1, sizeof(freebob_driver_midi_handle_t));
if (!m) {
- printError("not enough memory to create midi structure");
+ printError ("not enough memory to create midi structure");
return NULL;
}
- if (snd_seq_open(&m->seq_handle, "default", SND_SEQ_OPEN_DUPLEX, SND_SEQ_NONBLOCK) < 0) {
- printError("Error opening ALSA sequencer.");
- free(m);
+ if (snd_seq_open (&m->seq_handle, "default", SND_SEQ_OPEN_DUPLEX, SND_SEQ_NONBLOCK) < 0) {
+ printError ("Error opening ALSA sequencer.");
+ free (m);
return NULL;
}
- snd_seq_set_client_name(m->seq_handle, "FreeBoB Jack MIDI");
+ snd_seq_set_client_name (m->seq_handle, "FreeBoB Jack MIDI");
// find out the number of midi in/out ports we need to setup
- nchannels=freebob_streaming_get_nb_capture_streams(dev);
+ nchannels = freebob_streaming_get_nb_capture_streams (dev);
- m->nb_input_ports=0;
+ m->nb_input_ports = 0;
- for (chn = 0; chn < nchannels; chn++) {
- if(freebob_streaming_get_capture_stream_type(dev, chn) == freebob_stream_type_midi) {
+ for (chn = 0; chn < nchannels; chn++) {
+ if (freebob_streaming_get_capture_stream_type (dev, chn) == freebob_stream_type_midi) {
m->nb_input_ports++;
}
}
- m->input_ports=calloc(m->nb_input_ports,sizeof(freebob_midi_port_t *));
- if(!m->input_ports) {
- printError("not enough memory to create midi structure");
- free(m);
+ m->input_ports = calloc (m->nb_input_ports, sizeof(freebob_midi_port_t *));
+ if (!m->input_ports) {
+ printError ("not enough memory to create midi structure");
+ free (m);
return NULL;
}
- i=0;
+ i = 0;
for (chn = 0; chn < nchannels; chn++) {
- if(freebob_streaming_get_capture_stream_type(dev, chn) == freebob_stream_type_midi) {
- m->input_ports[i]=calloc(1,sizeof(freebob_midi_port_t));
- if(!m->input_ports[i]) {
+ if (freebob_streaming_get_capture_stream_type (dev, chn) == freebob_stream_type_midi) {
+ m->input_ports[i] = calloc (1, sizeof(freebob_midi_port_t));
+ if (!m->input_ports[i]) {
// fixme
- printError("Could not allocate memory for seq port");
+ printError ("Could not allocate memory for seq port");
continue;
}
- freebob_streaming_get_capture_stream_name(dev, chn, buf, sizeof(buf) - 1);
- printMessage("Register MIDI IN port %s", buf);
+ freebob_streaming_get_capture_stream_name (dev, chn, buf, sizeof(buf) - 1);
+ printMessage ("Register MIDI IN port %s", buf);
- m->input_ports[i]->seq_port_nr=snd_seq_create_simple_port(m->seq_handle, buf,
- SND_SEQ_PORT_CAP_READ|SND_SEQ_PORT_CAP_SUBS_READ,
- SND_SEQ_PORT_TYPE_MIDI_GENERIC);
+ m->input_ports[i]->seq_port_nr = snd_seq_create_simple_port (m->seq_handle, buf,
+ SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ,
+ SND_SEQ_PORT_TYPE_MIDI_GENERIC);
- if(m->input_ports[i]->seq_port_nr<0) {
- printError("Could not create seq port");
- m->input_ports[i]->stream_nr=-1;
- m->input_ports[i]->seq_port_nr=-1;
+ if (m->input_ports[i]->seq_port_nr < 0) {
+ printError ("Could not create seq port");
+ m->input_ports[i]->stream_nr = -1;
+ m->input_ports[i]->seq_port_nr = -1;
} else {
- m->input_ports[i]->stream_nr=chn;
- m->input_ports[i]->seq_handle=m->seq_handle;
- if (snd_midi_event_new ( ALSA_SEQ_BUFF_SIZE, &(m->input_ports[i]->parser)) < 0) {
- printError("could not init parser for MIDI IN port %d",i);
- m->input_ports[i]->stream_nr=-1;
- m->input_ports[i]->seq_port_nr=-1;
+ m->input_ports[i]->stream_nr = chn;
+ m->input_ports[i]->seq_handle = m->seq_handle;
+ if (snd_midi_event_new ( ALSA_SEQ_BUFF_SIZE, &(m->input_ports[i]->parser)) < 0) {
+ printError ("could not init parser for MIDI IN port %d", i);
+ m->input_ports[i]->stream_nr = -1;
+ m->input_ports[i]->seq_port_nr = -1;
}
}
@@ -971,56 +984,55 @@ static freebob_driver_midi_handle_t *freebob_driver_midi_init(freebob_driver_t *
}
// playback
- nchannels=freebob_streaming_get_nb_playback_streams(dev);
+ nchannels = freebob_streaming_get_nb_playback_streams (dev);
- m->nb_output_ports=0;
+ m->nb_output_ports = 0;
- for (chn = 0; chn < nchannels; chn++) {
- if(freebob_streaming_get_playback_stream_type(dev, chn) == freebob_stream_type_midi) {
+ for (chn = 0; chn < nchannels; chn++) {
+ if (freebob_streaming_get_playback_stream_type (dev, chn) == freebob_stream_type_midi) {
m->nb_output_ports++;
}
}
- m->output_ports=calloc(m->nb_output_ports,sizeof(freebob_midi_port_t *));
- if(!m->output_ports) {
- printError("not enough memory to create midi structure");
- for (i = 0; i < m->nb_input_ports; i++) {
- free(m->input_ports[i]);
- }
- free(m->input_ports);
- free(m);
+ m->output_ports = calloc (m->nb_output_ports, sizeof(freebob_midi_port_t *));
+ if (!m->output_ports) {
+ printError ("not enough memory to create midi structure");
+ for (i = 0; i < m->nb_input_ports; i++)
+ free (m->input_ports[i]);
+ free (m->input_ports);
+ free (m);
return NULL;
}
- i=0;
+ i = 0;
for (chn = 0; chn < nchannels; chn++) {
- if(freebob_streaming_get_playback_stream_type(dev, chn) == freebob_stream_type_midi) {
- m->output_ports[i]=calloc(1,sizeof(freebob_midi_port_t));
- if(!m->output_ports[i]) {
+ if (freebob_streaming_get_playback_stream_type (dev, chn) == freebob_stream_type_midi) {
+ m->output_ports[i] = calloc (1, sizeof(freebob_midi_port_t));
+ if (!m->output_ports[i]) {
// fixme
- printError("Could not allocate memory for seq port");
+ printError ("Could not allocate memory for seq port");
continue;
}
- freebob_streaming_get_playback_stream_name(dev, chn, buf, sizeof(buf) - 1);
- printMessage("Register MIDI OUT port %s", buf);
+ freebob_streaming_get_playback_stream_name (dev, chn, buf, sizeof(buf) - 1);
+ printMessage ("Register MIDI OUT port %s", buf);
- m->output_ports[i]->seq_port_nr=snd_seq_create_simple_port(m->seq_handle, buf,
- SND_SEQ_PORT_CAP_WRITE|SND_SEQ_PORT_CAP_SUBS_WRITE,
- SND_SEQ_PORT_TYPE_MIDI_GENERIC);
+ m->output_ports[i]->seq_port_nr = snd_seq_create_simple_port (m->seq_handle, buf,
+ SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE,
+ SND_SEQ_PORT_TYPE_MIDI_GENERIC);
- if(m->output_ports[i]->seq_port_nr<0) {
- printError("Could not create seq port");
- m->output_ports[i]->stream_nr=-1;
- m->output_ports[i]->seq_port_nr=-1;
+ if (m->output_ports[i]->seq_port_nr < 0) {
+ printError ("Could not create seq port");
+ m->output_ports[i]->stream_nr = -1;
+ m->output_ports[i]->seq_port_nr = -1;
} else {
- m->output_ports[i]->stream_nr=chn;
- m->output_ports[i]->seq_handle=m->seq_handle;
- if (snd_midi_event_new ( ALSA_SEQ_BUFF_SIZE, &(m->output_ports[i]->parser)) < 0) {
- printError("could not init parser for MIDI OUT port %d",i);
- m->output_ports[i]->stream_nr=-1;
- m->output_ports[i]->seq_port_nr=-1;
+ m->output_ports[i]->stream_nr = chn;
+ m->output_ports[i]->seq_handle = m->seq_handle;
+ if (snd_midi_event_new ( ALSA_SEQ_BUFF_SIZE, &(m->output_ports[i]->parser)) < 0) {
+ printError ("could not init parser for MIDI OUT port %d", i);
+ m->output_ports[i]->stream_nr = -1;
+ m->output_ports[i]->seq_port_nr = -1;
}
}
@@ -1028,8 +1040,8 @@ static freebob_driver_midi_handle_t *freebob_driver_midi_init(freebob_driver_t *
}
}
- m->dev=dev;
- m->driver=driver;
+ m->dev = dev;
+ m->driver = driver;
return m;
}
@@ -1037,31 +1049,31 @@ static freebob_driver_midi_handle_t *freebob_driver_midi_init(freebob_driver_t *
static int
freebob_driver_midi_start (freebob_driver_midi_handle_t *m)
{
- assert(m);
+ assert (m);
// start threads
- m->queue_thread_realtime=(m->driver->engine->control->real_time? 1 : 0);
- m->queue_thread_priority=
+ m->queue_thread_realtime = (m->driver->engine->control->real_time ? 1 : 0);
+ m->queue_thread_priority =
m->driver->engine->control->client_priority +
FREEBOB_RT_PRIORITY_MIDI_RELATIVE;
- if (m->queue_thread_priority>98) {
- m->queue_thread_priority=98;
+ if (m->queue_thread_priority > 98) {
+ m->queue_thread_priority = 98;
}
if (m->queue_thread_realtime) {
- printMessage("MIDI threads running with Realtime scheduling, priority %d",
- m->queue_thread_priority);
+ printMessage ("MIDI threads running with Realtime scheduling, priority %d",
+ m->queue_thread_priority);
} else {
- printMessage("MIDI threads running without Realtime scheduling");
+ printMessage ("MIDI threads running without Realtime scheduling");
}
- if (jack_client_create_thread(NULL, &m->queue_thread, m->queue_thread_priority, m->queue_thread_realtime, freebob_driver_midi_queue_thread, (void *)m)) {
- printError(" cannot create midi queueing thread");
+ if (jack_client_create_thread (NULL, &m->queue_thread, m->queue_thread_priority, m->queue_thread_realtime, freebob_driver_midi_queue_thread, (void*)m)) {
+ printError (" cannot create midi queueing thread");
return -1;
}
- if (jack_client_create_thread(NULL, &m->dequeue_thread, m->queue_thread_priority, m->queue_thread_realtime, freebob_driver_midi_dequeue_thread, (void *)m)) {
- printError(" cannot create midi dequeueing thread");
+ if (jack_client_create_thread (NULL, &m->dequeue_thread, m->queue_thread_priority, m->queue_thread_realtime, freebob_driver_midi_dequeue_thread, (void*)m)) {
+ printError (" cannot create midi dequeueing thread");
return -1;
}
return 0;
@@ -1070,7 +1082,7 @@ freebob_driver_midi_start (freebob_driver_midi_handle_t *m)
static int
freebob_driver_midi_stop (freebob_driver_midi_handle_t *m)
{
- assert(m);
+ assert (m);
pthread_cancel (m->queue_thread);
pthread_join (m->queue_thread, NULL);
@@ -1084,25 +1096,23 @@ freebob_driver_midi_stop (freebob_driver_midi_handle_t *m)
static void
freebob_driver_midi_finish (freebob_driver_midi_handle_t *m)
{
- assert(m);
+ assert (m);
int i;
// TODO: add state info here, if not stopped then stop
- for (i=0;i<m->nb_input_ports;i++) {
- free(m->input_ports[i]);
+ for (i = 0; i < m->nb_input_ports; i++)
+ free (m->input_ports[i]);
- }
- free(m->input_ports);
+ free (m->input_ports);
- for (i=0;i<m->nb_output_ports;i++) {
- free(m->output_ports[i]);
- }
- free(m->output_ports);
+ for (i = 0; i < m->nb_output_ports; i++)
+ free (m->output_ports[i]);
+ free (m->output_ports);
- free(m);
+ free (m);
}
-#endif
+#endif
/*
* dlopen plugin stuff
*/
@@ -1116,12 +1126,12 @@ driver_get_descriptor ()
jack_driver_param_desc_t * params;
unsigned int i;
- desc = calloc (1, sizeof (jack_driver_desc_t));
+ desc = calloc (1, sizeof(jack_driver_desc_t));
strcpy (desc->name, "freebob");
desc->nparams = 11;
-
- params = calloc (desc->nparams, sizeof (jack_driver_param_desc_t));
+
+ params = calloc (desc->nparams, sizeof(jack_driver_param_desc_t));
desc->params = params;
i = 0;
@@ -1131,7 +1141,7 @@ driver_get_descriptor ()
strcpy (params[i].value.str, "hw:0");
strcpy (params[i].short_desc, "The FireWire device to use. Format is: 'hw:port[,node]'.");
strcpy (params[i].long_desc, params[i].short_desc);
-
+
i++;
strcpy (params[i].name, "period");
params[i].character = 'p';
@@ -1139,7 +1149,7 @@ driver_get_descriptor ()
params[i].value.ui = 1024;
strcpy (params[i].short_desc, "Frames per period");
strcpy (params[i].long_desc, params[i].short_desc);
-
+
i++;
strcpy (params[i].name, "nperiods");
params[i].character = 'n';
@@ -1187,7 +1197,7 @@ driver_get_descriptor ()
params[i].value.ui = 0;
strcpy (params[i].short_desc, "Extra input latency (frames)");
strcpy (params[i].long_desc, params[i].short_desc);
-
+
i++;
strcpy (params[i].name, "output-latency");
params[i].character = 'O';
@@ -1203,14 +1213,14 @@ driver_get_descriptor ()
params[i].value.ui = 0;
strcpy (params[i].short_desc, "Number of input channels to provide (note: currently ignored)");
strcpy (params[i].long_desc, params[i].short_desc);
-
+
i++;
strcpy (params[i].name, "outchannels");
params[i].character = 'o';
params[i].type = JackDriverParamUInt;
params[i].value.ui = 0;
strcpy (params[i].short_desc, "Number of output channels to provide (note: currently ignored)");
- strcpy (params[i].long_desc, params[i].short_desc);
+ strcpy (params[i].long_desc, params[i].short_desc);
return desc;
}
@@ -1221,40 +1231,38 @@ driver_initialize (jack_client_t *client, JSList * params)
{
jack_driver_t *driver;
- unsigned int port=0;
- unsigned int node_id=-1;
- int nbitems;
-
+ unsigned int port = 0;
+ unsigned int node_id = -1;
+ int nbitems;
+
const JSList * node;
const jack_driver_param_t * param;
freebob_jack_settings_t cmlparams;
-
- char *device_name="hw:0";
-
- cmlparams.period_size_set=0;
- cmlparams.sample_rate_set=0;
- cmlparams.buffer_size_set=0;
- cmlparams.port_set=0;
- cmlparams.node_id_set=0;
+
+ char *device_name = "hw:0";
+
+ cmlparams.period_size_set = 0;
+ cmlparams.sample_rate_set = 0;
+ cmlparams.buffer_size_set = 0;
+ cmlparams.port_set = 0;
+ cmlparams.node_id_set = 0;
/* default values */
- cmlparams.period_size=1024;
- cmlparams.sample_rate=48000;
- cmlparams.buffer_size=3;
- cmlparams.port=0;
- cmlparams.node_id=-1;
- cmlparams.playback_ports=0;
- cmlparams.capture_ports=0;
- cmlparams.playback_frame_latency=0;
- cmlparams.capture_frame_latency=0;
-
- for (node = params; node; node = jack_slist_next (node))
- {
- param = (jack_driver_param_t *) node->data;
-
- switch (param->character)
- {
+ cmlparams.period_size = 1024;
+ cmlparams.sample_rate = 48000;
+ cmlparams.buffer_size = 3;
+ cmlparams.port = 0;
+ cmlparams.node_id = -1;
+ cmlparams.playback_ports = 0;
+ cmlparams.capture_ports = 0;
+ cmlparams.playback_frame_latency = 0;
+ cmlparams.capture_frame_latency = 0;
+
+ for (node = params; node; node = jack_slist_next (node)) {
+ param = (jack_driver_param_t*)node->data;
+
+ switch (param->character) {
case 'd':
device_name = strdup (param->value.str);
break;
@@ -1265,7 +1273,7 @@ driver_initialize (jack_client_t *client, JSList * params)
case 'n':
cmlparams.buffer_size = param->value.ui;
cmlparams.buffer_size_set = 1;
- break;
+ break;
case 'r':
cmlparams.sample_rate = param->value.ui;
cmlparams.sample_rate_set = 1;
@@ -1300,32 +1308,32 @@ driver_initialize (jack_client_t *client, JSList * params)
cmlparams.capture_ports = TRUE;
}
- nbitems=sscanf(device_name,"hw:%u,%u",&port,&node_id);
- if (nbitems<2) {
- nbitems=sscanf(device_name,"hw:%u",&port);
-
- if(nbitems < 1) {
- free(device_name);
- printError("device (-d) argument not valid\n");
- return NULL;
- } else {
- cmlparams.port = port;
- cmlparams.port_set=1;
-
- cmlparams.node_id = -1;
- cmlparams.node_id_set=0;
- }
- } else {
- cmlparams.port = port;
- cmlparams.port_set=1;
-
- cmlparams.node_id = node_id;
- cmlparams.node_id_set=1;
- }
-
- jack_error("Freebob using Firewire port %d, node %d",cmlparams.port,cmlparams.node_id);
-
- driver=(jack_driver_t *)freebob_driver_new (client, "freebob_pcm", &cmlparams);
+ nbitems = sscanf (device_name, "hw:%u,%u", &port, &node_id);
+ if (nbitems < 2) {
+ nbitems = sscanf (device_name, "hw:%u", &port);
+
+ if (nbitems < 1) {
+ free (device_name);
+ printError ("device (-d) argument not valid\n");
+ return NULL;
+ } else {
+ cmlparams.port = port;
+ cmlparams.port_set = 1;
+
+ cmlparams.node_id = -1;
+ cmlparams.node_id_set = 0;
+ }
+ } else {
+ cmlparams.port = port;
+ cmlparams.port_set = 1;
+
+ cmlparams.node_id = node_id;
+ cmlparams.node_id_set = 1;
+ }
+
+ jack_error ("Freebob using Firewire port %d, node %d", cmlparams.port, cmlparams.node_id);
+
+ driver = (jack_driver_t*)freebob_driver_new (client, "freebob_pcm", &cmlparams);
return driver;
}
@@ -1333,8 +1341,8 @@ driver_initialize (jack_client_t *client, JSList * params)
void
driver_finish (jack_driver_t *driver)
{
- freebob_driver_t *drv=(freebob_driver_t *) driver;
-
+ freebob_driver_t *drv = (freebob_driver_t*)driver;
+
freebob_driver_delete (drv);
}
diff --git a/drivers/freebob/freebob_driver.h b/drivers/freebob/freebob_driver.h
index 337d841..4f638f0 100644
--- a/drivers/freebob/freebob_driver.h
+++ b/drivers/freebob/freebob_driver.h
@@ -23,11 +23,11 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-/*
+/*
* Main Jack driver entry routines
*
- */
-
+ */
+
#ifndef __JACK_FREEBOB_DRIVER_H__
#define __JACK_FREEBOB_DRIVER_H__
@@ -66,59 +66,59 @@
#include "engine.h"
// debug print control flags
-#define DEBUG_LEVEL_BUFFERS (1<<0)
-#define DEBUG_LEVEL_HANDLERS (1<<1)
-#define DEBUG_LEVEL_XRUN_RECOVERY (1<<2)
-#define DEBUG_LEVEL_WAIT (1<<3)
+#define DEBUG_LEVEL_BUFFERS (1 << 0)
+#define DEBUG_LEVEL_HANDLERS (1 << 1)
+#define DEBUG_LEVEL_XRUN_RECOVERY (1 << 2)
+#define DEBUG_LEVEL_WAIT (1 << 3)
-#define DEBUG_LEVEL_RUN_CYCLE (1<<8)
+#define DEBUG_LEVEL_RUN_CYCLE (1 << 8)
-#define DEBUG_LEVEL_PACKETCOUNTER (1<<16)
-#define DEBUG_LEVEL_STARTUP (1<<17)
-#define DEBUG_LEVEL_THREADS (1<<18)
+#define DEBUG_LEVEL_PACKETCOUNTER (1 << 16)
+#define DEBUG_LEVEL_STARTUP (1 << 17)
+#define DEBUG_LEVEL_THREADS (1 << 18)
#ifdef DEBUG_ENABLED
- // default debug level
+// default debug level
#define DEBUG_LEVEL ( DEBUG_LEVEL_RUN_CYCLE | \
- (DEBUG_LEVEL_XRUN_RECOVERY)| DEBUG_LEVEL_STARTUP | DEBUG_LEVEL_WAIT | DEBUG_LEVEL_PACKETCOUNTER)
+ (DEBUG_LEVEL_XRUN_RECOVERY) | DEBUG_LEVEL_STARTUP | DEBUG_LEVEL_WAIT | DEBUG_LEVEL_PACKETCOUNTER)
#warning Building debug build!
- #define printMessage(format, args...) jack_error( "FreeBoB MSG: %s:%d (%s): " format, __FILE__, __LINE__, __FUNCTION__, ##args )
- #define printError(format, args...) jack_error( "FreeBoB ERR: %s:%d (%s): " format, __FILE__, __LINE__, __FUNCTION__, ##args )
-
- //#define printEnter() jack_error( "FBDRV ENTERS: %s (%s)\n", __FUNCTION__, __FILE__)
- //#define printExit() jack_error( "FBDRV EXITS: %s (%s)\n", __FUNCTION__, __FILE__)
- #define printEnter()
- #define printExit()
-
- #define debugError(format, args...) jack_error( "FREEBOB ERR: %s:%d (%s): " format, __FILE__, __LINE__, __FUNCTION__, ##args )
- #define debugPrint(Level, format, args...) if(DEBUG_LEVEL & (Level)) jack_error("DEBUG %s:%d (%s) :" format, __FILE__, __LINE__, __FUNCTION__, ##args );
- #define debugPrintShort(Level, format, args...) if(DEBUG_LEVEL & (Level)) jack_error( format,##args );
- #define debugPrintWithTimeStamp(Level, format, args...) if(DEBUG_LEVEL & (Level)) jack_error( "%16lu: "format, debugGetCurrentUTime(),##args );
- #define SEGFAULT int *test=NULL; *test=1;
+ #define printMessage(format, args ...) jack_error ( "FreeBoB MSG: %s:%d (%s): " format, __FILE__, __LINE__, __FUNCTION__, ## args )
+ #define printError(format, args ...) jack_error ( "FreeBoB ERR: %s:%d (%s): " format, __FILE__, __LINE__, __FUNCTION__, ## args )
+
+//#define printEnter() jack_error( "FBDRV ENTERS: %s (%s)\n", __FUNCTION__, __FILE__)
+//#define printExit() jack_error( "FBDRV EXITS: %s (%s)\n", __FUNCTION__, __FILE__)
+ #define printEnter()
+ #define printExit()
+
+ #define debugError(format, args ...) jack_error ( "FREEBOB ERR: %s:%d (%s): " format, __FILE__, __LINE__, __FUNCTION__, ## args )
+ #define debugPrint(Level, format, args ...) if (DEBUG_LEVEL & (Level)) { jack_error ("DEBUG %s:%d (%s) :" format, __FILE__, __LINE__, __FUNCTION__, ## args ); }
+ #define debugPrintShort(Level, format, args ...) if (DEBUG_LEVEL & (Level)) { jack_error ( format, ## args ); }
+ #define debugPrintWithTimeStamp(Level, format, args ...) if (DEBUG_LEVEL & (Level)) { jack_error ( "%16lu: "format, debugGetCurrentUTime (), ## args ); }
+ #define SEGFAULT int *test = NULL; *test = 1;
#else
#define DEBUG_LEVEL
-
- #define printMessage(format, args...) if(g_verbose) \
- jack_error("FreeBoB MSG: " format, ##args )
- #define printError(format, args...) jack_error("FreeBoB ERR: " format, ##args )
-
- #define printEnter()
- #define printExit()
-
- #define debugError(format, args...)
- #define debugPrint(Level, format, args...)
- #define debugPrintShort(Level, format, args...)
- #define debugPrintWithTimeStamp(Level, format, args...)
+
+ #define printMessage(format, args ...) if (g_verbose) \
+ jack_error ("FreeBoB MSG: " format, ## args )
+ #define printError(format, args ...) jack_error ("FreeBoB ERR: " format, ## args )
+
+ #define printEnter()
+ #define printExit()
+
+ #define debugError(format, args ...)
+ #define debugPrint(Level, format, args ...)
+ #define debugPrintShort(Level, format, args ...)
+ #define debugPrintWithTimeStamp(Level, format, args ...)
#endif
// thread priority setup
-#define FREEBOB_RT_PRIORITY_PACKETIZER_RELATIVE 5
+#define FREEBOB_RT_PRIORITY_PACKETIZER_RELATIVE 5
-// MIDI
+// MIDI
#ifdef FREEBOB_DRIVER_WITH_ALSA_MIDI
@@ -130,9 +130,9 @@
#define MIDI_THREAD_SLEEP_TIME_USECS 100
// midi priority should be higher than the audio priority in order to
// make sure events are not only delivered on period boundarys
-// but I think it should be smaller than the packetizer thread in order not
+// but I think it should be smaller than the packetizer thread in order not
// to lose any packets
-#define FREEBOB_RT_PRIORITY_MIDI_RELATIVE 4
+#define FREEBOB_RT_PRIORITY_MIDI_RELATIVE 4
#endif // FREEBOB_DRIVER_WITH_ALSA_MIDI
@@ -145,7 +145,7 @@
typedef struct freebob_midi_input_port_t {
// jack
midi_unpack_t unpack;
-
+
// midi
int overruns;
} freebob_midi_input_port_t;
@@ -168,22 +168,22 @@ typedef struct _freebob_jack_settings freebob_jack_settings_t;
struct _freebob_jack_settings {
int period_size_set;
jack_nframes_t period_size;
-
+
int sample_rate_set;
int sample_rate;
-
+
int buffer_size_set;
jack_nframes_t buffer_size;
int port_set;
int port;
-
+
int node_id_set;
int node_id;
int playback_ports;
int capture_ports;
-
+
jack_nframes_t capture_frame_latency;
jack_nframes_t playback_frame_latency;
@@ -205,7 +205,7 @@ typedef struct _freebob_driver_midi_handle {
freebob_driver_t *driver;
snd_seq_t *seq_handle;
-
+
pthread_t queue_thread;
pthread_t dequeue_thread;
int queue_thread_realtime;
@@ -227,41 +227,40 @@ typedef struct _freebob_driver_midi_handle {
/*
* JACK driver structure
*/
-
-struct _freebob_driver
-{
+
+struct _freebob_driver {
JACK_DRIVER_NT_DECL
-
- jack_nframes_t sample_rate;
- jack_nframes_t period_size;
- unsigned long wait_time;
- jack_time_t wait_last;
- jack_time_t wait_next;
+ jack_nframes_t sample_rate;
+ jack_nframes_t period_size;
+ unsigned long wait_time;
+
+ jack_time_t wait_last;
+ jack_time_t wait_next;
int wait_late;
-
+
jack_client_t *client;
-
- int xrun_detected;
- int xrun_count;
-
+
+ int xrun_detected;
+ int xrun_count;
+
int process_count;
-
+
/* settings from the command line */
freebob_jack_settings_t settings;
-
+
/* the freebob virtual device */
freebob_device_t *dev;
-
+
JSList *capture_ports;
JSList *playback_ports;
JSList *monitor_ports;
- channel_t playback_nchannels;
- channel_t capture_nchannels;
+ channel_t playback_nchannels;
+ channel_t capture_nchannels;
- jack_nframes_t playback_frame_latency;
- jack_nframes_t capture_frame_latency;
+ jack_nframes_t playback_frame_latency;
+ jack_nframes_t capture_frame_latency;
freebob_device_info_t device_info;
freebob_options_t device_options;
@@ -276,7 +275,7 @@ struct _freebob_driver
#endif
-};
+};
diff --git a/drivers/netjack/net_driver.c b/drivers/netjack/net_driver.c
index 7f7c1d5..ab3d447 100644
--- a/drivers/netjack/net_driver.c
+++ b/drivers/netjack/net_driver.c
@@ -1,28 +1,28 @@
/* -*- mode: c; c-file-style: "linux"; -*- */
/*
-NetJack Driver
+ NetJack Driver
-Copyright (C) 2008 Pieter Palmers <pieterpalmers@users.sourceforge.net>
-Copyright (C) 2006 Torben Hohn <torbenh@gmx.de>
-Copyright (C) 2003 Robert Ham <rah@bash.sh>
-Copyright (C) 2001 Paul Davis
+ Copyright (C) 2008 Pieter Palmers <pieterpalmers@users.sourceforge.net>
+ Copyright (C) 2006 Torben Hohn <torbenh@gmx.de>
+ Copyright (C) 2003 Robert Ham <rah@bash.sh>
+ Copyright (C) 2001 Paul Davis
-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 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.
+ 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.
+ 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.
-$Id: net_driver.c,v 1.17 2006/04/16 20:16:10 torbenh Exp $
-*/
+ $Id: net_driver.c,v 1.17 2006/04/16 20:16:10 torbenh Exp $
+ */
#include <math.h>
#include <stdio.h>
@@ -49,7 +49,7 @@ $Id: net_driver.c,v 1.17 2006/04/16 20:16:10 torbenh Exp $
#undef DEBUG_WAKEUP
-#define MIN(x,y) ((x)<(y) ? (x) : (y))
+#define MIN(x, y) ((x) < (y) ? (x) : (y))
static jack_transport_state_t last_transport_state;
static int sync_state = TRUE;
@@ -57,276 +57,286 @@ static int sync_state = TRUE;
static jack_nframes_t
net_driver_wait (net_driver_t *driver, int extra_fd, int *status, float *delayed_usecs)
{
- netjack_driver_state_t *netj = &( driver->netj );
- int delay;
-
- delay = netjack_wait( netj, driver->engine->get_microseconds );
- if( delay ) {
- //driver->engine->delay( driver->engine, (float)delay );
- jack_error( "netxruns amount: %dms", delay/1000 );
- }
-
-
- driver->last_wait_ust = driver->engine->get_microseconds ();
- driver->engine->transport_cycle_start (driver->engine, driver->last_wait_ust);
-
- /* this driver doesn't work so well if we report a delay */
- /* XXX: this might not be the case anymore */
- /* the delayed _usecs is a resync or something. */
- *delayed_usecs = 0; /* lie about it */
- *status = 0;
- return netj->period_size;
-}
+ netjack_driver_state_t *netj = &( driver->netj );
+ int delay;
-static int
-net_driver_run_cycle (net_driver_t *driver)
-{
- jack_engine_t *engine = driver->engine;
- //netjack_driver_state_t *netj = &(driver->netj);
- int wait_status = -1;
- float delayed_usecs;
+ delay = netjack_wait ( netj, driver->engine->get_microseconds );
+ if ( delay ) {
+ //driver->engine->delay( driver->engine, (float)delay );
+ jack_error ( "netxruns amount: %dms", delay / 1000 );
+ }
- jack_nframes_t nframes = net_driver_wait (driver, -1, &wait_status,
- &delayed_usecs);
- // XXX: xrun code removed.
- // especially with celt there are no real xruns anymore.
- // things are different on the net.
+ driver->last_wait_ust = driver->engine->get_microseconds ();
+ driver->engine->transport_cycle_start (driver->engine, driver->last_wait_ust);
- if (wait_status == 0)
- return engine->run_cycle (engine, nframes, delayed_usecs);
+ /* this driver doesn't work so well if we report a delay */
+ /* XXX: this might not be the case anymore */
+ /* the delayed _usecs is a resync or something. */
+ *delayed_usecs = 0; /* lie about it */
+ *status = 0;
+ return netj->period_size;
+}
- if (wait_status < 0)
- return -1;
- else
- return 0;
+static int
+net_driver_run_cycle (net_driver_t *driver)
+{
+ jack_engine_t *engine = driver->engine;
+ //netjack_driver_state_t *netj = &(driver->netj);
+ int wait_status = -1;
+ float delayed_usecs;
+
+ jack_nframes_t nframes = net_driver_wait (driver, -1, &wait_status,
+ &delayed_usecs);
+
+ // XXX: xrun code removed.
+ // especially with celt there are no real xruns anymore.
+ // things are different on the net.
+
+ if (wait_status == 0) {
+ return engine->run_cycle (engine, nframes, delayed_usecs);
+ }
+
+ if (wait_status < 0) {
+ return -1;
+ } else {
+ return 0;
+ }
}
static int
net_driver_null_cycle (net_driver_t* driver, jack_nframes_t nframes)
{
- // TODO: talk to paul about this.
- // do i wait here ?
- // just sending out a packet marked with junk ?
+ // TODO: talk to paul about this.
+ // do i wait here ?
+ // just sending out a packet marked with junk ?
- netjack_driver_state_t *netj = &(driver->netj);
- int sync_state = (driver->engine->control->sync_remain <= 1);
- netjack_send_silence( netj, sync_state );
+ netjack_driver_state_t *netj = &(driver->netj);
+ int sync_state = (driver->engine->control->sync_remain <= 1);
- return 0;
+ netjack_send_silence ( netj, sync_state );
+
+ return 0;
}
static int
net_driver_bufsize (net_driver_t* driver, jack_nframes_t nframes)
{
- netjack_driver_state_t *netj = &(driver->netj);
- if (nframes != netj->period_size)
- return EINVAL;
+ netjack_driver_state_t *netj = &(driver->netj);
- return 0;
+ if (nframes != netj->period_size) {
+ return EINVAL;
+ }
+
+ return 0;
}
static int
net_driver_read (net_driver_t* driver, jack_nframes_t nframes)
{
- netjack_driver_state_t *netj = &(driver->netj);
-
- jack_position_t local_trans_pos;
- jack_transport_state_t local_trans_state;
-
- unsigned int *packet_buf, *packet_bufX;
-
- if( ! netj->packet_data_valid ) {
- render_payload_to_jack_ports (netj->bitdepth, NULL, netj->net_period_down, netj->capture_ports, netj->capture_srcs, nframes, netj->dont_htonl_floats );
- return 0;
- }
- packet_buf = netj->rx_buf;
-
- jacknet_packet_header *pkthdr = (jacknet_packet_header *)packet_buf;
-
- packet_bufX = packet_buf + sizeof(jacknet_packet_header) / sizeof(jack_default_audio_sample_t);
-
- netj->reply_port = pkthdr->reply_port;
- netj->latency = pkthdr->latency;
-
- // Special handling for latency=0
- if( netj->latency == 0 )
- netj->resync_threshold = 0;
- else
- netj->resync_threshold = MIN( 15, pkthdr->latency-1 );
-
- // check whether, we should handle the transport sync stuff, or leave trnasports untouched.
- if (netj->handle_transport_sync) {
- int compensated_tranport_pos = (pkthdr->transport_frame + (pkthdr->latency * nframes) + netj->codec_latency);
-
- // read local transport info....
- local_trans_state = jack_transport_query(netj->client, &local_trans_pos);
-
- // Now check if we have to start or stop local transport to sync to remote...
- switch (pkthdr->transport_state) {
- case JackTransportStarting:
- // the master transport is starting... so we set our reply to the sync_callback;
- if (local_trans_state == JackTransportStopped) {
- jack_transport_start(netj->client);
- last_transport_state = JackTransportStopped;
- sync_state = FALSE;
- jack_info("locally stopped... starting...");
- }
-
- if (local_trans_pos.frame != compensated_tranport_pos)
- {
- jack_transport_locate(netj->client, compensated_tranport_pos);
- last_transport_state = JackTransportRolling;
- sync_state = FALSE;
- jack_info("starting locate to %d", compensated_tranport_pos );
- }
- break;
- case JackTransportStopped:
- sync_state = TRUE;
- if (local_trans_pos.frame != (pkthdr->transport_frame)) {
- jack_transport_locate(netj->client, (pkthdr->transport_frame));
- jack_info("transport is stopped locate to %d", pkthdr->transport_frame);
- }
- if (local_trans_state != JackTransportStopped)
- jack_transport_stop(netj->client);
- break;
- case JackTransportRolling:
- sync_state = TRUE;
-// if(local_trans_pos.frame != (pkthdr->transport_frame + (pkthdr->latency) * nframes)) {
+ netjack_driver_state_t *netj = &(driver->netj);
+
+ jack_position_t local_trans_pos;
+ jack_transport_state_t local_trans_state;
+
+ unsigned int *packet_buf, *packet_bufX;
+
+ if ( !netj->packet_data_valid ) {
+ render_payload_to_jack_ports (netj->bitdepth, NULL, netj->net_period_down, netj->capture_ports, netj->capture_srcs, nframes, netj->dont_htonl_floats );
+ return 0;
+ }
+ packet_buf = netj->rx_buf;
+
+ jacknet_packet_header *pkthdr = (jacknet_packet_header*)packet_buf;
+
+ packet_bufX = packet_buf + sizeof(jacknet_packet_header) / sizeof(jack_default_audio_sample_t);
+
+ netj->reply_port = pkthdr->reply_port;
+ netj->latency = pkthdr->latency;
+
+ // Special handling for latency=0
+ if ( netj->latency == 0 ) {
+ netj->resync_threshold = 0;
+ } else {
+ netj->resync_threshold = MIN ( 15, pkthdr->latency - 1 );
+ }
+
+ // check whether, we should handle the transport sync stuff, or leave trnasports untouched.
+ if (netj->handle_transport_sync) {
+ int compensated_tranport_pos = (pkthdr->transport_frame + (pkthdr->latency * nframes) + netj->codec_latency);
+
+ // read local transport info....
+ local_trans_state = jack_transport_query (netj->client, &local_trans_pos);
+
+ // Now check if we have to start or stop local transport to sync to remote...
+ switch (pkthdr->transport_state) {
+ case JackTransportStarting:
+ // the master transport is starting... so we set our reply to the sync_callback;
+ if (local_trans_state == JackTransportStopped) {
+ jack_transport_start (netj->client);
+ last_transport_state = JackTransportStopped;
+ sync_state = FALSE;
+ jack_info ("locally stopped... starting...");
+ }
+
+ if (local_trans_pos.frame != compensated_tranport_pos) {
+ jack_transport_locate (netj->client, compensated_tranport_pos);
+ last_transport_state = JackTransportRolling;
+ sync_state = FALSE;
+ jack_info ("starting locate to %d", compensated_tranport_pos );
+ }
+ break;
+ case JackTransportStopped:
+ sync_state = TRUE;
+ if (local_trans_pos.frame != (pkthdr->transport_frame)) {
+ jack_transport_locate (netj->client, (pkthdr->transport_frame));
+ jack_info ("transport is stopped locate to %d", pkthdr->transport_frame);
+ }
+ if (local_trans_state != JackTransportStopped) {
+ jack_transport_stop (netj->client);
+ }
+ break;
+ case JackTransportRolling:
+ sync_state = TRUE;
+// if(local_trans_pos.frame != (pkthdr->transport_frame + (pkthdr->latency) * nframes)) {
// jack_transport_locate(netj->client, (pkthdr->transport_frame + (pkthdr->latency + 2) * nframes));
// jack_info("running locate to %d", pkthdr->transport_frame + (pkthdr->latency)*nframes);
-// }
- if (local_trans_state != JackTransportRolling)
- jack_transport_start (netj->client);
- break;
+// }
+ if (local_trans_state != JackTransportRolling) {
+ jack_transport_start (netj->client);
+ }
+ break;
- case JackTransportLooping:
- break;
- }
- }
+ case JackTransportLooping:
+ break;
+ }
+ }
- render_payload_to_jack_ports (netj->bitdepth, packet_bufX, netj->net_period_down, netj->capture_ports, netj->capture_srcs, nframes, netj->dont_htonl_floats );
- packet_cache_release_packet(netj->packcache, netj->expected_framecnt );
+ render_payload_to_jack_ports (netj->bitdepth, packet_bufX, netj->net_period_down, netj->capture_ports, netj->capture_srcs, nframes, netj->dont_htonl_floats );
+ packet_cache_release_packet (netj->packcache, netj->expected_framecnt );
- return 0;
+ return 0;
}
static int
net_driver_write (net_driver_t* driver, jack_nframes_t nframes)
{
- netjack_driver_state_t *netj = &(driver->netj);
+ netjack_driver_state_t *netj = &(driver->netj);
- int sync_state = (driver->engine->control->sync_remain <= 1);;
+ int sync_state = (driver->engine->control->sync_remain <= 1);;
- uint32_t *packet_buf, *packet_bufX;
+ uint32_t *packet_buf, *packet_bufX;
- int packet_size = get_sample_size(netj->bitdepth) * netj->playback_channels * netj->net_period_up + sizeof(jacknet_packet_header);
- jacknet_packet_header *pkthdr;
+ int packet_size = get_sample_size (netj->bitdepth) * netj->playback_channels * netj->net_period_up + sizeof(jacknet_packet_header);
+ jacknet_packet_header *pkthdr;
- packet_buf = alloca(packet_size);
- pkthdr = (jacknet_packet_header *)packet_buf;
+ packet_buf = alloca (packet_size);
+ pkthdr = (jacknet_packet_header*)packet_buf;
- if( netj->running_free ) {
- return 0;
- }
-
- // offset packet_bufX by the packetheader.
- packet_bufX = packet_buf + sizeof(jacknet_packet_header) / sizeof(jack_default_audio_sample_t);
-
- // clear unused header fields
- pkthdr->capture_channels_audio = 0;
- pkthdr->playback_channels_audio = 0;
- pkthdr->capture_channels_midi = 0;
- pkthdr->playback_channels_midi = 0;
- pkthdr->period_size = 0;
- pkthdr->sample_rate = 0;
- pkthdr->transport_frame = 0;
- pkthdr->transport_state = 0;
- pkthdr->framecnt = 0;
- pkthdr->reply_port = 0;
- pkthdr->mtu = 0;
-
- // set used header fields
- pkthdr->sync_state = sync_state;
- pkthdr->latency = netj->time_to_deadline;
- //printf( "time to deadline = %d goodness=%d\n", (int)netj->time_to_deadline, netj->deadline_goodness );
- pkthdr->framecnt = netj->expected_framecnt;
-
-
- render_jack_ports_to_payload(netj->bitdepth, netj->playback_ports, netj->playback_srcs, nframes, packet_bufX, netj->net_period_up, netj->dont_htonl_floats );
-
- packet_header_hton(pkthdr);
- if (netj->srcaddress_valid)
- {
- int r;
+ if ( netj->running_free ) {
+ return 0;
+ }
+
+ // offset packet_bufX by the packetheader.
+ packet_bufX = packet_buf + sizeof(jacknet_packet_header) / sizeof(jack_default_audio_sample_t);
+
+ // clear unused header fields
+ pkthdr->capture_channels_audio = 0;
+ pkthdr->playback_channels_audio = 0;
+ pkthdr->capture_channels_midi = 0;
+ pkthdr->playback_channels_midi = 0;
+ pkthdr->period_size = 0;
+ pkthdr->sample_rate = 0;
+ pkthdr->transport_frame = 0;
+ pkthdr->transport_state = 0;
+ pkthdr->framecnt = 0;
+ pkthdr->reply_port = 0;
+ pkthdr->mtu = 0;
+
+ // set used header fields
+ pkthdr->sync_state = sync_state;
+ pkthdr->latency = netj->time_to_deadline;
+ //printf( "time to deadline = %d goodness=%d\n", (int)netj->time_to_deadline, netj->deadline_goodness );
+ pkthdr->framecnt = netj->expected_framecnt;
+
+
+ render_jack_ports_to_payload (netj->bitdepth, netj->playback_ports, netj->playback_srcs, nframes, packet_bufX, netj->net_period_up, netj->dont_htonl_floats );
+
+ packet_header_hton (pkthdr);
+ if (netj->srcaddress_valid) {
+ int r;
#ifndef MSG_CONFIRM
- static const int flag = 0;
+ static const int flag = 0;
#else
- static const int flag = MSG_CONFIRM;
+ static const int flag = MSG_CONFIRM;
#endif
- if (netj->reply_port)
- netj->syncsource_address.sin_port = htons(netj->reply_port);
+ if (netj->reply_port) {
+ netj->syncsource_address.sin_port = htons (netj->reply_port);
+ }
- for( r=0; r<netj->redundancy; r++ )
- netjack_sendto(netj->sockfd, (char *)packet_buf, packet_size,
- flag, (struct sockaddr*)&(netj->syncsource_address), sizeof(struct sockaddr_in), netj->mtu);
- }
+ for ( r = 0; r < netj->redundancy; r++ )
+ netjack_sendto (netj->sockfd, (char*)packet_buf, packet_size,
+ flag, (struct sockaddr*)&(netj->syncsource_address), sizeof(struct sockaddr_in), netj->mtu);
+ }
- return 0;
+ return 0;
}
static int
net_driver_attach (net_driver_t *driver)
{
- netjack_driver_state_t *netj = &( driver->netj );
- if (driver->engine->set_buffer_size (driver->engine, netj->period_size)) {
- jack_error ("netjack: cannot set engine buffer size to %d (check MIDI)", netj->period_size);
- return -1;
- }
- driver->engine->set_sample_rate (driver->engine, netj->sample_rate);
-
- netjack_attach( netj );
- return 0;
+ netjack_driver_state_t *netj = &( driver->netj );
+
+ if (driver->engine->set_buffer_size (driver->engine, netj->period_size)) {
+ jack_error ("netjack: cannot set engine buffer size to %d (check MIDI)", netj->period_size);
+ return -1;
+ }
+ driver->engine->set_sample_rate (driver->engine, netj->sample_rate);
+
+ netjack_attach ( netj );
+ return 0;
}
static int
net_driver_detach (net_driver_t *driver)
{
- netjack_driver_state_t *netj = &( driver->netj );
+ netjack_driver_state_t *netj = &( driver->netj );
- if (driver->engine == 0)
- return 0;
+ if (driver->engine == 0) {
+ return 0;
+ }
- netjack_detach( netj );
- return 0;
+ netjack_detach ( netj );
+ return 0;
}
static void
net_driver_delete (net_driver_t *driver)
{
- netjack_driver_state_t *netj = &( driver->netj );
- netjack_release( netj );
- jack_driver_nt_finish ((jack_driver_nt_t *) driver);
- free (driver);
+ netjack_driver_state_t *netj = &( driver->netj );
+
+ netjack_release ( netj );
+ jack_driver_nt_finish ((jack_driver_nt_t*)driver);
+ free (driver);
}
static jack_driver_t *
net_driver_new (jack_client_t * client,
- char *name,
- unsigned int capture_ports,
- unsigned int playback_ports,
- unsigned int capture_ports_midi,
- unsigned int playback_ports_midi,
- jack_nframes_t sample_rate,
- jack_nframes_t period_size,
- unsigned int listen_port,
- unsigned int transport_sync,
- unsigned int resample_factor,
- unsigned int resample_factor_up,
- unsigned int bitdepth,
+ char *name,
+ unsigned int capture_ports,
+ unsigned int playback_ports,
+ unsigned int capture_ports_midi,
+ unsigned int playback_ports_midi,
+ jack_nframes_t sample_rate,
+ jack_nframes_t period_size,
+ unsigned int listen_port,
+ unsigned int transport_sync,
+ unsigned int resample_factor,
+ unsigned int resample_factor_up,
+ unsigned int bitdepth,
unsigned int use_autoconfig,
unsigned int latency,
unsigned int redundancy,
@@ -334,60 +344,60 @@ net_driver_new (jack_client_t * client,
int always_deadline,
int jitter_val)
{
- net_driver_t * driver;
-
- jack_info ("creating net driver ... %s|%" PRIu32 "|%" PRIu32
- "|%u|%u|%u|transport_sync:%u", name, sample_rate, period_size, listen_port,
- capture_ports, playback_ports, transport_sync);
-
- driver = (net_driver_t *) calloc (1, sizeof (net_driver_t));
-
- jack_driver_nt_init ((jack_driver_nt_t *) driver);
-
- driver->write = (JackDriverWriteFunction) net_driver_write;
- driver->read = (JackDriverReadFunction) net_driver_read;
- driver->null_cycle = (JackDriverNullCycleFunction) net_driver_null_cycle;
- driver->nt_attach = (JackDriverNTAttachFunction) net_driver_attach;
- driver->nt_detach = (JackDriverNTDetachFunction) net_driver_detach;
- driver->nt_bufsize = (JackDriverNTBufSizeFunction) net_driver_bufsize;
- driver->nt_run_cycle = (JackDriverNTRunCycleFunction) net_driver_run_cycle;
-
- driver->last_wait_ust = 0;
- driver->engine = NULL;
-
- netjack_driver_state_t *netj = &(driver->netj);
-
- netjack_init ( netj,
- client,
- name,
- capture_ports,
- playback_ports,
- capture_ports_midi,
- playback_ports_midi,
- sample_rate,
- period_size,
- listen_port,
- transport_sync,
- resample_factor,
- resample_factor_up,
- bitdepth,
- use_autoconfig,
- latency,
- redundancy,
- dont_htonl_floats,
- always_deadline,
- jitter_val );
-
- netjack_startup( netj );
-
- jack_info ("netjack: period : up: %d / dn: %d", netj->net_period_up, netj->net_period_down);
- jack_info ("netjack: framerate: %d", netj->sample_rate);
- jack_info ("netjack: audio : cap: %d / pbk: %d)", netj->capture_channels_audio, netj->playback_channels_audio);
- jack_info ("netjack: midi : cap: %d / pbk: %d)", netj->capture_channels_midi, netj->playback_channels_midi);
- jack_info ("netjack: buffsize : rx: %d)", netj->rx_bufsize);
- driver->period_usecs = netj->period_usecs;
-
- return (jack_driver_t *) driver;
+ net_driver_t * driver;
+
+ jack_info ("creating net driver ... %s|%" PRIu32 "|%" PRIu32
+ "|%u|%u|%u|transport_sync:%u", name, sample_rate, period_size, listen_port,
+ capture_ports, playback_ports, transport_sync);
+
+ driver = (net_driver_t*)calloc (1, sizeof(net_driver_t));
+
+ jack_driver_nt_init ((jack_driver_nt_t*)driver);
+
+ driver->write = (JackDriverWriteFunction)net_driver_write;
+ driver->read = (JackDriverReadFunction)net_driver_read;
+ driver->null_cycle = (JackDriverNullCycleFunction)net_driver_null_cycle;
+ driver->nt_attach = (JackDriverNTAttachFunction)net_driver_attach;
+ driver->nt_detach = (JackDriverNTDetachFunction)net_driver_detach;
+ driver->nt_bufsize = (JackDriverNTBufSizeFunction)net_driver_bufsize;
+ driver->nt_run_cycle = (JackDriverNTRunCycleFunction)net_driver_run_cycle;
+
+ driver->last_wait_ust = 0;
+ driver->engine = NULL;
+
+ netjack_driver_state_t *netj = &(driver->netj);
+
+ netjack_init ( netj,
+ client,
+ name,
+ capture_ports,
+ playback_ports,
+ capture_ports_midi,
+ playback_ports_midi,
+ sample_rate,
+ period_size,
+ listen_port,
+ transport_sync,
+ resample_factor,
+ resample_factor_up,
+ bitdepth,
+ use_autoconfig,
+ latency,
+ redundancy,
+ dont_htonl_floats,
+ always_deadline,
+ jitter_val );
+
+ netjack_startup ( netj );
+
+ jack_info ("netjack: period : up: %d / dn: %d", netj->net_period_up, netj->net_period_down);
+ jack_info ("netjack: framerate: %d", netj->sample_rate);
+ jack_info ("netjack: audio : cap: %d / pbk: %d)", netj->capture_channels_audio, netj->playback_channels_audio);
+ jack_info ("netjack: midi : cap: %d / pbk: %d)", netj->capture_channels_midi, netj->playback_channels_midi);
+ jack_info ("netjack: buffsize : rx: %d)", netj->rx_bufsize);
+ driver->period_usecs = netj->period_usecs;
+
+ return (jack_driver_t*)driver;
}
/* DRIVER "PLUGIN" INTERFACE */
@@ -395,173 +405,173 @@ net_driver_new (jack_client_t * client,
jack_driver_desc_t *
driver_get_descriptor ()
{
- jack_driver_desc_t * desc;
- jack_driver_param_desc_t * params;
- unsigned int i;
-
- desc = calloc (1, sizeof (jack_driver_desc_t));
- strcpy (desc->name, "net");
- desc->nparams = 18;
-
- params = calloc (desc->nparams, sizeof (jack_driver_param_desc_t));
-
- i = 0;
- strcpy (params[i].name, "audio-ins");
- params[i].character = 'i';
- params[i].type = JackDriverParamUInt;
- params[i].value.ui = 2U;
- strcpy (params[i].short_desc, "Number of capture channels (defaults to 2)");
- strcpy (params[i].long_desc, params[i].short_desc);
-
- i++;
- strcpy (params[i].name, "audio-outs");
- params[i].character = 'o';
- params[i].type = JackDriverParamUInt;
- params[i].value.ui = 2U;
- strcpy (params[i].short_desc, "Number of playback channels (defaults to 2)");
- strcpy (params[i].long_desc, params[i].short_desc);
-
- i++;
- strcpy (params[i].name, "midi-ins");
- params[i].character = 'I';
- params[i].type = JackDriverParamUInt;
- params[i].value.ui = 1U;
- strcpy (params[i].short_desc, "Number of midi capture channels (defaults to 1)");
- strcpy (params[i].long_desc, params[i].short_desc);
-
- i++;
- strcpy (params[i].name, "midi-outs");
- params[i].character = 'O';
- params[i].type = JackDriverParamUInt;
- params[i].value.ui = 1U;
- strcpy (params[i].short_desc, "Number of midi playback channels (defaults to 1)");
- strcpy (params[i].long_desc, params[i].short_desc);
-
- i++;
- strcpy (params[i].name, "rate");
- params[i].character = 'r';
- params[i].type = JackDriverParamUInt;
- params[i].value.ui = 48000U;
- strcpy (params[i].short_desc, "Sample rate");
- strcpy (params[i].long_desc, params[i].short_desc);
-
- i++;
- strcpy (params[i].name, "period");
- params[i].character = 'p';
- params[i].type = JackDriverParamUInt;
- params[i].value.ui = 1024U;
- strcpy (params[i].short_desc, "Frames per period");
- strcpy (params[i].long_desc, params[i].short_desc);
-
- i++;
- strcpy (params[i].name, "num-periods");
- params[i].character = 'n';
- params[i].type = JackDriverParamUInt;
- params[i].value.ui = 5U;
- strcpy (params[i].short_desc,
- "Network latency setting in no. of periods");
- strcpy (params[i].long_desc, params[i].short_desc);
-
- i++;
- strcpy (params[i].name, "listen-port");
- params[i].character = 'l';
- params[i].type = JackDriverParamUInt;
- params[i].value.ui = 3000U;
- strcpy (params[i].short_desc,
- "The socket port we are listening on for sync packets");
- strcpy (params[i].long_desc, params[i].short_desc);
-
- i++;
- strcpy (params[i].name, "factor");
- params[i].character = 'f';
- params[i].type = JackDriverParamUInt;
- params[i].value.ui = 1U;
- strcpy (params[i].short_desc,
- "Factor for sample rate reduction (deprecated)");
- strcpy (params[i].long_desc, params[i].short_desc);
-
- i++;
- strcpy (params[i].name, "upstream-factor");
- params[i].character = 'u';
- params[i].type = JackDriverParamUInt;
- params[i].value.ui = 0U;
- strcpy (params[i].short_desc,
- "Factor for sample rate reduction on the upstream (deprecated)");
- strcpy (params[i].long_desc, params[i].short_desc);
-
- i++;
- strcpy (params[i].name, "celt");
- params[i].character = 'c';
- params[i].type = JackDriverParamUInt;
- params[i].value.ui = 0U;
- strcpy (params[i].short_desc,
- "sets celt encoding and kbits value one channel is encoded at");
- strcpy (params[i].long_desc, params[i].short_desc);
-
- i++;
- strcpy (params[i].name, "bit-depth");
- params[i].character = 'b';
- params[i].type = JackDriverParamUInt;
- params[i].value.ui = 0U;
- strcpy (params[i].short_desc,
- "Sample bit-depth (0 for float, 8 for 8bit and 16 for 16bit)");
- strcpy (params[i].long_desc, params[i].short_desc);
-
- i++;
- strcpy (params[i].name, "transport-sync");
- params[i].character = 't';
- params[i].type = JackDriverParamUInt;
- params[i].value.ui = 1U;
- strcpy (params[i].short_desc,
- "Whether to slave the transport to the master transport");
- strcpy (params[i].long_desc, params[i].short_desc);
-
- i++;
- strcpy (params[i].name, "autoconf");
- params[i].character = 'a';
- params[i].type = JackDriverParamUInt;
- params[i].value.ui = 1U;
- strcpy (params[i].short_desc,
- "Whether to use Autoconfig, or just start.");
- strcpy (params[i].long_desc, params[i].short_desc);
- i++;
- strcpy (params[i].name, "redundancy");
- params[i].character = 'R';
- params[i].type = JackDriverParamUInt;
- params[i].value.ui = 1U;
- strcpy (params[i].short_desc,
- "Send packets N times");
- strcpy (params[i].long_desc, params[i].short_desc);
-
- i++;
- strcpy (params[i].name, "native-endian");
- params[i].character = 'e';
- params[i].type = JackDriverParamUInt;
- params[i].value.ui = 0U;
- strcpy (params[i].short_desc,
- "Don't convert samples to network byte order.");
- strcpy (params[i].long_desc, params[i].short_desc);
-
- i++;
- strcpy (params[i].name, "jitterval");
- params[i].character = 'J';
- params[i].type = JackDriverParamInt;
- params[i].value.i = 0;
- strcpy (params[i].short_desc,
- "attempted jitterbuffer microseconds on master");
- strcpy (params[i].long_desc, params[i].short_desc);
-
- i++;
- strcpy (params[i].name, "always-deadline");
- params[i].character = 'D';
- params[i].type = JackDriverParamUInt;
- params[i].value.ui = 0U;
- strcpy (params[i].short_desc,
- "Always wait until deadline");
- strcpy (params[i].long_desc, params[i].short_desc);
- desc->params = params;
-
- return desc;
+ jack_driver_desc_t * desc;
+ jack_driver_param_desc_t * params;
+ unsigned int i;
+
+ desc = calloc (1, sizeof(jack_driver_desc_t));
+ strcpy (desc->name, "net");
+ desc->nparams = 18;
+
+ params = calloc (desc->nparams, sizeof(jack_driver_param_desc_t));
+
+ i = 0;
+ strcpy (params[i].name, "audio-ins");
+ params[i].character = 'i';
+ params[i].type = JackDriverParamUInt;
+ params[i].value.ui = 2U;
+ strcpy (params[i].short_desc, "Number of capture channels (defaults to 2)");
+ strcpy (params[i].long_desc, params[i].short_desc);
+
+ i++;
+ strcpy (params[i].name, "audio-outs");
+ params[i].character = 'o';
+ params[i].type = JackDriverParamUInt;
+ params[i].value.ui = 2U;
+ strcpy (params[i].short_desc, "Number of playback channels (defaults to 2)");
+ strcpy (params[i].long_desc, params[i].short_desc);
+
+ i++;
+ strcpy (params[i].name, "midi-ins");
+ params[i].character = 'I';
+ params[i].type = JackDriverParamUInt;
+ params[i].value.ui = 1U;
+ strcpy (params[i].short_desc, "Number of midi capture channels (defaults to 1)");
+ strcpy (params[i].long_desc, params[i].short_desc);
+
+ i++;
+ strcpy (params[i].name, "midi-outs");
+ params[i].character = 'O';
+ params[i].type = JackDriverParamUInt;
+ params[i].value.ui = 1U;
+ strcpy (params[i].short_desc, "Number of midi playback channels (defaults to 1)");
+ strcpy (params[i].long_desc, params[i].short_desc);
+
+ i++;
+ strcpy (params[i].name, "rate");
+ params[i].character = 'r';
+ params[i].type = JackDriverParamUInt;
+ params[i].value.ui = 48000U;
+ strcpy (params[i].short_desc, "Sample rate");
+ strcpy (params[i].long_desc, params[i].short_desc);
+
+ i++;
+ strcpy (params[i].name, "period");
+ params[i].character = 'p';
+ params[i].type = JackDriverParamUInt;
+ params[i].value.ui = 1024U;
+ strcpy (params[i].short_desc, "Frames per period");
+ strcpy (params[i].long_desc, params[i].short_desc);
+
+ i++;
+ strcpy (params[i].name, "num-periods");
+ params[i].character = 'n';
+ params[i].type = JackDriverParamUInt;
+ params[i].value.ui = 5U;
+ strcpy (params[i].short_desc,
+ "Network latency setting in no. of periods");
+ strcpy (params[i].long_desc, params[i].short_desc);
+
+ i++;
+ strcpy (params[i].name, "listen-port");
+ params[i].character = 'l';
+ params[i].type = JackDriverParamUInt;
+ params[i].value.ui = 3000U;
+ strcpy (params[i].short_desc,
+ "The socket port we are listening on for sync packets");
+ strcpy (params[i].long_desc, params[i].short_desc);
+
+ i++;
+ strcpy (params[i].name, "factor");
+ params[i].character = 'f';
+ params[i].type = JackDriverParamUInt;
+ params[i].value.ui = 1U;
+ strcpy (params[i].short_desc,
+ "Factor for sample rate reduction (deprecated)");
+ strcpy (params[i].long_desc, params[i].short_desc);
+
+ i++;
+ strcpy (params[i].name, "upstream-factor");
+ params[i].character = 'u';
+ params[i].type = JackDriverParamUInt;
+ params[i].value.ui = 0U;
+ strcpy (params[i].short_desc,
+ "Factor for sample rate reduction on the upstream (deprecated)");
+ strcpy (params[i].long_desc, params[i].short_desc);
+
+ i++;
+ strcpy (params[i].name, "celt");
+ params[i].character = 'c';
+ params[i].type = JackDriverParamUInt;
+ params[i].value.ui = 0U;
+ strcpy (params[i].short_desc,
+ "sets celt encoding and kbits value one channel is encoded at");
+ strcpy (params[i].long_desc, params[i].short_desc);
+
+ i++;
+ strcpy (params[i].name, "bit-depth");
+ params[i].character = 'b';
+ params[i].type = JackDriverParamUInt;
+ params[i].value.ui = 0U;
+ strcpy (params[i].short_desc,
+ "Sample bit-depth (0 for float, 8 for 8bit and 16 for 16bit)");
+ strcpy (params[i].long_desc, params[i].short_desc);
+
+ i++;
+ strcpy (params[i].name, "transport-sync");
+ params[i].character = 't';
+ params[i].type = JackDriverParamUInt;
+ params[i].value.ui = 1U;
+ strcpy (params[i].short_desc,
+ "Whether to slave the transport to the master transport");
+ strcpy (params[i].long_desc, params[i].short_desc);
+
+ i++;
+ strcpy (params[i].name, "autoconf");
+ params[i].character = 'a';
+ params[i].type = JackDriverParamUInt;
+ params[i].value.ui = 1U;
+ strcpy (params[i].short_desc,
+ "Whether to use Autoconfig, or just start.");
+ strcpy (params[i].long_desc, params[i].short_desc);
+ i++;
+ strcpy (params[i].name, "redundancy");
+ params[i].character = 'R';
+ params[i].type = JackDriverParamUInt;
+ params[i].value.ui = 1U;
+ strcpy (params[i].short_desc,
+ "Send packets N times");
+ strcpy (params[i].long_desc, params[i].short_desc);
+
+ i++;
+ strcpy (params[i].name, "native-endian");
+ params[i].character = 'e';
+ params[i].type = JackDriverParamUInt;
+ params[i].value.ui = 0U;
+ strcpy (params[i].short_desc,
+ "Don't convert samples to network byte order.");
+ strcpy (params[i].long_desc, params[i].short_desc);
+
+ i++;
+ strcpy (params[i].name, "jitterval");
+ params[i].character = 'J';
+ params[i].type = JackDriverParamInt;
+ params[i].value.i = 0;
+ strcpy (params[i].short_desc,
+ "attempted jitterbuffer microseconds on master");
+ strcpy (params[i].long_desc, params[i].short_desc);
+
+ i++;
+ strcpy (params[i].name, "always-deadline");
+ params[i].character = 'D';
+ params[i].type = JackDriverParamUInt;
+ params[i].value.ui = 0U;
+ strcpy (params[i].short_desc,
+ "Always wait until deadline");
+ strcpy (params[i].long_desc, params[i].short_desc);
+ desc->params = params;
+
+ return desc;
}
const char driver_client_name[] = "net_pcm";
@@ -569,130 +579,130 @@ const char driver_client_name[] = "net_pcm";
jack_driver_t *
driver_initialize (jack_client_t *client, const JSList * params)
{
- jack_nframes_t sample_rate = 48000;
- jack_nframes_t resample_factor = 1;
- jack_nframes_t period_size = 1024;
- unsigned int capture_ports = 2;
- unsigned int playback_ports = 2;
- unsigned int capture_ports_midi = 1;
- unsigned int playback_ports_midi = 1;
- unsigned int listen_port = 3000;
- unsigned int resample_factor_up = 0;
- unsigned int bitdepth = 0;
- unsigned int handle_transport_sync = 1;
- unsigned int use_autoconfig = 1;
- unsigned int latency = 5;
- unsigned int redundancy = 1;
- int dont_htonl_floats = 0;
- int always_deadline = 0;
- int jitter_val = 0;
- const JSList * node;
- const jack_driver_param_t * param;
-
- for (node = params; node; node = jack_slist_next (node)) {
- param = (const jack_driver_param_t *) node->data;
-
- switch (param->character) {
-
- case 'i':
- capture_ports = param->value.ui;
- break;
-
- case 'o':
- playback_ports = param->value.ui;
- break;
-
- case 'I':
- capture_ports_midi = param->value.ui;
- break;
-
- case 'O':
- playback_ports_midi = param->value.ui;
- break;
-
- case 'r':
- sample_rate = param->value.ui;
- break;
-
- case 'p':
- period_size = param->value.ui;
- break;
-
- case 'l':
- listen_port = param->value.ui;
- break;
-
- case 'f':
+ jack_nframes_t sample_rate = 48000;
+ jack_nframes_t resample_factor = 1;
+ jack_nframes_t period_size = 1024;
+ unsigned int capture_ports = 2;
+ unsigned int playback_ports = 2;
+ unsigned int capture_ports_midi = 1;
+ unsigned int playback_ports_midi = 1;
+ unsigned int listen_port = 3000;
+ unsigned int resample_factor_up = 0;
+ unsigned int bitdepth = 0;
+ unsigned int handle_transport_sync = 1;
+ unsigned int use_autoconfig = 1;
+ unsigned int latency = 5;
+ unsigned int redundancy = 1;
+ int dont_htonl_floats = 0;
+ int always_deadline = 0;
+ int jitter_val = 0;
+ const JSList * node;
+ const jack_driver_param_t * param;
+
+ for (node = params; node; node = jack_slist_next (node)) {
+ param = (const jack_driver_param_t*)node->data;
+
+ switch (param->character) {
+
+ case 'i':
+ capture_ports = param->value.ui;
+ break;
+
+ case 'o':
+ playback_ports = param->value.ui;
+ break;
+
+ case 'I':
+ capture_ports_midi = param->value.ui;
+ break;
+
+ case 'O':
+ playback_ports_midi = param->value.ui;
+ break;
+
+ case 'r':
+ sample_rate = param->value.ui;
+ break;
+
+ case 'p':
+ period_size = param->value.ui;
+ break;
+
+ case 'l':
+ listen_port = param->value.ui;
+ break;
+
+ case 'f':
#if HAVE_SAMPLERATE
- resample_factor = param->value.ui;
+ resample_factor = param->value.ui;
#else
- printf( "not built with libsamplerate support\n" );
- exit(10);
+ printf ( "not built with libsamplerate support\n" );
+ exit (10);
#endif
- break;
+ break;
- case 'u':
+ case 'u':
#if HAVE_SAMPLERATE
- resample_factor_up = param->value.ui;
+ resample_factor_up = param->value.ui;
#else
- printf( "not built with libsamplerate support\n" );
- exit(10);
+ printf ( "not built with libsamplerate support\n" );
+ exit (10);
#endif
- break;
+ break;
- case 'b':
- bitdepth = param->value.ui;
- break;
+ case 'b':
+ bitdepth = param->value.ui;
+ break;
- case 'c':
+ case 'c':
#if HAVE_CELT
- bitdepth = 1000;
- resample_factor = param->value.ui;
+ bitdepth = 1000;
+ resample_factor = param->value.ui;
#else
- printf( "not built with celt support\n" );
- exit(10);
+ printf ( "not built with celt support\n" );
+ exit (10);
#endif
- break;
-
- case 't':
- handle_transport_sync = param->value.ui;
- break;
-
- case 'a':
- use_autoconfig = param->value.ui;
- break;
-
- case 'n':
- latency = param->value.ui;
- break;
-
- case 'R':
- redundancy = param->value.ui;
- break;
-
- case 'e':
- dont_htonl_floats = param->value.ui;
- break;
- case 'J':
- jitter_val = param->value.i;
- break;
- case 'D':
- always_deadline = param->value.ui;
- break;
- }
- }
-
- return net_driver_new (client, "net_pcm", capture_ports, playback_ports,
- capture_ports_midi, playback_ports_midi,
- sample_rate, period_size,
- listen_port, handle_transport_sync,
- resample_factor, resample_factor_up, bitdepth,
- use_autoconfig, latency, redundancy,
- dont_htonl_floats, always_deadline, jitter_val);
+ break;
+
+ case 't':
+ handle_transport_sync = param->value.ui;
+ break;
+
+ case 'a':
+ use_autoconfig = param->value.ui;
+ break;
+
+ case 'n':
+ latency = param->value.ui;
+ break;
+
+ case 'R':
+ redundancy = param->value.ui;
+ break;
+
+ case 'e':
+ dont_htonl_floats = param->value.ui;
+ break;
+ case 'J':
+ jitter_val = param->value.i;
+ break;
+ case 'D':
+ always_deadline = param->value.ui;
+ break;
+ }
+ }
+
+ return net_driver_new (client, "net_pcm", capture_ports, playback_ports,
+ capture_ports_midi, playback_ports_midi,
+ sample_rate, period_size,
+ listen_port, handle_transport_sync,
+ resample_factor, resample_factor_up, bitdepth,
+ use_autoconfig, latency, redundancy,
+ dont_htonl_floats, always_deadline, jitter_val);
}
void
driver_finish (jack_driver_t *driver)
{
- net_driver_delete ((net_driver_t *) driver);
+ net_driver_delete ((net_driver_t*)driver);
}
diff --git a/drivers/netjack/net_driver.h b/drivers/netjack/net_driver.h
index da4258d..0b73583 100644
--- a/drivers/netjack/net_driver.h
+++ b/drivers/netjack/net_driver.h
@@ -15,7 +15,7 @@
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 __JACK_NET_DRIVER_H__
@@ -35,11 +35,10 @@
typedef struct _net_driver net_driver_t;
-struct _net_driver
-{
- JACK_DRIVER_NT_DECL;
+struct _net_driver {
+ JACK_DRIVER_NT_DECL;
- netjack_driver_state_t netj;
+ netjack_driver_state_t netj;
};
#endif /* __JACK_NET_DRIVER_H__ */
diff --git a/drivers/netjack/netjack.c b/drivers/netjack/netjack.c
index f3afe4e..5d26e4b 100644
--- a/drivers/netjack/netjack.c
+++ b/drivers/netjack/netjack.c
@@ -1,29 +1,29 @@
/* -*- mode: c; c-file-style: "linux"; -*- */
/*
-NetJack Abstraction.
+ NetJack Abstraction.
-Copyright (C) 2008 Pieter Palmers <pieterpalmers@users.sourceforge.net>
-Copyright (C) 2006 Torben Hohn <torbenh@gmx.de>
-Copyright (C) 2003 Robert Ham <rah@bash.sh>
-Copyright (C) 2001 Paul Davis
+ Copyright (C) 2008 Pieter Palmers <pieterpalmers@users.sourceforge.net>
+ Copyright (C) 2006 Torben Hohn <torbenh@gmx.de>
+ Copyright (C) 2003 Robert Ham <rah@bash.sh>
+ Copyright (C) 2001 Paul Davis
-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 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.
+ 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.
+ 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.
-$Id: net_driver.c,v 1.17 2006/04/16 20:16:10 torbenh Exp $
-*/
+ $Id: net_driver.c,v 1.17 2006/04/16 20:16:10 torbenh Exp $
+ */
#include <math.h>
@@ -69,740 +69,736 @@ $Id: net_driver.c,v 1.17 2006/04/16 20:16:10 torbenh Exp $
// JACK2
//#include "jack/control.h"
-#define MIN(x,y) ((x)<(y) ? (x) : (y))
+#define MIN(x, y) ((x) < (y) ? (x) : (y))
static int sync_state = 1;
static jack_transport_state_t last_transport_state;
static int
-net_driver_sync_cb(jack_transport_state_t state, jack_position_t *pos, void *data)
+net_driver_sync_cb (jack_transport_state_t state, jack_position_t *pos, void *data)
{
- int retval = sync_state;
+ int retval = sync_state;
- if (state == JackTransportStarting && last_transport_state != JackTransportStarting) {
- retval = 0;
- }
+ if (state == JackTransportStarting && last_transport_state != JackTransportStarting) {
+ retval = 0;
+ }
// if (state == JackTransportStarting)
// jack_info("Starting sync_state = %d", sync_state);
- last_transport_state = state;
- return retval;
+ last_transport_state = state;
+ return retval;
}
-int netjack_wait( netjack_driver_state_t *netj, jack_time_t (*get_microseconds)(void) )
+int netjack_wait ( netjack_driver_state_t *netj, jack_time_t (*get_microseconds)(void) )
{
- int we_have_the_expected_frame = 0;
- jack_nframes_t next_frame_avail;
- jack_time_t packet_recv_time_stamp;
- jacknet_packet_header *pkthdr;
-
- if( !netj->next_deadline_valid ) {
- netj->next_deadline = get_microseconds() + netj->period_usecs;
- netj->next_deadline_valid = 1;
- }
-
- // Increment expected frame here.
-
- if( netj->expected_framecnt_valid ) {
- netj->expected_framecnt += 1;
- } else {
- // starting up.... lets look into the packetcache, and fetch the highest packet.
- packet_cache_drain_socket( netj->packcache, netj->sockfd, get_microseconds );
- if( packet_cache_get_highest_available_framecnt( netj->packcache, &next_frame_avail ) ) {
- netj->expected_framecnt = next_frame_avail;
- netj->expected_framecnt_valid = 1;
+ int we_have_the_expected_frame = 0;
+ jack_nframes_t next_frame_avail;
+ jack_time_t packet_recv_time_stamp;
+ jacknet_packet_header *pkthdr;
+
+ if ( !netj->next_deadline_valid ) {
+ netj->next_deadline = get_microseconds () + netj->period_usecs;
+ netj->next_deadline_valid = 1;
+ }
+
+ // Increment expected frame here.
+
+ if ( netj->expected_framecnt_valid ) {
+ netj->expected_framecnt += 1;
} else {
- // no packets there... start normally.
- netj->expected_framecnt = 0;
- netj->expected_framecnt_valid = 1;
+ // starting up.... lets look into the packetcache, and fetch the highest packet.
+ packet_cache_drain_socket ( netj->packcache, netj->sockfd, get_microseconds );
+ if ( packet_cache_get_highest_available_framecnt ( netj->packcache, &next_frame_avail ) ) {
+ netj->expected_framecnt = next_frame_avail;
+ netj->expected_framecnt_valid = 1;
+ } else {
+ // no packets there... start normally.
+ netj->expected_framecnt = 0;
+ netj->expected_framecnt_valid = 1;
+ }
+
}
- }
-
- //jack_log( "expect %d", netj->expected_framecnt );
- // Now check if required packet is already in the cache.
- // then poll (have deadline calculated)
- // then drain socket, rinse and repeat.
- while(1) {
- if( packet_cache_get_next_available_framecnt( netj->packcache, netj->expected_framecnt, &next_frame_avail) ) {
- if( next_frame_avail == netj->expected_framecnt ) {
- we_have_the_expected_frame = 1;
- if( !netj->always_deadline )
+ //jack_log( "expect %d", netj->expected_framecnt );
+ // Now check if required packet is already in the cache.
+ // then poll (have deadline calculated)
+ // then drain socket, rinse and repeat.
+ while (1) {
+ if ( packet_cache_get_next_available_framecnt ( netj->packcache, netj->expected_framecnt, &next_frame_avail) ) {
+ if ( next_frame_avail == netj->expected_framecnt ) {
+ we_have_the_expected_frame = 1;
+ if ( !netj->always_deadline ) {
+ break;
+ }
+ }
+ }
+ if ( !netjack_poll_deadline ( netj->sockfd, netj->next_deadline, get_microseconds ) ) {
break;
- }
- }
- if( ! netjack_poll_deadline( netj->sockfd, netj->next_deadline, get_microseconds ) ) {
- break;
- }
+ }
- packet_cache_drain_socket( netj->packcache, netj->sockfd, get_microseconds );
- }
+ packet_cache_drain_socket ( netj->packcache, netj->sockfd, get_microseconds );
+ }
- // check if we know who to send our packets too.
- if (!netj->srcaddress_valid)
- if( netj->packcache->master_address_valid ) {
- memcpy (&(netj->syncsource_address), &(netj->packcache->master_address), sizeof( struct sockaddr_in ) );
- netj->srcaddress_valid = 1;
+ // check if we know who to send our packets too.
+ if (!netj->srcaddress_valid) {
+ if ( netj->packcache->master_address_valid ) {
+ memcpy (&(netj->syncsource_address), &(netj->packcache->master_address), sizeof( struct sockaddr_in ) );
+ netj->srcaddress_valid = 1;
+ }
}
- // XXX: switching mode unconditionally is stupid.
- // if we were running free perhaps we like to behave differently
- // ie. fastforward one packet etc.
- // well... this is the first packet we see. hmm.... dunno ;S
- // it works... so...
- netj->running_free = 0;
+ // XXX: switching mode unconditionally is stupid.
+ // if we were running free perhaps we like to behave differently
+ // ie. fastforward one packet etc.
+ // well... this is the first packet we see. hmm.... dunno ;S
+ // it works... so...
+ netj->running_free = 0;
- //if( !we_have_the_expected_frame )
- // jack_error( "netxrun... %d", netj->expected_framecnt );
+ //if( !we_have_the_expected_frame )
+ // jack_error( "netxrun... %d", netj->expected_framecnt );
- if( we_have_the_expected_frame ) {
+ if ( we_have_the_expected_frame ) {
- jack_time_t now = get_microseconds();
- if( now < netj->next_deadline )
- netj->time_to_deadline = netj->next_deadline - now;
- else
- netj->time_to_deadline = 0;
+ jack_time_t now = get_microseconds ();
+ if ( now < netj->next_deadline ) {
+ netj->time_to_deadline = netj->next_deadline - now;
+ } else {
+ netj->time_to_deadline = 0;
+ }
- packet_cache_retreive_packet_pointer( netj->packcache, netj->expected_framecnt, (char **) &(netj->rx_buf), netj->rx_bufsize , &packet_recv_time_stamp);
- pkthdr = (jacknet_packet_header *) netj->rx_buf;
- packet_header_ntoh(pkthdr);
- netj->deadline_goodness = (int)pkthdr->sync_state;
- netj->packet_data_valid = 1;
-
- int want_deadline;
- if( netj->jitter_val != 0 )
- want_deadline = netj->jitter_val;
- else if( netj->latency < 4 )
- want_deadline = -netj->period_usecs/2;
- else
- want_deadline = (netj->period_usecs/4+10*(int)netj->period_usecs*netj->latency/100);
-
- if( netj->deadline_goodness != MASTER_FREEWHEELS ) {
- if( netj->deadline_goodness < want_deadline ) {
- netj->next_deadline -= netj->period_usecs/100;
- //jack_log( "goodness: %d, Adjust deadline: --- %d\n", netj->deadline_goodness, (int) netj->period_usecs*netj->latency/100 );
+ packet_cache_retreive_packet_pointer ( netj->packcache, netj->expected_framecnt, (char**)&(netj->rx_buf), netj->rx_bufsize, &packet_recv_time_stamp);
+ pkthdr = (jacknet_packet_header*)netj->rx_buf;
+ packet_header_ntoh (pkthdr);
+ netj->deadline_goodness = (int)pkthdr->sync_state;
+ netj->packet_data_valid = 1;
+
+ int want_deadline;
+ if ( netj->jitter_val != 0 ) {
+ want_deadline = netj->jitter_val;
+ } else if ( netj->latency < 4 ) {
+ want_deadline = -netj->period_usecs / 2;
+ } else {
+ want_deadline = (netj->period_usecs / 4 + 10 * (int)netj->period_usecs * netj->latency / 100);
}
- if( netj->deadline_goodness > want_deadline ) {
- netj->next_deadline += netj->period_usecs/100;
- //jack_log( "goodness: %d, Adjust deadline: +++ %d\n", netj->deadline_goodness, (int) netj->period_usecs*netj->latency/100 );
+
+ if ( netj->deadline_goodness != MASTER_FREEWHEELS ) {
+ if ( netj->deadline_goodness < want_deadline ) {
+ netj->next_deadline -= netj->period_usecs / 100;
+ //jack_log( "goodness: %d, Adjust deadline: --- %d\n", netj->deadline_goodness, (int) netj->period_usecs*netj->latency/100 );
+ }
+ if ( netj->deadline_goodness > want_deadline ) {
+ netj->next_deadline += netj->period_usecs / 100;
+ //jack_log( "goodness: %d, Adjust deadline: +++ %d\n", netj->deadline_goodness, (int) netj->period_usecs*netj->latency/100 );
+ }
}
- }
// if( netj->next_deadline < (netj->period_usecs*70/100) ) {
// jack_error( "master is forcing deadline_offset to below 70%% of period_usecs... increase latency setting on master" );
// netj->deadline_offset = (netj->period_usecs*90/100);
// }
- netj->next_deadline += netj->period_usecs;
- } else {
- netj->time_to_deadline = 0;
- netj->next_deadline += netj->period_usecs;
- // bah... the packet is not there.
- // either
- // - it got lost.
- // - its late
- // - sync source is not sending anymore.
-
- // lets check if we have the next packets, we will just run a cycle without data.
- // in that case.
-
- if( packet_cache_get_next_available_framecnt( netj->packcache, netj->expected_framecnt, &next_frame_avail) )
- {
- jack_nframes_t offset = next_frame_avail - netj->expected_framecnt;
-
- //XXX: hmm... i need to remember why resync_threshold wasnt right.
- //if( offset < netj->resync_threshold )
- if( offset < 10 ) {
- // ok. dont do nothing. we will run without data.
- // this seems to be one or 2 lost packets.
- //
- // this can also be reordered packet jitter.
- // (maybe this is not happening in real live)
- // but it happens in netem.
-
- netj->packet_data_valid = 0;
-
- // I also found this happening, when the packet queue, is too full.
- // but wtf ? use a smaller latency. this link can handle that ;S
- if( packet_cache_get_fill( netj->packcache, netj->expected_framecnt ) > 80.0 )
- netj->next_deadline -= netj->period_usecs/2;
-
-
- } else {
- // the diff is too high. but we have a packet in the future.
- // lets resync.
- netj->expected_framecnt = next_frame_avail;
- packet_cache_retreive_packet_pointer( netj->packcache, netj->expected_framecnt, (char **) &(netj->rx_buf), netj->rx_bufsize, NULL );
- pkthdr = (jacknet_packet_header *) netj->rx_buf;
- packet_header_ntoh(pkthdr);
- //netj->deadline_goodness = 0;
- netj->deadline_goodness = (int)pkthdr->sync_state - (int)netj->period_usecs * offset;
- netj->next_deadline_valid = 0;
- netj->packet_data_valid = 1;
- }
-
+ netj->next_deadline += netj->period_usecs;
} else {
- // no packets in buffer.
- netj->packet_data_valid = 0;
-
- //printf( "frame %d No Packet in queue. num_lost_packets = %d \n", netj->expected_framecnt, netj->num_lost_packets );
- if( netj->num_lost_packets < 5 ) {
- // ok. No Packet in queue. The packet was either lost,
- // or we are running too fast.
- //
- // Adjusting the deadline unconditionally resulted in
- // too many xruns on master.
- // But we need to adjust for the case we are running too fast.
- // So lets check if the last packet is there now.
- //
- // It would not be in the queue anymore, if it had been
- // retrieved. This might break for redundancy, but
- // i will make the packet cache drop redundant packets,
- // that have already been retreived.
- //
- if( packet_cache_get_highest_available_framecnt( netj->packcache, &next_frame_avail) ) {
- if( next_frame_avail == (netj->expected_framecnt - 1) ) {
- // Ok. the last packet is there now.
- // and it had not been retrieved.
- //
- // TODO: We are still dropping 2 packets.
- // perhaps we can adjust the deadline
- // when (num_packets lost == 0)
-
- // This might still be too much.
- netj->next_deadline += netj->period_usecs;
- }
- }
- } else if( (netj->num_lost_packets <= 100) ) {
- // lets try adjusting the deadline harder, for some packets, we might have just ran 2 fast.
- netj->next_deadline += netj->period_usecs*netj->latency/8;
- } else {
-
- // But now we can check for any new frame available.
- //
- if( packet_cache_get_highest_available_framecnt( netj->packcache, &next_frame_avail) ) {
- netj->expected_framecnt = next_frame_avail;
- packet_cache_retreive_packet_pointer( netj->packcache, netj->expected_framecnt, (char **) &(netj->rx_buf), netj->rx_bufsize, NULL );
- pkthdr = (jacknet_packet_header *) netj->rx_buf;
- packet_header_ntoh(pkthdr);
- netj->deadline_goodness = pkthdr->sync_state;
- netj->next_deadline_valid = 0;
- netj->packet_data_valid = 1;
- netj->running_free = 0;
- jack_info( "resync after freerun... %d", netj->expected_framecnt );
+ netj->time_to_deadline = 0;
+ netj->next_deadline += netj->period_usecs;
+ // bah... the packet is not there.
+ // either
+ // - it got lost.
+ // - its late
+ // - sync source is not sending anymore.
+
+ // lets check if we have the next packets, we will just run a cycle without data.
+ // in that case.
+
+ if ( packet_cache_get_next_available_framecnt ( netj->packcache, netj->expected_framecnt, &next_frame_avail) ) {
+ jack_nframes_t offset = next_frame_avail - netj->expected_framecnt;
+
+ //XXX: hmm... i need to remember why resync_threshold wasnt right.
+ //if( offset < netj->resync_threshold )
+ if ( offset < 10 ) {
+ // ok. dont do nothing. we will run without data.
+ // this seems to be one or 2 lost packets.
+ //
+ // this can also be reordered packet jitter.
+ // (maybe this is not happening in real live)
+ // but it happens in netem.
+
+ netj->packet_data_valid = 0;
+
+ // I also found this happening, when the packet queue, is too full.
+ // but wtf ? use a smaller latency. this link can handle that ;S
+ if ( packet_cache_get_fill ( netj->packcache, netj->expected_framecnt ) > 80.0 ) {
+ netj->next_deadline -= netj->period_usecs / 2;
+ }
+
+
+ } else {
+ // the diff is too high. but we have a packet in the future.
+ // lets resync.
+ netj->expected_framecnt = next_frame_avail;
+ packet_cache_retreive_packet_pointer ( netj->packcache, netj->expected_framecnt, (char**)&(netj->rx_buf), netj->rx_bufsize, NULL );
+ pkthdr = (jacknet_packet_header*)netj->rx_buf;
+ packet_header_ntoh (pkthdr);
+ //netj->deadline_goodness = 0;
+ netj->deadline_goodness = (int)pkthdr->sync_state - (int)netj->period_usecs * offset;
+ netj->next_deadline_valid = 0;
+ netj->packet_data_valid = 1;
+ }
+
} else {
- if( netj->num_lost_packets == 101 ) {
- jack_info( "master seems gone... entering freerun mode", netj->expected_framecnt );
- }
-
- netj->running_free = 1;
-
- // when we really dont see packets.
- // reset source address. and open possibility for new master.
- // maybe dsl reconnect. Also restart of netsource without fix
- // reply address changes port.
- if (netj->num_lost_packets > 200 ) {
- netj->srcaddress_valid = 0;
- packet_cache_reset_master_address( netj->packcache );
- }
+ // no packets in buffer.
+ netj->packet_data_valid = 0;
+
+ //printf( "frame %d No Packet in queue. num_lost_packets = %d \n", netj->expected_framecnt, netj->num_lost_packets );
+ if ( netj->num_lost_packets < 5 ) {
+ // ok. No Packet in queue. The packet was either lost,
+ // or we are running too fast.
+ //
+ // Adjusting the deadline unconditionally resulted in
+ // too many xruns on master.
+ // But we need to adjust for the case we are running too fast.
+ // So lets check if the last packet is there now.
+ //
+ // It would not be in the queue anymore, if it had been
+ // retrieved. This might break for redundancy, but
+ // i will make the packet cache drop redundant packets,
+ // that have already been retreived.
+ //
+ if ( packet_cache_get_highest_available_framecnt ( netj->packcache, &next_frame_avail) ) {
+ if ( next_frame_avail == (netj->expected_framecnt - 1) ) {
+ // Ok. the last packet is there now.
+ // and it had not been retrieved.
+ //
+ // TODO: We are still dropping 2 packets.
+ // perhaps we can adjust the deadline
+ // when (num_packets lost == 0)
+
+ // This might still be too much.
+ netj->next_deadline += netj->period_usecs;
+ }
+ }
+ } else if ( (netj->num_lost_packets <= 100) ) {
+ // lets try adjusting the deadline harder, for some packets, we might have just ran 2 fast.
+ netj->next_deadline += netj->period_usecs * netj->latency / 8;
+ } else {
+
+ // But now we can check for any new frame available.
+ //
+ if ( packet_cache_get_highest_available_framecnt ( netj->packcache, &next_frame_avail) ) {
+ netj->expected_framecnt = next_frame_avail;
+ packet_cache_retreive_packet_pointer ( netj->packcache, netj->expected_framecnt, (char**)&(netj->rx_buf), netj->rx_bufsize, NULL );
+ pkthdr = (jacknet_packet_header*)netj->rx_buf;
+ packet_header_ntoh (pkthdr);
+ netj->deadline_goodness = pkthdr->sync_state;
+ netj->next_deadline_valid = 0;
+ netj->packet_data_valid = 1;
+ netj->running_free = 0;
+ jack_info ( "resync after freerun... %d", netj->expected_framecnt );
+ } else {
+ if ( netj->num_lost_packets == 101 ) {
+ jack_info ( "master seems gone... entering freerun mode", netj->expected_framecnt );
+ }
+
+ netj->running_free = 1;
+
+ // when we really dont see packets.
+ // reset source address. and open possibility for new master.
+ // maybe dsl reconnect. Also restart of netsource without fix
+ // reply address changes port.
+ if (netj->num_lost_packets > 200 ) {
+ netj->srcaddress_valid = 0;
+ packet_cache_reset_master_address ( netj->packcache );
+ }
+ }
+ }
}
- }
}
- }
- int retval = 0;
+ int retval = 0;
- if( !netj->packet_data_valid ) {
- netj->num_lost_packets += 1;
- if( netj->num_lost_packets == 1 )
- retval = netj->period_usecs;
- } else {
- if( (netj->num_lost_packets>1) && !netj->running_free )
- retval = (netj->num_lost_packets-1) * netj->period_usecs;
+ if ( !netj->packet_data_valid ) {
+ netj->num_lost_packets += 1;
+ if ( netj->num_lost_packets == 1 ) {
+ retval = netj->period_usecs;
+ }
+ } else {
+ if ( (netj->num_lost_packets > 1) && !netj->running_free ) {
+ retval = (netj->num_lost_packets - 1) * netj->period_usecs;
+ }
- netj->num_lost_packets = 0;
- }
+ netj->num_lost_packets = 0;
+ }
- return retval;
+ return retval;
}
-void netjack_send_silence( netjack_driver_state_t *netj, int syncstate )
+void netjack_send_silence ( netjack_driver_state_t *netj, int syncstate )
{
- int tx_size = get_sample_size(netj->bitdepth) * netj->playback_channels * netj->net_period_up + sizeof(jacknet_packet_header);
- unsigned int *packet_buf, *packet_bufX;
+ int tx_size = get_sample_size (netj->bitdepth) * netj->playback_channels * netj->net_period_up + sizeof(jacknet_packet_header);
+ unsigned int *packet_buf, *packet_bufX;
- packet_buf = alloca( tx_size);
- jacknet_packet_header *tx_pkthdr = (jacknet_packet_header *)packet_buf;
- jacknet_packet_header *rx_pkthdr = (jacknet_packet_header *)netj->rx_buf;
+ packet_buf = alloca ( tx_size);
+ jacknet_packet_header *tx_pkthdr = (jacknet_packet_header*)packet_buf;
+ jacknet_packet_header *rx_pkthdr = (jacknet_packet_header*)netj->rx_buf;
- //framecnt = rx_pkthdr->framecnt;
+ //framecnt = rx_pkthdr->framecnt;
- netj->reply_port = rx_pkthdr->reply_port;
+ netj->reply_port = rx_pkthdr->reply_port;
- // offset packet_bufX by the packetheader.
- packet_bufX = packet_buf + sizeof(jacknet_packet_header) / sizeof(jack_default_audio_sample_t);
+ // offset packet_bufX by the packetheader.
+ packet_bufX = packet_buf + sizeof(jacknet_packet_header) / sizeof(jack_default_audio_sample_t);
- tx_pkthdr->sync_state = syncstate;
- tx_pkthdr->framecnt = netj->expected_framecnt;
+ tx_pkthdr->sync_state = syncstate;
+ tx_pkthdr->framecnt = netj->expected_framecnt;
- // memset 0 the payload.
- int payload_size = get_sample_size(netj->bitdepth) * netj->playback_channels * netj->net_period_up;
- memset(packet_bufX, 0, payload_size);
+ // memset 0 the payload.
+ int payload_size = get_sample_size (netj->bitdepth) * netj->playback_channels * netj->net_period_up;
+ memset (packet_bufX, 0, payload_size);
- packet_header_hton(tx_pkthdr);
- if (netj->srcaddress_valid)
- {
- int r;
- if (netj->reply_port)
- netj->syncsource_address.sin_port = htons(netj->reply_port);
+ packet_header_hton (tx_pkthdr);
+ if (netj->srcaddress_valid) {
+ int r;
+ if (netj->reply_port) {
+ netj->syncsource_address.sin_port = htons (netj->reply_port);
+ }
- for( r=0; r<netj->redundancy; r++ )
- netjack_sendto(netj->outsockfd, (char *)packet_buf, tx_size,
- 0, (struct sockaddr*)&(netj->syncsource_address), sizeof(struct sockaddr_in), netj->mtu);
- }
+ for ( r = 0; r < netj->redundancy; r++ )
+ netjack_sendto (netj->outsockfd, (char*)packet_buf, tx_size,
+ 0, (struct sockaddr*)&(netj->syncsource_address), sizeof(struct sockaddr_in), netj->mtu);
+ }
}
-void netjack_attach( netjack_driver_state_t *netj )
+void netjack_attach ( netjack_driver_state_t *netj )
{
- //puts ("net_driver_attach");
- jack_port_t * port;
- char buf[32];
- unsigned int chn;
- int port_flags;
+ //puts ("net_driver_attach");
+ jack_port_t * port;
+ char buf[32];
+ unsigned int chn;
+ int port_flags;
- if( netj->bitdepth == CELT_MODE )
- {
+ if ( netj->bitdepth == CELT_MODE ) {
#if HAVE_CELT
#if HAVE_CELT_API_0_7 || HAVE_CELT_API_0_8
- celt_int32 lookahead;
- netj->celt_mode = celt_mode_create( netj->sample_rate, netj->period_size, NULL );
+ celt_int32 lookahead;
+ netj->celt_mode = celt_mode_create ( netj->sample_rate, netj->period_size, NULL );
#else
- celt_int32_t lookahead;
- netj->celt_mode = celt_mode_create( netj->sample_rate, 1, netj->period_size, NULL );
+ celt_int32_t lookahead;
+ netj->celt_mode = celt_mode_create ( netj->sample_rate, 1, netj->period_size, NULL );
#endif
- celt_mode_info( netj->celt_mode, CELT_GET_LOOKAHEAD, &lookahead );
- netj->codec_latency = 2*lookahead;
+ celt_mode_info ( netj->celt_mode, CELT_GET_LOOKAHEAD, &lookahead );
+ netj->codec_latency = 2 * lookahead;
#endif
- }
+ }
- if (netj->handle_transport_sync)
- jack_set_sync_callback(netj->client, (JackSyncCallback) net_driver_sync_cb, NULL);
+ if (netj->handle_transport_sync) {
+ jack_set_sync_callback (netj->client, (JackSyncCallback)net_driver_sync_cb, NULL);
+ }
- port_flags = JackPortIsOutput | JackPortIsPhysical | JackPortIsTerminal;
+ port_flags = JackPortIsOutput | JackPortIsPhysical | JackPortIsTerminal;
- for (chn = 0; chn < netj->capture_channels_audio; chn++) {
- snprintf (buf, sizeof(buf) - 1, "capture_%u", chn + 1);
+ for (chn = 0; chn < netj->capture_channels_audio; chn++) {
+ snprintf (buf, sizeof(buf) - 1, "capture_%u", chn + 1);
- port = jack_port_register (netj->client, buf,
- JACK_DEFAULT_AUDIO_TYPE,
- port_flags, 0);
- if (!port) {
- jack_error ("NET: cannot register port for %s", buf);
- break;
- }
+ port = jack_port_register (netj->client, buf,
+ JACK_DEFAULT_AUDIO_TYPE,
+ port_flags, 0);
+ if (!port) {
+ jack_error ("NET: cannot register port for %s", buf);
+ break;
+ }
- netj->capture_ports =
- jack_slist_append (netj->capture_ports, port);
+ netj->capture_ports =
+ jack_slist_append (netj->capture_ports, port);
- if( netj->bitdepth == CELT_MODE ) {
+ if ( netj->bitdepth == CELT_MODE ) {
#if HAVE_CELT
#if HAVE_CELT_API_0_7 || HAVE_CELT_API_0_8
- netj->capture_srcs = jack_slist_append(netj->capture_srcs, celt_decoder_create( netj->celt_mode, 1, NULL ) );
+ netj->capture_srcs = jack_slist_append (netj->capture_srcs, celt_decoder_create ( netj->celt_mode, 1, NULL ) );
#else
- netj->capture_srcs = jack_slist_append(netj->capture_srcs, celt_decoder_create( netj->celt_mode ) );
+ netj->capture_srcs = jack_slist_append (netj->capture_srcs, celt_decoder_create ( netj->celt_mode ) );
#endif
#endif
- } else {
+ } else {
#if HAVE_SAMPLERATE
- netj->capture_srcs = jack_slist_append(netj->capture_srcs, src_new(SRC_LINEAR, 1, NULL));
+ netj->capture_srcs = jack_slist_append (netj->capture_srcs, src_new (SRC_LINEAR, 1, NULL));
#endif
+ }
}
- }
- for (chn = netj->capture_channels_audio; chn < netj->capture_channels; chn++) {
- snprintf (buf, sizeof(buf) - 1, "capture_%u", chn + 1);
+ for (chn = netj->capture_channels_audio; chn < netj->capture_channels; chn++) {
+ snprintf (buf, sizeof(buf) - 1, "capture_%u", chn + 1);
- port = jack_port_register (netj->client, buf,
- JACK_DEFAULT_MIDI_TYPE,
- port_flags, 0);
- if (!port) {
- jack_error ("NET: cannot register port for %s", buf);
- break;
- }
+ port = jack_port_register (netj->client, buf,
+ JACK_DEFAULT_MIDI_TYPE,
+ port_flags, 0);
+ if (!port) {
+ jack_error ("NET: cannot register port for %s", buf);
+ break;
+ }
- netj->capture_ports =
- jack_slist_append (netj->capture_ports, port);
- }
+ netj->capture_ports =
+ jack_slist_append (netj->capture_ports, port);
+ }
- port_flags = JackPortIsInput | JackPortIsPhysical | JackPortIsTerminal;
+ port_flags = JackPortIsInput | JackPortIsPhysical | JackPortIsTerminal;
- for (chn = 0; chn < netj->playback_channels_audio; chn++) {
- snprintf (buf, sizeof(buf) - 1, "playback_%u", chn + 1);
+ for (chn = 0; chn < netj->playback_channels_audio; chn++) {
+ snprintf (buf, sizeof(buf) - 1, "playback_%u", chn + 1);
- port = jack_port_register (netj->client, buf,
- JACK_DEFAULT_AUDIO_TYPE,
- port_flags, 0);
+ port = jack_port_register (netj->client, buf,
+ JACK_DEFAULT_AUDIO_TYPE,
+ port_flags, 0);
- if (!port) {
- jack_error ("NET: cannot register port for %s", buf);
- break;
- }
+ if (!port) {
+ jack_error ("NET: cannot register port for %s", buf);
+ break;
+ }
- netj->playback_ports =
- jack_slist_append (netj->playback_ports, port);
- if( netj->bitdepth == CELT_MODE ) {
+ netj->playback_ports =
+ jack_slist_append (netj->playback_ports, port);
+ if ( netj->bitdepth == CELT_MODE ) {
#if HAVE_CELT
#if HAVE_CELT_API_0_7 || HAVE_CELT_API_0_8
- CELTMode *celt_mode = celt_mode_create( netj->sample_rate, netj->period_size, NULL );
- netj->playback_srcs = jack_slist_append(netj->playback_srcs, celt_encoder_create( celt_mode, 1, NULL ) );
+ CELTMode *celt_mode = celt_mode_create ( netj->sample_rate, netj->period_size, NULL );
+ netj->playback_srcs = jack_slist_append (netj->playback_srcs, celt_encoder_create ( celt_mode, 1, NULL ) );
#else
- CELTMode *celt_mode = celt_mode_create( netj->sample_rate, 1, netj->period_size, NULL );
- netj->playback_srcs = jack_slist_append(netj->playback_srcs, celt_encoder_create( celt_mode ) );
+ CELTMode *celt_mode = celt_mode_create ( netj->sample_rate, 1, netj->period_size, NULL );
+ netj->playback_srcs = jack_slist_append (netj->playback_srcs, celt_encoder_create ( celt_mode ) );
#endif
#endif
- } else {
+ } else {
#if HAVE_SAMPLERATE
- netj->playback_srcs = jack_slist_append(netj->playback_srcs, src_new(SRC_LINEAR, 1, NULL));
+ netj->playback_srcs = jack_slist_append (netj->playback_srcs, src_new (SRC_LINEAR, 1, NULL));
#endif
+ }
}
- }
- for (chn = netj->playback_channels_audio; chn < netj->playback_channels; chn++) {
- snprintf (buf, sizeof(buf) - 1, "playback_%u", chn + 1);
+ for (chn = netj->playback_channels_audio; chn < netj->playback_channels; chn++) {
+ snprintf (buf, sizeof(buf) - 1, "playback_%u", chn + 1);
- port = jack_port_register (netj->client, buf,
- JACK_DEFAULT_MIDI_TYPE,
- port_flags, 0);
+ port = jack_port_register (netj->client, buf,
+ JACK_DEFAULT_MIDI_TYPE,
+ port_flags, 0);
- if (!port) {
- jack_error ("NET: cannot register port for %s", buf);
- break;
- }
+ if (!port) {
+ jack_error ("NET: cannot register port for %s", buf);
+ break;
+ }
- netj->playback_ports =
- jack_slist_append (netj->playback_ports, port);
- }
+ netj->playback_ports =
+ jack_slist_append (netj->playback_ports, port);
+ }
- jack_activate (netj->client);
+ jack_activate (netj->client);
}
-void netjack_detach( netjack_driver_state_t *netj )
+void netjack_detach ( netjack_driver_state_t *netj )
{
- JSList * node;
+ JSList * node;
- for (node = netj->capture_ports; node; node = jack_slist_next (node))
- jack_port_unregister (netj->client,
- ((jack_port_t *) node->data));
+ for (node = netj->capture_ports; node; node = jack_slist_next (node))
+ jack_port_unregister (netj->client,
+ ((jack_port_t*)node->data));
- jack_slist_free (netj->capture_ports);
- netj->capture_ports = NULL;
+ jack_slist_free (netj->capture_ports);
+ netj->capture_ports = NULL;
- for (node = netj->capture_srcs; node; node = jack_slist_next (node))
- {
+ for (node = netj->capture_srcs; node; node = jack_slist_next (node)) {
#if HAVE_CELT
- if( netj->bitdepth == CELT_MODE )
- {
- CELTDecoder * decoder = node->data;
- celt_decoder_destroy(decoder);
- }
- else
+ if ( netj->bitdepth == CELT_MODE ) {
+ CELTDecoder * decoder = node->data;
+ celt_decoder_destroy (decoder);
+ } else
#endif
- {
+ {
#if HAVE_SAMPLERATE
- SRC_STATE * src = node->data;
- src_delete(src);
+ SRC_STATE * src = node->data;
+ src_delete (src);
#endif
- }
- }
- jack_slist_free (netj->capture_srcs);
- netj->playback_srcs = NULL;
+ }
+ }
+ jack_slist_free (netj->capture_srcs);
+ netj->playback_srcs = NULL;
- for (node = netj->playback_ports; node; node = jack_slist_next (node))
- jack_port_unregister (netj->client,
- ((jack_port_t *) node->data));
+ for (node = netj->playback_ports; node; node = jack_slist_next (node))
+ jack_port_unregister (netj->client,
+ ((jack_port_t*)node->data));
- jack_slist_free (netj->playback_ports);
- netj->playback_ports = NULL;
+ jack_slist_free (netj->playback_ports);
+ netj->playback_ports = NULL;
- for (node = netj->playback_srcs; node; node = jack_slist_next (node))
- {
+ for (node = netj->playback_srcs; node; node = jack_slist_next (node)) {
#if HAVE_CELT
- if( netj->bitdepth == CELT_MODE )
- {
- CELTEncoder * encoder = node->data;
- celt_encoder_destroy(encoder);
- }
- else
+ if ( netj->bitdepth == CELT_MODE ) {
+ CELTEncoder * encoder = node->data;
+ celt_encoder_destroy (encoder);
+ } else
#endif
- {
+ {
#if HAVE_SAMPLERATE
- SRC_STATE * src = node->data;
- src_delete(src);
+ SRC_STATE * src = node->data;
+ src_delete (src);
#endif
- }
- }
- jack_slist_free (netj->playback_srcs);
- netj->playback_srcs = NULL;
+ }
+ }
+ jack_slist_free (netj->playback_srcs);
+ netj->playback_srcs = NULL;
#if HAVE_CELT
- if( netj->bitdepth == CELT_MODE )
- celt_mode_destroy(netj->celt_mode);
+ if ( netj->bitdepth == CELT_MODE ) {
+ celt_mode_destroy (netj->celt_mode);
+ }
#endif
}
netjack_driver_state_t *netjack_init (netjack_driver_state_t *netj,
- jack_client_t * client,
- const char *name,
- unsigned int capture_ports,
- unsigned int playback_ports,
- unsigned int capture_ports_midi,
- unsigned int playback_ports_midi,
- jack_nframes_t sample_rate,
- jack_nframes_t period_size,
- unsigned int listen_port,
- unsigned int transport_sync,
- unsigned int resample_factor,
- unsigned int resample_factor_up,
- unsigned int bitdepth,
- unsigned int use_autoconfig,
- unsigned int latency,
- unsigned int redundancy,
- int dont_htonl_floats,
- int always_deadline,
- int jitter_val )
+ jack_client_t * client,
+ const char *name,
+ unsigned int capture_ports,
+ unsigned int playback_ports,
+ unsigned int capture_ports_midi,
+ unsigned int playback_ports_midi,
+ jack_nframes_t sample_rate,
+ jack_nframes_t period_size,
+ unsigned int listen_port,
+ unsigned int transport_sync,
+ unsigned int resample_factor,
+ unsigned int resample_factor_up,
+ unsigned int bitdepth,
+ unsigned int use_autoconfig,
+ unsigned int latency,
+ unsigned int redundancy,
+ int dont_htonl_floats,
+ int always_deadline,
+ int jitter_val )
{
- // Fill in netj values.
- // might be subject to autoconfig...
- // so dont calculate anything with them...
+ // Fill in netj values.
+ // might be subject to autoconfig...
+ // so dont calculate anything with them...
- netj->sample_rate = sample_rate;
- netj->period_size = period_size;
- netj->dont_htonl_floats = dont_htonl_floats;
+ netj->sample_rate = sample_rate;
+ netj->period_size = period_size;
+ netj->dont_htonl_floats = dont_htonl_floats;
- netj->listen_port = listen_port;
+ netj->listen_port = listen_port;
- netj->capture_channels = capture_ports + capture_ports_midi;
- netj->capture_channels_audio = capture_ports;
- netj->capture_channels_midi = capture_ports_midi;
- netj->capture_ports = NULL;
- netj->playback_channels = playback_ports + playback_ports_midi;
- netj->playback_channels_audio = playback_ports;
- netj->playback_channels_midi = playback_ports_midi;
- netj->playback_ports = NULL;
- netj->codec_latency = 0;
+ netj->capture_channels = capture_ports + capture_ports_midi;
+ netj->capture_channels_audio = capture_ports;
+ netj->capture_channels_midi = capture_ports_midi;
+ netj->capture_ports = NULL;
+ netj->playback_channels = playback_ports + playback_ports_midi;
+ netj->playback_channels_audio = playback_ports;
+ netj->playback_channels_midi = playback_ports_midi;
+ netj->playback_ports = NULL;
+ netj->codec_latency = 0;
- netj->handle_transport_sync = transport_sync;
- netj->mtu = 1400;
- netj->latency = latency;
- netj->redundancy = redundancy;
- netj->use_autoconfig = use_autoconfig;
- netj->always_deadline = always_deadline;
+ netj->handle_transport_sync = transport_sync;
+ netj->mtu = 1400;
+ netj->latency = latency;
+ netj->redundancy = redundancy;
+ netj->use_autoconfig = use_autoconfig;
+ netj->always_deadline = always_deadline;
- netj->client = client;
+ netj->client = client;
- if ((bitdepth != 0) && (bitdepth != 8) && (bitdepth != 16) && (bitdepth != CELT_MODE))
- {
- jack_info ("Invalid bitdepth: %d (8, 16 or 0 for float) !!!", bitdepth);
- return NULL;
- }
- netj->bitdepth = bitdepth;
+ if ((bitdepth != 0) && (bitdepth != 8) && (bitdepth != 16) && (bitdepth != CELT_MODE)) {
+ jack_info ("Invalid bitdepth: %d (8, 16 or 0 for float) !!!", bitdepth);
+ return NULL;
+ }
+ netj->bitdepth = bitdepth;
- if (resample_factor_up == 0)
- resample_factor_up = resample_factor;
+ if (resample_factor_up == 0) {
+ resample_factor_up = resample_factor;
+ }
- netj->resample_factor = resample_factor;
- netj->resample_factor_up = resample_factor_up;
+ netj->resample_factor = resample_factor;
+ netj->resample_factor_up = resample_factor_up;
- netj->jitter_val = jitter_val;
+ netj->jitter_val = jitter_val;
- return netj;
+ return netj;
}
-void netjack_release( netjack_driver_state_t *netj )
+void netjack_release ( netjack_driver_state_t *netj )
{
- close( netj->sockfd );
- close( netj->outsockfd );
+ close ( netj->sockfd );
+ close ( netj->outsockfd );
- packet_cache_free( netj->packcache );
- netj->packcache = NULL;
+ packet_cache_free ( netj->packcache );
+ netj->packcache = NULL;
}
int
-netjack_startup( netjack_driver_state_t *netj )
+netjack_startup ( netjack_driver_state_t *netj )
{
- int first_pack_len;
- struct sockaddr_in address;
- // Now open the socket, and wait for the first packet to arrive...
- netj->sockfd = socket (AF_INET, SOCK_DGRAM, 0);
+ int first_pack_len;
+ struct sockaddr_in address;
+
+ // Now open the socket, and wait for the first packet to arrive...
+ netj->sockfd = socket (AF_INET, SOCK_DGRAM, 0);
#ifdef WIN32
- if (netj->sockfd == INVALID_SOCKET)
+ if (netj->sockfd == INVALID_SOCKET)
#else
- if (netj->sockfd == -1)
+ if (netj->sockfd == -1)
#endif
- {
- jack_info ("socket error");
- return -1;
- }
- address.sin_family = AF_INET;
- address.sin_port = htons(netj->listen_port);
- address.sin_addr.s_addr = htonl(INADDR_ANY);
- if (bind (netj->sockfd, (struct sockaddr *) &address, sizeof (address)) < 0)
- {
- jack_info("bind error");
- return -1;
- }
-
- netj->outsockfd = socket (AF_INET, SOCK_DGRAM, 0);
+ {
+ jack_info ("socket error");
+ return -1;
+ }
+ address.sin_family = AF_INET;
+ address.sin_port = htons (netj->listen_port);
+ address.sin_addr.s_addr = htonl (INADDR_ANY);
+ if (bind (netj->sockfd, (struct sockaddr*)&address, sizeof(address)) < 0) {
+ jack_info ("bind error");
+ return -1;
+ }
+
+ netj->outsockfd = socket (AF_INET, SOCK_DGRAM, 0);
#ifdef WIN32
- if (netj->outsockfd == INVALID_SOCKET)
+ if (netj->outsockfd == INVALID_SOCKET)
#else
- if (netj->outsockfd == -1)
+ if (netj->outsockfd == -1)
#endif
- {
- jack_info ("socket error");
- return -1;
- }
- netj->srcaddress_valid = 0;
- if (netj->use_autoconfig)
- {
- jacknet_packet_header *first_packet = alloca (sizeof (jacknet_packet_header));
+ {
+ jack_info ("socket error");
+ return -1;
+ }
+ netj->srcaddress_valid = 0;
+ if (netj->use_autoconfig) {
+ jacknet_packet_header *first_packet = alloca (sizeof(jacknet_packet_header));
#ifdef WIN32
- int address_size = sizeof( struct sockaddr_in );
+ int address_size = sizeof( struct sockaddr_in );
#else
- socklen_t address_size = sizeof (struct sockaddr_in);
+ socklen_t address_size = sizeof(struct sockaddr_in);
#endif
- //jack_info ("Waiting for an incoming packet !!!");
- //jack_info ("*** IMPORTANT *** Dont connect a client to jackd until the driver is attached to a clock source !!!");
-
- while(1) {
- if( ! netjack_poll( netj->sockfd, 1000 ) ) {
- jack_info ("Waiting aborted");
- return -1;
- }
- first_pack_len = recvfrom (netj->sockfd, (char *)first_packet, sizeof (jacknet_packet_header), 0, (struct sockaddr*) & netj->syncsource_address, &address_size);
+ //jack_info ("Waiting for an incoming packet !!!");
+ //jack_info ("*** IMPORTANT *** Dont connect a client to jackd until the driver is attached to a clock source !!!");
+
+ while (1) {
+ if ( !netjack_poll ( netj->sockfd, 1000 ) ) {
+ jack_info ("Waiting aborted");
+ return -1;
+ }
+ first_pack_len = recvfrom (netj->sockfd, (char*)first_packet, sizeof(jacknet_packet_header), 0, (struct sockaddr*)&netj->syncsource_address, &address_size);
#ifdef WIN32
- if( first_pack_len == -1 ) {
- first_pack_len = sizeof(jacknet_packet_header);
- break;
- }
+ if ( first_pack_len == -1 ) {
+ first_pack_len = sizeof(jacknet_packet_header);
+ break;
+ }
#else
- if (first_pack_len == sizeof (jacknet_packet_header))
- break;
+ if (first_pack_len == sizeof(jacknet_packet_header)) {
+ break;
+ }
#endif
- }
- netj->srcaddress_valid = 1;
+ }
+ netj->srcaddress_valid = 1;
+
+ if (first_pack_len == sizeof(jacknet_packet_header)) {
+ packet_header_ntoh (first_packet);
+
+ jack_info ("AutoConfig Override !!!");
+ if (netj->sample_rate != first_packet->sample_rate) {
+ jack_info ("AutoConfig Override: Master JACK sample rate = %d", first_packet->sample_rate);
+ netj->sample_rate = first_packet->sample_rate;
+ }
+
+ if (netj->period_size != first_packet->period_size) {
+ jack_info ("AutoConfig Override: Master JACK period size is %d", first_packet->period_size);
+ netj->period_size = first_packet->period_size;
+ }
+ if (netj->capture_channels_audio != first_packet->capture_channels_audio) {
+ jack_info ("AutoConfig Override: capture_channels_audio = %d", first_packet->capture_channels_audio);
+ netj->capture_channels_audio = first_packet->capture_channels_audio;
+ }
+ if (netj->capture_channels_midi != first_packet->capture_channels_midi) {
+ jack_info ("AutoConfig Override: capture_channels_midi = %d", first_packet->capture_channels_midi);
+ netj->capture_channels_midi = first_packet->capture_channels_midi;
+ }
+ if (netj->playback_channels_audio != first_packet->playback_channels_audio) {
+ jack_info ("AutoConfig Override: playback_channels_audio = %d", first_packet->playback_channels_audio);
+ netj->playback_channels_audio = first_packet->playback_channels_audio;
+ }
+ if (netj->playback_channels_midi != first_packet->playback_channels_midi) {
+ jack_info ("AutoConfig Override: playback_channels_midi = %d", first_packet->playback_channels_midi);
+ netj->playback_channels_midi = first_packet->playback_channels_midi;
+ }
+
+ netj->mtu = first_packet->mtu;
+ jack_info ("MTU is set to %d bytes", first_packet->mtu);
+ netj->latency = first_packet->latency;
+ }
+ }
+ netj->capture_channels = netj->capture_channels_audio + netj->capture_channels_midi;
+ netj->playback_channels = netj->playback_channels_audio + netj->playback_channels_midi;
- if (first_pack_len == sizeof (jacknet_packet_header))
- {
- packet_header_ntoh (first_packet);
-
- jack_info ("AutoConfig Override !!!");
- if (netj->sample_rate != first_packet->sample_rate)
- {
- jack_info ("AutoConfig Override: Master JACK sample rate = %d", first_packet->sample_rate);
- netj->sample_rate = first_packet->sample_rate;
- }
-
- if (netj->period_size != first_packet->period_size)
- {
- jack_info ("AutoConfig Override: Master JACK period size is %d", first_packet->period_size);
- netj->period_size = first_packet->period_size;
- }
- if (netj->capture_channels_audio != first_packet->capture_channels_audio)
- {
- jack_info ("AutoConfig Override: capture_channels_audio = %d", first_packet->capture_channels_audio);
- netj->capture_channels_audio = first_packet->capture_channels_audio;
- }
- if (netj->capture_channels_midi != first_packet->capture_channels_midi)
- {
- jack_info ("AutoConfig Override: capture_channels_midi = %d", first_packet->capture_channels_midi);
- netj->capture_channels_midi = first_packet->capture_channels_midi;
- }
- if (netj->playback_channels_audio != first_packet->playback_channels_audio)
- {
- jack_info ("AutoConfig Override: playback_channels_audio = %d", first_packet->playback_channels_audio);
- netj->playback_channels_audio = first_packet->playback_channels_audio;
- }
- if (netj->playback_channels_midi != first_packet->playback_channels_midi)
- {
- jack_info ("AutoConfig Override: playback_channels_midi = %d", first_packet->playback_channels_midi);
- netj->playback_channels_midi = first_packet->playback_channels_midi;
- }
-
- netj->mtu = first_packet->mtu;
- jack_info ("MTU is set to %d bytes", first_packet->mtu);
- netj->latency = first_packet->latency;
+ if ( (netj->capture_channels * netj->period_size * netj->latency * 4) > 100000000 ) {
+ jack_error ( "autoconfig requests more than 100MB packet cache... bailing out" );
+ exit (1);
}
- }
- netj->capture_channels = netj->capture_channels_audio + netj->capture_channels_midi;
- netj->playback_channels = netj->playback_channels_audio + netj->playback_channels_midi;
-
- if( (netj->capture_channels * netj->period_size * netj->latency * 4) > 100000000 ) {
- jack_error( "autoconfig requests more than 100MB packet cache... bailing out" );
- exit(1);
- }
-
- if( netj->playback_channels > 1000 ) {
- jack_error( "autoconfig requests more than 1000 playback channels... bailing out" );
- exit(1);
- }
-
-
- if( netj->mtu < (2*sizeof( jacknet_packet_header )) ) {
- jack_error( "bullshit mtu requested by autoconfig" );
- exit(1);
- }
-
- if( netj->sample_rate == 0 ) {
- jack_error( "sample_rate 0 requested by autoconfig" );
- exit(1);
- }
-
- // After possible Autoconfig: do all calculations...
- netj->period_usecs =
- (jack_time_t) floor ((((float) netj->period_size) / (float)netj->sample_rate)
- * 1000000.0f);
-
- if( netj->latency == 0 )
- netj->deadline_offset = 50*netj->period_usecs;
- else
- netj->deadline_offset = netj->period_usecs + 10*netj->latency*netj->period_usecs/100;
-
- if( netj->bitdepth == CELT_MODE ) {
- // celt mode.
- // TODO: this is a hack. But i dont want to change the packet header.
- netj->resample_factor = (netj->resample_factor * netj->period_size * 1024 / netj->sample_rate / 8)&(~1);
- netj->resample_factor_up = (netj->resample_factor_up * netj->period_size * 1024 / netj->sample_rate / 8)&(~1);
-
- netj->net_period_down = netj->resample_factor;
- netj->net_period_up = netj->resample_factor_up;
- } else {
- netj->net_period_down = (float) netj->period_size / (float) netj->resample_factor;
- netj->net_period_up = (float) netj->period_size / (float) netj->resample_factor_up;
- }
-
- netj->rx_bufsize = sizeof (jacknet_packet_header) + netj->net_period_down * netj->capture_channels * get_sample_size (netj->bitdepth);
- netj->packcache = packet_cache_new (netj->latency + 50, netj->rx_bufsize, netj->mtu);
-
- netj->expected_framecnt_valid = 0;
- netj->num_lost_packets = 0;
- netj->next_deadline_valid = 0;
- netj->deadline_goodness = 0;
- netj->time_to_deadline = 0;
-
- // Special handling for latency=0
- if( netj->latency == 0 )
- netj->resync_threshold = 0;
- else
- netj->resync_threshold = MIN( 15, netj->latency-1 );
-
- netj->running_free = 0;
-
- return 0;
+
+ if ( netj->playback_channels > 1000 ) {
+ jack_error ( "autoconfig requests more than 1000 playback channels... bailing out" );
+ exit (1);
+ }
+
+
+ if ( netj->mtu < (2 * sizeof( jacknet_packet_header )) ) {
+ jack_error ( "bullshit mtu requested by autoconfig" );
+ exit (1);
+ }
+
+ if ( netj->sample_rate == 0 ) {
+ jack_error ( "sample_rate 0 requested by autoconfig" );
+ exit (1);
+ }
+
+ // After possible Autoconfig: do all calculations...
+ netj->period_usecs =
+ (jack_time_t)floor ((((float)netj->period_size) / (float)netj->sample_rate)
+ * 1000000.0f);
+
+ if ( netj->latency == 0 ) {
+ netj->deadline_offset = 50 * netj->period_usecs;
+ } else {
+ netj->deadline_offset = netj->period_usecs + 10 * netj->latency * netj->period_usecs / 100;
+ }
+
+ if ( netj->bitdepth == CELT_MODE ) {
+ // celt mode.
+ // TODO: this is a hack. But i dont want to change the packet header.
+ netj->resample_factor = (netj->resample_factor * netj->period_size * 1024 / netj->sample_rate / 8) & (~1);
+ netj->resample_factor_up = (netj->resample_factor_up * netj->period_size * 1024 / netj->sample_rate / 8) & (~1);
+
+ netj->net_period_down = netj->resample_factor;
+ netj->net_period_up = netj->resample_factor_up;
+ } else {
+ netj->net_period_down = (float)netj->period_size / (float)netj->resample_factor;
+ netj->net_period_up = (float)netj->period_size / (float)netj->resample_factor_up;
+ }
+
+ netj->rx_bufsize = sizeof(jacknet_packet_header) + netj->net_period_down * netj->capture_channels * get_sample_size(netj->bitdepth);
+ netj->packcache = packet_cache_new (netj->latency + 50, netj->rx_bufsize, netj->mtu);
+
+ netj->expected_framecnt_valid = 0;
+ netj->num_lost_packets = 0;
+ netj->next_deadline_valid = 0;
+ netj->deadline_goodness = 0;
+ netj->time_to_deadline = 0;
+
+ // Special handling for latency=0
+ if ( netj->latency == 0 ) {
+ netj->resync_threshold = 0;
+ } else {
+ netj->resync_threshold = MIN ( 15, netj->latency - 1 );
+ }
+
+ netj->running_free = 0;
+
+ return 0;
}
diff --git a/drivers/netjack/netjack.h b/drivers/netjack/netjack.h
index 3ca6c62..f6aa365 100644
--- a/drivers/netjack/netjack.h
+++ b/drivers/netjack/netjack.h
@@ -16,7 +16,7 @@
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 __NETJACK_H__
#define __NETJACK_H__
@@ -45,105 +45,105 @@ struct _packet_cache;
typedef struct _netjack_driver_state netjack_driver_state_t;
struct _netjack_driver_state {
- jack_nframes_t net_period_up;
- jack_nframes_t net_period_down;
+ jack_nframes_t net_period_up;
+ jack_nframes_t net_period_down;
- jack_nframes_t sample_rate;
- jack_nframes_t bitdepth;
- jack_nframes_t period_size;
- jack_time_t period_usecs;
- int dont_htonl_floats;
- int always_deadline;
+ jack_nframes_t sample_rate;
+ jack_nframes_t bitdepth;
+ jack_nframes_t period_size;
+ jack_time_t period_usecs;
+ int dont_htonl_floats;
+ int always_deadline;
- jack_nframes_t codec_latency;
+ jack_nframes_t codec_latency;
- unsigned int listen_port;
+ unsigned int listen_port;
- unsigned int capture_channels;
- unsigned int playback_channels;
- unsigned int capture_channels_audio;
- unsigned int playback_channels_audio;
- unsigned int capture_channels_midi;
- unsigned int playback_channels_midi;
+ unsigned int capture_channels;
+ unsigned int playback_channels;
+ unsigned int capture_channels_audio;
+ unsigned int playback_channels_audio;
+ unsigned int capture_channels_midi;
+ unsigned int playback_channels_midi;
- JSList *capture_ports;
- JSList *playback_ports;
- JSList *playback_srcs;
- JSList *capture_srcs;
+ JSList *capture_ports;
+ JSList *playback_ports;
+ JSList *playback_srcs;
+ JSList *capture_srcs;
- jack_client_t *client;
+ jack_client_t *client;
#ifdef WIN32
- SOCKET sockfd;
- SOCKET outsockfd;
+ SOCKET sockfd;
+ SOCKET outsockfd;
#else
- int sockfd;
- int outsockfd;
+ int sockfd;
+ int outsockfd;
#endif
- struct sockaddr_in syncsource_address;
-
- int reply_port;
- int srcaddress_valid;
-
- int sync_state;
- unsigned int handle_transport_sync;
-
- unsigned int *rx_buf;
- unsigned int rx_bufsize;
- //unsigned int tx_bufsize;
- unsigned int mtu;
- unsigned int latency;
- unsigned int redundancy;
-
- jack_nframes_t expected_framecnt;
- int expected_framecnt_valid;
- unsigned int num_lost_packets;
- jack_time_t next_deadline;
- jack_time_t deadline_offset;
- int next_deadline_valid;
- int packet_data_valid;
- int resync_threshold;
- int running_free;
- int deadline_goodness;
- jack_time_t time_to_deadline;
- unsigned int use_autoconfig;
- unsigned int resample_factor;
- unsigned int resample_factor_up;
- int jitter_val;
- struct _packet_cache * packcache;
+ struct sockaddr_in syncsource_address;
+
+ int reply_port;
+ int srcaddress_valid;
+
+ int sync_state;
+ unsigned int handle_transport_sync;
+
+ unsigned int *rx_buf;
+ unsigned int rx_bufsize;
+ //unsigned int tx_bufsize;
+ unsigned int mtu;
+ unsigned int latency;
+ unsigned int redundancy;
+
+ jack_nframes_t expected_framecnt;
+ int expected_framecnt_valid;
+ unsigned int num_lost_packets;
+ jack_time_t next_deadline;
+ jack_time_t deadline_offset;
+ int next_deadline_valid;
+ int packet_data_valid;
+ int resync_threshold;
+ int running_free;
+ int deadline_goodness;
+ jack_time_t time_to_deadline;
+ unsigned int use_autoconfig;
+ unsigned int resample_factor;
+ unsigned int resample_factor_up;
+ int jitter_val;
+ struct _packet_cache * packcache;
#if HAVE_CELT
- CELTMode *celt_mode;
+ CELTMode *celt_mode;
#endif
};
-int netjack_wait( netjack_driver_state_t *netj, jack_time_t (*get_microseconds)(void) );
+int netjack_wait ( netjack_driver_state_t * netj, jack_time_t (*get_microseconds)(void) );
void netjack_send_silence( netjack_driver_state_t *netj, int syncstate );
-void netjack_read( netjack_driver_state_t *netj, jack_nframes_t nframes ) ;
+void netjack_read( netjack_driver_state_t *netj, jack_nframes_t nframes );
void netjack_write( netjack_driver_state_t *netj, jack_nframes_t nframes, int syncstate );
void netjack_attach( netjack_driver_state_t *netj );
void netjack_detach( netjack_driver_state_t *netj );
-netjack_driver_state_t *netjack_init (netjack_driver_state_t *netj,
- jack_client_t * client,
- const char *name,
- unsigned int capture_ports,
- unsigned int playback_ports,
- unsigned int capture_ports_midi,
- unsigned int playback_ports_midi,
- jack_nframes_t sample_rate,
- jack_nframes_t period_size,
- unsigned int listen_port,
- unsigned int transport_sync,
- unsigned int resample_factor,
- unsigned int resample_factor_up,
- unsigned int bitdepth,
- unsigned int use_autoconfig,
- unsigned int latency,
- unsigned int redundancy,
- int dont_htonl_floats,
- int always_deadline,
- int jitter_val );
+netjack_driver_state_t *netjack_init(netjack_driver_state_t *netj,
+ jack_client_t * client,
+ const char *name,
+ unsigned int capture_ports,
+ unsigned int playback_ports,
+ unsigned int capture_ports_midi,
+ unsigned int playback_ports_midi,
+ jack_nframes_t sample_rate,
+ jack_nframes_t period_size,
+ unsigned int listen_port,
+ unsigned int transport_sync,
+ unsigned int resample_factor,
+ unsigned int resample_factor_up,
+ unsigned int bitdepth,
+ unsigned int use_autoconfig,
+ unsigned int latency,
+ unsigned int redundancy,
+ int dont_htonl_floats,
+ int always_deadline,
+ int jitter_val );
void netjack_release( netjack_driver_state_t *netj );
int netjack_startup( netjack_driver_state_t *netj );
diff --git a/drivers/netjack/netjack_packet.c b/drivers/netjack/netjack_packet.c
index 35b2520..dd541c3 100644
--- a/drivers/netjack/netjack_packet.c
+++ b/drivers/netjack/netjack_packet.c
@@ -85,62 +85,65 @@ int fraggo = 0;
void
packet_header_hton (jacknet_packet_header *pkthdr)
{
- pkthdr->capture_channels_audio = htonl(pkthdr->capture_channels_audio);
- pkthdr->playback_channels_audio = htonl(pkthdr->playback_channels_audio);
- pkthdr->capture_channels_midi = htonl(pkthdr->capture_channels_midi);
- pkthdr->playback_channels_midi = htonl(pkthdr->playback_channels_midi);
- pkthdr->period_size = htonl(pkthdr->period_size);
- pkthdr->sample_rate = htonl(pkthdr->sample_rate);
- pkthdr->sync_state = htonl(pkthdr->sync_state);
- pkthdr->transport_frame = htonl(pkthdr->transport_frame);
- pkthdr->transport_state = htonl(pkthdr->transport_state);
- pkthdr->framecnt = htonl(pkthdr->framecnt);
- pkthdr->latency = htonl(pkthdr->latency);
- pkthdr->reply_port = htonl(pkthdr->reply_port);
- pkthdr->mtu = htonl(pkthdr->mtu);
- pkthdr->fragment_nr = htonl(pkthdr->fragment_nr);
+ pkthdr->capture_channels_audio = htonl (pkthdr->capture_channels_audio);
+ pkthdr->playback_channels_audio = htonl (pkthdr->playback_channels_audio);
+ pkthdr->capture_channels_midi = htonl (pkthdr->capture_channels_midi);
+ pkthdr->playback_channels_midi = htonl (pkthdr->playback_channels_midi);
+ pkthdr->period_size = htonl (pkthdr->period_size);
+ pkthdr->sample_rate = htonl (pkthdr->sample_rate);
+ pkthdr->sync_state = htonl (pkthdr->sync_state);
+ pkthdr->transport_frame = htonl (pkthdr->transport_frame);
+ pkthdr->transport_state = htonl (pkthdr->transport_state);
+ pkthdr->framecnt = htonl (pkthdr->framecnt);
+ pkthdr->latency = htonl (pkthdr->latency);
+ pkthdr->reply_port = htonl (pkthdr->reply_port);
+ pkthdr->mtu = htonl (pkthdr->mtu);
+ pkthdr->fragment_nr = htonl (pkthdr->fragment_nr);
}
void
packet_header_ntoh (jacknet_packet_header *pkthdr)
{
- pkthdr->capture_channels_audio = ntohl(pkthdr->capture_channels_audio);
- pkthdr->playback_channels_audio = ntohl(pkthdr->playback_channels_audio);
- pkthdr->capture_channels_midi = ntohl(pkthdr->capture_channels_midi);
- pkthdr->playback_channels_midi = ntohl(pkthdr->playback_channels_midi);
- pkthdr->period_size = ntohl(pkthdr->period_size);
- pkthdr->sample_rate = ntohl(pkthdr->sample_rate);
- pkthdr->sync_state = ntohl(pkthdr->sync_state);
- pkthdr->transport_frame = ntohl(pkthdr->transport_frame);
- pkthdr->transport_state = ntohl(pkthdr->transport_state);
- pkthdr->framecnt = ntohl(pkthdr->framecnt);
- pkthdr->latency = ntohl(pkthdr->latency);
- pkthdr->reply_port = ntohl(pkthdr->reply_port);
- pkthdr->mtu = ntohl(pkthdr->mtu);
- pkthdr->fragment_nr = ntohl(pkthdr->fragment_nr);
+ pkthdr->capture_channels_audio = ntohl (pkthdr->capture_channels_audio);
+ pkthdr->playback_channels_audio = ntohl (pkthdr->playback_channels_audio);
+ pkthdr->capture_channels_midi = ntohl (pkthdr->capture_channels_midi);
+ pkthdr->playback_channels_midi = ntohl (pkthdr->playback_channels_midi);
+ pkthdr->period_size = ntohl (pkthdr->period_size);
+ pkthdr->sample_rate = ntohl (pkthdr->sample_rate);
+ pkthdr->sync_state = ntohl (pkthdr->sync_state);
+ pkthdr->transport_frame = ntohl (pkthdr->transport_frame);
+ pkthdr->transport_state = ntohl (pkthdr->transport_state);
+ pkthdr->framecnt = ntohl (pkthdr->framecnt);
+ pkthdr->latency = ntohl (pkthdr->latency);
+ pkthdr->reply_port = ntohl (pkthdr->reply_port);
+ pkthdr->mtu = ntohl (pkthdr->mtu);
+ pkthdr->fragment_nr = ntohl (pkthdr->fragment_nr);
}
int get_sample_size (int bitdepth)
{
- if (bitdepth == 8)
- return sizeof (int8_t);
- if (bitdepth == 16)
- return sizeof (int16_t);
- //JN: why? is this for buffer sizes before or after encoding?
- //JN: if the former, why not int16_t, if the latter, shouldn't it depend on -c N?
- if( bitdepth == CELT_MODE )
- return sizeof( unsigned char );
- return sizeof (int32_t);
+ if (bitdepth == 8) {
+ return sizeof(int8_t);
+ }
+ if (bitdepth == 16) {
+ return sizeof(int16_t);
+ }
+ //JN: why? is this for buffer sizes before or after encoding?
+ //JN: if the former, why not int16_t, if the latter, shouldn't it depend on -c N?
+ if ( bitdepth == CELT_MODE ) {
+ return sizeof( unsigned char );
+ }
+ return sizeof(int32_t);
}
-int jack_port_is_audio(const char *porttype)
+int jack_port_is_audio (const char *porttype)
{
- return (strncmp (porttype, JACK_DEFAULT_AUDIO_TYPE, jack_port_type_size()) == 0);
+ return strncmp (porttype, JACK_DEFAULT_AUDIO_TYPE, jack_port_type_size ()) == 0;
}
-int jack_port_is_midi(const char *porttype)
+int jack_port_is_midi (const char *porttype)
{
- return (strncmp (porttype, JACK_DEFAULT_MIDI_TYPE, jack_port_type_size()) == 0);
+ return strncmp (porttype, JACK_DEFAULT_MIDI_TYPE, jack_port_type_size ()) == 0;
}
@@ -149,101 +152,97 @@ int jack_port_is_midi(const char *porttype)
packet_cache
*packet_cache_new (int num_packets, int pkt_size, int mtu)
{
- int fragment_payload_size = mtu - sizeof (jacknet_packet_header);
- int i, fragment_number;
-
- if( pkt_size == sizeof(jacknet_packet_header) )
- fragment_number = 1;
- else
- fragment_number = (pkt_size - sizeof (jacknet_packet_header) - 1) / fragment_payload_size + 1;
-
- packet_cache *pcache = malloc (sizeof (packet_cache));
- if (pcache == NULL)
- {
- jack_error ("could not allocate packet cache (1)");
- return NULL;
- }
-
- pcache->size = num_packets;
- pcache->packets = malloc (sizeof (cache_packet) * num_packets);
- pcache->master_address_valid = 0;
- pcache->last_framecnt_retreived = 0;
- pcache->last_framecnt_retreived_valid = 0;
-
- if (pcache->packets == NULL)
- {
- jack_error ("could not allocate packet cache (2)");
- return NULL;
- }
-
- for (i = 0; i < num_packets; i++)
- {
- pcache->packets[i].valid = 0;
- pcache->packets[i].num_fragments = fragment_number;
- pcache->packets[i].packet_size = pkt_size;
- pcache->packets[i].mtu = mtu;
- pcache->packets[i].framecnt = 0;
- pcache->packets[i].fragment_array = malloc (sizeof (char) * fragment_number);
- pcache->packets[i].packet_buf = malloc (pkt_size);
- if ((pcache->packets[i].fragment_array == NULL) || (pcache->packets[i].packet_buf == NULL))
- {
- jack_error ("could not allocate packet cache (3)");
- return NULL;
- }
- }
- pcache->mtu = mtu;
-
- return pcache;
+ int fragment_payload_size = mtu - sizeof(jacknet_packet_header);
+ int i, fragment_number;
+
+ if ( pkt_size == sizeof(jacknet_packet_header) ) {
+ fragment_number = 1;
+ } else {
+ fragment_number = (pkt_size - sizeof(jacknet_packet_header) - 1) / fragment_payload_size + 1;
+ }
+
+ packet_cache *pcache = malloc (sizeof(packet_cache));
+ if (pcache == NULL) {
+ jack_error ("could not allocate packet cache (1)");
+ return NULL;
+ }
+
+ pcache->size = num_packets;
+ pcache->packets = malloc (sizeof(cache_packet) * num_packets);
+ pcache->master_address_valid = 0;
+ pcache->last_framecnt_retreived = 0;
+ pcache->last_framecnt_retreived_valid = 0;
+
+ if (pcache->packets == NULL) {
+ jack_error ("could not allocate packet cache (2)");
+ return NULL;
+ }
+
+ for (i = 0; i < num_packets; i++) {
+ pcache->packets[i].valid = 0;
+ pcache->packets[i].num_fragments = fragment_number;
+ pcache->packets[i].packet_size = pkt_size;
+ pcache->packets[i].mtu = mtu;
+ pcache->packets[i].framecnt = 0;
+ pcache->packets[i].fragment_array = malloc (sizeof(char) * fragment_number);
+ pcache->packets[i].packet_buf = malloc (pkt_size);
+ if ((pcache->packets[i].fragment_array == NULL) || (pcache->packets[i].packet_buf == NULL)) {
+ jack_error ("could not allocate packet cache (3)");
+ return NULL;
+ }
+ }
+ pcache->mtu = mtu;
+
+ return pcache;
}
void
packet_cache_free (packet_cache *pcache)
{
- int i;
- if( pcache == NULL )
- return;
-
- for (i = 0; i < pcache->size; i++)
- {
- free (pcache->packets[i].fragment_array);
- free (pcache->packets[i].packet_buf);
- }
-
- free (pcache->packets);
- free (pcache);
+ int i;
+
+ if ( pcache == NULL ) {
+ return;
+ }
+
+ for (i = 0; i < pcache->size; i++) {
+ free (pcache->packets[i].fragment_array);
+ free (pcache->packets[i].packet_buf);
+ }
+
+ free (pcache->packets);
+ free (pcache);
}
cache_packet
*packet_cache_get_packet (packet_cache *pcache, jack_nframes_t framecnt)
{
- int i;
- cache_packet *retval;
-
- for (i = 0; i < pcache->size; i++)
- {
- if (pcache->packets[i].valid && (pcache->packets[i].framecnt == framecnt))
- return &(pcache->packets[i]);
- }
-
- // The Packet is not in the packet cache.
- // find a free packet.
-
- retval = packet_cache_get_free_packet (pcache);
- if (retval != NULL)
- {
- cache_packet_set_framecnt (retval, framecnt);
- return retval;
- }
-
- // No Free Packet available
- // Get The Oldest packet and reset it.
-
- retval = packet_cache_get_oldest_packet (pcache);
- //printf( "Dropping %d from Cache :S\n", retval->framecnt );
- cache_packet_reset (retval);
- cache_packet_set_framecnt (retval, framecnt);
-
- return retval;
+ int i;
+ cache_packet *retval;
+
+ for (i = 0; i < pcache->size; i++)
+ if (pcache->packets[i].valid && (pcache->packets[i].framecnt == framecnt)) {
+ return &(pcache->packets[i]);
+ }
+
+ // The Packet is not in the packet cache.
+ // find a free packet.
+
+ retval = packet_cache_get_free_packet (pcache);
+ if (retval != NULL) {
+ cache_packet_set_framecnt (retval, framecnt);
+ return retval;
+ }
+
+ // No Free Packet available
+ // Get The Oldest packet and reset it.
+
+ retval = packet_cache_get_oldest_packet (pcache);
+ //printf( "Dropping %d from Cache :S\n", retval->framecnt );
+ cache_packet_reset (retval);
+ cache_packet_set_framecnt (retval, framecnt);
+
+ return retval;
}
// TODO: fix wrapping case... need to pass
@@ -254,109 +253,105 @@ cache_packet
cache_packet
*packet_cache_get_oldest_packet (packet_cache *pcache)
{
- jack_nframes_t minimal_frame = JACK_MAX_FRAMES;
- cache_packet *retval = &(pcache->packets[0]);
- int i;
-
- for (i = 0; i < pcache->size; i++)
- {
- if (pcache->packets[i].valid && (pcache->packets[i].framecnt < minimal_frame))
- {
- minimal_frame = pcache->packets[i].framecnt;
- retval = &(pcache->packets[i]);
- }
- }
-
- return retval;
+ jack_nframes_t minimal_frame = JACK_MAX_FRAMES;
+ cache_packet *retval = &(pcache->packets[0]);
+ int i;
+
+ for (i = 0; i < pcache->size; i++) {
+ if (pcache->packets[i].valid && (pcache->packets[i].framecnt < minimal_frame)) {
+ minimal_frame = pcache->packets[i].framecnt;
+ retval = &(pcache->packets[i]);
+ }
+ }
+
+ return retval;
}
cache_packet
*packet_cache_get_free_packet (packet_cache *pcache)
{
- int i;
+ int i;
- for (i = 0; i < pcache->size; i++)
- {
- if (pcache->packets[i].valid == 0)
- return &(pcache->packets[i]);
- }
+ for (i = 0; i < pcache->size; i++)
+ if (pcache->packets[i].valid == 0) {
+ return &(pcache->packets[i]);
+ }
- return NULL;
+ return NULL;
}
void
cache_packet_reset (cache_packet *pack)
{
- int i;
- pack->valid = 0;
+ int i;
+
+ pack->valid = 0;
- // XXX: i dont think this is necessary here...
- // fragement array is cleared in _set_framecnt()
+ // XXX: i dont think this is necessary here...
+ // fragement array is cleared in _set_framecnt()
- for (i = 0; i < pack->num_fragments; i++)
- pack->fragment_array[i] = 0;
+ for (i = 0; i < pack->num_fragments; i++)
+ pack->fragment_array[i] = 0;
}
void
cache_packet_set_framecnt (cache_packet *pack, jack_nframes_t framecnt)
{
- int i;
+ int i;
- pack->framecnt = framecnt;
+ pack->framecnt = framecnt;
- for (i = 0; i < pack->num_fragments; i++)
- pack->fragment_array[i] = 0;
+ for (i = 0; i < pack->num_fragments; i++)
+ pack->fragment_array[i] = 0;
- pack->valid = 1;
+ pack->valid = 1;
}
void
cache_packet_add_fragment (cache_packet *pack, char *packet_buf, int rcv_len)
{
- jacknet_packet_header *pkthdr = (jacknet_packet_header *) packet_buf;
- int fragment_payload_size = pack->mtu - sizeof (jacknet_packet_header);
- char *packet_bufX = pack->packet_buf + sizeof (jacknet_packet_header);
- char *dataX = packet_buf + sizeof (jacknet_packet_header);
-
- jack_nframes_t fragment_nr = ntohl (pkthdr->fragment_nr);
- jack_nframes_t framecnt = ntohl (pkthdr->framecnt);
-
- if (framecnt != pack->framecnt)
- {
- jack_error ("errror. framecnts dont match");
- return;
- }
-
-
- if (fragment_nr == 0)
- {
- memcpy (pack->packet_buf, packet_buf, rcv_len);
- pack->fragment_array[0] = 1;
-
- return;
- }
-
- if ((fragment_nr < pack->num_fragments) && (fragment_nr > 0))
- {
- if ((fragment_nr * fragment_payload_size + rcv_len - sizeof (jacknet_packet_header)) <= (pack->packet_size - sizeof (jacknet_packet_header)))
- {
- memcpy (packet_bufX + fragment_nr * fragment_payload_size, dataX, rcv_len - sizeof (jacknet_packet_header));
- pack->fragment_array[fragment_nr] = 1;
- }
- else
- jack_error ("too long packet received...");
- }
+ jacknet_packet_header *pkthdr = (jacknet_packet_header*)packet_buf;
+ int fragment_payload_size = pack->mtu - sizeof(jacknet_packet_header);
+ char *packet_bufX = pack->packet_buf + sizeof(jacknet_packet_header);
+ char *dataX = packet_buf + sizeof(jacknet_packet_header);
+
+ jack_nframes_t fragment_nr = ntohl (pkthdr->fragment_nr);
+ jack_nframes_t framecnt = ntohl (pkthdr->framecnt);
+
+ if (framecnt != pack->framecnt) {
+ jack_error ("errror. framecnts dont match");
+ return;
+ }
+
+
+ if (fragment_nr == 0) {
+ memcpy (pack->packet_buf, packet_buf, rcv_len);
+ pack->fragment_array[0] = 1;
+
+ return;
+ }
+
+ if ((fragment_nr < pack->num_fragments) && (fragment_nr > 0)) {
+ if ((fragment_nr * fragment_payload_size + rcv_len - sizeof(jacknet_packet_header)) <= (pack->packet_size - sizeof(jacknet_packet_header))) {
+ memcpy (packet_bufX + fragment_nr * fragment_payload_size, dataX, rcv_len - sizeof(jacknet_packet_header));
+ pack->fragment_array[fragment_nr] = 1;
+ } else {
+ jack_error ("too long packet received...");
+ }
+ }
}
int
cache_packet_is_complete (cache_packet *pack)
{
- int i;
- for (i = 0; i < pack->num_fragments; i++)
- if (pack->fragment_array[i] == 0)
- return 0;
+ int i;
- return 1;
+ for (i = 0; i < pack->num_fragments; i++)
+ if (pack->fragment_array[i] == 0) {
+ return 0;
+ }
+
+ return 1;
}
#ifndef WIN32
@@ -365,985 +360,941 @@ cache_packet_is_complete (cache_packet *pack)
int
netjack_poll_deadline (int sockfd, jack_time_t deadline, jack_time_t (*get_microseconds)(void))
{
- struct pollfd fds;
- int poll_err = 0;
+ struct pollfd fds;
+ int poll_err = 0;
+
#if HAVE_PPOLL
- struct timespec timeout_spec = { 0, 0 };
+ struct timespec timeout_spec = { 0, 0 };
#else
- int timeout;
+ int timeout;
#endif
- jack_time_t now = get_microseconds();
- if( now >= deadline )
- return 0;
+ jack_time_t now = get_microseconds ();
+ if ( now >= deadline ) {
+ return 0;
+ }
- if( (deadline-now) >= 1000000 ) {
- jack_error( "deadline more than 1 second in the future, trimming it." );
- deadline = now+500000;
- }
+ if ( (deadline - now) >= 1000000 ) {
+ jack_error ( "deadline more than 1 second in the future, trimming it." );
+ deadline = now + 500000;
+ }
#if HAVE_PPOLL
- timeout_spec.tv_nsec = (deadline - now) * 1000;
+ timeout_spec.tv_nsec = (deadline - now) * 1000;
#else
- timeout = lrintf( (float)(deadline - now) / 1000.0 );
+ timeout = lrintf ( (float)(deadline - now) / 1000.0 );
#endif
- fds.fd = sockfd;
- fds.events = POLLIN;
+ fds.fd = sockfd;
+ fds.events = POLLIN;
#if HAVE_PPOLL
- poll_err = ppoll (&fds, 1, &timeout_spec, NULL);
+ poll_err = ppoll (&fds, 1, &timeout_spec, NULL);
#else
- poll_err = poll (&fds, 1, timeout);
+ poll_err = poll (&fds, 1, timeout);
#endif
- if (poll_err == -1)
- {
- switch (errno)
- {
- case EBADF:
- jack_error ("Error %d: An invalid file descriptor was given in one of the sets", errno);
- break;
- case EFAULT:
- jack_error ("Error %d: The array given as argument was not contained in the calling program's address space", errno);
- break;
- case EINTR:
- jack_error ("Error %d: A signal occurred before any requested event", errno);
- break;
- case EINVAL:
- jack_error ("Error %d: The nfds value exceeds the RLIMIT_NOFILE value", errno);
- break;
- case ENOMEM:
- jack_error ("Error %d: There was no space to allocate file descriptor tables", errno);
- break;
- }
- }
- return poll_err;
+ if (poll_err == -1) {
+ switch (errno) {
+ case EBADF:
+ jack_error ("Error %d: An invalid file descriptor was given in one of the sets", errno);
+ break;
+ case EFAULT:
+ jack_error ("Error %d: The array given as argument was not contained in the calling program's address space", errno);
+ break;
+ case EINTR:
+ jack_error ("Error %d: A signal occurred before any requested event", errno);
+ break;
+ case EINVAL:
+ jack_error ("Error %d: The nfds value exceeds the RLIMIT_NOFILE value", errno);
+ break;
+ case ENOMEM:
+ jack_error ("Error %d: There was no space to allocate file descriptor tables", errno);
+ break;
+ }
+ }
+ return poll_err;
}
int
netjack_poll (int sockfd, int timeout)
{
- struct pollfd fds;
- int i, poll_err = 0;
- sigset_t sigmask, rsigmask;
- struct sigaction action;
-
- sigemptyset(&sigmask);
- sigaddset(&sigmask, SIGHUP);
- sigaddset(&sigmask, SIGINT);
- sigaddset(&sigmask, SIGQUIT);
- sigaddset(&sigmask, SIGPIPE);
- sigaddset(&sigmask, SIGTERM);
- sigaddset(&sigmask, SIGUSR1);
- sigaddset(&sigmask, SIGUSR2);
+ struct pollfd fds;
+ int i, poll_err = 0;
+ sigset_t sigmask, rsigmask;
+ struct sigaction action;
+
+ sigemptyset (&sigmask);
+ sigaddset (&sigmask, SIGHUP);
+ sigaddset (&sigmask, SIGINT);
+ sigaddset (&sigmask, SIGQUIT);
+ sigaddset (&sigmask, SIGPIPE);
+ sigaddset (&sigmask, SIGTERM);
+ sigaddset (&sigmask, SIGUSR1);
+ sigaddset (&sigmask, SIGUSR2);
action.sa_handler = SIG_DFL;
action.sa_mask = sigmask;
action.sa_flags = SA_RESTART;
- for (i = 1; i < NSIG; i++)
- if (sigismember (&sigmask, i))
- sigaction (i, &action, 0);
-
- fds.fd = sockfd;
- fds.events = POLLIN;
-
- sigprocmask(SIG_UNBLOCK, &sigmask, &rsigmask);
- while (poll_err == 0)
- {
- poll_err = poll (&fds, 1, timeout);
- }
- sigprocmask(SIG_SETMASK, &rsigmask, NULL);
-
- if (poll_err == -1)
- {
- switch (errno)
- {
- case EBADF:
- jack_error ("Error %d: An invalid file descriptor was given in one of the sets", errno);
- break;
- case EFAULT:
- jack_error ("Error %d: The array given as argument was not contained in the calling program's address space", errno);
- break;
- case EINTR:
- jack_error ("Error %d: A signal occurred before any requested event", errno);
- break;
- case EINVAL:
- jack_error ("Error %d: The nfds value exceeds the RLIMIT_NOFILE value", errno);
- break;
- case ENOMEM:
- jack_error ("Error %d: There was no space to allocate file descriptor tables", errno);
- break;
- }
- return 0;
- }
- return 1;
+ for (i = 1; i < NSIG; i++)
+ if (sigismember (&sigmask, i)) {
+ sigaction (i, &action, 0);
+ }
+
+ fds.fd = sockfd;
+ fds.events = POLLIN;
+
+ sigprocmask (SIG_UNBLOCK, &sigmask, &rsigmask);
+ while (poll_err == 0)
+ poll_err = poll (&fds, 1, timeout);
+ sigprocmask (SIG_SETMASK, &rsigmask, NULL);
+
+ if (poll_err == -1) {
+ switch (errno) {
+ case EBADF:
+ jack_error ("Error %d: An invalid file descriptor was given in one of the sets", errno);
+ break;
+ case EFAULT:
+ jack_error ("Error %d: The array given as argument was not contained in the calling program's address space", errno);
+ break;
+ case EINTR:
+ jack_error ("Error %d: A signal occurred before any requested event", errno);
+ break;
+ case EINVAL:
+ jack_error ("Error %d: The nfds value exceeds the RLIMIT_NOFILE value", errno);
+ break;
+ case ENOMEM:
+ jack_error ("Error %d: There was no space to allocate file descriptor tables", errno);
+ break;
+ }
+ return 0;
+ }
+ return 1;
}
#else
int
netjack_poll (int sockfd, int timeout)
{
- jack_error( "netjack_poll not implemented" );
- return 0;
+ jack_error ( "netjack_poll not implemented" );
+ return 0;
}
int
netjack_poll_deadline (int sockfd, jack_time_t deadline, jack_time_t (*get_microseconds)(void))
{
- fd_set fds;
- FD_ZERO( &fds );
- FD_SET( sockfd, &fds );
-
- struct timeval timeout;
- while( 1 ) {
- jack_time_t now = get_microseconds();
- if( now >= deadline )
- return 0;
-
- int timeout_usecs = (deadline - now);
- //jack_error( "timeout = %d", timeout_usecs );
- timeout.tv_sec = 0;
- timeout.tv_usec = (timeout_usecs < 500) ? 500 : timeout_usecs;
- timeout.tv_usec = (timeout_usecs > 1000000) ? 500000 : timeout_usecs;
-
- int poll_err = select (0, &fds, NULL, NULL, &timeout);
- if( poll_err != 0 )
- return poll_err;
- }
-
- return 0;
+ fd_set fds;
+
+ FD_ZERO ( &fds );
+ FD_SET ( sockfd, &fds );
+
+ struct timeval timeout;
+ while ( 1 ) {
+ jack_time_t now = get_microseconds ();
+ if ( now >= deadline ) {
+ return 0;
+ }
+
+ int timeout_usecs = (deadline - now);
+ //jack_error( "timeout = %d", timeout_usecs );
+ timeout.tv_sec = 0;
+ timeout.tv_usec = (timeout_usecs < 500) ? 500 : timeout_usecs;
+ timeout.tv_usec = (timeout_usecs > 1000000) ? 500000 : timeout_usecs;
+
+ int poll_err = select (0, &fds, NULL, NULL, &timeout);
+ if ( poll_err != 0 ) {
+ return poll_err;
+ }
+ }
+
+ return 0;
}
#endif
// This now reads all a socket has into the cache.
// replacing netjack_recv functions.
void
-packet_cache_drain_socket( packet_cache *pcache, int sockfd, jack_time_t (*get_microseconds)(void) )
+packet_cache_drain_socket ( packet_cache *pcache, int sockfd, jack_time_t (*get_microseconds)(void) )
{
- char *rx_packet = alloca (pcache->mtu);
- jacknet_packet_header *pkthdr = (jacknet_packet_header *) rx_packet;
- int rcv_len;
- jack_nframes_t framecnt;
- cache_packet *cpack;
- struct sockaddr_in sender_address;
+ char *rx_packet = alloca (pcache->mtu);
+ jacknet_packet_header *pkthdr = (jacknet_packet_header*)rx_packet;
+ int rcv_len;
+ jack_nframes_t framecnt;
+ cache_packet *cpack;
+ struct sockaddr_in sender_address;
+
#ifdef WIN32
- size_t senderlen = sizeof( struct sockaddr_in );
- u_long parm = 1;
- ioctlsocket( sockfd, FIONBIO, &parm );
+ size_t senderlen = sizeof( struct sockaddr_in );
+ u_long parm = 1;
+ ioctlsocket ( sockfd, FIONBIO, &parm );
#else
- socklen_t senderlen = sizeof( struct sockaddr_in );
+ socklen_t senderlen = sizeof( struct sockaddr_in );
#endif
- while (1)
- {
+ while (1) {
#ifdef WIN32
- rcv_len = recvfrom (sockfd, rx_packet, pcache->mtu, 0,
- (struct sockaddr*) &sender_address, &senderlen);
+ rcv_len = recvfrom (sockfd, rx_packet, pcache->mtu, 0,
+ (struct sockaddr*)&sender_address, &senderlen);
#else
- rcv_len = recvfrom (sockfd, rx_packet, pcache->mtu, MSG_DONTWAIT,
- (struct sockaddr*) &sender_address, &senderlen);
+ rcv_len = recvfrom (sockfd, rx_packet, pcache->mtu, MSG_DONTWAIT,
+ (struct sockaddr*)&sender_address, &senderlen);
#endif
- if (rcv_len < 0)
- return;
+ if (rcv_len < 0) {
+ return;
+ }
- if (pcache->master_address_valid) {
- // Verify its from our master.
- if (memcmp (&sender_address, &(pcache->master_address), senderlen) != 0)
- continue;
- } else {
- // Setup this one as master
- //printf( "setup master...\n" );
- memcpy ( &(pcache->master_address), &sender_address, senderlen );
- pcache->master_address_valid = 1;
- }
+ if (pcache->master_address_valid) {
+ // Verify its from our master.
+ if (memcmp (&sender_address, &(pcache->master_address), senderlen) != 0) {
+ continue;
+ }
+ } else {
+ // Setup this one as master
+ //printf( "setup master...\n" );
+ memcpy ( &(pcache->master_address), &sender_address, senderlen );
+ pcache->master_address_valid = 1;
+ }
- framecnt = ntohl (pkthdr->framecnt);
- if( pcache->last_framecnt_retreived_valid && (framecnt <= pcache->last_framecnt_retreived ))
- continue;
+ framecnt = ntohl (pkthdr->framecnt);
+ if ( pcache->last_framecnt_retreived_valid && (framecnt <= pcache->last_framecnt_retreived )) {
+ continue;
+ }
- cpack = packet_cache_get_packet (pcache, framecnt);
- cache_packet_add_fragment (cpack, rx_packet, rcv_len);
- cpack->recv_timestamp = get_microseconds();
- }
+ cpack = packet_cache_get_packet (pcache, framecnt);
+ cache_packet_add_fragment (cpack, rx_packet, rcv_len);
+ cpack->recv_timestamp = get_microseconds ();
+ }
}
void
-packet_cache_reset_master_address( packet_cache *pcache )
+packet_cache_reset_master_address ( packet_cache *pcache )
{
- pcache->master_address_valid = 0;
- pcache->last_framecnt_retreived = 0;
- pcache->last_framecnt_retreived_valid = 0;
+ pcache->master_address_valid = 0;
+ pcache->last_framecnt_retreived = 0;
+ pcache->last_framecnt_retreived_valid = 0;
}
void
packet_cache_clear_old_packets (packet_cache *pcache, jack_nframes_t framecnt )
{
- int i;
-
- for (i = 0; i < pcache->size; i++)
- {
- if (pcache->packets[i].valid && (pcache->packets[i].framecnt < framecnt))
- {
- cache_packet_reset (&(pcache->packets[i]));
- }
- }
+ int i;
+
+ for (i = 0; i < pcache->size; i++) {
+ if (pcache->packets[i].valid && (pcache->packets[i].framecnt < framecnt)) {
+ cache_packet_reset (&(pcache->packets[i]));
+ }
+ }
}
int
-packet_cache_retreive_packet_pointer( packet_cache *pcache, jack_nframes_t framecnt, char **packet_buf, int pkt_size, jack_time_t *timestamp )
+packet_cache_retreive_packet_pointer ( packet_cache *pcache, jack_nframes_t framecnt, char **packet_buf, int pkt_size, jack_time_t *timestamp )
{
- int i;
- cache_packet *cpack = NULL;
+ int i;
+ cache_packet *cpack = NULL;
- for (i = 0; i < pcache->size; i++) {
- if (pcache->packets[i].valid && (pcache->packets[i].framecnt == framecnt)) {
- cpack = &(pcache->packets[i]);
- break;
+ for (i = 0; i < pcache->size; i++) {
+ if (pcache->packets[i].valid && (pcache->packets[i].framecnt == framecnt)) {
+ cpack = &(pcache->packets[i]);
+ break;
+ }
}
- }
- if( cpack == NULL ) {
- //printf( "retreive packet: %d....not found\n", framecnt );
- return -1;
- }
+ if ( cpack == NULL ) {
+ //printf( "retreive packet: %d....not found\n", framecnt );
+ return -1;
+ }
- if( !cache_packet_is_complete( cpack ) ) {
- return -1;
- }
+ if ( !cache_packet_is_complete ( cpack ) ) {
+ return -1;
+ }
- // ok. cpack is the one we want and its complete.
- *packet_buf = cpack->packet_buf;
- if( timestamp )
- *timestamp = cpack->recv_timestamp;
+ // ok. cpack is the one we want and its complete.
+ *packet_buf = cpack->packet_buf;
+ if ( timestamp ) {
+ *timestamp = cpack->recv_timestamp;
+ }
- pcache->last_framecnt_retreived_valid = 1;
- pcache->last_framecnt_retreived = framecnt;
+ pcache->last_framecnt_retreived_valid = 1;
+ pcache->last_framecnt_retreived = framecnt;
- return pkt_size;
+ return pkt_size;
}
int
-packet_cache_release_packet( packet_cache *pcache, jack_nframes_t framecnt )
+packet_cache_release_packet ( packet_cache *pcache, jack_nframes_t framecnt )
{
- int i;
- cache_packet *cpack = NULL;
+ int i;
+ cache_packet *cpack = NULL;
- for (i = 0; i < pcache->size; i++) {
- if (pcache->packets[i].valid && (pcache->packets[i].framecnt == framecnt)) {
- cpack = &(pcache->packets[i]);
- break;
+ for (i = 0; i < pcache->size; i++) {
+ if (pcache->packets[i].valid && (pcache->packets[i].framecnt == framecnt)) {
+ cpack = &(pcache->packets[i]);
+ break;
+ }
}
- }
- if( cpack == NULL ) {
- //printf( "retreive packet: %d....not found\n", framecnt );
- return -1;
- }
+ if ( cpack == NULL ) {
+ //printf( "retreive packet: %d....not found\n", framecnt );
+ return -1;
+ }
- if( !cache_packet_is_complete( cpack ) ) {
- return -1;
- }
+ if ( !cache_packet_is_complete ( cpack ) ) {
+ return -1;
+ }
- cache_packet_reset (cpack);
- packet_cache_clear_old_packets( pcache, framecnt );
+ cache_packet_reset (cpack);
+ packet_cache_clear_old_packets ( pcache, framecnt );
- return 0;
+ return 0;
}
float
-packet_cache_get_fill( packet_cache *pcache, jack_nframes_t expected_framecnt )
+packet_cache_get_fill ( packet_cache *pcache, jack_nframes_t expected_framecnt )
{
- int num_packets_before_us = 0;
- int i;
-
- for (i = 0; i < pcache->size; i++)
- {
- cache_packet *cpack = &(pcache->packets[i]);
- if (cpack->valid && cache_packet_is_complete( cpack ))
- if( cpack->framecnt >= expected_framecnt )
- num_packets_before_us += 1;
- }
-
- return 100.0 * (float)num_packets_before_us / (float)( pcache->size ) ;
+ int num_packets_before_us = 0;
+ int i;
+
+ for (i = 0; i < pcache->size; i++) {
+ cache_packet *cpack = &(pcache->packets[i]);
+ if (cpack->valid && cache_packet_is_complete ( cpack )) {
+ if ( cpack->framecnt >= expected_framecnt ) {
+ num_packets_before_us += 1;
+ }
+ }
+ }
+
+ return 100.0 * (float)num_packets_before_us / (float)( pcache->size );
}
// Returns 0 when no valid packet is inside the cache.
int
-packet_cache_get_next_available_framecnt( packet_cache *pcache, jack_nframes_t expected_framecnt, jack_nframes_t *framecnt )
+packet_cache_get_next_available_framecnt ( packet_cache *pcache, jack_nframes_t expected_framecnt, jack_nframes_t *framecnt )
{
- int i;
- jack_nframes_t best_offset = JACK_MAX_FRAMES/2-1;
- int retval = 0;
-
- for (i = 0; i < pcache->size; i++)
- {
- cache_packet *cpack = &(pcache->packets[i]);
- //printf( "p%d: valid=%d, frame %d\n", i, cpack->valid, cpack->framecnt );
-
- if (!cpack->valid || !cache_packet_is_complete( cpack )) {
- //printf( "invalid\n" );
- continue;
- }
+ int i;
+ jack_nframes_t best_offset = JACK_MAX_FRAMES / 2 - 1;
+ int retval = 0;
- if( cpack->framecnt < expected_framecnt )
- continue;
+ for (i = 0; i < pcache->size; i++) {
+ cache_packet *cpack = &(pcache->packets[i]);
+ //printf( "p%d: valid=%d, frame %d\n", i, cpack->valid, cpack->framecnt );
- if( (cpack->framecnt - expected_framecnt) > best_offset ) {
- continue;
- }
+ if (!cpack->valid || !cache_packet_is_complete ( cpack )) {
+ //printf( "invalid\n" );
+ continue;
+ }
+
+ if ( cpack->framecnt < expected_framecnt ) {
+ continue;
+ }
- best_offset = cpack->framecnt - expected_framecnt;
- retval = 1;
+ if ( (cpack->framecnt - expected_framecnt) > best_offset ) {
+ continue;
+ }
- if( best_offset == 0 )
- break;
- }
- if( retval && framecnt )
- *framecnt = expected_framecnt + best_offset;
+ best_offset = cpack->framecnt - expected_framecnt;
+ retval = 1;
- return retval;
+ if ( best_offset == 0 ) {
+ break;
+ }
+ }
+ if ( retval && framecnt ) {
+ *framecnt = expected_framecnt + best_offset;
+ }
+
+ return retval;
}
int
-packet_cache_get_highest_available_framecnt( packet_cache *pcache, jack_nframes_t *framecnt )
+packet_cache_get_highest_available_framecnt ( packet_cache *pcache, jack_nframes_t *framecnt )
{
- int i;
- jack_nframes_t best_value = 0;
- int retval = 0;
-
- for (i = 0; i < pcache->size; i++)
- {
- cache_packet *cpack = &(pcache->packets[i]);
- //printf( "p%d: valid=%d, frame %d\n", i, cpack->valid, cpack->framecnt );
-
- if (!cpack->valid || !cache_packet_is_complete( cpack )) {
- //printf( "invalid\n" );
- continue;
- }
+ int i;
+ jack_nframes_t best_value = 0;
+ int retval = 0;
- if (cpack->framecnt < best_value) {
- continue;
- }
+ for (i = 0; i < pcache->size; i++) {
+ cache_packet *cpack = &(pcache->packets[i]);
+ //printf( "p%d: valid=%d, frame %d\n", i, cpack->valid, cpack->framecnt );
- best_value = cpack->framecnt;
- retval = 1;
+ if (!cpack->valid || !cache_packet_is_complete ( cpack )) {
+ //printf( "invalid\n" );
+ continue;
+ }
+
+ if (cpack->framecnt < best_value) {
+ continue;
+ }
- }
- if( retval && framecnt )
- *framecnt = best_value;
+ best_value = cpack->framecnt;
+ retval = 1;
+
+ }
+ if ( retval && framecnt ) {
+ *framecnt = best_value;
+ }
- return retval;
+ return retval;
}
// Returns 0 when no valid packet is inside the cache.
int
-packet_cache_find_latency( packet_cache *pcache, jack_nframes_t expected_framecnt, jack_nframes_t *framecnt )
+packet_cache_find_latency ( packet_cache *pcache, jack_nframes_t expected_framecnt, jack_nframes_t *framecnt )
{
- int i;
- jack_nframes_t best_offset = 0;
- int retval = 0;
-
- for (i = 0; i < pcache->size; i++)
- {
- cache_packet *cpack = &(pcache->packets[i]);
- //printf( "p%d: valid=%d, frame %d\n", i, cpack->valid, cpack->framecnt );
-
- if (!cpack->valid || !cache_packet_is_complete( cpack )) {
- //printf( "invalid\n" );
- continue;
- }
+ int i;
+ jack_nframes_t best_offset = 0;
+ int retval = 0;
- if( (cpack->framecnt - expected_framecnt) < best_offset ) {
- continue;
- }
+ for (i = 0; i < pcache->size; i++) {
+ cache_packet *cpack = &(pcache->packets[i]);
+ //printf( "p%d: valid=%d, frame %d\n", i, cpack->valid, cpack->framecnt );
+
+ if (!cpack->valid || !cache_packet_is_complete ( cpack )) {
+ //printf( "invalid\n" );
+ continue;
+ }
+
+ if ( (cpack->framecnt - expected_framecnt) < best_offset ) {
+ continue;
+ }
- best_offset = cpack->framecnt - expected_framecnt;
- retval = 1;
+ best_offset = cpack->framecnt - expected_framecnt;
+ retval = 1;
- if( best_offset == 0 )
- break;
- }
- if( retval && framecnt )
- *framecnt = JACK_MAX_FRAMES - best_offset;
+ if ( best_offset == 0 ) {
+ break;
+ }
+ }
+ if ( retval && framecnt ) {
+ *framecnt = JACK_MAX_FRAMES - best_offset;
+ }
- return retval;
+ return retval;
}
// fragmented packet IO
void
netjack_sendto (int sockfd, char *packet_buf, int pkt_size, int flags, struct sockaddr *addr, int addr_size, int mtu)
{
- int frag_cnt = 0;
- char *tx_packet, *dataX;
- jacknet_packet_header *pkthdr;
-
- tx_packet = alloca (mtu + 10);
- dataX = tx_packet + sizeof (jacknet_packet_header);
- pkthdr = (jacknet_packet_header *) tx_packet;
-
- int fragment_payload_size = mtu - sizeof (jacknet_packet_header);
-
- if (pkt_size <= mtu) {
- int err;
- pkthdr = (jacknet_packet_header *) packet_buf;
- pkthdr->fragment_nr = htonl (0);
- err = sendto(sockfd, packet_buf, pkt_size, flags, addr, addr_size);
- if( err<0 ) {
- //printf( "error in send\n" );
- perror( "send" );
- }
- }
- else
- {
- int err;
- // Copy the packet header to the tx pack first.
- memcpy(tx_packet, packet_buf, sizeof (jacknet_packet_header));
-
- // Now loop and send all
- char *packet_bufX = packet_buf + sizeof (jacknet_packet_header);
-
- while (packet_bufX < (packet_buf + pkt_size - fragment_payload_size))
- {
- pkthdr->fragment_nr = htonl (frag_cnt++);
- memcpy (dataX, packet_bufX, fragment_payload_size);
- sendto (sockfd, tx_packet, mtu, flags, addr, addr_size);
- packet_bufX += fragment_payload_size;
- }
-
- int last_payload_size = packet_buf + pkt_size - packet_bufX;
- memcpy (dataX, packet_bufX, last_payload_size);
- pkthdr->fragment_nr = htonl (frag_cnt);
- //jack_log("last fragment_count = %d, payload_size = %d\n", fragment_count, last_payload_size);
-
- // sendto(last_pack_size);
- err = sendto(sockfd, tx_packet, last_payload_size + sizeof(jacknet_packet_header), flags, addr, addr_size);
- if( err<0 ) {
- //printf( "error in send\n" );
- perror( "send" );
+ int frag_cnt = 0;
+ char *tx_packet, *dataX;
+ jacknet_packet_header *pkthdr;
+
+ tx_packet = alloca (mtu + 10);
+ dataX = tx_packet + sizeof(jacknet_packet_header);
+ pkthdr = (jacknet_packet_header*)tx_packet;
+
+ int fragment_payload_size = mtu - sizeof(jacknet_packet_header);
+
+ if (pkt_size <= mtu) {
+ int err;
+ pkthdr = (jacknet_packet_header*)packet_buf;
+ pkthdr->fragment_nr = htonl (0);
+ err = sendto (sockfd, packet_buf, pkt_size, flags, addr, addr_size);
+ if ( err < 0 ) {
+ //printf( "error in send\n" );
+ perror ( "send" );
+ }
+ } else {
+ int err;
+ // Copy the packet header to the tx pack first.
+ memcpy (tx_packet, packet_buf, sizeof(jacknet_packet_header));
+
+ // Now loop and send all
+ char *packet_bufX = packet_buf + sizeof(jacknet_packet_header);
+
+ while (packet_bufX < (packet_buf + pkt_size - fragment_payload_size)) {
+ pkthdr->fragment_nr = htonl (frag_cnt++);
+ memcpy (dataX, packet_bufX, fragment_payload_size);
+ sendto (sockfd, tx_packet, mtu, flags, addr, addr_size);
+ packet_bufX += fragment_payload_size;
+ }
+
+ int last_payload_size = packet_buf + pkt_size - packet_bufX;
+ memcpy (dataX, packet_bufX, last_payload_size);
+ pkthdr->fragment_nr = htonl (frag_cnt);
+ //jack_log("last fragment_count = %d, payload_size = %d\n", fragment_count, last_payload_size);
+
+ // sendto(last_pack_size);
+ err = sendto (sockfd, tx_packet, last_payload_size + sizeof(jacknet_packet_header), flags, addr, addr_size);
+ if ( err < 0 ) {
+ //printf( "error in send\n" );
+ perror ( "send" );
+ }
}
- }
}
void
decode_midi_buffer (uint32_t *buffer_uint32, unsigned int buffer_size_uint32, jack_default_audio_sample_t* buf)
{
- int i;
- jack_midi_clear_buffer (buf);
- for (i = 0; i < buffer_size_uint32 - 3;)
- {
- uint32_t payload_size;
- payload_size = buffer_uint32[i];
- payload_size = ntohl (payload_size);
- if (payload_size)
- {
- jack_midi_event_t event;
- event.time = ntohl (buffer_uint32[i+1]);
- event.size = ntohl (buffer_uint32[i+2]);
- event.buffer = (jack_midi_data_t*) (&(buffer_uint32[i+3]));
- jack_midi_event_write (buf, event.time, event.buffer, event.size);
-
- // skip to the next event
- unsigned int nb_data_quads = (((event.size-1) & ~0x3) >> 2)+1;
- i += 3+nb_data_quads;
- }
- else
- break; // no events can follow an empty event, we're done
- }
+ int i;
+
+ jack_midi_clear_buffer (buf);
+ for (i = 0; i < buffer_size_uint32 - 3; ) {
+ uint32_t payload_size;
+ payload_size = buffer_uint32[i];
+ payload_size = ntohl (payload_size);
+ if (payload_size) {
+ jack_midi_event_t event;
+ event.time = ntohl (buffer_uint32[i + 1]);
+ event.size = ntohl (buffer_uint32[i + 2]);
+ event.buffer = (jack_midi_data_t*)(&(buffer_uint32[i + 3]));
+ jack_midi_event_write (buf, event.time, event.buffer, event.size);
+
+ // skip to the next event
+ unsigned int nb_data_quads = (((event.size - 1) & ~0x3) >> 2) + 1;
+ i += 3 + nb_data_quads;
+ } else {
+ break; // no events can follow an empty event, we're done
+ }
+ }
}
void
encode_midi_buffer (uint32_t *buffer_uint32, unsigned int buffer_size_uint32, jack_default_audio_sample_t* buf)
{
- int i;
- unsigned int written = 0;
- // midi port, encode midi events
- unsigned int nevents = jack_midi_get_event_count (buf);
- for (i = 0; i < nevents; ++i)
- {
- jack_midi_event_t event;
- jack_midi_event_get (&event, buf, i);
- unsigned int nb_data_quads = (((event.size - 1) & ~0x3) >> 2) + 1;
- unsigned int payload_size = 3 + nb_data_quads;
- // only write if we have sufficient space for the event
- // otherwise drop it
- if (written + payload_size < buffer_size_uint32 - 1)
- {
- // write header
- buffer_uint32[written]=htonl (payload_size);
- written++;
- buffer_uint32[written]=htonl (event.time);
- written++;
- buffer_uint32[written]=htonl (event.size);
- written++;
-
- // write data
- jack_midi_data_t* tmpbuff = (jack_midi_data_t*)(&(buffer_uint32[written]));
- memcpy (tmpbuff, event.buffer, event.size);
- written += nb_data_quads;
- }
- else
- {
- // buffer overflow
- jack_error ("midi buffer overflow");
- break;
- }
- }
- // now put a netjack_midi 'no-payload' event, signaling EOF
- buffer_uint32[written]=0;
+ int i;
+ unsigned int written = 0;
+ // midi port, encode midi events
+ unsigned int nevents = jack_midi_get_event_count (buf);
+
+ for (i = 0; i < nevents; ++i) {
+ jack_midi_event_t event;
+ jack_midi_event_get (&event, buf, i);
+ unsigned int nb_data_quads = (((event.size - 1) & ~0x3) >> 2) + 1;
+ unsigned int payload_size = 3 + nb_data_quads;
+ // only write if we have sufficient space for the event
+ // otherwise drop it
+ if (written + payload_size < buffer_size_uint32 - 1) {
+ // write header
+ buffer_uint32[written] = htonl (payload_size);
+ written++;
+ buffer_uint32[written] = htonl (event.time);
+ written++;
+ buffer_uint32[written] = htonl (event.size);
+ written++;
+
+ // write data
+ jack_midi_data_t* tmpbuff = (jack_midi_data_t*)(&(buffer_uint32[written]));
+ memcpy (tmpbuff, event.buffer, event.size);
+ written += nb_data_quads;
+ } else {
+ // buffer overflow
+ jack_error ("midi buffer overflow");
+ break;
+ }
+ }
+ // now put a netjack_midi 'no-payload' event, signaling EOF
+ buffer_uint32[written] = 0;
}
// render functions for float
void
render_payload_to_jack_ports_float ( void *packet_payload, jack_nframes_t net_period_down, JSList *capture_ports, JSList *capture_srcs, jack_nframes_t nframes, int dont_htonl_floats)
{
- int chn = 0;
- JSList *node = capture_ports;
+ int chn = 0;
+ JSList *node = capture_ports;
+
#if HAVE_SAMPLERATE
- JSList *src_node = capture_srcs;
+ JSList *src_node = capture_srcs;
#endif
- uint32_t *packet_bufX = (uint32_t *)packet_payload;
+ uint32_t *packet_bufX = (uint32_t*)packet_payload;
- if( !packet_payload )
- return;
+ if ( !packet_payload ) {
+ return;
+ }
- while (node != NULL)
- {
- int i;
- int_float_t val;
+ while (node != NULL) {
+ int i;
+ int_float_t val;
#if HAVE_SAMPLERATE
- SRC_DATA src;
+ SRC_DATA src;
#endif
- jack_port_t *port = (jack_port_t *) node->data;
- jack_default_audio_sample_t* buf = jack_port_get_buffer (port, nframes);
+ jack_port_t *port = (jack_port_t*)node->data;
+ jack_default_audio_sample_t* buf = jack_port_get_buffer (port, nframes);
- const char *porttype = jack_port_type (port);
+ const char *porttype = jack_port_type (port);
- if (jack_port_is_audio (porttype))
- {
+ if (jack_port_is_audio (porttype)) {
#if HAVE_SAMPLERATE
- // audio port, resample if necessary
- if (net_period_down != nframes)
- {
- SRC_STATE *src_state = src_node->data;
- for (i = 0; i < net_period_down; i++)
- {
- packet_bufX[i] = ntohl (packet_bufX[i]);
- }
-
- src.data_in = (float *) packet_bufX;
- src.input_frames = net_period_down;
-
- src.data_out = buf;
- src.output_frames = nframes;
-
- src.src_ratio = (float) nframes / (float) net_period_down;
- src.end_of_input = 0;
-
- src_set_ratio (src_state, src.src_ratio);
- src_process (src_state, &src);
- src_node = jack_slist_next (src_node);
- }
- else
+ // audio port, resample if necessary
+ if (net_period_down != nframes) {
+ SRC_STATE *src_state = src_node->data;
+ for (i = 0; i < net_period_down; i++)
+ packet_bufX[i] = ntohl (packet_bufX[i]);
+
+ src.data_in = (float*)packet_bufX;
+ src.input_frames = net_period_down;
+
+ src.data_out = buf;
+ src.output_frames = nframes;
+
+ src.src_ratio = (float)nframes / (float)net_period_down;
+ src.end_of_input = 0;
+
+ src_set_ratio (src_state, src.src_ratio);
+ src_process (src_state, &src);
+ src_node = jack_slist_next (src_node);
+ } else
#endif
- {
- if( dont_htonl_floats )
- {
- memcpy( buf, packet_bufX, net_period_down*sizeof(jack_default_audio_sample_t));
- }
- else
- {
- for (i = 0; i < net_period_down; i++)
- {
- val.i = packet_bufX[i];
- val.i = ntohl (val.i);
- buf[i] = val.f;
- }
+ {
+ if ( dont_htonl_floats ) {
+ memcpy ( buf, packet_bufX, net_period_down * sizeof(jack_default_audio_sample_t));
+ } else {
+ for (i = 0; i < net_period_down; i++) {
+ val.i = packet_bufX[i];
+ val.i = ntohl (val.i);
+ buf[i] = val.f;
+ }
+ }
+ }
+ } else if (jack_port_is_midi (porttype)) {
+ // midi port, decode midi events
+ // convert the data buffer to a standard format (uint32_t based)
+ unsigned int buffer_size_uint32 = net_period_down;
+ uint32_t * buffer_uint32 = (uint32_t*)packet_bufX;
+ decode_midi_buffer (buffer_uint32, buffer_size_uint32, buf);
}
- }
- }
- else if (jack_port_is_midi (porttype))
- {
- // midi port, decode midi events
- // convert the data buffer to a standard format (uint32_t based)
- unsigned int buffer_size_uint32 = net_period_down;
- uint32_t * buffer_uint32 = (uint32_t*)packet_bufX;
- decode_midi_buffer (buffer_uint32, buffer_size_uint32, buf);
- }
- packet_bufX = (packet_bufX + net_period_down);
- node = jack_slist_next (node);
- chn++;
- }
+ packet_bufX = (packet_bufX + net_period_down);
+ node = jack_slist_next (node);
+ chn++;
+ }
}
void
render_jack_ports_to_payload_float (JSList *playback_ports, JSList *playback_srcs, jack_nframes_t nframes, void *packet_payload, jack_nframes_t net_period_up, int dont_htonl_floats )
{
- int chn = 0;
- JSList *node = playback_ports;
+ int chn = 0;
+ JSList *node = playback_ports;
+
#if HAVE_SAMPLERATE
- JSList *src_node = playback_srcs;
+ JSList *src_node = playback_srcs;
#endif
- uint32_t *packet_bufX = (uint32_t *) packet_payload;
+ uint32_t *packet_bufX = (uint32_t*)packet_payload;
- while (node != NULL)
- {
+ while (node != NULL) {
#if HAVE_SAMPLERATE
- SRC_DATA src;
+ SRC_DATA src;
#endif
- int i;
- int_float_t val;
- jack_port_t *port = (jack_port_t *) node->data;
- jack_default_audio_sample_t* buf = jack_port_get_buffer (port, nframes);
+ int i;
+ int_float_t val;
+ jack_port_t *port = (jack_port_t*)node->data;
+ jack_default_audio_sample_t* buf = jack_port_get_buffer (port, nframes);
- const char *porttype = jack_port_type (port);
+ const char *porttype = jack_port_type (port);
- if (jack_port_is_audio (porttype))
- {
- // audio port, resample if necessary
+ if (jack_port_is_audio (porttype)) {
+ // audio port, resample if necessary
#if HAVE_SAMPLERATE
- if (net_period_up != nframes) {
- SRC_STATE *src_state = src_node->data;
- src.data_in = buf;
- src.input_frames = nframes;
-
- src.data_out = (float *) packet_bufX;
- src.output_frames = net_period_up;
-
- src.src_ratio = (float) net_period_up / (float) nframes;
- src.end_of_input = 0;
-
- src_set_ratio (src_state, src.src_ratio);
- src_process (src_state, &src);
-
- for (i = 0; i < net_period_up; i++)
- {
- packet_bufX[i] = htonl (packet_bufX[i]);
- }
- src_node = jack_slist_next (src_node);
- }
- else
+ if (net_period_up != nframes) {
+ SRC_STATE *src_state = src_node->data;
+ src.data_in = buf;
+ src.input_frames = nframes;
+
+ src.data_out = (float*)packet_bufX;
+ src.output_frames = net_period_up;
+
+ src.src_ratio = (float)net_period_up / (float)nframes;
+ src.end_of_input = 0;
+
+ src_set_ratio (src_state, src.src_ratio);
+ src_process (src_state, &src);
+
+ for (i = 0; i < net_period_up; i++)
+ packet_bufX[i] = htonl (packet_bufX[i]);
+ src_node = jack_slist_next (src_node);
+ } else
#endif
- {
- if( dont_htonl_floats )
- {
- memcpy( packet_bufX, buf, net_period_up*sizeof(jack_default_audio_sample_t) );
+ {
+ if ( dont_htonl_floats ) {
+ memcpy ( packet_bufX, buf, net_period_up * sizeof(jack_default_audio_sample_t) );
+ } else {
+ for (i = 0; i < net_period_up; i++) {
+ val.f = buf[i];
+ val.i = htonl (val.i);
+ packet_bufX[i] = val.i;
+ }
+ }
+ }
+ } else if (jack_port_is_midi (porttype)) {
+ // encode midi events from port to packet
+ // convert the data buffer to a standard format (uint32_t based)
+ unsigned int buffer_size_uint32 = net_period_up;
+ uint32_t * buffer_uint32 = (uint32_t*)packet_bufX;
+ encode_midi_buffer (buffer_uint32, buffer_size_uint32, buf);
}
- else
- {
- for (i = 0; i < net_period_up; i++)
- {
- val.f = buf[i];
- val.i = htonl (val.i);
- packet_bufX[i] = val.i;
- }
- }
- }
- }
- else if (jack_port_is_midi (porttype))
- {
- // encode midi events from port to packet
- // convert the data buffer to a standard format (uint32_t based)
- unsigned int buffer_size_uint32 = net_period_up;
- uint32_t * buffer_uint32 = (uint32_t*) packet_bufX;
- encode_midi_buffer (buffer_uint32, buffer_size_uint32, buf);
- }
- packet_bufX = (packet_bufX + net_period_up);
- node = jack_slist_next (node);
- chn++;
- }
+ packet_bufX = (packet_bufX + net_period_up);
+ node = jack_slist_next (node);
+ chn++;
+ }
}
// render functions for 16bit
void
render_payload_to_jack_ports_16bit (void *packet_payload, jack_nframes_t net_period_down, JSList *capture_ports, JSList *capture_srcs, jack_nframes_t nframes)
{
- int chn = 0;
- JSList *node = capture_ports;
+ int chn = 0;
+ JSList *node = capture_ports;
+
#if HAVE_SAMPLERATE
- JSList *src_node = capture_srcs;
+ JSList *src_node = capture_srcs;
#endif
- uint16_t *packet_bufX = (uint16_t *)packet_payload;
+ uint16_t *packet_bufX = (uint16_t*)packet_payload;
- if( !packet_payload )
- return;
+ if ( !packet_payload ) {
+ return;
+ }
- while (node != NULL)
- {
- int i;
- //uint32_t val;
+ while (node != NULL) {
+ int i;
+ //uint32_t val;
#if HAVE_SAMPLERATE
- SRC_DATA src;
+ SRC_DATA src;
#endif
- jack_port_t *port = (jack_port_t *) node->data;
- jack_default_audio_sample_t* buf = jack_port_get_buffer (port, nframes);
+ jack_port_t *port = (jack_port_t*)node->data;
+ jack_default_audio_sample_t* buf = jack_port_get_buffer (port, nframes);
#if HAVE_SAMPLERATE
- float *floatbuf = alloca (sizeof(float) * net_period_down);
+ float *floatbuf = alloca (sizeof(float) * net_period_down);
#endif
- const char *porttype = jack_port_type (port);
+ const char *porttype = jack_port_type (port);
- if (jack_port_is_audio (porttype))
- {
- // audio port, resample if necessary
+ if (jack_port_is_audio (porttype)) {
+ // audio port, resample if necessary
#if HAVE_SAMPLERATE
- if (net_period_down != nframes)
- {
- SRC_STATE *src_state = src_node->data;
- for (i = 0; i < net_period_down; i++)
- {
- floatbuf[i] = ((float) ntohs(packet_bufX[i])) / 32767.0 - 1.0;
- }
-
- src.data_in = floatbuf;
- src.input_frames = net_period_down;
-
- src.data_out = buf;
- src.output_frames = nframes;
-
- src.src_ratio = (float) nframes / (float) net_period_down;
- src.end_of_input = 0;
-
- src_set_ratio (src_state, src.src_ratio);
- src_process (src_state, &src);
- src_node = jack_slist_next (src_node);
- }
- else
+ if (net_period_down != nframes) {
+ SRC_STATE *src_state = src_node->data;
+ for (i = 0; i < net_period_down; i++)
+ floatbuf[i] = ((float)ntohs (packet_bufX[i])) / 32767.0 - 1.0;
+
+ src.data_in = floatbuf;
+ src.input_frames = net_period_down;
+
+ src.data_out = buf;
+ src.output_frames = nframes;
+
+ src.src_ratio = (float)nframes / (float)net_period_down;
+ src.end_of_input = 0;
+
+ src_set_ratio (src_state, src.src_ratio);
+ src_process (src_state, &src);
+ src_node = jack_slist_next (src_node);
+ } else
#endif
- for (i = 0; i < net_period_down; i++)
- buf[i] = ((float) ntohs (packet_bufX[i])) / 32768.0 - 1.0;
- }
- else if (jack_port_is_midi (porttype))
- {
- // midi port, decode midi events
- // convert the data buffer to a standard format (uint32_t based)
- unsigned int buffer_size_uint32 = net_period_down / 2;
- uint32_t * buffer_uint32 = (uint32_t*) packet_bufX;
- decode_midi_buffer (buffer_uint32, buffer_size_uint32, buf);
- }
- packet_bufX = (packet_bufX + net_period_down);
- node = jack_slist_next (node);
- chn++;
- }
+ for (i = 0; i < net_period_down; i++)
+ buf[i] = ((float)ntohs (packet_bufX[i])) / 32768.0 - 1.0;
+ } else if (jack_port_is_midi (porttype)) {
+ // midi port, decode midi events
+ // convert the data buffer to a standard format (uint32_t based)
+ unsigned int buffer_size_uint32 = net_period_down / 2;
+ uint32_t * buffer_uint32 = (uint32_t*)packet_bufX;
+ decode_midi_buffer (buffer_uint32, buffer_size_uint32, buf);
+ }
+ packet_bufX = (packet_bufX + net_period_down);
+ node = jack_slist_next (node);
+ chn++;
+ }
}
void
render_jack_ports_to_payload_16bit (JSList *playback_ports, JSList *playback_srcs, jack_nframes_t nframes, void *packet_payload, jack_nframes_t net_period_up)
{
- int chn = 0;
- JSList *node = playback_ports;
+ int chn = 0;
+ JSList *node = playback_ports;
+
#if HAVE_SAMPLERATE
- JSList *src_node = playback_srcs;
+ JSList *src_node = playback_srcs;
#endif
- uint16_t *packet_bufX = (uint16_t *)packet_payload;
+ uint16_t *packet_bufX = (uint16_t*)packet_payload;
- while (node != NULL)
- {
+ while (node != NULL) {
#if HAVE_SAMPLERATE
- SRC_DATA src;
+ SRC_DATA src;
#endif
- int i;
- jack_port_t *port = (jack_port_t *) node->data;
- jack_default_audio_sample_t* buf = jack_port_get_buffer (port, nframes);
- const char *porttype = jack_port_type (port);
+ int i;
+ jack_port_t *port = (jack_port_t*)node->data;
+ jack_default_audio_sample_t* buf = jack_port_get_buffer (port, nframes);
+ const char *porttype = jack_port_type (port);
- if (jack_port_is_audio (porttype))
- {
- // audio port, resample if necessary
+ if (jack_port_is_audio (porttype)) {
+ // audio port, resample if necessary
#if HAVE_SAMPLERATE
- if (net_period_up != nframes)
- {
- SRC_STATE *src_state = src_node->data;
+ if (net_period_up != nframes) {
+ SRC_STATE *src_state = src_node->data;
- float *floatbuf = alloca (sizeof(float) * net_period_up);
+ float *floatbuf = alloca (sizeof(float) * net_period_up);
- src.data_in = buf;
- src.input_frames = nframes;
+ src.data_in = buf;
+ src.input_frames = nframes;
- src.data_out = floatbuf;
- src.output_frames = net_period_up;
+ src.data_out = floatbuf;
+ src.output_frames = net_period_up;
- src.src_ratio = (float) net_period_up / (float) nframes;
- src.end_of_input = 0;
+ src.src_ratio = (float)net_period_up / (float)nframes;
+ src.end_of_input = 0;
- src_set_ratio (src_state, src.src_ratio);
- src_process (src_state, &src);
+ src_set_ratio (src_state, src.src_ratio);
+ src_process (src_state, &src);
- for (i = 0; i < net_period_up; i++)
- {
- packet_bufX[i] = htons (((uint16_t)((floatbuf[i] + 1.0) * 32767.0)));
- }
- src_node = jack_slist_next (src_node);
- }
- else
+ for (i = 0; i < net_period_up; i++)
+ packet_bufX[i] = htons (((uint16_t)((floatbuf[i] + 1.0) * 32767.0)));
+ src_node = jack_slist_next (src_node);
+ } else
#endif
- for (i = 0; i < net_period_up; i++)
- packet_bufX[i] = htons(((uint16_t)((buf[i] + 1.0) * 32767.0)));
- }
- else if (jack_port_is_midi (porttype))
- {
- // encode midi events from port to packet
- // convert the data buffer to a standard format (uint32_t based)
- unsigned int buffer_size_uint32 = net_period_up / 2;
- uint32_t * buffer_uint32 = (uint32_t*) packet_bufX;
- encode_midi_buffer (buffer_uint32, buffer_size_uint32, buf);
- }
- packet_bufX = (packet_bufX + net_period_up);
- node = jack_slist_next (node);
- chn++;
- }
+ for (i = 0; i < net_period_up; i++)
+ packet_bufX[i] = htons (((uint16_t)((buf[i] + 1.0) * 32767.0)));
+ } else if (jack_port_is_midi (porttype)) {
+ // encode midi events from port to packet
+ // convert the data buffer to a standard format (uint32_t based)
+ unsigned int buffer_size_uint32 = net_period_up / 2;
+ uint32_t * buffer_uint32 = (uint32_t*)packet_bufX;
+ encode_midi_buffer (buffer_uint32, buffer_size_uint32, buf);
+ }
+ packet_bufX = (packet_bufX + net_period_up);
+ node = jack_slist_next (node);
+ chn++;
+ }
}
// render functions for 8bit
void
render_payload_to_jack_ports_8bit (void *packet_payload, jack_nframes_t net_period_down, JSList *capture_ports, JSList *capture_srcs, jack_nframes_t nframes)
{
- int chn = 0;
- JSList *node = capture_ports;
+ int chn = 0;
+ JSList *node = capture_ports;
#if HAVE_SAMPLERATE
- JSList *src_node = capture_srcs;
+ JSList *src_node = capture_srcs;
#endif
- int8_t *packet_bufX = (int8_t *)packet_payload;
+ int8_t *packet_bufX = (int8_t*)packet_payload;
- if( !packet_payload )
- return;
+ if ( !packet_payload ) {
+ return;
+ }
- while (node != NULL)
- {
- int i;
- //uint32_t val;
+ while (node != NULL) {
+ int i;
+ //uint32_t val;
#if HAVE_SAMPLERATE
- SRC_DATA src;
+ SRC_DATA src;
#endif
- jack_port_t *port = (jack_port_t *) node->data;
- jack_default_audio_sample_t* buf = jack_port_get_buffer (port, nframes);
+ jack_port_t *port = (jack_port_t*)node->data;
+ jack_default_audio_sample_t* buf = jack_port_get_buffer (port, nframes);
#if HAVE_SAMPLERATE
- float *floatbuf = alloca (sizeof (float) * net_period_down);
+ float *floatbuf = alloca (sizeof(float) * net_period_down);
#endif
- const char *porttype = jack_port_type (port);
+ const char *porttype = jack_port_type (port);
- if (jack_port_is_audio(porttype))
- {
+ if (jack_port_is_audio (porttype)) {
#if HAVE_SAMPLERATE
- // audio port, resample if necessary
- if (net_period_down != nframes)
- {
- SRC_STATE *src_state = src_node->data;
- for (i = 0; i < net_period_down; i++)
- floatbuf[i] = ((float) packet_bufX[i]) / 127.0;
-
- src.data_in = floatbuf;
- src.input_frames = net_period_down;
-
- src.data_out = buf;
- src.output_frames = nframes;
-
- src.src_ratio = (float) nframes / (float) net_period_down;
- src.end_of_input = 0;
-
- src_set_ratio (src_state, src.src_ratio);
- src_process (src_state, &src);
- src_node = jack_slist_next (src_node);
- }
- else
+ // audio port, resample if necessary
+ if (net_period_down != nframes) {
+ SRC_STATE *src_state = src_node->data;
+ for (i = 0; i < net_period_down; i++)
+ floatbuf[i] = ((float)packet_bufX[i]) / 127.0;
+
+ src.data_in = floatbuf;
+ src.input_frames = net_period_down;
+
+ src.data_out = buf;
+ src.output_frames = nframes;
+
+ src.src_ratio = (float)nframes / (float)net_period_down;
+ src.end_of_input = 0;
+
+ src_set_ratio (src_state, src.src_ratio);
+ src_process (src_state, &src);
+ src_node = jack_slist_next (src_node);
+ } else
#endif
- for (i = 0; i < net_period_down; i++)
- buf[i] = ((float) packet_bufX[i]) / 127.0;
- }
- else if (jack_port_is_midi (porttype))
- {
- // midi port, decode midi events
- // convert the data buffer to a standard format (uint32_t based)
- unsigned int buffer_size_uint32 = net_period_down / 4;
- uint32_t * buffer_uint32 = (uint32_t*) packet_bufX;
- decode_midi_buffer (buffer_uint32, buffer_size_uint32, buf);
- }
- packet_bufX = (packet_bufX + net_period_down);
- node = jack_slist_next (node);
- chn++;
- }
+ for (i = 0; i < net_period_down; i++)
+ buf[i] = ((float)packet_bufX[i]) / 127.0;
+ } else if (jack_port_is_midi (porttype)) {
+ // midi port, decode midi events
+ // convert the data buffer to a standard format (uint32_t based)
+ unsigned int buffer_size_uint32 = net_period_down / 4;
+ uint32_t * buffer_uint32 = (uint32_t*)packet_bufX;
+ decode_midi_buffer (buffer_uint32, buffer_size_uint32, buf);
+ }
+ packet_bufX = (packet_bufX + net_period_down);
+ node = jack_slist_next (node);
+ chn++;
+ }
}
void
render_jack_ports_to_payload_8bit (JSList *playback_ports, JSList *playback_srcs, jack_nframes_t nframes, void *packet_payload, jack_nframes_t net_period_up)
{
- int chn = 0;
- JSList *node = playback_ports;
+ int chn = 0;
+ JSList *node = playback_ports;
+
#if HAVE_SAMPLERATE
- JSList *src_node = playback_srcs;
+ JSList *src_node = playback_srcs;
#endif
- int8_t *packet_bufX = (int8_t *)packet_payload;
+ int8_t *packet_bufX = (int8_t*)packet_payload;
- while (node != NULL)
- {
+ while (node != NULL) {
#if HAVE_SAMPLERATE
- SRC_DATA src;
+ SRC_DATA src;
#endif
- int i;
- jack_port_t *port = (jack_port_t *) node->data;
+ int i;
+ jack_port_t *port = (jack_port_t*)node->data;
- jack_default_audio_sample_t* buf = jack_port_get_buffer (port, nframes);
- const char *porttype = jack_port_type (port);
+ jack_default_audio_sample_t* buf = jack_port_get_buffer (port, nframes);
+ const char *porttype = jack_port_type (port);
- if (jack_port_is_audio (porttype))
- {
+ if (jack_port_is_audio (porttype)) {
#if HAVE_SAMPLERATE
- // audio port, resample if necessary
- if (net_period_up != nframes)
- {
+ // audio port, resample if necessary
+ if (net_period_up != nframes) {
- SRC_STATE *src_state = src_node->data;
+ SRC_STATE *src_state = src_node->data;
- float *floatbuf = alloca (sizeof (float) * net_period_up);
+ float *floatbuf = alloca (sizeof(float) * net_period_up);
- src.data_in = buf;
- src.input_frames = nframes;
+ src.data_in = buf;
+ src.input_frames = nframes;
- src.data_out = floatbuf;
- src.output_frames = net_period_up;
+ src.data_out = floatbuf;
+ src.output_frames = net_period_up;
- src.src_ratio = (float) net_period_up / (float) nframes;
- src.end_of_input = 0;
+ src.src_ratio = (float)net_period_up / (float)nframes;
+ src.end_of_input = 0;
- src_set_ratio (src_state, src.src_ratio);
- src_process (src_state, &src);
+ src_set_ratio (src_state, src.src_ratio);
+ src_process (src_state, &src);
- for (i = 0; i < net_period_up; i++)
- packet_bufX[i] = floatbuf[i] * 127.0;
- src_node = jack_slist_next (src_node);
- }
- else
+ for (i = 0; i < net_period_up; i++)
+ packet_bufX[i] = floatbuf[i] * 127.0;
+ src_node = jack_slist_next (src_node);
+ } else
#endif
- for (i = 0; i < net_period_up; i++)
- packet_bufX[i] = buf[i] * 127.0;
- }
- else if (jack_port_is_midi (porttype))
- {
- // encode midi events from port to packet
- // convert the data buffer to a standard format (uint32_t based)
- unsigned int buffer_size_uint32 = net_period_up / 4;
- uint32_t * buffer_uint32 = (uint32_t*) packet_bufX;
- encode_midi_buffer (buffer_uint32, buffer_size_uint32, buf);
- }
- packet_bufX = (packet_bufX + net_period_up);
- node = jack_slist_next (node);
- chn++;
- }
+ for (i = 0; i < net_period_up; i++)
+ packet_bufX[i] = buf[i] * 127.0;
+ } else if (jack_port_is_midi (porttype)) {
+ // encode midi events from port to packet
+ // convert the data buffer to a standard format (uint32_t based)
+ unsigned int buffer_size_uint32 = net_period_up / 4;
+ uint32_t * buffer_uint32 = (uint32_t*)packet_bufX;
+ encode_midi_buffer (buffer_uint32, buffer_size_uint32, buf);
+ }
+ packet_bufX = (packet_bufX + net_period_up);
+ node = jack_slist_next (node);
+ chn++;
+ }
}
#if HAVE_CELT
@@ -1351,97 +1302,93 @@ render_jack_ports_to_payload_8bit (JSList *playback_ports, JSList *playback_srcs
void
render_payload_to_jack_ports_celt (void *packet_payload, jack_nframes_t net_period_down, JSList *capture_ports, JSList *capture_srcs, jack_nframes_t nframes)
{
- int chn = 0;
- JSList *node = capture_ports;
- JSList *src_node = capture_srcs;
+ int chn = 0;
+ JSList *node = capture_ports;
+ JSList *src_node = capture_srcs;
- unsigned char *packet_bufX = (unsigned char *)packet_payload;
+ unsigned char *packet_bufX = (unsigned char*)packet_payload;
- while (node != NULL)
- {
- jack_port_t *port = (jack_port_t *) node->data;
- jack_default_audio_sample_t* buf = jack_port_get_buffer (port, nframes);
+ while (node != NULL) {
+ jack_port_t *port = (jack_port_t*)node->data;
+ jack_default_audio_sample_t* buf = jack_port_get_buffer (port, nframes);
- const char *porttype = jack_port_type (port);
+ const char *porttype = jack_port_type (port);
- if (jack_port_is_audio (porttype))
- {
- // audio port, decode celt data.
+ if (jack_port_is_audio (porttype)) {
+ // audio port, decode celt data.
- CELTDecoder *decoder = src_node->data;
+ CELTDecoder *decoder = src_node->data;
#if HAVE_CELT_API_0_8
- if( !packet_payload )
- celt_decode_float( decoder, NULL, net_period_down, buf, nframes );
- else
- celt_decode_float( decoder, packet_bufX, net_period_down, buf, nframes );
+ if ( !packet_payload ) {
+ celt_decode_float ( decoder, NULL, net_period_down, buf, nframes );
+ } else {
+ celt_decode_float ( decoder, packet_bufX, net_period_down, buf, nframes );
+ }
#else
- if( !packet_payload )
- celt_decode_float( decoder, NULL, net_period_down, buf );
- else
- celt_decode_float( decoder, packet_bufX, net_period_down, buf );
+ if ( !packet_payload ) {
+ celt_decode_float ( decoder, NULL, net_period_down, buf );
+ } else {
+ celt_decode_float ( decoder, packet_bufX, net_period_down, buf );
+ }
#endif
- src_node = jack_slist_next (src_node);
- }
- else if (jack_port_is_midi (porttype))
- {
- // midi port, decode midi events
- // convert the data buffer to a standard format (uint32_t based)
- unsigned int buffer_size_uint32 = net_period_down / 2;
- uint32_t * buffer_uint32 = (uint32_t*) packet_bufX;
- if( packet_payload )
- decode_midi_buffer (buffer_uint32, buffer_size_uint32, buf);
- }
- packet_bufX = (packet_bufX + net_period_down);
- node = jack_slist_next (node);
- chn++;
- }
+ src_node = jack_slist_next (src_node);
+ } else if (jack_port_is_midi (porttype)) {
+ // midi port, decode midi events
+ // convert the data buffer to a standard format (uint32_t based)
+ unsigned int buffer_size_uint32 = net_period_down / 2;
+ uint32_t * buffer_uint32 = (uint32_t*)packet_bufX;
+ if ( packet_payload ) {
+ decode_midi_buffer (buffer_uint32, buffer_size_uint32, buf);
+ }
+ }
+ packet_bufX = (packet_bufX + net_period_down);
+ node = jack_slist_next (node);
+ chn++;
+ }
}
void
render_jack_ports_to_payload_celt (JSList *playback_ports, JSList *playback_srcs, jack_nframes_t nframes, void *packet_payload, jack_nframes_t net_period_up)
{
- int chn = 0;
- JSList *node = playback_ports;
- JSList *src_node = playback_srcs;
-
- unsigned char *packet_bufX = (unsigned char *)packet_payload;
-
- while (node != NULL)
- {
- jack_port_t *port = (jack_port_t *) node->data;
- jack_default_audio_sample_t* buf = jack_port_get_buffer (port, nframes);
- const char *porttype = jack_port_type (port);
-
- if (jack_port_is_audio (porttype))
- {
- // audio port, encode celt data.
-
- int encoded_bytes;
- float *floatbuf = alloca (sizeof(float) * nframes );
- memcpy( floatbuf, buf, nframes*sizeof(float) );
- CELTEncoder *encoder = src_node->data;
+ int chn = 0;
+ JSList *node = playback_ports;
+ JSList *src_node = playback_srcs;
+
+ unsigned char *packet_bufX = (unsigned char*)packet_payload;
+
+ while (node != NULL) {
+ jack_port_t *port = (jack_port_t*)node->data;
+ jack_default_audio_sample_t* buf = jack_port_get_buffer (port, nframes);
+ const char *porttype = jack_port_type (port);
+
+ if (jack_port_is_audio (porttype)) {
+ // audio port, encode celt data.
+
+ int encoded_bytes;
+ float *floatbuf = alloca (sizeof(float) * nframes );
+ memcpy ( floatbuf, buf, nframes * sizeof(float) );
+ CELTEncoder *encoder = src_node->data;
#if HAVE_CELT_API_0_8
- encoded_bytes = celt_encode_float( encoder, floatbuf, nframes, packet_bufX, net_period_up );
+ encoded_bytes = celt_encode_float ( encoder, floatbuf, nframes, packet_bufX, net_period_up );
#else
- encoded_bytes = celt_encode_float( encoder, floatbuf, NULL, packet_bufX, net_period_up );
+ encoded_bytes = celt_encode_float ( encoder, floatbuf, NULL, packet_bufX, net_period_up );
#endif
- if( encoded_bytes != net_period_up )
- printf( "something in celt changed. netjack needs to be changed to handle this.\n" );
- src_node = jack_slist_next( src_node );
- }
- else if (jack_port_is_midi (porttype))
- {
- // encode midi events from port to packet
- // convert the data buffer to a standard format (uint32_t based)
- unsigned int buffer_size_uint32 = net_period_up / 2;
- uint32_t * buffer_uint32 = (uint32_t*) packet_bufX;
- encode_midi_buffer (buffer_uint32, buffer_size_uint32, buf);
- }
- packet_bufX = (packet_bufX + net_period_up);
- node = jack_slist_next (node);
- chn++;
- }
+ if ( encoded_bytes != net_period_up ) {
+ printf ( "something in celt changed. netjack needs to be changed to handle this.\n" );
+ }
+ src_node = jack_slist_next ( src_node );
+ } else if (jack_port_is_midi (porttype)) {
+ // encode midi events from port to packet
+ // convert the data buffer to a standard format (uint32_t based)
+ unsigned int buffer_size_uint32 = net_period_up / 2;
+ uint32_t * buffer_uint32 = (uint32_t*)packet_bufX;
+ encode_midi_buffer (buffer_uint32, buffer_size_uint32, buf);
+ }
+ packet_bufX = (packet_bufX + net_period_up);
+ node = jack_slist_next (node);
+ chn++;
+ }
}
#endif
@@ -1449,29 +1396,35 @@ render_jack_ports_to_payload_celt (JSList *playback_ports, JSList *playback_srcs
void
render_payload_to_jack_ports (int bitdepth, void *packet_payload, jack_nframes_t net_period_down, JSList *capture_ports, JSList *capture_srcs, jack_nframes_t nframes, int dont_htonl_floats)
{
- if (bitdepth == 8)
- render_payload_to_jack_ports_8bit (packet_payload, net_period_down, capture_ports, capture_srcs, nframes);
- else if (bitdepth == 16)
- render_payload_to_jack_ports_16bit (packet_payload, net_period_down, capture_ports, capture_srcs, nframes);
+ if (bitdepth == 8) {
+ render_payload_to_jack_ports_8bit (packet_payload, net_period_down, capture_ports, capture_srcs, nframes);
+ } else if (bitdepth == 16) {
+ render_payload_to_jack_ports_16bit (packet_payload, net_period_down, capture_ports, capture_srcs, nframes);
+ }
#if HAVE_CELT
- else if (bitdepth == CELT_MODE)
- render_payload_to_jack_ports_celt (packet_payload, net_period_down, capture_ports, capture_srcs, nframes);
+ else if (bitdepth == CELT_MODE) {
+ render_payload_to_jack_ports_celt (packet_payload, net_period_down, capture_ports, capture_srcs, nframes);
+ }
#endif
- else
- render_payload_to_jack_ports_float (packet_payload, net_period_down, capture_ports, capture_srcs, nframes, dont_htonl_floats);
+ else {
+ render_payload_to_jack_ports_float (packet_payload, net_period_down, capture_ports, capture_srcs, nframes, dont_htonl_floats);
+ }
}
void
render_jack_ports_to_payload (int bitdepth, JSList *playback_ports, JSList *playback_srcs, jack_nframes_t nframes, void *packet_payload, jack_nframes_t net_period_up, int dont_htonl_floats)
{
- if (bitdepth == 8)
- render_jack_ports_to_payload_8bit (playback_ports, playback_srcs, nframes, packet_payload, net_period_up);
- else if (bitdepth == 16)
- render_jack_ports_to_payload_16bit (playback_ports, playback_srcs, nframes, packet_payload, net_period_up);
+ if (bitdepth == 8) {
+ render_jack_ports_to_payload_8bit (playback_ports, playback_srcs, nframes, packet_payload, net_period_up);
+ } else if (bitdepth == 16) {
+ render_jack_ports_to_payload_16bit (playback_ports, playback_srcs, nframes, packet_payload, net_period_up);
+ }
#if HAVE_CELT
- else if (bitdepth == CELT_MODE)
- render_jack_ports_to_payload_celt (playback_ports, playback_srcs, nframes, packet_payload, net_period_up);
+ else if (bitdepth == CELT_MODE) {
+ render_jack_ports_to_payload_celt (playback_ports, playback_srcs, nframes, packet_payload, net_period_up);
+ }
#endif
- else
- render_jack_ports_to_payload_float (playback_ports, playback_srcs, nframes, packet_payload, net_period_up, dont_htonl_floats);
+ else {
+ render_jack_ports_to_payload_float (playback_ports, playback_srcs, nframes, packet_payload, net_period_up, dont_htonl_floats);
+ }
}
diff --git a/drivers/netjack/netjack_packet.h b/drivers/netjack/netjack_packet.h
index 97ac97d..2c0750f 100644
--- a/drivers/netjack/netjack_packet.h
+++ b/drivers/netjack/netjack_packet.h
@@ -28,8 +28,8 @@
#define __JACK_NET_PACKET_H__
#ifdef __cplusplus
- extern "C"
- {
+extern "C"
+{
#endif
#include <jack/jack.h>
@@ -46,81 +46,77 @@
typedef struct _jacknet_packet_header jacknet_packet_header;
-struct _jacknet_packet_header
-{
- // General AutoConf Data
- jack_nframes_t capture_channels_audio;
- jack_nframes_t playback_channels_audio;
- jack_nframes_t capture_channels_midi;
- jack_nframes_t playback_channels_midi;
- jack_nframes_t period_size;
- jack_nframes_t sample_rate;
-
- // Transport Sync
- jack_nframes_t sync_state;
- jack_nframes_t transport_frame;
- jack_nframes_t transport_state;
-
- // Packet loss Detection, and latency reduction
- jack_nframes_t framecnt;
- jack_nframes_t latency;
-
- jack_nframes_t reply_port;
- jack_nframes_t mtu;
- jack_nframes_t fragment_nr;
+struct _jacknet_packet_header {
+ // General AutoConf Data
+ jack_nframes_t capture_channels_audio;
+ jack_nframes_t playback_channels_audio;
+ jack_nframes_t capture_channels_midi;
+ jack_nframes_t playback_channels_midi;
+ jack_nframes_t period_size;
+ jack_nframes_t sample_rate;
+
+ // Transport Sync
+ jack_nframes_t sync_state;
+ jack_nframes_t transport_frame;
+ jack_nframes_t transport_state;
+
+ // Packet loss Detection, and latency reduction
+ jack_nframes_t framecnt;
+ jack_nframes_t latency;
+
+ jack_nframes_t reply_port;
+ jack_nframes_t mtu;
+ jack_nframes_t fragment_nr;
};
typedef union _int_float int_float_t;
-union _int_float
-{
- uint32_t i;
- float f;
+union _int_float {
+ uint32_t i;
+ float f;
};
// fragment reorder cache.
typedef struct _cache_packet cache_packet;
-struct _cache_packet
-{
- int valid;
- int num_fragments;
- int packet_size;
- int mtu;
- jack_time_t recv_timestamp;
- jack_nframes_t framecnt;
- char * fragment_array;
- char * packet_buf;
+struct _cache_packet {
+ int valid;
+ int num_fragments;
+ int packet_size;
+ int mtu;
+ jack_time_t recv_timestamp;
+ jack_nframes_t framecnt;
+ char * fragment_array;
+ char * packet_buf;
};
typedef struct _packet_cache packet_cache;
-struct _packet_cache
-{
- int size;
- cache_packet *packets;
- int mtu;
- struct sockaddr_in master_address;
- int master_address_valid;
- jack_nframes_t last_framecnt_retreived;
- int last_framecnt_retreived_valid;
+struct _packet_cache {
+ int size;
+ cache_packet *packets;
+ int mtu;
+ struct sockaddr_in master_address;
+ int master_address_valid;
+ jack_nframes_t last_framecnt_retreived;
+ int last_framecnt_retreived_valid;
};
// fragment cache function prototypes
// XXX: Some of these are private.
packet_cache *packet_cache_new(int num_packets, int pkt_size, int mtu);
-void packet_cache_free(packet_cache *pkt_cache);
+void packet_cache_free(packet_cache *pkt_cache);
cache_packet *packet_cache_get_packet(packet_cache *pkt_cache, jack_nframes_t framecnt);
cache_packet *packet_cache_get_oldest_packet(packet_cache *pkt_cache);
cache_packet *packet_cache_get_free_packet(packet_cache *pkt_cache);
-void cache_packet_reset(cache_packet *pack);
-void cache_packet_set_framecnt(cache_packet *pack, jack_nframes_t framecnt);
-void cache_packet_add_fragment(cache_packet *pack, char *packet_buf, int rcv_len);
-int cache_packet_is_complete(cache_packet *pack);
+void cache_packet_reset(cache_packet *pack);
+void cache_packet_set_framecnt(cache_packet *pack, jack_nframes_t framecnt);
+void cache_packet_add_fragment(cache_packet *pack, char *packet_buf, int rcv_len);
+int cache_packet_is_complete(cache_packet *pack);
-void packet_cache_drain_socket( packet_cache *pcache, int sockfd, jack_time_t (*get_microseconds)(void) );
+void packet_cache_drain_socket ( packet_cache * pcache, int sockfd, jack_time_t (*get_microseconds)(void) );
void packet_cache_reset_master_address( packet_cache *pcache );
float packet_cache_get_fill( packet_cache *pcache, jack_nframes_t expected_framecnt );
int packet_cache_retreive_packet_pointer( packet_cache *pcache, jack_nframes_t framecnt, char **packet_buf, int pkt_size, jack_time_t *timestamp );
@@ -149,10 +145,10 @@ void render_jack_ports_to_payload(int bitdepth, JSList *playback_ports, JSList *
// This one waits forever. an is not using ppoll
int netjack_poll(int sockfd, int timeout);
-void decode_midi_buffer (uint32_t *buffer_uint32, unsigned int buffer_size_uint32, jack_default_audio_sample_t* buf);
-void encode_midi_buffer (uint32_t *buffer_uint32, unsigned int buffer_size_uint32, jack_default_audio_sample_t* buf);
+void decode_midi_buffer(uint32_t *buffer_uint32, unsigned int buffer_size_uint32, jack_default_audio_sample_t* buf);
+void encode_midi_buffer(uint32_t *buffer_uint32, unsigned int buffer_size_uint32, jack_default_audio_sample_t* buf);
#ifdef __cplusplus
- }
+}
#endif
#endif
diff --git a/drivers/oss/oss_driver.c b/drivers/oss/oss_driver.c
index 2289e49..f53a2dd 100644
--- a/drivers/oss/oss_driver.c
+++ b/drivers/oss/oss_driver.c
@@ -1,24 +1,24 @@
/*
- OSS driver for Jack
- Copyright (C) 2003-2007 Jussi Laako <jussi@sonarnerd.net>
+ OSS driver for Jack
+ Copyright (C) 2003-2007 Jussi Laako <jussi@sonarnerd.net>
- 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 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.
+ 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., 59 Temple Place, Suite 330, Boston,
- MA 02111-1307 USA
+ 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., 59 Temple Place, Suite 330, Boston,
+ MA 02111-1307 USA
-*/
+ */
#include <config.h>
@@ -31,7 +31,7 @@
* defined as optional by the standard, so OS conformance to this level
* doesn't necessarily mean everything exists.
*/
-#define _XOPEN_SOURCE 600
+#define _XOPEN_SOURCE 600
#endif
#ifndef _REENTRANT
#define _REENTRANT
@@ -70,103 +70,92 @@
#ifndef SNDCTL_DSP_COOKEDMODE
#ifdef _SIOWR
-#define SNDCTL_DSP_COOKEDMODE _SIOWR('P', 30, int)
+#define SNDCTL_DSP_COOKEDMODE _SIOWR ('P', 30, int)
#else /* _SIOWR */
#warning "Unable to define cooked mode!"
#define OSS_NO_COOKED_MODE
#endif /* _SIOWR */
#endif /* SNDCTL_DSP_COOKEDMODE */
-#define OSS_DRIVER_N_PARAMS 11
+#define OSS_DRIVER_N_PARAMS 11
const static jack_driver_param_desc_t oss_params[OSS_DRIVER_N_PARAMS] = {
{ "rate",
- 'r',
- JackDriverParamUInt,
- { .ui = OSS_DRIVER_DEF_FS },
- NULL,
- "sample rate",
- "sample rate"
- },
+ 'r',
+ JackDriverParamUInt,
+ { .ui = OSS_DRIVER_DEF_FS },
+ NULL,
+ "sample rate",
+ "sample rate" },
{ "period",
- 'p',
- JackDriverParamUInt,
- { .ui = OSS_DRIVER_DEF_BLKSIZE },
- NULL,
- "period size",
- "period size"
- },
+ 'p',
+ JackDriverParamUInt,
+ { .ui = OSS_DRIVER_DEF_BLKSIZE },
+ NULL,
+ "period size",
+ "period size" },
{ "nperiods",
- 'n',
- JackDriverParamUInt,
- { .ui = OSS_DRIVER_DEF_NPERIODS },
- NULL,
- "number of periods in buffer",
- "number of periods in buffer"
- },
+ 'n',
+ JackDriverParamUInt,
+ { .ui = OSS_DRIVER_DEF_NPERIODS },
+ NULL,
+ "number of periods in buffer",
+ "number of periods in buffer" },
{ "wordlength",
- 'w',
- JackDriverParamInt,
- { .i = OSS_DRIVER_DEF_BITS },
- NULL,
- "word length",
- "word length"
- },
+ 'w',
+ JackDriverParamInt,
+ { .i = OSS_DRIVER_DEF_BITS },
+ NULL,
+ "word length",
+ "word length" },
{ "inchannels",
- 'i',
- JackDriverParamUInt,
- { .ui = OSS_DRIVER_DEF_INS },
- NULL,
- "capture channels",
- "capture channels"
- },
+ 'i',
+ JackDriverParamUInt,
+ { .ui = OSS_DRIVER_DEF_INS },
+ NULL,
+ "capture channels",
+ "capture channels" },
{ "outchannels",
- 'o',
- JackDriverParamUInt,
- { .ui = OSS_DRIVER_DEF_OUTS },
- NULL,
- "playback channels",
- "playback channels"
- },
+ 'o',
+ JackDriverParamUInt,
+ { .ui = OSS_DRIVER_DEF_OUTS },
+ NULL,
+ "playback channels",
+ "playback channels" },
{ "capture",
- 'C',
- JackDriverParamString,
- { .str = OSS_DRIVER_DEF_DEV },
- NULL,
- "input device",
- "input device"
- },
+ 'C',
+ JackDriverParamString,
+ { .str = OSS_DRIVER_DEF_DEV },
+ NULL,
+ "input device",
+ "input device" },
{ "playback",
- 'P',
- JackDriverParamString,
- { .str = OSS_DRIVER_DEF_DEV },
- NULL,
- "output device",
- "output device"
- },
+ 'P',
+ JackDriverParamString,
+ { .str = OSS_DRIVER_DEF_DEV },
+ NULL,
+ "output device",
+ "output device" },
{ "ignorehwbuf",
- 'b',
- JackDriverParamBool,
- { },
- NULL,
- "ignore hardware period size",
- "ignore hardware period size"
- },
+ 'b',
+ JackDriverParamBool,
+ { },
+ NULL,
+ "ignore hardware period size",
+ "ignore hardware period size" },
{ "input latency",
- 'I',
- JackDriverParamUInt,
- { .ui = 0 },
- NULL,
- "system input latency",
- "system input latency"
- },
+ 'I',
+ JackDriverParamUInt,
+ { .ui = 0 },
+ NULL,
+ "system input latency",
+ "system input latency" },
{ "output latency",
- 'O',
- JackDriverParamUInt,
- { .ui = 0 },
- NULL,
- "system output latency",
- "system output latency"
- }
+ 'O',
+ JackDriverParamUInt,
+ { .ui = 0 },
+ NULL,
+ "system output latency",
+ "system output latency" }
};
@@ -174,16 +163,16 @@ const static jack_driver_param_desc_t oss_params[OSS_DRIVER_N_PARAMS] = {
/* internal functions */
-static void set_period_size (oss_driver_t *driver,
- jack_nframes_t new_period_size)
+static void set_period_size (oss_driver_t *driver,
+ jack_nframes_t new_period_size)
{
driver->period_size = new_period_size;
- driver->period_usecs =
- ((double) driver->period_size /
- (double) driver->sample_rate) * 1e6;
+ driver->period_usecs =
+ ((double)driver->period_size /
+ (double)driver->sample_rate) * 1e6;
driver->last_wait_ust = 0;
- driver->last_periodtime = driver->engine->get_microseconds();
+ driver->last_periodtime = driver->engine->get_microseconds ();
driver->next_periodtime = 0;
driver->iodelay = 0.0F;
}
@@ -191,15 +180,13 @@ static void set_period_size (oss_driver_t *driver,
static inline void update_times (oss_driver_t *driver)
{
- driver->last_periodtime = driver->engine->get_microseconds();
- if (driver->next_periodtime > 0)
- {
+ driver->last_periodtime = driver->engine->get_microseconds ();
+ if (driver->next_periodtime > 0) {
driver->iodelay = (float)
- ((long double) driver->last_periodtime -
- (long double) driver->next_periodtime);
- }
- else driver->iodelay = 0.0F;
- driver->next_periodtime =
+ ((long double)driver->last_periodtime -
+ (long double)driver->next_periodtime);
+ } else { driver->iodelay = 0.0F; }
+ driver->next_periodtime =
driver->last_periodtime +
driver->period_usecs;
}
@@ -207,120 +194,110 @@ static inline void update_times (oss_driver_t *driver)
static inline void driver_cycle (oss_driver_t *driver)
{
- update_times(driver);
- driver->engine->transport_cycle_start(driver->engine,
- driver->last_periodtime);
+ update_times (driver);
+ driver->engine->transport_cycle_start (driver->engine,
+ driver->last_periodtime);
driver->last_wait_ust = driver->last_periodtime;
- driver->engine->run_cycle(driver->engine,
- driver->period_size, driver->iodelay);
+ driver->engine->run_cycle (driver->engine,
+ driver->period_size, driver->iodelay);
}
-static void copy_and_convert_in (jack_sample_t *dst, void *src,
- size_t nframes, int channel, int chcount, int bits)
+static void copy_and_convert_in (jack_sample_t *dst, void *src,
+ size_t nframes, int channel, int chcount, int bits)
{
int srcidx;
int dstidx;
- signed short *s16src = (signed short *) src;
- signed int *s32src = (signed int *) src;
- double *f64src = (double *) src;
+ signed short *s16src = (signed short*)src;
+ signed int *s32src = (signed int*)src;
+ double *f64src = (double*)src;
jack_sample_t scale;
srcidx = channel;
- switch (bits)
- {
- case 16:
- scale = 1.0f / 0x7fff;
- for (dstidx = 0; dstidx < nframes; dstidx++)
- {
- dst[dstidx] = (jack_sample_t)
- s16src[srcidx] * scale;
- srcidx += chcount;
- }
- break;
- case 24:
- scale = 1.0f / 0x7fffff;
- for (dstidx = 0; dstidx < nframes; dstidx++)
- {
- dst[dstidx] = (jack_sample_t)
- s32src[srcidx] * scale;
- srcidx += chcount;
- }
- break;
- case 32:
- scale = 1.0f / 0x7fffffff;
- for (dstidx = 0; dstidx < nframes; dstidx++)
- {
- dst[dstidx] = (jack_sample_t)
- s32src[srcidx] * scale;
- srcidx += chcount;
- }
- break;
- case 64:
- for (dstidx = 0; dstidx < nframes; dstidx++)
- {
- dst[dstidx] = (jack_sample_t) f64src[srcidx];
- srcidx += chcount;
- }
- break;
+ switch (bits) {
+ case 16:
+ scale = 1.0f / 0x7fff;
+ for (dstidx = 0; dstidx < nframes; dstidx++) {
+ dst[dstidx] = (jack_sample_t)
+ s16src[srcidx] * scale;
+ srcidx += chcount;
+ }
+ break;
+ case 24:
+ scale = 1.0f / 0x7fffff;
+ for (dstidx = 0; dstidx < nframes; dstidx++) {
+ dst[dstidx] = (jack_sample_t)
+ s32src[srcidx] * scale;
+ srcidx += chcount;
+ }
+ break;
+ case 32:
+ scale = 1.0f / 0x7fffffff;
+ for (dstidx = 0; dstidx < nframes; dstidx++) {
+ dst[dstidx] = (jack_sample_t)
+ s32src[srcidx] * scale;
+ srcidx += chcount;
+ }
+ break;
+ case 64:
+ for (dstidx = 0; dstidx < nframes; dstidx++) {
+ dst[dstidx] = (jack_sample_t)f64src[srcidx];
+ srcidx += chcount;
+ }
+ break;
}
}
-static void copy_and_convert_out (void *dst, jack_sample_t *src,
- size_t nframes, int channel, int chcount, int bits)
+static void copy_and_convert_out (void *dst, jack_sample_t *src,
+ size_t nframes, int channel, int chcount, int bits)
{
int srcidx;
int dstidx;
- signed short *s16dst = (signed short *) dst;
- signed int *s32dst = (signed int *) dst;
- double *f64dst = (double *) dst;
+ signed short *s16dst = (signed short*)dst;
+ signed int *s32dst = (signed int*)dst;
+ double *f64dst = (double*)dst;
jack_sample_t scale;
dstidx = channel;
- switch (bits)
- {
- case 16:
- scale = 0x7fff;
- for (srcidx = 0; srcidx < nframes; srcidx++)
- {
- s16dst[dstidx] = (signed short)
- (src[srcidx] >= 0.0f) ?
- (src[srcidx] * scale + 0.5f) :
- (src[srcidx] * scale - 0.5f);
- dstidx += chcount;
- }
- break;
- case 24:
- scale = 0x7fffff;
- for (srcidx = 0; srcidx < nframes; srcidx++)
- {
- s32dst[dstidx] = (signed int)
- (src[srcidx] >= 0.0f) ?
- (src[srcidx] * scale + 0.5f) :
- (src[srcidx] * scale - 0.5f);
- dstidx += chcount;
- }
- break;
- case 32:
- scale = 0x7fffffff;
- for (srcidx = 0; srcidx < nframes; srcidx++)
- {
- s32dst[dstidx] = (signed int)
- (src[srcidx] >= 0.0f) ?
- (src[srcidx] * scale + 0.5f) :
- (src[srcidx] * scale - 0.5f);
- dstidx += chcount;
- }
- break;
- case 64:
- for (srcidx = 0; srcidx < nframes; srcidx++)
- {
- f64dst[dstidx] = (double) src[srcidx];
- dstidx += chcount;
- }
- break;
+ switch (bits) {
+ case 16:
+ scale = 0x7fff;
+ for (srcidx = 0; srcidx < nframes; srcidx++) {
+ s16dst[dstidx] = (signed short)
+ (src[srcidx] >= 0.0f) ?
+ (src[srcidx] * scale + 0.5f) :
+ (src[srcidx] * scale - 0.5f);
+ dstidx += chcount;
+ }
+ break;
+ case 24:
+ scale = 0x7fffff;
+ for (srcidx = 0; srcidx < nframes; srcidx++) {
+ s32dst[dstidx] = (signed int)
+ (src[srcidx] >= 0.0f) ?
+ (src[srcidx] * scale + 0.5f) :
+ (src[srcidx] * scale - 0.5f);
+ dstidx += chcount;
+ }
+ break;
+ case 32:
+ scale = 0x7fffffff;
+ for (srcidx = 0; srcidx < nframes; srcidx++) {
+ s32dst[dstidx] = (signed int)
+ (src[srcidx] >= 0.0f) ?
+ (src[srcidx] * scale + 0.5f) :
+ (src[srcidx] * scale - 0.5f);
+ dstidx += chcount;
+ }
+ break;
+ case 64:
+ for (srcidx = 0; srcidx < nframes; srcidx++) {
+ f64dst[dstidx] = (double)src[srcidx];
+ dstidx += chcount;
+ }
+ break;
}
}
@@ -330,12 +307,11 @@ static void set_fragment (int fd, size_t fragsize, unsigned int fragcount)
int fragsize_2p;
int fragments;
- fragsize_2p = (int) (log(fragsize) / log(2.0) + 0.5);
+ fragsize_2p = (int)(log (fragsize) / log (2.0) + 0.5);
fragments = ((fragcount << 16) | (fragsize_2p & 0xffff));
- if (ioctl(fd, SNDCTL_DSP_SETFRAGMENT, &fragments) < 0)
- {
- jack_error("OSS: failed to set fragment size: %s@%i, errno=%d",
- __FILE__, __LINE__, errno);
+ if (ioctl (fd, SNDCTL_DSP_SETFRAGMENT, &fragments) < 0) {
+ jack_error ("OSS: failed to set fragment size: %s@%i, errno=%d",
+ __FILE__, __LINE__, errno);
}
}
@@ -344,17 +320,16 @@ static int get_fragment (int fd)
{
int fragsize;
- if (ioctl(fd, SNDCTL_DSP_GETBLKSIZE, &fragsize) < 0)
- {
- jack_error("OSS: failed to get fragment size: %s@%i, errno=%d",
- __FILE__, __LINE__, errno);
+ if (ioctl (fd, SNDCTL_DSP_GETBLKSIZE, &fragsize) < 0) {
+ jack_error ("OSS: failed to get fragment size: %s@%i, errno=%d",
+ __FILE__, __LINE__, errno);
return 0;
}
return fragsize;
}
-static void *io_thread (void *);
+static void *io_thread(void *);
/* jack driver interface */
@@ -369,54 +344,50 @@ static int oss_driver_attach (oss_driver_t *driver, jack_engine_t *engine)
jack_latency_range_t range;
driver->engine = engine;
- set_period_size(driver, driver->period_size);
+ set_period_size (driver, driver->period_size);
- if (engine->set_buffer_size(engine, driver->period_size)) {
+ if (engine->set_buffer_size (engine, driver->period_size)) {
jack_error ("OSS: cannot set engine buffer size to %d (check MIDI)", driver->period_size);
return -1;
}
- engine->set_sample_rate(engine, driver->sample_rate);
-
- port_flags = JackPortIsOutput|JackPortIsPhysical|JackPortIsTerminal;
- for (channel = 0; channel < driver->capture_channels; channel++)
- {
- snprintf(channel_name, sizeof(channel_name),
- "capture_%u", channel + 1);
- port = jack_port_register(driver->client, channel_name,
- JACK_DEFAULT_AUDIO_TYPE, port_flags, 0);
- if (port == NULL)
- {
- jack_error("OSS: cannot register port for %s: %s@%i",
- channel_name, __FILE__, __LINE__);
+ engine->set_sample_rate (engine, driver->sample_rate);
+
+ port_flags = JackPortIsOutput | JackPortIsPhysical | JackPortIsTerminal;
+ for (channel = 0; channel < driver->capture_channels; channel++) {
+ snprintf (channel_name, sizeof(channel_name),
+ "capture_%u", channel + 1);
+ port = jack_port_register (driver->client, channel_name,
+ JACK_DEFAULT_AUDIO_TYPE, port_flags, 0);
+ if (port == NULL) {
+ jack_error ("OSS: cannot register port for %s: %s@%i",
+ channel_name, __FILE__, __LINE__);
break;
}
range.min = range.max = driver->period_size + driver->sys_in_latency;
- jack_port_set_latency_range(port, JackCaptureLatency, &range);
- driver->capture_ports =
- jack_slist_append(driver->capture_ports, port);
+ jack_port_set_latency_range (port, JackCaptureLatency, &range);
+ driver->capture_ports =
+ jack_slist_append (driver->capture_ports, port);
}
- port_flags = JackPortIsInput|JackPortIsPhysical|JackPortIsTerminal;
- for (channel = 0; channel < driver->playback_channels; channel++)
- {
- snprintf(channel_name, sizeof(channel_name),
- "playback_%u", channel + 1);
- port = jack_port_register(driver->client, channel_name,
- JACK_DEFAULT_AUDIO_TYPE, port_flags, 0);
- if (port == NULL)
- {
- jack_error("OSS: cannot register port for %s: %s@%i",
- channel_name, __FILE__, __LINE__);
+ port_flags = JackPortIsInput | JackPortIsPhysical | JackPortIsTerminal;
+ for (channel = 0; channel < driver->playback_channels; channel++) {
+ snprintf (channel_name, sizeof(channel_name),
+ "playback_%u", channel + 1);
+ port = jack_port_register (driver->client, channel_name,
+ JACK_DEFAULT_AUDIO_TYPE, port_flags, 0);
+ if (port == NULL) {
+ jack_error ("OSS: cannot register port for %s: %s@%i",
+ channel_name, __FILE__, __LINE__);
break;
}
range.min = range.max = driver->period_size + driver->sys_out_latency;
- jack_port_set_latency_range(port, JackPlaybackLatency, &range);
+ jack_port_set_latency_range (port, JackPlaybackLatency, &range);
driver->playback_ports =
- jack_slist_append(driver->playback_ports, port);
+ jack_slist_append (driver->playback_ports, port);
}
- jack_activate(driver->client);
+ jack_activate (driver->client);
return 0;
}
@@ -426,29 +397,28 @@ static int oss_driver_detach (oss_driver_t *driver, jack_engine_t *engine)
{
JSList *node;
- if (driver->engine == NULL)
+ if (driver->engine == NULL) {
return -1;
+ }
/*jack_deactivate(driver->client);*/ /* ? */
node = driver->capture_ports;
- while (node != NULL)
- {
- jack_port_unregister(driver->client,
- ((jack_port_t *) node->data));
- node = jack_slist_next(node);
+ while (node != NULL) {
+ jack_port_unregister (driver->client,
+ ((jack_port_t*)node->data));
+ node = jack_slist_next (node);
}
- jack_slist_free(driver->capture_ports);
+ jack_slist_free (driver->capture_ports);
driver->capture_ports = NULL;
node = driver->playback_ports;
- while (node != NULL)
- {
- jack_port_unregister(driver->client,
- ((jack_port_t *) node->data));
- node = jack_slist_next(node);
+ while (node != NULL) {
+ jack_port_unregister (driver->client,
+ ((jack_port_t*)node->data));
+ node = jack_slist_next (node);
}
- jack_slist_free(driver->playback_ports);
+ jack_slist_free (driver->playback_ports);
driver->playback_ports = NULL;
driver->engine = NULL;
@@ -471,298 +441,271 @@ static int oss_driver_start (oss_driver_t *driver)
const char *indev = driver->indev;
const char *outdev = driver->outdev;
- switch (driver->bits)
- {
- case 24:
- case 32:
- samplesize = sizeof(int);
- break;
- case 64:
- samplesize = sizeof(double);
- break;
- case 16:
- default:
- samplesize = sizeof(short);
- break;
+ switch (driver->bits) {
+ case 24:
+ case 32:
+ samplesize = sizeof(int);
+ break;
+ case 64:
+ samplesize = sizeof(double);
+ break;
+ case 16:
+ default:
+ samplesize = sizeof(short);
+ break;
}
driver->trigger = 0;
- if (strcmp(indev, outdev) != 0)
- {
- if (driver->capture_channels > 0)
- {
- infd = open(indev, O_RDONLY|O_EXCL);
- if (infd < 0)
- {
- jack_error(
+ if (strcmp (indev, outdev) != 0) {
+ if (driver->capture_channels > 0) {
+ infd = open (indev, O_RDONLY | O_EXCL);
+ if (infd < 0) {
+ jack_error (
"OSS: failed to open input device %s: %s@%i, errno=%d",
indev, __FILE__, __LINE__, errno);
}
#ifndef OSS_NO_COOKED_MODE
- ioctl(infd, SNDCTL_DSP_COOKEDMODE, &flags);
+ ioctl (infd, SNDCTL_DSP_COOKEDMODE, &flags);
#endif
- fragsize = driver->period_size *
- driver->capture_channels * samplesize;
- set_fragment(infd, fragsize, driver->nperiods);
- }
- else infd = -1;
-
- if (driver->playback_channels > 0)
- {
- outfd = open(outdev, O_WRONLY|O_EXCL);
- if (outfd < 0)
- {
- jack_error(
+ fragsize = driver->period_size *
+ driver->capture_channels * samplesize;
+ set_fragment (infd, fragsize, driver->nperiods);
+ } else { infd = -1; }
+
+ if (driver->playback_channels > 0) {
+ outfd = open (outdev, O_WRONLY | O_EXCL);
+ if (outfd < 0) {
+ jack_error (
"OSS: failed to open output device %s: %s@%i, errno=%d",
outdev, __FILE__, __LINE__, errno);
}
#ifndef OSS_NO_COOKED_MODE
- ioctl(outfd, SNDCTL_DSP_COOKEDMODE, &flags);
+ ioctl (outfd, SNDCTL_DSP_COOKEDMODE, &flags);
#endif
- fragsize = driver->period_size *
- driver->playback_channels * samplesize;
- set_fragment(outfd, fragsize, driver->nperiods);
- }
- else outfd = -1;
- }
- else
- {
+ fragsize = driver->period_size *
+ driver->playback_channels * samplesize;
+ set_fragment (outfd, fragsize, driver->nperiods);
+ } else { outfd = -1; }
+ } else {
if (driver->capture_channels != 0 &&
- driver->playback_channels == 0)
- {
- infd = open(indev, O_RDWR|O_EXCL);
+ driver->playback_channels == 0) {
+ infd = open (indev, O_RDWR | O_EXCL);
outfd = -1;
- if (infd < 0)
- {
- jack_error(
+ if (infd < 0) {
+ jack_error (
"OSS: failed to open device %s: %s@%i, errno=%d",
indev, __FILE__, __LINE__, errno);
return -1;
}
#ifndef OSS_NO_COOKED_MODE
- ioctl(infd, SNDCTL_DSP_COOKEDMODE, &flags);
+ ioctl (infd, SNDCTL_DSP_COOKEDMODE, &flags);
#endif
- }
- else if (driver->capture_channels == 0 &&
- driver->playback_channels != 0)
- {
+ } else if (driver->capture_channels == 0 &&
+ driver->playback_channels != 0) {
infd = -1;
- outfd = open(outdev, O_RDWR|O_EXCL);
- if (outfd < 0)
- {
- jack_error(
+ outfd = open (outdev, O_RDWR | O_EXCL);
+ if (outfd < 0) {
+ jack_error (
"OSS: failed to open device %s: %s@%i, errno=%d",
outdev, __FILE__, __LINE__, errno);
return -1;
}
#ifndef OSS_NO_COOKED_MODE
- ioctl(outfd, SNDCTL_DSP_COOKEDMODE, &flags);
+ ioctl (outfd, SNDCTL_DSP_COOKEDMODE, &flags);
#endif
- }
- else
- {
- infd = outfd = open(indev, O_RDWR|O_EXCL);
- if (infd < 0)
- {
- jack_error(
+ } else {
+ infd = outfd = open (indev, O_RDWR | O_EXCL);
+ if (infd < 0) {
+ jack_error (
"OSS: failed to open device %s: %s@%i, errno=%d",
indev, __FILE__, __LINE__, errno);
return -1;
}
#ifndef OSS_NO_COOKED_MODE
- ioctl(infd, SNDCTL_DSP_COOKEDMODE, &flags);
+ ioctl (infd, SNDCTL_DSP_COOKEDMODE, &flags);
#endif
}
- if (infd >= 0 && outfd >= 0)
- {
- ioctl(outfd, SNDCTL_DSP_SETTRIGGER, &driver->trigger);
- driver->trigger = (PCM_ENABLE_INPUT|PCM_ENABLE_OUTPUT);
- if (ioctl(infd, SNDCTL_DSP_SETDUPLEX, 0) < 0)
- {
- if (errno != EINVAL) /* Dont care */
- jack_error(
+ if (infd >= 0 && outfd >= 0) {
+ ioctl (outfd, SNDCTL_DSP_SETTRIGGER, &driver->trigger);
+ driver->trigger = (PCM_ENABLE_INPUT | PCM_ENABLE_OUTPUT);
+ if (ioctl (infd, SNDCTL_DSP_SETDUPLEX, 0) < 0) {
+ if (errno != EINVAL) { /* Dont care */
+ jack_error (
"OSS: failed to enable full duplex for %s: %s@%i, errno=%d",
indev, __FILE__, __LINE__,
errno);
+ }
}
}
- if (infd >= 0)
- {
- fragsize = driver->period_size *
- driver->capture_channels * samplesize;
- set_fragment(infd, fragsize, driver->nperiods);
+ if (infd >= 0) {
+ fragsize = driver->period_size *
+ driver->capture_channels * samplesize;
+ set_fragment (infd, fragsize, driver->nperiods);
}
- if (outfd >= 0 && infd < 0)
- {
- fragsize = driver->period_size *
- driver->playback_channels * samplesize;
- set_fragment(outfd, fragsize, driver->nperiods);
+ if (outfd >= 0 && infd < 0) {
+ fragsize = driver->period_size *
+ driver->playback_channels * samplesize;
+ set_fragment (outfd, fragsize, driver->nperiods);
}
}
driver->infd = infd;
driver->outfd = outfd;
-
- if (infd >= 0)
- {
+
+ if (infd >= 0) {
format = driver->format;
- if (ioctl(infd, SNDCTL_DSP_SETFMT, &format) < 0)
- jack_error(
- "OSS: failed to set format for %s: %s@%i, errno=%d",
+ if (ioctl (infd, SNDCTL_DSP_SETFMT, &format) < 0) {
+ jack_error (
+ "OSS: failed to set format for %s: %s@%i, errno=%d",
indev, __FILE__, __LINE__, errno);
+ }
channels = driver->capture_channels;
- if (ioctl(infd, SNDCTL_DSP_CHANNELS, &channels) < 0)
- jack_error(
- "OSS: failed to set channels for %s: %s@%i, errno=%d",
+ if (ioctl (infd, SNDCTL_DSP_CHANNELS, &channels) < 0) {
+ jack_error (
+ "OSS: failed to set channels for %s: %s@%i, errno=%d",
indev, __FILE__, __LINE__, errno);
+ }
samplerate = driver->sample_rate;
- if (ioctl(infd, SNDCTL_DSP_SPEED, &samplerate) < 0)
- jack_error(
- "OSS: failed to set samplerate for %s: %s@%i, errno=%d",
+ if (ioctl (infd, SNDCTL_DSP_SPEED, &samplerate) < 0) {
+ jack_error (
+ "OSS: failed to set samplerate for %s: %s@%i, errno=%d",
indev, __FILE__, __LINE__, errno);
- jack_info("oss_driver: %s : 0x%x/%i/%i (%i)", indev,
- format, channels, samplerate, get_fragment(infd));
-
- period_size = get_fragment(infd) / samplesize / channels;
- if (period_size != driver->period_size &&
- !driver->ignorehwbuf)
- {
- jack_info("oss_driver: period size update: %u",
- period_size);
+ }
+ jack_info ("oss_driver: %s : 0x%x/%i/%i (%i)", indev,
+ format, channels, samplerate, get_fragment (infd));
+
+ period_size = get_fragment (infd) / samplesize / channels;
+ if (period_size != driver->period_size &&
+ !driver->ignorehwbuf) {
+ jack_info ("oss_driver: period size update: %u",
+ period_size);
driver->period_size = period_size;
- driver->period_usecs =
- ((double) driver->period_size /
- (double) driver->sample_rate) * 1e6;
- if (driver->engine->set_buffer_size(driver->engine,
- driver->period_size)) {
+ driver->period_usecs =
+ ((double)driver->period_size /
+ (double)driver->sample_rate) * 1e6;
+ if (driver->engine->set_buffer_size (driver->engine,
+ driver->period_size)) {
jack_error ("OSS: cannot set engine buffer size to %d (check MIDI)", driver->period_size);
return -1;
}
}
}
- if (outfd >= 0 && infd != outfd)
- {
+ if (outfd >= 0 && infd != outfd) {
format = driver->format;
- if (ioctl(outfd, SNDCTL_DSP_SETFMT, &format) < 0)
- jack_error(
- "OSS: failed to set format for %s: %s@%i, errno=%d",
+ if (ioctl (outfd, SNDCTL_DSP_SETFMT, &format) < 0) {
+ jack_error (
+ "OSS: failed to set format for %s: %s@%i, errno=%d",
outdev, __FILE__, __LINE__, errno);
+ }
channels = driver->playback_channels;
- if (ioctl(outfd, SNDCTL_DSP_CHANNELS, &channels) < 0)
- jack_error(
- "OSS: failed to set channels for %s: %s@%i, errno=%d",
+ if (ioctl (outfd, SNDCTL_DSP_CHANNELS, &channels) < 0) {
+ jack_error (
+ "OSS: failed to set channels for %s: %s@%i, errno=%d",
outdev, __FILE__, __LINE__, errno);
+ }
samplerate = driver->sample_rate;
- if (ioctl(outfd, SNDCTL_DSP_SPEED, &samplerate) < 0)
- jack_error(
- "OSS: failed to set samplerate for %s: %s@%i, errno=%d",
+ if (ioctl (outfd, SNDCTL_DSP_SPEED, &samplerate) < 0) {
+ jack_error (
+ "OSS: failed to set samplerate for %s: %s@%i, errno=%d",
outdev, __FILE__, __LINE__, errno);
- jack_info("oss_driver: %s : 0x%x/%i/%i (%i)", outdev,
- format, channels, samplerate,
- get_fragment(outfd));
+ }
+ jack_info ("oss_driver: %s : 0x%x/%i/%i (%i)", outdev,
+ format, channels, samplerate,
+ get_fragment (outfd));
- period_size = get_fragment(outfd) / samplesize / channels;
+ period_size = get_fragment (outfd) / samplesize / channels;
if (period_size != driver->period_size &&
- !driver->ignorehwbuf)
- {
- jack_info("oss_driver: period size update: %u",
- period_size);
+ !driver->ignorehwbuf) {
+ jack_info ("oss_driver: period size update: %u",
+ period_size);
driver->period_size = period_size;
- driver->period_usecs =
- ((double) driver->period_size /
- (double) driver->sample_rate) * 1e6;
- if (driver->engine->set_buffer_size(driver->engine,
- driver->period_size)) {
+ driver->period_usecs =
+ ((double)driver->period_size /
+ (double)driver->sample_rate) * 1e6;
+ if (driver->engine->set_buffer_size (driver->engine,
+ driver->period_size)) {
jack_error ("OSS: cannot set engine buffer size to %d (check MIDI)", driver->period_size);
return -1;
}
}
}
- if (driver->capture_channels > 0)
- {
- driver->indevbufsize = driver->period_size *
- driver->capture_channels * samplesize;
- driver->indevbuf = malloc(driver->indevbufsize);
- if (driver->indevbuf == NULL)
- {
- jack_error( "OSS: malloc() failed: %s@%i",
- __FILE__, __LINE__);
+ if (driver->capture_channels > 0) {
+ driver->indevbufsize = driver->period_size *
+ driver->capture_channels * samplesize;
+ driver->indevbuf = malloc (driver->indevbufsize);
+ if (driver->indevbuf == NULL) {
+ jack_error ( "OSS: malloc() failed: %s@%i",
+ __FILE__, __LINE__);
return -1;
}
- memset(driver->indevbuf, 0x00, driver->indevbufsize);
- }
- else
- {
+ memset (driver->indevbuf, 0x00, driver->indevbufsize);
+ } else {
driver->indevbufsize = 0;
driver->indevbuf = NULL;
}
- if (driver->playback_channels > 0)
- {
- driver->outdevbufsize = driver->period_size *
- driver->playback_channels * samplesize;
- driver->outdevbuf = malloc(driver->outdevbufsize);
- if (driver->outdevbuf == NULL)
- {
- jack_error("OSS: malloc() failed: %s@%i",
- __FILE__, __LINE__);
+ if (driver->playback_channels > 0) {
+ driver->outdevbufsize = driver->period_size *
+ driver->playback_channels * samplesize;
+ driver->outdevbuf = malloc (driver->outdevbufsize);
+ if (driver->outdevbuf == NULL) {
+ jack_error ("OSS: malloc() failed: %s@%i",
+ __FILE__, __LINE__);
return -1;
}
- memset(driver->outdevbuf, 0x00, driver->outdevbufsize);
- }
- else
- {
+ memset (driver->outdevbuf, 0x00, driver->outdevbufsize);
+ } else {
driver->outdevbufsize = 0;
driver->outdevbuf = NULL;
}
- jack_info("oss_driver: indevbuf %zd B, outdevbuf %zd B",
- driver->indevbufsize, driver->outdevbufsize);
-
- pthread_mutex_init(&driver->mutex_in, NULL);
- pthread_mutex_init(&driver->mutex_out, NULL);
-# ifdef USE_BARRIER
- puts("oss_driver: using barrier mode, (dual thread)");
- pthread_barrier_init(&driver->barrier, NULL, 2);
-# else
- puts("oss_driver: not using barrier mode, (single thread)");
-# endif
- sem_init(&driver->sem_start, 0, 0);
+ jack_info ("oss_driver: indevbuf %zd B, outdevbuf %zd B",
+ driver->indevbufsize, driver->outdevbufsize);
+
+ pthread_mutex_init (&driver->mutex_in, NULL);
+ pthread_mutex_init (&driver->mutex_out, NULL);
+# ifdef USE_BARRIER
+ puts ("oss_driver: using barrier mode, (dual thread)");
+ pthread_barrier_init (&driver->barrier, NULL, 2);
+# else
+ puts ("oss_driver: not using barrier mode, (single thread)");
+# endif
+ sem_init (&driver->sem_start, 0, 0);
driver->run = 1;
driver->threads = 0;
- if (infd >= 0)
- {
- if (jack_client_create_thread(NULL, &driver->thread_in,
- driver->engine->rtpriority,
- driver->engine->control->real_time,
- io_thread, driver) < 0)
- {
- jack_error("OSS: jack_client_create_thread() failed: %s@%i",
- __FILE__, __LINE__);
+ if (infd >= 0) {
+ if (jack_client_create_thread (NULL, &driver->thread_in,
+ driver->engine->rtpriority,
+ driver->engine->control->real_time,
+ io_thread, driver) < 0) {
+ jack_error ("OSS: jack_client_create_thread() failed: %s@%i",
+ __FILE__, __LINE__);
return -1;
}
driver->threads |= 1;
}
-# ifdef USE_BARRIER
- if (outfd >= 0)
- {
- if (jack_client_create_thread(NULL, &driver->thread_out,
- driver->engine->rtpriority,
- driver->engine->control->real_time,
- io_thread, driver) < 0)
- {
- jack_error("OSS: jack_client_create_thread() failed: %s@%i",
- __FILE__, __LINE__);
+# ifdef USE_BARRIER
+ if (outfd >= 0) {
+ if (jack_client_create_thread (NULL, &driver->thread_out,
+ driver->engine->rtpriority,
+ driver->engine->control->real_time,
+ io_thread, driver) < 0) {
+ jack_error ("OSS: jack_client_create_thread() failed: %s@%i",
+ __FILE__, __LINE__);
return -1;
}
driver->threads |= 2;
}
-# endif
+# endif
- if (driver->threads & 1) sem_post(&driver->sem_start);
- if (driver->threads & 2) sem_post(&driver->sem_start);
+ if (driver->threads & 1) {
+ sem_post (&driver->sem_start);
+ }
+ if (driver->threads & 2) {
+ sem_post (&driver->sem_start);
+ }
- driver->last_periodtime = driver->engine->get_microseconds();
+ driver->last_periodtime = driver->engine->get_microseconds ();
driver->next_periodtime = 0;
driver->iodelay = 0.0F;
@@ -775,50 +718,42 @@ static int oss_driver_stop (oss_driver_t *driver)
void *retval;
driver->run = 0;
- if (driver->threads & 1)
- {
- if (pthread_join(driver->thread_in, &retval) < 0)
- {
- jack_error("OSS: pthread_join() failed: %s@%i",
- __FILE__, __LINE__);
+ if (driver->threads & 1) {
+ if (pthread_join (driver->thread_in, &retval) < 0) {
+ jack_error ("OSS: pthread_join() failed: %s@%i",
+ __FILE__, __LINE__);
return -1;
}
}
- if (driver->threads & 2)
- {
- if (pthread_join(driver->thread_out, &retval) < 0)
- {
- jack_error("OSS: pthread_join() failed: %s@%i",
- __FILE__, __LINE__);
+ if (driver->threads & 2) {
+ if (pthread_join (driver->thread_out, &retval) < 0) {
+ jack_error ("OSS: pthread_join() failed: %s@%i",
+ __FILE__, __LINE__);
return -1;
}
}
- sem_destroy(&driver->sem_start);
-# ifdef USE_BARRIER
- pthread_barrier_destroy(&driver->barrier);
-# endif
- pthread_mutex_destroy(&driver->mutex_in);
- pthread_mutex_destroy(&driver->mutex_out);
-
- if (driver->outfd >= 0 && driver->outfd != driver->infd)
- {
- close(driver->outfd);
+ sem_destroy (&driver->sem_start);
+# ifdef USE_BARRIER
+ pthread_barrier_destroy (&driver->barrier);
+# endif
+ pthread_mutex_destroy (&driver->mutex_in);
+ pthread_mutex_destroy (&driver->mutex_out);
+
+ if (driver->outfd >= 0 && driver->outfd != driver->infd) {
+ close (driver->outfd);
driver->outfd = -1;
}
- if (driver->infd >= 0)
- {
- close(driver->infd);
+ if (driver->infd >= 0) {
+ close (driver->infd);
driver->infd = -1;
}
- if (driver->indevbuf != NULL)
- {
- free(driver->indevbuf);
+ if (driver->indevbuf != NULL) {
+ free (driver->indevbuf);
driver->indevbuf = NULL;
}
- if (driver->outdevbuf != NULL)
- {
- free(driver->outdevbuf);
+ if (driver->outdevbuf != NULL) {
+ free (driver->outdevbuf);
driver->outdevbuf = NULL;
}
@@ -833,37 +768,36 @@ static int oss_driver_read (oss_driver_t *driver, jack_nframes_t nframes)
JSList *node;
jack_port_t *port;
- if (!driver->run) return 0;
- if (nframes != driver->period_size)
- {
- jack_error(
+ if (!driver->run) {
+ return 0;
+ }
+ if (nframes != driver->period_size) {
+ jack_error (
"OSS: read failed nframes != period_size (%u/%u): %s@%i",
nframes, driver->period_size, __FILE__, __LINE__);
return -1;
}
- pthread_mutex_lock(&driver->mutex_in);
+ pthread_mutex_lock (&driver->mutex_in);
node = driver->capture_ports;
channel = 0;
- while (node != NULL)
- {
- port = (jack_port_t *) node->data;
-
- if (jack_port_connected(port))
- {
- portbuf = jack_port_get_buffer(port, nframes);
- copy_and_convert_in(portbuf, driver->indevbuf,
- nframes, channel,
- driver->capture_channels,
- driver->bits);
+ while (node != NULL) {
+ port = (jack_port_t*)node->data;
+
+ if (jack_port_connected (port)) {
+ portbuf = jack_port_get_buffer (port, nframes);
+ copy_and_convert_in (portbuf, driver->indevbuf,
+ nframes, channel,
+ driver->capture_channels,
+ driver->bits);
}
- node = jack_slist_next(node);
+ node = jack_slist_next (node);
channel++;
}
- pthread_mutex_unlock(&driver->mutex_in);
+ pthread_mutex_unlock (&driver->mutex_in);
return 0;
}
@@ -876,37 +810,36 @@ static int oss_driver_write (oss_driver_t *driver, jack_nframes_t nframes)
JSList *node;
jack_port_t *port;
- if (!driver->run) return 0;
- if (nframes != driver->period_size)
- {
- jack_error(
+ if (!driver->run) {
+ return 0;
+ }
+ if (nframes != driver->period_size) {
+ jack_error (
"OSS: write failed nframes != period_size (%u/%u): %s@%i",
nframes, driver->period_size, __FILE__, __LINE__);
return -1;
}
- pthread_mutex_lock(&driver->mutex_out);
+ pthread_mutex_lock (&driver->mutex_out);
node = driver->playback_ports;
channel = 0;
- while (node != NULL)
- {
- port = (jack_port_t *) node->data;
-
- if (jack_port_connected(port))
- {
- portbuf = jack_port_get_buffer(port, nframes);
- copy_and_convert_out(driver->outdevbuf, portbuf,
- nframes, channel,
- driver->playback_channels,
- driver->bits);
+ while (node != NULL) {
+ port = (jack_port_t*)node->data;
+
+ if (jack_port_connected (port)) {
+ portbuf = jack_port_get_buffer (port, nframes);
+ copy_and_convert_out (driver->outdevbuf, portbuf,
+ nframes, channel,
+ driver->playback_channels,
+ driver->bits);
}
- node = jack_slist_next(node);
+ node = jack_slist_next (node);
channel++;
}
- pthread_mutex_unlock(&driver->mutex_out);
+ pthread_mutex_unlock (&driver->mutex_out);
return 0;
}
@@ -914,13 +847,13 @@ static int oss_driver_write (oss_driver_t *driver, jack_nframes_t nframes)
static int oss_driver_null_cycle (oss_driver_t *driver, jack_nframes_t nframes)
{
- pthread_mutex_lock(&driver->mutex_in);
- memset(driver->indevbuf, 0x00, driver->indevbufsize);
- pthread_mutex_unlock(&driver->mutex_in);
+ pthread_mutex_lock (&driver->mutex_in);
+ memset (driver->indevbuf, 0x00, driver->indevbufsize);
+ pthread_mutex_unlock (&driver->mutex_in);
- pthread_mutex_lock(&driver->mutex_out);
- memset(driver->outdevbuf, 0x00, driver->outdevbufsize);
- pthread_mutex_unlock(&driver->mutex_out);
+ pthread_mutex_lock (&driver->mutex_out);
+ memset (driver->outdevbuf, 0x00, driver->outdevbufsize);
+ pthread_mutex_unlock (&driver->mutex_out);
return 0;
}
@@ -928,16 +861,16 @@ static int oss_driver_null_cycle (oss_driver_t *driver, jack_nframes_t nframes)
static int oss_driver_bufsize (oss_driver_t *driver, jack_nframes_t nframes)
{
- oss_driver_stop(driver);
+ oss_driver_stop (driver);
- set_period_size(driver, nframes);
- if (driver->engine->set_buffer_size(driver->engine, driver->period_size)) {
+ set_period_size (driver, nframes);
+ if (driver->engine->set_buffer_size (driver->engine, driver->period_size)) {
jack_error ("OSS: cannot set engine buffer size to %d (check MIDI)", driver->period_size);
return -1;
}
- jack_info("oss_driver: period size update: %u", nframes);
+ jack_info ("oss_driver: period size update: %u", nframes);
- oss_driver_start(driver);
+ oss_driver_start (driver);
return 0;
}
@@ -949,17 +882,13 @@ static int oss_driver_bufsize (oss_driver_t *driver, jack_nframes_t nframes)
#ifdef USE_BARRIER
static inline void synchronize (oss_driver_t *driver)
{
- if (driver->threads == 3)
- {
- if (pthread_barrier_wait(&driver->barrier) ==
- PTHREAD_BARRIER_SERIAL_THREAD)
- {
- driver_cycle(driver);
+ if (driver->threads == 3) {
+ if (pthread_barrier_wait (&driver->barrier) ==
+ PTHREAD_BARRIER_SERIAL_THREAD) {
+ driver_cycle (driver);
}
- }
- else
- {
- driver_cycle(driver);
+ } else {
+ driver_cycle (driver);
}
}
#endif
@@ -970,113 +899,98 @@ static void *io_thread (void *param)
size_t localsize;
ssize_t io_res;
void *localbuf;
- oss_driver_t *driver = (oss_driver_t *) param;
+ oss_driver_t *driver = (oss_driver_t*)param;
- sem_wait(&driver->sem_start);
+ sem_wait (&driver->sem_start);
-# ifdef USE_BARRIER
- if (pthread_self() == driver->thread_in)
- {
+# ifdef USE_BARRIER
+ if (pthread_self () == driver->thread_in) {
localsize = driver->indevbufsize;
- localbuf = malloc(localsize);
- if (localbuf == NULL)
- {
- jack_error("OSS: malloc() failed: %s@%i",
- __FILE__, __LINE__);
+ localbuf = malloc (localsize);
+ if (localbuf == NULL) {
+ jack_error ("OSS: malloc() failed: %s@%i",
+ __FILE__, __LINE__);
return NULL;
}
- while (driver->run)
- {
- io_res = read(driver->infd, localbuf, localsize);
- if (io_res < (ssize_t) localsize)
- {
- jack_error(
+ while (driver->run) {
+ io_res = read (driver->infd, localbuf, localsize);
+ if (io_res < (ssize_t)localsize) {
+ jack_error (
"OSS: read() failed: %s@%i, count=%d/%d, errno=%d",
__FILE__, __LINE__, io_res, localsize,
errno);
break;
}
- pthread_mutex_lock(&driver->mutex_in);
- memcpy(driver->indevbuf, localbuf, localsize);
- pthread_mutex_unlock(&driver->mutex_in);
+ pthread_mutex_lock (&driver->mutex_in);
+ memcpy (driver->indevbuf, localbuf, localsize);
+ pthread_mutex_unlock (&driver->mutex_in);
- synchronize(driver);
+ synchronize (driver);
}
- free(localbuf);
- }
- else if (pthread_self() == driver->thread_out)
- {
+ free (localbuf);
+ } else if (pthread_self () == driver->thread_out) {
localsize = driver->outdevbufsize;
- localbuf = malloc(localsize);
- if (localbuf == NULL)
- {
- jack_error("OSS: malloc() failed: %s@%i",
- __FILE__, __LINE__);
+ localbuf = malloc (localsize);
+ if (localbuf == NULL) {
+ jack_error ("OSS: malloc() failed: %s@%i",
+ __FILE__, __LINE__);
return NULL;
}
- if (driver->trigger)
- {
+ if (driver->trigger) {
/* don't care too much if this fails */
- memset(localbuf, 0x00, localsize);
- write(driver->outfd, localbuf, localsize);
- ioctl(driver->outfd, SNDCTL_DSP_SETTRIGGER, &driver->trigger);
+ memset (localbuf, 0x00, localsize);
+ write (driver->outfd, localbuf, localsize);
+ ioctl (driver->outfd, SNDCTL_DSP_SETTRIGGER, &driver->trigger);
}
- while (driver->run)
- {
- pthread_mutex_lock(&driver->mutex_out);
- memcpy(localbuf, driver->outdevbuf, localsize);
- pthread_mutex_unlock(&driver->mutex_out);
+ while (driver->run) {
+ pthread_mutex_lock (&driver->mutex_out);
+ memcpy (localbuf, driver->outdevbuf, localsize);
+ pthread_mutex_unlock (&driver->mutex_out);
- io_res = write(driver->outfd, localbuf, localsize);
- if (io_res < (ssize_t) localsize)
- {
- jack_error(
+ io_res = write (driver->outfd, localbuf, localsize);
+ if (io_res < (ssize_t)localsize) {
+ jack_error (
"OSS: write() failed: %s@%i, count=%d/%d, errno=%d",
__FILE__, __LINE__, io_res, localsize,
errno);
break;
}
- synchronize(driver);
+ synchronize (driver);
}
- free(localbuf);
+ free (localbuf);
}
-# else
+# else
localsize = (driver->indevbufsize >= driver->outdevbufsize) ?
- driver->indevbufsize : driver->outdevbufsize;
- localbuf = malloc(localsize);
- if (localbuf == NULL)
- {
- jack_error("OSS: malloc() failed: %s@%i", __FILE__, __LINE__);
+ driver->indevbufsize : driver->outdevbufsize;
+ localbuf = malloc (localsize);
+ if (localbuf == NULL) {
+ jack_error ("OSS: malloc() failed: %s@%i", __FILE__, __LINE__);
return NULL;
}
- if (driver->trigger)
- {
+ if (driver->trigger) {
/* don't care too much if this fails */
- memset(localbuf, 0x00, localsize);
- write(driver->outfd, localbuf, driver->outdevbufsize);
- ioctl(driver->outfd, SNDCTL_DSP_SETTRIGGER, &driver->trigger);
+ memset (localbuf, 0x00, localsize);
+ write (driver->outfd, localbuf, driver->outdevbufsize);
+ ioctl (driver->outfd, SNDCTL_DSP_SETTRIGGER, &driver->trigger);
}
- while (driver->run)
- {
- if (driver->playback_channels > 0)
- {
- pthread_mutex_lock(&driver->mutex_out);
- memcpy(localbuf, driver->outdevbuf,
+ while (driver->run) {
+ if (driver->playback_channels > 0) {
+ pthread_mutex_lock (&driver->mutex_out);
+ memcpy (localbuf, driver->outdevbuf,
driver->outdevbufsize);
- pthread_mutex_unlock(&driver->mutex_out);
+ pthread_mutex_unlock (&driver->mutex_out);
- io_res = write(driver->outfd, localbuf,
- driver->outdevbufsize);
- if (io_res < (ssize_t) driver->outdevbufsize)
- {
- jack_error(
+ io_res = write (driver->outfd, localbuf,
+ driver->outdevbufsize);
+ if (io_res < (ssize_t)driver->outdevbufsize) {
+ jack_error (
"OSS: write() failed: %s@%i, count=%d/%d, errno=%d",
__FILE__, __LINE__, io_res,
driver->outdevbufsize, errno);
@@ -1084,30 +998,28 @@ static void *io_thread (void *param)
}
}
- if (driver->capture_channels > 0)
- {
- io_res = read(driver->infd, localbuf,
- driver->indevbufsize);
- if (io_res < (ssize_t) driver->indevbufsize)
- {
- jack_error(
+ if (driver->capture_channels > 0) {
+ io_res = read (driver->infd, localbuf,
+ driver->indevbufsize);
+ if (io_res < (ssize_t)driver->indevbufsize) {
+ jack_error (
"OSS: read() failed: %s@%i, count=%d/%d, errno=%d",
__FILE__, __LINE__, io_res,
driver->indevbufsize, errno);
break;
}
- pthread_mutex_lock(&driver->mutex_in);
- memcpy(driver->indevbuf, localbuf,
+ pthread_mutex_lock (&driver->mutex_in);
+ memcpy (driver->indevbuf, localbuf,
driver->indevbufsize);
- pthread_mutex_unlock(&driver->mutex_in);
+ pthread_mutex_unlock (&driver->mutex_in);
}
- driver_cycle(driver);
+ driver_cycle (driver);
}
- free(localbuf);
-# endif
+ free (localbuf);
+# endif
return NULL;
}
@@ -1119,7 +1031,7 @@ static void *io_thread (void *param)
const char driver_client_name[] = "oss";
-void driver_finish (jack_driver_t *);
+void driver_finish(jack_driver_t *);
jack_driver_desc_t * driver_get_descriptor ()
@@ -1127,24 +1039,22 @@ jack_driver_desc_t * driver_get_descriptor ()
jack_driver_desc_t *desc;
jack_driver_param_desc_t *params;
- desc = (jack_driver_desc_t *) calloc(1, sizeof(jack_driver_desc_t));
- if (desc == NULL)
- {
- jack_error("oss_driver: calloc() failed: %s@%i, errno=%d",
- __FILE__, __LINE__, errno);
+ desc = (jack_driver_desc_t*)calloc (1, sizeof(jack_driver_desc_t));
+ if (desc == NULL) {
+ jack_error ("oss_driver: calloc() failed: %s@%i, errno=%d",
+ __FILE__, __LINE__, errno);
return NULL;
}
- strcpy(desc->name, driver_client_name);
+ strcpy (desc->name, driver_client_name);
desc->nparams = OSS_DRIVER_N_PARAMS;
- params = calloc(desc->nparams, sizeof(jack_driver_param_desc_t));
- if (params == NULL)
- {
- jack_error("oss_driver: calloc() failed: %s@%i, errno=%d",
- __FILE__, __LINE__, errno);
+ params = calloc (desc->nparams, sizeof(jack_driver_param_desc_t));
+ if (params == NULL) {
+ jack_error ("oss_driver: calloc() failed: %s@%i, errno=%d",
+ __FILE__, __LINE__, errno);
return NULL;
}
- memcpy(params, oss_params,
+ memcpy (params, oss_params,
desc->nparams * sizeof(jack_driver_param_desc_t));
desc->params = params;
@@ -1152,8 +1062,8 @@ jack_driver_desc_t * driver_get_descriptor ()
}
-jack_driver_t * driver_initialize (jack_client_t *client,
- JSList * params)
+jack_driver_t * driver_initialize (jack_client_t *client,
+ JSList * params)
{
int bits = OSS_DRIVER_DEF_BITS;
jack_nframes_t sample_rate = OSS_DRIVER_DEF_FS;
@@ -1167,25 +1077,24 @@ jack_driver_t * driver_initialize (jack_client_t *client,
const jack_driver_param_t *param;
oss_driver_t *driver;
- driver = (oss_driver_t *) malloc(sizeof(oss_driver_t));
- if (driver == NULL)
- {
- jack_error("OSS: malloc() failed: %s@%i, errno=%d",
- __FILE__, __LINE__, errno);
+ driver = (oss_driver_t*)malloc (sizeof(oss_driver_t));
+ if (driver == NULL) {
+ jack_error ("OSS: malloc() failed: %s@%i, errno=%d",
+ __FILE__, __LINE__, errno);
return NULL;
}
- memset(driver, 0x00, sizeof(oss_driver_t));
- jack_driver_init((jack_driver_t *) driver);
-
- driver->attach = (JackDriverAttachFunction) oss_driver_attach;
- driver->detach = (JackDriverDetachFunction) oss_driver_detach;
- driver->start = (JackDriverStartFunction) oss_driver_start;
- driver->stop = (JackDriverStopFunction) oss_driver_stop;
- driver->read = (JackDriverReadFunction) oss_driver_read;
- driver->write = (JackDriverWriteFunction) oss_driver_write;
- driver->null_cycle = (JackDriverNullCycleFunction)
- oss_driver_null_cycle;
- driver->bufsize = (JackDriverBufSizeFunction) oss_driver_bufsize;
+ memset (driver, 0x00, sizeof(oss_driver_t));
+ jack_driver_init ((jack_driver_t*)driver);
+
+ driver->attach = (JackDriverAttachFunction)oss_driver_attach;
+ driver->detach = (JackDriverDetachFunction)oss_driver_detach;
+ driver->start = (JackDriverStartFunction)oss_driver_start;
+ driver->stop = (JackDriverStopFunction)oss_driver_stop;
+ driver->read = (JackDriverReadFunction)oss_driver_read;
+ driver->write = (JackDriverWriteFunction)oss_driver_write;
+ driver->null_cycle = (JackDriverNullCycleFunction)
+ oss_driver_null_cycle;
+ driver->bufsize = (JackDriverBufSizeFunction)oss_driver_bufsize;
driver->indev = NULL;
driver->outdev = NULL;
@@ -1193,49 +1102,47 @@ jack_driver_t * driver_initialize (jack_client_t *client,
driver->trigger = 0;
pnode = params;
- while (pnode != NULL)
- {
- param = (const jack_driver_param_t *) pnode->data;
-
- switch (param->character)
- {
- case 'r':
- sample_rate = param->value.ui;
- break;
- case 'p':
- period_size = param->value.ui;
- break;
- case 'n':
- nperiods = param->value.ui;
- break;
- case 'w':
- bits = param->value.i;
- break;
- case 'i':
- capture_channels = param->value.ui;
- break;
- case 'o':
- playback_channels = param->value.ui;
- break;
- case 'C':
- driver->indev = strdup(param->value.str);
- break;
- case 'P':
- driver->outdev = strdup(param->value.str);
- break;
- case 'b':
- driver->ignorehwbuf = 1;
- break;
- case 'I':
- in_latency = param->value.ui;
- break;
- case 'O':
- out_latency = param->value.ui;
- break;
+ while (pnode != NULL) {
+ param = (const jack_driver_param_t*)pnode->data;
+
+ switch (param->character) {
+ case 'r':
+ sample_rate = param->value.ui;
+ break;
+ case 'p':
+ period_size = param->value.ui;
+ break;
+ case 'n':
+ nperiods = param->value.ui;
+ break;
+ case 'w':
+ bits = param->value.i;
+ break;
+ case 'i':
+ capture_channels = param->value.ui;
+ break;
+ case 'o':
+ playback_channels = param->value.ui;
+ break;
+ case 'C':
+ driver->indev = strdup (param->value.str);
+ break;
+ case 'P':
+ driver->outdev = strdup (param->value.str);
+ break;
+ case 'b':
+ driver->ignorehwbuf = 1;
+ break;
+ case 'I':
+ in_latency = param->value.ui;
+ break;
+ case 'O':
+ out_latency = param->value.ui;
+ break;
}
- pnode = jack_slist_next(pnode);
+ pnode = jack_slist_next (pnode);
}
-
+
driver->sample_rate = sample_rate;
driver->period_size = period_size;
driver->nperiods = nperiods;
@@ -1248,63 +1155,64 @@ jack_driver_t * driver_initialize (jack_client_t *client,
driver->finish = driver_finish;
- if (driver->indev == NULL)
- driver->indev = strdup(OSS_DRIVER_DEF_DEV);
- if (driver->outdev == NULL)
- driver->outdev = strdup(OSS_DRIVER_DEF_DEV);
+ if (driver->indev == NULL) {
+ driver->indev = strdup (OSS_DRIVER_DEF_DEV);
+ }
+ if (driver->outdev == NULL) {
+ driver->outdev = strdup (OSS_DRIVER_DEF_DEV);
+ }
driver->infd = -1;
driver->outfd = -1;
- switch (driver->bits)
- {
-# ifndef OSS_ENDIAN
-# ifdef __GNUC__
-# if (defined(__i386__) || defined(__alpha__) || defined(__arm__) || defined(__x86_64__) || (defined(__sh__) && !defined(__LITTLE_ENDIAN__)))
-# define OSS_LITTLE_ENDIAN 1234
-# define OSS_ENDIAN OSS_LITTLE_ENDIAN
-# else
-# define OSS_BIG_ENDIAN 4321
-# define OSS_ENDIAN OSS_BIG_ENDIAN
-# endif
-# else /* __GNUC__ */
-# if (defined(_AIX) || defined(AIX) || defined(sparc) || defined(__hppa) || defined(PPC) || defined(__powerpc__) && !defined(i386) && !defined(__i386) && !defined(__i386__))
-# define OSS_BIG_ENDIAN 4321
-# define OSS_ENDIAN OSS_BIG_ENDIAN
-# else
-# define OSS_LITTLE_ENDIAN 1234
-# define OSS_ENDIAN OSS_LITTLE_ENDIAN
-# endif
-# endif /* __GNUC__ */
-# endif /* OSS_ENDIAN */
-# if (OSS_ENDIAN == 1234)
- /* little-endian architectures */
- case 24: /* little-endian LSB aligned 24-bits in 32-bits integer */
- driver->format = 0x00008000;
- break;
- case 32: /* little-endian 32-bit integer */
- driver->format = 0x00001000;
- break;
- case 64: /* native-endian 64-bit float */
- driver->format = 0x00004000;
- break;
- case 16: /* little-endian 16-bit integer */
- default:
- driver->format = 0x00000010;
- break;
+ switch (driver->bits) {
+# ifndef OSS_ENDIAN
+# ifdef __GNUC__
+# if (defined(__i386__) || defined(__alpha__) || defined(__arm__) || defined(__x86_64__) || (defined(__sh__) && !defined(__LITTLE_ENDIAN__)))
+# define OSS_LITTLE_ENDIAN 1234
+# define OSS_ENDIAN OSS_LITTLE_ENDIAN
+# else
+# define OSS_BIG_ENDIAN 4321
+# define OSS_ENDIAN OSS_BIG_ENDIAN
+# endif
+# else /* __GNUC__ */
+# if (defined(_AIX) || defined(AIX) || defined(sparc) || defined(__hppa) || defined(PPC) || defined(__powerpc__) && !defined(i386) && !defined(__i386) && !defined(__i386__))
+# define OSS_BIG_ENDIAN 4321
+# define OSS_ENDIAN OSS_BIG_ENDIAN
+# else
+# define OSS_LITTLE_ENDIAN 1234
+# define OSS_ENDIAN OSS_LITTLE_ENDIAN
+# endif
+# endif /* __GNUC__ */
+# endif /* OSS_ENDIAN */
+# if (OSS_ENDIAN == 1234)
+ /* little-endian architectures */
+ case 24: /* little-endian LSB aligned 24-bits in 32-bits integer */
+ driver->format = 0x00008000;
+ break;
+ case 32: /* little-endian 32-bit integer */
+ driver->format = 0x00001000;
+ break;
+ case 64: /* native-endian 64-bit float */
+ driver->format = 0x00004000;
+ break;
+ case 16: /* little-endian 16-bit integer */
+ default:
+ driver->format = 0x00000010;
+ break;
/* big-endian architectures */
-# else
- case 24: /* big-endian LSB aligned 24-bits in 32-bits integer */
- break;
- driver->format = 0x00010000;
- case 32: /* big-endian 32-bit integer */
- driver->format = 0x00002000;
- break;
- case 64: /* native-endian 64-bit float */
- driver->format = 0x00004000;
- break;
- case 16: /* big-endian 16-bit integer */
- default:
- driver->format = 0x00000020;
-# endif
+# else
+ case 24: /* big-endian LSB aligned 24-bits in 32-bits integer */
+ break;
+ driver->format = 0x00010000;
+ case 32: /* big-endian 32-bit integer */
+ driver->format = 0x00002000;
+ break;
+ case 64: /* native-endian 64-bit float */
+ driver->format = 0x00004000;
+ break;
+ case 16: /* big-endian 16-bit integer */
+ default:
+ driver->format = 0x00000020;
+# endif
}
driver->indevbuf = driver->outdevbuf = NULL;
@@ -1315,19 +1223,21 @@ jack_driver_t * driver_initialize (jack_client_t *client,
driver->engine = NULL;
driver->client = client;
- return ((jack_driver_t *) driver);
+ return (jack_driver_t*)driver;
}
void driver_finish (jack_driver_t *driver)
{
- oss_driver_t *oss_driver = (oss_driver_t *) driver;
-
- oss_driver = (oss_driver_t *) driver;
- if (oss_driver->indev != NULL)
- free(oss_driver->indev);
- if (oss_driver->outdev != NULL)
- free(oss_driver->outdev);
- free(driver);
+ oss_driver_t *oss_driver = (oss_driver_t*)driver;
+
+ oss_driver = (oss_driver_t*)driver;
+ if (oss_driver->indev != NULL) {
+ free (oss_driver->indev);
+ }
+ if (oss_driver->outdev != NULL) {
+ free (oss_driver->outdev);
+ }
+ free (driver);
}
diff --git a/drivers/oss/oss_driver.h b/drivers/oss/oss_driver.h
index 5bdf12d..ace932f 100644
--- a/drivers/oss/oss_driver.h
+++ b/drivers/oss/oss_driver.h
@@ -1,24 +1,24 @@
/*
- OSS driver for Jack
- Copyright (C) 2003-2007 Jussi Laako <jussi@sonarnerd.net>
+ OSS driver for Jack
+ Copyright (C) 2003-2007 Jussi Laako <jussi@sonarnerd.net>
- 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 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.
+ 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., 59 Temple Place, Suite 330, Boston,
- MA 02111-1307 USA
+ 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., 59 Temple Place, Suite 330, Boston,
+ MA 02111-1307 USA
-*/
+ */
#ifndef __JACK_OSS_DRIVER_H__
@@ -35,19 +35,18 @@
#include "driver.h"
-#define OSS_DRIVER_DEF_DEV "/dev/dsp"
-#define OSS_DRIVER_DEF_FS 48000
-#define OSS_DRIVER_DEF_BLKSIZE 1024
-#define OSS_DRIVER_DEF_NPERIODS 2
-#define OSS_DRIVER_DEF_BITS 16
-#define OSS_DRIVER_DEF_INS 2
-#define OSS_DRIVER_DEF_OUTS 2
+#define OSS_DRIVER_DEF_DEV "/dev/dsp"
+#define OSS_DRIVER_DEF_FS 48000
+#define OSS_DRIVER_DEF_BLKSIZE 1024
+#define OSS_DRIVER_DEF_NPERIODS 2
+#define OSS_DRIVER_DEF_BITS 16
+#define OSS_DRIVER_DEF_INS 2
+#define OSS_DRIVER_DEF_OUTS 2
typedef jack_default_audio_sample_t jack_sample_t;
-typedef struct _oss_driver
-{
+typedef struct _oss_driver {
JACK_DRIVER_DECL
jack_nframes_t sample_rate;
@@ -89,9 +88,9 @@ typedef struct _oss_driver
pthread_t thread_out;
pthread_mutex_t mutex_in;
pthread_mutex_t mutex_out;
-# ifdef USE_BARRIER
+# ifdef USE_BARRIER
pthread_barrier_t barrier;
-# endif
+# endif
sem_t sem_start;
} oss_driver_t;
diff --git a/drivers/portaudio/portaudio_driver.c b/drivers/portaudio/portaudio_driver.c
index f7b78bf..5735bea 100644
--- a/drivers/portaudio/portaudio_driver.c
+++ b/drivers/portaudio/portaudio_driver.c
@@ -18,24 +18,24 @@
Grame Research Laboratory, 9, rue du Garet 69001 Lyon - France
grame@rd.grame.fr
-
+
02-09-03 : Modify jack port naming : add the name of the used driver
Add the -n option to load a specific driver using it's name
04-09-03 : Correct bug in -n option management : input and ouput have to be treated separately
08-09-03 : More robust driver loading code : new portaudio_load_default and portaudio_load_driver functions.
24-09-03 : Does not tries to load default device if the required one is not found, returns and error.
14-10-03 : After jack port name size extension, does not use fixed length for CoreAudio driver name anymore
- 09-01-04 : Handle different value for channel in and channel out (using -i and -o)
- 12-01-04 : Connect port names (inverse "in" and "out")
- 13-01-04 : Correct the length of jack port : use JACK_PORT_NAME_SIZE
- 22-03-04 : Remove jack_init_time, rename input and ouput ports using "capture" and "playback"
+ 09-01-04 : Handle different value for channel in and channel out (using -i and -o)
+ 12-01-04 : Connect port names (inverse "in" and "out")
+ 13-01-04 : Correct the length of jack port : use JACK_PORT_NAME_SIZE
+ 22-03-04 : Remove jack_init_time, rename input and ouput ports using "capture" and "playback"
10-11-04 : S. Letz: Add management of -I option for use with JackPilot.
- 17-11-04 : S. Letz: Better debug code.
- 03-02-05 : S. Letz: fix several driver detection bugs on OSX.
- 06-08-05 : S.Letz: Remove the "-I" parameter, change the semantic of "-n" parameter on OSX : -n (driver name) now correctly uses the PropertyDeviceUID
- (persistent accross reboot...) as the identifier for the used coreaudio driver.
+ 17-11-04 : S. Letz: Better debug code.
+ 03-02-05 : S. Letz: fix several driver detection bugs on OSX.
+ 06-08-05 : S.Letz: Remove the "-I" parameter, change the semantic of "-n" parameter on OSX : -n (driver name) now correctly uses the PropertyDeviceUID
+ (persistent accross reboot...) as the identifier for the used coreaudio driver.
-*/
+ */
#include <stdio.h>
#include <errno.h>
@@ -50,47 +50,49 @@
#include <CoreAudio/CoreAudio.h>
#include <CoreFoundation/CFString.h>
-static OSStatus get_device_name_from_id(AudioDeviceID id, char name[60])
+static OSStatus get_device_name_from_id (AudioDeviceID id, char name[60])
{
- UInt32 size = sizeof(char) * 60;
- OSStatus stat = AudioDeviceGetProperty(id, 0, false,
- kAudioDevicePropertyDeviceName,
- &size,
- &name[0]);
- return stat;
+ UInt32 size = sizeof(char) * 60;
+ OSStatus stat = AudioDeviceGetProperty (id, 0, false,
+ kAudioDevicePropertyDeviceName,
+ &size,
+ &name[0]);
+
+ return stat;
}
-static OSStatus get_device_id_from_num(int i, AudioDeviceID * id)
+static OSStatus get_device_id_from_num (int i, AudioDeviceID * id)
{
- OSStatus theStatus;
- UInt32 theSize;
- int nDevices;
- AudioDeviceID *theDeviceList;
-
- theStatus =
- AudioHardwareGetPropertyInfo(kAudioHardwarePropertyDevices,
- &theSize, NULL);
- nDevices = theSize / sizeof(AudioDeviceID);
- theDeviceList =
- (AudioDeviceID *) malloc(nDevices * sizeof(AudioDeviceID));
- theStatus =
- AudioHardwareGetProperty(kAudioHardwarePropertyDevices, &theSize,
- theDeviceList);
-
- *id = theDeviceList[i];
- return theStatus;
+ OSStatus theStatus;
+ UInt32 theSize;
+ int nDevices;
+ AudioDeviceID *theDeviceList;
+
+ theStatus =
+ AudioHardwareGetPropertyInfo (kAudioHardwarePropertyDevices,
+ &theSize, NULL);
+ nDevices = theSize / sizeof(AudioDeviceID);
+ theDeviceList =
+ (AudioDeviceID*)malloc (nDevices * sizeof(AudioDeviceID));
+ theStatus =
+ AudioHardwareGetProperty (kAudioHardwarePropertyDevices, &theSize,
+ theDeviceList);
+
+ *id = theDeviceList[i];
+ return theStatus;
}
-static OSStatus get_device_id_from_uid(char* UID, AudioDeviceID* id)
+static OSStatus get_device_id_from_uid (char* UID, AudioDeviceID* id)
{
UInt32 size = sizeof(AudioValueTranslation);
- CFStringRef inIUD = CFStringCreateWithCString(NULL, UID, CFStringGetSystemEncoding());
+ CFStringRef inIUD = CFStringCreateWithCString (NULL, UID, CFStringGetSystemEncoding ());
AudioValueTranslation value = { &inIUD, sizeof(CFStringRef), id, sizeof(AudioDeviceID) };
+
if (inIUD == NULL) {
return kAudioHardwareUnspecifiedError;
} else {
- OSStatus res = AudioHardwareGetProperty(kAudioHardwarePropertyDeviceForUID, &size, &value);
- CFRelease(inIUD);
+ OSStatus res = AudioHardwareGetProperty (kAudioHardwarePropertyDeviceForUID, &size, &value);
+ CFRelease (inIUD);
return res;
}
}
@@ -101,28 +103,28 @@ typedef unsigned int AudioDeviceID;
#define PRINTDEBUG 1
-void PALog(char *fmt, ...)
+void PALog (char *fmt, ...)
{
#ifdef PRINTDEBUG
- va_list ap;
- va_start(ap, fmt);
- fprintf(stderr, "JCA: ");
- vfprintf(stderr, fmt, ap);
- va_end(ap);
+ va_list ap;
+ va_start (ap, fmt);
+ fprintf (stderr, "JCA: ");
+ vfprintf (stderr, fmt, ap);
+ va_end (ap);
#endif
}
static int
-paCallback(void *inputBuffer, void *outputBuffer,
- unsigned long framesPerBuffer,
- PaTimestamp outTime, void *userData)
+paCallback (void *inputBuffer, void *outputBuffer,
+ unsigned long framesPerBuffer,
+ PaTimestamp outTime, void *userData)
{
portaudio_driver_t * driver = (portaudio_driver_t*)userData;
driver->inPortAudio = (float*)inputBuffer;
driver->outPortAudio = (float*)outputBuffer;
- driver->last_wait_ust = driver->engine->get_microseconds();
- return driver->engine->run_cycle(driver->engine, framesPerBuffer, 0);
+ driver->last_wait_ust = driver->engine->get_microseconds ();
+ return driver->engine->run_cycle (driver->engine, framesPerBuffer, 0);
}
static int
@@ -133,61 +135,61 @@ portaudio_driver_attach (portaudio_driver_t *driver, jack_engine_t *engine)
channel_t chn;
char buf[JACK_PORT_NAME_SIZE];
jack_latency_range_t range;
-
+
driver->engine = engine;
-
+
if (driver->engine->set_buffer_size (engine, driver->frames_per_cycle)) {
jack_error ("portaudio: cannot set engine buffer size to %d (check MIDI)", driver->frames_per_cycle);
return -1;
}
driver->engine->set_sample_rate (engine, driver->frame_rate);
-
- port_flags = JackPortIsOutput|JackPortIsPhysical|JackPortIsTerminal;
+
+ port_flags = JackPortIsOutput | JackPortIsPhysical | JackPortIsTerminal;
/*
- if (driver->has_hw_monitoring) {
- port_flags |= JackPortCanMonitor;
- }
- */
+ if (driver->has_hw_monitoring) {
+ port_flags |= JackPortCanMonitor;
+ }
+ */
for (chn = 0; chn < driver->capture_nchannels; chn++) {
- //snprintf (buf, sizeof(buf) - 1, "%s:capture%lu", driver->driver_name, chn+1);
- snprintf (buf, sizeof(buf) - 1, "%s:out%lu", driver->driver_name, chn+1);
+ //snprintf (buf, sizeof(buf) - 1, "%s:capture%lu", driver->driver_name, chn+1);
+ snprintf (buf, sizeof(buf) - 1, "%s:out%lu", driver->driver_name, chn + 1);
- if ((port = jack_port_register (driver->client, buf, JACK_DEFAULT_AUDIO_TYPE, port_flags, 0)) == NULL) {
- jack_error ("portaudio: cannot register port for %s", buf);
- break;
- }
+ if ((port = jack_port_register (driver->client, buf, JACK_DEFAULT_AUDIO_TYPE, port_flags, 0)) == NULL) {
+ jack_error ("portaudio: cannot register port for %s", buf);
+ break;
+ }
- /* XXX fix this so that it can handle: systemic (external) latency
- */
+ /* XXX fix this so that it can handle: systemic (external) latency
+ */
- range.min = range.max = driver->frames_per_cycle;
- jack_port_set_latency_range (port, JackCaptureLatency, &range);
- driver->capture_ports = jack_slist_append (driver->capture_ports, port);
+ range.min = range.max = driver->frames_per_cycle;
+ jack_port_set_latency_range (port, JackCaptureLatency, &range);
+ driver->capture_ports = jack_slist_append (driver->capture_ports, port);
}
-
- port_flags = JackPortIsInput|JackPortIsPhysical|JackPortIsTerminal;
+
+ port_flags = JackPortIsInput | JackPortIsPhysical | JackPortIsTerminal;
for (chn = 0; chn < driver->playback_nchannels; chn++) {
- //snprintf (buf, sizeof(buf) - 1, "%s:playback%lu", driver->driver_name, chn+1);
- snprintf (buf, sizeof(buf) - 1, "%s:in%lu", driver->driver_name, chn+1);
+ //snprintf (buf, sizeof(buf) - 1, "%s:playback%lu", driver->driver_name, chn+1);
+ snprintf (buf, sizeof(buf) - 1, "%s:in%lu", driver->driver_name, chn + 1);
- if ((port = jack_port_register (driver->client, buf, JACK_DEFAULT_AUDIO_TYPE, port_flags, 0)) == NULL) {
- jack_error ("portaudio: cannot register port for %s", buf);
- break;
- }
-
- /* XXX fix this so that it can handle: systemic (external) latency
- */
-
- range.min = range.max = driver->frames_per_cycle;
- jack_port_set_latency_range (port, JackPlaybackLatency, &range);
- driver->playback_ports = jack_slist_append (driver->playback_ports, port);
+ if ((port = jack_port_register (driver->client, buf, JACK_DEFAULT_AUDIO_TYPE, port_flags, 0)) == NULL) {
+ jack_error ("portaudio: cannot register port for %s", buf);
+ break;
+ }
+
+ /* XXX fix this so that it can handle: systemic (external) latency
+ */
+
+ range.min = range.max = driver->frames_per_cycle;
+ jack_port_set_latency_range (port, JackPlaybackLatency, &range);
+ driver->playback_ports = jack_slist_append (driver->playback_ports, port);
}
jack_activate (driver->client);
- return 0;
+ return 0;
}
static int
@@ -196,31 +198,29 @@ portaudio_driver_detach (portaudio_driver_t *driver, jack_engine_t *engine)
JSList *node;
if (driver->engine == 0) {
- return -1;
+ return -1;
}
- for (node = driver->capture_ports; node; node = jack_slist_next (node)) {
- jack_port_unregister (driver->client, ((jack_port_t *) node->data));
- }
+ for (node = driver->capture_ports; node; node = jack_slist_next (node))
+ jack_port_unregister (driver->client, ((jack_port_t*)node->data));
jack_slist_free (driver->capture_ports);
driver->capture_ports = 0;
-
- for (node = driver->playback_ports; node; node = jack_slist_next (node)) {
- jack_port_unregister (driver->client, ((jack_port_t *) node->data));
- }
+
+ for (node = driver->playback_ports; node; node = jack_slist_next (node))
+ jack_port_unregister (driver->client, ((jack_port_t*)node->data));
jack_slist_free (driver->playback_ports);
driver->playback_ports = 0;
-
+
driver->engine = 0;
- return 0;
+ return 0;
}
static int
portaudio_driver_null_cycle (portaudio_driver_t* driver, jack_nframes_t nframes)
{
- memset(driver->outPortAudio, 0, (driver->playback_nchannels * nframes * sizeof(float)));
+ memset (driver->outPortAudio, 0, (driver->playback_nchannels * nframes * sizeof(float)));
return 0;
}
@@ -234,22 +234,22 @@ portaudio_driver_read (portaudio_driver_t *driver, jack_nframes_t nframes)
int i;
for (chn = 0, node = driver->capture_ports; node; node = jack_slist_next (node), chn++) {
-
- port = (jack_port_t *)node->data;
-
- if (jack_port_connected (port) && (driver->inPortAudio != NULL)) {
- int channels = driver->capture_nchannels;
- float* in = driver->inPortAudio;
- buf = jack_port_get_buffer (port, nframes);
- for (i = 0; i< nframes; i++) buf[i] = in[channels*i+chn];
- }
+
+ port = (jack_port_t*)node->data;
+
+ if (jack_port_connected (port) && (driver->inPortAudio != NULL)) {
+ int channels = driver->capture_nchannels;
+ float* in = driver->inPortAudio;
+ buf = jack_port_get_buffer (port, nframes);
+ for (i = 0; i < nframes; i++) buf[i] = in[channels * i + chn];
+ }
}
-
+
driver->engine->transport_cycle_start (driver->engine,
- driver->engine->get_microseconds ());
+ driver->engine->get_microseconds ());
return 0;
-}
+}
static int
@@ -259,70 +259,72 @@ portaudio_driver_write (portaudio_driver_t *driver, jack_nframes_t nframes)
channel_t chn;
jack_port_t *port;
JSList *node;
- int i,bytes = nframes*sizeof(float);
-
+ int i, bytes = nframes * sizeof(float);
+
/* Clear in case of nothing is connected */
- memset(driver->outPortAudio, 0, driver->playback_nchannels*bytes);
-
+ memset (driver->outPortAudio, 0, driver->playback_nchannels * bytes);
+
for (chn = 0, node = driver->playback_ports; node; node = jack_slist_next (node), chn++) {
-
- port = (jack_port_t *)node->data;
-
- if (jack_port_connected (port) && (driver->outPortAudio != NULL)) {
- int channels = driver->playback_nchannels;
- float* out = driver->outPortAudio;
- buf = jack_port_get_buffer (port, nframes);
- for (i = 0; i< nframes; i++) out[channels*i+chn] = buf[i];
- }
+
+ port = (jack_port_t*)node->data;
+
+ if (jack_port_connected (port) && (driver->outPortAudio != NULL)) {
+ int channels = driver->playback_nchannels;
+ float* out = driver->outPortAudio;
+ buf = jack_port_get_buffer (port, nframes);
+ for (i = 0; i < nframes; i++) out[channels * i + chn] = buf[i];
+ }
}
-
+
return 0;
}
static int
portaudio_driver_audio_start (portaudio_driver_t *driver)
{
- PaError err = Pa_StartStream(driver->stream);
+ PaError err = Pa_StartStream (driver->stream);
+
return (err != paNoError) ? -1 : 0;
}
static int
portaudio_driver_audio_stop (portaudio_driver_t *driver)
{
- PaError err = Pa_StopStream(driver->stream);
+ PaError err = Pa_StopStream (driver->stream);
+
return (err != paNoError) ? -1 : 0;
}
static int
portaudio_driver_set_parameters (portaudio_driver_t* driver,
- jack_nframes_t nframes,
- jack_nframes_t rate)
+ jack_nframes_t nframes,
+ jack_nframes_t rate)
{
int capturing = driver->capturing;
int playing = driver->playing;
- int err = Pa_OpenStream(
+ int err = Pa_OpenStream (
&driver->stream,
- ((capturing) ? Pa_GetDefaultInputDeviceID() : paNoDevice),
- ((capturing) ? driver->capture_nchannels : 0),
- paFloat32, /* 32-bit float input */
+ ((capturing) ? Pa_GetDefaultInputDeviceID () : paNoDevice),
+ ((capturing) ? driver->capture_nchannels : 0),
+ paFloat32, /* 32-bit float input */
NULL,
- ((playing) ? Pa_GetDefaultOutputDeviceID() : paNoDevice),
- ((playing) ? driver->playback_nchannels : 0),
- paFloat32, /* 32-bit float output */
+ ((playing) ? Pa_GetDefaultOutputDeviceID () : paNoDevice),
+ ((playing) ? driver->playback_nchannels : 0),
+ paFloat32, /* 32-bit float output */
NULL,
- rate, /* sample rate */
- nframes, /* frames per buffer */
- 0, /* number of buffers = default min */
- paClipOff, /* we won't output out of
- * range samples so don't
- * bother clipping them */
+ rate, /* sample rate */
+ nframes, /* frames per buffer */
+ 0, /* number of buffers = default min */
+ paClipOff, /* we won't output out of
+ * range samples so don't
+ * bother clipping them */
paCallback,
driver);
-
+
if (err == paNoError) {
-
- driver->period_usecs = (((float) driver->frames_per_cycle)
+
+ driver->period_usecs = (((float)driver->frames_per_cycle)
/ driver->frame_rate) * 1000000.0f;
driver->frame_rate = rate;
driver->frames_per_cycle = nframes;
@@ -334,17 +336,17 @@ portaudio_driver_set_parameters (portaudio_driver_t* driver,
jack_error ("portaudio: cannot set engine buffer size to %d (check MIDI)", driver->frames_per_cycle);
return -1;
}
-
+
}
return 0;
- } else {
+ } else {
// JOQ: this driver is dead. How do we terminate it?
- Pa_Terminate();
- jack_error("Unable to set portaudio parameters");
- jack_error("Error number: %d", err);
- jack_error("Error message: %s", Pa_GetErrorText(err));
+ Pa_Terminate ();
+ jack_error ("Unable to set portaudio parameters");
+ jack_error ("Error number: %d", err);
+ jack_error ("Error message: %s", Pa_GetErrorText (err));
return EIO;
}
}
@@ -354,13 +356,13 @@ portaudio_driver_reset_parameters (portaudio_driver_t* driver,
jack_nframes_t nframes,
jack_nframes_t rate)
{
- if (!jack_power_of_two(nframes)) {
- jack_error("PA: frames must be a power of two "
- "(64, 512, 1024, ...)");
+ if (!jack_power_of_two (nframes)) {
+ jack_error ("PA: frames must be a power of two "
+ "(64, 512, 1024, ...)");
return EINVAL;
}
- Pa_CloseStream(driver->stream);
+ Pa_CloseStream (driver->stream);
return portaudio_driver_set_parameters (driver, nframes, rate);
}
@@ -391,166 +393,190 @@ portaudio_driver_bufsize (portaudio_driver_t* driver, jack_nframes_t nframes)
//== instance creation/destruction =============================================
-static int portaudio_load_default (portaudio_driver_t *driver,
- int numDevices,
- int capturing,
- int playing,
- int* inputDeviceID,
- int* outputDeviceID)
+static int portaudio_load_default (portaudio_driver_t *driver,
+ int numDevices,
+ int capturing,
+ int playing,
+ int* inputDeviceID,
+ int* outputDeviceID)
{
- const PaDeviceInfo *pdi;
- int i,j;
- int found = 0;
-
- PALog("Look for default driver\n");
-
- *inputDeviceID = Pa_GetDefaultInputDeviceID();
- *outputDeviceID = Pa_GetDefaultOutputDeviceID();
-
- for(i=0; i<numDevices; i++)
- {
- pdi = Pa_GetDeviceInfo(i);
- PALog("---------------------------------------------- #%d\n", i);
-
- if (i == Pa_GetDefaultInputDeviceID()) {
- driver->capture_nchannels = (capturing) ? pdi->maxInputChannels : 0;
- strcpy (driver->driver_name,pdi->name);
- found = 1;
- }
-
- if (i == Pa_GetDefaultOutputDeviceID()){
- driver->playback_nchannels = (playing) ? pdi->maxOutputChannels : 0;
- strcpy (driver->driver_name,pdi->name);
- found = 1;
- }
-
- PALog("\nName = %s\n", pdi->name);
- PALog("Max Inputs = %d ", pdi->maxInputChannels);
- PALog("Max Outputs = %d\n", pdi->maxOutputChannels);
- if( pdi->numSampleRates == -1 ){
- PALog("Sample Rate Range = %f to %f\n", pdi->sampleRates[0], pdi->sampleRates[1]);
- }else{
- PALog("Sample Rates =");
- for(j=0; j<pdi->numSampleRates; j++){
- PALog(" %8.2f,", pdi->sampleRates[j]);
- }
- PALog("\n");
- }
-
- PALog("Native Sample Formats = ");
- if (pdi->nativeSampleFormats & paInt8) PALog("paInt8, ");
- if (pdi->nativeSampleFormats & paUInt8) PALog("paUInt8, ");
- if (pdi->nativeSampleFormats & paInt16) PALog("paInt16, ");
- if (pdi->nativeSampleFormats & paInt32) PALog("paInt32, ");
- if (pdi->nativeSampleFormats & paFloat32) PALog("paFloat32, ");
- if (pdi->nativeSampleFormats & paInt24) PALog("paInt24, ");
- if (pdi->nativeSampleFormats & paPackedInt24) PALog("paPackedInt24, ");
- PALog("\n");
- }
-
- return found;
+ const PaDeviceInfo *pdi;
+ int i, j;
+ int found = 0;
+
+ PALog ("Look for default driver\n");
+
+ *inputDeviceID = Pa_GetDefaultInputDeviceID ();
+ *outputDeviceID = Pa_GetDefaultOutputDeviceID ();
+
+ for (i = 0; i < numDevices; i++) {
+ pdi = Pa_GetDeviceInfo (i);
+ PALog ("---------------------------------------------- #%d\n", i);
+
+ if (i == Pa_GetDefaultInputDeviceID ()) {
+ driver->capture_nchannels = (capturing) ? pdi->maxInputChannels : 0;
+ strcpy (driver->driver_name, pdi->name);
+ found = 1;
+ }
+
+ if (i == Pa_GetDefaultOutputDeviceID ()) {
+ driver->playback_nchannels = (playing) ? pdi->maxOutputChannels : 0;
+ strcpy (driver->driver_name, pdi->name);
+ found = 1;
+ }
+
+ PALog ("\nName = %s\n", pdi->name);
+ PALog ("Max Inputs = %d ", pdi->maxInputChannels);
+ PALog ("Max Outputs = %d\n", pdi->maxOutputChannels);
+ if ( pdi->numSampleRates == -1 ) {
+ PALog ("Sample Rate Range = %f to %f\n", pdi->sampleRates[0], pdi->sampleRates[1]);
+ } else {
+ PALog ("Sample Rates =");
+ for (j = 0; j < pdi->numSampleRates; j++)
+ PALog (" %8.2f,", pdi->sampleRates[j]);
+ PALog ("\n");
+ }
+
+ PALog ("Native Sample Formats = ");
+ if (pdi->nativeSampleFormats & paInt8) {
+ PALog ("paInt8, ");
+ }
+ if (pdi->nativeSampleFormats & paUInt8) {
+ PALog ("paUInt8, ");
+ }
+ if (pdi->nativeSampleFormats & paInt16) {
+ PALog ("paInt16, ");
+ }
+ if (pdi->nativeSampleFormats & paInt32) {
+ PALog ("paInt32, ");
+ }
+ if (pdi->nativeSampleFormats & paFloat32) {
+ PALog ("paFloat32, ");
+ }
+ if (pdi->nativeSampleFormats & paInt24) {
+ PALog ("paInt24, ");
+ }
+ if (pdi->nativeSampleFormats & paPackedInt24) {
+ PALog ("paPackedInt24, ");
+ }
+ PALog ("\n");
+ }
+
+ return found;
}
-static int portaudio_load_driver (portaudio_driver_t *driver,
- int numDevices,
- int capturing,
- int playing,
- int* inputDeviceID,
- int* outputDeviceID,
- char* driver_name)
+static int portaudio_load_driver (portaudio_driver_t *driver,
+ int numDevices,
+ int capturing,
+ int playing,
+ int* inputDeviceID,
+ int* outputDeviceID,
+ char* driver_name)
{
- const PaDeviceInfo *pdi;
- int found = 0;
- int i,j;
-
- PALog("Look for %s driver\n",driver_name);
-
- for(i=0; i<numDevices; i++)
- {
- pdi = Pa_GetDeviceInfo(i);
- PALog("---------------------------------------------- #%d\n", i);
-
+ const PaDeviceInfo *pdi;
+ int found = 0;
+ int i, j;
+
+ PALog ("Look for %s driver\n", driver_name);
+
+ for (i = 0; i < numDevices; i++) {
+ pdi = Pa_GetDeviceInfo (i);
+ PALog ("---------------------------------------------- #%d\n", i);
+
// compare the first character
if (strncmp (driver_name, pdi->name,
- JACK_DRIVER_PARAM_STRING_MAX) == 0) {
- if (pdi->maxInputChannels > 0) {
- *inputDeviceID = i;
- driver->capture_nchannels =
- (capturing) ? pdi->maxInputChannels : 0;
- strcpy(driver->driver_name,pdi->name);
- PALog("Found input driver = %s\n", driver_name);
- found = 1;
+ JACK_DRIVER_PARAM_STRING_MAX) == 0) {
+ if (pdi->maxInputChannels > 0) {
+ *inputDeviceID = i;
+ driver->capture_nchannels =
+ (capturing) ? pdi->maxInputChannels : 0;
+ strcpy (driver->driver_name, pdi->name);
+ PALog ("Found input driver = %s\n", driver_name);
+ found = 1;
+ }
+ if (pdi->maxOutputChannels > 0) {
+ *outputDeviceID = i;
+ driver->playback_nchannels =
+ (playing) ? pdi->maxOutputChannels : 0;
+ strcpy (driver->driver_name, pdi->name);
+ PALog ("Found output driver = %s\n", driver_name);
+ found = 1;
+ } else {
+ PALog ("Found driver without input or ouput = %s\n",
+ driver_name);
+ }
}
- if (pdi->maxOutputChannels > 0) {
- *outputDeviceID = i;
- driver->playback_nchannels =
- (playing) ? pdi->maxOutputChannels : 0;
- strcpy (driver->driver_name,pdi->name);
- PALog("Found output driver = %s\n", driver_name);
- found = 1;
+
+ PALog ("\nName = %s\n", pdi->name);
+ PALog ("Max Inputs = %d ", pdi->maxInputChannels);
+ PALog ("Max Outputs = %d\n", pdi->maxOutputChannels);
+ if ( pdi->numSampleRates == -1 ) {
+ PALog ("Sample Rate Range = %f to %f\n", pdi->sampleRates[0],
+ pdi->sampleRates[1]);
} else {
- PALog("Found driver without input or ouput = %s\n",
- driver_name);
- }
- }
-
- PALog("\nName = %s\n", pdi->name);
- PALog("Max Inputs = %d ", pdi->maxInputChannels);
- PALog("Max Outputs = %d\n", pdi->maxOutputChannels);
- if( pdi->numSampleRates == -1 ){
- PALog("Sample Rate Range = %f to %f\n", pdi->sampleRates[0],
- pdi->sampleRates[1]);
- }else{
- PALog("Sample Rates =");
- for(j=0; j<pdi->numSampleRates; j++){
- PALog(" %8.2f,", pdi->sampleRates[j]);
- }
- PALog("\n");
- }
-
- PALog("Native Sample Formats = ");
- if (pdi->nativeSampleFormats & paInt8) PALog("paInt8, ");
- if (pdi->nativeSampleFormats & paUInt8) PALog("paUInt8, ");
- if (pdi->nativeSampleFormats & paInt16) PALog("paInt16, ");
- if (pdi->nativeSampleFormats & paInt32) PALog("paInt32, ");
- if (pdi->nativeSampleFormats & paFloat32) PALog("paFloat32, ");
- if (pdi->nativeSampleFormats & paInt24) PALog("paInt24, ");
- if (pdi->nativeSampleFormats & paPackedInt24) PALog("paPackedInt24, ");
- PALog("\n");
- }
-
- return found;
+ PALog ("Sample Rates =");
+ for (j = 0; j < pdi->numSampleRates; j++)
+ PALog (" %8.2f,", pdi->sampleRates[j]);
+ PALog ("\n");
+ }
+
+ PALog ("Native Sample Formats = ");
+ if (pdi->nativeSampleFormats & paInt8) {
+ PALog ("paInt8, ");
+ }
+ if (pdi->nativeSampleFormats & paUInt8) {
+ PALog ("paUInt8, ");
+ }
+ if (pdi->nativeSampleFormats & paInt16) {
+ PALog ("paInt16, ");
+ }
+ if (pdi->nativeSampleFormats & paInt32) {
+ PALog ("paInt32, ");
+ }
+ if (pdi->nativeSampleFormats & paFloat32) {
+ PALog ("paFloat32, ");
+ }
+ if (pdi->nativeSampleFormats & paInt24) {
+ PALog ("paInt24, ");
+ }
+ if (pdi->nativeSampleFormats & paPackedInt24) {
+ PALog ("paPackedInt24, ");
+ }
+ PALog ("\n");
+ }
+
+ return found;
}
/** create a new driver instance
*/
static jack_driver_t *
-portaudio_driver_new (char *name,
- jack_client_t* client,
- jack_nframes_t frames_per_cycle,
- jack_nframes_t rate,
- int capturing,
- int playing,
- int chan_in,
- int chan_out,
- DitherAlgorithm dither,
- char* driver_name)
+portaudio_driver_new (char *name,
+ jack_client_t* client,
+ jack_nframes_t frames_per_cycle,
+ jack_nframes_t rate,
+ int capturing,
+ int playing,
+ int chan_in,
+ int chan_out,
+ DitherAlgorithm dither,
+ char* driver_name)
{
portaudio_driver_t *driver;
PaError err = paNoError;
int numDevices;
- int inputDeviceID,outputDeviceID;
+ int inputDeviceID, outputDeviceID;
int found;
-
- PALog("portaudio driver version : %d\n", kVersion);
- PALog("creating portaudio driver ... %" PRIu32 "|%" PRIu32 "\n",
- frames_per_cycle, rate);
- driver = (portaudio_driver_t *) calloc (1, sizeof (portaudio_driver_t));
+ PALog ("portaudio driver version : %d\n", kVersion);
+ PALog ("creating portaudio driver ... %" PRIu32 "|%" PRIu32 "\n",
+ frames_per_cycle, rate);
+
+ driver = (portaudio_driver_t*)calloc (1, sizeof(portaudio_driver_t));
- jack_driver_init ((jack_driver_t *) driver);
+ jack_driver_init ((jack_driver_t*)driver);
- if (!jack_power_of_two(frames_per_cycle)) {
+ if (!jack_power_of_two (frames_per_cycle)) {
jack_error ("PA: -p must be a power of two.");
goto error;
}
@@ -560,113 +586,123 @@ portaudio_driver_new (char *name,
driver->capturing = capturing;
driver->playing = playing;
- driver->attach = (JackDriverAttachFunction) portaudio_driver_attach;
- driver->detach = (JackDriverDetachFunction) portaudio_driver_detach;
- driver->read = (JackDriverReadFunction) portaudio_driver_read;
- driver->write = (JackDriverReadFunction) portaudio_driver_write;
- driver->null_cycle = (JackDriverNullCycleFunction) portaudio_driver_null_cycle;
- driver->bufsize = (JackDriverBufSizeFunction) portaudio_driver_bufsize;
- driver->start = (JackDriverStartFunction) portaudio_driver_audio_start;
- driver->stop = (JackDriverStopFunction) portaudio_driver_audio_stop;
+ driver->attach = (JackDriverAttachFunction)portaudio_driver_attach;
+ driver->detach = (JackDriverDetachFunction)portaudio_driver_detach;
+ driver->read = (JackDriverReadFunction)portaudio_driver_read;
+ driver->write = (JackDriverReadFunction)portaudio_driver_write;
+ driver->null_cycle = (JackDriverNullCycleFunction)portaudio_driver_null_cycle;
+ driver->bufsize = (JackDriverBufSizeFunction)portaudio_driver_bufsize;
+ driver->start = (JackDriverStartFunction)portaudio_driver_audio_start;
+ driver->stop = (JackDriverStopFunction)portaudio_driver_audio_stop;
driver->stream = NULL;
-#ifdef JACK_USE_MACH_THREADS
+#ifdef JACK_USE_MACH_THREADS
AudioDeviceID device_id;
if (driver_name) {
- if (get_device_id_from_uid(driver_name, &device_id) != noErr)
+ if (get_device_id_from_uid (driver_name, &device_id) != noErr) {
goto error;
- if (get_device_name_from_id(device_id, driver->driver_name) != noErr)
+ }
+ if (get_device_name_from_id (device_id, driver->driver_name) != noErr) {
goto error;
+ }
} else {
- if (get_device_id_from_num(0, &device_id) != noErr)
- goto error;
- if (get_device_name_from_id(device_id, driver->driver_name) != noErr)
+ if (get_device_id_from_num (0, &device_id) != noErr) {
+ goto error;
+ }
+ if (get_device_name_from_id (device_id, driver->driver_name) != noErr) {
goto error;
+ }
}
#endif
-
- err = Pa_Initialize();
- PALog("Pa_Initialize OK \n");
-
- PALog("Driver name required %s\n",driver->driver_name);
- numDevices = Pa_CountDevices();
-
- if( numDevices < 0 ){
- PALog("ERROR: Pa_CountDevices returned 0x%x\n", numDevices);
+
+ err = Pa_Initialize ();
+ PALog ("Pa_Initialize OK \n");
+
+ PALog ("Driver name required %s\n", driver->driver_name);
+ numDevices = Pa_CountDevices ();
+
+ if ( numDevices < 0 ) {
+ PALog ("ERROR: Pa_CountDevices returned 0x%x\n", numDevices);
err = numDevices;
goto error;
}
-
- PALog("Number of devices = %d\n", numDevices);
- if (strcmp(driver->driver_name,"") == 0) {
- found = portaudio_load_default(driver,numDevices,capturing,playing,&inputDeviceID,&outputDeviceID);
+ PALog ("Number of devices = %d\n", numDevices);
+
+ if (strcmp (driver->driver_name, "") == 0) {
+ found = portaudio_load_default (driver, numDevices, capturing, playing, &inputDeviceID, &outputDeviceID);
if (!found) {
- PALog("ERROR : default driver has not been found\n");
+ PALog ("ERROR : default driver has not been found\n");
err = paHostError;
goto error;
}
- }else{
- found = portaudio_load_driver(driver,numDevices,capturing,playing,&inputDeviceID,&outputDeviceID,driver->driver_name);
+ } else {
+ found = portaudio_load_driver (driver, numDevices, capturing, playing, &inputDeviceID, &outputDeviceID, driver->driver_name);
if (!found) {
- PALog("ERROR : driver %s has not been found \n",driver->driver_name);
- err = paHostError;
- goto error;
+ PALog ("ERROR : driver %s has not been found \n", driver->driver_name);
+ err = paHostError;
+ goto error;
}
}
- if (err != paNoError) goto error;
-
- PALog("Pa_GetDefaultOutputDeviceID() %ld\n", (long)Pa_GetDefaultOutputDeviceID());
- PALog("Pa_GetDefaultInputDeviceID() %ld\n", (long)Pa_GetDefaultInputDeviceID());
-
- PALog("--------------------------------------------------\n");
- PALog("CoreAudio driver %s will be loaded\n", driver->driver_name);
- PALog("inputDeviceID %ld\n", (long)inputDeviceID);
- PALog("outputDeviceID %ld\n", (long)outputDeviceID);
- PALog("driver->capture_nchannels %ld\n", driver->capture_nchannels);
- PALog("driver->playback_nchannels %ld\n", driver->playback_nchannels);
-
- PALog("chan_in, chan_out %ld %ld\n", (long)chan_in, (long)chan_out);
-
- if (chan_in > 0)
+ if (err != paNoError) {
+ goto error;
+ }
+
+ PALog ("Pa_GetDefaultOutputDeviceID() %ld\n", (long)Pa_GetDefaultOutputDeviceID ());
+ PALog ("Pa_GetDefaultInputDeviceID() %ld\n", (long)Pa_GetDefaultInputDeviceID ());
+
+ PALog ("--------------------------------------------------\n");
+ PALog ("CoreAudio driver %s will be loaded\n", driver->driver_name);
+ PALog ("inputDeviceID %ld\n", (long)inputDeviceID);
+ PALog ("outputDeviceID %ld\n", (long)outputDeviceID);
+ PALog ("driver->capture_nchannels %ld\n", driver->capture_nchannels);
+ PALog ("driver->playback_nchannels %ld\n", driver->playback_nchannels);
+
+ PALog ("chan_in, chan_out %ld %ld\n", (long)chan_in, (long)chan_out);
+
+ if (chan_in > 0) {
driver->capture_nchannels = (driver->capture_nchannels < chan_in) ? driver->capture_nchannels : chan_in;
-
- if (chan_out > 0)
+ }
+
+ if (chan_out > 0) {
driver->playback_nchannels = (driver->playback_nchannels < chan_out) ? driver->playback_nchannels : chan_out;
-
- PALog("driver->capture_nchannels %ld\n", driver->capture_nchannels);
- PALog("driver->playback_nchannels %ld\n", driver->playback_nchannels);
-
- err = Pa_OpenStream(&driver->stream,
- ((capturing && (driver->capture_nchannels > 0)) ? inputDeviceID : paNoDevice),
- ((capturing) ? driver->capture_nchannels : 0),
- paFloat32, // 32 bit floating point input
- NULL,
- ((playing && (driver->playback_nchannels > 0)) ? outputDeviceID : paNoDevice),
- ((playing) ? driver->playback_nchannels : 0),
- paFloat32, // 32 bit floating point output
- NULL,
- rate,
- frames_per_cycle, // frames per buffer
- 0, // number of buffers, if zero then use default minimum
- paClipOff, // we won't output out of range samples so don't bother clipping them
- paCallback,
- driver);
-
- if (err != paNoError) goto error;
-
- driver->client = client;
- driver->period_usecs = (((float) driver->frames_per_cycle) / driver->frame_rate) * 1000000.0f;
- return((jack_driver_t *) driver);
+ }
+
+ PALog ("driver->capture_nchannels %ld\n", driver->capture_nchannels);
+ PALog ("driver->playback_nchannels %ld\n", driver->playback_nchannels);
+
+ err = Pa_OpenStream (&driver->stream,
+ ((capturing && (driver->capture_nchannels > 0)) ? inputDeviceID : paNoDevice),
+ ((capturing) ? driver->capture_nchannels : 0),
+ paFloat32, // 32 bit floating point input
+ NULL,
+ ((playing && (driver->playback_nchannels > 0)) ? outputDeviceID : paNoDevice),
+ ((playing) ? driver->playback_nchannels : 0),
+ paFloat32, // 32 bit floating point output
+ NULL,
+ rate,
+ frames_per_cycle, // frames per buffer
+ 0, // number of buffers, if zero then use default minimum
+ paClipOff, // we won't output out of range samples so don't bother clipping them
+ paCallback,
+ driver);
+
+ if (err != paNoError) {
+ goto error;
+ }
+
+ driver->client = client;
+ driver->period_usecs = (((float)driver->frames_per_cycle) / driver->frame_rate) * 1000000.0f;
+ return (jack_driver_t*)driver;
error:
- Pa_Terminate();
- jack_error("An error occured while using the portaudio stream");
- jack_error("Error number: %d", err);
- jack_error("Error message: %s", Pa_GetErrorText(err));
- free(driver);
+ Pa_Terminate ();
+ jack_error ("An error occured while using the portaudio stream");
+ jack_error ("Error number: %d", err);
+ jack_error ("Error message: %s", Pa_GetErrorText (err));
+ free (driver);
return NULL;
}
@@ -676,9 +712,9 @@ static void
portaudio_driver_delete (portaudio_driver_t *driver)
{
/* Close PortAudio stream and terminate */
- Pa_CloseStream(driver->stream);
- Pa_Terminate();
- free(driver);
+ Pa_CloseStream (driver->stream);
+ Pa_Terminate ();
+ free (driver);
}
//== driver "plugin" interface =================================================
@@ -690,12 +726,13 @@ driver_get_descriptor ()
{
jack_driver_desc_t * desc;
unsigned int i;
- desc = calloc (1, sizeof (jack_driver_desc_t));
+
+ desc = calloc (1, sizeof(jack_driver_desc_t));
strcpy (desc->name, "portaudio");
desc->nparams = 10;
desc->params = calloc (desc->nparams,
- sizeof (jack_driver_param_desc_t));
+ sizeof(jack_driver_param_desc_t));
i = 0;
strcpy (desc->params[i].name, "channel");
@@ -704,7 +741,7 @@ driver_get_descriptor ()
desc->params[i].value.ui = 0;
strcpy (desc->params[i].short_desc, "Maximum number of channels");
strcpy (desc->params[i].long_desc, desc->params[i].short_desc);
-
+
i++;
strcpy (desc->params[i].name, "channelin");
desc->params[i].character = 'i';
@@ -760,7 +797,7 @@ driver_get_descriptor ()
desc->params[i].value.ui = 1024U;
strcpy (desc->params[i].short_desc, "Frames per period");
strcpy (desc->params[i].long_desc, desc->params[i].short_desc);
-
+
i++;
strcpy (desc->params[i].name, "name");
desc->params[i].character = 'n';
@@ -781,8 +818,8 @@ driver_get_descriptor ()
" t : triangular\n"
" s : shaped\n"
" - : no dithering");
-
- return desc;
+
+ return desc;
}
const char driver_client_name[] = "portaudio";
@@ -802,42 +839,42 @@ driver_initialize (jack_client_t *client, const JSList * params)
const jack_driver_param_t * param;
char *name = NULL;
-#ifdef JACK_USE_MACH_THREADS
- get_device_id_from_num(0,&deviceID); // takes a default value (first device)
+#ifdef JACK_USE_MACH_THREADS
+ get_device_id_from_num (0, &deviceID); // takes a default value (first device)
#endif
-
+
for (node = params; node; node = jack_slist_next (node)) {
- param = (const jack_driver_param_t *) node->data;
+ param = (const jack_driver_param_t*)node->data;
switch (param->character) {
-
+
case 'n':
- name = (char *) param->value.str;
- PALog("Driver name found %s\n",name);
+ name = (char*)param->value.str;
+ PALog ("Driver name found %s\n", name);
break;
-
+
case 'D':
capture = TRUE;
playback = TRUE;
break;
-
+
case 'c':
- chan_in = (int) param->value.ui;
- chan_out = (int) param->value.ui;
+ chan_in = (int)param->value.ui;
+ chan_out = (int)param->value.ui;
break;
-
+
case 'i':
- chan_in = (int) param->value.ui;
+ chan_in = (int)param->value.ui;
break;
-
+
case 'o':
- chan_out = (int) param->value.ui;
+ chan_out = (int)param->value.ui;
break;
-
+
case 'C':
capture = param->value.i;
break;
-
+
case 'P':
playback = param->value.i;
break;
@@ -845,25 +882,25 @@ driver_initialize (jack_client_t *client, const JSList * params)
case 'r':
srate = param->value.ui;
break;
-
+
case 'p':
- frames_per_interrupt = (unsigned int) param->value.ui;
+ frames_per_interrupt = (unsigned int)param->value.ui;
break;
-
+
case 'z':
- switch ((int) param->value.c) {
+ switch ((int)param->value.c) {
case '-':
dither = None;
break;
-
+
case 'r':
dither = Rectangular;
break;
-
+
case 's':
dither = Shaped;
break;
-
+
case 't':
default:
dither = Triangular;
@@ -887,6 +924,6 @@ driver_initialize (jack_client_t *client, const JSList * params)
void
driver_finish (jack_driver_t *driver)
{
- portaudio_driver_delete ((portaudio_driver_t *) driver);
+ portaudio_driver_delete ((portaudio_driver_t*)driver);
}
diff --git a/drivers/portaudio/portaudio_driver.h b/drivers/portaudio/portaudio_driver.h
index 55df853..778f4f6 100644
--- a/drivers/portaudio/portaudio_driver.h
+++ b/drivers/portaudio/portaudio_driver.h
@@ -14,10 +14,10 @@
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.
-
+
Grame Research Laboratory, 9, rue du Garet 69001 Lyon - France
grame@rd.grame.fr
-*/
+ */
#ifndef __jack_portaudio_driver_h__
#define __jack_portaudio_driver_h__
@@ -35,27 +35,27 @@
typedef struct {
- JACK_DRIVER_DECL
+ JACK_DRIVER_DECL
- struct _jack_engine *engine;
+ struct _jack_engine *engine;
- jack_nframes_t frame_rate;
- jack_nframes_t frames_per_cycle;
- unsigned long user_nperiods;
- int capturing;
- int playing;
+ jack_nframes_t frame_rate;
+ jack_nframes_t frames_per_cycle;
+ unsigned long user_nperiods;
+ int capturing;
+ int playing;
- channel_t playback_nchannels;
- channel_t capture_nchannels;
+ channel_t playback_nchannels;
+ channel_t capture_nchannels;
- jack_client_t *client;
- JSList *capture_ports;
- JSList *playback_ports;
+ jack_client_t *client;
+ JSList *capture_ports;
+ JSList *playback_ports;
- float *inPortAudio;
- float *outPortAudio;
- char driver_name[256];
- PortAudioStream* stream;
+ float *inPortAudio;
+ float *outPortAudio;
+ char driver_name[256];
+ PortAudioStream* stream;
} portaudio_driver_t;
diff --git a/drivers/sun/sun_driver.c b/drivers/sun/sun_driver.c
index 1d1af3e..accb620 100644
--- a/drivers/sun/sun_driver.c
+++ b/drivers/sun/sun_driver.c
@@ -1,27 +1,27 @@
/*
- Sun Audio API driver for Jack
- Copyright (C) 2008 Jacob Meuser <jakemsr@sdf.lonestar.org>
- Based heavily on oss_driver.c which came with the following
- copyright notice.
+ Sun Audio API driver for Jack
+ Copyright (C) 2008 Jacob Meuser <jakemsr@sdf.lonestar.org>
+ Based heavily on oss_driver.c which came with the following
+ copyright notice.
- Copyright (C) 2003-2007 Jussi Laako <jussi@sonarnerd.net>
+ Copyright (C) 2003-2007 Jussi Laako <jussi@sonarnerd.net>
- 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 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.
+ 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., 59 Temple Place, Suite 330, Boston,
- MA 02111-1307 USA
+ 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., 59 Temple Place, Suite 330, Boston,
+ MA 02111-1307 USA
-*/
+ */
#include <config.h>
@@ -60,85 +60,74 @@
#include "sun_driver.h"
-#define SUN_DRIVER_N_PARAMS 11
+#define SUN_DRIVER_N_PARAMS 11
const static jack_driver_param_desc_t sun_params[SUN_DRIVER_N_PARAMS] = {
{ "rate",
- 'r',
- JackDriverParamUInt,
- { .ui = SUN_DRIVER_DEF_FS },
- "sample rate",
- "sample rate"
- },
+ 'r',
+ JackDriverParamUInt,
+ { .ui = SUN_DRIVER_DEF_FS },
+ "sample rate",
+ "sample rate" },
{ "period",
- 'p',
- JackDriverParamUInt,
- { .ui = SUN_DRIVER_DEF_BLKSIZE },
- "period size",
- "period size"
- },
+ 'p',
+ JackDriverParamUInt,
+ { .ui = SUN_DRIVER_DEF_BLKSIZE },
+ "period size",
+ "period size" },
{ "nperiods",
- 'n',
- JackDriverParamUInt,
- { .ui = SUN_DRIVER_DEF_NPERIODS },
- "number of periods in buffer",
- "number of periods in buffer"
- },
+ 'n',
+ JackDriverParamUInt,
+ { .ui = SUN_DRIVER_DEF_NPERIODS },
+ "number of periods in buffer",
+ "number of periods in buffer" },
{ "wordlength",
- 'w',
- JackDriverParamInt,
- { .i = SUN_DRIVER_DEF_BITS },
- "word length",
- "word length"
- },
+ 'w',
+ JackDriverParamInt,
+ { .i = SUN_DRIVER_DEF_BITS },
+ "word length",
+ "word length" },
{ "inchannels",
- 'i',
- JackDriverParamUInt,
- { .ui = SUN_DRIVER_DEF_INS },
- "capture channels",
- "capture channels"
- },
+ 'i',
+ JackDriverParamUInt,
+ { .ui = SUN_DRIVER_DEF_INS },
+ "capture channels",
+ "capture channels" },
{ "outchannels",
- 'o',
- JackDriverParamUInt,
- { .ui = SUN_DRIVER_DEF_OUTS },
- "playback channels",
- "playback channels"
- },
+ 'o',
+ JackDriverParamUInt,
+ { .ui = SUN_DRIVER_DEF_OUTS },
+ "playback channels",
+ "playback channels" },
{ "capture",
- 'C',
- JackDriverParamString,
- { .str = SUN_DRIVER_DEF_DEV },
- "input device",
- "input device"
- },
+ 'C',
+ JackDriverParamString,
+ { .str = SUN_DRIVER_DEF_DEV },
+ "input device",
+ "input device" },
{ "playback",
- 'P',
- JackDriverParamString,
- { .str = SUN_DRIVER_DEF_DEV },
- "output device",
- "output device"
- },
+ 'P',
+ JackDriverParamString,
+ { .str = SUN_DRIVER_DEF_DEV },
+ "output device",
+ "output device" },
{ "ignorehwbuf",
- 'b',
- JackDriverParamBool,
- { },
- "ignore hardware period size",
- "ignore hardware period size"
- },
+ 'b',
+ JackDriverParamBool,
+ { },
+ "ignore hardware period size",
+ "ignore hardware period size" },
{ "input latency",
- 'I',
- JackDriverParamUInt,
- { .ui = 0 },
- "system input latency",
- "system input latency"
- },
+ 'I',
+ JackDriverParamUInt,
+ { .ui = 0 },
+ "system input latency",
+ "system input latency" },
{ "output latency",
- 'O',
- JackDriverParamUInt,
- { .ui = 0 },
- "system output latency",
- "system output latency"
- }
+ 'O',
+ JackDriverParamUInt,
+ { .ui = 0 },
+ "system output latency",
+ "system output latency" }
};
@@ -150,9 +139,9 @@ set_period_size (sun_driver_t *driver, jack_nframes_t new_period_size)
{
driver->period_size = new_period_size;
- driver->period_usecs =
- ((double) driver->period_size /
- (double) driver->sample_rate) * 1e6;
+ driver->period_usecs =
+ ((double)driver->period_size /
+ (double)driver->sample_rate) * 1e6;
driver->last_wait_ust = 0;
driver->iodelay = 0.0F;
driver->poll_timeout = (int)(driver->period_usecs / 666);
@@ -167,23 +156,21 @@ sun_driver_write_silence (sun_driver_t *driver, jack_nframes_t nframes)
void *localbuf;
localsize = nframes * driver->sample_bytes * driver->playback_channels;
- localbuf = malloc(localsize);
- if (localbuf == NULL)
- {
- jack_error("sun_driver: malloc() failed: %s@%i",
- __FILE__, __LINE__);
+ localbuf = malloc (localsize);
+ if (localbuf == NULL) {
+ jack_error ("sun_driver: malloc() failed: %s@%i",
+ __FILE__, __LINE__);
return;
}
- bzero(localbuf, localsize);
- io_res = write(driver->outfd, localbuf, localsize);
- if (io_res < (ssize_t) localsize)
- {
- jack_error("sun_driver: write() failed: %s: "
- "count=%d/%d: %s@%i", strerror(errno), io_res,
- localsize, __FILE__, __LINE__);
+ bzero (localbuf, localsize);
+ io_res = write (driver->outfd, localbuf, localsize);
+ if (io_res < (ssize_t)localsize) {
+ jack_error ("sun_driver: write() failed: %s: "
+ "count=%d/%d: %s@%i", strerror (errno), io_res,
+ localsize, __FILE__, __LINE__);
}
- free(localbuf);
+ free (localbuf);
}
@@ -195,22 +182,20 @@ sun_driver_read_silence (sun_driver_t *driver, jack_nframes_t nframes)
void *localbuf;
localsize = nframes * driver->sample_bytes * driver->capture_channels;
- localbuf = malloc(localsize);
- if (localbuf == NULL)
- {
- jack_error("sun_driver: malloc() failed: %s@%i",
- __FILE__, __LINE__);
+ localbuf = malloc (localsize);
+ if (localbuf == NULL) {
+ jack_error ("sun_driver: malloc() failed: %s@%i",
+ __FILE__, __LINE__);
return;
}
- io_res = read(driver->infd, localbuf, localsize);
- if (io_res < (ssize_t) localsize)
- {
- jack_error("sun_driver: read() failed: %s: "
- "count=%d/%d: %s@%i", strerror(errno), io_res,
- localsize, __FILE__, __LINE__);
+ io_res = read (driver->infd, localbuf, localsize);
+ if (io_res < (ssize_t)localsize) {
+ jack_error ("sun_driver: read() failed: %s: "
+ "count=%d/%d: %s@%i", strerror (errno), io_res,
+ localsize, __FILE__, __LINE__);
}
- free(localbuf);
+ free (localbuf);
}
@@ -235,63 +220,60 @@ sun_driver_wait (sun_driver_t *driver, int *status, float *iodelay)
pfd[0].fd = driver->infd;
pfd[0].events = POLLIN;
- if (driver->infd >= 0)
+ if (driver->infd >= 0) {
need_capture = 1;
+ }
pfd[1].fd = driver->outfd;
pfd[1].events = POLLOUT;
- if (driver->outfd >= 0)
+ if (driver->outfd >= 0) {
need_playback = 1;
+ }
- poll_enter = driver->engine->get_microseconds();
- if (poll_enter > driver->poll_next)
- {
+ poll_enter = driver->engine->get_microseconds ();
+ if (poll_enter > driver->poll_next) {
/* late. don't count as wakeup delay. */
driver->poll_next = 0;
}
- while (need_capture || need_playback)
- {
- nfds = poll(pfd, 2, driver->poll_timeout);
+ while (need_capture || need_playback) {
+ nfds = poll (pfd, 2, driver->poll_timeout);
if ( nfds == -1 ||
- ((pfd[0].revents | pfd[1].revents) &
- (POLLERR | POLLHUP | POLLNVAL)) )
- {
- jack_error("sun_driver: poll() error: %s: %s@%i",
- strerror(errno), __FILE__, __LINE__);
+ ((pfd[0].revents | pfd[1].revents) &
+ (POLLERR | POLLHUP | POLLNVAL)) ) {
+ jack_error ("sun_driver: poll() error: %s: %s@%i",
+ strerror (errno), __FILE__, __LINE__);
*status = -3;
return 0;
}
- if (nfds == 0)
- {
- jack_error("sun_driver: poll() timeout: %s@%i",
- __FILE__, __LINE__);
+ if (nfds == 0) {
+ jack_error ("sun_driver: poll() timeout: %s@%i",
+ __FILE__, __LINE__);
*status = -5;
return 0;
}
- if (need_capture && (pfd[0].revents & POLLIN))
- {
+ if (need_capture && (pfd[0].revents & POLLIN)) {
need_capture = 0;
pfd[0].fd = -1;
}
- if (need_playback && (pfd[1].revents & POLLOUT))
- {
+ if (need_playback && (pfd[1].revents & POLLOUT)) {
need_playback = 0;
pfd[1].fd = -1;
}
}
- poll_ret = driver->engine->get_microseconds();
+ poll_ret = driver->engine->get_microseconds ();
- if (driver->poll_next && poll_ret > driver->poll_next)
+ if (driver->poll_next && poll_ret > driver->poll_next) {
*iodelay = poll_ret - driver->poll_next;
+ }
driver->poll_last = poll_ret;
driver->poll_next = poll_ret + driver->period_usecs;
- driver->engine->transport_cycle_start(driver->engine, poll_ret);
+ driver->engine->transport_cycle_start (driver->engine, poll_ret);
#if defined(AUDIO_RERROR) && defined(AUDIO_PERROR)
@@ -304,95 +286,82 @@ sun_driver_wait (sun_driver_t *driver, int *status, float *iodelay)
* before we can write enough playback data to catch up.
*/
- if (driver->infd >= 0)
- {
- if (ioctl(driver->infd, AUDIO_RERROR, &capture_errors) < 0)
- {
- jack_error("sun_driver: AUDIO_RERROR failed: %s: %s@%i",
- strerror(errno), __FILE__, __LINE__);
+ if (driver->infd >= 0) {
+ if (ioctl (driver->infd, AUDIO_RERROR, &capture_errors) < 0) {
+ jack_error ("sun_driver: AUDIO_RERROR failed: %s: %s@%i",
+ strerror (errno), __FILE__, __LINE__);
return 0;
}
capture_errors -= driver->capture_drops;
driver->capture_drops += capture_errors;
}
- if (capture_errors > 0)
- {
+ if (capture_errors > 0) {
delay = (capture_errors * 1000.0) / driver->sample_rate;
- printf("sun_driver: capture xrun of %d frames (%f msec)\n",
+ printf ("sun_driver: capture xrun of %d frames (%f msec)\n",
capture_errors, delay);
}
- if (driver->outfd >= 0)
- {
- if (ioctl(driver->outfd, AUDIO_PERROR, &playback_errors) < 0)
- {
- jack_error("sun_driver: AUDIO_PERROR failed: %s: %s@%i",
- strerror(errno), __FILE__, __LINE__);
+ if (driver->outfd >= 0) {
+ if (ioctl (driver->outfd, AUDIO_PERROR, &playback_errors) < 0) {
+ jack_error ("sun_driver: AUDIO_PERROR failed: %s: %s@%i",
+ strerror (errno), __FILE__, __LINE__);
return 0;
}
playback_errors -= driver->playback_drops;
driver->playback_drops += playback_errors;
}
- if (playback_errors > 0)
- {
+ if (playback_errors > 0) {
delay = (playback_errors * 1000.0) / driver->sample_rate;
- printf("sun_driver: playback xrun of %d frames (%f msec)\n",
+ printf ("sun_driver: playback xrun of %d frames (%f msec)\n",
playback_errors, delay);
}
if ((driver->outfd >= 0 && driver->infd >= 0) &&
- (capture_errors || playback_errors))
- {
- if (ioctl(driver->infd, AUDIO_GETINFO, &auinfo) < 0)
- {
- jack_error("sun_driver: AUDIO_GETINFO failed: %s: "
- "%s@%i", strerror(errno), __FILE__, __LINE__);
+ (capture_errors || playback_errors)) {
+ if (ioctl (driver->infd, AUDIO_GETINFO, &auinfo) < 0) {
+ jack_error ("sun_driver: AUDIO_GETINFO failed: %s: "
+ "%s@%i", strerror (errno), __FILE__, __LINE__);
return 0;
}
capture_seek = auinfo.record.seek;
- if (driver->infd == driver->outfd)
+ if (driver->infd == driver->outfd) {
playback_seek = auinfo.play.seek;
- else
- {
- if (ioctl(driver->outfd, AUDIO_GETINFO, &auinfo) < 0)
- {
- jack_error("sun_driver: AUDIO_GETINFO failed: "
- "%s: %s@%i", strerror(errno),
- __FILE__, __LINE__);
+ } else {
+ if (ioctl (driver->outfd, AUDIO_GETINFO, &auinfo) < 0) {
+ jack_error ("sun_driver: AUDIO_GETINFO failed: "
+ "%s: %s@%i", strerror (errno),
+ __FILE__, __LINE__);
return 0;
}
playback_seek = auinfo.play.seek;
}
capture_seek /= driver->capture_channels *
- driver->sample_bytes;
+ driver->sample_bytes;
playback_seek /= driver->playback_channels *
- driver->sample_bytes;
+ driver->sample_bytes;
if (playback_seek == driver->period_size &&
- capture_seek == driver->period_size &&
- playback_errors)
- {
+ capture_seek == driver->period_size &&
+ playback_errors) {
/* normally, 1 period in each buffer is exactly
* what we want, but if there was an error then
* we effectively have 0 periods in the playback
* buffer, because the period in the buffer will
* be used to catch up to realtime.
*/
- printf("sun_driver: writing %d frames of silence "
+ printf ("sun_driver: writing %d frames of silence "
"to correct I/O sync\n", driver->period_size);
- sun_driver_write_silence(driver, driver->period_size);
- }
- else if (capture_errors && playback_errors)
- {
+ sun_driver_write_silence (driver, driver->period_size);
+ } else if (capture_errors && playback_errors) {
/* serious delay. we've lost the ability to
* write capture_errors frames to catch up on
* playback.
*/
- printf("sun_driver: writing %d frames of silence "
+ printf ("sun_driver: writing %d frames of silence "
"to correct I/O sync\n", capture_errors);
- sun_driver_write_silence(driver, capture_errors);
+ sun_driver_write_silence (driver, capture_errors);
}
}
@@ -416,22 +385,19 @@ sun_driver_run_cycle (sun_driver_t *driver)
nframes = sun_driver_wait (driver, &wait_status, &iodelay);
- if (wait_status < 0)
- {
- switch (wait_status)
- {
+ if (wait_status < 0) {
+ switch (wait_status) {
case -3:
/* poll() error */
return -1;
case -5:
/* poll() timeout */
- now = driver->engine->get_microseconds();
- if (now > driver->poll_next)
- {
+ now = driver->engine->get_microseconds ();
+ if (now > driver->poll_next) {
iodelay = now - driver->poll_next;
driver->poll_next = now + driver->period_usecs;
- driver->engine->delay(driver->engine, iodelay);
- printf("sun_driver: iodelay = %f\n", iodelay);
+ driver->engine->delay (driver->engine, iodelay);
+ printf ("sun_driver: iodelay = %f\n", iodelay);
}
break;
default:
@@ -440,116 +406,106 @@ sun_driver_run_cycle (sun_driver_t *driver)
}
}
- return driver->engine->run_cycle(driver->engine, nframes, iodelay);
+ return driver->engine->run_cycle (driver->engine, nframes, iodelay);
}
static void
-copy_and_convert_in (jack_sample_t *dst, void *src,
- size_t nframes, int channel, int chcount, int bits)
+copy_and_convert_in (jack_sample_t *dst, void *src,
+ size_t nframes, int channel, int chcount, int bits)
{
int srcidx;
int dstidx;
- signed short *s16src = (signed short *) src;
- signed int *s32src = (signed int *) src;
- double *f64src = (double *) src;
+ signed short *s16src = (signed short*)src;
+ signed int *s32src = (signed int*)src;
+ double *f64src = (double*)src;
jack_sample_t scale;
srcidx = channel;
- switch (bits)
- {
- case 16:
- scale = 1.0f / 0x7fff;
- for (dstidx = 0; dstidx < nframes; dstidx++)
- {
- dst[dstidx] = (jack_sample_t)
- s16src[srcidx] * scale;
- srcidx += chcount;
- }
- break;
- case 24:
- scale = 1.0f / 0x7fffff;
- for (dstidx = 0; dstidx < nframes; dstidx++)
- {
- dst[dstidx] = (jack_sample_t)
- s32src[srcidx] * scale;
- srcidx += chcount;
- }
- break;
- case 32:
- scale = 1.0f / 0x7fffffff;
- for (dstidx = 0; dstidx < nframes; dstidx++)
- {
- dst[dstidx] = (jack_sample_t)
- s32src[srcidx] * scale;
- srcidx += chcount;
- }
- break;
- case 64:
- for (dstidx = 0; dstidx < nframes; dstidx++)
- {
- dst[dstidx] = (jack_sample_t) f64src[srcidx];
- srcidx += chcount;
- }
- break;
+ switch (bits) {
+ case 16:
+ scale = 1.0f / 0x7fff;
+ for (dstidx = 0; dstidx < nframes; dstidx++) {
+ dst[dstidx] = (jack_sample_t)
+ s16src[srcidx] * scale;
+ srcidx += chcount;
+ }
+ break;
+ case 24:
+ scale = 1.0f / 0x7fffff;
+ for (dstidx = 0; dstidx < nframes; dstidx++) {
+ dst[dstidx] = (jack_sample_t)
+ s32src[srcidx] * scale;
+ srcidx += chcount;
+ }
+ break;
+ case 32:
+ scale = 1.0f / 0x7fffffff;
+ for (dstidx = 0; dstidx < nframes; dstidx++) {
+ dst[dstidx] = (jack_sample_t)
+ s32src[srcidx] * scale;
+ srcidx += chcount;
+ }
+ break;
+ case 64:
+ for (dstidx = 0; dstidx < nframes; dstidx++) {
+ dst[dstidx] = (jack_sample_t)f64src[srcidx];
+ srcidx += chcount;
+ }
+ break;
}
}
static void
-copy_and_convert_out (void *dst, jack_sample_t *src,
- size_t nframes, int channel, int chcount, int bits)
+copy_and_convert_out (void *dst, jack_sample_t *src,
+ size_t nframes, int channel, int chcount, int bits)
{
int srcidx;
int dstidx;
- signed short *s16dst = (signed short *) dst;
- signed int *s32dst = (signed int *) dst;
- double *f64dst = (double *) dst;
+ signed short *s16dst = (signed short*)dst;
+ signed int *s32dst = (signed int*)dst;
+ double *f64dst = (double*)dst;
jack_sample_t scale;
dstidx = channel;
- switch (bits)
- {
- case 16:
- scale = 0x7fff;
- for (srcidx = 0; srcidx < nframes; srcidx++)
- {
- s16dst[dstidx] = (signed short)
- (src[srcidx] >= 0.0f) ?
- (src[srcidx] * scale + 0.5f) :
- (src[srcidx] * scale - 0.5f);
- dstidx += chcount;
- }
- break;
- case 24:
- scale = 0x7fffff;
- for (srcidx = 0; srcidx < nframes; srcidx++)
- {
- s32dst[dstidx] = (signed int)
- (src[srcidx] >= 0.0f) ?
- (src[srcidx] * scale + 0.5f) :
- (src[srcidx] * scale - 0.5f);
- dstidx += chcount;
- }
- break;
- case 32:
- scale = 0x7fffffff;
- for (srcidx = 0; srcidx < nframes; srcidx++)
- {
- s32dst[dstidx] = (signed int)
- (src[srcidx] >= 0.0f) ?
- (src[srcidx] * scale + 0.5f) :
- (src[srcidx] * scale - 0.5f);
- dstidx += chcount;
- }
- break;
- case 64:
- for (srcidx = 0; srcidx < nframes; srcidx++)
- {
- f64dst[dstidx] = (double) src[srcidx];
- dstidx += chcount;
- }
- break;
+ switch (bits) {
+ case 16:
+ scale = 0x7fff;
+ for (srcidx = 0; srcidx < nframes; srcidx++) {
+ s16dst[dstidx] = (signed short)
+ (src[srcidx] >= 0.0f) ?
+ (src[srcidx] * scale + 0.5f) :
+ (src[srcidx] * scale - 0.5f);
+ dstidx += chcount;
+ }
+ break;
+ case 24:
+ scale = 0x7fffff;
+ for (srcidx = 0; srcidx < nframes; srcidx++) {
+ s32dst[dstidx] = (signed int)
+ (src[srcidx] >= 0.0f) ?
+ (src[srcidx] * scale + 0.5f) :
+ (src[srcidx] * scale - 0.5f);
+ dstidx += chcount;
+ }
+ break;
+ case 32:
+ scale = 0x7fffffff;
+ for (srcidx = 0; srcidx < nframes; srcidx++) {
+ s32dst[dstidx] = (signed int)
+ (src[srcidx] >= 0.0f) ?
+ (src[srcidx] * scale + 0.5f) :
+ (src[srcidx] * scale - 0.5f);
+ dstidx += chcount;
+ }
+ break;
+ case 64:
+ for (srcidx = 0; srcidx < nframes; srcidx++) {
+ f64dst[dstidx] = (double)src[srcidx];
+ dstidx += chcount;
+ }
+ break;
}
}
@@ -566,53 +522,49 @@ sun_driver_attach (sun_driver_t *driver)
jack_port_t *port;
jack_latency_range_t range;
- if (driver->engine->set_buffer_size(driver->engine, driver->period_size)) {
+ if (driver->engine->set_buffer_size (driver->engine, driver->period_size)) {
jack_error ("sun_driver: cannot set engine buffer size to %d (check MIDI)", driver->period_size);
return -1;
}
- driver->engine->set_sample_rate(driver->engine, driver->sample_rate);
-
- port_flags = JackPortIsOutput|JackPortIsPhysical|JackPortIsTerminal;
-
- for (channel = 0; channel < driver->capture_channels; channel++)
- {
- snprintf(channel_name, sizeof(channel_name),
- "capture_%u", channel + 1);
- port = jack_port_register(driver->client, channel_name,
- JACK_DEFAULT_AUDIO_TYPE, port_flags, 0);
- if (port == NULL)
- {
- jack_error("sun_driver: cannot register port for %s: "
- "%s@%i", channel_name, __FILE__, __LINE__);
+ driver->engine->set_sample_rate (driver->engine, driver->sample_rate);
+
+ port_flags = JackPortIsOutput | JackPortIsPhysical | JackPortIsTerminal;
+
+ for (channel = 0; channel < driver->capture_channels; channel++) {
+ snprintf (channel_name, sizeof(channel_name),
+ "capture_%u", channel + 1);
+ port = jack_port_register (driver->client, channel_name,
+ JACK_DEFAULT_AUDIO_TYPE, port_flags, 0);
+ if (port == NULL) {
+ jack_error ("sun_driver: cannot register port for %s: "
+ "%s@%i", channel_name, __FILE__, __LINE__);
break;
}
range.min = range.max = driver->period_size + driver->sys_in_latency;
- jack_port_set_latency_range(port, JackCaptureLatency, &range);
- driver->capture_ports =
- jack_slist_append(driver->capture_ports, port);
- }
-
- port_flags = JackPortIsInput|JackPortIsPhysical|JackPortIsTerminal;
- for (channel = 0; channel < driver->playback_channels; channel++)
- {
- snprintf(channel_name, sizeof(channel_name),
- "playback_%u", channel + 1);
- port = jack_port_register(driver->client, channel_name,
- JACK_DEFAULT_AUDIO_TYPE, port_flags, 0);
- if (port == NULL)
- {
- jack_error("sun_driver: cannot register port for "
- "%s: %s@%i", channel_name, __FILE__, __LINE__);
+ jack_port_set_latency_range (port, JackCaptureLatency, &range);
+ driver->capture_ports =
+ jack_slist_append (driver->capture_ports, port);
+ }
+
+ port_flags = JackPortIsInput | JackPortIsPhysical | JackPortIsTerminal;
+ for (channel = 0; channel < driver->playback_channels; channel++) {
+ snprintf (channel_name, sizeof(channel_name),
+ "playback_%u", channel + 1);
+ port = jack_port_register (driver->client, channel_name,
+ JACK_DEFAULT_AUDIO_TYPE, port_flags, 0);
+ if (port == NULL) {
+ jack_error ("sun_driver: cannot register port for "
+ "%s: %s@%i", channel_name, __FILE__, __LINE__);
break;
}
range.min = range.max = driver->period_size + driver->sys_out_latency;
- jack_port_set_latency_range(port, JackPlaybackLatency, &range);
+ jack_port_set_latency_range (port, JackPlaybackLatency, &range);
driver->playback_ports =
- jack_slist_append(driver->playback_ports, port);
+ jack_slist_append (driver->playback_ports, port);
}
- return jack_activate(driver->client);
+ return jack_activate (driver->client);
}
@@ -621,27 +573,26 @@ sun_driver_detach (sun_driver_t *driver)
{
JSList *node;
- if (driver->engine == NULL)
+ if (driver->engine == NULL) {
return 0;
+ }
node = driver->capture_ports;
- while (node != NULL)
- {
- jack_port_unregister(driver->client,
- ((jack_port_t *) node->data));
- node = jack_slist_next(node);
+ while (node != NULL) {
+ jack_port_unregister (driver->client,
+ ((jack_port_t*)node->data));
+ node = jack_slist_next (node);
}
- jack_slist_free(driver->capture_ports);
+ jack_slist_free (driver->capture_ports);
driver->capture_ports = NULL;
node = driver->playback_ports;
- while (node != NULL)
- {
- jack_port_unregister(driver->client,
- ((jack_port_t *) node->data));
- node = jack_slist_next(node);
+ while (node != NULL) {
+ jack_port_unregister (driver->client,
+ ((jack_port_t*)node->data));
+ node = jack_slist_next (node);
}
- jack_slist_free(driver->playback_ports);
+ jack_slist_free (driver->playback_ports);
driver->playback_ports = NULL;
return 0;
@@ -653,43 +604,38 @@ sun_driver_start (sun_driver_t *driver)
{
audio_info_t audio_if;
- if (driver->infd >= 0)
- {
+ if (driver->infd >= 0) {
#if defined(AUDIO_FLUSH)
- if (ioctl(driver->infd, AUDIO_FLUSH, NULL) < 0)
- {
- jack_error("sun_driver: capture flush failed: %s: "
- "%s@%i", strerror(errno), __FILE__, __LINE__);
+ if (ioctl (driver->infd, AUDIO_FLUSH, NULL) < 0) {
+ jack_error ("sun_driver: capture flush failed: %s: "
+ "%s@%i", strerror (errno), __FILE__, __LINE__);
return -1;
}
#endif
- AUDIO_INITINFO(&audio_if);
+ AUDIO_INITINFO (&audio_if);
audio_if.record.pause = 1;
- if (driver->outfd == driver->infd)
+ if (driver->outfd == driver->infd) {
audio_if.play.pause = 1;
- if (ioctl(driver->infd, AUDIO_SETINFO, &audio_if) < 0)
- {
- jack_error("sun_driver: pause capture failed: %s: "
- "%s@%i", strerror(errno), __FILE__, __LINE__);
+ }
+ if (ioctl (driver->infd, AUDIO_SETINFO, &audio_if) < 0) {
+ jack_error ("sun_driver: pause capture failed: %s: "
+ "%s@%i", strerror (errno), __FILE__, __LINE__);
return -1;
}
}
- if ((driver->outfd >= 0) && (driver->outfd != driver->infd))
- {
+ if ((driver->outfd >= 0) && (driver->outfd != driver->infd)) {
#if defined(AUDIO_FLUSH)
- if (ioctl(driver->outfd, AUDIO_FLUSH, NULL) < 0)
- {
- jack_error("sun_driver: playback flush failed: %s: "
- "%s@%i", strerror(errno), __FILE__, __LINE__);
+ if (ioctl (driver->outfd, AUDIO_FLUSH, NULL) < 0) {
+ jack_error ("sun_driver: playback flush failed: %s: "
+ "%s@%i", strerror (errno), __FILE__, __LINE__);
return -1;
}
#endif
- AUDIO_INITINFO(&audio_if);
+ AUDIO_INITINFO (&audio_if);
audio_if.play.pause = 1;
- if (ioctl(driver->outfd, AUDIO_SETINFO, &audio_if) < 0)
- {
- jack_error("sun_driver: pause playback failed: %s: "
- "%s@%i", strerror(errno), __FILE__, __LINE__);
+ if (ioctl (driver->outfd, AUDIO_SETINFO, &audio_if) < 0) {
+ jack_error ("sun_driver: pause playback failed: %s: "
+ "%s@%i", strerror (errno), __FILE__, __LINE__);
return -1;
}
}
@@ -697,39 +643,35 @@ sun_driver_start (sun_driver_t *driver)
/* AUDIO_FLUSH resets the counters these work with */
driver->playback_drops = driver->capture_drops = 0;
- if (driver->outfd >= 0)
- {
+ if (driver->outfd >= 0) {
/* "prime" the playback buffer. if we don't do this, we'll
* end up underrunning. it would get really ugly in duplex
* mode, for example, where we have to wait for a period to
* be available to read before we can write. also helps to
* keep constant latency from the beginning.
*/
- sun_driver_write_silence(driver,
- driver->nperiods * driver->period_size);
+ sun_driver_write_silence (driver,
+ driver->nperiods * driver->period_size);
}
- if (driver->infd >= 0)
- {
- AUDIO_INITINFO(&audio_if);
+ if (driver->infd >= 0) {
+ AUDIO_INITINFO (&audio_if);
audio_if.record.pause = 0;
- if (driver->outfd == driver->infd)
+ if (driver->outfd == driver->infd) {
audio_if.play.pause = 0;
- if (ioctl(driver->infd, AUDIO_SETINFO, &audio_if) < 0)
- {
- jack_error("sun_driver: start capture failed: %s: "
- "%s@%i", strerror(errno), __FILE__, __LINE__);
+ }
+ if (ioctl (driver->infd, AUDIO_SETINFO, &audio_if) < 0) {
+ jack_error ("sun_driver: start capture failed: %s: "
+ "%s@%i", strerror (errno), __FILE__, __LINE__);
return -1;
}
}
- if ((driver->outfd >= 0) && (driver->outfd != driver->infd))
- {
- AUDIO_INITINFO(&audio_if);
+ if ((driver->outfd >= 0) && (driver->outfd != driver->infd)) {
+ AUDIO_INITINFO (&audio_if);
audio_if.play.pause = 0;
- if (ioctl(driver->outfd, AUDIO_SETINFO, &audio_if) < 0)
- {
- jack_error("sun_driver: trigger playback failed: %s: "
- "%s@%i", strerror(errno), __FILE__, __LINE__);
+ if (ioctl (driver->outfd, AUDIO_SETINFO, &audio_if) < 0) {
+ jack_error ("sun_driver: trigger playback failed: %s: "
+ "%s@%i", strerror (errno), __FILE__, __LINE__);
return -1;
}
}
@@ -739,24 +681,27 @@ sun_driver_start (sun_driver_t *driver)
static int
-enc_equal(int a, int b)
+enc_equal (int a, int b)
{
- if (a == b)
+ if (a == b) {
return 1;
+ }
-#if defined(AUDIO_ENCODING_SLINEAR)
+#if defined(AUDIO_ENCODING_SLINEAR)
#if BYTE_ORDER == LITTLE_ENDIAN
if ((a == AUDIO_ENCODING_SLINEAR && b == AUDIO_ENCODING_SLINEAR_LE) ||
(a == AUDIO_ENCODING_SLINEAR_LE && b == AUDIO_ENCODING_SLINEAR) ||
(a == AUDIO_ENCODING_ULINEAR && b == AUDIO_ENCODING_ULINEAR_LE) ||
- (a == AUDIO_ENCODING_ULINEAR_LE && b == AUDIO_ENCODING_ULINEAR))
+ (a == AUDIO_ENCODING_ULINEAR_LE && b == AUDIO_ENCODING_ULINEAR)) {
return 1;
+ }
#elif BYTE_ORDER == BIG_ENDIAN
if ((a == AUDIO_ENCODING_SLINEAR && b == AUDIO_ENCODING_SLINEAR_BE) ||
(a == AUDIO_ENCODING_SLINEAR_BE && b == AUDIO_ENCODING_SLINEAR) ||
(a == AUDIO_ENCODING_ULINEAR && b == AUDIO_ENCODING_ULINEAR_BE) ||
- (a == AUDIO_ENCODING_ULINEAR_BE && b == AUDIO_ENCODING_ULINEAR))
+ (a == AUDIO_ENCODING_ULINEAR_BE && b == AUDIO_ENCODING_ULINEAR)) {
return 1;
+ }
#endif
#endif // AUDIO_ENCODING_SLINEAR
return 0;
@@ -778,75 +723,63 @@ sun_driver_set_parameters (sun_driver_t *driver)
driver->outdevbuf = NULL;
driver->sample_bytes = driver->bits / 8;
- if ((strcmp(indev, outdev) == 0) &&
- ((driver->capture_channels > 0) && (driver->playback_channels > 0)))
- {
- infd = outfd = open(indev, O_RDWR);
- if (infd < 0)
- {
- jack_error("sun_driver: failed to open duplex device "
- "%s: %s: %s@%i", indev, strerror(errno),
- __FILE__, __LINE__);
+ if ((strcmp (indev, outdev) == 0) &&
+ ((driver->capture_channels > 0) && (driver->playback_channels > 0))) {
+ infd = outfd = open (indev, O_RDWR);
+ if (infd < 0) {
+ jack_error ("sun_driver: failed to open duplex device "
+ "%s: %s: %s@%i", indev, strerror (errno),
+ __FILE__, __LINE__);
return -1;
}
#if defined(AUDIO_SETFD)
- if (ioctl(infd, AUDIO_SETFD, &s) < 0)
- {
- jack_error("sun_driver: failed to enable full duplex: "
- "%s: %s@%i", strerror(errno),
- __FILE__, __LINE__);
+ if (ioctl (infd, AUDIO_SETFD, &s) < 0) {
+ jack_error ("sun_driver: failed to enable full duplex: "
+ "%s: %s@%i", strerror (errno),
+ __FILE__, __LINE__);
return -1;
}
#endif
- }
- else
- {
- if (driver->capture_channels > 0)
- {
- infd = open(indev, O_RDONLY);
- if (infd < 0)
- {
- jack_error("sun_driver: failed to open input "
- "device %s: %s: %s@%i", indev,
- strerror(errno), __FILE__, __LINE__);
+ } else {
+ if (driver->capture_channels > 0) {
+ infd = open (indev, O_RDONLY);
+ if (infd < 0) {
+ jack_error ("sun_driver: failed to open input "
+ "device %s: %s: %s@%i", indev,
+ strerror (errno), __FILE__, __LINE__);
return -1;
}
}
- if (driver->playback_channels > 0)
- {
- outfd = open(outdev, O_WRONLY);
- if (outfd < 0)
- {
- jack_error("sun_driver: failed to open output "
- "device %s: %s: %s@%i", outdev,
- strerror(errno), __FILE__, __LINE__);
+ if (driver->playback_channels > 0) {
+ outfd = open (outdev, O_WRONLY);
+ if (outfd < 0) {
+ jack_error ("sun_driver: failed to open output "
+ "device %s: %s: %s@%i", outdev,
+ strerror (errno), __FILE__, __LINE__);
return -1;
}
}
}
- if (infd == -1 && outfd == -1)
- {
- jack_error("sun_driver: no device was opened: %s@%i",
- __FILE__, __LINE__);
+ if (infd == -1 && outfd == -1) {
+ jack_error ("sun_driver: no device was opened: %s@%i",
+ __FILE__, __LINE__);
return -1;
}
driver->infd = infd;
driver->outfd = outfd;
-
- AUDIO_INITINFO(&audio_if_in);
- AUDIO_INITINFO(&audio_if_out);
- if (infd >= 0)
- {
+ AUDIO_INITINFO (&audio_if_in);
+ AUDIO_INITINFO (&audio_if_out);
+
+ if (infd >= 0) {
audio_if_in.record.encoding = driver->format;
audio_if_in.record.precision = driver->bits;
audio_if_in.record.channels = driver->capture_channels;
audio_if_in.record.sample_rate = driver->sample_rate;
audio_if_in.record.pause = 1;
}
- if (outfd >= 0)
- {
+ if (outfd >= 0) {
audio_if_out.play.encoding = driver->format;
audio_if_out.play.precision = driver->bits;
audio_if_out.play.channels = driver->playback_channels;
@@ -856,22 +789,27 @@ sun_driver_set_parameters (sun_driver_t *driver)
#if defined(__OpenBSD__) || defined(__NetBSD__)
#if defined(__OpenBSD__)
- if (driver->infd >= 0)
+ if (driver->infd >= 0) {
audio_if_in.record.block_size = driver->capture_channels *
- driver->period_size * driver->sample_bytes;
- if (driver->outfd >= 0)
+ driver->period_size * driver->sample_bytes;
+ }
+ if (driver->outfd >= 0) {
audio_if_out.play.block_size = driver->playback_channels *
- driver->period_size * driver->sample_bytes;
+ driver->period_size * driver->sample_bytes;
+ }
#else
- if (driver->infd >= 0)
+ if (driver->infd >= 0) {
audio_if_in.blocksize = driver->capture_channels *
- driver->period_size * driver->sample_bytes;
- if (driver->outfd >= 0)
+ driver->period_size * driver->sample_bytes;
+ }
+ if (driver->outfd >= 0) {
audio_if_out.blocksize = driver->playback_channels *
- driver->period_size * driver->sample_bytes;
+ driver->period_size * driver->sample_bytes;
+ }
#endif
- if (infd == outfd)
+ if (infd == outfd) {
audio_if_in.play = audio_if_out.play;
+ }
/* this only affects playback. the capture buffer is
* always the max (64k on OpenBSD).
@@ -882,177 +820,155 @@ sun_driver_set_parameters (sun_driver_t *driver)
* playback. that means, if we are N frames late, the next
* N frames written will be discarded. this keeps playback
* time from expanding with each underrun.
- */
- if (infd == outfd)
- {
+ */
+ if (infd == outfd) {
audio_if_in.mode = AUMODE_PLAY | AUMODE_RECORD;
- }
- else
- {
- if (infd >= 0)
+ } else {
+ if (infd >= 0) {
audio_if_in.mode = AUMODE_RECORD;
+ }
- if (outfd >= 0)
+ if (outfd >= 0) {
audio_if_out.mode = AUMODE_PLAY;
+ }
}
#endif // OpenBSD || NetBSD
- if (infd >= 0)
- {
- if (ioctl(infd, AUDIO_SETINFO, &audio_if_in) < 0)
- {
- jack_error("sun_driver: failed to set parameters for "
- "%s: %s: %s@%i", indev, strerror(errno),
- __FILE__, __LINE__);
+ if (infd >= 0) {
+ if (ioctl (infd, AUDIO_SETINFO, &audio_if_in) < 0) {
+ jack_error ("sun_driver: failed to set parameters for "
+ "%s: %s: %s@%i", indev, strerror (errno),
+ __FILE__, __LINE__);
return -1;
}
}
- if (outfd >= 0 && outfd != infd)
- {
- if (ioctl(outfd, AUDIO_SETINFO, &audio_if_out) < 0)
- {
- jack_error("sun_driver: failed to set parameters for "
- "%s: %s: %s@%i", outdev, strerror(errno),
- __FILE__, __LINE__);
+ if (outfd >= 0 && outfd != infd) {
+ if (ioctl (outfd, AUDIO_SETINFO, &audio_if_out) < 0) {
+ jack_error ("sun_driver: failed to set parameters for "
+ "%s: %s: %s@%i", outdev, strerror (errno),
+ __FILE__, __LINE__);
return -1;
}
}
- if (infd >= 0)
- {
- if (ioctl(infd, AUDIO_GETINFO, &audio_if_in) < 0)
- {
- jack_error("sun_driver: AUDIO_GETINFO failed: %s: "
- "%s@%i", strerror(errno), __FILE__, __LINE__);
+ if (infd >= 0) {
+ if (ioctl (infd, AUDIO_GETINFO, &audio_if_in) < 0) {
+ jack_error ("sun_driver: AUDIO_GETINFO failed: %s: "
+ "%s@%i", strerror (errno), __FILE__, __LINE__);
return -1;
}
- if (!enc_equal(audio_if_in.record.encoding, driver->format) ||
+ if (!enc_equal (audio_if_in.record.encoding, driver->format) ||
audio_if_in.record.precision != driver->bits ||
audio_if_in.record.channels != driver->capture_channels ||
- audio_if_in.record.sample_rate != driver->sample_rate)
- {
- jack_error("sun_driver: setting capture parameters "
- "failed: %s@%i", __FILE__, __LINE__);
+ audio_if_in.record.sample_rate != driver->sample_rate) {
+ jack_error ("sun_driver: setting capture parameters "
+ "failed: %s@%i", __FILE__, __LINE__);
return -1;
}
#if defined(__OpenBSD__)
cap_period = audio_if_in.record.block_size /
- driver->capture_channels / driver->sample_bytes;
+ driver->capture_channels / driver->sample_bytes;
#elif defined(__NetBSD__)
cap_period = audio_if_in.blocksize /
- driver->capture_channels / driver->sample_bytes;
+ driver->capture_channels / driver->sample_bytes;
#else
/* how is this done on Solaris? */
cap_period = driver->period_size;
#endif
}
- if (outfd >= 0)
- {
- if (outfd == infd)
- {
+ if (outfd >= 0) {
+ if (outfd == infd) {
audio_if_out.play = audio_if_in.play;
- }
- else
- {
- if (ioctl(outfd, AUDIO_GETINFO, &audio_if_out) < 0)
- {
- jack_error("sun_driver: AUDIO_GETINFO failed: "
- "%s: %s@%i", strerror(errno),
- __FILE__, __LINE__);
+ } else {
+ if (ioctl (outfd, AUDIO_GETINFO, &audio_if_out) < 0) {
+ jack_error ("sun_driver: AUDIO_GETINFO failed: "
+ "%s: %s@%i", strerror (errno),
+ __FILE__, __LINE__);
return -1;
}
}
- if (!enc_equal(audio_if_out.play.encoding, driver->format) ||
+ if (!enc_equal (audio_if_out.play.encoding, driver->format) ||
audio_if_out.play.precision != driver->bits ||
audio_if_out.play.channels != driver->playback_channels ||
- audio_if_out.play.sample_rate != driver->sample_rate)
- {
- jack_error("sun_driver: playback settings failed: "
- "%s@%i", __FILE__, __LINE__);
+ audio_if_out.play.sample_rate != driver->sample_rate) {
+ jack_error ("sun_driver: playback settings failed: "
+ "%s@%i", __FILE__, __LINE__);
return -1;
}
#if defined(__OpenBSD__)
play_period = audio_if_out.play.block_size /
- driver->playback_channels / driver->sample_bytes;
+ driver->playback_channels / driver->sample_bytes;
#elif defined(__NetBSD__)
play_period = audio_if_out.blocksize /
- driver->playback_channels / driver->sample_bytes;
+ driver->playback_channels / driver->sample_bytes;
#else
/* how is this done on Solaris? */
play_period = driver->period_size;
#endif
}
- if (infd >= 0 && outfd >= 0 && play_period != cap_period)
- {
- jack_error("sun_driver: play and capture periods differ: "
- "%s@%i", __FILE__, __LINE__);
+ if (infd >= 0 && outfd >= 0 && play_period != cap_period) {
+ jack_error ("sun_driver: play and capture periods differ: "
+ "%s@%i", __FILE__, __LINE__);
return -1;
}
- if (infd >= 0)
+ if (infd >= 0) {
period_size = cap_period;
- else if (outfd >= 0)
+ } else if (outfd >= 0) {
period_size = play_period;
+ }
- if (period_size != 0 && period_size != driver->period_size &&
- !driver->ignorehwbuf)
- {
- printf("sun_driver: period size update: %u\n", period_size);
+ if (period_size != 0 && period_size != driver->period_size &&
+ !driver->ignorehwbuf) {
+ printf ("sun_driver: period size update: %u\n", period_size);
set_period_size (driver, period_size);
- if (driver->engine)
- if (driver->engine->set_buffer_size(driver->engine,
- driver->period_size)) {
+ if (driver->engine) {
+ if (driver->engine->set_buffer_size (driver->engine,
+ driver->period_size)) {
jack_error ("sun_driver: cannot set engine buffer size to %d (check MIDI)", driver->period_size);
return -1;
}
+ }
}
- if (driver->infd >= 0 && driver->capture_channels > 0)
- {
- driver->indevbufsize = driver->period_size *
- driver->capture_channels * driver->sample_bytes;
- driver->indevbuf = malloc(driver->indevbufsize);
- if (driver->indevbuf == NULL)
- {
- jack_error( "sun_driver: malloc() failed: %s@%i",
- __FILE__, __LINE__);
+ if (driver->infd >= 0 && driver->capture_channels > 0) {
+ driver->indevbufsize = driver->period_size *
+ driver->capture_channels * driver->sample_bytes;
+ driver->indevbuf = malloc (driver->indevbufsize);
+ if (driver->indevbuf == NULL) {
+ jack_error ( "sun_driver: malloc() failed: %s@%i",
+ __FILE__, __LINE__);
return -1;
}
- bzero(driver->indevbuf, driver->indevbufsize);
- }
- else
- {
+ bzero (driver->indevbuf, driver->indevbufsize);
+ } else {
driver->indevbufsize = 0;
driver->indevbuf = NULL;
}
- if (driver->outfd >= 0 && driver->playback_channels > 0)
- {
- driver->outdevbufsize = driver->period_size *
- driver->playback_channels * driver->sample_bytes;
- driver->outdevbuf = malloc(driver->outdevbufsize);
- if (driver->outdevbuf == NULL)
- {
- jack_error("sun_driver: malloc() failed: %s@%i",
- __FILE__, __LINE__);
+ if (driver->outfd >= 0 && driver->playback_channels > 0) {
+ driver->outdevbufsize = driver->period_size *
+ driver->playback_channels * driver->sample_bytes;
+ driver->outdevbuf = malloc (driver->outdevbufsize);
+ if (driver->outdevbuf == NULL) {
+ jack_error ("sun_driver: malloc() failed: %s@%i",
+ __FILE__, __LINE__);
return -1;
}
- bzero(driver->outdevbuf, driver->outdevbufsize);
- }
- else
- {
+ bzero (driver->outdevbuf, driver->outdevbufsize);
+ } else {
driver->outdevbufsize = 0;
driver->outdevbuf = NULL;
}
- printf("sun_driver: indevbuf %zd B, outdevbuf %zd B\n",
+ printf ("sun_driver: indevbuf %zd B, outdevbuf %zd B\n",
driver->indevbufsize, driver->outdevbufsize);
return 0;
@@ -1064,28 +980,25 @@ sun_driver_stop (sun_driver_t *driver)
{
audio_info_t audio_if;
- if (driver->infd >= 0)
- {
- AUDIO_INITINFO(&audio_if);
+ if (driver->infd >= 0) {
+ AUDIO_INITINFO (&audio_if);
audio_if.record.pause = 1;
- if (driver->outfd == driver->infd)
+ if (driver->outfd == driver->infd) {
audio_if.play.pause = 1;
- if (ioctl(driver->infd, AUDIO_SETINFO, &audio_if) < 0)
- {
- jack_error("sun_driver: capture pause failed: %s: "
- "%s@%i", strerror(errno), __FILE__, __LINE__);
+ }
+ if (ioctl (driver->infd, AUDIO_SETINFO, &audio_if) < 0) {
+ jack_error ("sun_driver: capture pause failed: %s: "
+ "%s@%i", strerror (errno), __FILE__, __LINE__);
return -1;
}
}
- if ((driver->outfd >= 0) && (driver->outfd != driver->infd))
- {
- AUDIO_INITINFO(&audio_if);
+ if ((driver->outfd >= 0) && (driver->outfd != driver->infd)) {
+ AUDIO_INITINFO (&audio_if);
audio_if.play.pause = 1;
- if (ioctl(driver->outfd, AUDIO_SETINFO, &audio_if) < 0)
- {
- jack_error("sun_driver: playback pause failed: %s: "
- "%s@%i", strerror(errno), __FILE__, __LINE__);
+ if (ioctl (driver->outfd, AUDIO_SETINFO, &audio_if) < 0) {
+ jack_error ("sun_driver: playback pause failed: %s: "
+ "%s@%i", strerror (errno), __FILE__, __LINE__);
return -1;
}
}
@@ -1104,49 +1017,45 @@ sun_driver_read (sun_driver_t *driver, jack_nframes_t nframes)
JSList *node;
jack_port_t *port;
- if (driver->engine->freewheeling || driver->infd < 0)
+ if (driver->engine->freewheeling || driver->infd < 0) {
return 0;
+ }
- if (nframes > driver->period_size)
- {
- jack_error("sun_driver: read failed: nframes > period_size: "
- "(%u/%u): %s@%i", nframes, driver->period_size,
- __FILE__, __LINE__);
+ if (nframes > driver->period_size) {
+ jack_error ("sun_driver: read failed: nframes > period_size: "
+ "(%u/%u): %s@%i", nframes, driver->period_size,
+ __FILE__, __LINE__);
return -1;
}
node = driver->capture_ports;
channel = 0;
- while (node != NULL)
- {
- port = (jack_port_t *) node->data;
-
- if (jack_port_connected(port))
- {
- portbuf = jack_port_get_buffer(port, nframes);
- copy_and_convert_in(portbuf, driver->indevbuf,
- nframes, channel,
- driver->capture_channels,
- driver->bits);
+ while (node != NULL) {
+ port = (jack_port_t*)node->data;
+
+ if (jack_port_connected (port)) {
+ portbuf = jack_port_get_buffer (port, nframes);
+ copy_and_convert_in (portbuf, driver->indevbuf,
+ nframes, channel,
+ driver->capture_channels,
+ driver->bits);
}
- node = jack_slist_next(node);
+ node = jack_slist_next (node);
channel++;
}
nbytes = nframes * driver->capture_channels * driver->sample_bytes;
io_res = 0;
- while (nbytes)
- {
- io_res = read(driver->infd, driver->indevbuf, nbytes);
- if (io_res < 0)
- {
- jack_error("sun_driver: read() failed: %s: %s@%i",
- strerror(errno), __FILE__, __LINE__);
+ while (nbytes) {
+ io_res = read (driver->infd, driver->indevbuf, nbytes);
+ if (io_res < 0) {
+ jack_error ("sun_driver: read() failed: %s: %s@%i",
+ strerror (errno), __FILE__, __LINE__);
break;
- }
- else
+ } else {
nbytes -= io_res;
+ }
}
return 0;
@@ -1164,51 +1073,47 @@ sun_driver_write (sun_driver_t *driver, jack_nframes_t nframes)
jack_port_t *port;
- if (driver->engine->freewheeling || driver->outfd < 0)
+ if (driver->engine->freewheeling || driver->outfd < 0) {
return 0;
+ }
- if (nframes > driver->period_size)
- {
- jack_error("sun_driver: write failed: nframes > period_size "
- "(%u/%u): %s@%i", nframes, driver->period_size,
- __FILE__, __LINE__);
+ if (nframes > driver->period_size) {
+ jack_error ("sun_driver: write failed: nframes > period_size "
+ "(%u/%u): %s@%i", nframes, driver->period_size,
+ __FILE__, __LINE__);
return -1;
}
- bzero(driver->outdevbuf, driver->outdevbufsize);
+ bzero (driver->outdevbuf, driver->outdevbufsize);
node = driver->playback_ports;
channel = 0;
- while (node != NULL)
- {
- port = (jack_port_t *) node->data;
-
- if (jack_port_connected(port))
- {
- portbuf = jack_port_get_buffer(port, nframes);
- copy_and_convert_out(driver->outdevbuf, portbuf,
- nframes, channel,
- driver->playback_channels,
- driver->bits);
+ while (node != NULL) {
+ port = (jack_port_t*)node->data;
+
+ if (jack_port_connected (port)) {
+ portbuf = jack_port_get_buffer (port, nframes);
+ copy_and_convert_out (driver->outdevbuf, portbuf,
+ nframes, channel,
+ driver->playback_channels,
+ driver->bits);
}
- node = jack_slist_next(node);
+ node = jack_slist_next (node);
channel++;
}
nbytes = nframes * driver->playback_channels * driver->sample_bytes;
io_res = 0;
- while (nbytes)
- {
- io_res = write(driver->outfd, driver->outdevbuf, nbytes);
- if (io_res < 0)
- {
- jack_error("sun_driver: write() failed: %s: %s@%i",
- strerror(errno), __FILE__, __LINE__);
+ while (nbytes) {
+ io_res = write (driver->outfd, driver->outdevbuf, nbytes);
+ if (io_res < 0) {
+ jack_error ("sun_driver: write() failed: %s: %s@%i",
+ strerror (errno), __FILE__, __LINE__);
break;
- }
- else
+ } else {
nbytes -= io_res;
+ }
}
return 0;
@@ -1218,21 +1123,22 @@ sun_driver_write (sun_driver_t *driver, jack_nframes_t nframes)
static int
sun_driver_null_cycle (sun_driver_t *driver, jack_nframes_t nframes)
{
- if (nframes > driver->period_size)
- {
- jack_error("sun_driver: null cycle failed: "
- "nframes > period_size (%u/%u): %s@%i", nframes,
- driver->period_size, __FILE__, __LINE__);
+ if (nframes > driver->period_size) {
+ jack_error ("sun_driver: null cycle failed: "
+ "nframes > period_size (%u/%u): %s@%i", nframes,
+ driver->period_size, __FILE__, __LINE__);
return -1;
}
- printf("sun_driver: running null cycle\n");
+ printf ("sun_driver: running null cycle\n");
- if (driver->outfd >= 0)
+ if (driver->outfd >= 0) {
sun_driver_write_silence (driver, nframes);
+ }
- if (driver->infd >= 0)
+ if (driver->infd >= 0) {
sun_driver_read_silence (driver, nframes);
+ }
return 0;
}
@@ -1241,89 +1147,88 @@ sun_driver_null_cycle (sun_driver_t *driver, jack_nframes_t nframes)
static int
sun_driver_bufsize (sun_driver_t *driver, jack_nframes_t nframes)
{
- return sun_driver_set_parameters(driver);
+ return sun_driver_set_parameters (driver);
}
static void
sun_driver_delete (sun_driver_t *driver)
{
- if (driver->outfd >= 0 && driver->outfd != driver->infd)
- {
- close(driver->outfd);
+ if (driver->outfd >= 0 && driver->outfd != driver->infd) {
+ close (driver->outfd);
driver->outfd = -1;
}
- if (driver->infd >= 0)
- {
- close(driver->infd);
+ if (driver->infd >= 0) {
+ close (driver->infd);
driver->infd = -1;
}
- if (driver->indevbuf != NULL)
- {
- free(driver->indevbuf);
+ if (driver->indevbuf != NULL) {
+ free (driver->indevbuf);
driver->indevbuf = NULL;
}
- if (driver->outdevbuf != NULL)
- {
- free(driver->outdevbuf);
+ if (driver->outdevbuf != NULL) {
+ free (driver->outdevbuf);
driver->outdevbuf = NULL;
}
- if (driver->indev != NULL)
- free(driver->indev);
+ if (driver->indev != NULL) {
+ free (driver->indev);
+ }
- if (driver->outdev != NULL)
- free(driver->outdev);
+ if (driver->outdev != NULL) {
+ free (driver->outdev);
+ }
- jack_driver_nt_finish((jack_driver_nt_t *) driver);
+ jack_driver_nt_finish ((jack_driver_nt_t*)driver);
- free(driver);
+ free (driver);
}
void
driver_finish (jack_driver_t *driver)
{
- sun_driver_delete ((sun_driver_t *)driver);
+ sun_driver_delete ((sun_driver_t*)driver);
}
static jack_driver_t *
sun_driver_new (char *indev, char *outdev, jack_client_t *client,
- jack_nframes_t sample_rate, jack_nframes_t period_size,
- jack_nframes_t nperiods, int bits,
- int capture_channels, int playback_channels,
- jack_nframes_t in_latency, jack_nframes_t out_latency,
- int ignorehwbuf)
+ jack_nframes_t sample_rate, jack_nframes_t period_size,
+ jack_nframes_t nperiods, int bits,
+ int capture_channels, int playback_channels,
+ jack_nframes_t in_latency, jack_nframes_t out_latency,
+ int ignorehwbuf)
{
sun_driver_t *driver;
- driver = (sun_driver_t *) malloc(sizeof(sun_driver_t));
- if (driver == NULL)
- {
- jack_error("sun_driver: malloc() failed: %s: %s@%i",
- strerror(errno), __FILE__, __LINE__);
+ driver = (sun_driver_t*)malloc (sizeof(sun_driver_t));
+ if (driver == NULL) {
+ jack_error ("sun_driver: malloc() failed: %s: %s@%i",
+ strerror (errno), __FILE__, __LINE__);
return NULL;
}
driver->engine = NULL;
- jack_driver_nt_init((jack_driver_nt_t *) driver);
-
- driver->nt_attach = (JackDriverNTAttachFunction) sun_driver_attach;
- driver->nt_detach = (JackDriverNTDetachFunction) sun_driver_detach;
- driver->read = (JackDriverReadFunction) sun_driver_read;
- driver->write = (JackDriverWriteFunction) sun_driver_write;
- driver->null_cycle = (JackDriverNullCycleFunction)
- sun_driver_null_cycle;
- driver->nt_bufsize = (JackDriverNTBufSizeFunction) sun_driver_bufsize;
- driver->nt_start = (JackDriverNTStartFunction) sun_driver_start;
- driver->nt_stop = (JackDriverNTStopFunction) sun_driver_stop;
- driver->nt_run_cycle = (JackDriverNTRunCycleFunction) sun_driver_run_cycle;
-
- if (indev != NULL)
- driver->indev = strdup(indev);
- if (outdev != NULL)
- driver->outdev = strdup(outdev);
+ jack_driver_nt_init ((jack_driver_nt_t*)driver);
+
+ driver->nt_attach = (JackDriverNTAttachFunction)sun_driver_attach;
+ driver->nt_detach = (JackDriverNTDetachFunction)sun_driver_detach;
+ driver->read = (JackDriverReadFunction)sun_driver_read;
+ driver->write = (JackDriverWriteFunction)sun_driver_write;
+ driver->null_cycle = (JackDriverNullCycleFunction)
+ sun_driver_null_cycle;
+ driver->nt_bufsize = (JackDriverNTBufSizeFunction)sun_driver_bufsize;
+ driver->nt_start = (JackDriverNTStartFunction)sun_driver_start;
+ driver->nt_stop = (JackDriverNTStopFunction)sun_driver_stop;
+ driver->nt_run_cycle = (JackDriverNTRunCycleFunction)sun_driver_run_cycle;
+
+ if (indev != NULL) {
+ driver->indev = strdup (indev);
+ }
+ if (outdev != NULL) {
+ driver->outdev = strdup (outdev);
+ }
driver->ignorehwbuf = ignorehwbuf;
@@ -1336,12 +1241,14 @@ sun_driver_new (char *indev, char *outdev, jack_client_t *client,
driver->sys_in_latency = in_latency;
driver->sys_out_latency = out_latency;
- set_period_size(driver, period_size);
-
- if (driver->indev == NULL)
- driver->indev = strdup(SUN_DRIVER_DEF_DEV);
- if (driver->outdev == NULL)
- driver->outdev = strdup(SUN_DRIVER_DEF_DEV);
+ set_period_size (driver, period_size);
+
+ if (driver->indev == NULL) {
+ driver->indev = strdup (SUN_DRIVER_DEF_DEV);
+ }
+ if (driver->outdev == NULL) {
+ driver->outdev = strdup (SUN_DRIVER_DEF_DEV);
+ }
driver->infd = -1;
driver->outfd = -1;
#if defined(AUDIO_ENCODING_SLINEAR)
@@ -1357,15 +1264,14 @@ sun_driver_new (char *indev, char *outdev, jack_client_t *client,
driver->iodelay = 0.0F;
driver->poll_last = driver->poll_next = 0;
- if (sun_driver_set_parameters (driver) < 0)
- {
- free(driver);
+ if (sun_driver_set_parameters (driver) < 0) {
+ free (driver);
return NULL;
}
driver->client = client;
- return (jack_driver_t *) driver;
+ return (jack_driver_t*)driver;
}
@@ -1381,24 +1287,22 @@ driver_get_descriptor ()
jack_driver_desc_t *desc;
jack_driver_param_desc_t *params;
- desc = (jack_driver_desc_t *) calloc(1, sizeof(jack_driver_desc_t));
- if (desc == NULL)
- {
- jack_error("sun_driver: calloc() failed: %s: %s@%i",
- strerror(errno), __FILE__, __LINE__);
+ desc = (jack_driver_desc_t*)calloc (1, sizeof(jack_driver_desc_t));
+ if (desc == NULL) {
+ jack_error ("sun_driver: calloc() failed: %s: %s@%i",
+ strerror (errno), __FILE__, __LINE__);
return NULL;
}
- strcpy(desc->name, driver_client_name);
+ strcpy (desc->name, driver_client_name);
desc->nparams = SUN_DRIVER_N_PARAMS;
- params = calloc(desc->nparams, sizeof(jack_driver_param_desc_t));
- if (params == NULL)
- {
- jack_error("sun_driver: calloc() failed: %s: %s@%i",
- strerror(errno), __FILE__, __LINE__);
+ params = calloc (desc->nparams, sizeof(jack_driver_param_desc_t));
+ if (params == NULL) {
+ jack_error ("sun_driver: calloc() failed: %s: %s@%i",
+ strerror (errno), __FILE__, __LINE__);
return NULL;
}
- memcpy(params, sun_params,
+ memcpy (params, sun_params,
desc->nparams * sizeof(jack_driver_param_desc_t));
desc->params = params;
@@ -1423,54 +1327,52 @@ driver_initialize (jack_client_t *client, JSList * params)
char *outdev;
int ignorehwbuf = 0;
- indev = strdup(SUN_DRIVER_DEF_DEV);
- outdev = strdup(SUN_DRIVER_DEF_DEV);
+ indev = strdup (SUN_DRIVER_DEF_DEV);
+ outdev = strdup (SUN_DRIVER_DEF_DEV);
pnode = params;
- while (pnode != NULL)
- {
- param = (const jack_driver_param_t *) pnode->data;
-
- switch (param->character)
- {
- case 'r':
- sample_rate = param->value.ui;
- break;
- case 'p':
- period_size = param->value.ui;
- break;
- case 'n':
- nperiods = param->value.ui;
- break;
- case 'w':
- bits = param->value.i;
- break;
- case 'i':
- capture_channels = param->value.ui;
- break;
- case 'o':
- playback_channels = param->value.ui;
- break;
- case 'C':
- indev = strdup(param->value.str);
- break;
- case 'P':
- outdev = strdup(param->value.str);
- break;
- case 'b':
- ignorehwbuf = 1;
- break;
- case 'I':
- in_latency = param->value.ui;
- break;
- case 'O':
- out_latency = param->value.ui;
- break;
+ while (pnode != NULL) {
+ param = (const jack_driver_param_t*)pnode->data;
+
+ switch (param->character) {
+ case 'r':
+ sample_rate = param->value.ui;
+ break;
+ case 'p':
+ period_size = param->value.ui;
+ break;
+ case 'n':
+ nperiods = param->value.ui;
+ break;
+ case 'w':
+ bits = param->value.i;
+ break;
+ case 'i':
+ capture_channels = param->value.ui;
+ break;
+ case 'o':
+ playback_channels = param->value.ui;
+ break;
+ case 'C':
+ indev = strdup (param->value.str);
+ break;
+ case 'P':
+ outdev = strdup (param->value.str);
+ break;
+ case 'b':
+ ignorehwbuf = 1;
+ break;
+ case 'I':
+ in_latency = param->value.ui;
+ break;
+ case 'O':
+ out_latency = param->value.ui;
+ break;
}
- pnode = jack_slist_next(pnode);
+ pnode = jack_slist_next (pnode);
}
-
+
return sun_driver_new (indev, outdev, client, sample_rate, period_size,
- nperiods, bits, capture_channels, playback_channels, in_latency,
- out_latency, ignorehwbuf);
+ nperiods, bits, capture_channels, playback_channels, in_latency,
+ out_latency, ignorehwbuf);
}
diff --git a/drivers/sun/sun_driver.h b/drivers/sun/sun_driver.h
index bd96674..8ee6850 100644
--- a/drivers/sun/sun_driver.h
+++ b/drivers/sun/sun_driver.h
@@ -1,28 +1,28 @@
/*
- Sun Audio API driver for Jack
- Copyright (C) 2008 Jacob Meuser <jakemsr@sdf.lonestar.org>
- Based heavily on oss_driver.h which came with the following
- copyright notice.
+ Sun Audio API driver for Jack
+ Copyright (C) 2008 Jacob Meuser <jakemsr@sdf.lonestar.org>
+ Based heavily on oss_driver.h which came with the following
+ copyright notice.
- Copyright (C) 2003-2007 Jussi Laako <jussi@sonarnerd.net>
+ Copyright (C) 2003-2007 Jussi Laako <jussi@sonarnerd.net>
- 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 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.
+ 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., 59 Temple Place, Suite 330, Boston,
- MA 02111-1307 USA
+ 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., 59 Temple Place, Suite 330, Boston,
+ MA 02111-1307 USA
-*/
+ */
#ifndef __JACK_SUN_DRIVER_H__
@@ -38,19 +38,18 @@
#include "driver.h"
-#define SUN_DRIVER_DEF_DEV "/dev/audio"
-#define SUN_DRIVER_DEF_FS 48000
-#define SUN_DRIVER_DEF_BLKSIZE 1024
-#define SUN_DRIVER_DEF_NPERIODS 2
-#define SUN_DRIVER_DEF_BITS 16
-#define SUN_DRIVER_DEF_INS 2
-#define SUN_DRIVER_DEF_OUTS 2
+#define SUN_DRIVER_DEF_DEV "/dev/audio"
+#define SUN_DRIVER_DEF_FS 48000
+#define SUN_DRIVER_DEF_BLKSIZE 1024
+#define SUN_DRIVER_DEF_NPERIODS 2
+#define SUN_DRIVER_DEF_BITS 16
+#define SUN_DRIVER_DEF_INS 2
+#define SUN_DRIVER_DEF_OUTS 2
typedef jack_default_audio_sample_t jack_sample_t;
-typedef struct _sun_driver
-{
+typedef struct _sun_driver {
JACK_DRIVER_NT_DECL
jack_nframes_t sample_rate;
diff --git a/example-clients b/example-clients
-Subproject 7fa089095c81e81dacd2554ae3184acc7f2d58e
+Subproject e74323c535876abca9a2293bd2ca426a3b91ff8
diff --git a/include/atomicity.h b/include/atomicity.h
index fb625ec..edf4ada 100644
--- a/include/atomicity.h
+++ b/include/atomicity.h
@@ -1,6 +1,6 @@
/*
Copyright (C) 2004 Jack O'Quin
-
+
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
@@ -15,7 +15,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
+ */
#ifndef __jack_atomicity_h__
#define __jack_atomicity_h__
diff --git a/include/bitset.h b/include/bitset.h
index f607815..4c89f9b 100644
--- a/include/bitset.h
+++ b/include/bitset.h
@@ -19,12 +19,12 @@
* 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.
@@ -33,8 +33,8 @@
#ifndef __bitset_h__
#define __bitset_h__
-#include <inttypes.h> /* POSIX standard fixed-size types */
-#include <assert.h> /* `#define NDEBUG' to disable */
+#include <inttypes.h> /* POSIX standard fixed-size types */
+#include <assert.h> /* `#define NDEBUG' to disable */
/* On some 64-bit machines, this implementation may be slightly
* inefficient, depending on how compilers allocate space for
@@ -45,67 +45,67 @@
typedef uint32_t _bitset_word_t;
typedef _bitset_word_t *bitset_t;
-#define WORD_SIZE(cardinality) (1+((cardinality)+31)/32)
-#define BYTE_SIZE(cardinality) (WORD_SIZE(cardinality)*sizeof(_bitset_word_t))
-#define WORD_INDEX(element) (1+(element)/32)
-#define BIT_INDEX(element) ((element)&037)
+#define WORD_SIZE(cardinality) (1 + ((cardinality) + 31) / 32)
+#define BYTE_SIZE(cardinality) (WORD_SIZE (cardinality) * sizeof(_bitset_word_t))
+#define WORD_INDEX(element) (1 + (element) / 32)
+#define BIT_INDEX(element) ((element) & 037)
static inline void
-bitset_add(bitset_t set, unsigned int element)
+bitset_add (bitset_t set, unsigned int element)
{
- assert(element < set[0]);
- set[WORD_INDEX(element)] |= (1 << BIT_INDEX(element));
+ assert (element < set[0]);
+ set[WORD_INDEX (element)] |= (1 << BIT_INDEX (element));
}
static inline void
-bitset_copy(bitset_t to_set, bitset_t from_set)
+bitset_copy (bitset_t to_set, bitset_t from_set)
{
- assert(to_set[0] == from_set[0]);
- memcpy(to_set, from_set, BYTE_SIZE(to_set[0]));
+ assert (to_set[0] == from_set[0]);
+ memcpy (to_set, from_set, BYTE_SIZE (to_set[0]));
}
static inline void
-bitset_create(bitset_t *set, unsigned int cardinality)
+bitset_create (bitset_t *set, unsigned int cardinality)
{
- *set = (bitset_t) calloc(WORD_SIZE(cardinality),
+ *set = (bitset_t)calloc (WORD_SIZE (cardinality),
sizeof(_bitset_word_t));
- assert(*set);
+ assert (*set);
*set[0] = cardinality;
}
static inline void
-bitset_destroy(bitset_t *set)
+bitset_destroy (bitset_t *set)
{
if (*set) {
- free(*set);
- *set = (bitset_t) 0;
+ free (*set);
+ *set = (bitset_t)0;
}
}
static inline int
-bitset_empty(bitset_t set)
+bitset_empty (bitset_t set)
{
int i;
_bitset_word_t result = 0;
- int nwords = WORD_SIZE(set[0]);
- for (i = 1; i < nwords; i++) {
+ int nwords = WORD_SIZE (set[0]);
+
+ for (i = 1; i < nwords; i++)
result |= set[i];
- }
- return (result == 0);
+ return result == 0;
}
static inline int
-bitset_contains(bitset_t set, unsigned int element)
+bitset_contains (bitset_t set, unsigned int element)
{
- assert(element < set[0]);
- return (0 != (set[WORD_INDEX(element)] & (1<<BIT_INDEX(element))));
+ assert (element < set[0]);
+ return 0 != (set[WORD_INDEX (element)] & (1 << BIT_INDEX (element)));
}
static inline void
-bitset_remove(bitset_t set, unsigned int element)
+bitset_remove (bitset_t set, unsigned int element)
{
- assert(element < set[0]);
- set[WORD_INDEX(element)] &= ~(1<<BIT_INDEX(element));
+ assert (element < set[0]);
+ set[WORD_INDEX (element)] &= ~(1 << BIT_INDEX (element));
}
#endif /* __bitset_h__ */
diff --git a/include/driver.h b/include/driver.h
index e483b5a..bc639f3 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2001 Paul Davis
+ Copyright (C) 2001 Paul Davis
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
@@ -15,7 +15,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
+ */
#ifndef __jack_driver_h__
#define __jack_driver_h__
@@ -26,53 +26,53 @@
#include "port.h"
#include "driver_interface.h"
-typedef float gain_t;
+typedef float gain_t;
typedef unsigned long channel_t;
-typedef enum {
+typedef enum {
Lock = 0x1,
NoLock = 0x2,
Sync = 0x4,
NoSync = 0x8
} ClockSyncStatus;
-typedef void (*ClockSyncListenerFunction)(channel_t,ClockSyncStatus,void*);
+typedef void (*ClockSyncListenerFunction)(channel_t, ClockSyncStatus, void*);
typedef struct {
- unsigned long id;
- ClockSyncListenerFunction function;
- void *arg;
+ unsigned long id;
+ ClockSyncListenerFunction function;
+ void *arg;
} ClockSyncListener;
struct _jack_engine;
struct _jack_driver;
-typedef int (*JackDriverAttachFunction)(struct _jack_driver *,
- struct _jack_engine *);
-typedef int (*JackDriverDetachFunction)(struct _jack_driver *,
- struct _jack_engine *);
-typedef int (*JackDriverReadFunction)(struct _jack_driver *,
- jack_nframes_t nframes);
-typedef int (*JackDriverWriteFunction)(struct _jack_driver *,
- jack_nframes_t nframes);
-typedef int (*JackDriverNullCycleFunction)(struct _jack_driver *,
- jack_nframes_t nframes);
-typedef int (*JackDriverStopFunction)(struct _jack_driver *);
-typedef int (*JackDriverStartFunction)(struct _jack_driver *);
-typedef int (*JackDriverBufSizeFunction)(struct _jack_driver *,
- jack_nframes_t nframes);
-/*
+typedef int (*JackDriverAttachFunction)(struct _jack_driver *,
+ struct _jack_engine *);
+typedef int (*JackDriverDetachFunction)(struct _jack_driver *,
+ struct _jack_engine *);
+typedef int (*JackDriverReadFunction)(struct _jack_driver *,
+ jack_nframes_t nframes);
+typedef int (*JackDriverWriteFunction)(struct _jack_driver *,
+ jack_nframes_t nframes);
+typedef int (*JackDriverNullCycleFunction)(struct _jack_driver *,
+ jack_nframes_t nframes);
+typedef int (*JackDriverStopFunction)(struct _jack_driver *);
+typedef int (*JackDriverStartFunction)(struct _jack_driver *);
+typedef int (*JackDriverBufSizeFunction)(struct _jack_driver *,
+ jack_nframes_t nframes);
+/*
Call sequence summary:
1) engine loads driver via runtime dynamic linking
- - calls jack_driver_load
- - we call dlsym for "driver_initialize" and execute it
+ - calls jack_driver_load
+ - we call dlsym for "driver_initialize" and execute it
2) engine attaches to driver
3) engine starts driver
4) driver runs its own thread, calling
while () {
driver->wait ();
- driver->engine->run_cycle ()
+ driver->engine->run_cycle ()
}
5) engine stops driver
6) engine detaches from driver
@@ -80,7 +80,7 @@ typedef int (*JackDriverBufSizeFunction)(struct _jack_driver *,
Note that stop/start may be called multiple times in the event of an
error return from the `wait' function.
-*/
+ */
typedef struct _jack_driver {
@@ -88,7 +88,7 @@ typedef struct _jack_driver {
each driver-specific structure using the JACK_DRIVER_DECL macro,
which is defined below. The comments that follow describe each
common field.
-
+
The driver should set this to be the interval it expects to elapse
between returning from the `wait' function. if set to zero, it
implies that the driver does not expect regular periodic wakeups.
@@ -106,7 +106,7 @@ typedef struct _jack_driver {
These are not used by the driver. They should not be written to or
modified in any way
-
+
void *handle;
struct _jack_internal_client *internal_client;
@@ -133,23 +133,23 @@ typedef struct _jack_driver {
JackDriverDetachFunction detach;
- The JACK engine will call this when it wants to wait until the
+ The JACK engine will call this when it wants to wait until the
driver decides that its time to process some data. the driver returns
- a count of the number of audioframes that can be processed.
+ a count of the number of audioframes that can be processed.
it should set the variable pointed to by `status' as follows:
zero: the wait completed normally, processing may begin
negative: the wait failed, and recovery is not possible
positive: the wait failed, and the driver stopped itself.
- a call to `start' will return the driver to
- a correct and known state.
+ a call to `start' will return the driver to
+ a correct and known state.
the driver should also fill out the `delayed_usecs' variable to
indicate any delay in its expected periodic execution. for example,
if it discovers that its return from poll(2) is later than it
expects it to be, it would place an estimate of the delay
- in this variable. the engine will use this to decide if it
+ in this variable. the engine will use this to decide if it
plans to continue execution.
JackDriverWaitFunction wait;
@@ -157,8 +157,8 @@ typedef struct _jack_driver {
The JACK engine will call this to ask the driver to move
data from its inputs to its output port buffers. it should
- return 0 to indicate successful completion, negative otherwise.
-
+ return 0 to indicate successful completion, negative otherwise.
+
This function will always be called after the wait function (above).
JackDriverReadFunction read;
@@ -166,8 +166,8 @@ typedef struct _jack_driver {
The JACK engine will call this to ask the driver to move
data from its input port buffers to its outputs. it should
- return 0 to indicate successful completion, negative otherwise.
-
+ return 0 to indicate successful completion, negative otherwise.
+
this function will always be called after the read function (above).
JackDriverWriteFunction write;
@@ -181,7 +181,7 @@ typedef struct _jack_driver {
JackDriverNullCycleFunction null_cycle;
-
+
The engine will call this when it plans to stop calling the `wait'
function for some period of time. the driver should take
appropriate steps to handle this (possibly no steps at all).
@@ -198,7 +198,7 @@ typedef struct _jack_driver {
at all). NOTE: The driver may wish to silence its playback buffers
(if any) from within this function or the function that actually
implements the change in state.
-
+
JackDriverStartFunction start;
The engine will call this to let the driver know that some client
@@ -206,48 +206,48 @@ typedef struct _jack_driver {
prior to this, and the start function after this one has returned.
JackDriverBufSizeFunction bufsize;
-*/
+ */
-/* define the fields here... */
+/* define the fields here... */
#define JACK_DRIVER_DECL \
- jack_time_t period_usecs; \
- jack_time_t last_wait_ust; \
- void *handle; \
- struct _jack_client_internal * internal_client; \
- void (*finish)(struct _jack_driver *);\
- JackDriverAttachFunction attach; \
- JackDriverDetachFunction detach; \
- JackDriverReadFunction read; \
- JackDriverWriteFunction write; \
- JackDriverNullCycleFunction null_cycle; \
- JackDriverStopFunction stop; \
- JackDriverStartFunction start; \
- JackDriverBufSizeFunction bufsize;
-
- JACK_DRIVER_DECL /* expand the macro */
+ jack_time_t period_usecs; \
+ jack_time_t last_wait_ust; \
+ void *handle; \
+ struct _jack_client_internal * internal_client; \
+ void (*finish)(struct _jack_driver *); \
+ JackDriverAttachFunction attach; \
+ JackDriverDetachFunction detach; \
+ JackDriverReadFunction read; \
+ JackDriverWriteFunction write; \
+ JackDriverNullCycleFunction null_cycle; \
+ JackDriverStopFunction stop; \
+ JackDriverStartFunction start; \
+ JackDriverBufSizeFunction bufsize;
+
+ JACK_DRIVER_DECL /* expand the macro */
} jack_driver_t;
-typedef jack_driver_desc_t * (*JackDriverDescFunction) ();
+typedef jack_driver_desc_t * (*JackDriverDescFunction)();
-void jack_driver_init (jack_driver_t *);
-void jack_driver_release (jack_driver_t *);
+void jack_driver_init(jack_driver_t *);
+void jack_driver_release(jack_driver_t *);
-jack_driver_t *jack_driver_load (int argc, char **argv);
-void jack_driver_unload (jack_driver_t *);
+jack_driver_t *jack_driver_load(int argc, char **argv);
+void jack_driver_unload(jack_driver_t *);
/****************************
- *** Non-Threaded Drivers ***
- ****************************/
+*** Non-Threaded Drivers ***
+****************************/
-/*
+/*
Call sequence summary:
1) engine loads driver via runtime dynamic linking
- - calls jack_driver_load
- - we call dlsym for "driver_initialize" and execute it
+ - calls jack_driver_load
+ - we call dlsym for "driver_initialize" and execute it
- driver_initialize calls jack_driver_nt_init
2) nt layer attaches to driver
3) nt layer starts driver
@@ -263,43 +263,43 @@ void jack_driver_unload (jack_driver_t *);
error return from the `wait' function.
-*/
+ */
struct _jack_driver_nt;
-typedef int (*JackDriverNTAttachFunction)(struct _jack_driver_nt *);
-typedef int (*JackDriverNTDetachFunction)(struct _jack_driver_nt *);
-typedef int (*JackDriverNTStopFunction)(struct _jack_driver_nt *);
-typedef int (*JackDriverNTStartFunction)(struct _jack_driver_nt *);
-typedef int (*JackDriverNTBufSizeFunction)(struct _jack_driver_nt *,
- jack_nframes_t nframes);
-typedef int (*JackDriverNTRunCycleFunction)(struct _jack_driver_nt *);
+typedef int (*JackDriverNTAttachFunction)(struct _jack_driver_nt *);
+typedef int (*JackDriverNTDetachFunction)(struct _jack_driver_nt *);
+typedef int (*JackDriverNTStopFunction)(struct _jack_driver_nt *);
+typedef int (*JackDriverNTStartFunction)(struct _jack_driver_nt *);
+typedef int (*JackDriverNTBufSizeFunction)(struct _jack_driver_nt *,
+ jack_nframes_t nframes);
+typedef int (*JackDriverNTRunCycleFunction)(struct _jack_driver_nt *);
typedef struct _jack_driver_nt {
#define JACK_DRIVER_NT_DECL \
- JACK_DRIVER_DECL \
- struct _jack_engine * engine; \
- volatile int nt_run; \
- pthread_t nt_thread; \
- pthread_mutex_t nt_run_lock; \
- JackDriverNTAttachFunction nt_attach; \
- JackDriverNTDetachFunction nt_detach; \
- JackDriverNTStopFunction nt_stop; \
- JackDriverNTStartFunction nt_start; \
- JackDriverNTBufSizeFunction nt_bufsize; \
- JackDriverNTRunCycleFunction nt_run_cycle;
+ JACK_DRIVER_DECL \
+ struct _jack_engine * engine; \
+ volatile int nt_run; \
+ pthread_t nt_thread; \
+ pthread_mutex_t nt_run_lock; \
+ JackDriverNTAttachFunction nt_attach; \
+ JackDriverNTDetachFunction nt_detach; \
+ JackDriverNTStopFunction nt_stop; \
+ JackDriverNTStartFunction nt_start; \
+ JackDriverNTBufSizeFunction nt_bufsize; \
+ JackDriverNTRunCycleFunction nt_run_cycle;
#define nt_read read
#define nt_write write
#define nt_null_cycle null_cycle
- JACK_DRIVER_NT_DECL
+ JACK_DRIVER_NT_DECL
} jack_driver_nt_t;
-void jack_driver_nt_init (jack_driver_nt_t * driver);
-void jack_driver_nt_finish (jack_driver_nt_t * driver);
+void jack_driver_nt_init(jack_driver_nt_t * driver);
+void jack_driver_nt_finish(jack_driver_nt_t * driver);
#endif /* __jack_driver_h__ */
diff --git a/include/driver_interface.h b/include/driver_interface.h
index 2cd0d15..d8ec1a3 100644
--- a/include/driver_interface.h
+++ b/include/driver_interface.h
@@ -1,21 +1,21 @@
/*
Copyright (C) 2003 Bob Ham <rah@bash.sh>
-
+
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
+ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
+ */
#ifndef __jack_driver_interface_h__
#define __jack_driver_interface_h__
@@ -33,82 +33,77 @@ extern "C" {
#define JACK_DRIVER_PARAM_NAME_MAX 15
#define JACK_DRIVER_PARAM_STRING_MAX 63
-#define JACK_CONSTRAINT_FLAG_RANGE ((uint32_t)1) /**< if set, constraint is a range (min-max) */
-#define JACK_CONSTRAINT_FLAG_STRICT ((uint32_t)2) /**< if set, constraint is strict, i.e. supplying non-matching value will not work */
-#define JACK_CONSTRAINT_FLAG_FAKE_VALUE ((uint32_t)4) /**< if set, values have no user meaningful meaning */
+#define JACK_CONSTRAINT_FLAG_RANGE ((uint32_t)1) /**< if set, constraint is a range (min-max) */
+#define JACK_CONSTRAINT_FLAG_STRICT ((uint32_t)2) /**< if set, constraint is strict, i.e. supplying non-matching value will not work */
+#define JACK_CONSTRAINT_FLAG_FAKE_VALUE ((uint32_t)4) /**< if set, values have no user meaningful meaning */
/** Driver parameter types */
-typedef enum
-{
- JackDriverParamInt = 1,
- JackDriverParamUInt,
- JackDriverParamChar,
- JackDriverParamString,
- JackDriverParamBool
+typedef enum {
+ JackDriverParamInt = 1,
+ JackDriverParamUInt,
+ JackDriverParamChar,
+ JackDriverParamString,
+ JackDriverParamBool
} jack_driver_param_type_t;
/** Driver parameter value */
-typedef union
-{
- uint32_t ui;
- int32_t i;
- char c;
- char str[JACK_DRIVER_PARAM_STRING_MAX+1];
+typedef union {
+ uint32_t ui;
+ int32_t i;
+ char c;
+ char str[JACK_DRIVER_PARAM_STRING_MAX + 1];
} jack_driver_param_value_t;
typedef struct {
- jack_driver_param_value_t value;
- char short_desc[64]; /**< A short (~30 chars) description for the user */
+ jack_driver_param_value_t value;
+ char short_desc[64]; /**< A short (~30 chars) description for the user */
} jack_driver_param_value_enum_t;
typedef struct {
- uint32_t flags; /**< JACK_CONSTRAINT_FLAG_XXX */
-
- union {
- struct {
- jack_driver_param_value_t min;
- jack_driver_param_value_t max;
- } range; /**< valid when JACK_CONSTRAINT_FLAG_RANGE flag is set */
-
- struct {
- uint32_t count;
- jack_driver_param_value_enum_t * possible_values_array;
- } enumeration; /**< valid when JACK_CONSTRAINT_FLAG_RANGE flag is not set */
- } constraint;
+ uint32_t flags; /**< JACK_CONSTRAINT_FLAG_XXX */
+
+ union {
+ struct {
+ jack_driver_param_value_t min;
+ jack_driver_param_value_t max;
+ } range; /**< valid when JACK_CONSTRAINT_FLAG_RANGE flag is set */
+
+ struct {
+ uint32_t count;
+ jack_driver_param_value_enum_t * possible_values_array;
+ } enumeration; /**< valid when JACK_CONSTRAINT_FLAG_RANGE flag is not set */
+ } constraint;
} jack_driver_param_constraint_desc_t;
/** A driver parameter descriptor */
-typedef struct
-{
- char name[JACK_DRIVER_NAME_MAX+1]; /**< The parameter's name */
- char character; /**< The parameter's character (for getopt, etc) */
- jack_driver_param_type_t type; /**< The parameter's type */
- jack_driver_param_value_t value; /**< The parameter's (default) value */
- jack_driver_param_constraint_desc_t * constraint; /**< Pointer to parameter constraint descriptor. NULL if there is no constraint */
- char short_desc[64]; /**< A short (~30 chars) description for the user */
- char long_desc[1024]; /**< A longer description for the user */
+typedef struct {
+ char name[JACK_DRIVER_NAME_MAX + 1]; /**< The parameter's name */
+ char character; /**< The parameter's character (for getopt, etc) */
+ jack_driver_param_type_t type; /**< The parameter's type */
+ jack_driver_param_value_t value; /**< The parameter's (default) value */
+ jack_driver_param_constraint_desc_t * constraint; /**< Pointer to parameter constraint descriptor. NULL if there is no constraint */
+ char short_desc[64]; /**< A short (~30 chars) description for the user */
+ char long_desc[1024]; /**< A longer description for the user */
} jack_driver_param_desc_t;
/** A driver parameter */
-typedef struct
-{
- char character;
- jack_driver_param_value_t value;
+typedef struct {
+ char character;
+ jack_driver_param_value_t value;
} jack_driver_param_t;
/** A struct for describing a jack driver */
-typedef struct
-{
- char name[JACK_DRIVER_NAME_MAX+1]; /**< The driver's canonical name */
- char file[PATH_MAX+1]; /**< The filename of the driver's shared object file */
- uint32_t nparams; /**< The number of parameters the driver has */
- jack_driver_param_desc_t * params; /**< An array of parameter descriptors */
-
+typedef struct {
+ char name[JACK_DRIVER_NAME_MAX + 1]; /**< The driver's canonical name */
+ char file[PATH_MAX + 1]; /**< The filename of the driver's shared object file */
+ uint32_t nparams; /**< The number of parameters the driver has */
+ jack_driver_param_desc_t * params; /**< An array of parameter descriptors */
+
} jack_driver_desc_t;
diff --git a/include/driver_parse.h b/include/driver_parse.h
index fe0cf56..8015140 100644
--- a/include/driver_parse.h
+++ b/include/driver_parse.h
@@ -1,22 +1,22 @@
/* -*- mode: c; c-file-style: "linux"; -*- */
/*
- Copyright (C) 2003 Bob Ham <rah@bash.sh
-
- 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.
+ Copyright (C) 2003 Bob Ham <rah@bash.sh
- 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.
+ 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.
- 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.
+ 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 __jack_driver_parse_h__
#define __jack_driver_parse_h__
@@ -43,10 +43,11 @@ jack_print_driver_options (jack_driver_desc_t * desc, FILE *file)
break;
case JackDriverParamString:
if (desc->params[i].value.str &&
- strcmp (desc->params[i].value.str, "") != 0)
+ strcmp (desc->params[i].value.str, "") != 0) {
sprintf (arg_default, "%s", desc->params[i].value.str);
- else
+ } else {
sprintf (arg_default, "none");
+ }
break;
case JackDriverParamBool:
sprintf (arg_default, "%s", desc->params[i].value.i ? "true" : "false");
@@ -66,7 +67,7 @@ jack_print_driver_param_usage (jack_driver_desc_t * desc, unsigned long param, F
{
fprintf (file, "Usage information for the '%s' parameter for driver '%s':\n",
desc->params[param].name, desc->name);
-
+
fprintf (file, "%s\n", desc->params[param].long_desc);
}
@@ -108,14 +109,14 @@ jack_parse_driver_params (jack_driver_desc_t * desc, int argc, char **argv, JSLi
/* set up the stuff for getopt */
- options = calloc (desc->nparams*3 + 1, sizeof (char));
- long_options = calloc (desc->nparams + 1, sizeof (struct option));
+ options = calloc (desc->nparams * 3 + 1, sizeof(char));
+ long_options = calloc (desc->nparams + 1, sizeof(struct option));
options_ptr = options;
for (i = 0; i < desc->nparams; i++) {
sprintf (options_ptr, "%c::", desc->params[i].character);
options_ptr += 3;
-
+
long_options[i].name = desc->params[i].name;
long_options[i].flag = NULL;
long_options[i].val = desc->params[i].character;
@@ -125,7 +126,7 @@ jack_parse_driver_params (jack_driver_desc_t * desc, int argc, char **argv, JSLi
/* create the params */
optind = 0;
opterr = 0;
- while ((opt = getopt_long(argc, argv, options, long_options, NULL)) != -1) {
+ while ((opt = getopt_long (argc, argv, options, long_options, NULL)) != -1) {
if (opt == ':' || opt == '?') {
if (opt == ':') {
@@ -145,12 +146,12 @@ jack_parse_driver_params (jack_driver_desc_t * desc, int argc, char **argv, JSLi
}
}
- driver_param = calloc (1, sizeof (jack_driver_param_t));
+ driver_param = calloc (1, sizeof(jack_driver_param_t));
driver_param->character = desc->params[param_index].character;
if (!optarg && optind < argc &&
- strlen(argv[optind]) &&
+ strlen (argv[optind]) &&
argv[optind][0] != '-') {
optarg = argv[optind];
}
@@ -186,7 +187,7 @@ jack_parse_driver_params (jack_driver_desc_t * desc, int argc, char **argv, JSLi
}
break;
}
- } else {
+ } else {
if (desc->params[param_index].type == JackDriverParamBool) {
driver_param->value.i = TRUE;
} else {
@@ -200,8 +201,9 @@ jack_parse_driver_params (jack_driver_desc_t * desc, int argc, char **argv, JSLi
free (options);
free (long_options);
- if (param_ptr)
+ if (param_ptr) {
*param_ptr = params;
+ }
return 0;
}
diff --git a/include/engine.h b/include/engine.h
index 69772e5..5106713 100644
--- a/include/engine.h
+++ b/include/engine.h
@@ -1,7 +1,7 @@
/* -*- mode: c; c-file-style: "bsd"; -*- */
/*
Copyright (C) 2001-2003 Paul Davis
-
+
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
@@ -16,7 +16,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
+ */
#ifndef __jack_engine_h__
#define __jack_engine_h__
@@ -30,30 +30,30 @@ struct _jack_client_internal;
struct _jack_port_internal;
/* Structures is allocated by the engine in local memory to keep track
- * of port buffers and connections.
+ * of port buffers and connections.
*/
typedef struct {
- jack_shm_info_t* shm_info;
- jack_shmsize_t offset;
+ jack_shm_info_t* shm_info;
+ jack_shmsize_t offset;
} jack_port_buffer_info_t;
/* The engine keeps an array of these in its local memory. */
typedef struct _jack_port_internal {
- struct _jack_port_shared *shared;
- JSList *connections;
- jack_port_buffer_info_t *buffer_info;
+ struct _jack_port_shared *shared;
+ JSList *connections;
+ jack_port_buffer_info_t *buffer_info;
} jack_port_internal_t;
/* The engine's internal port type structure. */
typedef struct _jack_port_buffer_list {
- pthread_mutex_t lock; /* only lock within server */
- JSList *freelist; /* list of free buffers */
- jack_port_buffer_info_t *info; /* jack_buffer_info_t array */
+ pthread_mutex_t lock; /* only lock within server */
+ JSList *freelist; /* list of free buffers */
+ jack_port_buffer_info_t *info; /* jack_buffer_info_t array */
} jack_port_buffer_list_t;
typedef struct _jack_reserved_name {
- jack_uuid_t uuid;
- char name[JACK_CLIENT_NAME_SIZE];
+ jack_uuid_t uuid;
+ char name[JACK_CLIENT_NAME_SIZE];
} jack_reserved_name_t;
#define JACKD_WATCHDOG_TIMEOUT 10000
@@ -61,167 +61,169 @@ typedef struct _jack_reserved_name {
/* The main engine structure in local memory. */
struct _jack_engine {
- jack_control_t *control;
-
- JSList *drivers;
- struct _jack_driver *driver;
- jack_driver_desc_t *driver_desc;
- JSList *driver_params;
-
- JSList *slave_drivers;
-
- /* these are "callbacks" made by the driver backend */
- int (*set_buffer_size) (struct _jack_engine *, jack_nframes_t frames);
- int (*set_sample_rate) (struct _jack_engine *, jack_nframes_t frames);
- int (*run_cycle) (struct _jack_engine *, jack_nframes_t nframes,
- float delayed_usecs);
- void (*delay) (struct _jack_engine *, float delayed_usecs);
- void (*transport_cycle_start) (struct _jack_engine *, jack_time_t time);
- void (*driver_exit) (struct _jack_engine *);
- jack_time_t (*get_microseconds)(void);
- /* "private" sections starts here */
-
- /* engine serialization -- use precedence for deadlock avoidance */
- pthread_mutex_t request_lock; /* precedes client_lock */
- pthread_rwlock_t client_lock;
- pthread_mutex_t port_lock;
- pthread_mutex_t problem_lock; /* must hold write lock on client_lock */
- int process_errors;
- int period_msecs;
-
- /* Time to wait for clients in msecs. Used when jackd is run
- * without realtime priority enabled. */
- int client_timeout_msecs;
-
- /* info on the shm segment containing this->control */
-
- jack_shm_info_t control_shm;
-
- /* address-space local port buffer and segment info,
- indexed by the port type_id
- */
- jack_port_buffer_list_t port_buffers[JACK_MAX_PORT_TYPES];
- jack_shm_info_t port_segment[JACK_MAX_PORT_TYPES];
-
- unsigned int port_max;
- pthread_t server_thread;
-
- int fds[2];
- int cleanup_fifo[2];
- size_t pfd_size;
- size_t pfd_max;
- struct pollfd *pfd;
- char fifo_prefix[PATH_MAX+1];
- int *fifo;
- unsigned long fifo_size;
-
- /* session handling */
- int session_reply_fd;
- int session_pending_replies;
-
- unsigned long external_client_cnt;
- int rtpriority;
- volatile char freewheeling;
- volatile char stop_freewheeling;
- jack_uuid_t fwclient;
- pthread_t freewheel_thread;
- char verbose;
- char do_munlock;
- const char *server_name;
- char temporary;
- int reordered;
- int feedbackcount;
- int removing_clients;
- pid_t wait_pid;
- int nozombies;
- int timeout_count_threshold;
- volatile int problems;
- volatile int timeout_count;
- volatile int new_clients_allowed;
-
- /* these lists are protected by `client_lock' */
- JSList *clients;
- JSList *clients_waiting;
- JSList *reserved_client_names;
-
- jack_port_internal_t *internal_ports;
- jack_client_internal_t *timebase_client;
- jack_port_buffer_info_t *silent_buffer;
- jack_client_internal_t *current_client;
+ jack_control_t *control;
+
+ JSList *drivers;
+ struct _jack_driver *driver;
+ jack_driver_desc_t *driver_desc;
+ JSList *driver_params;
+
+ JSList *slave_drivers;
+
+ /* these are "callbacks" made by the driver backend */
+ int (*set_buffer_size)(struct _jack_engine *, jack_nframes_t frames);
+ int (*set_sample_rate)(struct _jack_engine *, jack_nframes_t frames);
+ int (*run_cycle)(struct _jack_engine *, jack_nframes_t nframes,
+ float delayed_usecs);
+ void (*delay)(struct _jack_engine *, float delayed_usecs);
+ void (*transport_cycle_start)(struct _jack_engine *, jack_time_t time);
+ void (*driver_exit)(struct _jack_engine *);
+ jack_time_t (*get_microseconds)(void);
+ /* "private" sections starts here */
+
+ /* engine serialization -- use precedence for deadlock avoidance */
+ pthread_mutex_t request_lock; /* precedes client_lock */
+ pthread_rwlock_t client_lock;
+ pthread_mutex_t port_lock;
+ pthread_mutex_t problem_lock; /* must hold write lock on client_lock */
+ int process_errors;
+ int period_msecs;
+
+ /* Time to wait for clients in msecs. Used when jackd is run
+ * without realtime priority enabled. */
+ int client_timeout_msecs;
+
+ /* info on the shm segment containing this->control */
+
+ jack_shm_info_t control_shm;
+
+ /* address-space local port buffer and segment info,
+ indexed by the port type_id
+ */
+ jack_port_buffer_list_t port_buffers[JACK_MAX_PORT_TYPES];
+ jack_shm_info_t port_segment[JACK_MAX_PORT_TYPES];
+
+ unsigned int port_max;
+ pthread_t server_thread;
+
+ int fds[2];
+ int cleanup_fifo[2];
+ size_t pfd_size;
+ size_t pfd_max;
+ struct pollfd *pfd;
+ char fifo_prefix[PATH_MAX + 1];
+ int *fifo;
+ unsigned long fifo_size;
+
+ /* session handling */
+ int session_reply_fd;
+ int session_pending_replies;
+
+ unsigned long external_client_cnt;
+ int rtpriority;
+ volatile char freewheeling;
+ volatile char stop_freewheeling;
+ jack_uuid_t fwclient;
+ pthread_t freewheel_thread;
+ char verbose;
+ char do_munlock;
+ const char *server_name;
+ char temporary;
+ int reordered;
+ int feedbackcount;
+ int removing_clients;
+ pid_t wait_pid;
+ int nozombies;
+ int timeout_count_threshold;
+ volatile int problems;
+ volatile int timeout_count;
+ volatile int new_clients_allowed;
+
+ /* these lists are protected by `client_lock' */
+ JSList *clients;
+ JSList *clients_waiting;
+ JSList *reserved_client_names;
+
+ jack_port_internal_t *internal_ports;
+ jack_client_internal_t *timebase_client;
+ jack_port_buffer_info_t *silent_buffer;
+ jack_client_internal_t *current_client;
#define JACK_ENGINE_ROLLING_COUNT 32
#define JACK_ENGINE_ROLLING_INTERVAL 1024
- jack_time_t rolling_client_usecs[JACK_ENGINE_ROLLING_COUNT];
- int rolling_client_usecs_cnt;
- int rolling_client_usecs_index;
- int rolling_interval;
- float max_usecs;
- float spare_usecs;
+ jack_time_t rolling_client_usecs[JACK_ENGINE_ROLLING_COUNT];
+ int rolling_client_usecs_cnt;
+ int rolling_client_usecs_index;
+ int rolling_interval;
+ float max_usecs;
+ float spare_usecs;
+
+ int first_wakeup;
- int first_wakeup;
-
#ifdef JACK_USE_MACH_THREADS
- /* specific resources for server/client real-time thread communication */
- mach_port_t servertask, bp;
- int portnum;
+ /* specific resources for server/client real-time thread communication */
+ mach_port_t servertask, bp;
+ int portnum;
#endif
- /* used for port names munging */
- int audio_out_cnt;
- int audio_in_cnt;
- int midi_out_cnt;
- int midi_in_cnt;
+ /* used for port names munging */
+ int audio_out_cnt;
+ int audio_in_cnt;
+ int midi_out_cnt;
+ int midi_in_cnt;
};
/* public functions */
-jack_engine_t *jack_engine_new (int real_time, int real_time_priority,
- int do_mlock, int do_unlock,
- const char *server_name, int temporary,
- int verbose, int client_timeout,
- unsigned int port_max,
- pid_t waitpid, jack_nframes_t frame_time_offset, int nozombies,
- int timeout_count_threshold,
- JSList *drivers);
-void jack_engine_delete (jack_engine_t *);
-int jack_run (jack_engine_t *engine);
-int jack_wait (jack_engine_t *engine);
-int jack_engine_load_driver (jack_engine_t *engine,
- jack_driver_desc_t * driver_desc,
- JSList * driver_params);
-int jack_engine_load_slave_driver (jack_engine_t *engine,
- jack_driver_desc_t * driver_desc,
- JSList * driver_params);
-void jack_dump_configuration(jack_engine_t *engine, int take_lock);
+jack_engine_t *jack_engine_new(int real_time, int real_time_priority,
+ int do_mlock, int do_unlock,
+ const char *server_name, int temporary,
+ int verbose, int client_timeout,
+ unsigned int port_max,
+ pid_t waitpid, jack_nframes_t frame_time_offset, int nozombies,
+ int timeout_count_threshold,
+ JSList *drivers);
+void jack_engine_delete(jack_engine_t *);
+int jack_run(jack_engine_t *engine);
+int jack_wait(jack_engine_t *engine);
+int jack_engine_load_driver(jack_engine_t *engine,
+ jack_driver_desc_t * driver_desc,
+ JSList * driver_params);
+int jack_engine_load_slave_driver(jack_engine_t *engine,
+ jack_driver_desc_t * driver_desc,
+ JSList * driver_params);
+void jack_dump_configuration(jack_engine_t *engine, int take_lock);
/* private engine functions */
-void jack_engine_reset_rolling_usecs (jack_engine_t *engine);
-int internal_client_request (void* ptr, jack_request_t *request);
-int jack_get_fifo_fd (jack_engine_t *engine,
- unsigned int which_fifo);
+void jack_engine_reset_rolling_usecs(jack_engine_t *engine);
+int internal_client_request(void* ptr, jack_request_t *request);
+int jack_get_fifo_fd(jack_engine_t *engine,
+ unsigned int which_fifo);
extern jack_timer_type_t clock_source;
extern jack_client_internal_t *
-jack_client_internal_by_id (jack_engine_t *engine, jack_uuid_t id);
+jack_client_internal_by_id(jack_engine_t *engine, jack_uuid_t id);
-#define jack_rdlock_graph(e) { DEBUG ("acquiring graph read lock"); if (pthread_rwlock_rdlock (&e->client_lock)) abort(); }
-#define jack_lock_graph(e) { DEBUG ("acquiring graph write lock"); if (pthread_rwlock_wrlock (&e->client_lock)) abort(); }
+#define jack_rdlock_graph(e) { DEBUG ("acquiring graph read lock"); if (pthread_rwlock_rdlock (&e->client_lock)) { abort (); } }
+#define jack_lock_graph(e) { DEBUG ("acquiring graph write lock"); if (pthread_rwlock_wrlock (&e->client_lock)) { abort (); } }
#define jack_try_rdlock_graph(e) pthread_rwlock_tryrdlock (&e->client_lock)
-#define jack_unlock_graph(e) { DEBUG ("release graph lock"); if (pthread_rwlock_unlock (&e->client_lock)) abort(); }
+#define jack_unlock_graph(e) { DEBUG ("release graph lock"); if (pthread_rwlock_unlock (&e->client_lock)) { abort (); } }
#define jack_trylock_problems(e) pthread_mutex_trylock (&e->problem_lock)
-#define jack_lock_problems(e) { DEBUG ("acquiring problem lock"); if (pthread_mutex_lock (&e->problem_lock)) abort(); }
-#define jack_unlock_problems(e) { DEBUG ("release problem lock"); if (pthread_mutex_unlock (&e->problem_lock)) abort(); }
+#define jack_lock_problems(e) { DEBUG ("acquiring problem lock"); if (pthread_mutex_lock (&e->problem_lock)) { abort (); } }
+#define jack_unlock_problems(e) { DEBUG ("release problem lock"); if (pthread_mutex_unlock (&e->problem_lock)) { abort (); } }
#if 0
-static inline void jack_rdlock_graph (jack_engine_t* engine) {
+static inline void jack_rdlock_graph (jack_engine_t* engine)
+{
DEBUG ("acquiring graph read lock");
pthread_rwlock_rdlock (&engine->client_lock);
}
-static inline void jack_lock_graph (jack_engine_t* engine) {
+static inline void jack_lock_graph (jack_engine_t* engine)
+{
DEBUG ("acquiring graph lock");
pthread_rwlock_wrlock (&engine->client_lock);
}
@@ -232,7 +234,7 @@ static inline int jack_try_rdlock_graph (jack_engine_t *engine)
return pthread_rwlock_tryrdlock (&engine->client_lock);
}
-static inline void jack_unlock_graph (jack_engine_t* engine)
+static inline void jack_unlock_graph (jack_engine_t* engine)
{
DEBUG ("releasing graph lock");
pthread_rwlock_unlock (&engine->client_lock);
@@ -245,24 +247,24 @@ static inline unsigned int jack_power_of_two (unsigned int n)
}
/* Internal port handling interfaces for JACK engine. */
-void jack_port_clear_connections (jack_engine_t *engine,
- jack_port_internal_t *port);
-void jack_port_registration_notify (jack_engine_t *, jack_port_id_t, int);
-void jack_port_release (jack_engine_t *engine, jack_port_internal_t *);
-void jack_sort_graph (jack_engine_t *engine);
-int jack_stop_freewheeling (jack_engine_t* engine, int engine_exiting);
+void jack_port_clear_connections(jack_engine_t *engine,
+ jack_port_internal_t *port);
+void jack_port_registration_notify (jack_engine_t *, jack_port_id_t, int);
+void jack_port_release(jack_engine_t *engine, jack_port_internal_t *);
+void jack_sort_graph(jack_engine_t *engine);
+int jack_stop_freewheeling(jack_engine_t* engine, int engine_exiting);
jack_client_internal_t *
-jack_client_by_name (jack_engine_t *engine, const char *name);
+jack_client_by_name(jack_engine_t *engine, const char *name);
-int jack_deliver_event (jack_engine_t *, jack_client_internal_t *, const jack_event_t *, ...);
+int jack_deliver_event(jack_engine_t *, jack_client_internal_t *, const jack_event_t *, ...);
void
-jack_engine_signal_problems (jack_engine_t* engine);
+jack_engine_signal_problems(jack_engine_t* engine);
int
-jack_use_driver (jack_engine_t *engine, struct _jack_driver *driver);
+jack_use_driver(jack_engine_t *engine, struct _jack_driver *driver);
int
-jack_drivers_start (jack_engine_t *engine);
+jack_drivers_start(jack_engine_t *engine);
int
-jack_add_slave_driver (jack_engine_t *engine, struct _jack_driver *driver);
+jack_add_slave_driver(jack_engine_t *engine, struct _jack_driver *driver);
#endif /* __jack_engine_h__ */
diff --git a/include/hardware.h b/include/hardware.h
index 01aefca..3064d9e 100644
--- a/include/hardware.h
+++ b/include/hardware.h
@@ -1,6 +1,6 @@
/*
Copyright (C) 2001 Paul Davis
-
+
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
@@ -15,14 +15,14 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
+ */
#ifndef __jack_hardware_h__
#define __jack_hardware_h__
#include <jack/types.h>
-typedef enum {
+typedef enum {
AutoSync,
WordClock,
ClockMaster
@@ -48,18 +48,18 @@ typedef double (*JackHardwareGetHardwarePower)(jack_port_t *port, jack_nframes_t
typedef struct _jack_hardware {
- unsigned long capabilities;
- unsigned long input_monitor_mask;
+ unsigned long capabilities;
+ unsigned long input_monitor_mask;
- JackHardwareChangeSampleClockFunction change_sample_clock;
- JackHardwareSetInputMonitorMaskFunction set_input_monitor_mask;
- JackHardwareReleaseFunction release;
- JackHardwareGetHardwarePeak get_hardware_peak;
- JackHardwareGetHardwarePower get_hardware_power;
- void *private;
+ JackHardwareChangeSampleClockFunction change_sample_clock;
+ JackHardwareSetInputMonitorMaskFunction set_input_monitor_mask;
+ JackHardwareReleaseFunction release;
+ JackHardwareGetHardwarePeak get_hardware_peak;
+ JackHardwareGetHardwarePower get_hardware_power;
+ void *private;
} jack_hardware_t;
-jack_hardware_t * jack_hardware_new ();
+jack_hardware_t * jack_hardware_new();
#endif /* __jack_hardware_h__ */
diff --git a/include/internal.h b/include/internal.h
index 036d703..ed2202d 100644
--- a/include/internal.h
+++ b/include/internal.h
@@ -6,7 +6,7 @@
JACK_PROTOCOL_VERSION in configure.in.
Copyright (C) 2001-2003 Paul Davis
-
+
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
@@ -21,7 +21,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
+ */
#ifndef __jack_internal_h__
#define __jack_internal_h__
@@ -35,9 +35,9 @@
#include <sys/time.h>
/* Needed by <sysdeps/time.h> */
-extern void jack_error (const char *fmt, ...);
+extern void jack_error(const char *fmt, ...);
-extern void jack_info (const char *fmt, ...);
+extern void jack_info(const char *fmt, ...);
#include <jack/jack.h>
#include <jack/types.h>
@@ -55,8 +55,8 @@ typedef enum {
JACK_TIMER_HPET,
} jack_timer_type_t;
-void jack_init_time ();
-void jack_set_clock_source (jack_timer_type_t);
+void jack_init_time();
+void jack_set_clock_source (jack_timer_type_t);
const char* jack_clock_source_name (jack_timer_type_t);
#include <sysdeps/time.h>
@@ -73,31 +73,31 @@ const char* jack_clock_source_name (jack_timer_type_t);
#define PATH_MAX MAXPATHLEN
#else
#define PATH_MAX 1024
- #endif /* MAXPATHLEN */
-#endif /* !PATH_MAX */
+ #endif /* MAXPATHLEN */
+#endif /* !PATH_MAX */
#ifdef DEBUG_ENABLED
/* grab thread id instead of PID on linux */
#if defined(__gnu_linux__)
#ifdef gettid /* glibc has a version */
- #define GETTID() gettid()
+ #define GETTID() gettid ()
#else /* use our own version */
- #include <sys/syscall.h>
- #define GETTID() syscall(__NR_gettid)
+ #include <sys/syscall.h>
+ #define GETTID() syscall (__NR_gettid)
#endif
#else
- #define GETTID() getpid()
+ #define GETTID() getpid ()
#endif
-#define DEBUG(format,args...) \
- MESSAGE("jack:%5d:%" PRIu64 " %s:%s:%d: " format "", GETTID(), jack_get_microseconds(), __FILE__, __FUNCTION__, __LINE__ , ## args)
+#define DEBUG(format, args ...) \
+ MESSAGE ("jack:%5d:%" PRIu64 " %s:%s:%d: " format "", GETTID (), jack_get_microseconds (), __FILE__, __FUNCTION__, __LINE__, ## args)
#else
#if JACK_CPP_VARARGS_BROKEN
- #define DEBUG(format...)
+ #define DEBUG(format ...)
#else
- #define DEBUG(format,args...)
+ #define DEBUG(format, args ...)
#endif
#endif
@@ -109,129 +109,129 @@ const char* jack_clock_source_name (jack_timer_type_t);
* sends SIGUSR2 to the client.
*/
#ifdef DO_PREEMPTION_CHECKING
-#define CHECK_PREEMPTION(engine, onoff) \
+#define CHECK_PREEMPTION(engine, onoff) \
if ((engine)->real_time) gettimeofday (1, (onoff))
#else
#define CHECK_PREEMPTION(engine, onoff)
#endif
-#ifndef FALSE
-#define FALSE (0)
+#ifndef FALSE
+#define FALSE (0)
#endif
-#ifndef TRUE
-#define TRUE (1)
+#ifndef TRUE
+#define TRUE (1)
#endif
-typedef struct _jack_engine jack_engine_t;
+typedef struct _jack_engine jack_engine_t;
typedef struct _jack_request jack_request_t;
typedef void * dlhandle;
typedef enum {
- TransportCommandNone = 0,
- TransportCommandStart = 1,
- TransportCommandStop = 2,
+ TransportCommandNone = 0,
+ TransportCommandStart = 1,
+ TransportCommandStop = 2,
} transport_command_t;
typedef struct {
- volatile uint32_t guard1;
- volatile jack_nframes_t frames;
- volatile jack_time_t current_wakeup;
- volatile jack_time_t next_wakeup;
- volatile float period_usecs;
- volatile int32_t initialized;
- volatile uint32_t guard2;
-
+ volatile uint32_t guard1;
+ volatile jack_nframes_t frames;
+ volatile jack_time_t current_wakeup;
+ volatile jack_time_t next_wakeup;
+ volatile float period_usecs;
+ volatile int32_t initialized;
+ volatile uint32_t guard2;
+
/* not accessed by clients */
- int32_t reset_pending; /* xrun happened, deal with it */
- float filter_omega; /* set once, never altered */
+ int32_t reset_pending; /* xrun happened, deal with it */
+ float filter_omega; /* set once, never altered */
} POST_PACKED_STRUCTURE jack_frame_timer_t;
/* JACK engine shared memory data structure. */
typedef struct {
- jack_transport_state_t transport_state;
- volatile transport_command_t transport_cmd;
- transport_command_t previous_cmd; /* previous transport_cmd */
- jack_position_t current_time; /* position for current cycle */
- jack_position_t pending_time; /* position for next cycle */
- jack_position_t request_time; /* latest requested position */
- jack_unique_t prev_request; /* previous request unique ID */
- volatile _Atomic_word seq_number; /* unique ID sequence number */
- int8_t new_pos; /* new position this cycle */
- int8_t pending_pos; /* new position request pending */
- jack_nframes_t pending_frame; /* pending frame number */
- int32_t sync_clients; /* number of active_slowsync clients */
- int32_t sync_remain; /* number of them with sync_poll */
- jack_time_t sync_timeout;
- jack_time_t sync_time_left;
- jack_frame_timer_t frame_timer;
- int32_t internal;
- jack_timer_type_t clock_source;
- pid_t engine_pid;
- jack_nframes_t buffer_size;
- int8_t real_time;
- int8_t do_mlock;
- int8_t do_munlock;
- int32_t client_priority;
- int32_t max_client_priority;
- int32_t has_capabilities;
- float cpu_load;
- float xrun_delayed_usecs;
- float max_delayed_usecs;
- uint32_t port_max;
- int32_t engine_ok;
- jack_port_type_id_t n_port_types;
- jack_port_type_info_t port_types[JACK_MAX_PORT_TYPES];
- jack_port_shared_t ports[0];
+ jack_transport_state_t transport_state;
+ volatile transport_command_t transport_cmd;
+ transport_command_t previous_cmd; /* previous transport_cmd */
+ jack_position_t current_time; /* position for current cycle */
+ jack_position_t pending_time; /* position for next cycle */
+ jack_position_t request_time; /* latest requested position */
+ jack_unique_t prev_request; /* previous request unique ID */
+ volatile _Atomic_word seq_number; /* unique ID sequence number */
+ int8_t new_pos; /* new position this cycle */
+ int8_t pending_pos; /* new position request pending */
+ jack_nframes_t pending_frame; /* pending frame number */
+ int32_t sync_clients; /* number of active_slowsync clients */
+ int32_t sync_remain; /* number of them with sync_poll */
+ jack_time_t sync_timeout;
+ jack_time_t sync_time_left;
+ jack_frame_timer_t frame_timer;
+ int32_t internal;
+ jack_timer_type_t clock_source;
+ pid_t engine_pid;
+ jack_nframes_t buffer_size;
+ int8_t real_time;
+ int8_t do_mlock;
+ int8_t do_munlock;
+ int32_t client_priority;
+ int32_t max_client_priority;
+ int32_t has_capabilities;
+ float cpu_load;
+ float xrun_delayed_usecs;
+ float max_delayed_usecs;
+ uint32_t port_max;
+ int32_t engine_ok;
+ jack_port_type_id_t n_port_types;
+ jack_port_type_info_t port_types[JACK_MAX_PORT_TYPES];
+ jack_port_shared_t ports[0];
} POST_PACKED_STRUCTURE jack_control_t;
typedef enum {
- BufferSizeChange,
- SampleRateChange,
- AttachPortSegment,
- PortConnected,
- PortDisconnected,
- GraphReordered,
- PortRegistered,
- PortUnregistered,
- XRun,
- StartFreewheel,
- StopFreewheel,
- ClientRegistered,
- ClientUnregistered,
- SaveSession,
- LatencyCallback,
- PropertyChange,
- PortRename
+ BufferSizeChange,
+ SampleRateChange,
+ AttachPortSegment,
+ PortConnected,
+ PortDisconnected,
+ GraphReordered,
+ PortRegistered,
+ PortUnregistered,
+ XRun,
+ StartFreewheel,
+ StopFreewheel,
+ ClientRegistered,
+ ClientUnregistered,
+ SaveSession,
+ LatencyCallback,
+ PropertyChange,
+ PortRename
} JackEventType;
const char* jack_event_type_name (JackEventType);
typedef struct {
- JackEventType type;
- union {
- uint32_t n;
- char name[JACK_PORT_NAME_SIZE];
- jack_port_id_t port_id;
- jack_port_id_t self_id;
- jack_uuid_t uuid;
- } x;
- union {
- uint32_t n;
- jack_port_type_id_t ptid;
- jack_port_id_t other_id;
- uint32_t key_size; /* key data will follow the event structure */
- } y;
- union {
- char other_name[JACK_PORT_NAME_SIZE];
- jack_property_change_t property_change;
- } z;
+ JackEventType type;
+ union {
+ uint32_t n;
+ char name[JACK_PORT_NAME_SIZE];
+ jack_port_id_t port_id;
+ jack_port_id_t self_id;
+ jack_uuid_t uuid;
+ } x;
+ union {
+ uint32_t n;
+ jack_port_type_id_t ptid;
+ jack_port_id_t other_id;
+ uint32_t key_size; /* key data will follow the event structure */
+ } y;
+ union {
+ char other_name[JACK_PORT_NAME_SIZE];
+ jack_property_change_t property_change;
+ } z;
} POST_PACKED_STRUCTURE jack_event_t;
typedef enum {
@@ -250,112 +250,112 @@ typedef enum {
/* JACK client shared memory data structure. */
typedef volatile struct {
- jack_uuid_t uuid; /* w: engine r: engine and client */
- volatile jack_client_state_t state; /* w: engine and client r: engine */
- volatile char name[JACK_CLIENT_NAME_SIZE];
- volatile char session_command[JACK_PORT_NAME_SIZE];
- volatile jack_session_flags_t session_flags;
- volatile ClientType type; /* w: engine r: engine and client */
- volatile int8_t active; /* w: engine r: engine and client */
- volatile int8_t dead; /* r/w: engine */
- volatile int8_t timed_out; /* r/w: engine */
- volatile int8_t is_timebase; /* w: engine, r: engine and client */
- volatile int8_t timebase_new; /* w: engine and client, r: engine */
- volatile int8_t is_slowsync; /* w: engine, r: engine and client */
- volatile int8_t active_slowsync; /* w: engine, r: engine and client */
- volatile int8_t sync_poll; /* w: engine and client, r: engine */
- volatile int8_t sync_new; /* w: engine and client, r: engine */
- volatile pid_t pid; /* w: client r: engine; client pid */
- volatile pid_t pgrp; /* w: client r: engine; client pgrp */
- volatile uint64_t signalled_at;
- volatile uint64_t awake_at;
- volatile uint64_t finished_at;
- volatile int32_t last_status; /* w: client, r: engine and client */
-
- /* indicators for whether callbacks have been set for this client.
- We do not include ptrs to the callbacks here (or their arguments)
- so that we can avoid 32/64 bit pointer size mismatches between
- the jack server and a client. The pointers are in the client-
- local structure which is part of the libjack compiled for
- either 32 bit or 64 bit clients.
- */
- volatile uint8_t process_cbset;
- volatile uint8_t thread_init_cbset;
- volatile uint8_t bufsize_cbset;
- volatile uint8_t srate_cbset;
- volatile uint8_t port_register_cbset;
- volatile uint8_t port_connect_cbset;
- volatile uint8_t graph_order_cbset;
- volatile uint8_t xrun_cbset;
- volatile uint8_t sync_cb_cbset;
- volatile uint8_t timebase_cb_cbset;
- volatile uint8_t freewheel_cb_cbset;
- volatile uint8_t client_register_cbset;
- volatile uint8_t thread_cb_cbset;
- volatile uint8_t session_cbset;
- volatile uint8_t latency_cbset;
- volatile uint8_t property_cbset;
- volatile uint8_t port_rename_cbset;
+ jack_uuid_t uuid; /* w: engine r: engine and client */
+ volatile jack_client_state_t state; /* w: engine and client r: engine */
+ volatile char name[JACK_CLIENT_NAME_SIZE];
+ volatile char session_command[JACK_PORT_NAME_SIZE];
+ volatile jack_session_flags_t session_flags;
+ volatile ClientType type; /* w: engine r: engine and client */
+ volatile int8_t active; /* w: engine r: engine and client */
+ volatile int8_t dead; /* r/w: engine */
+ volatile int8_t timed_out; /* r/w: engine */
+ volatile int8_t is_timebase; /* w: engine, r: engine and client */
+ volatile int8_t timebase_new; /* w: engine and client, r: engine */
+ volatile int8_t is_slowsync; /* w: engine, r: engine and client */
+ volatile int8_t active_slowsync; /* w: engine, r: engine and client */
+ volatile int8_t sync_poll; /* w: engine and client, r: engine */
+ volatile int8_t sync_new; /* w: engine and client, r: engine */
+ volatile pid_t pid; /* w: client r: engine; client pid */
+ volatile pid_t pgrp; /* w: client r: engine; client pgrp */
+ volatile uint64_t signalled_at;
+ volatile uint64_t awake_at;
+ volatile uint64_t finished_at;
+ volatile int32_t last_status; /* w: client, r: engine and client */
+
+ /* indicators for whether callbacks have been set for this client.
+ We do not include ptrs to the callbacks here (or their arguments)
+ so that we can avoid 32/64 bit pointer size mismatches between
+ the jack server and a client. The pointers are in the client-
+ local structure which is part of the libjack compiled for
+ either 32 bit or 64 bit clients.
+ */
+ volatile uint8_t process_cbset;
+ volatile uint8_t thread_init_cbset;
+ volatile uint8_t bufsize_cbset;
+ volatile uint8_t srate_cbset;
+ volatile uint8_t port_register_cbset;
+ volatile uint8_t port_connect_cbset;
+ volatile uint8_t graph_order_cbset;
+ volatile uint8_t xrun_cbset;
+ volatile uint8_t sync_cb_cbset;
+ volatile uint8_t timebase_cb_cbset;
+ volatile uint8_t freewheel_cb_cbset;
+ volatile uint8_t client_register_cbset;
+ volatile uint8_t thread_cb_cbset;
+ volatile uint8_t session_cbset;
+ volatile uint8_t latency_cbset;
+ volatile uint8_t property_cbset;
+ volatile uint8_t port_rename_cbset;
} POST_PACKED_STRUCTURE jack_client_control_t;
typedef struct {
-
- uint32_t protocol_v; /* protocol version, must go first */
- int32_t load;
- ClientType type;
- jack_options_t options;
- jack_uuid_t uuid;
- char name[JACK_CLIENT_NAME_SIZE];
- char object_path[PATH_MAX+1];
- char object_data[1024];
+ uint32_t protocol_v; /* protocol version, must go first */
+ int32_t load;
+ ClientType type;
+ jack_options_t options;
+ jack_uuid_t uuid;
+
+ char name[JACK_CLIENT_NAME_SIZE];
+ char object_path[PATH_MAX + 1];
+ char object_data[1024];
} POST_PACKED_STRUCTURE jack_client_connect_request_t;
typedef struct {
- jack_status_t status;
+ jack_status_t status;
- jack_shm_registry_index_t client_shm_index;
- jack_shm_registry_index_t engine_shm_index;
+ jack_shm_registry_index_t client_shm_index;
+ jack_shm_registry_index_t engine_shm_index;
- char fifo_prefix[PATH_MAX+1];
+ char fifo_prefix[PATH_MAX + 1];
- int32_t realtime;
- int32_t realtime_priority;
+ int32_t realtime;
+ int32_t realtime_priority;
- char name[JACK_CLIENT_NAME_SIZE]; /* unique name, if assigned */
+ char name[JACK_CLIENT_NAME_SIZE]; /* unique name, if assigned */
- /* these are actually pointers, but they must
- be the same size regardless of whether the
- server and/or client are 64 bit or 32 bit.
- force them to be 64 bit.
- */
+ /* these are actually pointers, but they must
+ be the same size regardless of whether the
+ server and/or client are 64 bit or 32 bit.
+ force them to be 64 bit.
+ */
- uint64_t client_control;
- uint64_t engine_control;
+ uint64_t client_control;
+ uint64_t engine_control;
#ifdef JACK_USE_MACH_THREADS
- /* specific resources for server/client real-time thread communication */
- int32_t portnum;
+ /* specific resources for server/client real-time thread communication */
+ int32_t portnum;
#endif
} POST_PACKED_STRUCTURE jack_client_connect_result_t;
typedef struct {
- jack_uuid_t client_id;
+ jack_uuid_t client_id;
} POST_PACKED_STRUCTURE jack_client_connect_ack_request_t;
typedef struct {
- int8_t status;
+ int8_t status;
} POST_PACKED_STRUCTURE jack_client_connect_ack_result_t;
typedef enum {
RegisterPort = 1,
UnRegisterPort = 2,
ConnectPorts = 3,
- DisconnectPorts = 4,
+ DisconnectPorts = 4,
SetTimeBaseClient = 5,
ActivateClient = 6,
DeactivateClient = 7,
@@ -387,69 +387,69 @@ typedef enum {
} RequestType;
struct _jack_request {
-
- //RequestType type;
- uint32_t type;
- union {
- struct {
- char name[JACK_PORT_NAME_SIZE];
- char type[JACK_PORT_TYPE_SIZE];
- uint32_t flags;
- jack_shmsize_t buffer_size;
- jack_port_id_t port_id;
- jack_uuid_t client_id;
- } POST_PACKED_STRUCTURE port_info;
- struct {
- char source_port[JACK_PORT_NAME_SIZE];
- char destination_port[JACK_PORT_NAME_SIZE];
- } POST_PACKED_STRUCTURE connect;
- struct {
- char path[JACK_PORT_NAME_SIZE];
- jack_session_event_type_t type;
- char target[JACK_CLIENT_NAME_SIZE];
- } POST_PACKED_STRUCTURE session;
- struct {
- int32_t nports;
- const char **ports; /* this is only exposed to internal clients, so there
- is no 64/32 issue. external clients read the ports
- one by one from the server, and allocate their
- own "ports" array in their own address space.
-
- we are lucky, because this is part of a union
- whose other components are bigger than this one.
- otherwise it would change structure size when
- comparing the 64 and 32 bit versions.
- */
- } POST_PACKED_STRUCTURE port_connections;
- struct {
- jack_uuid_t client_id;
- int32_t conditional;
- } POST_PACKED_STRUCTURE timebase;
- struct {
- char name[JACK_CLIENT_NAME_SIZE];
- jack_uuid_t uuid;
- } POST_PACKED_STRUCTURE reservename;
- struct {
- //jack_options_t options;
- uint32_t options;
- jack_uuid_t uuid;
- char name[JACK_CLIENT_NAME_SIZE];
- char path[PATH_MAX+1];
- char init[JACK_LOAD_INIT_LIMIT];
- } POST_PACKED_STRUCTURE intclient;
- struct {
- jack_property_change_t change;
- jack_uuid_t uuid;
- size_t keylen;
- const char* key; /* not delivered inline to server, see oop_client_deliver_request() */
- } POST_PACKED_STRUCTURE property;
- jack_uuid_t client_id;
- jack_nframes_t nframes;
- jack_time_t timeout;
- pid_t cap_pid;
- char name[JACK_CLIENT_NAME_SIZE];
- } POST_PACKED_STRUCTURE x;
- int32_t status;
+
+ //RequestType type;
+ uint32_t type;
+ union {
+ struct {
+ char name[JACK_PORT_NAME_SIZE];
+ char type[JACK_PORT_TYPE_SIZE];
+ uint32_t flags;
+ jack_shmsize_t buffer_size;
+ jack_port_id_t port_id;
+ jack_uuid_t client_id;
+ } POST_PACKED_STRUCTURE port_info;
+ struct {
+ char source_port[JACK_PORT_NAME_SIZE];
+ char destination_port[JACK_PORT_NAME_SIZE];
+ } POST_PACKED_STRUCTURE connect;
+ struct {
+ char path[JACK_PORT_NAME_SIZE];
+ jack_session_event_type_t type;
+ char target[JACK_CLIENT_NAME_SIZE];
+ } POST_PACKED_STRUCTURE session;
+ struct {
+ int32_t nports;
+ const char **ports; /* this is only exposed to internal clients, so there
+ is no 64/32 issue. external clients read the ports
+ one by one from the server, and allocate their
+ own "ports" array in their own address space.
+
+ we are lucky, because this is part of a union
+ whose other components are bigger than this one.
+ otherwise it would change structure size when
+ comparing the 64 and 32 bit versions.
+ */
+ } POST_PACKED_STRUCTURE port_connections;
+ struct {
+ jack_uuid_t client_id;
+ int32_t conditional;
+ } POST_PACKED_STRUCTURE timebase;
+ struct {
+ char name[JACK_CLIENT_NAME_SIZE];
+ jack_uuid_t uuid;
+ } POST_PACKED_STRUCTURE reservename;
+ struct {
+ //jack_options_t options;
+ uint32_t options;
+ jack_uuid_t uuid;
+ char name[JACK_CLIENT_NAME_SIZE];
+ char path[PATH_MAX + 1];
+ char init[JACK_LOAD_INIT_LIMIT];
+ } POST_PACKED_STRUCTURE intclient;
+ struct {
+ jack_property_change_t change;
+ jack_uuid_t uuid;
+ size_t keylen;
+ const char* key; /* not delivered inline to server, see oop_client_deliver_request() */
+ } POST_PACKED_STRUCTURE property;
+ jack_uuid_t client_id;
+ jack_nframes_t nframes;
+ jack_time_t timeout;
+ pid_t cap_pid;
+ char name[JACK_CLIENT_NAME_SIZE];
+ } POST_PACKED_STRUCTURE x;
+ int32_t status;
} POST_PACKED_STRUCTURE;
/* Per-client structure allocated in the server's address space.
@@ -458,36 +458,36 @@ struct _jack_request {
typedef struct _jack_client_internal {
- jack_client_control_t *control;
-
- int request_fd;
- int event_fd;
- int subgraph_start_fd;
- int subgraph_wait_fd;
- JSList *ports; /* protected by engine->client_lock */
- JSList *truefeeds; /* protected by engine->client_lock */
- JSList *sortfeeds; /* protected by engine->client_lock */
- int fedcount;
- int tfedcount;
- jack_shm_info_t control_shm;
- unsigned long execution_order;
- struct _jack_client_internal *next_client; /* not a linked list! */
- dlhandle handle;
- int (*initialize)(jack_client_t*, const char*); /* int. clients only */
- void (*finish)(void *); /* internal clients only */
- int error;
-
- int session_reply_pending;
-
+ jack_client_control_t *control;
+
+ int request_fd;
+ int event_fd;
+ int subgraph_start_fd;
+ int subgraph_wait_fd;
+ JSList *ports; /* protected by engine->client_lock */
+ JSList *truefeeds; /* protected by engine->client_lock */
+ JSList *sortfeeds; /* protected by engine->client_lock */
+ int fedcount;
+ int tfedcount;
+ jack_shm_info_t control_shm;
+ unsigned long execution_order;
+ struct _jack_client_internal *next_client; /* not a linked list! */
+ dlhandle handle;
+ int (*initialize)(jack_client_t*, const char*); /* int. clients only */
+ void (*finish)(void *); /* internal clients only */
+ int error;
+
+ int session_reply_pending;
+
#ifdef JACK_USE_MACH_THREADS
- /* specific resources for server/client real-time thread communication */
- mach_port_t serverport;
- trivial_message message;
- int running;
- int portnum;
-#endif /* JACK_USE_MACH_THREADS */
-
- jack_client_t *private_client;
+ /* specific resources for server/client real-time thread communication */
+ mach_port_t serverport;
+ trivial_message message;
+ int running;
+ int portnum;
+#endif /* JACK_USE_MACH_THREADS */
+
+ jack_client_t *private_client;
} jack_client_internal_t;
typedef struct _jack_thread_arg {
@@ -499,21 +499,21 @@ typedef struct _jack_thread_arg {
pid_t cap_pid;
} jack_thread_arg_t;
-extern int jack_client_handle_port_connection (jack_client_t *client,
- jack_event_t *event);
-extern jack_client_t *jack_driver_client_new (jack_engine_t *,
- const char *client_name);
-extern jack_client_t *jack_client_alloc_internal (jack_client_control_t*,
- jack_engine_t*);
+extern int jack_client_handle_port_connection(jack_client_t *client,
+ jack_event_t *event);
+extern jack_client_t *jack_driver_client_new(jack_engine_t *,
+ const char *client_name);
+extern jack_client_t *jack_client_alloc_internal(jack_client_control_t*,
+ jack_engine_t*);
/* internal clients call this. it's defined in jack/engine.c */
-void handle_internal_client_request (jack_control_t*, jack_request_t*);
+void handle_internal_client_request(jack_control_t*, jack_request_t*);
extern char *jack_tmpdir;
-extern char *jack_user_dir (void);
+extern char *jack_user_dir(void);
-extern char *jack_server_dir (const char *server_name, char *server_dir);
+extern char *jack_server_dir(const char *server_name, char *server_dir);
extern void *jack_zero_filled_buffer;
@@ -521,46 +521,46 @@ extern jack_port_functions_t jack_builtin_audio_functions;
extern jack_port_type_info_t jack_builtin_port_types[];
-extern void jack_client_fix_port_buffers (jack_client_t *client);
+extern void jack_client_fix_port_buffers(jack_client_t *client);
-extern void jack_transport_copy_position (jack_position_t *from,
- jack_position_t *to);
-extern void jack_call_sync_client (jack_client_t *client);
+extern void jack_transport_copy_position(jack_position_t *from,
+ jack_position_t *to);
+extern void jack_call_sync_client(jack_client_t *client);
-extern void jack_call_timebase_master (jack_client_t *client);
+extern void jack_call_timebase_master(jack_client_t *client);
-extern char *jack_default_server_name (void);
+extern char *jack_default_server_name(void);
-void silent_jack_error_callback (const char *desc);
+void silent_jack_error_callback(const char *desc);
/* needed for port management */
-extern jack_port_t *jack_port_by_id_int (const jack_client_t *client,
- jack_port_id_t id, int* free);
+extern jack_port_t *jack_port_by_id_int(const jack_client_t *client,
+ jack_port_id_t id, int* free);
-extern jack_port_t *jack_port_by_name_int (jack_client_t *client,
- const char *port_name);
-extern int jack_port_name_equals (jack_port_shared_t* port, const char* target);
+extern jack_port_t *jack_port_by_name_int(jack_client_t *client,
+ const char *port_name);
+extern int jack_port_name_equals(jack_port_shared_t* port, const char* target);
/** Get the size (in bytes) of the data structure used to store
- * MIDI events internally.
+ * MIDI events internally.
*/
-extern size_t jack_midi_internal_event_size ();
+extern size_t jack_midi_internal_event_size();
-extern int jack_client_handle_latency_callback (jack_client_t *client, jack_event_t *event, int is_driver);
+extern int jack_client_handle_latency_callback(jack_client_t *client, jack_event_t *event, int is_driver);
#ifdef __GNUC__
-# define likely(x) __builtin_expect((x),1)
-# define unlikely(x) __builtin_expect((x),0)
+# define likely(x) __builtin_expect ((x), 1)
+# define unlikely(x) __builtin_expect ((x), 0)
#else
-# define likely(x) (x)
-# define unlikely(x) (x)
+# define likely(x) (x)
+# define unlikely(x) (x)
#endif
#ifdef VALGRIND_CLEAN
#include <string.h>
-#define VALGRIND_MEMSET(ptr,val,size) memset ((ptr),(val),(size))
+#define VALGRIND_MEMSET(ptr, val, size) memset ((ptr), (val), (size))
#else
-#define VALGRIND_MEMSET(ptr,val,size)
+#define VALGRIND_MEMSET(ptr, val, size)
#endif
#endif /* __jack_internal_h__ */
diff --git a/include/intsimd.h b/include/intsimd.h
index 2377bd1..ab5572c 100644
--- a/include/intsimd.h
+++ b/include/intsimd.h
@@ -1,21 +1,21 @@
/*
Copyright (C) 2005-2007 Jussi Laako
-
+
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 __jack_intsimd_h__
#define __jack_intsimd_h__
@@ -23,34 +23,34 @@
#ifdef USE_DYNSIMD
#if (defined(__i386__) || defined(__x86_64__))
#define ARCH_X86
-#endif /* __i386__ || __x86_64__ */
-#endif /* USE_DYNSIMD */
+#endif /* __i386__ || __x86_64__ */
+#endif /* USE_DYNSIMD */
#ifdef ARCH_X86
-#define ARCH_X86_SSE(x) ((x) & 0xff)
-#define ARCH_X86_HAVE_SSE2(x) (ARCH_X86_SSE(x) >= 2)
-#define ARCH_X86_3DNOW(x) ((x) >> 8)
-#define ARCH_X86_HAVE_3DNOW(x) (ARCH_X86_3DNOW(x))
+#define ARCH_X86_SSE(x) ((x) & 0xff)
+#define ARCH_X86_HAVE_SSE2(x) (ARCH_X86_SSE (x) >= 2)
+#define ARCH_X86_3DNOW(x) ((x) >> 8)
+#define ARCH_X86_HAVE_3DNOW(x) (ARCH_X86_3DNOW (x))
-typedef float v2sf __attribute__((vector_size(8)));
-typedef float v4sf __attribute__((vector_size(16)));
+typedef float v2sf __attribute__((vector_size (8)));
+typedef float v4sf __attribute__((vector_size (16)));
typedef v2sf * pv2sf;
typedef v4sf * pv4sf;
extern int cpu_type;
-int have_3dnow (void);
-int have_sse (void);
-void x86_3dnow_copyf (float *, const float *, int);
-void x86_3dnow_add2f (float *, const float *, int);
-void x86_sse_copyf (float *, const float *, int);
-void x86_sse_add2f (float *, const float *, int);
-void x86_sse_f2i (int *, const float *, int, float);
-void x86_sse_i2f (float *, const int *, int, float);
+int have_3dnow(void);
+int have_sse(void);
+void x86_3dnow_copyf(float *, const float *, int);
+void x86_3dnow_add2f(float *, const float *, int);
+void x86_sse_copyf(float *, const float *, int);
+void x86_sse_add2f(float *, const float *, int);
+void x86_sse_f2i(int *, const float *, int, float);
+void x86_sse_i2f(float *, const int *, int, float);
#endif /* ARCH_X86 */
-void jack_port_set_funcs (void);
+void jack_port_set_funcs(void);
#endif /* __jack_intsimd_h__ */
diff --git a/include/memops.h b/include/memops.h
index a5582bf..a9b63e7 100644
--- a/include/memops.h
+++ b/include/memops.h
@@ -1,5 +1,5 @@
/*
- Copyright (C) 1999-2000 Paul Davis
+ Copyright (C) 1999-2000 Paul Davis
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
@@ -15,14 +15,14 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
+ */
#ifndef __jack_memops_h__
#define __jack_memops_h__
#include <jack/types.h>
-typedef enum {
+typedef enum {
None,
Rectangular,
Triangular,
@@ -33,52 +33,52 @@ typedef enum {
#define DITHER_BUF_MASK 7
typedef struct {
- unsigned int depth;
- float rm1;
- unsigned int idx;
- float e[DITHER_BUF_SIZE];
+ unsigned int depth;
+ float rm1;
+ unsigned int idx;
+ float e[DITHER_BUF_SIZE];
} dither_state_t;
/* float functions */
-void sample_move_floatLE_sSs (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long dst_skip);
-void sample_move_dS_floatLE (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
+void sample_move_floatLE_sSs(jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long dst_skip);
+void sample_move_dS_floatLE(char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
/* integer functions */
-void sample_move_d32u24_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
-void sample_move_d32u24_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
-void sample_move_d24_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
-void sample_move_d24_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
-void sample_move_d16_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
-void sample_move_d16_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
-
-void sample_move_dither_rect_d32u24_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
-void sample_move_dither_rect_d32u24_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
-void sample_move_dither_tri_d32u24_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
-void sample_move_dither_tri_d32u24_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
-void sample_move_dither_shaped_d32u24_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
-void sample_move_dither_shaped_d32u24_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
-void sample_move_dither_rect_d24_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
-void sample_move_dither_rect_d24_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
-void sample_move_dither_tri_d24_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
-void sample_move_dither_tri_d24_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
-void sample_move_dither_shaped_d24_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
-void sample_move_dither_shaped_d24_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
-void sample_move_dither_rect_d16_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
-void sample_move_dither_rect_d16_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
-void sample_move_dither_tri_d16_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
-void sample_move_dither_tri_d16_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
-void sample_move_dither_shaped_d16_sSs (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
-void sample_move_dither_shaped_d16_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
-
-void sample_move_dS_s32u24s (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip);
-void sample_move_dS_s32u24 (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip);
-void sample_move_dS_s24s (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip);
-void sample_move_dS_s24 (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip);
-void sample_move_dS_s16s (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip);
-void sample_move_dS_s16 (jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip);
-
-void sample_merge_d16_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
-void sample_merge_d32u24_sS (char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
+void sample_move_d32u24_sSs(char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
+void sample_move_d32u24_sS(char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
+void sample_move_d24_sSs(char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
+void sample_move_d24_sS(char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
+void sample_move_d16_sSs(char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
+void sample_move_d16_sS(char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
+
+void sample_move_dither_rect_d32u24_sSs(char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
+void sample_move_dither_rect_d32u24_sS(char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
+void sample_move_dither_tri_d32u24_sSs(char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
+void sample_move_dither_tri_d32u24_sS(char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
+void sample_move_dither_shaped_d32u24_sSs(char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
+void sample_move_dither_shaped_d32u24_sS(char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
+void sample_move_dither_rect_d24_sSs(char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
+void sample_move_dither_rect_d24_sS(char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
+void sample_move_dither_tri_d24_sSs(char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
+void sample_move_dither_tri_d24_sS(char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
+void sample_move_dither_shaped_d24_sSs(char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
+void sample_move_dither_shaped_d24_sS(char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
+void sample_move_dither_rect_d16_sSs(char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
+void sample_move_dither_rect_d16_sS(char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
+void sample_move_dither_tri_d16_sSs(char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
+void sample_move_dither_tri_d16_sS(char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
+void sample_move_dither_shaped_d16_sSs(char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
+void sample_move_dither_shaped_d16_sS(char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
+
+void sample_move_dS_s32u24s(jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip);
+void sample_move_dS_s32u24(jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip);
+void sample_move_dS_s24s(jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip);
+void sample_move_dS_s24(jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip);
+void sample_move_dS_s16s(jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip);
+void sample_move_dS_s16(jack_default_audio_sample_t *dst, char *src, unsigned long nsamples, unsigned long src_skip);
+
+void sample_merge_d16_sS(char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
+void sample_merge_d32u24_sS(char *dst, jack_default_audio_sample_t *src, unsigned long nsamples, unsigned long dst_skip, dither_state_t *state);
static __inline__ void
sample_merge (jack_default_audio_sample_t *dst, jack_default_audio_sample_t *src, unsigned long cnt)
@@ -95,21 +95,21 @@ static __inline__ void
sample_memcpy (jack_default_audio_sample_t *dst, jack_default_audio_sample_t *src, unsigned long cnt)
{
- memcpy (dst, src, cnt * sizeof (jack_default_audio_sample_t));
+ memcpy (dst, src, cnt * sizeof(jack_default_audio_sample_t));
}
-void memset_interleave (char *dst, char val, unsigned long bytes, unsigned long unit_bytes, unsigned long skip_bytes);
-void memcpy_fake (char *dst, char *src, unsigned long src_bytes, unsigned long foo, unsigned long bar);
+void memset_interleave(char *dst, char val, unsigned long bytes, unsigned long unit_bytes, unsigned long skip_bytes);
+void memcpy_fake(char *dst, char *src, unsigned long src_bytes, unsigned long foo, unsigned long bar);
-void memcpy_interleave_d16_s16 (char *dst, char *src, unsigned long src_bytes, unsigned long dst_skip_bytes, unsigned long src_skip_bytes);
-void memcpy_interleave_d24_s24 (char *dst, char *src, unsigned long src_bytes, unsigned long dst_skip_bytes, unsigned long src_skip_bytes);
-void memcpy_interleave_d32_s32 (char *dst, char *src, unsigned long src_bytes, unsigned long dst_skip_bytes, unsigned long src_skip_bytes);
+void memcpy_interleave_d16_s16(char *dst, char *src, unsigned long src_bytes, unsigned long dst_skip_bytes, unsigned long src_skip_bytes);
+void memcpy_interleave_d24_s24(char *dst, char *src, unsigned long src_bytes, unsigned long dst_skip_bytes, unsigned long src_skip_bytes);
+void memcpy_interleave_d32_s32(char *dst, char *src, unsigned long src_bytes, unsigned long dst_skip_bytes, unsigned long src_skip_bytes);
-void merge_memcpy_interleave_d16_s16 (char *dst, char *src, unsigned long src_bytes, unsigned long dst_skip_bytes, unsigned long src_skip_bytes);
-void merge_memcpy_interleave_d24_s24 (char *dst, char *src, unsigned long src_bytes, unsigned long dst_skip_bytes, unsigned long src_skip_bytes);
-void merge_memcpy_interleave_d32_s32 (char *dst, char *src, unsigned long src_bytes, unsigned long dst_skip_bytes, unsigned long src_skip_bytes);
+void merge_memcpy_interleave_d16_s16(char *dst, char *src, unsigned long src_bytes, unsigned long dst_skip_bytes, unsigned long src_skip_bytes);
+void merge_memcpy_interleave_d24_s24(char *dst, char *src, unsigned long src_bytes, unsigned long dst_skip_bytes, unsigned long src_skip_bytes);
+void merge_memcpy_interleave_d32_s32(char *dst, char *src, unsigned long src_bytes, unsigned long dst_skip_bytes, unsigned long src_skip_bytes);
-void merge_memcpy_d16_s16 (char *dst, char *src, unsigned long src_bytes, unsigned long foo, unsigned long bar);
-void merge_memcpy_d32_s32 (char *dst, char *src, unsigned long src_bytes, unsigned long foo, unsigned long bar);
+void merge_memcpy_d16_s16(char *dst, char *src, unsigned long src_bytes, unsigned long foo, unsigned long bar);
+void merge_memcpy_d32_s32(char *dst, char *src, unsigned long src_bytes, unsigned long foo, unsigned long bar);
#endif /* __jack_memops_h__ */
diff --git a/include/messagebuffer.h b/include/messagebuffer.h
index 18b8027..627e148 100644
--- a/include/messagebuffer.h
+++ b/include/messagebuffer.h
@@ -8,19 +8,19 @@
/*
* Copyright (C) 2004 Rui Nuno Capela, Steve Harris
- *
+ *
* 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
+ * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
@@ -28,17 +28,17 @@
#ifndef __jack_messagebuffer_h__
#define __jack_messagebuffer_h__
-#define MESSAGE(fmt,args...) jack_messagebuffer_add(fmt , ##args)
-#define VERBOSE(engine,fmt,args...) \
+#define MESSAGE(fmt, args ...) jack_messagebuffer_add (fmt, ## args)
+#define VERBOSE(engine, fmt, args ...) \
if ((engine)->verbose) \
- jack_messagebuffer_add(fmt , ##args)
+ jack_messagebuffer_add (fmt, ## args)
void jack_messagebuffer_init();
void jack_messagebuffer_exit();
-void jack_message_buffer_thread_init (void (*cb)(void*), void*);
+void jack_message_buffer_thread_init(void (*cb)(void*), void*);
void jack_messagebuffer_add(const char *fmt, ...);
-void jack_messagebuffer_thread_init (void (*cb)(void*), void* arg);
+void jack_messagebuffer_thread_init(void (*cb)(void*), void* arg);
#endif /* __jack_messagebuffer_h__ */
diff --git a/include/pool.h b/include/pool.h
index 41ad618..4cde852 100644
--- a/include/pool.h
+++ b/include/pool.h
@@ -1,28 +1,28 @@
/*
Copyright (C) 2001 Paul Davis
-
+
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
+ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
+ */
#ifndef __jack_pool_h__
#define __jack_pool_h__
#include <sys/types.h>
-void * jack_pool_alloc (size_t bytes);
-void jack_pool_release (void *);
+void * jack_pool_alloc(size_t bytes);
+void jack_pool_release(void *);
#endif /* __jack_pool_h__ */
diff --git a/include/port.h b/include/port.h
index 9ddcc1c..066b4b7 100644
--- a/include/port.h
+++ b/include/port.h
@@ -1,21 +1,21 @@
/*
Copyright (C) 2001 Paul Davis
-
+
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
+ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
+ */
#ifndef __jack_port_h__
#define __jack_port_h__
@@ -38,7 +38,7 @@
* - one other
*
* which is probably enough for more than just the foreseeable future.
- */
+ */
#define JACK_MAX_PORT_TYPES 4
#define JACK_AUDIO_PORT_TYPE 0
#define JACK_MIDI_PORT_TYPE 1
@@ -47,14 +47,14 @@
#define JACK_CLIENT_NAME_SIZE 33
/* JACK shared memory segments are limited to MAX_INT32, they can be
- * shared between 32-bit and 64-bit clients.
+ * shared between 32-bit and 64-bit clients.
*/
#define JACK_SHM_MAX (MAX_INT32)
typedef int32_t jack_port_type_id_t;
#define JACK_BACKEND_ALIAS "system"
-/* Port type structure.
+/* Port type structure.
*
* (1) One for each port type is part of the engine's jack_control_t
* shared memory structure.
@@ -66,71 +66,71 @@ typedef int32_t jack_port_type_id_t;
*/
typedef struct _jack_port_type_info {
- jack_port_type_id_t ptype_id;
- const char type_name[JACK_PORT_TYPE_SIZE];
+ jack_port_type_id_t ptype_id;
+ const char type_name[JACK_PORT_TYPE_SIZE];
- /* If == 1, then a buffer to handle nframes worth of data has
- * sizeof(jack_default_audio_sample_t) * nframes bytes.
- *
- * If > 1, the buffer allocated for input mixing will be
- * this value times sizeof(jack_default_audio_sample_t)
- * * nframes bytes in size. For non-audio data types,
- * it may have a different value.
- *
- * If < 0, the value should be ignored, and buffer_size
- * should be used.
- */
- int32_t buffer_scale_factor;
+ /* If == 1, then a buffer to handle nframes worth of data has
+ * sizeof(jack_default_audio_sample_t) * nframes bytes.
+ *
+ * If > 1, the buffer allocated for input mixing will be
+ * this value times sizeof(jack_default_audio_sample_t)
+ * * nframes bytes in size. For non-audio data types,
+ * it may have a different value.
+ *
+ * If < 0, the value should be ignored, and buffer_size
+ * should be used.
+ */
+ int32_t buffer_scale_factor;
- /* ignored unless buffer_scale_factor is < 0. see above */
- jack_shmsize_t buffer_size;
+ /* ignored unless buffer_scale_factor is < 0. see above */
+ jack_shmsize_t buffer_size;
- jack_shm_registry_index_t shm_registry_index;
+ jack_shm_registry_index_t shm_registry_index;
- jack_shmsize_t zero_buffer_offset;
+ jack_shmsize_t zero_buffer_offset;
} POST_PACKED_STRUCTURE jack_port_type_info_t;
/* Allocated by the engine in shared memory. */
typedef struct _jack_port_shared {
- jack_port_type_id_t ptype_id; /* index into port type array */
- jack_shmsize_t offset; /* buffer offset in shm segment */
- jack_port_id_t id; /* index into engine port array */
- jack_uuid_t uuid;
- uint32_t flags;
- char name[JACK_CLIENT_NAME_SIZE+JACK_PORT_NAME_SIZE];
- char alias1[JACK_CLIENT_NAME_SIZE+JACK_PORT_NAME_SIZE];
- char alias2[JACK_CLIENT_NAME_SIZE+JACK_PORT_NAME_SIZE];
- jack_uuid_t client_id; /* who owns me */
-
- volatile jack_nframes_t latency;
- volatile jack_nframes_t total_latency;
- volatile jack_latency_range_t playback_latency;
- volatile jack_latency_range_t capture_latency;
- volatile uint8_t monitor_requests;
-
- char has_mixdown; /* port has a mixdown function */
- char in_use;
- char unused; /* legacy locked field */
+ jack_port_type_id_t ptype_id; /* index into port type array */
+ jack_shmsize_t offset; /* buffer offset in shm segment */
+ jack_port_id_t id; /* index into engine port array */
+ jack_uuid_t uuid;
+ uint32_t flags;
+ char name[JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE];
+ char alias1[JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE];
+ char alias2[JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE];
+ jack_uuid_t client_id; /* who owns me */
+
+ volatile jack_nframes_t latency;
+ volatile jack_nframes_t total_latency;
+ volatile jack_latency_range_t playback_latency;
+ volatile jack_latency_range_t capture_latency;
+ volatile uint8_t monitor_requests;
+
+ char has_mixdown; /* port has a mixdown function */
+ char in_use;
+ char unused; /* legacy locked field */
} POST_PACKED_STRUCTURE jack_port_shared_t;
typedef struct _jack_port_functions {
- /* Function to initialize port buffer. Cannot be NULL.
- * NOTE: This must take a buffer rather than jack_port_t as it is called
- * in jack_engine_place_buffers() before any port creation.
- * A better solution is to make jack_engine_place_buffers to be type-specific,
- * but this works.
- */
- void (*buffer_init)(void *buffer, size_t size, jack_nframes_t);
+ /* Function to initialize port buffer. Cannot be NULL.
+ * NOTE: This must take a buffer rather than jack_port_t as it is called
+ * in jack_engine_place_buffers() before any port creation.
+ * A better solution is to make jack_engine_place_buffers to be type-specific,
+ * but this works.
+ */
+ void (*buffer_init)(void *buffer, size_t size, jack_nframes_t);
- /* Function to mixdown multiple inputs to a buffer. Can be NULL,
- * indicating that multiple input connections are not legal for
- * this data type.
- */
- void (*mixdown)(jack_port_t *, jack_nframes_t);
+ /* Function to mixdown multiple inputs to a buffer. Can be NULL,
+ * indicating that multiple input connections are not legal for
+ * this data type.
+ */
+ void (*mixdown)(jack_port_t *, jack_nframes_t);
} jack_port_functions_t;
@@ -146,14 +146,14 @@ jack_get_port_functions(jack_port_type_id_t ptid);
/* Allocated by the client in local memory. */
struct _jack_port {
- void **client_segment_base;
- void *mix_buffer;
- jack_port_type_info_t *type_info; /* shared memory type info */
- struct _jack_port_shared *shared; /* corresponding shm struct */
- struct _jack_port *tied; /* locally tied source port */
- jack_port_functions_t fptr;
- pthread_mutex_t connection_lock;
- JSList *connections;
+ void **client_segment_base;
+ void *mix_buffer;
+ jack_port_type_info_t *type_info; /* shared memory type info */
+ struct _jack_port_shared *shared; /* corresponding shm struct */
+ struct _jack_port *tied; /* locally tied source port */
+ jack_port_functions_t fptr;
+ pthread_mutex_t connection_lock;
+ JSList *connections;
};
/* Inline would be cleaner, but it needs to be fast even in
@@ -161,13 +161,13 @@ struct _jack_port {
* ports. jack_port_buffer() works for both input and output ports.
*/
#define jack_port_buffer(p) \
- ((void *) ((p)->mix_buffer? (p)->mix_buffer: \
- *(p)->client_segment_base + (p)->shared->offset))
+ ((void*)((p)->mix_buffer ? (p)->mix_buffer : \
+ *(p)->client_segment_base + (p)->shared->offset))
#define jack_output_port_buffer(p) \
- ((void *) (*(p)->client_segment_base + (p)->shared->offset))
+ ((void*)(*(p)->client_segment_base + (p)->shared->offset))
/* not for use by JACK applications */
-size_t jack_port_type_buffer_size (jack_port_type_info_t* port_type_info, jack_nframes_t nframes);
+size_t jack_port_type_buffer_size(jack_port_type_info_t* port_type_info, jack_nframes_t nframes);
#endif /* __jack_port_h__ */
diff --git a/include/sanitycheck.h b/include/sanitycheck.h
index 5c98896..50c228b 100644
--- a/include/sanitycheck.h
+++ b/include/sanitycheck.h
@@ -16,7 +16,7 @@
*
**/
-int sanitycheck (int do_realtime_check,
- int do_freqscaling_check);
+int sanitycheck(int do_realtime_check,
+ int do_freqscaling_check);
#endif /* __jack_sanitycheck_h__ */
diff --git a/include/shm.h b/include/shm.h
index 8103ce9..950e735 100644
--- a/include/shm.h
+++ b/include/shm.h
@@ -5,12 +5,12 @@
#include <sys/types.h>
#include <jack/types.h>
-#define MAX_SERVERS 8 /* maximum concurrent servers */
-#define MAX_SHM_ID 256 /* generally about 16 per server */
-#define JACK_SERVER_NAME_SIZE 256 /* maximum length of server name */
-#define JACK_SHM_MAGIC 0x4a41434b /* shm magic number: "JACK" */
-#define JACK_SHM_NULL_INDEX -1 /* NULL SHM index */
-#define JACK_SHM_REGISTRY_INDEX -2 /* pseudo SHM index for registry */
+#define MAX_SERVERS 8 /* maximum concurrent servers */
+#define MAX_SHM_ID 256 /* generally about 16 per server */
+#define JACK_SERVER_NAME_SIZE 256 /* maximum length of server name */
+#define JACK_SHM_MAGIC 0x4a41434b /* shm magic number: "JACK" */
+#define JACK_SHM_NULL_INDEX -1 /* NULL SHM index */
+#define JACK_SHM_REGISTRY_INDEX -2 /* pseudo SHM index for registry */
/* On Mac OS X, SHM_NAME_MAX is the maximum length of a shared memory
@@ -21,21 +21,21 @@
#ifndef SHM_NAME_MAX
#define SHM_NAME_MAX NAME_MAX
#endif
-typedef char shm_name_t[SHM_NAME_MAX];
+typedef char shm_name_t[SHM_NAME_MAX];
typedef shm_name_t jack_shm_id_t;
#else /* System V SHM */
-typedef int jack_shm_id_t;
+typedef int jack_shm_id_t;
#endif /* SHM type */
/* shared memory type */
typedef enum {
- shm_POSIX = 1, /* POSIX shared memory */
- shm_SYSV = 2 /* System V shared memory */
+ shm_POSIX = 1, /* POSIX shared memory */
+ shm_SYSV = 2 /* System V shared memory */
} jack_shmtype_t;
typedef int16_t jack_shm_registry_index_t;
-/**
+/**
* A structure holding information about shared memory allocated by
* JACK. this persists across invocations of JACK, and can be used by
* multiple JACK servers. It contains no pointers and is valid across
@@ -45,31 +45,31 @@ typedef int16_t jack_shm_registry_index_t;
* server names, followed by an array of segment registry entries.
*/
typedef struct _jack_shm_server {
- pid_t pid; /* process ID */
- char name[JACK_SERVER_NAME_SIZE];
+ pid_t pid; /* process ID */
+ char name[JACK_SERVER_NAME_SIZE];
} jack_shm_server_t;
typedef struct _jack_shm_header {
- uint32_t magic; /* magic number */
- uint16_t protocol; /* JACK protocol version */
- jack_shmtype_t type; /* shm type */
- jack_shmsize_t size; /* total registry segment size */
- jack_shmsize_t hdr_len; /* size of header */
- jack_shmsize_t entry_len; /* size of registry entry */
- jack_shm_server_t server[MAX_SERVERS]; /* current server array */
+ uint32_t magic; /* magic number */
+ uint16_t protocol; /* JACK protocol version */
+ jack_shmtype_t type; /* shm type */
+ jack_shmsize_t size; /* total registry segment size */
+ jack_shmsize_t hdr_len; /* size of header */
+ jack_shmsize_t entry_len; /* size of registry entry */
+ jack_shm_server_t server[MAX_SERVERS]; /* current server array */
} jack_shm_header_t;
typedef struct _jack_shm_registry {
- jack_shm_registry_index_t index; /* offset into the registry */
- pid_t allocator; /* PID that created shm segment */
- jack_shmsize_t size; /* for POSIX unattach */
- jack_shm_id_t id; /* API specific, see above */
+ jack_shm_registry_index_t index; /* offset into the registry */
+ pid_t allocator; /* PID that created shm segment */
+ jack_shmsize_t size; /* for POSIX unattach */
+ jack_shm_id_t id; /* API specific, see above */
} jack_shm_registry_t;
-#define JACK_SHM_REGISTRY_SIZE (sizeof (jack_shm_header_t) \
- + sizeof (jack_shm_registry_t) * MAX_SHM_ID)
+#define JACK_SHM_REGISTRY_SIZE (sizeof(jack_shm_header_t) \
+ + sizeof(jack_shm_registry_t) * MAX_SHM_ID)
-/**
+/**
* a structure holding information about shared memory
* allocated by JACK. this version is valid only
* for a given address space. It contains a pointer
@@ -77,34 +77,35 @@ typedef struct _jack_shm_registry {
* attached to the address space.
*/
typedef struct _jack_shm_info {
- jack_shm_registry_index_t index; /* offset into the registry */
- void *attached_at; /* address where attached */
+ jack_shm_registry_index_t index; /* offset into the registry */
+ void *attached_at; /* address where attached */
} jack_shm_info_t;
/* utility functions used only within JACK */
-extern void jack_shm_copy_from_registry (jack_shm_info_t*,
+extern void jack_shm_copy_from_registry (jack_shm_info_t *,
jack_shm_registry_index_t);
-extern void jack_shm_copy_to_registry (jack_shm_info_t*,
- jack_shm_registry_index_t*);
+extern void jack_shm_copy_to_registry(jack_shm_info_t*,
+ jack_shm_registry_index_t*);
extern void jack_release_shm_info (jack_shm_registry_index_t);
-static inline char* jack_shm_addr (jack_shm_info_t* si) {
+static inline char* jack_shm_addr (jack_shm_info_t* si)
+{
return si->attached_at;
}
/* here beginneth the API */
-extern int jack_register_server (const char *server_name, int new_registry);
-extern void jack_unregister_server (const char *server_name);
+extern int jack_register_server(const char *server_name, int new_registry);
+extern void jack_unregister_server(const char *server_name);
-extern int jack_initialize_shm (const char *server_name);
-extern int jack_cleanup_shm (void);
+extern int jack_initialize_shm(const char *server_name);
+extern int jack_cleanup_shm(void);
-extern int jack_shmalloc (jack_shmsize_t size, jack_shm_info_t* result);
-extern void jack_release_shm (jack_shm_info_t*);
-extern void jack_destroy_shm (jack_shm_info_t*);
-extern int jack_attach_shm (jack_shm_info_t*);
-extern int jack_resize_shm (jack_shm_info_t*, jack_shmsize_t size);
+extern int jack_shmalloc(jack_shmsize_t size, jack_shm_info_t* result);
+extern void jack_release_shm(jack_shm_info_t*);
+extern void jack_destroy_shm(jack_shm_info_t*);
+extern int jack_attach_shm(jack_shm_info_t*);
+extern int jack_resize_shm(jack_shm_info_t*, jack_shmsize_t size);
#endif /* __jack_shm_h__ */
diff --git a/include/start.h b/include/start.h
index 00212e4..3048560 100644
--- a/include/start.h
+++ b/include/start.h
@@ -15,7 +15,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
+ */
#define PIPE_READ_FD (3)
#define PIPE_WRITE_FD (4)
diff --git a/include/systemtest.h b/include/systemtest.h
index 27e0ae7..9445372 100644
--- a/include/systemtest.h
+++ b/include/systemtest.h
@@ -5,9 +5,9 @@
* GPL, yabbadabba
*
* Set of functions to gather system information for the jack setup wizard.
- *
+ *
* @author Florian Faber, faber@faberman.de
- *
+ *
* @version 0.1 (2009-01-15) [FF]
* - initial version
*
@@ -15,7 +15,7 @@
/**
- * This function checks for the existence of known frequency scaling mechanisms
+ * This function checks for the existence of known frequency scaling mechanisms
* in this system.
*
* @returns 0 if the system has no frequency scaling capabilities non-0 otherwise.
@@ -24,8 +24,8 @@ int system_has_frequencyscaling();
/**
- * This function determines wether the CPU has a variable clock speed if frequency
- * scaling is available.
+ * This function determines wether the CPU has a variable clock speed if frequency
+ * scaling is available.
*
* @returns 0 if system doesn't use frequency scaling at the moment, non-0 otherwise
**/
@@ -38,7 +38,7 @@ int system_uses_frequencyscaling();
*
* @returns 1 if there appears to be such a line
**/
-int system_has_rtprio_limits_conf ();
+int system_has_rtprio_limits_conf();
/**
* Checks for the existence of the 'audio' group on this system
diff --git a/include/unlock.h b/include/unlock.h
index 3979efb..caa7e27 100644
--- a/include/unlock.h
+++ b/include/unlock.h
@@ -1,26 +1,26 @@
/* -*- mode: c; c-file-style: "bsd"; -*- */
/*
Copyright (C) 2001-2003 Paul Davis
-
+
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
+ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
+ */
#ifndef __jack_mlock_h__
#define __jack_mlock_h__
-extern void cleanup_mlock (void);
+extern void cleanup_mlock(void);
#endif /* __jack_mlock_h__ */
diff --git a/include/varargs.h b/include/varargs.h
index ae9e58a..d09e1a3 100644
--- a/include/varargs.h
+++ b/include/varargs.h
@@ -1,18 +1,18 @@
/*
* Copyright (C) 2004 Jack O'Quin
- *
+ *
* 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
+ * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
@@ -26,9 +26,9 @@ extern "C" {
/* variable argument structure */
typedef struct {
- char *server_name; /* server name */
- char *load_name; /* load module name */
- char *load_init; /* initialization string */
+ char *server_name; /* server name */
+ char *load_name; /* load module name */
+ char *load_init; /* initialization string */
char *sess_uuid;
} jack_varargs_t;
@@ -46,16 +46,20 @@ jack_varargs_parse (jack_options_t options, va_list ap, jack_varargs_t *va)
jack_varargs_init (va);
if ((options & JackServerName)) {
- char *sn = va_arg(ap, char *);
- if (sn)
+ char *sn = va_arg (ap, char *);
+ if (sn) {
va->server_name = sn;
+ }
+ }
+ if ((options & JackLoadName)) {
+ va->load_name = va_arg (ap, char *);
+ }
+ if ((options & JackLoadInit)) {
+ va->load_init = va_arg (ap, char *);
+ }
+ if ((options & JackSessionID)) {
+ va->sess_uuid = va_arg (ap, char *);
}
- if ((options & JackLoadName))
- va->load_name = va_arg(ap, char *);
- if ((options & JackLoadInit))
- va->load_init = va_arg(ap, char *);
- if ((options & JackSessionID))
- va->sess_uuid = va_arg(ap, char *);
}
#ifdef __cplusplus
diff --git a/jack b/jack
-Subproject 07f1ecf1ce119d861ec631cb4a6a81a1ab1e565
+Subproject a2536c8b348bbfb21ec53db901e7992d7ffef47
diff --git a/jackd/clientengine.c b/jackd/clientengine.c
index b783bb6..365e287 100644
--- a/jackd/clientengine.c
+++ b/jackd/clientengine.c
@@ -4,7 +4,7 @@
*
* Copyright (C) 2001-2003 Paul Davis
* Copyright (C) 2004 Jack O'Quin
- *
+ *
* 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
@@ -55,7 +55,7 @@ jack_client_disconnect_ports (jack_engine_t *engine,
/* call tree **** MUST HOLD *** engine->client_lock */
for (node = client->ports; node; node = jack_slist_next (node)) {
- port = (jack_port_internal_t *) node->data;
+ port = (jack_port_internal_t*)node->data;
jack_port_clear_connections (engine, port);
jack_port_registration_notify (engine, port->shared->id, FALSE);
jack_port_release (engine, port);
@@ -67,26 +67,26 @@ jack_client_disconnect_ports (jack_engine_t *engine,
client->truefeeds = 0;
client->sortfeeds = 0;
client->ports = 0;
-}
+}
int
jack_client_do_deactivate (jack_engine_t *engine,
jack_client_internal_t *client, int sort_graph)
{
/* caller must hold engine->client_lock and must have checked for and/or
- * cleared all connections held by client.
+ * cleared all connections held by client.
*/
- VERBOSE(engine,"+++ deactivate %s", client->control->name);
+ VERBOSE (engine, "+++ deactivate %s", client->control->name);
client->control->active = FALSE;
jack_transport_client_exit (engine, client);
if (!jack_client_is_internal (client) &&
- engine->external_client_cnt > 0) {
+ engine->external_client_cnt > 0) {
engine->external_client_cnt--;
}
-
+
if (sort_graph) {
jack_sort_graph (engine);
}
@@ -98,21 +98,21 @@ jack_load_client (jack_engine_t *engine, jack_client_internal_t *client,
const char *so_name)
{
const char *errstr;
- char path_to_so[PATH_MAX+1];
+ char path_to_so[PATH_MAX + 1];
+
+ if (!so_name) {
+ return -1;
+ }
- if (!so_name) {
- return -1;
- }
+ if (so_name[0] == '/') {
+ /* Absolute, use as-is, user beware ... */
+ snprintf (path_to_so, sizeof(path_to_so), "%s.so", so_name);
+ } else {
+ snprintf (path_to_so, sizeof(path_to_so), ADDON_DIR "/%s.so", so_name);
+ }
- if (so_name[0] == '/') {
- /* Absolute, use as-is, user beware ... */
- snprintf (path_to_so, sizeof (path_to_so), "%s.so", so_name);
- } else {
- snprintf (path_to_so, sizeof (path_to_so), ADDON_DIR "/%s.so", so_name);
- }
+ client->handle = dlopen (path_to_so, RTLD_NOW | RTLD_GLOBAL);
- client->handle = dlopen (path_to_so, RTLD_NOW|RTLD_GLOBAL);
-
if (client->handle == 0) {
if ((errstr = dlerror ()) != 0) {
jack_error ("%s", errstr);
@@ -131,9 +131,9 @@ jack_load_client (jack_engine_t *engine, jack_client_internal_t *client,
return -1;
}
- client->finish = (void (*)(void *)) dlsym (client->handle,
- "jack_finish");
-
+ client->finish = (void (*)(void *))dlsym (client->handle,
+ "jack_finish");
+
if ((errstr = dlerror ()) != 0) {
jack_error ("%s has no finish() function", so_name);
dlclose (client->handle);
@@ -177,17 +177,17 @@ jack_remove_client (jack_engine_t *engine, jack_client_internal_t *client)
JSList *node;
jack_uuid_t finalizer = JACK_UUID_EMPTY_INITIALIZER;
- jack_uuid_clear (&finalizer);
+ jack_uuid_clear (&finalizer);
/* caller must write-hold the client lock */
VERBOSE (engine, "removing client \"%s\"", client->control->name);
- if (client->control->type == ClientInternal) {
- /* unload it while its still a regular client */
+ if (client->control->type == ClientInternal) {
+ /* unload it while its still a regular client */
jack_client_unload (client);
- }
+ }
/* if its not already a zombie, make it so */
@@ -199,11 +199,11 @@ jack_remove_client (jack_engine_t *engine, jack_client_internal_t *client)
engine->session_pending_replies -= 1;
if (engine->session_pending_replies == 0) {
- if (write (engine->session_reply_fd, &finalizer, sizeof (finalizer))
- < (ssize_t) sizeof (finalizer)) {
+ if (write (engine->session_reply_fd, &finalizer, sizeof(finalizer))
+ < (ssize_t)sizeof(finalizer)) {
jack_error ("cannot write SessionNotify result "
- "to client via fd = %d (%s)",
- engine->session_reply_fd, strerror (errno));
+ "to client via fd = %d (%s)",
+ engine->session_reply_fd, strerror (errno));
}
engine->session_reply_fd = -1;
}
@@ -212,56 +212,56 @@ jack_remove_client (jack_engine_t *engine, jack_client_internal_t *client)
if (client->control->type == ClientExternal) {
/* try to force the server thread to return from poll */
-
+
close (client->event_fd);
close (client->request_fd);
- }
+ }
- VERBOSE (engine, "before: client list contains %d", jack_slist_length (engine->clients));
+ VERBOSE (engine, "before: client list contains %d", jack_slist_length (engine->clients));
for (node = engine->clients; node; node = jack_slist_next (node)) {
- if (jack_uuid_compare (((jack_client_internal_t *) node->data)->control->uuid, client->control->uuid) == 0) {
+ if (jack_uuid_compare (((jack_client_internal_t*)node->data)->control->uuid, client->control->uuid) == 0) {
engine->clients = jack_slist_remove_link (engine->clients, node);
jack_slist_free_1 (node);
- VERBOSE (engine, "removed from client list, via matching UUID");
+ VERBOSE (engine, "removed from client list, via matching UUID");
break;
}
}
- VERBOSE (engine, "after: client list contains %d", jack_slist_length (engine->clients));
+ VERBOSE (engine, "after: client list contains %d", jack_slist_length (engine->clients));
jack_client_delete (engine, client);
if (engine->temporary) {
- int external_clients = 0;
-
- /* count external clients only when deciding whether to shutdown */
-
- for (node = engine->clients; node; node = jack_slist_next (node)) {
- jack_client_internal_t* client = (jack_client_internal_t*) node->data;
- if (client->control->type == ClientExternal) {
- external_clients++;
- }
- }
-
- if (external_clients == 0) {
- if (engine->wait_pid >= 0) {
- /* block new clients from being created
- after we release the lock.
- */
- engine->new_clients_allowed = 0;
- /* tell the waiter we're done
- to initiate a normal shutdown.
- */
- VERBOSE (engine, "Kill wait pid to stop");
- kill (engine->wait_pid, SIGUSR2);
- /* unlock the graph so that the server thread can finish */
- jack_unlock_graph (engine);
- sleep (-1);
- } else {
- exit (0);
- }
- }
+ int external_clients = 0;
+
+ /* count external clients only when deciding whether to shutdown */
+
+ for (node = engine->clients; node; node = jack_slist_next (node)) {
+ jack_client_internal_t* client = (jack_client_internal_t*)node->data;
+ if (client->control->type == ClientExternal) {
+ external_clients++;
+ }
+ }
+
+ if (external_clients == 0) {
+ if (engine->wait_pid >= 0) {
+ /* block new clients from being created
+ after we release the lock.
+ */
+ engine->new_clients_allowed = 0;
+ /* tell the waiter we're done
+ to initiate a normal shutdown.
+ */
+ VERBOSE (engine, "Kill wait pid to stop");
+ kill (engine->wait_pid, SIGUSR2);
+ /* unlock the graph so that the server thread can finish */
+ jack_unlock_graph (engine);
+ sleep (-1);
+ } else {
+ exit (0);
+ }
+ }
}
}
@@ -276,10 +276,10 @@ jack_check_clients (jack_engine_t* engine, int with_timeout_check)
for (node = engine->clients; node; node = jack_slist_next (node)) {
- client = (jack_client_internal_t *) node->data;
+ client = (jack_client_internal_t*)node->data;
if (client->error) {
- VERBOSE (engine, "client %s already marked with error = %d\n", client->control->name, client->error);
+ VERBOSE (engine, "client %s already marked with error = %d\n", client->control->name, client->error);
errs++;
continue;
}
@@ -291,15 +291,15 @@ jack_check_clients (jack_engine_t* engine, int with_timeout_check)
* scheduler screwed us up and never woke up the
* client in time. sigh.
*/
-
- VERBOSE (engine, "checking client %s: awake at %" PRIu64 " finished at %" PRIu64,
+
+ VERBOSE (engine, "checking client %s: awake at %" PRIu64 " finished at %" PRIu64,
client->control->name,
client->control->awake_at,
client->control->finished_at);
-
+
if (client->control->awake_at > 0) {
if (client->control->finished_at == 0) {
- jack_time_t now = jack_get_microseconds();
+ jack_time_t now = jack_get_microseconds ();
if ((now - client->control->awake_at) < engine->driver->period_usecs) {
/* we give the client a bit of time, to finish the cycle
@@ -308,7 +308,7 @@ jack_check_clients (jack_engine_t* engine, int with_timeout_check)
struct timespec wait_time;
wait_time.tv_sec = 0;
wait_time.tv_nsec = (engine->driver->period_usecs - (now - client->control->awake_at)) * 1000;
- VERBOSE (engine, "client %s seems to have timed out. we may have mercy of %d ns." , client->control->name, (int) wait_time.tv_nsec );
+ VERBOSE (engine, "client %s seems to have timed out. we may have mercy of %d ns.", client->control->name, (int)wait_time.tv_nsec );
nanosleep (&wait_time, NULL);
}
@@ -329,7 +329,7 @@ jack_check_clients (jack_engine_t* engine, int with_timeout_check)
}
}
}
-
+
if (errs) {
jack_engine_signal_problems (engine);
}
@@ -351,47 +351,47 @@ jack_remove_clients (jack_engine_t* engine, int* exit_freewheeling_when_done)
/* remove all dead clients */
for (node = engine->clients; node; ) {
-
+
tmp = jack_slist_next (node);
-
- client = (jack_client_internal_t *) node->data;
- VERBOSE(engine, "client %s error status %d", client->control->name, client->error);
-
+ client = (jack_client_internal_t*)node->data;
+
+ VERBOSE (engine, "client %s error status %d", client->control->name, client->error);
+
if (client->error) {
-
+
if (engine->freewheeling && jack_uuid_compare (client->control->uuid, engine->fwclient) == 0) {
VERBOSE (engine, "freewheeling client has errors");
*exit_freewheeling_when_done = 1;
}
-
+
/* if we have a communication problem with the
client, remove it. otherwise, turn it into
a zombie. the client will/should realize
this and will close its sockets. then
we'll end up back here again and will
finally remove the client.
- */
+ */
if (client->error >= JACK_ERROR_WITH_SOCKETS) {
VERBOSE (engine, "removing failed "
"client %s state = %s errors"
- " = %d",
+ " = %d",
client->control->name,
jack_client_state_name (client),
client->error);
jack_remove_client (engine,
- (jack_client_internal_t *)
+ (jack_client_internal_t*)
node->data);
} else {
VERBOSE (engine, "client failure: "
"client %s state = %s errors"
- " = %d",
+ " = %d",
client->control->name,
jack_client_state_name (client),
client->error);
if (!engine->nozombies) {
jack_zombify_client (engine,
- (jack_client_internal_t *)
+ (jack_client_internal_t*)
node->data);
client->error = 0;
}
@@ -399,14 +399,14 @@ jack_remove_clients (jack_engine_t* engine, int* exit_freewheeling_when_done)
need_sort = TRUE;
}
-
+
node = tmp;
}
if (need_sort) {
jack_sort_graph (engine);
}
-
+
jack_engine_reset_rolling_usecs (engine);
VERBOSE (engine, "-- Removing failed clients ...");
@@ -421,10 +421,10 @@ jack_client_by_name (jack_engine_t *engine, const char *name)
jack_rdlock_graph (engine);
for (node = engine->clients; node; node = jack_slist_next (node)) {
- if (strcmp ((const char *) ((jack_client_internal_t *)
- node->data)->control->name,
+ if (strcmp ((const char*)((jack_client_internal_t*)
+ node->data)->control->name,
name) == 0) {
- client = (jack_client_internal_t *) node->data;
+ client = (jack_client_internal_t*)node->data;
break;
}
}
@@ -437,26 +437,26 @@ static int
jack_client_id_by_name (jack_engine_t *engine, const char *name, jack_uuid_t id)
{
JSList *node;
- int ret = -1;
+ int ret = -1;
- jack_uuid_clear (&id);
+ jack_uuid_clear (&id);
jack_rdlock_graph (engine);
for (node = engine->clients; node; node = jack_slist_next (node)) {
- if (strcmp ((const char *) ((jack_client_internal_t *)
- node->data)->control->name,
+ if (strcmp ((const char*)((jack_client_internal_t*)
+ node->data)->control->name,
name) == 0) {
- jack_client_internal_t *client =
- (jack_client_internal_t *) node->data;
+ jack_client_internal_t *client =
+ (jack_client_internal_t*)node->data;
jack_uuid_copy (&id, client->control->uuid);
- ret = 0;
+ ret = 0;
break;
}
}
jack_unlock_graph (engine);
- return ret;
+ return ret;
}
jack_client_internal_t *
@@ -469,8 +469,8 @@ jack_client_internal_by_id (jack_engine_t *engine, jack_uuid_t id)
for (node = engine->clients; node; node = jack_slist_next (node)) {
- if (jack_uuid_compare (((jack_client_internal_t *) node->data)->control->uuid, id) == 0) {
- client = (jack_client_internal_t *) node->data;
+ if (jack_uuid_compare (((jack_client_internal_t*)node->data)->control->uuid, id) == 0) {
+ client = (jack_client_internal_t*)node->data;
break;
}
}
@@ -479,14 +479,15 @@ jack_client_internal_by_id (jack_engine_t *engine, jack_uuid_t id)
}
int
-jack_client_name_reserved( jack_engine_t *engine, const char *name )
+jack_client_name_reserved ( jack_engine_t *engine, const char *name )
{
JSList *node;
- for (node = engine->reserved_client_names; node; node = jack_slist_next (node)) {
- jack_reserved_name_t *reservation = (jack_reserved_name_t *) node->data;
+
+ for (node = engine->reserved_client_names; node; node = jack_slist_next (node)) {
+ jack_reserved_name_t *reservation = (jack_reserved_name_t*)node->data;
if (!strcmp (reservation->name, name)) {
return 1;
- }
+ }
}
return 0;
}
@@ -503,7 +504,7 @@ jack_generate_unique_name (jack_engine_t *engine, char *name)
if (length > JACK_CLIENT_NAME_SIZE - 4) {
jack_error ("%s exists and is too long to make unique", name);
- return 1; /* failure */
+ return 1; /* failure */
}
/* generate a unique name by appending "-01".."-99" */
@@ -513,7 +514,7 @@ jack_generate_unique_name (jack_engine_t *engine, char *name)
name[tens] = '0';
name[ones] = '1';
name[length] = '\0';
- while (jack_client_by_name (engine, name) || jack_client_name_reserved( engine, name )) {
+ while (jack_client_by_name (engine, name) || jack_client_name_reserved ( engine, name )) {
if (name[ones] == '9') {
if (name[tens] == '9') {
jack_error ("client %s has 99 extra"
@@ -541,7 +542,7 @@ jack_client_name_invalid (jack_engine_t *engine, char *name,
* startup. There are no other clients at that point, anyway.
*/
- if (jack_client_by_name (engine, name) || jack_client_name_reserved(engine, name )) {
+ if (jack_client_by_name (engine, name) || jack_client_name_reserved (engine, name )) {
*status |= JackNameNotUnique;
@@ -552,7 +553,7 @@ jack_client_name_invalid (jack_engine_t *engine, char *name,
return TRUE;
}
- if (jack_generate_unique_name(engine, name)) {
+ if (jack_generate_unique_name (engine, name)) {
*status |= JackFailure;
return TRUE;
}
@@ -568,8 +569,8 @@ jack_setup_client_control (jack_engine_t *engine, int fd, ClientType type, const
{
jack_client_internal_t *client;
- client = (jack_client_internal_t *)
- malloc (sizeof (jack_client_internal_t));
+ client = (jack_client_internal_t*)
+ malloc (sizeof(jack_client_internal_t));
client->request_fd = fd;
client->event_fd = -1;
@@ -584,19 +585,19 @@ jack_setup_client_control (jack_engine_t *engine, int fd, ClientType type, const
client->private_client = NULL;
if (type != ClientExternal) {
-
- client->control = (jack_client_control_t *)
- malloc (sizeof (jack_client_control_t));
+
+ client->control = (jack_client_control_t*)
+ malloc (sizeof(jack_client_control_t));
} else {
- if (jack_shmalloc (sizeof (jack_client_control_t),
+ if (jack_shmalloc (sizeof(jack_client_control_t),
&client->control_shm)) {
- jack_error ("cannot create client control block for %s",
+ jack_error ("cannot create client control block for %s",
name);
free (client);
- return 0;
- }
+ return 0;
+ }
if (jack_attach_shm (&client->control_shm)) {
jack_error ("cannot attach to client control block "
@@ -606,8 +607,8 @@ jack_setup_client_control (jack_engine_t *engine, int fd, ClientType type, const
return 0;
}
- client->control = (jack_client_control_t *)
- jack_shm_addr (&client->control_shm);
+ client->control = (jack_client_control_t*)
+ jack_shm_addr (&client->control_shm);
}
client->control->type = type;
@@ -615,13 +616,13 @@ jack_setup_client_control (jack_engine_t *engine, int fd, ClientType type, const
client->control->dead = FALSE;
client->control->timed_out = 0;
- if (jack_uuid_empty (uuid)) {
- client->control->uuid = jack_client_uuid_generate ();
- } else {
- jack_uuid_copy (&client->control->uuid, uuid);
- }
+ if (jack_uuid_empty (uuid)) {
+ client->control->uuid = jack_client_uuid_generate ();
+ } else {
+ jack_uuid_copy (&client->control->uuid, uuid);
+ }
- strcpy ((char *) client->control->name, name);
+ strcpy ((char*)client->control->name, name);
client->subgraph_start_fd = -1;
client->subgraph_wait_fd = -1;
@@ -642,33 +643,33 @@ jack_setup_client_control (jack_engine_t *engine, int fd, ClientType type, const
#if 0
if (type != ClientExternal) {
- client->process = NULL;
- client->process_arg = NULL;
- client->bufsize = NULL;
- client->bufsize_arg = NULL;
- client->srate = NULL;
- client->srate_arg = NULL;
- client->xrun = NULL;
- client->xrun_arg = NULL;
- client->port_register = NULL;
- client->port_register_arg = NULL;
- client->port_connect = NULL;
- client->port_connect_arg = NULL;
- client->graph_order = NULL;
- client->graph_order_arg = NULL;
- client->client_register = NULL;
- client->client_register_arg = NULL;
- client->thread_cb = NULL;
- client->thread_cb_arg = NULL;
+ client->process = NULL;
+ client->process_arg = NULL;
+ client->bufsize = NULL;
+ client->bufsize_arg = NULL;
+ client->srate = NULL;
+ client->srate_arg = NULL;
+ client->xrun = NULL;
+ client->xrun_arg = NULL;
+ client->port_register = NULL;
+ client->port_register_arg = NULL;
+ client->port_connect = NULL;
+ client->port_connect_arg = NULL;
+ client->graph_order = NULL;
+ client->graph_order_arg = NULL;
+ client->client_register = NULL;
+ client->client_register_arg = NULL;
+ client->thread_cb = NULL;
+ client->thread_cb_arg = NULL;
}
#endif
jack_transport_client_new (client);
-
+
#ifdef JACK_USE_MACH_THREADS
- /* specific resources for server/client real-time thread
+ /* specific resources for server/client real-time thread
* communication */
- allocate_mach_serverport(engine, client);
- client->running = FALSE;
+ allocate_mach_serverport (engine, client);
+ client->running = FALSE;
#endif
return client;
@@ -679,16 +680,16 @@ jack_ensure_uuid_unique (jack_engine_t *engine, jack_uuid_t uuid)
{
JSList *node;
- if (jack_uuid_empty (uuid)) {
- return;
- }
+ if (jack_uuid_empty (uuid)) {
+ return;
+ }
jack_lock_graph (engine);
- for (node=engine->clients; node; node=jack_slist_next (node)) {
- jack_client_internal_t *client = (jack_client_internal_t *) node->data;
+ for (node = engine->clients; node; node = jack_slist_next (node)) {
+ jack_client_internal_t *client = (jack_client_internal_t*)node->data;
if (jack_uuid_compare (client->control->uuid, uuid) == 0) {
jack_uuid_clear (&uuid);
- }
+ }
}
jack_unlock_graph (engine);
}
@@ -696,24 +697,25 @@ jack_ensure_uuid_unique (jack_engine_t *engine, jack_uuid_t uuid)
/* set up all types of clients */
static jack_client_internal_t *
setup_client (jack_engine_t *engine, ClientType type, char *name,
- jack_uuid_t uuid,
+ jack_uuid_t uuid,
jack_options_t options, jack_status_t *status, int client_fd,
const char *object_path, const char *object_data)
{
/* called with the request_lock */
jack_client_internal_t *client;
- char bufx[64];
+ char bufx[64];
/* validate client name, generate a unique one if appropriate */
- if (jack_client_name_invalid (engine, name, options, status))
+ if (jack_client_name_invalid (engine, name, options, status)) {
return NULL;
+ }
- jack_ensure_uuid_unique (engine, uuid);
+ jack_ensure_uuid_unique (engine, uuid);
/* create a client struct for this name */
if ((client = jack_setup_client_control (engine, client_fd,
type, name, uuid)) == NULL) {
- *status |= (JackFailure|JackInitFailure);
+ *status |= (JackFailure | JackInitFailure);
jack_error ("cannot create new client object");
return NULL;
}
@@ -724,22 +726,22 @@ setup_client (jack_engine_t *engine, ClientType type, char *name,
jack_error ("cannot dynamically load client from"
" \"%s\"", object_path);
jack_client_delete (engine, client);
- *status |= (JackFailure|JackLoadFailure);
+ *status |= (JackFailure | JackLoadFailure);
return NULL;
}
}
- jack_uuid_unparse (client->control->uuid, bufx);
-
- VERBOSE (engine, "new client: %s, uuid = %s"
- " type %d @ %p fd = %d",
+ jack_uuid_unparse (client->control->uuid, bufx);
+
+ VERBOSE (engine, "new client: %s, uuid = %s"
+ " type %d @ %p fd = %d",
client->control->name, bufx,
type, client->control, client_fd);
- if (jack_client_is_internal(client)) {
+ if (jack_client_is_internal (client)) {
- // XXX: do i need to lock the graph here ?
- // i moved this one up in the init process, lets see what happens.
+ // XXX: do i need to lock the graph here ?
+ // i moved this one up in the init process, lets see what happens.
/* Internal clients need to make regular JACK API
* calls, which need a jack_client_t structure.
@@ -758,10 +760,10 @@ setup_client (jack_engine_t *engine, ClientType type, char *name,
/* add new client to the clients list */
jack_lock_graph (engine);
- engine->clients = jack_slist_prepend (engine->clients, client);
+ engine->clients = jack_slist_prepend (engine->clients, client);
jack_engine_reset_rolling_usecs (engine);
-
- if (jack_client_is_internal(client)) {
+
+ if (jack_client_is_internal (client)) {
jack_unlock_graph (engine);
@@ -782,7 +784,7 @@ setup_client (jack_engine_t *engine, ClientType type, char *name,
jack_lock_graph (engine);
jack_remove_client (engine, client);
jack_unlock_graph (engine);
- *status |= (JackFailure|JackInitFailure);
+ *status |= (JackFailure | JackInitFailure);
client = NULL;
//JOQ: not clear that all allocated
//storage has been cleaned up properly.
@@ -790,11 +792,11 @@ setup_client (jack_engine_t *engine, ClientType type, char *name,
pthread_mutex_lock (&engine->request_lock);
}
- } else { /* external client */
+ } else { /* external client */
jack_unlock_graph (engine);
}
-
+
return client;
}
@@ -804,13 +806,13 @@ jack_create_driver_client (jack_engine_t *engine, char *name)
jack_client_connect_request_t req;
jack_status_t status;
jack_client_internal_t *client;
- jack_uuid_t empty_uuid = JACK_UUID_EMPTY_INITIALIZER;
+ jack_uuid_t empty_uuid = JACK_UUID_EMPTY_INITIALIZER;
- VALGRIND_MEMSET(&empty_uuid, 0, sizeof(empty_uuid));
+ VALGRIND_MEMSET (&empty_uuid, 0, sizeof(empty_uuid));
- snprintf (req.name, sizeof (req.name), "%s", name);
+ snprintf (req.name, sizeof(req.name), "%s", name);
- jack_uuid_clear (&empty_uuid);
+ jack_uuid_clear (&empty_uuid);
pthread_mutex_lock (&engine->request_lock);
client = setup_client (engine, ClientDriver, name, empty_uuid, JackUseExactName,
@@ -825,19 +827,19 @@ handle_unload_client (jack_engine_t *engine, jack_uuid_t id)
{
/* called *without* the request_lock */
jack_client_internal_t *client;
- jack_status_t status = (JackNoSuchClient|JackFailure);
+ jack_status_t status = (JackNoSuchClient | JackFailure);
jack_lock_graph (engine);
if ((client = jack_client_internal_by_id (engine, id))) {
VERBOSE (engine, "unloading client \"%s\"",
client->control->name);
- if (client->control->type != ClientInternal) {
- status = JackFailure|JackInvalidOption;
- } else {
- jack_remove_client (engine, client);
- status = 0;
- }
+ if (client->control->type != ClientInternal) {
+ status = JackFailure | JackInvalidOption;
+ } else {
+ jack_remove_client (engine, client);
+ status = 0;
+ }
}
jack_unlock_graph (engine);
@@ -849,12 +851,13 @@ static char *
jack_get_reserved_name (jack_engine_t *engine, jack_uuid_t uuid)
{
JSList *node;
- for (node = engine->reserved_client_names; node; node = jack_slist_next (node)) {
- jack_reserved_name_t *reservation = (jack_reserved_name_t *) node->data;
+
+ for (node = engine->reserved_client_names; node; node = jack_slist_next (node)) {
+ jack_reserved_name_t *reservation = (jack_reserved_name_t*)node->data;
if (jack_uuid_compare (reservation->uuid, uuid) != 0) {
char *retval = strdup (reservation->name);
free (reservation);
- engine->reserved_client_names =
+ engine->reserved_client_names =
jack_slist_remove (engine->reserved_client_names, reservation);
return retval;
}
@@ -872,43 +875,43 @@ jack_client_create (jack_engine_t *engine, int client_fd)
res.status = 0;
- VALGRIND_MEMSET(&res, 0, sizeof (res));
+ VALGRIND_MEMSET (&res, 0, sizeof(res));
+
+ nbytes = read (client_fd, &req, sizeof(req));
- nbytes = read (client_fd, &req, sizeof (req));
-
- if (nbytes == 0) { /* EOF? */
- jack_error ("cannot read connection request from client (%s)", strerror(errno));
- return -1;
- }
+ if (nbytes == 0) { /* EOF? */
+ jack_error ("cannot read connection request from client (%s)", strerror (errno));
+ return -1;
+ }
/* First verify protocol version (first field of request), if
- * present, then make sure request has the expected length. */
- if ((nbytes < sizeof (req.protocol_v))
+ * present, then make sure request has the expected length. */
+ if ((nbytes < sizeof(req.protocol_v))
|| (req.protocol_v != jack_protocol_version)
- || (nbytes != sizeof (req))) {
+ || (nbytes != sizeof(req))) {
/* JACK protocol incompatibility */
- res.status |= (JackFailure|JackVersionError);
+ res.status |= (JackFailure | JackVersionError);
jack_error ("JACK protocol mismatch (%d vs %d)", req.protocol_v, jack_protocol_version);
- if (write (client_fd, &res, sizeof (res)) != sizeof (res)) {
+ if (write (client_fd, &res, sizeof(res)) != sizeof(res)) {
jack_error ("cannot write client connection response");
}
return -1;
}
- if (!req.load) { /* internal client close? */
+ if (!req.load) { /* internal client close? */
int rc = -1;
jack_uuid_t id = JACK_UUID_EMPTY_INITIALIZER;
- if (jack_client_id_by_name(engine, req.name, id) == 0) {
+ if (jack_client_id_by_name (engine, req.name, id) == 0) {
rc = handle_unload_client (engine, id);
}
-
+
/* close does not send a reply */
return rc;
}
-
+
pthread_mutex_lock (&engine->request_lock);
if (!jack_uuid_empty (req.uuid)) {
char *res_name = jack_get_reserved_name (engine, req.uuid);
@@ -936,8 +939,8 @@ jack_client_create (jack_engine_t *engine, int client_fd)
/* Mach port number for server/client communication */
res.portnum = client->portnum;
#endif
-
- if (jack_client_is_internal(client)) {
+
+ if (jack_client_is_internal (client)) {
/* the ->control pointers are for an internal client
so we know they are the right sized pointers
for this server. however, to keep the result
@@ -945,14 +948,14 @@ jack_client_create (jack_engine_t *engine, int client_fd)
clients/servers, the result structure stores
them as 64 bit integer, so we have to do a slightly
forced cast here.
- */
- res.client_control = (uint64_t) ((intptr_t) client->control);
- res.engine_control = (uint64_t) ((intptr_t) engine->control);
+ */
+ res.client_control = (uint64_t)((intptr_t)client->control);
+ res.engine_control = (uint64_t)((intptr_t)engine->control);
} else {
strcpy (res.fifo_prefix, engine->fifo_prefix);
}
- if (write (client_fd, &res, sizeof (res)) != sizeof (res)) {
+ if (write (client_fd, &res, sizeof(res)) != sizeof(res)) {
jack_error ("cannot write connection response to client");
jack_lock_graph (engine);
client->control->dead = 1;
@@ -965,7 +968,7 @@ jack_client_create (jack_engine_t *engine, int client_fd)
close (client_fd);
}
- jack_client_registration_notify (engine, (const char*) client->control->name, 1);
+ jack_client_registration_notify (engine, (const char*)client->control->name, 1);
return 0;
}
@@ -979,15 +982,14 @@ jack_client_activate (jack_engine_t *engine, jack_uuid_t id)
int i;
jack_event_t event;
- VALGRIND_MEMSET(&event, 0, sizeof(event));
+ VALGRIND_MEMSET (&event, 0, sizeof(event));
jack_lock_graph (engine);
- if ((client = jack_client_internal_by_id (engine, id)))
- {
+ if ((client = jack_client_internal_by_id (engine, id))) {
client->control->active = TRUE;
- jack_transport_activate(engine, client);
+ jack_transport_activate (engine, client);
/* we call this to make sure the FIFO is
* built+ready by the time the client needs
@@ -996,7 +998,7 @@ jack_client_activate (jack_engine_t *engine, jack_uuid_t id)
*/
jack_get_fifo_fd (engine,
- ++engine->external_client_cnt);
+ ++engine->external_client_cnt);
jack_sort_graph (engine);
@@ -1007,12 +1009,12 @@ jack_client_activate (jack_engine_t *engine, jack_uuid_t id)
}
event.type = BufferSizeChange;
- event.x.n = engine->control->buffer_size;
+ event.x.n = engine->control->buffer_size;
jack_deliver_event (engine, client, &event);
// send delayed notifications for ports.
for (node = client->ports; node; node = jack_slist_next (node)) {
- jack_port_internal_t *port = (jack_port_internal_t *) node->data;
+ jack_port_internal_t *port = (jack_port_internal_t*)node->data;
jack_port_registration_notify (engine, port->shared->id, TRUE);
}
@@ -1022,7 +1024,7 @@ jack_client_activate (jack_engine_t *engine, jack_uuid_t id)
jack_unlock_graph (engine);
return ret;
-}
+}
int
jack_client_deactivate (jack_engine_t *engine, jack_uuid_t id)
@@ -1035,18 +1037,18 @@ jack_client_deactivate (jack_engine_t *engine, jack_uuid_t id)
for (node = engine->clients; node; node = jack_slist_next (node)) {
jack_client_internal_t *client =
- (jack_client_internal_t *) node->data;
-
+ (jack_client_internal_t*)node->data;
+
if (jack_uuid_compare (client->control->uuid, id) == 0) {
-
- JSList *portnode;
+
+ JSList *portnode;
jack_port_internal_t *port;
for (portnode = client->ports; portnode;
portnode = jack_slist_next (portnode)) {
- port = (jack_port_internal_t *) portnode->data;
+ port = (jack_port_internal_t*)portnode->data;
jack_port_clear_connections (engine, port);
- }
+ }
ret = jack_client_do_deactivate (engine, client, TRUE);
break;
@@ -1056,7 +1058,7 @@ jack_client_deactivate (jack_engine_t *engine, jack_uuid_t id)
jack_unlock_graph (engine);
return ret;
-}
+}
int
@@ -1067,20 +1069,20 @@ jack_mark_client_socket_error (jack_engine_t *engine, int fd)
jack_client_internal_t *client = 0;
JSList *node;
- for (node = engine->clients; node; node = jack_slist_next (node)) {
+ for (node = engine->clients; node; node = jack_slist_next (node)) {
- if (jack_client_is_internal((jack_client_internal_t *)
- node->data)) {
- continue;
- }
+ if (jack_client_is_internal ((jack_client_internal_t*)
+ node->data)) {
+ continue;
+ }
- if (((jack_client_internal_t *) node->data)->request_fd == fd) {
- client = (jack_client_internal_t *) node->data;
- break;
- }
- }
+ if (((jack_client_internal_t*)node->data)->request_fd == fd) {
+ client = (jack_client_internal_t*)node->data;
+ break;
+ }
+ }
- if (client) {
+ if (client) {
VERBOSE (engine, "marking client %s with SOCKET error state = "
"%s errors = %d", client->control->name,
jack_client_state_name (client),
@@ -1094,34 +1096,35 @@ jack_mark_client_socket_error (jack_engine_t *engine, int fd)
void
jack_client_delete (jack_engine_t *engine, jack_client_internal_t *client)
{
- jack_uuid_t uuid = JACK_UUID_EMPTY_INITIALIZER;
- jack_uuid_copy (&uuid, client->control->uuid);
+ jack_uuid_t uuid = JACK_UUID_EMPTY_INITIALIZER;
- jack_client_registration_notify (engine, (const char*) client->control->name, 0);
+ jack_uuid_copy (&uuid, client->control->uuid);
- jack_remove_properties (NULL, uuid);
- /* have to do the notification ourselves, since the client argument
- to jack_remove_properties() was NULL
- */
- jack_property_change_notify (engine, PropertyDeleted, uuid, NULL);
+ jack_client_registration_notify (engine, (const char*)client->control->name, 0);
+
+ jack_remove_properties (NULL, uuid);
+ /* have to do the notification ourselves, since the client argument
+ to jack_remove_properties() was NULL
+ */
+ jack_property_change_notify (engine, PropertyDeleted, uuid, NULL);
if (jack_client_is_internal (client)) {
free (client->private_client);
- free ((void *) client->control);
+ free ((void*)client->control);
- } else {
+ } else {
/* release the client segment, mark it for
destruction, and free up the shm registry
information so that it can be reused.
- */
+ */
jack_release_shm (&client->control_shm);
jack_destroy_shm (&client->control_shm);
- }
+ }
- free (client);
+ free (client);
}
@@ -1134,7 +1137,7 @@ jack_intclient_handle_request (jack_engine_t *engine, jack_request_t *req)
if ((client = jack_client_by_name (engine, req->x.intclient.name))) {
jack_uuid_copy (&req->x.intclient.uuid, client->control->uuid);
} else {
- req->status |= (JackNoSuchClient|JackFailure);
+ req->status |= (JackNoSuchClient | JackFailure);
}
}
@@ -1144,21 +1147,21 @@ jack_intclient_load_request (jack_engine_t *engine, jack_request_t *req)
/* called with the request_lock */
jack_client_internal_t *client;
jack_status_t status = 0;
- jack_uuid_t empty_uuid = JACK_UUID_EMPTY_INITIALIZER;
+ jack_uuid_t empty_uuid = JACK_UUID_EMPTY_INITIALIZER;
VERBOSE (engine, "load internal client %s from %s, init `%s', "
"options: 0x%x", req->x.intclient.name,
req->x.intclient.path, req->x.intclient.init,
req->x.intclient.options);
- jack_uuid_clear (&empty_uuid);
+ jack_uuid_clear (&empty_uuid);
client = setup_client (engine, ClientInternal, req->x.intclient.name, empty_uuid,
- req->x.intclient.options|JackUseExactName, &status, -1,
+ req->x.intclient.options | JackUseExactName, &status, -1,
req->x.intclient.path, req->x.intclient.init);
if (client == NULL) {
- status |= JackFailure; /* just making sure */
+ status |= JackFailure; /* just making sure */
jack_uuid_clear (&req->x.intclient.uuid);
VERBOSE (engine, "load failed, status = 0x%x", status);
} else {
@@ -1176,12 +1179,12 @@ jack_intclient_name_request (jack_engine_t *engine, jack_request_t *req)
jack_rdlock_graph (engine);
if ((client = jack_client_internal_by_id (engine,
req->x.intclient.uuid))) {
- strncpy ((char *) req->x.intclient.name,
- (char *) client->control->name,
- sizeof (req->x.intclient.name));
+ strncpy ((char*)req->x.intclient.name,
+ (char*)client->control->name,
+ sizeof(req->x.intclient.name));
req->status = 0;
} else {
- req->status = (JackNoSuchClient|JackFailure);
+ req->status = (JackNoSuchClient | JackFailure);
}
jack_unlock_graph (engine);
}
@@ -1193,7 +1196,7 @@ jack_intclient_unload_request (jack_engine_t *engine, jack_request_t *req)
* handle_unload_client() *without* it. */
if (!jack_uuid_empty (req->x.intclient.uuid)) {
- /* non-empty UUID */
+ /* non-empty UUID */
pthread_mutex_unlock (&engine->request_lock);
req->status = handle_unload_client (engine, req->x.intclient.uuid);
pthread_mutex_lock (&engine->request_lock);
diff --git a/jackd/clientengine.h b/jackd/clientengine.h
index 1d49b28..afda1c4 100644
--- a/jackd/clientengine.h
+++ b/jackd/clientengine.h
@@ -3,7 +3,7 @@
*
* Copyright (C) 2001-2003 Paul Davis
* Copyright (C) 2004 Jack O'Quin
- *
+ *
* 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
@@ -20,11 +20,11 @@
*
*/
-static inline int
+static inline int
jack_client_is_internal (jack_client_internal_t *client)
{
return (client->control->type == ClientInternal) ||
- (client->control->type == ClientDriver);
+ (client->control->type == ClientDriver);
}
static inline char *
@@ -42,26 +42,26 @@ jack_client_state_name (jack_client_internal_t *client)
#define JACK_ERROR_WITH_SOCKETS 10000000
-int jack_client_activate (jack_engine_t *engine, jack_uuid_t id);
-int jack_client_deactivate (jack_engine_t *engine, jack_uuid_t id);
-int jack_client_create (jack_engine_t *engine, int client_fd);
-void jack_client_delete (jack_engine_t *engine,
- jack_client_internal_t *client);
-int jack_mark_client_socket_error (jack_engine_t *engine, int fd);
+int jack_client_activate(jack_engine_t *engine, jack_uuid_t id);
+int jack_client_deactivate(jack_engine_t *engine, jack_uuid_t id);
+int jack_client_create(jack_engine_t *engine, int client_fd);
+void jack_client_delete(jack_engine_t *engine,
+ jack_client_internal_t *client);
+int jack_mark_client_socket_error(jack_engine_t *engine, int fd);
jack_client_internal_t *
- jack_create_driver_client (jack_engine_t *engine, char *name);
-void jack_intclient_handle_request (jack_engine_t *engine,
- jack_request_t *req);
-void jack_intclient_load_request (jack_engine_t *engine,
- jack_request_t *req);
-void jack_intclient_name_request (jack_engine_t *engine,
- jack_request_t *req);
-void jack_intclient_unload_request (jack_engine_t *engine,
- jack_request_t *req);
-int jack_check_clients (jack_engine_t* engine, int with_timeout_check);
-void jack_remove_clients (jack_engine_t* engine, int* exit_freewheeling);
-void jack_client_registration_notify (jack_engine_t *engine,
- const char* name, int yn);
-void jack_property_change_notify (jack_engine_t *engine, jack_property_change_t change, jack_uuid_t uuid, const char* key);
+jack_create_driver_client(jack_engine_t *engine, char *name);
+void jack_intclient_handle_request(jack_engine_t *engine,
+ jack_request_t *req);
+void jack_intclient_load_request(jack_engine_t *engine,
+ jack_request_t *req);
+void jack_intclient_name_request(jack_engine_t *engine,
+ jack_request_t *req);
+void jack_intclient_unload_request(jack_engine_t *engine,
+ jack_request_t *req);
+int jack_check_clients(jack_engine_t* engine, int with_timeout_check);
+void jack_remove_clients(jack_engine_t* engine, int* exit_freewheeling);
+void jack_client_registration_notify(jack_engine_t *engine,
+ const char* name, int yn);
+void jack_property_change_notify(jack_engine_t *engine, jack_property_change_t change, jack_uuid_t uuid, const char* key);
-void jack_remove_client (jack_engine_t *engine, jack_client_internal_t *client);
+void jack_remove_client(jack_engine_t *engine, jack_client_internal_t *client);
diff --git a/jackd/controlapi.c b/jackd/controlapi.c
index 3b14cee..90edc28 100644
--- a/jackd/controlapi.c
+++ b/jackd/controlapi.c
@@ -1,24 +1,24 @@
// u/* -*- Mode: C++ ; c-basic-offset: 4 -*- */
/*
- JACK control API implementation
+ JACK control API implementation
- Copyright (C) 2008 Nedko Arnaudov
- Copyright (C) 2008 Grame
+ Copyright (C) 2008 Nedko Arnaudov
+ Copyright (C) 2008 Grame
- 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; version 2 of the License.
+ 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; version 2 of the License.
- 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.
+ 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.
+ 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 WIN32
#include <stdint.h>
@@ -58,250 +58,238 @@
*/
static JSList *drivers = NULL;
-struct jackctl_server
-{
- JSList * drivers;
- JSList * internals;
- JSList * parameters;
-
- jack_engine_t * engine;
-
- /* string, server name */
- union jackctl_parameter_value name;
- union jackctl_parameter_value default_name;
-
- /* bool, whether to be "realtime" */
- union jackctl_parameter_value realtime;
- union jackctl_parameter_value default_realtime;
-
- /* int32_t */
- union jackctl_parameter_value realtime_priority;
- union jackctl_parameter_value default_realtime_priority;
-
- /* bool, whether to exit once all clients have closed their connections */
- union jackctl_parameter_value temporary;
- union jackctl_parameter_value default_temporary;
-
- /* bool, whether to be verbose */
- union jackctl_parameter_value verbose;
- union jackctl_parameter_value default_verbose;
-
- /* int32_t, msecs; if zero, use period size. */
- union jackctl_parameter_value client_timeout;
- union jackctl_parameter_value default_client_timeout;
-
- /* uint32_t, clock source type */
- union jackctl_parameter_value clock_source;
- union jackctl_parameter_value default_clock_source;
-
- /* uint32_t, max port number */
- union jackctl_parameter_value port_max;
- union jackctl_parameter_value default_port_max;
-
- /* bool */
- union jackctl_parameter_value replace_registry;
- union jackctl_parameter_value default_replace_registry;
-
- /* bool, use mlock */
- union jackctl_parameter_value do_mlock;
- union jackctl_parameter_value default_do_mlock;
-
- /* bool, munlock gui libraries */
- union jackctl_parameter_value do_unlock;
- union jackctl_parameter_value default_do_unlock;
-
- /* bool, dont zombify... */
- union jackctl_parameter_value nozombies;
- union jackctl_parameter_value default_nozombies;
-
- /* int, timeout thres... */
- union jackctl_parameter_value timothres;
- union jackctl_parameter_value default_timothres;
+struct jackctl_server {
+ JSList * drivers;
+ JSList * internals;
+ JSList * parameters;
+
+ jack_engine_t * engine;
+
+ /* string, server name */
+ union jackctl_parameter_value name;
+ union jackctl_parameter_value default_name;
+
+ /* bool, whether to be "realtime" */
+ union jackctl_parameter_value realtime;
+ union jackctl_parameter_value default_realtime;
+
+ /* int32_t */
+ union jackctl_parameter_value realtime_priority;
+ union jackctl_parameter_value default_realtime_priority;
+
+ /* bool, whether to exit once all clients have closed their connections */
+ union jackctl_parameter_value temporary;
+ union jackctl_parameter_value default_temporary;
+
+ /* bool, whether to be verbose */
+ union jackctl_parameter_value verbose;
+ union jackctl_parameter_value default_verbose;
+
+ /* int32_t, msecs; if zero, use period size. */
+ union jackctl_parameter_value client_timeout;
+ union jackctl_parameter_value default_client_timeout;
+
+ /* uint32_t, clock source type */
+ union jackctl_parameter_value clock_source;
+ union jackctl_parameter_value default_clock_source;
+
+ /* uint32_t, max port number */
+ union jackctl_parameter_value port_max;
+ union jackctl_parameter_value default_port_max;
+
+ /* bool */
+ union jackctl_parameter_value replace_registry;
+ union jackctl_parameter_value default_replace_registry;
+
+ /* bool, use mlock */
+ union jackctl_parameter_value do_mlock;
+ union jackctl_parameter_value default_do_mlock;
+
+ /* bool, munlock gui libraries */
+ union jackctl_parameter_value do_unlock;
+ union jackctl_parameter_value default_do_unlock;
+
+ /* bool, dont zombify... */
+ union jackctl_parameter_value nozombies;
+ union jackctl_parameter_value default_nozombies;
+
+ /* int, timeout thres... */
+ union jackctl_parameter_value timothres;
+ union jackctl_parameter_value default_timothres;
};
-struct jackctl_driver
-{
- jack_driver_desc_t * desc_ptr;
- JSList * parameters;
- JSList * set_parameters;
+struct jackctl_driver {
+ jack_driver_desc_t * desc_ptr;
+ JSList * parameters;
+ JSList * set_parameters;
};
-struct jackctl_internal
-{
- jack_driver_desc_t * desc_ptr;
- JSList * parameters;
- JSList * set_parameters;
- int refnum;
+struct jackctl_internal {
+ jack_driver_desc_t * desc_ptr;
+ JSList * parameters;
+ JSList * set_parameters;
+ int refnum;
};
-struct jackctl_parameter
-{
- const char * name;
- const char * short_description;
- const char * long_description;
- jackctl_param_type_t type;
- bool is_set;
- union jackctl_parameter_value * value_ptr;
- union jackctl_parameter_value * default_value_ptr;
-
- union jackctl_parameter_value value;
- union jackctl_parameter_value default_value;
- struct jackctl_driver * driver_ptr;
- char id;
- jack_driver_param_t * driver_parameter_ptr;
- jack_driver_param_constraint_desc_t * constraint_ptr;
+struct jackctl_parameter {
+ const char * name;
+ const char * short_description;
+ const char * long_description;
+ jackctl_param_type_t type;
+ bool is_set;
+ union jackctl_parameter_value * value_ptr;
+ union jackctl_parameter_value * default_value_ptr;
+
+ union jackctl_parameter_value value;
+ union jackctl_parameter_value default_value;
+ struct jackctl_driver * driver_ptr;
+ char id;
+ jack_driver_param_t * driver_parameter_ptr;
+ jack_driver_param_constraint_desc_t * constraint_ptr;
};
static
struct jackctl_parameter *
-jackctl_add_parameter(
- JSList ** parameters_list_ptr_ptr,
- char id,
- const char * name,
- const char * short_description,
- const char * long_description,
- jackctl_param_type_t type,
- union jackctl_parameter_value * value_ptr,
- union jackctl_parameter_value * default_value_ptr,
- union jackctl_parameter_value value,
- jack_driver_param_constraint_desc_t * constraint_ptr)
+jackctl_add_parameter (
+ JSList ** parameters_list_ptr_ptr,
+ char id,
+ const char * name,
+ const char * short_description,
+ const char * long_description,
+ jackctl_param_type_t type,
+ union jackctl_parameter_value * value_ptr,
+ union jackctl_parameter_value * default_value_ptr,
+ union jackctl_parameter_value value,
+ jack_driver_param_constraint_desc_t * constraint_ptr)
{
- struct jackctl_parameter * parameter_ptr;
+ struct jackctl_parameter * parameter_ptr;
- parameter_ptr = (struct jackctl_parameter *)malloc(sizeof(struct jackctl_parameter));
- if (parameter_ptr == NULL)
- {
- jack_error("Cannot allocate memory for jackctl_parameter structure.");
- goto fail;
- }
+ parameter_ptr = (struct jackctl_parameter*)malloc (sizeof(struct jackctl_parameter));
+ if (parameter_ptr == NULL) {
+ jack_error ("Cannot allocate memory for jackctl_parameter structure.");
+ goto fail;
+ }
- parameter_ptr->name = name;
- parameter_ptr->short_description = short_description;
- parameter_ptr->long_description = long_description;
- parameter_ptr->type = type;
- parameter_ptr->is_set = false;
+ parameter_ptr->name = name;
+ parameter_ptr->short_description = short_description;
+ parameter_ptr->long_description = long_description;
+ parameter_ptr->type = type;
+ parameter_ptr->is_set = false;
- if (value_ptr == NULL)
- {
- value_ptr = &parameter_ptr->value;
- }
+ if (value_ptr == NULL) {
+ value_ptr = &parameter_ptr->value;
+ }
- if (default_value_ptr == NULL)
- {
- default_value_ptr = &parameter_ptr->default_value;
- }
+ if (default_value_ptr == NULL) {
+ default_value_ptr = &parameter_ptr->default_value;
+ }
- parameter_ptr->value_ptr = value_ptr;
- parameter_ptr->default_value_ptr = default_value_ptr;
+ parameter_ptr->value_ptr = value_ptr;
+ parameter_ptr->default_value_ptr = default_value_ptr;
- *value_ptr = *default_value_ptr = value;
+ *value_ptr = *default_value_ptr = value;
- parameter_ptr->driver_ptr = NULL;
- parameter_ptr->driver_parameter_ptr = NULL;
- parameter_ptr->id = id;
- parameter_ptr->constraint_ptr = constraint_ptr;
+ parameter_ptr->driver_ptr = NULL;
+ parameter_ptr->driver_parameter_ptr = NULL;
+ parameter_ptr->id = id;
+ parameter_ptr->constraint_ptr = constraint_ptr;
- *parameters_list_ptr_ptr = jack_slist_append(*parameters_list_ptr_ptr, parameter_ptr);
+ *parameters_list_ptr_ptr = jack_slist_append (*parameters_list_ptr_ptr, parameter_ptr);
- return parameter_ptr;
+ return parameter_ptr;
fail:
- return NULL;
+ return NULL;
}
static
void
-jackctl_free_driver_parameters(
- struct jackctl_driver * driver_ptr)
+jackctl_free_driver_parameters (
+ struct jackctl_driver * driver_ptr)
{
- JSList * next_node_ptr;
-
- while (driver_ptr->parameters)
- {
- next_node_ptr = driver_ptr->parameters->next;
- free(driver_ptr->parameters->data);
- free(driver_ptr->parameters);
- driver_ptr->parameters = next_node_ptr;
- }
-
- while (driver_ptr->set_parameters)
- {
- next_node_ptr = driver_ptr->set_parameters->next;
- free(driver_ptr->set_parameters->data);
- free(driver_ptr->set_parameters);
- driver_ptr->set_parameters = next_node_ptr;
- }
+ JSList * next_node_ptr;
+
+ while (driver_ptr->parameters) {
+ next_node_ptr = driver_ptr->parameters->next;
+ free (driver_ptr->parameters->data);
+ free (driver_ptr->parameters);
+ driver_ptr->parameters = next_node_ptr;
+ }
+
+ while (driver_ptr->set_parameters) {
+ next_node_ptr = driver_ptr->set_parameters->next;
+ free (driver_ptr->set_parameters->data);
+ free (driver_ptr->set_parameters);
+ driver_ptr->set_parameters = next_node_ptr;
+ }
}
static
bool
-jackctl_add_driver_parameters(
- struct jackctl_driver * driver_ptr)
+jackctl_add_driver_parameters (
+ struct jackctl_driver * driver_ptr)
{
- uint32_t i;
- union jackctl_parameter_value jackctl_value;
- jackctl_param_type_t jackctl_type;
- struct jackctl_parameter * parameter_ptr;
- jack_driver_param_desc_t * descriptor_ptr;
-
- for (i = 0 ; i < driver_ptr->desc_ptr->nparams ; i++)
- {
- descriptor_ptr = driver_ptr->desc_ptr->params + i;
-
- switch (descriptor_ptr->type)
- {
- case JackDriverParamInt:
- jackctl_type = JackParamInt;
- jackctl_value.i = descriptor_ptr->value.i;
- break;
- case JackDriverParamUInt:
- jackctl_type = JackParamUInt;
- jackctl_value.ui = descriptor_ptr->value.ui;
- break;
- case JackDriverParamChar:
- jackctl_type = JackParamChar;
- jackctl_value.c = descriptor_ptr->value.c;
- break;
- case JackDriverParamString:
- jackctl_type = JackParamString;
- strcpy(jackctl_value.str, descriptor_ptr->value.str);
- break;
- case JackDriverParamBool:
- jackctl_type = JackParamBool;
- jackctl_value.b = descriptor_ptr->value.i;
- break;
- default:
- jack_error("unknown driver parameter type %i", (int)descriptor_ptr->type);
- assert(0);
- goto fail;
- }
-
- parameter_ptr = jackctl_add_parameter(
- &driver_ptr->parameters,
- descriptor_ptr->character,
- descriptor_ptr->name,
- descriptor_ptr->short_desc,
- descriptor_ptr->long_desc,
- jackctl_type,
- NULL,
- NULL,
- jackctl_value,
- descriptor_ptr->constraint);
-
- if (parameter_ptr == NULL)
- {
- goto fail;
- }
-
- parameter_ptr->driver_ptr = driver_ptr;
- }
-
- return true;
+ uint32_t i;
+ union jackctl_parameter_value jackctl_value;
+ jackctl_param_type_t jackctl_type;
+ struct jackctl_parameter * parameter_ptr;
+ jack_driver_param_desc_t * descriptor_ptr;
+
+ for (i = 0; i < driver_ptr->desc_ptr->nparams; i++) {
+ descriptor_ptr = driver_ptr->desc_ptr->params + i;
+
+ switch (descriptor_ptr->type) {
+ case JackDriverParamInt:
+ jackctl_type = JackParamInt;
+ jackctl_value.i = descriptor_ptr->value.i;
+ break;
+ case JackDriverParamUInt:
+ jackctl_type = JackParamUInt;
+ jackctl_value.ui = descriptor_ptr->value.ui;
+ break;
+ case JackDriverParamChar:
+ jackctl_type = JackParamChar;
+ jackctl_value.c = descriptor_ptr->value.c;
+ break;
+ case JackDriverParamString:
+ jackctl_type = JackParamString;
+ strcpy (jackctl_value.str, descriptor_ptr->value.str);
+ break;
+ case JackDriverParamBool:
+ jackctl_type = JackParamBool;
+ jackctl_value.b = descriptor_ptr->value.i;
+ break;
+ default:
+ jack_error ("unknown driver parameter type %i", (int)descriptor_ptr->type);
+ assert (0);
+ goto fail;
+ }
+
+ parameter_ptr = jackctl_add_parameter (
+ &driver_ptr->parameters,
+ descriptor_ptr->character,
+ descriptor_ptr->name,
+ descriptor_ptr->short_desc,
+ descriptor_ptr->long_desc,
+ jackctl_type,
+ NULL,
+ NULL,
+ jackctl_value,
+ descriptor_ptr->constraint);
+
+ if (parameter_ptr == NULL) {
+ goto fail;
+ }
+
+ parameter_ptr->driver_ptr = driver_ptr;
+ }
+
+ return true;
fail:
- jackctl_free_driver_parameters(driver_ptr);
+ jackctl_free_driver_parameters (driver_ptr);
- return false;
+ return false;
}
static jack_driver_desc_t *
@@ -316,7 +304,7 @@ jack_drivers_get_descriptor (JSList * drivers, const char * sofile)
int err;
char* driver_dir;
- if ((driver_dir = getenv("JACK_DRIVER_DIR")) == 0) {
+ if ((driver_dir = getenv ("JACK_DRIVER_DIR")) == 0) {
driver_dir = ADDON_DIR;
}
filename = malloc (strlen (driver_dir) + 1 + strlen (sofile) + 1);
@@ -326,17 +314,17 @@ jack_drivers_get_descriptor (JSList * drivers, const char * sofile)
// jack_info ("getting driver descriptor from %s", filename);
// }
- if ((dlhandle = dlopen (filename, RTLD_NOW|RTLD_GLOBAL)) == NULL) {
+ if ((dlhandle = dlopen (filename, RTLD_NOW | RTLD_GLOBAL)) == NULL) {
jack_error ("could not open driver .so '%s': %s\n", filename, dlerror ());
free (filename);
return NULL;
}
so_get_descriptor = (JackDriverDescFunction)
- dlsym (dlhandle, "driver_get_descriptor");
+ dlsym (dlhandle, "driver_get_descriptor");
if ((dlerr = dlerror ()) != NULL) {
- jack_error("%s", dlerr);
+ jack_error ("%s", dlerr);
dlclose (dlhandle);
free (filename);
return NULL;
@@ -355,7 +343,7 @@ jack_drivers_get_descriptor (JSList * drivers, const char * sofile)
/* check it doesn't exist already */
for (node = drivers; node; node = jack_slist_next (node)) {
- other_descriptor = (jack_driver_desc_t *) node->data;
+ other_descriptor = (jack_driver_desc_t*)node->data;
if (strcmp (descriptor->name, other_descriptor->name) == 0) {
jack_error ("the drivers in '%s' and '%s' both have the name '%s'; using the first\n",
@@ -383,7 +371,7 @@ jack_drivers_load ()
jack_driver_desc_t * desc;
char* driver_dir;
- if ((driver_dir = getenv("JACK_DRIVER_DIR")) == 0) {
+ if ((driver_dir = getenv ("JACK_DRIVER_DIR")) == 0) {
driver_dir = ADDON_DIR;
}
@@ -395,7 +383,7 @@ jack_drivers_load ()
driver_dir, strerror (errno));
return NULL;
}
-
+
while ( (dir_entry = readdir (dir_stream)) ) {
/* check the filename is of the right format */
if (strncmp ("jack_", dir_entry->d_name, 5) != 0) {
@@ -436,8 +424,9 @@ jack_cleanup_files (const char *server_name)
{
DIR *dir;
struct dirent *dirent;
- char dir_name[PATH_MAX+1] = "";
- jack_server_dir (server_name, dir_name);
+ char dir_name[PATH_MAX + 1] = "";
+
+ jack_server_dir (server_name, dir_name);
/* On termination, we remove all files that jackd creates so
* subsequent attempts to start jackd will not believe that an
@@ -463,27 +452,27 @@ jack_cleanup_files (const char *server_name)
/* unlink all the files in this directory, they are mine */
while ((dirent = readdir (dir)) != NULL) {
- char fullpath[PATH_MAX+1];
+ char fullpath[PATH_MAX + 1];
if ((strcmp (dirent->d_name, ".") == 0)
|| (strcmp (dirent->d_name, "..") == 0)) {
continue;
}
- snprintf (fullpath, sizeof (fullpath), "%s/%s",
+ snprintf (fullpath, sizeof(fullpath), "%s/%s",
dir_name, dirent->d_name);
if (unlink (fullpath)) {
jack_error ("cannot unlink `%s' (%s)", fullpath,
strerror (errno));
}
- }
+ }
closedir (dir);
/* now, delete the per-server subdirectory, itself */
if (rmdir (dir_name)) {
- jack_error ("cannot remove `%s' (%s)", dir_name,
+ jack_error ("cannot remove `%s' (%s)", dir_name,
strerror (errno));
}
@@ -497,1040 +486,1001 @@ jack_cleanup_files (const char *server_name)
}
static int
-jackctl_drivers_load(
- struct jackctl_server * server_ptr)
+jackctl_drivers_load (
+ struct jackctl_server * server_ptr)
{
- struct jackctl_driver * driver_ptr;
- JSList *node_ptr;
- JSList *descriptor_node_ptr;
-
- descriptor_node_ptr = jack_drivers_load();
- if (descriptor_node_ptr == NULL)
- {
- jack_error("could not find any drivers in driver directory!");
- return false;
- }
-
- while (descriptor_node_ptr != NULL)
- {
- driver_ptr = (struct jackctl_driver *)malloc(sizeof(struct jackctl_driver));
- if (driver_ptr == NULL)
- {
- jack_error("memory allocation of jackctl_driver structure failed.");
- goto next;
- }
-
- driver_ptr->desc_ptr = (jack_driver_desc_t *)descriptor_node_ptr->data;
- driver_ptr->parameters = NULL;
- driver_ptr->set_parameters = NULL;
-
- if (!jackctl_add_driver_parameters(driver_ptr))
- {
- assert(driver_ptr->parameters == NULL);
- free(driver_ptr);
- goto next;
- }
-
- server_ptr->drivers = jack_slist_append(server_ptr->drivers, driver_ptr);
-
- next:
- node_ptr = descriptor_node_ptr;
- descriptor_node_ptr = descriptor_node_ptr->next;
- free(node_ptr);
- }
-
- return true;
+ struct jackctl_driver * driver_ptr;
+ JSList *node_ptr;
+ JSList *descriptor_node_ptr;
+
+ descriptor_node_ptr = jack_drivers_load ();
+ if (descriptor_node_ptr == NULL) {
+ jack_error ("could not find any drivers in driver directory!");
+ return false;
+ }
+
+ while (descriptor_node_ptr != NULL) {
+ driver_ptr = (struct jackctl_driver*)malloc (sizeof(struct jackctl_driver));
+ if (driver_ptr == NULL) {
+ jack_error ("memory allocation of jackctl_driver structure failed.");
+ goto next;
+ }
+
+ driver_ptr->desc_ptr = (jack_driver_desc_t*)descriptor_node_ptr->data;
+ driver_ptr->parameters = NULL;
+ driver_ptr->set_parameters = NULL;
+
+ if (!jackctl_add_driver_parameters (driver_ptr)) {
+ assert (driver_ptr->parameters == NULL);
+ free (driver_ptr);
+ goto next;
+ }
+
+ server_ptr->drivers = jack_slist_append (server_ptr->drivers, driver_ptr);
+
+next:
+ node_ptr = descriptor_node_ptr;
+ descriptor_node_ptr = descriptor_node_ptr->next;
+ free (node_ptr);
+ }
+
+ return true;
}
static
void
-jackctl_server_free_drivers(
- struct jackctl_server * server_ptr)
+jackctl_server_free_drivers (
+ struct jackctl_server * server_ptr)
{
- JSList * next_node_ptr;
- struct jackctl_driver * driver_ptr;
-
- while (server_ptr->drivers)
- {
- next_node_ptr = server_ptr->drivers->next;
- driver_ptr = (struct jackctl_driver *)server_ptr->drivers->data;
-
- jackctl_free_driver_parameters(driver_ptr);
- free(driver_ptr->desc_ptr->params);
- free(driver_ptr->desc_ptr);
- free(driver_ptr);
-
- free(server_ptr->drivers);
- server_ptr->drivers = next_node_ptr;
- }
+ JSList * next_node_ptr;
+ struct jackctl_driver * driver_ptr;
+
+ while (server_ptr->drivers) {
+ next_node_ptr = server_ptr->drivers->next;
+ driver_ptr = (struct jackctl_driver*)server_ptr->drivers->data;
+
+ jackctl_free_driver_parameters (driver_ptr);
+ free (driver_ptr->desc_ptr->params);
+ free (driver_ptr->desc_ptr);
+ free (driver_ptr);
+
+ free (server_ptr->drivers);
+ server_ptr->drivers = next_node_ptr;
+ }
}
static int
-jackctl_internals_load(
- struct jackctl_server * server_ptr)
+jackctl_internals_load (
+ struct jackctl_server * server_ptr)
{
- struct jackctl_internal * internal_ptr;
- JSList *node_ptr;
- JSList *descriptor_node_ptr = NULL;
-
- //XXX: jack1 doesnt support internals enumeration.
- //descriptor_node_ptr = jack_internals_load(NULL);
- if (descriptor_node_ptr == NULL)
- {
- return false;
- }
-
- while (descriptor_node_ptr != NULL)
- {
- internal_ptr = (struct jackctl_internal *)malloc(sizeof(struct jackctl_internal));
- if (internal_ptr == NULL)
- {
- jack_error("memory allocation of jackctl_driver structure failed.");
- goto next;
- }
-
- internal_ptr->desc_ptr = (jack_driver_desc_t *)descriptor_node_ptr->data;
- internal_ptr->parameters = NULL;
- internal_ptr->set_parameters = NULL;
-
- if (!jackctl_add_driver_parameters((struct jackctl_driver *)internal_ptr))
- {
- assert(internal_ptr->parameters == NULL);
- free(internal_ptr);
- goto next;
- }
-
- server_ptr->internals = jack_slist_append(server_ptr->internals, internal_ptr);
-
- next:
- node_ptr = descriptor_node_ptr;
- descriptor_node_ptr = descriptor_node_ptr->next;
- free(node_ptr);
- }
-
- return true;
+ struct jackctl_internal * internal_ptr;
+ JSList *node_ptr;
+ JSList *descriptor_node_ptr = NULL;
+
+ //XXX: jack1 doesnt support internals enumeration.
+ //descriptor_node_ptr = jack_internals_load(NULL);
+ if (descriptor_node_ptr == NULL) {
+ return false;
+ }
+
+ while (descriptor_node_ptr != NULL) {
+ internal_ptr = (struct jackctl_internal*)malloc (sizeof(struct jackctl_internal));
+ if (internal_ptr == NULL) {
+ jack_error ("memory allocation of jackctl_driver structure failed.");
+ goto next;
+ }
+
+ internal_ptr->desc_ptr = (jack_driver_desc_t*)descriptor_node_ptr->data;
+ internal_ptr->parameters = NULL;
+ internal_ptr->set_parameters = NULL;
+
+ if (!jackctl_add_driver_parameters ((struct jackctl_driver*)internal_ptr)) {
+ assert (internal_ptr->parameters == NULL);
+ free (internal_ptr);
+ goto next;
+ }
+
+ server_ptr->internals = jack_slist_append (server_ptr->internals, internal_ptr);
+
+next:
+ node_ptr = descriptor_node_ptr;
+ descriptor_node_ptr = descriptor_node_ptr->next;
+ free (node_ptr);
+ }
+
+ return true;
}
static
void
-jackctl_server_free_internals(
- struct jackctl_server * server_ptr)
+jackctl_server_free_internals (
+ struct jackctl_server * server_ptr)
{
- JSList * next_node_ptr;
- struct jackctl_internal * internal_ptr;
-
- while (server_ptr->internals)
- {
- next_node_ptr = server_ptr->internals->next;
- internal_ptr = (struct jackctl_internal *)server_ptr->internals->data;
-
- jackctl_free_driver_parameters((struct jackctl_driver *)internal_ptr);
- free(internal_ptr->desc_ptr->params);
- free(internal_ptr->desc_ptr);
- free(internal_ptr);
-
- free(server_ptr->internals);
- server_ptr->internals = next_node_ptr;
- }
+ JSList * next_node_ptr;
+ struct jackctl_internal * internal_ptr;
+
+ while (server_ptr->internals) {
+ next_node_ptr = server_ptr->internals->next;
+ internal_ptr = (struct jackctl_internal*)server_ptr->internals->data;
+
+ jackctl_free_driver_parameters ((struct jackctl_driver*)internal_ptr);
+ free (internal_ptr->desc_ptr->params);
+ free (internal_ptr->desc_ptr);
+ free (internal_ptr);
+
+ free (server_ptr->internals);
+ server_ptr->internals = next_node_ptr;
+ }
}
static
void
-jackctl_server_free_parameters(
- struct jackctl_server * server_ptr)
+jackctl_server_free_parameters (
+ struct jackctl_server * server_ptr)
{
- JSList * next_node_ptr;
-
- while (server_ptr->parameters)
- {
- next_node_ptr = server_ptr->parameters->next;
- free(server_ptr->parameters->data);
- free(server_ptr->parameters);
- server_ptr->parameters = next_node_ptr;
- }
+ JSList * next_node_ptr;
+
+ while (server_ptr->parameters) {
+ next_node_ptr = server_ptr->parameters->next;
+ free (server_ptr->parameters->data);
+ free (server_ptr->parameters);
+ server_ptr->parameters = next_node_ptr;
+ }
}
#ifdef WIN32
static HANDLE waitEvent;
-static void do_nothing_handler(int signum)
+static void do_nothing_handler (int signum)
{
- printf("jack main caught signal %d\n", signum);
- (void) signal(SIGINT, SIG_DFL);
- SetEvent(waitEvent);
+ printf ("jack main caught signal %d\n", signum);
+ (void)signal (SIGINT, SIG_DFL);
+ SetEvent (waitEvent);
}
sigset_t
-jackctl_setup_signals(
- unsigned int flags)
+jackctl_setup_signals (
+ unsigned int flags)
{
- if ((waitEvent = CreateEvent(NULL, FALSE, FALSE, NULL)) == NULL) {
- jack_error("CreateEvent fails err = %ld", GetLastError());
- return 0;
- }
+ if ((waitEvent = CreateEvent (NULL, FALSE, FALSE, NULL)) == NULL) {
+ jack_error ("CreateEvent fails err = %ld", GetLastError ());
+ return 0;
+ }
- (void) signal(SIGINT, do_nothing_handler);
- (void) signal(SIGABRT, do_nothing_handler);
- (void) signal(SIGTERM, do_nothing_handler);
+ (void)signal (SIGINT, do_nothing_handler);
+ (void)signal (SIGABRT, do_nothing_handler);
+ (void)signal (SIGTERM, do_nothing_handler);
- return (sigset_t)waitEvent;
+ return (sigset_t)waitEvent;
}
-void jackctl_wait_signals(sigset_t signals)
+void jackctl_wait_signals (sigset_t signals)
{
- if (WaitForSingleObject(waitEvent, INFINITE) != WAIT_OBJECT_0) {
- jack_error("WaitForSingleObject fails err = %ld", GetLastError());
- }
+ if (WaitForSingleObject (waitEvent, INFINITE) != WAIT_OBJECT_0) {
+ jack_error ("WaitForSingleObject fails err = %ld", GetLastError ());
+ }
}
#else
static
void
-do_nothing_handler(int sig)
+do_nothing_handler (int sig)
{
- /* this is used by the child (active) process, but it never
- gets called unless we are already shutting down after
- another signal.
- */
- char buf[64];
- snprintf (buf, sizeof(buf), "received signal %d during shutdown (ignored)\n", sig);
+ /* this is used by the child (active) process, but it never
+ gets called unless we are already shutting down after
+ another signal.
+ */
+ char buf[64];
+
+ snprintf (buf, sizeof(buf), "received signal %d during shutdown (ignored)\n", sig);
}
sigset_t
-jackctl_setup_signals(
- unsigned int flags)
+jackctl_setup_signals (
+ unsigned int flags)
{
- sigset_t signals;
- sigset_t allsignals;
- struct sigaction action;
- int i;
-
- /* ensure that we are in our own process group so that
- kill (SIG, -pgrp) does the right thing.
- */
-
- setsid();
-
- pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
-
- /* what's this for?
-
- POSIX says that signals are delivered like this:
-
- * if a thread has blocked that signal, it is not
- a candidate to receive the signal.
- * of all threads not blocking the signal, pick
- one at random, and deliver the signal.
-
- this means that a simple-minded multi-threaded program can
- expect to get POSIX signals delivered randomly to any one
- of its threads,
-
- here, we block all signals that we think we might receive
- and want to catch. all "child" threads will inherit this
- setting. if we create a thread that calls sigwait() on the
- same set of signals, implicitly unblocking all those
- signals. any of those signals that are delivered to the
- process will be delivered to that thread, and that thread
- alone. this makes cleanup for a signal-driven exit much
- easier, since we know which thread is doing it and more
- importantly, we are free to call async-unsafe functions,
- because the code is executing in normal thread context
- after a return from sigwait().
- */
-
- sigemptyset(&signals);
- sigaddset(&signals, SIGHUP);
- sigaddset(&signals, SIGINT);
- sigaddset(&signals, SIGQUIT);
- sigaddset(&signals, SIGPIPE);
- sigaddset(&signals, SIGTERM);
- sigaddset(&signals, SIGUSR1);
- sigaddset(&signals, SIGUSR2);
-
- /* all child threads will inherit this mask unless they
- * explicitly reset it
- */
-
- pthread_sigmask(SIG_BLOCK, &signals, 0);
-
- /* install a do-nothing handler because otherwise pthreads
- behaviour is undefined when we enter sigwait.
- */
-
- sigfillset(&allsignals);
- action.sa_handler = do_nothing_handler;
- action.sa_mask = allsignals;
- action.sa_flags = SA_RESTART|SA_RESETHAND;
-
- for (i = 1; i < NSIG; i++)
- {
- if (sigismember (&signals, i))
- {
- sigaction(i, &action, 0);
- }
- }
-
- return signals;
+ sigset_t signals;
+ sigset_t allsignals;
+ struct sigaction action;
+ int i;
+
+ /* ensure that we are in our own process group so that
+ kill (SIG, -pgrp) does the right thing.
+ */
+
+ setsid ();
+
+ pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
+
+ /* what's this for?
+
+ POSIX says that signals are delivered like this:
+
+ * if a thread has blocked that signal, it is not
+ a candidate to receive the signal.
+ * of all threads not blocking the signal, pick
+ one at random, and deliver the signal.
+
+ this means that a simple-minded multi-threaded program can
+ expect to get POSIX signals delivered randomly to any one
+ of its threads,
+
+ here, we block all signals that we think we might receive
+ and want to catch. all "child" threads will inherit this
+ setting. if we create a thread that calls sigwait() on the
+ same set of signals, implicitly unblocking all those
+ signals. any of those signals that are delivered to the
+ process will be delivered to that thread, and that thread
+ alone. this makes cleanup for a signal-driven exit much
+ easier, since we know which thread is doing it and more
+ importantly, we are free to call async-unsafe functions,
+ because the code is executing in normal thread context
+ after a return from sigwait().
+ */
+
+ sigemptyset (&signals);
+ sigaddset (&signals, SIGHUP);
+ sigaddset (&signals, SIGINT);
+ sigaddset (&signals, SIGQUIT);
+ sigaddset (&signals, SIGPIPE);
+ sigaddset (&signals, SIGTERM);
+ sigaddset (&signals, SIGUSR1);
+ sigaddset (&signals, SIGUSR2);
+
+ /* all child threads will inherit this mask unless they
+ * explicitly reset it
+ */
+
+ pthread_sigmask (SIG_BLOCK, &signals, 0);
+
+ /* install a do-nothing handler because otherwise pthreads
+ behaviour is undefined when we enter sigwait.
+ */
+
+ sigfillset (&allsignals);
+ action.sa_handler = do_nothing_handler;
+ action.sa_mask = allsignals;
+ action.sa_flags = SA_RESTART | SA_RESETHAND;
+
+ for (i = 1; i < NSIG; i++) {
+ if (sigismember (&signals, i)) {
+ sigaction (i, &action, 0);
+ }
+ }
+
+ return signals;
}
void
-jackctl_wait_signals(sigset_t signals)
+jackctl_wait_signals (sigset_t signals)
{
- int sig;
- bool waiting = true;
+ int sig;
+ bool waiting = true;
- while (waiting) {
+ while (waiting) {
#if defined(sun) && !defined(__sun__) // SUN compiler only, to check
- sigwait(&signals);
+ sigwait (&signals);
#else
- sigwait(&signals, &sig);
+ sigwait (&signals, &sig);
#endif
- fprintf(stderr, "jack main caught signal %d\n", sig);
-
- switch (sig) {
- case SIGUSR1:
- //jack_dump_configuration(engine, 1);
- break;
- case SIGUSR2:
- // driver exit
- waiting = false;
- break;
- case SIGTTOU:
- break;
- default:
- waiting = false;
- break;
- }
- }
-
- if (sig != SIGSEGV) {
- // unblock signals so we can see them during shutdown.
- // this will help prod developers not to lose sight of
- // bugs that cause segfaults etc. during shutdown.
- sigprocmask(SIG_UNBLOCK, &signals, 0);
- }
+ fprintf (stderr, "jack main caught signal %d\n", sig);
+
+ switch (sig) {
+ case SIGUSR1:
+ //jack_dump_configuration(engine, 1);
+ break;
+ case SIGUSR2:
+ // driver exit
+ waiting = false;
+ break;
+ case SIGTTOU:
+ break;
+ default:
+ waiting = false;
+ break;
+ }
+ }
+
+ if (sig != SIGSEGV) {
+ // unblock signals so we can see them during shutdown.
+ // this will help prod developers not to lose sight of
+ // bugs that cause segfaults etc. during shutdown.
+ sigprocmask (SIG_UNBLOCK, &signals, 0);
+ }
}
#endif
static sigset_t
-jackctl_block_signals()
+jackctl_block_signals ()
{
- sigset_t signals;
- sigset_t oldsignals;
+ sigset_t signals;
+ sigset_t oldsignals;
- sigemptyset(&signals);
- sigaddset(&signals, SIGHUP);
- sigaddset(&signals, SIGINT);
- sigaddset(&signals, SIGQUIT);
- sigaddset(&signals, SIGPIPE);
- sigaddset(&signals, SIGTERM);
- sigaddset(&signals, SIGUSR1);
- sigaddset(&signals, SIGUSR2);
+ sigemptyset (&signals);
+ sigaddset (&signals, SIGHUP);
+ sigaddset (&signals, SIGINT);
+ sigaddset (&signals, SIGQUIT);
+ sigaddset (&signals, SIGPIPE);
+ sigaddset (&signals, SIGTERM);
+ sigaddset (&signals, SIGUSR1);
+ sigaddset (&signals, SIGUSR2);
- pthread_sigmask(SIG_BLOCK, &signals, &oldsignals);
+ pthread_sigmask (SIG_BLOCK, &signals, &oldsignals);
- return oldsignals;
+ return oldsignals;
}
static void
-jackctl_unblock_signals(sigset_t oldsignals)
+jackctl_unblock_signals (sigset_t oldsignals)
{
- pthread_sigmask(SIG_SETMASK, &oldsignals, 0);
+ pthread_sigmask (SIG_SETMASK, &oldsignals, 0);
}
static
jack_driver_param_constraint_desc_t *
-get_realtime_priority_constraint()
+get_realtime_priority_constraint ()
{
#ifndef __OpenBSD__
- jack_driver_param_constraint_desc_t * constraint_ptr;
+ jack_driver_param_constraint_desc_t * constraint_ptr;
- int max = sched_get_priority_max (SCHED_FIFO);
- int min = sched_get_priority_min (SCHED_FIFO);
+ int max = sched_get_priority_max (SCHED_FIFO);
+ int min = sched_get_priority_min (SCHED_FIFO);
- //jack_info("realtime priority range is (%d,%d)", min, max);
+ //jack_info("realtime priority range is (%d,%d)", min, max);
- constraint_ptr = (jack_driver_param_constraint_desc_t *)calloc(1, sizeof(jack_driver_param_value_enum_t));
- if (constraint_ptr == NULL)
- {
- jack_error("Cannot allocate memory for jack_driver_param_constraint_desc_t structure.");
- return NULL;
- }
- constraint_ptr->flags = JACK_CONSTRAINT_FLAG_RANGE;
+ constraint_ptr = (jack_driver_param_constraint_desc_t*)calloc (1, sizeof(jack_driver_param_value_enum_t));
+ if (constraint_ptr == NULL) {
+ jack_error ("Cannot allocate memory for jack_driver_param_constraint_desc_t structure.");
+ return NULL;
+ }
+ constraint_ptr->flags = JACK_CONSTRAINT_FLAG_RANGE;
- constraint_ptr->constraint.range.min.i = min;
- constraint_ptr->constraint.range.max.i = max;
+ constraint_ptr->constraint.range.min.i = min;
+ constraint_ptr->constraint.range.max.i = max;
- return constraint_ptr;
+ return constraint_ptr;
#else
- return NULL
+ return NULL
#endif
}
-jackctl_server_t * jackctl_server_create(
- bool (* on_device_acquire)(const char * device_name),
- void (* on_device_release)(const char * device_name))
+jackctl_server_t * jackctl_server_create (
+ bool (* on_device_acquire)(const char * device_name),
+ void (* on_device_release)(const char * device_name))
{
- struct jackctl_server * server_ptr;
- union jackctl_parameter_value value;
-
- server_ptr = (struct jackctl_server *)malloc(sizeof(struct jackctl_server));
- if (server_ptr == NULL)
- {
- jack_error("Cannot allocate memory for jackctl_server structure.");
- goto fail;
- }
-
- server_ptr->drivers = NULL;
- server_ptr->internals = NULL;
- server_ptr->parameters = NULL;
- server_ptr->engine = NULL;
-
- strcpy(value.str, jack_default_server_name() );
- if (jackctl_add_parameter(
- &server_ptr->parameters,
- 'n',
- "name",
- "Server name to use.",
- "",
- JackParamString,
- &server_ptr->name,
- &server_ptr->default_name,
- value, NULL) == NULL)
- {
- goto fail_free_parameters;
- }
-
- value.b = false;
- if (jackctl_add_parameter(
- &server_ptr->parameters,
- 'R',
- "realtime",
- "Whether to use realtime mode.",
- "Use realtime scheduling. This is needed for reliable low-latency performance. On most systems, it requires JACK to run with special scheduler and memory allocation privileges, which may be obtained in several ways. On Linux you should use PAM.",
- JackParamBool,
- &server_ptr->realtime,
- &server_ptr->default_realtime,
- value, NULL) == NULL)
- {
- goto fail_free_parameters;
- }
-
- value.i = 10;
- if (jackctl_add_parameter(
- &server_ptr->parameters,
- 'P',
- "realtime-priority",
- "Scheduler priority when running in realtime mode.",
- "",
- JackParamInt,
- &server_ptr->realtime_priority,
- &server_ptr->default_realtime_priority,
- value,
- get_realtime_priority_constraint()
- ) == NULL)
- {
- goto fail_free_parameters;
- }
-
- value.b = false;
- if (jackctl_add_parameter(
- &server_ptr->parameters,
- 'T',
- "temporary",
- "Exit once all clients have closed their connections.",
- "",
- JackParamBool,
- &server_ptr->temporary,
- &server_ptr->default_temporary,
- value, NULL) == NULL)
- {
- goto fail_free_parameters;
- }
-
- value.b = false;
- if (jackctl_add_parameter(
- &server_ptr->parameters,
- 'v',
- "verbose",
- "Verbose mode.",
- "",
- JackParamBool,
- &server_ptr->verbose,
- &server_ptr->default_verbose,
- value, NULL) == NULL)
- {
- goto fail_free_parameters;
- }
-
- value.i = 0;
- if (jackctl_add_parameter(
- &server_ptr->parameters,
- 't',
- "client-timeout",
- "Client timeout limit in milliseconds.",
- "",
- JackParamInt,
- &server_ptr->client_timeout,
- &server_ptr->default_client_timeout,
- value, NULL) == NULL)
- {
- goto fail_free_parameters;
- }
-
- value.ui = 0;
- if (jackctl_add_parameter(
- &server_ptr->parameters,
- 'c',
- "clock-source",
- "Clocksource type : c(ycle) | h(pet) | s(ystem).",
- "",
- JackParamUInt,
- &server_ptr->clock_source,
- &server_ptr->default_clock_source,
- value, NULL) == NULL)
- {
- goto fail_free_parameters;
- }
-
- value.ui = 128;
- if (jackctl_add_parameter(
- &server_ptr->parameters,
- 'p',
- "port-max",
- "Maximum number of ports.",
- "",
- JackParamUInt,
- &server_ptr->port_max,
- &server_ptr->default_port_max,
- value, NULL) == NULL)
- {
- goto fail_free_parameters;
- }
-
- value.b = false;
- if (jackctl_add_parameter(
- &server_ptr->parameters,
- '\0',
- "replace-registry",
- "Replace shared memory registry.",
- "",
- JackParamBool,
- &server_ptr->replace_registry,
- &server_ptr->default_replace_registry,
- value, NULL) == NULL)
- {
- goto fail_free_parameters;
- }
-
- value.b = false;
- if (jackctl_add_parameter(
- &server_ptr->parameters,
- 'm',
- "mlock",
- "Use mlock.",
- "",
- JackParamBool,
- &server_ptr->do_mlock,
- &server_ptr->default_do_mlock,
- value, NULL) == NULL)
- {
- goto fail_free_parameters;
- }
-
- value.b = false;
- if (jackctl_add_parameter(
- &server_ptr->parameters,
- 'u',
- "unlock",
- "munlock memory for big libraries",
- "",
- JackParamBool,
- &server_ptr->do_unlock,
- &server_ptr->default_do_unlock,
- value, NULL) == NULL)
- {
- goto fail_free_parameters;
- }
-
- value.b = false;
- if (jackctl_add_parameter(
- &server_ptr->parameters,
- 'Z',
- "nozombies",
- "dont zombifiy offending clients",
- "",
- JackParamBool,
- &server_ptr->nozombies,
- &server_ptr->default_nozombies,
- value, NULL) == NULL)
- {
- goto fail_free_parameters;
- }
-
- value.ui = 0;
- if (jackctl_add_parameter(
- &server_ptr->parameters,
- 'C',
- "timeout-threshold",
- "threshold for suspending processing",
- "",
- JackParamUInt,
- &server_ptr->timothres,
- &server_ptr->default_timothres,
- value, NULL) == NULL)
- {
- goto fail_free_parameters;
- }
-
- //TODO: need
- //JackServerGlobals::on_device_acquire = on_device_acquire;
- //JackServerGlobals::on_device_release = on_device_release;
-
- if (!jackctl_drivers_load(server_ptr))
- {
- goto fail_free_parameters;
- }
-
- /* Allowed to fail */
- jackctl_internals_load(server_ptr);
-
- return server_ptr;
+ struct jackctl_server * server_ptr;
+ union jackctl_parameter_value value;
+
+ server_ptr = (struct jackctl_server*)malloc (sizeof(struct jackctl_server));
+ if (server_ptr == NULL) {
+ jack_error ("Cannot allocate memory for jackctl_server structure.");
+ goto fail;
+ }
+
+ server_ptr->drivers = NULL;
+ server_ptr->internals = NULL;
+ server_ptr->parameters = NULL;
+ server_ptr->engine = NULL;
+
+ strcpy (value.str, jack_default_server_name () );
+ if (jackctl_add_parameter (
+ &server_ptr->parameters,
+ 'n',
+ "name",
+ "Server name to use.",
+ "",
+ JackParamString,
+ &server_ptr->name,
+ &server_ptr->default_name,
+ value, NULL) == NULL) {
+ goto fail_free_parameters;
+ }
+
+ value.b = false;
+ if (jackctl_add_parameter (
+ &server_ptr->parameters,
+ 'R',
+ "realtime",
+ "Whether to use realtime mode.",
+ "Use realtime scheduling. This is needed for reliable low-latency performance. On most systems, it requires JACK to run with special scheduler and memory allocation privileges, which may be obtained in several ways. On Linux you should use PAM.",
+ JackParamBool,
+ &server_ptr->realtime,
+ &server_ptr->default_realtime,
+ value, NULL) == NULL) {
+ goto fail_free_parameters;
+ }
+
+ value.i = 10;
+ if (jackctl_add_parameter (
+ &server_ptr->parameters,
+ 'P',
+ "realtime-priority",
+ "Scheduler priority when running in realtime mode.",
+ "",
+ JackParamInt,
+ &server_ptr->realtime_priority,
+ &server_ptr->default_realtime_priority,
+ value,
+ get_realtime_priority_constraint ()
+ ) == NULL) {
+ goto fail_free_parameters;
+ }
+
+ value.b = false;
+ if (jackctl_add_parameter (
+ &server_ptr->parameters,
+ 'T',
+ "temporary",
+ "Exit once all clients have closed their connections.",
+ "",
+ JackParamBool,
+ &server_ptr->temporary,
+ &server_ptr->default_temporary,
+ value, NULL) == NULL) {
+ goto fail_free_parameters;
+ }
+
+ value.b = false;
+ if (jackctl_add_parameter (
+ &server_ptr->parameters,
+ 'v',
+ "verbose",
+ "Verbose mode.",
+ "",
+ JackParamBool,
+ &server_ptr->verbose,
+ &server_ptr->default_verbose,
+ value, NULL) == NULL) {
+ goto fail_free_parameters;
+ }
+
+ value.i = 0;
+ if (jackctl_add_parameter (
+ &server_ptr->parameters,
+ 't',
+ "client-timeout",
+ "Client timeout limit in milliseconds.",
+ "",
+ JackParamInt,
+ &server_ptr->client_timeout,
+ &server_ptr->default_client_timeout,
+ value, NULL) == NULL) {
+ goto fail_free_parameters;
+ }
+
+ value.ui = 0;
+ if (jackctl_add_parameter (
+ &server_ptr->parameters,
+ 'c',
+ "clock-source",
+ "Clocksource type : c(ycle) | h(pet) | s(ystem).",
+ "",
+ JackParamUInt,
+ &server_ptr->clock_source,
+ &server_ptr->default_clock_source,
+ value, NULL) == NULL) {
+ goto fail_free_parameters;
+ }
+
+ value.ui = 128;
+ if (jackctl_add_parameter (
+ &server_ptr->parameters,
+ 'p',
+ "port-max",
+ "Maximum number of ports.",
+ "",
+ JackParamUInt,
+ &server_ptr->port_max,
+ &server_ptr->default_port_max,
+ value, NULL) == NULL) {
+ goto fail_free_parameters;
+ }
+
+ value.b = false;
+ if (jackctl_add_parameter (
+ &server_ptr->parameters,
+ '\0',
+ "replace-registry",
+ "Replace shared memory registry.",
+ "",
+ JackParamBool,
+ &server_ptr->replace_registry,
+ &server_ptr->default_replace_registry,
+ value, NULL) == NULL) {
+ goto fail_free_parameters;
+ }
+
+ value.b = false;
+ if (jackctl_add_parameter (
+ &server_ptr->parameters,
+ 'm',
+ "mlock",
+ "Use mlock.",
+ "",
+ JackParamBool,
+ &server_ptr->do_mlock,
+ &server_ptr->default_do_mlock,
+ value, NULL) == NULL) {
+ goto fail_free_parameters;
+ }
+
+ value.b = false;
+ if (jackctl_add_parameter (
+ &server_ptr->parameters,
+ 'u',
+ "unlock",
+ "munlock memory for big libraries",
+ "",
+ JackParamBool,
+ &server_ptr->do_unlock,
+ &server_ptr->default_do_unlock,
+ value, NULL) == NULL) {
+ goto fail_free_parameters;
+ }
+
+ value.b = false;
+ if (jackctl_add_parameter (
+ &server_ptr->parameters,
+ 'Z',
+ "nozombies",
+ "dont zombifiy offending clients",
+ "",
+ JackParamBool,
+ &server_ptr->nozombies,
+ &server_ptr->default_nozombies,
+ value, NULL) == NULL) {
+ goto fail_free_parameters;
+ }
+
+ value.ui = 0;
+ if (jackctl_add_parameter (
+ &server_ptr->parameters,
+ 'C',
+ "timeout-threshold",
+ "threshold for suspending processing",
+ "",
+ JackParamUInt,
+ &server_ptr->timothres,
+ &server_ptr->default_timothres,
+ value, NULL) == NULL) {
+ goto fail_free_parameters;
+ }
+
+ //TODO: need
+ //JackServerGlobals::on_device_acquire = on_device_acquire;
+ //JackServerGlobals::on_device_release = on_device_release;
+
+ if (!jackctl_drivers_load (server_ptr)) {
+ goto fail_free_parameters;
+ }
+
+ /* Allowed to fail */
+ jackctl_internals_load (server_ptr);
+
+ return server_ptr;
fail_free_parameters:
- jackctl_server_free_parameters(server_ptr);
+ jackctl_server_free_parameters (server_ptr);
- free(server_ptr);
+ free (server_ptr);
fail:
- return NULL;
+ return NULL;
}
-void jackctl_server_destroy(jackctl_server_t *server_ptr)
+void jackctl_server_destroy (jackctl_server_t *server_ptr)
{
- jackctl_server_free_drivers(server_ptr);
- jackctl_server_free_internals(server_ptr);
- jackctl_server_free_parameters(server_ptr);
- free(server_ptr);
+ jackctl_server_free_drivers (server_ptr);
+ jackctl_server_free_internals (server_ptr);
+ jackctl_server_free_parameters (server_ptr);
+ free (server_ptr);
}
-const JSList * jackctl_server_get_drivers_list(jackctl_server_t *server_ptr)
+const JSList * jackctl_server_get_drivers_list (jackctl_server_t *server_ptr)
{
- return server_ptr->drivers;
+ return server_ptr->drivers;
}
-bool jackctl_server_stop(jackctl_server_t *server_ptr)
+bool jackctl_server_stop (jackctl_server_t *server_ptr)
{
//jack_engine_driver_exit (server_ptr->engine);
jack_engine_delete (server_ptr->engine);
- /* clean up shared memory and files from this server instance */
- //jack_log("cleaning up shared memory");
+ /* clean up shared memory and files from this server instance */
+ //jack_log("cleaning up shared memory");
- jack_cleanup_shm();
+ jack_cleanup_shm ();
- //jack_log("cleaning up files");
+ //jack_log("cleaning up files");
- jack_cleanup_files (server_ptr->name.str);
+ jack_cleanup_files (server_ptr->name.str);
- //jack_log("unregistering server `%s'", server_ptr->name.str);
+ //jack_log("unregistering server `%s'", server_ptr->name.str);
- jack_unregister_server(server_ptr->name.str);
+ jack_unregister_server (server_ptr->name.str);
- server_ptr->engine = NULL;
+ server_ptr->engine = NULL;
- return true;
+ return true;
}
-const JSList * jackctl_server_get_parameters(jackctl_server_t *server_ptr)
+const JSList * jackctl_server_get_parameters (jackctl_server_t *server_ptr)
{
- return server_ptr->parameters;
+ return server_ptr->parameters;
}
bool
-jackctl_server_start(
- jackctl_server_t *server_ptr,
- jackctl_driver_t *driver_ptr)
+jackctl_server_start (
+ jackctl_server_t *server_ptr,
+ jackctl_driver_t *driver_ptr)
{
- int rc;
- sigset_t oldsignals;
-
-
- // TODO:
- int frame_time_offset = 0;
-
- rc = jack_register_server (server_ptr->name.str, server_ptr->replace_registry.b);
- switch (rc)
- {
- case EEXIST:
- jack_error("`%s' server already active", server_ptr->name.str);
- goto fail;
- case ENOSPC:
- jack_error("too many servers already active");
- goto fail;
- case ENOMEM:
- jack_error("no access to shm registry");
- goto fail;
- }
-
- //jack_log("server `%s' registered", server_ptr->name.str);
-
- /* clean up shared memory and files from any previous
- * instance of this server name */
- jack_cleanup_shm ();
- jack_cleanup_files (server_ptr->name.str);
-
- if (!server_ptr->realtime.b && server_ptr->client_timeout.i == 0)
- server_ptr->client_timeout.i = 500; /* 0.5 sec; usable when non realtime. */
-
- oldsignals = jackctl_block_signals();
-
- if ((server_ptr->engine = jack_engine_new (server_ptr->realtime.b, server_ptr->realtime_priority.i,
- server_ptr->do_mlock.b, server_ptr->do_unlock.b, server_ptr->name.str,
- server_ptr->temporary.b, server_ptr->verbose.b, server_ptr->client_timeout.i,
- server_ptr->port_max.i, getpid(), frame_time_offset,
- server_ptr->nozombies.b, server_ptr->timothres.ui, drivers)) == 0) {
- jack_error ("cannot create engine");
- goto fail_unregister;
- }
-
- if (jack_engine_load_driver (server_ptr->engine, driver_ptr->desc_ptr, driver_ptr->set_parameters))
- {
+ int rc;
+ sigset_t oldsignals;
+
+
+ // TODO:
+ int frame_time_offset = 0;
+
+ rc = jack_register_server (server_ptr->name.str, server_ptr->replace_registry.b);
+ switch (rc) {
+ case EEXIST:
+ jack_error ("`%s' server already active", server_ptr->name.str);
+ goto fail;
+ case ENOSPC:
+ jack_error ("too many servers already active");
+ goto fail;
+ case ENOMEM:
+ jack_error ("no access to shm registry");
+ goto fail;
+ }
+
+ //jack_log("server `%s' registered", server_ptr->name.str);
+
+ /* clean up shared memory and files from any previous
+ * instance of this server name */
+ jack_cleanup_shm ();
+ jack_cleanup_files (server_ptr->name.str);
+
+ if (!server_ptr->realtime.b && server_ptr->client_timeout.i == 0) {
+ server_ptr->client_timeout.i = 500; /* 0.5 sec; usable when non realtime. */
+
+ }
+ oldsignals = jackctl_block_signals ();
+
+ if ((server_ptr->engine = jack_engine_new (server_ptr->realtime.b, server_ptr->realtime_priority.i,
+ server_ptr->do_mlock.b, server_ptr->do_unlock.b, server_ptr->name.str,
+ server_ptr->temporary.b, server_ptr->verbose.b, server_ptr->client_timeout.i,
+ server_ptr->port_max.i, getpid (), frame_time_offset,
+ server_ptr->nozombies.b, server_ptr->timothres.ui, drivers)) == 0) {
+ jack_error ("cannot create engine");
+ goto fail_unregister;
+ }
+
+ if (jack_engine_load_driver (server_ptr->engine, driver_ptr->desc_ptr, driver_ptr->set_parameters)) {
jack_error ("cannot load driver module %s", driver_ptr->desc_ptr->name);
goto fail_delete;
- }
+ }
- if (server_ptr->engine->driver->start (server_ptr->engine->driver) != 0) {
- jack_error ("cannot start driver");
- goto fail_close;
- }
+ if (server_ptr->engine->driver->start (server_ptr->engine->driver) != 0) {
+ jack_error ("cannot start driver");
+ goto fail_close;
+ }
- jackctl_unblock_signals( oldsignals );
- return true;
+ jackctl_unblock_signals ( oldsignals );
+ return true;
fail_close:
fail_delete:
- jack_engine_delete (server_ptr->engine);
- server_ptr->engine = NULL;
+ jack_engine_delete (server_ptr->engine);
+ server_ptr->engine = NULL;
fail_unregister:
- //jack_log("cleaning up shared memory");
+ //jack_log("cleaning up shared memory");
- jack_cleanup_shm();
+ jack_cleanup_shm ();
- //jack_log("cleaning up files");
+ //jack_log("cleaning up files");
- jack_cleanup_files(server_ptr->name.str);
+ jack_cleanup_files (server_ptr->name.str);
- //jack_log("unregistering server `%s'", server_ptr->name.str);
+ //jack_log("unregistering server `%s'", server_ptr->name.str);
- jack_unregister_server(server_ptr->name.str);
- jackctl_unblock_signals( oldsignals );
+ jack_unregister_server (server_ptr->name.str);
+ jackctl_unblock_signals ( oldsignals );
fail:
- return false;
+ return false;
}
-const char * jackctl_driver_get_name(jackctl_driver_t *driver_ptr)
+const char * jackctl_driver_get_name (jackctl_driver_t *driver_ptr)
{
- return driver_ptr->desc_ptr->name;
+ return driver_ptr->desc_ptr->name;
}
-const JSList * jackctl_driver_get_parameters(jackctl_driver_t *driver_ptr)
+const JSList * jackctl_driver_get_parameters (jackctl_driver_t *driver_ptr)
{
- return driver_ptr->parameters;
+ return driver_ptr->parameters;
}
-jack_driver_desc_t * jackctl_driver_get_desc(jackctl_driver_t *driver_ptr)
+jack_driver_desc_t * jackctl_driver_get_desc (jackctl_driver_t *driver_ptr)
{
- return driver_ptr->desc_ptr;
+ return driver_ptr->desc_ptr;
}
-const char * jackctl_parameter_get_name(jackctl_parameter_t *parameter_ptr)
+const char * jackctl_parameter_get_name (jackctl_parameter_t *parameter_ptr)
{
- return parameter_ptr->name;
+ return parameter_ptr->name;
}
-const char * jackctl_parameter_get_short_description(jackctl_parameter_t *parameter_ptr)
+const char * jackctl_parameter_get_short_description (jackctl_parameter_t *parameter_ptr)
{
- return parameter_ptr->short_description;
+ return parameter_ptr->short_description;
}
-const char * jackctl_parameter_get_long_description(jackctl_parameter_t *parameter_ptr)
+const char * jackctl_parameter_get_long_description (jackctl_parameter_t *parameter_ptr)
{
- return parameter_ptr->long_description;
+ return parameter_ptr->long_description;
}
-bool jackctl_parameter_has_range_constraint(jackctl_parameter_t *parameter_ptr)
+bool jackctl_parameter_has_range_constraint (jackctl_parameter_t *parameter_ptr)
{
- return parameter_ptr->constraint_ptr != NULL && (parameter_ptr->constraint_ptr->flags & JACK_CONSTRAINT_FLAG_RANGE) != 0;
+ return parameter_ptr->constraint_ptr != NULL && (parameter_ptr->constraint_ptr->flags & JACK_CONSTRAINT_FLAG_RANGE) != 0;
}
-bool jackctl_parameter_has_enum_constraint(jackctl_parameter_t *parameter_ptr)
+bool jackctl_parameter_has_enum_constraint (jackctl_parameter_t *parameter_ptr)
{
- return parameter_ptr->constraint_ptr != NULL && (parameter_ptr->constraint_ptr->flags & JACK_CONSTRAINT_FLAG_RANGE) == 0;
+ return parameter_ptr->constraint_ptr != NULL && (parameter_ptr->constraint_ptr->flags & JACK_CONSTRAINT_FLAG_RANGE) == 0;
}
-uint32_t jackctl_parameter_get_enum_constraints_count(jackctl_parameter_t *parameter_ptr)
+uint32_t jackctl_parameter_get_enum_constraints_count (jackctl_parameter_t *parameter_ptr)
{
- if (!jackctl_parameter_has_enum_constraint(parameter_ptr))
- {
- return 0;
- }
+ if (!jackctl_parameter_has_enum_constraint (parameter_ptr)) {
+ return 0;
+ }
- return parameter_ptr->constraint_ptr->constraint.enumeration.count;
+ return parameter_ptr->constraint_ptr->constraint.enumeration.count;
}
-union jackctl_parameter_value jackctl_parameter_get_enum_constraint_value(jackctl_parameter_t *parameter_ptr, uint32_t index)
+union jackctl_parameter_value jackctl_parameter_get_enum_constraint_value (jackctl_parameter_t *parameter_ptr, uint32_t index)
{
- jack_driver_param_value_t * value_ptr;
- union jackctl_parameter_value jackctl_value;
-
- value_ptr = &parameter_ptr->constraint_ptr->constraint.enumeration.possible_values_array[index].value;
-
- switch (parameter_ptr->type)
- {
- case JackParamInt:
- jackctl_value.i = value_ptr->i;
- break;
- case JackParamUInt:
- jackctl_value.ui = value_ptr->ui;
- break;
- case JackParamChar:
- jackctl_value.c = value_ptr->c;
- break;
- case JackParamString:
- strcpy(jackctl_value.str, value_ptr->str);
- break;
- default:
- jack_error("bad driver parameter type %i (enum constraint)", (int)parameter_ptr->type);
- assert(0);
- }
-
- return jackctl_value;
+ jack_driver_param_value_t * value_ptr;
+ union jackctl_parameter_value jackctl_value;
+
+ value_ptr = &parameter_ptr->constraint_ptr->constraint.enumeration.possible_values_array[index].value;
+
+ switch (parameter_ptr->type) {
+ case JackParamInt:
+ jackctl_value.i = value_ptr->i;
+ break;
+ case JackParamUInt:
+ jackctl_value.ui = value_ptr->ui;
+ break;
+ case JackParamChar:
+ jackctl_value.c = value_ptr->c;
+ break;
+ case JackParamString:
+ strcpy (jackctl_value.str, value_ptr->str);
+ break;
+ default:
+ jack_error ("bad driver parameter type %i (enum constraint)", (int)parameter_ptr->type);
+ assert (0);
+ }
+
+ return jackctl_value;
}
-const char * jackctl_parameter_get_enum_constraint_description(jackctl_parameter_t *parameter_ptr, uint32_t index)
+const char * jackctl_parameter_get_enum_constraint_description (jackctl_parameter_t *parameter_ptr, uint32_t index)
{
- return parameter_ptr->constraint_ptr->constraint.enumeration.possible_values_array[index].short_desc;
+ return parameter_ptr->constraint_ptr->constraint.enumeration.possible_values_array[index].short_desc;
}
-void jackctl_parameter_get_range_constraint(jackctl_parameter_t *parameter_ptr, union jackctl_parameter_value * min_ptr, union jackctl_parameter_value * max_ptr)
+void jackctl_parameter_get_range_constraint (jackctl_parameter_t *parameter_ptr, union jackctl_parameter_value * min_ptr, union jackctl_parameter_value * max_ptr)
{
- switch (parameter_ptr->type)
- {
- case JackParamInt:
- min_ptr->i = parameter_ptr->constraint_ptr->constraint.range.min.i;
- max_ptr->i = parameter_ptr->constraint_ptr->constraint.range.max.i;
- return;
- case JackParamUInt:
- min_ptr->ui = parameter_ptr->constraint_ptr->constraint.range.min.ui;
- max_ptr->ui = parameter_ptr->constraint_ptr->constraint.range.max.ui;
- return;
- default:
- jack_error("bad driver parameter type %i (range constraint)", (int)parameter_ptr->type);
- assert(0);
- }
+ switch (parameter_ptr->type) {
+ case JackParamInt:
+ min_ptr->i = parameter_ptr->constraint_ptr->constraint.range.min.i;
+ max_ptr->i = parameter_ptr->constraint_ptr->constraint.range.max.i;
+ return;
+ case JackParamUInt:
+ min_ptr->ui = parameter_ptr->constraint_ptr->constraint.range.min.ui;
+ max_ptr->ui = parameter_ptr->constraint_ptr->constraint.range.max.ui;
+ return;
+ default:
+ jack_error ("bad driver parameter type %i (range constraint)", (int)parameter_ptr->type);
+ assert (0);
+ }
}
-bool jackctl_parameter_constraint_is_strict(jackctl_parameter_t * parameter_ptr)
+bool jackctl_parameter_constraint_is_strict (jackctl_parameter_t * parameter_ptr)
{
- return parameter_ptr->constraint_ptr != NULL && (parameter_ptr->constraint_ptr->flags & JACK_CONSTRAINT_FLAG_STRICT) != 0;
+ return parameter_ptr->constraint_ptr != NULL && (parameter_ptr->constraint_ptr->flags & JACK_CONSTRAINT_FLAG_STRICT) != 0;
}
-bool jackctl_parameter_constraint_is_fake_value(jackctl_parameter_t * parameter_ptr)
+bool jackctl_parameter_constraint_is_fake_value (jackctl_parameter_t * parameter_ptr)
{
- return parameter_ptr->constraint_ptr != NULL && (parameter_ptr->constraint_ptr->flags & JACK_CONSTRAINT_FLAG_FAKE_VALUE) != 0;
+ return parameter_ptr->constraint_ptr != NULL && (parameter_ptr->constraint_ptr->flags & JACK_CONSTRAINT_FLAG_FAKE_VALUE) != 0;
}
-jackctl_param_type_t jackctl_parameter_get_type(jackctl_parameter_t *parameter_ptr)
+jackctl_param_type_t jackctl_parameter_get_type (jackctl_parameter_t *parameter_ptr)
{
- return parameter_ptr->type;
+ return parameter_ptr->type;
}
-char jackctl_parameter_get_id(jackctl_parameter_t * parameter_ptr)
+char jackctl_parameter_get_id (jackctl_parameter_t * parameter_ptr)
{
- return parameter_ptr->id;
+ return parameter_ptr->id;
}
-bool jackctl_parameter_is_set(jackctl_parameter_t *parameter_ptr)
+bool jackctl_parameter_is_set (jackctl_parameter_t *parameter_ptr)
{
- return parameter_ptr->is_set;
+ return parameter_ptr->is_set;
}
-union jackctl_parameter_value jackctl_parameter_get_value(jackctl_parameter_t *parameter_ptr)
+union jackctl_parameter_value jackctl_parameter_get_value (jackctl_parameter_t *parameter_ptr)
{
- return *(parameter_ptr->value_ptr);
+ return *(parameter_ptr->value_ptr);
}
-bool jackctl_parameter_reset(jackctl_parameter_t *parameter_ptr)
+bool jackctl_parameter_reset (jackctl_parameter_t *parameter_ptr)
{
- if (!parameter_ptr->is_set)
- {
- return true;
- }
+ if (!parameter_ptr->is_set) {
+ return true;
+ }
- parameter_ptr->is_set = false;
+ parameter_ptr->is_set = false;
- *parameter_ptr->value_ptr = *parameter_ptr->default_value_ptr;
+ *parameter_ptr->value_ptr = *parameter_ptr->default_value_ptr;
- return true;
+ return true;
}
-bool jackctl_parameter_set_value(jackctl_parameter_t *parameter_ptr, const union jackctl_parameter_value * value_ptr)
+bool jackctl_parameter_set_value (jackctl_parameter_t *parameter_ptr, const union jackctl_parameter_value * value_ptr)
{
- bool new_driver_parameter;
+ bool new_driver_parameter;
- /* for driver parameters, set the parameter by adding jack_driver_param_t in the set_parameters list */
- if (parameter_ptr->driver_ptr != NULL)
- {
+ /* for driver parameters, set the parameter by adding jack_driver_param_t in the set_parameters list */
+ if (parameter_ptr->driver_ptr != NULL) {
/* jack_info("setting driver parameter %p ...", parameter_ptr); */
- new_driver_parameter = parameter_ptr->driver_parameter_ptr == NULL;
- if (new_driver_parameter)
- {
+ new_driver_parameter = parameter_ptr->driver_parameter_ptr == NULL;
+ if (new_driver_parameter) {
/* jack_info("new driver parameter..."); */
- parameter_ptr->driver_parameter_ptr = (jack_driver_param_t *)malloc(sizeof(jack_driver_param_t));
- if (parameter_ptr->driver_parameter_ptr == NULL)
- {
- jack_error ("Allocation of jack_driver_param_t structure failed");
- return false;
- }
-
- parameter_ptr->driver_parameter_ptr->character = parameter_ptr->id;
- parameter_ptr->driver_ptr->set_parameters = jack_slist_append(parameter_ptr->driver_ptr->set_parameters, parameter_ptr->driver_parameter_ptr);
- }
-
- switch (parameter_ptr->type)
- {
- case JackParamInt:
- parameter_ptr->driver_parameter_ptr->value.i = value_ptr->i;
- break;
- case JackParamUInt:
- parameter_ptr->driver_parameter_ptr->value.ui = value_ptr->ui;
- break;
- case JackParamChar:
- parameter_ptr->driver_parameter_ptr->value.c = value_ptr->c;
- break;
- case JackParamString:
- strcpy(parameter_ptr->driver_parameter_ptr->value.str, value_ptr->str);
- break;
- case JackParamBool:
- parameter_ptr->driver_parameter_ptr->value.i = value_ptr->b;
- break;
- default:
- jack_error("unknown parameter type %i", (int)parameter_ptr->type);
- assert(0);
-
- if (new_driver_parameter)
- {
- parameter_ptr->driver_ptr->set_parameters = jack_slist_remove(parameter_ptr->driver_ptr->set_parameters, parameter_ptr->driver_parameter_ptr);
- }
-
- return false;
- }
- }
-
- parameter_ptr->is_set = true;
- *parameter_ptr->value_ptr = *value_ptr;
-
- return true;
+ parameter_ptr->driver_parameter_ptr = (jack_driver_param_t*)malloc (sizeof(jack_driver_param_t));
+ if (parameter_ptr->driver_parameter_ptr == NULL) {
+ jack_error ("Allocation of jack_driver_param_t structure failed");
+ return false;
+ }
+
+ parameter_ptr->driver_parameter_ptr->character = parameter_ptr->id;
+ parameter_ptr->driver_ptr->set_parameters = jack_slist_append (parameter_ptr->driver_ptr->set_parameters, parameter_ptr->driver_parameter_ptr);
+ }
+
+ switch (parameter_ptr->type) {
+ case JackParamInt:
+ parameter_ptr->driver_parameter_ptr->value.i = value_ptr->i;
+ break;
+ case JackParamUInt:
+ parameter_ptr->driver_parameter_ptr->value.ui = value_ptr->ui;
+ break;
+ case JackParamChar:
+ parameter_ptr->driver_parameter_ptr->value.c = value_ptr->c;
+ break;
+ case JackParamString:
+ strcpy (parameter_ptr->driver_parameter_ptr->value.str, value_ptr->str);
+ break;
+ case JackParamBool:
+ parameter_ptr->driver_parameter_ptr->value.i = value_ptr->b;
+ break;
+ default:
+ jack_error ("unknown parameter type %i", (int)parameter_ptr->type);
+ assert (0);
+
+ if (new_driver_parameter) {
+ parameter_ptr->driver_ptr->set_parameters = jack_slist_remove (parameter_ptr->driver_ptr->set_parameters, parameter_ptr->driver_parameter_ptr);
+ }
+
+ return false;
+ }
+ }
+
+ parameter_ptr->is_set = true;
+ *parameter_ptr->value_ptr = *value_ptr;
+
+ return true;
}
-union jackctl_parameter_value jackctl_parameter_get_default_value(jackctl_parameter_t *parameter_ptr)
+union jackctl_parameter_value jackctl_parameter_get_default_value (jackctl_parameter_t *parameter_ptr)
{
- return *(parameter_ptr->default_value_ptr);
+ return *(parameter_ptr->default_value_ptr);
}
// Internals clients
-const JSList * jackctl_server_get_internals_list(jackctl_server_t *server_ptr)
+const JSList * jackctl_server_get_internals_list (jackctl_server_t *server_ptr)
{
- return server_ptr->internals;
+ return server_ptr->internals;
}
-const char * jackctl_internal_get_name(jackctl_internal_t *internal_ptr)
+const char * jackctl_internal_get_name (jackctl_internal_t *internal_ptr)
{
- return internal_ptr->desc_ptr->name;
+ return internal_ptr->desc_ptr->name;
}
-const JSList * jackctl_internal_get_parameters(jackctl_internal_t *internal_ptr)
+const JSList * jackctl_internal_get_parameters (jackctl_internal_t *internal_ptr)
{
- return internal_ptr->parameters;
+ return internal_ptr->parameters;
}
-bool jackctl_server_load_internal(
- jackctl_server_t * server_ptr,
- jackctl_internal_t * internal)
+bool jackctl_server_load_internal (
+ jackctl_server_t * server_ptr,
+ jackctl_internal_t * internal)
{
return false;
}
-bool jackctl_server_unload_internal(
- jackctl_server_t * server_ptr,
- jackctl_internal_t * internal)
+bool jackctl_server_unload_internal (
+ jackctl_server_t * server_ptr,
+ jackctl_internal_t * internal)
{
return false;
}
-bool jackctl_server_add_slave(jackctl_server_t * server_ptr, jackctl_driver_t * driver_ptr)
+bool jackctl_server_add_slave (jackctl_server_t * server_ptr, jackctl_driver_t * driver_ptr)
{
return false;
}
-bool jackctl_server_remove_slave(jackctl_server_t * server_ptr, jackctl_driver_t * driver_ptr)
+bool jackctl_server_remove_slave (jackctl_server_t * server_ptr, jackctl_driver_t * driver_ptr)
{
return false;
}
-bool jackctl_server_switch_master(jackctl_server_t * server_ptr, jackctl_driver_t * driver_ptr)
+bool jackctl_server_switch_master (jackctl_server_t * server_ptr, jackctl_driver_t * driver_ptr)
{
- jack_driver_t *old_driver;
+ jack_driver_t *old_driver;
- if (server_ptr->engine == NULL)
- goto fail_nostart;
+ if (server_ptr->engine == NULL) {
+ goto fail_nostart;
+ }
- old_driver = server_ptr->engine->driver;
+ old_driver = server_ptr->engine->driver;
- if (old_driver)
- {
- old_driver->stop (old_driver );
- old_driver->detach (old_driver, server_ptr->engine);
+ if (old_driver) {
+ old_driver->stop (old_driver );
+ old_driver->detach (old_driver, server_ptr->engine);
- pthread_mutex_lock (&server_ptr->engine->request_lock);
- jack_lock_graph (server_ptr->engine);
- jack_remove_client (server_ptr->engine, old_driver->internal_client);
- jack_unlock_graph (server_ptr->engine);
- pthread_mutex_unlock (&server_ptr->engine->request_lock);
+ pthread_mutex_lock (&server_ptr->engine->request_lock);
+ jack_lock_graph (server_ptr->engine);
+ jack_remove_client (server_ptr->engine, old_driver->internal_client);
+ jack_unlock_graph (server_ptr->engine);
+ pthread_mutex_unlock (&server_ptr->engine->request_lock);
- server_ptr->engine->driver = NULL;
+ server_ptr->engine->driver = NULL;
- jack_driver_unload (old_driver);
- }
+ jack_driver_unload (old_driver);
+ }
- if (jack_engine_load_driver (server_ptr->engine, driver_ptr->desc_ptr, driver_ptr->set_parameters))
- {
- jack_error ("cannot load driver module %s", driver_ptr->desc_ptr->name);
- goto fail_nodriver;
- }
+ if (jack_engine_load_driver (server_ptr->engine, driver_ptr->desc_ptr, driver_ptr->set_parameters)) {
+ jack_error ("cannot load driver module %s", driver_ptr->desc_ptr->name);
+ goto fail_nodriver;
+ }
- if (server_ptr->engine->driver->start (server_ptr->engine->driver) != 0) {
- jack_error ("cannot start driver");
- jack_use_driver(server_ptr->engine, NULL);
- goto fail_nodriver;
- }
+ if (server_ptr->engine->driver->start (server_ptr->engine->driver) != 0) {
+ jack_error ("cannot start driver");
+ jack_use_driver (server_ptr->engine, NULL);
+ goto fail_nodriver;
+ }
- return true;
+ return true;
fail_nodriver:
- jack_error ("could not initialise new driver, leaving without driver");
+ jack_error ("could not initialise new driver, leaving without driver");
fail_nostart:
- return false;
+ return false;
}
diff --git a/jackd/engine.c b/jackd/engine.c
index ff42547..c6b2e60 100644
--- a/jackd/engine.c
+++ b/jackd/engine.c
@@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
+ */
#include <config.h>
@@ -69,80 +69,80 @@
typedef struct {
- jack_port_internal_t *source;
- jack_port_internal_t *destination;
- signed int dir; /* -1 = feedback, 0 = self, 1 = forward */
- jack_client_internal_t *srcclient;
- jack_client_internal_t *dstclient;
+ jack_port_internal_t *source;
+ jack_port_internal_t *destination;
+ signed int dir; /* -1 = feedback, 0 = self, 1 = forward */
+ jack_client_internal_t *srcclient;
+ jack_client_internal_t *dstclient;
} jack_connection_internal_t;
typedef struct _jack_driver_info {
- jack_driver_t *(*initialize)(jack_client_t*, const JSList *);
- void (*finish);
- char (*client_name);
- dlhandle handle;
+ jack_driver_t *(*initialize)(jack_client_t *, const JSList *);
+ void (*finish);
+ char (*client_name);
+ dlhandle handle;
} jack_driver_info_t;
jack_timer_type_t clock_source = JACK_TIMER_SYSTEM_CLOCK;
-static int jack_port_assign_buffer (jack_engine_t *,
- jack_port_internal_t *);
-static jack_port_internal_t *jack_get_port_by_name (jack_engine_t *,
- const char *name);
-static int jack_rechain_graph (jack_engine_t *engine);
-static void jack_clear_fifos (jack_engine_t *engine);
-static int jack_port_do_connect (jack_engine_t *engine,
- const char *source_port,
- const char *destination_port);
-static int jack_port_do_disconnect (jack_engine_t *engine,
- const char *source_port,
- const char *destination_port);
-static int jack_port_do_disconnect_all (jack_engine_t *engine,
- jack_port_id_t);
-static int jack_port_do_unregister (jack_engine_t *engine, jack_request_t *);
-static int jack_port_do_register (jack_engine_t *engine, jack_request_t *, int);
-static int jack_do_get_port_connections (jack_engine_t *engine,
- jack_request_t *req, int reply_fd);
-static int jack_port_disconnect_internal (jack_engine_t *engine,
- jack_port_internal_t *src,
- jack_port_internal_t *dst);
-static int jack_send_connection_notification (jack_engine_t *,
- jack_uuid_t,
- jack_port_id_t,
- jack_port_id_t, int);
-static void jack_deliver_event_to_all (jack_engine_t *engine,
- jack_event_t *event);
-static void jack_notify_all_port_interested_clients (jack_engine_t *engine,
- jack_uuid_t exclude_src_id,
- jack_uuid_t exclude_dst_id,
- jack_port_id_t a,
- jack_port_id_t b,
- int connect);
-static void jack_engine_post_process (jack_engine_t *);
-static int jack_run_cycle (jack_engine_t *engine, jack_nframes_t nframes,
- float delayed_usecs);
-static int jack_run_one_cycle (jack_engine_t *engine, jack_nframes_t nframes,
- float delayed_usecs);
-static void jack_engine_delay (jack_engine_t *engine,
- float delayed_usecs);
-static void jack_engine_driver_exit (jack_engine_t* engine);
-static int jack_start_freewheeling (jack_engine_t* engine, jack_uuid_t);
-static int jack_client_feeds_transitive (jack_client_internal_t *source,
- jack_client_internal_t *dest);
-static int jack_client_sort (jack_client_internal_t *a,
- jack_client_internal_t *b);
-static void jack_check_acyclic (jack_engine_t* engine);
-static void jack_compute_all_port_total_latencies (jack_engine_t *engine);
-static void jack_compute_port_total_latency (jack_engine_t *engine, jack_port_shared_t*);
-static int jack_check_client_status (jack_engine_t* engine);
-static int jack_do_session_notify (jack_engine_t *engine, jack_request_t *req, int reply_fd );
-static void jack_port_rename_notify (jack_engine_t *engine, const char* old_name, const char* new_name);
-static void jack_do_get_client_by_uuid (jack_engine_t *engine, jack_request_t *req);
-static void jack_do_get_uuid_by_client_name (jack_engine_t *engine, jack_request_t *req);
-static void jack_do_reserve_name (jack_engine_t *engine, jack_request_t *req);
-static void jack_do_session_reply (jack_engine_t *engine, jack_request_t *req );
-static void jack_compute_new_latency (jack_engine_t *engine);
-static int jack_do_has_session_cb (jack_engine_t *engine, jack_request_t *req);
+static int jack_port_assign_buffer(jack_engine_t *,
+ jack_port_internal_t *);
+static jack_port_internal_t *jack_get_port_by_name(jack_engine_t *,
+ const char *name);
+static int jack_rechain_graph(jack_engine_t *engine);
+static void jack_clear_fifos(jack_engine_t *engine);
+static int jack_port_do_connect(jack_engine_t *engine,
+ const char *source_port,
+ const char *destination_port);
+static int jack_port_do_disconnect(jack_engine_t *engine,
+ const char *source_port,
+ const char *destination_port);
+static int jack_port_do_disconnect_all(jack_engine_t *engine,
+ jack_port_id_t);
+static int jack_port_do_unregister(jack_engine_t *engine, jack_request_t *);
+static int jack_port_do_register(jack_engine_t *engine, jack_request_t *, int);
+static int jack_do_get_port_connections(jack_engine_t *engine,
+ jack_request_t *req, int reply_fd);
+static int jack_port_disconnect_internal(jack_engine_t *engine,
+ jack_port_internal_t *src,
+ jack_port_internal_t *dst);
+static int jack_send_connection_notification(jack_engine_t *,
+ jack_uuid_t,
+ jack_port_id_t,
+ jack_port_id_t, int);
+static void jack_deliver_event_to_all(jack_engine_t *engine,
+ jack_event_t *event);
+static void jack_notify_all_port_interested_clients(jack_engine_t *engine,
+ jack_uuid_t exclude_src_id,
+ jack_uuid_t exclude_dst_id,
+ jack_port_id_t a,
+ jack_port_id_t b,
+ int connect);
+static void jack_engine_post_process(jack_engine_t *);
+static int jack_run_cycle(jack_engine_t *engine, jack_nframes_t nframes,
+ float delayed_usecs);
+static int jack_run_one_cycle(jack_engine_t *engine, jack_nframes_t nframes,
+ float delayed_usecs);
+static void jack_engine_delay(jack_engine_t *engine,
+ float delayed_usecs);
+static void jack_engine_driver_exit(jack_engine_t* engine);
+static int jack_start_freewheeling(jack_engine_t* engine, jack_uuid_t);
+static int jack_client_feeds_transitive(jack_client_internal_t *source,
+ jack_client_internal_t *dest);
+static int jack_client_sort(jack_client_internal_t *a,
+ jack_client_internal_t *b);
+static void jack_check_acyclic(jack_engine_t* engine);
+static void jack_compute_all_port_total_latencies(jack_engine_t *engine);
+static void jack_compute_port_total_latency(jack_engine_t *engine, jack_port_shared_t*);
+static int jack_check_client_status(jack_engine_t* engine);
+static int jack_do_session_notify(jack_engine_t *engine, jack_request_t *req, int reply_fd );
+static void jack_port_rename_notify(jack_engine_t *engine, const char* old_name, const char* new_name);
+static void jack_do_get_client_by_uuid(jack_engine_t *engine, jack_request_t *req);
+static void jack_do_get_uuid_by_client_name(jack_engine_t *engine, jack_request_t *req);
+static void jack_do_reserve_name(jack_engine_t *engine, jack_request_t *req);
+static void jack_do_session_reply(jack_engine_t *engine, jack_request_t *req );
+static void jack_compute_new_latency(jack_engine_t *engine);
+static int jack_do_has_session_cb(jack_engine_t *engine, jack_request_t *req);
static inline int
jack_rolling_interval (jack_time_t period_usecs)
@@ -154,7 +154,7 @@ void
jack_engine_reset_rolling_usecs (jack_engine_t *engine)
{
memset (engine->rolling_client_usecs, 0,
- sizeof (engine->rolling_client_usecs));
+ sizeof(engine->rolling_client_usecs));
engine->rolling_client_usecs_index = 0;
engine->rolling_client_usecs_cnt = 0;
@@ -173,7 +173,7 @@ jack_port_type_info (jack_engine_t *engine, jack_port_internal_t *port)
{
/* Returns a pointer to the port type information in the
engine's shared control structure.
- */
+ */
return &engine->control->port_types[port->shared->ptype_id];
}
@@ -200,7 +200,7 @@ make_directory (const char *path)
mode = 0700;
}
- if (mkdir (path, mode) < 0){
+ if (mkdir (path, mode) < 0) {
jack_error ("cannot create %s directory (%s)\n",
path, strerror (errno));
return -1;
@@ -226,7 +226,7 @@ static int
make_socket_subdirectories (const char *server_name)
{
struct stat statbuf;
- char server_dir[PATH_MAX+1] = "";
+ char server_dir[PATH_MAX + 1] = "";
/* check tmpdir directory */
if (stat (jack_tmpdir, &statbuf)) {
@@ -234,7 +234,7 @@ make_socket_subdirectories (const char *server_name)
jack_tmpdir, strerror (errno));
return -1;
} else {
- if (!S_ISDIR(statbuf.st_mode)) {
+ if (!S_ISDIR (statbuf.st_mode)) {
jack_error ("%s exists, but is not a directory!\n",
jack_tmpdir);
return -1;
@@ -259,7 +259,7 @@ make_sockets (const char *server_name, int fd[2])
{
struct sockaddr_un addr;
int i;
- char server_dir[PATH_MAX+1] = "";
+ char server_dir[PATH_MAX + 1] = "";
if (make_socket_subdirectories (server_name) < 0) {
return -1;
@@ -275,7 +275,7 @@ make_sockets (const char *server_name, int fd[2])
addr.sun_family = AF_UNIX;
for (i = 0; i < 999; i++) {
- snprintf (addr.sun_path, sizeof (addr.sun_path) - 1,
+ snprintf (addr.sun_path, sizeof(addr.sun_path) - 1,
"%s/jack_%d", jack_server_dir (server_name, server_dir), i);
if (access (addr.sun_path, F_OK) != 0) {
break;
@@ -288,7 +288,7 @@ make_sockets (const char *server_name, int fd[2])
return -1;
}
- if (bind (fd[0], (struct sockaddr *) &addr, sizeof (addr)) < 0) {
+ if (bind (fd[0], (struct sockaddr*)&addr, sizeof(addr)) < 0) {
jack_error ("cannot bind server to socket (%s)",
strerror (errno));
close (fd[0]);
@@ -313,7 +313,7 @@ make_sockets (const char *server_name, int fd[2])
addr.sun_family = AF_UNIX;
for (i = 0; i < 999; i++) {
- snprintf (addr.sun_path, sizeof (addr.sun_path) - 1,
+ snprintf (addr.sun_path, sizeof(addr.sun_path) - 1,
"%s/jack_ack_%d", jack_server_dir (server_name, server_dir), i);
if (access (addr.sun_path, F_OK) != 0) {
break;
@@ -327,7 +327,7 @@ make_sockets (const char *server_name, int fd[2])
return -1;
}
- if (bind (fd[1], (struct sockaddr *) &addr, sizeof (addr)) < 0) {
+ if (bind (fd[1], (struct sockaddr*)&addr, sizeof(addr)) < 0) {
jack_error ("cannot bind server to socket (%s)",
strerror (errno));
close (fd[0]);
@@ -354,10 +354,10 @@ jack_engine_place_port_buffers (jack_engine_t* engine,
unsigned long nports,
jack_nframes_t nframes)
{
- jack_shmsize_t offset; /* shared memory offset */
+ jack_shmsize_t offset; /* shared memory offset */
jack_port_buffer_info_t *bi;
jack_port_buffer_list_t* pti = &engine->port_buffers[ptid];
- jack_port_functions_t *pfuncs = jack_get_port_functions(ptid);
+ jack_port_functions_t *pfuncs = jack_get_port_functions (ptid);
pthread_mutex_lock (&pti->lock);
offset = 0;
@@ -399,8 +399,8 @@ jack_engine_place_port_buffers (jack_engine_t* engine,
* list in memory address order, offset zero must come
* first.
*/
- bi = pti->info = (jack_port_buffer_info_t *)
- malloc (nports * sizeof (jack_port_buffer_info_t));
+ bi = pti->info = (jack_port_buffer_info_t*)
+ malloc (nports * sizeof(jack_port_buffer_info_t));
while (offset < size) {
bi->offset = offset;
@@ -413,22 +413,23 @@ jack_engine_place_port_buffers (jack_engine_t* engine,
* for an empy buffer area.
* NOTE: audio buffer is zeroed in its buffer_init function.
*/
- bi = (jack_port_buffer_info_t *) pti->freelist->data;
+ bi = (jack_port_buffer_info_t*)pti->freelist->data;
pti->freelist = jack_slist_remove_link (pti->freelist,
pti->freelist);
port_type->zero_buffer_offset = bi->offset;
- if (ptid == JACK_AUDIO_PORT_TYPE)
+ if (ptid == JACK_AUDIO_PORT_TYPE) {
engine->silent_buffer = bi;
+ }
}
/* initialize buffers */
{
int i;
jack_shm_info_t *shm_info = &engine->port_segment[ptid];
- char* shm_segment = (char *) jack_shm_addr(shm_info);
+ char* shm_segment = (char*)jack_shm_addr (shm_info);
bi = pti->info;
- for (i=0; i<nports; ++i, ++bi)
- pfuncs->buffer_init(shm_segment + bi->offset, one_buffer, nframes);
+ for (i = 0; i < nports; ++i, ++bi)
+ pfuncs->buffer_init (shm_segment + bi->offset, one_buffer, nframes);
}
pthread_mutex_unlock (&pti->lock);
@@ -441,8 +442,8 @@ jack_resize_port_segment (jack_engine_t *engine,
unsigned long nports)
{
jack_event_t event;
- jack_shmsize_t one_buffer; /* size of one buffer */
- jack_shmsize_t size; /* segment size */
+ jack_shmsize_t one_buffer; /* size of one buffer */
+ jack_shmsize_t size; /* segment size */
jack_port_type_info_t* port_type = &engine->control->port_types[ptid];
jack_shm_info_t* shm_info = &engine->port_segment[ptid];
@@ -486,7 +487,7 @@ jack_resize_port_segment (jack_engine_t *engine,
#ifdef USE_MLOCK
if (engine->control->real_time) {
- /* Although we've called mlockall(CURRENT|FUTURE), the
+ /* Although we've called mlockall(CURRENT|FUTURE), the
* Linux VM manager still allows newly allocated pages
* to fault on first reference. This mlock() ensures
* that any new pages are present before restarting
@@ -497,11 +498,11 @@ jack_resize_port_segment (jack_engine_t *engine,
int rc = mlock (jack_shm_addr (shm_info), size);
if (rc < 0) {
- jack_error("JACK: unable to mlock() port buffers: "
- "%s", strerror(errno));
+ jack_error ("JACK: unable to mlock() port buffers: "
+ "%s", strerror (errno));
}
}
-#endif /* USE_MLOCK */
+#endif /* USE_MLOCK */
/* Tell everybody about this segment. */
event.type = AttachPortSegment;
@@ -525,9 +526,10 @@ jack_driver_buffer_size (jack_engine_t *engine, jack_nframes_t nframes)
VERBOSE (engine, "new buffer size %" PRIu32, nframes);
engine->control->buffer_size = nframes;
- if (engine->driver)
+ if (engine->driver) {
engine->rolling_interval =
jack_rolling_interval (engine->driver->period_usecs);
+ }
for (i = 0; i < engine->control->n_port_types; ++i) {
if (jack_resize_port_segment (engine, i, engine->control->port_max)) {
@@ -550,32 +552,34 @@ jack_set_buffer_size_request (jack_engine_t *engine, jack_nframes_t nframes)
int rc;
jack_driver_t* driver = engine->driver;
- if (driver == NULL)
- return ENXIO; /* no such device */
+ if (driver == NULL) {
+ return ENXIO; /* no such device */
- if (!jack_power_of_two(nframes)) {
- jack_error("buffer size %" PRIu32 " not a power of 2",
- nframes);
+ }
+ if (!jack_power_of_two (nframes)) {
+ jack_error ("buffer size %" PRIu32 " not a power of 2",
+ nframes);
return EINVAL;
}
- rc = driver->bufsize(driver, nframes);
- if (rc != 0)
- jack_error("driver does not support %" PRIu32
- "-frame buffers", nframes);
+ rc = driver->bufsize (driver, nframes);
+ if (rc != 0) {
+ jack_error ("driver does not support %" PRIu32
+ "-frame buffers", nframes);
+ }
return rc;
}
static JSList *
-jack_process_internal(jack_engine_t *engine, JSList *node,
- jack_nframes_t nframes)
+jack_process_internal (jack_engine_t *engine, JSList *node,
+ jack_nframes_t nframes)
{
jack_client_internal_t *client;
jack_client_control_t *ctl;
- client = (jack_client_internal_t *) node->data;
+ client = (jack_client_internal_t*)node->data;
ctl = client->control;
/* internal client */
@@ -586,24 +590,28 @@ jack_process_internal(jack_engine_t *engine, JSList *node,
/* XXX how to time out an internal client? */
- if (ctl->sync_cb_cbset)
+ if (ctl->sync_cb_cbset) {
jack_call_sync_client (client->private_client);
+ }
- if (ctl->process_cbset)
+ if (ctl->process_cbset) {
if (client->private_client->process (nframes, client->private_client->process_arg)) {
jack_error ("internal client %s failed", ctl->name);
engine->process_errors++;
}
+ }
- if (ctl->timebase_cb_cbset)
+ if (ctl->timebase_cb_cbset) {
jack_call_timebase_master (client->private_client);
+ }
ctl->state = Finished;
- if (engine->process_errors)
- return NULL; /* will stop the loop */
- else
+ if (engine->process_errors) {
+ return NULL; /* will stop the loop */
+ } else {
return jack_slist_next (node);
+ }
}
#ifdef __linux
@@ -611,7 +619,7 @@ jack_process_internal(jack_engine_t *engine, JSList *node,
/* Linux kernels somewhere between 2.6.18 and 2.6.24 had a bug
in poll(2) that led poll to return early. To fix it, we need
to know that that jack_get_microseconds() is monotonic.
-*/
+ */
#ifdef HAVE_CLOCK_GETTIME
static const int system_clock_monotonic = 1;
@@ -629,7 +637,7 @@ linux_poll_bug_encountered (jack_engine_t* engine, jack_time_t then, jack_time_t
/*
So, adjust poll timeout to account for time already spent waiting.
- */
+ */
VERBOSE (engine, "FALSE WAKEUP (%lldusecs vs. %lld usec)", (now - then), *required);
*required -= (now - then);
@@ -644,22 +652,22 @@ linux_poll_bug_encountered (jack_engine_t* engine, jack_time_t then, jack_time_t
#ifdef JACK_USE_MACH_THREADS
static JSList *
-jack_process_external(jack_engine_t *engine, JSList *node)
+jack_process_external (jack_engine_t *engine, JSList *node)
{
- jack_client_internal_t * client = (jack_client_internal_t *) node->data;
+ jack_client_internal_t * client = (jack_client_internal_t*)node->data;
jack_client_control_t *ctl;
- client = (jack_client_internal_t *) node->data;
+ client = (jack_client_internal_t*)node->data;
ctl = client->control;
engine->current_client = client;
// a race exists if we do this after the write(2)
ctl->state = Triggered;
- ctl->signalled_at = jack_get_microseconds();
+ ctl->signalled_at = jack_get_microseconds ();
- if (jack_client_resume(client) < 0) {
- jack_error("Client will be removed\n");
+ if (jack_client_resume (client) < 0) {
+ jack_error ("Client will be removed\n");
ctl->state = Finished;
}
@@ -667,7 +675,7 @@ jack_process_external(jack_engine_t *engine, JSList *node)
}
#else /* !JACK_USE_MACH_THREADS */
static JSList *
-jack_process_external(jack_engine_t *engine, JSList *node)
+jack_process_external (jack_engine_t *engine, JSList *node)
{
int status = 0;
char c = 0;
@@ -679,7 +687,7 @@ jack_process_external(jack_engine_t *engine, JSList *node)
jack_time_t now, then;
int pollret;
- client = (jack_client_internal_t *) node->data;
+ client = (jack_client_internal_t*)node->data;
ctl = client->control;
@@ -688,14 +696,14 @@ jack_process_external(jack_engine_t *engine, JSList *node)
/* a race exists if we do this after the write(2) */
ctl->state = Triggered;
- ctl->signalled_at = jack_get_microseconds();
+ ctl->signalled_at = jack_get_microseconds ();
engine->current_client = client;
DEBUG ("calling process() on an external subgraph, fd==%d",
client->subgraph_start_fd);
- if (write (client->subgraph_start_fd, &c, sizeof (c)) != sizeof (c)) {
+ if (write (client->subgraph_start_fd, &c, sizeof(c)) != sizeof(c)) {
jack_error ("cannot initiate graph processing (%s)",
strerror (errno));
engine->process_errors++;
@@ -709,14 +717,14 @@ jack_process_external(jack_engine_t *engine, JSList *node)
poll_timeout_usecs = 250000; /* 0.25 seconds */
} else {
poll_timeout_usecs = (engine->client_timeout_msecs > 0 ?
- engine->client_timeout_msecs * 1000 :
- engine->driver->period_usecs);
+ engine->client_timeout_msecs * 1000 :
+ engine->driver->period_usecs);
}
- again:
+again:
poll_timeout = 1 + poll_timeout_usecs / 1000;
pfd[0].fd = client->subgraph_wait_fd;
- pfd[0].events = POLLERR|POLLIN|POLLHUP|POLLNVAL;
+ pfd[0].events = POLLERR | POLLIN | POLLHUP | POLLNVAL;
DEBUG ("waiting on fd==%d for process() subgraph to finish (timeout = %d, period_usecs = %d)",
client->subgraph_wait_fd, poll_timeout, engine->driver->period_usecs);
@@ -743,7 +751,7 @@ jack_process_external(jack_engine_t *engine, JSList *node)
/* no events, no errors, we woke up because poll()
decided that time was up ...
- */
+ */
if (engine->freewheeling) {
if (jack_check_client_status (engine)) {
@@ -751,7 +759,7 @@ jack_process_external(jack_engine_t *engine, JSList *node)
} else {
/* all clients are fine - we're just not done yet. since
we're freewheeling, that is fine.
- */
+ */
goto again;
}
}
@@ -774,7 +782,7 @@ jack_process_external(jack_engine_t *engine, JSList *node)
pollret, pfd[0].revents);
status = 1;
#ifdef __linux
- }
+ }
#endif
}
@@ -793,13 +801,13 @@ jack_process_external(jack_engine_t *engine, JSList *node)
ctl->signalled_at,
ctl->awake_at,
ctl->finished_at,
- ctl->finished_at? (ctl->finished_at -
- ctl->signalled_at): 0);
+ ctl->finished_at ? (ctl->finished_at -
+ ctl->signalled_at) : 0);
if (jack_check_clients (engine, 1)) {
engine->process_errors++;
- return NULL; /* will stop the loop */
+ return NULL; /* will stop the loop */
}
} else {
engine->timeout_count = 0;
@@ -809,21 +817,21 @@ jack_process_external(jack_engine_t *engine, JSList *node)
DEBUG ("reading byte from subgraph_wait_fd==%d",
client->subgraph_wait_fd);
- if (read (client->subgraph_wait_fd, &c, sizeof(c)) != sizeof (c)) {
+ if (read (client->subgraph_wait_fd, &c, sizeof(c)) != sizeof(c)) {
if (errno == EAGAIN) {
jack_error ("pp: cannot clean up byte from graph wait "
- "fd - no data present");
+ "fd - no data present");
} else {
jack_error ("pp: cannot clean up byte from graph wait fd (%s)",
- strerror (errno));
+ strerror (errno));
client->error++;
}
- return NULL; /* will stop the loop */
+ return NULL; /* will stop the loop */
}
/* Move to next internal client (or end of client list) */
while (node) {
- if (jack_client_is_internal ((jack_client_internal_t *)
+ if (jack_client_is_internal ((jack_client_internal_t*)
node->data)) {
break;
}
@@ -846,7 +854,7 @@ jack_engine_process (jack_engine_t *engine, jack_nframes_t nframes)
for (node = engine->clients; node; node = jack_slist_next (node)) {
jack_client_control_t *ctl =
- ((jack_client_internal_t *) node->data)->control;
+ ((jack_client_internal_t*)node->data)->control;
ctl->state = NotTriggered;
ctl->timed_out = 0;
ctl->awake_at = 0;
@@ -855,14 +863,14 @@ jack_engine_process (jack_engine_t *engine, jack_nframes_t nframes)
for (node = engine->clients; engine->process_errors == 0 && node; ) {
- client = (jack_client_internal_t *) node->data;
+ client = (jack_client_internal_t*)node->data;
DEBUG ("considering client %s for processing",
client->control->name);
if (!client->control->active ||
- (!client->control->process_cbset && !client->control->thread_cb_cbset) ||
- client->control->dead) {
+ (!client->control->process_cbset && !client->control->thread_cb_cbset) ||
+ client->control->dead) {
node = jack_slist_next (node);
} else if (jack_client_is_internal (client)) {
node = jack_process_internal (engine, node, nframes);
@@ -875,7 +883,7 @@ jack_engine_process (jack_engine_t *engine, jack_nframes_t nframes)
}
static void
-jack_calc_cpu_load(jack_engine_t *engine)
+jack_calc_cpu_load (jack_engine_t *engine)
{
jack_time_t cycle_end = jack_get_microseconds ();
@@ -893,7 +901,7 @@ jack_calc_cpu_load(jack_engine_t *engine)
/* every so often, recompute the current maximum use over the
last JACK_ENGINE_ROLLING_COUNT client iterations.
- */
+ */
if (++engine->rolling_client_usecs_cnt
% engine->rolling_interval == 0) {
@@ -946,9 +954,9 @@ jack_load_driver (jack_engine_t *engine, jack_driver_desc_t * driver_desc)
const char *errstr;
jack_driver_info_t *info;
- info = (jack_driver_info_t *) calloc (1, sizeof (*info));
+ info = (jack_driver_info_t*)calloc (1, sizeof(*info));
- info->handle = dlopen (driver_desc->file, RTLD_NOW|RTLD_GLOBAL);
+ info->handle = dlopen (driver_desc->file, RTLD_NOW | RTLD_GLOBAL);
if (info->handle == NULL) {
if ((errstr = dlerror ()) != 0) {
@@ -977,7 +985,7 @@ jack_load_driver (jack_engine_t *engine, jack_driver_desc_t * driver_desc)
goto fail;
}
- info->client_name = (char *) dlsym (info->handle, "driver_client_name");
+ info->client_name = (char*)dlsym (info->handle, "driver_client_name");
if ((errstr = dlerror ()) != 0) {
jack_error ("no client name in in shared driver object %s",
@@ -987,7 +995,7 @@ jack_load_driver (jack_engine_t *engine, jack_driver_desc_t * driver_desc)
return info;
- fail:
+fail:
if (info->handle) {
dlclose (info->handle);
}
@@ -1000,6 +1008,7 @@ void
jack_driver_unload (jack_driver_t *driver)
{
void* handle = driver->handle;
+
driver->finish (driver);
dlclose (handle);
}
@@ -1018,7 +1027,7 @@ jack_engine_load_driver (jack_engine_t *engine,
}
if ((client = jack_create_driver_client (engine, info->client_name)
- ) == NULL) {
+ ) == NULL) {
return -1;
}
@@ -1059,7 +1068,7 @@ jack_engine_load_slave_driver (jack_engine_t *engine,
}
if ((client = jack_create_driver_client (engine, info->client_name)
- ) == NULL) {
+ ) == NULL) {
jack_info ("Creating slave failed\n");
return -1;
}
@@ -1092,7 +1101,7 @@ jack_engine_load_slave_driver (jack_engine_t *engine,
static int check_capabilities (jack_engine_t *engine)
{
- cap_t caps = cap_init();
+ cap_t caps = cap_init ();
cap_flag_value_t cap;
pid_t pid;
int have_all_caps = 1;
@@ -1110,28 +1119,28 @@ static int check_capabilities (jack_engine_t *engine)
return 0;
}
/* check that we are able to give capabilites to other processes */
- cap_get_flag(caps, CAP_SETPCAP, CAP_EFFECTIVE, &cap);
+ cap_get_flag (caps, CAP_SETPCAP, CAP_EFFECTIVE, &cap);
if (cap == CAP_CLEAR) {
have_all_caps = 0;
goto done;
}
/* check that we have the capabilities we want to transfer */
- cap_get_flag(caps, CAP_SYS_NICE, CAP_EFFECTIVE, &cap);
+ cap_get_flag (caps, CAP_SYS_NICE, CAP_EFFECTIVE, &cap);
if (cap == CAP_CLEAR) {
have_all_caps = 0;
goto done;
}
- cap_get_flag(caps, CAP_SYS_RESOURCE, CAP_EFFECTIVE, &cap);
+ cap_get_flag (caps, CAP_SYS_RESOURCE, CAP_EFFECTIVE, &cap);
if (cap == CAP_CLEAR) {
have_all_caps = 0;
goto done;
}
- cap_get_flag(caps, CAP_IPC_LOCK, CAP_EFFECTIVE, &cap);
+ cap_get_flag (caps, CAP_IPC_LOCK, CAP_EFFECTIVE, &cap);
if (cap == CAP_CLEAR) {
have_all_caps = 0;
goto done;
}
- done:
+done:
cap_free (caps);
return have_all_caps;
}
@@ -1139,24 +1148,24 @@ static int check_capabilities (jack_engine_t *engine)
static int give_capabilities (jack_engine_t *engine, pid_t pid)
{
- cap_t caps = cap_init();
+ cap_t caps = cap_init ();
const unsigned caps_size = 3;
- cap_value_t cap_list[] = {CAP_SYS_NICE, CAP_SYS_RESOURCE, CAP_IPC_LOCK};
+ cap_value_t cap_list[] = { CAP_SYS_NICE, CAP_SYS_RESOURCE, CAP_IPC_LOCK };
if (caps == NULL) {
VERBOSE (engine, "give: could not allocate capability"
" working storage");
return -1;
}
- cap_clear(caps);
+ cap_clear (caps);
if (capgetp (pid, caps)) {
VERBOSE (engine, "give: could not get current "
"capabilities for process %d", pid);
- cap_clear(caps);
+ cap_clear (caps);
}
- cap_set_flag(caps, CAP_EFFECTIVE, caps_size, cap_list , CAP_SET);
- cap_set_flag(caps, CAP_INHERITABLE, caps_size, cap_list , CAP_SET);
- cap_set_flag(caps, CAP_PERMITTED, caps_size, cap_list , CAP_SET);
+ cap_set_flag (caps, CAP_EFFECTIVE, caps_size, cap_list, CAP_SET);
+ cap_set_flag (caps, CAP_INHERITABLE, caps_size, cap_list, CAP_SET);
+ cap_set_flag (caps, CAP_PERMITTED, caps_size, cap_list, CAP_SET);
if (capsetp (pid, caps)) {
cap_free (caps);
return -1;
@@ -1174,7 +1183,7 @@ jack_set_client_capabilities (jack_engine_t *engine, pid_t cap_pid)
already checked that the engine has
realtime capabilities, that it is running
realtime and that the pid is defined
- */
+ */
if ((ret = give_capabilities (engine, cap_pid)) != 0) {
jack_error ("could not give capabilities to "
@@ -1217,19 +1226,19 @@ do_request (jack_engine_t *engine, jack_request_t *req, int *reply_fd)
case ConnectPorts:
req->status = jack_port_do_connect
- (engine, req->x.connect.source_port,
- req->x.connect.destination_port);
+ (engine, req->x.connect.source_port,
+ req->x.connect.destination_port);
break;
case DisconnectPort:
req->status = jack_port_do_disconnect_all
- (engine, req->x.port_info.port_id);
+ (engine, req->x.port_info.port_id);
break;
case DisconnectPorts:
req->status = jack_port_do_disconnect
- (engine, req->x.connect.source_port,
- req->x.connect.destination_port);
+ (engine, req->x.connect.source_port,
+ req->x.connect.destination_port);
break;
case ActivateClient:
@@ -1272,13 +1281,13 @@ do_request (jack_engine_t *engine, jack_request_t *req, int *reply_fd)
req->status = jack_set_client_capabilities (engine,
req->x.cap_pid);
break;
-#endif /* USE_CAPABILITIES */
+#endif /* USE_CAPABILITIES */
case GetPortConnections:
case GetPortNConnections:
//JOQ bug: reply_fd may be NULL if internal request
if ((req->status =
- jack_do_get_port_connections (engine, req, *reply_fd))
+ jack_do_get_port_connections (engine, req, *reply_fd))
== 0) {
/* we have already replied, don't do it again */
*reply_fd = -1;
@@ -1354,7 +1363,7 @@ do_request (jack_engine_t *engine, jack_request_t *req, int *reply_fd)
case SessionNotify:
jack_rdlock_graph (engine);
if ((req->status =
- jack_do_session_notify (engine, req, *reply_fd))
+ jack_do_session_notify (engine, req, *reply_fd))
>= 0) {
/* we have already replied, don't do it again */
*reply_fd = -1;
@@ -1390,7 +1399,7 @@ do_request (jack_engine_t *engine, jack_request_t *req, int *reply_fd)
int
internal_client_request (void* ptr, jack_request_t *request)
{
- do_request ((jack_engine_t*) ptr, request, NULL);
+ do_request ((jack_engine_t*)ptr, request, NULL);
return request->status;
}
@@ -1406,8 +1415,8 @@ handle_external_client_request (jack_engine_t *engine, int fd)
ssize_t r;
for (node = engine->clients; node; node = jack_slist_next (node)) {
- if (((jack_client_internal_t *) node->data)->request_fd == fd) {
- client = (jack_client_internal_t *) node->data;
+ if (((jack_client_internal_t*)node->data)->request_fd == fd) {
+ client = (jack_client_internal_t*)node->data;
break;
}
}
@@ -1417,8 +1426,8 @@ handle_external_client_request (jack_engine_t *engine, int fd)
return -1;
}
- if ((r = read (client->request_fd, &req, sizeof (req)))
- < (ssize_t) sizeof (req)) {
+ if ((r = read (client->request_fd, &req, sizeof(req)))
+ < (ssize_t)sizeof(req)) {
if (r == 0) {
#ifdef JACK_USE_MACH_THREADS
/* poll is implemented using
@@ -1431,9 +1440,9 @@ handle_external_client_request (jack_engine_t *engine, int fd)
Linux poll behaviour. Thus we use
this condition as a socket error
and remove the client.
- */
+ */
jack_mark_client_socket_error (engine, fd);
-#endif /* JACK_USE_MACH_THREADS */
+#endif /* JACK_USE_MACH_THREADS */
return 1;
} else {
jack_error ("cannot read request from client (%d/%d/%s)",
@@ -1446,12 +1455,12 @@ handle_external_client_request (jack_engine_t *engine, int fd)
if (req.type == PropertyChangeNotify) {
if (req.x.property.keylen) {
- req.x.property.key = (char*) malloc (req.x.property.keylen);
- if ((r = read (client->request_fd, (char*) req.x.property.key, req.x.property.keylen)) != req.x.property.keylen) {
+ req.x.property.key = (char*)malloc (req.x.property.keylen);
+ if ((r = read (client->request_fd, (char*)req.x.property.key, req.x.property.keylen)) != req.x.property.keylen) {
jack_error ("cannot read property key from client (%d/%d/%s)",
- r, sizeof(req), strerror (errno));
+ r, sizeof(req), strerror (errno));
return -1;
- }
+ }
} else {
req.x.property.key = 0;
}
@@ -1464,13 +1473,13 @@ handle_external_client_request (jack_engine_t *engine, int fd)
jack_lock_graph (engine);
if (req.type == PropertyChangeNotify && req.x.property.key) {
- free ((char *) req.x.property.key);
+ free ((char*)req.x.property.key);
}
if (reply_fd >= 0) {
DEBUG ("replying to client");
- if (write (reply_fd, &req, sizeof (req))
- < (ssize_t) sizeof (req)) {
+ if (write (reply_fd, &req, sizeof(req))
+ < (ssize_t)sizeof(req)) {
jack_error ("cannot write request result to client");
return -1;
}
@@ -1488,7 +1497,7 @@ handle_client_ack_connection (jack_engine_t *engine, int client_fd)
jack_client_connect_ack_request_t req;
jack_client_connect_ack_result_t res;
- if (read (client_fd, &req, sizeof (req)) != sizeof (req)) {
+ if (read (client_fd, &req, sizeof(req)) != sizeof(req)) {
jack_error ("cannot read ACK connection request from client");
return -1;
}
@@ -1505,7 +1514,7 @@ handle_client_ack_connection (jack_engine_t *engine, int client_fd)
res.status = 0;
- if (write (client->event_fd, &res, sizeof (res)) != sizeof (res)) {
+ if (write (client->event_fd, &res, sizeof(res)) != sizeof(res)) {
jack_error ("cannot write ACK connection response to client");
return -1;
}
@@ -1518,7 +1527,7 @@ static void *
jack_server_thread (void *arg)
{
- jack_engine_t *engine = (jack_engine_t *) arg;
+ jack_engine_t *engine = (jack_engine_t*)arg;
struct sockaddr_un client_addr;
socklen_t client_addrlen;
int problemsProblemsPROBLEMS = 0;
@@ -1541,32 +1550,33 @@ jack_server_thread (void *arg)
free (engine->pfd);
}
- engine->pfd = (struct pollfd *) malloc(sizeof(struct pollfd) *
- (fixed_fd_cnt + clients));
+ engine->pfd = (struct pollfd*)malloc (sizeof(struct pollfd) *
+ (fixed_fd_cnt + clients));
if (engine->pfd == NULL) {
/*
* this can happen if limits.conf was changed
* but the user hasn't logged out and back in yet
*/
- if (errno == EAGAIN)
- jack_error("malloc failed (%s) - make"
- "sure you log out and back"
- "in after changing limits"
- ".conf!", strerror(errno));
- else
- jack_error("malloc failed (%s)", strerror(errno));
+ if (errno == EAGAIN) {
+ jack_error ("malloc failed (%s) - make"
+ "sure you log out and back"
+ "in after changing limits"
+ ".conf!", strerror (errno));
+ } else {
+ jack_error ("malloc failed (%s)", strerror (errno));
+ }
break;
}
}
engine->pfd[0].fd = engine->fds[0];
- engine->pfd[0].events = POLLIN|POLLERR;
+ engine->pfd[0].events = POLLIN | POLLERR;
engine->pfd[1].fd = engine->fds[1];
- engine->pfd[1].events = POLLIN|POLLERR;
+ engine->pfd[1].events = POLLIN | POLLERR;
engine->pfd[2].fd = engine->cleanup_fifo[0];
- engine->pfd[2].events = POLLIN|POLLERR;
+ engine->pfd[2].events = POLLIN | POLLERR;
engine->pfd_max = fixed_fd_cnt;
for (node = engine->clients; node; node = node->next) {
@@ -1576,14 +1586,14 @@ jack_server_thread (void *arg)
if (client->request_fd < 0 || client->error >= JACK_ERROR_WITH_SOCKETS) {
continue;
}
- if( client->control->dead ) {
+ if ( client->control->dead ) {
engine->pfd[engine->pfd_max].fd = client->request_fd;
- engine->pfd[engine->pfd_max].events = POLLHUP|POLLNVAL;
+ engine->pfd[engine->pfd_max].events = POLLHUP | POLLNVAL;
engine->pfd_max++;
continue;
}
engine->pfd[engine->pfd_max].fd = client->request_fd;
- engine->pfd[engine->pfd_max].events = POLLIN|POLLPRI|POLLERR|POLLHUP|POLLNVAL;
+ engine->pfd[engine->pfd_max].events = POLLIN | POLLPRI | POLLERR | POLLHUP | POLLNVAL;
engine->pfd_max++;
}
@@ -1593,7 +1603,7 @@ jack_server_thread (void *arg)
/* go to sleep for a long, long time, or until a request
arrives, or until a communication channel is broken
- */
+ */
if (poll (engine->pfd, engine->pfd_max, -1) < 0) {
if (errno == EINTR) {
@@ -1603,11 +1613,11 @@ jack_server_thread (void *arg)
break;
}
- VERBOSE(engine, "server thread back from poll");
+ VERBOSE (engine, "server thread back from poll");
/* Stephane Letz: letz@grame.fr : has to be added
* otherwise pthread_cancel() does not work on MacOSX */
- pthread_testcancel();
+ pthread_testcancel ();
/* empty cleanup FIFO if necessary */
@@ -1619,7 +1629,7 @@ jack_server_thread (void *arg)
if (engine->pfd[2].revents & POLLIN) {
char c;
- while (read (engine->cleanup_fifo[0], &c, 1) == 1);
+ while (read (engine->cleanup_fifo[0], &c, 1) == 1) ;
}
/* check each client socket before handling other request*/
@@ -1690,13 +1700,13 @@ jack_server_thread (void *arg)
if (engine->control->engine_ok && engine->pfd[0].revents & POLLIN) {
DEBUG ("pfd[0].revents & POLLIN");
- memset (&client_addr, 0, sizeof (client_addr));
- client_addrlen = sizeof (client_addr);
+ memset (&client_addr, 0, sizeof(client_addr));
+ client_addrlen = sizeof(client_addr);
if ((client_socket =
- accept (engine->fds[0],
- (struct sockaddr *) &client_addr,
- &client_addrlen)) < 0) {
+ accept (engine->fds[0],
+ (struct sockaddr*)&client_addr,
+ &client_addrlen)) < 0) {
jack_error ("cannot accept new connection (%s)",
strerror (errno));
} else if (!engine->new_clients_allowed || jack_client_create (engine, client_socket) < 0) {
@@ -1716,17 +1726,17 @@ jack_server_thread (void *arg)
if (engine->control->engine_ok && engine->pfd[1].revents & POLLIN) {
DEBUG ("pfd[1].revents & POLLIN");
- memset (&client_addr, 0, sizeof (client_addr));
- client_addrlen = sizeof (client_addr);
+ memset (&client_addr, 0, sizeof(client_addr));
+ client_addrlen = sizeof(client_addr);
if ((client_socket =
- accept (engine->fds[1],
- (struct sockaddr *) &client_addr,
- &client_addrlen)) < 0) {
+ accept (engine->fds[1],
+ (struct sockaddr*)&client_addr,
+ &client_addrlen)) < 0) {
jack_error ("cannot accept new ACK connection"
" (%s)", strerror (errno));
} else if (handle_client_ack_connection
- (engine, client_socket)) {
+ (engine, client_socket)) {
jack_error ("cannot complete client ACK "
"connection process");
close (client_socket);
@@ -1745,24 +1755,24 @@ jack_engine_new (int realtime, int rtpriority, int do_mlock, int do_unlock,
{
jack_engine_t *engine;
unsigned int i;
- char server_dir[PATH_MAX+1] = "";
+ char server_dir[PATH_MAX + 1] = "";
#ifdef USE_CAPABILITIES
uid_t uid = getuid ();
uid_t euid = geteuid ();
-#endif /* USE_CAPABILITIES */
+#endif /* USE_CAPABILITIES */
/* before we start allocating resources, make sure that if realtime was requested that we can
actually do it.
- */
+ */
if (realtime) {
- if (jack_acquire_real_time_scheduling (pthread_self(), 10) != 0) {
+ if (jack_acquire_real_time_scheduling (pthread_self (), 10) != 0) {
/* can't run realtime - time to bomb */
return NULL;
}
- jack_drop_real_time_scheduling (pthread_self());
+ jack_drop_real_time_scheduling (pthread_self ());
#ifdef USE_MLOCK
@@ -1771,18 +1781,18 @@ jack_engine_new (int realtime, int rtpriority, int do_mlock, int do_unlock,
strerror (errno));
#ifdef ENSURE_MLOCK
return NULL;
-#endif /* ENSURE_MLOCK */
+#endif /* ENSURE_MLOCK */
}
-#endif /* USE_MLOCK */
+#endif /* USE_MLOCK */
}
/* start a thread to display messages from realtime threads */
- jack_messagebuffer_init();
+ jack_messagebuffer_init ();
jack_init_time ();
/* allocate the engine, zero the structure to ease debugging */
- engine = (jack_engine_t *) calloc (1, sizeof (jack_engine_t));
+ engine = (jack_engine_t*)calloc (1, sizeof(jack_engine_t));
engine->drivers = drivers;
engine->driver = NULL;
@@ -1842,10 +1852,9 @@ jack_engine_new (int realtime, int rtpriority, int do_mlock, int do_unlock,
engine->pfd = 0;
engine->fifo_size = 16;
- engine->fifo = (int *) malloc (sizeof (int) * engine->fifo_size);
- for (i = 0; i < engine->fifo_size; i++) {
+ engine->fifo = (int*)malloc (sizeof(int) * engine->fifo_size);
+ for (i = 0; i < engine->fifo_size; i++)
engine->fifo[i] = -1;
- }
if (pipe (engine->cleanup_fifo)) {
jack_error ("cannot create cleanup FIFOs (%s)", strerror (errno));
@@ -1864,10 +1873,10 @@ jack_engine_new (int realtime, int rtpriority, int do_mlock, int do_unlock,
engine->external_client_cnt = 0;
- srandom (time ((time_t *) 0));
+ srandom (time ((time_t*)0));
- if (jack_shmalloc (sizeof (jack_control_t)
- + ((sizeof (jack_port_shared_t) * engine->port_max)),
+ if (jack_shmalloc (sizeof(jack_control_t)
+ + ((sizeof(jack_port_shared_t) * engine->port_max)),
&engine->control_shm)) {
jack_error ("cannot create engine control shared memory "
"segment (%s)", strerror (errno));
@@ -1881,8 +1890,8 @@ jack_engine_new (int realtime, int rtpriority, int do_mlock, int do_unlock,
return NULL;
}
- engine->control = (jack_control_t *)
- jack_shm_addr (&engine->control_shm);
+ engine->control = (jack_control_t*)
+ jack_shm_addr (&engine->control_shm);
/* Setup port type information from builtins. buffer space is
* allocated when the driver calls jack_driver_buffer_size().
@@ -1891,7 +1900,7 @@ jack_engine_new (int realtime, int rtpriority, int do_mlock, int do_unlock,
memcpy (&engine->control->port_types[i],
&jack_builtin_port_types[i],
- sizeof (jack_port_type_info_t));
+ sizeof(jack_port_type_info_t));
VERBOSE (engine, "registered builtin port type %s",
engine->control->port_types[i].type_name);
@@ -1925,12 +1934,11 @@ jack_engine_new (int realtime, int rtpriority, int do_mlock, int do_unlock,
/* allocate internal port structures so that we can keep track
* of port connections.
*/
- engine->internal_ports = (jack_port_internal_t *)
- malloc (sizeof (jack_port_internal_t) * engine->port_max);
+ engine->internal_ports = (jack_port_internal_t*)
+ malloc (sizeof(jack_port_internal_t) * engine->port_max);
- for (i = 0; i < engine->port_max; i++) {
+ for (i = 0; i < engine->port_max; i++)
engine->internal_ports[i].connections = 0;
- }
if (make_sockets (engine->server_name, engine->fds) < 0) {
jack_error ("cannot create server sockets");
@@ -1945,7 +1953,7 @@ jack_engine_new (int realtime, int rtpriority, int do_mlock, int do_unlock,
but less than the server. see thread.h for
jack_client_real_time_priority() and jack_client_max_real_time_priority()
which are affected by this.
- */
+ */
engine->control->client_priority = (realtime
? engine->rtpriority - 5
@@ -1961,7 +1969,7 @@ jack_engine_new (int realtime, int rtpriority, int do_mlock, int do_unlock,
jack_set_clock_source (clock_source);
engine->control->clock_source = clock_source;
- engine->get_microseconds = jack_get_microseconds_pointer();
+ engine->get_microseconds = jack_get_microseconds_pointer ();
VERBOSE (engine, "clock source = %s", jack_clock_source_name (clock_source));
@@ -1970,8 +1978,8 @@ jack_engine_new (int realtime, int rtpriority, int do_mlock, int do_unlock,
engine->control->frame_timer.current_wakeup = 0;
engine->control->frame_timer.next_wakeup = 0;
engine->control->frame_timer.initialized = 0;
- engine->control->frame_timer.filter_omega = 0; /* Initialised later */
- engine->control->frame_timer.period_usecs = 0; /* Initialised later */
+ engine->control->frame_timer.filter_omega = 0; /* Initialised later */
+ engine->control->frame_timer.period_usecs = 0; /* Initialised later */
engine->first_wakeup = 1;
@@ -1985,13 +1993,13 @@ jack_engine_new (int realtime, int rtpriority, int do_mlock, int do_unlock,
#ifdef JACK_USE_MACH_THREADS
/* specific resources for server/client real-time thread
* communication */
- engine->servertask = mach_task_self();
- if (task_get_bootstrap_port(engine->servertask, &engine->bp)){
- jack_error("Jackd: Can't find bootstrap mach port");
+ engine->servertask = mach_task_self ();
+ if (task_get_bootstrap_port (engine->servertask, &engine->bp)) {
+ jack_error ("Jackd: Can't find bootstrap mach port");
return NULL;
}
engine->portnum = 0;
-#endif /* JACK_USE_MACH_THREADS */
+#endif /* JACK_USE_MACH_THREADS */
#ifdef USE_CAPABILITIES
@@ -2008,21 +2016,21 @@ jack_engine_new (int realtime, int rtpriority, int do_mlock, int do_unlock,
}
if (engine->verbose) {
size_t size;
- cap_t cap = cap_init();
- capgetp(0, cap);
+ cap_t cap = cap_init ();
+ capgetp (0, cap);
VERBOSE (engine, "capabilities: %s",
- cap_to_text(cap, &size));
+ cap_to_text (cap, &size));
}
}
-#endif /* USE_CAPABILITIES */
+#endif /* USE_CAPABILITIES */
engine->control->engine_ok = 1;
- snprintf (engine->fifo_prefix, sizeof (engine->fifo_prefix),
+ snprintf (engine->fifo_prefix, sizeof(engine->fifo_prefix),
"%s/jack-ack-fifo-%d",
jack_server_dir (engine->server_name, server_dir), getpid ());
- (void) jack_get_fifo_fd (engine, 0);
+ (void)jack_get_fifo_fd (engine, 0);
jack_client_create_thread (NULL, &engine->server_thread, 0, FALSE,
&jack_server_thread, engine);
@@ -2039,8 +2047,9 @@ jack_engine_delay (jack_engine_t *engine, float delayed_usecs)
engine->control->xrun_delayed_usecs = delayed_usecs;
- if (delayed_usecs > engine->control->max_delayed_usecs)
+ if (delayed_usecs > engine->control->max_delayed_usecs) {
engine->control->max_delayed_usecs = delayed_usecs;
+ }
event.type = XRun;
@@ -2050,14 +2059,14 @@ jack_engine_delay (jack_engine_t *engine, float delayed_usecs)
static void*
jack_engine_freewheel (void *arg)
{
- jack_engine_t* engine = (jack_engine_t *) arg;
+ jack_engine_t* engine = (jack_engine_t*)arg;
jack_client_internal_t* client;
VERBOSE (engine, "freewheel thread starting ...");
/* we should not be running SCHED_FIFO, so we don't
have to do anything about scheduling.
- */
+ */
client = jack_client_internal_by_id (engine, engine->fwclient);
@@ -2069,7 +2078,7 @@ jack_engine_freewheel (void *arg)
/* run one cycle() will already have told the server thread
about issues, and the server thread will clean up.
however, its time for us to depart this world ...
- */
+ */
break;
}
}
@@ -2079,37 +2088,36 @@ jack_engine_freewheel (void *arg)
}
static void
-jack_slave_driver_remove(jack_engine_t *engine, jack_driver_t *sdriver)
+jack_slave_driver_remove (jack_engine_t *engine, jack_driver_t *sdriver)
{
sdriver->detach (sdriver, engine);
- engine->slave_drivers = jack_slist_remove(engine->slave_drivers, sdriver);
+ engine->slave_drivers = jack_slist_remove (engine->slave_drivers, sdriver);
- jack_driver_unload(sdriver);
+ jack_driver_unload (sdriver);
}
int
jack_drivers_start (jack_engine_t *engine)
{
JSList *node;
JSList *failed_drivers = NULL;
+
/* first start the slave drivers */
- for (node=engine->slave_drivers; node; node=jack_slist_next(node))
- {
+ for (node = engine->slave_drivers; node; node = jack_slist_next (node)) {
jack_driver_t *sdriver = node->data;
if (sdriver->start (sdriver)) {
- failed_drivers = jack_slist_append(failed_drivers, sdriver);
+ failed_drivers = jack_slist_append (failed_drivers, sdriver);
}
}
// Clean up drivers which failed to start.
- for (node=failed_drivers; node; node=jack_slist_next(node))
- {
+ for (node = failed_drivers; node; node = jack_slist_next (node)) {
jack_driver_t *sdriver = node->data;
- jack_error( "slave driver %s failed to start, removing it", sdriver->internal_client->control->name );
- jack_slave_driver_remove(engine, sdriver);
+ jack_error ( "slave driver %s failed to start, removing it", sdriver->internal_client->control->name );
+ jack_slave_driver_remove (engine, sdriver);
}
/* now the master driver is started */
- return engine->driver->start(engine->driver);
+ return engine->driver->start (engine->driver);
}
static int
@@ -2117,13 +2125,12 @@ jack_drivers_stop (jack_engine_t *engine)
{
JSList *node;
/* first stop the master driver */
- int retval = engine->driver->stop(engine->driver);
+ int retval = engine->driver->stop (engine->driver);
/* now the slave drivers are stopped */
- for (node=engine->slave_drivers; node; node=jack_slist_next(node))
- {
+ for (node = engine->slave_drivers; node; node = jack_slist_next (node)) {
jack_driver_t *sdriver = node->data;
- sdriver->stop( sdriver );
+ sdriver->stop ( sdriver );
}
return retval;
@@ -2133,30 +2140,30 @@ static int
jack_drivers_read (jack_engine_t *engine, jack_nframes_t nframes)
{
JSList *node;
+
/* first read the slave drivers */
- for (node=engine->slave_drivers; node; node=jack_slist_next(node))
- {
+ for (node = engine->slave_drivers; node; node = jack_slist_next (node)) {
jack_driver_t *sdriver = node->data;
sdriver->read (sdriver, nframes);
}
/* now the master driver is read */
- return engine->driver->read(engine->driver, nframes);
+ return engine->driver->read (engine->driver, nframes);
}
static int
jack_drivers_write (jack_engine_t *engine, jack_nframes_t nframes)
{
JSList *node;
+
/* first start the slave drivers */
- for (node=engine->slave_drivers; node; node=jack_slist_next(node))
- {
+ for (node = engine->slave_drivers; node; node = jack_slist_next (node)) {
jack_driver_t *sdriver = node->data;
sdriver->write (sdriver, nframes);
}
/* now the master driver is written */
- return engine->driver->write(engine->driver, nframes);
+ return engine->driver->write (engine->driver, nframes);
}
static int
jack_start_freewheeling (jack_engine_t* engine, jack_uuid_t client_id)
@@ -2175,7 +2182,7 @@ jack_start_freewheeling (jack_engine_t* engine, jack_uuid_t client_id)
/* stop driver before telling anyone about it so
there are no more process() calls being handled.
- */
+ */
if (jack_drivers_stop (engine)) {
jack_error ("could not stop driver for freewheeling");
@@ -2225,7 +2232,7 @@ jack_stop_freewheeling (jack_engine_t* engine, int engine_exiting)
/* tell the freewheel thread to stop, and wait for it
to exit.
- */
+ */
engine->stop_freewheeling = 1;
@@ -2263,25 +2270,25 @@ jack_check_client_status (jack_engine_t* engine)
/* we are already late, or something else went wrong,
so it can't hurt to check the existence of all
clients.
- */
+ */
for (node = engine->clients; node;
node = jack_slist_next (node)) {
jack_client_internal_t *client =
- (jack_client_internal_t *) node->data;
+ (jack_client_internal_t*)node->data;
if (client->control->type == ClientExternal) {
if (kill (client->control->pid, 0)) {
- VERBOSE(engine,
- "client %s has died/exited",
- client->control->name);
+ VERBOSE (engine,
+ "client %s has died/exited",
+ client->control->name);
client->error++;
err++;
}
- if(client->control->last_status != 0) {
- VERBOSE(engine,
- "client %s has nonzero process callback status (%d)\n",
- client->control->name, client->control->last_status);
+ if (client->control->last_status != 0) {
+ VERBOSE (engine,
+ "client %s has nonzero process callback status (%d)\n",
+ client->control->name, client->control->last_status);
client->error++;
err++;
}
@@ -2309,14 +2316,14 @@ jack_run_one_cycle (jack_engine_t *engine, jack_nframes_t nframes,
engine->spare_usecs &&
((WORK_SCALE * engine->spare_usecs) <= delayed_usecs)) {
- MESSAGE("delay of %.3f usecs exceeds estimated spare"
+ MESSAGE ("delay of %.3f usecs exceeds estimated spare"
" time of %.3f; restart ...\n",
delayed_usecs, WORK_SCALE * engine->spare_usecs);
if (++consecutive_excessive_delays > 10) {
jack_error ("too many consecutive interrupt delays "
"... engine pausing");
- return -1; /* will exit the thread loop */
+ return -1; /* will exit the thread loop */
}
jack_engine_delay (engine, delayed_usecs);
@@ -2351,7 +2358,7 @@ jack_run_one_cycle (jack_engine_t *engine, jack_nframes_t nframes,
return 0;
}
- if (engine->problems || (engine->timeout_count_threshold && (engine->timeout_count > (1 + engine->timeout_count_threshold*1000/engine->driver->period_usecs) ))) {
+ if (engine->problems || (engine->timeout_count_threshold && (engine->timeout_count > (1 + engine->timeout_count_threshold * 1000 / engine->driver->period_usecs) ))) {
VERBOSE (engine, "problem-driven null cycle problems=%d", engine->problems);
jack_unlock_problems (engine);
jack_unlock_graph (engine);
@@ -2367,13 +2374,13 @@ jack_run_one_cycle (jack_engine_t *engine, jack_nframes_t nframes,
jack_unlock_problems (engine);
if (!engine->freewheeling) {
- DEBUG("waiting for driver read\n");
+ DEBUG ("waiting for driver read\n");
if (jack_drivers_read (engine, nframes)) {
goto unlock;
}
}
- DEBUG("run process\n");
+ DEBUG ("run process\n");
if (jack_engine_process (engine, nframes) != 0) {
DEBUG ("engine process cycle failed");
@@ -2388,14 +2395,15 @@ jack_run_one_cycle (jack_engine_t *engine, jack_nframes_t nframes,
jack_engine_post_process (engine);
- if (delayed_usecs > engine->control->max_delayed_usecs)
+ if (delayed_usecs > engine->control->max_delayed_usecs) {
engine->control->max_delayed_usecs = delayed_usecs;
+ }
ret = 0;
- unlock:
+unlock:
jack_unlock_graph (engine);
- DEBUG("cycle finished, status = %d", ret);
+ DEBUG ("cycle finished, status = %d", ret);
return ret;
}
@@ -2422,7 +2430,7 @@ jack_run_cycle (jack_engine_t *engine, jack_nframes_t nframes,
{
jack_time_t now = engine->driver->last_wait_ust;
jack_time_t dus = 0;
- jack_time_t p_usecs = engine->driver->period_usecs ;
+ jack_time_t p_usecs = engine->driver->period_usecs;
jack_nframes_t b_size = engine->control->buffer_size;
jack_nframes_t left;
jack_frame_timer_t* timer = &engine->control->frame_timer;
@@ -2430,21 +2438,20 @@ jack_run_cycle (jack_engine_t *engine, jack_nframes_t nframes,
if (engine->verbose) {
if (nframes != b_size) {
VERBOSE (engine,
- "late driver wakeup: nframes to process = %"
- PRIu32 ".", nframes);
+ "late driver wakeup: nframes to process = %"
+ PRIu32 ".", nframes);
}
}
/* Run as many cycles as it takes to consume nframes */
- for (left = nframes; left >= b_size; left -= b_size)
- {
+ for (left = nframes; left >= b_size; left -= b_size) {
/* Change: the DLL code is now inside this loop which ensures
that more than one period is run if more than a buffer size
of frames is available. This is a very unlikely event, but
it is possible and now handled correctly.
FA 25/06/2014
- */
+ */
/* Change: 'first_wakeup' now means only the very first wakeup
after the engine was created. In that case frame time is not
modified, it stays at the initialised value.
@@ -2455,14 +2462,14 @@ jack_run_cycle (jack_engine_t *engine, jack_nframes_t nframes,
frame time for the start of each period will have a correct
idea of the number of frames that were skipped.
FA 25/06/2014
- */
+ */
/* Change: in contrast to previous versions, the DLL is *not*
run if any of the two conditions above is true, it is just
initialised correctly for the current period. Previously it
was initialised and then run, which meant that the requred
initialisation was rather counter-intiutive.
FA 25/06/2014
- */
+ */
/* Added initialisation of timer->period_usecs, required
due to the modified implementation of the DLL itself.
OTOH, this should maybe not be repeated after e.g.
@@ -2470,13 +2477,13 @@ jack_run_cycle (jack_engine_t *engine, jack_nframes_t nframes,
more accurate than the nominal one. But it doesn't really
harm either.
FA 13/02/2012
- */
+ */
/* Added initialisation of timer->filter_omega. This makes
the DLL bandwidth independent of the actual period time.
The bandwidth is now 1/8 Hz in all cases. The value of
timer->filter_omega is 2 * pi * BW * Tperiod.
FA 13/02/2012
- */
+ */
// maybe need a memory barrier here
timer->guard1++;
@@ -2494,27 +2501,25 @@ jack_run_cycle (jack_engine_t *engine, jack_nframes_t nframes,
// Initialiase the DLL.
timer->current_wakeup = now;
timer->next_wakeup = now + p_usecs;
- timer->period_usecs = (float) p_usecs;
+ timer->period_usecs = (float)p_usecs;
timer->filter_omega = timer->period_usecs * 7.854e-7f;
timer->initialized = 1;
// Reset both conditions.
engine->first_wakeup = 0;
timer->reset_pending = 0;
- }
- else
- {
+ } else {
// Normal cycle. This code was originally in
// jack_inc_frame_time() but only used here.
// Moving it here means that now all code
// related to timekeeping is close together
// and easy to understand.
- float delta = (float)((int64_t) now - (int64_t) timer->next_wakeup);
+ float delta = (float)((int64_t)now - (int64_t)timer->next_wakeup);
delta *= timer->filter_omega;
timer->current_wakeup = timer->next_wakeup;
timer->frames += b_size;
timer->period_usecs += timer->filter_omega * delta;
- timer->next_wakeup += (int64_t) floorf (timer->period_usecs + 1.41f * delta + 0.5f);
+ timer->next_wakeup += (int64_t)floorf (timer->period_usecs + 1.41f * delta + 0.5f);
}
// maybe need a memory barrier here
@@ -2534,14 +2539,15 @@ jack_engine_delete (jack_engine_t *engine)
{
int i;
- if (engine == NULL)
+ if (engine == NULL) {
return;
+ }
VERBOSE (engine, "starting server engine shutdown");
jack_stop_freewheeling (engine, 1);
- engine->control->engine_ok = 0; /* tell clients we're going away */
+ engine->control->engine_ok = 0; /* tell clients we're going away */
/* this will wake the server thread and cause it to exit */
@@ -2554,9 +2560,8 @@ jack_engine_delete (jack_engine_t *engine)
/* now really tell them we're going away */
- for (i = 0; i < engine->pfd_max; ++i) {
+ for (i = 0; i < engine->pfd_max; ++i)
shutdown (engine->pfd[i].fd, SHUT_RDWR);
- }
if (engine->driver) {
jack_driver_t* driver = engine->driver;
@@ -2590,9 +2595,9 @@ jack_engine_delete (jack_engine_t *engine)
VERBOSE (engine, "last xrun delay: %.3f usecs",
- engine->control->xrun_delayed_usecs);
+ engine->control->xrun_delayed_usecs);
VERBOSE (engine, "max delay reported by backend: %.3f usecs",
- engine->control->max_delayed_usecs);
+ engine->control->max_delayed_usecs);
/* free engine control shm segment */
engine->control = NULL;
@@ -2604,7 +2609,7 @@ jack_engine_delete (jack_engine_t *engine)
free (engine);
- jack_messagebuffer_exit();
+ jack_messagebuffer_exit ();
}
void
@@ -2616,9 +2621,9 @@ jack_port_clear_connections (jack_engine_t *engine,
for (node = port->connections; node; ) {
next = jack_slist_next (node);
jack_port_disconnect_internal (
- engine, ((jack_connection_internal_t *)
+ engine, ((jack_connection_internal_t*)
node->data)->source,
- ((jack_connection_internal_t *)
+ ((jack_connection_internal_t*)
node->data)->destination);
node = next;
}
@@ -2635,7 +2640,7 @@ jack_deliver_event_to_all (jack_engine_t *engine, jack_event_t *event)
jack_rdlock_graph (engine);
for (node = engine->clients; node; node = jack_slist_next (node)) {
jack_deliver_event (engine,
- (jack_client_internal_t *) node->data,
+ (jack_client_internal_t*)node->data,
event);
}
jack_unlock_graph (engine);
@@ -2644,11 +2649,12 @@ jack_deliver_event_to_all (jack_engine_t *engine, jack_event_t *event)
static void jack_do_get_client_by_uuid (jack_engine_t *engine, jack_request_t *req)
{
JSList *node;
+
req->status = -1;
for (node = engine->clients; node; node = jack_slist_next (node)) {
- jack_client_internal_t* client = (jack_client_internal_t*) node->data;
+ jack_client_internal_t* client = (jack_client_internal_t*)node->data;
if (jack_uuid_compare (client->control->uuid, req->x.client_id) == 0) {
- snprintf( req->x.port_info.name, sizeof(req->x.port_info.name), "%s", client->control->name );
+ snprintf ( req->x.port_info.name, sizeof(req->x.port_info.name), "%s", client->control->name );
req->status = 0;
return;
}
@@ -2658,6 +2664,7 @@ static void jack_do_get_client_by_uuid (jack_engine_t *engine, jack_request_t *r
static void jack_do_get_uuid_by_client_name (jack_engine_t *engine, jack_request_t *req)
{
JSList *node;
+
req->status = -1;
if (strcmp (req->x.name, "system") == 0) {
@@ -2670,7 +2677,7 @@ static void jack_do_get_uuid_by_client_name (jack_engine_t *engine, jack_request
}
for (node = engine->clients; node; node = jack_slist_next (node)) {
- jack_client_internal_t* client = (jack_client_internal_t*) node->data;
+ jack_client_internal_t* client = (jack_client_internal_t*)node->data;
if (strcmp (client->control->name, req->x.name) == 0) {
jack_uuid_copy (&req->x.client_id, client->control->uuid);
req->status = 0;
@@ -2683,22 +2690,23 @@ static void jack_do_reserve_name (jack_engine_t *engine, jack_request_t *req)
{
jack_reserved_name_t *reservation;
JSList *node;
+
// check is name is free...
for (node = engine->clients; node; node = jack_slist_next (node)) {
- jack_client_internal_t* client = (jack_client_internal_t*) node->data;
- if( !strcmp( (char *)client->control->name, req->x.reservename.name )) {
+ jack_client_internal_t* client = (jack_client_internal_t*)node->data;
+ if ( !strcmp ( (char*)client->control->name, req->x.reservename.name )) {
req->status = -1;
return;
}
}
- reservation = malloc (sizeof (jack_reserved_name_t));
+ reservation = malloc (sizeof(jack_reserved_name_t));
if (reservation == NULL) {
req->status = -1;
return;
}
- snprintf (reservation->name, sizeof (reservation->name), "%s", req->x.reservename.name);
+ snprintf (reservation->name, sizeof(reservation->name), "%s", req->x.reservename.name);
jack_uuid_copy (&reservation->uuid, req->x.reservename.uuid);
engine->reserved_client_names = jack_slist_append (engine->reserved_client_names, reservation);
@@ -2707,31 +2715,31 @@ static void jack_do_reserve_name (jack_engine_t *engine, jack_request_t *req)
static int jack_send_session_reply ( jack_engine_t *engine, jack_client_internal_t *client )
{
- if (write (engine->session_reply_fd, (const void *) &client->control->uuid, sizeof (client->control->uuid))
- < (ssize_t) sizeof (client->control->uuid)) {
+ if (write (engine->session_reply_fd, (const void*)&client->control->uuid, sizeof(client->control->uuid))
+ < (ssize_t)sizeof(client->control->uuid)) {
jack_error ("cannot write SessionNotify result "
"to client via fd = %d (%s)",
engine->session_reply_fd, strerror (errno));
return -1;
}
- if (write (engine->session_reply_fd, (const void *) client->control->name, sizeof (client->control->name))
- < (ssize_t) sizeof (client->control->name)) {
+ if (write (engine->session_reply_fd, (const void*)client->control->name, sizeof(client->control->name))
+ < (ssize_t)sizeof(client->control->name)) {
jack_error ("cannot write SessionNotify result "
"to client via fd = %d (%s)",
engine->session_reply_fd, strerror (errno));
return -1;
}
- if (write (engine->session_reply_fd, (const void *) client->control->session_command,
- sizeof (client->control->session_command))
- < (ssize_t) sizeof (client->control->session_command)) {
+ if (write (engine->session_reply_fd, (const void*)client->control->session_command,
+ sizeof(client->control->session_command))
+ < (ssize_t)sizeof(client->control->session_command)) {
jack_error ("cannot write SessionNotify result "
"to client via fd = %d (%s)",
engine->session_reply_fd, strerror (errno));
return -1;
}
- if (write (engine->session_reply_fd, (const void *) ( & client->control->session_flags ),
- sizeof (client->control->session_flags))
- < (ssize_t) sizeof (client->control->session_flags)) {
+ if (write (engine->session_reply_fd, (const void*)( &client->control->session_flags ),
+ sizeof(client->control->session_flags))
+ < (ssize_t)sizeof(client->control->session_flags)) {
jack_error ("cannot write SessionNotify result "
"to client via fd = %d (%s)",
engine->session_reply_fd, strerror (errno));
@@ -2774,25 +2782,26 @@ jack_do_session_notify (jack_engine_t *engine, jack_request_t *req, int reply_fd
}
for (node = engine->clients; node; node = jack_slist_next (node)) {
- jack_client_internal_t* client = (jack_client_internal_t*) node->data;
+ jack_client_internal_t* client = (jack_client_internal_t*)node->data;
if (client->control->session_cbset) {
// in case we only want to send to a special client.
// uuid assign is still complete. not sure if thats necessary.
- if( (req->x.session.target[0] != 0) && strcmp(req->x.session.target, (char *)client->control->name) )
+ if ( (req->x.session.target[0] != 0) && strcmp (req->x.session.target, (char*)client->control->name) ) {
continue;
+ }
/* the caller of jack_session_notify() is required to have created the session dir
- */
+ */
- if (req->x.session.path[strlen(req->x.session.path)-1] == '/') {
- snprintf (event.x.name, sizeof (event.x.name), "%s%s/", req->x.session.path, client->control->name );
+ if (req->x.session.path[strlen (req->x.session.path) - 1] == '/') {
+ snprintf (event.x.name, sizeof(event.x.name), "%s%s/", req->x.session.path, client->control->name );
} else {
- snprintf (event.x.name, sizeof (event.x.name), "%s/%s/", req->x.session.path, client->control->name );
+ snprintf (event.x.name, sizeof(event.x.name), "%s/%s/", req->x.session.path, client->control->name );
}
if (mkdir (event.x.name, 0777) != 0) {
jack_error ("cannot create session directory (%s) for client %s: %s",
- event.x.name, client->control->name, strerror (errno));
+ event.x.name, client->control->name, strerror (errno));
break;
}
@@ -2803,21 +2812,23 @@ jack_do_session_notify (jack_engine_t *engine, jack_request_t *req, int reply_fd
client->session_reply_pending = TRUE;
} else if (reply == 2) {
// immediate reply
- if (jack_send_session_reply (engine, client))
+ if (jack_send_session_reply (engine, client)) {
goto error_out;
+ }
}
}
}
- if (engine->session_pending_replies != 0)
+ if (engine->session_pending_replies != 0) {
return 0;
+ }
send_final:
- if (write (reply_fd, &finalizer, sizeof (finalizer))
- < (ssize_t) sizeof (finalizer)) {
+ if (write (reply_fd, &finalizer, sizeof(finalizer))
+ < (ssize_t)sizeof(finalizer)) {
jack_error ("cannot write SessionNotify result "
- "to client via fd = %d (%s)",
- reply_fd, strerror (errno));
+ "to client via fd = %d (%s)",
+ reply_fd, strerror (errno));
goto error_out;
}
@@ -2834,8 +2845,9 @@ jack_do_has_session_cb (jack_engine_t *engine, jack_request_t *req)
int retval = -1;
client = jack_client_by_name (engine, req->x.name);
- if (client == NULL)
+ if (client == NULL) {
goto out;
+ }
retval = client->control->session_cbset ? 1 : 0;
out:
@@ -2871,11 +2883,11 @@ static void jack_do_session_reply (jack_engine_t *engine, jack_request_t *req )
}
if (engine->session_pending_replies == 0) {
- if (write (engine->session_reply_fd, &finalizer, sizeof (finalizer))
- < (ssize_t) sizeof (finalizer)) {
+ if (write (engine->session_reply_fd, &finalizer, sizeof(finalizer))
+ < (ssize_t)sizeof(finalizer)) {
jack_error ("cannot write SessionNotify result "
- "to client via fd = %d (%s)",
- engine->session_reply_fd, strerror (errno));
+ "to client via fd = %d (%s)",
+ engine->session_reply_fd, strerror (errno));
req->status = -1;
}
engine->session_reply_fd = -1;
@@ -2899,7 +2911,7 @@ jack_notify_all_port_interested_clients (jack_engine_t *engine, jack_uuid_t src,
jack_client_internal_t* dst_client = jack_client_internal_by_id (engine, dst);
for (node = engine->clients; node; node = jack_slist_next (node)) {
- jack_client_internal_t* client = (jack_client_internal_t*) node->data;
+ jack_client_internal_t* client = (jack_client_internal_t*)node->data;
if (src_client != client && dst_client != client && client->control->port_connect_cbset != FALSE) {
/* one of the ports belong to this client or it has a port connect callback */
@@ -2913,7 +2925,7 @@ jack_deliver_event (jack_engine_t *engine, jack_client_internal_t *client,
const jack_event_t *event, ...)
{
va_list ap;
- char status=0;
+ char status = 0;
char* key = 0;
size_t keylen = 0;
@@ -2925,7 +2937,7 @@ jack_deliver_event (jack_engine_t *engine, jack_client_internal_t *client,
/* we are not RT-constrained here, so use kill(2) to beef up
our check on a client's continued well-being
- */
+ */
if (client->control->dead || client->error >= JACK_ERROR_WITH_SOCKETS
|| (client->control->type == ClientExternal && kill (client->control->pid, 0))) {
@@ -2978,7 +2990,7 @@ jack_deliver_event (jack_engine_t *engine, jack_client_internal_t *client,
if (client->control->srate_cbset) {
client->private_client->srate
(event->x.n,
- client->private_client->srate_arg);
+ client->private_client->srate_arg);
}
break;
@@ -3019,120 +3031,120 @@ jack_deliver_event (jack_engine_t *engine, jack_client_internal_t *client,
/* there's a thread waiting for events, so
* it's worth telling the client */
- DEBUG ("engine writing on event fd");
+ DEBUG ("engine writing on event fd");
- if (write (client->event_fd, event, sizeof (*event)) != sizeof (*event)) {
- jack_error ("cannot send event to client [%s] (%s)",
- client->control->name,
- strerror (errno));
- client->error += JACK_ERROR_WITH_SOCKETS;
- jack_engine_signal_problems (engine);
- }
+ if (write (client->event_fd, event, sizeof(*event)) != sizeof(*event)) {
+ jack_error ("cannot send event to client [%s] (%s)",
+ client->control->name,
+ strerror (errno));
+ client->error += JACK_ERROR_WITH_SOCKETS;
+ jack_engine_signal_problems (engine);
+ }
- /* for property changes, deliver the extra data representing
- the variable length "key" that has changed in some way.
- */
-
- if (event->type == PropertyChange) {
- if (keylen) {
- if (write (client->event_fd, key, keylen) != keylen) {
- jack_error ("cannot send property change key to client [%s] (%s)",
- client->control->name,
- strerror (errno));
- client->error += JACK_ERROR_WITH_SOCKETS;
- jack_engine_signal_problems (engine);
+ /* for property changes, deliver the extra data representing
+ the variable length "key" that has changed in some way.
+ */
+
+ if (event->type == PropertyChange) {
+ if (keylen) {
+ if (write (client->event_fd, key, keylen) != keylen) {
+ jack_error ("cannot send property change key to client [%s] (%s)",
+ client->control->name,
+ strerror (errno));
+ client->error += JACK_ERROR_WITH_SOCKETS;
+ jack_engine_signal_problems (engine);
+ }
}
}
- }
- if (client->error) {
- status = -1;
- } else {
- // then we check whether there really is an error.... :)
-
- struct pollfd pfd[1];
- pfd[0].fd = client->event_fd;
- pfd[0].events = POLLERR|POLLIN|POLLHUP|POLLNVAL;
- jack_time_t poll_timeout = JACKD_CLIENT_EVENT_TIMEOUT;
- int poll_ret;
- jack_time_t then = jack_get_microseconds ();
- jack_time_t now;
-
- /* if we're not running realtime and there is a client timeout set
- that exceeds the default client event timeout (which is not
- bound by RT limits, then use the larger timeout.
- */
-
- if (!engine->control->real_time && (engine->client_timeout_msecs > poll_timeout)) {
- poll_timeout = engine->client_timeout_msecs;
- }
+ if (client->error) {
+ status = -1;
+ } else {
+ // then we check whether there really is an error.... :)
+
+ struct pollfd pfd[1];
+ pfd[0].fd = client->event_fd;
+ pfd[0].events = POLLERR | POLLIN | POLLHUP | POLLNVAL;
+ jack_time_t poll_timeout = JACKD_CLIENT_EVENT_TIMEOUT;
+ int poll_ret;
+ jack_time_t then = jack_get_microseconds ();
+ jack_time_t now;
+
+ /* if we're not running realtime and there is a client timeout set
+ that exceeds the default client event timeout (which is not
+ bound by RT limits, then use the larger timeout.
+ */
+
+ if (!engine->control->real_time && (engine->client_timeout_msecs > poll_timeout)) {
+ poll_timeout = engine->client_timeout_msecs;
+ }
#ifdef __linux
- again:
+again:
#endif
- VERBOSE(engine,"client event poll on %d for %s starts at %lld",
- client->event_fd, client->control->name, then);
- if ((poll_ret = poll (pfd, 1, poll_timeout)) < 0) {
- DEBUG ("client event poll not ok! (-1) poll returned an error");
- jack_error ("poll on subgraph processing failed (%s)", strerror (errno));
- status = -1;
- } else {
+ VERBOSE (engine, "client event poll on %d for %s starts at %lld",
+ client->event_fd, client->control->name, then);
+ if ((poll_ret = poll (pfd, 1, poll_timeout)) < 0) {
+ DEBUG ("client event poll not ok! (-1) poll returned an error");
+ jack_error ("poll on subgraph processing failed (%s)", strerror (errno));
+ status = -1;
+ } else {
- DEBUG ("\n\n\n\n\n back from client event poll, revents = 0x%x\n\n\n", pfd[0].revents);
- now = jack_get_microseconds();
- VERBOSE(engine,"back from client event poll after %lld usecs", now - then);
+ DEBUG ("\n\n\n\n\n back from client event poll, revents = 0x%x\n\n\n", pfd[0].revents);
+ now = jack_get_microseconds ();
+ VERBOSE (engine, "back from client event poll after %lld usecs", now - then);
- if (pfd[0].revents & ~POLLIN) {
+ if (pfd[0].revents & ~POLLIN) {
- /* some kind of OOB socket event */
+ /* some kind of OOB socket event */
- DEBUG ("client event poll not ok! (-2), revents = %d\n", pfd[0].revents);
- jack_error ("subgraph starting at %s lost client", client->control->name);
- status = -2;
+ DEBUG ("client event poll not ok! (-2), revents = %d\n", pfd[0].revents);
+ jack_error ("subgraph starting at %s lost client", client->control->name);
+ status = -2;
- } else if (pfd[0].revents & POLLIN) {
+ } else if (pfd[0].revents & POLLIN) {
- /* client responded normally */
+ /* client responded normally */
- DEBUG ("client event poll ok!");
- status = 0;
+ DEBUG ("client event poll ok!");
+ status = 0;
- } else if (poll_ret == 0) {
+ } else if (poll_ret == 0) {
- /* no events, no errors, we woke up because poll()
- decided that time was up ...
- */
+ /* no events, no errors, we woke up because poll()
+ decided that time was up ...
+ */
#ifdef __linux
- if (linux_poll_bug_encountered (engine, then, &poll_timeout)) {
- goto again;
- }
-
- if (poll_timeout < 200) {
- VERBOSE (engine, "FALSE WAKEUP skipped, remaining = %lld usec", poll_timeout);
- status = 0;
- } else {
+ if (linux_poll_bug_encountered (engine, then, &poll_timeout)) {
+ goto again;
+ }
+
+ if (poll_timeout < 200) {
+ VERBOSE (engine, "FALSE WAKEUP skipped, remaining = %lld usec", poll_timeout);
+ status = 0;
+ } else {
#endif
DEBUG ("client event poll not ok! (1 = poll timed out, revents = 0x%04x, poll_ret = %d)", pfd[0].revents, poll_ret);
- VERBOSE (engine,"client %s did not respond to event type %d in time"
- "(fd=%d, revents = 0x%04x, timeout was %lld)",
- client->control->name, event->type,
- client->event_fd,
- pfd[0].revents,
- poll_timeout);
+ VERBOSE (engine, "client %s did not respond to event type %d in time"
+ "(fd=%d, revents = 0x%04x, timeout was %lld)",
+ client->control->name, event->type,
+ client->event_fd,
+ pfd[0].revents,
+ poll_timeout);
status = -2;
#ifdef __linux
}
#endif
- }
+ }
}
}
if (status == 0) {
- if (read (client->event_fd, &status, sizeof (status)) != sizeof (status)) {
+ if (read (client->event_fd, &status, sizeof(status)) != sizeof(status)) {
jack_error ("cannot read event response from client [%s] (%s)",
- client->control->name,
- strerror (errno));
+ client->control->name,
+ strerror (errno));
status = -1;
}
@@ -3140,23 +3152,23 @@ jack_deliver_event (jack_engine_t *engine, jack_client_internal_t *client,
switch (status) {
case -1:
jack_error ("internal poll failure reading response from client %s to a %s event",
- client->control->name,
- jack_event_type_name (event->type));
+ client->control->name,
+ jack_event_type_name (event->type));
break;
case -2:
jack_error ("timeout waiting for client %s to handle a %s event",
- client->control->name,
- jack_event_type_name (event->type));
+ client->control->name,
+ jack_event_type_name (event->type));
break;
default:
jack_error ("bad status (%d) from client %s while handling a %s event",
- (int) status,
- client->control->name,
- jack_event_type_name (event->type));
+ (int)status,
+ client->control->name,
+ jack_event_type_name (event->type));
}
}
- if (status<0) {
+ if (status < 0) {
client->error += JACK_ERROR_WITH_SOCKETS;
jack_engine_signal_problems (engine);
}
@@ -3177,19 +3189,19 @@ jack_rechain_graph (jack_engine_t *engine)
jack_event_t event;
int upstream_is_jackd;
- VALGRIND_MEMSET(&event, 0, sizeof (event));
+ VALGRIND_MEMSET (&event, 0, sizeof(event));
jack_clear_fifos (engine);
subgraph_client = 0;
- VERBOSE(engine, "++ jack_rechain_graph():");
+ VERBOSE (engine, "++ jack_rechain_graph():");
event.type = GraphReordered;
for (n = 0, node = engine->clients, next = NULL; node; node = next) {
- jack_client_internal_t* client = (jack_client_internal_t *) node->data;
+ jack_client_internal_t* client = (jack_client_internal_t*)node->data;
next = jack_slist_next (node);
@@ -3197,8 +3209,8 @@ jack_rechain_graph (jack_engine_t *engine)
continue;
}
- VERBOSE(engine, "+++ client is now %s active ? %d",
- client->control->name, client->control->active);
+ VERBOSE (engine, "+++ client is now %s active ? %d",
+ client->control->name, client->control->active);
if (client->control->active) {
@@ -3210,13 +3222,14 @@ jack_rechain_graph (jack_engine_t *engine)
break;
}
next = jack_slist_next (next);
- };
+ }
+ ;
if (next == NULL) {
next_client = NULL;
} else {
- next_client = (jack_client_internal_t *)
- next->data;
+ next_client = (jack_client_internal_t*)
+ next->data;
}
client->execution_order = n;
@@ -3260,7 +3273,7 @@ jack_rechain_graph (jack_engine_t *engine)
if (subgraph_client == NULL) {
- /* start a new subgraph. the
+ /* start a new subgraph. the
* engine will start the chain
* by writing to the nth
* FIFO.
@@ -3280,12 +3293,11 @@ jack_rechain_graph (jack_engine_t *engine)
/* this external client after
this will have jackd as its
upstream connection.
- */
+ */
upstream_is_jackd = 1;
- }
- else {
+ } else {
VERBOSE (engine, "client %s: in"
" subgraph after %s, "
"execution_order="
@@ -3299,7 +3311,7 @@ jack_rechain_graph (jack_engine_t *engine)
this will have another
client as its upstream
connection.
- */
+ */
upstream_is_jackd = 0;
}
@@ -3307,7 +3319,7 @@ jack_rechain_graph (jack_engine_t *engine)
/* make sure fifo for 'n + 1' exists
* before issuing client reorder
*/
- (void) jack_get_fifo_fd(
+ (void)jack_get_fifo_fd (
engine, client->execution_order + 1);
event.x.n = client->execution_order;
event.y.n = upstream_is_jackd;
@@ -3344,9 +3356,8 @@ jack_get_port_total_latency (jack_engine_t *engine,
char prefix[32];
int i;
- for (i = 0; i < hop_count; ++i) {
+ for (i = 0; i < hop_count; ++i)
prefix[i] = '\t';
- }
prefix[i] = '\0';
#endif
@@ -3357,7 +3368,7 @@ jack_get_port_total_latency (jack_engine_t *engine,
/* we don't prevent cyclic graphs, so we have to do something
to bottom out in the event that they are created.
- */
+ */
if (hop_count > 8) {
return latency;
@@ -3372,7 +3383,7 @@ jack_get_port_total_latency (jack_engine_t *engine,
jack_nframes_t this_latency;
jack_connection_internal_t *connection;
- connection = (jack_connection_internal_t *) node->data;
+ connection = (jack_connection_internal_t*)node->data;
if ((toward_port &&
@@ -3382,9 +3393,9 @@ jack_get_port_total_latency (jack_engine_t *engine,
#ifdef DEBUG_TOTAL_LATENCY_COMPUTATION
jack_info ("%s\tskip connection %s->%s",
- prefix,
- connection->source->shared->name,
- connection->destination->shared->name);
+ prefix,
+ connection->source->shared->name,
+ connection->destination->shared->name);
#endif
continue;
@@ -3392,20 +3403,20 @@ jack_get_port_total_latency (jack_engine_t *engine,
#ifdef DEBUG_TOTAL_LATENCY_COMPUTATION
jack_info ("%s\tconnection %s->%s ... ",
- prefix,
- connection->source->shared->name,
- connection->destination->shared->name);
+ prefix,
+ connection->source->shared->name,
+ connection->destination->shared->name);
#endif
/* if we're a destination in the connection, recurse
on the source to get its total latency
- */
+ */
if (connection->destination == port) {
if (connection->source->shared->flags
& JackPortIsTerminal) {
this_latency = connection->source->
- shared->latency;
+ shared->latency;
} else {
this_latency =
jack_get_port_total_latency (
@@ -3421,7 +3432,7 @@ jack_get_port_total_latency (jack_engine_t *engine,
if (connection->destination->shared->flags
& JackPortIsTerminal) {
this_latency = connection->destination->
- shared->latency;
+ shared->latency;
} else {
this_latency =
jack_get_port_total_latency (
@@ -3460,23 +3471,23 @@ jack_compute_all_port_total_latencies (jack_engine_t *engine)
{
jack_port_shared_t *shared = engine->control->ports;
unsigned int i;
- int toward_port;
+ int toward_port;
for (i = 0; i < engine->control->port_max; i++) {
if (shared[i].in_use) {
- if (shared[i].flags & JackPortIsOutput) {
- toward_port = FALSE;
- } else {
- toward_port = TRUE;
- }
-
- shared[i].total_latency =
- jack_get_port_total_latency (
- engine, &engine->internal_ports[i],
- 0, toward_port);
- }
- }
+ if (shared[i].flags & JackPortIsOutput) {
+ toward_port = FALSE;
+ } else {
+ toward_port = TRUE;
+ }
+
+ shared[i].total_latency =
+ jack_get_port_total_latency (
+ engine, &engine->internal_ports[i],
+ 0, toward_port);
+ }
+ }
}
static void
@@ -3486,7 +3497,7 @@ jack_compute_new_latency (jack_engine_t *engine)
JSList *reverse_list = NULL;
jack_event_t event;
- VALGRIND_MEMSET (&event, 0, sizeof (event));
+ VALGRIND_MEMSET (&event, 0, sizeof(event));
event.type = LatencyCallback;
event.x.n = 0;
@@ -3495,9 +3506,9 @@ jack_compute_new_latency (jack_engine_t *engine)
* capture latency callback.
* also builds up list in reverse graph order.
*/
- for (node = engine->clients; node; node = jack_slist_next(node)) {
+ for (node = engine->clients; node; node = jack_slist_next (node)) {
- jack_client_internal_t* client = (jack_client_internal_t *) node->data;
+ jack_client_internal_t* client = (jack_client_internal_t*)node->data;
reverse_list = jack_slist_prepend (reverse_list, client);
jack_deliver_event (engine, client, &event);
}
@@ -3509,8 +3520,8 @@ jack_compute_new_latency (jack_engine_t *engine)
/* now issue playback latency callbacks in reverse graphorder
*/
event.x.n = 1;
- for (node = reverse_list; node; node = jack_slist_next(node)) {
- jack_client_internal_t* client = (jack_client_internal_t *) node->data;
+ for (node = reverse_list; node; node = jack_slist_next (node)) {
+ jack_client_internal_t* client = (jack_client_internal_t*)node->data;
jack_deliver_event (engine, client, &event);
}
@@ -3556,7 +3567,7 @@ jack_sort_graph (jack_engine_t *engine)
VERBOSE (engine, "++ jack_sort_graph");
engine->clients = jack_slist_sort (engine->clients,
- (JCompareFunc) jack_client_sort);
+ (JCompareFunc)jack_client_sort);
jack_compute_all_port_total_latencies (engine);
jack_compute_new_latency (engine);
jack_rechain_graph (engine);
@@ -3597,7 +3608,7 @@ jack_client_feeds_transitive (jack_client_internal_t *source,
for (node = source->sortfeeds; node; node = jack_slist_next (node)) {
- med = (jack_client_internal_t *) node->data;
+ med = (jack_client_internal_t*)node->data;
if (jack_client_feeds_transitive (med, dest)) {
return 1;
@@ -3627,7 +3638,7 @@ jack_check_acyclic (jack_engine_t *engine)
for (srcnode = engine->clients; srcnode;
srcnode = jack_slist_next (srcnode)) {
- src = (jack_client_internal_t *) srcnode->data;
+ src = (jack_client_internal_t*)srcnode->data;
src->tfedcount = src->fedcount;
unsortedclients++;
}
@@ -3640,9 +3651,9 @@ jack_check_acyclic (jack_engine_t *engine)
stuck = TRUE;
for (srcnode = engine->clients; srcnode;
- srcnode = jack_slist_next (srcnode)) {
+ srcnode = jack_slist_next (srcnode)) {
- src = (jack_client_internal_t *) srcnode->data;
+ src = (jack_client_internal_t*)srcnode->data;
if (!src->tfedcount) {
@@ -3653,8 +3664,8 @@ jack_check_acyclic (jack_engine_t *engine)
for (dstnode = src->truefeeds; dstnode;
dstnode = jack_slist_next (dstnode)) {
- dst = (jack_client_internal_t *)
- dstnode->data;
+ dst = (jack_client_internal_t*)
+ dstnode->data;
dst->tfedcount--;
}
}
@@ -3672,39 +3683,38 @@ jack_check_acyclic (jack_engine_t *engine)
for (srcnode = engine->clients; srcnode;
srcnode = jack_slist_next (srcnode)) {
- src = (jack_client_internal_t *) srcnode->data;
+ src = (jack_client_internal_t*)srcnode->data;
for (portnode = src->ports; portnode;
portnode = jack_slist_next (portnode)) {
- port = (jack_port_internal_t *) portnode->data;
+ port = (jack_port_internal_t*)portnode->data;
for (connnode = port->connections; connnode;
connnode = jack_slist_next (connnode)) {
conn = (jack_connection_internal_t*)
- connnode->data;
-
- if (conn->dir == -1 )
+ connnode->data;
- /*&&
- conn->srcclient == src) */{
+ if (conn->dir == -1 ) {
+ /*&&
+ conn->srcclient == src) */
VERBOSE (engine,
- "reversing connection from "
- "%s to %s",
- conn->srcclient->control->name,
- conn->dstclient->control->name);
+ "reversing connection from "
+ "%s to %s",
+ conn->srcclient->control->name,
+ conn->dstclient->control->name);
conn->dir = 1;
conn->dstclient->sortfeeds =
- jack_slist_remove
- (conn->dstclient->sortfeeds,
- conn->srcclient);
+ jack_slist_remove
+ (conn->dstclient->sortfeeds,
+ conn->srcclient);
conn->srcclient->sortfeeds =
- jack_slist_prepend
- (conn->srcclient->sortfeeds,
- conn->dstclient );
+ jack_slist_prepend
+ (conn->srcclient->sortfeeds,
+ conn->dstclient );
}
}
}
@@ -3716,7 +3726,7 @@ jack_check_acyclic (jack_engine_t *engine)
/**
* Dumps current engine configuration.
*/
-void jack_dump_configuration(jack_engine_t *engine, int take_lock)
+void jack_dump_configuration (jack_engine_t *engine, int take_lock)
{
JSList *clientnode, *portnode, *connectionnode;
jack_client_internal_t *client;
@@ -3733,39 +3743,39 @@ void jack_dump_configuration(jack_engine_t *engine, int take_lock)
for (n = 0, clientnode = engine->clients; clientnode;
clientnode = jack_slist_next (clientnode)) {
- client = (jack_client_internal_t *) clientnode->data;
+ client = (jack_client_internal_t*)clientnode->data;
ctl = client->control;
jack_info ("client #%d: %s (type: %d, process? %s, thread ? %s"
- " start=%d wait=%d",
- ++n,
- ctl->name,
- ctl->type,
- ctl->process_cbset ? "yes" : "no",
- ctl->thread_cb_cbset ? "yes" : "no",
- client->subgraph_start_fd,
- client->subgraph_wait_fd);
-
- for(m = 0, portnode = client->ports; portnode;
- portnode = jack_slist_next (portnode)) {
- port = (jack_port_internal_t *) portnode->data;
-
- jack_info("\t port #%d: %s", ++m,
- port->shared->name);
-
- for(o = 0, connectionnode = port->connections;
- connectionnode;
- connectionnode = jack_slist_next (connectionnode)) {
- connection = (jack_connection_internal_t *)
- connectionnode->data;
-
- jack_info("\t\t connection #%d: %s %s",
- ++o,
- (port->shared->flags
- & JackPortIsInput)? "<-": "->",
- (port->shared->flags & JackPortIsInput)?
- connection->source->shared->name:
- connection->destination->shared->name);
+ " start=%d wait=%d",
+ ++n,
+ ctl->name,
+ ctl->type,
+ ctl->process_cbset ? "yes" : "no",
+ ctl->thread_cb_cbset ? "yes" : "no",
+ client->subgraph_start_fd,
+ client->subgraph_wait_fd);
+
+ for (m = 0, portnode = client->ports; portnode;
+ portnode = jack_slist_next (portnode)) {
+ port = (jack_port_internal_t*)portnode->data;
+
+ jack_info ("\t port #%d: %s", ++m,
+ port->shared->name);
+
+ for (o = 0, connectionnode = port->connections;
+ connectionnode;
+ connectionnode = jack_slist_next (connectionnode)) {
+ connection = (jack_connection_internal_t*)
+ connectionnode->data;
+
+ jack_info ("\t\t connection #%d: %s %s",
+ ++o,
+ (port->shared->flags
+ & JackPortIsInput) ? "<-" : "->",
+ (port->shared->flags & JackPortIsInput) ?
+ connection->source->shared->name :
+ connection->destination->shared->name);
}
}
}
@@ -3775,13 +3785,13 @@ void jack_dump_configuration(jack_engine_t *engine, int take_lock)
}
- jack_info("engine.c: <-- dump ends -->");
+ jack_info ("engine.c: <-- dump ends -->");
}
static int
jack_port_do_connect (jack_engine_t *engine,
- const char *source_port,
- const char *destination_port)
+ const char *source_port,
+ const char *destination_port)
{
jack_connection_internal_t *connection;
jack_port_internal_t *srcport, *dstport;
@@ -3823,7 +3833,7 @@ jack_port_do_connect (jack_engine_t *engine,
}
if ((srcclient = jack_client_internal_by_id (engine,
- srcport->shared->client_id))
+ srcport->shared->client_id))
== 0) {
jack_error ("unknown client set as owner of port - "
"cannot connect");
@@ -3837,7 +3847,7 @@ jack_port_do_connect (jack_engine_t *engine,
}
if ((dstclient = jack_client_internal_by_id (engine,
- dstport->shared->client_id))
+ dstport->shared->client_id))
== 0) {
jack_error ("unknown client set as owner of port - cannot "
"connect");
@@ -3851,14 +3861,14 @@ jack_port_do_connect (jack_engine_t *engine,
}
for (it = srcport->connections; it; it = it->next) {
- if (((jack_connection_internal_t *)it->data)->destination
+ if (((jack_connection_internal_t*)it->data)->destination
== dstport) {
return EEXIST;
}
}
- connection = (jack_connection_internal_t *)
- malloc (sizeof (jack_connection_internal_t));
+ connection = (jack_connection_internal_t*)
+ malloc (sizeof(jack_connection_internal_t));
connection->source = srcport;
connection->destination = dstport;
@@ -3880,8 +3890,7 @@ jack_port_do_connect (jack_engine_t *engine,
return -1;
} else {
- if (dstclient->control->type == ClientDriver)
- {
+ if (dstclient->control->type == ClientDriver) {
/* Ignore output connections to drivers for purposes
of sorting. Drivers are executed first in the sort
order anyway, and we don't want to treat graphs
@@ -3895,11 +3904,10 @@ jack_port_do_connect (jack_engine_t *engine,
connection->dir = 1;
- }
- else if (srcclient != dstclient) {
+ } else if (srcclient != dstclient) {
srcclient->truefeeds = jack_slist_prepend
- (srcclient->truefeeds, dstclient);
+ (srcclient->truefeeds, dstclient);
dstclient->fedcount++;
@@ -3917,7 +3925,7 @@ jack_port_do_connect (jack_engine_t *engine,
dstport->shared->name);
dstclient->sortfeeds = jack_slist_prepend
- (dstclient->sortfeeds, srcclient);
+ (dstclient->sortfeeds, srcclient);
connection->dir = -1;
engine->feedbackcount++;
@@ -3935,13 +3943,11 @@ jack_port_do_connect (jack_engine_t *engine,
dstport->shared->name);
srcclient->sortfeeds = jack_slist_prepend
- (srcclient->sortfeeds, dstclient);
+ (srcclient->sortfeeds, dstclient);
connection->dir = 1;
}
- }
- else
- {
+ } else {
/* this is a connection to self */
VERBOSE (engine,
@@ -3996,7 +4002,7 @@ jack_port_disconnect_internal (jack_engine_t *engine,
for (node = srcport->connections; node;
node = jack_slist_next (node)) {
- connect = (jack_connection_internal_t *) node->data;
+ connect = (jack_connection_internal_t*)node->data;
if (connect->source == srcport &&
connect->destination == dstport) {
@@ -4022,7 +4028,7 @@ jack_port_disconnect_internal (jack_engine_t *engine,
srcport. this isn't ideal for all
situations, but it works better for most of
them.
- */
+ */
if (srcport->connections == NULL) {
srcport->shared->monitor_requests = 0;
}
@@ -4044,13 +4050,13 @@ jack_port_disconnect_internal (jack_engine_t *engine,
jack_client_internal_t *dst;
src = jack_client_internal_by_id
- (engine, srcport->shared->client_id);
+ (engine, srcport->shared->client_id);
dst = jack_client_internal_by_id
- (engine, dstport->shared->client_id);
+ (engine, dstport->shared->client_id);
src->truefeeds = jack_slist_remove
- (src->truefeeds, dst);
+ (src->truefeeds, dst);
dst->fedcount--;
@@ -4058,12 +4064,12 @@ jack_port_disconnect_internal (jack_engine_t *engine,
/* normal connection: remove dest from
source's sortfeeds list */
src->sortfeeds = jack_slist_remove
- (src->sortfeeds, dst);
+ (src->sortfeeds, dst);
} else {
/* feedback connection: remove source
from dest's sortfeeds list */
dst->sortfeeds = jack_slist_remove
- (dst->sortfeeds, src);
+ (dst->sortfeeds, src);
engine->feedbackcount--;
VERBOSE (engine,
"feedback count down to %d",
@@ -4142,10 +4148,10 @@ int
jack_get_fifo_fd (jack_engine_t *engine, unsigned int which_fifo)
{
/* caller must hold client_lock */
- char path[PATH_MAX+1];
+ char path[PATH_MAX + 1];
struct stat statbuf;
- snprintf (path, sizeof (path), "%s-%d", engine->fifo_prefix,
+ snprintf (path, sizeof(path), "%s-%d", engine->fifo_prefix,
which_fifo);
DEBUG ("%s", path);
@@ -4153,7 +4159,7 @@ jack_get_fifo_fd (jack_engine_t *engine, unsigned int which_fifo)
if (stat (path, &statbuf)) {
if (errno == ENOENT) {
- if (mkfifo(path, 0666) < 0){
+ if (mkfifo (path, 0666) < 0) {
jack_error ("cannot create inter-client FIFO"
" [%s] (%s)\n", path,
strerror (errno));
@@ -4165,7 +4171,7 @@ jack_get_fifo_fd (jack_engine_t *engine, unsigned int which_fifo)
return -1;
}
} else {
- if (!S_ISFIFO(statbuf.st_mode)) {
+ if (!S_ISFIFO (statbuf.st_mode)) {
jack_error ("FIFO %d (%s) already exists, but is not"
" a FIFO!\n", which_fifo, path);
return -1;
@@ -4175,18 +4181,17 @@ jack_get_fifo_fd (jack_engine_t *engine, unsigned int which_fifo)
if (which_fifo >= engine->fifo_size) {
unsigned int i;
- engine->fifo = (int *)
- realloc (engine->fifo,
- sizeof (int) * (engine->fifo_size + 16));
- for (i = engine->fifo_size; i < engine->fifo_size + 16; i++) {
+ engine->fifo = (int*)
+ realloc (engine->fifo,
+ sizeof(int) * (engine->fifo_size + 16));
+ for (i = engine->fifo_size; i < engine->fifo_size + 16; i++)
engine->fifo[i] = -1;
- }
engine->fifo_size += 16;
}
if (engine->fifo[which_fifo] < 0) {
if ((engine->fifo[which_fifo] =
- open (path, O_RDWR|O_CREAT|O_NONBLOCK, 0666)) < 0) {
+ open (path, O_RDWR | O_CREAT | O_NONBLOCK, 0666)) < 0) {
jack_error ("cannot open fifo [%s] (%s)", path,
strerror (errno));
return -1;
@@ -4209,10 +4214,10 @@ jack_clear_fifos (jack_engine_t *engine)
/* this just drains the existing FIFO's of any data left in
them by aborted clients, etc. there is only ever going to
be 0, 1 or 2 bytes in them, but we'll allow for up to 16.
- */
+ */
for (i = 0; i < engine->fifo_size; i++) {
if (engine->fifo[i] >= 0) {
- int nread = read (engine->fifo[i], buf, sizeof (buf));
+ int nread = read (engine->fifo[i], buf, sizeof(buf));
if (nread < 0 && errno != EAGAIN) {
jack_error ("clear fifo[%d] error: %s",
@@ -4281,7 +4286,7 @@ jack_get_free_port (jack_engine_t *engine)
pthread_mutex_unlock (&engine->port_lock);
if (i == engine->port_max) {
- return (jack_port_id_t) -1;
+ return (jack_port_id_t)-1;
}
return i;
@@ -4291,11 +4296,12 @@ void
jack_port_release (jack_engine_t *engine, jack_port_internal_t *port)
{
char buf[JACK_UUID_STRING_SIZE];
+
jack_uuid_unparse (port->shared->uuid, buf);
if (jack_remove_properties (NULL, port->shared->uuid) > 0) {
/* have to do the notification ourselves, since the client argument
to jack_remove_properties() was NULL
- */
+ */
jack_property_change_notify (engine, PropertyDeleted, port->shared->uuid, NULL);
}
@@ -4373,13 +4379,13 @@ jack_port_do_register (jack_engine_t *engine, jack_request_t *req, int internal)
return -1;
}
- if ((port = jack_get_port_by_name(engine, req->x.port_info.name)) != NULL) {
+ if ((port = jack_get_port_by_name (engine, req->x.port_info.name)) != NULL) {
jack_error ("duplicate port name (%s) in port registration request", req->x.port_info.name);
jack_unlock_graph (engine);
return -1;
}
- if ((port_id = jack_get_free_port (engine)) == (jack_port_id_t) -1) {
+ if ((port_id = jack_get_free_port (engine)) == (jack_port_id_t)-1) {
jack_error ("no ports available!");
jack_unlock_graph (engine);
return -1;
@@ -4392,9 +4398,9 @@ jack_port_do_register (jack_engine_t *engine, jack_request_t *req, int internal)
}
/* if the port belongs to the backend client, do some magic with names
- */
+ */
- backend_client_name = (char *) engine->driver->internal_client->control->name;
+ backend_client_name = (char*)engine->driver->internal_client->control->name;
len = strlen (backend_client_name);
if (strncmp (req->x.port_info.name, backend_client_name, len) != 0) {
@@ -4403,29 +4409,27 @@ jack_port_do_register (jack_engine_t *engine, jack_request_t *req, int internal)
/* use backend's original as an alias, use predefined names */
- if (strcmp(req->x.port_info.type, JACK_DEFAULT_AUDIO_TYPE) == 0) {
- if ((req->x.port_info.flags & (JackPortIsPhysical|JackPortIsInput)) == (JackPortIsPhysical|JackPortIsInput)) {
- snprintf (shared->name, sizeof (shared->name), JACK_BACKEND_ALIAS ":playback_%d", ++engine->audio_out_cnt);
+ if (strcmp (req->x.port_info.type, JACK_DEFAULT_AUDIO_TYPE) == 0) {
+ if ((req->x.port_info.flags & (JackPortIsPhysical | JackPortIsInput)) == (JackPortIsPhysical | JackPortIsInput)) {
+ snprintf (shared->name, sizeof(shared->name), JACK_BACKEND_ALIAS ":playback_%d", ++engine->audio_out_cnt);
strcpy (shared->alias1, req->x.port_info.name);
goto next;
- }
- else if ((req->x.port_info.flags & (JackPortIsPhysical|JackPortIsOutput)) == (JackPortIsPhysical|JackPortIsOutput)) {
- snprintf (shared->name, sizeof (shared->name), JACK_BACKEND_ALIAS ":capture_%d", ++engine->audio_in_cnt);
+ } else if ((req->x.port_info.flags & (JackPortIsPhysical | JackPortIsOutput)) == (JackPortIsPhysical | JackPortIsOutput)) {
+ snprintf (shared->name, sizeof(shared->name), JACK_BACKEND_ALIAS ":capture_%d", ++engine->audio_in_cnt);
strcpy (shared->alias1, req->x.port_info.name);
goto next;
}
}
-#if 0 // do not do this for MIDI
+#if 0 // do not do this for MIDI
- else if (strcmp(req->x.port_info.type, JACK_DEFAULT_MIDI_TYPE) == 0) {
- if ((req->x.port_info.flags & (JackPortIsPhysical|JackPortIsInput)) == (JackPortIsPhysical|JackPortIsInput)) {
- snprintf (shared->name, sizeof (shared->name), JACK_BACKEND_ALIAS ":midi_playback_%d", ++engine->midi_out_cnt);
+ else if (strcmp (req->x.port_info.type, JACK_DEFAULT_MIDI_TYPE) == 0) {
+ if ((req->x.port_info.flags & (JackPortIsPhysical | JackPortIsInput)) == (JackPortIsPhysical | JackPortIsInput)) {
+ snprintf (shared->name, sizeof(shared->name), JACK_BACKEND_ALIAS ":midi_playback_%d", ++engine->midi_out_cnt);
strcpy (shared->alias1, req->x.port_info.name);
goto next;
- }
- else if ((req->x.port_info.flags & (JackPortIsPhysical|JackPortIsOutput)) == (JackPortIsPhysical|JackPortIsOutput)) {
- snprintf (shared->name, sizeof (shared->name), JACK_BACKEND_ALIAS ":midi_capture_%d", ++engine->midi_in_cnt);
+ } else if ((req->x.port_info.flags & (JackPortIsPhysical | JackPortIsOutput)) == (JackPortIsPhysical | JackPortIsOutput)) {
+ snprintf (shared->name, sizeof(shared->name), JACK_BACKEND_ALIAS ":midi_capture_%d", ++engine->midi_in_cnt);
strcpy (shared->alias1, req->x.port_info.name);
goto next;
}
@@ -4459,8 +4463,9 @@ next:
}
client->ports = jack_slist_prepend (client->ports, port);
- if( client->control->active )
+ if ( client->control->active ) {
jack_port_registration_notify (engine, port_id, TRUE);
+ }
jack_unlock_graph (engine);
VERBOSE (engine, "registered port %s, offset = %u",
@@ -4543,17 +4548,17 @@ jack_do_get_port_connections (jack_engine_t *engine, jack_request_t *req,
for (node = engine->clients; node; node = jack_slist_next (node)) {
- if (((jack_client_internal_t *) node->data)->request_fd
+ if (((jack_client_internal_t*)node->data)->request_fd
== reply_fd) {
- internal = jack_client_is_internal(
- (jack_client_internal_t *) node->data);
+ internal = jack_client_is_internal (
+ (jack_client_internal_t*)node->data);
break;
}
}
if (!internal) {
- if (write (reply_fd, req, sizeof (*req))
- < (ssize_t) sizeof (req)) {
+ if (write (reply_fd, req, sizeof(*req))
+ < (ssize_t)sizeof(req)) {
jack_error ("cannot write GetPortConnections result "
"to client via fd = %d (%s)",
reply_fd, strerror (errno));
@@ -4561,8 +4566,8 @@ jack_do_get_port_connections (jack_engine_t *engine, jack_request_t *req,
}
} else {
req->x.port_connections.ports = (const char**)
- malloc (sizeof (char *)
- * req->x.port_connections.nports);
+ malloc (sizeof(char *)
+ * req->x.port_connections.nports);
}
if (req->type == GetPortConnections) {
@@ -4572,12 +4577,12 @@ jack_do_get_port_connections (jack_engine_t *engine, jack_request_t *req,
jack_port_id_t port_id;
- if (((jack_connection_internal_t *) node->data)->source
+ if (((jack_connection_internal_t*)node->data)->source
== port) {
- port_id = ((jack_connection_internal_t *)
+ port_id = ((jack_connection_internal_t*)
node->data)->destination->shared->id;
} else {
- port_id = ((jack_connection_internal_t *)
+ port_id = ((jack_connection_internal_t*)
node->data)->source->shared->id;
}
@@ -4587,7 +4592,7 @@ jack_do_get_port_connections (jack_engine_t *engine, jack_request_t *req,
* names. store in malloc'ed space,
* client frees
*/
- char **ports = (char **) req->x.port_connections.ports;
+ char **ports = (char**)req->x.port_connections.ports;
ports[i] = engine->control->ports[port_id].name;
@@ -4598,8 +4603,8 @@ jack_do_get_port_connections (jack_engine_t *engine, jack_request_t *req,
* the reply fd.
*/
if (write (reply_fd, &port_id,
- sizeof (port_id))
- < (ssize_t) sizeof (port_id)) {
+ sizeof(port_id))
+ < (ssize_t)sizeof(port_id)) {
jack_error ("cannot write port id "
"to client");
goto out;
@@ -4610,7 +4615,7 @@ jack_do_get_port_connections (jack_engine_t *engine, jack_request_t *req,
ret = 0;
- out:
+out:
req->status = ret;
jack_unlock_graph (engine);
return ret;
@@ -4629,7 +4634,7 @@ jack_port_registration_notify (jack_engine_t *engine,
for (node = engine->clients; node; node = jack_slist_next (node)) {
- client = (jack_client_internal_t *) node->data;
+ client = (jack_client_internal_t*)node->data;
if (!client->control->active) {
continue;
@@ -4639,7 +4644,7 @@ jack_port_registration_notify (jack_engine_t *engine,
if (jack_deliver_event (engine, client, &event)) {
jack_error ("cannot send port registration"
" notification to %s (%s)",
- client->control->name,
+ client->control->name,
strerror (errno));
}
}
@@ -4648,8 +4653,8 @@ jack_port_registration_notify (jack_engine_t *engine,
static void
jack_port_rename_notify (jack_engine_t *engine,
- const char* old_name,
- const char* new_name)
+ const char* old_name,
+ const char* new_name)
{
jack_event_t event;
jack_client_internal_t *client;
@@ -4659,18 +4664,18 @@ jack_port_rename_notify (jack_engine_t *engine,
if ((port = jack_get_port_by_name (engine, new_name)) == NULL) {
/* possible race condition: port renamed again
since this rename happened. Oh well.
- */
+ */
return;
}
event.type = PortRename;
event.y.other_id = port->shared->id;
- snprintf (event.x.name, JACK_PORT_NAME_SIZE-1, "%s", old_name);
- snprintf (event.z.other_name, JACK_PORT_NAME_SIZE-1, "%s", new_name);
+ snprintf (event.x.name, JACK_PORT_NAME_SIZE - 1, "%s", old_name);
+ snprintf (event.z.other_name, JACK_PORT_NAME_SIZE - 1, "%s", new_name);
for (node = engine->clients; node; node = jack_slist_next (node)) {
- client = (jack_client_internal_t *) node->data;
+ client = (jack_client_internal_t*)node->data;
if (!client->control->active) {
continue;
@@ -4679,9 +4684,9 @@ jack_port_rename_notify (jack_engine_t *engine,
if (client->control->port_rename_cbset) {
if (jack_deliver_event (engine, client, &event)) {
jack_error ("cannot send port registration"
- " notification to %s (%s)",
- client->control->name,
- strerror (errno));
+ " notification to %s (%s)",
+ client->control->name,
+ strerror (errno));
}
}
}
@@ -4696,17 +4701,17 @@ jack_client_registration_notify (jack_engine_t *engine,
JSList *node;
event.type = (yn ? ClientRegistered : ClientUnregistered);
- snprintf (event.x.name, sizeof (event.x.name), "%s", name);
+ snprintf (event.x.name, sizeof(event.x.name), "%s", name);
for (node = engine->clients; node; node = jack_slist_next (node)) {
- client = (jack_client_internal_t *) node->data;
+ client = (jack_client_internal_t*)node->data;
if (!client->control->active) {
continue;
}
- if (strcmp ((char*) client->control->name, (char*) name) == 0) {
+ if (strcmp ((char*)client->control->name, (char*)name) == 0) {
/* do not notify client of its own registration */
continue;
}
@@ -4715,7 +4720,7 @@ jack_client_registration_notify (jack_engine_t *engine,
if (jack_deliver_event (engine, client, &event)) {
jack_error ("cannot send client registration"
" notification to %s (%s)",
- client->control->name,
+ client->control->name,
strerror (errno));
}
}
@@ -4724,9 +4729,9 @@ jack_client_registration_notify (jack_engine_t *engine,
void
jack_property_change_notify (jack_engine_t *engine,
- jack_property_change_t change,
- jack_uuid_t uuid,
- const char* key)
+ jack_property_change_t change,
+ jack_uuid_t uuid,
+ const char* key)
{
jack_event_t event;
jack_client_internal_t *client;
@@ -4744,7 +4749,7 @@ jack_property_change_notify (jack_engine_t *engine,
for (node = engine->clients; node; node = jack_slist_next (node)) {
- client = (jack_client_internal_t *) node->data;
+ client = (jack_client_internal_t*)node->data;
if (!client->control->active) {
continue;
@@ -4753,8 +4758,8 @@ jack_property_change_notify (jack_engine_t *engine,
if (client->control->property_cbset) {
if (jack_deliver_event (engine, client, &event, key)) {
jack_error ("cannot send property change notification to %s (%s)",
- client->control->name,
- strerror (errno));
+ client->control->name,
+ strerror (errno));
}
}
}
@@ -4783,7 +4788,7 @@ jack_port_assign_buffer (jack_engine_t *engine, jack_port_internal_t *port)
return -1;
}
- bi = (jack_port_buffer_info_t *) blist->freelist->data;
+ bi = (jack_port_buffer_info_t*)blist->freelist->data;
blist->freelist = jack_slist_remove (blist->freelist, bi);
port->shared->offset = bi->offset;
@@ -4800,7 +4805,7 @@ jack_get_port_by_name (jack_engine_t *engine, const char *name)
/* Note the potential race on "in_use". Other design
elements prevent this from being a problem.
- */
+ */
for (id = 0; id < engine->port_max; id++) {
if (engine->control->ports[id].in_use &&
@@ -4820,9 +4825,9 @@ jack_send_connection_notification (jack_engine_t *engine,
{
jack_client_internal_t *client;
- jack_event_t event;
+ jack_event_t event;
- VALGRIND_MEMSET(&event, 0, sizeof(event));
+ VALGRIND_MEMSET (&event, 0, sizeof(event));
if ((client = jack_client_internal_by_id (engine, client_id)) == NULL) {
jack_error ("no such client %" PRIu32
@@ -4850,6 +4855,7 @@ static void
jack_wake_server_thread (jack_engine_t* engine)
{
char c = 0;
+
/* we don't actually care if this fails */
VERBOSE (engine, "waking server thread");
write (engine->cleanup_fifo[1], &c, 1);
diff --git a/jackd/jackd.c b/jackd/jackd.c
index 1a59b84..0faae93 100644
--- a/jackd/jackd.c
+++ b/jackd/jackd.c
@@ -1,7 +1,7 @@
/* -*- mode: c; c-file-style: "bsd"; -*- */
/*
Copyright (C) 2001-2005 Paul Davis
-
+
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
@@ -16,7 +16,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
+ */
#include <config.h>
@@ -73,19 +73,20 @@ static jack_nframes_t frame_time_offset = 0;
static int nozombies = 0;
static int timeout_count_threshold = 0;
-extern int sanitycheck (int, int);
+extern int sanitycheck(int, int);
static jack_driver_desc_t *
-jack_find_driver_descriptor (const char * name);
+jack_find_driver_descriptor(const char * name);
-static void
+static void
do_nothing_handler (int sig)
{
/* this is used by the child (active) process, but it never
gets called unless we are already shutting down after
another signal.
- */
+ */
char buf[64];
+
snprintf (buf, sizeof(buf),
"received signal %d during shutdown (ignored)\n", sig);
write (1, buf, strlen (buf));
@@ -93,147 +94,147 @@ do_nothing_handler (int sig)
static void
jack_load_internal_clients (JSList* load_list)
-{
+{
JSList * node;
- for (node = load_list; node; node = jack_slist_next (node)) {
-
- char* str = (char*) node->data;
- jack_request_t req;
- char* colon = strchr (str, ':');
- char* slash = strchr (str, '/');
- char* client_name = NULL;
- char* path = NULL;
- char* args = NULL;
- char* rest = NULL;
- int free_path = 0;
- int free_name = 0;
- size_t len;
-
- /* possible argument forms:
-
- client-name:client-type/args
- client-type/args
- client-name:client-type
- client-type
-
- client-name is the desired JACK client name.
- client-type is basically the name of the DLL/DSO without any suffix.
- args is a string whose contents will be passed to the client as
- it is instantiated
- */
-
- if ((slash == NULL && colon == NULL) || (slash && colon && colon > slash)) {
-
- /* client-type */
-
- client_name = str;
- path = client_name;
-
- } else if (slash && colon) {
-
- /* client-name:client-type/args */
-
- len = colon - str;
- if (len) {
- /* add 1 to leave space for a NULL */
- client_name = (char*) malloc (len + 1);
- free_name = 1;
- memcpy (client_name, str, len);
- client_name[len] = '\0';
- }
-
- len = slash - (colon+1);
- if (len) {
- /* add 1 to leave space for a NULL */
- path = (char*) malloc (len + 1);
- free_path = 1;
- memcpy (path, colon + 1, len);
- path[len] = '\0';
- } else {
- path = client_name;
- }
-
- rest = slash + 1;
- len = strlen (rest);
-
- if (len) {
- /* add 1 to leave space for a NULL */
- args = (char*) malloc (len + 1);
- memcpy (args, rest, len);
- args[len] = '\0';
- }
-
- } else if (slash && colon == NULL) {
-
- /* client-type/args */
-
- len = slash - str;
-
- if (len) {
- /* add 1 to leave space for a NULL */
- path = (char *) malloc (len + 1);
- free_path = 1;
- memcpy (path, str, len);
- path[len] = '\0';
- }
-
- rest = slash + 1;
- len = strlen (rest);
-
- if (len) {
- /* add 1 to leave space for a NULL */
- args = (char*) malloc (len + 1);
- memcpy (args, rest, len);
- args[len] = '\0';
- }
- } else {
-
- /* client-name:client-type */
-
- len = colon - str;
-
- if (len) {
- /* add 1 to leave space for a NULL */
- client_name = (char *) malloc (len + 1);
- free_name = 1;
- memcpy (client_name, str, len);
- client_name[len] = '\0';
- path = colon + 1;
- }
- }
-
- if (client_name == NULL || path == NULL) {
- fprintf (stderr, "incorrect format for internal client specification (%s)\n", str);
- exit (1);
- }
-
- memset (&req, 0, sizeof (req));
- req.type = IntClientLoad;
- req.x.intclient.options = 0;
- strncpy (req.x.intclient.name, client_name, sizeof (req.x.intclient.name));
- strncpy (req.x.intclient.path, path, sizeof (req.x.intclient.path));
-
- if (args) {
- strncpy (req.x.intclient.init, args, sizeof (req.x.intclient.init));
- } else {
- req.x.intclient.init[0] = '\0';
- }
-
- pthread_mutex_lock (&engine->request_lock);
- jack_intclient_load_request (engine, &req);
- pthread_mutex_unlock (&engine->request_lock);
-
- if (free_name) {
- free (client_name);
- }
- if (free_path) {
- free (path);
- }
- if (args) {
- free (args);
- }
- }
+ for (node = load_list; node; node = jack_slist_next (node)) {
+
+ char* str = (char*)node->data;
+ jack_request_t req;
+ char* colon = strchr (str, ':');
+ char* slash = strchr (str, '/');
+ char* client_name = NULL;
+ char* path = NULL;
+ char* args = NULL;
+ char* rest = NULL;
+ int free_path = 0;
+ int free_name = 0;
+ size_t len;
+
+ /* possible argument forms:
+
+ client-name:client-type/args
+ client-type/args
+ client-name:client-type
+ client-type
+
+ client-name is the desired JACK client name.
+ client-type is basically the name of the DLL/DSO without any suffix.
+ args is a string whose contents will be passed to the client as
+ it is instantiated
+ */
+
+ if ((slash == NULL && colon == NULL) || (slash && colon && colon > slash)) {
+
+ /* client-type */
+
+ client_name = str;
+ path = client_name;
+
+ } else if (slash && colon) {
+
+ /* client-name:client-type/args */
+
+ len = colon - str;
+ if (len) {
+ /* add 1 to leave space for a NULL */
+ client_name = (char*)malloc (len + 1);
+ free_name = 1;
+ memcpy (client_name, str, len);
+ client_name[len] = '\0';
+ }
+
+ len = slash - (colon + 1);
+ if (len) {
+ /* add 1 to leave space for a NULL */
+ path = (char*)malloc (len + 1);
+ free_path = 1;
+ memcpy (path, colon + 1, len);
+ path[len] = '\0';
+ } else {
+ path = client_name;
+ }
+
+ rest = slash + 1;
+ len = strlen (rest);
+
+ if (len) {
+ /* add 1 to leave space for a NULL */
+ args = (char*)malloc (len + 1);
+ memcpy (args, rest, len);
+ args[len] = '\0';
+ }
+
+ } else if (slash && colon == NULL) {
+
+ /* client-type/args */
+
+ len = slash - str;
+
+ if (len) {
+ /* add 1 to leave space for a NULL */
+ path = (char*)malloc (len + 1);
+ free_path = 1;
+ memcpy (path, str, len);
+ path[len] = '\0';
+ }
+
+ rest = slash + 1;
+ len = strlen (rest);
+
+ if (len) {
+ /* add 1 to leave space for a NULL */
+ args = (char*)malloc (len + 1);
+ memcpy (args, rest, len);
+ args[len] = '\0';
+ }
+ } else {
+
+ /* client-name:client-type */
+
+ len = colon - str;
+
+ if (len) {
+ /* add 1 to leave space for a NULL */
+ client_name = (char*)malloc (len + 1);
+ free_name = 1;
+ memcpy (client_name, str, len);
+ client_name[len] = '\0';
+ path = colon + 1;
+ }
+ }
+
+ if (client_name == NULL || path == NULL) {
+ fprintf (stderr, "incorrect format for internal client specification (%s)\n", str);
+ exit (1);
+ }
+
+ memset (&req, 0, sizeof(req));
+ req.type = IntClientLoad;
+ req.x.intclient.options = 0;
+ strncpy (req.x.intclient.name, client_name, sizeof(req.x.intclient.name));
+ strncpy (req.x.intclient.path, path, sizeof(req.x.intclient.path));
+
+ if (args) {
+ strncpy (req.x.intclient.init, args, sizeof(req.x.intclient.init));
+ } else {
+ req.x.intclient.init[0] = '\0';
+ }
+
+ pthread_mutex_lock (&engine->request_lock);
+ jack_intclient_load_request (engine, &req);
+ pthread_mutex_unlock (&engine->request_lock);
+
+ if (free_name) {
+ free (client_name);
+ }
+ if (free_path) {
+ free (path);
+ }
+ if (args) {
+ free (args);
+ }
+ }
}
static int
@@ -248,7 +249,7 @@ jack_main (jack_driver_desc_t * driver_desc, JSList * driver_params, JSList * sl
/* ensure that we are in our own process group so that
kill (SIG, -pgrp) does the right thing.
- */
+ */
setsid ();
@@ -258,14 +259,14 @@ jack_main (jack_driver_desc_t * driver_desc, JSList * driver_params, JSList * sl
POSIX says that signals are delivered like this:
- * if a thread has blocked that signal, it is not
+ * if a thread has blocked that signal, it is not
a candidate to receive the signal.
- * of all threads not blocking the signal, pick
+ * of all threads not blocking the signal, pick
one at random, and deliver the signal.
- this means that a simple-minded multi-threaded program can
- expect to get POSIX signals delivered randomly to any one
- of its threads,
+ this means that a simple-minded multi-threaded program can
+ expect to get POSIX signals delivered randomly to any one
+ of its threads,
here, we block all signals that we think we might receive
and want to catch. all "child" threads will inherit this
@@ -278,50 +279,51 @@ jack_main (jack_driver_desc_t * driver_desc, JSList * driver_params, JSList * sl
importantly, we are free to call async-unsafe functions,
because the code is executing in normal thread context
after a return from sigwait().
- */
+ */
sigemptyset (&signals);
- sigaddset(&signals, SIGHUP);
- sigaddset(&signals, SIGINT);
- sigaddset(&signals, SIGQUIT);
- sigaddset(&signals, SIGPIPE);
- sigaddset(&signals, SIGTERM);
- sigaddset(&signals, SIGUSR1);
- sigaddset(&signals, SIGUSR2);
+ sigaddset (&signals, SIGHUP);
+ sigaddset (&signals, SIGINT);
+ sigaddset (&signals, SIGQUIT);
+ sigaddset (&signals, SIGPIPE);
+ sigaddset (&signals, SIGTERM);
+ sigaddset (&signals, SIGUSR1);
+ sigaddset (&signals, SIGUSR2);
/* all child threads will inherit this mask unless they
- * explicitly reset it
+ * explicitly reset it
*/
pthread_sigmask (SIG_BLOCK, &signals, 0);
- if (!realtime && client_timeout == 0)
+ if (!realtime && client_timeout == 0) {
client_timeout = 500; /* 0.5 sec; usable when non realtime. */
+ }
/* get the engine/driver started */
- if ((engine = jack_engine_new (realtime, realtime_priority,
+ if ((engine = jack_engine_new (realtime, realtime_priority,
do_mlock, do_unlock, server_name,
temporary, verbose, client_timeout,
- port_max, getpid(), frame_time_offset,
+ port_max, getpid (), frame_time_offset,
nozombies, timeout_count_threshold, drivers)) == 0) {
jack_error ("cannot create engine");
return -1;
}
jack_info ("loading driver ..");
-
+
if (jack_engine_load_driver (engine, driver_desc, driver_params)) {
jack_error ("cannot load driver module %s",
- driver_desc->name);
+ driver_desc->name);
goto error;
}
- for (node=slave_names; node; node=jack_slist_next(node)) {
+ for (node = slave_names; node; node = jack_slist_next (node)) {
char *sl_name = node->data;
- jack_driver_desc_t *sl_desc = jack_find_driver_descriptor(sl_name);
+ jack_driver_desc_t *sl_desc = jack_find_driver_descriptor (sl_name);
if (sl_desc) {
- jack_engine_load_slave_driver(engine, sl_desc, NULL);
+ jack_engine_load_slave_driver (engine, sl_desc, NULL);
}
}
@@ -331,25 +333,25 @@ jack_main (jack_driver_desc_t * driver_desc, JSList * driver_params, JSList * sl
goto error;
}
- jack_load_internal_clients (load_list);
+ jack_load_internal_clients (load_list);
/* install a do-nothing handler because otherwise pthreads
behaviour is undefined when we enter sigwait.
- */
+ */
sigfillset (&allsignals);
action.sa_handler = do_nothing_handler;
action.sa_mask = allsignals;
- action.sa_flags = SA_RESTART|SA_RESETHAND;
+ action.sa_flags = SA_RESTART | SA_RESETHAND;
for (i = 1; i < NSIG; i++) {
if (sigismember (&signals, i)) {
sigaction (i, &action, 0);
- }
+ }
}
-
+
if (verbose) {
- jack_info ("%d waiting for signals", getpid());
+ jack_info ("%d waiting for signals", getpid ());
}
waiting = TRUE;
@@ -358,10 +360,10 @@ jack_main (jack_driver_desc_t * driver_desc, JSList * driver_params, JSList * sl
sigwait (&signals, &sig);
jack_info ("jack main caught signal %d", sig);
-
+
switch (sig) {
case SIGUSR1:
- jack_dump_configuration(engine, 1);
+ jack_dump_configuration (engine, 1);
break;
case SIGUSR2:
/* driver exit */
@@ -371,20 +373,20 @@ jack_main (jack_driver_desc_t * driver_desc, JSList * driver_params, JSList * sl
waiting = FALSE;
break;
}
- }
-
+ }
+
if (sig != SIGSEGV) {
/* unblock signals so we can see them during shutdown.
this will help prod developers not to lose sight of
bugs that cause segfaults etc. during shutdown.
- */
+ */
sigprocmask (SIG_UNBLOCK, &signals, 0);
}
-
+
jack_engine_delete (engine);
return 1;
-
+
error:
jack_engine_delete (engine);
return -1;
@@ -402,7 +404,7 @@ jack_drivers_get_descriptor (JSList * drivers, const char * sofile)
int err;
char* driver_dir;
- if ((driver_dir = getenv("JACK_DRIVER_DIR")) == 0) {
+ if ((driver_dir = getenv ("JACK_DRIVER_DIR")) == 0) {
driver_dir = ADDON_DIR;
}
filename = malloc (strlen (driver_dir) + 1 + strlen (sofile) + 1);
@@ -412,17 +414,17 @@ jack_drivers_get_descriptor (JSList * drivers, const char * sofile)
jack_info ("getting driver descriptor from %s", filename);
}
- if ((dlhandle = dlopen (filename, RTLD_NOW|RTLD_GLOBAL)) == NULL) {
+ if ((dlhandle = dlopen (filename, RTLD_NOW | RTLD_GLOBAL)) == NULL) {
jack_error ("could not open driver .so '%s': %s\n", filename, dlerror ());
free (filename);
return NULL;
}
so_get_descriptor = (JackDriverDescFunction)
- dlsym (dlhandle, "driver_get_descriptor");
+ dlsym (dlhandle, "driver_get_descriptor");
if ((dlerr = dlerror ()) != NULL) {
- jack_error("%s", dlerr);
+ jack_error ("%s", dlerr);
dlclose (dlhandle);
free (filename);
return NULL;
@@ -441,7 +443,7 @@ jack_drivers_get_descriptor (JSList * drivers, const char * sofile)
/* check it doesn't exist already */
for (node = drivers; node; node = jack_slist_next (node)) {
- other_descriptor = (jack_driver_desc_t *) node->data;
+ other_descriptor = (jack_driver_desc_t*)node->data;
if (strcmp (descriptor->name, other_descriptor->name) == 0) {
jack_error ("the drivers in '%s' and '%s' both have the name '%s'; using the first\n",
@@ -469,7 +471,7 @@ jack_drivers_load ()
jack_driver_desc_t * desc;
char* driver_dir;
- if ((driver_dir = getenv("JACK_DRIVER_DIR")) == 0) {
+ if ((driver_dir = getenv ("JACK_DRIVER_DIR")) == 0) {
driver_dir = ADDON_DIR;
}
@@ -481,7 +483,7 @@ jack_drivers_load ()
driver_dir, strerror (errno));
return NULL;
}
-
+
while ( (dir_entry = readdir (dir_stream)) ) {
/* check the filename is of the right format */
if (strncmp ("jack_", dir_entry->d_name, 5) != 0) {
@@ -520,26 +522,26 @@ jack_drivers_load ()
static void copyright (FILE* file)
{
fprintf (file, "jackd " VERSION "\n"
-"Copyright 2001-2009 Paul Davis, Stephane Letz, Jack O'Quinn, Torben Hohn and others.\n"
-"jackd comes with ABSOLUTELY NO WARRANTY\n"
-"This is free software, and you are welcome to redistribute it\n"
-"under certain conditions; see the file COPYING for details\n\n");
+ "Copyright 2001-2009 Paul Davis, Stephane Letz, Jack O'Quinn, Torben Hohn and others.\n"
+ "jackd comes with ABSOLUTELY NO WARRANTY\n"
+ "This is free software, and you are welcome to redistribute it\n"
+ "under certain conditions; see the file COPYING for details\n\n");
}
-static void usage (FILE *file)
+static void usage (FILE *file)
{
copyright (file);
fprintf (file, "\n"
-"usage: jackd [ server options ] -d backend [ ... backend options ... ]\n"
-" (see the manual page for jackd for a complete list of options)\n\n"
+ "usage: jackd [ server options ] -d backend [ ... backend options ... ]\n"
+ " (see the manual page for jackd for a complete list of options)\n\n"
#ifdef __APPLE__
-" Available backends may include: coreaudio, dummy, net, portaudio.\n\n"
-#else
-" Available backends may include: alsa, dummy, freebob, firewire, net, oss, sun, or portaudio.\n\n"
+ " Available backends may include: coreaudio, dummy, net, portaudio.\n\n"
+#else
+ " Available backends may include: alsa, dummy, freebob, firewire, net, oss, sun, or portaudio.\n\n"
#endif
-" jackd -d backend --help\n"
-" to display options for each backend\n\n");
-}
+ " jackd -d backend --help\n"
+ " to display options for each backend\n\n");
+}
static jack_driver_desc_t *
jack_find_driver_descriptor (const char * name)
@@ -548,7 +550,7 @@ jack_find_driver_descriptor (const char * name)
JSList * node;
for (node = drivers; node; node = jack_slist_next (node)) {
- desc = (jack_driver_desc_t *) node->data;
+ desc = (jack_driver_desc_t*)node->data;
if (strcmp (desc->name, name) != 0) {
desc = NULL;
@@ -565,8 +567,9 @@ jack_cleanup_files (const char *server_name)
{
DIR *dir;
struct dirent *dirent;
- char dir_name[PATH_MAX+1] = "";
- jack_server_dir (server_name, dir_name);
+ char dir_name[PATH_MAX + 1] = "";
+
+ jack_server_dir (server_name, dir_name);
/* On termination, we remove all files that jackd creates so
* subsequent attempts to start jackd will not believe that an
@@ -592,27 +595,27 @@ jack_cleanup_files (const char *server_name)
/* unlink all the files in this directory, they are mine */
while ((dirent = readdir (dir)) != NULL) {
- char fullpath[PATH_MAX+1];
+ char fullpath[PATH_MAX + 1];
if ((strcmp (dirent->d_name, ".") == 0)
|| (strcmp (dirent->d_name, "..") == 0)) {
continue;
}
- snprintf (fullpath, sizeof (fullpath), "%s/%s",
+ snprintf (fullpath, sizeof(fullpath), "%s/%s",
dir_name, dirent->d_name);
if (unlink (fullpath)) {
jack_error ("cannot unlink `%s' (%s)", fullpath,
strerror (errno));
}
- }
+ }
closedir (dir);
/* now, delete the per-server subdirectory, itself */
if (rmdir (dir_name)) {
- jack_error ("cannot remove `%s' (%s)", dir_name,
+ jack_error ("cannot remove `%s' (%s)", dir_name,
strerror (errno));
}
@@ -633,20 +636,20 @@ maybe_use_capabilities ()
/* check to see if there is a pipe in the right descriptor */
if ((status = fstat (PIPE_WRITE_FD, &pipe_stat)) == 0 &&
- S_ISFIFO(pipe_stat.st_mode)) {
+ S_ISFIFO (pipe_stat.st_mode)) {
/* tell jackstart we are up and running */
- char c = 1;
+ char c = 1;
- if (write (PIPE_WRITE_FD, &c, 1) != 1) {
- jack_error ("cannot write to jackstart sync "
- "pipe %d (%s)", PIPE_WRITE_FD,
- strerror (errno));
- }
+ if (write (PIPE_WRITE_FD, &c, 1) != 1) {
+ jack_error ("cannot write to jackstart sync "
+ "pipe %d (%s)", PIPE_WRITE_FD,
+ strerror (errno));
+ }
- if (close(PIPE_WRITE_FD) != 0) {
- jack_error("jackd: error on startup pipe close: %s",
- strerror (errno));
+ if (close (PIPE_WRITE_FD) != 0) {
+ jack_error ("jackd: error on startup pipe close: %s",
+ strerror (errno));
} else {
/* wait for jackstart process to set our capabilities */
if (wait (&status) == -1) {
@@ -660,10 +663,10 @@ maybe_use_capabilities ()
}
}
}
-#endif /* USE_CAPABILITIES */
+#endif /* USE_CAPABILITIES */
}
-int
+int
main (int argc, char *argv[])
{
@@ -677,38 +680,38 @@ main (int argc, char *argv[])
#else
const char *options = "d:P:uvshVrRZTFlI:t:mM:n:Np:c:X:C:";
#endif
- struct option long_options[] =
- {
+ struct option long_options[] =
+ {
/* keep ordered by single-letter option code */
#ifdef HAVE_ZITA_BRIDGE_DEPS
- { "alsa-add", 1, 0, 'A' },
+ { "alsa-add", 1, 0, 'A' },
#endif
- { "clock-source", 1, 0, 'c' },
- { "driver", 1, 0, 'd' },
- { "help", 0, 0, 'h' },
- { "tmpdir-location", 0, 0, 'l' },
- { "internal-client", 0, 0, 'I' },
- { "no-mlock", 0, 0, 'm' },
- { "midi-bufsize", 1, 0, 'M' },
- { "name", 1, 0, 'n' },
- { "no-sanity-checks", 0, 0, 'N' },
- { "port-max", 1, 0, 'p' },
- { "realtime-priority", 1, 0, 'P' },
- { "no-realtime", 0, 0, 'r' },
- { "realtime", 0, 0, 'R' },
- { "replace-registry", 0, &replace_registry, 0 },
- { "silent", 0, 0, 's' },
- { "sync", 0, 0, 'S' },
- { "timeout", 1, 0, 't' },
- { "temporary", 0, 0, 'T' },
- { "unlock", 0, 0, 'u' },
- { "version", 0, 0, 'V' },
- { "verbose", 0, 0, 'v' },
- { "slave-driver", 1, 0, 'X' },
- { "nozombies", 0, 0, 'Z' },
- { "timeout-thres", 2, 0, 'C' },
- { 0, 0, 0, 0 }
+ { "clock-source", 1, 0, 'c' },
+ { "driver", 1, 0, 'd' },
+ { "help", 0, 0, 'h' },
+ { "tmpdir-location", 0, 0, 'l' },
+ { "internal-client", 0, 0, 'I' },
+ { "no-mlock", 0, 0, 'm' },
+ { "midi-bufsize", 1, 0, 'M' },
+ { "name", 1, 0, 'n' },
+ { "no-sanity-checks", 0, 0, 'N' },
+ { "port-max", 1, 0, 'p' },
+ { "realtime-priority", 1, 0, 'P' },
+ { "no-realtime", 0, 0, 'r' },
+ { "realtime", 0, 0, 'R' },
+ { "replace-registry", 0, &replace_registry, 0 },
+ { "silent", 0, 0, 's' },
+ { "sync", 0, 0, 'S' },
+ { "timeout", 1, 0, 't' },
+ { "temporary", 0, 0, 'T' },
+ { "unlock", 0, 0, 'u' },
+ { "version", 0, 0, 'V' },
+ { "verbose", 0, 0, 'v' },
+ { "slave-driver", 1, 0, 'X' },
+ { "nozombies", 0, 0, 'Z' },
+ { "timeout-thres", 2, 0, 'C' },
+ { 0, 0, 0, 0 }
};
int opt = 0;
int option_index = 0;
@@ -717,16 +720,16 @@ main (int argc, char *argv[])
char **driver_args = NULL;
JSList * driver_params;
JSList * slave_drivers = NULL;
- JSList * load_list = NULL;
+ JSList * load_list = NULL;
size_t midi_buffer_size = 0;
int driver_nargs = 1;
int i;
int rc;
#ifdef HAVE_ZITA_BRIDGE_DEPS
- const char* alsa_add_client_name_playback = "zalsa_out";
- const char* alsa_add_client_name_capture = "zalsa_in";
- char alsa_add_args[64];
- char* dirstr;
+ const char* alsa_add_client_name_playback = "zalsa_out";
+ const char* alsa_add_client_name_capture = "zalsa_in";
+ char alsa_add_args[64];
+ char* dirstr;
#endif
setvbuf (stdout, NULL, _IOLBF, 0);
@@ -739,37 +742,37 @@ main (int argc, char *argv[])
switch (opt) {
#ifdef HAVE_ZITA_BRIDGE_DEPS
- case 'A':
- /* add a new internal client named after the ALSA device name
- given as optarg, using the last character 'p' or 'c' to
- indicate playback or capture. If there isn't one,
- assume capture (common case: USB mics etc.)
- */
- if ((dirstr = strstr (optarg, "%p")) != NULL && dirstr == (optarg + strlen(optarg) - 2)) {
- snprintf (alsa_add_args, sizeof (alsa_add_args), "%.*s_play:%s/-dhw:%.*s",
- (int) strlen (optarg) - 2, optarg,
- alsa_add_client_name_playback,
- (int) strlen (optarg) - 2, optarg);
- load_list = jack_slist_append(load_list, strdup (alsa_add_args));
- } else if ((dirstr = strstr (optarg, "%c")) != NULL && dirstr == (optarg + strlen(optarg) - 2)) {
- snprintf (alsa_add_args, sizeof (alsa_add_args), "%.*s_rec:%s/-dhw:%.*s",
- (int) strlen (optarg) - 2, optarg,
- alsa_add_client_name_capture,
- (int) strlen (optarg) - 2, optarg);
- load_list = jack_slist_append(load_list, strdup (alsa_add_args));
- } else {
- snprintf (alsa_add_args, sizeof (alsa_add_args), "%s_play:%s/-dhw:%s",
- optarg,
- alsa_add_client_name_playback,
- optarg);
- load_list = jack_slist_append(load_list, strdup (alsa_add_args));
- snprintf (alsa_add_args, sizeof (alsa_add_args), "%s_rec:%s/-dhw:%s",
- optarg,
- alsa_add_client_name_capture,
- optarg);
- load_list = jack_slist_append(load_list, strdup (alsa_add_args));
- }
- break;
+ case 'A':
+ /* add a new internal client named after the ALSA device name
+ given as optarg, using the last character 'p' or 'c' to
+ indicate playback or capture. If there isn't one,
+ assume capture (common case: USB mics etc.)
+ */
+ if ((dirstr = strstr (optarg, "%p")) != NULL && dirstr == (optarg + strlen (optarg) - 2)) {
+ snprintf (alsa_add_args, sizeof(alsa_add_args), "%.*s_play:%s/-dhw:%.*s",
+ (int)strlen (optarg) - 2, optarg,
+ alsa_add_client_name_playback,
+ (int)strlen (optarg) - 2, optarg);
+ load_list = jack_slist_append (load_list, strdup (alsa_add_args));
+ } else if ((dirstr = strstr (optarg, "%c")) != NULL && dirstr == (optarg + strlen (optarg) - 2)) {
+ snprintf (alsa_add_args, sizeof(alsa_add_args), "%.*s_rec:%s/-dhw:%.*s",
+ (int)strlen (optarg) - 2, optarg,
+ alsa_add_client_name_capture,
+ (int)strlen (optarg) - 2, optarg);
+ load_list = jack_slist_append (load_list, strdup (alsa_add_args));
+ } else {
+ snprintf (alsa_add_args, sizeof(alsa_add_args), "%s_play:%s/-dhw:%s",
+ optarg,
+ alsa_add_client_name_playback,
+ optarg);
+ load_list = jack_slist_append (load_list, strdup (alsa_add_args));
+ snprintf (alsa_add_args, sizeof(alsa_add_args), "%s_rec:%s/-dhw:%s",
+ optarg,
+ alsa_add_client_name_capture,
+ optarg);
+ load_list = jack_slist_append (load_list, strdup (alsa_add_args));
+ }
+ break;
#endif
case 'c':
@@ -791,10 +794,11 @@ main (int argc, char *argv[])
break;
case 'C':
- if (optarg)
+ if (optarg) {
timeout_count_threshold = atoi (optarg);
- else
+ } else {
timeout_count_threshold = 250;
+ }
break;
case 'd':
@@ -803,7 +807,7 @@ main (int argc, char *argv[])
break;
case 'D':
- frame_time_offset = JACK_MAX_FRAMES - atoi(optarg);
+ frame_time_offset = JACK_MAX_FRAMES - atoi (optarg);
break;
case 'l':
@@ -811,16 +815,16 @@ main (int argc, char *argv[])
printf ("%s\n", jack_tmpdir);
exit (0);
- case 'I':
- load_list = jack_slist_append(load_list, optarg);
- break;
+ case 'I':
+ load_list = jack_slist_append (load_list, optarg);
+ break;
case 'm':
do_mlock = 0;
break;
case 'M':
- midi_buffer_size = (unsigned int) atol (optarg);
+ midi_buffer_size = (unsigned int)atol (optarg);
break;
case 'n':
@@ -832,7 +836,7 @@ main (int argc, char *argv[])
break;
case 'p':
- port_max = (unsigned int) atol (optarg);
+ port_max = (unsigned int)atol (optarg);
break;
case 'P':
@@ -852,9 +856,9 @@ main (int argc, char *argv[])
jack_set_error_function (silent_jack_error_callback);
break;
- case 'S':
- /* this option is for jack2 only (synchronous mode) */
- break;
+ case 'S':
+ /* this option is for jack2 only (synchronous mode) */
+ break;
case 'T':
temporary = 1;
@@ -877,7 +881,7 @@ main (int argc, char *argv[])
break;
case 'X':
- slave_drivers = jack_slist_append(slave_drivers, optarg);
+ slave_drivers = jack_slist_append (slave_drivers, optarg);
break;
case 'Z':
nozombies = 1;
@@ -886,7 +890,7 @@ main (int argc, char *argv[])
default:
jack_error ("Unknown option character %c",
optopt);
- /*fallthru*/
+ /*fallthru*/
case 'h':
usage (stdout);
return -1;
@@ -894,10 +898,10 @@ main (int argc, char *argv[])
}
if (show_version) {
- printf ( "jackd version " VERSION
- " tmpdir " DEFAULT_TMP_DIR
- " protocol " PROTOCOL_VERSION
- "\n");
+ printf ( "jackd version " VERSION
+ " tmpdir " DEFAULT_TMP_DIR
+ " protocol " PROTOCOL_VERSION
+ "\n");
return 0;
}
@@ -912,26 +916,26 @@ main (int argc, char *argv[])
exit (1);
}
- /* DIRTY HACK needed to pick up -X supplied as part of ALSA driver args. This is legacy
- hack to make control apps like qjackctl based on the < 0.124 command line interface
- continue to work correctly.
-
- If -X seq was given as part of the driver args, load the ALSA MIDI slave driver.
- */
-
- for (i = seen_driver; i < argc; ++i) {
- if (strcmp (argv[i], "-X") == 0) {
- if (argc >= i + 2) {
- if (strcmp (argv[i+1], "seq") == 0) {
- slave_drivers = jack_slist_append (slave_drivers,"alsa_midi");
- }
- }
- break;
- } else if (strcmp (argv[i], "-Xseq") == 0) {
- slave_drivers = jack_slist_append (slave_drivers,"alsa_midi");
- break;
- }
- }
+ /* DIRTY HACK needed to pick up -X supplied as part of ALSA driver args. This is legacy
+ hack to make control apps like qjackctl based on the < 0.124 command line interface
+ continue to work correctly.
+
+ If -X seq was given as part of the driver args, load the ALSA MIDI slave driver.
+ */
+
+ for (i = seen_driver; i < argc; ++i) {
+ if (strcmp (argv[i], "-X") == 0) {
+ if (argc >= i + 2) {
+ if (strcmp (argv[i + 1], "seq") == 0) {
+ slave_drivers = jack_slist_append (slave_drivers, "alsa_midi");
+ }
+ }
+ break;
+ } else if (strcmp (argv[i], "-Xseq") == 0) {
+ slave_drivers = jack_slist_append (slave_drivers, "alsa_midi");
+ break;
+ }
+ }
drivers = jack_drivers_load ();
@@ -939,7 +943,7 @@ main (int argc, char *argv[])
fprintf (stderr, "jackd: no drivers found; exiting\n");
exit (1);
}
-
+
if (midi_buffer_size != 0) {
jack_port_type_info_t* port_type = &jack_builtin_port_types[JACK_MIDI_PORT_TYPE];
port_type->buffer_size = midi_buffer_size * jack_midi_internal_event_size ();
@@ -967,20 +971,20 @@ main (int argc, char *argv[])
return -1;
}
- driver_args = (char **) malloc (sizeof (char *) * driver_nargs);
+ driver_args = (char**)malloc (sizeof(char *) * driver_nargs);
driver_args[0] = driver_name;
-
- for (i = 1; i < driver_nargs; i++) {
+
+ for (i = 1; i < driver_nargs; i++)
driver_args[i] = argv[optind++];
- }
if (jack_parse_driver_params (desc, driver_nargs,
driver_args, &driver_params)) {
exit (0);
}
- if (server_name == NULL)
+ if (server_name == NULL) {
server_name = jack_default_server_name ();
+ }
rc = jack_register_server (server_name, replace_registry);
switch (rc) {
@@ -994,9 +998,10 @@ main (int argc, char *argv[])
fprintf (stderr, "no access to shm registry\n");
exit (3);
default:
- if (verbose)
+ if (verbose) {
fprintf (stderr, "server `%s' registered\n",
server_name);
+ }
}
/* clean up shared memory and files from any previous
@@ -1008,14 +1013,17 @@ main (int argc, char *argv[])
jack_main (desc, driver_params, slave_drivers, load_list);
/* clean up shared memory and files from this server instance */
- if (verbose)
+ if (verbose) {
fprintf (stderr, "cleaning up shared memory\n");
+ }
jack_cleanup_shm ();
- if (verbose)
+ if (verbose) {
fprintf (stderr, "cleaning up files\n");
+ }
jack_cleanup_files (server_name);
- if (verbose)
+ if (verbose) {
fprintf (stderr, "unregistering server `%s'\n", server_name);
+ }
jack_unregister_server (server_name);
exit (0);
diff --git a/jackd/jackstart.c b/jackd/jackstart.c
index 0bd21da..9b3fdc1 100644
--- a/jackd/jackstart.c
+++ b/jackd/jackstart.c
@@ -18,7 +18,7 @@
Finn Arne Gangstad <finnag@guardian.no> and givertcap.c, written by
Tommi Ilmonen, Tommi.Ilmonen@hut.fi
-*/
+ */
#include <sys/types.h>
#include <sys/stat.h>
@@ -51,7 +51,7 @@ static char *jackd_md5_sum = JACKD_MD5_SUM;
static int check_capabilities (void)
{
- cap_t caps = cap_init();
+ cap_t caps = cap_init ();
cap_flag_value_t cap;
pid_t pid;
int have_all_caps = 1;
@@ -67,28 +67,28 @@ static int check_capabilities (void)
return 0;
}
/* check that we are able to give capabilites to other processes */
- cap_get_flag(caps, CAP_SETPCAP, CAP_EFFECTIVE, &cap);
+ cap_get_flag (caps, CAP_SETPCAP, CAP_EFFECTIVE, &cap);
if (cap == CAP_CLEAR) {
have_all_caps = 0;
goto done;
}
/* check that we have the capabilities we want to transfer */
- cap_get_flag(caps, CAP_SYS_NICE, CAP_EFFECTIVE, &cap);
+ cap_get_flag (caps, CAP_SYS_NICE, CAP_EFFECTIVE, &cap);
if (cap == CAP_CLEAR) {
have_all_caps = 0;
goto done;
}
- cap_get_flag(caps, CAP_SYS_RESOURCE, CAP_EFFECTIVE, &cap);
+ cap_get_flag (caps, CAP_SYS_RESOURCE, CAP_EFFECTIVE, &cap);
if (cap == CAP_CLEAR) {
have_all_caps = 0;
goto done;
}
- cap_get_flag(caps, CAP_IPC_LOCK, CAP_EFFECTIVE, &cap);
+ cap_get_flag (caps, CAP_IPC_LOCK, CAP_EFFECTIVE, &cap);
if (cap == CAP_CLEAR) {
have_all_caps = 0;
goto done;
}
- done:
+done:
cap_free (caps);
return have_all_caps;
}
@@ -96,23 +96,23 @@ static int check_capabilities (void)
static int give_capabilities (pid_t pid)
{
- cap_t caps = cap_init();
+ cap_t caps = cap_init ();
const unsigned caps_size = 4;
cap_value_t cap_list[] =
- { CAP_SETPCAP, CAP_SYS_NICE, CAP_SYS_RESOURCE, CAP_IPC_LOCK} ;
+ { CAP_SETPCAP, CAP_SYS_NICE, CAP_SYS_RESOURCE, CAP_IPC_LOCK };
if (caps == NULL) {
fprintf (stderr, "jackstart: could not allocate capability working storage\n");
return -1;
}
- cap_clear(caps);
+ cap_clear (caps);
if (capgetp (pid, caps)) {
fprintf (stderr, "jackstart: could not get capabilities for process %d\n", pid);
- cap_clear(caps);
+ cap_clear (caps);
}
- cap_set_flag(caps, CAP_EFFECTIVE, caps_size, cap_list , CAP_SET);
- cap_set_flag(caps, CAP_INHERITABLE, caps_size, cap_list , CAP_SET);
- cap_set_flag(caps, CAP_PERMITTED, caps_size, cap_list , CAP_SET);
+ cap_set_flag (caps, CAP_EFFECTIVE, caps_size, cap_list, CAP_SET);
+ cap_set_flag (caps, CAP_INHERITABLE, caps_size, cap_list, CAP_SET);
+ cap_set_flag (caps, CAP_PERMITTED, caps_size, cap_list, CAP_SET);
if (capsetp (pid, caps)) {
fprintf (stderr, "jackstart: could not give capabilities: %s\n", strerror (errno));
cap_free (caps);
@@ -127,12 +127,12 @@ static int check_binary (const char *binpath)
struct stat status;
FILE *binstream;
- if (lstat(jackd_bin_path, &status)) {
+ if (lstat (jackd_bin_path, &status)) {
fprintf (stderr, "jackstart: could not stat %s: %s\n",
- binpath, strerror(errno));
+ binpath, strerror (errno));
return -1;
}
- if (!(S_ISREG(status.st_mode))) {
+ if (!(S_ISREG (status.st_mode))) {
fprintf (stderr, "jackstart: %s is not a regular file\n",
binpath);
return -1;
@@ -149,8 +149,8 @@ static int check_binary (const char *binpath)
return -1;
}
if ((binstream = fopen (binpath, "r")) == NULL) {
- fprintf (stderr, "jackstart: can't open %s for reading: %s\n",
- binpath, strerror(errno));
+ fprintf (stderr, "jackstart: can't open %s for reading: %s\n",
+ binpath, strerror (errno));
return -1;
} else {
/* md5sum the executable file, check man evp for more details */
@@ -161,7 +161,7 @@ static int check_binary (const char *binpath)
char md_string[3];
int i, j;
- md5_init(&ctx);
+ md5_init (&ctx);
while (1) {
size_t n;
sum = 0;
@@ -170,24 +170,25 @@ static int check_binary (const char *binpath)
sum += n;
} while (sum < READ_BLOCKSIZE && n != 0);
if (n == 0 && ferror (binstream)) {
- fprintf (stderr, "jackstart: error while reading %s: %s\n", binpath, strerror(errno));
+ fprintf (stderr, "jackstart: error while reading %s: %s\n", binpath, strerror (errno));
return -1;
}
if (n == 0) {
break;
}
- md5_process(&ctx, buffer, READ_BLOCKSIZE);
+ md5_process (&ctx, buffer, READ_BLOCKSIZE);
+ }
+ if (sum > 0) {
+ md5_process (&ctx, buffer, sum);
}
- if (sum > 0)
- md5_process(&ctx, buffer, sum);
if (fclose (binstream)) {
- fprintf (stderr, "jackstart: could not close %s after reading: %s\n", binpath, strerror(errno));
+ fprintf (stderr, "jackstart: could not close %s after reading: %s\n", binpath, strerror (errno));
}
- md5_finish(&ctx, md_value);
- for(i = 0, j = 0; i < sizeof(md_value); i++, j+=2) {
- sprintf(md_string, "%02x", md_value[i]);
+ md5_finish (&ctx, md_value);
+ for (i = 0, j = 0; i < sizeof(md_value); i++, j += 2) {
+ sprintf (md_string, "%02x", md_value[i]);
if (md_string[0] != jackd_md5_sum[j] ||
- md_string[1] != jackd_md5_sum[j+1]) {
+ md_string[1] != jackd_md5_sum[j + 1]) {
fprintf (stderr, "jackstart: md5 checksum for %s does not match\n", binpath);
return -1;
}
@@ -196,7 +197,7 @@ static int check_binary (const char *binpath)
return 0;
}
-int main(int argc, char **argv)
+int main (int argc, char **argv)
{
uid_t uid, euid;
pid_t pid, parent_pid;
@@ -222,97 +223,97 @@ int main(int argc, char **argv)
/* see if we can get the required capabilities */
if (check_capabilities () == 0) {
size_t size;
- cap_t cap = cap_init();
- capgetp(0, cap);
+ cap_t cap = cap_init ();
+ capgetp (0, cap);
fprintf (stderr, "jackstart: cannot get realtime capabilities, current capabilities are:\n");
- fprintf (stderr, " %s\n", cap_to_text(cap, &size));
+ fprintf (stderr, " %s\n", cap_to_text (cap, &size));
fprintf (stderr, " probably running under a kernel with capabilities disabled,\n");
fprintf (stderr, " a suitable kernel would have printed something like \"=eip\"\n\n");
}
/* check the executable, owner, permissions, md5 checksum */
- if (check_binary(jackd_bin_path)) {
- exit(1);
+ if (check_binary (jackd_bin_path)) {
+ exit (1);
}
/* set process group to current pid */
- if (setpgid (0, getpid())) {
- fprintf (stderr, "jackstart: failed to set process group: %s\n",
- strerror(errno));
+ if (setpgid (0, getpid ())) {
+ fprintf (stderr, "jackstart: failed to set process group: %s\n",
+ strerror (errno));
exit (1);
}
/* create pipe to synchronize with jackd */
if (pipe (pipe_fds)) {
fprintf (stderr, "jackstart: could not create pipe: %s\n",
- strerror(errno));
+ strerror (errno));
exit (1);
}
/* make sure the file descriptors are the right ones,
otherwise dup them, this is to make sure that both
jackstart and jackd use the same fds
- */
+ */
if (pipe_fds[0] != PIPE_READ_FD) {
if (dup2 (pipe_fds[0], PIPE_READ_FD) != PIPE_READ_FD) {
fprintf (stderr, "jackstart: could not dup pipe read file descriptor: %s\n",
- strerror(errno));
+ strerror (errno));
exit (1);
}
}
if (pipe_fds[1] != PIPE_WRITE_FD) {
- if (dup2(pipe_fds[1], PIPE_WRITE_FD)!=PIPE_WRITE_FD) {
+ if (dup2 (pipe_fds[1], PIPE_WRITE_FD) != PIPE_WRITE_FD) {
fprintf (stderr, "jackstart: could not dup pipe write file descriptor: %s\n",
- strerror(errno));
+ strerror (errno));
exit (1);
}
}
/* fork off a child to wait for jackd to start */
- fflush(NULL);
- pid = fork();
+ fflush (NULL);
+ pid = fork ();
if (pid == -1) {
fprintf (stderr, "jackstart: fork failed\n");
exit (1);
}
if (pid) {
/* mother process: drops privileges, execs jackd */
- close(PIPE_READ_FD);
+ close (PIPE_READ_FD);
/* get rid of any supplemental groups */
if (!getuid () && setgroups (0, 0)) {
- fprintf (stderr, "jackstart: setgroups failed: %s\n", strerror(errno));
+ fprintf (stderr, "jackstart: setgroups failed: %s\n", strerror (errno));
exit (1);
}
/* set gid and uid */
- setregid(gid, gid);
- setreuid(uid, uid);
- execvp(jackd_bin_path, argv);
-
+ setregid (gid, gid);
+ setreuid (uid, uid);
+ execvp (jackd_bin_path, argv);
+
/* we could not start jackd, clean up and exit */
- fprintf(stderr, "jackstart: unable to execute %s: %s\n", jackd_bin_path, strerror(errno));
+ fprintf (stderr, "jackstart: unable to execute %s: %s\n", jackd_bin_path, strerror (errno));
close (PIPE_WRITE_FD);
wait (&err);
exit (1);
} else {
/* child process: grants privileges to jackd */
- close(PIPE_WRITE_FD);
+ close (PIPE_WRITE_FD);
/* wait for jackd to start */
while (1) {
- int ret;
+ int ret;
char c;
- /* picking up pipe closure is a tricky business.
+ /* picking up pipe closure is a tricky business.
this seems to work as well as anything else.
- */
+ */
- ret = read(PIPE_READ_FD, &c, 1);
+ ret = read (PIPE_READ_FD, &c, 1);
fprintf (stderr, "back from read, ret = %d errno == %s\n", ret, strerror (errno));
if (ret == 1) {
- break;
+ break;
} else if (errno != EINTR) {
- break;
+ break;
}
}
diff --git a/jackd/md5.c b/jackd/md5.c
index 15342b9..1dc458b 100644
--- a/jackd/md5.c
+++ b/jackd/md5.c
@@ -54,7 +54,7 @@
/* static char *rcs_id =
-/* version id for the library */
+ /* version id for the library */
/* static char *version_id = "$MD5Version: 1.0.0 November-19-1997 $"; */
/****************************** local routines *******************************/
@@ -78,140 +78,139 @@
*
* buf_len - The length of the buffer.
*/
-static void process_block(md5_t *md5_p, const void *buffer,
+static void process_block (md5_t *md5_p, const void *buffer,
const unsigned int buf_len)
{
- md5_uint32 correct[16];
- const void *buf_p = buffer, *end_p;
- unsigned int words_n;
- md5_uint32 A, B, C, D;
-
- words_n = buf_len / sizeof(md5_uint32);
- end_p = (char *)buf_p + words_n * sizeof(md5_uint32);
-
- A = md5_p->md_A;
- B = md5_p->md_B;
- C = md5_p->md_C;
- D = md5_p->md_D;
-
- /*
- * First increment the byte count. RFC 1321 specifies the possible
- * length of the file up to 2^64 bits. Here we only compute the
- * number of bytes with a double word increment. Modified to do
- * this to better avoid overflows in the lower word -- Gray 10/97.
- */
- if (md5_p->md_total[0] > MAX_MD5_UINT32 - buf_len) {
- md5_p->md_total[1]++;
- md5_p->md_total[0] -= (MAX_MD5_UINT32 - buf_len);
- }
- else {
- md5_p->md_total[0] += buf_len;
- }
-
- /*
- * Process all bytes in the buffer with MD5_BLOCK bytes in each
- * round of the loop.
- */
- while (buf_p < end_p) {
- md5_uint32 A_save, B_save, C_save, D_save;
- md5_uint32 *corr_p = correct;
-
- A_save = A;
- B_save = B;
- C_save = C;
- D_save = D;
-
- /*
- * Before we start, one word to the strange constants. They are
- * defined in RFC 1321 as
- *
- * T[i] = (int) (4294967296.0 * fabs (sin (i))), i=1..MD5_BLOCK
- */
-
- /* Round 1. */
- OP1 (A, B, C, D, buf_p, corr_p, 7, 0xd76aa478);
- OP1 (D, A, B, C, buf_p, corr_p, 12, 0xe8c7b756);
- OP1 (C, D, A, B, buf_p, corr_p, 17, 0x242070db);
- OP1 (B, C, D, A, buf_p, corr_p, 22, 0xc1bdceee);
- OP1 (A, B, C, D, buf_p, corr_p, 7, 0xf57c0faf);
- OP1 (D, A, B, C, buf_p, corr_p, 12, 0x4787c62a);
- OP1 (C, D, A, B, buf_p, corr_p, 17, 0xa8304613);
- OP1 (B, C, D, A, buf_p, corr_p, 22, 0xfd469501);
- OP1 (A, B, C, D, buf_p, corr_p, 7, 0x698098d8);
- OP1 (D, A, B, C, buf_p, corr_p, 12, 0x8b44f7af);
- OP1 (C, D, A, B, buf_p, corr_p, 17, 0xffff5bb1);
- OP1 (B, C, D, A, buf_p, corr_p, 22, 0x895cd7be);
- OP1 (A, B, C, D, buf_p, corr_p, 7, 0x6b901122);
- OP1 (D, A, B, C, buf_p, corr_p, 12, 0xfd987193);
- OP1 (C, D, A, B, buf_p, corr_p, 17, 0xa679438e);
- OP1 (B, C, D, A, buf_p, corr_p, 22, 0x49b40821);
-
- /* Round 2. */
- OP234 (FG, A, B, C, D, correct[ 1], 5, 0xf61e2562);
- OP234 (FG, D, A, B, C, correct[ 6], 9, 0xc040b340);
- OP234 (FG, C, D, A, B, correct[ 11], 14, 0x265e5a51);
- OP234 (FG, B, C, D, A, correct[ 0], 20, 0xe9b6c7aa);
- OP234 (FG, A, B, C, D, correct[ 5], 5, 0xd62f105d);
- OP234 (FG, D, A, B, C, correct[ 10], 9, 0x02441453);
- OP234 (FG, C, D, A, B, correct[ 15], 14, 0xd8a1e681);
- OP234 (FG, B, C, D, A, correct[ 4], 20, 0xe7d3fbc8);
- OP234 (FG, A, B, C, D, correct[ 9], 5, 0x21e1cde6);
- OP234 (FG, D, A, B, C, correct[ 14], 9, 0xc33707d6);
- OP234 (FG, C, D, A, B, correct[ 3], 14, 0xf4d50d87);
- OP234 (FG, B, C, D, A, correct[ 8], 20, 0x455a14ed);
- OP234 (FG, A, B, C, D, correct[ 13], 5, 0xa9e3e905);
- OP234 (FG, D, A, B, C, correct[ 2], 9, 0xfcefa3f8);
- OP234 (FG, C, D, A, B, correct[ 7], 14, 0x676f02d9);
- OP234 (FG, B, C, D, A, correct[ 12], 20, 0x8d2a4c8a);
-
- /* Round 3. */
- OP234 (FH, A, B, C, D, correct[ 5], 4, 0xfffa3942);
- OP234 (FH, D, A, B, C, correct[ 8], 11, 0x8771f681);
- OP234 (FH, C, D, A, B, correct[ 11], 16, 0x6d9d6122);
- OP234 (FH, B, C, D, A, correct[ 14], 23, 0xfde5380c);
- OP234 (FH, A, B, C, D, correct[ 1], 4, 0xa4beea44);
- OP234 (FH, D, A, B, C, correct[ 4], 11, 0x4bdecfa9);
- OP234 (FH, C, D, A, B, correct[ 7], 16, 0xf6bb4b60);
- OP234 (FH, B, C, D, A, correct[ 10], 23, 0xbebfbc70);
- OP234 (FH, A, B, C, D, correct[ 13], 4, 0x289b7ec6);
- OP234 (FH, D, A, B, C, correct[ 0], 11, 0xeaa127fa);
- OP234 (FH, C, D, A, B, correct[ 3], 16, 0xd4ef3085);
- OP234 (FH, B, C, D, A, correct[ 6], 23, 0x04881d05);
- OP234 (FH, A, B, C, D, correct[ 9], 4, 0xd9d4d039);
- OP234 (FH, D, A, B, C, correct[ 12], 11, 0xe6db99e5);
- OP234 (FH, C, D, A, B, correct[ 15], 16, 0x1fa27cf8);
- OP234 (FH, B, C, D, A, correct[ 2], 23, 0xc4ac5665);
-
- /* Round 4. */
- OP234 (FI, A, B, C, D, correct[ 0], 6, 0xf4292244);
- OP234 (FI, D, A, B, C, correct[ 7], 10, 0x432aff97);
- OP234 (FI, C, D, A, B, correct[ 14], 15, 0xab9423a7);
- OP234 (FI, B, C, D, A, correct[ 5], 21, 0xfc93a039);
- OP234 (FI, A, B, C, D, correct[ 12], 6, 0x655b59c3);
- OP234 (FI, D, A, B, C, correct[ 3], 10, 0x8f0ccc92);
- OP234 (FI, C, D, A, B, correct[ 10], 15, 0xffeff47d);
- OP234 (FI, B, C, D, A, correct[ 1], 21, 0x85845dd1);
- OP234 (FI, A, B, C, D, correct[ 8], 6, 0x6fa87e4f);
- OP234 (FI, D, A, B, C, correct[ 15], 10, 0xfe2ce6e0);
- OP234 (FI, C, D, A, B, correct[ 6], 15, 0xa3014314);
- OP234 (FI, B, C, D, A, correct[ 13], 21, 0x4e0811a1);
- OP234 (FI, A, B, C, D, correct[ 4], 6, 0xf7537e82);
- OP234 (FI, D, A, B, C, correct[ 11], 10, 0xbd3af235);
- OP234 (FI, C, D, A, B, correct[ 2], 15, 0x2ad7d2bb);
- OP234 (FI, B, C, D, A, correct[ 9], 21, 0xeb86d391);
-
- /* Add the starting values of the context. */
- A += A_save;
- B += B_save;
- C += C_save;
- D += D_save;
- }
-
- /* Put checksum in context given as argument. */
- md5_p->md_A = A;
- md5_p->md_B = B;
- md5_p->md_C = C;
- md5_p->md_D = D;
+ md5_uint32 correct[16];
+ const void *buf_p = buffer, *end_p;
+ unsigned int words_n;
+ md5_uint32 A, B, C, D;
+
+ words_n = buf_len / sizeof(md5_uint32);
+ end_p = (char*)buf_p + words_n * sizeof(md5_uint32);
+
+ A = md5_p->md_A;
+ B = md5_p->md_B;
+ C = md5_p->md_C;
+ D = md5_p->md_D;
+
+ /*
+ * First increment the byte count. RFC 1321 specifies the possible
+ * length of the file up to 2^64 bits. Here we only compute the
+ * number of bytes with a double word increment. Modified to do
+ * this to better avoid overflows in the lower word -- Gray 10/97.
+ */
+ if (md5_p->md_total[0] > MAX_MD5_UINT32 - buf_len) {
+ md5_p->md_total[1]++;
+ md5_p->md_total[0] -= (MAX_MD5_UINT32 - buf_len);
+ } else {
+ md5_p->md_total[0] += buf_len;
+ }
+
+ /*
+ * Process all bytes in the buffer with MD5_BLOCK bytes in each
+ * round of the loop.
+ */
+ while (buf_p < end_p) {
+ md5_uint32 A_save, B_save, C_save, D_save;
+ md5_uint32 *corr_p = correct;
+
+ A_save = A;
+ B_save = B;
+ C_save = C;
+ D_save = D;
+
+ /*
+ * Before we start, one word to the strange constants. They are
+ * defined in RFC 1321 as
+ *
+ * T[i] = (int) (4294967296.0 * fabs (sin (i))), i=1..MD5_BLOCK
+ */
+
+ /* Round 1. */
+ OP1 (A, B, C, D, buf_p, corr_p, 7, 0xd76aa478);
+ OP1 (D, A, B, C, buf_p, corr_p, 12, 0xe8c7b756);
+ OP1 (C, D, A, B, buf_p, corr_p, 17, 0x242070db);
+ OP1 (B, C, D, A, buf_p, corr_p, 22, 0xc1bdceee);
+ OP1 (A, B, C, D, buf_p, corr_p, 7, 0xf57c0faf);
+ OP1 (D, A, B, C, buf_p, corr_p, 12, 0x4787c62a);
+ OP1 (C, D, A, B, buf_p, corr_p, 17, 0xa8304613);
+ OP1 (B, C, D, A, buf_p, corr_p, 22, 0xfd469501);
+ OP1 (A, B, C, D, buf_p, corr_p, 7, 0x698098d8);
+ OP1 (D, A, B, C, buf_p, corr_p, 12, 0x8b44f7af);
+ OP1 (C, D, A, B, buf_p, corr_p, 17, 0xffff5bb1);
+ OP1 (B, C, D, A, buf_p, corr_p, 22, 0x895cd7be);
+ OP1 (A, B, C, D, buf_p, corr_p, 7, 0x6b901122);
+ OP1 (D, A, B, C, buf_p, corr_p, 12, 0xfd987193);
+ OP1 (C, D, A, B, buf_p, corr_p, 17, 0xa679438e);
+ OP1 (B, C, D, A, buf_p, corr_p, 22, 0x49b40821);
+
+ /* Round 2. */
+ OP234 (FG, A, B, C, D, correct[ 1], 5, 0xf61e2562);
+ OP234 (FG, D, A, B, C, correct[ 6], 9, 0xc040b340);
+ OP234 (FG, C, D, A, B, correct[ 11], 14, 0x265e5a51);
+ OP234 (FG, B, C, D, A, correct[ 0], 20, 0xe9b6c7aa);
+ OP234 (FG, A, B, C, D, correct[ 5], 5, 0xd62f105d);
+ OP234 (FG, D, A, B, C, correct[ 10], 9, 0x02441453);
+ OP234 (FG, C, D, A, B, correct[ 15], 14, 0xd8a1e681);
+ OP234 (FG, B, C, D, A, correct[ 4], 20, 0xe7d3fbc8);
+ OP234 (FG, A, B, C, D, correct[ 9], 5, 0x21e1cde6);
+ OP234 (FG, D, A, B, C, correct[ 14], 9, 0xc33707d6);
+ OP234 (FG, C, D, A, B, correct[ 3], 14, 0xf4d50d87);
+ OP234 (FG, B, C, D, A, correct[ 8], 20, 0x455a14ed);
+ OP234 (FG, A, B, C, D, correct[ 13], 5, 0xa9e3e905);
+ OP234 (FG, D, A, B, C, correct[ 2], 9, 0xfcefa3f8);
+ OP234 (FG, C, D, A, B, correct[ 7], 14, 0x676f02d9);
+ OP234 (FG, B, C, D, A, correct[ 12], 20, 0x8d2a4c8a);
+
+ /* Round 3. */
+ OP234 (FH, A, B, C, D, correct[ 5], 4, 0xfffa3942);
+ OP234 (FH, D, A, B, C, correct[ 8], 11, 0x8771f681);
+ OP234 (FH, C, D, A, B, correct[ 11], 16, 0x6d9d6122);
+ OP234 (FH, B, C, D, A, correct[ 14], 23, 0xfde5380c);
+ OP234 (FH, A, B, C, D, correct[ 1], 4, 0xa4beea44);
+ OP234 (FH, D, A, B, C, correct[ 4], 11, 0x4bdecfa9);
+ OP234 (FH, C, D, A, B, correct[ 7], 16, 0xf6bb4b60);
+ OP234 (FH, B, C, D, A, correct[ 10], 23, 0xbebfbc70);
+ OP234 (FH, A, B, C, D, correct[ 13], 4, 0x289b7ec6);
+ OP234 (FH, D, A, B, C, correct[ 0], 11, 0xeaa127fa);
+ OP234 (FH, C, D, A, B, correct[ 3], 16, 0xd4ef3085);
+ OP234 (FH, B, C, D, A, correct[ 6], 23, 0x04881d05);
+ OP234 (FH, A, B, C, D, correct[ 9], 4, 0xd9d4d039);
+ OP234 (FH, D, A, B, C, correct[ 12], 11, 0xe6db99e5);
+ OP234 (FH, C, D, A, B, correct[ 15], 16, 0x1fa27cf8);
+ OP234 (FH, B, C, D, A, correct[ 2], 23, 0xc4ac5665);
+
+ /* Round 4. */
+ OP234 (FI, A, B, C, D, correct[ 0], 6, 0xf4292244);
+ OP234 (FI, D, A, B, C, correct[ 7], 10, 0x432aff97);
+ OP234 (FI, C, D, A, B, correct[ 14], 15, 0xab9423a7);
+ OP234 (FI, B, C, D, A, correct[ 5], 21, 0xfc93a039);
+ OP234 (FI, A, B, C, D, correct[ 12], 6, 0x655b59c3);
+ OP234 (FI, D, A, B, C, correct[ 3], 10, 0x8f0ccc92);
+ OP234 (FI, C, D, A, B, correct[ 10], 15, 0xffeff47d);
+ OP234 (FI, B, C, D, A, correct[ 1], 21, 0x85845dd1);
+ OP234 (FI, A, B, C, D, correct[ 8], 6, 0x6fa87e4f);
+ OP234 (FI, D, A, B, C, correct[ 15], 10, 0xfe2ce6e0);
+ OP234 (FI, C, D, A, B, correct[ 6], 15, 0xa3014314);
+ OP234 (FI, B, C, D, A, correct[ 13], 21, 0x4e0811a1);
+ OP234 (FI, A, B, C, D, correct[ 4], 6, 0xf7537e82);
+ OP234 (FI, D, A, B, C, correct[ 11], 10, 0xbd3af235);
+ OP234 (FI, C, D, A, B, correct[ 2], 15, 0x2ad7d2bb);
+ OP234 (FI, B, C, D, A, correct[ 9], 21, 0xeb86d391);
+
+ /* Add the starting values of the context. */
+ A += A_save;
+ B += B_save;
+ C += C_save;
+ D += D_save;
+ }
+
+ /* Put checksum in context given as argument. */
+ md5_p->md_A = A;
+ md5_p->md_B = B;
+ md5_p->md_C = C;
+ md5_p->md_D = D;
}
/*
@@ -232,25 +231,25 @@ static void process_block(md5_t *md5_p, const void *buffer,
*
* result - A 16 byte buffer that will contain the MD5 signature.
*/
-static void md5_get_result(const md5_t *md5_p, void *result)
+static void md5_get_result (const md5_t *md5_p, void *result)
{
- md5_uint32 hold;
- void *res_p = result;
+ md5_uint32 hold;
+ void *res_p = result;
- hold = SWAP(md5_p->md_A);
- memcpy(res_p, &hold, sizeof(md5_uint32));
- res_p = (char *)res_p + sizeof(md5_uint32);
+ hold = SWAP (md5_p->md_A);
+ memcpy (res_p, &hold, sizeof(md5_uint32));
+ res_p = (char*)res_p + sizeof(md5_uint32);
- hold = SWAP(md5_p->md_B);
- memcpy(res_p, &hold, sizeof(md5_uint32));
- res_p = (char *)res_p + sizeof(md5_uint32);
+ hold = SWAP (md5_p->md_B);
+ memcpy (res_p, &hold, sizeof(md5_uint32));
+ res_p = (char*)res_p + sizeof(md5_uint32);
- hold = SWAP(md5_p->md_C);
- memcpy(res_p, &hold, sizeof(md5_uint32));
- res_p = (char *)res_p + sizeof(md5_uint32);
+ hold = SWAP (md5_p->md_C);
+ memcpy (res_p, &hold, sizeof(md5_uint32));
+ res_p = (char*)res_p + sizeof(md5_uint32);
- hold = SWAP(md5_p->md_D);
- memcpy(res_p, &hold, sizeof(md5_uint32));
+ hold = SWAP (md5_p->md_D);
+ memcpy (res_p, &hold, sizeof(md5_uint32));
}
/***************************** exported routines *****************************/
@@ -275,16 +274,16 @@ static void md5_get_result(const md5_t *md5_p, void *result)
*
* md5_p - Pointer to md5 structure that we are initializing.
*/
-void md5_init(md5_t *md5_p)
+void md5_init (md5_t *md5_p)
{
- md5_p->md_A = 0x67452301;
- md5_p->md_B = 0xefcdab89;
- md5_p->md_C = 0x98badcfe;
- md5_p->md_D = 0x10325476;
-
- md5_p->md_total[0] = 0;
- md5_p->md_total[1] = 0;
- md5_p->md_buf_len = 0;
+ md5_p->md_A = 0x67452301;
+ md5_p->md_B = 0xefcdab89;
+ md5_p->md_C = 0x98badcfe;
+ md5_p->md_D = 0x10325476;
+
+ md5_p->md_total[0] = 0;
+ md5_p->md_total[1] = 0;
+ md5_p->md_buf_len = 0;
}
/*
@@ -310,55 +309,54 @@ void md5_init(md5_t *md5_p)
*
* buf_len - The length of the buffer.
*/
-void md5_process(md5_t *md5_p, const void *buffer,
- const unsigned int buf_len)
+void md5_process (md5_t *md5_p, const void *buffer,
+ const unsigned int buf_len)
{
- unsigned int len = buf_len;
- unsigned int in_block, add;
-
- /*
- * When we already have some bytes in our internal buffer, copy some
- * from the user to fill the block.
- */
- if (md5_p->md_buf_len > 0) {
-
- in_block = md5_p->md_buf_len;
- if (in_block + len > sizeof(md5_p->md_buffer)) {
- add = sizeof(md5_p->md_buffer) - in_block;
- }
- else {
- add = len;
- }
-
- memcpy (md5_p->md_buffer + in_block, buffer, add);
- md5_p->md_buf_len += add;
- in_block += add;
-
- if (in_block > MD5_BLOCK_SIZE) {
- process_block (md5_p, md5_p->md_buffer, in_block & ~BLOCK_SIZE_MASK);
- /* the regions in the following copy operation will not overlap. */
- memcpy (md5_p->md_buffer,
- md5_p->md_buffer + (in_block & ~BLOCK_SIZE_MASK),
- in_block & BLOCK_SIZE_MASK);
- md5_p->md_buf_len = in_block & BLOCK_SIZE_MASK;
- }
-
- buffer = (const char *)buffer + add;
- len -= add;
- }
-
- /* process available complete blocks right from the user buffer */
- if (len > MD5_BLOCK_SIZE) {
- process_block (md5_p, buffer, len & ~BLOCK_SIZE_MASK);
- buffer = (const char *) buffer + (len & ~BLOCK_SIZE_MASK);
- len &= BLOCK_SIZE_MASK;
- }
-
- /* copy remaining bytes into the internal buffer */
- if (len > 0) {
- memcpy (md5_p->md_buffer, buffer, len);
- md5_p->md_buf_len = len;
- }
+ unsigned int len = buf_len;
+ unsigned int in_block, add;
+
+ /*
+ * When we already have some bytes in our internal buffer, copy some
+ * from the user to fill the block.
+ */
+ if (md5_p->md_buf_len > 0) {
+
+ in_block = md5_p->md_buf_len;
+ if (in_block + len > sizeof(md5_p->md_buffer)) {
+ add = sizeof(md5_p->md_buffer) - in_block;
+ } else {
+ add = len;
+ }
+
+ memcpy (md5_p->md_buffer + in_block, buffer, add);
+ md5_p->md_buf_len += add;
+ in_block += add;
+
+ if (in_block > MD5_BLOCK_SIZE) {
+ process_block (md5_p, md5_p->md_buffer, in_block & ~BLOCK_SIZE_MASK);
+ /* the regions in the following copy operation will not overlap. */
+ memcpy (md5_p->md_buffer,
+ md5_p->md_buffer + (in_block & ~BLOCK_SIZE_MASK),
+ in_block & BLOCK_SIZE_MASK);
+ md5_p->md_buf_len = in_block & BLOCK_SIZE_MASK;
+ }
+
+ buffer = (const char*)buffer + add;
+ len -= add;
+ }
+
+ /* process available complete blocks right from the user buffer */
+ if (len > MD5_BLOCK_SIZE) {
+ process_block (md5_p, buffer, len & ~BLOCK_SIZE_MASK);
+ buffer = (const char*)buffer + (len & ~BLOCK_SIZE_MASK);
+ len &= BLOCK_SIZE_MASK;
+ }
+
+ /* copy remaining bytes into the internal buffer */
+ if (len > 0) {
+ memcpy (md5_p->md_buffer, buffer, len);
+ md5_p->md_buf_len = len;
+ }
}
/*
@@ -380,63 +378,62 @@ void md5_process(md5_t *md5_p, const void *buffer,
*
* signature - A 16 byte buffer that will contain the MD5 signature.
*/
-void md5_finish(md5_t *md5_p, void *signature)
+void md5_finish (md5_t *md5_p, void *signature)
{
- md5_uint32 bytes, hold;
- int pad;
-
- /* take yet unprocessed bytes into account */
- bytes = md5_p->md_buf_len;
-
- /*
- * Count remaining bytes. Modified to do this to better avoid
- * overflows in the lower word -- Gray 10/97.
- */
- if (md5_p->md_total[0] > MAX_MD5_UINT32 - bytes) {
- md5_p->md_total[1]++;
- md5_p->md_total[0] -= (MAX_MD5_UINT32 - bytes);
- }
- else {
- md5_p->md_total[0] += bytes;
- }
-
- /*
- * Pad the buffer to the next MD5_BLOCK-byte boundary. (RFC 1321,
- * 3.1: Step 1). We need enough room for two size words and the
- * bytes left in the buffer. For some reason even if we are equal
- * to the block-size, we add an addition block of pad bytes.
- */
- pad = MD5_BLOCK_SIZE - (sizeof(md5_uint32) * 2) - bytes;
- if (pad <= 0) {
- pad += MD5_BLOCK_SIZE;
- }
-
- /*
- * Modified from a fixed array to this assignment and memset to be
- * more flexible with block-sizes -- Gray 10/97.
- */
- if (pad > 0) {
- /* some sort of padding start byte */
- md5_p->md_buffer[bytes] = (unsigned char)0x80;
- if (pad > 1) {
- memset (md5_p->md_buffer + bytes + 1, 0, pad - 1);
- }
- bytes += pad;
- }
-
- /* put the 64-bit file length in _bits_ (i.e. *8) at the end of the buffer */
- hold = SWAP(md5_p->md_total[0] << 3);
- memcpy(md5_p->md_buffer + bytes, &hold, sizeof(md5_uint32));
- bytes += sizeof(md5_uint32);
-
- /* shift the high word over by 3 and add in the top 3 bits from the low */
- hold = SWAP((md5_p->md_total[1] << 3) | (md5_p->md_total[0] >> 29));
- memcpy(md5_p->md_buffer + bytes, &hold, sizeof(md5_uint32));
- bytes += sizeof(md5_uint32);
-
- /* process last bytes, the padding chars, and size words */
- process_block(md5_p, md5_p->md_buffer, bytes);
- md5_get_result(md5_p, signature);
+ md5_uint32 bytes, hold;
+ int pad;
+
+ /* take yet unprocessed bytes into account */
+ bytes = md5_p->md_buf_len;
+
+ /*
+ * Count remaining bytes. Modified to do this to better avoid
+ * overflows in the lower word -- Gray 10/97.
+ */
+ if (md5_p->md_total[0] > MAX_MD5_UINT32 - bytes) {
+ md5_p->md_total[1]++;
+ md5_p->md_total[0] -= (MAX_MD5_UINT32 - bytes);
+ } else {
+ md5_p->md_total[0] += bytes;
+ }
+
+ /*
+ * Pad the buffer to the next MD5_BLOCK-byte boundary. (RFC 1321,
+ * 3.1: Step 1). We need enough room for two size words and the
+ * bytes left in the buffer. For some reason even if we are equal
+ * to the block-size, we add an addition block of pad bytes.
+ */
+ pad = MD5_BLOCK_SIZE - (sizeof(md5_uint32) * 2) - bytes;
+ if (pad <= 0) {
+ pad += MD5_BLOCK_SIZE;
+ }
+
+ /*
+ * Modified from a fixed array to this assignment and memset to be
+ * more flexible with block-sizes -- Gray 10/97.
+ */
+ if (pad > 0) {
+ /* some sort of padding start byte */
+ md5_p->md_buffer[bytes] = (unsigned char)0x80;
+ if (pad > 1) {
+ memset (md5_p->md_buffer + bytes + 1, 0, pad - 1);
+ }
+ bytes += pad;
+ }
+
+ /* put the 64-bit file length in _bits_ (i.e. *8) at the end of the buffer */
+ hold = SWAP (md5_p->md_total[0] << 3);
+ memcpy (md5_p->md_buffer + bytes, &hold, sizeof(md5_uint32));
+ bytes += sizeof(md5_uint32);
+
+ /* shift the high word over by 3 and add in the top 3 bits from the low */
+ hold = SWAP ((md5_p->md_total[1] << 3) | (md5_p->md_total[0] >> 29));
+ memcpy (md5_p->md_buffer + bytes, &hold, sizeof(md5_uint32));
+ bytes += sizeof(md5_uint32);
+
+ /* process last bytes, the padding chars, and size words */
+ process_block (md5_p, md5_p->md_buffer, bytes);
+ md5_get_result (md5_p, signature);
}
/*
@@ -460,19 +457,19 @@ void md5_finish(md5_t *md5_p, void *signature)
*
* signature - A 16 byte buffer that will contain the MD5 signature.
*/
-void md5_buffer(const char *buffer, const unsigned int buf_len,
- void *signature)
+void md5_buffer (const char *buffer, const unsigned int buf_len,
+ void *signature)
{
- md5_t md5;
+ md5_t md5;
- /* initialize the computation context */
- md5_init(&md5);
+ /* initialize the computation context */
+ md5_init (&md5);
- /* process whole buffer but last buf_len % MD5_BLOCK bytes */
- md5_process(&md5, buffer, buf_len);
+ /* process whole buffer but last buf_len % MD5_BLOCK bytes */
+ md5_process (&md5, buffer, buf_len);
- /* put result in desired memory area */
- md5_finish(&md5, signature);
+ /* put result in desired memory area */
+ md5_finish (&md5, signature);
}
/*
@@ -496,31 +493,31 @@ void md5_buffer(const char *buffer, const unsigned int buf_len,
*
* str_len - the length of the string.
*/
-void md5_sig_to_string(void *signature, char *str, const int str_len)
+void md5_sig_to_string (void *signature, char *str, const int str_len)
{
- unsigned char *sig_p;
- char *str_p, *max_p;
- unsigned int high, low;
-
- str_p = str;
- max_p = str + str_len;
-
- for (sig_p = (unsigned char *)signature;
- sig_p < (unsigned char *)signature + MD5_SIZE;
- sig_p++) {
- high = *sig_p / 16;
- low = *sig_p % 16;
- /* account for 2 chars */
- if (str_p + 1 >= max_p) {
- break;
- }
- *str_p++ = HEX_STRING[high];
- *str_p++ = HEX_STRING[low];
- }
- /* account for 2 chars */
- if (str_p < max_p) {
- *str_p++ = '\0';
- }
+ unsigned char *sig_p;
+ char *str_p, *max_p;
+ unsigned int high, low;
+
+ str_p = str;
+ max_p = str + str_len;
+
+ for (sig_p = (unsigned char*)signature;
+ sig_p < (unsigned char*)signature + MD5_SIZE;
+ sig_p++) {
+ high = *sig_p / 16;
+ low = *sig_p % 16;
+ /* account for 2 chars */
+ if (str_p + 1 >= max_p) {
+ break;
+ }
+ *str_p++ = HEX_STRING[high];
+ *str_p++ = HEX_STRING[low];
+ }
+ /* account for 2 chars */
+ if (str_p < max_p) {
+ *str_p++ = '\0';
+ }
}
/*
@@ -542,20 +539,20 @@ void md5_sig_to_string(void *signature, char *str, const int str_len)
* str - A string of charactes which _must_ be at least 32 bytes long (2
* characters per MD5 byte).
*/
-void md5_sig_from_string(void *signature, const char *str)
+void md5_sig_from_string (void *signature, const char *str)
{
- unsigned char *sig_p;
- const char *str_p;
- char *hex;
- unsigned int high, low, val;
-
- hex = HEX_STRING;
- sig_p = signature;
-
- for (str_p = str; str_p < str + MD5_SIZE * 2; str_p += 2) {
- high = strchr(hex, *str_p) - hex;
- low = strchr(hex, *(str_p + 1)) - hex;
- val = high * 16 + low;
- *sig_p++ = val;
- }
+ unsigned char *sig_p;
+ const char *str_p;
+ char *hex;
+ unsigned int high, low, val;
+
+ hex = HEX_STRING;
+ sig_p = signature;
+
+ for (str_p = str; str_p < str + MD5_SIZE * 2; str_p += 2) {
+ high = strchr (hex, *str_p) - hex;
+ low = strchr (hex, *(str_p + 1)) - hex;
+ val = high * 16 + low;
+ *sig_p++ = val;
+ }
}
diff --git a/jackd/md5.h b/jackd/md5.h
index de5ddf3..358c6ea 100644
--- a/jackd/md5.h
+++ b/jackd/md5.h
@@ -36,34 +36,33 @@
* external programs only. The MD5 routines themselves reference the
* signature as 4 unsigned 32-bit integers.
*/
-#define MD5_SIZE 16
+#define MD5_SIZE 16
/*
* NOTE: the following is assumed to generate a 32-bit unsigned data
* type.
*/
-typedef unsigned int md5_uint32;
-#define MAX_MD5_UINT32 ((md5_uint32)4294967295U)
+typedef unsigned int md5_uint32;
+#define MAX_MD5_UINT32 ((md5_uint32)4294967295U)
/*
* The MD5 algorithm works on blocks of characters of 64 bytes. This
* is an internal value only and is not necessary for external use.
*/
-#define MD5_BLOCK_SIZE 64
+#define MD5_BLOCK_SIZE 64
/*
* Structure to save state of computation between the single steps.
*/
-typedef struct
-{
- md5_uint32 md_A; /* accumulater 1 */
- md5_uint32 md_B; /* accumulater 2 */
- md5_uint32 md_C; /* accumulater 3 */
- md5_uint32 md_D; /* accumulater 4 */
-
- md5_uint32 md_total[2]; /* totaling storage */
- md5_uint32 md_buf_len; /* length of the storage buffer */
- char md_buffer[MD5_BLOCK_SIZE * 2]; /* character storage buffer */
+typedef struct {
+ md5_uint32 md_A; /* accumulater 1 */
+ md5_uint32 md_B; /* accumulater 2 */
+ md5_uint32 md_C; /* accumulater 3 */
+ md5_uint32 md_D; /* accumulater 4 */
+
+ md5_uint32 md_total[2]; /* totaling storage */
+ md5_uint32 md_buf_len; /* length of the storage buffer */
+ char md_buffer[MD5_BLOCK_SIZE * 2]; /* character storage buffer */
} md5_t;
/*<<<<<<<<<< The below prototypes are auto-generated by fillproto */
@@ -89,7 +88,7 @@ typedef struct
* md5_p - Pointer to md5 structure that we are initializing.
*/
extern
-void md5_init(md5_t *md5_p);
+void md5_init(md5_t *md5_p);
/*
* md5_process
@@ -115,7 +114,7 @@ void md5_init(md5_t *md5_p);
* buf_len - The length of the buffer.
*/
extern
-void md5_process(md5_t *md5_p, const void *buffer,
+void md5_process(md5_t *md5_p, const void *buffer,
const unsigned int buf_len);
/*
@@ -138,7 +137,7 @@ void md5_process(md5_t *md5_p, const void *buffer,
* signature - A 16 byte buffer that will contain the MD5 signature.
*/
extern
-void md5_finish(md5_t *md5_p, void *signature);
+void md5_finish(md5_t *md5_p, void *signature);
/*
* md5_buffer
@@ -162,7 +161,7 @@ void md5_finish(md5_t *md5_p, void *signature);
* signature - A 16 byte buffer that will contain the MD5 signature.
*/
extern
-void md5_buffer(const char *buffer, const unsigned int buf_len,
+void md5_buffer(const char *buffer, const unsigned int buf_len,
void *signature);
/*
@@ -187,7 +186,7 @@ void md5_buffer(const char *buffer, const unsigned int buf_len,
* str_len - the length of the string.
*/
extern
-void md5_sig_to_string(void *signature, char *str, const int str_len);
+void md5_sig_to_string(void *signature, char *str, const int str_len);
/*
* md5_sig_from_string
@@ -209,7 +208,7 @@ void md5_sig_to_string(void *signature, char *str, const int str_len);
* characters per MD5 byte).
*/
extern
-void md5_sig_from_string(void *signature, const char *str);
+void md5_sig_from_string(void *signature, const char *str);
/*<<<<<<<<<< This is end of the auto-generated output from fillproto. */
diff --git a/jackd/md5_loc.h b/jackd/md5_loc.h
index cc1c085..e1b4790 100644
--- a/jackd/md5_loc.h
+++ b/jackd/md5_loc.h
@@ -29,8 +29,8 @@
#ifndef __MD5_LOC_H__
#define __MD5_LOC_H__
-#define HEX_STRING "0123456789abcdef" /* to convert to hex */
-#define BLOCK_SIZE_MASK (MD5_BLOCK_SIZE - 1)
+#define HEX_STRING "0123456789abcdef" /* to convert to hex */
+#define BLOCK_SIZE_MASK (MD5_BLOCK_SIZE - 1)
#include <config.h>
@@ -44,11 +44,11 @@
* big endian - big is better
*/
#define SWAP(n) \
- (((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24))
+ (((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24))
#else
/*
- + * little endian
- + */
+ + * little endian
+ + */
#define SWAP(n) (n)
#endif
@@ -59,17 +59,17 @@
* implementation).
*/
/* #define FF(b, c, d) ((b & c) | (~b & d)) */
-#define FF(b, c, d) (d ^ (b & (c ^ d)))
-#define FG(b, c, d) FF(d, b, c)
-#define FH(b, c, d) (b ^ c ^ d)
-#define FI(b, c, d) (c ^ (b | ~d))
+#define FF(b, c, d) (d ^ (b & (c ^ d)))
+#define FG(b, c, d) FF (d, b, c)
+#define FH(b, c, d) (b ^ c ^ d)
+#define FI(b, c, d) (c ^ (b | ~d))
/*
* It is unfortunate that C does not provide an operator for cyclic
* rotation. Hope the C compiler is smart enough. -- Modified to
* remove the w = at the front - Gray 2/97
*/
-#define CYCLIC(w, s) ((w << s) | (w >> (32 - s)))
+#define CYCLIC(w, s) ((w << s) | (w >> (32 - s)))
/*
* First Round: using the given function, the context and a constant
@@ -81,15 +81,15 @@
* fix the handling of unaligned buffer spaces - Gray 7/97
*/
#define OP1(a, b, c, d, b_p, c_p, s, T) \
- do { \
- memcpy(c_p, b_p, sizeof(md5_uint32)); \
- *c_p = SWAP(*c_p); \
- a += FF (b, c, d) + *c_p + T; \
- a = CYCLIC (a, s); \
- a += b; \
- b_p = (char *)b_p + sizeof(md5_uint32); \
- c_p++; \
- } while (0)
+ do { \
+ memcpy (c_p, b_p, sizeof(md5_uint32)); \
+ *c_p = SWAP (*c_p); \
+ a += FF (b, c, d) + *c_p + T; \
+ a = CYCLIC (a, s); \
+ a += b; \
+ b_p = (char*)b_p + sizeof(md5_uint32); \
+ c_p++; \
+ } while (0)
/*
* Second to Fourth Round: we have the possibly swapped words in
@@ -97,10 +97,10 @@
* argument specifying the function to use.
*/
#define OP234(FUNC, a, b, c, d, k, s, T) \
- do { \
- a += FUNC (b, c, d) + k + T; \
- a = CYCLIC (a, s); \
- a += b; \
- } while (0)
+ do { \
+ a += FUNC (b, c, d) + k + T; \
+ a = CYCLIC (a, s); \
+ a += b; \
+ } while (0)
#endif /* ! __MD5_LOC_H__ */
diff --git a/jackd/transengine.c b/jackd/transengine.c
index 8c84639..29c9df6 100644
--- a/jackd/transengine.c
+++ b/jackd/transengine.c
@@ -3,21 +3,21 @@
Copyright (C) 2001-2003 Paul Davis
Copyright (C) 2003 Jack O'Quin
-
+
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
Lesser 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 <config.h>
#include <errno.h>
@@ -70,7 +70,7 @@ jack_sync_poll_deactivate (jack_engine_t *engine,
}
client->control->active_slowsync = 0;
engine->control->sync_clients--;
- assert(engine->control->sync_clients >= 0);
+ assert (engine->control->sync_clients >= 0);
}
/* stop polling all the slow-sync clients
@@ -80,11 +80,11 @@ static void
jack_sync_poll_stop (jack_engine_t *engine)
{
JSList *node;
- long poll_count = 0; /* count sync_poll clients */
+ long poll_count = 0; /* count sync_poll clients */
for (node = engine->clients; node; node = jack_slist_next (node)) {
jack_client_internal_t *client =
- (jack_client_internal_t *) node->data;
+ (jack_client_internal_t*)node->data;
if (client->control->active_slowsync &&
client->control->sync_poll) {
client->control->sync_poll = 0;
@@ -98,7 +98,7 @@ jack_sync_poll_stop (jack_engine_t *engine)
"sync poll halted with %" PRIu32
" clients and %8.6f secs remaining",
engine->control->sync_remain,
- (double) (engine->control->sync_time_left / 1000000.0));
+ (double)(engine->control->sync_time_left / 1000000.0));
engine->control->sync_remain = 0;
engine->control->sync_time_left = 0;
}
@@ -110,11 +110,11 @@ static void
jack_sync_poll_start (jack_engine_t *engine)
{
JSList *node;
- long sync_count = 0; /* count slow-sync clients */
+ long sync_count = 0; /* count slow-sync clients */
for (node = engine->clients; node; node = jack_slist_next (node)) {
jack_client_internal_t *client =
- (jack_client_internal_t *) node->data;
+ (jack_client_internal_t*)node->data;
if (client->control->active_slowsync) {
client->control->sync_poll = 1;
sync_count++;
@@ -127,7 +127,7 @@ jack_sync_poll_start (jack_engine_t *engine)
engine->control->sync_time_left = engine->control->sync_timeout;
VERBOSE (engine, "transport Starting, sync poll of %" PRIu32
" clients for %8.6f secs", engine->control->sync_remain,
- (double) (engine->control->sync_time_left / 1000000.0));
+ (double)(engine->control->sync_time_left / 1000000.0));
}
/* check for sync timeout */
@@ -136,7 +136,7 @@ jack_sync_timeout (jack_engine_t *engine)
{
jack_control_t *ectl = engine->control;
jack_time_t buf_usecs =
- ((ectl->buffer_size * (jack_time_t) 1000000) /
+ ((ectl->buffer_size * (jack_time_t)1000000) /
ectl->current_time.frame_rate);
/* compare carefully, jack_time_t is unsigned */
@@ -184,8 +184,9 @@ jack_timebase_reset (jack_engine_t *engine, jack_uuid_t client_id)
VERBOSE (engine, "%s resigned as timebase master",
client->control->name);
ret = 0;
- } else
+ } else {
ret = EINVAL;
+ }
jack_unlock_graph (engine);
@@ -205,7 +206,7 @@ jack_timebase_set (jack_engine_t *engine,
client = jack_client_internal_by_id (engine, client_id);
if (client == NULL) {
- VERBOSE (engine, " %" PRIu32 " no longer exists", client_id);
+ VERBOSE (engine, " %" PRIu32 " no longer exists", client_id);
jack_unlock_graph (engine);
return EINVAL;
}
@@ -219,9 +220,10 @@ jack_timebase_set (jack_engine_t *engine,
VERBOSE (engine, " %s is already the master",
engine->timebase_client->control->name);
ret = EBUSY;
- } else
+ } else {
VERBOSE (engine, " %s was already timebase master:",
client->control->name);
+ }
} else {
@@ -231,8 +233,9 @@ jack_timebase_set (jack_engine_t *engine,
}
engine->timebase_client = client;
client->control->is_timebase = 1;
- if (client->control->active)
+ if (client->control->active) {
client->control->timebase_new = 1;
+ }
VERBOSE (engine, "new timebase master: %s",
client->control->name);
}
@@ -249,7 +252,7 @@ void
jack_transport_activate (jack_engine_t *engine, jack_client_internal_t *client)
{
if (client->control->is_slowsync) {
- assert(!client->control->active_slowsync);
+ assert (!client->control->active_slowsync);
client->control->active_slowsync = 1;
engine->control->sync_clients++;
jack_sync_poll_new (engine, client);
@@ -274,13 +277,13 @@ jack_transport_init (jack_engine_t *engine)
memset (&ectl->pending_time, 0, sizeof(ectl->pending_time));
memset (&ectl->request_time, 0, sizeof(ectl->request_time));
ectl->prev_request = 0;
- ectl->seq_number = 1; /* can't start at 0 */
+ ectl->seq_number = 1; /* can't start at 0 */
ectl->new_pos = 0;
ectl->pending_pos = 0;
ectl->pending_frame = 0;
ectl->sync_clients = 0;
ectl->sync_remain = 0;
- ectl->sync_timeout = 2000000; /* 2 second default */
+ ectl->sync_timeout = 2000000; /* 2 second default */
ectl->sync_time_left = 0;
}
@@ -303,15 +306,17 @@ jack_transport_client_exit (jack_engine_t *engine,
}
if (client->control->is_slowsync) {
- if (client->control->active_slowsync)
+ if (client->control->active_slowsync) {
jack_sync_poll_deactivate (engine, client);
- if (client->control->dead)
+ }
+ if (client->control->dead) {
client->control->is_slowsync = 0;
+ }
}
}
/* when a new client is being created */
-void
+void
jack_transport_client_new (jack_client_internal_t *client)
{
client->control->is_timebase = 0;
@@ -320,16 +325,16 @@ jack_transport_client_new (jack_client_internal_t *client)
client->control->active_slowsync = 0;
client->control->sync_poll = 0;
client->control->sync_new = 0;
-
+
client->control->sync_cb_cbset = FALSE;
client->control->timebase_cb_cbset = FALSE;
#if 0
if (client->control->type != ClientExternal) {
- client->sync_cb = NULL;
- client->sync_arg = NULL;
- client->timebase_cb = NULL;
- client->timebase_arg = NULL;
+ client->sync_cb = NULL;
+ client->sync_arg = NULL;
+ client->timebase_cb = NULL;
+ client->timebase_arg = NULL;
}
#endif
}
@@ -347,12 +352,14 @@ jack_transport_client_reset_sync (jack_engine_t *engine,
client = jack_client_internal_by_id (engine, client_id);
if (client && (client->control->is_slowsync)) {
- if (client->control->active_slowsync)
+ if (client->control->active_slowsync) {
jack_sync_poll_deactivate (engine, client);
+ }
client->control->is_slowsync = 0;
ret = 0;
- } else
+ } else {
ret = EINVAL;
+ }
jack_unlock_graph (engine);
@@ -393,8 +400,9 @@ jack_transport_client_set_sync (jack_engine_t *engine,
jack_sync_poll_new (engine, client);
}
ret = 0;
- } else
+ } else {
ret = EINVAL;
+ }
DEBUG ("unlocking write lock for set_sync");
jack_unlock_graph (engine);
@@ -411,10 +419,11 @@ void
jack_transport_cycle_end (jack_engine_t *engine)
{
jack_control_t *ectl = engine->control;
- transport_command_t cmd; /* latest transport command */
+ transport_command_t cmd; /* latest transport command */
/* Promote pending_time to current_time. Maintain the usecs,
* frame_rate and frame values, clients may not set them. */
+
ectl->pending_time.usecs = ectl->current_time.usecs;
ectl->pending_time.frame_rate = ectl->current_time.frame_rate;
ectl->pending_time.frame = ectl->pending_frame;
@@ -424,11 +433,11 @@ jack_transport_cycle_end (jack_engine_t *engine)
/* check sync results from previous cycle */
if (ectl->transport_state == JackTransportStarting) {
if ((ectl->sync_remain == 0) ||
- (jack_sync_timeout(engine))) {
+ (jack_sync_timeout (engine))) {
ectl->transport_state = JackTransportRolling;
VERBOSE (engine, "transport Rolling, %8.6f sec"
" left for poll",
- (double) (ectl->sync_time_left / 1000000.0));
+ (double)(ectl->sync_time_left / 1000000.0));
}
}
@@ -437,9 +446,10 @@ jack_transport_cycle_end (jack_engine_t *engine)
if (cmd != ectl->previous_cmd) {
ectl->previous_cmd = cmd;
VERBOSE (engine, "transport command: %s",
- (cmd == TransportCommandStart? "START": "STOP"));
- } else
+ (cmd == TransportCommandStart ? "START" : "STOP"));
+ } else {
cmd = TransportCommandNone;
+ }
/* state transition switch */
@@ -449,7 +459,7 @@ jack_transport_cycle_end (jack_engine_t *engine)
if (cmd == TransportCommandStart) {
if (ectl->sync_clients) {
ectl->transport_state = JackTransportStarting;
- jack_sync_poll_start(engine);
+ jack_sync_poll_start (engine);
} else {
ectl->transport_state = JackTransportRolling;
VERBOSE (engine, "transport Rolling");
@@ -461,12 +471,13 @@ jack_transport_cycle_end (jack_engine_t *engine)
if (cmd == TransportCommandStop) {
ectl->transport_state = JackTransportStopped;
VERBOSE (engine, "transport Stopped");
- if (ectl->sync_remain)
- jack_sync_poll_stop(engine);
+ if (ectl->sync_remain) {
+ jack_sync_poll_stop (engine);
+ }
} else if (ectl->new_pos) {
if (ectl->sync_clients) {
ectl->transport_state = JackTransportStarting;
- jack_sync_poll_start(engine);
+ jack_sync_poll_start (engine);
} else {
ectl->transport_state = JackTransportRolling;
VERBOSE (engine, "transport Rolling");
@@ -478,12 +489,13 @@ jack_transport_cycle_end (jack_engine_t *engine)
if (cmd == TransportCommandStop) {
ectl->transport_state = JackTransportStopped;
VERBOSE (engine, "transport Stopped");
- if (ectl->sync_remain)
- jack_sync_poll_stop(engine);
+ if (ectl->sync_remain) {
+ jack_sync_poll_stop (engine);
+ }
} else if (ectl->new_pos) {
if (ectl->sync_clients) {
ectl->transport_state = JackTransportStarting;
- jack_sync_poll_start(engine);
+ jack_sync_poll_start (engine);
}
}
break;
@@ -497,15 +509,15 @@ jack_transport_cycle_end (jack_engine_t *engine)
if (ectl->transport_state == JackTransportRolling) {
ectl->pending_time.frame =
ectl->current_time.frame + ectl->buffer_size;
- }
+ }
/* See if an asynchronous position request arrived during the
* last cycle. The request_time could change during the
* guarded copy. If so, we use the newest request. */
ectl->pending_pos = 0;
if (ectl->request_time.unique_1 != ectl->prev_request) {
- jack_transport_copy_position(&ectl->request_time,
- &ectl->pending_time);
+ jack_transport_copy_position (&ectl->request_time,
+ &ectl->pending_time);
VERBOSE (engine, "new transport position: %" PRIu32
", id=0x%" PRIx64, ectl->pending_time.frame,
ectl->pending_time.unique_1);
@@ -518,19 +530,19 @@ jack_transport_cycle_end (jack_engine_t *engine)
}
/* driver callback at start of cycle */
-void
+void
jack_transport_cycle_start (jack_engine_t *engine, jack_time_t time)
{
engine->control->current_time.usecs = time;
}
/* on SetSyncTimeout request */
-int
+int
jack_transport_set_sync_timeout (jack_engine_t *engine,
jack_time_t usecs)
{
engine->control->sync_timeout = usecs;
VERBOSE (engine, "new sync timeout: %8.6f secs",
- (double) (usecs / 1000000.0));
+ (double)(usecs / 1000000.0));
return 0;
}
diff --git a/jackd/transengine.h b/jackd/transengine.h
index b433c47..44c7026 100644
--- a/jackd/transengine.h
+++ b/jackd/transengine.h
@@ -2,7 +2,7 @@
Internal interfaces for JACK transport engine.
Copyright (C) 2003 Jack O'Quin
-
+
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
@@ -16,24 +16,24 @@
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.
-*/
+ */
-int jack_set_sample_rate (jack_engine_t *engine, jack_nframes_t nframes);
-int jack_timebase_reset (jack_engine_t *engine,
- jack_uuid_t client_id);
-int jack_timebase_set (jack_engine_t *engine,
- jack_uuid_t client_id, int conditional);
-void jack_transport_activate (jack_engine_t *engine,
- jack_client_internal_t *client);
-void jack_transport_init (jack_engine_t *engine);
-void jack_transport_client_exit (jack_engine_t *engine,
- jack_client_internal_t *client);
-void jack_transport_client_new (jack_client_internal_t *client);
-int jack_transport_client_reset_sync (jack_engine_t *engine,
- jack_uuid_t client_id);
-int jack_transport_client_set_sync (jack_engine_t *engine,
- jack_uuid_t client_id);
-void jack_transport_cycle_end (jack_engine_t *engine);
-void jack_transport_cycle_start(jack_engine_t *engine, jack_time_t time);
-int jack_transport_set_sync_timeout (jack_engine_t *engine,
- jack_time_t usecs);
+int jack_set_sample_rate(jack_engine_t *engine, jack_nframes_t nframes);
+int jack_timebase_reset(jack_engine_t *engine,
+ jack_uuid_t client_id);
+int jack_timebase_set(jack_engine_t *engine,
+ jack_uuid_t client_id, int conditional);
+void jack_transport_activate(jack_engine_t *engine,
+ jack_client_internal_t *client);
+void jack_transport_init(jack_engine_t *engine);
+void jack_transport_client_exit(jack_engine_t *engine,
+ jack_client_internal_t *client);
+void jack_transport_client_new(jack_client_internal_t *client);
+int jack_transport_client_reset_sync(jack_engine_t *engine,
+ jack_uuid_t client_id);
+int jack_transport_client_set_sync(jack_engine_t *engine,
+ jack_uuid_t client_id);
+void jack_transport_cycle_end(jack_engine_t *engine);
+void jack_transport_cycle_start(jack_engine_t *engine, jack_time_t time);
+int jack_transport_set_sync_timeout(jack_engine_t *engine,
+ jack_time_t usecs);
diff --git a/libjack/client.c b/libjack/client.c
index 32e97d8..34e8b09 100644
--- a/libjack/client.c
+++ b/libjack/client.c
@@ -2,22 +2,22 @@
/*
Copyright (C) 2001-2003 Paul Davis
Copyright (C) 2005 Jussi Laako
-
+
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
+ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
+ */
#include <config.h>
@@ -67,10 +67,10 @@
#endif
static pthread_mutex_t client_lock;
-static pthread_cond_t client_ready;
+static pthread_cond_t client_ready;
static int
-jack_client_close_aux (jack_client_t *client);
+jack_client_close_aux(jack_client_t *client);
#define EVENT_POLL_INDEX 0
#define WAIT_POLL_INDEX 1
@@ -78,9 +78,9 @@ jack_client_close_aux (jack_client_t *client);
#define graph_wait_fd pollfd[WAIT_POLL_INDEX].fd
typedef struct {
- int status;
- struct _jack_client *client;
- const char *client_name;
+ int status;
+ struct _jack_client *client;
+ const char *client_name;
} client_info;
#ifdef USE_DYNSIMD
@@ -92,16 +92,19 @@ int cpu_type = 0;
static void
init_cpu ()
{
- cpu_type = ((have_3dnow() << 8) | have_sse());
+ cpu_type = ((have_3dnow () << 8) | have_sse ());
#if 0
- if (ARCH_X86_HAVE_3DNOW(cpu_type))
- jack_debug("Enhanced3DNow! detected");
- if (ARCH_X86_HAVE_SSE2(cpu_type))
- jack_debug("SSE2 detected");
- if ((!ARCH_X86_HAVE_3DNOW(cpu_type)) && (!ARCH_X86_HAVE_SSE2(cpu_type)))
- jack_debug("No supported SIMD instruction sets detected");
+ if (ARCH_X86_HAVE_3DNOW (cpu_type)) {
+ jack_debug ("Enhanced3DNow! detected");
+ }
+ if (ARCH_X86_HAVE_SSE2 (cpu_type)) {
+ jack_debug ("SSE2 detected");
+ }
+ if ((!ARCH_X86_HAVE_3DNOW (cpu_type)) && (!ARCH_X86_HAVE_SSE2 (cpu_type))) {
+ jack_debug ("No supported SIMD instruction sets detected");
+ }
#endif
- jack_port_set_funcs();
+ jack_port_set_funcs ();
}
#else /* ARCH_X86 */
@@ -109,12 +112,12 @@ init_cpu ()
static void
init_cpu ()
{
- jack_port_set_funcs();
+ jack_port_set_funcs ();
}
-#endif /* ARCH_X86 */
+#endif /* ARCH_X86 */
-#endif /* USE_DYNSIMD */
+#endif /* USE_DYNSIMD */
char *jack_tmpdir = DEFAULT_TMP_DIR;
@@ -123,7 +126,7 @@ jack_get_tmpdir ()
{
FILE* in;
size_t len;
- char buf[PATH_MAX+2]; /* allow tmpdir to live anywhere, plus newline, plus null */
+ char buf[PATH_MAX + 2]; /* allow tmpdir to live anywhere, plus newline, plus null */
char *pathenv;
char *pathcopy;
char *p;
@@ -132,7 +135,7 @@ jack_get_tmpdir ()
resetting PATH for the exec'd command. since we *want* to
use the user's PATH setting to locate jackd, we have to
do it ourselves.
- */
+ */
if ((pathenv = getenv ("PATH")) == 0) {
return -1;
@@ -146,14 +149,14 @@ jack_get_tmpdir ()
p = strtok (pathcopy, ":");
while (p) {
- char jackd[PATH_MAX+1];
- char command[PATH_MAX+4];
+ char jackd[PATH_MAX + 1];
+ char command[PATH_MAX + 4];
+
+ snprintf (jackd, sizeof(jackd), "%s/jackd", p);
- snprintf (jackd, sizeof (jackd), "%s/jackd", p);
-
if (access (jackd, X_OK) == 0) {
-
- snprintf (command, sizeof (command), "%s -l", jackd);
+
+ snprintf (command, sizeof(command), "%s -l", jackd);
if ((in = popen (command, "r")) != NULL) {
break;
@@ -169,7 +172,7 @@ jack_get_tmpdir ()
return -1;
}
- if (fgets (buf, sizeof (buf), in) == NULL) {
+ if (fgets (buf, sizeof(buf), in) == NULL) {
pclose (in);
free (pathcopy);
return -1;
@@ -177,28 +180,28 @@ jack_get_tmpdir ()
len = strlen (buf);
- if (buf[len-1] != '\n') {
+ if (buf[len - 1] != '\n') {
/* didn't get a whole line */
pclose (in);
free (pathcopy);
return -1;
}
- if ((jack_tmpdir = (char *) malloc (len)) == NULL) {
+ if ((jack_tmpdir = (char*)malloc (len)) == NULL) {
free (pathcopy);
return -1;
}
- memcpy (jack_tmpdir, buf, len-1);
- jack_tmpdir[len-1] = '\0';
-
+ memcpy (jack_tmpdir, buf, len - 1);
+ jack_tmpdir[len - 1] = '\0';
+
pclose (in);
free (pathcopy);
return 0;
}
-void
+void
jack_error (const char *fmt, ...)
{
va_list ap;
@@ -210,21 +213,21 @@ jack_error (const char *fmt, ...)
va_end (ap);
}
-void
+void
default_jack_error_callback (const char *desc)
{
- fprintf(stderr, "%s\n", desc);
- fflush(stderr);
+ fprintf (stderr, "%s\n", desc);
+ fflush (stderr);
}
-void
+void
default_jack_info_callback (const char *desc)
{
- fprintf(stdout, "%s\n", desc);
- fflush(stdout);
+ fprintf (stdout, "%s\n", desc);
+ fflush (stdout);
}
-void
+void
silent_jack_error_callback (const char *desc)
{
}
@@ -232,7 +235,7 @@ silent_jack_error_callback (const char *desc)
void (*jack_error_callback)(const char *desc) = &default_jack_error_callback;
void (*jack_info_callback)(const char *desc) = &default_jack_info_callback;
-void
+void
jack_info (const char *fmt, ...)
{
va_list ap;
@@ -248,45 +251,48 @@ static int
oop_client_deliver_request (void *ptr, jack_request_t *req)
{
int wok, rok;
- jack_client_t *client = (jack_client_t*) ptr;
-
- wok = (write (client->request_fd, req, sizeof (*req))
- == sizeof (*req));
-
- /* if necessary, add variable length key data after a PropertyChange request
- */
-
- if (req->type == PropertyChangeNotify) {
- if (req->x.property.keylen) {
- if (write (client->request_fd, req->x.property.key, req->x.property.keylen) != req->x.property.keylen) {
- jack_error ("cannot send property key of length %d to server",
- req->x.property.keylen);
- req->status = -1;
- return req->status;
- }
- }
- }
-
- rok = (read (client->request_fd, req, sizeof (*req))
- == sizeof (*req));
-
- if (wok && rok) { /* everything OK? */
+ jack_client_t *client = (jack_client_t*)ptr;
+
+ wok = (write (client->request_fd, req, sizeof(*req))
+ == sizeof(*req));
+
+ /* if necessary, add variable length key data after a PropertyChange request
+ */
+
+ if (req->type == PropertyChangeNotify) {
+ if (req->x.property.keylen) {
+ if (write (client->request_fd, req->x.property.key, req->x.property.keylen) != req->x.property.keylen) {
+ jack_error ("cannot send property key of length %d to server",
+ req->x.property.keylen);
+ req->status = -1;
+ return req->status;
+ }
+ }
+ }
+
+ rok = (read (client->request_fd, req, sizeof(*req))
+ == sizeof(*req));
+
+ if (wok && rok) { /* everything OK? */
return req->status;
}
- req->status = -1; /* request failed */
+ req->status = -1; /* request failed */
/* check for server shutdown */
- if (client->engine->engine_ok == 0)
+ if (client->engine->engine_ok == 0) {
return req->status;
+ }
/* otherwise report errors */
- if (!wok)
+ if (!wok) {
jack_error ("cannot send request type %d to server",
- req->type);
- if (!rok)
+ req->type);
+ }
+ if (!rok) {
jack_error ("cannot read result for request type %d from"
" server (%s)", req->type, strerror (errno));
+ }
return req->status;
}
@@ -301,18 +307,18 @@ jack_client_deliver_request (const jack_client_t *client, jack_request_t *req)
return client->deliver_request (client->deliver_arg, req);
}
-#if JACK_USE_MACH_THREADS
+#if JACK_USE_MACH_THREADS
jack_client_t *
jack_client_alloc ()
{
jack_client_t *client;
- if ((client = (jack_client_t *) calloc (1, sizeof (jack_client_t))) == NULL) {
+ if ((client = (jack_client_t*)calloc (1, sizeof(jack_client_t))) == NULL) {
return NULL;
}
- if ((client->pollfd = (struct pollfd *) malloc (sizeof (struct pollfd) * 1)) == NULL) {
+ if ((client->pollfd = (struct pollfd*)malloc (sizeof(struct pollfd) * 1)) == NULL) {
free (client);
return NULL;
}
@@ -335,8 +341,8 @@ jack_client_alloc ()
client->port_segment = NULL;
#ifdef USE_DYNSIMD
- init_cpu();
-#endif /* USE_DYNSIMD */
+ init_cpu ();
+#endif /* USE_DYNSIMD */
return client;
}
@@ -348,10 +354,10 @@ jack_client_alloc ()
{
jack_client_t *client;
- if ((client = (jack_client_t *) calloc (1, sizeof (jack_client_t))) == NULL) {
+ if ((client = (jack_client_t*)calloc (1, sizeof(jack_client_t))) == NULL) {
return NULL;
}
- if ((client->pollfd = (struct pollfd *) malloc (sizeof (struct pollfd) * 2)) == NULL) {
+ if ((client->pollfd = (struct pollfd*)malloc (sizeof(struct pollfd) * 2)) == NULL) {
free (client);
return NULL;
}
@@ -374,8 +380,8 @@ jack_client_alloc ()
client->port_segment = NULL;
#ifdef USE_DYNSIMD
- init_cpu();
-#endif /* USE_DYNSIMD */
+ init_cpu ();
+#endif /* USE_DYNSIMD */
return client;
}
@@ -394,7 +400,7 @@ jack_client_alloc_internal (jack_client_control_t *cc, jack_engine_t* engine)
client->control = cc;
client->engine = engine->control;
-
+
client->n_port_types = client->engine->n_port_types;
client->port_segment = &engine->port_segment[0];
@@ -421,23 +427,23 @@ jack_client_fix_port_buffers (jack_client_t *client)
and sets the buffer pointer to NULL. This will cause
jack_port_get_buffer() to reallocate space for the
buffer on the next call (if there is one).
- */
+ */
for (node = client->ports; node; node = jack_slist_next (node)) {
- port = (jack_port_t *) node->data;
+ port = (jack_port_t*)node->data;
if (port->shared->flags & JackPortIsInput) {
if (port->mix_buffer) {
- size_t buffer_size =
- jack_port_type_buffer_size( port->type_info,
- client->engine->buffer_size );
+ size_t buffer_size =
+ jack_port_type_buffer_size ( port->type_info,
+ client->engine->buffer_size );
jack_pool_release (port->mix_buffer);
port->mix_buffer = NULL;
pthread_mutex_lock (&port->connection_lock);
if (jack_slist_length (port->connections) > 1) {
port->mix_buffer = jack_pool_alloc (buffer_size);
- port->fptr.buffer_init (port->mix_buffer,
- buffer_size,
+ port->fptr.buffer_init (port->mix_buffer,
+ buffer_size,
client->engine->buffer_size);
}
pthread_mutex_unlock (&port->connection_lock);
@@ -453,7 +459,7 @@ jack_client_handle_port_connection (jack_client_t *client, jack_event_t *event)
jack_port_t *other = 0;
JSList *node;
int need_free = FALSE;
-
+
if (jack_uuid_compare (client->engine->ports[event->x.self_id].client_id, client->control->uuid) == 0 ||
jack_uuid_compare (client->engine->ports[event->y.other_id].client_id, client->control->uuid) == 0) {
@@ -464,42 +470,42 @@ jack_client_handle_port_connection (jack_client_t *client, jack_event_t *event)
other = jack_port_new (client, event->y.other_id,
client->engine);
/* jack_port_by_id_int() always returns an internal
- * port that does not need to be deallocated
+ * port that does not need to be deallocated
*/
control_port = jack_port_by_id_int (client, event->x.self_id,
&need_free);
pthread_mutex_lock (&control_port->connection_lock);
if ((control_port->shared->flags & JackPortIsInput)
- && (control_port->connections != NULL)
- && (control_port->mix_buffer == NULL) ) {
- size_t buffer_size =
- jack_port_type_buffer_size( control_port->type_info,
- client->engine->buffer_size );
+ && (control_port->connections != NULL)
+ && (control_port->mix_buffer == NULL) ) {
+ size_t buffer_size =
+ jack_port_type_buffer_size ( control_port->type_info,
+ client->engine->buffer_size );
control_port->mix_buffer = jack_pool_alloc (buffer_size);
- control_port->fptr.buffer_init (control_port->mix_buffer,
- buffer_size,
+ control_port->fptr.buffer_init (control_port->mix_buffer,
+ buffer_size,
client->engine->buffer_size);
}
control_port->connections =
jack_slist_prepend (control_port->connections,
- (void *) other);
+ (void*)other);
pthread_mutex_unlock (&control_port->connection_lock);
break;
-
+
case PortDisconnected:
/* jack_port_by_id_int() always returns an internal
- * port that does not need to be deallocated
+ * port that does not need to be deallocated
*/
control_port = jack_port_by_id_int (client, event->x.self_id,
&need_free);
pthread_mutex_lock (&control_port->connection_lock);
-
+
for (node = control_port->connections; node;
node = jack_slist_next (node)) {
-
- other = (jack_port_t *) node->data;
+
+ other = (jack_port_t*)node->data;
if (other->shared->id == event->y.other_id) {
control_port->connections =
@@ -511,10 +517,10 @@ jack_client_handle_port_connection (jack_client_t *client, jack_event_t *event)
break;
}
}
-
+
pthread_mutex_unlock (&control_port->connection_lock);
break;
-
+
default:
/* impossible */
break;
@@ -523,8 +529,8 @@ jack_client_handle_port_connection (jack_client_t *client, jack_event_t *event)
if (client->control->port_connect_cbset) {
client->port_connect (event->x.self_id, event->y.other_id,
- (event->type == PortConnected ? 1 : 0),
- client->port_connect_arg);
+ (event->type == PortConnected ? 1 : 0),
+ client->port_connect_arg);
}
return 0;
@@ -533,16 +539,16 @@ jack_client_handle_port_connection (jack_client_t *client, jack_event_t *event)
int
jack_client_handle_session_callback (jack_client_t *client, jack_event_t *event)
{
- char uuidstr[37];
+ char uuidstr[37];
jack_session_event_t *s_event;
- if (! client->control->session_cbset) {
+ if (!client->control->session_cbset) {
return -1;
}
- jack_uuid_unparse (client->control->uuid, uuidstr);
+ jack_uuid_unparse (client->control->uuid, uuidstr);
- s_event = malloc( sizeof(jack_session_event_t) );
+ s_event = malloc ( sizeof(jack_session_event_t) );
s_event->type = event->y.n;
s_event->session_dir = strdup (event->x.name);
s_event->client_uuid = strdup (uuidstr);
@@ -571,16 +577,19 @@ jack_port_recalculate_latency (jack_port_t *port, jack_latency_callback_mode_t m
jack_port_get_latency_range (other, mode, &other_latency);
- if (other_latency.max > latency.max)
+ if (other_latency.max > latency.max) {
latency.max = other_latency.max;
- if (other_latency.min < latency.min)
+ }
+ if (other_latency.min < latency.min) {
latency.min = other_latency.min;
+ }
}
pthread_mutex_unlock (&port->connection_lock);
- if (latency.min == UINT32_MAX)
+ if (latency.min == UINT32_MAX) {
latency.min = 0;
+ }
jack_port_set_latency_range (port, mode, &latency);
}
@@ -588,7 +597,7 @@ jack_port_recalculate_latency (jack_port_t *port, jack_latency_callback_mode_t m
int
jack_client_handle_latency_callback (jack_client_t *client, jack_event_t *event, int is_driver)
{
- jack_latency_callback_mode_t mode = (event->x.n==0) ? JackCaptureLatency : JackPlaybackLatency;
+ jack_latency_callback_mode_t mode = (event->x.n == 0) ? JackCaptureLatency : JackPlaybackLatency;
JSList *node;
jack_latency_range_t latency = { UINT32_MAX, 0 };
@@ -611,7 +620,7 @@ jack_client_handle_latency_callback (jack_client_t *client, jack_event_t *event,
*/
if (is_driver && !client->control->latency_cbset) {
return 0;
- }
+ }
if (!client->control->latency_cbset) {
/*
@@ -629,15 +638,18 @@ jack_client_handle_latency_callback (jack_client_t *client, jack_event_t *event,
jack_latency_range_t other_latency;
jack_port_get_latency_range (port, mode, &other_latency);
- if (other_latency.max > latency.max)
+ if (other_latency.max > latency.max) {
latency.max = other_latency.max;
- if (other_latency.min < latency.min)
+ }
+ if (other_latency.min < latency.min) {
latency.min = other_latency.min;
+ }
}
}
- if (latency.min == UINT32_MAX)
+ if (latency.min == UINT32_MAX) {
latency.min = 0;
+ }
/* now set the found latency on all input ports
*/
@@ -659,15 +671,18 @@ jack_client_handle_latency_callback (jack_client_t *client, jack_event_t *event,
jack_latency_range_t other_latency;
jack_port_get_latency_range (port, mode, &other_latency);
- if (other_latency.max > latency.max)
+ if (other_latency.max > latency.max) {
latency.max = other_latency.max;
- if (other_latency.min < latency.min)
+ }
+ if (other_latency.min < latency.min) {
latency.min = other_latency.min;
+ }
}
}
- if (latency.min == UINT32_MAX)
+ if (latency.min == UINT32_MAX) {
latency.min = 0;
+ }
/* now set the found latency on all output ports
*/
@@ -691,14 +706,14 @@ jack_client_handle_latency_callback (jack_client_t *client, jack_event_t *event,
#if JACK_USE_MACH_THREADS
-static int
+static int
jack_handle_reorder (jack_client_t *client, jack_event_t *event)
-{
+{
client->pollmax = 1;
/* If the client registered its own callback for graph order events,
execute it now.
- */
+ */
if (client->control->graph_order_cbset) {
client->graph_order (client->graph_order_arg);
@@ -709,10 +724,10 @@ jack_handle_reorder (jack_client_t *client, jack_event_t *event)
#else
-static int
+static int
jack_handle_reorder (jack_client_t *client, jack_event_t *event)
-{
- char path[PATH_MAX+1];
+{
+ char path[PATH_MAX + 1];
DEBUG ("graph reorder\n");
@@ -720,7 +735,7 @@ jack_handle_reorder (jack_client_t *client, jack_event_t *event)
DEBUG ("closing graph_wait_fd==%d", client->graph_wait_fd);
close (client->graph_wait_fd);
client->graph_wait_fd = -1;
- }
+ }
if (client->graph_next_fd >= 0) {
DEBUG ("closing graph_next_fd==%d", client->graph_next_fd);
@@ -729,17 +744,17 @@ jack_handle_reorder (jack_client_t *client, jack_event_t *event)
}
sprintf (path, "%s-%" PRIu32, client->fifo_prefix, event->x.n);
-
- if ((client->graph_wait_fd = open (path, O_RDONLY|O_NONBLOCK)) < 0) {
+
+ if ((client->graph_wait_fd = open (path, O_RDONLY | O_NONBLOCK)) < 0) {
jack_error ("cannot open specified fifo [%s] for reading (%s)",
path, strerror (errno));
return -1;
}
DEBUG ("opened new graph_wait_fd %d (%s)", client->graph_wait_fd, path);
- sprintf (path, "%s-%" PRIu32, client->fifo_prefix, event->x.n+1);
-
- if ((client->graph_next_fd = open (path, O_WRONLY|O_NONBLOCK)) < 0) {
+ sprintf (path, "%s-%" PRIu32, client->fifo_prefix, event->x.n + 1);
+
+ if ((client->graph_next_fd = open (path, O_WRONLY | O_NONBLOCK)) < 0) {
jack_error ("cannot open specified fifo [%s] for writing (%s)",
path, strerror (errno));
return -1;
@@ -749,12 +764,12 @@ jack_handle_reorder (jack_client_t *client, jack_event_t *event)
client->pollmax = 2;
DEBUG ("opened new graph_next_fd %d (%s) (upstream is jackd? %d)",
- client->graph_next_fd, path,
+ client->graph_next_fd, path,
client->upstream_is_jackd);
/* If the client registered its own callback for graph order events,
execute it now.
- */
+ */
if (client->control->graph_order_cbset) {
client->graph_order (client->graph_order_arg);
@@ -764,7 +779,7 @@ jack_handle_reorder (jack_client_t *client, jack_event_t *event)
}
#endif
-
+
static int
server_connect (const char *server_name)
{
@@ -772,7 +787,7 @@ server_connect (const char *server_name)
struct sockaddr_un addr;
int which = 0;
- char server_dir[PATH_MAX+1] = "";
+ char server_dir[PATH_MAX + 1] = "";
if ((fd = socket (AF_UNIX, SOCK_STREAM, 0)) < 0) {
jack_error ("cannot create client socket (%s)",
@@ -784,12 +799,12 @@ server_connect (const char *server_name)
//jack_info ("DEBUG: connecting to `%s' server", server_name);
addr.sun_family = AF_UNIX;
- snprintf (addr.sun_path, sizeof (addr.sun_path) - 1, "%s/jack_%d",
- jack_server_dir (server_name, server_dir) , which);
+ snprintf (addr.sun_path, sizeof(addr.sun_path) - 1, "%s/jack_%d",
+ jack_server_dir (server_name, server_dir), which);
- if (connect (fd, (struct sockaddr *) &addr, sizeof (addr)) < 0) {
+ if (connect (fd, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
close (fd);
- jack_error ("connect(2) call to %s failed (err=%s)", addr.sun_path, strerror (errno));
+ jack_error ("connect(2) call to %s failed (err=%s)", addr.sun_path, strerror (errno));
return -1;
}
return fd;
@@ -803,7 +818,7 @@ server_event_connect (jack_client_t *client, const char *server_name)
jack_client_connect_ack_request_t req;
jack_client_connect_ack_result_t res;
- char server_dir[PATH_MAX+1] = "";
+ char server_dir[PATH_MAX + 1] = "";
if ((fd = socket (AF_UNIX, SOCK_STREAM, 0)) < 0) {
jack_error ("cannot create client event socket (%s)",
@@ -812,10 +827,10 @@ server_event_connect (jack_client_t *client, const char *server_name)
}
addr.sun_family = AF_UNIX;
- snprintf (addr.sun_path, sizeof (addr.sun_path) - 1, "%s/jack_ack_0",
- jack_server_dir (server_name,server_dir));
+ snprintf (addr.sun_path, sizeof(addr.sun_path) - 1, "%s/jack_ack_0",
+ jack_server_dir (server_name, server_dir));
- if (connect (fd, (struct sockaddr *) &addr, sizeof (addr)) < 0) {
+ if (connect (fd, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
jack_error ("cannot connect to jack server for events",
strerror (errno));
close (fd);
@@ -824,14 +839,14 @@ server_event_connect (jack_client_t *client, const char *server_name)
jack_uuid_copy (&req.client_id, client->control->uuid);
- if (write (fd, &req, sizeof (req)) != sizeof (req)) {
+ if (write (fd, &req, sizeof(req)) != sizeof(req)) {
jack_error ("cannot write event connect request to server (%s)",
strerror (errno));
close (fd);
return -1;
}
- if (read (fd, &res, sizeof (res)) != sizeof (res)) {
+ if (read (fd, &res, sizeof(res)) != sizeof(res)) {
jack_error ("cannot read event connect result from server (%s)",
strerror (errno));
close (fd);
@@ -863,32 +878,32 @@ _start_server (const char *server_name)
int i = 0;
int good = 0;
int ret;
- char *startup_file;
+ char *startup_file;
- if ((startup_file = getenv ("JACK_RC_FILE")) == NULL) {
- snprintf(filename, 255, "%s/.jackdrc", getenv("HOME"));
- startup_file = filename;
- }
+ if ((startup_file = getenv ("JACK_RC_FILE")) == NULL) {
+ snprintf (filename, 255, "%s/.jackdrc", getenv ("HOME"));
+ startup_file = filename;
+ }
- fp = fopen(startup_file, "r");
+ fp = fopen (startup_file, "r");
if (!fp) {
- fp = fopen("/etc/jackdrc", "r");
+ fp = fopen ("/etc/jackdrc", "r");
}
/* if still not found, check old config name for backwards compatability */
if (!fp) {
- fp = fopen("/etc/jackd.conf", "r");
+ fp = fopen ("/etc/jackd.conf", "r");
}
if (fp) {
arguments[0] = '\0';
- ret = fscanf(fp, "%s", buffer);
- while(ret != 0 && ret != EOF) {
- strcat(arguments, buffer);
- strcat(arguments, " ");
- ret = fscanf(fp, "%s", buffer);
+ ret = fscanf (fp, "%s", buffer);
+ while (ret != 0 && ret != EOF) {
+ strcat (arguments, buffer);
+ strcat (arguments, " ");
+ ret = fscanf (fp, "%s", buffer);
}
- if (strlen(arguments) > 0) {
+ if (strlen (arguments) > 0) {
good = 1;
}
}
@@ -896,64 +911,63 @@ _start_server (const char *server_name)
if (!good) {
#if defined(USE_CAPABILITIES)
command = JACK_LOCATION "/jackstart";
- strncpy(arguments, JACK_LOCATION "/jackstart -T -R -d "
- JACK_DEFAULT_DRIVER " -p 512", 255);
-#else /* !USE_CAPABILITIES */
+ strncpy (arguments, JACK_LOCATION "/jackstart -T -R -d "
+ JACK_DEFAULT_DRIVER " -p 512", 255);
+#else /* !USE_CAPABILITIES */
command = JACK_LOCATION "/jackd";
- strncpy(arguments, JACK_LOCATION "/jackd -T -d "
- JACK_DEFAULT_DRIVER, 255);
-#endif /* USE_CAPABILITIES */
+ strncpy (arguments, JACK_LOCATION "/jackd -T -d "
+ JACK_DEFAULT_DRIVER, 255);
+#endif /* USE_CAPABILITIES */
} else {
- result = strcspn(arguments, " ");
- if ((command = (char *) malloc(result+1)) == NULL) {
+ result = strcspn (arguments, " ");
+ if ((command = (char*)malloc (result + 1)) == NULL) {
goto failure;
}
- strncpy(command, arguments, result);
+ strncpy (command, arguments, result);
command[result] = '\0';
}
- if ((argv = (char **) malloc (255)) == NULL) {
+ if ((argv = (char**)malloc (255)) == NULL) {
goto failure;
}
-
- while(1) {
+
+ while (1) {
/* insert -T and -nserver_name in front of arguments */
if (i == 1) {
- argv[i] = (char *) malloc(strlen ("-T") + 1);
- strcpy (argv[i++], "-T");
+ argv[i] = (char*)malloc (strlen ("-T") + 1);
+ strcpy (argv[i++], "-T");
if (server_name) {
size_t optlen = strlen ("-n");
char *buf =
malloc (optlen
+ strlen (server_name) + 1);
strcpy (buf, "-n");
- strcpy (buf+optlen, server_name);
+ strcpy (buf + optlen, server_name);
argv[i++] = buf;
}
}
/* skip whitespace */
- while (pos < strlen(arguments) && arguments[pos] && arguments[pos] == ' ') {
+ while (pos < strlen (arguments) && arguments[pos] && arguments[pos] == ' ')
++pos;
- }
- if (pos >= strlen(arguments)) {
+ if (pos >= strlen (arguments)) {
break;
}
if (arguments[pos] == '\"') {
++pos;
- result = strcspn(arguments + pos, "\"");
+ result = strcspn (arguments + pos, "\"");
} else {
- result = strcspn(arguments + pos, " ");
+ result = strcspn (arguments + pos, " ");
}
if (0 == result) {
break;
}
- argv[i] = (char*)malloc(result + 1);
- strncpy(argv[i], arguments + pos, result);
+ argv[i] = (char*)malloc (result + 1);
+ strncpy (argv[i], arguments + pos, result);
argv[i][result] = '\0';
pos += result + 1;
if (++i > 253) {
@@ -964,9 +978,9 @@ _start_server (const char *server_name)
#if 0
fprintf (stderr, "execing JACK using %s\n", command);
- for (_xx = 0; argv[_xx]; ++_xx) {
+ for (_xx = 0; argv[_xx]; ++_xx)
fprintf (stderr, "\targv[%d] = %s\n", _xx, argv[_xx]);
- }
+
#endif
execv (command, argv);
@@ -980,11 +994,11 @@ failure:
int
start_server (const char *server_name, jack_options_t options)
{
- int status;
- pid_t first_child_pid;
+ int status;
+ pid_t first_child_pid;
if ((options & JackNoStartServer)
- || getenv("JACK_NO_START_SERVER")) {
+ || getenv ("JACK_NO_START_SERVER")) {
return 1;
}
@@ -998,28 +1012,28 @@ start_server (const char *server_name, jack_options_t options)
* probably relatively small.
*/
- first_child_pid = fork();
+ first_child_pid = fork ();
switch (first_child_pid) {
- case 0: /* child process */
- switch (fork()) {
- case 0: /* grandchild process */
- _start_server(server_name);
- _exit (99); /* exec failed */
+ case 0: /* child process */
+ switch (fork ()) {
+ case 0: /* grandchild process */
+ _start_server (server_name);
+ _exit (99); /* exec failed */
case -1:
_exit (98);
default:
_exit (0);
}
- case -1: /* fork() error */
- return 1; /* failed to start server */
+ case -1: /* fork() error */
+ return 1; /* failed to start server */
}
- /* reap the initaial child */
- waitpid (first_child_pid, &status, 0);
+ /* reap the initaial child */
+ waitpid (first_child_pid, &status, 0);
/* only the original parent process goes here */
- return 0; /* (probably) successful */
+ return 0; /* (probably) successful */
}
static int
@@ -1031,46 +1045,46 @@ jack_request_client (ClientType type,
jack_client_connect_request_t req;
*req_fd = -1;
- memset (&req, 0, sizeof (req));
+ memset (&req, 0, sizeof(req));
req.options = options;
- if (strlen (client_name) >= sizeof (req.name)) {
+ if (strlen (client_name) >= sizeof(req.name)) {
jack_error ("\"%s\" is too long to be used as a JACK client"
" name.\n"
"Please use %lu characters or less.",
- client_name, sizeof (req.name));
+ client_name, sizeof(req.name));
return -1;
}
if (va->load_name
- && (strlen (va->load_name) > sizeof (req.object_path) - 1)) {
+ && (strlen (va->load_name) > sizeof(req.object_path) - 1)) {
jack_error ("\"%s\" is too long to be used as a JACK shared"
" object name.\n"
- "Please use %lu characters or less.",
- va->load_name, sizeof (req.object_path) - 1);
+ "Please use %lu characters or less.",
+ va->load_name, sizeof(req.object_path) - 1);
return -1;
}
if (va->load_init
- && (strlen (va->load_init) > sizeof (req.object_data) - 1)) {
+ && (strlen (va->load_init) > sizeof(req.object_data) - 1)) {
jack_error ("\"%s\" is too long to be used as a JACK shared"
" object data string.\n"
- "Please use %lu characters or less.",
- va->load_init, sizeof (req.object_data) - 1);
+ "Please use %lu characters or less.",
+ va->load_init, sizeof(req.object_data) - 1);
return -1;
}
-
+
if ((*req_fd = server_connect (va->server_name)) < 0) {
int trys;
- if (start_server(va->server_name, options)) {
- *status |= (JackFailure|JackServerFailed);
+ if (start_server (va->server_name, options)) {
+ *status |= (JackFailure | JackServerFailed);
goto fail;
}
trys = 5;
do {
- sleep(1);
+ sleep (1);
if (--trys < 0) {
- *status |= (JackFailure|JackServerFailed);
+ *status |= (JackFailure | JackServerFailed);
goto fail;
}
} while ((*req_fd = server_connect (va->server_name)) < 0);
@@ -1081,52 +1095,52 @@ jack_request_client (ClientType type,
if (va->sess_uuid && strlen (va->sess_uuid)) {
if (jack_uuid_parse (va->sess_uuid, &req.uuid) != 0) {
- jack_error ("Given UUID [%s] is not parseable", va->sess_uuid);
- goto fail;
- }
- } else {
+ jack_error ("Given UUID [%s] is not parseable", va->sess_uuid);
+ goto fail;
+ }
+ } else {
jack_uuid_clear (&req.uuid);
- }
+ }
req.protocol_v = jack_protocol_version;
req.load = TRUE;
req.type = type;
- snprintf (req.name, sizeof (req.name),
+ snprintf (req.name, sizeof(req.name),
"%s", client_name);
- snprintf (req.object_path, sizeof (req.object_path),
+ snprintf (req.object_path, sizeof(req.object_path),
"%s", va->load_name);
- snprintf (req.object_data, sizeof (req.object_data),
+ snprintf (req.object_data, sizeof(req.object_data),
"%s", va->load_init);
- if (write (*req_fd, &req, sizeof (req)) != sizeof (req)) {
+ if (write (*req_fd, &req, sizeof(req)) != sizeof(req)) {
jack_error ("cannot send request to jack server (%s)",
strerror (errno));
- *status |= (JackFailure|JackServerError);
+ *status |= (JackFailure | JackServerError);
goto fail;
}
- if (read (*req_fd, res, sizeof (*res)) != sizeof (*res)) {
+ if (read (*req_fd, res, sizeof(*res)) != sizeof(*res)) {
if (errno == 0) {
/* server shut the socket */
jack_error ("could not attach as client");
- *status |= (JackFailure|JackServerError);
+ *status |= (JackFailure | JackServerError);
goto fail;
}
-
+
if (errno == ECONNRESET) {
jack_error ("could not attach as JACK client "
"(server has exited)");
- *status |= (JackFailure|JackServerError);
+ *status |= (JackFailure | JackServerError);
goto fail;
}
-
+
jack_error ("cannot read response from jack server (%s)",
strerror (errno));
- *status |= (JackFailure|JackServerError);
+ *status |= (JackFailure | JackServerError);
goto fail;
}
- *status |= res->status; /* return server status bits */
+ *status |= res->status; /* return server status bits */
if (*status & JackFailure) {
if (*status & JackVersionError) {
@@ -1151,8 +1165,8 @@ jack_request_client (ClientType type,
return 0;
- fail:
- jack_error ("attempt to connect to server failed");
+fail:
+ jack_error ("attempt to connect to server failed");
if (*req_fd >= 0) {
close (*req_fd);
*req_fd = -1;
@@ -1164,29 +1178,29 @@ int
jack_attach_port_segment (jack_client_t *client, jack_port_type_id_t ptid)
{
/* Lookup, attach and register the port/buffer segments in use
- * right now.
+ * right now.
*/
if (client->control->type != ClientExternal) {
- jack_error("Only external clients need attach port segments");
- abort();
+ jack_error ("Only external clients need attach port segments");
+ abort ();
}
/* make sure we have space to store the port
segment information.
- */
+ */
if (ptid >= client->n_port_types) {
-
+
client->port_segment = (jack_shm_info_t*)
- realloc (client->port_segment,
- sizeof (jack_shm_info_t) * (ptid+1));
+ realloc (client->port_segment,
+ sizeof(jack_shm_info_t) * (ptid + 1));
memset (&client->port_segment[client->n_port_types],
0,
- sizeof (jack_shm_info_t) *
+ sizeof(jack_shm_info_t) *
(ptid - client->n_port_types));
-
+
client->n_port_types = ptid + 1;
} else {
@@ -1213,38 +1227,39 @@ jack_attach_port_segment (jack_client_t *client, jack_port_type_id_t ptid)
jack_client_t *
jack_client_open_aux (const char *client_name,
- jack_options_t options,
- jack_status_t *status, va_list ap)
+ jack_options_t options,
+ jack_status_t *status, va_list ap)
{
/* optional arguments: */
- jack_varargs_t va; /* variable arguments */
+ jack_varargs_t va; /* variable arguments */
int req_fd = -1;
int ev_fd = -1;
- jack_client_connect_result_t res;
+ jack_client_connect_result_t res;
jack_client_t *client;
jack_port_type_id_t ptid;
jack_status_t my_status;
jack_messagebuffer_init ();
-
- if (status == NULL) /* no status from caller? */
- status = &my_status; /* use local status word */
+
+ if (status == NULL) { /* no status from caller? */
+ status = &my_status; /* use local status word */
+ }
*status = 0;
/* validate parameters */
if ((options & ~JackOpenOptions)) {
- *status |= (JackFailure|JackInvalidOption);
+ *status |= (JackFailure | JackInvalidOption);
jack_messagebuffer_exit ();
return NULL;
}
/* parse variable arguments */
- jack_varargs_parse(options, ap, &va);
+ jack_varargs_parse (options, ap, &va);
/* External clients need to know where the tmpdir used for
communication with the server lives
- */
+ */
if (jack_get_tmpdir ()) {
*status |= JackFailure;
jack_messagebuffer_exit ();
@@ -1269,16 +1284,16 @@ jack_client_open_aux (const char *client_name,
strcpy (client->fifo_prefix, res.fifo_prefix);
client->request_fd = req_fd;
client->pollfd[EVENT_POLL_INDEX].events =
- POLLIN|POLLERR|POLLHUP|POLLNVAL;
+ POLLIN | POLLERR | POLLHUP | POLLNVAL;
#ifndef JACK_USE_MACH_THREADS
client->pollfd[WAIT_POLL_INDEX].events =
- POLLIN|POLLERR|POLLHUP|POLLNVAL;
+ POLLIN | POLLERR | POLLHUP | POLLNVAL;
#endif
/* Don't access shared memory until server connected. */
if (jack_initialize_shm (va.server_name)) {
jack_error ("Unable to initialize shared memory.");
- *status |= (JackFailure|JackShmFailure);
+ *status |= (JackFailure | JackShmFailure);
goto fail;
}
@@ -1289,8 +1304,8 @@ jack_client_open_aux (const char *client_name,
" segment");
goto fail;
}
-
- client->engine = (jack_control_t *) jack_shm_addr (&client->engine_shm);
+
+ client->engine = (jack_control_t*)jack_shm_addr (&client->engine_shm);
/* initialize clock source as early as possible */
jack_set_clock_source (client->engine->clock_source);
@@ -1302,9 +1317,9 @@ jack_client_open_aux (const char *client_name,
" segment");
goto fail;
}
-
- client->control = (jack_client_control_t *)
- jack_shm_addr (&client->control_shm);
+
+ client->control = (jack_client_control_t*)
+ jack_shm_addr (&client->control_shm);
/* Nobody else needs to access this shared memory any more, so
* destroy it. Because we have it attached, it won't vanish
@@ -1313,10 +1328,10 @@ jack_client_open_aux (const char *client_name,
jack_destroy_shm (&client->control_shm);
client->n_port_types = client->engine->n_port_types;
- if ((client->port_segment = (jack_shm_info_t *) malloc (sizeof (jack_shm_info_t) * client->n_port_types)) == NULL) {
+ if ((client->port_segment = (jack_shm_info_t*)malloc (sizeof(jack_shm_info_t) * client->n_port_types)) == NULL) {
goto fail;
}
-
+
for (ptid = 0; ptid < client->n_port_types; ++ptid) {
client->port_segment[ptid].index =
client->engine->port_types[ptid].shm_registry_index;
@@ -1327,7 +1342,7 @@ jack_client_open_aux (const char *client_name,
}
/* set up the client so that it does the right thing for an
- * external client
+ * external client
*/
client->deliver_request = oop_client_deliver_request;
client->deliver_arg = client;
@@ -1337,25 +1352,26 @@ jack_client_open_aux (const char *client_name,
}
client->event_fd = ev_fd;
-
+
#ifdef JACK_USE_MACH_THREADS
- /* specific resources for server/client real-time thread
+ /* specific resources for server/client real-time thread
* communication */
- client->clienttask = mach_task_self();
-
- if (task_get_bootstrap_port(client->clienttask, &client->bp)){
- jack_error ("Can't find bootstrap port");
- goto fail;
- }
-
- if (allocate_mach_clientport(client, res.portnum) < 0) {
- jack_error("Can't allocate mach port");
- goto fail;
- };
-#endif /* JACK_USE_MACH_THREADS */
- return client;
-
- fail:
+ client->clienttask = mach_task_self ();
+
+ if (task_get_bootstrap_port (client->clienttask, &client->bp)) {
+ jack_error ("Can't find bootstrap port");
+ goto fail;
+ }
+
+ if (allocate_mach_clientport (client, res.portnum) < 0) {
+ jack_error ("Can't allocate mach port");
+ goto fail;
+ }
+ ;
+#endif /* JACK_USE_MACH_THREADS */
+ return client;
+
+fail:
jack_messagebuffer_exit ();
if (client->engine) {
@@ -1377,12 +1393,13 @@ jack_client_open_aux (const char *client_name,
return NULL;
}
-jack_client_t* jack_client_open(const char* ext_client_name, jack_options_t options, jack_status_t* status, ...)
+jack_client_t* jack_client_open (const char* ext_client_name, jack_options_t options, jack_status_t* status, ...)
{
va_list ap;
- va_start(ap, status);
- jack_client_t* res = jack_client_open_aux(ext_client_name, options, status, ap);
- va_end(ap);
+
+ va_start (ap, status);
+ jack_client_t* res = jack_client_open_aux (ext_client_name, options, status, ap);
+ va_end (ap);
return res;
}
@@ -1390,8 +1407,10 @@ jack_client_t *
jack_client_new (const char *client_name)
{
jack_options_t options = JackUseExactName;
- if (getenv("JACK_START_SERVER") == NULL)
+
+ if (getenv ("JACK_START_SERVER") == NULL) {
options |= JackNoStartServer;
+ }
return jack_client_open (client_name, options, NULL);
}
@@ -1411,12 +1430,13 @@ jack_internal_client_new (const char *client_name,
jack_status_t status;
jack_options_t options = JackUseExactName;
- if (getenv("JACK_START_SERVER") == NULL)
+ if (getenv ("JACK_START_SERVER") == NULL) {
options |= JackNoStartServer;
+ }
jack_varargs_init (&va);
- va.load_name = (char *) so_name;
- va.load_init = (char *) so_data;
+ va.load_name = (char*)so_name;
+ va.load_init = (char*)so_data;
return jack_request_client (ClientInternal, client_name,
options, &status, &va, &res, &req_fd);
@@ -1426,8 +1446,10 @@ char *
jack_default_server_name (void)
{
char *server_name;
- if ((server_name = getenv("JACK_DEFAULT_SERVER")) == NULL)
+
+ if ((server_name = getenv ("JACK_DEFAULT_SERVER")) == NULL) {
server_name = "default";
+ }
return server_name;
}
@@ -1435,15 +1457,15 @@ jack_default_server_name (void)
char *
jack_user_dir (void)
{
- static char user_dir[PATH_MAX+1] = "";
+ static char user_dir[PATH_MAX + 1] = "";
/* format the path name on the first call */
if (user_dir[0] == '\0') {
if (getenv ("JACK_PROMISCUOUS_SERVER")) {
- snprintf (user_dir, sizeof (user_dir), "%s/jack",
+ snprintf (user_dir, sizeof(user_dir), "%s/jack",
jack_tmpdir);
} else {
- snprintf (user_dir, sizeof (user_dir), "%s/jack-%d",
+ snprintf (user_dir, sizeof(user_dir), "%s/jack-%d",
jack_tmpdir, getuid ());
}
}
@@ -1458,13 +1480,13 @@ jack_server_dir (const char *server_name, char *server_dir)
/* format the path name into the suppled server_dir char array,
* assuming that server_dir is at least as large as PATH_MAX+1 */
- if (server_name == NULL || server_name[0] == '\0') {
- snprintf (server_dir, PATH_MAX+1, "%s/%s",
- jack_user_dir (), jack_default_server_name());
- } else {
- snprintf (server_dir, PATH_MAX+1, "%s/%s",
- jack_user_dir (), server_name);
- }
+ if (server_name == NULL || server_name[0] == '\0') {
+ snprintf (server_dir, PATH_MAX + 1, "%s/%s",
+ jack_user_dir (), jack_default_server_name ());
+ } else {
+ snprintf (server_dir, PATH_MAX + 1, "%s/%s",
+ jack_user_dir (), server_name);
+ }
return server_dir;
}
@@ -1477,19 +1499,19 @@ jack_internal_client_close (const char *client_name)
char *server_name = jack_default_server_name ();
req.load = FALSE;
- snprintf (req.name, sizeof (req.name), "%s", client_name);
-
+ snprintf (req.name, sizeof(req.name), "%s", client_name);
+
if ((fd = server_connect (server_name)) < 0) {
return;
}
- if (write (fd, &req, sizeof (req)) != sizeof(req)) {
+ if (write (fd, &req, sizeof(req)) != sizeof(req)) {
jack_error ("cannot deliver ClientUnload request to JACK "
"server.");
}
/* no response to this request */
-
+
close (fd);
return;
}
@@ -1498,7 +1520,8 @@ int
jack_recompute_total_latencies (jack_client_t* client)
{
jack_request_t request;
- VALGRIND_MEMSET (&request, 0, sizeof (request));
+
+ VALGRIND_MEMSET (&request, 0, sizeof(request));
request.type = RecomputeTotalLatencies;
return jack_client_deliver_request (client, &request);
@@ -1508,7 +1531,8 @@ int
jack_recompute_total_latency (jack_client_t* client, jack_port_t* port)
{
jack_request_t request;
- VALGRIND_MEMSET (&request, 0, sizeof (request));
+
+ VALGRIND_MEMSET (&request, 0, sizeof(request));
request.type = RecomputeTotalLatency;
request.x.port_info.port_id = port->shared->id;
@@ -1519,7 +1543,8 @@ int
jack_set_freewheel (jack_client_t* client, int onoff)
{
jack_request_t request;
- VALGRIND_MEMSET (&request, 0, sizeof (request));
+
+ VALGRIND_MEMSET (&request, 0, sizeof(request));
request.type = onoff ? FreeWheel : StopFreeWheel;
jack_uuid_copy (&request.x.client_id, client->control->uuid);
@@ -1532,25 +1557,25 @@ jack_session_reply (jack_client_t *client, jack_session_event_t *event )
int retval = 0;
if (event->command_line) {
- snprintf ((char *)client->control->session_command,
- sizeof(client->control->session_command),
- "%s", event->command_line);
+ snprintf ((char*)client->control->session_command,
+ sizeof(client->control->session_command),
+ "%s", event->command_line);
client->control->session_flags = event->flags;
} else {
retval = -1;
}
- if (pthread_self() == client->thread_id) {
+ if (pthread_self () == client->thread_id) {
client->session_cb_immediate_reply = 1;
} else {
jack_request_t request;
- VALGRIND_MEMSET (&request, 0, sizeof (request));
+ VALGRIND_MEMSET (&request, 0, sizeof(request));
request.type = SessionReply;
jack_uuid_copy (&request.x.client_id, client->control->uuid);
- retval = jack_client_deliver_request(client, &request);
+ retval = jack_client_deliver_request (client, &request);
}
return retval;
@@ -1559,32 +1584,37 @@ jack_session_reply (jack_client_t *client, jack_session_event_t *event )
void
jack_session_event_free (jack_session_event_t *event)
{
- if (event->command_line)
+ if (event->command_line) {
free (event->command_line);
+ }
- free ((char *)event->session_dir);
- free ((char *)event->client_uuid);
+ free ((char*)event->session_dir);
+ free ((char*)event->client_uuid);
free (event);
}
void
jack_session_commands_free (jack_session_command_t *cmds)
{
- int i=0;
- while(1) {
- if (cmds[i].client_name)
- free ((char *)cmds[i].client_name);
- if (cmds[i].command)
- free ((char *)cmds[i].command);
- if (cmds[i].uuid)
- free ((char *)cmds[i].uuid);
- else
+ int i = 0;
+
+ while (1) {
+ if (cmds[i].client_name) {
+ free ((char*)cmds[i].client_name);
+ }
+ if (cmds[i].command) {
+ free ((char*)cmds[i].command);
+ }
+ if (cmds[i].uuid) {
+ free ((char*)cmds[i].uuid);
+ } else {
break;
+ }
i += 1;
}
- free(cmds);
+ free (cmds);
}
jack_session_command_t *
@@ -1594,80 +1624,84 @@ jack_session_notify (jack_client_t* client, const char *target, jack_session_eve
jack_session_command_t *retval = NULL;
int num_replies = 0;
- VALGRIND_MEMSET (&request, 0, sizeof (request));
+ VALGRIND_MEMSET (&request, 0, sizeof(request));
request.type = SessionNotify;
- if( path )
- snprintf( request.x.session.path, sizeof( request.x.session.path ), "%s", path );
- else
+ if ( path ) {
+ snprintf ( request.x.session.path, sizeof( request.x.session.path ), "%s", path );
+ } else {
request.x.session.path[0] = '\0';
+ }
- if( target )
- snprintf( request.x.session.target, sizeof( request.x.session.target ), "%s", target );
- else
+ if ( target ) {
+ snprintf ( request.x.session.target, sizeof( request.x.session.target ), "%s", target );
+ } else {
request.x.session.target[0] = '\0';
+ }
request.x.session.type = code;
-
- if( (write (client->request_fd, &request, sizeof (request))
- != sizeof (request)) ) {
+
+ if ( (write (client->request_fd, &request, sizeof(request))
+ != sizeof(request)) ) {
jack_error ("cannot send request type %d to server",
- request.type);
+ request.type);
goto out;
}
- while( 1 ) {
+ while ( 1 ) {
jack_uuid_t uid;
- if (read (client->request_fd, &uid, sizeof (uid)) != sizeof (uid)) {
+ if (read (client->request_fd, &uid, sizeof(uid)) != sizeof(uid)) {
jack_error ("cannot read result for request type %d from"
- " server (%s)", request.type, strerror (errno));
+ " server (%s)", request.type, strerror (errno));
goto out;
}
num_replies += 1;
- retval = realloc( retval, (num_replies)*sizeof(jack_session_command_t) );
- retval[num_replies-1].client_name = malloc (JACK_CLIENT_NAME_SIZE);
- retval[num_replies-1].command = malloc (JACK_PORT_NAME_SIZE);
- retval[num_replies-1].uuid = malloc (JACK_UUID_STRING_SIZE);
-
- if ( (retval[num_replies-1].client_name == NULL)
- ||(retval[num_replies-1].command == NULL)
- ||(retval[num_replies-1].uuid == NULL) )
- goto out;
+ retval = realloc ( retval, (num_replies) * sizeof(jack_session_command_t) );
+ retval[num_replies - 1].client_name = malloc (JACK_CLIENT_NAME_SIZE);
+ retval[num_replies - 1].command = malloc (JACK_PORT_NAME_SIZE);
+ retval[num_replies - 1].uuid = malloc (JACK_UUID_STRING_SIZE);
+
+ if ( (retval[num_replies - 1].client_name == NULL)
+ || (retval[num_replies - 1].command == NULL)
+ || (retval[num_replies - 1].uuid == NULL) ) {
+ goto out;
+ }
if (jack_uuid_empty (uid)) {
break;
- }
+ }
- if (read (client->request_fd, (char *)retval[num_replies-1].client_name, JACK_CLIENT_NAME_SIZE)
- != JACK_CLIENT_NAME_SIZE) {
+ if (read (client->request_fd, (char*)retval[num_replies - 1].client_name, JACK_CLIENT_NAME_SIZE)
+ != JACK_CLIENT_NAME_SIZE) {
jack_error ("cannot read result for request type %d from"
- " server (%s)", request.type, strerror (errno));
+ " server (%s)", request.type, strerror (errno));
goto out;
}
- if (read (client->request_fd, (char *)retval[num_replies-1].command, JACK_PORT_NAME_SIZE)
- != JACK_PORT_NAME_SIZE) {
+ if (read (client->request_fd, (char*)retval[num_replies - 1].command, JACK_PORT_NAME_SIZE)
+ != JACK_PORT_NAME_SIZE) {
jack_error ("cannot read result for request type %d from"
- " server (%s)", request.type, strerror (errno));
+ " server (%s)", request.type, strerror (errno));
goto out;
}
- if (read (client->request_fd, & retval[num_replies-1].flags, sizeof(retval[num_replies-1].flags) )
- != sizeof(retval[num_replies-1].flags) ) {
+ if (read (client->request_fd, &retval[num_replies - 1].flags, sizeof(retval[num_replies - 1].flags) )
+ != sizeof(retval[num_replies - 1].flags) ) {
jack_error ("cannot read result for request type %d from"
- " server (%s)", request.type, strerror (errno));
+ " server (%s)", request.type, strerror (errno));
goto out;
}
- jack_uuid_unparse (uid, (char *)retval[num_replies-1].uuid);
+ jack_uuid_unparse (uid, (char*)retval[num_replies - 1].uuid);
}
- free((char *)retval[num_replies-1].uuid);
- retval[num_replies-1].uuid = NULL;
- retval[num_replies-1].client_name = NULL;
- retval[num_replies-1].command = NULL;
+ free ((char*)retval[num_replies - 1].uuid);
+ retval[num_replies - 1].uuid = NULL;
+ retval[num_replies - 1].client_name = NULL;
+ retval[num_replies - 1].command = NULL;
return retval;
out:
- if( retval )
- jack_session_commands_free(retval);
+ if ( retval ) {
+ jack_session_commands_free (retval);
+ }
return NULL;
}
@@ -1676,12 +1710,13 @@ jack_client_has_session_callback (jack_client_t *client, const char *client_name
{
jack_request_t request;
int retval;
- VALGRIND_MEMSET (&request, 0, sizeof (request));
+
+ VALGRIND_MEMSET (&request, 0, sizeof(request));
request.type = SessionHasCallback;
strncpy (request.x.name, client_name, JACK_CLIENT_NAME_SIZE);
- retval = jack_client_deliver_request(client, &request);
+ retval = jack_client_deliver_request (client, &request);
return retval;
}
@@ -1692,7 +1727,7 @@ jack_start_freewheel (jack_client_t* client)
jack_client_control_t *control = client->control;
if (client->engine->real_time) {
-#if JACK_USE_MACH_THREADS
+#if JACK_USE_MACH_THREADS
jack_drop_real_time_scheduling (client->process_thread);
#else
jack_drop_real_time_scheduling (client->thread);
@@ -1710,12 +1745,12 @@ jack_stop_freewheel (jack_client_t* client)
jack_client_control_t *control = client->control;
if (client->engine->real_time) {
-#if JACK_USE_MACH_THREADS
+#if JACK_USE_MACH_THREADS
jack_acquire_real_time_scheduling (client->process_thread,
- client->engine->client_priority);
+ client->engine->client_priority);
#else
- jack_acquire_real_time_scheduling (client->thread,
- client->engine->client_priority);
+ jack_acquire_real_time_scheduling (client->thread,
+ client->engine->client_priority);
#endif
}
@@ -1728,7 +1763,7 @@ static void
jack_client_thread_suicide (jack_client_t* client, const char* reason)
{
#ifdef JACK_USE_MACH_THREADS
- client->rt_thread_ok = FALSE;
+ client->rt_thread_ok = FALSE;
#endif
if (client->on_info_shutdown) {
@@ -1741,7 +1776,7 @@ jack_client_thread_suicide (jack_client_t* client, const char* reason)
jack_error ("jack_client_thread: %s - exiting from JACK", reason);
jack_client_close_aux (client);
/* Need a fix : possibly make client crash if
- * zombified without shutdown handler
+ * zombified without shutdown handler
*/
}
@@ -1757,39 +1792,39 @@ jack_client_process_events (jack_client_t* client)
jack_client_control_t *control = client->control;
JSList *node;
jack_port_t* port;
- char* key = 0;
+ char* key = 0;
DEBUG ("process events");
if (client->pollfd[EVENT_POLL_INDEX].revents & POLLIN) {
-
+
DEBUG ("client receives an event, "
"now reading on event fd");
-
+
/* server has sent us an event. process the
* event and reply */
-
- if (read (client->event_fd, &event, sizeof (event))
- != sizeof (event)) {
+
+ if (read (client->event_fd, &event, sizeof(event))
+ != sizeof(event)) {
jack_error ("cannot read server event (%s)",
strerror (errno));
return -1;
}
- if (event.type == PropertyChange) {
- if (event.y.key_size) {
- key = (char *) malloc (event.y.key_size);
- if (read (client->event_fd, key, event.y.key_size) !=
- event.y.key_size) {
- jack_error ("cannot read property change key (%s)",
- strerror (errno));
- return -1;
- }
- }
- }
+ if (event.type == PropertyChange) {
+ if (event.y.key_size) {
+ key = (char*)malloc (event.y.key_size);
+ if (read (client->event_fd, key, event.y.key_size) !=
+ event.y.key_size) {
+ jack_error ("cannot read property change key (%s)",
+ strerror (errno));
+ return -1;
+ }
+ }
+ }
status = 0;
-
+
switch (event.type) {
case PortRegistered:
for (node = client->ports_ext; node; node = jack_slist_next (node)) {
@@ -1801,76 +1836,76 @@ jack_client_process_events (jack_client_t* client)
if (control->port_register_cbset) {
client->port_register
(event.x.port_id, TRUE,
- client->port_register_arg);
- }
+ client->port_register_arg);
+ }
break;
-
+
case PortUnregistered:
if (control->port_register_cbset) {
client->port_register
(event.x.port_id, FALSE,
- client->port_register_arg);
+ client->port_register_arg);
}
break;
-
+
case ClientRegistered:
if (control->client_register_cbset) {
client->client_register
(event.x.name, TRUE,
- client->client_register_arg);
- }
+ client->client_register_arg);
+ }
break;
-
+
case ClientUnregistered:
if (control->client_register_cbset) {
client->client_register
(event.x.name, FALSE,
- client->client_register_arg);
+ client->client_register_arg);
}
break;
-
+
case GraphReordered:
status = jack_handle_reorder (client, &event);
break;
-
+
case PortConnected:
case PortDisconnected:
status = jack_client_handle_port_connection
- (client, &event);
+ (client, &event);
break;
-
+
case BufferSizeChange:
jack_client_fix_port_buffers (client);
if (control->bufsize_cbset) {
status = client->bufsize
- (client->engine->buffer_size,
- client->bufsize_arg);
- }
+ (client->engine->buffer_size,
+ client->bufsize_arg);
+ }
break;
-
+
case SampleRateChange:
if (control->srate_cbset) {
status = client->srate
- (client->engine->current_time.frame_rate,
- client->srate_arg);
+ (client->engine->current_time.frame_rate,
+ client->srate_arg);
}
break;
-
+
case XRun:
if (control->xrun_cbset) {
status = client->xrun
- (client->xrun_arg);
+ (client->xrun_arg);
}
break;
-
+
case AttachPortSegment:
jack_attach_port_segment (client, event.y.ptid);
break;
-
+
case StartFreewheel:
jack_start_freewheel (client);
break;
-
+
case StopFreewheel:
jack_stop_freewheel (client);
break;
@@ -1880,31 +1915,31 @@ jack_client_process_events (jack_client_t* client)
case LatencyCallback:
status = jack_client_handle_latency_callback (client, &event, 0 );
break;
- case PropertyChange:
- if (control->property_cbset) {
- client->property_cb (event.x.uuid, key, event.z.property_change, client->property_cb_arg);
- }
- if (key) {
- free (key);
- }
- break;
- case PortRename:
- if (control->port_rename_cbset) {
- client->port_rename_cb (event.y.other_id, event.x.name, event.z.other_name, client->port_rename_arg);
- }
- break;
- }
-
+ case PropertyChange:
+ if (control->property_cbset) {
+ client->property_cb (event.x.uuid, key, event.z.property_change, client->property_cb_arg);
+ }
+ if (key) {
+ free (key);
+ }
+ break;
+ case PortRename:
+ if (control->port_rename_cbset) {
+ client->port_rename_cb (event.y.other_id, event.x.name, event.z.other_name, client->port_rename_arg);
+ }
+ break;
+ }
+
DEBUG ("client has dealt with the event, writing "
"response on event fd");
-
- if (write (client->event_fd, &status, sizeof (status))
- != sizeof (status)) {
+
+ if (write (client->event_fd, &status, sizeof(status))
+ != sizeof(status)) {
jack_error ("cannot send event response to "
"engine (%s)", strerror (errno));
return -1;
}
- }
+ }
return 0;
}
@@ -1918,19 +1953,19 @@ jack_wake_next_client (jack_client_t* client)
int pret = 0;
char c = 0;
- if (write (client->graph_next_fd, &c, sizeof (c))
- != sizeof (c)) {
- DEBUG("cannot write byte to fd %d", client->graph_next_fd);
+ if (write (client->graph_next_fd, &c, sizeof(c))
+ != sizeof(c)) {
+ DEBUG ("cannot write byte to fd %d", client->graph_next_fd);
jack_error ("cannot continue execution of the "
"processing graph (%s)",
- strerror(errno));
+ strerror (errno));
return -1;
}
-
+
DEBUG ("client sent message to next stage by %" PRIu64 "",
- jack_get_microseconds());
-
- DEBUG("reading cleanup byte from pipe %d\n", client->graph_wait_fd);
+ jack_get_microseconds ());
+
+ DEBUG ("reading cleanup byte from pipe %d\n", client->graph_wait_fd);
/* "upstream client went away? readability is checked in
* jack_client_core_wait(), but that's almost a whole cycle
@@ -1942,21 +1977,21 @@ jack_wake_next_client (jack_client_t* client)
pfds[0].events = POLLIN;
/* 0 timeout, don't actually wait */
- pret = poll(pfds, 1, 0);
+ pret = poll (pfds, 1, 0);
}
if (pret > 0 && (pfds[0].revents & POLLIN)) {
- if (read (client->graph_wait_fd, &c, sizeof (c))
- != sizeof (c)) {
+ if (read (client->graph_wait_fd, &c, sizeof(c))
+ != sizeof(c)) {
jack_error ("cannot complete execution of the "
- "processing graph (%s)", strerror(errno));
+ "processing graph (%s)", strerror (errno));
return -1;
}
} else {
- DEBUG("cleanup byte from pipe %d not available?\n",
- client->graph_wait_fd);
+ DEBUG ("cleanup byte from pipe %d not available?\n",
+ client->graph_wait_fd);
}
-#endif
+#endif
return 0;
}
@@ -1970,10 +2005,10 @@ jack_osx_event_thread_work (void* arg)
All we do here is to poll() for callbacks from the server,
and then process any callbacks that arrive.
- */
+ */
- jack_client_t* client = (jack_client_t*) arg;
+ jack_client_t* client = (jack_client_t*)arg;
jack_client_control_t *control = client->control;
if (control->thread_init_cbset) {
@@ -1981,14 +2016,14 @@ jack_osx_event_thread_work (void* arg)
client->thread_init (client->thread_init_arg);
}
- while (1) {
+ while (1) {
/* this is OS X - we're only waiting on events */
-
+
DEBUG ("client polling on %s", client->pollmax == 2 ?
"event_fd and graph_wait_fd..." :
"event_fd only");
-
+
while (1) {
if (poll (client->pollfd, client->pollmax, 1000) < 0) {
if (errno == EINTR) {
@@ -1998,15 +2033,15 @@ jack_osx_event_thread_work (void* arg)
strerror (errno));
break;
}
-
- pthread_testcancel();
-
+
+ pthread_testcancel ();
+
if (jack_client_process_events (client)) {
DEBUG ("event processing failed\n");
break;
}
}
-
+
if (control->dead || client->pollfd[EVENT_POLL_INDEX].revents & ~POLLIN) {
DEBUG ("client appears dead or event pollfd has error status\n");
break;
@@ -2027,12 +2062,12 @@ jack_client_core_wait (jack_client_t* client)
{
jack_client_control_t *control = client->control;
- /* this is not OS X - we're waiting on events & process wakeups */
+ /* this is not OS X - we're waiting on events & process wakeups */
DEBUG ("client polling on %s", client->pollmax == 2 ?
"event_fd and graph_wait_fd..." :
"event_fd only");
-
+
while (1) {
if (poll (client->pollfd, client->pollmax, 1000) < 0) {
if (errno == EINTR) {
@@ -2043,30 +2078,30 @@ jack_client_core_wait (jack_client_t* client)
return -1;
}
- pthread_testcancel();
+ pthread_testcancel ();
/* get an accurate timestamp on waking from poll for a
- * process() cycle.
+ * process() cycle.
*/
-
+
if (client->graph_wait_fd >= 0
&& client->pollfd[WAIT_POLL_INDEX].revents & POLLIN) {
- control->awake_at = jack_get_microseconds();
+ control->awake_at = jack_get_microseconds ();
}
-
+
DEBUG ("pfd[EVENT].revents = 0x%x pfd[WAIT].revents = 0x%x",
client->pollfd[EVENT_POLL_INDEX].revents,
client->pollfd[WAIT_POLL_INDEX].revents);
-
+
if (client->graph_wait_fd >= 0 &&
(client->pollfd[WAIT_POLL_INDEX].revents & ~POLLIN)) {
-
+
/* our upstream "wait" connection
closed, which either means that
an intermediate client exited, or
jackd exited, or jackd zombified
us.
-
+
we can discover the zombification
via client->control->dead, but
the other two possibilities are
@@ -2074,8 +2109,8 @@ jack_client_core_wait (jack_client_t* client)
this situation. so we have to
check what we are connected to,
and act accordingly.
- */
-
+ */
+
if (client->upstream_is_jackd) {
DEBUG ("WE (%s) DIE\n", client->name);
return 0;
@@ -2085,12 +2120,12 @@ jack_client_core_wait (jack_client_t* client)
* again until we get a
* GraphReordered event.
*/
-
+
client->graph_wait_fd = -1;
client->pollmax = 1;
}
}
-
+
if (jack_client_process_events (client)) {
DEBUG ("event processing failed\n");
return 0;
@@ -2113,39 +2148,39 @@ jack_client_core_wait (jack_client_t* client)
#endif
-static void*
+static void*
jack_process_thread_work (void* arg)
{
/* this is the RT process thread used to handle process()
callbacks, and on non-OSX systems, server events/callbacks
as well.
- */
+ */
- jack_client_t* client = (jack_client_t*) arg;
+ jack_client_t* client = (jack_client_t*)arg;
jack_client_control_t *control = client->control;
/* notify the waiting client that this thread
is up and running.
- */
+ */
pthread_mutex_lock (&client_lock);
client->thread_ok = TRUE;
- client->thread_id = pthread_self();
+ client->thread_id = pthread_self ();
pthread_cond_signal (&client_ready);
pthread_mutex_unlock (&client_lock);
- control->pid = getpid();
- control->pgrp = getpgrp();
+ control->pid = getpid ();
+ control->pgrp = getpgrp ();
#ifdef JACK_USE_MACH_THREADS
client->rt_thread_ok = TRUE;
-#endif
+#endif
if (control->thread_cb_cbset) {
- /* client provided a thread function to run,
+ /* client provided a thread function to run,
so just do that.
- */
+ */
client->thread_cb (client->thread_cb_arg);
@@ -2155,29 +2190,29 @@ jack_process_thread_work (void* arg)
DEBUG ("calling process thread init callback");
client->thread_init (client->thread_init_arg);
}
-
+
while (1) {
int status;
-
+
if (jack_cycle_wait (client) != client->engine->buffer_size) {
break;
}
-
+
if (control->process_cbset) {
-
+
/* run process callback, then wait... ad-infinitum */
-
- DEBUG("client calls process()");
+
+ DEBUG ("client calls process()");
status = client->process (client->engine->buffer_size, client->process_arg);
control->state = Finished;
} else {
status = 0;
}
-
- /* if status was non-zero, this will not return (it will call
+
+ /* if status was non-zero, this will not return (it will call
jack_client_thread_suicide()
- */
-
+ */
+
jack_cycle_signal (client, status);
}
}
@@ -2190,12 +2225,13 @@ jack_process_thread_work (void* arg)
jack_nframes_t
jack_thread_wait (jack_client_t* client, int status)
{
- static int msg_delivered = 0;
- if (!msg_delivered) {
- jack_error("jack_thread_wait(): deprecated, use jack_cycle_wait/jack_cycle_signal");
- msg_delivered = 1;
- }
- return 0;
+ static int msg_delivered = 0;
+
+ if (!msg_delivered) {
+ jack_error ("jack_thread_wait(): deprecated, use jack_cycle_wait/jack_cycle_signal");
+ msg_delivered = 1;
+ }
+ return 0;
}
jack_nframes_t jack_cycle_wait (jack_client_t* client)
@@ -2203,38 +2239,38 @@ jack_nframes_t jack_cycle_wait (jack_client_t* client)
jack_client_control_t *control = client->control;
/* SECTION TWO: WAIT FOR NEXT DATA PROCESSING TIME */
-
+
#ifdef JACK_USE_MACH_THREADS
- /* on OS X systems, this thread is running a callback provided
- by the client that has called this function in order to wait
- for the next process callback. This is how we do that ...
- */
- jack_client_suspend (client);
+ /* on OS X systems, this thread is running a callback provided
+ by the client that has called this function in order to wait
+ for the next process callback. This is how we do that ...
+ */
+ jack_client_suspend (client);
#else
- /* on non-OSX systems, this thread is running a callback provided
- by the client that has called this function in order to wait
- for the next process() callback or the next event from the
- server.
- */
+ /* on non-OSX systems, this thread is running a callback provided
+ by the client that has called this function in order to wait
+ for the next process() callback or the next event from the
+ server.
+ */
if (jack_client_core_wait (client)) {
return 0;
}
#endif
-
- /* SECTION THREE: START NEXT DATA PROCESSING TIME */
-
+
+ /* SECTION THREE: START NEXT DATA PROCESSING TIME */
+
/* Time to do data processing */
-
- control->awake_at = jack_get_microseconds();
+
+ control->awake_at = jack_get_microseconds ();
client->control->state = Running;
-
+
/* begin preemption checking */
CHECK_PREEMPTION (client->engine, TRUE);
-
+
if (client->control->sync_cb_cbset) {
jack_call_sync_client (client);
- }
-
+ }
+
return client->engine->buffer_size;
}
@@ -2242,69 +2278,69 @@ void jack_cycle_signal (jack_client_t* client, int status)
{
client->control->last_status = status;
- /* SECTION ONE: HOUSEKEEPING/CLEANUP FROM LAST DATA PROCESSING */
-
+ /* SECTION ONE: HOUSEKEEPING/CLEANUP FROM LAST DATA PROCESSING */
+
/* housekeeping/cleanup after data processing */
-
+
if (status == 0 && client->control->timebase_cb_cbset) {
jack_call_timebase_master (client);
}
-
+
/* end preemption checking */
CHECK_PREEMPTION (client->engine, FALSE);
-
- client->control->finished_at = jack_get_microseconds();
- client->control->state = Finished;
-
- /* wake the next client in the chain (could be the server),
+
+ client->control->finished_at = jack_get_microseconds ();
+ client->control->state = Finished;
+
+ /* wake the next client in the chain (could be the server),
and check if we were killed during the process
cycle.
- */
-
+ */
+
if (jack_wake_next_client (client)) {
- DEBUG("client cannot wake next, or is dead\n");
+ DEBUG ("client cannot wake next, or is dead\n");
jack_client_thread_suicide (client, "graph error");
/*NOTREACHED*/
}
-
- if (client->control->dead) {
+
+ if (client->control->dead) {
jack_client_thread_suicide (client, "zombified");
/*NOTREACHED*/
- }
+ }
if (status) {
jack_client_thread_suicide (client, "process error");
/*NOTREACHED*/
}
- if (!client->engine->engine_ok) {
+ if (!client->engine->engine_ok) {
jack_client_thread_suicide (client, "JACK died");
/*NOTREACHED*/
- }
+ }
}
static int
jack_start_thread (jack_client_t *client)
{
#ifdef USE_MLOCK
- if (client->engine->real_time) {
+ if (client->engine->real_time) {
if (client->engine->do_mlock
&& (mlockall (MCL_CURRENT | MCL_FUTURE) != 0)) {
jack_error ("cannot lock down memory for RT thread "
"(%s)", strerror (errno));
- }
-
- if (client->engine->do_munlock) {
- cleanup_mlock ();
- }
+ }
+
+ if (client->engine->do_munlock) {
+ cleanup_mlock ();
+ }
}
-#endif /* USE_MLOCK */
+#endif /* USE_MLOCK */
#ifdef JACK_USE_MACH_THREADS
/* Stephane Letz : letz@grame.fr
On MacOSX, the event/callback-handling thread does not need to be real-time.
-*/
- if (jack_client_create_thread (client,
+ */
+ if (jack_client_create_thread (client,
&client->thread,
client->engine->client_priority,
FALSE,
@@ -2313,10 +2349,10 @@ jack_start_thread (jack_client_t *client)
}
#else
if (jack_client_create_thread (client,
- &client->thread,
- client->engine->client_priority,
- client->engine->real_time,
- jack_process_thread_work, client)) {
+ &client->thread,
+ client->engine->client_priority,
+ client->engine->real_time,
+ jack_process_thread_work, client)) {
return -1;
}
@@ -2332,21 +2368,21 @@ jack_start_thread (jack_client_t *client)
methods that encapsulated the underlying mechanism
used.
- */
+ */
- if (jack_client_create_thread(client,
- &client->process_thread,
- client->engine->client_priority,
- client->engine->real_time,
- jack_process_thread_work, client)) {
+ if (jack_client_create_thread (client,
+ &client->process_thread,
+ client->engine->client_priority,
+ client->engine->real_time,
+ jack_process_thread_work, client)) {
return -1;
}
-#endif /* JACK_USE_MACH_THREADS */
+#endif /* JACK_USE_MACH_THREADS */
return 0;
}
-int
+int
jack_activate (jack_client_t *client)
{
jack_request_t req;
@@ -2368,9 +2404,9 @@ jack_activate (jack_client_t *client)
/* we need to ask the engine for realtime capabilities
before trying to start the realtime thread
- */
+ */
- VALGRIND_MEMSET (&req, 0, sizeof (req));
+ VALGRIND_MEMSET (&req, 0, sizeof(req));
req.type = SetClientCapabilities;
req.x.client_id = client->control->id;
@@ -2387,19 +2423,19 @@ jack_activate (jack_client_t *client)
give the client the required capabilities.
For now, leave the client so that it
still runs, albeit non-realtime.
- */
-
+ */
+
jack_error ("could not receive realtime capabilities, "
"client will run non-realtime");
- }
+ }
}
-#endif /* USE_CAPABILITIES */
+#endif /* USE_CAPABILITIES */
if (client->first_active) {
pthread_mutex_init (&client_lock, NULL);
pthread_cond_init (&client_ready, NULL);
-
+
pthread_mutex_lock (&client_lock);
if (jack_start_thread (client)) {
@@ -2418,7 +2454,7 @@ jack_activate (jack_client_t *client)
client->first_active = FALSE;
}
- startit:
+startit:
req.type = ActivateClient;
jack_uuid_copy (&req.x.client_id, client->control->uuid);
@@ -2426,16 +2462,16 @@ jack_activate (jack_client_t *client)
return jack_client_deliver_request (client, &req);
}
-static int
+static int
jack_deactivate_aux (jack_client_t *client)
{
jack_request_t req;
- int rc = ESRCH; /* already shut down */
-
- if (client && client->control) { /* not shut down? */
+ int rc = ESRCH; /* already shut down */
+
+ if (client && client->control) { /* not shut down? */
rc = 0;
- if (client->control->active) { /* still active? */
- VALGRIND_MEMSET (&req, 0, sizeof (req));
+ if (client->control->active) { /* still active? */
+ VALGRIND_MEMSET (&req, 0, sizeof(req));
req.type = DeactivateClient;
jack_uuid_copy (&req.x.client_id, client->control->uuid);
rc = jack_client_deliver_request (client, &req);
@@ -2444,10 +2480,10 @@ jack_deactivate_aux (jack_client_t *client)
return rc;
}
-int
+int
jack_deactivate (jack_client_t *client)
{
- return jack_deactivate_aux(client);
+ return jack_deactivate_aux (client);
}
static int
@@ -2458,13 +2494,13 @@ jack_client_close_aux (jack_client_t *client)
int rc;
rc = jack_deactivate_aux (client);
- if (rc == ESRCH) { /* already shut down? */
+ if (rc == ESRCH) { /* already shut down? */
return rc;
}
if (client->control->type == ClientExternal) {
-#if JACK_USE_MACH_THREADS
+#if JACK_USE_MACH_THREADS
if (client->rt_thread_ok) {
// MacOSX pthread_cancel not implemented in
// Darwin 5.5, 6.4
@@ -2473,12 +2509,12 @@ jack_client_close_aux (jack_client_t *client)
thread_terminate (machThread);
}
#endif
-
+
/* stop the thread that communicates with the jack
- * server, only if it was actually running
+ * server, only if it was actually running
*/
-
- if (client->thread_ok){
+
+ if (client->thread_ok) {
pthread_cancel (client->thread);
pthread_join (client->thread, &status);
}
@@ -2494,9 +2530,8 @@ jack_client_close_aux (jack_client_t *client)
if (client->port_segment) {
jack_port_type_id_t ptid;
- for (ptid = 0; ptid < client->n_port_types; ++ptid) {
+ for (ptid = 0; ptid < client->n_port_types; ++ptid)
jack_release_shm (&client->port_segment[ptid]);
- }
free (client->port_segment);
client->port_segment = NULL;
}
@@ -2505,12 +2540,12 @@ jack_client_close_aux (jack_client_t *client)
if (client->graph_wait_fd >= 0) {
close (client->graph_wait_fd);
}
-
+
if (client->graph_next_fd >= 0) {
close (client->graph_next_fd);
}
-#endif
-
+#endif
+
close (client->event_fd);
if (shutdown (client->request_fd, SHUT_RDWR)) {
@@ -2521,13 +2556,11 @@ jack_client_close_aux (jack_client_t *client)
}
- for (node = client->ports; node; node = jack_slist_next (node)) {
+ for (node = client->ports; node; node = jack_slist_next (node))
free (node->data);
- }
jack_slist_free (client->ports);
- for (node = client->ports_ext; node; node = jack_slist_next (node)) {
+ for (node = client->ports_ext; node; node = jack_slist_next (node))
free (node->data);
- }
jack_slist_free (client->ports_ext);
jack_client_free (client);
jack_messagebuffer_exit ();
@@ -2538,16 +2571,16 @@ jack_client_close_aux (jack_client_t *client)
int
jack_client_close (jack_client_t *client)
{
- return jack_client_close_aux(client);
-}
+ return jack_client_close_aux (client);
+}
-int
+int
jack_is_realtime (jack_client_t *client)
{
return client->engine->real_time;
}
-jack_nframes_t
+jack_nframes_t
jack_get_buffer_size (jack_client_t *client)
{
return client->engine->buffer_size;
@@ -2559,11 +2592,11 @@ jack_set_buffer_size (jack_client_t *client, jack_nframes_t nframes)
#ifdef DO_BUFFER_RESIZE
jack_request_t req;
- VALGRIND_MEMSET (&req, 0, sizeof (req));
+ VALGRIND_MEMSET (&req, 0, sizeof(req));
- if (nframes < 1 || nframes > 16384) {
- return ERANGE;
- }
+ if (nframes < 1 || nframes > 16384) {
+ return ERANGE;
+ }
req.type = SetBufferSize;
req.x.nframes = nframes;
@@ -2572,23 +2605,23 @@ jack_set_buffer_size (jack_client_t *client, jack_nframes_t nframes)
#else
return ENOSYS;
-#endif /* DO_BUFFER_RESIZE */
+#endif /* DO_BUFFER_RESIZE */
}
-int
+int
jack_connect (jack_client_t *client, const char *source_port,
const char *destination_port)
{
jack_request_t req;
- VALGRIND_MEMSET (&req, 0, sizeof (req));
+ VALGRIND_MEMSET (&req, 0, sizeof(req));
req.type = ConnectPorts;
snprintf (req.x.connect.source_port,
- sizeof (req.x.connect.source_port), "%s", source_port);
+ sizeof(req.x.connect.source_port), "%s", source_port);
snprintf (req.x.connect.destination_port,
- sizeof (req.x.connect.destination_port),
+ sizeof(req.x.connect.destination_port),
"%s", destination_port);
return jack_client_deliver_request (client, &req);
@@ -2608,7 +2641,7 @@ jack_port_disconnect (jack_client_t *client, jack_port_t *port)
pthread_mutex_unlock (&port->connection_lock);
- VALGRIND_MEMSET (&req, 0, sizeof (req));
+ VALGRIND_MEMSET (&req, 0, sizeof(req));
req.type = DisconnectPort;
req.x.port_info.port_id = port->shared->id;
@@ -2616,38 +2649,38 @@ jack_port_disconnect (jack_client_t *client, jack_port_t *port)
return jack_client_deliver_request (client, &req);
}
-int
+int
jack_disconnect (jack_client_t *client, const char *source_port,
const char *destination_port)
{
jack_request_t req;
- VALGRIND_MEMSET (&req, 0, sizeof (req));
+ VALGRIND_MEMSET (&req, 0, sizeof(req));
req.type = DisconnectPorts;
snprintf (req.x.connect.source_port,
- sizeof (req.x.connect.source_port), "%s", source_port);
+ sizeof(req.x.connect.source_port), "%s", source_port);
snprintf (req.x.connect.destination_port,
- sizeof (req.x.connect.destination_port),
+ sizeof(req.x.connect.destination_port),
"%s", destination_port);
-
+
return jack_client_deliver_request (client, &req);
}
void
-jack_set_error_function (void (*func) (const char *))
+jack_set_error_function (void (*func)(const char *))
{
jack_error_callback = func;
}
void
-jack_set_info_function (void (*func) (const char *))
+jack_set_info_function (void (*func)(const char *))
{
jack_info_callback = func;
}
-int
+int
jack_set_graph_order_callback (jack_client_t *client,
JackGraphOrderCallback callback, void *arg)
{
@@ -2661,9 +2694,9 @@ jack_set_graph_order_callback (jack_client_t *client,
return 0;
}
-int
+int
jack_set_latency_callback (jack_client_t *client,
- JackLatencyCallback callback, void *arg)
+ JackLatencyCallback callback, void *arg)
{
if (client->control->active) {
jack_error ("You cannot set callbacks on an active client.");
@@ -2686,7 +2719,7 @@ int jack_set_xrun_callback (jack_client_t *client,
client->xrun = callback;
client->xrun_arg = arg;
client->control->xrun_cbset = (callback != NULL);
- return 0;
+ return 0;
}
int
@@ -2698,12 +2731,12 @@ jack_set_process_callback (jack_client_t *client,
jack_error ("You cannot set callbacks on an active client.");
return -1;
}
-
+
if (client->control->thread_cb_cbset) {
jack_error ("A thread callback has already been setup, both models cannot be used at the same time!");
return -1;
}
-
+
client->process_arg = arg;
client->process = callback;
client->control->process_cbset = (callback != NULL);
@@ -2756,8 +2789,8 @@ jack_set_buffer_size_callback (jack_client_t *client,
int
jack_set_port_rename_callback (jack_client_t *client,
- JackPortRenameCallback callback,
- void *arg)
+ JackPortRenameCallback callback,
+ void *arg)
{
if (client->control->active) {
jack_error ("You cannot set callbacks on an active client.");
@@ -2770,9 +2803,9 @@ jack_set_port_rename_callback (jack_client_t *client,
}
int
-jack_set_port_registration_callback(jack_client_t *client,
- JackPortRegistrationCallback callback,
- void *arg)
+jack_set_port_registration_callback (jack_client_t *client,
+ JackPortRegistrationCallback callback,
+ void *arg)
{
if (client->control->active) {
jack_error ("You cannot set callbacks on an active client.");
@@ -2785,9 +2818,9 @@ jack_set_port_registration_callback(jack_client_t *client,
}
int
-jack_set_port_connect_callback(jack_client_t *client,
- JackPortConnectCallback callback,
- void *arg)
+jack_set_port_connect_callback (jack_client_t *client,
+ JackPortConnectCallback callback,
+ void *arg)
{
if (client->control->active) {
jack_error ("You cannot set callbacks on an active client.");
@@ -2800,9 +2833,9 @@ jack_set_port_connect_callback(jack_client_t *client,
}
int
-jack_set_client_registration_callback(jack_client_t *client,
- JackClientRegistrationCallback callback,
- void *arg)
+jack_set_client_registration_callback (jack_client_t *client,
+ JackClientRegistrationCallback callback,
+ void *arg)
{
if (client->control->active) {
jack_error ("You cannot set callbacks on an active client.");
@@ -2815,13 +2848,13 @@ jack_set_client_registration_callback(jack_client_t *client,
}
int
-jack_set_process_thread(jack_client_t* client, JackThreadCallback callback, void *arg)
+jack_set_process_thread (jack_client_t* client, JackThreadCallback callback, void *arg)
{
if (client->control->active) {
jack_error ("You cannot set callbacks on an active client.");
return -1;
}
-
+
if (client->control->process_cbset) {
jack_error ("A process callback has already been setup, both models cannot be used at the same time!");
return -1;
@@ -2834,7 +2867,7 @@ jack_set_process_thread(jack_client_t* client, JackThreadCallback callback, void
}
int
-jack_set_session_callback(jack_client_t* client, JackSessionCallback callback, void *arg)
+jack_set_session_callback (jack_client_t* client, JackSessionCallback callback, void *arg)
{
if (client->control->active) {
jack_error ("You cannot set callbacks on an active client.");
@@ -2869,64 +2902,68 @@ jack_on_info_shutdown (jack_client_t *client, void (*function)(jack_status_t, co
char *
jack_get_client_name_by_uuid (jack_client_t *client, const char *uuid_str)
-{
+{
jack_request_t request;
-
- VALGRIND_MEMSET (&request, 0, sizeof (request));
- if (jack_uuid_parse (uuid_str, &request.x.client_id) != 0) {
- return NULL;
- }
+ VALGRIND_MEMSET (&request, 0, sizeof(request));
+
+ if (jack_uuid_parse (uuid_str, &request.x.client_id) != 0) {
+ return NULL;
+ }
request.type = GetClientByUUID;
- if( jack_client_deliver_request (client, &request))
+ if ( jack_client_deliver_request (client, &request)) {
return NULL;
+ }
- return strdup (request.x.port_info.name);
+ return strdup (request.x.port_info.name);
}
char*
jack_get_uuid_for_client_name (jack_client_t *client, const char *client_name)
{
jack_request_t request;
- size_t len = strlen(client_name) + 1;
- if ( len > sizeof(request.x.name) )
+ size_t len = strlen (client_name) + 1;
+
+ if ( len > sizeof(request.x.name) ) {
return NULL;
+ }
- VALGRIND_MEMSET (&request, 0, sizeof (request));
+ VALGRIND_MEMSET (&request, 0, sizeof(request));
request.type = GetUUIDByClientName;
- memcpy(request.x.name, client_name, len);
+ memcpy (request.x.name, client_name, len);
- if (jack_client_deliver_request( client, &request)) {
+ if (jack_client_deliver_request ( client, &request)) {
return NULL;
- }
+ }
- char buf[37];
- jack_uuid_unparse (request.x.client_id, buf);
- return strdup (buf);
+ char buf[37];
+ jack_uuid_unparse (request.x.client_id, buf);
+ return strdup (buf);
}
char *
jack_client_get_uuid (jack_client_t *client)
-{
+{
char retval[37];
- jack_uuid_unparse (client->control->uuid, retval);
+
+ jack_uuid_unparse (client->control->uuid, retval);
return strdup (retval);
}
int
jack_reserve_client_name (jack_client_t *client, const char *name, const char *uuid_str)
-{
+{
jack_request_t request;
- VALGRIND_MEMSET (&request, 0, sizeof (request));
+ VALGRIND_MEMSET (&request, 0, sizeof(request));
request.type = ReserveName;
- snprintf( request.x.reservename.name, sizeof( request.x.reservename.name ), "%s", name );
- if (jack_uuid_parse (uuid_str, &request.x.reservename.uuid) != 0) {
- return -1;
- }
+ snprintf ( request.x.reservename.name, sizeof( request.x.reservename.name ), "%s", name );
+ if (jack_uuid_parse (uuid_str, &request.x.reservename.uuid) != 0) {
+ return -1;
+ }
return jack_client_deliver_request (client, &request);
}
@@ -2950,17 +2987,17 @@ jack_get_ports (jack_client_t *client,
if (port_name_pattern && port_name_pattern[0]) {
regcomp (&port_regex, port_name_pattern,
- REG_EXTENDED|REG_NOSUB);
+ REG_EXTENDED | REG_NOSUB);
}
if (type_name_pattern && type_name_pattern[0]) {
regcomp (&type_regex, type_name_pattern,
- REG_EXTENDED|REG_NOSUB);
+ REG_EXTENDED | REG_NOSUB);
}
psp = engine->ports;
match_cnt = 0;
- if ((matching_ports = (const char **) malloc (sizeof (char *) * (engine->port_max + 1))) == NULL) {
+ if ((matching_ports = (const char**)malloc (sizeof(char *) * (engine->port_max + 1))) == NULL) {
return NULL;
}
@@ -2981,7 +3018,7 @@ jack_get_ports (jack_client_t *client,
if (regexec (&port_regex, psp[i].name, 0, NULL, 0)) {
matching = 0;
}
- }
+ }
if (matching && type_name_pattern && type_name_pattern[0]) {
jack_port_type_id_t ptid = psp[i].ptype_id;
@@ -2990,8 +3027,8 @@ jack_get_ports (jack_client_t *client,
0, NULL, 0)) {
matching = 0;
}
- }
-
+ }
+
if (matching) {
matching_ports[match_cnt++] = psp[i].name;
}
@@ -3007,8 +3044,8 @@ jack_get_ports (jack_client_t *client,
free (matching_ports);
matching_ports = 0;
} else {
- matching_ports[match_cnt] = 0;
- }
+ matching_ports[match_cnt] = 0;
+ }
return matching_ports;
}
@@ -3040,28 +3077,28 @@ jack_reset_max_delayed_usecs (jack_client_t *client)
pthread_t
jack_client_thread_id (jack_client_t *client)
{
- if (client->control->type != ClientExternal) {
- /* Internal and driver clients run in ... ??? */
- return 0;
- }
+ if (client->control->type != ClientExternal) {
+ /* Internal and driver clients run in ... ??? */
+ return 0;
+ }
return client->thread_id;
}
int
-jack_client_name_size(void)
+jack_client_name_size (void)
{
return JACK_CLIENT_NAME_SIZE;
}
int
-jack_port_name_size(void)
+jack_port_name_size (void)
{
return JACK_PORT_NAME_SIZE;
}
int
-jack_port_type_size(void)
+jack_port_type_size (void)
{
return JACK_PORT_TYPE_SIZE;
}
@@ -3075,44 +3112,44 @@ jack_free (void* ptr)
const char*
jack_event_type_name (JackEventType type)
{
- switch (type) {
- case BufferSizeChange:
- return "buffer size change";
- case SampleRateChange:
- return "sample rate change";
- case AttachPortSegment:
- return "port segment attached";
- case PortConnected:
- return "ports connected";
- case PortDisconnected:
- return "ports disconnected";
- case GraphReordered:
- return "graph reordered";
- case PortRegistered:
- return "port registered";
- case PortUnregistered:
- return "port unregistered";
- case XRun:
- return "xrun";
- case StartFreewheel:
- return "freewheel started";
- case StopFreewheel:
- return "freewheel stopped";
- case ClientRegistered:
- return "client registered";
- case ClientUnregistered:
- return "client unregistered";
- case SaveSession:
- return "save session";
- case LatencyCallback:
- return "latency callback";
- case PropertyChange:
- return "property change callback";
- case PortRename:
- return "port rename";
- default:
- break;
- }
-
- return "unknown";
+ switch (type) {
+ case BufferSizeChange:
+ return "buffer size change";
+ case SampleRateChange:
+ return "sample rate change";
+ case AttachPortSegment:
+ return "port segment attached";
+ case PortConnected:
+ return "ports connected";
+ case PortDisconnected:
+ return "ports disconnected";
+ case GraphReordered:
+ return "graph reordered";
+ case PortRegistered:
+ return "port registered";
+ case PortUnregistered:
+ return "port unregistered";
+ case XRun:
+ return "xrun";
+ case StartFreewheel:
+ return "freewheel started";
+ case StopFreewheel:
+ return "freewheel stopped";
+ case ClientRegistered:
+ return "client registered";
+ case ClientUnregistered:
+ return "client unregistered";
+ case SaveSession:
+ return "save session";
+ case LatencyCallback:
+ return "latency callback";
+ case PropertyChange:
+ return "property change callback";
+ case PortRename:
+ return "port rename";
+ default:
+ break;
+ }
+
+ return "unknown";
}
diff --git a/libjack/driver.c b/libjack/driver.c
index f5093af..cbffed9 100644
--- a/libjack/driver.c
+++ b/libjack/driver.c
@@ -1,22 +1,22 @@
/* -*- mode: c; c-file-style: "linux"; -*- */
/*
Copyright (C) 2001-2003 Paul Davis
-
+
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
+ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-*/
+
+ */
#include <config.h>
#include <stdio.h>
@@ -36,22 +36,46 @@
#include <sys/mman.h>
#endif /* USE_MLOCK */
-static int dummy_attach (jack_driver_t *drv, jack_engine_t *eng) { return 0; }
-static int dummy_detach (jack_driver_t *drv, jack_engine_t *eng) { return 0; }
+static int dummy_attach (jack_driver_t *drv, jack_engine_t *eng)
+{
+ return 0;
+}
+static int dummy_detach (jack_driver_t *drv, jack_engine_t *eng)
+{
+ return 0;
+}
static int dummy_write (jack_driver_t *drv,
- jack_nframes_t nframes) { return 0; }
-static int dummy_read (jack_driver_t *drv, jack_nframes_t nframes) { return 0; }
+ jack_nframes_t nframes)
+{
+ return 0;
+}
+static int dummy_read (jack_driver_t *drv, jack_nframes_t nframes)
+{
+ return 0;
+}
static int dummy_null_cycle (jack_driver_t *drv,
- jack_nframes_t nframes) { return 0; }
+ jack_nframes_t nframes)
+{
+ return 0;
+}
static int dummy_bufsize (jack_driver_t *drv,
- jack_nframes_t nframes) {return 0;}
-static int dummy_stop (jack_driver_t *drv) { return 0; }
-static int dummy_start (jack_driver_t *drv) { return 0; }
+ jack_nframes_t nframes)
+{
+ return 0;
+}
+static int dummy_stop (jack_driver_t *drv)
+{
+ return 0;
+}
+static int dummy_start (jack_driver_t *drv)
+{
+ return 0;
+}
void
jack_driver_init (jack_driver_t *driver)
{
- memset (driver, 0, sizeof (*driver));
+ memset (driver, 0, sizeof(*driver));
driver->attach = dummy_attach;
driver->detach = dummy_detach;
@@ -66,12 +90,21 @@ jack_driver_init (jack_driver_t *driver)
/****************************
- *** Non-Threaded Drivers ***
- ****************************/
+*** Non-Threaded Drivers ***
+****************************/
-static int dummy_nt_run_cycle (jack_driver_nt_t *drv) { return 0; }
-static int dummy_nt_attach (jack_driver_nt_t *drv) { return 0; }
-static int dummy_nt_detach (jack_driver_nt_t *drv) { return 0; }
+static int dummy_nt_run_cycle (jack_driver_nt_t *drv)
+{
+ return 0;
+}
+static int dummy_nt_attach (jack_driver_nt_t *drv)
+{
+ return 0;
+}
+static int dummy_nt_detach (jack_driver_nt_t *drv)
+{
+ return 0;
+}
/*
@@ -104,16 +137,16 @@ jack_driver_nt_detach (jack_driver_nt_t * driver, jack_engine_t * engine)
static void *
jack_driver_nt_thread (void * arg)
{
- jack_driver_nt_t * driver = (jack_driver_nt_t *) arg;
+ jack_driver_nt_t * driver = (jack_driver_nt_t*)arg;
int rc = 0;
int run;
/* This thread may start running before pthread_create()
* actually stores the driver->nt_thread value. It's safer to
- * store it here as well.
+ * store it here as well.
*/
- driver->nt_thread = pthread_self();
+ driver->nt_thread = pthread_self ();
pthread_mutex_lock (&driver->nt_run_lock);
@@ -130,7 +163,7 @@ jack_driver_nt_thread (void * arg)
pthread_mutex_unlock (&driver->nt_run_lock);
- out:
+out:
if (rc) {
driver->nt_run = DRIVER_NT_DYING;
driver->engine->driver_exit (driver->engine);
@@ -145,13 +178,13 @@ jack_driver_nt_start (jack_driver_nt_t * driver)
/* stop the new thread from really starting until the driver has
been started.
- */
-
+ */
+
pthread_mutex_lock (&driver->nt_run_lock);
driver->nt_run = DRIVER_NT_RUN;
if ((err = jack_client_create_thread (NULL,
- &driver->nt_thread,
+ &driver->nt_thread,
driver->engine->rtpriority,
driver->engine->control->real_time,
jack_driver_nt_thread, driver)) != 0) {
@@ -180,7 +213,7 @@ jack_driver_nt_do_stop (jack_driver_nt_t * driver, int run)
int err;
pthread_mutex_lock (&driver->nt_run_lock);
- if(driver->nt_run != DRIVER_NT_DYING) {
+ if (driver->nt_run != DRIVER_NT_DYING) {
driver->nt_run = run;
}
pthread_mutex_unlock (&driver->nt_run_lock);
@@ -189,7 +222,7 @@ jack_driver_nt_do_stop (jack_driver_nt_t * driver, int run)
if (driver->nt_thread && driver->nt_run != DRIVER_NT_DYING
&& (err = pthread_join (driver->nt_thread, NULL)) != 0) {
jack_error ("DRIVER NT: error waiting for driver thread: %s",
- strerror (err));
+ strerror (err));
return err;
}
@@ -235,19 +268,19 @@ jack_driver_nt_bufsize (jack_driver_nt_t * driver, jack_nframes_t nframes)
void
jack_driver_nt_init (jack_driver_nt_t * driver)
{
- memset (driver, 0, sizeof (*driver));
+ memset (driver, 0, sizeof(*driver));
- jack_driver_init ((jack_driver_t *) driver);
+ jack_driver_init ((jack_driver_t*)driver);
- driver->attach = (JackDriverAttachFunction) jack_driver_nt_attach;
- driver->detach = (JackDriverDetachFunction) jack_driver_nt_detach;
- driver->bufsize = (JackDriverBufSizeFunction) jack_driver_nt_bufsize;
- driver->stop = (JackDriverStopFunction) jack_driver_nt_stop;
- driver->start = (JackDriverStartFunction) jack_driver_nt_start;
+ driver->attach = (JackDriverAttachFunction)jack_driver_nt_attach;
+ driver->detach = (JackDriverDetachFunction)jack_driver_nt_detach;
+ driver->bufsize = (JackDriverBufSizeFunction)jack_driver_nt_bufsize;
+ driver->stop = (JackDriverStopFunction)jack_driver_nt_stop;
+ driver->start = (JackDriverStartFunction)jack_driver_nt_start;
- driver->nt_bufsize = (JackDriverNTBufSizeFunction) dummy_bufsize;
- driver->nt_start = (JackDriverNTStartFunction) dummy_start;
- driver->nt_stop = (JackDriverNTStopFunction) dummy_stop;
+ driver->nt_bufsize = (JackDriverNTBufSizeFunction)dummy_bufsize;
+ driver->nt_start = (JackDriverNTStartFunction)dummy_start;
+ driver->nt_stop = (JackDriverNTStopFunction)dummy_stop;
driver->nt_attach = dummy_nt_attach;
driver->nt_detach = dummy_nt_detach;
driver->nt_run_cycle = dummy_nt_run_cycle;
@@ -257,7 +290,7 @@ jack_driver_nt_init (jack_driver_nt_t * driver)
}
void
-jack_driver_nt_finish (jack_driver_nt_t * driver)
+jack_driver_nt_finish (jack_driver_nt_t * driver)
{
pthread_mutex_destroy (&driver->nt_run_lock);
}
diff --git a/libjack/intclient.c b/libjack/intclient.c
index e06722b..cc8d1e3 100644
--- a/libjack/intclient.c
+++ b/libjack/intclient.c
@@ -1,19 +1,19 @@
/* -*- mode: c; c-file-style: "bsd"; -*- */
/*
* Copyright (C) 2004 Jack O'Quin
- *
+ *
* 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
+ * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
@@ -34,59 +34,62 @@
#include "local.h"
static int
-jack_intclient_request(RequestType type, jack_client_t *client,
- const char* client_name, jack_options_t options,
- jack_status_t *status, jack_intclient_t uuid, jack_varargs_t *va)
+jack_intclient_request (RequestType type, jack_client_t *client,
+ const char* client_name, jack_options_t options,
+ jack_status_t *status, jack_intclient_t uuid, jack_varargs_t *va)
{
jack_request_t req;
- memset (&req, 0, sizeof (req));
+ memset (&req, 0, sizeof(req));
- if (strlen (client_name) >= sizeof (req.x.intclient.name)) {
+ if (strlen (client_name) >= sizeof(req.x.intclient.name)) {
jack_error ("\"%s\" is too long for a JACK client name.\n"
"Please use %lu characters or less.",
- client_name, sizeof (req.x.intclient.name));
+ client_name, sizeof(req.x.intclient.name));
return -1;
}
if (va->load_name
- && (strlen (va->load_name) > sizeof (req.x.intclient.path) - 1)) {
+ && (strlen (va->load_name) > sizeof(req.x.intclient.path) - 1)) {
jack_error ("\"%s\" is too long for a shared object name.\n"
- "Please use %lu characters or less.",
- va->load_name, sizeof (req.x.intclient.path) - 1);
- *status |= (JackFailure|JackInvalidOption);
+ "Please use %lu characters or less.",
+ va->load_name, sizeof(req.x.intclient.path) - 1);
+ *status |= (JackFailure | JackInvalidOption);
return -1;
}
if (va->load_init
- && (strlen (va->load_init) > sizeof (req.x.intclient.init) - 1)) {
+ && (strlen (va->load_init) > sizeof(req.x.intclient.init) - 1)) {
jack_error ("\"%s\" is too long for internal client init "
"string.\nPlease use %lu characters or less.",
- va->load_init, sizeof (req.x.intclient.init) - 1);
- *status |= (JackFailure|JackInvalidOption);
+ va->load_init, sizeof(req.x.intclient.init) - 1);
+ *status |= (JackFailure | JackInvalidOption);
return -1;
}
req.type = type;
req.x.intclient.options = options;
strncpy (req.x.intclient.name, client_name,
- sizeof (req.x.intclient.name));
- if (va->load_name)
+ sizeof(req.x.intclient.name));
+ if (va->load_name) {
strncpy (req.x.intclient.path, va->load_name,
- sizeof (req.x.intclient.path));
- if (va->load_init)
+ sizeof(req.x.intclient.path));
+ }
+ if (va->load_init) {
strncpy (req.x.intclient.init, va->load_init,
- sizeof (req.x.intclient.init));
+ sizeof(req.x.intclient.init));
+ }
jack_client_deliver_request (client, &req);
*status |= req.status;
- if (*status & JackFailure)
+ if (*status & JackFailure) {
return -1;
+ }
jack_uuid_copy (&uuid, req.x.intclient.uuid);
- return 0;
+ return 0;
}
char *
@@ -96,7 +99,7 @@ jack_get_internal_client_name (jack_client_t *client,
jack_request_t req;
char *name;
- memset (&req, 0, sizeof (req));
+ memset (&req, 0, sizeof(req));
req.type = IntClientName;
req.x.intclient.options = JackNullOption;
jack_uuid_copy (&req.x.intclient.uuid, intclient);
@@ -119,48 +122,50 @@ int
jack_internal_client_handle (jack_client_t *client,
const char *client_name,
jack_status_t *status,
- jack_intclient_t *handle)
+ jack_intclient_t *handle)
{
jack_request_t req;
jack_status_t my_status;
- if (status == NULL) /* no status from caller? */
- status = &my_status; /* use local status word */
+ if (status == NULL) { /* no status from caller? */
+ status = &my_status; /* use local status word */
+ }
*status = 0;
- memset (&req, 0, sizeof (req));
+ memset (&req, 0, sizeof(req));
req.type = IntClientHandle;
req.x.intclient.options = JackNullOption;
strncpy (req.x.intclient.name, client_name,
- sizeof (req.x.intclient.name));
+ sizeof(req.x.intclient.name));
*status = jack_client_deliver_request (client, &req);
- if (!jack_uuid_empty (req.x.intclient.uuid)) {
- jack_uuid_copy (handle, req.x.intclient.uuid);
- return 0;
- }
+ if (!jack_uuid_empty (req.x.intclient.uuid)) {
+ jack_uuid_copy (handle, req.x.intclient.uuid);
+ return 0;
+ }
- return -1;
+ return -1;
}
int
jack_internal_client_load_aux (jack_client_t *client,
- const char *client_name,
- jack_options_t options,
- jack_status_t *status,
- jack_intclient_t handle, va_list ap)
+ const char *client_name,
+ jack_options_t options,
+ jack_status_t *status,
+ jack_intclient_t handle, va_list ap)
{
jack_varargs_t va;
jack_status_t my_status;
- if (status == NULL) /* no status from caller? */
- status = &my_status; /* use local status word */
+ if (status == NULL) { /* no status from caller? */
+ status = &my_status; /* use local status word */
+ }
*status = 0;
/* validate parameters */
if ((options & ~JackLoadOptions)) {
- *status |= (JackFailure|JackInvalidOption);
+ *status |= (JackFailure | JackInvalidOption);
return -1;
}
@@ -175,14 +180,15 @@ int
jack_internal_client_load (jack_client_t *client,
const char *client_name,
jack_options_t options,
- jack_status_t *status,
- jack_intclient_t handle, ...)
+ jack_status_t *status,
+ jack_intclient_t handle, ...)
{
- va_list ap;
- va_start(ap, handle);
- int res = jack_internal_client_load_aux(client, client_name, options, status, handle, ap);
- va_end(ap);
- return res;
+ va_list ap;
+
+ va_start (ap, handle);
+ int res = jack_internal_client_load_aux (client, client_name, options, status, handle, ap);
+ va_end (ap);
+ return res;
}
jack_status_t
@@ -194,15 +200,15 @@ jack_internal_client_unload (jack_client_t *client,
if (intclient) {
- memset (&req, 0, sizeof (req));
+ memset (&req, 0, sizeof(req));
req.type = IntClientUnload;
req.x.intclient.options = JackNullOption;
jack_uuid_copy (&req.x.intclient.uuid, intclient);
jack_client_deliver_request (client, &req);
status = req.status;
- } else { /* intclient is null */
- status = (JackNoSuchClient|JackFailure);
+ } else { /* intclient is null */
+ status = (JackNoSuchClient | JackFailure);
}
return status;
diff --git a/libjack/local.h b/libjack/local.h
index 3f7f074..c90d7b0 100644
--- a/libjack/local.h
+++ b/libjack/local.h
@@ -4,100 +4,100 @@
/* Client data structure, in the client address space. */
struct _jack_client {
- jack_control_t *engine;
- jack_client_control_t *control;
- jack_shm_info_t engine_shm;
- jack_shm_info_t control_shm;
+ jack_control_t *engine;
+ jack_client_control_t *control;
+ jack_shm_info_t engine_shm;
+ jack_shm_info_t control_shm;
- struct pollfd* pollfd;
- int pollmax;
- int graph_next_fd;
- int request_fd;
- int upstream_is_jackd;
+ struct pollfd* pollfd;
+ int pollmax;
+ int graph_next_fd;
+ int request_fd;
+ int upstream_is_jackd;
- /* these two are copied from the engine when the
- * client is created.
- */
+ /* these two are copied from the engine when the
+ * client is created.
+ */
- jack_port_type_id_t n_port_types;
- jack_shm_info_t* port_segment;
+ jack_port_type_id_t n_port_types;
+ jack_shm_info_t* port_segment;
- JSList *ports;
- JSList *ports_ext;
+ JSList *ports;
+ JSList *ports_ext;
- pthread_t thread;
- char fifo_prefix[PATH_MAX+1];
- void (*on_shutdown)(void *arg);
- void *on_shutdown_arg;
- void (*on_info_shutdown)(jack_status_t, const char*, void *arg);
- void *on_info_shutdown_arg;
- char thread_ok : 1;
- char first_active : 1;
- pthread_t thread_id;
- char name[JACK_CLIENT_NAME_SIZE];
- int session_cb_immediate_reply;
+ pthread_t thread;
+ char fifo_prefix[PATH_MAX + 1];
+ void (*on_shutdown)(void *arg);
+ void *on_shutdown_arg;
+ void (*on_info_shutdown)(jack_status_t, const char*, void *arg);
+ void *on_info_shutdown_arg;
+ char thread_ok : 1;
+ char first_active : 1;
+ pthread_t thread_id;
+ char name[JACK_CLIENT_NAME_SIZE];
+ int session_cb_immediate_reply;
#ifdef JACK_USE_MACH_THREADS
- /* specific ressources for server/client real-time thread communication */
- mach_port_t clienttask, bp, serverport, replyport;
- trivial_message message;
- pthread_t process_thread;
- char rt_thread_ok : 1;
+ /* specific ressources for server/client real-time thread communication */
+ mach_port_t clienttask, bp, serverport, replyport;
+ trivial_message message;
+ pthread_t process_thread;
+ char rt_thread_ok : 1;
#endif
- /* callbacks
- */
- JackProcessCallback process;
- void *process_arg;
- JackThreadInitCallback thread_init;
- void *thread_init_arg;
- JackBufferSizeCallback bufsize;
- void *bufsize_arg;
- JackSampleRateCallback srate;
- void *srate_arg;
- JackPortRegistrationCallback port_register;
- void *port_register_arg;
- JackPortConnectCallback port_connect;
- void *port_connect_arg;
- JackGraphOrderCallback graph_order;
- void *graph_order_arg;
- JackXRunCallback xrun;
- void *xrun_arg;
- JackSyncCallback sync_cb;
- void *sync_arg;
- JackTimebaseCallback timebase_cb;
- void *timebase_arg;
- JackFreewheelCallback freewheel_cb;
- void *freewheel_arg;
- JackClientRegistrationCallback client_register;
- void *client_register_arg;
- JackThreadCallback thread_cb;
- void *thread_cb_arg;
- JackSessionCallback session_cb;
- void *session_cb_arg;
- JackLatencyCallback latency_cb;
- void *latency_cb_arg;
- JackPropertyChangeCallback property_cb;
- void *property_cb_arg;
- JackPortRenameCallback port_rename_cb;
- void *port_rename_arg;
+ /* callbacks
+ */
+ JackProcessCallback process;
+ void *process_arg;
+ JackThreadInitCallback thread_init;
+ void *thread_init_arg;
+ JackBufferSizeCallback bufsize;
+ void *bufsize_arg;
+ JackSampleRateCallback srate;
+ void *srate_arg;
+ JackPortRegistrationCallback port_register;
+ void *port_register_arg;
+ JackPortConnectCallback port_connect;
+ void *port_connect_arg;
+ JackGraphOrderCallback graph_order;
+ void *graph_order_arg;
+ JackXRunCallback xrun;
+ void *xrun_arg;
+ JackSyncCallback sync_cb;
+ void *sync_arg;
+ JackTimebaseCallback timebase_cb;
+ void *timebase_arg;
+ JackFreewheelCallback freewheel_cb;
+ void *freewheel_arg;
+ JackClientRegistrationCallback client_register;
+ void *client_register_arg;
+ JackThreadCallback thread_cb;
+ void *thread_cb_arg;
+ JackSessionCallback session_cb;
+ void *session_cb_arg;
+ JackLatencyCallback latency_cb;
+ void *latency_cb_arg;
+ JackPropertyChangeCallback property_cb;
+ void *property_cb_arg;
+ JackPortRenameCallback port_rename_cb;
+ void *port_rename_arg;
- /* external clients: set by libjack
- * internal clients: set by engine */
- int (*deliver_request)(void*, jack_request_t*); /* JOQ: 64/32 bug! */
- void *deliver_arg;
+ /* external clients: set by libjack
+ * internal clients: set by engine */
+ int (*deliver_request)(void*, jack_request_t*); /* JOQ: 64/32 bug! */
+ void *deliver_arg;
};
-extern int jack_client_deliver_request (const jack_client_t *client,
- jack_request_t *req);
-extern jack_port_t *jack_port_new (const jack_client_t *client,
- jack_port_id_t port_id,
- jack_control_t *control);
+extern int jack_client_deliver_request(const jack_client_t *client,
+ jack_request_t *req);
+extern jack_port_t *jack_port_new(const jack_client_t *client,
+ jack_port_id_t port_id,
+ jack_control_t *control);
extern void *jack_zero_filled_buffer;
extern void jack_set_clock_source (jack_timer_type_t);
-extern char* jack_server_dir (const char* server_name, char* server_dir);
+extern char* jack_server_dir(const char* server_name, char* server_dir);
#endif /* __jack_libjack_local_h__ */
diff --git a/libjack/messagebuffer.c b/libjack/messagebuffer.c
index f0fc4fb..5f9541a 100644
--- a/libjack/messagebuffer.c
+++ b/libjack/messagebuffer.c
@@ -13,14 +13,14 @@
* 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
+ * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
@@ -36,9 +36,9 @@
#include "internal.h"
/* MB_NEXT() relies on the fact that MB_BUFFERS is a power of two */
-#define MB_BUFFERS 128
-#define MB_NEXT(index) ((index+1) & (MB_BUFFERS-1))
-#define MB_BUFFERSIZE 256 /* message length limit */
+#define MB_BUFFERS 128
+#define MB_NEXT(index) ((index + 1) & (MB_BUFFERS - 1))
+#define MB_BUFFERSIZE 256 /* message length limit */
static char mb_buffers[MB_BUFFERS][MB_BUFFERSIZE];
static volatile unsigned int mb_initialized = 0;
@@ -52,112 +52,116 @@ static void (*mb_thread_init_callback)(void*) = 0;
static void* mb_thread_init_callback_arg = 0;
static void
-mb_flush()
+mb_flush ()
{
/* called WITHOUT the mb_write_lock */
while (mb_outbuffer != mb_inbuffer) {
- jack_info(mb_buffers[mb_outbuffer]);
- mb_outbuffer = MB_NEXT(mb_outbuffer);
+ jack_info (mb_buffers[mb_outbuffer]);
+ mb_outbuffer = MB_NEXT (mb_outbuffer);
}
}
static void *
-mb_thread_func(void *arg)
+mb_thread_func (void *arg)
{
/* The mutex is only to eliminate collisions between multiple
* writer threads and protect the condition variable. */
- pthread_mutex_lock(&mb_write_lock);
+ pthread_mutex_lock (&mb_write_lock);
while (mb_initialized) {
- pthread_cond_wait(&mb_ready_cond, &mb_write_lock);
+ pthread_cond_wait (&mb_ready_cond, &mb_write_lock);
if (mb_thread_init_callback) {
/* the client asked for all threads to run a thread
initialization callback, which includes us.
- */
+ */
mb_thread_init_callback (mb_thread_init_callback_arg);
mb_thread_init_callback = 0;
/* note that we've done it */
- pthread_cond_signal(&mb_ready_cond);
+ pthread_cond_signal (&mb_ready_cond);
}
/* releasing the mutex reduces contention */
- pthread_mutex_unlock(&mb_write_lock);
- mb_flush();
- pthread_mutex_lock(&mb_write_lock);
+ pthread_mutex_unlock (&mb_write_lock);
+ mb_flush ();
+ pthread_mutex_lock (&mb_write_lock);
}
- pthread_mutex_unlock(&mb_write_lock);
+ pthread_mutex_unlock (&mb_write_lock);
return NULL;
}
-void
+void
jack_messagebuffer_init ()
{
- if (mb_initialized)
+ if (mb_initialized) {
return;
+ }
- pthread_mutex_init(&mb_write_lock, NULL);
- pthread_cond_init(&mb_ready_cond, NULL);
+ pthread_mutex_init (&mb_write_lock, NULL);
+ pthread_cond_init (&mb_ready_cond, NULL);
mb_overruns = 0;
mb_initialized = 1;
- if (jack_thread_creator (&mb_writer_thread, NULL, &mb_thread_func, NULL) != 0)
+ if (jack_thread_creator (&mb_writer_thread, NULL, &mb_thread_func, NULL) != 0) {
mb_initialized = 0;
+ }
}
-void
+void
jack_messagebuffer_exit ()
{
- if (!mb_initialized)
+ if (!mb_initialized) {
return;
+ }
- pthread_mutex_lock(&mb_write_lock);
+ pthread_mutex_lock (&mb_write_lock);
mb_initialized = 0;
- pthread_cond_signal(&mb_ready_cond);
- pthread_mutex_unlock(&mb_write_lock);
+ pthread_cond_signal (&mb_ready_cond);
+ pthread_mutex_unlock (&mb_write_lock);
- pthread_join(mb_writer_thread, NULL);
- mb_flush();
+ pthread_join (mb_writer_thread, NULL);
+ mb_flush ();
- if (mb_overruns)
- jack_error("WARNING: %d message buffer overruns!",
- mb_overruns);
+ if (mb_overruns) {
+ jack_error ("WARNING: %d message buffer overruns!",
+ mb_overruns);
+ }
- pthread_mutex_destroy(&mb_write_lock);
- pthread_cond_destroy(&mb_ready_cond);
+ pthread_mutex_destroy (&mb_write_lock);
+ pthread_cond_destroy (&mb_ready_cond);
}
-void
+void
jack_messagebuffer_add (const char *fmt, ...)
{
char msg[MB_BUFFERSIZE];
va_list ap;
/* format the message first, to reduce lock contention */
- va_start(ap, fmt);
- vsnprintf(msg, MB_BUFFERSIZE, fmt, ap);
- va_end(ap);
+ va_start (ap, fmt);
+ vsnprintf (msg, MB_BUFFERSIZE, fmt, ap);
+ va_end (ap);
if (!mb_initialized) {
/* Unable to print message with realtime safety.
* Complain and print it anyway. */
- fprintf(stderr, "ERROR: messagebuffer not initialized: %s",
- msg);
+ fprintf (stderr, "ERROR: messagebuffer not initialized: %s",
+ msg);
return;
}
- if (pthread_mutex_trylock(&mb_write_lock) == 0) {
- strncpy(mb_buffers[mb_inbuffer], msg, MB_BUFFERSIZE);
- mb_inbuffer = MB_NEXT(mb_inbuffer);
- pthread_cond_signal(&mb_ready_cond);
- pthread_mutex_unlock(&mb_write_lock);
- } else { /* lock collision */
- atomic_add(&mb_overruns, 1);
+ if (pthread_mutex_trylock (&mb_write_lock) == 0) {
+ strncpy (mb_buffers[mb_inbuffer], msg, MB_BUFFERSIZE);
+ mb_inbuffer = MB_NEXT (mb_inbuffer);
+ pthread_cond_signal (&mb_ready_cond);
+ pthread_mutex_unlock (&mb_write_lock);
+ } else { /* lock collision */
+ atomic_add (&mb_overruns, 1);
}
}
@@ -171,11 +175,11 @@ jack_messagebuffer_thread_init (void (*cb)(void*), void* arg)
mb_thread_init_callback = cb;
/* wake msg buffer thread */
- pthread_cond_signal(&mb_ready_cond);
+ pthread_cond_signal (&mb_ready_cond);
/* wait for it to be done */
- pthread_cond_wait(&mb_ready_cond, &mb_write_lock);
+ pthread_cond_wait (&mb_ready_cond, &mb_write_lock);
/* and we're done */
pthread_mutex_unlock (&mb_write_lock);
-}
+}
diff --git a/libjack/metadata.c b/libjack/metadata.c
index a12778f..226ac1d 100644
--- a/libjack/metadata.c
+++ b/libjack/metadata.c
@@ -1,20 +1,20 @@
/*
- Copyright (C) 2013 Paul Davis
-
- 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.
-*/
+ Copyright (C) 2013 Paul Davis
+
+ 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 <string.h>
#include <db.h>
@@ -39,519 +39,551 @@ static DB_ENV* db_env = NULL;
static int
jack_property_init (const char* server_name)
{
- int ret;
- char dbpath[PATH_MAX+1];
- char server_dir[PATH_MAX+1];
-
- /* idempotent */
-
- if (db_env) {
- return 0;
- }
-
- if ((ret = db_env_create(&db_env, 0)) != 0) {
- jack_error ("cannot initialize DB environment: %s\n", db_strerror(ret));
- return -1;
- }
-
- if ((ret = db_env->open(db_env, jack_server_dir (server_name, server_dir), DB_CREATE | DB_INIT_LOCK | DB_INIT_MPOOL | DB_THREAD, 0)) != 0) {
- jack_error ("cannot open DB environment: %s", db_strerror (ret));
- return -1;
- }
-
- if ((ret = db_create (&db, db_env, 0)) != 0) {
- jack_error ("Cannot initialize metadata DB (%s)", db_strerror (ret));
- return -1;
- }
-
- snprintf (dbpath, sizeof (dbpath), "%s/%s", jack_server_dir (server_name, server_dir), "metadata.db");
-
- if ((ret = db->open (db, NULL, dbpath, NULL, DB_HASH, DB_CREATE|DB_THREAD, 0666)) != 0) {
- jack_error ("Cannot open metadata DB at %s: %s", dbpath, db_strerror (ret));
- db->close (db, 0);
- db = NULL;
- return -1;
- }
-
- return 0;
+ int ret;
+ char dbpath[PATH_MAX + 1];
+ char server_dir[PATH_MAX + 1];
+
+ /* idempotent */
+
+ if (db_env) {
+ return 0;
+ }
+
+ if ((ret = db_env_create (&db_env, 0)) != 0) {
+ jack_error ("cannot initialize DB environment: %s\n", db_strerror (ret));
+ return -1;
+ }
+
+ if ((ret = db_env->open (db_env, jack_server_dir (server_name, server_dir), DB_CREATE | DB_INIT_LOCK | DB_INIT_MPOOL | DB_THREAD, 0)) != 0) {
+ jack_error ("cannot open DB environment: %s", db_strerror (ret));
+ return -1;
+ }
+
+ if ((ret = db_create (&db, db_env, 0)) != 0) {
+ jack_error ("Cannot initialize metadata DB (%s)", db_strerror (ret));
+ return -1;
+ }
+
+ snprintf (dbpath, sizeof(dbpath), "%s/%s", jack_server_dir (server_name, server_dir), "metadata.db");
+
+ if ((ret = db->open (db, NULL, dbpath, NULL, DB_HASH, DB_CREATE | DB_THREAD, 0666)) != 0) {
+ jack_error ("Cannot open metadata DB at %s: %s", dbpath, db_strerror (ret));
+ db->close (db, 0);
+ db = NULL;
+ return -1;
+ }
+
+ return 0;
}
-static void jack_properties_uninit () __attribute__ ((destructor));
+static void jack_properties_uninit() __attribute__ ((destructor));
void
jack_properties_uninit ()
{
- if (db) {
- db->close (db, 0);
- db = NULL;
- }
- if (db_env) {
- db_env->close (db_env, 0);
- db_env = 0;
- }
+ if (db) {
+ db->close (db, 0);
+ db = NULL;
+ }
+ if (db_env) {
+ db_env->close (db_env, 0);
+ db_env = 0;
+ }
}
void
-jack_free_description(jack_description_t* desc, int free_actual_description_too)
+jack_free_description (jack_description_t* desc, int free_actual_description_too)
{
- uint32_t n;
-
- for (n = 0; n < desc->property_cnt; ++n) {
- free ((char*) desc->properties[n].key);
- free ((char*) desc->properties[n].data);
- if (desc->properties[n].type) {
- free ((char*) desc->properties[n].type);
- }
- }
+ uint32_t n;
+
+ for (n = 0; n < desc->property_cnt; ++n) {
+ free ((char*)desc->properties[n].key);
+ free ((char*)desc->properties[n].data);
+ if (desc->properties[n].type) {
+ free ((char*)desc->properties[n].type);
+ }
+ }
- free (desc->properties);
+ free (desc->properties);
- if (free_actual_description_too) {
- free (desc);
- }
+ if (free_actual_description_too) {
+ free (desc);
+ }
}
static int
jack_property_change_notify (jack_client_t* client, jack_uuid_t uuid, const char* key, jack_property_change_t change)
{
- jack_request_t req;
+ jack_request_t req;
- /* the engine passes in a NULL client when it removes metadata during port or client removal
- */
+ /* the engine passes in a NULL client when it removes metadata during port or client removal
+ */
- if (client == NULL) {
- return 0;
- }
+ if (client == NULL) {
+ return 0;
+ }
- req.type = PropertyChangeNotify;
- req.x.property.change = change;
- jack_uuid_copy (&req.x.property.uuid, uuid);
- req.x.property.keylen = key ? strlen (key) + 1 : 0;
- req.x.property.key = key;
- return jack_client_deliver_request (client, &req);
+ req.type = PropertyChangeNotify;
+ req.x.property.change = change;
+ jack_uuid_copy (&req.x.property.uuid, uuid);
+ req.x.property.keylen = key ? strlen (key) + 1 : 0;
+ req.x.property.key = key;
+ return jack_client_deliver_request (client, &req);
}
static void
make_key_dbt (DBT* dbt, jack_uuid_t subject, const char* key)
{
- char ustr[JACK_UUID_STRING_SIZE];
- size_t len1, len2;
-
- memset(dbt, 0, sizeof(DBT));
- memset(ustr, 0, JACK_UUID_STRING_SIZE);
- jack_uuid_unparse (subject, ustr);
- len1 = JACK_UUID_STRING_SIZE;
- len2 = strlen (key) + 1;
- dbt->size = len1 + len2;
- dbt->data = malloc (dbt->size);
- memcpy (dbt->data, ustr, len1); // copy subject+null
- memcpy (dbt->data + len1, key, len2); // copy key+null
+ char ustr[JACK_UUID_STRING_SIZE];
+ size_t len1, len2;
+
+ memset (dbt, 0, sizeof(DBT));
+ memset (ustr, 0, JACK_UUID_STRING_SIZE);
+ jack_uuid_unparse (subject, ustr);
+ len1 = JACK_UUID_STRING_SIZE;
+ len2 = strlen (key) + 1;
+ dbt->size = len1 + len2;
+ dbt->data = malloc (dbt->size);
+ memcpy (dbt->data, ustr, len1); // copy subject+null
+ memcpy (dbt->data + len1, key, len2); // copy key+null
}
int
jack_set_property (jack_client_t* client,
- jack_uuid_t subject,
- const char* key,
- const char* value,
- const char* type)
+ jack_uuid_t subject,
+ const char* key,
+ const char* value,
+ const char* type)
{
- DBT d_key;
- DBT data;
- int ret;
- size_t len1, len2;
- jack_property_change_t change;
-
- if (!key || key[0] == '\0') {
- jack_error ("empty key string for metadata not allowed");
- return -1;
- }
-
- if (!value || value[0] == '\0') {
- jack_error ("empty value string for metadata not allowed");
- return -1;
- }
-
- if (jack_property_init (NULL)) {
- return -1;
- }
-
- /* build a key */
-
- make_key_dbt (&d_key, subject, key);
-
- /* build data */
-
- memset(&data, 0, sizeof(data));
-
- len1 = strlen(value) + 1;
- if (type && type[0] != '\0') {
- len2 = strlen(type) + 1;
- } else {
- len2 = 0;
- }
-
- data.size = len1 + len2;
- data.data = malloc (data.size);
- memcpy (data.data, value, len1);
-
- if (len2) {
- memcpy (data.data + len1, type, len2);
- }
-
- if (db->exists (db, NULL, &d_key, 0) == DB_NOTFOUND) {
- change = PropertyCreated;
- } else {
- change = PropertyChanged;
- }
-
- if ((ret = db->put (db, NULL, &d_key, &data, 0)) != 0) {
- char ustr[JACK_UUID_STRING_SIZE];
- jack_uuid_unparse (subject, ustr);
- jack_error ("Cannot store metadata for %s/%s (%s)", ustr, key, db_strerror (ret));
- if (d_key.size > 0) free(d_key.data);
- if (data.size > 0) free(data.data);
- return -1;
- }
-
- jack_property_change_notify (client, subject, key, change);
-
- if (d_key.size > 0) free(d_key.data);
- if (data.size > 0) free(data.data);
-
- return 0;
+ DBT d_key;
+ DBT data;
+ int ret;
+ size_t len1, len2;
+ jack_property_change_t change;
+
+ if (!key || key[0] == '\0') {
+ jack_error ("empty key string for metadata not allowed");
+ return -1;
+ }
+
+ if (!value || value[0] == '\0') {
+ jack_error ("empty value string for metadata not allowed");
+ return -1;
+ }
+
+ if (jack_property_init (NULL)) {
+ return -1;
+ }
+
+ /* build a key */
+
+ make_key_dbt (&d_key, subject, key);
+
+ /* build data */
+
+ memset (&data, 0, sizeof(data));
+
+ len1 = strlen (value) + 1;
+ if (type && type[0] != '\0') {
+ len2 = strlen (type) + 1;
+ } else {
+ len2 = 0;
+ }
+
+ data.size = len1 + len2;
+ data.data = malloc (data.size);
+ memcpy (data.data, value, len1);
+
+ if (len2) {
+ memcpy (data.data + len1, type, len2);
+ }
+
+ if (db->exists (db, NULL, &d_key, 0) == DB_NOTFOUND) {
+ change = PropertyCreated;
+ } else {
+ change = PropertyChanged;
+ }
+
+ if ((ret = db->put (db, NULL, &d_key, &data, 0)) != 0) {
+ char ustr[JACK_UUID_STRING_SIZE];
+ jack_uuid_unparse (subject, ustr);
+ jack_error ("Cannot store metadata for %s/%s (%s)", ustr, key, db_strerror (ret));
+ if (d_key.size > 0) {
+ free (d_key.data);
+ }
+ if (data.size > 0) {
+ free (data.data);
+ }
+ return -1;
+ }
+
+ jack_property_change_notify (client, subject, key, change);
+
+ if (d_key.size > 0) {
+ free (d_key.data);
+ }
+ if (data.size > 0) {
+ free (data.data);
+ }
+
+ return 0;
}
int
jack_get_property (jack_uuid_t subject,
- const char* key,
- char** value,
- char** type)
+ const char* key,
+ char** value,
+ char** type)
{
- DBT d_key;
- DBT data;
- int ret;
- size_t len1, len2;
-
- if (key == NULL || key[0] == '\0') {
- return -1;
- }
-
- if (jack_property_init (NULL)) {
- return -1;
- }
-
- /* build a key */
-
- make_key_dbt (&d_key, subject, key);
-
- /* setup data DBT */
-
- memset(&data, 0, sizeof(data));
- data.flags = DB_DBT_MALLOC;
-
- if ((ret = db->get (db, NULL, &d_key, &data, 0)) != 0) {
- if (ret != DB_NOTFOUND) {
- char ustr[JACK_UUID_STRING_SIZE];
- jack_uuid_unparse (subject, ustr);
- jack_error ("Cannot metadata for %s/%s (%s)", ustr, key, db_strerror (ret));
- }
- if (d_key.size > 0) free(d_key.data);
- if (data.size > 0) free(data.data);
- return -1;
- }
-
- /* result must have at least 2 chars plus 2 nulls to be valid
- */
-
- if (data.size < 4) {
- if (d_key.size > 0) free(d_key.data);
- if (data.size > 0) free(data.data);
- return -1;
- }
-
- len1 = strlen (data.data) + 1;
- (*value) = (char *) malloc (len1);
- memcpy (*value, data.data, len1);
-
- if (len1 < data.size) {
- len2 = strlen (data.data+len1) + 1;
-
- (*type) = (char *) malloc (len2);
- memcpy (*type, data.data+len1, len2);
- } else {
- /* no type specified, assume default */
- *type = NULL;
- }
-
- if (d_key.size > 0) free(d_key.data);
- if (data.size > 0) free(data.data);
-
- return 0;
+ DBT d_key;
+ DBT data;
+ int ret;
+ size_t len1, len2;
+
+ if (key == NULL || key[0] == '\0') {
+ return -1;
+ }
+
+ if (jack_property_init (NULL)) {
+ return -1;
+ }
+
+ /* build a key */
+
+ make_key_dbt (&d_key, subject, key);
+
+ /* setup data DBT */
+
+ memset (&data, 0, sizeof(data));
+ data.flags = DB_DBT_MALLOC;
+
+ if ((ret = db->get (db, NULL, &d_key, &data, 0)) != 0) {
+ if (ret != DB_NOTFOUND) {
+ char ustr[JACK_UUID_STRING_SIZE];
+ jack_uuid_unparse (subject, ustr);
+ jack_error ("Cannot metadata for %s/%s (%s)", ustr, key, db_strerror (ret));
+ }
+ if (d_key.size > 0) {
+ free (d_key.data);
+ }
+ if (data.size > 0) {
+ free (data.data);
+ }
+ return -1;
+ }
+
+ /* result must have at least 2 chars plus 2 nulls to be valid
+ */
+
+ if (data.size < 4) {
+ if (d_key.size > 0) {
+ free (d_key.data);
+ }
+ if (data.size > 0) {
+ free (data.data);
+ }
+ return -1;
+ }
+
+ len1 = strlen (data.data) + 1;
+ (*value) = (char*)malloc (len1);
+ memcpy (*value, data.data, len1);
+
+ if (len1 < data.size) {
+ len2 = strlen (data.data + len1) + 1;
+
+ (*type) = (char*)malloc (len2);
+ memcpy (*type, data.data + len1, len2);
+ } else {
+ /* no type specified, assume default */
+ *type = NULL;
+ }
+
+ if (d_key.size > 0) {
+ free (d_key.data);
+ }
+ if (data.size > 0) {
+ free (data.data);
+ }
+
+ return 0;
}
int
jack_get_properties (jack_uuid_t subject,
- jack_description_t* desc)
+ jack_description_t* desc)
{
- DBT key;
- DBT data;
- DBC* cursor;
- int ret;
- size_t len1, len2;
- size_t cnt = 0;
- char ustr[JACK_UUID_STRING_SIZE];
- size_t props_size = 0;
- jack_property_t* prop;
-
- desc->properties = NULL;
- desc->property_cnt = 0;
-
- memset(ustr, 0, JACK_UUID_STRING_SIZE);
- jack_uuid_unparse (subject, ustr);
-
- if (jack_property_init (NULL)) {
- return -1;
- }
-
-
- if ((ret = db->cursor (db, NULL, &cursor, 0)) != 0) {
- jack_error ("Cannot create cursor for metadata search (%s)", db_strerror (ret));
- return -1;
- }
-
- memset(&key, 0, sizeof(key));
- memset(&data, 0, sizeof(data));
- data.flags = DB_DBT_MALLOC;
-
- while ((ret = cursor->get(cursor, &key, &data, DB_NEXT)) == 0) {
-
- /* require 2 extra chars (data+null) for key,
- which is composed of UUID str plus a key name
- */
-
- if (key.size < JACK_UUID_STRING_SIZE + 2) {
- /* if (key.size > 0) free(key.data); */
- if (data.size > 0) free(data.data);
- continue;
- }
-
- if (memcmp (ustr, key.data, JACK_UUID_STRING_SIZE) != 0) {
- /* not relevant */
- /* if (key.size > 0) free(key.data); */
- if (data.size > 0) free(data.data);
- continue;
- }
-
- /* result must have at least 2 chars plus 2 nulls to be valid
- */
-
- if (data.size < 4) {
- /* if (key.size > 0) free(key.data); */
- if (data.size > 0) free(data.data);
- continue;
- }
-
- /* realloc array if necessary */
-
- if (cnt == props_size) {
- if (props_size == 0) {
- props_size = 8; /* a rough guess at a likely upper bound for the number of properties */
- } else {
- props_size *= 2;
- }
-
- desc->properties = (jack_property_t*) realloc (desc->properties, sizeof (jack_property_t) * props_size);
- }
-
- prop = &desc->properties[cnt];
-
- /* store UUID/subject */
-
- jack_uuid_copy (&desc->subject, subject);
-
- /* copy key (without leading UUID as subject */
-
- len1 = key.size - JACK_UUID_STRING_SIZE;
- prop->key = malloc (len1);
- memcpy ((char*) prop->key, key.data + JACK_UUID_STRING_SIZE, len1);
-
- /* copy data (which contains 1 or 2 null terminated strings, the value
- and optionally a MIME type.
- */
-
- len1 = strlen (data.data) + 1;
- prop->data = (char *) malloc (len1);
- memcpy ((char*) prop->data, data.data, len1);
-
- if (len1 < data.size) {
- len2 = strlen (data.data+len1) + 1;
-
- prop->type= (char *) malloc (len2);
- memcpy ((char*) prop->type, data.data+len1, len2);
- } else {
- /* no type specified, assume default */
- prop->type = NULL;
- }
-
- /* if (key.size > 0) free(key.data); */
- if (data.size > 0) free(data.data);
-
- ++cnt;
- }
-
- cursor->close (cursor);
- desc->property_cnt = cnt;
-
- return cnt;
+ DBT key;
+ DBT data;
+ DBC* cursor;
+ int ret;
+ size_t len1, len2;
+ size_t cnt = 0;
+ char ustr[JACK_UUID_STRING_SIZE];
+ size_t props_size = 0;
+ jack_property_t* prop;
+
+ desc->properties = NULL;
+ desc->property_cnt = 0;
+
+ memset (ustr, 0, JACK_UUID_STRING_SIZE);
+ jack_uuid_unparse (subject, ustr);
+
+ if (jack_property_init (NULL)) {
+ return -1;
+ }
+
+
+ if ((ret = db->cursor (db, NULL, &cursor, 0)) != 0) {
+ jack_error ("Cannot create cursor for metadata search (%s)", db_strerror (ret));
+ return -1;
+ }
+
+ memset (&key, 0, sizeof(key));
+ memset (&data, 0, sizeof(data));
+ data.flags = DB_DBT_MALLOC;
+
+ while ((ret = cursor->get (cursor, &key, &data, DB_NEXT)) == 0) {
+
+ /* require 2 extra chars (data+null) for key,
+ which is composed of UUID str plus a key name
+ */
+
+ if (key.size < JACK_UUID_STRING_SIZE + 2) {
+ /* if (key.size > 0) free(key.data); */
+ if (data.size > 0) {
+ free (data.data);
+ }
+ continue;
+ }
+
+ if (memcmp (ustr, key.data, JACK_UUID_STRING_SIZE) != 0) {
+ /* not relevant */
+ /* if (key.size > 0) free(key.data); */
+ if (data.size > 0) {
+ free (data.data);
+ }
+ continue;
+ }
+
+ /* result must have at least 2 chars plus 2 nulls to be valid
+ */
+
+ if (data.size < 4) {
+ /* if (key.size > 0) free(key.data); */
+ if (data.size > 0) {
+ free (data.data);
+ }
+ continue;
+ }
+
+ /* realloc array if necessary */
+
+ if (cnt == props_size) {
+ if (props_size == 0) {
+ props_size = 8; /* a rough guess at a likely upper bound for the number of properties */
+ } else {
+ props_size *= 2;
+ }
+
+ desc->properties = (jack_property_t*)realloc (desc->properties, sizeof(jack_property_t) * props_size);
+ }
+
+ prop = &desc->properties[cnt];
+
+ /* store UUID/subject */
+
+ jack_uuid_copy (&desc->subject, subject);
+
+ /* copy key (without leading UUID as subject */
+
+ len1 = key.size - JACK_UUID_STRING_SIZE;
+ prop->key = malloc (len1);
+ memcpy ((char*)prop->key, key.data + JACK_UUID_STRING_SIZE, len1);
+
+ /* copy data (which contains 1 or 2 null terminated strings, the value
+ and optionally a MIME type.
+ */
+
+ len1 = strlen (data.data) + 1;
+ prop->data = (char*)malloc (len1);
+ memcpy ((char*)prop->data, data.data, len1);
+
+ if (len1 < data.size) {
+ len2 = strlen (data.data + len1) + 1;
+
+ prop->type = (char*)malloc (len2);
+ memcpy ((char*)prop->type, data.data + len1, len2);
+ } else {
+ /* no type specified, assume default */
+ prop->type = NULL;
+ }
+
+ /* if (key.size > 0) free(key.data); */
+ if (data.size > 0) {
+ free (data.data);
+ }
+
+ ++cnt;
+ }
+
+ cursor->close (cursor);
+ desc->property_cnt = cnt;
+
+ return cnt;
}
int
jack_get_all_properties (jack_description_t** descriptions)
{
- DBT key;
- DBT data;
- DBC* cursor;
- int ret;
- size_t dcnt = 0;
- size_t dsize = 0;
- size_t n = 0;
- jack_description_t* desc = NULL;
- jack_uuid_t uuid = JACK_UUID_EMPTY_INITIALIZER;
- jack_description_t* current_desc = NULL;
- jack_property_t* current_prop = NULL;
- size_t len1, len2;
-
- if (jack_property_init (NULL)) {
- return -1;
- }
-
- if ((ret = db->cursor (db, NULL, &cursor, 0)) != 0) {
- jack_error ("Cannot create cursor for metadata search (%s)", db_strerror (ret));
- return -1;
- }
-
- memset(&key, 0, sizeof(key));
- memset(&data, 0, sizeof(data));
- data.flags = DB_DBT_MALLOC;
-
- dsize = 8; /* initial guess at number of descriptions we need */
- dcnt = 0;
- desc = (jack_description_t*) malloc (dsize * sizeof (jack_description_t));
-
- while ((ret = cursor->get(cursor, &key, &data, DB_NEXT)) == 0) {
-
- /* require 2 extra chars (data+null) for key,
- which is composed of UUID str plus a key name
- */
-
- if (key.size < JACK_UUID_STRING_SIZE + 2) {
- /* if (key.size > 0) free(key.data); */
- if (data.size > 0) free(data.data);
- continue;
- }
-
- if (jack_uuid_parse (key.data, &uuid) != 0) {
- continue;
- }
-
- /* do we have an existing description for this UUID */
-
- for (n = 0; n < dcnt ; ++n) {
- if (jack_uuid_compare (uuid, desc[n].subject) == 0) {
- break;
- }
- }
-
- if (n == dcnt) {
- /* we do not have an existing description, so grow the array */
-
- if (dcnt == dsize) {
- dsize *= 2;
- desc = (jack_description_t*) realloc (desc, sizeof (jack_description_t) * dsize);
- }
-
- /* initialize */
-
- desc[n].property_size = 0;
- desc[n].property_cnt = 0;
- desc[n].properties = NULL;
-
- /* set up UUID */
-
- jack_uuid_copy (&desc[n].subject, uuid);
- dcnt++;
- }
-
- current_desc = &desc[n];
-
- /* see if there is room for the new property or if we need to realloc
- */
-
- if (current_desc->property_cnt == current_desc->property_size) {
- if (current_desc->property_size == 0) {
- current_desc->property_size = 8;
- } else {
- current_desc->property_size *= 2;
- }
-
- current_desc->properties = (jack_property_t*) realloc (current_desc->properties, sizeof (jack_property_t) * current_desc->property_size);
- }
-
- current_prop = &current_desc->properties[current_desc->property_cnt++];
-
- /* copy key (without leading UUID) */
-
- len1 = key.size - JACK_UUID_STRING_SIZE;
- current_prop->key = malloc (len1);
- memcpy ((char*) current_prop->key, key.data + JACK_UUID_STRING_SIZE, len1);
-
- /* copy data (which contains 1 or 2 null terminated strings, the value
- and optionally a MIME type.
- */
-
- len1 = strlen (data.data) + 1;
- current_prop->data = (char *) malloc (len1);
- memcpy ((char*) current_prop->data, data.data, len1);
-
- if (len1 < data.size) {
- len2 = strlen (data.data+len1) + 1;
-
- current_prop->type= (char *) malloc (len2);
- memcpy ((char*) current_prop->type, data.data+len1, len2);
- } else {
- /* no type specified, assume default */
- current_prop->type = NULL;
- }
-
- /* if (key.size > 0) free(key.data); */
- if (data.size > 0) free(data.data);
- }
-
- cursor->close (cursor);
-
- (*descriptions) = desc;
-
- return dcnt;
+ DBT key;
+ DBT data;
+ DBC* cursor;
+ int ret;
+ size_t dcnt = 0;
+ size_t dsize = 0;
+ size_t n = 0;
+ jack_description_t* desc = NULL;
+ jack_uuid_t uuid = JACK_UUID_EMPTY_INITIALIZER;
+ jack_description_t* current_desc = NULL;
+ jack_property_t* current_prop = NULL;
+ size_t len1, len2;
+
+ if (jack_property_init (NULL)) {
+ return -1;
+ }
+
+ if ((ret = db->cursor (db, NULL, &cursor, 0)) != 0) {
+ jack_error ("Cannot create cursor for metadata search (%s)", db_strerror (ret));
+ return -1;
+ }
+
+ memset (&key, 0, sizeof(key));
+ memset (&data, 0, sizeof(data));
+ data.flags = DB_DBT_MALLOC;
+
+ dsize = 8; /* initial guess at number of descriptions we need */
+ dcnt = 0;
+ desc = (jack_description_t*)malloc (dsize * sizeof(jack_description_t));
+
+ while ((ret = cursor->get (cursor, &key, &data, DB_NEXT)) == 0) {
+
+ /* require 2 extra chars (data+null) for key,
+ which is composed of UUID str plus a key name
+ */
+
+ if (key.size < JACK_UUID_STRING_SIZE + 2) {
+ /* if (key.size > 0) free(key.data); */
+ if (data.size > 0) {
+ free (data.data);
+ }
+ continue;
+ }
+
+ if (jack_uuid_parse (key.data, &uuid) != 0) {
+ continue;
+ }
+
+ /* do we have an existing description for this UUID */
+
+ for (n = 0; n < dcnt; ++n) {
+ if (jack_uuid_compare (uuid, desc[n].subject) == 0) {
+ break;
+ }
+ }
+
+ if (n == dcnt) {
+ /* we do not have an existing description, so grow the array */
+
+ if (dcnt == dsize) {
+ dsize *= 2;
+ desc = (jack_description_t*)realloc (desc, sizeof(jack_description_t) * dsize);
+ }
+
+ /* initialize */
+
+ desc[n].property_size = 0;
+ desc[n].property_cnt = 0;
+ desc[n].properties = NULL;
+
+ /* set up UUID */
+
+ jack_uuid_copy (&desc[n].subject, uuid);
+ dcnt++;
+ }
+
+ current_desc = &desc[n];
+
+ /* see if there is room for the new property or if we need to realloc
+ */
+
+ if (current_desc->property_cnt == current_desc->property_size) {
+ if (current_desc->property_size == 0) {
+ current_desc->property_size = 8;
+ } else {
+ current_desc->property_size *= 2;
+ }
+
+ current_desc->properties = (jack_property_t*)realloc (current_desc->properties, sizeof(jack_property_t) * current_desc->property_size);
+ }
+
+ current_prop = &current_desc->properties[current_desc->property_cnt++];
+
+ /* copy key (without leading UUID) */
+
+ len1 = key.size - JACK_UUID_STRING_SIZE;
+ current_prop->key = malloc (len1);
+ memcpy ((char*)current_prop->key, key.data + JACK_UUID_STRING_SIZE, len1);
+
+ /* copy data (which contains 1 or 2 null terminated strings, the value
+ and optionally a MIME type.
+ */
+
+ len1 = strlen (data.data) + 1;
+ current_prop->data = (char*)malloc (len1);
+ memcpy ((char*)current_prop->data, data.data, len1);
+
+ if (len1 < data.size) {
+ len2 = strlen (data.data + len1) + 1;
+
+ current_prop->type = (char*)malloc (len2);
+ memcpy ((char*)current_prop->type, data.data + len1, len2);
+ } else {
+ /* no type specified, assume default */
+ current_prop->type = NULL;
+ }
+
+ /* if (key.size > 0) free(key.data); */
+ if (data.size > 0) {
+ free (data.data);
+ }
+ }
+
+ cursor->close (cursor);
+
+ (*descriptions) = desc;
+
+ return dcnt;
}
int
-jack_get_description (jack_uuid_t subject,
- jack_description_t* desc)
+jack_get_description (jack_uuid_t subject,
+ jack_description_t* desc)
{
- return 0;
+ return 0;
}
int
jack_get_all_descriptions (jack_description_t** descs)
{
- return 0;
+ return 0;
}
-int
+int
jack_set_property_change_callback (jack_client_t *client,
- JackPropertyChangeCallback callback, void *arg)
+ JackPropertyChangeCallback callback, void *arg)
{
if (client->control->active) {
jack_error ("You cannot set callbacks on an active client.");
@@ -563,118 +595,128 @@ jack_set_property_change_callback (jack_client_t *client,
return 0;
}
-int
+int
jack_remove_property (jack_client_t* client, jack_uuid_t subject, const char* key)
{
- DBT d_key;
- int ret;
+ DBT d_key;
+ int ret;
- if (jack_property_init (NULL)) {
- return -1;
- }
+ if (jack_property_init (NULL)) {
+ return -1;
+ }
- make_key_dbt (&d_key, subject, key);
- if ((ret = db->del (db, NULL, &d_key, 0)) != 0) {
- jack_error ("Cannot delete key %s (%s)", key, db_strerror (ret));
- if (d_key.size > 0) free(d_key.data);
- return -1;
- }
+ make_key_dbt (&d_key, subject, key);
+ if ((ret = db->del (db, NULL, &d_key, 0)) != 0) {
+ jack_error ("Cannot delete key %s (%s)", key, db_strerror (ret));
+ if (d_key.size > 0) {
+ free (d_key.data);
+ }
+ return -1;
+ }
- jack_property_change_notify (client, subject, key, PropertyDeleted);
+ jack_property_change_notify (client, subject, key, PropertyDeleted);
- if (d_key.size > 0) free(d_key.data);
+ if (d_key.size > 0) {
+ free (d_key.data);
+ }
- return 0;
+ return 0;
}
-int
+int
jack_remove_properties (jack_client_t* client, jack_uuid_t subject)
{
- DBT key;
- DBT data;
- DBC* cursor;
- int ret;
- char ustr[JACK_UUID_STRING_SIZE];
- int retval = 0;
- uint32_t cnt = 0;
-
- memset(ustr, 0, JACK_UUID_STRING_SIZE);
- jack_uuid_unparse (subject, ustr);
-
- if (jack_property_init (NULL)) {
- return -1;
- }
-
- if ((ret = db->cursor (db, NULL, &cursor, 0)) != 0) {
- jack_error ("Cannot create cursor for metadata search (%s)", db_strerror (ret));
- return -1;
- }
-
- memset(&key, 0, sizeof(key));
- memset(&data, 0, sizeof(data));
- data.flags = DB_DBT_MALLOC;
-
- while ((ret = cursor->get(cursor, &key, &data, DB_NEXT)) == 0) {
-
- /* require 2 extra chars (data+null) for key,
- which is composed of UUID str plus a key name
- */
-
- if (key.size < JACK_UUID_STRING_SIZE + 2) {
- /* if (key.size > 0) free(key.data); */
- if (data.size > 0) free(data.data);
- continue;
- }
-
- if (memcmp (ustr, key.data, JACK_UUID_STRING_SIZE) != 0) {
- /* not relevant */
- /* if (key.size > 0) free(key.data); */
- if (data.size > 0) free(data.data);
- continue;
- }
-
- if ((ret = cursor->del (cursor, 0)) != 0) {
- jack_error ("cannot delete property (%s)", db_strerror (ret));
- /* don't return -1 here since this would leave things
- even more inconsistent. wait till the cursor is finished
- */
- retval = -1;
- }
- cnt++;
-
- /* if (key.size > 0) free(key.data); */
- if (data.size > 0) free(data.data);
- }
-
- cursor->close (cursor);
-
- if (cnt) {
- jack_property_change_notify (client, subject, NULL, PropertyDeleted);
- }
-
- if (retval) {
- return -1;
- }
-
- return cnt;
+ DBT key;
+ DBT data;
+ DBC* cursor;
+ int ret;
+ char ustr[JACK_UUID_STRING_SIZE];
+ int retval = 0;
+ uint32_t cnt = 0;
+
+ memset (ustr, 0, JACK_UUID_STRING_SIZE);
+ jack_uuid_unparse (subject, ustr);
+
+ if (jack_property_init (NULL)) {
+ return -1;
+ }
+
+ if ((ret = db->cursor (db, NULL, &cursor, 0)) != 0) {
+ jack_error ("Cannot create cursor for metadata search (%s)", db_strerror (ret));
+ return -1;
+ }
+
+ memset (&key, 0, sizeof(key));
+ memset (&data, 0, sizeof(data));
+ data.flags = DB_DBT_MALLOC;
+
+ while ((ret = cursor->get (cursor, &key, &data, DB_NEXT)) == 0) {
+
+ /* require 2 extra chars (data+null) for key,
+ which is composed of UUID str plus a key name
+ */
+
+ if (key.size < JACK_UUID_STRING_SIZE + 2) {
+ /* if (key.size > 0) free(key.data); */
+ if (data.size > 0) {
+ free (data.data);
+ }
+ continue;
+ }
+
+ if (memcmp (ustr, key.data, JACK_UUID_STRING_SIZE) != 0) {
+ /* not relevant */
+ /* if (key.size > 0) free(key.data); */
+ if (data.size > 0) {
+ free (data.data);
+ }
+ continue;
+ }
+
+ if ((ret = cursor->del (cursor, 0)) != 0) {
+ jack_error ("cannot delete property (%s)", db_strerror (ret));
+ /* don't return -1 here since this would leave things
+ even more inconsistent. wait till the cursor is finished
+ */
+ retval = -1;
+ }
+ cnt++;
+
+ /* if (key.size > 0) free(key.data); */
+ if (data.size > 0) {
+ free (data.data);
+ }
+ }
+
+ cursor->close (cursor);
+
+ if (cnt) {
+ jack_property_change_notify (client, subject, NULL, PropertyDeleted);
+ }
+
+ if (retval) {
+ return -1;
+ }
+
+ return cnt;
}
-int
+int
jack_remove_all_properties (jack_client_t* client)
{
- int ret;
- jack_uuid_t empty_uuid = JACK_UUID_EMPTY_INITIALIZER;
+ int ret;
+ jack_uuid_t empty_uuid = JACK_UUID_EMPTY_INITIALIZER;
- if (jack_property_init (NULL)) {
- return -1;
- }
+ if (jack_property_init (NULL)) {
+ return -1;
+ }
- if ((ret = db->truncate (db, NULL, NULL, 0)) != 0) {
- jack_error ("Cannot clear properties (%s)", db_strerror (ret));
- return -1;
- }
+ if ((ret = db->truncate (db, NULL, NULL, 0)) != 0) {
+ jack_error ("Cannot clear properties (%s)", db_strerror (ret));
+ return -1;
+ }
- jack_property_change_notify (client, empty_uuid, NULL, PropertyDeleted);
+ jack_property_change_notify (client, empty_uuid, NULL, PropertyDeleted);
- return 0;
+ return 0;
}
diff --git a/libjack/midiport.c b/libjack/midiport.c
index b673972..d5e607d 100644
--- a/libjack/midiport.c
+++ b/libjack/midiport.c
@@ -1,21 +1,21 @@
/*
Copyright (C) 2004-2006 Ian Esten
Copyright (C) 2006 Dave Robillard
-
+
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
+ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
+ */
#include <assert.h>
#include <stdio.h>
@@ -30,47 +30,49 @@
enum { MIDI_INLINE_MAX = 4 }; /* 4 bytes for default event size */
typedef struct _jack_midi_port_info_private {
- jack_nframes_t nframes; /**< Number of frames in buffer */
- uint32_t buffer_size; /**< Size of buffer in bytes */
- uint32_t event_count; /**< Number of events stored in this buffer */
- jack_nframes_t last_write_loc; /**< Used for both writing and mixdown */
- uint32_t events_lost; /**< Number of events lost in this buffer */
+ jack_nframes_t nframes; /**< Number of frames in buffer */
+ uint32_t buffer_size; /**< Size of buffer in bytes */
+ uint32_t event_count; /**< Number of events stored in this buffer */
+ jack_nframes_t last_write_loc; /**< Used for both writing and mixdown */
+ uint32_t events_lost; /**< Number of events lost in this buffer */
} POST_PACKED_STRUCTURE jack_midi_port_info_private_t;
typedef struct _jack_midi_port_internal_event {
- uint16_t time; /* offset within buffer limit to 64k */
- uint16_t size; /* event size limited to 64k */
- union {
- jack_shmsize_t byte_offset;
- jack_midi_data_t inline_data[MIDI_INLINE_MAX];
+ uint16_t time; /* offset within buffer limit to 64k */
+ uint16_t size; /* event size limited to 64k */
+ union {
+ jack_shmsize_t byte_offset;
+ jack_midi_data_t inline_data[MIDI_INLINE_MAX];
} POST_PACKED_STRUCTURE;
} POST_PACKED_STRUCTURE jack_midi_port_internal_event_t;
size_t
jack_midi_internal_event_size ()
{
- return sizeof (jack_midi_port_internal_event_t);
+ return sizeof(jack_midi_port_internal_event_t);
}
static inline jack_midi_data_t*
-jack_midi_event_data(void* port_buffer,
- const jack_midi_port_internal_event_t* event)
+jack_midi_event_data (void* port_buffer,
+ const jack_midi_port_internal_event_t* event)
{
- if (event->size <= MIDI_INLINE_MAX)
- return (jack_midi_data_t*) event->inline_data;
- else
- return ((jack_midi_data_t *)port_buffer) + event->byte_offset;
+ if (event->size <= MIDI_INLINE_MAX) {
+ return (jack_midi_data_t*)event->inline_data;
+ } else {
+ return ((jack_midi_data_t*)port_buffer) + event->byte_offset;
+ }
}
/* jack_midi_port_functions.buffer_init */
static void
-jack_midi_buffer_init(void *port_buffer,
- size_t buffer_size,
+jack_midi_buffer_init (void *port_buffer,
+ size_t buffer_size,
jack_nframes_t nframes)
{
jack_midi_port_info_private_t *info =
- (jack_midi_port_info_private_t *) port_buffer;
+ (jack_midi_port_info_private_t*)port_buffer;
+
/* We can also add some magic field to midi buffer to validate client calls */
info->nframes = nframes;
info->buffer_size = buffer_size;
@@ -81,86 +83,90 @@ jack_midi_buffer_init(void *port_buffer,
uint32_t
-jack_midi_get_event_count(void *port_buffer)
+jack_midi_get_event_count (void *port_buffer)
{
jack_midi_port_info_private_t *info =
- (jack_midi_port_info_private_t *) port_buffer;
+ (jack_midi_port_info_private_t*)port_buffer;
+
return info->event_count;
}
int
-jack_midi_event_get(jack_midi_event_t *event,
- void *port_buffer,
- uint32_t event_idx)
+jack_midi_event_get (jack_midi_event_t *event,
+ void *port_buffer,
+ uint32_t event_idx)
{
jack_midi_port_internal_event_t *port_event;
jack_midi_port_info_private_t *info =
- (jack_midi_port_info_private_t *) port_buffer;
-
+ (jack_midi_port_info_private_t*)port_buffer;
+
if (event_idx >= info->event_count)
#ifdef ENODATA
- return ENODATA;
+ { return ENODATA; }
#else
- return ENOMSG;
+ { return ENOMSG; }
#endif
-
- port_event = (jack_midi_port_internal_event_t *) (info + 1);
+
+ port_event = (jack_midi_port_internal_event_t*)(info + 1);
port_event += event_idx;
event->time = port_event->time;
event->size = port_event->size;
- event->buffer = jack_midi_event_data(port_buffer, port_event);
-
+ event->buffer = jack_midi_event_data (port_buffer, port_event);
+
return 0;
}
size_t
-jack_midi_max_event_size(void *port_buffer)
+jack_midi_max_event_size (void *port_buffer)
{
jack_midi_port_info_private_t *info =
- (jack_midi_port_info_private_t *) port_buffer;
+ (jack_midi_port_info_private_t*)port_buffer;
size_t buffer_size =
info->buffer_size;
-
+
/* (event_count + 1) below accounts for jack_midi_port_internal_event_t
* which would be needed to store the next event */
size_t used_size = sizeof(jack_midi_port_info_private_t)
- + info->last_write_loc
- + ((info->event_count + 1)
- * sizeof(jack_midi_port_internal_event_t));
-
- if (used_size > buffer_size)
+ + info->last_write_loc
+ + ((info->event_count + 1)
+ * sizeof(jack_midi_port_internal_event_t));
+
+ if (used_size > buffer_size) {
return 0;
- else if ((buffer_size - used_size) < MIDI_INLINE_MAX)
+ } else if ((buffer_size - used_size) < MIDI_INLINE_MAX) {
return MIDI_INLINE_MAX;
- else
- return (buffer_size - used_size);
+ } else {
+ return buffer_size - used_size;
+ }
}
jack_midi_data_t*
-jack_midi_event_reserve(void *port_buffer,
- jack_nframes_t time,
- size_t data_size)
+jack_midi_event_reserve (void *port_buffer,
+ jack_nframes_t time,
+ size_t data_size)
{
- jack_midi_data_t *retbuf = (jack_midi_data_t *) port_buffer;
+ jack_midi_data_t *retbuf = (jack_midi_data_t*)port_buffer;
jack_midi_port_info_private_t *info =
- (jack_midi_port_info_private_t *) port_buffer;
+ (jack_midi_port_info_private_t*)port_buffer;
jack_midi_port_internal_event_t *event_buffer =
- (jack_midi_port_internal_event_t *) (info + 1);
+ (jack_midi_port_internal_event_t*)(info + 1);
size_t buffer_size =
info->buffer_size;
-
- if (time < 0 || time >= info->nframes)
- goto failed;
-
- if (info->event_count > 0 && time < event_buffer[info->event_count-1].time)
- goto failed;
+
+ if (time < 0 || time >= info->nframes) {
+ goto failed;
+ }
+
+ if (info->event_count > 0 && time < event_buffer[info->event_count - 1].time) {
+ goto failed;
+ }
/* Check if data_size is >0 and there is enough space in the buffer for the event. */
- if (data_size <=0) {
+ if (data_size <= 0) {
goto failed; // return NULL?
} else if (jack_midi_max_event_size (port_buffer) < data_size) {
goto failed;
@@ -180,23 +186,23 @@ jack_midi_event_reserve(void *port_buffer,
info->event_count += 1;
return retbuf;
}
- failed:
- info->events_lost++;
+failed:
+ info->events_lost++;
return NULL;
}
int
-jack_midi_event_write(void *port_buffer,
- jack_nframes_t time,
- const jack_midi_data_t *data,
- size_t data_size)
+jack_midi_event_write (void *port_buffer,
+ jack_nframes_t time,
+ const jack_midi_data_t *data,
+ size_t data_size)
{
jack_midi_data_t *retbuf =
- jack_midi_event_reserve(port_buffer, time, data_size);
+ jack_midi_event_reserve (port_buffer, time, data_size);
if (retbuf) {
- memcpy(retbuf, data, data_size);
+ memcpy (retbuf, data, data_size);
return 0;
} else {
return ENOBUFS;
@@ -210,10 +216,10 @@ jack_midi_event_write(void *port_buffer,
* been reset.
*/
void
-jack_midi_clear_buffer(void *port_buffer)
+jack_midi_clear_buffer (void *port_buffer)
{
jack_midi_port_info_private_t *info =
- (jack_midi_port_info_private_t *) port_buffer;
+ (jack_midi_port_info_private_t*)port_buffer;
info->event_count = 0;
info->last_write_loc = 0;
@@ -223,40 +229,40 @@ jack_midi_clear_buffer(void *port_buffer)
/* jack_midi_port_functions.mixdown */
static void
-jack_midi_port_mixdown(jack_port_t *port, jack_nframes_t nframes)
+jack_midi_port_mixdown (jack_port_t *port, jack_nframes_t nframes)
{
JSList *node;
jack_port_t *input;
- jack_nframes_t num_events = 0;
- jack_nframes_t i = 0;
- int err = 0;
- jack_nframes_t lost_events = 0;
+ jack_nframes_t num_events = 0;
+ jack_nframes_t i = 0;
+ int err = 0;
+ jack_nframes_t lost_events = 0;
/* The next (single) event to mix in to the buffer */
jack_midi_port_info_private_t *earliest_info;
jack_midi_port_internal_event_t *earliest_event;
jack_midi_data_t *earliest_buffer;
-
- jack_midi_port_info_private_t *in_info; /* For finding next event */
- jack_midi_port_internal_event_t *in_events; /* Corresponds to in_info */
- jack_midi_port_info_private_t *out_info; /* Output 'buffer' */
- jack_midi_clear_buffer(port->mix_buffer);
-
- out_info = (jack_midi_port_info_private_t *) port->mix_buffer;
+ jack_midi_port_info_private_t *in_info; /* For finding next event */
+ jack_midi_port_internal_event_t *in_events; /* Corresponds to in_info */
+ jack_midi_port_info_private_t *out_info; /* Output 'buffer' */
+
+ jack_midi_clear_buffer (port->mix_buffer);
+
+ out_info = (jack_midi_port_info_private_t*)port->mix_buffer;
/* This function uses jack_midi_port_info_private_t.last_write_loc of the
* source ports to store indices of the last event read from that buffer
* so far. This is OK because last_write_loc is used when writing events
* to a buffer, which at this stage is already complete so the value
* can be safely smashed. */
-
+
/* Iterate through all connections to see how many events we need to mix,
* and initialise their 'last event read' (last_write_loc) to 0 */
- for (node = port->connections; node; node = jack_slist_next(node)) {
- input = (jack_port_t *) node->data;
+ for (node = port->connections; node; node = jack_slist_next (node)) {
+ input = (jack_port_t*)node->data;
in_info =
- (jack_midi_port_info_private_t *) jack_output_port_buffer(input);
+ (jack_midi_port_info_private_t*)jack_output_port_buffer (input);
num_events += in_info->event_count;
lost_events += in_info->events_lost;
in_info->last_write_loc = 0;
@@ -270,36 +276,36 @@ jack_midi_port_mixdown(jack_port_t *port, jack_nframes_t nframes)
/* Find the earliest unread event, to mix next
* (search for an event earlier than earliest_event) */
- for (node = port->connections; node; node = jack_slist_next(node)) {
- in_info = (jack_midi_port_info_private_t *)
- jack_output_port_buffer(((jack_port_t *) node->data));
- in_events = (jack_midi_port_internal_event_t *) (in_info + 1);
+ for (node = port->connections; node; node = jack_slist_next (node)) {
+ in_info = (jack_midi_port_info_private_t*)
+ jack_output_port_buffer (((jack_port_t*)node->data));
+ in_events = (jack_midi_port_internal_event_t*)(in_info + 1);
/* If there are unread events left in this port.. */
if (in_info->event_count > in_info->last_write_loc) {
/* .. and this event is the new earliest .. */
/* NOTE: that's why we compare time with <, not <= */
if (earliest_info == NULL
- || in_events[in_info->last_write_loc].time
- < earliest_event->time) {
+ || in_events[in_info->last_write_loc].time
+ < earliest_event->time) {
/* .. then set this event as the next earliest */
earliest_info = in_info;
- earliest_event = (jack_midi_port_internal_event_t *)
- (&in_events[in_info->last_write_loc]);
+ earliest_event = (jack_midi_port_internal_event_t*)
+ (&in_events[in_info->last_write_loc]);
}
}
}
if (earliest_info && earliest_event) {
- earliest_buffer = (jack_midi_data_t *) earliest_info;
-
+ earliest_buffer = (jack_midi_data_t*)earliest_info;
+
/* Write event to output */
- err = jack_midi_event_write(
- jack_port_buffer(port),
+ err = jack_midi_event_write (
+ jack_port_buffer (port),
earliest_event->time,
- jack_midi_event_data(earliest_buffer, earliest_event),
+ jack_midi_event_data (earliest_buffer, earliest_event),
earliest_event->size);
-
+
earliest_info->last_write_loc++;
if (err) {
@@ -308,7 +314,7 @@ jack_midi_port_mixdown(jack_port_t *port, jack_nframes_t nframes)
}
}
}
- assert(out_info->event_count == num_events - out_info->events_lost);
+ assert (out_info->event_count == num_events - out_info->events_lost);
// inherit total lost events count from all connected ports.
out_info->events_lost += lost_events;
@@ -316,12 +322,12 @@ jack_midi_port_mixdown(jack_port_t *port, jack_nframes_t nframes)
uint32_t
-jack_midi_get_lost_event_count(void *port_buffer)
+jack_midi_get_lost_event_count (void *port_buffer)
{
- return ((jack_midi_port_info_private_t *) port_buffer)->events_lost;
+ return ((jack_midi_port_info_private_t*)port_buffer)->events_lost;
}
jack_port_functions_t jack_builtin_midi_functions = {
- .buffer_init = jack_midi_buffer_init,
- .mixdown = jack_midi_port_mixdown,
+ .buffer_init = jack_midi_buffer_init,
+ .mixdown = jack_midi_port_mixdown,
};
diff --git a/libjack/pool.c b/libjack/pool.c
index f329cd5..4b7ecf3 100644
--- a/libjack/pool.c
+++ b/libjack/pool.c
@@ -1,21 +1,21 @@
/*
Copyright (C) 2001-2003 Paul Davis
-
+
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
+ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-*/
+
+ */
#include <config.h>
@@ -33,11 +33,11 @@ jack_pool_alloc (size_t bytes)
{
#ifdef HAVE_POSIX_MEMALIGN
void* m;
- int err = posix_memalign (&m, 64, bytes);
+ int err = posix_memalign (&m, 64, bytes);
return (!err) ? m : 0;
#else
return malloc (bytes);
-#endif /* HAVE_POSIX_MEMALIGN */
+#endif /* HAVE_POSIX_MEMALIGN */
}
void
diff --git a/libjack/port.c b/libjack/port.c
index 5d42b9f..ae67cbb 100644
--- a/libjack/port.c
+++ b/libjack/port.c
@@ -1,22 +1,22 @@
/*
Copyright (C) 2001-2003 Paul Davis
Copyright (C) 2005 Jussi Laako
-
+
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
+ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
+ */
#include <string.h>
#include <stdio.h>
@@ -41,36 +41,34 @@
#include "local.h"
static void jack_generic_buffer_init(void *port_buffer,
- size_t buffer_size,
- jack_nframes_t nframes);
-
-static void jack_audio_port_mixdown (jack_port_t *port,
+ size_t buffer_size,
jack_nframes_t nframes);
+static void jack_audio_port_mixdown(jack_port_t *port,
+ jack_nframes_t nframes);
+
/* These function pointers are local to each address space. For
* internal clients they reside within jackd; for external clients in
* the application process. */
jack_port_functions_t jack_builtin_audio_functions = {
- .buffer_init = jack_generic_buffer_init,
- .mixdown = jack_audio_port_mixdown,
+ .buffer_init = jack_generic_buffer_init,
+ .mixdown = jack_audio_port_mixdown,
};
extern jack_port_functions_t jack_builtin_midi_functions;
jack_port_functions_t jack_builtin_NULL_functions = {
- .buffer_init = jack_generic_buffer_init,
- .mixdown = NULL,
+ .buffer_init = jack_generic_buffer_init,
+ .mixdown = NULL,
};
/* Only the Audio and MIDI port types are currently built in. */
jack_port_type_info_t jack_builtin_port_types[] = {
- { .type_name = JACK_DEFAULT_AUDIO_TYPE,
- .buffer_scale_factor = 1,
- },
- { .type_name = JACK_DEFAULT_MIDI_TYPE,
+ { .type_name = JACK_DEFAULT_AUDIO_TYPE,
+ .buffer_scale_factor = 1, },
+ { .type_name = JACK_DEFAULT_MIDI_TYPE,
.buffer_scale_factor = -1,
- .buffer_size = 2048
- },
+ .buffer_size = 2048 },
{ .type_name = "", }
};
@@ -78,13 +76,13 @@ jack_port_type_info_t jack_builtin_port_types[] = {
#ifdef USE_DYNSIMD
-static void (*opt_copy) (float *, const float *, int);
-static void (*opt_mix) (float *, const float *, int);
+static void (*opt_copy)(float *, const float *, int);
+static void (*opt_mix)(float *, const float *, int);
static void
gen_copyf (float *dest, const float *src, int length)
{
- memcpy(dest, src, length * sizeof(float));
+ memcpy (dest, src, length * sizeof(float));
}
static void
@@ -96,22 +94,20 @@ gen_mixf (float *dest, const float *src, int length)
while (n--)
*dest++ += *src++;
/*for (iSample = 0; iSample < iDataLength; iSample++)
- fpDest[iSample] += fpSrc[iSample];*/
+ fpDest[iSample] += fpSrc[iSample];*/
}
#ifdef ARCH_X86
void jack_port_set_funcs ()
{
- if (ARCH_X86_HAVE_SSE2(cpu_type)) {
+ if (ARCH_X86_HAVE_SSE2 (cpu_type)) {
opt_copy = x86_sse_copyf;
opt_mix = x86_sse_add2f;
- }
- else if (ARCH_X86_HAVE_3DNOW(cpu_type)) {
+ } else if (ARCH_X86_HAVE_3DNOW (cpu_type)) {
opt_copy = x86_3dnow_copyf;
opt_mix = x86_3dnow_add2f;
- }
- else {
+ } else {
opt_copy = gen_copyf;
opt_mix = gen_mixf;
}
@@ -125,34 +121,34 @@ void jack_port_set_funcs ()
opt_mix = gen_mixf;
}
-#endif /* ARCH_X86 */
+#endif /* ARCH_X86 */
-#endif /* USE_DYNSIMD */
+#endif /* USE_DYNSIMD */
int
jack_port_name_equals (jack_port_shared_t* port, const char* target)
{
- char buf[JACK_PORT_NAME_SIZE+1];
+ char buf[JACK_PORT_NAME_SIZE + 1];
/* this nasty, nasty kludge is here because between 0.109.0 and 0.109.1,
the ALSA audio backend had the name "ALSA", whereas as before and
after it, it was called "alsa_pcm". this stops breakage for
any setups that have saved "alsa_pcm" or "ALSA" in their connection
state.
- */
+ */
if (strncmp (target, "ALSA:capture", 12) == 0 || strncmp (target, "ALSA:playback", 13) == 0) {
- snprintf (buf, sizeof (buf), "alsa_pcm%s", target+4);
+ snprintf (buf, sizeof(buf), "alsa_pcm%s", target + 4);
target = buf;
}
- return (strcmp (port->name, target) == 0 ||
- strcmp (port->alias1, target) == 0 ||
- strcmp (port->alias2, target) == 0);
+ return strcmp (port->name, target) == 0 ||
+ strcmp (port->alias1, target) == 0 ||
+ strcmp (port->alias2, target) == 0;
}
jack_port_functions_t *
-jack_get_port_functions(jack_port_type_id_t ptid)
+jack_get_port_functions (jack_port_type_id_t ptid)
{
switch (ptid) {
case JACK_AUDIO_PORT_TYPE:
@@ -169,9 +165,9 @@ jack_get_port_functions(jack_port_type_id_t ptid)
* Fills buffer with zeroes. For audio ports, engine->silent_buffer relies on it.
*/
static void
-jack_generic_buffer_init(void *buffer, size_t size, jack_nframes_t nframes)
-{
- memset(buffer, 0, size);
+jack_generic_buffer_init (void *buffer, size_t size, jack_nframes_t nframes)
+{
+ memset (buffer, 0, size);
}
@@ -183,10 +179,10 @@ jack_port_new (const jack_client_t *client, jack_port_id_t port_id,
jack_port_type_id_t ptid = shared->ptype_id;
jack_port_t *port;
- if ((port = (jack_port_t *) malloc (sizeof (jack_port_t))) == NULL) {
+ if ((port = (jack_port_t*)malloc (sizeof(jack_port_t))) == NULL) {
return NULL;
}
-
+
port->mix_buffer = NULL;
port->client_segment_base = NULL;
port->shared = shared;
@@ -196,14 +192,15 @@ jack_port_new (const jack_client_t *client, jack_port_id_t port_id,
port->tied = NULL;
if (jack_uuid_compare (client->control->uuid, port->shared->client_id) == 0) {
-
+
/* It's our port, so initialize the pointers to port
* functions within this address space. These builtin
- * definitions can be overridden by the client.
+ * definitions can be overridden by the client.
*/
- jack_port_functions_t *port_functions = jack_get_port_functions(ptid);
- if (port_functions == NULL)
+ jack_port_functions_t *port_functions = jack_get_port_functions (ptid);
+ if (port_functions == NULL) {
port_functions = &jack_builtin_NULL_functions;
+ }
port->fptr = *port_functions;
port->shared->has_mixdown = (port->fptr.mixdown ? TRUE : FALSE);
}
@@ -213,32 +210,33 @@ jack_port_new (const jack_client_t *client, jack_port_id_t port_id,
directly, because port->client_segment_base and/or
port->offset can change if the buffer size or port counts
are changed.
- */
+ */
port->client_segment_base =
- (void **) &client->port_segment[ptid].attached_at;
+ (void**)&client->port_segment[ptid].attached_at;
return port;
}
-size_t
+size_t
jack_port_type_get_buffer_size (jack_client_t *client, const char *port_type)
{
int i;
- for (i=0; i<client->engine->n_port_types; i++) {
- if (!strcmp(port_type, client->engine->port_types[i].type_name))
+ for (i = 0; i < client->engine->n_port_types; i++)
+ if (!strcmp (port_type, client->engine->port_types[i].type_name)) {
break;
- }
+ }
- if (i==client->engine->n_port_types)
+ if (i == client->engine->n_port_types) {
return 0;
+ }
return jack_port_type_buffer_size (&(client->engine->port_types[i]), client->engine->buffer_size);
}
jack_port_t *
-jack_port_register (jack_client_t *client,
+jack_port_register (jack_client_t *client,
const char *port_name,
const char *port_type,
unsigned long flags,
@@ -246,29 +244,29 @@ jack_port_register (jack_client_t *client,
{
jack_request_t req;
jack_port_t *port = 0;
- int length ;
+ int length;
- VALGRIND_MEMSET (&req, 0, sizeof (req));
+ VALGRIND_MEMSET (&req, 0, sizeof(req));
req.type = RegisterPort;
- length = strlen ((const char *) client->control->name)
- + 1 + strlen (port_name);
- if ( length >= sizeof (req.x.port_info.name) ) {
- jack_error ("\"%s:%s\" is too long to be used as a JACK port name.\n"
- "Please use %lu characters or less.",
- client->control->name ,
- port_name,
- sizeof (req.x.port_info.name) - 1);
- return NULL ;
+ length = strlen ((const char*)client->control->name)
+ + 1 + strlen (port_name);
+ if ( length >= sizeof(req.x.port_info.name) ) {
+ jack_error ("\"%s:%s\" is too long to be used as a JACK port name.\n"
+ "Please use %lu characters or less.",
+ client->control->name,
+ port_name,
+ sizeof(req.x.port_info.name) - 1);
+ return NULL;
}
- strcpy ((char *) req.x.port_info.name,
- (const char *) client->control->name);
- strcat ((char *) req.x.port_info.name, ":");
- strcat ((char *) req.x.port_info.name, port_name);
+ strcpy ((char*)req.x.port_info.name,
+ (const char*)client->control->name);
+ strcat ((char*)req.x.port_info.name, ":");
+ strcat ((char*)req.x.port_info.name, port_name);
- snprintf (req.x.port_info.type, sizeof (req.x.port_info.type),
+ snprintf (req.x.port_info.type, sizeof(req.x.port_info.type),
"%s", port_type);
req.x.port_info.flags = flags;
req.x.port_info.buffer_size = buffer_size;
@@ -290,12 +288,12 @@ jack_port_register (jack_client_t *client,
return port;
}
-int
+int
jack_port_unregister (jack_client_t *client, jack_port_t *port)
{
jack_request_t req;
-
- VALGRIND_MEMSET (&req, 0, sizeof (req));
+
+ VALGRIND_MEMSET (&req, 0, sizeof(req));
req.type = UnRegisterPort;
@@ -324,20 +322,20 @@ jack_port_connected_to (const jack_port_t *port, const char *portname)
while we are checking for them. that's hard,
and has a non-trivial performance impact
for jackd.
- */
+ */
- pthread_mutex_lock (&((jack_port_t *) port)->connection_lock);
+ pthread_mutex_lock (&((jack_port_t*)port)->connection_lock);
for (node = port->connections; node; node = jack_slist_next (node)) {
- jack_port_t *other_port = (jack_port_t *) node->data;
-
+ jack_port_t *other_port = (jack_port_t*)node->data;
+
if (jack_port_name_equals (other_port->shared, portname)) {
ret = TRUE;
break;
}
}
- pthread_mutex_unlock (&((jack_port_t *) port)->connection_lock);
+ pthread_mutex_unlock (&((jack_port_t*)port)->connection_lock);
return ret;
}
@@ -353,29 +351,29 @@ jack_port_get_connections (const jack_port_t *port)
while we are checking for them. that's hard,
and has a non-trivial performance impact
for jackd.
- */
+ */
- pthread_mutex_lock (&((jack_port_t *) port)->connection_lock);
+ pthread_mutex_lock (&((jack_port_t*)port)->connection_lock);
if (port->connections != NULL) {
- ret = (const char **)
- malloc (sizeof (char *)
- * (jack_slist_length (port->connections) + 1));
+ ret = (const char**)
+ malloc (sizeof(char *)
+ * (jack_slist_length (port->connections) + 1));
if (ret == NULL) {
- pthread_mutex_unlock (&((jack_port_t *)port)->connection_lock);
+ pthread_mutex_unlock (&((jack_port_t*)port)->connection_lock);
return NULL;
}
for (n = 0, node = port->connections; node;
node = jack_slist_next (node), ++n) {
- jack_port_t* other =(jack_port_t *) node->data;
+ jack_port_t* other = (jack_port_t*)node->data;
ret[n] = other->shared->name;
}
ret[n] = NULL;
}
- pthread_mutex_unlock (&((jack_port_t *) port)->connection_lock);
+ pthread_mutex_unlock (&((jack_port_t*)port)->connection_lock);
return ret;
}
@@ -395,8 +393,8 @@ jack_port_get_all_connections (const jack_client_t *client,
return NULL;
}
- VALGRIND_MEMSET (&req, 0, sizeof (req));
-
+ VALGRIND_MEMSET (&req, 0, sizeof(req));
+
req.type = GetPortConnections;
req.x.port_info.name[0] = '\0';
@@ -417,15 +415,15 @@ jack_port_get_all_connections (const jack_client_t *client,
return req.x.port_connections.ports;
}
- if ((ret = (const char **) malloc (sizeof (char *) * (req.x.port_connections.nports + 1))) == NULL) {
+ if ((ret = (const char**)malloc (sizeof(char *) * (req.x.port_connections.nports + 1))) == NULL) {
return NULL;
}
for (i = 0; i < req.x.port_connections.nports; ++i ) {
jack_port_id_t port_id;
-
- if (read (client->request_fd, &port_id, sizeof (port_id))
- != sizeof (port_id)) {
+
+ if (read (client->request_fd, &port_id, sizeof(port_id))
+ != sizeof(port_id)) {
jack_error ("cannot read port id from server");
return 0;
}
@@ -448,14 +446,15 @@ jack_port_by_id_int (const jack_client_t *client, jack_port_id_t id, int* free)
JSList *node;
for (node = client->ports; node; node = jack_slist_next (node)) {
- if (((jack_port_t *) node->data)->shared->id == id) {
+ if (((jack_port_t*)node->data)->shared->id == id) {
*free = FALSE;
- return (jack_port_t *) node->data;
+ return (jack_port_t*)node->data;
}
}
- if (id >= client->engine->port_max)
+ if (id >= client->engine->port_max) {
return NULL;
+ }
if (client->engine->ports[id].in_use) {
*free = TRUE;
@@ -471,18 +470,20 @@ jack_port_by_id (jack_client_t *client, jack_port_id_t id)
JSList *node;
jack_port_t* port;
int need_free = FALSE;
+
for (node = client->ports_ext; node; node = jack_slist_next (node)) {
port = node->data;
if (port->shared->id == id) { // Found port, return the cached structure
return port;
}
}
-
+
// Otherwise possibly allocate a new port structure, keep it in the ports_ext list for later use
- port = jack_port_by_id_int (client,id,&need_free);
- if (port != NULL && need_free)
+ port = jack_port_by_id_int (client, id, &need_free);
+ if (port != NULL && need_free) {
client->ports_ext =
jack_slist_prepend (client->ports_ext, port);
+ }
return port;
}
@@ -491,10 +492,10 @@ jack_port_by_name_int (jack_client_t *client, const char *port_name)
{
unsigned long i, limit;
jack_port_shared_t *port;
-
+
limit = client->engine->port_max;
port = &client->engine->ports[0];
-
+
for (i = 0; i < limit; i++) {
if (port[i].in_use && jack_port_name_equals (&port[i], port_name)) {
return jack_port_new (client, port[i].id,
@@ -510,6 +511,7 @@ jack_port_by_name (jack_client_t *client, const char *port_name)
{
JSList *node;
jack_port_t* port;
+
for (node = client->ports_ext; node; node = jack_slist_next (node)) {
port = node->data;
if (jack_port_name_equals (port->shared, port_name)) {
@@ -517,13 +519,14 @@ jack_port_by_name (jack_client_t *client, const char *port_name)
return port;
}
}
-
+
/* Otherwise allocate a new port structure, keep it in the
* ports_ext list for later use. */
port = jack_port_by_name_int (client, port_name);
- if (port != NULL)
+ if (port != NULL) {
client->ports_ext =
jack_slist_prepend (client->ports_ext, port);
+ }
return port;
}
@@ -543,7 +546,7 @@ void
jack_port_set_latency (jack_port_t *port, jack_nframes_t nframes)
{
port->shared->latency = nframes;
-
+
/* setup the new latency values here,
* so we dont need to change the backend codes.
*/
@@ -564,15 +567,15 @@ jack_port_get_buffer (jack_port_t *port, jack_nframes_t nframes)
/* Output port. The buffer was assigned by the engine
when the port was registered.
- */
+ */
if (port->shared->flags & JackPortIsOutput) {
if (port->tied) {
return jack_port_get_buffer (port->tied, nframes);
}
-
- if (port->client_segment_base == NULL || *port->client_segment_base == MAP_FAILED) {
- return NULL;
- }
+
+ if (port->client_segment_base == NULL || *port->client_segment_base == MAP_FAILED) {
+ return NULL;
+ }
return jack_output_port_buffer (port);
}
@@ -581,23 +584,23 @@ jack_port_get_buffer (jack_port_t *port, jack_nframes_t nframes)
process() callback, and since no connections can be
made/broken during this phase (enforced by the jack
server), there is no need to take the connection lock here
- */
+ */
if ((node = port->connections) == NULL) {
-
- if (port->client_segment_base == NULL || *port->client_segment_base == MAP_FAILED) {
- return NULL;
- }
+
+ if (port->client_segment_base == NULL || *port->client_segment_base == MAP_FAILED) {
+ return NULL;
+ }
/* no connections; return a zero-filled buffer */
- return (void *) (*(port->client_segment_base) + port->type_info->zero_buffer_offset);
+ return (void*)(*(port->client_segment_base) + port->type_info->zero_buffer_offset);
}
if ((next = jack_slist_next (node)) == NULL) {
/* one connection: use zero-copy mode - just pass
the buffer of the connected (output) port.
- */
- return jack_port_get_buffer (((jack_port_t *) node->data),
+ */
+ return jack_port_get_buffer (((jack_port_t*)node->data),
nframes);
}
@@ -605,25 +608,25 @@ jack_port_get_buffer (jack_port_t *port, jack_nframes_t nframes)
incoming data into that buffer. We have already
established the existence of a mixdown function during the
connection process.
- */
+ */
if (port->mix_buffer == NULL) {
- jack_error( "internal jack error: mix_buffer not allocated" );
+ jack_error ( "internal jack error: mix_buffer not allocated" );
return NULL;
}
port->fptr.mixdown (port, nframes);
- return (void *) port->mix_buffer;
+ return (void*)port->mix_buffer;
}
size_t
jack_port_type_buffer_size (jack_port_type_info_t* port_type_info, jack_nframes_t nframes)
{
- if( port_type_info->buffer_scale_factor < 0 ) {
+ if ( port_type_info->buffer_scale_factor < 0 ) {
return port_type_info->buffer_size;
- }
+ }
return port_type_info->buffer_scale_factor
- * sizeof (jack_default_audio_sample_t)
- * nframes;
+ * sizeof(jack_default_audio_sample_t)
+ * nframes;
}
int
@@ -655,7 +658,7 @@ jack_port_untie (jack_port_t *port)
return 0;
}
-int
+int
jack_port_request_monitor (jack_port_t *port, int onoff)
{
@@ -669,21 +672,21 @@ jack_port_request_monitor (jack_port_t *port, int onoff)
JSList *node;
- /* this port is for input, so recurse over each of the
+ /* this port is for input, so recurse over each of the
connected ports.
*/
pthread_mutex_lock (&port->connection_lock);
for (node = port->connections; node;
node = jack_slist_next (node)) {
-
+
/* drop the lock because if there is a feedback loop,
we will deadlock. XXX much worse things will
happen if there is a feedback loop !!!
- */
+ */
pthread_mutex_unlock (&port->connection_lock);
- jack_port_request_monitor ((jack_port_t *) node->data,
+ jack_port_request_monitor ((jack_port_t*)node->data,
onoff);
pthread_mutex_lock (&port->connection_lock);
}
@@ -692,8 +695,8 @@ jack_port_request_monitor (jack_port_t *port, int onoff)
return 0;
}
-
-int
+
+int
jack_port_request_monitor_by_name (jack_client_t *client,
const char *port_name, int onoff)
@@ -704,7 +707,7 @@ jack_port_request_monitor_by_name (jack_client_t *client,
limit = client->engine->port_max;
ports = &client->engine->ports[0];
-
+
for (i = 0; i < limit; i++) {
if (ports[i].in_use &&
strcmp (ports[i].name, port_name) == 0) {
@@ -757,14 +760,14 @@ int
jack_port_get_aliases (const jack_port_t *port, char* const aliases[2])
{
int cnt = 0;
-
+
if (port->shared->alias1[0] != '\0') {
- snprintf (aliases[0], JACK_CLIENT_NAME_SIZE+JACK_PORT_NAME_SIZE, "%s", port->shared->alias1);
+ snprintf (aliases[0], JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE, "%s", port->shared->alias1);
cnt++;
}
if (port->shared->alias2[0] != '\0') {
- snprintf (aliases[1], JACK_CLIENT_NAME_SIZE+JACK_PORT_NAME_SIZE, "%s", port->shared->alias2);
+ snprintf (aliases[1], JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE, "%s", port->shared->alias2);
cnt++;
}
@@ -776,12 +779,12 @@ jack_port_short_name (const jack_port_t *port)
{
/* we know there is always a colon, because we put
it there ...
- */
+ */
return strchr (port->shared->name, ':') + 1;
}
-int
+int
jack_port_is_mine (const jack_client_t *client, const jack_port_t *port)
{
return jack_uuid_compare (port->shared->client_id, client->control->uuid) == 0;
@@ -813,16 +816,16 @@ jack_port_rename (jack_client_t* client, jack_port_t *port, const char *new_name
req.type = PortNameChanged;
/* re-purpose an appropriate part of the request union to convey the names */
- snprintf ((char *) req.x.connect.source_port, JACK_PORT_NAME_SIZE-1, "%s", old_name);
- snprintf ((char *) req.x.connect.destination_port, JACK_PORT_NAME_SIZE-1, "%s", new_name);
-
- (void) jack_client_deliver_request (client, &req);
+ snprintf ((char*)req.x.connect.source_port, JACK_PORT_NAME_SIZE - 1, "%s", old_name);
+ snprintf ((char*)req.x.connect.destination_port, JACK_PORT_NAME_SIZE - 1, "%s", new_name);
+
+ (void)jack_client_deliver_request (client, &req);
}
free (old_name);
return ret;
-}
+}
int
jack_port_set_name (jack_port_t *port, const char *new_name)
{
@@ -832,13 +835,13 @@ jack_port_set_name (jack_port_t *port, const char *new_name)
if (strcmp (new_name, port->shared->name) == 0) {
return 0;
}
-
+
colon = strchr (port->shared->name, ':');
- len = sizeof (port->shared->name) -
- ((int) (colon - port->shared->name)) - 2;
- snprintf (colon+1, len, "%s", new_name);
+ len = sizeof(port->shared->name) -
+ ((int)(colon - port->shared->name)) - 2;
+ snprintf (colon + 1, len, "%s", new_name);
+
-
return 0;
}
@@ -846,9 +849,9 @@ int
jack_port_set_alias (jack_port_t *port, const char *alias)
{
if (port->shared->alias1[0] == '\0') {
- snprintf (port->shared->alias1, sizeof (port->shared->alias1), "%s", alias);
+ snprintf (port->shared->alias1, sizeof(port->shared->alias1), "%s", alias);
} else if (port->shared->alias2[0] == '\0') {
- snprintf (port->shared->alias2, sizeof (port->shared->alias2), "%s", alias);
+ snprintf (port->shared->alias2, sizeof(port->shared->alias2), "%s", alias);
} else {
return -1;
}
@@ -870,55 +873,59 @@ jack_port_unset_alias (jack_port_t *port, const char *alias)
return 0;
}
-void
+void
jack_port_set_latency_range (jack_port_t *port, jack_latency_callback_mode_t mode, jack_latency_range_t *range)
{
if (mode == JackCaptureLatency) {
port->shared->capture_latency = *range;
- /* hack to set port->shared->latency up for
+ /* hack to set port->shared->latency up for
* backend ports
*/
- if ((port->shared->flags & JackPortIsOutput) && (port->shared->flags & JackPortIsPhysical))
+ if ((port->shared->flags & JackPortIsOutput) && (port->shared->flags & JackPortIsPhysical)) {
port->shared->latency = (range->min + range->max) / 2;
+ }
} else {
port->shared->playback_latency = *range;
- /* hack to set port->shared->latency up for
+ /* hack to set port->shared->latency up for
* backend ports
*/
- if ((port->shared->flags & JackPortIsInput) && (port->shared->flags & JackPortIsPhysical))
+ if ((port->shared->flags & JackPortIsInput) && (port->shared->flags & JackPortIsPhysical)) {
port->shared->latency = (range->min + range->max) / 2;
+ }
}
}
-void
+void
jack_port_get_latency_range (jack_port_t *port, jack_latency_callback_mode_t mode, jack_latency_range_t *range)
{
- if (mode == JackCaptureLatency)
+ if (mode == JackCaptureLatency) {
*range = port->shared->capture_latency;
- else
+ } else {
*range = port->shared->playback_latency;
+ }
}
/* AUDIO PORT SUPPORT */
-static inline float f_max(float x, float a)
+static inline float f_max (float x, float a)
{
x -= a;
x += fabs (x);
x *= 0.5;
x += a;
- return (x);
+ return x;
}
-static void
+static void
jack_audio_port_mixdown (jack_port_t *port, jack_nframes_t nframes)
{
JSList *node;
jack_port_t *input;
+
#ifndef ARCH_X86
jack_nframes_t n;
jack_default_audio_sample_t *dst, *src;
@@ -928,39 +935,39 @@ jack_audio_port_mixdown (jack_port_t *port, jack_nframes_t nframes)
/* by the time we've called this, we've already established
the existence of more than one connection to this input
port and allocated a mix_buffer.
- */
+ */
/* no need to take connection lock, since this is called
from the process() callback, and the jack server
ensures that no changes to connections happen
during this time.
- */
+ */
node = port->connections;
- input = (jack_port_t *) node->data;
+ input = (jack_port_t*)node->data;
buffer = port->mix_buffer;
#ifndef USE_DYNSIMD
memcpy (buffer, jack_output_port_buffer (input),
- sizeof (jack_default_audio_sample_t) * nframes);
-#else /* USE_DYNSIMD */
+ sizeof(jack_default_audio_sample_t) * nframes);
+#else /* USE_DYNSIMD */
opt_copy (buffer, jack_output_port_buffer (input), nframes);
#endif /* USE_DYNSIMD */
for (node = jack_slist_next (node); node;
node = jack_slist_next (node)) {
- input = (jack_port_t *) node->data;
+ input = (jack_port_t*)node->data;
#ifndef USE_DYNSIMD
n = nframes;
dst = buffer;
src = jack_output_port_buffer (input);
- while (n--) {
+ while (n--)
*dst++ += *src++;
- }
-#else /* USE_DYNSIMD */
+
+#else /* USE_DYNSIMD */
opt_mix (buffer, jack_output_port_buffer (input), nframes);
#endif /* USE_DYNSIMD */
}
diff --git a/libjack/ringbuffer.c b/libjack/ringbuffer.c
index c06a1b2..b8cf3e6 100644
--- a/libjack/ringbuffer.c
+++ b/libjack/ringbuffer.c
@@ -1,24 +1,24 @@
/*
- Copyright (C) 2000 Paul Davis
- Copyright (C) 2003 Rohan Drape
-
- 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.
-
- ISO/POSIX C version of Paul Davis's lock free ringbuffer C++ code.
- This is safe for the case of one read thread and one write thread.
-*/
+ Copyright (C) 2000 Paul Davis
+ Copyright (C) 2003 Rohan Drape
+
+ 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.
+
+ ISO/POSIX C version of Paul Davis's lock free ringbuffer C++ code.
+ This is safe for the case of one read thread and one write thread.
+ */
#include <config.h>
@@ -37,13 +37,13 @@ jack_ringbuffer_create (size_t sz)
{
int power_of_two;
jack_ringbuffer_t *rb;
-
- if ((rb = malloc (sizeof (jack_ringbuffer_t))) == NULL) {
+
+ if ((rb = malloc (sizeof(jack_ringbuffer_t))) == NULL) {
return NULL;
}
-
- for (power_of_two = 1; 1 << power_of_two < sz; power_of_two++);
-
+
+ for (power_of_two = 1; 1 << power_of_two < sz; power_of_two++) ;
+
rb->size = 1 << power_of_two;
rb->size_mask = rb->size;
rb->size_mask -= 1;
@@ -54,7 +54,7 @@ jack_ringbuffer_create (size_t sz)
return NULL;
}
rb->mlocked = 0;
-
+
return rb;
}
@@ -67,7 +67,7 @@ jack_ringbuffer_free (jack_ringbuffer_t * rb)
if (rb->mlocked) {
munlock (rb->buf, rb->size);
}
-#endif /* USE_MLOCK */
+#endif /* USE_MLOCK */
free (rb->buf);
free (rb);
}
@@ -81,7 +81,7 @@ jack_ringbuffer_mlock (jack_ringbuffer_t * rb)
if (mlock (rb->buf, rb->size)) {
return -1;
}
-#endif /* USE_MLOCK */
+#endif /* USE_MLOCK */
rb->mlocked = 1;
return 0;
}
@@ -104,10 +104,10 @@ size_t
jack_ringbuffer_read_space (const jack_ringbuffer_t * rb)
{
size_t w, r;
-
+
w = rb->write_ptr;
r = rb->read_ptr;
-
+
if (w > r) {
return w - r;
} else {
@@ -174,8 +174,8 @@ jack_ringbuffer_read (jack_ringbuffer_t * rb, char *dest, size_t cnt)
return to_read;
}
-/* The copying data reader w/o read pointer advance. Copy at most
- `cnt' bytes from `rb' to `dest'. Returns the actual number of bytes
+/* The copying data reader w/o read pointer advance. Copy at most
+ `cnt' bytes from `rb' to `dest'. Returns the actual number of bytes
copied. */
size_t
@@ -260,6 +260,7 @@ void
jack_ringbuffer_read_advance (jack_ringbuffer_t * rb, size_t cnt)
{
size_t tmp = (rb->read_ptr + cnt) & rb->size_mask;
+
rb->read_ptr = tmp;
}
@@ -269,6 +270,7 @@ void
jack_ringbuffer_write_advance (jack_ringbuffer_t * rb, size_t cnt)
{
size_t tmp = (rb->write_ptr + cnt) & rb->size_mask;
+
rb->write_ptr = tmp;
}
diff --git a/libjack/sanitycheck.c b/libjack/sanitycheck.c
index 257b7ee..b77e254 100644
--- a/libjack/sanitycheck.c
+++ b/libjack/sanitycheck.c
@@ -1,20 +1,20 @@
/*
Copyright (C) 2001-2003 Paul Davis
-
+
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
+ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-*/
+
+ */
#include <sysdeps/sanitycheck.c>
diff --git a/libjack/shm.c b/libjack/shm.c
index f3401c7..c5e24f2 100644
--- a/libjack/shm.c
+++ b/libjack/shm.c
@@ -12,22 +12,22 @@
/*
Copyright (C) 2001-2003 Paul Davis
-
+
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
+ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-*/
+
+ */
#include <config.h>
@@ -58,13 +58,13 @@ static jack_shmtype_t jack_shmtype = shm_SYSV;
#endif
/* interface-dependent forward declarations */
-static int jack_access_registry (jack_shm_info_t *ri);
-static int jack_create_registry (jack_shm_info_t *ri);
-static void jack_remove_shm (jack_shm_id_t *id);
+static int jack_access_registry(jack_shm_info_t *ri);
+static int jack_create_registry(jack_shm_info_t *ri);
+static void jack_remove_shm(jack_shm_id_t *id);
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * common interface-independent section
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+* common interface-independent section
+* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* The JACK SHM registry is a chunk of memory for keeping track of the
* shared memory used by each active JACK server. This allows the
@@ -74,10 +74,10 @@ static void jack_remove_shm (jack_shm_id_t *id);
*/
/* per-process global data for the SHM interfaces */
-static jack_shm_id_t registry_id; /* SHM id for the registry */
-static jack_shm_info_t registry_info = { /* SHM info for the registry */
- .index = JACK_SHM_NULL_INDEX,
- .attached_at = MAP_FAILED
+static jack_shm_id_t registry_id; /* SHM id for the registry */
+static jack_shm_info_t registry_info = { /* SHM info for the registry */
+ .index = JACK_SHM_NULL_INDEX,
+ .attached_at = MAP_FAILED
};
/* pointers to registry header and array */
@@ -121,29 +121,29 @@ semaphore_init ()
key_t semkey = JACK_SEMAPHORE_KEY;
struct sembuf sbuf;
int create_flags = IPC_CREAT | IPC_EXCL
- | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
+ | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
/* Get semaphore ID associated with this key. */
- if ((semid = semget(semkey, 0, 0)) == -1) {
+ if ((semid = semget (semkey, 0, 0)) == -1) {
/* Semaphore does not exist - Create. */
- if ((semid = semget(semkey, 1, create_flags)) != -1) {
+ if ((semid = semget (semkey, 1, create_flags)) != -1) {
/* Initialize the semaphore, allow one owner. */
sbuf.sem_num = 0;
sbuf.sem_op = 1;
sbuf.sem_flg = 0;
- if (semop(semid, &sbuf, 1) == -1) {
+ if (semop (semid, &sbuf, 1) == -1) {
semaphore_error ("semop");
}
} else if (errno == EEXIST) {
- if ((semid = semget(semkey, 0, 0)) == -1) {
+ if ((semid = semget (semkey, 0, 0)) == -1) {
semaphore_error ("semget");
}
} else {
- semaphore_error ("semget creation");
+ semaphore_error ("semget creation");
}
}
}
@@ -156,21 +156,22 @@ semaphore_add (int value)
sbuf.sem_num = 0;
sbuf.sem_op = value;
sbuf.sem_flg = SEM_UNDO;
- if (semop(semid, &sbuf, 1) == -1) {
+ if (semop (semid, &sbuf, 1) == -1) {
semaphore_error ("semop");
}
}
-static void
+static void
jack_shm_lock_registry (void)
{
- if (semid == -1)
+ if (semid == -1) {
semaphore_init ();
+ }
semaphore_add (-1);
}
-static void
+static void
jack_shm_unlock_registry (void)
{
semaphore_add (1);
@@ -188,12 +189,11 @@ jack_shm_init_registry ()
jack_shm_header->protocol = jack_protocol_version;
jack_shm_header->type = jack_shmtype;
jack_shm_header->size = JACK_SHM_REGISTRY_SIZE;
- jack_shm_header->hdr_len = sizeof (jack_shm_header_t);
- jack_shm_header->entry_len = sizeof (jack_shm_registry_t);
+ jack_shm_header->hdr_len = sizeof(jack_shm_header_t);
+ jack_shm_header->entry_len = sizeof(jack_shm_registry_t);
- for (i = 0; i < MAX_SHM_ID; ++i) {
+ for (i = 0; i < MAX_SHM_ID; ++i)
jack_shm_registry[i].index = i;
- }
}
static int
@@ -205,10 +205,10 @@ jack_shm_validate_registry ()
&& (jack_shm_header->protocol == jack_protocol_version)
&& (jack_shm_header->type == jack_shmtype)
&& (jack_shm_header->size == JACK_SHM_REGISTRY_SIZE)
- && (jack_shm_header->hdr_len == sizeof (jack_shm_header_t))
- && (jack_shm_header->entry_len == sizeof (jack_shm_registry_t))) {
+ && (jack_shm_header->hdr_len == sizeof(jack_shm_header_t))
+ && (jack_shm_header->entry_len == sizeof(jack_shm_registry_t))) {
- return 0; /* registry OK */
+ return 0; /* registry OK */
}
return -1;
@@ -233,7 +233,7 @@ jack_shm_validate_registry ()
static void
jack_set_server_prefix (const char *server_name)
{
- snprintf (jack_shm_server_prefix, sizeof (jack_shm_server_prefix),
+ snprintf (jack_shm_server_prefix, sizeof(jack_shm_server_prefix),
"/jack-%d:%s:", getuid (), server_name);
}
@@ -246,9 +246,10 @@ jack_server_initialize_shm (int new_registry)
{
int rc;
- if (jack_shm_header)
- return 0; /* already initialized */
+ if (jack_shm_header) {
+ return 0; /* already initialized */
+ }
jack_shm_lock_registry ();
rc = jack_access_registry (&registry_info);
@@ -259,14 +260,15 @@ jack_server_initialize_shm (int new_registry)
}
switch (rc) {
- case ENOENT: /* registry does not exist */
+ case ENOENT: /* registry does not exist */
rc = jack_create_registry (&registry_info);
break;
- case 0: /* existing registry */
- if (jack_shm_validate_registry () == 0)
+ case 0: /* existing registry */
+ if (jack_shm_validate_registry () == 0) {
break;
- /* else it was invalid, so fall through */
- case EINVAL: /* bad registry */
+ }
+ /* else it was invalid, so fall through */
+ case EINVAL: /* bad registry */
/* Apparently, this registry was created by an older
* JACK version. Delete it so we can try again. */
jack_release_shm (&registry_info);
@@ -280,7 +282,7 @@ jack_server_initialize_shm (int new_registry)
#endif
}
break;
- default: /* failure return code */
+ default: /* failure return code */
break;
}
@@ -300,9 +302,10 @@ jack_initialize_shm (const char *server_name)
{
int rc;
- if (jack_shm_header)
- return 0; /* already initialized */
+ if (jack_shm_header) {
+ return 0; /* already initialized */
+ }
jack_set_server_prefix (server_name);
jack_shm_lock_registry ();
@@ -322,9 +325,10 @@ void
jack_destroy_shm (jack_shm_info_t* si)
{
/* must NOT have the registry locked */
- if (si->index == JACK_SHM_NULL_INDEX)
- return; /* segment not allocated */
+ if (si->index == JACK_SHM_NULL_INDEX) {
+ return; /* segment not allocated */
+ }
jack_remove_shm (&jack_shm_registry[si->index].id);
jack_release_shm_info (si->index);
}
@@ -341,7 +345,7 @@ jack_get_free_shm_info ()
break;
}
}
-
+
if (i < MAX_SHM_ID) {
si = &jack_shm_registry[i];
}
@@ -356,21 +360,21 @@ jack_release_shm_entry (jack_shm_registry_index_t index)
jack_shm_registry[index].size = 0;
jack_shm_registry[index].allocator = 0;
memset (&jack_shm_registry[index].id, 0,
- sizeof (jack_shm_registry[index].id));
+ sizeof(jack_shm_registry[index].id));
}
void
jack_release_shm_info (jack_shm_registry_index_t index)
{
/* must NOT have the registry locked */
- if (jack_shm_registry[index].allocator == getpid()) {
+ if (jack_shm_registry[index].allocator == getpid ()) {
jack_shm_lock_registry ();
jack_release_shm_entry (index);
jack_shm_unlock_registry ();
}
}
-/* Claim server_name for this process.
+/* Claim server_name for this process.
*
* returns 0 if successful
* EEXIST if server_name was already active for this user
@@ -387,8 +391,9 @@ jack_register_server (const char *server_name, int new_registry)
jack_info ("JACK compiled with %s SHM support.", JACK_SHM_TYPE);
- if (jack_server_initialize_shm (new_registry))
+ if (jack_server_initialize_shm (new_registry)) {
return ENOMEM;
+ }
jack_shm_lock_registry ();
@@ -399,34 +404,35 @@ jack_register_server (const char *server_name, int new_registry)
if (strncmp (jack_shm_header->server[i].name,
jack_shm_server_prefix,
- JACK_SERVER_NAME_SIZE) != 0)
- continue; /* no match */
+ JACK_SERVER_NAME_SIZE) != 0) {
+ continue; /* no match */
+ }
if (jack_shm_header->server[i].pid == my_pid) {
jack_shm_unlock_registry ();
- return 0; /* it's me */
+ return 0; /* it's me */
}
/* see if server still exists */
if (kill (jack_shm_header->server[i].pid, 0) == 0) {
jack_shm_unlock_registry ();
- return EEXIST; /* other server running */
+ return EEXIST; /* other server running */
}
/* it's gone, reclaim this entry */
memset (&jack_shm_header->server[i], 0,
- sizeof (jack_shm_server_t));
+ sizeof(jack_shm_server_t));
}
/* find a free entry */
- for (i = 0; i < MAX_SERVERS; i++) {
- if (jack_shm_header->server[i].pid == 0)
+ for (i = 0; i < MAX_SERVERS; i++)
+ if (jack_shm_header->server[i].pid == 0) {
break;
- }
+ }
if (i >= MAX_SERVERS) {
jack_shm_unlock_registry ();
- return ENOSPC; /* out of space */
+ return ENOSPC; /* out of space */
}
/* claim it */
@@ -452,7 +458,7 @@ jack_unregister_server (const char *server_name /* unused */)
for (i = 0; i < MAX_SERVERS; i++) {
if (jack_shm_header->server[i].pid == my_pid) {
memset (&jack_shm_header->server[i], 0,
- sizeof (jack_shm_server_t));
+ sizeof(jack_shm_server_t));
}
}
@@ -469,22 +475,23 @@ jack_cleanup_shm ()
pid_t my_pid = getpid ();
jack_shm_lock_registry ();
-
+
for (i = 0; i < MAX_SHM_ID; i++) {
jack_shm_registry_t* r;
r = &jack_shm_registry[i];
- memcpy (&copy, r, sizeof (jack_shm_info_t));
+ memcpy (&copy, r, sizeof(jack_shm_info_t));
destroy = FALSE;
/* ignore unused entries */
- if (r->allocator == 0)
+ if (r->allocator == 0) {
continue;
+ }
/* is this my shm segment? */
if (r->allocator == my_pid) {
- /* allocated by this process, so unattach
+ /* allocated by this process, so unattach
and destroy. */
jack_release_shm (&copy);
destroy = TRUE;
@@ -552,8 +559,8 @@ jack_resize_shm (jack_shm_info_t* si, jack_shmsize_t size)
#ifdef USE_POSIX_SHM
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * POSIX interface-dependent functions
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+* POSIX interface-dependent functions
+* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* gain addressability to existing SHM registry segment
*
@@ -569,7 +576,7 @@ jack_access_registry (jack_shm_info_t *ri)
/* registry must be locked */
int shm_fd;
- strncpy (registry_id, "/jack-shm-registry", sizeof (registry_id));
+ strncpy (registry_id, "/jack-shm-registry", sizeof(registry_id));
/* try to open an existing segment */
if ((shm_fd = shm_open (registry_id, O_RDWR, 0666)) < 0) {
@@ -583,7 +590,7 @@ jack_access_registry (jack_shm_info_t *ri)
}
if ((ri->attached_at = mmap (0, JACK_SHM_REGISTRY_SIZE,
- PROT_READ|PROT_WRITE,
+ PROT_READ | PROT_WRITE,
MAP_SHARED, shm_fd, 0)) == MAP_FAILED) {
jack_error ("cannot mmap shm registry segment (%s)",
strerror (errno));
@@ -594,7 +601,7 @@ jack_access_registry (jack_shm_info_t *ri)
/* set up global pointers */
ri->index = JACK_SHM_REGISTRY_INDEX;
jack_shm_header = ri->attached_at;
- jack_shm_registry = (jack_shm_registry_t *) (jack_shm_header + 1);
+ jack_shm_registry = (jack_shm_registry_t*)(jack_shm_header + 1);
return 0;
}
@@ -612,9 +619,9 @@ jack_create_registry (jack_shm_info_t *ri)
/* registry must be locked */
int shm_fd;
- strncpy (registry_id, "/jack-shm-registry", sizeof (registry_id));
+ strncpy (registry_id, "/jack-shm-registry", sizeof(registry_id));
- if ((shm_fd = shm_open (registry_id, O_RDWR|O_CREAT, 0666)) < 0) {
+ if ((shm_fd = shm_open (registry_id, O_RDWR | O_CREAT, 0666)) < 0) {
int rc = errno;
jack_error ("cannot create shm registry segment (%s)",
strerror (errno));
@@ -633,7 +640,7 @@ jack_create_registry (jack_shm_info_t *ri)
}
if ((ri->attached_at = mmap (0, JACK_SHM_REGISTRY_SIZE,
- PROT_READ|PROT_WRITE,
+ PROT_READ | PROT_WRITE,
MAP_SHARED, shm_fd, 0)) == MAP_FAILED) {
jack_error ("cannot mmap shm registry segment (%s)",
strerror (errno));
@@ -645,7 +652,7 @@ jack_create_registry (jack_shm_info_t *ri)
/* set up global pointers */
ri->index = JACK_SHM_REGISTRY_INDEX;
jack_shm_header = ri->attached_at;
- jack_shm_registry = (jack_shm_registry_t *) (jack_shm_header + 1);
+ jack_shm_registry = (jack_shm_registry_t*)(jack_shm_header + 1);
/* initialize registry contents */
jack_shm_init_registry ();
@@ -661,8 +668,8 @@ jack_remove_shm (jack_shm_id_t *id)
the shm segment, so this failing is not an error.
XXX it would be good to differentiate between these
two conditions.
- */
- shm_unlink ((char *) id);
+ */
+ shm_unlink ((char*)id);
}
void
@@ -681,7 +688,7 @@ jack_shmalloc (jack_shmsize_t size, jack_shm_info_t* si)
jack_shm_registry_t* registry;
int shm_fd;
int rc = -1;
- char name[SHM_NAME_MAX+1];
+ char name[SHM_NAME_MAX + 1];
jack_shm_lock_registry ();
@@ -697,14 +704,14 @@ jack_shmalloc (jack_shmsize_t size, jack_shm_info_t* si)
* actual names. So, we construct a short name from the
* registry index for uniqueness.
*/
- snprintf (name, sizeof (name), "/jack-%d", registry->index);
+ snprintf (name, sizeof(name), "/jack-%d", registry->index);
- if (strlen (name) >= sizeof (registry->id)) {
+ if (strlen (name) >= sizeof(registry->id)) {
jack_error ("shm segment name too long %s", name);
goto unlock;
}
- if ((shm_fd = shm_open (name, O_RDWR|O_CREAT, 0666)) < 0) {
+ if ((shm_fd = shm_open (name, O_RDWR | O_CREAT, 0666)) < 0) {
jack_error ("cannot create shm segment %s (%s)",
name, strerror (errno));
goto unlock;
@@ -720,13 +727,13 @@ jack_shmalloc (jack_shmsize_t size, jack_shm_info_t* si)
close (shm_fd);
registry->size = size;
- strncpy (registry->id, name, sizeof (registry->id));
- registry->allocator = getpid();
+ strncpy (registry->id, name, sizeof(registry->id));
+ registry->allocator = getpid ();
si->index = registry->index;
- si->attached_at = MAP_FAILED; /* not attached */
- rc = 0; /* success */
+ si->attached_at = MAP_FAILED; /* not attached */
+ rc = 0; /* success */
- unlock:
+unlock:
jack_shm_unlock_registry ();
return rc;
}
@@ -744,9 +751,9 @@ jack_attach_shm (jack_shm_info_t* si)
return -1;
}
- if ((si->attached_at = mmap (0, registry->size, PROT_READ|PROT_WRITE,
+ if ((si->attached_at = mmap (0, registry->size, PROT_READ | PROT_WRITE,
MAP_SHARED, shm_fd, 0)) == MAP_FAILED) {
- jack_error ("cannot mmap shm segment %s (%s)",
+ jack_error ("cannot mmap shm segment %s (%s)",
registry->id,
strerror (errno));
close (shm_fd);
@@ -761,8 +768,8 @@ jack_attach_shm (jack_shm_info_t* si)
#else
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * System V interface-dependent functions
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+* System V interface-dependent functions
+* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* gain addressability to existing SHM registry segment
*
@@ -784,15 +791,15 @@ jack_access_registry (jack_shm_info_t *ri)
switch (errno) {
- case ENOENT: /* segment does not exist */
+ case ENOENT: /* segment does not exist */
return ENOENT;
- case EINVAL: /* segment exists, but too small */
+ case EINVAL: /* segment exists, but too small */
/* attempt minimum size access */
registry_id = shmget (JACK_SHM_REGISTRY_KEY, 1, 0666);
return EINVAL;
- default: /* or other error */
+ default: /* or other error */
jack_error ("unable to access shm registry (%s)",
strerror (errno));
return errno;
@@ -808,7 +815,7 @@ jack_access_registry (jack_shm_info_t *ri)
/* set up global pointers */
ri->index = JACK_SHM_REGISTRY_INDEX;
jack_shm_header = ri->attached_at;
- jack_shm_registry = (jack_shm_registry_t *) (jack_shm_header + 1);
+ jack_shm_registry = (jack_shm_registry_t*)(jack_shm_header + 1);
return 0;
}
@@ -826,7 +833,7 @@ jack_create_registry (jack_shm_info_t *ri)
/* registry must be locked */
if ((registry_id = shmget (JACK_SHM_REGISTRY_KEY,
JACK_SHM_REGISTRY_SIZE,
- 0666|IPC_CREAT)) < 0) {
+ 0666 | IPC_CREAT)) < 0) {
jack_error ("cannot create shm registry segment (%s)",
strerror (errno));
return errno;
@@ -841,7 +848,7 @@ jack_create_registry (jack_shm_info_t *ri)
/* set up global pointers */
ri->index = JACK_SHM_REGISTRY_INDEX;
jack_shm_header = ri->attached_at;
- jack_shm_registry = (jack_shm_registry_t *) (jack_shm_header + 1);
+ jack_shm_registry = (jack_shm_registry_t*)(jack_shm_header + 1);
/* initialize registry contents */
jack_shm_init_registry ();
@@ -853,11 +860,11 @@ static void
jack_remove_shm (jack_shm_id_t *id)
{
/* registry may or may not be locked */
- /* this call can fail if we are attempting to
+ /* this call can fail if we are attempting to
remove a segment that was already deleted
- by the client. XXX i suppose the
+ by the client. XXX i suppose the
function should take a "canfail" argument.
- */
+ */
shmctl (*id, IPC_RMID, NULL);
}
@@ -871,7 +878,7 @@ jack_release_shm (jack_shm_info_t* si)
}
int
-jack_shmalloc (jack_shmsize_t size, jack_shm_info_t* si)
+jack_shmalloc (jack_shmsize_t size, jack_shm_info_t* si)
{
int shmflags;
int shmid;
@@ -888,7 +895,7 @@ jack_shmalloc (jack_shmsize_t size, jack_shm_info_t* si)
registry->size = size;
registry->id = shmid;
- registry->allocator = getpid();
+ registry->allocator = getpid ();
si->index = registry->index;
si->attached_at = MAP_FAILED; /* not attached */
rc = 0;
diff --git a/libjack/simd.c b/libjack/simd.c
index 0c2c558..139ba2c 100644
--- a/libjack/simd.c
+++ b/libjack/simd.c
@@ -1,22 +1,22 @@
/* -*- mode: c; c-file-style: "bsd"; -*- */
/*
Copyright (C) 2005-2008 Jussi Laako
-
+
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
+ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
+ */
#include <config.h>
@@ -45,23 +45,23 @@ have_3dnow ()
"movl $0x80000001, %%eax\n\t" \
"cpuid\n\t" \
\
- "xorl %%eax, %%eax\n\t" \
+ "xorl %%eax, %%eax\n\t" \
\
"movl $1, %%ecx\n\t" \
"shll $31, %%ecx\n\t" \
"testl %%ecx, %%edx\n\t" \
- "jz tdnow_testexit\n\t" \
+ "jz tdnow_testexit\n\t" \
"movl $1, %%eax\n\t" \
\
"movl $1, %%ecx\n\t" \
"shll $30, %%ecx\n\t" \
"testl %%ecx, %%edx\n\t" \
- "jz tdnow_testexit\n\t" \
+ "jz tdnow_testexit\n\t" \
"movl $2, %%eax\n\t" \
"jmp tdnow_testexit\n\t" \
\
"tdnow_prexit:\n\t" \
- "xorl %%eax, %%eax\n\t" \
+ "xorl %%eax, %%eax\n\t" \
"tdnow_testexit:\n\t"
: "=a" (res)
:
@@ -88,7 +88,7 @@ have_sse ()
"movl $1, %%eax\n\t" \
"cpuid\n\t" \
\
- "xorl %%eax, %%eax\n\t" \
+ "xorl %%eax, %%eax\n\t" \
\
"movl $1, %%ebx\n\t" \
"shll $25, %%ebx\n\t" \
@@ -123,49 +123,47 @@ void
x86_3dnow_copyf (float *dest, const float *src, int length)
{
int i, n1, n2;
- pv2sf m64p_src = (pv2sf) src;
- pv2sf m64p_dest = (pv2sf) dest;
+ pv2sf m64p_src = (pv2sf)src;
+ pv2sf m64p_dest = (pv2sf)dest;
n1 = (length >> 4);
n2 = ((length & 0xf) >> 1);
- for (i = 0; i < n1; i++)
- {
+ for (i = 0; i < n1; i++) {
asm volatile ("movq %0, %%mm0\n\t"
- : : "m" (*m64p_src++) : "mm0", "memory");
+ : : "m" (*m64p_src++) : "mm0", "memory");
asm volatile ("movq %0, %%mm1\n\t"
- : : "m" (*m64p_src++) : "mm1", "memory");
+ : : "m" (*m64p_src++) : "mm1", "memory");
asm volatile ("movq %0, %%mm2\n\t"
- : : "m" (*m64p_src++) : "mm2", "memory");
+ : : "m" (*m64p_src++) : "mm2", "memory");
asm volatile ("movq %0, %%mm3\n\t"
- : : "m" (*m64p_src++) : "mm3", "memory");
+ : : "m" (*m64p_src++) : "mm3", "memory");
asm volatile ("movq %0, %%mm4\n\t"
- : : "m" (*m64p_src++) : "mm4", "memory");
+ : : "m" (*m64p_src++) : "mm4", "memory");
asm volatile ("movq %0, %%mm5\n\t"
- : : "m" (*m64p_src++) : "mm5", "memory");
+ : : "m" (*m64p_src++) : "mm5", "memory");
asm volatile ("movq %0, %%mm6\n\t"
- : : "m" (*m64p_src++) : "mm6", "memory");
+ : : "m" (*m64p_src++) : "mm6", "memory");
asm volatile ("movq %0, %%mm7\n\t"
- : : "m" (*m64p_src++) : "mm7", "memory");
+ : : "m" (*m64p_src++) : "mm7", "memory");
asm volatile ("movq %%mm0, %0\n\t"
- : "=m" (*m64p_dest++) : : "mm0", "memory");
+ : "=m" (*m64p_dest++) : : "mm0", "memory");
asm volatile ("movq %%mm1, %0\n\t"
- : "=m" (*m64p_dest++) : : "mm1", "memory");
+ : "=m" (*m64p_dest++) : : "mm1", "memory");
asm volatile ("movq %%mm2, %0\n\t"
- : "=m" (*m64p_dest++) : : "mm2", "memory");
+ : "=m" (*m64p_dest++) : : "mm2", "memory");
asm volatile ("movq %%mm3, %0\n\t"
- : "=m" (*m64p_dest++) : : "mm3", "memory");
+ : "=m" (*m64p_dest++) : : "mm3", "memory");
asm volatile ("movq %%mm4, %0\n\t"
- : "=m" (*m64p_dest++) : : "mm4", "memory");
+ : "=m" (*m64p_dest++) : : "mm4", "memory");
asm volatile ("movq %%mm5, %0\n\t"
- : "=m" (*m64p_dest++) : : "mm5", "memory");
+ : "=m" (*m64p_dest++) : : "mm5", "memory");
asm volatile ("movq %%mm6, %0\n\t"
- : "=m" (*m64p_dest++) : : "mm6", "memory");
+ : "=m" (*m64p_dest++) : : "mm6", "memory");
asm volatile ("movq %%mm7, %0\n\t"
- : "=m" (*m64p_dest++) : : "mm7", "memory");
+ : "=m" (*m64p_dest++) : : "mm7", "memory");
}
- for (i = 0; i < n2; i++)
- {
+ for (i = 0; i < n2; i++) {
asm volatile (
"movq %1, %%mm0\n\t" \
"movq %%mm0, %0\n\t"
@@ -173,8 +171,7 @@ x86_3dnow_copyf (float *dest, const float *src, int length)
: "m" (*m64p_src++)
: "mm0", "memory");
}
- if (length & 0x1)
- {
+ if (length & 0x1) {
asm volatile (
"movd %1, %%mm0\n\t" \
"movd %%mm0, %0\n\t"
@@ -191,23 +188,21 @@ void
x86_3dnow_add2f (float *dest, const float *src, int length)
{
int i, n;
- pv2sf m64p_dest = (pv2sf) dest;
- pv2sf m64p_src = (pv2sf) src;
+ pv2sf m64p_dest = (pv2sf)dest;
+ pv2sf m64p_src = (pv2sf)src;
n = (length >> 1);
- for (i = 0; i < n; i++)
- {
+ for (i = 0; i < n; i++) {
asm volatile (
"movq %1, %%mm0\n\t" \
"pfadd %2, %%mm0\n\t" \
"movq %%mm0, %0\n\t"
: "=m" (m64p_dest[i])
: "m0" (m64p_dest[i]),
- "m" (m64p_src[i])
+ "m" (m64p_src[i])
: "mm0", "memory");
}
- if (n & 0x1)
- {
+ if (n & 0x1) {
asm volatile (
"movd %1, %%mm0\n\t" \
"movd %2, %%mm1\n\t" \
@@ -215,7 +210,7 @@ x86_3dnow_add2f (float *dest, const float *src, int length)
"movd %%mm0, %0\n\t"
: "=m" (dest[length - 1])
: "m0" (dest[length - 1]),
- "m" (src[length - 1])
+ "m" (src[length - 1])
: "mm0", "mm1", "memory");
}
asm volatile (
@@ -227,59 +222,56 @@ void
x86_sse_copyf (float *dest, const float *src, int length)
{
int i, n1, n2, si3;
- pv4sf m128p_src = (pv4sf) src;
- pv4sf m128p_dest = (pv4sf) dest;
+ pv4sf m128p_src = (pv4sf)src;
+ pv4sf m128p_dest = (pv4sf)dest;
n1 = (length >> 5);
n2 = ((length & 0x1f) >> 2);
si3 = (length & ~0x3);
- for (i = 0; i < n1; i++)
- {
+ for (i = 0; i < n1; i++) {
asm volatile ("movaps %0, %%xmm0\n\t"
- : : "m" (*m128p_src++) : "xmm0", "memory");
+ : : "m" (*m128p_src++) : "xmm0", "memory");
asm volatile ("movaps %0, %%xmm1\n\t"
- : : "m" (*m128p_src++) : "xmm1", "memory");
+ : : "m" (*m128p_src++) : "xmm1", "memory");
asm volatile ("movaps %0, %%xmm2\n\t"
- : : "m" (*m128p_src++) : "xmm2", "memory");
+ : : "m" (*m128p_src++) : "xmm2", "memory");
asm volatile ("movaps %0, %%xmm3\n\t"
- : : "m" (*m128p_src++) : "xmm3", "memory");
+ : : "m" (*m128p_src++) : "xmm3", "memory");
asm volatile ("movaps %0, %%xmm4\n\t"
- : : "m" (*m128p_src++) : "xmm4", "memory");
+ : : "m" (*m128p_src++) : "xmm4", "memory");
asm volatile ("movaps %0, %%xmm5\n\t"
- : : "m" (*m128p_src++) : "xmm5", "memory");
+ : : "m" (*m128p_src++) : "xmm5", "memory");
asm volatile ("movaps %0, %%xmm6\n\t"
- : : "m" (*m128p_src++) : "xmm6", "memory");
+ : : "m" (*m128p_src++) : "xmm6", "memory");
asm volatile ("movaps %0, %%xmm7\n\t"
- : : "m" (*m128p_src++) : "xmm7", "memory");
+ : : "m" (*m128p_src++) : "xmm7", "memory");
asm volatile ("movaps %%xmm0, %0\n\t"
- : "=m" (*m128p_dest++) : : "xmm0", "memory");
+ : "=m" (*m128p_dest++) : : "xmm0", "memory");
asm volatile ("movaps %%xmm1, %0\n\t"
- : "=m" (*m128p_dest++) : : "xmm1", "memory");
+ : "=m" (*m128p_dest++) : : "xmm1", "memory");
asm volatile ("movaps %%xmm2, %0\n\t"
- : "=m" (*m128p_dest++) : : "xmm2", "memory");
+ : "=m" (*m128p_dest++) : : "xmm2", "memory");
asm volatile ("movaps %%xmm3, %0\n\t"
- : "=m" (*m128p_dest++) : : "xmm3", "memory");
+ : "=m" (*m128p_dest++) : : "xmm3", "memory");
asm volatile ("movaps %%xmm4, %0\n\t"
- : "=m" (*m128p_dest++) : : "xmm4", "memory");
+ : "=m" (*m128p_dest++) : : "xmm4", "memory");
asm volatile ("movaps %%xmm5, %0\n\t"
- : "=m" (*m128p_dest++) : : "xmm5", "memory");
+ : "=m" (*m128p_dest++) : : "xmm5", "memory");
asm volatile ("movaps %%xmm6, %0\n\t"
- : "=m" (*m128p_dest++) : : "xmm6", "memory");
+ : "=m" (*m128p_dest++) : : "xmm6", "memory");
asm volatile ("movaps %%xmm7, %0\n\t"
- : "=m" (*m128p_dest++) : : "xmm7", "memory");
+ : "=m" (*m128p_dest++) : : "xmm7", "memory");
}
- for (i = 0; i < n2; i++)
- {
+ for (i = 0; i < n2; i++) {
asm volatile (
- "movaps %1, %%xmm0\n\t" \
+ "movaps %1, %%xmm0\n\t" \
"movaps %%xmm0, %0\n\t"
: "=m" (*m128p_dest++)
: "m" (*m128p_src++)
: "xmm0", "memory");
}
- for (i = si3; i < length; i++)
- {
+ for (i = si3; i < length; i++) {
asm volatile (
"movss %1, %%xmm0\n\t" \
"movss %%xmm0, %0\n\t"
@@ -293,38 +285,35 @@ void
x86_sse_add2f (float *dest, const float *src, int length)
{
int i, n, si2;
- pv4sf m128p_src = (pv4sf) src;
- pv4sf m128p_dest = (pv4sf) dest;
+ pv4sf m128p_src = (pv4sf)src;
+ pv4sf m128p_dest = (pv4sf)dest;
- if (__builtin_expect(((long) src & 0xf) || ((long) dest & 0xf), 0))
- {
+ if (__builtin_expect (((long)src & 0xf) || ((long)dest & 0xf), 0)) {
/*jack_error("x86_sse_add2f(): non aligned pointers!");*/
si2 = 0;
goto sse_nonalign;
}
si2 = (length & ~0x3);
n = (length >> 2);
- for (i = 0; i < n; i++)
- {
+ for (i = 0; i < n; i++) {
asm volatile (
- "movaps %1, %%xmm0\n\t" \
+ "movaps %1, %%xmm0\n\t" \
"addps %2, %%xmm0\n\t" \
"movaps %%xmm0, %0\n\t"
: "=m" (m128p_dest[i])
: "m0" (m128p_dest[i]),
- "m" (m128p_src[i])
+ "m" (m128p_src[i])
: "xmm0", "memory");
}
sse_nonalign:
- for (i = si2; i < length; i++)
- {
+ for (i = si2; i < length; i++) {
asm volatile (
"movss %1, %%xmm0\n\t" \
"addss %2, %%xmm0\n\t" \
"movss %%xmm0, %0\n\t"
: "=m" (dest[i])
: "m0" (dest[i]),
- "m" (src[i])
+ "m" (src[i])
: "xmm0", "memory");
}
}
@@ -332,29 +321,29 @@ sse_nonalign:
void x86_sse_f2i (int *dest, const float *src, int length, float scale)
{
int i;
- static const float max[4] __attribute__((aligned(16))) =
- { -1.0F, -1.0F, -1.0F, -1.0F };
- static const float min[4] __attribute__((aligned(16))) =
- { 1.0F, 1.0F, 1.0F, 1.0F };
- float s[4] __attribute__((aligned(16)));
+ static const float max[4] __attribute__((aligned (16))) =
+ { -1.0F, -1.0F, -1.0F, -1.0F };
+ static const float min[4] __attribute__((aligned (16))) =
+ { 1.0F, 1.0F, 1.0F, 1.0F };
+ float s[4] __attribute__((aligned (16)));
s[0] = s[1] = s[2] = s[3] = scale;
asm volatile (
- "movaps %0, %%xmm4\n\t" \
- "movaps %1, %%xmm5\n\t" \
+ "movaps %0, %%xmm4\n\t" \
+ "movaps %1, %%xmm5\n\t" \
"movaps %2, %%xmm6\n\t"
:
: "m" (*max),
- "m" (*min),
- "m" (*s)
+ "m" (*min),
+ "m" (*s)
: "xmm4", "xmm5", "xmm6");
- if (__builtin_expect((((long) dest & 0xf) || ((long) src & 0xf)), 0))
+ if (__builtin_expect ((((long)dest & 0xf) || ((long)src & 0xf)), 0)) {
goto sse_nonalign;
- for (i = 0; i < length; i += 4)
- {
+ }
+ for (i = 0; i < length; i += 4) {
asm volatile (
- "movaps %1, %%xmm1\n\t" \
+ "movaps %1, %%xmm1\n\t" \
"maxps %%xmm4, %%xmm1\n\t" \
"minps %%xmm5, %%xmm1\n\t" \
"mulps %%xmm6, %%xmm1\n\t" \
@@ -367,10 +356,9 @@ void x86_sse_f2i (int *dest, const float *src, int length, float scale)
return;
sse_nonalign:
- for (i = 0; i < length; i += 4)
- {
+ for (i = 0; i < length; i += 4) {
asm volatile (
- "movups %1, %%xmm1\n\t" \
+ "movups %1, %%xmm1\n\t" \
"maxps %%xmm4, %%xmm1\n\t" \
"minps %%xmm5, %%xmm1\n\t" \
"mulps %%xmm6, %%xmm1\n\t" \
@@ -386,7 +374,7 @@ sse_nonalign:
void x86_sse_i2f (float *dest, const int *src, int length, float scale)
{
int i;
- float s[4] __attribute__((aligned(16)));
+ float s[4] __attribute__((aligned (16)));
s[0] = s[1] = s[2] = s[3] = scale;
asm volatile (
@@ -395,10 +383,10 @@ void x86_sse_i2f (float *dest, const int *src, int length, float scale)
: "m" (*s)
: "xmm4" );
- if (__builtin_expect((((long) dest & 0xf) || ((long) src & 0xf)), 0))
- goto sse_nonalign;
- for (i = 0; i < length; i += 4)
- {
+ if (__builtin_expect ((((long)dest & 0xf) || ((long)src & 0xf)), 0)) {
+ goto sse_nonalign;
+ }
+ for (i = 0; i < length; i += 4) {
asm volatile (
"cvtdq2ps %1, %%xmm0\n\t" \
"mulps %%xmm4, %%xmm0\n\t" \
@@ -410,10 +398,9 @@ void x86_sse_i2f (float *dest, const int *src, int length, float scale)
return;
sse_nonalign:
- for (i = 0; i < length; i += 4)
- {
+ for (i = 0; i < length; i += 4) {
asm volatile (
- "movdqu %1, %%xmm1\n\t" \
+ "movdqu %1, %%xmm1\n\t" \
"cvtdq2ps %%xmm1, %%xmm0\n\t" \
"mulps %%xmm4, %%xmm0\n\t" \
"movups %%xmm0, %0\n\t"
@@ -423,7 +410,7 @@ sse_nonalign:
}
}
-#endif /* ARCH_X86 */
+#endif /* ARCH_X86 */
-#endif /* USE_DYNSIMD */
+#endif /* USE_DYNSIMD */
diff --git a/libjack/systemtest.c b/libjack/systemtest.c
index adf464a..2ccb431 100644
--- a/libjack/systemtest.c
+++ b/libjack/systemtest.c
@@ -1,20 +1,20 @@
/*
Copyright (C) 2001-2003 Paul Davis
-
+
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
+ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-*/
+
+ */
#include <sysdeps/systemtest.c>
diff --git a/libjack/thread.c b/libjack/thread.c
index 70cd03e..d17e7d8 100644
--- a/libjack/thread.c
+++ b/libjack/thread.c
@@ -1,25 +1,25 @@
/*
- Copyright (C) 2004 Paul Davis
-
- 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.
+ Copyright (C) 2004 Paul Davis
- 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.
+ 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.
- 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.
+ 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.
- Thread creation function including workarounds for real-time scheduling
- behaviour on different glibc versions.
+ 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.
+ Thread creation function including workarounds for real-time scheduling
+ behaviour on different glibc versions.
-*/
+
+ */
#include <config.h>
@@ -43,7 +43,7 @@
jack_thread_creator_t jack_thread_creator = pthread_create;
void
-jack_set_thread_creator (jack_thread_creator_t jtc)
+jack_set_thread_creator (jack_thread_creator_t jtc)
{
jack_thread_creator = jtc;
}
@@ -52,10 +52,11 @@ static inline void
log_result (char *msg, int res)
{
char outbuf[500];
- snprintf(outbuf, sizeof(outbuf),
- "jack_client_create_thread: error %d %s: %s",
- res, msg, strerror(res));
- jack_error(outbuf);
+
+ snprintf (outbuf, sizeof(outbuf),
+ "jack_client_create_thread: error %d %s: %s",
+ res, msg, strerror (res));
+ jack_error (outbuf);
}
static void
@@ -64,24 +65,24 @@ maybe_get_capabilities (jack_client_t* client)
#ifdef USE_CAPABILITIES
if (client != 0) {
-
+
jack_request_t req;
if (client->engine->has_capabilities != 0) {
-
+
/* we need to ask the engine for realtime capabilities
before trying to run the thread work function
- */
-
- VALGRIND_MEMSET (&req, 0, sizeof (req));
-
+ */
+
+ VALGRIND_MEMSET (&req, 0, sizeof(req));
+
req.type = SetClientCapabilities;
- req.x.cap_pid = getpid();
-
+ req.x.cap_pid = getpid ();
+
jack_client_deliver_request (client, &req);
-
+
if (req.status) {
-
+
/* what to do? engine is running realtime, it
is using capabilities and has them
(otherwise we would not get an error
@@ -89,51 +90,51 @@ maybe_get_capabilities (jack_client_t* client)
give the client the required capabilities.
for now, allow the client to run, albeit
non-realtime.
- */
-
+ */
+
jack_error ("could not receive realtime capabilities, "
"client will run non-realtime");
-
+
}
}
}
-#endif /* USE_CAPABILITIES */
-}
+#endif /* USE_CAPABILITIES */
+}
static void
-jack_thread_touch_stack()
+jack_thread_touch_stack ()
{
char buf[JACK_THREAD_STACK_TOUCH];
int i;
volatile char *buf_ptr = buf;
- for (i = 0; i < JACK_THREAD_STACK_TOUCH; i++) {
- buf_ptr[i] = (char) (i & 0xff);
- }
+ for (i = 0; i < JACK_THREAD_STACK_TOUCH; i++)
+ buf_ptr[i] = (char)(i & 0xff);
}
-typedef void (* stack_touch_t)();
+typedef void (*stack_touch_t)();
static volatile stack_touch_t ptr_jack_thread_touch_stack = jack_thread_touch_stack;
static void*
jack_thread_proxy (void* varg)
{
- jack_thread_arg_t* arg = (jack_thread_arg_t*) varg;
+ jack_thread_arg_t* arg = (jack_thread_arg_t*)varg;
+
void* (*work)(void*);
void* warg;
jack_client_t* client = arg->client;
if (arg->realtime) {
- ptr_jack_thread_touch_stack();
+ ptr_jack_thread_touch_stack ();
maybe_get_capabilities (client);
- jack_acquire_real_time_scheduling (pthread_self(), arg->priority);
+ jack_acquire_real_time_scheduling (pthread_self (), arg->priority);
}
warg = arg->arg;
work = arg->work_function;
free (arg);
-
+
return work (warg);
}
@@ -148,15 +149,15 @@ jack_client_create_thread (jack_client_t* client,
#ifndef JACK_USE_MACH_THREADS
pthread_attr_t attr;
jack_thread_arg_t* thread_args;
-#endif /* !JACK_USE_MACH_THREADS */
+#endif /* !JACK_USE_MACH_THREADS */
int result = 0;
if (!realtime) {
result = jack_thread_creator (thread, 0, start_routine, arg);
if (result) {
- log_result("creating thread with default parameters",
- result);
+ log_result ("creating thread with default parameters",
+ result);
}
return result;
}
@@ -168,34 +169,34 @@ jack_client_create_thread (jack_client_t* client,
#ifndef JACK_USE_MACH_THREADS
- pthread_attr_init(&attr);
- result = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
+ pthread_attr_init (&attr);
+ result = pthread_attr_setinheritsched (&attr, PTHREAD_EXPLICIT_SCHED);
if (result) {
- log_result("requesting explicit scheduling", result);
+ log_result ("requesting explicit scheduling", result);
return result;
}
- result = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
+ result = pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_JOINABLE);
if (result) {
- log_result("requesting joinable thread creation", result);
+ log_result ("requesting joinable thread creation", result);
return result;
}
#ifdef __OpenBSD__
- result = pthread_attr_setscope(&attr, PTHREAD_SCOPE_PROCESS);
+ result = pthread_attr_setscope (&attr, PTHREAD_SCOPE_PROCESS);
#else
- result = pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
+ result = pthread_attr_setscope (&attr, PTHREAD_SCOPE_SYSTEM);
#endif
if (result) {
- log_result("requesting system scheduling scope", result);
+ log_result ("requesting system scheduling scope", result);
return result;
}
- result = pthread_attr_setstacksize(&attr, THREAD_STACK);
- if (result) {
- log_result("setting thread stack size", result);
- return result;
- }
+ result = pthread_attr_setstacksize (&attr, THREAD_STACK);
+ if (result) {
+ log_result ("setting thread stack size", result);
+ return result;
+ }
- if ((thread_args = (jack_thread_arg_t *) malloc (sizeof (jack_thread_arg_t))) == NULL) {
+ if ((thread_args = (jack_thread_arg_t*)malloc (sizeof(jack_thread_arg_t))) == NULL) {
return -1;
}
@@ -211,7 +212,7 @@ jack_client_create_thread (jack_client_t* client,
return result;
}
-#else /* JACK_USE_MACH_THREADS */
+#else /* JACK_USE_MACH_THREADS */
result = jack_thread_creator (thread, 0, start_routine, arg);
if (result) {
@@ -221,8 +222,8 @@ jack_client_create_thread (jack_client_t* client,
/* time constraint thread */
setThreadToPriority (*thread, 96, TRUE, 10000000);
-
-#endif /* JACK_USE_MACH_THREADS */
+
+#endif /* JACK_USE_MACH_THREADS */
return 0;
}
@@ -233,7 +234,7 @@ jack_client_real_time_priority (jack_client_t* client)
if (!client->engine->real_time) {
return -1;
}
-
+
return client->engine->client_priority;
}
@@ -247,20 +248,20 @@ jack_client_max_real_time_priority (jack_client_t* client)
return client->engine->max_client_priority;
}
-#if JACK_USE_MACH_THREADS
+#if JACK_USE_MACH_THREADS
int
jack_drop_real_time_scheduling (pthread_t thread)
{
- setThreadToPriority(thread, 31, FALSE, 10000000);
- return 0;
+ setThreadToPriority (thread, 31, FALSE, 10000000);
+ return 0;
}
int
jack_acquire_real_time_scheduling (pthread_t thread, int priority)
- //priority is unused
+//priority is unused
{
- setThreadToPriority(thread, 96, TRUE, 10000000);
+ setThreadToPriority (thread, 96, TRUE, 10000000);
return 0;
}
@@ -271,8 +272,8 @@ jack_drop_real_time_scheduling (pthread_t thread)
{
struct sched_param rtparam;
int x;
-
- memset (&rtparam, 0, sizeof (rtparam));
+
+ memset (&rtparam, 0, sizeof(rtparam));
rtparam.sched_priority = 0;
if ((x = pthread_setschedparam (thread, SCHED_OTHER, &rtparam)) != 0) {
@@ -280,7 +281,7 @@ jack_drop_real_time_scheduling (pthread_t thread)
strerror (errno));
return -1;
}
- return 0;
+ return 0;
}
int
@@ -288,20 +289,20 @@ jack_acquire_real_time_scheduling (pthread_t thread, int priority)
{
struct sched_param rtparam;
int x;
-
- memset (&rtparam, 0, sizeof (rtparam));
+
+ memset (&rtparam, 0, sizeof(rtparam));
rtparam.sched_priority = priority;
-
+
if ((x = pthread_setschedparam (thread, SCHED_FIFO, &rtparam)) != 0) {
jack_error ("cannot use real-time scheduling (FIFO at priority %d) "
- "[for thread %d, from thread %d] (%d: %s)",
- rtparam.sched_priority,
- thread, pthread_self(),
+ "[for thread %d, from thread %d] (%d: %s)",
+ rtparam.sched_priority,
+ thread, pthread_self (),
x, strerror (x));
return -1;
}
- return 0;
+ return 0;
}
#endif /* JACK_USE_MACH_THREADS */
diff --git a/libjack/time.c b/libjack/time.c
index d450aa6..f476ebf 100644
--- a/libjack/time.c
+++ b/libjack/time.c
@@ -2,22 +2,22 @@
/*
Copyright (C) 2001-2003 Paul Davis
Copyright (C) 2005 Jussi Laako
-
+
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
+ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
+ */
#include <config.h>
@@ -62,26 +62,28 @@ jack_clock_source_name (jack_timer_type_t src)
#ifndef HAVE_CLOCK_GETTIME
-jack_time_t
-jack_get_microseconds_from_system (void) {
+jack_time_t
+jack_get_microseconds_from_system (void)
+{
jack_time_t jackTime;
struct timeval tv;
gettimeofday (&tv, NULL);
- jackTime = (jack_time_t) tv.tv_sec * 1000000 + (jack_time_t) tv.tv_usec;
+ jackTime = (jack_time_t)tv.tv_sec * 1000000 + (jack_time_t)tv.tv_usec;
return jackTime;
}
#else
-jack_time_t
-jack_get_microseconds_from_system (void) {
+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;
+ clock_gettime (CLOCK_MONOTONIC, &time);
+ jackTime = (jack_time_t)time.tv_sec * 1e6 +
+ (jack_time_t)time.tv_nsec / 1e3;
return jackTime;
}
diff --git a/libjack/transclient.c b/libjack/transclient.c
index 5a6fd08..9d92c36 100644
--- a/libjack/transclient.c
+++ b/libjack/transclient.c
@@ -3,22 +3,22 @@
Copyright (C) 2001-2003 Paul Davis
Copyright (C) 2003 Jack O'Quin
-
+
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 <config.h>
#include <errno.h>
@@ -39,7 +39,7 @@ jack_unique_t
jack_generate_unique_id (jack_control_t *ectl)
{
/* The jack_unique_t is an opaque type. */
- return exchange_and_add(&ectl->seq_number, 1);
+ return exchange_and_add (&ectl->seq_number, 1);
}
static inline void
@@ -49,7 +49,7 @@ jack_read_frame_time (const jack_client_t *client, jack_frame_timer_t *copy)
long timeout = 1000;
do {
- /* throttle the busy wait if we don't get
+ /* throttle the busy wait if we don't get
the answer very quickly.
XXX This is disgusting. on a UP
@@ -58,7 +58,7 @@ jack_read_frame_time (const jack_client_t *client, jack_frame_timer_t *copy)
system, it should wait for half of
the context switch time before
sleeping.
- */
+ */
if (tries > 10) {
usleep (20);
@@ -67,7 +67,7 @@ jack_read_frame_time (const jack_client_t *client, jack_frame_timer_t *copy)
/* debug code to avoid system hangs... */
if (--timeout == 0) {
jack_error ("hung in loop copying position A");
- abort();
+ abort ();
}
}
@@ -97,7 +97,7 @@ jack_transport_copy_position (jack_position_t *from, jack_position_t *to)
/* debug code to avoid system hangs... */
if (--timeout == 0) {
jack_error ("hung in loop copying position B");
- abort();
+ abort ();
}
}
*to = *from;
@@ -112,7 +112,7 @@ jack_transport_request_new_pos (jack_client_t *client, jack_position_t *pos)
jack_control_t *ectl = client->engine;
/* distinguish this request from all others */
- pos->unique_1 = pos->unique_2 = jack_generate_unique_id(ectl);
+ pos->unique_1 = pos->unique_2 = jack_generate_unique_id (ectl);
/* clients may not set these fields */
pos->usecs = ectl->current_time.usecs;
@@ -120,7 +120,7 @@ jack_transport_request_new_pos (jack_client_t *client, jack_position_t *pos)
/* carefully copy requested postion into shared memory */
jack_transport_copy_position (pos, &ectl->request_time);
-
+
return 0;
}
@@ -139,8 +139,8 @@ jack_call_sync_client (jack_client_t *client)
control->active_slowsync) {
if (client->sync_cb (ectl->transport_state,
- &ectl->current_time,
- client->sync_arg)) {
+ &ectl->current_time,
+ client->sync_arg)) {
if (control->sync_poll) {
control->sync_poll = 0;
@@ -156,14 +156,14 @@ jack_call_timebase_master (jack_client_t *client)
{
jack_client_control_t *control = client->control;
jack_control_t *ectl = client->engine;
- int new_pos = (int) ectl->pending_pos;
+ int new_pos = (int)ectl->pending_pos;
+
-
/* Make sure this is still the master; is_timebase is set in a
* critical section; timebase_cb is not. */
- if (control->is_timebase) {
+ if (control->is_timebase) {
- if (control->timebase_new) { /* first callback? */
+ if (control->timebase_new) { /* first callback? */
control->timebase_new = 0;
new_pos = 1;
}
@@ -173,10 +173,10 @@ jack_call_timebase_master (jack_client_t *client)
new_pos) {
client->timebase_cb (ectl->transport_state,
- ectl->buffer_size,
- &ectl->pending_time,
- new_pos,
- client->timebase_arg);
+ ectl->buffer_size,
+ &ectl->pending_time,
+ new_pos,
+ client->timebase_arg);
}
} else {
@@ -194,35 +194,35 @@ jack_call_timebase_master (jack_client_t *client)
jack_nframes_t
jack_get_current_transport_frame (const jack_client_t *client)
{
- jack_position_t position;
+ jack_position_t position;
float usecs;
jack_nframes_t elapsed;
jack_transport_state_t tstate;
- /* get the current transport position information.
+ /* get the current transport position information.
this is thread-safe and atomic with respect
to the structure contents.
- */
+ */
tstate = jack_transport_query (client, &position);
-
+
if (tstate != JackTransportRolling) {
return position.frame;
}
-
+
/* compute the elapsed usecs then audio frames since
the transport info was last updated
- */
-
- usecs = jack_get_microseconds() - position.usecs;
- elapsed = (jack_nframes_t) floor ((((float) position.frame_rate)
- / 1000000.0f) * usecs);
+ */
+
+ usecs = jack_get_microseconds () - position.usecs;
+ elapsed = (jack_nframes_t)floor ((((float)position.frame_rate)
+ / 1000000.0f) * usecs);
/* return the estimated transport frame position
*/
-
+
return position.frame + elapsed;
-}
+}
jack_nframes_t
jack_frames_since_cycle_start (const jack_client_t *client)
@@ -230,59 +230,59 @@ jack_frames_since_cycle_start (const jack_client_t *client)
float usecs;
jack_control_t *ectl = client->engine;
- usecs = jack_get_microseconds() - ectl->current_time.usecs;
- return (jack_nframes_t) floor ((((float) ectl->current_time.frame_rate)
- / 1000000.0f) * usecs);
+ usecs = jack_get_microseconds () - ectl->current_time.usecs;
+ return (jack_nframes_t)floor ((((float)ectl->current_time.frame_rate)
+ / 1000000.0f) * usecs);
}
int
jack_get_cycle_times (const jack_client_t *client,
jack_nframes_t *current_frames,
- jack_time_t *current_usecs,
- jack_time_t *next_usecs,
+ jack_time_t *current_usecs,
+ jack_time_t *next_usecs,
float *period_usecs)
{
jack_frame_timer_t time;
jack_read_frame_time (client, &time);
if (time.initialized) {
- *current_frames = time.frames;
- *current_usecs = time.current_wakeup;
- *next_usecs = time.next_wakeup;
- *period_usecs = time.period_usecs;
- return 0;
+ *current_frames = time.frames;
+ *current_usecs = time.current_wakeup;
+ *next_usecs = time.next_wakeup;
+ *period_usecs = time.period_usecs;
+ return 0;
}
return 1;
}
jack_time_t
-jack_get_time()
+jack_get_time ()
{
- return jack_get_microseconds();
+ return jack_get_microseconds ();
}
jack_nframes_t
-jack_time_to_frames(const jack_client_t *client, jack_time_t usecs)
+jack_time_to_frames (const jack_client_t *client, jack_time_t usecs)
{
jack_frame_timer_t time;
jack_control_t *ectl = client->engine;
jack_read_frame_time (client, &time);
if (time.initialized) {
- /*
- Make sure we have signed differences. It would make a lot of sense
- to use the standard signed intNN_t types everywhere instead of e.g.
- jack_nframes_t and jack_time_t. This would at least ensure that the
- types used below are the correct ones. There is no way to get a type
- that would be 'a signed version of jack_time_t' for example - the
- types below are inherently fragile and there is no automatic way to
- check they are the correct ones. The only way is to check manually
- against jack/types.h. FA - 16/02/2012
- */
- int64_t du = usecs - time.current_wakeup;
- int64_t dp = time.next_wakeup - time.current_wakeup;
- return time.frames + (int32_t) floor (((double) du / (double) dp
- * ectl->buffer_size) + 0.5);
+ /*
+ Make sure we have signed differences. It would make a lot of sense
+ to use the standard signed intNN_t types everywhere instead of e.g.
+ jack_nframes_t and jack_time_t. This would at least ensure that the
+ types used below are the correct ones. There is no way to get a type
+ that would be 'a signed version of jack_time_t' for example - the
+ types below are inherently fragile and there is no automatic way to
+ check they are the correct ones. The only way is to check manually
+ against jack/types.h. FA - 16/02/2012
+ */
+ int64_t du = usecs - time.current_wakeup;
+ int64_t dp = time.next_wakeup - time.current_wakeup;
+ return time.frames + (int32_t)floor (((double)du / (double)dp
+ * ectl->buffer_size) + 0.5);
}
return 0;
}
@@ -290,8 +290,9 @@ jack_time_to_frames(const jack_client_t *client, jack_time_t usecs)
jack_nframes_t
jack_frame_time (const jack_client_t *client)
{
- jack_time_t now = jack_get_microseconds();
- return jack_time_to_frames(client, now);
+ jack_time_t now = jack_get_microseconds ();
+
+ return jack_time_to_frames (client, now);
}
jack_nframes_t
@@ -301,28 +302,28 @@ jack_last_frame_time (const jack_client_t *client)
}
jack_time_t
-jack_frames_to_time(const jack_client_t *client, jack_nframes_t frames)
+jack_frames_to_time (const jack_client_t *client, jack_nframes_t frames)
{
jack_frame_timer_t time;
jack_control_t *ectl = client->engine;
jack_read_frame_time (client, &time);
if (time.initialized) {
- /*
- Make sure we have signed differences. It would make a lot of sense
- to use the standard signed intNN_t types everywhere instead of e.g.
- jack_nframes_t and jack_time_t. This would at least ensure that the
- types used below are the correct ones. There is no way to get a type
- that would be 'a signed version of jack_time_t' for example - the
- types below are inherently fragile and there is no automatic way to
- check they are the correct ones. The only way is to check manually
- against jack/types.h. FA - 16/02/2012
- */
- int32_t df = frames - time.frames;
- int64_t dp = time.next_wakeup - time.current_wakeup;
- return time.current_wakeup + (int64_t) floor (((double) df * (double) dp
- / ectl->buffer_size) + 0.5);
- }
+ /*
+ Make sure we have signed differences. It would make a lot of sense
+ to use the standard signed intNN_t types everywhere instead of e.g.
+ jack_nframes_t and jack_time_t. This would at least ensure that the
+ types used below are the correct ones. There is no way to get a type
+ that would be 'a signed version of jack_time_t' for example - the
+ types below are inherently fragile and there is no automatic way to
+ check they are the correct ones. The only way is to check manually
+ against jack/types.h. FA - 16/02/2012
+ */
+ int32_t df = frames - time.frames;
+ int64_t dp = time.next_wakeup - time.current_wakeup;
+ return time.current_wakeup + (int64_t)floor (((double)df * (double)dp
+ / ectl->buffer_size) + 0.5);
+ }
return 0;
}
@@ -351,15 +352,15 @@ jack_set_sample_rate_callback (jack_client_t *client,
return 0;
}
-int
+int
jack_release_timebase (jack_client_t *client)
{
int rc;
jack_request_t req;
jack_client_control_t *ctl = client->control;
- VALGRIND_MEMSET (&req, 0, sizeof (req));
-
+ VALGRIND_MEMSET (&req, 0, sizeof(req));
+
req.type = ResetTimeBaseClient;
jack_uuid_copy (&req.x.client_id, ctl->uuid);
@@ -373,7 +374,7 @@ jack_release_timebase (jack_client_t *client)
return rc;
}
-int
+int
jack_set_sync_callback (jack_client_t *client,
JackSyncCallback sync_callback, void *arg)
{
@@ -381,12 +382,13 @@ jack_set_sync_callback (jack_client_t *client,
jack_request_t req;
int rc;
- VALGRIND_MEMSET (&req, 0, sizeof (req));
-
- if (sync_callback)
+ VALGRIND_MEMSET (&req, 0, sizeof(req));
+
+ if (sync_callback) {
req.type = SetSyncClient;
- else
+ } else {
req.type = ResetSyncClient;
+ }
jack_uuid_copy (&req.x.client_id, ctl->uuid);
rc = jack_client_deliver_request (client, &req);
@@ -398,20 +400,20 @@ jack_set_sync_callback (jack_client_t *client,
return rc;
}
-int
+int
jack_set_sync_timeout (jack_client_t *client, jack_time_t usecs)
{
jack_request_t req;
- VALGRIND_MEMSET (&req, 0, sizeof (req));
-
+ VALGRIND_MEMSET (&req, 0, sizeof(req));
+
req.type = SetSyncTimeout;
req.x.timeout = usecs;
return jack_client_deliver_request (client, &req);
}
-int
+int
jack_set_timebase_callback (jack_client_t *client, int conditional,
JackTimebaseCallback timebase_cb, void *arg)
{
@@ -419,8 +421,8 @@ jack_set_timebase_callback (jack_client_t *client, int conditional,
jack_request_t req;
jack_client_control_t *ctl = client->control;
- VALGRIND_MEMSET (&req, 0, sizeof (req));
-
+ VALGRIND_MEMSET (&req, 0, sizeof(req));
+
req.type = SetTimeBaseClient;
jack_uuid_copy (&req.x.timebase.client_id, ctl->uuid);
req.x.timebase.conditional = conditional;
@@ -444,14 +446,14 @@ jack_transport_locate (jack_client_t *client, jack_nframes_t frame)
return jack_transport_request_new_pos (client, &pos);
}
-jack_transport_state_t
+jack_transport_state_t
jack_transport_query (const jack_client_t *client, jack_position_t *pos)
{
jack_control_t *ectl = client->engine;
if (pos) {
/* the guarded copy makes this function work in any
- * thread
+ * thread
*/
jack_transport_copy_position (&ectl->current_time, pos);
}
@@ -466,13 +468,14 @@ jack_transport_reposition (jack_client_t *client, const jack_position_t *pos)
jack_position_t tmp = *pos;
/* validate input */
- if (tmp.valid & ~JACK_POSITION_MASK) /* unknown field present? */
+ if (tmp.valid & ~JACK_POSITION_MASK) { /* unknown field present? */
return EINVAL;
+ }
return jack_transport_request_new_pos (client, &tmp);
}
-void
+void
jack_transport_start (jack_client_t *client)
{
client->engine->transport_cmd = TransportCommandStart;
@@ -494,7 +497,7 @@ jack_engine_takeover_timebase (jack_client_t *client)
{
jack_error ("jack_engine_takeover_timebase() is no longer supported.");
return ENOSYS;
-}
+}
void
jack_get_transport_info (jack_client_t *client,
@@ -503,14 +506,15 @@ jack_get_transport_info (jack_client_t *client,
jack_control_t *ectl = client->engine;
static int first_time = 1;
- if (first_time)
+ if (first_time) {
jack_error ("jack_get_transport_info() is deprecated.");
+ }
first_time = 0;
/* check that this is the process thread */
- if (!pthread_equal(client->thread_id, pthread_self())) {
- jack_error("Invalid thread for jack_get_transport_info().");
- abort(); /* kill this client */
+ if (!pthread_equal (client->thread_id, pthread_self ())) {
+ jack_error ("Invalid thread for jack_get_transport_info().");
+ abort (); /* kill this client */
}
info->usecs = ectl->current_time.usecs;
@@ -538,9 +542,10 @@ jack_set_transport_info (jack_client_t *client,
{
static int first_time = 1;
- if (first_time)
+ if (first_time) {
jack_error ("jack_set_transport_info() no longer supported.");
+ }
first_time = 0;
-}
+}
#endif /* OLD_TRANSPORT */
diff --git a/libjack/unlock.c b/libjack/unlock.c
index fc04278..9c1a37e 100644
--- a/libjack/unlock.c
+++ b/libjack/unlock.c
@@ -1,22 +1,22 @@
/* -*- mode: c; c-file-style: "bsd"; -*- */
/*
Copyright (C) 2004 Paul Davis
-
+
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
+ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
+ */
#include <stdio.h>
#include <unistd.h>
@@ -46,8 +46,8 @@ static char* library_roots[] = {
"/usr/lib",
"/usr/local/lib",
"/usr/X11R6/lib",
- "/opt/lib", /* solaris-y */
- "/opt/local/lib", /* common on OS X */
+ "/opt/lib", /* solaris-y */
+ "/opt/local/lib", /* common on OS X */
NULL
};
@@ -57,13 +57,13 @@ cleanup_mlock ()
FILE* map;
size_t start;
size_t end;
- char path[PATH_MAX+1];
+ char path[PATH_MAX + 1];
int unlock;
int i;
int whoknows;
int looks_like_library;
- snprintf (path, sizeof(path), "/proc/%d/maps", getpid());
+ snprintf (path, sizeof(path), "/proc/%d/maps", getpid ());
if ((map = fopen (path, "r")) == NULL) {
jack_error ("can't open map file");
@@ -98,7 +98,7 @@ cleanup_mlock ()
if (!looks_like_library) {
continue;
}
-
+
for (i = 0; blacklist[i]; ++i) {
if (strstr (path, blacklist[i])) {
unlock = 1;
@@ -109,21 +109,21 @@ cleanup_mlock ()
if (end - start > 1048576) {
unlock = 1;
}
-
+
for (i = 0; whitelist[i]; ++i) {
if (strstr (path, whitelist[i])) {
unlock = 0;
break;
}
}
-
+
if (unlock) {
jack_info ("unlocking %s", path);
- munlock ((char *) start, end - start);
+ munlock ((char*)start, end - start);
}
}
fclose (map);
}
-
-
+
+
diff --git a/libjack/uuid.c b/libjack/uuid.c
index 9a3894d..9b86f5f 100644
--- a/libjack/uuid.c
+++ b/libjack/uuid.c
@@ -5,17 +5,17 @@
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
+ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
+ */
#include <stdio.h>
#include <stdint.h>
@@ -26,87 +26,89 @@
#include "internal.h"
static pthread_mutex_t uuid_lock = PTHREAD_MUTEX_INITIALIZER;
-static uint32_t uuid_cnt = 0;
+static uint32_t uuid_cnt = 0;
enum JackUUIDType {
- JackUUIDPort = 0x1,
- JackUUIDClient = 0x2
+ JackUUIDPort = 0x1,
+ JackUUIDClient = 0x2
};
jack_uuid_t
jack_client_uuid_generate ()
{
- jack_uuid_t uuid = JackUUIDClient;
- pthread_mutex_lock (&uuid_lock);
- uuid = (uuid << 32) | ++uuid_cnt;
- pthread_mutex_unlock (&uuid_lock);
- return uuid;
+ jack_uuid_t uuid = JackUUIDClient;
+
+ pthread_mutex_lock (&uuid_lock);
+ uuid = (uuid << 32) | ++uuid_cnt;
+ pthread_mutex_unlock (&uuid_lock);
+ return uuid;
}
jack_uuid_t
jack_port_uuid_generate (uint32_t port_id)
{
- jack_uuid_t uuid = JackUUIDPort;
- uuid = (uuid << 32) | (port_id + 1);
- return uuid;
+ jack_uuid_t uuid = JackUUIDPort;
+
+ uuid = (uuid << 32) | (port_id + 1);
+ return uuid;
}
uint32_t
jack_uuid_to_index (jack_uuid_t u)
{
- return (u & 0xffff) - 1;
+ return (u & 0xffff) - 1;
}
int
jack_uuid_empty (jack_uuid_t u)
{
- return (u == 0);
+ return u == 0;
}
int
jack_uuid_compare (jack_uuid_t a, jack_uuid_t b)
{
- if (a == b) {
- return 0;
- }
+ if (a == b) {
+ return 0;
+ }
- if (a < b) {
- return -1;
- }
+ if (a < b) {
+ return -1;
+ }
- return 1;
+ return 1;
}
void
jack_uuid_copy (jack_uuid_t* dst, jack_uuid_t src)
{
- *dst = src;
+ *dst = src;
}
void
jack_uuid_clear (jack_uuid_t* u)
{
- *u = 0;
+ *u = 0;
}
void
jack_uuid_unparse (jack_uuid_t u, char b[JACK_UUID_STRING_SIZE])
{
- snprintf (b, JACK_UUID_STRING_SIZE, "%" PRIu64, u);
+ snprintf (b, JACK_UUID_STRING_SIZE, "%" PRIu64, u);
}
int
jack_uuid_parse (const char *b, jack_uuid_t* u)
{
- if (sscanf (b, "%" PRIu64, u) == 1) {
+ if (sscanf (b, "%" PRIu64, u) == 1) {
- if (*u < (0x1LL << 32)) {
- /* has not type bits set - not legal */
- return -1;
- }
+ if (*u < (0x1LL << 32)) {
+ /* has not type bits set - not legal */
+ return -1;
+ }
- return 0;
- }
+ return 0;
+ }
- return -1;
+ return -1;
}
diff --git a/tools b/tools
-Subproject 02ddc6ea2f16e41326c675b1bcfcd6335390b88
+Subproject 8e140b72de0231d129c6006db969f1dba4f1486