Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AUGraphStop crashes right after stream ending (iOS 14 only bug) #453

Closed
IlyaOst opened this issue Aug 12, 2020 · 25 comments
Closed

AUGraphStop crashes right after stream ending (iOS 14 only bug) #453

IlyaOst opened this issue Aug 12, 2020 · 25 comments

Comments

@IlyaOst
Copy link

IlyaOst commented Aug 12, 2020

While adopting my app to new iOS 14, I faced a bug that StreamingKit crashes at stopAudioUnitWithReason method in status = AUGraphStop(audioGraph) line.
This happens only after music file ends playing, with reason == STKAudioPlayerStopReasonEof. Frequency of crash = 100%.
Also, no description of this problem was provided by Xcode.

How can this be fixed? This is a very serious issue.

@iDevelopper
Copy link

Only happen on simulator, not on device, right?

@IlyaOst
Copy link
Author

IlyaOst commented Aug 12, 2020

Unfortunately not :(
Tested this on my iPhone 6S, also have a feedback from current users who already did update on new iOS.

On simulator I have a problem simillar to #451.
Absolutely can't start and have a break in CHECK_STATUS_AND_RETURN(AUGraphInitialize(audioGraph)).

@iDevelopper
Copy link

I forgot I had the same issue. This is what i did:

    func audioPlayer(_ audioPlayer: STKAudioPlayer, unexpectedError errorCode: STKAudioPlayerErrorCode) {
        DispatchQueue.main.async {
            self.pause() // UI
            self.audioPlayer.stop()
        }
    }

@IlyaOst
Copy link
Author

IlyaOst commented Aug 13, 2020

I don't have any call for this delegate method, seems useless to me :(

@iDevelopper
Copy link

So you can use a category (extension) I wrote in the past (see #398), to get notified.

STKAutoRecoveringHTTPDataSource+PBPrivate.zip

Import STKAutoRecoveringHTTPDataSource+PBPrivate.h in your Bridging-Header.h

And for example:

        let dataSource = STKAudioPlayer.dataSource(from: url)
        
        (dataSource as! STKAutoRecoveringHTTPDataSource).audioPlayer = self.audioPlayer
        
        self.audioPlayer.setDataSource(dataSource, withQueueItemId: SampleQueueId(url: url, andCount: 0))

@LYongLiang
Copy link

Hello, have you found a solution?

@iDevelopper
Copy link

Yes, see my reply above.

@LYongLiang
Copy link

Could you update your adjustments to Git?

@iDevelopper
Copy link

@LYongLiang

No, I wrote this category for my own use. I am neither the owner nor a contributor of this repo.

@iDevelopper
Copy link

You can submit a PR if you want...

@LYongLiang
Copy link

        let dataSource = STKAudioPlayer.dataSource(from: url)
        
        (dataSource as? STKAutoRecoveringHTTPDataSource)?.audioPlayer = self.audioPlayer
        
        self.audioPlayer.setDataSource(dataSource, withQueueItemId: url as NSObject)

I tried. In ios14 beta, it still crashes after the audio play end.

@iDevelopper
Copy link

Have you implemented the delegate function and called audioPlayer.stop()?
#453 (comment)
No crash for me even in iOS 14.

@LYongLiang
Copy link

Thank you for your reply.

I wrote a demo that you can try on the device.
Test.zip

Crash thread:
image

Crash device:
image

Only happen on device , on ios14.

@iDevelopper
Copy link

I have updated Xcode beta 4 to Xcode beta 5 just before reading your comment.

Your sample does not crash.

Could you check with Xcode beta 5?

@LYongLiang
Copy link

Since Xcode12 is still in beta, So I packaged it with Xcode11.5.

I compiled with Xcode11.5, exported the IPA package, installed it on an ios14beta device, and the crash occurred.

@LYongLiang
Copy link

Thank you very much for your help.

I have solved the problem for the time being,

In this method:
-(void) stopAudioUnitWithReason:(STKAudioPlayerStopReason)stopReasonIn

I have modified :

if (!(stopReasonIn == STKAudioPlayerStopReasonEof && [[UIDevice currentDevice].systemVersion compare:@"14.0"] != NSOrderedAscending)) {
    status = AUGraphStop(audioGraph);
    if (status)
    {
        [self unexpectedError:STKAudioPlayerErrorAudioSystemError];
    }

}

Thank you again.

@AlexeyKolmyk
Copy link

AlexeyKolmyk commented Aug 21, 2020

Hello. Seems like this problem appear (on iOS14) because status = AUGraphStop(audioGraph); invokes in AURemoteIO::IOThread. I've found another possible fix:

-(void) audioQueueFinishedPlaying:(STKQueueEntry*)entry
{
    STKQueueEntry* next = [bufferingQueue dequeue];

    [self processFinishPlayingIfAnyAndPlayingNext:entry withNext:next];
    [self invokeOnPlaybackThread:^
    {
        [self processRunloop];
    }];
}

But not 100% sure about it. Will glad to hear any improvements/suggestions

@IlyaOst
Copy link
Author

IlyaOst commented Aug 21, 2020

Thank a much for your help, guys. But as I see now, in beta 5 this problem disappeared. Check this please, and I probably will close the issue.

@lixiang1994
Copy link

你好。似乎这个问题(在iOS14上)出现,因为status = AUGraphStop(audioGraph);在AUremoteIO::IOThread中调用。我找到了另一个可能的修复方法:

-(void) audioQueueFinishedPlaying:(STKQueueEntry*)entry
{
    STKQueueEntry* next = [bufferingQueue dequeue];

    [self processFinishPlayingIfAnyAndPlayingNext:entry withNext:next];
    [self invokeOnPlaybackThread:^
    {
        [self processRunloop];
    }];
}

但不能百分之百确定。很高兴听到任何改进/建议

Hello. Seems like this problem appear (on iOS14) because status = AUGraphStop(audioGraph); invokes in AURemoteIO::IOThread. I've found another possible fix:

-(void) audioQueueFinishedPlaying:(STKQueueEntry*)entry
{
    STKQueueEntry* next = [bufferingQueue dequeue];

    [self processFinishPlayingIfAnyAndPlayingNext:entry withNext:next];
    [self invokeOnPlaybackThread:^
    {
        [self processRunloop];
    }];
}

But not 100% sure about it. Will glad to hear any improvements/suggestions

Unfortunately, while this change fixes the crash, it causes playback to not finish properly.

@FaceWaller
Copy link

FaceWaller commented Mar 7, 2023

[self processFinishPlayingIfAnyAndPlayingNext:entry withNext:next]; 也放进了block里,不然会有stopReason不准的问题

-(void) audioQueueFinishedPlaying:(STKQueueEntry*)entry
{
    STKQueueEntry* next = [bufferingQueue dequeue];
    [self invokeOnPlaybackThread:^
    {
        [self processFinishPlayingIfAnyAndPlayingNext:entry withNext:next];
        [self processRunloop];
    }];
}

@ShenYj
Copy link

ShenYj commented Apr 12, 2023

  • 1

caulk
0x000000020bec4f6c _ZN5caulk6thread4joinEv + 104

6
AudioToolbox
0x00000001c6f94c24 0x00000001c6df7000 + 1694756
7
StreamingKit
0x0000000104ce88ec -[STKAudioPlayer stopAudioUnitWithReason:] + 104
8
StreamingKit
0x0000000104ce5e7c -[STKAudioPlayer processRunloop] + 448
9
StreamingKit
0x0000000104ce5228 -[STKAudioPlayer audioQueueFinishedPlaying:] + 88
10
StreamingKit
0x0000000104ce81f4 OutputRenderCallback + 1412
11
libEmbeddedSystemAUs.dylib
0x00000002141f8c30 0x00000002141dc000 + 117808

37
libsystem_pthread.dylib
0x00000001fa5416cc _pthread_start + 148

@ShenYj
Copy link

ShenYj commented Apr 12, 2023

ly happen on device , on ios14.

16.3.1 (20D67) happened

@wenroudeerwa
Copy link

wenroudeerwa commented Apr 17, 2023

image
I have encountered this problem, and there are guys who know what to do,thank you!

@ShenYj
Copy link

ShenYj commented Apr 25, 2023

因为线上持续有这个问题,我今天刚好测试了下,只要长时间播放,不一会就会遇到

@ShenYj
Copy link

ShenYj commented Apr 8, 2024

gist

不想fork维护,目前通过pod hook修改了源码观察

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants