Bug 237025 - RemoteSampleBufferDisplayLayer::enqueueSample should not change media samples owned by its object heap
Summary: RemoteSampleBufferDisplayLayer::enqueueSample should not change media samples...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebRTC (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: youenn fablet
URL:
Keywords: InRadar
Depends on:
Blocks: 237027
  Show dependency treegraph
 
Reported: 2022-02-22 01:23 PST by youenn fablet
Modified: 2022-02-24 15:48 PST (History)
10 users (show)

See Also:


Attachments
Patch (21.79 KB, patch)
2022-02-22 01:45 PST, youenn fablet
no flags Details | Formatted Diff | Diff
Patch for landing (21.80 KB, patch)
2022-02-22 23:48 PST, youenn fablet
no flags Details | Formatted Diff | Diff
Post-commit changes (7.01 KB, patch)
2022-02-23 05:16 PST, youenn fablet
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description youenn fablet 2022-02-22 01:23:36 PST
RemoteSampleBufferDisplayLayer::enqueueSample should not change media samples owned by its object heap
Comment 1 youenn fablet 2022-02-22 01:45:31 PST
Created attachment 452843 [details]
Patch
Comment 2 Darin Adler 2022-02-22 09:58:46 PST
Comment on attachment 452843 [details]
Patch

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

> Source/WebKit/WebProcess/GPU/webrtc/RemoteVideoFrameObjectHeapProxyProcessor.cpp:46
> +    , m_sharedVideoFrameReader(nullptr)

This should be initialized in the header, not the .cpp file.

> Source/WebKit/WebProcess/GPU/webrtc/SharedVideoFrame.cpp:101
> +        IOSurfaceRef surface = pixelBuffer ? CVPixelBufferGetIOSurface(pixelBuffer) : nullptr;
> +        if (surface) {

This looks better to me:

    if (auto pixelBuffer = downcast<MediaSampleAVFObjC>(frame).pixelBuffer()) {
        if (auto surface = CVPixelBufferGetIOSurface(pixelBuffer)) {

> Source/WebKit/WebProcess/GPU/webrtc/SharedVideoFrame.h:127
> +    switchOn(buffer,
> +    [&](std::nullptr_t representation) {
> +        encoder << (uint8_t)0;
> +    }, [&](const RemoteVideoFrameReadReference& reference) {
> +        encoder << (uint8_t)1;
> +        encoder << reference;
> +    } , [&](const MachSendRight& sendRight) {
> +        encoder << (uint8_t)2;
> +        encoder << sendRight;
> +    });

Not sure the indentation here is right. But also, variant should have an encode overload that does this automatically. Why doesn’t this work?

    encoder << buffer;

If it doesn't, we can fix that.

> Source/WebKit/WebProcess/GPU/webrtc/SharedVideoFrame.h:161
> +    uint8_t bufferType;
> +    if (!decoder.decode(bufferType))
> +        return { };
> +
> +    if (bufferType > 2)
> +        return { };
> +
> +    if (bufferType == 1) {
> +        std::optional<RemoteVideoFrameReadReference> reference;
> +        decoder >> reference;
> +        if (!reference)
> +            return { };
> +        frame.buffer = WTFMove(*reference);
> +    } else if (bufferType == 2) {
> +        MachSendRight sendRight;
> +        if (!decoder.decode(sendRight))
> +            return { };
> +        frame.buffer = WTFMove(sendRight);
> +    }
> +    return frame;

This would be *so* much better in the Variant version.
Comment 3 youenn fablet 2022-02-22 10:03:29 PST
(In reply to Darin Adler from comment #2)
> Comment on attachment 452843 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=452843&action=review
> 
> > Source/WebKit/WebProcess/GPU/webrtc/RemoteVideoFrameObjectHeapProxyProcessor.cpp:46
> > +    , m_sharedVideoFrameReader(nullptr)
> 
> This should be initialized in the header, not the .cpp file.

This requires including RemoteVideoFrameObjectHeap.h in SharedVideoFrame.h header file.
I guess I can change the constructor to take a RemoteVideoFrameObjectHeap* instead of a RefPtr<RemoteVideoFrameObjectHeap>&&.


> Not sure the indentation here is right. But also, variant should have an
> encode overload that does this automatically. Why doesn’t this work?
> 
>     encoder << buffer;
> 
> If it doesn't, we can fix that.

I did not know about the encoder variant, will use it.
Comment 4 Darin Adler 2022-02-22 10:06:53 PST
Comment on attachment 452843 [details]
Patch

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

>>> Source/WebKit/WebProcess/GPU/webrtc/RemoteVideoFrameObjectHeapProxyProcessor.cpp:46
>>> +    , m_sharedVideoFrameReader(nullptr)
>> 
>> This should be initialized in the header, not the .cpp file.
> 
> This requires including RemoteVideoFrameObjectHeap.h in SharedVideoFrame.h header file.
> I guess I can change the constructor to take a RemoteVideoFrameObjectHeap* instead of a RefPtr<RemoteVideoFrameObjectHeap>&&.

Or add a default constructor.
Comment 5 youenn fablet 2022-02-22 23:48:58 PST
Created attachment 452943 [details]
Patch for landing
Comment 6 EWS 2022-02-23 01:13:13 PST
Committed r290358 (247676@main): <https://commits.webkit.org/247676@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 452943 [details].
Comment 7 Radar WebKit Bug Importer 2022-02-23 01:14:20 PST
<rdar://problem/89343447>
Comment 8 youenn fablet 2022-02-23 05:10:33 PST
(In reply to youenn fablet from comment #5)
> Created attachment 452943 [details]
> Patch for landing

I forgot to commit the changes to use variant encoder before landing the patch...
I will upload a follow-up patch to fix that.
Comment 9 youenn fablet 2022-02-23 05:16:51 PST
Reopening to attach new patch.
Comment 10 youenn fablet 2022-02-23 05:16:53 PST
Created attachment 452965 [details]
Post-commit changes
Comment 11 EWS 2022-02-23 08:01:21 PST
Committed r290373 (247689@main): <https://commits.webkit.org/247689@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 452965 [details].