I've modified dom's 2711 FFmpeg branch and I'm playing with it trying to decode multiple HEVC streams at the same time. From what I understand, the code should support multiple threads working with the argon (is there an official name for it?) hardware decoder. At least that's what I understand from the usage of thread_idx and the various "thread local variables".
This works decoding a single video when setting the av decoder options 'threads' value to (for example) "auto". I've now refactored the code, so only a single instance of the RPI_DEBUG struct is shared (and ref-counted) across multiple decoder instances, while each decoder has their own pool of zc images. This all works ok when decoding a single video, with or without multiple threads.
When decoding two videos, the following happens and both videos corrupt rather quickly:
I suspect that there's still some shared state that I'm missing in rpi_hevc_start_frame, rpi_hevc_decode_slice or rpi_hevc_end_frame. My naive understanding so far is that those functions either have their state in the respective AVCodecContext, or in the "slotted" variables selected by thread_idx. So multiple invocations for two videos should only refer to either their state in the AVCodecContext or in the thread local state selected during each rpi_hevc_start_frame/rpi_hevc_decode_slice/rpi_hevc_end_frame cycle.
To further prevent state leaking, I've also tried to lock frame decoding to a single user, by acquiring a global lock at the start of rpi_hevc_start_frame and releasing it at the end of rpi_hevc_end_frame. This also doesn't help. Anyone have any suggestion what I might overlook?