| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "media/filters/video_renderer_impl.h" | 5 #include "media/filters/video_renderer_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
| 10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| 11 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/threading/platform_thread.h" | 13 #include "base/threading/platform_thread.h" |
| 14 #include "media/base/bind_to_current_loop.h" |
| 14 #include "media/base/buffers.h" | 15 #include "media/base/buffers.h" |
| 15 #include "media/base/limits.h" | 16 #include "media/base/limits.h" |
| 16 #include "media/base/pipeline.h" | 17 #include "media/base/pipeline.h" |
| 17 #include "media/base/video_frame.h" | 18 #include "media/base/video_frame.h" |
| 18 | 19 |
| 19 namespace media { | 20 namespace media { |
| 20 | 21 |
| 21 VideoRendererImpl::VideoRendererImpl( | 22 VideoRendererImpl::VideoRendererImpl( |
| 22 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 23 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 23 ScopedVector<VideoDecoder> decoders, | 24 ScopedVector<VideoDecoder> decoders, |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 DCHECK(!statistics_cb.is_null()); | 120 DCHECK(!statistics_cb.is_null()); |
| 120 DCHECK(!max_time_cb.is_null()); | 121 DCHECK(!max_time_cb.is_null()); |
| 121 DCHECK(!buffering_state_cb.is_null()); | 122 DCHECK(!buffering_state_cb.is_null()); |
| 122 DCHECK(!ended_cb.is_null()); | 123 DCHECK(!ended_cb.is_null()); |
| 123 DCHECK(!get_time_cb.is_null()); | 124 DCHECK(!get_time_cb.is_null()); |
| 124 DCHECK(!get_duration_cb.is_null()); | 125 DCHECK(!get_duration_cb.is_null()); |
| 125 DCHECK_EQ(kUninitialized, state_); | 126 DCHECK_EQ(kUninitialized, state_); |
| 126 | 127 |
| 127 low_delay_ = low_delay; | 128 low_delay_ = low_delay; |
| 128 | 129 |
| 129 init_cb_ = init_cb; | 130 // Always post |init_cb_| because |this| could be destroyed if initialization |
| 131 // failed. |
| 132 init_cb_ = BindToCurrentLoop(init_cb); |
| 133 |
| 130 statistics_cb_ = statistics_cb; | 134 statistics_cb_ = statistics_cb; |
| 131 max_time_cb_ = max_time_cb; | 135 max_time_cb_ = max_time_cb; |
| 132 buffering_state_cb_ = buffering_state_cb; | 136 buffering_state_cb_ = buffering_state_cb; |
| 133 ended_cb_ = ended_cb; | 137 ended_cb_ = ended_cb; |
| 134 error_cb_ = error_cb; | 138 error_cb_ = error_cb; |
| 135 get_time_cb_ = get_time_cb; | 139 get_time_cb_ = get_time_cb; |
| 136 get_duration_cb_ = get_duration_cb; | 140 get_duration_cb_ = get_duration_cb; |
| 137 state_ = kInitializing; | 141 state_ = kInitializing; |
| 138 | 142 |
| 139 video_frame_stream_->Initialize( | 143 video_frame_stream_->Initialize( |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 frames_decoded_++; | 289 frames_decoded_++; |
| 286 frames_dropped_++; | 290 frames_dropped_++; |
| 287 | 291 |
| 288 task_runner_->PostTask( | 292 task_runner_->PostTask( |
| 289 FROM_HERE, | 293 FROM_HERE, |
| 290 base::Bind(&VideoRendererImpl::AttemptRead, weak_factory_.GetWeakPtr())); | 294 base::Bind(&VideoRendererImpl::AttemptRead, weak_factory_.GetWeakPtr())); |
| 291 } | 295 } |
| 292 | 296 |
| 293 void VideoRendererImpl::FrameReady(VideoFrameStream::Status status, | 297 void VideoRendererImpl::FrameReady(VideoFrameStream::Status status, |
| 294 const scoped_refptr<VideoFrame>& frame) { | 298 const scoped_refptr<VideoFrame>& frame) { |
| 299 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 295 base::AutoLock auto_lock(lock_); | 300 base::AutoLock auto_lock(lock_); |
| 296 DCHECK_NE(state_, kUninitialized); | 301 DCHECK_NE(state_, kUninitialized); |
| 297 DCHECK_NE(state_, kFlushed); | 302 DCHECK_NE(state_, kFlushed); |
| 298 | 303 |
| 299 CHECK(pending_read_); | 304 CHECK(pending_read_); |
| 300 pending_read_ = false; | 305 pending_read_ = false; |
| 301 | 306 |
| 302 if (status == VideoFrameStream::DECODE_ERROR || | 307 if (status == VideoFrameStream::DECODE_ERROR || |
| 303 status == VideoFrameStream::DECRYPT_ERROR) { | 308 status == VideoFrameStream::DECRYPT_ERROR) { |
| 304 DCHECK(!frame.get()); | 309 DCHECK(!frame.get()); |
| 305 PipelineStatus error = PIPELINE_ERROR_DECODE; | 310 PipelineStatus error = PIPELINE_ERROR_DECODE; |
| 306 if (status == VideoFrameStream::DECRYPT_ERROR) | 311 if (status == VideoFrameStream::DECRYPT_ERROR) |
| 307 error = PIPELINE_ERROR_DECRYPT; | 312 error = PIPELINE_ERROR_DECRYPT; |
| 308 error_cb_.Run(error); | 313 task_runner_->PostTask(FROM_HERE, base::Bind(error_cb_, error)); |
| 309 return; | 314 return; |
| 310 } | 315 } |
| 311 | 316 |
| 312 // Already-queued VideoFrameStream ReadCB's can fire after various state | 317 // Already-queued VideoFrameStream ReadCB's can fire after various state |
| 313 // transitions have happened; in that case just drop those frames immediately. | 318 // transitions have happened; in that case just drop those frames immediately. |
| 314 if (state_ == kFlushing) | 319 if (state_ == kFlushing) |
| 315 return; | 320 return; |
| 316 | 321 |
| 317 DCHECK_EQ(state_, kPlaying); | 322 DCHECK_EQ(state_, kPlaying); |
| 318 | 323 |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 task_runner_->PostTask(FROM_HERE, base::Bind(statistics_cb_, statistics)); | 474 task_runner_->PostTask(FROM_HERE, base::Bind(statistics_cb_, statistics)); |
| 470 | 475 |
| 471 frames_decoded_ = 0; | 476 frames_decoded_ = 0; |
| 472 frames_dropped_ = 0; | 477 frames_dropped_ = 0; |
| 473 } | 478 } |
| 474 | 479 |
| 475 frame_available_.TimedWait(wait_duration); | 480 frame_available_.TimedWait(wait_duration); |
| 476 } | 481 } |
| 477 | 482 |
| 478 } // namespace media | 483 } // namespace media |
| OLD | NEW |