Commit fa739e09 authored by Simon Morlat's avatar Simon Morlat
Browse files

implement immediate destruction of audio unit when the core says that we no longer need sound.

parent 83e6c0dc
......@@ -169,6 +169,7 @@ struct au_filter_write_data{
};
static void stop_audio_unit (au_card_t* d);
static void cancel_audio_unit_timer(au_card_t* card);
/*
......@@ -214,7 +215,7 @@ static void create_io_unit (AudioUnit* au, MSSndCard* sndcard) {
check_audiounit_call( AudioComponentInstanceNew(foundComponent, au) );
ms_message("AudioUnit created with type %x.", subtype);
ms_message("AudioUnit created with type %s.", subtype==kAudioUnitSubType_RemoteIO ? "kAudioUnitSubType_RemoteIO" : "kAudioUnitSubType_VoiceProcessingIO" );
}
......@@ -246,7 +247,7 @@ static void au_init(MSSndCard *card){
d->nchannels=1;
d->ms_snd_card=card;
card->preferred_sample_rate=44100;
card->capabilities|=MS_SND_CARD_CAP_BUILTIN_ECHO_CANCELLER;
card->capabilities|=MS_SND_CARD_CAP_BUILTIN_ECHO_CANCELLER|MS_SND_CARD_CAP_IS_SLOW;
ms_mutex_init(&d->mutex,NULL);
AudioSessionInitialize(NULL, NULL, au_interruption_listener, d);
card->data=d;
......@@ -259,6 +260,18 @@ static void au_uninit(MSSndCard *card){
ms_free(d);
}
static void au_usage_hint(MSSndCard *card, bool_t used){
au_card_t *d=(au_card_t*)card->data;
if (!used){
ms_mutex_lock(&d->mutex);
cancel_audio_unit_timer(d);
stop_audio_unit(d);
ms_mutex_unlock(&d->mutex);
}
}
static void au_detect(MSSndCardManager *m);
static MSSndCard *au_duplicate(MSSndCard *obj);
......@@ -274,7 +287,8 @@ MSSndCardDesc au_card_desc={
.create_reader=ms_au_read_new,
.create_writer=ms_au_write_new,
.uninit=au_uninit,
.duplicate=au_duplicate
.duplicate=au_duplicate,
.usage_hint=au_usage_hint
};
static MSSndCard *au_duplicate(MSSndCard *obj){
......@@ -393,9 +407,7 @@ static OSStatus au_write_cb (
/****************config**************/
static void configure_audio_session (au_card_t* d,uint64_t time) {
OSStatus auresult;
UInt32 audioCategory;
UInt32 doSetProperty = 1;
UInt32 audioCategorySize=sizeof(audioCategory);
bool_t changed;
......@@ -526,7 +538,7 @@ static void stop_audio_unit (au_card_t* d) {
d->rate=0; /*uninit*/
}
static void check_audio_unit(au_card_t* card){
static void cancel_audio_unit_timer(au_card_t* card){
if (card->shutdown_timer){
CFRunLoopRemoveTimer(CFRunLoopGetMain(), card->shutdown_timer,kCFRunLoopCommonModes);
CFRunLoopTimerInvalidate(card->shutdown_timer);
......@@ -541,7 +553,7 @@ static void au_read_preprocess(MSFilter *f){
au_filter_read_data_t *d= (au_filter_read_data_t*)f->data;
au_card_t* card=d->base.card;
check_audio_unit(card);
cancel_audio_unit_timer(card);
configure_audio_session(card, f->ticker->time);
if (!card->io_unit) create_io_unit(&card->io_unit, card->ms_snd_card);
......@@ -613,7 +625,7 @@ static void au_write_preprocess(MSFilter *f){
au_filter_write_data_t *d= (au_filter_write_data_t*)f->data;
au_card_t* card=d->base.card;
check_audio_unit(card);
cancel_audio_unit_timer(card);
if (card->io_unit_started) {
ms_message("AudioUnit already started");
......@@ -807,7 +819,9 @@ static MSFilterMethod au_methods[]={
static void shutdown_timer(CFRunLoopTimerRef timer, void *info){
au_card_t *card=(au_card_t*)info;
ms_mutex_lock(&card->mutex);
stop_audio_unit(card);
ms_mutex_unlock(&card->mutex);
}
static void check_unused(au_card_t *card){
......@@ -833,12 +847,12 @@ static void au_read_uninit(MSFilter *f) {
au_card_t* card=d->base.card;
ms_mutex_lock(&card->mutex);
card->read_data=NULL;
ms_mutex_unlock(&card->mutex);
if( card->is_tester){
if (card->is_tester){
stop_audio_unit(card);
} else {
check_unused(card);
}
ms_mutex_unlock(&card->mutex);
ms_mutex_destroy(&d->mutex);
ms_free(d);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment