From f5b7ebf56e5368419257a7454c69ee604a6120b4 Mon Sep 17 00:00:00 2001 From: Danmei Chen Date: Wed, 3 Apr 2019 15:47:58 +0200 Subject: [PATCH] add early-media and disable it by default --- Classes/Base.lproj/CallIncomingView.xib | 164 ++++++++++-------- Classes/CallIncomingView.h | 5 + Classes/CallIncomingView.m | 21 +++ Classes/LinphoneCoreSettingsStore.m | 3 + Classes/LinphoneManager.m | 22 ++- Classes/SettingsView.m | 4 + Resources/linphonerc-factory | 2 + Settings/InAppSettings.bundle/Call.plist | 10 ++ .../fr.lproj/Call.strings | Bin 636 -> 730 bytes 9 files changed, 146 insertions(+), 85 deletions(-) diff --git a/Classes/Base.lproj/CallIncomingView.xib b/Classes/Base.lproj/CallIncomingView.xib index e9a8a5437..4577ebeb3 100644 --- a/Classes/Base.lproj/CallIncomingView.xib +++ b/Classes/Base.lproj/CallIncomingView.xib @@ -1,14 +1,19 @@ - - + + + + + - + + + @@ -19,58 +24,44 @@ - + - + - + - - - + - + + + + - + - - - + + @@ -169,24 +178,10 @@ - - + + - - @@ -197,7 +192,7 @@ - + @@ -211,7 +206,7 @@ - + @@ -220,19 +215,19 @@ - + @@ -280,24 +275,41 @@ + + + - + - - - - + + - + - - - - + + + + diff --git a/Classes/CallIncomingView.h b/Classes/CallIncomingView.h index 05d12b915..6007993cb 100644 --- a/Classes/CallIncomingView.h +++ b/Classes/CallIncomingView.h @@ -34,6 +34,9 @@ @interface CallIncomingView : TPMultiLayoutViewController { } + +@property(nonatomic) Boolean earlyMedia; + @property(weak, nonatomic) IBOutlet UILabel *nameLabel; @property(nonatomic, strong) IBOutlet UILabel *addressLabel; @property(nonatomic, strong) IBOutlet UIRoundedImageView *avatarImage; @@ -41,6 +44,8 @@ @property(nonatomic, strong) id delegate; @property(weak, nonatomic) IBOutlet UIView *tabVideoBar; @property(weak, nonatomic) IBOutlet UIView *tabBar; +@property (weak, nonatomic) IBOutlet UIView *earlyMediaView; + - (IBAction)onAcceptClick:(id)event; - (IBAction)onDeclineClick:(id)event; diff --git a/Classes/CallIncomingView.m b/Classes/CallIncomingView.m index c81d20549..a91a80b92 100644 --- a/Classes/CallIncomingView.m +++ b/Classes/CallIncomingView.m @@ -66,6 +66,10 @@ static UICompositeViewDescription *compositeDescription = nil; - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { [super didRotateFromInterfaceOrientation:fromInterfaceOrientation]; + if (_earlyMedia && [LinphoneManager.instance lpConfigBoolForKey:@"pref_accept_early_media"] && linphone_core_get_calls_nb(LC) < 2) { + _earlyMediaView.hidden = NO; + linphone_core_set_native_video_window_id(LC, (__bridge void *)(_earlyMediaView)); + } if (_call) { [self update]; } @@ -105,9 +109,26 @@ static UICompositeViewDescription *compositeDescription = nil; } #pragma mark - Property Functions +static void hideSpinner(LinphoneCall *call, void *user_data) { + CallIncomingView *thiz = (__bridge CallIncomingView *)user_data; + thiz.earlyMedia = TRUE; + thiz.earlyMediaView.hidden = NO; + linphone_core_set_native_video_window_id(LC, (__bridge void *)(thiz.earlyMediaView)); +} - (void)setCall:(LinphoneCall *)call { _call = call; + _earlyMedia = FALSE; + if ([LinphoneManager.instance lpConfigBoolForKey:@"pref_accept_early_media"] && linphone_core_get_calls_nb(LC) < 2) { + linphone_call_accept_early_media(_call); + // linphone_call_params_get_used_video_codec return 0 if no video stream enabled + if (linphone_call_params_get_used_video_codec(linphone_call_get_current_params(_call))) { + linphone_call_set_next_video_frame_decoded_callback(call, hideSpinner, (__bridge void *)(self)); + } + } else { + _earlyMediaView.hidden = YES; + } + [self update]; [self callUpdate:_call state:linphone_call_get_state(call)]; } diff --git a/Classes/LinphoneCoreSettingsStore.m b/Classes/LinphoneCoreSettingsStore.m index 9345e23f9..614a3681f 100644 --- a/Classes/LinphoneCoreSettingsStore.m +++ b/Classes/LinphoneCoreSettingsStore.m @@ -330,6 +330,8 @@ [self setBool:[lm lpConfigBoolForKey:@"repeat_call_notification"] forKey:@"repeat_call_notification_preference"]; + [self setBool:[lm lpConfigBoolForKey:@"pref_accept_early_media"] + forKey:@"pref_accept_early_media_preference"]; } // chat section @@ -767,6 +769,7 @@ linphone_core_set_in_call_timeout(LC, [self integerForKey:@"in_call_timeout_preference"]); [lm lpConfigSetString:[self stringForKey:@"voice_mail_uri_preference"] forKey:@"voice_mail_uri"]; [lm lpConfigSetBool:[self boolForKey:@"repeat_call_notification_preference"] forKey:@"repeat_call_notification"]; + [lm lpConfigSetBool:[self boolForKey:@"pref_accept_early_media_preference"] forKey:@"pref_accept_early_media"]; // chat section int val = [self integerForKey:@"use_lime_preference"]; diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index a83a18666..a6cd44017 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -622,18 +622,22 @@ static void linphone_iphone_display_status(struct _LinphoneCore *lc, const char if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_9_x_Max) { if (call && (linphone_core_get_calls_nb(LC) < 2)) { + if ([LinphoneManager.instance lpConfigBoolForKey:@"pref_accept_early_media"]) { + [PhoneMainView.instance displayIncomingCall:call]; + } else { #if !TARGET_IPHONE_SIMULATOR - NSString *callId = [NSString stringWithUTF8String:linphone_call_log_get_call_id(linphone_call_get_call_log(call))]; - NSUUID *uuid = [NSUUID UUID]; - [LinphoneManager.instance.providerDelegate.calls setObject:callId forKey:uuid]; - [LinphoneManager.instance.providerDelegate.uuids setObject:uuid forKey:callId]; - BOOL video = ([UIApplication sharedApplication].applicationState == UIApplicationStateActive && - linphone_video_activation_policy_get_automatically_accept(linphone_core_get_video_activation_policy(LC)) && - linphone_call_params_video_enabled(linphone_call_get_remote_params(call))); - [LinphoneManager.instance.providerDelegate reportIncomingCall:call withUUID:uuid handle:address video:video]; + NSString *callId = [NSString stringWithUTF8String:linphone_call_log_get_call_id(linphone_call_get_call_log(call))]; + NSUUID *uuid = [NSUUID UUID]; + [LinphoneManager.instance.providerDelegate.calls setObject:callId forKey:uuid]; + [LinphoneManager.instance.providerDelegate.uuids setObject:uuid forKey:callId]; + BOOL video = ([UIApplication sharedApplication].applicationState == UIApplicationStateActive && + linphone_video_activation_policy_get_automatically_accept(linphone_core_get_video_activation_policy(LC)) && + linphone_call_params_video_enabled(linphone_call_get_remote_params(call))); + [LinphoneManager.instance.providerDelegate reportIncomingCall:call withUUID:uuid handle:address video:video]; #else - [PhoneMainView.instance displayIncomingCall:call]; + [PhoneMainView.instance displayIncomingCall:call]; #endif + } } else if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive) { // Create a UNNotification UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init]; diff --git a/Classes/SettingsView.m b/Classes/SettingsView.m index d60dbd860..e0e711453 100644 --- a/Classes/SettingsView.m +++ b/Classes/SettingsView.m @@ -707,6 +707,10 @@ void update_hash_cbs(LinphoneAccountCreator *creator, LinphoneAccountCreatorStat if ([[UIDevice currentDevice].systemVersion floatValue] < 8) { [hiddenKeys addObject:@"repeat_call_notification_preference"]; } + + if (![lm lpConfigBoolForKey:@"accept_early_media" inSection:@"app"]) { + [hiddenKeys addObject:@"pref_accept_early_media_preference"]; + } if (![[lm lpConfigStringForKey:@"auto_download_mode"] isEqualToString:@"Customize"]) { [hiddenKeys addObject:@"auto_download_incoming_files_max_size"]; diff --git a/Resources/linphonerc-factory b/Resources/linphonerc-factory index 383f76700..f88c40585 100644 --- a/Resources/linphonerc-factory +++ b/Resources/linphonerc-factory @@ -22,6 +22,8 @@ send_logs_include_linphonerc_and_chathistory=0 #use_phone_number=0 publish_presence=0 +accept_early_media=0 + [assistant] password_length=-1 username_length=-1 diff --git a/Settings/InAppSettings.bundle/Call.plist b/Settings/InAppSettings.bundle/Call.plist index d7c407cc8..5245da068 100644 --- a/Settings/InAppSettings.bundle/Call.plist +++ b/Settings/InAppSettings.bundle/Call.plist @@ -88,6 +88,16 @@ Type PSToggleSwitchSpecifier + + DefaultValue + + Key + pref_accept_early_media_preference + Title + Accept early-media + Type + PSToggleSwitchSpecifier + diff --git a/Settings/InAppSettings.bundle/fr.lproj/Call.strings b/Settings/InAppSettings.bundle/fr.lproj/Call.strings index 7ba96833f89e9118d7cce85c2ef1523c90ccd36c..6a37d55a075302edfe216ab61aeef907e97355dc 100644 GIT binary patch delta 102 zcmeyva*K6C4O5&FgCj#S5T-H|FqAMT0O>@AB8D7>N(NnqTp%xnArmN~1eCD_VpP?s NK$W<4STk@j002q_69E7K delta 7 Ocmcb``iEsh4HEzkAp;Ho