Title: [228709] trunk/Source/WebCore
Revision
228709
Author
[email protected]
Date
2018-02-19 13:22:15 -0800 (Mon, 19 Feb 2018)

Log Message

[EME] Add mechanism for MediaKeySession to react to HDCP changes
https://bugs.webkit.org/show_bug.cgi?id=182935

Reviewed by Eric Carlson.

Add a client callback interface to CDMInterface to allow subclasses to communicate up to
MediaKeySEssion. Add a virtual method to CDMInterface to allow it to be notified of HDCP
status changes. Override this method in CDMInstanceFairPlayStreamingAVFObjC. Hook up the
outputObscuredDueToInsufficientExternalProtectionChanged() methods in both
MediaPlayerPrivateAVFoundationObjC and MediaPlayerPrivateMediaSourceAVFObjC to this new
CDMInstance method. Add an Internals method to simulate an HDCP error for testing purposes.

* Modules/encryptedmedia/MediaKeySession.cpp:
(WebCore::MediaKeySession::MediaKeySession):
(WebCore::MediaKeySession::~MediaKeySession):
(WebCore::MediaKeySession::updateKeyStatuses):
* Modules/encryptedmedia/MediaKeySession.h:
* platform/encryptedmedia/CDMInstance.h:
(WebCore::CDMInstance::setHDCPStatus):
(WebCore::CDMInstance::setClient):
(WebCore::CDMInstance::clearClient):
* platform/graphics/MediaPlayer.cpp:
(WebCore::MediaPlayer::beginSimulatedHDCPError):
(WebCore::MediaPlayer::endSimulatedHDCPError):
* platform/graphics/MediaPlayer.h:
* platform/graphics/MediaPlayerPrivate.h:
(WebCore::MediaPlayerPrivateInterface::beginSimulatedHDCPError):
(WebCore::MediaPlayerPrivateInterface::endSimulatedHDCPError):
* platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.h:
* platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.mm:
(WebCore::CDMInstanceFairPlayStreamingAVFObjC::setClient):
(WebCore::CDMInstanceFairPlayStreamingAVFObjC::clearClient):
(WebCore::CDMInstanceFairPlayStreamingAVFObjC::sessionIdentifierChanged):
(WebCore::CDMInstanceFairPlayStreamingAVFObjC::outputObscuredDueToInsufficientExternalProtectionChanged):
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(WebCore::MediaPlayerPrivateAVFoundationObjC::outputObscuredDueToInsufficientExternalProtectionChanged):
(WebCore::playerKVOProperties):
(-[WebCoreAVFMovieObserver observeValueForKeyPath:ofObject:change:context:]):
* platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.h:
* platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm:
(WebCore::MediaPlayerPrivateMediaSourceAVFObjC::outputObscuredDueToInsufficientExternalProtectionChanged):
* platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h:
* platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm:
(-[WebAVSampleBufferErrorListener observeValueForKeyPath:ofObject:change:context:]):
(WebCore::SourceBufferPrivateAVFObjC::outputObscuredDueToInsufficientExternalProtectionChanged):
* testing/Internals.cpp:
(WebCore::Internals::beginSimulatedHDCPError):
(WebCore::Internals::endSimulatedHDCPError):
* testing/Internals.h:
* testing/Internals.idl:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (228708 => 228709)


