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/gpu_video_decoder.h" | 5 #include "media/filters/gpu_video_decoder.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 | 434 |
435 // Update frame's timestamp. | 435 // Update frame's timestamp. |
436 base::TimeDelta timestamp; | 436 base::TimeDelta timestamp; |
437 gfx::Rect visible_rect; | 437 gfx::Rect visible_rect; |
438 gfx::Size natural_size; | 438 gfx::Size natural_size; |
439 GetBufferData(picture.bitstream_buffer_id(), ×tamp, &visible_rect, | 439 GetBufferData(picture.bitstream_buffer_id(), ×tamp, &visible_rect, |
440 &natural_size); | 440 &natural_size); |
441 DCHECK(decoder_texture_target_); | 441 DCHECK(decoder_texture_target_); |
442 | 442 |
443 scoped_refptr<VideoFrame> frame(VideoFrame::WrapNativeTexture( | 443 scoped_refptr<VideoFrame> frame(VideoFrame::WrapNativeTexture( |
444 make_scoped_ptr(new VideoFrame::MailboxHolder( | 444 make_scoped_ptr(new gpu::MailboxHolder( |
445 pb.texture_mailbox(), | 445 pb.texture_mailbox(), decoder_texture_target_, 0 /* sync_point */)), |
446 0, // sync_point | 446 BindToCurrentLoop(base::Bind(&GpuVideoDecoder::ReusePictureBuffer, |
447 BindToCurrentLoop(base::Bind(&GpuVideoDecoder::ReusePictureBuffer, | 447 weak_this_, |
448 weak_this_, | 448 picture.picture_buffer_id())), |
449 picture.picture_buffer_id())))), | |
450 decoder_texture_target_, | |
451 pb.size(), | 449 pb.size(), |
452 visible_rect, | 450 visible_rect, |
453 natural_size, | 451 natural_size, |
454 timestamp, | 452 timestamp, |
455 base::Bind(&GpuVideoAcceleratorFactories::ReadPixels, | 453 base::Bind(&GpuVideoAcceleratorFactories::ReadPixels, |
456 factories_, | 454 factories_, |
457 pb.texture_id(), | 455 pb.texture_id(), |
458 gfx::Size(visible_rect.width(), visible_rect.height())), | 456 gfx::Size(visible_rect.width(), visible_rect.height())))); |
459 base::Closure())); | |
460 CHECK_GT(available_pictures_, 0); | 457 CHECK_GT(available_pictures_, 0); |
461 --available_pictures_; | 458 --available_pictures_; |
462 bool inserted = | 459 bool inserted = |
463 picture_buffers_at_display_.insert(picture.picture_buffer_id()).second; | 460 picture_buffers_at_display_.insert(picture.picture_buffer_id()).second; |
464 DCHECK(inserted); | 461 DCHECK(inserted); |
465 | 462 |
466 EnqueueFrameAndTriggerFrameDelivery(frame); | 463 EnqueueFrameAndTriggerFrameDelivery(frame); |
467 } | 464 } |
468 | 465 |
469 void GpuVideoDecoder::EnqueueFrameAndTriggerFrameDelivery( | 466 void GpuVideoDecoder::EnqueueFrameAndTriggerFrameDelivery( |
(...skipping 11 matching lines...) Expand all Loading... |
481 DCHECK(!ready_video_frames_.empty()); | 478 DCHECK(!ready_video_frames_.empty()); |
482 | 479 |
483 if (pending_decode_cb_.is_null()) | 480 if (pending_decode_cb_.is_null()) |
484 return; | 481 return; |
485 | 482 |
486 base::ResetAndReturn(&pending_decode_cb_) | 483 base::ResetAndReturn(&pending_decode_cb_) |
487 .Run(kOk, ready_video_frames_.front()); | 484 .Run(kOk, ready_video_frames_.front()); |
488 ready_video_frames_.pop_front(); | 485 ready_video_frames_.pop_front(); |
489 } | 486 } |
490 | 487 |
491 void GpuVideoDecoder::ReusePictureBuffer(int64 picture_buffer_id, | 488 void GpuVideoDecoder::ReusePictureBuffer( |
492 uint32 sync_point) { | 489 int64 picture_buffer_id, |
| 490 scoped_ptr<gpu::MailboxHolder> mailbox_holder) { |
493 DVLOG(3) << "ReusePictureBuffer(" << picture_buffer_id << ")"; | 491 DVLOG(3) << "ReusePictureBuffer(" << picture_buffer_id << ")"; |
494 DCHECK(gvd_loop_proxy_->BelongsToCurrentThread()); | 492 DCHECK(gvd_loop_proxy_->BelongsToCurrentThread()); |
495 | 493 |
496 if (!vda_) | 494 if (!vda_) |
497 return; | 495 return; |
498 | 496 |
499 CHECK(!picture_buffers_at_display_.empty()); | 497 CHECK(!picture_buffers_at_display_.empty()); |
500 | 498 |
501 size_t num_erased = picture_buffers_at_display_.erase(picture_buffer_id); | 499 size_t num_erased = picture_buffers_at_display_.erase(picture_buffer_id); |
502 DCHECK(num_erased); | 500 DCHECK(num_erased); |
503 | 501 |
504 PictureBufferMap::iterator it = | 502 PictureBufferMap::iterator it = |
505 assigned_picture_buffers_.find(picture_buffer_id); | 503 assigned_picture_buffers_.find(picture_buffer_id); |
506 | 504 |
507 if (it == assigned_picture_buffers_.end()) { | 505 if (it == assigned_picture_buffers_.end()) { |
508 // This picture was dismissed while in display, so we postponed deletion. | 506 // This picture was dismissed while in display, so we postponed deletion. |
509 it = dismissed_picture_buffers_.find(picture_buffer_id); | 507 it = dismissed_picture_buffers_.find(picture_buffer_id); |
510 DCHECK(it != dismissed_picture_buffers_.end()); | 508 DCHECK(it != dismissed_picture_buffers_.end()); |
511 factories_->DeleteTexture(it->second.texture_id()); | 509 factories_->DeleteTexture(it->second.texture_id()); |
512 dismissed_picture_buffers_.erase(it); | 510 dismissed_picture_buffers_.erase(it); |
513 return; | 511 return; |
514 } | 512 } |
515 | 513 |
516 factories_->WaitSyncPoint(sync_point); | 514 factories_->WaitSyncPoint(mailbox_holder->sync_point()); |
517 ++available_pictures_; | 515 ++available_pictures_; |
518 | 516 |
519 vda_->ReusePictureBuffer(picture_buffer_id); | 517 vda_->ReusePictureBuffer(picture_buffer_id); |
520 } | 518 } |
521 | 519 |
522 GpuVideoDecoder::SHMBuffer* GpuVideoDecoder::GetSHM(size_t min_size) { | 520 GpuVideoDecoder::SHMBuffer* GpuVideoDecoder::GetSHM(size_t min_size) { |
523 DCHECK(gvd_loop_proxy_->BelongsToCurrentThread()); | 521 DCHECK(gvd_loop_proxy_->BelongsToCurrentThread()); |
524 if (available_shm_segments_.empty() || | 522 if (available_shm_segments_.empty() || |
525 available_shm_segments_.back()->size < min_size) { | 523 available_shm_segments_.back()->size < min_size) { |
526 size_t size_to_allocate = std::max(min_size, kSharedMemorySegmentBytes); | 524 size_t size_to_allocate = std::max(min_size, kSharedMemorySegmentBytes); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
615 | 613 |
616 state_ = kError; | 614 state_ = kError; |
617 | 615 |
618 if (!pending_decode_cb_.is_null()) { | 616 if (!pending_decode_cb_.is_null()) { |
619 base::ResetAndReturn(&pending_decode_cb_).Run(kDecodeError, NULL); | 617 base::ResetAndReturn(&pending_decode_cb_).Run(kDecodeError, NULL); |
620 return; | 618 return; |
621 } | 619 } |
622 } | 620 } |
623 | 621 |
624 } // namespace media | 622 } // namespace media |
OLD | NEW |