Chromium Code Reviews| 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..ea564502d3ecb871c2f2db94c9972766ba764d2b |
| --- /dev/null |
| +++ b/chrome/browser/media/webrtc_rtp_dump_writer.h |
| @@ -0,0 +1,71 @@ |
| +// 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/time/time.h" |
| + |
| +namespace base { |
| +class File; |
| +} // namespace base |
| + |
| +// 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 responsible for cleaning up the dump file. |
| +// |
| +// This object must run on the IO thread. |
|
Henrik Grunell
2014/05/07 09:38:19
You can't write to file on the IO thread, you'll n
|
| +class WebRtcRtpDumpWriter { |
| + public: |
| + // |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& dump_path, |
| + size_t max_dump_size, |
| + const base::Closure& max_dump_size_reached_callback); |
| + ~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. |
| + void WriteRtpPacket(const uint8* packet, size_t length); |
| + |
| + // Flushes the in-memory buffer to the disk. |finished_callback| will be |
| + // called to indicate whether the operation has succeeded, if the operation |
| + // is finished before this object is destroyed. |
| + void Flush(const base::Callback<void(bool)>& finished_callback); |
| + |
| + private: |
| + static void CompressAndWriteToFileOnFileThread( |
| + const scoped_ptr<std::vector<uint8>>& buffer, |
| + const base::FilePath& dump_path, |
| + bool* result); |
| + |
| + void OnFlushDone(const base::Callback<void(bool)>& callback, |
| + const scoped_ptr<bool>& result); |
| + |
| + // All data members should be accessed on the IO thread only, except that |
| + // |dump_| should be deleted on the FILE thread. |
| + |
| + base::FilePath dump_path_; |
| + size_t max_dump_size_; |
| + base::Closure max_dump_size_reached_callback_; |
| + |
| + std::vector<uint8> buffer_; |
| + base::TimeTicks start_time_; |
| + base::WeakPtrFactory<WebRtcRtpDumpWriter> weak_ptr_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(WebRtcRtpDumpWriter); |
| +}; |
| + |
| +#endif // CHROME_BROWSER_MEDIA_WEBRTC_RTP_DUMP_WRITER_H_ |