diff options
| author | Tomasz Kramkowski <tomasz@kramkow.ski> | 2026-11-17 17:03:49 +0000 |
|---|---|---|
| committer | Tomasz Kramkowski <tomasz@kramkow.ski> | 2026-11-17 17:03:49 +0000 |
| commit | 363fe07ad4cd514d907647ee0eda2310f6efa3c0 (patch) | |
| tree | 31cc927f256747e17887c8bb049b800457fe3208 /frame-steamos/recovery-watchdog.c | |
| parent | c750b7298bddab8f273365a96ec482538cd39201 (diff) | |
| download | steamvr-patches-363fe07ad4cd514d907647ee0eda2310f6efa3c0.tar.gz steamvr-patches-363fe07ad4cd514d907647ee0eda2310f6efa3c0.tar.xz steamvr-patches-363fe07ad4cd514d907647ee0eda2310f6efa3c0.zip | |
frame-steamos: fix a couple of bugs
It's possible to hang after a reset waiting for the first frame if that
frame never arrives. This adds calls to the existing decoder watchdog
handler to ensure this is recoverable.
Sub-optimal but better than nothing. Shouldn't happen normally anyway,
and the patch is still worth it as it fixes genuine repeat resets in
much more common cases.
Additionally, the headset can send an ack even when there is nothing to
ack, and it acks frame ID 0 in that case, this breaks the steamvr patch
which keeps the ACK cutoff at all times (it can cause things to get
stuck in 3.3FPS mode).
Diffstat (limited to 'frame-steamos/recovery-watchdog.c')
| -rw-r--r-- | frame-steamos/recovery-watchdog.c | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/frame-steamos/recovery-watchdog.c b/frame-steamos/recovery-watchdog.c new file mode 100644 index 0000000..d557c9d --- /dev/null +++ b/frame-steamos/recovery-watchdog.c @@ -0,0 +1,97 @@ +// SPDX-FileCopyrightText: 2026 Tomasz Kramkowski <tomasz@kramkow.ski> +// SPDX-License-Identifier: CC0-1.0 + +#include <stdbool.h> +#include <stddef.h> +#include <stdint.h> + +#define ASSERT_OFFSET(type, field, expected) \ + _Static_assert( \ + offsetof(type, field) == (expected), #type "." #field " offset" \ + ) + +struct CodecVtable; + +// SVLCodecV4L2 +struct Codec { + const struct CodecVtable *vtable; + unsigned char unknown_008[0x30 - 0x08]; + uint8_t initialized; + unsigned char unknown_031[0x13c - 0x31]; + uint8_t media_thread_quitting; + unsigned char unknown_13d[0x154 - 0x13d]; + int32_t reset_state; + unsigned char unknown_158[0x1c8 - 0x158]; + uint8_t reset_thread_quitting; +}; +ASSERT_OFFSET(struct Codec, initialized, 0x30); +ASSERT_OFFSET(struct Codec, media_thread_quitting, 0x13c); +ASSERT_OFFSET(struct Codec, reset_state, 0x154); +ASSERT_OFFSET(struct Codec, reset_thread_quitting, 0x1c8); + +struct Renderer { + unsigned char unknown_000[0x10]; + struct Codec *codec; +}; +ASSERT_OFFSET(struct Renderer, codec, 0x10); + +struct Client { + unsigned char unknown_000[0x1b0]; + struct Renderer *renderer; + unsigned char unknown_1b8[0x7e06 - 0x1b8]; + uint8_t did_ever_receive_bookend; +}; +ASSERT_OFFSET(struct Client, renderer, 0x1b0); +ASSERT_OFFSET(struct Client, did_ever_receive_bookend, 0x7e06); + +struct FecReceiver { + unsigned char unknown_000[0x88]; + int32_t last_submitted_frame; + unsigned char unknown_08c[0xb90 - 0x8c]; + struct Client *client; +}; +ASSERT_OFFSET(struct FecReceiver, last_submitted_frame, 0x88); +ASSERT_OFFSET(struct FecReceiver, client, 0xb90); + +extern const struct CodecVtable v4l2_vtable __attribute__((visibility("hidden"))); +extern void fec_error_check(struct FecReceiver *); +// SVLCodecV4L2::CheckStuck +extern void check_stuck(struct Codec *, bool debug); + +// The `EventsThread` runs separately from the video receiving code, and handles +// scheduled work. +// There's an existing periodic event that re-schedules itself every 1ms that +// handles various network related bookkeeping, checks and maintenance. This +// hooks at the end of that function where it calls a FEC error checking +// function while holding the receiver lock. +void recovery_watchdog(struct FecReceiver *fec) +{ + // Call the function whose call the hook replaces. + fec_error_check(fec); + if (fec->last_submitted_frame != -1) return; + + struct Client *client = fec->client; + if (!client) return; + + // Decoder initialization happens before the host starts sending video. + // Do not run the watchdog until this stream has received its first + // "bookend". + if (!__atomic_load_n(&client->did_ever_receive_bookend, __ATOMIC_ACQUIRE)) + return; + struct Renderer *renderer = client->renderer; + if (!renderer || !renderer->codec) return; + struct Codec *codec = renderer->codec; + if (codec->vtable != &v4l2_vtable) return; + if (__atomic_load_n(&codec->reset_state, __ATOMIC_ACQUIRE)) return; + if (!codec->initialized) return; + if (__atomic_load_n(&codec->media_thread_quitting, __ATOMIC_ACQUIRE)) return; + if (__atomic_load_n(&codec->reset_thread_quitting, __ATOMIC_ACQUIRE)) return; + + // SVLCodecV4L2::CheckStuck is normally called after submitting a frame + // for decoding (and also as part of some decoder error handling) and + // checks if the decoder is making progress. It requests a stream-reset + // after ~330ms of no progress. And then a local decoder reset after + // 800ms of no progress. We call it here solely for the stream-reset + // functionality. + check_stuck(codec, false); +} |
