Method captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection only called a few times

大兔子大兔子 提交于 2019-12-08 02:39:31

问题


I'm capturing audio from external bluetooth microphone. But I can't record anything.

This method is only called one time, at the beginning of the current AvCaptureSession.

- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection

After that I never get called this method for process the audio.

For instantiate the capture session I do this:

self.captureSession.usesApplicationAudioSession = true;
self.captureSession.automaticallyConfiguresApplicationAudioSession = true;
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionAllowBluetooth error:nil];


/* Audio */
AVCaptureDevice *audioDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];


audioIn = [[AVCaptureDeviceInput alloc] initWithDevice:audioDevice error:nil];
if ( [_captureSession canAddInput:audioIn] ) {
    [_captureSession addInput:audioIn];
}
[audioIn release];

audioOut = [[AVCaptureAudioDataOutput alloc] init];
// Put audio on its own queue to ensure that our video processing doesn't cause us to drop audio
dispatch_queue_t audioCaptureQueue = dispatch_queue_create( "com.apple.sample.capturepipeline.audio", DISPATCH_QUEUE_SERIAL );
[audioOut setSampleBufferDelegate:self queue:audioCaptureQueue];

[audioCaptureQueue release];

if ( [self.captureSession canAddOutput:audioOut] ) {
    [self.captureSession addOutput:audioOut];
}
_audioConnection = [audioOut connectionWithMediaType:AVMediaTypeAudio];
[audioOut release];

If I use another bluetooth device is always working, but not with this one. I thought this device could be faulty, but actually is working in another apps to record audio.

Is really strange the problem. Anyone knows what could be happening?

Thanks!

来源:https://stackoverflow.com/questions/29868892/method-captureoutputavcaptureoutput-captureoutput-didoutputsamplebuffercms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!