[Pkg-alsa-devel] Bug#236394: Accidentally reverted pcm_direct.c fixes

Michel Daenzer Michel Daenzer <daenzer@debian.org>, 236394@bugs.debian.org
Sat, 06 Mar 2004 02:37:22 +0100


This is a multi-part MIME message sent by reportbug.

--===============1977696669==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Package: libasound2
Version: 1.0.2-1
Severity: normal
Tags: patch

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


These fixes were accidentally reverted due to sf.net CVS problems. At least
the last hunk is needed for smooth playback with xine using the dmix plugin.

I posted about this to the alsa-devel under the subject 'reverted
pcm_direct.c fixes', and the fixes have been reinstated in CVS, but the
thread isn't available in the archives yet. I can post an URL as soon as
it's there, if that would be helpful.


- -- System Information:
  APT prefers testing
  APT policy: (990, 'testing'), (500, 'unstable'), (101, 'experimental')
Architecture: powerpc (ppc)
Kernel: Linux 2.6.3-ben1
Locale: LANG=de_CH.UTF-8, LC_CTYPE=de_CH.UTF-8

Versions of packages libasound2 depends on:
ii  libc6                       2.3.2.ds1-11 GNU C Library: Shared libraries an

- -- no debconf information

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFASStRWoGvjmrbsgARAp1BAJ0fA/VNqDs0LOwofZPsI+3VY+UO+ACgrH6v
UFeNJ9CjnpIrLbL3vfFyCXE=
=mzpE
-----END PGP SIGNATURE-----

--===============1977696669==
Content-Type: text/x-c; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="alsa-lib-cvs.diff"

Index: src/pcm/pcm_direct.c
===================================================================
RCS file: /cvsroot/alsa/alsa-lib/src/pcm/pcm_direct.c,v
retrieving revision 1.17
diff -p -u -r1.17 pcm_direct.c
--- src/pcm/pcm_direct.c	25 Feb 2004 11:24:30 -0000	1.17
+++ src/pcm/pcm_direct.c	5 Mar 2004 17:31:02 -0000
@@ -100,11 +100,21 @@ int snd_pcm_direct_semaphore_up(snd_pcm_
 int snd_pcm_direct_shm_create_or_connect(snd_pcm_direct_t *dmix)
 {
 	struct shmid_ds buf;
-	int ret = 0;
+	int tmpid, err;
 	
+retryget:
 	dmix->shmid = shmget(dmix->ipc_key, sizeof(snd_pcm_direct_share_t), IPC_CREAT | 0666);
-	if (dmix->shmid < 0)
-		return -errno;
+	err = -errno;
+	if (dmix->shmid < 0){
+		if (errno == EINVAL)
+		if ((tmpid = shmget(dmix->ipc_key, 0, 0666)) != -1)
+		if (!shmctl(tmpid, IPC_STAT, &buf))
+		if (!buf.shm_nattch)
+	    	/* no users so destroy the segment */
+		if (!shmctl(tmpid, IPC_RMID, NULL))
+		    goto retryget;
+		return err;
+	}
 	dmix->shmptr = shmat(dmix->shmid, 0, 0);
 	if (dmix->shmptr == (void *) -1) {
 		snd_pcm_direct_shm_discard(dmix);
@@ -117,9 +127,9 @@ int snd_pcm_direct_shm_create_or_connect
 	}
 	if (buf.shm_nattch == 1) {	/* we're the first user, clear the segment */
 		memset(dmix->shmptr, 0, sizeof(snd_pcm_direct_share_t));
-		ret = 1;
+		return 1;
 	}
-	return ret;
+	return 0;
 }
 
 int snd_pcm_direct_shm_discard(snd_pcm_direct_t *dmix)
@@ -409,15 +419,23 @@ int snd_pcm_direct_poll_revents(snd_pcm_
 {
 	snd_pcm_direct_t *dmix = pcm->private_data;
 	unsigned short events;
-	static snd_timer_read_t rbuf[5];	/* can be overwriten by multiple plugins, we don't need the value */
+	/* rbuf might be overwriten by multiple plugins */
+	/* we don't need the value */
+	static snd_timer_read_t rbuf[5];
 
 	assert(pfds && nfds == 1 && revents);
 	events = pfds[0].revents;
 	if (events & POLLIN) {
-		events |= POLLOUT;
-		events &= ~POLLIN;
+		int empty = 0;
+		if (pcm->stream == SND_PCM_STREAM_PLAYBACK) {
+			events |= POLLOUT;
+			events &= ~POLLIN;
+			empty = snd_pcm_mmap_playback_avail(pcm) < pcm->avail_min;
+		} else {
+			empty = snd_pcm_mmap_capture_avail(pcm) < pcm->avail_min;
+		}
 		/* empty the timer read queue */
-		while (snd_timer_read(dmix->timer, &rbuf, sizeof(rbuf)) == sizeof(rbuf)) ;
+		while (empty && snd_timer_read(dmix->timer, &rbuf, sizeof(rbuf)) == sizeof(rbuf)) ;
 	}
 	*revents = events;
 	return 0;

--===============1977696669==--