2015-08-11 13:11:09 +02:00
|
|
|
/* video_call.c
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2015-07-22 20:06:14 +02:00
|
|
|
#include "toxic.h"
|
|
|
|
#include "windows.h"
|
|
|
|
#include "video_call.h"
|
2015-07-24 20:10:13 +02:00
|
|
|
#include "video_device.h"
|
2015-07-22 20:06:14 +02:00
|
|
|
#include "chat_commands.h"
|
|
|
|
#include "global_commands.h"
|
|
|
|
#include "line_info.h"
|
|
|
|
#include "notify.h"
|
2020-03-15 19:57:00 +01:00
|
|
|
#include "misc_tools.h"
|
2015-07-22 20:06:14 +02:00
|
|
|
|
2015-08-10 13:14:38 +02:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <curses.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <assert.h>
|
2015-07-24 20:10:13 +02:00
|
|
|
|
2018-07-06 17:45:35 +02:00
|
|
|
#ifdef VIDEO
|
|
|
|
|
2015-08-12 11:33:59 +02:00
|
|
|
#define default_video_bit_rate 5000
|
|
|
|
|
2018-07-18 17:41:17 +02:00
|
|
|
void on_video_receive_frame(ToxAV *av, uint32_t friend_number,
|
2018-07-18 17:33:16 +02:00
|
|
|
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);
|
2015-10-20 23:59:14 +02:00
|
|
|
|
2018-07-18 17:41:17 +02:00
|
|
|
void on_video_bit_rate(ToxAV *av, uint32_t friend_number, uint32_t video_bit_rate, void *user_data);
|
2015-07-24 20:10:13 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
static void print_err(ToxWindow *self, const char *error_str)
|
2015-07-24 20:10:13 +02:00
|
|
|
{
|
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s", error_str);
|
|
|
|
}
|
2015-07-22 20:06:14 +02:00
|
|
|
|
2015-08-11 13:11:09 +02:00
|
|
|
ToxAV *init_video(ToxWindow *self, Tox *tox)
|
2015-07-22 20:06:14 +02:00
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(tox);
|
|
|
|
|
2015-08-11 13:11:09 +02:00
|
|
|
CallControl.video_errors = ve_None;
|
|
|
|
|
2015-08-10 13:14:38 +02:00
|
|
|
CallControl.video_enabled = true;
|
2015-08-12 11:33:59 +02:00
|
|
|
CallControl.video_bit_rate = 0;
|
2015-08-10 13:14:38 +02:00
|
|
|
CallControl.video_frame_duration = 10;
|
2015-07-22 20:06:14 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (!CallControl.av) {
|
2015-08-10 13:14:38 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Video failed to init with ToxAV instance");
|
|
|
|
|
2015-07-24 20:10:13 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2015-07-22 20:06:14 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (init_video_devices(CallControl.av) == vde_InternalError) {
|
2015-07-24 20:10:13 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to init video devices");
|
2015-08-10 13:14:38 +02:00
|
|
|
|
2015-07-24 20:10:13 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2015-07-22 20:06:14 +02:00
|
|
|
|
2018-07-18 17:41:17 +02:00
|
|
|
toxav_callback_video_receive_frame(CallControl.av, on_video_receive_frame, &CallControl);
|
|
|
|
toxav_callback_video_bit_rate(CallControl.av, on_video_bit_rate, &CallControl);
|
2015-07-22 20:06:14 +02:00
|
|
|
|
2015-08-11 13:11:09 +02:00
|
|
|
return CallControl.av;
|
2015-07-24 20:10:13 +02:00
|
|
|
}
|
2015-07-22 20:06:14 +02:00
|
|
|
|
2018-09-08 19:23:07 +02:00
|
|
|
void terminate_video(void)
|
2015-08-06 06:26:45 +02:00
|
|
|
{
|
|
|
|
int i;
|
2016-09-25 03:07:04 +02:00
|
|
|
|
2017-11-20 13:02:56 +01:00
|
|
|
for (i = 0; i < CallControl.max_calls; ++i) {
|
2016-09-25 03:07:04 +02:00
|
|
|
Call *this_call = &CallControl.calls[i];
|
2015-08-14 03:01:05 +02:00
|
|
|
|
|
|
|
stop_video_transmission(this_call, i);
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (this_call->vout_idx != -1) {
|
2015-08-14 03:01:05 +02:00
|
|
|
close_video_device(vdt_output, this_call->vout_idx);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2015-08-14 03:01:05 +02:00
|
|
|
}
|
2015-08-06 06:26:45 +02:00
|
|
|
|
|
|
|
terminate_video_devices();
|
|
|
|
}
|
|
|
|
|
2016-09-25 03:07:04 +02:00
|
|
|
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)
|
2015-07-30 08:49:27 +02:00
|
|
|
{
|
2016-09-25 03:07:04 +02:00
|
|
|
uint32_t friend_number = *((uint32_t *)data); /* TODO: Or pass an array of call_idx's */
|
|
|
|
Call *this_call = &CallControl.calls[friend_number];
|
2018-10-10 05:06:57 +02:00
|
|
|
Toxav_Err_Send_Frame error;
|
2015-08-10 13:14:38 +02:00
|
|
|
|
2015-08-12 11:33:59 +02:00
|
|
|
/* Drop frame if video sending is disabled */
|
2018-07-18 17:33:16 +02:00
|
|
|
if (CallControl.video_bit_rate == 0 || this_call->vin_idx == -1) {
|
2015-08-12 11:33:59 +02:00
|
|
|
line_info_add(CallControl.prompt, NULL, NULL, NULL, SYS_MSG, 0, 0, "Video frame dropped.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (toxav_video_send_frame(CallControl.av, friend_number, width, height, y, u, v, &error) == false) {
|
2015-08-10 13:14:38 +02:00
|
|
|
line_info_add(CallControl.prompt, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to send video frame");
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (error == TOXAV_ERR_SEND_FRAME_NULL) {
|
2015-08-11 13:11:09 +02:00
|
|
|
line_info_add(CallControl.prompt, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to capture video frame");
|
2018-07-18 17:33:16 +02:00
|
|
|
} else if (error == TOXAV_ERR_SEND_FRAME_INVALID) {
|
2015-08-11 13:11:09 +02:00
|
|
|
line_info_add(CallControl.prompt, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to prepare video frame");
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2015-08-06 06:26:45 +02:00
|
|
|
}
|
2015-07-30 08:49:27 +02:00
|
|
|
}
|
|
|
|
|
2015-08-07 18:40:35 +02:00
|
|
|
void write_video_device_callback(uint32_t friend_number, uint16_t width, uint16_t height,
|
2016-09-25 03:07:04 +02:00
|
|
|
uint8_t const *y, uint8_t const *u, uint8_t const *v,
|
|
|
|
int32_t ystride, int32_t ustride, int32_t vstride,
|
|
|
|
void *user_data)
|
2015-07-30 08:49:27 +02:00
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(friend_number);
|
|
|
|
|
2015-08-14 06:51:39 +02:00
|
|
|
write_video_out(width, height, y, u, v, ystride, ustride, vstride, user_data);
|
2015-07-30 08:49:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int start_video_transmission(ToxWindow *self, ToxAV *av, Call *call)
|
|
|
|
{
|
2018-07-18 17:33:16 +02:00
|
|
|
if (!self || !av) {
|
2015-08-10 13:14:38 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to prepare transmission");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-08-12 11:33:59 +02:00
|
|
|
CallControl.video_bit_rate = default_video_bit_rate;
|
2015-11-12 11:01:28 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (toxav_video_set_bit_rate(CallControl.av, self->num, CallControl.video_bit_rate, NULL) == false) {
|
2015-08-10 13:14:38 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to set video bit rate");
|
2015-07-30 08:49:27 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (open_primary_video_device(vdt_input, &call->vin_idx) != vde_None) {
|
2015-07-30 08:49:27 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to open input video device!");
|
2015-08-07 18:40:35 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2015-10-20 23:59:14 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (register_video_device_callback(self->num, call->vin_idx, read_video_device_callback, &self->num) != vde_None) {
|
2015-07-30 08:49:27 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to register input video handler!");
|
2015-11-12 11:01:28 +01:00
|
|
|
return -1;
|
|
|
|
}
|
2015-07-30 08:49:27 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int stop_video_transmission(Call *call, int friend_number)
|
|
|
|
{
|
2015-08-12 11:33:59 +02:00
|
|
|
CallControl.video_bit_rate = 0;
|
2018-02-24 21:38:07 +01:00
|
|
|
toxav_video_set_bit_rate(CallControl.av, friend_number, CallControl.video_bit_rate, NULL);
|
2015-08-10 13:14:38 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (call->vin_idx != -1) {
|
2015-08-11 13:11:09 +02:00
|
|
|
close_video_device(vdt_input, call->vin_idx);
|
2015-08-12 11:33:59 +02:00
|
|
|
call->vin_idx = -1;
|
2015-11-08 09:57:01 +01:00
|
|
|
}
|
2015-08-10 13:14:38 +02:00
|
|
|
|
2015-08-07 18:40:35 +02:00
|
|
|
return 0;
|
2015-07-30 08:49:27 +02:00
|
|
|
}
|
2015-08-06 06:26:45 +02:00
|
|
|
/*
|
|
|
|
* End of transmission
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Callbacks
|
|
|
|
*/
|
2018-07-18 17:41:17 +02:00
|
|
|
void on_video_receive_frame(ToxAV *av, uint32_t friend_number,
|
2016-09-25 03:07:04 +02:00
|
|
|
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)
|
2015-07-24 20:10:13 +02:00
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(av);
|
|
|
|
|
2015-08-07 18:40:35 +02:00
|
|
|
write_video_device_callback(friend_number, width, height, y, u, v, ystride, ustride, vstride, user_data);
|
2015-07-24 20:10:13 +02:00
|
|
|
}
|
2015-07-22 20:06:14 +02:00
|
|
|
|
2018-07-18 17:41:17 +02:00
|
|
|
void on_video_bit_rate(ToxAV *av, uint32_t friend_number, uint32_t video_bit_rate, void *user_data)
|
2015-07-22 20:06:14 +02:00
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(av);
|
|
|
|
UNUSED_VAR(user_data);
|
|
|
|
|
2015-10-20 23:59:14 +02:00
|
|
|
CallControl.video_bit_rate = video_bit_rate;
|
2018-02-24 21:38:07 +01:00
|
|
|
toxav_video_set_bit_rate(CallControl.av, friend_number, CallControl.video_bit_rate, NULL);
|
2015-07-24 20:10:13 +02:00
|
|
|
}
|
|
|
|
|
2015-08-11 13:11:09 +02:00
|
|
|
void callback_recv_video_starting(uint32_t friend_number)
|
2015-08-07 18:40:35 +02:00
|
|
|
{
|
2016-09-25 03:07:04 +02:00
|
|
|
Call *this_call = &CallControl.calls[friend_number];
|
2015-08-07 18:40:35 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (this_call->vout_idx != -1) {
|
2015-11-12 11:01:28 +01:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2015-08-11 13:11:09 +02:00
|
|
|
|
2015-11-12 11:01:28 +01:00
|
|
|
open_primary_video_device(vdt_output, &this_call->vout_idx);
|
2015-08-07 18:40:35 +02:00
|
|
|
}
|
2015-08-11 13:11:09 +02:00
|
|
|
void callback_recv_video_end(uint32_t friend_number)
|
2015-10-20 23:59:14 +02:00
|
|
|
{
|
2016-09-25 03:07:04 +02:00
|
|
|
Call *this_call = &CallControl.calls[friend_number];
|
2015-07-30 08:49:27 +02:00
|
|
|
|
2015-08-11 13:11:09 +02:00
|
|
|
close_video_device(vdt_output, this_call->vout_idx);
|
2015-08-12 11:33:59 +02:00
|
|
|
this_call->vout_idx = -1;
|
2015-08-10 13:14:38 +02:00
|
|
|
}
|
2015-08-11 13:11:09 +02:00
|
|
|
void callback_video_starting(uint32_t friend_number)
|
2015-07-30 08:49:27 +02:00
|
|
|
{
|
2016-09-25 03:07:04 +02:00
|
|
|
Call *this_call = &CallControl.calls[friend_number];
|
2015-08-10 13:14:38 +02:00
|
|
|
|
2018-10-10 05:06:57 +02:00
|
|
|
Toxav_Err_Call_Control error = TOXAV_ERR_CALL_CONTROL_OK;
|
2015-08-10 13:14:38 +02:00
|
|
|
toxav_call_control(CallControl.av, friend_number, TOXAV_CALL_CONTROL_SHOW_VIDEO, &error);
|
|
|
|
|
|
|
|
if (error == TOXAV_ERR_CALL_CONTROL_OK) {
|
2015-11-12 11:01:28 +01:00
|
|
|
size_t i;
|
2016-09-25 03:07:04 +02:00
|
|
|
|
2015-08-10 13:14:38 +02:00
|
|
|
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
2020-04-11 02:00:00 +02:00
|
|
|
ToxWindow *window = get_window_ptr(i);
|
|
|
|
|
|
|
|
if (window != NULL && window->is_call && window->num == friend_number) {
|
|
|
|
if (0 != start_video_transmission(window, CallControl.av, this_call)) {
|
|
|
|
line_info_add(window, NULL, NULL, NULL, SYS_MSG, 0, 0, "Error starting transmission!");
|
2015-08-10 13:14:38 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-11 02:00:00 +02:00
|
|
|
line_info_add(window, NULL, NULL, NULL, SYS_MSG, 0, 0, "Video capture starting.");
|
2015-07-30 08:49:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-08-11 13:11:09 +02:00
|
|
|
void callback_video_end(uint32_t friend_number)
|
2015-07-30 08:49:27 +02:00
|
|
|
{
|
2015-08-12 11:33:59 +02:00
|
|
|
stop_video_transmission(&CallControl.calls[friend_number], friend_number);
|
2015-07-30 08:49:27 +02:00
|
|
|
}
|
2015-08-06 06:26:45 +02:00
|
|
|
/*
|
|
|
|
* End of Callbacks
|
|
|
|
*/
|
2015-07-30 08:49:27 +02:00
|
|
|
|
|
|
|
|
2015-08-07 18:40:35 +02:00
|
|
|
|
2015-08-06 06:26:45 +02:00
|
|
|
/*
|
|
|
|
* Commands from chat_commands.h
|
|
|
|
*/
|
2015-07-30 08:49:27 +02:00
|
|
|
void cmd_video(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(window);
|
|
|
|
UNUSED_VAR(m);
|
|
|
|
UNUSED_VAR(argv);
|
|
|
|
|
2015-11-12 11:01:28 +01:00
|
|
|
const char *error_str;
|
2016-09-25 03:07:04 +02:00
|
|
|
Call *this_call = &CallControl.calls[self->num];
|
2015-11-12 11:01:28 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (argc != 0) {
|
2015-11-12 11:01:28 +01:00
|
|
|
error_str = "Unknown arguments.";
|
|
|
|
goto on_error;
|
|
|
|
}
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (!CallControl.av) {
|
2015-11-12 11:01:28 +01:00
|
|
|
error_str = "ToxAV not supported!";
|
|
|
|
goto on_error;
|
|
|
|
}
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (!self->stb->connection) {
|
2015-11-12 11:01:28 +01:00
|
|
|
error_str = "Friend is offline.";
|
|
|
|
goto on_error;
|
|
|
|
}
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (!self->is_call) {
|
2015-11-12 11:01:28 +01:00
|
|
|
error_str = "Not in call!";
|
|
|
|
goto on_error;
|
|
|
|
}
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (this_call->vin_idx == -1) {
|
2015-11-12 11:01:28 +01:00
|
|
|
callback_video_starting(self->num);
|
2018-07-18 17:33:16 +02:00
|
|
|
} else {
|
2015-11-12 11:01:28 +01:00
|
|
|
callback_video_end(self->num);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2015-11-12 11:01:28 +01:00
|
|
|
|
|
|
|
return;
|
|
|
|
on_error:
|
2018-07-18 17:33:16 +02:00
|
|
|
print_err(self, error_str);
|
2015-07-30 08:49:27 +02:00
|
|
|
}
|
|
|
|
|
2015-07-24 20:10:13 +02:00
|
|
|
void cmd_list_video_devices(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(window);
|
|
|
|
UNUSED_VAR(m);
|
|
|
|
|
2015-07-24 20:10:13 +02:00
|
|
|
const char *error_str;
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (argc != 1) {
|
|
|
|
if (argc < 1) {
|
|
|
|
error_str = "Type must be specified!";
|
|
|
|
} else {
|
|
|
|
error_str = "Only one argument allowed!";
|
|
|
|
}
|
2015-07-24 20:10:13 +02:00
|
|
|
|
|
|
|
goto on_error;
|
|
|
|
}
|
|
|
|
|
2015-07-30 08:49:27 +02:00
|
|
|
VideoDeviceType type;
|
2015-07-24 20:10:13 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (strcasecmp(argv[1], "in") == 0) { /* Input devices */
|
2015-08-16 09:20:16 +02:00
|
|
|
type = vdt_input;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2015-07-24 20:10:13 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
else if (strcasecmp(argv[1], "out") == 0) { /* Output devices */
|
2015-08-16 09:20:16 +02:00
|
|
|
type = vdt_output;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2015-07-24 20:10:13 +02:00
|
|
|
|
|
|
|
else {
|
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid type: %s", argv[1]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
print_video_devices(self, type);
|
|
|
|
|
|
|
|
return;
|
|
|
|
on_error:
|
2018-07-18 17:33:16 +02:00
|
|
|
print_err(self, error_str);
|
2015-07-30 08:49:27 +02:00
|
|
|
}
|
|
|
|
|
2015-08-06 06:26:45 +02:00
|
|
|
/* This changes primary video device only */
|
2015-07-30 08:49:27 +02:00
|
|
|
void cmd_change_video_device(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(window);
|
|
|
|
UNUSED_VAR(m);
|
|
|
|
|
2015-07-30 08:49:27 +02:00
|
|
|
const char *error_str;
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
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!";
|
|
|
|
}
|
2015-07-30 08:49:27 +02:00
|
|
|
|
|
|
|
goto on_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
VideoDeviceType type;
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (strcmp(argv[1], "in") == 0) { /* Input devices */
|
2015-08-16 09:20:16 +02:00
|
|
|
type = vdt_input;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2015-07-30 08:49:27 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
else if (strcmp(argv[1], "out") == 0) { /* Output devices */
|
2015-08-16 09:20:16 +02:00
|
|
|
type = vdt_output;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2015-07-30 08:49:27 +02:00
|
|
|
|
|
|
|
else {
|
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid type: %s", argv[1]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
char *end;
|
|
|
|
long int selection = strtol(argv[2], &end, 10);
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (*end) {
|
2015-07-30 08:49:27 +02:00
|
|
|
error_str = "Invalid input";
|
|
|
|
goto on_error;
|
|
|
|
}
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (set_primary_video_device(type, selection) == vde_InvalidSelection) {
|
2015-08-10 13:14:38 +02:00
|
|
|
error_str = "Invalid selection!";
|
2015-07-30 08:49:27 +02:00
|
|
|
goto on_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
on_error:
|
2018-07-18 17:33:16 +02:00
|
|
|
print_err(self, error_str);
|
2015-07-30 08:49:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmd_ccur_video_device(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(window);
|
|
|
|
UNUSED_VAR(m);
|
|
|
|
|
2015-07-30 08:49:27 +02:00
|
|
|
const char *error_str;
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
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!";
|
|
|
|
}
|
2015-07-30 08:49:27 +02:00
|
|
|
|
|
|
|
goto on_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
VideoDeviceType type;
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (strcmp(argv[1], "in") == 0) { /* Input devices */
|
2015-08-16 09:20:16 +02:00
|
|
|
type = vdt_input;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2015-07-30 08:49:27 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
else if (strcmp(argv[1], "out") == 0) { /* Output devices */
|
2015-08-16 09:20:16 +02:00
|
|
|
type = vdt_output;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2015-07-30 08:49:27 +02:00
|
|
|
|
|
|
|
else {
|
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid type: %s", argv[1]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
char *end;
|
|
|
|
long int selection = strtol(argv[2], &end, 10);
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (*end) {
|
2015-07-30 08:49:27 +02:00
|
|
|
error_str = "Invalid input";
|
|
|
|
goto on_error;
|
|
|
|
}
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (video_selection_valid(type, selection) == vde_InvalidSelection) {
|
2016-09-25 03:07:04 +02:00
|
|
|
error_str = "Invalid selection!";
|
2015-07-30 08:49:27 +02:00
|
|
|
goto on_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If call is active, change device */
|
2018-07-18 17:33:16 +02:00
|
|
|
if (self->is_call) {
|
2016-09-25 03:07:04 +02:00
|
|
|
Call *this_call = &CallControl.calls[self->num];
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (this_call->ttas) {
|
2015-07-30 08:49:27 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (type == vdt_output) {
|
2016-09-25 03:07:04 +02:00
|
|
|
} else {
|
2015-07-30 08:49:27 +02:00
|
|
|
/* TODO: check for failure */
|
2015-08-16 09:20:16 +02:00
|
|
|
close_video_device(vdt_input, this_call->vin_idx);
|
|
|
|
open_video_device(vdt_input, selection, &this_call->vin_idx);
|
2015-08-11 13:11:09 +02:00
|
|
|
register_video_device_callback(self->num, this_call->vin_idx, read_video_device_callback, &self->num);
|
2015-07-30 08:49:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
2016-09-25 03:07:04 +02:00
|
|
|
on_error:
|
2018-07-18 17:33:16 +02:00
|
|
|
print_err(self, error_str);
|
2015-10-20 23:59:14 +02:00
|
|
|
}
|
2015-11-12 11:01:28 +01:00
|
|
|
|
|
|
|
void stop_video_stream(ToxWindow *self)
|
|
|
|
{
|
|
|
|
Call *this_call = &CallControl.calls[self->num];
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (this_call && this_call->vin_idx != -1) {
|
2015-11-12 11:01:28 +01:00
|
|
|
stop_video_transmission(this_call, self->num);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2015-11-12 11:01:28 +01:00
|
|
|
}
|
2018-07-06 17:45:35 +02:00
|
|
|
|
2018-10-08 19:39:04 +02:00
|
|
|
#endif /* VIDEO */
|