Giter Club home page Giter Club logo

Comments (4)

devopvoid avatar devopvoid commented on June 14, 2024

I never tried that, due to lack of time. As far as I know, the native WebRTC implementation does not catch a device change, even if you enumerate the devices after one is (dis)connected. The implementation with (dis)connected callbacks is my own. Thus its a bit hard to tell device module to switch the device.

The next thing to consider are the media tracks managed by the peer connection, since each track (mic/cam) is bound to a device. You can switch tracks or the sources of tracks, but if the source is not updated it obviously goes wrong.

I would handle this issue with a low priority.

from webrtc-java.

Stasyanych avatar Stasyanych commented on June 14, 2024

Thank you for your quick response!
I want to share the method that I tried. Maybe it will be useful.
I found on the Internet that it is possible to replace a track by calling the sender.replaceTrack method and specify AudioTrack as an input parameter. In the browser implementation WebRTC, it looks something like this::

//...
var audioTrack = stream.getAudioTracks()[0];
var sender = pc.getSenders().find(function(s) {
      return s.track.kind == audioTrack.kind;
    });
 sender.replaceTrack(audioTrack);
//...

I tried to do something similar in the DeviceChangeListener.deviceConnected method. I re-created AudioTrack and tried to replace the track. This did not give a positive result. Code on kotlin::

connection.senders.find {
    it.track.kind.equals(MediaStreamTrack.AUDIO_TRACK_KIND)
}?.let { rtcSender ->
      val audioOptions = AudioOptions().apply {
          this.noiseSuppression = true
          this.echoCancellation = true
      }
      val audioSource = peerConnectionFactory?.createAudioSource(audioOptions)
      val audioTrack = peerConnectionFactory?.createAudioTrack("audioTrack", audioSource)
      rtcSender.replaceTrack(audioTrack)
  }

I also made an attempt to replace
rtcSender.replaceTrack(audioTrack)
on

rtcSender.track.dispose() // otherwise, the removeTrack method will hang
connection.removeTrack(rtcSender)
connection.addTrack(audioTrack, listOf("stream"))

also to no avail

from webrtc-java.

devopvoid avatar devopvoid commented on June 14, 2024

Hi @Stasyanych,
this should work at runtime when the media is already flowing and you send/receive audio:

AudioDevice captureDevice; // Get desired device.
AudioDevice playbackDevice; // Get desired device.

AudioDeviceModule deviceModule = new AudioDeviceModule();
// For sending audio.
deviceModule.setRecordingDevice(captureDevice);
deviceModule.initRecording();
// For receiving audio.
deviceModule.setPlayoutDevice(playbackDevice);
deviceModule.initPlayout();

PeerConnectionFactory factory = new PeerConnectionFactory(deviceModule);

// Initialize PeerConnection and establish connection.

// Change audio recording and playback device at runtime.

// For sending audio.
deviceModule.stopRecording();
deviceModule.setRecordingDevice(newRecordingDevice);
deviceModule.initRecording();
deviceModule.startRecording();

// For receiving audio.
deviceModule.stopPlayout();
deviceModule.setPlayoutDevice(newPlaybackDevice);
deviceModule.initPlayout();
deviceModule.startPlayout();

from webrtc-java.

Stasyanych avatar Stasyanych commented on June 14, 2024

Thank you! I will definitely check it out.

from webrtc-java.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.