diff --git a/soundio/soundio.h b/soundio/soundio.h index 7cfd6ad..4b648f6 100644 --- a/soundio/soundio.h +++ b/soundio/soundio.h @@ -359,7 +359,7 @@ struct SoundIo { /// * #SoundIoErrorSystemResources /// * #SoundIoErrorOpeningDevice - unexpected problem accessing device /// information - void (*on_backend_disconnect)(struct SoundIo *, int err); + void (*on_backend_disconnect)(struct SoundIo *, enum SoundIoError err); /// Optional callback. Called from an unknown thread that you should not use /// to call any soundio functions. You may use this to signal a condition /// variable to wake up. Called when ::soundio_wait_events would be woken up. @@ -502,7 +502,7 @@ struct SoundIoDevice { /// Possible errors: /// * #SoundIoErrorOpeningDevice /// * #SoundIoErrorNoMem - int probe_error; + enum SoundIoError probe_error; }; /// The size of this struct is not part of the API or ABI. @@ -580,7 +580,7 @@ struct SoundIoOutStream { /// If you do not supply error_callback, the default callback will print /// a message to stderr and then call `abort`. /// This is called from the SoundIoOutStream::write_callback thread context. - void (*error_callback)(struct SoundIoOutStream *, int err); + void (*error_callback)(struct SoundIoOutStream *, enum SoundIoError err); /// Optional: Name of the stream. Defaults to "SoundIoOutStream" /// PulseAudio uses this for the stream name. @@ -604,7 +604,7 @@ struct SoundIoOutStream { /// If setting the channel layout fails for some reason, this field is set /// to an error code. Possible error codes are: /// * #SoundIoErrorIncompatibleDevice - int layout_error; + enum SoundIoError layout_error; }; /// The size of this struct is not part of the API or ABI. @@ -664,7 +664,7 @@ struct SoundIoInStream { /// If you do not supply `error_callback`, the default callback will print /// a message to stderr and then abort(). /// This is called from the SoundIoInStream::read_callback thread context. - void (*error_callback)(struct SoundIoInStream *, int err); + void (*error_callback)(struct SoundIoInStream *, enum SoundIoError err); /// Optional: Name of the stream. Defaults to "SoundIoInStream"; /// PulseAudio uses this for the stream name. @@ -686,7 +686,7 @@ struct SoundIoInStream { /// If setting the channel layout fails for some reason, this field is set /// to an error code. Possible error codes are: #SoundIoErrorIncompatibleDevice - int layout_error; + enum SoundIoError layout_error; }; /// See also ::soundio_version_major, ::soundio_version_minor, ::soundio_version_patch @@ -713,7 +713,7 @@ SOUNDIO_EXPORT void soundio_destroy(struct SoundIo *soundio); /// * #SoundIoErrorSystemResources /// * #SoundIoErrorNoSuchClient - when JACK returns `JackNoSuchClient` /// See also ::soundio_disconnect -SOUNDIO_EXPORT int soundio_connect(struct SoundIo *soundio); +SOUNDIO_EXPORT enum SoundIoError soundio_connect(struct SoundIo *soundio); /// Instead of calling ::soundio_connect you may call this function to try a /// specific backend. /// Possible errors: @@ -725,11 +725,11 @@ SOUNDIO_EXPORT int soundio_connect(struct SoundIo *soundio); /// * #SoundIoErrorInitAudioBackend - requested `backend` is not active /// * #SoundIoErrorBackendDisconnected - backend disconnected while connecting /// See also ::soundio_disconnect -SOUNDIO_EXPORT int soundio_connect_backend(struct SoundIo *soundio, enum SoundIoBackend backend); +SOUNDIO_EXPORT enum SoundIoError soundio_connect_backend(struct SoundIo *soundio, enum SoundIoBackend backend); SOUNDIO_EXPORT void soundio_disconnect(struct SoundIo *soundio); /// Get a string representation of a #SoundIoError -SOUNDIO_EXPORT const char *soundio_strerror(int error); +SOUNDIO_EXPORT const char *soundio_strerror(enum SoundIoError error); /// Get a string representation of a #SoundIoBackend SOUNDIO_EXPORT const char *soundio_backend_name(enum SoundIoBackend backend); @@ -962,7 +962,7 @@ SOUNDIO_EXPORT void soundio_outstream_destroy(struct SoundIoOutStream *outstream /// greater than the number of channels the backend can handle. /// * #SoundIoErrorIncompatibleDevice - stream parameters requested are not /// compatible with the chosen device. -SOUNDIO_EXPORT int soundio_outstream_open(struct SoundIoOutStream *outstream); +SOUNDIO_EXPORT enum SoundIoError soundio_outstream_open(struct SoundIoOutStream *outstream); /// After you call this function, SoundIoOutStream::write_callback will be called. /// @@ -973,7 +973,7 @@ SOUNDIO_EXPORT int soundio_outstream_open(struct SoundIoOutStream *outstream); /// * #SoundIoErrorNoMem /// * #SoundIoErrorSystemResources /// * #SoundIoErrorBackendDisconnected -SOUNDIO_EXPORT int soundio_outstream_start(struct SoundIoOutStream *outstream); +SOUNDIO_EXPORT enum SoundIoError soundio_outstream_start(struct SoundIoOutStream *outstream); /// Call this function when you are ready to begin writing to the device buffer. /// * `outstream` - (in) The output stream you want to write to. @@ -1005,7 +1005,7 @@ SOUNDIO_EXPORT int soundio_outstream_start(struct SoundIoOutStream *outstream); /// * #SoundIoErrorIncompatibleDevice - in rare cases it might just now /// be discovered that the device uses non-byte-aligned access, in which /// case this error code is returned. -SOUNDIO_EXPORT int soundio_outstream_begin_write(struct SoundIoOutStream *outstream, +SOUNDIO_EXPORT enum SoundIoError soundio_outstream_begin_write(struct SoundIoOutStream *outstream, struct SoundIoChannelArea **areas, int *frame_count); /// Commits the write that you began with ::soundio_outstream_begin_write. @@ -1017,7 +1017,7 @@ SOUNDIO_EXPORT int soundio_outstream_begin_write(struct SoundIoOutStream *outstr /// also get a SoundIoOutStream::underflow_callback, and you might not get /// this error code when an underflow occurs. Unlike #SoundIoErrorStreaming, /// the outstream is still in a valid state and streaming can continue. -SOUNDIO_EXPORT int soundio_outstream_end_write(struct SoundIoOutStream *outstream); +SOUNDIO_EXPORT enum SoundIoError soundio_outstream_end_write(struct SoundIoOutStream *outstream); /// Clears the output stream buffer. /// This function can be called from any thread. @@ -1032,7 +1032,7 @@ SOUNDIO_EXPORT int soundio_outstream_end_write(struct SoundIoOutStream *outstrea /// * #SoundIoErrorStreaming /// * #SoundIoErrorIncompatibleBackend /// * #SoundIoErrorIncompatibleDevice -SOUNDIO_EXPORT int soundio_outstream_clear_buffer(struct SoundIoOutStream *outstream); +SOUNDIO_EXPORT enum SoundIoError soundio_outstream_clear_buffer(struct SoundIoOutStream *outstream); /// If the underlying backend and device support pausing, this pauses the /// stream. SoundIoOutStream::write_callback may be called a few more times if @@ -1053,7 +1053,7 @@ SOUNDIO_EXPORT int soundio_outstream_clear_buffer(struct SoundIoOutStream *outst /// * #SoundIoErrorIncompatibleBackend - backend does not support /// pausing/unpausing. /// * #SoundIoErrorInvalid - outstream not opened and started -SOUNDIO_EXPORT int soundio_outstream_pause(struct SoundIoOutStream *outstream, bool pause); +SOUNDIO_EXPORT enum SoundIoError soundio_outstream_pause(struct SoundIoOutStream *outstream, bool pause); /// Obtain the total number of seconds that the next frame written after the /// last frame written with ::soundio_outstream_end_write will take to become @@ -1066,7 +1066,7 @@ SOUNDIO_EXPORT int soundio_outstream_pause(struct SoundIoOutStream *outstream, b /// /// Possible errors: /// * #SoundIoErrorStreaming -SOUNDIO_EXPORT int soundio_outstream_get_latency(struct SoundIoOutStream *outstream, +SOUNDIO_EXPORT enum SoundIoError soundio_outstream_get_latency(struct SoundIoOutStream *outstream, double *out_latency); @@ -1098,7 +1098,7 @@ SOUNDIO_EXPORT void soundio_instream_destroy(struct SoundIoInStream *instream); /// * #SoundIoErrorNoSuchClient /// * #SoundIoErrorIncompatibleBackend /// * #SoundIoErrorIncompatibleDevice -SOUNDIO_EXPORT int soundio_instream_open(struct SoundIoInStream *instream); +SOUNDIO_EXPORT enum SoundIoError soundio_instream_open(struct SoundIoInStream *instream); /// After you call this function, SoundIoInStream::read_callback will be called. /// @@ -1107,7 +1107,7 @@ SOUNDIO_EXPORT int soundio_instream_open(struct SoundIoInStream *instream); /// * #SoundIoErrorStreaming /// * #SoundIoErrorOpeningDevice /// * #SoundIoErrorSystemResources -SOUNDIO_EXPORT int soundio_instream_start(struct SoundIoInStream *instream); +SOUNDIO_EXPORT enum SoundIoError soundio_instream_start(struct SoundIoInStream *instream); /// Call this function when you are ready to begin reading from the device /// buffer. @@ -1138,7 +1138,7 @@ SOUNDIO_EXPORT int soundio_instream_start(struct SoundIoInStream *instream); /// * #SoundIoErrorIncompatibleDevice - in rare cases it might just now /// be discovered that the device uses non-byte-aligned access, in which /// case this error code is returned. -SOUNDIO_EXPORT int soundio_instream_begin_read(struct SoundIoInStream *instream, +SOUNDIO_EXPORT enum SoundIoError soundio_instream_begin_read(struct SoundIoInStream *instream, struct SoundIoChannelArea **areas, int *frame_count); /// This will drop all of the frames from when you called /// ::soundio_instream_begin_read. @@ -1148,7 +1148,7 @@ SOUNDIO_EXPORT int soundio_instream_begin_read(struct SoundIoInStream *instream, /// /// Possible errors: /// * #SoundIoErrorStreaming -SOUNDIO_EXPORT int soundio_instream_end_read(struct SoundIoInStream *instream); +SOUNDIO_EXPORT enum SoundIoError soundio_instream_end_read(struct SoundIoInStream *instream); /// If the underyling device supports pausing, this pauses the stream and /// prevents SoundIoInStream::read_callback from being called. Otherwise this returns @@ -1161,7 +1161,7 @@ SOUNDIO_EXPORT int soundio_instream_end_read(struct SoundIoInStream *instream); /// * #SoundIoErrorBackendDisconnected /// * #SoundIoErrorStreaming /// * #SoundIoErrorIncompatibleDevice - device does not support pausing/unpausing -SOUNDIO_EXPORT int soundio_instream_pause(struct SoundIoInStream *instream, bool pause); +SOUNDIO_EXPORT enum SoundIoError soundio_instream_pause(struct SoundIoInStream *instream, bool pause); /// Obtain the number of seconds that the next frame of sound being /// captured will take to arrive in the buffer, plus the amount of time that is @@ -1171,7 +1171,7 @@ SOUNDIO_EXPORT int soundio_instream_pause(struct SoundIoInStream *instream, bool /// /// Possible errors: /// * #SoundIoErrorStreaming -SOUNDIO_EXPORT int soundio_instream_get_latency(struct SoundIoInStream *instream, +SOUNDIO_EXPORT enum SoundIoError soundio_instream_get_latency(struct SoundIoInStream *instream, double *out_latency); diff --git a/src/alsa.c b/src/alsa.c index 81a2fda..78dc2b9 100644 --- a/src/alsa.c +++ b/src/alsa.c @@ -1276,7 +1276,7 @@ static void instream_thread_run(void *arg) { } } -static int outstream_open_alsa(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os) { +static enum SoundIoError outstream_open_alsa(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os) { struct SoundIoOutStreamAlsa *osa = &os->backend_data.alsa; struct SoundIoOutStream *outstream = &os->pub; struct SoundIoDevice *device = outstream->device; @@ -1439,13 +1439,13 @@ static int outstream_open_alsa(struct SoundIoPrivate *si, struct SoundIoOutStrea return 0; } -static int outstream_start_alsa(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os) { +static enum SoundIoError outstream_start_alsa(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os) { struct SoundIoOutStreamAlsa *osa = &os->backend_data.alsa; struct SoundIo *soundio = &si->pub; assert(!osa->thread); - int err; + enum SoundIoError err; SOUNDIO_ATOMIC_FLAG_TEST_AND_SET(osa->thread_exit_flag); if ((err = soundio_os_thread_create(outstream_thread_run, os, soundio->emit_rtprio_warning, &osa->thread))) return err; @@ -1453,7 +1453,7 @@ static int outstream_start_alsa(struct SoundIoPrivate *si, struct SoundIoOutStre return 0; } -static int outstream_begin_write_alsa(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os, +static enum SoundIoError outstream_begin_write_alsa(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os, struct SoundIoChannelArea **out_areas, int *frame_count) { *out_areas = NULL; @@ -1504,7 +1504,7 @@ static int outstream_begin_write_alsa(struct SoundIoPrivate *si, struct SoundIoO return 0; } -static int outstream_end_write_alsa(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os) { +static enum SoundIoError outstream_end_write_alsa(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os) { struct SoundIoOutStreamAlsa *osa = &os->backend_data.alsa; struct SoundIoOutStream *outstream = &os->pub; @@ -1531,7 +1531,7 @@ static int outstream_end_write_alsa(struct SoundIoPrivate *si, struct SoundIoOut return 0; } -static int outstream_clear_buffer_alsa(struct SoundIoPrivate *si, +static enum SoundIoError outstream_clear_buffer_alsa(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os) { struct SoundIoOutStreamAlsa *osa = &os->backend_data.alsa; @@ -1539,7 +1539,7 @@ static int outstream_clear_buffer_alsa(struct SoundIoPrivate *si, return 0; } -static int outstream_pause_alsa(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os, bool pause) { +static enum SoundIoError outstream_pause_alsa(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os, bool pause) { if (!si) return SoundIoErrorInvalid; @@ -1560,7 +1560,7 @@ static int outstream_pause_alsa(struct SoundIoPrivate *si, struct SoundIoOutStre return 0; } -static int outstream_get_latency_alsa(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os, +static enum SoundIoError outstream_get_latency_alsa(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os, double *out_latency) { struct SoundIoOutStream *outstream = &os->pub; @@ -1600,7 +1600,7 @@ static void instream_destroy_alsa(struct SoundIoPrivate *si, struct SoundIoInStr isa->sample_buffer = NULL; } -static int instream_open_alsa(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is) { +static enum SoundIoError instream_open_alsa(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is) { struct SoundIoInStreamAlsa *isa = &is->backend_data.alsa; struct SoundIoInStream *instream = &is->pub; struct SoundIoDevice *device = instream->device; @@ -1741,14 +1741,14 @@ static int instream_open_alsa(struct SoundIoPrivate *si, struct SoundIoInStreamP return 0; } -static int instream_start_alsa(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is) { +static enum SoundIoError instream_start_alsa(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is) { struct SoundIoInStreamAlsa *isa = &is->backend_data.alsa; struct SoundIo *soundio = &si->pub; assert(!isa->thread); SOUNDIO_ATOMIC_FLAG_TEST_AND_SET(isa->thread_exit_flag); - int err; + enum SoundIoError err; if ((err = soundio_os_thread_create(instream_thread_run, is, soundio->emit_rtprio_warning, &isa->thread))) { instream_destroy_alsa(si, is); return err; @@ -1757,7 +1757,7 @@ static int instream_start_alsa(struct SoundIoPrivate *si, struct SoundIoInStream return 0; } -static int instream_begin_read_alsa(struct SoundIoPrivate *si, +static enum SoundIoError instream_begin_read_alsa(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is, struct SoundIoChannelArea **out_areas, int *frame_count) { *out_areas = NULL; @@ -1822,7 +1822,7 @@ static int instream_begin_read_alsa(struct SoundIoPrivate *si, return 0; } -static int instream_end_read_alsa(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is) { +static enum SoundIoError instream_end_read_alsa(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is) { struct SoundIoInStreamAlsa *isa = &is->backend_data.alsa; if (isa->access == SND_PCM_ACCESS_RW_INTERLEAVED) { @@ -1841,7 +1841,7 @@ static int instream_end_read_alsa(struct SoundIoPrivate *si, struct SoundIoInStr return 0; } -static int instream_pause_alsa(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is, bool pause) { +static enum SoundIoError instream_pause_alsa(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is, bool pause) { struct SoundIoInStreamAlsa *isa = &is->backend_data.alsa; if (isa->is_paused == pause) @@ -1855,7 +1855,7 @@ static int instream_pause_alsa(struct SoundIoPrivate *si, struct SoundIoInStream return 0; } -static int instream_get_latency_alsa(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is, +static enum SoundIoError instream_get_latency_alsa(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is, double *out_latency) { struct SoundIoInStream *instream = &is->pub; @@ -1871,7 +1871,7 @@ static int instream_get_latency_alsa(struct SoundIoPrivate *si, struct SoundIoIn return 0; } -int soundio_alsa_init(struct SoundIoPrivate *si) { +enum SoundIoError soundio_alsa_init(struct SoundIoPrivate *si) { struct SoundIoAlsa *sia = &si->backend_data.alsa; int err; diff --git a/src/alsa.h b/src/alsa.h index e2b1764..6954141 100644 --- a/src/alsa.h +++ b/src/alsa.h @@ -16,7 +16,7 @@ #include struct SoundIoPrivate; -int soundio_alsa_init(struct SoundIoPrivate *si); +enum SoundIoError soundio_alsa_init(struct SoundIoPrivate *si); struct SoundIoDeviceAlsa { int make_the_struct_not_empty; }; diff --git a/src/coreaudio.c b/src/coreaudio.c index a483b53..8b32078 100644 --- a/src/coreaudio.c +++ b/src/coreaudio.c @@ -946,7 +946,7 @@ static int set_ca_desc(enum SoundIoFormat fmt, AudioStreamBasicDescription *desc return 0; } -static int outstream_open_ca(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os) { +static enum SoundIoError outstream_open_ca(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os) { struct SoundIoOutStreamCoreAudio *osca = &os->backend_data.coreaudio; struct SoundIoOutStream *outstream = &os->pub; struct SoundIoDevice *device = outstream->device; @@ -1046,7 +1046,7 @@ static int outstream_open_ca(struct SoundIoPrivate *si, struct SoundIoOutStreamP return 0; } -static int outstream_pause_ca(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os, bool pause) { +static enum SoundIoError outstream_pause_ca(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os, bool pause) { struct SoundIoOutStreamCoreAudio *osca = &os->backend_data.coreaudio; OSStatus os_err; if (pause) { @@ -1062,11 +1062,11 @@ static int outstream_pause_ca(struct SoundIoPrivate *si, struct SoundIoOutStream return 0; } -static int outstream_start_ca(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os) { +static enum SoundIoError outstream_start_ca(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os) { return outstream_pause_ca(si, os, false); } -static int outstream_begin_write_ca(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os, +static enum SoundIoError outstream_begin_write_ca(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os, struct SoundIoChannelArea **out_areas, int *frame_count) { struct SoundIoOutStream *outstream = &os->pub; @@ -1091,7 +1091,7 @@ static int outstream_begin_write_ca(struct SoundIoPrivate *si, struct SoundIoOut return 0; } -static int outstream_end_write_ca(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os) { +static enum SoundIoError outstream_end_write_ca(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os) { struct SoundIoOutStreamCoreAudio *osca = &os->backend_data.coreaudio; osca->buffer_index += 1; osca->frames_left -= osca->write_frame_count; @@ -1099,11 +1099,11 @@ static int outstream_end_write_ca(struct SoundIoPrivate *si, struct SoundIoOutSt return 0; } -static int outstream_clear_buffer_ca(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os) { +static enum SoundIoError outstream_clear_buffer_ca(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os) { return SoundIoErrorIncompatibleBackend; } -static int outstream_get_latency_ca(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os, +static enum SoundIoError outstream_get_latency_ca(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os, double *out_latency) { struct SoundIoOutStreamCoreAudio *osca = &os->backend_data.coreaudio; @@ -1188,7 +1188,7 @@ static OSStatus read_callback_ca(void *userdata, AudioUnitRenderActionFlags *io_ return noErr; } -static int instream_open_ca(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is) { +static enum SoundIoError instream_open_ca(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is) { struct SoundIoInStreamCoreAudio *isca = &is->backend_data.coreaudio; struct SoundIoInStream *instream = &is->pub; struct SoundIoDevice *device = instream->device; @@ -1332,7 +1332,7 @@ static int instream_open_ca(struct SoundIoPrivate *si, struct SoundIoInStreamPri return 0; } -static int instream_pause_ca(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is, bool pause) { +static enum SoundIoError instream_pause_ca(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is, bool pause) { struct SoundIoInStreamCoreAudio *isca = &is->backend_data.coreaudio; OSStatus os_err; if (pause) { @@ -1348,11 +1348,11 @@ static int instream_pause_ca(struct SoundIoPrivate *si, struct SoundIoInStreamPr return 0; } -static int instream_start_ca(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is) { +static enum SoundIoError instream_start_ca(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is) { return instream_pause_ca(si, is, false); } -static int instream_begin_read_ca(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is, +static enum SoundIoError instream_begin_read_ca(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is, struct SoundIoChannelArea **out_areas, int *frame_count) { struct SoundIoInStreamCoreAudio *isca = &is->backend_data.coreaudio; @@ -1365,13 +1365,13 @@ static int instream_begin_read_ca(struct SoundIoPrivate *si, struct SoundIoInStr return 0; } -static int instream_end_read_ca(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is) { +static enum SoundIoError instream_end_read_ca(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is) { struct SoundIoInStreamCoreAudio *isca = &is->backend_data.coreaudio; isca->frames_left = 0; return 0; } -static int instream_get_latency_ca(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is, +static enum SoundIoError instream_get_latency_ca(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is, double *out_latency) { struct SoundIoInStreamCoreAudio *isca = &is->backend_data.coreaudio; @@ -1380,7 +1380,7 @@ static int instream_get_latency_ca(struct SoundIoPrivate *si, struct SoundIoInSt } -int soundio_coreaudio_init(struct SoundIoPrivate *si) { +enum SoundIoError soundio_coreaudio_init(struct SoundIoPrivate *si) { struct SoundIoCoreAudio *sica = &si->backend_data.coreaudio; int err; diff --git a/src/coreaudio.h b/src/coreaudio.h index 784a71c..8b80f74 100644 --- a/src/coreaudio.h +++ b/src/coreaudio.h @@ -17,7 +17,7 @@ #include struct SoundIoPrivate; -int soundio_coreaudio_init(struct SoundIoPrivate *si); +enum SoundIoError soundio_coreaudio_init(struct SoundIoPrivate *si); struct SoundIoDeviceCoreAudio { AudioDeviceID device_id; diff --git a/src/dummy.c b/src/dummy.c index 5e0ff61..22aedd2 100644 --- a/src/dummy.c +++ b/src/dummy.c @@ -172,7 +172,7 @@ static void outstream_destroy_dummy(struct SoundIoPrivate *si, struct SoundIoOut soundio_ring_buffer_deinit(&osd->ring_buffer); } -static int outstream_open_dummy(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os) { +static enum SoundIoError outstream_open_dummy(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os) { struct SoundIoOutStreamDummy *osd = &os->backend_data.dummy; struct SoundIoOutStream *outstream = &os->pub; struct SoundIoDevice *device = outstream->device; @@ -187,7 +187,7 @@ static int outstream_open_dummy(struct SoundIoPrivate *si, struct SoundIoOutStre osd->period_duration = outstream->software_latency / 2.0; - int err; + enum SoundIoError err; int buffer_size = outstream->bytes_per_frame * outstream->sample_rate * outstream->software_latency; if ((err = soundio_ring_buffer_init(&osd->ring_buffer, buffer_size))) { outstream_destroy_dummy(si, os); @@ -206,13 +206,15 @@ static int outstream_open_dummy(struct SoundIoPrivate *si, struct SoundIoOutStre return 0; } -static int outstream_pause_dummy(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os, bool pause) { +static enum SoundIoError outstream_pause_dummy(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os, + bool pause) +{ struct SoundIoOutStreamDummy *osd = &os->backend_data.dummy; SOUNDIO_ATOMIC_STORE(osd->pause_requested, pause); - return 0; + return SoundIoErrorNone; } -static int outstream_start_dummy(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os) { +static enum SoundIoError outstream_start_dummy(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os) { struct SoundIoOutStreamDummy *osd = &os->backend_data.dummy; struct SoundIo *soundio = &si->pub; assert(!osd->thread); @@ -223,10 +225,10 @@ static int outstream_start_dummy(struct SoundIoPrivate *si, struct SoundIoOutStr { return err; } - return 0; + return SoundIoErrorNone; } -static int outstream_begin_write_dummy(struct SoundIoPrivate *si, +static enum SoundIoError outstream_begin_write_dummy(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os, struct SoundIoChannelArea **out_areas, int *frame_count) { struct SoundIoOutStream *outstream = &os->pub; @@ -243,32 +245,32 @@ static int outstream_begin_write_dummy(struct SoundIoPrivate *si, osd->write_frame_count = *frame_count; *out_areas = osd->areas; - return 0; + return SoundIoErrorNone; } -static int outstream_end_write_dummy(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os) { +static enum SoundIoError outstream_end_write_dummy(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os) { struct SoundIoOutStreamDummy *osd = &os->backend_data.dummy; struct SoundIoOutStream *outstream = &os->pub; int byte_count = osd->write_frame_count * outstream->bytes_per_frame; soundio_ring_buffer_advance_write_ptr(&osd->ring_buffer, byte_count); osd->frames_left -= osd->write_frame_count; - return 0; + return SoundIoErrorNone; } -static int outstream_clear_buffer_dummy(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os) { +static enum SoundIoError outstream_clear_buffer_dummy(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os) { struct SoundIoOutStreamDummy *osd = &os->backend_data.dummy; SOUNDIO_ATOMIC_FLAG_CLEAR(osd->clear_buffer_flag); soundio_os_cond_signal(osd->cond, NULL); - return 0; + return SoundIoErrorNone; } -static int outstream_get_latency_dummy(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os, double *out_latency) { +static enum SoundIoError outstream_get_latency_dummy(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os, double *out_latency) { struct SoundIoOutStream *outstream = &os->pub; struct SoundIoOutStreamDummy *osd = &os->backend_data.dummy; int fill_bytes = soundio_ring_buffer_fill_count(&osd->ring_buffer); *out_latency = (fill_bytes / outstream->bytes_per_frame) / (double)outstream->sample_rate; - return 0; + return SoundIoErrorNone; } static void instream_destroy_dummy(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is) { @@ -286,7 +288,7 @@ static void instream_destroy_dummy(struct SoundIoPrivate *si, struct SoundIoInSt soundio_ring_buffer_deinit(&isd->ring_buffer); } -static int instream_open_dummy(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is) { +static enum SoundIoError instream_open_dummy(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is) { struct SoundIoInStreamDummy *isd = &is->backend_data.dummy; struct SoundIoInStream *instream = &is->pub; struct SoundIoDevice *device = instream->device; @@ -321,13 +323,13 @@ static int instream_open_dummy(struct SoundIoPrivate *si, struct SoundIoInStream return 0; } -static int instream_pause_dummy(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is, bool pause) { +static enum SoundIoError instream_pause_dummy(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is, bool pause) { struct SoundIoInStreamDummy *isd = &is->backend_data.dummy; SOUNDIO_ATOMIC_STORE(isd->pause_requested, pause); return 0; } -static int instream_start_dummy(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is) { +static enum SoundIoError instream_start_dummy(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is) { struct SoundIoInStreamDummy *isd = &is->backend_data.dummy; struct SoundIo *soundio = &si->pub; assert(!isd->thread); @@ -341,7 +343,7 @@ static int instream_start_dummy(struct SoundIoPrivate *si, struct SoundIoInStrea return 0; } -static int instream_begin_read_dummy(struct SoundIoPrivate *si, +static enum SoundIoError instream_begin_read_dummy(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is, struct SoundIoChannelArea **out_areas, int *frame_count) { struct SoundIoInStream *instream = &is->pub; @@ -361,7 +363,7 @@ static int instream_begin_read_dummy(struct SoundIoPrivate *si, return 0; } -static int instream_end_read_dummy(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is) { +static enum SoundIoError instream_end_read_dummy(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is) { struct SoundIoInStreamDummy *isd = &is->backend_data.dummy; struct SoundIoInStream *instream = &is->pub; int byte_count = isd->read_frame_count * instream->bytes_per_frame; @@ -370,7 +372,7 @@ static int instream_end_read_dummy(struct SoundIoPrivate *si, struct SoundIoInSt return 0; } -static int instream_get_latency_dummy(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is, double *out_latency) { +static enum SoundIoError instream_get_latency_dummy(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is, double *out_latency) { struct SoundIoInStream *instream = &is->pub; struct SoundIoInStreamDummy *osd = &is->backend_data.dummy; int fill_bytes = soundio_ring_buffer_fill_count(&osd->ring_buffer); @@ -379,7 +381,7 @@ static int instream_get_latency_dummy(struct SoundIoPrivate *si, struct SoundIoI return 0; } -static int set_all_device_formats(struct SoundIoDevice *device) { +static enum SoundIoError set_all_device_formats(struct SoundIoDevice *device) { device->format_count = 22; device->formats = ALLOCATE(enum SoundIoFormat, device->format_count); if (!device->formats) @@ -419,7 +421,7 @@ static void set_all_device_sample_rates(struct SoundIoDevice *device) { device->sample_rates[0].max = SOUNDIO_MAX_SAMPLE_RATE; } -static int set_all_device_channel_layouts(struct SoundIoDevice *device) { +static enum SoundIoError set_all_device_channel_layouts(struct SoundIoDevice *device) { device->layout_count = soundio_channel_layout_builtin_count(); device->layouts = ALLOCATE(struct SoundIoChannelLayout, device->layout_count); if (!device->layouts) @@ -429,7 +431,7 @@ static int set_all_device_channel_layouts(struct SoundIoDevice *device) { return 0; } -int soundio_dummy_init(struct SoundIoPrivate *si) { +enum SoundIoError soundio_dummy_init(struct SoundIoPrivate *si) { struct SoundIo *soundio = &si->pub; struct SoundIoDummy *sid = &si->backend_data.dummy; diff --git a/src/dummy.h b/src/dummy.h index d50d12e..2ed01a6 100644 --- a/src/dummy.h +++ b/src/dummy.h @@ -14,7 +14,7 @@ #include "atomics.h" struct SoundIoPrivate; -int soundio_dummy_init(struct SoundIoPrivate *si); +enum SoundIoError soundio_dummy_init(struct SoundIoPrivate *si); struct SoundIoDummy { struct SoundIoOsMutex *mutex; diff --git a/src/jack.c b/src/jack.c index c56bf15..fff441f 100644 --- a/src/jack.c +++ b/src/jack.c @@ -425,7 +425,7 @@ static inline jack_nframes_t nframes_max(jack_nframes_t a, jack_nframes_t b) { return (a >= b) ? a : b; } -static int outstream_open_jack(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os) { +static enum SoundIoError outstream_open_jack(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os) { struct SoundIoJack *sij = &si->backend_data.jack; struct SoundIoOutStreamJack *osj = &os->backend_data.jack; struct SoundIoOutStream *outstream = &os->pub; @@ -454,7 +454,7 @@ static int outstream_open_jack(struct SoundIoPrivate *si, struct SoundIoOutStrea return SoundIoErrorOpeningDevice; } - int err; + enum SoundIoError err; if ((err = jack_set_process_callback(osj->client, outstream_process_callback, os))) { outstream_destroy_jack(si, os); return SoundIoErrorOpeningDevice; @@ -521,7 +521,7 @@ static int outstream_open_jack(struct SoundIoPrivate *si, struct SoundIoOutStrea return 0; } -static int outstream_pause_jack(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os, bool pause) { +static enum SoundIoError outstream_pause_jack(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os, bool pause) { struct SoundIoJack *sij = &si->backend_data.jack; if (sij->is_shutdown) @@ -530,11 +530,11 @@ static int outstream_pause_jack(struct SoundIoPrivate *si, struct SoundIoOutStre return SoundIoErrorIncompatibleBackend; } -static int outstream_start_jack(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os) { +static enum SoundIoError outstream_start_jack(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os) { struct SoundIoOutStreamJack *osj = &os->backend_data.jack; struct SoundIoOutStream *outstream = &os->pub; struct SoundIoJack *sij = &si->backend_data.jack; - int err; + enum SoundIoError err; if (sij->is_shutdown) return SoundIoErrorBackendDisconnected; @@ -556,7 +556,7 @@ static int outstream_start_jack(struct SoundIoPrivate *si, struct SoundIoOutStre return 0; } -static int outstream_begin_write_jack(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os, +static enum SoundIoError outstream_begin_write_jack(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os, struct SoundIoChannelArea **out_areas, int *frame_count) { struct SoundIoOutStreamJack *osj = &os->backend_data.jack; @@ -569,17 +569,17 @@ static int outstream_begin_write_jack(struct SoundIoPrivate *si, struct SoundIoO return 0; } -static int outstream_end_write_jack(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os) { +static enum SoundIoError outstream_end_write_jack(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os) { struct SoundIoOutStreamJack *osj = &os->backend_data.jack; osj->frames_left = 0; return 0; } -static int outstream_clear_buffer_jack(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os) { +static enum SoundIoError outstream_clear_buffer_jack(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os) { return SoundIoErrorIncompatibleBackend; } -static int outstream_get_latency_jack(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os, +static enum SoundIoError outstream_get_latency_jack(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os, double *out_latency) { struct SoundIoOutStreamJack *osj = &os->backend_data.jack; @@ -646,7 +646,7 @@ static int instream_process_callback(jack_nframes_t nframes, void *arg) { return 0; } -static int instream_open_jack(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is) { +static enum SoundIoError instream_open_jack(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is) { struct SoundIoInStream *instream = &is->pub; struct SoundIoInStreamJack *isj = &is->backend_data.jack; struct SoundIoJack *sij = &si->backend_data.jack; @@ -675,7 +675,7 @@ static int instream_open_jack(struct SoundIoPrivate *si, struct SoundIoInStreamP return SoundIoErrorOpeningDevice; } - int err; + enum SoundIoError err; if ((err = jack_set_process_callback(isj->client, instream_process_callback, is))) { instream_destroy_jack(si, is); return SoundIoErrorOpeningDevice; @@ -741,7 +741,7 @@ static int instream_open_jack(struct SoundIoPrivate *si, struct SoundIoInStreamP return 0; } -static int instream_pause_jack(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is, bool pause) { +static enum SoundIoError instream_pause_jack(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is, bool pause) { struct SoundIoJack *sij = &si->backend_data.jack; if (sij->is_shutdown) @@ -750,11 +750,11 @@ static int instream_pause_jack(struct SoundIoPrivate *si, struct SoundIoInStream return SoundIoErrorIncompatibleBackend; } -static int instream_start_jack(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is) { +static enum SoundIoError instream_start_jack(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is) { struct SoundIoInStreamJack *isj = &is->backend_data.jack; struct SoundIoInStream *instream = &is->pub; struct SoundIoJack *sij = &si->backend_data.jack; - int err; + enum SoundIoError err; if (sij->is_shutdown) return SoundIoErrorBackendDisconnected; @@ -776,7 +776,7 @@ static int instream_start_jack(struct SoundIoPrivate *si, struct SoundIoInStream return 0; } -static int instream_begin_read_jack(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is, +static enum SoundIoError instream_begin_read_jack(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is, struct SoundIoChannelArea **out_areas, int *frame_count) { struct SoundIoInStreamJack *isj = &is->backend_data.jack; @@ -789,13 +789,13 @@ static int instream_begin_read_jack(struct SoundIoPrivate *si, struct SoundIoInS return 0; } -static int instream_end_read_jack(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is) { +static enum SoundIoError instream_end_read_jack(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is) { struct SoundIoInStreamJack *isj = &is->backend_data.jack; isj->frames_left = 0; return 0; } -static int instream_get_latency_jack(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is, +static enum SoundIoError instream_get_latency_jack(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is, double *out_latency) { struct SoundIoInStreamJack *isj = &is->backend_data.jack; @@ -865,7 +865,7 @@ static void destroy_jack(struct SoundIoPrivate *si) { soundio_os_mutex_destroy(sij->mutex); } -int soundio_jack_init(struct SoundIoPrivate *si) { +enum SoundIoError soundio_jack_init(struct SoundIoPrivate *si) { struct SoundIoJack *sij = &si->backend_data.jack; struct SoundIo *soundio = &si->pub; diff --git a/src/jack.h b/src/jack.h index e96cf9b..d960939 100644 --- a/src/jack.h +++ b/src/jack.h @@ -20,7 +20,7 @@ #pragma GCC diagnostic pop struct SoundIoPrivate; -int soundio_jack_init(struct SoundIoPrivate *si); +enum SoundIoError soundio_jack_init(struct SoundIoPrivate *si); struct SoundIoDeviceJackPort { char *full_name; diff --git a/src/pulseaudio.c b/src/pulseaudio.c index 3f1bb6a..339018b 100644 --- a/src/pulseaudio.c +++ b/src/pulseaudio.c @@ -661,7 +661,7 @@ static void timing_update_callback(pa_stream *stream, int success, void *userdat pa_threaded_mainloop_signal(sipa->main_loop, 0); } -static int outstream_open_pa(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os) { +static enum SoundIoError outstream_open_pa(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os) { struct SoundIoOutStreamPulseAudio *ospa = &os->backend_data.pulseaudio; struct SoundIoOutStream *outstream = &os->pub; @@ -737,7 +737,7 @@ static int outstream_open_pa(struct SoundIoPrivate *si, struct SoundIoOutStreamP return 0; } -static int outstream_start_pa(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os) { +static enum SoundIoError outstream_start_pa(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os) { struct SoundIoOutStream *outstream = &os->pub; struct SoundIoPulseAudio *sipa = &si->backend_data.pulseaudio; struct SoundIoOutStreamPulseAudio *ospa = &os->backend_data.pulseaudio; @@ -763,7 +763,7 @@ static int outstream_start_pa(struct SoundIoPrivate *si, struct SoundIoOutStream return 0; } -static int outstream_begin_write_pa(struct SoundIoPrivate *si, +static enum SoundIoError outstream_begin_write_pa(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os, struct SoundIoChannelArea **out_areas, int *frame_count) { struct SoundIoOutStream *outstream = &os->pub; @@ -785,7 +785,7 @@ static int outstream_begin_write_pa(struct SoundIoPrivate *si, return 0; } -static int outstream_end_write_pa(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os) { +static enum SoundIoError outstream_end_write_pa(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os) { struct SoundIoOutStreamPulseAudio *ospa = &os->backend_data.pulseaudio; pa_stream *stream = ospa->stream; @@ -796,7 +796,7 @@ static int outstream_end_write_pa(struct SoundIoPrivate *si, struct SoundIoOutSt return 0; } -static int outstream_clear_buffer_pa(struct SoundIoPrivate *si, +static enum SoundIoError outstream_clear_buffer_pa(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os) { struct SoundIoOutStreamPulseAudio *ospa = &os->backend_data.pulseaudio; @@ -804,7 +804,7 @@ static int outstream_clear_buffer_pa(struct SoundIoPrivate *si, return 0; } -static int outstream_pause_pa(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os, bool pause) { +static enum SoundIoError outstream_pause_pa(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os, bool pause) { struct SoundIoOutStreamPulseAudio *ospa = &os->backend_data.pulseaudio; struct SoundIoPulseAudio *sipa = &si->backend_data.pulseaudio; @@ -828,7 +828,7 @@ static int outstream_pause_pa(struct SoundIoPrivate *si, struct SoundIoOutStream return 0; } -static int outstream_get_latency_pa(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os, double *out_latency) { +static enum SoundIoError outstream_get_latency_pa(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os, double *out_latency) { struct SoundIoOutStreamPulseAudio *ospa = &os->backend_data.pulseaudio; int err; @@ -890,7 +890,7 @@ static void instream_destroy_pa(struct SoundIoPrivate *si, struct SoundIoInStrea } } -static int instream_open_pa(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is) { +static enum SoundIoError instream_open_pa(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is) { struct SoundIoInStreamPulseAudio *ispa = &is->backend_data.pulseaudio; struct SoundIoInStream *instream = &is->pub; @@ -941,7 +941,7 @@ static int instream_open_pa(struct SoundIoPrivate *si, struct SoundIoInStreamPri return 0; } -static int instream_start_pa(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is) { +static enum SoundIoError instream_start_pa(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is) { struct SoundIoInStream *instream = &is->pub; struct SoundIoInStreamPulseAudio *ispa = &is->backend_data.pulseaudio; struct SoundIoPulseAudio *sipa = &si->backend_data.pulseaudio; @@ -971,7 +971,7 @@ static int instream_start_pa(struct SoundIoPrivate *si, struct SoundIoInStreamPr return 0; } -static int instream_begin_read_pa(struct SoundIoPrivate *si, +static enum SoundIoError instream_begin_read_pa(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is, struct SoundIoChannelArea **out_areas, int *frame_count) { struct SoundIoInStream *instream = &is->pub; @@ -1007,7 +1007,7 @@ static int instream_begin_read_pa(struct SoundIoPrivate *si, return 0; } -static int instream_end_read_pa(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is) { +static enum SoundIoError instream_end_read_pa(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is) { struct SoundIoInStream *instream = &is->pub; struct SoundIoInStreamPulseAudio *ispa = &is->backend_data.pulseaudio; pa_stream *stream = ispa->stream; @@ -1032,7 +1032,7 @@ static int instream_end_read_pa(struct SoundIoPrivate *si, struct SoundIoInStrea return 0; } -static int instream_pause_pa(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is, bool pause) { +static enum SoundIoError instream_pause_pa(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is, bool pause) { struct SoundIoInStreamPulseAudio *ispa = &is->backend_data.pulseaudio; struct SoundIoPulseAudio *sipa = &si->backend_data.pulseaudio; @@ -1054,7 +1054,7 @@ static int instream_pause_pa(struct SoundIoPrivate *si, struct SoundIoInStreamPr return 0; } -static int instream_get_latency_pa(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is, double *out_latency) { +static enum SoundIoError instream_get_latency_pa(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is, double *out_latency) { struct SoundIoInStreamPulseAudio *ispa = &is->backend_data.pulseaudio; int err; @@ -1067,7 +1067,7 @@ static int instream_get_latency_pa(struct SoundIoPrivate *si, struct SoundIoInSt return 0; } -int soundio_pulseaudio_init(struct SoundIoPrivate *si) { +enum SoundIoError soundio_pulseaudio_init(struct SoundIoPrivate *si) { struct SoundIo *soundio = &si->pub; struct SoundIoPulseAudio *sipa = &si->backend_data.pulseaudio; diff --git a/src/pulseaudio.h b/src/pulseaudio.h index a216e26..0ae2bef 100644 --- a/src/pulseaudio.h +++ b/src/pulseaudio.h @@ -14,7 +14,7 @@ #include struct SoundIoPrivate; -int soundio_pulseaudio_init(struct SoundIoPrivate *si); +enum SoundIoError soundio_pulseaudio_init(struct SoundIoPrivate *si); struct SoundIoDevicePulseAudio { int make_the_struct_not_empty; }; diff --git a/src/soundio.c b/src/soundio.c index 866841d..3de5fab 100644 --- a/src/soundio.c +++ b/src/soundio.c @@ -33,7 +33,7 @@ static const enum SoundIoBackend available_backends[] = { SoundIoBackendDummy, }; -typedef int (*backend_init_t)(struct SoundIoPrivate *); +typedef enum SoundIoError (*backend_init_t)(struct SoundIoPrivate *); static backend_init_t backend_init_fns[] = { NULL, // None backend @@ -73,8 +73,8 @@ static backend_init_t backend_init_fns[] = { SOUNDIO_MAKE_LIST_DEF(struct SoundIoDevice*, SoundIoListDevicePtr, SOUNDIO_LIST_NOT_STATIC) SOUNDIO_MAKE_LIST_DEF(struct SoundIoSampleRateRange, SoundIoListSampleRateRange, SOUNDIO_LIST_NOT_STATIC) -const char *soundio_strerror(int error) { - switch ((enum SoundIoError)error) { +const char *soundio_strerror(enum SoundIoError error) { + switch (error) { case SoundIoErrorNone: return "(no error)"; case SoundIoErrorNoMem: return "out of memory"; case SoundIoErrorInitAudioBackend: return "unable to initialize audio backend"; @@ -181,7 +181,7 @@ void soundio_destroy(struct SoundIo *soundio) { static void do_nothing_cb(struct SoundIo *soundio) { } static void default_msg_callback(const char *msg) { } -static void default_backend_disconnect_cb(struct SoundIo *soundio, int err) { +static void default_backend_disconnect_cb(struct SoundIo *soundio, enum SoundIoError err) { soundio_panic("libsoundio: backend disconnected: %s", soundio_strerror(err)); } @@ -195,7 +195,7 @@ static void default_emit_rtprio_warning(void) { } struct SoundIo *soundio_create(void) { - int err; + enum SoundIoError err; if ((err = soundio_os_init())) return NULL; struct SoundIoPrivate *si = ALLOCATE(struct SoundIoPrivate, 1); @@ -212,7 +212,7 @@ struct SoundIo *soundio_create(void) { return soundio; } -int soundio_connect(struct SoundIo *soundio) { +enum SoundIoError soundio_connect(struct SoundIo *soundio) { int err = 0; for (int i = 0; i < ARRAY_LENGTH(available_backends); i += 1) { @@ -227,7 +227,7 @@ int soundio_connect(struct SoundIo *soundio) { return err; } -int soundio_connect_backend(struct SoundIo *soundio, enum SoundIoBackend backend) { +enum SoundIoError soundio_connect_backend(struct SoundIo *soundio, enum SoundIoBackend backend) { struct SoundIoPrivate *si = (struct SoundIoPrivate *)soundio; if (soundio->current_backend) @@ -236,7 +236,7 @@ int soundio_connect_backend(struct SoundIo *soundio, enum SoundIoBackend backend if (backend <= 0 || backend > SoundIoBackendDummy) return SoundIoErrorInvalid; - int (*fn)(struct SoundIoPrivate *) = backend_init_fns[backend]; + enum SoundIoError (*fn)(struct SoundIoPrivate *) = backend_init_fns[backend]; if (!fn) return SoundIoErrorBackendUnavailable; @@ -446,7 +446,7 @@ void soundio_force_device_scan(struct SoundIo *soundio) { si->force_device_scan(si); } -int soundio_outstream_begin_write(struct SoundIoOutStream *outstream, +enum SoundIoError soundio_outstream_begin_write(struct SoundIoOutStream *outstream, struct SoundIoChannelArea **areas, int *frame_count) { struct SoundIo *soundio = outstream->device->soundio; @@ -457,14 +457,14 @@ int soundio_outstream_begin_write(struct SoundIoOutStream *outstream, return si->outstream_begin_write(si, os, areas, frame_count); } -int soundio_outstream_end_write(struct SoundIoOutStream *outstream) { +enum SoundIoError soundio_outstream_end_write(struct SoundIoOutStream *outstream) { struct SoundIo *soundio = outstream->device->soundio; struct SoundIoPrivate *si = (struct SoundIoPrivate *)soundio; struct SoundIoOutStreamPrivate *os = (struct SoundIoOutStreamPrivate *)outstream; return si->outstream_end_write(si, os); } -static void default_outstream_error_callback(struct SoundIoOutStream *os, int err) { +static void default_outstream_error_callback(struct SoundIoOutStream *os, enum SoundIoError err) { soundio_panic("libsoundio: %s", soundio_strerror(err)); } @@ -488,7 +488,7 @@ struct SoundIoOutStream *soundio_outstream_create(struct SoundIoDevice *device) return outstream; } -int soundio_outstream_open(struct SoundIoOutStream *outstream) { +enum SoundIoError soundio_outstream_open(struct SoundIoOutStream *outstream) { struct SoundIoDevice *device = outstream->device; if (device->aim != SoundIoDeviceAimOutput) @@ -540,35 +540,35 @@ void soundio_outstream_destroy(struct SoundIoOutStream *outstream) { free(os); } -int soundio_outstream_start(struct SoundIoOutStream *outstream) { +enum SoundIoError soundio_outstream_start(struct SoundIoOutStream *outstream) { struct SoundIo *soundio = outstream->device->soundio; struct SoundIoPrivate *si = (struct SoundIoPrivate *)soundio; struct SoundIoOutStreamPrivate *os = (struct SoundIoOutStreamPrivate *)outstream; return si->outstream_start(si, os); } -int soundio_outstream_pause(struct SoundIoOutStream *outstream, bool pause) { +enum SoundIoError soundio_outstream_pause(struct SoundIoOutStream *outstream, bool pause) { struct SoundIo *soundio = outstream->device->soundio; struct SoundIoPrivate *si = (struct SoundIoPrivate *)soundio; struct SoundIoOutStreamPrivate *os = (struct SoundIoOutStreamPrivate *)outstream; return si->outstream_pause(si, os, pause); } -int soundio_outstream_clear_buffer(struct SoundIoOutStream *outstream) { +enum SoundIoError soundio_outstream_clear_buffer(struct SoundIoOutStream *outstream) { struct SoundIo *soundio = outstream->device->soundio; struct SoundIoPrivate *si = (struct SoundIoPrivate *)soundio; struct SoundIoOutStreamPrivate *os = (struct SoundIoOutStreamPrivate *)outstream; return si->outstream_clear_buffer(si, os); } -int soundio_outstream_get_latency(struct SoundIoOutStream *outstream, double *out_latency) { +enum SoundIoError soundio_outstream_get_latency(struct SoundIoOutStream *outstream, double *out_latency) { struct SoundIo *soundio = outstream->device->soundio; struct SoundIoPrivate *si = (struct SoundIoPrivate *)soundio; struct SoundIoOutStreamPrivate *os = (struct SoundIoOutStreamPrivate *)outstream; return si->outstream_get_latency(si, os, out_latency); } -static void default_instream_error_callback(struct SoundIoInStream *is, int err) { +static void default_instream_error_callback(struct SoundIoInStream *is, enum SoundIoError err) { soundio_panic("libsoundio: %s", soundio_strerror(err)); } @@ -592,7 +592,7 @@ struct SoundIoInStream *soundio_instream_create(struct SoundIoDevice *device) { return instream; } -int soundio_instream_open(struct SoundIoInStream *instream) { +enum SoundIoError soundio_instream_open(struct SoundIoInStream *instream) { struct SoundIoDevice *device = instream->device; if (device->aim != SoundIoDeviceAimInput) return SoundIoErrorInvalid; @@ -628,7 +628,7 @@ int soundio_instream_open(struct SoundIoInStream *instream) { return si->instream_open(si, is); } -int soundio_instream_start(struct SoundIoInStream *instream) { +enum SoundIoError soundio_instream_start(struct SoundIoInStream *instream) { struct SoundIo *soundio = instream->device->soundio; struct SoundIoPrivate *si = (struct SoundIoPrivate *)soundio; struct SoundIoInStreamPrivate *is = (struct SoundIoInStreamPrivate *)instream; @@ -650,14 +650,14 @@ void soundio_instream_destroy(struct SoundIoInStream *instream) { free(is); } -int soundio_instream_pause(struct SoundIoInStream *instream, bool pause) { +enum SoundIoError soundio_instream_pause(struct SoundIoInStream *instream, bool pause) { struct SoundIo *soundio = instream->device->soundio; struct SoundIoPrivate *si = (struct SoundIoPrivate *)soundio; struct SoundIoInStreamPrivate *is = (struct SoundIoInStreamPrivate *)instream; return si->instream_pause(si, is, pause); } -int soundio_instream_begin_read(struct SoundIoInStream *instream, +enum SoundIoError soundio_instream_begin_read(struct SoundIoInStream *instream, struct SoundIoChannelArea **areas, int *frame_count) { struct SoundIo *soundio = instream->device->soundio; @@ -666,14 +666,14 @@ int soundio_instream_begin_read(struct SoundIoInStream *instream, return si->instream_begin_read(si, is, areas, frame_count); } -int soundio_instream_end_read(struct SoundIoInStream *instream) { +enum SoundIoError soundio_instream_end_read(struct SoundIoInStream *instream) { struct SoundIo *soundio = instream->device->soundio; struct SoundIoPrivate *si = (struct SoundIoPrivate *)soundio; struct SoundIoInStreamPrivate *is = (struct SoundIoInStreamPrivate *)instream; return si->instream_end_read(si, is); } -int soundio_instream_get_latency(struct SoundIoInStream *instream, double *out_latency) { +enum SoundIoError soundio_instream_get_latency(struct SoundIoInStream *instream, double *out_latency) { struct SoundIo *soundio = instream->device->soundio; struct SoundIoPrivate *si = (struct SoundIoPrivate *)soundio; struct SoundIoInStreamPrivate *is = (struct SoundIoInStreamPrivate *)instream; diff --git a/src/soundio_private.h b/src/soundio_private.h index 213b36f..1e1ab4a 100644 --- a/src/soundio_private.h +++ b/src/soundio_private.h @@ -143,25 +143,25 @@ struct SoundIoPrivate { void (*wakeup)(struct SoundIoPrivate *); void (*force_device_scan)(struct SoundIoPrivate *); - int (*outstream_open)(struct SoundIoPrivate *, struct SoundIoOutStreamPrivate *); + enum SoundIoError (*outstream_open)(struct SoundIoPrivate *, struct SoundIoOutStreamPrivate *); void (*outstream_destroy)(struct SoundIoPrivate *, struct SoundIoOutStreamPrivate *); - int (*outstream_start)(struct SoundIoPrivate *, struct SoundIoOutStreamPrivate *); - int (*outstream_begin_write)(struct SoundIoPrivate *, struct SoundIoOutStreamPrivate *, + enum SoundIoError (*outstream_start)(struct SoundIoPrivate *, struct SoundIoOutStreamPrivate *); + enum SoundIoError (*outstream_begin_write)(struct SoundIoPrivate *, struct SoundIoOutStreamPrivate *, struct SoundIoChannelArea **out_areas, int *out_frame_count); - int (*outstream_end_write)(struct SoundIoPrivate *, struct SoundIoOutStreamPrivate *); - int (*outstream_clear_buffer)(struct SoundIoPrivate *, struct SoundIoOutStreamPrivate *); - int (*outstream_pause)(struct SoundIoPrivate *, struct SoundIoOutStreamPrivate *, bool pause); - int (*outstream_get_latency)(struct SoundIoPrivate *, struct SoundIoOutStreamPrivate *, double *out_latency); + enum SoundIoError (*outstream_end_write)(struct SoundIoPrivate *, struct SoundIoOutStreamPrivate *); + enum SoundIoError (*outstream_clear_buffer)(struct SoundIoPrivate *, struct SoundIoOutStreamPrivate *); + enum SoundIoError (*outstream_pause)(struct SoundIoPrivate *, struct SoundIoOutStreamPrivate *, bool pause); + enum SoundIoError (*outstream_get_latency)(struct SoundIoPrivate *, struct SoundIoOutStreamPrivate *, double *out_latency); - int (*instream_open)(struct SoundIoPrivate *, struct SoundIoInStreamPrivate *); + enum SoundIoError (*instream_open)(struct SoundIoPrivate *, struct SoundIoInStreamPrivate *); void (*instream_destroy)(struct SoundIoPrivate *, struct SoundIoInStreamPrivate *); - int (*instream_start)(struct SoundIoPrivate *, struct SoundIoInStreamPrivate *); - int (*instream_begin_read)(struct SoundIoPrivate *, struct SoundIoInStreamPrivate *, + enum SoundIoError (*instream_start)(struct SoundIoPrivate *, struct SoundIoInStreamPrivate *); + enum SoundIoError (*instream_begin_read)(struct SoundIoPrivate *, struct SoundIoInStreamPrivate *, struct SoundIoChannelArea **out_areas, int *out_frame_count); - int (*instream_end_read)(struct SoundIoPrivate *, struct SoundIoInStreamPrivate *); - int (*instream_pause)(struct SoundIoPrivate *, struct SoundIoInStreamPrivate *, bool pause); - int (*instream_get_latency)(struct SoundIoPrivate *, struct SoundIoInStreamPrivate *, double *out_latency); + enum SoundIoError (*instream_end_read)(struct SoundIoPrivate *, struct SoundIoInStreamPrivate *); + enum SoundIoError (*instream_pause)(struct SoundIoPrivate *, struct SoundIoInStreamPrivate *, bool pause); + enum SoundIoError (*instream_get_latency)(struct SoundIoPrivate *, struct SoundIoInStreamPrivate *, double *out_latency); union SoundIoBackendData backend_data; }; diff --git a/test/backend_disconnect_recover.c b/test/backend_disconnect_recover.c index 046a150..8f04191 100644 --- a/test/backend_disconnect_recover.c +++ b/test/backend_disconnect_recover.c @@ -38,7 +38,7 @@ static enum SoundIoBackend backend = SoundIoBackendNone; static bool severed = false; -static void on_backend_disconnect(struct SoundIo *soundio, int err) { +static void on_backend_disconnect(struct SoundIo *soundio, enum SoundIoError err) { fprintf(stderr, "OK backend disconnected with '%s'.\n", soundio_strerror(err)); severed = true; } diff --git a/test/unit_tests.c b/test/unit_tests.c index 2a39282..9ba33f4 100644 --- a/test/unit_tests.c +++ b/test/unit_tests.c @@ -26,7 +26,7 @@ static void test_os_get_time(void) { } static void write_callback(struct SoundIoOutStream *device, int frame_count_min, int frame_count_max) { } -static void error_callback(struct SoundIoOutStream *device, int err) { } +static void error_callback(struct SoundIoOutStream *device, enum SoundIoError err) { } static void test_create_outstream(void) { struct SoundIo *soundio = soundio_create();