Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome Android not using all codec options in SDP offer

When I run RTCRtpSender.getCapabilities("video").codecs; on Chrome Android it includes H264. However, I run var offer = RTCPeerConnection.createOffer() and look at offer.sdp it will only sometimes include H264 in the offer. This is causing me issues with an application that requires H264 - it works inconsistently as a result of rejecting those offers that don't include H264, and I don't know how to force the SDP offer to include it. How do I make sure createOffer includes all available codecs? I would prefer not to have to do any manual editing of the SDP.

like image 839
Andrew Avatar asked Oct 26 '22 22:10

Andrew


1 Answers

I've been facing the same problem. As Pedro Vergara commented, it looks like a bug introduced in recent versions of Chrome Android. For now, I did a simple workaround by keep calling RTCRtpSender.getCapabilities('video') until it lists the expected H.264 codec support, before any attempt to create the SDP offer. Something like this:

console.log('Waiting for H.264 codec support');
checkH264(20);

function checkH264(count) {
  if (count > 0) {
    console.log('Getting video codec capabilities');
    let capabilities = JSON.stringify(RTCRtpSender.getCapabilities('video').codecs);
    console.log(capabilities);
    if (capabilities.toLowerCase().includes('video/h264')) {
      console.log('H.264 support found. Ready to proceed now! =)');
      // Proceed to SDP offer creation...
    } else {
      setTimeout(checkH264, 1000, count - 1);
    }
  } else {
    console.warn('H.264 support not found');
    // Proceed with caution. SDP offer may not contain H.264...
  }
}

Notice that the code above gives some time for Chrome to make H.264 available, by using setTimeout(). Just calling RTCRtpSender.getCapabilities('video') twice or more without really waiting may not work.

like image 149
Roberto Gueleri Avatar answered Nov 13 '22 03:11

Roberto Gueleri