Rename PcmListener to PcmStream::Listener

Reorganize include order
This commit is contained in:
badaix 2021-12-12 12:19:46 +01:00
parent c49841cf6f
commit d326252268
30 changed files with 227 additions and 144 deletions

View file

@ -1,6 +1,6 @@
/***
This file is part of snapcast
Copyright (C) 2014-2020 Johannes Pohl
Copyright (C) 2014-2021 Johannes Pohl
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
@ -19,15 +19,18 @@
#ifndef CONTROLLER_HPP
#define CONTROLLER_HPP
// local headers
#include "client_connection.hpp"
#include "client_settings.hpp"
#include "decoder/decoder.hpp"
#include "message/message.hpp"
#include "message/server_settings.hpp"
// #include "message/stream_tags.hpp"
// #include "metadata.hpp"
#include "player/player.hpp"
#include "stream.hpp"
// 3rd party headers
// standard headers
#include <atomic>
#include <thread>

View file

@ -16,14 +16,20 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
// prototype/interface header file
#include "server.hpp"
// local headers
#include "common/aixlog.hpp"
#include "config.hpp"
#include "message/client_info.hpp"
#include "message/hello.hpp"
// #include "message/stream_tags.hpp"
#include "message/time.hpp"
#include "stream_session_tcp.hpp"
// 3rd party headers
// standard headers
#include <iostream>
using namespace std;

View file

@ -19,13 +19,7 @@
#ifndef SERVER_HPP
#define SERVER_HPP
#include <boost/asio.hpp>
#include <memory>
#include <mutex>
#include <set>
#include <sstream>
#include <vector>
// local headers
#include "common/queue.h"
#include "common/sample_format.hpp"
#include "control_server.hpp"
@ -38,6 +32,17 @@
#include "stream_session.hpp"
#include "streamreader/stream_manager.hpp"
// 3rd party headers
#include <boost/asio.hpp>
// standard headers
#include <memory>
#include <mutex>
#include <set>
#include <sstream>
#include <vector>
using namespace streamreader;
using boost::asio::ip::tcp;
@ -45,14 +50,11 @@ using acceptor_ptr = std::unique_ptr<tcp::acceptor>;
using session_ptr = std::shared_ptr<StreamSession>;
/// Forwars PCM data to the connected clients
/**
* Reads PCM data using PipeStream, implements PcmListener to get the (encoded) PCM stream.
* Accepts and holds client connections (StreamSession)
* Receives (via the StreamMessageReceiver interface) and answers messages from the clients
* Forwards PCM data to the clients
* Receives and routes PcmStreams
* Processes ControlSession messages
*/
class Server : public StreamMessageReceiver, public ControlMessageReceiver, public PcmListener
class Server : public StreamMessageReceiver, public ControlMessageReceiver, public PcmStream::Listener
{
public:
// TODO: revise handler names
@ -77,7 +79,7 @@ private:
};
void onNewSession(std::shared_ptr<StreamSession> session) override;
/// Implementation of PcmListener
/// Implementation of PcmStream::Listener
void onPropertiesChanged(const PcmStream* pcmStream, const Properties& properties) override;
void onStateChanged(const PcmStream* pcmStream, ReaderState state) override;
void onChunkRead(const PcmStream* pcmStream, const msg::PcmChunk& chunk) override;

View file

@ -16,14 +16,20 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
// prototype/interface header file
#include "stream_server.hpp"
// local headers
#include "common/aixlog.hpp"
#include "config.hpp"
#include "message/client_info.hpp"
#include "message/hello.hpp"
// #include "message/stream_tags.hpp"
#include "message/time.hpp"
#include "stream_session_tcp.hpp"
// 3rd party headers
// standard headers
#include <iostream>
using namespace std;

View file

