mirror of
https://github.com/Tha14/toxic.git
synced 2025-07-03 06:06:45 +02:00
Update astylerc to match toxcore & reformat all source files
This commit is contained in:
136
src/video_call.c
136
src/video_call.c
@ -41,15 +41,15 @@
|
||||
|
||||
#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,
|
||||
int32_t ystride, int32_t ustride, int32_t vstride,
|
||||
void *user_data );
|
||||
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,
|
||||
int32_t ystride, int32_t ustride, int32_t vstride,
|
||||
void *user_data);
|
||||
|
||||
void video_bit_rate_status_cb( ToxAV *av, uint32_t friend_number, uint32_t video_bit_rate, void *user_data);
|
||||
void video_bit_rate_status_cb(ToxAV *av, uint32_t friend_number, uint32_t video_bit_rate, void *user_data);
|
||||
|
||||
static void print_err (ToxWindow *self, const char *error_str)
|
||||
static void print_err(ToxWindow *self, const char *error_str)
|
||||
{
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s", error_str);
|
||||
}
|
||||
@ -62,13 +62,13 @@ ToxAV *init_video(ToxWindow *self, Tox *tox)
|
||||
CallControl.video_bit_rate = 0;
|
||||
CallControl.video_frame_duration = 10;
|
||||
|
||||
if ( !CallControl.av ) {
|
||||
if (!CallControl.av) {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Video failed to init with ToxAV instance");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ( init_video_devices(CallControl.av) == vde_InternalError ) {
|
||||
if (init_video_devices(CallControl.av) == vde_InternalError) {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to init video devices");
|
||||
|
||||
return NULL;
|
||||
@ -89,8 +89,9 @@ void terminate_video()
|
||||
|
||||
stop_video_transmission(this_call, i);
|
||||
|
||||
if ( this_call->vout_idx != -1 )
|
||||
if (this_call->vout_idx != -1) {
|
||||
close_video_device(vdt_output, this_call->vout_idx);
|
||||
}
|
||||
}
|
||||
|
||||
terminate_video_devices();
|
||||
@ -104,18 +105,19 @@ void read_video_device_callback(int16_t width, int16_t height, const uint8_t *y,
|
||||
TOXAV_ERR_SEND_FRAME error;
|
||||
|
||||
/* Drop frame if video sending is disabled */
|
||||
if ( CallControl.video_bit_rate == 0 || this_call->vin_idx == -1 ) {
|
||||
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 ) {
|
||||
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");
|
||||
|
||||
if ( error == TOXAV_ERR_SEND_FRAME_NULL )
|
||||
if (error == TOXAV_ERR_SEND_FRAME_NULL) {
|
||||
line_info_add(CallControl.prompt, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to capture video frame");
|
||||
else if ( error == TOXAV_ERR_SEND_FRAME_INVALID )
|
||||
} else if (error == TOXAV_ERR_SEND_FRAME_INVALID) {
|
||||
line_info_add(CallControl.prompt, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to prepare video frame");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -129,24 +131,24 @@ void write_video_device_callback(uint32_t friend_number, uint16_t width, uint16_
|
||||
|
||||
int start_video_transmission(ToxWindow *self, ToxAV *av, Call *call)
|
||||
{
|
||||
if ( !self || !av) {
|
||||
if (!self || !av) {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to prepare transmission");
|
||||
return -1;
|
||||
}
|
||||
|
||||
CallControl.video_bit_rate = default_video_bit_rate;
|
||||
|
||||
if ( toxav_video_set_bit_rate(CallControl.av, self->num, CallControl.video_bit_rate, NULL) == false ) {
|
||||
if (toxav_video_set_bit_rate(CallControl.av, self->num, 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;
|
||||
}
|
||||
|
||||
if ( open_primary_video_device(vdt_input, &call->vin_idx) != vde_None ) {
|
||||
if (open_primary_video_device(vdt_input, &call->vin_idx) != vde_None) {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to open input video device!");
|
||||
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;
|
||||
}
|
||||
@ -159,7 +161,7 @@ int stop_video_transmission(Call *call, int friend_number)
|
||||
CallControl.video_bit_rate = 0;
|
||||
toxav_video_set_bit_rate(CallControl.av, friend_number, CallControl.video_bit_rate, NULL);
|
||||
|
||||
if ( call->vin_idx != -1 ) {
|
||||
if (call->vin_idx != -1) {
|
||||
close_video_device(vdt_input, call->vin_idx);
|
||||
call->vin_idx = -1;
|
||||
}
|
||||
@ -196,8 +198,9 @@ 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);
|
||||
}
|
||||
@ -220,8 +223,8 @@ void callback_video_starting(uint32_t friend_number)
|
||||
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 (windows[i].is_call && windows[i].num == friend_number) {
|
||||
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;
|
||||
}
|
||||
@ -249,54 +252,60 @@ void cmd_video(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[M
|
||||
const char *error_str;
|
||||
Call *this_call = &CallControl.calls[self->num];
|
||||
|
||||
if ( argc != 0 ) {
|
||||
if (argc != 0) {
|
||||
error_str = "Unknown arguments.";
|
||||
goto on_error;
|
||||
}
|
||||
|
||||
if ( !CallControl.av ) {
|
||||
if (!CallControl.av) {
|
||||
error_str = "ToxAV not supported!";
|
||||
goto on_error;
|
||||
}
|
||||
|
||||
if ( !self->stb->connection ) {
|
||||
if (!self->stb->connection) {
|
||||
error_str = "Friend is offline.";
|
||||
goto on_error;
|
||||
}
|
||||
|
||||
if ( !self->is_call ) {
|
||||
if (!self->is_call) {
|
||||
error_str = "Not in call!";
|
||||
goto on_error;
|
||||
}
|
||||
|
||||
if ( this_call->vin_idx == -1 )
|
||||
if (this_call->vin_idx == -1) {
|
||||
callback_video_starting(self->num);
|
||||
else
|
||||
} else {
|
||||
callback_video_end(self->num);
|
||||
}
|
||||
|
||||
return;
|
||||
on_error:
|
||||
print_err (self, error_str);
|
||||
print_err(self, error_str);
|
||||
}
|
||||
|
||||
void cmd_list_video_devices(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
||||
{
|
||||
const char *error_str;
|
||||
|
||||
if ( argc != 1 ) {
|
||||
if ( argc < 1 ) error_str = "Type must be specified!";
|
||||
else error_str = "Only one argument allowed!";
|
||||
if (argc != 1) {
|
||||
if (argc < 1) {
|
||||
error_str = "Type must be specified!";
|
||||
} else {
|
||||
error_str = "Only one argument allowed!";
|
||||
}
|
||||
|
||||
goto on_error;
|
||||
}
|
||||
|
||||
VideoDeviceType type;
|
||||
|
||||
if ( strcasecmp(argv[1], "in") == 0 ) /* Input devices */
|
||||
if (strcasecmp(argv[1], "in") == 0) { /* Input devices */
|
||||
type = vdt_input;
|
||||
}
|
||||
|
||||
else if ( strcasecmp(argv[1], "out") == 0 ) /* Output devices */
|
||||
else if (strcasecmp(argv[1], "out") == 0) { /* Output devices */
|
||||
type = vdt_output;
|
||||
}
|
||||
|
||||
else {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid type: %s", argv[1]);
|
||||
@ -307,7 +316,7 @@ void cmd_list_video_devices(WINDOW *window, ToxWindow *self, Tox *m, int argc, c
|
||||
|
||||
return;
|
||||
on_error:
|
||||
print_err (self, error_str);
|
||||
print_err(self, error_str);
|
||||
}
|
||||
|
||||
/* This changes primary video device only */
|
||||
@ -315,21 +324,27 @@ void cmd_change_video_device(WINDOW *window, ToxWindow *self, Tox *m, int argc,
|
||||
{
|
||||
const char *error_str;
|
||||
|
||||
if ( argc != 2 ) {
|
||||
if ( argc < 1 ) error_str = "Type must be specified!";
|
||||
else if ( argc < 2 ) error_str = "Must have id!";
|
||||
else error_str = "Only two arguments allowed!";
|
||||
if (argc != 2) {
|
||||
if (argc < 1) {
|
||||
error_str = "Type must be specified!";
|
||||
} else if (argc < 2) {
|
||||
error_str = "Must have id!";
|
||||
} else {
|
||||
error_str = "Only two arguments allowed!";
|
||||
}
|
||||
|
||||
goto on_error;
|
||||
}
|
||||
|
||||
VideoDeviceType type;
|
||||
|
||||
if ( strcmp(argv[1], "in") == 0 ) /* Input devices */
|
||||
if (strcmp(argv[1], "in") == 0) { /* Input devices */
|
||||
type = vdt_input;
|
||||
}
|
||||
|
||||
else if ( strcmp(argv[1], "out") == 0 ) /* Output devices */
|
||||
else if (strcmp(argv[1], "out") == 0) { /* Output devices */
|
||||
type = vdt_output;
|
||||
}
|
||||
|
||||
else {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid type: %s", argv[1]);
|
||||
@ -340,40 +355,46 @@ void cmd_change_video_device(WINDOW *window, ToxWindow *self, Tox *m, int argc,
|
||||
char *end;
|
||||
long int selection = strtol(argv[2], &end, 10);
|
||||
|
||||
if ( *end ) {
|
||||
if (*end) {
|
||||
error_str = "Invalid input";
|
||||
goto on_error;
|
||||
}
|
||||
|
||||
if ( set_primary_video_device(type, selection) == vde_InvalidSelection ) {
|
||||
if (set_primary_video_device(type, selection) == vde_InvalidSelection) {
|
||||
error_str = "Invalid selection!";
|
||||
goto on_error;
|
||||
}
|
||||
|
||||
return;
|
||||
on_error:
|
||||
print_err (self, error_str);
|
||||
print_err(self, error_str);
|
||||
}
|
||||
|
||||
void cmd_ccur_video_device(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
||||
{
|
||||
const char *error_str;
|
||||
|
||||
if ( argc != 2 ) {
|
||||
if ( argc < 1 ) error_str = "Type must be specified!";
|
||||
else if ( argc < 2 ) error_str = "Must have id!";
|
||||
else error_str = "Only two arguments allowed!";
|
||||
if (argc != 2) {
|
||||
if (argc < 1) {
|
||||
error_str = "Type must be specified!";
|
||||
} else if (argc < 2) {
|
||||
error_str = "Must have id!";
|
||||
} else {
|
||||
error_str = "Only two arguments allowed!";
|
||||
}
|
||||
|
||||
goto on_error;
|
||||
}
|
||||
|
||||
VideoDeviceType type;
|
||||
|
||||
if ( strcmp(argv[1], "in") == 0 ) /* Input devices */
|
||||
if (strcmp(argv[1], "in") == 0) { /* Input devices */
|
||||
type = vdt_input;
|
||||
}
|
||||
|
||||
else if ( strcmp(argv[1], "out") == 0 ) /* Output devices */
|
||||
else if (strcmp(argv[1], "out") == 0) { /* Output devices */
|
||||
type = vdt_output;
|
||||
}
|
||||
|
||||
else {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid type: %s", argv[1]);
|
||||
@ -384,23 +405,23 @@ void cmd_ccur_video_device(WINDOW *window, ToxWindow *self, Tox *m, int argc, ch
|
||||
char *end;
|
||||
long int selection = strtol(argv[2], &end, 10);
|
||||
|
||||
if ( *end ) {
|
||||
if (*end) {
|
||||
error_str = "Invalid input";
|
||||
goto on_error;
|
||||
}
|
||||
|
||||
if ( video_selection_valid(type, selection) == vde_InvalidSelection ) {
|
||||
if (video_selection_valid(type, selection) == vde_InvalidSelection) {
|
||||
error_str = "Invalid selection!";
|
||||
goto on_error;
|
||||
}
|
||||
|
||||
/* If call is active, change device */
|
||||
if ( self->is_call ) {
|
||||
if (self->is_call) {
|
||||
Call *this_call = &CallControl.calls[self->num];
|
||||
|
||||
if ( this_call->ttas ) {
|
||||
if (this_call->ttas) {
|
||||
|
||||
if ( type == vdt_output ) {
|
||||
if (type == vdt_output) {
|
||||
} else {
|
||||
/* TODO: check for failure */
|
||||
close_video_device(vdt_input, this_call->vin_idx);
|
||||
@ -414,15 +435,16 @@ void cmd_ccur_video_device(WINDOW *window, ToxWindow *self, Tox *m, int argc, ch
|
||||
|
||||
return;
|
||||
on_error:
|
||||
print_err (self, error_str);
|
||||
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)
|
||||
if (this_call && this_call->vin_idx != -1) {
|
||||
stop_video_transmission(this_call, self->num);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user