diff --git a/src/audio/codecDescriptor.cpp b/src/audio/codecDescriptor.cpp index 8fe6984658a45fadedf946a74bc9836eb409ae89..63f0cdd1f94c044ae6ab5841402a873e36f141c1 100644 --- a/src/audio/codecDescriptor.cpp +++ b/src/audio/codecDescriptor.cpp @@ -51,7 +51,6 @@ CodecDescriptor::deleteHandlePointer( void ) void CodecDescriptor::init() { - _debug("Scanning %s to find audio codecs....\n", CODECS_DIR); std::vector<AudioCodec*> CodecDynamicList = scanCodecDirectory(); _nbCodecs = CodecDynamicList.size(); if( _nbCodecs <= 0 ){ @@ -194,30 +193,39 @@ CodecDescriptor::scanCodecDirectory( void ) { std::vector<AudioCodec*> codecs; std::string tmp; - std::string codecDir = CODECS_DIR; - codecDir.append("/"); - std::string current = "."; - std::string previous = ".."; - DIR *dir = opendir( codecDir.c_str() ); - AudioCodec* audioCodec; - if( dir ){ - dirent *dirStruct; - while( dirStruct = readdir( dir )) { - tmp = dirStruct -> d_name ; - if( tmp == current || tmp == previous){} - else{ - if( seemsValid( tmp ) ) - { - //_debug("Codec : %s\n", tmp.c_str()); - audioCodec = loadCodec( codecDir.append(tmp) ); - codecs.push_back( audioCodec ); - codecDir = CODECS_DIR; - codecDir.append("/"); + int i; + + std::string libDir = std::string(CODECS_DIR).append("/"); + std::string homeDir = std::string(HOMEDIR) + DIR_SEPARATOR_STR + "." + PROGDIR + "/"; + std::vector<std::string> dirToScan; + dirToScan.push_back(homeDir); + dirToScan.push_back(libDir); + + for( i = 0 ; i < dirToScan.size() ; i++ ) + { + std::string dirStr = dirToScan[i]; + _debug("Scanning %s to find audio codecs....\n", dirStr.c_str()); + DIR *dir = opendir( dirStr.c_str() ); + AudioCodec* audioCodec; + if( dir ){ + dirent *dirStruct; + while( dirStruct = readdir( dir )) { + tmp = dirStruct -> d_name ; + if( tmp == CURRENT_DIR || tmp == PARENT_DIR){} + else{ + if( seemsValid( tmp ) && !alreadyInCache( tmp )) + { + //_debug("Codec : %s\n", tmp.c_str()); + _Cache.push_back( tmp ); + audioCodec = loadCodec( dirStr.append(tmp) ); + codecs.push_back( audioCodec ); + dirStr = dirToScan[i]; + } } } } + closedir( dir ); } - closedir( dir ); return codecs; } @@ -280,3 +288,15 @@ CodecDescriptor::seemsValid( std::string lib) else return false; } + + bool +CodecDescriptor::alreadyInCache( std::string lib ) +{ + int i; + for( i = 0 ; i < _Cache.size() ; i++ ) + { + if( _Cache[i] == lib ){ + return true;} + } + return false; +} diff --git a/src/audio/codecDescriptor.h b/src/audio/codecDescriptor.h index da2ae9ffc0637064ece513ff8028cc5ff5490e58..5991b5707d4af4d396b87e0a031a5a7ed6dcf897 100644 --- a/src/audio/codecDescriptor.h +++ b/src/audio/codecDescriptor.h @@ -30,6 +30,7 @@ #include <dirent.h> #include "../global.h" +#include "../user_cfg.h" #include "codecs/audiocodec.h" typedef enum { @@ -203,7 +204,7 @@ private: void unloadCodec( CodecHandlePointer ); bool seemsValid( std::string ); - + bool alreadyInCache( std::string ); /* * Map the payload of a codec and its name */ @@ -219,6 +220,8 @@ private: */ CodecOrder _codecOrder; + std::vector<std::string> _Cache; + /* * Number of codecs loaded */ diff --git a/src/global.h b/src/global.h index 3e6e963873bcd3628caaa55e250ce7f8216bc979..b842274b017afb32d5b63af92bcfa148e428ca75 100644 --- a/src/global.h +++ b/src/global.h @@ -85,6 +85,8 @@ typedef short int16; #define SFL_CODEC_VALID_PREFIX "libcodec_" #define SFL_CODEC_VALID_EXTEN ".so" +#define CURRENT_DIR "." +#define PARENT_DIR ".." #define SFL_PCM_BOTH 0x0021 #define SFL_PCM_PLAYBACK 0x0022 diff --git a/src/user_cfg.h b/src/user_cfg.h index a70f3858d84ce3216913bb4b83241e042a37ff8d..ba1386914a5c1019fa07865ef22f1b4795aaf66c 100644 --- a/src/user_cfg.h +++ b/src/user_cfg.h @@ -88,12 +88,10 @@ #define DFT_PULSE_LENGTH_STR "250" #define SIP_INFO_STR "0" #define DFT_DRIVER_STR "0" -#define DFT_NB_CODEC_STR "3" // volume by default 100% #define DFT_VOL_SPKR_STR "100" #define DFT_VOL_MICRO_STR "100" -#define DFT_CODECS "0/8/3" // liste ordonnée de payload #define DFT_RINGTONE "konga.ul" #define DFT_SKIN "metal" #define DFT_ZONE "North America" @@ -101,8 +99,6 @@ #define DFT_FRAME_SIZE "20" #define DFT_SAMPLE_RATE "44100" #define SAMPLE_RATE1 "44100" -#define SAMPLE_RATE2 "48000" -#define SAMPLE_RATE3 "96000" // zeroconfig default value #ifdef USE_ZEROCONF #define CONFIG_ZEROCONF_DEFAULT_STR "1"