alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
From: Stas Sergeev <stsp@aknet.ru>
To: alsa-devel@alsa-project.org
Subject: underruns and strange code in pcm_rate.c (and patch)
Date: Mon, 05 Nov 2007 02:48:52 +0300	[thread overview]
Message-ID: <472E5A64.6010705@aknet.ru> (raw)

[-- Attachment #1: Type: text/plain, Size: 1009 bytes --]

Hi.

I spent 4 week-ends debugging the
constant underruns and lock-ups with
the libao-based programs.
Now I've finally tracked the problem
to some strange code in pcm_rate.c,
namely snd_pcm_rate_poll_descriptors().
I am not sure what was the reason
behind altering the "avail_min" every
time. Looks like some heuristic was
intended, say "see what amount of
fragment part was written now, and
make sure that amount of free space will
be available next time, after poll".
Whatever, this code gives underruns.
It can increase avail_min by almost period_size.
libao sets avail_min==period_size,
so we can end up with avail_min==period_size*2.
libao sets buffer_size==stop_threshold==period_size*2.
So we end up with avail_min~=stop_threshold,
which gives underruns.
Since I don't know how this code was
indended to work, I just removed it,
and everything works perfectly now
(also had to patch libao to check
the returned rate).

The patch is attached, any comments?

Signed-off-by: Stas Sergeev <stsp@aknet.ru>


[-- Attachment #2: pcm_rate.diff --]
[-- Type: text/x-patch, Size: 1676 bytes --]

--- alsa-lib/src/pcm/pcm_rate.c.old	2007-11-04 17:57:01.000000000 +0300
+++ alsa-lib/src/pcm/pcm_rate.c	2007-11-05 02:20:36.000000000 +0300
@@ -715,38 +715,6 @@
 	return n;
 }
 
-static int snd_pcm_rate_poll_descriptors(snd_pcm_t *pcm, struct pollfd *pfds, unsigned int space)
-{
-	snd_pcm_rate_t *rate = pcm->private_data;
-	snd_pcm_uframes_t avail_min;
-	int ret, err;
-
-	ret = snd_pcm_generic_poll_descriptors(pcm, pfds, space);
-	if (ret < 0)
-		return ret;
-
-	avail_min = rate->appl_ptr % pcm->period_size;
-	if (avail_min > 0) {
-		recalc(pcm, &avail_min);
-		if (avail_min < rate->gen.slave->buffer_size &&
-		    avail_min != rate->gen.slave->period_size)
-			avail_min++;	/* 1st small little rounding correction */
-		if (avail_min < rate->gen.slave->buffer_size &&
-		    avail_min != rate->gen.slave->period_size)
-			avail_min++;	/* 2nd small little rounding correction */
-		avail_min += rate->orig_avail_min;
-	} else {
-		avail_min = rate->orig_avail_min;
-	}
-	if (rate->sw_params.avail_min == avail_min)
-		return ret;
-	rate->sw_params.avail_min = avail_min;
-	err = snd_pcm_sw_params(rate->gen.slave, &rate->sw_params);
-	if (err < 0)
-		return err;
-	return ret;
-}
-
 static int snd_pcm_rate_commit_area(snd_pcm_t *pcm, snd_pcm_rate_t *rate,
 				    snd_pcm_uframes_t appl_offset,
 				    snd_pcm_uframes_t size,
@@ -1229,7 +1197,7 @@
 	.avail_update = snd_pcm_rate_avail_update,
 	.mmap_commit = snd_pcm_rate_mmap_commit,
 	.poll_descriptors_count = snd_pcm_generic_poll_descriptors_count,
-	.poll_descriptors = snd_pcm_rate_poll_descriptors,
+	.poll_descriptors = snd_pcm_generic_poll_descriptors,
 	.poll_revents = snd_pcm_rate_poll_revents,
 };
 

[-- Attachment #3: Type: text/plain, Size: 160 bytes --]

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

             reply	other threads:[~2007-11-04 23:47 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-04 23:48 Stas Sergeev [this message]
2007-11-06 11:29 ` underruns and strange code in pcm_rate.c (and patch) Takashi Iwai
2007-11-06 14:47   ` James Courtier-Dutton
2007-11-06 17:14     ` Stas Sergeev
2007-11-07 11:28       ` Takashi Iwai
2007-11-07 10:40     ` Takashi Iwai
2007-11-06 16:10   ` Stas Sergeev
2007-11-07 10:54     ` Takashi Iwai
2007-11-07 17:16       ` underruns and strange code in pcm_rate.c Stas Sergeev
2007-11-07 14:23         ` Takashi Iwai
2007-11-07 18:52           ` Stas Sergeev
2007-11-08  3:36             ` Takashi Iwai
2007-11-08  8:09               ` Stas Sergeev
2007-11-08  5:38                 ` Takashi Iwai
2007-11-08  9:05                   ` Stas Sergeev
2007-11-08  6:17                     ` Takashi Iwai
2007-11-08 18:34                       ` Stas Sergeev
2007-11-09 16:20                   ` Timur Tabi
2007-11-09 18:17                     ` Stas Sergeev
2007-11-09 19:52                       ` Timur Tabi
2007-11-09 20:00                         ` Stas Sergeev
2007-11-09 20:06                           ` Timur Tabi
2007-11-09 20:11                             ` Lee Revell
2007-11-09 20:16                               ` Timur Tabi
2007-11-09 20:30                                 ` Lee Revell
2007-11-09 20:33                                   ` Timur Tabi
2007-11-09 21:37                                     ` Lee Revell
2007-11-09 22:52                                       ` Stas Sergeev
2007-11-09 22:53                                         ` Timur Tabi
2007-11-12 12:12                     ` Clemens Ladisch
2007-11-12 15:56                       ` Timur Tabi
2008-01-31 20:49                       ` Timur Tabi
2008-02-01 12:32                         ` Takashi Iwai
2008-02-01 14:46                           ` Timur Tabi
2008-02-01 15:07                             ` Takashi Iwai
2008-02-01 15:18                               ` Timur Tabi
2008-02-01 15:27                                 ` Takashi Iwai
2008-02-01 16:00                                   ` Timur Tabi
2007-11-07 18:40       ` underruns and strange code in pcm_rate.c (and patch) Stas Sergeev
2007-11-08  4:42         ` Takashi Iwai
2007-11-08  8:27           ` Stas Sergeev
2007-11-08  5:54             ` Takashi Iwai
2007-11-08  9:13               ` Stas Sergeev
2007-11-08  6:25                 ` Takashi Iwai
2007-11-08 14:10   ` Alexander E. Patrakov
2007-11-06 13:56 ` Stas Sergeev
2007-11-08 20:06 ` Timur Tabi
2007-11-08 22:01   ` Timur Tabi

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=472E5A64.6010705@aknet.ru \
    --to=stsp@aknet.ru \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).