--- trunk/Source/WebCore/ChangeLog	2018-02-19 21:03:39 UTC (rev 228708)
+++ trunk/Source/WebCore/ChangeLog	2018-02-19 21:22:15 UTC (rev 228709)
@@ -1,3 +1,57 @@
+2018-02-19  Jer Noble  <[email protected]>
+
+        [EME] Add mechanism for MediaKeySession to react to HDCP changes
+        https://bugs.webkit.org/show_bug.cgi?id=182935
+
+        Reviewed by Eric Carlson.
+
+        Add a client callback interface to CDMInterface to allow subclasses to communicate up to
+        MediaKeySEssion. Add a virtual method to CDMInterface to allow it to be notified of HDCP
+        status changes. Override this method in CDMInstanceFairPlayStreamingAVFObjC. Hook up the
+        outputObscuredDueToInsufficientExternalProtectionChanged() methods in both
+        MediaPlayerPrivateAVFoundationObjC and MediaPlayerPrivateMediaSourceAVFObjC to this new
+        CDMInstance method. Add an Internals method to simulate an HDCP error for testing purposes.
+
+        * Modules/encryptedmedia/MediaKeySession.cpp:
+        (WebCore::MediaKeySession::MediaKeySession):
+        (WebCore::MediaKeySession::~MediaKeySession):
+        (WebCore::MediaKeySession::updateKeyStatuses):
+        * Modules/encryptedmedia/MediaKeySession.h:
+        * platform/encryptedmedia/CDMInstance.h:
+        (WebCore::CDMInstance::setHDCPStatus):
+        (WebCore::CDMInstance::setClient):
+        (WebCore::CDMInstance::clearClient):
+        * platform/graphics/MediaPlayer.cpp:
+        (WebCore::MediaPlayer::beginSimulatedHDCPError):
+        (WebCore::MediaPlayer::endSimulatedHDCPError):
+        * platform/graphics/MediaPlayer.h:
+        * platform/graphics/MediaPlayerPrivate.h:
+        (WebCore::MediaPlayerPrivateInterface::beginSimulatedHDCPError):
+        (WebCore::MediaPlayerPrivateInterface::endSimulatedHDCPError):
+        * platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.h:
+        * platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.mm:
+        (WebCore::CDMInstanceFairPlayStreamingAVFObjC::setClient):
+        (WebCore::CDMInstanceFairPlayStreamingAVFObjC::clearClient):
+        (WebCore::CDMInstanceFairPlayStreamingAVFObjC::sessionIdentifierChanged):
+        (WebCore::CDMInstanceFairPlayStreamingAVFObjC::outputObscuredDueToInsufficientExternalProtectionChanged):
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
+        (WebCore::MediaPlayerPrivateAVFoundationObjC::outputObscuredDueToInsufficientExternalProtectionChanged):
+        (WebCore::playerKVOProperties):
+        (-[WebCoreAVFMovieObserver observeValueForKeyPath:ofObject:change:context:]):
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.h:
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm:
+        (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::outputObscuredDueToInsufficientExternalProtectionChanged):
+        * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h:
+        * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm:
+        (-[WebAVSampleBufferErrorListener observeValueForKeyPath:ofObject:change:context:]):
+        (WebCore::SourceBufferPrivateAVFObjC::outputObscuredDueToInsufficientExternalProtectionChanged):
+        * testing/Internals.cpp:
+        (WebCore::Internals::beginSimulatedHDCPError):
+        (WebCore::Internals::endSimulatedHDCPError):
+        * testing/Internals.h:
+        * testing/Internals.idl:
+
 2018-02-19  Chris Dumez  <[email protected]>
 
         CrashTracer: com.apple.WebKit.WebContent at WebCore: WebCore::TimerBase::~TimerBase

Modified: trunk/Source/WebCore/Modules/encryptedmedia/MediaKeySession.cpp (228708 => 228709)


--- trunk/Source/WebCore/Modules/encryptedmedia/MediaKeySession.cpp	2018-02-19 21:03:39 UTC (rev 228708)
+++ trunk/Source/WebCore/Modules/encryptedmedia/MediaKeySession.cpp	2018-02-19 21:22:15 UTC (rev 228709)
@@ -87,11 +87,14 @@
     UNUSED_PARAM(m_useDistinctiveIdentifier);
     UNUSED_PARAM(m_closed);
     UNUSED_PARAM(m_uninitialized);
+
+    m_instance->setClient(*this);
 }
 
 MediaKeySession::~MediaKeySession()
 {
     m_keyStatuses->detachSession();
+    m_instance->clearClient();
 }
 
 const String& MediaKeySession::sessionId() const
@@ -596,7 +599,7 @@
     m_eventQueue.enqueueEvent(WTFMove(messageEvent));
 }
 
