NokiMo
Stefan Dej (meteyou)
Stefan Dej (meteyou)

patreon


Mainsail Update 09-2024

At the beginning of the week, I was still swimming in the lake, and this morning, when I woke up, I saw snow on the surrounding mountains and it had become very cold. Just as this week behaved, this month has also felt and developed quite differently than I thought. But unlike this week, it developed positively. Now I'm sitting here (11:30 p.m.) with a cup of tea, writing this Patreon post, this time a bit more detailed. I hope you like it. Whether you prefer short status updates or such detailed information in the future, please let me know in the comments.

But now to the status update. I started this month by rebuilding the docs (https://docs.mainsail.xyz) and worked on the debug tool on the side. However, we had to adjust our priorities since Mr Yel is currently working on implementing WebRTC for Spyglass. Spyglass is a streaming backend programmed initially by a Patreon member (@roamingthings) here for the Raspberry Cam V3 and then further developed with Mr Yel.

Mr Yel discovered a bug in the WebRTC client for MediaMTX in Mainsail during his work. MediaMTX uses the "standard" WHEP to establish the connection between server and client, and he wants to use this for Spyglass as well. For the implementation of WHEP in Spyglass, Mr Yel had to delve deeply into this standard. With his knowledge and ability to incorporate debugging options on the server side, we significantly optimized the client in Mainsail during connection establishment and controlled shutdown (when the page is switched or the panel is closed) and eliminated some bugs.

With this knowledge, I tackled the implementation of WebRTC for Camera-Streamer and found some minor bugs in cleanly closing the streams. Unfortunately, this streamer does not use a standard but is close to WHEP.

Immediately after that, a user reported a bug (memory leak) in the MJPEGStreamer implementation in Mainsail. This bug was already known but could never really be identified or reproduced. However, due to his unique setup (extremely high FPS settings), we were able to find the error this time. This bug was especially noticeable in Firefox, but in hindsight, I think all browsers were affected.

And now, here is a brief technical explanation of the bug that we found. The streaming client MJPEGStreamer establishes a data stream that loads directly into RAM, and Mainsail reads along and detects whenever a new JPEG begins (MJPEG streams just concatenated JPEG images). The individual frames are extracted from the stream and displayed in a normal <img> tag (an HTML image element). I always thought the stream in the RAM caused problems in Firefox because it is restarted every 30 seconds so that the previews 30 seconds can be cleaned, but perhaps Firefox couldn't manage this (this process is called "garbage collection"). Nevertheless, this wasn't the bug, and Firefox was adequately cleaning up the streams from RAM. The problem was the temporary cache of the individual frames. Especially with higher FPS, the frames arrived via the stream faster than the browser could render them. If the next frame was finished before the old one could be rendered, the old one couldn't be deleted, which inflated the browser's RAM until it overflowed—debugging and fixing this occupied three crew members for almost a week.

After overhauling three webcam clients, I tackled the last essential ones and worked on the MJPEGStreamer-Adaptive mode, refactoring the entire code. I paid special attention to RAM management and massively improved performance during frame rendering (mainly achieved through code simplification).

For the rest of the month, I focused on small features and bug reports from the issue tracker on GitHub, working through the milestone for v2.13.0. I tried to fix or implement an issue every evening and then continued working on the debug tool. I won't go into these features in detail now, but I will list them. If you have questions, feel free to ask in the comments or directly on GitHub in the pull request. Here is a brief overview of the implementations:

Additionally, the following pull requests were contributed this month:

Now comes the part where I try to predict the future (which usually never turns out as expected).

Unfortunately, we have not yet been able to release the new MainsailOS version with Bookworm because Kwadfan is still trying to contribute to the network module to change the WLAN data afterward in CustomPiOS. This would then be available to all custom images provided with CustomPiOS and Raspberry Pi OS Bookworm, establishing more or less a "standard." A relatively well-known image that would also benefit from this is OctoPi, for example. Therefore, we also contacted foosel (the maintainer of Octoprint) to ensure it fits her project.

Furthermore, I will finish working through my milestone list to release v2.13.0. Only three issues are currently still open. Some pull requests still need to be approved by other team members. The debug tool will probably no longer be part of v2.13.0, as I only work on it on the side, and I prefer to release the webcam bug fixes first because I consider them very important.

I am also working on rewriting the docs from GitBook and moving them back to GitHub using mkdocs as a framework. This rewrite brings me a lot of joy as I try out every function of Mainsail myself again to describe it as accurately as possible. However, I'm noticing how patchy and outdated the current docs are, which really shouldn't be the case. I don't think I'll finish the docs in the next month either. This process will take another 2-3 months at the current pace I'm progressing.

So, you've received a detailed overview of the last month and a vague preview of the next month. And I realize once again how bad I am at writing texts. It's now 2 a.m., and I'm going to sleep (this post will be published at 12 noon).

Best regards,
Stefan Dej

Mainsail Update 09-2024

Related Creators