diff --git a/client/player/alsaPlayer.cpp b/client/player/alsaPlayer.cpp index 5afd8739..10c5f128 100644 --- a/client/player/alsaPlayer.cpp +++ b/client/player/alsaPlayer.cpp @@ -198,6 +198,8 @@ void AlsaPlayer::worker() { snd_pcm_sframes_t pcm; snd_pcm_sframes_t framesDelay; + long lastChunkTick = 0; + while (active_) { if (handle_ == NULL) @@ -220,6 +222,7 @@ void AlsaPlayer::worker() if (stream_->getPlayerChunk(buff_, delay, frames_)) { + lastChunkTick = chronos::getTickCount(); adjustVolume(buff_, frames_); if ((pcm = snd_pcm_writei(handle_, buff_, frames_)) == -EPIPE) { @@ -236,7 +239,15 @@ void AlsaPlayer::worker() { logO << "Failed to get chunk\n"; while (active_ && !stream_->waitForChunk(100)) + { logD << "Waiting for chunk\n"; + if ((handle_ != NULL) && (chronos::getTickCount() - lastChunkTick > 5000)) + { + logO << "No chunk received for 5000ms. Closing ALSA.\n"; + uninitAlsa(); + stream_->clearChunks(); + } + } } } } diff --git a/client/stream.cpp b/client/stream.cpp index 9be367ee..3e88cd92 100644 --- a/client/stream.cpp +++ b/client/stream.cpp @@ -67,6 +67,7 @@ void Stream::clearChunks() { while (chunks_.size() > 0) chunks_.pop(); + resetBuffers(); } @@ -364,7 +365,7 @@ bool Stream::getPlayerChunk(void* outputBuffer, const cs::usec& outputBufferDacT logO << "Chunk: " << age.count()/100 << "\t" << miniBuffer_.median()/100 << "\t" << shortMedian_/100 << "\t" << median_/100 << "\t" << buffer_.size() << "\t" << cs::duration(outputBufferDacTime) << "\n"; // logO << "Chunk: " << age.count()/1000 << "\t" << miniBuffer_.median()/1000 << "\t" << shortMedian_/1000 << "\t" << median_/1000 << "\t" << buffer_.size() << "\t" << cs::duration(outputBufferDacTime) << "\n"; } - return true; + return (abs(cs::duration(age)) < 500); } catch(int e) { diff --git a/notes.txt b/notes.txt index 44dd8194..7924554b 100644 --- a/notes.txt +++ b/notes.txt @@ -83,3 +83,11 @@ https://en.wikipedia.org/wiki/Uniform_Resource_Identifier -HiRes Audio -Android auto start -pipe creation mode: `-s pipe:///tmp/snapfifo?mode=[read|create]` + + +*Dependencies +libavahi-client3 +libflac8 +libogg0 +libvorbis0a +libvorbisenc2