 Chromium Code Reviews
 Chromium Code Reviews Issue 2865113002:
  AecDump implementation.  (Closed)
    
  
    Issue 2865113002:
  AecDump implementation.  (Closed) 
  | OLD | NEW | 
|---|---|
| 1 /* | 1 /* | 
| 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 
| 3 * | 3 * | 
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license | 
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source | 
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found | 
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may | 
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. | 
| 9 */ | 9 */ | 
| 10 | 10 | 
| 11 #include "webrtc/modules/audio_processing/aec_dump/aec_dump.h" | 11 #include "webrtc/modules/audio_processing/aec_dump/aec_dump.h" | 
| 12 | 12 | 
| 13 #include "webrtc/base/checks.h" | |
| 14 #include "webrtc/base/event.h" | |
| 15 #include "webrtc/base/ignore_wundef.h" | |
| 16 #include "webrtc/base/protobuf_utils.h" | |
| 17 #include "webrtc/modules/audio_processing/aec_dump/write_to_file_task.h" | |
| 18 | |
| 19 // Files generated at build-time by the protobuf compiler. | |
| 20 RTC_PUSH_IGNORING_WUNDEF() | |
| 21 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD | |
| 22 #include "external/webrtc/webrtc/modules/audio_processing/debug.pb.h" | |
| 23 #else | |
| 24 #include "webrtc/modules/audio_processing/debug.pb.h" | |
| 25 #endif | |
| 26 RTC_POP_IGNORING_WUNDEF() | |
| 27 | |
| 13 namespace webrtc { | 28 namespace webrtc { | 
| 14 | 29 | 
| 15 InternalAPMConfig::InternalAPMConfig() = default; | 30 InternalAPMConfig::InternalAPMConfig() = default; | 
| 16 InternalAPMConfig::InternalAPMConfig(const InternalAPMConfig&) = default; | 31 InternalAPMConfig::InternalAPMConfig(const InternalAPMConfig&) = default; | 
| 17 InternalAPMConfig::InternalAPMConfig(InternalAPMConfig&&) = default; | 32 InternalAPMConfig::InternalAPMConfig(InternalAPMConfig&&) = default; | 
| 18 | 33 | 
| 19 AecDump::AecDump(int64_t max_log_size_bytes, rtc::TaskQueue* worker_queue) {} | 34 AecDump::AecDump(int64_t max_log_size_bytes, rtc::TaskQueue* worker_queue) | 
| 35 : debug_file_(FileWrapper::Create()), | |
| 36 num_bytes_left_for_log_(max_log_size_bytes), | |
| 37 worker_queue_(worker_queue) {} | |
| 20 | 38 | 
| 21 AecDump::AecDump(rtc::PlatformFile file, | 39 AecDump::AecDump(rtc::PlatformFile file, | 
| 22 int64_t max_log_size_bytes, | 40 int64_t max_log_size_bytes, | 
| 23 rtc::TaskQueue* worker_queue) {} | 41 rtc::TaskQueue* worker_queue) | 
| 42 : AecDump(max_log_size_bytes, worker_queue) { | |
| 43 FILE* handle = rtc::FdopenPlatformFileForWriting(file); | |
| 44 RTC_DCHECK(handle); | |
| 45 debug_file_->OpenFromFileHandle(handle); | |
| 46 } | |
| 24 | 47 | 
| 25 AecDump::AecDump(std::string file_name, | 48 AecDump::AecDump(std::string file_name, | 
| 26 int64_t max_log_size_bytes, | 49 int64_t max_log_size_bytes, | 
| 27 rtc::TaskQueue* worker_queue) {} | 50 rtc::TaskQueue* worker_queue) | 
| 51 : AecDump(max_log_size_bytes, worker_queue) { | |
| 52 RTC_DCHECK(debug_file_); | |
| 53 debug_file_->OpenFile(file_name.c_str(), false); | |
| 54 } | |
| 28 | 55 | 
| 29 AecDump::AecDump(FILE* handle, | 56 AecDump::AecDump(FILE* handle, | 
| 30 int64_t max_log_size_bytes, | 57 int64_t max_log_size_bytes, | 
| 31 rtc::TaskQueue* worker_queue) {} | 58 rtc::TaskQueue* worker_queue) | 
| 59 : AecDump(max_log_size_bytes, worker_queue) { | |
| 60 RTC_DCHECK(debug_file_); | |
| 61 debug_file_->OpenFromFileHandle(handle); | |
| 62 } | |
| 32 | 63 | 
| 33 AecDump::~AecDump() {} | 64 AecDump::~AecDump() { | 
| 34 | 65 // Block until all tasks have finished running. | 
| 35 AecDump::CaptureStreamInfo::CaptureStreamInfo() = default; | 66 rtc::Event thread_sync_event(false /* manual_reset */, false); | 
| 36 AecDump::CaptureStreamInfo::~CaptureStreamInfo() = default; | 67 worker_queue_->PostTask([&thread_sync_event] { thread_sync_event.Set(); }); | 
| 37 | 68 thread_sync_event.Wait(rtc::Event::kForever); | 
| 
peah-webrtc
2017/05/09 07:14:57
What does this do? Can this wait forever in the de
 
aleloi
2017/05/12 13:07:56
It pauses execution until 'thread_sync_event.Set()
 | |
| 38 void AecDump::CaptureStreamInfo::AddInput(FloatAudioFrame src) {} | 69 } | 
| 39 void AecDump::CaptureStreamInfo::AddOutput(FloatAudioFrame src) {} | |
| 40 | |
| 41 void AecDump::CaptureStreamInfo::AddInput(const AudioFrame& frame) {} | |
| 42 void AecDump::CaptureStreamInfo::AddOutput(const AudioFrame& frame) {} | |
| 43 | |
| 44 void AecDump::CaptureStreamInfo::set_delay(int delay) {} | |
| 45 void AecDump::CaptureStreamInfo::set_drift(int drift) {} | |
| 46 void AecDump::CaptureStreamInfo::set_level(int level) {} | |
| 47 void AecDump::CaptureStreamInfo::set_keypress(bool keypress) {} | |
| 48 | |
| 49 std::unique_ptr<audioproc::Event> GetEventMsg(); | |
| 50 | 70 | 
| 51 void AecDump::WriteInitMessage(const InternalAPMStreamsConfig& streams_config) { | 71 void AecDump::WriteInitMessage(const InternalAPMStreamsConfig& streams_config) { | 
| 72 auto event = std::unique_ptr<audioproc::Event>(new audioproc::Event()); | |
| 73 event->set_type(audioproc::Event::INIT); | |
| 74 audioproc::Init* msg = event->mutable_init(); | |
| 75 | |
| 76 msg->set_sample_rate(streams_config.input_sample_rate); | |
| 77 msg->set_output_sample_rate(streams_config.output_sample_rate); | |
| 78 msg->set_reverse_sample_rate(streams_config.render_input_sample_rate); | |
| 79 msg->set_reverse_output_sample_rate(streams_config.render_output_sample_rate); | |
| 80 | |
| 81 msg->set_num_input_channels( | |
| 82 static_cast<int32_t>(streams_config.input_num_channels)); | |
| 83 msg->set_num_output_channels( | |
| 84 static_cast<int32_t>(streams_config.output_num_channels)); | |
| 85 msg->set_num_reverse_channels( | |
| 86 static_cast<int32_t>(streams_config.render_input_num_channels)); | |
| 87 msg->set_num_reverse_output_channels( | |
| 88 streams_config.render_output_num_channels); | |
| 89 | |
| 90 PostTask(std::move(event)); | |
| 52 } | 91 } | 
| 53 | 92 | 
| 54 void AecDump::WriteRenderStreamMessage(const AudioFrame& frame) {} | 93 void AecDump::WriteRenderStreamMessage(const AudioFrame& frame) { | 
| 94 auto event = std::unique_ptr<audioproc::Event>(new audioproc::Event()); | |
| 55 | 95 | 
| 56 void AecDump::WriteRenderStreamMessage(FloatAudioFrame src) {} | 96 event->set_type(audioproc::Event::REVERSE_STREAM); | 
| 97 audioproc::ReverseStream* msg = event->mutable_reverse_stream(); | |
| 98 const size_t data_size = | |
| 99 sizeof(int16_t) * frame.samples_per_channel_ * frame.num_channels_; | |
| 100 msg->set_data(frame.data_, data_size); | |
| 101 | |
| 102 PostTask(std::move(event)); | |
| 103 } | |
| 104 | |
| 105 void AecDump::WriteRenderStreamMessage(FloatAudioFrame src) { | |
| 
peah-webrtc
2017/05/09 07:14:57
Instead of passing a FloatAudioFrame as
aec_dump_-
 
aleloi
2017/05/12 13:07:56
I have a mild preference for leaving FloatAudioFra
 | |
| 106 auto event = std::unique_ptr<audioproc::Event>(new audioproc::Event()); | |
| 107 event->set_type(audioproc::Event::REVERSE_STREAM); | |
| 108 | |
| 109 audioproc::ReverseStream* msg = event->mutable_reverse_stream(); | |
| 110 | |
| 111 for (size_t i = 0; i < src.num_channels(); ++i) { | |
| 112 const auto& channel_view = src.channel(i); | |
| 113 msg->add_channel(channel_view.begin(), sizeof(float) * channel_view.size()); | |
| 114 } | |
| 115 | |
| 116 PostTask(std::move(event)); | |
| 117 } | |
| 57 | 118 | 
| 58 void AecDump::WriteCaptureStreamMessage( | 119 void AecDump::WriteCaptureStreamMessage( | 
| 59 CaptureStreamInfo* capture_stream_info) {} | 120 CaptureStreamInfo* capture_stream_info) { | 
| 121 auto event_ptr = capture_stream_info->GetEventMsg(); | |
| 122 if (event_ptr) { | |
| 123 PostTask(std::move(event_ptr)); | |
| 124 } | |
| 125 } | |
| 60 | 126 | 
| 61 void AecDump::WriteConfig(const InternalAPMConfig& config, bool forced) {} | 127 void CopyFromConfigToEvent(const webrtc::InternalAPMConfig& config, | 
| 128 webrtc::audioproc::Config* pb_cfg) { | |
| 129 pb_cfg->set_aec_enabled(config.aec_enabled); | |
| 130 pb_cfg->set_aec_delay_agnostic_enabled(config.aec_delay_agnostic_enabled); | |
| 131 pb_cfg->set_aec_drift_compensation_enabled( | |
| 132 config.aec_drift_compensation_enabled); | |
| 133 pb_cfg->set_aec_extended_filter_enabled(config.aec_extended_filter_enabled); | |
| 134 pb_cfg->set_aec_suppression_level(config.aec_suppression_level); | |
| 62 | 135 | 
| 63 void AecDump::PostTask(std::unique_ptr<audioproc::Event> event) {} | 136 pb_cfg->set_aecm_enabled(config.aecm_enabled); | 
| 137 pb_cfg->set_aecm_comfort_noise_enabled(config.aecm_comfort_noise_enabled); | |
| 138 pb_cfg->set_aecm_routing_mode(config.aecm_routing_mode); | |
| 139 | |
| 140 pb_cfg->set_agc_enabled(config.agc_enabled); | |
| 141 pb_cfg->set_agc_mode(config.agc_mode); | |
| 142 pb_cfg->set_agc_limiter_enabled(config.agc_limiter_enabled); | |
| 143 pb_cfg->set_noise_robust_agc_enabled(config.noise_robust_agc_enabled); | |
| 144 | |
| 145 pb_cfg->set_hpf_enabled(config.hpf_enabled); | |
| 146 | |
| 147 pb_cfg->set_ns_enabled(config.ns_enabled); | |
| 148 pb_cfg->set_ns_level(config.ns_level); | |
| 149 | |
| 150 pb_cfg->set_transient_suppression_enabled( | |
| 151 config.transient_suppression_enabled); | |
| 152 pb_cfg->set_intelligibility_enhancer_enabled( | |
| 153 config.intelligibility_enhancer_enabled); | |
| 154 | |
| 155 pb_cfg->set_experiments_description(config.experiments_description); | |
| 156 } | |
| 157 | |
| 158 void AecDump::WriteConfig(const InternalAPMConfig& config, bool forced) { | |
| 159 auto event = std::unique_ptr<audioproc::Event>(new audioproc::Event()); | |
| 
peah-webrtc
2017/05/09 07:14:57
I'd prefer to make this part of the WriteToFileTas
 
aleloi
2017/05/12 13:07:56
That makes everything a little simpler. I like it!
 | |
| 160 event->set_type(audioproc::Event::CONFIG); | |
| 161 CopyFromConfigToEvent(config, event->mutable_config()); | |
| 162 | |
| 163 ProtoString serialized_config = event->mutable_config()->SerializeAsString(); | |
| 164 { | |
| 165 rtc::CritScope cs(&config_string_lock_); | |
| 166 if (!forced && serialized_config == last_serialized_capture_config_) { | |
| 167 return; | |
| 168 } | |
| 169 last_serialized_capture_config_ = serialized_config; | |
| 170 } | |
| 171 | |
| 172 PostTask(std::move(event)); | |
| 173 } | |
| 174 | |
| 175 void AecDump::PostTask(std::unique_ptr<audioproc::Event> event) { | |
| 176 RTC_DCHECK(event); | |
| 177 worker_queue_->PostTask(std::unique_ptr<rtc::QueuedTask>(new WriteToFileTask( | |
| 178 debug_file_.get(), std::move(event), &num_bytes_left_for_log_))); | |
| 179 } | |
| 64 } // namespace webrtc | 180 } // namespace webrtc | 
| OLD | NEW |