mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-20 12:36:17 +02:00
playerchunk
git-svn-id: svn://elaine/murooma/trunk@46 d8a302eb-03bc-478d-80e4-98257eca68ef
This commit is contained in:
parent
8699eb8bc2
commit
a0e58017e1
3 changed files with 25 additions and 16 deletions
2
chunk.h
2
chunk.h
|
@ -11,7 +11,7 @@
|
||||||
#define PLAYER_CHUNK_MS (5)
|
#define PLAYER_CHUNK_MS (5)
|
||||||
#define PLAYER_CHUNK_SIZE (SAMPLE_RATE*CHANNELS*SAMPLE_BIT/8*PLAYER_CHUNK_MS/1000)
|
#define PLAYER_CHUNK_SIZE (SAMPLE_RATE*CHANNELS*SAMPLE_BIT/8*PLAYER_CHUNK_MS/1000)
|
||||||
|
|
||||||
#define FRAMES_PER_BUFFER (WIRE_CHUNK_SIZE/4)
|
#define FRAMES_PER_BUFFER (PLAYER_CHUNK_SIZE/(CHANNELS*SAMPLE_BIT/8))
|
||||||
|
|
||||||
int bufferMs;
|
int bufferMs;
|
||||||
|
|
||||||
|
|
33
client.cpp
33
client.cpp
|
@ -23,7 +23,7 @@
|
||||||
|
|
||||||
|
|
||||||
DoubleBuffer<int> buffer(30000 / WIRE_CHUNK_MS);
|
DoubleBuffer<int> buffer(30000 / WIRE_CHUNK_MS);
|
||||||
std::deque<Chunk*> chunks;
|
std::deque<PlayerChunk*> chunks;
|
||||||
std::deque<int> timeDiffs;
|
std::deque<int> timeDiffs;
|
||||||
std::mutex mtx;
|
std::mutex mtx;
|
||||||
std::mutex mutex;
|
std::mutex mutex;
|
||||||
|
@ -54,7 +54,7 @@ void player()
|
||||||
if (chunks.empty())
|
if (chunks.empty())
|
||||||
cv.wait(lck);
|
cv.wait(lck);
|
||||||
mutex.lock();
|
mutex.lock();
|
||||||
Chunk* chunk = chunks.front();
|
PlayerChunk* chunk = chunks.front();
|
||||||
// std::cerr << "Chunks: " << chunks.size() << "\n";
|
// std::cerr << "Chunks: " << chunks.size() << "\n";
|
||||||
chunks.pop_front();
|
chunks.pop_front();
|
||||||
mutex.unlock();
|
mutex.unlock();
|
||||||
|
@ -128,7 +128,7 @@ static int patestCallback( const void *inputBuffer, void *outputBuffer,
|
||||||
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<PlayerChunk*>* chunks = (std::deque<PlayerChunk*>*)userData;
|
||||||
short* out = (short*)outputBuffer;
|
short* out = (short*)outputBuffer;
|
||||||
unsigned long i;
|
unsigned long i;
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ static int patestCallback( const void *inputBuffer, void *outputBuffer,
|
||||||
|
|
||||||
std::unique_lock<std::mutex> lck(mtx);
|
std::unique_lock<std::mutex> lck(mtx);
|
||||||
int age = 0;
|
int age = 0;
|
||||||
Chunk* chunk = NULL;
|
PlayerChunk* chunk = NULL;
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
if (chunks->empty())
|
if (chunks->empty())
|
||||||
|
@ -161,7 +161,7 @@ static int patestCallback( const void *inputBuffer, void *outputBuffer,
|
||||||
}
|
}
|
||||||
else if (/*!buffer.full() &&*/ (age < bufferMs - std::max(100, 2*WIRE_CHUNK_MS)))
|
else if (/*!buffer.full() &&*/ (age < bufferMs - std::max(100, 2*WIRE_CHUNK_MS)))
|
||||||
{
|
{
|
||||||
chunk = new Chunk();
|
chunk = new PlayerChunk();
|
||||||
memset(&(chunk->payload[0]), 0, WIRE_CHUNK_SIZE);
|
memset(&(chunk->payload[0]), 0, WIRE_CHUNK_SIZE);
|
||||||
std::cerr << "age < bufferMs (" << age << " < " << bufferMs << "), playing silence\n";
|
std::cerr << "age < bufferMs (" << age << " < " << bufferMs << "), playing silence\n";
|
||||||
usleep(10 * 1000);
|
usleep(10 * 1000);
|
||||||
|
@ -181,7 +181,7 @@ static int patestCallback( const void *inputBuffer, void *outputBuffer,
|
||||||
buffer.clear();
|
buffer.clear();
|
||||||
if (bufferMs - median > WIRE_CHUNK_MS)
|
if (bufferMs - median > WIRE_CHUNK_MS)
|
||||||
{
|
{
|
||||||
chunk = new Chunk();
|
chunk = new PlayerChunk();
|
||||||
memset(&(chunk->payload[0]), 0, WIRE_CHUNK_SIZE);
|
memset(&(chunk->payload[0]), 0, WIRE_CHUNK_SIZE);
|
||||||
sleepMs(bufferMs - median - WIRE_CHUNK_MS + 10);
|
sleepMs(bufferMs - median - WIRE_CHUNK_MS + 10);
|
||||||
break;
|
break;
|
||||||
|
@ -238,7 +238,7 @@ int initAudio()
|
||||||
fprintf(stderr,"Error: No default output device.\n");
|
fprintf(stderr,"Error: No default output device.\n");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
outputParameters.channelCount = 2; /* stereo output */
|
outputParameters.channelCount = CHANNELS; /* stereo output */
|
||||||
outputParameters.sampleFormat = paInt16; /* 32 bit floating point output */
|
outputParameters.sampleFormat = paInt16; /* 32 bit floating point output */
|
||||||
outputParameters.suggestedLatency = Pa_GetDeviceInfo( outputParameters.device )->defaultLowOutputLatency;
|
outputParameters.suggestedLatency = Pa_GetDeviceInfo( outputParameters.device )->defaultLowOutputLatency;
|
||||||
outputParameters.hostApiSpecificStreamInfo = NULL;
|
outputParameters.hostApiSpecificStreamInfo = NULL;
|
||||||
|
@ -307,14 +307,21 @@ int main (int argc, char *argv[])
|
||||||
subscriber.recv(&update);
|
subscriber.recv(&update);
|
||||||
Chunk* chunk = new Chunk();
|
Chunk* chunk = new Chunk();
|
||||||
memcpy(chunk, update.data(), sizeof(Chunk));
|
memcpy(chunk, update.data(), sizeof(Chunk));
|
||||||
timeval now;
|
for (size_t n=0; n<WIRE_CHUNK_MS/PLAYER_CHUNK_MS; ++n)
|
||||||
gettimeofday(&now, NULL);
|
{
|
||||||
|
PlayerChunk* playerChunk = new PlayerChunk();
|
||||||
|
// for (size_t m=0; m<PLAYER_CHUNK_SIZE; ++m)
|
||||||
|
memcpy(&(playerChunk->payload[0]), &chunk->payload[n*PLAYER_CHUNK_SIZE], PLAYER_CHUNK_SIZE);
|
||||||
|
mutex.lock();
|
||||||
|
chunks.push_back(playerChunk);
|
||||||
|
mutex.unlock();
|
||||||
|
cv.notify_all();
|
||||||
|
}
|
||||||
|
|
||||||
|
// timeval now;
|
||||||
|
// gettimeofday(&now, NULL);
|
||||||
// std::cerr << "New chunk: " << chunkTime(*chunk) << "\t" << timeToStr(now) << "\t" << getAge(*chunk) << "\n";
|
// std::cerr << "New chunk: " << chunkTime(*chunk) << "\t" << timeToStr(now) << "\t" << getAge(*chunk) << "\n";
|
||||||
|
|
||||||
mutex.lock();
|
|
||||||
chunks.push_back(chunk);
|
|
||||||
mutex.unlock();
|
|
||||||
cv.notify_all();
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,8 @@ std::string timeToStr(const timeval& timestamp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string chunkTime(const Chunk& chunk)
|
template <typename T>
|
||||||
|
std::string chunkTime(const T& chunk)
|
||||||
{
|
{
|
||||||
timeval ts;
|
timeval ts;
|
||||||
ts.tv_sec = chunk.tv_sec;
|
ts.tv_sec = chunk.tv_sec;
|
||||||
|
@ -32,7 +33,8 @@ int diff_ms(const timeval& t1, const timeval& t2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int getAge(const Chunk& chunk)
|
template <typename T>
|
||||||
|
int getAge(const T& chunk)
|
||||||
{
|
{
|
||||||
timeval now;
|
timeval now;
|
||||||
gettimeofday(&now, NULL);
|
gettimeofday(&now, NULL);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue