Korea FreeBSD Users Group News, Internal, Projects, Home
Software, Support, Documentation

Re: [KFUG] 5.2R pcm audio



[ ³¯Â¥¼ø »öÀÎ ] [ ´ñ±Û¼ø »öÀÎ ] [ ÃÖ»óÀ§ »öÀÎ] [ °Ë»ö]

[ÀÌÀü ±Û] [´ÙÀ½ ±Û] [ÀÌÀü ´ñ±Û] [´ÙÀ½ ´ñ±Û]


On Fri, Jan 16, 2004 at 10:38:35AM +0900, To questions@xxxxxxxxxxxxxx wrote:
 > 얼마전 제가 사용하는 시스템을 5.2R로 설치한 후부터 xmms에서
 > 이상한 문제가 발생하고 있습니다.
 > 
 > 1. 플레이 중지 후 xmms를 종료하면 약 1초정도 플레이를 하다가
 >    종료합니다.
 > 2. xmms에서 플레이 중이거나 플레이를 멈춘 상태에서 다른 곡을
 >     선택하면(playlist editor에서) 약 1초 정도의 지연이 일어납니다.
 > 
 > libthr이나 libkse를 사용해도 결과는 마찬가지 입니다.
 > 전 P3(SMP)에 Sound Blaster Live!를 사용합니다.
 > 
 > 플레이중 다른 곡을 선택했을 때 truss(1) 결과는 다음과 같습니다.
 > ...
 > 0.000155886 poll(0x8150000,0x2,0x0)              = 1 (0x1)
 > 0.000131301 write(11,0x822be70,2560)             = 2560 (0xa00)
 > 0.000067327 ioctl(11,SNDCTL_DSP_GETOSPACE,0xbfabaf40) = 0 (0x0)
 > 0.000177676 ioctl(11,SNDCTL_DSP_RESET,0x0)       = 0 (0x0)
 > 0.000086882 fstat(11,0xbfabae80)                 = 0 (0x0)
 > 0.000345016 fcntl(0xb,0x3,0x0)                   = 5 (0x5)
 > 0.000165943 fcntl(0xb,0x4,0x1)                   = 0 (0x0)
 > 0.999180343 close(11)                            = 0 (0x0)
 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 > 0.000238298 clock_gettime(0x0,0xbfaedfa8)        = 0 (0x0)
 > 0.000203937 clock_gettime(0x0,0xbfaedfa8)        = 0 (0x0)
 > 0.001563885 write(5,0x816b000,48)                = 48 (0x30)
 > ...
 > 
 > 문제는 close(2)에 있는것 같은데 약 1초 정도의 시간이 걸린것
 > 같습니다. 이게 pcm buffer문제인지 Sound Blaster driver문제인지
 > 먼저 확인해야겠습니다.
 > 
 > 다른 분들은 어떠세요?
 > 중요한 문제는 아니지만 좀 성가시군요. :(
 > 

두가지 문제중 후자는 해결된것 같습니다. 전자의 경우는 수정은 가능한데
프로그램특성에 따라서 다른 영향을 미칠것 같아서 일단 그대로 두기로
했습니다. pcm의 buffering이 너무 복잡해서 제대로 이해하지 못한관계로
완벽한 해결책은 아니지만 적어도 xmms에서 곡을 변경하거나 할경우에
더 이상 1초의 지연은 발생하지 않습니다.
시간이 좀 더 나면 pcm code를 보면서 수정해야 겠지만 pf 유지가 더
우선이라 장담은 못하겠습니다.

#cd /usr/src
#patch -p0 < /path/to/pcm.patch
그리고 일반적인 커널빌드 절차를 밟으면 되겠습니다. 모듈로 사용하시
는 분은 빌드 후 kldunload로 pcm module과 sound hardware module을
unload한 후 다시 로드하면 별도의 리부팅이 필요없습니다.

* 주의
 - 이 패치는 5.2R 전용입니다.(아마도 -CURRENT도 적용될겁니다.)
 - 이 패치는 많은 환경에서 시험되지 않았습니다. 저의 경우 xmms에서만
   시험했기 때문에 mplayer나 mpg123, aviplayer등에서의 동작은 
   아직 모릅니다.
 - 문제가 발생하면 이전버젼으로 돌아갈 수 있도록 반드시 파일을
   백업하고 patch하시기 바랍니다.

-- 
Pyun YongHyeon <http://www.kr.freebsd.org/~yongari>
--- sys/dev/sound/pcm/channel.c.ORG	Fri Dec  5 11:08:13 2003
+++ sys/dev/sound/pcm/channel.c	Fri Jan 16 17:49:17 2004
@@ -631,14 +631,23 @@
  * finally, we stop the dma.
  *
  * called from: dsp_close, not valid for record channels.
+ *
+ *
+ * XXX
+ *  Flush hardware buffers only. When software buffers are very large
+ * I got a 10 timeouts and delays up to 1 sec. Due to sound hardware's
+ * operation is very slow compared to other devices, it is not reasonable
+ * to flush all buffered data at this time.
+ * If an application depends on previous behaviour(huge writes and closes
+ * the device to drain all data), this implementation may not work!!
  */
 
 int
 chn_flush(struct pcm_channel *c)
 {
-    	int ret, count, resid, resid_p;
+    	int ret, count;
     	struct snd_dbuf *b = c->bufhard;
-    	struct snd_dbuf *bs = c->bufsoft;
+	struct snd_dbuf *bs = c->bufsoft;
 
 	CHN_LOCKASSERT(c);
 	KASSERT(c->direction == PCMDIR_PLAY, ("chn_flush on bad channel"));
@@ -656,23 +665,16 @@
 	}
 
 	c->flags |= CHN_F_CLOSING;
-	resid = sndbuf_getready(bs) + sndbuf_getready(b);
-	resid_p = resid;
+	/* max. timeout is 10x100ms */
 	count = 10;
 	ret = 0;
-	while ((count > 0) && (resid > sndbuf_getsize(b)) && (ret == 0)) {
-		/* still pending output data. */
+	while ((count > 0) && (sndbuf_getready(b) > 0) && (ret == 0)) {
+		/* still pending output data in hardware. waits up to 100ms */
 		ret = chn_sleep(c, "pcmflu", hz / 10);
 		if (ret == EWOULDBLOCK)
 			ret = 0;
-		if (ret == 0) {
-			resid = sndbuf_getready(bs) + sndbuf_getready(b);
-			if (resid == resid_p)
-				count--;
-			if (resid > resid_p)
-				DEB(printf("chn_flush: buffer length increasind %d -> %d\n", resid_p, resid));
-			resid_p = resid;
-		}
+		if (ret == 0)
+			count--;
    	}
 	if (count == 0)
 		DEB(printf("chn_flush: timeout, hw %d, sw %d\n",
_______________________________________________
한국 FreeBSD 사용자 그룹(KFUG) questions 메일링 리스트
questions at kr.FreeBSD.org
http://www.kr.FreeBSD.org/mailman/listinfo/questions

[ ³¯Â¥¼ø »öÀÎ ] [ ´ñ±Û¼ø »öÀÎ ] [ ÃÖ»óÀ§ »öÀÎ] [ °Ë»ö]

Copyright © 1998-2005 Korea FreeBSD Users Group.
All rights reserved. webmaster at kr.FreeBSD.org
$Date: 2004/01/16 20:42:57 $
Powered by FreeBSD