| 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" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 DCHECK(task_runner_->BelongsToCurrentThread()); | 53 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 54 base::AutoLock auto_lock(lock_); | 54 base::AutoLock auto_lock(lock_); |
| 55 DCHECK_EQ(kPrerolled, state_); | 55 DCHECK_EQ(kPrerolled, state_); |
| 56 state_ = kPlaying; | 56 state_ = kPlaying; |
| 57 callback.Run(); | 57 callback.Run(); |
| 58 } | 58 } |
| 59 | 59 |
| 60 void VideoRendererImpl::Pause(const base::Closure& callback) { | 60 void VideoRendererImpl::Pause(const base::Closure& callback) { |
| 61 DCHECK(task_runner_->BelongsToCurrentThread()); | 61 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 62 base::AutoLock auto_lock(lock_); | 62 base::AutoLock auto_lock(lock_); |
| 63 DCHECK(state_ != kUninitialized || state_ == kError); | 63 DCHECK_NE(state_, kUninitialized); |
| 64 state_ = kPaused; | 64 state_ = kPaused; |
| 65 callback.Run(); | 65 callback.Run(); |
| 66 } | 66 } |
| 67 | 67 |
| 68 void VideoRendererImpl::Flush(const base::Closure& callback) { | 68 void VideoRendererImpl::Flush(const base::Closure& callback) { |
| 69 DCHECK(task_runner_->BelongsToCurrentThread()); | 69 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 70 base::AutoLock auto_lock(lock_); | 70 base::AutoLock auto_lock(lock_); |
| 71 DCHECK_EQ(state_, kPaused); | 71 DCHECK_EQ(state_, kPaused); |
| 72 flush_cb_ = callback; | 72 flush_cb_ = callback; |
| 73 state_ = kFlushing; | 73 state_ = kFlushing; |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 return; | 205 return; |
| 206 } | 206 } |
| 207 | 207 |
| 208 // We're all good! Consider ourselves flushed. (ThreadMain() should never | 208 // We're all good! Consider ourselves flushed. (ThreadMain() should never |
| 209 // see us in the kUninitialized state). | 209 // see us in the kUninitialized state). |
| 210 // Since we had an initial Preroll(), we consider ourself flushed, because we | 210 // Since we had an initial Preroll(), we consider ourself flushed, because we |
| 211 // have not populated any buffers yet. | 211 // have not populated any buffers yet. |
| 212 state_ = kFlushed; | 212 state_ = kFlushed; |
| 213 | 213 |
| 214 // Create our video thread. | 214 // Create our video thread. |
| 215 if (!base::PlatformThread::Create(0, this, &thread_)) { | 215 CHECK(base::PlatformThread::Create(0, this, &thread_)); |
| 216 NOTREACHED() << "Video thread creation failed"; | |
| 217 state_ = kError; | |
| 218 base::ResetAndReturn(&init_cb_).Run(PIPELINE_ERROR_INITIALIZATION_FAILED); | |
| 219 return; | |
| 220 } | |
| 221 | 216 |
| 222 #if defined(OS_WIN) | 217 #if defined(OS_WIN) |
| 223 // Bump up our priority so our sleeping is more accurate. | 218 // Bump up our priority so our sleeping is more accurate. |
| 224 // TODO(scherkus): find out if this is necessary, but it seems to help. | 219 // TODO(scherkus): find out if this is necessary, but it seems to help. |
| 225 ::SetThreadPriority(thread_.platform_handle(), THREAD_PRIORITY_ABOVE_NORMAL); | 220 ::SetThreadPriority(thread_.platform_handle(), THREAD_PRIORITY_ABOVE_NORMAL); |
| 226 #endif // defined(OS_WIN) | 221 #endif // defined(OS_WIN) |
| 227 base::ResetAndReturn(&init_cb_).Run(PIPELINE_OK); | 222 base::ResetAndReturn(&init_cb_).Run(PIPELINE_OK); |
| 228 } | 223 } |
| 229 | 224 |
| 230 // PlatformThread::Delegate implementation. | 225 // PlatformThread::Delegate implementation. |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 base::ResetAndReturn(&preroll_cb_).Run(error); | 351 base::ResetAndReturn(&preroll_cb_).Run(error); |
| 357 return; | 352 return; |
| 358 } | 353 } |
| 359 | 354 |
| 360 error_cb_.Run(error); | 355 error_cb_.Run(error); |
| 361 return; | 356 return; |
| 362 } | 357 } |
| 363 | 358 |
| 364 // Already-queued VideoFrameStream ReadCB's can fire after various state | 359 // Already-queued VideoFrameStream ReadCB's can fire after various state |
| 365 // transitions have happened; in that case just drop those frames immediately. | 360 // transitions have happened; in that case just drop those frames immediately. |
| 366 if (state_ == kStopped || state_ == kError || state_ == kFlushing) | 361 if (state_ == kStopped || state_ == kFlushing) |
| 367 return; | 362 return; |
| 368 | 363 |
| 369 if (!frame.get()) { | 364 if (!frame.get()) { |
| 370 // Abort preroll early for a NULL frame because we won't get more frames. | 365 // Abort preroll early for a NULL frame because we won't get more frames. |
| 371 // A new preroll will be requested after this one completes so there is no | 366 // A new preroll will be requested after this one completes so there is no |
| 372 // point trying to collect more frames. | 367 // point trying to collect more frames. |
| 373 if (state_ == kPrerolling) | 368 if (state_ == kPrerolling) |
| 374 TransitionToPrerolled_Locked(); | 369 TransitionToPrerolled_Locked(); |
| 375 | 370 |
| 376 return; | 371 return; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 pending_read_ = true; | 456 pending_read_ = true; |
| 462 video_frame_stream_.Read(base::Bind(&VideoRendererImpl::FrameReady, | 457 video_frame_stream_.Read(base::Bind(&VideoRendererImpl::FrameReady, |
| 463 weak_factory_.GetWeakPtr())); | 458 weak_factory_.GetWeakPtr())); |
| 464 return; | 459 return; |
| 465 | 460 |
| 466 case kUninitialized: | 461 case kUninitialized: |
| 467 case kInitializing: | 462 case kInitializing: |
| 468 case kFlushing: | 463 case kFlushing: |
| 469 case kFlushed: | 464 case kFlushed: |
| 470 case kStopped: | 465 case kStopped: |
| 471 case kError: | |
| 472 return; | 466 return; |
| 473 } | 467 } |
| 474 } | 468 } |
| 475 | 469 |
| 476 void VideoRendererImpl::OnVideoFrameStreamResetDone() { | 470 void VideoRendererImpl::OnVideoFrameStreamResetDone() { |
| 477 base::AutoLock auto_lock(lock_); | 471 base::AutoLock auto_lock(lock_); |
| 478 if (state_ == kStopped) | 472 if (state_ == kStopped) |
| 479 return; | 473 return; |
| 480 | 474 |
| 481 DCHECK_EQ(kFlushing, state_); | 475 DCHECK_EQ(kFlushing, state_); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 statistics_cb_.Run(statistics); | 530 statistics_cb_.Run(statistics); |
| 537 | 531 |
| 538 frames_decoded_ = 0; | 532 frames_decoded_ = 0; |
| 539 frames_dropped_ = 0; | 533 frames_dropped_ = 0; |
| 540 } | 534 } |
| 541 | 535 |
| 542 frame_available_.TimedWait(wait_duration); | 536 frame_available_.TimedWait(wait_duration); |
| 543 } | 537 } |
| 544 | 538 |
| 545 } // namespace media | 539 } // namespace media |
| OLD | NEW |