Skip to content

Commit

Permalink
Fix: Front Camera Issue in iOS
Browse files Browse the repository at this point in the history
Original patch from BradLarson#70.
With a little fix for mirrored output of front camera.
  • Loading branch information
ShivaHuang committed Mar 15, 2017
1 parent 8c3bdee commit 9ff481d
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions framework/Source/iOS/Camera.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public enum PhysicalCameraLocation {
// Documentation: "The front-facing camera would always deliver buffers in AVCaptureVideoOrientationLandscapeLeft and the back-facing camera would always deliver buffers in AVCaptureVideoOrientationLandscapeRight."
func imageOrientation() -> ImageOrientation {
switch self {
case .backFacing: return .landscapeRight
case .frontFacing: return .landscapeLeft
case .backFacing: return .portrait
case .frontFacing: return .portrait
}
}

Expand Down Expand Up @@ -151,6 +151,20 @@ public class Camera: NSObject, ImageSource, AVCaptureVideoDataOutputSampleBuffer
captureSession.addOutput(videoOutput)
}
captureSession.sessionPreset = sessionPreset

var captureConnection: AVCaptureConnection!
for connection in videoOutput.connections {
for port in (connection as AnyObject).inputPorts {
if (port as AnyObject).mediaType == AVMediaTypeVideo {
captureConnection = connection as? AVCaptureConnection
captureConnection.isVideoMirrored = location == .frontFacing
}
}
}

if captureConnection.isVideoOrientationSupported {
captureConnection.videoOrientation = .portrait
}
captureSession.commitConfiguration()

super.init()
Expand Down

0 comments on commit 9ff481d

Please sign in to comment.