2014-06-22 02:18:23 +02:00
|
|
|
/* audio_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/>.
|
|
|
|
*
|
2014-02-23 00:00:34 +01:00
|
|
|
*/
|
|
|
|
|
2014-04-08 12:11:10 +02:00
|
|
|
#include "audio_call.h"
|
2015-05-25 23:59:06 +02:00
|
|
|
#include "audio_device.h"
|
2014-03-07 03:14:04 +01:00
|
|
|
#include "chat_commands.h"
|
2020-04-18 02:00:00 +02:00
|
|
|
#include "chat.h"
|
|
|
|
#include "friendlist.h"
|
2014-03-08 01:12:51 +01:00
|
|
|
#include "global_commands.h"
|
2014-03-25 09:39:44 +01:00
|
|
|
#include "line_info.h"
|
2020-03-15 19:57:00 +01:00
|
|
|
#include "misc_tools.h"
|
2020-04-18 02:00:00 +02:00
|
|
|
#include "notify.h"
|
2020-11-18 22:29:01 +01:00
|
|
|
#include "settings.h"
|
2020-04-18 02:00:00 +02:00
|
|
|
#include "toxic.h"
|
|
|
|
#include "windows.h"
|
2014-03-12 00:25:13 +01:00
|
|
|
|
2018-07-06 17:45:35 +02:00
|
|
|
#ifdef AUDIO
|
|
|
|
|
2015-08-10 13:14:38 +02:00
|
|
|
#ifdef VIDEO
|
|
|
|
#include "video_call.h"
|
|
|
|
#endif /* VIDEO */
|
2015-08-06 06:26:45 +02:00
|
|
|
|
2020-04-14 02:00:00 +02:00
|
|
|
#include <assert.h>
|
2014-03-07 03:14:04 +01:00
|
|
|
#include <curses.h>
|
|
|
|
#include <pthread.h>
|
2020-04-14 02:00:00 +02:00
|
|
|
#include <stdbool.h>
|
2014-03-07 03:14:04 +01:00
|
|
|
#include <stdlib.h>
|
2020-04-14 02:00:00 +02:00
|
|
|
#include <string.h>
|
|
|
|
#include <strings.h>
|
|
|
|
#include <unistd.h>
|
2014-03-07 03:14:04 +01:00
|
|
|
|
2014-06-12 01:40:43 +02:00
|
|
|
#ifdef __APPLE__
|
|
|
|
#include <OpenAL/al.h>
|
|
|
|
#include <OpenAL/alc.h>
|
|
|
|
#else
|
|
|
|
#include <AL/al.h>
|
|
|
|
#include <AL/alc.h>
|
2014-07-31 13:14:33 +02:00
|
|
|
/* compatibility with older versions of OpenAL */
|
|
|
|
#ifndef ALC_ALL_DEVICES_SPECIFIER
|
|
|
|
#include <AL/alext.h>
|
2018-10-08 19:39:04 +02:00
|
|
|
#endif /* ALC_ALL_DEVICES_SPECIFIER */
|
|
|
|
#endif /* __APPLE__ */
|
2014-06-12 01:40:43 +02:00
|
|
|
|
2015-11-04 02:36:41 +01:00
|
|
|
extern FriendsList Friends;
|
2018-10-10 00:59:25 +02:00
|
|
|
extern ToxWindow *windows[MAX_WINDOWS_NUM];
|
|
|
|
|
2018-01-20 19:30:35 +01:00
|
|
|
struct CallControl CallControl;
|
2015-11-04 02:36:41 +01:00
|
|
|
|
2020-11-18 22:29:01 +01:00
|
|
|
extern struct user_settings *user_settings;
|
2020-05-07 02:00:00 +02:00
|
|
|
extern struct Winthread Winthread;
|
|
|
|
|
2018-07-18 17:41:17 +02:00
|
|
|
void on_call(ToxAV *av, uint32_t friend_number, bool audio_enabled, bool video_enabled,
|
2018-07-18 17:33:16 +02:00
|
|
|
void *user_data);
|
2018-07-18 17:41:17 +02:00
|
|
|
void on_call_state(ToxAV *av, uint32_t friend_number, uint32_t state, void *user_data);
|
|
|
|
void on_audio_receive_frame(ToxAV *av, uint32_t friend_number, int16_t const *pcm, size_t sample_count,
|
2018-07-18 17:33:16 +02:00
|
|
|
uint8_t channels, uint32_t sampling_rate, void *user_data);
|
|
|
|
|
|
|
|
void callback_recv_invite(Tox *m, uint32_t friend_number);
|
|
|
|
void callback_recv_ringing(uint32_t friend_number);
|
|
|
|
void callback_recv_starting(uint32_t friend_number);
|
|
|
|
void callback_recv_ending(uint32_t friend_number);
|
|
|
|
void callback_call_started(uint32_t friend_number);
|
|
|
|
void callback_call_canceled(uint32_t friend_number);
|
|
|
|
void callback_call_rejected(uint32_t friend_number);
|
|
|
|
void callback_call_ended(uint32_t friend_number);
|
|
|
|
|
|
|
|
void write_device_callback(uint32_t friend_number, const int16_t *PCM, uint16_t sample_count, uint8_t channels,
|
|
|
|
uint32_t sample_rate);
|
|
|
|
|
2020-04-14 02:00:00 +02:00
|
|
|
void audio_bit_rate_callback(ToxAV *av, uint32_t friend_number, uint32_t audio_bit_rate, void *user_data);
|
2020-10-27 20:20:21 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
static void print_err(ToxWindow *self, const char *error_str)
|
2014-03-25 09:39:44 +01:00
|
|
|
{
|
2020-11-30 23:55:57 +01:00
|
|
|
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "%s", error_str);
|
2014-03-25 09:39:44 +01:00
|
|
|
}
|
|
|
|
|
2015-06-12 17:50:26 +02:00
|
|
|
ToxAV *init_audio(ToxWindow *self, Tox *tox)
|
2015-03-28 07:56:54 +01:00
|
|
|
{
|
2018-10-10 05:06:57 +02:00
|
|
|
Toxav_Err_New error;
|
2015-08-11 13:11:09 +02:00
|
|
|
CallControl.audio_errors = ae_None;
|
2015-08-10 13:14:38 +02:00
|
|
|
CallControl.prompt = self;
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2015-08-10 13:14:38 +02:00
|
|
|
CallControl.av = toxav_new(tox, &error);
|
2015-07-30 08:49:27 +02:00
|
|
|
|
2015-08-10 13:14:38 +02:00
|
|
|
CallControl.audio_enabled = true;
|
2020-04-14 02:00:00 +02:00
|
|
|
CallControl.default_audio_bit_rate = 64;
|
2015-08-10 13:14:38 +02:00
|
|
|
CallControl.audio_sample_rate = 48000;
|
2016-04-05 06:49:46 +02:00
|
|
|
CallControl.audio_frame_duration = 20;
|
2020-11-18 22:29:01 +01:00
|
|
|
CallControl.audio_channels = user_settings->chat_audio_channels;
|
2015-07-30 08:49:27 +02:00
|
|
|
|
2015-08-10 13:14:38 +02:00
|
|
|
CallControl.video_enabled = false;
|
2020-04-14 02:00:00 +02:00
|
|
|
CallControl.default_video_bit_rate = 0;
|
2015-08-10 13:14:38 +02:00
|
|
|
CallControl.video_frame_duration = 0;
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (!CallControl.av) {
|
2015-08-11 13:11:09 +02:00
|
|
|
CallControl.audio_errors |= ae_StartingCoreAudio;
|
2020-11-30 23:55:57 +01:00
|
|
|
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to init ToxAV");
|
2015-08-10 13:14:38 +02:00
|
|
|
|
2014-06-21 01:58:00 +02:00
|
|
|
return NULL;
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2020-04-04 02:00:00 +02:00
|
|
|
if (init_devices() == de_InternalError) {
|
2020-11-30 23:55:57 +01:00
|
|
|
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to init devices");
|
2015-08-10 13:14:38 +02:00
|
|
|
toxav_kill(CallControl.av);
|
|
|
|
|
|
|
|
return CallControl.av = NULL;
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2018-07-18 17:41:17 +02:00
|
|
|
toxav_callback_call(CallControl.av, on_call, tox);
|
|
|
|
toxav_callback_call_state(CallControl.av, on_call_state, NULL);
|
|
|
|
toxav_callback_audio_receive_frame(CallControl.av, on_audio_receive_frame, NULL);
|
2020-04-14 02:00:00 +02:00
|
|
|
toxav_callback_audio_bit_rate(CallControl.av, audio_bit_rate_callback, NULL);
|
2015-06-12 17:50:26 +02:00
|
|
|
|
2015-08-10 13:14:38 +02:00
|
|
|
return CallControl.av;
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
|
|
|
|
2016-09-25 03:07:04 +02:00
|
|
|
void read_device_callback(const int16_t *captured, uint32_t size, void *data)
|
2014-03-07 03:14:04 +01:00
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(size);
|
|
|
|
|
2018-10-10 05:06:57 +02:00
|
|
|
Toxav_Err_Send_Frame error;
|
2015-11-08 09:57:01 +01:00
|
|
|
uint32_t friend_number = *((uint32_t *)data); /* TODO: Or pass an array of call_idx's */
|
|
|
|
int64_t sample_count = ((int64_t) CallControl.audio_sample_rate) * \
|
|
|
|
((int64_t) CallControl.audio_frame_duration) / 1000;
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2020-04-04 02:00:00 +02:00
|
|
|
if (sample_count <= 0) {
|
|
|
|
return;
|
2016-09-25 03:07:04 +02:00
|
|
|
}
|
2020-04-04 02:00:00 +02:00
|
|
|
|
|
|
|
toxav_audio_send_frame(CallControl.av, friend_number,
|
|
|
|
captured, sample_count,
|
|
|
|
CallControl.audio_channels,
|
|
|
|
CallControl.audio_sample_rate, &error);
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
|
|
|
|
2016-09-25 03:07:04 +02:00
|
|
|
void write_device_callback(uint32_t friend_number, const int16_t *PCM, uint16_t sample_count, uint8_t channels,
|
2016-04-05 06:49:46 +02:00
|
|
|
uint32_t sample_rate)
|
2014-06-21 01:58:00 +02:00
|
|
|
{
|
2020-04-14 02:00:00 +02:00
|
|
|
if (CallControl.calls[friend_number].status == cs_Active) {
|
2016-04-05 06:49:46 +02:00
|
|
|
write_out(CallControl.calls[friend_number].out_idx, PCM, sample_count, channels, sample_rate);
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
|
|
|
|
2020-04-14 02:00:00 +02:00
|
|
|
bool init_call(Call *call)
|
2014-03-07 03:14:04 +01:00
|
|
|
{
|
2020-04-14 02:00:00 +02:00
|
|
|
if (call->status != cs_None) {
|
|
|
|
return false;
|
2014-05-16 20:00:01 +02:00
|
|
|
}
|
2014-11-15 02:13:08 +01:00
|
|
|
|
2020-11-14 01:00:00 +01:00
|
|
|
*call = (struct Call) {
|
|
|
|
0
|
|
|
|
};
|
2020-04-14 02:00:00 +02:00
|
|
|
|
|
|
|
call->status = cs_Pending;
|
|
|
|
|
|
|
|
call->in_idx = -1;
|
|
|
|
call->out_idx = -1;
|
|
|
|
call->audio_bit_rate = CallControl.default_audio_bit_rate;
|
|
|
|
#ifdef VIDEO
|
|
|
|
call->vin_idx = -1;
|
|
|
|
call->vout_idx = -1;
|
|
|
|
call->video_width = CallControl.default_video_width;
|
|
|
|
call->video_height = CallControl.default_video_height;
|
|
|
|
call->video_bit_rate = CallControl.default_video_bit_rate;
|
|
|
|
#endif /* VIDEO */
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool cancel_call(Call *call)
|
|
|
|
{
|
|
|
|
if (call->status != cs_Pending) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
call->status = cs_None;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int start_transmission(ToxWindow *self, Call *call)
|
|
|
|
{
|
|
|
|
if (!self || !CallControl.av) {
|
2020-11-30 23:55:57 +01:00
|
|
|
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to prepare audio transmission");
|
2014-09-24 04:51:56 +02:00
|
|
|
return -1;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-11-15 02:13:08 +01:00
|
|
|
|
2020-05-07 02:00:00 +02:00
|
|
|
DeviceError error = open_input_device(&call->in_idx, read_device_callback, &self->num, false,
|
2020-04-04 02:00:00 +02:00
|
|
|
CallControl.audio_sample_rate, CallControl.audio_frame_duration, CallControl.audio_channels);
|
2015-06-12 17:50:26 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (error != de_None) {
|
|
|
|
if (error == de_FailedStart) {
|
2020-11-30 23:55:57 +01:00
|
|
|
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to start audio input device");
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2015-06-12 17:50:26 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (error == de_InternalError) {
|
2020-11-30 23:55:57 +01:00
|
|
|
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Internal error with opening audio input device");
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2015-08-10 13:14:38 +02:00
|
|
|
}
|
2014-11-15 02:13:08 +01:00
|
|
|
|
2020-04-04 02:00:00 +02:00
|
|
|
if (open_output_device(&call->out_idx,
|
|
|
|
CallControl.audio_sample_rate, CallControl.audio_frame_duration, CallControl.audio_channels) != de_None) {
|
2020-11-30 23:55:57 +01:00
|
|
|
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to open audio output device!");
|
2014-07-10 01:24:14 +02:00
|
|
|
}
|
2014-11-15 02:13:08 +01:00
|
|
|
|
2014-07-10 01:24:14 +02:00
|
|
|
return 0;
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
|
|
|
|
2020-04-14 02:00:00 +02:00
|
|
|
static void start_call(ToxWindow *self, Call *call)
|
2015-03-28 07:56:54 +01:00
|
|
|
{
|
2020-04-14 02:00:00 +02:00
|
|
|
if (call->status != cs_Pending) {
|
|
|
|
return;
|
|
|
|
}
|
2015-08-10 13:14:38 +02:00
|
|
|
|
2020-04-14 02:00:00 +02:00
|
|
|
if (start_transmission(self, call) != 0) {
|
|
|
|
return;
|
|
|
|
}
|
2015-07-03 21:39:27 +02:00
|
|
|
|
2020-04-14 02:00:00 +02:00
|
|
|
call->status = cs_Active;
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2020-04-14 02:00:00 +02:00
|
|
|
#ifdef VIDEO
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2020-04-14 02:00:00 +02:00
|
|
|
if (call->state & TOXAV_FRIEND_CALL_STATE_SENDING_V) {
|
|
|
|
callback_recv_video_starting(self->num);
|
|
|
|
}
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2020-04-14 02:00:00 +02:00
|
|
|
if (call->video_bit_rate) {
|
|
|
|
start_video_transmission(self, CallControl.av, call);
|
|
|
|
}
|
2015-06-12 17:50:26 +02:00
|
|
|
|
2020-04-14 02:00:00 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static int stop_transmission(Call *call, uint32_t friend_number)
|
|
|
|
{
|
|
|
|
if (call->status != cs_Active) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
call->status = cs_None;
|
|
|
|
|
|
|
|
if (call->in_idx != -1) {
|
|
|
|
close_device(input, call->in_idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (call->out_idx != -1) {
|
|
|
|
close_device(output, call->out_idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
Toxav_Err_Call_Control error = TOXAV_ERR_CALL_CONTROL_OK;
|
|
|
|
|
|
|
|
if (call->state > TOXAV_FRIEND_CALL_STATE_FINISHED) {
|
|
|
|
toxav_call_control(CallControl.av, friend_number, TOXAV_CALL_CONTROL_CANCEL, &error);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (error != TOXAV_ERR_CALL_CONTROL_OK) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void terminate_audio(void)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < CallControl.max_calls; ++i) {
|
|
|
|
stop_transmission(&CallControl.calls[i], i);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CallControl.av) {
|
|
|
|
toxav_kill(CallControl.av);
|
2014-06-21 01:58:00 +02:00
|
|
|
}
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2020-04-14 02:00:00 +02:00
|
|
|
terminate_devices();
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
2020-04-14 02:00:00 +02:00
|
|
|
|
2014-03-07 03:14:04 +01:00
|
|
|
/*
|
|
|
|
* End of transmission
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Callbacks
|
|
|
|
*/
|
2018-07-18 17:41:17 +02:00
|
|
|
void on_call(ToxAV *av, uint32_t friend_number, bool audio_enabled, bool video_enabled, void *user_data)
|
2015-06-12 17:50:26 +02:00
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(av);
|
|
|
|
|
2015-11-04 02:36:41 +01:00
|
|
|
Tox *m = (Tox *) user_data;
|
2020-04-14 02:00:00 +02:00
|
|
|
|
|
|
|
Call *call = &CallControl.calls[friend_number];
|
|
|
|
init_call(call);
|
|
|
|
|
|
|
|
call->state = TOXAV_FRIEND_CALL_STATE_ACCEPTING_A | TOXAV_FRIEND_CALL_STATE_ACCEPTING_V;
|
|
|
|
|
|
|
|
if (audio_enabled) {
|
|
|
|
call->state |= TOXAV_FRIEND_CALL_STATE_SENDING_A;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (video_enabled) {
|
|
|
|
call->state |= TOXAV_FRIEND_CALL_STATE_SENDING_V;
|
|
|
|
}
|
|
|
|
|
2015-11-12 11:01:28 +01:00
|
|
|
callback_recv_invite(m, friend_number);
|
2015-06-12 17:50:26 +02:00
|
|
|
}
|
|
|
|
|
2018-07-18 17:41:17 +02:00
|
|
|
void on_call_state(ToxAV *av, uint32_t friend_number, uint32_t state, void *user_data)
|
2014-04-19 23:58:13 +02:00
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(av);
|
|
|
|
UNUSED_VAR(user_data);
|
|
|
|
|
2020-04-14 02:00:00 +02:00
|
|
|
Call *call = &CallControl.calls[friend_number];
|
2015-06-12 17:50:26 +02:00
|
|
|
|
2020-04-14 02:00:00 +02:00
|
|
|
if (call->status == cs_None) {
|
|
|
|
return;
|
|
|
|
}
|
2015-08-11 13:11:09 +02:00
|
|
|
|
2020-04-14 02:00:00 +02:00
|
|
|
call->state = state;
|
2015-08-10 13:14:38 +02:00
|
|
|
|
2020-04-14 02:00:00 +02:00
|
|
|
switch (state) {
|
|
|
|
case TOXAV_FRIEND_CALL_STATE_ERROR:
|
|
|
|
case TOXAV_FRIEND_CALL_STATE_FINISHED:
|
|
|
|
if (state == TOXAV_FRIEND_CALL_STATE_ERROR) {
|
2020-11-30 23:55:57 +01:00
|
|
|
line_info_add(CallControl.prompt, false, NULL, NULL, SYS_MSG, 0, 0, "ToxAV callstate error!");
|
2020-04-14 02:00:00 +02:00
|
|
|
}
|
2016-09-25 03:07:04 +02:00
|
|
|
|
2020-04-14 02:00:00 +02:00
|
|
|
if (call->status == cs_Pending) {
|
|
|
|
cancel_call(call);
|
2015-08-10 13:14:38 +02:00
|
|
|
callback_call_rejected(friend_number);
|
2018-07-18 17:33:16 +02:00
|
|
|
} else {
|
2015-08-10 13:14:38 +02:00
|
|
|
|
2015-08-11 13:11:09 +02:00
|
|
|
#ifdef VIDEO
|
2020-04-14 02:00:00 +02:00
|
|
|
callback_recv_video_end(friend_number);
|
|
|
|
callback_video_end(friend_number);
|
2015-08-11 13:11:09 +02:00
|
|
|
#endif /* VIDEO */
|
2015-08-10 13:14:38 +02:00
|
|
|
|
2020-04-14 02:00:00 +02:00
|
|
|
stop_transmission(call, friend_number);
|
|
|
|
callback_call_ended(friend_number);
|
|
|
|
}
|
2015-08-10 13:14:38 +02:00
|
|
|
|
2016-09-25 03:07:04 +02:00
|
|
|
break;
|
|
|
|
|
2015-08-11 13:11:09 +02:00
|
|
|
default:
|
2020-04-14 02:00:00 +02:00
|
|
|
if (call->status == cs_Pending) {
|
2015-08-11 13:11:09 +02:00
|
|
|
/* Start answered call */
|
2015-08-12 11:33:59 +02:00
|
|
|
callback_call_started(friend_number);
|
2020-04-14 02:00:00 +02:00
|
|
|
}
|
2015-08-10 13:14:38 +02:00
|
|
|
|
|
|
|
#ifdef VIDEO
|
2016-09-25 03:07:04 +02:00
|
|
|
|
2020-04-14 02:00:00 +02:00
|
|
|
/* Handle receiving client video call states */
|
|
|
|
if (state & TOXAV_FRIEND_CALL_STATE_SENDING_V) {
|
|
|
|
callback_recv_video_starting(friend_number);
|
|
|
|
} else {
|
|
|
|
callback_recv_video_end(friend_number);
|
|
|
|
}
|
2015-08-10 13:14:38 +02:00
|
|
|
|
|
|
|
#endif /* VIDEO */
|
2015-08-11 13:11:09 +02:00
|
|
|
|
2016-09-25 03:07:04 +02:00
|
|
|
break;
|
2015-08-11 13:11:09 +02:00
|
|
|
}
|
2015-07-03 21:39:27 +02:00
|
|
|
}
|
|
|
|
|
2018-07-18 17:41:17 +02:00
|
|
|
void on_audio_receive_frame(ToxAV *av, uint32_t friend_number,
|
2016-09-25 03:07:04 +02:00
|
|
|
int16_t const *pcm, size_t sample_count,
|
|
|
|
uint8_t channels, uint32_t sampling_rate, void *user_data)
|
2014-03-07 03:14:04 +01:00
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(av);
|
|
|
|
UNUSED_VAR(user_data);
|
|
|
|
|
2016-04-05 06:49:46 +02:00
|
|
|
write_device_callback(friend_number, pcm, sample_count, channels, sampling_rate);
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
2015-06-12 17:50:26 +02:00
|
|
|
|
2020-04-14 02:00:00 +02:00
|
|
|
void audio_bit_rate_callback(ToxAV *av, uint32_t friend_number, uint32_t audio_bit_rate, void *user_data)
|
2014-03-07 03:14:04 +01:00
|
|
|
{
|
2020-04-14 02:00:00 +02:00
|
|
|
UNUSED_VAR(user_data);
|
|
|
|
|
|
|
|
Call *call = &CallControl.calls[friend_number];
|
|
|
|
call->audio_bit_rate = audio_bit_rate;
|
|
|
|
toxav_audio_set_bit_rate(av, friend_number, audio_bit_rate, NULL);
|
2015-06-12 17:50:26 +02:00
|
|
|
}
|
|
|
|
|
2015-11-04 02:36:41 +01:00
|
|
|
void callback_recv_invite(Tox *m, uint32_t friend_number)
|
|
|
|
{
|
2018-07-18 17:33:16 +02:00
|
|
|
if (friend_number >= Friends.max_idx) {
|
2015-11-04 02:36:41 +01:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2015-07-03 21:39:27 +02:00
|
|
|
|
2015-11-04 02:36:41 +01:00
|
|
|
if (Friends.list[friend_number].chatwin == -1) {
|
2018-07-18 17:33:16 +02:00
|
|
|
if (get_num_active_windows() >= MAX_WINDOWS_NUM) {
|
2015-11-04 02:36:41 +01:00
|
|
|
return;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2015-06-12 17:50:26 +02:00
|
|
|
|
2015-11-04 02:36:41 +01:00
|
|
|
Friends.list[friend_number].chatwin = add_window(m, new_chat(m, Friends.list[friend_number].num));
|
|
|
|
}
|
|
|
|
|
2020-04-14 02:00:00 +02:00
|
|
|
const Call *call = &CallControl.calls[friend_number];
|
|
|
|
|
2018-10-10 00:59:25 +02:00
|
|
|
for (uint8_t i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
|
|
|
if (windows[i] != NULL && windows[i]->onInvite != NULL && windows[i]->num == friend_number) {
|
2020-04-14 02:00:00 +02:00
|
|
|
windows[i]->onInvite(windows[i], CallControl.av, friend_number, call->state);
|
2015-11-04 02:36:41 +01:00
|
|
|
}
|
|
|
|
}
|
2015-06-12 17:50:26 +02:00
|
|
|
}
|
2015-08-11 13:11:09 +02:00
|
|
|
void callback_recv_ringing(uint32_t friend_number)
|
2015-06-12 17:50:26 +02:00
|
|
|
{
|
2020-04-14 02:00:00 +02:00
|
|
|
const Call *call = &CallControl.calls[friend_number];
|
|
|
|
|
2018-10-10 00:59:25 +02:00
|
|
|
for (uint8_t i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
|
|
|
if (windows[i] != NULL && windows[i]->onRinging != NULL && windows[i]->num == friend_number) {
|
2020-04-14 02:00:00 +02:00
|
|
|
windows[i]->onRinging(windows[i], CallControl.av, friend_number, call->state);
|
2015-11-04 02:36:41 +01:00
|
|
|
}
|
|
|
|
}
|
2015-06-12 17:50:26 +02:00
|
|
|
}
|
2015-08-11 13:11:09 +02:00
|
|
|
void callback_recv_starting(uint32_t friend_number)
|
2015-06-12 17:50:26 +02:00
|
|
|
{
|
2020-04-14 02:00:00 +02:00
|
|
|
Call *call = &CallControl.calls[friend_number];
|
|
|
|
|
2018-10-10 00:59:25 +02:00
|
|
|
for (uint8_t i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
|
|
|
if (windows[i] != NULL && windows[i]->onStarting != NULL && windows[i]->num == friend_number) {
|
2020-04-14 02:00:00 +02:00
|
|
|
windows[i]->onStarting(windows[i], CallControl.av, friend_number, call->state);
|
2015-08-10 13:14:38 +02:00
|
|
|
|
2020-04-14 02:00:00 +02:00
|
|
|
start_call(windows[i], call);
|
2014-05-16 20:00:01 +02:00
|
|
|
}
|
2015-08-10 13:14:38 +02:00
|
|
|
}
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
2015-08-11 13:11:09 +02:00
|
|
|
void callback_recv_ending(uint32_t friend_number)
|
2014-04-19 23:58:13 +02:00
|
|
|
{
|
2020-04-14 02:00:00 +02:00
|
|
|
const Call *call = &CallControl.calls[friend_number];
|
|
|
|
|
2018-10-10 00:59:25 +02:00
|
|
|
for (uint8_t i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
|
|
|
if (windows[i] != NULL && windows[i]->onEnding != NULL && windows[i]->num == friend_number) {
|
2020-04-14 02:00:00 +02:00
|
|
|
windows[i]->onEnding(windows[i], CallControl.av, friend_number, call->state);
|
2015-11-04 02:36:41 +01:00
|
|
|
}
|
|
|
|
}
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
2015-08-11 13:11:09 +02:00
|
|
|
void callback_call_started(uint32_t friend_number)
|
2015-03-28 07:56:54 +01:00
|
|
|
{
|
2020-04-14 02:00:00 +02:00
|
|
|
Call *call = &CallControl.calls[friend_number];
|
|
|
|
|
2018-10-10 00:59:25 +02:00
|
|
|
for (uint8_t i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
|
|
|
if (windows[i] != NULL && windows[i]->onStart != NULL && windows[i]->num == friend_number) {
|
2020-04-14 02:00:00 +02:00
|
|
|
windows[i]->onStart(windows[i], CallControl.av, friend_number, call->state);
|
2015-07-03 21:39:27 +02:00
|
|
|
|
2020-04-14 02:00:00 +02:00
|
|
|
start_call(windows[i], call);
|
2014-05-16 20:00:01 +02:00
|
|
|
}
|
2018-10-10 00:59:25 +02:00
|
|
|
}
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
2015-08-11 13:11:09 +02:00
|
|
|
void callback_call_canceled(uint32_t friend_number)
|
2014-03-07 03:14:04 +01:00
|
|
|
{
|
2020-04-14 02:00:00 +02:00
|
|
|
const Call *call = &CallControl.calls[friend_number];
|
|
|
|
|
2018-10-10 00:59:25 +02:00
|
|
|
for (uint8_t i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
|
|
|
if (windows[i] != NULL && windows[i]->onCancel != NULL && windows[i]->num == friend_number) {
|
2020-04-14 02:00:00 +02:00
|
|
|
windows[i]->onCancel(windows[i], CallControl.av, friend_number, call->state);
|
2015-11-04 02:36:41 +01:00
|
|
|
}
|
|
|
|
}
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
2015-08-11 13:11:09 +02:00
|
|
|
void callback_call_rejected(uint32_t friend_number)
|
2014-03-07 03:14:04 +01:00
|
|
|
{
|
2020-04-14 02:00:00 +02:00
|
|
|
const Call *call = &CallControl.calls[friend_number];
|
|
|
|
|
2018-10-10 00:59:25 +02:00
|
|
|
for (uint8_t i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
|
|
|
if (windows[i] != NULL && windows[i]->onReject != NULL && windows[i]->num == friend_number) {
|
2020-04-14 02:00:00 +02:00
|
|
|
windows[i]->onReject(windows[i], CallControl.av, friend_number, call->state);
|
2015-11-04 02:36:41 +01:00
|
|
|
}
|
|
|
|
}
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
2015-08-11 13:11:09 +02:00
|
|
|
void callback_call_ended(uint32_t friend_number)
|
2014-04-19 23:58:13 +02:00
|
|
|
{
|
2020-04-14 02:00:00 +02:00
|
|
|
const Call *call = &CallControl.calls[friend_number];
|
|
|
|
|
2018-10-10 00:59:25 +02:00
|
|
|
for (uint8_t i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
|
|
|
if (windows[i] != NULL && windows[i]->onEnd != NULL && windows[i]->num == friend_number) {
|
2020-04-14 02:00:00 +02:00
|
|
|
windows[i]->onEnd(windows[i], CallControl.av, friend_number, call->state);
|
2015-11-04 02:36:41 +01:00
|
|
|
}
|
|
|
|
}
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
2014-11-26 06:48:58 +01:00
|
|
|
|
2014-04-19 23:58:13 +02:00
|
|
|
/*
|
|
|
|
* End of Callbacks
|
2014-03-07 03:14:04 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Commands from chat_commands.h
|
|
|
|
*/
|
|
|
|
void cmd_call(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);
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (argc != 0) {
|
2020-04-14 02:00:00 +02:00
|
|
|
print_err(self, "Unknown arguments.");
|
|
|
|
return;
|
2014-04-19 23:58:13 +02:00
|
|
|
}
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (!CallControl.av) {
|
2020-04-14 02:00:00 +02:00
|
|
|
print_err(self, "ToxAV not supported!");
|
|
|
|
return;
|
2014-04-19 23:58:13 +02:00
|
|
|
}
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (!self->stb->connection) {
|
2020-04-14 02:00:00 +02:00
|
|
|
print_err(self, "Friend is offline.");
|
|
|
|
return;
|
2015-08-10 13:14:38 +02:00
|
|
|
}
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2020-04-14 02:00:00 +02:00
|
|
|
Call *call = &CallControl.calls[self->num];
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2020-04-14 02:00:00 +02:00
|
|
|
if (call->status != cs_None) {
|
|
|
|
print_err(self, "Already calling.");
|
|
|
|
return;
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
2014-03-25 09:39:44 +01:00
|
|
|
|
2020-04-14 02:00:00 +02:00
|
|
|
init_call(call);
|
2014-03-25 09:39:44 +01:00
|
|
|
|
2020-04-14 02:00:00 +02:00
|
|
|
place_call(self);
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmd_answer(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);
|
|
|
|
|
2018-10-10 05:06:57 +02:00
|
|
|
Toxav_Err_Answer error;
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (argc != 0) {
|
2020-04-14 02:00:00 +02:00
|
|
|
print_err(self, "Unknown arguments.");
|
|
|
|
return;
|
2014-04-19 23:58:13 +02:00
|
|
|
}
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (!CallControl.av) {
|
2020-04-14 02:00:00 +02:00
|
|
|
print_err(self, "Audio not supported!");
|
|
|
|
return;
|
2014-04-19 23:58:13 +02:00
|
|
|
}
|
|
|
|
|
2020-04-14 02:00:00 +02:00
|
|
|
Call *call = &CallControl.calls[self->num];
|
|
|
|
|
|
|
|
if (call->status != cs_Pending) {
|
|
|
|
print_err(self, "No incoming call!");
|
|
|
|
return;
|
2015-08-10 13:14:38 +02:00
|
|
|
}
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2020-04-14 02:00:00 +02:00
|
|
|
toxav_answer(CallControl.av, self->num, call->audio_bit_rate, call->video_bit_rate, &error);
|
2016-09-25 03:07:04 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (error != TOXAV_ERR_ANSWER_OK) {
|
|
|
|
if (error == TOXAV_ERR_ANSWER_FRIEND_NOT_CALLING) {
|
2020-04-14 02:00:00 +02:00
|
|
|
print_err(self, "No incoming call!");
|
2018-07-18 17:33:16 +02:00
|
|
|
} else if (error == TOXAV_ERR_ANSWER_CODEC_INITIALIZATION) {
|
2020-04-14 02:00:00 +02:00
|
|
|
print_err(self, "Failed to initialize codecs!");
|
2018-07-18 17:33:16 +02:00
|
|
|
} else if (error == TOXAV_ERR_ANSWER_FRIEND_NOT_FOUND) {
|
2020-04-14 02:00:00 +02:00
|
|
|
print_err(self, "Friend not found!");
|
2018-07-18 17:33:16 +02:00
|
|
|
} else if (error == TOXAV_ERR_ANSWER_INVALID_BIT_RATE) {
|
2020-04-14 02:00:00 +02:00
|
|
|
print_err(self, "Invalid bit rate!");
|
2018-07-18 17:33:16 +02:00
|
|
|
} else {
|
2020-04-14 02:00:00 +02:00
|
|
|
print_err(self, "Internal error!");
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2020-04-14 02:00:00 +02:00
|
|
|
return;
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2014-03-07 03:14:04 +01:00
|
|
|
/* Callback will print status... */
|
2015-08-10 13:14:38 +02:00
|
|
|
callback_recv_starting(self->num);
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
|
|
|
|
2014-03-23 22:54:56 +01:00
|
|
|
void cmd_reject(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);
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (argc != 0) {
|
2020-04-14 02:00:00 +02:00
|
|
|
print_err(self, "Unknown arguments.");
|
|
|
|
return;
|
2014-04-19 23:58:13 +02:00
|
|
|
}
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (!CallControl.av) {
|
2020-04-14 02:00:00 +02:00
|
|
|
print_err(self, "Audio not supported!");
|
|
|
|
return;
|
2014-04-19 23:58:13 +02:00
|
|
|
}
|
|
|
|
|
2020-04-14 02:00:00 +02:00
|
|
|
Call *call = &CallControl.calls[self->num];
|
|
|
|
|
|
|
|
if (call->status != cs_Pending) {
|
|
|
|
print_err(self, "No incoming call!");
|
|
|
|
return;
|
2014-03-23 22:54:56 +01:00
|
|
|
}
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2015-08-10 13:14:38 +02:00
|
|
|
/* Manually send a cancel call control because call hasn't started */
|
2015-10-20 23:59:14 +02:00
|
|
|
toxav_call_control(CallControl.av, self->num, TOXAV_CALL_CONTROL_CANCEL, NULL);
|
2020-04-14 02:00:00 +02:00
|
|
|
cancel_call(call);
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2015-08-10 13:14:38 +02:00
|
|
|
/* Callback will print status... */
|
|
|
|
callback_call_rejected(self->num);
|
2014-03-23 22:54:56 +01:00
|
|
|
}
|
|
|
|
|
2014-03-07 03:14:04 +01:00
|
|
|
void cmd_hangup(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);
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (!CallControl.av) {
|
2020-04-14 02:00:00 +02:00
|
|
|
print_err(self, "Audio not supported!");
|
|
|
|
return;
|
2015-11-12 11:01:28 +01:00
|
|
|
}
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (argc != 0) {
|
2020-04-14 02:00:00 +02:00
|
|
|
print_err(self, "Unknown arguments.");
|
|
|
|
return;
|
2014-04-19 23:58:13 +02:00
|
|
|
}
|
|
|
|
|
2020-04-14 02:00:00 +02:00
|
|
|
Call *call = &CallControl.calls[self->num];
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2020-04-14 02:00:00 +02:00
|
|
|
if (call->status == cs_None) {
|
|
|
|
print_err(self, "Not in a call.");
|
|
|
|
return;
|
|
|
|
}
|
2015-10-20 23:59:14 +02:00
|
|
|
|
2015-11-20 05:49:58 +01:00
|
|
|
stop_current_call(self);
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
|
|
|
|
2014-03-08 01:12:51 +01:00
|
|
|
void cmd_list_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);
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (argc != 1) {
|
|
|
|
if (argc < 1) {
|
2020-04-14 02:00:00 +02:00
|
|
|
print_err(self, "Type must be specified!");
|
2018-07-18 17:33:16 +02:00
|
|
|
} else {
|
2020-04-14 02:00:00 +02:00
|
|
|
print_err(self, "Only one argument allowed!");
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2020-04-14 02:00:00 +02:00
|
|
|
return;
|
2014-03-08 01:12:51 +01:00
|
|
|
}
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2014-06-21 01:58:00 +02:00
|
|
|
DeviceType type;
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (strcasecmp(argv[1], "in") == 0) { /* Input devices */
|
2014-03-08 01:12:51 +01:00
|
|
|
type = input;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
else if (strcasecmp(argv[1], "out") == 0) { /* Output devices */
|
2014-03-08 01:12:51 +01:00
|
|
|
type = output;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2014-03-08 01:12:51 +01:00
|
|
|
else {
|
2020-11-30 23:55:57 +01:00
|
|
|
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Invalid type: %s", argv[1]);
|
2014-03-08 01:12:51 +01:00
|
|
|
return;
|
|
|
|
}
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2017-10-31 17:08:06 +01:00
|
|
|
// Refresh device list.
|
2020-04-04 02:00:00 +02:00
|
|
|
get_al_device_names();
|
2017-10-31 17:08:06 +01:00
|
|
|
|
2020-04-04 02:00:00 +02:00
|
|
|
print_al_devices(self, type);
|
2014-03-08 01:12:51 +01:00
|
|
|
}
|
2014-03-07 03:14:04 +01:00
|
|
|
|
2014-06-21 01:58:00 +02:00
|
|
|
/* This changes primary device only */
|
2014-03-08 01:12:51 +01:00
|
|
|
void cmd_change_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);
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (argc != 2) {
|
|
|
|
if (argc < 1) {
|
2020-04-14 02:00:00 +02:00
|
|
|
print_err(self, "Type must be specified!");
|
2018-07-18 17:33:16 +02:00
|
|
|
} else if (argc < 2) {
|
2020-04-14 02:00:00 +02:00
|
|
|
print_err(self, "Must have id!");
|
2018-07-18 17:33:16 +02:00
|
|
|
} else {
|
2020-04-14 02:00:00 +02:00
|
|
|
print_err(self, "Only two arguments allowed!");
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2020-04-14 02:00:00 +02:00
|
|
|
return;
|
2014-03-08 01:12:51 +01:00
|
|
|
}
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2014-06-21 01:58:00 +02:00
|
|
|
DeviceType type;
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (strcmp(argv[1], "in") == 0) { /* Input devices */
|
2014-03-08 01:12:51 +01:00
|
|
|
type = input;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
else if (strcmp(argv[1], "out") == 0) { /* Output devices */
|
2014-03-08 01:12:51 +01:00
|
|
|
type = output;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2014-03-08 01:12:51 +01:00
|
|
|
else {
|
2020-11-30 23:55:57 +01:00
|
|
|
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Invalid type: %s", argv[1]);
|
2014-03-08 01:12:51 +01:00
|
|
|
return;
|
|
|
|
}
|
2014-04-19 23:58:13 +02:00
|
|
|
|
|
|
|
|
2014-03-08 01:12:51 +01:00
|
|
|
char *end;
|
|
|
|
long int selection = strtol(argv[2], &end, 10);
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (*end) {
|
2020-04-14 02:00:00 +02:00
|
|
|
print_err(self, "Invalid input");
|
|
|
|
return;
|
2014-03-08 01:12:51 +01:00
|
|
|
}
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2020-04-04 02:00:00 +02:00
|
|
|
if (set_al_device(type, selection) == de_InvalidSelection) {
|
2020-04-14 02:00:00 +02:00
|
|
|
print_err(self, "Invalid selection!");
|
|
|
|
return;
|
2014-05-16 20:00:01 +02:00
|
|
|
}
|
2014-06-21 01:58:00 +02:00
|
|
|
}
|
|
|
|
|
2014-07-31 18:48:49 +02:00
|
|
|
void cmd_mute(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
2014-08-02 21:35:57 +02:00
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(window);
|
|
|
|
UNUSED_VAR(m);
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (argc != 1) {
|
2020-04-14 02:00:00 +02:00
|
|
|
print_err(self, "Specify type: \"/mute in\" or \"/mute out\".");
|
|
|
|
return;
|
2014-06-22 02:18:23 +02:00
|
|
|
}
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2014-06-22 02:18:23 +02:00
|
|
|
DeviceType type;
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (strcasecmp(argv[1], "in") == 0) { /* Input devices */
|
2014-06-22 02:18:23 +02:00
|
|
|
type = input;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
else if (strcasecmp(argv[1], "out") == 0) { /* Output devices */
|
2014-06-22 02:18:23 +02:00
|
|
|
type = output;
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2014-06-22 02:18:23 +02:00
|
|
|
else {
|
2020-11-30 23:55:57 +01:00
|
|
|
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Invalid type: %s", argv[1]);
|
2014-06-22 02:18:23 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-03-28 07:56:54 +01:00
|
|
|
|
|
|
|
|
2014-06-22 02:18:23 +02:00
|
|
|
/* If call is active, use this_call values */
|
2020-04-14 02:00:00 +02:00
|
|
|
Call *this_call = &CallControl.calls[self->num];
|
2016-09-25 03:07:04 +02:00
|
|
|
|
2020-04-14 02:00:00 +02:00
|
|
|
if (this_call->status == cs_Active) {
|
2018-07-18 17:33:16 +02:00
|
|
|
if (type == input) {
|
2014-06-24 00:54:23 +02:00
|
|
|
device_mute(type, this_call->in_idx);
|
2020-05-07 02:00:00 +02:00
|
|
|
self->chatwin->infobox.in_is_muted = device_is_muted(type, this_call->in_idx);
|
2014-06-24 00:54:23 +02:00
|
|
|
} else {
|
|
|
|
device_mute(type, this_call->out_idx);
|
2020-05-07 02:00:00 +02:00
|
|
|
self->chatwin->infobox.out_is_muted = device_is_muted(type, this_call->out_idx);
|
2014-06-24 00:54:23 +02:00
|
|
|
}
|
2014-06-22 02:18:23 +02:00
|
|
|
}
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2014-06-22 02:18:23 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-31 18:48:49 +02:00
|
|
|
void cmd_sense(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
2014-07-07 04:15:35 +02:00
|
|
|
{
|
2020-03-15 19:57:00 +01:00
|
|
|
UNUSED_VAR(window);
|
|
|
|
UNUSED_VAR(m);
|
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (argc != 1) {
|
|
|
|
if (argc < 1) {
|
2020-04-14 02:00:00 +02:00
|
|
|
print_err(self, "Must have value!");
|
2018-07-18 17:33:16 +02:00
|
|
|
} else {
|
2020-04-14 02:00:00 +02:00
|
|
|
print_err(self, "Only two arguments allowed!");
|
2018-07-18 17:33:16 +02:00
|
|
|
}
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2020-04-14 02:00:00 +02:00
|
|
|
return;
|
2014-06-22 02:18:23 +02:00
|
|
|
}
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2014-06-22 02:18:23 +02:00
|
|
|
char *end;
|
|
|
|
float value = strtof(argv[1], &end);
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2018-07-18 17:33:16 +02:00
|
|
|
if (*end) {
|
2020-04-14 02:00:00 +02:00
|
|
|
print_err(self, "Invalid input");
|
|
|
|
return;
|
2014-06-22 02:18:23 +02:00
|
|
|
}
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2020-04-14 02:00:00 +02:00
|
|
|
const Call *call = &CallControl.calls[self->num];
|
|
|
|
|
2014-06-22 02:18:23 +02:00
|
|
|
/* Call must be active */
|
2020-04-14 02:00:00 +02:00
|
|
|
if (call->status == cs_Active) {
|
|
|
|
device_set_VAD_threshold(call->in_idx, value);
|
2014-06-24 00:54:23 +02:00
|
|
|
self->chatwin->infobox.vad_lvl = value;
|
2015-03-28 07:56:54 +01:00
|
|
|
}
|
|
|
|
|
2014-06-22 02:18:23 +02:00
|
|
|
return;
|
2014-03-25 09:39:44 +01:00
|
|
|
}
|
2014-07-04 18:04:03 +02:00
|
|
|
|
2017-06-30 00:26:06 +02:00
|
|
|
void cmd_bitrate(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);
|
|
|
|
|
2020-04-14 02:00:00 +02:00
|
|
|
Call *call = &CallControl.calls[self->num];
|
2017-06-30 00:26:06 +02:00
|
|
|
|
2020-04-14 02:00:00 +02:00
|
|
|
if (call->status != cs_Active) {
|
|
|
|
print_err(self, "Must be in a call");
|
|
|
|
return;
|
2017-06-30 00:26:06 +02:00
|
|
|
}
|
|
|
|
|
2020-04-14 02:00:00 +02:00
|
|
|
if (argc == 0) {
|
2020-11-30 23:55:57 +01:00
|
|
|
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0,
|
2020-04-14 02:00:00 +02:00
|
|
|
"Current audio encoding bitrate: %u", call->audio_bit_rate);
|
|
|
|
return;
|
2017-06-30 00:26:06 +02:00
|
|
|
}
|
|
|
|
|
2020-04-14 02:00:00 +02:00
|
|
|
if (argc > 1) {
|
|
|
|
print_err(self, "Too many arguments.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *end;
|
|
|
|
const long int bit_rate = strtol(argv[1], &end, 10);
|
|
|
|
|
|
|
|
if (*end || bit_rate < 0 || bit_rate > UINT32_MAX) {
|
|
|
|
print_err(self, "Invalid input");
|
|
|
|
return;
|
|
|
|
}
|
2017-06-30 00:26:06 +02:00
|
|
|
|
2018-10-10 05:06:57 +02:00
|
|
|
Toxav_Err_Bit_Rate_Set error;
|
2020-04-14 02:00:00 +02:00
|
|
|
toxav_audio_set_bit_rate(CallControl.av, self->num, bit_rate, &error);
|
2017-06-30 00:26:06 +02:00
|
|
|
|
|
|
|
if (error != TOXAV_ERR_BIT_RATE_SET_OK) {
|
2020-04-14 02:00:00 +02:00
|
|
|
if (error == TOXAV_ERR_BIT_RATE_SET_SYNC) {
|
|
|
|
print_err(self, "Synchronization error occured");
|
|
|
|
} else if (error == TOXAV_ERR_BIT_RATE_SET_INVALID_BIT_RATE) {
|
|
|
|
print_err(self, "Invalid audio bit rate value (valid is 6-510)");
|
|
|
|
} else if (error == TOXAV_ERR_BIT_RATE_SET_FRIEND_NOT_FOUND) {
|
|
|
|
print_err(self, "Friend not found");
|
|
|
|
} else if (error == TOXAV_ERR_BIT_RATE_SET_FRIEND_NOT_IN_CALL) {
|
|
|
|
print_err(self, "Friend is not in the call");
|
|
|
|
} else {
|
|
|
|
print_err(self, "Unknown error");
|
|
|
|
}
|
2017-06-30 00:26:06 +02:00
|
|
|
|
2020-04-14 02:00:00 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-06-30 00:26:06 +02:00
|
|
|
|
2020-04-14 02:00:00 +02:00
|
|
|
call->audio_bit_rate = bit_rate;
|
2017-06-30 00:26:06 +02:00
|
|
|
|
2020-04-14 02:00:00 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-06-30 00:26:06 +02:00
|
|
|
|
2020-04-14 02:00:00 +02:00
|
|
|
void place_call(ToxWindow *self)
|
|
|
|
{
|
|
|
|
Call *call = &CallControl.calls[self->num];
|
2017-06-30 00:26:06 +02:00
|
|
|
|
2020-04-14 02:00:00 +02:00
|
|
|
if (call->status != cs_Pending) {
|
|
|
|
return;
|
2017-06-30 00:26:06 +02:00
|
|
|
}
|
|
|
|
|
2020-04-14 02:00:00 +02:00
|
|
|
Toxav_Err_Call error;
|
|
|
|
|
|
|
|
toxav_call(CallControl.av, self->num, call->audio_bit_rate, call->video_bit_rate, &error);
|
2017-06-30 00:26:06 +02:00
|
|
|
|
2020-04-14 02:00:00 +02:00
|
|
|
if (error != TOXAV_ERR_CALL_OK) {
|
|
|
|
if (error == TOXAV_ERR_CALL_FRIEND_ALREADY_IN_CALL) {
|
|
|
|
print_err(self, "Already in a call!");
|
|
|
|
} else if (error == TOXAV_ERR_CALL_MALLOC) {
|
|
|
|
print_err(self, "Memory allocation issue");
|
|
|
|
} else if (error == TOXAV_ERR_CALL_FRIEND_NOT_FOUND) {
|
|
|
|
print_err(self, "Friend number invalid");
|
|
|
|
} else if (error == TOXAV_ERR_CALL_FRIEND_NOT_CONNECTED) {
|
|
|
|
print_err(self, "Friend is valid but not currently connected");
|
|
|
|
} else {
|
|
|
|
print_err(self, "Internal error!");
|
|
|
|
}
|
|
|
|
|
|
|
|
cancel_call(call);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
callback_recv_ringing(self->num);
|
2017-06-30 00:26:06 +02:00
|
|
|
}
|
2014-07-04 18:04:03 +02:00
|
|
|
|
2016-09-25 03:07:04 +02:00
|
|
|
void stop_current_call(ToxWindow *self)
|
2015-03-28 07:56:54 +01:00
|
|
|
{
|
2020-04-14 02:00:00 +02:00
|
|
|
Call *call = &CallControl.calls[self->num];
|
|
|
|
|
|
|
|
if (call->status == cs_Pending) {
|
|
|
|
toxav_call_control(CallControl.av, self->num, TOXAV_CALL_CONTROL_CANCEL, NULL);
|
2019-07-12 17:51:08 +02:00
|
|
|
|
2020-04-14 02:00:00 +02:00
|
|
|
cancel_call(call);
|
2015-11-20 05:49:58 +01:00
|
|
|
callback_call_canceled(self->num);
|
|
|
|
} else {
|
2020-04-14 02:00:00 +02:00
|
|
|
|
|
|
|
#ifdef VIDEO
|
|
|
|
callback_recv_video_end(self->num);
|
|
|
|
callback_video_end(self->num);
|
|
|
|
#endif /* VIDEO */
|
|
|
|
|
|
|
|
stop_transmission(call, self->num);
|
2015-11-20 05:49:58 +01:00
|
|
|
callback_call_ended(self->num);
|
|
|
|
}
|
2014-07-06 22:52:11 +02:00
|
|
|
}
|
2017-11-20 13:02:56 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reallocates the Calls list according to n.
|
|
|
|
*/
|
|
|
|
static void realloc_calls(uint32_t n)
|
|
|
|
{
|
2020-11-19 20:21:45 +01:00
|
|
|
if (n == 0) {
|
2017-11-20 13:02:56 +01:00
|
|
|
free(CallControl.calls);
|
|
|
|
CallControl.calls = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Call *temp = realloc(CallControl.calls, n * sizeof(Call));
|
|
|
|
|
|
|
|
if (temp == NULL) {
|
|
|
|
exit_toxic_err("failed in realloc_calls", FATALERR_MEMORY);
|
|
|
|
}
|
|
|
|
|
|
|
|
CallControl.calls = temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Inits the call structure for a given friend. Called when a friend is added to the friends list.
|
|
|
|
* Index must be equivalent to the friend's friendlist index.
|
|
|
|
*/
|
|
|
|
void init_friend_AV(uint32_t index)
|
|
|
|
{
|
|
|
|
if (index == CallControl.max_calls) {
|
2020-04-14 02:00:00 +02:00
|
|
|
realloc_calls(CallControl.max_calls + 1);
|
|
|
|
CallControl.calls[CallControl.max_calls] = (Call) {
|
|
|
|
0
|
|
|
|
};
|
2017-11-20 13:02:56 +01:00
|
|
|
++CallControl.max_calls;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-11-20 13:07:24 +01:00
|
|
|
* Deletes a call structure from the Calls list. Called when a friend is deleted from the friends list.
|
|
|
|
* Index must be equivalent to the size of the Calls list.
|
2017-11-20 13:02:56 +01:00
|
|
|
*/
|
|
|
|
void del_friend_AV(uint32_t index)
|
|
|
|
{
|
|
|
|
realloc_calls(index);
|
|
|
|
CallControl.max_calls = index;
|
|
|
|
}
|
2018-07-06 17:45:35 +02:00
|
|
|
|
2018-10-08 19:39:04 +02:00
|
|
|
#endif /* AUDIO */
|