declare_list(clients);
static int clientcount; /* = 0 */
static int maxBandwidth;
-static bool_t bOpus = true;
+bool_t bOpus = true;
int iCodecAlpha, iCodecBeta;
bool_t bPreferAlpha;
while (Client_iterate(&client_itr) != NULL) {
codec_itr = NULL;
+ if (client_itr->codec_count == 0 && !client_itr->bOpus)
+ continue;
while (Client_codec_iterate(client_itr, &codec_itr) != NULL) {
found = false;
list_iterate(itr, &codec_list) {
cd->count = 1;
list_add_tail(&cd->node, &codec_list);
}
- users++;
- if (client_itr->bOpus)
- opus++;
}
+ users++;
+ if (client_itr->bOpus)
+ opus++;
}
-
+
+ if (users == 0)
+ return;
+
enableOpus = ((opus * 100 / users) >= getIntConf(OPUS_THRESHOLD));
list_iterate(itr, &codec_list) {
uint32_t *tree_id;
message_t *sendmsg = NULL;
- message = malloc(strlen(OPUS_WARN));
+ message = malloc(strlen(OPUS_WARN) + 1);
if (!message)
Log_fatal("Out of memory");
tree_id = malloc(sizeof(uint32_t));
}
bOpus = enableOpus;
+ Log_info("OPUS codec is %s", bOpus ? "enabled" : "disabled");
sendmsg = Msg_create(CodecVersion);
sendmsg->payload.codecVersion->alpha = iCodecAlpha;
sendmsg->payload.codecVersion->beta = iCodecBeta;
sendmsg->payload.codecVersion->prefer_alpha = bPreferAlpha;
+ sendmsg->payload.codecVersion->has_opus = true;
+ sendmsg->payload.codecVersion->opus = bOpus;
+
Client_send_message_except(NULL, sendmsg);
Log_info("CELT codec switch 0x%x 0x%x (prefer 0x%x)", iCodecAlpha, iCodecBeta,
bPreferAlpha ? iCodecAlpha : iCodecBeta);
+
+ client_itr = NULL;
+ while (Client_iterate(&client_itr) != NULL) {
+ if ((client_itr->authenticated || client_itr == connectingClient) &&
+ !client_itr->bOpus) {
+ char *message;
+ uint32_t *tree_id;
+ message_t *sendmsg = NULL;
+
+ message = malloc(strlen(OPUS_WARN) + 1);
+ if (!message)
+ Log_fatal("Out of memory");
+ tree_id = malloc(sizeof(uint32_t));
+ if (!tree_id)
+ Log_fatal("Out of memory");
+ *tree_id = 0;
+ sendmsg = Msg_create(TextMessage);
+ sendmsg->payload.textMessage->message = message;
+ sendmsg->payload.textMessage->n_tree_id = 1;
+ sendmsg->payload.textMessage->tree_id = tree_id;
+ sprintf(message, OPUS_WARN);
+ Client_send_message(client_itr, sendmsg);
+ sendmsg = NULL;
+ }
+ }
}
sendmsg = Msg_create(UserRemove);
sendmsg->payload.userRemove->session = client->sessionId;
Client_send_message_except(client, sendmsg);
+ recheckCodecVersions(NULL); /* Can use better codec now? */
}
list_iterate_safe(itr, save, &client->txMsgQueue) {
list_del(&list_get_entry(itr, message_t, node)->node);
#define MAX_TEXT 512
#define MAX_USERNAME 128
+#define NO_CELT_MESSAGE "<strong>WARNING:</strong> Your client doesn't support the CELT codec, you won't be able to talk to or hear most clients. Please make sure your client was built with CELT support."
+
+
extern channel_t *defaultChan;
extern int iCodecAlpha, iCodecBeta;
extern bool_t bPreferAlpha, bOpus;
+static bool_t fake_celt_support;
+
static void sendServerReject(client_t *client, const char *reason, MumbleProto__Reject__RejectType type)
{
message_t *msg = Msg_create(Reject);
Log_debug("Client %d CELT codec ver 0x%x", client->sessionId, codec_itr->codec);
} else {
- Client_codec_add(client, (int32_t)0x8000000a);
+ Client_codec_add(client, (int32_t)0x8000000b);
client->codec_count = 1;
+ fake_celt_support = true;
}
if (msg->payload.authenticate->opus)
client->bOpus = true;
sendmsg->payload.codecVersion->alpha = iCodecAlpha;
sendmsg->payload.codecVersion->beta = iCodecBeta;
sendmsg->payload.codecVersion->prefer_alpha = bPreferAlpha;
+ sendmsg->payload.codecVersion->has_opus = true;
+ sendmsg->payload.codecVersion->opus = bOpus;
Client_send_message(client, sendmsg);
-
+
+ if (!bOpus && client->bOpus && fake_celt_support) {
+ char *message;
+ uint32_t *tree_id;
+ message_t *sendmsg = NULL;
+
+ message = malloc(strlen(NO_CELT_MESSAGE) + 1);
+ if (!message)
+ Log_fatal("Out of memory");
+ tree_id = malloc(sizeof(uint32_t));
+ if (!tree_id)
+ Log_fatal("Out of memory");
+ *tree_id = 0;
+ sendmsg = Msg_create(TextMessage);
+ sendmsg->payload.textMessage->message = message;
+ sendmsg->payload.textMessage->n_tree_id = 1;
+ sendmsg->payload.textMessage->tree_id = tree_id;
+ sprintf(message, NO_CELT_MESSAGE);
+ Client_send_message(client, sendmsg);
+ sendmsg = NULL;
+ }
+
/* Iterate channels and send channel info */
ch_itr = NULL;
while (Chan_iterate(&ch_itr) != NULL) {