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