# In-call quality monitoring (/en/realtime-media/broadcast-streaming/build/optimize-quality-and-connection/in-call-quality-monitoring/windows)

> 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-4]

    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-4]

    Ensure that you have implemented the [SDK quickstart](../../index) in your project.

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

    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 app, add the following code:

    ```cpp
    class FUserRtcEventHandler : public agora::rtc::IRtcEngineEventHandler
    {
      public:
      void onNetworkQuality(agora::rtc::uid_t uid, int txQuality, int rxQuality) override
      {
        AsyncTask(ENamedThreads::GameThread, [=]()
        {
          // Log uplink and downlink last mile network quality
          UBFL_Logger::Print(FString::Printf(TEXT("%s Network quality: UID: %u, TX Quality: %d, RX Quality: %d"), *FString(FUNCTION_MACRO), uid, txQuality, rxQuality), WidgetPtr->GetLogMsgViewPtr());
          // ... (your implementation)
        });
      }

      void onRtcStats(const agora::rtc::RtcStats& stats) override
      {
        AsyncTask(ENamedThreads::GameThread, [=]()
        {
          // Log real-time interaction statistics
          UBFL_Logger::Print(FString::Printf(TEXT("%s User(s): %d"), *FString(FUNCTION_MACRO), stats.userCount), WidgetPtr->GetLogMsgViewPtr());
          UBFL_Logger::Print(FString::Printf(TEXT("Packet loss rate: %d"), *FString(FUNCTION_MACRO), stats.rxPacketLossRate), WidgetPtr->GetLogMsgViewPtr());
          // ... (your implementation)
        });
      }

      void onLocalAudioStats(const agora::rtc::LocalAudioStats& stats) override
      {
        AsyncTask(ENamedThreads::GameThread, [=]()
        {
          // Log statistics for the sent audio stream
          UBFL_Logger::Print(FString::Printf(TEXT("%s Sent audio stream stats: %d"), *FString(FUNCTION_MACRO), stats.sentAudioBitrate), WidgetPtr->GetLogMsgViewPtr());
          // ... (your implementation)
        });
      }

      void onLocalAudioStateChanged(agora::rtc::LOCAL_AUDIO_STREAM_STATE state, agora::rtc::LOCAL_AUDIO_STREAM_ERROR error) override
      {
        AsyncTask(ENamedThreads::GameThread, [=]()
        {
          // Log local audio stream state changes
          UBFL_Logger::Print(FString::Printf(TEXT("%s Local audio stream state changed: State: %d, Error: %d"), *FString(FUNCTION_MACRO), state, error), WidgetPtr->GetLogMsgViewPtr());
          // ... (your implementation)
        });
      }

      void onRemoteAudioStats(const agora::rtc::RemoteAudioStats& stats) override
      {
        AsyncTask(ENamedThreads::GameThread, [=]()
        {
          // Log statistics for the received remote audio stream
          UBFL_Logger::Print(FString::Printf(TEXT("%s Received remote audio stream stats: %d"), *FString(FUNCTION_MACRO), stats.receivedBitrate), WidgetPtr->GetLogMsgViewPtr());
          // ... (your implementation)
        });
      }

      void onRemoteAudioStateChanged(agora::rtc::uid_t uid, agora::rtc::REMOTE_AUDIO_STATE state, agora::rtc::REMOTE_AUDIO_STATE_REASON reason, int elapsed) override
      {
        AsyncTask(ENamedThreads::GameThread, [=]()
        {
          // Log remote audio stream state changes
          UBFL_Logger::Print(FString::Printf(TEXT("%s Remote audio stream state changed: UID: %u, State: %d, Reason: %d, Elapsed: %d"), *FString(FUNCTION_MACRO), uid, state, reason, elapsed), WidgetPtr->GetLogMsgViewPtr());
          // ... (your implementation)
        });
      }

      void onLocalVideoStats(const agora::rtc::LocalVideoStats& stats) override
      {
        AsyncTask(ENamedThreads::GameThread, [=]()
        {
          // Log statistics for the sent video stream
          UBFL_Logger::Print(FString::Printf(TEXT("%s Sent video stream stats: %d"), *FString(FUNCTION_MACRO), stats.sentBitrate), WidgetPtr->GetLogMsgViewPtr());
          // ... (your implementation)
        });
      }

      void onLocalVideoStateChanged(agora::rtc::VIDEO_SOURCE_TYPE source, agora::rtc::LOCAL_VIDEO_STREAM_STATE state, agora::rtc::LOCAL_VIDEO_STREAM_ERROR error) override
      {
        AsyncTask(ENamedThreads::GameThread, [=]()
        {
          // Log local video stream state changes
          UBFL_Logger::Print(FString::Printf(TEXT("%s Local video stream state changed: Source: %d, State: %d, Error: %d"), *FString(FUNCTION_MACRO), source, state, error), WidgetPtr->GetLogMsgViewPtr());
          // ... (your implementation)
        });
      }

      void onRemoteVideoStats(const agora::rtc::RemoteVideoStats& stats) override
      {
        AsyncTask(ENamedThreads::GameThread, [=]()
        {
          // Log statistics for the received remote video stream
          UBFL_Logger::Print(FString::Printf(TEXT("%s Received remote video stream stats: %d"), *FString(FUNCTION_MACRO), stats.receivedBitrate), WidgetPtr->GetLogMsgViewPtr());
          // ... (your implementation)
        });
      }

      void onRemoteVideoStateChanged(agora::rtc::uid_t uid, agora::rtc::REMOTE_VIDEO_STATE state, agora::rtc::REMOTE_VIDEO_STATE_REASON reason, int elapsed) override
      {
        AsyncTask(ENamedThreads::GameThread, [=]()
        {
          // Log remote video stream state changes
          UBFL_Logger::Print(FString::Printf(TEXT("%s Remote video stream state changed: UID: %u, State: %d, Reason: %d, Elapsed: %d"), *FString(FUNCTION_MACRO), uid, state, reason, elapsed), WidgetPtr->GetLogMsgViewPtr());
          // ... (your implementation)
        });
      }
    };
    ```

    ## Reference [#reference-4]

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

    | Value | Enumeration         | Description                                                                                 |
    | :---: | :------------------ | :------------------------------------------------------------------------------------------ |
    |   0   | `QUALITY_UNKNOWN`   | Network quality is unknown.                                                                 |
    |   1   | `QUALITY_EXCELLENT` | The network quality is excellent.                                                           |
    |   2   | `QUALITY_GOOD`      | The network quality is good, but the bitrate may be slightly lower than excellent.          |
    |   3   | `QUALITY_POOR`      | The network quality is average, and users may experience a slight decrease in call quality. |
    |   4   | `QUALITY_BAD`       | The network quality is poor, and users are unable to make smooth calls.                     |
    |   5   | `QUALITY_VBAD`      | The network quality is extremely poor, making it almost impossible for users to make calls. |
    |   6   | `QUALITY_DOWN`      | The network connection is interrupted, and the user is completely unable to make a call.    |
    |   8   | `QUALITY_DETECTING` | Last-mile detection tests are underway.                                                     |

    ### API reference [#api-reference-4]

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

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

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

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

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

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

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

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

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

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

    
  
      
  
      
  
      
  
      
  
      
  
