Skip to content
This repository has been archived by the owner on Dec 6, 2023. It is now read-only.

Commit

Permalink
Add a check to see if there is currently audio for a call. (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
Redmer Loen authored May 7, 2018
1 parent 3fc4eac commit 00dfdbc
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Example/VialerSIPLib/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<action selector="useVideoSwichPressed:" destination="AyF-vj-IOS" eventType="touchUpInside" id="bak-YC-pTt"/>
</connections>
</switch>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Unreigster after call" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="hgl-hR-eAW">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Unregister after call" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="hgl-hR-eAW">
<rect key="frame" x="18" y="521" width="210" height="30"/>
<fontDescription key="fontDescription" type="system" pointSize="25"/>
<color key="textColor" red="0.0" green="0.48058944939999998" blue="0.99789065119999998" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
Expand Down
8 changes: 8 additions & 0 deletions Example/VialerSIPLib/VSLCallViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class VSLCallViewController: UIViewController, VSLKeypadViewControllerDelegate {
activeCall?.addObserver(self, forKeyPath: "callState", options: .new, context: &myContext)
activeCall?.addObserver(self, forKeyPath: "onHold", options: .new, context: &myContext)
NotificationCenter.default.addObserver(self, selector: #selector(updateUI), name: NSNotification.Name(rawValue: VSLAudioControllerAudioInterrupted), object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(noAudioForCall), name: Notification.Name.VSLCallNoAudioForCall, object: nil)
}

override func viewWillDisappear(_ animated: Bool) {
Expand All @@ -63,6 +64,7 @@ class VSLCallViewController: UIViewController, VSLKeypadViewControllerDelegate {
activeCall?.removeObserver(self, forKeyPath: "callState")
activeCall?.removeObserver(self, forKeyPath: "onHold")
NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: VSLAudioControllerAudioInterrupted), object: nil)
NotificationCenter.default.removeObserver(self, name: Notification.Name.VSLCallNoAudioForCall, object: nil)
}

// MARK: - Outlets
Expand Down Expand Up @@ -168,6 +170,12 @@ class VSLCallViewController: UIViewController, VSLKeypadViewControllerDelegate {
}
}

@objc func noAudioForCall() {
guard let call = activeCall, call.callState != .disconnected else { return }

call.reinvite()
}

@objc func updateUI() {
guard let call = activeCall else { return }
updateLabels(call: call, statusLabel: statusLabel, numberLabel: numberLabel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#import "DDLogWrapper.h"
#import <VialerSIPLib/VSLAudioController.h>
#import <VialerSIPLib/VSLCall.h>
#import <VialerSIPLib/VialerSIPLib.h>
#import <VialerSIPLib/VSLRingtone.h>
#import <VialerSIPLib/CallKitProviderDelegate.h>
Expand Down
9 changes: 8 additions & 1 deletion Pod/Classes/VSLCall.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,16 @@ extern NSString * _Nonnull const VSLCallStateChangedNotification;
*/
extern NSString * _Nonnull const VSLNotificationUserInfoVideoSizeRenderKey;

/**
* Notification for when the VSLCall object has been dealloced.
*/
extern NSString * _Nonnull const VSLCallDeallocNotification;

/**
* Notification for when there is no audio during a call.
*/
extern NSString * _Nonnull const VSLCallNoAudioForCallNotification;

/**
* Notification that will be posted when a phonecall is connected.
*/
Expand All @@ -34,7 +42,6 @@ extern NSString * _Nonnull const VSLCallConnectedNotification DEPRECATED_MSG_ATT
*/
extern NSString * _Nonnull const VSLCallDisconnectedNotification DEPRECATED_MSG_ATTRIBUTE("Deprecated, listen for VSLCallStateChangedNotification instead");


/**
* The posible errors VSLCall can return.
*/
Expand Down
38 changes: 37 additions & 1 deletion Pod/Classes/VSLCall.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
NSString * const VSLCallConnectedNotification = @"VSLCallConnectedNotification";
NSString * const VSLCallDisconnectedNotification = @"VSLCallDisconnectedNotification";
NSString * const VSLCallDeallocNotification = @"VSLCallDeallocNotification";
NSString * const VSLCallNoAudioForCallNotification = @"VSLCallNoAudioForCallNotification";

@interface VSLCall()
@property (readwrite, nonatomic) VSLCallState callState;
Expand Down Expand Up @@ -51,6 +52,8 @@ @interface VSLCall()
@property (strong, nonatomic) NSString *numberToCall;
@property (weak, nonatomic) VSLAccount *account;
@property (nonatomic) BOOL reinviteCall;
@property (readwrite, nonatomic) NSTimer *audioCheckTimer;
@property (readwrite, nonatomic) int audioCheckTimerFired;
/**
* Stats
*/
Expand Down Expand Up @@ -388,9 +391,42 @@ - (void)mediaStateChanged:(pjsua_call_info)callInfo {
pjsua_conf_connect(0, callInfo.conf_slot);
}

if (self.mediaState == VSLMediaStateActive && ![self.audioCheckTimer isValid]) {
dispatch_async(dispatch_get_main_queue(), ^{
self.audioCheckTimerFired = 0;
self.audioCheckTimer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(checkIfAudioPresent) userInfo: nil repeats: YES];
});
}

[self updateCallInfo:callInfo];
}

