Index: content/common/gpu/media/dxva_video_decode_accelerator.cc |
=================================================================== |
--- content/common/gpu/media/dxva_video_decode_accelerator.cc (revision 169901) |
+++ content/common/gpu/media/dxva_video_decode_accelerator.cc (working copy) |
@@ -24,6 +24,7 @@ |
#include "base/message_loop.h" |
#include "base/process_util.h" |
#include "base/shared_memory.h" |
+#include "base/threading/worker_pool.h" |
#include "media/video/video_decode_accelerator.h" |
#include "third_party/angle/include/EGL/egl.h" |
#include "third_party/angle/include/EGL/eglext.h" |
@@ -367,10 +368,14 @@ |
DXVAVideoDecodeAccelerator::PendingSampleInfo::~PendingSampleInfo() {} |
// static |
-void DXVAVideoDecodeAccelerator::PreSandboxInitialization() { |
+// Initializes DXVA on a separate thread. |
+void DXVAVideoDecodeAccelerator::PreSandboxInitialization( |
+ const base::Closure& completion_task) { |
// Should be called only once during program startup. |
DCHECK(!pre_sandbox_init_done_); |
+ base::ScopedClosureRunner scoped_completion_runner(completion_task); |
+ |
static wchar_t* decoding_dlls[] = { |
L"d3d9.dll", |
L"dxva2.dll", |
@@ -387,15 +392,24 @@ |
} |
} |
- RETURN_ON_FAILURE(CreateD3DDevManager(), |
- "Failed to initialize D3D device and manager",); |
- pre_sandbox_init_done_ = true; |
+ HRESULT hr = Direct3DCreate9Ex(D3D_SDK_VERSION, &d3d9_); |
+ RETURN_ON_HR_FAILURE(hr, |
+ "Failed to initialize D3D9.",); |
+ |
+ // Initialize H/W video decoding stuff which fails in the sandbox. This is |
+ // done on a worker thread because it takes 10s of ms. |
+ scoped_completion_runner.Release(); |
+ base::WorkerPool::PostTask( |
+ FROM_HERE, |
+ base::Bind(&DXVAVideoDecodeAccelerator::CreateD3DDevManager, |
+ completion_task), |
+ true); |
} |
// static |
-bool DXVAVideoDecodeAccelerator::CreateD3DDevManager() { |
- HRESULT hr = Direct3DCreate9Ex(D3D_SDK_VERSION, &d3d9_); |
- RETURN_ON_HR_FAILURE(hr, "Direct3DCreate9Ex failed", false); |
+void DXVAVideoDecodeAccelerator::CreateD3DDevManager( |
+ const base::Closure& completion_task) { |
+ base::ScopedClosureRunner scoped_completion_runner(completion_task); |
D3DPRESENT_PARAMETERS present_params = {0}; |
present_params.BackBufferWidth = 1; |
@@ -409,32 +423,34 @@ |
present_params.FullScreen_RefreshRateInHz = 0; |
present_params.PresentationInterval = 0; |
- hr = d3d9_->CreateDeviceEx(D3DADAPTER_DEFAULT, |
- D3DDEVTYPE_HAL, |
- ::GetShellWindow(), |
- D3DCREATE_FPU_PRESERVE | |
- D3DCREATE_SOFTWARE_VERTEXPROCESSING | |
- D3DCREATE_DISABLE_PSGP_THREADING | |
- D3DCREATE_MULTITHREADED, |
- &present_params, |
- NULL, |
- &device_); |
- RETURN_ON_HR_FAILURE(hr, "Failed to create D3D device", false); |
+ HRESULT hr = d3d9_->CreateDeviceEx(D3DADAPTER_DEFAULT, |
+ D3DDEVTYPE_HAL, |
+ ::GetShellWindow(), |
+ D3DCREATE_FPU_PRESERVE | |
+ D3DCREATE_SOFTWARE_VERTEXPROCESSING | |
+ D3DCREATE_DISABLE_PSGP_THREADING | |
+ D3DCREATE_MULTITHREADED, |
+ &present_params, |
+ NULL, |
+ &device_); |
+ RETURN_ON_HR_FAILURE(hr, "Failed to create D3D device",); |
hr = DXVA2CreateDirect3DDeviceManager9(&dev_manager_reset_token_, |
&device_manager_); |
- RETURN_ON_HR_FAILURE(hr, "DXVA2CreateDirect3DDeviceManager9 failed", false); |
+ RETURN_ON_HR_FAILURE(hr, "DXVA2CreateDirect3DDeviceManager9 failed",); |
hr = device_manager_->ResetDevice(device_, dev_manager_reset_token_); |
- RETURN_ON_HR_FAILURE(hr, "Failed to reset device", false); |
+ RETURN_ON_HR_FAILURE(hr, "Failed to reset device",); |
hr = device_->CreateQuery(D3DQUERYTYPE_EVENT, &query_); |
- RETURN_ON_HR_FAILURE(hr, "Failed to create D3D device query", false); |
+ RETURN_ON_HR_FAILURE(hr, "Failed to create D3D device query",); |
+ |
// Ensure query_ API works (to avoid an infinite loop later in |
// CopyOutputSampleDataToPictureBuffer). |
hr = query_->Issue(D3DISSUE_END); |
- RETURN_ON_HR_FAILURE(hr, "Failed to issue END test query", false); |
- return true; |
+ RETURN_ON_HR_FAILURE(hr, "Failed to issue END test query",); |
+ |
+ pre_sandbox_init_done_ = true; |
} |
DXVAVideoDecodeAccelerator::DXVAVideoDecodeAccelerator( |