|
1 | 1 | #include "dll/voicechat.h" |
2 | | - |
3 | | -static std::atomic<bool> isInited{ false }; |
| 2 | + |
| 3 | +static std::atomic<bool> isInited{ false }; |
4 | 4 |
|
5 | 5 | bool VoiceChat::InitVoiceSystem() { |
6 | 6 | if (!isInited) { |
7 | 7 | if (Pa_Initialize() != paNoError) { |
8 | 8 | PRINT_DEBUG("PortAudio initialization failed"); |
9 | 9 | return false; |
10 | | - } |
| 10 | + } |
11 | 11 | isInited = true; |
12 | 12 | } |
13 | 13 | isRecording = false; |
14 | 14 | isPlaying = false; |
15 | 15 | encoder = nullptr; |
16 | 16 | inputStream = nullptr; |
17 | 17 | outputStream = nullptr; |
| 18 | + PRINT_DEBUG("VoiceSystem initialized!"); |
18 | 19 | return true; |
19 | 20 | } |
20 | 21 |
|
21 | 22 | void VoiceChat::ShutdownVoiceSystem() { |
22 | 23 | if (isInited) { |
23 | | - Pa_Terminate(); |
| 24 | + Pa_Terminate(); |
24 | 25 | isInited = false; |
| 26 | + PRINT_DEBUG("VoiceSystem Terminated!"); |
25 | 27 | } |
26 | 28 | } |
27 | 29 |
|
@@ -188,6 +190,13 @@ EVoiceResult VoiceChat::GetAvailableVoice(uint32_t* pcbCompressed) { |
188 | 190 | EVoiceResult VoiceChat::GetVoice(bool bWantCompressed, void* pDestBuffer, uint32_t cbDestBufferSize, uint32_t* nBytesWritten) { |
189 | 191 | if (!pDestBuffer || !nBytesWritten) return k_EVoiceResultNotInitialized; |
190 | 192 |
|
| 193 | + // if we does not recording dont do anything. |
| 194 | + if (isRecording.load()) return k_EVoiceResultNotRecording; |
| 195 | + |
| 196 | + // should we have this here ? -detanup |
| 197 | + // some games might not initialize this. (?? FUCKING WHY? ) |
| 198 | + if (!InitVoiceSystem()) return k_EVoiceResultNotInitialized; |
| 199 | + |
191 | 200 | std::unique_lock<std::mutex> lock(inputMutex); |
192 | 201 | inputCond.wait_for(lock, std::chrono::milliseconds(20), [this] { |
193 | 202 | return !this->encodedQueue.empty(); |
@@ -252,4 +261,5 @@ void VoiceChat::QueueIncomingVoice(uint64_t userId, const uint8_t* data, size_t |
252 | 261 | if (!data || len == 0) return; |
253 | 262 | std::lock_guard<std::mutex> lock(playbackQueueMutex); |
254 | 263 | playbackQueue.push({ userId, std::vector<uint8_t>(data, data + len) }); |
255 | | -} |
| 264 | +} |
| 265 | + |
0 commit comments