The issue was caused by the default behavior of the WebRTC negotiation when Opus is used as the audio codec.
For chromium-based browsers, opus stream information in SDP have to be set to stereo by "stereo=1" attribute. Otherwise, the browser will downmix the audio to mono by default.
This fix updated the PeerConnection setup logic to modify offer/answer SDP to include the "stereo=1" attribute for the Opus codec.
Changes
Introduced updateAnswerSdpToFixStereoAudioIssue() in index.js to modify the answer SDP to include the "stereo=1" attribute for the Opus codec.
Updated startWhepStream() in index.js to call updateAnswerSdpToFixStereoAudioIssue() to modify the offer and answer SDP.
Tests
Manual Tests
Confirmed that the audio is palyed in stereo in the Chromium-based following browsers:
Google Chrome 123.0.6312.106 (64-bit)
Microsoft Edge 123.0.2420.81 (64-bit)
OBS Studio (Browser Source) 30.0.2 (64-bit)
OBS Studio (Browser Source) 30.1.2 (64-bit)
Confirmed that the audio is played in stereo in the non-affected browser (regression test):
Fixes #1
Summary
The issue was caused by the default behavior of the WebRTC negotiation when Opus is used as the audio codec. For chromium-based browsers, opus stream information in SDP have to be set to stereo by "stereo=1" attribute. Otherwise, the browser will downmix the audio to mono by default.
This fix updated the PeerConnection setup logic to modify offer/answer SDP to include the "stereo=1" attribute for the Opus codec.
Changes
updateAnswerSdpToFixStereoAudioIssue()
in index.js to modify the answer SDP to include the "stereo=1" attribute for the Opus codec.startWhepStream()
in index.js to callupdateAnswerSdpToFixStereoAudioIssue()
to modify the offer and answer SDP.Tests
Manual Tests
Confirmed that the audio is palyed in stereo in the Chromium-based following browsers:
Confirmed that the audio is played in stereo in the non-affected browser (regression test):
Automated Tests
N/A