From 0b7bd756593105b2aa198bdcf03dea7c0f2a884a Mon Sep 17 00:00:00 2001 From: magjed Date: Mon, 9 Jan 2017 07:09:23 -0800 Subject: [PATCH] AVFoundationVideoCapturer: Fix apply_rotation() logic When apply_rotation() returns true, rotation and captured width/heigh are not set correctly. BUG=webrtc:6925 Review-Url: https://codereview.webrtc.org/2611113003 Cr-Commit-Position: refs/heads/master@{#15963} --- .../Classes/avfoundationvideocapturer.mm | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/webrtc/sdk/objc/Framework/Classes/avfoundationvideocapturer.mm b/webrtc/sdk/objc/Framework/Classes/avfoundationvideocapturer.mm index 28ae3f2bd4..cecb13cdb9 100644 --- a/webrtc/sdk/objc/Framework/Classes/avfoundationvideocapturer.mm +++ b/webrtc/sdk/objc/Framework/Classes/avfoundationvideocapturer.mm @@ -131,8 +131,8 @@ void AVFoundationVideoCapturer::CaptureSampleBuffer( return; } - const int captured_width = CVPixelBufferGetWidth(image_buffer); - const int captured_height = CVPixelBufferGetHeight(image_buffer); + int captured_width = CVPixelBufferGetWidth(image_buffer); + int captured_height = CVPixelBufferGetHeight(image_buffer); int adapted_width; int adapted_height; @@ -161,10 +161,14 @@ void AVFoundationVideoCapturer::CaptureSampleBuffer( // not critical here. if (apply_rotation() && rotation != kVideoRotation_0) { buffer = buffer->NativeToI420Buffer(); - rtc::scoped_refptr rotated_buffer = - (rotation == kVideoRotation_180) - ? I420Buffer::Create(adapted_width, adapted_height) - : I420Buffer::Create(adapted_height, adapted_width); + rtc::scoped_refptr rotated_buffer; + if (rotation == kVideoRotation_0 || rotation == kVideoRotation_180) { + rotated_buffer = I420Buffer::Create(adapted_width, adapted_height); + } else { + // Swap width and height. + rotated_buffer = I420Buffer::Create(adapted_height, adapted_width); + std::swap(captured_width, captured_height); + } libyuv::I420Rotate( buffer->DataY(), buffer->StrideY(), buffer->DataU(), buffer->StrideU(), @@ -175,6 +179,7 @@ void AVFoundationVideoCapturer::CaptureSampleBuffer( buffer->width(), buffer->height(), static_cast(rotation)); buffer = rotated_buffer; + rotation = kVideoRotation_0; } OnFrame(webrtc::VideoFrame(buffer, rotation, translated_camera_time_us),