Tried to fix problems with MGMSIP.

This commit is contained in:
GRMrGecko 2010-09-21 20:47:54 -05:00
parent f52814a819
commit 7278b4e612
6 changed files with 127 additions and 47 deletions

View File

@ -125,7 +125,7 @@ typedef enum {
- (void)stop; - (void)stop;
- (void)restart; - (void)restart;
- (void)registerThread; - (void)registerThread:(pj_thread_desc *)thePJThreadDesc;
- (void)loginToAccount:(MGMSIPAccount *)theAccount; - (void)loginToAccount:(MGMSIPAccount *)theAccount;
- (void)logoutOfAccount:(MGMSIPAccount *)theAccount; - (void)logoutOfAccount:(MGMSIPAccount *)theAccount;

View File

@ -359,7 +359,8 @@ static OSStatus MGMAudioDevicesChanged(AudioHardwarePropertyID propertyID, void
[pool drain]; [pool drain];
return; return;
} }
[self registerThread]; pj_thread_desc PJThreadDesc;
[self registerThread:&PJThreadDesc];
PJPool = pjsua_pool_create("MGMSIP-pjsua", 1000, 1000); PJPool = pjsua_pool_create("MGMSIP-pjsua", 1000, 1000);
@ -427,6 +428,7 @@ static OSStatus MGMAudioDevicesChanged(AudioHardwarePropertyID propertyID, void
status = pjsua_init(&sipConfig, &loggingConfig, &mediaConfig); status = pjsua_init(&sipConfig, &loggingConfig, &mediaConfig);
if (status!=PJ_SUCCESS) { if (status!=PJ_SUCCESS) {
NSLog(@"Error initializing PJSUA"); NSLog(@"Error initializing PJSUA");
bzero(&PJThreadDesc, sizeof(pj_thread_desc));
[self stop]; [self stop];
[lock unlock]; [lock unlock];
[pool drain]; [pool drain];
@ -438,6 +440,7 @@ static OSStatus MGMAudioDevicesChanged(AudioHardwarePropertyID propertyID, void
status = pjmedia_tonegen_create2(PJPool, &name, mediaConfig.clock_rate, mediaConfig.channel_count, samplesPerFrame, 16, PJMEDIA_TONEGEN_LOOP, &ringbackPort); status = pjmedia_tonegen_create2(PJPool, &name, mediaConfig.clock_rate, mediaConfig.channel_count, samplesPerFrame, 16, PJMEDIA_TONEGEN_LOOP, &ringbackPort);
if (status!=PJ_SUCCESS) { if (status!=PJ_SUCCESS) {
NSLog(@"Error creating ringback tones"); NSLog(@"Error creating ringback tones");
bzero(&PJThreadDesc, sizeof(pj_thread_desc));
[self stop]; [self stop];
[lock unlock]; [lock unlock];
[pool drain]; [pool drain];
@ -456,6 +459,7 @@ static OSStatus MGMAudioDevicesChanged(AudioHardwarePropertyID propertyID, void
status = pjsua_conf_add_port(PJPool, ringbackPort, &ringbackSlot); status = pjsua_conf_add_port(PJPool, ringbackPort, &ringbackSlot);
if (status!=PJ_SUCCESS) { if (status!=PJ_SUCCESS) {
NSLog(@"Error adding ringback tone"); NSLog(@"Error adding ringback tone");
bzero(&PJThreadDesc, sizeof(pj_thread_desc));
[self stop]; [self stop];
[lock unlock]; [lock unlock];
[pool drain]; [pool drain];
@ -470,6 +474,7 @@ static OSStatus MGMAudioDevicesChanged(AudioHardwarePropertyID propertyID, void
status = pjsua_transport_create(PJSIP_TRANSPORT_UDP, &transportConfig, &UDPTransport); status = pjsua_transport_create(PJSIP_TRANSPORT_UDP, &transportConfig, &UDPTransport);
if (status!=PJ_SUCCESS) { if (status!=PJ_SUCCESS) {
NSLog(@"Error creating transport"); NSLog(@"Error creating transport");
bzero(&PJThreadDesc, sizeof(pj_thread_desc));
[self stop]; [self stop];
[lock unlock]; [lock unlock];
[pool drain]; [pool drain];
@ -492,6 +497,7 @@ static OSStatus MGMAudioDevicesChanged(AudioHardwarePropertyID propertyID, void
status = pjsua_start(); status = pjsua_start();
if (status!=PJ_SUCCESS) { if (status!=PJ_SUCCESS) {
NSLog(@"Error starting PJSUA"); NSLog(@"Error starting PJSUA");
bzero(&PJThreadDesc, sizeof(pj_thread_desc));
[self stop]; [self stop];
[lock unlock]; [lock unlock];
[pool drain]; [pool drain];
@ -513,6 +519,7 @@ static OSStatus MGMAudioDevicesChanged(AudioHardwarePropertyID propertyID, void
NSLog(@"MGMSIP Started"); NSLog(@"MGMSIP Started");
bzero(&PJThreadDesc, sizeof(pj_thread_desc));
[lock unlock]; [lock unlock];
[pool drain]; [pool drain];
} }
@ -532,7 +539,8 @@ static OSStatus MGMAudioDevicesChanged(AudioHardwarePropertyID propertyID, void
[accounts makeObjectsPerformSelector:@selector(logout)]; [accounts makeObjectsPerformSelector:@selector(logout)];
[self registerThread]; pj_thread_desc PJThreadDesc;
[self registerThread:&PJThreadDesc];
if (ringbackPort!=NULL && ringbackSlot!=PJSUA_INVALID_ID) { if (ringbackPort!=NULL && ringbackSlot!=PJSUA_INVALID_ID) {
pjsua_conf_remove_port(ringbackSlot); pjsua_conf_remove_port(ringbackSlot);
@ -551,6 +559,7 @@ static OSStatus MGMAudioDevicesChanged(AudioHardwarePropertyID propertyID, void
status = pjsua_destroy(); status = pjsua_destroy();
if (status!=PJ_SUCCESS) if (status!=PJ_SUCCESS)
NSLog(@"Error stopping SIP"); NSLog(@"Error stopping SIP");
bzero(&PJThreadDesc, sizeof(pj_thread_desc));
state = MGMSIPStoppedState; state = MGMSIPStoppedState;
@ -596,11 +605,10 @@ static OSStatus MGMAudioDevicesChanged(AudioHardwarePropertyID propertyID, void
[self stop]; [self stop];
} }
- (void)registerThread { - (void)registerThread:(pj_thread_desc *)thePJThreadDesc {
pj_thread_desc PJThreadDesc;
if (!pj_thread_is_registered()) { if (!pj_thread_is_registered()) {
pj_thread_t *PJThread; pj_thread_t *PJThread;
pj_status_t status = pj_thread_register(NULL, PJThreadDesc, &PJThread); pj_status_t status = pj_thread_register(NULL, *thePJThreadDesc, &PJThread);
if (status!=PJ_SUCCESS) if (status!=PJ_SUCCESS)
NSLog(@"Error registering thread for PJSUA with status %d", status); NSLog(@"Error registering thread for PJSUA with status %d", status);
} }
@ -625,7 +633,8 @@ static OSStatus MGMAudioDevicesChanged(AudioHardwarePropertyID propertyID, void
return; return;
} }
[self registerThread]; pj_thread_desc PJThreadDesc;
[self registerThread:&PJThreadDesc];
pjsua_acc_config accountConfig; pjsua_acc_config accountConfig;
pjsua_acc_config_default(&accountConfig); pjsua_acc_config_default(&accountConfig);
@ -666,11 +675,13 @@ static OSStatus MGMAudioDevicesChanged(AudioHardwarePropertyID propertyID, void
[theAccount loginErrored]; [theAccount loginErrored];
NSLog(@"Error With Account %@: %@", theAccount, [theAccount lastError]); NSLog(@"Error With Account %@: %@", theAccount, [theAccount lastError]);
[accounts removeObject:theAccount]; [accounts removeObject:theAccount];
bzero(&PJThreadDesc, sizeof(pj_thread_desc));
[pool drain]; [pool drain];
return; return;
} }
[theAccount setIdentifier:identifier]; [theAccount setIdentifier:identifier];
[theAccount setOnline:YES]; [theAccount setOnline:YES];
bzero(&PJThreadDesc, sizeof(pj_thread_desc));
if (delegate!=nil && [delegate respondsToSelector:@selector(accountLoggedIn:)]) [delegate accountLoggedIn:theAccount]; if (delegate!=nil && [delegate respondsToSelector:@selector(accountLoggedIn:)]) [delegate accountLoggedIn:theAccount];
if ([theAccount delegate]!=nil && [[theAccount delegate] respondsToSelector:@selector(loggedIn)]) [[theAccount delegate] loggedIn]; if ([theAccount delegate]!=nil && [[theAccount delegate] respondsToSelector:@selector(loggedIn)]) [[theAccount delegate] loggedIn];
[pool drain]; [pool drain];
@ -686,7 +697,8 @@ static OSStatus MGMAudioDevicesChanged(AudioHardwarePropertyID propertyID, void
return; return;
} }
[self registerThread]; pj_thread_desc PJThreadDesc;
[self registerThread:&PJThreadDesc];
pj_status_t status = pjsua_acc_del([theAccount identifier]); pj_status_t status = pjsua_acc_del([theAccount identifier]);
if (status!=PJ_SUCCESS) { if (status!=PJ_SUCCESS) {
@ -700,6 +712,7 @@ static OSStatus MGMAudioDevicesChanged(AudioHardwarePropertyID propertyID, void
if (delegate!=nil && [delegate respondsToSelector:@selector(accountLoggedOut:)]) [delegate accountLoggedOut:theAccount]; if (delegate!=nil && [delegate respondsToSelector:@selector(accountLoggedOut:)]) [delegate accountLoggedOut:theAccount];
if ([theAccount delegate]!=nil && [[theAccount delegate] respondsToSelector:@selector(loggedOut)]) [[theAccount delegate] loggedOut]; if ([theAccount delegate]!=nil && [[theAccount delegate] respondsToSelector:@selector(loggedOut)]) [[theAccount delegate] loggedOut];
[accounts removeObject:theAccount]; [accounts removeObject:theAccount];
bzero(&PJThreadDesc, sizeof(pj_thread_desc));
[pool drain]; [pool drain];
} }
@ -722,30 +735,36 @@ static OSStatus MGMAudioDevicesChanged(AudioHardwarePropertyID propertyID, void
} }
- (void)hangUpAllCalls { - (void)hangUpAllCalls {
[self registerThread]; pj_thread_desc PJThreadDesc;
[self registerThread:&PJThreadDesc];
pjsua_call_hangup_all(); pjsua_call_hangup_all();
bzero(&PJThreadDesc, sizeof(pj_thread_desc));
} }
- (float)volume { - (float)volume {
return [[NSUserDefaults standardUserDefaults] floatForKey:MGMSIPVolume]; return [[NSUserDefaults standardUserDefaults] floatForKey:MGMSIPVolume];
} }
- (void)setVolume:(float)theVolume { - (void)setVolume:(float)theVolume {
[self registerThread]; pj_thread_desc PJThreadDesc;
[self registerThread:&PJThreadDesc];
[[NSUserDefaults standardUserDefaults] setFloat:theVolume forKey:MGMSIPVolume]; [[NSUserDefaults standardUserDefaults] setFloat:theVolume forKey:MGMSIPVolume];
pjsua_conf_adjust_tx_level(0, theVolume); pjsua_conf_adjust_tx_level(0, theVolume);
[[NSNotificationCenter defaultCenter] postNotificationName:MGMSIPVolumeChangedNotification object:[NSNumber numberWithFloat:theVolume]]; [[NSNotificationCenter defaultCenter] postNotificationName:MGMSIPVolumeChangedNotification object:[NSNumber numberWithFloat:theVolume]];
bzero(&PJThreadDesc, sizeof(pj_thread_desc));
} }
- (float)micVolume { - (float)micVolume {
return [[NSUserDefaults standardUserDefaults] floatForKey:MGMSIPMicVolume]; return [[NSUserDefaults standardUserDefaults] floatForKey:MGMSIPMicVolume];
} }
- (void)setMicVolume:(float)theVolume { - (void)setMicVolume:(float)theVolume {
[self registerThread]; pj_thread_desc PJThreadDesc;
[self registerThread:&PJThreadDesc];
[[NSUserDefaults standardUserDefaults] setFloat:theVolume forKey:MGMSIPMicVolume]; [[NSUserDefaults standardUserDefaults] setFloat:theVolume forKey:MGMSIPMicVolume];
pjsua_conf_adjust_rx_level(0, theVolume); pjsua_conf_adjust_rx_level(0, theVolume);
[[NSNotificationCenter defaultCenter] postNotificationName:MGMSIPMicVolumeChangedNotification object:[NSNumber numberWithFloat:theVolume]]; [[NSNotificationCenter defaultCenter] postNotificationName:MGMSIPMicVolumeChangedNotification object:[NSNumber numberWithFloat:theVolume]];
bzero(&PJThreadDesc, sizeof(pj_thread_desc));
} }
- (BOOL)setInputSoundDevice:(int)theInputDevice outputSoundDevice:(int)theOutputDevice { - (BOOL)setInputSoundDevice:(int)theInputDevice outputSoundDevice:(int)theOutputDevice {
@ -790,18 +809,22 @@ static OSStatus MGMAudioDevicesChanged(AudioHardwarePropertyID propertyID, void
[defaults setObject:inputDeviceUID forKey:MGMSIPACurrentInputDevice]; [defaults setObject:inputDeviceUID forKey:MGMSIPACurrentInputDevice];
[defaults setObject:outputDeviceUID forKey:MGMSIPACurrentOutputDevice]; [defaults setObject:outputDeviceUID forKey:MGMSIPACurrentOutputDevice];
[self registerThread]; pj_thread_desc PJThreadDesc;
[self registerThread:&PJThreadDesc];
pj_status_t status = pjsua_set_snd_dev(theInputDevice, theOutputDevice); pj_status_t status = pjsua_set_snd_dev(theInputDevice, theOutputDevice);
bzero(&PJThreadDesc, sizeof(pj_thread_desc));
return (status==PJ_SUCCESS); return (status==PJ_SUCCESS);
} }
- (BOOL)stopSound { - (BOOL)stopSound {
if (state!=MGMSIPStartedState) if (state!=MGMSIPStartedState)
return NO; return NO;
[self registerThread]; pj_thread_desc PJThreadDesc;
[self registerThread:&PJThreadDesc];
pj_status_t status = pjsua_set_null_snd_dev(); pj_status_t status = pjsua_set_null_snd_dev();
bzero(&PJThreadDesc, sizeof(pj_thread_desc));
return (status==PJ_SUCCESS); return (status==PJ_SUCCESS);
} }
- (void)updateAudioDevices { - (void)updateAudioDevices {
@ -919,7 +942,8 @@ static OSStatus MGMAudioDevicesChanged(AudioHardwarePropertyID propertyID, void
if (audioDevices!=nil) [audioDevices release]; if (audioDevices!=nil) [audioDevices release];
audioDevices = [devicesArray copy]; audioDevices = [devicesArray copy];
[self registerThread]; pj_thread_desc PJThreadDesc;
[self registerThread:&PJThreadDesc];
pjsua_set_null_snd_dev(); pjsua_set_null_snd_dev();
pjmedia_snd_deinit(); pjmedia_snd_deinit();
@ -928,6 +952,7 @@ static OSStatus MGMAudioDevicesChanged(AudioHardwarePropertyID propertyID, void
[self setInputSoundDevice:currentInput outputSoundDevice:currentOutput]; [self setInputSoundDevice:currentInput outputSoundDevice:currentOutput];
[[NSNotificationCenter defaultCenter] postNotificationName:MGMSIPAudioChangedNotification object:audioDevices]; [[NSNotificationCenter defaultCenter] postNotificationName:MGMSIPAudioChangedNotification object:audioDevices];
bzero(&PJThreadDesc, sizeof(pj_thread_desc));
[pool drain]; [pool drain];
} }
- (NSArray *)audioDevices { - (NSArray *)audioDevices {

View File

@ -247,10 +247,12 @@ const int MGMSIPAccountReregisterTimeoutDefault = 300;
if (identifier==PJSUA_INVALID_ID) if (identifier==PJSUA_INVALID_ID)
return; return;
[[MGMSIP sharedSIP] registerThread]; pj_thread_desc PJThreadDesc;
[[MGMSIP sharedSIP] registerThread:&PJThreadDesc];
pjsua_acc_set_registration(identifier, (isRegistered ? PJ_TRUE : PJ_FALSE)); pjsua_acc_set_registration(identifier, (isRegistered ? PJ_TRUE : PJ_FALSE));
[self setOnline:isRegistered]; [self setOnline:isRegistered];
bzero(&PJThreadDesc, sizeof(pj_thread_desc));
} }
- (void)networkConnected:(NSNotification *)theNotification { - (void)networkConnected:(NSNotification *)theNotification {
if ([self isLoggedIn]) if ([self isLoggedIn])
@ -260,10 +262,12 @@ const int MGMSIPAccountReregisterTimeoutDefault = 300;
if (identifier==PJSUA_INVALID_ID) if (identifier==PJSUA_INVALID_ID)
return 0; return 0;
[[MGMSIP sharedSIP] registerThread]; pj_thread_desc PJThreadDesc;
[[MGMSIP sharedSIP] registerThread:&PJThreadDesc];
pjsua_acc_info accountInfo; pjsua_acc_info accountInfo;
pj_status_t status = pjsua_acc_get_info(identifier, &accountInfo); pj_status_t status = pjsua_acc_get_info(identifier, &accountInfo);
bzero(&PJThreadDesc, sizeof(pj_thread_desc));
if (status!=PJ_SUCCESS) if (status!=PJ_SUCCESS)
return 0; return 0;
return accountInfo.status; return accountInfo.status;
@ -272,10 +276,12 @@ const int MGMSIPAccountReregisterTimeoutDefault = 300;
if (identifier==PJSUA_INVALID_ID) if (identifier==PJSUA_INVALID_ID)
return nil; return nil;
[[MGMSIP sharedSIP] registerThread]; pj_thread_desc PJThreadDesc;
[[MGMSIP sharedSIP] registerThread:&PJThreadDesc];
pjsua_acc_info accountInfo; pjsua_acc_info accountInfo;
pj_status_t status = pjsua_acc_get_info(identifier, &accountInfo); pj_status_t status = pjsua_acc_get_info(identifier, &accountInfo);
bzero(&PJThreadDesc, sizeof(pj_thread_desc));
if (status!=PJ_SUCCESS) if (status!=PJ_SUCCESS)
return nil; return nil;
return [NSString stringWithPJString:accountInfo.status_text]; return [NSString stringWithPJString:accountInfo.status_text];
@ -284,10 +290,12 @@ const int MGMSIPAccountReregisterTimeoutDefault = 300;
if (identifier==PJSUA_INVALID_ID) if (identifier==PJSUA_INVALID_ID)
return -1; return -1;
[[MGMSIP sharedSIP] registerThread]; pj_thread_desc PJThreadDesc;
[[MGMSIP sharedSIP] registerThread:&PJThreadDesc];
pjsua_acc_info accountInfo; pjsua_acc_info accountInfo;
pj_status_t status = pjsua_acc_get_info(identifier, &accountInfo); pj_status_t status = pjsua_acc_get_info(identifier, &accountInfo);
bzero(&PJThreadDesc, sizeof(pj_thread_desc));
if (status!=PJ_SUCCESS) if (status!=PJ_SUCCESS)
return -1; return -1;
return accountInfo.expires; return accountInfo.expires;
@ -297,10 +305,12 @@ const int MGMSIPAccountReregisterTimeoutDefault = 300;
if (identifier==PJSUA_INVALID_ID) if (identifier==PJSUA_INVALID_ID)
return NO; return NO;
[[MGMSIP sharedSIP] registerThread]; pj_thread_desc PJThreadDesc;
[[MGMSIP sharedSIP] registerThread:&PJThreadDesc];
pjsua_acc_info accountInfo; pjsua_acc_info accountInfo;
pj_status_t status = pjsua_acc_get_info(identifier, &accountInfo); pj_status_t status = pjsua_acc_get_info(identifier, &accountInfo);
bzero(&PJThreadDesc, sizeof(pj_thread_desc));
if (status!=PJ_SUCCESS) if (status!=PJ_SUCCESS)
return NO; return NO;
return (accountInfo.online_status==PJ_TRUE); return (accountInfo.online_status==PJ_TRUE);
@ -309,7 +319,8 @@ const int MGMSIPAccountReregisterTimeoutDefault = 300;
if ([self identifier]==PJSUA_INVALID_ID) if ([self identifier]==PJSUA_INVALID_ID)
return; return;
[[MGMSIP sharedSIP] registerThread]; pj_thread_desc PJThreadDesc;
[[MGMSIP sharedSIP] registerThread:&PJThreadDesc];
pj_status_t status = pjsua_acc_set_online_status(identifier, (isOnline ? PJ_TRUE : PJ_FALSE)); pj_status_t status = pjsua_acc_set_online_status(identifier, (isOnline ? PJ_TRUE : PJ_FALSE));
if (status==PJ_SUCCESS) { if (status==PJ_SUCCESS) {
@ -321,15 +332,18 @@ const int MGMSIPAccountReregisterTimeoutDefault = 300;
if (isOnline) if (isOnline)
reregisterTimer = [[NSTimer scheduledTimerWithTimeInterval:(float)reregisterTimeout target:self selector:@selector(reregister) userInfo:nil repeats:YES] retain]; reregisterTimer = [[NSTimer scheduledTimerWithTimeInterval:(float)reregisterTimeout target:self selector:@selector(reregister) userInfo:nil repeats:YES] retain];
} }
bzero(&PJThreadDesc, sizeof(pj_thread_desc));
} }
- (NSString *)onlineStatusText { - (NSString *)onlineStatusText {
if (identifier==PJSUA_INVALID_ID) if (identifier==PJSUA_INVALID_ID)
return nil; return nil;
[[MGMSIP sharedSIP] registerThread]; pj_thread_desc PJThreadDesc;
[[MGMSIP sharedSIP] registerThread:&PJThreadDesc];
pjsua_acc_info accountInfo; pjsua_acc_info accountInfo;
pj_status_t status = pjsua_acc_get_info(identifier, &accountInfo); pj_status_t status = pjsua_acc_get_info(identifier, &accountInfo);
bzero(&PJThreadDesc, sizeof(pj_thread_desc));
if (status!=PJ_SUCCESS) if (status!=PJ_SUCCESS)
return nil; return nil;
return [NSString stringWithPJString:accountInfo.online_status_text]; return [NSString stringWithPJString:accountInfo.online_status_text];
@ -345,7 +359,8 @@ const int MGMSIPAccountReregisterTimeoutDefault = 300;
return [self makeCallToSIPURL:SIPURL]; return [self makeCallToSIPURL:SIPURL];
} }
- (MGMSIPCall *)makeCallToSIPURL:(MGMSIPURL *)theURL { - (MGMSIPCall *)makeCallToSIPURL:(MGMSIPURL *)theURL {
[[MGMSIP sharedSIP] registerThread]; pj_thread_desc PJThreadDesc;
[[MGMSIP sharedSIP] registerThread:&PJThreadDesc];
pjsua_call_id callIdentifier; pjsua_call_id callIdentifier;
pj_str_t url = [[theURL SIPID] PJString]; pj_str_t url = [[theURL SIPID] PJString];
@ -356,6 +371,7 @@ const int MGMSIPAccountReregisterTimeoutDefault = 300;
} else { } else {
call = [self callWithIdentifier:callIdentifier]; call = [self callWithIdentifier:callIdentifier];
} }
bzero(&PJThreadDesc, sizeof(pj_thread_desc));
return call; return call;
} }
- (NSArray *)calls { - (NSArray *)calls {

View File

@ -19,7 +19,8 @@
account = theAccount; account = theAccount;
identifier = theIdentifier; identifier = theIdentifier;
[[MGMSIP sharedSIP] registerThread]; pj_thread_desc PJThreadDesc;
[[MGMSIP sharedSIP] registerThread:&PJThreadDesc];
pjsua_call_info callInfo; pjsua_call_info callInfo;
pj_status_t status = pjsua_call_get_info(identifier, &callInfo); pj_status_t status = pjsua_call_get_info(identifier, &callInfo);
@ -40,6 +41,7 @@
incoming = (state==MGMSIPCallIncomingState); incoming = (state==MGMSIPCallIncomingState);
muted = NO; muted = NO;
} }
bzero(&PJThreadDesc, sizeof(pj_thread_desc));
} }
return self; return self;
} }
@ -142,26 +144,34 @@
if (identifier==PJSUA_INVALID_ID) if (identifier==PJSUA_INVALID_ID)
return NO; return NO;
[[MGMSIP sharedSIP] registerThread]; pj_thread_desc PJThreadDesc;
[[MGMSIP sharedSIP] registerThread:&PJThreadDesc];
return pjsua_call_is_active(identifier); pj_bool_t active = pjsua_call_is_active(identifier);
bzero(&PJThreadDesc, sizeof(pj_thread_desc));
return (active==PJ_TRUE);
} }
- (BOOL)hasMedia { - (BOOL)hasMedia {
if (identifier==PJSUA_INVALID_ID) if (identifier==PJSUA_INVALID_ID)
return NO; return NO;
[[MGMSIP sharedSIP] registerThread]; pj_thread_desc PJThreadDesc;
[[MGMSIP sharedSIP] registerThread:&PJThreadDesc];
return pjsua_call_has_media(identifier); pj_bool_t media = pjsua_call_has_media(identifier);
bzero(&PJThreadDesc, sizeof(pj_thread_desc));
return (media==PJ_TRUE);
} }
- (BOOL)hasActiveMedia { - (BOOL)hasActiveMedia {
if (identifier==PJSUA_INVALID_ID) if (identifier==PJSUA_INVALID_ID)
return NO; return NO;
[[MGMSIP sharedSIP] registerThread]; pj_thread_desc PJThreadDesc;
[[MGMSIP sharedSIP] registerThread:&PJThreadDesc];
pjsua_call_info callInfo; pjsua_call_info callInfo;
pjsua_call_get_info(identifier, &callInfo); pjsua_call_get_info(identifier, &callInfo);
bzero(&PJThreadDesc, sizeof(pj_thread_desc));
return (callInfo.media_status==PJSUA_CALL_MEDIA_ACTIVE); return (callInfo.media_status==PJSUA_CALL_MEDIA_ACTIVE);
} }
@ -175,10 +185,12 @@
if (identifier==PJSUA_INVALID_ID) if (identifier==PJSUA_INVALID_ID)
return NO; return NO;
[[MGMSIP sharedSIP] registerThread]; pj_thread_desc PJThreadDesc;
[[MGMSIP sharedSIP] registerThread:&PJThreadDesc];
pjsua_call_info callInfo; pjsua_call_info callInfo;
pjsua_call_get_info(identifier, &callInfo); pjsua_call_get_info(identifier, &callInfo);
bzero(&PJThreadDesc, sizeof(pj_thread_desc));
return (callInfo.media_status==PJSUA_CALL_MEDIA_REMOTE_HOLD); return (callInfo.media_status==PJSUA_CALL_MEDIA_REMOTE_HOLD);
} }
- (void)setHoldMusicPath:(NSString *)thePath { - (void)setHoldMusicPath:(NSString *)thePath {
@ -186,7 +198,8 @@
holdMusicPath = [thePath copy]; holdMusicPath = [thePath copy];
} }
- (void)hold { - (void)hold {
[[MGMSIP sharedSIP] registerThread]; pj_thread_desc PJThreadDesc;
[[MGMSIP sharedSIP] registerThread:&PJThreadDesc];
if (state==MGMSIPCallConfirmedState) { if (state==MGMSIPCallConfirmedState) {
pjsua_conf_port_id conf_port = pjsua_call_get_conf_port(identifier); pjsua_conf_port_id conf_port = pjsua_call_get_conf_port(identifier);
@ -202,6 +215,7 @@
[self performSelectorOnMainThread:@selector(stopHoldMusic) withObject:nil waitUntilDone:NO]; [self performSelectorOnMainThread:@selector(stopHoldMusic) withObject:nil waitUntilDone:NO];
} }
} }
bzero(&PJThreadDesc, sizeof(pj_thread_desc));
} }
- (void)startHoldMusic { - (void)startHoldMusic {
if (holdMusicPlayer!=PJSUA_INVALID_ID) if (holdMusicPlayer!=PJSUA_INVALID_ID)
@ -217,17 +231,20 @@
if (identifier==PJSUA_INVALID_ID || state==MGMSIPCallDisconnectedState) if (identifier==PJSUA_INVALID_ID || state==MGMSIPCallDisconnectedState)
return; return;
[[MGMSIP sharedSIP] registerThread]; pj_thread_desc PJThreadDesc;
[[MGMSIP sharedSIP] registerThread:&PJThreadDesc];
pj_status_t status = pjsua_call_answer(identifier, PJSIP_SC_OK, NULL, NULL); pj_status_t status = pjsua_call_answer(identifier, PJSIP_SC_OK, NULL, NULL);
if (status!=PJ_SUCCESS) if (status!=PJ_SUCCESS)
NSLog(@"Error answering call %@", self); NSLog(@"Error answering call %@", self);
bzero(&PJThreadDesc, sizeof(pj_thread_desc));
} }
- (void)hangUp { - (void)hangUp {
if (identifier==PJSUA_INVALID_ID || state==MGMSIPCallDisconnectedState) if (identifier==PJSUA_INVALID_ID || state==MGMSIPCallDisconnectedState)
return; return;
[[MGMSIP sharedSIP] registerThread]; pj_thread_desc PJThreadDesc;
[[MGMSIP sharedSIP] registerThread:&PJThreadDesc];
pj_status_t status = pjsua_call_hangup(identifier, 0, NULL, NULL); pj_status_t status = pjsua_call_hangup(identifier, 0, NULL, NULL);
if (status!=PJ_SUCCESS) if (status!=PJ_SUCCESS)
@ -238,22 +255,26 @@
if (identifier==PJSUA_INVALID_ID || state==MGMSIPCallDisconnectedState) if (identifier==PJSUA_INVALID_ID || state==MGMSIPCallDisconnectedState)
return; return;
[[MGMSIP sharedSIP] registerThread]; pj_thread_desc PJThreadDesc;
[[MGMSIP sharedSIP] registerThread:&PJThreadDesc];
pj_status_t status = pjsua_call_answer(identifier, PJSIP_SC_RINGING, NULL, NULL); pj_status_t status = pjsua_call_answer(identifier, PJSIP_SC_RINGING, NULL, NULL);
if (status!=PJ_SUCCESS) if (status!=PJ_SUCCESS)
NSLog(@"Error sending ringing notification to call %@", self); NSLog(@"Error sending ringing notification to call %@", self);
bzero(&PJThreadDesc, sizeof(pj_thread_desc));
} }
- (void)replyWithTemporarilyUnavailable { - (void)replyWithTemporarilyUnavailable {
if (identifier==PJSUA_INVALID_ID || state==MGMSIPCallDisconnectedState) if (identifier==PJSUA_INVALID_ID || state==MGMSIPCallDisconnectedState)
return; return;
[[MGMSIP sharedSIP] registerThread]; pj_thread_desc PJThreadDesc;
[[MGMSIP sharedSIP] registerThread:&PJThreadDesc];
pj_status_t status = pjsua_call_answer(identifier, PJSIP_SC_TEMPORARILY_UNAVAILABLE, NULL, NULL); pj_status_t status = pjsua_call_answer(identifier, PJSIP_SC_TEMPORARILY_UNAVAILABLE, NULL, NULL);
if (status!=PJ_SUCCESS) if (status!=PJ_SUCCESS)
NSLog(@"Error replying 480 Temporarily Unavailable"); NSLog(@"Error replying 480 Temporarily Unavailable");
bzero(&PJThreadDesc, sizeof(pj_thread_desc));
} }
- (void)startRingback { - (void)startRingback {
@ -264,11 +285,13 @@
return; return;
isRingbackOn = YES; isRingbackOn = YES;
[[MGMSIP sharedSIP] registerThread]; pj_thread_desc PJThreadDesc;
[[MGMSIP sharedSIP] registerThread:&PJThreadDesc];
[[MGMSIP sharedSIP] setRingbackCount:[[MGMSIP sharedSIP] ringbackCount]+1]; [[MGMSIP sharedSIP] setRingbackCount:[[MGMSIP sharedSIP] ringbackCount]+1];
if ([[MGMSIP sharedSIP] ringbackCount]==1 && [[MGMSIP sharedSIP] ringbackSlot]!=PJSUA_INVALID_ID) if ([[MGMSIP sharedSIP] ringbackCount]==1 && [[MGMSIP sharedSIP] ringbackSlot]!=PJSUA_INVALID_ID)
pjsua_conf_connect([[MGMSIP sharedSIP] ringbackSlot], 0); pjsua_conf_connect([[MGMSIP sharedSIP] ringbackSlot], 0);
bzero(&PJThreadDesc, sizeof(pj_thread_desc));
} }
- (void)stopRingback { - (void)stopRingback {
if (identifier==PJSUA_INVALID_ID || state==MGMSIPCallDisconnectedState) if (identifier==PJSUA_INVALID_ID || state==MGMSIPCallDisconnectedState)
@ -278,7 +301,8 @@
return; return;
isRingbackOn = NO; isRingbackOn = NO;
[[MGMSIP sharedSIP] registerThread]; pj_thread_desc PJThreadDesc;
[[MGMSIP sharedSIP] registerThread:&PJThreadDesc];
int ringbackCount = [[MGMSIP sharedSIP] ringbackCount]; int ringbackCount = [[MGMSIP sharedSIP] ringbackCount];
if (ringbackCount<0) return; if (ringbackCount<0) return;
@ -287,13 +311,15 @@
pjsua_conf_disconnect([[MGMSIP sharedSIP] ringbackSlot], 0); pjsua_conf_disconnect([[MGMSIP sharedSIP] ringbackSlot], 0);
pjmedia_tonegen_rewind([[MGMSIP sharedSIP] ringbackPort]); pjmedia_tonegen_rewind([[MGMSIP sharedSIP] ringbackPort]);
} }
bzero(&PJThreadDesc, sizeof(pj_thread_desc));
} }
- (void)sendDTMFDigits:(NSString *)theDigits { - (void)sendDTMFDigits:(NSString *)theDigits {
if (identifier==PJSUA_INVALID_ID || state!=MGMSIPCallConfirmedState) if (identifier==PJSUA_INVALID_ID || state!=MGMSIPCallConfirmedState)
return; return;
[[MGMSIP sharedSIP] registerThread]; pj_thread_desc PJThreadDesc;
[[MGMSIP sharedSIP] registerThread:&PJThreadDesc];
pj_str_t digits = [theDigits PJString]; pj_str_t digits = [theDigits PJString];
pj_status_t status = pjsua_call_dial_dtmf(identifier, &digits); pj_status_t status = pjsua_call_dial_dtmf(identifier, &digits);
@ -310,6 +336,7 @@
NSLog(@"Unable to send DTMF with status %d.", status); NSLog(@"Unable to send DTMF with status %d.", status);
} }
} }
bzero(&PJThreadDesc, sizeof(pj_thread_desc));
} }
- (void)playSound:(NSString *)theFile { - (void)playSound:(NSString *)theFile {
@ -325,7 +352,8 @@
if (identifier==PJSUA_INVALID_ID || state!=MGMSIPCallConfirmedState) if (identifier==PJSUA_INVALID_ID || state!=MGMSIPCallConfirmedState)
return PJSUA_INVALID_ID; return PJSUA_INVALID_ID;
[[MGMSIP sharedSIP] registerThread]; pj_thread_desc PJThreadDesc;
[[MGMSIP sharedSIP] registerThread:&PJThreadDesc];
pjsua_player_id player_id = PJSUA_INVALID_ID; pjsua_player_id player_id = PJSUA_INVALID_ID;
if (theFile==nil || ![[NSFileManager defaultManager] fileExistsAtPath:theFile]) if (theFile==nil || ![[NSFileManager defaultManager] fileExistsAtPath:theFile])
@ -340,16 +368,19 @@
if (status!=PJ_SUCCESS) if (status!=PJ_SUCCESS)
NSLog(@"Unable to play sound"); NSLog(@"Unable to play sound");
} }
bzero(&PJThreadDesc, sizeof(pj_thread_desc));
return player_id; return player_id;
} }
- (void)stopPlayingSound:(pjsua_player_id *)thePlayerID { - (void)stopPlayingSound:(pjsua_player_id *)thePlayerID {
if (*thePlayerID==PJSUA_INVALID_ID) if (*thePlayerID==PJSUA_INVALID_ID)
return; return;
[[MGMSIP sharedSIP] registerThread]; pj_thread_desc PJThreadDesc;
[[MGMSIP sharedSIP] registerThread:&PJThreadDesc];
pjsua_player_destroy(*thePlayerID); pjsua_player_destroy(*thePlayerID);
*thePlayerID = PJSUA_INVALID_ID; *thePlayerID = PJSUA_INVALID_ID;
bzero(&PJThreadDesc, sizeof(pj_thread_desc));
} }
- (BOOL)isRecording { - (BOOL)isRecording {
@ -362,7 +393,8 @@
if (recorderID!=PJSUA_INVALID_ID || identifier==PJSUA_INVALID_ID || state!=MGMSIPCallConfirmedState) if (recorderID!=PJSUA_INVALID_ID || identifier==PJSUA_INVALID_ID || state!=MGMSIPCallConfirmedState)
return; return;
[[MGMSIP sharedSIP] registerThread]; pj_thread_desc PJThreadDesc;
[[MGMSIP sharedSIP] registerThread:&PJThreadDesc];
pj_str_t file = [toFile PJString]; pj_str_t file = [toFile PJString];
pj_status_t status = pjsua_recorder_create(&file, 0, NULL, 0, 0, &recorderID); pj_status_t status = pjsua_recorder_create(&file, 0, NULL, 0, 0, &recorderID);
@ -372,6 +404,7 @@
pjsua_conf_connect(pjsua_call_get_conf_port(identifier), pjsua_recorder_get_conf_port(recorderID)); pjsua_conf_connect(pjsua_call_get_conf_port(identifier), pjsua_recorder_get_conf_port(recorderID));
pjsua_conf_connect(0, pjsua_recorder_get_conf_port(recorderID)); pjsua_conf_connect(0, pjsua_recorder_get_conf_port(recorderID));
} }
bzero(&PJThreadDesc, sizeof(pj_thread_desc));
} }
- (void)stopRecording { - (void)stopRecording {
[self performSelectorOnMainThread:@selector(stopRecordingMain) withObject:nil waitUntilDone:YES]; [self performSelectorOnMainThread:@selector(stopRecordingMain) withObject:nil waitUntilDone:YES];
@ -380,10 +413,12 @@
if (recorderID==PJSUA_INVALID_ID) if (recorderID==PJSUA_INVALID_ID)
return; return;
[[MGMSIP sharedSIP] registerThread]; pj_thread_desc PJThreadDesc;
[[MGMSIP sharedSIP] registerThread:&PJThreadDesc];
pjsua_recorder_destroy(recorderID); pjsua_recorder_destroy(recorderID);
recorderID = PJSUA_INVALID_ID; recorderID = PJSUA_INVALID_ID;
bzero(&PJThreadDesc, sizeof(pj_thread_desc));
} }
- (BOOL)isMuted { - (BOOL)isMuted {
@ -393,7 +428,8 @@
if (identifier==PJSUA_INVALID_ID || holdMusicPlayer!=PJSUA_INVALID_ID || state!=MGMSIPCallConfirmedState) if (identifier==PJSUA_INVALID_ID || holdMusicPlayer!=PJSUA_INVALID_ID || state!=MGMSIPCallConfirmedState)
return; return;
[[MGMSIP sharedSIP] registerThread]; pj_thread_desc PJThreadDesc;
[[MGMSIP sharedSIP] registerThread:&PJThreadDesc];
pj_status_t status; pj_status_t status;
if (muted) if (muted)
@ -404,6 +440,7 @@
NSLog(@"Error %@ speakers for call %@", (muted ? @"unmuting" : @"mutting"), self); NSLog(@"Error %@ speakers for call %@", (muted ? @"unmuting" : @"mutting"), self);
else else
muted = !muted; muted = !muted;
bzero(&PJThreadDesc, sizeof(pj_thread_desc));
} }
- (BOOL)isMicMuted { - (BOOL)isMicMuted {
return micMuted; return micMuted;
@ -412,7 +449,8 @@
if (identifier==PJSUA_INVALID_ID || holdMusicPlayer!=PJSUA_INVALID_ID || state!=MGMSIPCallConfirmedState) if (identifier==PJSUA_INVALID_ID || holdMusicPlayer!=PJSUA_INVALID_ID || state!=MGMSIPCallConfirmedState)
return; return;
[[MGMSIP sharedSIP] registerThread]; pj_thread_desc PJThreadDesc;
[[MGMSIP sharedSIP] registerThread:&PJThreadDesc];
pj_status_t status; pj_status_t status;
if (micMuted) if (micMuted)
@ -423,6 +461,7 @@
NSLog(@"Error %@ microphone for call %@", (micMuted ? @"unmuting" : @"mutting"), self); NSLog(@"Error %@ microphone for call %@", (micMuted ? @"unmuting" : @"mutting"), self);
else else
micMuted = !micMuted; micMuted = !micMuted;
bzero(&PJThreadDesc, sizeof(pj_thread_desc));
} }
@end @end
#endif #endif

