Bug 147171 - Fill vectors in UserMediaRequest with only UIDs of devices that satisfy constraints
Summary: Fill vectors in UserMediaRequest with only UIDs of devices that satisfy const...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Matthew Daiter
URL:
Keywords: InRadar, PlatformOnly
Depends on:
Blocks:
 
Reported: 2015-07-21 16:25 PDT by Matthew Daiter
Modified: 2015-07-22 11:10 PDT (History)
8 users (show)

See Also:


Attachments
Patch (11.22 KB, patch)
2015-07-21 16:48 PDT, Matthew Daiter
no flags Details | Formatted Diff | Diff
Patch (13.03 KB, patch)
2015-07-21 17:21 PDT, Matthew Daiter
no flags Details | Formatted Diff | Diff
Patch (13.38 KB, patch)
2015-07-21 18:06 PDT, Matthew Daiter
no flags Details | Formatted Diff | Diff
Patch (14.25 KB, patch)
2015-07-21 18:46 PDT, Matthew Daiter
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Matthew Daiter 2015-07-21 16:25:28 PDT
We currently send a list of devices, no matter what, to Safari for requesting user media. There should be an easy way to create a list of only devices that can satisfy constraints.
Comment 1 Radar WebKit Bug Importer 2015-07-21 16:26:11 PDT
<rdar://problem/21931121>
Comment 2 Matthew Daiter 2015-07-21 16:48:04 PDT
Created attachment 257218 [details]
Patch
Comment 3 Darin Adler 2015-07-21 16:59:32 PDT
Comment on attachment 257218 [details]
Patch

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

Doesn’t build because you forgot to update the other implementations of MediaStreamCreationClient, specifically MockRealtimeMediaSourceCenter.

> Source/WebCore/Modules/mediastream/UserMediaRequest.cpp:126
> +    for (auto audioTrack : audioTracks)

This will churn reference counts unnecessarily as we iterate each item and copy it into a RefPtr. To fix that, use auto& instead of auto.

> Source/WebCore/Modules/mediastream/UserMediaRequest.cpp:128
> +    for (auto videoTrack : videoTracks)

Ditto.

> Source/WebCore/Modules/mediastream/UserMediaRequest.h:74
> +    Vector<String> filteredListUIDsVideo() const { return m_filteredListUIDsVideo; }
> +    Vector<String> filteredListUIDsAudio() const { return m_filteredListUIDsAudio; }

It’s inefficient to copy these vectors just to return them. Please consider returning const Vector<String>& instead.

> Source/WebCore/platform/mediastream/MediaStreamCreationClient.h:41
> +    virtual void constraintsValidated(Vector<RefPtr<RealtimeMediaSource>>, Vector<RefPtr<RealtimeMediaSource>>) = 0;

It’s inefficient to copy these vectors as part of calling this function. Please consider const Vector&. Also, it’s not clear what these two vectors represent, so these arguments need names.

> Source/WebCore/platform/mediastream/mac/AVCaptureDeviceManager.mm:383
> +    Vector<RefPtr<RealtimeMediaSource>> bestSourcesList = Vector<RefPtr<RealtimeMediaSource>>();

No need to do the "=" part here. Vectors are empty by default without any explicit initialization.

> Source/WebCore/platform/mediastream/mac/AVCaptureDeviceManager.mm:389
>      Vector<CaptureDevice>& devices = captureDeviceList();
>      size_t count = devices.size();

This code should really use a modern for loop, like this:

    for (auto& device : captureDeviceList()) {

Then below use “device” wherever the old code used “devices[i]”. Only issue is that we’d need to rename the local variables named device below.

> Source/WebCore/platform/mediastream/mac/RealtimeMediaSourceCenterMac.cpp:102
> +        // FIXME: consider the constraints when choosing among multiple devices. For now just select the first available

Please capitalize the sentence in a comment like this. The word "consider".

> Source/WebCore/platform/mediastream/mac/RealtimeMediaSourceCenterMac.cpp:117
> +        // FIXME: consider the constraints when choosing among multiple devices. For now just select the first available

Please capitalize the sentence in a comment like this. The word "consider".
Comment 4 Matthew Daiter 2015-07-21 17:21:33 PDT
Created attachment 257221 [details]
Patch
Comment 5 Eric Carlson 2015-07-21 17:51:53 PDT
Comment on attachment 257221 [details]
Patch

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

Looks good overall, but it obviously needs to be rebased so it applies to trunk.

> Source/WebCore/Modules/mediastream/UserMediaRequest.h:74
> +    const Vector<String>& deviceUIDsVideo() const { return m_deviceUIDsVideo; }
> +    const Vector<String>& deviceUIDsAudio() const { return m_deviceUIDsAudio; }

Nit: I think audioDeviceUIDs and videoDeviceUIDs would be better. Also for the instance variables.
Comment 6 Matthew Daiter 2015-07-21 17:52:44 PDT
Comment on attachment 257221 [details]
Patch

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

>> Source/WebCore/Modules/mediastream/UserMediaRequest.h:74
>> +    const Vector<String>& deviceUIDsAudio() const { return m_deviceUIDsAudio; }
> 
> Nit: I think audioDeviceUIDs and videoDeviceUIDs would be better. Also for the instance variables.

Fixed.
Comment 7 Matthew Daiter 2015-07-21 18:06:22 PDT
Created attachment 257231 [details]
Patch
Comment 8 Matthew Daiter 2015-07-21 18:46:32 PDT
Created attachment 257236 [details]
Patch
Comment 9 Eric Carlson 2015-07-22 06:51:00 PDT
Comment on attachment 257236 [details]
Patch

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

> Source/WebCore/Modules/mediastream/UserMediaRequest.h:80
> +    virtual void constraintsValidated(const Vector<RefPtr<RealtimeMediaSource>>&, const Vector<RefPtr<RealtimeMediaSource>>&) override final;

As Darin noted earlier, it is not clear what these two vectors represent so these arguments need names.
Comment 10 WebKit Commit Bot 2015-07-22 11:10:28 PDT
Comment on attachment 257236 [details]
Patch

Clearing flags on attachment: 257236

Committed r187168: <http://trac.webkit.org/changeset/187168>
Comment 11 WebKit Commit Bot 2015-07-22 11:10:36 PDT
All reviewed patches have been landed.  Closing bug.