Call ChannelManager aec dump methods on the worker thread.

Before, the calls went through the signaling thread and
blocked while the operation completed on the worker.

Bug: webrtc:12601
Change-Id: I58991fa98a55d0fa9304a68bd85bb269f1f123d2
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/212619
Commit-Queue: Tommi <tommi@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33615}
diff --git a/api/peer_connection_factory_proxy.h b/api/peer_connection_factory_proxy.h
index 9056495..0eb2b39 100644
--- a/api/peer_connection_factory_proxy.h
+++ b/api/peer_connection_factory_proxy.h
@@ -22,7 +22,7 @@
 
 // TODO(deadbeef): Move this to .cc file and out of api/. What threads methods
 // are called on is an implementation detail.
-BEGIN_PRIMARY_PROXY_MAP(PeerConnectionFactory)
+BEGIN_PROXY_MAP(PeerConnectionFactory)
 PROXY_PRIMARY_THREAD_DESTRUCTOR()
 PROXY_METHOD1(void, SetOptions, const Options&)
 PROXY_METHOD4(rtc::scoped_refptr<PeerConnectionInterface>,
@@ -59,8 +59,8 @@
               CreateAudioTrack,
               const std::string&,
               AudioSourceInterface*)
-PROXY_METHOD2(bool, StartAecDump, FILE*, int64_t)
-PROXY_METHOD0(void, StopAecDump)
+PROXY_SECONDARY_METHOD2(bool, StartAecDump, FILE*, int64_t)
+PROXY_SECONDARY_METHOD0(void, StopAecDump)
 END_PROXY_MAP()
 
 }  // namespace webrtc
diff --git a/pc/channel_manager.cc b/pc/channel_manager.cc
index 75e728a..3fc0cd1 100644
--- a/pc/channel_manager.cc
+++ b/pc/channel_manager.cc
@@ -360,14 +360,13 @@
 
 bool ChannelManager::StartAecDump(webrtc::FileWrapper file,
                                   int64_t max_size_bytes) {
-  return worker_thread_->Invoke<bool>(RTC_FROM_HERE, [&] {
-    return media_engine_->voice().StartAecDump(std::move(file), max_size_bytes);
-  });
+  RTC_DCHECK_RUN_ON(worker_thread_);
+  return media_engine_->voice().StartAecDump(std::move(file), max_size_bytes);
 }
 
 void ChannelManager::StopAecDump() {
-  worker_thread_->Invoke<void>(RTC_FROM_HERE,
-                               [&] { media_engine_->voice().StopAecDump(); });
+  RTC_DCHECK_RUN_ON(worker_thread_);
+  media_engine_->voice().StopAecDump();
 }
 
 }  // namespace cricket
diff --git a/pc/peer_connection_factory.cc b/pc/peer_connection_factory.cc
index ee5c74f..c911871 100644
--- a/pc/peer_connection_factory.cc
+++ b/pc/peer_connection_factory.cc
@@ -73,8 +73,8 @@
   // Verify that the invocation and the initialization ended up agreeing on the
   // thread.
   RTC_DCHECK_RUN_ON(pc_factory->signaling_thread());
-  return PeerConnectionFactoryProxy::Create(pc_factory->signaling_thread(),
-                                            pc_factory);
+  return PeerConnectionFactoryProxy::Create(
+      pc_factory->signaling_thread(), pc_factory->worker_thread(), pc_factory);
 }
 
 // Static
@@ -176,12 +176,12 @@
 }
 
 bool PeerConnectionFactory::StartAecDump(FILE* file, int64_t max_size_bytes) {
-  RTC_DCHECK(signaling_thread()->IsCurrent());
+  RTC_DCHECK_RUN_ON(worker_thread());
   return channel_manager()->StartAecDump(FileWrapper(file), max_size_bytes);
 }
 
 void PeerConnectionFactory::StopAecDump() {
-  RTC_DCHECK(signaling_thread()->IsCurrent());
+  RTC_DCHECK_RUN_ON(worker_thread());
   channel_manager()->StopAecDump();
 }
 
diff --git a/pc/peer_connection_factory.h b/pc/peer_connection_factory.h
index cbc7397..71d7830 100644
--- a/pc/peer_connection_factory.h
+++ b/pc/peer_connection_factory.h
@@ -117,6 +117,8 @@
     return context_->signaling_thread();
   }
 
+  rtc::Thread* worker_thread() const { return context_->worker_thread(); }
+
   const Options& options() const {
     RTC_DCHECK_RUN_ON(signaling_thread());
     return options_;
@@ -137,7 +139,6 @@
   virtual ~PeerConnectionFactory();
 
  private:
-  rtc::Thread* worker_thread() const { return context_->worker_thread(); }
   rtc::Thread* network_thread() const { return context_->network_thread(); }
 
   bool IsTrialEnabled(absl::string_view key) const;