Skip to content
Snippets Groups Projects
Commit 999590a3 authored by Kateryna Kostiuk's avatar Kateryna Kostiuk Committed by Kateryna Kostiuk
Browse files

core audio: listen to device events

Change-Id: If31c502b0afa6a476ed9b538512784ed94778cbe
parent 298a8e35
No related branches found
No related tags found
No related merge requests found
......@@ -125,6 +125,10 @@ private:
UInt32 inNumberAddresses,
const AudioObjectPropertyAddress inAddresses[],
void* inRefCon);
static OSStatus devicesChangedCallback(AudioObjectID inObjectID,
UInt32 inNumberAddresses,
const AudioObjectPropertyAddress inAddresses[],
void* inRefCon);
void read(AudioUnitRenderActionFlags* ioActionFlags,
const AudioTimeStamp* inTimeStamp,
......
......@@ -175,6 +175,7 @@ CoreLayer::initAudioLayerIO(AudioDeviceType stream)
&size,
&playbackDeviceID);
}
// add listener for detecting when devices are removed
const AudioObjectPropertyAddress aliveAddress = {kAudioDevicePropertyDeviceIsAlive,
kAudioObjectPropertyScopeGlobal,
......@@ -182,6 +183,12 @@ CoreLayer::initAudioLayerIO(AudioDeviceType stream)
AudioObjectAddPropertyListener(playbackDeviceID, &aliveAddress, &deviceIsAliveCallback, this);
AudioObjectAddPropertyListener(inputDeviceID, &aliveAddress, &deviceIsAliveCallback, this);
// add listener to detect when devices changed
const AudioObjectPropertyAddress changedAddress = {kAudioHardwarePropertyDevices,
kAudioObjectPropertyScopeGlobal,
kAudioObjectPropertyElementMaster};
AudioObjectAddPropertyListener(kAudioObjectSystemObject, &changedAddress, &devicesChangedCallback, this);
// Set stream format
AudioStreamBasicDescription info;
size = sizeof(info);
......@@ -360,6 +367,18 @@ CoreLayer::deviceIsAliveCallback(AudioObjectID inObjectID,
return kAudioServicesNoError;
}
OSStatus
CoreLayer::devicesChangedCallback(AudioObjectID inObjectID,
UInt32 inNumberAddresses,
const AudioObjectPropertyAddress inAddresses[],
void* inRefCon)
{
if (static_cast<CoreLayer*>(inRefCon)->status_ != Status::Started)
return kAudioServicesNoError;
static_cast<CoreLayer*>(inRefCon)->devicesChanged();
return kAudioServicesNoError;
}
OSStatus
CoreLayer::outputCallback(void* inRefCon,
AudioUnitRenderActionFlags* ioActionFlags,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment