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
3e93c392
Commit
3e93c392
authored
Mar 10, 2021
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
output/wasapi: make `enumerator` a local variable
parent
0a97e68a
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
14 deletions
+16
-14
WasapiOutputPlugin.cxx
src/output/plugins/wasapi/WasapiOutputPlugin.cxx
+16
-14
No files found.
src/output/plugins/wasapi/WasapiOutputPlugin.cxx
View file @
3e93c392
...
@@ -233,7 +233,6 @@ class WasapiOutput final : public AudioOutput {
...
@@ -233,7 +233,6 @@ class WasapiOutput final : public AudioOutput {
#endif
#endif
std
::
string
device_config
;
std
::
string
device_config
;
std
::
shared_ptr
<
COMWorker
>
com_worker
;
std
::
shared_ptr
<
COMWorker
>
com_worker
;
ComPtr
<
IMMDeviceEnumerator
>
enumerator
;
ComPtr
<
IMMDevice
>
device
;
ComPtr
<
IMMDevice
>
device
;
ComPtr
<
IAudioClient
>
client
;
ComPtr
<
IAudioClient
>
client
;
WAVEFORMATEXTENSIBLE
device_format
;
WAVEFORMATEXTENSIBLE
device_format
;
...
@@ -293,9 +292,11 @@ private:
...
@@ -293,9 +292,11 @@ private:
bool
TryFormatExclusive
(
const
AudioFormat
&
audio_format
);
bool
TryFormatExclusive
(
const
AudioFormat
&
audio_format
);
void
FindExclusiveFormatSupported
(
AudioFormat
&
audio_format
);
void
FindExclusiveFormatSupported
(
AudioFormat
&
audio_format
);
void
FindSharedFormatSupported
(
AudioFormat
&
audio_format
);
void
FindSharedFormatSupported
(
AudioFormat
&
audio_format
);
void
EnumerateDevices
();
static
void
EnumerateDevices
(
IMMDeviceEnumerator
&
enumerator
);
ComPtr
<
IMMDevice
>
GetDevice
(
unsigned
int
index
);
static
ComPtr
<
IMMDevice
>
GetDevice
(
IMMDeviceEnumerator
&
enumerator
,
ComPtr
<
IMMDevice
>
SearchDevice
(
std
::
string_view
name
);
unsigned
index
);
static
ComPtr
<
IMMDevice
>
SearchDevice
(
IMMDeviceEnumerator
&
enumerator
,
std
::
string_view
name
);
};
};
WasapiOutput
&
WasapiOutput
&
...
@@ -434,7 +435,6 @@ WasapiOutput::DoDisable() noexcept
...
@@ -434,7 +435,6 @@ WasapiOutput::DoDisable() noexcept
assert
(
!
thread
);
assert
(
!
thread
);
device
.
reset
();
device
.
reset
();
enumerator
.
reset
();
}
}
/// run inside COMWorkerThread
/// run inside COMWorkerThread
...
@@ -695,12 +695,13 @@ WasapiOutput::Cancel() noexcept
...
@@ -695,12 +695,13 @@ WasapiOutput::Cancel() noexcept
void
void
WasapiOutput
::
OpenDevice
()
WasapiOutput
::
OpenDevice
()
{
{
ComPtr
<
IMMDeviceEnumerator
>
enumerator
;
enumerator
.
CoCreateInstance
(
__uuidof
(
MMDeviceEnumerator
),
nullptr
,
enumerator
.
CoCreateInstance
(
__uuidof
(
MMDeviceEnumerator
),
nullptr
,
CLSCTX_INPROC_SERVER
);
CLSCTX_INPROC_SERVER
);
if
(
enumerate_devices
)
{
if
(
enumerate_devices
)
{
try
{
try
{
EnumerateDevices
();
EnumerateDevices
(
*
enumerator
);
}
catch
(...)
{
}
catch
(...)
{
LogError
(
std
::
current_exception
());
LogError
(
std
::
current_exception
());
}
}
...
@@ -709,12 +710,12 @@ WasapiOutput::OpenDevice()
...
@@ -709,12 +710,12 @@ WasapiOutput::OpenDevice()
if
(
!
device_config
.
empty
())
{
if
(
!
device_config
.
empty
())
{
unsigned
int
id
;
unsigned
int
id
;
if
(
!
SafeSilenceTry
([
this
,
&
id
]()
{
id
=
std
::
stoul
(
device_config
);
}))
{
if
(
!
SafeSilenceTry
([
this
,
&
id
]()
{
id
=
std
::
stoul
(
device_config
);
}))
{
device
=
SearchDevice
(
device_config
);
device
=
SearchDevice
(
*
enumerator
,
device_config
);
if
(
!
device
)
if
(
!
device
)
throw
FormatRuntimeError
(
"Device '%s' not found"
,
throw
FormatRuntimeError
(
"Device '%s' not found"
,
device_config
.
c_str
());
device_config
.
c_str
());
}
else
}
else
device
=
GetDevice
(
id
);
device
=
GetDevice
(
*
enumerator
,
id
);
}
else
{
}
else
{
device
=
GetDefaultAudioEndpoint
(
*
enumerator
);
device
=
GetDefaultAudioEndpoint
(
*
enumerator
);
}
}
...
@@ -915,9 +916,9 @@ WasapiOutput::FindSharedFormatSupported(AudioFormat &audio_format)
...
@@ -915,9 +916,9 @@ WasapiOutput::FindSharedFormatSupported(AudioFormat &audio_format)
/// run inside COMWorkerThread
/// run inside COMWorkerThread
void
void
WasapiOutput
::
EnumerateDevices
()
WasapiOutput
::
EnumerateDevices
(
IMMDeviceEnumerator
&
enumerator
)
{
{
const
auto
device_collection
=
EnumAudioEndpoints
(
*
enumerator
);
const
auto
device_collection
=
EnumAudioEndpoints
(
enumerator
);
const
UINT
count
=
GetCount
(
*
device_collection
);
const
UINT
count
=
GetCount
(
*
device_collection
);
for
(
UINT
i
=
0
;
i
<
count
;
++
i
)
{
for
(
UINT
i
=
0
;
i
<
count
;
++
i
)
{
...
@@ -938,17 +939,18 @@ WasapiOutput::EnumerateDevices()
...
@@ -938,17 +939,18 @@ WasapiOutput::EnumerateDevices()
/// run inside COMWorkerThread
/// run inside COMWorkerThread
ComPtr
<
IMMDevice
>
ComPtr
<
IMMDevice
>
WasapiOutput
::
GetDevice
(
unsigned
int
index
)
WasapiOutput
::
GetDevice
(
IMMDeviceEnumerator
&
enumerator
,
unsigned
index
)
{
{
const
auto
device_collection
=
EnumAudioEndpoints
(
*
enumerator
);
const
auto
device_collection
=
EnumAudioEndpoints
(
enumerator
);
return
Item
(
*
device_collection
,
index
);
return
Item
(
*
device_collection
,
index
);
}
}
/// run inside COMWorkerThread
/// run inside COMWorkerThread
ComPtr
<
IMMDevice
>
ComPtr
<
IMMDevice
>
WasapiOutput
::
SearchDevice
(
std
::
string_view
name
)
WasapiOutput
::
SearchDevice
(
IMMDeviceEnumerator
&
enumerator
,
std
::
string_view
name
)
{
{
const
auto
device_collection
=
EnumAudioEndpoints
(
*
enumerator
);
const
auto
device_collection
=
EnumAudioEndpoints
(
enumerator
);
const
UINT
count
=
GetCount
(
*
device_collection
);
const
UINT
count
=
GetCount
(
*
device_collection
);
for
(
UINT
i
=
0
;
i
<
count
;
++
i
)
{
for
(
UINT
i
=
0
;
i
<
count
;
++
i
)
{
...
...
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