devopvoid / webrtc-java

WebRTC for desktop platforms running Java
Apache License 2.0
248 stars 60 forks source link

Possibility to specify AudioDevice for AudioSource #7

Closed vria closed 2 years ago

vria commented 3 years ago

Hi,

first of all thank you for this fascinating project!

Today it is possible to chose audio input / audio output device on the configuration page. However this choice is ignored when it comes to PeerConnectionClient, the application always uses the default OS settings.

The bottom line of this feature is to enable multiple audio tracks that are backed by multiple audio input devices. Is there a way to achieve this in current code ? If not, what improvement could you imagine ?

Thanks !

devopvoid commented 3 years ago

Today it is possible to chose audio input / audio output device on the configuration page. However this choice is ignored when it comes to PeerConnectionClient, the application always uses the default OS settings.

It's possible. Should be a one-liner or so. Currently I'm working on another project, but soon I will update the api.

The bottom line of this feature is to enable multiple audio tracks that are backed by multiple audio input devices. Is there a way to achieve this in current code ? If not, what improvement could you imagine ?

You can do this by adding multiple MediaStreamTracks to the RTCPeerConnection (addTrack or addTransceiver).

With the current state you could create individual MediaSources for the MediaStreamTracks.

vria commented 3 years ago

Hi @devopvoid, hope you are doing well.

If you don't have time to work on this issue I could take care of it. I think PeerConnectionClient::addAudio method lacks the code similar to addVideo:

AudioConfiguration audioConfig = config.getAudioConfiguration();
AudioDevice device = audioConfig.getRecordingDevice();
audioSource = new AudioDeviceSource();
audioSource.setAudioCaptureDevice(device);

But there is no such class as AudioDeviceSource where we can specify arbitrary audio recording device. Do you think it worth creating ? Could it be backed by C++ objetcs ?

devopvoid commented 3 years ago

Hi @vria, sorry for the late response!

In the current state of the project you can choose the audio recording and playback device by providing a AudioDeviceModule to the PeerConnectionFactory constructor. That way, I just mirrored the native API.

As for multiple arbitrary audio sources one have to implement the corresponding native code as well. If you are willing to do that, you are more than welcome :-)

I'll have a look into that, maybe there is better support by the API now. I just switched to the latest WebRTC version.

devopvoid commented 2 years ago

This is now possible with the AudioDeviceModule passed to the PeerConnectionFactory.

  1. var audioDevModule = new AudioDeviceModule();
  2. audioDevModule.setPlayoutDevice(...) or audioDevModule.setRecordingDevice(...)
  3. audioDevModule.initPlayout() or audioDevModule.initRecording() This step is important, otherwise the PeerConnection won't select your device.
  4. var factory = new PeerConnectionFactory(audioDevModule);
  5. ...