Connect webrtc::Config to WrappingBitrateEstimator

This is the second CL for this change. Connection to the ViE API
remains to be done.

BUG=2698
R=mflodman@webrtc.org, stefan@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/5769004

git-svn-id: http://webrtc.googlecode.com/svn/trunk/webrtc@5455 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/experiments.h b/experiments.h
index 0fe1cd1..f6d54a0 100644
--- a/experiments.h
+++ b/experiments.h
@@ -21,5 +21,12 @@
 
   const bool redundant_payloads;
 };
+
+struct RemoteBitrateEstimatorMinRate {
+  RemoteBitrateEstimatorMinRate() : min_rate(30000) {}
+  RemoteBitrateEstimatorMinRate(uint32_t min_rate) : min_rate(min_rate) {}
+
+  uint32_t min_rate;
+};
 }  // namespace webrtc
 #endif  // WEBRTC_EXPERIMENTS_H_
diff --git a/video_engine/vie_base_impl.cc b/video_engine/vie_base_impl.cc
index 9b466b2..d9276f5 100644
--- a/video_engine/vie_base_impl.cc
+++ b/video_engine/vie_base_impl.cc
@@ -154,9 +154,15 @@
 }
 
 int ViEBaseImpl::CreateChannel(int& video_channel) {  // NOLINT
+  return CreateChannel(video_channel, static_cast<const Config*>(NULL));
+}
+
+int ViEBaseImpl::CreateChannel(int& video_channel,  // NOLINT
+                               const Config* config) {
   WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_.instance_id()),
                "%s", __FUNCTION__);
-  if (shared_data_.channel_manager()->CreateChannel(&video_channel) == -1) {
+  if (shared_data_.channel_manager()->CreateChannel(&video_channel,
+                                                    config) == -1) {
     WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(shared_data_.instance_id()),
                  "%s: Could not create channel", __FUNCTION__);
     video_channel = -1;
diff --git a/video_engine/vie_base_impl.h b/video_engine/vie_base_impl.h
index 231efc9..04c1b40 100644
--- a/video_engine/vie_base_impl.h
+++ b/video_engine/vie_base_impl.h
@@ -40,6 +40,8 @@
                                  int* capture_queue_delay_ms_per_s);
   virtual int CreateChannel(int& video_channel);  // NOLINT
   virtual int CreateChannel(int& video_channel,  // NOLINT
+                            const Config* config);
+  virtual int CreateChannel(int& video_channel,  // NOLINT
                             int original_channel);
   virtual int CreateReceiveChannel(int& video_channel,  // NOLINT
                                    int original_channel);
diff --git a/video_engine/vie_channel_group.cc b/video_engine/vie_channel_group.cc
index f079a10..f79d65a 100644
--- a/video_engine/vie_channel_group.cc
+++ b/video_engine/vie_channel_group.cc
@@ -11,6 +11,7 @@
 #include "webrtc/video_engine/vie_channel_group.h"
 
 #include "webrtc/common.h"
+#include "webrtc/experiments.h"
 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h"
 #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h"
 #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h"
@@ -31,13 +32,14 @@
 class WrappingBitrateEstimator : public RemoteBitrateEstimator {
  public:
   WrappingBitrateEstimator(int engine_id, RemoteBitrateObserver* observer,
-                           Clock* clock, ProcessThread* process_thread)
+                           Clock* clock, ProcessThread* process_thread,
+                           const Config& config)
       : observer_(observer),
         clock_(clock),
         process_thread_(process_thread),
         crit_sect_(CriticalSectionWrapper::CreateCriticalSection()),
         engine_id_(engine_id),
-        min_bitrate_bps_(30000),
+        min_bitrate_bps_(config.Get<RemoteBitrateEstimatorMinRate>().min_rate),
         rbe_(RemoteBitrateEstimatorFactory().Create(observer_, clock_,
                                                     min_bitrate_bps_)),
         using_absolute_send_time_(false),
@@ -131,15 +133,23 @@
 }  // namespace
 
 ChannelGroup::ChannelGroup(int engine_id, ProcessThread* process_thread,
-                           const Config& config)
+                           const Config* config)
     : remb_(new VieRemb()),
       bitrate_controller_(BitrateController::CreateBitrateController(true)),
       call_stats_(new CallStats()),
-      remote_bitrate_estimator_(new WrappingBitrateEstimator(engine_id,
-                                remb_.get(), Clock::GetRealTimeClock(),
-                                process_thread)),
       encoder_state_feedback_(new EncoderStateFeedback()),
