Title: [209188] trunk/Source/WebCore
Revision
209188
Author
eric.carl...@apple.com
Date
2016-12-01 11:27:25 -0800 (Thu, 01 Dec 2016)

Log Message

[MediaStream][Mac] Video presets sometimes don't work
https://bugs.webkit.org/show_bug.cgi?id=165214
<rdar://problem/29444533>

Reviewed by Jer Noble.

* platform/mediastream/mac/AVVideoCaptureSource.h:
* platform/mediastream/mac/AVVideoCaptureSource.mm:
(WebCore::AVVideoCaptureSource::setPreset): Set videoSettings width and height.
(WebCore::AVVideoCaptureSource::setupCaptureSession): Store videoSettings object for later use.
  Set videoSettings width and height.
(WebCore::AVVideoCaptureSource::bestSessionPresetForVideoDimensions):
(WebCore::AVVideoCaptureSource::sizeForPreset): New.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (209187 => 209188)


--- trunk/Source/WebCore/ChangeLog	2016-12-01 18:41:08 UTC (rev 209187)
+++ trunk/Source/WebCore/ChangeLog	2016-12-01 19:27:25 UTC (rev 209188)
@@ -1,3 +1,19 @@
+2016-12-01  Eric Carlson  <eric.carl...@apple.com>
+
+        [MediaStream][Mac] Video presets sometimes don't work
+        https://bugs.webkit.org/show_bug.cgi?id=165214
+        <rdar://problem/29444533>
+
+        Reviewed by Jer Noble.
+
+        * platform/mediastream/mac/AVVideoCaptureSource.h:
+        * platform/mediastream/mac/AVVideoCaptureSource.mm:
+        (WebCore::AVVideoCaptureSource::setPreset): Set videoSettings width and height.
+        (WebCore::AVVideoCaptureSource::setupCaptureSession): Store videoSettings object for later use.
+          Set videoSettings width and height.
+        (WebCore::AVVideoCaptureSource::bestSessionPresetForVideoDimensions):
+        (WebCore::AVVideoCaptureSource::sizeForPreset): New.
+
 2016-12-01  Antoine Quint  <grao...@apple.com>
 
         [Modern Media Controls] Promote the "on" property from AirPlayButton to IconButton

Modified: trunk/Source/WebCore/platform/mediastream/mac/AVVideoCaptureSource.h (209187 => 209188)


--- trunk/Source/WebCore/platform/mediastream/mac/AVVideoCaptureSource.h	2016-12-01 18:41:08 UTC (rev 209187)
+++ trunk/Source/WebCore/platform/mediastream/mac/AVVideoCaptureSource.h	2016-12-01 19:27:25 UTC (rev 209188)
@@ -86,6 +86,7 @@
     RetainPtr<NSString> m_pendingPreset;
     RetainPtr<CMSampleBufferRef> m_buffer;
     RetainPtr<CGImageRef> m_lastImage;
+    RetainPtr<AVCaptureVideoDataOutput> m_videoOutput;
 
     Vector<Float64> m_videoFrameTimeStamps;
     Float64 m_frameRate { 0 };

Modified: trunk/Source/WebCore/platform/mediastream/mac/AVVideoCaptureSource.mm (209187 => 209188)


--- trunk/Source/WebCore/platform/mediastream/mac/AVVideoCaptureSource.mm	2016-12-01 18:41:08 UTC (rev 209187)
+++ trunk/Source/WebCore/platform/mediastream/mac/AVVideoCaptureSource.mm	2016-12-01 19:27:25 UTC (rev 209188)
@@ -333,6 +333,30 @@
     return setPreset(preset);
 }
 
