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
fee75dc7
Commit
fee75dc7
authored
Nov 08, 2018
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
{output,mixer}/alsa: use snd_pcm_poll_descriptors_revents()
This call was missing, causing very high CPU usage when the ALSA output plugin was used with dmix. Closes #391
parent
ba5c856f
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
67 additions
and
0 deletions
+67
-0
NEWS
NEWS
+1
-0
AlsaInputPlugin.cxx
src/input/plugins/AlsaInputPlugin.cxx
+2
-0
NonBlock.cxx
src/lib/alsa/NonBlock.cxx
+48
-0
NonBlock.hxx
src/lib/alsa/NonBlock.hxx
+12
-0
AlsaMixerPlugin.cxx
src/mixer/plugins/AlsaMixerPlugin.cxx
+2
-0
AlsaOutputPlugin.cxx
src/output/plugins/AlsaOutputPlugin.cxx
+2
-0
No files found.
NEWS
View file @
fee75dc7
...
...
@@ -3,6 +3,7 @@ ver 0.21.2 (not yet released)
- ffmpeg: require FFmpeg 3.1 or later
- ffmpeg: fix broken sound with certain codecs
* output
- alsa: fix high CPU usage with dmix
- httpd: fix two crash bugs
* mixer
- alsa: fix more rounding errors
...
...
src/input/plugins/AlsaInputPlugin.cxx
View file @
fee75dc7
...
...
@@ -185,6 +185,8 @@ AlsaInputStream::PrepareSockets() noexcept
void
AlsaInputStream
::
DispatchSockets
()
noexcept
{
non_block
.
DispatchSockets
(
*
this
,
capture_handle
);
const
std
::
lock_guard
<
Mutex
>
protect
(
mutex
);
auto
w
=
PrepareWriteBuffer
();
...
...
src/lib/alsa/NonBlock.cxx
View file @
fee75dc7
...
...
@@ -49,6 +49,30 @@ AlsaNonBlockPcm::PrepareSockets(MultiSocketMonitor &m, snd_pcm_t *pcm)
return
std
::
chrono
::
steady_clock
::
duration
(
-
1
);
}
void
AlsaNonBlockPcm
::
DispatchSockets
(
MultiSocketMonitor
&
m
,
snd_pcm_t
*
pcm
)
noexcept
{
int
count
=
snd_pcm_poll_descriptors_count
(
pcm
);
if
(
count
<=
0
)
return
;
const
auto
pfds
=
pfd_buffer
.
Get
(
count
),
end
=
pfds
+
count
;
auto
*
i
=
pfds
;
m
.
ForEachReturnedEvent
([
&
i
,
end
](
SocketDescriptor
s
,
unsigned
events
){
if
(
i
>=
end
)
return
;
i
->
fd
=
s
.
Get
();
i
->
events
=
i
->
revents
=
events
;
++
i
;
});
unsigned
short
dummy
;
snd_pcm_poll_descriptors_revents
(
pcm
,
pfds
,
i
-
pfds
,
&
dummy
);
}
std
::
chrono
::
steady_clock
::
duration
AlsaNonBlockMixer
::
PrepareSockets
(
MultiSocketMonitor
&
m
,
snd_mixer_t
*
mixer
)
noexcept
{
...
...
@@ -67,3 +91,27 @@ AlsaNonBlockMixer::PrepareSockets(MultiSocketMonitor &m, snd_mixer_t *mixer) noe
m
.
ReplaceSocketList
(
pfds
,
count
);
return
std
::
chrono
::
steady_clock
::
duration
(
-
1
);
}
void
AlsaNonBlockMixer
::
DispatchSockets
(
MultiSocketMonitor
&
m
,
snd_mixer_t
*
mixer
)
noexcept
{
int
count
=
snd_mixer_poll_descriptors_count
(
mixer
);
if
(
count
<=
0
)
return
;
const
auto
pfds
=
pfd_buffer
.
Get
(
count
),
end
=
pfds
+
count
;
auto
*
i
=
pfds
;
m
.
ForEachReturnedEvent
([
&
i
,
end
](
SocketDescriptor
s
,
unsigned
events
){
if
(
i
>=
end
)
return
;
i
->
fd
=
s
.
Get
();
i
->
events
=
i
->
revents
=
events
;
++
i
;
});
unsigned
short
dummy
;
snd_mixer_poll_descriptors_revents
(
mixer
,
pfds
,
i
-
pfds
,
&
dummy
);
}
src/lib/alsa/NonBlock.hxx
View file @
fee75dc7
...
...
@@ -42,6 +42,12 @@ public:
*/
std
::
chrono
::
steady_clock
::
duration
PrepareSockets
(
MultiSocketMonitor
&
m
,
snd_pcm_t
*
pcm
);
/**
* Wrapper for snd_pcm_poll_descriptors_revents(), to be
* called from MultiSocketMonitor::DispatchSockets().
*/
void
DispatchSockets
(
MultiSocketMonitor
&
m
,
snd_pcm_t
*
pcm
)
noexcept
;
};
/**
...
...
@@ -54,6 +60,12 @@ class AlsaNonBlockMixer {
public
:
std
::
chrono
::
steady_clock
::
duration
PrepareSockets
(
MultiSocketMonitor
&
m
,
snd_mixer_t
*
mixer
)
noexcept
;
/**
* Wrapper for snd_mixer_poll_descriptors_revents(), to be
* called from MultiSocketMonitor::DispatchSockets().
*/
void
DispatchSockets
(
MultiSocketMonitor
&
m
,
snd_mixer_t
*
mixer
)
noexcept
;
};
#endif
src/mixer/plugins/AlsaMixerPlugin.cxx
View file @
fee75dc7
...
...
@@ -117,6 +117,8 @@ AlsaMixerMonitor::DispatchSockets() noexcept
{
assert
(
mixer
!=
nullptr
);
non_block
.
DispatchSockets
(
*
this
,
mixer
);
int
err
=
snd_mixer_handle_events
(
mixer
);
if
(
err
<
0
)
{
FormatError
(
alsa_mixer_domain
,
...
...
src/output/plugins/AlsaOutputPlugin.cxx
View file @
fee75dc7
...
...
@@ -889,6 +889,8 @@ AlsaOutput::PrepareSockets() noexcept
void
AlsaOutput
::
DispatchSockets
()
noexcept
try
{
non_block
.
DispatchSockets
(
*
this
,
pcm
);
{
const
std
::
lock_guard
<
Mutex
>
lock
(
mutex
);
...
...
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