Delete UDP stream

This commit is contained in:
badaix 2019-11-27 23:03:13 +01:00
parent 40c910104b
commit 22262bd203
5 changed files with 1 additions and 157 deletions

View file

@ -13,7 +13,6 @@ set(SERVER_SOURCES
streamreader/stream_manager.cpp streamreader/stream_manager.cpp
streamreader/pcm_stream.cpp streamreader/pcm_stream.cpp
streamreader/tcp_stream.cpp streamreader/tcp_stream.cpp
streamreader/udp_stream.cpp
streamreader/pipe_stream.cpp streamreader/pipe_stream.cpp
streamreader/file_stream.cpp streamreader/file_stream.cpp
streamreader/airplay_stream.cpp streamreader/airplay_stream.cpp

View file

@ -44,7 +44,7 @@ endif
CXXFLAGS += $(ADD_CFLAGS) -std=c++14 -Wall -Wextra -Wpedantic -Wno-unused-function -DBOOST_ERROR_CODE_HEADER_ONLY -DHAS_FLAC -DHAS_OGG -DHAS_VORBIS -DHAS_VORBIS_ENC -DHAS_OPUS -DVERSION=\"$(VERSION)\" -I. -I.. -I../common CXXFLAGS += $(ADD_CFLAGS) -std=c++14 -Wall -Wextra -Wpedantic -Wno-unused-function -DBOOST_ERROR_CODE_HEADER_ONLY -DHAS_FLAC -DHAS_OGG -DHAS_VORBIS -DHAS_VORBIS_ENC -DHAS_OPUS -DVERSION=\"$(VERSION)\" -I. -I.. -I../common
LDFLAGS += $(ADD_LDFLAGS) -lvorbis -lvorbisenc -logg -lFLAC -lopus LDFLAGS += $(ADD_LDFLAGS) -lvorbis -lvorbisenc -logg -lFLAC -lopus
OBJ = snapserver.o config.o control_server.o control_session_tcp.o control_session_http.o stream_server.o stream_session.o streamreader/stream_uri.o streamreader/base64.o streamreader/stream_manager.o streamreader/pcm_stream.o streamreader/pipe_stream.o streamreader/file_stream.o streamreader/process_stream.o streamreader/airplay_stream.o streamreader/librespot_stream.o streamreader/watchdog.o encoder/encoder_factory.o encoder/flac_encoder.o encoder/opus_encoder.o encoder/pcm_encoder.o encoder/ogg_encoder.o ../common/sample_format.o OBJ = snapserver.o config.o control_server.o control_session_tcp.o control_session_http.o stream_server.o stream_session.o streamreader/stream_uri.o streamreader/base64.o streamreader/stream_manager.o streamreader/pcm_stream.o streamreader/pipe_stream.o streamreader/file_stream.o streamreader/tcp_stream.o streamreader/process_stream.o streamreader/airplay_stream.o streamreader/librespot_stream.o streamreader/watchdog.o encoder/encoder_factory.o encoder/flac_encoder.o encoder/opus_encoder.o encoder/pcm_encoder.o encoder/ogg_encoder.o ../common/sample_format.o
ifneq (,$(TARGET)) ifneq (,$(TARGET))
CXXFLAGS += -D$(TARGET) CXXFLAGS += -D$(TARGET)

View file

@ -27,7 +27,6 @@
#include "pipe_stream.hpp" #include "pipe_stream.hpp"
#include "process_stream.hpp" #include "process_stream.hpp"
#include "tcp_stream.hpp" #include "tcp_stream.hpp"
#include "udp_stream.hpp"
using namespace std; using namespace std;
@ -84,10 +83,6 @@ PcmStreamPtr StreamManager::addStream(const std::string& uri)
{ {
stream = make_shared<TcpStream>(pcmListener_, ioc_, streamUri); stream = make_shared<TcpStream>(pcmListener_, ioc_, streamUri);
} }
else if (streamUri.scheme == "experimental.udp")
{
stream = make_shared<UdpStream>(pcmListener_, ioc_, streamUri);
}
else else
{ {
throw SnapException("Unknown stream type: " + streamUri.scheme); throw SnapException("Unknown stream type: " + streamUri.scheme);

View file

@ -1,97 +0,0 @@
/***
This file is part of snapcast
Copyright (C) 2014-2019 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/>.
***/
#include <cerrno>
#include <fcntl.h>
#include <memory>
#include <sys/stat.h>
#include <unistd.h>
#include "common/aixlog.hpp"
#include "common/snap_exception.hpp"
#include "common/str_compat.hpp"
#include "encoder/encoder_factory.hpp"
#include "udp_stream.hpp"
using namespace std;
UdpStream::UdpStream(PcmListener* pcmListener, boost::asio::io_context& ioc, const StreamUri& uri) : PcmStream(pcmListener, ioc, uri)
{
size_t port = 5004;
try
{
port = cpt::stoi(uri_.getQuery("port", cpt::to_string(port)));
}
catch (...)
{
}
LOG(INFO) << "UdpStream port: " << port << "\n";
socket_ = make_unique<udp::socket>(ioc_, udp::endpoint(udp::v4(), port));
chunk_ = make_unique<msg::PcmChunk>(sampleFormat_, pcmReadMs_);
LOG(DEBUG) << "Chunk size: " << chunk_->payloadSize << "\n";
}
UdpStream::~UdpStream()
{
}
void UdpStream::start()
{
encoder_->init(this, sampleFormat_);
active_ = true;
tv_chunk_.tv_sec = 0;
do_read();
}
void UdpStream::do_read()
{
auto self = shared_from_this();
if (tv_chunk_.tv_sec != 0)
{
chunk_->timestamp.sec = tv_chunk_.tv_sec;
chunk_->timestamp.usec = tv_chunk_.tv_usec;
// tvEncodedChunk_ = tv_chunk_;
chronos::addUs(tv_chunk_, pcmReadMs_ * 1000);
// chronos::systemtimeofday(&tv_chunk_);
}
socket_->async_receive_from(boost::asio::buffer(chunk_->payload, chunk_->payloadSize), sender_endpoint_,
[this, self](boost::system::error_code ec, std::size_t bytes_recvd) {
if (ec)
{
LOG(ERROR) << "Error reading message: " << ec.message() << "\n";
return;
}
LOG(DEBUG) << "Read: " << bytes_recvd << " bytes\n";
if (tv_chunk_.tv_sec == 0)
{
chronos::systemtimeofday(&tv_chunk_);
chunk_->timestamp.sec = tv_chunk_.tv_sec;
chunk_->timestamp.usec = tv_chunk_.tv_usec;
tvEncodedChunk_ = tv_chunk_;
}
// encoder_->encode(chunk_.get());
do_read();
});
}

View file

@ -1,53 +0,0 @@
/***
This file is part of snapcast
Copyright (C) 2014-2019 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/>.
***/
#ifndef UDP_STREAM_HPP
#define UDP_STREAM_HPP
#include "pcm_stream.hpp"
#include <boost/asio.hpp>
#include <memory>
using boost::asio::ip::udp;
/// Reads and decodes PCM data from a named pipe
/**
* 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
*/
class UdpStream : public PcmStream, public std::enable_shared_from_this<UdpStream>
{
public:
/// ctor. Encoded PCM data is passed to the PipeListener
UdpStream(PcmListener* pcmListener, boost::asio::io_context& ioc, const StreamUri& uri);
~UdpStream() override;
void start() override;
protected:
void do_read();
std::unique_ptr<udp::socket> socket_;
std::unique_ptr<msg::PcmChunk> chunk_;
timeval tv_chunk_;
udp::endpoint sender_endpoint_;
};
#endif