@ -19,13 +19,7 @@
#ifndef STREAM_SERVER_HPP
#define STREAM_SERVER_HPP
#include <boost/asio.hpp>
#include <memory>
#include <mutex>
#include <set>
#include <sstream>
#include <vector>
// local headers
#include "common/queue.h"
#include "common/sample_format.hpp"
#include "control_server.hpp"
@ -37,6 +31,17 @@
#include "stream_session.hpp"
#include "streamreader/stream_manager.hpp"
// 3rd party headers
#include <boost/asio.hpp>
// standard headers
#include <memory>
#include <mutex>
#include <set>
#include <sstream>
#include <vector>
using namespace streamreader;
using boost::asio::ip::tcp;
@ -46,7 +51,7 @@ using session_ptr = std::shared_ptr<StreamSession>;
/// Forwars PCM data to the connected clients
/**
* Reads PCM data using PipeStream, implements PcmListener to get the (encoded) PCM stream.
* Reads PCM data from several StreamSessions
* Accepts and holds client connections (StreamSession)
* Receives (via the StreamMessageReceiver interface) and answers messages from the clients
* Forwards PCM data to the clients

View file

@ -16,7 +16,10 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
// prototype/interface header file
#include "airplay_stream.hpp"
// local headers
#include "base64.h"
#include "common/aixlog.hpp"
#include "common/snap_exception.hpp"
@ -47,7 +50,7 @@ string hex2str(const string& input)
* Without HAS_EXPAT defined no parsing will occur.
*/
AirplayStream::AirplayStream(PcmListener* pcmListener, boost::asio::io_context& ioc, const ServerSettings& server_settings, const StreamUri& uri)
AirplayStream::AirplayStream(PcmStream::Listener* pcmListener, boost::asio::io_context& ioc, const ServerSettings& server_settings, const StreamUri& uri)
: ProcessStream(pcmListener, ioc, server_settings, uri), port_(5000), pipe_open_timer_(ioc)
{
logStderr_ = true;

View file

@ -19,12 +19,12 @@
#ifndef AIRPLAY_STREAM_HPP
#define AIRPLAY_STREAM_HPP
// local headers
#include "process_stream.hpp"
/*
* Expat is used in metadata parsing from Shairport-sync.
* Without HAS_EXPAT defined no parsing will occur.
*/
// 3rd party headers
// Expat is used in metadata parsing from Shairport-sync.
// Without HAS_EXPAT defined no parsing will occur.
#ifdef HAS_EXPAT
#include <expat.h>
#endif
@ -51,7 +51,7 @@ public:
/**
* Starts librespot, reads PCM data from stdout, and passes the data to an encoder.
* Implements EncoderListener to get the encoded data.
* Data is passed to the PcmListener
* Data is passed to the PcmStream::Listener
* usage:
* snapserver -s "airplay:///shairport-sync?name=Airplay[&devicename=Snapcast][&port=5000]"
*/
@ -59,7 +59,7 @@ class AirplayStream : public ProcessStream
{
public:
/// ctor. Encoded PCM data is passed to the PipeListener
AirplayStream(PcmListener* pcmListener, boost::asio::io_context& ioc, const ServerSettings& server_settings, const StreamUri& uri);
AirplayStream(PcmStream::Listener* pcmListener, boost::asio::io_context& ioc, const ServerSettings& server_settings, const StreamUri& uri);
~AirplayStream() override;
protected:

View file

@ -16,17 +16,17 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#include <cerrno>
#include <fcntl.h>
#include <memory>
#include <sys/stat.h>
#include <unistd.h>
// prototype/interface header file
#include "alsa_stream.hpp"
// local headers
#include "common/aixlog.hpp"
#include "common/snap_exception.hpp"
#include "common/str_compat.hpp"
#include "alsa_stream.hpp"
// standard headers
#include <cerrno>
#include <memory>
using namespace std;
@ -65,7 +65,7 @@ void wait(boost::asio::steady_timer& timer, const std::chrono::duration<Rep, Per
} // namespace
AlsaStream::AlsaStream(PcmListener* pcmListener, boost::asio::io_context& ioc, const ServerSettings& server_settings, const StreamUri& uri)
AlsaStream::AlsaStream(PcmStream::Listener* pcmListener, boost::asio::io_context& ioc, const ServerSettings& server_settings, const StreamUri& uri)
: PcmStream(pcmListener, ioc, server_settings, uri), handle_(nullptr), read_timer_(strand_), silence_(0ms)
{
device_ = uri_.getQuery("device", "hw:0");

View file

@ -19,7 +19,10 @@
#ifndef ALSA_STREAM_HPP
#define ALSA_STREAM_HPP
// local headers
#include "pcm_stream.hpp"
// 3rd party headers
#include <alsa/asoundlib.h>
#include <boost/asio.hpp>
@ -31,13 +34,13 @@ namespace streamreader
/**
* Reads PCM from an alsa audio device device and passes the data to an encoder.
* Implements EncoderListener to get the encoded data.
* Data is passed to the PcmListener
* Data is passed to the PcmStream::Listener
*/
class AlsaStream : public PcmStream
{
public:
/// ctor. Encoded PCM data is passed to the PipeListener
AlsaStream(PcmListener* pcmListener, boost::asio::io_context& ioc, const ServerSettings& server_settings, const StreamUri& uri);
AlsaStream(PcmStream::Listener* pcmListener, boost::asio::io_context& ioc, const ServerSettings& server_settings, const StreamUri& uri);
void start() override;
void stop() override;

View file

@ -19,12 +19,18 @@
#ifndef ASIO_STREAM_HPP
#define ASIO_STREAM_HPP
// local headers
#include "common/aixlog.hpp"
#include "common/str_compat.hpp"
#include "pcm_stream.hpp"
#include <atomic>
// 3rd party headers
#include <boost/asio.hpp>
// standard headers
#include <atomic>
namespace streamreader
{
@ -33,7 +39,7 @@ class AsioStream : public PcmStream
{
public:
/// ctor. Encoded PCM data is passed to the PipeListener
AsioStream(PcmListener* pcmListener, boost::asio::io_context& ioc, const ServerSettings& server_settings, const StreamUri& uri);
AsioStream(PcmStream::Listener* pcmListener, boost::asio::io_context& ioc, const ServerSettings& server_settings, const StreamUri& uri);
void start() override;
void stop() override;
@ -82,7 +88,7 @@ void AsioStream<ReadStream>::wait(Timer& timer, const std::chrono::duration<Rep,
template <typename ReadStream>
AsioStream<ReadStream>::AsioStream(PcmListener* pcmListener, boost::asio::io_context& ioc, const ServerSettings& server_settings, const StreamUri& uri)
AsioStream<ReadStream>::AsioStream(PcmStream::Listener* pcmListener, boost::asio::io_context& ioc, const ServerSettings& server_settings, const StreamUri& uri)
: PcmStream(pcmListener, ioc, server_settings, uri), read_timer_(strand_), state_timer_(strand_)
{
chunk_ = std::make_unique<msg::PcmChunk>(sampleFormat_, chunk_ms_);

View file

@ -16,14 +16,16 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#include <fcntl.h>
#include <memory>
#include <sys/stat.h>
// prototype/interface header file
#include "file_stream.hpp"
// local headers
#include "common/aixlog.hpp"
#include "common/snap_exception.hpp"
#include "encoder/encoder_factory.hpp"
#include "file_stream.hpp"
// 3rd party headers
#include <memory>
using namespace std;
@ -34,7 +36,7 @@ namespace streamreader
static constexpr auto LOG_TAG = "FileStream";
FileStream::FileStream(PcmListener* pcmListener, boost::asio::io_context& ioc, const ServerSettings& server_settings, const StreamUri& uri)
FileStream::FileStream(PcmStream::Listener* pcmListener, boost::asio::io_context& ioc, const ServerSettings& server_settings, const StreamUri& uri)
: PosixStream(pcmListener, ioc, server_settings, uri)
{
struct stat buffer;

View file

@ -19,6 +19,7 @@
#ifndef FILE_STREAM_HPP
#define FILE_STREAM_HPP
// local headers
#include "posix_stream.hpp"
namespace streamreader
@ -28,13 +29,13 @@ namespace streamreader
/**
* Reads PCM from a file and passes the data to an encoder.
* Implements EncoderListener to get the encoded data.
* Data is passed to the PcmListener
* Data is passed to the PcmStream::Listener
*/
class FileStream : public PosixStream
{
public:
/// ctor. Encoded PCM data is passed to the PipeListener
FileStream(PcmListener* pcmListener, boost::asio::io_context& ioc, const ServerSettings& server_settings, const StreamUri& uri);
FileStream(PcmStream::Listener* pcmListener, boost::asio::io_context& ioc, const ServerSettings& server_settings, const StreamUri& uri);
protected:
void do_connect() override;

View file

@ -16,11 +16,16 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
// prototype/interface header file
#include "librespot_stream.hpp"
// local headers
#include "common/aixlog.hpp"
#include "common/snap_exception.hpp"
#include "common/utils.hpp"
#include "common/utils/string_utils.hpp"
// standard headers
#include <regex>
@ -32,7 +37,7 @@ namespace streamreader
static constexpr auto LOG_TAG = "LibrespotStream";
LibrespotStream::LibrespotStream(PcmListener* pcmListener, boost::asio::io_context& ioc, const ServerSettings& server_settings, const StreamUri& uri)
LibrespotStream::LibrespotStream(PcmStream::Listener* pcmListener, boost::asio::io_context& ioc, const ServerSettings& server_settings, const StreamUri& uri)
: ProcessStream(pcmListener, ioc, server_settings, uri)
{
wd_timeout_sec_ = cpt::stoul(uri_.getQuery("wd_timeout", "7800")); ///< 130min

View file

@ -19,6 +19,7 @@
#ifndef SPOTIFY_STREAM_HPP
#define SPOTIFY_STREAM_HPP
// local headers
#include "process_stream.hpp"
namespace streamreader
@ -28,7 +29,7 @@ namespace streamreader
/**
* Starts librespot, reads PCM data from stdout, and passes the data to an encoder.
* Implements EncoderListener to get the encoded data.
* Data is passed to the PcmListener
* Data is passed to the PcmStream::Listener
* usage:
* snapserver -s "spotify:///librespot?name=Spotify&username=<my username>&password=<my password>[&devicename=Snapcast][&bitrate=320][&volume=<volume in
* percent>][&cache=<cache dir>]"
@ -37,7 +38,7 @@ class LibrespotStream : public ProcessStream
{
public:
/// ctor. Encoded PCM data is passed to the PipeListener
LibrespotStream(PcmListener* pcmListener, boost::asio::io_context& ioc, const ServerSettings& server_settings, const StreamUri& uri);
LibrespotStream(PcmStream::Listener* pcmListener, boost::asio::io_context& ioc, const ServerSettings& server_settings, const StreamUri& uri);
protected:
bool killall_;

View file

@ -16,7 +16,10 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
// prototype/interface header file
#include "meta_stream.hpp"
// local headers
#include "common/aixlog.hpp"
#include "common/snap_exception.hpp"
#include "common/utils/string_utils.hpp"
@ -32,7 +35,7 @@ static constexpr auto LOG_TAG = "MetaStream";
// static constexpr auto kResyncTolerance = 50ms;
MetaStream::MetaStream(PcmListener* pcmListener, const std::vector<std::shared_ptr<PcmStream>>& streams, boost::asio::io_context& ioc,
MetaStream::MetaStream(PcmStream::Listener* pcmListener, const std::vector<std::shared_ptr<PcmStream>>& streams, boost::asio::io_context& ioc,
const ServerSettings& server_settings, const StreamUri& uri)
: PcmStream(pcmListener, ioc, server_settings, uri), first_read_(true)
{

View file

@ -19,8 +19,11 @@
#ifndef META_STREAM_HPP
#define META_STREAM_HPP
// local headers
#include "posix_stream.hpp"
#include "resampler.hpp"
// standard headers
#include <memory>
namespace streamreader
@ -31,13 +34,13 @@ namespace streamreader
/**
* Reads PCM and passes the data to an encoder.
* Implements EncoderListener to get the encoded data.
* Data is passed to the PcmListener
* Data is passed to the PcmStream::Listener
*/
class MetaStream : public PcmStream, public PcmListener
class MetaStream : public PcmStream, public PcmStream::Listener
{
public:
/// ctor. Encoded PCM data is passed to the PcmListener
MetaStream(PcmListener* pcmListener, const std::vector<std::shared_ptr<PcmStream>>& streams, boost::asio::io_context& ioc,
/// ctor. Encoded PCM data is passed to the PcmStream::Listener
MetaStream(PcmStream::Listener* pcmListener, const std::vector<std::shared_ptr<PcmStream>>& streams, boost::asio::io_context& ioc,
const ServerSettings& server_settings, const StreamUri& uri);
virtual ~MetaStream();
@ -61,7 +64,7 @@ public:
void play(ResultHandler handler) override;
protected:
/// Implementation of PcmListener
/// Implementation of PcmStream::Listener
void onPropertiesChanged(const PcmStream* pcmStream, const Properties& properties) override;
void onStateChanged(const PcmStream* pcmStream, ReaderState state) override;
void onChunkRead(const PcmStream* pcmStream, const msg::PcmChunk& chunk) override;

View file

@ -16,8 +16,10 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
// prototype/interface header file
#include "pcm_stream.hpp"
// local headers
#include "base64.h"
#include "common/aixlog.hpp"
#include "common/error_code.hpp"
@ -27,11 +29,11 @@
#include "control_error.hpp"
#include "encoder/encoder_factory.hpp"
// 3rd party headers
#include <boost/asio/ip/host_name.hpp>
#include <fcntl.h>
// standard headers
#include <memory>
#include <sys/stat.h>
using namespace std;
@ -42,7 +44,7 @@ namespace streamreader
static constexpr auto LOG_TAG = "PcmStream";
PcmStream::PcmStream(PcmListener* pcmListener, boost::asio::io_context& ioc, const ServerSettings& server_settings, const StreamUri& uri)
PcmStream::PcmStream(PcmStream::Listener* pcmListener, boost::asio::io_context& ioc, const ServerSettings& server_settings, const StreamUri& uri)
: active_(false), strand_(net::make_strand(ioc.get_executor())), pcmListeners_{pcmListener}, uri_(uri), chunk_ms_(20), state_(ReaderState::kIdle),
ioc_(ioc), server_settings_(server_settings), req_id_(0), property_timer_(strand_)
{
@ -302,7 +304,7 @@ json PcmStream::toJson() const
}
void PcmStream::addListener(PcmListener* pcmListener)
void PcmStream::addListener(PcmStream::Listener* pcmListener)
{
pcmListeners_.push_back(pcmListener);
}

View file

@ -19,15 +19,7 @@
#ifndef PCM_STREAM_HPP
#define PCM_STREAM_HPP
#include <atomic>
#include <mutex>
#include <string>
#include <vector>
#include <boost/asio/io_context.hpp>
#include <boost/asio/read_until.hpp>
#include <boost/asio/steady_timer.hpp>
// local headers
#include "common/error_code.hpp"
#include "common/json.hpp"
#include "common/sample_format.hpp"
@ -39,8 +31,18 @@
#include "stream_control.hpp"
#include "stream_uri.hpp"
// 3rd party headers
#include <boost/asio/io_context.hpp>
#include <boost/asio/read_until.hpp>
#include <boost/asio/steady_timer.hpp>
// standard headers
#include <atomic>
#include <mutex>
#include <string>
#include <vector>
namespace bp = boost::process;
namespace net = boost::asio;
using json = nlohmann::json;
@ -92,11 +94,20 @@ static constexpr auto kUriChunkMs = "chunk_ms";
static constexpr auto kControlScript = "controlscript";
/// Reads and decodes PCM data
/**
* Reads PCM and passes the data to an encoder.
* Implements EncoderListener to get the encoded data.
* Data is passed to the PcmStream::Listener
*/
class PcmStream
{
public:
/// Callback interface for users of PcmStream
/**
* Users of PcmStream should implement this to get the data
*/
class PcmListener
class Listener
{
public:
virtual void onPropertiesChanged(const PcmStream* pcmStream, const Properties& properties) = 0;
@ -107,20 +118,10 @@ public:
};
/// Reads and decodes PCM data
/**
* Reads PCM and passes the data to an encoder.
* Implements EncoderListener to get the encoded data.
* Data is passed to the PcmListener
*/
class PcmStream
{
public:
using ResultHandler = std::function<void(const snapcast::ErrorCode& ec)>;
/// ctor. Encoded PCM data is passed to the PcmListener
PcmStream(PcmListener* pcmListener, boost::asio::io_context& ioc, const ServerSettings& server_settings, const StreamUri& uri);
/// ctor. Encoded PCM data is passed to the PcmStream::Listener
PcmStream(PcmStream::Listener* pcmListener, boost::asio::io_context& ioc, const ServerSettings& server_settings, const StreamUri& uri);
virtual ~PcmStream();
virtual void start();
@ -155,7 +156,7 @@ public:
virtual ReaderState getState() const;
virtual json toJson() const;
void addListener(PcmListener* pcmListener);
void addListener(PcmStream::Listener* pcmListener);
protected:
std::atomic<bool> active_;
@ -181,7 +182,7 @@ protected:
net::strand<net::any_io_executor> strand_;
std::chrono::time_point<std::chrono::steady_clock> tvEncodedChunk_;
std::vector<PcmListener*> pcmListeners_;
std::vector<PcmStream::Listener*> pcmListeners_;
StreamUri uri_;
SampleFormat sampleFormat_;
size_t chunk_ms_;

View file

@ -16,16 +16,17 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#include <cerrno>
#include <fcntl.h>
#include <memory>
#include <sys/stat.h>
#include <unistd.h>
// prototype/interface header file
#include "pipe_stream.hpp"
// local headers
#include "common/aixlog.hpp"
#include "common/snap_exception.hpp"
#include "common/str_compat.hpp"
#include "pipe_stream.hpp"
// standard headers
#include <cerrno>
#include <memory>
using namespace std;
@ -36,7 +37,7 @@ namespace streamreader
static constexpr auto LOG_TAG = "PipeStream";
PipeStream::PipeStream(PcmListener* pcmListener, boost::asio::io_context& ioc, const ServerSettings& server_settings, const StreamUri& uri)
PipeStream::PipeStream(PcmStream::Listener* pcmListener, boost::asio::io_context& ioc, const ServerSettings& server_settings, const StreamUri& uri)
: PosixStream(pcmListener, ioc, server_settings, uri)
{
umask(0);

View file

@ -19,6 +19,7 @@
#ifndef PIPE_STREAM_HPP
#define PIPE_STREAM_HPP
// local headers
#include "posix_stream.hpp"
namespace streamreader
@ -31,13 +32,13 @@ using boost::asio::posix::stream_descriptor;
/**
* Reads PCM from a named pipe and passes the data to an encoder.
* Implements EncoderListener to get the encoded data.
* Data is passed to the PcmListener
* Data is passed to the PcmStream::Listener
*/
class PipeStream : public PosixStream
{
public:
/// ctor. Encoded PCM data is passed to the PipeListener
PipeStream(PcmListener* pcmListener, boost::asio::io_context& ioc, const ServerSettings& server_settings, const StreamUri& uri);
PipeStream(PcmStream::Listener* pcmListener, boost::asio::io_context& ioc, const ServerSettings& server_settings, const StreamUri& uri);
protected:
void do_connect() override;

View file

@ -16,16 +16,17 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#include <cerrno>
#include <fcntl.h>
#include <memory>
#include <sys/stat.h>
#include <unistd.h>
// prototype/interface header file
#include "posix_stream.hpp"
// local headers
#include "common/aixlog.hpp"
#include "common/snap_exception.hpp"
#include "common/str_compat.hpp"
#include "posix_stream.hpp"
// standard headers
#include <cerrno>
#include <memory>
using namespace std;
@ -37,7 +38,7 @@ namespace streamreader
static constexpr auto LOG_TAG = "PosixStream";
static constexpr auto kResyncTolerance = 50ms;
PosixStream::PosixStream(PcmListener* pcmListener, boost::asio::io_context& ioc, const ServerSettings& server_settings, const StreamUri& uri)
PosixStream::PosixStream(PcmStream::Listener* pcmListener, boost::asio::io_context& ioc, const ServerSettings& server_settings, const StreamUri& uri)
: AsioStream<stream_descriptor>(pcmListener, ioc, server_settings, uri)
{
if (uri_.query.find("dryout_ms") != uri_.query.end())

View file

@ -19,6 +19,7 @@
#ifndef POSIX_STREAM_HPP
#define POSIX_STREAM_HPP
// local headers
#include "asio_stream.hpp"
namespace streamreader
@ -31,13 +32,13 @@ using boost::asio::posix::stream_descriptor;
/**
* Reads PCM from a file descriptor and passes the data to an encoder.
* Implements EncoderListener to get the encoded data.
* Data is passed to the PcmListener
* Data is passed to the PcmStream::Listener
*/
class PosixStream : public AsioStream<stream_descriptor>
{
public:
/// ctor. Encoded PCM data is passed to the PipeListener
PosixStream(PcmListener* pcmListener, boost::asio::io_context& ioc, const ServerSettings& server_settings, const StreamUri& uri);
PosixStream(PcmStream::Listener* pcmListener, boost::asio::io_context& ioc, const ServerSettings& server_settings, const StreamUri& uri);
protected:
void connect() override;

View file

@ -17,14 +17,17 @@
***/
// prototype/interface header file
#include "process_stream.hpp"
// local headers
#include "common/aixlog.hpp"
#include "common/snap_exception.hpp"
#include "common/utils.hpp"
#include "common/utils/string_utils.hpp"
// standard headers
#include <climits>
#include <fcntl.h>
#include <sys/stat.h>
using namespace std;
@ -35,7 +38,7 @@ namespace streamreader
static constexpr auto LOG_TAG = "ProcessStream";
ProcessStream::ProcessStream(PcmListener* pcmListener, boost::asio::io_context& ioc, const ServerSettings& server_settings, const StreamUri& uri)
ProcessStream::ProcessStream(PcmStream::Listener* pcmListener, boost::asio::io_context& ioc, const ServerSettings& server_settings, const StreamUri& uri)
: PosixStream(pcmListener, ioc, server_settings, uri)
{
params_ = uri_.getQuery("params");

View file

@ -19,13 +19,15 @@
#ifndef PROCESS_STREAM_HPP
#define PROCESS_STREAM_HPP
// local headers
#include "posix_stream.hpp"
#include "watchdog.hpp"
// standard headers
#include <memory>
#include <string>
#include <vector>
#include "posix_stream.hpp"
#include "watchdog.hpp"
namespace bp = boost::process;
@ -37,13 +39,13 @@ namespace streamreader
/**
* Starts an external process, reads PCM data from stdout, and passes the data to an encoder.
* Implements EncoderListener to get the encoded data.
* Data is passed to the PcmListener
* Data is passed to the PcmStream::Listener
*/
class ProcessStream : public PosixStream, public WatchdogListener
{
public:
/// ctor. Encoded PCM data is passed to the PipeListener
ProcessStream(PcmListener* pcmListener, boost::asio::io_context& ioc, const ServerSettings& server_settings, const StreamUri& uri);
ProcessStream(PcmStream::Listener* pcmListener, boost::asio::io_context& ioc, const ServerSettings& server_settings, const StreamUri& uri);
~ProcessStream() override = default;
protected:

View file

@ -16,16 +16,20 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#include <fcntl.h>
#include <memory>
#include <sys/stat.h>
// prototype/interface header file
#include "stream_control.hpp"
// local headers
#include "common/aixlog.hpp"
#include "common/snap_exception.hpp"
#include "common/str_compat.hpp"
#include "common/utils/string_utils.hpp"
#include "encoder/encoder_factory.hpp"
#include "stream_control.hpp"
// 3rd party headers
// standard headers
#include <memory>
using namespace std;

View file

@ -19,6 +19,11 @@
#ifndef STREAM_CONTROL_HPP
#define STREAM_CONTROL_HPP
// local headers
#include "jsonrpcpp.hpp"
#include "server_settings.hpp"
// 3rd party headers
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpragmas"
#pragma GCC diagnostic ignored "-Wunused-result"
@ -28,13 +33,11 @@
#pragma GCC diagnostic ignored "-Wc++11-narrowing"
#include <boost/process.hpp>
#pragma GCC diagnostic pop
#include <map>
#include <string>
#include <boost/asio.hpp>
#include "jsonrpcpp.hpp"
#include "server_settings.hpp"
// standard headers
#include <map>
#include <string>
namespace bp = boost::process;

View file

@ -16,7 +16,10 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
// prototype/interface header file
#include "stream_manager.hpp"
// local headers
#include "airplay_stream.hpp"
#ifdef HAS_ALSA
#include "alsa_stream.hpp"
@ -32,13 +35,17 @@
#include "process_stream.hpp"
#include "tcp_stream.hpp"
// 3rd party headers
// standard headers
using namespace std;
namespace streamreader
{
StreamManager::StreamManager(PcmListener* pcmListener, boost::asio::io_context& ioc, const ServerSettings& settings)
StreamManager::StreamManager(PcmStream::Listener* pcmListener, boost::asio::io_context& ioc, const ServerSettings& settings)
// const std::string& defaultSampleFormat, const std::string& defaultCodec, size_t defaultChunkBufferMs)
: pcmListener_(pcmListener), settings_(settings), ioc_(ioc)
{

View file

@ -19,10 +19,14 @@
#ifndef STREAM_MANAGER_HPP
#define STREAM_MANAGER_HPP
// local headers
#include "pcm_stream.hpp"
#include "server_settings.hpp"
// 3rd party headers
#include <boost/asio/io_context.hpp>
// standard headers
#include <memory>
#include <string>
#include <vector>
@ -35,7 +39,7 @@ using PcmStreamPtr = std::shared_ptr<PcmStream>;
class StreamManager
{
public:
StreamManager(PcmListener* pcmListener, boost::asio::io_context& ioc, const ServerSettings& settings);
StreamManager(PcmStream::Listener* pcmListener, boost::asio::io_context& ioc, const ServerSettings& settings);
PcmStreamPtr addStream(const std::string& uri);
PcmStreamPtr addStream(StreamUri& streamUri);
@ -49,7 +53,7 @@ public:
private:
std::vector<PcmStreamPtr> streams_;
PcmListener* pcmListener_;
PcmStream::Listener* pcmListener_;
ServerSettings settings_;
boost::asio::io_context& ioc_;
};

View file

@ -16,18 +16,21 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#include <cerrno>
#include <fcntl.h>
#include <memory>
#include <sys/stat.h>
#include <unistd.h>
// prototype/interface header file
#include "tcp_stream.hpp"
// local headers
#include "common/aixlog.hpp"
#include "common/snap_exception.hpp"
#include "common/str_compat.hpp"
#include "common/utils/string_utils.hpp"
#include "encoder/encoder_factory.hpp"
#include "tcp_stream.hpp"
// 3rd party headers
// standard headers
#include <cerrno>
#include <memory>
using namespace std;
@ -37,7 +40,7 @@ namespace streamreader
static constexpr auto LOG_TAG = "TcpStream";
TcpStream::TcpStream(PcmListener* pcmListener, boost::asio::io_context& ioc, const ServerSettings& server_settings, const StreamUri& uri)
TcpStream::TcpStream(PcmStream::Listener* pcmListener, boost::asio::io_context& ioc, const ServerSettings& server_settings, const StreamUri& uri)
: AsioStream<tcp::socket>(pcmListener, ioc, server_settings, uri), reconnect_timer_(ioc)
{
host_ = uri_.host;

View file

@ -19,6 +19,7 @@
#ifndef TCP_STREAM_HPP
#define TCP_STREAM_HPP
// local headers
#include "asio_stream.hpp"
using boost::asio::ip::tcp;
@ -30,13 +31,13 @@ namespace streamreader
/**
* Reads PCM from a named pipe and passes the data to an encoder.
* Implements EncoderListener to get the encoded data.
* Data is passed to the PcmListener
* Data is passed to the PcmStream::Listener
*/
class TcpStream : public AsioStream<tcp::socket>
{
public:
/// ctor. Encoded PCM data is passed to the PipeListener
TcpStream(PcmListener* pcmListener, boost::asio::io_context& ioc, const ServerSettings& server_settings, const StreamUri& uri);
TcpStream(PcmStream::Listener* pcmListener, boost::asio::io_context& ioc, const ServerSettings& server_settings, const StreamUri& uri);
protected:
void do_connect() override;