# In-call quality monitoring (/en/realtime-media/interactive-live-streaming/build/optimize-quality-and-connection/in-call-quality-monitoring/unreal)

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

During a call, Video SDK triggers callbacks related to the video calling quality. These callbacks enable you to monitor your users' experience, troubleshoot issues, and optimize their overall experience

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

    After a user joins a channel, Video SDK triggers a series of callbacks every 2 seconds, reporting information such as uplink and downlink network quality, real-time interaction statistics, and statistics of local and remote audio and video streams.

    When there is a change in the audio or video state of a user, Video SDK triggers a callback to report the latest state and the reason for the change. The following figure shows the audio transmission process between app clients:

    **Audio transmission process**

    ![Audio transmission process](https://assets-docs.agora.io/images/video-sdk/in-call-quality.svg)

    To monitor the call quality, Agora provides the following call quality notifications:

    **Network quality**

    The network quality callback provides insight into the uplink and downlink last mile network quality for each participant in the channel. Last mile refers to the network from your device to Agora server. The [Network quality scores](#network-quality-score) are calculated based on factors such as sending or receiving bitrate, network packet loss rate, round-trip delay, and network jitter.

    **Statistics**

    The statistics callback, triggered every 2 seconds, reports key metrics such as call duration, the number of participants, system CPU usage, and app CPU usage.

    **Audio quality**

    Callbacks related to audio quality cover both local and remote audio streams. You monitor statistics and status changes, to gain insights into the quality of audio streams and any related reasons for status changes.

    **Video quality**

    Video quality callbacks provide information on both local and remote video streams. You receive statistics and status change notifications, that enable you to understand the quality of video streams and any related reasons for status changes.

    ## Prerequisites [#prerequisites-9]

    Ensure that you have implemented the [SDK quickstart](/en/realtime-media/video/get-started-sdk) in your project.

    ## Implement in-call quality monitoring [#implement-in-call-quality-monitoring-9]

    In `IRtcEngineEventHandler`, implement the following real-time interaction quality statistics callbacks and audio or video state monitoring callbacks to understand user interaction experience:

    * `onNetworkQuality`: Reports uplink and downlink last mile network quality.
    * `onRtcStats`: Reports real-time interaction statistics.
    * `onLocalAudioStats`: Reports statistics for the sent audio stream.
    * `onLocalAudioStateChanged`: Reports local audio stream state changes.
    * `onRemoteAudioStats`: Reports statistics for the received remote audio stream.
    * `onRemoteAudioStateChanged`: Reports remote audio stream state changes.
    * `onLocalVideoStats`: Reports statistics for the sent video stream.
    * `onLocalVideoStateChanged`: Reports local video stream state changes.
    * `onRemoteVideoStats`: Reports statistics for the received remote video stream.
    * `onRemoteVideoStateChanged`: Reports remote video stream state changes.

    In your game, add the following code:

    ```csharp
    class MyRtcEngineEventHandler : public IRtcEngineEventHandler
    {
      public:
      // Implement the onNetworkQuality callback
      virtual void onNetworkQuality(uid_t uid, int txQuality, int rxQuality) override
      {
        UE_LOG(LogTemp, Warning, TEXT("onNetworkQuality - Uid: %d, TxQuality: %d, RxQuality: %d"), uid, txQuality, rxQuality);
      }

      // Implement the onRtcStats callback
      virtual void onRtcStats(const agora::rtc::RtcStats& stats) override
      {
        UE_LOG(LogTemp, Warning, TEXT("onRtcStats - User(s): %d"), stats.userCount);
        UE_LOG(LogTemp, Warning, TEXT("Packet loss rate: %d"), stats.rxPacketLossRate);
      }

      // Implement the onRemoteVideoStateChanged callback
      virtual void onRemoteVideoStateChanged(uid_t uid, REMOTE_VIDEO_STATE state, REMOTE_VIDEO_STATE_REASON reason, int elapsed) override
      {
        UE_LOG(LogTemp, Warning, TEXT("onRemoteVideoStateChanged - Uid: %d, NewState: %d, Reason: %d, Elapsed: %d"), uid, state, reason, elapsed);
      }

      // Implement the onRemoteVideoStats callback
      virtual void onRemoteVideoStats(const agora::rtc::RemoteVideoStats& stats) override
      {
        UE_LOG(LogTemp, Warning, TEXT("onRemoteVideoStats - User id: %d, Received bitrate: %d, Total frozen time: %d"),
          stats.uid, stats.receivedBitrate, stats.totalFrozenTime);
      }

      // Implement the onLocalAudioStats callback
      virtual void onLocalAudioStats(const agora::rtc::LocalAudioStats& stats) override
      {
        UE_LOG(LogTemp, Warning, TEXT("onLocalAudioStats - Sent bitrate: %d, Sent sample rate: %d"),
          stats.sentBitrate, stats.sentSampleRate);
      }

      // Implement the onLocalAudioStateChanged callback
      virtual void onLocalAudioStateChanged(LOCAL_AUDIO_STREAM_STATE state, LOCAL_AUDIO_STREAM_ERROR error) override
      {
        UE_LOG(LogTemp, Warning, TEXT("onLocalAudioStateChanged - State: %d, Error: %d"), state, error);
      }

      // Implement the onRemoteAudioStats callback
      virtual void onRemoteAudioStats(const agora::rtc::RemoteAudioStats& stats) override
      {
        UE_LOG(LogTemp, Warning, TEXT("onRemoteAudioStats - User id: %d, Received bitrate: %d, Network delay: %d"),
          stats.uid, stats.receivedBitrate, stats.networkTransportDelay);
      }

      // Implement the onRemoteAudioStateChanged callback
      virtual void onRemoteAudioStateChanged(uid_t uid, REMOTE_AUDIO_STATE state, REMOTE_AUDIO_STATE_REASON reason, int elapsed) override
      {
        UE_LOG(LogTemp, Warning, TEXT("onRemoteAudioStateChanged - Uid: %d, NewState: %d, Reason: %d, Elapsed: %d"), uid, state, reason, elapsed);
      }

      // Implement the onLocalVideoStats callback
      virtual void onLocalVideoStats(const agora::rtc::VIDEO_SOURCE_TYPE source, const const agora::rtc::LocalVideoStats& stats) override
      {
        UE_LOG(LogTemp, Warning, TEXT("onLocalVideoStats - Sent frame rate: %d, Encoded frame width: %d"),
          stats.sentFrameRate, stats.encodedFrameWidth);
      }

      // Implement the onLocalVideoStateChanged callback
      virtual void onLocalVideoStateChanged(VIDEO_SOURCE_TYPE source, LOCAL_VIDEO_STREAM_STATE state, LOCAL_VIDEO_STREAM_ERROR error) override
      {
        UE_LOG(LogTemp, Warning, TEXT("onLocalVideoStateChanged - State: %d, Error: %d"), state, error);
      }
    };
    ```

    ## Reference [#reference-9]

    ### Network quality score [#network-quality-score-9]

    | Value | Enumeration         | Description                                                                    |
    | :---: | :------------------ | :----------------------------------------------------------------------------- |
    |   0   | `QUALITY_UNKNOWN`   | The quality is unknown or the user is not receiving a stream.                  |
    |   1   | `QUALITY_EXCELLENT` | The quality is excellent.                                                      |
    |   2   | `QUALITY_GOOD`      | The network quality is good, but the bitrate is slightly lower than excellent. |
    |   3   | `QUALITY_POOR`      | Users can feel the communication is slightly impaired.                         |
    |   4   | `QUALITY_BAD`       | Users cannot communicate smoothly.                                             |
    |   5   | `QUALITY_VBAD`      | The quality is so bad that users can barely communicate.                       |
    |   6   | `QUALITY_DOWN`      | The network is down, and users cannot communicate at all.                      |

    ### API reference [#api-reference-9]

    * [`onNetworkQuality`](https://api-ref.agora.io/en/video-sdk/unreal-engine/4.x/API/class_irtcengineeventhandler.html#callback_irtcengineeventhandler_onnetworkquality)

    * [`onRemoteAudioStateChanged`](https://api-ref.agora.io/en/video-sdk/unreal-engine/4.x/API/class_irtcengineeventhandler.html#callback_irtcengineeventhandler_onremoteaudiostatechanged)

    * [`onRemoteVideoStateChanged`](https://api-ref.agora.io/en/video-sdk/unreal-engine/4.x/API/class_irtcengineeventhandler.html#callback_irtcengineeventhandler_onremotevideostatechanged)

    * [`onLocalAudioStateChanged`](https://api-ref.agora.io/en/video-sdk/unreal-engine/4.x/API/class_irtcengineeventhandler.html#callback_irtcengineeventhandler_onlocalaudiostatechanged)

    * [`onLocalVideoStateChanged`](https://api-ref.agora.io/en/video-sdk/unreal-engine/4.x/API/class_irtcengineeventhandler.html#callback_irtcengineeventhandler_onlocalvideostatechanged)

    * [`onRemoteAudioStats`](https://api-ref.agora.io/en/video-sdk/unreal-engine/4.x/API/class_irtcengineeventhandler.html#callback_irtcengineeventhandler_onremoteaudiostats)

    * [`onRemoteVideoStats`](https://api-ref.agora.io/en/video-sdk/unreal-engine/4.x/API/class_irtcengineeventhandler.html#callback_irtcengineeventhandler_onremotevideostats)

    * [`onLocalAudioStats`](https://api-ref.agora.io/en/video-sdk/unreal-engine/4.x/API/class_irtcengineeventhandler.html#callback_irtcengineeventhandler_onlocalaudiostats)

    * [`onLocalVideoStats`](https://api-ref.agora.io/en/video-sdk/unreal-engine/4.x/API/class_irtcengineeventhandler.html#callback_irtcengineeventhandler_onlocalvideostats)

    * [`onRtcStats`](https://api-ref.agora.io/en/video-sdk/unreal-engine/4.x/API/class_irtcengineeventhandler.html#callback_irtcengineeventhandler_onrtcstats)

    
  
