Skip to content

Commit

Permalink
fix audioCapture crash
Browse files Browse the repository at this point in the history
  • Loading branch information
chenliming committed Nov 17, 2016
1 parent b3a8d96 commit f6feec3
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions LFLiveKit/capture/LFAudioCapture.m
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ - (instancetype)initWithAudioConfiguration:(LFLiveAudioConfiguration *)configura
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];

dispatch_async(self.taskQueue, ^{
dispatch_sync(self.taskQueue, ^{
if (self.componetInstance) {
self.isRunning = NO;
AudioOutputUnitStop(self.componetInstance);
Expand All @@ -121,7 +121,7 @@ - (void)setRunning:(BOOL)running {
AudioOutputUnitStart(self.componetInstance);
});
} else {
dispatch_async(self.taskQueue, ^{
dispatch_sync(self.taskQueue, ^{
self.isRunning = NO;
NSLog(@"MicrophoneSource: stopRunning");
AudioOutputUnitStop(self.componetInstance);
Expand Down Expand Up @@ -182,7 +182,7 @@ - (void)handleInterruption:(NSNotification *)notification {
reason = [[[notification userInfo] objectForKey:AVAudioSessionInterruptionTypeKey] integerValue];
if (reason == AVAudioSessionInterruptionTypeBegan) {
if (self.isRunning) {
dispatch_async(self.taskQueue, ^{
dispatch_sync(self.taskQueue, ^{
NSLog(@"MicrophoneSource: stopRunning");
AudioOutputUnitStop(self.componetInstance);
});
Expand Down

2 comments on commit f6feec3

@JiangangYang
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为什么要使用多线程退出?直接退出也没问题哈?
if (self.componetInstance) {
self.isRunning = NO;
AudioOutputUnitStop(self.componetInstance);
AudioComponentInstanceDispose(self.componetInstance);
self.componetInstance = nil;
self.component = nil;
}

@chenliming777
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是没有问题 dealloc里面的代码不加都没有问题(因为setRunning为NO会调用) 多线程主要保证的是数据来了的同时与stop同时可能出现线程问题

Please sign in to comment.