From 05f5f16af3316d97d21e14a936617e36a667af93 Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Thu, 12 Nov 2015 05:01:28 -0500 Subject: [PATCH 1/7] Fix various video bugs; it should be working now! --- src/audio_call.c | 14 ++++---- src/chat.c | 15 +++++--- src/global_commands.c | 2 +- src/misc_tools.c | 5 ++- src/toxic.c | 2 -- src/video_call.c | 79 +++++++++++++++++++++++-------------------- src/video_call.h | 5 +-- src/video_device.c | 70 ++++++++++++++++++++++---------------- 8 files changed, 109 insertions(+), 83 deletions(-) diff --git a/src/audio_call.c b/src/audio_call.c index 0b7ce4b..357dfea 100644 --- a/src/audio_call.c +++ b/src/audio_call.c @@ -265,12 +265,7 @@ void call_cb(ToxAV *av, uint32_t friend_number, bool audio_enabled, bool video_e { Tox *m = (Tox *) user_data; CallControl.pending_call = true; - - if (video_enabled) - /* FIXME enable video calls */ - toxav_call_control(av, friend_number, TOXAV_CALL_CONTROL_CANCEL, NULL); - else if (audio_enabled) - callback_recv_invite(m, friend_number); + callback_recv_invite(m, friend_number); } void callstate_cb(ToxAV *av, uint32_t friend_number, uint32_t state, void *user_data) @@ -573,7 +568,12 @@ on_error: void cmd_hangup(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) { - const char *error_str; + const char *error_str = NULL; + + if ( !self->is_call) { + error_str = "Not in a call."; + goto on_error; + } if ( argc != 0 ) { error_str = "Unknown arguments."; diff --git a/src/chat.c b/src/chat.c index 81dbb7a..662236c 100644 --- a/src/chat.c +++ b/src/chat.c @@ -49,7 +49,10 @@ #ifdef AUDIO #include "audio_call.h" -#endif /* AUDIO */ +#ifdef VIDEO + #include "video_call.h" +#endif /* VIDEO */ +#endif /* AUDIO */ extern char *DATA_FILE; extern FriendsList Friends; @@ -63,9 +66,9 @@ static void kill_infobox(ToxWindow *self); #endif /* AUDIO */ #ifdef AUDIO -#define AC_NUM_CHAT_COMMANDS 29 +#define AC_NUM_CHAT_COMMANDS 30 #else -#define AC_NUM_CHAT_COMMANDS 22 +#define AC_NUM_CHAT_COMMANDS 23 #endif /* AUDIO */ /* Array of chat command names used for tab completion. */ @@ -92,6 +95,7 @@ static const char chat_cmd_list[AC_NUM_CHAT_COMMANDS][MAX_CMDNAME_SIZE] = { { "/savefile" }, { "/sendfile" }, { "/status" }, + { "/video" }, #ifdef AUDIO @@ -128,8 +132,11 @@ void kill_chat_window(ToxWindow *self, Tox *m) cqueue_cleanup(ctx->cqueue); #ifdef AUDIO +#ifdef VIDEO + stop_video_stream(self); +#endif /* VIDEO */ stop_current_call(self); -#endif +#endif /* AUDIO */ delwin(ctx->linewin); delwin(ctx->history); diff --git a/src/global_commands.c b/src/global_commands.c index 42c731c..3dde49d 100644 --- a/src/global_commands.c +++ b/src/global_commands.c @@ -444,7 +444,7 @@ void cmd_myqr(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MA nick[nick_len] = '\0'; size_t data_file_len = strlen(DATA_FILE); - char dir[data_file_len]; + char dir[data_file_len + 1]; size_t dir_len = get_base_dir(DATA_FILE, data_file_len, dir); char qr_path[dir_len + nick_len + strlen(QRCODE_FILENAME_EXT) + 1]; diff --git a/src/misc_tools.c b/src/misc_tools.c index 0214661..d86c338 100644 --- a/src/misc_tools.c +++ b/src/misc_tools.c @@ -282,12 +282,15 @@ size_t get_file_name(char *namebuf, size_t bufsize, const char *pathname) } /* Gets the base directory of path and puts it in dir. - * dir must have at least as much space as path_len. + * dir must have at least as much space as path_len + 1. * * Returns the length of the base directory. */ size_t get_base_dir(const char *path, size_t path_len, char *dir) { + if (path_len == 0 || path == NULL) + return 0; + size_t dir_len = char_rfind(path, '/', path_len); if (dir_len != 0 && dir_len < path_len) diff --git a/src/toxic.c b/src/toxic.c index 6fd04d0..4eb4b93 100644 --- a/src/toxic.c +++ b/src/toxic.c @@ -153,11 +153,9 @@ void exit_toxic_success(Tox *m) terminate_notify(); #ifdef AUDIO - #ifdef VIDEO terminate_video(); #endif /* VIDEO */ - terminate_audio(); #endif /* AUDIO */ diff --git a/src/video_call.c b/src/video_call.c index 95da741..7a3282b 100644 --- a/src/video_call.c +++ b/src/video_call.c @@ -132,6 +132,7 @@ int start_video_transmission(ToxWindow *self, ToxAV *av, Call *call) } CallControl.video_bit_rate = default_video_bit_rate; + if ( toxav_bit_rate_set(CallControl.av, self->num, -1, CallControl.video_bit_rate, NULL) == false ) { line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to set video bit rate"); return -1; @@ -142,8 +143,10 @@ int start_video_transmission(ToxWindow *self, ToxAV *av, Call *call) return -1; } - if ( register_video_device_callback(self->num, call->vin_idx, read_video_device_callback, &self->num) != vde_None ) + if ( register_video_device_callback(self->num, call->vin_idx, read_video_device_callback, &self->num) != vde_None ) { line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to register input video handler!"); + return -1; + } return 0; } @@ -189,14 +192,12 @@ void video_bit_rate_status_cb(ToxAV *av, uint32_t friend_number, uint32_t audio_ void callback_recv_video_starting(uint32_t friend_number) { - return; + Call* this_call = &CallControl.calls[friend_number]; - // Call* this_call = &CallControl.calls[friend_number]; + if ( this_call->vout_idx != -1 ) + return; - // if ( this_call->vout_idx != -1 ) - // return; - - // open_primary_video_device(vdt_output, &this_call->vout_idx); + open_primary_video_device(vdt_output, &this_call->vout_idx); } void callback_recv_video_end(uint32_t friend_number) { @@ -214,10 +215,10 @@ void callback_video_starting(uint32_t friend_number) toxav_call_control(CallControl.av, friend_number, TOXAV_CALL_CONTROL_SHOW_VIDEO, &error); if (error == TOXAV_ERR_CALL_CONTROL_OK) { - int i; + size_t i; for (i = 0; i < MAX_WINDOWS_NUM; ++i) { if ( windows[i].is_call && windows[i].num == friend_number ) { - if(0 != start_video_transmission(&windows[i], CallControl.av, this_call)) { + if ( 0 != start_video_transmission(&windows[i], CallControl.av, this_call) ) { line_info_add(&windows[i], NULL, NULL, NULL, SYS_MSG, 0, 0, "Error starting transmission!"); return; } @@ -242,39 +243,37 @@ void callback_video_end(uint32_t friend_number) */ void cmd_video(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) { - return; // TODO: Fix video + const char *error_str; + Call* this_call = &CallControl.calls[self->num]; -// const char *error_str; -// Call* this_call = &CallControl.calls[self->num]; + if ( argc != 0 ) { + error_str = "Unknown arguments."; + goto on_error; + } -// if ( argc != 0 ) { -// error_str = "Unknown arguments."; -// goto on_error; -// } + if ( !CallControl.av ) { + error_str = "ToxAV not supported!"; + goto on_error; + } -// if ( !CallControl.av ) { -// error_str = "ToxAV not supported!"; -// goto on_error; -// } + if ( !self->stb->connection ) { + error_str = "Friend is offline."; + goto on_error; + } -// if ( !self->stb->connection ) { -// error_str = "Friend is offline."; -// goto on_error; -// } + if ( !self->is_call ) { + error_str = "Not in call!"; + goto on_error; + } -// if ( !self->is_call ) { -// error_str = "Not in call!"; -// goto on_error; -// } + if ( this_call->vin_idx == -1 ) + callback_video_starting(self->num); + else + callback_video_end(self->num); -// if ( this_call->vin_idx == -1 ) -// callback_video_starting(self->num); -// else -// callback_video_end(self->num); - -// return; -// on_error: -// print_err (self, error_str); + return; +on_error: + print_err (self, error_str); } void cmd_list_video_devices(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) @@ -414,3 +413,11 @@ void cmd_ccur_video_device(WINDOW *window, ToxWindow *self, Tox *m, int argc, ch on_error: print_err (self, error_str); } + +void stop_video_stream(ToxWindow *self) +{ + Call *this_call = &CallControl.calls[self->num]; + + if (this_call && this_call->vin_idx != -1) + stop_video_transmission(this_call, self->num); +} diff --git a/src/video_call.h b/src/video_call.h index 00a0ce0..9cb8394 100644 --- a/src/video_call.h +++ b/src/video_call.h @@ -26,7 +26,7 @@ #include #include "audio_call.h" - + #include "video_device.h" /* You will have to pass pointer to first member of 'windows' declared in windows.c */ @@ -34,10 +34,11 @@ ToxAV *init_video(ToxWindow *self, Tox *tox); void terminate_video(); int start_video_transmission(ToxWindow *self, ToxAV *av, Call *call); int stop_video_transmission(Call *call, int friend_number); +void stop_video_stream(ToxWindow *self); void callback_recv_video_starting(uint32_t friend_number); void callback_recv_video_end(uint32_t friend_number); void callback_video_starting(uint32_t friend_number); void callback_video_end(uint32_t friend_number); -#endif /* VIDEO_CALL_H */ \ No newline at end of file +#endif /* VIDEO_CALL_H */ diff --git a/src/video_device.c b/src/video_device.c index 2c59946..ef9381e 100644 --- a/src/video_device.c +++ b/src/video_device.c @@ -50,7 +50,6 @@ #include #include #include -#include #define inline__ inline __attribute__((always_inline)) @@ -300,24 +299,32 @@ VideoDeviceError open_video_device(VideoDeviceType type, int32_t selection, uint lock; - uint32_t i; - for (i = 0; i < MAX_DEVICES && video_devices_running[type][i]; ++i); + uint32_t i, temp_idx = -1; - if (i == MAX_DEVICES) { unlock; return vde_AllDevicesBusy; } - else *device_idx = i; + for (i = 0; i < MAX_DEVICES; ++i) { + if ( !video_devices_running[type][i] ) { + temp_idx = i; + break; + } + } + + if (temp_idx == -1) { + unlock; + return vde_AllDevicesBusy; + } for (i = 0; i < MAX_DEVICES; i ++) { /* Check if any device has the same selection */ if ( video_devices_running[type][i] && video_devices_running[type][i]->selection == selection ) { - video_devices_running[type][*device_idx] = video_devices_running[type][i]; - video_devices_running[type][i]->ref_count ++; + video_devices_running[type][temp_idx] = video_devices_running[type][i]; + video_devices_running[type][i]->ref_count++; unlock; return vde_None; } } - VideoDevice* device = video_devices_running[type][*device_idx] = calloc(1, sizeof(VideoDevice)); + VideoDevice* device = video_devices_running[type][temp_idx] = calloc(1, sizeof(VideoDevice)); device->selection = selection; if ( pthread_mutex_init(device->mutex, NULL) != 0 ) { @@ -336,6 +343,7 @@ VideoDeviceError open_video_device(VideoDeviceType type, int32_t selection, uint device->fd = open(device_address, O_RDWR); if ( device->fd == -1 ) { + unlock; return vde_FailedStart; } @@ -344,7 +352,7 @@ VideoDeviceError open_video_device(VideoDeviceType type, int32_t selection, uint if ( -1 == xioctl(device->fd, VIDIOC_QUERYCAP, &cap) ) { close(device->fd); free(device); - + unlock; return vde_FailedStart; } @@ -357,7 +365,7 @@ VideoDeviceError open_video_device(VideoDeviceType type, int32_t selection, uint if( -1 == xioctl(device->fd, VIDIOC_G_FMT, &fmt) ) { close(device->fd); free(device); - + unlock; return vde_FailedStart; } @@ -373,14 +381,14 @@ VideoDeviceError open_video_device(VideoDeviceType type, int32_t selection, uint if ( -1 == xioctl(device->fd, VIDIOC_REQBUFS, &req) ) { close(device->fd); free(device); - + unlock; return vde_FailedStart; } if ( req.count < 2 ) { close(device->fd); free(device); - + unlock; return vde_FailedStart; } @@ -397,7 +405,7 @@ VideoDeviceError open_video_device(VideoDeviceType type, int32_t selection, uint if ( -1 == xioctl(device->fd, VIDIOC_QUERYBUF, &buf) ) { close(device->fd); free(device); - + unlock; return vde_FailedStart; } @@ -413,7 +421,7 @@ VideoDeviceError open_video_device(VideoDeviceType type, int32_t selection, uint munmap(device->buffers[i].start, device->buffers[i].length); close(device->fd); free(device); - + unlock; return vde_FailedStart; } } @@ -434,7 +442,7 @@ VideoDeviceError open_video_device(VideoDeviceType type, int32_t selection, uint munmap(device->buffers[i].start, device->buffers[i].length); close(device->fd); free(device); - + unlock; return vde_FailedStart; } } @@ -443,23 +451,23 @@ VideoDeviceError open_video_device(VideoDeviceType type, int32_t selection, uint /* Turn on video stream */ if ( -1 == xioctl(device->fd, VIDIOC_STREAMON, &type) ) { - close_video_device(vdt_input, *device_idx); - + close_video_device(vdt_input, temp_idx); + unlock; return vde_FailedStart; } #else /* __OSX__ */ if ( osx_video_open_device(selection, &device->video_width, &device->video_height) != 0 ) { free(device); - + unlock; return vde_FailedStart; } #endif /* Create X11 window associated to device */ if ( (device->x_display = XOpenDisplay(NULL)) == NULL ) { - close_video_device(vdt_input, *device_idx); - + close_video_device(vdt_input, temp_idx); + unlock; return vde_FailedStart; } @@ -468,8 +476,8 @@ VideoDeviceError open_video_device(VideoDeviceType type, int32_t selection, uint if ( !(device->x_window = XCreateSimpleWindow(device->x_display, RootWindow(device->x_display, screen), 0, 0, device->video_width, device->video_height, 0, BlackPixel(device->x_display, screen), BlackPixel(device->x_display, screen))) ) { - close_video_device(vdt_input, *device_idx); - + close_video_device(vdt_input, temp_idx); + unlock; return vde_FailedStart; } @@ -477,8 +485,8 @@ VideoDeviceError open_video_device(VideoDeviceType type, int32_t selection, uint XSelectInput(device->x_display, device->x_window, ExposureMask|ButtonPressMask|KeyPressMask); if ( (device->x_gc = DefaultGC(device->x_display, screen)) == NULL ) { - close_video_device(vdt_input, *device_idx); - + close_video_device(vdt_input, temp_idx); + unlock; return vde_FailedStart; } @@ -498,8 +506,8 @@ VideoDeviceError open_video_device(VideoDeviceType type, int32_t selection, uint /* Create X11 window associated to device */ if ( (device->x_display = XOpenDisplay(NULL)) == NULL ) { - close_video_device(vdt_output, *device_idx); - + close_video_device(vdt_output, temp_idx); + unlock; return vde_FailedStart; } @@ -507,8 +515,8 @@ VideoDeviceError open_video_device(VideoDeviceType type, int32_t selection, uint if ( !(device->x_window = XCreateSimpleWindow(device->x_display, RootWindow(device->x_display, screen), 0, 0, 100, 100, 0, BlackPixel(device->x_display, screen), BlackPixel(device->x_display, screen))) ) { - close_video_device(vdt_output, *device_idx); - + close_video_device(vdt_output, temp_idx); + unlock; return vde_FailedStart; } @@ -516,8 +524,8 @@ VideoDeviceError open_video_device(VideoDeviceType type, int32_t selection, uint XSelectInput(device->x_display, device->x_window, ExposureMask|ButtonPressMask|KeyPressMask); if ( (device->x_gc = DefaultGC(device->x_display, screen)) == NULL ) { - close_video_device(vdt_output, *device_idx); - + close_video_device(vdt_output, temp_idx); + unlock; return vde_FailedStart; } @@ -533,7 +541,9 @@ VideoDeviceError open_video_device(VideoDeviceType type, int32_t selection, uint vpx_img_alloc(&device->input, VPX_IMG_FMT_I420, device->video_width, device->video_height, 1); } + *device_idx = temp_idx; unlock; + return vde_None; } From ab99c1ac7352f7d2354e2969a6c14ccdbeaea6a4 Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Thu, 12 Nov 2015 05:04:37 -0500 Subject: [PATCH 2/7] Fix building on FreeBSD (courtesy of thierry-FreeBSD) --- cfg/systems/FreeBSD.mk | 2 +- src/video_device.c | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/cfg/systems/FreeBSD.mk b/cfg/systems/FreeBSD.mk index 1ae75e8..bdccdba 100644 --- a/cfg/systems/FreeBSD.mk +++ b/cfg/systems/FreeBSD.mk @@ -1,4 +1,4 @@ # Specials options for freebsd systems LIBS := $(filter-out ncursesw, $(LIBS)) -LDFLAGS += -lncursesw +LDFLAGS += -lncursesw -lcurl MANDIR = $(PREFIX)/man diff --git a/src/video_device.c b/src/video_device.c index ef9381e..19b4508 100644 --- a/src/video_device.c +++ b/src/video_device.c @@ -30,7 +30,7 @@ #include -#ifdef __linux__ +#if defined(__linux__) || defined(__FreeBSD__) #include #include #include @@ -65,7 +65,7 @@ typedef struct VideoDevice { void* cb_data; /* Data to be passed to callback */ int32_t friend_number; /* ToxAV friend number */ -#ifdef __linux__ +#if defined(__linux__) || defined(__FreeBSD__) int fd; /* File descriptor of video device selected/opened */ struct v4l2_format fmt; struct VideoBuffer *buffers; @@ -131,7 +131,7 @@ static void yuv420tobgr(uint16_t width, uint16_t height, const uint8_t *y, } } -#ifdef __linux__ +#if defined(__linux__) || defined(__FreeBSD__) static void yuv422to420(uint8_t *plane_y, uint8_t *plane_u, uint8_t *plane_v, uint8_t *input, uint16_t width, uint16_t height) { @@ -177,7 +177,7 @@ VideoDeviceError init_video_devices() { size[vdt_input] = 0; -#ifdef __linux__ +#if defined(__linux__) || defined(__FreeBSD__) for (; size[vdt_input] <= MAX_DEVICES; ++size[vdt_input]) { int fd; char device_address[] = "/dev/videoXX"; @@ -257,7 +257,7 @@ VideoDeviceError terminate_video_devices() VideoDeviceError register_video_device_callback(int32_t friend_number, uint32_t device_idx, VideoDataHandleCallback callback, void* data) { -#ifdef __linux__ +#if defined(__linux__) || defined(__FreeBSD__) if ( size[vdt_input] <= device_idx || !video_devices_running[vdt_input][device_idx] || !video_devices_running[vdt_input][device_idx]->fd ) return vde_InvalidSelection; #else /* __OSX__ */ @@ -336,7 +336,7 @@ VideoDeviceError open_video_device(VideoDeviceType type, int32_t selection, uint if ( type == vdt_input ) { video_thread_paused = true; -#ifdef __linux__ +#if defined(__linux__) || defined(__FreeBSD__) /* Open selected device */ char device_address[] = "/dev/videoXX"; snprintf(device_address + 10 , sizeof(device_address) - 10, "%i", selection); @@ -632,7 +632,7 @@ void* video_thread_poll (void* arg) // TODO: maybe use thread for every input so uint8_t *u = device->input.planes[1]; uint8_t *v = device->input.planes[2]; -#ifdef __linux__ +#if defined(__linux__) || defined(__FreeBSD__) struct v4l2_buffer buf; memset(&(buf), 0, sizeof(buf)); @@ -690,7 +690,7 @@ void* video_thread_poll (void* arg) // TODO: maybe use thread for every input so XFlush(device->x_display); free(img_data); -#ifdef __linux__ +#if defined(__linux__) || defined(__FreeBSD__) if ( -1 == xioctl(device->fd, VIDIOC_QBUF, &buf) ) { unlock; continue; @@ -725,7 +725,7 @@ VideoDeviceError close_video_device(VideoDeviceType type, uint32_t device_idx) if ( !device->ref_count ) { if ( type == vdt_input ) { -#ifdef __linux__ +#if defined(__linux__) || defined(__FreeBSD__) enum v4l2_buf_type buf_type = V4L2_BUF_TYPE_VIDEO_CAPTURE; if( -1 == xioctl(device->fd, VIDIOC_STREAMOFF, &buf_type) ) {} @@ -745,7 +745,7 @@ VideoDeviceError close_video_device(VideoDeviceType type, uint32_t device_idx) XCloseDisplay(device->x_display); pthread_mutex_destroy(device->mutex); -#ifdef __linux__ +#if defined(__linux__) || defined(__FreeBSD__) free(device->buffers); #endif /* __linux__ */ From 65c07a57dba6db4fa9460a87158be2702e11a220 Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Thu, 12 Nov 2015 17:14:10 -0500 Subject: [PATCH 3/7] Properly close audio devices on quit --- src/audio_call.c | 11 +++++------ src/chat.c | 4 ++-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/audio_call.c b/src/audio_call.c index 357dfea..6003a8a 100644 --- a/src/audio_call.c +++ b/src/audio_call.c @@ -570,7 +570,7 @@ void cmd_hangup(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[ { const char *error_str = NULL; - if ( !self->is_call) { + if ( !self->is_call ) { error_str = "Not in a call."; goto on_error; } @@ -587,11 +587,8 @@ void cmd_hangup(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[ #ifdef VIDEO callback_video_end(self->num); - #endif /* VIDEO */ - - if ( CallControl.pending_call ) { /* Manually send a cancel call control because call hasn't started */ toxav_call_control(CallControl.av, self->num, TOXAV_CALL_CONTROL_CANCEL, NULL); @@ -836,6 +833,8 @@ on_error: void stop_current_call(ToxWindow* self) { - TOXAV_ERR_CALL_CONTROL error; - toxav_call_control(CallControl.av, self->num, TOXAV_CALL_CONTROL_CANCEL, &error); + Call *this_call = &CallControl.calls[self->num]; + + if (this_call && self->is_call) + stop_transmission(this_call, self->num); } diff --git a/src/chat.c b/src/chat.c index 662236c..0e59c85 100644 --- a/src/chat.c +++ b/src/chat.c @@ -68,7 +68,7 @@ static void kill_infobox(ToxWindow *self); #ifdef AUDIO #define AC_NUM_CHAT_COMMANDS 30 #else -#define AC_NUM_CHAT_COMMANDS 23 +#define AC_NUM_CHAT_COMMANDS 22 #endif /* AUDIO */ /* Array of chat command names used for tab completion. */ @@ -95,7 +95,6 @@ static const char chat_cmd_list[AC_NUM_CHAT_COMMANDS][MAX_CMDNAME_SIZE] = { { "/savefile" }, { "/sendfile" }, { "/status" }, - { "/video" }, #ifdef AUDIO @@ -106,6 +105,7 @@ static const char chat_cmd_list[AC_NUM_CHAT_COMMANDS][MAX_CMDNAME_SIZE] = { { "/sdev" }, { "/mute" }, { "/sense" }, + { "/video" }, #endif /* AUDIO */ }; From 74c1eef1d12c627aa4bfedbf4d4680081c9c4bd5 Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Thu, 12 Nov 2015 17:18:37 -0500 Subject: [PATCH 4/7] Bump version to 0.7.0 --- cfg/global_vars.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cfg/global_vars.mk b/cfg/global_vars.mk index de60c24..2fa9723 100644 --- a/cfg/global_vars.mk +++ b/cfg/global_vars.mk @@ -1,5 +1,5 @@ # Version -TOXIC_VERSION = 0.6.1 +TOXIC_VERSION = 0.7.0 REV = $(shell git rev-list HEAD --count 2>/dev/null || echo -n "error") ifneq (, $(findstring error, $(REV))) VERSION = $(TOXIC_VERSION) From 9f0feb722341fe90dea744cec96d0f6a78213e52 Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Thu, 12 Nov 2015 18:03:45 -0500 Subject: [PATCH 5/7] Allow custom nospam values --- src/global_commands.c | 20 +++++++++++++++++--- src/help.c | 2 +- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/global_commands.c b/src/global_commands.c index 3dde49d..1cc2340 100644 --- a/src/global_commands.c +++ b/src/global_commands.c @@ -524,11 +524,25 @@ void cmd_note(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MA void cmd_nospam(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) { - uint32_t nospam = rand(); /* should be random enough */ - tox_self_set_nospam(m, nospam); - line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Your Tox ID has been changed to:"); + long int nospam = rand(); + + if (argc > 0) { + nospam = strtol(argv[1], NULL, 16); + + if ((nospam == 0 && strcmp(argv[1], "0")) || nospam < 0) { + line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid nospam value."); + return; + } + } + + uint32_t old_nospam = tox_self_get_nospam(m); + tox_self_set_nospam(m, (uint32_t) nospam); + + line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Your new Tox ID is:"); cmd_myid(window, self, m, 0, NULL); + line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, ""); line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Any services that relied on your old ID will need to be updated manually."); + line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "If you ever want your old Tox ID back, type '/nospam %X'", old_nospam); } void cmd_prompt_help(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) diff --git a/src/help.c b/src/help.c index 3ecc3f5..d986ee7 100644 --- a/src/help.c +++ b/src/help.c @@ -154,7 +154,7 @@ static void help_draw_global(ToxWindow *self) wprintw(win, " /status : Set status with optional note\n"); wprintw(win, " /note : Set a personal note\n"); wprintw(win, " /nick : Set your nickname\n"); - wprintw(win, " /nospam : Change part of your Tox ID to stop spam\n"); + wprintw(win, " /nospam : Change part of your Tox ID to stop spam\n"); wprintw(win, " /log or : Enable/disable logging\n"); wprintw(win, " /group : Create a group chat where type: text | audio\n"); wprintw(win, " /myid : Print your Tox ID\n"); From b24c5d8cf831af26cfc6555f8a1f38c51ba06343 Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Thu, 19 Nov 2015 23:49:58 -0500 Subject: [PATCH 6/7] Fix AV bug Pending call now properly hangs up when you use the /hangup command or close the chat window --- src/audio_call.c | 35 +++++++++++++++++------------------ src/chat.c | 10 +++++----- src/name_lookup.c | 2 +- 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/audio_call.c b/src/audio_call.c index 6003a8a..d88ae6b 100644 --- a/src/audio_call.c +++ b/src/audio_call.c @@ -570,8 +570,8 @@ void cmd_hangup(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[ { const char *error_str = NULL; - if ( !self->is_call ) { - error_str = "Not in a call."; + if ( !CallControl.av ) { + error_str = "Audio not supported!"; goto on_error; } @@ -580,8 +580,8 @@ void cmd_hangup(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[ goto on_error; } - if ( !CallControl.av ) { - error_str = "Audio not supported!"; + if ( !self->is_call && !CallControl.pending_call ) { + error_str = "Not in a call."; goto on_error; } @@ -589,18 +589,7 @@ void cmd_hangup(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[ callback_video_end(self->num); #endif /* VIDEO */ - if ( CallControl.pending_call ) { - /* Manually send a cancel call control because call hasn't started */ - toxav_call_control(CallControl.av, self->num, TOXAV_CALL_CONTROL_CANCEL, NULL); - callback_call_canceled(self->num); - } - else { - stop_transmission(&CallControl.calls[self->num], self->num); - callback_call_ended(self->num); - } - - CallControl.pending_call = false; - + stop_current_call(self); return; on_error: print_err (self, error_str); @@ -835,6 +824,16 @@ void stop_current_call(ToxWindow* self) { Call *this_call = &CallControl.calls[self->num]; - if (this_call && self->is_call) - stop_transmission(this_call, self->num); + if ( !this_call ) + return; + + if ( CallControl.pending_call ) { + toxav_call_control(CallControl.av, self->num, TOXAV_CALL_CONTROL_CANCEL, NULL); + callback_call_canceled(self->num); + } else { + stop_transmission(&CallControl.calls[self->num], self->num); + callback_call_ended(self->num); + } + + CallControl.pending_call = false; } diff --git a/src/chat.c b/src/chat.c index 0e59c85..b3e293e 100644 --- a/src/chat.c +++ b/src/chat.c @@ -126,11 +126,6 @@ void kill_chat_window(ToxWindow *self, Tox *m) ChatContext *ctx = self->chatwin; StatusBar *statusbar = self->stb; - kill_all_file_transfers_friend(m, self->num); - log_disable(ctx->log); - line_info_cleanup(ctx->hst); - cqueue_cleanup(ctx->cqueue); - #ifdef AUDIO #ifdef VIDEO stop_video_stream(self); @@ -138,6 +133,11 @@ void kill_chat_window(ToxWindow *self, Tox *m) stop_current_call(self); #endif /* AUDIO */ + kill_all_file_transfers_friend(m, self->num); + log_disable(ctx->log); + line_info_cleanup(ctx->hst); + cqueue_cleanup(ctx->cqueue); + delwin(ctx->linewin); delwin(ctx->history); delwin(statusbar->topline); diff --git a/src/name_lookup.c b/src/name_lookup.c index fad4c9e..3fc7e36 100644 --- a/src/name_lookup.c +++ b/src/name_lookup.c @@ -329,7 +329,7 @@ void *lookup_thread_func(void *data) curl_easy_setopt(c_handle, CURLOPT_HTTPHEADER, headers); curl_easy_setopt(c_handle, CURLOPT_URL, real_domain); curl_easy_setopt(c_handle, CURLOPT_WRITEFUNCTION, write_lookup_data); - curl_easy_setopt(c_handle, CURLOPT_WRITEDATA, (void *) &recv_data); + curl_easy_setopt(c_handle, CURLOPT_WRITEDATA, &recv_data); curl_easy_setopt(c_handle, CURLOPT_USERAGENT, "libcurl-agent/1.0"); curl_easy_setopt(c_handle, CURLOPT_POSTFIELDS, post_data); From aade65bfe13e796940dcf95e7667f6cc105a74b2 Mon Sep 17 00:00:00 2001 From: Oleksiy Protas Date: Wed, 25 Nov 2015 10:26:12 +0200 Subject: [PATCH 7/7] Correctly operational from OSX terminals --- src/xtra.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/xtra.c b/src/xtra.c index 05004c3..1ff34bd 100644 --- a/src/xtra.c +++ b/src/xtra.c @@ -271,6 +271,11 @@ int init_xtra(drop_callback d) Xtra.terminal_window = focused_window_id(); + /* OSX: if focused window is 0, it means toxic is ran from + * native terminal and not X11 terminal window, silently exit */ + if (!Xtra.terminal_window) + return 0; + { /* Create an invisible window which will act as proxy for the DnD operation. */ XSetWindowAttributes attr = {0}; @@ -343,7 +348,7 @@ int init_xtra(drop_callback d) void terminate_xtra() { - if (!Xtra.display) return; + if (!Xtra.display || !Xtra.terminal_window) return; XEvent terminate = { .xclient = {