summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorColin Guthrie <cguthrie@mandriva.org>2011-02-25 09:24:07 +0000
committerColin Guthrie <cguthrie@mandriva.org>2011-02-25 09:24:07 +0000
commita3dbdb044656e2f3ab9c7ae54fe74b9669155f2d (patch)
treed033464ab41e36f04763235160f1024afa0438b7 /src
parentf51889c6f64f11221caba3615bf779fc19d0dd15 (diff)
parent821562b9bc8d1a9033daaae0fd5373498a085054 (diff)
Merge remote-tracking branch 'mkbosmans/mingw32-build'
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am84
-rw-r--r--src/daemon/cpulimit.c2
-rw-r--r--src/daemon/daemon-conf.c5
-rw-r--r--src/daemon/dumpmodules.c2
-rw-r--r--src/daemon/ltdl-bind-now.c4
-rw-r--r--src/daemon/main.c14
-rw-r--r--src/modules/bluetooth/module-bluetooth-device.c3
-rw-r--r--src/modules/module-augment-properties.c2
-rw-r--r--src/modules/module-cli.c6
-rw-r--r--src/modules/module-esound-sink.c14
-rw-r--r--src/modules/module-match.c7
-rw-r--r--src/modules/module-pipe-sink.c2
-rw-r--r--src/modules/module-pipe-source.c2
-rw-r--r--src/modules/module-protocol-stub.c5
-rw-r--r--src/modules/module-sine-source.c2
-rw-r--r--src/modules/module-waveout.c395
-rw-r--r--src/modules/oss/module-oss.c2
-rw-r--r--src/modules/rtp/module-rtp-recv.c2
-rw-r--r--src/pulse/context.c12
-rw-r--r--src/pulse/def.h1
-rw-r--r--src/pulse/mainloop-api.h1
-rw-r--r--src/pulse/mainloop.c2
-rw-r--r--src/pulse/rtclock.c2
-rw-r--r--src/pulse/thread-mainloop.c9
-rw-r--r--src/pulse/timeval.c16
-rw-r--r--src/pulse/util.c30
-rw-r--r--src/pulsecore/authkey.c3
-rw-r--r--src/pulsecore/core-rtclock.c32
-rw-r--r--src/pulsecore/core-rtclock.h2
-rw-r--r--src/pulsecore/core-util.c126
-rw-r--r--src/pulsecore/core-util.h2
-rw-r--r--src/pulsecore/creds.h4
-rw-r--r--src/pulsecore/fdsem.c18
-rw-r--r--src/pulsecore/inet_ntop.c11
-rw-r--r--src/pulsecore/inet_ntop.h8
-rw-r--r--src/pulsecore/inet_pton.c10
-rw-r--r--src/pulsecore/inet_pton.h8
-rw-r--r--src/pulsecore/iochannel.c7
-rw-r--r--src/pulsecore/ioline.c2
-rw-r--r--src/pulsecore/ipacl.c7
-rw-r--r--src/pulsecore/lock-autospawn.c13
-rw-r--r--src/pulsecore/log.c3
-rw-r--r--src/pulsecore/memblockq.c2
-rw-r--r--src/pulsecore/memtrap.c7
-rw-r--r--src/pulsecore/mutex-win32.c25
-rw-r--r--src/pulsecore/parseaddr.c5
-rw-r--r--src/pulsecore/pipe.c7
-rw-r--r--src/pulsecore/poll.c11
-rw-r--r--src/pulsecore/proplist-util.c2
-rw-r--r--src/pulsecore/pstream.c6
-rw-r--r--src/pulsecore/random.c17
-rw-r--r--src/pulsecore/rtpoll.c1
-rw-r--r--src/pulsecore/socket-client.c9
-rw-r--r--src/pulsecore/socket-server.c11
-rw-r--r--src/pulsecore/socket-util.c8
-rw-r--r--src/pulsecore/socket-util.h2
-rw-r--r--src/pulsecore/socket.h (renamed from src/pulsecore/winsock.h)9
-rw-r--r--src/pulsecore/start-child.c3
-rw-r--r--src/pulsecore/tagstruct.c2
-rw-r--r--src/pulsecore/tagstruct.h1
-rw-r--r--src/pulsecore/thread-mq.h2
-rw-r--r--src/pulsecore/thread-win32.c5
-rw-r--r--src/pulsecore/thread.h2
-rw-r--r--src/tests/asyncq-test.c2
-rw-r--r--src/tests/ipacl-test.c9
-rw-r--r--src/tests/rtstutter.c62
66 files changed, 659 insertions, 433 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 0ee7abc1..77fc882b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -74,12 +74,12 @@ BINLDFLAGS = -static
endif
if OS_IS_WIN32
-AM_LDFLAGS+=-Wl,--export-all-symbols
+AM_LDFLAGS+=-Wl,--export-all-symbols,--enable-auto-import -no-undefined
WINSOCK_LIBS=-lwsock32 -lws2_32 -lwininet
endif
FOREIGN_CFLAGS = -w
-MODULE_LDFLAGS = -module -disable-static -avoid-version $(LDFLAGS_NOUNDEFINED)
+MODULE_LDFLAGS = $(AM_LDFLAGS) -module -disable-static -avoid-version $(LDFLAGS_NOUNDEFINED)
MODULE_LIBADD = $(AM_LIBADD) libpulsecore-@PA_MAJORMINOR@.la libpulsecommon-@PA_MAJORMINOR@.la libpulse.la
###################################
@@ -112,8 +112,10 @@ pulseconf_DATA = \
daemon.conf \
client.conf
+if HAVE_DBUS
dbuspolicy_DATA = \
daemon/pulseaudio-system.conf
+endif
if HAVE_X11
xdgautostart_in_files = \
@@ -175,10 +177,15 @@ endif
# Utility programs #
###################################
+bin_SCRIPTS = esdcompat
+
bin_PROGRAMS += \
pacat \
- pactl \
- pasuspender
+ pactl
+
+if !OS_IS_WIN32
+bin_PROGRAMS += pasuspender
+endif
if HAVE_AF_UNIX
bin_PROGRAMS += pacmd
@@ -186,14 +193,13 @@ endif
if HAVE_X11
bin_PROGRAMS += pax11publish
+bin_SCRIPTS += start-pulseaudio-x11 start-pulseaudio-kde
endif
if HAVE_AVAHI
bin_PROGRAMS += pabrowse
endif
-bin_SCRIPTS = esdcompat start-pulseaudio-x11 start-pulseaudio-kde
-
pacat_SOURCES = utils/pacat.c
pacat_LDADD = $(AM_LDADD) libpulse.la libpulsecommon-@PA_MAJORMINOR@.la $(LIBSNDFILE_LIBS)
pacat_CFLAGS = $(AM_CFLAGS) $(LIBSNDFILE_CFLAGS)
@@ -256,9 +262,7 @@ TESTS = \
envelope-test \
proplist-test \
lock-autospawn-test \
- prioq-test \
- sigbus-test \
- usergroup-test
+ prioq-test
TESTS_BINARIES = \
mainloop-test \
@@ -295,9 +299,16 @@ TESTS_BINARIES = \
rtstutter \
stripnul \
lock-autospawn-test \
- prioq-test \
+ prioq-test
+
+if !OS_IS_WIN32
+TESTS += \
+ sigbus-test \
+ usergroup-test
+TESTS_BINARIES += \
sigbus-test \
usergroup-test
+endif
if HAVE_SIGXCPU
#TESTS += \
@@ -326,9 +337,11 @@ TESTS_BINARIES += \
endif
if !OS_IS_DARWIN
+if !OS_IS_WIN32
TESTS_BINARIES += \
once-test
endif
+endif
if BUILD_TESTS_DEFAULT
noinst_PROGRAMS = $(TESTS_BINARIES)
@@ -562,6 +575,14 @@ libpulsecommon_@PA_MAJORMINOR@_la_SOURCES = \
pulse/client-conf.c pulse/client-conf.h \
pulse/i18n.c pulse/i18n.h \
pulse/fork-detect.c pulse/fork-detect.h \
+ pulse/xmalloc.c pulse/xmalloc.h \
+ pulse/proplist.c pulse/proplist.h \
+ pulse/utf8.c pulse/utf8.h \
+ pulse/channelmap.c pulse/channelmap.h \
+ pulse/sample.c pulse/sample.h \
+ pulse/util.c pulse/util.h \
+ pulse/timeval.c pulse/timeval.h \
+ pulse/rtclock.c pulse/rtclock.h \
pulsecore/atomic.h \
pulsecore/authkey.c pulsecore/authkey.h \
pulsecore/conf-parser.c pulsecore/conf-parser.h \
@@ -617,7 +638,7 @@ libpulsecommon_@PA_MAJORMINOR@_la_SOURCES = \
pulsecore/tokenizer.c pulsecore/tokenizer.h \
pulsecore/usergroup.c pulsecore/usergroup.h \
pulsecore/sndfile-util.c pulsecore/sndfile-util.h \
- pulsecore/winsock.h
+ pulsecore/socket.h
libpulsecommon_@PA_MAJORMINOR@_la_CFLAGS = $(AM_CFLAGS) $(LIBSAMPLERATE_CFLAGS) $(LIBSNDFILE_CFLAGS)
libpulsecommon_@PA_MAJORMINOR@_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version
@@ -858,7 +879,7 @@ libpulsecore_@PA_MAJORMINOR@_la_SOURCES = \
pulsecore/database.h
libpulsecore_@PA_MAJORMINOR@_la_CFLAGS = $(AM_CFLAGS) $(LIBSAMPLERATE_CFLAGS) $(LIBSPEEX_CFLAGS) $(LIBSNDFILE_CFLAGS) $(WINSOCK_CFLAGS)
-libpulsecore_@PA_MAJORMINOR@_la_LDFLAGS = -avoid-version
+libpulsecore_@PA_MAJORMINOR@_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version
libpulsecore_@PA_MAJORMINOR@_la_LIBADD = $(AM_LIBADD) $(LIBLTDL) $(LIBSAMPLERATE_LIBS) $(LIBSPEEX_LIBS) $(LIBSNDFILE_LIBS) $(WINSOCK_LIBS) $(LTLIBICONV) libpulsecommon-@PA_MAJORMINOR@.la libpulse.la libpulsecore-foreign.la
if HAVE_X11
@@ -928,27 +949,27 @@ modlibexec_LTLIBRARIES += \
endif
libprotocol_simple_la_SOURCES = pulsecore/protocol-simple.c pulsecore/protocol-simple.h
-libprotocol_simple_la_LDFLAGS = -avoid-version
+libprotocol_simple_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version
libprotocol_simple_la_LIBADD = $(AM_LIBADD) libpulsecore-@PA_MAJORMINOR@.la libpulsecommon-@PA_MAJORMINOR@.la libpulse.la
libcli_la_SOURCES = pulsecore/cli.c pulsecore/cli.h
-libcli_la_LDFLAGS = -avoid-version
+libcli_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version
libcli_la_LIBADD = $(AM_LIBADD) libpulsecore-@PA_MAJORMINOR@.la libpulsecommon-@PA_MAJORMINOR@.la libpulse.la
libprotocol_cli_la_SOURCES = pulsecore/protocol-cli.c pulsecore/protocol-cli.h
-libprotocol_cli_la_LDFLAGS = -avoid-version
+libprotocol_cli_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version
libprotocol_cli_la_LIBADD = $(AM_LIBADD) libpulsecore-@PA_MAJORMINOR@.la libpulsecommon-@PA_MAJORMINOR@.la libpulse.la libcli.la
libprotocol_http_la_SOURCES = pulsecore/protocol-http.c pulsecore/protocol-http.h pulsecore/mime-type.c pulsecore/mime-type.h
-libprotocol_http_la_LDFLAGS = -avoid-version
+libprotocol_http_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version
libprotocol_http_la_LIBADD = $(AM_LIBADD) libpulsecore-@PA_MAJORMINOR@.la libpulsecommon-@PA_MAJORMINOR@.la libpulse.la
libprotocol_native_la_SOURCES = pulsecore/protocol-native.c pulsecore/protocol-native.h pulsecore/native-common.h
-libprotocol_native_la_LDFLAGS = -avoid-version
+libprotocol_native_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version
libprotocol_native_la_LIBADD = $(AM_LIBADD) libpulsecore-@PA_MAJORMINOR@.la libpulsecommon-@PA_MAJORMINOR@.la libpulse.la
libprotocol_esound_la_SOURCES = pulsecore/protocol-esound.c pulsecore/protocol-esound.h pulsecore/esound.h
-libprotocol_esound_la_LDFLAGS = -avoid-version
+libprotocol_esound_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version
libprotocol_esound_la_LIBADD = $(AM_LIBADD) libpulsecore-@PA_MAJORMINOR@.la libpulsecommon-@PA_MAJORMINOR@.la libpulse.la
librtp_la_SOURCES = \
@@ -957,19 +978,19 @@ librtp_la_SOURCES = \
modules/rtp/sap.c modules/rtp/sap.h \
modules/rtp/rtsp_client.c modules/rtp/rtsp_client.h \
modules/rtp/headerlist.c modules/rtp/headerlist.h
-librtp_la_LDFLAGS = -avoid-version
+librtp_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version
librtp_la_LIBADD = $(AM_LIBADD) libpulsecore-@PA_MAJORMINOR@.la libpulsecommon-@PA_MAJORMINOR@.la libpulse.la
libraop_la_SOURCES = \
modules/raop/raop_client.c modules/raop/raop_client.h \
modules/raop/base64.c modules/raop/base64.h
libraop_la_CFLAGS = $(AM_CFLAGS) $(OPENSSL_CFLAGS) -I$(top_srcdir)/src/modules/rtp
-libraop_la_LDFLAGS = -avoid-version
+libraop_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version
libraop_la_LIBADD = $(AM_LIBADD) $(OPENSSL_LIBS) libpulsecore-@PA_MAJORMINOR@.la librtp.la libpulsecommon-@PA_MAJORMINOR@.la libpulse.la
# Avahi
libavahi_wrap_la_SOURCES = pulsecore/avahi-wrap.c pulsecore/avahi-wrap.h
-libavahi_wrap_la_LDFLAGS = -avoid-version
+libavahi_wrap_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version
libavahi_wrap_la_CFLAGS = $(AM_CFLAGS) $(AVAHI_CFLAGS)
libavahi_wrap_la_LIBADD = $(AM_LIBADD) $(AVAHI_CFLAGS) libpulsecore-@PA_MAJORMINOR@.la libpulsecommon-@PA_MAJORMINOR@.la libpulse.la
@@ -1165,10 +1186,10 @@ pulselibexec_PROGRAMS += \
gconf-helper
endif
-#if OS_IS_WIN32
-#modlibexec_LTLIBRARIES += \
-# module-waveout.la
-#endif
+if HAVE_WAVEOUT
+modlibexec_LTLIBRARIES += \
+ module-waveout.la
+endif
if HAVE_HAL
modlibexec_LTLIBRARIES += \
@@ -1408,7 +1429,7 @@ module_esound_compat_spawnpid_la_LDFLAGS = $(MODULE_LDFLAGS)
module_esound_compat_spawnpid_la_LIBADD = $(MODULE_LIBADD)
module_esound_sink_la_SOURCES = modules/module-esound-sink.c
-module_esound_sink_la_LDFLAGS = $(MODULE_LDFLAGS)
+module_esound_sink_la_LDFLAGS = $(MODULE_LDFLAGS) $(WINSOCK_LIBS)
module_esound_sink_la_LIBADD = $(MODULE_LIBADD)
# Pipes
@@ -1432,7 +1453,7 @@ module_null_sink_la_LDFLAGS = $(MODULE_LDFLAGS)
module_null_sink_la_LIBADD = $(MODULE_LIBADD)
module_sine_source_la_SOURCES = modules/module-sine-source.c
-module_sine_source_la_LDFLAGS = -module -avoid-version
+module_sine_source_la_LDFLAGS = $(MODULE_LDFLAGS)
module_sine_source_la_LIBADD = $(MODULE_LIBADD)
# Couplings
@@ -1606,11 +1627,10 @@ module_mmkbd_evdev_la_LIBADD = $(MODULE_LIBADD)
module_mmkbd_evdev_la_CFLAGS = $(AM_CFLAGS)
# Windows waveout
-
-#module_waveout_la_SOURCES = modules/module-waveout.c
-#module_waveout_la_LDFLAGS = $(MODULE_LDFLAGS)
-#module_waveout_la_LIBADD = $(MODULE_LIBADD) -lwinmm
-#module_waveout_la_CFLAGS = $(AM_CFLAGS)
+module_waveout_la_SOURCES = modules/module-waveout.c
+module_waveout_la_LDFLAGS = $(MODULE_LDFLAGS)
+module_waveout_la_LIBADD = $(MODULE_LIBADD) -lwinmm
+module_waveout_la_CFLAGS = $(AM_CFLAGS)
# Hardware autodetection module
module_detect_la_SOURCES = modules/module-detect.c
diff --git a/src/daemon/cpulimit.c b/src/daemon/cpulimit.c
index f5042a75..c1c2a6f6 100644
--- a/src/daemon/cpulimit.c
+++ b/src/daemon/cpulimit.c
@@ -140,7 +140,7 @@ static void signal_handler(int sig) {
write_err("Soft CPU time limit exhausted, terminating.\n");
/* Try a soft cleanup */
- (void) write(the_pipe[1], &c, sizeof(c));
+ (void) pa_write(the_pipe[1], &c, sizeof(c), NULL);
phase = PHASE_SOFT;
reset_cpu_time(CPUTIME_INTERVAL_HARD);
diff --git a/src/daemon/daemon-conf.c b/src/daemon/daemon-conf.c
index 74e81351..3339f3b0 100644
--- a/src/daemon/daemon-conf.c
+++ b/src/daemon/daemon-conf.c
@@ -28,7 +28,10 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
+
+#ifdef HAVE_SCHED_H
#include <sched.h>
+#endif
#include <pulse/xmalloc.h>
#include <pulse/timeval.h>
@@ -460,10 +463,12 @@ static int parse_rtprio(const char *filename, unsigned line, const char *section
pa_assert(rvalue);
pa_assert(data);
+#ifdef HAVE_SCHED_H
if (pa_atoi(rvalue, &rtprio) < 0 || rtprio < sched_get_priority_min(SCHED_FIFO) || rtprio > sched_get_priority_max(SCHED_FIFO)) {
pa_log("[%s:%u] Invalid realtime priority '%s'.", filename, line, rvalue);
return -1;
}
+#endif
c->realtime_priority = (int) rtprio;
return 0;
diff --git a/src/daemon/dumpmodules.c b/src/daemon/dumpmodules.c
index 92470b49..d0504dc5 100644
--- a/src/daemon/dumpmodules.c
+++ b/src/daemon/dumpmodules.c
@@ -90,7 +90,9 @@ static void show_info(const char *name, const char *path, void (*info)(const cha
}
}
+#ifndef OS_IS_WIN32
extern const lt_dlsymlist lt_preloaded_symbols[];
+#endif
static int is_preloaded(const char *name) {
const lt_dlsymlist *l;
diff --git a/src/daemon/ltdl-bind-now.c b/src/daemon/ltdl-bind-now.c
index 276b2a06..2ba73ce7 100644
--- a/src/daemon/ltdl-bind-now.c
+++ b/src/daemon/ltdl-bind-now.c
@@ -51,6 +51,10 @@
#undef PA_BIND_NOW
#endif
+#ifdef OS_IS_WIN32
+#undef PA_BIND_NOW
+#endif
+
#ifdef PA_BIND_NOW
/*
diff --git a/src/daemon/main.c b/src/daemon/main.c
index cad6f70d..243e7c0a 100644
--- a/src/daemon/main.c
+++ b/src/daemon/main.c
@@ -43,10 +43,6 @@
#include <sys/mman.h>
#endif
-#ifdef HAVE_SYS_IOCTL_H
-#include <sys/ioctl.h>
-#endif
-
#ifdef HAVE_PWD_H
#include <pwd.h>
#endif
@@ -74,7 +70,7 @@
#include <pulse/i18n.h>
#include <pulsecore/lock-autospawn.h>
-#include <pulsecore/winsock.h>
+#include <pulsecore/socket.h>
#include <pulsecore/core-error.h>
#include <pulsecore/core-rtclock.h>
#include <pulsecore/core.h>
@@ -137,7 +133,7 @@ static void message_cb(pa_mainloop_api*a, pa_time_event*e, const struct timeval
}
pa_timeval_add(pa_gettimeofday(&tvnext), 100000);
- a->rtclock_time_restart(e, &tvnext);
+ a->time_restart(e, &tvnext);
}
#endif
@@ -658,6 +654,7 @@ int main(int argc, char *argv[]) {
goto finish;
}
+#ifdef HAVE_GETUID
if (getuid() == 0 && !conf->system_instance)
pa_log_warn(_("This program is not intended to be run as root (unless --system is specified)."));
#ifndef HAVE_DBUS /* A similar, only a notice worthy check was done earlier, if D-Bus is enabled. */
@@ -666,6 +663,7 @@ int main(int argc, char *argv[]) {
goto finish;
}
#endif
+#endif /* HAVE_GETUID */
if (conf->cmd == PA_CMD_START && conf->system_instance) {
pa_log(_("--start not supported for system instances."));
@@ -984,7 +982,7 @@ int main(int argc, char *argv[]) {
#endif
#ifdef OS_IS_WIN32
- win32_timer = pa_mainloop_get_api(mainloop)->rtclock_time_new(pa_mainloop_get_api(mainloop), pa_gettimeofday(&win32_tv), message_cb, NULL);
+ win32_timer = pa_mainloop_get_api(mainloop)->time_new(pa_mainloop_get_api(mainloop), pa_gettimeofday(&win32_tv), message_cb, NULL);
#endif
if (!conf->no_cpu_limit)
@@ -1080,7 +1078,7 @@ finish:
}
#ifdef OS_IS_WIN32
- if (win32_timer)
+ if (mainloop && win32_timer)
pa_mainloop_get_api(mainloop)->time_free(win32_timer);
#endif
diff --git a/src/modules/bluetooth/module-bluetooth-device.c b/src/modules/bluetooth/module-bluetooth-device.c
index 6d31c1eb..dc09ffca 100644
--- a/src/modules/bluetooth/module-bluetooth-device.c
+++ b/src/modules/bluetooth/module-bluetooth-device.c
@@ -25,8 +25,6 @@
#include <string.h>
#include <errno.h>
-#include <poll.h>
-#include <sys/ioctl.h>
#include <linux/sockios.h>
#include <arpa/inet.h>
@@ -44,6 +42,7 @@
#include <pulsecore/socket-util.h>
#include <pulsecore/thread.h>
#include <pulsecore/thread-mq.h>
+#include <pulsecore/poll.h>
#include <pulsecore/rtpoll.h>
#include <pulsecore/time-smoother.h>
#include <pulsecore/namereg.h>
diff --git a/src/modules/module-augment-properties.c b/src/modules/module-augment-properties.c
index 30df69d8..bdeee291 100644
--- a/src/modules/module-augment-properties.c
+++ b/src/modules/module-augment-properties.c
@@ -180,6 +180,7 @@ static void update_rule(struct rule *r) {
DIR *desktopfiles_dir;
struct dirent *dir;
+#ifdef DT_DIR
/* Let's try a more aggressive search, but only one level */
if ((desktopfiles_dir = opendir(DESKTOPFILEDIR))) {
while ((dir = readdir(desktopfiles_dir))) {
@@ -200,6 +201,7 @@ static void update_rule(struct rule *r) {
}
closedir(desktopfiles_dir);
}
+#endif
}
if (!found) {
r->good = FALSE;
diff --git a/src/modules/module-cli.c b/src/modules/module-cli.c
index c5ff4564..90ce3b63 100644
--- a/src/modules/module-cli.c
+++ b/src/modules/module-cli.c
@@ -105,10 +105,14 @@ int pa__init(pa_module*m) {
* of log messages, particularly because if stdout and stderr are
* dup'ed they share the same O_NDELAY, too. */
+#ifndef OS_IS_WIN32
if ((fd = pa_open_cloexec("/dev/tty", O_RDWR|O_NONBLOCK, 0)) >= 0) {
io = pa_iochannel_new(m->core->mainloop, fd, fd);
pa_log_debug("Managed to open /dev/tty.");
- } else {
+ }
+ else
+#endif
+ {
io = pa_iochannel_new(m->core->mainloop, STDIN_FILENO, STDOUT_FILENO);
pa_iochannel_set_noclose(io, TRUE);
pa_log_debug("Failed to open /dev/tty, using stdin/stdout fds instead.");
diff --git a/src/modules/module-esound-sink.c b/src/modules/module-esound-sink.c
index 02541e62..5a1391d7 100644
--- a/src/modules/module-esound-sink.c
+++ b/src/modules/module-esound-sink.c
@@ -31,11 +31,18 @@
#include <fcntl.h>
#include <unistd.h>
#include <limits.h>
-#include <poll.h>
-#include <sys/socket.h>
+
+#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
+#endif
+
+#ifdef HAVE_NETINET_TCP_H
#include <netinet/tcp.h>
+#endif
+
+#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
+#endif
#ifdef HAVE_LINUX_SOCKIOS_H
#include <linux/sockios.h>
@@ -45,6 +52,7 @@
#include <pulse/timeval.h>
#include <pulse/xmalloc.h>
+#include <pulsecore/socket.h>
#include <pulsecore/core-error.h>
#include <pulsecore/iochannel.h>
#include <pulsecore/sink.h>
@@ -60,6 +68,8 @@
#include <pulsecore/thread.h>
#include <pulsecore/time-smoother.h>
#include <pulsecore/socket-util.h>
+#include <pulsecore/rtpoll.h>
+#include <pulsecore/poll.h>
#include "module-esound-sink-symdef.h"
diff --git a/src/modules/module-match.c b/src/modules/module-match.c
index d83c86c3..f9f36fdb 100644
--- a/src/modules/module-match.c
+++ b/src/modules/module-match.c
@@ -27,10 +27,15 @@
#include <string.h>
#include <errno.h>
#include <sys/types.h>
-#include <regex.h>
#include <stdio.h>
#include <stdlib.h>
+#if defined(HAVE_REGEX_H)
+#include <regex.h>
+#elif defined(HAVE_PCREPOSIX_H)
+#include <pcreposix.h>
+#endif
+
#include <pulse/xmalloc.h>
#include <pulsecore/core-error.h>
diff --git a/src/modules/module-pipe-sink.c b/src/modules/module-pipe-sink.c
index e26cbf64..4ed91aae 100644
--- a/src/modules/module-pipe-sink.c
+++ b/src/modules/module-pipe-sink.c
@@ -32,7 +32,6 @@
#include <unistd.h>
#include <limits.h>
#include <sys/ioctl.h>
-#include <poll.h>
#ifdef HAVE_SYS_FILIO_H
#include <sys/filio.h>
@@ -49,6 +48,7 @@
#include <pulsecore/thread.h>
#include <pulsecore/thread-mq.h>
#include <pulsecore/rtpoll.h>
+#include <pulsecore/poll.h>
#include "module-pipe-sink-symdef.h"
diff --git a/src/modules/module-pipe-source.c b/src/modules/module-pipe-source.c
index 1a6607df..c50536ef 100644
--- a/src/modules/module-pipe-source.c
+++ b/src/modules/module-pipe-source.c
@@ -32,7 +32,6 @@
#include <unistd.h>
#include <limits.h>
#include <sys/ioctl.h>
-#include <sys/poll.h>
#ifdef HAVE_SYS_FILIO_H
#include <sys/filio.h>
@@ -49,6 +48,7 @@
#include <pulsecore/thread.h>
#include <pulsecore/thread-mq.h>
#include <pulsecore/rtpoll.h>
+#include <pulsecore/poll.h>
#include "module-pipe-source-symdef.h"
diff --git a/src/modules/module-protocol-stub.c b/src/modules/module-protocol-stub.c
index e21186bb..7ba54054 100644
--- a/src/modules/module-protocol-stub.c
+++ b/src/modules/module-protocol-stub.c
@@ -30,9 +30,6 @@
#include <unistd.h>
#include <limits.h>
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
#ifdef HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif
@@ -42,9 +39,9 @@
#include <pulse/xmalloc.h>
-#include <pulsecore/winsock.h>
#include <pulsecore/core-error.h>
#include <pulsecore/module.h>
+#include <pulsecore/socket.h>
#include <pulsecore/socket-server.h>
#include <pulsecore/socket-util.h>
#include <pulsecore/core-util.h>
diff --git a/src/modules/module-sine-source.c b/src/modules/module-sine-source.c
index c66099c0..955834f1 100644
--- a/src/modules/module-sine-source.c
+++ b/src/modules/module-sine-source.c
@@ -31,7 +31,6 @@
#include <fcntl.h>
#include <unistd.h>
#include <limits.h>
-#include <sys/ioctl.h>
#include <pulse/rtclock.h>
#include <pulse/timeval.h>
@@ -47,7 +46,6 @@
#include <pulsecore/thread.h>
#include <pulsecore/thread-mq.h>
#include <pulsecore/rtpoll.h>
-#include <pulsecore/poll.h>
#include "module-sine-source-symdef.h"
diff --git a/src/modules/module-waveout.c b/src/modules/module-waveout.c
index 6fedceb2..0dbf7ef9 100644
--- a/src/modules/module-waveout.c
+++ b/src/modules/module-waveout.c
@@ -31,6 +31,7 @@
#include <pulse/xmalloc.h>
#include <pulse/timeval.h>
+#include <pulse/rtclock.h>
#include <pulsecore/sink.h>
#include <pulsecore/source.h>
@@ -39,12 +40,14 @@
#include <pulsecore/sample-util.h>
#include <pulsecore/core-util.h>
#include <pulsecore/log.h>
+#include <pulsecore/thread.h>
+#include <pulsecore/thread-mq.h>
#include "module-waveout-symdef.h"
-PA_MODULE_AUTHOR("Pierre Ossman")
-PA_MODULE_DESCRIPTION("Windows waveOut Sink/Source")
-PA_MODULE_VERSION(PACKAGE_VERSION)
+PA_MODULE_AUTHOR("Pierre Ossman");
+PA_MODULE_DESCRIPTION("Windows waveOut Sink/Source");
+PA_MODULE_VERSION(PACKAGE_VERSION);
PA_MODULE_USAGE(
"sink_name=<name for the sink> "
"source_name=<name for the source> "
@@ -56,7 +59,7 @@ PA_MODULE_USAGE(
"rate=<sample rate> "
"fragments=<number of fragments> "
"fragment_size=<fragment size> "
- "channel_map=<channel map>")
+ "channel_map=<channel map>");
#define DEFAULT_SINK_NAME "wave_output"
#define DEFAULT_SOURCE_NAME "wave_input"
@@ -67,10 +70,12 @@ struct userdata {
pa_sink *sink;
pa_source *source;
pa_core *core;
- pa_time_event *event;
- pa_defer_event *defer;
pa_usec_t poll_timeout;
+ pa_thread *thread;
+ pa_thread_mq thread_mq;
+ pa_rtpoll *rtpoll;
+
uint32_t fragments, fragment_size;
uint32_t free_ofrags, free_ifrags;
@@ -103,22 +108,19 @@ static const char* const valid_modargs[] = {
NULL
};
-static void update_usage(struct userdata *u) {
- pa_module_set_used(u->module,
- (u->sink ? pa_sink_used_by(u->sink) : 0) +
- (u->source ? pa_source_used_by(u->source) : 0));
-}
-
-static void do_write(struct userdata *u)
-{
+static void do_write(struct userdata *u) {
uint32_t free_frags;
pa_memchunk memchunk;
WAVEHDR *hdr;
MMRESULT res;
+ void *p;
if (!u->sink)
return;
+ if (!PA_SINK_IS_LINKED(u->sink->state))
+ return;
+
EnterCriticalSection(&u->crit);
free_frags = u->free_ofrags;
LeaveCriticalSection(&u->crit);
@@ -137,18 +139,17 @@ static void do_write(struct userdata *u)
len = u->fragment_size - hdr->dwBufferLength;
- if (pa_sink_render(u->sink, len, &memchunk) < 0)
- break;
+ pa_sink_render(u->sink, len, &memchunk);
- assert(memchunk.memblock);
- assert(memchunk.memblock->data);
- assert(memchunk.length);
+ pa_assert(memchunk.memblock);
+ pa_assert(memchunk.length);
if (memchunk.length < len)
len = memchunk.length;
- memcpy(hdr->lpData + hdr->dwBufferLength,
- (char*)memchunk.memblock->data + memchunk.index, len);
+ p = pa_memblock_acquire(memchunk.memblock);
+ memcpy(hdr->lpData + hdr->dwBufferLength, (char*) p + memchunk.index, len);
+ pa_memblock_release(memchunk.memblock);
hdr->dwBufferLength += len;
@@ -165,15 +166,12 @@ static void do_write(struct userdata *u)
u->sink_underflow = 0;
res = waveOutPrepareHeader(u->hwo, hdr, sizeof(WAVEHDR));
- if (res != MMSYSERR_NOERROR) {
- pa_log_error(__FILE__ ": ERROR: Unable to prepare waveOut block: %d",
- res);
- }
+ if (res != MMSYSERR_NOERROR)
+ pa_log_error("Unable to prepare waveOut block: %d", res);
+
res = waveOutWrite(u->hwo, hdr, sizeof(WAVEHDR));
- if (res != MMSYSERR_NOERROR) {
- pa_log_error(__FILE__ ": ERROR: Unable to write waveOut block: %d",
- res);
- }
+ if (res != MMSYSERR_NOERROR)
+ pa_log_error("Unable to write waveOut block: %d", res);
u->written_bytes += hdr->dwBufferLength;
@@ -187,21 +185,22 @@ static void do_write(struct userdata *u)
}
}
-static void do_read(struct userdata *u)
-{
+static void do_read(struct userdata *u) {
uint32_t free_frags;
pa_memchunk memchunk;
WAVEHDR *hdr;
MMRESULT res;
+ void *p;
if (!u->source)
return;
- EnterCriticalSection(&u->crit);
+ if (!PA_SOURCE_IS_LINKED(u->source->state))
+ return;
+ EnterCriticalSection(&u->crit);
free_frags = u->free_ifrags;
u->free_ifrags = 0;
-
LeaveCriticalSection(&u->crit);
if (free_frags == u->fragments)
@@ -214,11 +213,13 @@ static void do_read(struct userdata *u)
if (hdr->dwBytesRecorded) {
memchunk.memblock = pa_memblock_new(u->core->mempool, hdr->dwBytesRecorded);
- assert(memchunk.memblock);
+ pa_assert(memchunk.memblock);
- memcpy((char*)memchunk.memblock->data, hdr->lpData, hdr->dwBytesRecorded);
+ p = pa_memblock_acquire(memchunk.memblock);
+ memcpy((char*) p, hdr->lpData, hdr->dwBytesRecorded);
+ pa_memblock_release(memchunk.memblock);
- memchunk.length = memchunk.memblock->length = hdr->dwBytesRecorded;
+ memchunk.length = hdr->dwBytesRecorded;
memchunk.index = 0;
pa_source_post(u->source, &memchunk);
@@ -226,15 +227,12 @@ static void do_read(struct userdata *u)
}
res = waveInPrepareHeader(u->hwi, hdr, sizeof(WAVEHDR));
- if (res != MMSYSERR_NOERROR) {
- pa_log_error(__FILE__ ": ERROR: Unable to prepare waveIn block: %d",
- res);
- }
+ if (res != MMSYSERR_NOERROR)
+ pa_log_error("Unable to prepare waveIn block: %d", res);
+
res = waveInAddBuffer(u->hwi, hdr, sizeof(WAVEHDR));
- if (res != MMSYSERR_NOERROR) {
- pa_log_error(__FILE__ ": ERROR: Unable to add waveIn block: %d",
- res);
- }
+ if (res != MMSYSERR_NOERROR)
+ pa_log_error("Unable to add waveIn block: %d", res);
free_frags--;
u->cur_ihdr++;
@@ -242,32 +240,53 @@ static void do_read(struct userdata *u)
}
}
-static void poll_cb(pa_mainloop_api*a, pa_time_event *e, const struct timeval *tv, void *userdata) {
+static void thread_func(void *userdata) {
struct userdata *u = userdata;
- struct timeval ntv;
- assert(u);
+ pa_assert(u);
+ pa_assert(u->sink || u->source);
- update_usage(u);
+ pa_log_debug("Thread starting up");
- do_write(u);
- do_read(u);
+ if (u->core->realtime_scheduling)
+ pa_make_realtime(u->core->realtime_priority);
- pa_gettimeofday(&ntv);
- pa_timeval_add(&ntv, u->poll_timeout);
+ pa_thread_mq_install(&u->thread_mq);
- a->rtclock_time_restart(e, &ntv);
-}
+ for (;;) {
+ int ret;
-static void defer_cb(pa_mainloop_api*a, pa_defer_event *e, void *userdata) {
- struct userdata *u = userdata;
+ if (PA_SINK_IS_OPENED(u->sink->thread_info.state) ||
+ PA_SOURCE_IS_OPENED(u->source->thread_info.state)) {
+
+ if (u->sink->thread_info.rewind_requested)
+ pa_sink_process_rewind(u->sink, 0);
- assert(u);
+ if (PA_SINK_IS_OPENED(u->sink->thread_info.state))
+ do_write(u);
+ if (PA_SOURCE_IS_OPENED(u->source->thread_info.state))
+ do_read(u);
- a->defer_enable(e, 0);
+ pa_rtpoll_set_timer_relative(u->rtpoll, u->poll_timeout);
+ } else
+ pa_rtpoll_set_timer_disabled(u->rtpoll);
- do_write(u);
- do_read(u);
+ /* Hmm, nothing to do. Let's sleep */
+ if ((ret = pa_rtpoll_run(u->rtpoll, TRUE)) < 0)
+ goto fail;
+
+ if (ret == 0)
+ goto finish;
+ }
+
+fail:
+ /* If this was no regular exit from the loop we have to continue
+ * processing messages until we received PA_MESSAGE_SHUTDOWN */
+ pa_asyncmsgq_post(u->thread_mq.outq, PA_MSGOBJECT(u->core), PA_CORE_MESSAGE_UNLOAD_MODULE, u->module, 0, NULL, NULL);
+ pa_asyncmsgq_wait_for(u->thread_mq.inq, PA_MESSAGE_SHUTDOWN);
+
+finish:
+ pa_log_debug("Thread shutting down");
}
static void CALLBACK chunk_done_cb(HWAVEOUT hwo, UINT msg, DWORD_PTR inst, DWORD param1, DWORD param2) {
@@ -277,10 +296,8 @@ static void CALLBACK chunk_done_cb(HWAVEOUT hwo, UINT msg, DWORD_PTR inst, DWORD
return;
EnterCriticalSection(&u->crit);
-
u->free_ofrags++;
- assert(u->free_ofrags <= u->fragments);
-
+ pa_assert(u->free_ofrags <= u->fragments);
LeaveCriticalSection(&u->crit);
}
@@ -291,107 +308,124 @@ static void CALLBACK chunk_ready_cb(HWAVEIN hwi, UINT msg, DWORD_PTR inst, DWORD
return;
EnterCriticalSection(&u->crit);
-
u->free_ifrags++;
- assert(u->free_ifrags <= u->fragments);
-
+ pa_assert(u->free_ifrags <= u->fragments);
LeaveCriticalSection(&u->crit);
}
-static pa_usec_t sink_get_latency_cb(pa_sink *s) {
- struct userdata *u = s->userdata;
+static pa_usec_t sink_get_latency(struct userdata *u) {
uint32_t free_frags;
MMTIME mmt;
- assert(s && u && u->sink);
+ pa_assert(u);
+ pa_assert(u->sink);
memset(&mmt, 0, sizeof(mmt));
mmt.wType = TIME_BYTES;
if (waveOutGetPosition(u->hwo, &mmt, sizeof(mmt)) == MMSYSERR_NOERROR)
- return pa_bytes_to_usec(u->written_bytes - mmt.u.cb, &s->sample_spec);
+ return pa_bytes_to_usec(u->written_bytes - mmt.u.cb, &u->sink->sample_spec);
else {
EnterCriticalSection(&u->crit);
-
free_frags = u->free_ofrags;
-
LeaveCriticalSection(&u->crit);
- return pa_bytes_to_usec((u->fragments - free_frags) * u->fragment_size,
- &s->sample_spec);
+ return pa_bytes_to_usec((u->fragments - free_frags) * u->fragment_size, &u->sink->sample_spec);
}
}
-static pa_usec_t source_get_latency_cb(pa_source *s) {
+static pa_usec_t source_get_latency(struct userdata *u) {
pa_usec_t r = 0;
- struct userdata *u = s->userdata;
uint32_t free_frags;
- assert(s && u && u->sink);
+ pa_assert(u);
+ pa_assert(u->source);
EnterCriticalSection(&u->crit);
-
free_frags = u->free_ifrags;
-
LeaveCriticalSection(&u->crit);
- r += pa_bytes_to_usec((free_frags + 1) * u->fragment_size, &s->sample_spec);
+ r += pa_bytes_to_usec((free_frags + 1) * u->fragment_size, &u->source->sample_spec);
return r;
}
-static void notify_sink_cb(pa_sink *s) {
- struct userdata *u = s->userdata;
- assert(u);
+static int process_msg(pa_msgobject *o, int code, void *data, int64_t offset, pa_memchunk *chunk) {
+ struct userdata *u;
- u->core->mainloop->defer_enable(u->defer, 1);
-}
+ if (pa_sink_isinstance(o)) {
+ u = PA_SINK(o)->userdata;
-static void notify_source_cb(pa_source *s) {
- struct userdata *u = s->userdata;
- assert(u);
+ switch (code) {
+
+ case PA_SINK_MESSAGE_GET_LATENCY: {
+ pa_usec_t r = 0;
+ if (u->hwo)
+ r = sink_get_latency(u);
+ *((pa_usec_t*) data) = r;
+ return 0;
+ }
+
+ }
+
+ return pa_sink_process_msg(o, code, data, offset, chunk);
+ }
+
+ if (pa_source_isinstance(o)) {
+ u = PA_SOURCE(o)->userdata;
+
+ switch (code) {
- u->core->mainloop->defer_enable(u->defer, 1);
+ case PA_SOURCE_MESSAGE_GET_LATENCY: {
+ pa_usec_t r = 0;
+ if (u->hwi)
+ r = source_get_latency(u);
+ *((pa_usec_t*) data) = r;
+ return 0;
+ }
+
+ }
+
+ return pa_source_process_msg(o, code, data, offset, chunk);
+ }
+
+ return -1;
}
-static int sink_get_hw_volume_cb(pa_sink *s) {
+static void sink_get_volume_cb(pa_sink *s) {
struct userdata *u = s->userdata;
DWORD vol;
pa_volume_t left, right;
if (waveOutGetVolume(u->hwo, &vol) != MMSYSERR_NOERROR)
- return -1;
+ return;
left = PA_CLAMP_VOLUME((vol & 0xFFFF) * PA_VOLUME_NORM / WAVEOUT_MAX_VOLUME);
right = PA_CLAMP_VOLUME(((vol >> 16) & 0xFFFF) * PA_VOLUME_NORM / WAVEOUT_MAX_VOLUME);
/* Windows supports > 2 channels, except for volume control */
- if (s->hw_volume.channels > 2)
- pa_cvolume_set(&s->hw_volume, s->hw_volume.channels, (left + right)/2);
-
- s->hw_volume.values[0] = left;
- if (s->hw_volume.channels > 1)
- s->hw_volume.values[1] = right;
+ if (s->real_volume.channels > 2)
+ pa_cvolume_set(&s->real_volume, s->real_volume.channels, (left + right)/2);
- return 0;
+ s->real_volume.values[0] = left;
+ if (s->real_volume.channels > 1)
+ s->real_volume.values[1] = right;
}
-static int sink_set_hw_volume_cb(pa_sink *s) {
+static void sink_set_volume_cb(pa_sink *s) {
struct userdata *u = s->userdata;
DWORD vol;
- vol = s->hw_volume.values[0] * WAVEOUT_MAX_VOLUME / PA_VOLUME_NORM;
- if (s->hw_volume.channels > 1)
- vol |= (s->hw_volume.values[0] * WAVEOUT_MAX_VOLUME / PA_VOLUME_NORM) << 16;
+ vol = s->real_volume.values[0] * WAVEOUT_MAX_VOLUME / PA_VOLUME_NORM;
+ if (s->real_volume.channels > 1)
+ vol |= (s->real_volume.values[1] * WAVEOUT_MAX_VOLUME / PA_VOLUME_NORM) << 16;
if (waveOutSetVolume(u->hwo, vol) != MMSYSERR_NOERROR)
- return -1;
-
- return 0;
+ return;
}
static int ss_to_waveformat(pa_sample_spec *ss, LPWAVEFORMATEX wf) {
wf->wFormatTag = WAVE_FORMAT_PCM;
if (ss->channels > 2) {
- pa_log_error("ERROR: More than two channels not supported.");
+ pa_log_error("More than two channels not supported.");
return -1;
}
@@ -404,7 +438,7 @@ static int ss_to_waveformat(pa_sample_spec *ss, LPWAVEFORMATEX wf) {
case 44100:
break;
default:
- pa_log_error("ERROR: Unsupported sample rate.");
+ pa_log_error("Unsupported sample rate.");
return -1;
}
@@ -415,7 +449,7 @@ static int ss_to_waveformat(pa_sample_spec *ss, LPWAVEFORMATEX wf) {
else if (ss->format == PA_SAMPLE_S16NE)
wf->wBitsPerSample = 16;
else {
- pa_log_error("ERROR: Unsupported sample format.");
+ pa_log_error("Unsupported sample format.");
return -1;
}
@@ -427,21 +461,31 @@ static int ss_to_waveformat(pa_sample_spec *ss, LPWAVEFORMATEX wf) {
return 0;
}
-int pa__init(pa_core *c, pa_module*m) {
+int pa__get_n_used(pa_module *m) {
+ struct userdata *u;
+ pa_assert(m);
+ pa_assert(m->userdata);
+ u = (struct userdata *)m->userdata;
+
+ return (u->sink ? pa_sink_used_by(u->sink) : 0) +
+ (u->source ? pa_source_used_by(u->source) : 0);
+}
+
+int pa__init(pa_module *m) {
struct userdata *u = NULL;
HWAVEOUT hwo = INVALID_HANDLE_VALUE;
HWAVEIN hwi = INVALID_HANDLE_VALUE;
WAVEFORMATEX wf;
int nfrags, frag_size;
- int record = 1, playback = 1;
+ pa_bool_t record = TRUE, playback = TRUE;
unsigned int device;
pa_sample_spec ss;
pa_channel_map map;
pa_modargs *ma = NULL;
unsigned int i;
- struct timeval tv;
- assert(c && m);
+ pa_assert(m);
+ pa_assert(m->core);
if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
pa_log("failed to parse module arguments.");
@@ -471,7 +515,7 @@ int pa__init(pa_core *c, pa_module*m) {
goto fail;
}
- ss = c->default_sample_spec;
+ ss = m->core->default_sample_spec;
if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map, PA_CHANNEL_MAP_WAVEEX) < 0) {
pa_log("failed to parse sample specification");
goto fail;
@@ -505,34 +549,47 @@ int pa__init(pa_core *c, pa_module*m) {
InitializeCriticalSection(&u->crit);
if (hwi != INVALID_HANDLE_VALUE) {
- u->source = pa_source_new(c, __FILE__, pa_modargs_get_value(ma, "source_name", DEFAULT_SOURCE_NAME), 0, &ss, &map);
- assert(u->source);
+ pa_source_new_data data;
+ pa_source_new_data_init(&data);
+ data.driver = __FILE__;
+ data.module = m;
+ pa_source_new_data_set_sample_spec(&data, &ss);
+ pa_source_new_data_set_channel_map(&data, &map);
+ pa_source_new_data_set_name(&data, pa_modargs_get_value(ma, "source_name", DEFAULT_SOURCE_NAME));
+ u->source = pa_source_new(m->core, &data, PA_SOURCE_HARDWARE|PA_SOURCE_LATENCY);
+ pa_source_new_data_done(&data);
+
+ pa_assert(u->source);
u->source->userdata = u;
- u->source->notify = notify_source_cb;
- u->source->get_latency = source_get_latency_cb;
- pa_source_set_owner(u->source, m);
pa_source_set_description(u->source, "Windows waveIn PCM");
- u->source->is_hardware = 1;
+ u->source->parent.process_msg = process_msg;
} else
u->source = NULL;
if (hwo != INVALID_HANDLE_VALUE) {
- u->sink = pa_sink_new(c, __FILE__, pa_modargs_get_value(ma, "sink_name", DEFAULT_SINK_NAME), 0, &ss, &map);
- assert(u->sink);
- u->sink->notify = notify_sink_cb;
- u->sink->get_latency = sink_get_latency_cb;
- u->sink->get_hw_volume = sink_get_hw_volume_cb;
- u->sink->set_hw_volume = sink_set_hw_volume_cb;
+ pa_sink_new_data data;
+ pa_sink_new_data_init(&data);
+ data.driver = __FILE__;
+ data.module = m;
+ pa_sink_new_data_set_sample_spec(&data, &ss);
+ pa_sink_new_data_set_channel_map(&data, &map);
+ pa_sink_new_data_set_name(&data, pa_modargs_get_value(ma, "sink_name", DEFAULT_SINK_NAME));
+ u->sink = pa_sink_new(m->core, &data, PA_SINK_HARDWARE|PA_SINK_LATENCY);
+ pa_sink_new_data_done(&data);
+
+ pa_assert(u->sink);
+ u->sink->get_volume = sink_get_volume_cb;
+ u->sink->set_volume = sink_set_volume_cb;
u->sink->userdata = u;
- pa_sink_set_owner(u->sink, m);
pa_sink_set_description(u->sink, "Windows waveOut PCM");
- u->sink->is_hardware = 1;
+ u->sink->parent.process_msg = process_msg;
} else
u->sink = NULL;
- assert(u->source || u->sink);
+ pa_assert(u->source || u->sink);
+ pa_modargs_free(ma);
- u->core = c;
+ u->core = m->core;
u->hwi = hwi;
u->hwo = hwo;
@@ -546,82 +603,84 @@ int pa__init(pa_core *c, pa_module*m) {
u->poll_timeout = pa_bytes_to_usec(u->fragments * u->fragment_size / 10, &ss);
- pa_gettimeofday(&tv);
- pa_timeval_add(&tv, u->poll_timeout);
-
- u->event = c->mainloop->rtclock_time_new(c->mainloop, &tv, poll_cb, u);
- assert(u->event);
-
- u->defer = c->mainloop->defer_new(c->mainloop, defer_cb, u);
- assert(u->defer);
- c->mainloop->defer_enable(u->defer, 0);
-
u->cur_ihdr = 0;
u->cur_ohdr = 0;
u->ihdrs = pa_xmalloc0(sizeof(WAVEHDR) * u->fragments);
- assert(u->ihdrs);
+ pa_assert(u->ihdrs);
u->ohdrs = pa_xmalloc0(sizeof(WAVEHDR) * u->fragments);
- assert(u->ohdrs);
+ pa_assert(u->ohdrs);
for (i = 0;i < u->fragments;i++) {
u->ihdrs[i].dwBufferLength = u->fragment_size;
u->ohdrs[i].dwBufferLength = u->fragment_size;
u->ihdrs[i].lpData = pa_xmalloc(u->fragment_size);
- assert(u->ihdrs);
+ pa_assert(u->ihdrs);
u->ohdrs[i].lpData = pa_xmalloc(u->fragment_size);
- assert(u->ohdrs);
+ pa_assert(u->ohdrs);
}
u->module = m;
m->userdata = u;
- pa_modargs_free(ma);
-
/* Read mixer settings */
if (u->sink)
- sink_get_hw_volume_cb(u->sink);
-
- return 0;
+ sink_get_volume_cb(u->sink);
-fail:
- if (hwi != INVALID_HANDLE_VALUE)
- waveInClose(hwi);
+ u->rtpoll = pa_rtpoll_new();
+ pa_thread_mq_init(&u->thread_mq, m->core->mainloop, u->rtpoll);
+ if (!(u->thread = pa_thread_new("waveout-source", thread_func, u))) {
+ pa_log("Failed to create thread.");
+ goto fail;
+ }
- if (hwo != INVALID_HANDLE_VALUE)
- waveOutClose(hwo);
+ if (u->sink) {
+ pa_sink_set_asyncmsgq(u->sink, u->thread_mq.inq);
+ pa_sink_set_rtpoll(u->sink, u->rtpoll);
+ pa_sink_put(u->sink);
+ }
+ if (u->source) {
+ pa_source_set_asyncmsgq(u->source, u->thread_mq.inq);
+ pa_source_set_rtpoll(u->source, u->rtpoll);
+ pa_source_put(u->source);
+ }
- if (u)
- pa_xfree(u);
+ return 0;
+fail:
if (ma)
pa_modargs_free(ma);
+ pa__done(m);
+
return -1;
}
-void pa__done(pa_core *c, pa_module*m) {
+void pa__done(pa_module *m) {
struct userdata *u;
unsigned int i;
- assert(c && m);
+ pa_assert(m);
+ pa_assert(m->core);
if (!(u = m->userdata))
return;
- if (u->event)
- c->mainloop->time_free(u->event);
+ if (u->sink)
+ pa_sink_unlink(u->sink);
+ if (u->source)
+ pa_source_unlink(u->source);
- if (u->defer)
- c->mainloop->defer_free(u->defer);
+ pa_asyncmsgq_send(u->thread_mq.inq, NULL, PA_MESSAGE_SHUTDOWN, NULL, 0, NULL);
+ if (u->thread)
+ pa_thread_free(u->thread);
+ pa_thread_mq_done(&u->thread_mq);
- if (u->sink) {
- pa_sink_disconnect(u->sink);
+ if (u->sink)
pa_sink_unref(u->sink);
- }
-
- if (u->source) {
- pa_source_disconnect(u->source);
+ if (u->source)
pa_source_unref(u->source);
- }
+
+ if (u->rtpoll)
+ pa_rtpoll_free(u->rtpoll);
if (u->hwi != INVALID_HANDLE_VALUE) {
waveInReset(u->hwi);
diff --git a/src/modules/oss/module-oss.c b/src/modules/oss/module-oss.c
index ba9b99e0..c9dc4e7a 100644
--- a/src/modules/oss/module-oss.c
+++ b/src/modules/oss/module-oss.c
@@ -53,7 +53,6 @@
#include <unistd.h>
#include <limits.h>
#include <signal.h>
-#include <poll.h>
#include <pulse/xmalloc.h>
#include <pulse/util.h>
@@ -70,6 +69,7 @@
#include <pulsecore/macro.h>
#include <pulsecore/thread-mq.h>
#include <pulsecore/rtpoll.h>
+#include <pulsecore/poll.h>
#if defined(__NetBSD__) && !defined(SNDCTL_DSP_GETODELAY)
#include <sys/audioio.h>
diff --git a/src/modules/rtp/module-rtp-recv.c b/src/modules/rtp/module-rtp-recv.c
index b59519fb..a920e66e 100644
--- a/src/modules/rtp/module-rtp-recv.c
+++ b/src/modules/rtp/module-rtp-recv.c
@@ -31,7 +31,6 @@
#include <errno.h>
#include <string.h>
#include <unistd.h>
-#include <poll.h>
#include <pulse/rtclock.h>
#include <pulse/timeval.h>
@@ -54,6 +53,7 @@
#include <pulsecore/atomic.h>
#include <pulsecore/socket-util.h>
#include <pulsecore/once.h>
+#include <pulsecore/poll.h>
#include "module-rtp-recv-symdef.h"
diff --git a/src/pulse/context.c b/src/pulse/context.c
index 7a539b4d..8f632b5d 100644
--- a/src/pulse/context.c
+++ b/src/pulse/context.c
@@ -39,9 +39,6 @@
#include <sys/wait.h>
#endif
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
#ifdef HAVE_SYS_UN_H
#include <sys/un.h>
#endif
@@ -57,9 +54,7 @@
#include <pulse/mainloop.h>
#include <pulse/timeval.h>
-#include <pulsecore/winsock.h>
#include <pulsecore/core-error.h>
-
#include <pulsecore/native-common.h>
#include <pulsecore/pdispatch.h>
#include <pulsecore/pstream.h>
@@ -69,6 +64,7 @@
#include <pulsecore/core-rtclock.h>
#include <pulsecore/core-util.h>
#include <pulsecore/log.h>
+#include <pulsecore/socket.h>
#include <pulsecore/socket-util.h>
#include <pulsecore/creds.h>
#include <pulsecore/macro.h>
@@ -589,10 +585,12 @@ static char *get_old_legacy_runtime_dir(void) {
return NULL;
}
+#ifdef HAVE_GETUID
if (st.st_uid != getuid()) {
pa_xfree(p);
return NULL;
}
+#endif
return p;
}
@@ -611,10 +609,12 @@ static char *get_very_old_legacy_runtime_dir(void) {
return NULL;
}
+#ifdef HAVE_GETUID
if (st.st_uid != getuid()) {
pa_xfree(p);
return NULL;
}
+#endif
return p;
}
@@ -1001,6 +1001,7 @@ int pa_context_connect(
/* Set up autospawning */
if (!(flags & PA_CONTEXT_NOAUTOSPAWN) && c->conf->autospawn) {
+#ifdef HAVE_GETUID
if (getuid() == 0)
pa_log_debug("Not doing autospawn since we are root.");
else {
@@ -1009,6 +1010,7 @@ int pa_context_connect(
if (api)
c->spawn_api = *api;
}
+#endif
}
pa_context_set_state(c, PA_CONTEXT_CONNECTING);
diff --git a/src/pulse/def.h b/src/pulse/def.h
index 4a8da137..ac4ae538 100644
--- a/src/pulse/def.h
+++ b/src/pulse/def.h
@@ -25,7 +25,6 @@
#include <inttypes.h>
#include <sys/time.h>
-#include <time.h>
#include <pulse/cdecl.h>
#include <pulse/sample.h>
diff --git a/src/pulse/mainloop-api.h b/src/pulse/mainloop-api.h
index aa0d5e73..0ce2219b 100644
--- a/src/pulse/mainloop-api.h
+++ b/src/pulse/mainloop-api.h
@@ -24,7 +24,6 @@
***/
#include <sys/time.h>
-#include <time.h>
#include <pulse/cdecl.h>
#include <pulse/sample.h>
diff --git a/src/pulse/mainloop.c b/src/pulse/mainloop.c
index 8f743ec7..8c261381 100644
--- a/src/pulse/mainloop.c
+++ b/src/pulse/mainloop.c
@@ -47,7 +47,7 @@
#include <pulsecore/llist.h>
#include <pulsecore/log.h>
#include <pulsecore/core-error.h>
-#include <pulsecore/winsock.h>
+#include <pulsecore/socket.h>
#include <pulsecore/macro.h>
#include "mainloop.h"
diff --git a/src/pulse/rtclock.c b/src/pulse/rtclock.c
index 49ff6aae..baa0f3a5 100644
--- a/src/pulse/rtclock.c
+++ b/src/pulse/rtclock.c
@@ -23,10 +23,10 @@
#include <config.h>
#endif
+#include <pulse/timeval.h>
#include <pulsecore/core-rtclock.h>
#include "rtclock.h"
-#include "timeval.h"
pa_usec_t pa_rtclock_now(void) {
struct timeval tv;
diff --git a/src/pulse/thread-mainloop.c b/src/pulse/thread-mainloop.c
index c3cf49c4..ef4ef56e 100644
--- a/src/pulse/thread-mainloop.c
+++ b/src/pulse/thread-mainloop.c
@@ -31,12 +31,6 @@
#include <signal.h>
#include <stdio.h>
-#ifdef HAVE_POLL_H
-#include <poll.h>
-#else
-#include <pulsecore/poll.h>
-#endif
-
#include <pulse/xmalloc.h>
#include <pulse/mainloop.h>
#include <pulse/i18n.h>
@@ -46,6 +40,7 @@
#include <pulsecore/thread.h>
#include <pulsecore/mutex.h>
#include <pulsecore/macro.h>
+#include <pulsecore/poll.h>
#include "thread-mainloop.h"
@@ -72,7 +67,7 @@ static int poll_func(struct pollfd *ufds, unsigned long nfds, int timeout, void
* avahi_simple_poll_quit() can succeed from another thread. */
pa_mutex_unlock(mutex);
- r = poll(ufds, nfds, timeout);
+ r = pa_poll(ufds, nfds, timeout);
pa_mutex_lock(mutex);
return r;
diff --git a/src/pulse/timeval.c b/src/pulse/timeval.c
index cde4417c..10ba322f 100644
--- a/src/pulse/timeval.c
+++ b/src/pulse/timeval.c
@@ -31,36 +31,28 @@
#include <windows.h>
#endif
-#include <pulsecore/winsock.h>
#include <pulsecore/macro.h>
#include <pulsecore/core-util.h>
#include "timeval.h"
struct timeval *pa_gettimeofday(struct timeval *tv) {
-#ifdef HAVE_GETTIMEOFDAY
pa_assert(tv);
- pa_assert_se(gettimeofday(tv, NULL) == 0);
- return tv;
-#elif defined(OS_IS_WIN32)
+#if defined(OS_IS_WIN32)
/*
* Copied from implementation by Steven Edwards (LGPL).
* Found on wine mailing list.
*/
-
#if defined(_MSC_VER) || defined(__BORLANDC__)
#define EPOCHFILETIME (116444736000000000i64)
#else
#define EPOCHFILETIME (116444736000000000LL)
#endif
-
FILETIME ft;
LARGE_INTEGER li;
int64_t t;
- pa_assert(tv);
-
GetSystemTimeAsFileTime(&ft);
li.LowPart = ft.dwLowDateTime;
li.HighPart = ft.dwHighDateTime;
@@ -69,11 +61,13 @@ struct timeval *pa_gettimeofday(struct timeval *tv) {
t /= 10; /* In microseconds */
tv->tv_sec = (time_t) (t / PA_USEC_PER_SEC);
tv->tv_usec = (suseconds_t) (t % PA_USEC_PER_SEC);
-
- return tv;
+#elif defined(HAVE_GETTIMEOFDAY)
+ pa_assert_se(gettimeofday(tv, NULL) == 0);
#else
#error "Platform lacks gettimeofday() or equivalent function."
#endif
+
+ return tv;
}
pa_usec_t pa_timeval_diff(const struct timeval *a, const struct timeval *b) {
diff --git a/src/pulse/util.c b/src/pulse/util.c
index ca766dab..c5cfc8ca 100644
--- a/src/pulse/util.c
+++ b/src/pulse/util.c
@@ -37,10 +37,6 @@
#include <pwd.h>
#endif
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
-
#ifdef HAVE_NETDB_H
#include <netdb.h>
#endif
@@ -56,7 +52,7 @@
#include <pulse/xmalloc.h>
#include <pulse/timeval.h>
-#include <pulsecore/winsock.h>
+#include <pulsecore/socket.h>
#include <pulsecore/core-error.h>
#include <pulsecore/log.h>
#include <pulsecore/core-util.h>
@@ -79,11 +75,15 @@ char *pa_get_user_name(char *s, size_t l) {
pa_assert(s);
pa_assert(l > 0);
- if ((p = (getuid() == 0 ? "root" : NULL)) ||
- (p = getenv("USER")) ||
- (p = getenv("LOGNAME")) ||
- (p = getenv("USERNAME")))
- {
+ p = NULL;
+#ifdef HAVE_GETUID
+ p = getuid() == 0 ? "root" : NULL;
+#endif
+ if (!p) p = getenv("USER");
+ if (!p) p = getenv("LOGNAME");
+ if (!p) p = getenv("USERNAME");
+
+ if (p) {
name = pa_strlcpy(s, p, l);
} else {
#ifdef HAVE_PWD_H
@@ -195,11 +195,11 @@ char *pa_get_binary_name(char *s, size_t l) {
{
char *rp;
- if ((rp = pa_readlink("/proc/curproc/file"))) {
- pa_strlcpy(s, pa_path_get_filename(rp), l);
- pa_xfree(rp);
- return s;
- }
+ if ((rp = pa_readlink("/proc/curproc/file"))) {
+ pa_strlcpy(s, pa_path_get_filename(rp), l);
+ pa_xfree(rp);
+ return s;
+ }
}
#endif
diff --git a/src/pulsecore/authkey.c b/src/pulsecore/authkey.c
index d671e367..92509d89 100644
--- a/src/pulsecore/authkey.c
+++ b/src/pulsecore/authkey.c
@@ -31,7 +31,6 @@
#include <stdio.h>
#include <inttypes.h>
#include <stdlib.h>
-#include <time.h>
#include <limits.h>
#include <sys/stat.h>
@@ -151,7 +150,7 @@ static char *normalize_path(const char *fn) {
#ifndef OS_IS_WIN32
if (fn[0] != '/') {
#else
- if (strlen(fn) < 3 || !isalpha(fn[0]) || fn[1] != ':' || fn[2] != '\\') {
+ if (strlen(fn) < 3 || !IsCharAlpha(fn[0]) || fn[1] != ':' || fn[2] != '\\') {
#endif
char *homedir, *s;
diff --git a/src/pulsecore/core-rtclock.c b/src/pulsecore/core-rtclock.c
index 110158ba..ac2c097a 100644
--- a/src/pulsecore/core-rtclock.c
+++ b/src/pulsecore/core-rtclock.c
@@ -40,12 +40,20 @@
#include <unistd.h>
#endif
+#ifdef HAVE_WINDOWS_H
+#include <windows.h>
+#endif
+
#include <pulse/timeval.h>
#include <pulsecore/macro.h>
#include <pulsecore/core-error.h>
#include "core-rtclock.h"
+#ifdef OS_IS_WIN32
+static int64_t counter_freq = 0;
+#endif
+
pa_usec_t pa_rtclock_age(const struct timeval *tv) {
struct timeval now;
pa_assert(tv);
@@ -88,6 +96,17 @@ struct timeval *pa_rtclock_get(struct timeval *tv) {
tv->tv_usec = ts.tv_nsec / PA_NSEC_PER_USEC;
return tv;
+#elif defined(OS_IS_WIN32)
+ if (counter_freq > 0) {
+ LARGE_INTEGER count;
+
+ pa_assert_se(QueryPerformanceCounter(&count));
+
+ tv->tv_sec = count.QuadPart / counter_freq;
+ tv->tv_usec = (count.QuadPart % counter_freq) * PA_USEC_PER_SEC / counter_freq;
+
+ return tv;
+ }
#endif /* HAVE_CLOCK_GETTIME */
return pa_gettimeofday(tv);
@@ -118,6 +137,11 @@ pa_bool_t pa_rtclock_hrtimer(void) {
pa_assert_se(clock_getres(CLOCK_REALTIME, &ts) == 0);
return ts.tv_sec == 0 && ts.tv_nsec <= (long) (PA_HRTIMER_THRESHOLD_USEC*PA_NSEC_PER_USEC);
+#elif defined(OS_IS_WIN32)
+
+ if (counter_freq > 0)
+ return counter_freq >= (int64_t) (PA_USEC_PER_SEC/PA_HRTIMER_THRESHOLD_USEC);
+
#endif /* HAVE_CLOCK_GETTIME */
return FALSE;
@@ -148,6 +172,12 @@ void pa_rtclock_hrtimer_enable(void) {
}
}
+#elif defined(OS_IS_WIN32)
+ LARGE_INTEGER freq;
+
+ pa_assert_se(QueryPerformanceFrequency(&freq));
+ counter_freq = freq.QuadPart;
+
#endif
}
@@ -174,6 +204,7 @@ struct timeval* pa_rtclock_from_wallclock(struct timeval *tv) {
return tv;
}
+#ifdef HAVE_CLOCK_GETTIME
pa_usec_t pa_timespec_load(const struct timespec *ts) {
if (PA_UNLIKELY(!ts))
@@ -198,6 +229,7 @@ struct timespec* pa_timespec_store(struct timespec *ts, pa_usec_t v) {
return ts;
}
+#endif
static struct timeval* wallclock_from_rtclock(struct timeval *tv) {
diff --git a/src/pulsecore/core-rtclock.h b/src/pulsecore/core-rtclock.h
index 3b393ed5..62535368 100644
--- a/src/pulsecore/core-rtclock.h
+++ b/src/pulsecore/core-rtclock.h
@@ -43,8 +43,10 @@ void pa_rtclock_hrtimer_enable(void);
struct timeval* pa_rtclock_from_wallclock(struct timeval *tv);
+#ifdef HAVE_CLOCK_GETTIME
pa_usec_t pa_timespec_load(const struct timespec *ts);
struct timespec* pa_timespec_store(struct timespec *ts, pa_usec_t v);
+#endif
struct timeval* pa_timeval_rtstore(struct timeval *tv, pa_usec_t v, pa_bool_t rtclock);
diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c
index 4e7d0d71..8a377e37 100644
--- a/src/pulsecore/core-util.c
+++ b/src/pulsecore/core-util.c
@@ -34,16 +34,24 @@
#include <fcntl.h>
#include <unistd.h>
#include <limits.h>
-#include <time.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
-#include <sys/time.h>
#include <dirent.h>
-#include <regex.h>
+
+#ifdef HAVE_LANGINFO_H
#include <langinfo.h>
+#endif
+
+#ifdef HAVE_UNAME
#include <sys/utsname.h>
-#include <sys/socket.h>
+#endif
+
+#if defined(HAVE_REGEX_H)
+#include <regex.h>
+#elif defined(HAVE_PCREPOSIX_H)
+#include <pcreposix.h>
+#endif
#ifdef HAVE_STRTOF_L
#include <locale.h>
@@ -81,6 +89,10 @@
#include <windows.h>
#endif
+#ifndef ENOTSUP
+#define ENOTSUP 135
+#endif
+
#ifdef HAVE_PWD_H
#include <pwd.h>
#endif
@@ -110,7 +122,7 @@
#include <pulse/utf8.h>
#include <pulsecore/core-error.h>
-#include <pulsecore/winsock.h>
+#include <pulsecore/socket.h>
#include <pulsecore/log.h>
#include <pulsecore/macro.h>
#include <pulsecore/thread.h>
@@ -118,6 +130,7 @@
#include <pulsecore/usergroup.h>
#include <pulsecore/strlist.h>
#include <pulsecore/cpu-x86.h>
+#include <pulsecore/pipe.h>
#include "core-util.h"
@@ -136,20 +149,18 @@ static pa_strlist *recorded_env = NULL;
#define PULSE_ROOTENV "PULSE_ROOT"
int pa_set_root(HANDLE handle) {
- char library_path[MAX_PATH + sizeof(PULSE_ROOTENV) + 1], *sep;
-
- strcpy(library_path, PULSE_ROOTENV "=");
+ char library_path[MAX_PATH], *sep;
/* FIXME: Needs to set errno */
- if (!GetModuleFileName(handle, library_path + sizeof(PULSE_ROOTENV), MAX_PATH))
+ if (!GetModuleFileName(handle, library_path, MAX_PATH))
return 0;
sep = strrchr(library_path, PA_PATH_SEP_CHAR);
if (sep)
*sep = '\0';
- if (_putenv(library_path) < 0)
+ if (!SetEnvironmentVariable(PULSE_ROOTENV, library_path))
return 0;
return 1;
@@ -217,7 +228,7 @@ int pa_make_secure_dir(const char* dir, mode_t m, uid_t uid, gid_t gid) {
if (r < 0 && errno != EEXIST)
return -1;
-#ifdef HAVE_FSTAT
+#if defined(HAVE_FSTAT) && !defined(OS_IS_WIN32)
if ((fd = open(dir,
#ifdef O_CLOEXEC
O_CLOEXEC|
@@ -255,7 +266,6 @@ int pa_make_secure_dir(const char* dir, mode_t m, uid_t uid, gid_t gid) {
#endif
pa_assert_se(pa_close(fd) >= 0);
-
#endif
#ifdef HAVE_LSTAT
@@ -611,6 +621,7 @@ char *pa_strlcpy(char *b, const char *s, size_t l) {
}
static int set_scheduler(int rtprio) {
+#ifdef HAVE_SCHED_H
struct sched_param sp;
#ifdef HAVE_DBUS
int r;
@@ -634,6 +645,7 @@ static int set_scheduler(int rtprio) {
pa_log_debug("SCHED_RR worked.");
return 0;
}
+#endif /* HAVE_SCHED_H */
#ifdef HAVE_DBUS
/* Try to talk to RealtimeKit */
@@ -684,14 +696,21 @@ int pa_make_realtime(int rtprio) {
pa_log_info("Successfully enabled SCHED_RR scheduling for thread, with priority %i, which is lower than the requested %i.", p, rtprio);
return 0;
}
+#elif defined(OS_IS_WIN32)
+ /* Windows only allows realtime scheduling to be set on a per process basis.
+ * Therefore, instead of making the thread realtime, just give it the highest non-realtime priority. */
+ if(SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL)) {
+ pa_log_info("Successfully enabled THREAD_PRIORITY_TIME_CRITICAL scheduling for thread.");
+ return 0;
+ }
- pa_log_info("Failed to acquire real-time scheduling: %s", pa_cstrerror(errno));
- return -1;
+ pa_log_warn("SetThreadPriority() failed: 0x%08X", GetLastError());
+ errno = EPERM;
#else
-
errno = ENOTSUP;
- return -1;
#endif
+ pa_log_info("Failed to acquire real-time scheduling: %s", pa_cstrerror(errno));
+ return -1;
}
static int set_nice(int nice_level) {
@@ -703,10 +722,12 @@ static int set_nice(int nice_level) {
dbus_error_init(&error);
#endif
+#ifdef HAVE_SYS_RESOURCE_H
if (setpriority(PRIO_PROCESS, 0, nice_level) >= 0) {
pa_log_debug("setpriority() worked.");
return 0;
}
+#endif
#ifdef HAVE_DBUS
/* Try to talk to RealtimeKit */
@@ -827,6 +848,7 @@ int pa_parse_boolean(const char *v) {
else if (!strcmp(v, "0") || v[0] == 'n' || v[0] == 'N' || v[0] == 'f' || v[0] == 'F' || !strcasecmp(v, "off"))
return 0;
+#ifdef HAVE_LANGINFO_H
/* And then we check language dependant */
if ((expr = nl_langinfo(YESEXPR)))
if (expr[0])
@@ -837,6 +859,7 @@ int pa_parse_boolean(const char *v) {
if (expr[0])
if (pa_match(expr, v) > 0)
return 0;
+#endif
errno = EINVAL;
return -1;
@@ -1150,23 +1173,23 @@ int pa_check_in_group(gid_t g) {
#else /* HAVE_GRP_H */
int pa_own_uid_in_group(const char *name, gid_t *gid) {
- errno = ENOSUP;
+ errno = ENOTSUP;
return -1;
}
int pa_uid_in_group(uid_t uid, const char *name) {
- errno = ENOSUP;
+ errno = ENOTSUP;
return -1;
}
gid_t pa_get_gid_of_group(const char *name) {
- errno = ENOSUP;
+ errno = ENOTSUP;
return (gid_t) -1;
}
int pa_check_in_group(gid_t g) {
- errno = ENOSUP;
+ errno = ENOTSUP;
return -1;
}
@@ -1339,11 +1362,13 @@ static char *get_pulse_home(void) {
goto finish;
}
+#ifdef HAVE_GETUID
if (st.st_uid != getuid()) {
pa_log_error("Home directory %s not ours.", h);
errno = EACCES;
goto finish;
}
+#endif
ret = pa_sprintf_malloc("%s" PA_PATH_SEP ".pulse", h);
@@ -1441,7 +1466,11 @@ static char* make_random_dir(mode_t m) {
fn[i] = table[rand() % (sizeof(table)-1)];
u = umask((~m) & 0777);
+#ifndef OS_IS_WIN32
r = mkdir(fn, m);
+#else
+ r = mkdir(fn);
+#endif
saved_errno = errno;
umask(u);
@@ -1464,6 +1493,7 @@ static int make_random_dir_and_link(mode_t m, const char *k) {
if (!(p = make_random_dir(m)))
return -1;
+#ifdef HAVE_SYMLINK
if (symlink(p, k) < 0) {
int saved_errno = errno;
@@ -1476,6 +1506,10 @@ static int make_random_dir_and_link(mode_t m, const char *k) {
errno = saved_errno;
return -1;
}
+#else
+ pa_xfree(p);
+ return -1;
+#endif
pa_xfree(p);
return 0;
@@ -1534,6 +1568,7 @@ char *pa_get_runtime_dir(void) {
goto fail;
}
+#ifdef HAVE_SYMLINK
/* Hmm, so the runtime directory didn't exist yet, so let's
* create one in /tmp and symlink that to it */
@@ -1546,6 +1581,11 @@ char *pa_get_runtime_dir(void) {
goto fail;
}
+#else
+ /* No symlink possible, so let's just create the runtime directly */
+ if (!mkdir(k))
+ goto fail;
+#endif
return k;
}
@@ -1560,6 +1600,7 @@ char *pa_get_runtime_dir(void) {
/* Hmm, so this symlink is still around, make sure nobody fools
* us */
+#ifdef HAVE_LSTAT
if (lstat(p, &st) < 0) {
if (errno != ENOENT) {
@@ -1579,6 +1620,7 @@ char *pa_get_runtime_dir(void) {
pa_log_info("Hmm, runtime path exists, but points to an invalid directory. Changing runtime directory.");
}
+#endif
pa_xfree(p);
p = NULL;
@@ -2218,6 +2260,7 @@ void pa_close_pipe(int fds[2]) {
}
char *pa_readlink(const char *p) {
+#ifdef HAVE_READLINK
size_t l = 100;
for (;;) {
@@ -2239,6 +2282,9 @@ char *pa_readlink(const char *p) {
pa_xfree(c);
l *= 2;
}
+#else
+ return NULL;
+#endif
}
int pa_close_all(int except_fd, ...) {
@@ -2277,6 +2323,7 @@ int pa_close_all(int except_fd, ...) {
}
int pa_close_allv(const int except_fds[]) {
+#ifndef OS_IS_WIN32
struct rlimit rl;
int maxfd, fd;
@@ -2366,6 +2413,7 @@ int pa_close_allv(const int except_fds[]) {
if (pa_close(fd) < 0 && errno != EBADF)
return -1;
}
+#endif /* !OS_IS_WIN32 */
return 0;
}
@@ -2406,6 +2454,7 @@ int pa_unblock_sigs(int except, ...) {
}
int pa_unblock_sigsv(const int except[]) {
+#ifndef OS_IS_WIN32
int i;
sigset_t ss;
@@ -2417,6 +2466,9 @@ int pa_unblock_sigsv(const int except[]) {
return -1;
return sigprocmask(SIG_SETMASK, &ss, NULL);
+#else
+ return 0;
+#endif
}
int pa_reset_sigs(int except, ...) {
@@ -2455,6 +2507,7 @@ int pa_reset_sigs(int except, ...) {
}
int pa_reset_sigsv(const int except[]) {
+#ifndef OS_IS_WIN32
int sig;
for (sig = 1; sig < NSIG; sig++) {
@@ -2491,6 +2544,7 @@ int pa_reset_sigsv(const int except[]) {
return -1;
}
}
+#endif
return 0;
}
@@ -2501,7 +2555,11 @@ void pa_set_env(const char *key, const char *value) {
/* This is not thread-safe */
- putenv(pa_sprintf_malloc("%s=%s", key, value));
+#ifdef OS_IS_WIN32
+ SetEnvironmentVariable(key, value);
+#else
+ setenv(key, value, 1);
+#endif
}
void pa_set_env_and_record(const char *key, const char *value) {
@@ -2526,7 +2584,11 @@ void pa_unset_env_recorded(void) {
if (!s)
break;
+#ifdef OS_IS_WIN32
+ SetEnvironmentVariable(s, NULL);
+#else
unsetenv(s);
+#endif
pa_xfree(s);
}
}
@@ -2625,9 +2687,13 @@ char *pa_machine_id(void) {
if ((h = pa_get_host_name_malloc()))
return h;
+#ifndef OS_IS_WIN32
/* If no hostname was set we use the POSIX hostid. It's usually
* the IPv4 address. Might not be that stable. */
return pa_sprintf_malloc("%08lx", (unsigned long) gethostid);
+#else
+ return NULL;
+#endif
}
char *pa_session_id(void) {
@@ -2640,11 +2706,22 @@ char *pa_session_id(void) {
}
char *pa_uname_string(void) {
+#ifdef HAVE_UNAME
struct utsname u;
pa_assert_se(uname(&u) >= 0);
return pa_sprintf_malloc("%s %s %s %s", u.sysname, u.machine, u.release, u.version);
+#endif
+#ifdef OS_IS_WIN32
+ OSVERSIONINFO i;
+
+ pa_zero(i);
+ i.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+ pa_assert_se(GetVersionEx(&i));
+
+ return pa_sprintf_malloc("Windows %d.%d (%d) %s", i.dwMajorVersion, i.dwMinorVersion, i.dwBuildNumber, i.szCSDVersion);
+#endif
}
#ifdef HAVE_VALGRIND_MEMCHECK_H
@@ -2793,10 +2870,17 @@ char *pa_realpath(const char *path) {
char *path_buf;
path_buf = pa_xmalloc(PATH_MAX);
+#if defined(OS_IS_WIN32)
+ if (!(t = _fullpath(path_buf, path, _MAX_PATH))) {
+ pa_xfree(path_buf);
+ return NULL;
+ }
+#else
if (!(t = realpath(path, path_buf))) {
pa_xfree(path_buf);
return NULL;
}
+#endif
}
#else
#error "It's not clear whether this system supports realpath(..., NULL) like GNU libc does. If it doesn't we need a private version of realpath() here."
diff --git a/src/pulsecore/core-util.h b/src/pulsecore/core-util.h
index 0d63cfcb..8619330d 100644
--- a/src/pulsecore/core-util.h
+++ b/src/pulsecore/core-util.h
@@ -28,7 +28,6 @@
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
-#include <sys/socket.h>
#ifdef HAVE_SYS_RESOURCE_H
#include <sys/resource.h>
@@ -36,6 +35,7 @@
#include <pulse/gccmacro.h>
#include <pulsecore/macro.h>
+#include <pulsecore/socket.h>
#ifndef PACKAGE
#error "Please include config.h before including this file!"
diff --git a/src/pulsecore/creds.h b/src/pulsecore/creds.h
index c15c469b..9e6fb124 100644
--- a/src/pulsecore/creds.h
+++ b/src/pulsecore/creds.h
@@ -28,9 +28,7 @@
#error "Please include config.h before including this file!"
#endif
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
+#include <pulsecore/socket.h>
#ifdef HAVE_SYS_UN_H
#include <sys/un.h>
diff --git a/src/pulsecore/fdsem.c b/src/pulsecore/fdsem.c
index 5bf99479..62380451 100644
--- a/src/pulsecore/fdsem.c
+++ b/src/pulsecore/fdsem.c
@@ -154,7 +154,7 @@ static void flush(pa_fdsem *f) {
if (f->efd >= 0) {
uint64_t u;
- if ((r = read(f->efd, &u, sizeof(u))) != sizeof(u)) {
+ if ((r = pa_read(f->efd, &u, sizeof(u), NULL)) != sizeof(u)) {
if (r >= 0 || errno != EINTR) {
pa_log_error("Invalid read from eventfd: %s", r < 0 ? pa_cstrerror(errno) : "EOF");
@@ -167,7 +167,7 @@ static void flush(pa_fdsem *f) {
} else
#endif
- if ((r = read(f->fds[0], &x, sizeof(x))) <= 0) {
+ if ((r = pa_read(f->fds[0], &x, sizeof(x), NULL)) <= 0) {
if (r >= 0 || errno != EINTR) {
pa_log_error("Invalid read from pipe: %s", r < 0 ? pa_cstrerror(errno) : "EOF");
@@ -197,9 +197,9 @@ void pa_fdsem_post(pa_fdsem *f) {
if (f->efd >= 0) {
uint64_t u = 1;
- if ((r = write(f->efd, &u, sizeof(u))) != sizeof(u)) {
+ if ((r = pa_write(f->efd, &u, sizeof(u), NULL)) != sizeof(u)) {
if (r >= 0 || errno != EINTR) {
- pa_log_error("Invalid read from pipe: %s", r < 0 ? pa_cstrerror(errno) : "EOF");
+ pa_log_error("Invalid write to eventfd: %s", r < 0 ? pa_cstrerror(errno) : "EOF");
pa_assert_not_reached();
}
@@ -208,9 +208,9 @@ void pa_fdsem_post(pa_fdsem *f) {
} else
#endif
- if ((r = write(f->fds[1], &x, 1)) != 1) {
+ if ((r = pa_write(f->fds[1], &x, 1, NULL)) != 1) {
if (r >= 0 || errno != EINTR) {
- pa_log_error("Invalid read from pipe: %s", r < 0 ? pa_cstrerror(errno) : "EOF");
+ pa_log_error("Invalid write to pipe: %s", r < 0 ? pa_cstrerror(errno) : "EOF");
pa_assert_not_reached();
}
@@ -241,10 +241,10 @@ void pa_fdsem_wait(pa_fdsem *f) {
if (f->efd >= 0) {
uint64_t u;
- if ((r = read(f->efd, &u, sizeof(u))) != sizeof(u)) {
+ if ((r = pa_read(f->efd, &u, sizeof(u), NULL)) != sizeof(u)) {
if (r >= 0 || errno != EINTR) {
- pa_log_error("Invalid read from pipe: %s", r < 0 ? pa_cstrerror(errno) : "EOF");
+ pa_log_error("Invalid read from eventfd: %s", r < 0 ? pa_cstrerror(errno) : "EOF");
pa_assert_not_reached();
}
@@ -255,7 +255,7 @@ void pa_fdsem_wait(pa_fdsem *f) {
} else
#endif
- if ((r = read(f->fds[0], &x, sizeof(x))) <= 0) {
+ if ((r = pa_read(f->fds[0], &x, sizeof(x), NULL)) <= 0) {
if (r >= 0 || errno != EINTR) {
pa_log_error("Invalid read from pipe: %s", r < 0 ? pa_cstrerror(errno) : "EOF");
diff --git a/src/pulsecore/inet_ntop.c b/src/pulsecore/inet_ntop.c
index 012a1a05..059b25cc 100644
--- a/src/pulsecore/inet_ntop.c
+++ b/src/pulsecore/inet_ntop.c
@@ -28,11 +28,9 @@
#ifndef HAVE_INET_NTOP
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
-
-#include "winsock.h"
+#include <pulsecore/core-util.h>
+#include <pulsecore/macro.h>
+#include <pulsecore/socket.h>
#include "inet_ntop.h"
@@ -42,7 +40,8 @@ const char *inet_ntop(int af, const void *src, char *dst, socklen_t cnt) {
struct in6_addr *in6 = (struct in6_addr*)src;
#endif
- assert(src && dst);
+ pa_assert(src);
+ pa_assert(dst);
switch (af) {
case AF_INET:
diff --git a/src/pulsecore/inet_ntop.h b/src/pulsecore/inet_ntop.h
index 7fb67b44..77ace6a4 100644
--- a/src/pulsecore/inet_ntop.h
+++ b/src/pulsecore/inet_ntop.h
@@ -1,12 +1,12 @@
#ifndef fooinet_ntophfoo
#define fooinet_ntophfoo
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
+#ifndef HAVE_INET_NTOP
-#include "winsock.h"
+#include <pulsecore/socket.h>
const char *inet_ntop(int af, const void *src, char *dst, socklen_t cnt);
#endif
+
+#endif
diff --git a/src/pulsecore/inet_pton.c b/src/pulsecore/inet_pton.c
index abdfa467..efb15263 100644
--- a/src/pulsecore/inet_pton.c
+++ b/src/pulsecore/inet_pton.c
@@ -28,11 +28,8 @@
#ifndef HAVE_INET_PTON
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
-
-#include "winsock.h"
+#include <pulsecore/macro.h>
+#include <pulsecore/socket.h>
#include "inet_pton.h"
@@ -42,7 +39,8 @@ int inet_pton(int af, const char *src, void *dst) {
struct in6_addr *in6 = (struct in6_addr*)dst;
#endif
- assert(src && dst);
+ pa_assert(src);
+ pa_assert(dst);
switch (af) {
case AF_INET:
diff --git a/src/pulsecore/inet_pton.h b/src/pulsecore/inet_pton.h
index 111b4a07..913efc4c 100644
--- a/src/pulsecore/inet_pton.h
+++ b/src/pulsecore/inet_pton.h
@@ -1,12 +1,12 @@
#ifndef fooinet_ptonhfoo
#define fooinet_ptonhfoo
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
+#ifndef HAVE_INET_PTON
-#include "winsock.h"
+#include <pulsecore/socket.h>
int inet_pton(int af, const char *src, void *dst);
#endif
+
+#endif
diff --git a/src/pulsecore/iochannel.c b/src/pulsecore/iochannel.c
index f85c9896..f89b0670 100644
--- a/src/pulsecore/iochannel.c
+++ b/src/pulsecore/iochannel.c
@@ -28,19 +28,16 @@
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
+
#ifdef HAVE_SYS_UN_H
#include <sys/un.h>
#endif
-#include "winsock.h"
-
#include <pulse/xmalloc.h>
#include <pulsecore/core-error.h>
#include <pulsecore/core-util.h>
+#include <pulsecore/socket.h>
#include <pulsecore/socket-util.h>
#include <pulsecore/log.h>
#include <pulsecore/macro.h>
diff --git a/src/pulsecore/ioline.c b/src/pulsecore/ioline.c
index 7afdb08c..963f7d22 100644
--- a/src/pulsecore/ioline.c
+++ b/src/pulsecore/ioline.c
@@ -30,7 +30,7 @@
#include <pulse/xmalloc.h>
-#include <pulsecore/winsock.h>
+#include <pulsecore/socket.h>
#include <pulsecore/core-error.h>
#include <pulsecore/log.h>
#include <pulsecore/macro.h>
diff --git a/src/pulsecore/ipacl.c b/src/pulsecore/ipacl.c
index 312e0403..0cbe34af 100644
--- a/src/pulsecore/ipacl.c
+++ b/src/pulsecore/ipacl.c
@@ -28,9 +28,6 @@
#include <sys/types.h>
#include <string.h>
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
@@ -50,10 +47,10 @@
#include <pulsecore/llist.h>
#include <pulsecore/log.h>
#include <pulsecore/macro.h>
-#include <pulsecore/winsock.h>
+#include <pulsecore/socket.h>
#ifndef HAVE_INET_PTON
-#include "inet_pton.h"
+#include <pulsecore/inet_pton.h>
#endif
#include "ipacl.h"
diff --git a/src/pulsecore/lock-autospawn.c b/src/pulsecore/lock-autospawn.c
index 422f5eb2..a9c942fb 100644
--- a/src/pulsecore/lock-autospawn.c
+++ b/src/pulsecore/lock-autospawn.c
@@ -26,9 +26,11 @@
#include <fcntl.h>
#include <errno.h>
#include <string.h>
-#include <sys/poll.h>
#include <signal.h>
+
+#ifdef HAVE_PTHREAD
#include <pthread.h>
+#endif
#include <pulse/i18n.h>
#include <pulse/xmalloc.h>
@@ -159,7 +161,7 @@ static void ping(void) {
for (;;) {
char x = 'x';
- if ((s = write(pipe_fd[1], &x, 1)) == 1)
+ if ((s = pa_write(pipe_fd[1], &x, 1, NULL)) == 1)
break;
pa_assert(s < 0);
@@ -186,7 +188,7 @@ static void wait_for_ping(void) {
if ((k = pa_poll(&pfd, 1, -1)) != 1) {
pa_assert(k < 0);
pa_assert(errno == EINTR);
- } else if ((s = read(pipe_fd[0], &x, 1)) != 1) {
+ } else if ((s = pa_read(pipe_fd[0], &x, 1, NULL)) != 1) {
pa_assert(s < 0);
pa_assert(errno == EAGAIN);
}
@@ -198,7 +200,7 @@ static void empty_pipe(void) {
pa_assert(pipe_fd[0] >= 0);
- if ((s = read(pipe_fd[0], &x, sizeof(x))) < 1) {
+ if ((s = pa_read(pipe_fd[0], &x, sizeof(x), NULL)) < 1) {
pa_assert(s < 0);
pa_assert(errno == EAGAIN);
}
@@ -207,11 +209,14 @@ static void empty_pipe(void) {
static void thread_func(void *u) {
int fd;
char *lf;
+
+#ifdef HAVE_PTHREAD
sigset_t fullset;
/* No signals in this thread please */
sigfillset(&fullset);
pthread_sigmask(SIG_BLOCK, &fullset, NULL);
+#endif
if (!(lf = pa_runtime_path(AUTOSPAWN_LOCK))) {
pa_log_warn(_("Cannot access autospawn lock."));
diff --git a/src/pulsecore/log.c b/src/pulsecore/log.c
index 7ba41ee9..2c0e267a 100644
--- a/src/pulsecore/log.c
+++ b/src/pulsecore/log.c
@@ -374,6 +374,9 @@ void pa_log_levelv_meta(
fprintf(stderr, "%s%c: %s%s%s%s%s%s\n", timestamp, level_to_char[level], location, prefix, t, grey, pa_strempty(bt), suffix);
else
fprintf(stderr, "%s%s%s%s%s%s%s\n", timestamp, location, prefix, t, grey, pa_strempty(bt), suffix);
+#ifdef OS_IS_WIN32
+ fflush(stderr);
+#endif
pa_xfree(local_t);
diff --git a/src/pulsecore/memblockq.c b/src/pulsecore/memblockq.c
index c7840484..11faedac 100644
--- a/src/pulsecore/memblockq.c
+++ b/src/pulsecore/memblockq.c
@@ -23,8 +23,6 @@
#include <config.h>
#endif
-#include <sys/time.h>
-#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
diff --git a/src/pulsecore/memtrap.c b/src/pulsecore/memtrap.c
index 4fc18210..b56d806a 100644
--- a/src/pulsecore/memtrap.c
+++ b/src/pulsecore/memtrap.c
@@ -24,7 +24,10 @@
#endif
#include <signal.h>
+
+#ifdef HAVE_SYS_MMAN_H
#include <sys/mman.h>
+#endif
/* This is deprecated on glibc but is still used by FreeBSD */
#if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
@@ -68,6 +71,7 @@ static void sigsafe_error(const char *s) {
(void) write(STDERR_FILENO, s, strlen(s));
}
+#ifdef HAVE_SIGACTION
static void signal_handler(int sig, siginfo_t* si, void *data) {
unsigned j;
pa_memtrap *m;
@@ -102,6 +106,7 @@ fail:
sigsafe_error("Failed to handle SIGBUS.\n");
abort();
}
+#endif
static void memtrap_link(pa_memtrap *m, unsigned j) {
pa_assert(m);
@@ -221,6 +226,7 @@ unlock:
}
void pa_memtrap_install(void) {
+#ifdef HAVE_SIGACTION
struct sigaction sa;
allocate_aupdate();
@@ -230,4 +236,5 @@ void pa_memtrap_install(void) {
sa.sa_flags = SA_RESTART|SA_SIGINFO;
pa_assert_se(sigaction(SIGBUS, &sa, NULL) == 0);
+#endif
}
diff --git a/src/pulsecore/mutex-win32.c b/src/pulsecore/mutex-win32.c
index 3a910b03..f4652a90 100644
--- a/src/pulsecore/mutex-win32.c
+++ b/src/pulsecore/mutex-win32.c
@@ -91,7 +91,7 @@ void pa_cond_signal(pa_cond *c, int broadcast) {
return;
if (broadcast)
- SetEvent(pa_hashmap_get_first(c->wait_events));
+ SetEvent(pa_hashmap_first(c->wait_events));
else {
void *iter;
const void *key;
@@ -131,3 +131,26 @@ int pa_cond_wait(pa_cond *c, pa_mutex *m) {
return 0;
}
+
+/* This is a copy of the function in mutex-posix.c */
+pa_mutex* pa_static_mutex_get(pa_static_mutex *s, pa_bool_t recursive, pa_bool_t inherit_priority) {
+ pa_mutex *m;
+
+ pa_assert(s);
+
+ /* First, check if already initialized and short cut */
+ if ((m = pa_atomic_ptr_load(&s->ptr)))
+ return m;
+
+ /* OK, not initialized, so let's allocate, and fill in */
+ m = pa_mutex_new(recursive, inherit_priority);
+ if ((pa_atomic_ptr_cmpxchg(&s->ptr, NULL, m)))
+ return m;
+
+ pa_mutex_free(m);
+
+ /* Him, filling in failed, so someone else must have filled in
+ * already */
+ pa_assert_se(m = pa_atomic_ptr_load(&s->ptr));
+ return m;
+}
diff --git a/src/pulsecore/parseaddr.c b/src/pulsecore/parseaddr.c
index 44cd9a05..99fdcbf4 100644
--- a/src/pulsecore/parseaddr.c
+++ b/src/pulsecore/parseaddr.c
@@ -25,14 +25,17 @@
#include <string.h>
#include <stdlib.h>
+
+#ifdef HAVE_ARPA_INET_H
#include <arpa/inet.h>
-#include <sys/socket.h>
+#endif
#include <pulse/xmalloc.h>
#include <pulse/util.h>
#include <pulsecore/core-util.h>
#include <pulsecore/macro.h>
+#include <pulsecore/inet_pton.h>
#include "parseaddr.h"
diff --git a/src/pulsecore/pipe.c b/src/pulsecore/pipe.c
index c21e4b1f..f873ef6b 100644
--- a/src/pulsecore/pipe.c
+++ b/src/pulsecore/pipe.c
@@ -29,11 +29,8 @@
#include <sys/types.h>
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
-
-#include "winsock.h"
+#include <pulsecore/socket.h>
+#include <pulsecore/core-util.h>
#include "pipe.h"
diff --git a/src/pulsecore/poll.c b/src/pulsecore/poll.c
index b98fb169..b993c478 100644
--- a/src/pulsecore/poll.c
+++ b/src/pulsecore/poll.c
@@ -45,8 +45,7 @@
#include <sys/select.h>
#endif
-#include "winsock.h"
-
+#include <pulsecore/socket.h>
#include <pulsecore/core-util.h>
#include <pulse/util.h>
@@ -187,11 +186,11 @@ int pa_poll (struct pollfd *fds, unsigned long int nfds, int timeout) {
* connected socket, a server socket, or something else using a
* 0-byte recv, and use ioctl(2) to detect POLLHUP. */
r = recv(f->fd, NULL, 0, MSG_PEEK);
- if (r == 0 || (r < 0 && errno == ENOTSOCK))
- ioctl(f->fd, FIONREAD, &r);
+ if (r == 0 || (r < 0 && errno == ENOTSOCK))
+ ioctl(f->fd, FIONREAD, &r);
- if (r == 0)
- f->revents |= POLLHUP;
+ if (r == 0)
+ f->revents |= POLLHUP;
#else /* !OS_IS_DARWIN */
if (recv (f->fd, data, 64, MSG_PEEK) == -1) {
if (errno == ESHUTDOWN || errno == ECONNRESET ||
diff --git a/src/pulsecore/proplist-util.c b/src/pulsecore/proplist-util.c
index 23864bcb..642c498c 100644
--- a/src/pulsecore/proplist-util.c
+++ b/src/pulsecore/proplist-util.c
@@ -25,7 +25,7 @@
#include <string.h>
#include <locale.h>
-#include <dlfcn.h>
+#include <libintl.h>
#ifdef __APPLE__
#include <crt_externs.h>
diff --git a/src/pulsecore/pstream.c b/src/pulsecore/pstream.c
index 3e0bfa3b..369e22ca 100644
--- a/src/pulsecore/pstream.c
+++ b/src/pulsecore/pstream.c
@@ -28,9 +28,6 @@
#include <stdlib.h>
#include <unistd.h>
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
#ifdef HAVE_SYS_UN_H
#include <sys/un.h>
#endif
@@ -38,10 +35,9 @@
#include <netinet/in.h>
#endif
-
#include <pulse/xmalloc.h>
-#include <pulsecore/winsock.h>
+#include <pulsecore/socket.h>
#include <pulsecore/queue.h>
#include <pulsecore/log.h>
#include <pulsecore/core-scache.h>
diff --git a/src/pulsecore/random.c b/src/pulsecore/random.c
index 3d159bf2..bdbc1437 100644
--- a/src/pulsecore/random.c
+++ b/src/pulsecore/random.c
@@ -31,6 +31,11 @@
#include <stdlib.h>
#include <time.h>
+#ifdef HAVE_WINDOWS_H
+#include <windows.h>
+#include <wincrypt.h>
+#endif
+
#include <pulsecore/core-util.h>
#include <pulsecore/log.h>
#include <pulsecore/macro.h>
@@ -43,10 +48,20 @@ static const char * const devices[] = { "/dev/urandom", "/dev/random", NULL };
static int random_proper(void *ret_data, size_t length) {
#ifdef OS_IS_WIN32
+ int ret = -1;
+
pa_assert(ret_data);
pa_assert(length > 0);
- return -1;
+ HCRYPTPROV hCryptProv = NULL;
+
+ if (CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) {
+ if(CryptGenRandom(hCryptProv, length, ret_data))
+ ret = 0;
+ CryptReleaseContext(hCryptProv, 0);
+ }
+
+ return ret;
#else /* OS_IS_WIN32 */
diff --git a/src/pulsecore/rtpoll.c b/src/pulsecore/rtpoll.c
index 2ef78736..98d7d625 100644
--- a/src/pulsecore/rtpoll.c
+++ b/src/pulsecore/rtpoll.c
@@ -40,7 +40,6 @@
#include <pulsecore/llist.h>
#include <pulsecore/flist.h>
#include <pulsecore/core-util.h>
-#include <pulsecore/winsock.h>
#include <pulsecore/ratelimit.h>
#include <pulse/rtclock.h>
diff --git a/src/pulsecore/socket-client.c b/src/pulsecore/socket-client.c
index 7c449bee..ae7abc9e 100644
--- a/src/pulsecore/socket-client.c
+++ b/src/pulsecore/socket-client.c
@@ -32,9 +32,6 @@
#include <string.h>
#include <stdlib.h>
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
#ifdef HAVE_SYS_UN_H
#include <sys/un.h>
#endif
@@ -56,9 +53,9 @@
#include <pulse/timeval.h>
#include <pulse/xmalloc.h>
-#include <pulsecore/winsock.h>
-#include <pulsecore/core-error.h>
+#include <pulsecore/socket.h>
#include <pulsecore/socket-util.h>
+#include <pulsecore/core-error.h>
#include <pulsecore/core-rtclock.h>
#include <pulsecore/core-util.h>
#include <pulsecore/socket-util.h>
@@ -525,7 +522,7 @@ pa_socket_client* pa_socket_client_new_string(pa_mainloop_api *m, pa_bool_t use_
if (!host)
goto finish;
- pa_zero(sa);
+ pa_zero(s);
s.sin_family = AF_INET;
memcpy(&s.sin_addr, host->h_addr, sizeof(struct in_addr));
s.sin_port = htons(a.port);
diff --git a/src/pulsecore/socket-server.c b/src/pulsecore/socket-server.c
index 3b7c6973..e45ded04 100644
--- a/src/pulsecore/socket-server.c
+++ b/src/pulsecore/socket-server.c
@@ -32,9 +32,6 @@
#include <unistd.h>
#include <sys/stat.h>
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
#ifdef HAVE_SYS_UN_H
#include <sys/un.h>
#ifndef SUN_LEN
@@ -54,18 +51,16 @@
#endif
#ifndef HAVE_INET_NTOP
-#include "inet_ntop.h"
+#include <pulsecore/inet_ntop.h>
#endif
-
#ifndef HAVE_INET_PTON
-#include "inet_pton.h"
+#include <pulsecore/inet_pton.h>
#endif
-#include "winsock.h"
-
#include <pulse/xmalloc.h>
#include <pulse/util.h>
+#include <pulsecore/socket.h>
#include <pulsecore/socket-util.h>
#include <pulsecore/core-util.h>
#include <pulsecore/log.h>
diff --git a/src/pulsecore/socket-util.c b/src/pulsecore/socket-util.c
index 2cc9882a..0b16e0f9 100644
--- a/src/pulsecore/socket-util.c
+++ b/src/pulsecore/socket-util.c
@@ -36,9 +36,6 @@
#include <unistd.h>
#include <sys/stat.h>
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
#ifdef HAVE_SYS_UN_H
#include <sys/un.h>
#endif
@@ -62,17 +59,16 @@
#endif
#ifndef HAVE_INET_NTOP
-#include "inet_ntop.h"
+#include <pulsecore/inet_ntop.h>
#endif
-#include "winsock.h"
-
#include <pulse/xmalloc.h>
#include <pulsecore/core-error.h>
#include <pulsecore/core-util.h>
#include <pulsecore/log.h>
#include <pulsecore/macro.h>
+#include <pulsecore/socket.h>
#include "socket-util.h"
diff --git a/src/pulsecore/socket-util.h b/src/pulsecore/socket-util.h
index f6d16376..154afd4a 100644
--- a/src/pulsecore/socket-util.h
+++ b/src/pulsecore/socket-util.h
@@ -24,8 +24,8 @@
***/
#include <sys/types.h>
-#include <sys/socket.h>
+#include <pulsecore/socket.h>
#include <pulsecore/macro.h>
void pa_socket_peer_to_string(int fd, char *c, size_t l);
diff --git a/src/pulsecore/winsock.h b/src/pulsecore/socket.h
index 0352bf4d..0d38bee6 100644
--- a/src/pulsecore/winsock.h
+++ b/src/pulsecore/socket.h
@@ -1,5 +1,9 @@
-#ifndef foowinsockhfoo
-#define foowinsockhfoo
+#ifndef foopulsecoresockethfoo
+#define foopulsecoresockethfoo
+
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
#ifdef HAVE_WINSOCK2_H
#include <winsock2.h>
@@ -14,6 +18,7 @@
#define ECONNREFUSED WSAECONNREFUSED
#define EHOSTUNREACH WSAEHOSTUNREACH
#define EWOULDBLOCK WSAEWOULDBLOCK
+#define EADDRINUSE WSAEADDRINUSE
typedef long suseconds_t;
diff --git a/src/pulsecore/start-child.c b/src/pulsecore/start-child.c
index 4a70aea1..fd1baebb 100644
--- a/src/pulsecore/start-child.c
+++ b/src/pulsecore/start-child.c
@@ -40,6 +40,7 @@
#include <pulsecore/core-util.h>
#include <pulsecore/core-error.h>
+#include <pulsecore/pipe.h>
#include "start-child.h"
@@ -47,6 +48,7 @@ int pa_start_child_for_read(const char *name, const char *argv1, pid_t *pid) {
pid_t child;
int pipe_fds[2] = { -1, -1 };
+#ifdef HAVE_FORK
if (pipe(pipe_fds) < 0) {
pa_log("pipe() failed: %s", pa_cstrerror(errno));
goto fail;
@@ -104,6 +106,7 @@ int pa_start_child_for_read(const char *name, const char *argv1, pid_t *pid) {
execl(name, name, argv1, NULL);
_exit(1);
}
+#endif
fail:
pa_close_pipe(pipe_fds);
diff --git a/src/pulsecore/tagstruct.c b/src/pulsecore/tagstruct.c
index 330b7596..804b9f90 100644
--- a/src/pulsecore/tagstruct.c
+++ b/src/pulsecore/tagstruct.c
@@ -35,7 +35,7 @@
#include <pulse/xmalloc.h>
-#include <pulsecore/winsock.h>
+#include <pulsecore/socket.h>
#include <pulsecore/macro.h>
#include "tagstruct.h"
diff --git a/src/pulsecore/tagstruct.h b/src/pulsecore/tagstruct.h
index 1a99e924..b6553ada 100644
--- a/src/pulsecore/tagstruct.h
+++ b/src/pulsecore/tagstruct.h
@@ -25,7 +25,6 @@
#include <inttypes.h>
#include <sys/types.h>
#include <sys/time.h>
-#include <time.h>
#include <pulse/sample.h>
#include <pulse/channelmap.h>
diff --git a/src/pulsecore/thread-mq.h b/src/pulsecore/thread-mq.h
index 96839d25..a1f4b3fe 100644
--- a/src/pulsecore/thread-mq.h
+++ b/src/pulsecore/thread-mq.h
@@ -27,7 +27,7 @@
#include <pulsecore/rtpoll.h>
/* Two way communication between a thread and a mainloop. Before the
- * thread is started a pa_pthread_mq should be initialized and than
+ * thread is started a pa_thread_mq should be initialized and than
* attached to the thread using pa_thread_mq_install(). */
typedef struct pa_thread_mq {
diff --git a/src/pulsecore/thread-win32.c b/src/pulsecore/thread-win32.c
index 0a1baa54..7d458b97 100644
--- a/src/pulsecore/thread-win32.c
+++ b/src/pulsecore/thread-win32.c
@@ -71,8 +71,9 @@ static DWORD WINAPI internal_thread_func(LPVOID param) {
return 0;
}
-pa_thread* pa_thread_new(pa_thread_func_t thread_func, void *userdata) {
+pa_thread* pa_thread_new(const char *name, pa_thread_func_t thread_func, void *userdata) {
pa_thread *t;
+ DWORD thread_id;
assert(thread_func);
@@ -80,7 +81,7 @@ pa_thread* pa_thread_new(pa_thread_func_t thread_func, void *userdata) {
t->thread_func = thread_func;
t->userdata = userdata;
- t->thread = CreateThread(NULL, 0, internal_thread_func, t, 0, NULL);
+ t->thread = CreateThread(NULL, 0, internal_thread_func, t, 0, &thread_id);
if (!t->thread) {
pa_xfree(t);
diff --git a/src/pulsecore/thread.h b/src/pulsecore/thread.h
index aea02764..79b61ae0 100644
--- a/src/pulsecore/thread.h
+++ b/src/pulsecore/thread.h
@@ -92,7 +92,7 @@ void *pa_tls_set(pa_tls *t, void *userdata);
} \
struct __stupid_useless_struct_to_allow_trailing_semicolon
-#ifdef SUPPORT_TLS___THREAD
+#if defined(SUPPORT_TLS___THREAD) && !defined(OS_IS_WIN32)
/* An optimized version of the above that requires no dynamic
* allocation if the compiler supports __thread */
#define PA_STATIC_TLS_DECLARE_NO_FREE(name) \
diff --git a/src/tests/asyncq-test.c b/src/tests/asyncq-test.c
index 538bbb17..eae8cce9 100644
--- a/src/tests/asyncq-test.c
+++ b/src/tests/asyncq-test.c
@@ -51,7 +51,7 @@ static void consumer(void *_q) {
void *p;
int i;
- sleep(1);
+ pa_msleep(1000);
for (i = 0;; i++) {
p = pa_asyncq_pop(q, TRUE);
diff --git a/src/tests/ipacl-test.c b/src/tests/ipacl-test.c
index 57b70685..58663468 100644
--- a/src/tests/ipacl-test.c
+++ b/src/tests/ipacl-test.c
@@ -8,9 +8,6 @@
#include <assert.h>
#include <string.h>
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
@@ -24,10 +21,10 @@
#include <arpa/inet.h>
#endif
-#include "../pulsecore/winsock.h"
-#include "../pulsecore/macro.h"
-
+#include <pulsecore/socket.h>
+#include <pulsecore/macro.h>
#include <pulsecore/ipacl.h>
+#include <pulsecore/inet_pton.h>
int main(int argc, char *argv[]) {
struct sockaddr_in sa;
diff --git a/src/tests/rtstutter.c b/src/tests/rtstutter.c
index c93fee93..9ef835c3 100644
--- a/src/tests/rtstutter.c
+++ b/src/tests/rtstutter.c
@@ -26,78 +26,69 @@
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
-#include <sched.h>
#include <inttypes.h>
#include <string.h>
+
+#ifdef HAVE_PTHREAD
#include <pthread.h>
+#endif
+#include <pulse/util.h>
#include <pulse/timeval.h>
#include <pulse/gccmacro.h>
#include <pulsecore/log.h>
#include <pulsecore/macro.h>
+#include <pulsecore/thread.h>
#include <pulsecore/core-util.h>
+#include <pulsecore/core-rtclock.h>
static int msec_lower, msec_upper;
-static void* work(void *p) PA_GCC_NORETURN;
+static void work(void *p) PA_GCC_NORETURN;
-static void* work(void *p) {
-#ifdef HAVE_PTHREAD_SETAFFINITY_NP
- cpu_set_t mask;
-#endif
- struct sched_param param;
+static void work(void *p) {
pa_log_notice("CPU%i: Created thread.", PA_PTR_TO_UINT(p));
- memset(&param, 0, sizeof(param));
- param.sched_priority = 12;
- pa_assert_se(pthread_setschedparam(pthread_self(), SCHED_FIFO, &param) == 0);
+ pa_make_realtime(12);
#ifdef HAVE_PTHREAD_SETAFFINITY_NP
+{
+ cpu_set_t mask;
+
CPU_ZERO(&mask);
CPU_SET((size_t) PA_PTR_TO_UINT(p), &mask);
pa_assert_se(pthread_setaffinity_np(pthread_self(), sizeof(mask), &mask) == 0);
+}
#endif
for (;;) {
- struct timespec now, end;
- uint64_t nsec;
+ struct timeval now, end;
+ uint64_t usec;
pa_log_notice("CPU%i: Sleeping for 1s", PA_PTR_TO_UINT(p));
- sleep(1);
-
-#ifdef CLOCK_REALTIME
- pa_assert_se(clock_gettime(CLOCK_REALTIME, &end) == 0);
-#endif
-
- nsec =
- (uint64_t) ((((double) rand())*(double)(msec_upper-msec_lower)*PA_NSEC_PER_MSEC)/RAND_MAX) +
- (uint64_t) ((uint64_t) msec_lower*PA_NSEC_PER_MSEC);
+ pa_msleep(1000);
- pa_log_notice("CPU%i: Freezing for %ims", PA_PTR_TO_UINT(p), (int) (nsec/PA_NSEC_PER_MSEC));
+ usec =
+ (uint64_t) ((((double) rand())*(double)(msec_upper-msec_lower)*PA_USEC_PER_MSEC)/RAND_MAX) +
+ (uint64_t) ((uint64_t) msec_lower*PA_USEC_PER_MSEC);
- end.tv_sec += (time_t) (nsec / PA_NSEC_PER_SEC);
- end.tv_nsec += (long int) (nsec % PA_NSEC_PER_SEC);
+ pa_log_notice("CPU%i: Freezing for %ims", PA_PTR_TO_UINT(p), (int) (usec/PA_USEC_PER_MSEC));
- while ((pa_usec_t) end.tv_nsec > PA_NSEC_PER_SEC) {
- end.tv_sec++;
- end.tv_nsec -= (long int) PA_NSEC_PER_SEC;
- }
+ pa_rtclock_get(&end);
+ pa_timeval_add(&end, usec);
do {
-#ifdef CLOCK_REALTIME
- pa_assert_se(clock_gettime(CLOCK_REALTIME, &now) == 0);
-#endif
- } while (now.tv_sec < end.tv_sec ||
- (now.tv_sec == end.tv_sec && now.tv_nsec < end.tv_nsec));
+ pa_rtclock_get(&now);
+ } while (pa_timeval_cmp(&now, &end) < 0);
}
}
int main(int argc, char*argv[]) {
unsigned n;
- pa_log_set_level(PA_LOG_DEBUG);
+ pa_log_set_level(PA_LOG_INFO);
srand((unsigned) time(NULL));
@@ -118,8 +109,7 @@ int main(int argc, char*argv[]) {
pa_log_notice("Creating random latencies in the range of %ims to %ims.", msec_lower, msec_upper);
for (n = 1; n < pa_ncpus(); n++) {
- pthread_t t;
- pa_assert_se(pthread_create(&t, NULL, work, PA_UINT_TO_PTR(n)) == 0);
+ pa_assert_se(pa_thread_new("rtstutter", work, PA_UINT_TO_PTR(n)));
}
work(PA_INT_TO_PTR(0));