Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
jami-daemon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
jami-daemon
Commits
deb597fd
Commit
deb597fd
authored
4 years ago
by
Kateryna Kostiuk
Committed by
Adrien Béraud
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
audio macOS: restart audio when device disconnected
Change-Id: Iebfebf26ea4e3851d714f2b14da90b8f1d30ee35
parent
73f602fc
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/media/audio/coreaudio/osx/corelayer.cpp
+62
-14
62 additions, 14 deletions
src/media/audio/coreaudio/osx/corelayer.cpp
src/media/audio/coreaudio/osx/corelayer.h
+4
-0
4 additions, 0 deletions
src/media/audio/coreaudio/osx/corelayer.h
with
66 additions
and
14 deletions
src/media/audio/coreaudio/osx/corelayer.cpp
+
62
−
14
View file @
deb597fd
...
...
@@ -98,10 +98,10 @@ CoreLayer::initAudioLayerIO()
//get capture divice
auto
captureList
=
getDeviceList
(
true
);
auto
inputDeviceID
=
captureList
[
indexIn_
].
id_
;
AudioDeviceID
inputDeviceID
=
captureList
[
indexIn_
].
id_
;
//get playback device
auto
playbackList
=
getDeviceList
(
false
);
auto
playbackDeviceID
=
playbackList
[
indexOut_
].
id_
;
AudioDeviceID
playbackDeviceID
=
playbackList
[
indexOut_
].
id_
;
AudioUnitScope
outputBus
=
0
;
AudioUnitScope
inputBus
=
1
;
...
...
@@ -124,21 +124,56 @@ CoreLayer::initAudioLayerIO()
//set capture device
UInt32
size
=
sizeof
(
inputDeviceID
);
AudioUnitSetProperty
(
ioUnit_
,
kAudioOutputUnitProperty_CurrentDevice
,
kAudioUnitScope_Global
,
inputBus
,
&
inputDeviceID
,
size
);
auto
error
=
AudioUnitSetProperty
(
ioUnit_
,
kAudioOutputUnitProperty_CurrentDevice
,
kAudioUnitScope_Global
,
inputBus
,
&
inputDeviceID
,
size
);
//if failed get default device
if
(
error
!=
kAudioServicesNoError
)
{
const
AudioObjectPropertyAddress
inputInfo
=
{
kAudioHardwarePropertyDefaultInputDevice
,
kAudioObjectPropertyScopeGlobal
,
kAudioObjectPropertyElementMaster
};
auto
status
=
AudioObjectGetPropertyData
(
kAudioObjectSystemObject
,
&
inputInfo
,
0
,
NULL
,
&
size
,
&
inputDeviceID
);
}
//set playback device
size
=
sizeof
(
playbackDeviceID
);
AudioUnitSetProperty
(
ioUnit_
,
kAudioOutputUnitProperty_CurrentDevice
,
kAudioUnitScope_Global
,
outputBus
,
&
playbackDeviceID
,
size
);
error
=
AudioUnitSetProperty
(
ioUnit_
,
kAudioOutputUnitProperty_CurrentDevice
,
kAudioUnitScope_Global
,
outputBus
,
&
playbackDeviceID
,
size
);
//if failed get default device
if
(
error
!=
kAudioServicesNoError
)
{
const
AudioObjectPropertyAddress
outputInfo
=
{
kAudioHardwarePropertyDefaultOutputDevice
,
kAudioObjectPropertyScopeGlobal
,
kAudioObjectPropertyElementMaster
};
auto
status
=
AudioObjectGetPropertyData
(
kAudioObjectSystemObject
,
&
outputInfo
,
0
,
NULL
,
&
size
,
&
playbackDeviceID
);
}
// add listener for detecting when devices are removed
const
AudioObjectPropertyAddress
aliveAddress
=
{
kAudioDevicePropertyDeviceIsAlive
,
kAudioObjectPropertyScopeGlobal
,
kAudioObjectPropertyElementMaster
};
AudioObjectAddPropertyListener
(
playbackDeviceID
,
&
aliveAddress
,
&
deviceIsAliveCallback
,
this
);
AudioObjectAddPropertyListener
(
inputDeviceID
,
&
aliveAddress
,
&
deviceIsAliveCallback
,
this
);
// Set stream format
AudioStreamBasicDescription
info
;
...
...
@@ -307,6 +342,19 @@ CoreLayer::stopStream()
//// PRIVATE /////
OSStatus
CoreLayer
::
deviceIsAliveCallback
(
AudioObjectID
inObjectID
,
UInt32
inNumberAddresses
,
const
AudioObjectPropertyAddress
inAddresses
[],
void
*
inRefCon
)
{
if
(
static_cast
<
CoreLayer
*>
(
inRefCon
)
->
status_
!=
Status
::
Started
)
return
kAudioServicesNoError
;
static_cast
<
CoreLayer
*>
(
inRefCon
)
->
stopStream
();
static_cast
<
CoreLayer
*>
(
inRefCon
)
->
startStream
();
return
kAudioServicesNoError
;
}
OSStatus
CoreLayer
::
outputCallback
(
void
*
inRefCon
,
AudioUnitRenderActionFlags
*
ioActionFlags
,
...
...
This diff is collapsed.
Click to expand it.
src/media/audio/coreaudio/osx/corelayer.h
+
4
−
0
View file @
deb597fd
...
...
@@ -134,6 +134,10 @@ class CoreLayer : public AudioLayer {
UInt32
inBusNumber
,
UInt32
inNumberFrames
,
AudioBufferList
*
ioData
);
static
OSStatus
deviceIsAliveCallback
(
AudioObjectID
inObjectID
,
UInt32
inNumberAddresses
,
const
AudioObjectPropertyAddress
inAddresses
[],
void
*
inRefCon
);
void
read
(
AudioUnitRenderActionFlags
*
ioActionFlags
,
const
AudioTimeStamp
*
inTimeStamp
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment