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
030f87c9
Commit
030f87c9
authored
Sep 16, 2017
by
Christopher Zimmermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add sndio mixer plugin
parent
ae941a76
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
125 additions
and
5 deletions
+125
-5
Makefile.am
Makefile.am
+1
-0
mpdconf.example
doc/mpdconf.example
+1
-1
MixerList.hxx
src/mixer/MixerList.hxx
+1
-0
SndioMixerPlugin.cxx
src/mixer/plugins/SndioMixerPlugin.cxx
+63
-0
SndioOutputPlugin.cxx
src/output/plugins/SndioOutputPlugin.cxx
+49
-3
SndioOutputPlugin.hxx
src/output/plugins/SndioOutputPlugin.hxx
+10
-1
No files found.
Makefile.am
View file @
030f87c9
...
...
@@ -1469,6 +1469,7 @@ if ENABLE_SNDIO
liboutput_plugins_a_SOURCES
+=
\
src/output/plugins/SndioOutputPlugin.cxx
\
src/output/plugins/SndioOutputPlugin.hxx
libmixer_plugins_a_SOURCES
+=
src/mixer/plugins/SndioMixerPlugin.cxx
endif
if
ENABLE_HAIKU
...
...
doc/mpdconf.example
View file @
030f87c9
...
...
@@ -310,7 +310,7 @@ input {
#audio_output {
# type "sndio"
# name "sndio output"
# mixer_type "
soft
ware"
# mixer_type "
hard
ware"
#}
#
# An example of an OS X output:
...
...
src/mixer/MixerList.hxx
View file @
030f87c9
...
...
@@ -36,5 +36,6 @@ extern const MixerPlugin osx_mixer_plugin;
extern
const
MixerPlugin
roar_mixer_plugin
;
extern
const
MixerPlugin
pulse_mixer_plugin
;
extern
const
MixerPlugin
winmm_mixer_plugin
;
extern
const
MixerPlugin
sndio_mixer_plugin
;
#endif
src/mixer/plugins/SndioMixerPlugin.cxx
0 → 100644
View file @
030f87c9
/*
* Copyright 2017 Christopher Zimmermann <christopher@gmerlin.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "config.h"
#include "mixer/MixerInternal.hxx"
#include "mixer/Listener.hxx"
#include "output/plugins/SndioOutputPlugin.hxx"
#include <sndio.h>
class
SndioMixer
final
:
public
Mixer
{
SndioOutput
&
output
;
public
:
SndioMixer
(
SndioOutput
&
_output
,
MixerListener
&
_listener
)
:
Mixer
(
sndio_mixer_plugin
,
_listener
),
output
(
_output
)
{
output
.
RegisterMixerListener
(
this
,
&
_listener
);
}
/* virtual methods from class Mixer */
void
Open
()
override
{}
void
Close
()
noexcept
override
{}
int
GetVolume
()
override
{
return
output
.
GetVolume
();
}
void
SetVolume
(
unsigned
volume
)
override
{
output
.
SetVolume
(
volume
);
}
};
static
Mixer
*
sndio_mixer_init
(
gcc_unused
EventLoop
&
event_loop
,
AudioOutput
&
ao
,
MixerListener
&
listener
,
gcc_unused
const
ConfigBlock
&
block
)
{
return
new
SndioMixer
((
SndioOutput
&
)
ao
,
listener
);
}
const
MixerPlugin
sndio_mixer_plugin
=
{
sndio_mixer_init
,
false
,
};
src/output/plugins/SndioOutputPlugin.cxx
View file @
030f87c9
...
...
@@ -19,6 +19,7 @@
#include "config.h"
#include "SndioOutputPlugin.hxx"
#include "mixer/MixerList.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
...
...
@@ -47,10 +48,16 @@ SndioOutput::SndioOutput(const ConfigBlock &block)
:
AudioOutput
(
0
),
device
(
block
.
GetBlockValue
(
"device"
,
SIO_DEVANY
)),
buffer_time
(
block
.
GetBlockValue
(
"buffer_time"
,
MPD_SNDIO_BUFFER_TIME_MS
))
MPD_SNDIO_BUFFER_TIME_MS
)),
raw_volume
(
SIO_MAXVOL
)
{
}
static
void
VolumeCallback
(
void
*
arg
,
unsigned
int
volume
)
{
((
SndioOutput
*
)
arg
)
->
VolumeChanged
(
volume
);
}
AudioOutput
*
SndioOutput
::
Create
(
EventLoop
&
,
const
ConfigBlock
&
block
)
{
return
new
SndioOutput
(
block
);
...
...
@@ -125,6 +132,15 @@ SndioOutput::Open(AudioFormat &audio_format)
throw
std
::
runtime_error
(
"Requested audio params cannot be satisfied"
);
}
// Set volume after opening fresh audio stream which does
// know nothing about previous audio streams.
sio_setvol
(
sio_hdl
,
raw_volume
);
// sio_onvol returns 0 if no volume knob is available.
// This is the case on raw audio devices rather than
// the sndiod audio server.
if
(
sio_onvol
(
sio_hdl
,
VolumeCallback
,
this
)
==
0
)
raw_volume
=
-
1
;
if
(
!
sio_start
(
sio_hdl
))
{
sio_close
(
sio_hdl
);
throw
std
::
runtime_error
(
"Failed to start audio device"
);
...
...
@@ -148,9 +164,39 @@ SndioOutput::Play(const void *chunk, size_t size)
return
n
;
}
void
SndioOutput
::
SetVolume
(
unsigned
int
volume
)
{
sio_setvol
(
sio_hdl
,
volume
*
SIO_MAXVOL
/
100
);
}
static
inline
unsigned
int
RawToPercent
(
int
raw_volume
)
{
return
raw_volume
<
0
?
100
:
raw_volume
*
100
/
SIO_MAXVOL
;
}
void
SndioOutput
::
VolumeChanged
(
int
_raw_volume
)
{
if
(
raw_volume
>=
0
&&
listener
!=
nullptr
&&
mixer
!=
nullptr
)
{
raw_volume
=
_raw_volume
;
listener
->
OnMixerVolumeChanged
(
*
mixer
,
RawToPercent
(
raw_volume
));
}
}
unsigned
int
SndioOutput
::
GetVolume
()
{
return
RawToPercent
(
raw_volume
);
}
void
SndioOutput
::
RegisterMixerListener
(
Mixer
*
_mixer
,
MixerListener
*
_listener
)
{
mixer
=
_mixer
;
listener
=
_listener
;
}
const
struct
AudioOutputPlugin
sndio_output_plugin
=
{
"sndio"
,
sndio_test_default_device
,
&
SndioOutput
::
Create
,
nullptr
,
SndioOutput
::
Create
,
&
sndio_mixer_plugin
,
};
src/output/plugins/SndioOutputPlugin.hxx
View file @
030f87c9
...
...
@@ -18,6 +18,7 @@
*/
#include "../OutputAPI.hxx"
#include "mixer/Listener.hxx"
#ifndef MPD_SNDIO_OUTPUT_PLUGIN_HXX
#define MPD_SNDIO_OUTPUT_PLUGIN_HXX
...
...
@@ -25,15 +26,23 @@
extern
const
struct
AudioOutputPlugin
sndio_output_plugin
;
class
SndioOutput
final
:
AudioOutput
{
Mixer
*
mixer
=
nullptr
;
MixerListener
*
listener
=
nullptr
;
const
char
*
const
device
;
const
unsigned
buffer_time
;
/* in ms */
struct
sio_hdl
*
sio_hdl
;
int
raw_volume
;
public
:
SndioOutput
(
const
ConfigBlock
&
block
);
static
AudioOutput
*
Create
(
EventLoop
&
,
const
ConfigBlock
&
block
);
const
ConfigBlock
&
block
);
void
SetVolume
(
unsigned
int
_volume
);
unsigned
int
GetVolume
();
void
VolumeChanged
(
int
_volume
);
void
RegisterMixerListener
(
Mixer
*
_mixer
,
MixerListener
*
_listener
);
private
:
void
Open
(
AudioFormat
&
audio_format
)
override
;
...
...
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