AVCaptureSession for audio and video combined - Audio part gives EXC_BAD_ACCESS

I made a wonderful little app called Night Cam that can record night vision video. I am updating it now.

Video capture works absolutely fine, but there is no sound. There is a problem that occurs as soon as I turn on the application when recording is not performed (I will change it to activate the sound only when recording later).

Here is the relevant 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->normal_delegate = self;
[audio_output setSampleBufferDelegate:special_delegate queue:queue];
dispatch_release(queue);

"Special Delegate":

 @implementation AudioOutputBufferDelegate
    -(void)captureOutput: (AVCaptureOutput *) captureOutput didOutputSampleBuffer: (CMSampleBufferRef) sampleBuffer fromConnection: (AVCaptureConnection *) conenction{
        if (normal_delegate->recording) {
            [normal_delegate->audio_writer_input appendSampleBuffer: sampleBuffer];
        }
    }
@end

The boolean entry is not set, so nothing is added. You do not need to worry about configuring AVAssestWriter, because it is not configured at all when the application crashes. I have to be the audio input setting.

Here is the call column when it fails:

> #0    0x33479464 in objc_msgSend
> #1    0x348154b2 in -[AVCaptureAudioDataOutput _AVCaptureAudioDataOutput_AudioDataBecameReady]
> #2    0x34815690 in AVCaptureAudioDataOutput_AudioDataBecameReady
> #3    0x33cc5984 in FigRecorderRemoteCallbacksServer_SampleBuffersArePending
> #4    0x33cc2adc in _XSampleBuffersArePending
> #5    0x33ca42ba in figrecordercallbacks_server
> #6    0x33ca3238 in remrec_ClientPortCallBack
> #7    0x33a5dbe6 in __CFMachPortPerform
> #8    0x33a556fe in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__
> #9    0x33a556c2 in __CFRunLoopDoSource1
> #10   0x33a47f7c in __CFRunLoopRun
> #11   0x33a47c86 in CFRunLoopRunSpecific
> #12   0x33a47b8e in CFRunLoopRunInMode
> #13   0x33b0e4aa in GSEventRunModal
> #14   0x33b0e556 in GSEventRun
> #15   0x32099328 in -[UIApplication _run]
> #16   0x32096e92 in UIApplicationMain
> #17   0x000023e0 in main at main.m:14

Thanks for any help.

+3
3

, . NSZombieEnabled ? EXC_BAD_ACCESS, . , , .

+2

, , .

+1

The special_delegate object must be saved.

+1
source

Source: https://habr.com/ru/post/1796183/


All Articles