Apply clang-format across the whole tree
Run clang-format (the repo's .clang-format: LLVM base, 120 cols, tabs, Allman functions) over every source file so the tree is formatter-clean. Whitespace only -- no behavior change; full x64 + x86 suites pass. Also set SortIncludes: false in .clang-format. Windows include order is load-bearing (windows.h must precede tlhelp32.h / mmreg.h / xinput.h / dinput.h; winsock2.h must precede windows.h), and the default alphabetical sort reorders tlhelp32.h ahead of windows.h -- a build break. Leaving order alone keeps the manual, correct grouping.
This commit is contained in:
@@ -34,16 +34,14 @@ using namespace coop;
|
||||
using coop::tone::ToneFormat;
|
||||
using coop::tone::ToneSource;
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
|
||||
int g_failures = 0;
|
||||
|
||||
// Returns 1 (and logs) on failure, 0 on success -- so callers can sum a tally.
|
||||
int expect(bool ok, const char* what)
|
||||
{
|
||||
if (!ok)
|
||||
{
|
||||
if (!ok) {
|
||||
std::printf(" FAIL: %s\n", what);
|
||||
++g_failures;
|
||||
return 1;
|
||||
@@ -63,10 +61,8 @@ bool ring_has_nonsilent(AudioRingHeader* ring)
|
||||
{
|
||||
std::vector<std::uint8_t> buf(128 * 1024, 0);
|
||||
const std::uint32_t got = audio_ring_pop(*ring, buf.data(), static_cast<std::uint32_t>(buf.size()));
|
||||
for (std::uint32_t i = 0; i < got; ++i)
|
||||
{
|
||||
if (buf[i] != 0)
|
||||
{
|
||||
for (std::uint32_t i = 0; i < got; ++i) {
|
||||
if (buf[i] != 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -85,15 +81,13 @@ void test_see_init(hook::IpcClient& ipc, AudioRingHeader* ring, SharedBlock* blo
|
||||
{
|
||||
char d[64];
|
||||
reset_ring(ring, block);
|
||||
if (!hook::install_audio_hooks(ipc, ring))
|
||||
{
|
||||
if (!hook::install_audio_hooks(ipc, ring)) {
|
||||
std::printf(" SKIP see-init (audio hooks unavailable)\n");
|
||||
return;
|
||||
}
|
||||
|
||||
ToneSource tone;
|
||||
if (!tone.open(want))
|
||||
{
|
||||
if (!tone.open(want)) {
|
||||
std::printf(" SKIP see-init %s (format unavailable here)\n", fmt_desc(want, d, sizeof(d)));
|
||||
hook::remove_audio_hooks();
|
||||
return;
|
||||
@@ -103,8 +97,7 @@ void test_see_init(hook::IpcClient& ipc, AudioRingHeader* ring, SharedBlock* blo
|
||||
// Exact format publishes at registration; render briefly so capture fills the ring.
|
||||
const std::uint64_t silenced_before = hook::audio_frames_silenced();
|
||||
const DWORD end = GetTickCount() + 300;
|
||||
while (GetTickCount() < end)
|
||||
{
|
||||
while (GetTickCount() < end) {
|
||||
tone.render_step(50);
|
||||
}
|
||||
|
||||
@@ -117,8 +110,7 @@ void test_see_init(hook::IpcClient& ipc, AudioRingHeader* ring, SharedBlock* blo
|
||||
fail += expect(s.sample_rate == f.rate, "see-init: HookStatus rate == exact rate");
|
||||
fail += expect(s.format_state == AudioFormat_Exact, "see-init: provenance == Exact");
|
||||
fail += expect(ring_has_nonsilent(ring), "see-init: non-silent audio captured");
|
||||
fail += expect(hook::audio_frames_silenced() > silenced_before,
|
||||
"see-init: local playback muted (no echo)");
|
||||
fail += expect(hook::audio_frames_silenced() > silenced_before, "see-init: local playback muted (no echo)");
|
||||
std::printf(" %s see-init %s -> ring %uHz/%uch/%ubit state=%u\n", fail == 0 ? "PASS" : "FAIL",
|
||||
fmt_desc(f, d, sizeof(d)), ring->sample_rate, ring->channels, ring->bits, s.format_state);
|
||||
|
||||
@@ -137,8 +129,7 @@ void test_guess(hook::IpcClient& ipc, AudioRingHeader* ring, SharedBlock* block,
|
||||
ToneSource tone;
|
||||
ToneFormat want;
|
||||
want.rate = rate; // channels/bits resolve to the device's
|
||||
if (!tone.open(want))
|
||||
{
|
||||
if (!tone.open(want)) {
|
||||
std::printf(" SKIP guess %u Hz (format unavailable here)\n", rate);
|
||||
return;
|
||||
}
|
||||
@@ -147,14 +138,12 @@ void test_guess(hook::IpcClient& ipc, AudioRingHeader* ring, SharedBlock* block,
|
||||
// Let the stream reach steady state before attaching, like a game already running when
|
||||
// we inject (the real case) -- not a stream we caught at its first buffer.
|
||||
const DWORD warm = GetTickCount() + 300;
|
||||
while (GetTickCount() < warm)
|
||||
{
|
||||
while (GetTickCount() < warm) {
|
||||
tone.render_step(30);
|
||||
}
|
||||
|
||||
// Hooks install *after* the client exists -> the lazy-discovery (guess) path.
|
||||
if (!hook::install_audio_hooks(ipc, ring))
|
||||
{
|
||||
if (!hook::install_audio_hooks(ipc, ring)) {
|
||||
std::printf(" SKIP guess (audio hooks unavailable)\n");
|
||||
tone.close();
|
||||
return;
|
||||
@@ -163,16 +152,14 @@ void test_guess(hook::IpcClient& ipc, AudioRingHeader* ring, SharedBlock* block,
|
||||
// Render while driving republish (the DLL's worker does this each tick) until the
|
||||
// measured rate is published, then render a bit more so capture fills the ring.
|
||||
const DWORD measure_deadline = GetTickCount() + 2000;
|
||||
while (GetTickCount() < measure_deadline && !audio_ring_format_ready(*ring))
|
||||
{
|
||||
while (GetTickCount() < measure_deadline && !audio_ring_format_ready(*ring)) {
|
||||
tone.render_step(30);
|
||||
hook::republish_audio_format();
|
||||
}
|
||||
// Format is published; from here the hook must capture AND mute (the no-echo path).
|
||||
const std::uint64_t silenced_before = hook::audio_frames_silenced();
|
||||
const DWORD cap_end = GetTickCount() + 200;
|
||||
while (GetTickCount() < cap_end)
|
||||
{
|
||||
while (GetTickCount() < cap_end) {
|
||||
tone.render_step(30);
|
||||
}
|
||||
|
||||
@@ -188,8 +175,8 @@ void test_guess(hook::IpcClient& ipc, AudioRingHeader* ring, SharedBlock* block,
|
||||
// game plays locally AND the mirror re-renders it, slightly delayed = a metallic double.
|
||||
fail += expect(hook::audio_frames_silenced() > silenced_before,
|
||||
"guess: local playback muted (no echo) -- the Brotato double-audio bug");
|
||||
std::printf(" %s guess %u Hz (device %uch/%ubit) -> measured %uHz state=%u\n", fail == 0 ? "PASS" : "FAIL",
|
||||
rate, f.channels, f.bits, ring->sample_rate, s.format_state);
|
||||
std::printf(" %s guess %u Hz (device %uch/%ubit) -> measured %uHz state=%u\n", fail == 0 ? "PASS" : "FAIL", rate,
|
||||
f.channels, f.bits, ring->sample_rate, s.format_state);
|
||||
|
||||
tone.close();
|
||||
hook::remove_audio_hooks();
|
||||
@@ -200,26 +187,23 @@ void test_guess(hook::IpcClient& ipc, AudioRingHeader* ring, SharedBlock* block,
|
||||
// VirtualQuery clamp must stop the copy reading past the source buffer. We can't assert a
|
||||
// "correct" format here (it's fundamentally undetectable); we assert the hook survives and
|
||||
// doesn't read absurd amounts, i.e. the unit test completes without an access violation.
|
||||
void test_guess_mismatch_safe(hook::IpcClient& ipc, AudioRingHeader* ring, SharedBlock* block,
|
||||
const ToneFormat& want, const char* label)
|
||||
void test_guess_mismatch_safe(hook::IpcClient& ipc, AudioRingHeader* ring, SharedBlock* block, const ToneFormat& want,
|
||||
const char* label)
|
||||
{
|
||||
char d[64];
|
||||
reset_ring(ring, block);
|
||||
|
||||
ToneSource tone;
|
||||
if (!tone.open(want))
|
||||
{
|
||||
if (!tone.open(want)) {
|
||||
std::printf(" SKIP guess-mismatch %s (%s unavailable here)\n", label, fmt_desc(want, d, sizeof(d)));
|
||||
return;
|
||||
}
|
||||
const ToneFormat& f = tone.format();
|
||||
const DWORD warm = GetTickCount() + 300; // steady state before attaching
|
||||
while (GetTickCount() < warm)
|
||||
{
|
||||
while (GetTickCount() < warm) {
|
||||
tone.render_step(30);
|
||||
}
|
||||
if (!hook::install_audio_hooks(ipc, ring))
|
||||
{
|
||||
if (!hook::install_audio_hooks(ipc, ring)) {
|
||||
std::printf(" SKIP guess-mismatch (audio hooks unavailable)\n");
|
||||
tone.close();
|
||||
return;
|
||||
@@ -228,8 +212,7 @@ void test_guess_mismatch_safe(hook::IpcClient& ipc, AudioRingHeader* ring, Share
|
||||
// Render and capture through the guessed (too-large) block. The clamp must keep this
|
||||
// from over-reading; reaching the end of the loop is the pass (no AV).
|
||||
const DWORD end = GetTickCount() + 600;
|
||||
while (GetTickCount() < end)
|
||||
{
|
||||
while (GetTickCount() < end) {
|
||||
tone.render_step(30);
|
||||
hook::republish_audio_format();
|
||||
}
|
||||
@@ -244,8 +227,7 @@ void test_guess_mismatch_safe(hook::IpcClient& ipc, AudioRingHeader* ring, Share
|
||||
|
||||
int main()
|
||||
{
|
||||
if (FAILED(CoInitializeEx(nullptr, COINIT_MULTITHREADED)))
|
||||
{
|
||||
if (FAILED(CoInitializeEx(nullptr, COINIT_MULTITHREADED))) {
|
||||
std::printf("FAIL: CoInitializeEx\n");
|
||||
return 1;
|
||||
}
|
||||
@@ -253,8 +235,7 @@ int main()
|
||||
// Host side: the IPC SharedBlock (named by our pid) the hook's IpcClient connects to,
|
||||
// plus one producer ring with capture enabled.
|
||||
SharedMemory shm;
|
||||
if (!shm.create(shared_memory_name(GetCurrentProcessId()), sizeof(SharedBlock)))
|
||||
{
|
||||
if (!shm.create(shared_memory_name(GetCurrentProcessId()), sizeof(SharedBlock))) {
|
||||
std::printf("FAIL: create shared memory\n");
|
||||
return 1;
|
||||
}
|
||||
@@ -276,8 +257,7 @@ int main()
|
||||
ToneFormat dev;
|
||||
{
|
||||
ToneSource probe;
|
||||
if (!probe.open(ToneFormat{}))
|
||||
{
|
||||
if (!probe.open(ToneFormat{})) {
|
||||
std::printf("SKIP: no default render endpoint (no audio device?)\n");
|
||||
CoUninitialize();
|
||||
return 0;
|
||||
@@ -297,8 +277,7 @@ int main()
|
||||
{44100, 1, 16, false}, // mono PCM
|
||||
{48000, 6, 32, true}, // 5.1 float
|
||||
};
|
||||
for (const ToneFormat& f : see_init)
|
||||
{
|
||||
for (const ToneFormat& f : see_init) {
|
||||
test_see_init(ipc, ring, block, f);
|
||||
}
|
||||
|
||||
@@ -306,8 +285,7 @@ int main()
|
||||
// rate differs -- the hook measures + corrects it to the true rate (the Brotato/Godot
|
||||
// case). Rendered at the device's channel/bit layout, so the bytes/frame match.
|
||||
std::printf("== GUESS, byte-compatible (pre-existing client -> measure the true rate) ==\n");
|
||||
for (unsigned rate : {44100u, 48000u, 96000u})
|
||||
{
|
||||
for (unsigned rate : {44100u, 48000u, 96000u}) {
|
||||
test_guess(ipc, ring, block, rate);
|
||||
}
|
||||
|
||||
@@ -316,15 +294,13 @@ int main()
|
||||
// a documented limitation), but the VirtualQuery clamp must keep the capture safe rather
|
||||
// than over-reading the source buffer.
|
||||
std::printf("== GUESS, byte-incompatible (channels/bits differ -> capture must stay safe) ==\n");
|
||||
if (dev.channels >= 2)
|
||||
{
|
||||
if (dev.channels >= 2) {
|
||||
test_guess_mismatch_safe(ipc, ring, block, {dev.rate, 1, dev.bits, dev.is_float}, "mono");
|
||||
}
|
||||
{
|
||||
const unsigned alt_bits = (dev.bits == 32) ? 16u : 32u;
|
||||
const bool alt_float = (alt_bits == 32);
|
||||
test_guess_mismatch_safe(ipc, ring, block, {dev.rate, dev.channels, alt_bits, alt_float},
|
||||
"alt bit depth");
|
||||
test_guess_mismatch_safe(ipc, ring, block, {dev.rate, dev.channels, alt_bits, alt_float}, "alt bit depth");
|
||||
}
|
||||
|
||||
CoUninitialize();
|
||||
|
||||
Reference in New Issue
Block a user