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

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 #include "base/memory/weak_ptr.h"
12 #include "chrome/browser/media/rtp_dump_type.h"
13
14 class WebRtcRtpDumpWriter;
15
16 // WebRtcRtpDumpHandler handles operations regarding the WebRTC RTP dump:
17 // - Starts or stops the RTP dumping on behalf of the client.
18 // - Stops the RTP dumping when the max dump file size is reached.
19 // - Writes the dump file.
20 // - Provides the dump file to the client code to be uploaded when
21 // ReleaseRtpDump is called.
22 // - Cleans up the dump file if not transferred to the client before the object
23 // is destroyed.
24 //
25 // Must be created/used/destroyed on the browser IO thread.
26 class WebRtcRtpDumpHandler {
27 public:
28 typedef base::Callback<void(bool, const std::string&)> GenericDoneCallback;
29
30 struct ReleasedDumps {
31 ReleasedDumps(const base::FilePath& incoming_dump,
32 const base::FilePath& outgoing_dump)
33 : incoming_dump_path(incoming_dump),
34 outgoing_dump_path(outgoing_dump) {}
35
36 const base::FilePath incoming_dump_path;
37 const base::FilePath outgoing_dump_path;
38 };
39
40 // The caller must make sure |dump_dir| exists. RTP dump files are saved under
41 // |dump_dir| as "rtpdump_$DIRECTION_$TIMESTAMP.gz", where $DIRECTION is
42 // 'send' for outgoing dump or 'recv' for incoming dump. $TIMESTAMP is the
43 // dump started time converted to a double number in microsecond precision,
44 // which should guarantee the uniqueness across tabs and dump streams in
45 // practice.
46 explicit WebRtcRtpDumpHandler(const base::FilePath& dump_dir);
47 ~WebRtcRtpDumpHandler();
48
49 // Starts the specified type of dumping. Incoming/outgoing dumping can be
50 // started separately. Returns true if called in a valid state, i.e. the
51 // specified type of dump has not been started.
52 bool StartDump(RtpDumpType type, std::string* error_message);
53
54 // Stops the specified type of dumping. Incoming/outgoing dumping can be
55 // stopped separately. Returns asynchronously through |callback|, where
56 // |success| is true if StopDump is called in a valid state. The callback is
57 // called when the writer finishes writing the dumps.
58 void StopDump(RtpDumpType type, const GenericDoneCallback& callback);
59
60 // Releases all the dumps to the caller and resets the state.
61 // It should only be called when both incoming and outgoing dumping has been
62 // stopped. Returns the dump file paths if called in a valid state.
63 //
64 // The caller will own the dump file after the method returns. If ReleaseDump
65 // returns false or not called before this object goes away, the dump file
66 // will be deleted by this object.
67 ReleasedDumps ReleaseDumps();
68
69 // Adds an RTP packet to the dump. The caller must make sure it's a valid RTP
70 // packet.
71 void OnRtpPacket(const uint8* packet_header,
72 size_t header_length,
73 size_t packet_length,
74 bool incoming);
75
76 // Stops all ongoing dumps and call |callback| when finished.
77 void StopOngoingDumps(const base::Closure& callback);
78
79 private:
80 friend class WebRtcRtpDumpHandlerTest;
81
82 // State transitions:
83 // initial --> STATE_NONE
84 // StartDump --> STATE_STARTED
85 // StopDump --> STATE_STOPPED
86 // ReleaseDump --> STATE_RELEASING
87 // ReleaseDump done --> STATE_NONE
88 enum State {
89 STATE_NONE,
90 STATE_STARTED,
91 STATE_STOPPING,
92 STATE_STOPPED,
93 };
94
95 // For unit test to inject a fake writer.
96 void SetDumpWriterForTesting(scoped_ptr<WebRtcRtpDumpWriter> writer);
97
98 // Callback from the dump writer when the max dump size is reached.
99 void OnMaxDumpSizeReached();
100
101 // Callback from the dump writer when ending dumps finishes. Calls |callback|
102 // when finished.
103 void OnDumpEnded(const base::Closure& callback,
104 RtpDumpType ended_type,
105 bool incoming_succeeded,
106 bool outgoing_succeeded);
107
108 // The directory containing the dump files.
109 const base::FilePath dump_dir_;
110
111 // The dump file paths.
112 base::FilePath incoming_dump_path_;
113 base::FilePath outgoing_dump_path_;
114
115 // The states of the incoming and outgoing dump.
116 State incoming_state_;
117 State outgoing_state_;
118
119 // The object used to create and write the dump file.
120 scoped_ptr<WebRtcRtpDumpWriter> dump_writer_;
121
122 base::WeakPtrFactory<WebRtcRtpDumpHandler> weak_ptr_factory_;
123
124 DISALLOW_COPY_AND_ASSIGN(WebRtcRtpDumpHandler);
125 };
126
127 #endif // CHROME_BROWSER_MEDIA_WEBRTC_RTP_DUMP_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698