| 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 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 const blink::WebMediaStream& web_stream, | 128 const blink::WebMediaStream& web_stream, |
| 129 const base::WeakPtr<WebMediaPlayerMS>& player) | 129 const base::WeakPtr<WebMediaPlayerMS>& player) |
| 130 : compositor_task_runner_(compositor_task_runner), | 130 : compositor_task_runner_(compositor_task_runner), |
| 131 player_(player), | 131 player_(player), |
| 132 video_frame_provider_client_(nullptr), | 132 video_frame_provider_client_(nullptr), |
| 133 current_frame_used_by_compositor_(false), | 133 current_frame_used_by_compositor_(false), |
| 134 last_render_length_(base::TimeDelta::FromSecondsD(1.0 / 60.0)), | 134 last_render_length_(base::TimeDelta::FromSecondsD(1.0 / 60.0)), |
| 135 total_frame_count_(0), | 135 total_frame_count_(0), |
| 136 dropped_frame_count_(0), | 136 dropped_frame_count_(0), |
| 137 stopped_(true), | 137 stopped_(true), |
| 138 weak_ptr_factory_(this) { | 138 weak_factory_for_compositor_(this) { |
| 139 main_message_loop_ = base::MessageLoop::current(); | 139 main_message_loop_ = base::MessageLoop::current(); |
| 140 | 140 |
| 141 blink::WebVector<blink::WebMediaStreamTrack> video_tracks; | 141 blink::WebVector<blink::WebMediaStreamTrack> video_tracks; |
| 142 if (!web_stream.isNull()) | 142 if (!web_stream.isNull()) |
| 143 web_stream.videoTracks(video_tracks); | 143 web_stream.videoTracks(video_tracks); |
| 144 | 144 |
| 145 const bool remote_video = | 145 const bool remote_video = |
| 146 video_tracks.size() && video_tracks[0].source().remote(); | 146 video_tracks.size() && video_tracks[0].source().remote(); |
| 147 | 147 |
| 148 if (remote_video && | 148 if (remote_video && |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 DCHECK(compositor_task_runner_->BelongsToCurrentThread()); | 196 DCHECK(compositor_task_runner_->BelongsToCurrentThread()); |
| 197 if (video_frame_provider_client_) | 197 if (video_frame_provider_client_) |
| 198 video_frame_provider_client_->StopUsingProvider(); | 198 video_frame_provider_client_->StopUsingProvider(); |
| 199 | 199 |
| 200 video_frame_provider_client_ = client; | 200 video_frame_provider_client_ = client; |
| 201 if (video_frame_provider_client_ && !stopped_) | 201 if (video_frame_provider_client_ && !stopped_) |
| 202 video_frame_provider_client_->StartRendering(); | 202 video_frame_provider_client_->StartRendering(); |
| 203 } | 203 } |
| 204 | 204 |
| 205 void WebMediaPlayerMSCompositor::EnqueueFrame( | 205 void WebMediaPlayerMSCompositor::EnqueueFrame( |
| 206 const scoped_refptr<media::VideoFrame>& frame) { | 206 scoped_refptr<media::VideoFrame> frame) { |
| 207 DCHECK(thread_checker_.CalledOnValidThread()); | 207 DCHECK(compositor_task_runner_->BelongsToCurrentThread()); |
| 208 base::AutoLock auto_lock(current_frame_lock_); | 208 base::AutoLock auto_lock(current_frame_lock_); |
| 209 ++total_frame_count_; | 209 ++total_frame_count_; |
| 210 | 210 |
| 211 // With algorithm off, just let |current_frame_| hold the incoming |frame|. | 211 // With algorithm off, just let |current_frame_| hold the incoming |frame|. |
| 212 if (!rendering_frame_buffer_) { | 212 if (!rendering_frame_buffer_) { |
| 213 SetCurrentFrame(frame); | 213 SetCurrentFrame(frame); |
| 214 return; | 214 return; |
| 215 } | 215 } |
| 216 | 216 |
| 217 // This is a signal frame saying that the stream is stopped. | 217 // This is a signal frame saying that the stream is stopped. |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 WebMediaPlayerMSCompositor::GetCurrentFrameWithoutUpdatingStatistics() { | 311 WebMediaPlayerMSCompositor::GetCurrentFrameWithoutUpdatingStatistics() { |
| 312 DVLOG(3) << __func__; | 312 DVLOG(3) << __func__; |
| 313 base::AutoLock auto_lock(current_frame_lock_); | 313 base::AutoLock auto_lock(current_frame_lock_); |
| 314 return current_frame_; | 314 return current_frame_; |
| 315 } | 315 } |
| 316 | 316 |
| 317 void WebMediaPlayerMSCompositor::StartRendering() { | 317 void WebMediaPlayerMSCompositor::StartRendering() { |
| 318 DCHECK(thread_checker_.CalledOnValidThread()); | 318 DCHECK(thread_checker_.CalledOnValidThread()); |
| 319 compositor_task_runner_->PostTask( | 319 compositor_task_runner_->PostTask( |
| 320 FROM_HERE, base::Bind(&WebMediaPlayerMSCompositor::StartRenderingInternal, | 320 FROM_HERE, base::Bind(&WebMediaPlayerMSCompositor::StartRenderingInternal, |
| 321 weak_ptr_factory_.GetWeakPtr())); | 321 GetWeakPtr())); |
| 322 } | 322 } |
| 323 | 323 |
| 324 void WebMediaPlayerMSCompositor::StartRenderingInternal() { | 324 void WebMediaPlayerMSCompositor::StartRenderingInternal() { |
| 325 DCHECK(compositor_task_runner_->BelongsToCurrentThread()); | 325 DCHECK(compositor_task_runner_->BelongsToCurrentThread()); |
| 326 stopped_ = false; | 326 stopped_ = false; |
| 327 | 327 |
| 328 if (video_frame_provider_client_) | 328 if (video_frame_provider_client_) |
| 329 video_frame_provider_client_->StartRendering(); | 329 video_frame_provider_client_->StartRendering(); |
| 330 } | 330 } |
| 331 | 331 |
| 332 void WebMediaPlayerMSCompositor::StopRendering() { | 332 void WebMediaPlayerMSCompositor::StopRendering() { |
| 333 DCHECK(thread_checker_.CalledOnValidThread()); | 333 DCHECK(thread_checker_.CalledOnValidThread()); |
| 334 compositor_task_runner_->PostTask( | 334 compositor_task_runner_->PostTask( |
| 335 FROM_HERE, base::Bind(&WebMediaPlayerMSCompositor::StopRenderingInternal, | 335 FROM_HERE, base::Bind(&WebMediaPlayerMSCompositor::StopRenderingInternal, |
| 336 weak_ptr_factory_.GetWeakPtr())); | 336 GetWeakPtr())); |
| 337 } | 337 } |
| 338 | 338 |
| 339 void WebMediaPlayerMSCompositor::StopRenderingInternal() { | 339 void WebMediaPlayerMSCompositor::StopRenderingInternal() { |
| 340 DCHECK(compositor_task_runner_->BelongsToCurrentThread()); | 340 DCHECK(compositor_task_runner_->BelongsToCurrentThread()); |
| 341 stopped_ = true; | 341 stopped_ = true; |
| 342 | 342 |
| 343 // It is possible that the video gets paused and then resumed. We need to | 343 // It is possible that the video gets paused and then resumed. We need to |
| 344 // reset VideoRendererAlgorithm, otherwise, VideoRendererAlgorithm will think | 344 // reset VideoRendererAlgorithm, otherwise, VideoRendererAlgorithm will think |
| 345 // there is a very long frame in the queue and then make totally wrong | 345 // there is a very long frame in the queue and then make totally wrong |
| 346 // frame selection. | 346 // frame selection. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 361 return; | 361 return; |
| 362 | 362 |
| 363 // Copy the frame so that rendering can show the last received frame. | 363 // Copy the frame so that rendering can show the last received frame. |
| 364 // The original frame must not be referenced when the player is paused since | 364 // The original frame must not be referenced when the player is paused since |
| 365 // there might be a finite number of available buffers. E.g, video that | 365 // there might be a finite number of available buffers. E.g, video that |
| 366 // originates from a video camera. | 366 // originates from a video camera. |
| 367 current_frame_ = | 367 current_frame_ = |
| 368 CopyFrame(current_frame_, player_->GetSkCanvasVideoRenderer()); | 368 CopyFrame(current_frame_, player_->GetSkCanvasVideoRenderer()); |
| 369 } | 369 } |
| 370 | 370 |
| 371 base::WeakPtr<WebMediaPlayerMSCompositor> |
| 372 WebMediaPlayerMSCompositor::GetWeakPtr() { |
| 373 return weak_factory_for_compositor_.GetWeakPtr(); |
| 374 } |
| 375 |
| 371 bool WebMediaPlayerMSCompositor::MapTimestampsToRenderTimeTicks( | 376 bool WebMediaPlayerMSCompositor::MapTimestampsToRenderTimeTicks( |
| 372 const std::vector<base::TimeDelta>& timestamps, | 377 const std::vector<base::TimeDelta>& timestamps, |
| 373 std::vector<base::TimeTicks>* wall_clock_times) { | 378 std::vector<base::TimeTicks>* wall_clock_times) { |
| 374 DCHECK(compositor_task_runner_->BelongsToCurrentThread() || | 379 DCHECK(compositor_task_runner_->BelongsToCurrentThread() || |
| 375 thread_checker_.CalledOnValidThread()); | 380 thread_checker_.CalledOnValidThread()); |
| 376 for (const base::TimeDelta& timestamp : timestamps) { | 381 for (const base::TimeDelta& timestamp : timestamps) { |
| 377 DCHECK(timestamps_to_clock_times_.count(timestamp)); | 382 DCHECK(timestamps_to_clock_times_.count(timestamp)); |
| 378 wall_clock_times->push_back(timestamps_to_clock_times_[timestamp]); | 383 wall_clock_times->push_back(timestamps_to_clock_times_[timestamp]); |
| 379 } | 384 } |
| 380 return true; | 385 return true; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 } | 443 } |
| 439 | 444 |
| 440 if (!rendering_frame_buffer_) { | 445 if (!rendering_frame_buffer_) { |
| 441 rendering_frame_buffer_.reset(new media::VideoRendererAlgorithm( | 446 rendering_frame_buffer_.reset(new media::VideoRendererAlgorithm( |
| 442 base::Bind(&WebMediaPlayerMSCompositor::MapTimestampsToRenderTimeTicks, | 447 base::Bind(&WebMediaPlayerMSCompositor::MapTimestampsToRenderTimeTicks, |
| 443 base::Unretained(this)))); | 448 base::Unretained(this)))); |
| 444 } | 449 } |
| 445 } | 450 } |
| 446 | 451 |
| 447 } // namespace content | 452 } // namespace content |
| OLD | NEW |