| Index: chrome/browser/media/webrtc_logging_handler_host.cc
|
| diff --git a/chrome/browser/media/webrtc_logging_handler_host.cc b/chrome/browser/media/webrtc_logging_handler_host.cc
|
| index ef7dc1938027ac96e225cee8d53f88a39269acea..daa0acc2b0ef1937748edd6ce2ba06a97164c4b5 100644
|
| --- a/chrome/browser/media/webrtc_logging_handler_host.cc
|
| +++ b/chrome/browser/media/webrtc_logging_handler_host.cc
|
| @@ -105,6 +105,15 @@ void FormatMetaDataAsLogMessage(
|
| message->resize(message->size() - 1);
|
| }
|
|
|
| +// Returns a path name to be used as prefix for audio debug recordings files.
|
| +base::FilePath GetAudioDebugRecordingsPrefixPath(
|
| + const base::FilePath& directory,
|
| + uint64_t audio_debug_recordings_id) {
|
| + static const char kAudioDebugRecordingsFilePrefix[] = "AudioDebugRecordings.";
|
| + return directory.AppendASCII(kAudioDebugRecordingsFilePrefix +
|
| + base::Int64ToString(audio_debug_recordings_id));
|
| +}
|
| +
|
| } // namespace
|
|
|
| WebRtcLogBuffer::WebRtcLogBuffer()
|
| @@ -141,12 +150,15 @@ void WebRtcLogBuffer::SetComplete() {
|
| }
|
|
|
| WebRtcLoggingHandlerHost::WebRtcLoggingHandlerHost(
|
| - Profile* profile, WebRtcLogUploader* log_uploader)
|
| + Profile* profile,
|
| + WebRtcLogUploader* log_uploader)
|
| : BrowserMessageFilter(WebRtcLoggingMsgStart),
|
| profile_(profile),
|
| logging_state_(CLOSED),
|
| upload_log_on_render_close_(false),
|
| - log_uploader_(log_uploader) {
|
| + log_uploader_(log_uploader),
|
| + is_audio_debug_recordings_in_progress_(false),
|
| + current_audio_debug_recordings_id_(0) {
|
| DCHECK(profile_);
|
| DCHECK(log_uploader_);
|
| }
|
| @@ -429,6 +441,35 @@ void WebRtcLoggingHandlerHost::DumpRtpPacketOnIOThread(
|
| }
|
| }
|
|
|
| +void WebRtcLoggingHandlerHost::StartAudioDebugRecordings(
|
| + content::RenderProcessHost* host,
|
| + base::TimeDelta delay,
|
| + const AudioDebugRecordingsCallback& callback,
|
| + const AudioDebugRecordingsErrorCallback& error_callback) {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| +
|
| + BrowserThread::PostTaskAndReplyWithResult(
|
| + BrowserThread::FILE, FROM_HERE,
|
| + base::Bind(&WebRtcLoggingHandlerHost::GetLogDirectoryAndEnsureExists,
|
| + this),
|
| + base::Bind(&WebRtcLoggingHandlerHost::DoStartAudioDebugRecordings, this,
|
| + host, delay, callback, error_callback));
|
| +}
|
| +
|
| +void WebRtcLoggingHandlerHost::StopAudioDebugRecordings(
|
| + content::RenderProcessHost* host,
|
| + const AudioDebugRecordingsCallback& callback,
|
| + const AudioDebugRecordingsErrorCallback& error_callback) {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| + BrowserThread::PostTaskAndReplyWithResult(
|
| + BrowserThread::FILE, FROM_HERE,
|
| + base::Bind(&WebRtcLoggingHandlerHost::GetLogDirectoryAndEnsureExists,
|
| + this),
|
| + base::Bind(&WebRtcLoggingHandlerHost::DoStopAudioDebugRecordings, this,
|
| + host, true /* manual stop */,
|
| + current_audio_debug_recordings_id_, callback, error_callback));
|
| +}
|
| +
|
| void WebRtcLoggingHandlerHost::OnChannelClosing() {
|
| DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| if (logging_state_ == STARTED || logging_state_ == STOPPED) {
|
| @@ -765,3 +806,68 @@ void WebRtcLoggingHandlerHost::FireGenericDoneCallback(
|
| FROM_HERE,
|
| base::Bind(callback, success, error_message_with_state));
|
| }
|
| +
|
| +void WebRtcLoggingHandlerHost::DoStartAudioDebugRecordings(
|
| + content::RenderProcessHost* host,
|
| + base::TimeDelta delay,
|
| + const AudioDebugRecordingsCallback& callback,
|
| + const AudioDebugRecordingsErrorCallback& error_callback,
|
| + const base::FilePath& log_directory) {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| +
|
| + if (is_audio_debug_recordings_in_progress_) {
|
| + error_callback.Run("Audio debug recordings already in progress");
|
| + return;
|
| + }
|
| +
|
| + is_audio_debug_recordings_in_progress_ = true;
|
| + base::FilePath prefix_path = GetAudioDebugRecordingsPrefixPath(
|
| + log_directory, ++current_audio_debug_recordings_id_);
|
| + host->EnableAudioDebugRecordings(prefix_path);
|
| +
|
| + if (delay.is_zero()) {
|
| + callback.Run(prefix_path.AsUTF8Unsafe(), false /* not stopped */,
|
| + false /* not manually stopped */);
|
| + return;
|
| + }
|
| +
|
| + BrowserThread::PostTask(
|
| + BrowserThread::UI, FROM_HERE,
|
| + base::Bind(&WebRtcLoggingHandlerHost::DoStopAudioDebugRecordings, this,
|
| + host, false /* no manual stop */,
|
| + current_audio_debug_recordings_id_, callback, error_callback,
|
| + prefix_path));
|
| +}
|
| +
|
| +void WebRtcLoggingHandlerHost::DoStopAudioDebugRecordings(
|
| + content::RenderProcessHost* host,
|
| + bool is_manual_stop,
|
| + uint64_t audio_debug_recordings_id,
|
| + const AudioDebugRecordingsCallback& callback,
|
| + const AudioDebugRecordingsErrorCallback& error_callback,
|
| + const base::FilePath& log_directory) {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| + DCHECK_LE(audio_debug_recordings_id, current_audio_debug_recordings_id_);
|
| +
|
| + base::FilePath prefix_path = GetAudioDebugRecordingsPrefixPath(
|
| + log_directory, audio_debug_recordings_id);
|
| + // Prevent an old posted StopAudioDebugRecordings() call to stop a newer dump.
|
| + // This could happen in a sequence like:
|
| + // Start(10); //Start dump 1. Post Stop() to run after 10 seconds.
|
| + // Stop(); // Manually stop dump 1 before 10 seconds;
|
| + // Start(20); // Start dump 2. Posted Stop() for 1 should not stop dump 2.
|
| + if (audio_debug_recordings_id < current_audio_debug_recordings_id_) {
|
| + callback.Run(prefix_path.AsUTF8Unsafe(), false /* not stopped */,
|
| + is_manual_stop);
|
| + return;
|
| + }
|
| +
|
| + if (!is_audio_debug_recordings_in_progress_) {
|
| + error_callback.Run("No audio debug recording in progress");
|
| + return;
|
| + }
|
| +
|
| + host->DisableAudioDebugRecordings();
|
| + is_audio_debug_recordings_in_progress_ = false;
|
| + callback.Run(prefix_path.AsUTF8Unsafe(), true /* stopped */, is_manual_stop);
|
| +}
|
|
|