mediasoup-broadcaster-demo is recording from microphone

(repost - used wrong account)

I might be misunderstanding, but isn’t the mediasoup-broadcaster-demo supposed not produce any sound? Looking into MediaStreamTrackFactory.cpp it definitely looks like that:

auto fakeAudioCaptureModule = FakeAudioCaptureModule::Create();
if (!fakeAudioCaptureModule)
{
	MSC_THROW_INVALID_STATE_ERROR("audio capture module creation errored");
}

factory = webrtc::CreatePeerConnectionFactory(
  networkThread,
  workerThread,
  signalingThread,
  fakeAudioCaptureModule,
  webrtc::CreateBuiltinAudioEncoderFactory(),
  webrtc::CreateBuiltinAudioDecoderFactory(),
  webrtc::CreateBuiltinVideoEncoderFactory(),
  webrtc::CreateBuiltinVideoDecoderFactory(),
  nullptr /*audio_mixer*/,
  nullptr /*audio_processing*/);

and then in the fake_audio_capture_module.h

// This class implements an AudioCaptureModule that can be used to detect if
// audio is being received properly if it is fed by another AudioCaptureModule
// in some arbitrary audio pipeline where they are connected. It does not play
// out or record any audio so it does not need access to any hardware and can
// therefore be used in the gtest testing framework.

But when I run the application it grabs the computer’s microphone:

(I can also hear myself :slight_smile:)

I am running the mediasoup-broadcaster-demo on Ubuntu 18.04.04.

I don’t understand yet why, but it seems that the audio is taken from the PeerConnectionFactory created in the PeerConnection.cpp.

I have made a little experiment demonstrating this here. Basically just doing the same as in the MediaStreamTrackFactory.cpp but in the PeerConnection.cpp (in the PeerConnection constructor)

In case someone else runs into this problem, here is what worked for me:

Device::Load(…) and device.CreateSendTransport(…) both accept an optional “PeerConnection::Options” parameter which in turn contains an optional webrtc::PeerConnectionFactoryInterface* member. Provinding the same factory as used by the audio module (for example from MediaStreamTrackFactory’s createFactory()) apparently solves this problem.

There’s a gotcha though. The factory’s network thread needs to be created like this:

networkThread = rtc::Thread::CreateWithSocketServer().release();

Have a look at this for a working example.

I didn’t check for any side-effects, so use it with care. Anyway, as libmediasoup creators said repeatedly, this library is still work in progress.

Thanks for your sharing!