use explicit initialization of audio library
This commit is contained in:
parent
8403e175f5
commit
179b578a64
|
|
@ -31,17 +31,17 @@ TypeHandle AudioManager::_type_handle;
|
|||
|
||||
|
||||
namespace {
|
||||
PT(AudioManager) create_NullAudioManger() {
|
||||
audio_debug("create_NullAudioManger()");
|
||||
AudioManager *create_NullAudioManager() {
|
||||
audio_debug("create_NullAudioManager()");
|
||||
return new NullAudioManager();
|
||||
}
|
||||
}
|
||||
|
||||
Create_AudioManager_proc* AudioManager::_create_AudioManager
|
||||
=create_NullAudioManger;
|
||||
=create_NullAudioManager;
|
||||
|
||||
void AudioManager::register_AudioManager_creator(Create_AudioManager_proc* proc) {
|
||||
nassertv(_create_AudioManager==create_NullAudioManger);
|
||||
nassertv(_create_AudioManager==create_NullAudioManager);
|
||||
_create_AudioManager=proc;
|
||||
}
|
||||
|
||||
|
|
@ -50,37 +50,46 @@ void AudioManager::register_AudioManager_creator(Create_AudioManager_proc* proc)
|
|||
// Factory method for getting a platform specific AudioManager:
|
||||
PT(AudioManager) AudioManager::create_AudioManager() {
|
||||
audio_debug("create_AudioManager()\n audio_library_name=\""<<audio_library_name<<"\"");
|
||||
static int lib_load;
|
||||
static bool lib_load = false;
|
||||
if (!lib_load) {
|
||||
lib_load=1;
|
||||
lib_load = true;
|
||||
if (!audio_library_name.empty() && !(audio_library_name == "null")) {
|
||||
Filename dl_name = Filename::dso_filename(
|
||||
"lib"+string(audio_library_name)+".so");
|
||||
dl_name.to_os_specific();
|
||||
audio_debug(" dl_name=\""<<dl_name<<"\"");
|
||||
void* lib = load_dso(get_plugin_path().get_value(), dl_name);
|
||||
if (!lib) {
|
||||
void *handle = load_dso(get_plugin_path().get_value(), dl_name);
|
||||
if (handle == (void *)NULL) {
|
||||
audio_error(" LoadLibrary() failed, will use NullAudioManager");
|
||||
audio_error(" "<<load_dso_error());
|
||||
nassertr(_create_AudioManager==create_NullAudioManger, 0);
|
||||
nassertr(_create_AudioManager == create_NullAudioManager, NULL);
|
||||
} else {
|
||||
// ...the library will register itself with the AudioManager.
|
||||
#if defined(DWORD) && defined(WIN32) && !defined(NDEBUG) //[
|
||||
const int bufLen=256;
|
||||
char path[bufLen];
|
||||
DWORD count = GetModuleFileName((HMODULE)lib, path, bufLen);
|
||||
if (count) {
|
||||
audio_debug(" GetModuleFileName() \""<<path<<"\"");
|
||||
} else {
|
||||
audio_debug(" GetModuleFileName() failed.");
|
||||
}
|
||||
#endif //]
|
||||
// Get the special function from the dso, which should return
|
||||
// the AudioManager factory function.
|
||||
string symbol_name = "get_audio_manager_func_" + audio_library_name.get_value();
|
||||
void *dso_symbol = get_dso_symbol(handle, symbol_name);
|
||||
if (audio_cat.is_debug()) {
|
||||
audio_cat.debug()
|
||||
<< "symbol of " << symbol_name << " = " << dso_symbol << "\n";
|
||||
}
|
||||
|
||||
if (dso_symbol == (void *)NULL) {
|
||||
// Couldn't find the module function.
|
||||
unload_dso(handle);
|
||||
handle = NULL;
|
||||
audio_error(" Audio library did not provide get_audio_manager_func, will use NullAudioManager");
|
||||
} else {
|
||||
typedef Create_AudioManager_proc *FuncType();
|
||||
Create_AudioManager_proc *factory_func = (*(FuncType *)dso_symbol)();
|
||||
AudioManager::register_AudioManager_creator(factory_func);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
PT(AudioManager) am = (*_create_AudioManager)();
|
||||
if (!am->is_valid()) {
|
||||
am = create_NullAudioManger();
|
||||
if (!am->is_exact_type(NullAudioManager::get_class_type()) && !am->is_valid()) {
|
||||
audio_error(" " << am->get_type() << " is not valid, will use NullAudioManager");
|
||||
am = create_NullAudioManager();
|
||||
}
|
||||
return am;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
#include "filterProperties.h"
|
||||
#include "movieAudio.h"
|
||||
|
||||
typedef PT(AudioManager) Create_AudioManager_proc();
|
||||
typedef AudioManager *Create_AudioManager_proc();
|
||||
|
||||
|
||||
class EXPCL_PANDA_AUDIO AudioManager : public TypedReferenceCount {
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@
|
|||
#include "pandabase.h"
|
||||
#ifdef HAVE_FMODEX //[
|
||||
|
||||
|
||||
#include "config_fmodAudio.h"
|
||||
#include "audioManager.h"
|
||||
#include "fmodAudioManager.h"
|
||||
#include "fmodAudioSound.h"
|
||||
#include "pandaSystem.h"
|
||||
|
|
@ -39,15 +39,13 @@ ConfigureFn(config_fmodAudio) {
|
|||
////////////////////////////////////////////////////////////////////
|
||||
void
|
||||
init_libFmodAudio() {
|
||||
cerr << "init_libFmodAudio\n";
|
||||
static bool initialized = false;
|
||||
if (initialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
initialized = true;
|
||||
|
||||
AudioManager::register_AudioManager_creator(Create_AudioManager);
|
||||
|
||||
FmodAudioManager::init_type();
|
||||
FmodAudioSound::init_type();
|
||||
|
||||
|
|
@ -57,4 +55,16 @@ init_libFmodAudio() {
|
|||
ps->set_system_tag("audio", "implementation", "FMOD");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: get_audio_manager_func_fmod_audio
|
||||
// Description: This function is called when the dynamic library is
|
||||
// loaded; it should return the Create_AudioManager
|
||||
// function appropriate to create a FmodAudioManager.
|
||||
///////////////////////////////////////////////////////////////////
|
||||
Create_AudioManager_proc *
|
||||
get_audio_manager_func_fmod_audio() {
|
||||
init_libFmodAudio();
|
||||
return &Create_FmodAudioManager;
|
||||
}
|
||||
|
||||
#endif //]
|
||||
|
|
|
|||
|
|
@ -20,11 +20,13 @@
|
|||
#ifdef HAVE_FMODEX //[
|
||||
#include "notifyCategoryProxy.h"
|
||||
#include "dconfig.h"
|
||||
#include "audioManager.h"
|
||||
|
||||
ConfigureDecl(config_fmodAudio, EXPCL_FMOD_AUDIO, EXPTP_FMOD_AUDIO);
|
||||
NotifyCategoryDecl(fmodAudio, EXPCL_FMOD_AUDIO, EXPTP_FMOD_AUDIO);
|
||||
|
||||
extern EXPCL_FMOD_AUDIO void init_libFmodAudio();
|
||||
extern "C" EXPCL_FMOD_AUDIO Create_AudioManager_proc *get_audio_manager_func_fmod_audio();
|
||||
|
||||
#endif //]
|
||||
|
||||
|
|
|
|||
|
|
@ -77,9 +77,6 @@ init_libMilesAudio() {
|
|||
return;
|
||||
}
|
||||
initialized = true;
|
||||
|
||||
AudioManager::register_AudioManager_creator(Create_AudioManager);
|
||||
|
||||
MilesAudioManager::init_type();
|
||||
MilesAudioSound::init_type();
|
||||
MilesAudioSample::init_type();
|
||||
|
|
@ -92,4 +89,16 @@ init_libMilesAudio() {
|
|||
ps->set_system_tag("audio", "implementation", "Miles");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: get_audio_manager_func_miles_audio
|
||||
// Description: This function is called when the dynamic library is
|
||||
// loaded; it should return the Create_AudioManager
|
||||
// function appropriate to create a MilesAudioManager.
|
||||
///////////////////////////////////////////////////////////////////
|
||||
Create_AudioManager_proc *
|
||||
get_audio_manager_func_miles_audio() {
|
||||
init_libMilesAudio();
|
||||
return &Create_MilesAudioManager;
|
||||
}
|
||||
|
||||
#endif //]
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
#include "configVariableBool.h"
|
||||
#include "configVariableInt.h"
|
||||
#include "dconfig.h"
|
||||
#include "audioManager.h"
|
||||
|
||||
ConfigureDecl(config_milesAudio, EXPCL_MILES_AUDIO, EXPTP_MILES_AUDIO);
|
||||
NotifyCategoryDecl(milesAudio, EXPCL_MILES_AUDIO, EXPTP_MILES_AUDIO);
|
||||
|
|
@ -32,7 +33,7 @@ extern ConfigVariableInt miles_audio_preload_threshold;
|
|||
extern ConfigVariableBool miles_audio_panda_threads;
|
||||
|
||||
extern EXPCL_MILES_AUDIO void init_libMilesAudio();
|
||||
|
||||
extern "C" EXPCL_MILES_AUDIO Create_AudioManager_proc *get_audio_manager_func_miles_audio();
|
||||
#endif //]
|
||||
|
||||
#endif // CONFIG_MILESAUDIO_H
|
||||
|
|
|
|||
|
|
@ -45,9 +45,6 @@ init_libOpenALAudio() {
|
|||
}
|
||||
|
||||
initialized = true;
|
||||
|
||||
AudioManager::register_AudioManager_creator(Create_AudioManager);
|
||||
|
||||
OpenALAudioManager::init_type();
|
||||
OpenALAudioSound::init_type();
|
||||
|
||||
|
|
@ -57,4 +54,16 @@ init_libOpenALAudio() {
|
|||
ps->set_system_tag("audio", "implementation", "OpenAL");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: get_audio_manager_func_openal_audio
|
||||
// Description: This function is called when the dynamic library is
|
||||
// loaded; it should return the Create_AudioManager
|
||||
// function appropriate to create an OpenALAudioManager.
|
||||
///////////////////////////////////////////////////////////////////
|
||||
Create_AudioManager_proc *
|
||||
get_audio_manager_func_openal_audio() {
|
||||
init_libOpenALAudio();
|
||||
return &Create_OpenALAudioManager;
|
||||
}
|
||||
|
||||
#endif //]
|
||||
|
|
|
|||
|
|
@ -20,11 +20,13 @@
|
|||
#ifdef HAVE_OPENAL //[
|
||||
#include "notifyCategoryProxy.h"
|
||||
#include "dconfig.h"
|
||||
#include "audioManager.h"
|
||||
|
||||
ConfigureDecl(config_openalAudio, EXPCL_OPENAL_AUDIO, EXPTP_OPENAL_AUDIO);
|
||||
NotifyCategoryDecl(openalAudio, EXPCL_OPENAL_AUDIO, EXPTP_OPENAL_AUDIO);
|
||||
|
||||
extern EXPCL_OPENAL_AUDIO void init_libOpenALAudio();
|
||||
extern "C" EXPCL_OPENAL_AUDIO Create_AudioManager_proc *get_audio_manager_func_openal_audio();
|
||||
|
||||
#endif //]
|
||||
|
||||
|
|
|
|||
|
|
@ -67,11 +67,12 @@ void fmod_audio_errcheck(const char *context, FMOD_RESULT result) {
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Create_AudioManager
|
||||
// Function: Create_FmodAudioManager
|
||||
// Access: Private
|
||||
// Description: Factory Function
|
||||
////////////////////////////////////////////////////////////////////
|
||||
PT(AudioManager) Create_AudioManager() {
|
||||
AudioManager *Create_FmodAudioManager() {
|
||||
audio_debug("Create_FmodAudioManager()");
|
||||
return new FmodAudioManager;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -238,7 +238,7 @@ private:
|
|||
|
||||
};
|
||||
|
||||
EXPCL_FMOD_AUDIO PT(AudioManager) Create_AudioManager();
|
||||
EXPCL_FMOD_AUDIO AudioManager *Create_FmodAudioManager();
|
||||
|
||||
|
||||
#endif //]
|
||||
|
|
|
|||
|
|
@ -35,8 +35,8 @@
|
|||
|
||||
TypeHandle MilesAudioManager::_type_handle;
|
||||
|
||||
PT(AudioManager) Create_AudioManager() {
|
||||
audio_debug("Create_AudioManager() Miles.");
|
||||
AudioManager *Create_MilesAudioManager() {
|
||||
audio_debug("Create_MilesAudioManager()");
|
||||
return new MilesAudioManager();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -176,7 +176,7 @@ private:
|
|||
friend class MilesAudioStream;
|
||||
};
|
||||
|
||||
EXPCL_MILES_AUDIO PT(AudioManager) Create_AudioManager();
|
||||
EXPCL_MILES_AUDIO AudioManager *Create_MilesAudioManager();
|
||||
|
||||
|
||||
#endif //]
|
||||
|
|
|
|||
|
|
@ -61,11 +61,12 @@ void alc_audio_errcheck(const char *context,ALCdevice* device) {
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Create_AudioManager
|
||||
// Function: Create_OpenALAudioManager
|
||||
// Access: Private
|
||||
// Description: Factory Function
|
||||
////////////////////////////////////////////////////////////////////
|
||||
PT(AudioManager) Create_AudioManager() {
|
||||
AudioManager *Create_OpenALAudioManager() {
|
||||
audio_debug("Create_OpenALAudioManager()");
|
||||
return new OpenALAudioManager;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -242,7 +242,7 @@ private:
|
|||
|
||||
};
|
||||
|
||||
EXPCL_OPENAL_AUDIO PT(AudioManager) Create_AudioManager();
|
||||
EXPCL_OPENAL_AUDIO AudioManager *Create_AudioManager();
|
||||
|
||||
|
||||
#endif //]
|
||||
|
|
|
|||
Loading…
Reference in New Issue