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_WRITER_H_ | |
| 6 #define CHROME_BROWSER_MEDIA_WEBRTC_RTP_DUMP_WRITER_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 "base/threading/thread_checker.h" | |
| 13 #include "base/time/time.h" | |
| 14 | |
| 15 // This class is responsible for creating the compressed RTP header dump file: | |
| 16 // - Adds the RTP headers to an in-memory buffer. | |
| 17 // - When the in-memory buffer is full, compresses it, and writes it to the | |
| 18 // disk. Drop the packet and notifies the client if the max file size is | |
| 19 // reached. | |
| 20 // - The uncompressed dump follows the standard RTPPlay format | |
| 21 // (http://www.cs.columbia.edu/irt/software/rtptools/). | |
| 22 // - The caller is always responsible for cleaning up the dump file in all | |
| 23 // cases. | |
| 24 // - WebRtcRtpDumpWriter does not stop writing to the dump after the max size | |
| 25 // limit is reached. The caller must stop calling WriteRtpPacket instead. | |
| 26 // | |
| 27 // This object must run on the IO thread. | |
| 28 class WebRtcRtpDumpWriter { | |
| 29 public: | |
| 30 typedef base::Callback<void(bool)> EndDumpCallback; | |
| 31 | |
| 32 // Returns the header length of the RTP packet. | |
| 33 static size_t GetRtpHeaderLen(const uint8* packet, size_t length); | |
| 34 | |
| 35 // |dump_path| is the file path of the compressed dump file. |max_dump_size| | |
| 36 // is the max size of the compressed dump file in bytes. | |
| 37 // |max_dump_size_reached_callback| will be called when the on-disk file size | |
| 38 // reaches |max_dump_size|. | |
| 39 WebRtcRtpDumpWriter(const base::FilePath& incoming_dump_path, | |
|
Henrik Grunell
2014/05/14 12:14:12
I think this class should handle one dump only and
jiayl
2014/05/14 18:59:12
See my other reply about max size limit.
| |
| 40 const base::FilePath& outgoing_dump_path, | |
| 41 size_t max_dump_size, | |
| 42 const base::Closure& max_dump_size_reached_callback); | |
| 43 | |
| 44 virtual ~WebRtcRtpDumpWriter(); | |
| 45 | |
| 46 // Adds a RTP packet to the dump. The caller must make sure it's a valid RTP | |
| 47 // packet. No validation is done by this method. | |
| 48 virtual void WriteRtpPacket(const uint8* packet_header, | |
| 49 size_t header_length, | |
| 50 size_t packet_length, | |
| 51 bool incoming); | |
| 52 | |
| 53 // Flushes the in-memory buffer to the disk and ends the dump. | |
| 54 // |finished_callback| will be called to indicate whether the dump is valid. | |
| 55 // If this object is destroyed before the operation is finished, the callback | |
| 56 // will be canceled and the dump files will be deleted. | |
| 57 virtual void EndDump(bool incoming, const EndDumpCallback& finished_callback); | |
| 58 | |
| 59 size_t max_dump_size() const { return max_dump_size_; } | |
| 60 | |
| 61 private: | |
| 62 enum FlushResult { | |
| 63 // Flushing has succeeded and the dump size is under the max limit. | |
| 64 FLUSH_RESULT_SUCCESS, | |
| 65 // Nothing has been written to disk and the dump is empty. | |
| 66 FLUSH_RESULT_NO_DATA, | |
| 67 // Flushing has failed for other reasons. | |
| 68 FLUSH_RESULT_FAILURE | |
| 69 }; | |
| 70 | |
| 71 class FileThreadWorker; | |
| 72 | |
| 73 static bool FlushResultToDumpValidity(FlushResult); | |
| 74 | |
| 75 void FlushBuffer(bool incoming, | |
| 76 bool end_stream, | |
| 77 const EndDumpCallback& callback); | |
| 78 | |
| 79 void OnFlushDone(const EndDumpCallback& callback, | |
| 80 const scoped_ptr<FlushResult>& result, | |
| 81 const scoped_ptr<size_t>& bytes_written); | |
| 82 | |
| 83 const size_t max_dump_size_; | |
| 84 const base::Closure max_dump_size_reached_callback_; | |
| 85 | |
| 86 std::vector<uint8> incoming_buffer_; | |
| 87 std::vector<uint8> outgoing_buffer_; | |
| 88 base::TimeTicks start_time_; | |
| 89 size_t total_dump_size_on_disk_; | |
| 90 | |
| 91 // File thread workers must be called and deleted on the FILE thread. | |
| 92 scoped_ptr<FileThreadWorker> incoming_file_thread_worker_; | |
| 93 scoped_ptr<FileThreadWorker> outgoing_file_thread_worker_; | |
| 94 | |
| 95 base::ThreadChecker thread_checker_; | |
| 96 | |
| 97 base::WeakPtrFactory<WebRtcRtpDumpWriter> weak_ptr_factory_; | |
| 98 | |
| 99 DISALLOW_COPY_AND_ASSIGN(WebRtcRtpDumpWriter); | |
| 100 }; | |
| 101 | |
| 102 #endif // CHROME_BROWSER_MEDIA_WEBRTC_RTP_DUMP_WRITER_H_ | |
| OLD | NEW |