output/snapcast: Zeroconf support
This commit is contained in:
@@ -119,7 +119,7 @@ if get_option('snapcast')
|
||||
'snapcast/SnapcastOutputPlugin.cxx',
|
||||
'snapcast/Client.cxx',
|
||||
]
|
||||
output_plugins_deps += [ event_dep, net_dep, yajl_dep ]
|
||||
output_plugins_deps += [ event_dep, net_dep, yajl_dep, zeroconf_dep ]
|
||||
|
||||
output_features.set('HAVE_YAJL', yajl_dep.found())
|
||||
|
||||
|
@@ -30,14 +30,21 @@
|
||||
#include "util/AllocatedArray.hxx"
|
||||
#include "util/IntrusiveList.hxx"
|
||||
|
||||
#include "config.h" // for HAVE_ZEROCONF
|
||||
|
||||
#include <memory>
|
||||
|
||||
struct ConfigBlock;
|
||||
class SnapcastClient;
|
||||
class PreparedEncoder;
|
||||
class Encoder;
|
||||
class ZeroconfHelper;
|
||||
|
||||
class SnapcastOutput final : AudioOutput, ServerSocket {
|
||||
#ifdef HAVE_ZEROCONF
|
||||
unsigned zeroconf_port = 0;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* True if the audio output is open and accepts client
|
||||
* connections.
|
||||
@@ -46,6 +53,10 @@ class SnapcastOutput final : AudioOutput, ServerSocket {
|
||||
|
||||
InjectEvent inject_event;
|
||||
|
||||
#ifdef HAVE_ZEROCONF
|
||||
std::unique_ptr<ZeroconfHelper> zeroconf_helper;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* The configured encoder plugin.
|
||||
*/
|
||||
|
@@ -32,6 +32,10 @@
|
||||
#include "util/DeleteDisposer.hxx"
|
||||
#include "config/Net.hxx"
|
||||
|
||||
#ifdef HAVE_ZEROCONF
|
||||
#include "zeroconf/Helper.hxx"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_YAJL
|
||||
#include "lib/yajl/Gen.hxx"
|
||||
#endif
|
||||
@@ -49,8 +53,14 @@ SnapcastOutput::SnapcastOutput(EventLoop &_loop, const ConfigBlock &block)
|
||||
// TODO: support other encoder plugins?
|
||||
prepared_encoder(encoder_init(wave_encoder_plugin, block))
|
||||
{
|
||||
const unsigned port = block.GetBlockValue("port", 1704U);
|
||||
ServerSocketAddGeneric(*this, block.GetBlockValue("bind_to_address"),
|
||||
block.GetBlockValue("port", 1704U));
|
||||
port);
|
||||
|
||||
#ifdef HAVE_ZEROCONF
|
||||
if (block.GetBlockValue("zeroconf", true))
|
||||
zeroconf_port = port;
|
||||
#endif
|
||||
}
|
||||
|
||||
SnapcastOutput::~SnapcastOutput() noexcept = default;
|
||||
@@ -62,6 +72,13 @@ SnapcastOutput::Bind()
|
||||
|
||||
BlockingCall(GetEventLoop(), [this](){
|
||||
ServerSocket::Open();
|
||||
|
||||
#ifdef HAVE_ZEROCONF
|
||||
if (zeroconf_port > 0)
|
||||
zeroconf_helper = std::make_unique<ZeroconfHelper>
|
||||
(GetEventLoop(), "Music Player Daemon",
|
||||
"_snapcast._tcp", zeroconf_port);
|
||||
#endif
|
||||
});
|
||||
|
||||
// TODO: Zeroconf integration
|
||||
@@ -73,6 +90,8 @@ SnapcastOutput::Unbind() noexcept
|
||||
assert(!open);
|
||||
|
||||
BlockingCall(GetEventLoop(), [this](){
|
||||
zeroconf_helper.reset();
|
||||
|
||||
ServerSocket::Close();
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user