Skip to content

Commit

Permalink
Merge branch 'alsa-drain-recovery' of https://github.com/borine/MPD
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Apr 15, 2024
2 parents 9e8bca4 + b1f28d6 commit 9c7b930
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/output/plugins/AlsaOutputPlugin.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -910,14 +910,14 @@ AlsaOutput::Recover(int err) noexcept
/* fall-through to snd_pcm_prepare: */
[[fallthrough]];

case SND_PCM_STATE_OPEN:
case SND_PCM_STATE_SETUP:
case SND_PCM_STATE_XRUN:
period_buffer.Rewind();
written = false;
err = snd_pcm_prepare(pcm);
break;

case SND_PCM_STATE_OPEN:
case SND_PCM_STATE_DISCONNECTED:
case SND_PCM_STATE_DRAINING:
/* can't play in this state; throw the error */
Expand Down Expand Up @@ -1002,14 +1002,19 @@ AlsaOutput::DrainInternal()
period_buffer.FillWithSilence(silence, out_frame_size);

/* drain period_buffer */
if (!period_buffer.IsDrained()) {
unsigned int retry_count = 0;
while (!period_buffer.IsDrained() && retry_count <= 1) {
auto frames_written = WriteFromPeriodBuffer();
if (frames_written < 0) {
if (frames_written == -EAGAIN)
if (frames_written == -EAGAIN || frames_written == -EINTR)
return false;

throw Alsa::MakeError(frames_written,
"snd_pcm_writei() failed");
if (Recover(frames_written) < 0)
throw Alsa::MakeError(frames_written,
"snd_pcm_writei() failed");

retry_count++;
continue;
}

/* need to call CopyRingToPeriodBuffer() and
Expand Down

0 comments on commit 9c7b930

Please sign in to comment.