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 // ChromotingClient is the controller for the Client implementation. | 5 // ChromotingClient is the controller for the Client implementation. |
6 | 6 |
7 #ifndef REMOTING_CLIENT_CHROMOTING_CLIENT_H_ | 7 #ifndef REMOTING_CLIENT_CHROMOTING_CLIENT_H_ |
8 #define REMOTING_CLIENT_CHROMOTING_CLIENT_H_ | 8 #define REMOTING_CLIENT_CHROMOTING_CLIENT_H_ |
9 | 9 |
10 #include <list> | 10 #include <list> |
11 | 11 |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "base/time.h" | 15 #include "base/time.h" |
16 #include "remoting/client/client_config.h" | 16 #include "remoting/client/client_config.h" |
17 #include "remoting/client/chromoting_stats.h" | 17 #include "remoting/client/chromoting_stats.h" |
18 #include "remoting/protocol/audio_stub.h" | |
19 #include "remoting/protocol/client_stub.h" | 18 #include "remoting/protocol/client_stub.h" |
20 #include "remoting/protocol/clipboard_stub.h" | 19 #include "remoting/protocol/clipboard_stub.h" |
21 #include "remoting/protocol/connection_to_host.h" | 20 #include "remoting/protocol/connection_to_host.h" |
22 #include "remoting/protocol/input_stub.h" | 21 #include "remoting/protocol/input_stub.h" |
23 #include "remoting/protocol/video_stub.h" | 22 #include "remoting/protocol/video_stub.h" |
24 #include "remoting/jingle_glue/xmpp_proxy.h" | 23 #include "remoting/jingle_glue/xmpp_proxy.h" |
25 | 24 |
26 namespace base { | 25 namespace base { |
27 class SingleThreadTaskRunner; | 26 class SingleThreadTaskRunner; |
28 } // namespace base | 27 } // namespace base |
29 | 28 |
30 namespace remoting { | 29 namespace remoting { |
31 | 30 |
32 namespace protocol { | 31 namespace protocol { |
33 class TransportFactory; | 32 class TransportFactory; |
34 } // namespace protocol | 33 } // namespace protocol |
35 | 34 |
36 class AudioPlayer; | 35 class AudioDecodeScheduler; |
37 class ClientUserInterface; | 36 class ClientUserInterface; |
38 class RectangleUpdateDecoder; | 37 class RectangleUpdateDecoder; |
39 | 38 |
40 // TODO(sergeyu): Move VideoStub implementation to RectangleUpdateDecoder. | 39 // TODO(sergeyu): Move VideoStub implementation to RectangleUpdateDecoder. |
41 class ChromotingClient : public protocol::ConnectionToHost::HostEventCallback, | 40 class ChromotingClient : public protocol::ConnectionToHost::HostEventCallback, |
42 public protocol::ClientStub, | 41 public protocol::ClientStub, |
43 public protocol::VideoStub, | 42 public protocol::VideoStub { |
44 public protocol::AudioStub { | |
45 public: | 43 public: |
46 // Objects passed in are not owned by this class. | 44 // Objects passed in are not owned by this class. |
47 ChromotingClient(const ClientConfig& config, | 45 ChromotingClient(const ClientConfig& config, |
48 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 46 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
49 protocol::ConnectionToHost* connection, | 47 protocol::ConnectionToHost* connection, |
50 ClientUserInterface* user_interface, | 48 ClientUserInterface* user_interface, |
51 RectangleUpdateDecoder* rectangle_decoder, | 49 RectangleUpdateDecoder* rectangle_decoder, |
52 AudioPlayer* audio_player); | 50 AudioDecodeScheduler* audio_decode_scheduler); |
53 | 51 |
54 virtual ~ChromotingClient(); | 52 virtual ~ChromotingClient(); |
55 | 53 |
56 // Start/stop the client. Must be called on the main thread. | 54 // Start/stop the client. Must be called on the main thread. |
57 void Start(scoped_refptr<XmppProxy> xmpp_proxy, | 55 void Start(scoped_refptr<XmppProxy> xmpp_proxy, |
58 scoped_ptr<protocol::TransportFactory> transport_factory); | 56 scoped_ptr<protocol::TransportFactory> transport_factory); |
59 void Stop(const base::Closure& shutdown_task); | 57 void Stop(const base::Closure& shutdown_task); |
60 | 58 |
61 // Return the stats recorded by this client. | 59 // Return the stats recorded by this client. |
62 ChromotingStats* GetStats(); | 60 ChromotingStats* GetStats(); |
(...skipping 10 matching lines...) Expand all Loading... | |
73 virtual void OnConnectionState( | 71 virtual void OnConnectionState( |
74 protocol::ConnectionToHost::State state, | 72 protocol::ConnectionToHost::State state, |
75 protocol::ErrorCode error) OVERRIDE; | 73 protocol::ErrorCode error) OVERRIDE; |
76 virtual void OnConnectionReady(bool ready) OVERRIDE; | 74 virtual void OnConnectionReady(bool ready) OVERRIDE; |
77 | 75 |
78 // VideoStub implementation. | 76 // VideoStub implementation. |
79 virtual void ProcessVideoPacket(scoped_ptr<VideoPacket> packet, | 77 virtual void ProcessVideoPacket(scoped_ptr<VideoPacket> packet, |
80 const base::Closure& done) OVERRIDE; | 78 const base::Closure& done) OVERRIDE; |
81 virtual int GetPendingVideoPackets() OVERRIDE; | 79 virtual int GetPendingVideoPackets() OVERRIDE; |
82 | 80 |
83 // AudioStub implementation. | |
84 virtual void ProcessAudioPacket(scoped_ptr<AudioPacket> packet, | |
85 const base::Closure& done) OVERRIDE; | |
86 | |
87 private: | 81 private: |
88 struct QueuedVideoPacket { | 82 struct QueuedVideoPacket { |
89 QueuedVideoPacket(scoped_ptr<VideoPacket> packet, | 83 QueuedVideoPacket(scoped_ptr<VideoPacket> packet, |
90 const base::Closure& done); | 84 const base::Closure& done); |
91 ~QueuedVideoPacket(); | 85 ~QueuedVideoPacket(); |
92 VideoPacket* packet; | 86 VideoPacket* packet; |
93 base::Closure done; | 87 base::Closure done; |
94 }; | 88 }; |
95 | 89 |
96 // Initializes connection. | 90 // Initializes connection. |
97 void Initialize(); | 91 void Initialize(); |
98 | 92 |
99 // If a packet is not being processed, dispatches a single message from the | 93 // If a packet is not being processed, dispatches a single message from the |
100 // |received_packets_| queue. | 94 // |received_packets_| queue. |
101 void DispatchPacket(); | 95 void DispatchPacket(); |
102 | 96 |
103 // Callback method when a VideoPacket is processed. | 97 // Callback method when a VideoPacket is processed. |
104 // If |last_packet| is true then |decode_start| contains the timestamp when | 98 // If |last_packet| is true then |decode_start| contains the timestamp when |
105 // the packet will start to be processed. | 99 // the packet will start to be processed. |
106 void OnPacketDone(bool last_packet, base::Time decode_start); | 100 void OnPacketDone(bool last_packet, base::Time decode_start); |
107 | 101 |
108 void OnDisconnected(const base::Closure& shutdown_task); | 102 void OnDisconnected(const base::Closure& shutdown_task); |
109 | 103 |
110 // The following are not owned by this class. | 104 // The following are not owned by this class. |
111 ClientConfig config_; | 105 ClientConfig config_; |
112 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 106 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
113 protocol::ConnectionToHost* connection_; | 107 protocol::ConnectionToHost* connection_; |
114 ClientUserInterface* user_interface_; | 108 ClientUserInterface* user_interface_; |
115 RectangleUpdateDecoder* rectangle_decoder_; | 109 RectangleUpdateDecoder* rectangle_decoder_; |
116 AudioPlayer* audio_player_; | 110 AudioDecodeScheduler* audio_decode_scheduler_; |
Sergey Ulanov
2012/08/02 20:32:48
Can we own it here?
kxing
2012/08/03 14:51:47
Done.
| |
117 | 111 |
118 // If non-NULL, this is called when the client is done. | 112 // If non-NULL, this is called when the client is done. |
119 base::Closure client_done_; | 113 base::Closure client_done_; |
120 | 114 |
121 // Contains all video packets that have been received, but have not yet been | 115 // Contains all video packets that have been received, but have not yet been |
122 // processed. | 116 // processed. |
123 // | 117 // |
124 // Used to serialize sending of messages to the client. | 118 // Used to serialize sending of messages to the client. |
125 std::list<QueuedVideoPacket> received_packets_; | 119 std::list<QueuedVideoPacket> received_packets_; |
126 | 120 |
(...skipping 10 matching lines...) Expand all Loading... | |
137 // WeakPtr used to avoid tasks accessing the client after it is deleted. | 131 // WeakPtr used to avoid tasks accessing the client after it is deleted. |
138 base::WeakPtrFactory<ChromotingClient> weak_factory_; | 132 base::WeakPtrFactory<ChromotingClient> weak_factory_; |
139 base::WeakPtr<ChromotingClient> weak_ptr_; | 133 base::WeakPtr<ChromotingClient> weak_ptr_; |
140 | 134 |
141 DISALLOW_COPY_AND_ASSIGN(ChromotingClient); | 135 DISALLOW_COPY_AND_ASSIGN(ChromotingClient); |
142 }; | 136 }; |
143 | 137 |
144 } // namespace remoting | 138 } // namespace remoting |
145 | 139 |
146 #endif // REMOTING_CLIENT_CHROMOTING_CLIENT_H_ | 140 #endif // REMOTING_CLIENT_CHROMOTING_CLIENT_H_ |
OLD | NEW |