| 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 RETURN_ON_HR_FAILURE(hr, "Failed to unlock buffer", NULL); | 135 RETURN_ON_HR_FAILURE(hr, "Failed to unlock buffer", NULL); |
| 136 | 136 |
| 137 hr = buffer->SetCurrentLength(size); | 137 hr = buffer->SetCurrentLength(size); |
| 138 RETURN_ON_HR_FAILURE(hr, "Failed to set buffer length", NULL); | 138 RETURN_ON_HR_FAILURE(hr, "Failed to set buffer length", NULL); |
| 139 | 139 |
| 140 return sample.Detach(); | 140 return sample.Detach(); |
| 141 } | 141 } |
| 142 | 142 |
| 143 static IMFSample* CreateSampleFromInputBuffer( | 143 static IMFSample* CreateSampleFromInputBuffer( |
| 144 const media::BitstreamBuffer& bitstream_buffer, | 144 const media::BitstreamBuffer& bitstream_buffer, |
| 145 base::ProcessHandle renderer_process, | |
| 146 DWORD stream_size, | 145 DWORD stream_size, |
| 147 DWORD alignment) { | 146 DWORD alignment) { |
| 148 HANDLE shared_memory_handle = NULL; | 147 base::SharedMemory shm(bitstream_buffer.handle(), true); |
| 149 RETURN_ON_FAILURE(::DuplicateHandle(renderer_process, | |
| 150 bitstream_buffer.handle(), | |
| 151 base::GetCurrentProcessHandle(), | |
| 152 &shared_memory_handle, | |
| 153 0, | |
| 154 FALSE, | |
| 155 DUPLICATE_SAME_ACCESS), | |
| 156 "Duplicate handle failed", NULL); | |
| 157 | |
| 158 base::SharedMemory shm(shared_memory_handle, true); | |
| 159 RETURN_ON_FAILURE(shm.Map(bitstream_buffer.size()), | 148 RETURN_ON_FAILURE(shm.Map(bitstream_buffer.size()), |
| 160 "Failed in base::SharedMemory::Map", NULL); | 149 "Failed in base::SharedMemory::Map", NULL); |
| 161 | 150 |
| 162 return CreateInputSample(reinterpret_cast<const uint8*>(shm.memory()), | 151 return CreateInputSample(reinterpret_cast<const uint8*>(shm.memory()), |
| 163 bitstream_buffer.size(), | 152 bitstream_buffer.size(), |
| 164 stream_size, | 153 stream_size, |
| 165 alignment); | 154 alignment); |
| 166 } | 155 } |
| 167 | 156 |
| 168 // Helper function to read the bitmap from the D3D surface passed in. | 157 // Helper function to read the bitmap from the D3D surface passed in. |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 hr = device_manager_->ResetDevice(device_, dev_manager_reset_token_); | 487 hr = device_manager_->ResetDevice(device_, dev_manager_reset_token_); |
| 499 RETURN_ON_HR_FAILURE(hr, "Failed to reset device", false); | 488 RETURN_ON_HR_FAILURE(hr, "Failed to reset device", false); |
| 500 | 489 |
| 501 hr = device_->CreateQuery(D3DQUERYTYPE_EVENT, &query_); | 490 hr = device_->CreateQuery(D3DQUERYTYPE_EVENT, &query_); |
| 502 RETURN_ON_HR_FAILURE(hr, "Failed to create D3D device query", false); | 491 RETURN_ON_HR_FAILURE(hr, "Failed to create D3D device query", false); |
| 503 | 492 |
| 504 return true; | 493 return true; |
| 505 } | 494 } |
| 506 | 495 |
| 507 DXVAVideoDecodeAccelerator::DXVAVideoDecodeAccelerator( | 496 DXVAVideoDecodeAccelerator::DXVAVideoDecodeAccelerator( |
| 508 media::VideoDecodeAccelerator::Client* client, | 497 media::VideoDecodeAccelerator::Client* client) |
| 509 base::ProcessHandle renderer_process) | |
| 510 : client_(client), | 498 : client_(client), |
| 511 egl_config_(NULL), | 499 egl_config_(NULL), |
| 512 state_(kUninitialized), | 500 state_(kUninitialized), |
| 513 pictures_requested_(false), | 501 pictures_requested_(false), |
| 514 renderer_process_(renderer_process), | |
| 515 last_input_buffer_id_(-1), | 502 last_input_buffer_id_(-1), |
| 516 inputs_before_decode_(0) { | 503 inputs_before_decode_(0) { |
| 517 memset(&input_stream_info_, 0, sizeof(input_stream_info_)); | 504 memset(&input_stream_info_, 0, sizeof(input_stream_info_)); |
| 518 memset(&output_stream_info_, 0, sizeof(output_stream_info_)); | 505 memset(&output_stream_info_, 0, sizeof(output_stream_info_)); |
| 519 } | 506 } |
| 520 | 507 |
| 521 DXVAVideoDecodeAccelerator::~DXVAVideoDecodeAccelerator() { | 508 DXVAVideoDecodeAccelerator::~DXVAVideoDecodeAccelerator() { |
| 522 client_ = NULL; | 509 client_ = NULL; |
| 523 } | 510 } |
| 524 | 511 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 553 | 540 |
| 554 void DXVAVideoDecodeAccelerator::Decode( | 541 void DXVAVideoDecodeAccelerator::Decode( |
| 555 const media::BitstreamBuffer& bitstream_buffer) { | 542 const media::BitstreamBuffer& bitstream_buffer) { |
| 556 DCHECK(CalledOnValidThread()); | 543 DCHECK(CalledOnValidThread()); |
| 557 | 544 |
| 558 RETURN_AND_NOTIFY_ON_FAILURE((state_ == kNormal || state_ == kStopped), | 545 RETURN_AND_NOTIFY_ON_FAILURE((state_ == kNormal || state_ == kStopped), |
| 559 "Invalid state: " << state_, ILLEGAL_STATE,); | 546 "Invalid state: " << state_, ILLEGAL_STATE,); |
| 560 | 547 |
| 561 base::win::ScopedComPtr<IMFSample> sample; | 548 base::win::ScopedComPtr<IMFSample> sample; |
| 562 sample.Attach(CreateSampleFromInputBuffer(bitstream_buffer, | 549 sample.Attach(CreateSampleFromInputBuffer(bitstream_buffer, |
| 563 renderer_process_, | |
| 564 input_stream_info_.cbSize, | 550 input_stream_info_.cbSize, |
| 565 input_stream_info_.cbAlignment)); | 551 input_stream_info_.cbAlignment)); |
| 566 RETURN_AND_NOTIFY_ON_FAILURE(sample, "Failed to create input sample", | 552 RETURN_AND_NOTIFY_ON_FAILURE(sample, "Failed to create input sample", |
| 567 PLATFORM_FAILURE,); | 553 PLATFORM_FAILURE,); |
| 568 if (!inputs_before_decode_) { | 554 if (!inputs_before_decode_) { |
| 569 TRACE_EVENT_BEGIN_ETW("DXVAVideoDecodeAccelerator.Decoding", this, ""); | 555 TRACE_EVENT_BEGIN_ETW("DXVAVideoDecodeAccelerator.Decoding", this, ""); |
| 570 } | 556 } |
| 571 inputs_before_decode_++; | 557 inputs_before_decode_++; |
| 572 | 558 |
| 573 RETURN_AND_NOTIFY_ON_FAILURE( | 559 RETURN_AND_NOTIFY_ON_FAILURE( |
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1032 gfx::Size(width, height)); | 1018 gfx::Size(width, height)); |
| 1033 } | 1019 } |
| 1034 } | 1020 } |
| 1035 | 1021 |
| 1036 void DXVAVideoDecodeAccelerator::NotifyPictureReady( | 1022 void DXVAVideoDecodeAccelerator::NotifyPictureReady( |
| 1037 const media::Picture& picture) { | 1023 const media::Picture& picture) { |
| 1038 // This task could execute after the decoder has been torn down. | 1024 // This task could execute after the decoder has been torn down. |
| 1039 if (state_ != kUninitialized && client_) | 1025 if (state_ != kUninitialized && client_) |
| 1040 client_->PictureReady(picture); | 1026 client_->PictureReady(picture); |
| 1041 } | 1027 } |
| OLD | NEW |