Skip to content

Commit

Permalink
Adds a checkbox to chrome://webrtc-internals to log an RTC event log.
Browse files Browse the repository at this point in the history
RTC event logs store a combination of RTP/RTCP headers and internal WebRTC
events, and can be used for analyzing issues in WebRTC, especially those
related to jitter buffers and bandwidth estimation.

BUG=chromium:545491
TBR=sievers@chromium.org

Review URL: https://codereview.chromium.org/1480593002

Cr-Commit-Position: refs/heads/master@{#366200}
  • Loading branch information
ivoc authored and Commit bot committed Dec 18, 2015
1 parent f19cde7 commit add54f0
Show file tree
Hide file tree
Showing 18 changed files with 369 additions and 26 deletions.
81 changes: 77 additions & 4 deletions content/browser/media/webrtc_internals.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,16 @@ static base::ListValue* EnsureLogList(base::DictionaryValue* dict) {
} // namespace

WebRTCInternals::WebRTCInternals()
: audio_debug_recordings_(false) {
: audio_debug_recordings_(false),
event_log_recordings_(false),
selecting_event_log_(false) {
// TODO(grunell): Shouldn't all the webrtc_internals* files be excluded from the
// build if WebRTC is disabled?
#if defined(ENABLE_WEBRTC)
audio_debug_recordings_file_path_ =
GetContentClient()->browser()->GetDefaultDownloadDirectory();
event_log_recordings_file_path_ = audio_debug_recordings_file_path_;

if (audio_debug_recordings_file_path_.empty()) {
// In this case the default path (|audio_debug_recordings_file_path_|) will
// be empty and the platform default path will be used in the file dialog
Expand All @@ -53,6 +57,8 @@ WebRTCInternals::WebRTCInternals()
audio_debug_recordings_file_path_ =
audio_debug_recordings_file_path_.Append(
FILE_PATH_LITERAL("audio_debug"));
event_log_recordings_file_path_ =
event_log_recordings_file_path_.Append(FILE_PATH_LITERAL("event_log"));
}
#endif // defined(ENABLE_WEBRTC)
}
Expand Down Expand Up @@ -247,6 +253,8 @@ void WebRTCInternals::EnableAudioDebugRecordings(
#if defined(OS_ANDROID)
EnableAudioDebugRecordingsOnAllRenderProcessHosts();
#else
selecting_event_log_ = false;
DCHECK(select_file_dialog_ == nullptr);
select_file_dialog_ = ui::SelectFileDialog::Create(this, NULL);
select_file_dialog_->SelectFile(
ui::SelectFileDialog::SELECT_SAVEAS_FILE,
Expand Down Expand Up @@ -288,6 +296,50 @@ const base::FilePath& WebRTCInternals::GetAudioDebugRecordingsFilePath() const {
return audio_debug_recordings_file_path_;
}

void WebRTCInternals::SetEventLogRecordings(
bool enable,
content::WebContents* web_contents) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
#if defined(ENABLE_WEBRTC)
if (enable) {
#if defined(OS_ANDROID)
EnableEventLogRecordingsOnAllRenderProcessHosts();
#else
DCHECK(web_contents);
DCHECK(select_file_dialog_ == nullptr);
selecting_event_log_ = true;
select_file_dialog_ = ui::SelectFileDialog::Create(this, nullptr);
select_file_dialog_->SelectFile(
ui::SelectFileDialog::SELECT_SAVEAS_FILE, base::string16(),
event_log_recordings_file_path_, nullptr, 0, FILE_PATH_LITERAL(""),
web_contents->GetTopLevelNativeWindow(), nullptr);
#endif
} else {
event_log_recordings_ = false;
// Tear down the dialog since the user has unchecked the audio debug
// recordings box.
select_file_dialog_ = nullptr;
DCHECK(select_file_dialog_->HasOneRef());

for (RenderProcessHost::iterator i(
content::RenderProcessHost::AllHostsIterator());
!i.IsAtEnd(); i.Advance()) {
i.GetCurrentValue()->DisableEventLogRecordings();
}
}
#endif
}

bool WebRTCInternals::IsEventLogRecordingsEnabled() const {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
return event_log_recordings_;
}

const base::FilePath& WebRTCInternals::GetEventLogRecordingsFilePath() const {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
return event_log_recordings_file_path_;
}

void WebRTCInternals::ResetForTesting() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
observers_.Clear();
Expand Down Expand Up @@ -318,15 +370,24 @@ void WebRTCInternals::FileSelected(const base::FilePath& path,
void* /*unused_params */) {
#if defined(ENABLE_WEBRTC)
DCHECK_CURRENTLY_ON(BrowserThread::UI);
audio_debug_recordings_file_path_ = path;
EnableAudioDebugRecordingsOnAllRenderProcessHosts();
if (selecting_event_log_) {
event_log_recordings_file_path_ = path;
EnableEventLogRecordingsOnAllRenderProcessHosts();
} else {
audio_debug_recordings_file_path_ = path;
EnableAudioDebugRecordingsOnAllRenderProcessHosts();
}
#endif
}

void WebRTCInternals::FileSelectionCanceled(void* params) {
#if defined(ENABLE_WEBRTC)
DCHECK_CURRENTLY_ON(BrowserThread::UI);
SendUpdate("audioDebugRecordingsFileSelectionCancelled", NULL);
if (selecting_event_log_) {
SendUpdate("eventLogRecordingsFileSelectionCancelled", nullptr);
} else {
SendUpdate("audioDebugRecordingsFileSelectionCancelled", nullptr);
}
#endif
}

Expand Down Expand Up @@ -393,6 +454,18 @@ void WebRTCInternals::EnableAudioDebugRecordingsOnAllRenderProcessHosts() {
audio_debug_recordings_file_path_);
}
}

void WebRTCInternals::EnableEventLogRecordingsOnAllRenderProcessHosts() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);

