The reason for this problem is that the audio request is triggered by FAudioPlayoutRequester::Runnable::Run(), and Sleep() is used in this function to ensure that the data is requested once at a fixed time.
But the elapsed time of Sleep () is not accurate. Sleep(10ms) may will wait for 11ms.
So we comment the Sleep(), just keep this thread running while. This will bring more performance consumption, but it is not serious at present.
uint32 FAudioPlayoutRequester::Runnable::Run()
{
this->LastAudioRequestTimeMs = rtc::TimeMillis();
this->bIsRunning = true;
// Request audio in a loop until this boolean is toggled off.
while(this->bIsRunning)
{
int64_t Now = rtc::TimeMillis();
int64_t DeltaMs = Now - this->LastAudioRequestTimeMs;
// Check if the 10ms delta has elapsed, if it has not, then sleep the remaining
if(DeltaMs < FAudioPlayoutRequester::RequestIntervalMs)
{
//comment these codes
//int64_t SleepTimeMs = FAudioPlayoutRequester::RequestIntervalMs - DeltaMs;
//float SleepTimeSecs = (float)SleepTimeMs / 1000.0f;
//FPlatformProcess::Sleep(SleepTimeSecs);
continue;
}
// Update request time to now seeing as the 10ms delta has elapsed
this->LastAudioRequestTimeMs = Now;
// Actually request playout
this->RequestPlayoutFunc();
}
return 0;
}