I'm developing a real-time communication application using AgoraRTC, and I want to implement dynamic frame rate adjustment based on the current network quality

I'm looking for code examples, best practices

i have added this , should i increase interval or this is wrong way to update frame rate


const AgoraRTC = require('AgoraRTC');
let client = AgoraRTC.createClient({ mode: 'rtc', codec: 'h264' });

// Function to set the frame rate dynamically
async function setDynamicFrameRate() {
  // Perform the network probe test
  const result = await client.startLastmileProbeTest({
    probeConfig: {
      expectedUplinkBitrate: 1000,
      expectedDownlinkBitrate: 1000,
      audioPacketLossRate: 2,
      videoPacketLossRate: 2,
      lastmileProbeConfig: true
    }
  });

  // Calculate the recommended frame rate based on the network quality
  const recommendedFrameRate = calculateRecommendedFrameRate(result);

  // Set the video profile parameters
  client.setVideoProfile({ frameRate: recommendedFrameRate });
}

// Function to calculate the recommended frame rate based on the network quality
function calculateRecommendedFrameRate(networkQuality) {
  if (networkQuality.uplinkNetworkInfo.networkGrade < 2) {
    return 15;
  } else if (networkQuality.uplinkNetworkInfo.networkGrade < 3) {
    return 20;
  } else if (networkQuality.uplinkNetworkInfo.networkGrade < 4) {
    return 25;
  } else {
    return 30;
  }
}

// Start the dynamic frame rate adjustment
setInterval(setDynamicFrameRate, 10000);  // Adjust the interval as needed

Edited

updated package "agora-rtc-sdk-ng": "^4.19.1",

also, code


const AgoraRTC = require('AgoraRTC');
let client = AgoraRTC.createClient({ mode: 'rtc', codec: 'h264' });

// Function to set the frame rate dynamically

  async function setDynamicFrameRate() {
    // Perform the network probe test
    const stats = await client.getRTCStats();

    // Calculate the recommended frame rate based on the network quality
    const recommendedFrameRate = calculateRecommendedFrameRate(stats);
    console.log("rfr", stats.RTT, recommendedFrameRate);

    // Set the video profile parameters
    client.setEncoderConfiguration({
      frameRate: recommendedFrameRate,
    });
  }

  // Function to calculate the recommended frame rate based on the network quality
  function calculateRecommendedFrameRate(stats) {
    // Check the RTT (Round-Trip Time)
    if (stats.RTT < 100) {
      return 30;
    } else if (stats.RTT < 200) {
      return 25;
    } else if (stats.RTT < 300) {
      return 20;
    } else {
      return 15;
    }
  }

// Start the dynamic frame rate adjustment
setInterval(setDynamicFrameRate, 10000);  // Adjust the interval as needed

what should calculateRecommendedFrameRate for better quality of video?

0

There are 0 answers