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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 DCHECK(config.IsValidConfig()); | 147 DCHECK(config.IsValidConfig()); |
148 DCHECK(!config.is_encrypted()); | 148 DCHECK(!config.is_encrypted()); |
149 | 149 |
150 weak_this_ = weak_factory_.GetWeakPtr(); | 150 weak_this_ = weak_factory_.GetWeakPtr(); |
151 | 151 |
152 PipelineStatusCB status_cb = | 152 PipelineStatusCB status_cb = |
153 base::Bind(&ReportGpuVideoDecoderInitializeStatusToUMAAndRunCB, | 153 base::Bind(&ReportGpuVideoDecoderInitializeStatusToUMAAndRunCB, |
154 BindToCurrentLoop(orig_status_cb)); | 154 BindToCurrentLoop(orig_status_cb)); |
155 | 155 |
156 bool previously_initialized = config_.IsValidConfig(); | 156 bool previously_initialized = config_.IsValidConfig(); |
157 #if !defined(OS_CHROMEOS) && !defined(OS_WIN) | 157 #if !defined(OS_CHROMEOS) && !defined(OS_WIN) && \ |
| 158 !(defined(OS_LINUX) && defined(ARCH_CPU_X86_FAMILY) && defined(USE_X11)) |
158 if (previously_initialized) { | 159 if (previously_initialized) { |
159 // TODO(xhwang): Make GpuVideoDecoder reinitializable. | 160 // TODO(xhwang): Make GpuVideoDecoder reinitializable. |
160 // See http://crbug.com/233608 | 161 // See http://crbug.com/233608 |
161 DVLOG(1) << "GpuVideoDecoder reinitialization not supported."; | 162 DVLOG(1) << "GpuVideoDecoder reinitialization not supported."; |
162 status_cb.Run(DECODER_ERROR_NOT_SUPPORTED); | 163 status_cb.Run(DECODER_ERROR_NOT_SUPPORTED); |
163 return; | 164 return; |
164 } | 165 } |
165 #endif | 166 #endif |
166 DVLOG(1) << "(Re)initializing GVD with config: " | 167 DVLOG(1) << "(Re)initializing GVD with config: " |
167 << config.AsHumanReadableString(); | 168 << config.AsHumanReadableString(); |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 } else { | 418 } else { |
418 // Texture in display. Postpone deletion until after it's returned to us. | 419 // Texture in display. Postpone deletion until after it's returned to us. |
419 bool inserted = dismissed_picture_buffers_.insert(std::make_pair( | 420 bool inserted = dismissed_picture_buffers_.insert(std::make_pair( |
420 id, buffer_to_dismiss)).second; | 421 id, buffer_to_dismiss)).second; |
421 DCHECK(inserted); | 422 DCHECK(inserted); |
422 } | 423 } |
423 } | 424 } |
424 | 425 |
425 static void ReadPixelsSyncInner( | 426 static void ReadPixelsSyncInner( |
426 const scoped_refptr<media::GpuVideoAcceleratorFactories>& factories, | 427 const scoped_refptr<media::GpuVideoAcceleratorFactories>& factories, |
427 uint32 texture_id, | 428 const scoped_refptr<VideoFrame>& frame, |
428 const gfx::Rect& visible_rect, | |
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(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 const scoped_refptr<VideoFrame>& frame, |
438 const gfx::Rect& visible_rect, | |
439 const SkBitmap& pixels) { | 438 const SkBitmap& pixels) { |
440 base::WaitableEvent event(true, false); | 439 base::WaitableEvent event(true, false); |
441 if (!factories->GetTaskRunner()->PostTask(FROM_HERE, | 440 if (!factories->GetTaskRunner()->PostTask( |
442 base::Bind(&ReadPixelsSyncInner, | 441 FROM_HERE, |
443 factories, | 442 base::Bind(&ReadPixelsSyncInner, factories, frame, pixels, &event))) |
444 texture_id, | |
445 visible_rect, | |
446 pixels, | |
447 &event))) | |
448 return; | 443 return; |
449 event.Wait(); | 444 event.Wait(); |
450 } | 445 } |
451 | 446 |
452 void GpuVideoDecoder::PictureReady(const media::Picture& picture) { | 447 void GpuVideoDecoder::PictureReady(const media::Picture& picture) { |
453 DVLOG(3) << "PictureReady()"; | 448 DVLOG(3) << "PictureReady()"; |
454 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); | 449 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); |
455 | 450 |
456 PictureBufferMap::iterator it = | 451 PictureBufferMap::iterator it = |
457 assigned_picture_buffers_.find(picture.picture_buffer_id()); | 452 assigned_picture_buffers_.find(picture.picture_buffer_id()); |
(...skipping 15 matching lines...) Expand all Loading... |
473 scoped_refptr<VideoFrame> frame(VideoFrame::WrapNativeTexture( | 468 scoped_refptr<VideoFrame> frame(VideoFrame::WrapNativeTexture( |
474 make_scoped_ptr(new gpu::MailboxHolder( | 469 make_scoped_ptr(new gpu::MailboxHolder( |
475 pb.texture_mailbox(), decoder_texture_target_, 0 /* sync_point */)), | 470 pb.texture_mailbox(), decoder_texture_target_, 0 /* sync_point */)), |
476 BindToCurrentLoop(base::Bind(&GpuVideoDecoder::ReusePictureBuffer, | 471 BindToCurrentLoop(base::Bind(&GpuVideoDecoder::ReusePictureBuffer, |
477 weak_this_, | 472 weak_this_, |
478 picture.picture_buffer_id())), | 473 picture.picture_buffer_id())), |
479 pb.size(), | 474 pb.size(), |
480 visible_rect, | 475 visible_rect, |
481 natural_size, | 476 natural_size, |
482 timestamp, | 477 timestamp, |
483 base::Bind(&ReadPixelsSync, factories_, pb.texture_id(), visible_rect))); | 478 base::Bind(&ReadPixelsSync, factories_))); |
484 CHECK_GT(available_pictures_, 0); | 479 CHECK_GT(available_pictures_, 0); |
485 --available_pictures_; | 480 --available_pictures_; |
486 bool inserted = | 481 bool inserted = |
487 picture_buffers_at_display_.insert(picture.picture_buffer_id()).second; | 482 picture_buffers_at_display_.insert(picture.picture_buffer_id()).second; |
488 DCHECK(inserted); | 483 DCHECK(inserted); |
489 | 484 |
490 EnqueueFrameAndTriggerFrameDelivery(frame); | 485 EnqueueFrameAndTriggerFrameDelivery(frame); |
491 } | 486 } |
492 | 487 |
493 void GpuVideoDecoder::EnqueueFrameAndTriggerFrameDelivery( | 488 void GpuVideoDecoder::EnqueueFrameAndTriggerFrameDelivery( |
(...skipping 13 matching lines...) Expand all Loading... |
507 if (pending_decode_cb_.is_null()) | 502 if (pending_decode_cb_.is_null()) |
508 return; | 503 return; |
509 | 504 |
510 base::ResetAndReturn(&pending_decode_cb_) | 505 base::ResetAndReturn(&pending_decode_cb_) |
511 .Run(kOk, ready_video_frames_.front()); | 506 .Run(kOk, ready_video_frames_.front()); |
512 ready_video_frames_.pop_front(); | 507 ready_video_frames_.pop_front(); |
513 } | 508 } |
514 | 509 |
515 void GpuVideoDecoder::ReusePictureBuffer( | 510 void GpuVideoDecoder::ReusePictureBuffer( |
516 int64 picture_buffer_id, | 511 int64 picture_buffer_id, |
517 scoped_ptr<gpu::MailboxHolder> mailbox_holder) { | 512 scoped_ptr<gpu::MailboxHolder> mailbox_holder, |
| 513 const std::vector<uint32>& release_sync_points) { |
518 DVLOG(3) << "ReusePictureBuffer(" << picture_buffer_id << ")"; | 514 DVLOG(3) << "ReusePictureBuffer(" << picture_buffer_id << ")"; |
519 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); | 515 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); |
520 | 516 |
521 if (!vda_) | 517 if (!vda_) |
522 return; | 518 return; |
523 | 519 |
524 CHECK(!picture_buffers_at_display_.empty()); | 520 CHECK(!picture_buffers_at_display_.empty()); |
525 | 521 |
526 size_t num_erased = picture_buffers_at_display_.erase(picture_buffer_id); | 522 size_t num_erased = picture_buffers_at_display_.erase(picture_buffer_id); |
527 DCHECK(num_erased); | 523 DCHECK(num_erased); |
528 | 524 |
529 PictureBufferMap::iterator it = | 525 PictureBufferMap::iterator it = |
530 assigned_picture_buffers_.find(picture_buffer_id); | 526 assigned_picture_buffers_.find(picture_buffer_id); |
531 | 527 |
532 if (it == assigned_picture_buffers_.end()) { | 528 if (it == assigned_picture_buffers_.end()) { |
533 // This picture was dismissed while in display, so we postponed deletion. | 529 // This picture was dismissed while in display, so we postponed deletion. |
534 it = dismissed_picture_buffers_.find(picture_buffer_id); | 530 it = dismissed_picture_buffers_.find(picture_buffer_id); |
535 DCHECK(it != dismissed_picture_buffers_.end()); | 531 DCHECK(it != dismissed_picture_buffers_.end()); |
536 factories_->DeleteTexture(it->second.texture_id()); | 532 factories_->DeleteTexture(it->second.texture_id()); |
537 dismissed_picture_buffers_.erase(it); | 533 dismissed_picture_buffers_.erase(it); |
538 return; | 534 return; |
539 } | 535 } |
540 | 536 |
541 factories_->WaitSyncPoint(mailbox_holder->sync_point); | 537 for (size_t i = 0; i < release_sync_points.size(); i++) |
| 538 factories_->WaitSyncPoint(release_sync_points[i]); |
| 539 |
542 ++available_pictures_; | 540 ++available_pictures_; |
543 | 541 |
544 vda_->ReusePictureBuffer(picture_buffer_id); | 542 vda_->ReusePictureBuffer(picture_buffer_id); |
545 } | 543 } |
546 | 544 |
547 GpuVideoDecoder::SHMBuffer* GpuVideoDecoder::GetSHM(size_t min_size) { | 545 GpuVideoDecoder::SHMBuffer* GpuVideoDecoder::GetSHM(size_t min_size) { |
548 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); | 546 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); |
549 if (available_shm_segments_.empty() || | 547 if (available_shm_segments_.empty() || |
550 available_shm_segments_.back()->size < min_size) { | 548 available_shm_segments_.back()->size < min_size) { |
551 size_t size_to_allocate = std::max(min_size, kSharedMemorySegmentBytes); | 549 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; | 643 return; |
646 } | 644 } |
647 } | 645 } |
648 | 646 |
649 void GpuVideoDecoder::DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent() | 647 void GpuVideoDecoder::DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent() |
650 const { | 648 const { |
651 DCHECK(factories_->GetTaskRunner()->BelongsToCurrentThread()); | 649 DCHECK(factories_->GetTaskRunner()->BelongsToCurrentThread()); |
652 } | 650 } |
653 | 651 |
654 } // namespace media | 652 } // namespace media |
OLD | NEW |