Title: [201524] trunk/Source/WebCore
Revision
201524
Author
jer.no...@apple.com
Date
2016-05-31 14:24:19 -0700 (Tue, 31 May 2016)

Log Message

[EME] Sound continues playing when video's src is changed
https://bugs.webkit.org/show_bug.cgi?id=158233

Reviewed by Eric Carlson.

When CDMSessionAVFoundation began listening for outputObscuredDueToInsufficientExternalProtection
KVO notifications, it retained the AVPlayer owned by MediaPlayerPrivateAVFoundationObjC, which
caused the AVPlayer to outlive its original owner, and to continue playing even after the
MediaPlayerPrivateAVFoundationObjC had been destroyed.

Rather than observe for outputObscuredDueToInsufficientExternalProtection changes in
CDMSessionAVFoundation, add a backreference from the media player to the session, listen for changes
in the player, and have the player notify the session when the value of that property changes.

* platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.h:
(WebCore::CDMSessionAVFoundationObjC::createWeakPtr):
* platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.mm:
(WebCore::CDMSessionAVFoundationObjC::CDMSessionAVFoundationObjC):
(-[WebCDMSessionAVFoundationObjCListener initWithParent:player:]): Deleted.
(-[WebCDMSessionAVFoundationObjCListener invalidate]): Deleted.
(-[WebCDMSessionAVFoundationObjCListener observeValueForKeyPath:ofObject:change:context:]): Deleted.
(WebCore::CDMSessionAVFoundationObjC::~CDMSessionAVFoundationObjC): Deleted.
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(WebCore::MediaPlayerPrivateAVFoundationObjC::removeSession):
(WebCore::MediaPlayerPrivateAVFoundationObjC::createSession):
(WebCore::MediaPlayerPrivateAVFoundationObjC::outputObscuredDueToInsufficientExternalProtectionChanged):
(WebCore::playerKVOProperties):
(-[WebCoreAVFMovieObserver observeValueForKeyPath:ofObject:change:context:]):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (201523 => 201524)


--- trunk/Source/WebCore/ChangeLog	2016-05-31 20:57:20 UTC (rev 201523)
+++ trunk/Source/WebCore/ChangeLog	2016-05-31 21:24:19 UTC (rev 201524)
@@ -1,3 +1,35 @@
+2016-05-31  Jer Noble  <jer.no...@apple.com>
+
+        [EME] Sound continues playing when video's src is changed
+        https://bugs.webkit.org/show_bug.cgi?id=158233
+
+        Reviewed by Eric Carlson.
+
+        When CDMSessionAVFoundation began listening for outputObscuredDueToInsufficientExternalProtection
+        KVO notifications, it retained the AVPlayer owned by MediaPlayerPrivateAVFoundationObjC, which
+        caused the AVPlayer to outlive its original owner, and to continue playing even after the
+        MediaPlayerPrivateAVFoundationObjC had been destroyed.
+
+        Rather than observe for outputObscuredDueToInsufficientExternalProtection changes in
+        CDMSessionAVFoundation, add a backreference from the media player to the session, listen for changes
+        in the player, and have the player notify the session when the value of that property changes.
+
+        * platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.h:
+        (WebCore::CDMSessionAVFoundationObjC::createWeakPtr):
+        * platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.mm:
+        (WebCore::CDMSessionAVFoundationObjC::CDMSessionAVFoundationObjC):
+        (-[WebCDMSessionAVFoundationObjCListener initWithParent:player:]): Deleted.
+        (-[WebCDMSessionAVFoundationObjCListener invalidate]): Deleted.
+        (-[WebCDMSessionAVFoundationObjCListener observeValueForKeyPath:ofObject:change:context:]): Deleted.
+        (WebCore::CDMSessionAVFoundationObjC::~CDMSessionAVFoundationObjC): Deleted.
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
+        (WebCore::MediaPlayerPrivateAVFoundationObjC::removeSession):
+        (WebCore::MediaPlayerPrivateAVFoundationObjC::createSession):
+        (WebCore::MediaPlayerPrivateAVFoundationObjC::outputObscuredDueToInsufficientExternalProtectionChanged):
+        (WebCore::playerKVOProperties):
+        (-[WebCoreAVFMovieObserver observeValueForKeyPath:ofObject:change:context:]):
+
 2016-05-31  Eric Carlson  <eric.carl...@apple.com>
 
         [Mac] AirPlay route is sometimes reset when changing video.src

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


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.h	2016-05-31 20:57:20 UTC (rev 201523)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.h	2016-05-31 21:24:19 UTC (rev 201524)
@@ -53,12 +53,14 @@
 
     void playerDidReceiveError(NSError *);
 
+    WeakPtr<CDMSessionAVFoundationObjC> createWeakPtr() { return m_weakPtrFactory.createWeakPtr(); }
+
 protected:
     WeakPtr<MediaPlayerPrivateAVFoundationObjC> m_parent;
     CDMSessionClient* m_client;
     String m_sessionId;
     RetainPtr<AVAssetResourceLoadingRequest> m_request;
-    RetainPtr<WebCDMSessionAVFoundationObjCListener> m_listener;
+    WeakPtrFactory<CDMSessionAVFoundationObjC> m_weakPtrFactory;
 };
 
 }

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


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.mm	2016-05-31 20:57:20 UTC (rev 201523)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.mm	2016-05-31 21:24:19 UTC (rev 201524)
@@ -46,68 +46,18 @@
 #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> protectedSelf = { self };
-            callOnMainThread([protectedSelf = WTFMove(protectedSelf), error = WTFMove(error)] {
-                if (protectedSelf->_parent)
-                    protectedSelf->_parent->playerDidReceiveError(error.get());
-            });
-        }
-    } else
-        ASSERT_NOT_REACHED();
-}
-@end
-
 namespace WebCore {
 
 CDMSessionAVFoundationObjC::CDMSessionAVFoundationObjC(MediaPlayerPrivateAVFoundationObjC* parent, CDMSessionClient* client)
     : m_parent(parent->createWeakPtr())
     , m_client(client)
     , m_sessionId(createCanonicalUUIDString())
-    , m_listener(adoptNS([[WebCDMSessionAVFoundationObjCListener alloc] initWithParent:this player:parent->avPlayer()]))
+    , m_weakPtrFactory(this)
 {
 }
 
 CDMSessionAVFoundationObjC::~CDMSessionAVFoundationObjC()
 {
-    [m_listener invalidate];
 }
 
 RefPtr<Uint8Array> CDMSessionAVFoundationObjC::generateKeyRequest(const String& mimeType, Uint8Array* initData, String& destinationURL, unsigned short& errorCode, uint32_t& systemCode)

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


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h	2016-05-31 20:57:20 UTC (rev 201523)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h	2016-05-31 21:24:19 UTC (rev 201524)
@@ -67,6 +67,7 @@
 
 class AudioSourceProviderAVFObjC;
 class AudioTrackPrivateAVFObjC;
+class CDMSessionAVFoundationObjC;
 class InbandMetadataTextTrackPrivateAVF;
 class InbandTextTrackPrivateAVFObjC;
 class MediaSelectionGroupAVFObjC;
@@ -142,12 +143,20 @@
 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
     void playbackTargetIsWirelessDidChange();
 #endif
-    
+
+#if ENABLE(ENCRYPTED_MEDIA_V2)
+    void outputObscuredDueToInsufficientExternalProtectionChanged(bool);
+#endif
+
 #if ENABLE(AVF_CAPTIONS)
     void notifyTrackModeChanged() override;
     void synchronizeTextTrackState() override;
 #endif
-    
+
+#if ENABLE(ENCRYPTED_MEDIA_V2)
+    void removeSession(CDMSession&);
+#endif
+
     WeakPtr<MediaPlayerPrivateAVFoundationObjC> createWeakPtr() { return m_weakPtrFactory.createWeakPtr(); }
 
 private:
@@ -392,6 +401,10 @@
     RefPtr<MediaPlaybackTarget> m_playbackTarget { nullptr };
 #endif
 
+#if ENABLE(ENCRYPTED_MEDIA_V2)
+    WeakPtr<CDMSessionAVFoundationObjC> m_session;
+#endif
+
     mutable RetainPtr<NSArray> m_cachedSeekableRanges;
     mutable RetainPtr<NSArray> m_cachedLoadedRanges;
     RetainPtr<NSArray> m_cachedTracks;

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


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm	2016-05-31 20:57:20 UTC (rev 201523)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm	2016-05-31 21:24:19 UTC (rev 201524)
@@ -2585,12 +2585,25 @@
         m_keyURIToRequestMap.remove(keyId);
 }
 
+void MediaPlayerPrivateAVFoundationObjC::removeSession(CDMSession& session)
+{
+    ASSERT(&session == m_session);
+    m_session = nullptr;
+}
+
 std::unique_ptr<CDMSession> MediaPlayerPrivateAVFoundationObjC::createSession(const String& keySystem, CDMSessionClient* client)
 {
     if (!keySystemIsSupported(keySystem))
         return nullptr;
+    auto session = std::make_unique<CDMSessionAVFoundationObjC>(this, client);
+    m_session = session->createWeakPtr();
+    return WTFMove(session);
+}
 
-    return std::make_unique<CDMSessionAVFoundationObjC>(this, client);
+void MediaPlayerPrivateAVFoundationObjC::outputObscuredDueToInsufficientExternalProtectionChanged(bool newValue)
+{
+    if (m_session && newValue)
+        m_session->playerDidReceiveError([NSError errorWithDomain:@"com.apple.WebKit" code:'HDCP' userInfo:nil]);
 }
 #endif
 
@@ -3294,6 +3307,9 @@
 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
                             @"externalPlaybackActive", @"allowsExternalPlayback",
 #endif
+#if ENABLE(ENCRYPTED_MEDIA_V2)
+                            @"outputObscuredDueToInsufficientExternalProtection",
+#endif
                             nil];
     return keys;
 }
@@ -3416,6 +3432,10 @@
         else if ([keyPath isEqualToString:@"externalPlaybackActive"] || [keyPath isEqualToString:@"allowsExternalPlayback"])
             function = std::bind(&MediaPlayerPrivateAVFoundationObjC::playbackTargetIsWirelessDidChange, m_callback);
 #endif
+#if ENABLE(ENCRYPTED_MEDIA_V2)
+        else if ([keyPath isEqualToString:@"outputObscuredDueToInsufficientExternalProtection"])
+            function = std::bind(&MediaPlayerPrivateAVFoundationObjC::outputObscuredDueToInsufficientExternalProtectionChanged, m_callback, [newValue boolValue]);
+#endif
     }
     
     if (!function)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to