versatica / libmediasoupclient

mediasoup client side C++ library
https://mediasoup.org
ISC License
286 stars 177 forks source link

Audio only plays back through the left channel (works fine in Chrome and vanilla C++ libwebrtc app) #114

Closed maxweisel closed 3 years ago

maxweisel commented 3 years ago

Heyo,

I've got a weird one that I can't seem to track down. When using libmediasoupclient, audio always plays back exclusively through the left channel. Both Chrome and my native C++ libwebrtc app that manually establishes the PeerConnection play back correctly.

My libmediasoupclient application and my vanilla C++ libwebrtc app link against the same static library for libwebrtc so there's no discrepancy there. I've looked through libmediasoupclient and I can't seem to figure out what it could be doing in order to cause audio to only play from the left channel. I pass a custom PeerConnectionFactory, but I use the same code to create it in both native applications.

Max

ibc commented 3 years ago

Not a libmediasoupclient issue. You may need to create your own PeerConnection factory instead of letting libwebrtc choose a default one based on OS, and libmediasoupclient let you pass such a factory.

maxweisel commented 3 years ago

I pass a custom PeerConnectionFactory, but I use the same code to create it in both native applications.

I am already doing this. I use the same PeerConnectionFactory in both versions.

maxweisel commented 3 years ago

Any chance I can get this re-opened? I really think this is a bug in libmediasoupclient (or possibly the C++ sdptransform implementation). It seems SDP shows this as a mono stream, but it gets turned into a stereo one before being handed to the PeerConnection.

mstarich commented 3 years ago

You might need to add something to your server.js file, under the mediaCodecs section. Mine looks like this:

               {
                     kind      : 'audio',
                     mimeType  : 'audio/opus',
                     clockRate : 48000,
                     channels  : 2,
                     parameters :
                    {
                         'useinbandfec' : 1,
                         'stereo'       : 1,
                         'ptime'        : 10
                    }
              }

maybe this will help you out. I know we get stereo audio.

Mike

On Thu, Apr 8, 2021 at 1:02 PM Max Weisel @.***> wrote:

Any chance I can get this re-opened? I really think this is a bug in libmediasoupclient (or possibly the C++ sdptransform implementation). It seems SDP shows this as a mono stream, but it gets turned into a stereo one before being handed to the PeerConnection.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/versatica/libmediasoupclient/issues/114#issuecomment-816131799, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABUZ7KH5XG7CFESDSVEWWFTTHYDV3ANCNFSM42TOTTYQ .

maxweisel commented 3 years ago

Thanks for the suggestion! Just gave that a shot,and I can see it showing up in the rtpParameters for the consumer on the client, but I'm still getting left-channel only whether the producer is Chrome or another libmediasoupclient client. Interestingly I now see that the stream is stereo before and after sdptransform does its thing, but still no change in output.

Do you use the built-in AudioDeviceModule? or something custom? I'm wondering if the built-in one for macOS has issues with stereo opus streams, or possibly it's treating a mono stream as stereo. I couldn't find any leads on the webrtc discuss group so I find it hard to believe it's the AudioDeviceModule. Will keep digging and report back.

Max

maxweisel commented 3 years ago

Still not entirely sure, but I can now replicate the bug without libmediasoupclient. I think @ibc is right here. I'll start with the AudioDeviceModule and work my way back up. Thanks for the help @mstarich!

ibc commented 3 years ago

Making stereo work is not easy in libwebrtc and Chrome. Cooperation of both sender and receiver is needed. However mediasoup-client and libmediasoupclient provide with OPUS options in the produce() APo for stereo to work. You just need to enable it in sender side (better than in server side). Then consume as usual in your C++ app and check the remote SDP and local SDP to verify that there is stereo=true in opus fmpt line. This has been tested.

Then, whether libwebrtc will play stereo or not that's another story unfortunately.

maxweisel commented 3 years ago

Thanks for the info! I was actually able to hunt this one down and it was entirely within AudioDeviceModule on the Mac. My libmediasoupclient application was bound to a 4-channel interface, AudioDeviceModule didn't know how to interpret it and mixed everything down to a single channel. My vanilla C++ libwebrtc app was bound to a 2-channel interface and worked as expected.

I suspect Chrome works because it doesn't use the built-in AudioDeviceModule and has different code for handling audio interfaces with more than 2 channels =S