Hikayeler

Reklam vermek için turkmmo@gmail.com
Kaynak ikonu

Voice Chat System Fixed My version V3

indirmek için izniniz yok

Infernal2.1

Level 2
Üye
Katılım
23 Haz 2020
Konular
9
Mesajlar
96
Online süresi
11g 79173s
Reaksiyon Skoru
26
Altın Konu
0
Başarım Puanı
61
TM Yaşı
5 Yıl 10 Ay
MmoLira
3,967
DevLira
12

Metin2 EP, Valorant VP dahil tüm oyun ürünlerini en uygun fiyatlarla bulabilir, Item ve Karakterlerinizi hızlıca satabilirsiniz. HEMEN TIKLA!

Root Causes of Voice Chat System Issues

🔴 Reconnection bug (sound does not return upon entering range)

3 combined root causes:



playback.h — `neededMoreSamples` was not initialized. When creating a speaker buffer, the boolean had a garbage value → the jitter buffer did not insert silence correctly → audio never started.



Fix: bool neededMoreSamples = true;

VoiceChat.cpp — smallestSplValue and inactiveBypassLeft were static. They persisted across sessions. Upon reconnecting, the voice detection threshold remained calibrated with old values → new voice was rejected as noise.



Fix: Moved to class members with reset in Initialize()/Destroy()

flac_decoder.h — After an error or end of stream, the decoder remained in an invalid state. initialize() did not reinitialize if it was not in UNINITIALIZED. New packets failed silently.



Fix: execute() detects error/end states and automatically calls finish() + initialize()

🔴 Packet corruption

2 root causes:



packet.h (server + client) — TVoiceChatPacket without #pragma pack(1). The#pragmanserted padding between the uint8_t header and uint16_t size. Server and client could have different sizes → different sizeof(TVoiceChatPacket) → validation pack.dataSize != pack.size - sizeof(TVoiceChatPacket) failed or passed incorrectly.



Fix: #pragma pack(push, 1) / #pragmak(pop) on bot#pragma

input_main.cpp (server) — *(TVoiceChatPacket*)c_pData without verifying that uiBytes >= sizeof(TVoiceChatPacket) → buffer over-read. Invalid packet read memory


Fix: Bounds check first, then safe memcpy instead of pointer cast

🔴 Race conditions (crackling, crashes)

2 root causes:



playback.h — setSpeakerVolume() modified m_SpeakerBuffers without a mutex, while the audio thread was reading it in dataCallback.



Fix: std::lock_guard<std::mutex> added

playback.h — mixedSamples was static inside getSamples(), called from the audio thread. Static in a function = shared across invocations, not thread-safe if re-entry occurred.



Fix: Moved to member m_MixBuffer

🟡 Incorrect sample calculation

playback.h — samplesPerMillisecond() used m_Device.capture.channels but the class is Playback (it has no capture). The correct field is m_Device.playback.channels.



🟡 Oversized receive buffer

PythonNetworkStreamPhaseGame.cpp — Allocated sampleRate * 8 channels * sizeof(int16_t) = ~768KB per packet, when the actual data is ~6KB. Used std::max<uint8_t>(8, channelCount), which always returns at least 8.



Fix: Buffer sized to actual packet.dataSize

🟡 Static vector in hot path

VoiceChat.cpp — samplesVec was static, causing the vector to retain old state between calls and be reused without being properly cleaned up.



Fix: Normal local variable std::vector<int16_t> samplesVec(samples, samples + sampleCount)

vc_ui.png



1775476172073.png



V3.0 TEST AND WORK




Game-level fixes

🎤 Sound wouldn't come back when you got close to someone

You'd leave the voice chat range → get close again → total silence. You had to reconnect for it to work again. Now the audio resumes automatically when you return to the range.



🔇 Voice chat would cut out during map changes / reconnections

When changing maps or reconnecting, voice chat would stop working. The microphone would detect your voice as “background noise” because it remembered the sound levels from the previous session. Now it recalibrates upon reconnecting.



🔊 Crackling / noise when changing a player’s volume

If you adjusted a speaker’s volume while they were speaking, it could cause crackling or glitches. Now volume changes are smooth without interrupting the audio.



📡 Corrupted packets caused disconnections or silence

If a voice packet arrived malformed, it could corrupt subsequent packets and desynchronize the connection. In the worst case, the client would disconnect. Now the server validates correctly before processing.



💾 Excessive memory usage when receiving voice

Each voice packet allocated ~768KB of memory when it only needed ~6KB. With multiple players speaking, RAM usage skyrocketed. Now it uses only what is necessary.
 
Moderatör tarafında düzenlendi:

En Çok Reaksiyon Alan Mesajlar

Ty for share

System fix so working?
 
Thanks for the fix!!

Edit 2:

After applying the "Fix," the error of closing the cliente.
 
Son düzenleme:
New files:

VoiceChannelManager.h - Global singleton that manages server channel members

Channel logic:

Event Behavior

Player clicks “Join” Sends /voice_channel_join → server adds to CVoiceChannelManager → sets quest flag voice_chat.server_channel=1 → broadcasts member list to all

Player clicks “Leave” Sends /voice_channel_leave → server removes → quest flag = 0 → broadcasts updated list

Player speaks in Server channel Audio goes to ALL channel members regardless of map/realm (distance=0)

Player teleports (same core) CHARACTER persists → VID does not change → remains in the channel automatically

Player teleports (cross-core) CHARACTER is destroyed → OnDisconnect() removes → in new core, OnLogin() detects quest flag=1 → auto-rejoin → broadcast new list

Player disconnects from the game VoiceChannelOnDisconnect() removes → broadcast list without him

Player reconnects VoiceChannelOnLogin() detects quest flag → re-adds → broadcasts list → UI receives voice_channel_joined 1 + member list

UI (Python):
List of connected members with a counter (“Connected: 5”)
Maximum of 8 visible members + “... +N more”
Listen toggle for the Server channel (4th button)
Final Packet Audit (Disconnect)
3 disconnect vectors removed:
1. SEND from audio thread (CRITICAL - previously fixed):

onCaptureSamples() ran on miniaudio thread → Send() on main thread = race condition
Fix: Thread-safe queue + FlushPendingPackets() from Process() on main thread
Fix: Thread-safe queue + FlushPendingPackets() from Process() on main thread
2. RECV with robust validation (now improved):

The M2 framework with DYNAMIC_SIZE_PACKET reads uint16_t size at offset 1 → waits for ALL bytes before calling the handler
Guarantee: both Recv() (header + data) will always have data available
Extra: validation of size vs. dataSize consistency; if they don’t match, the bytes are consumed without disconnecting (return true instead of return false)
Extra: 16KB limit; oversized packets are silently discarded
3. Incorrect phases (already fixed):

input.cpp (handshake) and input_login.cpp (login) both handle HEADER_CG_VOICE_CHAT by returning p->dataSize → the packet is consumed without error during phase transitions
Result: 0% probability of disconnection due to voice chat provided that packets are well-formed on both sides (and malformed packets are handled gracefully without disconnecting).


New Link :
 

Şu an konuyu görüntüleyenler (Toplam : 1, Üye: 0, Misafir: 1)

Geri
Üst