getUserMedia capture changes on iOS after homing out
authoryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 14 May 2019 19:30:19 +0000 (19:30 +0000)
committeryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 14 May 2019 19:30:19 +0000 (19:30 +0000)
https://bugs.webkit.org/show_bug.cgi?id=197707

Reviewed by Eric Carlson.

In case of muting an AVVideoCaptureSource on iOS, the session is cleared.
We need to store the preset information, to setup the new session on unnmuting correctly.
Manually tested.

* platform/mediastream/mac/AVVideoCaptureSource.h:
* platform/mediastream/mac/AVVideoCaptureSource.mm:
(WebCore::AVVideoCaptureSource::setSizeAndFrameRateWithPreset):
(WebCore::AVVideoCaptureSource::setSessionSizeAndFrameRate):
(WebCore::AVVideoCaptureSource::setupCaptureSession):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@245296 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/mediastream/RealtimeVideoSource.cpp
Source/WebCore/platform/mediastream/RealtimeVideoSource.h
Source/WebCore/platform/mediastream/mac/AVVideoCaptureSource.h
Source/WebCore/platform/mediastream/mac/AVVideoCaptureSource.mm
Source/WebCore/platform/mock/MockRealtimeVideoSource.cpp
Source/WebCore/platform/mock/MockRealtimeVideoSource.h

index b244766..24993f0 100644 (file)
@@ -1,3 +1,20 @@
+2019-05-14  Youenn Fablet  <youenn@apple.com>
+
+        getUserMedia capture changes on iOS after homing out
+        https://bugs.webkit.org/show_bug.cgi?id=197707
+
+        Reviewed by Eric Carlson.
+
+        In case of muting an AVVideoCaptureSource on iOS, the session is cleared.
+        We need to store the preset information, to setup the new session on unnmuting correctly.
+        Manually tested.
+
+        * platform/mediastream/mac/AVVideoCaptureSource.h:
+        * platform/mediastream/mac/AVVideoCaptureSource.mm:
+        (WebCore::AVVideoCaptureSource::setSizeAndFrameRateWithPreset):
+        (WebCore::AVVideoCaptureSource::setSessionSizeAndFrameRate):
+        (WebCore::AVVideoCaptureSource::setupCaptureSession):
+
 2019-05-14  Oriol Brufau  <obrufau@igalia.com>
 
         [css-grid] Update grid when changing auto repeat type
index ada1ec3..f24e008 100644 (file)
@@ -366,7 +366,7 @@ void RealtimeVideoSource::setSizeAndFrameRate(Optional<int> width, Optional<int>
     if (!match)
         return;
 
-    setSizeAndFrameRateWithPreset(match->requestedSize, match->requestedFrameRate, match->encodingPreset);
+    setFrameRateWithPreset(match->requestedFrameRate, match->encodingPreset);
 
     if (!match->requestedSize.isEmpty())
         setSize(match->requestedSize);
index 99bacbe..1a17938 100644 (file)
@@ -51,7 +51,7 @@ protected:
 
     virtual void generatePresets() = 0;
     virtual bool prefersPreset(VideoPreset&) { return true; }
-    virtual void setSizeAndFrameRateWithPreset(IntSize, double, RefPtr<VideoPreset>) { };
+    virtual void setFrameRateWithPreset(double, RefPtr<VideoPreset>) { };
     virtual bool canResizeVideoFrames() const { return false; }
     bool shouldUsePreset(VideoPreset& current, VideoPreset& candidate);
 
index 417a73b..5d6cb1e 100644 (file)
@@ -91,11 +91,12 @@ private:
     CaptureDevice::DeviceType deviceType() const final { return CaptureDevice::DeviceType::Camera; }
     bool interrupted() const final;
 
-    void setSizeAndFrameRateWithPreset(IntSize, double, RefPtr<VideoPreset>) final;
+    void setFrameRateWithPreset(double, RefPtr<VideoPreset>) final;
     bool prefersPreset(VideoPreset&) final;
     void generatePresets() final;
     bool canResizeVideoFrames() const final { return true; }
 
+    void setSessionSizeAndFrameRate();
     bool setPreset(NSString*);
     void computeSampleRotation();
     AVFrameRateRange* frameDurationForFrameRate(double);
@@ -127,12 +128,11 @@ private:
     RetainPtr<WebCoreAVVideoCaptureSourceObserver> m_objcObserver;
     RetainPtr<AVCaptureSession> m_session;
     RetainPtr<AVCaptureDevice> m_device;
-    RefPtr<VideoPreset> m_pendingPreset;
 
     Lock m_presetMutex;
     RefPtr<AVVideoPreset> m_currentPreset;
-    IntSize m_pendingSize;
-    double m_pendingFrameRate;
+    IntSize m_currentSize;
+    double m_currentFrameRate;
     InterruptionReason m_interruption { InterruptionReason::None };
     int m_framesToDropAtStartup { 0 };
     bool m_isRunning { false };
index a537643..3cdca30 100644 (file)
@@ -283,22 +283,23 @@ bool AVVideoCaptureSource::prefersPreset(VideoPreset& preset)
     return true;
 }
 