-void MediaKeySession::updateKeyStatuses(CDMInstance::KeyStatusVector&& inputStatuses)
+void MediaKeySession::updateKeyStatuses(CDMInstanceClient::KeyStatusVector&& inputStatuses)
 {
     // https://w3c.github.io/encrypted-media/#update-key-statuses
     // W3C Editor's Draft 09 November 2016

Modified: trunk/Source/WebCore/Modules/encryptedmedia/MediaKeySession.h (228708 => 228709)


--- trunk/Source/WebCore/Modules/encryptedmedia/MediaKeySession.h	2018-02-19 21:03:39 UTC (rev 228708)
+++ trunk/Source/WebCore/Modules/encryptedmedia/MediaKeySession.h	2018-02-19 21:22:15 UTC (rev 228709)
@@ -52,7 +52,7 @@
 class MediaKeys;
 class SharedBuffer;
 
-class MediaKeySession final : public RefCounted<MediaKeySession>, public EventTargetWithInlineData, public ActiveDOMObject {
+class MediaKeySession final : public RefCounted<MediaKeySession>, public EventTargetWithInlineData, public ActiveDOMObject, public CDMInstanceClient {
 public:
     static Ref<MediaKeySession> create(ScriptExecutionContext&, WeakPtr<MediaKeys>&&, MediaKeySessionType, bool useDistinctiveIdentifier, Ref<CDM>&&, Ref<CDMInstance>&&);
     virtual ~MediaKeySession();
@@ -80,11 +80,13 @@
 private:
     MediaKeySession(ScriptExecutionContext&, WeakPtr<MediaKeys>&&, MediaKeySessionType, bool useDistinctiveIdentifier, Ref<CDM>&&, Ref<CDMInstance>&&);
     void enqueueMessage(MediaKeyMessageType, const SharedBuffer&);
-    void updateKeyStatuses(CDMInstance::KeyStatusVector&&);
     void updateExpiration(double);
     void sessionClosed();
     String mediaKeysStorageDirectory() const;
 
+    // CDMInstanceClient
+    void updateKeyStatuses(CDMInstanceClient::KeyStatusVector&&) override;
+
     // EventTarget
     EventTargetInterface eventTargetInterface() const override { return MediaKeySessionEventTargetInterfaceType; }
     ScriptExecutionContext* scriptExecutionContext() const override { return ActiveDOMObject::scriptExecutionContext(); }

Modified: trunk/Source/WebCore/platform/encryptedmedia/CDMInstance.h (228708 => 228709)


--- trunk/Source/WebCore/platform/encryptedmedia/CDMInstance.h	2018-02-19 21:03:39 UTC (rev 228708)
+++ trunk/Source/WebCore/platform/encryptedmedia/CDMInstance.h	2018-02-19 21:22:15 UTC (rev 228709)
@@ -43,6 +43,15 @@
 
 struct CDMKeySystemConfiguration;
 
+class CDMInstanceClient {
+public:
+    virtual ~CDMInstanceClient() = default;
+
+    using KeyStatus = CDMKeyStatus;
+    using KeyStatusVector = Vector<std::pair<Ref<SharedBuffer>, KeyStatus>>;
+    virtual void updateKeyStatuses(KeyStatusVector&&) = 0;
+};
+
 class CDMInstance : public RefCounted<CDMInstance> {
 public:
     virtual ~CDMInstance() = default;
@@ -70,10 +79,21 @@
     virtual SuccessValue setServerCertificate(Ref<SharedBuffer>&&) = 0;
     virtual SuccessValue setStorageDirectory(const String&) = 0;
 
+    enum class HDCPStatus {
+        Unknown,
+        Valid,
+        OutputRestricted,
+        OutputDownscaled,
+    };
+    virtual SuccessValue setHDCPStatus(HDCPStatus) { return Failed; }
+
+    virtual void setClient(CDMInstanceClient&) { }
+    virtual void clearClient() { }
+
     using LicenseCallback = Function<void(Ref<SharedBuffer>&& message, const String& sessionId, bool needsIndividualization, SuccessValue succeeded)>;
     virtual void requestLicense(LicenseType, const AtomicString& initDataType, Ref<SharedBuffer>&& initData, LicenseCallback) = 0;
 
-    using KeyStatusVector = Vector<std::pair<Ref<SharedBuffer>, KeyStatus>>;
+    using KeyStatusVector = CDMInstanceClient::KeyStatusVector;
     using Message = std::pair<MessageType, Ref<SharedBuffer>>;
     using LicenseUpdateCallback = Function<void(bool sessionWasClosed, std::optional<KeyStatusVector>&& changedKeys, std::optional<double>&& changedExpiration, std::optional<Message>&& message, SuccessValue succeeded)>;
     virtual void updateLicense(const String& sessionId, LicenseType, const SharedBuffer& response, LicenseUpdateCallback) = 0;

Modified: trunk/Source/WebCore/platform/graphics/MediaPlayer.cpp (228708 => 228709)


--- trunk/Source/WebCore/platform/graphics/MediaPlayer.cpp	2018-02-19 21:03:39 UTC (rev 228708)
+++ trunk/Source/WebCore/platform/graphics/MediaPlayer.cpp	2018-02-19 21:22:15 UTC (rev 228709)
@@ -1378,6 +1378,18 @@
 }
 #endif
 
+void MediaPlayer::beginSimulatedHDCPError()
+{
+    if (m_private)
+        m_private->beginSimulatedHDCPError();
+}
+
+void MediaPlayer::endSimulatedHDCPError()
+{
+    if (m_private)
+        m_private->endSimulatedHDCPError();
+}
+
 String MediaPlayer::languageOfPrimaryAudioTrack() const
 {
     if (!m_private)

Modified: trunk/Source/WebCore/platform/graphics/MediaPlayer.h (228708 => 228709)


--- trunk/Source/WebCore/platform/graphics/MediaPlayer.h	2018-02-19 21:03:39 UTC (rev 228708)
+++ trunk/Source/WebCore/platform/graphics/MediaPlayer.h	2018-02-19 21:22:15 UTC (rev 228709)
@@ -595,6 +595,9 @@
     WEBCORE_EXPORT void simulateAudioInterruption();
 #endif
 
+    WEBCORE_EXPORT void beginSimulatedHDCPError();
+    WEBCORE_EXPORT void endSimulatedHDCPError();
+
     String languageOfPrimaryAudioTrack() const;
 
     size_t extraMemoryCost() const;

Modified: trunk/Source/WebCore/platform/graphics/MediaPlayerPrivate.h (228708 => 228709)


--- trunk/Source/WebCore/platform/graphics/MediaPlayerPrivate.h	2018-02-19 21:03:39 UTC (rev 228708)
+++ trunk/Source/WebCore/platform/graphics/MediaPlayerPrivate.h	2018-02-19 21:22:15 UTC (rev 228709)
@@ -253,6 +253,9 @@
     virtual void simulateAudioInterruption() { }
 #endif
 
+    virtual void beginSimulatedHDCPError() { }
+    virtual void endSimulatedHDCPError() { }
+
     virtual String languageOfPrimaryAudioTrack() const { return emptyString(); }
 
     virtual size_t extraMemoryCost() const

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.h (228708 => 228709)


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.h	2018-02-19 21:03:39 UTC (rev 228708)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.h	2018-02-19 21:22:15 UTC (rev 228709)
@@ -65,6 +65,8 @@
     void closeSession(const String&, CloseSessionCallback) final;
     void removeSessionData(const String&, LicenseType, RemoveSessionDataCallback) final;
     void storeRecordOfKeyUsage(const String&) final;
+    void setClient(CDMInstanceClient&) final;
+    void clearClient() final;
 
     const String& keySystem() const final;
 
@@ -74,6 +76,7 @@
     void didFailToProvideRequest(AVContentKeyRequest *, NSError *);
     bool shouldRetryRequestForReason(AVContentKeyRequest *, NSString *);
     void sessionIdentifierChanged(NSData *);
+    void outputObscuredDueToInsufficientExternalProtectionChanged(bool);
 
     AVContentKeySession *contentKeySession() { return m_session.get(); }
 
@@ -91,6 +94,7 @@
     RetainPtr<AVContentKeyRequest> m_request;
     RetainPtr<WebCoreFPSContentKeySessionDelegate> m_delegate;
     Vector<RetainPtr<NSData>> m_expiredSessions;
+    CDMInstanceClient* m_client;
     String m_sessionId;
 
     LicenseCallback m_requestLicenseCallback;

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.mm (228708 => 228709)


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.mm	2018-02-19 21:03:39 UTC (rev 228708)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.mm	2018-02-19 21:22:15 UTC (rev 228709)
@@ -409,6 +409,16 @@
     // no-op; key usage data is stored automatically.
 }
 
+void CDMInstanceFairPlayStreamingAVFObjC::setClient(CDMInstanceClient& client)
+{
+    m_client = &client;
+}
+
+void CDMInstanceFairPlayStreamingAVFObjC::clearClient()
+{
+    m_client = nullptr;
+}
+
 const String& CDMInstanceFairPlayStreamingAVFObjC::keySystem() const
 {
     static NeverDestroyed<String> s_keySystem { ASCIILiteral("com.apple.fps") };
@@ -480,8 +490,41 @@
 
     auto sessionIdentifierString = adoptNS([[NSString alloc] initWithData:sessionIdentifier encoding:NSUTF8StringEncoding]);
     m_sessionId = sessionIdentifierString.get();
-}   
+}
 
+void CDMInstanceFairPlayStreamingAVFObjC::outputObscuredDueToInsufficientExternalProtectionChanged(bool obscured)
+{
+    if (!m_client || !m_request)
+        return;
+
+    CDMKeyStatus status;
+    if (obscured)
+        status = CDMKeyStatus::OutputRestricted;
+    else {
+        switch (m_request.get().status) {
+        case AVContentKeyRequestStatusRequestingResponse:
+        case AVContentKeyRequestStatusRetried:
+            status = CDMKeyStatus::StatusPending;
+            break;
+        case AVContentKeyRequestStatusReceivedResponse:
+        case AVContentKeyRequestStatusRenewed:
+            status = CDMKeyStatus::Usable;
+            break;
+        case AVContentKeyRequestStatusCancelled:
+            status = CDMKeyStatus::Released;
+            break;
+        case AVContentKeyRequestStatusFailed:
+            status = CDMKeyStatus::InternalError;
+            break;
+        }
+    }
+
+    auto keyStatuses = keyIDs().map([status] (const Ref<SharedBuffer>& keyID) -> KeyStatusVector::ValueType {
+        return { keyID.copyRef(), status };
+    });
+    m_client->updateKeyStatuses(WTFMove(keyStatuses));
 }
 
+}
+
 #endif // ENABLE(ENCRYPTED_MEDIA) && HAVE(AVCONTENTKEYSESSION)

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h (228708 => 228709)


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h	2018-02-19 21:03:39 UTC (rev 228708)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h	2018-02-19 21:22:15 UTC (rev 228709)
@@ -140,8 +140,10 @@
     void playbackTargetIsWirelessDidChange();
 #endif
 
-#if ENABLE(LEGACY_ENCRYPTED_MEDIA)
+#if ENABLE(LEGACY_ENCRYPTED_MEDIA) || (ENABLE(ENCRYPTED_MEDIA) && HAVE(AVCONTENTKEYSESSION))
     void outputObscuredDueToInsufficientExternalProtectionChanged(bool);
+    void beginSimulatedHDCPError() override { outputObscuredDueToInsufficientExternalProtectionChanged(true); }
+    void endSimulatedHDCPError() override { outputObscuredDueToInsufficientExternalProtectionChanged(false); }
 #endif
 
 #if ENABLE(AVF_CAPTIONS)

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm (228708 => 228709)


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm	2018-02-19 21:03:39 UTC (rev 228708)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm	2018-02-19 21:22:15 UTC (rev 228709)
@@ -2474,14 +2474,24 @@
     m_session = session->createWeakPtr();
     return WTFMove(session);
 }
