1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-22 22:03:02 +01:00

Merge branch 'calls_fix'

This commit is contained in:
jfreegman 2017-11-20 07:03:22 -05:00
commit a5a1f6015d
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63
4 changed files with 59 additions and 7 deletions

View File

@ -133,8 +133,6 @@ ToxAV *init_audio(ToxWindow *self, Tox *tox)
CallControl.video_frame_duration = 0; CallControl.video_frame_duration = 0;
#endif /* VIDEO */ #endif /* VIDEO */
memset(CallControl.calls, 0, sizeof(CallControl.calls));
if ( !CallControl.av ) { if ( !CallControl.av ) {
CallControl.audio_errors |= ae_StartingCoreAudio; CallControl.audio_errors |= ae_StartingCoreAudio;
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to init ToxAV"); line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to init ToxAV");
@ -160,7 +158,7 @@ void terminate_audio()
{ {
int i; int i;
for (i = 0; i < MAX_CALLS; ++i) for (i = 0; i < CallControl.max_calls; ++i)
stop_transmission(&CallControl.calls[i], i); stop_transmission(&CallControl.calls[i], i);
if ( CallControl.av ) if ( CallControl.av )
@ -900,3 +898,47 @@ void stop_current_call(ToxWindow *self)
CallControl.pending_call = false; CallControl.pending_call = false;
} }
/**
* Reallocates the Calls list according to n.
*/
static void realloc_calls(uint32_t n)
{
if (n <= 0) {
free(CallControl.calls);
CallControl.calls = NULL;
return;
}
Call *temp = realloc(CallControl.calls, n * sizeof(Call));
if (temp == NULL) {
exit_toxic_err("failed in realloc_calls", FATALERR_MEMORY);
}
CallControl.calls = temp;
}
/**
* Inits the call structure for a given friend. Called when a friend is added to the friends list.
* Index must be equivalent to the friend's friendlist index.
*/
void init_friend_AV(uint32_t index)
{
realloc_calls(CallControl.max_calls + 1);
memset(&CallControl.calls[CallControl.max_calls], 0, sizeof(Call));
if (index == CallControl.max_calls) {
++CallControl.max_calls;
}
}
/**
* Deletes the call structure for a given friend. Called when a friend is deleted from the friends list.
* Index must be equivalent to the friend's friendlist index.
*/
void del_friend_AV(uint32_t index)
{
realloc_calls(index);
CallControl.max_calls = index;
}

View File

@ -27,8 +27,6 @@
#include "audio_device.h" #include "audio_device.h"
#define MAX_CALLS 10
typedef enum _AudioError { typedef enum _AudioError {
ae_None = 0, ae_None = 0,
ae_StartingCaptureDevice = 1 << 0, ae_StartingCaptureDevice = 1 << 0,
@ -65,7 +63,9 @@ struct CallControl {
ToxAV *av; ToxAV *av;
ToxWindow *prompt; ToxWindow *prompt;
Call calls[MAX_CALLS]; Call *calls;
uint32_t max_calls;
uint32_t call_state; uint32_t call_state;
bool pending_call; bool pending_call;
bool audio_enabled; bool audio_enabled;
@ -89,5 +89,7 @@ void terminate_audio();
int start_transmission(ToxWindow *self, Call *call); int start_transmission(ToxWindow *self, Call *call);
int stop_transmission(Call *call, uint32_t friend_number); int stop_transmission(Call *call, uint32_t friend_number);
void stop_current_call(ToxWindow *self); void stop_current_call(ToxWindow *self);
void init_friend_AV(uint32_t index);
void del_friend_AV(uint32_t index);
#endif /* AUDIO_CALL_H */ #endif /* AUDIO_CALL_H */

View File

@ -466,6 +466,10 @@ void friendlist_onFriendAdded(ToxWindow *self, Tox *m, uint32_t num, bool sort)
if (sort) if (sort)
sort_friendlist_index(); sort_friendlist_index();
#ifdef AUDIO
init_friend_AV(i);
#endif
return; return;
} }
} }
@ -605,6 +609,10 @@ static void delete_friend(Tox *m, uint32_t f_num)
Friends.max_idx = i; Friends.max_idx = i;
realloc_friends(i); realloc_friends(i);
#ifdef AUDIO
del_friend_AV(i);
#endif
/* make sure num_selected stays within Friends.num_friends range */ /* make sure num_selected stays within Friends.num_friends range */
if (Friends.num_friends && Friends.num_selected == Friends.num_friends) if (Friends.num_friends && Friends.num_selected == Friends.num_friends)
--Friends.num_selected; --Friends.num_selected;

View File

@ -83,7 +83,7 @@ void terminate_video()
{ {
int i; int i;
for (i = 0; i < MAX_CALLS; ++i) { for (i = 0; i < CallControl.max_calls; ++i) {
Call *this_call = &CallControl.calls[i]; Call *this_call = &CallControl.calls[i];
stop_video_transmission(this_call, i); stop_video_transmission(this_call, i);