Reputation: 381
I'm trying to collect into an array 150 CMSampleBufferRef that i recieve from my iPhone's Video Camera. Somehow the camera stops calling the delegate after 13 buffers. I tried working with NSMutableArray, CFArray. nothing helped. I suspect it something with memory but i get nothing about memory warning.
I'll be happy for some help with that.
Thanks ahead.
session = [[AVCaptureSession alloc]init];
//Quality Preset
if ([session canSetSessionPreset:AVCaptureSessionPresetLow]) {
session.sessionPreset = AVCaptureSessionPresetLow;
}
[session beginConfiguration];
AVCaptureDevice *videoDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
AVCaptureDeviceInput *newVideoDeviceInput = [AVCaptureDeviceInput deviceInputWithDevice:videoDevice error:nil];
AVCaptureVideoDataOutput *output = [[AVCaptureVideoDataOutput alloc] init];
output.videoSettings = @{ (NSString *)kCVPixelBufferPixelFormatTypeKey : @(kCVPixelFormatType_32BGRA) };
dispatch_queue_t queue = dispatch_queue_create("MyQueue", NULL);
[output setSampleBufferDelegate:self queue:queue];
[session addOutput:output];
[session addInput:newVideoDeviceInput];
AVCaptureConnection *conn = [output connectionWithMediaType:AVMediaTypeVideo];
if (conn.supportsVideoMinFrameDuration)
conn.videoMinFrameDuration = CMTimeMake(1, 10);
if (conn.supportsVideoMaxFrameDuration)
conn.videoMaxFrameDuration = CMTimeMake(1, 10);
[session commitConfiguration];
arr = CFArrayCreateMutable( NULL, 150, &kCFTypeArrayCallBacks );
counter=0;
[session startRunning];
That was my StartRecording method.
- (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection *)connection {
if (counter==150) {
[self StopRecording:nil];
return;
}
CFArrayInsertValueAtIndex(arr, counter, sampleBuffer);
counter= (counter+1)%150;
}
@end
Tha's the buffer collection method.
Upvotes: 4
Views: 940
Reputation: 1552
What are you trying todo? AVFoundation passes the CMSampleBuffer to the hardware encoder. My theory is when it doesn't detect incoming frames, it just stops passing you frames. Instead, try storing CVPixelBufferRef in a CVPixelBufferPool.
CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
Upvotes: 2