1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
/***
This file is part of snapcast
Copyright (C) 2014-2025 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
the Free Software Foundation, either version 3 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, see <http://www.gnu.org/licenses/>.
***/
#pragma once
// local headers
#include "process_stream.hpp"
// 3rd party headers
#include <boost/asio/streambuf.hpp>
// Expat is used in metadata parsing from Shairport-sync.
// Without HAS_EXPAT defined no parsing will occur.
#ifdef HAS_EXPAT
#include <expat.h>
#endif
namespace streamreader
{
/// Tage entry??
struct TageEntry
{
std::string code; ///< code
std::string type; ///< type
std::string data; ///< data
bool isBase64{false}; ///< is base64?
int length{0}; ///< length
};
/**
* Starts shairport-sync, reads PCM data from stdout, and passes the data to an encoder.
* Implements EncoderListener to get the encoded data.
* Data is passed to the PcmStream::Listener
* usage:
* snapserver -s "airplay:///shairport-sync?name=Airplay[&devicename=Snapcast][&port=5000]"
*/
class AirplayStream : public ProcessStream
{
public:
/// c'tor. Encoded PCM data is passed to the PipeListener
AirplayStream(PcmStream::Listener* pcmListener, boost::asio::io_context& ioc, const ServerSettings& server_settings, const StreamUri& uri,
PcmStream::Source source);
/// d'tor
~AirplayStream() override;
private:
#ifdef HAS_EXPAT
XML_Parser parser_;
std::unique_ptr<TageEntry> entry_;
std::string buf_;
/// set whenever metadata_ has changed
Metadata meta_;
bool metadata_dirty_;
#endif
void pipeReadLine();
#ifdef HAS_EXPAT
int parse(const std::string& line);
void createParser();
void push();
template <typename T>
void setMetaData(std::optional<T>& meta_value, const T& value);
#endif
void setParamsAndPipePathFromPort();
void connect() override;
void disconnect() override;
void onStderrMsg(const std::string& line) override;
void initExeAndPath(const std::string& filename) override;
size_t port_;
std::string pipePath_;
std::string params_wo_port_;
std::unique_ptr<boost::asio::posix::stream_descriptor> pipe_fd_;
boost::asio::steady_timer pipe_open_timer_;
boost::asio::streambuf streambuf_pipe_;
#ifdef HAS_EXPAT
static void XMLCALL element_start(void* userdata, const char* element_name, const char** attr);
static void XMLCALL element_end(void* userdata, const char* element_name);
static void XMLCALL data(void* userdata, const char* content, int length);
#endif
private:
AixLog::Severity read_logseverity_{AixLog::Severity::info};
};
} // namespace streamreader
|