From b6348e6f029ecaaa9c061b026390cbe5efb184b2 Mon Sep 17 00:00:00 2001 From: Benjamin Reis Date: Wed, 16 Aug 2017 15:42:17 +0200 Subject: [PATCH] ref and unref pending call and address in provider delegates --- Classes/ProviderDelegate.h | 2 +- Classes/ProviderDelegate.m | 31 +++++++++++++++++++++++-------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/Classes/ProviderDelegate.h b/Classes/ProviderDelegate.h index 00a96b98c..488a4316e 100644 --- a/Classes/ProviderDelegate.h +++ b/Classes/ProviderDelegate.h @@ -18,7 +18,7 @@ @property CXCallController *controller; @property NSMutableDictionary *calls; @property NSMutableDictionary *uuids; -@property LinphoneCall *pendingCall; +@property(nonatomic) LinphoneCall *pendingCall; @property LinphoneAddress *pendingAddr; @property BOOL pendingCallVideo; @property int callKitCalls; diff --git a/Classes/ProviderDelegate.m b/Classes/ProviderDelegate.m index 2a53eca43..3479aaaee 100644 --- a/Classes/ProviderDelegate.m +++ b/Classes/ProviderDelegate.m @@ -89,6 +89,17 @@ }]; } +- (void)setPendingCall:(LinphoneCall *)pendingCall { + if (pendingCall) { + _pendingCall = pendingCall; + if (_pendingCall) + linphone_call_ref(_pendingCall); + } else if (_pendingCall) { + linphone_call_unref(_pendingCall); + _pendingCall = NULL; + } +} + #pragma mark - CXProdiverDelegate Protocol - (void)provider:(CXProvider *)provider performAnswerCallAction:(CXAnswerCallAction *)action { @@ -125,7 +136,7 @@ call = [LinphoneManager.instance callByCallId:callID]; } if (call != NULL) { - _pendingCall = call; + self.pendingCall = call; } } @@ -192,7 +203,7 @@ linphone_core_enter_conference(LC); [NSNotificationCenter.defaultCenter postNotificationName:kLinphoneCallUpdate object:self]; } else { - _pendingCall = call; + self.pendingCall = call; } } } @@ -211,14 +222,14 @@ - (void)provider:(CXProvider *)provider didActivateAudioSession:(AVAudioSession *)audioSession { LOGD(@"CallKit : Audio session activated"); // Now we can (re)start the call - if (_pendingCall) { - LinphoneCallState state = linphone_call_get_state(_pendingCall); + if (self.pendingCall) { + LinphoneCallState state = linphone_call_get_state(self.pendingCall); switch (state) { case LinphoneCallIncomingReceived: - [LinphoneManager.instance acceptCall:(LinphoneCall *)_pendingCall evenWithVideo:_pendingCallVideo]; + [LinphoneManager.instance acceptCall:(LinphoneCall *)self.pendingCall evenWithVideo:_pendingCallVideo]; break; case LinphoneCallPaused: - linphone_call_resume((LinphoneCall *)_pendingCall); + linphone_call_resume((LinphoneCall *)self.pendingCall); break; case LinphoneCallStreamsRunning: // May happen when multiple calls @@ -234,7 +245,9 @@ } } - _pendingCall = NULL; + self.pendingCall = NULL; + if (_pendingAddr) + linphone_address_unref(_pendingAddr); _pendingAddr = NULL; _pendingCallVideo = FALSE; } @@ -242,7 +255,9 @@ - (void)provider:(CXProvider *)provider didDeactivateAudioSession:(nonnull AVAudioSession *)audioSession { LOGD(@"CallKit : Audio session deactivated"); - _pendingCall = NULL; + self.pendingCall = NULL; + if (_pendingAddr) + linphone_address_unref(_pendingAddr); _pendingAddr = NULL; _pendingCallVideo = FALSE; }