r874 - trunk/code/client
DONOTREPLY at icculus.org
DONOTREPLY at icculus.org
Sun Aug 27 11:31:04 EDT 2006
Author: thilo
Date: 2006-08-27 11:31:03 -0400 (Sun, 27 Aug 2006)
New Revision: 874
Modified:
trunk/code/client/snd_openal.c
Log:
- Fixed filehandle / filedescriptor leak in S_AL_StartBackgroundTrack introduced in rev. 832
- intro now plays correctly before looping sound.
Modified: trunk/code/client/snd_openal.c
===================================================================
--- trunk/code/client/snd_openal.c 2006-08-26 12:43:38 UTC (rev 873)
+++ trunk/code/client/snd_openal.c 2006-08-27 15:31:03 UTC (rev 874)
@@ -1291,6 +1291,7 @@
static ALuint musicBuffers[NUM_MUSIC_BUFFERS];
static snd_stream_t *mus_stream;
+static snd_stream_t *intro_stream;
static char s_backgroundLoop[MAX_QPATH];
static byte decode_buffer[MUSIC_BUFFER_SIZE];
@@ -1334,6 +1335,26 @@
/*
=================
+S_AL_CloseMusicFiles
+=================
+*/
+static void S_AL_CloseMusicFiles(void)
+{
+ if(intro_stream)
+ {
+ S_CodecCloseStream(intro_stream);
+ intro_stream = NULL;
+ }
+
+ if(mus_stream)
+ {
+ S_CodecCloseStream(mus_stream);
+ mus_stream = NULL;
+ }
+}
+
+/*
+=================
S_AL_StopBackgroundTrack
=================
*/
@@ -1356,9 +1377,7 @@
S_AL_MusicSourceFree();
// Unload the stream
- if(mus_stream)
- S_CodecCloseStream(mus_stream);
- mus_stream = NULL;
+ S_AL_CloseMusicFiles();
musicPlaying = qfalse;
}
@@ -1374,27 +1393,42 @@
ALenum error;
int l;
ALuint format;
+ snd_stream_t *curstream;
- if(!mus_stream)
+ if(intro_stream)
+ curstream = intro_stream;
+ else
+ curstream = mus_stream;
+
+ if(!curstream)
return;
- l = S_CodecReadStream(mus_stream, MUSIC_BUFFER_SIZE, decode_buffer);
+ l = S_CodecReadStream(curstream, MUSIC_BUFFER_SIZE, decode_buffer);
// Run out data to read, start at the beginning again
if(l == 0)
{
- S_CodecCloseStream(mus_stream);
- mus_stream = S_CodecOpenStream(s_backgroundLoop);
- if(!mus_stream)
+ S_CodecCloseStream(curstream);
+
+ // the intro stream just finished playing so we don't need to reopen
+ // the music stream.
+ if(intro_stream)
+ intro_stream = NULL;
+ else
+ mus_stream = S_CodecOpenStream(s_backgroundLoop);
+
+ curstream = mus_stream;
+
+ if(!curstream)
{
S_AL_StopBackgroundTrack();
return;
}
- l = S_CodecReadStream(mus_stream, MUSIC_BUFFER_SIZE, decode_buffer);
+ l = S_CodecReadStream(curstream, MUSIC_BUFFER_SIZE, decode_buffer);
}
- format = S_AL_Format(mus_stream->info.width, mus_stream->info.channels);
+ format = S_AL_Format(curstream->info.width, curstream->info.channels);
if( l == 0 )
{
@@ -1404,7 +1438,7 @@
qalBufferData( b, AL_FORMAT_MONO16, (void *)dummyData, 2, 22050 );
}
else
- qalBufferData(b, format, decode_buffer, l, mus_stream->info.rate);
+ qalBufferData(b, format, decode_buffer, l, curstream->info.rate);
if( ( error = qalGetError( ) ) != AL_NO_ERROR )
{
@@ -1424,37 +1458,45 @@
void S_AL_StartBackgroundTrack( const char *intro, const char *loop )
{
int i;
+ qboolean issame;
// Stop any existing music that might be playing
S_AL_StopBackgroundTrack();
- if ( !intro || !intro[0] ) {
- intro = loop;
- }
- if ( !loop || !loop[0] ) {
+ if((!intro || !*intro) && (!intro || !*intro))
+ return;
+
+ // Allocate a musicSource
+ S_AL_MusicSourceGet();
+ if(musicSourceHandle == -1)
+ return;
+
+ if (!loop || !*loop)
+ {
loop = intro;
+ issame = qtrue;
}
+ else if(intro && *intro && !strcmp(intro, loop))
+ issame = qtrue;
+ else
+ issame = qfalse;
- if((!intro || !intro[0]) && (!intro || !intro[0]))
- return;
-
// Copy the loop over
strncpy( s_backgroundLoop, loop, sizeof( s_backgroundLoop ) );
- // Open the intro
- mus_stream = S_CodecOpenStream(intro);
+ if(!issame)
+ {
+ // Open the intro and don't mind whether it succeeds.
+ // The important part is the loop.
+ intro_stream = S_CodecOpenStream(intro);
+ }
+ else
+ intro_stream = NULL;
- if(!mus_stream)
- return;
-
- // Allocate a musicSource
- S_AL_MusicSourceGet();
- if(musicSourceHandle == -1)
- return;
-
mus_stream = S_CodecOpenStream(s_backgroundLoop);
if(!mus_stream)
{
+ S_AL_CloseMusicFiles();
S_AL_MusicSourceFree();
return;
}
More information about the quake3-commits
mailing list