From f252ddd5987e95528f7f8d2ad152eeae17a02316 Mon Sep 17 00:00:00 2001 From: Rik van Riel Date: Sat, 1 Aug 2020 13:14:01 -0400 Subject: [PATCH 1/2] Export pa_context_errno Make the pa_context_errno call available in SoundCard, so we can better debug what is going wrong with pulseaudio. Signed-off-by: Rik van Riel --- soundcard/pulseaudio.py | 1 + soundcard/pulseaudio.py.h | 1 + 2 files changed, 2 insertions(+) diff --git a/soundcard/pulseaudio.py b/soundcard/pulseaudio.py index 6ea8b19..b3284bd 100644 --- a/soundcard/pulseaudio.py +++ b/soundcard/pulseaudio.py @@ -237,6 +237,7 @@ def __exit__(self_, exc_type, exc_value, traceback): _pa_context_drain = _lock(_pa.pa_context_drain) _pa_context_disconnect = _lock(_pa.pa_context_disconnect) _pa_context_unref = _lock(_pa.pa_context_unref) + _pa_context_errno = _lock(_pa.pa_context_errno) _pa_operation_get_state = _lock(_pa.pa_operation_get_state) _pa_operation_unref = _lock(_pa.pa_operation_unref) _pa_stream_get_state = _lock(_pa.pa_stream_get_state) diff --git a/soundcard/pulseaudio.py.h b/soundcard/pulseaudio.py.h index ca1d93b..7b1facc 100644 --- a/soundcard/pulseaudio.py.h +++ b/soundcard/pulseaudio.py.h @@ -159,6 +159,7 @@ typedef enum pa_context_flags {PA_CONTEXT_NOFLAGS = 0} pa_context_flags_t; typedef struct pa_spawn_api pa_spawn_api; int pa_context_connect(pa_context *c, const char *server, pa_context_flags_t flags, const pa_spawn_api *api); void pa_context_disconnect(pa_context *c); +int pa_context_errno(const pa_context *c); typedef enum pa_context_state { PA_CONTEXT_UNCONNECTED, PA_CONTEXT_CONNECTING, From 0ec01973ecca0666ed257c0343c586911e3ef7b2 Mon Sep 17 00:00:00 2001 From: Rik van Riel Date: Sat, 1 Aug 2020 17:02:26 -0400 Subject: [PATCH 2/2] Throw exception when pa_stream_new fails Throw an exception with the pulseaudio errno when pa_stream_new fails to set up a stream. This could be handled by the application using SoundCard. Signed-off-by: Rik van Riel --- soundcard/pulseaudio.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/soundcard/pulseaudio.py b/soundcard/pulseaudio.py index b3284bd..9a154fc 100644 --- a/soundcard/pulseaudio.py +++ b/soundcard/pulseaudio.py @@ -653,6 +653,9 @@ def __enter__(self): raise RuntimeError('invalid channel map') self.stream = _pulse._pa_stream_new(_pulse.context, self._name.encode(), samplespec, channelmap) + if not self.stream: + errno = _pulse._pa_context_errno(_pulse.context) + raise RuntimeError("stream creation failed with error ", errno) bufattr = _ffi.new("pa_buffer_attr*") bufattr.maxlength = 2**32-1 # max buffer length numchannels = self.channels if isinstance(self.channels, int) else len(self.channels)