| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
#ifndef MODULES_AUDIO_PROCESSING_INCLUDE_CONFIG_H_ |
| 12 |
#define MODULES_AUDIO_PROCESSING_INCLUDE_CONFIG_H_ |
| 13 |
|
| 14 |
#include <map> |
| 15 |
|
| 16 |
#include "rtc_base/system/rtc_export.h" |
| 17 |
|
| 18 |
namespace webrtc { |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
enum class ConfigOptionID { |
| 23 |
kMyExperimentForTest, |
| 24 |
kAlgo1CostFunctionForTest, |
| 25 |
kTemporalLayersFactory, |
| 26 |
kNetEqCapacityConfig, |
| 27 |
kNetEqFastAccelerate, |
| 28 |
kVoicePacing, |
| 29 |
kExtendedFilter, |
| 30 |
kDelayAgnostic, |
| 31 |
kExperimentalAgc, |
| 32 |
kExperimentalNs, |
| 33 |
kBeamforming, |
| 34 |
kIntelligibility, |
| 35 |
kEchoCanceller3, |
| 36 |
kAecRefinedAdaptiveFilter, |
| 37 |
kLevelControl |
| 38 |
}; |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
class RTC_EXPORT Config { |
| 61 |
public: |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
template <typename T> |
| 68 |
const T& Get() const; |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
template <typename T> |
| 73 |
void Set(T* value); |
| 74 |
|
| 75 |
Config(); |
| 76 |
~Config(); |
| 77 |
|
| 78 |
private: |
| 79 |
struct BaseOption { |
| 80 |
virtual ~BaseOption() {} |
| 81 |
}; |
| 82 |
|
| 83 |
template <typename T> |
| 84 |
struct Option : BaseOption { |
| 85 |
explicit Option(T* v) : value(v) {} |
| 86 |
~Option() { delete value; } |
| 87 |
T* value; |
| 88 |
}; |
| 89 |
|
| 90 |
template <typename T> |
| 91 |
static ConfigOptionID identifier() { |
| 92 |
return T::identifier; |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
template <typename T> |
| 99 |
static const T& default_value() { |
| 100 |
static const T* const def = new T(); |
| 101 |
return *def; |
| 102 |
} |
| 103 |
|
| 104 |
typedef std::map<ConfigOptionID, BaseOption*> OptionMap; |
| 105 |
OptionMap options_; |
| 106 |
|
| 107 |
Config(const Config&); |
| 108 |
void operator=(const Config&); |
| 109 |
}; |
| 110 |
|
| 111 |
template <typename T> |
| 112 |
const T& Config::Get() const { |
| 113 |
OptionMap::const_iterator it = options_.find(identifier<T>()); |
| 114 |
if (it != options_.end()) { |
| 115 |
const T* t = static_cast<Option<T>*>(it->second)->value; |
| 116 |
if (t) { |
| 117 |
return *t; |
| 118 |
} |
| 119 |
} |
| 120 |
return default_value<T>(); |
| 121 |
} |
| 122 |
|
| 123 |
template <typename T> |
| 124 |
void Config::Set(T* value) { |
| 125 |
BaseOption*& it = options_[identifier<T>()]; |
| 126 |
delete it; |
| 127 |
it = new Option<T>(value); |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
#endif |