| 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 "content/common/gpu/media/dxva_video_decode_accelerator.h" | 5 #include "content/common/gpu/media/dxva_video_decode_accelerator.h" |
| 6 | 6 |
| 7 #if !defined(OS_WIN) | 7 #if !defined(OS_WIN) |
| 8 #error This file should only be built on Windows. | 8 #error This file should only be built on Windows. |
| 9 #endif // !defined(OS_WIN) | 9 #endif // !defined(OS_WIN) |
| 10 | 10 |
| (...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 DXVAVideoDecodeAccelerator::PendingSampleInfo::~PendingSampleInfo() {} | 510 DXVAVideoDecodeAccelerator::PendingSampleInfo::~PendingSampleInfo() {} |
| 511 | 511 |
| 512 DXVAVideoDecodeAccelerator::DXVAVideoDecodeAccelerator( | 512 DXVAVideoDecodeAccelerator::DXVAVideoDecodeAccelerator( |
| 513 const base::Callback<bool(void)>& make_context_current, | 513 const base::Callback<bool(void)>& make_context_current, |
| 514 gfx::GLContext* gl_context) | 514 gfx::GLContext* gl_context) |
| 515 : client_(NULL), | 515 : client_(NULL), |
| 516 dev_manager_reset_token_(0), | 516 dev_manager_reset_token_(0), |
| 517 dx11_dev_manager_reset_token_(0), | 517 dx11_dev_manager_reset_token_(0), |
| 518 egl_config_(NULL), | 518 egl_config_(NULL), |
| 519 state_(kUninitialized), | 519 state_(kUninitialized), |
| 520 num_picture_buffers_(kNumPictureBuffers), |
| 520 pictures_requested_(false), | 521 pictures_requested_(false), |
| 521 inputs_before_decode_(0), | 522 inputs_before_decode_(0), |
| 522 sent_drain_message_(false), | 523 sent_drain_message_(false), |
| 523 make_context_current_(make_context_current), | 524 make_context_current_(make_context_current), |
| 524 codec_(media::kUnknownVideoCodec), | 525 codec_(media::kUnknownVideoCodec), |
| 525 decoder_thread_("DXVAVideoDecoderThread"), | 526 decoder_thread_("DXVAVideoDecoderThread"), |
| 526 pending_flush_(false), | 527 pending_flush_(false), |
| 527 use_dx11_(false), | 528 use_dx11_(false), |
| 528 dx11_video_format_converter_media_type_needs_init_(true), | 529 dx11_video_format_converter_media_type_needs_init_(true), |
| 529 gl_context_(gl_context), | 530 gl_context_(gl_context), |
| 530 weak_this_factory_(this) { | 531 weak_this_factory_(this) { |
| 531 weak_ptr_ = weak_this_factory_.GetWeakPtr(); | 532 weak_ptr_ = weak_this_factory_.GetWeakPtr(); |
| 532 memset(&input_stream_info_, 0, sizeof(input_stream_info_)); | 533 memset(&input_stream_info_, 0, sizeof(input_stream_info_)); |
| 533 memset(&output_stream_info_, 0, sizeof(output_stream_info_)); | 534 memset(&output_stream_info_, 0, sizeof(output_stream_info_)); |
| 534 } | 535 } |
| 535 | 536 |
| 536 DXVAVideoDecodeAccelerator::~DXVAVideoDecodeAccelerator() { | 537 DXVAVideoDecodeAccelerator::~DXVAVideoDecodeAccelerator() { |
| 537 client_ = NULL; | 538 client_ = NULL; |
| 538 } | 539 } |
| 539 | 540 |
| 540 bool DXVAVideoDecodeAccelerator::Initialize(media::VideoCodecProfile profile, | 541 bool DXVAVideoDecodeAccelerator::Initialize(media::VideoCodecProfile profile, |
| 541 Client* client) { | 542 uint32_t min_picture_count, |
| 543 Client* client) { |
| 542 client_ = client; | 544 client_ = client; |
| 543 | 545 |
| 546 num_picture_buffers_ = std::max(min_picture_count, |
| 547 static_cast<uint32_t>(kNumPictureBuffers)); |
| 548 |
| 544 main_thread_task_runner_ = base::MessageLoop::current()->task_runner(); | 549 main_thread_task_runner_ = base::MessageLoop::current()->task_runner(); |
| 545 | 550 |
| 546 bool profile_supported = false; | 551 bool profile_supported = false; |
| 547 for (const auto& supported_profile : kSupportedProfiles) { | 552 for (const auto& supported_profile : kSupportedProfiles) { |
| 548 if (profile == supported_profile) { | 553 if (profile == supported_profile) { |
| 549 profile_supported = true; | 554 profile_supported = true; |
| 550 break; | 555 break; |
| 551 } | 556 } |
| 552 } | 557 } |
| 553 if (!profile_supported) { | 558 if (!profile_supported) { |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 770 base::Unretained(this), sample)); | 775 base::Unretained(this), sample)); |
| 771 } | 776 } |
| 772 | 777 |
| 773 void DXVAVideoDecodeAccelerator::AssignPictureBuffers( | 778 void DXVAVideoDecodeAccelerator::AssignPictureBuffers( |
| 774 const std::vector<media::PictureBuffer>& buffers) { | 779 const std::vector<media::PictureBuffer>& buffers) { |
| 775 DCHECK(main_thread_task_runner_->BelongsToCurrentThread()); | 780 DCHECK(main_thread_task_runner_->BelongsToCurrentThread()); |
| 776 | 781 |
| 777 State state = GetState(); | 782 State state = GetState(); |
| 778 RETURN_AND_NOTIFY_ON_FAILURE((state != kUninitialized), | 783 RETURN_AND_NOTIFY_ON_FAILURE((state != kUninitialized), |
| 779 "Invalid state: " << state, ILLEGAL_STATE,); | 784 "Invalid state: " << state, ILLEGAL_STATE,); |
| 780 RETURN_AND_NOTIFY_ON_FAILURE((kNumPictureBuffers == buffers.size()), | 785 RETURN_AND_NOTIFY_ON_FAILURE((num_picture_buffers_ == buffers.size()), |
| 781 "Failed to provide requested picture buffers. (Got " << buffers.size() << | 786 "Failed to provide requested picture buffers. (Got " << buffers.size() << |
| 782 ", requested " << kNumPictureBuffers << ")", INVALID_ARGUMENT,); | 787 ", requested " << num_picture_buffers_ << ")", INVALID_ARGUMENT,); |
| 783 | 788 |
| 784 // Copy the picture buffers provided by the client to the available list, | 789 // Copy the picture buffers provided by the client to the available list, |
| 785 // and mark these buffers as available for use. | 790 // and mark these buffers as available for use. |
| 786 for (size_t buffer_index = 0; buffer_index < buffers.size(); | 791 for (size_t buffer_index = 0; buffer_index < buffers.size(); |
| 787 ++buffer_index) { | 792 ++buffer_index) { |
| 788 linked_ptr<DXVAPictureBuffer> picture_buffer = | 793 linked_ptr<DXVAPictureBuffer> picture_buffer = |
| 789 DXVAPictureBuffer::Create(*this, buffers[buffer_index], egl_config_); | 794 DXVAPictureBuffer::Create(*this, buffers[buffer_index], egl_config_); |
| 790 RETURN_AND_NOTIFY_ON_FAILURE(picture_buffer.get(), | 795 RETURN_AND_NOTIFY_ON_FAILURE(picture_buffer.get(), |
| 791 "Failed to allocate picture buffer", PLATFORM_FAILURE,); | 796 "Failed to allocate picture buffer", PLATFORM_FAILURE,); |
| 792 | 797 |
| (...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1472 DCHECK(main_thread_task_runner_->BelongsToCurrentThread()); | 1477 DCHECK(main_thread_task_runner_->BelongsToCurrentThread()); |
| 1473 if (client_) | 1478 if (client_) |
| 1474 client_->NotifyResetDone(); | 1479 client_->NotifyResetDone(); |
| 1475 } | 1480 } |
| 1476 | 1481 |
| 1477 void DXVAVideoDecodeAccelerator::RequestPictureBuffers(int width, int height) { | 1482 void DXVAVideoDecodeAccelerator::RequestPictureBuffers(int width, int height) { |
| 1478 DCHECK(main_thread_task_runner_->BelongsToCurrentThread()); | 1483 DCHECK(main_thread_task_runner_->BelongsToCurrentThread()); |
| 1479 // This task could execute after the decoder has been torn down. | 1484 // This task could execute after the decoder has been torn down. |
| 1480 if (GetState() != kUninitialized && client_) { | 1485 if (GetState() != kUninitialized && client_) { |
| 1481 client_->ProvidePictureBuffers( | 1486 client_->ProvidePictureBuffers( |
| 1482 kNumPictureBuffers, | 1487 num_picture_buffers_, |
| 1483 gfx::Size(width, height), | 1488 gfx::Size(width, height), |
| 1484 GL_TEXTURE_2D); | 1489 GL_TEXTURE_2D); |
| 1485 } | 1490 } |
| 1486 } | 1491 } |
| 1487 | 1492 |
| 1488 void DXVAVideoDecodeAccelerator::NotifyPictureReady( | 1493 void DXVAVideoDecodeAccelerator::NotifyPictureReady( |
| 1489 int picture_buffer_id, | 1494 int picture_buffer_id, |
| 1490 int input_buffer_id, | 1495 int input_buffer_id, |
| 1491 const gfx::Rect& picture_buffer_size) { | 1496 const gfx::Rect& picture_buffer_size) { |
| 1492 DCHECK(main_thread_task_runner_->BelongsToCurrentThread()); | 1497 DCHECK(main_thread_task_runner_->BelongsToCurrentThread()); |
| (...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2187 D3DSURFACE_DESC surface_desc; | 2192 D3DSURFACE_DESC surface_desc; |
| 2188 hr = surface->GetDesc(&surface_desc); | 2193 hr = surface->GetDesc(&surface_desc); |
| 2189 RETURN_ON_HR_FAILURE(hr, "Failed to get surface description", false); | 2194 RETURN_ON_HR_FAILURE(hr, "Failed to get surface description", false); |
| 2190 *width = surface_desc.Width; | 2195 *width = surface_desc.Width; |
| 2191 *height = surface_desc.Height; | 2196 *height = surface_desc.Height; |
| 2192 } | 2197 } |
| 2193 return true; | 2198 return true; |
| 2194 } | 2199 } |
| 2195 | 2200 |
| 2196 } // namespace content | 2201 } // namespace content |
| OLD | NEW |