# Pre-call tests (/en/realtime-media/voice/build/manage-connection-and-quality/pre-call-tests/unity)

> For AI agents: see the complete documentation index at [llms.txt](/llms.txt).

In video calling implementations that demand high communication quality, pre-call detection helps identify and troubleshoot issues beforehand, ensuring seamless real-time interaction.

      
  
      
  
      
  
      
  
      
  
      
  
      
  
      
  
      
    This page shows you how to use Video SDK to run pre-call tests to identify and troubleshoot communication quality issues in your game.

    ## Understand the tech [#understand-the-tech-8]

    Pre-call testing typically covers two aspects:

    * **Equipment quality test**

      To test whether the local microphone, speaker, and camera are working properly, you run an echo test. The basic process of conducting an echo test is as follows:

      **Pre-call echo test**

    ![Echo Test](https://assets-docs.agora.io/images/video-sdk/pre-call-echo-test.svg)

    * **Network quality analysis**

      The quality of the last mile network affects the smoothness and clarity of the audio and video that the user sends and receives. Last mile refers to the last leg of communication network between the edge server of the Agora SDRTN® and the end-user devices. Network quality analysis enables you to get feedback on the available bandwidth, packet loss rate, network jitter, and round-trip delay of the upstream and downstream last-mile networks. The following figure shows the basic process of running a last-mile probe test.

      **Pre-call last mile test**

    ![Last Mile Test](https://assets-docs.agora.io/images/video-sdk/pre-call-last-mile-test.svg)

    <CalloutContainer type="info">
      <CalloutDescription>
        Best practice is to run the device test first and then perform a network test.
      </CalloutDescription>
    </CalloutContainer>

    ## Prerequisites [#prerequisites-8]

    Ensure that you have implemented the [SDK quickstart](../index.mdx) project and that your game has obtained permissions to use the relevant devices.

    ## Implement pre-call testing [#implement-pre-call-testing-8]

    This section shows you how to implement pre-call testing in your project.

    ### Equipment quality test [#equipment-quality-test-8]

    The SDK provides the `StartEchoTest` method to test the network connection and whether the audio and video devices are working properly. Refer to the following steps to implement the device quality test:

    1. Before joining a channel, call `StartEchoTest`. Specify the `intervalInSeconds` parameter to set the delay time for the echo test. The value range is 2-10 seconds and the default value is 10.

    2. After starting the test, speak into the microphone. The user's audio is played back after a short delay. If the playback is normal, it means that the user's devices and upstream and downstream network are working normally.

    3. To stop the test, call `StopEchoTest`, and then call `JoinChannel` to join a channel.

    To implement running an echo test in your game, refer to the following code:

    ```csharp
    // Start Echo Test
    // Only a host can call StartEchoTest.
    RtcEngine.StartEchoTest(2);

    // Wait and check if you can hear voice playback

    // Stop the echo test
    // Call stopEchoTest to end the echo test. Until you call stopEchoTest, you cannot start another test or join a channel.
    RtcEngine.StopEchoTest();
    ```

    #### Audio recording device test [#audio-recording-device-test-2]

    To test whether a local audio recording device, such as a microphone, is working properly, refer to the following steps.

    1. Call `StartRecordingDeviceTest` and set the `indicationInterval` parameter to the time interval after which the callback is triggered.

    2. After starting the test, speak into the microphone. The SDK reports `uid = 0`, and the volume information of the device in the `OnAudioVolumeIndication` callback.

    3. When you are done testing, call `StopRecordingDeviceTest` to stop the test.
       <CalloutContainer type="info">
         <CalloutDescription>
           Best practice is to set the `indicationInterval` parameter to more than `200` milliseconds and not less than `10` milliseconds, otherwise the `OnAudioVolumeIndication` callback may not be received.
         </CalloutDescription>
       </CalloutContainer>

    To implement running a recording device test in your game, refer to the following code:

    ```csharp
    // Create the IRtcEngine object
    RtcEngine = Agora.Rtc.RtcEngine.CreateAgoraRtcEngine();
    UserEventHandler handler = new UserEventHandler(this);
    RtcEngineContext context = new RtcEngineContext(_appID, 0,
                CHANNEL_PROFILE_TYPE.CHANNEL_PROFILE_LIVE_BROADCASTING,
                AUDIO_SCENARIO_TYPE.AUDIO_SCENARIO_DEFAULT);
    // Initialize IRtcEngine
    RtcEngine.Initialize(context);
    // Set up listen callbacks
    RtcEngine.InitEventHandler(handler);
    // Get the IAudioDeviceManager object.
    IAudioDeviceManager audioDeviceManager = RtcEngine.GetAudioDeviceManager();
    // Enable local audio recording test
    audioDeviceManager.StartRecordingDeviceTest(100);

    class UserEventHandler : IRtcEngineEventHandler
    {
      // Implement the audio volume callback
      public override void OnAudioVolumeIndication(RtcConnection connection, AudioVolumeInfo[] speakers, uint speakerNumber, int totalVolume)
      {

      }
    }
    ```

    #### Audio playback device test [#audio-playback-device-test-2]

    To test that the local audio playback device is working properly, refer to the following steps:

    1. Call `StartPlaybackDeviceTest` and set the `testAudioFilePath` parameter to the absolute path of the audio file to be played.

    2. If the user hears the audio, the playback device is working properly. The SDK triggers the `OnAudioVolumeIndication` callback to report `uid = 1` and the volume information of the playback device.

    3. When you are done testing, call `stopPlaybackDeviceTest` to stop the test.

       ```csharp
       RtcEngine = Agora.Rtc.RtcEngine.CreateAgoraRtcEngine();
       UserEventHandler handler = new UserEventHandler(this);
       RtcEngineContext context = new RtcEngineContext(_appID, 0,
                   CHANNEL_PROFILE_TYPE.CHANNEL_PROFILE_LIVE_BROADCASTING,
                   AUDIO_SCENARIO_TYPE.AUDIO_SCENARIO_DEFAULT);
       RtcEngine.Initialize(context);
       // Set up listen callbacks
       RtcEngine.InitEventHandler(handler);
       // Test the local audio playback device
       IAudioDeviceManager audioDeviceManager = RtcEngine.GetAudioDeviceManager();
       audioDeviceManager.StartPlaybackDeviceTest("/User/hello.mp3");

       class UserEventHandler : IRtcEngineEventHandler
       {
         // Implement the audio volume callback interface
         public override void OnAudioVolumeIndication(RtcConnection connection, AudioVolumeInfo[] speakers, uint speakerNumber, int totalVolume)
         {

         }
       }
       ```

    #### Audio equipment loop detection [#audio-equipment-loop-detection]

    #### Audio device loopback test [#audio-device-loopback-test-2]

    To test if the local audio device loop is working properly, refer to the following steps:

    1. Call `StartAudioDeviceLoopbackTest` and set the `indicationInterval` parameter to the time interval after which the callback is triggered.

    2. After starting the test, speak into the microphone. The microphone captures the sound and then plays it on the playback device. The SDK returns two `oOnAudioVolumeIndication` callbacks to report the volume information of the audio capture device with `uid= 0`, and the audio playback device with `uid= 1`, respectively.

    3. When you are done testing, call `StopAudioDeviceLoopbackTest` to stop the recording device test.
       <CalloutContainer type="info">
         <CalloutDescription>
           Best practice is to set the `indicationInterval` parameter to more than `200` milliseconds and not less than `10` milliseconds, otherwise the `onAudioVolumeIndication` callback may not be received.
         </CalloutDescription>
       </CalloutContainer>

    To implement an audio loopback device test in your game, refer to the following code:

    ```csharp
    RtcEngine = Agora.Rtc.RtcEngine.CreateAgoraRtcEngine();
    UserEventHandler handler = new UserEventHandler(this);
    RtcEngineContext context = new RtcEngineContext(_appID, 0,
              CHANNEL_PROFILE_TYPE.CHANNEL_PROFILE_LIVE_BROADCASTING,
              AUDIO_SCENARIO_TYPE.AUDIO_SCENARIO_DEFAULT);
    RtcEngine.Initialize(context);
    // Set up the callbacks
    RtcEngine.InitEventHandler(handler);
    // Test the local audio device loop
    IAudioDeviceManager audioDeviceManager = RtcEngine.GetAudioDeviceManager();
    audioDeviceManager.StartAudioDeviceLoopbackTest(100);

    // Call StopAudioDeviceLoopbackTest when you are done testing
    audioDeviceManager.StopAudioDeviceLoopbackTest();

    class UserEventHandler : IRtcEngineEventHandler
    {
      // Implement the audio volume callback interface
      public override void OnAudioVolumeIndication(RtcConnection connection, AudioVolumeInfo[] speakers, uint speakerNumber, int totalVolume)
      {

      }
    }
    ```

    ### Network quality analysis [#network-quality-analysis-8]

    The SDK provides the `StartLastmileProbeTest` method to probe the last-mile network quality before joining a channel. The method returns information about the network quality score and network statistics. Take the following steps to run a last-mile network quality probe test:

    1. Before joining a channel or switching user roles, call `StartLastmileProbeTest` to start the network test. Set the probe configuration and the expected maximum bitrate in `LastmileProbeConfig`.

    2. After you start the test, the SDK triggers the following callbacks:

       * `OnLastmileQuality`: This callback is triggered two seconds after `StartLastmileProbeTest` is called. It provides feedback on the upstream and downstream network quality through a subjective `quality` score.

       * `OnLastmileProbeResult`: This callback is triggered 30 seconds after `StartLastmileProbeTest` is called. It returns objective real-time network statistics, including `packetLossRate`, network `jitter`, and `availableBandwidth`.

    3. Call `stopLastmileProbeTest` to stop last-mile network testing.

    To implement network quality testing in your game, refer to the following code:

    ```csharp
    RtcEngine = Agora.Rtc.RtcEngine.CreateAgoraRtcEngine();
    UserEventHandler handler = new UserEventHandler(this);
    RtcEngineContext context = new RtcEngineContext(_appID, 0,
                CHANNEL_PROFILE_TYPE.CHANNEL_PROFILE_LIVE_BROADCASTING,
                AUDIO_SCENARIO_TYPE.AUDIO_SCENARIO_DEFAULT);
    RtcEngine.Initialize(context);
    // Set up callbacks
    RtcEngine.InitEventHandler(handler);
    // Start last-mile network inspection
    RtcEngine.StartLastmileProbeTest(new LastmileProbeConfig());

    // Stop the network test.
    // Agora recommends not calling any other APIs until the test is over
    RtcEngine.StopLastmileProbeTest();

    class UserEventHandler : IRtcEngineEventHandler
    {
      // This callback occurs approximately 2 seconds after the Last-mile network test starts
      public override void OnLastmileQuality(int quality)
      {

      }

      // This callback occurs approximately 30 seconds after the Last-mile network test starts
      public override void OnLastmileProbeResult(LastmileProbeResult result)
      {

      }
    }
    ```

    ## Reference [#reference-8]

    This section contains content that completes the information on this page, or points you to documentation that explains other aspects to this product.

    ### Troubleshooting device and network issues [#troubleshooting-device-and-network-issues-8]

    If you encounter problems while running pre-call tests, first ensure that you have implemented the API calls properly. To troubleshoot device and network issues, refer to the following table:

    | Problem                                                                           | Solution                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
    | :-------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
    | Can't hear sound when testing audio devices.                                      | * Check that the recording device and the playback device are working properly, and are not occupied by other programs.
    * Check that the network connection is normal.                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
    | Cannot see the screen when testing video devices.                                 | - Check that the video device is working properly and not occupied by other programs.
    - Check whether the network connection is normal.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
    | Poor uplink network quality detected (packet loss > 5%; network jitter > 100ms)   | * Check that the local network is working properly.
    * Ensure that the bitrate of the published audio and video streams does not exceed the available uplink bandwidth by reducing the resolution or lowering the frame rate.                                                                                                                                                                                                                                                                                                                                                                                            |
    | Poor downlink network quality detected (packet loss > 5%; network jitter > 100ms) | - Check that the local network is working properly.
    - Ensure that the total bandwidth of the local subscription does not exceed the available downstream bandwidth by:
      * Reducing the number of subscribed audio and video streams on the receiving end or reducing the bitrate of published audio and video streams on the sending end.
      * Enabling dual-stream mode on the sending side and requesting to receive small streams on the receiving side to reduce bandwidth consumption.
      * Enabling the video stream fallback function or the multiple streams by priority fallback function at the receiving end. |

    ### API reference [#api-reference-8]

    * [`StartRecordingDeviceTest`](https://api-ref.agora.io/en/video-sdk/unity/4.x/API/class_iaudiodevicemanager.html#api_iaudiodevicemanager_startrecordingdevicetest)
    * [`StopRecordingDeviceTest`](https://api-ref.agora.io/en/video-sdk/unity/4.x/API/class_iaudiodevicemanager.html#api_iaudiodevicemanager_stoprecordingdevicetest)
    * [`StartPlaybackDeviceTest`](https://api-ref.agora.io/en/video-sdk/unity/4.x/API/class_iaudiodevicemanager.html#api_iaudiodevicemanager_startplaybackdevicetest)
    * [`StopPlaybackDeviceTest`](https://api-ref.agora.io/en/video-sdk/unity/4.x/API/class_iaudiodevicemanager.html#api_iaudiodevicemanager_stopplaybackdevicetest)
    * [`StartAudioDeviceLoopbackTest`](https://api-ref.agora.io/en/video-sdk/unity/4.x/API/class_iaudiodevicemanager.html#api_iaudiodevicemanager_startaudiodeviceloopbacktest)
    * [`StopAudioDeviceLoopbackTest`](https://api-ref.agora.io/en/video-sdk/unity/4.x/API/class_iaudiodevicemanager.html#api_iaudiodevicemanager_stopaudiodeviceloopbacktest)
    * [`StartEchoTest`](https://api-ref.agora.io/en/video-sdk/unity/4.x/API/class_irtcengine.html#api_irtcengine_startechotest2)
    * [`StopEchoTest`](https://api-ref.agora.io/en/video-sdk/unity/4.x/API/class_irtcengine.html#api_irtcengine_stopechotest)
    * [`StartLastmileProbeTest`](https://api-ref.agora.io/en/video-sdk/unity/4.x/API/class_irtcengine.html#api_irtcengine_startlastmileprobetest)
    * [`StopLastmileProbeTest`](https://api-ref.agora.io/en/video-sdk/unity/4.x/API/class_irtcengine.html#api_irtcengine_stoplastmileprobetest)
    * [`OnlastmileQuality`](https://api-ref.agora.io/en/video-sdk/unity/4.x/API/class_irtcengineeventhandler.html#callback_irtcengineeventhandler_onlastmilequality)
    * [`OnlastmileProbeResult`](https://api-ref.agora.io/en/video-sdk/unity/4.x/API/class_irtcengineeventhandler.html#callback_irtcengineeventhandler_onlastmileproberesult)

    
  
      
  
      
  
