| 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 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 // Texture in display. Postpone deletion until after it's returned to us. | 418 // Texture in display. Postpone deletion until after it's returned to us. |
| 419 bool inserted = dismissed_picture_buffers_.insert(std::make_pair( | 419 bool inserted = dismissed_picture_buffers_.insert(std::make_pair( |
| 420 id, buffer_to_dismiss)).second; | 420 id, buffer_to_dismiss)).second; |
| 421 DCHECK(inserted); | 421 DCHECK(inserted); |
| 422 } | 422 } |
| 423 } | 423 } |
| 424 | 424 |
| 425 static void ReadPixelsSyncInner( | 425 static void ReadPixelsSyncInner( |
| 426 const scoped_refptr<media::GpuVideoAcceleratorFactories>& factories, | 426 const scoped_refptr<media::GpuVideoAcceleratorFactories>& factories, |
| 427 uint32 texture_id, | 427 uint32 texture_id, |
| 428 const gfx::Rect& visible_rect, | 428 const scoped_refptr<VideoFrame>& frame, |
| 429 const SkBitmap& pixels, | 429 const SkBitmap& pixels, |
| 430 base::WaitableEvent* event) { | 430 base::WaitableEvent* event) { |
| 431 factories->ReadPixels(texture_id, visible_rect, pixels); | 431 factories->ReadPixels(texture_id, frame, pixels); |
| 432 event->Signal(); | 432 event->Signal(); |
| 433 } | 433 } |
| 434 | 434 |
| 435 static void ReadPixelsSync( | 435 static void ReadPixelsSync( |
| 436 const scoped_refptr<media::GpuVideoAcceleratorFactories>& factories, | 436 const scoped_refptr<media::GpuVideoAcceleratorFactories>& factories, |
| 437 uint32 texture_id, | 437 uint32 texture_id, |
| 438 const gfx::Rect& visible_rect, | 438 const scoped_refptr<VideoFrame>& frame, |
| 439 const SkBitmap& pixels) { | 439 const SkBitmap& pixels) { |
| 440 base::WaitableEvent event(true, false); | 440 base::WaitableEvent event(true, false); |
| 441 if (!factories->GetTaskRunner()->PostTask(FROM_HERE, | 441 if (!factories->GetTaskRunner()->PostTask(FROM_HERE, |
| 442 base::Bind(&ReadPixelsSyncInner, | 442 base::Bind(&ReadPixelsSyncInner, |
| 443 factories, | 443 factories, |
| 444 texture_id, | 444 texture_id, |
| 445 visible_rect, | 445 frame, |
| 446 pixels, | 446 pixels, |
| 447 &event))) | 447 &event))) |
| 448 return; | 448 return; |
| 449 event.Wait(); | 449 event.Wait(); |
| 450 } | 450 } |
| 451 | 451 |
| 452 void GpuVideoDecoder::PictureReady(const media::Picture& picture) { | 452 void GpuVideoDecoder::PictureReady(const media::Picture& picture) { |
| 453 DVLOG(3) << "PictureReady()"; | 453 DVLOG(3) << "PictureReady()"; |
| 454 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); | 454 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); |
| 455 | 455 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 473 scoped_refptr<VideoFrame> frame(VideoFrame::WrapNativeTexture( | 473 scoped_refptr<VideoFrame> frame(VideoFrame::WrapNativeTexture( |
| 474 make_scoped_ptr(new gpu::MailboxHolder( | 474 make_scoped_ptr(new gpu::MailboxHolder( |
| 475 pb.texture_mailbox(), decoder_texture_target_, 0 /* sync_point */)), | 475 pb.texture_mailbox(), decoder_texture_target_, 0 /* sync_point */)), |
| 476 BindToCurrentLoop(base::Bind(&GpuVideoDecoder::ReusePictureBuffer, | 476 BindToCurrentLoop(base::Bind(&GpuVideoDecoder::ReusePictureBuffer, |
| 477 weak_this_, | 477 weak_this_, |
| 478 picture.picture_buffer_id())), | 478 picture.picture_buffer_id())), |
| 479 pb.size(), | 479 pb.size(), |
| 480 visible_rect, | 480 visible_rect, |
| 481 natural_size, | 481 natural_size, |
| 482 timestamp, | 482 timestamp, |
| 483 base::Bind(&ReadPixelsSync, factories_, pb.texture_id(), visible_rect))); | 483 base::Bind(&ReadPixelsSync, factories_, pb.texture_id()))); |
| 484 CHECK_GT(available_pictures_, 0); | 484 CHECK_GT(available_pictures_, 0); |
| 485 --available_pictures_; | 485 --available_pictures_; |
| 486 bool inserted = | 486 bool inserted = |
| 487 picture_buffers_at_display_.insert(picture.picture_buffer_id()).second; | 487 picture_buffers_at_display_.insert(picture.picture_buffer_id()).second; |
| 488 DCHECK(inserted); | 488 DCHECK(inserted); |
| 489 | 489 |
| 490 EnqueueFrameAndTriggerFrameDelivery(frame); | 490 EnqueueFrameAndTriggerFrameDelivery(frame); |
| 491 } | 491 } |
| 492 | 492 |
| 493 void GpuVideoDecoder::EnqueueFrameAndTriggerFrameDelivery( | 493 void GpuVideoDecoder::EnqueueFrameAndTriggerFrameDelivery( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 507 if (pending_decode_cb_.is_null()) | 507 if (pending_decode_cb_.is_null()) |
| 508 return; | 508 return; |
| 509 | 509 |
| 510 base::ResetAndReturn(&pending_decode_cb_) | 510 base::ResetAndReturn(&pending_decode_cb_) |
| 511 .Run(kOk, ready_video_frames_.front()); | 511 .Run(kOk, ready_video_frames_.front()); |
| 512 ready_video_frames_.pop_front(); | 512 ready_video_frames_.pop_front(); |
| 513 } | 513 } |
| 514 | 514 |
| 515 void GpuVideoDecoder::ReusePictureBuffer( | 515 void GpuVideoDecoder::ReusePictureBuffer( |
| 516 int64 picture_buffer_id, | 516 int64 picture_buffer_id, |
| 517 scoped_ptr<gpu::MailboxHolder> mailbox_holder) { | 517 scoped_ptr<gpu::MailboxHolder> mailbox_holder, |
| 518 const std::vector<uint32>& release_sync_points) { |
| 518 DVLOG(3) << "ReusePictureBuffer(" << picture_buffer_id << ")"; | 519 DVLOG(3) << "ReusePictureBuffer(" << picture_buffer_id << ")"; |
| 519 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); | 520 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); |
| 520 | 521 |
| 521 if (!vda_) | 522 if (!vda_) |
| 522 return; | 523 return; |
| 523 | 524 |
| 524 CHECK(!picture_buffers_at_display_.empty()); | 525 CHECK(!picture_buffers_at_display_.empty()); |
| 525 | 526 |
| 526 size_t num_erased = picture_buffers_at_display_.erase(picture_buffer_id); | 527 size_t num_erased = picture_buffers_at_display_.erase(picture_buffer_id); |
| 527 DCHECK(num_erased); | 528 DCHECK(num_erased); |
| 528 | 529 |
| 529 PictureBufferMap::iterator it = | 530 PictureBufferMap::iterator it = |
| 530 assigned_picture_buffers_.find(picture_buffer_id); | 531 assigned_picture_buffers_.find(picture_buffer_id); |
| 531 | 532 |
| 532 if (it == assigned_picture_buffers_.end()) { | 533 if (it == assigned_picture_buffers_.end()) { |
| 533 // This picture was dismissed while in display, so we postponed deletion. | 534 // This picture was dismissed while in display, so we postponed deletion. |
| 534 it = dismissed_picture_buffers_.find(picture_buffer_id); | 535 it = dismissed_picture_buffers_.find(picture_buffer_id); |
| 535 DCHECK(it != dismissed_picture_buffers_.end()); | 536 DCHECK(it != dismissed_picture_buffers_.end()); |
| 536 factories_->DeleteTexture(it->second.texture_id()); | 537 factories_->DeleteTexture(it->second.texture_id()); |
| 537 dismissed_picture_buffers_.erase(it); | 538 dismissed_picture_buffers_.erase(it); |
| 538 return; | 539 return; |
| 539 } | 540 } |
| 540 | 541 |
| 541 factories_->WaitSyncPoint(mailbox_holder->sync_point); | 542 for (size_t i = 0; i < release_sync_points.size(); i++) |
| 543 factories_->WaitSyncPoint(release_sync_points[i]); |
| 544 |
| 542 ++available_pictures_; | 545 ++available_pictures_; |
| 543 | 546 |
| 544 vda_->ReusePictureBuffer(picture_buffer_id); | 547 vda_->ReusePictureBuffer(picture_buffer_id); |
| 545 } | 548 } |
| 546 | 549 |
| 547 GpuVideoDecoder::SHMBuffer* GpuVideoDecoder::GetSHM(size_t min_size) { | 550 GpuVideoDecoder::SHMBuffer* GpuVideoDecoder::GetSHM(size_t min_size) { |
| 548 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); | 551 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); |
| 549 if (available_shm_segments_.empty() || | 552 if (available_shm_segments_.empty() || |
| 550 available_shm_segments_.back()->size < min_size) { | 553 available_shm_segments_.back()->size < min_size) { |
| 551 size_t size_to_allocate = std::max(min_size, kSharedMemorySegmentBytes); | 554 size_t size_to_allocate = std::max(min_size, kSharedMemorySegmentBytes); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 645 return; | 648 return; |
| 646 } | 649 } |
| 647 } | 650 } |
| 648 | 651 |
| 649 void GpuVideoDecoder::DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent() | 652 void GpuVideoDecoder::DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent() |
| 650 const { | 653 const { |
| 651 DCHECK(factories_->GetTaskRunner()->BelongsToCurrentThread()); | 654 DCHECK(factories_->GetTaskRunner()->BelongsToCurrentThread()); |
| 652 } | 655 } |
| 653 | 656 |
| 654 } // namespace media | 657 } // namespace media |
| OLD | NEW |