+#endif
 
+#if ENABLE(ENCRYPTED_MEDIA) || ENABLE(LEGACY_ENCRYPTED_MEDIA)
 void MediaPlayerPrivateAVFoundationObjC::outputObscuredDueToInsufficientExternalProtectionChanged(bool newValue)
 {
+#if ENABLE(LEGACY_ENCRYPTED_MEDIA)
     if (m_session && newValue)
         m_session->playerDidReceiveError([NSError errorWithDomain:@"com.apple.WebKit" code:'HDCP' userInfo:nil]);
-}
+#endif
 
+#if ENABLE(ENCRYPTED_MEDIA) && HAVE(AVCONTENTKEYSESSION)
+    if (m_cdmInstance)
+        m_cdmInstance->outputObscuredDueToInsufficientExternalProtectionChanged(newValue);
+#elif !ENABLE(LEGACY_ENCRYPTED_MEDIA)
+    UNUSED_PARAM(newValue);
 #endif
+}
+#endif
 
 #if ENABLE(ENCRYPTED_MEDIA)
 void MediaPlayerPrivateAVFoundationObjC::cdmInstanceAttached(CDMInstance& instance)
@@ -3290,7 +3300,7 @@
         @"externalPlaybackActive",
         @"allowsExternalPlayback",
 #endif
