Bug 187896

Summary: 'ended' Event doesn't fire on MediaStreamTrack when a USB camera is unplugged
Product: WebKit Reporter: Adam <adam>
Component: WebRTCAssignee: Eric Carlson <eric.carlson>
Status: RESOLVED FIXED    
Severity: Normal CC: commit-queue, eric.carlson, jer.noble, jonlee, webkit-bug-importer, youennf
Priority: P2 Keywords: InRadar
Version: Safari Technology Preview   
Hardware: Mac   
OS: macOS 10.13   
Attachments:
Description Flags
Patch
none
Patch
none
Patch for landing. none

Description Adam 2018-07-22 18:32:11 PDT
Steps to reproduce:

1. Plug in a USB web cam
2. Go to https://output.jsbin.com/fofeyan
3. Choose the USB webcam as your camera and click the switch device button
4. Allow access to the camera and wait for it to be acquired.
5. Unplug the USB webcam

Expected result: You get an alert saying 'track ended'. This happens in Chrome and Firefox. But in Safari there is no 'ended' Event on the MediaStreamTrack.

I tested this in Safari Tech Preview 12.0 and it's not firing there either.
Comment 1 Radar WebKit Bug Importer 2018-07-27 17:33:21 PDT
<rdar://problem/42681445>
Comment 2 Eric Carlson 2018-12-21 13:22:41 PST
Created attachment 357973 [details]
Patch
Comment 3 Eric Carlson 2018-12-21 14:04:04 PST
Created attachment 357978 [details]
Patch
Comment 4 Jer Noble 2018-12-21 14:13:13 PST
View in context: https://bugs.webkit.org/attachment.cgi?id=357973&action=review

> Source/WebCore/platform/mediastream/mac/AVVideoCaptureSource.mm:636
> +    AVCaptureDeviceTypedef *device = [notification object];
> +    if (this->device() == device)

Nit: You don't seem to need the local variable here.

> Source/WebCore/platform/mediastream/mac/AVVideoCaptureSource.mm:726
> +    if (!m_callback)
> +        return;
> +
> +    m_callback->deviceDisconnected(notification);

Nit: how about:

if (m_callback)
    m_callback->deviceDisconnected(notification);

> Source/WebCore/platform/mediastream/mac/CoreAudioCaptureDeviceManager.cpp:95
> +    bool isNonAggregable = !name || !String { name }.startsWith("com.apple.audio.CoreAudio");

Woah, that looks super weird.  I realize that brace-initialization is the new hotness, but I don't think it's supposed to be used for anonymous variables like this.
Comment 5 youenn fablet 2018-12-21 14:24:21 PST
Comment on attachment 357978 [details]
Patch

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

> Source/WebCore/platform/mediastream/mac/CoreAudioCaptureSource.cpp:206
> +void CoreAudioSharedUnit::setCaptureDevice(const String& persistentID, uint32_t captureDeviceID)

Could be String&&

> Source/WebCore/platform/mediastream/mac/CoreAudioCaptureSource.cpp:232
> +    }

Nit: use WTF::anyOf
Comment 6 Eric Carlson 2018-12-21 15:15:48 PST
Created attachment 357988 [details]
Patch for landing.
Comment 7 WebKit Commit Bot 2018-12-21 17:37:08 PST
Comment on attachment 357988 [details]
Patch for landing.

Clearing flags on attachment: 357988

Committed r239531: <https://trac.webkit.org/changeset/239531>
Comment 8 WebKit Commit Bot 2018-12-21 17:37:10 PST
All reviewed patches have been landed.  Closing bug.