Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(249)

Side by Side Diff: remoting/host/video_scheduler.h

Issue 11778049: Making DesktopEnvironment a factory class used by ClientSession to create audio/video capturers and… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « remoting/host/remoting_me2me_host.cc ('k') | remoting/host/video_scheduler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_VIDEO_SCHEDULER_H_ 5 #ifndef REMOTING_HOST_VIDEO_SCHEDULER_H_
6 #define REMOTING_HOST_VIDEO_SCHEDULER_H_ 6 #define REMOTING_HOST_VIDEO_SCHEDULER_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"
12 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
14 #include "base/time.h" 13 #include "base/time.h"
15 #include "base/timer.h" 14 #include "base/timer.h"
16 #include "remoting/capturer/video_frame_capturer.h" 15 #include "remoting/capturer/video_frame_capturer.h"
17 #include "remoting/codec/video_encoder.h" 16 #include "remoting/codec/video_encoder.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"
19 #include "third_party/skia/include/core/SkSize.h"
20 20
21 namespace base { 21 namespace base {
22 class SingleThreadTaskRunner; 22 class SingleThreadTaskRunner;
23 } // namespace base 23 } // namespace base
24 24
25 namespace remoting { 25 namespace remoting {
26 26
27 class CaptureData; 27 class CaptureData;
28 class CursorShapeInfo; 28 class CursorShapeInfo;
29 class VideoFrameCapturer; 29 class VideoFrameCapturer;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 // of the capture, encode and network processes. However, it also needs to 69 // of the capture, encode and network processes. However, it also needs to
70 // rate-limit captures to avoid overloading the host system, either by consuming 70 // rate-limit captures to avoid overloading the host system, either by consuming
71 // too much CPU, or hogging the host's graphics subsystem. 71 // too much CPU, or hogging the host's graphics subsystem.
72 72
73 class VideoScheduler : public base::RefCountedThreadSafe<VideoScheduler>, 73 class VideoScheduler : public base::RefCountedThreadSafe<VideoScheduler>,
74 public VideoFrameCapturer::Delegate { 74 public VideoFrameCapturer::Delegate {
75 public: 75 public:
76 // Creates a VideoScheduler running capture, encode and network tasks on the 76 // Creates a VideoScheduler running capture, encode and network tasks on the
77 // supplied TaskRunners. Video and cursor shape updates will be pumped to 77 // supplied TaskRunners. Video and cursor shape updates will be pumped to
78 // |video_stub| and |client_stub|, which must remain valid until Stop() is 78 // |video_stub| and |client_stub|, which must remain valid until Stop() is
79 // called. |capturer| is used to capture frames and must remain valid until 79 // called. |capturer| is used to capture frames.
80 // the |done_task| supplied to Stop() is executed.
81 static scoped_refptr<VideoScheduler> Create( 80 static scoped_refptr<VideoScheduler> Create(
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 VideoFrameCapturer* capturer, 84 scoped_ptr<VideoFrameCapturer> capturer,
86 scoped_ptr<VideoEncoder> encoder, 85 scoped_ptr<VideoEncoder> encoder,
87 protocol::CursorShapeStub* cursor_stub, 86 protocol::CursorShapeStub* cursor_stub,
88 protocol::VideoStub* video_stub); 87 protocol::VideoStub* video_stub);
89 88
90 // VideoFrameCapturer::Delegate implementation. 89 // VideoFrameCapturer::Delegate implementation.
91 virtual void OnCaptureCompleted( 90 virtual void OnCaptureCompleted(
92 scoped_refptr<CaptureData> capture_data) OVERRIDE; 91 scoped_refptr<CaptureData> capture_data) OVERRIDE;
93 virtual void OnCursorShapeChanged( 92 virtual void OnCursorShapeChanged(
94 scoped_ptr<MouseCursorShape> cursor_shape) OVERRIDE; 93 scoped_ptr<MouseCursorShape> cursor_shape) OVERRIDE;
95 94
96 // Stop scheduling frame captures. |done_task| is executed on the network 95 // Stop scheduling frame captures. This object cannot be re-used once
97 // thread when capturing has stopped. This object cannot be re-used once
98 // it has been stopped. 96 // it has been stopped.
99 void Stop(const base::Closure& done_task); 97 void Stop();
100 98
101 // Pauses or resumes scheduling of frame captures. Pausing/resuming captures 99 // Pauses or resumes scheduling of frame captures. Pausing/resuming captures
102 // only affects capture scheduling and does not stop/start the capturer. 100 // only affects capture scheduling and does not stop/start the capturer.
103 void Pause(bool pause); 101 void Pause(bool pause);
104 102
105 // Updates the sequence number embedded in VideoPackets. 103 // Updates the sequence number embedded in VideoPackets.
106 // Sequence numbers are used for performance measurements. 104 // Sequence numbers are used for performance measurements.
107 void UpdateSequenceNumber(int64 sequence_number); 105 void UpdateSequenceNumber(int64 sequence_number);
108 106
109 private: 107 private:
110 friend class base::RefCountedThreadSafe<VideoScheduler>; 108 friend class base::RefCountedThreadSafe<VideoScheduler>;
111 109
112 VideoScheduler( 110 VideoScheduler(
113 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner, 111 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner,
114 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner, 112 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner,
115 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, 113 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner,
116 VideoFrameCapturer* capturer, 114 scoped_ptr<VideoFrameCapturer> capturer,
117 scoped_ptr<VideoEncoder> encoder, 115 scoped_ptr<VideoEncoder> encoder,
118 protocol::CursorShapeStub* cursor_stub, 116 protocol::CursorShapeStub* cursor_stub,
119 protocol::VideoStub* video_stub); 117 protocol::VideoStub* video_stub);
120 virtual ~VideoScheduler(); 118 virtual ~VideoScheduler();
121 119
122 // Capturer thread ---------------------------------------------------------- 120 // Capturer thread ----------------------------------------------------------
123 121
124 // Starts the capturer on the capture thread. 122 // Starts the capturer on the capture thread.
125 void StartOnCaptureThread(); 123 void StartOnCaptureThread();
126 124
127 // Stops scheduling frame captures on the capture thread, and posts 125 // Stops scheduling frame captures on the capture thread, and posts
128 // |done_task| to the network thread when done. 126 // StopOnEncodeThread() to the network thread when done.
129 void StopOnCaptureThread(const base::Closure& done_task); 127 void StopOnCaptureThread();
130 128
131 // Schedules the next call to CaptureNextFrame. 129 // Schedules the next call to CaptureNextFrame.
132 void ScheduleNextCapture(); 130 void ScheduleNextCapture();
133 131
134 // Starts the next frame capture, unless there are already too many pending. 132 // Starts the next frame capture, unless there are already too many pending.
135 void CaptureNextFrame(); 133 void CaptureNextFrame();
136 134
137 // Called when a frame capture has been encoded & sent to the client. 135 // Called when a frame capture has been encoded & sent to the client.
138 void FrameCaptureCompleted(); 136 void FrameCaptureCompleted();
139 137
140 // Network thread ----------------------------------------------------------- 138 // Network thread -----------------------------------------------------------
141 139
142 // Send |packet| to the client, unless we are in the process of stopping. 140 // Send |packet| to the client, unless we are in the process of stopping.
143 void SendVideoPacket(scoped_ptr<VideoPacket> packet); 141 void SendVideoPacket(scoped_ptr<VideoPacket> packet);
144 142
145 // Callback passed to |video_stub_| for the last packet in each frame, to 143 // Callback passed to |video_stub_| for the last packet in each frame, to
146 // rate-limit frame captures to network throughput. 144 // rate-limit frame captures to network throughput.
147 void VideoFrameSentCallback(); 145 void VideoFrameSentCallback();
148 146
149 // Send updated cursor shape to client. 147 // Send updated cursor shape to client.
150 void SendCursorShape(scoped_ptr<protocol::CursorShapeInfo> cursor_shape); 148 void SendCursorShape(scoped_ptr<protocol::CursorShapeInfo> cursor_shape);
151 149
150 // Posted to the network thread to delete |capturer| on the thread that
151 // created it.
152 void StopOnNetworkThread(scoped_ptr<VideoFrameCapturer> capturer);
153
152 // Encoder thread ----------------------------------------------------------- 154 // Encoder thread -----------------------------------------------------------
153 155
154 // Encode a frame, passing generated VideoPackets to SendVideoPacket(). 156 // Encode a frame, passing generated VideoPackets to SendVideoPacket().
155 void EncodeFrame(scoped_refptr<CaptureData> capture_data); 157 void EncodeFrame(scoped_refptr<CaptureData> capture_data);
156 158
157 void EncodedDataAvailableCallback(scoped_ptr<VideoPacket> packet); 159 void EncodedDataAvailableCallback(scoped_ptr<VideoPacket> packet);
158 160
159 // Used to synchronize capture and encode thread teardown, notifying the 161 // Used to synchronize capture and encode thread teardown, notifying the
160 // network thread when done. 162 // network thread when done.
161 void StopOnEncodeThread(const base::Closure& done_task); 163 void StopOnEncodeThread(scoped_ptr<VideoFrameCapturer> capturer);
162 164
163 // Task runners used by this class. 165 // Task runners used by this class.
164 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner_; 166 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner_;
165 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner_; 167 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner_;
166 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; 168 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_;
167 169
168 // Used to capture frames. Always accessed on the capture thread. 170 // Used to capture frames. Always accessed on the capture thread.
169 VideoFrameCapturer* capturer_; 171 scoped_ptr<VideoFrameCapturer> capturer_;
170 172
171 // Used to encode captured frames. Always accessed on the encode thread. 173 // Used to encode captured frames. Always accessed on the encode thread.
172 scoped_ptr<VideoEncoder> encoder_; 174 scoped_ptr<VideoEncoder> encoder_;
173 175
174 // Interfaces through which video frames and cursor shapes are passed to the 176 // Interfaces through which video frames and cursor shapes are passed to the
175 // client. These members are always accessed on the network thread. 177 // client. These members are always accessed on the network thread.
176 protocol::CursorShapeStub* cursor_stub_; 178 protocol::CursorShapeStub* cursor_stub_;
177 protocol::VideoStub* video_stub_; 179 protocol::VideoStub* video_stub_;
178 180
179 // Timer used to schedule CaptureNextFrame(). 181 // Timer used to schedule CaptureNextFrame().
(...skipping 13 matching lines...) Expand all
193 195
194 // An object to schedule capturing. 196 // An object to schedule capturing.
195 CaptureScheduler scheduler_; 197 CaptureScheduler scheduler_;
196 198
197 DISALLOW_COPY_AND_ASSIGN(VideoScheduler); 199 DISALLOW_COPY_AND_ASSIGN(VideoScheduler);
198 }; 200 };
199 201
200 } // namespace remoting 202 } // namespace remoting
201 203
202 #endif // REMOTING_HOST_VIDEO_SCHEDULER_H_ 204 #endif // REMOTING_HOST_VIDEO_SCHEDULER_H_
OLDNEW
« no previous file with comments | « remoting/host/remoting_me2me_host.cc ('k') | remoting/host/video_scheduler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698