Changeset 231913 in webkit
- Timestamp:
- May 17, 2018 11:44:33 AM (6 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r231911 r231913 1 2018-05-17 Eric Carlson <eric.carlson@apple.com> 2 3 [iOS] Update AirPlay route monitoring 4 https://bugs.webkit.org/show_bug.cgi?id=185706 5 <rdar://problem/40230677> 6 7 Reviewed by Jer Noble. 8 9 Use an AVRouteDetector instead of an MPVolumeView and an MPAVRoutingController for AirPlay 10 route detection and availability monitoring. 11 12 No new tests, tested manually. 13 14 * html/MediaElementSession.cpp: 15 (WebCore::MediaElementSession::hasWirelessPlaybackTargets): No need to update m_hasPlaybackTargets 16 manually, it is always updated by the session manager when route availability changes. 17 18 * platform/audio/ios/MediaSessionManagerIOS.mm: 19 (-[WebMediaSessionHelper dealloc]): Pull the logic from safelyTearDown inline. 20 (-[WebMediaSessionHelper hasWirelessTargetsAvailable]): Use the AVRouteDetector. 21 (-[WebMediaSessionHelper startMonitoringAirPlayRoutes]): Ditto. Simplify logic, there is no 22 need to dispatch twice. 23 (-[WebMediaSessionHelper stopMonitoringAirPlayRoutes]): Don't release the route detector 24 completely, just disable route detection, because AVRouteDetector is a lightweight object so 25 it is not worth the overhead of dealloc/realloc to disable/enable route detection. 26 (-[WebMediaSessionHelper interruption:]): Use callOnWebThreadOrDispatchAsyncOnMainThread 27 instead of WebThreadRun so it works correctly in WK2 as well as in WK1. 28 (-[WebMediaSessionHelper applicationWillEnterForeground:]): Ditto. 29 (-[WebMediaSessionHelper applicationDidBecomeActive:]): Ditto. 30 (-[WebMediaSessionHelper applicationWillResignActive:]): Ditto. 31 (-[WebMediaSessionHelper wirelessRoutesAvailableDidChange:]): Ditto. 32 (-[WebMediaSessionHelper applicationDidEnterBackground:]): Ditto. 33 (safelyTearDown): Deleted. 34 1 35 2018-05-17 Chris Dumez <cdumez@apple.com> 2 36 -
trunk/Source/WebCore/html/MediaElementSession.cpp
r231817 r231913 550 550 bool MediaElementSession::hasWirelessPlaybackTargets() const 551 551 { 552 #if PLATFORM(IOS)553 // FIXME: consolidate Mac and iOS implementations554 m_hasPlaybackTargets = PlatformMediaSessionManager::sharedManager().hasWirelessTargetsAvailable();555 #endif556 557 552 INFO_LOG(LOGIDENTIFIER, "returning ", m_hasPlaybackTargets); 558 553 -
trunk/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm
r231866 r231913 35 35 #import "WebCoreThreadRun.h" 36 36 #import <AVFoundation/AVAudioSession.h> 37 #import <AVFoundation/AVRouteDetector.h> 37 38 #import <UIKit/UIApplication.h> 38 39 #import <objc/runtime.h> … … 46 47 #import <MediaPlayer/MPMediaItem.h> 47 48 #import <MediaPlayer/MPNowPlayingInfoCenter.h> 48 #import <MediaPlayer/MPVolumeView.h>49 49 #import <pal/spi/ios/MediaPlayerSPI.h> 50 50 #endif … … 52 52 SOFT_LINK_FRAMEWORK(AVFoundation) 53 53 SOFT_LINK_CLASS(AVFoundation, AVAudioSession) 54 SOFT_LINK_CLASS(AVFoundation, AVRouteDetector) 54 55 SOFT_LINK_POINTER(AVFoundation, AVAudioSessionInterruptionNotification, NSString *) 55 56 SOFT_LINK_POINTER(AVFoundation, AVAudioSessionInterruptionTypeKey, NSString *) 56 57 SOFT_LINK_POINTER(AVFoundation, AVAudioSessionInterruptionOptionKey, NSString *) 58 SOFT_LINK_POINTER(AVFoundation, AVRouteDetectorMultipleRoutesDetectedDidChangeNotification, NSString *) 57 59 58 60 #define AVAudioSession getAVAudioSessionClass() … … 76 78 #if HAVE(MEDIA_PLAYER) 77 79 SOFT_LINK_FRAMEWORK(MediaPlayer) 78 SOFT_LINK_CLASS(MediaPlayer, MPAVRoutingController)79 80 SOFT_LINK_CLASS(MediaPlayer, MPNowPlayingInfoCenter) 80 SOFT_LINK_CLASS(MediaPlayer, MPVolumeView)81 81 SOFT_LINK_POINTER(MediaPlayer, MPMediaItemPropertyTitle, NSString *) 82 82 SOFT_LINK_POINTER(MediaPlayer, MPMediaItemPropertyPlaybackDuration, NSString *) 83 83 SOFT_LINK_POINTER(MediaPlayer, MPNowPlayingInfoPropertyElapsedPlaybackTime, NSString *) 84 84 SOFT_LINK_POINTER(MediaPlayer, MPNowPlayingInfoPropertyPlaybackRate, NSString *) 85 SOFT_LINK_POINTER(MediaPlayer, MPVolumeViewWirelessRoutesAvailableDidChangeNotification, NSString *)86 85 SOFT_LINK_POINTER(MediaPlayer, kMRMediaRemoteNowPlayingInfoUniqueIdentifier, NSString *) 87 86 … … 90 89 #define MPNowPlayingInfoPropertyElapsedPlaybackTime getMPNowPlayingInfoPropertyElapsedPlaybackTime() 91 90 #define MPNowPlayingInfoPropertyPlaybackRate getMPNowPlayingInfoPropertyPlaybackRate() 92 #define MPVolumeViewWirelessRoutesAvailableDidChangeNotification getMPVolumeViewWirelessRoutesAvailableDidChangeNotification()93 91 #define kMRMediaRemoteNowPlayingInfoUniqueIdentifier getkMRMediaRemoteNowPlayingInfoUniqueIdentifier() 94 92 #endif // HAVE(MEDIA_PLAYER) … … 104 102 MediaSessionManageriOS* _callback; 105 103 106 #if HAVE(MEDIA_PLAYER) 107 RetainPtr<MPVolumeView> _volumeView; 108 RetainPtr<MPAVRoutingController> _airPlayPresenceRoutingController; 104 RetainPtr<AVRouteDetector> _routeDetector; 109 105 bool _monitoringAirPlayRoutes; 110 106 bool _startMonitoringAirPlayRoutesPending; 111 #endif112 107 } 113 108 … … 347 342 } 348 343 349 #if HAVE(MEDIA_PLAYER)350 static void safelyTearDown(RetainPtr<MPVolumeView> volumeView, RetainPtr<MPAVRoutingController> routingController)351 {352 dispatch_async(dispatch_get_main_queue(), [volumeView = WTFMove(volumeView), routingController = WTFMove(routingController)] () mutable {353 LOG(Media, "safelyTearDown - dipatched to UI thread.");354 BEGIN_BLOCK_OBJC_EXCEPTIONS355 [routingController setDiscoveryMode:MPRouteDiscoveryModeDisabled];356 volumeView.clear();357 routingController.clear();358 END_BLOCK_OBJC_EXCEPTIONS359 });360 }361 #endif362 363 344 - (void)dealloc 364 345 { … … 366 347 367 348 #if HAVE(MEDIA_PLAYER) 368 if (!pthread_main_np()) 369 safelyTearDown(WTFMove(_volumeView), WTFMove(_airPlayPresenceRoutingController)); 370 else 371 [_airPlayPresenceRoutingController setDiscoveryMode:MPRouteDiscoveryModeDisabled]; 349 if (!pthread_main_np()) { 350 dispatch_async(dispatch_get_main_queue(), [routeDetector = WTFMove(_routeDetector)] () mutable { 351 LOG(Media, "safelyTearDown - dipatched to UI thread."); 352 BEGIN_BLOCK_OBJC_EXCEPTIONS 353 routeDetector.get().routeDetectionEnabled = NO; 354 routeDetector.clear(); 355 END_BLOCK_OBJC_EXCEPTIONS 356 }); 357 } else 358 _routeDetector.get().routeDetectionEnabled = NO; 372 359 #endif 373 360 … … 385 372 { 386 373 LOG(Media, "-[WebMediaSessionHelper hasWirelessTargetsAvailable]"); 387 #if HAVE(MEDIA_PLAYER) 388 return _volumeView ? [_volumeView areWirelessRoutesAvailable] : NO; 389 #else 390 return NO; 391 #endif 374 return _routeDetector.get().multipleRoutesDetected; 392 375 } 393 376 … … 403 386 return; 404 387 388 if (_routeDetector) { 389 _routeDetector.get().routeDetectionEnabled = YES; 390 return; 391 } 392 405 393 _startMonitoringAirPlayRoutesPending = true; 406 394 407 395 LOG(Media, "-[WebMediaSessionHelper startMonitoringAirPlayRoutes]"); 408 396 409 dispatch_async(dispatch_get_main_queue(), [protectedSelf = RetainPtr<WebMediaSessionHelper>(self)] () mutable { 410 LOG(Media, "-[WebMediaSessionHelper startMonitoringAirPlayRoutes] - dipatched to main queue"); 411 412 BEGIN_BLOCK_OBJC_EXCEPTIONS 413 RetainPtr<MPVolumeView> volumeView = adoptNS([allocMPVolumeViewInstance() init]); 414 RetainPtr<MPAVRoutingController> routingController = adoptNS([allocMPAVRoutingControllerInstance() initWithName:@"WebCore - HTML media element checking for AirPlay route presence"]); 415 416 [routingController setDiscoveryMode:MPRouteDiscoveryModePresence]; 417 418 callOnWebThreadOrDispatchAsyncOnMainThread([protectedSelf = WTFMove(protectedSelf), volumeView = WTFMove(volumeView), routingController = WTFMove(routingController)]() mutable { 419 420 protectedSelf->_startMonitoringAirPlayRoutesPending = false; 421 422 if (!protectedSelf->_monitoringAirPlayRoutes) { 423 safelyTearDown(WTFMove(volumeView), WTFMove(routingController)); 424 return; 425 } 426 427 ASSERT(!protectedSelf->_volumeView); 428 protectedSelf->_volumeView = volumeView; 429 430 [[NSNotificationCenter defaultCenter] addObserver:protectedSelf.get() selector:@selector(wirelessRoutesAvailableDidChange:) name:MPVolumeViewWirelessRoutesAvailableDidChangeNotification object:volumeView.get()]; 431 432 ASSERT(!protectedSelf->_airPlayPresenceRoutingController); 433 protectedSelf->_airPlayPresenceRoutingController = routingController; 434 }); 435 END_BLOCK_OBJC_EXCEPTIONS 436 397 callOnWebThreadOrDispatchAsyncOnMainThread([protectedSelf = WTFMove(self)]() mutable { 398 ASSERT(!protectedSelf->_routeDetector); 399 400 if (protectedSelf->_callback) { 401 BEGIN_BLOCK_OBJC_EXCEPTIONS 402 protectedSelf->_routeDetector = adoptNS([allocAVRouteDetectorInstance() init]); 403 protectedSelf->_routeDetector.get().routeDetectionEnabled = protectedSelf->_monitoringAirPlayRoutes; 404 [[NSNotificationCenter defaultCenter] addObserver:protectedSelf selector:@selector(wirelessRoutesAvailableDidChange:) name:getAVRouteDetectorMultipleRoutesDetectedDidChangeNotification() object:protectedSelf->_routeDetector.get()]; 405 END_BLOCK_OBJC_EXCEPTIONS 406 } 407 408 protectedSelf->_startMonitoringAirPlayRoutesPending = false; 437 409 }); 438 410 } … … 443 415 return; 444 416 417 LOG(Media, "-[WebMediaSessionHelper stopMonitoringAirPlayRoutes]"); 418 445 419 _monitoringAirPlayRoutes = false; 446 447 LOG(Media, "-[WebMediaSessionHelper stopMonitoringAirPlayRoutes]"); 448 449 RetainPtr<MPVolumeView> volumeView = _volumeView; 450 RetainPtr<MPAVRoutingController> airPlayPresenceRoutingController = _airPlayPresenceRoutingController; 451 452 _volumeView.clear(); 453 _airPlayPresenceRoutingController.clear(); 454 455 if (volumeView) 456 [[NSNotificationCenter defaultCenter] removeObserver:self name:MPVolumeViewWirelessRoutesAvailableDidChangeNotification object:volumeView.get()]; 457 458 safelyTearDown(WTFMove(volumeView), WTFMove(airPlayPresenceRoutingController)); 420 _routeDetector.get().routeDetectionEnabled = NO; 459 421 } 460 422 #endif // HAVE(MEDIA_PLAYER) … … 473 435 flags = PlatformMediaSession::MayResumePlaying; 474 436 475 WebThreadRun(^{ 476 if (!_callback) 437 callOnWebThreadOrDispatchAsyncOnMainThread([protectedSelf = WTFMove(self), type, flags]() mutable { 438 auto* callback = protectedSelf->_callback; 439 if (!callback) 477 440 return; 478 441 479 442 if (type == AVAudioSessionInterruptionTypeBegan) 480 _callback->beginInterruption(PlatformMediaSession::SystemInterruption);443 callback->beginInterruption(PlatformMediaSession::SystemInterruption); 481 444 else 482 _callback->endInterruption(flags);445 callback->endInterruption(flags); 483 446 484 447 }); … … 495 458 496 459 BOOL isSuspendedUnderLock = [[[notification userInfo] objectForKey:@"isSuspendedUnderLock"] boolValue]; 497 498 WebThreadRun(^{ 499 if (!_callback) 500 return; 501 502 _callback->applicationWillEnterForeground(isSuspendedUnderLock); 460 callOnWebThreadOrDispatchAsyncOnMainThread([protectedSelf = WTFMove(self), isSuspendedUnderLock]() mutable { 461 if (auto* callback = protectedSelf->_callback) 462 callback->applicationWillEnterForeground(isSuspendedUnderLock); 503 463 }); 504 464 } … … 513 473 LOG(Media, "-[WebMediaSessionHelper applicationDidBecomeActive]"); 514 474 515 WebThreadRun(^{ 516 if (!_callback) 517 return; 518 519 _callback->applicationDidBecomeActive(); 475 callOnWebThreadOrDispatchAsyncOnMainThread([protectedSelf = WTFMove(self)]() mutable { 476 if (auto* callback = protectedSelf->_callback) 477 callback->applicationDidBecomeActive(); 520 478 }); 521 479 } … … 530 488 LOG(Media, "-[WebMediaSessionHelper applicationWillResignActive]"); 531 489 532 WebThreadRun(^{ 533 if (!_callback) 534 return; 535 536 _callback->applicationWillBecomeInactive(); 490 callOnWebThreadOrDispatchAsyncOnMainThread([protectedSelf = WTFMove(self)]() mutable { 491 if (auto* callback = protectedSelf->_callback) 492 callback->applicationWillBecomeInactive(); 537 493 }); 538 494 } … … 542 498 UNUSED_PARAM(notification); 543 499 544 if (!_callback )500 if (!_callback || !_monitoringAirPlayRoutes) 545 501 return; 546 502 547 503 LOG(Media, "-[WebMediaSessionHelper wirelessRoutesAvailableDidChange]"); 548 504 549 WebThreadRun(^{ 550 if (!_callback) 551 return; 552 553 _callback->externalOutputDeviceAvailableDidChange(); 505 callOnWebThreadOrDispatchAsyncOnMainThread([protectedSelf = WTFMove(self)]() mutable { 506 if (auto* callback = protectedSelf->_callback) 507 callback->externalOutputDeviceAvailableDidChange(); 554 508 }); 555 509 } … … 563 517 564 518 BOOL isSuspendedUnderLock = [[[notification userInfo] objectForKey:@"isSuspendedUnderLock"] boolValue]; 565 566 WebThreadRun(^{ 567 if (!_callback) 568 return; 569 570 _callback->applicationDidEnterBackground(isSuspendedUnderLock); 519 callOnWebThreadOrDispatchAsyncOnMainThread([protectedSelf = WTFMove(self), isSuspendedUnderLock]() mutable { 520 if (auto* callback = protectedSelf->_callback) 521 callback->applicationDidEnterBackground(isSuspendedUnderLock); 571 522 }); 572 523 }
Note: See TracChangeset
for help on using the changeset viewer.