[MediaStream] AVVideoCaptureSource reports incorrect size when frames are scaled
authoreric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 9 Nov 2018 21:26:16 +0000 (21:26 +0000)
committereric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 9 Nov 2018 21:26:16 +0000 (21:26 +0000)
https://bugs.webkit.org/show_bug.cgi?id=191479
<rdar://problem/45952201>

Reviewed by Jer Noble.

No new tests, tested manually.

* platform/mediastream/RealtimeVideoSource.cpp:
(WebCore::RealtimeVideoSource::standardVideoSizes): Drive-by fix: add a few more standard
video frame sizes, correct a typo.
(WebCore::RealtimeVideoSource::bestSupportedSizeAndFrameRate): Drive-by fix: don't consider
rescaled sized when we already have an exact or aspect ratio match because it won't be used.

* platform/mediastream/mac/AVVideoCaptureSource.h:
(WebCore::AVVideoCaptureSource::width const): Deleted.
(WebCore::AVVideoCaptureSource::height const): Deleted.
* platform/mediastream/mac/AVVideoCaptureSource.mm:
(WebCore::AVVideoCaptureSource::setSizeAndFrameRateWithPreset): Delete m_requestedSize.
(WebCore::AVVideoCaptureSource::shutdownCaptureSession): Delete m_width and m_height.
(WebCore::AVVideoCaptureSource::processNewFrame): Don't call setSize with captured size,
the frame may be resized before deliver.

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

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

index 79dcdd5..bb3987e 100644 (file)
@@ -1,3 +1,28 @@
+2018-11-09  Eric Carlson  <eric.carlson@apple.com>
+
+        [MediaStream] AVVideoCaptureSource reports incorrect size when frames are scaled
+        https://bugs.webkit.org/show_bug.cgi?id=191479
+        <rdar://problem/45952201>
+
+        Reviewed by Jer Noble.
+
+        No new tests, tested manually.
+
+        * platform/mediastream/RealtimeVideoSource.cpp:
+        (WebCore::RealtimeVideoSource::standardVideoSizes): Drive-by fix: add a few more standard
+        video frame sizes, correct a typo.
+        (WebCore::RealtimeVideoSource::bestSupportedSizeAndFrameRate): Drive-by fix: don't consider
+        rescaled sized when we already have an exact or aspect ratio match because it won't be used.
+
+        * platform/mediastream/mac/AVVideoCaptureSource.h:
+        (WebCore::AVVideoCaptureSource::width const): Deleted.
+        (WebCore::AVVideoCaptureSource::height const): Deleted.
+        * platform/mediastream/mac/AVVideoCaptureSource.mm:
+        (WebCore::AVVideoCaptureSource::setSizeAndFrameRateWithPreset): Delete m_requestedSize.
+        (WebCore::AVVideoCaptureSource::shutdownCaptureSession): Delete m_width and m_height.
+        (WebCore::AVVideoCaptureSource::processNewFrame): Don't call setSize with captured size,
+        the frame may be resized before deliver.
+
 2018-11-09  Ross Kirsling  <ross.kirsling@sony.com>
 
         Unreviewed MSVC build fix after r238039 (and r238046).
index 0b4a6ed..4f59a60 100644 (file)
@@ -103,20 +103,21 @@ const Vector<IntSize>& RealtimeVideoSource::standardVideoSizes()
             { 112, 112 },
             { 160, 160 },
             { 160, 120 }, // 4:3, QQVGA
+            { 176, 144 }, // 4:3, QCIF
             { 192, 192 },
             { 192, 112 }, // 16:9
             { 192, 144 }, // 3:4
             { 240, 240 },
             { 240, 160 }, // 3:2, HQVGA
             { 320, 320 },
-            { 320, 176 }, // 16:9
+            { 320, 180 }, // 16:9
             { 320, 240 }, // 4:3, QVGA
             { 352, 288 }, // CIF
             { 480, 272 }, // 16:9
             { 480, 360 }, // 4:3
             { 480, 480 },
             { 640, 640 },