-#if ENABLE(LEGACY_ENCRYPTED_MEDIA)
+#if ENABLE(LEGACY_ENCRYPTED_MEDIA) || ENABLE(ENCRYPTED_MEDIA)
         @"outputObscuredDueToInsufficientExternalProtection",
 #endif
     nil];
@@ -3408,7 +3418,7 @@
         else if ([keyPath isEqualToString:@"externalPlaybackActive"] || [keyPath isEqualToString:@"allowsExternalPlayback"])
             function = std::bind(&MediaPlayerPrivateAVFoundationObjC::playbackTargetIsWirelessDidChange, m_callback);
 #endif
-#if ENABLE(LEGACY_ENCRYPTED_MEDIA)
+#if ENABLE(LEGACY_ENCRYPTED_MEDIA) || ENABLE(ENCRYPTED_MEDIA)
         else if ([keyPath isEqualToString:@"outputObscuredDueToInsufficientExternalProtection"])
             function = std::bind(&MediaPlayerPrivateAVFoundationObjC::outputObscuredDueToInsufficientExternalProtectionChanged, m_callback, [newValue boolValue]);
 #endif

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.h (228708 => 228709)


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.h	2018-02-19 21:03:39 UTC (rev 228708)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.h	2018-02-19 21:22:15 UTC (rev 228709)
@@ -135,6 +135,10 @@
 
 #if ENABLE(LEGACY_ENCRYPTED_MEDIA) || ENABLE(ENCRYPTED_MEDIA)
     void keyNeeded(Uint8Array*);
