Skip to content

Commit

Permalink
Make audio rate control a bit more aggressive.
Browse files Browse the repository at this point in the history
  • Loading branch information
Themaister committed Nov 4, 2023
1 parent 3ab33cd commit 492563c
Showing 1 changed file with 16 additions and 27 deletions.
43 changes: 16 additions & 27 deletions video/ffmpeg_decode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@ struct VideoDecoder::Impl
double get_estimated_audio_playback_timestamp(double elapsed_time);
double latch_estimated_video_playback_timestamp(double elapsed_time, double target_latency);
void latch_estimated_audio_playback_timestamp(double pts);
void set_audio_delta_rate_factor(float delta);
double get_audio_buffering_duration();
double get_last_video_buffering_pts();
unsigned get_num_ready_video_frames();
Expand Down Expand Up @@ -2197,20 +2198,14 @@ double VideoDecoder::Impl::get_audio_buffering_duration()
#endif
}

void VideoDecoder::Impl::latch_estimated_audio_playback_timestamp(double pts)
void VideoDecoder::Impl::set_audio_delta_rate_factor(float delta)
{
#ifdef HAVE_GRANITE_AUDIO
if (!stream)
return;

auto delta = float(pts - get_estimated_audio_playback_timestamp_raw());

if (delta > 0.25f)
if (delta > 0.10f)
{
// Speed up, audio buffer is too large.
stream->set_rate_factor(1.005f);
}
else if (delta < -0.25f)
else if (delta < -0.10f)
{
// Slow down.
stream->set_rate_factor(0.995f);
Expand All @@ -2219,8 +2214,18 @@ void VideoDecoder::Impl::latch_estimated_audio_playback_timestamp(double pts)
{
// This is inaudible in practice. Practical distortion will be much lower than outer limits.
// And should be less than 1 cent on average.
stream->set_rate_factor(1.0f + delta * 0.02f);
stream->set_rate_factor(1.0f + delta * 0.05f);
}
}

void VideoDecoder::Impl::latch_estimated_audio_playback_timestamp(double pts)
{
#ifdef HAVE_GRANITE_AUDIO
if (!stream)
return;

auto delta = float(pts - get_estimated_audio_playback_timestamp_raw());
set_audio_delta_rate_factor(delta);
#else
(void)pts;
#endif
Expand All @@ -2234,23 +2239,7 @@ void VideoDecoder::Impl::latch_audio_buffering_target(double target_buffer_time)

double current_time = get_audio_buffering_duration();
auto delta = float(current_time - target_buffer_time);

if (delta > 0.25f)
{
// Speed up, audio buffer is too large.
stream->set_rate_factor(1.005f);
}
else if (delta < -0.25f)
{
// Slow down.
stream->set_rate_factor(0.995f);
}
else
{
// This is inaudible in practice. Practical distortion will be much lower than outer limits.
// And should be less than 1 cent on average.
stream->set_rate_factor(1.0f + delta * 0.02f);
}
set_audio_delta_rate_factor(delta);
#else
(void)target_buffer_time;
#endif
Expand Down

0 comments on commit 492563c

Please sign in to comment.