Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: webrtc/modules/audio_processing/aec_dump/aec_dump_impl.cc

Issue 2865113002: AecDump implementation. (Closed)
Patch Set: Rebase on small fixes. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include <utility>
12
13 #include "webrtc/modules/audio_processing/aec_dump/aec_dump_impl.h"
14
15 #include "webrtc/base/checks.h"
16 #include "webrtc/base/event.h"
17 #include "webrtc/base/ptr_util.h"
18 #include "webrtc/modules/audio_processing/aec_dump/aec_dump_factory.h"
19
20 namespace webrtc {
21
22 AecDumpImpl::AecDumpImpl(int64_t max_log_size_bytes,
23 rtc::TaskQueue* worker_queue)
24 : debug_file_(FileWrapper::Create()),
25 num_bytes_left_for_log_(max_log_size_bytes),
26 worker_queue_(worker_queue),
27 capture_stream_info_(CreateWriteToFileTask()) {}
28
29 AecDumpImpl::AecDumpImpl(rtc::PlatformFile file,
30 int64_t max_log_size_bytes,
31 rtc::TaskQueue* worker_queue)
32 : AecDumpImpl(max_log_size_bytes, worker_queue) {
33 FILE* handle = rtc::FdopenPlatformFileForWriting(file);
34 RTC_DCHECK(handle);
35 debug_file_->OpenFromFileHandle(handle);
36 }
37
38 AecDumpImpl::AecDumpImpl(std::string file_name,
39 int64_t max_log_size_bytes,
40 rtc::TaskQueue* worker_queue)
41 : AecDumpImpl(max_log_size_bytes, worker_queue) {
42 RTC_DCHECK(debug_file_);
43 debug_file_->OpenFile(file_name.c_str(), false);
44 }
45
46 AecDumpImpl::AecDumpImpl(FILE* handle,
47 int64_t max_log_size_bytes,
48 rtc::TaskQueue* worker_queue)
49 : AecDumpImpl(max_log_size_bytes, worker_queue) {
50 RTC_DCHECK(debug_file_);
51 debug_file_->OpenFromFileHandle(handle);
52 }
53
54 AecDumpImpl::~AecDumpImpl() {
55 // Block until all tasks have finished running.
56 rtc::Event thread_sync_event(false /* manual_reset */, false);
57 worker_queue_->PostTask([&thread_sync_event] { thread_sync_event.Set(); });
58 // Wait until the event has been signaled with .Set(). By then all
59 // pending tasks will have finished.
60 thread_sync_event.Wait(rtc::Event::kForever);
61 }
62
63 void AecDumpImpl::AddCaptureStreamInput(const FloatAudioFrame& src) {
peah-webrtc 2017/05/16 06:30:37 You could probably put these (63-79) in the header
aleloi 2017/05/16 20:10:16 The chromium-style plugin disagrees: virtual metho
64 capture_stream_info_.AddInput(src);
65 }
66
67 void AecDumpImpl::AddCaptureStreamOutput(const FloatAudioFrame& src) {
68 capture_stream_info_.AddOutput(src);
69 }
70
71 void AecDumpImpl::AddCaptureStreamInput(const AudioFrame& frame) {
72 capture_stream_info_.AddInput(frame);
73 }
74
75 void AecDumpImpl::AddCaptureStreamOutput(const AudioFrame& frame) {
76 capture_stream_info_.AddOutput(frame);
77 }
78
79 void AecDumpImpl::AddAudioProcessingState(const AudioProcessingState& state) {
80 capture_stream_info_.AddAudioProcessingState(state);
81 }
82
83 void AecDumpImpl::WriteInitMessage(
84 const InternalAPMStreamsConfig& streams_config) {
85 auto task = CreateWriteToFileTask();
86 auto* event = task->GetEvent();
87 event->set_type(audioproc::Event::INIT);
88 audioproc::Init* msg = event->mutable_init();
89
90 msg->set_sample_rate(streams_config.input_sample_rate);
91 msg->set_output_sample_rate(streams_config.output_sample_rate);
92 msg->set_reverse_sample_rate(streams_config.render_input_sample_rate);
93 msg->set_reverse_output_sample_rate(streams_config.render_output_sample_rate);
94
95 msg->set_num_input_channels(
96 static_cast<int32_t>(streams_config.input_num_channels));
97 msg->set_num_output_channels(
98 static_cast<int32_t>(streams_config.output_num_channels));
99 msg->set_num_reverse_channels(
100 static_cast<int32_t>(streams_config.render_input_num_channels));
101 msg->set_num_reverse_output_channels(
102 streams_config.render_output_num_channels);
103
104 worker_queue_->PostTask(std::unique_ptr<rtc::QueuedTask>(std::move(task)));
105 }
106
107 void AecDumpImpl::WriteRenderStreamMessage(const AudioFrame& frame) {
108 auto task = CreateWriteToFileTask();
109 auto* event = task->GetEvent();
110
111 event->set_type(audioproc::Event::REVERSE_STREAM);
112 audioproc::ReverseStream* msg = event->mutable_reverse_stream();
113 const size_t data_size =
114 sizeof(int16_t) * frame.samples_per_channel_ * frame.num_channels_;
115 msg->set_data(frame.data_, data_size);
116
117 worker_queue_->PostTask(std::unique_ptr<rtc::QueuedTask>(std::move(task)));
118 }
119
120 void AecDumpImpl::WriteRenderStreamMessage(const FloatAudioFrame& src) {
121 auto task = CreateWriteToFileTask();
122 auto* event = task->GetEvent();
123
124 // auto event = std::unique_ptr<audioproc::Event>(new audioproc::Event());
peah-webrtc 2017/05/16 06:30:37 Is line 124 intended to be commented out? I guess
aleloi 2017/05/16 20:10:16 Done.
125 event->set_type(audioproc::Event::REVERSE_STREAM);
126
127 audioproc::ReverseStream* msg = event->mutable_reverse_stream();
128
129 for (size_t i = 0; i < src.num_channels(); ++i) {
130 const auto& channel_view = src.channel(i);
131 msg->add_channel(channel_view.begin(), sizeof(float) * channel_view.size());
132 }
133
134 worker_queue_->PostTask(std::unique_ptr<rtc::QueuedTask>(std::move(task)));
135 }
136
137 void AecDumpImpl::WriteCaptureStreamMessage() {
138 auto task = capture_stream_info_.GetTask();
139 RTC_DCHECK(task);
140 worker_queue_->PostTask(std::unique_ptr<rtc::QueuedTask>(std::move(task)));
141 capture_stream_info_.SetTask(CreateWriteToFileTask());
142 }
143
144 void CopyFromConfigToEvent(const webrtc::InternalAPMConfig& config,
peah-webrtc 2017/05/16 06:30:37 Can this method be put in the anonymous namespace?
aleloi 2017/05/16 20:10:16 Done.
145 webrtc::audioproc::Config* pb_cfg) {
146 pb_cfg->set_aec_enabled(config.aec_enabled);
147 pb_cfg->set_aec_delay_agnostic_enabled(config.aec_delay_agnostic_enabled);
148 pb_cfg->set_aec_drift_compensation_enabled(
149 config.aec_drift_compensation_enabled);
150 pb_cfg->set_aec_extended_filter_enabled(config.aec_extended_filter_enabled);
151 pb_cfg->set_aec_suppression_level(config.aec_suppression_level);
152
153 pb_cfg->set_aecm_enabled(config.aecm_enabled);
154 pb_cfg->set_aecm_comfort_noise_enabled(config.aecm_comfort_noise_enabled);
155 pb_cfg->set_aecm_routing_mode(config.aecm_routing_mode);
156
157 pb_cfg->set_agc_enabled(config.agc_enabled);
158 pb_cfg->set_agc_mode(config.agc_mode);
159 pb_cfg->set_agc_limiter_enabled(config.agc_limiter_enabled);
160 pb_cfg->set_noise_robust_agc_enabled(config.noise_robust_agc_enabled);
161
162 pb_cfg->set_hpf_enabled(config.hpf_enabled);
163
164 pb_cfg->set_ns_enabled(config.ns_enabled);
165 pb_cfg->set_ns_level(config.ns_level);
166
167 pb_cfg->set_transient_suppression_enabled(
168 config.transient_suppression_enabled);
169 pb_cfg->set_intelligibility_enhancer_enabled(
170 config.intelligibility_enhancer_enabled);
171
172 pb_cfg->set_experiments_description(config.experiments_description);
173 }
174
175 void AecDumpImpl::WriteConfig(const InternalAPMConfig& config, bool forced) {
176 auto task = CreateWriteToFileTask();
177 auto* event = task->GetEvent();
178 event->set_type(audioproc::Event::CONFIG);
179 CopyFromConfigToEvent(config, event->mutable_config());
180
181 ProtoString serialized_config = event->mutable_config()->SerializeAsString();
182 {
183 rtc::CritScope cs(&config_string_lock_);
peah-webrtc 2017/05/16 06:30:38 I don't see that locking is needed for the config_
aleloi 2017/05/16 20:10:16 There was something detected by the tsan bots that
184 if (!forced && serialized_config == last_serialized_capture_config_) {
185 return;
186 }
187 last_serialized_capture_config_ = serialized_config;
188 }
189
190 worker_queue_->PostTask(std::unique_ptr<rtc::QueuedTask>(std::move(task)));
191 }
192
193 std::unique_ptr<WriteToFileTask> AecDumpImpl::CreateWriteToFileTask() {
194 return rtc::MakeUnique<WriteToFileTask>(debug_file_.get(),
195 &num_bytes_left_for_log_);
196 }
197
198 std::unique_ptr<AecDump> AecDumpFactory::Create(rtc::PlatformFile file,
199 int64_t max_log_size_bytes,
200 rtc::TaskQueue* worker_queue) {
201 return std::unique_ptr<AecDumpImpl>(
202 new AecDumpImpl(file, max_log_size_bytes, worker_queue));
203 }
204
205 std::unique_ptr<AecDump> AecDumpFactory::Create(std::string file_name,
206 int64_t max_log_size_bytes,
207 rtc::TaskQueue* worker_queue) {
208 return std::unique_ptr<AecDumpImpl>(
209 new AecDumpImpl(file_name, max_log_size_bytes, worker_queue));
210 }
211
212 std::unique_ptr<AecDump> AecDumpFactory::Create(FILE* handle,
213 int64_t max_log_size_bytes,
214 rtc::TaskQueue* worker_queue) {
215 return std::unique_ptr<AecDumpImpl>(
216 new AecDumpImpl(handle, max_log_size_bytes, worker_queue));
217 }
218 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698