Pipewire webrtc echo cancellation not working

156 Views Asked by At

I'm writing a pipewire node (pipewire version 1.0.0) to play a sound and record from microphone simultaneously, the audio spec is 8kHz sampling rate, 1 channel and SPA_AUDIO_FORMAT_S16 format. the app works and can play/record sound as well. the problem is where I enable libpipewire-module-echo-cancel and configure it to remove acoustic echo using webrtc as no sound is heard or recorded. I also changed the app to connect with Echo Cancellation Sink and Echo Cancellation Source nodes. the pipewire graph seems to be ok:

pw-dot output

the output of pw-top: (there are errors in Echo Cancellation Source and Echo Cancellation Playback increasing with time)

S   ID  QUANT   RATE    WAIT    BUSY   W/Q   B/Q  ERR FORMAT           NAME
S   28      0      0    ---     ---   ---   ---     0                  Dummy-Driver
S   29      0      0    ---     ---   ---   ---     0                  Freewheel-Driver
R   48   2048  48000   6.5ms  10.5us  0.15  0.00    0    S32LE 2 48000 alsa_input.platform-sound.stereo-fallback
R   32   1680   8000 178.4us 136.3us  0.00  0.00    0     F32P 2 48000  + Echo Cancellation Capture
R   33   1680   8000 339.5us  27.0us  0.01  0.00  689     F32P 2 48000  + Echo Cancellation Source
R   34   1680   8000 134.6us 128.2us  0.00  0.00    0     F32P 2 48000  + Echo Cancellation Sink
R   35   1680   8000 429.4us  19.9us  0.01  0.00  689     F32P 2 48000  + Echo Cancellation Playback
R   47      0      0  43.0us   1.1ms  0.00  0.02    0    S32LE 2 48000  + alsa_output.platform-sound.stereo-fallback
R   67      0      0   1.3ms   1.2ms  0.03  0.03    1     S16LE 1 8000  + myapp
R   68      0      0   3.2ms   2.8ms  0.08  0.07    1     S16LE 1 8000  + myapp

pw-link -l :

Echo Cancellation Capture:input_FL
  |<- alsa_input.platform-sound.stereo-fallback:capture_FL
Echo Cancellation Capture:input_FR
  |<- alsa_input.platform-sound.stereo-fallback:capture_FR
Echo Cancellation Source:capture_FL
  |-> myapp:input_FL
Echo Cancellation Source:capture_FR
  |-> myapp:input_FR
Echo Cancellation Sink:playback_FL
  |<- myapp:output_FL
Echo Cancellation Sink:playback_FR
  |<- myapp:output_FR
Echo Cancellation Playback:output_FL
  |-> alsa_output.platform-sound.stereo-fallback:playback_FL
Echo Cancellation Playback:output_FR
  |-> alsa_output.platform-sound.stereo-fallback:playback_FR
alsa_output.platform-sound.stereo-fallback:playback_FL
  |<- Echo Cancellation Playback:output_FL
alsa_output.platform-sound.stereo-fallback:playback_FR
  |<- Echo Cancellation Playback:output_FR
alsa_input.platform-sound.stereo-fallback:capture_FL
  |-> Echo Cancellation Capture:input_FL
alsa_input.platform-sound.stereo-fallback:capture_FR
  |-> Echo Cancellation Capture:input_FR
myapp:input_FL
  |<- Echo Cancellation Source:capture_FL
myapp:input_FR
  |<- Echo Cancellation Source:capture_FR
myapp:output_FL
  |-> Echo Cancellation Sink:playback_FL
myapp:output_FR
  |-> Echo Cancellation Sink:playback_FR

the related configuration of pipewire:

{   name = libpipewire-module-echo-cancel
      args = {
          library.name  = aec/libspa-aec-webrtc
          node.latency = 1700/8000
          # monitor.mode = false
          capture.props = {
             node.name = "Echo Cancellation Capture"
             #audio.channels = 1
             node.passive = true
             target.object = "alsa_input.platform-sound.stereo-fallback"
          }
          source.props = {
             node.name = "Echo Cancellation Source"
             #audio.channels = 1
          }
          sink.props = {
             node.name = "Echo Cancellation Sink"
             #audio.channels = 1
          }
          playback.props = {
             node.name = "Echo Cancellation Playback"
             #audio.channels = 1
             node.passive = true
             target.object = "alsa_output.platform-sound.stereo-fallback"
          }
      }
    }

I doubt to 8kHz sampling rate as aec3 seems not working with it, so changed to use aecm (aec.args = {mobile = 1}) but still not working.

another question is why the count of channels are shown 2 in all graphs and command outputs while the sound is mono channel and the app is written to work with mono channel as you can see:

params_play[0] = spa_format_audio_raw_build(&b_play, SPA_PARAM_EnumFormat,
            &SPA_AUDIO_INFO_RAW_INIT(
                .format = SPA_AUDIO_FORMAT_S16,
                .channels = 1,
                .rate = 8000 ));

I remind that the app worked before enabling echo cancellation but after enabling that, no sound is heard or recorded. can anyone help me to solve this problem? thanks.

note: I built pipewire for a embedded board with Yocto.

0

There are 0 best solutions below