diff --git a/stream.cpp b/stream.cpp index 66f0ba35..3e597b93 100644 --- a/stream.cpp +++ b/stream.cpp @@ -24,19 +24,7 @@ void Stream::setBufferLen(size_t bufferLenMs) void Stream::addChunk(Chunk* chunk) { -// Chunk* c = new Chunk(*chunk); -// mutex.lock(); chunks.push(shared_ptr(chunk)); -// mutex.unlock(); -} - - - -shared_ptr Stream::getNextChunk() -{ - if (!chunk) - chunk = chunks.pop(); - return chunk; } @@ -50,7 +38,9 @@ void Stream::getSilentPlayerChunk(short* outputBuffer) time_point_ms Stream::getNextPlayerChunk(short* outputBuffer, int correction) { - chunk = getNextChunk(); + if (!chunk) + chunk = chunks.pop(); + time_point_ms tp = chunk->timePoint(); int read = 0; int toRead = PLAYER_CHUNK_SIZE + correction*PLAYER_CHUNK_MS_SIZE; @@ -65,10 +55,7 @@ time_point_ms Stream::getNextPlayerChunk(short* outputBuffer, int correction) { read += chunk->read(buffer + read, toRead - read); if (chunk->isEndOfChunk()) - { - chunk = NULL; - chunk = getNextChunk(); - } + chunk = chunks.pop(); } if (correction != 0) diff --git a/stream.h b/stream.h index 25df9364..04e263cb 100644 --- a/stream.h +++ b/stream.h @@ -18,13 +18,12 @@ class Stream public: Stream(); void addChunk(Chunk* chunk); - std::shared_ptr getNextChunk(); - time_point_ms getNextPlayerChunk(short* outputBuffer, int correction = 0); - void getSilentPlayerChunk(short* outputBuffer); void getChunk(short* outputBuffer, double outputBufferDacTime, unsigned long framesPerBuffer); void setBufferLen(size_t bufferLenMs); private: + time_point_ms getNextPlayerChunk(short* outputBuffer, int correction = 0); + void getSilentPlayerChunk(short* outputBuffer); void sleepMs(int ms); int sleep;