Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 9 Aug 2013 13:28:18 +0000 (UTC)
From:      Alexey Dokuchaev <danfe@FreeBSD.org>
To:        ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org
Subject:   svn commit: r324435 - in head/games/quake2lnx: . files
Message-ID:  <201308091328.r79DSIt7046790@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
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 <sys/mman.h>
+ #include <sys/shm.h>
+ #include <sys/wait.h>
+-#if defined(__FreeBSD__)
+ #include <sys/soundcard.h>
+-#endif
+-#if defined(__linux__)
+-#include <linux/soundcard.h>
+-#endif
+ #include <stdio.h>
++#include <unistd.h>
+ 
+ #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;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201308091328.r79DSIt7046790>