Commit 1290af9d authored by sergeyu@chromium.org's avatar sergeyu@chromium.org

Revert 96089 - Remove video_channel() from Session interface

BUG=None
TEST=Unittests.

Review URL: http://codereview.chromium.org/7508044

TBR=sergeyu@chromium.org
Review URL: http://codereview.chromium.org/7604021

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@96106 0039d316-1c4b-4281-b951-d872f2087c98
parent f8aa077c
......@@ -12,8 +12,4 @@ const char kChromotingTokenDefaultServiceName[] = "chromiumsync";
const char kChromotingXmlNamespace[] = "google:remoting";
const char kVideoChannelName[] = "video";
const char kVideoRtpChannelName[] = "videortp";
const char kVideoRtcpChannelName[] = "videortpc";
} // namespace remoting
......@@ -17,11 +17,6 @@ extern const char kChromotingTokenDefaultServiceName[];
// Namespace used for chromoting XMPP stanzas.
extern const char kChromotingXmlNamespace[];
// Channel names.
extern const char kVideoChannelName[];
extern const char kVideoRtpChannelName[];
extern const char kVideoRtcpChannelName[];
} // namespace remoting
#endif // REMOTING_BASE_CONSTANTS_H_
......@@ -41,8 +41,7 @@ class BufferedSocketWriterBase
// Initializes the writer. Must be called on the thread that will be used
// to access the socket in the future. |callback| will be called after each
// failed write. Caller retains ownership of |socket|.
// TODO(sergeyu): Change it so that it take ownership of |socket|.
// failed write.
void Init(net::Socket* socket, WriteFailedCallback* callback);
// Puts a new data chunk in the buffer. Returns false and doesn't enqueue
......
......@@ -4,7 +4,6 @@
#include "remoting/protocol/connection_to_client.h"
#include "base/bind.h"
#include "google/protobuf/message.h"
#include "net/base/io_buffer.h"
#include "remoting/protocol/client_control_sender.h"
......@@ -97,18 +96,20 @@ void ConnectionToClient::OnSessionStateChange(protocol::Session::State state) {
client_control_sender_.reset(
new ClientControlSender(session_->control_channel()));
video_writer_.reset(VideoWriter::Create(session_->config()));
video_writer_->Init(
session_.get(), base::Bind(&ConnectionToClient::OnVideoInitialized,
base::Unretained(this)));
video_writer_->Init(session_.get());
dispatcher_.reset(new HostMessageDispatcher());
dispatcher_->Initialize(this, host_stub_, input_stub_);
handler_->OnConnectionOpened(this);
break;
case protocol::Session::CLOSED:
CloseChannels();
handler_->OnConnectionClosed(this);
break;
case protocol::Session::FAILED:
CloseOnError();
CloseChannels();
handler_->OnConnectionFailed(this);
break;
default:
// We shouldn't receive other states.
......@@ -116,20 +117,6 @@ void ConnectionToClient::OnSessionStateChange(protocol::Session::State state) {
}
}
void ConnectionToClient::OnVideoInitialized(bool successful) {
if (!successful) {
CloseOnError();
return;
}
handler_->OnConnectionOpened(this);
}
void ConnectionToClient::CloseOnError() {
CloseChannels();
handler_->OnConnectionFailed(this);
}
void ConnectionToClient::CloseChannels() {
if (video_writer_.get())
video_writer_->Close();
......
......@@ -90,11 +90,6 @@ class ConnectionToClient :
// Callback for protocol Session.
void OnSessionStateChange(Session::State state);
// Callback for VideoReader::Init().
void OnVideoInitialized(bool successful);
void CloseOnError();
// Stops writing in the channels.
void CloseChannels();
......
......@@ -4,7 +4,6 @@
#include "base/message_loop.h"
#include "remoting/base/base_mock_objects.h"
#include "remoting/base/constants.h"
#include "remoting/protocol/fake_session.h"
#include "remoting/protocol/connection_to_client.h"
#include "remoting/protocol/protocol_mock_objects.h"
......@@ -61,9 +60,7 @@ TEST_F(ConnectionToClientTest, SendUpdateStream) {
// Verify that something has been written.
// TODO(sergeyu): Verify that the correct data has been written.
ASSERT_TRUE(session_->GetStreamChannel(kVideoChannelName));
EXPECT_GT(session_->GetStreamChannel(kVideoChannelName)->
written_data().size(), 0u);
EXPECT_GT(session_->video_channel()->written_data().size(), 0u);
// And then close the connection to ConnectionToClient.
viewer_->Disconnect();
......
......@@ -176,7 +176,8 @@ void ConnectionToHost::OnSessionStateChange(
switch (state) {
case Session::FAILED:
state_ = STATE_FAILED;
CloseOnError();
CloseChannels();
event_callback_->OnConnectionFailed(this);
break;
case Session::CLOSED:
......@@ -189,10 +190,7 @@ void ConnectionToHost::OnSessionStateChange(
state_ = STATE_CONNECTED;
// Initialize reader and writer.
video_reader_.reset(VideoReader::Create(session_->config()));
video_reader_->Init(
session_.get(), video_stub_,
base::Bind(&ConnectionToHost::OnVideoChannelInitialized,
base::Unretained(this)));
video_reader_->Init(session_.get(), video_stub_);
host_control_sender_.reset(
new HostControlSender(session_->control_channel()));
dispatcher_->Initialize(session_.get(), client_stub_);
......@@ -205,27 +203,12 @@ void ConnectionToHost::OnSessionStateChange(
}
}
void ConnectionToHost::OnVideoChannelInitialized(bool successful) {
if (!successful) {
CloseOnError();
return;
}
}
void ConnectionToHost::CloseOnError() {
state_ = STATE_FAILED;
CloseChannels();
event_callback_->OnConnectionFailed(this);
}
void ConnectionToHost::CloseChannels() {
if (input_sender_.get())
input_sender_->Close();
if (host_control_sender_.get())
host_control_sender_->Close();
video_reader_.reset();
}
void ConnectionToHost::OnClientAuthenticated() {
......
......@@ -124,14 +124,9 @@ class ConnectionToHost : public SignalStrategy::StatusObserver,
// Callback for |session_|.
void OnSessionStateChange(Session::State state);
// Callback for VideoReader::Init().
void OnVideoChannelInitialized(bool successful);
// Callback for |video_reader_|.
void OnVideoPacket(VideoPacket* packet);
void CloseOnError();
// Stops writing in the channels.
void CloseChannels();
......
......@@ -70,67 +70,6 @@ bool FakeSocket::SetSendBufferSize(int32 size) {
return false;
}
int FakeSocket::Connect(net::CompletionCallback* callback) {
return net::OK;
}
void FakeSocket::Disconnect() {
NOTIMPLEMENTED();
}
bool FakeSocket::IsConnected() const {
return true;
}
bool FakeSocket::IsConnectedAndIdle() const {
NOTIMPLEMENTED();
return false;
}
int FakeSocket::GetPeerAddress(
net::AddressList* address) const {
NOTIMPLEMENTED();
return net::ERR_FAILED;
}
int FakeSocket::GetLocalAddress(
net::IPEndPoint* address) const {
NOTIMPLEMENTED();
return net::ERR_FAILED;
}
const net::BoundNetLog& FakeSocket::NetLog() const {
return net_log_;
}
void FakeSocket::SetSubresourceSpeculation() {
NOTIMPLEMENTED();
}
void FakeSocket::SetOmniboxSpeculation() {
NOTIMPLEMENTED();
}
bool FakeSocket::WasEverUsed() const {
NOTIMPLEMENTED();
return true;
}
bool FakeSocket::UsingTCPFastOpen() const {
NOTIMPLEMENTED();
return true;
}
int64 FakeSocket::NumBytesRead() const {
NOTIMPLEMENTED();
return 0;
}
base::TimeDelta FakeSocket::GetConnectTimeMicros() const {
NOTIMPLEMENTED();
return base::TimeDelta();
}
FakeUdpSocket::FakeUdpSocket()
: read_pending_(false),
input_pos_(0) {
......@@ -196,31 +135,21 @@ FakeSession::FakeSession()
FakeSession::~FakeSession() { }
FakeSocket* FakeSession::GetStreamChannel(const std::string& name) {
return stream_channels_[name];
}
FakeUdpSocket* FakeSession::GetDatagramChannel(const std::string& name) {
return datagram_channels_[name];
}
void FakeSession::SetStateChangeCallback(StateChangeCallback* callback) {
void FakeSession::SetStateChangeCallback(
StateChangeCallback* callback) {
callback_.reset(callback);
}
void FakeSession::CreateStreamChannel(
const std::string& name, const StreamChannelCallback& callback) {
LOG(ERROR) << " creating channel " << name;
FakeSocket* channel = new FakeSocket();
stream_channels_[name] = channel;
callback.Run(name, channel);
NOTIMPLEMENTED();
callback.Run(name, NULL);
}
void FakeSession::CreateDatagramChannel(
const std::string& name, const DatagramChannelCallback& callback) {
FakeUdpSocket* channel = new FakeUdpSocket();
datagram_channels_[name] = channel;
callback.Run(name, channel);
NOTIMPLEMENTED();
callback.Run(name, NULL);
}
FakeSocket* FakeSession::control_channel() {
......@@ -231,6 +160,18 @@ FakeSocket* FakeSession::event_channel() {
return &event_channel_;
}
FakeSocket* FakeSession::video_channel() {
return &video_channel_;
}
FakeUdpSocket* FakeSession::video_rtp_channel() {
return &video_rtp_channel_;
}
FakeUdpSocket* FakeSession::video_rtcp_channel() {
return &video_rtcp_channel_;
}
const std::string& FakeSession::jid() {
return jid_;
}
......
......@@ -5,13 +5,11 @@
#ifndef REMOTING_PROTOCOL_FAKE_SESSION_H_
#define REMOTING_PROTOCOL_FAKE_SESSION_H_
#include <map>
#include <string>
#include <vector>
#include "base/memory/scoped_ptr.h"
#include "net/socket/socket.h"
#include "net/socket/stream_socket.h"
#include "remoting/protocol/session.h"
namespace remoting {
......@@ -24,7 +22,7 @@ extern const char kTestJid[];
// Read() reads data from another buffer that can be set with AppendInputData().
// Pending reads are supported, so if there is a pending read AppendInputData()
// calls the read callback.
class FakeSocket : public net::StreamSocket {
class FakeSocket : public net::Socket {
public:
FakeSocket();
virtual ~FakeSocket();
......@@ -44,21 +42,6 @@ class FakeSocket : public net::StreamSocket {
virtual bool SetReceiveBufferSize(int32 size);
virtual bool SetSendBufferSize(int32 size);
// net::StreamSocket interface.
virtual int Connect(net::CompletionCallback* callback) OVERRIDE;
virtual void Disconnect() OVERRIDE;
virtual bool IsConnected() const OVERRIDE;
virtual bool IsConnectedAndIdle() const OVERRIDE;
virtual int GetPeerAddress(net::AddressList* address) const OVERRIDE;
virtual int GetLocalAddress(net::IPEndPoint* address) const OVERRIDE;
virtual const net::BoundNetLog& NetLog() const OVERRIDE;
virtual void SetSubresourceSpeculation() OVERRIDE;
virtual void SetOmniboxSpeculation() OVERRIDE;
virtual bool WasEverUsed() const OVERRIDE;
virtual bool UsingTCPFastOpen() const OVERRIDE;
virtual int64 NumBytesRead() const OVERRIDE;
virtual base::TimeDelta GetConnectTimeMicros() const OVERRIDE;
private:
bool read_pending_;
scoped_refptr<net::IOBuffer> read_buffer_;
......@@ -68,10 +51,6 @@ class FakeSocket : public net::StreamSocket {
std::string written_data_;
std::string input_data_;
int input_pos_;
net::BoundNetLog net_log_;
DISALLOW_COPY_AND_ASSIGN(FakeSocket);
};
// FakeUdpSocket is similar to FakeSocket but behaves as UDP socket. All written
......@@ -107,8 +86,6 @@ class FakeUdpSocket : public net::Socket {
std::vector<std::string> written_packets_;
std::vector<std::string> input_packets_;
int input_pos_;
DISALLOW_COPY_AND_ASSIGN(FakeUdpSocket);
};
// FakeSession is a dummy protocol::Session that uses FakeSocket for all
......@@ -126,10 +103,6 @@ class FakeSession : public Session {
bool is_closed() const { return closed_; }
FakeSocket* GetStreamChannel(const std::string& name);
FakeUdpSocket* GetDatagramChannel(const std::string& name);
// Session interface.
virtual void SetStateChangeCallback(StateChangeCallback* callback);
virtual void CreateStreamChannel(
......@@ -139,6 +112,10 @@ class FakeSession : public Session {
virtual FakeSocket* control_channel();
virtual FakeSocket* event_channel();
virtual FakeSocket* video_channel();
virtual FakeUdpSocket* video_rtp_channel();
virtual FakeUdpSocket* video_rtcp_channel();
virtual const std::string& jid();
......@@ -163,9 +140,9 @@ class FakeSession : public Session {
MessageLoop* message_loop_;
FakeSocket control_channel_;
FakeSocket event_channel_;
std::map<std::string, FakeSocket*> stream_channels_;
std::map<std::string, FakeUdpSocket*> datagram_channels_;
FakeSocket video_channel_;
FakeUdpSocket video_rtp_channel_;
FakeUdpSocket video_rtcp_channel_;
std::string initiator_token_;
std::string receiver_token_;
......@@ -174,8 +151,6 @@ class FakeSession : public Session {
std::string jid_;
bool closed_;
DISALLOW_COPY_AND_ASSIGN(FakeSession);
};
} // namespace protocol
......
......@@ -33,6 +33,7 @@ namespace {
const char kControlChannelName[] = "control";
const char kEventChannelName[] = "event";
const char kVideoChannelName[] = "video";
const int kMasterKeyLength = 16;
const int kChannelKeyLength = 16;
......@@ -159,6 +160,7 @@ void JingleSession::CloseInternal(int result, bool failed) {
control_channel_socket_.reset();
event_channel_socket_.reset();
video_channel_socket_.reset();
STLDeleteContainerPairSecondPointers(channel_connectors_.begin(),
channel_connectors_.end());
......@@ -222,6 +224,23 @@ net::Socket* JingleSession::event_channel() {
return event_channel_socket_.get();
}
net::Socket* JingleSession::video_channel() {
DCHECK(CalledOnValidThread());
return video_channel_socket_.get();
}
net::Socket* JingleSession::video_rtp_channel() {
DCHECK(CalledOnValidThread());
NOTREACHED();
return NULL;
}
net::Socket* JingleSession::video_rtcp_channel() {
DCHECK(CalledOnValidThread());
NOTREACHED();
return NULL;
}
const std::string& JingleSession::jid() {
// TODO(sergeyu): Fix ChromotingHost so that it doesn't call this
// method on invalid thread and uncomment this DCHECK.
......@@ -493,6 +512,7 @@ void JingleSession::CreateChannels() {
base::Unretained(this)));
CreateStreamChannel(kControlChannelName, stream_callback);
CreateStreamChannel(kEventChannelName, stream_callback);
CreateStreamChannel(kVideoChannelName, stream_callback);
}
void JingleSession::OnStreamChannelConnected(const std::string& name,
......@@ -513,11 +533,14 @@ void JingleSession::OnChannelConnected(const std::string& name,
control_channel_socket_.reset(socket);
} else if (name == kEventChannelName) {
event_channel_socket_.reset(socket);
} else if (name == kVideoChannelName) {
video_channel_socket_.reset(socket);
} else {
NOTREACHED();
}
if (control_channel_socket_.get() && event_channel_socket_.get()) {
if (control_channel_socket_.get() && event_channel_socket_.get() &&
video_channel_socket_.get()) {
// TODO(sergeyu): State should be set to CONNECTED in OnAccept
// independent of the channels state.
SetState(CONNECTED);
......
......@@ -38,6 +38,9 @@ class JingleSession : public protocol::Session,
const DatagramChannelCallback& callback) OVERRIDE;
virtual net::Socket* control_channel() OVERRIDE;
virtual net::Socket* event_channel() OVERRIDE;
virtual net::Socket* video_channel() OVERRIDE;
virtual net::Socket* video_rtp_channel() OVERRIDE;
virtual net::Socket* video_rtcp_channel() OVERRIDE;
virtual const std::string& jid() OVERRIDE;
virtual const CandidateSessionConfig* candidate_config() OVERRIDE;
virtual const SessionConfig* config() OVERRIDE;
......@@ -182,6 +185,7 @@ class JingleSession : public protocol::Session,
scoped_ptr<net::Socket> control_channel_socket_;
scoped_ptr<net::Socket> event_channel_socket_;
scoped_ptr<net::Socket> video_channel_socket_;
ScopedRunnableMethodFactory<JingleSession> task_factory_;
......
......@@ -4,10 +4,7 @@
#include "remoting/protocol/protobuf_video_reader.h"
#include "base/bind.h"
#include "base/task.h"
#include "net/socket/stream_socket.h"
#include "remoting/base/constants.h"
#include "remoting/proto/video.pb.h"
#include "remoting/protocol/session.h"
......@@ -22,28 +19,11 @@ ProtobufVideoReader::ProtobufVideoReader(VideoPacketFormat::Encoding encoding)
ProtobufVideoReader::~ProtobufVideoReader() { }
void ProtobufVideoReader::Init(protocol::Session* session,
VideoStub* video_stub,
const InitializedCallback& callback) {
initialized_callback_ = callback;
VideoStub* video_stub) {
reader_.Init(
session->video_channel(),
NewCallback(this, &ProtobufVideoReader::OnNewData));
video_stub_ = video_stub;
session->CreateStreamChannel(
kVideoChannelName,
base::Bind(&ProtobufVideoReader::OnChannelReady, base::Unretained(this)));
}
void ProtobufVideoReader::OnChannelReady(const std::string& name,
net::StreamSocket* socket) {
DCHECK_EQ(name, std::string(kVideoChannelName));
if (!socket) {
initialized_callback_.Run(false);
return;
}
DCHECK(!channel_.get());
channel_.reset(socket);
reader_.Init(socket, NewCallback(this, &ProtobufVideoReader::OnNewData));
initialized_callback_.Run(true);
}
void ProtobufVideoReader::OnNewData(VideoPacket* packet, Task* done_task) {
......
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// 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 "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 {
......@@ -25,21 +20,13 @@ class ProtobufVideoReader : public VideoReader {
virtual ~ProtobufVideoReader();
// VideoReader interface.
virtual void Init(protocol::Session* session,
VideoStub* video_stub,
const InitializedCallback& callback) OVERRIDE;
virtual void Init(protocol::Session* session, VideoStub* video_stub);
private:
void OnChannelReady(const std::string& name, net::StreamSocket* socket);
void OnNewData(VideoPacket* packet, Task* done_task);
InitializedCallback initialized_callback_;
VideoPacketFormat::Encoding encoding_;
// TODO(sergeyu): Remove |channel_| and let |reader_| own it.
scoped_ptr<net::StreamSocket> channel_;
ProtobufMessageReader<VideoPacket> reader_;
// The stub that processes all received packets.
......
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// 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 "base/bind.h"
#include "base/task.h"
#include "net/socket/stream_socket.h"
#include "remoting/base/constants.h"
#include "remoting/proto/video.pb.h"
#include "remoting/protocol/rtp_writer.h"
#include "remoting/protocol/session.h"
......@@ -20,35 +17,14 @@ ProtobufVideoWriter::ProtobufVideoWriter() { }
ProtobufVideoWriter::~ProtobufVideoWriter() { }
void ProtobufVideoWriter::Init(protocol::Session* session,
const InitializedCallback& callback) {
initialized_callback_ = callback;
session->CreateStreamChannel(
kVideoChannelName,
base::Bind(&ProtobufVideoWriter::OnChannelReady, base::Unretained(this)));
}
void ProtobufVideoWriter::OnChannelReady(const std::string& name,
net::StreamSocket* socket) {
DCHECK_EQ(name, std::string(kVideoChannelName));
if (!socket) {
initialized_callback_.Run(false);
return;
}
DCHECK(!channel_.get());
channel_.reset(socket);
void ProtobufVideoWriter::Init(protocol::Session* session) {
buffered_writer_ = new BufferedSocketWriter();
// TODO(sergeyu): Provide WriteFailedCallback for the buffered writer.
buffered_writer_->Init(socket, NULL);
initialized_callback_.Run(true);
buffered_writer_->Init(session->video_channel(), NULL);
}
void ProtobufVideoWriter::Close() {
buffered_writer_->Close();
channel_.reset();
}
void ProtobufVideoWriter::ProcessVideoPacket(const VideoPacket* packet,
......
......@@ -5,17 +5,10 @@
#ifndef REMOTING_PROTOCOL_PROTOBUF_VIDEO_WRITER_H_
#define REMOTING_PROTOCOL_PROTOBUF_VIDEO_WRITER_H_
#include <string>
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "remoting/protocol/video_writer.h"
namespace net {
class StreamSocket;
} // namespace net
namespace remoting {
namespace protocol {
......@@ -28,8 +21,7 @@ class ProtobufVideoWriter : public VideoWriter {
virtual ~ProtobufVideoWriter();
// VideoWriter interface.
virtual void Init(protocol::Session* session,
const InitializedCallback& callback) OVERRIDE;
virtual void Init(protocol::Session* session) OVERRIDE;
virtual void Close() OVERRIDE;
// VideoStub interface.
......@@ -38,13 +30,6 @@ class ProtobufVideoWriter : public VideoWriter {
virtual int GetPendingPackets() OVERRIDE;
private:
void OnChannelReady(const std::string& name, net::StreamSocket* socket);
InitializedCallback initialized_callback_;
// TODO(sergeyu): Remove |channel_| and let |buffered_writer_| own it.
scoped_ptr<net::StreamSocket> channel_;
scoped_refptr<BufferedSocketWriter> buffered_writer_;
DISALLOW_COPY_AND_ASSIGN(ProtobufVideoWriter);
......
......@@ -4,9 +4,7 @@
#include "remoting/protocol/rtp_video_reader.h"
#include "base/bind.h"
#include "base/task.h"
#include "remoting/base/constants.h"
#include "remoting/proto/video.pb.h"
#include "remoting/protocol/session.h"
......@@ -24,8 +22,7 @@ RtpVideoReader::PacketsQueueEntry::PacketsQueueEntry()
}
RtpVideoReader::RtpVideoReader()
: initialized_(false),
last_sequence_number_(0),
: last_sequence_number_(0),
video_stub_(NULL) {
}
......@@ -33,47 +30,11 @@ RtpVideoReader::~RtpVideoReader() {
ResetQueue();
}
void RtpVideoReader::Init(protocol::Session* session,
VideoStub* video_stub,
const InitializedCallback& callback) {
initialized_callback_ = callback;
void RtpVideoReader::Init(protocol::Session* session, VideoStub* video_stub) {
rtp_reader_.Init(session->video_rtp_channel(),
NewCallback(this, &RtpVideoReader::OnRtpPacket));
rtcp_writer_.Init(session->video_rtcp_channel());
video_stub_ = video_stub;
session->CreateDatagramChannel(
kVideoRtpChannelName,
base::Bind(&RtpVideoReader::OnChannelReady, base::Unretained(this)));
session->CreateDatagramChannel(
kVideoRtcpChannelName,
base::Bind(&RtpVideoReader::OnChannelReady, base::Unretained(this)));
}
void RtpVideoReader::OnChannelReady(const std::string& name,
net::Socket* socket) {
if (!socket) {
if (!initialized_) {
initialized_ = true;
initialized_callback_.Run(false);
}
return;
}
if (name == kVideoRtpChannelName) {
DCHECK(!rtp_channel_.get());
rtp_channel_.reset(socket);
rtp_reader_.Init(socket, NewCallback(this, &RtpVideoReader::OnRtpPacket));
} else if (name == kVideoRtcpChannelName) {
DCHECK(!rtcp_channel_.get());
rtcp_channel_.reset(socket);
rtcp_writer_.Init(socket);
} else {
NOTREACHED();
}
if (rtp_channel_.get() && rtcp_channel_.get()) {
DCHECK(!initialized_);
initialized_ = true;
initialized_callback_.Run(true);
}
}
void RtpVideoReader::ResetQueue() {
......
......@@ -5,9 +5,7 @@
#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"
......@@ -15,8 +13,6 @@
namespace remoting {
namespace protocol {
class RtcpWriter;
class RtpReader;
class Session;
class RtpVideoReader : public VideoReader {
......@@ -25,9 +21,7 @@ class RtpVideoReader : public VideoReader {
virtual ~RtpVideoReader();
// VideoReader interface.
virtual void Init(protocol::Session* session,
VideoStub* video_stub,
const InitializedCallback& callback) OVERRIDE;
virtual void Init(protocol::Session* session, VideoStub* video_stub);
private:
friend class RtpVideoReaderTest;
......@@ -50,8 +44,6 @@ class RtpVideoReader : public VideoReader {
typedef std::deque<PacketsQueueEntry> PacketsQueue;
void OnChannelReady(const std::string& name, net::Socket* socket);
void OnRtpPacket(const RtpPacket* rtp_packet);
void CheckFullPacket(const PacketsQueue::iterator& pos);
void RebuildVideoPacket(const PacketsQueue::iterator& from,
......@@ -64,12 +56,7 @@ class RtpVideoReader : public VideoReader {
// |kReceiverReportsIntervalMs|.
void SendReceiverReportIf();
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_;
......
......@@ -4,7 +4,6 @@
#include <vector>
#include "base/bind.h"
#include "base/message_loop.h"
#include "base/string_number_conversions.h"
#include "net/base/io_buffer.h"
......@@ -66,16 +65,10 @@ class RtpVideoReaderTest : public testing::Test,
void Reset() {
session_.reset(new FakeSession());
reader_.reset(new RtpVideoReader());
reader_->Init(session_.get(), this,
base::Bind(&RtpVideoReaderTest::OnReaderInitialized,
base::Unretained(this)));
reader_->Init(session_.get(), 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) {
......
......@@ -4,11 +4,9 @@
#include "remoting/protocol/rtp_video_writer.h"
#include "base/bind.h"
#include "base/task.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"
......@@ -20,56 +18,18 @@ namespace {
const int kMtu = 1200;
} // namespace
RtpVideoWriter::RtpVideoWriter()
: initialized_(false) {
}
RtpVideoWriter::RtpVideoWriter() { }
RtpVideoWriter::~RtpVideoWriter() {
Close();
}
void RtpVideoWriter::Init(protocol::Session* session,
const InitializedCallback& callback) {
initialized_callback_ = callback;
session->CreateDatagramChannel(
kVideoRtpChannelName,
base::Bind(&RtpVideoWriter::OnChannelReady, base::Unretained(this)));
session->CreateDatagramChannel(
kVideoRtcpChannelName,
base::Bind(&RtpVideoWriter::OnChannelReady, base::Unretained(this)));
}
void RtpVideoWriter::OnChannelReady(const std::string& name,
net::Socket* socket) {
if (!socket) {
if (!initialized_) {
initialized_ = true;
initialized_callback_.Run(false);
}
return;
}
if (name == kVideoRtpChannelName) {
DCHECK(!rtp_channel_.get());
rtp_channel_.reset(socket);
rtp_writer_.Init(socket);
} else if (name == kVideoRtcpChannelName) {
DCHECK(!rtcp_channel_.get());
rtcp_channel_.reset(socket);
// TODO(sergeyu): Use RTCP channel somehow.
}
if (rtp_channel_.get() && rtcp_channel_.get()) {
DCHECK(!initialized_);
initialized_ = true;
initialized_callback_.Run(true);
}
void RtpVideoWriter::Init(protocol::Session* session) {
rtp_writer_.Init(session->video_rtp_channel());
}
void RtpVideoWriter::Close() {
rtp_writer_.Close();
rtp_channel_.reset();
rtcp_channel_.reset();
}
void RtpVideoWriter::ProcessVideoPacket(const VideoPacket* packet, Task* done) {
......
......@@ -5,7 +5,6 @@
#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"
......@@ -20,8 +19,7 @@ class RtpVideoWriter : public VideoWriter {
virtual ~RtpVideoWriter();
// VideoWriter interface.
virtual void Init(protocol::Session* session,
const InitializedCallback& callback) OVERRIDE;
virtual void Init(protocol::Session* session) OVERRIDE;
virtual void Close() OVERRIDE;
// VideoStub interface.
......@@ -30,14 +28,7 @@ class RtpVideoWriter : public VideoWriter {
virtual int GetPendingPackets() OVERRIDE;
private:
void OnChannelReady(const std::string& name, net::Socket* socket);
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);
};
......
......@@ -5,10 +5,8 @@
#include <string>
#include <vector>
#include "base/bind.h"
#include "base/message_loop.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"
......@@ -59,13 +57,7 @@ class RtpVideoWriterTest : public testing::Test {
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);
writer_.Init(session_.get());
}
void InitData(int size) {
......@@ -96,7 +88,7 @@ class RtpVideoWriterTest : public testing::Test {
void VerifyResult(const ExpectedPacket expected[],
int count) {
const vector<string>& rtp_packets =
session_->GetDatagramChannel(kVideoRtpChannelName)->written_packets();
session_->video_rtp_channel()->written_packets();
ASSERT_EQ(count, static_cast<int>(rtp_packets.size()));
int pos = 0;
for (int i = 0; i < count; ++i) {
......
......@@ -64,6 +64,9 @@ class Session : public base::NonThreadSafe {
// instead.
virtual net::Socket* control_channel() = 0;
virtual net::Socket* event_channel() = 0;
virtual net::Socket* video_channel() = 0;
virtual net::Socket* video_rtp_channel() = 0;
virtual net::Socket* video_rtcp_channel() = 0;
// JID of the other side.
virtual const std::string& jid() = 0;
......
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// 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.
......@@ -25,17 +25,12 @@ class VideoReader {
public:
static VideoReader* Create(const SessionConfig* config);
// The callback is called when initialization is finished. The
// parameter is set to true on success.
typedef base::Callback<void(bool)> InitializedCallback;
virtual ~VideoReader();
// 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;
VideoStub* video_stub) = 0;
protected:
VideoReader() { }
......
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// 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.
......@@ -11,7 +11,6 @@
#define REMOTING_PROTOCOL_VIDEO_WRITER_H_
#include "base/basictypes.h"
#include "base/callback.h"
#include "remoting/protocol/video_stub.h"
namespace remoting {
......@@ -24,14 +23,10 @@ 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 VideoWriter* Create(const SessionConfig* config);
// Initializes the writer.
virtual void Init(Session* session, const InitializedCallback& callback) = 0;
virtual void Init(Session* session) = 0;
// Stops writing. Must be called on the network thread before this
// object is destroyed.
......
# Following tests create real libjingle connections, and libjingle has
# hardcoded timeouts, so these tests fail under TSan.
JingleSessionTest.Connect
JingleSessionTest.TestUdpChannel
JingleSessionTest.TestTcpChannel
JingleSessionTest.TestControlChannel
JingleSessionTest.TestEventChannel
JingleSessionTest.TestVideoChannel
JingleSessionTest.TestVideoRtpChannel
JingleSessionTest.TestSpeed
# This test fails on an assertion, see http://crbug.com/57266
......
......@@ -2,6 +2,8 @@
# hardcoded timeouts, so these tests fail under TSan.
JingleSessionTest.Connect
JingleSessionTest.ConnectBadChannelAuth
JingleSessionTest.TestUdpChannel
JingleSessionTest.TestTcpChannel
JingleSessionTest.TestControlChannel
JingleSessionTest.TestEventChannel
JingleSessionTest.TestSpeed
JingleSessionTest.TestVideoChannel
JingleSessionTest.TestVideoRtpChannel
# Following tests create real libjingle connections, and libjingle has
# hardcoded timeouts, so these tests fail under TSan.
JingleSessionTest.Connect
JingleSessionTest.TestUdpChannel
JingleSessionTest.TestTcpChannel
JingleSessionTest.TestControlChannel
JingleSessionTest.TestEventChannel
JingleSessionTest.TestVideoChannel
JingleSessionTest.TestVideoRtpChannel
JingleSessionTest.TestSpeed
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