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 52567c4ab628008a71517f652fab2b00cccb80cc..08bb553d92ea005b7a5e68aff6ed129280c42a8f 100644 |
--- a/chrome/browser/media/webrtc_logging_handler_host.cc |
+++ b/chrome/browser/media/webrtc_logging_handler_host.cc |
@@ -19,6 +19,8 @@ |
#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/media/webrtc_rtp_dump_writer.h" |
#include "chrome/browser/profiles/profile.h" |
#include "chrome/common/chrome_switches.h" |
#include "chrome/common/media/webrtc_logging_messages.h" |
@@ -48,15 +50,14 @@ |
using base::IntToString; |
using content::BrowserThread; |
+namespace { |
#if defined(OS_ANDROID) |
const size_t kWebRtcLogSize = 1 * 1024 * 1024; // 1 MB |
#else |
-const size_t kWebRtcLogSize = 6 * 1024 * 1024; // 6 MB |
+const size_t kWebRtcLogSize = 4 * 1024 * 1024; // 4 MB |
Henrik Grunell
2014/05/13 09:12:31
What's the rationale for decreasing this?
jiayl
2014/05/13 21:48:17
The max upload size including log and dumps is 10,
Henrik Grunell
2014/05/14 12:14:12
OK.
|
#endif |
-namespace { |
- |
const char kLogNotStoppedOrNoLogOpen[] = |
"Logging not stopped or no log open."; |
@@ -190,7 +191,7 @@ void WebRtcLoggingHandlerHost::UploadLog(const UploadDoneCallback& callback) { |
FROM_HERE, |
base::Bind(&WebRtcLoggingHandlerHost::GetLogDirectoryAndEnsureExists, |
this), |
- base::Bind(&WebRtcLoggingHandlerHost::TriggerUploadLog, this)); |
+ base::Bind(&WebRtcLoggingHandlerHost::TriggerUploadLogAndRtpDump, this)); |
} |
void WebRtcLoggingHandlerHost::UploadLogDone() { |
@@ -212,6 +213,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 +231,81 @@ 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, ""); |
Henrik Grunell
2014/05/13 09:12:31
Add an error message (third argument) for all plac
jiayl
2014/05/13 21:48:17
Done.
|
+ return; |
+ } |
+ |
+ if (!rtp_dump_handler_) { |
+ content::BrowserThread::PostTaskAndReplyWithResult( |
Henrik Grunell
2014/05/13 09:12:31
What happens if there's another call to StartRtpDu
jiayl
2014/05/13 21:48:17
Changed CreateRtpDumpHandlerAndStart to check if r
Henrik Grunell
2014/05/14 12:14:12
So, it's safe to call multiple times?
jiayl
2014/05/14 16:07:58
yes, it's safe.
|
+ content::BrowserThread::FILE, |
+ FROM_HERE, |
+ base::Bind(&WebRtcLoggingHandlerHost::GetLogDirectoryAndEnsureExists, |
+ this), |
+ base::Bind(&WebRtcLoggingHandlerHost::CreateRtpDumpHandlerAndStart, |
+ this, |
+ incoming, |
+ outgoing, |
+ callback)); |
+ return; |
+ } |
+ |
+ WebRtcRtpDumpHandler::PacketType type = {incoming, outgoing}; |
Henrik Grunell
2014/05/13 09:12:31
I think this part should be moved to it's own func
jiayl
2014/05/13 21:48:17
Done.
|
+ bool result = rtp_dump_handler_->StartDump(type); |
+ FireGenericDoneCallback(&start_callback, result, ""); |
} |
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, ""); |
+ return; |
+ } |
+ |
+ WebRtcRtpDumpHandler::PacketType type = {incoming, outgoing}; |
+ bool result = rtp_dump_handler_->StopDump(type); |
+ FireGenericDoneCallback(&stop_callback, result, ""); |
+} |
+ |
+void WebRtcLoggingHandlerHost::OnRtpPacket(const uint8* packet_header, |
Henrik Grunell
2014/05/13 09:12:31
Which thread should this be called on? Thread chec
jiayl
2014/05/13 21:48:17
In practice it called on the browser UI thread. Si
|
+ 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_) { |
Henrik Grunell
2014/05/13 09:12:31
Is |rtp_dump_handler_| expected to be NULL sometim
jiayl
2014/05/13 21:48:17
The call is triggered by P2PSocketHost, which live
Henrik Grunell
2014/05/14 12:14:12
This sounds dangerous. Do you mean it can be a rac
jiayl
2014/05/14 16:07:58
There is no race in the impl. What I mean is that
|
+ rtp_dump_handler_->OnRtpPacket( |
+ packet_header.get(), header_length, packet_length, incoming); |
+ } |
} |
void WebRtcLoggingHandlerHost::OnChannelClosing() { |
@@ -250,7 +319,8 @@ void WebRtcLoggingHandlerHost::OnChannelClosing() { |
FROM_HERE, |
base::Bind(&WebRtcLoggingHandlerHost::GetLogDirectoryAndEnsureExists, |
this), |
- base::Bind(&WebRtcLoggingHandlerHost::TriggerUploadLog, this)); |
+ base::Bind(&WebRtcLoggingHandlerHost::TriggerUploadLogAndRtpDump, |
+ this)); |
} else { |
g_browser_process->webrtc_log_uploader()->LoggingStoppedDontUpload(); |
} |
@@ -448,13 +518,61 @@ base::FilePath WebRtcLoggingHandlerHost::GetLogDirectoryAndEnsureExists() { |
return log_dir_path; |
} |
-void WebRtcLoggingHandlerHost::TriggerUploadLog( |
+void WebRtcLoggingHandlerHost::TriggerUploadLogAndRtpDump( |
const base::FilePath& log_directory) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
DCHECK_EQ(logging_state_, UPLOADING); |
+ if (rtp_dump_handler_ && |
Henrik Grunell
2014/05/13 09:12:31
Same here, can it be NULL?
jiayl
2014/05/13 21:48:17
It can be NULL if rtp dump is never started.
|
+ rtp_dump_handler_->ReleaseDump(base::Bind( |
Henrik Grunell
2014/05/13 09:12:31
So the dump handler will call DoUpload in ReleaseD
jiayl
2014/05/13 21:48:17
Now Refactored to end the dump on StopDump. So Rel
|
+ &WebRtcLoggingHandlerHost::DoUpload, this, log_directory))) { |
+ return; |
+ } |
+ |
+ DoUpload(log_directory, WebRtcRtpDumpHandler::ReleasedDumps()); |
+} |
+ |
+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)); |
+ DCHECK(!rtp_dump_handler_); |
+ |
+ rtp_dump_handler_.reset(new WebRtcRtpDumpHandler(dump_dir)); |
+ |
+ StartRtpDump(incoming, outgoing, callback); |
+} |
+ |
+void WebRtcLoggingHandlerHost::DoUpload( |
+ 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(); |
@@ -470,14 +588,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(); |
-} |