From 78af10fa1f79b7b3b8162304f01a731be66640df Mon Sep 17 00:00:00 2001 From: Ansa89 Date: Mon, 23 Jun 2014 10:57:27 +0200 Subject: [PATCH 1/5] Cast time to "time_t" --- src/friendlist.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/friendlist.c b/src/friendlist.c index a1573de..7efe008 100644 --- a/src/friendlist.c +++ b/src/friendlist.c @@ -91,7 +91,7 @@ void sort_friendlist_index(void) static void update_friend_last_online(int32_t num, uint64_t timestamp) { friends[num].last_online.last_on = timestamp; - friends[num].last_online.tm = *localtime(×tamp); + friends[num].last_online.tm = *localtime((const time_t*)×tamp); /* if the format changes make sure TIME_STR_SIZE is the correct size */ const char *t = user_settings->time == TIME_12 ? "%I:%M %p" : "%H:%M"; @@ -383,7 +383,7 @@ static void friendlist_onDraw(ToxWindow *self, Tox *m) getmaxyx(self->window, y2, x2); uint64_t cur_time = get_unix_time(); - struct tm cur_loc_tm = *localtime(&cur_time); + struct tm cur_loc_tm = *localtime((const time_t*)&cur_time); bool fix_statuses = x2 != self->x; /* true if window x axis has changed */ From cb93c6ec650cf0aad81b7ffd2482a8dbd4bbc89f Mon Sep 17 00:00:00 2001 From: Ansa89 Date: Mon, 23 Jun 2014 10:58:24 +0200 Subject: [PATCH 2/5] Cast time to "time_t" --- src/misc_tools.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/misc_tools.c b/src/misc_tools.c index 01cf96a..001ad88 100644 --- a/src/misc_tools.c +++ b/src/misc_tools.c @@ -55,7 +55,7 @@ struct tm *get_time(void) { struct tm *timeinfo; uint64_t t = get_unix_time(); - timeinfo = localtime(&t); + timeinfo = localtime((const time_t*)&t); return timeinfo; } From f47991e18e0721f619a67359db30d24755513a79 Mon Sep 17 00:00:00 2001 From: mannol Date: Mon, 23 Jun 2014 23:57:12 +0200 Subject: [PATCH 3/5] Reverse call_idx and enable running call when devices fail to load --- src/audio_call.c | 53 ++++++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/src/audio_call.c b/src/audio_call.c index b4e80cf..689bc61 100644 --- a/src/audio_call.c +++ b/src/audio_call.c @@ -189,37 +189,41 @@ void *transmission(void *arg) int32_t dec_frame_len; int16_t PCM[frame_size]; + _Bool has_output = 1; - - if ( open_primary_device(input, &this_call->in_idx) != de_None ) goto cleanup; + if ( open_primary_device(input, &this_call->in_idx) != de_None ) + line_info_add(self, NULL, NULL, NULL, "Failed to open input device!", SYS_MSG, 0, 0); if ( register_device_callback(call_index, this_call->in_idx, read_device_callback, &call_index, _True) != de_None) /* Set VAD as true for all; TODO: Make it more dynamic */ - goto cleanup; + line_info_add(self, NULL, NULL, NULL, "Failed to register input handler!", SYS_MSG, 0, 0); - if ( open_primary_device(output, &this_call->out_idx) != de_None ) goto cleanup; - + if ( open_primary_device(output, &this_call->out_idx) != de_None ) { + line_info_add(self, NULL, NULL, NULL, "Failed to open output device!", SYS_MSG, 0, 0); + has_output = 0; + } /* Start transmission */ while (this_call->ttas) { - lock; - - if (playback_device_ready(this_call->out_idx) == de_Busy) { - unlock; - continue; - } - - dec_frame_len = toxav_recv_audio(ASettins.av, call_index, frame_size, PCM); + if ( has_output ) { + lock; + + if (playback_device_ready(this_call->out_idx) == de_Busy) { + unlock; + continue; + } + + dec_frame_len = toxav_recv_audio(ASettins.av, call_index, frame_size, PCM); - /* Play the packet */ - if (dec_frame_len > 0) { - write_out(this_call->out_idx, PCM, dec_frame_len, av_DefaultSettings.audio_channels); + /* Play the packet */ + if (dec_frame_len > 0) { + write_out(this_call->out_idx, PCM, dec_frame_len, av_DefaultSettings.audio_channels); + } + else if (dec_frame_len != 0) { + /* >implying it'll ever get an error */ + } + + unlock; } - else if (dec_frame_len != 0) { - /* >implying it'll ever get an error */ - } - - unlock; - usleep(1000); } @@ -304,10 +308,12 @@ void callback_recv_ending ( int32_t call_index, void* arg ) { CB_BODY(call_index, arg, onEnding); stop_transmission(call_index); + ((ToxWindow*)arg)->call_idx = -1; } void callback_recv_error ( int32_t call_index, void* arg ) { CB_BODY(call_index, arg, onError); + stop_transmission(call_index); } void callback_call_started ( int32_t call_index, void* arg ) { @@ -328,6 +334,7 @@ void callback_call_canceled ( int32_t call_index, void* arg ) /* In case call is active */ stop_transmission(call_index); + ((ToxWindow*)arg)->call_idx = -1; } void callback_call_rejected ( int32_t call_index, void* arg ) { @@ -337,6 +344,7 @@ void callback_call_ended ( int32_t call_index, void* arg ) { CB_BODY(call_index, arg, onEnd); stop_transmission(call_index); + ((ToxWindow*)arg)->call_idx = -1; } void callback_requ_timeout ( int32_t call_index, void* arg ) @@ -351,6 +359,7 @@ void callback_peer_timeout ( int32_t call_index, void* arg ) * actions that one can possibly take on timeout */ toxav_stop_call(ASettins.av, call_index); + ((ToxWindow*)arg)->call_idx = -1; } /* * End of Callbacks From 476b056ed072e53d6c1473b8caa89b6b8f145b05 Mon Sep 17 00:00:00 2001 From: mannol Date: Tue, 24 Jun 2014 00:20:44 +0200 Subject: [PATCH 4/5] make it dynamic --- src/audio_call.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/audio_call.c b/src/audio_call.c index 689bc61..67607ec 100644 --- a/src/audio_call.c +++ b/src/audio_call.c @@ -55,7 +55,7 @@ typedef struct _Call { pthread_t ttid; /* Transmission thread id */ - _Bool ttas; /* Transmission thread active status (0 - stopped, 1- running) */ + _Bool ttas, has_output; /* Transmission thread active status (0 - stopped, 1- running) */ int in_idx, out_idx; pthread_mutex_t mutex; } Call; @@ -189,7 +189,7 @@ void *transmission(void *arg) int32_t dec_frame_len; int16_t PCM[frame_size]; - _Bool has_output = 1; + this_call->has_output = 1; if ( open_primary_device(input, &this_call->in_idx) != de_None ) line_info_add(self, NULL, NULL, NULL, "Failed to open input device!", SYS_MSG, 0, 0); @@ -199,13 +199,13 @@ void *transmission(void *arg) if ( open_primary_device(output, &this_call->out_idx) != de_None ) { line_info_add(self, NULL, NULL, NULL, "Failed to open output device!", SYS_MSG, 0, 0); - has_output = 0; + this_call->has_output = 0; } /* Start transmission */ while (this_call->ttas) { - if ( has_output ) { - lock; + lock; + if ( this_call->has_output ) { if (playback_device_ready(this_call->out_idx) == de_Busy) { unlock; @@ -222,8 +222,9 @@ void *transmission(void *arg) /* >implying it'll ever get an error */ } - unlock; } + unlock; + usleep(1000); } @@ -653,7 +654,8 @@ void cmd_ccur_device(WINDOW * window, ToxWindow * self, Tox *m, int argc, char ( if (type == output) { pthread_mutex_lock(&this_call->mutex); close_device(output, this_call->out_idx); - open_device(output, selection, &this_call->out_idx); + this_call->has_output = open_device(output, selection, &this_call->out_idx) + == de_None ? 1 : 0; pthread_mutex_unlock(&this_call->mutex); } else { From 2a6a5b13d7cb4f23265058378f537b95cf1764c0 Mon Sep 17 00:00:00 2001 From: mannol Date: Tue, 24 Jun 2014 00:30:11 +0200 Subject: [PATCH 5/5] Forgot to set index in some callbacks --- src/audio_call.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/audio_call.c b/src/audio_call.c index 67607ec..3f3b665 100644 --- a/src/audio_call.c +++ b/src/audio_call.c @@ -315,6 +315,7 @@ void callback_recv_error ( int32_t call_index, void* arg ) { CB_BODY(call_index, arg, onError); stop_transmission(call_index); + ((ToxWindow*)arg)->call_idx = -1; } void callback_call_started ( int32_t call_index, void* arg ) { @@ -351,6 +352,7 @@ void callback_call_ended ( int32_t call_index, void* arg ) void callback_requ_timeout ( int32_t call_index, void* arg ) { CB_BODY(call_index, arg, onRequestTimeout); + ((ToxWindow*)arg)->call_idx = -1; } void callback_peer_timeout ( int32_t call_index, void* arg ) {