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 #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" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/time.h" | 14 #include "base/time.h" |
15 #include "base/timer.h" | 15 #include "base/timer.h" |
16 #include "remoting/base/encoder.h" | 16 #include "remoting/base/encoder.h" |
17 #include "remoting/host/capturer.h" | |
18 #include "remoting/host/capture_scheduler.h" | 17 #include "remoting/host/capture_scheduler.h" |
19 #include "remoting/proto/video.pb.h" | 18 #include "remoting/proto/video.pb.h" |
20 | 19 |
21 namespace base { | 20 namespace base { |
22 class SingleThreadTaskRunner; | 21 class SingleThreadTaskRunner; |
23 } // namespace base | 22 } // namespace base |
24 | 23 |
25 namespace remoting { | 24 namespace remoting { |
26 | 25 |
| 26 class CaptureData; |
| 27 class VideoFrameCapturer; |
| 28 |
27 namespace protocol { | 29 namespace protocol { |
28 class ConnectionToClient; | 30 class ConnectionToClient; |
29 class CursorShapeInfo; | 31 class CursorShapeInfo; |
30 } // namespace protocol | 32 } // namespace protocol |
31 | 33 |
32 class CaptureData; | 34 // A class for controlling and coordinate VideoFrameCapturer, Encoder |
33 | |
34 // A class for controlling and coordinate Capturer, Encoder | |
35 // and NetworkChannel in a record session. | 35 // and NetworkChannel in a record session. |
36 // | 36 // |
37 // THREADING | 37 // THREADING |
38 // | 38 // |
39 // This class works on three threads, namely capture, encode and network | 39 // This class works on three threads, namely capture, encode and network |
40 // thread. The main function of this class is to coordinate and schedule | 40 // thread. The main function of this class is to coordinate and schedule |
41 // capture, encode and transmission of data on different threads. | 41 // capture, encode and transmission of data on different threads. |
42 // | 42 // |
43 // The following is an example of timeline for operations scheduled. | 43 // The following is an example of timeline for operations scheduled. |
44 // | 44 // |
(...skipping 23 matching lines...) Expand all Loading... |
68 // 2. Make sure there is at most one outstanding capture not being encoded. | 68 // 2. Make sure there is at most one outstanding capture not being encoded. |
69 // 3. Distribute tasks on three threads on a timely fashion to minimize latency. | 69 // 3. Distribute tasks on three threads on a timely fashion to minimize latency. |
70 // | 70 // |
71 // This class has the following state variables: | 71 // This class has the following state variables: |
72 // |capture_timer_| - If this is set to NULL there should be no activity on | 72 // |capture_timer_| - If this is set to NULL there should be no activity on |
73 // the capture thread by this object. | 73 // the capture thread by this object. |
74 // |network_stopped_| - This state is to prevent activity on the network thread | 74 // |network_stopped_| - This state is to prevent activity on the network thread |
75 // if set to false. | 75 // if set to false. |
76 class ScreenRecorder : public base::RefCountedThreadSafe<ScreenRecorder> { | 76 class ScreenRecorder : public base::RefCountedThreadSafe<ScreenRecorder> { |
77 public: | 77 public: |
78 | |
79 // Construct a ScreenRecorder. Message loops and threads are provided. | 78 // Construct a ScreenRecorder. Message loops and threads are provided. |
80 // This object does not own capturer but owns encoder. | 79 // This object does not own capturer but owns encoder. |
81 ScreenRecorder( | 80 ScreenRecorder( |
82 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner, | 81 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner, |
83 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner, | 82 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner, |
84 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, | 83 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, |
85 Capturer* capturer, | 84 VideoFrameCapturer* capturer, |
86 Encoder* encoder); | 85 Encoder* encoder); |
87 | 86 |
88 // Start recording. | 87 // Start recording. |
89 void Start(); | 88 void Start(); |
90 | 89 |
91 // Stop the recording session. |done_task| is executed when recording is fully | 90 // Stop the recording session. |done_task| is executed when recording is fully |
92 // stopped. This object cannot be used again after |task| is executed. | 91 // stopped. This object cannot be used again after |task| is executed. |
93 void Stop(const base::Closure& done_task); | 92 void Stop(const base::Closure& done_task); |
94 | 93 |
95 // Add a connection to this recording session. | 94 // Add a connection to this recording session. |
96 void AddConnection(protocol::ConnectionToClient* connection); | 95 void AddConnection(protocol::ConnectionToClient* connection); |
97 | 96 |
98 // Remove a connection from receiving screen updates. | 97 // Remove a connection from receiving screen updates. |
99 void RemoveConnection(protocol::ConnectionToClient* connection); | 98 void RemoveConnection(protocol::ConnectionToClient* connection); |
100 | 99 |
101 // Remove all connections. | 100 // Remove all connections. |
102 void RemoveAllConnections(); | 101 void RemoveAllConnections(); |
103 | 102 |
104 // Update the sequence number for tracing performance. | 103 // Update the sequence number for tracing performance. |
105 void UpdateSequenceNumber(int64 sequence_number); | 104 void UpdateSequenceNumber(int64 sequence_number); |
106 | 105 |
107 private: | 106 private: |
108 friend class base::RefCountedThreadSafe<ScreenRecorder>; | 107 friend class base::RefCountedThreadSafe<ScreenRecorder>; |
109 virtual ~ScreenRecorder(); | 108 virtual ~ScreenRecorder(); |
110 | 109 |
111 // Getters for capturer and encoder. | 110 // Getters for capturer and encoder. |
112 Capturer* capturer(); | 111 VideoFrameCapturer* capturer(); |
113 Encoder* encoder(); | 112 Encoder* encoder(); |
114 | 113 |
115 bool is_recording(); | 114 bool is_recording(); |
116 | 115 |
117 // Capturer thread ---------------------------------------------------------- | 116 // Capturer thread ---------------------------------------------------------- |
118 | 117 |
119 void DoStart(); | 118 void DoStart(); |
120 void DoSetMaxRate(double max_rate); | 119 void DoSetMaxRate(double max_rate); |
121 | 120 |
122 // Hepler method to schedule next capture using the current rate. | 121 // Hepler method to schedule next capture using the current rate. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 void EncodedDataAvailableCallback(scoped_ptr<VideoPacket> packet); | 155 void EncodedDataAvailableCallback(scoped_ptr<VideoPacket> packet); |
157 void SendVideoPacket(VideoPacket* packet); | 156 void SendVideoPacket(VideoPacket* packet); |
158 | 157 |
159 // Task runners used by this class. | 158 // Task runners used by this class. |
160 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner_; | 159 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner_; |
161 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner_; | 160 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner_; |
162 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; | 161 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; |
163 | 162 |
164 // Reference to the capturer. This member is always accessed on the capture | 163 // Reference to the capturer. This member is always accessed on the capture |
165 // thread. | 164 // thread. |
166 Capturer* capturer_; | 165 VideoFrameCapturer* capturer_; |
167 | 166 |
168 // Reference to the encoder. This member is always accessed on the encode | 167 // Reference to the encoder. This member is always accessed on the encode |
169 // thread. | 168 // thread. |
170 scoped_ptr<Encoder> encoder_; | 169 scoped_ptr<Encoder> encoder_; |
171 | 170 |
172 // A list of clients connected to this hosts. | 171 // A list of clients connected to this hosts. |
173 // This member is always accessed on the network thread. | 172 // This member is always accessed on the network thread. |
174 typedef std::vector<protocol::ConnectionToClient*> ConnectionToClientList; | 173 typedef std::vector<protocol::ConnectionToClient*> ConnectionToClientList; |
175 ConnectionToClientList connections_; | 174 ConnectionToClientList connections_; |
176 | 175 |
(...skipping 26 matching lines...) Expand all Loading... |
203 | 202 |
204 // An object to schedule capturing. | 203 // An object to schedule capturing. |
205 CaptureScheduler scheduler_; | 204 CaptureScheduler scheduler_; |
206 | 205 |
207 DISALLOW_COPY_AND_ASSIGN(ScreenRecorder); | 206 DISALLOW_COPY_AND_ASSIGN(ScreenRecorder); |
208 }; | 207 }; |
209 | 208 |
210 } // namespace remoting | 209 } // namespace remoting |
211 | 210 |
212 #endif // REMOTING_HOST_SCREEN_RECORDER_H_ | 211 #endif // REMOTING_HOST_SCREEN_RECORDER_H_ |
OLD | NEW |