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/gpu/dxva_video_decode_accelerator_win.h" | 5 #include "media/gpu/dxva_video_decode_accelerator_win.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #if !defined(OS_WIN) | 9 #if !defined(OS_WIN) |
10 #error This file should only be built on Windows. | 10 #error This file should only be built on Windows. |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 uint32_t min_size, | 284 uint32_t min_size, |
285 int alignment) { | 285 int alignment) { |
286 CHECK(stream); | 286 CHECK(stream); |
287 CHECK_GT(size, 0U); | 287 CHECK_GT(size, 0U); |
288 base::win::ScopedComPtr<IMFSample> sample; | 288 base::win::ScopedComPtr<IMFSample> sample; |
289 sample = mf::CreateEmptySampleWithBuffer(std::max(min_size, size), alignment); | 289 sample = mf::CreateEmptySampleWithBuffer(std::max(min_size, size), alignment); |
290 RETURN_ON_FAILURE(sample.Get(), "Failed to create empty sample", | 290 RETURN_ON_FAILURE(sample.Get(), "Failed to create empty sample", |
291 base::win::ScopedComPtr<IMFSample>()); | 291 base::win::ScopedComPtr<IMFSample>()); |
292 | 292 |
293 base::win::ScopedComPtr<IMFMediaBuffer> buffer; | 293 base::win::ScopedComPtr<IMFMediaBuffer> buffer; |
294 HRESULT hr = sample->GetBufferByIndex(0, buffer.Receive()); | 294 HRESULT hr = sample->GetBufferByIndex(0, buffer.GetAddressOf()); |
295 RETURN_ON_HR_FAILURE(hr, "Failed to get buffer from sample", | 295 RETURN_ON_HR_FAILURE(hr, "Failed to get buffer from sample", |
296 base::win::ScopedComPtr<IMFSample>()); | 296 base::win::ScopedComPtr<IMFSample>()); |
297 | 297 |
298 DWORD max_length = 0; | 298 DWORD max_length = 0; |
299 DWORD current_length = 0; | 299 DWORD current_length = 0; |
300 uint8_t* destination = NULL; | 300 uint8_t* destination = NULL; |
301 hr = buffer->Lock(&destination, &max_length, ¤t_length); | 301 hr = buffer->Lock(&destination, &max_length, ¤t_length); |
302 RETURN_ON_HR_FAILURE(hr, "Failed to lock buffer", | 302 RETURN_ON_HR_FAILURE(hr, "Failed to lock buffer", |
303 base::win::ScopedComPtr<IMFSample>()); | 303 base::win::ScopedComPtr<IMFSample>()); |
304 | 304 |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
649 } | 649 } |
650 | 650 |
651 bool DXVAVideoDecodeAccelerator::CreateD3DDevManager() { | 651 bool DXVAVideoDecodeAccelerator::CreateD3DDevManager() { |
652 TRACE_EVENT0("gpu", "DXVAVideoDecodeAccelerator_CreateD3DDevManager"); | 652 TRACE_EVENT0("gpu", "DXVAVideoDecodeAccelerator_CreateD3DDevManager"); |
653 // The device may exist if the last state was a config change. | 653 // The device may exist if the last state was a config change. |
654 if (d3d9_.Get()) | 654 if (d3d9_.Get()) |
655 return true; | 655 return true; |
656 | 656 |
657 HRESULT hr = E_FAIL; | 657 HRESULT hr = E_FAIL; |
658 | 658 |
659 hr = Direct3DCreate9Ex(D3D_SDK_VERSION, d3d9_.Receive()); | 659 hr = Direct3DCreate9Ex(D3D_SDK_VERSION, d3d9_.GetAddressOf()); |
660 RETURN_ON_HR_FAILURE(hr, "Direct3DCreate9Ex failed", false); | 660 RETURN_ON_HR_FAILURE(hr, "Direct3DCreate9Ex failed", false); |
661 | 661 |
662 hr = d3d9_->CheckDeviceFormatConversion( | 662 hr = d3d9_->CheckDeviceFormatConversion( |
663 D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, | 663 D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, |
664 static_cast<D3DFORMAT>(MAKEFOURCC('N', 'V', '1', '2')), D3DFMT_X8R8G8B8); | 664 static_cast<D3DFORMAT>(MAKEFOURCC('N', 'V', '1', '2')), D3DFMT_X8R8G8B8); |
665 RETURN_ON_HR_FAILURE(hr, "D3D9 driver does not support H/W format conversion", | 665 RETURN_ON_HR_FAILURE(hr, "D3D9 driver does not support H/W format conversion", |
666 false); | 666 false); |
667 | 667 |
668 base::win::ScopedComPtr<IDirect3DDevice9> angle_device = | 668 base::win::ScopedComPtr<IDirect3DDevice9> angle_device = |
669 gl::QueryD3D9DeviceObjectFromANGLE(); | 669 gl::QueryD3D9DeviceObjectFromANGLE(); |
(...skipping 15 matching lines...) Expand all Loading... |
685 present_params.hDeviceWindow = NULL; | 685 present_params.hDeviceWindow = NULL; |
686 present_params.Windowed = TRUE; | 686 present_params.Windowed = TRUE; |
687 present_params.Flags = D3DPRESENTFLAG_VIDEO; | 687 present_params.Flags = D3DPRESENTFLAG_VIDEO; |
688 present_params.FullScreen_RefreshRateInHz = 0; | 688 present_params.FullScreen_RefreshRateInHz = 0; |
689 present_params.PresentationInterval = 0; | 689 present_params.PresentationInterval = 0; |
690 | 690 |
691 hr = d3d9_->CreateDeviceEx( | 691 hr = d3d9_->CreateDeviceEx( |
692 D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, NULL, | 692 D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, NULL, |
693 D3DCREATE_FPU_PRESERVE | D3DCREATE_MIXED_VERTEXPROCESSING | | 693 D3DCREATE_FPU_PRESERVE | D3DCREATE_MIXED_VERTEXPROCESSING | |
694 D3DCREATE_MULTITHREADED, | 694 D3DCREATE_MULTITHREADED, |
695 &present_params, NULL, d3d9_device_ex_.Receive()); | 695 &present_params, NULL, d3d9_device_ex_.GetAddressOf()); |
696 RETURN_ON_HR_FAILURE(hr, "Failed to create D3D device", false); | 696 RETURN_ON_HR_FAILURE(hr, "Failed to create D3D device", false); |
697 } | 697 } |
698 | 698 |
699 hr = DXVA2CreateDirect3DDeviceManager9(&dev_manager_reset_token_, | 699 hr = DXVA2CreateDirect3DDeviceManager9(&dev_manager_reset_token_, |
700 device_manager_.Receive()); | 700 device_manager_.GetAddressOf()); |
701 RETURN_ON_HR_FAILURE(hr, "DXVA2CreateDirect3DDeviceManager9 failed", false); | 701 RETURN_ON_HR_FAILURE(hr, "DXVA2CreateDirect3DDeviceManager9 failed", false); |
702 | 702 |
703 hr = device_manager_->ResetDevice(d3d9_device_ex_.Get(), | 703 hr = device_manager_->ResetDevice(d3d9_device_ex_.Get(), |
704 dev_manager_reset_token_); | 704 dev_manager_reset_token_); |
705 RETURN_ON_HR_FAILURE(hr, "Failed to reset device", false); | 705 RETURN_ON_HR_FAILURE(hr, "Failed to reset device", false); |
706 | 706 |
707 hr = d3d9_device_ex_->CreateQuery(D3DQUERYTYPE_EVENT, query_.Receive()); | 707 hr = d3d9_device_ex_->CreateQuery(D3DQUERYTYPE_EVENT, query_.GetAddressOf()); |
708 RETURN_ON_HR_FAILURE(hr, "Failed to create D3D device query", false); | 708 RETURN_ON_HR_FAILURE(hr, "Failed to create D3D device query", false); |
709 // Ensure query_ API works (to avoid an infinite loop later in | 709 // Ensure query_ API works (to avoid an infinite loop later in |
710 // CopyOutputSampleDataToPictureBuffer). | 710 // CopyOutputSampleDataToPictureBuffer). |
711 hr = query_->Issue(D3DISSUE_END); | 711 hr = query_->Issue(D3DISSUE_END); |
712 RETURN_ON_HR_FAILURE(hr, "Failed to issue END test query", false); | 712 RETURN_ON_HR_FAILURE(hr, "Failed to issue END test query", false); |
713 | 713 |
714 CreateVideoProcessor(); | 714 CreateVideoProcessor(); |
715 return true; | 715 return true; |
716 } | 716 } |
717 | 717 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
771 for (f = 0; f < format_count; f++) { | 771 for (f = 0; f < format_count; f++) { |
772 if (formats[f] == D3DFMT_X8R8G8B8) { | 772 if (formats[f] == D3DFMT_X8R8G8B8) { |
773 break; | 773 break; |
774 } | 774 } |
775 } | 775 } |
776 if (f == format_count) | 776 if (f == format_count) |
777 continue; | 777 continue; |
778 | 778 |
779 // Create video processor | 779 // Create video processor |
780 hr = video_processor_service_->CreateVideoProcessor( | 780 hr = video_processor_service_->CreateVideoProcessor( |
781 guids[g], &inputDesc, D3DFMT_X8R8G8B8, 0, processor_.Receive()); | 781 guids[g], &inputDesc, D3DFMT_X8R8G8B8, 0, processor_.GetAddressOf()); |
782 if (hr) | 782 if (hr) |
783 continue; | 783 continue; |
784 | 784 |
785 DXVA2_ValueRange range; | 785 DXVA2_ValueRange range; |
786 processor_->GetProcAmpRange(DXVA2_ProcAmp_Brightness, &range); | 786 processor_->GetProcAmpRange(DXVA2_ProcAmp_Brightness, &range); |
787 default_procamp_values_.Brightness = range.DefaultValue; | 787 default_procamp_values_.Brightness = range.DefaultValue; |
788 processor_->GetProcAmpRange(DXVA2_ProcAmp_Contrast, &range); | 788 processor_->GetProcAmpRange(DXVA2_ProcAmp_Contrast, &range); |
789 default_procamp_values_.Contrast = range.DefaultValue; | 789 default_procamp_values_.Contrast = range.DefaultValue; |
790 processor_->GetProcAmpRange(DXVA2_ProcAmp_Hue, &range); | 790 processor_->GetProcAmpRange(DXVA2_ProcAmp_Hue, &range); |
791 default_procamp_values_.Hue = range.DefaultValue; | 791 default_procamp_values_.Hue = range.DefaultValue; |
792 processor_->GetProcAmpRange(DXVA2_ProcAmp_Saturation, &range); | 792 processor_->GetProcAmpRange(DXVA2_ProcAmp_Saturation, &range); |
793 default_procamp_values_.Saturation = range.DefaultValue; | 793 default_procamp_values_.Saturation = range.DefaultValue; |
794 | 794 |
795 return true; | 795 return true; |
796 } | 796 } |
797 return false; | 797 return false; |
798 } | 798 } |
799 | 799 |
800 bool DXVAVideoDecodeAccelerator::CreateDX11DevManager() { | 800 bool DXVAVideoDecodeAccelerator::CreateDX11DevManager() { |
801 // The device may exist if the last state was a config change. | 801 // The device may exist if the last state was a config change. |
802 if (D3D11Device()) | 802 if (D3D11Device()) |
803 return true; | 803 return true; |
804 HRESULT hr = create_dxgi_device_manager_(&dx11_dev_manager_reset_token_, | 804 HRESULT hr = create_dxgi_device_manager_( |
805 d3d11_device_manager_.Receive()); | 805 &dx11_dev_manager_reset_token_, d3d11_device_manager_.GetAddressOf()); |
806 RETURN_ON_HR_FAILURE(hr, "MFCreateDXGIDeviceManager failed", false); | 806 RETURN_ON_HR_FAILURE(hr, "MFCreateDXGIDeviceManager failed", false); |
807 | 807 |
808 angle_device_ = gl::QueryD3D11DeviceObjectFromANGLE(); | 808 angle_device_ = gl::QueryD3D11DeviceObjectFromANGLE(); |
809 if (!angle_device_) | 809 if (!angle_device_) |
810 copy_nv12_textures_ = false; | 810 copy_nv12_textures_ = false; |
811 if (share_nv12_textures_) { | 811 if (share_nv12_textures_) { |
812 RETURN_ON_FAILURE(angle_device_.Get(), "Failed to get d3d11 device", false); | 812 RETURN_ON_FAILURE(angle_device_.Get(), "Failed to get d3d11 device", false); |
813 | 813 |
814 using_angle_device_ = true; | 814 using_angle_device_ = true; |
815 } | 815 } |
816 | 816 |
817 if (use_fp16_ || !share_nv12_textures_) { | 817 if (use_fp16_ || !share_nv12_textures_) { |
818 // This array defines the set of DirectX hardware feature levels we support. | 818 // This array defines the set of DirectX hardware feature levels we support. |
819 // The ordering MUST be preserved. All applications are assumed to support | 819 // The ordering MUST be preserved. All applications are assumed to support |
820 // 9.1 unless otherwise stated by the application. | 820 // 9.1 unless otherwise stated by the application. |
821 D3D_FEATURE_LEVEL feature_levels[] = { | 821 D3D_FEATURE_LEVEL feature_levels[] = { |
822 D3D_FEATURE_LEVEL_11_1, D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_1, | 822 D3D_FEATURE_LEVEL_11_1, D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_1, |
823 D3D_FEATURE_LEVEL_10_0, D3D_FEATURE_LEVEL_9_3, D3D_FEATURE_LEVEL_9_2, | 823 D3D_FEATURE_LEVEL_10_0, D3D_FEATURE_LEVEL_9_3, D3D_FEATURE_LEVEL_9_2, |
824 D3D_FEATURE_LEVEL_9_1}; | 824 D3D_FEATURE_LEVEL_9_1}; |
825 | 825 |
826 UINT flags = D3D11_CREATE_DEVICE_VIDEO_SUPPORT; | 826 UINT flags = D3D11_CREATE_DEVICE_VIDEO_SUPPORT; |
827 | 827 |
828 D3D_FEATURE_LEVEL feature_level_out = D3D_FEATURE_LEVEL_11_0; | 828 D3D_FEATURE_LEVEL feature_level_out = D3D_FEATURE_LEVEL_11_0; |
829 #if defined _DEBUG | 829 #if defined _DEBUG |
830 flags |= D3D11_CREATE_DEVICE_DEBUG; | 830 flags |= D3D11_CREATE_DEVICE_DEBUG; |
831 | 831 |
832 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, flags, | 832 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, flags, |
833 feature_levels, arraysize(feature_levels), | 833 feature_levels, arraysize(feature_levels), |
834 D3D11_SDK_VERSION, d3d11_device_.Receive(), | 834 D3D11_SDK_VERSION, d3d11_device_.GetAddressOf(), |
835 &feature_level_out, d3d11_device_context_.Receive()); | 835 &feature_level_out, |
| 836 d3d11_device_context_.GetAddressOf()); |
836 if (hr == DXGI_ERROR_SDK_COMPONENT_MISSING) { | 837 if (hr == DXGI_ERROR_SDK_COMPONENT_MISSING) { |
837 LOG(ERROR) | 838 LOG(ERROR) |
838 << "Debug DXGI device creation failed, falling back to release."; | 839 << "Debug DXGI device creation failed, falling back to release."; |
839 flags &= ~D3D11_CREATE_DEVICE_DEBUG; | 840 flags &= ~D3D11_CREATE_DEVICE_DEBUG; |
840 } else { | 841 } else { |
841 RETURN_ON_HR_FAILURE(hr, "Failed to create debug DX11 device", false); | 842 RETURN_ON_HR_FAILURE(hr, "Failed to create debug DX11 device", false); |
842 } | 843 } |
843 #endif | 844 #endif |
844 if (!d3d11_device_context_) { | 845 if (!d3d11_device_context_) { |
845 hr = D3D11CreateDevice( | 846 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, flags, |
846 NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, flags, feature_levels, | 847 feature_levels, arraysize(feature_levels), |
847 arraysize(feature_levels), D3D11_SDK_VERSION, d3d11_device_.Receive(), | 848 D3D11_SDK_VERSION, d3d11_device_.GetAddressOf(), |
848 &feature_level_out, d3d11_device_context_.Receive()); | 849 &feature_level_out, |
| 850 d3d11_device_context_.GetAddressOf()); |
849 RETURN_ON_HR_FAILURE(hr, "Failed to create DX11 device", false); | 851 RETURN_ON_HR_FAILURE(hr, "Failed to create DX11 device", false); |
850 } | 852 } |
851 | 853 |
852 hr = d3d11_device_.CopyTo(video_device_.Receive()); | 854 hr = d3d11_device_.CopyTo(video_device_.GetAddressOf()); |
853 RETURN_ON_HR_FAILURE(hr, "Failed to get video device", false); | 855 RETURN_ON_HR_FAILURE(hr, "Failed to get video device", false); |
854 | 856 |
855 hr = d3d11_device_context_.CopyTo(video_context_.Receive()); | 857 hr = d3d11_device_context_.CopyTo(video_context_.GetAddressOf()); |
856 RETURN_ON_HR_FAILURE(hr, "Failed to get video context", false); | 858 RETURN_ON_HR_FAILURE(hr, "Failed to get video context", false); |
857 } | 859 } |
858 | 860 |
859 D3D11_FEATURE_DATA_D3D11_OPTIONS options; | 861 D3D11_FEATURE_DATA_D3D11_OPTIONS options; |
860 hr = D3D11Device()->CheckFeatureSupport(D3D11_FEATURE_D3D11_OPTIONS, &options, | 862 hr = D3D11Device()->CheckFeatureSupport(D3D11_FEATURE_D3D11_OPTIONS, &options, |
861 sizeof(options)); | 863 sizeof(options)); |
862 RETURN_ON_HR_FAILURE(hr, "Failed to retrieve D3D11 options", false); | 864 RETURN_ON_HR_FAILURE(hr, "Failed to retrieve D3D11 options", false); |
863 | 865 |
864 // Need extended resource sharing so we can share the NV12 texture between | 866 // Need extended resource sharing so we can share the NV12 texture between |
865 // ANGLE and the decoder context. | 867 // ANGLE and the decoder context. |
(...skipping 23 matching lines...) Expand all Loading... |
889 RETURN_ON_HR_FAILURE(hr, "Failed to query ID3D10Multithread", false); | 891 RETURN_ON_HR_FAILURE(hr, "Failed to query ID3D10Multithread", false); |
890 multi_threaded_->SetMultithreadProtected(TRUE); | 892 multi_threaded_->SetMultithreadProtected(TRUE); |
891 | 893 |
892 hr = d3d11_device_manager_->ResetDevice(D3D11Device(), | 894 hr = d3d11_device_manager_->ResetDevice(D3D11Device(), |
893 dx11_dev_manager_reset_token_); | 895 dx11_dev_manager_reset_token_); |
894 RETURN_ON_HR_FAILURE(hr, "Failed to reset device", false); | 896 RETURN_ON_HR_FAILURE(hr, "Failed to reset device", false); |
895 | 897 |
896 D3D11_QUERY_DESC query_desc; | 898 D3D11_QUERY_DESC query_desc; |
897 query_desc.Query = D3D11_QUERY_EVENT; | 899 query_desc.Query = D3D11_QUERY_EVENT; |
898 query_desc.MiscFlags = 0; | 900 query_desc.MiscFlags = 0; |
899 hr = D3D11Device()->CreateQuery(&query_desc, d3d11_query_.Receive()); | 901 hr = D3D11Device()->CreateQuery(&query_desc, d3d11_query_.GetAddressOf()); |
900 RETURN_ON_HR_FAILURE(hr, "Failed to create DX11 device query", false); | 902 RETURN_ON_HR_FAILURE(hr, "Failed to create DX11 device query", false); |
901 | 903 |
902 return true; | 904 return true; |
903 } | 905 } |
904 | 906 |
905 void DXVAVideoDecodeAccelerator::Decode( | 907 void DXVAVideoDecodeAccelerator::Decode( |
906 const BitstreamBuffer& bitstream_buffer) { | 908 const BitstreamBuffer& bitstream_buffer) { |
907 TRACE_EVENT0("media", "DXVAVideoDecodeAccelerator::Decode"); | 909 TRACE_EVENT0("media", "DXVAVideoDecodeAccelerator::Decode"); |
908 DCHECK(main_thread_task_runner_->BelongsToCurrentThread()); | 910 DCHECK(main_thread_task_runner_->BelongsToCurrentThread()); |
909 | 911 |
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1369 if (FAILED(hr) || config_count == 0) | 1371 if (FAILED(hr) || config_count == 0) |
1370 return max_resolution; | 1372 return max_resolution; |
1371 | 1373 |
1372 D3D11_VIDEO_DECODER_CONFIG config = {}; | 1374 D3D11_VIDEO_DECODER_CONFIG config = {}; |
1373 hr = video_device->GetVideoDecoderConfig(&desc, 0, &config); | 1375 hr = video_device->GetVideoDecoderConfig(&desc, 0, &config); |
1374 if (FAILED(hr)) | 1376 if (FAILED(hr)) |
1375 return max_resolution; | 1377 return max_resolution; |
1376 | 1378 |
1377 base::win::ScopedComPtr<ID3D11VideoDecoder> video_decoder; | 1379 base::win::ScopedComPtr<ID3D11VideoDecoder> video_decoder; |
1378 hr = video_device->CreateVideoDecoder(&desc, &config, | 1380 hr = video_device->CreateVideoDecoder(&desc, &config, |
1379 video_decoder.Receive()); | 1381 video_decoder.GetAddressOf()); |
1380 if (!video_decoder.Get()) | 1382 if (!video_decoder.Get()) |
1381 return max_resolution; | 1383 return max_resolution; |
1382 | 1384 |
1383 max_resolution = resolution_array[res_idx]; | 1385 max_resolution = resolution_array[res_idx]; |
1384 } | 1386 } |
1385 } | 1387 } |
1386 return max_resolution; | 1388 return max_resolution; |
1387 } | 1389 } |
1388 | 1390 |
1389 // static | 1391 // static |
(...skipping 10 matching lines...) Expand all Loading... |
1400 return legacy_gpu; | 1402 return legacy_gpu; |
1401 | 1403 |
1402 legacy_gpu_determined = true; | 1404 legacy_gpu_determined = true; |
1403 | 1405 |
1404 base::win::ScopedComPtr<IDXGIDevice> dxgi_device; | 1406 base::win::ScopedComPtr<IDXGIDevice> dxgi_device; |
1405 HRESULT hr = dxgi_device.QueryFrom(device); | 1407 HRESULT hr = dxgi_device.QueryFrom(device); |
1406 if (FAILED(hr)) | 1408 if (FAILED(hr)) |
1407 return legacy_gpu; | 1409 return legacy_gpu; |
1408 | 1410 |
1409 base::win::ScopedComPtr<IDXGIAdapter> adapter; | 1411 base::win::ScopedComPtr<IDXGIAdapter> adapter; |
1410 hr = dxgi_device->GetAdapter(adapter.Receive()); | 1412 hr = dxgi_device->GetAdapter(adapter.GetAddressOf()); |
1411 if (FAILED(hr)) | 1413 if (FAILED(hr)) |
1412 return legacy_gpu; | 1414 return legacy_gpu; |
1413 | 1415 |
1414 DXGI_ADAPTER_DESC adapter_desc = {}; | 1416 DXGI_ADAPTER_DESC adapter_desc = {}; |
1415 hr = adapter->GetDesc(&adapter_desc); | 1417 hr = adapter->GetDesc(&adapter_desc); |
1416 if (FAILED(hr)) | 1418 if (FAILED(hr)) |
1417 return legacy_gpu; | 1419 return legacy_gpu; |
1418 | 1420 |
1419 // We check if the device is an Intel or an AMD device and whether it is in | 1421 // We check if the device is an Intel or an AMD device and whether it is in |
1420 // the global list defined by the g_AMDUVD3GPUList and g_IntelLegacyGPUList | 1422 // the global list defined by the g_AMDUVD3GPUList and g_IntelLegacyGPUList |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1590 // TODO(hubbe): Share/copy P010/P016 textures. | 1592 // TODO(hubbe): Share/copy P010/P016 textures. |
1591 share_nv12_textures_ = false; | 1593 share_nv12_textures_ = false; |
1592 copy_nv12_textures_ = false; | 1594 copy_nv12_textures_ = false; |
1593 } | 1595 } |
1594 | 1596 |
1595 return SetDecoderMediaTypes(); | 1597 return SetDecoderMediaTypes(); |
1596 } | 1598 } |
1597 | 1599 |
1598 bool DXVAVideoDecodeAccelerator::CheckDecoderDxvaSupport() { | 1600 bool DXVAVideoDecodeAccelerator::CheckDecoderDxvaSupport() { |
1599 base::win::ScopedComPtr<IMFAttributes> attributes; | 1601 base::win::ScopedComPtr<IMFAttributes> attributes; |
1600 HRESULT hr = decoder_->GetAttributes(attributes.Receive()); | 1602 HRESULT hr = decoder_->GetAttributes(attributes.GetAddressOf()); |
1601 RETURN_ON_HR_FAILURE(hr, "Failed to get decoder attributes", false); | 1603 RETURN_ON_HR_FAILURE(hr, "Failed to get decoder attributes", false); |
1602 | 1604 |
1603 UINT32 dxva = 0; | 1605 UINT32 dxva = 0; |
1604 hr = attributes->GetUINT32(MF_SA_D3D_AWARE, &dxva); | 1606 hr = attributes->GetUINT32(MF_SA_D3D_AWARE, &dxva); |
1605 RETURN_ON_HR_FAILURE(hr, "Failed to check if decoder supports DXVA", false); | 1607 RETURN_ON_HR_FAILURE(hr, "Failed to check if decoder supports DXVA", false); |
1606 | 1608 |
1607 if (codec_ == kCodecH264) { | 1609 if (codec_ == kCodecH264) { |
1608 hr = attributes->SetUINT32(CODECAPI_AVDecVideoAcceleration_H264, TRUE); | 1610 hr = attributes->SetUINT32(CODECAPI_AVDecVideoAcceleration_H264, TRUE); |
1609 RETURN_ON_HR_FAILURE(hr, "Failed to enable DXVA H/W decoding", false); | 1611 RETURN_ON_HR_FAILURE(hr, "Failed to enable DXVA H/W decoding", false); |
1610 } | 1612 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1657 bool DXVAVideoDecodeAccelerator::SetDecoderMediaTypes() { | 1659 bool DXVAVideoDecodeAccelerator::SetDecoderMediaTypes() { |
1658 RETURN_ON_FAILURE(SetDecoderInputMediaType(), | 1660 RETURN_ON_FAILURE(SetDecoderInputMediaType(), |
1659 "Failed to set decoder input media type", false); | 1661 "Failed to set decoder input media type", false); |
1660 return SetDecoderOutputMediaType(MFVideoFormat_NV12) || | 1662 return SetDecoderOutputMediaType(MFVideoFormat_NV12) || |
1661 SetDecoderOutputMediaType(MFVideoFormat_P010) || | 1663 SetDecoderOutputMediaType(MFVideoFormat_P010) || |
1662 SetDecoderOutputMediaType(MFVideoFormat_P016); | 1664 SetDecoderOutputMediaType(MFVideoFormat_P016); |
1663 } | 1665 } |
1664 | 1666 |
1665 bool DXVAVideoDecodeAccelerator::SetDecoderInputMediaType() { | 1667 bool DXVAVideoDecodeAccelerator::SetDecoderInputMediaType() { |
1666 base::win::ScopedComPtr<IMFMediaType> media_type; | 1668 base::win::ScopedComPtr<IMFMediaType> media_type; |
1667 HRESULT hr = MFCreateMediaType(media_type.Receive()); | 1669 HRESULT hr = MFCreateMediaType(media_type.GetAddressOf()); |
1668 RETURN_ON_HR_FAILURE(hr, "MFCreateMediaType failed", false); | 1670 RETURN_ON_HR_FAILURE(hr, "MFCreateMediaType failed", false); |
1669 | 1671 |
1670 hr = media_type->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video); | 1672 hr = media_type->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video); |
1671 RETURN_ON_HR_FAILURE(hr, "Failed to set major input type", false); | 1673 RETURN_ON_HR_FAILURE(hr, "Failed to set major input type", false); |
1672 | 1674 |
1673 if (codec_ == kCodecH264) { | 1675 if (codec_ == kCodecH264) { |
1674 hr = media_type->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_H264); | 1676 hr = media_type->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_H264); |
1675 } else if (codec_ == kCodecVP8) { | 1677 } else if (codec_ == kCodecVP8) { |
1676 hr = media_type->SetGUID(MF_MT_SUBTYPE, MEDIASUBTYPE_VP80); | 1678 hr = media_type->SetGUID(MF_MT_SUBTYPE, MEDIASUBTYPE_VP80); |
1677 } else if (codec_ == kCodecVP9) { | 1679 } else if (codec_ == kCodecVP9) { |
(...skipping 26 matching lines...) Expand all Loading... |
1704 return true; | 1706 return true; |
1705 } | 1707 } |
1706 | 1708 |
1707 bool DXVAVideoDecodeAccelerator::SetDecoderOutputMediaType( | 1709 bool DXVAVideoDecodeAccelerator::SetDecoderOutputMediaType( |
1708 const GUID& subtype) { | 1710 const GUID& subtype) { |
1709 bool result = SetTransformOutputType(decoder_.Get(), subtype, 0, 0); | 1711 bool result = SetTransformOutputType(decoder_.Get(), subtype, 0, 0); |
1710 | 1712 |
1711 if (share_nv12_textures_) { | 1713 if (share_nv12_textures_) { |
1712 base::win::ScopedComPtr<IMFAttributes> out_attributes; | 1714 base::win::ScopedComPtr<IMFAttributes> out_attributes; |
1713 HRESULT hr = | 1715 HRESULT hr = |
1714 decoder_->GetOutputStreamAttributes(0, out_attributes.Receive()); | 1716 decoder_->GetOutputStreamAttributes(0, out_attributes.GetAddressOf()); |
1715 RETURN_ON_HR_FAILURE(hr, "Failed to get stream attributes", false); | 1717 RETURN_ON_HR_FAILURE(hr, "Failed to get stream attributes", false); |
1716 out_attributes->SetUINT32(MF_SA_D3D11_BINDFLAGS, | 1718 out_attributes->SetUINT32(MF_SA_D3D11_BINDFLAGS, |
1717 D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DECODER); | 1719 D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DECODER); |
1718 // For some reason newer Intel drivers need D3D11_BIND_DECODER textures to | 1720 // For some reason newer Intel drivers need D3D11_BIND_DECODER textures to |
1719 // be created with a share handle or they'll crash in | 1721 // be created with a share handle or they'll crash in |
1720 // CreateShaderResourceView. Technically MF_SA_D3D11_SHARED_WITHOUT_MUTEX | 1722 // CreateShaderResourceView. Technically MF_SA_D3D11_SHARED_WITHOUT_MUTEX |
1721 // is only honored by the sample allocator, not by the media foundation | 1723 // is only honored by the sample allocator, not by the media foundation |
1722 // transform, but Microsoft's h.264 transform happens to pass it through. | 1724 // transform, but Microsoft's h.264 transform happens to pass it through. |
1723 out_attributes->SetUINT32(MF_SA_D3D11_SHARED_WITHOUT_MUTEX, TRUE); | 1725 out_attributes->SetUINT32(MF_SA_D3D11_SHARED_WITHOUT_MUTEX, TRUE); |
1724 } | 1726 } |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1941 FROM_HERE, | 1943 FROM_HERE, |
1942 base::Bind(&DXVAVideoDecodeAccelerator::BindPictureBufferToSample, | 1944 base::Bind(&DXVAVideoDecodeAccelerator::BindPictureBufferToSample, |
1943 weak_ptr_, pending_sample->output_sample, | 1945 weak_ptr_, pending_sample->output_sample, |
1944 pending_sample->picture_buffer_id, | 1946 pending_sample->picture_buffer_id, |
1945 pending_sample->input_buffer_id)); | 1947 pending_sample->input_buffer_id)); |
1946 continue; | 1948 continue; |
1947 } | 1949 } |
1948 | 1950 |
1949 base::win::ScopedComPtr<IMFMediaBuffer> output_buffer; | 1951 base::win::ScopedComPtr<IMFMediaBuffer> output_buffer; |
1950 HRESULT hr = pending_sample->output_sample->GetBufferByIndex( | 1952 HRESULT hr = pending_sample->output_sample->GetBufferByIndex( |
1951 0, output_buffer.Receive()); | 1953 0, output_buffer.GetAddressOf()); |
1952 RETURN_AND_NOTIFY_ON_HR_FAILURE( | 1954 RETURN_AND_NOTIFY_ON_HR_FAILURE( |
1953 hr, "Failed to get buffer from output sample", PLATFORM_FAILURE, ); | 1955 hr, "Failed to get buffer from output sample", PLATFORM_FAILURE, ); |
1954 | 1956 |
1955 base::win::ScopedComPtr<IDirect3DSurface9> surface; | 1957 base::win::ScopedComPtr<IDirect3DSurface9> surface; |
1956 base::win::ScopedComPtr<ID3D11Texture2D> d3d11_texture; | 1958 base::win::ScopedComPtr<ID3D11Texture2D> d3d11_texture; |
1957 | 1959 |
1958 if (use_dx11_) { | 1960 if (use_dx11_) { |
1959 base::win::ScopedComPtr<IMFDXGIBuffer> dxgi_buffer; | 1961 base::win::ScopedComPtr<IMFDXGIBuffer> dxgi_buffer; |
1960 hr = dxgi_buffer.QueryFrom(output_buffer.Get()); | 1962 hr = dxgi_buffer.QueryFrom(output_buffer.Get()); |
1961 RETURN_AND_NOTIFY_ON_HR_FAILURE( | 1963 RETURN_AND_NOTIFY_ON_HR_FAILURE( |
1962 hr, "Failed to get DXGIBuffer from output sample", | 1964 hr, "Failed to get DXGIBuffer from output sample", |
1963 PLATFORM_FAILURE, ); | 1965 PLATFORM_FAILURE, ); |
1964 hr = dxgi_buffer->GetResource( | 1966 hr = dxgi_buffer->GetResource( |
1965 __uuidof(ID3D11Texture2D), | 1967 __uuidof(ID3D11Texture2D), |
1966 reinterpret_cast<void**>(d3d11_texture.Receive())); | 1968 reinterpret_cast<void**>(d3d11_texture.GetAddressOf())); |
1967 } else { | 1969 } else { |
1968 hr = MFGetService(output_buffer.Get(), MR_BUFFER_SERVICE, | 1970 hr = MFGetService(output_buffer.Get(), MR_BUFFER_SERVICE, |
1969 IID_PPV_ARGS(surface.Receive())); | 1971 IID_PPV_ARGS(surface.GetAddressOf())); |
1970 } | 1972 } |
1971 RETURN_AND_NOTIFY_ON_HR_FAILURE( | 1973 RETURN_AND_NOTIFY_ON_HR_FAILURE( |
1972 hr, "Failed to get surface from output sample", PLATFORM_FAILURE, ); | 1974 hr, "Failed to get surface from output sample", PLATFORM_FAILURE, ); |
1973 | 1975 |
1974 RETURN_AND_NOTIFY_ON_FAILURE( | 1976 RETURN_AND_NOTIFY_ON_FAILURE( |
1975 index->second->CopyOutputSampleDataToPictureBuffer( | 1977 index->second->CopyOutputSampleDataToPictureBuffer( |
1976 this, surface.Get(), d3d11_texture.Get(), | 1978 this, surface.Get(), d3d11_texture.Get(), |
1977 pending_sample->input_buffer_id), | 1979 pending_sample->input_buffer_id), |
1978 "Failed to copy output sample", PLATFORM_FAILURE, ); | 1980 "Failed to copy output sample", PLATFORM_FAILURE, ); |
1979 } | 1981 } |
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2680 | 2682 |
2681 if (dest_keyed_mutex) { | 2683 if (dest_keyed_mutex) { |
2682 HRESULT hr = | 2684 HRESULT hr = |
2683 dest_keyed_mutex->AcquireSync(keyed_mutex_value, kAcquireSyncWaitMs); | 2685 dest_keyed_mutex->AcquireSync(keyed_mutex_value, kAcquireSyncWaitMs); |
2684 RETURN_AND_NOTIFY_ON_FAILURE( | 2686 RETURN_AND_NOTIFY_ON_FAILURE( |
2685 hr == S_OK, "D3D11 failed to acquire keyed mutex for texture.", | 2687 hr == S_OK, "D3D11 failed to acquire keyed mutex for texture.", |
2686 PLATFORM_FAILURE, ); | 2688 PLATFORM_FAILURE, ); |
2687 } | 2689 } |
2688 | 2690 |
2689 base::win::ScopedComPtr<IMFMediaBuffer> output_buffer; | 2691 base::win::ScopedComPtr<IMFMediaBuffer> output_buffer; |
2690 hr = input_sample->GetBufferByIndex(0, output_buffer.Receive()); | 2692 hr = input_sample->GetBufferByIndex(0, output_buffer.GetAddressOf()); |
2691 RETURN_AND_NOTIFY_ON_HR_FAILURE(hr, "Failed to get buffer from output sample", | 2693 RETURN_AND_NOTIFY_ON_HR_FAILURE(hr, "Failed to get buffer from output sample", |
2692 PLATFORM_FAILURE, ); | 2694 PLATFORM_FAILURE, ); |
2693 | 2695 |
2694 base::win::ScopedComPtr<IMFDXGIBuffer> dxgi_buffer; | 2696 base::win::ScopedComPtr<IMFDXGIBuffer> dxgi_buffer; |
2695 hr = dxgi_buffer.QueryFrom(output_buffer.Get()); | 2697 hr = dxgi_buffer.QueryFrom(output_buffer.Get()); |
2696 RETURN_AND_NOTIFY_ON_HR_FAILURE( | 2698 RETURN_AND_NOTIFY_ON_HR_FAILURE( |
2697 hr, "Failed to get DXGIBuffer from output sample", PLATFORM_FAILURE, ); | 2699 hr, "Failed to get DXGIBuffer from output sample", PLATFORM_FAILURE, ); |
2698 UINT index = 0; | 2700 UINT index = 0; |
2699 hr = dxgi_buffer->GetSubresourceIndex(&index); | 2701 hr = dxgi_buffer->GetSubresourceIndex(&index); |
2700 RETURN_AND_NOTIFY_ON_HR_FAILURE(hr, "Failed to get resource index", | 2702 RETURN_AND_NOTIFY_ON_HR_FAILURE(hr, "Failed to get resource index", |
2701 PLATFORM_FAILURE, ); | 2703 PLATFORM_FAILURE, ); |
2702 | 2704 |
2703 base::win::ScopedComPtr<ID3D11Texture2D> dx11_decoding_texture; | 2705 base::win::ScopedComPtr<ID3D11Texture2D> dx11_decoding_texture; |
2704 hr = dxgi_buffer->GetResource(IID_PPV_ARGS(dx11_decoding_texture.Receive())); | 2706 hr = dxgi_buffer->GetResource( |
| 2707 IID_PPV_ARGS(dx11_decoding_texture.GetAddressOf())); |
2705 RETURN_AND_NOTIFY_ON_HR_FAILURE( | 2708 RETURN_AND_NOTIFY_ON_HR_FAILURE( |
2706 hr, "Failed to get resource from output sample", PLATFORM_FAILURE, ); | 2709 hr, "Failed to get resource from output sample", PLATFORM_FAILURE, ); |
2707 | 2710 |
2708 D3D11_VIDEO_PROCESSOR_OUTPUT_VIEW_DESC output_view_desc = { | 2711 D3D11_VIDEO_PROCESSOR_OUTPUT_VIEW_DESC output_view_desc = { |
2709 D3D11_VPOV_DIMENSION_TEXTURE2D}; | 2712 D3D11_VPOV_DIMENSION_TEXTURE2D}; |
2710 output_view_desc.Texture2D.MipSlice = 0; | 2713 output_view_desc.Texture2D.MipSlice = 0; |
2711 base::win::ScopedComPtr<ID3D11VideoProcessorOutputView> output_view; | 2714 base::win::ScopedComPtr<ID3D11VideoProcessorOutputView> output_view; |
2712 hr = video_device_->CreateVideoProcessorOutputView( | 2715 hr = video_device_->CreateVideoProcessorOutputView( |
2713 dest_texture, enumerator_.Get(), &output_view_desc, | 2716 dest_texture, enumerator_.Get(), &output_view_desc, |
2714 output_view.Receive()); | 2717 output_view.GetAddressOf()); |
2715 RETURN_AND_NOTIFY_ON_HR_FAILURE(hr, "Failed to get output view", | 2718 RETURN_AND_NOTIFY_ON_HR_FAILURE(hr, "Failed to get output view", |
2716 PLATFORM_FAILURE, ); | 2719 PLATFORM_FAILURE, ); |
2717 | 2720 |
2718 D3D11_VIDEO_PROCESSOR_INPUT_VIEW_DESC input_view_desc = {0}; | 2721 D3D11_VIDEO_PROCESSOR_INPUT_VIEW_DESC input_view_desc = {0}; |
2719 input_view_desc.ViewDimension = D3D11_VPIV_DIMENSION_TEXTURE2D; | 2722 input_view_desc.ViewDimension = D3D11_VPIV_DIMENSION_TEXTURE2D; |
2720 input_view_desc.Texture2D.ArraySlice = index; | 2723 input_view_desc.Texture2D.ArraySlice = index; |
2721 input_view_desc.Texture2D.MipSlice = 0; | 2724 input_view_desc.Texture2D.MipSlice = 0; |
2722 base::win::ScopedComPtr<ID3D11VideoProcessorInputView> input_view; | 2725 base::win::ScopedComPtr<ID3D11VideoProcessorInputView> input_view; |
2723 hr = video_device_->CreateVideoProcessorInputView( | 2726 hr = video_device_->CreateVideoProcessorInputView( |
2724 dx11_decoding_texture.Get(), enumerator_.Get(), &input_view_desc, | 2727 dx11_decoding_texture.Get(), enumerator_.Get(), &input_view_desc, |
2725 input_view.Receive()); | 2728 input_view.GetAddressOf()); |
2726 RETURN_AND_NOTIFY_ON_HR_FAILURE(hr, "Failed to get input view", | 2729 RETURN_AND_NOTIFY_ON_HR_FAILURE(hr, "Failed to get input view", |
2727 PLATFORM_FAILURE, ); | 2730 PLATFORM_FAILURE, ); |
2728 | 2731 |
2729 D3D11_VIDEO_PROCESSOR_STREAM streams = {0}; | 2732 D3D11_VIDEO_PROCESSOR_STREAM streams = {0}; |
2730 streams.Enable = TRUE; | 2733 streams.Enable = TRUE; |
2731 streams.pInputSurface = input_view.Get(); | 2734 streams.pInputSurface = input_view.Get(); |
2732 | 2735 |
2733 hr = video_context_->VideoProcessorBlt(d3d11_processor_.Get(), | 2736 hr = video_context_->VideoProcessorBlt(d3d11_processor_.Get(), |
2734 output_view.Get(), 0, 1, &streams); | 2737 output_view.Get(), 0, 1, &streams); |
2735 | 2738 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2823 desc.InputFrameRate.Denominator = 1; | 2826 desc.InputFrameRate.Denominator = 1; |
2824 desc.InputWidth = width; | 2827 desc.InputWidth = width; |
2825 desc.InputHeight = height; | 2828 desc.InputHeight = height; |
2826 desc.OutputFrameRate.Numerator = 60; | 2829 desc.OutputFrameRate.Numerator = 60; |
2827 desc.OutputFrameRate.Denominator = 1; | 2830 desc.OutputFrameRate.Denominator = 1; |
2828 desc.OutputWidth = width; | 2831 desc.OutputWidth = width; |
2829 desc.OutputHeight = height; | 2832 desc.OutputHeight = height; |
2830 desc.Usage = D3D11_VIDEO_USAGE_PLAYBACK_NORMAL; | 2833 desc.Usage = D3D11_VIDEO_USAGE_PLAYBACK_NORMAL; |
2831 | 2834 |
2832 HRESULT hr = video_device_->CreateVideoProcessorEnumerator( | 2835 HRESULT hr = video_device_->CreateVideoProcessorEnumerator( |
2833 &desc, enumerator_.Receive()); | 2836 &desc, enumerator_.GetAddressOf()); |
2834 RETURN_ON_HR_FAILURE(hr, "Failed to enumerate video processors", false); | 2837 RETURN_ON_HR_FAILURE(hr, "Failed to enumerate video processors", false); |
2835 | 2838 |
2836 // TODO(Hubbe): Find correct index | 2839 // TODO(Hubbe): Find correct index |
2837 hr = video_device_->CreateVideoProcessor(enumerator_.Get(), 0, | 2840 hr = video_device_->CreateVideoProcessor(enumerator_.Get(), 0, |
2838 d3d11_processor_.Receive()); | 2841 d3d11_processor_.GetAddressOf()); |
2839 RETURN_ON_HR_FAILURE(hr, "Failed to create video processor.", false); | 2842 RETURN_ON_HR_FAILURE(hr, "Failed to create video processor.", false); |
2840 processor_width_ = width; | 2843 processor_width_ = width; |
2841 processor_height_ = height; | 2844 processor_height_ = height; |
2842 | 2845 |
2843 video_context_->VideoProcessorSetStreamAutoProcessingMode( | 2846 video_context_->VideoProcessorSetStreamAutoProcessingMode( |
2844 d3d11_processor_.Get(), 0, false); | 2847 d3d11_processor_.Get(), 0, false); |
2845 } | 2848 } |
2846 | 2849 |
2847 if (copy_nv12_textures_) { | 2850 if (copy_nv12_textures_) { |
2848 // If we're copying NV12 textures, make sure we set the same | 2851 // If we're copying NV12 textures, make sure we set the same |
2849 // color space on input and output. | 2852 // color space on input and output. |
2850 D3D11_VIDEO_PROCESSOR_COLOR_SPACE d3d11_color_space = {0}; | 2853 D3D11_VIDEO_PROCESSOR_COLOR_SPACE d3d11_color_space = {0}; |
2851 d3d11_color_space.RGB_Range = 1; | 2854 d3d11_color_space.RGB_Range = 1; |
2852 d3d11_color_space.Nominal_Range = D3D11_VIDEO_PROCESSOR_NOMINAL_RANGE_0_255; | 2855 d3d11_color_space.Nominal_Range = D3D11_VIDEO_PROCESSOR_NOMINAL_RANGE_0_255; |
2853 | 2856 |
2854 video_context_->VideoProcessorSetOutputColorSpace(d3d11_processor_.Get(), | 2857 video_context_->VideoProcessorSetOutputColorSpace(d3d11_processor_.Get(), |
2855 &d3d11_color_space); | 2858 &d3d11_color_space); |
2856 | 2859 |
2857 video_context_->VideoProcessorSetStreamColorSpace(d3d11_processor_.Get(), 0, | 2860 video_context_->VideoProcessorSetStreamColorSpace(d3d11_processor_.Get(), 0, |
2858 &d3d11_color_space); | 2861 &d3d11_color_space); |
2859 dx11_converter_output_color_space_ = color_space; | 2862 dx11_converter_output_color_space_ = color_space; |
2860 } else { | 2863 } else { |
2861 dx11_converter_output_color_space_ = gfx::ColorSpace::CreateSRGB(); | 2864 dx11_converter_output_color_space_ = gfx::ColorSpace::CreateSRGB(); |
2862 if (use_color_info_ || use_fp16_) { | 2865 if (use_color_info_ || use_fp16_) { |
2863 base::win::ScopedComPtr<ID3D11VideoContext1> video_context1; | 2866 base::win::ScopedComPtr<ID3D11VideoContext1> video_context1; |
2864 HRESULT hr = video_context_.CopyTo(video_context1.Receive()); | 2867 HRESULT hr = video_context_.CopyTo(video_context1.GetAddressOf()); |
2865 if (SUCCEEDED(hr)) { | 2868 if (SUCCEEDED(hr)) { |
2866 if (use_fp16_ && | 2869 if (use_fp16_ && |
2867 base::CommandLine::ForCurrentProcess()->HasSwitch( | 2870 base::CommandLine::ForCurrentProcess()->HasSwitch( |
2868 switches::kEnableHDR) && | 2871 switches::kEnableHDR) && |
2869 color_space.IsHDR()) { | 2872 color_space.IsHDR()) { |
2870 // Note, we only use the SCRGBLinear output color space when | 2873 // Note, we only use the SCRGBLinear output color space when |
2871 // the input is PQ, because nvidia drivers will not convert | 2874 // the input is PQ, because nvidia drivers will not convert |
2872 // G22 to G10 for some reason. | 2875 // G22 to G10 for some reason. |
2873 dx11_converter_output_color_space_ = | 2876 dx11_converter_output_color_space_ = |
2874 gfx::ColorSpace::CreateSCRGBLinear(); | 2877 gfx::ColorSpace::CreateSCRGBLinear(); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2916 } | 2919 } |
2917 } | 2920 } |
2918 } | 2921 } |
2919 return true; | 2922 return true; |
2920 } | 2923 } |
2921 | 2924 |
2922 bool DXVAVideoDecodeAccelerator::GetVideoFrameDimensions(IMFSample* sample, | 2925 bool DXVAVideoDecodeAccelerator::GetVideoFrameDimensions(IMFSample* sample, |
2923 int* width, | 2926 int* width, |
2924 int* height) { | 2927 int* height) { |
2925 base::win::ScopedComPtr<IMFMediaBuffer> output_buffer; | 2928 base::win::ScopedComPtr<IMFMediaBuffer> output_buffer; |
2926 HRESULT hr = sample->GetBufferByIndex(0, output_buffer.Receive()); | 2929 HRESULT hr = sample->GetBufferByIndex(0, output_buffer.GetAddressOf()); |
2927 RETURN_ON_HR_FAILURE(hr, "Failed to get buffer from output sample", false); | 2930 RETURN_ON_HR_FAILURE(hr, "Failed to get buffer from output sample", false); |
2928 | 2931 |
2929 if (use_dx11_) { | 2932 if (use_dx11_) { |
2930 base::win::ScopedComPtr<IMFDXGIBuffer> dxgi_buffer; | 2933 base::win::ScopedComPtr<IMFDXGIBuffer> dxgi_buffer; |
2931 base::win::ScopedComPtr<ID3D11Texture2D> d3d11_texture; | 2934 base::win::ScopedComPtr<ID3D11Texture2D> d3d11_texture; |
2932 hr = dxgi_buffer.QueryFrom(output_buffer.Get()); | 2935 hr = dxgi_buffer.QueryFrom(output_buffer.Get()); |
2933 RETURN_ON_HR_FAILURE(hr, "Failed to get DXGIBuffer from output sample", | 2936 RETURN_ON_HR_FAILURE(hr, "Failed to get DXGIBuffer from output sample", |
2934 false); | 2937 false); |
2935 hr = dxgi_buffer->GetResource( | 2938 hr = dxgi_buffer->GetResource( |
2936 __uuidof(ID3D11Texture2D), | 2939 __uuidof(ID3D11Texture2D), |
2937 reinterpret_cast<void**>(d3d11_texture.Receive())); | 2940 reinterpret_cast<void**>(d3d11_texture.GetAddressOf())); |
2938 RETURN_ON_HR_FAILURE(hr, "Failed to get D3D11Texture from output buffer", | 2941 RETURN_ON_HR_FAILURE(hr, "Failed to get D3D11Texture from output buffer", |
2939 false); | 2942 false); |
2940 D3D11_TEXTURE2D_DESC d3d11_texture_desc; | 2943 D3D11_TEXTURE2D_DESC d3d11_texture_desc; |
2941 d3d11_texture->GetDesc(&d3d11_texture_desc); | 2944 d3d11_texture->GetDesc(&d3d11_texture_desc); |
2942 *width = d3d11_texture_desc.Width; | 2945 *width = d3d11_texture_desc.Width; |
2943 *height = d3d11_texture_desc.Height; | 2946 *height = d3d11_texture_desc.Height; |
2944 output_array_size_ = d3d11_texture_desc.ArraySize; | 2947 output_array_size_ = d3d11_texture_desc.ArraySize; |
2945 } else { | 2948 } else { |
2946 base::win::ScopedComPtr<IDirect3DSurface9> surface; | 2949 base::win::ScopedComPtr<IDirect3DSurface9> surface; |
2947 hr = MFGetService(output_buffer.Get(), MR_BUFFER_SERVICE, | 2950 hr = MFGetService(output_buffer.Get(), MR_BUFFER_SERVICE, |
2948 IID_PPV_ARGS(surface.Receive())); | 2951 IID_PPV_ARGS(surface.GetAddressOf())); |
2949 RETURN_ON_HR_FAILURE(hr, "Failed to get D3D surface from output sample", | 2952 RETURN_ON_HR_FAILURE(hr, "Failed to get D3D surface from output sample", |
2950 false); | 2953 false); |
2951 D3DSURFACE_DESC surface_desc; | 2954 D3DSURFACE_DESC surface_desc; |
2952 hr = surface->GetDesc(&surface_desc); | 2955 hr = surface->GetDesc(&surface_desc); |
2953 RETURN_ON_HR_FAILURE(hr, "Failed to get surface description", false); | 2956 RETURN_ON_HR_FAILURE(hr, "Failed to get surface description", false); |
2954 *width = surface_desc.Width; | 2957 *width = surface_desc.Width; |
2955 *height = surface_desc.Height; | 2958 *height = surface_desc.Height; |
2956 } | 2959 } |
2957 return true; | 2960 return true; |
2958 } | 2961 } |
2959 | 2962 |
2960 bool DXVAVideoDecodeAccelerator::SetTransformOutputType(IMFTransform* transform, | 2963 bool DXVAVideoDecodeAccelerator::SetTransformOutputType(IMFTransform* transform, |
2961 const GUID& output_type, | 2964 const GUID& output_type, |
2962 int width, | 2965 int width, |
2963 int height) { | 2966 int height) { |
2964 HRESULT hr = E_FAIL; | 2967 HRESULT hr = E_FAIL; |
2965 base::win::ScopedComPtr<IMFMediaType> media_type; | 2968 base::win::ScopedComPtr<IMFMediaType> media_type; |
2966 | 2969 |
2967 for (uint32_t i = 0; | 2970 for (uint32_t i = 0; SUCCEEDED( |
2968 SUCCEEDED(transform->GetOutputAvailableType(0, i, media_type.Receive())); | 2971 transform->GetOutputAvailableType(0, i, media_type.GetAddressOf())); |
2969 ++i) { | 2972 ++i) { |
2970 GUID out_subtype = {0}; | 2973 GUID out_subtype = {0}; |
2971 hr = media_type->GetGUID(MF_MT_SUBTYPE, &out_subtype); | 2974 hr = media_type->GetGUID(MF_MT_SUBTYPE, &out_subtype); |
2972 RETURN_ON_HR_FAILURE(hr, "Failed to get output major type", false); | 2975 RETURN_ON_HR_FAILURE(hr, "Failed to get output major type", false); |
2973 | 2976 |
2974 if (out_subtype == output_type) { | 2977 if (out_subtype == output_type) { |
2975 if (width && height) { | 2978 if (width && height) { |
2976 hr = MFSetAttributeSize(media_type.Get(), MF_MT_FRAME_SIZE, width, | 2979 hr = MFSetAttributeSize(media_type.Get(), MF_MT_FRAME_SIZE, width, |
2977 height); | 2980 height); |
2978 RETURN_ON_HR_FAILURE(hr, "Failed to set media type attributes", false); | 2981 RETURN_ON_HR_FAILURE(hr, "Failed to set media type attributes", false); |
2979 } | 2982 } |
2980 hr = transform->SetOutputType(0, media_type.Get(), 0); // No flags | 2983 hr = transform->SetOutputType(0, media_type.Get(), 0); // No flags |
2981 RETURN_ON_HR_FAILURE(hr, "Failed to set output type", false); | 2984 RETURN_ON_HR_FAILURE(hr, "Failed to set output type", false); |
2982 return true; | 2985 return true; |
2983 } | 2986 } |
2984 media_type.Reset(); | 2987 media_type.Reset(); |
2985 } | 2988 } |
2986 return false; | 2989 return false; |
2987 } | 2990 } |
2988 | 2991 |
2989 HRESULT DXVAVideoDecodeAccelerator::CheckConfigChanged(IMFSample* sample, | 2992 HRESULT DXVAVideoDecodeAccelerator::CheckConfigChanged(IMFSample* sample, |
2990 bool* config_changed) { | 2993 bool* config_changed) { |
2991 if (codec_ != kCodecH264) | 2994 if (codec_ != kCodecH264) |
2992 return S_FALSE; | 2995 return S_FALSE; |
2993 | 2996 |
2994 base::win::ScopedComPtr<IMFMediaBuffer> buffer; | 2997 base::win::ScopedComPtr<IMFMediaBuffer> buffer; |
2995 HRESULT hr = sample->GetBufferByIndex(0, buffer.Receive()); | 2998 HRESULT hr = sample->GetBufferByIndex(0, buffer.GetAddressOf()); |
2996 RETURN_ON_HR_FAILURE(hr, "Failed to get buffer from input sample", hr); | 2999 RETURN_ON_HR_FAILURE(hr, "Failed to get buffer from input sample", hr); |
2997 | 3000 |
2998 mf::MediaBufferScopedPointer scoped_media_buffer(buffer.Get()); | 3001 mf::MediaBufferScopedPointer scoped_media_buffer(buffer.Get()); |
2999 | 3002 |
3000 if (!config_change_detector_->DetectConfig( | 3003 if (!config_change_detector_->DetectConfig( |
3001 scoped_media_buffer.get(), scoped_media_buffer.current_length())) { | 3004 scoped_media_buffer.get(), scoped_media_buffer.current_length())) { |
3002 RETURN_ON_HR_FAILURE(E_FAIL, "Failed to detect H.264 stream config", | 3005 RETURN_ON_HR_FAILURE(E_FAIL, "Failed to detect H.264 stream config", |
3003 E_FAIL); | 3006 E_FAIL); |
3004 } | 3007 } |
3005 *config_changed = config_change_detector_->config_changed(); | 3008 *config_changed = config_change_detector_->config_changed(); |
(...skipping 15 matching lines...) Expand all Loading... |
3021 uint32_t DXVAVideoDecodeAccelerator::GetTextureTarget() const { | 3024 uint32_t DXVAVideoDecodeAccelerator::GetTextureTarget() const { |
3022 bool provide_nv12_textures = share_nv12_textures_ || copy_nv12_textures_; | 3025 bool provide_nv12_textures = share_nv12_textures_ || copy_nv12_textures_; |
3023 return provide_nv12_textures ? GL_TEXTURE_EXTERNAL_OES : GL_TEXTURE_2D; | 3026 return provide_nv12_textures ? GL_TEXTURE_EXTERNAL_OES : GL_TEXTURE_2D; |
3024 } | 3027 } |
3025 | 3028 |
3026 ID3D11Device* DXVAVideoDecodeAccelerator::D3D11Device() const { | 3029 ID3D11Device* DXVAVideoDecodeAccelerator::D3D11Device() const { |
3027 return share_nv12_textures_ ? angle_device_.Get() : d3d11_device_.Get(); | 3030 return share_nv12_textures_ ? angle_device_.Get() : d3d11_device_.Get(); |
3028 } | 3031 } |
3029 | 3032 |
3030 } // namespace media | 3033 } // namespace media |
OLD | NEW |