mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-10 07:36:41 +02:00
latency
git-svn-id: svn://elaine/murooma/trunk@311 d8a302eb-03bc-478d-80e4-98257eca68ef
This commit is contained in:
parent
5e9eebd7a7
commit
8710e5e898
4 changed files with 18 additions and 9 deletions
|
@ -48,10 +48,11 @@ void Controller::onMessageReceived(ClientConnection* connection, const BaseMessa
|
|||
}
|
||||
|
||||
|
||||
void Controller::start(const PcmDevice& pcmDevice, const std::string& _ip, size_t _port)
|
||||
void Controller::start(const PcmDevice& pcmDevice, const std::string& _ip, size_t _port, size_t latency)
|
||||
{
|
||||
ip = _ip;
|
||||
pcmDevice_ = pcmDevice;
|
||||
latency_ = latency;
|
||||
clientConnection = new ClientConnection(this, ip, _port);
|
||||
controllerThread = new thread(&Controller::worker, this);
|
||||
}
|
||||
|
@ -107,7 +108,7 @@ void Controller::worker()
|
|||
cout << "diff to server [ms]: " << TimeProvider::getInstance().getDiffToServer<chronos::msec>().count() << "\n";
|
||||
|
||||
stream = new Stream(*sampleFormat);
|
||||
stream->setBufferLen(serverSettings->bufferMs);
|
||||
stream->setBufferLen(serverSettings->bufferMs - latency_);
|
||||
|
||||
Player player(pcmDevice_, stream);
|
||||
player.start();
|
||||
|
|
|
@ -14,7 +14,7 @@ class Controller : public MessageReceiver
|
|||
{
|
||||
public:
|
||||
Controller();
|
||||
void start(const PcmDevice& pcmDevice, const std::string& _ip, size_t _port);
|
||||
void start(const PcmDevice& pcmDevice, const std::string& _ip, size_t _port, size_t latency);
|
||||
void stop();
|
||||
virtual void onMessageReceived(ClientConnection* connection, const BaseMessage& baseMessage, char* buffer);
|
||||
virtual void onException(ClientConnection* connection, const std::exception& exception);
|
||||
|
@ -29,6 +29,7 @@ private:
|
|||
std::shared_ptr<SampleFormat> sampleFormat;
|
||||
Decoder* decoder;
|
||||
PcmDevice pcmDevice_;
|
||||
size_t latency_;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -50,6 +50,7 @@ int main (int argc, char *argv[])
|
|||
string ip;
|
||||
// int bufferMs;
|
||||
size_t port;
|
||||
size_t latency;
|
||||
bool runAsDaemon;
|
||||
bool listPcmDevices;
|
||||
|
||||
|
@ -62,6 +63,7 @@ int main (int argc, char *argv[])
|
|||
("soundcard,s", po::value<string>(&soundcard)->default_value("default"), "index or name of the soundcard")
|
||||
// ("buffer,b", po::value<int>(&bufferMs)->default_value(300), "buffer size [ms]")
|
||||
("daemon,d", po::bool_switch(&runAsDaemon)->default_value(false), "daemonize")
|
||||
("latency", po::value<size_t>(&latency)->default_value(0), "latency")
|
||||
;
|
||||
|
||||
po::variables_map vm;
|
||||
|
@ -101,7 +103,7 @@ int main (int argc, char *argv[])
|
|||
|
||||
|
||||
Controller controller;
|
||||
controller.start(pcmDevice, ip, port);
|
||||
controller.start(pcmDevice, ip, port, latency);
|
||||
|
||||
while(true)
|
||||
usleep(10000);
|
||||
|
|
|
@ -17,6 +17,7 @@ Stream::Stream(const SampleFormat& sampleFormat) : format(format_), format_(samp
|
|||
bufferMs = msec(500);
|
||||
|
||||
playedSamples = 0;
|
||||
playedSamplesTime = time_point_hrc::min();
|
||||
/*
|
||||
48000 x
|
||||
------- = -----
|
||||
|
@ -173,13 +174,17 @@ void Stream::resetBuffers()
|
|||
|
||||
bool Stream::getPlayerChunk(void* outputBuffer, const chronos::usec& outputBufferDacTime, unsigned long framesPerBuffer)
|
||||
{
|
||||
/*if (playedSamples == 0)
|
||||
/*if (playedSamplesTime == time_point_hrc::min())
|
||||
playedSamplesTime = chronos::hrc::now() + outputBufferDacTime;
|
||||
playedSamples += framesPerBuffer;
|
||||
chronos::msec since = std::chrono::duration_cast<msec>(chronos::hrc::now() + outputBufferDacTime - playedSamplesTime);
|
||||
if (since.count() > 0)
|
||||
cout << (double)playedSamples / (double)since.count() << "\n";
|
||||
else
|
||||
{
|
||||
playedSamples += framesPerBuffer;
|
||||
chronos::msec since = std::chrono::duration_cast<msec>(chronos::hrc::now() + outputBufferDacTime - playedSamplesTime);
|
||||
if (since.count() > 0)
|
||||
cout << (double)playedSamples / (double)since.count() << "\n";
|
||||
}
|
||||
*/
|
||||
|
||||
if (outputBufferDacTime > bufferMs)
|
||||
return false;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue