diff options
Diffstat (limited to 'remoting/protocol')
23 files changed, 489 insertions, 26 deletions
diff --git a/remoting/protocol/chromotocol_config.h b/remoting/protocol/chromotocol_config.h index bd0bcbc..aef2ecc 100644 --- a/remoting/protocol/chromotocol_config.h +++ b/remoting/protocol/chromotocol_config.h @@ -25,8 +25,9 @@ struct ChannelConfig { enum Codec { CODEC_UNDEFINED, // Used for event and control channels. - CODEC_VP8, + CODEC_VERBATIM, CODEC_ZIP, + CODEC_VP8, }; ChannelConfig(); diff --git a/remoting/protocol/message_decoder.h b/remoting/protocol/message_decoder.h index d28d9e0..207dee5 100644 --- a/remoting/protocol/message_decoder.h +++ b/remoting/protocol/message_decoder.h @@ -11,6 +11,7 @@ #include "base/ref_counted.h" #include "base/scoped_ptr.h" #include "google/protobuf/message_lite.h" +#include "remoting/base/multiple_array_input_stream.h" namespace net { class DrainableIOBuffer; @@ -25,7 +26,6 @@ class ClientControlMessage; class ClientEventMessage; class HostControlMessage; class HostEventMessage; -class MultipleArrayInputStream; // MessageDecoder uses MultipleArrayInputStream to decode bytes into // protocol buffer messages. This can be used to decode bytes received from diff --git a/remoting/protocol/message_reader.h b/remoting/protocol/message_reader.h index d3540bb..44e6a5c 100644 --- a/remoting/protocol/message_reader.h +++ b/remoting/protocol/message_reader.h @@ -10,6 +10,7 @@ #include "base/scoped_ptr.h" #include "base/task.h" #include "net/base/completion_callback.h" +#include "net/base/io_buffer.h" #include "remoting/protocol/message_decoder.h" namespace net { diff --git a/remoting/protocol/protobuf_video_reader.cc b/remoting/protocol/protobuf_video_reader.cc new file mode 100644 index 0000000..70ac3cf --- /dev/null +++ b/remoting/protocol/protobuf_video_reader.cc @@ -0,0 +1,30 @@ +// 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/protobuf_video_reader.h" + +#include "base/task.h" +#include "remoting/protocol/chromotocol_connection.h" + +namespace remoting { + +ProtobufVideoReader::ProtobufVideoReader() { } +ProtobufVideoReader::~ProtobufVideoReader() { } + +void ProtobufVideoReader::Init(ChromotocolConnection* connection, + VideoStub* video_stub) { + reader_.Init<VideoPacket>(connection->video_channel(), + NewCallback(this, &ProtobufVideoReader::OnNewData)); + video_stub_ = video_stub; +} + +void ProtobufVideoReader::Close() { + reader_.Close(); +} + +void ProtobufVideoReader::OnNewData(VideoPacket* packet) { + video_stub_->ProcessVideoPacket(packet, new DeleteTask<VideoPacket>(packet)); +} + +} // namespace remoting diff --git a/remoting/protocol/protobuf_video_reader.h b/remoting/protocol/protobuf_video_reader.h new file mode 100644 index 0000000..cad98c5 --- /dev/null +++ b/remoting/protocol/protobuf_video_reader.h @@ -0,0 +1,35 @@ +// 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_PROTOBUF_VIDEO_READER_H_ +#define REMOTING_PROTOCOL_PROTOBUF_VIDEO_READER_H_ + +#include "remoting/protocol/message_reader.h" +#include "remoting/protocol/video_reader.h" + +namespace remoting { + +class ProtobufVideoReader : public VideoReader { + public: + ProtobufVideoReader(); + virtual ~ProtobufVideoReader(); + + // VideoReader interface. + virtual void Init(ChromotocolConnection* connection, VideoStub* video_stub); + virtual void Close(); + + private: + void OnNewData(VideoPacket* packet); + + MessageReader reader_; + + // The stub that processes all received packets. + VideoStub* video_stub_; + + DISALLOW_COPY_AND_ASSIGN(ProtobufVideoReader); +}; + +} // namespace remoting + +#endif // REMOTING_PROTOCOL_PROTOBUF_VIDEO_READER_H_ diff --git a/remoting/protocol/protobuf_video_writer.cc b/remoting/protocol/protobuf_video_writer.cc new file mode 100644 index 0000000..96b4e34 --- /dev/null +++ b/remoting/protocol/protobuf_video_writer.cc @@ -0,0 +1,36 @@ +// 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/protobuf_video_writer.h" + +#include "remoting/protocol/chromotocol_connection.h" +#include "remoting/protocol/rtp_writer.h" +#include "remoting/protocol/util.h" + +namespace remoting { + +ProtobufVideoWriter::ProtobufVideoWriter() { } + +ProtobufVideoWriter::~ProtobufVideoWriter() { } + +void ProtobufVideoWriter::Init(ChromotocolConnection* connection) { + buffered_writer_ = new BufferedSocketWriter(); + // TODO(sergeyu): Provide WriteFailedCallback for the buffered writer. + buffered_writer_->Init(connection->video_channel(), NULL); +} + +void ProtobufVideoWriter::SendPacket(const VideoPacket& packet) { + buffered_writer_->Write(SerializeAndFrameMessage(packet)); +} + +int ProtobufVideoWriter::GetPendingPackets() { + return buffered_writer_->GetBufferChunks(); +} + + +void ProtobufVideoWriter::Close() { + buffered_writer_->Close(); +} + +} // namespace remoting diff --git a/remoting/protocol/protobuf_video_writer.h b/remoting/protocol/protobuf_video_writer.h new file mode 100644 index 0000000..02d3034 --- /dev/null +++ b/remoting/protocol/protobuf_video_writer.h @@ -0,0 +1,34 @@ +// 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_PROTOBUF_VIDEO_WRITER_H_ +#define REMOTING_PROTOCOL_PROTOBUF_VIDEO_WRITER_H_ + +#include "base/ref_counted.h" +#include "remoting/protocol/video_writer.h" + +namespace remoting { + +class BufferedSocketWriter; + +class ProtobufVideoWriter : public VideoWriter { + public: + ProtobufVideoWriter(); + virtual ~ProtobufVideoWriter(); + + // VideoWriter interface. + virtual void Init(ChromotocolConnection* connection); + virtual void SendPacket(const VideoPacket& packet); + virtual int GetPendingPackets(); + virtual void Close(); + + private: + scoped_refptr<BufferedSocketWriter> buffered_writer_; + + DISALLOW_COPY_AND_ASSIGN(ProtobufVideoWriter); +}; + +} // namespace remoting + +#endif // REMOTING_PROTOCOL_PROTOBUF_VIDEO_WRITER_H_ diff --git a/remoting/protocol/rtp_reader.cc b/remoting/protocol/rtp_reader.cc index a3659fb..31b133e 100644 --- a/remoting/protocol/rtp_reader.cc +++ b/remoting/protocol/rtp_reader.cc @@ -34,7 +34,7 @@ void RtpReader::OnDataReceived(net::IOBuffer* buffer, int data_size) { packet.payload = buffer->data() + header_size; packet.payload_size = data_size - header_size; - on_message_callback_->Run(&packet); + on_message_callback_->Run(packet); } } // namespace remoting diff --git a/remoting/protocol/rtp_reader.h b/remoting/protocol/rtp_reader.h index b9a12df..3fc3983 100644 --- a/remoting/protocol/rtp_reader.h +++ b/remoting/protocol/rtp_reader.h @@ -28,7 +28,7 @@ class RtpReader : public SocketReaderBase { // The OnMessageCallback is called whenever a new message is received. // Ownership of the message is passed the callback. - typedef Callback1<RtpPacket*>::Type OnMessageCallback; + typedef Callback1<const RtpPacket&>::Type 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 diff --git a/remoting/protocol/rtp_utils.cc b/remoting/protocol/rtp_utils.cc index df10af2..25cbefc 100644 --- a/remoting/protocol/rtp_utils.cc +++ b/remoting/protocol/rtp_utils.cc @@ -48,13 +48,10 @@ void PackRtpHeader(uint8* buffer, int buffer_size, } static inline uint8 ExtractBits(uint8 byte, int bits_count, int shift) { - return (byte >> shift) && ((1 << bits_count) - 1); + return (byte >> shift) & ((1 << bits_count) - 1); } int UnpackRtpHeader(const uint8* buffer, int buffer_size, RtpHeader* header) { - DCHECK_LT(header->sources, 1 << 4); - DCHECK_LT(header->payload_type, 1 << 7); - if (buffer_size < kRtpBaseHeaderSize) { return -1; } @@ -69,13 +66,13 @@ int UnpackRtpHeader(const uint8* buffer, int buffer_size, RtpHeader* header) { header->sources = ExtractBits(buffer[0], 4, 0); header->marker = ExtractBits(buffer[1], 1, 7) != 0; - header->sources = ExtractBits(buffer[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_LE(header->sources, 16); + DCHECK_LT(header->sources, 16); if (buffer_size < GetRtpHeaderSize(header->sources)) { return -1; diff --git a/remoting/protocol/rtp_video_reader.cc b/remoting/protocol/rtp_video_reader.cc new file mode 100644 index 0000000..8de6d91 --- /dev/null +++ b/remoting/protocol/rtp_video_reader.cc @@ -0,0 +1,41 @@ +// 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_video_reader.h" + +#include "base/task.h" +#include "remoting/protocol/chromotocol_connection.h" + +namespace remoting { + +RtpVideoReader::RtpVideoReader() { } +RtpVideoReader::~RtpVideoReader() { } + +void RtpVideoReader::Init(ChromotocolConnection* connection, + VideoStub* video_stub) { + rtp_reader_.Init(connection->video_rtp_channel(), + NewCallback(this, &RtpVideoReader::OnRtpPacket)); + video_stub_ = video_stub; +} + +void RtpVideoReader::Close() { + rtp_reader_.Close(); +} + +void RtpVideoReader::OnRtpPacket(const RtpPacket& rtp_packet) { + VideoPacket* packet = new VideoPacket(); + packet->set_data(rtp_packet.payload, rtp_packet.payload_size); + + packet->mutable_format()->set_encoding(VideoPacketFormat::ENCODING_VP8); + packet->set_flags(rtp_packet.header.marker ? VideoPacket::LAST_PACKET : 0); + packet->mutable_format()->set_pixel_format(PIXEL_FORMAT_RGB32); + packet->mutable_format()->set_x(0); + packet->mutable_format()->set_y(0); + packet->mutable_format()->set_width(800); + packet->mutable_format()->set_height(600); + + video_stub_->ProcessVideoPacket(packet, new DeleteTask<VideoPacket>(packet)); +} + +} // namespace remoting diff --git a/remoting/protocol/rtp_video_reader.h b/remoting/protocol/rtp_video_reader.h new file mode 100644 index 0000000..d7f526e --- /dev/null +++ b/remoting/protocol/rtp_video_reader.h @@ -0,0 +1,35 @@ +// 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_VIDEO_READER_H_ +#define REMOTING_PROTOCOL_RTP_VIDEO_READER_H_ + +#include "remoting/protocol/rtp_reader.h" +#include "remoting/protocol/video_reader.h" + +namespace remoting { + +class RtpVideoReader : public VideoReader { + public: + RtpVideoReader(); + virtual ~RtpVideoReader(); + + // VideoReader interface. + virtual void Init(ChromotocolConnection* connection, VideoStub* video_stub); + virtual void Close(); + + private: + void OnRtpPacket(const RtpPacket& rtp_packet); + + RtpReader rtp_reader_; + + // The stub that processes all received packets. + VideoStub* video_stub_; + + DISALLOW_COPY_AND_ASSIGN(RtpVideoReader); +}; + +} // namespace remoting + +#endif // REMOTING_PROTOCOL_RTP_VIDEO_READER_H_ diff --git a/remoting/protocol/rtp_video_writer.cc b/remoting/protocol/rtp_video_writer.cc new file mode 100644 index 0000000..6307c0c --- /dev/null +++ b/remoting/protocol/rtp_video_writer.cc @@ -0,0 +1,35 @@ +// 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_video_writer.h" + +#include "remoting/protocol/chromotocol_connection.h" +#include "remoting/protocol/rtp_writer.h" + +namespace remoting { + +RtpVideoWriter::RtpVideoWriter() { } + +RtpVideoWriter::~RtpVideoWriter() { } + +void RtpVideoWriter::Init(ChromotocolConnection* connection) { + rtp_writer_.Init(connection->video_rtp_channel(), + connection->video_rtcp_channel()); +} + +void RtpVideoWriter::SendPacket(const VideoPacket& packet) { + rtp_writer_.SendPacket(packet.data().data(), packet.data().length(), + packet.timestamp()); +} + +int RtpVideoWriter::GetPendingPackets() { + return rtp_writer_.GetPendingPackets(); +} + + +void RtpVideoWriter::Close() { + rtp_writer_.Close(); +} + +} // namespace remoting diff --git a/remoting/protocol/rtp_video_writer.h b/remoting/protocol/rtp_video_writer.h new file mode 100644 index 0000000..4084576 --- /dev/null +++ b/remoting/protocol/rtp_video_writer.h @@ -0,0 +1,32 @@ +// 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_VIDEO_WRITER_H_ +#define REMOTING_PROTOCOL_RTP_VIDEO_WRITER_H_ + +#include "remoting/protocol/rtp_writer.h" +#include "remoting/protocol/video_writer.h" + +namespace remoting { + +class RtpVideoWriter : public VideoWriter { + public: + RtpVideoWriter(); + virtual ~RtpVideoWriter(); + + // VideoWriter interface. + virtual void Init(ChromotocolConnection* connection); + virtual void SendPacket(const VideoPacket& packet); + virtual int GetPendingPackets(); + virtual void Close(); + + private: + RtpWriter rtp_writer_; + + DISALLOW_COPY_AND_ASSIGN(RtpVideoWriter); +}; + +} // namespace remoting + +#endif // REMOTING_PROTOCOL_RTP_VIDEO_WRITER_H_ diff --git a/remoting/protocol/rtp_writer.cc b/remoting/protocol/rtp_writer.cc index a9df798..909a572 100644 --- a/remoting/protocol/rtp_writer.cc +++ b/remoting/protocol/rtp_writer.cc @@ -32,7 +32,7 @@ void RtpWriter::Init(net::Socket* rtp_socket, net::Socket* rtcp_socket) { rtcp_socket_ = rtcp_socket; } -void RtpWriter::SendPacket(const char* data, int packet_size, +void RtpWriter::SendPacket(const char* payload, int payload_size, uint32 timestamp) { RtpHeader header; header.padding = false; @@ -49,15 +49,15 @@ void RtpWriter::SendPacket(const char* data, int packet_size, // TODO(sergeyu): Add VP8 payload header. int position = 0; - while (position < packet_size) { + while (position < payload_size) { // Allocate buffer. - int size = std::max(kMtu, packet_size - position); - int header_size = GetRtpHeaderSize(header.sources) + size; + int size = std::min(kMtu, payload_size - position); + int header_size = GetRtpHeaderSize(header.sources); int total_size = size + header_size; net::IOBufferWithSize* buffer = new net::IOBufferWithSize(total_size); // Set marker if this is the last frame. - header.marker = (position + size) == packet_size; + header.marker = (position + size) == payload_size; // TODO(sergeyu): Handle sequence number wrapping. header.sequence_number = last_packet_number_; @@ -68,7 +68,7 @@ void RtpWriter::SendPacket(const char* data, int packet_size, header); // Copy data to the buffer. - memcpy(buffer->data() + header_size, data + position, size); + memcpy(buffer->data() + header_size, payload + position, size); // Send it. buffered_rtp_writer_->Write(buffer); @@ -76,7 +76,11 @@ void RtpWriter::SendPacket(const char* data, int packet_size, position += size; } - DCHECK_EQ(position, packet_size); + DCHECK_EQ(position, payload_size); +} + +int RtpWriter::GetPendingPackets() { + return buffered_rtp_writer_->GetBufferChunks(); } // Stop writing and drop pending data. Must be called from the same thread as diff --git a/remoting/protocol/rtp_writer.h b/remoting/protocol/rtp_writer.h index 5ba7501..6bcd7ec 100644 --- a/remoting/protocol/rtp_writer.h +++ b/remoting/protocol/rtp_writer.h @@ -19,8 +19,11 @@ class RtpWriter { // to. void Init(net::Socket* rtp_socket, net::Socket* rtcp_socket); - void SendPacket(const char* buffer, int packet_size, - uint32 timestamp); + // Sends next packet. + void SendPacket(const char* payload, int payload_size, uint32 timestamp); + + // Returns number of packets queued in the buffer. + int GetPendingPackets(); // Stop writing and drop pending data. Must be called from the same thread as // Init(). diff --git a/remoting/protocol/stream_writer.cc b/remoting/protocol/stream_writer.cc index ce91650..9d1f2a7 100644 --- a/remoting/protocol/stream_writer.cc +++ b/remoting/protocol/stream_writer.cc @@ -5,6 +5,7 @@ #include "remoting/protocol/stream_writer.h" #include "base/message_loop.h" +#include "remoting/protocol/buffered_socket_writer.h" #include "remoting/protocol/chromotocol_connection.h" #include "remoting/protocol/util.h" @@ -34,13 +35,11 @@ void StreamWriterBase::Close() { buffered_writer_->Close(); } -bool EventStreamWriter::SendMessage( - const ChromotingClientMessage& message) { +bool EventStreamWriter::SendMessage(const ChromotingClientMessage& message) { return buffered_writer_->Write(SerializeAndFrameMessage(message)); } -bool VideoStreamWriter::SendMessage( - const ChromotingHostMessage& message) { +bool ControlStreamWriter::SendMessage(const ChromotingHostMessage& message) { return buffered_writer_->Write(SerializeAndFrameMessage(message)); } diff --git a/remoting/protocol/stream_writer.h b/remoting/protocol/stream_writer.h index 75f6180..f5b018b 100644 --- a/remoting/protocol/stream_writer.h +++ b/remoting/protocol/stream_writer.h @@ -5,12 +5,16 @@ #ifndef REMOTING_PROTOCOL_STREAM_WRITER_H_ #define REMOTING_PROTOCOL_STREAM_WRITER_H_ +#include "base/ref_counted.h" #include "remoting/proto/internal.pb.h" -#include "remoting/protocol/buffered_socket_writer.h" + +namespace net { +class Socket; +} // namespace net namespace remoting { -class ChromotingConnection; +class BufferedSocketWriter; class StreamWriterBase { public: @@ -41,7 +45,7 @@ class EventStreamWriter : public StreamWriterBase { bool SendMessage(const ChromotingClientMessage& message); }; -class VideoStreamWriter : public StreamWriterBase { +class ControlStreamWriter : public StreamWriterBase { public: // Sends the |message| or returns false if called before Init(). // Can be called on any thread. diff --git a/remoting/protocol/video_reader.cc b/remoting/protocol/video_reader.cc new file mode 100644 index 0000000..63cdae3 --- /dev/null +++ b/remoting/protocol/video_reader.cc @@ -0,0 +1,26 @@ +// 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/video_reader.h" + +#include "remoting/protocol/chromotocol_config.h" +#include "remoting/protocol/protobuf_video_reader.h" +#include "remoting/protocol/rtp_video_reader.h" + +namespace remoting { + +VideoReader::~VideoReader() { } + +// static +VideoReader* VideoReader::Create(const ChromotocolConfig* config) { + const ChannelConfig& video_config = config->video_config(); + if (video_config.transport == ChannelConfig::TRANSPORT_SRTP) { + return new RtpVideoReader(); + } else if (video_config.transport == ChannelConfig::TRANSPORT_STREAM) { + return new ProtobufVideoReader(); + } + return NULL; +} + +} // namespace remoting diff --git a/remoting/protocol/video_reader.h b/remoting/protocol/video_reader.h new file mode 100644 index 0000000..ca39619 --- /dev/null +++ b/remoting/protocol/video_reader.h @@ -0,0 +1,43 @@ +// 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. + +// 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. + +#ifndef REMOTING_PROTOCOL_VIDEO_READER_H_ +#define REMOTING_PROTOCOL_VIDEO_READER_H_ + +#include "base/callback.h" +#include "remoting/protocol/video_stub.h" + +namespace remoting { + +class ChromotocolConfig; +class ChromotocolConnection; + +class VideoReader { + public: + static VideoReader* Create(const ChromotocolConfig* config); + + virtual ~VideoReader(); + + // Initializies the reader. Doesn't take ownership of either |connection| + // or |video_stub|. + virtual void Init(ChromotocolConnection* connection, + VideoStub* video_stub) = 0; + + // Closes the reader. The stub should not be called after Close(). + virtual void Close() = 0; + + protected: + VideoReader() { } + + private: + DISALLOW_COPY_AND_ASSIGN(VideoReader); +}; + +} // namespace remoting + +#endif // REMOTING_PROTOCOL_VIDEO_READER_H_ diff --git a/remoting/protocol/video_stub.h b/remoting/protocol/video_stub.h new file mode 100644 index 0000000..9f9657f --- /dev/null +++ b/remoting/protocol/video_stub.h @@ -0,0 +1,33 @@ +// 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_VIDEO_STUB_H_ +#define REMOTING_PROTOCOL_VIDEO_STUB_H_ + +#include "remoting/proto/video.pb.h" + +class Task; + +namespace remoting { + +class VideoStub { + public: + virtual ~VideoStub() { } + + // TODO(sergeyu): VideoPacket is the protobuf message that is used to send + // video packets in protobuf stream. It should not be used here. Add another + // struct and use it to represent video packets internally. + virtual void ProcessVideoPacket(const VideoPacket* video_packet, + Task* done) = 0; + + protected: + VideoStub() { } + + private: + DISALLOW_COPY_AND_ASSIGN(VideoStub); +}; + +} // namespace remoting + +#endif // REMOTING_PROTOCOL_VIDEO_STUB_H_ diff --git a/remoting/protocol/video_writer.cc b/remoting/protocol/video_writer.cc new file mode 100644 index 0000000..c451010 --- /dev/null +++ b/remoting/protocol/video_writer.cc @@ -0,0 +1,26 @@ +// 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/video_writer.h" + +#include "remoting/protocol/chromotocol_config.h" +#include "remoting/protocol/protobuf_video_writer.h" +#include "remoting/protocol/rtp_video_writer.h" + +namespace remoting { + +VideoWriter::~VideoWriter() { } + +// static +VideoWriter* VideoWriter::Create(const ChromotocolConfig* config) { + const ChannelConfig& video_config = config->video_config(); + if (video_config.transport == ChannelConfig::TRANSPORT_SRTP) { + return new RtpVideoWriter(); + } else if (video_config.transport == ChannelConfig::TRANSPORT_STREAM) { + return new ProtobufVideoWriter(); + } + return NULL; +} + +} // namespace remoting diff --git a/remoting/protocol/video_writer.h b/remoting/protocol/video_writer.h new file mode 100644 index 0000000..9c98a8e --- /dev/null +++ b/remoting/protocol/video_writer.h @@ -0,0 +1,48 @@ +// 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. + +// 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. + +#ifndef REMOTING_PROTOCOL_VIDEO_WRITER_H_ +#define REMOTING_PROTOCOL_VIDEO_WRITER_H_ + +#include "base/basictypes.h" +#include "remoting/proto/video.pb.h" + +namespace remoting { + +class ChromotocolConfig; +class ChromotocolConnection; + +// TODO(sergeyu): VideoWriter should implement VideoStub interface. +class VideoWriter { + public: + virtual ~VideoWriter(); + + static VideoWriter* Create(const ChromotocolConfig* config); + + // Initializes the writer. + virtual void Init(ChromotocolConnection* connection) = 0; + + // Sends the |packet|. + virtual void SendPacket(const VideoPacket& packet) = 0; + + // Returns number of packets currently pending in the buffer. + virtual int GetPendingPackets() = 0; + + virtual void Close() = 0; + + protected: + VideoWriter() { } + + private: + DISALLOW_COPY_AND_ASSIGN(VideoWriter); +}; + +} // namespace remoting + +#endif // REMOTING_PROTOCOL_VIDEO_WRITER_H_ |