Asusoft
Asusoft

Reputation: 362

How to Ensure H264 Codec is Negotiated in WebRTC SDP on React Native?

I’m working on a React Native app that uses react-native-webrtc and SIP.js for video calls. The SIP server sends an INVITE SDP that includes support for multiple codecs, including H264, VP8, and VP9. However, when my app responds with the 200 OK SDP, H264 is not included, and VP8/VP9 are negotiated instead.

Here’s the relevant part of the INVITE SDP from the SIP server (caller):

m=video 10536 UDP/TLS/RTP/SAVPF 99 100 108 34 103 31 109 104
a=rtpmap:99 H264/90000
a=fmtp:99 packetization-mode=1;level-asymmetry-allowed=1;profile-level-id=42001F
a=rtpmap:100 VP8/90000
a=rtpmap:108 VP9/90000

And here’s the 200 OK SDP from my app (callee):

m=video 9 UDP/TLS/RTP/SAVPF 100 108
a=rtpmap:100 VP8/90000
a=rtpmap:108 VP9/90000

It seems that my app is not negotiating H264 properly, even though it is included in the INVITE SDP. Here’s what I’ve tried: 1. SDP Manipulation: I modified the SDP in peerConnection.createAnswer() to prioritize H264:

peerConnection.createAnswer()
  .then((answer) => {
    const updatedSDP = answer.sdp
      .replace(/m=video [^\r\n]+/, match => match.replace(/100 108/g, '99 100 108'))
      .replace(/a=rtpmap:100 VP8\/90000\r\n/g, 'a=rtpmap:99 H264/90000\r\n');

    peerConnection.setLocalDescription({
      type: answer.type,
      sdp: updatedSDP,
    });
  })
  .catch(error => console.error('Error creating answer:', error));
2.  Checked for H264 Support:
•   Verified that a=rtpmap:99 H264/90000 appears in the INVITE SDP.
•   Confirmed the SIP server supports H264.

3.  Configured Transceiver:

I attempted to set the preferred codec during peer connection setup:

peerConnection.addTransceiver('video', {
  direction: 'sendrecv',
  sendEncodings: [{ codecPayloadType: 99 }],
});

Despite these efforts, H264 is not being negotiated, and the response SDP always excludes H264.

My Questions:

1.  How can I ensure that my app negotiates H264 in the 200 OK SDP?
2.  Is there a way to force react-native-webrtc to include H264 in the codec list?
3.  Could this be an issue with the WebRTC build in react-native-webrtc? If so, how can I confirm and resolve it?

Any insights or suggestions to troubleshoot and resolve this would be greatly appreciated! Thank you.

Upvotes: 0

Views: 59

Answers (0)

Related Questions