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