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 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
428 (!needs_all_picture_buffers_to_decode_ && available_pictures_ > 0) || | 429 (!needs_all_picture_buffers_to_decode_ && available_pictures_ > 0) || |
429 available_pictures_ == | 430 available_pictures_ == |
430 static_cast<int>(assigned_picture_buffers_.size()); | 431 static_cast<int>(assigned_picture_buffers_.size()); |
431 } | 432 } |
432 | 433 |
433 int GpuVideoDecoder::GetMaxDecodeRequests() const { | 434 int GpuVideoDecoder::GetMaxDecodeRequests() const { |
434 return kMaxInFlightDecodes; | 435 return kMaxInFlightDecodes; |
435 } | 436 } |
436 | 437 |
437 void GpuVideoDecoder::ProvidePictureBuffers(uint32_t count, | 438 void GpuVideoDecoder::ProvidePictureBuffers(uint32_t count, |
439 VideoPixelFormat format, | |
438 uint32_t textures_per_buffer, | 440 uint32_t textures_per_buffer, |
439 const gfx::Size& size, | 441 const gfx::Size& size, |
440 uint32_t texture_target) { | 442 uint32_t texture_target) { |
441 DVLOG(3) << "ProvidePictureBuffers(" << count << ", " | 443 DVLOG(3) << "ProvidePictureBuffers(" << count << ", " |
442 << size.width() << "x" << size.height() << ")"; | 444 << size.width() << "x" << size.height() << ")"; |
443 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); | 445 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); |
444 | 446 |
445 std::vector<uint32_t> texture_ids; | 447 std::vector<uint32_t> texture_ids; |
446 std::vector<gpu::Mailbox> texture_mailboxes; | 448 std::vector<gpu::Mailbox> texture_mailboxes; |
447 decoder_texture_target_ = texture_target; | 449 decoder_texture_target_ = texture_target; |
(...skipping 22 matching lines...) Expand all Loading... | |
470 | 472 |
471 picture_buffers.push_back( | 473 picture_buffers.push_back( |
472 PictureBuffer(next_picture_buffer_id_++, size, ids, mailboxes)); | 474 PictureBuffer(next_picture_buffer_id_++, size, ids, mailboxes)); |
473 bool inserted = assigned_picture_buffers_.insert(std::make_pair( | 475 bool inserted = assigned_picture_buffers_.insert(std::make_pair( |
474 picture_buffers.back().id(), picture_buffers.back())).second; | 476 picture_buffers.back().id(), picture_buffers.back())).second; |
475 DCHECK(inserted); | 477 DCHECK(inserted); |
476 } | 478 } |
477 | 479 |
478 available_pictures_ += count; | 480 available_pictures_ += count; |
479 | 481 |
482 if (format == PIXEL_FORMAT_UNKNOWN) { | |
483 format = IsOpaque(config_.format()) ? PIXEL_FORMAT_XRGB : PIXEL_FORMAT_ARGB; | |
484 } | |
485 | |
486 // TODO(jbauman): Move decoder_texture_target_ and pixel_format_ to the | |
487 // picture buffer. http://crbug.com/614789 | |
488 if ((pixel_format_ != PIXEL_FORMAT_UNKNOWN) && (pixel_format_ != format)) { | |
Pawel Osciak
2016/05/26 08:54:07
We should probably check for this at the beginning
| |
489 NotifyError(VideoDecodeAccelerator::PLATFORM_FAILURE); | |
490 return; | |
491 } | |
492 | |
493 pixel_format_ = format; | |
494 | |
480 vda_->AssignPictureBuffers(picture_buffers); | 495 vda_->AssignPictureBuffers(picture_buffers); |
481 } | 496 } |
482 | 497 |
483 void GpuVideoDecoder::DismissPictureBuffer(int32_t id) { | 498 void GpuVideoDecoder::DismissPictureBuffer(int32_t id) { |
484 DVLOG(3) << "DismissPictureBuffer(" << id << ")"; | 499 DVLOG(3) << "DismissPictureBuffer(" << id << ")"; |
485 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); | 500 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); |
486 | 501 |
487 PictureBufferMap::iterator it = assigned_picture_buffers_.find(id); | 502 PictureBufferMap::iterator it = assigned_picture_buffers_.find(id); |
488 if (it == assigned_picture_buffers_.end()) { | 503 if (it == assigned_picture_buffers_.end()) { |
489 NOTREACHED() << "Missing picture buffer: " << id; | 504 NOTREACHED() << "Missing picture buffer: " << id; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
542 visible_rect = picture.visible_rect(); | 557 visible_rect = picture.visible_rect(); |
543 } | 558 } |
544 if (!gfx::Rect(pb.size()).Contains(visible_rect)) { | 559 if (!gfx::Rect(pb.size()).Contains(visible_rect)) { |
545 LOG(WARNING) << "Visible size " << visible_rect.ToString() | 560 LOG(WARNING) << "Visible size " << visible_rect.ToString() |
546 << " is larger than coded size " << pb.size().ToString(); | 561 << " is larger than coded size " << pb.size().ToString(); |
547 visible_rect = gfx::Rect(pb.size()); | 562 visible_rect = gfx::Rect(pb.size()); |
548 } | 563 } |
549 | 564 |
550 DCHECK(decoder_texture_target_); | 565 DCHECK(decoder_texture_target_); |
551 | 566 |
552 VideoPixelFormat pixel_format = vda_->GetOutputFormat(); | |
553 if (pixel_format == PIXEL_FORMAT_UNKNOWN) { | |
554 pixel_format = | |
555 IsOpaque(config_.format()) ? PIXEL_FORMAT_XRGB : PIXEL_FORMAT_ARGB; | |
556 } | |
557 | |
558 gpu::MailboxHolder mailbox_holders[VideoFrame::kMaxPlanes]; | 567 gpu::MailboxHolder mailbox_holders[VideoFrame::kMaxPlanes]; |
559 for (size_t i = 0; i < pb.texture_ids().size(); ++i) { | 568 for (size_t i = 0; i < pb.texture_ids().size(); ++i) { |
560 mailbox_holders[i] = gpu::MailboxHolder( | 569 mailbox_holders[i] = gpu::MailboxHolder( |
561 pb.texture_mailbox(i), gpu::SyncToken(), decoder_texture_target_); | 570 pb.texture_mailbox(i), gpu::SyncToken(), decoder_texture_target_); |
562 } | 571 } |
563 | 572 |
564 scoped_refptr<VideoFrame> frame(VideoFrame::WrapNativeTextures( | 573 scoped_refptr<VideoFrame> frame(VideoFrame::WrapNativeTextures( |
565 pixel_format, mailbox_holders, | 574 pixel_format_, mailbox_holders, |
566 base::Bind(&ReleaseMailboxTrampoline, factories_->GetTaskRunner(), | 575 base::Bind(&ReleaseMailboxTrampoline, factories_->GetTaskRunner(), |
567 base::Bind(&GpuVideoDecoder::ReleaseMailbox, | 576 base::Bind(&GpuVideoDecoder::ReleaseMailbox, |
568 weak_factory_.GetWeakPtr(), factories_, | 577 weak_factory_.GetWeakPtr(), factories_, |
569 picture.picture_buffer_id(), pb.texture_ids())), | 578 picture.picture_buffer_id(), pb.texture_ids())), |
570 pb.size(), visible_rect, natural_size, timestamp)); | 579 pb.size(), visible_rect, natural_size, timestamp)); |
571 if (!frame) { | 580 if (!frame) { |
572 DLOG(ERROR) << "Create frame failed for: " << picture.picture_buffer_id(); | 581 DLOG(ERROR) << "Create frame failed for: " << picture.picture_buffer_id(); |
573 NotifyError(VideoDecodeAccelerator::PLATFORM_FAILURE); | 582 NotifyError(VideoDecodeAccelerator::PLATFORM_FAILURE); |
574 return; | 583 return; |
575 } | 584 } |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
781 } | 790 } |
782 return false; | 791 return false; |
783 } | 792 } |
784 | 793 |
785 void GpuVideoDecoder::DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent() | 794 void GpuVideoDecoder::DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent() |
786 const { | 795 const { |
787 DCHECK(factories_->GetTaskRunner()->BelongsToCurrentThread()); | 796 DCHECK(factories_->GetTaskRunner()->BelongsToCurrentThread()); |
788 } | 797 } |
789 | 798 |
790 } // namespace media | 799 } // namespace media |
OLD | NEW |