Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cocoa] Transition Legacy Fairplay CDM off AVStreamSession #12378

Conversation

jernoble
Copy link
Contributor

@jernoble jernoble commented Apr 4, 2023

2ef8f77

[Cocoa] Transition Legacy Fairplay CDM off AVStreamSession
https://bugs.webkit.org/show_bug.cgi?id=254992
rdar://107202864

Reviewed by Eric Carlson.

Clients of the prefixed WebKit EME APIs using the Fairplay "V2" protocol will use
a CDM implementation that relies upon AVStreamSession. This implementation will
break when "sampleBufferContentKeySessionSupport" is enabled, as it relies upon
platform changes only available through AVContentKeySession.

Remove the AVStreamSession-based CDM implementation and funnel all support through
the existing AVContentKeySession-based legacy CDM. At the same time, modify that
AVContentKeySession-based CDM to query the "sampleBufferContentKeySessionSupport"
setting and opt into the non-legacy AVContentKeySession path when it is enabled.

Drive-by fix: When opting into the non-legacy codepath, the
-contentKeySession:didProvideContentKeyRequest: delegate callbock becomes asynchronous.
To retain the existing synchronous behavior of the CDM, set an explicit work queue
for the delegate callbacks, and make the setting and getting of m_keyRequest thread-safe.
Add a semaphore to be used to detect when the m_keyRequest value changes.

Drive-by fix #2: Fix some unified-build included errors exposed by removing
CDMSessionAVStreamSession.h

Add LayoutTests for basic legacy EME API playback.

* LayoutTests/http/tests/media/fairplay/legacy-eme.js: Added.
(selectKeySystem):
(async startLegacyEME):
(extractContentId):
(concatInitDataIdAndCertificate):
* LayoutTests/http/tests/media/fairplay/legacy-fairplay-error-expected.txt: Added.
* LayoutTests/http/tests/media/fairplay/legacy-fairplay-error.html: Added.
* LayoutTests/http/tests/media/fairplay/legacy-fairplay-hls-expected.txt: Added.
* LayoutTests/http/tests/media/fairplay/legacy-fairplay-hls.html: Added.
* LayoutTests/http/tests/media/fairplay/legacy-fairplay-mse-v2-expected.txt: Added.
* LayoutTests/http/tests/media/fairplay/legacy-fairplay-mse-v2.html: Added.
* LayoutTests/http/tests/media/fairplay/legacy-fairplay-mse-v3-expected.txt: Added.
* LayoutTests/http/tests/media/fairplay/legacy-fairplay-mse-v3.html: Added.
* LayoutTests/http/tests/media/fairplay/support.js:
(uInt16ArrayToString):
(stringToUint16Array):
* Source/WTF/wtf/PlatformHave.h:
* Source/WebCore/Modules/encryptedmedia/legacy/LegacyCDM.cpp:
(WebCore::platformRegisterFactories):
* Source/WebCore/PAL/pal/cocoa/AVFoundationSoftLink.h:
* Source/WebCore/PAL/pal/cocoa/AVFoundationSoftLink.mm:
* Source/WebCore/SourcesCocoa.txt:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/platform/graphics/LegacyCDMSession.h:
* Source/WebCore/platform/graphics/avfoundation/CDMPrivateMediaSourceAVFObjC.mm:
(WebCore::queryDecoderAvailability):
(WebCore::CDMPrivateMediaSourceAVFObjC::createSession):
* Source/WebCore/platform/graphics/avfoundation/objc/CDMSessionAVContentKeySession.h:
* Source/WebCore/platform/graphics/avfoundation/objc/CDMSessionAVContentKeySession.mm:
(-[WebCDMSessionAVContentKeySessionDelegate contentKeySessionContentProtectionSessionIdentifierDidChange:]):
(WebCore::CDMSessionAVContentKeySession::CDMSessionAVContentKeySession):
(WebCore::CDMSessionAVContentKeySession::update):
(WebCore::CDMSessionAVContentKeySession::hasContentKeyRequest const):
(WebCore::CDMSessionAVContentKeySession::contentKeyRequest):
(WebCore::CDMSessionAVContentKeySession::didProvideContentKeyRequest):
(WebCore::CDMSessionAVContentKeySession::contentKeySession):
* Source/WebCore/platform/graphics/avfoundation/objc/CDMSessionAVStreamSession.h: Removed.
* Source/WebCore/platform/graphics/avfoundation/objc/CDMSessionAVStreamSession.mm: Removed.
* Source/WebCore/platform/graphics/avfoundation/objc/CDMSessionMediaSourceAVFObjC.h:
(WebCore::toCDMSessionMediaSourceAVFObjC):
* Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.h:
(WebCore::MediaPlayerPrivateMediaSourceAVFObjC::hasStreamSession): Deleted.
* Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm:
(WebCore::MediaPlayerPrivateMediaSourceAVFObjC::setCDMSession):
(WebCore::MediaPlayerPrivateMediaSourceAVFObjC::streamSession): Deleted.
* Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm:
(WebCore::SourceBufferPrivateAVFObjC::didProvideMediaDataForTrackId):
(WebCore::SourceBufferPrivateAVFObjC::willProvideContentKeyRequestInitializationDataForTrackID):
(WebCore::SourceBufferPrivateAVFObjC::destroyStreamDataParser):
(WebCore::copyKeyIDs): Deleted.
* Tools/TestWebKitAPI/Tests/WebCore/cocoa/AVFoundationSoftLinkTest.mm:
(TestWebKitAPI::TEST):

