All of lore.kernel.org
 help / color / mirror / Atom feed
* return value of snd_pcm_wait()
@ 2003-07-14 14:24 Takashi Iwai
  2003-07-14 14:39 ` Jaroslav Kysela
  0 siblings, 1 reply; 2+ messages in thread
From: Takashi Iwai @ 2003-07-14 14:24 UTC (permalink / raw)
  To: alsa-devel

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

Hi,

currently, snd_pcm_wait() returns -EIO if any error happens during
poll(), regardless what really happened.
i believe it's better to return a reasonable error code corresponding
to the current state, such as -EPIPE and -ESTRPIPE.

the attached patch adds this feature by calling snd_pcm_state() in
snd_pcm_wait().  this cleans up also some codes there.

i think there is no major drawback by this change.  but i'd like to
ask here to make it sure.

do you see any problems?


Takashi

[-- Attachment #2: pcm-wait-fix.dif --]
[-- Type: application/octet-stream, Size: 1767 bytes --]

Index: alsa-lib/src/pcm/pcm.c
===================================================================
RCS file: /suse/tiwai/cvs/alsa/alsa-lib/src/pcm/pcm.c,v
retrieving revision 1.134
diff -u -r1.134 pcm.c
--- alsa-lib/src/pcm/pcm.c	24 Jun 2003 10:03:53 -0000	1.134
+++ alsa-lib/src/pcm/pcm.c	14 Jul 2003 14:20:29 -0000
@@ -2000,6 +2000,7 @@
  * \param pcm PCM handle
  * \param timeout maximum time in milliseconds to wait
  * \return a positive value on success otherwise a negative error code
+ *         (-EPIPE for the xrun and -ESTRPIPE for the suspended status) 
  * \retval 0 timeout occurred
  * \retval 1 PCM stream is ready for I/O
  */
@@ -2016,8 +2017,17 @@
 	err = snd_pcm_poll_descriptors_revents(pcm, &pfd, 1, &revents);
 	if (err < 0)
 		return err;
-	if (revents & (POLLERR | POLLNVAL))
-		return -EIO;
+	if (revents & (POLLERR | POLLNVAL)) {
+		/* check more precisely */
+		switch (snd_pcm_state(pcm)) {
+		case SND_PCM_STATE_XRUN:
+			return -EPIPE;
+		case SND_PCM_STATE_SUSPENDED:
+			return -ESTRPIPE;
+		default:
+			return -EIO;
+		}
+	}
 	return err > 0 ? 1 : 0;
 }
 
@@ -6110,15 +6120,8 @@
 			}
 
 			err = snd_pcm_wait(pcm, -1);
-			state = snd_pcm_state(pcm);
-			if (err < 0) {
-				/* check more precisely */
-				if (state == SND_PCM_STATE_XRUN)
-					err = -EPIPE;
-				else if (state == SND_PCM_STATE_SUSPENDED)
-					err = -ESTRPIPE;
+			if (err < 0)
 				break;
-			}
 			goto _again;
 			
 		}
@@ -6187,15 +6190,8 @@
 			}
 
 			err = snd_pcm_wait(pcm, -1);
-			state = snd_pcm_state(pcm);
-			if (err < 0) {
-				/* check more precisely */
-				if (state == SND_PCM_STATE_XRUN)
-					err = -EPIPE;
-				else if (state == SND_PCM_STATE_SUSPENDED)
-					err = -ESTRPIPE;
+			if (err < 0)
 				break;
-			}
 			goto _again;
 			
 		}

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

end of thread, other threads:[~2003-07-14 14:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-07-14 14:24 return value of snd_pcm_wait() Takashi Iwai
2003-07-14 14:39 ` Jaroslav Kysela

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.