diff options
author | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-09 21:56:39 +0000 |
---|---|---|
committer | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-09 21:56:39 +0000 |
commit | ef0a59a6fd722a0910196c951dc676c19127a28b (patch) | |
tree | 9d90ab9227e4222fa312dadae114c8d2247028bf /remoting/host | |
parent | e9fdd159ffd94e3e097bd6905d84e6b564b04c2c (diff) | |
download | chromium_src-ef0a59a6fd722a0910196c951dc676c19127a28b.zip chromium_src-ef0a59a6fd722a0910196c951dc676c19127a28b.tar.gz chromium_src-ef0a59a6fd722a0910196c951dc676c19127a28b.tar.bz2 |
Implement a chromoting client using X11
Using XRender to render the chromoting client. This patch has done several things:
1. Rename chromotocol_pb to remoting
2. Defined ChromotingView as the display area of the remote view
3. Implemented X11Client as the client that uses X11 for display
4. Implemented X11View that uses XRender for drawing
5. Fixed several problems in host capturer and encoder
Review URL: http://codereview.chromium.org/2745006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49329 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/host')
-rw-r--r-- | remoting/host/capturer.cc | 4 | ||||
-rw-r--r-- | remoting/host/capturer.h | 4 | ||||
-rw-r--r-- | remoting/host/capturer_fake.cc | 12 | ||||
-rw-r--r-- | remoting/host/capturer_fake_ascii.cc | 2 | ||||
-rw-r--r-- | remoting/host/capturer_gdi.cc | 2 | ||||
-rw-r--r-- | remoting/host/client_connection.cc | 10 | ||||
-rw-r--r-- | remoting/host/client_connection.h | 2 | ||||
-rw-r--r-- | remoting/host/client_connection_unittest.cc | 3 | ||||
-rw-r--r-- | remoting/host/encoder.h | 4 | ||||
-rw-r--r-- | remoting/host/encoder_verbatim.cc | 38 | ||||
-rw-r--r-- | remoting/host/encoder_verbatim.h | 7 | ||||
-rw-r--r-- | remoting/host/encoder_vp8.cc | 2 | ||||
-rw-r--r-- | remoting/host/encoder_vp8.h | 2 | ||||
-rw-r--r-- | remoting/host/encoder_vp8_unittest.cc | 3 | ||||
-rw-r--r-- | remoting/host/event_executor_win.cc | 10 | ||||
-rw-r--r-- | remoting/host/mock_objects.h | 8 | ||||
-rw-r--r-- | remoting/host/session_manager.cc | 23 | ||||
-rw-r--r-- | remoting/host/session_manager.h | 6 | ||||
-rw-r--r-- | remoting/host/session_manager_unittest.cc | 6 | ||||
-rw-r--r-- | remoting/host/simple_host.cc | 30 |
20 files changed, 95 insertions, 83 deletions
diff --git a/remoting/host/capturer.cc b/remoting/host/capturer.cc index 2f92d18..789723b 100644 --- a/remoting/host/capturer.cc +++ b/remoting/host/capturer.cc @@ -9,7 +9,7 @@ namespace remoting { Capturer::Capturer() : width_(0), height_(0), - pixel_format_(chromotocol_pb::PixelFormatInvalid), + pixel_format_(PixelFormatInvalid), bytes_per_pixel_(0), bytes_per_row_(0), current_buffer_(0) { @@ -30,7 +30,7 @@ int Capturer::GetHeight() const { return height_; } -chromotocol_pb::PixelFormat Capturer::GetPixelFormat() const { +PixelFormat Capturer::GetPixelFormat() const { return pixel_format_; } diff --git a/remoting/host/capturer.h b/remoting/host/capturer.h index 64e25f2..6007b350 100644 --- a/remoting/host/capturer.h +++ b/remoting/host/capturer.h @@ -77,7 +77,7 @@ class Capturer { virtual int GetHeight() const; // Get the pixel format of the image captured. - virtual chromotocol_pb::PixelFormat GetPixelFormat() const; + virtual PixelFormat GetPixelFormat() const; // Invalidate the specified screen rect. virtual void InvalidateRect(gfx::Rect dirty); @@ -100,7 +100,7 @@ class Capturer { int height_; // Format of pixels returned in buffer. - chromotocol_pb::PixelFormat pixel_format_; + PixelFormat pixel_format_; // Information about screen. int bytes_per_pixel_; diff --git a/remoting/host/capturer_fake.cc b/remoting/host/capturer_fake.cc index 5c087b39..f1a8135 100644 --- a/remoting/host/capturer_fake.cc +++ b/remoting/host/capturer_fake.cc @@ -8,9 +8,9 @@ namespace remoting { -static const int kWidth = 640; -static const int kHeight = 480; -static const int kBytesPerPixel = 3; // 24 bit RGB is 3 bytes per pixel. +static const int kWidth = 320; +static const int kHeight = 240; +static const int kBytesPerPixel = 4; // 32 bit RGB is 4 bytes per pixel. static const int kMaxColorChannelValue = 255; CapturerFake::CapturerFake() @@ -18,7 +18,7 @@ CapturerFake::CapturerFake() // Dimensions of screen. width_ = kWidth; height_ = kHeight; - pixel_format_ = chromotocol_pb::PixelFormatRgb24; + pixel_format_ = PixelFormatRgb32; bytes_per_pixel_ = kBytesPerPixel; bytes_per_row_ = width_ * bytes_per_pixel_; @@ -75,12 +75,14 @@ void CapturerFake::GetDataStride(int strides[]) const { void CapturerFake::GenerateImage() { uint8* row = buffers_[current_buffer_].get(); for (int y = 0; y < height_; ++y) { + int offset = y % 3; for (int x = 0; x < width_; ++x) { - row[x] = seed_++; + row[x * kBytesPerPixel + offset] = seed_++; seed_ &= kMaxColorChannelValue; } row += bytes_per_row_; } + ++seed_; } } // namespace remoting diff --git a/remoting/host/capturer_fake_ascii.cc b/remoting/host/capturer_fake_ascii.cc index 7ab7e6b..00f8529 100644 --- a/remoting/host/capturer_fake_ascii.cc +++ b/remoting/host/capturer_fake_ascii.cc @@ -16,7 +16,7 @@ CapturerFakeAscii::CapturerFakeAscii() { // Dimensions of screen. width_ = kWidth; height_ = kHeight; - pixel_format_ = chromotocol_pb::PixelFormatAscii; + pixel_format_ = PixelFormatAscii; bytes_per_pixel_ = kBytesPerPixel; bytes_per_row_ = width_ * bytes_per_pixel_; diff --git a/remoting/host/capturer_gdi.cc b/remoting/host/capturer_gdi.cc index 3b5a844..af32f9b 100644 --- a/remoting/host/capturer_gdi.cc +++ b/remoting/host/capturer_gdi.cc @@ -84,7 +84,7 @@ void CapturerGdi::InitializeBuffers() { int rounded_width = (width_ + 3) & (~3); // Dimensions of screen. - pixel_format_ = chromotocol_pb::PixelFormatRgb24; + pixel_format_ = PixelFormatRgb24; bytes_per_pixel_ = kBytesPerPixel; bytes_per_row_ = rounded_width * bytes_per_pixel_; diff --git a/remoting/host/client_connection.cc b/remoting/host/client_connection.cc index 9ae7b95..5bf962c 100644 --- a/remoting/host/client_connection.cc +++ b/remoting/host/client_connection.cc @@ -40,7 +40,7 @@ void ClientConnection::SendInitClientMessage(int width, int height) { DCHECK(!update_stream_size_); DCHECK(channel_.get()); - chromotocol_pb::HostMessage msg; + HostMessage msg; msg.mutable_init_client()->set_width(width); msg.mutable_init_client()->set_height(height); DCHECK(msg.IsInitialized()); @@ -51,7 +51,7 @@ void ClientConnection::SendBeginUpdateStreamMessage() { DCHECK_EQ(loop_, MessageLoop::current()); DCHECK(channel_.get()); - chromotocol_pb::HostMessage msg; + HostMessage msg; msg.mutable_begin_update_stream(); DCHECK(msg.IsInitialized()); @@ -62,12 +62,12 @@ void ClientConnection::SendBeginUpdateStreamMessage() { } void ClientConnection::SendUpdateStreamPacketMessage( - chromotocol_pb::UpdateStreamPacketHeader* header, + UpdateStreamPacketHeader* header, scoped_refptr<DataBuffer> data) { DCHECK_EQ(loop_, MessageLoop::current()); DCHECK(channel_.get()); - chromotocol_pb::HostMessage msg; + HostMessage msg; msg.mutable_update_stream_packet()->mutable_header()->CopyFrom(*header); // TODO(hclam): This introduce one memory copy. Eliminate it. msg.mutable_update_stream_packet()->set_data( @@ -83,7 +83,7 @@ void ClientConnection::SendEndUpdateStreamMessage() { DCHECK_EQ(loop_, MessageLoop::current()); DCHECK(channel_.get()); - chromotocol_pb::HostMessage msg; + HostMessage msg; msg.mutable_end_update_stream(); DCHECK(msg.IsInitialized()); diff --git a/remoting/host/client_connection.h b/remoting/host/client_connection.h index 13318c3..4b46ee3 100644 --- a/remoting/host/client_connection.h +++ b/remoting/host/client_connection.h @@ -78,7 +78,7 @@ class ClientConnection : public base::RefCountedThreadSafe<ClientConnection>, // Send encoded update stream data to the viewer. The viewer // should not take ownership of the data. virtual void SendUpdateStreamPacketMessage( - chromotocol_pb::UpdateStreamPacketHeader* header, + UpdateStreamPacketHeader* header, scoped_refptr<media::DataBuffer> data); // Notifies the viewer the update stream has ended. diff --git a/remoting/host/client_connection_unittest.cc b/remoting/host/client_connection_unittest.cc index 1256f25..d7be888 100644 --- a/remoting/host/client_connection_unittest.cc +++ b/remoting/host/client_connection_unittest.cc @@ -51,8 +51,7 @@ TEST_F(ClientConnectionTest, SendUpdateStream) { // Then send the actual data. EXPECT_CALL(*channel_, Write(_)); - chromotocol_pb::UpdateStreamPacketHeader* header - = new chromotocol_pb::UpdateStreamPacketHeader(); + UpdateStreamPacketHeader* header = new UpdateStreamPacketHeader(); header->set_x(0); header->set_y(0); header->set_width(640); diff --git a/remoting/host/encoder.h b/remoting/host/encoder.h index e3af66b..53ddb63 100644 --- a/remoting/host/encoder.h +++ b/remoting/host/encoder.h @@ -44,7 +44,7 @@ class Encoder { const uint8** input_data, const int* strides, bool key_frame, - chromotocol_pb::UpdateStreamPacketHeader* header, + UpdateStreamPacketHeader* header, scoped_refptr<media::DataBuffer>* output_data, bool* encode_done, Task* data_available_task) = 0; @@ -55,7 +55,7 @@ class Encoder { // Set the pixel format of the incoming images. Need to call this before // calling Encode(). - virtual void SetPixelFormat(chromotocol_pb::PixelFormat pixel_format) = 0; + virtual void SetPixelFormat(PixelFormat pixel_format) = 0; }; } // namespace remoting diff --git a/remoting/host/encoder_verbatim.cc b/remoting/host/encoder_verbatim.cc index 0ef7677..58525f1 100644 --- a/remoting/host/encoder_verbatim.cc +++ b/remoting/host/encoder_verbatim.cc @@ -10,17 +10,16 @@ namespace remoting { -using chromotocol_pb::UpdateStreamPacketHeader; using media::DataBuffer; void EncoderVerbatim::Encode(const DirtyRects& dirty_rects, - const uint8** input_data, - const int* strides, - bool key_frame, - UpdateStreamPacketHeader* header, - scoped_refptr<DataBuffer>* output_data, - bool* encode_done, - Task* data_available_task) { + const uint8** input_data, + const int* strides, + bool key_frame, + UpdateStreamPacketHeader* header, + scoped_refptr<DataBuffer>* output_data, + bool* encode_done, + Task* data_available_task) { int num_rects = dirty_rects.size(); for (int i = 0; i < num_rects; i++) { if (EncodeRect(dirty_rects[i], input_data, strides, header, output_data)) { @@ -37,26 +36,28 @@ void EncoderVerbatim::SetSize(int width, int height) { height_ = height; } -void EncoderVerbatim::SetPixelFormat(chromotocol_pb::PixelFormat pixel_format) { +void EncoderVerbatim::SetPixelFormat(PixelFormat pixel_format) { // These are sorted so that the most common formats are checked first. - if (pixel_format == chromotocol_pb::PixelFormatRgb24) { + // TODO(hclam): Extract this into a util function. + if (pixel_format == PixelFormatRgb24) { bytes_per_pixel_ = 3; - } else if (pixel_format == chromotocol_pb::PixelFormatRgb565) { + } else if (pixel_format == PixelFormatRgb565) { bytes_per_pixel_ = 2; - } else if (pixel_format == chromotocol_pb::PixelFormatRgb32) { + } else if (pixel_format == PixelFormatRgb32) { bytes_per_pixel_ = 4; - } else if (pixel_format != chromotocol_pb::PixelFormatAscii) { + } else if (pixel_format != PixelFormatAscii) { bytes_per_pixel_ = 1; } else { NOTREACHED() << "Pixel format not supported"; } + pixel_format_ = pixel_format; } bool EncoderVerbatim::EncodeRect(const gfx::Rect& dirty, - const uint8** input_data, - const int* strides, - UpdateStreamPacketHeader* header, - scoped_refptr<DataBuffer>* output_data) { + const uint8** input_data, + const int* strides, + UpdateStreamPacketHeader* header, + scoped_refptr<DataBuffer>* output_data) { const int kPlanes = 3; // Calculate the size of output. @@ -70,7 +71,8 @@ bool EncoderVerbatim::EncodeRect(const gfx::Rect& dirty, header->set_y(dirty.y()); header->set_width(dirty.width()); header->set_height(dirty.height()); - header->set_encoding(chromotocol_pb::EncodingNone); + header->set_encoding(EncodingNone); + header->set_pixel_format(pixel_format_); *output_data = new DataBuffer(output_size); (*output_data)->SetDataSize(output_size); diff --git a/remoting/host/encoder_verbatim.h b/remoting/host/encoder_verbatim.h index 2b5e39d..d7a1760 100644 --- a/remoting/host/encoder_verbatim.h +++ b/remoting/host/encoder_verbatim.h @@ -21,12 +21,12 @@ class EncoderVerbatim : public Encoder { const uint8** input_data, const int* strides, bool key_frame, - chromotocol_pb::UpdateStreamPacketHeader* header, + UpdateStreamPacketHeader* header, scoped_refptr<media::DataBuffer>* output_data, bool* encode_done, Task* data_available_task); virtual void SetSize(int width, int height); - virtual void SetPixelFormat(chromotocol_pb::PixelFormat pixel_format); + virtual void SetPixelFormat(PixelFormat pixel_format); private: // Encode a single dirty rect. Called by Encode(). @@ -34,12 +34,13 @@ class EncoderVerbatim : public Encoder { bool EncodeRect(const gfx::Rect& dirty, const uint8** input_data, const int* strides, - chromotocol_pb::UpdateStreamPacketHeader* header, + UpdateStreamPacketHeader* header, scoped_refptr<media::DataBuffer>* output_data); int width_; int height_; int bytes_per_pixel_; + PixelFormat pixel_format_; }; } // namespace remoting diff --git a/remoting/host/encoder_vp8.cc b/remoting/host/encoder_vp8.cc index a1e45e7..231acd5 100644 --- a/remoting/host/encoder_vp8.cc +++ b/remoting/host/encoder_vp8.cc @@ -56,7 +56,7 @@ void EncoderVp8::Encode(const DirtyRects& dirty_rects, const uint8** input_data, const int* strides, bool key_frame, - chromotocol_pb::UpdateStreamPacketHeader* header, + UpdateStreamPacketHeader* header, scoped_refptr<media::DataBuffer>* output_data, bool* encode_done, Task* data_available_task) { diff --git a/remoting/host/encoder_vp8.h b/remoting/host/encoder_vp8.h index e8c73b7..1cd16ac 100644 --- a/remoting/host/encoder_vp8.h +++ b/remoting/host/encoder_vp8.h @@ -32,7 +32,7 @@ class EncoderVp8 : public Encoder { const uint8** input_data, const int* strides, bool key_frame, - chromotocol_pb::UpdateStreamPacketHeader* header, + UpdateStreamPacketHeader* header, scoped_refptr<media::DataBuffer>* output_data, bool* encode_done, Task* data_available_task); diff --git a/remoting/host/encoder_vp8_unittest.cc b/remoting/host/encoder_vp8_unittest.cc index 2dbc81b..0b29830 100644 --- a/remoting/host/encoder_vp8_unittest.cc +++ b/remoting/host/encoder_vp8_unittest.cc @@ -47,8 +47,7 @@ TEST(EncoderVp8Test, SimpleEncode) { GenerateData(planes[2], kWidth * kHeight / 4); scoped_refptr<EncodeDoneHandler> handler = new EncodeDoneHandler(); - chromotocol_pb::UpdateStreamPacketHeader* header - = new chromotocol_pb::UpdateStreamPacketHeader(); + UpdateStreamPacketHeader* header = new UpdateStreamPacketHeader(); scoped_refptr<media::DataBuffer> encoded_data; bool encode_done = false; EXPECT_CALL(*handler, EncodeDone()); diff --git a/remoting/host/event_executor_win.cc b/remoting/host/event_executor_win.cc index cc7f8f8..de82a5a 100644 --- a/remoting/host/event_executor_win.cc +++ b/remoting/host/event_executor_win.cc @@ -355,7 +355,7 @@ EventExecutorWin::~EventExecutorWin() { void EventExecutorWin::HandleInputEvents(ClientMessageList* messages) { for (size_t i = 0; i < messages->size(); ++i) { - chromotocol_pb::ClientMessage* msg = (*messages)[i]; + ClientMessage* msg = (*messages)[i]; if (msg->has_mouse_set_position_event()) { mouse_event(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, static_cast<int>((msg->mouse_set_position_event().x() * 65535)), @@ -369,20 +369,20 @@ void EventExecutorWin::HandleInputEvents(ClientMessageList* messages) { // TODO(hclam): Handle wheel events. } else if (msg->has_mouse_down_event()) { if (msg->mouse_down_event().button() == - chromotocol_pb::MouseDownEvent::LEFT) { + MouseDownEvent::LEFT) { mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0); } else if (msg->mouse_down_event().button() == - chromotocol_pb::MouseDownEvent::RIGHT) { + MouseDownEvent::RIGHT) { mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0); } else { // TODO(hclam): Handle other buttons. } } else if (msg->has_mouse_up_event()) { if (msg->mouse_up_event().button() == - chromotocol_pb::MouseUpEvent::LEFT) { + MouseUpEvent::LEFT) { mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0); } else if (msg->mouse_up_event().button() == - chromotocol_pb::MouseUpEvent::RIGHT) { + MouseUpEvent::RIGHT) { mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0); } else { // TODO(hclam): Handle other buttons. diff --git a/remoting/host/mock_objects.h b/remoting/host/mock_objects.h index 1f33263..d492376 100644 --- a/remoting/host/mock_objects.h +++ b/remoting/host/mock_objects.h @@ -27,7 +27,7 @@ class MockCapturer : public Capturer { MOCK_CONST_METHOD1(GetDirtyRects, void(DirtyRects* rects)); MOCK_CONST_METHOD0(GetWidth, int()); MOCK_CONST_METHOD0(GetHeight, int()); - MOCK_CONST_METHOD0(GetPixelFormat, chromotocol_pb::PixelFormat()); + MOCK_CONST_METHOD0(GetPixelFormat, PixelFormat()); private: DISALLOW_COPY_AND_ASSIGN(MockCapturer); @@ -42,12 +42,12 @@ class MockEncoder : public Encoder { const uint8** planes, const int* strides, bool key_frame, - chromotocol_pb::UpdateStreamPacketHeader* output_data_header, + UpdateStreamPacketHeader* output_data_header, scoped_refptr<media::DataBuffer>* output_data, bool* encode_done, Task* data_available_task)); MOCK_METHOD2(SetSize, void(int width, int height)); - MOCK_METHOD1(SetPixelFormat, void(chromotocol_pb::PixelFormat pixel_format)); + MOCK_METHOD1(SetPixelFormat, void(PixelFormat pixel_format)); private: DISALLOW_COPY_AND_ASSIGN(MockEncoder); @@ -70,7 +70,7 @@ class MockClientConnection : public ClientConnection { MOCK_METHOD2(SendInitClientMessage, void(int width, int height)); MOCK_METHOD0(SendBeginUpdateStreamMessage, void()); MOCK_METHOD2(SendUpdateStreamPacketMessage, - void(chromotocol_pb::UpdateStreamPacketHeader* header, + void(UpdateStreamPacketHeader* header, scoped_refptr<media::DataBuffer> data)); MOCK_METHOD0(SendEndUpdateStreamMessage, void()); MOCK_METHOD0(GetPendingUpdateStreamMessages, int()); diff --git a/remoting/host/session_manager.cc b/remoting/host/session_manager.cc index da16a55..0160993 100644 --- a/remoting/host/session_manager.cc +++ b/remoting/host/session_manager.cc @@ -49,7 +49,7 @@ SessionManager::SessionManager( rate_control_started_(false), capture_width_(0), capture_height_(0), - capture_pixel_format_(chromotocol_pb::PixelFormatInvalid), + capture_pixel_format_(PixelFormatInvalid), encode_stream_started_(false), encode_done_(false) { DCHECK(capture_loop_); @@ -59,7 +59,6 @@ SessionManager::SessionManager( SessionManager::~SessionManager() { clients_.clear(); - DCHECK_EQ(0u, clients_.size()); } void SessionManager::Start() { @@ -132,9 +131,10 @@ void SessionManager::SetMaxRate(double rate) { } void SessionManager::AddClient(scoped_refptr<ClientConnection> client) { - network_loop_->PostTask( + // Gets the init information for the client. + capture_loop_->PostTask( FROM_HERE, - NewRunnableMethod(this, &SessionManager::DoAddClient, client)); + NewRunnableMethod(this, &SessionManager::DoGetInitInfo, client)); } void SessionManager::RemoveClient(scoped_refptr<ClientConnection> client) { @@ -214,7 +214,7 @@ void SessionManager::DoEncode() { } void SessionManager::DoSendUpdate( - chromotocol_pb::UpdateStreamPacketHeader* header, + UpdateStreamPacketHeader* header, scoped_refptr<media::DataBuffer> encoded_data, bool begin_update, bool end_update) { DCHECK_EQ(network_loop_, MessageLoop::current()); @@ -242,10 +242,18 @@ void SessionManager::DoSendInit(scoped_refptr<ClientConnection> client, void SessionManager::DoGetInitInfo(scoped_refptr<ClientConnection> client) { DCHECK_EQ(capture_loop_, MessageLoop::current()); + // Sends the init message to the cleint. network_loop_->PostTask( FROM_HERE, NewRunnableMethod(this, &SessionManager::DoSendInit, client, capturer_->GetWidth(), capturer_->GetHeight())); + + // And then add the client to the list so it can receive update stream. + // It is important we do so in such order or the client will receive + // update stream before init message. + network_loop_->PostTask( + FROM_HERE, + NewRunnableMethod(this, &SessionManager::DoAddClient, client)); } void SessionManager::DoSetRate(double rate) { @@ -279,11 +287,6 @@ void SessionManager::DoAddClient(scoped_refptr<ClientConnection> client) { // TODO(hclam): Force a full frame for next encode. clients_.push_back(client); - - // Gets the init information for the client. - capture_loop_->PostTask( - FROM_HERE, - NewRunnableMethod(this, &SessionManager::DoGetInitInfo, client)); } void SessionManager::DoRemoveClient(scoped_refptr<ClientConnection> client) { diff --git a/remoting/host/session_manager.h b/remoting/host/session_manager.h index 2a88020..677e3bd 100644 --- a/remoting/host/session_manager.h +++ b/remoting/host/session_manager.h @@ -104,7 +104,7 @@ class SessionManager : public base::RefCountedThreadSafe<SessionManager> { void DoFinishEncode(); void DoEncode(); void DoSendUpdate( - chromotocol_pb::UpdateStreamPacketHeader* header, + UpdateStreamPacketHeader* header, scoped_refptr<media::DataBuffer> encoded_data, bool begin_update, bool end_update); @@ -168,11 +168,11 @@ class SessionManager : public base::RefCountedThreadSafe<SessionManager> { int capture_data_strides_[3]; int capture_width_; int capture_height_; - chromotocol_pb::PixelFormat capture_pixel_format_; + PixelFormat capture_pixel_format_; // The following members are accessed on the encode thread. // Output parameter written by Encoder to carry encoded data. - chromotocol_pb::UpdateStreamPacketHeader encoded_data_header_; + UpdateStreamPacketHeader encoded_data_header_; scoped_refptr<media::DataBuffer> encoded_data_; // True if we have started receiving encoded data from the Encoder. diff --git a/remoting/host/session_manager_unittest.cc b/remoting/host/session_manager_unittest.cc index 9f4cdea..008d063 100644 --- a/remoting/host/session_manager_unittest.cc +++ b/remoting/host/session_manager_unittest.cc @@ -28,8 +28,8 @@ static uint8* kData[3] = { reinterpret_cast<uint8*>(0x02), reinterpret_cast<uint8*>(0x03), }; -static const chromotocol_pb::PixelFormat kFormat = - chromotocol_pb::PixelFormatRgb32; +static const PixelFormat kFormat = + PixelFormatRgb32; class SessionManagerTest : public testing::Test { public: @@ -106,7 +106,7 @@ TEST_F(SessionManagerTest, OneRecordCycle) { .WillOnce(Return(kFormat)); // Expect the encoder be called. - chromotocol_pb::UpdateStreamPacketHeader header; + UpdateStreamPacketHeader header; scoped_refptr<media::DataBuffer> buffer = new media::DataBuffer(0); EXPECT_CALL(*encoder_, SetSize(kWidth, kHeight)); EXPECT_CALL(*encoder_, SetPixelFormat(kFormat)); diff --git a/remoting/host/simple_host.cc b/remoting/host/simple_host.cc index 8455ff5..ab9f6b7 100644 --- a/remoting/host/simple_host.cc +++ b/remoting/host/simple_host.cc @@ -45,11 +45,16 @@ void SimpleHost::DestroySession() { // First we tell the session to pause and then we wait until all // the tasks are done. - session_->Pause(); + if (session_.get()) { + session_->Pause(); - // TODO(hclam): Revise the order. - encode_thread_.Stop(); - capture_thread_.Stop(); + // TODO(hclam): Revise the order. + DCHECK(encode_thread_.IsRunning()); + encode_thread_.Stop(); + + DCHECK(capture_thread_.IsRunning()); + capture_thread_.Stop(); + } } // This method talks to the cloud to register the host process. If @@ -69,7 +74,7 @@ void SimpleHost::OnClientConnected(ClientConnection* client) { DCHECK_EQ(&main_loop_, MessageLoop::current()); // Create a new RecordSession if there was none. - if (!session_) { + if (!session_.get()) { // The first we need to make sure capture and encode thread are // running. capture_thread_.Start(); @@ -101,8 +106,8 @@ void SimpleHost::OnClientDisconnected(ClientConnection* client) { DCHECK_EQ(&main_loop_, MessageLoop::current()); // Remove the client from the session manager. - DCHECK(session_); - session_->RemoveClient(client); + if (session_.get()) + session_->RemoveClient(client); // Also remove reference to ClientConnection from this object. client_ = NULL; @@ -157,10 +162,8 @@ void SimpleHost::OnStateChange(JingleClient* jingle_client, DCHECK_EQ(jingle_client_.get(), jingle_client); if (state == JingleClient::CONNECTED) { - // TODO(hclam): Change to use LOG(INFO). - // LOG(INFO) << "Host connected as " - // << jingle_client->GetFullJid() << "." << std::endl; - printf("Host connected as %s\n", jingle_client->GetFullJid().c_str()); + LOG(INFO) << "Host connected as " + << jingle_client->GetFullJid() << "." << std::endl; // Start heartbeating after we connected heartbeat_sender_ = new HeartbeatSender(); @@ -168,8 +171,10 @@ void SimpleHost::OnStateChange(JingleClient* jingle_client, heartbeat_sender_->Start(jingle_client_.get(), "HostID"); } else if (state == JingleClient::CLOSED) { LOG(INFO) << "Host disconnected from talk network." << std::endl; - heartbeat_sender_ = NULL; + + // Quit the message loop if disconected. + main_loop_.PostTask(FROM_HERE, new MessageLoop::QuitTask()); } } @@ -178,6 +183,7 @@ bool SimpleHost::OnAcceptConnection( JingleChannel::Callback** channel_callback) { DCHECK_EQ(jingle_client_.get(), jingle_client); + // TODO(hclam): Allow multiple clients to connect to the host. if (client_.get()) return false; |