Canonical link: https://commits.webkit.org/262647@main

e9f85b0

Misc iOS, tvOS & watchOS macOS Linux Windows
❌ πŸ§ͺ style βœ… πŸ›  ios βœ… πŸ›  mac βœ… πŸ›  wpe βœ… πŸ›  wincairo
βœ… πŸ§ͺ bindings βœ… πŸ›  ios-sim βœ… πŸ›  mac-AS-debug ❌ πŸ§ͺ wpe-wk2
βœ… πŸ§ͺ webkitperl βœ… πŸ§ͺ ios-wk2 βœ… πŸ§ͺ api-mac βœ… πŸ›  gtk
βœ… πŸ§ͺ api-ios βœ… πŸ§ͺ mac-wk1 βœ… πŸ§ͺ gtk-wk2
βœ… πŸ›  πŸ§ͺ jsc βœ… πŸ›  tv βœ… πŸ§ͺ mac-wk2 ❌ πŸ§ͺ api-gtk
βœ… πŸ›  πŸ§ͺ jsc-arm64 βœ… πŸ›  tv-sim βœ… πŸ§ͺ mac-AS-debug-wk2 βœ… πŸ›  jsc-armv7
βœ… πŸ›  watch βœ… πŸ§ͺ mac-wk2-stress βœ… πŸ§ͺ jsc-armv7-tests
βœ… πŸ›  πŸ§ͺ merge βœ… πŸ›  watch-sim βœ… πŸ›  jsc-mips
βœ… πŸ§ͺ jsc-mips-tests

@jernoble jernoble self-assigned this Apr 4, 2023
@jernoble jernoble added the Media Bugs related to the HTML 5 Media elements. label Apr 4, 2023
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Apr 4, 2023
@jernoble jernoble removed the merging-blocked Applied to prevent a change from being merged label Apr 4, 2023
@jernoble jernoble force-pushed the eng/Cocoa-Transition-Legacy-Fairplay-CDM-off-AVStreamSession branch from 2b6c8d3 to e52af3e Compare April 4, 2023 19:21
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Apr 4, 2023
RetainPtr<NSData> nsInitData = m_initData ? m_initData->createNSData() : nil;
NSData* nsIdentifier = m_identifier ? [NSData dataWithBytes:m_identifier->data() length:m_identifier->length()] : nil;
if ([contentKeySession() respondsToSelector:@selector(processContentKeyRequestWithIdentifier:initializationData:options:)])
[contentKeySession() processContentKeyRequestWithIdentifier:nsIdentifier initializationData:nsInitData.get() options:nil];
else
[contentKeySession() processContentKeyRequestInitializationData:nsInitData.get() options:nil];
m_hasKeyRequestSemaphore.waitFor(5_s);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A commend and a named constant would help someone looking at this understand why we wait for exactly 5 seconds.

