Skip to content

Commit

Permalink
Fixed video capturing on Mac.
Browse files Browse the repository at this point in the history
On specific Macbooks (no exact pattern, unfortunately),
video from an integrated camera is not captured.
Changed AVCaptureVideoDataOutput pixel format configuration
as in Chromium which solved the problem.
https://chromium.googlesource.com/chromium/src/media/+/master/capture/video/mac/video_capture_device_avfoundation_mac.mm
FourCharCode best_fourcc = kCVPixelFormatType_422YpCbCr8;

Tested with external cameras as well.

Bug: webrtc:8958
Change-Id: Ib99382b38d1914e2963761a33df310024524c9a4
Reviewed-on: https://webrtc-review.googlesource.com/58880
Commit-Queue: Magnus Jedvert <[email protected]>
Reviewed-by: Magnus Jedvert <[email protected]>
Reviewed-by: Per Kjellander <[email protected]>
Cr-Commit-Position: refs/heads/master@{#22709}
  • Loading branch information
MMX777 authored and Commit Bot committed Apr 3, 2018
1 parent 8487988 commit 3cfe9e1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Jens Nielsen <[email protected]>
Jiawei Ou <[email protected]>
Jie Mao <[email protected]>
Luke Weber <[email protected]>
Maksim Khobat <[email protected]>
Mallikarjuna Rao V <[email protected]>
Manish Jethani <[email protected]>
Martin Storsjo <[email protected]>
Expand Down
21 changes: 8 additions & 13 deletions modules/video_capture/objc/rtc_video_capture_objc.mm
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ - (id)initWithOwner:(VideoCaptureIos*)owner {
AVCaptureVideoDataOutput* captureOutput = [[AVCaptureVideoDataOutput alloc] init];
NSString* key = (NSString*)kCVPixelBufferPixelFormatTypeKey;

NSNumber* val = [NSNumber numberWithUnsignedInt:kCVPixelFormatType_420YpCbCr8BiPlanarFullRange];
NSNumber* val = [NSNumber numberWithUnsignedInt:kCVPixelFormatType_422YpCbCr8];
NSDictionary* videoSettings = [NSDictionary dictionaryWithObject:val forKey:key];
captureOutput.videoSettings = videoSettings;

Expand Down Expand Up @@ -319,21 +319,16 @@ - (void)captureOutput:(AVCaptureOutput*)captureOutput
return;
}

const int kYPlaneIndex = 0;
const int kUVPlaneIndex = 1;

uint8_t* baseAddress = (uint8_t*)CVPixelBufferGetBaseAddressOfPlane(videoFrame, kYPlaneIndex);
size_t yPlaneBytesPerRow = CVPixelBufferGetBytesPerRowOfPlane(videoFrame, kYPlaneIndex);
size_t yPlaneHeight = CVPixelBufferGetHeightOfPlane(videoFrame, kYPlaneIndex);
size_t uvPlaneBytesPerRow = CVPixelBufferGetBytesPerRowOfPlane(videoFrame, kUVPlaneIndex);
size_t uvPlaneHeight = CVPixelBufferGetHeightOfPlane(videoFrame, kUVPlaneIndex);
size_t frameSize = yPlaneBytesPerRow * yPlaneHeight + uvPlaneBytesPerRow * uvPlaneHeight;
uint8_t* baseAddress = (uint8_t*)CVPixelBufferGetBaseAddress(videoFrame);
const size_t width = CVPixelBufferGetWidth(videoFrame);
const size_t height = CVPixelBufferGetHeight(videoFrame);
const size_t frameSize = width * height * 2;

VideoCaptureCapability tempCaptureCapability;
tempCaptureCapability.width = CVPixelBufferGetWidth(videoFrame);
tempCaptureCapability.height = CVPixelBufferGetHeight(videoFrame);
tempCaptureCapability.width = width;
tempCaptureCapability.height = height;
tempCaptureCapability.maxFPS = _capability.maxFPS;
tempCaptureCapability.videoType = VideoType::kNV12;
tempCaptureCapability.videoType = VideoType::kUYVY;

_owner->IncomingFrame(baseAddress, frameSize, tempCaptureCapability, 0);

Expand Down

0 comments on commit 3cfe9e1

Please sign in to comment.