Placeholder-Software / Dissonance

Unity Voice Chat Asset
71 stars 5 forks source link

Performance issue with frame skips #58

Closed gydovrowl closed 6 years ago

gydovrowl commented 6 years ago

Context

We are using dissonance in our project to send voice chats from an admin client (windows 10, unity 2017.1) to multiple clients (android, galaxy S6, unity 2017.1). The admin client will host the dissonance server and the clients will connect to it. We noticed that some longer running processes can cause a frame skip, i.e. the following line will appear in the logs: [Dissonance:Recording] CapturePipelineManager: Detected a frame skip of (x)ms, forcing reset of Microphone capture pipeline. After this frame skip, performance will drop significantly.

Expected Behavior

After the Microphone capture pipeline reset, execution should continue normally.

Actual Behavior

Something in DissonanceComms.Update() causes a significant slowdown. This seems to trigger another frame skip, keeping the app locked in a frame skip-reset loop. I have attached a screenshot of the profiler demonstrating our problem: some operation causes a frame skip and after that most time is spent in the DissonanceComms.Update() pasted image at 2017_10_06 02_13 pm

Steps to Reproduce

  1. Add DissonanceSetup to scene, configure correct triggers.
  2. Perform some long running operation, causing a frame skip.
  3. Subsequent frames get stuck in DissonanceComms.Update() and cause another frame skip

Your Environment

martindevans commented 6 years ago

Hi gydovrowl,

Someone else reported a similar problem and we already have a fix merged in ready for the next version of Dissonance - exponentially backing off the skip detector so it will never report multiple skips within a short timespan. That will probably be available on the store within a week or two.

For now I suggest you simply remove skip detection. Find this section of code in Assets/Plugins/Dissonance/Core/Audio/Capture/CapturePipelineManager.cs (Line 95):

private bool DetectFrameSkip(float deltaTime)
{
    // If frame rate is less than 8 frames per second reset the transmission pipeline. If FPS is actually 8 then this will break
    // voice transmission (due to reset every frame) but that's fine because we can't really run good voice at 8fps anyway. In the
    // more likely case that this was just a stutter in frame rate it will reset the pipeline and fix the mic desync.
    var skip = deltaTime > 0.125f;
    if (skip)
        Log.Warn("Detected a frame skip of {0}ms, forcing reset of Microphone capture pipeline", deltaTime * 1000f);

    return skip;
}

And simply change it to:

private bool DetectFrameSkip(float deltaTime)
{
    return false;
}
gydovrowl commented 6 years ago

Hello @martindevans , Thank you for your quick response!

We will use this workaround for now and we will eagerly await the next release!

martindevans commented 6 years ago

Dissonance 3.0.3 just went live on the asset store with this fix merged in. I'll close this issue now, feel free to re-open it if this continues to be a problem.