+
+    void outputObscuredDueToInsufficientExternalProtectionChanged(bool);
+    void beginSimulatedHDCPError() override { outputObscuredDueToInsufficientExternalProtectionChanged(true); }
+    void endSimulatedHDCPError() override { outputObscuredDueToInsufficientExternalProtectionChanged(false); }
 #endif
 #if ENABLE(ENCRYPTED_MEDIA)
     void initializationDataEncountered(const String&, RefPtr<ArrayBuffer>&&);

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm (228708 => 228709)


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm	2018-02-19 21:03:39 UTC (rev 228708)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm	2018-02-19 21:22:15 UTC (rev 228709)
@@ -956,7 +956,17 @@
 {
     m_player->keyNeeded(initData);
 }
+
+void MediaPlayerPrivateMediaSourceAVFObjC::outputObscuredDueToInsufficientExternalProtectionChanged(bool obscured)
+{
+#if ENABLE(ENCRYPTED_MEDIA)
+    if (m_cdmInstance)
+        m_cdmInstance->setHDCPStatus(obscured ? CDMInstance::HDCPStatus::OutputRestricted : CDMInstance::HDCPStatus::Valid);
+#else
+    UNUSED_PARAM(obscured);
 #endif
+}
+#endif
 
 #if ENABLE(ENCRYPTED_MEDIA)
 void MediaPlayerPrivateMediaSourceAVFObjC::cdmInstanceAttached(CDMInstance& instance)

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h (228708 => 228709)


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h	2018-02-19 21:03:39 UTC (rev 228708)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h	2018-02-19 21:22:15 UTC (rev 228709)
@@ -116,6 +116,7 @@
     void registerForErrorNotifications(SourceBufferPrivateAVFObjCErrorClient*);
     void unregisterForErrorNotifications(SourceBufferPrivateAVFObjCErrorClient*);
     void layerDidReceiveError(AVSampleBufferDisplayLayer *, NSError *);
+    void outputObscuredDueToInsufficientExternalProtectionChanged(bool);
 #pragma clang diagnostic push
 #pragma clang diagnostic ignored "-Wunknown-pragmas"
 #pragma clang diagnostic ignored "-Wunguarded-availability-new"

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm (228708 => 228709)


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm	2018-02-19 21:03:39 UTC (rev 228708)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm	2018-02-19 21:22:15 UTC (rev 228709)
@@ -373,12 +373,9 @@
                 protectedSelf->_parent->layerDidReceiveError(layer.get(), error.get());
             });
         } else if ([keyPath isEqualTo:@"outputObscuredDueToInsufficientExternalProtection"]) {
-            if ([[change valueForKey:NSKeyValueChangeNewKey] boolValue]) {
-                RetainPtr<NSError> error = [NSError errorWithDomain:@"com.apple.WebKit" code:'HDCP' userInfo:nil];
-                callOnMainThread([protectedSelf = WTFMove(protectedSelf), layer = WTFMove(layer), error = WTFMove(error)] {
-                    protectedSelf->_parent->layerDidReceiveError(layer.get(), error.get());
-                });
-            }
+            callOnMainThread([protectedSelf = WTFMove(protectedSelf), obscured = [[change valueForKey:NSKeyValueChangeNewKey] boolValue]] {
+                protectedSelf->_parent->outputObscuredDueToInsufficientExternalProtectionChanged(obscured);
+            });
         } else
             ASSERT_NOT_REACHED();
 
