AEC dump `Stream::level` renamed

Making it clear that the field is used to store the applied input
volume and not the recommended input volume.

Bug: webrtc:7494, b/241923537
Change-Id: Ib91bc1a12348f63e3a4ba6e068ed02e40786a87b
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/271342
Reviewed-by: Jesus de Vicente Pena <devicentepena@webrtc.org>
Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38051}
diff --git a/modules/audio_processing/aec_dump/capture_stream_info.cc b/modules/audio_processing/aec_dump/capture_stream_info.cc
index 7a1ee8b..207fad9 100644
--- a/modules/audio_processing/aec_dump/capture_stream_info.cc
+++ b/modules/audio_processing/aec_dump/capture_stream_info.cc
@@ -53,7 +53,7 @@
   auto* stream = event_->mutable_stream();
   stream->set_delay(state.delay);
   stream->set_drift(state.drift);
-  stream->set_level(state.level);
+  stream->set_applied_input_volume(state.applied_input_volume);
   stream->set_keypress(state.keypress);
 }
 }  // namespace webrtc
diff --git a/modules/audio_processing/audio_processing_impl.cc b/modules/audio_processing/audio_processing_impl.cc
index 5256f9f..453b8d9 100644
--- a/modules/audio_processing/audio_processing_impl.cc
+++ b/modules/audio_processing/audio_processing_impl.cc
@@ -2148,7 +2148,10 @@
   AecDump::AudioProcessingState audio_proc_state;
   audio_proc_state.delay = capture_nonlocked_.stream_delay_ms;
   audio_proc_state.drift = 0;
-  audio_proc_state.level = recommended_stream_analog_level_locked();
+  // TODO(bugs.webrtc.org/7494): Refactor to clarify that `stream_analog_level`
+  // is in fact assigned to the applied volume and not to the recommended one.
+  audio_proc_state.applied_input_volume =
+      recommended_stream_analog_level_locked();
   audio_proc_state.keypress = capture_.key_pressed;
   aec_dump_->AddAudioProcessingState(audio_proc_state);
 }
diff --git a/modules/audio_processing/audio_processing_unittest.cc b/modules/audio_processing/audio_processing_unittest.cc
index a051474..523afe9 100644
--- a/modules/audio_processing/audio_processing_unittest.cc
+++ b/modules/audio_processing/audio_processing_unittest.cc
@@ -357,7 +357,7 @@
   EXPECT_EQ(actual.output_data(), expected.output_data());
   EXPECT_EQ(actual.delay(), expected.delay());
   EXPECT_EQ(actual.drift(), expected.drift());
-  EXPECT_EQ(actual.level(), expected.level());
+  EXPECT_EQ(actual.applied_input_volume(), expected.applied_input_volume());
   EXPECT_EQ(actual.keypress(), expected.keypress());
 }
 
@@ -1518,7 +1518,7 @@
       // ProcessStream could have changed this for the output frame.
       frame_.num_channels = apm_->num_input_channels();
 
-      apm_->set_stream_analog_level(msg.level());
+      apm_->set_stream_analog_level(msg.applied_input_volume());
       EXPECT_NOERR(apm_->set_stream_delay_ms(msg.delay()));
       if (msg.has_keypress()) {
         apm_->set_stream_key_pressed(msg.keypress());
diff --git a/modules/audio_processing/debug.proto b/modules/audio_processing/debug.proto
index 4bc1a52..cc5efbc 100644
--- a/modules/audio_processing/debug.proto
+++ b/modules/audio_processing/debug.proto
@@ -35,7 +35,7 @@
 
   optional int32 delay = 3;
   optional sint32 drift = 4;
-  optional int32 level = 5;
+  optional int32 applied_input_volume = 5;
   optional bool keypress = 6;
 
   // float deinterleaved data, where each repeated element points to a single
diff --git a/modules/audio_processing/include/aec_dump.h b/modules/audio_processing/include/aec_dump.h
index 07477d2..cc31071 100644
--- a/modules/audio_processing/include/aec_dump.h
+++ b/modules/audio_processing/include/aec_dump.h
@@ -67,7 +67,7 @@
   struct AudioProcessingState {
     int delay;
     int drift;
-    int level;
+    int applied_input_volume;
     bool keypress;
   };
 
diff --git a/modules/audio_processing/test/aec_dump_based_simulator.cc b/modules/audio_processing/test/aec_dump_based_simulator.cc
index ec35dd3..261734d 100644
--- a/modules/audio_processing/test/aec_dump_based_simulator.cc
+++ b/modules/audio_processing/test/aec_dump_based_simulator.cc
@@ -174,9 +174,9 @@
     }
   }
 
-  // Level is always logged in AEC dumps.
-  RTC_CHECK(msg.has_level());
-  aec_dump_mic_level_ = msg.level();
+  // The stream analog level is always logged in the AEC dumps.
+  RTC_CHECK(msg.has_applied_input_volume());
+  aec_dump_mic_level_ = msg.applied_input_volume();
 }
 
 void AecDumpBasedSimulator::VerifyProcessStreamBitExactness(
diff --git a/modules/audio_processing/test/debug_dump_replayer.cc b/modules/audio_processing/test/debug_dump_replayer.cc
index 2419313..4155173 100644
--- a/modules/audio_processing/test/debug_dump_replayer.cc
+++ b/modules/audio_processing/test/debug_dump_replayer.cc
@@ -121,7 +121,7 @@
   // APM should have been created.
   RTC_CHECK(apm_.get());
 
-  apm_->set_stream_analog_level(msg.level());
+  apm_->set_stream_analog_level(msg.applied_input_volume());
   RTC_CHECK_EQ(AudioProcessing::kNoError,
                apm_->set_stream_delay_ms(msg.delay()));
 
diff --git a/rtc_tools/unpack_aecdump/unpack.cc b/rtc_tools/unpack_aecdump/unpack.cc
index 642aa5d..a43fe75 100644
--- a/rtc_tools/unpack_aecdump/unpack.cc
+++ b/rtc_tools/unpack_aecdump/unpack.cc
@@ -60,7 +60,7 @@
 ABSL_FLAG(std::string,
           level_file,
           "level.int32",
-          "The name of the level file.");
+          "The name of the applied input volume file.");
 ABSL_FLAG(std::string,
           keypress_file,
           "keypress.bool",
@@ -468,10 +468,10 @@
           }
         }
 
-        if (msg.has_level()) {
+        if (msg.has_applied_input_volume()) {
           static FILE* level_file =
               OpenFile(absl::GetFlag(FLAGS_level_file), "wb");
-          int32_t level = msg.level();
+          int32_t level = msg.applied_input_volume();
           if (absl::GetFlag(FLAGS_text)) {
             fprintf(level_file, "%d\n", level);
           } else {