View File

@ -74,7 +74,7 @@
[NSTask launchedTaskWithLaunchPath:relaunchPath arguments:[NSArray arrayWithObjects:pathToRelaunch, [NSString stringWithFormat:@"%d", [[NSProcessInfo processInfo] processIdentifier]], nil]]; [NSTask launchedTaskWithLaunchPath:relaunchPath arguments:[NSArray arrayWithObjects:pathToRelaunch, [NSString stringWithFormat:@"%d", [[NSProcessInfo processInfo] processIdentifier]], nil]];
[[NSApplication sharedApplication] terminate:self]; [[NSApplication sharedApplication] terminate:self];
} }
//[[MGMSIP sharedSIP] restart]; [[MGMSIP sharedSIP] restart];
} }
if (mainView!=nil) if (mainView!=nil)
[mainView release]; [mainView release];

View File

@ -368,7 +368,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = Classes/VoiceBase/VoiceBase_Prefix.pch; GCC_PREFIX_HEADER = Classes/VoiceBase/VoiceBase_Prefix.pch;
INFOPLIST_FILE = Resources/VoiceBase/Info.plist; INFOPLIST_FILE = Resources/VoiceBase/Info.plist;
INSTALL_PATH = "$(HOME)/Library/Frameworks"; INSTALL_PATH = "@executable_path/../Frameworks";
PRODUCT_NAME = VoiceBase; PRODUCT_NAME = VoiceBase;
WRAPPER_EXTENSION = framework; WRAPPER_EXTENSION = framework;
}; };
@ -390,7 +390,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = Classes/VoiceBase/VoiceBase_Prefix.pch; GCC_PREFIX_HEADER = Classes/VoiceBase/VoiceBase_Prefix.pch;
INFOPLIST_FILE = Resources/VoiceBase/Info.plist; INFOPLIST_FILE = Resources/VoiceBase/Info.plist;
INSTALL_PATH = "$(HOME)/Library/Frameworks"; INSTALL_PATH = "@executable_path/../Frameworks";
PRODUCT_NAME = VoiceBase; PRODUCT_NAME = VoiceBase;
WRAPPER_EXTENSION = framework; WRAPPER_EXTENSION = framework;
}; };
@ -480,7 +480,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = Classes/VoiceBase/VoiceBase_Prefix.pch; GCC_PREFIX_HEADER = Classes/VoiceBase/VoiceBase_Prefix.pch;
INFOPLIST_FILE = Resources/VoiceBase/Info.plist; INFOPLIST_FILE = Resources/VoiceBase/Info.plist;
INSTALL_PATH = "$(HOME)/Library/Frameworks"; INSTALL_PATH = "@executable_path/../Frameworks";
OTHER_LDFLAGS = ( OTHER_LDFLAGS = (
"-lpjsua-universal", "-lpjsua-universal",
"-lpjsip-ua-universal", "-lpjsip-ua-universal",