Changeset 209188 in webkit


Ignore:
Timestamp:
Dec 1, 2016 11:27:25 AM (7 years ago)
Author:
eric.carlson@apple.com
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.

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r209187 r209188  
     12016-12-01  Eric Carlson  <eric.carlson@apple.com>
     2
     3        [MediaStream][Mac] Video presets sometimes don't work
     4        https://bugs.webkit.org/show_bug.cgi?id=165214
     5        <rdar://problem/29444533>
     6
     7        Reviewed by Jer Noble.
     8
     9        * platform/mediastream/mac/AVVideoCaptureSource.h:
     10        * platform/mediastream/mac/AVVideoCaptureSource.mm:
     11        (WebCore::AVVideoCaptureSource::setPreset): Set videoSettings width and height.
     12        (WebCore::AVVideoCaptureSource::setupCaptureSession): Store videoSettings object for later use.
     13          Set videoSettings width and height.
     14        (WebCore::AVVideoCaptureSource::bestSessionPresetForVideoDimensions):
     15        (WebCore::AVVideoCaptureSource::sizeForPreset): New.
     16
    1172016-12-01  Antoine Quint  <graouts@apple.com>
    218
  • trunk/Source/WebCore/platform/mediastream/mac/AVVideoCaptureSource.h

    r208985 r209188  
    8787    RetainPtr<CMSampleBufferRef> m_buffer;
    8888    RetainPtr<CGImageRef> m_lastImage;
     89    RetainPtr<AVCaptureVideoDataOutput> m_videoOutput;
    8990
    9091    Vector<Float64> m_videoFrameTimeStamps;
  • trunk/Source/WebCore/platform/mediastream/mac/AVVideoCaptureSource.mm

    r209141 r209188  
    334334}
    335335
     336static IntSize sizeForPreset(NSString* preset)
     337{
     338    if (!preset)
     339        return { };
     340
     341    if ([preset isEqualToString:AVCaptureSessionPreset1280x720])
     342        return { 1280, 720 };
     343
     344    if ([preset isEqualToString:AVCaptureSessionPreset960x540])
     345        return { 960, 540 };
     346
     347    if ([preset isEqualToString:AVCaptureSessionPreset640x480])
     348        return { 640, 480 };
     349
     350    if ([preset isEqualToString:AVCaptureSessionPreset352x288])
     351        return { 352, 288 };
     352
     353    if ([preset isEqualToString:AVCaptureSessionPreset320x240])
     354        return { 320, 240 };
     355   
     356    return { };
     357   
     358}
     359
    336360bool AVVideoCaptureSource::setPreset(NSString *preset)
    337361{
     
    340364        return true;
    341365    }
    342     m_pendingPreset = nullptr;
    343     if (!preset)
     366
     367    auto size = sizeForPreset(preset);
     368    if (size.width() == m_width && size.height() == m_height)
    344369        return true;
    345370
    346371    @try {
    347372        session().sessionPreset = preset;
     373#if PLATFORM(MAC)
     374        auto settingsDictionary = @{ (NSString*)kCVPixelBufferPixelFormatTypeKey: @(videoCaptureFormat), (NSString*)kCVPixelBufferWidthKey: @(size.width()), (NSString*)kCVPixelBufferHeightKey: @(size.height()), };
     375        [m_videoOutput setVideoSettings:settingsDictionary];
     376#endif
    348377    } @catch(NSException *exception) {
    349378        LOG(Media, "AVVideoCaptureSource::applySize(%p), exception thrown configuring device: <%s> %s", this, [[exception name] UTF8String], [[exception reason] UTF8String]);
     
    399428void AVVideoCaptureSource::setupCaptureSession()
    400429{
    401     if (m_pendingPreset)
    402         setPreset(m_pendingPreset.get());
    403 
    404430    NSError *error = nil;
    405431    RetainPtr<AVCaptureDeviceInputType> videoIn = adoptNS([allocAVCaptureDeviceInputInstance() initWithDevice:device() error:&error]);
     
    415441    [session() addInput:videoIn.get()];
    416442
    417     RetainPtr<AVCaptureVideoDataOutputType> videoOutput = adoptNS([allocAVCaptureVideoDataOutputInstance() init]);
    418     RetainPtr<NSDictionary> settingsDictionary = adoptNS([[NSDictionary alloc] initWithObjectsAndKeys: [NSNumber numberWithInt:videoCaptureFormat], kCVPixelBufferPixelFormatTypeKey, nil]);
    419     [videoOutput setVideoSettings:settingsDictionary.get()];
    420     [videoOutput setAlwaysDiscardsLateVideoFrames:YES];
    421     setVideoSampleBufferDelegate(videoOutput.get());
    422 
    423     if (![session() canAddOutput:videoOutput.get()]) {
     443    m_videoOutput = adoptNS([allocAVCaptureVideoDataOutputInstance() init]);
     444    auto settingsDictionary = adoptNS([[NSMutableDictionary alloc] initWithObjectsAndKeys: [NSNumber numberWithInt:videoCaptureFormat], kCVPixelBufferPixelFormatTypeKey, nil]);
     445    if (m_pendingPreset) {
     446#if PLATFORM(MAC)
     447        auto size = sizeForPreset(m_pendingPreset.get());
     448        [settingsDictionary.get() setObject:[NSNumber numberWithInt:size.width()] forKey:(NSString*)kCVPixelBufferWidthKey];
     449        [settingsDictionary.get() setObject:[NSNumber numberWithInt:size.height()] forKey:(NSString*)kCVPixelBufferHeightKey];
     450#endif
     451    }
     452
     453    [m_videoOutput setVideoSettings:settingsDictionary.get()];
     454    [m_videoOutput setAlwaysDiscardsLateVideoFrames:YES];
     455    setVideoSampleBufferDelegate(m_videoOutput.get());
     456
     457    if (![session() canAddOutput:m_videoOutput.get()]) {
    424458        LOG(Media, "AVVideoCaptureSource::setupCaptureSession(%p), unable to add video sample buffer output delegate", this);
    425459        return;
    426460    }
    427     [session() addOutput:videoOutput.get()];
     461    [session() addOutput:m_videoOutput.get()];
     462
     463#if PLATFORM(IOS)
     464    setPreset(m_pendingPreset.get());
     465#endif
     466
    428467}
    429468
     
    568607}
    569608
    570 NSString *AVVideoCaptureSource::bestSessionPresetForVideoDimensions(std::optional<int> width, std::optional<int> height) const
     609NSString* AVVideoCaptureSource::bestSessionPresetForVideoDimensions(std::optional<int> width, std::optional<int> height) const
    571610{
    572611    if (!width && !height)
Note: See TracChangeset for help on using the changeset viewer.