Bug 231621 - Adopt attribution AVCaptureSession SPI for GPU process
Summary: Adopt attribution AVCaptureSession SPI for GPU process
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Media (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Kate Cheney
URL:
Keywords: InRadar
Depends on:
Blocks: 231882 231977
  Show dependency treegraph
 
Reported: 2021-10-12 14:35 PDT by Kate Cheney
Modified: 2022-03-16 13:17 PDT (History)
15 users (show)

See Also:


Attachments
Patch (12.72 KB, patch)
2021-10-12 14:55 PDT, Kate Cheney
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (13.11 KB, patch)
2021-10-12 15:06 PDT, Kate Cheney
no flags Details | Formatted Diff | Diff
Patch (13.12 KB, patch)
2021-10-12 16:42 PDT, Kate Cheney
no flags Details | Formatted Diff | Diff
Patch (13.05 KB, patch)
2021-10-13 09:29 PDT, Kate Cheney
no flags Details | Formatted Diff | Diff
Patch (28.36 KB, patch)
2021-10-13 13:37 PDT, Kate Cheney
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (28.61 KB, patch)
2021-10-13 14:16 PDT, Kate Cheney
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (28.46 KB, patch)
2021-10-13 14:27 PDT, Kate Cheney
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (28.36 KB, patch)
2021-10-13 14:34 PDT, Kate Cheney
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (28.38 KB, patch)
2021-10-13 14:44 PDT, Kate Cheney
no flags Details | Formatted Diff | Diff
Patch (28.06 KB, patch)
2021-10-14 13:04 PDT, Kate Cheney
no flags Details | Formatted Diff | Diff
Patch for landing (29.13 KB, patch)
2021-10-14 15:59 PDT, Kate Cheney
no flags Details | Formatted Diff | Diff
Patch for build fix #3 (5.67 KB, patch)
2021-10-17 14:27 PDT, David Kilzer (:ddkilzer)
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch for build fix #3 v2 (5.67 KB, patch)
2021-10-17 14:33 PDT, David Kilzer (:ddkilzer)
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Kate Cheney 2021-10-12 14:35:18 PDT
Adopt attribution AVCaptureSession SPI for GPU process
Comment 1 Kate Cheney 2021-10-12 14:55:07 PDT
Created attachment 440988 [details]
Patch
Comment 2 Kate Cheney 2021-10-12 14:55:22 PDT
rdar://80748535
Comment 3 Kate Cheney 2021-10-12 15:06:38 PDT
Created attachment 440994 [details]
Patch
Comment 4 Kate Cheney 2021-10-12 16:42:55 PDT
Created attachment 441019 [details]
Patch
Comment 5 Kate Cheney 2021-10-13 09:29:11 PDT
Created attachment 441090 [details]
Patch
Comment 6 Eric Carlson 2021-10-13 10:13:17 PDT
Comment on attachment 441090 [details]
Patch

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

> Source/WebCore/platform/mediastream/RealtimeMediaSourceCenter.h:50
> +#if USE(APPLE_INTERNAL_SDK)
> +#include <TCC/TCC.h>
> +#endif

#include "TCCSPI.h"

> Source/WebCore/platform/mediastream/mac/AVVideoCaptureSource.mm:51
> +#if USE(APPLE_INTERNAL_SDK)
> +#import <AVFoundation/AVCaptureSession_Private.h>
> +#endif

This should go in AVFoundationSPI.h

> Source/WebCore/platform/mediastream/mac/AVVideoCaptureSource.mm:60
> +@interface AVCaptureSession (AVCaptureSessionPrivate)
> +- (instancetype)initWithAssumedIdentity:(tcc_identity_t)tccIdentity SPI_AVAILABLE(ios(15.0)) API_UNAVAILABLE(macos, macCatalyst, watchos, tvos);
> +@end
> +

Ditto

> Source/WebKit/UIProcess/Cocoa/UserMediaCaptureManagerProxy.cpp:34
> +#include "TCCSoftLink.h"

It looks like this isn't needed.
Comment 7 Kate Cheney 2021-10-13 10:36:14 PDT
(In reply to Eric Carlson from comment #6)
> Comment on attachment 441090 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=441090&action=review
> 
> > Source/WebCore/platform/mediastream/RealtimeMediaSourceCenter.h:50
> > +#if USE(APPLE_INTERNAL_SDK)
> > +#include <TCC/TCC.h>
> > +#endif
> 
> #include "TCCSPI.h"
> 

TCCSPI.h is in WebKit, I don't think it can be included from WebCore.

> > Source/WebCore/platform/mediastream/mac/AVVideoCaptureSource.mm:51
> > +#if USE(APPLE_INTERNAL_SDK)
> > +#import <AVFoundation/AVCaptureSession_Private.h>
> > +#endif
> 
> This should go in AVFoundationSPI.h
> 
> > Source/WebCore/platform/mediastream/mac/AVVideoCaptureSource.mm:60
> > +@interface AVCaptureSession (AVCaptureSessionPrivate)
> > +- (instancetype)initWithAssumedIdentity:(tcc_identity_t)tccIdentity SPI_AVAILABLE(ios(15.0)) API_UNAVAILABLE(macos, macCatalyst, watchos, tvos);
> > +@end
> > +
> 
> Ditto

Ok. Was getting errors trying to include AVFoundationSPI.h in this file. I will try again.

> 
> > Source/WebKit/UIProcess/Cocoa/UserMediaCaptureManagerProxy.cpp:34
> > +#include "TCCSoftLink.h"
> 
> It looks like this isn't needed.

Oops, leftover from a previous version. Will remove.
Comment 8 Eric Carlson 2021-10-13 10:54:34 PDT
Comment on attachment 441090 [details]
Patch

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

>>> Source/WebCore/platform/mediastream/RealtimeMediaSourceCenter.h:50
>>> +#endif
>> 
>> #include "TCCSPI.h"
> 
> TCCSPI.h is in WebKit, I don't think it can be included from WebCore.

You can move it to PAL. `:#if USE(APPLE_INTERNAL_SDK)` should generally only be used in *SPI and *SoftLink files
Comment 9 Kate Cheney 2021-10-13 13:37:20 PDT
Created attachment 441129 [details]
Patch
Comment 10 Kate Cheney 2021-10-13 14:16:19 PDT
Created attachment 441133 [details]
Patch
Comment 11 Kate Cheney 2021-10-13 14:27:44 PDT
Created attachment 441135 [details]
Patch
Comment 12 Kate Cheney 2021-10-13 14:34:31 PDT
Created attachment 441136 [details]
Patch
Comment 13 Kate Cheney 2021-10-13 14:44:03 PDT
Created attachment 441137 [details]
Patch
Comment 14 Eric Carlson 2021-10-14 07:12:05 PDT
Comment on attachment 441137 [details]
Patch

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

Does this work when we capture in the web process?

> Source/WebKit/GPUProcess/cocoa/GPUConnectionToWebProcessCocoa.mm:88
> +std::optional<tcc_identity_t> GPUConnectionToWebProcess::setTCCIdentityInGPUProcess()
> +{
> +    auto auditToken = gpuProcess().parentProcessConnection()->getAuditToken();
> +    if (!auditToken)
> +        return std::nullopt;
> +
> +    NSError *error = nil;
> +    auto bundleProxy = [LSBundleProxy bundleProxyWithAuditToken:*auditToken error:&error];
> +    if (error)
> +        return std::nullopt;
> +
> +    tcc_identity_t identity = nil;
> +    identity = tcc_identity_create(TCC_IDENTITY_CODE_BUNDLE_ID, [bundleProxy.bundleIdentifier UTF8String]);
> +    if (!identity)
> +        return std::nullopt;
> +
> +    WebCore::RealtimeMediaSourceCenter::singleton().setIdentity(identity);
> +
> +    return identity;
> +}

This name is wrong. It is a method on GPUConnectionToWebProcess, so "InGPUProcess" is redundant, and it returns a value so the "set" prefix is confusing. Does it need to return the identity token?

> Source/WebKit/UIProcess/Cocoa/UserMediaCaptureManagerProxy.cpp:353
> +        WebCore::RealtimeMediaSourceCenter::singleton().setIdentity(*identity);

Doesn't setTCCIdentityInGPUProcess already do this?
Comment 15 Kate Cheney 2021-10-14 13:04:24 PDT
Created attachment 441264 [details]
Patch
Comment 16 Kate Cheney 2021-10-14 13:18:45 PDT
(In reply to Eric Carlson from comment #14)
> Comment on attachment 441137 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=441137&action=review
> 
> Does this work when we capture in the web process?
> 

When I disable GPU Process for video capture in settings I am unable to use any video capture at all so I am not able to test. This is not related to my patch as it also reproduces without it. I can add a speculative implementation but it might be better to investigate that separately and post a fix after, especially since capture in GPU Process seems to be on by default.
Comment 17 Eric Carlson 2021-10-14 15:42:40 PDT
(In reply to Kate Cheney from comment #16)
> 
> When I disable GPU Process for video capture in settings I am unable to use
> any video capture at all so I am not able to test. This is not related to my
> patch as it also reproduces without it. I can add a speculative
> implementation but it might be better to investigate that separately and
> post a fix after, especially since capture in GPU Process seems to be on by
> default.
>
It is on by default, but the experimental setting is exposed so in theory it should be switchable. 

Please add a FIXME in the place you think the fix should go (UserMediaCaptureManager::setupCaptureProcesses?).
Comment 18 Eric Carlson 2021-10-14 15:43:39 PDT
Comment on attachment 441264 [details]
Patch

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

Thanks!

> Source/WebKit/ChangeLog:14
> +        (WebKit::GPUConnectionToWebProcess::setTCCIdentityInGPUProcess):

This is now incorrect.

> Source/WebKit/ChangeLog:20
> +        (WebKit::UserMediaCaptureManagerProxy::ConnectionProxy::setTCCIdentityInGPUProcess):

Ditto
Comment 19 Kate Cheney 2021-10-14 15:59:39 PDT
Created attachment 441298 [details]
Patch for landing
Comment 20 Kate Cheney 2021-10-14 15:59:52 PDT
(In reply to Eric Carlson from comment #17)
> (In reply to Kate Cheney from comment #16)
> > 
> > When I disable GPU Process for video capture in settings I am unable to use
> > any video capture at all so I am not able to test. This is not related to my
> > patch as it also reproduces without it. I can add a speculative
> > implementation but it might be better to investigate that separately and
> > post a fix after, especially since capture in GPU Process seems to be on by
> > default.
> >
> It is on by default, but the experimental setting is exposed so in theory it
> should be switchable. 
> 
> Please add a FIXME in the place you think the fix should go
> (UserMediaCaptureManager::setupCaptureProcesses?).

Added.
Comment 21 Kate Cheney 2021-10-14 16:00:07 PDT
(In reply to Eric Carlson from comment #18)
> Comment on attachment 441264 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=441264&action=review
> 
> Thanks!
> 
> > Source/WebKit/ChangeLog:14
> > +        (WebKit::GPUConnectionToWebProcess::setTCCIdentityInGPUProcess):
> 
> This is now incorrect.
> 
> > Source/WebKit/ChangeLog:20
> > +        (WebKit::UserMediaCaptureManagerProxy::ConnectionProxy::setTCCIdentityInGPUProcess):
> 
> Ditto

Fixed both, thanks for the review.
Comment 22 EWS 2021-10-14 17:39:59 PDT
Committed r284220 (243029@main): <https://commits.webkit.org/243029@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 441298 [details].
Comment 23 Alex Christensen 2021-10-14 18:24:30 PDT
r284222
Comment 24 Alex Christensen 2021-10-14 18:34:49 PDT
Comment on attachment 441298 [details]
Patch for landing

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

> Source/WebKit/GPUProcess/cocoa/GPUConnectionToWebProcessCocoa.mm:81
> +    identity = tcc_identity_create(TCC_IDENTITY_CODE_BUNDLE_ID, [bundleProxy.bundleIdentifier UTF8String]);

tcc_identity_create is annotated with OS_OBJECT_RETURNS_RETAINED, which means this is probably a memory leak.  It should probably be auto identity = adoptOSObject(tcc_identity_create(...)); which means my build fix of calling tcc_identity_t will probably also need to be changed to OS_OBJECT_DECL if OS_OBJECT_USE_OBJC is defined.
Comment 25 David Kilzer (:ddkilzer) 2021-10-17 14:09:48 PDT
(In reply to EWS from comment #22)
> Committed r284220 (243029@main): <https://commits.webkit.org/243029@main>
> 
> All reviewed patches have been landed. Closing bug and clearing flags on
> attachment 441298 [details].

(In reply to Alex Christensen from comment #23)
> r284222

Second follow-up fix by Kate for MacCatalyst:

r284251
Comment 26 David Kilzer (:ddkilzer) 2021-10-17 14:27:47 PDT
Reopening to attach new patch.
Comment 27 David Kilzer (:ddkilzer) 2021-10-17 14:27:49 PDT
Created attachment 441549 [details]
Patch for build fix #3
Comment 28 David Kilzer (:ddkilzer) 2021-10-17 14:29:48 PDT
(In reply to David Kilzer (:ddkilzer) from comment #27)
> Created attachment 441549 [details]
> Patch for build fix #3

macOS 10.15 Catalina builds are still failing internally (inlining WebKit.framework).

This attempts to fix them.
Comment 29 David Kilzer (:ddkilzer) 2021-10-17 14:32:12 PDT
Comment on attachment 441549 [details]
Patch for build fix #3

Typo: #endf
Comment 30 David Kilzer (:ddkilzer) 2021-10-17 14:33:52 PDT
Created attachment 441550 [details]
Patch for build fix #3 v2
Comment 31 David Kilzer (:ddkilzer) 2021-10-17 14:49:47 PDT
(In reply to Alex Christensen from comment #24)
> Comment on attachment 441298 [details]
> Patch for landing
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=441298&action=review
> 
> > Source/WebKit/GPUProcess/cocoa/GPUConnectionToWebProcessCocoa.mm:81
> > +    identity = tcc_identity_create(TCC_IDENTITY_CODE_BUNDLE_ID, [bundleProxy.bundleIdentifier UTF8String]);
> 
> tcc_identity_create is annotated with OS_OBJECT_RETURNS_RETAINED, which
> means this is probably a memory leak.  It should probably be auto identity =
> adoptOSObject(tcc_identity_create(...)); which means my build fix of calling
> tcc_identity_t will probably also need to be changed to OS_OBJECT_DECL if
> OS_OBJECT_USE_OBJC is defined.

Bug 231882: WebKit::GPUConnectionToWebProcess::setTCCIdentity() leaks a tcc_identity_t
Comment 32 David Kilzer (:ddkilzer) 2021-10-17 15:35:09 PDT
Comment on attachment 441550 [details]
Patch for build fix #3 v2

Marking cq+ as WebKit project built on Apple Cocoa platforms.
Comment 33 EWS 2021-10-17 16:15:55 PDT
Committed r284344 (243138@main): <https://commits.webkit.org/243138@main>

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