Skip to content

Commit

Permalink
Merge pull request #104 from rikvanriel/master
Browse files Browse the repository at this point in the history
return pulseaudio errno exception on stream creation failure
  • Loading branch information
bastibe authored Aug 11, 2020
2 parents 7fda36c + 0ec0197 commit 878ad90
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions soundcard/pulseaudio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -652,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)
Expand Down
1 change: 1 addition & 0 deletions soundcard/pulseaudio.py.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 878ad90

Please sign in to comment.