AudioProcessingModule has a feature to make a recording of its
configuration, inputs and outputs over a period of time. It is
activated by AudioProcessing::StartRecording. The data is stored in
binary protobuf format in a specified file. The file IO is, as of
this CL, done from the real-time audio thread.

This CL contains an interface for AecDump, a new APM submodule that
will handle the recordings. Calls to the new interface from the
AudioProcessingModule are added. These calls have no effect, and for a
short while, audio_processing_impl.cc will contain two copies of
recording calls.

The original calls are guarded by the WEBRTC_AUDIOPROC_DEBUG_DUMP
preprocessor define. They still have an effect, while the new ones do
not. In the following CLs, the old recording calls will be removed,
and an implementation of AecDump added.

The reasons for the refactoring is to move file IO operations from the
real-time audio thread, to add a top-level low-priority task queue for
logging tasks like this, to simplify and modularize audio_processing_impl.cc
and remove some of the preprocessor directives. These goals will be
archived by the upcoming CLs. The implementation is in
https://codereview.webrtc.org/2865113002.

BUG=webrtc:7404

Review-Url: https://codereview.webrtc.org/2778783002
Cr-Commit-Position: refs/heads/master@{#18233}
diff --git a/webrtc/modules/audio_processing/audio_processing_impl.h b/webrtc/modules/audio_processing/audio_processing_impl.h
index 0985257..b4128a9 100644
--- a/webrtc/modules/audio_processing/audio_processing_impl.h
+++ b/webrtc/modules/audio_processing/audio_processing_impl.h
@@ -23,6 +23,7 @@
 #include "webrtc/base/swap_queue.h"
 #include "webrtc/base/thread_annotations.h"
 #include "webrtc/modules/audio_processing/audio_buffer.h"
+#include "webrtc/modules/audio_processing/include/aec_dump.h"
 #include "webrtc/modules/audio_processing/include/audio_processing.h"
 #include "webrtc/modules/audio_processing/render_queue_item_verifier.h"
 #include "webrtc/modules/audio_processing/rms_level.h"
@@ -64,6 +65,8 @@
   void ApplyConfig(const AudioProcessing::Config& config) override;
   void SetExtraOptions(const webrtc::Config& config) override;
   void UpdateHistogramsOnCallEnd() override;
+  void AttachAecDump(std::unique_ptr<AecDump> aec_dump) override;
+  void DetachAecDump() override;
   int StartDebugRecording(const char filename[kMaxFilenameSize],
                           int64_t max_log_size_bytes) override;
   int StartDebugRecording(FILE* handle, int64_t max_log_size_bytes) override;
@@ -279,6 +282,34 @@
       EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
   int ProcessRenderStreamLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
 
+  // Collects configuration settings from public and private
+  // submodules to be saved as an audioproc::Config message on the
+  // AecDump if it is attached.  If not |forced|, only writes the current
+  // config if it is different from the last saved one; if |forced|,
+  // writes the config regardless of the last saved.
+  void WriteAecDumpConfigMessage(bool forced)
+      EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
+
+  // Notifies attached AecDump of current configuration and capture data.
+  void RecordUnprocessedCaptureStream(const float* const* capture_stream)
+      EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
+
+  void RecordUnprocessedCaptureStream(const AudioFrame& capture_frame)
+      EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
+
+  // Notifies attached AecDump of current configuration and
+  // processed capture data and issues a capture stream recording
+  // request.
+  void RecordProcessedCaptureStream(
+      const float* const* processed_capture_stream)
+      EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
+
+  void RecordProcessedCaptureStream(const AudioFrame& processed_capture_frame)
+      EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
+
+  // Notifies attached AecDump about current state (delay, drift, etc).
+  void RecordAudioProcessingState() EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);
+
 // Debug dump methods that are internal and called without locks.
 // TODO(peah): Make thread safe.
 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
@@ -303,6 +334,14 @@
   ApmDebugDumpState debug_dump_;
 #endif
 
+  // AecDump instance used for optionally logging APM config, input
+  // and output to file in the AEC-dump format defined in debug.proto.
+  std::unique_ptr<AecDump> aec_dump_;
+
+  // Hold the last config written with AecDump for avoiding writing
+  // the same config twice.
+  InternalAPMConfig apm_config_for_aec_dump_ GUARDED_BY(crit_capture_);
+
   // Critical sections.
   rtc::CriticalSection crit_render_ ACQUIRED_BEFORE(crit_capture_);
   rtc::CriticalSection crit_capture_;