From: Lennart Poettering <mznyfn@0pointer.de>
To: Takashi Iwai <tiwai@suse.de>
Cc: alsa-devel@alsa-project.org
Subject: Re: PCM delay compensation
Date: Sun, 22 Feb 2009 00:45:04 +0100 [thread overview]
Message-ID: <20090221234502.GA8504@tango.0pointer.de> (raw)
In-Reply-To: <s5h4p3ol8ui.wl%tiwai@suse.de>
On Tue, 07.10.08 17:32, Takashi Iwai (tiwai@suse.de) wrote:
> Hi,
Sorry for the overly long delay.
>
> the patch below (to the latest sound git tree) adds the extra delay
> count for USB-audio driver. This change will appear as the return
> value of snd_pcm_delay().
>
> Could you check whether it's appropriate behavior you've wanted?
I have now tested this patch on the current 2.6.29-rc5 kernel. The
effect is that snd_pcm_delay() returns always increasing values, as if
the playback never proceeds. Most movie players which need that call
to synchronize video frames hence stall completely.
Lennart
> diff --git a/include/sound/pcm.h b/include/sound/pcm.h
> index 40c5a6f..dcbdc60 100644
> --- a/include/sound/pcm.h
> +++ b/include/sound/pcm.h
> @@ -269,6 +269,7 @@ struct snd_pcm_runtime {
> snd_pcm_uframes_t avail_max;
> snd_pcm_uframes_t hw_ptr_base; /* Position at buffer restart */
> snd_pcm_uframes_t hw_ptr_interrupt; /* Position at interrupt time*/
> + snd_pcm_sframes_t delay; /* extra delay; typically FIFO size */
>
> /* -- HW params -- */
> snd_pcm_access_t access; /* access mode */
> diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
> index e61e125..df7c3fa 100644
> --- a/sound/core/pcm_native.c
> +++ b/sound/core/pcm_native.c
> @@ -597,14 +597,15 @@ int snd_pcm_status(struct snd_pcm_substream *substream,
> if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
> status->avail = snd_pcm_playback_avail(runtime);
> if (runtime->status->state == SNDRV_PCM_STATE_RUNNING ||
> - runtime->status->state == SNDRV_PCM_STATE_DRAINING)
> + runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
> status->delay = runtime->buffer_size - status->avail;
> - else
> + status->delay += runtime->delay;
> + } else
> status->delay = 0;
> } else {
> status->avail = snd_pcm_capture_avail(runtime);
> if (runtime->status->state == SNDRV_PCM_STATE_RUNNING)
> - status->delay = status->avail;
> + status->delay = status->avail + runtime->delay;
> else
> status->delay = 0;
> }
> @@ -2423,6 +2424,7 @@ static int snd_pcm_delay(struct snd_pcm_substream *substream,
> n = snd_pcm_playback_hw_avail(runtime);
> else
> n = snd_pcm_capture_avail(runtime);
> + n += runtime->delay;
> break;
> case SNDRV_PCM_STATE_XRUN:
> err = -EPIPE;
> diff --git a/sound/usb/usbaudio.c b/sound/usb/usbaudio.c
> index 6e70ba4..7d5a103 100644
> --- a/sound/usb/usbaudio.c
> +++ b/sound/usb/usbaudio.c
> @@ -629,6 +629,7 @@ static int prepare_playback_urb(struct snd_usb_substream *subs,
> subs->hwptr_done += offs;
> if (subs->hwptr_done >= runtime->buffer_size)
> subs->hwptr_done -= runtime->buffer_size;
> + runtime->delay += offs;
> spin_unlock_irqrestore(&subs->lock, flags);
> urb->transfer_buffer_length = offs * stride;
> if (period_elapsed)
> @@ -638,12 +639,20 @@ static int prepare_playback_urb(struct snd_usb_substream *subs,
>
> /*
> * process after playback data complete
> - * - nothing to do
> + * - decrease the delay count again
> */
> static int retire_playback_urb(struct snd_usb_substream *subs,
> struct snd_pcm_runtime *runtime,
> struct urb *urb)
> {
> + unsigned long flags;
> + int stride = runtime->frame_bits >> 3;
> + int processed = urb->transfer_buffer_length / stride;
> +
> + spin_lock_irqsave(&subs->lock, flags);
> + if (processed > runtime->delay)
> + runtime->delay -= processed;
> + spin_unlock_irqrestore(&subs->lock, flags);
> return 0;
> }
>
> @@ -1542,6 +1551,7 @@ static int snd_usb_pcm_prepare(struct snd_pcm_substream *substream)
> subs->hwptr_done = 0;
> subs->transfer_done = 0;
> subs->phase = 0;
> + runtime->delay = 0;
>
> /* clear urbs (to be sure) */
> deactivate_urbs(subs, 0, 1);
> _______________________________________________
> Alsa-devel mailing list
> Alsa-devel@alsa-project.org
> http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Lennart
--
Lennart Poettering Red Hat, Inc.
lennart [at] poettering [dot] net ICQ# 11060553
http://0pointer.net/lennart/ GnuPG 0x1A015CC4
next prev parent reply other threads:[~2009-02-21 23:45 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-07 15:32 PCM delay compensation Takashi Iwai
2008-10-29 9:33 ` Takashi Iwai
2009-02-21 23:45 ` Lennart Poettering [this message]
2009-02-23 7:45 ` Takashi Iwai
2009-02-23 16:24 ` Lennart Poettering
2009-02-23 16:28 ` Takashi Iwai
2009-02-23 16:33 ` 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=20090221234502.GA8504@tango.0pointer.de \
--to=mznyfn@0pointer.de \
--cc=alsa-devel@alsa-project.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.