Use an explicit identifier in Config

This let's us use them to configure them when using WebRTC as an external library. One use case where this is necessary is in the Android OS.

Review URL: https://codereview.webrtc.org/1538643004

Cr-Commit-Position: refs/heads/master@{#11231}
This commit is contained in:
aluebs
2016-01-12 18:50:25 -08:00
committed by Commit bot
parent e591f9377f
commit 25249d92d3
7 changed files with 48 additions and 7 deletions

View File

@ -712,10 +712,16 @@
'include_dirs': [ 'include_dirs': [
'<(DEPTH)/testing/gtest/include', '<(DEPTH)/testing/gtest/include',
], ],
'include_dirs!': [
'<(DEPTH)/webrtc',
],
'direct_dependent_settings': { 'direct_dependent_settings': {
'include_dirs': [ 'include_dirs': [
'<(DEPTH)/testing/gtest/include', '<(DEPTH)/testing/gtest/include',
], ],
'include_dirs!': [
'<(DEPTH)/webrtc',
],
}, },
'sources': [ 'sources': [
'session/media/audiomonitor.cc', 'session/media/audiomonitor.cc',

View File

@ -238,6 +238,12 @@ source_set("webrtc_common") {
configs += [ ":common_config" ] configs += [ ":common_config" ]
public_configs = [ ":common_inherited_config" ] public_configs = [ ":common_inherited_config" ]
if (is_clang) {
# Suppress warnings from Chrome's Clang plugins.
# See http://code.google.com/p/webrtc/issues/detail?id=163 for details.
configs -= [ "//build/config/clang:find_bad_constructs" ]
}
} }
source_set("gtest_prod") { source_set("gtest_prod") {

View File

@ -17,6 +17,23 @@
namespace webrtc { namespace webrtc {
// Only add new values to the end of the enumeration and never remove (only
// deprecate) to maintain binary compatibility.
enum class ConfigOptionID {
kMyExperimentForTest,
kAlgo1CostFunctionForTest,
kTemporalLayersFactory,
kNetEqCapacityConfig,
kNetEqFastAccelerate,
kVoicePacing,
kExtendedFilter,
kDelayAgnostic,
kExperimentalAgc,
kExperimentalNs,
kBeamforming,
kIntelligibility
};
// Class Config is designed to ease passing a set of options across webrtc code. // Class Config is designed to ease passing a set of options across webrtc code.
// Options are identified by typename in order to avoid incorrect casts. // Options are identified by typename in order to avoid incorrect casts.
// //
@ -61,8 +78,6 @@ class Config {
} }
private: private:
typedef void* OptionIdentifier;
struct BaseOption { struct BaseOption {
virtual ~BaseOption() {} virtual ~BaseOption() {}
}; };
@ -76,11 +91,9 @@ class Config {
T* value; T* value;
}; };
// Own implementation of rtti-subset to avoid depending on rtti and its costs.
template<typename T> template<typename T>
static OptionIdentifier identifier() { static ConfigOptionID identifier() {
static char id_placeholder; return T::identifier;
return &id_placeholder;
} }
// Used to instantiate a default constructed object that doesn't needs to be // Used to instantiate a default constructed object that doesn't needs to be
@ -92,7 +105,7 @@ class Config {
return def; return def;
} }
typedef std::map<OptionIdentifier, BaseOption*> OptionMap; typedef std::map<ConfigOptionID, BaseOption*> OptionMap;
OptionMap options_; OptionMap options_;
// RTC_DISALLOW_COPY_AND_ASSIGN // RTC_DISALLOW_COPY_AND_ASSIGN

View File

@ -16,6 +16,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "webrtc/common.h"
#include "webrtc/common_types.h" #include "webrtc/common_types.h"
#include "webrtc/typedefs.h" #include "webrtc/typedefs.h"
@ -128,6 +129,7 @@ struct VideoEncoderConfig {
struct NetEqCapacityConfig { struct NetEqCapacityConfig {
NetEqCapacityConfig() : enabled(false), capacity(0) {} NetEqCapacityConfig() : enabled(false), capacity(0) {}
explicit NetEqCapacityConfig(int value) : enabled(true), capacity(value) {} explicit NetEqCapacityConfig(int value) : enabled(true), capacity(value) {}
static const ConfigOptionID identifier = ConfigOptionID::kNetEqCapacityConfig;
bool enabled; bool enabled;
int capacity; int capacity;
}; };
@ -135,12 +137,14 @@ struct NetEqCapacityConfig {
struct NetEqFastAccelerate { struct NetEqFastAccelerate {
NetEqFastAccelerate() : enabled(false) {} NetEqFastAccelerate() : enabled(false) {}
explicit NetEqFastAccelerate(bool value) : enabled(value) {} explicit NetEqFastAccelerate(bool value) : enabled(value) {}
static const ConfigOptionID identifier = ConfigOptionID::kNetEqFastAccelerate;
bool enabled; bool enabled;
}; };
struct VoicePacing { struct VoicePacing {
VoicePacing() : enabled(false) {} VoicePacing() : enabled(false) {}
explicit VoicePacing(bool value) : enabled(value) {} explicit VoicePacing(bool value) : enabled(value) {}
static const ConfigOptionID identifier = ConfigOptionID::kVoicePacing;
bool enabled; bool enabled;
}; };

View File

@ -65,6 +65,7 @@ class VoiceDetection;
struct ExtendedFilter { struct ExtendedFilter {
ExtendedFilter() : enabled(false) {} ExtendedFilter() : enabled(false) {}
explicit ExtendedFilter(bool enabled) : enabled(enabled) {} explicit ExtendedFilter(bool enabled) : enabled(enabled) {}
static const ConfigOptionID identifier = ConfigOptionID::kExtendedFilter;
bool enabled; bool enabled;
}; };
@ -76,6 +77,7 @@ struct ExtendedFilter {
struct DelayAgnostic { struct DelayAgnostic {
DelayAgnostic() : enabled(false) {} DelayAgnostic() : enabled(false) {}
explicit DelayAgnostic(bool enabled) : enabled(enabled) {} explicit DelayAgnostic(bool enabled) : enabled(enabled) {}
static const ConfigOptionID identifier = ConfigOptionID::kDelayAgnostic;
bool enabled; bool enabled;
}; };
@ -96,6 +98,7 @@ struct ExperimentalAgc {
: enabled(enabled), startup_min_volume(kAgcStartupMinVolume) {} : enabled(enabled), startup_min_volume(kAgcStartupMinVolume) {}
ExperimentalAgc(bool enabled, int startup_min_volume) ExperimentalAgc(bool enabled, int startup_min_volume)
: enabled(enabled), startup_min_volume(startup_min_volume) {} : enabled(enabled), startup_min_volume(startup_min_volume) {}
static const ConfigOptionID identifier = ConfigOptionID::kExperimentalAgc;
bool enabled; bool enabled;
int startup_min_volume; int startup_min_volume;
}; };
@ -105,6 +108,7 @@ struct ExperimentalAgc {
struct ExperimentalNs { struct ExperimentalNs {
ExperimentalNs() : enabled(false) {} ExperimentalNs() : enabled(false) {}
explicit ExperimentalNs(bool enabled) : enabled(enabled) {} explicit ExperimentalNs(bool enabled) : enabled(enabled) {}
static const ConfigOptionID identifier = ConfigOptionID::kExperimentalNs;
bool enabled; bool enabled;
}; };
@ -127,6 +131,7 @@ struct Beamforming {
: enabled(enabled), : enabled(enabled),
array_geometry(array_geometry), array_geometry(array_geometry),
target_direction(target_direction) {} target_direction(target_direction) {}
static const ConfigOptionID identifier = ConfigOptionID::kBeamforming;
const bool enabled; const bool enabled;
const std::vector<Point> array_geometry; const std::vector<Point> array_geometry;
const SphericalPointf target_direction; const SphericalPointf target_direction;
@ -141,6 +146,7 @@ struct Beamforming {
struct Intelligibility { struct Intelligibility {
Intelligibility() : enabled(false) {} Intelligibility() : enabled(false) {}
explicit Intelligibility(bool enabled) : enabled(enabled) {} explicit Intelligibility(bool enabled) : enabled(enabled) {}
static const ConfigOptionID identifier = ConfigOptionID::kIntelligibility;
bool enabled; bool enabled;
}; };

View File

@ -14,6 +14,7 @@
#include "vpx/vpx_encoder.h" #include "vpx/vpx_encoder.h"
#include "webrtc/common.h"
#include "webrtc/common_video/include/video_image.h" #include "webrtc/common_video/include/video_image.h"
#include "webrtc/typedefs.h" #include "webrtc/typedefs.h"
@ -30,6 +31,8 @@ class TemporalLayers {
virtual ~Factory() {} virtual ~Factory() {}
virtual TemporalLayers* Create(int temporal_layers, virtual TemporalLayers* Create(int temporal_layers,
uint8_t initial_tl0_pic_idx) const; uint8_t initial_tl0_pic_idx) const;
static const ConfigOptionID identifier =
ConfigOptionID::kTemporalLayersFactory;
}; };
virtual ~TemporalLayers() {} virtual ~TemporalLayers() {}

View File

@ -15,6 +15,7 @@ namespace webrtc {
namespace { namespace {
struct MyExperiment { struct MyExperiment {
static const ConfigOptionID identifier = ConfigOptionID::kMyExperimentForTest;
static const int kDefaultFactor; static const int kDefaultFactor;
static const int kDefaultOffset; static const int kDefaultOffset;
@ -56,6 +57,8 @@ TEST(Config, SetNullSetsTheOptionBackToDefault) {
} }
struct Algo1_CostFunction { struct Algo1_CostFunction {
static const ConfigOptionID identifier =
ConfigOptionID::kAlgo1CostFunctionForTest;
Algo1_CostFunction() {} Algo1_CostFunction() {}
virtual int cost(int x) const { virtual int cost(int x) const {