Commit d305f187 authored by ckdo's avatar ckdo Committed by Max Kellermann

Add the ability to specify media.role for pulse output plugin

This is useful in multiple mpd instances scenario, or multiple pulse outputs defined on the same mpd instance. It is actually a more flexible way to route flows than the "sink" parameter, letting the PulseAudio routing do its job, but with the ability to isolate routing for each output. If not specified, the role remains like it was before this commit, ie "music"
parent 4f6a713b
...@@ -14,6 +14,7 @@ ver 0.22 (not yet released) ...@@ -14,6 +14,7 @@ ver 0.22 (not yet released)
- volume: convert S16 to S24 to preserve quality and reduce dithering noise - volume: convert S16 to S24 to preserve quality and reduce dithering noise
* output * output
- jack: add option "auto_destination_ports" - jack: add option "auto_destination_ports"
- pulse: add option "media_role"
* switch to C++17 * switch to C++17
- GCC 7 or clang 4 (or newer) recommended - GCC 7 or clang 4 (or newer) recommended
......
...@@ -280,6 +280,7 @@ input { ...@@ -280,6 +280,7 @@ input {
# name "My Pulse Output" # name "My Pulse Output"
## server "remote_server" # optional ## server "remote_server" # optional
## sink "remote_server_sink" # optional ## sink "remote_server_sink" # optional
## media_role "media_role" #optional
#} #}
# #
# An example of a winmm output (Windows multimedia API). # An example of a winmm output (Windows multimedia API).
......
...@@ -1002,6 +1002,8 @@ The pulse plugin connects to a `PulseAudio <http://www.freedesktop.org/wiki/Soft ...@@ -1002,6 +1002,8 @@ The pulse plugin connects to a `PulseAudio <http://www.freedesktop.org/wiki/Soft
- Sets the host name of the PulseAudio server. By default, :program:`MPD` connects to the local PulseAudio server. - Sets the host name of the PulseAudio server. By default, :program:`MPD` connects to the local PulseAudio server.
* - **sink NAME** * - **sink NAME**
- Specifies the name of the PulseAudio sink :program:`MPD` should play on. - Specifies the name of the PulseAudio sink :program:`MPD` should play on.
* - **media_role ROLE**
- Specifies a custom media role that :program:`MPD` reports to PulseAudio. Default is "music". (optional).
* - **scale_volume FACTOR** * - **scale_volume FACTOR**
- Specifies a linear scaling coefficient (ranging from 0.5 to 5.0) to apply when adjusting volume through :program:`MPD`. For example, chosing a factor equal to ``"0.7"`` means that setting the volume to 100 in :program:`MPD` will set the PulseAudio volume to 70%, and a factor equal to ``"3.5"`` means that volume 100 in :program:`MPD` corresponds to a 350% PulseAudio volume. - Specifies a linear scaling coefficient (ranging from 0.5 to 5.0) to apply when adjusting volume through :program:`MPD`. For example, chosing a factor equal to ``"0.7"`` means that setting the volume to 100 in :program:`MPD` will set the PulseAudio volume to 70%, and a factor equal to ``"3.5"`` means that volume 100 in :program:`MPD` corresponds to a 350% PulseAudio volume.
......
...@@ -45,6 +45,7 @@ class PulseOutput final : AudioOutput { ...@@ -45,6 +45,7 @@ class PulseOutput final : AudioOutput {
const char *name; const char *name;
const char *server; const char *server;
const char *sink; const char *sink;
const char *const media_role;
PulseMixer *mixer = nullptr; PulseMixer *mixer = nullptr;
...@@ -177,7 +178,8 @@ PulseOutput::PulseOutput(const ConfigBlock &block) ...@@ -177,7 +178,8 @@ PulseOutput::PulseOutput(const ConfigBlock &block)
:AudioOutput(FLAG_ENABLE_DISABLE|FLAG_PAUSE), :AudioOutput(FLAG_ENABLE_DISABLE|FLAG_PAUSE),
name(block.GetBlockValue("name", "mpd_pulse")), name(block.GetBlockValue("name", "mpd_pulse")),
server(block.GetBlockValue("server")), server(block.GetBlockValue("server")),
sink(block.GetBlockValue("sink")) sink(block.GetBlockValue("sink")),
media_role(block.GetBlockValue("media_role"))
{ {
setenv("PULSE_PROP_media.role", "music", true); setenv("PULSE_PROP_media.role", "music", true);
setenv("PULSE_PROP_application.icon_name", "mpd", true); setenv("PULSE_PROP_application.icon_name", "mpd", true);
...@@ -393,8 +395,16 @@ PulseOutput::SetupContext() ...@@ -393,8 +395,16 @@ PulseOutput::SetupContext()
{ {
assert(mainloop != nullptr); assert(mainloop != nullptr);
context = pa_context_new(pa_threaded_mainloop_get_api(mainloop), pa_proplist *proplist = pa_proplist_new();
MPD_PULSE_NAME); if (media_role)
pa_proplist_sets(proplist, PA_PROP_MEDIA_ROLE, media_role);
context = pa_context_new_with_proplist(pa_threaded_mainloop_get_api(mainloop),
MPD_PULSE_NAME,
proplist);
pa_proplist_free(proplist);
if (context == nullptr) if (context == nullptr)
throw std::runtime_error("pa_context_new() has failed"); throw std::runtime_error("pa_context_new() has failed");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment