Changeset 257039 in webkit
- Timestamp:
- Feb 19, 2020 7:51:21 PM (4 years ago)
- Location:
- trunk
- Files:
-
- 32 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r257036 r257039 1 2020-02-19 Youenn Fablet <youenn@apple.com> 2 3 Add support for AudioSession handling in GPUProcess for capture 4 https://bugs.webkit.org/show_bug.cgi?id=207950 5 6 Reviewed by Eric Carlson. 7 8 * platform/ios/TestExpectations: 9 1 10 2020-02-19 Sunny He <sunny_he@apple.com> 2 11 -
trunk/LayoutTests/platform/ios/TestExpectations
r256897 r257039 107 107 fast/mediastream [ Skip ] 108 108 fast/mediastream/getUserMedia-default.html [ Pass ] 109 fast/mediastream/captureInGPUProcess.html [ Pass ] 109 110 110 111 # ENABLE(MEDIA_CAPTURE) is not enabled -
trunk/Source/WebCore/ChangeLog
r257036 r257039 1 2020-02-19 Youenn Fablet <youenn@apple.com> 2 3 Add support for AudioSession handling in GPUProcess for capture 4 https://bugs.webkit.org/show_bug.cgi?id=207950 5 6 Reviewed by Eric Carlson. 7 8 Add a dedicated interface for handling audio capture in session manager. 9 This was previoulsy PlatformMediaSessionClient, but this one is more related to audio/video rendering. 10 Use this new interface for MediaStreamTrack capture sources. 11 The session manager now owns a WeakHashSet of capture sources to compute the correct AudioSession category. 12 13 Modernize the code, for instance use an enum class for MediaType to remove some debug asserts. 14 Add a new PlatformMediaSessionManager::create that is used for sharedManager. 15 16 Remove the direct use of PlatformMediaSessionManager::sharedManager from classes that can be used outside of WebProcess. 17 This includes BaseAudioSharedUnit, for which we add a audioUnitWillStart callback 18 so that we compute the right AudioSession category before starting the capture. 19 20 Covered by existing tests and debug assertions to check for AudioSession category computation. 21 22 * Modules/mediastream/MediaStreamTrack.cpp: 23 (WebCore::MediaStreamTrack::MediaStreamTrack): 24 (WebCore::MediaStreamTrack::~MediaStreamTrack): 25 (WebCore::MediaStreamTrack::configureTrackRendering): 26 (WebCore::MediaStreamTrack::isCapturingAudio const): 27 * Modules/mediastream/MediaStreamTrack.h: 28 * Modules/webaudio/AudioContext.h: 29 * html/HTMLAudioElement.h: 30 * html/HTMLMediaElement.cpp: 31 (WebCore::HTMLMediaElement::shouldDisableSleep const): 32 (WebCore::HTMLMediaElement::mediaType const): 33 (WebCore::HTMLMediaElement::presentationType const): 34 * html/HTMLVideoElement.h: 35 * html/MediaElementSession.cpp: 36 (WebCore::MediaElementSession::canShowControlsManager const): 37 * html/MediaElementSession.h: 38 * platform/audio/PlatformMediaSession.cpp: 39 (WebCore::PlatformMediaSession::PlatformMediaSession): 40 (WebCore::PlatformMediaSession::activeAudioSessionRequired const): 41 * platform/audio/PlatformMediaSession.h: 42 * platform/audio/PlatformMediaSessionManager.cpp: 43 (WebCore::sharedPlatformMediaSessionManager): 44 (WebCore::PlatformMediaSessionManager::sharedManager): 45 (WebCore::PlatformMediaSessionManager::sharedManagerIfExists): 46 (WebCore::PlatformMediaSessionManager::create): 47 (WebCore::indexFromMediaType): 48 (WebCore::PlatformMediaSessionManager::resetRestrictions): 49 (WebCore::PlatformMediaSessionManager::has const): 50 (WebCore::PlatformMediaSessionManager::count const): 51 (WebCore::PlatformMediaSessionManager::countActiveAudioCaptureSources): 52 (WebCore::PlatformMediaSessionManager::addRestriction): 53 (WebCore::PlatformMediaSessionManager::removeRestriction): 54 (WebCore::PlatformMediaSessionManager::restrictions): 55 (WebCore::PlatformMediaSessionManager::sessionWillBeginPlayback): 56 (WebCore::PlatformMediaSessionManager::applicationWillBecomeInactive): 57 (WebCore::PlatformMediaSessionManager::applicationDidBecomeActive): 58 (WebCore::PlatformMediaSessionManager::applicationDidEnterBackground): 59 (WebCore::PlatformMediaSessionManager::applicationWillEnterForeground): 60 (WebCore::PlatformMediaSessionManager::sessionIsPlayingToWirelessPlaybackTargetChanged): 61 (WebCore::PlatformMediaSessionManager::addAudioCaptureSource): 62 (WebCore::PlatformMediaSessionManager::removeAudioCaptureSource): 63 * platform/audio/PlatformMediaSessionManager.h: 64 * platform/audio/cocoa/MediaSessionManagerCocoa.mm: 65 (PlatformMediaSessionManager::create): 66 (MediaSessionManagerCocoa::updateSessionState): 67 * platform/audio/ios/MediaSessionManagerIOS.mm: 68 (WebCore::PlatformMediaSessionManager::create): 69 (WebCore::MediaSessionManageriOS::resetRestrictions): 70 * platform/mediastream/MediaStreamTrackPrivate.cpp: 71 (WebCore::MediaStreamTrackPrivate::audioUnitWillStart): 72 * platform/mediastream/MediaStreamTrackPrivate.h: 73 * platform/mediastream/RealtimeMediaSource.h: 74 * platform/mediastream/mac/BaseAudioSharedUnit.cpp: 75 (WebCore::BaseAudioSharedUnit::startUnit): 76 * platform/mediastream/mac/BaseAudioSharedUnit.h: 77 * platform/mediastream/mac/CoreAudioCaptureSource.cpp: 78 (WebCore::CoreAudioCaptureSource::audioUnitWillStart): 79 * platform/mediastream/mac/CoreAudioCaptureSource.h: 80 * testing/Internals.cpp: 81 (WebCore::mediaTypeFromString): 82 (WebCore::Internals::setMediaSessionRestrictions): 83 (WebCore::Internals::mediaSessionRestrictions const): 84 1 85 2020-02-19 Sunny He <sunny_he@apple.com> 2 86 -
trunk/Source/WebCore/Modules/mediastream/MediaStreamTrack.cpp
r256936 r257039 76 76 , m_private(WTFMove(privateTrack)) 77 77 , m_isCaptureTrack(m_private->isCaptureTrack()) 78 , m_mediaSession(PlatformMediaSession::create(PlatformMediaSessionManager::sharedManager(), *this))79 78 { 80 79 ALWAYS_LOG(LOGIDENTIFIER); … … 86 85 87 86 allCaptureTracks().add(this); 87 88 if (m_private->type() == RealtimeMediaSource::Type::Audio) 89 PlatformMediaSessionManager::sharedManager().addAudioCaptureSource(*this); 88 90 89 91 if (auto document = this->document()) { … … 101 103 102 104 allCaptureTracks().remove(this); 105 106 if (m_private->type() == RealtimeMediaSource::Type::Audio) 107 PlatformMediaSessionManager::sharedManager().removeAudioCaptureSource(*this); 103 108 } 104 109 … … 537 542 void MediaStreamTrack::configureTrackRendering() 538 543 { 539 if (m_mediaSession && m_private->type() == RealtimeMediaSource::Type::Audio)540 m_mediaSession->canProduceAudioChanged();541 542 544 if (auto document = this->document()) 543 545 document->updateIsPlayingMedia(); … … 581 583 } 582 584 583 PlatformMediaSession::MediaType MediaStreamTrack::mediaType() const 584 { 585 return (isCaptureTrack() && canProduceAudio()) ? PlatformMediaSession::MediaStreamCapturingAudio : PlatformMediaSession::None; 586 } 587 588 PlatformMediaSession::MediaType MediaStreamTrack::presentationType() const 589 { 590 return mediaType(); 591 } 592 593 void MediaStreamTrack::mayResumePlayback(bool) 594 { 595 // FIXME: should a media stream track pay attention to this directly, or only when attached to a media element? 596 } 597 598 void MediaStreamTrack::suspendPlayback() 599 { 600 // FIXME: should a media stream track pay attention to this directly, or only when attached to a media element? 601 } 602 603 String MediaStreamTrack::sourceApplicationIdentifier() const 604 { 605 auto* document = this->document(); 606 if (document && document->frame()) { 607 if (auto* networkingContext = document->frame()->loader().networkingContext()) 608 return networkingContext->sourceApplicationIdentifier(); 609 } 610 611 return emptyString(); 612 } 613 614 bool MediaStreamTrack::canProduceAudio() const 615 { 616 return m_private->type() == RealtimeMediaSource::Type::Audio && !ended() && !muted(); 617 } 618 619 DocumentIdentifier MediaStreamTrack::hostingDocumentIdentifier() const 620 { 621 auto* document = downcast<Document>(m_scriptExecutionContext); 622 return document ? document->identifier() : DocumentIdentifier { }; 585 bool MediaStreamTrack::isCapturingAudio() const 586 { 587 ASSERT(isCaptureTrack() && m_private->type() == RealtimeMediaSource::Type::Audio); 588 return !ended() && !muted(); 623 589 } 624 590 -
trunk/Source/WebCore/Modules/mediastream/MediaStreamTrack.h
r256936 r257039 54 54 , public EventTargetWithInlineData 55 55 , private MediaStreamTrackPrivate::Observer 56 , private PlatformMediaSession Client56 , private PlatformMediaSession::AudioCaptureSource 57 57 #if !RELEASE_LOG_DISABLED 58 58 , private LoggerHelper … … 191 191 void trackEnabledChanged(MediaStreamTrackPrivate&) final; 192 192 193 // PlatformMediaSessionClient 194 PlatformMediaSession::MediaType mediaType() const final; 195 PlatformMediaSession::MediaType presentationType() const final; 196 void mayResumePlayback(bool shouldResume) final; 197 void suspendPlayback() final; 198 bool canReceiveRemoteControlCommands() const final { return false; } 199 void didReceiveRemoteControlCommand(PlatformMediaSession::RemoteControlCommandType, const PlatformMediaSession::RemoteCommandArgument*) final { } 200 bool supportsSeeking() const final { return false; } 201 bool shouldOverrideBackgroundPlaybackRestriction(PlatformMediaSession::InterruptionType) const final { return false; } 202 String sourceApplicationIdentifier() const final; 203 bool canProduceAudio() const final; 204 DocumentIdentifier hostingDocumentIdentifier() const final; 205 bool shouldOverridePauseDuringRouteChange() const final { return true; } 193 // PlatformMediaSession::AudioCaptureSource 194 bool isCapturingAudio() const final; 206 195 207 196 #if !RELEASE_LOG_DISABLED … … 217 206 bool m_ended { false }; 218 207 const bool m_isCaptureTrack { false }; 219 std::unique_ptr<PlatformMediaSession> m_mediaSession;220 208 }; 221 209 -
trunk/Source/WebCore/Modules/webaudio/AudioContext.h
r256936 r257039 348 348 349 349 // PlatformMediaSessionClient 350 PlatformMediaSession::MediaType mediaType() const override { return PlatformMediaSession:: WebAudio; }351 PlatformMediaSession::MediaType presentationType() const override { return PlatformMediaSession:: WebAudio; }350 PlatformMediaSession::MediaType mediaType() const override { return PlatformMediaSession::MediaType::WebAudio; } 351 PlatformMediaSession::MediaType presentationType() const override { return PlatformMediaSession::MediaType::WebAudio; } 352 352 void mayResumePlayback(bool shouldResume) override; 353 353 void suspendPlayback() override; -
trunk/Source/WebCore/html/HTMLAudioElement.h
r246490 r257039 44 44 HTMLAudioElement(const QualifiedName&, Document&, bool); 45 45 46 PlatformMediaSession::MediaType presentationType() const final { return PlatformMediaSession:: Audio; }46 PlatformMediaSession::MediaType presentationType() const final { return PlatformMediaSession::MediaType::Audio; } 47 47 }; 48 48 -
trunk/Source/WebCore/html/HTMLMediaElement.cpp
r256936 r257039 6917 6917 return SleepType::None; 6918 6918 6919 bool shouldBeAbleToSleep = mediaType() != PlatformMediaSession:: VideoAudio;6919 bool shouldBeAbleToSleep = mediaType() != PlatformMediaSession::MediaType::VideoAudio; 6920 6920 #if ENABLE(MEDIA_STREAM) 6921 6921 // Remote media stream video tracks may have their corresponding audio tracks being played outside of the media element. Let's ensure to not IDLE the screen in that case. … … 7518 7518 if (m_player && m_readyState >= HAVE_METADATA) { 7519 7519 if (hasVideo() && hasAudio() && !muted()) 7520 return PlatformMediaSession:: VideoAudio;7521 return hasVideo() ? PlatformMediaSession:: Video : PlatformMediaSession::Audio;7520 return PlatformMediaSession::MediaType::VideoAudio; 7521 return hasVideo() ? PlatformMediaSession::MediaType::Video : PlatformMediaSession::MediaType::Audio; 7522 7522 } 7523 7523 … … 7528 7528 { 7529 7529 if (hasTagName(HTMLNames::videoTag)) 7530 return muted() ? PlatformMediaSession:: Video : PlatformMediaSession::VideoAudio;7531 7532 return PlatformMediaSession:: Audio;7530 return muted() ? PlatformMediaSession::MediaType::Video : PlatformMediaSession::MediaType::VideoAudio; 7531 7532 return PlatformMediaSession::MediaType::Audio; 7533 7533 } 7534 7534 -
trunk/Source/WebCore/html/HTMLVideoElement.h
r254214 r257039 128 128 void setDisplayMode(DisplayMode) final; 129 129 130 PlatformMediaSession::MediaType presentationType() const final { return PlatformMediaSession:: Video; }130 PlatformMediaSession::MediaType presentationType() const final { return PlatformMediaSession::MediaType::Video; } 131 131 132 132 std::unique_ptr<HTMLImageLoader> m_imageLoader; -
trunk/Source/WebCore/html/MediaElementSession.cpp
r256904 r257039 437 437 } 438 438 439 if (client().presentationType() == Audio && purpose == PlaybackControlsPurpose::ControlsManager) {439 if (client().presentationType() == MediaType::Audio && purpose == PlaybackControlsPurpose::ControlsManager) { 440 440 if (!hasBehaviorRestriction(RequireUserGestureToControlControlsManager) || m_element.document().processingUserGestureForMedia()) { 441 441 INFO_LOG(LOGIDENTIFIER, "returning TRUE: audio element with user gesture"); -
trunk/Source/WebCore/html/MediaElementSession.h
r251737 r257039 154 154 static bool isMediaElementSessionMediaType(MediaType type) 155 155 { 156 return type == Video157 || type == Audio158 || type == VideoAudio;156 return type == MediaType::Video 157 || type == MediaType::Audio 158 || type == MediaType::VideoAudio; 159 159 } 160 160 -
trunk/Source/WebCore/platform/audio/PlatformMediaSession.cpp
r256936 r257039 124 124 #endif 125 125 { 126 ASSERT(m_client.mediaType() >= None && m_client.mediaType() <= MediaStreamCapturingAudio);127 126 manager.addSession(*this); 128 127 } … … 352 351 bool PlatformMediaSession::activeAudioSessionRequired() const 353 352 { 354 if (mediaType() == PlatformMediaSession:: None)353 if (mediaType() == PlatformMediaSession::MediaType::None) 355 354 return false; 356 355 if (state() != PlatformMediaSession::State::Playing) -
trunk/Source/WebCore/platform/audio/PlatformMediaSession.h
r256936 r257039 60 60 virtual ~PlatformMediaSession(); 61 61 62 enum MediaType {62 enum class MediaType { 63 63 None = 0, 64 64 Video, … … 66 66 Audio, 67 67 WebAudio, 68 MediaStreamCapturingAudio,69 68 }; 70 69 MediaType mediaType() const; … … 191 190 bool shouldOverridePauseDuringRouteChange() const; 192 191 192 class AudioCaptureSource : public CanMakeWeakPtr<AudioCaptureSource> { 193 public: 194 virtual ~AudioCaptureSource() = default; 195 virtual bool isCapturingAudio() const = 0; 196 }; 197 193 198 protected: 194 199 PlatformMediaSession(PlatformMediaSessionManager&, PlatformMediaSessionClient&); -
trunk/Source/WebCore/platform/audio/PlatformMediaSessionManager.cpp
r256844 r257039 36 36 #if ENABLE(VIDEO) || ENABLE(WEB_AUDIO) 37 37 38 static std::unique_ptr<PlatformMediaSessionManager>& sharedPlatformMediaSessionManager() 39 { 40 static NeverDestroyed<std::unique_ptr<PlatformMediaSessionManager>> platformMediaSessionManager; 41 return platformMediaSessionManager.get(); 42 } 43 44 PlatformMediaSessionManager& PlatformMediaSessionManager::sharedManager() 45 { 46 auto& manager = sharedPlatformMediaSessionManager(); 47 if (!manager) 48 manager = PlatformMediaSessionManager::create(); 49 return *manager; 50 } 51 52 PlatformMediaSessionManager* PlatformMediaSessionManager::sharedManagerIfExists() 53 { 54 return sharedPlatformMediaSessionManager().get(); 55 } 56 38 57 #if !PLATFORM(COCOA) 39 static PlatformMediaSessionManager* platformMediaSessionManager = nullptr; 40 41 PlatformMediaSessionManager& PlatformMediaSessionManager::sharedManager() 42 { 43 if (!platformMediaSessionManager) 44 platformMediaSessionManager = new PlatformMediaSessionManager; 45 return *platformMediaSessionManager; 46 } 47 48 PlatformMediaSessionManager* PlatformMediaSessionManager::sharedManagerIfExists() 49 { 50 return platformMediaSessionManager; 58 std::unique_ptr<PlatformMediaSessionManager> PlatformMediaSessionManager::create() 59 { 60 return std::unique_ptr<PlatformMediaSessionManager>(new PlatformMediaSessionManager); 51 61 } 52 62 #endif // !PLATFORM(COCOA) … … 67 77 } 68 78 79 static inline unsigned indexFromMediaType(PlatformMediaSession::MediaType type) 80 { 81 return static_cast<unsigned>(type); 82 } 83 69 84 void PlatformMediaSessionManager::resetRestrictions() 70 85 { 71 m_restrictions[PlatformMediaSession::Video] = NoRestrictions; 72 m_restrictions[PlatformMediaSession::Audio] = NoRestrictions; 73 m_restrictions[PlatformMediaSession::VideoAudio] = NoRestrictions; 74 m_restrictions[PlatformMediaSession::WebAudio] = NoRestrictions; 75 m_restrictions[PlatformMediaSession::MediaStreamCapturingAudio] = NoRestrictions; 86 m_restrictions[indexFromMediaType(PlatformMediaSession::MediaType::Video)] = NoRestrictions; 87 m_restrictions[indexFromMediaType(PlatformMediaSession::MediaType::Audio)] = NoRestrictions; 88 m_restrictions[indexFromMediaType(PlatformMediaSession::MediaType::VideoAudio)] = NoRestrictions; 89 m_restrictions[indexFromMediaType(PlatformMediaSession::MediaType::WebAudio)] = NoRestrictions; 76 90 } 77 91 78 92 bool PlatformMediaSessionManager::has(PlatformMediaSession::MediaType type) const 79 93 { 80 ASSERT(type >= PlatformMediaSession::None && type <= PlatformMediaSession::MediaStreamCapturingAudio);81 82 94 return anyOfSessions([type] (auto& session) { 83 95 return session.mediaType() == type; … … 101 113 int PlatformMediaSessionManager::count(PlatformMediaSession::MediaType type) const 102 114 { 103 ASSERT(type >= PlatformMediaSession::None && type <= PlatformMediaSession::MediaStreamCapturingAudio);104 105 115 int count = 0; 106 116 for (const auto& session : m_sessions) { … … 109 119 } 110 120 121 return count; 122 } 123 124 int PlatformMediaSessionManager::countActiveAudioCaptureSources() 125 { 126 int count = 0; 127 for (const auto& source : m_audioCaptureSources) { 128 if (source.isCapturingAudio()) 129 ++count; 130 } 111 131 return count; 112 132 } … … 180 200 void PlatformMediaSessionManager::addRestriction(PlatformMediaSession::MediaType type, SessionRestrictions restriction) 181 201 { 182 ASSERT(type > PlatformMediaSession::None && type <= PlatformMediaSession::MediaStreamCapturingAudio); 183 m_restrictions[type] |= restriction; 202 m_restrictions[indexFromMediaType(type)] |= restriction; 184 203 } 185 204 186 205 void PlatformMediaSessionManager::removeRestriction(PlatformMediaSession::MediaType type, SessionRestrictions restriction) 187 206 { 188 ASSERT(type > PlatformMediaSession::None && type <= PlatformMediaSession::MediaStreamCapturingAudio); 189 m_restrictions[type] &= ~restriction; 207 m_restrictions[indexFromMediaType(type)] &= ~restriction; 190 208 } 191 209 192 210 PlatformMediaSessionManager::SessionRestrictions PlatformMediaSessionManager::restrictions(PlatformMediaSession::MediaType type) 193 211 { 194 ASSERT(type > PlatformMediaSession::None && type <= PlatformMediaSession::MediaStreamCapturingAudio); 195 return m_restrictions[type]; 212 return m_restrictions[indexFromMediaType(type)]; 196 213 } 197 214 … … 200 217 setCurrentSession(session); 201 218 202 PlatformMediaSession::MediaTypesessionType = session.mediaType();203 SessionRestrictions restrictions = m_restrictions[sessionType];219 auto sessionType = session.mediaType(); 220 auto restrictions = this->restrictions(sessionType); 204 221 if (session.state() == PlatformMediaSession::Interrupted && restrictions & InterruptedPlaybackNotPermitted) { 205 222 ALWAYS_LOG(LOGIDENTIFIER, session.logIdentifier(), " returning false because session.state() is Interrupted, and InterruptedPlaybackNotPermitted"); … … 305 322 306 323 forEachMatchingSession([&](auto& session) { 307 return m_restrictions[session.mediaType()]& InactiveProcessPlaybackRestricted;324 return restrictions(session.mediaType()) & InactiveProcessPlaybackRestricted; 308 325 }, [](auto& session) { 309 326 session.beginInterruption(PlatformMediaSession::ProcessInactive); … … 316 333 317 334 forEachMatchingSession([&](auto& session) { 318 return m_restrictions[session.mediaType()]& InactiveProcessPlaybackRestricted;335 return restrictions(session.mediaType()) & InactiveProcessPlaybackRestricted; 319 336 }, [](auto& session) { 320 337 session.endInterruption(PlatformMediaSession::MayResumePlaying); … … 332 349 333 350 forEachSession([&] (auto& session) { 334 if (suspendedUnderLock && m_restrictions[session.mediaType()]& SuspendedUnderLockPlaybackRestricted)351 if (suspendedUnderLock && restrictions(session.mediaType()) & SuspendedUnderLockPlaybackRestricted) 335 352 session.beginInterruption(PlatformMediaSession::SuspendedUnderLock); 336 else if ( m_restrictions[session.mediaType()]& BackgroundProcessPlaybackRestricted)353 else if (restrictions(session.mediaType()) & BackgroundProcessPlaybackRestricted) 337 354 session.beginInterruption(PlatformMediaSession::EnteringBackground); 338 355 }); … … 349 366 350 367 forEachMatchingSession([&](auto& session) { 351 return (suspendedUnderLock && m_restrictions[session.mediaType()] & SuspendedUnderLockPlaybackRestricted) || m_restrictions[session.mediaType()]& BackgroundProcessPlaybackRestricted;368 return (suspendedUnderLock && restrictions(session.mediaType()) & SuspendedUnderLockPlaybackRestricted) || restrictions(session.mediaType()) & BackgroundProcessPlaybackRestricted; 352 369 }, [](auto& session) { 353 370 session.endInterruption(PlatformMediaSession::MayResumePlaying); … … 401 418 void PlatformMediaSessionManager::sessionIsPlayingToWirelessPlaybackTargetChanged(PlatformMediaSession& session) 402 419 { 403 if (!m_isApplicationInBackground || !( m_restrictions[session.mediaType()]& BackgroundProcessPlaybackRestricted))420 if (!m_isApplicationInBackground || !(restrictions(session.mediaType()) & BackgroundProcessPlaybackRestricted)) 404 421 return; 405 422 … … 541 558 } 542 559 560 void PlatformMediaSessionManager::addAudioCaptureSource(PlatformMediaSession::AudioCaptureSource& source) 561 { 562 ASSERT(!m_audioCaptureSources.contains(source)); 563 m_audioCaptureSources.add(source); 564 updateSessionState(); 565 } 566 567 568 void PlatformMediaSessionManager::removeAudioCaptureSource(PlatformMediaSession::AudioCaptureSource& source) 569 { 570 ASSERT(m_audioCaptureSources.contains(source)); 571 m_audioCaptureSources.remove(source); 572 updateSessionState(); 573 } 574 543 575 #if USE(AUDIO_SESSION) 544 576 void PlatformMediaSessionManager::maybeDeactivateAudioSession() -
trunk/Source/WebCore/platform/audio/PlatformMediaSessionManager.h
r256904 r257039 35 35 #include <wtf/AggregateLogger.h> 36 36 #include <wtf/Vector.h> 37 #include <wtf/WeakHashSet.h> 37 38 #include <wtf/WeakPtr.h> 38 39 … … 55 56 WEBCORE_EXPORT static PlatformMediaSessionManager* sharedManagerIfExists(); 56 57 WEBCORE_EXPORT static PlatformMediaSessionManager& sharedManager(); 58 WEBCORE_EXPORT static std::unique_ptr<PlatformMediaSessionManager> create(); 57 59 58 60 static void updateNowPlayingInfoIfNecessary(); … … 139 141 bool processIsSuspended() const { return m_processIsSuspended; } 140 142 143 WEBCORE_EXPORT void addAudioCaptureSource(PlatformMediaSession::AudioCaptureSource&); 144 WEBCORE_EXPORT void removeAudioCaptureSource(PlatformMediaSession::AudioCaptureSource&); 145 141 146 protected: 142 147 friend class PlatformMediaSession; … … 164 169 #endif 165 170 171 int countActiveAudioCaptureSources(); 172 166 173 private: 167 174 friend class Internals; … … 184 191 Vector<WeakPtr<PlatformMediaSession>> sessionsMatching(const Function<bool(const PlatformMediaSession&)>&) const; 185 192 186 SessionRestrictions m_restrictions[ PlatformMediaSession::MediaStreamCapturingAudio+ 1];193 SessionRestrictions m_restrictions[static_cast<unsigned>(PlatformMediaSession::MediaType::WebAudio) + 1]; 187 194 mutable Vector<WeakPtr<PlatformMediaSession>> m_sessions; 188 195 std::unique_ptr<RemoteCommandListener> m_remoteCommandListener; … … 205 212 #endif 206 213 214 WeakHashSet<PlatformMediaSession::AudioCaptureSource> m_audioCaptureSources; 215 207 216 #if !RELEASE_LOG_DISABLED 208 217 Ref<AggregateLogger> m_logger; -
trunk/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.mm
r255116 r257039 46 46 47 47 #if PLATFORM(MAC) 48 static MediaSessionManagerCocoa* platformMediaSessionManager = nullptr; 49 50 PlatformMediaSessionManager& PlatformMediaSessionManager::sharedManager() 51 { 52 if (!platformMediaSessionManager) 53 platformMediaSessionManager = new MediaSessionManagerCocoa; 54 return *platformMediaSessionManager; 55 } 56 57 PlatformMediaSessionManager* PlatformMediaSessionManager::sharedManagerIfExists() 58 { 59 return platformMediaSessionManager; 60 } 61 #endif 48 std::unique_ptr<PlatformMediaSessionManager> PlatformMediaSessionManager::create() 49 { 50 return makeUnique<MediaSessionManagerCocoa>(); 51 } 52 #endif // !PLATFORM(MAC) 62 53 63 54 void MediaSessionManagerCocoa::updateSessionState() 64 55 { 65 int videoCount = count(PlatformMediaSession:: Video);66 int videoAudioCount = count(PlatformMediaSession:: VideoAudio);67 int audioCount = count(PlatformMediaSession:: Audio);68 int webAudioCount = count(PlatformMediaSession:: WebAudio);69 int captureCount = count (PlatformMediaSession::MediaStreamCapturingAudio);56 int videoCount = count(PlatformMediaSession::MediaType::Video); 57 int videoAudioCount = count(PlatformMediaSession::MediaType::VideoAudio); 58 int audioCount = count(PlatformMediaSession::MediaType::Audio); 59 int webAudioCount = count(PlatformMediaSession::MediaType::WebAudio); 60 int captureCount = countActiveAudioCaptureSources(); 70 61 ALWAYS_LOG(LOGIDENTIFIER, "types: " 71 62 "AudioCapture(", captureCount, "), " … … 100 91 forEachSession([&hasAudibleAudioOrVideoMediaType] (auto& session) mutable { 101 92 auto type = session.mediaType(); 102 if ((type == PlatformMediaSession:: VideoAudio || type == PlatformMediaSession::Audio) && session.canProduceAudio() && session.hasPlayedSinceLastInterruption())93 if ((type == PlatformMediaSession::MediaType::VideoAudio || type == PlatformMediaSession::MediaType::Audio) && session.canProduceAudio() && session.hasPlayedSinceLastInterruption()) 103 94 hasAudibleAudioOrVideoMediaType = true; 104 95 if (session.isPlayingToWirelessPlaybackTarget()) -
trunk/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm
r256770 r257039 99 99 namespace WebCore { 100 100 101 static MediaSessionManageriOS* platformMediaSessionManager = nullptr; 102 103 PlatformMediaSessionManager& PlatformMediaSessionManager::sharedManager() 104 { 105 if (!platformMediaSessionManager) 106 platformMediaSessionManager = new MediaSessionManageriOS; 107 return *platformMediaSessionManager; 108 } 109 110 PlatformMediaSessionManager* PlatformMediaSessionManager::sharedManagerIfExists() 111 { 112 return platformMediaSessionManager; 101 std::unique_ptr<PlatformMediaSessionManager> PlatformMediaSessionManager::create() 102 { 103 return std::unique_ptr<MediaSessionManageriOS>(new MediaSessionManageriOS); 113 104 } 114 105 … … 144 135 if (ramSize() < systemMemoryRequiredForVideoInBackgroundTabs) { 145 136 ALWAYS_LOG(LOGIDENTIFIER, "restricting video in background tabs because system memory = ", ramSize()); 146 addRestriction(PlatformMediaSession:: Video, BackgroundTabPlaybackRestricted);147 } 148 149 addRestriction(PlatformMediaSession:: Video, BackgroundProcessPlaybackRestricted);150 addRestriction(PlatformMediaSession:: VideoAudio, ConcurrentPlaybackNotPermitted | BackgroundProcessPlaybackRestricted | SuspendedUnderLockPlaybackRestricted);137 addRestriction(PlatformMediaSession::MediaType::Video, BackgroundTabPlaybackRestricted); 138 } 139 140 addRestriction(PlatformMediaSession::MediaType::Video, BackgroundProcessPlaybackRestricted); 141 addRestriction(PlatformMediaSession::MediaType::VideoAudio, ConcurrentPlaybackNotPermitted | BackgroundProcessPlaybackRestricted | SuspendedUnderLockPlaybackRestricted); 151 142 } 152 143 -
trunk/Source/WebCore/platform/mediastream/MediaStreamTrackPrivate.cpp
r249018 r257039 34 34 #include "IntRect.h" 35 35 #include "Logging.h" 36 #include "PlatformMediaSessionManager.h" 36 37 #include <wtf/UUID.h> 37 38 … … 303 304 } 304 305 306 void MediaStreamTrackPrivate::audioUnitWillStart() 307 { 308 if (!m_isEnded) 309 PlatformMediaSessionManager::sharedManager().sessionCanProduceAudioChanged(); 310 } 311 305 312 #if !RELEASE_LOG_DISABLED 306 313 WTFLogChannel& MediaStreamTrackPrivate::logChannel() const -
trunk/Source/WebCore/platform/mediastream/MediaStreamTrackPrivate.h
r254446 r257039 141 141 void videoSampleAvailable(MediaSample&) final; 142 142 void audioSamplesAvailable(const MediaTime&, const PlatformAudioData&, const AudioStreamDescription&, size_t) final; 143 void audioUnitWillStart() final; 143 144 144 145 void updateReadyState(); -
trunk/Source/WebCore/platform/mediastream/RealtimeMediaSource.h
r253275 r257039 84 84 virtual void sourceMutedChanged() { } 85 85 virtual void sourceSettingsChanged() { } 86 virtual void audioUnitWillStart() { } 86 87 87 88 // Observer state queries. -
trunk/Source/WebCore/platform/mediastream/mac/BaseAudioSharedUnit.cpp
r253953 r257039 31 31 #include "AudioSession.h" 32 32 #include "CoreAudioCaptureSource.h" 33 #include "DeprecatedGlobalSettings.h" 33 34 #include "Logging.h" 34 35 #include "PlatformMediaSessionManager.h" … … 94 95 OSStatus BaseAudioSharedUnit::startUnit() 95 96 { 96 #if PLATFORM(IOS_FAMILY) 97 if (!m_disableAudioSessionCheck) { 98 PlatformMediaSessionManager::sharedManager().sessionCanProduceAudioChanged(); 99 ASSERT(AudioSession::sharedSession().category() == AudioSession::PlayAndRecord); 100 } 101 #endif 97 forEachClient([](auto& client) { 98 client.audioUnitWillStart(); 99 }); 100 ASSERT(!DeprecatedGlobalSettings::shouldManageAudioSessionCategory() || AudioSession::sharedSession().category() == AudioSession::PlayAndRecord); 102 101 103 102 if (auto error = startInternal()) { -
trunk/Source/WebCore/platform/mediastream/mac/BaseAudioSharedUnit.h
r253705 r257039 77 77 virtual CapabilityValueOrRange sampleRateCapacities() const = 0; 78 78 79 void setDisableAudioSessionCheck(bool value) { m_disableAudioSessionCheck = value; };80 81 79 protected: 82 80 void forEachClient(const Function<void(CoreAudioCaptureSource&)>&) const; … … 106 104 HashSet<CoreAudioCaptureSource*> m_clients; 107 105 mutable RecursiveLock m_clientsLock; 108 bool m_disableAudioSessionCheck { false };109 106 }; 110 107 -
trunk/Source/WebCore/platform/mediastream/mac/CoreAudioCaptureSource.cpp
r254259 r257039 804 804 } 805 805 806 void CoreAudioCaptureSource::audioUnitWillStart() 807 { 808 forEachObserver([](auto& observer) { 809 observer.audioUnitWillStart(); 810 }); 811 } 812 806 813 } // namespace WebCore 807 814 -
trunk/Source/WebCore/platform/mediastream/mac/CoreAudioCaptureSource.h
r252961 r257039 90 90 91 91 void initializeToStartProducingData(); 92 void audioUnitWillStart(); 92 93 93 94 #if !RELEASE_LOG_DISABLED -
trunk/Source/WebCore/testing/Internals.cpp
r256918 r257039 3915 3915 { 3916 3916 if (equalLettersIgnoringASCIICase(mediaTypeString, "video")) 3917 return PlatformMediaSession:: Video;3917 return PlatformMediaSession::MediaType::Video; 3918 3918 if (equalLettersIgnoringASCIICase(mediaTypeString, "audio")) 3919 return PlatformMediaSession:: Audio;3919 return PlatformMediaSession::MediaType::Audio; 3920 3920 if (equalLettersIgnoringASCIICase(mediaTypeString, "videoaudio")) 3921 return PlatformMediaSession:: VideoAudio;3921 return PlatformMediaSession::MediaType::VideoAudio; 3922 3922 if (equalLettersIgnoringASCIICase(mediaTypeString, "webaudio")) 3923 return PlatformMediaSession::WebAudio; 3924 if (equalLettersIgnoringASCIICase(mediaTypeString, "mediastreamcapturingaudio")) 3925 return PlatformMediaSession::MediaStreamCapturingAudio; 3926 3927 return PlatformMediaSession::None; 3923 return PlatformMediaSession::MediaType::WebAudio; 3924 3925 return PlatformMediaSession::MediaType::None; 3928 3926 } 3929 3927 3930 3928 ExceptionOr<void> Internals::setMediaSessionRestrictions(const String& mediaTypeString, StringView restrictionsString) 3931 3929 { 3932 PlatformMediaSession::MediaTypemediaType = mediaTypeFromString(mediaTypeString);3933 if (mediaType == PlatformMediaSession:: None)3934 return Exception { InvalidAccessError }; 3935 3936 PlatformMediaSessionManager::SessionRestrictionsrestrictions = PlatformMediaSessionManager::sharedManager().restrictions(mediaType);3930 auto mediaType = mediaTypeFromString(mediaTypeString); 3931 if (mediaType == PlatformMediaSession::MediaType::None) 3932 return Exception { InvalidAccessError }; 3933 3934 auto restrictions = PlatformMediaSessionManager::sharedManager().restrictions(mediaType); 3937 3935 PlatformMediaSessionManager::sharedManager().removeRestriction(mediaType, restrictions); 3938 3936 … … 3960 3958 { 3961 3959 PlatformMediaSession::MediaType mediaType = mediaTypeFromString(mediaTypeString); 3962 if (mediaType == PlatformMediaSession:: None)3960 if (mediaType == PlatformMediaSession::MediaType::None) 3963 3961 return Exception { InvalidAccessError }; 3964 3962 -
trunk/Source/WebKit/ChangeLog
r257029 r257039 1 2020-02-19 Youenn Fablet <youenn@apple.com> 2 3 Add support for AudioSession handling in GPUProcess for capture 4 https://bugs.webkit.org/show_bug.cgi?id=207950 5 6 Reviewed by Eric Carlson. 7 8 Create a session manager for the GPUConnectionToWebProcess. 9 Pass it to any audio capture source proxy. 10 For UIProcesss audio capture, we still use the shared manager. 11 12 * GPUProcess/GPUConnectionToWebProcess.cpp: 13 (WebKit::GPUConnectionToWebProcess::sessionManager): 14 * GPUProcess/GPUConnectionToWebProcess.h: 15 * GPUProcess/GPUProcess.cpp: 16 (WebKit::GPUProcess::setMockCaptureDevicesEnabled): 17 * UIProcess/Cocoa/UserMediaCaptureManagerProxy.cpp: 18 (WebKit::UserMediaCaptureManagerProxy::SourceProxy::SourceProxy): 19 (WebKit::UserMediaCaptureManagerProxy::SourceProxy::~SourceProxy): 20 (WebKit::UserMediaCaptureManagerProxy::createMediaSourceForCaptureDeviceWithConstraints): 21 (WebKit::UserMediaCaptureManagerProxy::clone): 22 * UIProcess/Cocoa/UserMediaCaptureManagerProxy.h: 23 * UIProcess/WebProcessProxy.cpp: 24 1 25 2020-02-19 Per Arne Vollan <pvollan@apple.com> 2 26 -
trunk/Source/WebKit/GPUProcess/GPUConnectionToWebProcess.cpp
r256493 r257039 61 61 62 62 #include <WebCore/MockRealtimeMediaSourceCenter.h> 63 #include <WebCore/PlatformMediaSessionManager.h> 63 64 64 65 namespace WebKit { … … 78 79 void removeMessageReceiver(IPC::StringReference messageReceiverName) final { } 79 80 IPC::Connection& connection() final { return m_process.connection(); } 81 PlatformMediaSessionManager& sessionManager() final { return m_process.sessionManager(); } 80 82 81 83 GPUConnectionToWebProcess& m_process; … … 274 276 #endif 275 277 278 PlatformMediaSessionManager& GPUConnectionToWebProcess::sessionManager() 279 { 280 if (!m_sessionManager) 281 m_sessionManager = PlatformMediaSessionManager::create(); 282 return *m_sessionManager; 283 } 284 276 285 } // namespace WebKit 277 286 -
trunk/Source/WebKit/GPUProcess/GPUConnectionToWebProcess.h
r256493 r257039 37 37 #include <wtf/UniqueRef.h> 38 38 39 namespace WebCore { 40 class PlatformMediaSessionManager; 41 } 42 39 43 namespace WebKit { 40 44 … … 70 74 const String& mediaKeysStorageDirectory() const; 71 75 #endif 76 77 WebCore::PlatformMediaSessionManager& sessionManager(); 72 78 73 79 private: … … 112 118 std::unique_ptr<LibWebRTCCodecsProxy> m_libWebRTCCodecsProxy; 113 119 #endif 120 std::unique_ptr<WebCore::PlatformMediaSessionManager> m_sessionManager; 114 121 }; 115 122 -
trunk/Source/WebKit/GPUProcess/GPUProcess.cpp
r255346 r257039 152 152 { 153 153 #if ENABLE(MEDIA_STREAM) 154 // FIXME: Enable the audio session check by implementing an AudioSession for the GPUProcess.155 MockAudioSharedUnit::singleton().setDisableAudioSessionCheck(isEnabled);156 154 MockRealtimeMediaSourceCenter::setMockRealtimeMediaSourceCenterEnabled(isEnabled); 157 155 #endif -
trunk/Source/WebKit/UIProcess/Cocoa/UserMediaCaptureManagerProxy.cpp
r255211 r257039 36 36 #include <WebCore/CARingBuffer.h> 37 37 #include <WebCore/MediaConstraints.h> 38 #include <WebCore/PlatformMediaSessionManager.h> 38 39 #include <WebCore/RealtimeMediaSourceCenter.h> 39 40 #include <WebCore/RemoteVideoSample.h> … … 44 45 using namespace WebCore; 45 46 46 class UserMediaCaptureManagerProxy::SourceProxy : public RealtimeMediaSource::Observer, public SharedRingBufferStorage::Client { 47 class UserMediaCaptureManagerProxy::SourceProxy 48 : public RealtimeMediaSource::Observer 49 , public SharedRingBufferStorage::Client 50 , public PlatformMediaSession::AudioCaptureSource { 47 51 WTF_MAKE_FAST_ALLOCATED; 48 52 public: 49 SourceProxy(RealtimeMediaSourceIdentifier id, Ref<IPC::Connection>&& connection, Ref<RealtimeMediaSource>&& source)53 SourceProxy(RealtimeMediaSourceIdentifier id, PlatformMediaSessionManager& sessionManager, Ref<IPC::Connection>&& connection, Ref<RealtimeMediaSource>&& source) 50 54 : m_id(id) 55 , m_sessionManager(makeWeakPtr(sessionManager)) 51 56 , m_connection(WTFMove(connection)) 52 57 , m_source(WTFMove(source)) … … 54 59 { 55 60 m_source->addObserver(*this); 61 62 if (m_source->type() == RealtimeMediaSource::Type::Audio) 63 sessionManager.addAudioCaptureSource(*this); 56 64 } 57 65 … … 60 68 storage().invalidate(); 61 69 m_source->removeObserver(*this); 70 71 if (m_source->type() == RealtimeMediaSource::Type::Audio && m_sessionManager) 72 m_sessionManager->removeAudioCaptureSource(*this); 62 73 } 63 74 … … 66 77 CAAudioStreamDescription& description() { return m_description; } 67 78 int64_t numberOfFrames() { return m_numberOfFrames; } 79 80 bool isCapturingAudio() const final { return !m_isEnded && m_source->isProducingData(); } 81 82 void audioUnitWillStart() final 83 { 84 if (!m_isEnded && m_sessionManager) 85 m_sessionManager->sessionCanProduceAudioChanged(); 86 } 68 87 69 88 void start() … … 146 165 147 166 RealtimeMediaSourceIdentifier m_id; 167 WeakPtr<PlatformMediaSessionManager> m_sessionManager; 148 168 Ref<IPC::Connection> m_connection; 149 169 Ref<RealtimeMediaSource> m_source; … … 193 213 settings = source->settings(); 194 214 ASSERT(!m_proxies.contains(id)); 195 m_proxies.add(id, makeUnique<SourceProxy>(id, m_connectionProxy-> connection(), WTFMove(source)));215 m_proxies.add(id, makeUnique<SourceProxy>(id, m_connectionProxy->sessionManager(), m_connectionProxy->connection(), WTFMove(source))); 196 216 } else 197 217 invalidConstraints = WTFMove(sourceOrError.errorMessage); … … 249 269 ASSERT(!m_proxies.contains(newSourceID)); 250 270 if (auto* proxy = m_proxies.get(clonedID)) 251 m_proxies.add(newSourceID, makeUnique<SourceProxy>(newSourceID, m_connectionProxy-> connection(), proxy->source().clone()));271 m_proxies.add(newSourceID, makeUnique<SourceProxy>(newSourceID, m_connectionProxy->sessionManager(), m_connectionProxy->connection(), proxy->source().clone())); 252 272 } 253 273 -
trunk/Source/WebKit/UIProcess/Cocoa/UserMediaCaptureManagerProxy.h
r255133 r257039 36 36 #include <wtf/UniqueRef.h> 37 37 38 namespace WebCore { 39 class PlatformMediaSessionManager; 40 } 41 38 42 namespace WebKit { 39 43 … … 50 54 virtual void removeMessageReceiver(IPC::StringReference) = 0; 51 55 virtual IPC::Connection& connection() = 0; 56 virtual WebCore::PlatformMediaSessionManager& sessionManager() = 0; 52 57 }; 53 58 explicit UserMediaCaptureManagerProxy(UniqueRef<ConnectionProxy>&&); -
trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp
r256742 r257039 60 60 #include "WebsiteDataFetchOption.h" 61 61 #include <WebCore/DiagnosticLoggingKeys.h> 62 #include <WebCore/PlatformMediaSessionManager.h> 62 63 #include <WebCore/PrewarmInformation.h> 63 64 #include <WebCore/PublicSuffix.h> … … 160 161 void removeMessageReceiver(IPC::StringReference messageReceiverName) final { m_process.removeMessageReceiver(messageReceiverName); } 161 162 IPC::Connection& connection() final { return *m_process.connection(); } 163 PlatformMediaSessionManager& sessionManager() final { return PlatformMediaSessionManager::sharedManager(); } 162 164 163 165 WebProcessProxy& m_process;
Note: See TracChangeset
for help on using the changeset viewer.