Skip to content

Commit ac56c26

Browse files
committed
[macOS] camera OS indicator does not go away when stopping camera and screenshare
rdar://152962650 https://bugs.webkit.org/show_bug.cgi?id=297718 Reviewed by Eric Carlson. We need to do two things: - When capture starts, make sure the picker is active. - When capture is muted, make sure the picker stays active as long as the muted source may be unmuted. This is to ensure that capturing applications that can fullscreen (like KeyNotes) is working appropriately - When capture is ended, make sure the picker is inactive if there is no other source (started or muted). To do so, we do the following: - We move the setActive logic to WebDisplayMediaPromptHelper startObservingPicker/stopObservingPicker. - We make sure that ScreenCaptureKitCaptureSource keeps its m_sessionSource alive when stopped. This prevents the picker to be set back to inactive too early. - We continue to recreate m_sessionSource whenever starting to capture (initial start or unmute) to keep the existing code as is. - We make sure that ScreenCaptureKitCaptureSource clears its m_sessionSource when ended. Manually tested by muting/unmuting capture and capturing KeyNotes app/fullscreening it. * Source/WebCore/platform/mediastream/mac/ScreenCaptureKitCaptureSource.mm: (WebCore::ScreenCaptureKitCaptureSource::stop): (WebCore::ScreenCaptureKitCaptureSource::startContentStream): * Source/WebCore/platform/mediastream/mac/ScreenCaptureKitSharingSessionManager.mm: (-[WebDisplayMediaPromptHelper startObservingPicker:]): (-[WebDisplayMediaPromptHelper stopObservingPicker:]): (WebCore::ScreenCaptureKitSharingSessionManager::cancelPicking): (WebCore::ScreenCaptureKitSharingSessionManager::promptWithSCContentSharingPicker): (-[WebDisplayMediaPromptHelper hasObservingSession]): Deleted. Canonical link: https://commits.webkit.org/299161@main
1 parent ceb7560 commit ac56c26

File tree

2 files changed

+9
-17
lines changed

2 files changed

+9
-17
lines changed

Source/WebCore/platform/mediastream/mac/ScreenCaptureKitCaptureSource.mm

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,9 @@ - (void)outputVideoEffectDidStopForStream:(SCStream *)stream
262262
});
263263
[contentStream() stopCaptureWithCompletionHandler:stopHandler.get()];
264264

265-
if (m_sessionSource) {
265+
// We do not nullify m_sessionSource to keep the picker active since it is helping capture for some fullscreen cases.
266+
if (m_sessionSource)
266267
m_contentFilter = m_sessionSource->contentFilter();
267-
m_sessionSource = nullptr;
268-
}
269268
}
270269

271270
void ScreenCaptureKitCaptureSource::end()
@@ -400,9 +399,6 @@ - (void)outputVideoEffectDidStopForStream:(SCStream *)stream
400399
{
401400
ALWAYS_LOG_IF_POSSIBLE(LOGIDENTIFIER);
402401

403-
if (contentStream())
404-
return;
405-
406402
if (!m_captureHelper)
407403
m_captureHelper = adoptNS([[WebCoreScreenCaptureKitHelper alloc] initWithCallback:this]);
408404

Source/WebCore/platform/mediastream/mac/ScreenCaptureKitSharingSessionManager.mm

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ @interface WebDisplayMediaPromptHelper : NSObject <SCContentSharingSessionProtoc
6262

6363
- (instancetype)initWithCallback:(WebCore::ScreenCaptureKitSharingSessionManager*)callback;
6464
- (void)disconnect;
65-
- (BOOL)hasObservingSession;
6665
- (void)startObservingSession:(SCContentSharingSession *)session;
6766
- (void)stopObservingSession:(SCContentSharingSession *)session;
6867
- (void)sessionDidEnd:(SCContentSharingSession *)session;
@@ -97,11 +96,6 @@ - (void)disconnect
9796
_sessions.clear();
9897
}
9998

100-
- (BOOL)hasObservingSession
101-
{
102-
return _sessions.isEmpty();
103-
}
104-
10599
- (void)startObservingSession:(SCContentSharingSession *)session
106100
{
107101
ASSERT(!_sessions.contains(session));
@@ -178,6 +172,8 @@ - (void)startObservingPicker:(SCContentSharingPicker *)picker
178172
if (_observingPicker)
179173
return;
180174

175+
[picker setActive:YES];
176+
181177
_observingPicker = YES;
182178
[picker addObserver:self];
183179
}
@@ -187,6 +183,8 @@ - (void)stopObservingPicker:(SCContentSharingPicker *)picker
187183
if (!_observingPicker)
188184
return;
189185

186+
[picker setActive:NO];
187+
190188
_observingPicker = NO;
191189
[picker removeObserver:self];
192190
}
@@ -256,11 +254,10 @@ - (void)stopObservingPicker:(SCContentSharingPicker *)picker
256254
};
257255
#if HAVE(SC_CONTENT_SHARING_PICKER)
258256
if (useSCContentSharingPicker()) {
259-
RetainPtr picker = [PAL::getSCContentSharingPickerClass() sharedPicker];
260-
if (![m_promptHelper hasObservingSession])
261-
[picker setActive:NO];
262-
if (m_activeSources.isEmpty())
257+
if (m_activeSources.isEmpty()) {
258+
RetainPtr picker = [PAL::getSCContentSharingPickerClass() sharedPicker];
263259
[m_promptHelper stopObservingPicker:picker.get()];
260+
}
264261
}
265262
#endif
266263

@@ -473,7 +470,6 @@ - (void)stopObservingPicker:(SCContentSharingPicker *)picker
473470
RetainPtr picker = [PAL::getSCContentSharingPickerClass() sharedPicker];
474471
[picker setDefaultConfiguration:configuration.get()];
475472
[picker setMaximumStreamCount:@(std::numeric_limits<unsigned>::max())];
476-
[picker setActive:YES];
477473
[m_promptHelper startObservingPicker:picker.get()];
478474

479475
if (shareableContentStyle != SCShareableContentStyleNone && [picker respondsToSelector:@selector(presentPickerUsingContentStyle:)])

0 commit comments

Comments
 (0)