Skip to content

Commit

Permalink
dsFMOD: Do not call exported functions internally in the plugin
Browse files Browse the repository at this point in the history
If the same exported symbol (e.g., DM_Music_*) is present in multiple
concurrently loaded plugins, a call may not end up in the right place
on Unix platforms.

Changing the linker settings would alleviate this.
  • Loading branch information
skyjake committed Jul 12, 2012
1 parent c8263d4 commit 1c07905
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 18 deletions.
3 changes: 3 additions & 0 deletions doomsday/plugins/fmod/include/fmod_cd.h
Expand Up @@ -41,4 +41,7 @@ void DM_CDAudio_Stop(void);
}
#endif

// Internal:
void DMFmod_CDAudio_Shutdown(void);

#endif /* end of include guard: __FMOD_CD_H__ */
9 changes: 7 additions & 2 deletions doomsday/plugins/fmod/include/fmod_music.h
Expand Up @@ -46,7 +46,12 @@ int DM_Music_PlayFile(const char *filename, int looped);
#endif

// Internal:
void DM_Music_SetSoundFont(const char* fileName);
bool DM_Music_PlaySound(FMOD::Sound* customSound, bool needRelease);
void DMFmod_Music_Shutdown(void);
bool DMFmod_Music_PlaySound(FMOD::Sound* customSound, bool needRelease);
void DMFmod_Music_Pause(int setPause);
void DMFmod_Music_Stop(void);
void DMFmod_Music_Set(int prop, float value);
int DMFmod_Music_Get(int prop, void* ptr);
void DMFmod_Music_SetSoundFont(const char* fileName);

#endif /* end of include guard: __DSFMOD_MUS_H__ */
6 changes: 3 additions & 3 deletions doomsday/plugins/fmod/src/driver_fmod.cpp
Expand Up @@ -98,8 +98,8 @@ int DS_Init(void)
*/
void DS_Shutdown(void)
{
DM_Music_Shutdown();
DM_CDAudio_Shutdown();
DMFmod_Music_Shutdown();
DMFmod_CDAudio_Shutdown();

DSFMOD_TRACE("DS_Shutdown.");
fmodSystem->release();
Expand Down Expand Up @@ -135,7 +135,7 @@ int DS_Set(int prop, const void* ptr)
// Use the default.
path = 0;
}
DM_Music_SetSoundFont(path);
DMFmod_Music_SetSoundFont(path);
return true; }

default:
Expand Down
17 changes: 11 additions & 6 deletions doomsday/plugins/fmod/src/fmod_cd.cpp
Expand Up @@ -35,12 +35,17 @@ int DM_CDAudio_Init(void)
return fmodSystem != 0;
}

void DM_CDAudio_Shutdown(void)
void DMFmod_CDAudio_Shutdown(void)
{
// Will be shut down with the rest of FMOD.
DSFMOD_TRACE("CDAudio_Shutdown.");
}

void DM_CDAudio_Shutdown(void)
{
DMFmod_CDAudio_Shutdown();
}

void DM_CDAudio_Update(void)
{
// No need to update anything.
Expand All @@ -53,7 +58,7 @@ void DM_CDAudio_Set(int prop, float value)
switch(prop)
{
case MUSIP_VOLUME:
DM_Music_Set(MUSIP_VOLUME, value);
DMFmod_Music_Set(MUSIP_VOLUME, value);
break;

default:
Expand All @@ -76,7 +81,7 @@ int DM_CDAudio_Get(int prop, void* ptr)
break;

case MUSIP_PLAYING:
return DM_Music_Get(MUSIP_PLAYING, ptr);
return DMFmod_Music_Get(MUSIP_PLAYING, ptr);

default:
return false;
Expand Down Expand Up @@ -160,17 +165,17 @@ int DM_CDAudio_Play(int track, int looped)
}
#endif

return DM_Music_PlaySound(trackSound, needRelease); // takes ownership
return DMFmod_Music_PlaySound(trackSound, needRelease); // takes ownership
}

void DM_CDAudio_Pause(int pause)
{
DM_Music_Pause(pause);
DMFmod_Music_Pause(pause);
}

void DM_CDAudio_Stop(void)
{
DM_Music_Stop();
DMFmod_Music_Stop();

if(cdSound)
{
Expand Down
40 changes: 33 additions & 7 deletions doomsday/plugins/fmod/src/fmod_music.cpp
Expand Up @@ -111,7 +111,7 @@ int DM_Music_Init(void)
return fmodSystem != 0;
}

void DM_Music_Shutdown(void)
void DMFmod_Music_Shutdown(void)
{
if(!fmodSystem) return;

Expand All @@ -124,12 +124,18 @@ void DM_Music_Shutdown(void)
DSFMOD_TRACE("Music_Shutdown.");
}

void DM_Music_SetSoundFont(const char* fileName)
void DM_Music_Shutdown(void)
{
DMFmod_Music_Shutdown();
}

/// @internal
void DMFmod_Music_SetSoundFont(const char* fileName)
{
soundFontFileName = fileName;
}

void DM_Music_Set(int prop, float value)
void DMFmod_Music_Set(int prop, float value)
{
if(!fmodSystem)
return;
Expand All @@ -147,7 +153,12 @@ void DM_Music_Set(int prop, float value)
}
}

int DM_Music_Get(int prop, void* ptr)
void DM_Music_Set(int prop, float value)
{
DMFmod_Music_Set(prop, value);
}

int DMFmod_Music_Get(int prop, void* ptr)
{
switch(prop)
{
Expand All @@ -170,12 +181,17 @@ int DM_Music_Get(int prop, void* ptr)
return false;
}

int DM_Music_Get(int prop, void* ptr)
{
return DMFmod_Music_Get(prop, ptr);
}

void DM_Music_Update(void)
{
// No need to do anything. The callback handles restarting.
}

void DM_Music_Stop(void)
void DMFmod_Music_Stop(void)
{
if(!fmodSystem || !music) return;

Expand All @@ -184,6 +200,11 @@ void DM_Music_Stop(void)
music->stop();
}

void DM_Music_Stop(void)
{
DMFmod_Music_Stop();
}

static bool startSong()
{
if(!fmodSystem || !song) return false;
Expand All @@ -205,7 +226,7 @@ static bool startSong()
}

/// @internal
bool DM_Music_PlaySound(FMOD::Sound* customSound, bool needRelease)
bool DMFmod_Music_PlaySound(FMOD::Sound* customSound, bool needRelease)
{
releaseSong();
releaseSongBuffer();
Expand Down Expand Up @@ -251,13 +272,18 @@ int DM_Music_Play(int looped)
return startSong();
}

void DM_Music_Pause(int setPause)
void DMFmod_Music_Pause(int setPause)
{
if(!fmodSystem || !music) return;

music->setPaused(setPause != 0);
}

void DM_Music_Pause(int setPause)
{
DMFmod_Music_Pause(setPause);
}

void* DM_Music_SongBuffer(unsigned int length)
{
if(!fmodSystem) return NULL;
Expand Down

0 comments on commit 1c07905

Please sign in to comment.