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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
jami-daemon
Commits
2269b76f
Commit
2269b76f
authored
Feb 11, 2022
by
Kateryna Kostiuk
Committed by
Kateryna Kostiuk
Feb 11, 2022
Browse files
Options
Downloads
Patches
Plain Diff
coreaudio: handle the case when no audio device is connected
jami-client-qt#671
Change-Id: If0f2237042c746214cadb33ef8e56c22fe327a37
parent
7634487e
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/media/audio/coreaudio/osx/corelayer.mm
+64
-45
64 additions, 45 deletions
src/media/audio/coreaudio/osx/corelayer.mm
with
64 additions
and
45 deletions
src/media/audio/coreaudio/osx/corelayer.mm
+
64
−
45
View file @
2269b76f
...
@@ -104,13 +104,6 @@ CoreLayer::initAudioLayerIO(AudioDeviceType stream)
...
@@ -104,13 +104,6 @@ CoreLayer::initAudioLayerIO(AudioDeviceType stream)
// 5) Profit...
// 5) Profit...
JAMI_DBG
(
"INIT AUDIO IO"
);
JAMI_DBG
(
"INIT AUDIO IO"
);
// get capture divice
auto
captureList
=
getDeviceList
(
true
);
AudioDeviceID
inputDeviceID
=
captureList
[
indexIn_
].
id_
;
// get playback device
auto
playbackList
=
getDeviceList
(
false
);
AudioDeviceID
playbackDeviceID
=
playbackList
[
indexOut_
].
id_
;
AudioUnitScope
outputBus
=
0
;
AudioUnitScope
outputBus
=
0
;
AudioUnitScope
inputBus
=
1
;
AudioUnitScope
inputBus
=
1
;
AudioComponentDescription
desc
=
{
0
};
AudioComponentDescription
desc
=
{
0
};
...
@@ -134,16 +127,26 @@ CoreLayer::initAudioLayerIO(AudioDeviceType stream)
...
@@ -134,16 +127,26 @@ CoreLayer::initAudioLayerIO(AudioDeviceType stream)
return
;
return
;
}
}
// set capture device
AudioDeviceID
inputDeviceID
;
UInt32
size
=
sizeof
(
inputDeviceID
);
AudioDeviceID
playbackDeviceID
;
UInt32
size
=
sizeof
(
AudioDeviceID
);
if
(
stream
==
AudioDeviceType
::
CAPTURE
||
stream
==
AudioDeviceType
::
ALL
)
{
auto
captureList
=
getDeviceList
(
true
);
bool
useFallbackDevice
=
true
;
// try to set the device selected by the user. Otherwise, the default device will be set automatically.
if
(
indexIn_
<
captureList
.
size
())
{
inputDeviceID
=
captureList
[
indexIn_
].
id_
;
auto
error
=
AudioUnitSetProperty
(
ioUnit_
,
auto
error
=
AudioUnitSetProperty
(
ioUnit_
,
kAudioOutputUnitProperty_CurrentDevice
,
kAudioOutputUnitProperty_CurrentDevice
,
kAudioUnitScope_Global
,
kAudioUnitScope_Global
,
inputBus
,
inputBus
,
&
inputDeviceID
,
&
inputDeviceID
,
size
);
size
);
// if failed get default device
useFallbackDevice
=
error
!=
kAudioServicesNoError
;
if
(
error
!=
kAudioServicesNoError
)
{
}
// get a fallback capture device id so we could listen when the device disconnect.
if
(
useFallbackDevice
)
{
const
AudioObjectPropertyAddress
inputInfo
=
{
kAudioHardwarePropertyDefaultInputDevice
,
const
AudioObjectPropertyAddress
inputInfo
=
{
kAudioHardwarePropertyDefaultInputDevice
,
kAudioObjectPropertyScopeGlobal
,
kAudioObjectPropertyScopeGlobal
,
kAudioObjectPropertyElementMaster
};
kAudioObjectPropertyElementMaster
};
...
@@ -153,18 +156,29 @@ CoreLayer::initAudioLayerIO(AudioDeviceType stream)
...
@@ -153,18 +156,29 @@ CoreLayer::initAudioLayerIO(AudioDeviceType stream)
NULL
,
NULL
,
&
size
,
&
size
,
&
inputDeviceID
);
&
inputDeviceID
);
if
(
status
!=
kAudioServicesNoError
)
{
JAMI_ERR
()
<<
"failed to set audio input device"
;
return
;
}
}
}
}
// set playback device
if
(
stream
==
AudioDeviceType
::
PLAYBACK
||
stream
==
AudioDeviceType
::
ALL
||
stream
==
AudioDeviceType
::
RINGTONE
)
{
size
=
sizeof
(
playbackDeviceID
);
auto
playbackList
=
getDeviceList
(
false
);
error
=
AudioUnitSetProperty
(
ioUnit_
,
auto
index
=
stream
==
AudioDeviceType
::
RINGTONE
?
indexRing_
:
indexOut_
;
bool
useFallbackDevice
=
true
;
if
(
index
<
playbackList
.
size
())
{
playbackDeviceID
=
playbackList
[
index
].
id_
;
auto
error
=
AudioUnitSetProperty
(
ioUnit_
,
kAudioOutputUnitProperty_CurrentDevice
,
kAudioOutputUnitProperty_CurrentDevice
,
kAudioUnitScope_Global
,
kAudioUnitScope_Global
,
outputBus
,
outputBus
,
&
playbackDeviceID
,
&
playbackDeviceID
,
size
);
size
);
// if failed get default device
useFallbackDevice
=
error
!=
kAudioServicesNoError
;
if
(
error
!=
kAudioServicesNoError
)
{
}
// get fallback output device id.
if
(
useFallbackDevice
)
{
const
AudioObjectPropertyAddress
outputInfo
=
{
kAudioHardwarePropertyDefaultOutputDevice
,
const
AudioObjectPropertyAddress
outputInfo
=
{
kAudioHardwarePropertyDefaultOutputDevice
,
kAudioObjectPropertyScopeGlobal
,
kAudioObjectPropertyScopeGlobal
,
kAudioObjectPropertyElementMaster
};
kAudioObjectPropertyElementMaster
};
...
@@ -174,6 +188,11 @@ CoreLayer::initAudioLayerIO(AudioDeviceType stream)
...
@@ -174,6 +188,11 @@ CoreLayer::initAudioLayerIO(AudioDeviceType stream)
NULL
,
NULL
,
&
size
,
&
size
,
&
playbackDeviceID
);
&
playbackDeviceID
);
if
(
status
!=
kAudioServicesNoError
)
{
JAMI_ERR
()
<<
"failed to set audio output device"
;
return
;
}
}
}
}
// add listener for detecting when devices are removed
// add listener for detecting when devices are removed
...
...
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
sign in
to comment