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
2101daef
Commit
2101daef
authored
Jan 15, 2013
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mixer/Alsa: use MultiSocketMonitor
parent
083065f4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
55 additions
and
134 deletions
+55
-134
Makefile.am
Makefile.am
+2
-0
AlsaMixerPlugin.cxx
src/mixer/AlsaMixerPlugin.cxx
+37
-134
read_mixer.cxx
test/read_mixer.cxx
+8
-0
run_output.cxx
test/run_output.cxx
+8
-0
No files found.
Makefile.am
View file @
2101daef
...
@@ -1276,6 +1276,7 @@ test_run_output_LDADD = $(MPD_LIBS) \
...
@@ -1276,6 +1276,7 @@ test_run_output_LDADD = $(MPD_LIBS) \
$(ENCODER_LIBS)
\
$(ENCODER_LIBS)
\
libmixer_plugins.a
\
libmixer_plugins.a
\
$(FILTER_LIBS)
\
$(FILTER_LIBS)
\
libevent.a
\
libutil.a
\
libutil.a
\
$(GLIB_LIBS)
$(GLIB_LIBS)
test_run_output_SOURCES
=
test
/run_output.cxx
\
test_run_output_SOURCES
=
test
/run_output.cxx
\
...
@@ -1307,6 +1308,7 @@ test_read_mixer_LDADD = \
...
@@ -1307,6 +1308,7 @@ test_read_mixer_LDADD = \
libpcm.a
\
libpcm.a
\
libmixer_plugins.a
\
libmixer_plugins.a
\
$(OUTPUT_LIBS)
\
$(OUTPUT_LIBS)
\
libevent.a
\
$(GLIB_LIBS)
$(GLIB_LIBS)
test_read_mixer_SOURCES
=
test
/read_mixer.c
\
test_read_mixer_SOURCES
=
test
/read_mixer.c
\
src/ConfigFile.cxx src/tokenizer.c src/utils.c src/string_util.c
\
src/ConfigFile.cxx src/tokenizer.c src/utils.c src/string_util.c
\
...
...
src/mixer/AlsaMixerPlugin.cxx
View file @
2101daef
...
@@ -21,6 +21,10 @@
...
@@ -21,6 +21,10 @@
#include "mixer_api.h"
#include "mixer_api.h"
#include "output_api.h"
#include "output_api.h"
#include "GlobalEvents.hxx"
#include "GlobalEvents.hxx"
#include "Main.hxx"
#include "event/MultiSocketMonitor.hxx"
#include <algorithm>
#include <glib.h>
#include <glib.h>
#include <alsa/asoundlib.h>
#include <alsa/asoundlib.h>
...
@@ -29,13 +33,16 @@
...
@@ -29,13 +33,16 @@
#define VOLUME_MIXER_ALSA_CONTROL_DEFAULT "PCM"
#define VOLUME_MIXER_ALSA_CONTROL_DEFAULT "PCM"
#define VOLUME_MIXER_ALSA_INDEX_DEFAULT 0
#define VOLUME_MIXER_ALSA_INDEX_DEFAULT 0
struct
alsa_mixer_source
{
class
AlsaMixerMonitor
final
:
private
MultiSocketMonitor
{
GSource
source
;
snd_mixer_t
*
const
mixer
;
snd_mixer_t
*
mixer
;
public
:
AlsaMixerMonitor
(
EventLoop
&
_loop
,
snd_mixer_t
*
_mixer
)
:
MultiSocketMonitor
(
_loop
),
mixer
(
_mixer
)
{}
/** a linked list of all registered GPollFD objects */
private
:
GSList
*
fds
;
virtual
void
PrepareSockets
(
gcc_unused
gint
*
timeout_r
)
override
;
virtual
void
DispatchSockets
()
override
;
};
};
struct
alsa_mixer
{
struct
alsa_mixer
{
...
@@ -52,7 +59,7 @@ struct alsa_mixer {
...
@@ -52,7 +59,7 @@ struct alsa_mixer {
long
volume_max
;
long
volume_max
;
int
volume_set
;
int
volume_set
;
struct
alsa_mixer_source
*
source
;
AlsaMixerMonitor
*
monitor
;
};
};
/**
/**
...
@@ -64,144 +71,45 @@ alsa_mixer_quark(void)
...
@@ -64,144 +71,45 @@ alsa_mixer_quark(void)
return
g_quark_from_static_string
(
"alsa_mixer"
);
return
g_quark_from_static_string
(
"alsa_mixer"
);
}
}
/*
void
* GSource helper functions
AlsaMixerMonitor
::
PrepareSockets
(
gcc_unused
gint
*
timeout_r
)
*
*/
static
GSList
**
find_fd
(
GSList
**
list_r
,
int
fd
)
{
while
(
true
)
{
GSList
*
list
=
*
list_r
;
if
(
list
==
NULL
)
return
NULL
;
GPollFD
*
p
=
(
GPollFD
*
)
list
->
data
;
if
(
p
->
fd
==
fd
)
return
list_r
;
list_r
=
&
list
->
next
;
}
}
static
void
alsa_mixer_update_fd
(
struct
alsa_mixer_source
*
source
,
const
struct
pollfd
*
p
,
GSList
**
old_r
)
{
GSList
**
found_r
=
find_fd
(
old_r
,
p
->
fd
);
if
(
found_r
==
NULL
)
{
/* new fd */
GPollFD
*
q
=
g_new
(
GPollFD
,
1
);
q
->
fd
=
p
->
fd
;
q
->
events
=
p
->
events
;
g_source_add_poll
(
&
source
->
source
,
q
);
source
->
fds
=
g_slist_prepend
(
source
->
fds
,
q
);
return
;
}
GSList
*
found
=
*
found_r
;
*
found_r
=
found
->
next
;
GPollFD
*
q
=
(
GPollFD
*
)
found
->
data
;
if
(
q
->
events
!=
p
->
events
)
{
/* refresh events */
g_source_remove_poll
(
&
source
->
source
,
q
);
q
->
events
=
p
->
events
;
g_source_add_poll
(
&
source
->
source
,
q
);
}
found
->
next
=
source
->
fds
;
source
->
fds
=
found
;
}
static
void
alsa_mixer_update_fds
(
struct
alsa_mixer_source
*
source
)
{
{
int
count
=
snd_mixer_poll_descriptors_count
(
source
->
mixer
);
int
count
=
snd_mixer_poll_descriptors_count
(
mixer
);
if
(
count
<
0
)
if
(
count
<
0
)
count
=
0
;
count
=
0
;
struct
pollfd
*
pfds
=
g_new
(
struct
pollfd
,
count
);
struct
pollfd
*
pfds
=
g_new
(
struct
pollfd
,
count
);
count
=
snd_mixer_poll_descriptors
(
source
->
mixer
,
pfds
,
count
);
count
=
snd_mixer_poll_descriptors
(
mixer
,
pfds
,
count
);
if
(
count
<
0
)
if
(
count
<
0
)
count
=
0
;
count
=
0
;
GSList
*
old
=
source
->
fds
;
struct
pollfd
*
end
=
pfds
+
count
;
source
->
fds
=
NULL
;
for
(
int
i
=
0
;
i
<
count
;
++
i
)
UpdateSocketList
([
pfds
,
end
](
int
fd
)
->
unsigned
{
alsa_mixer_update_fd
(
source
,
&
pfds
[
i
],
&
old
);
auto
i
=
std
::
find_if
(
pfds
,
end
,
[
fd
](
const
struct
pollfd
&
pfd
){
g_free
(
pfds
);
return
pfd
.
fd
==
fd
;
});
if
(
i
==
end
)
return
0
;
for
(;
old
!=
NULL
;
old
=
old
->
next
)
{
auto
events
=
i
->
events
;
GPollFD
*
q
=
(
GPollFD
*
)
old
->
data
;
i
->
events
=
0
;
g_source_remove_poll
(
&
source
->
source
,
q
);
return
events
;
g_free
(
q
);
});
}
g_slist_free
(
old
);
for
(
auto
i
=
pfds
;
i
!=
end
;
++
i
)
}
if
(
i
->
events
!=
0
)
AddSocket
(
i
->
fd
,
i
->
events
);
/*
g_free
(
pfds
);
* GSource methods
*
*/
static
gboolean
alsa_mixer_source_prepare
(
GSource
*
_source
,
G_GNUC_UNUSED
gint
*
timeout_r
)
{
struct
alsa_mixer_source
*
source
=
(
struct
alsa_mixer_source
*
)
_source
;
alsa_mixer_update_fds
(
source
);
return
false
;
}
static
gboolean
alsa_mixer_source_check
(
GSource
*
_source
)
{
struct
alsa_mixer_source
*
source
=
(
struct
alsa_mixer_source
*
)
_source
;
for
(
const
GSList
*
i
=
source
->
fds
;
i
!=
NULL
;
i
=
i
->
next
)
{
const
GPollFD
*
poll_fd
=
(
GPollFD
*
)
i
->
data
;
if
(
poll_fd
->
revents
!=
0
)
return
true
;
}
return
false
;
}
}
static
gboolean
void
alsa_mixer_source_dispatch
(
GSource
*
_source
,
AlsaMixerMonitor
::
DispatchSockets
()
G_GNUC_UNUSED
GSourceFunc
callback
,
G_GNUC_UNUSED
gpointer
user_data
)
{
{
struct
alsa_mixer_source
*
source
=
(
struct
alsa_mixer_source
*
)
_source
;
snd_mixer_handle_events
(
mixer
);
snd_mixer_handle_events
(
source
->
mixer
);
return
true
;
}
}
static
void
alsa_mixer_source_finalize
(
GSource
*
_source
)
{
struct
alsa_mixer_source
*
source
=
(
struct
alsa_mixer_source
*
)
_source
;
for
(
GSList
*
i
=
source
->
fds
;
i
!=
NULL
;
i
=
i
->
next
)
g_free
(
i
->
data
);
g_slist_free
(
source
->
fds
);
}
static
GSourceFuncs
alsa_mixer_source_funcs
=
{
alsa_mixer_source_prepare
,
alsa_mixer_source_check
,
alsa_mixer_source_dispatch
,
alsa_mixer_source_finalize
,
nullptr
,
nullptr
,
};
/*
/*
* libasound callbacks
* libasound callbacks
*
*
...
@@ -306,11 +214,7 @@ alsa_mixer_setup(struct alsa_mixer *am, GError **error_r)
...
@@ -306,11 +214,7 @@ alsa_mixer_setup(struct alsa_mixer *am, GError **error_r)
snd_mixer_elem_set_callback
(
am
->
elem
,
alsa_mixer_elem_callback
);
snd_mixer_elem_set_callback
(
am
->
elem
,
alsa_mixer_elem_callback
);
am
->
source
=
(
struct
alsa_mixer_source
*
)
am
->
monitor
=
new
AlsaMixerMonitor
(
*
main_loop
,
am
->
handle
);
g_source_new
(
&
alsa_mixer_source_funcs
,
sizeof
(
*
am
->
source
));
am
->
source
->
mixer
=
am
->
handle
;
am
->
source
->
fds
=
NULL
;
g_source_attach
(
&
am
->
source
->
source
,
g_main_context_default
());
return
true
;
return
true
;
}
}
...
@@ -345,8 +249,7 @@ alsa_mixer_close(struct mixer *data)
...
@@ -345,8 +249,7 @@ alsa_mixer_close(struct mixer *data)
assert
(
am
->
handle
!=
NULL
);
assert
(
am
->
handle
!=
NULL
);
g_source_destroy
(
&
am
->
source
->
source
);
delete
am
->
monitor
;
g_source_unref
(
&
am
->
source
->
source
);
snd_mixer_elem_set_callback
(
am
->
elem
,
NULL
);
snd_mixer_elem_set_callback
(
am
->
elem
,
NULL
);
snd_mixer_close
(
am
->
handle
);
snd_mixer_close
(
am
->
handle
);
...
...
test/read_mixer.cxx
View file @
2101daef
...
@@ -27,6 +27,8 @@ extern "C" {
...
@@ -27,6 +27,8 @@ extern "C" {
#include "pcm_volume.h"
#include "pcm_volume.h"
#include "GlobalEvents.hxx"
#include "GlobalEvents.hxx"
#include "Main.hxx"
#include "event/Loop.hxx"
#include <glib.h>
#include <glib.h>
...
@@ -34,6 +36,8 @@ extern "C" {
...
@@ -34,6 +36,8 @@ extern "C" {
#include <string.h>
#include <string.h>
#include <unistd.h>
#include <unistd.h>
EventLoop
*
main_loop
;
#ifdef HAVE_PULSE
#ifdef HAVE_PULSE
#include "output/pulse_output_plugin.h"
#include "output/pulse_output_plugin.h"
...
@@ -122,6 +126,8 @@ int main(int argc, G_GNUC_UNUSED char **argv)
...
@@ -122,6 +126,8 @@ int main(int argc, G_GNUC_UNUSED char **argv)
g_thread_init
(
NULL
);
g_thread_init
(
NULL
);
main_loop
=
new
EventLoop
(
EventLoop
::
Default
());
mixer
=
mixer_new
(
&
alsa_mixer_plugin
,
NULL
,
NULL
,
&
error
);
mixer
=
mixer_new
(
&
alsa_mixer_plugin
,
NULL
,
NULL
,
&
error
);
if
(
mixer
==
NULL
)
{
if
(
mixer
==
NULL
)
{
g_printerr
(
"mixer_new() failed: %s
\n
"
,
error
->
message
);
g_printerr
(
"mixer_new() failed: %s
\n
"
,
error
->
message
);
...
@@ -141,6 +147,8 @@ int main(int argc, G_GNUC_UNUSED char **argv)
...
@@ -141,6 +147,8 @@ int main(int argc, G_GNUC_UNUSED char **argv)
mixer_close
(
mixer
);
mixer_close
(
mixer
);
mixer_free
(
mixer
);
mixer_free
(
mixer
);
delete
main_loop
;
assert
(
volume
>=
-
1
&&
volume
<=
100
);
assert
(
volume
>=
-
1
&&
volume
<=
100
);
if
(
volume
<
0
)
{
if
(
volume
<
0
)
{
...
...
test/run_output.cxx
View file @
2101daef
...
@@ -21,6 +21,8 @@
...
@@ -21,6 +21,8 @@
#include "OutputControl.hxx"
#include "OutputControl.hxx"
#include "conf.h"
#include "conf.h"
#include "Idle.hxx"
#include "Idle.hxx"
#include "Main.hxx"
#include "event/Loop.hxx"
#include "GlobalEvents.hxx"
#include "GlobalEvents.hxx"
#include "IOThread.hxx"
#include "IOThread.hxx"
...
@@ -42,6 +44,8 @@ extern "C" {
...
@@ -42,6 +44,8 @@ extern "C" {
#include <unistd.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdlib.h>
EventLoop
*
main_loop
;
void
void
GlobalEvents
::
Emit
(
gcc_unused
Event
event
)
GlobalEvents
::
Emit
(
gcc_unused
Event
event
)
{
{
...
@@ -211,6 +215,8 @@ int main(int argc, char **argv)
...
@@ -211,6 +215,8 @@ int main(int argc, char **argv)
return
1
;
return
1
;
}
}
main_loop
=
new
EventLoop
(
EventLoop
::
Default
());
io_thread_init
();
io_thread_init
();
if
(
!
io_thread_start
(
&
error
))
{
if
(
!
io_thread_start
(
&
error
))
{
g_warning
(
"%s"
,
error
->
message
);
g_warning
(
"%s"
,
error
->
message
);
...
@@ -247,6 +253,8 @@ int main(int argc, char **argv)
...
@@ -247,6 +253,8 @@ int main(int argc, char **argv)
io_thread_deinit
();
io_thread_deinit
();
delete
main_loop
;
config_global_finish
();
config_global_finish
();
return
success
?
EXIT_SUCCESS
:
EXIT_FAILURE
;
return
success
?
EXIT_SUCCESS
:
EXIT_FAILURE
;
...
...
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