Index: chrome/browser/media/webrtc_rtp_dump_writer.h |
diff --git a/chrome/browser/media/webrtc_rtp_dump_writer.h b/chrome/browser/media/webrtc_rtp_dump_writer.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..813489b6d8a7f0fa600d06e0a511078043200a85 |
--- /dev/null |
+++ b/chrome/browser/media/webrtc_rtp_dump_writer.h |
@@ -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. |
+ |
+#ifndef CHROME_BROWSER_MEDIA_WEBRTC_RTP_DUMP_WRITER_H_ |
+#define CHROME_BROWSER_MEDIA_WEBRTC_RTP_DUMP_WRITER_H_ |
+ |
+#include "base/basictypes.h" |
+#include "base/callback.h" |
+#include "base/files/file_path.h" |
+#include "base/memory/weak_ptr.h" |
+#include "base/threading/thread_checker.h" |
+#include "base/time/time.h" |
+ |
+// This class is responsible for creating the compressed RTP header dump file: |
+// - Adds the RTP headers to an in-memory buffer. |
+// - When the in-memory buffer is full, compresses it, and writes it to the |
+// disk. Drop the packet and notifies the client if the max file size is |
+// reached. |
+// - The uncompressed dump follows the standard RTPPlay format |
+// (http://www.cs.columbia.edu/irt/software/rtptools/). |
+// - The caller is always responsible for cleaning up the dump file in all |
+// cases. |
+// - WebRtcRtpDumpWriter does not stop writing to the dump after the max size |
+// limit is reached. The caller must stop calling WriteRtpPacket instead. |
+// |
+// This object must run on the IO thread. |
+class WebRtcRtpDumpWriter { |
+ public: |
+ typedef base::Callback<void(bool)> EndDumpCallback; |
+ |
+ // Returns the header length of the RTP packet. |
+ static size_t GetRtpHeaderLen(const uint8* packet, size_t length); |
+ |
+ // |dump_path| is the file path of the compressed dump file. |max_dump_size| |
+ // is the max size of the compressed dump file in bytes. |
+ // |max_dump_size_reached_callback| will be called when the on-disk file size |
+ // reaches |max_dump_size|. |
+ WebRtcRtpDumpWriter(const base::FilePath& incoming_dump_path, |
Henrik Grunell
2014/05/14 12:14:12
I think this class should handle one dump only and
jiayl
2014/05/14 18:59:12
See my other reply about max size limit.
|
+ const base::FilePath& outgoing_dump_path, |
+ size_t max_dump_size, |
+ const base::Closure& max_dump_size_reached_callback); |
+ |
+ virtual ~WebRtcRtpDumpWriter(); |
+ |
+ // Adds a RTP packet to the dump. The caller must make sure it's a valid RTP |
+ // packet. No validation is done by this method. |
+ virtual void WriteRtpPacket(const uint8* packet_header, |
+ size_t header_length, |
+ size_t packet_length, |
+ bool incoming); |
+ |
+ // Flushes the in-memory buffer to the disk and ends the dump. |
+ // |finished_callback| will be called to indicate whether the dump is valid. |
+ // If this object is destroyed before the operation is finished, the callback |
+ // will be canceled and the dump files will be deleted. |
+ virtual void EndDump(bool incoming, const EndDumpCallback& finished_callback); |
+ |
+ size_t max_dump_size() const { return max_dump_size_; } |
+ |
+ private: |
+ enum FlushResult { |
+ // Flushing has succeeded and the dump size is under the max limit. |
+ FLUSH_RESULT_SUCCESS, |
+ // Nothing has been written to disk and the dump is empty. |
+ FLUSH_RESULT_NO_DATA, |
+ // Flushing has failed for other reasons. |
+ FLUSH_RESULT_FAILURE |
+ }; |
+ |
+ class FileThreadWorker; |
+ |
+ static bool FlushResultToDumpValidity(FlushResult); |
+ |
+ void FlushBuffer(bool incoming, |
+ bool end_stream, |
+ const EndDumpCallback& callback); |
+ |
+ void OnFlushDone(const EndDumpCallback& callback, |
+ const scoped_ptr<FlushResult>& result, |
+ const scoped_ptr<size_t>& bytes_written); |
+ |
+ const size_t max_dump_size_; |
+ const base::Closure max_dump_size_reached_callback_; |
+ |
+ std::vector<uint8> incoming_buffer_; |
+ std::vector<uint8> outgoing_buffer_; |
+ base::TimeTicks start_time_; |
+ size_t total_dump_size_on_disk_; |
+ |
+ // File thread workers must be called and deleted on the FILE thread. |
+ scoped_ptr<FileThreadWorker> incoming_file_thread_worker_; |
+ scoped_ptr<FileThreadWorker> outgoing_file_thread_worker_; |
+ |
+ base::ThreadChecker thread_checker_; |
+ |
+ base::WeakPtrFactory<WebRtcRtpDumpWriter> weak_ptr_factory_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(WebRtcRtpDumpWriter); |
+}; |
+ |
+#endif // CHROME_BROWSER_MEDIA_WEBRTC_RTP_DUMP_WRITER_H_ |