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-06-22 02:18:23 +02:00
|
|
|
#include "toxic.h"
|
|
|
|
#include "windows.h"
|
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"
|
2014-03-08 01:12:51 +01:00
|
|
|
#include "global_commands.h"
|
2014-03-25 09:39:44 +01:00
|
|
|
#include "line_info.h"
|
2014-07-21 01:12:13 +02:00
|
|
|
#include "notify.h"
|
2014-03-12 00:25:13 +01:00
|
|
|
|
2014-09-23 03:24:45 +02:00
|
|
|
#include <stdbool.h>
|
2014-03-07 03:14:04 +01:00
|
|
|
#include <curses.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
2014-05-16 20:00:01 +02:00
|
|
|
#include <assert.h>
|
2014-03-07 03:14:04 +01:00
|
|
|
|
2015-05-25 16:38:52 +02:00
|
|
|
#ifdef NO_GETTEXT
|
|
|
|
#define gettext(A) (A)
|
|
|
|
#else
|
|
|
|
#include <libintl.h>
|
|
|
|
#endif
|
|
|
|
|
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>
|
|
|
|
#endif
|
2014-06-12 01:40:43 +02:00
|
|
|
#endif
|
|
|
|
|
2014-09-23 03:24:45 +02:00
|
|
|
#define cbend pthread_exit(NULL)
|
2014-03-07 03:14:04 +01:00
|
|
|
|
2014-05-16 20:00:01 +02:00
|
|
|
#define MAX_CALLS 10
|
|
|
|
|
2015-07-03 21:39:27 +02:00
|
|
|
#define frame_size (CallContrl.audio_sample_rate * CallContrl.audio_frame_duration / 1000)
|
2014-05-16 20:00:01 +02:00
|
|
|
|
2014-09-24 04:51:56 +02:00
|
|
|
static int set_call(Call* call, bool start)
|
2014-06-21 01:58:00 +02:00
|
|
|
{
|
|
|
|
call->in_idx = -1;
|
|
|
|
call->out_idx = -1;
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2014-06-21 01:58:00 +02:00
|
|
|
if ( start ) {
|
2014-09-23 03:24:45 +02:00
|
|
|
call->ttas = true;
|
2014-09-24 21:15:07 +02:00
|
|
|
|
2015-07-03 21:39:27 +02:00
|
|
|
if ( pthread_mutex_init(&call->mutex, NULL) != 0 )
|
2014-09-24 04:51:56 +02:00
|
|
|
return -1;
|
2014-06-21 01:58:00 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
call->ttid = 0;
|
2015-07-03 21:39:27 +02:00
|
|
|
if ( pthread_mutex_destroy(&call->mutex) != 0 )
|
2015-05-25 23:59:06 +02:00
|
|
|
return -1;
|
2014-06-21 01:58:00 +02:00
|
|
|
}
|
2014-09-24 04:51:56 +02:00
|
|
|
|
|
|
|
return 0;
|
2014-06-21 01:58:00 +02:00
|
|
|
}
|
|
|
|
|
2015-06-12 17:50:26 +02:00
|
|
|
typedef struct CallControl {
|
2014-03-07 03:14:04 +01:00
|
|
|
AudioError errors;
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2015-06-12 17:50:26 +02:00
|
|
|
ToxAV *av;
|
|
|
|
ToxWindow *window;
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2014-05-16 20:00:01 +02:00
|
|
|
Call calls[MAX_CALLS];
|
2015-06-12 17:50:26 +02:00
|
|
|
bool pending_call;
|
|
|
|
uint32_t call_state;
|
|
|
|
|
|
|
|
bool audio_enabled;
|
|
|
|
bool video_enabled;
|
|
|
|
uint32_t audio_bit_rate;
|
|
|
|
uint32_t video_bit_rate;
|
|
|
|
uint32_t audio_sample_rate;
|
2015-07-03 21:39:27 +02:00
|
|
|
uint32_t video_sample_rate;
|
2015-06-12 17:50:26 +02:00
|
|
|
int32_t audio_frame_duration;
|
|
|
|
int32_t video_frame_duration;
|
|
|
|
|
|
|
|
uint8_t audio_channels;
|
|
|
|
|
|
|
|
} CallControl;
|
|
|
|
|
|
|
|
CallControl CallContrl;
|
|
|
|
|
2015-07-03 21:39:27 +02:00
|
|
|
void call_cb( ToxAV *av, uint32_t friend_number, bool audio_enabled, bool video_enabled, void *user_data );
|
|
|
|
void callstate_cb( ToxAV *av, uint32_t friend_number, uint32_t state, void *user_data );
|
|
|
|
void receive_audio_frame_cb( ToxAV *av, uint32_t friend_number,
|
|
|
|
int16_t const *pcm, size_t sample_count,
|
|
|
|
uint8_t channels, uint32_t sampling_rate, void *user_data );
|
|
|
|
void audio_bit_rate_status_cb( ToxAV *av, uint32_t friend_number,
|
|
|
|
bool stable, uint32_t bit_rate, void *user_data );
|
|
|
|
void receive_video_frame_cb( ToxAV *av, uint32_t friend_number,
|
2015-06-12 17:50:26 +02:00
|
|
|
uint16_t width, uint16_t height,
|
|
|
|
uint8_t const *y, uint8_t const *u, uint8_t const *v, uint8_t const *a,
|
|
|
|
int32_t ystride, int32_t ustride, int32_t vstride, int32_t astride,
|
2015-07-03 21:39:27 +02:00
|
|
|
void *user_data );
|
|
|
|
void video_bit_rate_status_cb( ToxAV *av, uint32_t friend_number,
|
2015-06-12 17:50:26 +02:00
|
|
|
bool stable, uint32_t bit_rate, void *user_data);
|
|
|
|
|
|
|
|
void callback_recv_invite ( void* av, uint32_t friend_number, void *arg );
|
|
|
|
void callback_recv_ringing ( void* av, uint32_t friend_number, void *arg );
|
|
|
|
void callback_recv_starting ( void* av, uint32_t friend_number, void *arg );
|
|
|
|
void callback_recv_ending ( void* av, uint32_t friend_number, void *arg );
|
|
|
|
void callback_call_started ( void* av, uint32_t friend_number, void *arg );
|
|
|
|
void callback_call_canceled ( void* av, uint32_t friend_number, void *arg );
|
|
|
|
void callback_call_rejected ( void* av, uint32_t friend_number, void *arg );
|
|
|
|
void callback_call_ended ( void* av, uint32_t friend_number, void *arg );
|
|
|
|
void callback_requ_timeout ( void* av, uint32_t friend_number, void *arg );
|
|
|
|
void callback_peer_timeout ( void* av, uint32_t friend_number, void *arg );
|
|
|
|
void callback_media_change ( void* av, uint32_t friend_number, void *arg );
|
|
|
|
|
|
|
|
void write_device_callback( void* agent, int32_t friend_number, const int16_t* PCM, uint16_t size, void* arg );
|
2014-07-04 18:14:06 +02:00
|
|
|
|
2014-07-25 04:43:32 +02:00
|
|
|
static void print_err (ToxWindow *self, const char *error_str)
|
2014-03-25 09:39:44 +01:00
|
|
|
{
|
2014-08-02 21:35:57 +02:00
|
|
|
line_info_add(self, NULL, 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
|
|
|
{
|
2015-06-12 17:50:26 +02:00
|
|
|
TOXAV_ERR_NEW error;
|
2015-07-06 22:43:05 +02:00
|
|
|
CallContrl.errors = ae_None;
|
2015-06-12 17:50:26 +02:00
|
|
|
CallContrl.window = self;
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2015-06-12 17:50:26 +02:00
|
|
|
CallContrl.audio_enabled = true;
|
2015-07-03 21:39:27 +02:00
|
|
|
CallContrl.video_enabled = false;
|
2015-06-12 17:50:26 +02:00
|
|
|
CallContrl.audio_bit_rate = 48;
|
2015-07-03 21:39:27 +02:00
|
|
|
CallContrl.video_bit_rate = 0;
|
2015-06-12 17:50:26 +02:00
|
|
|
CallContrl.audio_sample_rate = 48000;
|
2015-07-03 21:39:27 +02:00
|
|
|
CallContrl.video_sample_rate = 0;
|
2015-06-12 17:50:26 +02:00
|
|
|
CallContrl.audio_frame_duration = 10;
|
2015-07-03 21:39:27 +02:00
|
|
|
CallContrl.video_frame_duration = 0;
|
2015-06-12 17:50:26 +02:00
|
|
|
CallContrl.audio_channels = 1;
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2015-06-12 17:50:26 +02:00
|
|
|
memset(CallContrl.calls, 0, sizeof(CallContrl.calls));
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2014-06-21 01:58:00 +02:00
|
|
|
/* Streaming stuff from core */
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2015-06-12 17:50:26 +02:00
|
|
|
CallContrl.av = toxav_new(tox, &error);
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2015-06-12 17:50:26 +02:00
|
|
|
|
|
|
|
if ( !CallContrl.av ) {
|
|
|
|
CallContrl.errors |= ae_StartingCoreAudio;
|
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to init ToxAV");
|
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
|
|
|
|
2015-06-12 17:50:26 +02:00
|
|
|
if ( init_devices(CallContrl.av) == de_InternalError ) {
|
2014-07-25 04:43:32 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to init devices");
|
2015-06-12 17:50:26 +02:00
|
|
|
toxav_kill(CallContrl.av);
|
|
|
|
return CallContrl.av = NULL;
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2015-06-12 17:50:26 +02:00
|
|
|
toxav_callback_call(CallContrl.av, call_cb, &CallContrl);
|
|
|
|
toxav_callback_call_state(CallContrl.av, callstate_cb, &CallContrl);
|
|
|
|
toxav_callback_audio_receive_frame(CallContrl.av, receive_audio_frame_cb, &CallContrl);
|
|
|
|
toxav_callback_audio_bit_rate_status(CallContrl.av, audio_bit_rate_status_cb, &CallContrl);
|
|
|
|
toxav_callback_video_receive_frame(CallContrl.av, receive_video_frame_cb, &CallContrl);
|
|
|
|
toxav_callback_video_bit_rate_status(CallContrl.av, video_bit_rate_status_cb, &CallContrl);
|
|
|
|
|
|
|
|
return CallContrl.av;
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void terminate_audio()
|
|
|
|
{
|
2014-05-16 20:00:01 +02:00
|
|
|
int i;
|
2014-11-26 21:22:34 +01:00
|
|
|
for (i = 0; i < MAX_CALLS; ++i)
|
2015-06-12 17:50:26 +02:00
|
|
|
stop_transmission(&CallContrl.calls[i], i);
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2015-06-12 17:50:26 +02:00
|
|
|
if ( CallContrl.av )
|
|
|
|
toxav_kill(CallContrl.av);
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2014-06-21 01:58:00 +02:00
|
|
|
terminate_devices();
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
|
|
|
|
2014-06-21 01:58:00 +02:00
|
|
|
void read_device_callback (const int16_t* captured, uint32_t size, void* data)
|
2014-03-07 03:14:04 +01:00
|
|
|
{
|
2015-07-03 21:39:27 +02:00
|
|
|
TOXAV_ERR_SEND_FRAME error;
|
2015-06-12 17:50:26 +02:00
|
|
|
int32_t friend_number = *((int32_t*)data); /* TODO: Or pass an array of call_idx's */
|
2015-07-03 21:39:27 +02:00
|
|
|
int64_t sample_count = CallContrl.audio_sample_rate * CallContrl.audio_frame_duration / 1000;
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2015-07-03 21:39:27 +02:00
|
|
|
if ( sample_count <= 0 || toxav_audio_send_frame(CallContrl.av, friend_number,
|
|
|
|
captured, sample_count,
|
|
|
|
CallContrl.audio_channels,
|
|
|
|
CallContrl.audio_sample_rate, &error) == false )
|
|
|
|
{}
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
|
|
|
|
2015-06-12 17:50:26 +02:00
|
|
|
void write_device_callback(void *agent, int32_t friend_number, const int16_t* PCM, uint16_t size, void* arg)
|
2014-06-21 01:58:00 +02:00
|
|
|
{
|
2014-11-26 06:48:58 +01:00
|
|
|
(void)arg;
|
|
|
|
(void)agent;
|
2014-11-15 02:13:08 +01:00
|
|
|
|
2015-07-03 21:39:27 +02:00
|
|
|
if (friend_number >= 0 && CallContrl.calls[friend_number].ttas)
|
2015-06-12 17:50:26 +02:00
|
|
|
write_out(CallContrl.calls[friend_number].out_idx, PCM, size, CallContrl.audio_channels);
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
|
|
|
|
2014-11-26 21:22:34 +01:00
|
|
|
int start_transmission(ToxWindow *self, Call *call)
|
2014-03-07 03:14:04 +01:00
|
|
|
{
|
2015-07-03 21:39:27 +02:00
|
|
|
if ( !self || !CallContrl.av) {
|
2014-07-25 04:43:32 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Could not prepare transmission");
|
2014-11-26 21:22:34 +01:00
|
|
|
return -1;
|
2014-05-16 20:00:01 +02:00
|
|
|
}
|
2014-11-15 02:13:08 +01:00
|
|
|
|
2014-11-26 21:22:34 +01:00
|
|
|
if (set_call(call, true) == -1)
|
2014-09-24 04:51:56 +02:00
|
|
|
return -1;
|
2014-11-15 02:13:08 +01:00
|
|
|
|
2015-07-03 21:39:27 +02:00
|
|
|
DeviceError error = open_primary_device(input, &call->in_idx, CallContrl.audio_sample_rate, CallContrl.audio_frame_duration, CallContrl.audio_channels);
|
2015-06-12 17:50:26 +02:00
|
|
|
|
2015-07-03 21:39:27 +02:00
|
|
|
if ( error == de_FailedStart)
|
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to start input device");
|
2015-06-12 17:50:26 +02:00
|
|
|
|
2015-07-03 21:39:27 +02:00
|
|
|
if ( error == de_InternalError )
|
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Internal error with opening input device");
|
2015-06-12 17:50:26 +02:00
|
|
|
|
2015-07-03 21:39:27 +02:00
|
|
|
if ( error != de_None )
|
2014-07-25 04:43:32 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to open input device!");
|
2014-11-15 02:13:08 +01:00
|
|
|
|
2015-06-12 17:50:26 +02:00
|
|
|
if ( register_device_callback(self->num, call->in_idx,
|
|
|
|
read_device_callback, &self->num, true) != de_None)
|
2014-07-10 01:24:14 +02:00
|
|
|
/* Set VAD as true for all; TODO: Make it more dynamic */
|
2015-05-25 16:38:52 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, gettext("Failed to register input handler!"));
|
2014-11-15 02:13:08 +01:00
|
|
|
|
2015-03-28 07:56:54 +01:00
|
|
|
if ( open_primary_device(output, &call->out_idx,
|
2015-07-03 21:39:27 +02:00
|
|
|
CallContrl.audio_sample_rate, CallContrl.audio_frame_duration, CallContrl.audio_channels) != de_None ) {
|
2014-07-25 04:43:32 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to open output device!");
|
2014-11-26 21:22:34 +01:00
|
|
|
call->has_output = 0;
|
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
|
|
|
}
|
|
|
|
|
2015-06-12 17:50:26 +02:00
|
|
|
int stop_transmission(Call *call, int32_t friend_number)
|
2015-03-28 07:56:54 +01:00
|
|
|
{
|
2014-11-26 21:22:34 +01:00
|
|
|
if ( call->ttas ) {
|
2015-07-03 21:39:27 +02:00
|
|
|
TOXAV_ERR_CALL_CONTROL error = TOXAV_ERR_CALL_CONTROL_OK;
|
|
|
|
if ( CallContrl.call_state != TOXAV_FRIEND_CALL_STATE_FINISHED )
|
|
|
|
toxav_call_control(CallContrl.av, friend_number, TOXAV_CALL_CONTROL_CANCEL, &error);
|
|
|
|
|
|
|
|
if ( error == TOXAV_ERR_CALL_CONTROL_OK ) {
|
2015-06-12 17:50:26 +02:00
|
|
|
call->ttas = false;
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2015-06-12 17:50:26 +02:00
|
|
|
if ( call->in_idx != -1 )
|
|
|
|
close_device(input, call->in_idx);
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2015-06-12 17:50:26 +02:00
|
|
|
if ( call->out_idx != -1 )
|
|
|
|
close_device(output, call->out_idx);
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2015-06-12 17:50:26 +02:00
|
|
|
if (set_call(call, false) == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
} else {
|
2014-09-24 04:51:56 +02:00
|
|
|
|
2015-06-12 17:50:26 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2014-06-21 01:58:00 +02:00
|
|
|
}
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2014-06-24 23:45:14 +02:00
|
|
|
return -1;
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* End of transmission
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Callbacks
|
|
|
|
*/
|
|
|
|
|
2015-06-12 17:50:26 +02:00
|
|
|
void call_cb(ToxAV *av, uint32_t friend_number, bool audio_enabled, bool video_enabled, void *user_data)
|
|
|
|
{
|
|
|
|
TOXAV_ERR_ANSWER error;
|
|
|
|
CallControl* cc = user_data;
|
|
|
|
ToxWindow* window = cc->window;
|
2015-07-03 21:39:27 +02:00
|
|
|
cc->audio_enabled = audio_enabled;
|
|
|
|
cc->video_enabled = video_enabled;
|
2015-06-12 17:50:26 +02:00
|
|
|
cc->pending_call = true;
|
|
|
|
|
|
|
|
callback_recv_invite(av, friend_number, user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void callstate_cb(ToxAV *av, uint32_t friend_number, uint32_t state, void *user_data)
|
2014-04-19 23:58:13 +02:00
|
|
|
{
|
2015-06-12 17:50:26 +02:00
|
|
|
CallControl* cc = user_data;
|
|
|
|
ToxWindow* window = cc->window;
|
|
|
|
cc->call_state = state;
|
|
|
|
|
2015-07-03 21:39:27 +02:00
|
|
|
if( state == TOXAV_FRIEND_CALL_STATE_FINISHED ) {
|
|
|
|
if ( CallContrl.pending_call ) {
|
|
|
|
CallContrl.pending_call = false;
|
|
|
|
callback_call_rejected(CallContrl.av, friend_number, &CallContrl);
|
|
|
|
} else {
|
2015-07-06 22:43:05 +02:00
|
|
|
callback_call_ended(av, friend_number, &CallContrl);
|
2015-07-03 21:39:27 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if( state == TOXAV_FRIEND_CALL_STATE_ERROR ) {
|
|
|
|
line_info_add(window, NULL, NULL, NULL, SYS_MSG, 0, 0, "ToxAV callstate error!");
|
|
|
|
CallContrl.pending_call = false;
|
2015-07-06 22:43:05 +02:00
|
|
|
callback_call_ended(av, friend_number, &CallContrl);
|
2015-07-03 21:39:27 +02:00
|
|
|
} else {
|
|
|
|
CallContrl.pending_call = false;
|
2015-07-06 22:43:05 +02:00
|
|
|
callback_call_started(av, friend_number, &CallContrl);
|
2015-07-03 21:39:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void receive_audio_frame_cb(ToxAV *av, uint32_t friend_number,
|
|
|
|
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
|
|
|
{
|
2015-06-12 17:50:26 +02:00
|
|
|
CallControl* cc = user_data;
|
|
|
|
|
|
|
|
write_device_callback(CallContrl.calls[friend_number].out_idx, friend_number, pcm, frame_size, cc);
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
2015-06-12 17:50:26 +02:00
|
|
|
|
2015-07-03 21:39:27 +02:00
|
|
|
void audio_bit_rate_status_cb(ToxAV *av, uint32_t friend_number,
|
|
|
|
bool stable, uint32_t bit_rate, void *user_data)
|
2014-03-07 03:14:04 +01:00
|
|
|
{
|
2015-06-12 17:50:26 +02:00
|
|
|
CallControl* cc = user_data;
|
|
|
|
|
2015-07-03 21:39:27 +02:00
|
|
|
if ( stable )
|
2015-06-12 17:50:26 +02:00
|
|
|
cc->audio_bit_rate = bit_rate;
|
|
|
|
}
|
|
|
|
|
|
|
|
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, uint8_t const *a,
|
|
|
|
int32_t ystride, int32_t ustride, int32_t vstride, int32_t astride,
|
|
|
|
void *user_data)
|
2015-07-03 21:39:27 +02:00
|
|
|
{}
|
2015-06-12 17:50:26 +02:00
|
|
|
|
|
|
|
void video_bit_rate_status_cb(ToxAV *av, uint32_t friend_number,
|
|
|
|
bool stable, uint32_t bit_rate, void *user_data)
|
|
|
|
{
|
|
|
|
CallControl* cc = user_data;
|
|
|
|
|
2015-07-03 21:39:27 +02:00
|
|
|
if ( stable )
|
2015-06-12 17:50:26 +02:00
|
|
|
cc->video_bit_rate = bit_rate;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-07-03 21:39:27 +02:00
|
|
|
|
|
|
|
|
2015-06-12 17:50:26 +02:00
|
|
|
#define CB_BODY(friend_number, Arg, onFunc) do { ToxWindow* windows = (Arg); int i;\
|
|
|
|
for (i = 0; i < MAX_WINDOWS_NUM; ++i) if (windows[i].onFunc != NULL) windows[i].onFunc(&windows[i], CallContrl.av, friend_number); } while (0)
|
|
|
|
|
|
|
|
|
|
|
|
void callback_recv_invite ( void* av, uint32_t friend_number, void* arg )
|
|
|
|
{
|
|
|
|
//CB_BODY(friend_number, arg, onInvite);
|
|
|
|
CallControl* cc = (CallControl*)arg;
|
|
|
|
ToxWindow* windows = cc->window;
|
|
|
|
|
2014-05-16 20:00:01 +02:00
|
|
|
int i;
|
2015-03-28 07:56:54 +01:00
|
|
|
for (i = 0; i < MAX_WINDOWS_NUM; ++i)
|
2015-06-12 17:50:26 +02:00
|
|
|
if (windows[i].onInvite != NULL && windows[i].num == friend_number) {
|
2015-07-06 22:43:05 +02:00
|
|
|
windows[i].onInvite(&windows[i], av, friend_number, cc->call_state);
|
2015-06-12 17:50:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void callback_recv_ringing ( void* av, uint32_t friend_number, void* arg )
|
|
|
|
{
|
|
|
|
//CB_BODY(friend_number, arg, onRinging);
|
|
|
|
CallControl* cc = arg;
|
|
|
|
ToxWindow* windows = cc->window;
|
2015-07-03 21:39:27 +02:00
|
|
|
|
2015-06-12 17:50:26 +02:00
|
|
|
int i;
|
|
|
|
for (i = 0; i < MAX_WINDOWS_NUM; ++i)
|
2015-07-03 21:39:27 +02:00
|
|
|
if (windows[i].onRinging != NULL && windows[i].is_call && windows[i].num == friend_number) {
|
2015-07-06 22:43:05 +02:00
|
|
|
windows[i].onRinging(&windows[i], av, friend_number, cc->call_state);
|
2015-06-12 17:50:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
void callback_recv_starting ( void* av, uint32_t friend_number, void* arg )
|
|
|
|
{
|
|
|
|
CallControl* cc = arg;
|
|
|
|
ToxWindow* windows = cc->window;
|
2015-07-03 21:39:27 +02:00
|
|
|
|
2015-06-12 17:50:26 +02:00
|
|
|
int i;
|
|
|
|
for (i = 0; i < MAX_WINDOWS_NUM; ++i)
|
2015-07-03 21:39:27 +02:00
|
|
|
if (windows[i].onStarting != NULL && windows[i].is_call && windows[i].num == friend_number) {
|
2015-07-06 22:43:05 +02:00
|
|
|
windows[i].onStarting(&windows[i], av, friend_number, cc->call_state);
|
2015-06-12 17:50:26 +02:00
|
|
|
if ( 0 != start_transmission(&windows[i], &CallContrl.calls[friend_number])) {/* YEAH! */
|
2014-07-25 04:43:32 +02:00
|
|
|
line_info_add(&windows[i], NULL, NULL, NULL, SYS_MSG, 0, 0 , "Error starting transmission!");
|
2014-05-16 20:00:01 +02:00
|
|
|
}
|
2014-07-10 01:24:14 +02:00
|
|
|
return;
|
2014-05-16 20:00:01 +02:00
|
|
|
}
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
2015-06-12 17:50:26 +02:00
|
|
|
void callback_recv_ending ( void* av, uint32_t friend_number, void* arg )
|
2014-04-19 23:58:13 +02:00
|
|
|
{
|
2015-06-12 17:50:26 +02:00
|
|
|
//CB_BODY(friend_number, arg, onEnding);
|
|
|
|
CallControl* cc = arg;
|
|
|
|
ToxWindow* windows = cc->window;
|
2015-07-03 21:39:27 +02:00
|
|
|
|
2015-06-12 17:50:26 +02:00
|
|
|
int i;
|
|
|
|
for (i = 0; i < MAX_WINDOWS_NUM; ++i)
|
2015-07-03 21:39:27 +02:00
|
|
|
if (windows[i].onEnding != NULL && windows[i].is_call && windows[i].num == friend_number) {
|
2015-07-06 22:43:05 +02:00
|
|
|
windows[i].onEnding(&windows[i], av, friend_number, cc->call_state);
|
2015-06-12 17:50:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
stop_transmission(&CallContrl.calls[friend_number], friend_number);
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
2014-07-21 01:12:13 +02:00
|
|
|
|
2015-06-12 17:50:26 +02:00
|
|
|
void callback_call_started ( void* av, uint32_t friend_number, void* arg )
|
2015-03-28 07:56:54 +01:00
|
|
|
{
|
2015-06-12 17:50:26 +02:00
|
|
|
CallControl* cc = arg;
|
|
|
|
ToxWindow* windows = cc->window;
|
2015-07-03 21:39:27 +02:00
|
|
|
|
2014-05-16 20:00:01 +02:00
|
|
|
int i;
|
2015-03-28 07:56:54 +01:00
|
|
|
for (i = 0; i < MAX_WINDOWS_NUM; ++i)
|
2015-07-03 21:39:27 +02:00
|
|
|
if (windows[i].onStart != NULL && windows[i].is_call && windows[i].num == friend_number) {
|
2015-07-06 22:43:05 +02:00
|
|
|
windows[i].onStart(&windows[i], av, friend_number, cc->call_state);
|
2015-06-12 17:50:26 +02:00
|
|
|
if ( 0 != start_transmission(&windows[i], &CallContrl.calls[friend_number]) ) {/* YEAH! */
|
2014-07-25 04:43:32 +02:00
|
|
|
line_info_add(&windows[i], NULL, NULL, NULL, SYS_MSG, 0, 0, "Error starting transmission!");
|
2014-05-16 20:00:01 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
2015-06-12 17:50:26 +02:00
|
|
|
void callback_call_canceled ( void* av, uint32_t friend_number, void* arg )
|
2014-03-07 03:14:04 +01:00
|
|
|
{
|
2015-06-12 17:50:26 +02:00
|
|
|
//CB_BODY(friend_number, arg, onCancel);
|
|
|
|
CallControl* cc = arg;
|
|
|
|
ToxWindow* windows = cc->window;
|
|
|
|
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < MAX_WINDOWS_NUM; ++i)
|
2015-07-03 21:39:27 +02:00
|
|
|
if (windows[i].onCancel != NULL && windows[i].is_call && windows[i].num == friend_number) {
|
2015-07-06 22:43:05 +02:00
|
|
|
windows[i].onCancel(&windows[i], av, friend_number, cc->call_state);
|
2015-06-12 17:50:26 +02:00
|
|
|
}
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2014-03-14 23:08:08 +01:00
|
|
|
/* In case call is active */
|
2015-06-12 17:50:26 +02:00
|
|
|
stop_transmission(&CallContrl.calls[friend_number], friend_number);
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
2015-06-12 17:50:26 +02:00
|
|
|
void callback_call_rejected ( void* av, uint32_t friend_number, void* arg )
|
2014-03-07 03:14:04 +01:00
|
|
|
{
|
2015-06-12 17:50:26 +02:00
|
|
|
//CB_BODY(friend_number, arg, onReject);
|
|
|
|
|
|
|
|
CallControl* cc = arg;
|
|
|
|
ToxWindow* windows = cc->window;
|
|
|
|
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < MAX_WINDOWS_NUM; ++i)
|
2015-07-03 21:39:27 +02:00
|
|
|
if (windows[i].onReject != NULL && windows[i].is_call && windows[i].num == friend_number) {
|
2015-07-06 22:43:05 +02:00
|
|
|
windows[i].onReject(&windows[i], av, friend_number, cc->call_state);
|
2015-06-12 17:50:26 +02:00
|
|
|
}
|
|
|
|
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
2015-06-12 17:50:26 +02:00
|
|
|
void callback_call_ended ( void* av, uint32_t friend_number, void* arg )
|
2014-04-19 23:58:13 +02:00
|
|
|
{
|
2015-06-12 17:50:26 +02:00
|
|
|
//CB_BODY(friend_number, arg, onEnd);
|
|
|
|
CallControl* cc = arg;
|
|
|
|
ToxWindow* windows = cc->window;
|
|
|
|
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < MAX_WINDOWS_NUM; ++i)
|
2015-07-03 21:39:27 +02:00
|
|
|
if (windows[i].onEnd != NULL && windows[i].is_call && windows[i].num == friend_number) {
|
2015-07-06 22:43:05 +02:00
|
|
|
windows[i].onEnd(&windows[i], av, friend_number, cc->call_state);
|
2015-06-12 17:50:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
stop_transmission(&CallContrl.calls[friend_number], friend_number);
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
|
|
|
|
2015-06-12 17:50:26 +02:00
|
|
|
void callback_requ_timeout ( void* av, uint32_t friend_number, void* arg )
|
2014-03-07 03:14:04 +01:00
|
|
|
{
|
2015-06-12 17:50:26 +02:00
|
|
|
//CB_BODY(friend_number, arg, onRequestTimeout);
|
|
|
|
CallControl* cc = arg;
|
|
|
|
ToxWindow* windows = cc->window;
|
|
|
|
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < MAX_WINDOWS_NUM; ++i)
|
2015-07-03 21:39:27 +02:00
|
|
|
if (windows[i].onRequestTimeout != NULL && windows[i].is_call && windows[i].num == friend_number) {
|
2015-07-06 22:43:05 +02:00
|
|
|
windows[i].onRequestTimeout(&windows[i], av, friend_number, cc->call_state);
|
2015-06-12 17:50:26 +02:00
|
|
|
}
|
2014-03-14 23:08:08 +01:00
|
|
|
}
|
2015-06-12 17:50:26 +02:00
|
|
|
void callback_peer_timeout ( void* av, uint32_t friend_number, void* arg )
|
2014-03-14 23:08:08 +01:00
|
|
|
{
|
2015-06-12 17:50:26 +02:00
|
|
|
//CB_BODY(friend_number, arg, onPeerTimeout);
|
|
|
|
CallControl* cc = arg;
|
|
|
|
ToxWindow* windows = cc->window;
|
|
|
|
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < MAX_WINDOWS_NUM; ++i)
|
2015-07-03 21:39:27 +02:00
|
|
|
if (windows[i].onPeerTimeout != NULL && windows[i].is_call && windows[i].num == friend_number) {
|
2015-07-06 22:43:05 +02:00
|
|
|
windows[i].onPeerTimeout(&windows[i], av, friend_number, cc->call_state);
|
2015-06-12 17:50:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
stop_transmission(&CallContrl.calls[friend_number], friend_number);
|
2014-03-14 23:08:08 +01:00
|
|
|
/* Call is stopped manually since there might be some other
|
|
|
|
* actions that one can possibly take on timeout
|
|
|
|
*/
|
2015-06-12 17:50:26 +02:00
|
|
|
TOXAV_ERR_CALL_CONTROL error;
|
2015-07-06 22:43:05 +02:00
|
|
|
bool call_running = toxav_call_control(av, friend_number, TOXAV_CALL_CONTROL_CANCEL, &error);
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
2014-11-26 21:22:34 +01:00
|
|
|
|
2015-06-12 17:50:26 +02:00
|
|
|
// void callback_media_change(void* av, int32_t friend_number, void* arg)
|
2014-11-26 06:48:58 +01:00
|
|
|
// {
|
2014-07-21 03:25:21 +02:00
|
|
|
/*... TODO cancel all media change requests */
|
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])
|
|
|
|
{
|
2015-06-12 17:50:26 +02:00
|
|
|
TOXAV_ERR_CALL error;
|
2014-07-25 04:43:32 +02:00
|
|
|
const char *error_str;
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2015-07-03 21:39:27 +02:00
|
|
|
if ( argc != 0 ) {
|
2014-08-04 20:35:34 +02:00
|
|
|
error_str = "Unknown arguments.";
|
2014-04-19 23:58:13 +02:00
|
|
|
goto on_error;
|
|
|
|
}
|
|
|
|
|
2015-06-12 17:50:26 +02:00
|
|
|
if ( !CallContrl.av ) {
|
|
|
|
error_str = "ToxAV not supported!";
|
2014-04-19 23:58:13 +02:00
|
|
|
goto on_error;
|
|
|
|
}
|
|
|
|
|
2015-07-03 21:39:27 +02:00
|
|
|
if ( !self->stb->connection ) {
|
2014-06-24 04:02:22 +02:00
|
|
|
error_str = "Friend is offline.";
|
|
|
|
goto on_error;
|
|
|
|
}
|
|
|
|
|
2015-06-12 17:50:26 +02:00
|
|
|
bool call_running;
|
|
|
|
call_running = toxav_call(CallContrl.av, self->num, CallContrl.audio_bit_rate, CallContrl.video_bit_rate, &error);
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2015-06-12 17:50:26 +02:00
|
|
|
if ( !call_running ) {
|
|
|
|
if ( error == TOXAV_ERR_CALL_FRIEND_ALREADY_IN_CALL ) error_str = "Already in a call!";
|
2015-07-03 21:39:27 +02:00
|
|
|
else if ( error == TOXAV_ERR_CALL_MALLOC ) error_str = "Memory allocation issue";
|
2015-06-12 17:50:26 +02:00
|
|
|
else if ( error == TOXAV_ERR_CALL_FRIEND_NOT_FOUND) error_str = "Friend number invalid";
|
|
|
|
else if ( error == TOXAV_ERR_CALL_FRIEND_NOT_CONNECTED) error_str = "Friend is valid but not currently connected";
|
2014-03-07 03:14:04 +01:00
|
|
|
else error_str = "Internal error!";
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2014-03-07 03:14:04 +01:00
|
|
|
goto on_error;
|
|
|
|
}
|
2014-03-25 09:39:44 +01:00
|
|
|
|
2015-05-25 16:38:52 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, gettext("Calling... idx: %d"), self->call_idx);
|
2014-03-25 09:39:44 +01:00
|
|
|
|
2014-03-07 03:14:04 +01:00
|
|
|
return;
|
2014-03-25 09:39:44 +01:00
|
|
|
on_error:
|
2014-07-25 04:43:32 +02:00
|
|
|
print_err(self, error_str);
|
2014-03-07 03:14:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmd_answer(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
|
|
|
{
|
2015-06-12 17:50:26 +02:00
|
|
|
TOXAV_ERR_ANSWER error;
|
2014-07-25 04:43:32 +02:00
|
|
|
const char *error_str;
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2015-07-03 21:39:27 +02:00
|
|
|
if ( argc != 0 ) {
|
2014-08-04 20:35:34 +02:00
|
|
|
error_str = "Unknown arguments.";
|
2014-04-19 23:58:13 +02:00
|
|
|
goto on_error;
|
|
|
|
}
|
|
|
|
|
2015-06-12 17:50:26 +02:00
|
|
|
if ( !CallContrl.av ) {
|
2014-04-19 23:58:13 +02:00
|
|
|
error_str = "Audio not supported!";
|
|
|
|
goto on_error;
|
|
|
|
}
|
|
|
|
|
2015-07-06 22:43:05 +02:00
|
|
|
bool call_running = toxav_answer(CallContrl.av, self->num, CallContrl.audio_bit_rate, CallContrl.video_bit_rate, &error);
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2015-06-12 17:50:26 +02:00
|
|
|
if ( !call_running ) {
|
|
|
|
if ( error == TOXAV_ERR_ANSWER_FRIEND_NOT_CALLING ) error_str = "No incoming call!";
|
2015-07-03 21:39:27 +02:00
|
|
|
else if ( error == TOXAV_ERR_ANSWER_CODEC_INITIALIZATION ) error_str = "Failed to initialize codecs!";
|
|
|
|
else if ( error == TOXAV_ERR_ANSWER_FRIEND_NOT_FOUND ) error_str = "Friend not found!";
|
|
|
|
else if ( error == TOXAV_ERR_ANSWER_INVALID_BIT_RATE ) error_str = "Invalid bit rate!";
|
2014-03-07 03:14:04 +01:00
|
|
|
else error_str = "Internal error!";
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2014-03-07 03:14:04 +01:00
|
|
|
goto on_error;
|
|
|
|
}
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2014-03-07 03:14:04 +01:00
|
|
|
/* Callback will print status... */
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2015-07-03 21:39:27 +02:00
|
|
|
self->is_call = call_running;
|
2015-06-12 17:50:26 +02:00
|
|
|
CallContrl.pending_call = false;
|
|
|
|
callback_recv_starting(CallContrl.av, self->num, &CallContrl);
|
|
|
|
|
2014-03-07 03:14:04 +01:00
|
|
|
return;
|
2014-04-19 23:58:13 +02:00
|
|
|
on_error:
|
2014-03-25 09:39:44 +01:00
|
|
|
print_err (self, error_str);
|
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])
|
|
|
|
{
|
2015-06-12 17:50:26 +02:00
|
|
|
TOXAV_ERR_CALL_CONTROL error;
|
2014-07-25 04:43:32 +02:00
|
|
|
const char *error_str;
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2015-07-03 21:39:27 +02:00
|
|
|
if ( argc != 0 ) {
|
2014-08-04 20:35:34 +02:00
|
|
|
error_str = "Unknown arguments.";
|
2014-04-19 23:58:13 +02:00
|
|
|
goto on_error;
|
|
|
|
}
|
|
|
|
|
2015-06-12 17:50:26 +02:00
|
|
|
if ( !CallContrl.av ) {
|
2014-04-19 23:58:13 +02:00
|
|
|
error_str = "Audio not supported!";
|
|
|
|
goto on_error;
|
|
|
|
}
|
|
|
|
|
2015-06-12 17:50:26 +02:00
|
|
|
bool call_running;
|
|
|
|
call_running = toxav_call_control(CallContrl.av, self->num, TOXAV_CALL_CONTROL_CANCEL, &error);
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2015-06-12 17:50:26 +02:00
|
|
|
if ( error != TOXAV_ERR_CALL_CONTROL_OK ) {
|
|
|
|
if ( error == TOXAV_ERR_CALL_CONTROL_INVALID_TRANSITION ) error_str = "Cannot reject in invalid state!";
|
|
|
|
else if ( CallContrl.pending_call == false ) error_str = "No incoming call!";
|
2014-03-23 22:54:56 +01:00
|
|
|
else error_str = "Internal error!";
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2014-03-23 22:54:56 +01:00
|
|
|
goto on_error;
|
|
|
|
}
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2014-03-23 22:54:56 +01:00
|
|
|
/* Callback will print status... */
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2015-07-03 21:39:27 +02:00
|
|
|
self->is_call = call_running;
|
2015-06-12 17:50:26 +02:00
|
|
|
CallContrl.pending_call = false;
|
|
|
|
callback_call_rejected(CallContrl.av, self->num, &CallContrl);
|
2015-07-03 21:39:27 +02:00
|
|
|
|
2014-03-23 22:54:56 +01:00
|
|
|
return;
|
2014-04-19 23:58:13 +02:00
|
|
|
on_error:
|
2014-03-26 03:02:48 +01:00
|
|
|
print_err (self, error_str);
|
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])
|
|
|
|
{
|
2015-06-12 17:50:26 +02:00
|
|
|
TOXAV_ERR_CALL_CONTROL error;
|
2014-07-25 04:43:32 +02:00
|
|
|
const char *error_str;
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2015-07-03 21:39:27 +02:00
|
|
|
if ( argc != 0 ) {
|
2014-08-04 20:35:34 +02:00
|
|
|
error_str = "Unknown arguments.";
|
2014-04-19 23:58:13 +02:00
|
|
|
goto on_error;
|
|
|
|
}
|
|
|
|
|
2015-06-12 17:50:26 +02:00
|
|
|
if ( !CallContrl.av ) {
|
2014-04-19 23:58:13 +02:00
|
|
|
error_str = "Audio not supported!";
|
|
|
|
goto on_error;
|
|
|
|
}
|
|
|
|
|
2015-06-12 17:50:26 +02:00
|
|
|
bool call_running;
|
2015-07-03 21:39:27 +02:00
|
|
|
if( CallContrl.pending_call && CallContrl.call_state != TOXAV_FRIEND_CALL_STATE_FINISHED ) {
|
2015-06-12 17:50:26 +02:00
|
|
|
call_running = toxav_call_control(CallContrl.av, self->num, TOXAV_CALL_CONTROL_CANCEL, &error);
|
2014-09-23 03:24:45 +02:00
|
|
|
#ifdef SOUND_NOTIFY
|
2014-08-04 05:11:19 +02:00
|
|
|
stop_sound(self->ringing_sound);
|
|
|
|
#endif
|
2015-06-12 17:50:26 +02:00
|
|
|
CallContrl.pending_call = false;
|
2015-07-03 21:39:27 +02:00
|
|
|
callback_call_ended(CallContrl.av, self->num, &CallContrl);
|
2014-08-04 05:11:19 +02:00
|
|
|
} else {
|
2015-07-03 21:39:27 +02:00
|
|
|
call_running = toxav_call_control(CallContrl.av, self->num, TOXAV_CALL_CONTROL_CANCEL, &error);
|
2015-06-12 17:50:26 +02:00
|
|
|
callback_call_ended(CallContrl.av, self->num, &CallContrl);
|
2014-04-19 23:58:13 +02:00
|
|
|
}
|
|
|
|
|
2015-06-12 17:50:26 +02:00
|
|
|
if ( error != TOXAV_ERR_CALL_CONTROL_OK ) {
|
|
|
|
if ( error == TOXAV_ERR_CALL_CONTROL_INVALID_TRANSITION ) error_str = "Cannot hangup in invalid state!";
|
|
|
|
else if ( error == TOXAV_ERR_CALL_CONTROL_FRIEND_NOT_IN_CALL ) error_str = "No call!";
|
2015-07-03 21:39:27 +02:00
|
|
|
else if ( error == TOXAV_ERR_CALL_CONTROL_FRIEND_NOT_FOUND ) error_str = "Invalid friend!";
|
2014-03-07 03:14:04 +01:00
|
|
|
else error_str = "Internal error!";
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2014-03-07 03:14:04 +01:00
|
|
|
goto on_error;
|
|
|
|
}
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2014-03-07 03:14:04 +01:00
|
|
|
return;
|
2014-04-19 23:58:13 +02:00
|
|
|
on_error:
|
2014-03-25 09:39:44 +01:00
|
|
|
print_err (self, error_str);
|
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])
|
|
|
|
{
|
2014-07-25 04:43:32 +02:00
|
|
|
const char *error_str;
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2014-03-08 01:12:51 +01:00
|
|
|
if ( argc != 1 ) {
|
2015-05-25 16:38:52 +02:00
|
|
|
if ( argc < 1 ) error_str = gettext("Type must be specified!");
|
|
|
|
else error_str = gettext("Only one argument allowed!");
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2014-03-08 01:12:51 +01:00
|
|
|
goto on_error;
|
|
|
|
}
|
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
|
|
|
|
2014-11-26 06:48:58 +01:00
|
|
|
if ( strcasecmp(argv[1], "in") == 0 ) /* Input devices */
|
2014-03-08 01:12:51 +01:00
|
|
|
type = input;
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2014-11-26 06:48:58 +01:00
|
|
|
else if ( strcasecmp(argv[1], "out") == 0 ) /* Output devices */
|
2014-03-08 01:12:51 +01:00
|
|
|
type = output;
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2014-03-08 01:12:51 +01:00
|
|
|
else {
|
2015-05-25 16:38:52 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, gettext("Invalid type: %s"), argv[1]);
|
2014-03-08 01:12:51 +01:00
|
|
|
return;
|
|
|
|
}
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2014-06-21 01:58:00 +02:00
|
|
|
print_devices(self, type);
|
2014-03-25 09:39:44 +01:00
|
|
|
|
2014-03-08 01:12:51 +01:00
|
|
|
return;
|
2014-04-19 23:58:13 +02:00
|
|
|
on_error:
|
2014-03-25 09:39:44 +01:00
|
|
|
print_err (self, error_str);
|
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])
|
|
|
|
{
|
2014-07-25 04:43:32 +02:00
|
|
|
const char *error_str;
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2014-03-08 01:12:51 +01:00
|
|
|
if ( argc != 2 ) {
|
2015-05-25 16:38:52 +02:00
|
|
|
if ( argc < 1 ) error_str = gettext("Type must be specified!");
|
|
|
|
else if ( argc < 2 ) error_str = gettext("Must have id!");
|
|
|
|
else error_str = gettext("Only two arguments allowed!");
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2014-03-08 01:12:51 +01:00
|
|
|
goto on_error;
|
|
|
|
}
|
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
|
|
|
|
2014-03-08 01:12:51 +01:00
|
|
|
if ( strcmp(argv[1], "in") == 0 ) /* Input devices */
|
|
|
|
type = input;
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2014-03-08 01:12:51 +01:00
|
|
|
else if ( strcmp(argv[1], "out") == 0 ) /* Output devices */
|
|
|
|
type = output;
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2014-03-08 01:12:51 +01:00
|
|
|
else {
|
2015-05-25 16:38:52 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, gettext("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
|
|
|
|
2014-03-08 01:12:51 +01:00
|
|
|
if ( *end ) {
|
2015-05-25 16:38:52 +02:00
|
|
|
error_str = gettext("Invalid input");
|
2014-03-08 01:12:51 +01:00
|
|
|
goto on_error;
|
|
|
|
}
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2014-06-21 01:58:00 +02:00
|
|
|
if ( set_primary_device(type, selection) == de_InvalidSelection ) {
|
2015-05-25 16:38:52 +02:00
|
|
|
error_str=gettext("Invalid selection!");
|
2014-05-16 20:00:01 +02:00
|
|
|
goto on_error;
|
|
|
|
}
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2014-06-21 01:58:00 +02:00
|
|
|
return;
|
|
|
|
on_error:
|
|
|
|
print_err (self, error_str);
|
|
|
|
}
|
|
|
|
|
2014-07-31 18:48:49 +02:00
|
|
|
void cmd_ccur_device(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
2014-08-02 21:35:57 +02:00
|
|
|
{
|
2014-07-25 04:43:32 +02:00
|
|
|
const char *error_str;
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2014-06-21 01:58:00 +02:00
|
|
|
if ( argc != 2 ) {
|
2015-05-25 16:38:52 +02:00
|
|
|
if ( argc < 1 ) error_str = gettext("Type must be specified!");
|
|
|
|
else if ( argc < 2 ) error_str = gettext("Must have id!");
|
|
|
|
else error_str = gettext("Only two arguments allowed!");
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2014-06-21 01:58:00 +02:00
|
|
|
goto on_error;
|
2014-05-16 20:00:01 +02:00
|
|
|
}
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2014-06-21 01:58:00 +02:00
|
|
|
DeviceType type;
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2014-06-21 01:58:00 +02:00
|
|
|
if ( strcmp(argv[1], "in") == 0 ) /* Input devices */
|
|
|
|
type = input;
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2014-06-21 01:58:00 +02:00
|
|
|
else if ( strcmp(argv[1], "out") == 0 ) /* Output devices */
|
|
|
|
type = output;
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2014-06-21 01:58:00 +02:00
|
|
|
else {
|
2015-05-25 16:38:52 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, gettext("Invalid type: %s"), argv[1]);
|
2014-06-21 01:58:00 +02:00
|
|
|
return;
|
2014-03-08 01:12:51 +01:00
|
|
|
}
|
2015-03-28 07:56:54 +01:00
|
|
|
|
|
|
|
|
2014-06-21 01:58:00 +02:00
|
|
|
char *end;
|
|
|
|
long int selection = strtol(argv[2], &end, 10);
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2014-06-21 01:58:00 +02:00
|
|
|
if ( *end ) {
|
2015-05-25 16:38:52 +02:00
|
|
|
error_str = gettext("Invalid input");
|
2014-06-21 01:58:00 +02:00
|
|
|
goto on_error;
|
|
|
|
}
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2014-06-21 01:58:00 +02:00
|
|
|
if ( selection_valid(type, selection) == de_InvalidSelection ) {
|
2015-05-25 16:38:52 +02:00
|
|
|
error_str=gettext("Invalid selection!");
|
2014-06-21 01:58:00 +02:00
|
|
|
goto on_error;
|
|
|
|
}
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2014-06-21 01:58:00 +02:00
|
|
|
/* If call is active, change device */
|
2015-07-03 21:39:27 +02:00
|
|
|
if ( self->is_call ) {
|
2015-06-12 17:50:26 +02:00
|
|
|
Call* this_call = &CallContrl.calls[self->num];
|
2014-06-21 01:58:00 +02:00
|
|
|
if (this_call->ttas) {
|
2015-03-28 07:56:54 +01:00
|
|
|
|
|
|
|
|
2014-06-21 01:58:00 +02:00
|
|
|
if (type == output) {
|
|
|
|
pthread_mutex_lock(&this_call->mutex);
|
|
|
|
close_device(output, this_call->out_idx);
|
2015-03-28 07:56:54 +01:00
|
|
|
this_call->has_output = open_device(output, selection, &this_call->out_idx,
|
2015-07-03 21:39:27 +02:00
|
|
|
CallContrl.audio_sample_rate, CallContrl.audio_frame_duration, CallContrl.audio_channels)
|
2014-06-24 00:20:44 +02:00
|
|
|
== de_None ? 1 : 0;
|
2014-06-21 01:58:00 +02:00
|
|
|
pthread_mutex_unlock(&this_call->mutex);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* TODO: check for failure */
|
|
|
|
close_device(input, this_call->in_idx);
|
2015-07-03 21:39:27 +02:00
|
|
|
open_device(input, selection, &this_call->in_idx, CallContrl.audio_sample_rate,
|
2015-06-12 17:50:26 +02:00
|
|
|
CallContrl.audio_frame_duration, CallContrl.audio_channels);
|
2014-06-21 01:58:00 +02:00
|
|
|
/* Set VAD as true for all; TODO: Make it more dynamic */
|
2015-06-12 17:50:26 +02:00
|
|
|
register_device_callback(self->num, this_call->in_idx, read_device_callback, &self->num, true);
|
2014-06-21 01:58:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2014-06-21 01:58:00 +02:00
|
|
|
self->device_selection[type] = selection;
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2014-03-08 01:12:51 +01:00
|
|
|
return;
|
2014-06-22 02:18:23 +02:00
|
|
|
on_error:
|
|
|
|
print_err (self, error_str);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2014-07-25 04:43:32 +02:00
|
|
|
const char *error_str;
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2014-06-22 02:18:23 +02:00
|
|
|
if ( argc != 1 ) {
|
2015-05-25 16:38:52 +02:00
|
|
|
if ( argc < 1 ) error_str = gettext("Type must be specified!");
|
|
|
|
else error_str = gettext("Only two arguments allowed!");
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2014-06-22 02:18:23 +02:00
|
|
|
goto on_error;
|
|
|
|
}
|
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
|
|
|
|
2014-08-04 20:35:34 +02:00
|
|
|
if ( strcasecmp(argv[1], "in") == 0 ) /* Input devices */
|
2014-06-22 02:18:23 +02:00
|
|
|
type = input;
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2014-08-04 20:35:34 +02:00
|
|
|
else if ( strcasecmp(argv[1], "out") == 0 ) /* Output devices */
|
2014-06-22 02:18:23 +02:00
|
|
|
type = output;
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2014-06-22 02:18:23 +02:00
|
|
|
else {
|
2015-05-25 16:38:52 +02:00
|
|
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, gettext("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 */
|
2015-07-03 21:39:27 +02:00
|
|
|
if ( self->is_call ) {
|
2015-06-12 17:50:26 +02:00
|
|
|
Call* this_call = &CallContrl.calls[self->num];
|
2015-03-28 07:56:54 +01:00
|
|
|
|
|
|
|
pthread_mutex_lock(&this_call->mutex);
|
2014-06-24 00:54:23 +02:00
|
|
|
if (type == input) {
|
|
|
|
device_mute(type, this_call->in_idx);
|
|
|
|
self->chatwin->infobox.in_is_muted ^= 1;
|
|
|
|
} else {
|
|
|
|
device_mute(type, this_call->out_idx);
|
2014-06-24 01:00:11 +02:00
|
|
|
self->chatwin->infobox.out_is_muted ^= 1;
|
2014-06-24 00:54:23 +02:00
|
|
|
}
|
|
|
|
pthread_mutex_unlock(&this_call->mutex);
|
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;
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2014-06-22 02:18:23 +02:00
|
|
|
on_error:
|
|
|
|
print_err (self, error_str);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2014-07-25 04:43:32 +02:00
|
|
|
const char *error_str;
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2014-06-22 02:18:23 +02:00
|
|
|
if ( argc != 1 ) {
|
2015-05-25 16:38:52 +02:00
|
|
|
if ( argc < 1 ) error_str = gettext("Must have value!");
|
|
|
|
else error_str = gettext("Only two arguments allowed!");
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2014-06-22 02:18:23 +02:00
|
|
|
goto on_error;
|
|
|
|
}
|
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
|
|
|
|
2014-06-22 02:18:23 +02:00
|
|
|
if ( *end ) {
|
2015-05-25 16:38:52 +02:00
|
|
|
error_str = gettext("Invalid input");
|
2014-06-22 02:18:23 +02:00
|
|
|
goto on_error;
|
|
|
|
}
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2014-06-22 02:18:23 +02:00
|
|
|
/* Call must be active */
|
2015-07-03 21:39:27 +02:00
|
|
|
if ( self->is_call ) {
|
2015-06-12 17:50:26 +02:00
|
|
|
device_set_VAD_treshold(CallContrl.calls[self->num].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;
|
2015-03-28 07:56:54 +01:00
|
|
|
|
2014-04-19 23:58:13 +02:00
|
|
|
on_error:
|
2014-03-25 09:39:44 +01:00
|
|
|
print_err (self, error_str);
|
|
|
|
}
|
2014-07-04 18:04:03 +02:00
|
|
|
|
|
|
|
|
|
|
|
void stop_current_call(ToxWindow* self)
|
2015-03-28 07:56:54 +01:00
|
|
|
{
|
2015-06-12 17:50:26 +02:00
|
|
|
TOXAV_ERR_CALL_CONTROL error;
|
|
|
|
bool call_running = toxav_call_control(CallContrl.av, &self->num, TOXAV_CALL_CONTROL_CANCEL, &error);
|
2015-07-03 21:39:27 +02:00
|
|
|
self->is_call = call_running;
|
2014-07-06 22:52:11 +02:00
|
|
|
}
|