-            { 640, 368 }, // 16:9
+            { 640, 360 }, // 16:9, 360p nHD
             { 640, 480 }, // 4:3
             { 720, 720 },
             { 800, 600 }, // 4:3, SVGA
@@ -127,7 +128,8 @@ const Vector<IntSize>& RealtimeVideoSource::standardVideoSizes()
             { 1280, 1024 }, // 5:4, SXGA
             { 1280, 720 }, // 16:9, WXGA
             { 1366, 768 }, // 16:9, HD
-            { 1920, 1080 }, // 16:9, FHD
+            { 1600, 1200}, // 4:3, UXGA
+            { 1920, 1080 }, // 16:9, 1080p FHD
             { 2560, 1440 }, // 16:9, QHD
             { 2592, 1936 },
             { 3264, 2448 }, // 3:4
@@ -301,6 +303,9 @@ std::optional<RealtimeVideoSource::CaptureSizeAndFrameRate> RealtimeVideoSource:
             }
         }
 
+        if (exactSizePreset || aspectRatioPreset)
+            continue;
+
         if (requestedWidth && requestedHeight) {
             const auto& minStandardSize = standardVideoSizes()[0];
             if (requestedWidth.value() >= minStandardSize.width() && requestedHeight.value() >= minStandardSize.height()) {
index 3c1b02c..653c8de 100644 (file)
@@ -57,9 +57,6 @@ public:
 
     WEBCORE_EXPORT static VideoCaptureFactory& factory();
 
-    int32_t width() const { return m_width; }
-    int32_t height() const { return m_height; }
-
     enum class InterruptionReason { None, VideoNotAllowedInBackground, AudioInUse, VideoInUse, VideoNotAllowedInSideBySide };
     void captureSessionBeginInterruption(RetainPtr<NSNotification>);
     void captureSessionEndInterruption(RetainPtr<NSNotification>);
@@ -112,9 +109,6 @@ private:
     RetainPtr<AVCaptureVideoDataOutput> m_videoOutput;
     std::unique_ptr<ImageTransferSessionVT> m_imageTransferSession;
 
-    IntSize m_requestedSize;
-    int32_t m_width { 0 };
-    int32_t m_height { 0 };
     int m_sensorOrientation { 0 };
     int m_deviceOrientation { 0 };
     MediaSample::VideoRotation m_sampleRotation { MediaSample::VideoRotation::None };
index 83afed7..198148c 100644 (file)
@@ -331,8 +331,6 @@ void AVVideoCaptureSource::setSizeAndFrameRateWithPreset(IntSize requestedSize,
 
     ASSERT(avPreset->format);
 
-    m_requestedSize = requestedSize;
-
     NSError *error = nil;
     [m_session beginConfiguration];
     @try {
@@ -474,8 +472,6 @@ bool AVVideoCaptureSource::setupCaptureSession()
 void AVVideoCaptureSource::shutdownCaptureSession()
 {
     m_buffer = nullptr;
-    m_width = 0;
-    m_height = 0;
 }
 
 void AVVideoCaptureSource::monitorOrientation(OrientationNotifier& notifier)
@@ -525,16 +521,6 @@ void AVVideoCaptureSource::processNewFrame(Ref<MediaSample>&& sample)
         return;
 
     m_buffer = &sample.get();
-    auto dimensions = roundedIntSize(sample->presentationSize());
-    if (m_sampleRotation == MediaSample::VideoRotation::Left || m_sampleRotation == MediaSample::VideoRotation::Right)
-        dimensions = { dimensions.height(), dimensions.width() };
-
-    if (dimensions.width() != m_width || dimensions.height() != m_height) {
-        m_width = dimensions.width();
-        m_height = dimensions.height();
-        setSize(dimensions);
-    }
-
     dispatchMediaSampleToObservers(WTFMove(sample));
 }