forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
media: Check hardware secure decryption capabilities on Windows
- Update KeySystemSupportImpl to check kDisableAcceleratedVideoDecode and kMojoVideoDecoder. - Update KeySystemSupportImpl to call ContentBrowserClient to query hardware secure decryption capabilities. - Add ContentBrowserClient::GetHardwareSecureDecryptionCaps(). - Implement ChromeContentBrowserClient::GetHardwareSecureDecryptionCaps(). - Add GetWidevineHardwareCaps() to check Widevine-specific caps on Windows. - Rename kEnableHardwareSecureCodecsForTesting to kOverrideHardwareSecureCodecsForTesting to better reflect that fact that real platform hardware secure codecs check will be skipped. Bug: 848532 Test: Added unit test. Change-Id: Ia931fc945e5eb2fd406793cf87e334f3f9e00256 Reviewed-on: https://chromium-review.googlesource.com/1106960 Reviewed-by: Alex Moshchuk <alexmos@chromium.org> Reviewed-by: John Rummell <jrummell@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Xiaohan Wang <xhwang@chromium.org> Cr-Commit-Position: refs/heads/master@{#570475}
- Loading branch information
1 parent
52e14d9
commit a4e4184
Showing
16 changed files
with
341 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
// Copyright 2018 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/browser/media/widevine_hardware_caps_win.h" | ||
|
||
#include <comdef.h> | ||
#include <d3d11_1.h> | ||
#include <initguid.h> | ||
#include <stdint.h> | ||
#include <wrl/client.h> | ||
#include <bitset> | ||
|
||
#include "base/macros.h" | ||
#include "base/stl_util.h" | ||
#include "media/base/decrypt_config.h" | ||
|
||
namespace { | ||
|
||
// Alias for printing HRESULT. | ||
const auto PrintHr = logging::SystemErrorCodeToString; | ||
|
||
// TODO(xhwang): Deduplicate this file and widevine_cdm_proxy_factory.cc. | ||
// clang-format off | ||
DEFINE_GUID(kD3DCryptoTypeIntelWidevine, | ||
0x586e681, 0x4e14, 0x4133, 0x85, 0xe5, 0xa1, 0x4, 0x1f, 0x59, 0x9e, 0x26); | ||
// clang-format on | ||
|
||
// Bit indices for Intel Widevine hardware secure decryption capabilities. | ||
// | ||
// Encryption schemes are defined in ISO/IEC 23001-7, "Common encryption in ISO | ||
// base media file format files". Version 1 refers to ISO/IEC 23001-7:2012. | ||
// Version 3 refers to ISO/IEC 23001-7:2016. The difference that matters in this | ||
// context is as follows: | ||
// - In Version 1, section 9.5, "In full sample encryption, the entire sample is | ||
// encrypted". | ||
// - In Version 3, section 9.4.1, "Full sample encryption MAY be used for all | ||
// encrypted media types other than NAL Structured video, which SHALL use | ||
// Subsample encryption." | ||
// Therefore with kCencVersion1, it is possible that an entire sample of NAL | ||
// Structured video is encrypted. This is not allowed with kCencVersion3. | ||
enum IntelWidevineCaps { | ||
kSupported = 0, | ||
kAesCtr = 8, | ||
kAesCbc = 9, | ||
kCencVersion1 = 10, | ||
kCencVersion3 = 11, | ||
kCbcs = 17, | ||
}; | ||
|
||
} // namespace | ||
|
||
void GetWidevineHardwareCaps( | ||
const base::flat_set<media::CdmProxy::Protocol>& cdm_proxy_protocols, | ||
base::flat_set<media::VideoCodec>* video_codecs, | ||
base::flat_set<media::EncryptionMode>* encryption_schemes) { | ||
DCHECK(!cdm_proxy_protocols.empty()); | ||
DCHECK(video_codecs->empty()); | ||
DCHECK(encryption_schemes->empty()); | ||
|
||
// We only support kD3DCryptoTypeIntelWidevine. | ||
if (!cdm_proxy_protocols.count(media::CdmProxy::Protocol::kIntel)) { | ||
DVLOG(1) << "CDM supported CdmProxy protocol not supported by the system"; | ||
return; | ||
} | ||
|
||
Microsoft::WRL::ComPtr<ID3D11Device> device; | ||
Microsoft::WRL::ComPtr<ID3D11VideoDevice> video_device; | ||
|
||
// D3D11CdmProxy requires D3D_FEATURE_LEVEL_11_1. | ||
const D3D_FEATURE_LEVEL feature_levels[] = {D3D_FEATURE_LEVEL_11_1}; | ||
|
||
// Create device and pupulate |device|. | ||
HRESULT hresult = D3D11CreateDevice( | ||
nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, 0, feature_levels, | ||
base::size(feature_levels), D3D11_SDK_VERSION, device.GetAddressOf(), | ||
nullptr, nullptr); | ||
|
||
if (FAILED(hresult)) { | ||
DVLOG(1) << "Failed to create the D3D11Device: " << PrintHr(hresult); | ||
return; | ||
} | ||
|
||
hresult = device.CopyTo(video_device.GetAddressOf()); | ||
if (FAILED(hresult)) { | ||
DVLOG(1) << "Failed to get ID3D11VideoDevice: " << PrintHr(hresult); | ||
return; | ||
} | ||
|
||
D3D11_VIDEO_CONTENT_PROTECTION_CAPS caps = {}; | ||
|
||
// Check whether kD3DCryptoTypeIntelWidevine is supported with H264 codec. | ||
// TODO(xhwang): Support query for VP9. | ||
hresult = video_device->GetContentProtectionCaps( | ||
&kD3DCryptoTypeIntelWidevine, &D3D11_DECODER_PROFILE_H264_VLD_NOFGT, | ||
&caps); | ||
if (FAILED(hresult)) { | ||
DVLOG(1) << "Failed to GetContentProtectionCaps: " << PrintHr(hresult); | ||
return; | ||
} | ||
|
||
// For kD3DCryptoTypeIntelWidevine, this is a bitmask of IntelWidevineCaps. | ||
auto capability = std::bitset<64>(caps.ProtectedMemorySize); | ||
DVLOG(1) << "Content protection caps: " << capability; | ||
|
||
if (!capability.test(IntelWidevineCaps::kSupported)) { | ||
DVLOG(1) << "Hardware secure decryption not supported"; | ||
return; | ||
} | ||
|
||
// TODO(xhwang): Support query for CBCS. | ||
if (!capability.test(IntelWidevineCaps::kAesCtr)) { | ||
DVLOG(1) << "AES-CTR decryption not supported"; | ||
return; | ||
} | ||
|
||
// There are contents encrypted with kCencVersion1 out there. Therefore we | ||
// require kCencVersion1 to declare "cenc" support. | ||
if (!capability.test(IntelWidevineCaps::kCencVersion1)) { | ||
DVLOG(1) << "CENC version 1 not supported"; | ||
return; | ||
} | ||
|
||
DVLOG(1) << "Widevine hardware secure H264/CENC decryption supported"; | ||
video_codecs->insert(media::VideoCodec::kCodecH264); | ||
encryption_schemes->insert(media::EncryptionMode::kCenc); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright 2018 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef CHROME_BROWSER_MEDIA_WIDEVINE_HARDWARE_CAPS_WIN_H_ | ||
#define CHROME_BROWSER_MEDIA_WIDEVINE_HARDWARE_CAPS_WIN_H_ | ||
|
||
#include "base/containers/flat_set.h" | ||
#include "media/base/video_codecs.h" | ||
#include "media/cdm/cdm_proxy.h" | ||
|
||
namespace media { | ||
enum class EncryptionMode; | ||
} | ||
|
||
// Get supported Widevine hardware capabilities, including supported | ||
// |video_codecs| and |encryption_schemes|. | ||
void GetWidevineHardwareCaps( | ||
const base::flat_set<media::CdmProxy::Protocol>& cdm_proxy_protocols, | ||
base::flat_set<media::VideoCodec>* video_codecs, | ||
base::flat_set<media::EncryptionMode>* encryption_schemes); | ||
|
||
#endif // CHROME_BROWSER_MEDIA_WIDEVINE_HARDWARE_CAPS_WIN_H_ |
18 changes: 18 additions & 0 deletions
18
chrome/browser/media/widevine_hardware_caps_win_unittest.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright 2018 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/browser/media/widevine_hardware_caps_win.h" | ||
|
||
#include "testing/gtest/include/gtest/gtest.h" | ||
|
||
TEST(WidevineHardwareCapsTest, GetWidevineHardwareCaps) { | ||
base::flat_set<media::CdmProxy::Protocol> cdm_proxy_protocols = { | ||
media::CdmProxy::Protocol::kIntel}; | ||
base::flat_set<media::VideoCodec> video_codecs; | ||
base::flat_set<media::EncryptionMode> encryption_schemes; | ||
|
||
// Not checking the results since it's hardware dependent. | ||
GetWidevineHardwareCaps(cdm_proxy_protocols, &video_codecs, | ||
&encryption_schemes); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.