Custom audio source in native WebRTC?

3,251 views
Skip to first unread message

mike ads

unread,
Mar 16, 2016, 12:26:01 PM3/16/16
to discuss-webrtc
Hello. I'm writing a native WebRTC app on Windows and I'm trying to set WebRTC to use my own custom audio device for input instead of the default microphone.

I've been doing research on this and besides some patch from 2013 for the WebRTC code, i don't seem to see any high-level way of doing this when adding audio tracks to the stream or creating the peer connection.

I have the ID of the device i would like instead of the default microphone (it's a Virtual Audio Cable), and it seems like WebRTC uses Windows' waveOutOpen API to open the device for capture, so my strategy will be to hook that windows API and replace the ID with my own device's ID when it's called, which seems a lot more reliable than patching WebRTC code.

Is there any proper way of doing this that I'm missing? Or does WebRTC still only try to capture audio from the default microphone device set in Windows?

Thanks!

Henrik Andreasson

unread,
Mar 16, 2016, 2:50:58 PM3/16/16
to discuss...@googlegroups.com
Have you tried the SetRecordingDevice API?
WebRTC always tries to avoid using the WaveAPI on Windows. Mainly intended for XP.
It can be used as fallback in some other cases as well even on Win7 and later.

--

---
You received this message because you are subscribed to the Google Groups "discuss-webrtc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss-webrt...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/discuss-webrtc/860cf265-3b94-49a4-912c-d1c252a8ca0a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

mike ads

unread,
Mar 16, 2016, 11:02:11 PM3/16/16
to discuss-webrtc
It seems like the only way to access that API is by creating a new Voice Engine, then the VoEHardware interface, and then calling that API? Is there a way to access the Voice Engine that's already being used by WebRTC?

mike ads

unread,
Mar 17, 2016, 1:00:38 AM3/17/16
to discuss-webrtc
Figured it out. You need to create your own AudioDeviceModule and pass it to the PeerConnectionFactory, and then use the module to enumerate the audio devices and set the correct one.

Ricky B.

unread,
Nov 3, 2016, 11:19:00 AM11/3/16
to discuss-webrtc
Hi!
Would you mind to share some of your example code on how to achieve this?

Dave Lewanda

unread,
Nov 16, 2016, 4:08:49 AM11/16/16
to discuss-webrtc
I'd like to second that request for any example code you can provide to create the AudioDeviceModule.

Saggy

unread,
Jun 6, 2017, 10:28:22 AM6/6/17
to discuss-webrtc
I am using a custom audio module, passed it while createpeerconnectionfactory.  I am and feeding audio into it audio data after every 10ms (160 bytes) of data.  Audio is PCM 16 bit 8Khz and mono.  but not able to hear anything at remote end.  I have saved the audio in parallel to a wave file and can verify that teh wav file has the audio.  Any ideas?

Ricky B.

unread,
Jun 7, 2017, 1:49:57 AM6/7/17
to discuss-webrtc
I can verify that this approach works, for both, reading and writing audio to/from a webrtc peer. So check carefully if you have written to the buffer and if your are muted or any other of the usual disturbances of the force occured ;)

Saggy

unread,
Jun 8, 2017, 1:54:19 AM6/8/17
to discuss-webrtc
Hi,

If you are willing to look I can share the implementation with u..I used a custom AudioCaptureModule and passed it to peer connection fatcoyr while initializing it.  I can verify that audio is not muted coz I am writing to a wav file simultaneously.. Thanks, do I need a skywalker now? ;)

Chrystian Guth

unread,
Sep 12, 2017, 10:51:49 AM9/12/17
to discuss-webrtc
@Saggy 

I used to do this in the past, but now i'm getting an assertion fail.

#

# Fatal error in ../../webrtc/modules/audio_device/audio_device_buffer.cc, line 84

# last system error: 0

# Check failed: rtc::internal::AnnounceOnThread::IsCurrent(&main_thread_checker_)

# 

#


:(

Raj

unread,
Oct 2, 2018, 2:52:30 PM10/2/18
to discuss-webrtc
Ricky B,
Can you please share the solution or share a free virtual audio driver that can be used for commercial purpose.  Please respond ASAP.
Reply all
Reply to author
Forward
0 new messages