mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-13 00:56:44 +02:00
buffering
git-svn-id: svn://elaine/murooma/trunk@33 d8a302eb-03bc-478d-80e4-98257eca68ef
This commit is contained in:
parent
5f01c5b99e
commit
fcf5250a47
2 changed files with 16 additions and 9 deletions
2
chunk.h
2
chunk.h
|
@ -1,7 +1,7 @@
|
||||||
#ifndef CHUNK_H
|
#ifndef CHUNK_H
|
||||||
#define CHUNK_H
|
#define CHUNK_H
|
||||||
|
|
||||||
#define MS (20)
|
#define MS (50)
|
||||||
//44100 / 20 = 2205
|
//44100 / 20 = 2205
|
||||||
#define SAMPLE_RATE (44100)
|
#define SAMPLE_RATE (44100)
|
||||||
#define SIZE (SAMPLE_RATE*4*MS/1000)
|
#define SIZE (SAMPLE_RATE*4*MS/1000)
|
||||||
|
|
21
client.cpp
21
client.cpp
|
@ -163,7 +163,7 @@ static int patestCallback( const void *inputBuffer, void *outputBuffer,
|
||||||
PaStreamCallbackFlags statusFlags,
|
PaStreamCallbackFlags statusFlags,
|
||||||
void *userData )
|
void *userData )
|
||||||
{
|
{
|
||||||
std::cerr << "outputBufferDacTime: " << timeInfo->outputBufferDacTime*1000 << "\n";
|
// std::cerr << "outputBufferDacTime: " << timeInfo->outputBufferDacTime*1000 << "\n";
|
||||||
std::deque<Chunk*>* chunks = (std::deque<Chunk*>*)userData;
|
std::deque<Chunk*>* chunks = (std::deque<Chunk*>*)userData;
|
||||||
short* out = (short*)outputBuffer;
|
short* out = (short*)outputBuffer;
|
||||||
unsigned long i;
|
unsigned long i;
|
||||||
|
@ -181,24 +181,31 @@ static int patestCallback( const void *inputBuffer, void *outputBuffer,
|
||||||
cv.wait(lck);
|
cv.wait(lck);
|
||||||
mutex.lock();
|
mutex.lock();
|
||||||
chunk = chunks->front();
|
chunk = chunks->front();
|
||||||
std::cerr << "Chunks: " << chunks->size() << "\n";
|
// std::cerr << "Chunks: " << chunks->size() << "\n";
|
||||||
chunks->pop_front();
|
|
||||||
mutex.unlock();
|
mutex.unlock();
|
||||||
age = getAge(*chunk) + timeInfo->outputBufferDacTime*1000;
|
age = getAge(*chunk) + timeInfo->outputBufferDacTime*1000;
|
||||||
std::cerr << "age: " << getAge(*chunk) << "\t" << age << "\n";
|
std::cerr << "age: " << getAge(*chunk) << "\t" << age << "\t" << timeInfo->outputBufferDacTime*1000 << "\n";
|
||||||
if (age > bufferMs + 150)
|
if (age > bufferMs + 2*MS)
|
||||||
{
|
{
|
||||||
|
chunks->pop_front();
|
||||||
delete chunk;
|
delete chunk;
|
||||||
|
std::cerr << "packe too old, dropping\n";
|
||||||
usleep(100);
|
usleep(100);
|
||||||
}
|
}
|
||||||
else if (age < bufferMs)
|
else if (age < bufferMs - 2*MS)
|
||||||
{
|
{
|
||||||
usleep(((bufferMs - age) + 100) * 1000);
|
chunk = new Chunk();
|
||||||
|
memset(&(chunk->payload[0]), 0, SIZE);
|
||||||
|
std::cerr << "age < bufferMs (" << age << " < " << bufferMs << "), playing silence\n";
|
||||||
|
usleep(10 * 1000);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
chunks->pop_front();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for( i=0; i<framesPerBuffer; i++)
|
for( i=0; i<framesPerBuffer; i++)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue