<html>
    <head>
      <base href="https://bugs.freedesktop.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [NEED]Try recover from snd_pcm_avail() -EPIPE"
   href="https://bugs.freedesktop.org/show_bug.cgi?id=96361">96361</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[NEED]Try recover from snd_pcm_avail() -EPIPE
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>PulseAudio
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>medium
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>alsa
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>pulseaudio-bugs@lists.freedesktop.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>cunshangzhishu@gmail.com
          </td>
        </tr>

        <tr>
          <th>QA Contact</th>
          <td>pulseaudio-bugs@lists.freedesktop.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>lennart@poettering.net
          </td>
        </tr></table>
      <p>
        <div>
        <pre>ALSA sink has been unloaded due to process_rewind() return -1.

"alsa-sink.c: process_rewind(1754) > [alsa-sink-Multimedia1 (*)]
snd_pcm_avail() failed: Broken pipe"
"sink.c: sink_free(843) > [pulseaudio] Freeing sink 2
"alsa_output.0.analog-stereo""
"module.c pa_module_free(183) > [pulseaudio] unloaded "module-alsa-sink"
(index: #15)"

Actually, sometimes we may meet snd_pcm_avail() -EPIPE from process_rewind,
pa_alsa_safe_avail. But how about do recover for this error case instead of
return error and unload sink?

I've tried make a patch for this issue. But I'm not sure about this is a proper
solution. Please give me your opinion. Thank you.

if (PA_UNLIKELY((unused = pa_alsa_safe_avail(u->pcm_handle, u->hwbuf_size,
&u->sink->sample_spec)) < 0)) {
    pa_log("snd_pcm_avail() failed: %s", pa_alsa_strerror((int) unused));
#ifdef RECOVER_FROM_EPIPE
    /* try recover if we got -EPIPE from snd_pcm_avail */
    if (unsed == -EPIPE) {
        pa_log("snd_pcm_avail() failed of -EPIPE. Try recover!!!");
        if (try_recover(u, "process_rewind", unused) < 0)
            return -1;
        else {
            pa_log_info("Tried rewind, but was apparently not possible.");
            pa_sink_process_rewind(u->sink, 0);
            return 0;
        }
    }
#endif
    return -1;
}</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are the assignee for the bug.</li>
          <li>You are the QA Contact for the bug.</li>
      </ul>
    </body>
</html>