Bug 187896 - 'ended' Event doesn't fire on MediaStreamTrack when a USB camera is unplugged
Summary: 'ended' Event doesn't fire on MediaStreamTrack when a USB camera is unplugged
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebRTC (show other bugs)
Version: Safari Technology Preview
Hardware: Mac macOS 10.13
: P2 Normal
Assignee: Eric Carlson
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2018-07-22 18:32 PDT by Adam
Modified: 2018-12-21 17:37 PST (History)
6 users (show)

See Also:


Attachments
Patch (18.67 KB, patch)
2018-12-21 13:22 PST, Eric Carlson
no flags Details | Formatted Diff | Diff
Patch (18.87 KB, patch)
2018-12-21 14:04 PST, Eric Carlson
no flags Details | Formatted Diff | Diff
Patch for landing. (18.95 KB, patch)
2018-12-21 15:15 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 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.