【问题标题】:AVCaptureSession for Audio and Video combined - Audio part gives EXC_BAD_ACCESS音频和视频结合的 AVCaptureSession - 音频部分给出 EXC_BAD_ACCESS
【发布时间】:2011-03-04 01:41:19
【问题描述】:

我做了一个很棒的小应用,叫做 Night Cam,可以录制夜视效果视频。目前正在更新中。

视频捕捉工作绝对正常,但音频却不行。在没有录制到文件的情况下打开应用程序就会出现问题(我将在以后将其更改为仅在录制时激活音频)。

以下是相关代码:

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);

“特别代表”是这样的:

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

录制布尔值未设置,因此没有附加任何内容。您也不必担心 AVAssestWriter 的设置,因为它在应用程序崩溃时根本没有设置。我必须是音频输入的设置。

这是崩溃时的调用堆栈:

> #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

感谢您的帮助。

【问题讨论】:

  • 您是否在启用僵尸检测的情况下运行您的应用程序?听起来像是对已释放对象的调用。 [audio_output setSampleBufferDelegate:special_delegate queue:queue]; 是否保留 special_delegate?在此调用之前和之后添加断点并尝试类似 'p (int)[special_delegate retaincount].在调试器中。
  • 你是对的!谢谢你。由于某种原因,它不保留它。我以为会的。
  • 我也面临同样的问题。你是如何解决这个问题的?我阅读了 cmets,其中提到您需要保留代表。但我的应用程序正在使用 ARC。我该如何解决?谢谢

标签: iphone objective-c ios avfoundation avcapturesession


【解决方案1】:

听起来您的程序正在访问某种错误的内存。您是否尝试在设置中启用 NSZombieEnabled 属性?我上周发现了一个类似的 EXC_BAD_ACCESS 问题。当你这样做时,它应该会在导致崩溃的调用中中断。

【讨论】:

    【解决方案2】:

    您似乎正在尝试访问尚未准备好或尚未创建的内容。

    【讨论】:

      【解决方案3】:

      需要保留的 special_delegate 对象。

      【讨论】:

        猜你喜欢
        • 2012-05-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-02-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多