close ALSA if there is no audio

This commit is contained in:
badaix 2016-08-10 08:49:16 +02:00
parent 3d43f51efd
commit cbdc850be1
3 changed files with 21 additions and 1 deletions

View file

@ -198,6 +198,8 @@ void AlsaPlayer::worker()
{ {
snd_pcm_sframes_t pcm; snd_pcm_sframes_t pcm;
snd_pcm_sframes_t framesDelay; snd_pcm_sframes_t framesDelay;
long lastChunkTick = 0;
while (active_) while (active_)
{ {
if (handle_ == NULL) if (handle_ == NULL)
@ -220,6 +222,7 @@ void AlsaPlayer::worker()
if (stream_->getPlayerChunk(buff_, delay, frames_)) if (stream_->getPlayerChunk(buff_, delay, frames_))
{ {
lastChunkTick = chronos::getTickCount();
adjustVolume(buff_, frames_); adjustVolume(buff_, frames_);
if ((pcm = snd_pcm_writei(handle_, buff_, frames_)) == -EPIPE) if ((pcm = snd_pcm_writei(handle_, buff_, frames_)) == -EPIPE)
{ {
@ -236,7 +239,15 @@ void AlsaPlayer::worker()
{ {
logO << "Failed to get chunk\n"; logO << "Failed to get chunk\n";
while (active_ && !stream_->waitForChunk(100)) while (active_ && !stream_->waitForChunk(100))
{
logD << "Waiting for chunk\n"; logD << "Waiting for chunk\n";
if ((handle_ != NULL) && (chronos::getTickCount() - lastChunkTick > 5000))
{
logO << "No chunk received for 5000ms. Closing ALSA.\n";
uninitAlsa();
stream_->clearChunks();
}
}
} }
} }
} }

View file

@ -67,6 +67,7 @@ void Stream::clearChunks()
{ {
while (chunks_.size() > 0) while (chunks_.size() > 0)
chunks_.pop(); 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<cs::msec>(outputBufferDacTime) << "\n"; logO << "Chunk: " << age.count()/100 << "\t" << miniBuffer_.median()/100 << "\t" << shortMedian_/100 << "\t" << median_/100 << "\t" << buffer_.size() << "\t" << cs::duration<cs::msec>(outputBufferDacTime) << "\n";
// logO << "Chunk: " << age.count()/1000 << "\t" << miniBuffer_.median()/1000 << "\t" << shortMedian_/1000 << "\t" << median_/1000 << "\t" << buffer_.size() << "\t" << cs::duration<cs::msec>(outputBufferDacTime) << "\n"; // logO << "Chunk: " << age.count()/1000 << "\t" << miniBuffer_.median()/1000 << "\t" << shortMedian_/1000 << "\t" << median_/1000 << "\t" << buffer_.size() << "\t" << cs::duration<cs::msec>(outputBufferDacTime) << "\n";
} }
return true; return (abs(cs::duration<cs::msec>(age)) < 500);
} }
catch(int e) catch(int e)
{ {

View file

@ -83,3 +83,11 @@ https://en.wikipedia.org/wiki/Uniform_Resource_Identifier
-HiRes Audio -HiRes Audio
-Android auto start -Android auto start
-pipe creation mode: `-s pipe:///tmp/snapfifo?mode=[read|create]` -pipe creation mode: `-s pipe:///tmp/snapfifo?mode=[read|create]`
*Dependencies
libavahi-client3
libflac8
libogg0
libvorbis0a
libvorbisenc2