| 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_SCREEN_RECORDER_H_ | 5 #ifndef REMOTING_HOST_SCREEN_RECORDER_H_ |
| 6 #define REMOTING_HOST_SCREEN_RECORDER_H_ | 6 #define REMOTING_HOST_SCREEN_RECORDER_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 MessageLoop* encode_loop, | 69 MessageLoop* encode_loop, |
| 70 MessageLoop* network_loop, | 70 MessageLoop* network_loop, |
| 71 Capturer* capturer, | 71 Capturer* capturer, |
| 72 Encoder* encoder); | 72 Encoder* encoder); |
| 73 | 73 |
| 74 virtual ~ScreenRecorder(); | 74 virtual ~ScreenRecorder(); |
| 75 | 75 |
| 76 // Start recording. | 76 // Start recording. |
| 77 void Start(); | 77 void Start(); |
| 78 | 78 |
| 79 // Pause the recording session. | 79 // Stop the recording session. |done_task| is executed when recording is fully |
| 80 void Pause(); | 80 // stopped. This object cannot be used again after |task| is executed. |
| 81 void Stop(Task* done_task); |
| 81 | 82 |
| 82 // Set the maximum capture rate. This is denoted by number of updates | 83 // Set the maximum capture rate. This is denoted by number of updates |
| 83 // in one second. The actual system may run in a slower rate than the maximum | 84 // in one second. The actual system may run in a slower rate than the maximum |
| 84 // rate due to various factors, e.g. capture speed, encode speed and network | 85 // rate due to various factors, e.g. capture speed, encode speed and network |
| 85 // conditions. | 86 // conditions. |
| 86 // This method should be called before Start() is called. | 87 // This method should be called before Start() is called. |
| 87 void SetMaxRate(double rate); | 88 void SetMaxRate(double rate); |
| 88 | 89 |
| 89 // Add a connection to this recording session. | 90 // Add a connection to this recording session. |
| 90 void AddConnection(scoped_refptr<protocol::ConnectionToClient> connection); | 91 void AddConnection(scoped_refptr<protocol::ConnectionToClient> connection); |
| 91 | 92 |
| 92 // Remove a connection from receiving screen updates. | 93 // Remove a connection from receiving screen updates. |
| 93 void RemoveConnection(scoped_refptr<protocol::ConnectionToClient> connection); | 94 void RemoveConnection(scoped_refptr<protocol::ConnectionToClient> connection); |
| 94 | 95 |
| 95 // Remove all connections. | 96 // Remove all connections. |
| 96 void RemoveAllConnections(); | 97 void RemoveAllConnections(); |
| 97 | 98 |
| 98 private: | 99 private: |
| 99 // Getters for capturer and encoder. | 100 // Getters for capturer and encoder. |
| 100 Capturer* capturer(); | 101 Capturer* capturer(); |
| 101 Encoder* encoder(); | 102 Encoder* encoder(); |
| 102 | 103 |
| 103 // Capturer thread ---------------------------------------------------------- | 104 // Capturer thread ---------------------------------------------------------- |
| 104 | 105 |
| 105 void DoStart(); | 106 void DoStart(); |
| 106 void DoPause(); | 107 void DoStop(Task* done_task); |
| 108 void DoCompleteStop(Task* done_task); |
| 107 | 109 |
| 108 void DoSetMaxRate(double max_rate); | 110 void DoSetMaxRate(double max_rate); |
| 109 | 111 |
| 110 // Hepler method to schedule next capture using the current rate. | 112 // Hepler method to schedule next capture using the current rate. |
| 111 void StartCaptureTimer(); | 113 void StartCaptureTimer(); |
| 112 | 114 |
| 113 void DoCapture(); | 115 void DoCapture(); |
| 114 void CaptureDoneCallback(scoped_refptr<CaptureData> capture_data); | 116 void CaptureDoneCallback(scoped_refptr<CaptureData> capture_data); |
| 115 void DoFinishSend(); | 117 void DoFinishOneRecording(); |
| 116 | 118 |
| 117 // Network thread ----------------------------------------------------------- | 119 // Network thread ----------------------------------------------------------- |
| 118 | 120 |
| 119 // DoSendVideoPacket takes ownership of the |packet| and is responsible | 121 // DoSendVideoPacket takes ownership of the |packet| and is responsible |
| 120 // for deleting it. | 122 // for deleting it. |
| 121 void DoSendVideoPacket(VideoPacket* packet); | 123 void DoSendVideoPacket(VideoPacket* packet); |
| 122 | 124 |
| 123 void DoSendInit(scoped_refptr<protocol::ConnectionToClient> connection, | 125 void DoSendInit(scoped_refptr<protocol::ConnectionToClient> connection, |
| 124 int width, int height); | 126 int width, int height); |
| 125 | 127 |
| 126 void DoAddConnection(scoped_refptr<protocol::ConnectionToClient> connection); | 128 void DoAddConnection(scoped_refptr<protocol::ConnectionToClient> connection); |
| 127 void DoRemoveClient(scoped_refptr<protocol::ConnectionToClient> connection); | 129 void DoRemoveClient(scoped_refptr<protocol::ConnectionToClient> connection); |
| 128 void DoRemoveAllClients(); | 130 void DoRemoveAllClients(); |
| 129 | 131 |
| 132 // Signal network thread to cease activities. |
| 133 void DoStopOnNetworkThread(Task* done_task); |
| 134 |
| 130 // Callback for the last packet in one update. Deletes |packet| and | 135 // Callback for the last packet in one update. Deletes |packet| and |
| 131 // schedules next screen capture. | 136 // schedules next screen capture. |
| 132 void OnFrameSent(VideoPacket* packet); | 137 void FrameSentCallback(VideoPacket* packet); |
| 133 | 138 |
| 134 // Encoder thread ----------------------------------------------------------- | 139 // Encoder thread ----------------------------------------------------------- |
| 135 | 140 |
| 136 void DoEncode(scoped_refptr<CaptureData> capture_data); | 141 void DoEncode(scoped_refptr<CaptureData> capture_data); |
| 137 | 142 |
| 138 // EncodeDataAvailableTask takes ownership of |packet|. | 143 // Perform stop operations on encode thread. |
| 139 void EncodeDataAvailableTask(VideoPacket* packet); | 144 void DoStopOnEncodeThread(Task* done_task); |
| 145 |
| 146 // EncodedDataAvailableCallback takes ownership of |packet|. |
| 147 void EncodedDataAvailableCallback(VideoPacket* packet); |
| 140 void SendVideoPacket(VideoPacket* packet); | 148 void SendVideoPacket(VideoPacket* packet); |
| 141 | 149 |
| 142 // Message loops used by this class. | 150 // Message loops used by this class. |
| 143 MessageLoop* capture_loop_; | 151 MessageLoop* capture_loop_; |
| 144 MessageLoop* encode_loop_; | 152 MessageLoop* encode_loop_; |
| 145 MessageLoop* network_loop_; | 153 MessageLoop* network_loop_; |
| 146 | 154 |
| 147 // Reference to the capturer. This member is always accessed on the capture | 155 // Reference to the capturer. This member is always accessed on the capture |
| 148 // thread. | 156 // thread. |
| 149 scoped_ptr<Capturer> capturer_; | 157 scoped_ptr<Capturer> capturer_; |
| 150 | 158 |
| 151 // Reference to the encoder. This member is always accessed on the encode | 159 // Reference to the encoder. This member is always accessed on the encode |
| 152 // thread. | 160 // thread. |
| 153 scoped_ptr<Encoder> encoder_; | 161 scoped_ptr<Encoder> encoder_; |
| 154 | 162 |
| 155 // A list of clients connected to this hosts. | 163 // A list of clients connected to this hosts. |
| 156 // This member is always accessed on the NETWORK thread. | 164 // This member is always accessed on the NETWORK thread. |
| 157 // TODO(hclam): Have to scoped_refptr the clients since they have a shorter | 165 // TODO(hclam): Have to scoped_refptr the clients since they have a shorter |
| 158 // lifetime than this object. | 166 // lifetime than this object. |
| 159 typedef std::vector<scoped_refptr<protocol::ConnectionToClient> > | 167 typedef std::vector<scoped_refptr<protocol::ConnectionToClient> > |
| 160 ConnectionToClientList; | 168 ConnectionToClientList; |
| 161 ConnectionToClientList connections_; | 169 ConnectionToClientList connections_; |
| 162 | 170 |
| 163 // The following members are accessed on the capture thread. | 171 // Flag that indicates recording has been started. |
| 164 bool started_; | 172 bool started_; |
| 165 | 173 |
| 174 // Flag that indicates network is being stopped. |
| 175 bool network_stopped_; |
| 176 |
| 166 // Timer that calls DoCapture. | 177 // Timer that calls DoCapture. |
| 167 base::RepeatingTimer<ScreenRecorder> capture_timer_; | 178 base::RepeatingTimer<ScreenRecorder> capture_timer_; |
| 168 | 179 |
| 169 // Count the number of recordings (i.e. capture or encode) happening. | 180 // Count the number of recordings (i.e. capture or encode) happening. |
| 170 int recordings_; | 181 int recordings_; |
| 171 | 182 |
| 172 // Set to true if we've skipped last capture because there are too | 183 // Set to true if we've skipped last capture because there are too |
| 173 // many pending frames. | 184 // many pending frames. |
| 174 int frame_skipped_; | 185 int frame_skipped_; |
| 175 | 186 |
| 176 // Number of captures to perform every second. Written on the capture thread. | 187 // Number of captures to perform every second. Written on the capture thread. |
| 177 double max_rate_; | 188 double max_rate_; |
| 178 | 189 |
| 179 DISALLOW_COPY_AND_ASSIGN(ScreenRecorder); | 190 DISALLOW_COPY_AND_ASSIGN(ScreenRecorder); |
| 180 }; | 191 }; |
| 181 | 192 |
| 182 } // namespace remoting | 193 } // namespace remoting |
| 183 | 194 |
| 184 #endif // REMOTING_HOST_SCREEN_RECORDER_H_ | 195 #endif // REMOTING_HOST_SCREEN_RECORDER_H_ |
| OLD | NEW |