OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_base.h" | 5 #include "media/filters/video_renderer_base.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/threading/platform_thread.h" | 10 #include "base/threading/platform_thread.h" |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 decoder_ = decoder; | 130 decoder_ = decoder; |
131 | 131 |
132 statistics_cb_ = statistics_cb; | 132 statistics_cb_ = statistics_cb; |
133 time_cb_ = time_cb; | 133 time_cb_ = time_cb; |
134 size_changed_cb_ = size_changed_cb; | 134 size_changed_cb_ = size_changed_cb; |
135 ended_cb_ = ended_cb; | 135 ended_cb_ = ended_cb; |
136 error_cb_ = error_cb; | 136 error_cb_ = error_cb; |
137 get_time_cb_ = get_time_cb; | 137 get_time_cb_ = get_time_cb; |
138 get_duration_cb_ = get_duration_cb; | 138 get_duration_cb_ = get_duration_cb; |
139 | 139 |
140 // Notify the pipeline of the video dimensions. | |
141 size_changed_cb_.Run(decoder_->natural_size()); | |
142 | |
143 // We're all good! Consider ourselves flushed. (ThreadMain() should never | 140 // We're all good! Consider ourselves flushed. (ThreadMain() should never |
144 // see us in the kUninitialized state). | 141 // see us in the kUninitialized state). |
145 // Since we had an initial Preroll(), we consider ourself flushed, because we | 142 // Since we had an initial Preroll(), we consider ourself flushed, because we |
146 // have not populated any buffers yet. | 143 // have not populated any buffers yet. |
147 state_ = kFlushed; | 144 state_ = kFlushed; |
148 | 145 |
149 set_opaque_cb_.Run(!decoder->HasAlpha()); | 146 set_opaque_cb_.Run(!decoder->HasAlpha()); |
150 set_opaque_cb_.Reset(); | 147 set_opaque_cb_.Reset(); |
151 | 148 |
152 // Create our video thread. | 149 // Create our video thread. |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 continue; | 290 continue; |
294 } | 291 } |
295 | 292 |
296 | 293 |
297 // Congratulations! You've made it past the video frame timing gauntlet. | 294 // Congratulations! You've made it past the video frame timing gauntlet. |
298 // | 295 // |
299 // We can now safely update the current frame, request another frame, and | 296 // We can now safely update the current frame, request another frame, and |
300 // signal to the client that a new frame is available. | 297 // signal to the client that a new frame is available. |
301 DCHECK(!pending_paint_); | 298 DCHECK(!pending_paint_); |
302 DCHECK(!ready_frames_.empty()); | 299 DCHECK(!ready_frames_.empty()); |
303 current_frame_ = ready_frames_.front(); | 300 SetCurrentFrameToNextReadyFrame(); |
304 ready_frames_.pop_front(); | |
305 AttemptRead_Locked(); | 301 AttemptRead_Locked(); |
306 | 302 |
307 base::AutoUnlock auto_unlock(lock_); | 303 base::AutoUnlock auto_unlock(lock_); |
308 paint_cb_.Run(); | 304 paint_cb_.Run(); |
309 } | 305 } |
310 } | 306 } |
311 | 307 |
| 308 void VideoRendererBase::SetCurrentFrameToNextReadyFrame() { |
| 309 current_frame_ = ready_frames_.front(); |
| 310 ready_frames_.pop_front(); |
| 311 |
| 312 // Notify the pipeline of natural_size() changes. |
| 313 const gfx::Size& natural_size = current_frame_->natural_size(); |
| 314 if (natural_size != last_natural_size_) { |
| 315 size_changed_cb_.Run(natural_size); |
| 316 last_natural_size_ = natural_size; |
| 317 } |
| 318 } |
| 319 |
312 void VideoRendererBase::GetCurrentFrame(scoped_refptr<VideoFrame>* frame_out) { | 320 void VideoRendererBase::GetCurrentFrame(scoped_refptr<VideoFrame>* frame_out) { |
313 base::AutoLock auto_lock(lock_); | 321 base::AutoLock auto_lock(lock_); |
314 DCHECK(!pending_paint_ && !pending_paint_with_last_available_); | 322 DCHECK(!pending_paint_ && !pending_paint_with_last_available_); |
315 | 323 |
316 if ((!current_frame_ || current_frame_->IsEndOfStream()) && | 324 if ((!current_frame_ || current_frame_->IsEndOfStream()) && |
317 (!last_available_frame_ || last_available_frame_->IsEndOfStream())) { | 325 (!last_available_frame_ || last_available_frame_->IsEndOfStream())) { |
318 *frame_out = NULL; | 326 *frame_out = NULL; |
319 return; | 327 return; |
320 } | 328 } |
321 | 329 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 | 458 |
451 // If we're at capacity or end of stream while prerolling we need to | 459 // If we're at capacity or end of stream while prerolling we need to |
452 // transition to prerolled. | 460 // transition to prerolled. |
453 if (state_ == kPrerolling) { | 461 if (state_ == kPrerolling) { |
454 DCHECK(!current_frame_); | 462 DCHECK(!current_frame_); |
455 state_ = kPrerolled; | 463 state_ = kPrerolled; |
456 | 464 |
457 // Because we might remain in the prerolled state for an undetermined amount | 465 // Because we might remain in the prerolled state for an undetermined amount |
458 // of time (i.e., we were not playing before we started prerolling), we'll | 466 // of time (i.e., we were not playing before we started prerolling), we'll |
459 // manually update the current frame and notify the subclass below. | 467 // manually update the current frame and notify the subclass below. |
460 if (!ready_frames_.front()->IsEndOfStream()) { | 468 if (!ready_frames_.front()->IsEndOfStream()) |
461 current_frame_ = ready_frames_.front(); | 469 SetCurrentFrameToNextReadyFrame(); |
462 ready_frames_.pop_front(); | |
463 } | |
464 | 470 |
465 // ...and we're done prerolling! | 471 // ...and we're done prerolling! |
466 DCHECK(!preroll_cb_.is_null()); | 472 DCHECK(!preroll_cb_.is_null()); |
467 base::ResetAndReturn(&preroll_cb_).Run(PIPELINE_OK); | 473 base::ResetAndReturn(&preroll_cb_).Run(PIPELINE_OK); |
468 | 474 |
469 base::AutoUnlock ul(lock_); | 475 base::AutoUnlock ul(lock_); |
470 paint_cb_.Run(); | 476 paint_cb_.Run(); |
471 } | 477 } |
472 } | 478 } |
473 | 479 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 | 557 |
552 int VideoRendererBase::NumFrames_Locked() const { | 558 int VideoRendererBase::NumFrames_Locked() const { |
553 lock_.AssertAcquired(); | 559 lock_.AssertAcquired(); |
554 int outstanding_frames = | 560 int outstanding_frames = |
555 (current_frame_ ? 1 : 0) + (last_available_frame_ ? 1 : 0) + | 561 (current_frame_ ? 1 : 0) + (last_available_frame_ ? 1 : 0) + |
556 (current_frame_ && (current_frame_ == last_available_frame_) ? -1 : 0); | 562 (current_frame_ && (current_frame_ == last_available_frame_) ? -1 : 0); |
557 return ready_frames_.size() + outstanding_frames; | 563 return ready_frames_.size() + outstanding_frames; |
558 } | 564 } |
559 | 565 |
560 } // namespace media | 566 } // namespace media |
OLD | NEW |