Note that there are some explanatory texts on larger screens.

plurals
  1. POMultiple Operation Queues with Different priorities
    primarykey
    data
    text
    <p>Good day, here's what i am trying to do:</p> <ul> <li>i have a photo processing app that takes images using AVFoundation</li> <li>i have a DeviceMotion queue that is processing device position at 60Hz</li> <li>when image is taken, it needs to be cropped and saved. DeviceMotion needs to keep running and interface updated without delays</li> </ul> <p>what i am seeing is: updates to interface from DeviceMotion queue are being frozen for the duration of image crop.</p> <p>this is how i start updates for DeviceMotion:</p> <pre><code>self.motionManager.deviceMotionUpdateInterval = 1.0f/60.0f; gyroQueue = [[NSOperationQueue alloc] init]; [self.motionManager startDeviceMotionUpdatesToQueue:gyroQueue withHandler:^(CMDeviceMotion *motion, NSError *error){ [NSThread setThreadPriority:1.0]; [self processMotion:motion withError:error]; }]; </code></pre> <p>when images is returned from AVFoundation it is added to the queue for processing:</p> <pre><code>imageProcessingQueue = [[NSOperationQueue alloc] init]; [imageProcessingQueue setName:@"ImageProcessingQueue"]; [imageProcessingQueue setMaxConcurrentOperationCount:1]; //[imageProcessingQueue addOperationWithBlock:^{ //[self processImage:[UIImage imageWithData:imageData]]; //}]; NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(processImage:) object:[UIImage imageWithData:imageData]]; [operation setThreadPriority:0.0]; [operation setQueuePriority:NSOperationQueuePriorityVeryLow]; [imageProcessingQueue addOperation:operation]; </code></pre> <p>and the method for processing the image:</p> <pre><code>- (void)processImage:(UIImage*)image { CGSize cropImageSize = CGSizeMake(640,960); UIImage *croppedImage = [image resizedImageWithContentMode:UIViewContentModeScaleAspectFit bounds:cropImageSize interpolationQuality:kImageCropInterpolationQuality]; NSData *compressedImageData = UIImageJPEGRepresentation(croppedImage, kJpegCompression); [self.doc addPhoto:compressedImageData]; } </code></pre> <p>the issue is: </p> <ul> <li>devicemotion updates are blocked for the duration of image crop when image is processed using the NSOperationQueue</li> </ul> <p>if i process the image using performSelectorInBackground - it works as desired (no delays to DeviceMotion queue)</p> <blockquote> <pre><code>[self performSelectorInBackground:@selector(processImage:) withObject:[UIImage imageWithData:imageData]]; </code></pre> </blockquote> <p>any ideas on where my understanding of background threading needs an update? :) </p> <p>PS. I have asked this question earlier but it got nowhere, so this is a re-post</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload