OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 |
(...skipping 24 matching lines...) Expand all Loading... | |
35 #include "webrtc/modules/audio_processing/noise_suppression_impl.h" | 35 #include "webrtc/modules/audio_processing/noise_suppression_impl.h" |
36 #include "webrtc/modules/audio_processing/processing_component.h" | 36 #include "webrtc/modules/audio_processing/processing_component.h" |
37 #include "webrtc/modules/audio_processing/transient/transient_suppressor.h" | 37 #include "webrtc/modules/audio_processing/transient/transient_suppressor.h" |
38 #include "webrtc/modules/audio_processing/voice_detection_impl.h" | 38 #include "webrtc/modules/audio_processing/voice_detection_impl.h" |
39 #include "webrtc/modules/interface/module_common_types.h" | 39 #include "webrtc/modules/interface/module_common_types.h" |
40 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" | 40 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" |
41 #include "webrtc/system_wrappers/interface/file_wrapper.h" | 41 #include "webrtc/system_wrappers/interface/file_wrapper.h" |
42 #include "webrtc/system_wrappers/interface/logging.h" | 42 #include "webrtc/system_wrappers/interface/logging.h" |
43 #include "webrtc/system_wrappers/interface/metrics.h" | 43 #include "webrtc/system_wrappers/interface/metrics.h" |
44 | 44 |
45 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | |
46 // Files generated at build-time by the protobuf compiler. | |
47 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD | |
48 #include "external/webrtc/webrtc/modules/audio_processing/debug.pb.h" | |
49 #else | |
50 #include "webrtc/audio_processing/debug.pb.h" | |
51 #endif | |
52 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP | |
53 | |
54 #define RETURN_ON_ERR(expr) \ | 45 #define RETURN_ON_ERR(expr) \ |
55 do { \ | 46 do { \ |
56 int err = (expr); \ | 47 int err = (expr); \ |
57 if (err != kNoError) { \ | 48 if (err != kNoError) { \ |
58 return err; \ | 49 return err; \ |
59 } \ | 50 } \ |
60 } while (0) | 51 } while (0) |
61 | 52 |
62 namespace webrtc { | 53 namespace webrtc { |
63 namespace { | 54 namespace { |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
187 echo_control_mobile_(NULL), | 178 echo_control_mobile_(NULL), |
188 gain_control_(NULL), | 179 gain_control_(NULL), |
189 high_pass_filter_(NULL), | 180 high_pass_filter_(NULL), |
190 level_estimator_(NULL), | 181 level_estimator_(NULL), |
191 noise_suppression_(NULL), | 182 noise_suppression_(NULL), |
192 voice_detection_(NULL), | 183 voice_detection_(NULL), |
193 crit_(CriticalSectionWrapper::CreateCriticalSection()), | 184 crit_(CriticalSectionWrapper::CreateCriticalSection()), |
194 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | 185 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
195 debug_file_(FileWrapper::Create()), | 186 debug_file_(FileWrapper::Create()), |
196 event_msg_(new audioproc::Event()), | 187 event_msg_(new audioproc::Event()), |
188 config_(new audioproc::Config()), | |
197 #endif | 189 #endif |
198 api_format_({{{kSampleRate16kHz, 1, false}, | 190 api_format_({{{kSampleRate16kHz, 1, false}, |
199 {kSampleRate16kHz, 1, false}, | 191 {kSampleRate16kHz, 1, false}, |
200 {kSampleRate16kHz, 1, false}, | 192 {kSampleRate16kHz, 1, false}, |
201 {kSampleRate16kHz, 1, false}}}), | 193 {kSampleRate16kHz, 1, false}}}), |
202 fwd_proc_format_(kSampleRate16kHz), | 194 fwd_proc_format_(kSampleRate16kHz), |
203 rev_proc_format_(kSampleRate16kHz, 1), | 195 rev_proc_format_(kSampleRate16kHz, 1), |
204 split_rate_(kSampleRate16kHz), | 196 split_rate_(kSampleRate16kHz), |
205 stream_delay_ms_(0), | 197 stream_delay_ms_(0), |
206 delay_offset_ms_(0), | 198 delay_offset_ms_(0), |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
243 | 235 |
244 noise_suppression_ = new NoiseSuppressionImpl(this, crit_); | 236 noise_suppression_ = new NoiseSuppressionImpl(this, crit_); |
245 component_list_.push_back(noise_suppression_); | 237 component_list_.push_back(noise_suppression_); |
246 | 238 |
247 voice_detection_ = new VoiceDetectionImpl(this, crit_); | 239 voice_detection_ = new VoiceDetectionImpl(this, crit_); |
248 component_list_.push_back(voice_detection_); | 240 component_list_.push_back(voice_detection_); |
249 | 241 |
250 gain_control_for_new_agc_.reset(new GainControlForNewAgc(gain_control_)); | 242 gain_control_for_new_agc_.reset(new GainControlForNewAgc(gain_control_)); |
251 | 243 |
252 SetExtraOptions(config); | 244 SetExtraOptions(config); |
245 | |
246 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | |
247 UpdateCurrentConfig(); | |
248 #endif | |
253 } | 249 } |
254 | 250 |
255 AudioProcessingImpl::~AudioProcessingImpl() { | 251 AudioProcessingImpl::~AudioProcessingImpl() { |
256 { | 252 { |
257 CriticalSectionScoped crit_scoped(crit_); | 253 CriticalSectionScoped crit_scoped(crit_); |
258 // Depends on gain_control_ and gain_control_for_new_agc_. | 254 // Depends on gain_control_ and gain_control_for_new_agc_. |
259 agc_manager_.reset(); | 255 agc_manager_.reset(); |
260 // Depends on gain_control_. | 256 // Depends on gain_control_. |
261 gain_control_for_new_agc_.reset(); | 257 gain_control_for_new_agc_.reset(); |
262 while (!component_list_.empty()) { | 258 while (!component_list_.empty()) { |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
553 | 549 |
554 ProcessingConfig processing_config = api_format_; | 550 ProcessingConfig processing_config = api_format_; |
555 processing_config.input_stream() = input_config; | 551 processing_config.input_stream() = input_config; |
556 processing_config.output_stream() = output_config; | 552 processing_config.output_stream() = output_config; |
557 | 553 |
558 RETURN_ON_ERR(MaybeInitializeLocked(processing_config)); | 554 RETURN_ON_ERR(MaybeInitializeLocked(processing_config)); |
559 assert(processing_config.input_stream().num_frames() == | 555 assert(processing_config.input_stream().num_frames() == |
560 api_format_.input_stream().num_frames()); | 556 api_format_.input_stream().num_frames()); |
561 | 557 |
562 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | 558 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
559 if (debug_file_->Open() && UpdateCurrentConfig()) { | |
560 RETURN_ON_ERR(WriteConfigMessage()); | |
561 } | |
562 | |
563 if (debug_file_->Open()) { | 563 if (debug_file_->Open()) { |
564 event_msg_->set_type(audioproc::Event::STREAM); | 564 event_msg_->set_type(audioproc::Event::STREAM); |
565 audioproc::Stream* msg = event_msg_->mutable_stream(); | 565 audioproc::Stream* msg = event_msg_->mutable_stream(); |
566 const size_t channel_size = | 566 const size_t channel_size = |
567 sizeof(float) * api_format_.input_stream().num_frames(); | 567 sizeof(float) * api_format_.input_stream().num_frames(); |
568 for (int i = 0; i < api_format_.input_stream().num_channels(); ++i) | 568 for (int i = 0; i < api_format_.input_stream().num_channels(); ++i) |
569 msg->add_input_channel(src[i], channel_size); | 569 msg->add_input_channel(src[i], channel_size); |
570 } | 570 } |
571 #endif | 571 #endif |
572 | 572 |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
939 if (debug_file_->CloseFile() == -1) { | 939 if (debug_file_->CloseFile() == -1) { |
940 return kFileError; | 940 return kFileError; |
941 } | 941 } |
942 } | 942 } |
943 | 943 |
944 if (debug_file_->OpenFile(filename, false) == -1) { | 944 if (debug_file_->OpenFile(filename, false) == -1) { |
945 debug_file_->CloseFile(); | 945 debug_file_->CloseFile(); |
946 return kFileError; | 946 return kFileError; |
947 } | 947 } |
948 | 948 |
949 int err = WriteInitMessage(); | 949 UpdateCurrentConfig(); |
950 int err = WriteConfigMessage(); | |
950 if (err != kNoError) { | 951 if (err != kNoError) { |
951 return err; | 952 return err; |
952 } | 953 } |
954 | |
955 err = WriteInitMessage(); | |
956 if (err != kNoError) { | |
957 return err; | |
958 } | |
953 return kNoError; | 959 return kNoError; |
954 #else | 960 #else |
955 return kUnsupportedFunctionError; | 961 return kUnsupportedFunctionError; |
956 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP | 962 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP |
957 } | 963 } |
958 | 964 |
959 int AudioProcessingImpl::StartDebugRecording(FILE* handle) { | 965 int AudioProcessingImpl::StartDebugRecording(FILE* handle) { |
960 CriticalSectionScoped crit_scoped(crit_); | 966 CriticalSectionScoped crit_scoped(crit_); |
961 | 967 |
962 if (handle == NULL) { | 968 if (handle == NULL) { |
963 return kNullPointerError; | 969 return kNullPointerError; |
964 } | 970 } |
965 | 971 |
966 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | 972 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
967 // Stop any ongoing recording. | 973 // Stop any ongoing recording. |
968 if (debug_file_->Open()) { | 974 if (debug_file_->Open()) { |
969 if (debug_file_->CloseFile() == -1) { | 975 if (debug_file_->CloseFile() == -1) { |
970 return kFileError; | 976 return kFileError; |
971 } | 977 } |
972 } | 978 } |
973 | 979 |
974 if (debug_file_->OpenFromFileHandle(handle, true, false) == -1) { | 980 if (debug_file_->OpenFromFileHandle(handle, true, false) == -1) { |
975 return kFileError; | 981 return kFileError; |
976 } | 982 } |
977 | 983 |
978 int err = WriteInitMessage(); | 984 UpdateCurrentConfig(); |
985 int err = WriteConfigMessage(); | |
979 if (err != kNoError) { | 986 if (err != kNoError) { |
980 return err; | 987 return err; |
981 } | 988 } |
989 | |
990 err = WriteInitMessage(); | |
991 if (err != kNoError) { | |
992 return err; | |
993 } | |
982 return kNoError; | 994 return kNoError; |
983 #else | 995 #else |
984 return kUnsupportedFunctionError; | 996 return kUnsupportedFunctionError; |
985 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP | 997 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP |
986 } | 998 } |
987 | 999 |
988 int AudioProcessingImpl::StartDebugRecordingForPlatformFile( | 1000 int AudioProcessingImpl::StartDebugRecordingForPlatformFile( |
989 rtc::PlatformFile handle) { | 1001 rtc::PlatformFile handle) { |
990 FILE* stream = rtc::FdopenPlatformFileForWriting(handle); | 1002 FILE* stream = rtc::FdopenPlatformFileForWriting(handle); |
991 return StartDebugRecording(stream); | 1003 return StartDebugRecording(stream); |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1248 msg->set_output_sample_rate(api_format_.output_stream().sample_rate_hz()); | 1260 msg->set_output_sample_rate(api_format_.output_stream().sample_rate_hz()); |
1249 // TODO(ekmeyerson): Add reverse output fields to event_msg_. | 1261 // TODO(ekmeyerson): Add reverse output fields to event_msg_. |
1250 | 1262 |
1251 int err = WriteMessageToDebugFile(); | 1263 int err = WriteMessageToDebugFile(); |
1252 if (err != kNoError) { | 1264 if (err != kNoError) { |
1253 return err; | 1265 return err; |
1254 } | 1266 } |
1255 | 1267 |
1256 return kNoError; | 1268 return kNoError; |
1257 } | 1269 } |
1270 | |
1271 bool AudioProcessingImpl::UpdateCurrentConfig() { | |
peah-webrtc
2015/10/02 08:34:27
This function became very long (for good reasons)
minyue-webrtc
2015/10/02 09:01:42
also goes away per Andrew's suggestion
| |
1272 bool changed = false; | |
1273 | |
1274 // Acoustic echo canceler. | |
1275 { | |
1276 const bool value = echo_cancellation_->is_enabled(); | |
1277 if (!config_->has_aec_enabled() || value != config_->aec_enabled()) { | |
1278 config_->set_aec_enabled(value); | |
1279 changed = true; | |
1280 } | |
1281 } | |
1282 { | |
1283 const bool value = echo_cancellation_->is_delay_agnostic_enabled(); | |
1284 if (!config_->has_aec_delay_agnostic() || | |
1285 value != config_->aec_delay_agnostic()) { | |
1286 config_->set_aec_delay_agnostic(value); | |
1287 changed = true; | |
1288 } | |
1289 } | |
1290 { | |
1291 const bool value = echo_cancellation_->is_drift_compensation_enabled(); | |
1292 if (!config_->has_aec_drift_compensation() || | |
1293 value != config_->aec_drift_compensation()) { | |
1294 config_->set_aec_drift_compensation(value); | |
1295 changed = true; | |
1296 } | |
1297 } | |
1298 { | |
1299 const bool value = echo_cancellation_->is_extended_filter_enabled(); | |
1300 if (!config_->has_aec_extended_filter() || | |
1301 value != config_->aec_extended_filter()) { | |
1302 config_->set_aec_extended_filter(value); | |
1303 changed = true; | |
1304 } | |
1305 } | |
1306 { | |
1307 const int value = static_cast<int>(echo_cancellation_->suppression_level()); | |
1308 if (!config_->has_aec_suppression_level() || | |
1309 value != config_->aec_suppression_level()) { | |
1310 config_->set_aec_suppression_level(value); | |
1311 changed = true; | |
1312 } | |
1313 } | |
1314 | |
1315 // Mobile AEC. | |
1316 { | |
1317 const bool value = echo_control_mobile_->is_enabled(); | |
1318 if (!config_->has_aecm_enabled() || value != config_->aecm_enabled()) { | |
1319 config_->set_aecm_enabled(value); | |
1320 changed = true; | |
1321 } | |
1322 } | |
1323 { | |
1324 const bool value = echo_control_mobile_->is_comfort_noise_enabled(); | |
1325 if (!config_->has_aecm_comfort_noise() || | |
1326 value != config_->aecm_comfort_noise()) { | |
1327 config_->set_aecm_comfort_noise(value); | |
1328 changed = true; | |
1329 } | |
1330 } | |
1331 { | |
1332 const int value = static_cast<int>(echo_control_mobile_->routing_mode()); | |
1333 if (!config_->has_aecm_routing_mode() || | |
1334 value != config_->aecm_routing_mode()) { | |
1335 config_->set_aecm_routing_mode(value); | |
1336 changed = true; | |
1337 } | |
1338 } | |
1339 | |
1340 // Automatic gain controller. | |
1341 { | |
1342 const bool value = gain_control_->is_enabled(); | |
1343 if (!config_->has_agc_enabled() || value != config_->agc_enabled()) { | |
1344 config_->set_agc_enabled(value); | |
1345 changed = true; | |
1346 } | |
1347 } | |
1348 { | |
1349 const bool value = use_new_agc_; | |
1350 if (!config_->has_agc_experiment() || value != config_->agc_experiment()) { | |
1351 config_->set_agc_experiment(value); | |
1352 changed = true; | |
1353 } | |
1354 } | |
1355 { | |
1356 const int value = static_cast<int>(gain_control_->mode()); | |
1357 if (!config_->has_agc_mode() || value != config_->agc_mode()) { | |
1358 config_->set_agc_mode(value); | |
1359 changed = true; | |
1360 } | |
1361 } | |
1362 { | |
1363 const bool value = gain_control_->is_limiter_enabled(); | |
1364 if (!config_->has_agc_limiter() || value != config_->agc_limiter()) { | |
1365 config_->set_agc_limiter(value); | |
1366 changed = true; | |
1367 } | |
1368 } | |
1369 | |
1370 // High pass filter. | |
1371 { | |
1372 const bool value = high_pass_filter_->is_enabled(); | |
1373 if (!config_->has_hpf_enabled() || value != config_->hpf_enabled()) { | |
1374 config_->set_hpf_enabled(value); | |
1375 changed = true; | |
1376 } | |
1377 } | |
1378 | |
1379 // Noise suppression. | |
1380 { | |
1381 const bool value = noise_suppression_->is_enabled(); | |
1382 if (!config_->has_ns_enabled() || value != config_->ns_enabled()) { | |
1383 config_->set_ns_enabled(value); | |
1384 changed = true; | |
1385 } | |
1386 } | |
1387 { | |
1388 const bool value = transient_suppressor_enabled_; | |
1389 if (!config_->has_ns_experiment() || value != config_->ns_experiment()) { | |
1390 config_->set_ns_experiment(value); | |
1391 changed = true; | |
1392 } | |
1393 } | |
1394 { | |
1395 const int value = static_cast<int>(noise_suppression_->level()); | |
1396 if (!config_->has_ns_level() || value != config_->ns_level()) { | |
1397 config_->set_ns_level(value); | |
1398 changed = true; | |
1399 } | |
1400 } | |
1401 | |
1402 return changed; | |
1403 } | |
1404 | |
1405 int AudioProcessingImpl::WriteConfigMessage() { | |
1406 event_msg_->set_type(audioproc::Event::CONFIG); | |
1407 event_msg_->mutable_config()->CopyFrom(*config_); | |
1408 | |
1409 int err = WriteMessageToDebugFile(); | |
1410 if (err != kNoError) { | |
1411 return err; | |
1412 } | |
1413 | |
1414 return kNoError; | |
1415 } | |
1258 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP | 1416 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP |
1259 | 1417 |
1260 } // namespace webrtc | 1418 } // namespace webrtc |
OLD | NEW |