Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/protocol/connection_to_client.h" | 5 #include "remoting/protocol/connection_to_client.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
| 10 #include "google/protobuf/message.h" | 10 #include "google/protobuf/message.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 void ConnectionToClient::UpdateSequenceNumber(int64 sequence_number) { | 61 void ConnectionToClient::UpdateSequenceNumber(int64 sequence_number) { |
| 62 DCHECK(CalledOnValidThread()); | 62 DCHECK(CalledOnValidThread()); |
| 63 handler_->OnSequenceNumberUpdated(this, sequence_number); | 63 handler_->OnSequenceNumberUpdated(this, sequence_number); |
| 64 } | 64 } |
| 65 | 65 |
| 66 VideoStub* ConnectionToClient::video_stub() { | 66 VideoStub* ConnectionToClient::video_stub() { |
| 67 DCHECK(CalledOnValidThread()); | 67 DCHECK(CalledOnValidThread()); |
| 68 return video_writer_.get(); | 68 return video_writer_.get(); |
| 69 } | 69 } |
| 70 | 70 |
| 71 AudioStub* ConnectionToClient::audio_stub() { | |
| 72 DCHECK(CalledOnValidThread()); | |
| 73 return audio_writer_.get(); | |
| 74 } | |
| 75 | |
| 71 // Return pointer to ClientStub. | 76 // Return pointer to ClientStub. |
| 72 ClientStub* ConnectionToClient::client_stub() { | 77 ClientStub* ConnectionToClient::client_stub() { |
| 73 DCHECK(CalledOnValidThread()); | 78 DCHECK(CalledOnValidThread()); |
| 74 return control_dispatcher_.get(); | 79 return control_dispatcher_.get(); |
| 75 } | 80 } |
| 76 | 81 |
| 77 void ConnectionToClient::set_clipboard_stub( | 82 void ConnectionToClient::set_clipboard_stub( |
| 78 protocol::ClipboardStub* clipboard_stub) { | 83 protocol::ClipboardStub* clipboard_stub) { |
| 79 DCHECK(CalledOnValidThread()); | 84 DCHECK(CalledOnValidThread()); |
| 80 clipboard_stub_ = clipboard_stub; | 85 clipboard_stub_ = clipboard_stub; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 event_dispatcher_->Init(session_.get(), base::Bind( | 118 event_dispatcher_->Init(session_.get(), base::Bind( |
| 114 &ConnectionToClient::OnChannelInitialized, base::Unretained(this))); | 119 &ConnectionToClient::OnChannelInitialized, base::Unretained(this))); |
| 115 event_dispatcher_->set_input_stub(input_stub_); | 120 event_dispatcher_->set_input_stub(input_stub_); |
| 116 event_dispatcher_->set_sequence_number_callback(base::Bind( | 121 event_dispatcher_->set_sequence_number_callback(base::Bind( |
| 117 &ConnectionToClient::UpdateSequenceNumber, base::Unretained(this))); | 122 &ConnectionToClient::UpdateSequenceNumber, base::Unretained(this))); |
| 118 | 123 |
| 119 video_writer_ = VideoWriter::Create(session_->config()); | 124 video_writer_ = VideoWriter::Create(session_->config()); |
| 120 video_writer_->Init(session_.get(), base::Bind( | 125 video_writer_->Init(session_.get(), base::Bind( |
| 121 &ConnectionToClient::OnChannelInitialized, base::Unretained(this))); | 126 &ConnectionToClient::OnChannelInitialized, base::Unretained(this))); |
| 122 | 127 |
| 128 if (AudioEnabled()) { | |
| 129 audio_writer_ = AudioWriter::Create(session_->config()); | |
| 130 audio_writer_->Init(session_.get(), base::Bind( | |
| 131 &ConnectionToClient::OnChannelInitialized, base::Unretained(this))); | |
| 132 } | |
| 133 | |
| 123 // Notify the handler after initializing the channels, so that | 134 // Notify the handler after initializing the channels, so that |
| 124 // ClientSession can get a client clipboard stub. | 135 // ClientSession can get a client clipboard stub. |
| 125 handler_->OnConnectionAuthenticated(this); | 136 handler_->OnConnectionAuthenticated(this); |
| 126 break; | 137 break; |
| 127 | 138 |
| 128 case Session::CLOSED: | 139 case Session::CLOSED: |
| 129 Close(OK); | 140 Close(OK); |
| 130 break; | 141 break; |
| 131 | 142 |
| 132 case Session::FAILED: | 143 case Session::FAILED: |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 151 } | 162 } |
| 152 | 163 |
| 153 NotifyIfChannelsReady(); | 164 NotifyIfChannelsReady(); |
| 154 } | 165 } |
| 155 | 166 |
| 156 void ConnectionToClient::NotifyIfChannelsReady() { | 167 void ConnectionToClient::NotifyIfChannelsReady() { |
| 157 DCHECK(CalledOnValidThread()); | 168 DCHECK(CalledOnValidThread()); |
| 158 | 169 |
| 159 if (control_dispatcher_.get() && control_dispatcher_->is_connected() && | 170 if (control_dispatcher_.get() && control_dispatcher_->is_connected() && |
| 160 event_dispatcher_.get() && event_dispatcher_->is_connected() && | 171 event_dispatcher_.get() && event_dispatcher_->is_connected() && |
| 161 video_writer_.get() && video_writer_->is_connected()) { | 172 video_writer_.get() && video_writer_->is_connected() && |
| 173 (!AudioEnabled() || | |
| 174 (audio_writer_.get() && audio_writer_->is_connected()))) { | |
| 162 handler_->OnConnectionChannelsConnected(this); | 175 handler_->OnConnectionChannelsConnected(this); |
| 163 } | 176 } |
| 164 } | 177 } |
| 165 | 178 |
| 166 void ConnectionToClient::Close(ErrorCode error) { | 179 void ConnectionToClient::Close(ErrorCode error) { |
| 167 CloseChannels(); | 180 CloseChannels(); |
| 168 handler_->OnConnectionClosed(this, error); | 181 handler_->OnConnectionClosed(this, error); |
| 169 } | 182 } |
| 170 | 183 |
| 171 void ConnectionToClient::CloseChannels() { | 184 void ConnectionToClient::CloseChannels() { |
| 172 control_dispatcher_.reset(); | 185 control_dispatcher_.reset(); |
| 173 event_dispatcher_.reset(); | 186 event_dispatcher_.reset(); |
| 174 video_writer_.reset(); | 187 video_writer_.reset(); |
| 188 audio_writer_.reset(); | |
| 189 } | |
| 190 | |
| 191 bool ConnectionToClient::AudioEnabled() { | |
|
Sergey Ulanov
2012/06/21 18:36:04
Actually it's better to call it is_audio_enabled()
kxing
2012/06/21 18:53:28
Done.
| |
| 192 return (session_->config().audio_config().transport != | |
|
Sergey Ulanov
2012/06/21 18:36:04
nit: don't need parenthesis here.
kxing
2012/06/21 18:53:28
Done.
| |
| 193 ChannelConfig::TRANSPORT_NONE); | |
| 175 } | 194 } |
| 176 | 195 |
| 177 } // namespace protocol | 196 } // namespace protocol |
| 178 } // namespace remoting | 197 } // namespace remoting |
| OLD | NEW |