Skip to content

Commit

Permalink
[iOS] AVVideoCaptureSource is not handling the case of another applic…
Browse files Browse the repository at this point in the history
…ation changing the device videoZoomFactor

https://bugs.webkit.org/show_bug.cgi?id=271643
rdar://125351159

Reviewed by Eric Carlson.

When another application is changing the device zoom, it got access to the device so AVVideoCaptureSource is not running.
When AVVideoCaptureSource restarts, we just have to reapply the device zoom.

Remove AVVideoCaptureSource::m_appliedZoom since the device videoZoomFactor can change when other iOS apps get access to the camera.
We thus always compare the zoom to be applied with the device zoom.

* Source/WebCore/platform/mediastream/mac/AVVideoCaptureSource.h:
* Source/WebCore/platform/mediastream/mac/AVVideoCaptureSource.mm:
(WebCore::AVVideoCaptureSource::setSessionSizeFrameRateAndZoom):

Canonical link: https://commits.webkit.org/276731@main
  • Loading branch information
youennf committed Mar 27, 2024
1 parent 6299ee9 commit ca83b80
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class AVVideoCaptureSource : public RealtimeVideoCaptureSource, private Orientat
void orientationChanged(IntDegrees orientation) final;

bool setFrameRateConstraint(double minFrameRate, double maxFrameRate);
bool areSettingsMatching(AVFrameRateRange*) const;

IntSize sizeForPreset(NSString*);

Expand Down Expand Up @@ -171,7 +172,6 @@ class AVVideoCaptureSource : public RealtimeVideoCaptureSource, private Orientat
std::optional<VideoPreset> m_currentPreset;
std::optional<VideoPreset> m_appliedPreset;
RetainPtr<AVFrameRateRange> m_appliedFrameRateRange;
double m_appliedZoom { 1 };

double m_currentFrameRate;
double m_currentZoom { 1 };
Expand Down
14 changes: 11 additions & 3 deletions Source/WebCore/platform/mediastream/mac/AVVideoCaptureSource.mm
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,15 @@ static bool isSameFrameRateRange(AVFrameRateRange* a, AVFrameRateRange* b)
return a.minFrameRate == b.minFrameRate && a.maxFrameRate == b.maxFrameRate && !PAL::CMTimeCompare(a.minFrameDuration, b.minFrameDuration) && !PAL::CMTimeCompare(a.maxFrameDuration, b.maxFrameDuration);
}

bool AVVideoCaptureSource::areSettingsMatching(AVFrameRateRange* frameRateRange) const
{
return m_appliedPreset && m_appliedPreset->format() == m_currentPreset->format() &&
#if PLATFORM(IOS_FAMILY)
device().videoZoomFactor == m_currentZoom &&
#endif
isSameFrameRateRange(m_appliedFrameRateRange.get(), frameRateRange);
}

void AVVideoCaptureSource::setSessionSizeFrameRateAndZoom()
{
ASSERT(m_beginConfigurationCount);
Expand All @@ -805,7 +814,7 @@ static bool isSameFrameRateRange(AVFrameRateRange* a, AVFrameRateRange* b)
auto* frameRateRange = frameDurationForFrameRate(m_currentFrameRate);
ASSERT(frameRateRange);

if (m_appliedPreset && m_appliedPreset->format() == m_currentPreset->format() && isSameFrameRateRange(m_appliedFrameRateRange.get(), frameRateRange) && m_appliedZoom == m_currentZoom) {
if (areSettingsMatching(frameRateRange)) {
ALWAYS_LOG_IF(loggerPtr(), LOGIDENTIFIER, " settings already match");
return;
}
Expand Down Expand Up @@ -846,10 +855,9 @@ static bool isSameFrameRateRange(AVFrameRateRange* a, AVFrameRateRange* b)
ERROR_LOG_IF(loggerPtr(), LOGIDENTIFIER, "cannot find proper frame rate range for the selected preset\n");

#if PLATFORM(IOS_FAMILY)
if (m_currentZoom != m_appliedZoom) {
if (m_currentZoom != device().videoZoomFactor) {
ALWAYS_LOG_IF(loggerPtr(), LOGIDENTIFIER, "setting zoom to ", m_currentZoom);
[device() setVideoZoomFactor:m_currentZoom];
m_appliedZoom = m_currentZoom;
}
#endif

Expand Down

0 comments on commit ca83b80

Please sign in to comment.