From owner-svn-ports-head@FreeBSD.ORG Fri Aug 9 13:28:19 2013 Return-Path: Delivered-To: svn-ports-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 788EA730; Fri, 9 Aug 2013 13:28:19 +0000 (UTC) (envelope-from danfe@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 550A727E5; Fri, 9 Aug 2013 13:28:19 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r79DSJ3X046795; Fri, 9 Aug 2013 13:28:19 GMT (envelope-from danfe@svn.freebsd.org) Received: (from danfe@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r79DSIt7046790; Fri, 9 Aug 2013 13:28:18 GMT (envelope-from danfe@svn.freebsd.org) Message-Id: <201308091328.r79DSIt7046790@svn.freebsd.org> From: Alexey Dokuchaev Date: Fri, 9 Aug 2013 13:28:18 +0000 (UTC) To: ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org Subject: svn commit: r324435 - in head/games/quake2lnx: . files X-SVN-Group: ports-head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-ports-head@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the ports tree for head List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 09 Aug 2013 13:28:19 -0000 Author: danfe Date: Fri Aug 9 13:28:18 2013 New Revision: 324435 URL: http://svnweb.freebsd.org/changeset/ports/324435 Log: - Some time ago, original (non-SDL) client executable started to yield choppy sound (when using standard OSS API). It happens because the SNDCTL_DSP_GETOSPACE ioctl() was issued before setting other important parameters; to remedy the problem, it should be moved below the mmap() call. While here, cleanup few more potential problems: avoid using AFMT_S16_LE as it would break on big-endian machines, align mmap()'ed buffer to the page size, and fix resource leaks here and there. - In the port's Makefile: bump PORTREVISION and convert USE_GMAKE Submitted by: Ozkan Sezer (via icculus.org quake2 mailing list) Added: head/games/quake2lnx/files/patch-src_linux_snd__linux.c (contents, props changed) Modified: head/games/quake2lnx/Makefile Modified: head/games/quake2lnx/Makefile ============================================================================== --- head/games/quake2lnx/Makefile Fri Aug 9 13:20:40 2013 (r324434) +++ head/games/quake2lnx/Makefile Fri Aug 9 13:28:18 2013 (r324435) @@ -3,7 +3,7 @@ PORTNAME= quake2lnx PORTVERSION= 0.16.2 -PORTREVISION= 10 +PORTREVISION= 11 CATEGORIES= games ipv6 MASTER_SITES= http://offload1.icculus.org/quake2/files/ DISTNAME= quake2-r${PORTVERSION} @@ -16,7 +16,7 @@ COMMENT= Icculus.org version of the orig LICENSE= GPLv2 -USE_GMAKE= yes +USES= gmake WANT_SDL= yes ALL_TARGET= build_release Added: head/games/quake2lnx/files/patch-src_linux_snd__linux.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/games/quake2lnx/files/patch-src_linux_snd__linux.c Fri Aug 9 13:28:18 2013 (r324435) @@ -0,0 +1,150 @@ +--- src/linux/snd_linux.c.orig 2002-02-10 06:09:23.000000000 +0800 ++++ src/linux/snd_linux.c 2013-08-09 20:43:48.000000000 +0800 +@@ -25,13 +25,9 @@ Foundation, Inc., 59 Temple Place - Suit + #include + #include + #include +-#if defined(__FreeBSD__) + #include +-#endif +-#if defined(__linux__) +-#include +-#endif + #include ++#include + + #include "../client/client.h" + #include "../client/snd_loc.h" +@@ -45,6 +41,7 @@ cvar_t *sndchannels; + cvar_t *snddevice; + + static int tryrates[] = { 11025, 22051, 44100, 48000, 8000 }; ++static unsigned long mmaplen; + + qboolean SNDDMA_Init(void) + { +@@ -53,6 +50,7 @@ qboolean SNDDMA_Init(void) + int fmt; + int tmp; + int i; ++ unsigned long sz; + struct audio_buf_info info; + int caps; + extern uid_t saved_euid; +@@ -65,7 +63,7 @@ qboolean SNDDMA_Init(void) + if (!snddevice) + { + sndbits = Cvar_Get("sndbits", "16", CVAR_ARCHIVE); +- sndspeed = Cvar_Get("sndspeed", "0", CVAR_ARCHIVE); ++ sndspeed = Cvar_Get("sndspeed", "44100", CVAR_ARCHIVE); + sndchannels = Cvar_Get("sndchannels", "2", CVAR_ARCHIVE); + snddevice = Cvar_Get("snddevice", "/dev/dsp", CVAR_ARCHIVE); + } +@@ -76,7 +74,7 @@ qboolean SNDDMA_Init(void) + { + seteuid(saved_euid); + +- audio_fd = open(snddevice->string, O_RDWR); ++ audio_fd = open(snddevice->string, O_RDWR|O_NONBLOCK); + + if (audio_fd == -1) + { +@@ -115,28 +113,19 @@ qboolean SNDDMA_Init(void) + return 0; + } + +- if (ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &info)==-1) +- { +- perror("GETOSPACE"); +- Com_Printf("SNDDMA_Init: GETOSPACE ioctl failed.\n"); +- close(audio_fd); +- audio_fd = -1; +- return 0; +- } +- + // set sample bits & speed + + dma.samplebits = (int)sndbits->value; + if (dma.samplebits != 16 && dma.samplebits != 8) + { + ioctl(audio_fd, SNDCTL_DSP_GETFMTS, &fmt); +- if (fmt & AFMT_S16_LE) dma.samplebits = 16; ++ if (fmt & AFMT_S16_NE) dma.samplebits = 16; + else if (fmt & AFMT_U8) dma.samplebits = 8; + } + + if (dma.samplebits == 16) + { +- rc = AFMT_S16_LE; ++ rc = AFMT_S16_NE; + rc = ioctl(audio_fd, SNDCTL_DSP_SETFMT, &rc); + if (rc < 0) + { +@@ -211,15 +200,27 @@ qboolean SNDDMA_Init(void) + return 0; + } + ++ rc = ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &info); ++ if (rc < 0) ++ { ++ perror("GETOSPACE"); ++ Com_Printf("SNDDMA_Init: GETOSPACE ioctl failed.\n"); ++ close(audio_fd); ++ audio_fd = -1; ++ return 0; ++ } ++ + dma.samples = info.fragstotal * info.fragsize / (dma.samplebits/8); + dma.submission_chunk = 1; + + // memory map the dma buffer +- ++ mmaplen = info.fragstotal * info.fragsize; ++ sz = sysconf (_SC_PAGESIZE); ++ mmaplen += sz - 1; ++ mmaplen &= ~(sz - 1); + if (!dma.buffer) +- dma.buffer = (unsigned char *) mmap(NULL, info.fragstotal +- * info.fragsize, PROT_WRITE|PROT_READ, MAP_FILE|MAP_SHARED, audio_fd, 0); +- if (!dma.buffer || dma.buffer == MAP_FAILED) ++ dma.buffer = (unsigned char *) mmap(NULL, mmaplen, PROT_WRITE|PROT_READ, MAP_FILE|MAP_SHARED, audio_fd, 0); ++ if (dma.buffer == MAP_FAILED) + { + perror(snddevice->string); + Com_Printf("SNDDMA_Init: Could not mmap %s.\n", snddevice->string); +@@ -236,6 +237,8 @@ qboolean SNDDMA_Init(void) + { + perror(snddevice->string); + Com_Printf("SNDDMA_Init: Could not toggle. (1)\n"); ++ munmap (dma.buffer, mmaplen); ++ dma.buffer=NULL; + close(audio_fd); + audio_fd = -1; + return 0; +@@ -246,6 +249,8 @@ qboolean SNDDMA_Init(void) + { + perror(snddevice->string); + Com_Printf("SNDDMA_Init: Could not toggle. (2)\n"); ++ munmap (dma.buffer, mmaplen); ++ dma.buffer=NULL; + close(audio_fd); + audio_fd = -1; + return 0; +@@ -267,6 +272,8 @@ int SNDDMA_GetDMAPos(void) + { + perror(snddevice->string); + Com_Printf("SNDDMA_GetDMAPos: GETOPTR failed.\n"); ++ munmap (dma.buffer, mmaplen); ++ dma.buffer=NULL; + close(audio_fd); + audio_fd = -1; + snd_inited = 0; +@@ -284,6 +291,8 @@ void SNDDMA_Shutdown(void) + #if 0 + if (snd_inited) + { ++ munmap (dma.buffer, mmaplen); ++ dma.buffer=NULL; + close(audio_fd); + audio_fd = -1; + snd_inited = 0;