FFmpegInteropX icon indicating copy to clipboard operation
FFmpegInteropX copied to clipboard

Problem with new HW acceleration and stream buffering

Open lukasf opened this issue 5 years ago • 8 comments

If we want to make our new native HW acceleration the new default, we will have a problem with streaming. The problem is this: Currently, we rely on the MSS buffer to get stable playback in streaming scenarios. The MSS buffer works by buffering our output samples. With the old HW acceleration (passthrough to system decoder), the output are compressed samples in system memory, so that works reasonably well (besides some general bugs in MSS buffering). But with the new HW acceleration, we output decoded frames in GPU memory. Using a buffer on that will quickly blow up GPU memory usage.

If we want to make our approach work with streaming as well, we'd have to provide our own internal buffering implementation.

One approach how this could be done: Instead of reading packets on demand, we could have an async read-ahead packet reader. It would read packets and fill stream buffers until a certain time limit or binary size limit is exceeded. Instead of having streams pull packets on demand, they have to wait until packets are made available.

lukasf avatar Jan 09 '21 11:01 lukasf

I wonder if we could get the OS to do the buffering for us, by loading ahead in the stream.

brabebhin avatar Jan 09 '21 15:01 brabebhin

The problem is that FFmpeg does all the stream creation and handling. And none of the buffering options seem to do any effect. There is no general read-ahead mechanism in FFmpeg.

lukasf avatar Jan 09 '21 16:01 lukasf

This sounds like a consumer-producer problem.

Take a look at this, looks promising...

https://github.com/cameron314/concurrentqueue

brabebhin avatar Jan 09 '21 17:01 brabebhin

That one could be helpful indeed

lukasf avatar Jan 09 '21 18:01 lukasf

Unfortunately I won't have much time to look into this in the following weeks...

In the mean time we could do a work around and force system codes when we create a stream source from URL.

brabebhin avatar Jan 21 '21 16:01 brabebhin

Same for me. I will be very busy the next 5-6 weeks. Been building a house since summer 2020, and it's almost finished now! ^^

lukasf avatar Jan 21 '21 18:01 lukasf

Sounds cool ^^. Congratulations!

brabebhin avatar Jan 21 '21 20:01 brabebhin

Thank you. Really looking forward to moving in, maybe in March!! :D But first we need to do the painting and floors ourselves, that will keep us busy for the next weeks...

lukasf avatar Jan 22 '21 11:01 lukasf