Chromium Code Reviews

Side by Side Diff: chrome/browser/media/webrtc_rtp_dump_writer.h

Issue 264793017: Implements RTP header dumping. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add WebRtcRtpDumpWriter Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_MEDIA_WEBRTC_RTP_DUMP_WRITER_H_
6 #define CHROME_BROWSER_MEDIA_WEBRTC_RTP_DUMP_WRITER_H_
7
8 #include "base/basictypes.h"
9 #include "base/callback.h"
10 #include "base/files/file_path.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/time/time.h"
13
14 namespace base {
15 class File;
16 } // namespace base
17
18 // This class is responsible for creating the compressed RTP header dump file:
19 // - Adds the RTP headers to an in-memory buffer.
20 // - When the in-memory buffer is full, compresses it, and writes it to the
21 // disk. Drop the packet and notifies the client if the max file size is
22 // reached.
23 // - The uncompressed dump follows the standard RTPPlay format
24 // (http://www.cs.columbia.edu/irt/software/rtptools/).
25 // - The caller is responsible for cleaning up the dump file.
26 //
27 // 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
28 class WebRtcRtpDumpWriter {
29 public:
30 // |dump_path| is the file path of the compressed dump file. |max_dump_size|
31 // is the max size of the compressed dump file in bytes.
32 // |max_dump_size_reached_callback| will be called when the on-disk file size
33 // reaches |max_dump_size|.
34 WebRtcRtpDumpWriter(const base::FilePath& dump_path,
35 size_t max_dump_size,
36 const base::Closure& max_dump_size_reached_callback);
37 ~WebRtcRtpDumpWriter();
38
39 // Adds a RTP packet to the dump. The caller must make sure it's a valid RTP
40 // packet. No validation is done by this method.
41 void WriteRtpPacket(const uint8* packet, size_t length);
42
43 // Flushes the in-memory buffer to the disk. |finished_callback| will be
44 // called to indicate whether the operation has succeeded, if the operation
45 // is finished before this object is destroyed.
46 void Flush(const base::Callback<void(bool)>& finished_callback);
47
48 private:
49 static void CompressAndWriteToFileOnFileThread(
50 const scoped_ptr<std::vector<uint8>>& buffer,
51 const base::FilePath& dump_path,
52 bool* result);
53
54 void OnFlushDone(const base::Callback<void(bool)>& callback,
55 const scoped_ptr<bool>& result);
56
57 // All data members should be accessed on the IO thread only, except that
58 // |dump_| should be deleted on the FILE thread.
59
60 base::FilePath dump_path_;
61 size_t max_dump_size_;
62 base::Closure max_dump_size_reached_callback_;
63
64 std::vector<uint8> buffer_;
65 base::TimeTicks start_time_;
66 base::WeakPtrFactory<WebRtcRtpDumpWriter> weak_ptr_factory_;
67
68 DISALLOW_COPY_AND_ASSIGN(WebRtcRtpDumpWriter);
69 };
70
71 #endif // CHROME_BROWSER_MEDIA_WEBRTC_RTP_DUMP_WRITER_H_
OLDNEW

Powered by Google App Engine