mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-17 19:16:14 +02:00
Rename onChunkRead to onNewChunk
This commit is contained in:
parent
01ce9a60c0
commit
ed0521a1d2
7 changed files with 16 additions and 5 deletions
|
@ -27,6 +27,7 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
namespace cs = chronos;
|
namespace cs = chronos;
|
||||||
|
|
||||||
|
|
|
@ -134,7 +134,7 @@ public:
|
||||||
SampleFormat format;
|
SampleFormat format;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint32_t idx_;
|
uint32_t idx_ = 0;
|
||||||
};
|
};
|
||||||
} // namespace msg
|
} // namespace msg
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,7 @@ PcmEncoder::PcmEncoder(const std::string& codecOptions) : Encoder(codecOptions)
|
||||||
|
|
||||||
void PcmEncoder::encode(const msg::PcmChunk* chunk)
|
void PcmEncoder::encode(const msg::PcmChunk* chunk)
|
||||||
{
|
{
|
||||||
|
// copy the chunk into a shared_ptr
|
||||||
auto pcmChunk = std::make_shared<msg::PcmChunk>(*chunk);
|
auto pcmChunk = std::make_shared<msg::PcmChunk>(*chunk);
|
||||||
listener_->onChunkEncoded(this, pcmChunk, pcmChunk->durationMs());
|
listener_->onChunkEncoded(this, pcmChunk, pcmChunk->durationMs());
|
||||||
}
|
}
|
||||||
|
|
|
@ -197,7 +197,7 @@ void AsioStream<ReadStream>::do_read()
|
||||||
nextTick_ = std::chrono::steady_clock::now();
|
nextTick_ = std::chrono::steady_clock::now();
|
||||||
}
|
}
|
||||||
|
|
||||||
encoder_->encode(chunk_.get());
|
onChunkRead(chunk_.get());
|
||||||
nextTick_ += chunk_->duration<std::chrono::nanoseconds>();
|
nextTick_ += chunk_->duration<std::chrono::nanoseconds>();
|
||||||
auto currentTick = std::chrono::steady_clock::now();
|
auto currentTick = std::chrono::steady_clock::now();
|
||||||
|
|
||||||
|
|
|
@ -133,13 +133,21 @@ void PcmStream::onChunkEncoded(const encoder::Encoder* /*encoder*/, std::shared_
|
||||||
if (duration <= 0)
|
if (duration <= 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// absolute start timestamp is the tvEncodedChunk_
|
||||||
auto microsecs = std::chrono::duration_cast<std::chrono::microseconds>(tvEncodedChunk_.time_since_epoch()).count();
|
auto microsecs = std::chrono::duration_cast<std::chrono::microseconds>(tvEncodedChunk_.time_since_epoch()).count();
|
||||||
chunk->timestamp.sec = microsecs / 1000000;
|
chunk->timestamp.sec = microsecs / 1000000;
|
||||||
chunk->timestamp.usec = microsecs % 1000000;
|
chunk->timestamp.usec = microsecs % 1000000;
|
||||||
|
|
||||||
|
// update tvEncodedChunk_ to the next chunk start by adding the current chunk duration
|
||||||
tvEncodedChunk_ += std::chrono::nanoseconds(static_cast<std::chrono::nanoseconds::rep>(duration * 1000000));
|
tvEncodedChunk_ += std::chrono::nanoseconds(static_cast<std::chrono::nanoseconds::rep>(duration * 1000000));
|
||||||
if (pcmListener_)
|
if (pcmListener_)
|
||||||
pcmListener_->onChunkRead(this, chunk, duration);
|
pcmListener_->onNewChunk(this, chunk, duration);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PcmStream::onChunkRead(const msg::PcmChunk* chunk)
|
||||||
|
{
|
||||||
|
encoder_->encode(chunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,7 @@ class PcmListener
|
||||||
public:
|
public:
|
||||||
virtual void onMetaChanged(const PcmStream* pcmStream) = 0;
|
virtual void onMetaChanged(const PcmStream* pcmStream) = 0;
|
||||||
virtual void onStateChanged(const PcmStream* pcmStream, const ReaderState& state) = 0;
|
virtual void onStateChanged(const PcmStream* pcmStream, const ReaderState& state) = 0;
|
||||||
virtual void onChunkRead(const PcmStream* pcmStream, std::shared_ptr<msg::PcmChunk> chunk, double duration) = 0;
|
virtual void onNewChunk(const PcmStream* pcmStream, std::shared_ptr<msg::PcmChunk> chunk, double duration) = 0;
|
||||||
virtual void onResync(const PcmStream* pcmStream, double ms) = 0;
|
virtual void onResync(const PcmStream* pcmStream, double ms) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -102,6 +102,7 @@ protected:
|
||||||
std::atomic<bool> active_;
|
std::atomic<bool> active_;
|
||||||
|
|
||||||
void setState(const ReaderState& newState);
|
void setState(const ReaderState& newState);
|
||||||
|
virtual void onChunkRead(const msg::PcmChunk* chunk);
|
||||||
|
|
||||||
std::chrono::time_point<std::chrono::steady_clock> tvEncodedChunk_;
|
std::chrono::time_point<std::chrono::steady_clock> tvEncodedChunk_;
|
||||||
PcmListener* pcmListener_;
|
PcmListener* pcmListener_;
|
||||||
|
|
|
@ -123,7 +123,7 @@ void PosixStream::do_read()
|
||||||
if ((idle_bytes_ == 0) || (idle_bytes_ <= max_idle_bytes_))
|
if ((idle_bytes_ == 0) || (idle_bytes_ <= max_idle_bytes_))
|
||||||
{
|
{
|
||||||
// the encoder will update the tvEncodedChunk when a chunk is encoded
|
// the encoder will update the tvEncodedChunk when a chunk is encoded
|
||||||
encoder_->encode(chunk_.get());
|
onChunkRead(chunk_.get());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue