Chromium Code Reviews| 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 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 | 70 |
| 71 GpuVideoDecoder::BufferData::~BufferData() {} | 71 GpuVideoDecoder::BufferData::~BufferData() {} |
| 72 | 72 |
| 73 GpuVideoDecoder::GpuVideoDecoder(GpuVideoAcceleratorFactories* factories, | 73 GpuVideoDecoder::GpuVideoDecoder(GpuVideoAcceleratorFactories* factories, |
| 74 const RequestSurfaceCB& request_surface_cb) | 74 const RequestSurfaceCB& request_surface_cb) |
| 75 : needs_bitstream_conversion_(false), | 75 : needs_bitstream_conversion_(false), |
| 76 factories_(factories), | 76 factories_(factories), |
| 77 state_(kNormal), | 77 state_(kNormal), |
| 78 request_surface_cb_(request_surface_cb), | 78 request_surface_cb_(request_surface_cb), |
| 79 decoder_texture_target_(0), | 79 decoder_texture_target_(0), |
| 80 pixel_format_(PIXEL_FORMAT_UNKNOWN), | |
| 80 next_picture_buffer_id_(0), | 81 next_picture_buffer_id_(0), |
| 81 next_bitstream_buffer_id_(0), | 82 next_bitstream_buffer_id_(0), |
| 82 available_pictures_(0), | 83 available_pictures_(0), |
| 83 needs_all_picture_buffers_to_decode_(false), | 84 needs_all_picture_buffers_to_decode_(false), |
| 84 supports_deferred_initialization_(false), | 85 supports_deferred_initialization_(false), |
| 85 weak_factory_(this) { | 86 weak_factory_(this) { |
| 86 DCHECK(factories_); | 87 DCHECK(factories_); |
| 87 } | 88 } |
| 88 | 89 |
| 89 void GpuVideoDecoder::Reset(const base::Closure& closure) { | 90 void GpuVideoDecoder::Reset(const base::Closure& closure) { |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 435 (!needs_all_picture_buffers_to_decode_ && available_pictures_ > 0) || | 436 (!needs_all_picture_buffers_to_decode_ && available_pictures_ > 0) || |
| 436 available_pictures_ == | 437 available_pictures_ == |
| 437 static_cast<int>(assigned_picture_buffers_.size()); | 438 static_cast<int>(assigned_picture_buffers_.size()); |
| 438 } | 439 } |
| 439 | 440 |
| 440 int GpuVideoDecoder::GetMaxDecodeRequests() const { | 441 int GpuVideoDecoder::GetMaxDecodeRequests() const { |
| 441 return kMaxInFlightDecodes; | 442 return kMaxInFlightDecodes; |
| 442 } | 443 } |
| 443 | 444 |
| 444 void GpuVideoDecoder::ProvidePictureBuffers(uint32_t count, | 445 void GpuVideoDecoder::ProvidePictureBuffers(uint32_t count, |
| 446 VideoPixelFormat format, | |
| 445 uint32_t textures_per_buffer, | 447 uint32_t textures_per_buffer, |
| 446 const gfx::Size& size, | 448 const gfx::Size& size, |
| 447 uint32_t texture_target) { | 449 uint32_t texture_target) { |
| 448 DVLOG(3) << "ProvidePictureBuffers(" << count << ", " | 450 DVLOG(3) << "ProvidePictureBuffers(" << count << ", " |
| 449 << size.width() << "x" << size.height() << ")"; | 451 << size.width() << "x" << size.height() << ")"; |
| 450 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); | 452 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); |
| 451 | 453 |
| 452 std::vector<uint32_t> texture_ids; | 454 std::vector<uint32_t> texture_ids; |
| 453 std::vector<gpu::Mailbox> texture_mailboxes; | 455 std::vector<gpu::Mailbox> texture_mailboxes; |
| 454 decoder_texture_target_ = texture_target; | 456 decoder_texture_target_ = texture_target; |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 477 | 479 |
| 478 picture_buffers.push_back( | 480 picture_buffers.push_back( |
| 479 PictureBuffer(next_picture_buffer_id_++, size, ids, mailboxes)); | 481 PictureBuffer(next_picture_buffer_id_++, size, ids, mailboxes)); |
| 480 bool inserted = assigned_picture_buffers_.insert(std::make_pair( | 482 bool inserted = assigned_picture_buffers_.insert(std::make_pair( |
| 481 picture_buffers.back().id(), picture_buffers.back())).second; | 483 picture_buffers.back().id(), picture_buffers.back())).second; |
| 482 DCHECK(inserted); | 484 DCHECK(inserted); |
| 483 } | 485 } |
| 484 | 486 |
| 485 available_pictures_ += count; | 487 available_pictures_ += count; |
| 486 | 488 |
| 489 pixel_format_ = format; | |
|
Pawel Osciak
2016/05/18 07:32:31
We may have more than one set of buffers with diff
liberato (no reviews please)
2016/05/18 14:49:27
+1. the renderer factory memorizes RGBA right now,
| |
| 490 | |
| 491 if (pixel_format_ == PIXEL_FORMAT_UNKNOWN) { | |
| 492 pixel_format_ = | |
| 493 IsOpaque(config_.format()) ? PIXEL_FORMAT_XRGB : PIXEL_FORMAT_ARGB; | |
| 494 } | |
| 495 | |
| 487 vda_->AssignPictureBuffers(picture_buffers); | 496 vda_->AssignPictureBuffers(picture_buffers); |
| 488 } | 497 } |
| 489 | 498 |
| 490 void GpuVideoDecoder::DismissPictureBuffer(int32_t id) { | 499 void GpuVideoDecoder::DismissPictureBuffer(int32_t id) { |
| 491 DVLOG(3) << "DismissPictureBuffer(" << id << ")"; | 500 DVLOG(3) << "DismissPictureBuffer(" << id << ")"; |
| 492 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); | 501 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); |
| 493 | 502 |
| 494 PictureBufferMap::iterator it = assigned_picture_buffers_.find(id); | 503 PictureBufferMap::iterator it = assigned_picture_buffers_.find(id); |
| 495 if (it == assigned_picture_buffers_.end()) { | 504 if (it == assigned_picture_buffers_.end()) { |
| 496 NOTREACHED() << "Missing picture buffer: " << id; | 505 NOTREACHED() << "Missing picture buffer: " << id; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 549 visible_rect = picture.visible_rect(); | 558 visible_rect = picture.visible_rect(); |
| 550 } | 559 } |
| 551 if (!gfx::Rect(pb.size()).Contains(visible_rect)) { | 560 if (!gfx::Rect(pb.size()).Contains(visible_rect)) { |
| 552 LOG(WARNING) << "Visible size " << visible_rect.ToString() | 561 LOG(WARNING) << "Visible size " << visible_rect.ToString() |
| 553 << " is larger than coded size " << pb.size().ToString(); | 562 << " is larger than coded size " << pb.size().ToString(); |
| 554 visible_rect = gfx::Rect(pb.size()); | 563 visible_rect = gfx::Rect(pb.size()); |
| 555 } | 564 } |
| 556 | 565 |
| 557 DCHECK(decoder_texture_target_); | 566 DCHECK(decoder_texture_target_); |
| 558 | 567 |
| 559 VideoPixelFormat pixel_format = vda_->GetOutputFormat(); | |
| 560 if (pixel_format == PIXEL_FORMAT_UNKNOWN) { | |
| 561 pixel_format = | |
| 562 IsOpaque(config_.format()) ? PIXEL_FORMAT_XRGB : PIXEL_FORMAT_ARGB; | |
| 563 } | |
| 564 | |
| 565 gpu::MailboxHolder mailbox_holders[VideoFrame::kMaxPlanes]; | 568 gpu::MailboxHolder mailbox_holders[VideoFrame::kMaxPlanes]; |
| 566 for (size_t i = 0; i < pb.texture_ids().size(); ++i) { | 569 for (size_t i = 0; i < pb.texture_ids().size(); ++i) { |
| 567 mailbox_holders[i] = gpu::MailboxHolder( | 570 mailbox_holders[i] = gpu::MailboxHolder( |
| 568 pb.texture_mailbox(i), gpu::SyncToken(), decoder_texture_target_); | 571 pb.texture_mailbox(i), gpu::SyncToken(), decoder_texture_target_); |
| 569 } | 572 } |
| 570 | 573 |
| 571 scoped_refptr<VideoFrame> frame(VideoFrame::WrapNativeTextures( | 574 scoped_refptr<VideoFrame> frame(VideoFrame::WrapNativeTextures( |
| 572 pixel_format, mailbox_holders, | 575 pixel_format_, mailbox_holders, |
| 573 base::Bind(&ReleaseMailboxTrampoline, factories_->GetTaskRunner(), | 576 base::Bind(&ReleaseMailboxTrampoline, factories_->GetTaskRunner(), |
| 574 base::Bind(&GpuVideoDecoder::ReleaseMailbox, | 577 base::Bind(&GpuVideoDecoder::ReleaseMailbox, |
| 575 weak_factory_.GetWeakPtr(), factories_, | 578 weak_factory_.GetWeakPtr(), factories_, |
| 576 picture.picture_buffer_id(), pb.texture_ids())), | 579 picture.picture_buffer_id(), pb.texture_ids())), |
| 577 pb.size(), visible_rect, natural_size, timestamp)); | 580 pb.size(), visible_rect, natural_size, timestamp)); |
| 578 if (!frame) { | 581 if (!frame) { |
| 579 DLOG(ERROR) << "Create frame failed for: " << picture.picture_buffer_id(); | 582 DLOG(ERROR) << "Create frame failed for: " << picture.picture_buffer_id(); |
| 580 NotifyError(VideoDecodeAccelerator::PLATFORM_FAILURE); | 583 NotifyError(VideoDecodeAccelerator::PLATFORM_FAILURE); |
| 581 return; | 584 return; |
| 582 } | 585 } |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 788 } | 791 } |
| 789 return false; | 792 return false; |
| 790 } | 793 } |
| 791 | 794 |
| 792 void GpuVideoDecoder::DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent() | 795 void GpuVideoDecoder::DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent() |
| 793 const { | 796 const { |
| 794 DCHECK(factories_->GetTaskRunner()->BelongsToCurrentThread()); | 797 DCHECK(factories_->GetTaskRunner()->BelongsToCurrentThread()); |
| 795 } | 798 } |
| 796 | 799 |
| 797 } // namespace media | 800 } // namespace media |
| OLD | NEW |