All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mirza Krak <mirza.krak@gmail.com>
To: Takashi Iwai <tiwai@suse.de>
Cc: linux-rockchip@lists.infradead.org, alsa-devel@alsa-project.org,
	"Heiko Stübner" <heiko@sntech.de>
Subject: Re: Bad PCM stream after a suspend/resume cycle
Date: Wed, 17 Jan 2018 15:08:27 +0100	[thread overview]
Message-ID: <CALw8SCV8penDHKxTjrg0Z7k6dTFxEq79G8fK74iPz+3vix1fcQ@mail.gmail.com> (raw)
In-Reply-To: <s5hwp0ndkcm.wl-tiwai@suse.de>

On 12 January 2018 at 19:04, Takashi Iwai <tiwai@suse.de> wrote:
> On Fri, 12 Jan 2018 14:36:45 +0100,
> Mirza Krak wrote:
>>

< snip >

>
> The EBADFD is already indicating a fatal error, and something is wrong
> in the driver.  Basically the driver should suspend the stream via
> snd_pcm_suspend*() call in the PM resume ops.  Most likely your driver
> misses that.
>
> That said, it's specific to your using driver, and you'd need to take
> a look at that code there.

Thank you for you patience with me.

I have looked further in to my hardware drivers and I can not really
see any faults here.

But I did some further testing and applying the following diff on
aplay "resolves" the problem (v1.1.4 of alsa-utils):

diff --git a/aplay/aplay.c b/aplay/aplay.c
index f793c82..040cec1 100644
--- a/aplay/aplay.c
+++ b/aplay/aplay.c
@@ -2020,6 +2020,8 @@ static ssize_t pcm_write(u_char *data, size_t count)
                if (test_position)
                        do_test_position();
                if (r == -EAGAIN || (r >= 0 && (size_t)r < count)) {
+                       if (snd_pcm_state(handle) == SND_PCM_STATE_SUSPENDED)
+                               suspend();
                        if (!test_nowait)
                                snd_pcm_wait(handle, 100);
                } else if (r == -EPIPE) {

Which means that there is no error in regard to suspending the stream
as it properly reports this when checked.

My problem is that this condition:

    (r >= 0 && (size_t)r < count)

Is always true after a suspend/resume cycle. Which normally does not
result in a "resume" call from aplay nor from snd_pcm_recover, which
means that it will try to write data to a suspended stream which
results in -EBADFD due to this (from alsa-lib):

snd_pcm_sframes_t snd_pcm_writei(snd_pcm_t *pcm, const void *buffer,
snd_pcm_uframes_t size)
{
    < snip >

    if (bad_pcm_state(pcm, P_STATE_RUNNABLE))
        return -EBADFD;
    return _snd_pcm_writei(pcm, buffer, size);
}

Because SUSPENDED is not part of the P_STATE_RUNNABLE, which maybe it should be?

-- 
Med Vänliga Hälsningar / Best Regards

Mirza Krak
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

  reply	other threads:[~2018-01-17 14:08 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-11  9:06 Bad PCM stream after a suspend/resume cycle Mirza Krak
2018-01-12 10:26 ` Takashi Iwai
2018-01-12 13:36   ` Mirza Krak
2018-01-12 18:04     ` Takashi Iwai
2018-01-17 14:08       ` Mirza Krak [this message]
2018-01-17 15:05         ` Takashi Iwai
2018-01-18  8:49           ` Mirza Krak
2018-01-18  9:12             ` Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CALw8SCV8penDHKxTjrg0Z7k6dTFxEq79G8fK74iPz+3vix1fcQ@mail.gmail.com \
    --to=mirza.krak@gmail.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=heiko@sntech.de \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.