| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "remoting/host/client_connection.h" | 5 #include "remoting/host/client_connection.h" |
| 6 | 6 |
| 7 #include "google/protobuf/message.h" | 7 #include "google/protobuf/message.h" |
| 8 #include "media/base/data_buffer.h" | 8 #include "media/base/data_buffer.h" |
| 9 #include "remoting/base/protocol_decoder.h" | 9 #include "remoting/base/protocol_decoder.h" |
| 10 #include "remoting/base/protocol_util.h" | 10 #include "remoting/base/protocol_util.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 ClientConnection::~ClientConnection() { | 33 ClientConnection::~ClientConnection() { |
| 34 // TODO(hclam): When we shut down the viewer we may have to close the | 34 // TODO(hclam): When we shut down the viewer we may have to close the |
| 35 // jingle channel. | 35 // jingle channel. |
| 36 } | 36 } |
| 37 | 37 |
| 38 void ClientConnection::SendInitClientMessage(int width, int height) { | 38 void ClientConnection::SendInitClientMessage(int width, int height) { |
| 39 DCHECK_EQ(loop_, MessageLoop::current()); | 39 DCHECK_EQ(loop_, MessageLoop::current()); |
| 40 DCHECK(!update_stream_size_); | 40 DCHECK(!update_stream_size_); |
| 41 DCHECK(channel_.get()); | 41 DCHECK(channel_.get()); |
| 42 | 42 |
| 43 chromotocol_pb::HostMessage msg; | 43 HostMessage msg; |
| 44 msg.mutable_init_client()->set_width(width); | 44 msg.mutable_init_client()->set_width(width); |
| 45 msg.mutable_init_client()->set_height(height); | 45 msg.mutable_init_client()->set_height(height); |
| 46 DCHECK(msg.IsInitialized()); | 46 DCHECK(msg.IsInitialized()); |
| 47 channel_->Write(SerializeAndFrameMessage(msg)); | 47 channel_->Write(SerializeAndFrameMessage(msg)); |
| 48 } | 48 } |
| 49 | 49 |
| 50 void ClientConnection::SendBeginUpdateStreamMessage() { | 50 void ClientConnection::SendBeginUpdateStreamMessage() { |
| 51 DCHECK_EQ(loop_, MessageLoop::current()); | 51 DCHECK_EQ(loop_, MessageLoop::current()); |
| 52 DCHECK(channel_.get()); | 52 DCHECK(channel_.get()); |
| 53 | 53 |
| 54 chromotocol_pb::HostMessage msg; | 54 HostMessage msg; |
| 55 msg.mutable_begin_update_stream(); | 55 msg.mutable_begin_update_stream(); |
| 56 DCHECK(msg.IsInitialized()); | 56 DCHECK(msg.IsInitialized()); |
| 57 | 57 |
| 58 scoped_refptr<DataBuffer> data = SerializeAndFrameMessage(msg); | 58 scoped_refptr<DataBuffer> data = SerializeAndFrameMessage(msg); |
| 59 DCHECK(!update_stream_size_); | 59 DCHECK(!update_stream_size_); |
| 60 update_stream_size_ += data->GetDataSize(); | 60 update_stream_size_ += data->GetDataSize(); |
| 61 channel_->Write(data); | 61 channel_->Write(data); |
| 62 } | 62 } |
| 63 | 63 |
| 64 void ClientConnection::SendUpdateStreamPacketMessage( | 64 void ClientConnection::SendUpdateStreamPacketMessage( |
| 65 chromotocol_pb::UpdateStreamPacketHeader* header, | 65 UpdateStreamPacketHeader* header, |
| 66 scoped_refptr<DataBuffer> data) { | 66 scoped_refptr<DataBuffer> data) { |
| 67 DCHECK_EQ(loop_, MessageLoop::current()); | 67 DCHECK_EQ(loop_, MessageLoop::current()); |
| 68 DCHECK(channel_.get()); | 68 DCHECK(channel_.get()); |
| 69 | 69 |
| 70 chromotocol_pb::HostMessage msg; | 70 HostMessage msg; |
| 71 msg.mutable_update_stream_packet()->mutable_header()->CopyFrom(*header); | 71 msg.mutable_update_stream_packet()->mutable_header()->CopyFrom(*header); |
| 72 // TODO(hclam): This introduce one memory copy. Eliminate it. | 72 // TODO(hclam): This introduce one memory copy. Eliminate it. |
| 73 msg.mutable_update_stream_packet()->set_data( | 73 msg.mutable_update_stream_packet()->set_data( |
| 74 data->GetData(), data->GetDataSize()); | 74 data->GetData(), data->GetDataSize()); |
| 75 DCHECK(msg.IsInitialized()); | 75 DCHECK(msg.IsInitialized()); |
| 76 | 76 |
| 77 scoped_refptr<DataBuffer> encoded_data = SerializeAndFrameMessage(msg); | 77 scoped_refptr<DataBuffer> encoded_data = SerializeAndFrameMessage(msg); |
| 78 update_stream_size_ += data->GetDataSize(); | 78 update_stream_size_ += data->GetDataSize(); |
| 79 channel_->Write(encoded_data); | 79 channel_->Write(encoded_data); |
| 80 } | 80 } |
| 81 | 81 |
| 82 void ClientConnection::SendEndUpdateStreamMessage() { | 82 void ClientConnection::SendEndUpdateStreamMessage() { |
| 83 DCHECK_EQ(loop_, MessageLoop::current()); | 83 DCHECK_EQ(loop_, MessageLoop::current()); |
| 84 DCHECK(channel_.get()); | 84 DCHECK(channel_.get()); |
| 85 | 85 |
| 86 chromotocol_pb::HostMessage msg; | 86 HostMessage msg; |
| 87 msg.mutable_end_update_stream(); | 87 msg.mutable_end_update_stream(); |
| 88 DCHECK(msg.IsInitialized()); | 88 DCHECK(msg.IsInitialized()); |
| 89 | 89 |
| 90 scoped_refptr<DataBuffer> data = SerializeAndFrameMessage(msg); | 90 scoped_refptr<DataBuffer> data = SerializeAndFrameMessage(msg); |
| 91 update_stream_size_ += data->GetDataSize(); | 91 update_stream_size_ += data->GetDataSize(); |
| 92 channel_->Write(data); | 92 channel_->Write(data); |
| 93 | 93 |
| 94 // Here's some logic to help finding the average update stream size. | 94 // Here's some logic to help finding the average update stream size. |
| 95 size_in_queue_ += update_stream_size_; | 95 size_in_queue_ += update_stream_size_; |
| 96 size_queue_.push_back(update_stream_size_); | 96 size_queue_.push_back(update_stream_size_); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 DCHECK(decoder_.get()); | 164 DCHECK(decoder_.get()); |
| 165 ClientMessageList list; | 165 ClientMessageList list; |
| 166 decoder_->ParseClientMessages(data, &list); | 166 decoder_->ParseClientMessages(data, &list); |
| 167 | 167 |
| 168 // Then submit the messages to the handler. | 168 // Then submit the messages to the handler. |
| 169 DCHECK(handler_); | 169 DCHECK(handler_); |
| 170 handler_->HandleMessages(this, &list); | 170 handler_->HandleMessages(this, &list); |
| 171 } | 171 } |
| 172 | 172 |
| 173 } // namespace remoting | 173 } // namespace remoting |
| OLD | NEW |