Chrome Android 未使用 SDP 中的所有编解码器选项

And*_*rew 5 android google-chrome h.264 sdp webrtc

当我RTCRtpSender.getCapabilities("video").codecs;在 Chrome Android 上运行时,它包含 H264。但是,我运行var offer = RTCPeerConnection.createOffer()并查看offer.sdp它有时只会在报价中包含 H264。这导致我遇到需要 H264 的应用程序的问题 - 由于拒绝那些不包含 H264 的报价,它的工作不一致,而且我不知道如何强制 SDP 报价包含它。如何确保createOffer包含所有可用的编解码器?我宁愿不必对 SDP 进行任何手动编辑。

Rob*_*eri 2

我也面临着同样的问题。正如 Pedro Vergara 评论的那样,这看起来像是 Chrome Android 最新版本中引入的一个错误。目前,我做了一个简单的解决方法,RTCRtpSender.getCapabilities('video')在尝试创建 SDP 优惠之前,继续调用,直到它列出预期的 H.264 编解码器支持。像这样的东西:

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...
  }
}
Run Code Online (Sandbox Code Playgroud)

请注意,上面的代码通过使用 为 Chrome 提供了一些时间来提供 H.264 setTimeout()。仅仅拨打RTCRtpSender.getCapabilities('video')两次或更多次而不真正等待可能行不通。