From: Alyssa M. <fu...@us...> - 2010-08-16 19:26:43
|
gemrb: Infinity Engine emulator The branch master has been updated via 1b08a57f397fd0e164e476c84b0c7fe99655eb3d (commit) Summary of changes: gemrb/plugins/SDLAudio/SDLAudio.cpp | 29 +++++++++++++++++++++++++++-- gemrb/plugins/SDLAudio/SDLAudio.h | 3 +++ 2 files changed, 30 insertions(+), 2 deletions(-) from 9386fd908367f981a04cbf8271036cc3ef59e438 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- http://gemrb.git.sourceforge.net/git/gitweb.cgi?p=gemrb/gemrb;a=commitdiff;h=1b08a57f397fd0e164e476c84b0c7fe99655eb3d commit 1b08a57f397fd0e164e476c84b0c7fe99655eb3d Author: Alyssa Milburn <fu...@fu...> Date: Mon Aug 16 21:27:59 2010 +0200 SDLAudio: don't leak audio buffers diff --git a/gemrb/plugins/SDLAudio/SDLAudio.cpp b/gemrb/plugins/SDLAudio/SDLAudio.cpp index 6ac9f1a..7d46baa 100644 --- a/gemrb/plugins/SDLAudio/SDLAudio.cpp +++ b/gemrb/plugins/SDLAudio/SDLAudio.cpp @@ -48,8 +48,12 @@ SDLAudio::~SDLAudio(void) Mix_HookMusic(NULL, NULL); FreeBuffers(); SDL_DestroyMutex(OurMutex); + Mix_ChannelFinished(NULL); } +// no user data for Mix_ChannelFinished :( +SDLAudio *g_sdlaudio = NULL; + bool SDLAudio::Init(void) { // TODO: we assume SDLVideo already got loaded @@ -61,7 +65,15 @@ bool SDLAudio::Init(void) return false; } Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels); + + channel_data.resize(Mix_AllocateChannels(-1)); + for (unsigned int i = 0; i < channel_data.size(); i++) { + channel_data[i] = NULL; + } + + g_sdlaudio = this; Mix_ReserveChannels(1); // for speech + Mix_ChannelFinished(channel_done_callback); return true; } @@ -91,6 +103,16 @@ void SDLAudio::music_callback(void *udata, unsigned short *stream, int len) { SDL_mutexV(driver->OurMutex); } +void SDLAudio::channel_done_callback(int channel) { + SDL_mutexP(g_sdlaudio->OurMutex); + assert(g_sdlaudio); + assert((unsigned int)channel < g_sdlaudio->channel_data.size()); + assert(g_sdlaudio->channel_data[channel]); + free(g_sdlaudio->channel_data[channel]); + g_sdlaudio->channel_data[channel] = NULL; + SDL_mutexV(g_sdlaudio->OurMutex); +} + unsigned int SDLAudio::Play(const char* ResRef, int XPos, int YPos, unsigned int flags) { // TODO: some panning @@ -148,14 +170,17 @@ unsigned int SDLAudio::Play(const char* ResRef, int XPos, int YPos, unsigned int if (flags & GEM_SND_SPEECH) { channel = 0; } + SDL_mutexP(OurMutex); channel = Mix_PlayChannel(channel, chunk, 0); if (channel < 0) { + SDL_mutexV(OurMutex); printf("error playing channel\n"); return 0; } - // TODO: keep track of the chunk, don't just leak! - // free(cvt.buf); // TODO: safe? + assert((unsigned int)channel < channel_data.size()); + channel_data[channel] = cvt.buf; + SDL_mutexV(OurMutex); return time_length; } diff --git a/gemrb/plugins/SDLAudio/SDLAudio.h b/gemrb/plugins/SDLAudio/SDLAudio.h index 65e3e57..5eff4bc 100644 --- a/gemrb/plugins/SDLAudio/SDLAudio.h +++ b/gemrb/plugins/SDLAudio/SDLAudio.h @@ -57,6 +57,9 @@ private: static void music_callback(void *udata, unsigned short *stream, int len); static void buffer_callback(void *udata, char *stream, int len); + static void channel_done_callback(int channel); + + std::vector<void *> channel_data; int XPos, YPos; Holder<SoundMgr> MusicReader; ----------------------------------------------------------------------- This is an automated email from the git hooks/post-receive script. -- gemrb: Infinity Engine emulator |