| 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. |
| 11 #endif // !defined(OS_WIN) | 11 #endif // !defined(OS_WIN) |
| 12 | 12 |
| 13 #include <codecapi.h> | 13 #include <codecapi.h> |
| 14 #include <dxgi1_2.h> | 14 #include <dxgi1_2.h> |
| 15 #include <ks.h> | 15 #include <ks.h> |
| 16 #include <mfapi.h> | 16 #include <mfapi.h> |
| 17 #include <mferror.h> | 17 #include <mferror.h> |
| 18 #include <ntverp.h> | 18 #include <ntverp.h> |
| 19 #include <stddef.h> | 19 #include <stddef.h> |
| 20 #include <string.h> | 20 #include <string.h> |
| 21 #include <wmcodecdsp.h> | 21 #include <wmcodecdsp.h> |
| 22 | 22 |
| 23 #include "base/atomicops.h" |
| 23 #include "base/base_paths_win.h" | 24 #include "base/base_paths_win.h" |
| 24 #include "base/bind.h" | 25 #include "base/bind.h" |
| 25 #include "base/callback.h" | 26 #include "base/callback.h" |
| 26 #include "base/debug/alias.h" | 27 #include "base/debug/alias.h" |
| 28 #include "base/debug/dump_without_crashing.h" |
| 27 #include "base/file_version_info.h" | 29 #include "base/file_version_info.h" |
| 28 #include "base/files/file_path.h" | 30 #include "base/files/file_path.h" |
| 29 #include "base/location.h" | 31 #include "base/location.h" |
| 30 #include "base/logging.h" | 32 #include "base/logging.h" |
| 31 #include "base/macros.h" | 33 #include "base/macros.h" |
| 32 #include "base/memory/shared_memory.h" | 34 #include "base/memory/shared_memory.h" |
| 33 #include "base/path_service.h" | 35 #include "base/path_service.h" |
| 34 #include "base/single_thread_task_runner.h" | 36 #include "base/single_thread_task_runner.h" |
| 35 #include "base/stl_util.h" | 37 #include "base/stl_util.h" |
| 38 #include "base/threading/thread_local_storage.h" |
| 36 #include "base/threading/thread_task_runner_handle.h" | 39 #include "base/threading/thread_task_runner_handle.h" |
| 37 #include "base/trace_event/trace_event.h" | 40 #include "base/trace_event/trace_event.h" |
| 38 #include "base/win/scoped_co_mem.h" | 41 #include "base/win/scoped_co_mem.h" |
| 39 #include "base/win/windows_version.h" | 42 #include "base/win/windows_version.h" |
| 40 #include "build/build_config.h" | 43 #include "build/build_config.h" |
| 41 #include "gpu/command_buffer/service/gpu_preferences.h" | 44 #include "gpu/command_buffer/service/gpu_preferences.h" |
| 42 #include "gpu/config/gpu_driver_bug_workarounds.h" | 45 #include "gpu/config/gpu_driver_bug_workarounds.h" |
| 43 #include "media/base/media_switches.h" | 46 #include "media/base/media_switches.h" |
| 44 #include "media/base/win/mf_helpers.h" | 47 #include "media/base/win/mf_helpers.h" |
| 45 #include "media/base/win/mf_initializer.h" | 48 #include "media/base/win/mf_initializer.h" |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 // Legacy Intel GPUs (Second generation) which have trouble with resolutions | 178 // Legacy Intel GPUs (Second generation) which have trouble with resolutions |
| 176 // higher than 1920 x 1088 | 179 // higher than 1920 x 1088 |
| 177 static const DWORD g_IntelLegacyGPUList[] = { | 180 static const DWORD g_IntelLegacyGPUList[] = { |
| 178 0x102, 0x106, 0x116, 0x126, | 181 0x102, 0x106, 0x116, 0x126, |
| 179 }; | 182 }; |
| 180 | 183 |
| 181 constexpr const wchar_t* const kMediaFoundationVideoDecoderDLLs[] = { | 184 constexpr const wchar_t* const kMediaFoundationVideoDecoderDLLs[] = { |
| 182 L"mf.dll", L"mfplat.dll", L"msmpeg2vdec.dll", | 185 L"mf.dll", L"mfplat.dll", L"msmpeg2vdec.dll", |
| 183 }; | 186 }; |
| 184 | 187 |
| 188 // Vectored exception handlers are global to the entire process, so use TLS to |
| 189 // ensure only the thread with the ScopedExceptionCatcher dumps anything. |
| 190 base::ThreadLocalStorage::StaticSlot g_catcher_tls_slot = TLS_INITIALIZER; |
| 191 |
| 192 base::subtle::Atomic32 g_dump_count; |
| 193 |
| 194 LONG CALLBACK VectoredCrashHandler(EXCEPTION_POINTERS* exception_pointers) { |
| 195 if (g_catcher_tls_slot.Get()) { |
| 196 // Only dump first time to ensure we don't spend a lot of time doing this |
| 197 // if the driver continually causes exceptions. |
| 198 if (base::subtle::Barrier_AtomicIncrement(&g_dump_count, 1) == 1) |
| 199 base::debug::DumpWithoutCrashing(); |
| 200 } |
| 201 return EXCEPTION_CONTINUE_SEARCH; |
| 202 } |
| 203 |
| 204 // The MS VP9 MFT swallows driver exceptions and later hangs because it gets |
| 205 // into a weird state. Add a vectored exception handler so a dump will be |
| 206 // reported. See http://crbug.com/636158 |
| 207 class ScopedExceptionCatcher { |
| 208 public: |
| 209 explicit ScopedExceptionCatcher(bool handle_exception) { |
| 210 if (handle_exception) { |
| 211 DCHECK(g_catcher_tls_slot.initialized()); |
| 212 g_catcher_tls_slot.Set(static_cast<void*>(this)); |
| 213 handler_ = AddVectoredExceptionHandler(1, &VectoredCrashHandler); |
| 214 } |
| 215 } |
| 216 |
| 217 ~ScopedExceptionCatcher() { |
| 218 if (handler_) { |
| 219 g_catcher_tls_slot.Set(nullptr); |
| 220 RemoveVectoredExceptionHandler(handler_); |
| 221 } |
| 222 } |
| 223 |
| 224 private: |
| 225 void* handler_ = nullptr; |
| 226 |
| 227 DISALLOW_COPY_AND_ASSIGN(ScopedExceptionCatcher); |
| 228 }; |
| 229 |
| 185 } // namespace | 230 } // namespace |
| 186 | 231 |
| 187 namespace media { | 232 namespace media { |
| 188 | 233 |
| 189 static const VideoCodecProfile kSupportedProfiles[] = { | 234 static const VideoCodecProfile kSupportedProfiles[] = { |
| 190 H264PROFILE_BASELINE, H264PROFILE_MAIN, H264PROFILE_HIGH, | 235 H264PROFILE_BASELINE, H264PROFILE_MAIN, H264PROFILE_HIGH, |
| 191 VP8PROFILE_ANY, VP9PROFILE_PROFILE0, VP9PROFILE_PROFILE1, | 236 VP8PROFILE_ANY, VP9PROFILE_PROFILE0, VP9PROFILE_PROFILE1, |
| 192 VP9PROFILE_PROFILE2, VP9PROFILE_PROFILE3}; | 237 VP9PROFILE_PROFILE2, VP9PROFILE_PROFILE3}; |
| 193 | 238 |
| 194 CreateDXGIDeviceManager | 239 CreateDXGIDeviceManager |
| (...skipping 1028 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1223 profile.profile = supported_profile; | 1268 profile.profile = supported_profile; |
| 1224 profile.min_resolution.SetSize(min_resolution.first, min_resolution.second); | 1269 profile.min_resolution.SetSize(min_resolution.first, min_resolution.second); |
| 1225 profile.max_resolution.SetSize(max_resolution.first, max_resolution.second); | 1270 profile.max_resolution.SetSize(max_resolution.first, max_resolution.second); |
| 1226 profiles.push_back(profile); | 1271 profiles.push_back(profile); |
| 1227 } | 1272 } |
| 1228 return profiles; | 1273 return profiles; |
| 1229 } | 1274 } |
| 1230 | 1275 |
| 1231 // static | 1276 // static |
| 1232 void DXVAVideoDecodeAccelerator::PreSandboxInitialization() { | 1277 void DXVAVideoDecodeAccelerator::PreSandboxInitialization() { |
| 1278 g_catcher_tls_slot.Initialize(nullptr); |
| 1233 for (const wchar_t* mfdll : kMediaFoundationVideoDecoderDLLs) | 1279 for (const wchar_t* mfdll : kMediaFoundationVideoDecoderDLLs) |
| 1234 ::LoadLibrary(mfdll); | 1280 ::LoadLibrary(mfdll); |
| 1235 ::LoadLibrary(L"dxva2.dll"); | 1281 ::LoadLibrary(L"dxva2.dll"); |
| 1236 | 1282 |
| 1237 if (base::win::GetVersion() > base::win::VERSION_WIN7) { | 1283 if (base::win::GetVersion() > base::win::VERSION_WIN7) { |
| 1238 LoadLibrary(L"msvproc.dll"); | 1284 LoadLibrary(L"msvproc.dll"); |
| 1239 } else { | 1285 } else { |
| 1240 #if defined(ENABLE_DX11_FOR_WIN7) | 1286 #if defined(ENABLE_DX11_FOR_WIN7) |
| 1241 LoadLibrary(L"mshtmlmedia.dll"); | 1287 LoadLibrary(L"mshtmlmedia.dll"); |
| 1242 #endif | 1288 #endif |
| (...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1737 DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); | 1783 DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); |
| 1738 // This function is also called from FlushInternal in a loop which could | 1784 // This function is also called from FlushInternal in a loop which could |
| 1739 // result in the state transitioning to kStopped due to no decoded output. | 1785 // result in the state transitioning to kStopped due to no decoded output. |
| 1740 State state = GetState(); | 1786 State state = GetState(); |
| 1741 RETURN_AND_NOTIFY_ON_FAILURE( | 1787 RETURN_AND_NOTIFY_ON_FAILURE( |
| 1742 (state == kNormal || state == kFlushing || state == kStopped), | 1788 (state == kNormal || state == kFlushing || state == kStopped), |
| 1743 "DoDecode: not in normal/flushing/stopped state", ILLEGAL_STATE, ); | 1789 "DoDecode: not in normal/flushing/stopped state", ILLEGAL_STATE, ); |
| 1744 | 1790 |
| 1745 MFT_OUTPUT_DATA_BUFFER output_data_buffer = {0}; | 1791 MFT_OUTPUT_DATA_BUFFER output_data_buffer = {0}; |
| 1746 DWORD status = 0; | 1792 DWORD status = 0; |
| 1747 HRESULT hr = decoder_->ProcessOutput(0, // No flags | 1793 HRESULT hr; |
| 1748 1, // # of out streams to pull from | 1794 { |
| 1749 &output_data_buffer, &status); | 1795 ScopedExceptionCatcher catcher(using_ms_vp9_mft_); |
| 1796 hr = decoder_->ProcessOutput(0, // No flags |
| 1797 1, // # of out streams to pull from |
| 1798 &output_data_buffer, &status); |
| 1799 } |
| 1750 IMFCollection* events = output_data_buffer.pEvents; | 1800 IMFCollection* events = output_data_buffer.pEvents; |
| 1751 if (events != NULL) { | 1801 if (events != NULL) { |
| 1752 DVLOG(1) << "Got events from ProcessOuput, but discarding"; | 1802 DVLOG(1) << "Got events from ProcessOuput, but discarding"; |
| 1753 events->Release(); | 1803 events->Release(); |
| 1754 } | 1804 } |
| 1755 if (FAILED(hr)) { | 1805 if (FAILED(hr)) { |
| 1756 // A stream change needs further ProcessInput calls to get back decoder | 1806 // A stream change needs further ProcessInput calls to get back decoder |
| 1757 // output which is why we need to set the state to stopped. | 1807 // output which is why we need to set the state to stopped. |
| 1758 if (hr == MF_E_TRANSFORM_STREAM_CHANGE) { | 1808 if (hr == MF_E_TRANSFORM_STREAM_CHANGE) { |
| 1759 if (!SetDecoderOutputMediaType(MFVideoFormat_NV12) && | 1809 if (!SetDecoderOutputMediaType(MFVideoFormat_NV12) && |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2167 return; | 2217 return; |
| 2168 } | 2218 } |
| 2169 | 2219 |
| 2170 gfx::ColorSpace color_space = config_change_detector_->current_color_space(); | 2220 gfx::ColorSpace color_space = config_change_detector_->current_color_space(); |
| 2171 | 2221 |
| 2172 if (!inputs_before_decode_) { | 2222 if (!inputs_before_decode_) { |
| 2173 TRACE_EVENT_ASYNC_BEGIN0("gpu", "DXVAVideoDecodeAccelerator.Decoding", | 2223 TRACE_EVENT_ASYNC_BEGIN0("gpu", "DXVAVideoDecodeAccelerator.Decoding", |
| 2174 this); | 2224 this); |
| 2175 } | 2225 } |
| 2176 inputs_before_decode_++; | 2226 inputs_before_decode_++; |
| 2177 | 2227 { |
| 2178 hr = decoder_->ProcessInput(0, sample.get(), 0); | 2228 ScopedExceptionCatcher catcher(using_ms_vp9_mft_); |
| 2229 hr = decoder_->ProcessInput(0, sample.get(), 0); |
| 2230 } |
| 2179 // As per msdn if the decoder returns MF_E_NOTACCEPTING then it means that it | 2231 // As per msdn if the decoder returns MF_E_NOTACCEPTING then it means that it |
| 2180 // has enough data to produce one or more output samples. In this case the | 2232 // has enough data to produce one or more output samples. In this case the |
| 2181 // recommended options are to | 2233 // recommended options are to |
| 2182 // 1. Generate new output by calling IMFTransform::ProcessOutput until it | 2234 // 1. Generate new output by calling IMFTransform::ProcessOutput until it |
| 2183 // returns MF_E_TRANSFORM_NEED_MORE_INPUT. | 2235 // returns MF_E_TRANSFORM_NEED_MORE_INPUT. |
| 2184 // 2. Flush the input data | 2236 // 2. Flush the input data |
| 2185 // We implement the first option, i.e to retrieve the output sample and then | 2237 // We implement the first option, i.e to retrieve the output sample and then |
| 2186 // process the input again. Failure in either of these steps is treated as a | 2238 // process the input again. Failure in either of these steps is treated as a |
| 2187 // decoder failure. | 2239 // decoder failure. |
| 2188 if (hr == MF_E_NOTACCEPTING) { | 2240 if (hr == MF_E_NOTACCEPTING) { |
| (...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2895 base::Bind(&DXVAVideoDecodeAccelerator::DecodePendingInputBuffers, | 2947 base::Bind(&DXVAVideoDecodeAccelerator::DecodePendingInputBuffers, |
| 2896 base::Unretained(this))); | 2948 base::Unretained(this))); |
| 2897 } | 2949 } |
| 2898 | 2950 |
| 2899 uint32_t DXVAVideoDecodeAccelerator::GetTextureTarget() const { | 2951 uint32_t DXVAVideoDecodeAccelerator::GetTextureTarget() const { |
| 2900 bool provide_nv12_textures = share_nv12_textures_ || copy_nv12_textures_; | 2952 bool provide_nv12_textures = share_nv12_textures_ || copy_nv12_textures_; |
| 2901 return provide_nv12_textures ? GL_TEXTURE_EXTERNAL_OES : GL_TEXTURE_2D; | 2953 return provide_nv12_textures ? GL_TEXTURE_EXTERNAL_OES : GL_TEXTURE_2D; |
| 2902 } | 2954 } |
| 2903 | 2955 |
| 2904 } // namespace media | 2956 } // namespace media |
| OLD | NEW |