Chromium Code Reviews| Index: webrtc/modules/audio_processing/audio_processing_impl.cc |
| diff --git a/webrtc/modules/audio_processing/audio_processing_impl.cc b/webrtc/modules/audio_processing/audio_processing_impl.cc |
| index f3ee0a399d54eaefad5020a550816051c421d0eb..f658792f10ab0cd3f7336e9c063e303d70e63fb8 100644 |
| --- a/webrtc/modules/audio_processing/audio_processing_impl.cc |
| +++ b/webrtc/modules/audio_processing/audio_processing_impl.cc |
| @@ -194,6 +194,7 @@ AudioProcessingImpl::AudioProcessingImpl(const Config& config, |
| #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
| debug_file_(FileWrapper::Create()), |
| event_msg_(new audioproc::Event()), |
| + nr_bytes_left_for_log_(-1), |
| #endif |
| api_format_({{{kSampleRate16kHz, 1, false}, |
| {kSampleRate16kHz, 1, false}, |
| @@ -901,7 +902,8 @@ int AudioProcessingImpl::delay_offset_ms() const { |
| } |
| int AudioProcessingImpl::StartDebugRecording( |
| - const char filename[AudioProcessing::kMaxFilenameSize]) { |
| + const char filename[AudioProcessing::kMaxFilenameSize], |
| + int64_t max_log_size_bytes) { |
| CriticalSectionScoped crit_scoped(crit_); |
| static_assert(kMaxFilenameSize == FileWrapper::kMaxFileNameSize, ""); |
| @@ -910,13 +912,8 @@ int AudioProcessingImpl::StartDebugRecording( |
| } |
| #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
| + nr_bytes_left_for_log_ = max_log_size_bytes; |
| // Stop any ongoing recording. |
| - if (debug_file_->Open()) { |
|
Andrew MacDonald
2015/11/24 17:28:59
Why did you remove this block? It's not removed fr
ivoc
2015/12/01 15:17:16
Good point, I'm not sure why I removed it initiall
|
| - if (debug_file_->CloseFile() == -1) { |
| - return kFileError; |
| - } |
| - } |
| - |
| if (debug_file_->OpenFile(filename, false) == -1) { |
| debug_file_->CloseFile(); |
| return kFileError; |
| @@ -930,7 +927,8 @@ int AudioProcessingImpl::StartDebugRecording( |
| #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP |
| } |
| -int AudioProcessingImpl::StartDebugRecording(FILE* handle) { |
| +int AudioProcessingImpl::StartDebugRecording(FILE* handle, |
| + int64_t max_log_size_bytes) { |
| CriticalSectionScoped crit_scoped(crit_); |
| if (handle == NULL) { |
| @@ -938,6 +936,8 @@ int AudioProcessingImpl::StartDebugRecording(FILE* handle) { |
| } |
| #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
| + nr_bytes_left_for_log_ = max_log_size_bytes; |
| + |
| // Stop any ongoing recording. |
| if (debug_file_->Open()) { |
| if (debug_file_->CloseFile() == -1) { |
| @@ -960,7 +960,7 @@ int AudioProcessingImpl::StartDebugRecording(FILE* handle) { |
| int AudioProcessingImpl::StartDebugRecordingForPlatformFile( |
| rtc::PlatformFile handle) { |
| FILE* stream = rtc::FdopenPlatformFileForWriting(handle); |
| - return StartDebugRecording(stream); |
| + return StartDebugRecording(stream, -1); |
| } |
| int AudioProcessingImpl::StopDebugRecording() { |
| @@ -1181,6 +1181,7 @@ void AudioProcessingImpl::UpdateHistogramsOnCallEnd() { |
| #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
| int AudioProcessingImpl::WriteMessageToDebugFile() { |
| + RTC_DCHECK(debug_file_->Open()); |
| int32_t size = event_msg_->ByteSize(); |
| if (size <= 0) { |
| return kUnspecifiedError; |
| @@ -1194,6 +1195,15 @@ int AudioProcessingImpl::WriteMessageToDebugFile() { |
| return kUnspecifiedError; |
| } |
| + if (nr_bytes_left_for_log_ >= 0) { |
| + nr_bytes_left_for_log_ -= (sizeof(int32_t) + event_str_.length()); |
| + if (nr_bytes_left_for_log_ < 0) { |
| + // Not enough bytes are left to write this message, so stop logging. |
| + debug_file_->CloseFile(); |
| + return kNoError; |
| + } |
| + } |
| + |
| // Write message preceded by its size. |
| if (!debug_file_->Write(&size, sizeof(int32_t))) { |
| return kFileError; |