Skip to content

Commit

Permalink
Add options to control realtime buffering lengths.
Browse files Browse the repository at this point in the history
  • Loading branch information
Themaister committed Oct 21, 2023
1 parent 6dd57f1 commit 38c9b57
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
11 changes: 3 additions & 8 deletions video/ffmpeg_decode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>(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>(unsigned(muglm::ceil(fps * opts.target_video_buffer_time)), 8);

video_queue.resize(num_frames);

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions video/ffmpeg_decode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 38c9b57

Please sign in to comment.