mirror of
https://github.com/Tha14/toxic.git
synced 2025-07-02 09:16:44 +02:00
Implement push-to-talk for conference audio
This commit is contained in:
@ -100,6 +100,7 @@ static const char *conference_cmd_list[] = {
|
||||
"/quit",
|
||||
"/requests",
|
||||
#ifdef AUDIO
|
||||
"/ptt",
|
||||
"/sense",
|
||||
#endif
|
||||
"/status",
|
||||
@ -200,6 +201,10 @@ int init_conference_win(Tox *m, uint32_t conferencenum, uint8_t type, const char
|
||||
conferences[i].audio_enabled = false;
|
||||
conferences[i].last_sent_audio = 0;
|
||||
|
||||
#ifdef AUDIO
|
||||
conferences[i].push_to_talk_enabled = user_settings->push_to_talk;
|
||||
#endif
|
||||
|
||||
set_active_window_index(conferences[i].chatwin);
|
||||
|
||||
conference_set_title(self, conferencenum, title, length);
|
||||
@ -568,6 +573,22 @@ static ConferencePeer *peer_in_conference(uint32_t conferencenum, uint32_t peern
|
||||
}
|
||||
|
||||
#ifdef AUDIO
|
||||
|
||||
/* Return true if ptt is disabled or enabled and active. */
|
||||
static bool conference_check_push_to_talk(ConferenceChat *chat)
|
||||
{
|
||||
if (!chat->push_to_talk_enabled) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return !timed_out(chat->ptt_last_pushed, 1);
|
||||
}
|
||||
|
||||
static void conference_enable_push_to_talk(ConferenceChat *chat)
|
||||
{
|
||||
chat->ptt_last_pushed = get_unix_time();
|
||||
}
|
||||
|
||||
static void set_peer_audio_position(Tox *m, uint32_t conferencenum, uint32_t peernum)
|
||||
{
|
||||
ConferenceChat *chat = &conferences[conferencenum];
|
||||
@ -599,7 +620,7 @@ static void set_peer_audio_position(Tox *m, uint32_t conferencenum, uint32_t pee
|
||||
const float angle = asinf(peer_posn - (float)(num_posns - 1) / 2);
|
||||
set_source_position(peer->audio_out_idx, sinf(angle), cosf(angle), 0);
|
||||
}
|
||||
#endif
|
||||
#endif // AUDIO
|
||||
|
||||
|
||||
static bool find_peer_by_pubkey(const ConferencePeer *list, uint32_t num_peers, uint8_t *pubkey, uint32_t *idx)
|
||||
@ -774,7 +795,6 @@ static int sidebar_offset(uint32_t conferencenum)
|
||||
return 2 + conferences[conferencenum].audio_enabled;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Return true if input is recognized by handler
|
||||
*/
|
||||
@ -817,6 +837,15 @@ static bool conference_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
|
||||
bool input_ret = false;
|
||||
ConferenceChat *chat = &conferences[self->num];
|
||||
|
||||
#ifdef AUDIO
|
||||
|
||||
if (chat->audio_enabled && chat->push_to_talk_enabled && key == KEY_F(2)) {
|
||||
input_ret = true;
|
||||
conference_enable_push_to_talk(chat);
|
||||
}
|
||||
|
||||
#endif // AUDIO
|
||||
|
||||
if (key == L'\t') { /* TAB key: auto-completes peer name or command */
|
||||
input_ret = true;
|
||||
|
||||
@ -997,6 +1026,12 @@ static void conference_onDraw(ToxWindow *self, Tox *m)
|
||||
return;
|
||||
}
|
||||
|
||||
ConferenceChat *chat = &conferences[self->num];
|
||||
|
||||
if (!chat->active) {
|
||||
return;
|
||||
}
|
||||
|
||||
ChatContext *ctx = self->chatwin;
|
||||
|
||||
pthread_mutex_lock(&Winthread.lock);
|
||||
@ -1019,8 +1054,8 @@ static void conference_onDraw(ToxWindow *self, Tox *m)
|
||||
mvwaddch(ctx->sidebar, y2 - CHATBOX_HEIGHT, 0, ACS_BTEE);
|
||||
|
||||
pthread_mutex_lock(&Winthread.lock);
|
||||
const uint32_t num_peers = conferences[self->num].num_peers;
|
||||
const bool audio = conferences[self->num].audio_enabled;
|
||||
const uint32_t num_peers = chat->num_peers;
|
||||
const bool audio = chat->audio_enabled;
|
||||
const int header_lines = sidebar_offset(self->num);
|
||||
pthread_mutex_unlock(&Winthread.lock);
|
||||
|
||||
@ -1029,32 +1064,45 @@ static void conference_onDraw(ToxWindow *self, Tox *m)
|
||||
if (audio) {
|
||||
#ifdef AUDIO
|
||||
pthread_mutex_lock(&Winthread.lock);
|
||||
const bool mic_on = !device_is_muted(input, conferences[self->num].audio_in_idx);
|
||||
const bool ptt_idle = !conference_check_push_to_talk(chat) && chat->push_to_talk_enabled;
|
||||
const bool mic_on = !device_is_muted(input, chat->audio_in_idx);
|
||||
const float volume = get_input_volume();
|
||||
const float threshold = device_get_VAD_threshold(conferences[self->num].audio_in_idx);
|
||||
const float threshold = device_get_VAD_threshold(chat->audio_in_idx);
|
||||
pthread_mutex_unlock(&Winthread.lock);
|
||||
|
||||
wmove(ctx->sidebar, line, 1);
|
||||
wattron(ctx->sidebar, A_BOLD);
|
||||
wprintw(ctx->sidebar, "Mic: ");
|
||||
const int color = mic_on && volume > threshold ? GREEN : RED;
|
||||
wattron(ctx->sidebar, COLOR_PAIR(color));
|
||||
|
||||
if (mic_on) {
|
||||
if (!mic_on) {
|
||||
wattron(ctx->sidebar, COLOR_PAIR(RED));
|
||||
wprintw(ctx->sidebar, "MUTED");
|
||||
wattroff(ctx->sidebar, COLOR_PAIR(RED));
|
||||
} else if (ptt_idle) {
|
||||
wattron(ctx->sidebar, COLOR_PAIR(GREEN));
|
||||
wprintw(ctx->sidebar, "PTT");
|
||||
wattroff(ctx->sidebar, COLOR_PAIR(GREEN));
|
||||
} else {
|
||||
const int color = volume > threshold ? GREEN : RED;
|
||||
wattron(ctx->sidebar, COLOR_PAIR(color));
|
||||
|
||||
float v = volume;
|
||||
|
||||
if (v <= 0.0f) {
|
||||
wprintw(ctx->sidebar, ".");
|
||||
}
|
||||
|
||||
while (v > 0.0f) {
|
||||
wprintw(ctx->sidebar, v > 10.0f ? (v > 15.0f ? "*" : "+") : (v > 5.0f ? "-" : "."));
|
||||
v -= 20.0f;
|
||||
}
|
||||
} else {
|
||||
wprintw(ctx->sidebar, "OFF");
|
||||
|
||||
wattroff(ctx->sidebar, COLOR_PAIR(color));
|
||||
}
|
||||
|
||||
wattroff(ctx->sidebar, COLOR_PAIR(color));
|
||||
wattroff(ctx->sidebar, A_BOLD);
|
||||
++line;
|
||||
#endif
|
||||
#endif // AUDIO
|
||||
}
|
||||
|
||||
wmove(ctx->sidebar, line, 1);
|
||||
@ -1195,7 +1243,13 @@ static void conference_read_device_callback(const int16_t *captured, uint32_t si
|
||||
|
||||
AudioInputCallbackData *audio_input_callback_data = (AudioInputCallbackData *)data;
|
||||
|
||||
conferences[audio_input_callback_data->conferencenum].last_sent_audio = get_unix_time();
|
||||
ConferenceChat *chat = &conferences[audio_input_callback_data->conferencenum];
|
||||
|
||||
if (!conference_check_push_to_talk(chat)) {
|
||||
return;
|
||||
}
|
||||
|
||||
chat->last_sent_audio = get_unix_time();
|
||||
|
||||
int channels = user_settings->conference_audio_channels;
|
||||
|
||||
@ -1228,6 +1282,19 @@ bool init_conference_audio_input(Tox *tox, uint32_t conferencenum)
|
||||
return success;
|
||||
}
|
||||
|
||||
bool toggle_conference_push_to_talk(uint32_t conferencenum, bool enabled)
|
||||
{
|
||||
ConferenceChat *chat = &conferences[conferencenum];
|
||||
|
||||
if (!chat->active) {
|
||||
return false;
|
||||
}
|
||||
|
||||
chat->push_to_talk_enabled = enabled;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool enable_conference_audio(Tox *tox, uint32_t conferencenum)
|
||||
{
|
||||
if (!toxav_groupchat_av_enabled(tox, conferencenum)) {
|
||||
@ -1312,4 +1379,4 @@ float conference_get_VAD_threshold(uint32_t conferencenum)
|
||||
|
||||
return device_get_VAD_threshold(chat->audio_in_idx);
|
||||
}
|
||||
#endif
|
||||
#endif // AUDIO
|
||||
|
Reference in New Issue
Block a user