mirror of
https://github.com/Tha14/toxic.git
synced 2024-12-24 02:33:25 +01:00
commit
6aee8c136b
@ -45,3 +45,16 @@ toxic_LDADD = $(LIBTOXCORE_LDFLAGS) \
|
||||
$(LIBSODIUM_LIBS) \
|
||||
$(WINSOCK2_LIBS)
|
||||
|
||||
|
||||
# For audio support
|
||||
if BUILD_AV
|
||||
|
||||
toxic_SOURCES += $(top_srcdir)/src/audio_call.c \
|
||||
$(top_srcdir)/src/audio_call.h
|
||||
|
||||
toxic_CFLAGS += $(LIBTOXAV_CFLAGS) \
|
||||
$(OPENAL_CFLAGS)
|
||||
|
||||
toxic_LDADD += $(LIBTOXAV_LIBS) \
|
||||
$(OPENAL_LIBS)
|
||||
endif
|
||||
|
67
configure.ac
67
configure.ac
@ -381,6 +381,73 @@ if test "x$LIBTOXCORE_FOUND" = "xno"; then
|
||||
AC_SUBST(LIBTOXCORE_LDFLAGS)
|
||||
fi
|
||||
|
||||
|
||||
####
|
||||
#### A/V Stuff
|
||||
|
||||
AV_SEARCH_DIR=
|
||||
BUILD_AV="yes"
|
||||
|
||||
AC_ARG_WITH(libtoxav-prefix,
|
||||
AC_HELP_STRING([--with-libtoxav-prefix=DIR],
|
||||
[search for libtoxav in DIR, i.e. look for libraries in
|
||||
DIR/lib and for headers in DIR/include]),
|
||||
[
|
||||
AV_SEARCH_DIR="$withval"
|
||||
]
|
||||
)
|
||||
|
||||
if test -n "$AV_SEARCH_DIR"; then
|
||||
CFLAGS="$CFLAGS -I$AV_SEARCH_DIR/include"
|
||||
CPPFLAGS="$CPPFLAGS -I$AV_SEARCH_DIR/include"
|
||||
LDFLAGS="$LDFLAGS -L$AV_SEARCH_DIR/lib"
|
||||
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$AV_SEARCH_DIR/lib/pkgconfig
|
||||
fi
|
||||
|
||||
# Check if specified enable
|
||||
AC_ARG_ENABLE([av],
|
||||
[AC_HELP_STRING([--disable-av], [build AV support libraries (default: auto)]) ],
|
||||
[
|
||||
if test "x$enableval" = "xno"; then
|
||||
BUILD_AV="no"
|
||||
elif test "x$enableval" = "xyes"; then
|
||||
BUILD_AV="yes"
|
||||
fi
|
||||
]
|
||||
)
|
||||
|
||||
# Check for A/V library
|
||||
|
||||
if test "x$BUILD_AV" = "xyes"; then
|
||||
PKG_CHECK_MODULES([OPENAL], [openal],
|
||||
[
|
||||
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
|
||||
|
||||
PKG_CHECK_MODULES([LIBTOXAV], [libtoxav],
|
||||
[
|
||||
AC_CHECK_HEADER([tox/toxav.h],
|
||||
[
|
||||
# Place define for audio support
|
||||
AC_DEFINE([_SUPPORT_AUDIO], [], [Is audio supported])
|
||||
AC_MSG_NOTICE([Building with audio support])
|
||||
],
|
||||
[
|
||||
AC_MSG_NOTICE([No A/V headers; disabling A/V support])
|
||||
BUILD_AV="no"
|
||||
],)
|
||||
],
|
||||
[
|
||||
AC_MSG_NOTICE([No A/V library; disabling A/V support])
|
||||
])
|
||||
],
|
||||
[
|
||||
AC_MSG_NOTICE([No openal library; disabling A/V support])
|
||||
])
|
||||
fi
|
||||
|
||||
AM_CONDITIONAL(BUILD_AV, test "x$BUILD_AV" = "xyes")
|
||||
|
||||
|
||||
TOXIC_VERSION="$PACKAGE_VERSION"
|
||||
AC_PATH_PROG([GIT], [git], [no])
|
||||
if test "x$GIT" != "xno"; then
|
||||
|
608
src/audio_call.c
Normal file
608
src/audio_call.c
Normal file
@ -0,0 +1,608 @@
|
||||
/*
|
||||
* Toxic -- Tox Curses Client
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "audio_call.h"
|
||||
#include "toxic_windows.h"
|
||||
#include "chat_commands.h"
|
||||
#include "global_commands.h"
|
||||
#include "toxic_windows.h"
|
||||
#include <curses.h>
|
||||
#include <AL/al.h>
|
||||
#include <AL/alc.h>
|
||||
#include <string.h>
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define MAX_DEVICES 32
|
||||
#define _cbend pthread_exit(NULL)
|
||||
|
||||
typedef struct _DeviceIx {
|
||||
|
||||
ALCdevice* dhndl; /* Handle of device selected/opened */
|
||||
ALCcontext* ctx; /* Device context */
|
||||
const char* devices[MAX_DEVICES]; /* Container */
|
||||
int size;
|
||||
int dix; /* Index of default device */
|
||||
} DeviceIx;
|
||||
|
||||
typedef enum _devices
|
||||
{
|
||||
input,
|
||||
output,
|
||||
} _devices;
|
||||
|
||||
struct _ASettings {
|
||||
|
||||
DeviceIx device[2];
|
||||
|
||||
AudioError errors;
|
||||
|
||||
ToxAv* av;
|
||||
|
||||
pthread_t ttid; /* Transmission thread id */
|
||||
int ttas; /* Transmission thread active status (0 - stopped, 1- running) */
|
||||
} ASettins;
|
||||
|
||||
|
||||
void *callback_recv_invite ( void *arg );
|
||||
void *callback_recv_ringing ( void *arg );
|
||||
void *callback_recv_starting ( void *arg );
|
||||
void *callback_recv_ending ( void *arg );
|
||||
void *callback_recv_error ( void *arg );
|
||||
void *callback_call_started ( void *arg );
|
||||
void *callback_call_canceled ( void *arg );
|
||||
void *callback_call_rejected ( void *arg );
|
||||
void *callback_call_ended ( void *arg );
|
||||
void *callback_requ_timeout ( void *arg );
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
ToxAv* init_audio(ToxWindow* window, Tox* tox)
|
||||
{
|
||||
ASettins.errors = NoError;
|
||||
ASettins.ttas = 0; /* Not running */
|
||||
|
||||
/* Capture device */
|
||||
const char* stringed_device_list = alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER);
|
||||
ASettins.device[input].size = 0;
|
||||
|
||||
if ( stringed_device_list ) {
|
||||
const char* default_device = alcGetString(NULL, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER);
|
||||
|
||||
for ( ; *stringed_device_list; ++ASettins.device[input].size ) {
|
||||
ASettins.device[input].devices[ASettins.device[input].size] = stringed_device_list;
|
||||
|
||||
if ( strcmp( default_device , ASettins.device[input].devices[ASettins.device[input].size] ) == 0 )
|
||||
ASettins.device[input].dix = ASettins.device[input].size;
|
||||
|
||||
stringed_device_list += strlen( stringed_device_list ) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ASettins.device[input].size ) { /* Have device */
|
||||
ASettins.device[input].dhndl = alcCaptureOpenDevice(
|
||||
ASettins.device[input].devices[ASettins.device[input].dix], AUDIO_SAMPLE_RATE, AL_FORMAT_MONO16, AUDIO_FRAME_SIZE * 4);
|
||||
|
||||
if (alcGetError(ASettins.device[input].dhndl) != AL_NO_ERROR) {
|
||||
ASettins.errors |= ErrorStartingCaptureDevice;
|
||||
}
|
||||
|
||||
wprintw(window->window, "Input device: %s\n", ASettins.device[input].devices[ASettins.device[input].dix]);
|
||||
} else { /* No device */
|
||||
wprintw(window->window, "No input device!\n");
|
||||
ASettins.device[input].dhndl = NULL;
|
||||
}
|
||||
|
||||
ASettins.device[input].ctx = NULL;
|
||||
|
||||
|
||||
|
||||
|
||||
/* Output device */
|
||||
stringed_device_list = alcGetString(NULL, ALC_DEVICE_SPECIFIER);
|
||||
ASettins.device[output].size = 0;
|
||||
|
||||
if ( stringed_device_list ) {
|
||||
const char* default_device = alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER);
|
||||
|
||||
for ( ; *stringed_device_list; ++ASettins.device[output].size ) {
|
||||
ASettins.device[output].devices[ASettins.device[output].size] = stringed_device_list;
|
||||
|
||||
if ( strcmp( default_device , ASettins.device[output].devices[ASettins.device[output].size] ) == 0 )
|
||||
ASettins.device[output].dix = ASettins.device[output].size;
|
||||
|
||||
stringed_device_list += strlen( stringed_device_list ) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ASettins.device[output].size ) { /* Have device */
|
||||
ASettins.device[output].dhndl = alcOpenDevice(ASettins.device[output].devices[ASettins.device[output].dix]);
|
||||
|
||||
if (alcGetError(ASettins.device[output].dhndl) != AL_NO_ERROR) {
|
||||
ASettins.errors |= ErrorStartingOutputDevice;
|
||||
}
|
||||
|
||||
wprintw(window->window, "Output device: %s\n", ASettins.device[output].devices[ASettins.device[output].dix]);
|
||||
ASettins.device[output].ctx = alcCreateContext(ASettins.device[output].dhndl, NULL);
|
||||
} else { /* No device */
|
||||
wprintw(window->window, "No output device!\n");
|
||||
ASettins.device[output].dhndl = NULL;
|
||||
ASettins.device[output].ctx = NULL;
|
||||
}
|
||||
|
||||
|
||||
/* Streaming stuff from core */
|
||||
ASettins.av = toxav_new(tox, 0, 0);
|
||||
|
||||
if ( !ASettins.av ) {
|
||||
ASettins.errors |= ErrorStartingCoreAudio;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
toxav_register_callstate_callback(callback_call_started, av_OnStart, window);
|
||||
toxav_register_callstate_callback(callback_call_canceled, av_OnCancel, window);
|
||||
toxav_register_callstate_callback(callback_call_rejected, av_OnReject, window);
|
||||
toxav_register_callstate_callback(callback_call_ended, av_OnEnd, window);
|
||||
toxav_register_callstate_callback(callback_recv_invite, av_OnInvite, window);
|
||||
|
||||
toxav_register_callstate_callback(callback_recv_ringing, av_OnRinging, window);
|
||||
toxav_register_callstate_callback(callback_recv_starting, av_OnStarting, window);
|
||||
toxav_register_callstate_callback(callback_recv_ending, av_OnEnding, window);
|
||||
|
||||
toxav_register_callstate_callback(callback_recv_error, av_OnError, window);
|
||||
toxav_register_callstate_callback(callback_requ_timeout, av_OnRequestTimeout, window);
|
||||
|
||||
return ASettins.av;
|
||||
}
|
||||
|
||||
void terminate_audio()
|
||||
{
|
||||
if ( ASettins.device[input].dhndl ) {
|
||||
alcCaptureCloseDevice(ASettins.device[input].dhndl);
|
||||
}
|
||||
|
||||
if ( ASettins.device[output].dhndl ) {
|
||||
alcCloseDevice(ASettins.device[output].dhndl);
|
||||
alcMakeContextCurrent(NULL);
|
||||
alcDestroyContext(ASettins.device[output].ctx);
|
||||
}
|
||||
|
||||
toxav_kill(ASettins.av);
|
||||
}
|
||||
|
||||
|
||||
int errors()
|
||||
{
|
||||
return ASettins.errors;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Transmission
|
||||
*/
|
||||
|
||||
void* transmission(void* arg)
|
||||
{
|
||||
(void)arg; /* Avoid warning */
|
||||
|
||||
ASettins.ttas = 1;
|
||||
|
||||
/* Prepare devices */
|
||||
alcCaptureStart(ASettins.device[input].dhndl);
|
||||
alcMakeContextCurrent(ASettins.device[output].ctx);
|
||||
|
||||
int32_t dec_frame_len;
|
||||
int16_t frame[4096];
|
||||
int32_t sample = 0;
|
||||
uint32_t buffer;
|
||||
int32_t ready;
|
||||
int32_t openal_buffers = 5;
|
||||
uint32_t source, *buffers;
|
||||
|
||||
/* Prepare buffers */
|
||||
buffers = calloc(sizeof(uint32_t), openal_buffers);
|
||||
alGenBuffers(openal_buffers, buffers);
|
||||
alGenSources((uint32_t)1, &source);
|
||||
alSourcei(source, AL_LOOPING, AL_FALSE);
|
||||
|
||||
|
||||
uint16_t zeros[AUDIO_FRAME_SIZE];
|
||||
memset(zeros, 0, AUDIO_FRAME_SIZE);
|
||||
int16_t PCM[AUDIO_FRAME_SIZE];
|
||||
|
||||
int32_t i = 0;
|
||||
for (; i < openal_buffers; ++i) {
|
||||
alBufferData(buffers[i], AL_FORMAT_MONO16, zeros, AUDIO_FRAME_SIZE, 48000);
|
||||
}
|
||||
|
||||
alSourceQueueBuffers(source, openal_buffers, buffers);
|
||||
alSourcePlay(source);
|
||||
|
||||
if (alGetError() != AL_NO_ERROR) {
|
||||
/* Print something? */
|
||||
/*fprintf(stderr, "Error starting audio\n");*/
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* Start transmission */
|
||||
while (ASettins.ttas) {
|
||||
|
||||
alcGetIntegerv(ASettins.device[input].dhndl, ALC_CAPTURE_SAMPLES, (int32_t) sizeof(int32_t), &sample);
|
||||
|
||||
/* RECORD AND SEND */
|
||||
if (sample >= AUDIO_FRAME_SIZE) {
|
||||
alcCaptureSamples(ASettins.device[input].dhndl, frame, AUDIO_FRAME_SIZE);
|
||||
|
||||
if (toxav_send_audio(ASettins.av, frame, AUDIO_FRAME_SIZE) < 0)
|
||||
/*fprintf(stderr, "Could not encode or send audio packet\n")*/;
|
||||
|
||||
} else usleep(1000);
|
||||
|
||||
|
||||
|
||||
/* PLAYBACK */
|
||||
|
||||
alGetSourcei(source, AL_BUFFERS_PROCESSED, &ready);
|
||||
|
||||
if (ready <= 0)
|
||||
continue;
|
||||
|
||||
dec_frame_len = toxav_recv_audio(ASettins.av, AUDIO_FRAME_SIZE, PCM);
|
||||
|
||||
/* Play the packet */
|
||||
if (dec_frame_len > 0) {
|
||||
alSourceUnqueueBuffers(source, 1, &buffer);
|
||||
alBufferData(buffer, AL_FORMAT_MONO16, PCM, dec_frame_len * 2 * 1, 48000);
|
||||
int32_t error = alGetError();
|
||||
|
||||
if (error != AL_NO_ERROR) {
|
||||
/*fprintf(stderr, "Error setting buffer %d\n", error);*/
|
||||
break;
|
||||
}
|
||||
|
||||
alSourceQueueBuffers(source, 1, &buffer);
|
||||
|
||||
if (alGetError() != AL_NO_ERROR) {
|
||||
/*fprintf(stderr, "Error: could not buffer audio\n");*/
|
||||
break;
|
||||
}
|
||||
|
||||
alGetSourcei(source, AL_SOURCE_STATE, &ready);
|
||||
|
||||
if (ready != AL_PLAYING) alSourcePlay(source);
|
||||
}
|
||||
|
||||
usleep(1000);
|
||||
}
|
||||
|
||||
cleanup:
|
||||
|
||||
alDeleteSources(1, &source);
|
||||
alDeleteBuffers(openal_buffers, buffers);
|
||||
alcMakeContextCurrent(NULL);
|
||||
|
||||
_cbend;
|
||||
}
|
||||
|
||||
int start_transmission()
|
||||
{
|
||||
if ( !toxav_capability_supported(ASettins.av, AudioDecoding) ||
|
||||
!toxav_capability_supported(ASettins.av, AudioEncoding) )
|
||||
return -1;
|
||||
|
||||
/* Don't provide support for video */
|
||||
toxav_prepare_transmission(ASettins.av, 0);
|
||||
|
||||
if ( 0 != pthread_create(&ASettins.ttid, NULL, transmission, NULL ) &&
|
||||
0 != pthread_detach(ASettins.ttid) ) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int stop_transmission()
|
||||
{
|
||||
ASettins.ttas = 0;
|
||||
}
|
||||
/*
|
||||
* End of transmission
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Callbacks
|
||||
*/
|
||||
|
||||
#define CB_BODY(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], ASettins.av); } while (0)
|
||||
|
||||
void *callback_recv_invite ( void* arg )
|
||||
{
|
||||
CB_BODY(arg, onInvite);
|
||||
_cbend;
|
||||
}
|
||||
void *callback_recv_ringing ( void* arg )
|
||||
{
|
||||
CB_BODY(arg, onRinging);
|
||||
_cbend;
|
||||
}
|
||||
void *callback_recv_starting ( void* arg )
|
||||
{
|
||||
CB_BODY(arg, onStarting);
|
||||
_cbend;
|
||||
}
|
||||
void *callback_recv_ending ( void* arg )
|
||||
{
|
||||
CB_BODY(arg, onEnding);
|
||||
stop_transmission();
|
||||
}
|
||||
void *callback_recv_error ( void* arg )
|
||||
{
|
||||
CB_BODY(arg, onError);
|
||||
_cbend;
|
||||
}
|
||||
void *callback_call_started ( void* arg )
|
||||
{
|
||||
CB_BODY(arg, onStart);
|
||||
_cbend;
|
||||
}
|
||||
void *callback_call_canceled ( void* arg )
|
||||
{
|
||||
CB_BODY(arg, onCancel);
|
||||
_cbend;
|
||||
}
|
||||
void *callback_call_rejected ( void* arg )
|
||||
{
|
||||
CB_BODY(arg, onReject);
|
||||
_cbend;
|
||||
}
|
||||
void *callback_call_ended ( void* arg )
|
||||
{
|
||||
CB_BODY(arg, onEnd);
|
||||
stop_transmission();
|
||||
_cbend;
|
||||
}
|
||||
|
||||
void *callback_requ_timeout ( void* arg )
|
||||
{
|
||||
CB_BODY(arg, onTimeout);
|
||||
_cbend;
|
||||
}
|
||||
|
||||
/*
|
||||
* End of Callbacks
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Commands from chat_commands.h
|
||||
*/
|
||||
void cmd_call(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
||||
{
|
||||
const char* error_str;
|
||||
|
||||
if (argc != 0) { error_str = "Invalid syntax!"; goto on_error; }
|
||||
|
||||
if ( !ASettins.av ) { error_str = "No audio supported!"; goto on_error; }
|
||||
|
||||
ToxAvError error = toxav_call(ASettins.av, self->num, TypeAudio, 30);
|
||||
|
||||
if ( error != ErrorNone ) {
|
||||
if ( error == ErrorAlreadyInCall ) error_str = "Already in a call!";
|
||||
else error_str = "Internal error!";
|
||||
|
||||
goto on_error;
|
||||
}
|
||||
|
||||
wprintw(window, "Calling...\n");
|
||||
|
||||
return;
|
||||
on_error:
|
||||
wprintw(window, "%s %d\n", error_str, argc);
|
||||
}
|
||||
|
||||
void cmd_answer(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
||||
{
|
||||
const char* error_str;
|
||||
|
||||
if (argc != 0) { error_str = "Invalid syntax!"; goto on_error; }
|
||||
|
||||
if ( !ASettins.av ) { error_str = "No audio supported!"; goto on_error; }
|
||||
|
||||
ToxAvError error = toxav_answer(ASettins.av, TypeAudio);
|
||||
|
||||
if ( error != ErrorNone ) {
|
||||
if ( error == ErrorInvalidState ) error_str = "Cannot answer in invalid state!";
|
||||
else if ( error == ErrorNoCall ) error_str = "No incomming call!";
|
||||
else error_str = "Internal error!";
|
||||
|
||||
goto on_error;
|
||||
}
|
||||
|
||||
/* Callback will print status... */
|
||||
|
||||
return;
|
||||
on_error:
|
||||
wprintw(window, "%s\n", error_str);
|
||||
}
|
||||
|
||||
void cmd_hangup(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
||||
{
|
||||
const char* error_str;
|
||||
|
||||
if (argc != 0) { error_str = "Invalid syntax!"; goto on_error; }
|
||||
|
||||
if ( !ASettins.av ) { error_str = "No audio supported!"; goto on_error; }
|
||||
|
||||
ToxAvError error = toxav_hangup(ASettins.av);
|
||||
|
||||
if ( error != ErrorNone ) {
|
||||
if ( error == ErrorInvalidState ) error_str = "Cannot hangup in invalid state!";
|
||||
else if ( error == ErrorNoCall ) error_str = "No call!";
|
||||
else error_str = "Internal error!";
|
||||
|
||||
goto on_error;
|
||||
}
|
||||
|
||||
return;
|
||||
on_error:
|
||||
wprintw(window, "%s\n", error_str);
|
||||
}
|
||||
|
||||
void cmd_cancel(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
||||
{
|
||||
const char* error_str;
|
||||
|
||||
if (argc != 0) { error_str = "Invalid syntax!"; goto on_error; }
|
||||
|
||||
if ( !ASettins.av ) { error_str = "No audio supported!"; goto on_error; }
|
||||
|
||||
ToxAvError error = toxav_hangup(ASettins.av);
|
||||
|
||||
if ( error != ErrorNone ) {
|
||||
if ( error == ErrorNoCall ) error_str = "No call!";
|
||||
else error_str = "Internal error!";
|
||||
|
||||
goto on_error;
|
||||
}
|
||||
|
||||
/* Callback will print status... */
|
||||
|
||||
return;
|
||||
on_error:
|
||||
wprintw(window, "%s\n", error_str);
|
||||
}
|
||||
|
||||
|
||||
void cmd_list_devices(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
||||
{
|
||||
const char* error_str;
|
||||
|
||||
if ( argc != 1 ) {
|
||||
if ( argc < 1 ) error_str = "Type must be specified!";
|
||||
else error_str = "Only one argument allowed!";
|
||||
|
||||
goto on_error;
|
||||
}
|
||||
|
||||
_devices type;
|
||||
|
||||
if ( strcmp(argv[1], "in") == 0 ) /* Input devices */
|
||||
type = input;
|
||||
|
||||
else if ( strcmp(argv[1], "out") == 0 ) /* Output devices */
|
||||
type = output;
|
||||
|
||||
else {
|
||||
wprintw(window, "Invalid type: %s\n", argv[1]);
|
||||
return;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
for ( ; i < ASettins.device[type].size; i ++)
|
||||
wprintw(window, "%d: %s\n", i, ASettins.device[type].devices[i]);
|
||||
|
||||
return;
|
||||
on_error:
|
||||
wprintw(window, "%s\n", error_str);
|
||||
}
|
||||
|
||||
void cmd_change_device(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
||||
{
|
||||
const char* error_str;
|
||||
|
||||
if ( argc != 2 ) {
|
||||
if ( argc < 1 ) error_str = "Type must be specified!";
|
||||
else if ( argc < 2 ) error_str = "Must have id!";
|
||||
else error_str = "Only two arguments allowed!";
|
||||
|
||||
goto on_error;
|
||||
}
|
||||
|
||||
if ( ASettins.ttas ) { /* Transmission is active */
|
||||
error_str = "Cannot change device while active transmission";
|
||||
goto on_error;
|
||||
}
|
||||
|
||||
_devices type;
|
||||
|
||||
if ( strcmp(argv[1], "in") == 0 ) /* Input devices */
|
||||
type = input;
|
||||
|
||||
else if ( strcmp(argv[1], "out") == 0 ) /* Output devices */
|
||||
type = output;
|
||||
|
||||
else {
|
||||
wprintw(window, "Invalid type: %s\n", argv[1]);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
char *end;
|
||||
long int selection = strtol(argv[2], &end, 10);
|
||||
|
||||
if ( *end ) {
|
||||
error_str = "Invalid input";
|
||||
goto on_error;
|
||||
}
|
||||
|
||||
if ( selection < 0 || selection >= ASettins.device[type].size ) {
|
||||
error_str = "No device with such index";
|
||||
goto on_error;
|
||||
}
|
||||
|
||||
/* Close default device */
|
||||
if ( ASettins.device[type].dhndl ) {
|
||||
alcCloseDevice(ASettins.device[type].dhndl);
|
||||
|
||||
if ( ASettins.device[type].ctx) { /* Output device has context with it */
|
||||
alcMakeContextCurrent(NULL);
|
||||
alcDestroyContext(ASettins.device[type].ctx);
|
||||
}
|
||||
}
|
||||
|
||||
/* Open new device */
|
||||
|
||||
if ( type == input ) {
|
||||
ASettins.device[input].dhndl = alcCaptureOpenDevice(
|
||||
ASettins.device[input].devices[selection], AUDIO_SAMPLE_RATE, AL_FORMAT_MONO16, AUDIO_FRAME_SIZE * 4);
|
||||
|
||||
if (alcGetError(ASettins.device[input].dhndl) != AL_NO_ERROR) {
|
||||
error_str = "Error starting input device!";
|
||||
ASettins.errors |= ErrorStartingCaptureDevice;
|
||||
}
|
||||
|
||||
ASettins.device[input].ctx = NULL;
|
||||
|
||||
wprintw(window, "Input device: %s\n", ASettins.device[type].devices[selection]);
|
||||
}
|
||||
else {
|
||||
ASettins.device[output].dhndl = alcOpenDevice(ASettins.device[output].devices[selection]);
|
||||
|
||||
if (alcGetError(ASettins.device[output].dhndl) != AL_NO_ERROR) {
|
||||
error_str = "Error starting output device!";
|
||||
ASettins.errors |= ErrorStartingOutputDevice;
|
||||
}
|
||||
|
||||
ASettins.device[output].ctx = alcCreateContext(ASettins.device[output].dhndl, NULL);
|
||||
|
||||
wprintw(window, "Output device: %s\n", ASettins.device[type].devices[selection]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
return;
|
||||
on_error:
|
||||
wprintw(window, "%s\n", error_str);
|
||||
}
|
30
src/audio_call.h
Normal file
30
src/audio_call.h
Normal file
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Toxic -- Tox Curses Client
|
||||
*/
|
||||
|
||||
#ifndef _audio_h
|
||||
#define _audio_h
|
||||
|
||||
#include <tox/toxav.h>
|
||||
|
||||
typedef struct ToxWindow ToxWindow;
|
||||
|
||||
typedef enum _AudioError
|
||||
{
|
||||
NoError = 0,
|
||||
ErrorStartingCaptureDevice = 1 << 0,
|
||||
ErrorStartingOutputDevice = 1 << 1,
|
||||
ErrorStartingCoreAudio = 1 << 2
|
||||
} AudioError;
|
||||
|
||||
/* You will have to pass pointer to first member of 'windows'
|
||||
* declared in windows.c otherwise undefined behaviour will
|
||||
*/
|
||||
ToxAv* init_audio(ToxWindow* window, Tox* tox);
|
||||
void terminate_audio();
|
||||
|
||||
int errors();
|
||||
|
||||
int start_transmission();
|
||||
|
||||
#endif /* _audio_h */
|
150
src/chat.c
150
src/chat.c
@ -35,13 +35,22 @@
|
||||
#include "toxic_strings.h"
|
||||
#include "log.h"
|
||||
|
||||
#ifdef _SUPPORT_AUDIO
|
||||
#include "audio_call.h"
|
||||
#endif /* _SUPPORT_AUDIO */
|
||||
|
||||
extern char *DATA_FILE;
|
||||
extern int store_data(Tox *m, char *path);
|
||||
|
||||
extern FileSender file_senders[MAX_FILES];
|
||||
extern ToxicFriend friends[MAX_FRIENDS_NUM];
|
||||
|
||||
#define AC_NUM_CHAT_COMMANDS 18
|
||||
|
||||
#ifdef _SUPPORT_AUDIO
|
||||
#define AC_NUM_CHAT_COMMANDS 22
|
||||
#else
|
||||
#define AC_NUM_CHAT_COMMANDS 18
|
||||
#endif /* _SUPPORT_AUDIO */
|
||||
|
||||
/* Array of chat command names used for tab completion. */
|
||||
static const uint8_t chat_cmd_list[AC_NUM_CHAT_COMMANDS][MAX_CMDNAME_SIZE] = {
|
||||
@ -63,6 +72,15 @@ static const uint8_t chat_cmd_list[AC_NUM_CHAT_COMMANDS][MAX_CMDNAME_SIZE] = {
|
||||
{ "/savefile" },
|
||||
{ "/sendfile" },
|
||||
{ "/status" },
|
||||
|
||||
#ifdef _SUPPORT_AUDIO
|
||||
|
||||
{ "/call" },
|
||||
{ "/cancel" },
|
||||
{ "/answer" },
|
||||
{ "/hangup" },
|
||||
|
||||
#endif /* _SUPPORT_AUDIO */
|
||||
};
|
||||
|
||||
static void set_typingstatus(ToxWindow *self, Tox *m, bool is_typing)
|
||||
@ -320,6 +338,123 @@ static void chat_onGroupInvite(ToxWindow *self, Tox *m, int friendnumber, uint8_
|
||||
alert_window(self, WINDOW_ALERT_2, true);
|
||||
}
|
||||
|
||||
/* Av Stuff */
|
||||
#ifdef _SUPPORT_AUDIO
|
||||
|
||||
void chat_onInvite (ToxWindow *self, ToxAv *av)
|
||||
{
|
||||
if (self->num != toxav_get_peer_id(av, 0))
|
||||
return;
|
||||
|
||||
ChatContext *ctx = self->chatwin;
|
||||
|
||||
wprintw(ctx->history, "Incomming audio call!\n"
|
||||
"Answer: \"/answer\" \"/cancel\"\n");
|
||||
|
||||
alert_window(self, WINDOW_ALERT_0, true);
|
||||
}
|
||||
void chat_onRinging (ToxWindow *self, ToxAv *av)
|
||||
{
|
||||
if (self->num != toxav_get_peer_id(av, 0))
|
||||
return;
|
||||
|
||||
ChatContext *ctx = self->chatwin;
|
||||
|
||||
wprintw(ctx->history, "Ringing...\n"
|
||||
"\"/cancel\" ?\n");
|
||||
}
|
||||
void chat_onStarting (ToxWindow *self, ToxAv *av)
|
||||
{
|
||||
if (self->num != toxav_get_peer_id(av, 0))
|
||||
return;
|
||||
|
||||
ChatContext *ctx = self->chatwin;
|
||||
|
||||
if ( 0 != start_transmission() ) {/* YEAH! */
|
||||
wprintw(ctx->history, "Error starting transmission!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
wprintw(ctx->history, "Call started! \n"
|
||||
"Type: \"/hangup\" to end it.\n");
|
||||
|
||||
}
|
||||
void chat_onEnding (ToxWindow *self, ToxAv *av)
|
||||
{
|
||||
if (self->num != toxav_get_peer_id(av, 0))
|
||||
return;
|
||||
|
||||
ChatContext *ctx = self->chatwin;
|
||||
|
||||
toxav_kill_transmission(av);
|
||||
|
||||
wprintw(ctx->history, "Call ended! \n");
|
||||
}
|
||||
void chat_onError (ToxWindow *self, ToxAv *av)
|
||||
{
|
||||
if (self->num != toxav_get_peer_id(av, 0))
|
||||
return;
|
||||
|
||||
ChatContext *ctx = self->chatwin;
|
||||
|
||||
wprintw(ctx->history, "Error! \n");
|
||||
}
|
||||
void chat_onStart (ToxWindow *self, ToxAv *av)
|
||||
{
|
||||
if (self->num != toxav_get_peer_id(av, 0))
|
||||
return;
|
||||
|
||||
ChatContext *ctx = self->chatwin;
|
||||
|
||||
if ( 0 != start_transmission() ) {/* YEAH! */
|
||||
wprintw(ctx->history, "Error starting transmission!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
wprintw(ctx->history, "Call started! \n"
|
||||
"Type: \"/hangup\" to end it.\n");
|
||||
}
|
||||
void chat_onCancel (ToxWindow *self, ToxAv *av)
|
||||
{
|
||||
if (self->num != toxav_get_peer_id(av, 0))
|
||||
return;
|
||||
|
||||
ChatContext *ctx = self->chatwin;
|
||||
|
||||
wprintw(ctx->history, "Call canceled! \n");
|
||||
}
|
||||
void chat_onReject (ToxWindow *self, ToxAv *av)
|
||||
{
|
||||
if (self->num != toxav_get_peer_id(av, 0))
|
||||
return;
|
||||
|
||||
ChatContext *ctx = self->chatwin;
|
||||
|
||||
wprintw(ctx->history, "Rejected! \n");
|
||||
}
|
||||
void chat_onEnd (ToxWindow *self, ToxAv *av)
|
||||
{
|
||||
if (self->num != toxav_get_peer_id(av, 0))
|
||||
return;
|
||||
|
||||
ChatContext *ctx = self->chatwin;
|
||||
|
||||
toxav_kill_transmission(av);
|
||||
|
||||
wprintw(ctx->history, "Call ended! \n");
|
||||
}
|
||||
void chat_onTimeout (ToxWindow *self, ToxAv *av)
|
||||
{
|
||||
if (self->num != toxav_get_peer_id(av, 0))
|
||||
return;
|
||||
|
||||
ChatContext *ctx = self->chatwin;
|
||||
|
||||
wprintw(ctx->history, "No answer! \n");
|
||||
}
|
||||
|
||||
#endif /* _SUPPORT_AUDIO */
|
||||
|
||||
static void send_action(ToxWindow *self, ChatContext *ctx, Tox *m, uint8_t *action) {
|
||||
if (action == NULL) {
|
||||
wprintw(ctx->history, "Invalid syntax.\n");
|
||||
@ -711,6 +846,19 @@ ToxWindow new_chat(Tox *m, int friendnum)
|
||||
ret.onFileControl = &chat_onFileControl;
|
||||
ret.onFileData = &chat_onFileData;
|
||||
|
||||
#ifdef _SUPPORT_AUDIO
|
||||
ret.onInvite = &chat_onInvite;
|
||||
ret.onRinging = &chat_onRinging;
|
||||
ret.onStarting = &chat_onStarting;
|
||||
ret.onEnding = &chat_onEnding;
|
||||
ret.onError = &chat_onError;
|
||||
ret.onStart = &chat_onStart;
|
||||
ret.onCancel = &chat_onCancel;
|
||||
ret.onReject = &chat_onReject;
|
||||
ret.onEnd = &chat_onEnd;
|
||||
ret.onTimeout = &chat_onTimeout;
|
||||
#endif /* _SUPPORT_AUDIO */
|
||||
|
||||
uint8_t name[TOX_MAX_NAME_LENGTH] = {'\0'};
|
||||
uint16_t len = tox_get_name(m, friendnum, name);
|
||||
memcpy(ret.name, name, len);
|
||||
|
@ -52,6 +52,15 @@ void cmd_chat_help(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*arg
|
||||
wprintw(window, "Chat commands:\n");
|
||||
wattroff(window, COLOR_PAIR(CYAN) | A_BOLD);
|
||||
|
||||
#ifdef _SUPPORT_AUDIO
|
||||
|
||||
wprintw(window, " /call : Audio call\n");
|
||||
wprintw(window, " /cancel : Cancel call\n");
|
||||
wprintw(window, " /answer : Answer incomming call\n");
|
||||
wprintw(window, " /hangup : Hangup active call\n");
|
||||
|
||||
#endif /* _SUPPORT_AUDIO */
|
||||
|
||||
wprintw(window, " /invite <n> : Invite friend to a group chat\n");
|
||||
wprintw(window, " /join : Join a pending group chat\n");
|
||||
wprintw(window, " /log <on> or <off> : Enable/disable logging\n");
|
||||
|
@ -25,3 +25,11 @@ void cmd_groupinvite(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_ST
|
||||
void cmd_join_group(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]);
|
||||
void cmd_savefile(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]);
|
||||
void cmd_sendfile(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]);
|
||||
|
||||
|
||||
#ifdef _SUPPORT_AUDIO
|
||||
void cmd_call(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]);
|
||||
void cmd_answer(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]);
|
||||
void cmd_hangup(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]);
|
||||
void cmd_cancel(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]);
|
||||
#endif /* _SUPPORT_AUDIO */
|
||||
|
@ -20,8 +20,13 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "toxic_windows.h"
|
||||
#include "execute.h"
|
||||
@ -48,6 +53,10 @@ static struct cmd_func global_commands[] = {
|
||||
{ "/q", cmd_quit },
|
||||
{ "/quit", cmd_quit },
|
||||
{ "/status", cmd_status },
|
||||
#ifdef _SUPPORT_AUDIO
|
||||
{ "/lsdev", cmd_list_devices },
|
||||
{ "/sdev", cmd_change_device },
|
||||
#endif /* _SUPPORT_AUDIO */
|
||||
};
|
||||
|
||||
static struct cmd_func chat_commands[] = {
|
||||
@ -56,6 +65,13 @@ static struct cmd_func chat_commands[] = {
|
||||
{ "/join", cmd_join_group },
|
||||
{ "/savefile", cmd_savefile },
|
||||
{ "/sendfile", cmd_sendfile },
|
||||
|
||||
#ifdef _SUPPORT_AUDIO
|
||||
{ "/call", cmd_call },
|
||||
{ "/cancel", cmd_cancel },
|
||||
{ "/answer", cmd_answer },
|
||||
{ "/hangup", cmd_hangup },
|
||||
#endif /* _SUPPORT_AUDIO */
|
||||
};
|
||||
|
||||
/* Parses input command and puts args into arg array.
|
||||
|
@ -21,8 +21,14 @@
|
||||
*/
|
||||
|
||||
#define MAX_NUM_ARGS 4 /* Includes command */
|
||||
#define GLOBAL_NUM_COMMANDS 14
|
||||
#define CHAT_NUM_COMMANDS 5
|
||||
|
||||
#ifdef _SUPPORT_AUDIO
|
||||
#define GLOBAL_NUM_COMMANDS 16
|
||||
#define CHAT_NUM_COMMANDS 9
|
||||
#else
|
||||
#define GLOBAL_NUM_COMMANDS 14
|
||||
#define CHAT_NUM_COMMANDS 5
|
||||
#endif /* _SUPPORT_AUDIO */
|
||||
|
||||
enum {
|
||||
GLOBAL_COMMAND_MODE,
|
||||
|
@ -20,6 +20,10 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "chat.h"
|
||||
#include "friendlist.h"
|
||||
#include "misc_tools.h"
|
||||
#include "audio_call.h"
|
||||
|
||||
extern char *DATA_FILE;
|
||||
extern ToxWindow *prompt;
|
||||
@ -467,6 +468,36 @@ static void friendlist_onInit(ToxWindow *self, Tox *m)
|
||||
|
||||
}
|
||||
|
||||
#ifdef _SUPPORT_AUDIO
|
||||
static void friendlist_onAv(ToxWindow *self, ToxAv *av)
|
||||
{
|
||||
int id = toxav_get_peer_id(av, 0);
|
||||
|
||||
if ( id >= max_friends_index)
|
||||
return;
|
||||
|
||||
Tox* m = toxav_get_tox(av);
|
||||
|
||||
if (friends[id].chatwin == -1) {
|
||||
if (get_num_active_windows() < MAX_WINDOWS_NUM) {
|
||||
friends[id].chatwin = add_window(m, new_chat(m, friends[id].num));
|
||||
} else {
|
||||
uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'};
|
||||
tox_get_name(m, id, nick);
|
||||
nick[TOXIC_MAX_NAME_LENGTH] = '\0';
|
||||
wprintw(prompt->window, "Audio action from: %s!\n", nick);
|
||||
|
||||
prep_prompt_win();
|
||||
wattron(prompt->window, COLOR_PAIR(RED));
|
||||
wprintw(prompt->window, "* Warning: Too many windows are open.\n");
|
||||
wattron(prompt->window, COLOR_PAIR(RED));
|
||||
|
||||
alert_window(prompt, WINDOW_ALERT_0, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* _SUPPORT_AUDIO */
|
||||
|
||||
ToxWindow new_friendlist(void)
|
||||
{
|
||||
ToxWindow ret;
|
||||
@ -487,6 +518,19 @@ ToxWindow new_friendlist(void)
|
||||
ret.onFileSendRequest = &friendlist_onFileSendRequest;
|
||||
ret.onGroupInvite = &friendlist_onGroupInvite;
|
||||
|
||||
#ifdef _SUPPORT_AUDIO
|
||||
ret.onInvite = &friendlist_onAv;
|
||||
ret.onRinging = &friendlist_onAv;
|
||||
ret.onStarting = &friendlist_onAv;
|
||||
ret.onEnding = &friendlist_onAv;
|
||||
ret.onError = &friendlist_onAv;
|
||||
ret.onStart = &friendlist_onAv;
|
||||
ret.onCancel = &friendlist_onAv;
|
||||
ret.onReject = &friendlist_onAv;
|
||||
ret.onEnd = &friendlist_onAv;
|
||||
ret.onTimeout = &friendlist_onAv;
|
||||
#endif /* _SUPPORT_AUDIO */
|
||||
|
||||
strcpy(ret.name, "friends");
|
||||
return ret;
|
||||
}
|
||||
|
@ -378,6 +378,11 @@ void cmd_prompt_help(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*a
|
||||
wprintw(window, " /clear : Clear the window\n");
|
||||
wprintw(window, " /quit or /exit : Exit Toxic\n");
|
||||
|
||||
#ifdef _SUPPORT_AUDIO
|
||||
wprintw(window, " /lsdev <type> : List devices where type: in|out\n");
|
||||
wprintw(window, " /sdev <type> <id> : Set active device\n");
|
||||
#endif /* _SUPPORT_AUDIO */
|
||||
|
||||
wattron(window, COLOR_PAIR(CYAN) | A_BOLD);
|
||||
wprintw(window, " * Argument messages must be enclosed in quotation marks.\n");
|
||||
wprintw(window, " * Use ctrl-o and ctrl-p to navigate through the tabs.\n\n");
|
||||
|
@ -32,3 +32,8 @@ void cmd_note(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]
|
||||
void cmd_prompt_help(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]);
|
||||
void cmd_quit(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]);
|
||||
void cmd_status(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]);
|
||||
|
||||
#ifdef _SUPPORT_AUDIO
|
||||
void cmd_list_devices(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]);
|
||||
void cmd_change_device(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]);
|
||||
#endif /* _SUPPORT_AUDIO */
|
@ -43,7 +43,7 @@ static GroupChat groupchats[MAX_WINDOWS_NUM];
|
||||
static int max_groupchat_index = 0;
|
||||
|
||||
/* temporary until group chats have unique commands */
|
||||
extern glob_cmd_list[AC_NUM_GLOB_COMMANDS][MAX_CMDNAME_SIZE];
|
||||
extern const uint8_t glob_cmd_list[AC_NUM_GLOB_COMMANDS][MAX_CMDNAME_SIZE];
|
||||
|
||||
int init_groupchat_win(ToxWindow *prompt, Tox *m, int groupnum)
|
||||
{
|
||||
|
@ -20,6 +20,10 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
28
src/main.c
28
src/main.c
@ -48,6 +48,7 @@
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <tox/tox.h>
|
||||
@ -59,10 +60,18 @@
|
||||
#include "misc_tools.h"
|
||||
#include "file_senders.h"
|
||||
|
||||
#ifdef _SUPPORT_AUDIO
|
||||
#include "audio_call.h"
|
||||
#endif /* _SUPPORT_AUDIO */
|
||||
|
||||
#ifndef PACKAGE_DATADIR
|
||||
#define PACKAGE_DATADIR "."
|
||||
#endif
|
||||
|
||||
#ifdef _SUPPORT_AUDIO
|
||||
ToxAv* av;
|
||||
#endif /* _SUPPORT_AUDIO */
|
||||
|
||||
/* Export for use in Callbacks */
|
||||
char *DATA_FILE = NULL;
|
||||
ToxWindow *prompt = NULL;
|
||||
@ -400,6 +409,9 @@ void exit_toxic(Tox *m)
|
||||
free(prompt->promptbuf->log);
|
||||
free(prompt->promptbuf);
|
||||
tox_kill(m);
|
||||
#ifdef _SUPPORT_AUDIO
|
||||
terminate_audio(prompt, av);
|
||||
#endif /* _SUPPORT_AUDIO */
|
||||
endwin();
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
@ -475,6 +487,22 @@ int main(int argc, char *argv[])
|
||||
|
||||
prompt = init_windows(m);
|
||||
|
||||
#ifdef _SUPPORT_AUDIO
|
||||
|
||||
attron(COLOR_PAIR(RED) | A_BOLD);
|
||||
wprintw(prompt->window, "Starting audio...\n");
|
||||
attroff(COLOR_PAIR(RED) | A_BOLD);
|
||||
|
||||
av = init_audio(prompt, m);
|
||||
|
||||
if ( errors() == NoError )
|
||||
wprintw(prompt->window, "Audio started with no problems.\n");
|
||||
else /* Get error code and stuff */
|
||||
wprintw(prompt->window, "Error starting audio!\n");
|
||||
|
||||
|
||||
#endif /* _SUPPORT_AUDIO */
|
||||
|
||||
if (f_loadfromfile)
|
||||
load_data(m, DATA_FILE);
|
||||
|
||||
|
@ -20,6 +20,10 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
@ -54,6 +54,13 @@ const uint8_t glob_cmd_list[AC_NUM_GLOB_COMMANDS][MAX_CMDNAME_SIZE] = {
|
||||
{ "/note" },
|
||||
{ "/quit" },
|
||||
{ "/status" },
|
||||
|
||||
#ifdef _SUPPORT_AUDIO
|
||||
|
||||
{ "/lsdev" },
|
||||
{ "/sdev" },
|
||||
|
||||
#endif /* _SUPPORT_AUDIO */
|
||||
};
|
||||
|
||||
/* prevents input string from eating system messages: call this prior to printing a prompt message
|
||||
|
@ -25,7 +25,12 @@
|
||||
|
||||
#define X_OFST 2 /* offset to account for prompt char */
|
||||
|
||||
#define AC_NUM_GLOB_COMMANDS 15
|
||||
|
||||
#ifdef _SUPPORT_AUDIO
|
||||
#define AC_NUM_GLOB_COMMANDS 17
|
||||
#else
|
||||
#define AC_NUM_GLOB_COMMANDS 15
|
||||
#endif /* _SUPPORT_AUDIO */
|
||||
|
||||
ToxWindow new_prompt(void);
|
||||
void prep_prompt_win(void);
|
||||
|
@ -20,6 +20,10 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
|
@ -33,7 +33,11 @@
|
||||
|
||||
#include <tox/tox.h>
|
||||
|
||||
#define UNKNOWN_NAME "Unknown"
|
||||
#ifdef _SUPPORT_AUDIO
|
||||
#include <tox/toxav.h>
|
||||
#endif /* _SUPPORT_AUDIO */
|
||||
|
||||
#define UNKNOWN_NAME "John Doe"
|
||||
|
||||
#define MAX_WINDOWS_NUM 32
|
||||
#define MAX_FRIENDS_NUM 100
|
||||
@ -106,6 +110,21 @@ struct ToxWindow {
|
||||
void(*onFileData)(ToxWindow *, Tox *, int, uint8_t, uint8_t *, uint16_t);
|
||||
void(*onTypingChange)(ToxWindow *, Tox *, int, int);
|
||||
|
||||
#ifdef _SUPPORT_AUDIO
|
||||
|
||||
void(*onInvite)(ToxWindow *, ToxAv *);
|
||||
void(*onRinging)(ToxWindow *, ToxAv *);
|
||||
void(*onStarting)(ToxWindow *, ToxAv *);
|
||||
void(*onEnding)(ToxWindow *, ToxAv *);
|
||||
void(*onError)(ToxWindow *, ToxAv *);
|
||||
void(*onStart)(ToxWindow *, ToxAv *);
|
||||
void(*onCancel)(ToxWindow *, ToxAv *);
|
||||
void(*onReject)(ToxWindow *, ToxAv *);
|
||||
void(*onEnd)(ToxWindow *, ToxAv *);
|
||||
void(*onTimeout)(ToxWindow *, ToxAv *);
|
||||
|
||||
#endif /* _SUPPORT_AUDIO */
|
||||
|
||||
char name[TOX_MAX_NAME_LENGTH];
|
||||
int num;
|
||||
bool active;
|
||||
|
Loading…
Reference in New Issue
Block a user