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 <array> | 8 #include <array> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 GpuVideoDecoder::GpuVideoDecoder( | 114 GpuVideoDecoder::GpuVideoDecoder( |
115 GpuVideoAcceleratorFactories* factories, | 115 GpuVideoAcceleratorFactories* factories, |
116 const RequestOverlayInfoCB& request_overlay_info_cb, | 116 const RequestOverlayInfoCB& request_overlay_info_cb, |
117 MediaLog* media_log) | 117 MediaLog* media_log) |
118 : needs_bitstream_conversion_(false), | 118 : needs_bitstream_conversion_(false), |
119 factories_(factories), | 119 factories_(factories), |
120 request_overlay_info_cb_(request_overlay_info_cb), | 120 request_overlay_info_cb_(request_overlay_info_cb), |
121 media_log_(media_log), | 121 media_log_(media_log), |
122 vda_initialized_(false), | 122 vda_initialized_(false), |
123 state_(kNormal), | 123 state_(kNormal), |
124 decoder_texture_target_(0), | |
125 pixel_format_(PIXEL_FORMAT_UNKNOWN), | |
126 next_picture_buffer_id_(0), | 124 next_picture_buffer_id_(0), |
127 next_bitstream_buffer_id_(0), | 125 next_bitstream_buffer_id_(0), |
128 available_pictures_(0), | 126 available_pictures_(0), |
129 needs_all_picture_buffers_to_decode_(false), | 127 needs_all_picture_buffers_to_decode_(false), |
130 supports_deferred_initialization_(false), | 128 supports_deferred_initialization_(false), |
131 requires_texture_copy_(false), | 129 requires_texture_copy_(false), |
132 cdm_id_(CdmContext::kInvalidCdmId), | 130 cdm_id_(CdmContext::kInvalidCdmId), |
133 weak_factory_(this) { | 131 weak_factory_(this) { |
134 DCHECK(factories_); | 132 DCHECK(factories_); |
135 } | 133 } |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 VideoPixelFormat format, | 531 VideoPixelFormat format, |
534 uint32_t textures_per_buffer, | 532 uint32_t textures_per_buffer, |
535 const gfx::Size& size, | 533 const gfx::Size& size, |
536 uint32_t texture_target) { | 534 uint32_t texture_target) { |
537 DVLOG(3) << "ProvidePictureBuffers(" << count << ", " | 535 DVLOG(3) << "ProvidePictureBuffers(" << count << ", " |
538 << size.width() << "x" << size.height() << ")"; | 536 << size.width() << "x" << size.height() << ")"; |
539 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); | 537 DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent(); |
540 | 538 |
541 std::vector<uint32_t> texture_ids; | 539 std::vector<uint32_t> texture_ids; |
542 std::vector<gpu::Mailbox> texture_mailboxes; | 540 std::vector<gpu::Mailbox> texture_mailboxes; |
543 decoder_texture_target_ = texture_target; | |
544 | 541 |
545 if (format == PIXEL_FORMAT_UNKNOWN) { | 542 if (format == PIXEL_FORMAT_UNKNOWN) { |
546 format = IsOpaque(config_.format()) ? PIXEL_FORMAT_XRGB : PIXEL_FORMAT_ARGB; | 543 format = IsOpaque(config_.format()) ? PIXEL_FORMAT_XRGB : PIXEL_FORMAT_ARGB; |
547 } | 544 } |
548 | 545 |
549 // TODO(jbauman): Move decoder_texture_target_ and pixel_format_ to the | 546 if (!factories_->CreateTextures(count * textures_per_buffer, size, |
550 // picture buffer. http://crbug.com/614789 | 547 &texture_ids, &texture_mailboxes, |
551 if ((pixel_format_ != PIXEL_FORMAT_UNKNOWN) && (pixel_format_ != format)) { | 548 texture_target)) { |
552 NotifyError(VideoDecodeAccelerator::PLATFORM_FAILURE); | 549 NotifyError(VideoDecodeAccelerator::PLATFORM_FAILURE); |
553 return; | 550 return; |
554 } | 551 } |
555 | 552 |
556 pixel_format_ = format; | |
557 if (!factories_->CreateTextures(count * textures_per_buffer, size, | |
558 &texture_ids, &texture_mailboxes, | |
559 decoder_texture_target_)) { | |
560 NotifyError(VideoDecodeAccelerator::PLATFORM_FAILURE); | |
561 return; | |
562 } | |
563 sync_token_ = factories_->CreateSyncToken(); | 553 sync_token_ = factories_->CreateSyncToken(); |
564 DCHECK_EQ(count * textures_per_buffer, texture_ids.size()); | 554 DCHECK_EQ(count * textures_per_buffer, texture_ids.size()); |
565 DCHECK_EQ(count * textures_per_buffer, texture_mailboxes.size()); | 555 DCHECK_EQ(count * textures_per_buffer, texture_mailboxes.size()); |
566 | 556 |
567 if (!vda_) | 557 if (!vda_) |
568 return; | 558 return; |
569 | 559 |
570 std::vector<PictureBuffer> picture_buffers; | 560 std::vector<PictureBuffer> picture_buffers; |
571 size_t index = 0; | 561 size_t index = 0; |
572 for (size_t i = 0; i < count; ++i) { | 562 for (size_t i = 0; i < count; ++i) { |
573 PictureBuffer::TextureIds ids; | 563 PictureBuffer::TextureIds ids; |
574 std::vector<gpu::Mailbox> mailboxes; | 564 std::vector<gpu::Mailbox> mailboxes; |
575 for (size_t j = 0; j < textures_per_buffer; j++) { | 565 for (size_t j = 0; j < textures_per_buffer; j++) { |
576 ids.push_back(texture_ids[index]); | 566 ids.push_back(texture_ids[index]); |
577 mailboxes.push_back(texture_mailboxes[index]); | 567 mailboxes.push_back(texture_mailboxes[index]); |
578 index++; | 568 index++; |
579 } | 569 } |
580 | 570 |
581 picture_buffers.push_back( | 571 picture_buffers.push_back(PictureBuffer(next_picture_buffer_id_++, size, |
582 PictureBuffer(next_picture_buffer_id_++, size, ids, mailboxes)); | 572 ids, mailboxes, texture_target, |
| 573 format)); |
583 bool inserted = assigned_picture_buffers_.insert(std::make_pair( | 574 bool inserted = assigned_picture_buffers_.insert(std::make_pair( |
584 picture_buffers.back().id(), picture_buffers.back())).second; | 575 picture_buffers.back().id(), picture_buffers.back())).second; |
585 DCHECK(inserted); | 576 DCHECK(inserted); |
586 } | 577 } |
587 | 578 |
588 available_pictures_ += count; | 579 available_pictures_ += count; |
589 | 580 |
590 vda_->AssignPictureBuffers(picture_buffers); | 581 vda_->AssignPictureBuffers(picture_buffers); |
591 } | 582 } |
592 | 583 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
651 | 642 |
652 if (!picture.visible_rect().IsEmpty()) { | 643 if (!picture.visible_rect().IsEmpty()) { |
653 visible_rect = picture.visible_rect(); | 644 visible_rect = picture.visible_rect(); |
654 } | 645 } |
655 if (!gfx::Rect(pb.size()).Contains(visible_rect)) { | 646 if (!gfx::Rect(pb.size()).Contains(visible_rect)) { |
656 LOG(WARNING) << "Visible size " << visible_rect.ToString() | 647 LOG(WARNING) << "Visible size " << visible_rect.ToString() |
657 << " is larger than coded size " << pb.size().ToString(); | 648 << " is larger than coded size " << pb.size().ToString(); |
658 visible_rect = gfx::Rect(pb.size()); | 649 visible_rect = gfx::Rect(pb.size()); |
659 } | 650 } |
660 | 651 |
661 DCHECK(decoder_texture_target_); | 652 DCHECK(pb.texture_target()); |
662 | 653 |
663 gpu::MailboxHolder mailbox_holders[VideoFrame::kMaxPlanes]; | 654 gpu::MailboxHolder mailbox_holders[VideoFrame::kMaxPlanes]; |
664 for (size_t i = 0; i < pb.client_texture_ids().size(); ++i) { | 655 for (size_t i = 0; i < pb.client_texture_ids().size(); ++i) { |
665 mailbox_holders[i] = gpu::MailboxHolder(pb.texture_mailbox(i), sync_token_, | 656 mailbox_holders[i] = gpu::MailboxHolder(pb.texture_mailbox(i), sync_token_, |
666 decoder_texture_target_); | 657 pb.texture_target()); |
667 } | 658 } |
668 | 659 |
669 scoped_refptr<VideoFrame> frame(VideoFrame::WrapNativeTextures( | 660 scoped_refptr<VideoFrame> frame(VideoFrame::WrapNativeTextures( |
670 pixel_format_, mailbox_holders, | 661 pb.pixel_format(), mailbox_holders, |
671 // Always post ReleaseMailbox to avoid deadlock with the compositor when | 662 // Always post ReleaseMailbox to avoid deadlock with the compositor when |
672 // releasing video frames on the media thread; http://crbug.com/710209. | 663 // releasing video frames on the media thread; http://crbug.com/710209. |
673 BindToCurrentLoop(base::Bind( | 664 BindToCurrentLoop(base::Bind( |
674 &GpuVideoDecoder::ReleaseMailbox, weak_factory_.GetWeakPtr(), | 665 &GpuVideoDecoder::ReleaseMailbox, weak_factory_.GetWeakPtr(), |
675 factories_, picture.picture_buffer_id(), pb.client_texture_ids())), | 666 factories_, picture.picture_buffer_id(), pb.client_texture_ids())), |
676 pb.size(), visible_rect, natural_size, timestamp)); | 667 pb.size(), visible_rect, natural_size, timestamp)); |
677 if (!frame) { | 668 if (!frame) { |
678 DLOG(ERROR) << "Create frame failed for: " << picture.picture_buffer_id(); | 669 DLOG(ERROR) << "Create frame failed for: " << picture.picture_buffer_id(); |
679 NotifyError(VideoDecodeAccelerator::PLATFORM_FAILURE); | 670 NotifyError(VideoDecodeAccelerator::PLATFORM_FAILURE); |
680 return; | 671 return; |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
900 } | 891 } |
901 return false; | 892 return false; |
902 } | 893 } |
903 | 894 |
904 void GpuVideoDecoder::DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent() | 895 void GpuVideoDecoder::DCheckGpuVideoAcceleratorFactoriesTaskRunnerIsCurrent() |
905 const { | 896 const { |
906 DCHECK(factories_->GetTaskRunner()->BelongsToCurrentThread()); | 897 DCHECK(factories_->GetTaskRunner()->BelongsToCurrentThread()); |
907 } | 898 } |
908 | 899 |
909 } // namespace media | 900 } // namespace media |
OLD | NEW |