Bug 180206 - [MediaStream] Use CaptureDevice instead of device ID to identify devices
Summary: [MediaStream] Use CaptureDevice instead of device ID to identify devices
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Media (show other bugs)
Version: Other
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Eric Carlson
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2017-11-30 10:29 PST by Eric Carlson
Modified: 2018-01-31 09:37 PST (History)
5 users (show)

See Also:


Attachments
Proposed patch. (52.90 KB, patch)
2017-11-30 11:44 PST, Eric Carlson
ews-watchlist: commit-queue-
Details | Formatted Diff | Diff
Archive of layout-test-results from ews105 for mac-elcapitan-wk2 (3.08 MB, application/zip)
2017-11-30 12:55 PST, EWS Watchlist
no flags Details
Updated patch. (53.46 KB, patch)
2017-11-30 13:53 PST, Eric Carlson
no flags Details | Formatted Diff | Diff
Updated patch. (53.61 KB, patch)
2017-11-30 14:13 PST, Eric Carlson
no flags Details | Formatted Diff | Diff
Patch for landing. (58.90 KB, patch)
2017-12-01 09:21 PST, Eric Carlson
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Eric Carlson 2017-11-30 10:29:07 PST
Use CaptureDevice instead of device ID to identify devices when requesting user permission.
Comment 1 Radar WebKit Bug Importer 2017-11-30 10:29:48 PST
<rdar://problem/35775758>
Comment 2 Eric Carlson 2017-11-30 11:44:31 PST
Created attachment 328001 [details]
Proposed patch.
Comment 3 EWS Watchlist 2017-11-30 12:55:05 PST
Comment on attachment 328001 [details]
Proposed patch.

Attachment 328001 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.webkit.org/results/5421399

New failing tests:
fast/mediastream/getUserMedia-grant-persistency.html
fast/mediastream/getUserMedia-grant-persistency2.html
http/tests/media/media-stream/get-user-media-prompt.html
Comment 4 EWS Watchlist 2017-11-30 12:55:06 PST
Created attachment 328008 [details]
Archive of layout-test-results from ews105 for mac-elcapitan-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews105  Port: mac-elcapitan-wk2  Platform: Mac OS X 10.11.6
Comment 5 Eric Carlson 2017-11-30 13:53:30 PST
Created attachment 328018 [details]
Updated patch.
Comment 6 Eric Carlson 2017-11-30 14:13:17 PST
Created attachment 328025 [details]
Updated patch.
Comment 7 youenn fablet 2017-11-30 21:18:09 PST
Comment on attachment 328025 [details]
Updated patch.

View in context: https://bugs.webkit.org/attachment.cgi?id=328025&action=review

> Source/WebCore/Modules/mediastream/UserMediaRequest.cpp:158
> +void UserMediaRequest::allow(std::optional<CaptureDevice>&& audioDevice, std::optional<CaptureDevice>&& videoDevice, String&& deviceIdentifierHashSalt)

An alternative to std::optional would be to consider that there is no CaptureDevice if CaptureDevice.persistentId is the null string or its type is none (i.e. default constructed CaptureDevice).
We could also have added an operator bool or helper method to know whether CaptureDevice was valid or not like optional has.
Not sure what is best, but optional is fine to me.

> Source/WebCore/Modules/mediastream/UserMediaRequest.cpp:162
> +    m_allowedVideoDevice = videoDevice;

We can probably move audioDevice/videoDevice.

> Source/WebKit/UIProcess/UserMediaPermissionRequestManagerProxy.cpp:219
> +void UserMediaPermissionRequestManagerProxy::grantAccess(uint64_t userMediaID, std::optional<CaptureDevice> audioDevice, std::optional<CaptureDevice> videoDevice, const String& deviceIdentifierHashSalt)

Should be const std::optional<CaptureDevice>& probably.

> Source/WebKit/UIProcess/UserMediaPermissionRequestManagerProxy.cpp:221
> +    UserMediaProcessManager::singleton().willCreateMediaStream(*this, audioDevice.has_value(), videoDevice.has_value());

could use !!audioDevice instead of has_value.

> Source/WebKit/UIProcess/UserMediaPermissionRequestProxy.h:54
> +    const Vector<String> audioDeviceUIDs() const;

Can we use Vector<> instead of const Vector<>?
Comment 8 Eric Carlson 2017-12-01 09:19:30 PST
Comment on attachment 328025 [details]
Updated patch.

View in context: https://bugs.webkit.org/attachment.cgi?id=328025&action=review

>> Source/WebCore/Modules/mediastream/UserMediaRequest.cpp:158
>> +void UserMediaRequest::allow(std::optional<CaptureDevice>&& audioDevice, std::optional<CaptureDevice>&& videoDevice, String&& deviceIdentifierHashSalt)
> 
> An alternative to std::optional would be to consider that there is no CaptureDevice if CaptureDevice.persistentId is the null string or its type is none (i.e. default constructed CaptureDevice).
> We could also have added an operator bool or helper method to know whether CaptureDevice was valid or not like optional has.
> Not sure what is best, but optional is fine to me.

Good idea. I added an operator bool that checks type != Unknown.

>> Source/WebCore/Modules/mediastream/UserMediaRequest.cpp:162
>> +    m_allowedVideoDevice = videoDevice;
> 
> We can probably move audioDevice/videoDevice.

That doesn't work because we have to WTFMove() the device parameters to RealtimeMediaSourceCenter::createMediaStream.

>> Source/WebKit/UIProcess/UserMediaPermissionRequestManagerProxy.cpp:219
>> +void UserMediaPermissionRequestManagerProxy::grantAccess(uint64_t userMediaID, std::optional<CaptureDevice> audioDevice, std::optional<CaptureDevice> videoDevice, const String& deviceIdentifierHashSalt)
> 
> Should be const std::optional<CaptureDevice>& probably.

Fixed.

>> Source/WebKit/UIProcess/UserMediaPermissionRequestManagerProxy.cpp:221
>> +    UserMediaProcessManager::singleton().willCreateMediaStream(*this, audioDevice.has_value(), videoDevice.has_value());
> 
> could use !!audioDevice instead of has_value.

I did that at first but changed to has_value at some point. Reconsidering, I think you are right.

>> Source/WebKit/UIProcess/UserMediaPermissionRequestProxy.h:54
>> +    const Vector<String> audioDeviceUIDs() const;
> 
> Can we use Vector<> instead of const Vector<>?

Fixed.
Comment 9 Eric Carlson 2017-12-01 09:21:25 PST
Created attachment 328098 [details]
Patch for landing.
Comment 10 WebKit Commit Bot 2017-12-01 10:09:07 PST
Comment on attachment 328098 [details]
Patch for landing.

Clearing flags on attachment: 328098

Committed r225395: <https://trac.webkit.org/changeset/225395>