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 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
232 | 232 |
233 noise_suppression_ = new NoiseSuppressionImpl(this, crit_); | 233 noise_suppression_ = new NoiseSuppressionImpl(this, crit_); |
234 component_list_.push_back(noise_suppression_); | 234 component_list_.push_back(noise_suppression_); |
235 | 235 |
236 voice_detection_ = new VoiceDetectionImpl(this, crit_); | 236 voice_detection_ = new VoiceDetectionImpl(this, crit_); |
237 component_list_.push_back(voice_detection_); | 237 component_list_.push_back(voice_detection_); |
238 | 238 |
239 gain_control_for_new_agc_.reset(new GainControlForNewAgc(gain_control_)); | 239 gain_control_for_new_agc_.reset(new GainControlForNewAgc(gain_control_)); |
240 | 240 |
241 SetExtraOptions(config); | 241 SetExtraOptions(config); |
242 | |
243 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | |
244 config_ = GetCurrentConfig(); | |
245 #endif | |
242 } | 246 } |
243 | 247 |
244 AudioProcessingImpl::~AudioProcessingImpl() { | 248 AudioProcessingImpl::~AudioProcessingImpl() { |
245 { | 249 { |
246 CriticalSectionScoped crit_scoped(crit_); | 250 CriticalSectionScoped crit_scoped(crit_); |
247 // Depends on gain_control_ and gain_control_for_new_agc_. | 251 // Depends on gain_control_ and gain_control_for_new_agc_. |
248 agc_manager_.reset(); | 252 agc_manager_.reset(); |
249 // Depends on gain_control_. | 253 // Depends on gain_control_. |
250 gain_control_for_new_agc_.reset(); | 254 gain_control_for_new_agc_.reset(); |
251 while (!component_list_.empty()) { | 255 while (!component_list_.empty()) { |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
545 ProcessingConfig processing_config = api_format_; | 549 ProcessingConfig processing_config = api_format_; |
546 processing_config.input_stream() = input_config; | 550 processing_config.input_stream() = input_config; |
547 processing_config.output_stream() = output_config; | 551 processing_config.output_stream() = output_config; |
548 | 552 |
549 RETURN_ON_ERR(MaybeInitializeLocked(processing_config)); | 553 RETURN_ON_ERR(MaybeInitializeLocked(processing_config)); |
550 assert(processing_config.input_stream().num_frames() == | 554 assert(processing_config.input_stream().num_frames() == |
551 api_format_.input_stream().num_frames()); | 555 api_format_.input_stream().num_frames()); |
552 | 556 |
553 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | 557 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
554 if (debug_file_->Open()) { | 558 if (debug_file_->Open()) { |
559 ApmConfig current_config = GetCurrentConfig(); | |
560 if (current_config != config_) { | |
561 config_ = current_config; | |
562 RETURN_ON_ERR(WriteConfigMessage()); | |
563 } | |
564 } | |
565 #endif | |
566 | |
567 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | |
568 if (debug_file_->Open()) { | |
555 event_msg_->set_type(audioproc::Event::STREAM); | 569 event_msg_->set_type(audioproc::Event::STREAM); |
556 audioproc::Stream* msg = event_msg_->mutable_stream(); | 570 audioproc::Stream* msg = event_msg_->mutable_stream(); |
557 const size_t channel_size = | 571 const size_t channel_size = |
558 sizeof(float) * api_format_.input_stream().num_frames(); | 572 sizeof(float) * api_format_.input_stream().num_frames(); |
559 for (int i = 0; i < api_format_.input_stream().num_channels(); ++i) | 573 for (int i = 0; i < api_format_.input_stream().num_channels(); ++i) |
560 msg->add_input_channel(src[i], channel_size); | 574 msg->add_input_channel(src[i], channel_size); |
561 } | 575 } |
562 #endif | 576 #endif |
563 | 577 |
564 capture_audio_->CopyFrom(src, api_format_.input_stream()); | 578 capture_audio_->CopyFrom(src, api_format_.input_stream()); |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
930 if (debug_file_->CloseFile() == -1) { | 944 if (debug_file_->CloseFile() == -1) { |
931 return kFileError; | 945 return kFileError; |
932 } | 946 } |
933 } | 947 } |
934 | 948 |
935 if (debug_file_->OpenFile(filename, false) == -1) { | 949 if (debug_file_->OpenFile(filename, false) == -1) { |
936 debug_file_->CloseFile(); | 950 debug_file_->CloseFile(); |
937 return kFileError; | 951 return kFileError; |
938 } | 952 } |
939 | 953 |
940 int err = WriteInitMessage(); | 954 config_ = GetCurrentConfig(); |
955 int err = WriteConfigMessage(); | |
941 if (err != kNoError) { | 956 if (err != kNoError) { |
942 return err; | 957 return err; |
943 } | 958 } |
959 | |
960 err = WriteInitMessage(); | |
961 if (err != kNoError) { | |
962 return err; | |
963 } | |
944 return kNoError; | 964 return kNoError; |
945 #else | 965 #else |
946 return kUnsupportedFunctionError; | 966 return kUnsupportedFunctionError; |
947 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP | 967 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP |
948 } | 968 } |
949 | 969 |
950 int AudioProcessingImpl::StartDebugRecording(FILE* handle) { | 970 int AudioProcessingImpl::StartDebugRecording(FILE* handle) { |
951 CriticalSectionScoped crit_scoped(crit_); | 971 CriticalSectionScoped crit_scoped(crit_); |
952 | 972 |
953 if (handle == NULL) { | 973 if (handle == NULL) { |
954 return kNullPointerError; | 974 return kNullPointerError; |
955 } | 975 } |
956 | 976 |
957 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | 977 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
958 // Stop any ongoing recording. | 978 // Stop any ongoing recording. |
959 if (debug_file_->Open()) { | 979 if (debug_file_->Open()) { |
960 if (debug_file_->CloseFile() == -1) { | 980 if (debug_file_->CloseFile() == -1) { |
961 return kFileError; | 981 return kFileError; |
962 } | 982 } |
963 } | 983 } |
964 | 984 |
965 if (debug_file_->OpenFromFileHandle(handle, true, false) == -1) { | 985 if (debug_file_->OpenFromFileHandle(handle, true, false) == -1) { |
966 return kFileError; | 986 return kFileError; |
967 } | 987 } |
968 | 988 |
969 int err = WriteInitMessage(); | 989 config_ = GetCurrentConfig(); |
990 int err = WriteConfigMessage(); | |
970 if (err != kNoError) { | 991 if (err != kNoError) { |
971 return err; | 992 return err; |
972 } | 993 } |
994 | |
995 err = WriteInitMessage(); | |
996 if (err != kNoError) { | |
997 return err; | |
998 } | |
973 return kNoError; | 999 return kNoError; |
974 #else | 1000 #else |
975 return kUnsupportedFunctionError; | 1001 return kUnsupportedFunctionError; |
976 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP | 1002 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP |
977 } | 1003 } |
978 | 1004 |
979 int AudioProcessingImpl::StartDebugRecordingForPlatformFile( | 1005 int AudioProcessingImpl::StartDebugRecordingForPlatformFile( |
980 rtc::PlatformFile handle) { | 1006 rtc::PlatformFile handle) { |
981 FILE* stream = rtc::FdopenPlatformFileForWriting(handle); | 1007 FILE* stream = rtc::FdopenPlatformFileForWriting(handle); |
982 return StartDebugRecording(stream); | 1008 return StartDebugRecording(stream); |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1239 msg->set_output_sample_rate(api_format_.output_stream().sample_rate_hz()); | 1265 msg->set_output_sample_rate(api_format_.output_stream().sample_rate_hz()); |
1240 // TODO(ekmeyerson): Add reverse output fields to event_msg_. | 1266 // TODO(ekmeyerson): Add reverse output fields to event_msg_. |
1241 | 1267 |
1242 int err = WriteMessageToDebugFile(); | 1268 int err = WriteMessageToDebugFile(); |
1243 if (err != kNoError) { | 1269 if (err != kNoError) { |
1244 return err; | 1270 return err; |
1245 } | 1271 } |
1246 | 1272 |
1247 return kNoError; | 1273 return kNoError; |
1248 } | 1274 } |
1275 | |
1276 AudioProcessingImpl::ApmConfig AudioProcessingImpl::GetCurrentConfig() const { | |
ivoc
2015/09/25 09:24:21
Wouldn't it be better to return an audioproc::Conf
minyue-webrtc
2015/09/25 09:49:09
I think it is very valid. I also felt it cumbersom
| |
1277 ApmConfig config; | |
1278 // Acoustic echo canceler | |
1279 config.aec_enabled = echo_cancellation_->is_enabled(); | |
1280 config.aec_delay_agnostic = echo_cancellation_->is_delay_agnostic_enabled(); | |
1281 config.aec_drift_compensation = | |
1282 echo_cancellation_->is_drift_compensation_enabled(); | |
1283 config.aec_extended_filter = | |
1284 echo_cancellation_->is_extended_filter_enabled(); | |
1285 config.aec_suppression_level = echo_cancellation_->suppression_level(); | |
1286 | |
1287 // Mobile AEC | |
1288 config.aecm_enabled = echo_control_mobile_->is_enabled(); | |
1289 config.aecm_comfort_noise = | |
1290 echo_control_mobile_->is_comfort_noise_enabled(); | |
1291 config.aecm_routing_mode = echo_control_mobile_->routing_mode(); | |
1292 | |
1293 // Automatic gain controller | |
1294 config.agc_enabled = gain_control_->is_enabled(); | |
1295 config.agc_experiment = use_new_agc_; | |
1296 config.agc_mode = gain_control_->mode(); | |
1297 config.agc_limiter = gain_control_->is_limiter_enabled(); | |
1298 | |
1299 // High pass filter | |
1300 config.hpf_enabled = high_pass_filter_->is_enabled(); | |
1301 | |
1302 // Noise suppression | |
1303 config.ns_enabled = noise_suppression_->is_enabled(); | |
1304 config.ns_experiment = transient_suppressor_enabled_; | |
1305 config.ns_level = noise_suppression_->level(); | |
1306 | |
1307 return config; | |
1308 } | |
1309 | |
1310 int AudioProcessingImpl::WriteConfigMessage() { | |
1311 event_msg_->set_type(audioproc::Event::CONFIG); | |
1312 audioproc::Config* msg = event_msg_->mutable_config(); | |
1313 | |
1314 // Acoustic echo canceler | |
1315 msg->set_aec_enabled(config_.aec_enabled); | |
1316 msg->set_aec_delay_agnostic(config_.aec_delay_agnostic); | |
1317 | |
1318 msg->set_aec_drift_compensation(config_.aec_drift_compensation); | |
1319 msg->set_aec_extended_filter(config_.aec_extended_filter); | |
1320 msg->set_aec_suppression_level(config_.aec_suppression_level); | |
1321 | |
1322 // Mobile AEC | |
1323 msg->set_aecm_enabled(config_.aecm_enabled); | |
1324 msg->set_aecm_comfort_noise(config_.aecm_comfort_noise); | |
1325 msg->set_aecm_routing_mode(config_.aecm_routing_mode); | |
1326 | |
1327 // Automatic gain controller | |
1328 msg->set_agc_enabled(config_.agc_enabled); | |
1329 msg->set_agc_experiment(config_.agc_experiment); | |
1330 msg->set_agc_mode(config_.agc_mode); | |
1331 msg->set_agc_limiter(config_.agc_limiter); | |
1332 | |
1333 // High pass filter | |
1334 msg->set_hpf_enabled(config_.hpf_enabled); | |
1335 | |
1336 // Noise suppression | |
1337 msg->set_ns_enabled(config_.ns_enabled); | |
1338 msg->set_ns_experiment(config_.ns_experiment); | |
1339 msg->set_ns_level(config_.ns_level); | |
1340 | |
1341 int err = WriteMessageToDebugFile(); | |
1342 if (err != kNoError) { | |
1343 return err; | |
1344 } | |
1345 | |
1346 return kNoError; | |
1347 } | |
1249 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP | 1348 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP |
1250 | 1349 |
1251 } // namespace webrtc | 1350 } // namespace webrtc |
OLD | NEW |