I have a camera session and i am taking images from the buffer:
-(void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
{
CVPixelBufferRef pixelBuffer = (CVPixelBufferRef)CMSampleBufferGetImageBuffer(sampleBuffer);
CIImage *ciImage = [CIImage imageWithCVPixelBuffer:pixelBuffer];
//rotate image 90°
ciImage = [ciImage imageByApplyingTransform:CGAffineTransformMakeRotation(-M_PI/2.0)];
}
And i am applying a filter on the image, and i want it to apply the filter on another queue, it is not thread-safe so if i take images to fast it will blend the images together (50/50 from left to right, i think), but i am trying to make it thread-safe, and it will not work by using NSLock or NSRecursiveLock because it will blend the images together.
dispatch_async(filterQueue, ^{
CIImage *scaleImage = [CIFilter filterWithName:@"CILanczosScaleTransform" keysAndValues:kCIInputImageKey, ciImage, @"inputScale", [NSNumber numberWithFloat:0.5], nil].outputImage;
CGImageRef cgImage = [imageContext createCGImage:scaleImage fromRect:scaleImage.extent];
[self.pictureArray addObject:[UIImage imageWithCGImage:cgImage]];
CGImageRelease(cgImage);
});
Can someone help me? i have not much knowledge in how to make code a thread-safe
Images blend like this: https://i.stack.imgur.com/wjrIl.png