flutter-webrtc icon indicating copy to clipboard operation
flutter-webrtc copied to clipboard

Feedback/Echo when turn on speaker in Android devices

Open anhlevfx opened this issue 3 years ago • 5 comments

Describe the bug

Usually feedback/echo when turn on speaker, caller will hear he/she voice after delay about 500ms.

To Reproduce

Can use example source code of this lib, update newest version lib and build apk file, install on two devices and make a call. If the first time the feedback/echo not happening, try again and usually it will.

Expected behavior

No feedback/echo

Platform information

  • Flutter version: 2.8.0
  • Plugin version: 8.0.0
  • OS: Android
  • OS version: 10, 11

anhlevfx avatar Dec 15 '21 09:12 anhlevfx

Hi @cloudwebrtc I tried log audio mode before start audio capture and found that, audio mode is normal, not communication. So I fixed by add codes to make sure when call getUserAudio() must switch audio mode to communication.

private AudioTrack getUserAudio(ConstraintsMap constraints) {

        // Audio mode need set MODE_IN_COMMUNICATION to make sure have best performance audio handle for VOIP call

        AudioManager audioManager = (AudioManager) applicationContext.getSystemService(Context.AUDIO_SERVICE);
        audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);

        MediaConstraints audioConstraints;
        if (constraints.getType("audio") == ObjectType.Boolean) {
            audioConstraints = new MediaConstraints();
            addDefaultAudioConstraints(audioConstraints);
        } else {
            audioConstraints = MediaConstraintsUtils.parseMediaConstraints(constraints.getMap("audio"));
        }

        Log.i(TAG, "getUserMedia(audio): " + audioConstraints);

        String trackId = stateProvider.getNextTrackUUID();
        PeerConnectionFactory pcFactory = stateProvider.getPeerConnectionFactory();
        AudioSource audioSource = pcFactory.createAudioSource(audioConstraints);

        return pcFactory.createAudioTrack(trackId, audioSource);
    }

It should be updated in next release.

anhlevfx avatar Dec 15 '21 09:12 anhlevfx

Hi @anhlevfx,

I'm using flutter_webrtc version 0.8.3 and can't see this fix. To which version this fix is applied?

Thanks

gshomali avatar Mar 28 '22 01:03 gshomali

Hello @gshomali , You should update local lib by yourself by using my codes above.

anhlevfx avatar Mar 29 '22 15:03 anhlevfx

Thanks!

gshomali avatar Mar 31 '22 13:03 gshomali

Was this implemented in the latest releases?

tigrenok00 avatar Sep 14 '22 11:09 tigrenok00

looks like @vsomayaji fixed this issue, and I'd be happy to accept a PR to close this issue

cloudwebrtc avatar Oct 11 '22 15:10 cloudwebrtc

@cloudwebrtc I'd be happy to open a PR from https://github.com/aira/flutter-webrtc/pull/1, but as I'm neither a WebRTC nor Android expert, there are a couple of things that worry me about the approach:

  1. Is it safe to set the mode to MODE_IN_COMMUNICATION every time someone calls getUserMedia requesting an audio track? Or are there times when they would want the mode to stay MODE_NORMAL?
  2. When should we change the mode back to MODE_NORMAL? I found this comment suggesting that if we leave the mode set to MODE_IN_COMMUNICATION, it can affect the device's audio settings even after the app exits. 😬

Thank you for this awesome plugin!

vsomayaji avatar Oct 11 '22 16:10 vsomayaji