-void AVVideoCaptureSource::setSizeAndFrameRateWithPreset(IntSize requestedSize, double requestedFrameRate, RefPtr<VideoPreset> preset)
+void AVVideoCaptureSource::setFrameRateWithPreset(double requestedFrameRate, RefPtr<VideoPreset> preset)
 {
-    ALWAYS_LOG_IF(loggerPtr(), LOGIDENTIFIER, SizeAndFrameRate { requestedSize.width(), requestedSize.height(), requestedFrameRate });
+    ALWAYS_LOG_IF(loggerPtr(), LOGIDENTIFIER, SizeAndFrameRate { preset->size.width(), preset->size.height(), requestedFrameRate });
 
     auto* avPreset = preset ? downcast<AVVideoPreset>(preset.get()) : nullptr;
+    m_currentPreset = avPreset;
+    m_currentFrameRate = requestedFrameRate;
 
-    if (!m_session) {
-        m_pendingPreset = avPreset;
-        m_pendingSize = requestedSize;
-        m_pendingFrameRate = requestedFrameRate;
-        return;
-    }
+    setSessionSizeAndFrameRate();
+}
 
-    m_pendingPreset = nullptr;
-    m_pendingFrameRate = 0;
+void AVVideoCaptureSource::setSessionSizeAndFrameRate()
+{
+    if (!m_session)
+        return;
 
+    auto* avPreset = m_currentPreset.get();
     if (!avPreset)
         return;
 
@@ -308,29 +309,29 @@ void AVVideoCaptureSource::setSizeAndFrameRateWithPreset(IntSize requestedSize,
     [m_session beginConfiguration];
     @try {
         if ([device() lockForConfiguration:&error]) {
-            if (!m_currentPreset || ![m_currentPreset->format.get() isEqual:avPreset->format.get()]) {
-                [device() setActiveFormat:avPreset->format.get()];
+            ALWAYS_LOG_IF(loggerPtr(), LOGIDENTIFIER, "setting preset to ", m_currentSize);
+            [device() setActiveFormat:avPreset->format.get()];
 
 #if PLATFORM(MAC)
-                auto settingsDictionary = @{
-                    (__bridge NSString *)kCVPixelBufferPixelFormatTypeKey: @(avVideoCapturePixelBufferFormat()),
-                    (__bridge NSString *)kCVPixelBufferWidthKey: @(avPreset->size.width()),
-                    (__bridge NSString *)kCVPixelBufferHeightKey: @(avPreset->size.height()),
-                    (__bridge NSString *)kCVPixelBufferIOSurfacePropertiesKey : @{ }
-                };
-                [m_videoOutput setVideoSettings:settingsDictionary];
+            auto settingsDictionary = @{
+                (__bridge NSString *)kCVPixelBufferPixelFormatTypeKey: @(avVideoCapturePixelBufferFormat()),
+                (__bridge NSString *)kCVPixelBufferWidthKey: @(avPreset->size.width()),
+                (__bridge NSString *)kCVPixelBufferHeightKey: @(avPreset->size.height()),
+                (__bridge NSString *)kCVPixelBufferIOSurfacePropertiesKey : @{ }
+            };
+            [m_videoOutput setVideoSettings:settingsDictionary];
 #endif
-            }
-            auto* frameRateRange = frameDurationForFrameRate(requestedFrameRate);
+
+            auto* frameRateRange = frameDurationForFrameRate(m_currentFrameRate);
             ASSERT(frameRateRange);
             if (!frameRateRange)
                 return;
 
-            requestedFrameRate = clampTo(requestedFrameRate, frameRateRange.minFrameRate, frameRateRange.maxFrameRate);
+            m_currentFrameRate = clampTo(m_currentFrameRate, frameRateRange.minFrameRate, frameRateRange.maxFrameRate);
 
-            ALWAYS_LOG_IF(loggerPtr(), LOGIDENTIFIER, "setting frame rate to ", requestedFrameRate);
-            [device() setActiveVideoMinFrameDuration: CMTimeMake(1, requestedFrameRate)];
-            [device() setActiveVideoMaxFrameDuration: CMTimeMake(1, requestedFrameRate)];
+            ALWAYS_LOG_IF(loggerPtr(), LOGIDENTIFIER, "setting frame rate to ", m_currentFrameRate);
+            [device() setActiveVideoMinFrameDuration: CMTimeMake(1, m_currentFrameRate)];
+            [device() setActiveVideoMaxFrameDuration: CMTimeMake(1, m_currentFrameRate)];
 
             [device() unlockForConfiguration];
         }
@@ -340,8 +341,6 @@ void AVVideoCaptureSource::setSizeAndFrameRateWithPreset(IntSize requestedSize,
     }
     [m_session commitConfiguration];
 
-    m_currentPreset = avPreset;
-
     ERROR_LOG_IF(error && loggerPtr(), LOGIDENTIFIER, [[error localizedDescription] UTF8String]);
 }
 
@@ -448,8 +447,7 @@ bool AVVideoCaptureSource::setupCaptureSession()
     }
     [session() addOutput:m_videoOutput.get()];
 
-    if (m_pendingPreset || m_pendingFrameRate)
-        setSizeAndFrameRateWithPreset(m_pendingSize, m_pendingFrameRate, m_pendingPreset);
+    setSessionSizeAndFrameRate();
 
     m_sensorOrientation = sensorOrientationFromVideoOutput(m_videoOutput.get());
     computeSampleRotation();
index f13c5b5..36d8c75 100644 (file)
@@ -181,9 +181,9 @@ const RealtimeMediaSourceSettings& MockRealtimeVideoSource::settings()
     return m_currentSettings.value();
 }
 
-void MockRealtimeVideoSource::setSizeAndFrameRateWithPreset(IntSize, double, RefPtr<VideoPreset> preset)
+void MockRealtimeVideoSource::setFrameRateWithPreset(double, RefPtr<VideoPreset> preset)
 {
-    m_preset = preset;
+    m_preset = WTFMove(preset);
     if (preset)
         setIntrinsicSize(preset->size);
 }
index 3c7e29e..866c1b0 100644 (file)
@@ -71,7 +71,7 @@ private:
     CaptureDevice::DeviceType deviceType() const final { return CaptureDevice::DeviceType::Camera; }
     bool supportsSizeAndFrameRate(Optional<int> width, Optional<int> height, Optional<double>) final;
     void setSizeAndFrameRate(Optional<int> width, Optional<int> height, Optional<double>) final;
-    void setSizeAndFrameRateWithPreset(IntSize, double, RefPtr<VideoPreset>) final;
+    void setFrameRateWithPreset(double, RefPtr<VideoPreset>) final;
     IntSize captureSize() const;
 
     void generatePresets() final;