OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "remoting/client/software_video_renderer.h" | 5 #include "remoting/client/software_video_renderer.h" |
6 | 6 |
7 #include <list> | 7 #include <list> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/callback_helpers.h" | 11 #include "base/callback_helpers.h" |
12 #include "base/location.h" | 12 #include "base/location.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
15 #include "remoting/base/util.h" | 15 #include "remoting/base/util.h" |
16 #include "remoting/client/frame_consumer.h" | 16 #include "remoting/client/frame_consumer_proxy.h" |
17 #include "remoting/codec/video_decoder.h" | 17 #include "remoting/codec/video_decoder.h" |
18 #include "remoting/codec/video_decoder_verbatim.h" | 18 #include "remoting/codec/video_decoder_verbatim.h" |
19 #include "remoting/codec/video_decoder_vpx.h" | 19 #include "remoting/codec/video_decoder_vpx.h" |
20 #include "remoting/protocol/session_config.h" | 20 #include "remoting/protocol/session_config.h" |
21 #include "third_party/libyuv/include/libyuv/convert_argb.h" | 21 #include "third_party/libyuv/include/libyuv/convert_argb.h" |
22 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" | 22 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" |
23 | 23 |
24 using base::Passed; | 24 using base::Passed; |
25 using remoting::protocol::ChannelConfig; | 25 using remoting::protocol::ChannelConfig; |
26 using remoting::protocol::SessionConfig; | 26 using remoting::protocol::SessionConfig; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 } | 73 } |
74 | 74 |
75 private: | 75 private: |
76 scoped_ptr<VideoDecoder> parent_; | 76 scoped_ptr<VideoDecoder> parent_; |
77 }; | 77 }; |
78 | 78 |
79 class SoftwareVideoRenderer::Core { | 79 class SoftwareVideoRenderer::Core { |
80 public: | 80 public: |
81 Core(scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 81 Core(scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
82 scoped_refptr<base::SingleThreadTaskRunner> decode_task_runner, | 82 scoped_refptr<base::SingleThreadTaskRunner> decode_task_runner, |
83 scoped_refptr<FrameConsumerProxy> consumer); | 83 scoped_ptr<FrameConsumerProxy> consumer); |
84 ~Core(); | 84 ~Core(); |
85 | 85 |
86 void OnSessionConfig(const protocol::SessionConfig& config); | 86 void OnSessionConfig(const protocol::SessionConfig& config); |
87 void DrawBuffer(webrtc::DesktopFrame* buffer); | 87 void DrawBuffer(webrtc::DesktopFrame* buffer); |
88 void InvalidateRegion(const webrtc::DesktopRegion& region); | 88 void InvalidateRegion(const webrtc::DesktopRegion& region); |
89 void RequestReturnBuffers(const base::Closure& done); | 89 void RequestReturnBuffers(const base::Closure& done); |
90 void SetOutputSizeAndClip( | 90 void SetOutputSizeAndClip( |
91 const webrtc::DesktopSize& view_size, | 91 const webrtc::DesktopSize& view_size, |
92 const webrtc::DesktopRect& clip_area); | 92 const webrtc::DesktopRect& clip_area); |
93 | 93 |
94 // Decodes the contents of |packet|. DecodePacket may keep a reference to | 94 // Decodes the contents of |packet|. DecodePacket may keep a reference to |
95 // |packet| so the |packet| must remain alive and valid until |done| is | 95 // |packet| so the |packet| must remain alive and valid until |done| is |
96 // executed. | 96 // executed. |
97 void DecodePacket(scoped_ptr<VideoPacket> packet, const base::Closure& done); | 97 void DecodePacket(scoped_ptr<VideoPacket> packet, const base::Closure& done); |
98 | 98 |
99 private: | 99 private: |
100 // Paints the invalidated region to the next available buffer and returns it | 100 // Paints the invalidated region to the next available buffer and returns it |
101 // to the consumer. | 101 // to the consumer. |
102 void SchedulePaint(); | 102 void SchedulePaint(); |
103 void DoPaint(); | 103 void DoPaint(); |
104 | 104 |
105 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | 105 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
106 scoped_refptr<base::SingleThreadTaskRunner> decode_task_runner_; | 106 scoped_refptr<base::SingleThreadTaskRunner> decode_task_runner_; |
107 scoped_refptr<FrameConsumerProxy> consumer_; | 107 scoped_ptr<FrameConsumerProxy> consumer_; |
108 scoped_ptr<VideoDecoder> decoder_; | 108 scoped_ptr<VideoDecoder> decoder_; |
109 | 109 |
110 // Remote screen size in pixels. | 110 // Remote screen size in pixels. |
111 webrtc::DesktopSize source_size_; | 111 webrtc::DesktopSize source_size_; |
112 | 112 |
113 // Vertical and horizontal DPI of the remote screen. | 113 // Vertical and horizontal DPI of the remote screen. |
114 webrtc::DesktopVector source_dpi_; | 114 webrtc::DesktopVector source_dpi_; |
115 | 115 |
116 // The current dimensions of the frame consumer view. | 116 // The current dimensions of the frame consumer view. |
117 webrtc::DesktopSize view_size_; | 117 webrtc::DesktopSize view_size_; |
118 webrtc::DesktopRect clip_area_; | 118 webrtc::DesktopRect clip_area_; |
119 | 119 |
120 // The drawing buffers supplied by the frame consumer. | 120 // The drawing buffers supplied by the frame consumer. |
121 std::list<webrtc::DesktopFrame*> buffers_; | 121 std::list<webrtc::DesktopFrame*> buffers_; |
122 | 122 |
123 // Flag used to coalesce runs of SchedulePaint()s into a single DoPaint(). | 123 // Flag used to coalesce runs of SchedulePaint()s into a single DoPaint(). |
124 bool paint_scheduled_; | 124 bool paint_scheduled_; |
125 | 125 |
126 base::WeakPtrFactory<Core> weak_factory_; | 126 base::WeakPtrFactory<Core> weak_factory_; |
127 }; | 127 }; |
128 | 128 |
129 SoftwareVideoRenderer::Core::Core( | 129 SoftwareVideoRenderer::Core::Core( |
130 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 130 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
131 scoped_refptr<base::SingleThreadTaskRunner> decode_task_runner, | 131 scoped_refptr<base::SingleThreadTaskRunner> decode_task_runner, |
132 scoped_refptr<FrameConsumerProxy> consumer) | 132 scoped_ptr<FrameConsumerProxy> consumer) |
133 : main_task_runner_(main_task_runner), | 133 : main_task_runner_(main_task_runner), |
134 decode_task_runner_(decode_task_runner), | 134 decode_task_runner_(decode_task_runner), |
135 consumer_(consumer), | 135 consumer_(consumer.Pass()), |
136 paint_scheduled_(false), | 136 paint_scheduled_(false), |
137 weak_factory_(this) { | 137 weak_factory_(this) { |
138 } | 138 } |
139 | 139 |
140 SoftwareVideoRenderer::Core::~Core() { | 140 SoftwareVideoRenderer::Core::~Core() { |
141 } | 141 } |
142 | 142 |
143 void SoftwareVideoRenderer::Core::OnSessionConfig(const SessionConfig& config) { | 143 void SoftwareVideoRenderer::Core::OnSessionConfig(const SessionConfig& config) { |
144 DCHECK(decode_task_runner_->BelongsToCurrentThread()); | 144 DCHECK(decode_task_runner_->BelongsToCurrentThread()); |
145 | 145 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 // Draw the invalidated region to the buffer. | 235 // Draw the invalidated region to the buffer. |
236 webrtc::DesktopFrame* buffer = buffers_.front(); | 236 webrtc::DesktopFrame* buffer = buffers_.front(); |
237 webrtc::DesktopRegion output_region; | 237 webrtc::DesktopRegion output_region; |
238 decoder_->RenderFrame(view_size_, clip_area_, | 238 decoder_->RenderFrame(view_size_, clip_area_, |
239 buffer->data(), buffer->stride(), &output_region); | 239 buffer->data(), buffer->stride(), &output_region); |
240 | 240 |
241 // Notify the consumer that painting is done. | 241 // Notify the consumer that painting is done. |
242 if (!output_region.is_empty()) { | 242 if (!output_region.is_empty()) { |
243 buffers_.pop_front(); | 243 buffers_.pop_front(); |
244 consumer_->ApplyBuffer(view_size_, clip_area_, buffer, output_region, | 244 consumer_->ApplyBuffer(view_size_, clip_area_, buffer, output_region, |
245 *decoder_->GetImageShape()); | 245 decoder_->GetImageShape()); |
246 } | 246 } |
247 } | 247 } |
248 | 248 |
249 void SoftwareVideoRenderer::Core::RequestReturnBuffers( | 249 void SoftwareVideoRenderer::Core::RequestReturnBuffers( |
250 const base::Closure& done) { | 250 const base::Closure& done) { |
251 DCHECK(decode_task_runner_->BelongsToCurrentThread()); | 251 DCHECK(decode_task_runner_->BelongsToCurrentThread()); |
252 | 252 |
253 while (!buffers_.empty()) { | 253 while (!buffers_.empty()) { |
254 consumer_->ReturnBuffer(buffers_.front()); | 254 consumer_->ReturnBuffer(buffers_.front()); |
255 buffers_.pop_front(); | 255 buffers_.pop_front(); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 } | 308 } |
309 } | 309 } |
310 | 310 |
311 SchedulePaint(); | 311 SchedulePaint(); |
312 } | 312 } |
313 } | 313 } |
314 | 314 |
315 SoftwareVideoRenderer::SoftwareVideoRenderer( | 315 SoftwareVideoRenderer::SoftwareVideoRenderer( |
316 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 316 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
317 scoped_refptr<base::SingleThreadTaskRunner> decode_task_runner, | 317 scoped_refptr<base::SingleThreadTaskRunner> decode_task_runner, |
318 scoped_refptr<FrameConsumerProxy> consumer) | 318 FrameConsumer* frame_consumer) |
319 : decode_task_runner_(decode_task_runner), | 319 : decode_task_runner_(decode_task_runner), |
320 core_(new Core(main_task_runner, decode_task_runner, consumer)), | |
321 latest_event_timestamp_(0), | 320 latest_event_timestamp_(0), |
| 321 weak_frame_consumer_(frame_consumer), |
322 weak_factory_(this) { | 322 weak_factory_(this) { |
323 DCHECK(CalledOnValidThread()); | 323 DCHECK(CalledOnValidThread()); |
| 324 core_ = make_scoped_ptr(new Core(main_task_runner, decode_task_runner, |
| 325 make_scoped_ptr(new FrameConsumerProxy( |
| 326 weak_frame_consumer_.GetWeakPtr())))); |
324 } | 327 } |
325 | 328 |
326 SoftwareVideoRenderer::~SoftwareVideoRenderer() { | 329 SoftwareVideoRenderer::~SoftwareVideoRenderer() { |
327 DCHECK(CalledOnValidThread()); | 330 DCHECK(CalledOnValidThread()); |
328 bool result = decode_task_runner_->DeleteSoon(FROM_HERE, core_.release()); | 331 bool result = decode_task_runner_->DeleteSoon(FROM_HERE, core_.release()); |
329 DCHECK(result); | 332 DCHECK(result); |
330 } | 333 } |
331 | 334 |
332 void SoftwareVideoRenderer::OnSessionConfig( | 335 void SoftwareVideoRenderer::OnSessionConfig( |
333 const protocol::SessionConfig& config) { | 336 const protocol::SessionConfig& config) { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 DCHECK(CalledOnValidThread()); | 424 DCHECK(CalledOnValidThread()); |
422 | 425 |
423 // Record the latency between the packet being received and presented. | 426 // Record the latency between the packet being received and presented. |
424 stats_.video_decode_ms()->Record( | 427 stats_.video_decode_ms()->Record( |
425 (base::Time::Now() - decode_start).InMilliseconds()); | 428 (base::Time::Now() - decode_start).InMilliseconds()); |
426 | 429 |
427 done.Run(); | 430 done.Run(); |
428 } | 431 } |
429 | 432 |
430 } // namespace remoting | 433 } // namespace remoting |
OLD | NEW |