4

I am streamlining the AVCamDemo project so that I can experiment with capturing only still images.

Below is the new code for captureStillImage() method:

- (void) captureStillImage
{
    AVCaptureConnection *stillImageConnection = [AVCamUtilities connectionWithMediaType:AVMediaTypeVideo fromConnections:[[self stillImageOutput] connections]];
    if ([stillImageConnection isVideoOrientationSupported]) {
        [stillImageConnection setVideoOrientation:orientation];
    }
    [[self stillImageOutput] captureStillImageAsynchronouslyFromConnection:stillImageConnection
                completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {
NSLog(@"In the completionHandler block");
           if (imageDataSampleBuffer != NULL) {
               NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
               UIImage *image = [[UIImage alloc] initWithData:imageData];
                     [self writeImageFile:image];
                     [image release];
            }
          if ([[self delegate] respondsToSelector:@selector(captureManagerStillImageCaptured:)]) {
               [[self delegate] captureManagerStillImageCaptured:self];
                }
     }];
NSLog(@"exiting....");
}

In my testing, I have found that sometimes, the NSLog statement in the block is not executed....and therefore the stillImage file does not get saved.

Am I running into timing issues? If so, how do I address them?

Thanks, and regards. Sam.

Ankur
  • 5,086
  • 19
  • 37
  • 62
Sam
  • 827
  • 4
  • 9
  • 21

0 Answers0