5

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.

Andrew
  • 6,295
  • 11
  • 56
  • 95
  • 3
    This is also happening to us, however we detected that H.264 is missing only the first time you load a website after killing Android Chrome and then asking for available codecs, even in `RTCRtpSender.getCapabilities("video").codecs;`. When navigating back and forth or F5'ing, H.264 appears consistently. We reported the bug to the Chromium team and are waiting for a response. https://bugs.chromium.org/p/webrtc/issues/detail?id=11620 – Pedro Adame Vergara May 29 '20 at 06:22
  • Why don't you tackle the issue from the other way around - if you are still going to handle the streaming, generate a remote offer that states that it is receive only and only supports h.264 and then locally create an answer for that remote offer. In that case, the answer is force to contain h.264 if it is available on the platform at all. – Rudolfs Bundulis Jun 02 '20 at 13:40

1 Answers1

2

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.

  • I'd buy you a beer if I could. I've been pulling out my hair for hours trying to figure out why casting with h264 wasn't working to the Chromecast with Google TV running android 10. – luca992 Mar 14 '21 at 01:53