Comment on lines 403 to 405
m_hasKeyRequestSemaphore.signal();
m_keyRequest = keyRequest;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't you signal the semaphore after setting m_keyRequest?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, good point!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(It won't matter in practice because the m_keyRequestLock will protect access to the variable till after this method returns, but you're right that it's currently incorrect.)

@jernoble jernoble removed the merging-blocked Applied to prevent a change from being merged label Apr 4, 2023
@jernoble jernoble force-pushed the eng/Cocoa-Transition-Legacy-Fairplay-CDM-off-AVStreamSession branch from e52af3e to 3861d13 Compare April 4, 2023 23:14
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Apr 5, 2023
@jernoble jernoble removed the merging-blocked Applied to prevent a change from being merged label Apr 5, 2023
@jernoble jernoble force-pushed the eng/Cocoa-Transition-Legacy-Fairplay-CDM-off-AVStreamSession branch from 3861d13 to dd48368 Compare April 5, 2023 16:17
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Apr 5, 2023
@jernoble jernoble removed the merging-blocked Applied to prevent a change from being merged label Apr 5, 2023
@jernoble jernoble force-pushed the eng/Cocoa-Transition-Legacy-Fairplay-CDM-off-AVStreamSession branch from dd48368 to e9f85b0 Compare April 5, 2023 20:02
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Apr 5, 2023
@jernoble jernoble added merge-queue Applied to send a pull request to merge-queue and removed merging-blocked Applied to prevent a change from being merged labels Apr 5, 2023
https://bugs.webkit.org/show_bug.cgi?id=254992
rdar://107202864

Reviewed by Eric Carlson.

Clients of the prefixed WebKit EME APIs using the Fairplay "V2" protocol will use
a CDM implementation that relies upon AVStreamSession. This implementation will
break when "sampleBufferContentKeySessionSupport" is enabled, as it relies upon
platform changes only available through AVContentKeySession.

Remove the AVStreamSession-based CDM implementation and funnel all support through
the existing AVContentKeySession-based legacy CDM. At the same time, modify that
AVContentKeySession-based CDM to query the "sampleBufferContentKeySessionSupport"
setting and opt into the non-legacy AVContentKeySession path when it is enabled.

Drive-by fix: When opting into the non-legacy codepath, the
-contentKeySession:didProvideContentKeyRequest: delegate callbock becomes asynchronous.
To retain the existing synchronous behavior of the CDM, set an explicit work queue
for the delegate callbacks, and make the setting and getting of m_keyRequest thread-safe.
Add a semaphore to be used to detect when the m_keyRequest value changes.

Drive-by fix #2: Fix some unified-build included errors exposed by removing
CDMSessionAVStreamSession.h

Add LayoutTests for basic legacy EME API playback.

