Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 if not transferred to the client before the object | |
| 25 // is destroyed. | |
| 26 // | |
| 27 // Must be created/used/destroyed on the IO thread. | |
|
Henrik Grunell
2014/05/14 12:14:12
I think you should have a ThreadChecker or make it
jiayl
2014/05/14 18:59:12
It's a stronger requirement than NonThreadSafe or
| |
| 28 class WebRtcRtpDumpHandler { | |
| 29 public: | |
| 30 typedef base::Callback<void(bool, const std::string&)> GenericDoneCallback; | |
| 31 | |
| 32 struct PacketType { | |
|
Henrik Grunell
2014/05/14 12:14:12
Maybe an enum with three values instead since {fal
jiayl
2014/05/14 18:59:12
Done.
| |
| 33 PacketType() : incoming(false), outgoing(false) {} | |
| 34 PacketType(bool incoming, bool outgoing) | |
| 35 : incoming(incoming), outgoing(outgoing) {} | |
| 36 | |
| 37 bool incoming; | |
| 38 bool outgoing; | |
| 39 }; | |
| 40 | |
| 41 struct ReleasedDumps { | |
| 42 ReleasedDumps() {} | |
| 43 | |
| 44 base::FilePath incoming_dump_path; | |
| 45 base::FilePath outgoing_dump_path; | |
| 46 }; | |
| 47 | |
| 48 // The caller must make sure |dump_dir| exists. RTP dump files are saved under | |
| 49 // |dump_dir| as "rtpdump_$DIRECTION_$TIMESTAMP.gz", where $DIRECTION is | |
| 50 // 'send' for outgoing dump or 'recv' for incoming dump. $TIMESTAMP is the | |
| 51 // dump started time converted to a double number in microsecond precision, | |
| 52 // which should guarantee the uniqueness across tabs and dump streams in | |
| 53 // practice. | |
| 54 explicit WebRtcRtpDumpHandler(const base::FilePath& dump_dir); | |
| 55 virtual ~WebRtcRtpDumpHandler(); | |
| 56 | |
| 57 // Starts the specified type of dumping. Incoming/outgoing dumping can be | |
| 58 // started separately. Returns true if called in a valid state, i.e. | |
| 59 // - if type.incoming == true, incoming dumping has not been started, and | |
| 60 // outgoing dumping is not started or ongoing, returns true. | |
| 61 // - if type.outgoing == true, outgoing dumping has not been started, and | |
| 62 // incoming dumping is not started or ongoing, returns true. | |
| 63 // - returns false in all other cases. | |
| 64 bool StartDump(const PacketType& type, std::string* error_message); | |
| 65 | |
| 66 // Stops the specified type of dumping. Incoming/outgoing dumping can be | |
| 67 // stopped separately. Returns asynchronously through |callback|, where | |
| 68 // |success| is true if StopDump is called in a valid state. | |
| 69 void StopDump(const PacketType& type, const GenericDoneCallback& callback); | |
| 70 | |
| 71 // Releases all the dumps to the caller and resets the state. | |
| 72 // It should only be called when both incoming and outgoing dumping has been | |
| 73 // stopped. Returns the dump file paths if called in a valid state. | |
| 74 // | |
| 75 // The caller will own the dump file after the method returns. If ReleaseDump | |
| 76 // returns false or not called before this object goes away, the dump file | |
| 77 // will be deleted by this object. | |
| 78 ReleasedDumps ReleaseDumps(); | |
| 79 | |
| 80 // Adds an 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 private: | |
| 88 friend class WebRtcRtpDumpHandlerTest; | |
| 89 | |
| 90 // State transitions: | |
| 91 // initial --> STATE_NONE | |
| 92 // StartDump --> STATE_STARTED | |
| 93 // StopDump --> STATE_STOPPED | |
| 94 // ReleaseDump --> STATE_RELEASING | |
| 95 // ReleaseDump done --> STATE_NONE | |
| 96 enum State { | |
| 97 STATE_NONE, | |
| 98 STATE_STARTED, | |
| 99 STATE_STOPPING, | |
| 100 STATE_STOPPED, | |
| 101 }; | |
| 102 | |
| 103 // Callback from the dump writer when the max dump size is reached. | |
| 104 void OnMaxDumpSizeReached(); | |
| 105 | |
| 106 // Callback from the dump writer when ending a dump finishes. Calls the | |
| 107 // |callback| if all types of dump are ended. | |
| 108 void OnDumpEnded(const GenericDoneCallback& callback, | |
| 109 bool incoming, | |
| 110 bool succeeded); | |
| 111 | |
| 112 // For mocking the dump writer in unit tests. | |
| 113 void SetDumpWriterForTesting(scoped_ptr<WebRtcRtpDumpWriter> writer); | |
|
Henrik Grunell
2014/05/14 12:14:12
Can the writer be injected in the constructor inst
jiayl
2014/05/14 18:59:12
It cannot. Because the writer has to be created wi
| |
| 114 | |
| 115 const base::FilePath dump_dir_; | |
|
Henrik Grunell
2014/05/14 12:14:12
Comment all member variables.
jiayl
2014/05/14 18:59:12
Done.
| |
| 116 base::FilePath incoming_dump_path_; | |
| 117 base::FilePath outgoing_dump_path_; | |
| 118 State incoming_state_; | |
| 119 State outgoing_state_; | |
| 120 scoped_ptr<WebRtcRtpDumpWriter> dump_writer_; | |
|
Henrik Grunell
2014/05/14 12:14:12
So there's one writer that for both incoming and o
jiayl
2014/05/14 16:07:58
It'll be more difficult to apply the max dump limi
Henrik Grunell
2014/05/15 14:36:34
I see. And the incoming and outgoing can't be expe
| |
| 121 | |
| 122 DISALLOW_COPY_AND_ASSIGN(WebRtcRtpDumpHandler); | |
| 123 }; | |
| 124 | |
| 125 #endif // CHROME_BROWSER_MEDIA_WEBRTC_RTP_DUMP_HANDLER_H_ | |
| OLD | NEW |