Title: [199672] trunk/Source/WebCore
Revision
199672
Author
jer.no...@apple.com
Date
2016-04-18 09:14:36 -0700 (Mon, 18 Apr 2016)

Log Message

[Mac][EME] Protected content over HLS is not notified when a HDCP violation occurs.
https://bugs.webkit.org/show_bug.cgi?id=156633

Reviewed by Eric Carlson.

Pass through the existing "outputObscuredDueToInsufficientExternalProtection" status as an
error, similarly to what we do for CDMSessionMediaSourceAVFObjC.

* platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.h:
(WebCore::CDMSessionAVFoundationObjC::~CDMSessionAVFoundationObjC): Deleted.
* platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.mm:
(SOFT_LINK_CLASS):
(-[WebCDMSessionAVFoundationObjCListener initWithParent:player:]):
(-[WebCDMSessionAVFoundationObjCListener invalidate]):
(-[WebCDMSessionAVFoundationObjCListener observeValueForKeyPath:ofObject:change:context:]):
(WebCore::CDMSessionAVFoundationObjC::CDMSessionAVFoundationObjC):
(WebCore::CDMSessionAVFoundationObjC::~CDMSessionAVFoundationObjC):
(WebCore::CDMSessionAVFoundationObjC::generateKeyRequest):
(WebCore::CDMSessionAVFoundationObjC::playerDidReceiveError):
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
(WebCore::MediaPlayerPrivateAVFoundationObjC::avPlayer):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (199671 => 199672)


--- trunk/Source/WebCore/ChangeLog	2016-04-18 16:04:07 UTC (rev 199671)
+++ trunk/Source/WebCore/ChangeLog	2016-04-18 16:14:36 UTC (rev 199672)
@@ -1,3 +1,27 @@
+2016-04-15  Jer Noble  <jer.no...@apple.com>
+
+        [Mac][EME] Protected content over HLS is not notified when a HDCP violation occurs.
+        https://bugs.webkit.org/show_bug.cgi?id=156633
+
+        Reviewed by Eric Carlson.
+
+        Pass through the existing "outputObscuredDueToInsufficientExternalProtection" status as an
+        error, similarly to what we do for CDMSessionMediaSourceAVFObjC.
+
+        * platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.h:
+        (WebCore::CDMSessionAVFoundationObjC::~CDMSessionAVFoundationObjC): Deleted.
+        * platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.mm:
+        (SOFT_LINK_CLASS):
+        (-[WebCDMSessionAVFoundationObjCListener initWithParent:player:]):
+        (-[WebCDMSessionAVFoundationObjCListener invalidate]):
+        (-[WebCDMSessionAVFoundationObjCListener observeValueForKeyPath:ofObject:change:context:]):
+        (WebCore::CDMSessionAVFoundationObjC::CDMSessionAVFoundationObjC):
+        (WebCore::CDMSessionAVFoundationObjC::~CDMSessionAVFoundationObjC):
+        (WebCore::CDMSessionAVFoundationObjC::generateKeyRequest):
+        (WebCore::CDMSessionAVFoundationObjC::playerDidReceiveError):
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
+        (WebCore::MediaPlayerPrivateAVFoundationObjC::avPlayer):
+
 2016-04-18  Chris Dumez  <cdu...@apple.com>
 
         Unreviewed, rolling out r199644.

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.h (199671 => 199672)


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.h	2016-04-18 16:04:07 UTC (rev 199671)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.h	2016-04-18 16:14:36 UTC (rev 199672)
@@ -28,10 +28,12 @@
 
 #include "CDMSession.h"
 #include <wtf/RetainPtr.h>
+#include <wtf/WeakPtr.h>
 
 #if ENABLE(ENCRYPTED_MEDIA_V2)
 
 OBJC_CLASS AVAssetResourceLoadingRequest;
+OBJC_CLASS WebCDMSessionAVFoundationObjCListener;
 
 namespace WebCore {
 
@@ -40,7 +42,7 @@
 class CDMSessionAVFoundationObjC : public CDMSession {
 public:
     CDMSessionAVFoundationObjC(MediaPlayerPrivateAVFoundationObjC* parent, CDMSessionClient*);
-    virtual ~CDMSessionAVFoundationObjC() { }
+    virtual ~CDMSessionAVFoundationObjC();
 
     CDMSessionType type() override { return CDMSessionTypeAVFoundationObjC; }
     void setClient(CDMSessionClient* client) override { m_client = client; }
@@ -49,11 +51,14 @@
     void releaseKeys() override;
     bool update(Uint8Array*, RefPtr<Uint8Array>& nextMessage, unsigned short& errorCode, uint32_t& systemCode) override;
 
+    void playerDidReceiveError(NSError *);
+
 protected:
-    MediaPlayerPrivateAVFoundationObjC* m_parent;
+    WeakPtr<MediaPlayerPrivateAVFoundationObjC> m_parent;
     CDMSessionClient* m_client;
     String m_sessionId;
     RetainPtr<AVAssetResourceLoadingRequest> m_request;
+    RetainPtr<WebCDMSessionAVFoundationObjCListener> m_listener;
 };
 
 }

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.mm (199671 => 199672)


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.mm	2016-04-18 16:04:07 UTC (rev 199671)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.mm	2016-04-18 16:14:36 UTC (rev 199672)
@@ -38,6 +38,7 @@
 #import "WebCoreNSErrorExtras.h"
 #import <AVFoundation/AVFoundation.h>
 #import <objc/objc-runtime.h>
