ant-media / Ant-Media-Server

Ant Media Server is a live streaming engine software that provides adaptive, ultra low latency streaming by using WebRTC technology with ~0.5 seconds latency. Ant Media Server is auto-scalable and it can run on-premise or on-cloud.
https://antmedia.io
Other
4.17k stars 618 forks source link

[IOS SDK] crash in WebRTC: EXC_BAD_ACCESS StartPlayout > Attempted to dereference garbage pointer 0x18. #4811

Open denmorgenshtern opened 1 year ago

denmorgenshtern commented 1 year ago

Description

App crashes somewhere after user changes RTCAudioSession.sharedInstance().isAudioEnabled state Problem appeared after this https://github.com/ant-media/WebRTC-iOS-SDK/pull/13

I don't know if it matters, but I use RTCAudioSession.sharedInstance to mute / unmute audio while playing stream

RTCAudioSession.sharedInstance().useManualAudio = true
RTCAudioSession.sharedInstance().isAudioEnabled = true / false

Steps to reproduce

Can't reproduce it myself, only see sentry logs, about 4% users, any iPhone devices and iOS versions

Logs

Log example ``` Version: iOS 16.1.1 (20B101) Report Version: 104 Exception Type: EXC_BAD_ACCESS (SIGBUS) Exception Codes: BUS_NOOP at 0x0000000000000018 Crashed Thread: 17 Application Specific Information: StartPlayout > Attempted to dereference garbage pointer 0x18. Thread 17 Crashed: 0 WebRTC 0x1063a09c0 -[RTCVideoEncoderSettings maxFramerate] 1 WebRTC 0x1064a626c webrtc::ios_adm::AudioDeviceIOS::StartPlayout 2 WebRTC 0x1064aa2c0 webrtc::ios_adm::AudioDeviceModuleIOS::StartPlayout 3 WebRTC 0x106597b40 webrtc::internal::AudioState::AddReceivingStream 4 WebRTC 0x106507cc4 cricket::WebRtcVoiceMediaChannel::SetPlayout 5 WebRTC 0x106330268 cricket::VoiceChannel::UpdateMediaSendRecvState_w 6 WebRTC 0x1063304cc cricket::VoiceChannel::SetLocalContent_w 7 WebRTC 0x10632ec18 cricket::BaseChannel::SetLocalContent 8 WebRTC 0x106384334 rtc::FunctionView::CallVoidPtr 9 WebRTC 0x1063e7f7c rtc::Thread::Dispatch 10 WebRTC 0x1063e7588 rtc::Thread::ProcessMessages 11 WebRTC 0x1063e8238 rtc::Thread::PreRun 12 libsystem_pthread.dylib 0x3be3076cc _pthread_start Thread 0 0 libsystem_kernel.dylib 0x39da42b48 mach_msg2_trap 1 libsystem_kernel.dylib 0x39da55008 mach_msg2_internal 2 libsystem_kernel.dylib 0x39da55248 mach_msg_overwrite 3 libsystem_kernel.dylib 0x39da4308c mach_msg 4 CoreFoundation 0x3242c2af0 5 CoreFoundation 0x3242c3d34 6 CoreFoundation 0x3242c8ed4 CFRunLoopRunSpecific 7 GraphicsServices 0x396943368 GSEventRunModal 8 UIKitCore 0x3289643d0 9 UIKitCore 0x328964034 UIApplicationMain 10 tv 0x204faf158 main (AppDelegate.swift:22) 11 0x1bbba0960 Thread 1 0 libsystem_kernel.dylib 0x39da43050 __workq_kernreturn 1 libsystem_pthread.dylib 0x3be306e44 _pthread_wqthread Thread 2 0 libsystem_kernel.dylib 0x39da43050 __workq_kernreturn 1 libsystem_pthread.dylib 0x3be306e44 _pthread_wqthread Thread 3 name: com.apple.uikit.eventfetch-thread 0 libsystem_kernel.dylib 0x39da42b48 mach_msg2_trap 1 libsystem_kernel.dylib 0x39da55008 mach_msg2_internal 2 libsystem_kernel.dylib 0x39da55248 mach_msg_overwrite 3 libsystem_kernel.dylib 0x39da4308c mach_msg 4 CoreFoundation 0x3242c2af0 5 CoreFoundation 0x3242c3d34 6 CoreFoundation 0x3242c8ed4 CFRunLoopRunSpecific 7 Foundation 0x318a5a334 8 Foundation 0x318a5a21c 9 UIKitCore 0x328a9933c 10 Foundation 0x318a73808 11 libsystem_pthread.dylib 0x3be3076cc _pthread_start Thread 4 0 libsystem_kernel.dylib 0x39da43050 __workq_kernreturn 1 libsystem_pthread.dylib 0x3be306e44 _pthread_wqthread Thread 5 0 libsystem_kernel.dylib 0x39da43050 __workq_kernreturn 1 libsystem_pthread.dylib 0x3be306e44 _pthread_wqthread Thread 6 0 libsystem_kernel.dylib 0x39da43050 __workq_kernreturn 1 libsystem_pthread.dylib 0x3be306e44 _pthread_wqthread Thread 7 0 libsystem_kernel.dylib 0x39da43008 __semwait_signal 1 libsystem_c.dylib 0x332e877d8 nanosleep 2 libsystem_c.dylib 0x332e9bad8 sleep 3 Sentry 0x105f3179c monitorCachedData (SentryCrashCachedData.c:144) 4 libsystem_pthread.dylib 0x3be3076cc _pthread_start Thread 8 name: SentryCrash Exception Handler (Secondary) 0 libsystem_kernel.dylib 0x39da42b48 mach_msg2_trap 1 libsystem_kernel.dylib 0x39da55008 mach_msg2_internal 2 libsystem_kernel.dylib 0x39da55248 mach_msg_overwrite 3 libsystem_kernel.dylib 0x39da4308c mach_msg 4 Sentry 0x105f3d680 handleExceptions (SentryCrashMonitor_MachException.c:303) 5 libsystem_pthread.dylib 0x3be3076cc _pthread_start Thread 10 name: io.sentry.app-hang-tracker 0 libsystem_kernel.dylib 0x39da43008 __semwait_signal 1 libsystem_c.dylib 0x332e877d8 nanosleep 2 Foundation 0x318acab60 3 Sentry 0x105f223f4 -[SentryANRTracker detectANRs] (SentryANRTracker.m:75) 4 Foundation 0x318a73808 5 libsystem_pthread.dylib 0x3be3076cc _pthread_start Thread 11 0 libsystem_pthread.dylib 0x3be306b90 Thread 12 0 libobjc.A.dylib 0x3168a24f0 1 libobjc.A.dylib 0x31689fad0 2 libobjc.A.dylib 0x31689a0c4 3 Foundation 0x318a2cad8 4 Foundation 0x318a2c81c 5 Foundation 0x318a729fc 6 Foundation 0x318a4f6c8 7 Foundation 0x318a4e074 8 CoreFoundation 0x324267d60 9 CoreFoundation 0x3242d0350 _CF_forwarding_prep_0 10 AudioSession 0x3564c4570 11 AudioSession 0x3564c43c4 12 AudioSession 0x3564d3ab4 13 WebRTC 0x1063c6ea0 -[RTCAudioSession overrideOutputAudioPort:error:] 14 WebRTCiOSSDK 0x1075ec000 AntMediaClient.speakerOn 15 WebRTCiOSSDK 0x1075ec1e4 thunk for closure 16 libdispatch.dylib 0x332df64b4 17 libdispatch.dylib 0x332df7fdc 18 libdispatch.dylib 0x332dff694 19 libdispatch.dylib 0x332e001e0 20 libdispatch.dylib 0x332e0ae10 21 libsystem_pthread.dylib 0x3be306df8 _pthread_wqthread Thread 13 name: JavaScriptCore libpas scavenger 0 libsystem_kernel.dylib 0x39da4341c __psynch_cvwait 1 libsystem_pthread.dylib 0x3be30e06c 2 JavaScriptCore 0x34ae8e3ec 3 libsystem_pthread.dylib 0x3be3076cc _pthread_start Thread 14 name: com.apple.NSURLConnectionLoader 0 libsystem_kernel.dylib 0x39da42b48 mach_msg2_trap 1 libsystem_kernel.dylib 0x39da55008 mach_msg2_internal 2 libsystem_kernel.dylib 0x39da55248 mach_msg_overwrite 3 libsystem_kernel.dylib 0x39da4308c mach_msg 4 CoreFoundation 0x3242c2af0 5 CoreFoundation 0x3242c3d34 6 CoreFoundation 0x3242c8ed4 CFRunLoopRunSpecific 7 CFNetwork 0x3267a25a8 _CFURLStorageSessionDisableCache 8 Foundation 0x318a73808 9 libsystem_pthread.dylib 0x3be3076cc _pthread_start Thread 16 0 libsystem_kernel.dylib 0x39da436ac select$DARWIN_EXTSN 1 WebRTC 0x1063e613c rtc::PhysicalSocketServer::WaitSelect 2 WebRTC 0x1063e5f34 rtc::PhysicalSocketServer::Wait 3 WebRTC 0x1063e7c50 rtc::Thread::Get 4 WebRTC 0x1063e7568 rtc::Thread::ProcessMessages 5 WebRTC 0x1063e8238 rtc::Thread::PreRun 6 libsystem_pthread.dylib 0x3be3076cc _pthread_start Thread 17 Crashed: 0 WebRTC 0x1063a09c0 -[RTCVideoEncoderSettings maxFramerate] 1 WebRTC 0x1064a626c webrtc::ios_adm::AudioDeviceIOS::StartPlayout 2 WebRTC 0x1064aa2c0 webrtc::ios_adm::AudioDeviceModuleIOS::StartPlayout 3 WebRTC 0x106597b40 webrtc::internal::AudioState::AddReceivingStream 4 WebRTC 0x106507cc4 cricket::WebRtcVoiceMediaChannel::SetPlayout 5 WebRTC 0x106330268 cricket::VoiceChannel::UpdateMediaSendRecvState_w 6 WebRTC 0x1063304cc cricket::VoiceChannel::SetLocalContent_w 7 WebRTC 0x10632ec18 cricket::BaseChannel::SetLocalContent 8 WebRTC 0x106384334 rtc::FunctionView::CallVoidPtr 9 WebRTC 0x1063e7f7c rtc::Thread::Dispatch 10 WebRTC 0x1063e7588 rtc::Thread::ProcessMessages 11 WebRTC 0x1063e8238 rtc::Thread::PreRun 12 libsystem_pthread.dylib 0x3be3076cc _pthread_start Thread 18 0 libsystem_kernel.dylib 0x39da4341c __psynch_cvwait 1 libsystem_pthread.dylib 0x3be30e06c 2 WebRTC 0x1063e3964 rtc::Event::Wait::lambda::operator() 3 WebRTC 0x1063e3848 rtc::Event::Wait 4 WebRTC 0x1063e35b8 rtc::NullSocketServer::Wait 5 WebRTC 0x1063e8498 rtc::Thread::BlockingCall 6 WebRTC 0x10637ace4 webrtc::SdpOfferAnswerHandler::PushdownMediaDescription 7 WebRTC 0x10637422c webrtc::SdpOfferAnswerHandler::ApplyLocalDescription 8 WebRTC 0x106377c28 webrtc::SdpOfferAnswerHandler::DoSetLocalDescription 9 WebRTC 0x106381620 rtc::rtc_operations_chain_internal::OperationWithFunctor::Run 10 WebRTC 0x1063739d8 webrtc::SdpOfferAnswerHandler::SetLocalDescription 11 WebRTC 0x106322bb8 webrtc::PeerConnection::SetLocalDescription 12 WebRTC 0x10631b074 webrtc::ReturnType::Invoke 13 WebRTC 0x106318bac webrtc::PeerConnectionProxyWithInternal::SetLocalDescription 14 WebRTC 0x1063b1c7c -[RTCPeerConnection setLocalDescription:completionHandler:] 15 WebRTCiOSSDK 0x1075f9764 WebRTCClient.sendAnswer (WebRTCClient.swift:181) 16 WebRTCiOSSDK 0x1075f9b5c thunk for closure 17 WebRTC 0x1063b2e78 webrtc::CreateSessionDescriptionObserverAdapter::OnSuccess 18 WebRTC 0x10638802c absl::internal_any_invocable::RemoteInvoker 19 WebRTC 0x1063e7f7c rtc::Thread::Dispatch 20 WebRTC 0x1063e7588 rtc::Thread::ProcessMessages 21 WebRTC 0x1063e8238 rtc::Thread::PreRun 22 libsystem_pthread.dylib 0x3be3076cc _pthread_start ```
zweropet commented 1 year ago

Have same problem

mekya commented 1 year ago

Hey @denmorgenshtern and @zweropet ,

There is a PR setting mic mute/unmute through setMicStatus method.

https://github.com/ant-media/WebRTC-iOS-SDK/pull/14

Could you please try it?

denmorgenshtern commented 1 year ago

hi @mekya, problem in mute / unmute audio while watching video stream, not mic.

mekya commented 1 year ago

hi @denmorgenshtern ,

Then what about mute/unmute the audio stream on the server side? In this way, the server will not send you the audio packets. If yes, there is a new method in the SDK to enableAudioTrack that receives boolean parameter.

There is also a fix to remove the AntMediaClient reference from AudioSession in the PR mentioned above.

If the solution above does not help you, please let me know.

denmorgenshtern commented 1 year ago

hi @mekya, server side solution doesn't fit for us. Our server broadcasts to many clients, the client should be able to mute / unmute the audio locally on his side.

mekya commented 1 year ago

Hi @denmorgenshtern ,

I mean mute/unmute the audio stream on the server side not for any one, just specifically for the user. In this way, you can also to save CPU and bandwidth.

Anyway, if you just want to mute/unmute the video, it's an iOS development for the Shared Audio Instance. If you need a specific method for the iOS SDK, please let me know.