Random NihAV news and rants

There’s not much going on with NihAV but it’s still something to write about, especially if you consider induced rants.

First, I’ve made a small clean-up and made some code improvements while testing what cargo clippy of version 1.100 complains about. All lints can be largely divided into four major categories: rather useful (useless imports or type conversions, using existing function instead of more complex expression e.g. .clamp(a, b) instead of .max(a).min(b) and so on), probably useful but using functions not present in the older rustc versions (e.g. .as_chunks() for constant chunk sizes), rather useless (IMO .is_multiple_of() and .div_ceil() belong to this category), and outright idiotic (or at least counterproductive). First example would be a proposal to use .checked_div() in code that looks like “if divisor is not zero, calculate some complex expressions involving division and do some other work, otherwise set some other variables and maybe report an error”—here you cannot get rid of the condition (since the alternative branch code is different) and adding a checked division function inside would not amount to anything. Another example would be constant complaining about loop indices; I understand that pure iterator version is less error-prone and maybe produces better-optimised code, but joining several iterators quickly becomes tedious and in some cases leads to rather monstrous expressions with higher cognitive load. That’s why I still mostly rely on common sense and don’t follow blindly all recommendations.

Another small but rather amusing thing is that somebody actually used my VP6 decoder for something and even bothered to report discrepancies in it and propose bit-exactness fixes (all via ruffle). My VP6 encoder had the same flaws so I fixed it as well. Still, who would’ve expected it to be useful?

Then I’ve finally added FLI/FLC decoding support (actually it’s mostly reused code from na_game_tool split into demuxer and decoder with various custom extensions thrown out). The reason is when I play FLI files with something libavcodec-based it does not bother even to tell an approximate duration of the file let alone seek in it. And invoking na_game_tool to decode file into raw video may get tiring when I want to quickly check some files from a game.

And finally I’ve changed nihav-sndplayer to use cpal crate for audio playback. Previously it relied on SDL2 for that task and I can’t say anything bad about it except for the excessive dependencies it bundles by default (like at least four audio decoders). Thus I tried to find something smaller but still up to the task. I’m glad to say that cpal works fine except that I had to bump compiler requirements to version 1.71 because of that. And that’s a prelude to the main rant.

My video player also relies on SDL2 for output and I tried to find something that can replace output libraries with something simpler and fewer dependencies. For video part I need single window with OpenGL support that would allow video playback by blitting RGB or YUV textures (preferably that I don’t have to write a shader for the latter), OSD overlay, and that it would handle basic keyboard and mouse events. No need even for window resizing let alone clipboard support, drag and drop or some other fancy bells and whistles. And it should work with the old rustc because while I can rely on the latest version I don’t see why I should, especially for the stuff that is essentially a thin wrapper over system libraries. And what do you know, that seems to be an impossible condition.

sdl2 crate that I use at least fits those requirements (while sdl3 fails to build with an old compiler version and apparently they still haven’t got to supporting sound properly). I also managed to compile a sample app using glfw but the result did not show any windows on one of my systems. With the rest it’s much worse as they often rely on Wayland protocol support crate that’s written in 2024 edition of the language (which means version 1.86 at least and less than two years old compiler). And the majority of the crates offering GUI plus OpenGL support also relies on winit, another crate I’d rather avoid (because it does too much and quite differently in every subsequent version). So the easiest way is to do nothing as even SDL1 is still around so one could expect subsequent versions to be around for some time as well. The alternative is to hack sdl2 crate in order to make it build smaller static version of SDL2 with all the cruft removed, or to re-implement Wayland protocol wrappers in an older Rust edition—and both make me think about many other much more pleasant ways to waste my time.

And the main problem here is crate authors not caring about compatibility. I can understand the desire to play with the latest language features but when you’re shipping a crate for others to use you should target the lowest possible version—not everybody wants or can use the latest version (gcc-rs exists already). When I bumped NihAV minimum compiler version to 1.69 it was mostly for the inline assembly features not offered previously. I can understand some complex code being expressed simpler with some new language features, but as I said above thin wrapper over some library calls should not have those (or pull dependencies with such characteristics—back in the day I managed to cut sdl2 crate dependencies in half by deleting five lines of code to generate random colour on request and rand crate dependency used for that). It’s with this mindset we got npm.js with all the consequences. Or boost. But since people do not care and there is nothing to make them care, I can only sigh and carry on.

Leave a Reply