alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
* underruns and strange code in pcm_rate.c (and patch)
@ 2007-11-04 23:48 Stas Sergeev
  2007-11-06 11:29 ` Takashi Iwai
                   ` (2 more replies)
  0 siblings, 3 replies; 48+ messages in thread
From: Stas Sergeev @ 2007-11-04 23:48 UTC (permalink / raw)
  To: alsa-devel

[-- 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

^ permalink raw reply	[flat|nested] 48+ messages in thread

end of thread, other threads:[~2008-02-01 16:00 UTC | newest]

Thread overview: 48+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-04 23:48 underruns and strange code in pcm_rate.c (and patch) Stas Sergeev
2007-11-06 11:29 ` 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

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).