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 #include "third_party/libjingle/source/talk/base/stream.h" | |
| 12 #include "third_party/libjingle/source/talk/media/base/rtpdump.h" | |
| 13 | |
| 14 // An interface for tracking RTP packets. | |
| 15 class WebRtcRtpPacketObserver { | |
| 16 public: | |
| 17 virtual void OnIncomingRtpPacket(const uint8* packet, size_t length) = 0; | |
| 18 virtual void OnOutgoingRtpPacket(const uint8* packet, size_t length) = 0; | |
| 19 }; | |
| 20 | |
| 21 // WebRtcRtpDumpHandler handles operations regarding the WebRTC RTP dump: | |
| 22 // - Adds the RTP headers to an in-memory buffer. | |
| 23 // - When the in-memory buffer is full, compresses it, and writes it to the | |
| 24 // disk. | |
| 25 // - Provides the dump file to the client code to be uploaded when | |
| 26 // ReleaseRtpDump is called. | |
| 27 // All public methods should be called on the IO thread. | |
| 28 class WebRtcRtpDumpHandler : public WebRtcRtpPacketObserver { | |
| 29 public: | |
| 30 struct PacketType { | |
| 31 bool incoming; | |
| 32 bool outgoing; | |
| 33 }; | |
| 34 | |
| 35 typedef base::Callback<void(bool success, const base::FilePath& dump_file)> | |
| 36 ReleaseDumpCallback; | |
| 37 | |
| 38 // The caller must make sure |dump_dir| exists. RTP dump files are saved under | |
| 39 // |dump_dir| as "rtpdump_XXXXX.gz". | |
| 40 explicit WebRtcRtpDumpHandler(const base::FilePath& dump_dir); | |
| 41 virtual ~WebRtcRtpDumpHandler(); | |
| 42 | |
| 43 // Incoming/outgoing dumping can be started separately. Returns true if called | |
| 44 // in a valid state, i.e. dumping has not been started for any type specified | |
| 45 // in |type|. | |
| 46 bool StartDump(const PacketType& type); | |
| 47 | |
| 48 // Incoming/outgoing dumping can be stopped separately. Returns true if called | |
| 49 // in a valid state, i.e. dumping has been started and not stopped for any | |
| 50 // type specified in |type|. | |
| 51 bool StopDump(const PacketType& type); | |
| 52 | |
| 53 // It should only be called when both incoming and outgoing dumping has been | |
| 54 // stopped. Returns true if it's called in a valid state and the callback will | |
| 55 // be called when it finishes writing the dump file. | |
| 56 // If the method returns true, the caller will own the dump file and should | |
| 57 // clean it up from the disk when suitable. Otherwise, the dump will be | |
| 58 // deleted before WebRtcRtpDumpHandler goes away. | |
| 59 bool ReleaseDump(const ReleaseDumpCallback& callback); | |
| 60 | |
| 61 // Implementation of WebRtcRtpPacketObserver. | |
| 62 virtual void OnIncomingRtpPacket(const uint8* packet, size_t length) OVERRIDE; | |
|
Henrik Grunell
2014/05/05 14:38:03
Who will call these?
jiayl
2014/05/05 16:50:56
From the socket classes in content/browser/rendere
Henrik Grunell
2014/05/06 08:34:26
Through RenderProcessHostImpl as for the log messa
| |
| 63 virtual void OnOutgoingRtpPacket(const uint8* packet, size_t length) OVERRIDE; | |
| 64 | |
| 65 private: | |
| 66 // State transitions: | |
| 67 // initial --> STATE_NONE | |
| 68 // StartDump --> STATE_STARTED | |
| 69 // StopDump --> STATE_STOPPED | |
| 70 // ReleaseDump --> STATE_NONE | |
| 71 enum State { | |
| 72 STATE_NONE, | |
| 73 STATE_STARTED, | |
| 74 STATE_STOPPED | |
| 75 }; | |
| 76 | |
| 77 base::FilePath dump_dir_; | |
| 78 base::FilePath dump_path_; | |
| 79 State incoming_state_; | |
| 80 State outgoing_state_; | |
| 81 scoped_ptr<talk_base::FifoBuffer> dump_buffer_; | |
|
Henrik Grunell
2014/05/05 14:38:03
Does it have to be a talk_base::FifoBuffer?
jiayl
2014/05/05 16:50:56
MemoryBufferBase is enough for the use, but it doe
| |
| 82 scoped_ptr<cricket::RtpDumpWriter> dump_writer_; | |
|
Henrik Grunell
2014/05/05 14:38:03
I'm wondering about how large the data can be? We
jiayl
2014/05/05 16:50:56
For 2Mbps video, there are 250 packets/s; for 40kb
| |
| 83 | |
| 84 DISALLOW_COPY_AND_ASSIGN(WebRtcRtpDumpHandler); | |
| 85 }; | |
| 86 | |
| 87 #endif // CHROME_BROWSER_MEDIA_WEBRTC_RTP_DUMP_HANDLER_H_ | |
| OLD | NEW |