Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Unified Diff: chrome/browser/media/webrtc_rtp_dump_handler.h

Issue 264793017: Implements RTP header dumping. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/media/webrtc_rtp_dump_handler.h
diff --git a/chrome/browser/media/webrtc_rtp_dump_handler.h b/chrome/browser/media/webrtc_rtp_dump_handler.h
new file mode 100644
index 0000000000000000000000000000000000000000..b40621d1706ea43bdbe8d08038c1e50bd78f63d6
--- /dev/null
+++ b/chrome/browser/media/webrtc_rtp_dump_handler.h
@@ -0,0 +1,87 @@
+// 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.
+
+#ifndef CHROME_BROWSER_MEDIA_WEBRTC_RTP_DUMP_HANDLER_H_
+#define CHROME_BROWSER_MEDIA_WEBRTC_RTP_DUMP_HANDLER_H_
+
+#include "base/basictypes.h"
+#include "base/callback.h"
+#include "base/files/file_path.h"
+#include "third_party/libjingle/source/talk/base/stream.h"
+#include "third_party/libjingle/source/talk/media/base/rtpdump.h"
+
+// An interface for tracking RTP packets.
+class WebRtcRtpPacketObserver {
+ public:
+ virtual void OnIncomingRtpPacket(const uint8* packet, size_t length) = 0;
+ virtual void OnOutgoingRtpPacket(const uint8* packet, size_t length) = 0;
+};
+
+// WebRtcRtpDumpHandler handles operations regarding the WebRTC RTP dump:
+// - Adds the RTP headers to an in-memory buffer.
+// - When the in-memory buffer is full, compresses it, and writes it to the
+// disk.
+// - Provides the dump file to the client code to be uploaded when
+// ReleaseRtpDump is called.
+// All public methods should be called on the IO thread.
+class WebRtcRtpDumpHandler : public WebRtcRtpPacketObserver {
+ public:
+ struct PacketType {
+ bool incoming;
+ bool outgoing;
+ };
+
+ typedef base::Callback<void(bool success, const base::FilePath& dump_file)>
+ ReleaseDumpCallback;
+
+ // The caller must make sure |dump_dir| exists. RTP dump files are saved under
+ // |dump_dir| as "rtpdump_XXXXX.gz".
+ explicit WebRtcRtpDumpHandler(const base::FilePath& dump_dir);
+ virtual ~WebRtcRtpDumpHandler();
+
+ // Incoming/outgoing dumping can be started separately. Returns true if called
+ // in a valid state, i.e. dumping has not been started for any type specified
+ // in |type|.
+ bool StartDump(const PacketType& type);
+
+ // Incoming/outgoing dumping can be stopped separately. Returns true if called
+ // in a valid state, i.e. dumping has been started and not stopped for any
+ // type specified in |type|.
+ bool StopDump(const PacketType& type);
+
+ // It should only be called when both incoming and outgoing dumping has been
+ // stopped. Returns true if it's called in a valid state and the callback will
+ // be called when it finishes writing the dump file.
+ // If the method returns true, the caller will own the dump file and should
+ // clean it up from the disk when suitable. Otherwise, the dump will be
+ // deleted before WebRtcRtpDumpHandler goes away.
+ bool ReleaseDump(const ReleaseDumpCallback& callback);
+
+ // Implementation of WebRtcRtpPacketObserver.
+ virtual void OnIncomingRtpPacket(const uint8* packet, size_t length) OVERRIDE;
Henrik Grunell 2014/05/05 14:38:03 Who will call these?
jiayl 2014/05/05 16:50:56 From the socket classes in content/browser/rendere
Henrik Grunell 2014/05/06 08:34:26 Through RenderProcessHostImpl as for the log messa
+ virtual void OnOutgoingRtpPacket(const uint8* packet, size_t length) OVERRIDE;
+
+ private:
+ // State transitions:
+ // initial --> STATE_NONE
+ // StartDump --> STATE_STARTED
+ // StopDump --> STATE_STOPPED
+ // ReleaseDump --> STATE_NONE
+ enum State {
+ STATE_NONE,
+ STATE_STARTED,
+ STATE_STOPPED
+ };
+
+ base::FilePath dump_dir_;
+ base::FilePath dump_path_;
+ State incoming_state_;
+ State outgoing_state_;
+ scoped_ptr<talk_base::FifoBuffer> dump_buffer_;
Henrik Grunell 2014/05/05 14:38:03 Does it have to be a talk_base::FifoBuffer?
jiayl 2014/05/05 16:50:56 MemoryBufferBase is enough for the use, but it doe
+ scoped_ptr<cricket::RtpDumpWriter> dump_writer_;
Henrik Grunell 2014/05/05 14:38:03 I'm wondering about how large the data can be? We
jiayl 2014/05/05 16:50:56 For 2Mbps video, there are 250 packets/s; for 40kb
+
+ DISALLOW_COPY_AND_ASSIGN(WebRtcRtpDumpHandler);
+};
+
+#endif // CHROME_BROWSER_MEDIA_WEBRTC_RTP_DUMP_HANDLER_H_

Powered by Google App Engine
This is Rietveld 408576698