All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rob Duncan <rduncan@tesla.com>
To: "alsa-devel@alsa-project.org" <alsa-devel@alsa-project.org>
Subject: Bug in snd_pcm_ioplug_avail_update()?
Date: Fri, 13 Jul 2018 15:10:29 -0700	[thread overview]
Message-ID: <dw77em7elyg52i.fsf@tesla.com> (raw)

It seems to me that there's something wrong in
snd_pcm_ioplug_avail_update() for capture IO plugins.

Once a bunch of conditions are met it makes this call:

	__snd_pcm_mmap_begin(pcm, &areas, &offset, &size);
	result = io->data->callback->transfer(io->data, areas, offset, size);
	if (result < 0)
		return result;

This transfers size frames from the IO plugin, which in general is not
all the available data: it's limited by the amount of contiguous space
in the mmap.

However, the function returns like this:

	avail = snd_pcm_mmap_avail(pcm);
	if (avail > io->avail_max)
		io->avail_max = avail;
	return (snd_pcm_sframes_t)avail;

But this is all the available data in the IO plugin, without considering
the contiguous space limitation. This means that there is now
uninitialized data in the mmap, and some data still in the IO plugin
that has yet to be transferred.

I'm running into this misbehaviour with a rate conversion plugin pulling
data from an IO plugin.  I get chunks of old data showing up later in
the stream, I think because the mmap buffer is not being fully written
to.

I suspect that this avail mismatch tricks snd_pcm_rate_avail_update()
into thinking that it can grab an integral number of periods of data
from the mmap, which is not the case.

But I'm quite tangled up trying to follow the control flow here so I
could certainly be mistaken.  I'd appreciate any insight into what might
be going wrong.

Thanks,

Rob.

             reply	other threads:[~2018-07-13 22:10 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-13 22:10 Rob Duncan [this message]
2018-07-16 18:38 ` Bug in snd_pcm_ioplug_avail_update()? Takashi Iwai
2018-07-16 23:53   ` Rob Duncan
2018-07-17  5:04     ` Takashi Iwai
2018-07-17 15:46       ` Rob Duncan
2018-07-17 15:54         ` 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=dw77em7elyg52i.fsf@tesla.com \
    --to=rduncan@tesla.com \
    --cc=alsa-devel@alsa-project.org \
    /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.