Saving CMSampleBufferRef from Camera

I am writing an AR application that uses a camera channel to take photos in certain places in the world. Now I am faced with a problem that I’m not sure what to do.

I use CVOpenGLESTextureCacheRef to create textures from CMSampleBufferRef. The power of the camera is shown and it works perfectly. The problem arises when I take 12 photos and create textures from them. The way it works is that as soon as I find a match with the target, I create a texture like this:

CVImageBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBufferCopy); size_t frameWidth = CVPixelBufferGetWidth(pixelBuffer); size_t frameHeight = CVPixelBufferGetHeight(pixelBuffer); CVOpenGLESTextureRef texture = NULL; CVReturn err = CVOpenGLESTextureCacheCreateTextureFromImage(kCFAllocatorDefault, cache, pixelBuffer, NULL, GL_TEXTURE_2D, GL_RGBA, (GLsizei)frameWidth, (GLsizei)frameHeight, GL_BGRA, GL_UNSIGNED_BYTE, 0, &texture); if (!texture || err) { NSLog(@"CVOpenGLESTextureCacheCreateTextureFromImage failed (error: %d)", err); return; } CVOpenGLESTextureCacheFlush(cache, 0); 

The texture is then displayed on the location of the photo in the world and rendered. I do not release texture here because I need it in the future. The texture used as the camera feed is clearly freed.

The problem occurs when taking the 12th photograph. The callback captureOutput:didOutputSampleBuffer:fromConnection: no longer called. I understand that this is because the pool is full, as indicated in the documentation:

If your application causes a sample reset by storing the provided CMSampleBufferRef objects for too long, but this requires access to the sample data for an extended period of time, consider copying the data to a new buffer and then releasing the sample buffer (if it was previously saved) so that the memory it refers to can be reused.

However, I am not sure what to do. I tried using CMSampleBufferCreateCopy to create a copy of the buffer, but this did not work because, as the documentation says, it creates a shallow copy.

How can I deal with this in the most efficient way?

+7
ios opengl-es
source share

No one has answered this question yet.

See similar questions:

5
Take ownership of memory from CVImageBufferRef

or similar:

335
Objective-C ARC: strong versus conservation and weak vs assign
195
@property save, assign, copy, non-atomically in Objective-C
14
Pulling data from a CMSampleBuffer to create a deep copy
4
Saving CMSampleBufferRef causes random crashes
3
How to perform a deep copy of a CMSampleBufferRef camera callback?
one
OpenGL texture interference suppression for camera (iOS)
one
Quick Problem 3 CGImage
one
Using CoreML to output texture textures to subregions
one
Convert CIImage to CMSampleBufferRef
0
Efficient way to process AVCapture output buffer through OpenGL

All Articles