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

Fix various video bugs; it should be working now!

This commit is contained in:
Jfreegman 2015-11-12 05:01:28 -05:00
parent d16be574f3
commit 05f5f16af3
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63
8 changed files with 109 additions and 83 deletions

View File

@ -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.";

View File

@ -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);

View File

@ -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];

View File

@ -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)

View File

@ -153,11 +153,9 @@ void exit_toxic_success(Tox *m)
terminate_notify();
#ifdef AUDIO
#ifdef VIDEO
terminate_video();
#endif /* VIDEO */
terminate_audio();
#endif /* AUDIO */

View File

@ -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);
}

View File

@ -34,6 +34,7 @@ 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);

View File

@ -50,7 +50,6 @@
#include <pthread.h>
#include <unistd.h>
#include <stdlib.h>
#include <assert.h>
#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;
}