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

Side by Side Diff: webrtc/modules/audio_processing/audio_processing_impl.cc

Issue 1413483003: Added option to specify a maximum file size when recording an AEC dump. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Processed first batch of reviews. Created 5 years, 1 month 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
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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 echo_control_mobile_(NULL), 187 echo_control_mobile_(NULL),
188 gain_control_(NULL), 188 gain_control_(NULL),
189 high_pass_filter_(NULL), 189 high_pass_filter_(NULL),
190 level_estimator_(NULL), 190 level_estimator_(NULL),
191 noise_suppression_(NULL), 191 noise_suppression_(NULL),
192 voice_detection_(NULL), 192 voice_detection_(NULL),
193 crit_(CriticalSectionWrapper::CreateCriticalSection()), 193 crit_(CriticalSectionWrapper::CreateCriticalSection()),
194 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP 194 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
195 debug_file_(FileWrapper::Create()), 195 debug_file_(FileWrapper::Create()),
196 event_msg_(new audioproc::Event()), 196 event_msg_(new audioproc::Event()),
197 nr_bytes_left_for_log(-1),
197 #endif 198 #endif
198 api_format_({{{kSampleRate16kHz, 1, false}, 199 api_format_({{{kSampleRate16kHz, 1, false},
199 {kSampleRate16kHz, 1, false}, 200 {kSampleRate16kHz, 1, false},
200 {kSampleRate16kHz, 1, false}, 201 {kSampleRate16kHz, 1, false},
201 {kSampleRate16kHz, 1, false}}}), 202 {kSampleRate16kHz, 1, false}}}),
202 fwd_proc_format_(kSampleRate16kHz), 203 fwd_proc_format_(kSampleRate16kHz),
203 rev_proc_format_(kSampleRate16kHz, 1), 204 rev_proc_format_(kSampleRate16kHz, 1),
204 split_rate_(kSampleRate16kHz), 205 split_rate_(kSampleRate16kHz),
205 stream_delay_ms_(0), 206 stream_delay_ms_(0),
206 delay_offset_ms_(0), 207 delay_offset_ms_(0),
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 RETURN_ON_ERR(ProcessStreamLocked()); 555 RETURN_ON_ERR(ProcessStreamLocked());
555 capture_audio_->CopyTo(api_format_.output_stream(), dest); 556 capture_audio_->CopyTo(api_format_.output_stream(), dest);
556 557
557 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP 558 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
558 if (debug_file_->Open()) { 559 if (debug_file_->Open()) {
559 audioproc::Stream* msg = event_msg_->mutable_stream(); 560 audioproc::Stream* msg = event_msg_->mutable_stream();
560 const size_t channel_size = 561 const size_t channel_size =
561 sizeof(float) * api_format_.output_stream().num_frames(); 562 sizeof(float) * api_format_.output_stream().num_frames();
562 for (int i = 0; i < api_format_.output_stream().num_channels(); ++i) 563 for (int i = 0; i < api_format_.output_stream().num_channels(); ++i)
563 msg->add_output_channel(dest[i], channel_size); 564 msg->add_output_channel(dest[i], channel_size);
564 RETURN_ON_ERR(WriteMessageToDebugFile()); 565 RETURN_ON_ERR(WriteMessageToDebugFile());
the sun 2015/11/11 15:54:42 What happens when ProcessStream() suddenly returns
ivoc 2015/11/11 16:44:31 Good point, I changed the return code when the siz
565 } 566 }
566 #endif 567 #endif
567 568
568 return kNoError; 569 return kNoError;
569 } 570 }
570 571
571 int AudioProcessingImpl::ProcessStream(AudioFrame* frame) { 572 int AudioProcessingImpl::ProcessStream(AudioFrame* frame) {
572 CriticalSectionScoped crit_scoped(crit_); 573 CriticalSectionScoped crit_scoped(crit_);
573 if (!frame) { 574 if (!frame) {
574 return kNullPointerError; 575 return kNullPointerError;
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
894 void AudioProcessingImpl::set_delay_offset_ms(int offset) { 895 void AudioProcessingImpl::set_delay_offset_ms(int offset) {
895 CriticalSectionScoped crit_scoped(crit_); 896 CriticalSectionScoped crit_scoped(crit_);
896 delay_offset_ms_ = offset; 897 delay_offset_ms_ = offset;
897 } 898 }
898 899
899 int AudioProcessingImpl::delay_offset_ms() const { 900 int AudioProcessingImpl::delay_offset_ms() const {
900 return delay_offset_ms_; 901 return delay_offset_ms_;
901 } 902 }
902 903
903 int AudioProcessingImpl::StartDebugRecording( 904 int AudioProcessingImpl::StartDebugRecording(
904 const char filename[AudioProcessing::kMaxFilenameSize]) { 905 const char filename[AudioProcessing::kMaxFilenameSize],
906 int64_t max_log_size_bytes) {
905 CriticalSectionScoped crit_scoped(crit_); 907 CriticalSectionScoped crit_scoped(crit_);
906 static_assert(kMaxFilenameSize == FileWrapper::kMaxFileNameSize, ""); 908 static_assert(kMaxFilenameSize == FileWrapper::kMaxFileNameSize, "");
907 909
908 if (filename == NULL) { 910 if (filename == NULL) {
909 return kNullPointerError; 911 return kNullPointerError;
910 } 912 }
911 913
912 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP 914 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
915 nr_bytes_left_for_log = max_log_size_bytes;
913 // Stop any ongoing recording. 916 // Stop any ongoing recording.
914 if (debug_file_->Open()) {
915 if (debug_file_->CloseFile() == -1) {
916 return kFileError;
917 }
918 }
919
920 if (debug_file_->OpenFile(filename, false) == -1) { 917 if (debug_file_->OpenFile(filename, false) == -1) {
921 debug_file_->CloseFile(); 918 debug_file_->CloseFile();
922 return kFileError; 919 return kFileError;
923 } 920 }
924 921
925 RETURN_ON_ERR(WriteConfigMessage(true)); 922 RETURN_ON_ERR(WriteConfigMessage(true));
926 RETURN_ON_ERR(WriteInitMessage()); 923 RETURN_ON_ERR(WriteInitMessage());
927 return kNoError; 924 return kNoError;
928 #else 925 #else
929 return kUnsupportedFunctionError; 926 return kUnsupportedFunctionError;
930 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP 927 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP
931 } 928 }
932 929
933 int AudioProcessingImpl::StartDebugRecording(FILE* handle) { 930 int AudioProcessingImpl::StartDebugRecording(FILE* handle,
931 int64_t max_log_size_bytes) {
934 CriticalSectionScoped crit_scoped(crit_); 932 CriticalSectionScoped crit_scoped(crit_);
935 933
936 if (handle == NULL) { 934 if (handle == NULL) {
937 return kNullPointerError; 935 return kNullPointerError;
938 } 936 }
939 937
940 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP 938 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
939 nr_bytes_left_for_log = max_log_size_bytes;
940
941 // Stop any ongoing recording. 941 // Stop any ongoing recording.
942 if (debug_file_->Open()) { 942 if (debug_file_->Open()) {
943 if (debug_file_->CloseFile() == -1) { 943 if (debug_file_->CloseFile() == -1) {
944 return kFileError; 944 return kFileError;
945 } 945 }
946 } 946 }
947 947
948 if (debug_file_->OpenFromFileHandle(handle, true, false) == -1) { 948 if (debug_file_->OpenFromFileHandle(handle, true, false) == -1) {
949 return kFileError; 949 return kFileError;
950 } 950 }
951 951
952 RETURN_ON_ERR(WriteConfigMessage(true)); 952 RETURN_ON_ERR(WriteConfigMessage(true));
953 RETURN_ON_ERR(WriteInitMessage()); 953 RETURN_ON_ERR(WriteInitMessage());
954 return kNoError; 954 return kNoError;
955 #else 955 #else
956 return kUnsupportedFunctionError; 956 return kUnsupportedFunctionError;
957 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP 957 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP
958 } 958 }
959 959
960 int AudioProcessingImpl::StartDebugRecordingForPlatformFile( 960 int AudioProcessingImpl::StartDebugRecordingForPlatformFile(
961 rtc::PlatformFile handle) { 961 rtc::PlatformFile handle) {
962 FILE* stream = rtc::FdopenPlatformFileForWriting(handle); 962 FILE* stream = rtc::FdopenPlatformFileForWriting(handle);
963 return StartDebugRecording(stream); 963 return StartDebugRecording(stream, -1);
964 } 964 }
965 965
966 int AudioProcessingImpl::StopDebugRecording() { 966 int AudioProcessingImpl::StopDebugRecording() {
967 CriticalSectionScoped crit_scoped(crit_); 967 CriticalSectionScoped crit_scoped(crit_);
968 968
969 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP 969 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
970 // We just return if recording hasn't started. 970 // We just return if recording hasn't started.
971 if (debug_file_->Open()) { 971 if (debug_file_->Open()) {
972 if (debug_file_->CloseFile() == -1) { 972 if (debug_file_->CloseFile() == -1) {
973 return kFileError; 973 return kFileError;
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
1174 if (aec_system_delay_jumps_ > -1) { 1174 if (aec_system_delay_jumps_ > -1) {
1175 RTC_HISTOGRAM_ENUMERATION("WebRTC.Audio.NumOfAecSystemDelayJumps", 1175 RTC_HISTOGRAM_ENUMERATION("WebRTC.Audio.NumOfAecSystemDelayJumps",
1176 aec_system_delay_jumps_, 51); 1176 aec_system_delay_jumps_, 51);
1177 } 1177 }
1178 aec_system_delay_jumps_ = -1; 1178 aec_system_delay_jumps_ = -1;
1179 last_aec_system_delay_ms_ = 0; 1179 last_aec_system_delay_ms_ = 0;
1180 } 1180 }
1181 1181
1182 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP 1182 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
1183 int AudioProcessingImpl::WriteMessageToDebugFile() { 1183 int AudioProcessingImpl::WriteMessageToDebugFile() {
1184 RTC_DCHECK(debug_file_->Open());
1184 int32_t size = event_msg_->ByteSize(); 1185 int32_t size = event_msg_->ByteSize();
1185 if (size <= 0) { 1186 if (size <= 0) {
1186 return kUnspecifiedError; 1187 return kUnspecifiedError;
1187 } 1188 }
1188 #if defined(WEBRTC_ARCH_BIG_ENDIAN) 1189 #if defined(WEBRTC_ARCH_BIG_ENDIAN)
1189 // TODO(ajm): Use little-endian "on the wire". For the moment, we can be 1190 // TODO(ajm): Use little-endian "on the wire". For the moment, we can be
1190 // pretty safe in assuming little-endian. 1191 // pretty safe in assuming little-endian.
1191 #endif 1192 #endif
1192 1193
1193 if (!event_msg_->SerializeToString(&event_str_)) { 1194 if (!event_msg_->SerializeToString(&event_str_)) {
1194 return kUnspecifiedError; 1195 return kUnspecifiedError;
1195 } 1196 }
1196 1197
1198 if (nr_bytes_left_for_log >= 0) {
1199 nr_bytes_left_for_log -= (sizeof(int32_t) + event_str_.length());
1200 if (nr_bytes_left_for_log < 0) {
1201 // Not enough bytes are left to write this message, so stop logging.
1202 debug_file_->CloseFile();
1203 return kUnspecifiedError;
1204 }
1205 }
1206
1197 // Write message preceded by its size. 1207 // Write message preceded by its size.
1198 if (!debug_file_->Write(&size, sizeof(int32_t))) { 1208 if (!debug_file_->Write(&size, sizeof(int32_t))) {
1199 return kFileError; 1209 return kFileError;
1200 } 1210 }
1201 if (!debug_file_->Write(event_str_.data(), event_str_.length())) { 1211 if (!debug_file_->Write(event_str_.data(), event_str_.length())) {
1202 return kFileError; 1212 return kFileError;
1203 } 1213 }
1204 1214
1205 event_msg_->Clear(); 1215 event_msg_->Clear();
1206 1216
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1264 1274
1265 event_msg_->set_type(audioproc::Event::CONFIG); 1275 event_msg_->set_type(audioproc::Event::CONFIG);
1266 event_msg_->mutable_config()->CopyFrom(config); 1276 event_msg_->mutable_config()->CopyFrom(config);
1267 1277
1268 RETURN_ON_ERR(WriteMessageToDebugFile()); 1278 RETURN_ON_ERR(WriteMessageToDebugFile());
1269 return kNoError; 1279 return kNoError;
1270 } 1280 }
1271 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP 1281 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP
1272 1282
1273 } // namespace webrtc 1283 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698