mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-22 20:43:02 +01:00
Merge branch 'master' into new_groupchats
This commit is contained in:
commit
1d1c051a44
@ -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)
|
||||
|
@ -1,4 +1,4 @@
|
||||
# Specials options for freebsd systems
|
||||
LIBS := $(filter-out ncursesw, $(LIBS))
|
||||
LDFLAGS += -lncursesw
|
||||
LDFLAGS += -lncursesw -lcurl
|
||||
MANDIR = $(PREFIX)/man
|
||||
|
@ -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,37 +568,28 @@ on_error:
|
||||
|
||||
void cmd_hangup(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
||||
{
|
||||
const char *error_str;
|
||||
|
||||
if ( argc != 0 ) {
|
||||
error_str = "Unknown arguments.";
|
||||
goto on_error;
|
||||
}
|
||||
const char *error_str = NULL;
|
||||
|
||||
if ( !CallControl.av ) {
|
||||
error_str = "Audio not supported!";
|
||||
goto on_error;
|
||||
}
|
||||
|
||||
if ( argc != 0 ) {
|
||||
error_str = "Unknown arguments.";
|
||||
goto on_error;
|
||||
}
|
||||
|
||||
if ( !self->is_call && !CallControl.pending_call ) {
|
||||
error_str = "Not in a call.";
|
||||
goto on_error;
|
||||
}
|
||||
|
||||
#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);
|
||||
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);
|
||||
@ -836,6 +822,18 @@ 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 )
|
||||
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;
|
||||
}
|
||||
|
17
src/chat.c
17
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;
|
||||
@ -103,6 +106,7 @@ static const char chat_cmd_list[AC_NUM_CHAT_COMMANDS][MAX_CMDNAME_SIZE] = {
|
||||
{ "/sdev" },
|
||||
{ "/mute" },
|
||||
{ "/sense" },
|
||||
{ "/video" },
|
||||
|
||||
#endif /* AUDIO */
|
||||
};
|
||||
@ -123,15 +127,18 @@ void kill_chat_window(ToxWindow *self, Tox *m)
|
||||
ChatContext *ctx = self->chatwin;
|
||||
StatusBar *statusbar = self->stb;
|
||||
|
||||
#ifdef AUDIO
|
||||
#ifdef VIDEO
|
||||
stop_video_stream(self);
|
||||
#endif /* VIDEO */
|
||||
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);
|
||||
|
||||
#ifdef AUDIO
|
||||
stop_current_call(self);
|
||||
#endif
|
||||
|
||||
delwin(ctx->linewin);
|
||||
delwin(ctx->history);
|
||||
delwin(statusbar->topline);
|
||||
|
@ -522,7 +522,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];
|
||||
@ -592,11 +592,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])
|
||||
|
@ -156,7 +156,7 @@ static void help_draw_global(ToxWindow *self)
|
||||
wprintw(win, " /group : Create a group chat\n");
|
||||
wprintw(win, " /join <chat id> <passwd> : Join a group chat with optional password\n");
|
||||
wprintw(win, " /nick <nick> : Set your nickname\n");
|
||||
wprintw(win, " /nospam : Change part of your Tox ID to stop spam\n");
|
||||
wprintw(win, " /nospam <value> : Change part of your Tox ID to stop spam\n");
|
||||
wprintw(win, " /log <on> or <off> : Enable/disable logging\n");
|
||||
wprintw(win, " /myid : Print your Tox ID\n");
|
||||
wprintw(win, " /myqr : Print your Tox ID's QR code to a file.\n");
|
||||
|
@ -300,12 +300,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)
|
||||
|
@ -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);
|
||||
|
||||
|
@ -154,11 +154,9 @@ void exit_toxic_success(Tox *m)
|
||||
terminate_notify();
|
||||
|
||||
#ifdef AUDIO
|
||||
|
||||
#ifdef VIDEO
|
||||
terminate_video();
|
||||
#endif /* VIDEO */
|
||||
|
||||
terminate_audio();
|
||||
#endif /* AUDIO */
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -26,7 +26,7 @@
|
||||
#include <tox/toxav.h>
|
||||
|
||||
#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 */
|
||||
#endif /* VIDEO_CALL_H */
|
||||
|
@ -30,7 +30,7 @@
|
||||
|
||||
#include <vpx/vpx_image.h>
|
||||
|
||||
#ifdef __linux__
|
||||
#if defined(__linux__) || defined(__FreeBSD__)
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/mman.h>
|
||||
@ -50,7 +50,6 @@
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
#define inline__ inline __attribute__((always_inline))
|
||||
|
||||
@ -66,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;
|
||||
@ -132,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)
|
||||
{
|
||||
@ -178,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";
|
||||
@ -258,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__ */
|
||||
@ -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 ) {
|
||||
@ -329,13 +336,14 @@ 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);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -622,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));
|
||||
|
||||
@ -680,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;
|
||||
@ -715,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) ) {}
|
||||
|
||||
@ -735,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__ */
|
||||
|
||||
|
@ -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 = {
|
||||
|
Loading…
Reference in New Issue
Block a user