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

Fixed video call receiving issues

This commit is contained in:
cnhenry 2015-08-12 04:33:59 -05:00
parent 6e0d19b01d
commit 2cdcbc07a7
5 changed files with 50 additions and 114 deletions

View File

@ -63,7 +63,7 @@ static int set_call(Call* call, bool start)
call->out_idx = -1;
#ifdef VIDEO
call->vin_idx = -1;
call->vin_idx = -1;
call->vout_idx = -1;
#endif /* VIDEO */
if ( start ) {
@ -273,12 +273,11 @@ void call_cb(ToxAV *av, uint32_t friend_number, bool audio_enabled, bool video_e
void callstate_cb(ToxAV *av, uint32_t friend_number, uint32_t state, void *user_data)
{
ToxWindow* windows = CallControl.prompt;
CallControl.call_state = state;
switch ( state ) {
case ( TOXAV_FRIEND_CALL_STATE_ERROR ):
line_info_add(windows, NULL, NULL, NULL, SYS_MSG, 0, 0, "ToxAV callstate error!");
line_info_add(CallControl.prompt, NULL, NULL, NULL, SYS_MSG, 0, 0, "ToxAV callstate error!");
#ifdef VIDEO
callback_video_end(friend_number);
@ -309,25 +308,22 @@ void callstate_cb(ToxAV *av, uint32_t friend_number, uint32_t state, void *user_
default:
if ( CallControl.pending_call ) {
/* Start answered call */
callback_call_started(friend_number);
callback_call_started(friend_number);
CallControl.pending_call = false;
} else {
#ifdef VIDEO
/* Handle receiving client video call states */
if ( state & ~TOXAV_FRIEND_CALL_STATE_SENDING_V )
if ( state & TOXAV_FRIEND_CALL_STATE_SENDING_V )
callback_recv_video_starting(friend_number);
else if ( state & ~TOXAV_FRIEND_CALL_STATE_SENDING_V )
callback_recv_video_end(friend_number);
if ( state & ~(TOXAV_FRIEND_CALL_STATE_ACCEPTING_V & TOXAV_FRIEND_CALL_STATE_SENDING_V)
&& CallControl.video_call != vs_Send )
CallControl.video_call = vs_None;
#endif /* VIDEO */
}
break;
}
}
void receive_audio_frame_cb(ToxAV *av, uint32_t friend_number,
@ -565,12 +561,17 @@ void cmd_hangup(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[
#endif /* VIDEO */
stop_transmission(&CallControl.calls[self->num], self->num);
if ( CallControl.pending_call )
callback_call_ended(self->num);
else
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;

View File

@ -44,13 +44,6 @@ typedef enum _VideoError {
ve_StartingCoreVideo = 1 << 2
} VideoError;
typedef enum _VideoState {
vs_None = 0,
vs_Send = 1 << 0,
vs_Receive = 1 << 1,
vs_SendReceive = 1 << 2
} VideoState;
#endif /* VIDEO */
typedef struct Call {
@ -86,7 +79,6 @@ struct CallControl {
#ifdef VIDEO
uint32_t video_bit_rate;
int32_t video_frame_duration;
VideoState video_call;
#endif /* VIDEO */

View File

@ -37,6 +37,8 @@
#include <stdlib.h>
#include <assert.h>
#define default_video_bit_rate 5000
void receive_video_frame_cb( ToxAV *av, uint32_t friend_number,
uint16_t width, uint16_t height,
uint8_t const *y, uint8_t const *u, uint8_t const *v,
@ -55,9 +57,8 @@ ToxAV *init_video(ToxWindow *self, Tox *tox)
CallControl.video_errors = ve_None;
CallControl.video_enabled = true;
CallControl.video_bit_rate = 5000;
CallControl.video_bit_rate = 0;
CallControl.video_frame_duration = 10;
CallControl.video_call = vs_None;
if ( !CallControl.av ) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Video failed to init with ToxAV instance");
@ -89,8 +90,15 @@ void terminate_video()
void read_video_device_callback(int16_t width, int16_t height, const uint8_t* y, const uint8_t* u, const uint8_t* v, void* data)
{
uint32_t friend_number = *((uint32_t*)data); /* TODO: Or pass an array of call_idx's */
Call* this_call = &CallControl.calls[friend_number];
TOXAV_ERR_SEND_FRAME error;
/* Drop frame if video sending is disabled */
if ( CallControl.video_bit_rate == 0 || this_call->vin_idx == -1 ) {
line_info_add(CallControl.prompt, NULL, NULL, NULL, SYS_MSG, 0, 0, "Video frame dropped.");
return;
}
if ( toxav_video_send_frame(CallControl.av, friend_number, width, height, y, u, v, &error ) == false ) {
line_info_add(CallControl.prompt, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to send video frame");
@ -106,8 +114,10 @@ void write_video_device_callback(uint32_t friend_number, uint16_t width, uint16_
int32_t ystride, int32_t ustride, int32_t vstride,
void *user_data)
{
if (write_video_out(width, height, y, u, v, ystride, ustride, vstride, user_data) == vde_DeviceNotActive)
callback_recv_video_starting(friend_number);
if ( write_video_out(width, height, y, u, v, ystride, ustride, vstride, user_data) == vde_DeviceNotActive ) {
//callback_recv_video_starting(friend_number);
return;
}
}
int start_video_transmission(ToxWindow *self, ToxAV *av, Call *call)
@ -117,7 +127,8 @@ int start_video_transmission(ToxWindow *self, ToxAV *av, Call *call)
return -1;
}
if (toxav_video_bit_rate_set(CallControl.av, self->num, CallControl.video_bit_rate, true, NULL) == false) {
CallControl.video_bit_rate = default_video_bit_rate;
if ( toxav_video_bit_rate_set(CallControl.av, self->num, CallControl.video_bit_rate, true, NULL) == false ) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to set video bit rate");
return -1;
}
@ -135,15 +146,12 @@ int start_video_transmission(ToxWindow *self, ToxAV *av, Call *call)
int stop_video_transmission(Call *call, int friend_number)
{
if (toxav_video_bit_rate_set(CallControl.av, friend_number, 0, true, NULL)) {
return -1;
}
CallControl.video_bit_rate = 0;
toxav_video_bit_rate_set(CallControl.av, friend_number, CallControl.video_bit_rate, true, NULL);
if ( call->vin_idx != -1 )
close_video_device(vdt_input, call->vin_idx);
if ( call->vout_idx != -1 )
close_video_device(vdt_output, call->vout_idx);
call->vin_idx = -1;
return 0;
}
@ -180,30 +188,17 @@ void callback_recv_video_starting(uint32_t friend_number)
{
Call* this_call = &CallControl.calls[friend_number];
if ( this_call->vout_idx == -1 )
if ( this_call->vout_idx != -1 )
return;
open_primary_video_device(vdt_output, &this_call->vout_idx);
if ( CallControl.video_call == vs_Send )
CallControl.video_call = vs_SendReceive;
else
CallControl.video_call = vs_Receive;
//line_info_add(CallControl.prompt, NULL, NULL, NULL, SYS_MSG, 0, 0, "%i recv start", CallControl.video_call);
}
void callback_recv_video_end(uint32_t friend_number)
{
{
Call* this_call = &CallControl.calls[friend_number];
close_video_device(vdt_output, this_call->vout_idx);
if ( CallControl.video_call == vs_SendReceive )
CallControl.video_call = vs_Send;
else
CallControl.video_call = vs_None;
//line_info_add(CallControl.prompt, NULL, NULL, NULL, SYS_MSG, 0, 0, "%i recv end", CallControl.video_call);
this_call->vout_idx = -1;
}
void callback_video_starting(uint32_t friend_number)
{
@ -223,13 +218,6 @@ void callback_video_starting(uint32_t friend_number)
}
line_info_add(&windows[i], NULL, NULL, NULL, SYS_MSG, 0, 0, "Video capture starting.");
if ( CallControl.video_call == vs_Receive )
CallControl.video_call = vs_SendReceive;
else
CallControl.video_call = vs_Send;
//line_info_add(CallControl.prompt, NULL, NULL, NULL, SYS_MSG, 0, 0, "%i start", CallControl.video_call);
}
}
}
@ -238,24 +226,12 @@ void callback_video_end(uint32_t friend_number)
{
ToxWindow* windows = CallControl.prompt;
if ( CallControl.video_call != vs_None ) {
int i;
for (i = 0; i < MAX_WINDOWS_NUM; ++i)
if ( windows[i].is_call && windows[i].num == friend_number )
line_info_add(&windows[i], NULL, NULL, NULL, SYS_MSG, 0, 0, "Video capture ending.");
int i;
for (i = 0; i < MAX_WINDOWS_NUM; ++i)
if ( windows[i].is_call && windows[i].num == friend_number )
line_info_add(&windows[i], NULL, NULL, NULL, SYS_MSG, 0, 0, "Video capture ending.");
toxav_video_bit_rate_set(CallControl.av, friend_number, 0, true, NULL);
for (i = 0; i < MAX_CALLS; ++i)
stop_video_transmission(&CallControl.calls[i], i);
if ( CallControl.video_call == vs_SendReceive )
CallControl.video_call = vs_Receive;
else
CallControl.video_call = vs_None;
//line_info_add(CallControl.prompt, NULL, NULL, NULL, SYS_MSG, 0, 0, "%i end", CallControl.video_call);
}
stop_video_transmission(&CallControl.calls[friend_number], friend_number);
}
/*
* End of Callbacks
@ -269,6 +245,7 @@ void callback_video_end(uint32_t friend_number)
void cmd_video(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
const char *error_str;
Call* this_call = &CallControl.calls[self->num];
if ( argc != 0 ) {
error_str = "Unknown arguments.";
@ -290,7 +267,7 @@ void cmd_video(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[M
goto on_error;
}
if ( CallControl.video_call == vs_Send || CallControl.video_call == vs_SendReceive ) {
if ( this_call->vin_idx != -1 ) {
error_str = "Video is already sending in this call.";
goto on_error;
}
@ -305,6 +282,7 @@ on_error:
void cmd_end_video(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
const char *error_str;
Call* this_call = &CallControl.calls[self->num];
if ( argc != 0 ) {
error_str = "Unknown arguments.";
@ -316,7 +294,7 @@ void cmd_end_video(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*arg
goto on_error;
}
if ( CallControl.video_call == vs_None ) {
if ( this_call->vin_idx == -1 ) {
error_str = "Video is not running in this call.";
goto on_error;
}

View File

@ -19,27 +19,6 @@
* along with Toxic. If not, see <http://www.gnu.org/licenses/>.
*
*/
/* video_call.h
*
*
* Copyright (C) 2014 Toxic All Rights Reserved.
*
* This file is part of Toxic.
*
* Toxic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Toxic is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Toxic. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef VIDEO_CALL_H
#define VIDEO_CALL_H

View File

@ -185,8 +185,8 @@ VideoDeviceError init_video_devices()
char* video_input_name;
/* Query V4L for capture capabilities */
if ( ioctl(fd, VIDIOC_QUERYCAP, &cap) == -1 ) {
video_input_name = &cap.card;
if ( ioctl(fd, VIDIOC_QUERYCAP, &cap) != -1 ) {
video_input_name = cap.card;
} else {
video_input_name = device_address;
}
@ -508,21 +508,6 @@ __inline VideoDeviceError write_video_out(uint16_t width, uint16_t height,
pthread_mutex_lock(device->mutex);
/* Recreate missing X11 window */
/*if ( !device->x_window ) {
int screen = DefaultScreen(device->x_display);
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));
XMapWindow(device->x_display, device->x_window);
XClearWindow(device->x_display, device->x_window);
XMapRaised(device->x_display, device->x_window);
XFlush(device->x_display);
}*/
/* Resize X11 window to correct size */
if ( device->video_width != width || device->video_height != height ) {
device->video_width = width;
@ -588,12 +573,13 @@ void* video_thread_poll (void* arg) // TODO: maybe use thread for every input so
if ( video_devices_running[vdt_input][i] != NULL )
{
/* Obtain frame image data from device buffers */
VideoDevice* device = video_devices_running[vdt_input][i];
void *data;
uint16_t video_width;
uint16_t video_height;
uint8_t *y, *u, *v;
#ifdef __linux__
VideoDevice* device = video_devices_running[vdt_input][i];
struct v4l2_buffer buf;
memset(&(buf), 0, sizeof(buf));