+#import <wtf/MainThread.h>
 
 SOFT_LINK_FRAMEWORK_OPTIONAL(AVFoundation)
 SOFT_LINK_CLASS(AVFoundation, AVURLAsset)
@@ -45,19 +46,79 @@
 #define AVURLAsset getAVURLAssetClass()
 #define AVAssetResourceLoadingRequest getAVAssetResourceLoadingRequest()
 
+@interface WebCDMSessionAVFoundationObjCListener : NSObject {
+    WebCore::CDMSessionAVFoundationObjC* _parent;
+    RetainPtr<AVPlayer> _player;
+}
+- (id)initWithParent:(WebCore::CDMSessionAVFoundationObjC*)parent player:(AVPlayer *)player;
+- (void)invalidate;
+@end
+
+@implementation WebCDMSessionAVFoundationObjCListener
+- (id)initWithParent:(WebCore::CDMSessionAVFoundationObjC*)parent player:(AVPlayer *)player
+{
+    self = [super init];
+    if (!self)
+        return nil;
+
+    _parent = parent;
+    _player = player;
+    [player addObserver:self forKeyPath:@"outputObscuredDueToInsufficientExternalProtection" options:NSKeyValueObservingOptionNew context:nil];
+
+    return self;
+}
+
+- (void)invalidate
+{
+    _parent = nullptr;
+    [_player removeObserver:self forKeyPath:@"outputObscuredDueToInsufficientExternalProtection"];
+    _player = nullptr;
+}
+
+- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
+{
+    UNUSED_PARAM(context);
+    UNUSED_PARAM(object);
+    ASSERT(_parent);
+
+    if ([keyPath isEqualTo:@"outputObscuredDueToInsufficientExternalProtection"]) {
+        if ([[change valueForKey:NSKeyValueChangeNewKey] intValue] == 1) {
+            RetainPtr<NSError> error = [NSError errorWithDomain:@"com.apple.WebKit" code:'HDCP' userInfo:nil];
+            RetainPtr<WebCDMSessionAVFoundationObjCListener> strongSelf = { self };
+            callOnMainThread([strongSelf, error] {
+                if (strongSelf->_parent)
+                    strongSelf->_parent->playerDidReceiveError(error.get());
+            });
+        }
+    } else
+        ASSERT_NOT_REACHED();
+}
+@end
+
 namespace WebCore {
 
 CDMSessionAVFoundationObjC::CDMSessionAVFoundationObjC(MediaPlayerPrivateAVFoundationObjC* parent, CDMSessionClient* client)
-    : m_parent(parent)
+    : m_parent(parent->createWeakPtr())
     , m_client(client)
     , m_sessionId(createCanonicalUUIDString())
+    , m_listener(adoptNS([[WebCDMSessionAVFoundationObjCListener alloc] initWithParent:this player:parent->avPlayer()]))
 {
 }
 
+CDMSessionAVFoundationObjC::~CDMSessionAVFoundationObjC()
+{
+    [m_listener invalidate];
+}
+
 RefPtr<Uint8Array> CDMSessionAVFoundationObjC::generateKeyRequest(const String& mimeType, Uint8Array* initData, String& destinationURL, unsigned short& errorCode, uint32_t& systemCode)
 {
     UNUSED_PARAM(mimeType);
 
+    if (!m_parent) {
+        errorCode = CDM::UnknownError;
+        return nullptr;
+    }
+
     String keyURI;
     String keyID;
     RefPtr<Uint8Array> certificate;
@@ -108,6 +169,15 @@
     return true;
 }
 
+void CDMSessionAVFoundationObjC::playerDidReceiveError(NSError *error)
+{
+    if (!m_client)
+        return;
+
+    unsigned long code = mediaKeyErrorSystemCode(error);
+    m_client->sendError(CDMSessionClient::MediaKeyErrorDomain, code);
 }
 
+}
+
 #endif

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


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h	2016-04-18 16:04:07 UTC (rev 199671)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h	2016-04-18 16:14:36 UTC (rev 199672)
@@ -99,6 +99,7 @@
     void processCue(NSArray *, NSArray *, const MediaTime&);
     void flushCues();
 #endif
+    AVPlayer *avPlayer() const { return m_avPlayer.get(); }
     
 #if HAVE(AVFOUNDATION_LOADER_DELEGATE)
     bool shouldWaitForLoadingOfResource(AVAssetResourceLoadingRequest*);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to