event_log_recordings_ = true;
for (RenderProcessHost::iterator i(
content::RenderProcessHost::AllHostsIterator());
!i.IsAtEnd(); i.Advance()) {
i.GetCurrentValue()->EnableEventLogRecordings(
event_log_recordings_file_path_);
}
}
#endif

void WebRTCInternals::CreateOrReleasePowerSaveBlocker() {
Expand Down
15 changes: 15 additions & 0 deletions content/browser/media/webrtc_internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ class CONTENT_EXPORT WebRTCInternals : public RenderProcessHostObserver,
bool IsAudioDebugRecordingsEnabled() const;
const base::FilePath& GetAudioDebugRecordingsFilePath() const;

// Enables or disables diagnostic event log.
void SetEventLogRecordings(bool enable, content::WebContents* web_contents);

bool IsEventLogRecordingsEnabled() const;
const base::FilePath& GetEventLogRecordingsFilePath() const;

void ResetForTesting();

private:
Expand Down Expand Up @@ -128,6 +134,10 @@ class CONTENT_EXPORT WebRTCInternals : public RenderProcessHostObserver,
// Enables diagnostic audio recordings on all render process hosts using
// |audio_debug_recordings_file_path_|.
void EnableAudioDebugRecordingsOnAllRenderProcessHosts();

// Enables event log recordings on all render process hosts using
// |event_log_recordings_file_path_|.
void EnableEventLogRecordingsOnAllRenderProcessHosts();
#endif

// Called whenever an element is added to or removed from
Expand Down Expand Up @@ -169,6 +179,11 @@ class CONTENT_EXPORT WebRTCInternals : public RenderProcessHostObserver,
bool audio_debug_recordings_;
base::FilePath audio_debug_recordings_file_path_;

// Diagnostic event log recording state.
bool event_log_recordings_;
bool selecting_event_log_;
base::FilePath event_log_recordings_file_path_;

// While |peer_connection_data_| is non-empty, hold an instance of
// PowerSaveBlocker. This prevents the application from being suspended while
// remoting.
Expand Down
17 changes: 17 additions & 0 deletions content/browser/media/webrtc_internals_message_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ void WebRTCInternalsMessageHandler::RegisterMessages() {
base::Unretained(this),
false));

web_ui()->RegisterMessageCallback(
"enableEventLogRecordings",
base::Bind(&WebRTCInternalsMessageHandler::OnSetEventLogRecordingsEnabled,
base::Unretained(this), true));

web_ui()->RegisterMessageCallback(
"disableEventLogRecordings",
base::Bind(&WebRTCInternalsMessageHandler::OnSetEventLogRecordingsEnabled,
base::Unretained(this), false));

web_ui()->RegisterMessageCallback("finishedDOMLoad",
base::Bind(&WebRTCInternalsMessageHandler::OnDOMLoadDone,
base::Unretained(this)));
Expand Down Expand Up @@ -81,6 +91,13 @@ void WebRTCInternalsMessageHandler::OnSetAudioDebugRecordingsEnabled(
}
}

void WebRTCInternalsMessageHandler::OnSetEventLogRecordingsEnabled(
bool enable,
const base::ListValue* /* unused_list */) {
WebRTCInternals::GetInstance()->SetEventLogRecordings(
enable, enable ? web_ui()->GetWebContents() : nullptr);
}

void WebRTCInternalsMessageHandler::OnDOMLoadDone(
const base::ListValue* /* unused_list */) {
WebRTCInternals::GetInstance()->UpdateObserver(this);
Expand Down
1 change: 1 addition & 0 deletions content/browser/media/webrtc_internals_message_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class WebRTCInternalsMessageHandler : public WebUIMessageHandler,
void OnGetAllStats(const base::ListValue* list);
void OnSetAudioDebugRecordingsEnabled(bool enable,
const base::ListValue* list);
void OnSetEventLogRecordingsEnabled(bool enable, const base::ListValue* list);
void OnDOMLoadDone(const base::ListValue* list);

DISALLOW_COPY_AND_ASSIGN(WebRTCInternalsMessageHandler);
Expand Down
Loading

0 comments on commit add54f0

Please sign in to comment.