| 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 #ifndef REMOTING_HOST_RECORD_SESSION_H_ | 5 #ifndef REMOTING_HOST_RECORD_SESSION_H_ |
| 6 #define REMOTING_HOST_RECORD_SESSION_H_ | 6 #define REMOTING_HOST_RECORD_SESSION_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 // v | 60 // v |
| 61 // | 61 // |
| 62 // SessionManager has the following responsibilities: | 62 // SessionManager has the following responsibilities: |
| 63 // 1. Make sure capture and encode occurs no more frequently than |rate|. | 63 // 1. Make sure capture and encode occurs no more frequently than |rate|. |
| 64 // 2. Make sure there is at most one outstanding capture not being encoded. | 64 // 2. Make sure there is at most one outstanding capture not being encoded. |
| 65 // 3. Distribute tasks on three threads on a timely fashion to minimize latency. | 65 // 3. Distribute tasks on three threads on a timely fashion to minimize latency. |
| 66 class SessionManager : public base::RefCountedThreadSafe<SessionManager> { | 66 class SessionManager : public base::RefCountedThreadSafe<SessionManager> { |
| 67 public: | 67 public: |
| 68 | 68 |
| 69 // Construct a SessionManager. Message loops and threads are provided. | 69 // Construct a SessionManager. Message loops and threads are provided. |
| 70 // Ownership of Capturer and Encoder are given to this object. | 70 // This object does not own capturer and encoder. |
| 71 SessionManager(MessageLoop* capture_loop, | 71 SessionManager(MessageLoop* capture_loop, |
| 72 MessageLoop* encode_loop, | 72 MessageLoop* encode_loop, |
| 73 MessageLoop* network_loop, | 73 MessageLoop* network_loop, |
| 74 Capturer* capturer, | 74 Capturer* capturer, |
| 75 Encoder* encoder); | 75 Encoder* encoder); |
| 76 | 76 |
| 77 virtual ~SessionManager(); | 77 virtual ~SessionManager(); |
| 78 | 78 |
| 79 // Start recording. | 79 // Start recording. |
| 80 void Start(); | 80 void Start(); |
| 81 | 81 |
| 82 // Pause the recording session. | 82 // Pause the recording session. |
| 83 void Pause(); | 83 void Pause(); |
| 84 | 84 |
| 85 // Set the maximum capture rate. This is denoted by number of updates | 85 // Set the maximum capture rate. This is denoted by number of updates |
| 86 // in one second. The actual system may run in a slower rate than the maximum | 86 // in one second. The actual system may run in a slower rate than the maximum |
| 87 // rate due to various factors, e.g. capture speed, encode speed and network | 87 // rate due to various factors, e.g. capture speed, encode speed and network |
| 88 // conditions. | 88 // conditions. |
| 89 // This method should be called before Start() is called. | 89 // This method should be called before Start() is called. |
| 90 void SetMaxRate(double rate); | 90 void SetMaxRate(double rate); |
| 91 | 91 |
| 92 // Add a client to this recording session. | 92 // Add a client to this recording session. |
| 93 void AddClient(scoped_refptr<ClientConnection> client); | 93 void AddClient(scoped_refptr<ClientConnection> client); |
| 94 | 94 |
| 95 // Remove a client from receiving screen updates. | 95 // Remove a client from receiving screen updates. |
| 96 void RemoveClient(scoped_refptr<ClientConnection> client); | 96 void RemoveClient(scoped_refptr<ClientConnection> client); |
| 97 | 97 |
| 98 // Remove all clients. |
| 99 void RemoveAllClients(); |
| 100 |
| 98 private: | 101 private: |
| 99 | 102 |
| 100 // Stores the data and information of a capture to pass off to the | 103 // Stores the data and information of a capture to pass off to the |
| 101 // encoding thread. | 104 // encoding thread. |
| 102 struct CaptureData { | 105 struct CaptureData { |
| 103 DirtyRects dirty_rects_; | 106 DirtyRects dirty_rects_; |
| 104 const uint8* data_[3]; | 107 const uint8* data_[3]; |
| 105 int data_strides_[3]; | 108 int data_strides_[3]; |
| 106 int width_; | 109 int width_; |
| 107 int height_; | 110 int height_; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 123 void DoSendUpdate(const UpdateStreamPacketHeader* header, | 126 void DoSendUpdate(const UpdateStreamPacketHeader* header, |
| 124 const scoped_refptr<media::DataBuffer> data, | 127 const scoped_refptr<media::DataBuffer> data, |
| 125 Encoder::EncodingState state); | 128 Encoder::EncodingState state); |
| 126 void DoSendInit(scoped_refptr<ClientConnection> client, | 129 void DoSendInit(scoped_refptr<ClientConnection> client, |
| 127 int width, int height); | 130 int width, int height); |
| 128 void DoGetInitInfo(scoped_refptr<ClientConnection> client); | 131 void DoGetInitInfo(scoped_refptr<ClientConnection> client); |
| 129 void DoSetRate(double rate); | 132 void DoSetRate(double rate); |
| 130 void DoSetMaxRate(double max_rate); | 133 void DoSetMaxRate(double max_rate); |
| 131 void DoAddClient(scoped_refptr<ClientConnection> client); | 134 void DoAddClient(scoped_refptr<ClientConnection> client); |
| 132 void DoRemoveClient(scoped_refptr<ClientConnection> client); | 135 void DoRemoveClient(scoped_refptr<ClientConnection> client); |
| 136 void DoRemoveAllClients(); |
| 133 void DoRateControl(); | 137 void DoRateControl(); |
| 134 | 138 |
| 135 // Hepler method to schedule next capture using the current rate. | 139 // Hepler method to schedule next capture using the current rate. |
| 136 void ScheduleNextCapture(); | 140 void ScheduleNextCapture(); |
| 137 | 141 |
| 138 // Helper method to schedule next rate regulation task. | 142 // Helper method to schedule next rate regulation task. |
| 139 void ScheduleNextRateControl(); | 143 void ScheduleNextRateControl(); |
| 140 | 144 |
| 141 void CaptureDoneTask(); | 145 void CaptureDoneTask(); |
| 142 // EncodeDataAvailableTask takes ownership of header and is responsible for | 146 // EncodeDataAvailableTask takes ownership of header and is responsible for |
| 143 // deleting it. | 147 // deleting it. |
| 144 void EncodeDataAvailableTask(const UpdateStreamPacketHeader *header, | 148 void EncodeDataAvailableTask(const UpdateStreamPacketHeader *header, |
| 145 const scoped_refptr<media::DataBuffer>& data, | 149 const scoped_refptr<media::DataBuffer>& data, |
| 146 Encoder::EncodingState state); | 150 Encoder::EncodingState state); |
| 147 | 151 |
| 152 // Getters for capturer and encoder. |
| 153 Capturer* capturer(); |
| 154 Encoder* encoder(); |
| 155 |
| 148 // Message loops used by this class. | 156 // Message loops used by this class. |
| 149 MessageLoop* capture_loop_; | 157 MessageLoop* capture_loop_; |
| 150 MessageLoop* encode_loop_; | 158 MessageLoop* encode_loop_; |
| 151 MessageLoop* network_loop_; | 159 MessageLoop* network_loop_; |
| 152 | 160 |
| 153 // Reference to the capturer. This member is always accessed on the capture | 161 // Reference to the capturer. This member is always accessed on the capture |
| 154 // thread. | 162 // thread. |
| 155 scoped_ptr<Capturer> capturer_; | 163 scoped_ptr<Capturer> capturer_; |
| 156 | 164 |
| 157 // Reference to the encoder. This member is always accessed on the encode | 165 // Reference to the encoder. This member is always accessed on the encode |
| (...skipping 20 matching lines...) Expand all Loading... |
| 178 | 186 |
| 179 // The following member is accessed on the network thread. | 187 // The following member is accessed on the network thread. |
| 180 bool rate_control_started_; | 188 bool rate_control_started_; |
| 181 | 189 |
| 182 DISALLOW_COPY_AND_ASSIGN(SessionManager); | 190 DISALLOW_COPY_AND_ASSIGN(SessionManager); |
| 183 }; | 191 }; |
| 184 | 192 |
| 185 } // namespace remoting | 193 } // namespace remoting |
| 186 | 194 |
| 187 #endif // REMOTING_HOST_RECORD_SESSION_H_ | 195 #endif // REMOTING_HOST_RECORD_SESSION_H_ |
| OLD | NEW |