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

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: for Henrik's comments Created 6 years, 7 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 unified diff | Download patch
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/threading/thread_checker.h"
13 #include "base/time/time.h"
14 #include "chrome/browser/media/rtp_dump_type.h"
15
16 // This class is responsible for creating the compressed RTP header dump file:
17 // - Adds the RTP headers to an in-memory buffer.
18 // - When the in-memory buffer is full, compresses it, and writes it to the
19 // disk.
20 // - Notifies the caller when the on-disk file size reaches the max limit.
21 // - The uncompressed dump follows the standard RTPPlay format
22 // (http://www.cs.columbia.edu/irt/software/rtptools/).
23 // - The caller is always responsible for cleaning up the dump file in all
24 // cases.
25 // - WebRtcRtpDumpWriter does not stop writing to the dump after the max size
26 // limit is reached. The caller must stop calling WriteRtpPacket instead.
27 //
28 // This object must run on the IO thread.
29 class WebRtcRtpDumpWriter {
30 public:
31 typedef base::Callback<void(bool incoming_succeeded, bool outgoing_succeeded)>
32 EndDumpCallback;
33
34 // |incoming_dump_path| and |outgoing_dump_path| are the file paths of the
35 // compressed dump files for incoming and outgoing packets respectively.
36 // |max_dump_size| is the max size of the compressed dump file in bytes.
37 // |max_dump_size_reached_callback| will be called when the on-disk file size
38 // reaches |max_dump_size|.
39 WebRtcRtpDumpWriter(const base::FilePath& incoming_dump_path,
40 const base::FilePath& outgoing_dump_path,
41 size_t max_dump_size,
42 const base::Closure& max_dump_size_reached_callback);
43
44 virtual ~WebRtcRtpDumpWriter();
45
46 // Adds a RTP packet to the dump. The caller must make sure it's a valid RTP
47 // packet. No validation is done by this method.
48 virtual void WriteRtpPacket(const uint8* packet_header,
49 size_t header_length,
50 size_t packet_length,
51 bool incoming);
52
53 // Flushes the in-memory buffer to the disk and ends the dump. Ignored if the
54 // dumps are already ended.
55 // |finished_callback| will be called to indicate whether the dump is valid.
56 // If this object is destroyed before the operation is finished, the callback
57 // will be canceled and the dump files will be deleted.
58 virtual void EndDump(RtpDumpType type,
59 const EndDumpCallback& finished_callback);
60
61 size_t max_dump_size() const;
62
63 private:
64 enum FlushResult {
65 // Flushing has succeeded and the dump size is under the max limit.
66 FLUSH_RESULT_SUCCESS,
67 // Nothing has been written to disk and the dump is empty.
68 FLUSH_RESULT_NO_DATA,
69 // Flushing has failed for other reasons.
70 FLUSH_RESULT_FAILURE
71 };
72
73 class FileThreadWorker;
74
75 typedef base::Callback<void(bool)> FlushDoneCallback;
76
77 struct EndDumpContext {
78 EndDumpContext(RtpDumpType type, const EndDumpCallback& callback);
79 ~EndDumpContext();
80
81 RtpDumpType type;
82 bool incoming_succeeded;
83 bool outgoing_succeeded;
84 EndDumpCallback callback;
85 };
86
87 void FlushBuffer(bool incoming,
88 bool end_stream,
89 const FlushDoneCallback& callback);
90
91 void OnFlushDone(const FlushDoneCallback& callback,
92 const scoped_ptr<FlushResult>& result,
93 const scoped_ptr<size_t>& bytes_written);
94
95 void OnDumpEnded(EndDumpContext context, bool incoming, bool success);
96
97 // The max limit on the total size of incoming and outgoing dumps on disk.
98 const size_t max_dump_size_;
99
100 // The callback to call when the max size limit is reached.
101 const base::Closure max_dump_size_reached_callback_;
102
103 // The in-memory buffers for the uncompressed dumps.
104 std::vector<uint8> incoming_buffer_;
105 std::vector<uint8> outgoing_buffer_;
106
107 // The time when the first packet is dumped.
108 base::TimeTicks start_time_;
109
110 // The total on-disk size of the compressed incoming and outgoing dumps.
111 size_t total_dump_size_on_disk_;
112
113 // File thread workers must be called and deleted on the FILE thread.
114 scoped_ptr<FileThreadWorker> incoming_file_thread_worker_;
115 scoped_ptr<FileThreadWorker> outgoing_file_thread_worker_;
116
117 base::ThreadChecker thread_checker_;
118
119 base::WeakPtrFactory<WebRtcRtpDumpWriter> weak_ptr_factory_;
120
121 DISALLOW_COPY_AND_ASSIGN(WebRtcRtpDumpWriter);
122 };
123
124 #endif // CHROME_BROWSER_MEDIA_WEBRTC_RTP_DUMP_WRITER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698