Note that there are some explanatory texts on larger screens.

plurals
  1. POAVCaptureSession for Audio and Video combined - Audio part gives EXC_BAD_ACCESS
    text
    copied!<p>I've made a wonderful little app called Night Cam which can record night vision effect videos. I'm in the process of updating it at the moment.</p> <p>The video capture works absolutely fine but the audio does not. There is a problem which occurs as soon as I turn on the application when no recording to file is taking place (I will change it to activate audio only when recording later).</p> <p>Here is the relevant code:</p> <pre><code>session = [[AVCaptureSession alloc] init]; session.sessionPreset = AVCaptureSessionPresetMedium; camera = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; microphone = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio]; AVCaptureDeviceInput * camera_input = [AVCaptureDeviceInput deviceInputWithDevice:camera error:nil]; [session addInput:camera_input]; AVCaptureDeviceInput * microphone_input = [AVCaptureDeviceInput deviceInputWithDevice:microphone error:nil]; [session addInput:microphone_input]; AVCaptureVideoDataOutput * output = [[AVCaptureVideoDataOutput alloc] init]; output.videoSettings = [NSDictionary dictionaryWithObject: [NSNumber numberWithInt:kCVPixelFormatType_32BGRA] forKey:(id)kCVPixelBufferPixelFormatTypeKey]; [session addOutput:output]; output.minFrameDuration = CMTimeMake(1,30); dispatch_queue_t queue = dispatch_queue_create("MY QUEUE", NULL); [output setSampleBufferDelegate:self queue:queue]; dispatch_release(queue); AVCaptureAudioDataOutput * audio_output = [[AVCaptureAudioDataOutput alloc] init]; [session addOutput:audio_output]; queue = dispatch_queue_create("MY QUEUE", NULL); AudioOutputBufferDelegate * special_delegate = [[[AudioOutputBufferDelegate alloc] init] autorelease]; special_delegate-&gt;normal_delegate = self; [audio_output setSampleBufferDelegate:special_delegate queue:queue]; dispatch_release(queue); </code></pre> <p>The "special delegate" is this:</p> <pre><code> @implementation AudioOutputBufferDelegate -(void)captureOutput: (AVCaptureOutput *) captureOutput didOutputSampleBuffer: (CMSampleBufferRef) sampleBuffer fromConnection: (AVCaptureConnection *) conenction{ if (normal_delegate-&gt;recording) { [normal_delegate-&gt;audio_writer_input appendSampleBuffer: sampleBuffer]; } } @end </code></pre> <p>The recording boolean is not set so nothing is appended. You don't need to worry about the setup of the AVAssestWriter either because it doesn't get set up at all at the point the app crashes. I must be the setup of the audio input.</p> <p>Here is the call stack when it crashes:</p> <pre><code>&gt; #0 0x33479464 in objc_msgSend &gt; #1 0x348154b2 in -[AVCaptureAudioDataOutput _AVCaptureAudioDataOutput_AudioDataBecameReady] &gt; #2 0x34815690 in AVCaptureAudioDataOutput_AudioDataBecameReady &gt; #3 0x33cc5984 in FigRecorderRemoteCallbacksServer_SampleBuffersArePending &gt; #4 0x33cc2adc in _XSampleBuffersArePending &gt; #5 0x33ca42ba in figrecordercallbacks_server &gt; #6 0x33ca3238 in remrec_ClientPortCallBack &gt; #7 0x33a5dbe6 in __CFMachPortPerform &gt; #8 0x33a556fe in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ &gt; #9 0x33a556c2 in __CFRunLoopDoSource1 &gt; #10 0x33a47f7c in __CFRunLoopRun &gt; #11 0x33a47c86 in CFRunLoopRunSpecific &gt; #12 0x33a47b8e in CFRunLoopRunInMode &gt; #13 0x33b0e4aa in GSEventRunModal &gt; #14 0x33b0e556 in GSEventRun &gt; #15 0x32099328 in -[UIApplication _run] &gt; #16 0x32096e92 in UIApplicationMain &gt; #17 0x000023e0 in main at main.m:14 </code></pre> <p>Thank you for any help.</p>
 

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