WebKit Bugzilla
Attachment 340591 Details for
Bug 185706
: [iOS] Update AirPlay route monitoring
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-185706-20180517092345.patch (text/plain), 15.60 KB, created by
Eric Carlson
on 2018-05-17 09:23:46 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Eric Carlson
Created:
2018-05-17 09:23:46 PDT
Size:
15.60 KB
patch
obsolete
>Subversion Revision: 231843 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 2af26a5e76a0228b39de4d08a3cded519e14d811..3ce03713d86a8d040177a2466c6b0b9ed6a97041 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,37 @@ >+2018-05-16 Eric Carlson <eric.carlson@apple.com> >+ >+ [iOS] Update AirPlay route monitoring >+ https://bugs.webkit.org/show_bug.cgi?id=185706 >+ <rdar://problem/40230677> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Use an AVRouteDetector instead of an MPVolumeView and an MPAVRoutingController for AirPlay >+ route detection and availability monitoring. >+ >+ No new tests, tested manually. >+ >+ * html/MediaElementSession.cpp: >+ (WebCore::MediaElementSession::hasWirelessPlaybackTargets): No need to update m_hasPlaybackTargets >+ manually, it is always updated by the session manager when route availability changes. >+ >+ * platform/audio/ios/MediaSessionManagerIOS.mm: >+ (-[WebMediaSessionHelper dealloc]): Pull the logic from safelyTearDown inline. >+ (-[WebMediaSessionHelper hasWirelessTargetsAvailable]): Use the AVRouteDetector. >+ (-[WebMediaSessionHelper startMonitoringAirPlayRoutes]): Ditto. Simplify logic, there is no >+ need to dispatch twice. >+ (-[WebMediaSessionHelper stopMonitoringAirPlayRoutes]): Don't release the route detector >+ completely, just disable route detection, because AVRouteDetector is a lightweight object so >+ it is not worth the overhead of dealloc/realloc to disable/enable route detection. >+ (-[WebMediaSessionHelper interruption:]): Use callOnWebThreadOrDispatchAsyncOnMainThread >+ instead of WebThreadRun so it works correctly in WK2 as well as in WK1. >+ (-[WebMediaSessionHelper applicationWillEnterForeground:]): Ditto. >+ (-[WebMediaSessionHelper applicationDidBecomeActive:]): Ditto. >+ (-[WebMediaSessionHelper applicationWillResignActive:]): Ditto. >+ (-[WebMediaSessionHelper wirelessRoutesAvailableDidChange:]): Ditto. >+ (-[WebMediaSessionHelper applicationDidEnterBackground:]): Ditto. >+ (safelyTearDown): Deleted. >+ > 2018-05-16 Antoine Quint <graouts@apple.com> > > REGRESSION (r230574): Interrupted hardware transitions don't behave correctly >diff --git a/Source/WebCore/html/MediaElementSession.cpp b/Source/WebCore/html/MediaElementSession.cpp >index c2bd79a6d1613e46ed6f04664280cc950290ea99..03b106045c6dc055c5a30aa9bd5934f369838396 100644 >--- a/Source/WebCore/html/MediaElementSession.cpp >+++ b/Source/WebCore/html/MediaElementSession.cpp >@@ -549,11 +549,6 @@ void MediaElementSession::showPlaybackTargetPicker() > > bool MediaElementSession::hasWirelessPlaybackTargets() const > { >-#if PLATFORM(IOS) >- // FIXME: consolidate Mac and iOS implementations >- m_hasPlaybackTargets = PlatformMediaSessionManager::sharedManager().hasWirelessTargetsAvailable(); >-#endif >- > INFO_LOG(LOGIDENTIFIER, "returning ", m_hasPlaybackTargets); > > return m_hasPlaybackTargets; >diff --git a/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm b/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm >index 8b0bb34eb62bdf95e8af648b1d2a75ff1dcbc7ca..a50b237c3887559bd0a8c689a6bc09718855038f 100644 >--- a/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm >+++ b/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm >@@ -34,6 +34,7 @@ > #import "SystemMemory.h" > #import "WebCoreThreadRun.h" > #import <AVFoundation/AVAudioSession.h> >+#import <AVFoundation/AVRouteDetector.h> > #import <UIKit/UIApplication.h> > #import <objc/runtime.h> > #import <wtf/BlockObjCExceptions.h> >@@ -45,15 +46,16 @@ > #if HAVE(MEDIA_PLAYER) > #import <MediaPlayer/MPMediaItem.h> > #import <MediaPlayer/MPNowPlayingInfoCenter.h> >-#import <MediaPlayer/MPVolumeView.h> > #import <pal/spi/ios/MediaPlayerSPI.h> > #endif > > SOFT_LINK_FRAMEWORK(AVFoundation) > SOFT_LINK_CLASS(AVFoundation, AVAudioSession) >+SOFT_LINK_CLASS(AVFoundation, AVRouteDetector) > SOFT_LINK_POINTER(AVFoundation, AVAudioSessionInterruptionNotification, NSString *) > SOFT_LINK_POINTER(AVFoundation, AVAudioSessionInterruptionTypeKey, NSString *) > SOFT_LINK_POINTER(AVFoundation, AVAudioSessionInterruptionOptionKey, NSString *) >+SOFT_LINK_POINTER(AVFoundation, AVRouteDetectorMultipleRoutesDetectedDidChangeNotification, NSString *) > > #define AVAudioSession getAVAudioSessionClass() > #define AVAudioSessionInterruptionNotification getAVAudioSessionInterruptionNotification() >@@ -75,21 +77,17 @@ SOFT_LINK_POINTER(UIKit, UIApplicationDidEnterBackgroundNotification, NSString * > > #if HAVE(MEDIA_PLAYER) > SOFT_LINK_FRAMEWORK(MediaPlayer) >-SOFT_LINK_CLASS(MediaPlayer, MPAVRoutingController) > SOFT_LINK_CLASS(MediaPlayer, MPNowPlayingInfoCenter) >-SOFT_LINK_CLASS(MediaPlayer, MPVolumeView) > SOFT_LINK_POINTER(MediaPlayer, MPMediaItemPropertyTitle, NSString *) > SOFT_LINK_POINTER(MediaPlayer, MPMediaItemPropertyPlaybackDuration, NSString *) > SOFT_LINK_POINTER(MediaPlayer, MPNowPlayingInfoPropertyElapsedPlaybackTime, NSString *) > SOFT_LINK_POINTER(MediaPlayer, MPNowPlayingInfoPropertyPlaybackRate, NSString *) >-SOFT_LINK_POINTER(MediaPlayer, MPVolumeViewWirelessRoutesAvailableDidChangeNotification, NSString *) > SOFT_LINK_POINTER(MediaPlayer, kMRMediaRemoteNowPlayingInfoUniqueIdentifier, NSString *) > > #define MPMediaItemPropertyTitle getMPMediaItemPropertyTitle() > #define MPMediaItemPropertyPlaybackDuration getMPMediaItemPropertyPlaybackDuration() > #define MPNowPlayingInfoPropertyElapsedPlaybackTime getMPNowPlayingInfoPropertyElapsedPlaybackTime() > #define MPNowPlayingInfoPropertyPlaybackRate getMPNowPlayingInfoPropertyPlaybackRate() >-#define MPVolumeViewWirelessRoutesAvailableDidChangeNotification getMPVolumeViewWirelessRoutesAvailableDidChangeNotification() > #define kMRMediaRemoteNowPlayingInfoUniqueIdentifier getkMRMediaRemoteNowPlayingInfoUniqueIdentifier() > #endif // HAVE(MEDIA_PLAYER) > >@@ -103,12 +101,9 @@ using namespace WebCore; > @interface WebMediaSessionHelper : NSObject { > MediaSessionManageriOS* _callback; > >-#if HAVE(MEDIA_PLAYER) >- RetainPtr<MPVolumeView> _volumeView; >- RetainPtr<MPAVRoutingController> _airPlayPresenceRoutingController; >+ RetainPtr<AVRouteDetector> _routeDetector; > bool _monitoringAirPlayRoutes; > bool _startMonitoringAirPlayRoutesPending; >-#endif > } > > - (id)initWithCallback:(MediaSessionManageriOS*)callback; >@@ -345,29 +340,21 @@ void MediaSessionManageriOS::externalOutputDeviceAvailableDidChange() > return self; > } > >-#if HAVE(MEDIA_PLAYER) >-static void safelyTearDown(RetainPtr<MPVolumeView> volumeView, RetainPtr<MPAVRoutingController> routingController) >-{ >- dispatch_async(dispatch_get_main_queue(), [volumeView = WTFMove(volumeView), routingController = WTFMove(routingController)] () mutable { >- LOG(Media, "safelyTearDown - dipatched to UI thread."); >- BEGIN_BLOCK_OBJC_EXCEPTIONS >- [routingController setDiscoveryMode:MPRouteDiscoveryModeDisabled]; >- volumeView.clear(); >- routingController.clear(); >- END_BLOCK_OBJC_EXCEPTIONS >- }); >-} >-#endif >- > - (void)dealloc > { > LOG(Media, "-[WebMediaSessionHelper dealloc]"); > > #if HAVE(MEDIA_PLAYER) >- if (!pthread_main_np()) >- safelyTearDown(WTFMove(_volumeView), WTFMove(_airPlayPresenceRoutingController)); >- else >- [_airPlayPresenceRoutingController setDiscoveryMode:MPRouteDiscoveryModeDisabled]; >+ if (!pthread_main_np()) { >+ dispatch_async(dispatch_get_main_queue(), [routeDetector = WTFMove(_routeDetector)] () mutable { >+ LOG(Media, "safelyTearDown - dipatched to UI thread."); >+ BEGIN_BLOCK_OBJC_EXCEPTIONS >+ routeDetector.get().routeDetectionEnabled = NO; >+ routeDetector.clear(); >+ END_BLOCK_OBJC_EXCEPTIONS >+ }); >+ } else >+ _routeDetector.get().routeDetectionEnabled = NO; > #endif > > [[NSNotificationCenter defaultCenter] removeObserver:self]; >@@ -383,11 +370,7 @@ static void safelyTearDown(RetainPtr<MPVolumeView> volumeView, RetainPtr<MPAVRou > - (BOOL)hasWirelessTargetsAvailable > { > LOG(Media, "-[WebMediaSessionHelper hasWirelessTargetsAvailable]"); >-#if HAVE(MEDIA_PLAYER) >- return _volumeView ? [_volumeView areWirelessRoutesAvailable] : NO; >-#else >- return NO; >-#endif >+ return _routeDetector.get().multipleRoutesDetected; > } > > #if HAVE(MEDIA_PLAYER) >@@ -401,38 +384,27 @@ static void safelyTearDown(RetainPtr<MPVolumeView> volumeView, RetainPtr<MPAVRou > if (_startMonitoringAirPlayRoutesPending) > return; > >+ if (_routeDetector) { >+ _routeDetector.get().routeDetectionEnabled = YES; >+ return; >+ } >+ > _startMonitoringAirPlayRoutesPending = true; > > LOG(Media, "-[WebMediaSessionHelper startMonitoringAirPlayRoutes]"); > >- dispatch_async(dispatch_get_main_queue(), [protectedSelf = RetainPtr<WebMediaSessionHelper>(self)] () mutable { >- LOG(Media, "-[WebMediaSessionHelper startMonitoringAirPlayRoutes] - dipatched to main queue"); >+ callOnWebThreadOrDispatchAsyncOnMainThread([protectedSelf = WTFMove(self)]() mutable { >+ ASSERT(!protectedSelf->_routeDetector); > >- BEGIN_BLOCK_OBJC_EXCEPTIONS >- RetainPtr<MPVolumeView> volumeView = adoptNS([allocMPVolumeViewInstance() init]); >- RetainPtr<MPAVRoutingController> routingController = adoptNS([allocMPAVRoutingControllerInstance() initWithName:@"WebCore - HTML media element checking for AirPlay route presence"]); >- >- [routingController setDiscoveryMode:MPRouteDiscoveryModePresence]; >- >- callOnWebThreadOrDispatchAsyncOnMainThread([protectedSelf = WTFMove(protectedSelf), volumeView = WTFMove(volumeView), routingController = WTFMove(routingController)]() mutable { >+ if (protectedSelf->_callback) { >+ BEGIN_BLOCK_OBJC_EXCEPTIONS >+ protectedSelf->_routeDetector = adoptNS([allocAVRouteDetectorInstance() init]); >+ protectedSelf->_routeDetector.get().routeDetectionEnabled = protectedSelf->_monitoringAirPlayRoutes; >+ [[NSNotificationCenter defaultCenter] addObserver:protectedSelf selector:@selector(wirelessRoutesAvailableDidChange:) name:getAVRouteDetectorMultipleRoutesDetectedDidChangeNotification() object:protectedSelf->_routeDetector.get()]; > > protectedSelf->_startMonitoringAirPlayRoutesPending = false; >- >- if (!protectedSelf->_monitoringAirPlayRoutes) { >- safelyTearDown(WTFMove(volumeView), WTFMove(routingController)); >- return; >- } >- >- ASSERT(!protectedSelf->_volumeView); >- protectedSelf->_volumeView = volumeView; >- >- [[NSNotificationCenter defaultCenter] addObserver:protectedSelf.get() selector:@selector(wirelessRoutesAvailableDidChange:) name:MPVolumeViewWirelessRoutesAvailableDidChangeNotification object:volumeView.get()]; >- >- ASSERT(!protectedSelf->_airPlayPresenceRoutingController); >- protectedSelf->_airPlayPresenceRoutingController = routingController; >- }); >- END_BLOCK_OBJC_EXCEPTIONS >- >+ END_BLOCK_OBJC_EXCEPTIONS >+ } > }); > } > >@@ -441,20 +413,10 @@ static void safelyTearDown(RetainPtr<MPVolumeView> volumeView, RetainPtr<MPAVRou > if (!_monitoringAirPlayRoutes) > return; > >- _monitoringAirPlayRoutes = false; >- > LOG(Media, "-[WebMediaSessionHelper stopMonitoringAirPlayRoutes]"); > >- RetainPtr<MPVolumeView> volumeView = _volumeView; >- RetainPtr<MPAVRoutingController> airPlayPresenceRoutingController = _airPlayPresenceRoutingController; >- >- _volumeView.clear(); >- _airPlayPresenceRoutingController.clear(); >- >- if (volumeView) >- [[NSNotificationCenter defaultCenter] removeObserver:self name:MPVolumeViewWirelessRoutesAvailableDidChangeNotification object:volumeView.get()]; >- >- safelyTearDown(WTFMove(volumeView), WTFMove(airPlayPresenceRoutingController)); >+ _monitoringAirPlayRoutes = false; >+ _routeDetector.get().routeDetectionEnabled = NO; > } > #endif // HAVE(MEDIA_PLAYER) > >@@ -471,14 +433,14 @@ static void safelyTearDown(RetainPtr<MPVolumeView> volumeView, RetainPtr<MPAVRou > if (type == AVAudioSessionInterruptionTypeEnded && [[[notification userInfo] objectForKey:AVAudioSessionInterruptionOptionKey] unsignedIntegerValue] == AVAudioSessionInterruptionOptionShouldResume) > flags = PlatformMediaSession::MayResumePlaying; > >- WebThreadRun(^{ >- if (!_callback) >+ callOnWebThreadOrDispatchAsyncOnMainThread([protectedSelf = WTFMove(self), type, flags]() mutable { >+ if (!protectedSelf->_callback) > return; > > if (type == AVAudioSessionInterruptionTypeBegan) >- _callback->beginInterruption(PlatformMediaSession::SystemInterruption); >+ protectedSelf->_callback->beginInterruption(PlatformMediaSession::SystemInterruption); > else >- _callback->endInterruption(flags); >+ protectedSelf->_callback->endInterruption(flags); > > }); > } >@@ -494,11 +456,11 @@ static void safelyTearDown(RetainPtr<MPVolumeView> volumeView, RetainPtr<MPAVRou > > BOOL isSuspendedUnderLock = [[[notification userInfo] objectForKey:@"isSuspendedUnderLock"] boolValue]; > >- WebThreadRun(^{ >- if (!_callback) >+ callOnWebThreadOrDispatchAsyncOnMainThread([protectedSelf = WTFMove(self), isSuspendedUnderLock]() mutable { >+ if (!protectedSelf->_callback) > return; > >- _callback->applicationWillEnterForeground(isSuspendedUnderLock); >+ protectedSelf->_callback->applicationWillEnterForeground(isSuspendedUnderLock); > }); > } > >@@ -511,11 +473,11 @@ static void safelyTearDown(RetainPtr<MPVolumeView> volumeView, RetainPtr<MPAVRou > > LOG(Media, "-[WebMediaSessionHelper applicationDidBecomeActive]"); > >- WebThreadRun(^{ >- if (!_callback) >+ callOnWebThreadOrDispatchAsyncOnMainThread([protectedSelf = WTFMove(self)]() mutable { >+ if (!protectedSelf->_callback) > return; > >- _callback->applicationDidBecomeActive(); >+ protectedSelf->_callback->applicationDidBecomeActive(); > }); > } > >@@ -528,11 +490,11 @@ static void safelyTearDown(RetainPtr<MPVolumeView> volumeView, RetainPtr<MPAVRou > > LOG(Media, "-[WebMediaSessionHelper applicationWillResignActive]"); > >- WebThreadRun(^{ >- if (!_callback) >+ callOnWebThreadOrDispatchAsyncOnMainThread([protectedSelf = WTFMove(self)]() mutable { >+ if (!protectedSelf->_callback) > return; > >- _callback->applicationWillBecomeInactive(); >+ protectedSelf->_callback->applicationWillBecomeInactive(); > }); > } > >@@ -540,16 +502,16 @@ static void safelyTearDown(RetainPtr<MPVolumeView> volumeView, RetainPtr<MPAVRou > { > UNUSED_PARAM(notification); > >- if (!_callback) >+ if (!_callback || !_monitoringAirPlayRoutes) > return; > > LOG(Media, "-[WebMediaSessionHelper wirelessRoutesAvailableDidChange]"); > >- WebThreadRun(^{ >- if (!_callback) >+ callOnWebThreadOrDispatchAsyncOnMainThread([protectedSelf = WTFMove(self)]() mutable { >+ if (!protectedSelf->_callback) > return; > >- _callback->externalOutputDeviceAvailableDidChange(); >+ protectedSelf->_callback->externalOutputDeviceAvailableDidChange(); > }); > } > >@@ -562,11 +524,11 @@ static void safelyTearDown(RetainPtr<MPVolumeView> volumeView, RetainPtr<MPAVRou > > BOOL isSuspendedUnderLock = [[[notification userInfo] objectForKey:@"isSuspendedUnderLock"] boolValue]; > >- WebThreadRun(^{ >- if (!_callback) >+ callOnWebThreadOrDispatchAsyncOnMainThread([protectedSelf = WTFMove(self), isSuspendedUnderLock]() mutable { >+ if (!protectedSelf->_callback) > return; > >- _callback->applicationDidEnterBackground(isSuspendedUnderLock); >+ protectedSelf->_callback->applicationDidEnterBackground(isSuspendedUnderLock); > }); > } > @end
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
jer.noble
:
review+
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 185706
: 340591 |
340610
|
340638