Changeset 248962 in webkit


Ignore:
Timestamp:
Aug 21, 2019 2:29:52 PM (5 years ago)
Author:
jer.noble@apple.com
Message:

Adopt AVSystemController_ActiveAudioRouteDidChangeNotification
https://bugs.webkit.org/show_bug.cgi?id=200992
<rdar://problem/54408993>

Reviewed by Eric Carlson.

When the system notifies us that the active audio route has changed in such a way
that necessitates pausing, pause all media sessions, exempting those that are
associated with WebRTC, since "pausing" an active audio conference isn't really
possible.

  • Modules/mediastream/MediaStream.h:
  • platform/audio/PlatformMediaSession.cpp:

(WebCore::PlatformMediaSession::shouldOverridePauseDuringRouteChange const):

  • platform/audio/PlatformMediaSession.h:

(WebCore::PlatformMediaSessionClient::shouldOverridePauseDuringRouteChange const):

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

(WebCore::MediaSessionManageriOS::activeRouteDidChange):
(-[WebMediaSessionHelper initWithCallback:]):
(-[WebMediaSessionHelper activeAudioRouteDidChange:]):

Location:
trunk/Source/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r248960 r248962  
     12019-08-21  Jer Noble  <jer.noble@apple.com>
     2
     3        Adopt AVSystemController_ActiveAudioRouteDidChangeNotification
     4        https://bugs.webkit.org/show_bug.cgi?id=200992
     5        <rdar://problem/54408993>
     6
     7        Reviewed by Eric Carlson.
     8
     9        When the system notifies us that the active audio route has changed in such a way
     10        that necessitates pausing, pause all media sessions, exempting those that are
     11        associated with WebRTC, since "pausing" an active audio conference isn't really
     12        possible.
     13
     14        * Modules/mediastream/MediaStream.h:
     15        * platform/audio/PlatformMediaSession.cpp:
     16        (WebCore::PlatformMediaSession::shouldOverridePauseDuringRouteChange const):
     17        * platform/audio/PlatformMediaSession.h:
     18        (WebCore::PlatformMediaSessionClient::shouldOverridePauseDuringRouteChange const):
     19        * platform/audio/ios/MediaSessionManagerIOS.h:
     20        * platform/audio/ios/MediaSessionManagerIOS.mm:
     21        (WebCore::MediaSessionManageriOS::activeRouteDidChange):
     22        (-[WebMediaSessionHelper initWithCallback:]):
     23        (-[WebMediaSessionHelper activeAudioRouteDidChange:]):
     24
    1252019-08-21  Ryosuke Niwa  <rniwa@webkit.org>
    226
  • trunk/Source/WebCore/Modules/mediastream/MediaStream.h

    r248467 r248962  
    160160    Document* hostingDocument() const final { return document(); }
    161161    bool processingUserGestureForMedia() const final;
     162    bool shouldOverridePauseDuringRouteChange() const { return true; }
    162163
    163164    // ActiveDOMObject API.
  • trunk/Source/WebCore/platform/audio/PlatformMediaSession.cpp

    r248846 r248962  
    394394}
    395395
     396bool PlatformMediaSession::shouldOverridePauseDuringRouteChange() const
     397{
     398    return m_client.shouldOverridePauseDuringRouteChange();
     399}
     400
    396401#if !RELEASE_LOG_DISABLED
    397402WTFLogChannel& PlatformMediaSession::logChannel() const
  • trunk/Source/WebCore/platform/audio/PlatformMediaSession.h

    r247118 r248962  
    193193
    194194    bool canPlayConcurrently(const PlatformMediaSession&) const;
     195    bool shouldOverridePauseDuringRouteChange() const;
    195196
    196197protected:
     
    262263    virtual void processIsSuspendedChanged() { }
    263264
     265    virtual bool shouldOverridePauseDuringRouteChange() const { return false; }
     266
    264267protected:
    265268    virtual ~PlatformMediaSessionClient() = default;
  • trunk/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.h

    r245947 r248962  
    5151    void carPlayServerDied();
    5252    void updateCarPlayIsConnected(Optional<bool>&&);
     53    void activeRouteDidChange(Optional<bool>&&);
    5354#endif
    5455
  • trunk/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm

    r245947 r248962  
    6161SOFT_LINK_CONSTANT_MAY_FAIL(Celestial, AVSystemController_CarPlayIsConnectedNotificationParameter, NSString *)
    6262SOFT_LINK_CONSTANT_MAY_FAIL(Celestial, AVSystemController_ServerConnectionDiedNotification, NSString *)
     63SOFT_LINK_CONSTANT_MAY_FAIL(Celestial, AVSystemController_ActiveAudioRouteDidChangeNotification, NSString *)
     64SOFT_LINK_CONSTANT_MAY_FAIL(Celestial, AVSystemController_ActiveAudioRouteDidChangeNotificationParameter_ShouldPause, NSString *)
    6365#endif
    6466
     
    223225
    224226    setIsPlayingToAutomotiveHeadUnit([[[getAVSystemControllerClass() sharedAVSystemController] attributeForKey:getAVSystemController_CarPlayIsConnectedAttribute()] boolValue]);
     227}
     228
     229void MediaSessionManageriOS::activeRouteDidChange(Optional<bool>&& shouldPause)
     230{
     231    if (!shouldPause || !shouldPause.value())
     232        return;
     233
     234    forEachSession([](auto& session) {
     235        if (!session.shouldOverridePauseDuringRouteChange())
     236            session.pauseSession();
     237    });
    225238}
    226239#endif
     
    255268    if (canLoadAVSystemController_CarPlayIsConnectedDidChangeNotification())
    256269        [center addObserver:self selector:@selector(carPlayIsConnectedDidChange:) name:getAVSystemController_CarPlayIsConnectedDidChangeNotification() object:nil];
     270    if (canLoadAVSystemController_ActiveAudioRouteDidChangeNotification())
     271        [center addObserver:self selector:@selector(activeAudioRouteDidChange:) name:getAVSystemController_ActiveAudioRouteDidChangeNotification() object:nil];
    257272#endif
    258273
     
    485500    });
    486501}
     502
     503- (void)activeAudioRouteDidChange:(NSNotification *)notification
     504{
     505    if (!_callback)
     506        return;
     507
     508    UNUSED_PARAM(notification);
     509    Optional<bool> shouldPause;
     510    if (notification && canLoadAVSystemController_ActiveAudioRouteDidChangeNotificationParameter_ShouldPause()) {
     511        NSNumber* nsShouldPause = [notification.userInfo valueForKey:getAVSystemController_ActiveAudioRouteDidChangeNotificationParameter_ShouldPause()];
     512        if (nsShouldPause)
     513            shouldPause = nsShouldPause.boolValue;
     514    }
     515
     516    callOnWebThreadOrDispatchAsyncOnMainThread([protectedSelf = retainPtr(self), shouldPause = WTFMove(shouldPause)]() mutable {
     517        if (auto* callback = protectedSelf->_callback)
     518            callback->activeRouteDidChange(WTFMove(shouldPause));
     519    });
     520
     521}
    487522#endif // HAVE(CELESTIAL)
    488523@end
Note: See TracChangeset for help on using the changeset viewer.