| Index: chrome/browser/media/webrtc_rtp_dump_handler.h
|
| diff --git a/chrome/browser/media/webrtc_rtp_dump_handler.h b/chrome/browser/media/webrtc_rtp_dump_handler.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..a382ddc76814ad72e5e0c107e3345806f8752209
|
| --- /dev/null
|
| +++ b/chrome/browser/media/webrtc_rtp_dump_handler.h
|
| @@ -0,0 +1,118 @@
|
| +// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#ifndef CHROME_BROWSER_MEDIA_WEBRTC_RTP_DUMP_HANDLER_H_
|
| +#define CHROME_BROWSER_MEDIA_WEBRTC_RTP_DUMP_HANDLER_H_
|
| +
|
| +#include "base/basictypes.h"
|
| +#include "base/callback.h"
|
| +#include "base/files/file_path.h"
|
| +
|
| +namespace base {
|
| +class FilePath;
|
| +} // namespace base
|
| +
|
| +class WebRtcRtpDumpWriter;
|
| +
|
| +// WebRtcRtpDumpHandler handles operations regarding the WebRTC RTP dump:
|
| +// - Starts or stops the RTP dumping on behalf of the client.
|
| +// - Stops the RTP dumping when the max dump file size is reached.
|
| +// - Writes the dump file.
|
| +// - Provides the dump file to the client code to be uploaded when
|
| +// ReleaseRtpDump is called.
|
| +// - Cleans up the dump file is not transferred to the client before the object
|
| +// is destroyed.
|
| +//
|
| +// Must be created/used/destroyed on the IO thread.
|
| +class WebRtcRtpDumpHandler {
|
| + public:
|
| + struct PacketType {
|
| + PacketType(bool incoming, bool outgoing)
|
| + : incoming(incoming), outgoing(outgoing) {}
|
| +
|
| + bool incoming;
|
| + bool outgoing;
|
| + };
|
| +
|
| + struct ReleasedDumps {
|
| + ReleasedDumps() {}
|
| +
|
| + base::FilePath incoming_dump_path;
|
| + base::FilePath outgoing_dump_path;
|
| + };
|
| +
|
| + typedef base::Callback<void(const ReleasedDumps& dumps)> ReleaseDumpCallback;
|
| +
|
| + // The caller must make sure |dump_dir| exists. RTP dump files are saved under
|
| + // |dump_dir| as "rtpdump_$DIRECTION_$TIMESTAMP.gz", where $DIRECTION is
|
| + // 'send' for outgoing dump or 'recv' for incoming dump. $TIMESTAMP is the
|
| + // dump started time converted to a double number in microsecond precision,
|
| + // which should guarantee the uniqueness across tabs and dump streams in
|
| + // practice.
|
| + explicit WebRtcRtpDumpHandler(const base::FilePath& dump_dir);
|
| + virtual ~WebRtcRtpDumpHandler();
|
| +
|
| + // Incoming/outgoing dumping can be started separately. Returns true if called
|
| + // in a valid state, i.e.
|
| + // - if type.incoming == true, incoming dumping has not been started, and
|
| + // outgoing dumping is not started or ongoing, returns true.
|
| + // - if type.outgoing == true, outgoing dumping has not been started, and
|
| + // incoming dumping is not started or ongoing, returns true.
|
| + // - returns false in all other cases.
|
| + bool StartDump(const PacketType& type);
|
| +
|
| + // Incoming/outgoing dumping can be stopped separately. Returns true if called
|
| + // in a valid state, i.e. dumping has been started and not stopped for any
|
| + // type specified in |type|.
|
| + bool StopDump(const PacketType& type);
|
| +
|
| + // It should only be called when both incoming and outgoing dumping has been
|
| + // stopped. Returns true if it's called in a valid state and the callback will
|
| + // be called when it finishes writing the dump file.
|
| + //
|
| + // The caller will own the dump file after the callback is called with a
|
| + // non-empty dump path. If ReleaseDump returns false or the callback has not
|
| + // happened before this object goes away or the callback is called with an
|
| + // empty dump path, the dump file will be deleted by this object.
|
| + bool ReleaseDump(const ReleaseDumpCallback& callback);
|
| +
|
| + // Adds a RTP packet to the dump. The caller must make sure it's a valid RTP
|
| + // packet.
|
| + void OnRtpPacket(const uint8* packet_header,
|
| + size_t header_length,
|
| + size_t packet_length,
|
| + bool incoming);
|
| +
|
| + // For mocking the dump writer in unit tests.
|
| + void SetDumpWriterForTesting(scoped_ptr<WebRtcRtpDumpWriter> writer);
|
| +
|
| + private:
|
| + // State transitions:
|
| + // initial --> STATE_NONE
|
| + // StartDump --> STATE_STARTED
|
| + // StopDump --> STATE_STOPPED
|
| + // ReleaseDump --> STATE_RELEASING
|
| + // ReleaseDump done --> STATE_NONE
|
| + enum State {
|
| + STATE_NONE,
|
| + STATE_STARTED,
|
| + STATE_STOPPED,
|
| + STATE_RELEASING,
|
| + };
|
| +
|
| + // Callbacks from the dump writer.
|
| + void OnMaxDumpSizeReached();
|
| + void OnDumpEnded(const ReleaseDumpCallback& callback, bool succeeded);
|
| +
|
| + base::FilePath dump_dir_;
|
| + base::FilePath incoming_dump_path_;
|
| + base::FilePath outgoing_dump_path_;
|
| + State incoming_state_;
|
| + State outgoing_state_;
|
| + scoped_ptr<WebRtcRtpDumpWriter> dump_writer_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(WebRtcRtpDumpHandler);
|
| +};
|
| +
|
| +#endif // CHROME_BROWSER_MEDIA_WEBRTC_RTP_DUMP_HANDLER_H_
|
|
|