Skip to content

Commit

Permalink
[Cocoa] Adopt AVContentKeySession compatibility mode APIs
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=246116
rdar://97347572

Reviewed by Eric Carlson.

Adopt these new compatibility mode APIs when the sampleBufferContentKeySessionSupportEnabled() setting is unset.

* Source/WTF/wtf/PlatformHave.h:
* Source/WebCore/PAL/pal/cocoa/AVFoundationSoftLink.h:
* Source/WebCore/PAL/pal/spi/cocoa/AVFoundationSPI.h:
* Source/WebCore/platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.mm:
(WebCore::CDMInstanceFairPlayStreamingAVFObjC::contentKeySession):
(WebCore::CDMInstanceSessionFairPlayStreamingAVFObjC::ensureSessionOrGroup):
* Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(WebCore::MediaPlayerPrivateAVFoundationObjC::createAVAssetForURL):

Canonical link: https://commits.webkit.org/255287@main
  • Loading branch information
jernoble committed Oct 7, 2022
1 parent 1b24ccb commit ef443cc
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Source/WTF/wtf/PlatformHave.h
Expand Up @@ -860,6 +860,13 @@
#define HAVE_AVCONTENTKEYREQUEST_PENDING_PROTECTION_STATUS 1
#endif

#if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 130000) \
|| (PLATFORM(IOS) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 160100) \
|| (PLATFORM(APPLETV) && __TV_OS_VERSION_MAX_ALLOWED >= 160100) \
|| (PLATFORM(WATCHOS) && __WATCH_OS_VERSION_MAX_ALLOWED >= 90100)
#define HAVE_AVCONTENTKEYREQUEST_COMPATABILITIY_MODE 1
#endif

