diff --git a/toxav/msi.c b/toxav/msi.c index 4bae076f..928e24c4 100755 --- a/toxav/msi.c +++ b/toxav/msi.c @@ -117,7 +117,7 @@ typedef struct _MSIMessage { static struct _Callbacks { MSICallback function; void* data; -} callbacks[10] = {0}; +} callbacks[11] = {0}; inline__ void invoke_callback(MSICallbackID id) { @@ -653,7 +653,7 @@ void handle_remote_connection_change(Messenger *messenger, int friend_num, uint8 for ( ; i < session->call->peer_count; i ++ ) if ( session->call->peers[i] == friend_num ) { - msi_stopcall(session); /* Stop the call for now */ + invoke_callback(MSI_OnPeerTimeout); return; } } @@ -747,10 +747,9 @@ void *handle_timeout ( void *arg ) } - return NULL; + pthread_exit(NULL); } - /** * @brief Add peer to peer list. * @@ -1244,13 +1243,12 @@ int msi_terminate_session ( MSISession *session ) assert ( session ); int _status = 0; - - terminate_call ( session ); + + /* If have call, cancel it */ + if ( session->call ) msi_cancel(session, 0, "MSI session terminated!"); + m_callback_msi_packet((struct Messenger *) session->messenger_handle, NULL, NULL); - - /* TODO: Clean it up more? */ - free ( session ); return _status; } diff --git a/toxav/msi.h b/toxav/msi.h index fcc24b4a..37fc07a3 100755 --- a/toxav/msi.h +++ b/toxav/msi.h @@ -131,7 +131,8 @@ typedef enum { /* Protocol */ MSI_OnError, - MSI_OnRequestTimeout + MSI_OnRequestTimeout, + MSI_OnPeerTimeout } MSICallbackID; diff --git a/toxav/phone.c b/toxav/phone.c index 43d24a2f..fb159f57 100755 --- a/toxav/phone.c +++ b/toxav/phone.c @@ -1147,18 +1147,21 @@ failed_init_ffmpeg: ; int av_terminate_session(av_session_t *_phone) { - toxav_hangup(_phone->av); - - free(_phone->_friends); - pthread_mutex_destroy ( &_phone->_mutex ); - + _phone->running_decaud = 0; + usleep(100000); /* Wait for tox_poll to end */ + + toxav_kill(_phone->av); + printf("\r[i] KILLED AV ARGH!\n"); + + usleep(1000000); /* Wait for cancel request to be sent */ Tox *_p = _phone->_messenger; _phone->_messenger = NULL; - usleep(100000); /* Wait for tox_poll to end */ - tox_kill(_p); - toxav_kill(_phone->av); + + free(_phone->_friends); + pthread_mutex_destroy ( &_phone->_mutex ); + free(_phone); printf("\r[i] Quit!\n"); diff --git a/toxav/toxav.h b/toxav/toxav.h index ffe79249..b67e82f8 100755 --- a/toxav/toxav.h +++ b/toxav/toxav.h @@ -70,8 +70,8 @@ typedef enum { /* Protocol */ av_OnError, - av_OnRequestTimeout - + av_OnRequestTimeout, + av_OnPeerTimeout } ToxAvCallbackID;