| Index: chrome/browser/media/webrtc_rtp_dump_handler.cc
|
| diff --git a/chrome/browser/media/webrtc_rtp_dump_handler.cc b/chrome/browser/media/webrtc_rtp_dump_handler.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..f58d2c309c23366e7f017905309d8049a4b01ce0
|
| --- /dev/null
|
| +++ b/chrome/browser/media/webrtc_rtp_dump_handler.cc
|
| @@ -0,0 +1,102 @@
|
| +// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/media/webrtc_rtp_dump_handler.h"
|
| +
|
| +#include "base/logging.h"
|
| +#include "base/strings/string_number_conversions.h"
|
| +#include "base/time/time.h"
|
| +#include "content/public/browser/browser_thread.h"
|
| +
|
| +using content::BrowserThread;
|
| +
|
| +static const size_t kInMemoryBufferSize = 4096;
|
| +
|
| +WebRtcRtpDumpHandler::WebRtcRtpDumpHandler(const base::FilePath& dump_dir)
|
| + : dump_dir_(dump_dir),
|
| + incoming_state_(STATE_NONE),
|
| + outgoing_state_(STATE_NONE) {}
|
| +
|
| +WebRtcRtpDumpHandler::~WebRtcRtpDumpHandler() {}
|
| +
|
| +bool WebRtcRtpDumpHandler::StartDump(const PacketType& type) {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| + bool succeeded = false;
|
| + if (type.incoming && incoming_state_ == STATE_NONE) {
|
| + incoming_state_ = STATE_STARTED;
|
| + succeeded = true;
|
| + }
|
| + if (type.outgoing && outgoing_state_ == STATE_NONE) {
|
| + outgoing_state_ = STATE_STARTED;
|
| + succeeded = true;
|
| + }
|
| +
|
| + if (succeeded && !dump_writer_) {
|
| + static const char kDumpFilePrefix[] = "rtpdump_";
|
| + static const char kDumpFileExtension[] = ".gz";
|
| +
|
| + std::string dump_id = base::DoubleToString(base::Time::Now().ToDoubleT());
|
| + dump_path_ = dump_dir_.AppendASCII(std::string(kDumpFilePrefix) + dump_id)
|
| + .AddExtension(FILE_PATH_LITERAL(kDumpFileExtension));
|
| +
|
| + dump_buffer_.reset(new talk_base::FifoBuffer(kInMemoryBufferSize));
|
| + dump_writer_.reset(new cricket::RtpDumpWriter(dump_buffer_.get()));
|
| + dump_writer_->set_packet_filter(cricket::PF_RTPHEADER);
|
| + }
|
| + return succeeded;
|
| +}
|
| +
|
| +bool WebRtcRtpDumpHandler::StopDump(const PacketType& type) {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| + bool succeeded = false;
|
| + if (type.incoming && incoming_state_ == STATE_STARTED) {
|
| + incoming_state_ = STATE_STOPPED;
|
| + succeeded = true;
|
| + }
|
| + if (type.outgoing && outgoing_state_ == STATE_STARTED) {
|
| + outgoing_state_ = STATE_STOPPED;
|
| + succeeded = true;
|
| + }
|
| + return succeeded;
|
| +}
|
| +
|
| +bool WebRtcRtpDumpHandler::ReleaseDump(const ReleaseDumpCallback& callback) {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| + // All types of dumps must have been stopped or not started.
|
| + if (incoming_state_ == STATE_STARTED ||
|
| + outgoing_state_ == STATE_STARTED ||
|
| + (incoming_state_ == STATE_NONE && outgoing_state_ == STATE_NONE))
|
| + return false;
|
| +
|
| + incoming_state_ = STATE_NONE;
|
| + outgoing_state_ = STATE_NONE;
|
| +
|
| + // TODO: flush the in memory buffer to disk and call |callback|.
|
| +
|
| + dump_writer_.reset();
|
| + dump_buffer_.reset();
|
| +
|
| + return true;
|
| +}
|
| +
|
| +void WebRtcRtpDumpHandler::OnIncomingRtpPacket(const uint8* packet,
|
| + size_t length) {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| + if (incoming_state_ != STATE_STARTED)
|
| + return;
|
| +
|
| + // TODO: check if the buffer is full and compress and flush to disk if so.
|
| + dump_writer_->WriteRtpPacket(packet, length);
|
| +}
|
| +
|
| +void WebRtcRtpDumpHandler::OnOutgoingRtpPacket(const uint8* packet,
|
| + size_t length) {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| + if (outgoing_state_ != STATE_STARTED)
|
| + return;
|
| +
|
| + // TODO: check if the buffer is full and compress and flush to disk if so.
|
| + dump_writer_->WriteRtpPacket(packet, length);
|
| +}
|
| +
|
|
|