| 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 816be38e2ff876b0a4083f8f433931c5132631e0..566ec9496a2b06c6c20d26c30f0082bc8b2bec97 100644
|
| --- a/chrome/browser/media/webrtc_logging_handler_host.cc
|
| +++ b/chrome/browser/media/webrtc_logging_handler_host.cc
|
| @@ -19,6 +19,7 @@
|
| #include "chrome/browser/chromeos/settings/cros_settings.h"
|
| #include "chrome/browser/media/webrtc_log_list.h"
|
| #include "chrome/browser/media/webrtc_log_uploader.h"
|
| +#include "chrome/browser/media/webrtc_rtp_dump_handler.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| #include "chrome/common/chrome_switches.h"
|
| #include "chrome/common/media/webrtc_logging_messages.h"
|
| @@ -48,6 +49,7 @@
|
| using base::IntToString;
|
| using content::BrowserThread;
|
|
|
| +namespace {
|
|
|
| #if defined(OS_ANDROID)
|
| const size_t kWebRtcLogSize = 1 * 1024 * 1024; // 1 MB
|
| @@ -55,8 +57,6 @@ const size_t kWebRtcLogSize = 1 * 1024 * 1024; // 1 MB
|
| const size_t kWebRtcLogSize = 6 * 1024 * 1024; // 6 MB
|
| #endif
|
|
|
| -namespace {
|
| -
|
| const char kLogNotStoppedOrNoLogOpen[] =
|
| "Logging not stopped or no log open.";
|
|
|
| @@ -190,7 +190,7 @@ void WebRtcLoggingHandlerHost::UploadLog(const UploadDoneCallback& callback) {
|
| FROM_HERE,
|
| base::Bind(&WebRtcLoggingHandlerHost::GetLogDirectoryAndEnsureExists,
|
| this),
|
| - base::Bind(&WebRtcLoggingHandlerHost::TriggerUploadLog, this));
|
| + base::Bind(&WebRtcLoggingHandlerHost::TriggerUpload, this));
|
| }
|
|
|
| void WebRtcLoggingHandlerHost::UploadLogDone() {
|
| @@ -212,6 +212,7 @@ void WebRtcLoggingHandlerHost::DiscardLog(const GenericDoneCallback& callback) {
|
| circular_buffer_.reset();
|
| log_buffer_.reset();
|
| logging_state_ = CLOSED;
|
| + rtp_dump_handler_.reset();
|
| FireGenericDoneCallback(&discard_callback, true, "");
|
| }
|
|
|
| @@ -229,14 +230,86 @@ void WebRtcLoggingHandlerHost::StartRtpDump(
|
| bool incoming,
|
| bool outgoing,
|
| const GenericDoneCallback& callback) {
|
| - NOTIMPLEMENTED();
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| + DCHECK(!callback.is_null());
|
| +
|
| + GenericDoneCallback start_callback = callback;
|
| + if (!incoming && !outgoing) {
|
| + FireGenericDoneCallback(
|
| + &start_callback,
|
| + false,
|
| + "Either incoming or outgoing argument must be true.");
|
| + return;
|
| + }
|
| +
|
| + if (!rtp_dump_handler_) {
|
| + content::BrowserThread::PostTaskAndReplyWithResult(
|
| + content::BrowserThread::FILE,
|
| + FROM_HERE,
|
| + base::Bind(&WebRtcLoggingHandlerHost::GetLogDirectoryAndEnsureExists,
|
| + this),
|
| + base::Bind(&WebRtcLoggingHandlerHost::CreateRtpDumpHandlerAndStart,
|
| + this,
|
| + incoming,
|
| + outgoing,
|
| + callback));
|
| + return;
|
| + }
|
| +
|
| + DoStartRtpDump(incoming, outgoing, &start_callback);
|
| }
|
|
|
| void WebRtcLoggingHandlerHost::StopRtpDump(
|
| bool incoming,
|
| bool outgoing,
|
| const GenericDoneCallback& callback) {
|
| - NOTIMPLEMENTED();
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| + DCHECK(!callback.is_null());
|
| +
|
| + GenericDoneCallback stop_callback = callback;
|
| + if (!(incoming || outgoing) || !rtp_dump_handler_) {
|
| + FireGenericDoneCallback(&stop_callback, false, "Invalid argument");
|
| + return;
|
| + }
|
| +
|
| + WebRtcRtpDumpHandler::PacketType type =
|
| + (incoming && outgoing)
|
| + ? WebRtcRtpDumpHandler::PACKET_TYPE_BOTH
|
| + : (incoming ? WebRtcRtpDumpHandler::PACKET_TYPE_INCOMING_ONLY
|
| + : WebRtcRtpDumpHandler::PACKET_TYPE_OUTGOING_ONLY);
|
| +
|
| + rtp_dump_handler_->StopDump(type, callback);
|
| +}
|
| +
|
| +void WebRtcLoggingHandlerHost::OnRtpPacket(const uint8* packet_header,
|
| + size_t header_length,
|
| + size_t packet_length,
|
| + bool incoming) {
|
| + scoped_ptr<uint8[]> header_data(new uint8[header_length]);
|
| + memcpy(header_data.get(), packet_header, header_length);
|
| +
|
| + BrowserThread::PostTask(
|
| + BrowserThread::IO,
|
| + FROM_HERE,
|
| + base::Bind(&WebRtcLoggingHandlerHost::DumpRtpPacketOnIOThread,
|
| + this,
|
| + base::Passed(&header_data),
|
| + header_length,
|
| + packet_length,
|
| + incoming));
|
| +}
|
| +
|
| +void WebRtcLoggingHandlerHost::DumpRtpPacketOnIOThread(
|
| + scoped_ptr<uint8[]> packet_header,
|
| + size_t header_length,
|
| + size_t packet_length,
|
| + bool incoming) {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| +
|
| + if (rtp_dump_handler_) {
|
| + rtp_dump_handler_->OnRtpPacket(
|
| + packet_header.get(), header_length, packet_length, incoming);
|
| + }
|
| }
|
|
|
| void WebRtcLoggingHandlerHost::OnChannelClosing() {
|
| @@ -250,7 +323,7 @@ void WebRtcLoggingHandlerHost::OnChannelClosing() {
|
| FROM_HERE,
|
| base::Bind(&WebRtcLoggingHandlerHost::GetLogDirectoryAndEnsureExists,
|
| this),
|
| - base::Bind(&WebRtcLoggingHandlerHost::TriggerUploadLog, this));
|
| + base::Bind(&WebRtcLoggingHandlerHost::TriggerUpload, this));
|
| } else {
|
| g_browser_process->webrtc_log_uploader()->LoggingStoppedDontUpload();
|
| }
|
| @@ -452,13 +525,77 @@ base::FilePath WebRtcLoggingHandlerHost::GetLogDirectoryAndEnsureExists() {
|
| return log_dir_path;
|
| }
|
|
|
| -void WebRtcLoggingHandlerHost::TriggerUploadLog(
|
| +void WebRtcLoggingHandlerHost::TriggerUpload(
|
| const base::FilePath& log_directory) {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| DCHECK_EQ(logging_state_, UPLOADING);
|
|
|
| + WebRtcRtpDumpHandler::ReleasedDumps dumps;
|
| + if (rtp_dump_handler_)
|
| + dumps = rtp_dump_handler_->ReleaseDumps();
|
| +
|
| + DoUploadLogAndDumps(log_directory, dumps);
|
| +}
|
| +
|
| +void WebRtcLoggingHandlerHost::FireGenericDoneCallback(
|
| + GenericDoneCallback* callback,
|
| + bool success,
|
| + const std::string& error_message) {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| + DCHECK(!(*callback).is_null());
|
| + content::BrowserThread::PostTask(
|
| + content::BrowserThread::UI,
|
| + FROM_HERE,
|
| + base::Bind(*callback, success, error_message));
|
| + (*callback).Reset();
|
| +}
|
| +
|
| +void WebRtcLoggingHandlerHost::CreateRtpDumpHandlerAndStart(
|
| + bool incoming,
|
| + bool outgoing,
|
| + GenericDoneCallback callback,
|
| + const base::FilePath& dump_dir) {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| +
|
| + if (!rtp_dump_handler_)
|
| + rtp_dump_handler_.reset(new WebRtcRtpDumpHandler(dump_dir));
|
| +
|
| + DoStartRtpDump(incoming, outgoing, &callback);
|
| +}
|
| +
|
| +void WebRtcLoggingHandlerHost::DoStartRtpDump(bool incoming,
|
| + bool outgoing,
|
| + GenericDoneCallback* callback) {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| + DCHECK(rtp_dump_handler_);
|
| +
|
| + std::string error;
|
| + WebRtcRtpDumpHandler::PacketType type =
|
| + (incoming && outgoing)
|
| + ? WebRtcRtpDumpHandler::PACKET_TYPE_BOTH
|
| + : (incoming ? WebRtcRtpDumpHandler::PACKET_TYPE_INCOMING_ONLY
|
| + : WebRtcRtpDumpHandler::PACKET_TYPE_OUTGOING_ONLY);
|
| +
|
| + bool result = rtp_dump_handler_->StartDump(type, &error);
|
| + FireGenericDoneCallback(callback, result, error);
|
| +}
|
| +
|
| +void WebRtcLoggingHandlerHost::DoUploadLogAndDumps(
|
| + const base::FilePath& log_directory,
|
| + const WebRtcRtpDumpHandler::ReleasedDumps& rtp_dumps) {
|
| WebRtcLogUploadDoneData upload_done_data;
|
| upload_done_data.log_path = log_directory;
|
| +
|
| + if (!rtp_dumps.incoming_dump_path.empty()) {
|
| + upload_done_data.rtp_dumps.push_back(
|
| + WebRtcRtpDumpDescription("rtpdump_recv", rtp_dumps.incoming_dump_path));
|
| + }
|
| +
|
| + if (!rtp_dumps.outgoing_dump_path.empty()) {
|
| + upload_done_data.rtp_dumps.push_back(
|
| + WebRtcRtpDumpDescription("rtpdump_send", rtp_dumps.outgoing_dump_path));
|
| + }
|
| +
|
| upload_done_data.callback = upload_callback_;
|
| upload_done_data.host = this;
|
| upload_callback_.Reset();
|
| @@ -474,14 +611,3 @@ void WebRtcLoggingHandlerHost::TriggerUploadLog(
|
| meta_data_.clear();
|
| circular_buffer_.reset();
|
| }
|
| -
|
| -void WebRtcLoggingHandlerHost::FireGenericDoneCallback(
|
| - GenericDoneCallback* callback, bool success,
|
| - const std::string& error_message) {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| - DCHECK(!(*callback).is_null());
|
| - content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
|
| - base::Bind(*callback, success,
|
| - error_message));
|
| - (*callback).Reset();
|
| -}
|
|
|