+      config_(config),
+      own_config_(),
       process_thread_(process_thread) {
+  if (!config) {
+    own_config_.reset(new Config);
+    config_ = own_config_.get();
+  }
+  assert(config_);  // Must have a valid config pointer here.
+  remote_bitrate_estimator_.reset(
+      new WrappingBitrateEstimator(engine_id, remb_.get(),
+                                   Clock::GetRealTimeClock(), process_thread,
+                                   *config_)),
   call_stats_->RegisterStatsObserver(remote_bitrate_estimator_.get());
   process_thread->RegisterModule(call_stats_.get());
 }
diff --git a/video_engine/vie_channel_group.h b/video_engine/vie_channel_group.h
index 95a042e..036967f 100644
--- a/video_engine/vie_channel_group.h
+++ b/video_engine/vie_channel_group.h
@@ -32,7 +32,7 @@
 class ChannelGroup {
  public:
   ChannelGroup(int engine_id, ProcessThread* process_thread,
-               const Config& config);
+               const Config* config);
   ~ChannelGroup();
 
   void AddChannel(int channel_id);
@@ -57,6 +57,9 @@
   scoped_ptr<RemoteBitrateEstimator> remote_bitrate_estimator_;
   scoped_ptr<EncoderStateFeedback> encoder_state_feedback_;
   ChannelSet channels_;
+  const Config* config_;
+  // Placeholder for the case where this owns the config.
+  scoped_ptr<Config> own_config_;
 
   // Registered at construct time and assumed to outlive this class.
   ProcessThread* process_thread_;
diff --git a/video_engine/vie_channel_manager.cc b/video_engine/vie_channel_manager.cc
index b62e282..37e4692 100644
--- a/video_engine/vie_channel_manager.cc
+++ b/video_engine/vie_channel_manager.cc
@@ -10,6 +10,7 @@
 
 #include "webrtc/video_engine/vie_channel_manager.h"
 
+#include "webrtc/common.h"
 #include "webrtc/engine_configurations.h"
 #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h"
 #include "webrtc/modules/utility/interface/process_thread.h"
@@ -37,7 +38,7 @@
       voice_sync_interface_(NULL),
       voice_engine_(NULL),
       module_process_thread_(NULL),
-      config_(config) {
+      engine_config_(config) {
   WEBRTC_TRACE(kTraceMemory, kTraceVideo, ViEId(engine_id),
                "ViEChannelManager::ViEChannelManager(engine_id: %d)",
                engine_id);
@@ -79,7 +80,8 @@
   module_process_thread_ = module_process_thread;
 }
 
-int ViEChannelManager::CreateChannel(int* channel_id) {
+int ViEChannelManager::CreateChannel(int* channel_id,
+                                     const Config* channel_group_config) {
   CriticalSectionScoped cs(channel_id_critsect_);
 
   // Get a new channel id.
@@ -90,11 +92,11 @@
 
   // Create a new channel group and add this channel.
   ChannelGroup* group = new ChannelGroup(engine_id_, module_process_thread_,
-                                         config_);
+                                         channel_group_config);
   BitrateController* bitrate_controller = group->GetBitrateController();
   ViEEncoder* vie_encoder = new ViEEncoder(engine_id_, new_channel_id,
                                            number_of_cores_,
-                                           config_,
+                                           engine_config_,
                                            *module_process_thread_,
                                            bitrate_controller);
 
@@ -163,7 +165,7 @@
   if (sender) {
     // We need to create a new ViEEncoder.
     vie_encoder = new ViEEncoder(engine_id_, new_channel_id, number_of_cores_,
-                                 config_,
+                                 engine_config_,
                                  *module_process_thread_,
                                  bitrate_controller);
     if (!(vie_encoder->Init() &&
@@ -402,7 +404,7 @@
 
   ViEChannel* vie_channel = new ViEChannel(channel_id, engine_id_,
                                            number_of_cores_,
-                                           config_,
+                                           engine_config_,
                                            *module_process_thread_,
                                            intra_frame_observer,
                                            bandwidth_observer,
diff --git a/video_engine/vie_channel_manager.h b/video_engine/vie_channel_manager.h
index db9eb11..8325098 100644
--- a/video_engine/vie_channel_manager.h
+++ b/video_engine/vie_channel_manager.h
@@ -50,7 +50,8 @@
   void SetModuleProcessThread(ProcessThread* module_process_thread);
 
   // Creates a new channel. 'channel_id' will be the id of the created channel.
-  int CreateChannel(int* channel_id);
+  int CreateChannel(int* channel_id,
+                    const Config* config);
 
   // Creates a new channel grouped with |original_channel|. The new channel
   // will get its own |ViEEncoder| if |sender| is set to true. It will be a
@@ -131,7 +132,7 @@
 
   VoiceEngine* voice_engine_;
   ProcessThread* module_process_thread_;
-  const Config& config_;
+  const Config& engine_config_;
 };
 
 class ViEChannelManagerScoped: private ViEManagerScopedBase {