I gave up, ripped out all Channels, Sequences, and Coroutines, and went back to plain Java Thread + Blocking Queue. This makes me sad because Kotlin is usually so much more clear.
Reasons why:
- Sequences were a nice way to consume frames, but ran out of memory if I tried to get fancy running in parallel.
- So I moved to Actors + Channels, but javacv.FFmpegFrameRecorder started crashing java.
- So I tried to do something that limited race-ahead memory usage, but Channels and Sequences are two different teams/philosophies. There aren’t good examples on how to use them together that I have been able to find.
- Coroutine scope - I don’t quite get it yet. It appears that not all the examples have moved to best practices yet. (Some use GlobalScope but then other places say don’t use that, and I could enclose something in runBlocking, coroutineScope, suspend, produce, etc)