Replace some pointers with references

This commit is contained in:
badaix 2020-08-18 23:36:17 +02:00
parent dde63f9dd8
commit dec7306a84
17 changed files with 77 additions and 67 deletions

View file

@ -224,7 +224,7 @@ void AlsaStream::do_read()
tvEncodedChunk_ = std::chrono::steady_clock::now() - duration;
}
onChunkRead(chunk_.get());
onChunkRead(*chunk_);
nextTick_ += duration;
auto currentTick = std::chrono::steady_clock::now();

View file

@ -86,7 +86,8 @@ AsioStream<ReadStream>::AsioStream(PcmListener* pcmListener, boost::asio::io_con
: PcmStream(pcmListener, ioc, uri), read_timer_(ioc), state_timer_(ioc)
{
chunk_ = std::make_unique<msg::PcmChunk>(sampleFormat_, chunk_ms_);
LOG(DEBUG) << "Chunk duration: " << chunk_->durationMs() << " ms, frames: " << chunk_->getFrameCount() << ", size: " << chunk_->payloadSize << "\n";
LOG(DEBUG, "AsioStream") << "Chunk duration: " << chunk_->durationMs() << " ms, frames: " << chunk_->getFrameCount() << ", size: " << chunk_->payloadSize
<< "\n";
bytes_read_ = 0;
buffer_ms_ = 50;
@ -197,7 +198,7 @@ void AsioStream<ReadStream>::do_read()
nextTick_ = std::chrono::steady_clock::now();
}
onChunkRead(chunk_.get());
onChunkRead(*chunk_);
nextTick_ += chunk_->duration<std::chrono::nanoseconds>();
auto currentTick = std::chrono::steady_clock::now();

View file

@ -145,7 +145,7 @@ void PcmStream::onChunkEncoded(const encoder::Encoder* /*encoder*/, std::shared_
}
void PcmStream::onChunkRead(const msg::PcmChunk* chunk)
void PcmStream::onChunkRead(const msg::PcmChunk& chunk)
{
encoder_->encode(chunk);
}

View file

@ -102,7 +102,7 @@ protected:
std::atomic<bool> active_;
void setState(const ReaderState& newState);
virtual void onChunkRead(const msg::PcmChunk* chunk);
virtual void onChunkRead(const msg::PcmChunk& chunk);
std::chrono::time_point<std::chrono::steady_clock> tvEncodedChunk_;
PcmListener* pcmListener_;

View file

@ -105,7 +105,7 @@ void PosixStream::do_read()
}
else
{
// LOG(DEBUG) << "count: " << count << "\n";
// LOG(DEBUG, LOG_TAG) << "count: " << count << "\n";
len += count;
bytes_read_ += len;
idle_bytes_ = 0;
@ -123,7 +123,7 @@ void PosixStream::do_read()
if ((idle_bytes_ == 0) || (idle_bytes_ <= max_idle_bytes_))
{
// the encoder will update the tvEncodedChunk when a chunk is encoded
onChunkRead(chunk_.get());
onChunkRead(*chunk_);
}
else
{
@ -143,7 +143,8 @@ void PosixStream::do_read()
}
else if (next_read >= -kResyncTolerance)
{
LOG(INFO) << "next read < 0 (" << getName() << "): " << std::chrono::duration_cast<std::chrono::microseconds>(next_read).count() / 1000. << " ms\n";
LOG(INFO, LOG_TAG) << "next read < 0 (" << getName() << "): " << std::chrono::duration_cast<std::chrono::microseconds>(next_read).count() / 1000.
<< " ms\n";
do_read();
}
else

View file

@ -35,6 +35,8 @@ using namespace std;
namespace streamreader
{
static constexpr auto LOG_TAG = "TcpStream";
TcpStream::TcpStream(PcmListener* pcmListener, boost::asio::io_context& ioc, const StreamUri& uri)
: AsioStream<tcp::socket>(pcmListener, ioc, uri), reconnect_timer_(ioc)
{
@ -57,7 +59,7 @@ TcpStream::TcpStream(PcmListener* pcmListener, boost::asio::io_context& ioc, con
port_ = cpt::stoi(uri_.getQuery("port", cpt::to_string(port_)), port_);
LOG(INFO) << "TcpStream host: " << host_ << ", port: " << port_ << ", is server: " << is_server_ << "\n";
LOG(INFO, LOG_TAG) << "TcpStream host: " << host_ << ", port: " << port_ << ", is server: " << is_server_ << "\n";
if (is_server_)
acceptor_ = make_unique<tcp::acceptor>(ioc_, tcp::endpoint(boost::asio::ip::address::from_string(host_), port_));
}
@ -73,13 +75,13 @@ void TcpStream::do_connect()
acceptor_->async_accept([this](boost::system::error_code ec, tcp::socket socket) {
if (!ec)
{
LOG(DEBUG) << "New client connection\n";
LOG(DEBUG, LOG_TAG) << "New client connection\n";
stream_ = make_unique<tcp::socket>(move(socket));
on_connect();
}
else
{
LOG(ERROR) << "Accept failed: " << ec.message() << "\n";
LOG(ERROR, LOG_TAG) << "Accept failed: " << ec.message() << "\n";
}
});
}
@ -90,12 +92,12 @@ void TcpStream::do_connect()
stream_->async_connect(endpoint, [this](const boost::system::error_code& ec) {
if (!ec)
{
LOG(DEBUG) << "Connected\n";
LOG(DEBUG, LOG_TAG) << "Connected\n";
on_connect();
}
else
{
LOG(DEBUG) << "Connect failed: " << ec.message() << "\n";
LOG(DEBUG, LOG_TAG) << "Connect failed: " << ec.message() << "\n";
wait(reconnect_timer_, 1s, [this] { connect(); });
}
});