Bug 147117 - Exposed method to query device by UID
Summary: Exposed method to query device by UID
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: 147131 147062
  Show dependency treegraph
 
Reported: 2015-07-20 12:16 PDT by Matthew Daiter
Modified: 2015-07-21 17:07 PDT (History)
8 users (show)

See Also:


Attachments
Patch (3.69 KB, patch)
2015-07-20 12:20 PDT, Matthew Daiter
no flags Details | Formatted Diff | Diff
Patch (3.88 KB, patch)
2015-07-20 16:48 PDT, Matthew Daiter
no flags Details | Formatted Diff | Diff
Patch (3.93 KB, patch)
2015-07-20 17:16 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-20 12:16:59 PDT
Needed for getting devices from Safari by UID.
Comment 1 Radar WebKit Bug Importer 2015-07-20 12:18:13 PDT
<rdar://problem/21904678>
Comment 2 Matthew Daiter 2015-07-20 12:20:26 PDT
Created attachment 257116 [details]
Patch
Comment 3 Eric Carlson 2015-07-20 13:51:08 PDT
Comment on attachment 257116 [details]
Patch

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

> Source/WebCore/platform/mediastream/mac/AVCaptureDeviceManager.h:53
> +    RefPtr<RealtimeMediaSource> sourceWithUID(String&, RealtimeMediaSource::Type, RefPtr<MediaConstraints>&&);

Ref&& seems wrong unless you are passing ownership of the RefPtr (https://www.webkit.org/coding/RefPtr.html). Because this argument is optional (I think), it should be a MediaConstraints*.

> Source/WebCore/platform/mediastream/mac/AVCaptureDeviceManager.mm:427
> +        AVCaptureDeviceType *device = [AVCaptureDevice deviceWithUniqueID:captureDevice.m_captureDeviceID];
> +        ASSERT(device);

captureDevice.m_captureDeviceID is set from device.uniqueID, so can you short circuit the lookup:

    if (captureDevice.m_captureDeviceID != deviceUID)
        continue;

> Source/WebCore/platform/mediastream/mac/AVCaptureDeviceManager.mm:436
> +            if (type == RealtimeMediaSource::Type::Audio && !captureDevice.m_audioSourceId.isEmpty()) {
> +                captureDevice.m_audioSource = AVAudioCaptureSource::create(device, captureDevice.m_audioSourceId, constraints);
> +                return captureDevice.m_audioSource;
> +            }
> +            if (type == RealtimeMediaSource::Type::Video && !captureDevice.m_videoSourceId.isEmpty()) {
> +                captureDevice.m_videoSource = AVVideoCaptureSource::create(device, captureDevice.m_videoSourceId, constraints);
> +                return captureDevice.m_videoSource;
> +            }

Don't you also need to consider constraints:

    String invalidConstraint;
    AVCaptureDeviceManager::singleton().verifyConstraintsForMediaType(type, constraints, invalidConstraint);
    if (!invalidConstraint.isEmpty())
        continue;
Comment 4 Matthew Daiter 2015-07-20 16:48:11 PDT
Created attachment 257145 [details]
Patch
Comment 5 Matthew Daiter 2015-07-20 16:51:03 PDT
Comment on attachment 257116 [details]
Patch

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

>> Source/WebCore/platform/mediastream/mac/AVCaptureDeviceManager.h:53
>> +    RefPtr<RealtimeMediaSource> sourceWithUID(String&, RealtimeMediaSource::Type, RefPtr<MediaConstraints>&&);
> 
> Ref&& seems wrong unless you are passing ownership of the RefPtr (https://www.webkit.org/coding/RefPtr.html). Because this argument is optional (I think), it should be a MediaConstraints*.

The RefPtr.html page said that the methods should be implemented with a RefPtr or Ref reference reference in the place of a PassRefPtr. However, the argument could be a raw pointer instead.
Fixed.
Comment 6 Eric Carlson 2015-07-20 17:07:54 PDT
(In reply to comment #5)
> Comment on attachment 257116 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=257116&action=review
> 
> >> Source/WebCore/platform/mediastream/mac/AVCaptureDeviceManager.h:53
> >> +    RefPtr<RealtimeMediaSource> sourceWithUID(String&, RealtimeMediaSource::Type, RefPtr<MediaConstraints>&&);
> > 
> > Ref&& seems wrong unless you are passing ownership of the RefPtr (https://www.webkit.org/coding/RefPtr.html). Because this argument is optional (I think), it should be a MediaConstraints*.
> 
> The RefPtr.html page said that the methods should be implemented with a
> RefPtr or Ref reference reference in the place of a PassRefPtr. However, the
> argument could be a raw pointer instead.
> Fixed.

Yes, but Ref&& should be used when passing ownership of an object:

    If a function does take ownership of an object, the argument should be 
    a Ref&& or a RefPtr&&. This includes many setter functions.
Comment 7 Eric Carlson 2015-07-20 17:13:08 PDT
Comment on attachment 257145 [details]
Patch

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

> Source/WebCore/platform/mediastream/mac/AVCaptureDeviceManager.mm:429
> +        String invalidConstraints;
> +        AVCaptureDeviceManager::singleton().verifyConstraintsForMediaType(type, constraints, invalidConstraints);
> +        if (!invalidConstraints.isEmpty())
> +            continue;

This should be wrapped with a "if (constraints) { ... }"

> Source/WebCore/platform/mediastream/mac/AVCaptureDeviceManager.mm:434
> +        if (captureDevice.m_captureDeviceID != deviceUID)
> +            continue;

This is cheap, it should be done before the verifyConstraintsForMediaType() call
Comment 8 Matthew Daiter 2015-07-20 17:15:46 PDT
Comment on attachment 257145 [details]
Patch

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

>> Source/WebCore/platform/mediastream/mac/AVCaptureDeviceManager.mm:429
>> +            continue;
> 
> This should be wrapped with a "if (constraints) { ... }"

Fixed.

>> Source/WebCore/platform/mediastream/mac/AVCaptureDeviceManager.mm:434
>> +            continue;
> 
> This is cheap, it should be done before the verifyConstraintsForMediaType() call

Fixed.
Comment 9 Matthew Daiter 2015-07-20 17:16:19 PDT
Created attachment 257152 [details]
Patch
Comment 10 WebKit Commit Bot 2015-07-21 17:07:24 PDT
Comment on attachment 257152 [details]
Patch

Clearing flags on attachment: 257152

Committed r187140: <http://trac.webkit.org/changeset/187140>
Comment 11 WebKit Commit Bot 2015-07-21 17:07:27 PDT
All reviewed patches have been landed.  Closing bug.