#if PLATFORM(MAC) || PLATFORM(IOS) || PLATFORM(MACCATALYST)
#if !defined(HAVE_CORE_ANIMATION_SEPARATED_LAYERS)
#define HAVE_CORE_ANIMATION_SEPARATED_LAYERS 1
Expand Down
2 changes: 2 additions & 0 deletions Source/WebCore/PAL/pal/cocoa/AVFoundationSoftLink.h
Expand Up @@ -134,6 +134,8 @@ SOFT_LINK_CONSTANT_MAY_FAIL_FOR_HEADER(PAL, AVFoundation, AVURLAssetAllowableVid
#define AVURLAssetAllowableVideoCodecTypesKey PAL::get_AVFoundation_AVURLAssetAllowableVideoCodecTypesKey()
SOFT_LINK_CONSTANT_MAY_FAIL_FOR_HEADER(PAL, AVFoundation, AVURLAssetAllowableCaptionFormatsKey, NSString *)
#define AVURLAssetAllowableCaptionFormatsKey PAL::get_AVFoundation_AVURLAssetAllowableCaptionFormatsKey()
SOFT_LINK_CONSTANT_MAY_FAIL_FOR_HEADER(PAL, AVFoundation, AVURLAssetShouldEnableLegacyWebKitCompatibilityModeForContentKeyRequests, NSString *)
#define AVURLAssetShouldEnableLegacyWebKitCompatibilityModeForContentKeyRequests PAL::get_AVFoundation_AVURLAssetShouldEnableLegacyWebKitCompatibilityModeForContentKeyRequests()
SOFT_LINK_CONSTANT_FOR_HEADER(PAL, AVFoundation, AVURLAssetInheritURIQueryComponentFromReferencingURIKey, NSString *)
#define AVURLAssetInheritURIQueryComponentFromReferencingURIKey PAL::get_AVFoundation_AVURLAssetInheritURIQueryComponentFromReferencingURIKey()
SOFT_LINK_CONSTANT_FOR_HEADER(PAL, AVFoundation, AVAssetImageGeneratorApertureModeCleanAperture, NSString *)
Expand Down
8 changes: 8 additions & 0 deletions Source/WebCore/PAL/pal/spi/cocoa/AVFoundationSPI.h
Expand Up @@ -256,6 +256,14 @@ typedef NS_ENUM(NSInteger, AVExternalContentProtectionStatus) {
@end
#endif

#if !HAVE(AVCONTENTKEYREQUEST_COMPATABILITIY_MODE)
NS_ASSUME_NONNULL_BEGIN
@interface AVContentKeyRequest (AVContentKeyRequest_WebKitCompatibilityMode)
+ (instancetype)contentKeySessionWithLegacyWebKitCompatibilityModeAndKeySystem:(AVContentKeySystem)keySystem storageDirectoryAtURL:(NSURL *)storageURL;
@end
NS_ASSUME_NONNULL_END
#endif

#endif // HAVE(AVCONTENTKEYSESSION)

#endif // USE(APPLE_INTERNAL_SDK)
Expand Down
Expand Up @@ -33,6 +33,7 @@
#import "CDMMediaCapability.h"
#import "InitDataRegistry.h"
#import "Logging.h"
#import "MediaSessionManagerCocoa.h"
#import "NotImplemented.h"
#import "SharedBuffer.h"
#import "TextDecoder.h"
Expand Down Expand Up @@ -254,6 +255,14 @@ static AtomString initTypeForRequest(AVContentKeyRequest* request)
#endif

auto storageURL = this->storageURL();
#if HAVE(AVCONTENTKEYREQUEST_COMPATABILITIY_MODE) && HAVE(AVCONTENTKEYSPECIFIER)
if (!MediaSessionManagerCocoa::sampleBufferContentKeySessionSupportEnabled()) {
if (!m_instance->persistentStateAllowed() || !storageURL)
m_session = [PAL::getAVContentKeySessionClass() contentKeySessionWithLegacyWebKitCompatibilityModeAndKeySystem:AVContentKeySystemFairPlayStreaming storageDirectoryAtURL:nil];
else
m_session = [PAL::getAVContentKeySessionClass() contentKeySessionWithLegacyWebKitCompatibilityModeAndKeySystem:AVContentKeySystemFairPlayStreaming storageDirectoryAtURL:storageURL];
} else
#endif
if (!persistentStateAllowed() || !storageURL)
m_session = [PAL::getAVContentKeySessionClass() contentKeySessionWithKeySystem:AVContentKeySystemFairPlayStreaming];
else
Expand Down Expand Up @@ -1603,6 +1612,14 @@ static auto requestStatusToCDMStatus(AVContentKeyRequestStatus status)
#endif

auto storageURL = m_instance->storageURL();
#if HAVE(AVCONTENTKEYREQUEST_COMPATABILITIY_MODE) && HAVE(AVCONTENTKEYSPECIFIER)
if (!MediaSessionManagerCocoa::sampleBufferContentKeySessionSupportEnabled()) {
if (!m_instance->persistentStateAllowed() || !storageURL)
m_session = [PAL::getAVContentKeySessionClass() contentKeySessionWithLegacyWebKitCompatibilityModeAndKeySystem:AVContentKeySystemFairPlayStreaming storageDirectoryAtURL:nil];
else
m_session = [PAL::getAVContentKeySessionClass() contentKeySessionWithLegacyWebKitCompatibilityModeAndKeySystem:AVContentKeySystemFairPlayStreaming storageDirectoryAtURL:storageURL];
} else
#endif
if (!m_instance->persistentStateAllowed() || !storageURL)
m_session = [PAL::getAVContentKeySessionClass() contentKeySessionWithKeySystem:AVContentKeySystemFairPlayStreaming];
else
Expand Down
Expand Up @@ -987,6 +987,11 @@ static URL conformFragmentIdentifierForURL(const URL& url)
if (willUseWebMFormatReader)
registerFormatReaderIfNecessary();

#if HAVE(AVCONTENTKEYREQUEST_COMPATABILITIY_MODE) && HAVE(AVCONTENTKEYSPECIFIER)
if (!MediaSessionManagerCocoa::sampleBufferContentKeySessionSupportEnabled() && PAL::canLoad_AVFoundation_AVURLAssetShouldEnableLegacyWebKitCompatibilityModeForContentKeyRequests())
[options setObject:@YES forKey:AVURLAssetShouldEnableLegacyWebKitCompatibilityModeForContentKeyRequests];
#endif

NSURL *cocoaURL = canonicalURL(url);

@try {
Expand Down

0 comments on commit ef443cc

Please sign in to comment.