The Fix That Brought the Bug Back
I use a second iPhone at home through a stream ( the setup ): the phone's screen comes off USB as H.264, an old laptop's GPU re-encodes it, and a fork of Sunshine streams it to my main phone. The bug in this post appeared twice. The second time, my fix for the first one was the cause. Round one: nothing for ten seconds Connecting to the phone was slow. Sometimes the picture took a couple of…
The bug that had previously been fixed resurfaced in a surprising manner. Initially, the issue occurred when connecting to the phone, with the screen coming through USB as H.264 and the phone's GPU re-encoding it. Sunshine streamed it to the main phone, but a bug appeared after the initial fix. The problem manifested as a delay in connection, followed by no video traffic for ten seconds, and then the connection terminating (-100).
The issue arose because the H.264 decoder could only start at a keyframe, and a still screen never sent one.
The fix for the first bug was to remember the phone's latest keyframe and every subsequent frame (up to 900 frames or 60 MB). The transcoder would wake every 100 ms to notice new viewers and restart the GPU pipeline, replaying the cached frames. This approach resolved the issue in the first instance. However, two days later, the same problem resurfaced, but this time, the transcoder's log indicated a new issue.
The transcoder began reporting its mode every five seconds, showing that it was using the "passthrough" fallback. The passthrough mode was activated when the GPU pipeline failed, allowing at least a picture to be displayed.
The transcoder continued to experience issues, with the GPU encoder becoming unavailable and the process leaking threads. Every GPU pipeline restart resulted in a new thread being spawned, which held the pipeline's bus until the pipeline was dropped. This led to an accumulation of threads, eventually reaching 500. The leak occurred because a keyframe request while the phone was quiet restarted the GPU at most once every five seconds. The fallback mechanism did not resolve the issue, as it did not include a replay of frames.
The primary solution was updating the transcoder to include a timeout for bus threads, ensuring they exited promptly when their pipeline was dropped. Additionally, the fallback mechanism was modified to include replays, allowing new viewers to bypass the issue that caused the initial bug to resurface. The fixes addressed the root cause of the problem, restoring the system's functionality.
Rewritten by urgent.news; may contain errors — check the original.