pedroSG94 / RootEncoder

RootEncoder for Android (rtmp-rtsp-stream-client-java) is a stream encoder to push video/audio to media servers using protocols RTMP, RTSP, SRT and UDP with all code written in Java/Kotlin
Apache License 2.0
2.45k stars 761 forks source link

Echo Problem #1489

Open liuming1989 opened 1 month ago

liuming1989 commented 1 month ago

Scenario: I use GenericStream of the "RootEncoder" framework to push a video to the server, and play an audio stream in the push stream scenario. The other party plays the video I pushed and pushes an audio stream. It can be understood as a one-to-one call scenario. Question: Currently, when the other party speaks, he can hear his own echo. Is there any way to eliminate this echo?

pedroSG94 commented 1 month ago

Hello,

You can try using echoCanceler to true in the prepareAudio method: https://github.com/pedroSG94/RootEncoder/blob/master/library/src/main/java/com/pedro/library/base/StreamBase.kt#L130

liuming1989 commented 1 month ago

boolean prepared = genericStream.prepareVideo(width,height,vBitrate,rotation)&&genericStream.prepareAudio(sampleRate,isStereo,aBitrate,true); I initialize the streaming framework like this. Do you think there is any problem? Currently I play a sound stream and use the framework to push a video stream. The other party can hear the sound of the sound stream I play through the video stream.

pedroSG94 commented 1 month ago

Try to enable noiseSuppressor too. If the problem persist you can try change the audio source of the microphonemanager. using this createmicrophone method: https://github.com/pedroSG94/RootEncoder/blob/master/encoder/src/main/java/com/pedro/encoder/input/audio/MicrophoneManager.java#L89 You will need copy MicrophoneSource class, change createMicrophone adding other source and use this new MicrophoneSource modified in the constructor. Sources documentation: https://developer.android.com/reference/android/media/MediaRecorder.AudioSource

I will implement a way to do it without copy the class manually and change it but you can start your tests this way for now.

liuming1989 commented 1 month ago

Okay, thank you. If it's convenient, please try the usage scenario I mentioned and see how to solve such problems. My original framework used MediaRecorder AudioSource VOICE-COMMUNICATION audio source, but there may be very low streaming sound on some tablets, which is why we found the framework you developed. Currently, everything in the framework is very good, except for the issue of echo in my current usage scenario

pedroSG94 commented 1 month ago

Hello,

Can you give me a code example to test it? I'm not sure the way you are doing that communication to fully reproduce the case. For now, I added a way to modify MediaRecorder.AudioSource to MicrophoneSource: https://github.com/pedroSG94/RootEncoder/commit/b3e367551187b63de2d4f234a0030c405229ad45

liuming1989 commented 1 month ago

BidirectionalDemo.zip This is the demo I made, which has the function of streaming and playing videos. You can use two mobile phones to enter the corresponding address and manually enable the permission. I did not take any action I used RootEncoder as the framework for streaming videos The framework for playing videos is my own

Hope you can solve the problem, thank you

pedroSG94 commented 1 month ago

Hello,

I was testing the app but I'm not able to reproduce the echo problem. Remember that if you have the both phones nearby you will have echo because the audio provided by one device is captured by the other device. You should test it with 2 persons and with a distance that you are sure that the microphone is not able to detect the audio from the other device producing echo.

Also, you can use this gradle:

implementation 'com.github.pedroSG94.RootEncoder:library:b3e3675511'

And change the microphone media source like this (try to test all values):

genericStream = new GenericStream(LiveStreamActivity.this,this, new Camera2Source(this), new MicrophoneSource(MediaRecorder.AudioSource.VOICE_CALL));
liuming1989 commented 4 weeks ago
implementation 'com.github.pedroSG94.RootEncoder:library:2.4.5'
implementation 'com.github.pedroSG94.RootEncoder:library:b3e3675511'

![Uploading 11111.jpg…]() Are they cited together?

pedroSG94 commented 4 weeks ago

No, remove the first (2.4.5) and use only the other