Add support for pause for iOS audioUnit
This commit is contained in:
parent
e707bf0126
commit
554bc193f0
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue