diff --git a/video/ffmpeg_decode.cpp b/video/ffmpeg_decode.cpp index e50cc225..7681b200 100644 --- a/video/ffmpeg_decode.cpp +++ b/video/ffmpeg_decode.cpp @@ -938,13 +938,7 @@ bool VideoDecoder::Impl::init_video_decoder_post_device() // In a steady state, we will keep the audio buffer at 200ms saturation. // It would be possible to add new video frames dynamically, // but we don't want to end up in an unbounded memory usage situation, especially VRAM. - - unsigned num_frames = std::max(unsigned(muglm::ceil(fps * 0.2)), 8); - - // Buffer a bit more in realtime mode. - // Allows us to absorb network issues better. - if (opts.realtime) - num_frames *= 2; + unsigned num_frames = std::max(unsigned(muglm::ceil(fps * opts.target_video_buffer_time)), 8); video_queue.resize(num_frames); @@ -1524,7 +1518,8 @@ bool VideoDecoder::Impl::drain_audio_frame() // Don't buffer too much. Prefer dropping audio in lieu of massive latency. bool drop_high_latency = false; - if (opts.realtime && float(stream->get_num_buffered_audio_frames()) > 0.5f * stream->get_sample_rate()) + if (opts.realtime && float(stream->get_num_buffered_audio_frames()) > + (opts.target_realtime_audio_buffer_time * stream->get_sample_rate())) drop_high_latency = true; AVFrame *av_frame; diff --git a/video/ffmpeg_decode.hpp b/video/ffmpeg_decode.hpp index 82a60b3c..84836c04 100644 --- a/video/ffmpeg_decode.hpp +++ b/video/ffmpeg_decode.hpp @@ -31,6 +31,8 @@ class VideoDecoder { bool mipgen = false; bool realtime = false; + float target_video_buffer_time = 0.2f; + float target_realtime_audio_buffer_time = 0.5f; }; bool init(Audio::Mixer *mixer, const char *path, const DecodeOptions &options);