Bug 181333 - [MediaStream] Add Mac screen capture source
Summary: [MediaStream] Add Mac screen capture source
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebRTC (show other bugs)
Version: Other
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Eric Carlson
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2018-01-05 11:43 PST by Eric Carlson
Modified: 2018-01-06 16:41 PST (History)
5 users (show)

See Also:


Attachments
Patch (32.56 KB, patch)
2018-01-05 12:05 PST, Eric Carlson
no flags Details | Formatted Diff | Diff
Patch (36.42 KB, patch)
2018-01-05 13:10 PST, Eric Carlson
no flags Details | Formatted Diff | Diff
Patch (36.52 KB, patch)
2018-01-05 13:28 PST, Eric Carlson
no flags Details | Formatted Diff | Diff
Patch (36.36 KB, patch)
2018-01-05 15:11 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 2018-01-05 11:43:20 PST
Add Mac screen capture source
Comment 1 Radar WebKit Bug Importer 2018-01-05 11:44:52 PST
<rdar://problem/36323219>
Comment 2 Eric Carlson 2018-01-05 12:05:02 PST
Created attachment 330566 [details]
Patch
Comment 3 Eric Carlson 2018-01-05 13:10:17 PST
Created attachment 330570 [details]
Patch
Comment 4 Eric Carlson 2018-01-05 13:28:30 PST
Created attachment 330576 [details]
Patch
Comment 5 Dean Jackson 2018-01-05 14:01:42 PST
Comment on attachment 330576 [details]
Patch

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

> Source/WebCore/platform/mediastream/mac/DisplayCaptureManagerCocoa.cpp:103
> +    auto maxDisplays = displayCount;
> +    CGDirectDisplayID activeDisplays[maxDisplays];
> +    err = CGGetActiveDisplayList(maxDisplays, &(activeDisplays[0]), &displayCount);
> +    if (err) {
> +        RELEASE_LOG(Media, "CGGetActiveDisplayList() returned error %d when trying to get the active display list", (int)err);
> +        return;
> +    }
> +    if (displayCount > maxDisplays)
> +        displayCount = maxDisplays;

How could this last test happen? Why would the display count change within this function?

Also, if displayCount has increased in size, isn't activeDisplays the wrong length (too short)?

> Source/WebCore/platform/mediastream/mac/DisplayCaptureManagerCocoa.cpp:110
> +        m_displaysInternal.append({ displayID, CGDisplayIDToOpenGLDisplayMask(displayID) });

Do you ever need to remove a display? Where does m_displaysInternal get reset?

