All of lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Cc: alsa-devel@alsa-project.org, broonie@kernel.org,
	P9ter Ujfalusi <peter.ujfalusi@linux.intel.com>,
	Ranjani Sridharan <ranjani.sridharan@linux.intel.com>,
	Kai Vehmanen <kai.vehmanen@linux.intel.com>
Subject: Re: [PATCH v2 1/3] ALSA: pcm: introduce INFO_NO_REWINDS flag
Date: Tue, 12 Oct 2021 08:11:21 +0200	[thread overview]
Message-ID: <s5hv9223h86.wl-tiwai@suse.de> (raw)
In-Reply-To: <1ae2012b-d6bd-77ce-0a9e-98aec4d0f868@linux.intel.com>

On Tue, 12 Oct 2021 02:19:16 +0200,
Pierre-Louis Bossart wrote:
> 
> > For example, check snd_pcm_playback_avail() and co.  That contains a
> > couple of more condition checks and corrections due to the possible
> > boundary crossing.  (Here, runtime->boundary may differ depending on
> > 32 or 64bit context.)
> > 
> > The actual implementation of the backward move check would be slightly
> > different from those, but I hope you get my idea.
> 
> I think I do but not sure how to precisely deal with the boundary
> wrap-around.
> 
> The only suggestion I have at this point would be to compare the 'avail'
> space before and after the appl_ptr changes in pcm_lib_apply_appl_ptr().
> If the 'avail' space grows as a result of user-space changes, that
> indicates a rewind (both for capture and playback), doesn't it?

There are a few different ways, and a simple one would be to treat as
a rewind if the change isn't 0..buffer_size.  e.g.

	snd_pcm_sframes_t diff = new_ptr - old_ptr;

	if (diff >= 0) {
		if (diff > buffer_size)
			return REWIND;
	} else {
		if (boundary + diff > buffer_size)
			return REWIND;
	}
	return OK;

Or, if a rewind is defined to be -buffer_size..-1, it'd be like:

	snd_pcm_sframes_t diff = new_ptr - old_ptr;

	if (diff >= 0) {
		if (boundary - diff <= buffer_size)
			return REWIND;
	} else {
		if (-diff <= buffer_size)
			return REWIND;
	}
	return OK;

In either way, the new_ptr has to be validated beforehand that it's
within 0..boundary-1.  (old_ptr is assumed to be valid.)

And don't miss that diff is a signed value, so it must be
snd_pcm_sframes_t, not *_uframes_t.


Takashi

  reply	other threads:[~2021-10-12  6:12 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-04 16:24 [PATCH v2 0/3] ASoC: SOF: Intel: power optimizations with HDaudio SPIB register Pierre-Louis Bossart
2021-10-04 16:24 ` [PATCH v2 1/3] ALSA: pcm: introduce INFO_NO_REWINDS flag Pierre-Louis Bossart
2021-10-05  6:59   ` Takashi Iwai
2021-10-05 13:10     ` Pierre-Louis Bossart
2021-10-05 13:35       ` Takashi Iwai
2021-10-12  0:19         ` Pierre-Louis Bossart
2021-10-12  6:11           ` Takashi Iwai [this message]
2021-10-12 15:15             ` Pierre-Louis Bossart
2021-10-12 15:27               ` Takashi Iwai
2021-10-12 16:41                 ` Pierre-Louis Bossart
2021-10-12 17:16                   ` Takashi Iwai
2021-10-12 18:02                     ` Pierre-Louis Bossart
2021-10-12 20:04                       ` Takashi Iwai
2021-10-04 16:24 ` [PATCH v2 2/3] ASOC: SOF: pcm: add .ack callback support Pierre-Louis Bossart
2021-10-04 16:24 ` [PATCH v2 3/3] ASoC: SOF: Intel: add .ack support for HDaudio platforms Pierre-Louis Bossart

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=s5hv9223h86.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=kai.vehmanen@linux.intel.com \
    --cc=peter.ujfalusi@linux.intel.com \
    --cc=pierre-louis.bossart@linux.intel.com \
    --cc=ranjani.sridharan@linux.intel.com \
    /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.