mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-23 01:43:01 +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 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)
|
||||
{
|
||||
@ -331,19 +329,6 @@ void callback_peer_timeout ( void* av, int32_t call_index, void* arg )
|
||||
*/
|
||||
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)
|
||||
// {
|
||||
|
@ -47,6 +47,5 @@ void terminate_audio();
|
||||
int start_transmission(ToxWindow *self, Call *call);
|
||||
int stop_transmission(Call *call, int call_index);
|
||||
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 */
|
||||
|
@ -33,10 +33,6 @@
|
||||
#include "chat.h"
|
||||
#include "file_senders.h"
|
||||
|
||||
#ifdef AUDIO
|
||||
#include "audio_call.h"
|
||||
#endif
|
||||
|
||||
extern ToxWindow *prompt;
|
||||
extern FriendsList Friends;
|
||||
|
||||
@ -143,7 +139,7 @@ void cmd_join_group(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*ar
|
||||
#ifdef AUDIO
|
||||
else
|
||||
groupnum = toxav_join_av_groupchat(m, self->num, (uint8_t *) groupkey, length,
|
||||
write_device_callback_group, self);
|
||||
write_device_callback_group, NULL);
|
||||
#endif
|
||||
|
||||
if (groupnum == -1) {
|
||||
|
12
src/device.c
12
src/device.c
@ -343,21 +343,21 @@ DeviceError register_device_callback( int32_t call_idx, uint32_t device_idx, Dat
|
||||
{
|
||||
if (size[input] <= device_idx || !running[input][device_idx] || running[input][device_idx]->dhndl == NULL)
|
||||
return de_InvalidSelection;
|
||||
|
||||
|
||||
lock;
|
||||
running[input][device_idx]->cb = callback;
|
||||
running[input][device_idx]->cb_data = data;
|
||||
running[input][device_idx]->enable_VAD = enable_VAD;
|
||||
running[input][device_idx]->call_idx = call_idx;
|
||||
unlock;
|
||||
|
||||
|
||||
return de_None;
|
||||
}
|
||||
|
||||
inline__ DeviceError write_out(uint32_t device_idx, const int16_t* data, uint32_t length, uint8_t channels)
|
||||
{
|
||||
if (device_idx >= MAX_DEVICES) return de_InvalidSelection;
|
||||
|
||||
|
||||
Device* device = running[output][device_idx];
|
||||
|
||||
if (!device || device->muted) return de_DeviceNotActive;
|
||||
@ -369,7 +369,7 @@ inline__ DeviceError write_out(uint32_t device_idx, const int16_t* data, uint32_
|
||||
ALint processed, queued;
|
||||
alGetSourcei(device->source, AL_BUFFERS_PROCESSED, &processed);
|
||||
alGetSourcei(device->source, AL_BUFFERS_QUEUED, &queued);
|
||||
|
||||
|
||||
if(processed) {
|
||||
ALuint bufids[processed];
|
||||
alSourceUnqueueBuffers(device->source, processed, bufids);
|
||||
@ -381,8 +381,8 @@ inline__ DeviceError write_out(uint32_t device_idx, const int16_t* data, uint32_
|
||||
pthread_mutex_unlock(device->mutex);
|
||||
return de_Busy;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
alBufferData(bufid, device->sound_mode, data, length * 2 * channels, device->sample_rate);
|
||||
alSourceQueueBuffers(device->source, 1, &bufid);
|
||||
|
||||
|
@ -35,10 +35,6 @@
|
||||
#include "prompt.h"
|
||||
#include "help.h"
|
||||
|
||||
#ifdef AUDIO
|
||||
#include "audio_call.h"
|
||||
#endif
|
||||
|
||||
extern char *DATA_FILE;
|
||||
extern ToxWindow *prompt;
|
||||
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);
|
||||
#ifdef AUDIO
|
||||
else
|
||||
groupnum = toxav_add_av_groupchat(m, write_device_callback_group, self);
|
||||
groupnum = toxav_add_av_groupchat(m, write_device_callback_group, NULL);
|
||||
#endif
|
||||
|
||||
if (groupnum == -1) {
|
||||
|
@ -107,8 +107,6 @@ static const char group_cmd_list[AC_NUM_GROUP_COMMANDS][MAX_CMDNAME_SIZE] = {
|
||||
};
|
||||
|
||||
#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_close_out_device(int groupnum);
|
||||
#endif /* AUDIO */
|
||||
@ -143,7 +141,8 @@ int init_groupchat_win(ToxWindow *prompt, Tox *m, int groupnum, uint8_t type)
|
||||
|
||||
#ifdef AUDIO
|
||||
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 */
|
||||
|
||||
set_active_window(groupchats[i].chatwin);
|
||||
@ -473,11 +472,6 @@ static void groupchat_onGroupNamelistChange(ToxWindow *self, Tox *m, int groupnu
|
||||
|
||||
switch (change) {
|
||||
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))
|
||||
break;
|
||||
|
||||
@ -508,11 +502,6 @@ static void groupchat_onGroupNamelistChange(ToxWindow *self, Tox *m, int groupnu
|
||||
break;
|
||||
|
||||
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";
|
||||
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
|
||||
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)
|
||||
{
|
||||
char dname[MAX_STR_SIZE];
|
||||
@ -765,9 +743,20 @@ static int group_audio_open_out_device(int groupnum)
|
||||
return -1;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
alSourceQueueBuffers(groupchats[groupnum].audio.source, OPENAL_BUFS, groupchats[groupnum].audio.buffers);
|
||||
alSourcePlay(groupchats[groupnum].audio.source);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -783,11 +772,7 @@ static int group_audio_close_out_device(int groupnum)
|
||||
if (alcGetCurrentContext() != groupchats[groupnum].audio.dvctx)
|
||||
alcMakeContextCurrent(groupchats[groupnum].audio.dvctx);
|
||||
|
||||
int i;
|
||||
int n = MIN(MAX_AUDIO_SOURCES, groupchats[groupnum].num_peers);
|
||||
|
||||
for (i = 0; i < n; ++i)
|
||||
group_audio_rm_source(groupnum, i);
|
||||
alDeleteSources((uint32_t) 1, &groupchats[groupnum].audio.source);
|
||||
|
||||
alcMakeContextCurrent(NULL);
|
||||
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)
|
||||
return -2;
|
||||
|
||||
ALuint source = groupchats[groupnum].audio.sources[peernum];
|
||||
ALuint bufid;
|
||||
ALint processed = 0;
|
||||
ALint queued = 0;
|
||||
ALint processed = 0, queued = 16;
|
||||
|
||||
alGetSourcei(source, AL_BUFFERS_PROCESSED, &processed);
|
||||
alGetSourcei(source, AL_BUFFERS_QUEUED, &queued);
|
||||
fprintf(stderr, "%d, %d\n", source, processed);
|
||||
alGetSourcei(groupchats[groupnum].audio.source, AL_BUFFERS_PROCESSED, &processed);
|
||||
alGetSourcei(groupchats[groupnum].audio.source, AL_BUFFERS_QUEUED, &queued);
|
||||
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) {
|
||||
ALuint bufids[processed];
|
||||
alSourceUnqueueBuffers(source, processed, bufids);
|
||||
alSourceUnqueueBuffers(groupchats[groupnum].audio.source, processed, bufids);
|
||||
alDeleteBuffers(processed - 1, bufids + 1);
|
||||
bufid = bufids[0];
|
||||
} 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);
|
||||
|
||||
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;
|
||||
alGetSourcei(source, AL_SOURCE_STATE, &state);
|
||||
alGetSourcei(groupchats[groupnum].audio.source, AL_SOURCE_STATE, &state);
|
||||
|
||||
if (state != AL_PLAYING)
|
||||
alSourcePlay(source);
|
||||
alSourcePlay(groupchats[groupnum].audio.source);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -847,10 +831,7 @@ static void groupchat_onWriteDevice(ToxWindow *self, Tox *m, int groupnum, int p
|
||||
if (groupnum != self->num)
|
||||
return;
|
||||
|
||||
if (peernum < 0 || peernum >= MAX_AUDIO_SOURCES)
|
||||
return;
|
||||
|
||||
if (groupchats[groupnum].audio.muted[peernum])
|
||||
if (peernum < 0)
|
||||
return;
|
||||
|
||||
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)
|
||||
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 */
|
||||
|
||||
|
@ -50,13 +50,11 @@
|
||||
#define GROUP_EVENT_WAIT 3
|
||||
|
||||
#ifdef AUDIO
|
||||
#define MAX_AUDIO_SOURCES 128 /* arbitrary limit */
|
||||
|
||||
struct GAudio {
|
||||
ALCdevice *dvhandle; /* Handle of device selected/opened */
|
||||
ALCcontext *dvctx;
|
||||
ALuint sources[MAX_AUDIO_SOURCES]; /* one audio source per peer */
|
||||
uint8_t muted[MAX_AUDIO_SOURCES];
|
||||
ALuint source;
|
||||
ALuint buffers[OPENAL_BUFS];
|
||||
};
|
||||
#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_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 */
|
||||
|
@ -54,8 +54,9 @@ void on_request(Tox *m, const uint8_t *public_key, const uint8_t *data, uint16_t
|
||||
int 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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 */
|
||||
|
||||
int add_window(Tox *m, ToxWindow w)
|
||||
|
Loading…
Reference in New Issue
Block a user