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

Side by Side 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, 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_HANDLER_H_
6 #define CHROME_BROWSER_MEDIA_WEBRTC_RTP_DUMP_HANDLER_H_
7
8 #include "base/basictypes.h"
9 #include "base/callback.h"
10 #include "base/files/file_path.h"
11
12 namespace base {
13 class FilePath;
14 } // namespace base
15
16 class WebRtcRtpDumpWriter;
17
18 // WebRtcRtpDumpHandler handles operations regarding the WebRTC RTP dump:
19 // - Starts or stops the RTP dumping on behalf of the client.
20 // - Stops the RTP dumping when the max dump file size is reached.
21 // - Writes the dump file.
22 // - Provides the dump file to the client code to be uploaded when
23 // ReleaseRtpDump is called.
24 // - Cleans up the dump file is not transferred to the client before the object
25 // is destroyed.
26 //
27 // Must be created/used/destroyed on the IO thread.
28 class WebRtcRtpDumpHandler {
29 public:
30 struct PacketType {
31 PacketType(bool incoming, bool outgoing)
32 : incoming(incoming), outgoing(outgoing) {}
33
34 bool incoming;
35 bool outgoing;
36 };
37
38 struct ReleasedDumps {
39 ReleasedDumps() {}
40
41 base::FilePath incoming_dump_path;
42 base::FilePath outgoing_dump_path;
43 };
44
45 typedef base::Callback<void(const ReleasedDumps& dumps)> ReleaseDumpCallback;
46
47 // The caller must make sure |dump_dir| exists. RTP dump files are saved under
48 // |dump_dir| as "rtpdump_$DIRECTION_$TIMESTAMP.gz", where $DIRECTION is
49 // 'send' for outgoing dump or 'recv' for incoming dump. $TIMESTAMP is the
50 // dump started time converted to a double number in microsecond precision,
51 // which should guarantee the uniqueness across tabs and dump streams in
52 // practice.
53 explicit WebRtcRtpDumpHandler(const base::FilePath& dump_dir);
54 virtual ~WebRtcRtpDumpHandler();
55
56 // Incoming/outgoing dumping can be started separately. Returns true if called
57 // in a valid state, i.e.
58 // - if type.incoming == true, incoming dumping has not been started, and
59 // outgoing dumping is not started or ongoing, returns true.
60 // - if type.outgoing == true, outgoing dumping has not been started, and
61 // incoming dumping is not started or ongoing, returns true.
62 // - returns false in all other cases.
63 bool StartDump(const PacketType& type);
64
65 // Incoming/outgoing dumping can be stopped separately. Returns true if called
66 // in a valid state, i.e. dumping has been started and not stopped for any
67 // type specified in |type|.
68 bool StopDump(const PacketType& type);
69
70 // It should only be called when both incoming and outgoing dumping has been
71 // stopped. Returns true if it's called in a valid state and the callback will
72 // be called when it finishes writing the dump file.
73 //
74 // The caller will own the dump file after the callback is called with a
75 // non-empty dump path. If ReleaseDump returns false or the callback has not
76 // happened before this object goes away or the callback is called with an
77 // empty dump path, the dump file will be deleted by this object.
78 bool ReleaseDump(const ReleaseDumpCallback& callback);
79
80 // Adds a RTP packet to the dump. The caller must make sure it's a valid RTP
81 // packet.
82 void OnRtpPacket(const uint8* packet_header,
83 size_t header_length,
84 size_t packet_length,
85 bool incoming);
86
87 // For mocking the dump writer in unit tests.
88 void SetDumpWriterForTesting(scoped_ptr<WebRtcRtpDumpWriter> writer);
89
90 private:
91 // State transitions:
92 // initial --> STATE_NONE
93 // StartDump --> STATE_STARTED
94 // StopDump --> STATE_STOPPED
95 // ReleaseDump --> STATE_RELEASING
96 // ReleaseDump done --> STATE_NONE
97 enum State {
98 STATE_NONE,
99 STATE_STARTED,
100 STATE_STOPPED,
101 STATE_RELEASING,
102 };
103
104 // Callbacks from the dump writer.
105 void OnMaxDumpSizeReached();
106 void OnDumpEnded(const ReleaseDumpCallback& callback, bool succeeded);
107
108 base::FilePath dump_dir_;
109 base::FilePath incoming_dump_path_;
110 base::FilePath outgoing_dump_path_;
111 State incoming_state_;
112 State outgoing_state_;
113 scoped_ptr<WebRtcRtpDumpWriter> dump_writer_;
114
115 DISALLOW_COPY_AND_ASSIGN(WebRtcRtpDumpHandler);
116 };
117
118 #endif // CHROME_BROWSER_MEDIA_WEBRTC_RTP_DUMP_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698