+static IntSize sizeForPreset(NSString* preset)
+{
+    if (!preset)
+        return { };
+
+    if ([preset isEqualToString:AVCaptureSessionPreset1280x720])
+        return { 1280, 720 };
+
+    if ([preset isEqualToString:AVCaptureSessionPreset960x540])
+        return { 960, 540 };
+
+    if ([preset isEqualToString:AVCaptureSessionPreset640x480])
+        return { 640, 480 };
+
+    if ([preset isEqualToString:AVCaptureSessionPreset352x288])
+        return { 352, 288 };
+
+    if ([preset isEqualToString:AVCaptureSessionPreset320x240])
+        return { 320, 240 };
+    
+    return { };
+    
+}
+
 bool AVVideoCaptureSource::setPreset(NSString *preset)
 {
     if (!session()) {
@@ -339,12 +363,17 @@
         m_pendingPreset = preset;
         return true;
     }
-    m_pendingPreset = nullptr;
-    if (!preset)
+
+    auto size = sizeForPreset(preset);
+    if (size.width() == m_width && size.height() == m_height)
         return true;
 
     @try {
         session().sessionPreset = preset;
+#if PLATFORM(MAC)
+        auto settingsDictionary = @{ (NSString*)kCVPixelBufferPixelFormatTypeKey: @(videoCaptureFormat), (NSString*)kCVPixelBufferWidthKey: @(size.width()), (NSString*)kCVPixelBufferHeightKey: @(size.height()), };
+        [m_videoOutput setVideoSettings:settingsDictionary];
+#endif
     } @catch(NSException *exception) {
         LOG(Media, "AVVideoCaptureSource::applySize(%p), exception thrown configuring device: <%s> %s", this, [[exception name] UTF8String], [[exception reason] UTF8String]);
         return false;
@@ -398,9 +427,6 @@
 
 void AVVideoCaptureSource::setupCaptureSession()
 {
-    if (m_pendingPreset)
-        setPreset(m_pendingPreset.get());
-
     NSError *error = nil;
     RetainPtr<AVCaptureDeviceInputType> videoIn = adoptNS([allocAVCaptureDeviceInputInstance() initWithDevice:device() error:&error]);
     if (error) {
@@ -414,17 +440,30 @@
     }
     [session() addInput:videoIn.get()];
 
-    RetainPtr<AVCaptureVideoDataOutputType> videoOutput = adoptNS([allocAVCaptureVideoDataOutputInstance() init]);
-    RetainPtr<NSDictionary> settingsDictionary = adoptNS([[NSDictionary alloc] initWithObjectsAndKeys: [NSNumber numberWithInt:videoCaptureFormat], kCVPixelBufferPixelFormatTypeKey, nil]);
-    [videoOutput setVideoSettings:settingsDictionary.get()];
-    [videoOutput setAlwaysDiscardsLateVideoFrames:YES];
-    setVideoSampleBufferDelegate(videoOutput.get());
+    m_videoOutput = adoptNS([allocAVCaptureVideoDataOutputInstance() init]);
+    auto settingsDictionary = adoptNS([[NSMutableDictionary alloc] initWithObjectsAndKeys: [NSNumber numberWithInt:videoCaptureFormat], kCVPixelBufferPixelFormatTypeKey, nil]);
+    if (m_pendingPreset) {
+#if PLATFORM(MAC)
+        auto size = sizeForPreset(m_pendingPreset.get());
+        [settingsDictionary.get() setObject:[NSNumber numberWithInt:size.width()] forKey:(NSString*)kCVPixelBufferWidthKey];
+        [settingsDictionary.get() setObject:[NSNumber numberWithInt:size.height()] forKey:(NSString*)kCVPixelBufferHeightKey];
+#endif
+    }
 
-    if (![session() canAddOutput:videoOutput.get()]) {
+    [m_videoOutput setVideoSettings:settingsDictionary.get()];
+    [m_videoOutput setAlwaysDiscardsLateVideoFrames:YES];
+    setVideoSampleBufferDelegate(m_videoOutput.get());
+
+    if (![session() canAddOutput:m_videoOutput.get()]) {
         LOG(Media, "AVVideoCaptureSource::setupCaptureSession(%p), unable to add video sample buffer output delegate", this);
         return;
     }
-    [session() addOutput:videoOutput.get()];
+    [session() addOutput:m_videoOutput.get()];
+
+#if PLATFORM(IOS)
+    setPreset(m_pendingPreset.get());
+#endif
+
 }
 
 void AVVideoCaptureSource::shutdownCaptureSession()
@@ -567,7 +606,7 @@
     return AVVideoSourcePreview::create(session(), device(), this);
 }
 
-NSString *AVVideoCaptureSource::bestSessionPresetForVideoDimensions(std::optional<int> width, std::optional<int> height) const
+NSString* AVVideoCaptureSource::bestSessionPresetForVideoDimensions(std::optional<int> width, std::optional<int> height) const
 {
     if (!width && !height)
         return nil;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to