@@ -987,6 +984,21 @@
         m_client->sourceBufferPrivateDidReceiveRenderingError(errorCode);
 }
 
+void SourceBufferPrivateAVFObjC::outputObscuredDueToInsufficientExternalProtectionChanged(bool obscured)
+{
+#if ENABLE(ENCRYPTED_MEDIA) && HAVE(AVCONTENTKEYSESSION)
+    if (m_mediaSource->player()->cdmInstance()) {
+        m_mediaSource->player()->outputObscuredDueToInsufficientExternalProtectionChanged(obscured);
+        return;
+    }
+#else
+    UNUSED_PARAM(obscured);
+#endif
+
+    RetainPtr<NSError> error = [NSError errorWithDomain:@"com.apple.WebKit" code:'HDCP' userInfo:nil];
+    layerDidReceiveError(m_displayLayer.get(), error.get());
+}
+
 #pragma clang diagnostic push
 #pragma clang diagnostic ignored "-Wunknown-pragmas"
 #pragma clang diagnostic ignored "-Wunguarded-availability-new"

Modified: trunk/Source/WebCore/testing/Internals.cpp (228708 => 228709)


--- trunk/Source/WebCore/testing/Internals.cpp	2018-02-19 21:03:39 UTC (rev 228708)
+++ trunk/Source/WebCore/testing/Internals.cpp	2018-02-19 21:22:15 UTC (rev 228709)
@@ -3158,6 +3158,18 @@
     return Exception { SyntaxError };
 }
 
+void Internals::beginSimulatedHDCPError(HTMLMediaElement& element)
+{
+    if (auto player = element.player())
+        player->beginSimulatedHDCPError();
+}
+
+void Internals::endSimulatedHDCPError(HTMLMediaElement& element)
+{
+    if (auto player = element.player())
+        player->endSimulatedHDCPError();
+}
+
 #endif
 
 bool Internals::isSelectPopupVisible(HTMLSelectElement& element)

Modified: trunk/Source/WebCore/testing/Internals.h (228708 => 228709)


--- trunk/Source/WebCore/testing/Internals.h	2018-02-19 21:03:39 UTC (rev 228708)
+++ trunk/Source/WebCore/testing/Internals.h	2018-02-19 21:22:15 UTC (rev 228709)
@@ -463,6 +463,8 @@
     Vector<String> mediaResponseContentRanges(HTMLMediaElement&);
     void simulateAudioInterruption(HTMLMediaElement&);
     ExceptionOr<bool> mediaElementHasCharacteristic(HTMLMediaElement&, const String&);
+    void beginSimulatedHDCPError(HTMLMediaElement&);
+    void endSimulatedHDCPError(HTMLMediaElement&);
 #endif
 
     bool isSelectPopupVisible(HTMLSelectElement&);

Modified: trunk/Source/WebCore/testing/Internals.idl (228708 => 228709)


--- trunk/Source/WebCore/testing/Internals.idl	2018-02-19 21:03:39 UTC (rev 228708)
+++ trunk/Source/WebCore/testing/Internals.idl	2018-02-19 21:22:15 UTC (rev 228709)
@@ -420,6 +420,8 @@
     [Conditional=VIDEO] sequence<DOMString> mediaResponseContentRanges(HTMLMediaElement media);
     [Conditional=VIDEO] void simulateAudioInterruption(HTMLMediaElement element);
     [Conditional=VIDEO, MayThrowException] boolean mediaElementHasCharacteristic(HTMLMediaElement element, DOMString characteristic);
+    [Conditional=VIDEO] void beginSimulatedHDCPError(HTMLMediaElement media);
+    [Conditional=VIDEO] void endSimulatedHDCPError(HTMLMediaElement media);
 
     [Conditional=LEGACY_ENCRYPTED_MEDIA] void initializeMockCDM();
     [Conditional=ENCRYPTED_MEDIA] MockCDMFactory registerMockCDM();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to