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/client/chromoting_client.h" | 5 #include "remoting/client/chromoting_client.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "remoting/client/audio_player.h" | 8 #include "remoting/client/audio_decode_scheduler.h" |
9 #include "remoting/client/client_context.h" | 9 #include "remoting/client/client_context.h" |
10 #include "remoting/client/client_user_interface.h" | 10 #include "remoting/client/client_user_interface.h" |
11 #include "remoting/client/rectangle_update_decoder.h" | 11 #include "remoting/client/rectangle_update_decoder.h" |
12 #include "remoting/proto/audio.pb.h" | 12 #include "remoting/proto/audio.pb.h" |
13 #include "remoting/proto/video.pb.h" | 13 #include "remoting/proto/video.pb.h" |
14 #include "remoting/protocol/authentication_method.h" | 14 #include "remoting/protocol/authentication_method.h" |
15 #include "remoting/protocol/connection_to_host.h" | 15 #include "remoting/protocol/connection_to_host.h" |
16 #include "remoting/protocol/negotiating_authenticator.h" | 16 #include "remoting/protocol/negotiating_authenticator.h" |
17 #include "remoting/protocol/session_config.h" | 17 #include "remoting/protocol/session_config.h" |
18 #include "remoting/protocol/transport.h" | 18 #include "remoting/protocol/transport.h" |
19 | 19 |
20 namespace remoting { | 20 namespace remoting { |
21 | 21 |
22 using protocol::AuthenticationMethod; | 22 using protocol::AuthenticationMethod; |
23 | 23 |
24 ChromotingClient::QueuedVideoPacket::QueuedVideoPacket( | 24 ChromotingClient::QueuedVideoPacket::QueuedVideoPacket( |
25 scoped_ptr<VideoPacket> packet, const base::Closure& done) | 25 scoped_ptr<VideoPacket> packet, const base::Closure& done) |
26 : packet(packet.release()), done(done) { | 26 : packet(packet.release()), done(done) { |
27 } | 27 } |
28 | 28 |
29 ChromotingClient::QueuedVideoPacket::~QueuedVideoPacket() { | 29 ChromotingClient::QueuedVideoPacket::~QueuedVideoPacket() { |
30 } | 30 } |
31 | 31 |
32 ChromotingClient::ChromotingClient( | 32 ChromotingClient::ChromotingClient( |
33 const ClientConfig& config, | 33 const ClientConfig& config, |
34 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 34 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
35 protocol::ConnectionToHost* connection, | 35 protocol::ConnectionToHost* connection, |
36 ClientUserInterface* user_interface, | 36 ClientUserInterface* user_interface, |
37 RectangleUpdateDecoder* rectangle_decoder, | 37 RectangleUpdateDecoder* rectangle_decoder, |
38 AudioPlayer* audio_player) | 38 AudioDecodeScheduler* audio_decode_scheduler) |
39 : config_(config), | 39 : config_(config), |
40 task_runner_(task_runner), | 40 task_runner_(task_runner), |
41 connection_(connection), | 41 connection_(connection), |
42 user_interface_(user_interface), | 42 user_interface_(user_interface), |
43 rectangle_decoder_(rectangle_decoder), | 43 rectangle_decoder_(rectangle_decoder), |
44 audio_player_(audio_player), | 44 audio_decode_scheduler_(audio_decode_scheduler), |
45 packet_being_processed_(false), | 45 packet_being_processed_(false), |
46 last_sequence_number_(0), | 46 last_sequence_number_(0), |
47 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 47 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
48 } | 48 } |
49 | 49 |
50 ChromotingClient::~ChromotingClient() { | 50 ChromotingClient::~ChromotingClient() { |
51 } | 51 } |
52 | 52 |
53 void ChromotingClient::Start( | 53 void ChromotingClient::Start( |
54 scoped_refptr<XmppProxy> xmpp_proxy, | 54 scoped_refptr<XmppProxy> xmpp_proxy, |
55 scoped_ptr<protocol::TransportFactory> transport_factory) { | 55 scoped_ptr<protocol::TransportFactory> transport_factory) { |
56 DCHECK(task_runner_->BelongsToCurrentThread()); | 56 DCHECK(task_runner_->BelongsToCurrentThread()); |
57 | 57 |
58 scoped_ptr<protocol::Authenticator> authenticator( | 58 scoped_ptr<protocol::Authenticator> authenticator( |
59 protocol::NegotiatingAuthenticator::CreateForClient( | 59 protocol::NegotiatingAuthenticator::CreateForClient( |
60 config_.authentication_tag, | 60 config_.authentication_tag, |
61 config_.shared_secret, config_.authentication_methods)); | 61 config_.shared_secret, config_.authentication_methods)); |
62 | 62 |
63 // Create a WeakPtr to ourself for to use for all posted tasks. | 63 // Create a WeakPtr to ourself for to use for all posted tasks. |
64 weak_ptr_ = weak_factory_.GetWeakPtr(); | 64 weak_ptr_ = weak_factory_.GetWeakPtr(); |
65 | 65 |
66 connection_->Connect(xmpp_proxy, config_.local_jid, config_.host_jid, | 66 connection_->Connect(xmpp_proxy, config_.local_jid, config_.host_jid, |
67 config_.host_public_key, transport_factory.Pass(), | 67 config_.host_public_key, transport_factory.Pass(), |
68 authenticator.Pass(), this, this, this, this, this); | 68 authenticator.Pass(), this, this, this, this, |
| 69 audio_decode_scheduler_); |
69 } | 70 } |
70 | 71 |
71 void ChromotingClient::Stop(const base::Closure& shutdown_task) { | 72 void ChromotingClient::Stop(const base::Closure& shutdown_task) { |
72 DCHECK(task_runner_->BelongsToCurrentThread()); | 73 DCHECK(task_runner_->BelongsToCurrentThread()); |
73 | 74 |
74 // Drop all pending packets. | 75 // Drop all pending packets. |
75 while(!received_packets_.empty()) { | 76 while(!received_packets_.empty()) { |
76 delete received_packets_.front().packet; | 77 delete received_packets_.front().packet; |
77 received_packets_.front().done.Run(); | 78 received_packets_.front().done.Run(); |
78 received_packets_.pop_front(); | 79 received_packets_.pop_front(); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 received_packets_.push_back(QueuedVideoPacket(packet.Pass(), done)); | 135 received_packets_.push_back(QueuedVideoPacket(packet.Pass(), done)); |
135 if (!packet_being_processed_) | 136 if (!packet_being_processed_) |
136 DispatchPacket(); | 137 DispatchPacket(); |
137 } | 138 } |
138 | 139 |
139 int ChromotingClient::GetPendingVideoPackets() { | 140 int ChromotingClient::GetPendingVideoPackets() { |
140 DCHECK(task_runner_->BelongsToCurrentThread()); | 141 DCHECK(task_runner_->BelongsToCurrentThread()); |
141 return received_packets_.size(); | 142 return received_packets_.size(); |
142 } | 143 } |
143 | 144 |
144 void ChromotingClient::ProcessAudioPacket(scoped_ptr<AudioPacket> packet, | |
145 const base::Closure& done) { | |
146 audio_player_->ProcessAudioPacket(packet.Pass()); | |
147 done.Run(); | |
148 } | |
149 | |
150 void ChromotingClient::DispatchPacket() { | 145 void ChromotingClient::DispatchPacket() { |
151 DCHECK(task_runner_->BelongsToCurrentThread()); | 146 DCHECK(task_runner_->BelongsToCurrentThread()); |
152 CHECK(!packet_being_processed_); | 147 CHECK(!packet_being_processed_); |
153 | 148 |
154 if (received_packets_.empty()) { | 149 if (received_packets_.empty()) { |
155 // Nothing to do! | 150 // Nothing to do! |
156 return; | 151 return; |
157 } | 152 } |
158 | 153 |
159 scoped_ptr<VideoPacket> packet(received_packets_.front().packet); | 154 scoped_ptr<VideoPacket> packet(received_packets_.front().packet); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 | 205 |
211 // Process the next video packet. | 206 // Process the next video packet. |
212 DispatchPacket(); | 207 DispatchPacket(); |
213 } | 208 } |
214 | 209 |
215 void ChromotingClient::Initialize() { | 210 void ChromotingClient::Initialize() { |
216 DCHECK(task_runner_->BelongsToCurrentThread()); | 211 DCHECK(task_runner_->BelongsToCurrentThread()); |
217 | 212 |
218 // Initialize the decoder. | 213 // Initialize the decoder. |
219 rectangle_decoder_->Initialize(connection_->config()); | 214 rectangle_decoder_->Initialize(connection_->config()); |
| 215 if (connection_->config().is_audio_enabled()) { |
| 216 audio_decode_scheduler_->Initialize(connection_->config()); |
| 217 } |
220 } | 218 } |
221 | 219 |
222 } // namespace remoting | 220 } // namespace remoting |
OLD | NEW |