aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMatthew Gregan <[email protected]>2012-10-18 17:57:10 +1300
committerMatthew Gregan <[email protected]>2012-10-18 17:57:10 +1300
commitf4c927fb1c2dc0a0580d0bca4bd267c34febada4 (patch)
tree5964bb693a13b480f7e5402ace1cf6364eff6f48
parentd8f950c4ec324d1a0602a142c5fa5df331178ffc (diff)
downloadcubeb-f4c927fb1c2dc0a0580d0bca4bd267c34febada4.tar.gz
cubeb-f4c927fb1c2dc0a0580d0bca4bd267c34febada4.zip
audiounit: make unit initialization failures non-fatal.
-rw-r--r--src/cubeb_audiounit.c34
1 files changed, 24 insertions, 10 deletions
diff --git a/src/cubeb_audiounit.c b/src/cubeb_audiounit.c
index fff0130..9fd46c4 100644
--- a/src/cubeb_audiounit.c
+++ b/src/cubeb_audiounit.c
@@ -181,17 +181,26 @@ cubeb_stream_init(cubeb * context, cubeb_stream ** stream, char const * stream_n
stm->frames_queued = 0;
r = OpenAComponent(comp, &stm->unit);
- assert(r == 0);
+ if (r != 0) {
+ cubeb_stream_destroy(stm);
+ return CUBEB_ERROR;
+ }
input.inputProc = audio_unit_output_callback;
input.inputProcRefCon = stm;
r = AudioUnitSetProperty(stm->unit, kAudioUnitProperty_SetRenderCallback,
kAudioUnitScope_Global, 0, &input, sizeof(input));
- assert(r == 0);
+ if (r != 0) {
+ cubeb_stream_destroy(stm);
+ return CUBEB_ERROR;
+ }
r = AudioUnitSetProperty(stm->unit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input,
0, &ss, sizeof(ss));
- assert(r == 0);
+ if (r != 0) {
+ cubeb_stream_destroy(stm);
+ return CUBEB_ERROR;
+ }
buffer_size = ss.mSampleRate / 1000.0 * latency * ss.mBytesPerFrame / NBUFS;
if (buffer_size % ss.mBytesPerFrame != 0) {
@@ -200,7 +209,10 @@ cubeb_stream_init(cubeb * context, cubeb_stream ** stream, char const * stream_n
assert(buffer_size % ss.mBytesPerFrame == 0);
r = AudioUnitInitialize(stm->unit);
- assert(r == 0);
+ if (r != 0) {
+ cubeb_stream_destroy(stm);
+ return CUBEB_ERROR;
+ }
*stream = stm;
@@ -214,14 +226,16 @@ cubeb_stream_destroy(cubeb_stream * stm)
stm->shutdown = 1;
- r = AudioOutputUnitStop(stm->unit);
- assert(r == 0);
+ if (stm->unit) {
+ r = AudioOutputUnitStop(stm->unit);
+ assert(r == 0);
- r = AudioUnitUninitialize(stm->unit);
- assert(r == 0);
+ r = AudioUnitUninitialize(stm->unit);
+ assert(r == 0);
- r = CloseComponent(stm->unit);
- assert(r == 0);
+ r = CloseComponent(stm->unit);
+ assert(r == 0);
+ }
r = pthread_mutex_destroy(&stm->mutex);
assert(r == 0);