Permalink
Browse files

Pulling in some random changes

  • Loading branch information...
gabriel committed Jul 28, 2011
1 parent 55c02f9 commit 060ba6fb2fe5c97eabe229baf4e39abe83a7ae83
View
@@ -1,3 +1,3 @@
build
-FFPlayer.xcodeproj/*.pbxuser
-FFPlayer.xcodeproj/*.mode1v3
+FFProcessing.xcodeproj/project.xcworkspace
+FFProcessing.xcodeproj/xcuserdata
@@ -23,13 +23,9 @@
CVImageBufferRef _imageBuffer;
- NSString *_sessionPreset;
-
dispatch_queue_t _queue;
}
-@property (retain, nonatomic) NSString *sessionPreset;
-
@end
#else
@interface FFAVCaptureSessionReader : NSObject <FFReader> {
@@ -20,11 +20,8 @@
@implementation FFAVCaptureSessionReader
-@synthesize sessionPreset=_sessionPreset;
-
- (void)dealloc {
[self close];
- [_sessionPreset release];
[super dealloc];
}
@@ -41,7 +38,7 @@ - (void)_setupVideoDevice:(AVCaptureDevice *)videoCaptureDevice {
[videoCaptureDevice unlockForConfiguration];
}
-- (BOOL)_start:(NSError **)error {
+- (BOOL)start:(NSError **)error {
if (_captureSession) {
FFSetError(error, 0, @"Capture session already started");
return NO;
@@ -50,18 +47,16 @@ - (BOOL)_start:(NSError **)error {
_captureSession = [[AVCaptureSession alloc] init];
NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
FFDebug(@"Devices: %@", devices);
- // [devices lastObject]; // For front camera
- AVCaptureDevice *videoCaptureDevice = [devices gh_firstObject];
+
+ AVCaptureDevice *videoCaptureDevice = [devices gh_firstObject]; // For back camera
+ //AVCaptureDevice *videoCaptureDevice = [devices lastObject]; // For front camera
if (!videoCaptureDevice) return NO;
[self _setupVideoDevice:videoCaptureDevice];
AVCaptureDeviceInput *videoInput = [AVCaptureDeviceInput deviceInputWithDevice:videoCaptureDevice error:error];
if (!videoInput) return NO;
- NSString *sessionPreset = _sessionPreset;
- if (!sessionPreset) sessionPreset = AVCaptureSessionPresetLow;
-
- [_captureSession setSessionPreset:sessionPreset];
+ [_captureSession setSessionPreset:AVCaptureSessionPresetLow]; // AVCaptureSessionPresetMedium
[_captureSession addInput:videoInput];
NSArray *audioCaptureDevices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeAudio];
@@ -73,7 +68,6 @@ - (BOOL)_start:(NSError **)error {
}
_videoOutput = [[AVCaptureVideoDataOutput alloc] init];
- //_videoOutput.minFrameDuration = CMTimeMake(1, 15);
_videoOutput.alwaysDiscardsLateVideoFrames = TRUE;
_videoOutput.videoSettings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithUnsignedInt:kCVPixelFormat], kCVPixelBufferPixelFormatTypeKey,
@@ -88,14 +82,15 @@ - (BOOL)_start:(NSError **)error {
}
[_captureSession addOutput:_videoOutput];
+ FFDebug(@"Starting capture session...");
[_captureSession startRunning];
FFDebug(@"Started capture session");
return YES;
}
- (void)close {
if (!_captureSession) return;
-
+ FFDebug(@"Closing capture session");
[_captureSession stopRunning];
// Wait until it stops
@@ -122,7 +117,8 @@ - (void)close {
- (FFVFrameRef)nextFrame:(NSError **)error {
_wantsData = YES;
if (!_captureSession) {
- [self _start:error];
+ //[self start:error];
+ NSAssert(NO, @"Call start: before requesting frame");
return NULL;
}
@@ -167,8 +163,8 @@ - (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CM
if (_frame == NULL) {
size_t width = CVPixelBufferGetWidth(imageBuffer);
size_t height = CVPixelBufferGetHeight(imageBuffer);
- FFDebug(@"Creating frame; width=%d, height=%d, size=%d", width, height, size);
FFPixelFormat pixelFormat = FFPixelFormatFromCVPixelFormat(kCVPixelFormat);
+ FFDebug(@"Creating frame; width=%d, height=%d, CVPixelBufferSize=%d, pixelFormat=%d", width, height, size, pixelFormat);
_frame = FFVFrameCreateWithData(FFVFormatMake(width, height, pixelFormat), NULL);
}
@@ -180,8 +176,8 @@ - (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CM
}
#if DEBUG
- static NSInteger DebugCount = 0;
- if (DebugCount++ % 30 == 0) FFDebug(@"[SAMPLE BUFFER]");
+ //static NSInteger DebugCount = 0;
+ //if (DebugCount++ % 30 == 0) FFDebug(@"[SAMPLE BUFFER]");
#endif
memcpy(_data, baseAddress, _dataSize);
@@ -197,13 +193,17 @@ - (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CM
@implementation FFAVCaptureSessionReader
+- (BOOL)start:(NSError **)error {
+ return YES;
+}
+
- (FFVFrameRef)nextFrame:(NSError **)error {
if (_frame == NULL) {
_frame = FFVFrameCreate(FFVFormatMake(320, 480, kFFPixelFormatType_32BGRA));
FFFill32BGRAImage(_frame, 0);
FFDebug(@"Filled 32BGRA image");
}
- FFDebug(@"[FRAME]");
+ FFDebug(@"[TEST FRAME]");
return _frame;
}
@@ -11,6 +11,10 @@
@implementation FFAVMockReader
+- (BOOL)start:(NSError **)error {
+ return YES;
+}
+
- (FFVFrameRef)nextFrame:(NSError **)error {
return NULL;
}
@@ -8,7 +8,6 @@
#import "FFDecoderOptions.h"
#import "FFUtils.h"
-#import "FFMPUtils.h"
@implementation FFDecoderOptions
@@ -8,7 +8,7 @@
#import "FFEncoderOptions.h"
#import "FFUtils.h"
-#import "FFMPUtils.h"
+
@implementation FFEncoderOptions
@@ -45,18 +45,17 @@ - (void)setupView:(GHGLView *)view {
[super setupView:view];
TextureSize texSize = {(GLsizei)view.frame.size.width, (GLsizei)view.frame.size.height};
TextureCoord3D texCoord = {1, 1};
+ [_imaging release];
_imaging = [[FFGLImaging alloc] initWithTextureSize:texSize textureCoord:texCoord];
- _imageEncoder = [[FFGLImageEncoder alloc] initWithWidth:texSize.wide height:texSize.high format:_GLFormat];
-
+ //_imageEncoder = [[FFGLImageEncoder alloc] initWithWidth:texSize.wide height:texSize.high format:_GLFormat];
GHGLCheckError();
}
- (BOOL)drawView:(GHGLView *)view {
NSAssert(_reader, @"No reader");
-
FFVFrameRef frame = [_reader nextFrame:nil];
if (frame == NULL) {
- //FFDebug(@"No frame");
+ //FFDebug(@"No frame from FFReader");
return NO;
}
@@ -69,7 +68,7 @@ - (BOOL)drawView:(GHGLView *)view {
FFVFormat format = FFVFrameGetFormat(frame);
// TODO(gabe): Assert (pixel) format is correct for our GL setup
if (data == NULL) {
- //FFDebug(@"No data");
+ FFDebug(@"No data");
return NO;
}
@@ -94,19 +93,19 @@ - (BOOL)drawView:(GHGLView *)view {
GHGLCheckError();
+ glBindTexture(GL_TEXTURE_2D, _texture);
+ glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ GHGLCheckError();
+
CGRect texRect = CGRectMake(0, 0, view.frame.size.height, view.frame.size.width); // TODO(gabe): ??
-
TexturedVertexData2D quad[4] = {
{{texRect.origin.y, texRect.origin.x}, {0, 1}},
{{texRect.origin.y, texRect.origin.x + texRect.size.width}, {1, 1}},
{{texRect.origin.y + texRect.size.height, texRect.origin.x}, {0, 0}},
{{texRect.origin.y + texRect.size.height, texRect.origin.x + texRect.size.width}, {1, 0}}
};
- glBindTexture(GL_TEXTURE_2D, _texture);
- glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
NSAssert(_imaging, @"No imaging");
[_imaging apply:quad options:_imagingOptions];
@@ -9,6 +9,7 @@
#import "FFReading.h"
@protocol FFReader <NSObject>
+- (BOOL)start:(NSError **)error;
- (FFVFrameRef)nextFrame:(NSError **)error;
- (void)close;
@end
@@ -23,6 +24,4 @@
- (id)initWithReading:(id<FFReading>)reading;
-- (FFVFrameRef)nextFrame:(NSError **)error;
-
@end
@@ -32,16 +32,25 @@ - (void)close {
FFVFrameRelease(_frame);
}
-- (FFVFrameRef)nextFrame:(NSError **)error {
+- (BOOL)start:(NSError **)error {
if (!_started) {
_started = YES;
[_reading start];
}
-
+
if (_frame == NULL) {
_frame = FFVFrameCreate([_reading format]);
- if (_frame == NULL) return NULL;
}
+ return YES;
+}
+
+- (FFVFrameRef)nextFrame:(NSError **)error {
+ if (!_started) {
+ if (![self start:error])
+ return NULL;
+ _started = YES;
+ }
+ if (_frame == NULL) return NULL;
if (![_reading readFrame:_frame]) return _frame;
@@ -70,17 +70,19 @@ void FFVFrameCopy(FFVFrameRef source, FFVFrameRef dest);
FFVFrameRef FFVFrameCreateFromCGImage(CGImageRef image);
+int FFVFormatGetSize(FFVFormat format);
+
#pragma mark -
static inline uint8_t *FFVFrameGetData(FFVFrameRef frame, int index) {
return frame->data[index];
}
-static inline int FFVFrameGetBytesPerPixel(FFVFrameRef frame, int index) {
+static inline NSUInteger FFVFrameGetBytesPerPixel(FFVFrameRef frame, int index) {
return frame->linesize[index] / frame->format.width;
}
-static inline int FFVFrameGetBytesPerRow(FFVFrameRef frame, int index) {
+static inline NSUInteger FFVFrameGetBytesPerRow(FFVFrameRef frame, int index) {
return frame->linesize[index];
}
@@ -21,8 +21,8 @@ void FFFill32BGRAImage(FFVFrameRef frame, NSInteger frameIndex) {
int p = (x * bytesPerPixel) + (y * bytesPerRow);
data[p] = (y % 4 == 0 ? 255 : 0);
data[p + 1] = (y % 4 == 1 ? 255 : 0);
- data[p + 2] = (y % 4 == 2 ? 255 : 0);
- data[p + 3] = (y % 4 == 3 ? 255 : 0);
+ data[p + 2] = (y % 4 == 2 ? 0 : 255);
+ data[p + 3] = (y % 4 == 3 ? 127 : 0);
}
}
}
@@ -37,7 +37,7 @@ - (void)loadView {
- (void)_reload {
FFAVCaptureSessionReader *reader = [[FFAVCaptureSessionReader alloc] init];
- reader.sessionPreset = AVCaptureSessionPresetLow;
+ [reader start:nil];
FFGLDrawable *drawable = [[FFGLDrawable alloc] initWithReader:reader filter:_filter];
_playerView.drawable = drawable;
[drawable release];

0 comments on commit 060ba6f

Please sign in to comment.