MCPcopy Create free account
hub / github.com/BohemiaInteractive/CWR / ExecuteTest

Function ExecuteTest

apps/tools/Tools/commands/VonCommand.cpp:106–302  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

104}
105
106static int ExecuteTest(int delayMs)
107{
108 if (!OpenALRuntime::EnsureLoaded())
109 {
110 std::cerr << "[von-test] OpenAL runtime unavailable: " << OpenALRuntime::LastError() << "\n";
111 return 1;
112 }
113 if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS))
114 {
115 std::cerr << "[von-test] SDL_Init failed: " << SDL_GetError() << "\n";
116 return 1;
117 }
118 ALCdevice* playDev = alcOpenDevice(nullptr);
119 if (!playDev)
120 {
121 std::cerr << "[von-test] Failed to open OpenAL playback device\n";
122 SDL_Quit();
123 return 1;
124 }
125 ALCcontext* ctx = alcCreateContext(playDev, nullptr);
126 alcMakeContextCurrent(ctx);
127 VoNSystem vonSys;
128 vonSys.initClient();
129 vonSys.initServer();
130
131 auto* client = vonSys.client();
132 client->setCodecFactory([]() { return std::make_unique<OpusCodec>(); });
133 client->setSenderId(1);
134 client->setChatChannel(VoNChatChannel::Direct);
135 client->createChannel(1, {}); // receive own echo
136
137 // Direct delivery keeps the echo path inside the same client process.
138 vonSys.server()->setRouting(1, VoNChatChannel::Direct, {1});
139 VoNCapture capture;
140 bool captureOk = capture.open(nullptr, RATE, RATE); // 1s buffer
141 if (!captureOk)
142 {
143 std::cerr << "[von-test] WARNING: No capture device available — transmit will be silent\n";
144 }
145 OpusCodec encoder;
146 std::vector<uint8_t> encBuf(encoder.maxEncodedSize());
147 std::vector<int16_t> capBuf(FRAME);
148 uint64_t origin = 0;
149 std::deque<DelayedPacket> delayQueue;
150 auto delayDuration = std::chrono::milliseconds(delayMs);
151 char titleBuf[256];
152 std::snprintf(titleBuf, sizeof(titleBuf), "VoN Echo Test | CapsLock=Transmit | Delay=%dms | Esc=Quit", delayMs);
153
154 SDL_Window* window = SDL_CreateWindow(titleBuf, WIN_W, WIN_H, 0);
155 if (!window)
156 {
157 std::cerr << "[von-test] SDL_CreateWindow failed: " << SDL_GetError() << "\n";
158 vonSys.shutdown();
159 alcMakeContextCurrent(nullptr);
160 alcDestroyContext(ctx);
161 alcCloseDevice(playDev);
162 SDL_Quit();
163 return 1;

Callers 2

SetupMethod · 0.85
SetupMethod · 0.85

Calls 15

EnsureLoadedFunction · 0.85
LastErrorFunction · 0.85
rmsLevelFunction · 0.85
drawPanelFunction · 0.85
initClientMethod · 0.80
initServerMethod · 0.80
setCodecFactoryMethod · 0.80
setSenderIdMethod · 0.80
setChatChannelMethod · 0.80
setRoutingMethod · 0.80
serverMethod · 0.80
shutdownMethod · 0.80

Tested by

no test coverage detected