Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
de632882
Commit
de632882
authored
May 28, 2020
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
output/osx: move code to FindAudioDeviceByName()
parent
745e492d
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
41 deletions
+46
-41
OSXOutputPlugin.cxx
src/output/plugins/OSXOutputPlugin.cxx
+46
-41
No files found.
src/output/plugins/OSXOutputPlugin.cxx
View file @
de632882
...
...
@@ -542,16 +542,36 @@ osx_output_hog_device(AudioDeviceID dev_id, bool hog)
}
}
static
void
osx_output_set_device
(
OSXOutput
*
oo
)
gcc_pure
static
bool
IsAudioDeviceName
(
AudioDeviceID
id
,
const
char
*
expected_name
)
noexcept
{
OSStatus
status
;
UInt32
size
;
static
constexpr
AudioObjectPropertyAddress
aopa_name
{
kAudioObjectPropertyName
,
kAudioObjectPropertyScopeGlobal
,
kAudioObjectPropertyElementMaster
,
};
if
(
oo
->
component_subtype
!=
kAudioUnitSubType_HALOutput
)
return
;
CFStringRef
cfname
;
UInt32
size
=
sizeof
(
cfname
);
if
(
AudioObjectGetPropertyData
(
id
,
&
aopa_name
,
0
,
nullptr
,
&
size
,
&
cfname
)
!=
noErr
)
return
false
;
const
Apple
::
StringRef
cfname_
(
cfname
);
char
actual_name
[
256
];
if
(
!
cfname_
.
GetCString
(
actual_name
,
sizeof
(
actual_name
)))
return
false
;
return
StringIsEqual
(
actual_name
,
expected_name
);
}
static
AudioDeviceID
FindAudioDeviceByName
(
const
char
*
name
)
{
/* what are the available audio device IDs? */
static
constexpr
AudioObjectPropertyAddress
aopa_hw_devices
{
kAudioHardwarePropertyDevices
,
...
...
@@ -559,60 +579,45 @@ osx_output_set_device(OSXOutput *oo)
kAudioObjectPropertyElementMaster
,
};
const
auto
device
ids
=
const
auto
ids
=
AudioObjectGetPropertyDataArray
<
AudioDeviceID
>
(
kAudioObjectSystemObject
,
aopa_hw_devices
);
/* which audio device matches oo->device_name? */
static
constexpr
AudioObjectPropertyAddress
aopa_name
{
kAudioObjectPropertyName
,
kAudioObjectPropertyScopeGlobal
,
kAudioObjectPropertyElementMaster
,
};
for
(
const
auto
id
:
ids
)
{
if
(
IsAudioDeviceName
(
id
,
name
))
return
id
;
}
const
unsigned
numdevices
=
deviceids
.
size
();
unsigned
i
;
size
=
sizeof
(
CFStringRef
);
for
(
i
=
0
;
i
<
numdevices
;
i
++
)
{
CFStringRef
cfname
=
nullptr
;
status
=
AudioObjectGetPropertyData
(
deviceids
[
i
],
&
aopa_name
,
0
,
nullptr
,
&
size
,
&
cfname
);
if
(
status
!=
noErr
)
continue
;
throw
FormatRuntimeError
(
"Found no audio device with name '%s' "
,
name
);
}
const
Apple
::
StringRef
cfname_
(
cfname
);
static
void
osx_output_set_device
(
OSXOutput
*
oo
)
{
if
(
oo
->
component_subtype
!=
kAudioUnitSubType_HALOutput
)
return
;
char
name
[
256
];
if
(
!
cfname_
.
GetCString
(
name
,
sizeof
(
name
)))
continue
;
const
auto
id
=
FindAudioDeviceByName
(
oo
->
device_name
);
if
(
StringIsEqual
(
oo
->
device_name
,
name
))
{
FormatDebug
(
osx_output_domain
,
"found matching device: ID=%u, name=%s"
,
(
unsigned
)
deviceids
[
i
],
name
);
break
;
}
}
if
(
i
==
numdevices
)
throw
FormatRuntimeError
(
"Found no audio device with name '%s' "
,
oo
->
device_name
);
(
unsigned
)
id
,
oo
->
device_name
);
OSStatus
status
;
status
=
AudioUnitSetProperty
(
oo
->
au
,
kAudioOutputUnitProperty_CurrentDevice
,
kAudioUnitScope_Global
,
0
,
&
(
deviceids
[
i
]),
sizeof
(
AudioDeviceID
));
&
id
,
sizeof
(
id
));
if
(
status
!=
noErr
)
Apple
::
ThrowOSStatus
(
status
,
"Unable to set OS X audio output device"
);
oo
->
dev_id
=
deviceids
[
i
]
;
oo
->
dev_id
=
id
;
FormatDebug
(
osx_output_domain
,
"set OS X audio output device ID=%u, name=%s"
,
(
unsigned
)
deviceids
[
i
]
,
oo
->
device_name
);
(
unsigned
)
id
,
oo
->
device_name
);
if
(
oo
->
channel_map
)
osx_output_set_channel_map
(
oo
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment