⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 245947 in webkit


Ignore:
Timestamp:
May 30, 2019, 9:46:39 PM (7 years ago)
Author:
jer.noble@apple.com
Message:

Video playback in Safari should continue when CarPlay is plugged in
https://bugs.webkit.org/show_bug.cgi?id=198345
<rdar://problem/45505750>

Reviewed by Eric Carlson.

Source/WebCore:

Test: media/video-isplayingtoautomotiveheadunit.html

  • html/HTMLMediaElement.cpp:

(WebCore::HTMLMediaElement::shouldOverrideBackgroundPlaybackRestriction const):

  • platform/audio/PlatformMediaSessionManager.cpp:

(WebCore::PlatformMediaSessionManager::setIsPlayingToAutomotiveHeadUnit):

  • platform/audio/PlatformMediaSessionManager.h:

(WebCore::PlatformMediaSessionManager::isPlayingToAutomotiveHeadUnit const):

  • platform/audio/ios/MediaSessionManagerIOS.h:
  • platform/audio/ios/MediaSessionManagerIOS.mm:

(WebCore::MediaSessionManageriOS::MediaSessionManageriOS):
(WebCore::MediaSessionManageriOS::carPlayServerDied):
(WebCore::MediaSessionManageriOS::updateCarPlayIsConnected):
(-[WebMediaSessionHelper initWithCallback:]):
(-[WebMediaSessionHelper startMonitoringAirPlayRoutes]):
(-[WebMediaSessionHelper interruption:]):
(-[WebMediaSessionHelper applicationWillEnterForeground:]):
(-[WebMediaSessionHelper applicationDidBecomeActive:]):
(-[WebMediaSessionHelper applicationWillResignActive:]):
(-[WebMediaSessionHelper wirelessRoutesAvailableDidChange:]):
(-[WebMediaSessionHelper applicationDidEnterBackground:]):
(-[WebMediaSessionHelper carPlayServerDied:]):
(-[WebMediaSessionHelper carPlayIsConnectedDidChange:]):

  • testing/Internals.cpp:

(WebCore::Internals::resetToConsistentState):
(WebCore::Internals::setIsPlayingToAutomotiveHeadUnit):

  • testing/Internals.h:
  • testing/Internals.idl:

LayoutTests:

  • media/video-isplayingtoautomotiveheadunit-expected.txt: Added.
  • media/video-isplayingtoautomotiveheadunit.html: Added.
Location:
trunk
Files:
2 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r245946 r245947  
     12019-05-30  Jer Noble  <jer.noble@apple.com>
     2
     3        Video playback in Safari should continue when CarPlay is plugged in
     4        https://bugs.webkit.org/show_bug.cgi?id=198345
     5        <rdar://problem/45505750>
     6
     7        Reviewed by Eric Carlson.
     8
     9        * media/video-isplayingtoautomotiveheadunit-expected.txt: Added.
     10        * media/video-isplayingtoautomotiveheadunit.html: Added.
     11
    1122019-05-30  Youenn Fablet  <youenn@apple.com>
    213
  • trunk/Source/WebCore/ChangeLog

    r245946 r245947  
     12019-05-30  Jer Noble  <jer.noble@apple.com>
     2
     3        Video playback in Safari should continue when CarPlay is plugged in
     4        https://bugs.webkit.org/show_bug.cgi?id=198345
     5        <rdar://problem/45505750>
     6
     7        Reviewed by Eric Carlson.
     8
     9        Test: media/video-isplayingtoautomotiveheadunit.html
     10
     11        * html/HTMLMediaElement.cpp:
     12        (WebCore::HTMLMediaElement::shouldOverrideBackgroundPlaybackRestriction const):
     13        * platform/audio/PlatformMediaSessionManager.cpp:
     14        (WebCore::PlatformMediaSessionManager::setIsPlayingToAutomotiveHeadUnit):
     15        * platform/audio/PlatformMediaSessionManager.h:
     16        (WebCore::PlatformMediaSessionManager::isPlayingToAutomotiveHeadUnit const):
     17        * platform/audio/ios/MediaSessionManagerIOS.h:
     18        * platform/audio/ios/MediaSessionManagerIOS.mm:
     19        (WebCore::MediaSessionManageriOS::MediaSessionManageriOS):
     20        (WebCore::MediaSessionManageriOS::carPlayServerDied):
     21        (WebCore::MediaSessionManageriOS::updateCarPlayIsConnected):
     22        (-[WebMediaSessionHelper initWithCallback:]):
     23        (-[WebMediaSessionHelper startMonitoringAirPlayRoutes]):
     24        (-[WebMediaSessionHelper interruption:]):
     25        (-[WebMediaSessionHelper applicationWillEnterForeground:]):
     26        (-[WebMediaSessionHelper applicationDidBecomeActive:]):
     27        (-[WebMediaSessionHelper applicationWillResignActive:]):
     28        (-[WebMediaSessionHelper wirelessRoutesAvailableDidChange:]):
     29        (-[WebMediaSessionHelper applicationDidEnterBackground:]):
     30        (-[WebMediaSessionHelper carPlayServerDied:]):
     31        (-[WebMediaSessionHelper carPlayIsConnectedDidChange:]):
     32        * testing/Internals.cpp:
     33        (WebCore::Internals::resetToConsistentState):
     34        (WebCore::Internals::setIsPlayingToAutomotiveHeadUnit):
     35        * testing/Internals.h:
     36        * testing/Internals.idl:
     37
    1382019-05-30  Youenn Fablet  <youenn@apple.com>
    239
  • trunk/Source/WebCore/html/HTMLMediaElement.cpp

    r245944 r245947  
    77167716            return true;
    77177717        }
     7718        if (PlatformMediaSessionManager::sharedManager().isPlayingToAutomotiveHeadUnit()) {
     7719            INFO_LOG(LOGIDENTIFIER, "returning true because isPlayingToAutomotiveHeadUnit() is true");
     7720            return true;
     7721        }
    77187722        if (m_videoFullscreenMode & VideoFullscreenModePictureInPicture)
    77197723            return true;
     
    77257729        if (isPlayingToExternalTarget()) {
    77267730            INFO_LOG(LOGIDENTIFIER, "returning true because isPlayingToExternalTarget() is true");
     7731            return true;
     7732        }
     7733        if (PlatformMediaSessionManager::sharedManager().isPlayingToAutomotiveHeadUnit()) {
     7734            INFO_LOG(LOGIDENTIFIER, "returning true because isPlayingToAutomotiveHeadUnit() is true");
    77277735            return true;
    77287736        }
  • trunk/Source/WebCore/platform/audio/PlatformMediaSessionManager.cpp

    r245944 r245947  
    392392}
    393393
     394void PlatformMediaSessionManager::setIsPlayingToAutomotiveHeadUnit(bool isPlayingToAutomotiveHeadUnit)
     395{
     396    if (isPlayingToAutomotiveHeadUnit == m_isPlayingToAutomotiveHeadUnit)
     397        return;
     398
     399    ALWAYS_LOG(LOGIDENTIFIER, isPlayingToAutomotiveHeadUnit);
     400    m_isPlayingToAutomotiveHeadUnit = isPlayingToAutomotiveHeadUnit;
     401}
    394402
    395403void PlatformMediaSessionManager::sessionIsPlayingToWirelessPlaybackTargetChanged(PlatformMediaSession& session)
  • trunk/Source/WebCore/platform/audio/PlatformMediaSessionManager.h

    r245944 r245947  
    130130    void sessionIsPlayingToWirelessPlaybackTargetChanged(PlatformMediaSession&);
    131131
     132    WEBCORE_EXPORT void setIsPlayingToAutomotiveHeadUnit(bool);
     133    bool isPlayingToAutomotiveHeadUnit() const { return m_isPlayingToAutomotiveHeadUnit; }
     134
    132135    void forEachMatchingSession(const Function<bool(const PlatformMediaSession&)>& predicate, const Function<void(PlatformMediaSession&)>& matchingCallback);
    133136
     
    189192    bool m_willIgnoreSystemInterruptions { false };
    190193    bool m_processIsSuspended { false };
     194    bool m_isPlayingToAutomotiveHeadUnit { false };
    191195
    192196#if USE(AUDIO_SESSION)
  • trunk/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.h

    r245944 r245947  
    4848    void externalOutputDeviceAvailableDidChange();
    4949    bool hasWirelessTargetsAvailable() override;
     50#if HAVE(CELESTIAL)
     51    void carPlayServerDied();
     52    void updateCarPlayIsConnected(Optional<bool>&&);
     53#endif
    5054
    5155private:
  • trunk/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm

    r245944 r245947  
    5757SOFT_LINK_CLASS_OPTIONAL(Celestial, AVSystemController)
    5858SOFT_LINK_CONSTANT_MAY_FAIL(Celestial, AVSystemController_PIDToInheritApplicationStateFrom, NSString *)
     59SOFT_LINK_CONSTANT_MAY_FAIL(Celestial, AVSystemController_CarPlayIsConnectedAttribute, NSString *)
     60SOFT_LINK_CONSTANT_MAY_FAIL(Celestial, AVSystemController_CarPlayIsConnectedDidChangeNotification, NSString *)
     61SOFT_LINK_CONSTANT_MAY_FAIL(Celestial, AVSystemController_CarPlayIsConnectedNotificationParameter, NSString *)
     62SOFT_LINK_CONSTANT_MAY_FAIL(Celestial, AVSystemController_ServerConnectionDiedNotification, NSString *)
    5963#endif
    6064
     
    110114    END_BLOCK_OBJC_EXCEPTIONS
    111115    resetRestrictions();
     116
     117#if HAVE(CELESTIAL)
     118    updateCarPlayIsConnected(WTF::nullopt);
     119#endif
    112120}
    113121
     
    194202    END_BLOCK_OBJC_EXCEPTIONS
    195203}
     204
     205#if HAVE(CELESTIAL)
     206void MediaSessionManageriOS::carPlayServerDied()
     207{
     208    ALWAYS_LOG(LOGIDENTIFIER);
     209    updateCarPlayIsConnected(WTF::nullopt);
     210}
     211
     212void MediaSessionManageriOS::updateCarPlayIsConnected(Optional<bool>&& carPlayIsConnected)
     213{
     214    if (carPlayIsConnected) {
     215        setIsPlayingToAutomotiveHeadUnit(carPlayIsConnected.value());
     216        return;
     217    }
     218
     219    if (!canLoadAVSystemController_CarPlayIsConnectedAttribute()) {
     220        setIsPlayingToAutomotiveHeadUnit(false);
     221        return;
     222    }
     223
     224    setIsPlayingToAutomotiveHeadUnit([[[getAVSystemControllerClass() sharedAVSystemController] attributeForKey:getAVSystemController_CarPlayIsConnectedAttribute()] boolValue]);
     225}
     226#endif
    196227
    197228} // namespace WebCore
     
    219250    [center addObserver:self selector:@selector(applicationDidEnterBackground:) name:PAL::get_UIKit_UIApplicationDidEnterBackgroundNotification() object:nil];
    220251    [center addObserver:self selector:@selector(applicationDidEnterBackground:) name:WebUIApplicationDidEnterBackgroundNotification object:nil];
     252#if HAVE(CELESTIAL)
     253    if (canLoadAVSystemController_ServerConnectionDiedNotification())
     254        [center addObserver:self selector:@selector(carPlayServerDied:) name:getAVSystemController_ServerConnectionDiedNotification() object:nil];
     255    if (canLoadAVSystemController_CarPlayIsConnectedDidChangeNotification())
     256        [center addObserver:self selector:@selector(carPlayIsConnectedDidChange:) name:getAVSystemController_CarPlayIsConnectedDidChangeNotification() object:nil];
     257#endif
    221258
    222259    // Now playing won't work unless we turn on the delivery of remote control events.
     
    287324    LOG(Media, "-[WebMediaSessionHelper startMonitoringAirPlayRoutes]");
    288325
    289     callOnWebThreadOrDispatchAsyncOnMainThread([protectedSelf = WTFMove(self)]() mutable {
     326    callOnWebThreadOrDispatchAsyncOnMainThread([protectedSelf = retainPtr(self)]() mutable {
    290327        ASSERT(!protectedSelf->_routeDetector);
    291328
     
    294331            protectedSelf->_routeDetector = adoptNS([PAL::allocAVRouteDetectorInstance() init]);
    295332            protectedSelf->_routeDetector.get().routeDetectionEnabled = protectedSelf->_monitoringAirPlayRoutes;
    296             [[NSNotificationCenter defaultCenter] addObserver:protectedSelf selector:@selector(wirelessRoutesAvailableDidChange:) name:AVRouteDetectorMultipleRoutesDetectedDidChangeNotification object:protectedSelf->_routeDetector.get()];
     333            [[NSNotificationCenter defaultCenter] addObserver:protectedSelf.get() selector:@selector(wirelessRoutesAvailableDidChange:) name:AVRouteDetectorMultipleRoutesDetectedDidChangeNotification object:protectedSelf->_routeDetector.get()];
    297334
    298335            protectedSelf->_callback->externalOutputDeviceAvailableDidChange();
     
    329366        flags = PlatformMediaSession::MayResumePlaying;
    330367
    331     callOnWebThreadOrDispatchAsyncOnMainThread([protectedSelf = WTFMove(self), type, flags]() mutable {
     368    callOnWebThreadOrDispatchAsyncOnMainThread([protectedSelf = retainPtr(self), type, flags]() mutable {
    332369        auto* callback = protectedSelf->_callback;
    333370        if (!callback)
     
    352389
    353390    BOOL isSuspendedUnderLock = [[[notification userInfo] objectForKey:@"isSuspendedUnderLock"] boolValue];
    354     callOnWebThreadOrDispatchAsyncOnMainThread([protectedSelf = WTFMove(self), isSuspendedUnderLock]() mutable {
     391    callOnWebThreadOrDispatchAsyncOnMainThread([protectedSelf = retainPtr(self), isSuspendedUnderLock]() mutable {
    355392        if (auto* callback = protectedSelf->_callback)
    356393            callback->applicationWillEnterForeground(isSuspendedUnderLock);
     
    367404    LOG(Media, "-[WebMediaSessionHelper applicationDidBecomeActive]");
    368405
    369     callOnWebThreadOrDispatchAsyncOnMainThread([protectedSelf = WTFMove(self)]() mutable {
     406    callOnWebThreadOrDispatchAsyncOnMainThread([protectedSelf = retainPtr(self)]() mutable {
    370407        if (auto* callback = protectedSelf->_callback)
    371408            callback->applicationDidBecomeActive();
     
    382419    LOG(Media, "-[WebMediaSessionHelper applicationWillResignActive]");
    383420
    384     callOnWebThreadOrDispatchAsyncOnMainThread([protectedSelf = WTFMove(self)]() mutable {
     421    callOnWebThreadOrDispatchAsyncOnMainThread([protectedSelf = retainPtr(self)]() mutable {
    385422        if (auto* callback = protectedSelf->_callback)
    386423            callback->applicationWillBecomeInactive();
     
    397434    LOG(Media, "-[WebMediaSessionHelper wirelessRoutesAvailableDidChange]");
    398435
    399     callOnWebThreadOrDispatchAsyncOnMainThread([protectedSelf = WTFMove(self)]() mutable {
     436    callOnWebThreadOrDispatchAsyncOnMainThread([protectedSelf = retainPtr(self)]() mutable {
    400437        if (auto* callback = protectedSelf->_callback)
    401438            callback->externalOutputDeviceAvailableDidChange();
     
    411448
    412449    BOOL isSuspendedUnderLock = [[[notification userInfo] objectForKey:@"isSuspendedUnderLock"] boolValue];
    413     callOnWebThreadOrDispatchAsyncOnMainThread([protectedSelf = WTFMove(self), isSuspendedUnderLock]() mutable {
     450    callOnWebThreadOrDispatchAsyncOnMainThread([protectedSelf = retainPtr(self), isSuspendedUnderLock]() mutable {
    414451        if (auto* callback = protectedSelf->_callback)
    415452            callback->applicationDidEnterBackground(isSuspendedUnderLock);
    416453    });
    417454}
     455
     456#if HAVE(CELESTIAL)
     457- (void)carPlayServerDied:(NSNotification *)notification
     458{
     459    if (!_callback)
     460        return;
     461
     462    LOG(Media, "-[WebMediaSessionHelper carPlayServerDied:]");
     463    UNUSED_PARAM(notification);
     464    callOnWebThreadOrDispatchAsyncOnMainThread([protectedSelf = retainPtr(self)]() mutable {
     465        if (auto* callback = protectedSelf->_callback)
     466            callback->carPlayServerDied();
     467    });
     468}
     469
     470- (void)carPlayIsConnectedDidChange:(NSNotification *)notification
     471{
     472    if (!_callback)
     473        return;
     474
     475    Optional<bool> carPlayIsConnected;
     476    if (notification && canLoadAVSystemController_CarPlayIsConnectedNotificationParameter()) {
     477        NSNumber *nsCarPlayIsConnected = [[notification userInfo] valueForKey:getAVSystemController_CarPlayIsConnectedNotificationParameter()];
     478        if (nsCarPlayIsConnected)
     479            carPlayIsConnected = [nsCarPlayIsConnected boolValue];
     480    }
     481
     482    callOnWebThreadOrDispatchAsyncOnMainThread([protectedSelf = retainPtr(self), carPlayIsConnected = WTFMove(carPlayIsConnected)]() mutable {
     483        if (auto* callback = protectedSelf->_callback)
     484            callback->updateCarPlayIsConnected(WTFMove(carPlayIsConnected));
     485    });
     486}
     487#endif // HAVE(CELESTIAL)
    418488@end
    419489
  • trunk/Source/WebCore/testing/Internals.cpp

    r245946 r245947  
    493493    PlatformMediaSessionManager::sharedManager().setWillIgnoreSystemInterruptions(true);
    494494#endif
     495    PlatformMediaSessionManager::sharedManager().setIsPlayingToAutomotiveHeadUnit(false);
    495496#if HAVE(ACCESSIBILITY)
    496497    AXObjectCache::setEnhancedUserInterfaceAccessibility(false);
     
    50765077}
    50775078
     5079void Internals::setIsPlayingToAutomotiveHeadUnit(bool isPlaying)
     5080{
     5081    PlatformMediaSessionManager::sharedManager().setIsPlayingToAutomotiveHeadUnit(isPlaying);
     5082}
     5083
    50785084} // namespace WebCore
  • trunk/Source/WebCore/testing/Internals.h

    r245946 r245947  
    825825    void setXHRMaximumIntervalForUserGestureForwarding(XMLHttpRequest&, double);
    826826
     827    void setIsPlayingToAutomotiveHeadUnit(bool);
     828
    827829private:
    828830    explicit Internals(Document&);
  • trunk/Source/WebCore/testing/Internals.idl

    r245946 r245947  
    755755
    756756    void setXHRMaximumIntervalForUserGestureForwarding(XMLHttpRequest xhr, double interval);
    757 };
     757
     758    void setIsPlayingToAutomotiveHeadUnit(boolean value);
     759};
Note: See TracChangeset for help on using the changeset viewer.