Skip to content

Commit a273f2e

Browse files
authored
Merge pull request #313 from Detanup01/vc-fix
more fixes on voice chat
2 parents c750088 + 10fed5b commit a273f2e

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

dll/voicechat.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
11
#include "dll/voicechat.h"
2-
3-
static std::atomic<bool> isInited{ false };
2+
3+
static std::atomic<bool> isInited{ false };
44

55
bool VoiceChat::InitVoiceSystem() {
66
if (!isInited) {
77
if (Pa_Initialize() != paNoError) {
88
PRINT_DEBUG("PortAudio initialization failed");
99
return false;
10-
}
10+
}
1111
isInited = true;
1212
}
1313
isRecording = false;
1414
isPlaying = false;
1515
encoder = nullptr;
1616
inputStream = nullptr;
1717
outputStream = nullptr;
18+
PRINT_DEBUG("VoiceSystem initialized!");
1819
return true;
1920
}
2021

2122
void VoiceChat::ShutdownVoiceSystem() {
2223
if (isInited) {
23-
Pa_Terminate();
24+
Pa_Terminate();
2425
isInited = false;
26+
PRINT_DEBUG("VoiceSystem Terminated!");
2527
}
2628
}
2729

@@ -188,6 +190,13 @@ EVoiceResult VoiceChat::GetAvailableVoice(uint32_t* pcbCompressed) {
188190
EVoiceResult VoiceChat::GetVoice(bool bWantCompressed, void* pDestBuffer, uint32_t cbDestBufferSize, uint32_t* nBytesWritten) {
189191
if (!pDestBuffer || !nBytesWritten) return k_EVoiceResultNotInitialized;
190192

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+
191200
std::unique_lock<std::mutex> lock(inputMutex);
192201
inputCond.wait_for(lock, std::chrono::milliseconds(20), [this] {
193202
return !this->encodedQueue.empty();
@@ -252,4 +261,5 @@ void VoiceChat::QueueIncomingVoice(uint64_t userId, const uint8_t* data, size_t
252261
if (!data || len == 0) return;
253262
std::lock_guard<std::mutex> lock(playbackQueueMutex);
254263
playbackQueue.push({ userId, std::vector<uint8_t>(data, data + len) });
255-
}
264+
}
265+

0 commit comments

Comments
 (0)