diff options
author | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-23 22:26:49 +0000 |
---|---|---|
committer | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-23 22:26:49 +0000 |
commit | d6f7b82a32eb60c8d41b9f205d6439e1071055c0 (patch) | |
tree | 0776048834b736b0741edef4467c3083b49ceed4 | |
parent | cec5b64f954504f5c6c95ebd7eec7e8fcfa15c87 (diff) | |
download | chromium_src-d6f7b82a32eb60c8d41b9f205d6439e1071055c0.zip chromium_src-d6f7b82a32eb60c8d41b9f205d6439e1071055c0.tar.gz chromium_src-d6f7b82a32eb60c8d41b9f205d6439e1071055c0.tar.bz2 |
Remove RTP support from chromoting.
RTP was never used by chromoting and we have no plans using this code in the
future.
Also some other minor cleanups.
Review URL: https://chromiumcodereview.appspot.com/10383294
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@138626 0039d316-1c4b-4281-b951-d872f2087c98
23 files changed, 12 insertions, 2071 deletions
diff --git a/remoting/host/simple_host_process.cc b/remoting/host/simple_host_process.cc index 3e2bc2a..58e3c5d 100644 --- a/remoting/host/simple_host_process.cc +++ b/remoting/host/simple_host_process.cc @@ -83,7 +83,6 @@ const char kMaxPortSwitchName[] = "max-port"; const char kVideoSwitchValueVerbatim[] = "verbatim"; const char kVideoSwitchValueZip[] = "zip"; const char kVideoSwitchValueVp8[] = "vp8"; -const char kVideoSwitchValueVp8Rtp[] = "vp8rtp"; } // namespace @@ -365,7 +364,6 @@ int main(int argc, char** argv) { CandidateSessionConfig::CreateDefault()); config->mutable_video_configs()->clear(); - ChannelConfig::TransportType transport = ChannelConfig::TRANSPORT_STREAM; ChannelConfig::Codec codec; if (video_codec == kVideoSwitchValueVerbatim) { codec = ChannelConfig::CODEC_VERBATIM; @@ -373,15 +371,13 @@ int main(int argc, char** argv) { codec = ChannelConfig::CODEC_ZIP; } else if (video_codec == kVideoSwitchValueVp8) { codec = ChannelConfig::CODEC_VP8; - } else if (video_codec == kVideoSwitchValueVp8Rtp) { - transport = ChannelConfig::TRANSPORT_SRTP; - codec = ChannelConfig::CODEC_VP8; } else { LOG(ERROR) << "Unknown video codec: " << video_codec; return 1; } config->mutable_video_configs()->push_back(ChannelConfig( - transport, remoting::protocol::kDefaultStreamVersion, codec)); + ChannelConfig::TRANSPORT_STREAM, + remoting::protocol::kDefaultStreamVersion, codec)); simple_host.set_protocol_config(config.release()); } diff --git a/remoting/protocol/content_description.cc b/remoting/protocol/content_description.cc index 06fd309..c88a362 100644 --- a/remoting/protocol/content_description.cc +++ b/remoting/protocol/content_description.cc @@ -37,8 +37,6 @@ const char kDeprecatedHeightAttr[] = "height"; const char kStreamTransport[] = "stream"; const char kDatagramTransport[] = "datagram"; -const char kSrtpTransport[] = "srtp"; -const char kRtpDtlsTransport[] = "rtp-dtls"; const char kVerbatimCodec[] = "verbatim"; const char kVp8Codec[] = "vp8"; @@ -50,10 +48,6 @@ const char* GetTransportName(ChannelConfig::TransportType type) { return kStreamTransport; case ChannelConfig::TRANSPORT_DATAGRAM: return kDatagramTransport; - case ChannelConfig::TRANSPORT_SRTP: - return kSrtpTransport; - case ChannelConfig::TRANSPORT_RTP_DTLS: - return kRtpDtlsTransport; } NOTREACHED(); return NULL; @@ -77,7 +71,7 @@ const char* GetCodecName(ChannelConfig::Codec type) { // Format a channel configuration tag for chromotocol session description, // e.g. for video channel: -// <video transport="srtp" version="1" codec="vp8" /> +// <video transport="stream" version="1" codec="vp8" /> XmlElement* FormatChannelConfig(const ChannelConfig& config, const std::string& tag_name) { XmlElement* result = new XmlElement( @@ -103,10 +97,6 @@ bool ParseTransportName(const std::string& value, *transport = ChannelConfig::TRANSPORT_STREAM; } else if (value == kDatagramTransport) { *transport = ChannelConfig::TRANSPORT_DATAGRAM; - } else if (value == kSrtpTransport) { - *transport = ChannelConfig::TRANSPORT_SRTP; - } else if (value == kRtpDtlsTransport) { - *transport = ChannelConfig::TRANSPORT_RTP_DTLS; } else { return false; } @@ -172,7 +162,7 @@ ContentDescription* ContentDescription::Copy() const { // <description xmlns="google:remoting"> // <control transport="stream" version="1" /> // <event transport="datagram" version="1" /> -// <video transport="srtp" codec="vp8" version="1" /> +// <video transport="stream" codec="vp8" version="1" /> // <authentication> // Message created by Authenticator implementation. // </authentication> diff --git a/remoting/protocol/protocol_mock_objects.h b/remoting/protocol/protocol_mock_objects.h index a333e61..c36fbe1 100644 --- a/remoting/protocol/protocol_mock_objects.h +++ b/remoting/protocol/protocol_mock_objects.h @@ -156,11 +156,6 @@ class MockSession : public Session { MOCK_METHOD2(CreateDatagramChannel, void( const std::string& name, const DatagramChannelCallback& callback)); MOCK_METHOD1(CancelChannelCreation, void(const std::string& name)); - MOCK_METHOD0(control_channel, net::Socket*()); - MOCK_METHOD0(event_channel, net::Socket*()); - MOCK_METHOD0(video_channel, net::Socket*()); - MOCK_METHOD0(video_rtp_channel, net::Socket*()); - MOCK_METHOD0(video_rtcp_channel, net::Socket*()); MOCK_METHOD0(jid, const std::string&()); MOCK_METHOD0(candidate_config, const CandidateSessionConfig*()); MOCK_METHOD0(config, const SessionConfig&()); diff --git a/remoting/protocol/rtcp_writer.cc b/remoting/protocol/rtcp_writer.cc deleted file mode 100644 index f039ec5..0000000 --- a/remoting/protocol/rtcp_writer.cc +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) 2010 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. - -#include "remoting/protocol/rtcp_writer.h" - -#include "net/base/io_buffer.h" -#include "net/base/net_errors.h" -#include "remoting/base/compound_buffer.h" -#include "remoting/protocol/buffered_socket_writer.h" -#include "remoting/protocol/rtp_utils.h" - -namespace remoting { -namespace protocol { - -RtcpWriter::RtcpWriter(base::MessageLoopProxy* message_loop) - : buffered_rtcp_writer_(new BufferedDatagramWriter(message_loop)) { -} - -RtcpWriter::~RtcpWriter() { -} - -void RtcpWriter::Close() { - buffered_rtcp_writer_->Close(); -} - -// Initializes the writer. Must be called on the thread the sockets -// belong to. -void RtcpWriter::Init(net::Socket* socket) { - buffered_rtcp_writer_->Init( - socket, BufferedSocketWriter::WriteFailedCallback()); -} - -void RtcpWriter::SendReport(const RtcpReceiverReport& report) { - int size = GetRtcpReceiverReportSize(report); - net::IOBufferWithSize* buffer = new net::IOBufferWithSize(size); - - PackRtcpReceiverReport(report, reinterpret_cast<uint8*>(buffer->data()), - size); - - buffered_rtcp_writer_->Write(buffer, base::Closure()); -} - -} // namespace protocol -} // namespace remoting diff --git a/remoting/protocol/rtcp_writer.h b/remoting/protocol/rtcp_writer.h deleted file mode 100644 index ff7d9cd..0000000 --- a/remoting/protocol/rtcp_writer.h +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (c) 2011 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 REMOTING_PROTOCOL_RTCP_WRITER_H_ -#define REMOTING_PROTOCOL_RTCP_WRITER_H_ - -#include "net/socket/socket.h" - -namespace base { -class MessageLoopProxy; -} // namespace base - -namespace remoting { - -namespace protocol { - -class BufferedDatagramWriter; -struct RtcpReceiverReport; - -class RtcpWriter { - public: - explicit RtcpWriter(base::MessageLoopProxy* message_loop); - virtual ~RtcpWriter(); - - // Initializes the writer. Must be called on the thread the socket - // belongs to. - void Init(net::Socket* socket); - void Close(); - - // Sends next packet. The packet is mutated by - void SendReport(const RtcpReceiverReport& report); - - // Returns number of packets queued in the buffer. - int GetPendingPackets(); - - private: - scoped_refptr<BufferedDatagramWriter> buffered_rtcp_writer_; - - DISALLOW_COPY_AND_ASSIGN(RtcpWriter); -}; - -} // namespace protocol -} // namespace remoting - -#endif // REMOTING_PROTOCOL_RTCP_WRITER_H_ diff --git a/remoting/protocol/rtp_reader.cc b/remoting/protocol/rtp_reader.cc deleted file mode 100644 index 8f8da7a..0000000 --- a/remoting/protocol/rtp_reader.cc +++ /dev/null @@ -1,121 +0,0 @@ -// Copyright (c) 2011 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. - -#include "remoting/protocol/rtp_reader.h" - -#include "net/base/completion_callback.h" -#include "net/base/io_buffer.h" - -namespace remoting { -namespace protocol { - -namespace { -const int kInitialSequenceNumber = -1; - -// Recommended values from RTP spec. -const int kMaxDropout = 3000; -const int kMaxMisorder = 100; -} // namespace - -RtpPacket::RtpPacket() - : extended_sequence_number_(0) { -} - -RtpPacket::~RtpPacket() { } - -// RtpReader class. -RtpReader::RtpReader() - : max_sequence_number_(0), - wrap_around_count_(0), - start_sequence_number_(kInitialSequenceNumber), - total_packets_received_(0) { -} - -RtpReader::~RtpReader() { -} - -void RtpReader::Init(net::Socket* socket, - const OnMessageCallback& on_message_callback) { - DCHECK(!on_message_callback.is_null()); - on_message_callback_ = on_message_callback; - SocketReaderBase::Init(socket); -} - -void RtpReader::OnDataReceived(net::IOBuffer* buffer, int data_size) { - scoped_ptr<RtpPacket> packet(new RtpPacket()); - int header_size = UnpackRtpHeader(reinterpret_cast<uint8*>(buffer->data()), - data_size, packet->mutable_header()); - if (header_size < 0) { - LOG(WARNING) << "Received invalid RTP packet."; - return; - } - - int descriptor_size = UnpackVp8Descriptor( - reinterpret_cast<uint8*>(buffer->data()) + header_size, - data_size - header_size, packet->mutable_vp8_descriptor()); - if (descriptor_size < 0) { - LOG(WARNING) << "Received RTP packet with an invalid VP8 descriptor."; - return; - } - - packet->mutable_payload()->Append( - buffer, buffer->data() + header_size + descriptor_size, - data_size - header_size - descriptor_size); - - uint16 sequence_number = packet->header().sequence_number; - - // Reset |start_sequence_number_| after we've received first packet. - if (start_sequence_number_ == kInitialSequenceNumber) { - start_sequence_number_ = sequence_number; - max_sequence_number_ = sequence_number; - } - - int16 delta = sequence_number - max_sequence_number_; - if (delta <= -kMaxMisorder || delta > kMaxDropout) { - // TODO(sergeyu): Do we need to handle restarted transmission? - LOG(WARNING) << "Received RTP packet with invalid sequence number."; - return; - } - - packet->set_extended_sequence_number( - (wrap_around_count_ << 16) + max_sequence_number_ + delta); - - if (delta > 0 && delta < kMaxDropout) { - if (sequence_number < max_sequence_number_) { - wrap_around_count_++; - } - max_sequence_number_ = sequence_number; - } - - ++total_packets_received_; - - on_message_callback_.Run(packet.release()); -} - -void RtpReader::GetReceiverReport(RtcpReceiverReport* report) { - int expected_packets = start_sequence_number_ >= 0 ? - 1 + max_sequence_number_ - start_sequence_number_ : 0; - if (expected_packets > total_packets_received_) { - report->total_lost_packets = expected_packets - total_packets_received_; - } else { - report->total_lost_packets = 0; - } - - double loss_fraction = expected_packets > 0 ? - report->total_lost_packets / expected_packets : 0.0L; - DCHECK_GE(loss_fraction, 0.0); - DCHECK_LE(loss_fraction, 1.0); - report->loss_fraction = static_cast<uint8>(255 * loss_fraction); - - report->last_sequence_number = max_sequence_number_; - - // TODO(sergeyu): Implement jitter calculation. - // - // TODO(sergeyu): Set last_sender_report_timestamp and - // last_sender_report_delay fields when sender reports are - // implemented. -} - -} // namespace protocol -} // namespace remoting diff --git a/remoting/protocol/rtp_reader.h b/remoting/protocol/rtp_reader.h deleted file mode 100644 index ddaefee..0000000 --- a/remoting/protocol/rtp_reader.h +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright (c) 2012 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 REMOTING_PROTOCOL_RTP_READER_H_ -#define REMOTING_PROTOCOL_RTP_READER_H_ - -#include "base/callback.h" -#include "remoting/base/compound_buffer.h" -#include "remoting/protocol/rtp_utils.h" -#include "remoting/protocol/socket_reader_base.h" - -namespace remoting { -namespace protocol { - -class RtpPacket { - public: - RtpPacket(); - ~RtpPacket(); - - const RtpHeader& header() const { return header_; } - RtpHeader* mutable_header() { return &header_; } - - const Vp8Descriptor& vp8_descriptor() const { return vp8_descriptor_; } - Vp8Descriptor* mutable_vp8_descriptor() { return &vp8_descriptor_; } - - const CompoundBuffer& payload() const { return payload_; } - CompoundBuffer* mutable_payload() { return &payload_; } - - uint32 extended_sequence_number() const { - return extended_sequence_number_; - } - void set_extended_sequence_number(uint32 value) { - extended_sequence_number_ = value; - } - - private: - RtpHeader header_; - CompoundBuffer payload_; - Vp8Descriptor vp8_descriptor_; - uint32 extended_sequence_number_; -}; - -// RtpReader implements and RTP receiver. It reads packets from RTP -// socket, parses them, calculates extended sequence number and then -// passes them to a callback. It also collects statistics for RTCP -// receiver reports, but doesn't send any RTCP packets itself. -class RtpReader : public SocketReaderBase { - public: - RtpReader(); - virtual ~RtpReader(); - - // The OnMessageCallback is called whenever a new message is received. - // Ownership of the message is passed the callback. - typedef base::Callback<void(const RtpPacket*)> OnMessageCallback; - - // Initialize the reader and start reading. Must be called on the thread - // |socket| belongs to. The callback will be called when a new message is - // received. RtpReader owns |on_message_callback|, doesn't own - // |socket|. - void Init(net::Socket* socket, const OnMessageCallback& on_message_callback); - - void GetReceiverReport(RtcpReceiverReport* report); - - protected: - friend class RtpVideoReaderTest; - - virtual void OnDataReceived(net::IOBuffer* buffer, int data_size) OVERRIDE; - - private: - OnMessageCallback on_message_callback_; - - uint16 max_sequence_number_; - uint16 wrap_around_count_; - int start_sequence_number_; - int total_packets_received_; - - DISALLOW_COPY_AND_ASSIGN(RtpReader); -}; - -} // namespace protocol -} // namespace remoting - - -#endif // REMOTING_PROTOCOL_RTP_READER_H_ diff --git a/remoting/protocol/rtp_utils.cc b/remoting/protocol/rtp_utils.cc deleted file mode 100644 index 92b6d67..0000000 --- a/remoting/protocol/rtp_utils.cc +++ /dev/null @@ -1,358 +0,0 @@ -// Copyright (c) 2012 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. - -#include "remoting/protocol/rtp_utils.h" - -#include "base/logging.h" -#include "third_party/libjingle/source/talk/base/byteorder.h" - -using talk_base::GetBE16; -using talk_base::GetBE32; -using talk_base::SetBE16; -using talk_base::SetBE32; - -namespace remoting { -namespace protocol { - -namespace { -const int kRtpBaseHeaderSize = 12; -const uint8 kRtpVersionNumber = 2; -const int kRtpMaxSources = 16; -const int kBytesPerCSRC = 4; -const int kRtcpBaseHeaderSize = 4; -const int kRtcpReceiverReportSize = 28; -const int kRtcpReceiverReportTotalSize = - kRtcpBaseHeaderSize + kRtcpReceiverReportSize; -const int kRtcpReceiverReportPacketType = 201; -} // namespace - -RtpHeader::RtpHeader() - : padding(false), - extension(false), - sources(0), - marker(false), - payload_type(0), - sequence_number(0), - timestamp(0), - sync_source_id(0) { - memset(source_id, 0, sizeof(source_id)); -} - -RtcpReceiverReport::RtcpReceiverReport() - : receiver_ssrc(0), - sender_ssrc(0), - loss_fraction(0), - total_lost_packets(0), - last_sequence_number(0), - jitter(0), - last_sender_report_timestamp(0), - last_sender_report_delay(0) { -} - -static inline uint8 ExtractBits(uint8 byte, int bits_count, int shift) { - return (byte >> shift) & ((1 << bits_count) - 1); -} - -// RTP Header format: -// -// 0 1 2 3 -// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// |V=2|P|X| CC |M| PT | sequence number | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | timestamp | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | synchronization source (SSRC) identifier | -// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ -// | contributing source (CSRC) identifiers | -// | .... | -// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ -// -// On the diagram above order of bytes and order of bits within each -// byte are big-endian. So bits 0 and 7 are the most and the least -// significant bits in the first byte, bit 8 is the most significant -// bit in the second byte, etc. - -int GetRtpHeaderSize(const RtpHeader& header) { - DCHECK_GE(header.sources, 0); - DCHECK_LT(header.sources, kRtpMaxSources); - return kRtpBaseHeaderSize + header.sources * kBytesPerCSRC; -} - -void PackRtpHeader(const RtpHeader& header, uint8* buffer, int buffer_size) { - DCHECK_LT(header.sources, kRtpMaxSources); - DCHECK_LT(header.payload_type, 1 << 7); - CHECK_GE(buffer_size, GetRtpHeaderSize(header)); - - buffer[0] = (kRtpVersionNumber << 6) | - ((uint8)header.padding << 5) | - ((uint8)header.extension << 4) | - header.sources; - buffer[1] = ((uint8)header.marker << 7) | - header.payload_type; - SetBE16(buffer + 2, header.sequence_number); - SetBE32(buffer + 4, header.timestamp); - SetBE32(buffer + 8, header.sync_source_id); - - for (int i = 0; i < header.sources; i++) { - SetBE32(buffer + i * 4 + 12, header.source_id[i]); - } -} - -int UnpackRtpHeader(const uint8* buffer, int buffer_size, RtpHeader* header) { - if (buffer_size < kRtpBaseHeaderSize) { - return -1; - } - - int version = ExtractBits(buffer[0], 2, 6); - if (version != kRtpVersionNumber) { - return -1; - } - - header->padding = ExtractBits(buffer[0], 1, 5) != 0; - header->extension = ExtractBits(buffer[0], 1, 4) != 0; - header->sources = ExtractBits(buffer[0], 4, 0); - - header->marker = ExtractBits(buffer[1], 1, 7) != 0; - header->payload_type = ExtractBits(buffer[1], 7, 0); - - header->sequence_number = GetBE16(buffer + 2); - header->timestamp = GetBE32(buffer + 4); - header->sync_source_id = GetBE32(buffer + 8); - - DCHECK_LT(header->sources, 16); - - if (buffer_size < GetRtpHeaderSize(*header)) { - return -1; - } - for (int i = 0; i < header->sources; i++) { - header->source_id[i] = GetBE32(buffer + i * 4 + 12); - } - - return GetRtpHeaderSize(*header); -} - -// RTCP receiver report: -// -// 0 1 2 3 -// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// |V=2|P| RC=1 | PT=201 | length | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | SSRC of sender | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | SSRC of the reportee | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | fraction lost | cumulative number of packets lost | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | extended highest sequence number received | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | interarrival jitter | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | last SR (LSR) | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | delay since last SR (DLSR) | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - -int GetRtcpReceiverReportSize(const RtcpReceiverReport& report) { - return kRtcpReceiverReportTotalSize; -} - -void PackRtcpReceiverReport(const RtcpReceiverReport& report, - uint8* buffer, int buffer_size) { - CHECK_GE(buffer_size, GetRtcpReceiverReportSize(report)); - - buffer[0] = (kRtpVersionNumber << 6) | - 1 /* RC=1 */; - buffer[1] = kRtcpReceiverReportPacketType; - SetBE16(buffer + 2, kRtcpReceiverReportSize); - - SetBE32(buffer + 4, report.receiver_ssrc); - SetBE32(buffer + 8, report.sender_ssrc); - SetBE32(buffer + 12, report.total_lost_packets & 0xFFFFFF); - buffer[12] = report.loss_fraction; - SetBE32(buffer + 16, report.last_sequence_number); - SetBE32(buffer + 20, report.jitter); - SetBE32(buffer + 24, report.last_sender_report_timestamp); - SetBE32(buffer + 28, report.last_sender_report_delay); -} - -int UnpackRtcpReceiverReport(const uint8* buffer, int buffer_size, - RtcpReceiverReport* report) { - if (buffer_size < kRtcpReceiverReportTotalSize) { - return -1; - } - - int version = ExtractBits(buffer[0], 2, 6); - if (version != kRtpVersionNumber) { - return -1; - } - - int report_count = ExtractBits(buffer[0], 5, 0); - if (report_count != 1) { - // Received RTCP packet with more than one report. This isn't - // supported in the current implementation. - return -1; - } - - int packet_type = buffer[1]; - if (packet_type != kRtcpReceiverReportPacketType) { - // The packet isn't receiver report. - return -1; - } - - int report_size = GetBE16(buffer + 2); - if (report_size != kRtcpReceiverReportSize) { - // Invalid size of the report. - return -1; - } - - report->receiver_ssrc = GetBE32(buffer + 4); - report->sender_ssrc = GetBE32(buffer + 8); - report->loss_fraction = buffer[12]; - report->total_lost_packets = GetBE32(buffer + 12) & 0xFFFFFF; - report->last_sequence_number = GetBE32(buffer + 16); - report->jitter = GetBE32(buffer + 20); - report->last_sender_report_timestamp = GetBE32(buffer + 24); - report->last_sender_report_delay = GetBE32(buffer + 28); - - return kRtcpReceiverReportTotalSize; -} - -// VP8 Payload Descriptor format: -// -// 0 1 2 3 -// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | RSV |I|N|FI |B| PictureID (integer #bytes) | -// +-+-+-+-+-+-+-+-+ | -// : : -// | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | : (VP8 data or VP8 payload header; byte aligned)| -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// -// On the diagram above order of bytes and order of bits within each -// byte are big-endian. So bits 0 and 7 are the most and the least -// significant bits in the first byte, bit 8 is the most significant -// bit in the second byte, etc. -// -// RSV: 3 bits -// Bits reserved for future use. MUST be equal to zero and MUST be -// ignored by the receiver. -// -// I: 1 bit -// PictureID present. When set to one, a PictureID is provided after -// the first byte of the payload descriptor. When set to zero, the -// PictureID is omitted, and the one-byte payload descriptor is -// immediately followed by the VP8 payload. -// -// N: 1 bit -// Non-reference frame. When set to one, the frame can be discarded -// without affecting any other future or past frames. -// -// FI: 2 bits -// Fragmentation information field. This field contains information -// about the fragmentation of VP8 payloads carried in the RTP -// packet. The four different values are listed below. -// -// FI Fragmentation status -// 00 The RTP packet contains no fragmented VP8 partitions. The -// payload is one or several complete partitions. -// 01 The RTP packet contains the first part of a fragmented -// partition. The fragment must be placed in its own RTP packet. -// 10 The RTP packet contains a fragment that is neither the first nor -// the last part of a fragmented partition. The fragment must be -// placed in its own RTP packet. -// 11 The RTP packet contains the last part of a fragmented -// partition. The fragment must be placed in its own RTP packet. -// -// B: 1 bit -// Beginning VP8 frame. When set to 1 this signals that a new VP8 -// frame starts in this RTP packet. -// -// PictureID: Multiple of 8 bits -// This is a running index of the frames. The field is present only if -// the I bit is equal to one. The most significant bit of each byte is -// an extension flag. The 7 following bits carry (parts of) the -// PictureID. If the extension flag is one, the PictureID continues in -// the next byte. If the extension flag is zero, the 7 remaining bits -// are the last (and least significant) bits in the PictureID. The -// sender may choose any number of bytes for the PictureID. The -// PictureID SHALL start on a random number, and SHALL wrap after -// reaching the maximum ID as chosen by the application - -int GetVp8DescriptorSize(const Vp8Descriptor& descriptor) { - if (descriptor.picture_id == kuint32max) - return 1; - int result = 2; - // We need 1 byte per each 7 bits in picture_id. - uint32 picture_id = descriptor.picture_id >> 7; - while (picture_id > 0) { - picture_id >>= 7; - ++result; - } - return result; -} - -void PackVp8Descriptor(const Vp8Descriptor& descriptor, uint8* buffer, - int buffer_size) { - CHECK_GT(buffer_size, 0); - - buffer[0] = - ((uint8)(descriptor.picture_id != kuint32max) << 4) | - ((uint8)descriptor.non_reference_frame << 3) | - (descriptor.fragmentation_info << 1) | - ((uint8)descriptor.frame_beginning); - - uint32 picture_id = descriptor.picture_id; - if (picture_id == kuint32max) - return; - - int pos = 1; - while (picture_id > 0) { - CHECK_LT(pos, buffer_size); - buffer[pos] = picture_id & 0x7F; - picture_id >>= 7; - - // Set the extension bit if neccessary. - if (picture_id > 0) - buffer[pos] |= 0x80; - ++pos; - } -} - -int UnpackVp8Descriptor(const uint8* buffer, int buffer_size, - Vp8Descriptor* descriptor) { - if (buffer_size <= 0) - return -1; - - bool picture_id_present = ExtractBits(buffer[0], 1, 4) != 0; - descriptor->non_reference_frame = ExtractBits(buffer[0], 1, 3) != 0; - descriptor->fragmentation_info = ExtractBits(buffer[0], 2, 1); - descriptor->frame_beginning = ExtractBits(buffer[0], 1, 0) != 0; - - // Return here if we don't need to decode PictureID. - if (!picture_id_present) { - descriptor->picture_id = kuint32max; - return 1; - } - - // Decode PictureID. - bool extension = true; - int pos = 1; - descriptor->picture_id = 0; - while (extension) { - if (pos >= buffer_size) - return -1; - - descriptor->picture_id |= buffer[pos] & 0x7F; - extension = (buffer[pos] & 0x80) != 0; - pos += 1; - } - return pos; -} - -} // namespace protocol -} // namespace remoting diff --git a/remoting/protocol/rtp_utils.h b/remoting/protocol/rtp_utils.h deleted file mode 100644 index 4441d78..0000000 --- a/remoting/protocol/rtp_utils.h +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright (c) 2010 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 REMOTING_PROTOCOL_RTP_UTILS_H_ -#define REMOTING_PROTOCOL_RTP_UTILS_H_ - -#include "base/basictypes.h" - -namespace remoting { -namespace protocol { - -struct RtpHeader { - RtpHeader(); - - // RTP version is always set to 2. - // version = 2 - bool padding; - bool extension; - uint8 sources; - bool marker; - uint8 payload_type; - uint16 sequence_number; - uint32 timestamp; - uint32 sync_source_id; - uint32 source_id[15]; -}; - -struct RtcpReceiverReport { - RtcpReceiverReport(); - - uint32 receiver_ssrc; - uint32 sender_ssrc; - uint8 loss_fraction; // 8bit fixed point value in the interval [0..1]. - uint32 total_lost_packets; - uint32 last_sequence_number; - uint32 jitter; - uint32 last_sender_report_timestamp; - uint32 last_sender_report_delay; -}; - -// Vp8Descriptor struct used to store values of the VP8 RTP descriptor -// fields. Meaning of each field is documented in the RTP Payload -// Format for VP8 spec: http://www.webmproject.org/code/specs/rtp/ . -struct Vp8Descriptor { - enum FragmentationInfo { - NOT_FRAGMENTED = 0, - FIRST_FRAGMENT = 1, - MIDDLE_FRAGMENT = 2, - LAST_FRAGMENT = 3, - }; - - Vp8Descriptor() - : non_reference_frame(false), - fragmentation_info(NOT_FRAGMENTED), - frame_beginning(false), - picture_id(kuint32max) { - } - - bool non_reference_frame; - uint8 fragmentation_info; - bool frame_beginning; - - // PictureID is considered to be absent if |picture_id| is set to kuint32max. - uint32 picture_id; -}; - -// Returns size of RTP header for the specified number of sources. -int GetRtpHeaderSize(const RtpHeader& header); - -// Packs RTP header into the buffer. -void PackRtpHeader(const RtpHeader& header, uint8* buffer, int buffer_size); - -// Unpacks RTP header and stores unpacked values in |header|. -int UnpackRtpHeader(const uint8* buffer, int buffer_size, RtpHeader* header); - -// Three following functions below are used to pack and unpack RTCP -// Receiver Report packets. They implement only subset of RTCP that is -// useful for chromoting. Particularly there are following -// limitations: -// -// 1. Only one report per packet. There is always only one sender and -// only one receiver in chromotocol session, so we never need to -// have more than one report per packet. -// 2. No RTCP Sender Report. Sender Reports are useful for streams -// synchronization (e.g. audio/video syncronization), but it is -// not needed for screencasts. - -// Returns size of RTCP Receiver Report packet. -int GetRtcpReceiverReportSize(const RtcpReceiverReport& report); - -// Packs RTCP Receiver Report into the |buffer|. -void PackRtcpReceiverReport(const RtcpReceiverReport& report, - uint8* buffer, int buffer_size); - -// Unpack RTCP Receiver Report packet. If the packet is invalid -// returns -1, othewise returns size of the data that was read from -// the packet. -int UnpackRtcpReceiverReport(const uint8* buffer, int buffer_size, - RtcpReceiverReport* report); - -// Returns size of VP8 Payload Descriptor. -int GetVp8DescriptorSize(const Vp8Descriptor& descriptor); - -// Packs VP8 Payload Descriptor into the |buffer|. -void PackVp8Descriptor(const Vp8Descriptor& descriptor, uint8* buffer, - int buffer_size); - -// Unpacks VP8 Payload Descriptor. If the descriptor is not valid -// returns -1, otherwise returns size of the descriptor. -int UnpackVp8Descriptor(const uint8* buffer, int buffer_size, - Vp8Descriptor* descriptor); - -} // namespace protocol -} // namespace remoting - -#endif // REMOTING_PROTOCOL_RTP_UTILS_H_ diff --git a/remoting/protocol/rtp_video_reader.cc b/remoting/protocol/rtp_video_reader.cc deleted file mode 100644 index ee0c5ef..0000000 --- a/remoting/protocol/rtp_video_reader.cc +++ /dev/null @@ -1,241 +0,0 @@ -// Copyright (c) 2012 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. - -#include "remoting/protocol/rtp_video_reader.h" - -#include "base/bind.h" -#include "base/bind_helpers.h" -#include "remoting/base/constants.h" -#include "remoting/proto/video.pb.h" -#include "remoting/protocol/session.h" - -namespace remoting { -namespace protocol { - -namespace { -const int kMaxPacketsInQueue = 1024; -const int kReceiverReportsIntervalMs = 1000; -} // namespace - -RtpVideoReader::PacketsQueueEntry::PacketsQueueEntry() - : received(false), - packet(NULL) { -} - -RtpVideoReader::RtpVideoReader(base::MessageLoopProxy* message_loop) - : session_(NULL), - initialized_(false), - rtcp_writer_(message_loop), - last_sequence_number_(0), - video_stub_(NULL) { -} - -RtpVideoReader::~RtpVideoReader() { - if (session_) { - session_->CancelChannelCreation(kVideoRtpChannelName); - session_->CancelChannelCreation(kVideoRtcpChannelName); - } - ResetQueue(); -} - -void RtpVideoReader::Init(protocol::Session* session, - VideoStub* video_stub, - const InitializedCallback& callback) { - session_ = session; - initialized_callback_ = callback; - video_stub_ = video_stub; - - session_->CreateDatagramChannel( - kVideoRtpChannelName, - base::Bind(&RtpVideoReader::OnChannelReady, - base::Unretained(this), true)); - session_->CreateDatagramChannel( - kVideoRtcpChannelName, - base::Bind(&RtpVideoReader::OnChannelReady, - base::Unretained(this), false)); -} - -bool RtpVideoReader::is_connected() { - return rtp_channel_.get() && rtcp_channel_.get(); -} - -void RtpVideoReader::OnChannelReady(bool rtp, scoped_ptr<net::Socket> socket) { - if (!socket.get()) { - if (!initialized_) { - initialized_ = true; - initialized_callback_.Run(false); - } - return; - } - - if (rtp) { - DCHECK(!rtp_channel_.get()); - rtp_channel_ = socket.Pass(); - rtp_reader_.Init(rtp_channel_.get(), - base::Bind(&RtpVideoReader::OnRtpPacket, - base::Unretained(this))); - } else { - DCHECK(!rtcp_channel_.get()); - rtcp_channel_ = socket.Pass(); - rtcp_writer_.Init(rtcp_channel_.get()); - } - - if (rtp_channel_.get() && rtcp_channel_.get()) { - DCHECK(!initialized_); - initialized_ = true; - initialized_callback_.Run(true); - } -} - -void RtpVideoReader::ResetQueue() { - for (PacketsQueue::iterator it = packets_queue_.begin(); - it != packets_queue_.end(); ++it) { - delete it->packet; - } - packets_queue_.assign(kMaxPacketsInQueue, PacketsQueueEntry()); -} - -void RtpVideoReader::OnRtpPacket(const RtpPacket* rtp_packet) { - uint32 sequence_number = rtp_packet->extended_sequence_number(); - int32 relative_number = sequence_number - last_sequence_number_; - int packet_index; - - if (packets_queue_.empty()) { - // This is the first packet we've received. Setup the queue. - ResetQueue(); - last_sequence_number_ = sequence_number; - packet_index = packets_queue_.size() - 1; - } else if (relative_number > 0) { - if (relative_number > kMaxPacketsInQueue) { - // Sequence number jumped too much for some reason. Reset the queue. - ResetQueue(); - } else { - packets_queue_.resize(packets_queue_.size() + relative_number); - // Cleanup old packets, so that we don't have more than - // |kMaxPacketsInQueue| packets. - while (static_cast<int>(packets_queue_.size()) > kMaxPacketsInQueue) { - delete packets_queue_.front().packet; - packets_queue_.pop_front(); - } - } - last_sequence_number_ = sequence_number; - packet_index = packets_queue_.size() - 1; - } else { - packet_index = packets_queue_.size() - 1 + relative_number; - if (packet_index < 0) { - // The packet is too old. Just drop it. - delete rtp_packet; - return; - } - } - - CHECK_LT(packet_index, static_cast<int>(packets_queue_.size())); - - if (packets_queue_[packet_index].received) { - VLOG(1) << "Received duplicate packet with sequence number " - << sequence_number; - delete rtp_packet; - return; - } - - packets_queue_[packet_index].packet = rtp_packet; - packets_queue_[packet_index].received = true; - - CheckFullPacket(packets_queue_.begin() + packet_index); -} - -void RtpVideoReader::CheckFullPacket(const PacketsQueue::iterator& pos) { - if (pos->packet->vp8_descriptor().fragmentation_info == - Vp8Descriptor::NOT_FRAGMENTED) { - // The packet is not fragmented. - RebuildVideoPacket(pos, pos); - return; - } - - PacketsQueue::iterator first = pos; - while (first > packets_queue_.begin() && first->packet && - first->packet->vp8_descriptor().fragmentation_info != - Vp8Descriptor::FIRST_FRAGMENT) { - first--; - } - if (!first->packet || first->packet->vp8_descriptor().fragmentation_info != - Vp8Descriptor::FIRST_FRAGMENT) { - // We don't have first fragment. - return; - } - - PacketsQueue::iterator last = pos; - while (last < (packets_queue_.end() - 1) && last->packet && - last->packet->vp8_descriptor().fragmentation_info != - Vp8Descriptor::LAST_FRAGMENT) { - last++; - } - if (!last->packet || last->packet->vp8_descriptor().fragmentation_info != - Vp8Descriptor::LAST_FRAGMENT) { - // We don't have last fragment. - return; - } - - // We've found first and last fragments, and we have all fragments in the - // middle, so we can rebuild fill packet. - RebuildVideoPacket(first, last); -} - -void RtpVideoReader::RebuildVideoPacket(const PacketsQueue::iterator& first, - const PacketsQueue::iterator& last) { - scoped_ptr<VideoPacket> packet(new VideoPacket()); - - // Set flags. - if (first->packet->vp8_descriptor().frame_beginning) - packet->set_flags(packet->flags() | VideoPacket::FIRST_PACKET); - - if (last->packet->header().marker) - packet->set_flags(packet->flags() | VideoPacket::LAST_PACKET); - - packet->set_timestamp(first->packet->header().timestamp); - - // Rebuild packet content from the fragments. - // TODO(sergeyu): Use CompoundBuffer inside of VideoPacket, so that we don't - // need to memcopy any data. - CompoundBuffer content; - for (PacketsQueue::iterator it = first; it <= last; ++it) { - content.Append(it->packet->payload()); - - // Delete packet because we don't need it anymore. - delete it->packet; - it->packet = NULL; - // Here we keep |received| flag set to true, so that duplicate RTP - // packets will be ignored. - } - - packet->mutable_data()->resize(content.total_bytes()); - content.CopyTo(const_cast<char*>(packet->mutable_data()->data()), - packet->data().size()); - - // Set format. - packet->mutable_format()->set_encoding(VideoPacketFormat::ENCODING_VP8); - - video_stub_->ProcessVideoPacket(packet.Pass(), base::Closure()); - - SendReceiverReportIf(); -} - -void RtpVideoReader::SendReceiverReportIf() { - base::Time now = base::Time::Now(); - - // Send receiver report only if we haven't sent any bofore, or - // enough time has passed since the last report. - if (last_receiver_report_.is_null() || - (now - last_receiver_report_).InMilliseconds() > - kReceiverReportsIntervalMs) { - RtcpReceiverReport report; - rtp_reader_.GetReceiverReport(&report); - rtcp_writer_.SendReport(report); - - last_receiver_report_ = now; - } -} - -} // namespace protocol -} // namespace remoting diff --git a/remoting/protocol/rtp_video_reader.h b/remoting/protocol/rtp_video_reader.h deleted file mode 100644 index fb58e9bf..0000000 --- a/remoting/protocol/rtp_video_reader.h +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright (c) 2012 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 REMOTING_PROTOCOL_RTP_VIDEO_READER_H_ -#define REMOTING_PROTOCOL_RTP_VIDEO_READER_H_ - -#include "base/compiler_specific.h" -#include "base/time.h" -#include "base/memory/scoped_ptr.h" -#include "remoting/protocol/rtcp_writer.h" -#include "remoting/protocol/rtp_reader.h" -#include "remoting/protocol/video_reader.h" - -namespace base { -class MessageLoopProxy; -} // namespace base - -namespace remoting { -namespace protocol { - -class RtcpWriter; -class RtpReader; -class Session; - -class RtpVideoReader : public VideoReader { - public: - RtpVideoReader(base::MessageLoopProxy* message_loop); - virtual ~RtpVideoReader(); - - // VideoReader interface. - virtual void Init(protocol::Session* session, - VideoStub* video_stub, - const InitializedCallback& callback) OVERRIDE; - virtual bool is_connected() OVERRIDE; - - private: - friend class RtpVideoReaderTest; - - // Following struct is used to store pending packets in |packets_queue_|. - // Each entry may be in three different states: - // |received| == false, |packet| == NULL - packet with the corresponding - // sequence number hasn't been received. - // |received| == true, |packet| != NULL - packet with the corresponding - // sequence number has been received, but hasn't been processed, still - // waiting for other fragments. - // |received| == true, |packet| == NULL - packet with the corresponding - // sequence number has been received and processed. Ignore any additional - // packet with the same sequence number. - struct PacketsQueueEntry { - PacketsQueueEntry(); - bool received; - const RtpPacket* packet; - }; - - typedef std::deque<PacketsQueueEntry> PacketsQueue; - - void OnChannelReady(bool rtp, scoped_ptr<net::Socket> socket); - - void OnRtpPacket(const RtpPacket* rtp_packet); - void CheckFullPacket(const PacketsQueue::iterator& pos); - void RebuildVideoPacket(const PacketsQueue::iterator& from, - const PacketsQueue::iterator& to); - void ResetQueue(); - - // Helper method that sends RTCP receiver reports if enough time has - // passed since the last report. It is called from - // OnRtpPacket(). Interval between reports is defined by - // |kReceiverReportsIntervalMs|. - void SendReceiverReportIf(); - - Session* session_; - - bool initialized_; - InitializedCallback initialized_callback_; - - scoped_ptr<net::Socket> rtp_channel_; - RtpReader rtp_reader_; - scoped_ptr<net::Socket> rtcp_channel_; - RtcpWriter rtcp_writer_; - - PacketsQueue packets_queue_; - uint32 last_sequence_number_; - - base::Time last_receiver_report_; - - // The stub that processes all received packets. - VideoStub* video_stub_; - - DISALLOW_COPY_AND_ASSIGN(RtpVideoReader); -}; - -} // namespace protocol -} // namespace remoting - -#endif // REMOTING_PROTOCOL_RTP_VIDEO_READER_H_ diff --git a/remoting/protocol/rtp_video_reader_unittest.cc b/remoting/protocol/rtp_video_reader_unittest.cc deleted file mode 100644 index 01c7715..0000000 --- a/remoting/protocol/rtp_video_reader_unittest.cc +++ /dev/null @@ -1,379 +0,0 @@ -// Copyright (c) 2012 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. - -#include <vector> - -#include "base/bind.h" -#include "base/message_loop.h" -#include "base/message_loop_proxy.h" -#include "base/string_number_conversions.h" -#include "net/base/io_buffer.h" -#include "remoting/proto/video.pb.h" -#include "remoting/protocol/fake_session.h" -#include "remoting/protocol/rtp_utils.h" -#include "remoting/protocol/rtp_video_reader.h" -#include "testing/gtest/include/gtest/gtest.h" - -using net::IOBuffer; -using std::vector; - -namespace remoting { -namespace protocol { - -class RtpVideoReaderTest : public testing::Test, - public VideoStub { - public: - // VideoStub interface. - virtual void ProcessVideoPacket(scoped_ptr<VideoPacket> video_packet, - const base::Closure& done) { - received_packets_.push_back(VideoPacket()); - received_packets_.back() = *video_packet; - if (!done.is_null()) - done.Run(); - } - - virtual int GetPendingPackets() { - return 0; - } - - protected: - struct FragmentInfo { - int sequence_number; - int timestamp; - bool first; - bool last; - Vp8Descriptor::FragmentationInfo fragmentation_info; - int start; - int end; - }; - - struct ExpectedPacket { - int timestamp; - int flags; - int start; - int end; - }; - - virtual void SetUp() { - Reset(); - InitData(100); - } - - virtual void TearDown() { - message_loop_.RunAllPending(); - } - - void Reset() { - session_.reset(new FakeSession()); - reader_.reset(new RtpVideoReader( - base::MessageLoopProxy::current())); - reader_->Init(session_.get(), this, - base::Bind(&RtpVideoReaderTest::OnReaderInitialized, - base::Unretained(this))); - received_packets_.clear(); - } - - void OnReaderInitialized(bool success) { - ASSERT_TRUE(success); - } - - void InitData(int size) { - data_.resize(size); - for (int i = 0; i < size; ++i) { - data_[i] = static_cast<char>(i); - } - } - - bool CompareData(const CompoundBuffer& buffer, char* data, int size) { - scoped_refptr<IOBuffer> buffer_data = buffer.ToIOBufferWithSize(); - return buffer.total_bytes() == size && - memcmp(buffer_data->data(), data, size) == 0; - } - - void SplitAndSend(const FragmentInfo fragments[], int count) { - for (int i = 0; i < count; ++i) { - RtpHeader header; - header.sequence_number = fragments[i].sequence_number; - header.marker = fragments[i].last; - header.timestamp = fragments[i].timestamp; - - Vp8Descriptor descriptor; - descriptor.non_reference_frame = true; - descriptor.frame_beginning = fragments[i].first; - descriptor.fragmentation_info = fragments[i].fragmentation_info; - - int header_size = GetRtpHeaderSize(header); - int vp8_desc_size = GetVp8DescriptorSize(descriptor); - int payload_size = fragments[i].end - fragments[i].start; - int size = header_size + vp8_desc_size + payload_size; - scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(size); - - PackRtpHeader(header, reinterpret_cast<uint8*>(buffer->data()), - header_size); - PackVp8Descriptor(descriptor, reinterpret_cast<uint8*>(buffer->data()) + - header_size, vp8_desc_size); - - memcpy(buffer->data() + header_size + vp8_desc_size, - &*data_.begin() + fragments[i].start, payload_size); - - reader_->rtp_reader_.OnDataReceived(buffer, size); - } - } - - void CheckResults(const ExpectedPacket expected[], int count) { - ASSERT_EQ(count, static_cast<int>(received_packets_.size())); - for (int i = 0; i < count; ++i) { - SCOPED_TRACE("Packet " + base::IntToString(i)); - - int expected_size = expected[i].end - expected[i].start; - EXPECT_EQ(expected_size, - static_cast<int>(received_packets_[i].data().size())); - EXPECT_EQ(0, memcmp(&*received_packets_[i].data().data(), - &*data_.begin() + expected[i].start, expected_size)); - EXPECT_EQ(expected[i].flags, received_packets_[i].flags()); - EXPECT_EQ(expected[i].timestamp, received_packets_[i].timestamp()); - } - } - - MessageLoop message_loop_; - - scoped_ptr<FakeSession> session_; - scoped_ptr<RtpVideoReader> reader_; - - vector<char> data_; - vector<VideoPacket> received_packets_; -}; - -// One non-fragmented packet marked as first. -TEST_F(RtpVideoReaderTest, NotFragmented_FirstPacket) { - FragmentInfo fragments[] = { - { 300, 123, true, false, Vp8Descriptor::NOT_FRAGMENTED, 0, 100 }, - }; - SplitAndSend(fragments, arraysize(fragments)); - - ExpectedPacket expected[] = { - { 123, VideoPacket::FIRST_PACKET, 0, 100 }, - }; - CheckResults(expected, arraysize(expected)); -} - -// One non-fragmented packet marked as last. -TEST_F(RtpVideoReaderTest, NotFragmented_LastPacket) { - FragmentInfo fragments[] = { - { 3000, 123, false, true, Vp8Descriptor::NOT_FRAGMENTED, 0, 100 }, - }; - SplitAndSend(fragments, arraysize(fragments)); - - ExpectedPacket expected[] = { - { 123, VideoPacket::LAST_PACKET, 0, 100 }, - }; - CheckResults(expected, arraysize(expected)); -} - -// Duplicated non-fragmented packet. Must be processed only once. -TEST_F(RtpVideoReaderTest, NotFragmented_Duplicate) { - FragmentInfo fragments[] = { - { 300, 123, true, false, Vp8Descriptor::NOT_FRAGMENTED, 0, 100 }, - { 300, 123, true, false, Vp8Descriptor::NOT_FRAGMENTED, 0, 100 }, - }; - SplitAndSend(fragments, arraysize(fragments)); - - ExpectedPacket expected[] = { - { 123, VideoPacket::FIRST_PACKET, 0, 100 }, - }; - CheckResults(expected, arraysize(expected)); -} - -// First packet split into two fragments. -TEST_F(RtpVideoReaderTest, TwoFragments_FirstPacket) { - FragmentInfo fragments[] = { - { 300, 321, true, false, Vp8Descriptor::FIRST_FRAGMENT, 0, 50 }, - { 301, 321, false, false, Vp8Descriptor::LAST_FRAGMENT, 50, 100 }, - }; - SplitAndSend(fragments, arraysize(fragments)); - - ExpectedPacket expected[] = { - { 321, VideoPacket::FIRST_PACKET, 0, 100 }, - }; - CheckResults(expected, arraysize(expected)); -} - -// Last packet split into two fragments. -TEST_F(RtpVideoReaderTest, TwoFragments_LastPacket) { - FragmentInfo fragments[] = { - { 3000, 400, false, false, Vp8Descriptor::FIRST_FRAGMENT, 0, 50 }, - { 3001, 400, false, true, Vp8Descriptor::LAST_FRAGMENT, 50, 100 }, - }; - SplitAndSend(fragments, arraysize(fragments)); - - ExpectedPacket expected[] = { - { 400, VideoPacket::LAST_PACKET, 0, 100 }, - }; - CheckResults(expected, arraysize(expected)); -} - -// Duplicated second fragment. -TEST_F(RtpVideoReaderTest, TwoFragments_WithDuplicate) { - FragmentInfo fragments[] = { - { 3000, 400, false, false, Vp8Descriptor::FIRST_FRAGMENT, 0, 50 }, - { 3001, 400, false, true, Vp8Descriptor::LAST_FRAGMENT, 50, 100 }, - { 3001, 400, false, true, Vp8Descriptor::LAST_FRAGMENT, 50, 100 }, - }; - SplitAndSend(fragments, arraysize(fragments)); - - ExpectedPacket expected[] = { - { 400, VideoPacket::LAST_PACKET, 0, 100 }, - }; - CheckResults(expected, arraysize(expected)); -} - -// Packet split into three fragments. -TEST_F(RtpVideoReaderTest, ThreeFragments_Ordered) { - FragmentInfo fragments[] = { - { 300, 400, true, false, Vp8Descriptor::FIRST_FRAGMENT, 0, 50 }, - { 301, 400, false, false, Vp8Descriptor::MIDDLE_FRAGMENT, 50, 90 }, - { 302, 400, false, false, Vp8Descriptor::LAST_FRAGMENT, 90, 100 }, - }; - SplitAndSend(fragments, arraysize(fragments)); - - ExpectedPacket expected[] = { - { 400, VideoPacket::FIRST_PACKET, 0, 100 }, - }; - CheckResults(expected, arraysize(expected)); -} - -// Packet split into three fragments received in reverse order. -TEST_F(RtpVideoReaderTest, ThreeFragments_ReverseOrder) { - FragmentInfo fragments[] = { - { 302, 400, false, false, Vp8Descriptor::LAST_FRAGMENT, 90, 100 }, - { 301, 400, false, false, Vp8Descriptor::MIDDLE_FRAGMENT, 50, 90 }, - { 300, 400, true, false, Vp8Descriptor::FIRST_FRAGMENT, 0, 50 }, - }; - SplitAndSend(fragments, arraysize(fragments)); - - ExpectedPacket expected[] = { - { 400, VideoPacket::FIRST_PACKET, 0, 100 }, - }; - CheckResults(expected, arraysize(expected)); -} - -// Two fragmented packets. -TEST_F(RtpVideoReaderTest, TwoPackets) { - FragmentInfo fragments[] = { - { 300, 100, true, false, Vp8Descriptor::FIRST_FRAGMENT, 0, 10 }, - { 301, 100, false, false, Vp8Descriptor::MIDDLE_FRAGMENT, 10, 20 }, - { 302, 100, false, false, Vp8Descriptor::LAST_FRAGMENT, 20, 40 }, - - { 303, 200, false, false, Vp8Descriptor::FIRST_FRAGMENT, 40, 70 }, - { 304, 200, false, true, Vp8Descriptor::LAST_FRAGMENT, 70, 100 }, - }; - SplitAndSend(fragments, arraysize(fragments)); - - ExpectedPacket expected[] = { - { 100, VideoPacket::FIRST_PACKET, 0, 40 }, - { 200, VideoPacket::LAST_PACKET, 40, 100 }, - }; - CheckResults(expected, arraysize(expected)); -} - -// Sequence of three packets, with one lost fragment lost in the second packet. -TEST_F(RtpVideoReaderTest, LostFragment) { - FragmentInfo fragments[] = { - { 300, 100, true, false, Vp8Descriptor::FIRST_FRAGMENT, 0, 10 }, - { 301, 100, false, false, Vp8Descriptor::MIDDLE_FRAGMENT, 10, 20 }, - { 302, 100, false, false, Vp8Descriptor::LAST_FRAGMENT, 20, 30 }, - - // Lost: { 303, 200, false, false, Vp8Descriptor::FIRST_FRAGMENT, 40, 50 }, - { 304, 200, false, true, Vp8Descriptor::LAST_FRAGMENT, 30, 40 }, - - { 305, 300, true, false, Vp8Descriptor::FIRST_FRAGMENT, 50, 70 }, - { 306, 300, false, true, Vp8Descriptor::LAST_FRAGMENT, 70, 100 }, - }; - SplitAndSend(fragments, arraysize(fragments)); - - ExpectedPacket expected[] = { - { 100, VideoPacket::FIRST_PACKET, 0, 30 }, - { 300, VideoPacket::FIRST_PACKET | VideoPacket::LAST_PACKET, 50, 100 }, - }; - CheckResults(expected, arraysize(expected)); -} - -// Sequence of four packets, with two lost fragments. -TEST_F(RtpVideoReaderTest, TwoLostFragments) { - // Fragments 303 and 306 should not be combined because they belong to - // different Vp8 partitions. - FragmentInfo fragments[] = { - { 300, 100, true, false, Vp8Descriptor::FIRST_FRAGMENT, 0, 10 }, - { 301, 100, false, false, Vp8Descriptor::MIDDLE_FRAGMENT, 10, 20 }, - { 302, 100, false, false, Vp8Descriptor::LAST_FRAGMENT, 20, 30 }, - - { 303, 200, false, false, Vp8Descriptor::FIRST_FRAGMENT, 40, 50 }, - // Lost: { 304, 200, false, true, Vp8Descriptor::LAST_FRAGMENT, 30, 40 }, - - // Lost: { 305, 300, true, false, Vp8Descriptor::FIRST_FRAGMENT, 50, 60 }, - { 306, 300, false, true, Vp8Descriptor::LAST_FRAGMENT, 60, 70 }, - - { 307, 400, true, false, Vp8Descriptor::FIRST_FRAGMENT, 70, 80 }, - { 308, 400, false, true, Vp8Descriptor::LAST_FRAGMENT, 80, 100 }, - }; - SplitAndSend(fragments, arraysize(fragments)); - - ExpectedPacket expected[] = { - { 100, VideoPacket::FIRST_PACKET, 0, 30 }, - { 400, VideoPacket::FIRST_PACKET | VideoPacket::LAST_PACKET, 70, 100 }, - }; - CheckResults(expected, arraysize(expected)); -} - -// Sequence number wrapping. -TEST_F(RtpVideoReaderTest, SequenceNumberWrapping) { - FragmentInfo fragments[] = { - { 65534, 400, true, false, Vp8Descriptor::FIRST_FRAGMENT, 0, 50 }, - { 65535, 400, false, false, Vp8Descriptor::MIDDLE_FRAGMENT, 50, 90 }, - { 0, 400, false, false, Vp8Descriptor::LAST_FRAGMENT, 90, 100 }, - }; - SplitAndSend(fragments, arraysize(fragments)); - - ExpectedPacket expected[] = { - { 400, VideoPacket::FIRST_PACKET, 0, 100 }, - }; - CheckResults(expected, arraysize(expected)); -} - -// Sequence number wrapping for fragments received out of order. -TEST_F(RtpVideoReaderTest, SequenceNumberWrappingReordered) { - FragmentInfo fragments[] = { - { 0, 400, false, false, Vp8Descriptor::LAST_FRAGMENT, 90, 100 }, - { 65534, 400, true, false, Vp8Descriptor::FIRST_FRAGMENT, 0, 50 }, - { 65535, 400, false, false, Vp8Descriptor::MIDDLE_FRAGMENT, 50, 90 }, - }; - SplitAndSend(fragments, arraysize(fragments)); - - ExpectedPacket expected[] = { - { 400, VideoPacket::FIRST_PACKET, 0, 100 }, - }; - CheckResults(expected, arraysize(expected)); -} - -// An old packet with invalid sequence number. -TEST_F(RtpVideoReaderTest, OldPacket) { - FragmentInfo fragments[] = { - { 32000, 123, true, true, Vp8Descriptor::NOT_FRAGMENTED, 0, 30 }, - - // Should be ignored. - { 10000, 532, true, true, Vp8Descriptor::NOT_FRAGMENTED, 30, 40 }, - - { 32001, 223, true, true, Vp8Descriptor::NOT_FRAGMENTED, 40, 50 }, - }; - SplitAndSend(fragments, arraysize(fragments)); - - ExpectedPacket expected[] = { - { 123, VideoPacket::FIRST_PACKET | VideoPacket::LAST_PACKET, 0, 30 }, - { 223, VideoPacket::FIRST_PACKET | VideoPacket::LAST_PACKET, 40, 50 }, - }; - CheckResults(expected, arraysize(expected)); -} - -} // namespace protocol -} // namespace remoting diff --git a/remoting/protocol/rtp_video_writer.cc b/remoting/protocol/rtp_video_writer.cc deleted file mode 100644 index 5534a46..0000000 --- a/remoting/protocol/rtp_video_writer.cc +++ /dev/null @@ -1,152 +0,0 @@ -// Copyright (c) 2012 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. - -#include "remoting/protocol/rtp_video_writer.h" - -#include "base/bind.h" -#include "base/callback.h" -#include "net/base/io_buffer.h" -#include "remoting/base/compound_buffer.h" -#include "remoting/base/constants.h" -#include "remoting/proto/video.pb.h" -#include "remoting/protocol/rtp_writer.h" -#include "remoting/protocol/session.h" - -namespace remoting { -namespace protocol { - -namespace { -const int kMtu = 1200; -} // namespace - -RtpVideoWriter::RtpVideoWriter(base::MessageLoopProxy* message_loop) - : session_(NULL), - initialized_(false), - rtp_writer_(message_loop) { -} - -RtpVideoWriter::~RtpVideoWriter() { - Close(); -} - -void RtpVideoWriter::Init(protocol::Session* session, - const InitializedCallback& callback) { - session_ = session; - initialized_callback_ = callback; - session->CreateDatagramChannel( - kVideoRtpChannelName, - base::Bind(&RtpVideoWriter::OnChannelReady, - base::Unretained(this), true)); - session->CreateDatagramChannel( - kVideoRtcpChannelName, - base::Bind(&RtpVideoWriter::OnChannelReady, - base::Unretained(this), false)); -} - -void RtpVideoWriter::OnChannelReady(bool rtp, scoped_ptr<net::Socket> socket) { - if (!socket.get()) { - if (!initialized_) { - initialized_ = true; - initialized_callback_.Run(false); - } - return; - } - - if (rtp) { - DCHECK(!rtp_channel_.get()); - rtp_channel_ = socket.Pass(); - rtp_writer_.Init(rtp_channel_.get()); - } else { - DCHECK(!rtcp_channel_.get()); - rtcp_channel_ = socket.Pass(); - // TODO(sergeyu): Use RTCP channel somehow. - } - - if (rtp_channel_.get() && rtcp_channel_.get()) { - DCHECK(!initialized_); - initialized_ = true; - initialized_callback_.Run(true); - } -} - -void RtpVideoWriter::Close() { - rtp_writer_.Close(); - rtp_channel_.reset(); - rtcp_channel_.reset(); - if (session_) { - session_->CancelChannelCreation(kVideoRtpChannelName); - session_->CancelChannelCreation(kVideoRtcpChannelName); - session_ = NULL; - } -} - -bool RtpVideoWriter::is_connected() { - return rtp_channel_.get() && rtcp_channel_.get(); -} - -void RtpVideoWriter::ProcessVideoPacket(const scoped_ptr<VideoPacket> packet, - const base::Closure& done) { - CHECK(packet->format().encoding() == VideoPacketFormat::ENCODING_VP8) - << "Only VP8 is supported in RTP."; - - CompoundBuffer payload; - // TODO(sergeyu): This copy would not be necessary CompoundBuffer was used - // inside of VideoPacket. - payload.AppendCopyOf(packet->data().data(), packet->data().size()); - - Vp8Descriptor vp8_desriptor; - // TODO(sergeyu): Add a flag in VideoPacket that indicates whether this is a - // key frame or not. - vp8_desriptor.non_reference_frame = false; - vp8_desriptor.picture_id = kuint32max; - - int position = 0; - while (position < payload.total_bytes()) { - int size = std::min(kMtu, payload.total_bytes() - position); - - // Frame beginning flag is set only for the first packet in the first - // partition. - vp8_desriptor.frame_beginning = - (packet->flags() & VideoPacket::FIRST_PACKET) != 0 && position == 0; - - // Marker bit is set only for the last packet in the last partition. - bool marker = (position + size) == payload.total_bytes() && - (packet->flags() & VideoPacket::LAST_PACKET) != 0; - - // Set fragmentation flag appropriately. - if (position == 0) { - if (size == payload.total_bytes()) { - vp8_desriptor.fragmentation_info = Vp8Descriptor::NOT_FRAGMENTED; - } else { - vp8_desriptor.fragmentation_info = Vp8Descriptor::FIRST_FRAGMENT; - } - } else { - if (position + size == payload.total_bytes()) { - vp8_desriptor.fragmentation_info = Vp8Descriptor::LAST_FRAGMENT; - } else { - vp8_desriptor.fragmentation_info = Vp8Descriptor::MIDDLE_FRAGMENT; - } - } - - // Create CompoundBuffer for the chunk. - CompoundBuffer chunk; - chunk.CopyFrom(payload, position, position + size); - - // And send it. - rtp_writer_.SendPacket(packet->timestamp(), marker, vp8_desriptor, chunk); - - position += size; - } - DCHECK_EQ(position, payload.total_bytes()); - - if (!done.is_null()) - done.Run(); -} - -int RtpVideoWriter::GetPendingPackets() { - return rtp_writer_.GetPendingPackets(); -} - -} // namespace protocol -} // namespace remoting diff --git a/remoting/protocol/rtp_video_writer.h b/remoting/protocol/rtp_video_writer.h deleted file mode 100644 index 5bc7c91..0000000 --- a/remoting/protocol/rtp_video_writer.h +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) 2012 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 REMOTING_PROTOCOL_RTP_VIDEO_WRITER_H_ -#define REMOTING_PROTOCOL_RTP_VIDEO_WRITER_H_ - -#include "base/memory/scoped_ptr.h" -#include "remoting/protocol/rtp_writer.h" -#include "remoting/protocol/video_writer.h" - -namespace base { -class MessageLoopProxy; -} // namespace base - -namespace remoting { -namespace protocol { - -class Session; - -class RtpVideoWriter : public VideoWriter { - public: - RtpVideoWriter(base::MessageLoopProxy* message_loop); - virtual ~RtpVideoWriter(); - - // VideoWriter interface. - virtual void Init(Session* session, - const InitializedCallback& callback) OVERRIDE; - virtual void Close() OVERRIDE; - virtual bool is_connected() OVERRIDE; - - // VideoStub interface. - virtual void ProcessVideoPacket(scoped_ptr<VideoPacket> packet, - const base::Closure& done) OVERRIDE; - virtual int GetPendingPackets() OVERRIDE; - - private: - void OnChannelReady(bool rtp, scoped_ptr<net::Socket> socket); - - Session* session_; - - bool initialized_; - InitializedCallback initialized_callback_; - - scoped_ptr<net::Socket> rtp_channel_; - RtpWriter rtp_writer_; - scoped_ptr<net::Socket> rtcp_channel_; - - DISALLOW_COPY_AND_ASSIGN(RtpVideoWriter); -}; - -} // namespace protocol -} // namespace remoting - -#endif // REMOTING_PROTOCOL_RTP_VIDEO_WRITER_H_ diff --git a/remoting/protocol/rtp_video_writer_unittest.cc b/remoting/protocol/rtp_video_writer_unittest.cc deleted file mode 100644 index c2c7555..0000000 --- a/remoting/protocol/rtp_video_writer_unittest.cc +++ /dev/null @@ -1,192 +0,0 @@ -// Copyright (c) 2012 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. - -#include <string> -#include <vector> - -#include "base/bind.h" -#include "base/message_loop.h" -#include "base/message_loop_proxy.h" -#include "base/string_number_conversions.h" -#include "remoting/base/constants.h" -#include "remoting/proto/video.pb.h" -#include "remoting/protocol/fake_session.h" -#include "remoting/protocol/rtp_reader.h" -#include "remoting/protocol/rtp_utils.h" -#include "remoting/protocol/rtp_video_writer.h" -#include "testing/gtest/include/gtest/gtest.h" - -using net::IOBuffer; -using std::string; -using std::vector; - -namespace remoting { -namespace protocol { - -namespace { - -bool ParsePacket(const string& data, RtpPacket* packet) { - int header_size = UnpackRtpHeader( - reinterpret_cast<const uint8*>(&*data.begin()), - data.size(), packet->mutable_header()); - if (header_size < 0) { - return false; - } - - int descriptor_size = UnpackVp8Descriptor( - reinterpret_cast<const uint8*>(&*data.begin()) + header_size, - data.size() - header_size, packet->mutable_vp8_descriptor()); - if (descriptor_size < 0) { - return false; - } - - packet->mutable_payload()->AppendCopyOf( - &*data.begin() + header_size + descriptor_size, - data.size() - header_size - descriptor_size); - - return true; -} - -} // namespace - -class RtpVideoWriterTest : public testing::Test { - protected: - struct ExpectedPacket { - bool first; - Vp8Descriptor::FragmentationInfo fragmentation_info; - bool last; - }; - - RtpVideoWriterTest() - : writer_(base::MessageLoopProxy::current()) { - } - - virtual void SetUp() { - session_.reset(new FakeSession()); - writer_.Init(session_.get(), - base::Bind(&RtpVideoWriterTest::OnWriterInitialized, - base::Unretained(this))); - } - - void OnWriterInitialized(bool success) { - ASSERT_TRUE(success); - } - - void InitData(int size) { - data_.resize(size); - for (int i = 0; i < size; ++i) { - data_[i] = static_cast<char>(i); - } - } - - void InitPacket(int size, bool first, bool last) { - InitData(size); - - packet_.reset(new VideoPacket()); - packet_->mutable_format()->set_encoding(VideoPacketFormat::ENCODING_VP8); - if (first) - packet_->set_flags(packet_->flags() | VideoPacket::FIRST_PACKET); - if (last) - packet_->set_flags(packet_->flags() | VideoPacket::LAST_PACKET); - packet_->mutable_data()->assign(data_.begin(), data_.end()); - } - - bool CompareData(const CompoundBuffer& buffer, char* data, int size) { - scoped_refptr<IOBuffer> buffer_data = buffer.ToIOBufferWithSize(); - return buffer.total_bytes() == size && - memcmp(buffer_data->data(), data, size) == 0; - } - - void VerifyResult(const ExpectedPacket expected[], - int count) { - const vector<string>& rtp_packets = - session_->GetDatagramChannel(kVideoRtpChannelName)->written_packets(); - ASSERT_EQ(count, static_cast<int>(rtp_packets.size())); - int pos = 0; - for (int i = 0; i < count; ++i) { - SCOPED_TRACE("Packet " + base::IntToString(i)); - - RtpPacket packet; - ASSERT_TRUE(ParsePacket(rtp_packets[i], &packet)); - EXPECT_EQ(expected[i].first, packet.vp8_descriptor().frame_beginning); - EXPECT_EQ(expected[i].last, packet.header().marker); - EXPECT_EQ(expected[i].fragmentation_info, - packet.vp8_descriptor().fragmentation_info); - EXPECT_TRUE(CompareData(packet.payload(), &*data_.begin() + pos, - packet.payload().total_bytes())); - pos += packet.payload().total_bytes(); - } - EXPECT_EQ(pos, static_cast<int>(data_.size())); - } - - MessageLoop message_loop_; - - scoped_ptr<FakeSession> session_; - RtpVideoWriter writer_; - - vector<char> data_; - scoped_ptr<VideoPacket> packet_; -}; - -TEST_F(RtpVideoWriterTest, NotFragmented_FirstPacket) { - InitPacket(1024, true, false); - writer_.ProcessVideoPacket(packet_.Pass(), base::Closure()); - message_loop_.RunAllPending(); - - ExpectedPacket expected[] = { - { true, Vp8Descriptor::NOT_FRAGMENTED, false } - }; - VerifyResult(expected, arraysize(expected)); -} - -TEST_F(RtpVideoWriterTest, NotFragmented_LastPackes) { - InitPacket(1024, false, true); - writer_.ProcessVideoPacket(packet_.Pass(), base::Closure()); - message_loop_.RunAllPending(); - - ExpectedPacket expected[] = { - { false, Vp8Descriptor::NOT_FRAGMENTED, true } - }; - VerifyResult(expected, arraysize(expected)); -} - -TEST_F(RtpVideoWriterTest, TwoFragments_FirstPacket) { - InitPacket(2000, true, false); - writer_.ProcessVideoPacket(packet_.Pass(), base::Closure()); - message_loop_.RunAllPending(); - - ExpectedPacket expected[] = { - { true, Vp8Descriptor::FIRST_FRAGMENT, false }, - { false, Vp8Descriptor::LAST_FRAGMENT, false }, - }; - VerifyResult(expected, arraysize(expected)); -} - -TEST_F(RtpVideoWriterTest, TwoFragments_LastPacket) { - InitPacket(2000, false, true); - writer_.ProcessVideoPacket(packet_.Pass(), base::Closure()); - message_loop_.RunAllPending(); - - ExpectedPacket expected[] = { - { false, Vp8Descriptor::FIRST_FRAGMENT, false }, - { false, Vp8Descriptor::LAST_FRAGMENT, true }, - }; - VerifyResult(expected, arraysize(expected)); -} - -TEST_F(RtpVideoWriterTest, ThreeFragments) { - InitPacket(3000, true, true); - writer_.ProcessVideoPacket(packet_.Pass(), base::Closure()); - message_loop_.RunAllPending(); - - ExpectedPacket expected[] = { - { true, Vp8Descriptor::FIRST_FRAGMENT, false }, - { false, Vp8Descriptor::MIDDLE_FRAGMENT, false }, - { false, Vp8Descriptor::LAST_FRAGMENT, true }, - }; - VerifyResult(expected, arraysize(expected)); -} - -} // namespace protocol -} // namespace remoting diff --git a/remoting/protocol/rtp_writer.cc b/remoting/protocol/rtp_writer.cc deleted file mode 100644 index 9b57ea0..0000000 --- a/remoting/protocol/rtp_writer.cc +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright (c) 2010 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. - -#include "remoting/protocol/rtp_writer.h" - -#include "net/base/io_buffer.h" -#include "net/base/net_errors.h" -#include "remoting/base/compound_buffer.h" -#include "remoting/protocol/rtp_utils.h" - -namespace remoting { -namespace protocol { - -namespace { -const uint8 kRtpPayloadTypePrivate = 96; -} // namespace - -RtpWriter::RtpWriter(base::MessageLoopProxy* message_loop) - : last_packet_number_(0), - buffered_rtp_writer_(new BufferedDatagramWriter(message_loop)) { -} - -RtpWriter::~RtpWriter() { } - -// Initializes the writer. Must be called on the thread the sockets belong -// to. -void RtpWriter::Init(net::Socket* rtp_socket) { - buffered_rtp_writer_->Init( - rtp_socket, BufferedSocketWriter::WriteFailedCallback()); -} - -void RtpWriter::Close() { - buffered_rtp_writer_->Close(); -} - -void RtpWriter::SendPacket(uint32 timestamp, bool marker, - const Vp8Descriptor& vp8_descriptor, - const CompoundBuffer& payload) { - RtpHeader header; - header.padding = false; - header.extension = false; - header.sources = 0; - header.marker = marker; - header.payload_type = kRtpPayloadTypePrivate; - header.timestamp = timestamp; - - // TODO(sergeyu): RTP requires that SSRC is chosen randomly by each - // participant. There are only two participants in chromoting session, - // so SSRC isn't useful. Implement it in future if neccessary. - header.sync_source_id = 0; - - header.sequence_number = last_packet_number_ & 0xFFFF; - ++last_packet_number_; - - int header_size = GetRtpHeaderSize(header); - int vp8_descriptor_size = GetVp8DescriptorSize(vp8_descriptor); - int payload_size = payload.total_bytes(); - int total_size = header_size + vp8_descriptor_size + payload_size; - - net::IOBufferWithSize* buffer = new net::IOBufferWithSize(total_size); - - // Pack header. - PackRtpHeader(header, reinterpret_cast<uint8*>(buffer->data()), - header_size); - - // Pack VP8 descriptor. - PackVp8Descriptor(vp8_descriptor, - reinterpret_cast<uint8*>(buffer->data()) + header_size, - vp8_descriptor_size); - - // Copy payload to the buffer. - payload.CopyTo(buffer->data() + header_size + vp8_descriptor_size, - payload_size); - - // And write the packet. - buffered_rtp_writer_->Write(buffer, base::Closure()); -} - -int RtpWriter::GetPendingPackets() { - return buffered_rtp_writer_->GetBufferChunks(); -} - -} // namespace protocol -} // namespace remoting diff --git a/remoting/protocol/rtp_writer.h b/remoting/protocol/rtp_writer.h deleted file mode 100644 index 8ce626b..0000000 --- a/remoting/protocol/rtp_writer.h +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) 2010 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 REMOTING_PROTOCOL_RTP_WRITER_H_ -#define REMOTING_PROTOCOL_RTP_WRITER_H_ - -#include "net/socket/socket.h" -#include "remoting/protocol/buffered_socket_writer.h" -#include "remoting/protocol/rtp_utils.h" - -namespace remoting { - -class CompoundBuffer; - -namespace protocol { - -class RtpWriter { - public: - RtpWriter(base::MessageLoopProxy* message_loop); - virtual ~RtpWriter(); - - // Initializes the writer. Must be called on the thread the socket - // belongs to. - void Init(net::Socket* socket); - void Close(); - - // Sends next packet. The packet is mutated by - void SendPacket(uint32 timestamp, bool marker, - const Vp8Descriptor& vp8_descriptor, - const CompoundBuffer& payload); - - // Returns number of packets queued in the buffer. - int GetPendingPackets(); - - private: - uint32 last_packet_number_; - - scoped_refptr<BufferedDatagramWriter> buffered_rtp_writer_; -}; - -} // namespace protocol -} // namespace remoting - -#endif // REMOTING_PROTOCOL_RTP_WRITER_H_ diff --git a/remoting/protocol/session_config.h b/remoting/protocol/session_config.h index 07dcaa2..e1cd39e 100644 --- a/remoting/protocol/session_config.h +++ b/remoting/protocol/session_config.h @@ -23,8 +23,6 @@ struct ChannelConfig { enum TransportType { TRANSPORT_STREAM, TRANSPORT_DATAGRAM, - TRANSPORT_SRTP, - TRANSPORT_RTP_DTLS, }; enum Codec { diff --git a/remoting/protocol/video_reader.cc b/remoting/protocol/video_reader.cc index 464b512..692008a 100644 --- a/remoting/protocol/video_reader.cc +++ b/remoting/protocol/video_reader.cc @@ -6,7 +6,6 @@ #include "remoting/protocol/session_config.h" #include "remoting/protocol/protobuf_video_reader.h" -#include "remoting/protocol/rtp_video_reader.h" namespace remoting { namespace protocol { @@ -17,9 +16,7 @@ VideoReader::~VideoReader() { } VideoReader* VideoReader::Create(base::MessageLoopProxy* message_loop, const SessionConfig& config) { const ChannelConfig& video_config = config.video_config(); - if (video_config.transport == ChannelConfig::TRANSPORT_SRTP) { - return new RtpVideoReader(message_loop); - } else if (video_config.transport == ChannelConfig::TRANSPORT_STREAM) { + if (video_config.transport == ChannelConfig::TRANSPORT_STREAM) { if (video_config.codec == ChannelConfig::CODEC_VP8) { return new ProtobufVideoReader(VideoPacketFormat::ENCODING_VP8); } else if (video_config.codec == ChannelConfig::CODEC_ZIP) { diff --git a/remoting/protocol/video_reader.h b/remoting/protocol/video_reader.h index f1269ec..d327f66 100644 --- a/remoting/protocol/video_reader.h +++ b/remoting/protocol/video_reader.h @@ -2,9 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// VideoReader is a generic interface for a video stream reader. RtpVideoReader -// and ProtobufVideoReader implement this interface for RTP and protobuf video -// streams. VideoReader is used by ConnectionToHost to read video stream. +// VideoReader is a generic interface used by ConnectionToHost to read +// video stream. ProtobufVideoReader implements this interface for +// protobuf video stream. #ifndef REMOTING_PROTOCOL_VIDEO_READER_H_ #define REMOTING_PROTOCOL_VIDEO_READER_H_ diff --git a/remoting/protocol/video_writer.cc b/remoting/protocol/video_writer.cc index 8ebf285..b3e0f03 100644 --- a/remoting/protocol/video_writer.cc +++ b/remoting/protocol/video_writer.cc @@ -6,7 +6,6 @@ #include "remoting/protocol/session_config.h" #include "remoting/protocol/protobuf_video_writer.h" -#include "remoting/protocol/rtp_video_writer.h" namespace remoting { namespace protocol { @@ -17,9 +16,7 @@ VideoWriter::~VideoWriter() { } VideoWriter* VideoWriter::Create(base::MessageLoopProxy* message_loop, const SessionConfig& config) { const ChannelConfig& video_config = config.video_config(); - if (video_config.transport == ChannelConfig::TRANSPORT_SRTP) { - return new RtpVideoWriter(message_loop); - } else if (video_config.transport == ChannelConfig::TRANSPORT_STREAM) { + if (video_config.transport == ChannelConfig::TRANSPORT_STREAM) { return new ProtobufVideoWriter(message_loop); } return NULL; diff --git a/remoting/protocol/video_writer.h b/remoting/protocol/video_writer.h index 9a7ced9..67d3a7b 100644 --- a/remoting/protocol/video_writer.h +++ b/remoting/protocol/video_writer.h @@ -2,10 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// VideoWriter is a generic interface for a video stream writer. RtpVideoWriter -// and ProtobufVideoWriter implement this interface for RTP and protobuf video -// streams. VideoWriter is used by ConnectionToClient to write into the video -// stream. +// VideoWriter is a generic interface used by ConnectionToClient to +// write into the video stream. ProtobufVideoWriter implements this +// interface for protobuf video streams. #ifndef REMOTING_PROTOCOL_VIDEO_WRITER_H_ #define REMOTING_PROTOCOL_VIDEO_WRITER_H_ diff --git a/remoting/remoting.gyp b/remoting/remoting.gyp index ef16878..9474b66 100644 --- a/remoting/remoting.gyp +++ b/remoting/remoting.gyp @@ -1519,18 +1519,6 @@ 'protocol/protobuf_video_reader.h', 'protocol/protobuf_video_writer.cc', 'protocol/protobuf_video_writer.h', - 'protocol/rtcp_writer.cc', - 'protocol/rtcp_writer.h', - 'protocol/rtp_reader.cc', - 'protocol/rtp_reader.h', - 'protocol/rtp_utils.cc', - 'protocol/rtp_utils.h', - 'protocol/rtp_video_reader.cc', - 'protocol/rtp_video_reader.h', - 'protocol/rtp_video_writer.cc', - 'protocol/rtp_video_writer.h', - 'protocol/rtp_writer.cc', - 'protocol/rtp_writer.h', 'protocol/session.h', 'protocol/session_config.cc', 'protocol/session_config.h', @@ -1680,8 +1668,6 @@ 'protocol/protocol_mock_objects.cc', 'protocol/protocol_mock_objects.h', 'protocol/ppapi_module_stub.cc', - 'protocol/rtp_video_reader_unittest.cc', - 'protocol/rtp_video_writer_unittest.cc', 'protocol/ssl_hmac_channel_authenticator_unittest.cc', 'protocol/v1_authenticator_unittest.cc', 'protocol/v2_authenticator_unittest.cc', |