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?
ios opengl-es
Ilija
source share