Commit 2385cffe authored by sergeyu's avatar sergeyu Committed by Commit bot

Simplify VideoReader and VideoWriter

Previously VideoReader/Writer were abstract interfaces with single
implementation. Now both the reader and writer are concrete
implementations reusing ChannelDispatcherBase, which significantly
simplified both.

BUG=402993

Review URL: https://codereview.chromium.org/577473002

Cr-Commit-Position: refs/heads/master@{#295760}
parent 2405b306
...@@ -31,6 +31,8 @@ static_library("protocol") { ...@@ -31,6 +31,8 @@ static_library("protocol") {
"client_event_dispatcher.cc", "client_event_dispatcher.cc",
"client_event_dispatcher.h", "client_event_dispatcher.h",
"client_stub.h", "client_stub.h",
"client_video_dispatcher.cc",
"client_video_dispatcher.h",
"clipboard_echo_filter.cc", "clipboard_echo_filter.cc",
"clipboard_echo_filter.h", "clipboard_echo_filter.h",
"clipboard_filter.cc", "clipboard_filter.cc",
...@@ -51,6 +53,8 @@ static_library("protocol") { ...@@ -51,6 +53,8 @@ static_library("protocol") {
"host_event_dispatcher.cc", "host_event_dispatcher.cc",
"host_event_dispatcher.h", "host_event_dispatcher.h",
"host_stub.h", "host_stub.h",
"host_video_dispatcher.cc",
"host_video_dispatcher.h",
"input_event_tracker.cc", "input_event_tracker.cc",
"input_event_tracker.h", "input_event_tracker.h",
"input_filter.cc", "input_filter.cc",
...@@ -95,10 +99,6 @@ static_library("protocol") { ...@@ -95,10 +99,6 @@ static_library("protocol") {
"pairing_host_authenticator.h", "pairing_host_authenticator.h",
"pairing_registry.cc", "pairing_registry.cc",
"pairing_registry.h", "pairing_registry.h",
"protobuf_video_reader.cc",
"protobuf_video_reader.h",
"protobuf_video_writer.cc",
"protobuf_video_writer.h",
"pseudotcp_channel_factory.cc", "pseudotcp_channel_factory.cc",
"pseudotcp_channel_factory.h", "pseudotcp_channel_factory.h",
"secure_channel_factory.cc", "secure_channel_factory.cc",
...@@ -123,11 +123,7 @@ static_library("protocol") { ...@@ -123,11 +123,7 @@ static_library("protocol") {
"transport.h", "transport.h",
"v2_authenticator.cc", "v2_authenticator.cc",
"v2_authenticator.h", "v2_authenticator.h",
"video_reader.cc",
"video_reader.h",
"video_stub.h", "video_stub.h",
"video_writer.cc",
"video_writer.h",
"../signaling/iq_sender.cc", "../signaling/iq_sender.cc",
"../signaling/iq_sender.h", "../signaling/iq_sender.h",
"../signaling/jingle_info_request.cc", "../signaling/jingle_info_request.cc",
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "remoting/protocol/client_video_dispatcher.h"
#include "base/bind.h"
#include "net/socket/stream_socket.h"
#include "remoting/base/constants.h"
#include "remoting/proto/video.pb.h"
#include "remoting/protocol/video_stub.h"
namespace remoting {
namespace protocol {
ClientVideoDispatcher::ClientVideoDispatcher(VideoStub* video_stub)
: ChannelDispatcherBase(kVideoChannelName),
video_stub_(video_stub) {
}
ClientVideoDispatcher::~ClientVideoDispatcher() {
}
void ClientVideoDispatcher::OnInitialized() {
reader_.Init(channel(), base::Bind(&VideoStub::ProcessVideoPacket,
base::Unretained(video_stub_)));
}
} // namespace protocol
} // namespace remoting
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef REMOTING_PROTOCOL_CLIENT_VIDEO_DISPATCHER_H_
#define REMOTING_PROTOCOL_CLIENT_VIDEO_DISPATCHER_H_
#include "base/compiler_specific.h"
#include "remoting/proto/video.pb.h"
#include "remoting/protocol/channel_dispatcher_base.h"
#include "remoting/protocol/message_reader.h"
namespace remoting {
namespace protocol {
class VideoStub;
class ClientVideoDispatcher : public ChannelDispatcherBase {
public:
explicit ClientVideoDispatcher(VideoStub* video_stub);
virtual ~ClientVideoDispatcher();
protected:
// ChannelDispatcherBase overrides.
virtual void OnInitialized() OVERRIDE;
private:
ProtobufMessageReader<VideoPacket> reader_;
// The stub to which VideoPackets are passed for processing.
VideoStub* video_stub_;
DISALLOW_COPY_AND_ASSIGN(ClientVideoDispatcher);
};
} // namespace protocol
} // namespace remoting
#endif // REMOTING_PROTOCOL_CLIENT_VIDEO_DISPATCHER_H_
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "remoting/protocol/host_control_dispatcher.h" #include "remoting/protocol/host_control_dispatcher.h"
#include "remoting/protocol/host_event_dispatcher.h" #include "remoting/protocol/host_event_dispatcher.h"
#include "remoting/protocol/host_stub.h" #include "remoting/protocol/host_stub.h"
#include "remoting/protocol/host_video_dispatcher.h"
#include "remoting/protocol/input_stub.h" #include "remoting/protocol/input_stub.h"
namespace remoting { namespace remoting {
...@@ -56,7 +57,7 @@ void ConnectionToClient::UpdateSequenceNumber(int64 sequence_number) { ...@@ -56,7 +57,7 @@ void ConnectionToClient::UpdateSequenceNumber(int64 sequence_number) {
VideoStub* ConnectionToClient::video_stub() { VideoStub* ConnectionToClient::video_stub() {
DCHECK(CalledOnValidThread()); DCHECK(CalledOnValidThread());
return video_writer_.get(); return video_dispatcher_.get();
} }
AudioStub* ConnectionToClient::audio_stub() { AudioStub* ConnectionToClient::audio_stub() {
...@@ -134,9 +135,11 @@ void ConnectionToClient::OnSessionStateChange(Session::State state) { ...@@ -134,9 +135,11 @@ void ConnectionToClient::OnSessionStateChange(Session::State state) {
event_dispatcher_->set_sequence_number_callback(base::Bind( event_dispatcher_->set_sequence_number_callback(base::Bind(
&ConnectionToClient::UpdateSequenceNumber, base::Unretained(this))); &ConnectionToClient::UpdateSequenceNumber, base::Unretained(this)));
video_writer_ = VideoWriter::Create(session_->config()); video_dispatcher_.reset(new HostVideoDispatcher());
video_writer_->Init(session_.get(), base::Bind( video_dispatcher_->Init(
&ConnectionToClient::OnChannelInitialized, base::Unretained(this))); session_.get(), session_->config().video_config(),
base::Bind(&ConnectionToClient::OnChannelInitialized,
base::Unretained(this)));
audio_writer_ = AudioWriter::Create(session_->config()); audio_writer_ = AudioWriter::Create(session_->config());
if (audio_writer_.get()) { if (audio_writer_.get()) {
...@@ -186,7 +189,7 @@ void ConnectionToClient::NotifyIfChannelsReady() { ...@@ -186,7 +189,7 @@ void ConnectionToClient::NotifyIfChannelsReady() {
return; return;
if (!event_dispatcher_.get() || !event_dispatcher_->is_connected()) if (!event_dispatcher_.get() || !event_dispatcher_->is_connected())
return; return;
if (!video_writer_.get() || !video_writer_->is_connected()) if (!video_dispatcher_.get() || !video_dispatcher_->is_connected())
return; return;
if ((!audio_writer_.get() || !audio_writer_->is_connected()) && if ((!audio_writer_.get() || !audio_writer_->is_connected()) &&
session_->config().is_audio_enabled()) { session_->config().is_audio_enabled()) {
...@@ -203,7 +206,7 @@ void ConnectionToClient::Close(ErrorCode error) { ...@@ -203,7 +206,7 @@ void ConnectionToClient::Close(ErrorCode error) {
void ConnectionToClient::CloseChannels() { void ConnectionToClient::CloseChannels() {
control_dispatcher_.reset(); control_dispatcher_.reset();
event_dispatcher_.reset(); event_dispatcher_.reset();
video_writer_.reset(); video_dispatcher_.reset();
audio_writer_.reset(); audio_writer_.reset();
} }
......
...@@ -14,17 +14,18 @@ ...@@ -14,17 +14,18 @@
#include "base/threading/non_thread_safe.h" #include "base/threading/non_thread_safe.h"
#include "remoting/protocol/audio_writer.h" #include "remoting/protocol/audio_writer.h"
#include "remoting/protocol/session.h" #include "remoting/protocol/session.h"
#include "remoting/protocol/video_writer.h"
namespace remoting { namespace remoting {
namespace protocol { namespace protocol {
class ClientStub; class ClientStub;
class ClipboardStub; class ClipboardStub;
class HostStub;
class InputStub;
class HostControlDispatcher; class HostControlDispatcher;
class HostEventDispatcher; class HostEventDispatcher;
class HostStub;
class HostVideoDispatcher;
class InputStub;
class VideoStub;
// This class represents a remote viewer connection to the chromoting // This class represents a remote viewer connection to the chromoting
// host. It sets up all protocol channels and connects them to the // host. It sets up all protocol channels and connects them to the
...@@ -128,7 +129,7 @@ class ConnectionToClient : public base::NonThreadSafe, ...@@ -128,7 +129,7 @@ class ConnectionToClient : public base::NonThreadSafe,
scoped_ptr<HostControlDispatcher> control_dispatcher_; scoped_ptr<HostControlDispatcher> control_dispatcher_;
scoped_ptr<HostEventDispatcher> event_dispatcher_; scoped_ptr<HostEventDispatcher> event_dispatcher_;
scoped_ptr<VideoWriter> video_writer_; scoped_ptr<HostVideoDispatcher> video_dispatcher_;
scoped_ptr<AudioWriter> audio_writer_; scoped_ptr<AudioWriter> audio_writer_;
DISALLOW_COPY_AND_ASSIGN(ConnectionToClient); DISALLOW_COPY_AND_ASSIGN(ConnectionToClient);
......
...@@ -15,11 +15,11 @@ ...@@ -15,11 +15,11 @@
#include "remoting/protocol/client_control_dispatcher.h" #include "remoting/protocol/client_control_dispatcher.h"
#include "remoting/protocol/client_event_dispatcher.h" #include "remoting/protocol/client_event_dispatcher.h"
#include "remoting/protocol/client_stub.h" #include "remoting/protocol/client_stub.h"
#include "remoting/protocol/client_video_dispatcher.h"
#include "remoting/protocol/clipboard_stub.h" #include "remoting/protocol/clipboard_stub.h"
#include "remoting/protocol/errors.h" #include "remoting/protocol/errors.h"
#include "remoting/protocol/jingle_session_manager.h" #include "remoting/protocol/jingle_session_manager.h"
#include "remoting/protocol/transport.h" #include "remoting/protocol/transport.h"
#include "remoting/protocol/video_reader.h"
#include "remoting/protocol/video_stub.h" #include "remoting/protocol/video_stub.h"
namespace remoting { namespace remoting {
...@@ -197,8 +197,9 @@ void ConnectionToHost::OnSessionStateChange( ...@@ -197,8 +197,9 @@ void ConnectionToHost::OnSessionStateChange(
base::Bind(&ConnectionToHost::OnChannelInitialized, base::Bind(&ConnectionToHost::OnChannelInitialized,
base::Unretained(this))); base::Unretained(this)));
video_reader_ = VideoReader::Create(session_->config()); video_dispatcher_.reset(
video_reader_->Init(session_.get(), monitored_video_stub_.get(), new ClientVideoDispatcher(monitored_video_stub_.get()));
video_dispatcher_->Init(session_.get(), session_->config().video_config(),
base::Bind(&ConnectionToHost::OnChannelInitialized, base::Bind(&ConnectionToHost::OnChannelInitialized,
base::Unretained(this))); base::Unretained(this)));
...@@ -263,7 +264,7 @@ void ConnectionToHost::NotifyIfChannelsReady() { ...@@ -263,7 +264,7 @@ void ConnectionToHost::NotifyIfChannelsReady() {
return; return;
if (!event_dispatcher_.get() || !event_dispatcher_->is_connected()) if (!event_dispatcher_.get() || !event_dispatcher_->is_connected())
return; return;
if (!video_reader_.get() || !video_reader_->is_connected()) if (!video_dispatcher_.get() || !video_dispatcher_->is_connected())
return; return;
if ((!audio_reader_.get() || !audio_reader_->is_connected()) && if ((!audio_reader_.get() || !audio_reader_->is_connected()) &&
session_->config().is_audio_enabled()) { session_->config().is_audio_enabled()) {
...@@ -288,7 +289,7 @@ void ConnectionToHost::CloseChannels() { ...@@ -288,7 +289,7 @@ void ConnectionToHost::CloseChannels() {
event_dispatcher_.reset(); event_dispatcher_.reset();
clipboard_forwarder_.set_clipboard_stub(NULL); clipboard_forwarder_.set_clipboard_stub(NULL);
event_forwarder_.set_input_stub(NULL); event_forwarder_.set_input_stub(NULL);
video_reader_.reset(); video_dispatcher_.reset();
audio_reader_.reset(); audio_reader_.reset();
} }
......
...@@ -42,7 +42,7 @@ class HostStub; ...@@ -42,7 +42,7 @@ class HostStub;
class InputStub; class InputStub;
class SessionConfig; class SessionConfig;
class TransportFactory; class TransportFactory;
class VideoReader; class ClientVideoDispatcher;
class VideoStub; class VideoStub;
class ConnectionToHost : public SignalStrategy::Listener, class ConnectionToHost : public SignalStrategy::Listener,
...@@ -173,7 +173,7 @@ class ConnectionToHost : public SignalStrategy::Listener, ...@@ -173,7 +173,7 @@ class ConnectionToHost : public SignalStrategy::Listener,
scoped_ptr<Session> session_; scoped_ptr<Session> session_;
scoped_ptr<MonitoredVideoStub> monitored_video_stub_; scoped_ptr<MonitoredVideoStub> monitored_video_stub_;
scoped_ptr<VideoReader> video_reader_; scoped_ptr<ClientVideoDispatcher> video_dispatcher_;
scoped_ptr<AudioReader> audio_reader_; scoped_ptr<AudioReader> audio_reader_;
scoped_ptr<ClientControlDispatcher> control_dispatcher_; scoped_ptr<ClientControlDispatcher> control_dispatcher_;
scoped_ptr<ClientEventDispatcher> event_dispatcher_; scoped_ptr<ClientEventDispatcher> event_dispatcher_;
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "remoting/protocol/host_video_dispatcher.h"
#include "base/bind.h"
#include "net/socket/stream_socket.h"
#include "remoting/base/constants.h"
#include "remoting/proto/video.pb.h"
#include "remoting/protocol/message_serialization.h"
namespace remoting {
namespace protocol {
HostVideoDispatcher::HostVideoDispatcher()
: ChannelDispatcherBase(kVideoChannelName) {
}
HostVideoDispatcher::~HostVideoDispatcher() {
}
void HostVideoDispatcher::OnInitialized() {
// TODO(sergeyu): Provide WriteFailedCallback for the buffered writer.
writer_.Init(channel(), BufferedSocketWriter::WriteFailedCallback());
}
void HostVideoDispatcher::ProcessVideoPacket(scoped_ptr<VideoPacket> packet,
const base::Closure& done) {
writer_.Write(SerializeAndFrameMessage(*packet), done);
}
} // namespace protocol
} // namespace remoting
// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef REMOTING_PROTOCOL_PROTOBUF_VIDEO_WRITER_H_ #ifndef REMOTING_PROTOCOL_HOST_VIDEO_DISPATCHER_H_
#define REMOTING_PROTOCOL_PROTOBUF_VIDEO_WRITER_H_ #define REMOTING_PROTOCOL_HOST_VIDEO_DISPATCHER_H_
#include <string> #include <string>
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "remoting/protocol/buffered_socket_writer.h" #include "remoting/protocol/buffered_socket_writer.h"
#include "remoting/protocol/video_writer.h" #include "remoting/protocol/channel_dispatcher_base.h"
#include "remoting/protocol/video_stub.h"
namespace net {
class StreamSocket;
} // namespace net
namespace remoting { namespace remoting {
namespace protocol { namespace protocol {
class StreamChannelFactory; class HostVideoDispatcher : public ChannelDispatcherBase, public VideoStub {
class Session;
class ProtobufVideoWriter : public VideoWriter {
public: public:
ProtobufVideoWriter(); HostVideoDispatcher();
virtual ~ProtobufVideoWriter(); virtual ~HostVideoDispatcher();
// VideoWriter interface.
virtual void Init(protocol::Session* session,
const InitializedCallback& callback) OVERRIDE;
virtual void Close() OVERRIDE;
virtual bool is_connected() OVERRIDE;
// VideoStub interface. // VideoStub interface.
virtual void ProcessVideoPacket(scoped_ptr<VideoPacket> packet, virtual void ProcessVideoPacket(scoped_ptr<VideoPacket> packet,
const base::Closure& done) OVERRIDE; const base::Closure& done) OVERRIDE;
private: protected:
void OnChannelReady(scoped_ptr<net::StreamSocket> socket); // ChannelDispatcherBase overrides.
virtual void OnInitialized() OVERRIDE;
InitializedCallback initialized_callback_; private:
BufferedSocketWriter writer_;
StreamChannelFactory* channel_factory_;
scoped_ptr<net::StreamSocket> channel_;
BufferedSocketWriter buffered_writer_;
DISALLOW_COPY_AND_ASSIGN(ProtobufVideoWriter); DISALLOW_COPY_AND_ASSIGN(HostVideoDispatcher);
}; };
} // namespace protocol } // namespace protocol
} // namespace remoting } // namespace remoting
#endif // REMOTING_PROTOCOL_PROTOBUF_VIDEO_WRITER_H_ #endif // REMOTING_PROTOCOL_HOST_VIDEO_DISPATCHER_H_
// 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/protobuf_video_reader.h"
#include "base/bind.h"
#include "net/socket/stream_socket.h"
#include "remoting/base/constants.h"
#include "remoting/proto/video.pb.h"
#include "remoting/protocol/session.h"
#include "remoting/protocol/stream_channel_factory.h"
namespace remoting {
namespace protocol {
ProtobufVideoReader::ProtobufVideoReader(VideoPacketFormat::Encoding encoding)
: encoding_(encoding),
channel_factory_(NULL),
video_stub_(NULL) {
}
ProtobufVideoReader::~ProtobufVideoReader() {
if (channel_factory_)
channel_factory_->CancelChannelCreation(kVideoChannelName);
}
void ProtobufVideoReader::Init(protocol::Session* session,
VideoStub* video_stub,
const InitializedCallback& callback) {
channel_factory_ = session->GetTransportChannelFactory();
initialized_callback_ = callback;
video_stub_ = video_stub;
channel_factory_->CreateChannel(
kVideoChannelName,
base::Bind(&ProtobufVideoReader::OnChannelReady, base::Unretained(this)));
}
bool ProtobufVideoReader::is_connected() {
return channel_.get() != NULL;
}
void ProtobufVideoReader::OnChannelReady(scoped_ptr<net::StreamSocket> socket) {
if (!socket.get()) {
initialized_callback_.Run(false);
return;
}
DCHECK(!channel_.get());
channel_ = socket.Pass();
reader_.Init(channel_.get(), base::Bind(&ProtobufVideoReader::OnNewData,
base::Unretained(this)));
initialized_callback_.Run(true);
}
void ProtobufVideoReader::OnNewData(scoped_ptr<VideoPacket> packet,
const base::Closure& done_task) {
video_stub_->ProcessVideoPacket(packet.Pass(), done_task);
}
} // namespace protocol
} // namespace remoting
// 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_PROTOBUF_VIDEO_READER_H_
#define REMOTING_PROTOCOL_PROTOBUF_VIDEO_READER_H_
#include "base/compiler_specific.h"
#include "remoting/proto/video.pb.h"
#include "remoting/protocol/message_reader.h"
#include "remoting/protocol/video_reader.h"
namespace net {
class StreamSocket;
} // namespace net
namespace remoting {
namespace protocol {
class StreamChannelFactory;
class Session;
class ProtobufVideoReader : public VideoReader {
public:
ProtobufVideoReader(VideoPacketFormat::Encoding encoding);
virtual ~ProtobufVideoReader();
// VideoReader interface.
virtual void Init(protocol::Session* session,
VideoStub* video_stub,
const InitializedCallback& callback) OVERRIDE;
virtual bool is_connected() OVERRIDE;
private:
void OnChannelReady(scoped_ptr<net::StreamSocket> socket);
void OnNewData(scoped_ptr<VideoPacket> packet,
const base::Closure& done_task);
InitializedCallback initialized_callback_;
VideoPacketFormat::Encoding encoding_;
StreamChannelFactory* channel_factory_;
scoped_ptr<net::StreamSocket> channel_;
ProtobufMessageReader<VideoPacket> reader_;
// The stub that processes all received packets.
VideoStub* video_stub_;
DISALLOW_COPY_AND_ASSIGN(ProtobufVideoReader);
};
} // namespace protocol
} // namespace remoting
#endif // REMOTING_PROTOCOL_PROTOBUF_VIDEO_READER_H_
// 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/protobuf_video_writer.h"
#include "base/bind.h"
#include "net/socket/stream_socket.h"
#include "remoting/base/constants.h"
#include "remoting/proto/video.pb.h"
#include "remoting/protocol/message_serialization.h"
#include "remoting/protocol/session.h"
#include "remoting/protocol/stream_channel_factory.h"
namespace remoting {
namespace protocol {
ProtobufVideoWriter::ProtobufVideoWriter()
: channel_factory_(NULL) {
}
ProtobufVideoWriter::~ProtobufVideoWriter() {
Close();
}
void ProtobufVideoWriter::Init(protocol::Session* session,
const InitializedCallback& callback) {
channel_factory_ = session->GetTransportChannelFactory();
initialized_callback_ = callback;
channel_factory_->CreateChannel(
kVideoChannelName,
base::Bind(&ProtobufVideoWriter::OnChannelReady, base::Unretained(this)));
}
void ProtobufVideoWriter::OnChannelReady(scoped_ptr<net::StreamSocket> socket) {
if (!socket.get()) {
initialized_callback_.Run(false);
return;
}
DCHECK(!channel_.get());
channel_ = socket.Pass();
// TODO(sergeyu): Provide WriteFailedCallback for the buffered writer.
buffered_writer_.Init(
channel_.get(), BufferedSocketWriter::WriteFailedCallback());
initialized_callback_.Run(true);
}
void ProtobufVideoWriter::Close() {
buffered_writer_.Close();
channel_.reset();
if (channel_factory_) {
channel_factory_->CancelChannelCreation(kVideoChannelName);
channel_factory_ = NULL;
}
}
bool ProtobufVideoWriter::is_connected() {
return channel_.get() != NULL;
}
void ProtobufVideoWriter::ProcessVideoPacket(scoped_ptr<VideoPacket> packet,
const base::Closure& done) {
buffered_writer_.Write(SerializeAndFrameMessage(*packet), done);
}
} // namespace protocol
} // namespace remoting
// 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/video_reader.h"
#include "remoting/protocol/session_config.h"
#include "remoting/protocol/protobuf_video_reader.h"
namespace remoting {
namespace protocol {
VideoReader::~VideoReader() { }
// static
scoped_ptr<VideoReader> VideoReader::Create(const SessionConfig& config) {
const ChannelConfig& video_config = config.video_config();
if (video_config.transport == ChannelConfig::TRANSPORT_STREAM) {
if (video_config.codec == ChannelConfig::CODEC_VP8) {
return scoped_ptr<VideoReader>(
new ProtobufVideoReader(VideoPacketFormat::ENCODING_VP8));
} else if (video_config.codec == ChannelConfig::CODEC_VP9) {
return scoped_ptr<VideoReader>(
new ProtobufVideoReader(VideoPacketFormat::ENCODING_VP9));
} else if (video_config.codec == ChannelConfig::CODEC_ZIP) {
return scoped_ptr<VideoReader>(
new ProtobufVideoReader(VideoPacketFormat::ENCODING_ZLIB));
} else if (video_config.codec == ChannelConfig::CODEC_VERBATIM) {
return scoped_ptr<VideoReader>(
new ProtobufVideoReader(VideoPacketFormat::ENCODING_VERBATIM));
}
}
NOTREACHED();
return scoped_ptr<VideoReader>();
}
} // namespace protocol
} // namespace remoting
// 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.
// 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_
#include "base/callback.h"
#include "base/memory/scoped_ptr.h"
#include "remoting/protocol/video_stub.h"
namespace remoting {
namespace protocol {
class Session;
class SessionConfig;
class VideoReader {
public:
// The callback is called when initialization is finished. The
// parameter is set to true on success.
typedef base::Callback<void(bool)> InitializedCallback;
virtual ~VideoReader();
static scoped_ptr<VideoReader> Create(const SessionConfig& config);
// Initializies the reader. Doesn't take ownership of either |connection|
// or |video_stub|.
virtual void Init(Session* session,
VideoStub* video_stub,
const InitializedCallback& callback) = 0;
virtual bool is_connected() = 0;
protected:
VideoReader() { }
private:
DISALLOW_COPY_AND_ASSIGN(VideoReader);
};
} // namespace protocol
} // namespace remoting
#endif // REMOTING_PROTOCOL_VIDEO_READER_H_
// 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/video_writer.h"
#include "remoting/protocol/session_config.h"
#include "remoting/protocol/protobuf_video_writer.h"
namespace remoting {
namespace protocol {
VideoWriter::~VideoWriter() { }
// static
scoped_ptr<VideoWriter> VideoWriter::Create(const SessionConfig& config) {
const ChannelConfig& video_config = config.video_config();
if (video_config.transport == ChannelConfig::TRANSPORT_STREAM) {
return scoped_ptr<VideoWriter>(new ProtobufVideoWriter());
}
return scoped_ptr<VideoWriter>();
}
} // namespace protocol
} // namespace remoting
// 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.
// 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_
#include "base/basictypes.h"
#include "base/callback.h"
#include "remoting/protocol/video_stub.h"
namespace remoting {
namespace protocol {
class Session;
class SessionConfig;
class VideoWriter : public VideoStub {
public:
virtual ~VideoWriter();
// The callback is called when initialization is finished. The
// parameter is set to true on success.
typedef base::Callback<void(bool)> InitializedCallback;
static scoped_ptr<VideoWriter> Create(const SessionConfig& config);
// Initializes the writer.
virtual void Init(Session* session, const InitializedCallback& callback) = 0;
// Stops writing. Must be called on the network thread before this
// object is destroyed.
virtual void Close() = 0;
// Returns true if the channel is connected.
virtual bool is_connected() = 0;
protected:
VideoWriter() { }
private:
DISALLOW_COPY_AND_ASSIGN(VideoWriter);
};
} // namespace protocol
} // namespace remoting
#endif // REMOTING_PROTOCOL_VIDEO_WRITER_H_
...@@ -100,6 +100,8 @@ ...@@ -100,6 +100,8 @@
'protocol/client_event_dispatcher.cc', 'protocol/client_event_dispatcher.cc',
'protocol/client_event_dispatcher.h', 'protocol/client_event_dispatcher.h',
'protocol/client_stub.h', 'protocol/client_stub.h',
'protocol/client_video_dispatcher.cc',
'protocol/client_video_dispatcher.h',
'protocol/clipboard_echo_filter.cc', 'protocol/clipboard_echo_filter.cc',
'protocol/clipboard_echo_filter.h', 'protocol/clipboard_echo_filter.h',
'protocol/clipboard_filter.cc', 'protocol/clipboard_filter.cc',
...@@ -120,6 +122,8 @@ ...@@ -120,6 +122,8 @@
'protocol/host_event_dispatcher.cc', 'protocol/host_event_dispatcher.cc',
'protocol/host_event_dispatcher.h', 'protocol/host_event_dispatcher.h',
'protocol/host_stub.h', 'protocol/host_stub.h',
'protocol/host_video_dispatcher.cc',
'protocol/host_video_dispatcher.h',
'protocol/input_event_tracker.cc', 'protocol/input_event_tracker.cc',
'protocol/input_event_tracker.h', 'protocol/input_event_tracker.h',
'protocol/input_filter.cc', 'protocol/input_filter.cc',
...@@ -164,10 +168,6 @@ ...@@ -164,10 +168,6 @@
'protocol/pairing_host_authenticator.h', 'protocol/pairing_host_authenticator.h',
'protocol/pairing_registry.cc', 'protocol/pairing_registry.cc',
'protocol/pairing_registry.h', 'protocol/pairing_registry.h',
'protocol/protobuf_video_reader.cc',
'protocol/protobuf_video_reader.h',
'protocol/protobuf_video_writer.cc',
'protocol/protobuf_video_writer.h',
'protocol/pseudotcp_channel_factory.cc', 'protocol/pseudotcp_channel_factory.cc',
'protocol/pseudotcp_channel_factory.h', 'protocol/pseudotcp_channel_factory.h',
'protocol/secure_channel_factory.cc', 'protocol/secure_channel_factory.cc',
...@@ -192,11 +192,7 @@ ...@@ -192,11 +192,7 @@
'protocol/transport.h', 'protocol/transport.h',
'protocol/v2_authenticator.cc', 'protocol/v2_authenticator.cc',
'protocol/v2_authenticator.h', 'protocol/v2_authenticator.h',
'protocol/video_reader.cc',
'protocol/video_reader.h',
'protocol/video_stub.h', 'protocol/video_stub.h',
'protocol/video_writer.cc',
'protocol/video_writer.h',
'signaling/iq_sender.cc', 'signaling/iq_sender.cc',
'signaling/iq_sender.h', 'signaling/iq_sender.h',
'signaling/jingle_info_request.cc', 'signaling/jingle_info_request.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment