Skip to content

Commit

Permalink
Added two new properties on the camera inputs: horizontallyMirrorFron…
Browse files Browse the repository at this point in the history
…tFacingCamera and horizontallyMirrorRearFacingCamera which determine whether the camera should be mirrored in those positions. Fixed a potential issue with movie playback in the Simulator.
  • Loading branch information
BradLarson committed Aug 28, 2012
1 parent 356b09e commit 2cb7f32
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ - (void)viewDidLoad
// videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPreset1920x1080 cameraPosition:AVCaptureDevicePositionBack];

videoCamera.outputImageOrientation = UIInterfaceOrientationPortrait;
videoCamera.horizontallyMirrorFrontFacingCamera = NO;
videoCamera.horizontallyMirrorRearFacingCamera = YES;

filter = [[GPUImageSepiaFilter alloc] init];

Expand Down
4 changes: 4 additions & 0 deletions framework/Source/GPUImageMovie.m
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,11 @@ - (void)processMovieFrame:(CMSampleBufferRef)movieSampleBuffer;
CVImageBufferRef movieFrame = CMSampleBufferGetImageBuffer(movieSampleBuffer);

int bufferHeight = CVPixelBufferGetHeight(movieFrame);
#if TARGET_IPHONE_SIMULATOR
int bufferWidth = CVPixelBufferGetBytesPerRow(movieFrame) / 4; // This works around certain movie frame types on the Simulator (see https://github.com/BradLarson/GPUImage/issues/424)
#else
int bufferWidth = CVPixelBufferGetWidth(movieFrame);
#endif

CFAbsoluteTime startTime = CFAbsoluteTimeGetCurrent();

Expand Down
3 changes: 3 additions & 0 deletions framework/Source/GPUImageVideoCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
/// This determines the rotation applied to the output image, based on the source material
@property(readwrite, nonatomic) UIInterfaceOrientation outputImageOrientation;

/// These properties determine whether or not the two camera orientations should be mirrored. By default, both are NO.
@property(readwrite, nonatomic) BOOL horizontallyMirrorFrontFacingCamera, horizontallyMirrorRearFacingCamera;

@property(nonatomic, retain) id<GPUImageVideoCameraDelegate> delegate;

/// @name Initialization and teardown
Expand Down
70 changes: 58 additions & 12 deletions framework/Source/GPUImageVideoCamera.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ @interface GPUImageVideoCamera ()
dispatch_queue_t cameraProcessingQueue, audioProcessingQueue;
}

- (void)updateOrientationSendToTargets;

@end

@implementation GPUImageVideoCamera
Expand All @@ -27,6 +29,7 @@ @implementation GPUImageVideoCamera
@synthesize runBenchmark = _runBenchmark;
@synthesize outputImageOrientation = _outputImageOrientation;
@synthesize delegate = _delegate;
@synthesize horizontallyMirrorFrontFacingCamera = _horizontallyMirrorFrontFacingCamera, horizontallyMirrorRearFacingCamera = _horizontallyMirrorRearFacingCamera;

#pragma mark -
#pragma mark Initialization and teardown
Expand Down Expand Up @@ -546,32 +549,57 @@ - (void)setAudioEncodingTarget:(GPUImageMovieWriter *)newValue;
});
}

- (void)setOutputImageOrientation:(UIInterfaceOrientation)newValue;
- (void)updateOrientationSendToTargets;
{
runSynchronouslyOnVideoProcessingQueue(^{
_outputImageOrientation = newValue;

// From the iOS 5.0 release notes:
// In previous iOS versions, the front-facing camera would always deliver buffers in AVCaptureVideoOrientationLandscapeLeft and the back-facing camera would always deliver buffers in AVCaptureVideoOrientationLandscapeRight.

if ([self cameraPosition] == AVCaptureDevicePositionBack)
{
switch(_outputImageOrientation)
if (_horizontallyMirrorRearFacingCamera)
{
case UIInterfaceOrientationPortrait:outputRotation = kGPUImageRotateRight; break;
case UIInterfaceOrientationPortraitUpsideDown:outputRotation = kGPUImageRotateLeft; break;
case UIInterfaceOrientationLandscapeLeft:outputRotation = kGPUImageNoRotation; break;
case UIInterfaceOrientationLandscapeRight:outputRotation = kGPUImageRotate180; break;
switch(_outputImageOrientation)
{
case UIInterfaceOrientationPortrait:outputRotation = kGPUImageRotateRightFlipVertical; break;
case UIInterfaceOrientationPortraitUpsideDown:outputRotation = kGPUImageRotate180; break;
case UIInterfaceOrientationLandscapeLeft:outputRotation = kGPUImageFlipHorizonal; break;
case UIInterfaceOrientationLandscapeRight:outputRotation = kGPUImageFlipVertical; break;
}
}
else
{
switch(_outputImageOrientation)
{
case UIInterfaceOrientationPortrait:outputRotation = kGPUImageRotateRight; break;
case UIInterfaceOrientationPortraitUpsideDown:outputRotation = kGPUImageRotateLeft; break;
case UIInterfaceOrientationLandscapeLeft:outputRotation = kGPUImageNoRotation; break;
case UIInterfaceOrientationLandscapeRight:outputRotation = kGPUImageRotate180; break;
}
}
}
else
{
switch(_outputImageOrientation)
if (_horizontallyMirrorFrontFacingCamera)
{
switch(_outputImageOrientation)
{
case UIInterfaceOrientationPortrait:outputRotation = kGPUImageRotateRight; break;
case UIInterfaceOrientationPortraitUpsideDown:outputRotation = kGPUImageRotateLeft; break;
case UIInterfaceOrientationLandscapeLeft:outputRotation = kGPUImageRotate180; break;
case UIInterfaceOrientationLandscapeRight:outputRotation = kGPUImageNoRotation; break;
}
}
else
{
case UIInterfaceOrientationPortrait:outputRotation = kGPUImageRotateRight; break;
case UIInterfaceOrientationPortraitUpsideDown:outputRotation = kGPUImageRotateLeft; break;
case UIInterfaceOrientationLandscapeLeft:outputRotation = kGPUImageRotate180; break;
case UIInterfaceOrientationLandscapeRight:outputRotation = kGPUImageNoRotation; break;
switch(_outputImageOrientation)
{
case UIInterfaceOrientationPortrait:outputRotation = kGPUImageRotateRightFlipVertical; break;
case UIInterfaceOrientationPortraitUpsideDown:outputRotation = kGPUImageRotateRight; break;
case UIInterfaceOrientationLandscapeLeft:outputRotation = kGPUImageFlipVertical; break;
case UIInterfaceOrientationLandscapeRight:outputRotation = kGPUImageFlipHorizonal; break;
}
}
}

Expand All @@ -583,4 +611,22 @@ - (void)setOutputImageOrientation:(UIInterfaceOrientation)newValue;
});
}

- (void)setOutputImageOrientation:(UIInterfaceOrientation)newValue;
{
_outputImageOrientation = newValue;
[self updateOrientationSendToTargets];
}

- (void)setHorizontallyMirrorFrontFacingCamera:(BOOL)newValue
{
_horizontallyMirrorFrontFacingCamera = newValue;
[self updateOrientationSendToTargets];
}

- (void)setHorizontallyMirrorRearFacingCamera:(BOOL)newValue
{
_horizontallyMirrorRearFacingCamera = newValue;
[self updateOrientationSendToTargets];
}

@end

0 comments on commit 2cb7f32

Please sign in to comment.