OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "content/renderer/media/webmediaplayer_ms_compositor.h" | 5 #include "content/renderer/media/webmediaplayer_ms_compositor.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/hash.h" | 10 #include "base/hash.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 const scoped_refptr<base::SingleThreadTaskRunner>& compositor_task_runner, | 97 const scoped_refptr<base::SingleThreadTaskRunner>& compositor_task_runner, |
98 const blink::WebURL& url, | 98 const blink::WebURL& url, |
99 const base::WeakPtr<WebMediaPlayerMS>& player) | 99 const base::WeakPtr<WebMediaPlayerMS>& player) |
100 : compositor_task_runner_(compositor_task_runner), | 100 : compositor_task_runner_(compositor_task_runner), |
101 player_(player), | 101 player_(player), |
102 video_frame_provider_client_(nullptr), | 102 video_frame_provider_client_(nullptr), |
103 current_frame_used_by_compositor_(false), | 103 current_frame_used_by_compositor_(false), |
104 last_render_length_(base::TimeDelta::FromSecondsD(1.0 / 60.0)), | 104 last_render_length_(base::TimeDelta::FromSecondsD(1.0 / 60.0)), |
105 total_frame_count_(0), | 105 total_frame_count_(0), |
106 dropped_frame_count_(0), | 106 dropped_frame_count_(0), |
107 stopped_(true) { | 107 stopped_(true), |
| 108 weak_ptr_factory_(this) { |
108 main_message_loop_ = base::MessageLoop::current(); | 109 main_message_loop_ = base::MessageLoop::current(); |
109 | 110 |
110 const blink::WebMediaStream web_stream( | 111 const blink::WebMediaStream web_stream( |
111 blink::WebMediaStreamRegistry::lookupMediaStreamDescriptor(url)); | 112 blink::WebMediaStreamRegistry::lookupMediaStreamDescriptor(url)); |
112 blink::WebVector<blink::WebMediaStreamTrack> video_tracks; | 113 blink::WebVector<blink::WebMediaStreamTrack> video_tracks; |
113 if (!web_stream.isNull()) | 114 if (!web_stream.isNull()) |
114 web_stream.videoTracks(video_tracks); | 115 web_stream.videoTracks(video_tracks); |
115 | 116 |
116 const bool remote_video = | 117 const bool remote_video = |
117 video_tracks.size() && video_tracks[0].source().remote(); | 118 video_tracks.size() && video_tracks[0].source().remote(); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 void WebMediaPlayerMSCompositor::PutCurrentFrame() { | 266 void WebMediaPlayerMSCompositor::PutCurrentFrame() { |
266 DVLOG(3) << __FUNCTION__; | 267 DVLOG(3) << __FUNCTION__; |
267 base::AutoLock auto_lock(current_frame_lock_); | 268 base::AutoLock auto_lock(current_frame_lock_); |
268 current_frame_used_by_compositor_ = true; | 269 current_frame_used_by_compositor_ = true; |
269 } | 270 } |
270 | 271 |
271 void WebMediaPlayerMSCompositor::StartRendering() { | 272 void WebMediaPlayerMSCompositor::StartRendering() { |
272 DCHECK(thread_checker_.CalledOnValidThread()); | 273 DCHECK(thread_checker_.CalledOnValidThread()); |
273 compositor_task_runner_->PostTask( | 274 compositor_task_runner_->PostTask( |
274 FROM_HERE, base::Bind(&WebMediaPlayerMSCompositor::StartRenderingInternal, | 275 FROM_HERE, base::Bind(&WebMediaPlayerMSCompositor::StartRenderingInternal, |
275 base::Unretained(this))); | 276 weak_ptr_factory_.GetWeakPtr())); |
276 } | 277 } |
277 | 278 |
278 void WebMediaPlayerMSCompositor::StartRenderingInternal() { | 279 void WebMediaPlayerMSCompositor::StartRenderingInternal() { |
279 DCHECK(compositor_task_runner_->BelongsToCurrentThread()); | 280 DCHECK(compositor_task_runner_->BelongsToCurrentThread()); |
280 stopped_ = false; | 281 stopped_ = false; |
281 | 282 |
282 if (video_frame_provider_client_) | 283 if (video_frame_provider_client_) |
283 video_frame_provider_client_->StartRendering(); | 284 video_frame_provider_client_->StartRendering(); |
284 } | 285 } |
285 | 286 |
286 void WebMediaPlayerMSCompositor::StopRendering() { | 287 void WebMediaPlayerMSCompositor::StopRendering() { |
287 DCHECK(thread_checker_.CalledOnValidThread()); | 288 DCHECK(thread_checker_.CalledOnValidThread()); |
288 compositor_task_runner_->PostTask( | 289 compositor_task_runner_->PostTask( |
289 FROM_HERE, base::Bind(&WebMediaPlayerMSCompositor::StopRenderingInternal, | 290 FROM_HERE, base::Bind(&WebMediaPlayerMSCompositor::StopRenderingInternal, |
290 base::Unretained(this))); | 291 weak_ptr_factory_.GetWeakPtr())); |
291 } | 292 } |
292 | 293 |
293 void WebMediaPlayerMSCompositor::StopRenderingInternal() { | 294 void WebMediaPlayerMSCompositor::StopRenderingInternal() { |
294 DCHECK(compositor_task_runner_->BelongsToCurrentThread()); | 295 DCHECK(compositor_task_runner_->BelongsToCurrentThread()); |
295 stopped_ = true; | 296 stopped_ = true; |
296 | 297 |
297 // It is possible that the video gets paused and then resumed. We need to | 298 // It is possible that the video gets paused and then resumed. We need to |
298 // reset VideoRendererAlgorithm, otherwise, VideoRendererAlgorithm will think | 299 // reset VideoRendererAlgorithm, otherwise, VideoRendererAlgorithm will think |
299 // there is a very long frame in the queue and then make totally wrong | 300 // there is a very long frame in the queue and then make totally wrong |
300 // frame selection. | 301 // frame selection. |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 } | 384 } |
384 | 385 |
385 if (!rendering_frame_buffer_) { | 386 if (!rendering_frame_buffer_) { |
386 rendering_frame_buffer_.reset(new media::VideoRendererAlgorithm( | 387 rendering_frame_buffer_.reset(new media::VideoRendererAlgorithm( |
387 base::Bind(&WebMediaPlayerMSCompositor::MapTimestampsToRenderTimeTicks, | 388 base::Bind(&WebMediaPlayerMSCompositor::MapTimestampsToRenderTimeTicks, |
388 base::Unretained(this)))); | 389 base::Unretained(this)))); |
389 } | 390 } |
390 } | 391 } |
391 | 392 |
392 } // namespace content | 393 } // namespace content |
OLD | NEW |