mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-23 05:53:02 +01:00
group audio stuff
This commit is contained in:
parent
424189cad9
commit
7865cea284
@ -98,8 +98,6 @@ void callback_peer_timeout ( void* av, int32_t call_index, void *arg );
|
|||||||
void callback_media_change ( void* av, int32_t call_index, void *arg );
|
void callback_media_change ( void* av, int32_t call_index, void *arg );
|
||||||
|
|
||||||
void write_device_callback( void* agent, int32_t call_index, const int16_t* PCM, uint16_t size, void* arg );
|
void write_device_callback( void* agent, int32_t call_index, const int16_t* PCM, uint16_t size, void* arg );
|
||||||
void write_device_callback_group( Tox *m, int groupnum, int peernum, const int16_t *pcm, unsigned int samples,
|
|
||||||
uint8_t channels, unsigned int sample_rate, void *arg );
|
|
||||||
|
|
||||||
static void print_err (ToxWindow *self, const char *error_str)
|
static void print_err (ToxWindow *self, const char *error_str)
|
||||||
{
|
{
|
||||||
@ -331,19 +329,6 @@ void callback_peer_timeout ( void* av, int32_t call_index, void* arg )
|
|||||||
*/
|
*/
|
||||||
toxav_stop_call(ASettins.av, call_index);
|
toxav_stop_call(ASettins.av, call_index);
|
||||||
}
|
}
|
||||||
void write_device_callback_group(Tox *m, int groupnum, int peernum, const int16_t *pcm, unsigned int samples,
|
|
||||||
uint8_t channels, unsigned int sample_rate, void *arg)
|
|
||||||
{
|
|
||||||
return; /* TODO: fix this stuff */
|
|
||||||
|
|
||||||
ToxWindow *windows = arg;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
|
||||||
if (windows[i].onWriteDevice != NULL)
|
|
||||||
windows[i].onWriteDevice(&windows[i], m, groupnum, peernum, pcm, samples, channels, samples);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// void callback_media_change(void* av, int32_t call_index, void* arg)
|
// void callback_media_change(void* av, int32_t call_index, void* arg)
|
||||||
// {
|
// {
|
||||||
|
@ -47,6 +47,5 @@ void terminate_audio();
|
|||||||
int start_transmission(ToxWindow *self, Call *call);
|
int start_transmission(ToxWindow *self, Call *call);
|
||||||
int stop_transmission(Call *call, int call_index);
|
int stop_transmission(Call *call, int call_index);
|
||||||
void stop_current_call(ToxWindow *self);
|
void stop_current_call(ToxWindow *self);
|
||||||
void write_device_callback_group(Tox *m, int groupnum, int peernum, const int16_t *pcm, unsigned int samples,
|
|
||||||
uint8_t channels, unsigned int sample_rate, void *arg);
|
|
||||||
#endif /* AUDIO_H */
|
#endif /* AUDIO_H */
|
||||||
|
@ -33,10 +33,6 @@
|
|||||||
#include "chat.h"
|
#include "chat.h"
|
||||||
#include "file_senders.h"
|
#include "file_senders.h"
|
||||||
|
|
||||||
#ifdef AUDIO
|
|
||||||
#include "audio_call.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
extern ToxWindow *prompt;
|
extern ToxWindow *prompt;
|
||||||
extern FriendsList Friends;
|
extern FriendsList Friends;
|
||||||
|
|
||||||
@ -143,7 +139,7 @@ void cmd_join_group(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*ar
|
|||||||
#ifdef AUDIO
|
#ifdef AUDIO
|
||||||
else
|
else
|
||||||
groupnum = toxav_join_av_groupchat(m, self->num, (uint8_t *) groupkey, length,
|
groupnum = toxav_join_av_groupchat(m, self->num, (uint8_t *) groupkey, length,
|
||||||
write_device_callback_group, self);
|
write_device_callback_group, NULL);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (groupnum == -1) {
|
if (groupnum == -1) {
|
||||||
|
@ -35,10 +35,6 @@
|
|||||||
#include "prompt.h"
|
#include "prompt.h"
|
||||||
#include "help.h"
|
#include "help.h"
|
||||||
|
|
||||||
#ifdef AUDIO
|
|
||||||
#include "audio_call.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
extern char *DATA_FILE;
|
extern char *DATA_FILE;
|
||||||
extern ToxWindow *prompt;
|
extern ToxWindow *prompt;
|
||||||
extern FriendsList Friends;
|
extern FriendsList Friends;
|
||||||
@ -351,7 +347,7 @@ void cmd_groupchat(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*arg
|
|||||||
groupnum = tox_add_groupchat(m);
|
groupnum = tox_add_groupchat(m);
|
||||||
#ifdef AUDIO
|
#ifdef AUDIO
|
||||||
else
|
else
|
||||||
groupnum = toxav_add_av_groupchat(m, write_device_callback_group, self);
|
groupnum = toxav_add_av_groupchat(m, write_device_callback_group, NULL);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (groupnum == -1) {
|
if (groupnum == -1) {
|
||||||
|
@ -107,8 +107,6 @@ static const char group_cmd_list[AC_NUM_GROUP_COMMANDS][MAX_CMDNAME_SIZE] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
#ifdef AUDIO
|
#ifdef AUDIO
|
||||||
static void group_audio_add_source(int groupnum, int peernum);
|
|
||||||
static void group_audio_rm_source(int groupnum, int peernum);
|
|
||||||
static int group_audio_open_out_device(int groupnum);
|
static int group_audio_open_out_device(int groupnum);
|
||||||
static int group_audio_close_out_device(int groupnum);
|
static int group_audio_close_out_device(int groupnum);
|
||||||
#endif /* AUDIO */
|
#endif /* AUDIO */
|
||||||
@ -143,7 +141,8 @@ int init_groupchat_win(ToxWindow *prompt, Tox *m, int groupnum, uint8_t type)
|
|||||||
|
|
||||||
#ifdef AUDIO
|
#ifdef AUDIO
|
||||||
if (type == TOX_GROUPCHAT_TYPE_AV)
|
if (type == TOX_GROUPCHAT_TYPE_AV)
|
||||||
group_audio_open_out_device(i);
|
if (group_audio_open_out_device(i) == -1)
|
||||||
|
fprintf(stderr, "Group Audio failed to init\n");
|
||||||
#endif /* AUDIO */
|
#endif /* AUDIO */
|
||||||
|
|
||||||
set_active_window(groupchats[i].chatwin);
|
set_active_window(groupchats[i].chatwin);
|
||||||
@ -473,11 +472,6 @@ static void groupchat_onGroupNamelistChange(ToxWindow *self, Tox *m, int groupnu
|
|||||||
|
|
||||||
switch (change) {
|
switch (change) {
|
||||||
case TOX_CHAT_CHANGE_PEER_ADD:
|
case TOX_CHAT_CHANGE_PEER_ADD:
|
||||||
#ifdef AUDIO
|
|
||||||
if (groupchats[groupnum].type == TOX_GROUPCHAT_TYPE_AV)
|
|
||||||
group_audio_add_source(groupnum, peernum);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!timed_out(groupchats[groupnum].start_time, get_unix_time(), GROUP_EVENT_WAIT))
|
if (!timed_out(groupchats[groupnum].start_time, get_unix_time(), GROUP_EVENT_WAIT))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -508,11 +502,6 @@ static void groupchat_onGroupNamelistChange(ToxWindow *self, Tox *m, int groupnu
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case TOX_CHAT_CHANGE_PEER_DEL:
|
case TOX_CHAT_CHANGE_PEER_DEL:
|
||||||
#ifdef AUDIO
|
|
||||||
if (groupchats[groupnum].type == TOX_GROUPCHAT_TYPE_AV)
|
|
||||||
group_audio_rm_source(groupnum, peernum);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
event = "has left the room";
|
event = "has left the room";
|
||||||
line_info_add(self, timefrmt, (char *) oldpeername, NULL, CONNECTION, 0, RED, event);
|
line_info_add(self, timefrmt, (char *) oldpeername, NULL, CONNECTION, 0, RED, event);
|
||||||
|
|
||||||
@ -742,17 +731,6 @@ static void groupchat_onInit(ToxWindow *self, Tox *m)
|
|||||||
|
|
||||||
|
|
||||||
#ifdef AUDIO
|
#ifdef AUDIO
|
||||||
static void group_audio_add_source(int groupnum, int peernum)
|
|
||||||
{
|
|
||||||
alGenSources((uint32_t) 1, &groupchats[groupnum].audio.sources[peernum]);
|
|
||||||
alSourcei(groupchats[groupnum].audio.sources[peernum], AL_LOOPING, AL_FALSE);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void group_audio_rm_source(int groupnum, int peernum)
|
|
||||||
{
|
|
||||||
alDeleteSources((uint32_t) 1, &groupchats[groupnum].audio.sources[peernum]);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int group_audio_open_out_device(int groupnum)
|
static int group_audio_open_out_device(int groupnum)
|
||||||
{
|
{
|
||||||
char dname[MAX_STR_SIZE];
|
char dname[MAX_STR_SIZE];
|
||||||
@ -765,9 +743,20 @@ static int group_audio_open_out_device(int groupnum)
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
groupchats[groupnum].audio.dvctx = alcCreateContext(groupchats[groupnum].audio.dvhandle, NULL);
|
groupchats[groupnum].audio.dvctx = alcCreateContext(groupchats[groupnum].audio.dvhandle, NULL);
|
||||||
|
alcMakeContextCurrent(groupchats[groupnum].audio.dvctx);
|
||||||
|
alGenBuffers(OPENAL_BUFS, groupchats[groupnum].audio.buffers);
|
||||||
|
alGenSources((uint32_t) 1, &groupchats[groupnum].audio.source);
|
||||||
|
alSourcei(groupchats[groupnum].audio.source, AL_LOOPING, AL_FALSE);
|
||||||
|
|
||||||
if (!alcMakeContextCurrent(groupchats[groupnum].audio.dvctx))
|
if (alcGetError(groupchats[groupnum].audio.dvhandle) != AL_NO_ERROR) {
|
||||||
|
group_audio_close_out_device(groupnum);
|
||||||
|
groupchats[groupnum].audio.dvhandle = NULL;
|
||||||
|
groupchats[groupnum].audio.dvctx = NULL;
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
alSourceQueueBuffers(groupchats[groupnum].audio.source, OPENAL_BUFS, groupchats[groupnum].audio.buffers);
|
||||||
|
alSourcePlay(groupchats[groupnum].audio.source);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -783,11 +772,7 @@ static int group_audio_close_out_device(int groupnum)
|
|||||||
if (alcGetCurrentContext() != groupchats[groupnum].audio.dvctx)
|
if (alcGetCurrentContext() != groupchats[groupnum].audio.dvctx)
|
||||||
alcMakeContextCurrent(groupchats[groupnum].audio.dvctx);
|
alcMakeContextCurrent(groupchats[groupnum].audio.dvctx);
|
||||||
|
|
||||||
int i;
|
alDeleteSources((uint32_t) 1, &groupchats[groupnum].audio.source);
|
||||||
int n = MIN(MAX_AUDIO_SOURCES, groupchats[groupnum].num_peers);
|
|
||||||
|
|
||||||
for (i = 0; i < n; ++i)
|
|
||||||
group_audio_rm_source(groupnum, i);
|
|
||||||
|
|
||||||
alcMakeContextCurrent(NULL);
|
alcMakeContextCurrent(NULL);
|
||||||
alcDestroyContext(groupchats[groupnum].audio.dvctx);
|
alcDestroyContext(groupchats[groupnum].audio.dvctx);
|
||||||
@ -807,18 +792,17 @@ static int group_audio_write(int peernum, int groupnum, const int16_t *pcm, unsi
|
|||||||
if (channels == 0 || channels > 2)
|
if (channels == 0 || channels > 2)
|
||||||
return -2;
|
return -2;
|
||||||
|
|
||||||
ALuint source = groupchats[groupnum].audio.sources[peernum];
|
|
||||||
ALuint bufid;
|
ALuint bufid;
|
||||||
ALint processed = 0;
|
ALint processed = 0, queued = 16;
|
||||||
ALint queued = 0;
|
|
||||||
|
|
||||||
alGetSourcei(source, AL_BUFFERS_PROCESSED, &processed);
|
alGetSourcei(groupchats[groupnum].audio.source, AL_BUFFERS_PROCESSED, &processed);
|
||||||
alGetSourcei(source, AL_BUFFERS_QUEUED, &queued);
|
alGetSourcei(groupchats[groupnum].audio.source, AL_BUFFERS_QUEUED, &queued);
|
||||||
fprintf(stderr, "%d, %d\n", source, processed);
|
alSourcei(groupchats[groupnum].audio.source, AL_LOOPING, AL_FALSE);
|
||||||
|
fprintf(stderr, "source: %d, queued: %d, processed: %d\n", groupchats[groupnum].audio.source, queued, processed);
|
||||||
|
|
||||||
if (processed) {
|
if (processed) {
|
||||||
ALuint bufids[processed];
|
ALuint bufids[processed];
|
||||||
alSourceUnqueueBuffers(source, processed, bufids);
|
alSourceUnqueueBuffers(groupchats[groupnum].audio.source, processed, bufids);
|
||||||
alDeleteBuffers(processed - 1, bufids + 1);
|
alDeleteBuffers(processed - 1, bufids + 1);
|
||||||
bufid = bufids[0];
|
bufid = bufids[0];
|
||||||
} else if (queued < 16) {
|
} else if (queued < 16) {
|
||||||
@ -830,13 +814,13 @@ static int group_audio_write(int peernum, int groupnum, const int16_t *pcm, unsi
|
|||||||
int length = samples * channels * sizeof(int16_t);
|
int length = samples * channels * sizeof(int16_t);
|
||||||
|
|
||||||
alBufferData(bufid, (channels == 1) ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16, pcm, length, sample_rate);
|
alBufferData(bufid, (channels == 1) ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16, pcm, length, sample_rate);
|
||||||
alSourceQueueBuffers(source, 1, &bufid);
|
alSourceQueueBuffers(groupchats[groupnum].audio.source, 1, &bufid);
|
||||||
|
|
||||||
ALint state;
|
ALint state;
|
||||||
alGetSourcei(source, AL_SOURCE_STATE, &state);
|
alGetSourcei(groupchats[groupnum].audio.source, AL_SOURCE_STATE, &state);
|
||||||
|
|
||||||
if (state != AL_PLAYING)
|
if (state != AL_PLAYING)
|
||||||
alSourcePlay(source);
|
alSourcePlay(groupchats[groupnum].audio.source);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -847,10 +831,7 @@ static void groupchat_onWriteDevice(ToxWindow *self, Tox *m, int groupnum, int p
|
|||||||
if (groupnum != self->num)
|
if (groupnum != self->num)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (peernum < 0 || peernum >= MAX_AUDIO_SOURCES)
|
if (peernum < 0)
|
||||||
return;
|
|
||||||
|
|
||||||
if (groupchats[groupnum].audio.muted[peernum])
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (groupchats[groupnum].audio.dvhandle == NULL)
|
if (groupchats[groupnum].audio.dvhandle == NULL)
|
||||||
@ -859,7 +840,8 @@ static void groupchat_onWriteDevice(ToxWindow *self, Tox *m, int groupnum, int p
|
|||||||
if (groupchats[groupnum].audio.dvctx == NULL)
|
if (groupchats[groupnum].audio.dvctx == NULL)
|
||||||
fprintf(stderr, "ctx is null\n");
|
fprintf(stderr, "ctx is null\n");
|
||||||
|
|
||||||
group_audio_write(peernum, groupnum, pcm, samples, channels, sample_rate);
|
int ret = group_audio_write(peernum, groupnum, pcm, samples, channels, sample_rate);
|
||||||
|
fprintf(stderr, "write: %d\n", ret);
|
||||||
}
|
}
|
||||||
#endif /* AUDIO */
|
#endif /* AUDIO */
|
||||||
|
|
||||||
|
@ -50,13 +50,11 @@
|
|||||||
#define GROUP_EVENT_WAIT 3
|
#define GROUP_EVENT_WAIT 3
|
||||||
|
|
||||||
#ifdef AUDIO
|
#ifdef AUDIO
|
||||||
#define MAX_AUDIO_SOURCES 128 /* arbitrary limit */
|
|
||||||
|
|
||||||
struct GAudio {
|
struct GAudio {
|
||||||
ALCdevice *dvhandle; /* Handle of device selected/opened */
|
ALCdevice *dvhandle; /* Handle of device selected/opened */
|
||||||
ALCcontext *dvctx;
|
ALCcontext *dvctx;
|
||||||
ALuint sources[MAX_AUDIO_SOURCES]; /* one audio source per peer */
|
ALuint source;
|
||||||
uint8_t muted[MAX_AUDIO_SOURCES];
|
ALuint buffers[OPENAL_BUFS];
|
||||||
};
|
};
|
||||||
#endif /* AUDIO */
|
#endif /* AUDIO */
|
||||||
|
|
||||||
|
@ -116,4 +116,9 @@ void on_file_data(Tox *m, int32_t friendnumber, uint8_t filenumber, const uint8_
|
|||||||
void on_typing_change(Tox *m, int32_t friendnumber, uint8_t is_typing, void *userdata);
|
void on_typing_change(Tox *m, int32_t friendnumber, uint8_t is_typing, void *userdata);
|
||||||
void on_read_receipt(Tox *m, int32_t, uint32_t, void *userdata);
|
void on_read_receipt(Tox *m, int32_t, uint32_t, void *userdata);
|
||||||
|
|
||||||
|
#ifdef AUDIO
|
||||||
|
void write_device_callback_group(Tox *m, int groupnum, int peernum, const int16_t *pcm, unsigned int samples,
|
||||||
|
uint8_t channels, unsigned int sample_rate, void *arg);
|
||||||
|
#endif /* AUDIO */
|
||||||
|
|
||||||
#endif /* #define TOXIC_H */
|
#endif /* #define TOXIC_H */
|
||||||
|
@ -54,10 +54,11 @@ void on_request(Tox *m, const uint8_t *public_key, const uint8_t *data, uint16_t
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
||||||
if (windows[i].onFriendRequest != NULL)
|
if (windows[i].onFriendRequest != NULL) {
|
||||||
windows[i].onFriendRequest(&windows[i], m, (const char *) public_key, msg, length);
|
windows[i].onFriendRequest(&windows[i], m, (const char *) public_key, msg, length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void on_connectionchange(Tox *m, int32_t friendnumber, uint8_t status, void *userdata)
|
void on_connectionchange(Tox *m, int32_t friendnumber, uint8_t status, void *userdata)
|
||||||
{
|
{
|
||||||
@ -268,6 +269,19 @@ void on_read_receipt(Tox *m, int32_t friendnumber, uint32_t receipt, void *userd
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef AUDIO
|
||||||
|
void write_device_callback_group(Tox *m, int groupnum, int peernum, const int16_t *pcm, unsigned int samples,
|
||||||
|
uint8_t channels, unsigned int sample_rate, void *arg)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
||||||
|
if (windows[i].onWriteDevice != NULL)
|
||||||
|
windows[i].onWriteDevice(&windows[i], m, groupnum, peernum, pcm, samples, channels, samples);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif /* AUDIO */
|
||||||
|
|
||||||
/* CALLBACKS END */
|
/* CALLBACKS END */
|
||||||
|
|
||||||
int add_window(Tox *m, ToxWindow w)
|
int add_window(Tox *m, ToxWindow w)
|
||||||
|
Loading…
Reference in New Issue
Block a user