> Source/WebCore/platform/mediastream/mac/DisplayCaptureManagerCocoa.cpp:126
> +    for (auto &device : m_displaysInternal) {

Nit auto& not auto &

> Source/WebCore/platform/mediastream/mac/ScreenDisplayCaptureSourceMac.h:95
> +    class DisplaySurface {
> +    public:
> +        DisplaySurface() = default;
> +        ~DisplaySurface()
> +        {
> +            if (m_surface)
> +                IOSurfaceDecrementUseCount(m_surface.get());
> +        }
> +
> +        DisplaySurface& operator=(IOSurfaceRef surface)
> +        {
> +            if (m_surface)
> +                IOSurfaceDecrementUseCount(m_surface.get());
> +            if (surface)
> +                IOSurfaceIncrementUseCount(surface);
> +            m_surface = surface;
> +            return *this;
> +        }
> +
> +        IOSurfaceRef ioSurface() const { return m_surface.get(); }
> +
> +    private:
> +        RetainPtr<IOSurfaceRef> m_surface;
> +    };

I was going to ask why you don't use platform/graphics/cocoa/IOSurface but I don't think you'd get any benefit. Also, it seems those are intended to own a surface, whereas you're just borrowing one for a while.

The name DisplaySurface through me off a bit though.

> Source/WebCore/platform/mediastream/mac/ScreenDisplayCaptureSourceMac.mm:52
> +static int32_t roundUpToMacroblockMultiple(int32_t size)
> +{
> +    return (size + 15) & ~15;
> +}

I'll take your word for this :)

> Source/WebCore/platform/mediastream/mac/ScreenDisplayCaptureSourceMac.mm:76
> +    if (displayCount > maxDisplays)
> +        displayCount = maxDisplays;

Same comment here. I must be missing it.

> Source/WebCore/platform/mediastream/mac/ScreenDisplayCaptureSourceMac.mm:83
> +    for (auto display : activeDisplays) {
> +        if (displayMask == CGDisplayIDToOpenGLDisplayMask(display))
> +            return display;
> +    }
> +

As discussed on IRC... find_first_of

> Source/WebCore/platform/mediastream/mac/ScreenDisplayCaptureSourceMac.mm:143
> +                screenWidth = 640;
> +                screenHeight = 480;

Are these numbers defined somewhere? should you put a fixme in to identify them?

> Source/WebCore/platform/mediastream/mac/ScreenDisplayCaptureSourceMac.mm:156
> +        int depth = 6;

What is 6?
Comment 6 Eric Carlson 2018-01-05 15:02:28 PST
Comment on attachment 330576 [details]
Patch

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

>> Source/WebCore/platform/mediastream/mac/DisplayCaptureManagerCocoa.cpp:103
>> +        displayCount = maxDisplays;
> 
> How could this last test happen? Why would the display count change within this function?
> 
> Also, if displayCount has increased in size, isn't activeDisplays the wrong length (too short)?

Both are good points, fixed.

>> Source/WebCore/platform/mediastream/mac/DisplayCaptureManagerCocoa.cpp:110
>> +        m_displaysInternal.append({ displayID, CGDisplayIDToOpenGLDisplayMask(displayID) });
> 
> Do you ever need to remove a display? Where does m_displaysInternal get reset?

We never remove a display from our list, but if it disappears it is marked as inactive.

>> Source/WebCore/platform/mediastream/mac/DisplayCaptureManagerCocoa.cpp:126
>> +    for (auto &device : m_displaysInternal) {
> 
> Nit auto& not auto &

Fixed.

>> Source/WebCore/platform/mediastream/mac/ScreenDisplayCaptureSourceMac.mm:52
>> +}
> 
> I'll take your word for this :)

:-)

>> Source/WebCore/platform/mediastream/mac/ScreenDisplayCaptureSourceMac.mm:76
>> +        displayCount = maxDisplays;
> 
> Same comment here. I must be missing it.

Fixed.

>> Source/WebCore/platform/mediastream/mac/ScreenDisplayCaptureSourceMac.mm:83
>> +
> 
> As discussed on IRC... find_first_of

Actually I was wrong, it won't work because activeDisplays is a C-style array.

>> Source/WebCore/platform/mediastream/mac/ScreenDisplayCaptureSourceMac.mm:143
>> +                screenHeight = 480;
> 
> Are these numbers defined somewhere? should you put a fixme in to identify them?

I guess failing to get width or height should result in a failure. Changed.

>> Source/WebCore/platform/mediastream/mac/ScreenDisplayCaptureSourceMac.mm:156
>> +        int depth = 6;
> 
> What is 6?

The maximum number of frames to queue. Added a constant.
Comment 7 Eric Carlson 2018-01-05 15:11:19 PST
Created attachment 330592 [details]
Patch
Comment 8 WebKit Commit Bot 2018-01-05 15:34:33 PST
Comment on attachment 330592 [details]
Patch

Clearing flags on attachment: 330592

Committed r226468: <https://trac.webkit.org/changeset/226468>
Comment 9 WebKit Commit Bot 2018-01-05 15:34:35 PST
All reviewed patches have been landed.  Closing bug.
Comment 10 Simon Fraser (smfr) 2018-01-06 16:41:31 PST
Comment on attachment 330592 [details]
Patch

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

> Source/WebCore/platform/mediastream/mac/ScreenDisplayCaptureSourceMac.h:72
> +    class DisplaySurface {

Can this just use our IOSurface class?

> Source/WebCore/platform/mediastream/mac/ScreenDisplayCaptureSourceMac.mm:152
> +        static CGColorSpaceRef deviceRGBColorSpace = CGColorSpaceCreateDeviceRGB();

We're trying to avoid use of deviceRGB anywhere now, since it's effectively the same as sRGB. Can you change this to use sRGBColorSpaceRef() from GraphicsContextCG.h?