diff options
author | System Administrator <root@Mamadous-MacBook-Pro.local> | 2016-08-05 23:18:42 +0200 |
---|---|---|
committer | System Administrator <root@Mamadous-MacBook-Pro.local> | 2016-08-05 23:18:42 +0200 |
commit | 554bc193f0039ec129b7ac2eb80934bc67815dda (patch) | |
tree | 31d5e419d4235b0761128b11b8b36d8e7e3d2c7d /tinyDAV | |
parent | e707bf0126d60cc0843f18db65704adc50547ec5 (diff) | |
download | doubango-554bc193f0039ec129b7ac2eb80934bc67815dda.zip doubango-554bc193f0039ec129b7ac2eb80934bc67815dda.tar.gz |
Add support for pause for iOS audioUnit
Diffstat (limited to 'tinyDAV')
-rwxr-xr-x | tinyDAV/src/audio/coreaudio/tdav_consumer_audiounit.c | 40 | ||||
-rwxr-xr-x | tinyDAV/src/audio/coreaudio/tdav_producer_audiounit.c | 41 |
2 files changed, 79 insertions, 2 deletions
diff --git a/tinyDAV/src/audio/coreaudio/tdav_consumer_audiounit.c b/tinyDAV/src/audio/coreaudio/tdav_consumer_audiounit.c index 12ed8db..6cbe2b5 100755 --- a/tinyDAV/src/audio/coreaudio/tdav_consumer_audiounit.c +++ b/tinyDAV/src/audio/coreaudio/tdav_consumer_audiounit.c @@ -37,6 +37,8 @@ #define kRingPacketCount +10 static tsk_size_t tdav_consumer_audiounit_get(tdav_consumer_audiounit_t* self, void* data, tsk_size_t size); +static int tdav_consumer_audiounit_pause(tmedia_consumer_t* self); +static int tdav_consumer_audiounit_resume(tmedia_consumer_t* self); static OSStatus __handle_output_buffer(void *inRefCon, AudioUnitRenderActionFlags *ioActionFlags, @@ -109,6 +111,10 @@ int tdav_consumer_audiounit_set(tmedia_consumer_t* self, const tmedia_param_t* p int32_t interrupt = *((uint8_t*)param->value) ? 1 : 0; return tdav_audiounit_handle_interrupt(consumer->audioUnitHandle, interrupt); } + else if (tsk_striequals(param->key, "pause") || tsk_striequals(param->key, "hold")) { + int32_t pause = *((uint8_t*)param->value) ? 1 : 0; + return pause ? tdav_consumer_audiounit_pause(self) : tdav_consumer_audiounit_resume(self); + } } } return tdav_consumer_audio_set(TDAV_CONSUMER_AUDIO(self), param); @@ -337,11 +343,43 @@ static int tdav_consumer_audiounit_pause(tmedia_consumer_t* self) TSK_DEBUG_ERROR("Invalid parameter"); return -1; } - consumer->paused = tsk_true; + if (!consumer->paused) { + consumer->paused = tsk_true; + if (consumer->started) { + int ret = tdav_audiounit_handle_stop(consumer->audioUnitHandle); + if(ret) { + TSK_DEBUG_ERROR("tdav_audiounit_handle_stop failed with error code=%d", ret); + } + consumer->started = false; + } + } + TSK_DEBUG_INFO("AudioUnit consumer paused"); return 0; } +static int tdav_consumer_audiounit_resume(tmedia_consumer_t* self) +{ + tdav_consumer_audiounit_t* consumer = (tdav_consumer_audiounit_t*)self; + if(!consumer) { + TSK_DEBUG_ERROR("Invalid parameter"); + return -1; + } + if (consumer->paused) { + consumer->paused = tsk_false; + if (!consumer->started) { + int ret = tdav_audiounit_handle_start(consumer->audioUnitHandle); + if(ret) { + TSK_DEBUG_ERROR("tdav_audiounit_handle_start failed with error code=%d", ret); + } + consumer->started = true; + } + } + + TSK_DEBUG_INFO("AudioUnit consumer resumed"); + return 0; +} + static int tdav_consumer_audiounit_stop(tmedia_consumer_t* self) { tdav_consumer_audiounit_t* consumer = (tdav_consumer_audiounit_t*)self; diff --git a/tinyDAV/src/audio/coreaudio/tdav_producer_audiounit.c b/tinyDAV/src/audio/coreaudio/tdav_producer_audiounit.c index 7f8af7e..b2b60f7 100755 --- a/tinyDAV/src/audio/coreaudio/tdav_producer_audiounit.c +++ b/tinyDAV/src/audio/coreaudio/tdav_producer_audiounit.c @@ -35,6 +35,9 @@ #define kRingPacketCount 10 +static int tdav_producer_audiounit_pause(tmedia_producer_t* self); +static int tdav_producer_audiounit_resume(tmedia_producer_t* self); + static OSStatus __handle_input_buffer(void *inRefCon, AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, @@ -91,6 +94,10 @@ int tdav_producer_audiounit_set(tmedia_producer_t* self, const tmedia_param_t* p int32_t interrupt = *((uint8_t*)param->value) ? 1 : 0; return tdav_audiounit_handle_interrupt(producer->audioUnitHandle, interrupt); } + else if (tsk_striequals(param->key, "pause") || tsk_striequals(param->key, "hold")) { + int32_t pause = *((uint8_t*)param->value) ? 1 : 0; + return pause ? tdav_producer_audiounit_pause(self) : tdav_producer_audiounit_resume(self); + } } } return tdav_producer_audio_set(TDAV_PRODUCER_AUDIO(self), param); @@ -319,11 +326,43 @@ static int tdav_producer_audiounit_pause(tmedia_producer_t* self) TSK_DEBUG_ERROR("Invalid parameter"); return -1; } - producer->paused = tsk_true; + if (!producer->paused) { + producer->paused = tsk_true; + if (producer->started) { + int ret = tdav_audiounit_handle_stop(producer->audioUnitHandle); + if(ret) { + TSK_DEBUG_ERROR("tdav_audiounit_handle_stop failed with error code=%d", ret); + // do not return even if failed => we MUST stop the thread! + } + producer->started = false; + } + } TSK_DEBUG_INFO("AudioUnit producer paused"); return 0; } +static int tdav_producer_audiounit_resume(tmedia_producer_t* self) +{ + tdav_producer_audiounit_t* producer = (tdav_producer_audiounit_t*)self; + if(!producer) { + TSK_DEBUG_ERROR("Invalid parameter"); + return -1; + } + if (producer->paused) { + if (!producer->started) { + int ret = tdav_audiounit_handle_start(producer->audioUnitHandle); + if(ret) { + TSK_DEBUG_ERROR("tdav_audiounit_handle_start failed with error code=%d", ret); + // do not return even if failed => we MUST stop the thread! + } + } + producer->paused = false; + producer->started = true; + } + TSK_DEBUG_INFO("AudioUnit producer resumed"); + return 0; +} + static int tdav_producer_audiounit_stop(tmedia_producer_t* self) { tdav_producer_audiounit_t* producer = (tdav_producer_audiounit_t*)self; |