Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Haoxiang Li
committed
Aug 16, 2012
1 parent
53c842d
commit 58b37e5
Showing
8 changed files
with
526 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// MPMainViewController.h | ||
// MotionPattern | ||
// | ||
// Created by Haoxiang Li on 8/14/12. | ||
// Copyright (c) 2012 Haoxiang Li. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@class MPVideoProcessor; | ||
|
||
@interface MPMainViewController : UIViewController | ||
|
||
@property (strong, nonatomic) IBOutlet UIButton *m_controlButton; | ||
@property (strong, nonatomic) IBOutlet UIImageView *m_imageView; | ||
|
||
@property (strong, nonatomic) MPVideoProcessor *m_videoProcessor; | ||
|
||
- (IBAction)controlButtonTapped:(id)sender; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// | ||
// MPMainViewController.m | ||
// MotionPattern | ||
// | ||
// Created by Haoxiang Li on 8/14/12. | ||
// Copyright (c) 2012 Haoxiang Li. All rights reserved. | ||
// | ||
|
||
#import "MPMainViewController.h" | ||
#import "MPVideoProcessor.h" | ||
#import <AVFoundation/AVFoundation.h> | ||
|
||
#define kControlButtonStatusWaitForStart 0x100 | ||
#define kControlButtonStatusWaitForStop 0x101 | ||
#define kControlButtonCaptionStart @"Start" | ||
#define kControlButtonCaptionStop @"Stop" | ||
|
||
@interface MPMainViewController () <AVCaptureVideoDataOutputSampleBufferDelegate> | ||
@end | ||
|
||
@implementation MPMainViewController | ||
@synthesize m_imageView, m_controlButton; | ||
|
||
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil | ||
{ | ||
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; | ||
if (self) { | ||
// Custom initialization | ||
self.m_videoProcessor = [[MPVideoProcessor alloc] init]; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)viewDidLoad | ||
{ | ||
[super viewDidLoad]; | ||
|
||
[self.m_controlButton setTag:kControlButtonStatusWaitForStart]; | ||
[self.m_controlButton setTitle:kControlButtonCaptionStart forState:UIControlStateNormal]; | ||
|
||
//< Something Tricky here | ||
self.m_imageView.layer.affineTransform = CGAffineTransformMakeRotation(M_PI_2); | ||
} | ||
|
||
- (void)viewDidUnload | ||
{ | ||
[super viewDidUnload]; | ||
} | ||
|
||
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation | ||
{ | ||
return (interfaceOrientation == UIInterfaceOrientationPortrait); | ||
} | ||
|
||
#pragma mark - AVCaptureVideoDataOutputSampleBufferDelegate | ||
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection { | ||
|
||
CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer); | ||
CVPixelBufferLockBaseAddress(imageBuffer, 0); | ||
|
||
CGImageRef dstImage = [MPVideoProcessor createGrayScaleImageRefFromImageBuffer:imageBuffer]; | ||
|
||
CVPixelBufferUnlockBaseAddress(imageBuffer, 0); | ||
|
||
dispatch_sync(dispatch_get_main_queue(), ^{ | ||
self.m_imageView.layer.contents = (__bridge id)dstImage; | ||
}); | ||
|
||
CGImageRelease(dstImage); | ||
} | ||
|
||
#pragma IBAction | ||
- (IBAction)controlButtonTapped:(UIButton *)controlBtn { | ||
if (controlBtn.tag == kControlButtonStatusWaitForStart) | ||
{ | ||
NSLog(@"Start Tapped"); | ||
[self.m_controlButton setTag:kControlButtonStatusWaitForStop]; | ||
[self.m_controlButton setTitle:kControlButtonCaptionStop forState:UIControlStateNormal]; | ||
|
||
[self.m_videoProcessor setupAVCaptureSession]; | ||
//< higher quality | ||
[self.m_videoProcessor.m_avSession setSessionPreset:AVCaptureSessionPresetHigh]; | ||
[self.m_videoProcessor startAVSessionWithBufferDelegate:self]; | ||
} | ||
else | ||
{ | ||
NSLog(@"Stop Tapped"); | ||
[self.m_controlButton setTag:kControlButtonStatusWaitForStart]; | ||
[self.m_controlButton setTitle:kControlButtonCaptionStart forState:UIControlStateNormal]; | ||
[self.m_videoProcessor stopAVSession]; | ||
} | ||
} | ||
|
||
@end |
Oops, something went wrong.