+void recheckCodecVersions()
+{
+ int codec_map[MAX_CODECS][2];
+ client_t *itr;
+ int i, codecindex, max = 0, version, current_version;
+ message_t *sendmsg;
+
+ memset(codec_map, 0, MAX_CODECS * 2 * sizeof(int));
+ while (Client_iterate(&itr) != NULL) {
+ for (i = 0; i < itr->codec_count; i++) {
+ for (codecindex = 0; codecindex < MAX_CODECS; codecindex++) {
+ if (codec_map[codecindex][0] == 0)
+ codec_map[codecindex][0] = itr->codecs[i];
+ if (itr->codecs[i] == codec_map[codecindex][0])
+ codec_map[codecindex][1]++;
+ }
+ }
+ }
+ if (codec_map[codecindex][0] == 0)
+ return;
+ for (codecindex = 0; codecindex < MAX_CODECS; codecindex++) {
+ if (codec_map[codecindex][0] == 0)
+ break;
+ if (codec_map[codecindex][1] > max) {
+ max = codec_map[codecindex][1];
+ version = codec_map[codecindex][0];
+ }
+ }
+ current_version = bPreferAlpha ? iCodecAlpha : iCodecBeta;
+ if (current_version == version)
+ return;
+ // If we don't already use the compat bitstream version set
+ // it as alpha and announce it. If another codec now got the
+ // majority set it as the opposite of the currently valid bPreferAlpha
+ // and announce it.
+ if (version == (uint32_t)0x8000000a)
+ bPreferAlpha = true;
+ else
+ bPreferAlpha = ! bPreferAlpha;
+
+ if (bPreferAlpha)
+ iCodecAlpha = version;
+ else
+ iCodecBeta = version;
+
+ sendmsg = Msg_create(CodecVersion);
+ sendmsg->payload.codecVersion->alpha = version;
+ sendmsg->payload.codecVersion->beta = version;
+ sendmsg->payload.codecVersion->beta = bPreferAlpha;
+ Client_send_message_except(NULL, sendmsg);
+
+}
+