* LayoutTests/http/tests/media/fairplay/legacy-eme.js: Added.
(selectKeySystem):
(async startLegacyEME):
(extractContentId):
(concatInitDataIdAndCertificate):
* LayoutTests/http/tests/media/fairplay/legacy-fairplay-error-expected.txt: Added.
* LayoutTests/http/tests/media/fairplay/legacy-fairplay-error.html: Added.
* LayoutTests/http/tests/media/fairplay/legacy-fairplay-hls-expected.txt: Added.
* LayoutTests/http/tests/media/fairplay/legacy-fairplay-hls.html: Added.
* LayoutTests/http/tests/media/fairplay/legacy-fairplay-mse-v2-expected.txt: Added.
* LayoutTests/http/tests/media/fairplay/legacy-fairplay-mse-v2.html: Added.
* LayoutTests/http/tests/media/fairplay/legacy-fairplay-mse-v3-expected.txt: Added.
* LayoutTests/http/tests/media/fairplay/legacy-fairplay-mse-v3.html: Added.
* LayoutTests/http/tests/media/fairplay/support.js:
(uInt16ArrayToString):
(stringToUint16Array):
* Source/WTF/wtf/PlatformHave.h:
* Source/WebCore/Modules/encryptedmedia/legacy/LegacyCDM.cpp:
(WebCore::platformRegisterFactories):
* Source/WebCore/PAL/pal/cocoa/AVFoundationSoftLink.h:
* Source/WebCore/PAL/pal/cocoa/AVFoundationSoftLink.mm:
* Source/WebCore/SourcesCocoa.txt:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/platform/graphics/LegacyCDMSession.h:
* Source/WebCore/platform/graphics/avfoundation/CDMPrivateMediaSourceAVFObjC.mm:
(WebCore::queryDecoderAvailability):
(WebCore::CDMPrivateMediaSourceAVFObjC::createSession):
* Source/WebCore/platform/graphics/avfoundation/objc/CDMSessionAVContentKeySession.h:
* Source/WebCore/platform/graphics/avfoundation/objc/CDMSessionAVContentKeySession.mm:
(-[WebCDMSessionAVContentKeySessionDelegate contentKeySessionContentProtectionSessionIdentifierDidChange:]):
(WebCore::CDMSessionAVContentKeySession::CDMSessionAVContentKeySession):
(WebCore::CDMSessionAVContentKeySession::update):
(WebCore::CDMSessionAVContentKeySession::hasContentKeyRequest const):
(WebCore::CDMSessionAVContentKeySession::contentKeyRequest):
(WebCore::CDMSessionAVContentKeySession::didProvideContentKeyRequest):
(WebCore::CDMSessionAVContentKeySession::contentKeySession):
* Source/WebCore/platform/graphics/avfoundation/objc/CDMSessionAVStreamSession.h: Removed.
* Source/WebCore/platform/graphics/avfoundation/objc/CDMSessionAVStreamSession.mm: Removed.
* Source/WebCore/platform/graphics/avfoundation/objc/CDMSessionMediaSourceAVFObjC.h:
(WebCore::toCDMSessionMediaSourceAVFObjC):
* Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.h:
(WebCore::MediaPlayerPrivateMediaSourceAVFObjC::hasStreamSession): Deleted.
* Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm:
(WebCore::MediaPlayerPrivateMediaSourceAVFObjC::setCDMSession):
(WebCore::MediaPlayerPrivateMediaSourceAVFObjC::streamSession): Deleted.
* Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm:
(WebCore::SourceBufferPrivateAVFObjC::didProvideMediaDataForTrackId):
(WebCore::SourceBufferPrivateAVFObjC::willProvideContentKeyRequestInitializationDataForTrackID):
(WebCore::SourceBufferPrivateAVFObjC::destroyStreamDataParser):
(WebCore::copyKeyIDs): Deleted.
* Tools/TestWebKitAPI/Tests/WebCore/cocoa/AVFoundationSoftLinkTest.mm:
(TestWebKitAPI::TEST):

Canonical link: https://commits.webkit.org/262647@main
@webkit-commit-queue webkit-commit-queue force-pushed the eng/Cocoa-Transition-Legacy-Fairplay-CDM-off-AVStreamSession branch from e9f85b0 to 2ef8f77 Compare April 6, 2023 00:02
@webkit-commit-queue
Copy link
Collaborator

Committed 262647@main (2ef8f77): https://commits.webkit.org/262647@main

Reviewed commits have been landed. Closing PR #12378 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit 2ef8f77 into WebKit:main Apr 6, 2023
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Apr 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Media Bugs related to the HTML 5 Media elements.
Projects
None yet
5 participants