[MediaStream] Move capture device monitoring to WebKit
authoreric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 20 Aug 2018 18:10:22 +0000 (18:10 +0000)
committereric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 20 Aug 2018 18:10:22 +0000 (18:10 +0000)
commitf07c6ece833fabd0016d1d6efba27ee1e9641d3c
tree290b0c999030cbe39ddb4bafd308348c63f3184b
parent30fa1325cccf7fa2d3934d72346dd3fd666aecf6
[MediaStream] Move capture device monitoring to WebKit
https://bugs.webkit.org/show_bug.cgi?id=188521
<rdar://problem/43251787>

Reviewed by Youenn Fablet.

Source/WebCore:

No new tests, updated fast/mediastream/device-change-event-2.html for the changes.

* Modules/mediastream/MediaDevices.cpp:
(WebCore::MediaDevices::MediaDevices): Device change listener is added in addEventListener.
(WebCore::MediaDevices::stop): Device change listener is on the user media controller.
(WebCore::MediaDevices::addEventListener): Add the device change listener only once the first
event handler is added.
* Modules/mediastream/MediaDevices.h:

* Modules/mediastream/UserMediaClient.h:
* Modules/mediastream/UserMediaController.h:
(WebCore::UserMediaController::addDeviceChangeObserver): Pass through to the client.
(WebCore::UserMediaController::removeDeviceChangeObserver): Ditto.

* platform/mediastream/CaptureDeviceManager.cpp:
(CaptureDeviceManager::deviceChanged): Notify RealtimeMediaSourceCenter.
(nextObserverToken): Deleted.
(CaptureDeviceManager::addCaptureDeviceChangedObserver): Deleted.
(CaptureDeviceManager::removeCaptureDeviceChangedObserver): Deleted.
* platform/mediastream/CaptureDeviceManager.h:

* platform/mediastream/RealtimeMediaSourceCenter.cpp:
(WebCore::RealtimeMediaSourceCenter::setDevicesChangedObserver):
(WebCore::RealtimeMediaSourceCenter::captureDevicesChanged):
(WebCore::observerMap): Deleted.
(WebCore::RealtimeMediaSourceCenter::addDevicesChangedObserver): Deleted.
(WebCore::RealtimeMediaSourceCenter::removeDevicesChangedObserver): Deleted.
* platform/mediastream/RealtimeMediaSourceCenter.h:

* platform/mediastream/ios/AVAudioSessionCaptureDeviceManager.mm:
(WebCore::AVAudioSessionCaptureDeviceManager::refreshAudioCaptureDevices): Call base class.

* platform/mediastream/mac/AVCaptureDeviceManager.mm:
(WebCore::AVCaptureDeviceManager::deviceConnected): Ditto.
(WebCore::AVCaptureDeviceManager::deviceDisconnected): Ditto.

* platform/mediastream/mac/CoreAudioCaptureDeviceManager.cpp:
(WebCore::deviceHasInputStreams): Drive-by fix, check the number of buffers to see if the
device has input streams.
(WebCore::CoreAudioCaptureDeviceManager::coreAudioCaptureDevices): Use new bool parameter
added to refreshAudioCaptureDevices so we won't trigger a device change event on the first scan.
(WebCore::CoreAudioCaptureDeviceManager::refreshAudioCaptureDevices): Add param.
(WebCore::CoreAudioCaptureDeviceManager::devicesChanged): Use new param.
* platform/mediastream/mac/CoreAudioCaptureDeviceManager.h:

* platform/mock/MockRealtimeMediaSourceCenter.cpp:
(WebCore::MockRealtimeMediaSourceCenter::setDevices): Don't need to call captureDevicesChanged,
it is done in the UI process.
(WebCore::MockRealtimeMediaSourceCenter::addDevice): Ditto.
(WebCore::MockRealtimeMediaSourceCenter::removeDevice): Ditto.

* testing/InternalSettings.cpp:
(WebCore::InternalSettings::setPageIsFocusedAndActive): New, used by updated test.
* testing/Internals.h:
* testing/Internals.idl:

Source/WebKit:

* UIProcess/UserMediaPermissionRequestManagerProxy.cpp:
(WebKit::UserMediaPermissionRequestManagerProxy::captureDevicesChanged): Notify as appropriate.
(WebKit::UserMediaPermissionRequestManagerProxy::viewIsBecomingVisible): Change name from
viewIsBecomingVisible. Call captureDevicesChanged if a change happened when not visible.
(WebKit::UserMediaPermissionRequestManagerProxy::watchdogTimerFired): Clear m_pendingDeviceChangeEvent.
(WebKit::UserMediaPermissionRequestManagerProxy::processPregrantedRequests): Deleted.
* UIProcess/UserMediaPermissionRequestManagerProxy.h:

