3

I try to save the sample buffer instead of an UIImage to an array, to convert it later on. This to speed up the image capturing and maybe not get memory warnings. I just can't figure out how to save it to the array and then use it again to call [self imageFromSampleBuffer:sampleBuffer]. I tried something like this, but how do I convert the data back to a CMSampleBufferRef object?

- (void)captureOutput:(AVCaptureOutput *)captureOutput 
    didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer 
   fromConnection:(AVCaptureConnection *)connection { 
// Create a UIImage from the sample buffer data
//      UIImage *image = [self imageFromSampleBuffer:sampleBuffer];
//      [arrCaptures addObject:image];

[arrImageBuffer addObject:[NSData dataWithBytes:sampleBuffer length:sizeof(sampleBuffer)] ];}

2 Answers 2

5

Why not just use a CFArray and directly put the CMSampleBufferRef objects in there?

Sign up to request clarification or add additional context in comments.

10 Comments

Thanks, well I can't really figure out how to do that. I tried to put it in an NSValue object and ALMOST got it working. I guess I got some homework to do.
Try making a CFMutableArray and then doing CFArrayAppendValue(arr, sampleBuffer). developer.apple.com/library/mac/documentation/CoreFoundation/…
It seems to work to store with CFArrayAppendValue(arrCFImageBuffer, sampleBuffer); But after I don't find the way to get it back. This doesn't work: CMSampleBufferRef imageBuffer = CFArrayGetValueAtIndex(arrCFImageBuffer, currImageIdx);
What do you mean by "doesn't work"; i.e. what's the problem? Does it crash? You may need to cast the return value like CMSampleBufferRef imageBuffer = (CMSampleBufferRef)CFArrayGetValueAtIndex(arrCFImageBuffer, currImageIdx); and also be sure to provide kCFTypeArrayCallBacks as the third argument to CFArrayCreateMutable.
@Snilleblixten - that's because AVFoundation uses pool of 13 (in your case) preallocated CMSampleBuffer instances and recycles them. Since you're adding them to the array, they get retained and not released back to the pool. You have to create a copy of the CMSampleBuffer (CMSampleBufferCopy creates shallow copy, so it won't work) and then release the buffer back to the pool.
|
4

You can use CFArray but you should remember that the CMSampleBufferRef is not retained, and that the "captureOutput:didOutputSampleBuffer:fromConnection:" uses a memory pool - and when you don't release the memory it stops sending new samples (that is why you get only 13 samples) as you can read in:captureOutput:didOutputSampleBuffer:fromConnection:

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.