- (void)checkIfAudioPresent {
pjsua_call_info callInfo;
pjsua_call_get_info((pjsua_call_id)self.callId, &callInfo);

pj_status_t status;
pjsua_stream_stat stream_stat;
status = pjsua_call_get_stream_stat((pjsua_call_id)self.callId, callInfo.media[0].index, &stream_stat);

int rxPkt = stream_stat.rtcp.rx.pkt;
int txPkt = stream_stat.rtcp.tx.pkt;

if (rxPkt == 0 || txPkt == 0) {
VSLLogWarning(@"There is NO audio %f: sec into the call. Trying a reinvite", self.lastSeenConnectDuration);
[[NSNotificationCenter defaultCenter] postNotificationName:VSLCallNoAudioForCallNotification object:nil];
[self.audioCheckTimer invalidate];
}

if (self.audioCheckTimerFired > 5) {
VSLLogInfo(@"There is audio in the last 10 seconds rxPkt: %d and txPkt: %d", rxPkt, txPkt);
[self.audioCheckTimer invalidate];
self.audioCheckTimerFired = 0;
}

self.audioCheckTimerFired++;
}

#pragma mark - User actions
- (void)answerWithCompletion:(void (^)(NSError *error))completion {
pj_status_t status;
Expand Down Expand Up @@ -729,7 +765,6 @@ - (void)calculateStats {
VSLLogError(@"Stream is not active!");
}


VSLCallStats *callStats = [[VSLCallStats alloc] initWithCall: self];
NSDictionary *stats = [callStats generate];
if ([stats count] > 0) {
Expand All @@ -740,6 +775,7 @@ - (void)calculateStats {

VSLLogDebug(@"activeCodec: %@ with MOS score: %f and MBs used: %f", self.activeCodec, self.MOS, self.totalMBsUsed);
}
[self.audioCheckTimer invalidate];
}

- (NSString *)debugDescription {
Expand Down
1 change: 1 addition & 0 deletions Pod/Classes/VSLEndpoint.m
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,7 @@ static void onRegState2(pjsua_acc_id acc_id, pjsua_reg_info *info) {
if ([VSLEndpoint sharedEndpoint].ipChangeInProgress) {
// When disableVideoSupport is on reinivite the calls again. And in the reinivite
// disable the video stream. Otherwise the response is an 488 Not Acceptatble here.
// When videosupport has been disabled in the PBX.
if ([VSLEndpoint sharedEndpoint].endpointConfiguration.disableVideoSupport) {
VSLIpChangeConfiguration *ipChangeConfiguration = [VSLEndpoint sharedEndpoint].endpointConfiguration.ipChangeConfiguration;
VSLAccount *account = [[VSLEndpoint sharedEndpoint] lookupAccount:acc_id];
Expand Down

0 comments on commit 00dfdbc

Please sign in to comment.