* UIProcess/UserMediaProcessManager.cpp:
(WebKit::UserMediaProcessManager::UserMediaProcessManager): Initialize timer.
(WebKit::UserMediaProcessManager::captureDevicesChanged): New, notify each manager.
(WebKit::UserMediaProcessManager::beginMonitoringCaptureDevices): Cache the device list and
register device change listener the first time it is called.
* UIProcess/UserMediaProcessManager.h:

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::viewIsBecomingVisible):
(WebKit::WebPageProxy::beginMonitoringCaptureDevices):
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:

* WebProcess/MediaStream/UserMediaPermissionRequestManager.cpp:
(WebKit::UserMediaPermissionRequestManager::addDeviceChangeObserver): Add listener, tell page
to start monitoring device changes.
(WebKit::UserMediaPermissionRequestManager::removeDeviceChangeObserver): Remove listener.
(WebKit::UserMediaPermissionRequestManager::captureDevicesChanged): Call listeners.
* WebProcess/MediaStream/UserMediaPermissionRequestManager.h:

* WebProcess/WebCoreSupport/WebUserMediaClient.cpp:
(WebKit::WebUserMediaClient::addDeviceChangeObserver):
(WebKit::WebUserMediaClient::removeDeviceChangeObserver):
* WebProcess/WebCoreSupport/WebUserMediaClient.h:

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::captureDevicesChanged):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:

* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::addMockMediaDevice):
(WebKit::WebProcess::clearMockMediaDevices):
(WebKit::WebProcess::removeMockMediaDevice):
(WebKit::WebProcess::resetMockMediaDevices):
(WebKit::WebProcess::captureDevicesChanged):
* WebProcess/WebProcess.h:

LayoutTests:

* fast/mediastream/device-change-event-2-expected.txt: Updated.
* fast/mediastream/device-change-event-2.html: Updated.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@235086 268f45cc-cd09-0410-ab3c-d52691b4dbfc
40 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/mediastream/device-change-event-2-expected.txt
LayoutTests/fast/mediastream/device-change-event-2.html
Source/WebCore/ChangeLog
Source/WebCore/Modules/mediastream/MediaDevices.cpp
Source/WebCore/Modules/mediastream/MediaDevices.h
Source/WebCore/Modules/mediastream/UserMediaClient.h
Source/WebCore/Modules/mediastream/UserMediaController.h
Source/WebCore/page/Page.h
Source/WebCore/platform/mediastream/CaptureDeviceManager.cpp
Source/WebCore/platform/mediastream/CaptureDeviceManager.h
Source/WebCore/platform/mediastream/RealtimeMediaSource.cpp
Source/WebCore/platform/mediastream/RealtimeMediaSourceCenter.cpp
Source/WebCore/platform/mediastream/RealtimeMediaSourceCenter.h
Source/WebCore/platform/mediastream/ios/AVAudioSessionCaptureDeviceManager.mm
Source/WebCore/platform/mediastream/mac/AVCaptureDeviceManager.mm
Source/WebCore/platform/mediastream/mac/CoreAudioCaptureDeviceManager.cpp
Source/WebCore/platform/mediastream/mac/CoreAudioCaptureDeviceManager.h
Source/WebCore/platform/mock/MockRealtimeMediaSource.cpp
Source/WebCore/platform/mock/MockRealtimeMediaSourceCenter.cpp
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h
Source/WebCore/testing/Internals.idl
Source/WebKit/ChangeLog
Source/WebKit/Scripts/webkit/messages.py
Source/WebKit/UIProcess/UserMediaPermissionRequestManagerProxy.cpp
Source/WebKit/UIProcess/UserMediaPermissionRequestManagerProxy.h
Source/WebKit/UIProcess/UserMediaProcessManager.cpp
Source/WebKit/UIProcess/UserMediaProcessManager.h
Source/WebKit/UIProcess/WebPageProxy.cpp
Source/WebKit/UIProcess/WebPageProxy.h
Source/WebKit/UIProcess/WebPageProxy.messages.in
Source/WebKit/WebKit.xcodeproj/project.pbxproj
Source/WebKit/WebProcess/MediaStream/UserMediaPermissionRequestManager.cpp
Source/WebKit/WebProcess/MediaStream/UserMediaPermissionRequestManager.h
Source/WebKit/WebProcess/WebCoreSupport/WebUserMediaClient.cpp
Source/WebKit/WebProcess/WebCoreSupport/WebUserMediaClient.h
Source/WebKit/WebProcess/WebPage/WebPage.cpp
Source/WebKit/WebProcess/WebPage/WebPage.h
Source/WebKit/WebProcess/WebPage/WebPage.messages.in