quiniouben / vban

VBAN protocol open-source implementation
GNU General Public License v3.0
464 stars 65 forks source link

vban_emitter: alsa loopback Broken Pipe error #21

Open TGNThump opened 6 years ago

TGNThump commented 6 years ago

Hey, I'm getting the following error output:

Debug: socket_write invoked
Debug: audio_read invoked with size 256
Error: alsa_read: snd_pcm_writei failed: Broken pipe
ALSA lib pcm.c:8306:(snd_pcm_recover) overrun occurred
Warning: packet_check: packet too small
Error: main: packet prepared is invalid
Info: socket_close: closing socket with port 6980
quiniouben commented 6 years ago

Hi, thank you for reporting. I assume you use vban_emitter, right ? Can you give a try at arecord with same parameters ? eg (assuming you used 48kHz, stereo, 16bit): $ arecord -fdat This should show: ` Recording WAVE 'stdin' : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo

(garbage characters) `

TGNThump commented 6 years ago

Not sure if this is the same issue, I changed some settings around, but am still experiencing problems.

arecord -f dat -D send test.wav
Recording WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo

produces a clean file that sounds good.

When I run

 vban_emitter -i 10.8.0.6 -p 6980 -s Assistant -d send -l 4
vban_emitter version 2.0.5

Info: socket_open: opening socket with port 6980
Info: socket_open with port: 6980
Info: audio_init: config is direction in, backend , device send, buffer size 1024
Info: audio_backend_get_by_name: taking default backend alsa
Info: audio_set_map_config: new map config is nb channels 0
Info: audio_set_stream_config: new stream config is nb channels 2, sample rate 44100, bit_fmt 16I

I get a connection bunch of packets send (sounding choppy and broken, likely because of the incorrect sample rate) before the following happens:

Debug: packet_pcm_check: packet is vban: 1312899670, sr: 16, nbs: 63, nbc: 1, bit: 1, name: Assistant, nu: 1199
Debug: socket_write invoked
Debug: audio_read invoked with size 256
Error: alsa_read: snd_pcm_writei failed: Broken pipe
ALSA lib pcm.c:8306:(snd_pcm_recover) overrun occurred
Warning: packet_check: packet too small
Error: main: packet prepared is invalid
Info: socket_close: closing socket with port 6980

However, fixing the sample rate with

vban_emitter -i 10.8.0.6 -p 6980 -s Assistant -d send -l 4 -r 48000

results in no connection and the following:

vban_emitter version 2.0.5

Info: socket_open: opening socket with port 6980
Info: socket_open with port: 6980
Info: audio_init: config is direction in, backend , device send, buffer size 1024
Info: audio_backend_get_by_name: taking default backend alsa
Info: audio_set_map_config: new map config is nb channels 0
Info: audio_set_stream_config: new stream config is nb channels 2, sample rate 48000, bit_fmt 16I
Debug: alsa_open: snd_pcm_open
Debug: audio_read invoked with size 256
Error: alsa_read: snd_pcm_writei failed: Input/output error
Error: alsa_read: snd_pcm_writei failed: Input/output error
Info: socket_close: closing socket with port 6980

Any help would be greately apreciated.

quiniouben commented 6 years ago

Hi, thanks a lot for experimenting around. I must admit I am a bit puzzled but let's see how to sort and fix this out. So, first things first: what is your environment (hardware platform, audio device, os, audio engines (pulse, jack...), vban receptor application used) ?

TGNThump commented 6 years ago

My setup is a Ubuntu 17.10 Virtual Machine running on a FreeNAS Server. There are no hw audio devices attached and my audio is using the alsa loopback virtual device. My .asoundrc is the following:

pcm.!default {
  type asym
  capture.pcm "mic"
  playback.pcm "speaker"
}

pcm.mic {
  type plug
  slave {
    pcm "hw:Loopback,1,1"
    rate 48000
    format S16_LE
  }
}

pcm.speaker {
  type dmix
  ipc_key 2867
  slave {
    pcm "hw:Loopback,0,0"
    rate 48000
    format S16_LE
    channels 2
    period_size 1024
  }
}

pcm.send {
  type plug
  slave {
    pcm "hw:Loopback,1,0"
    rate 48000
    format S16_LE
  }
}

pcm.recv {
  type dmix
  ipc_key 2868
  slave {
    pcm "hw:Loopback,0,1"
    rate 48000
    format S16_LE
    channels 2
    period_size 1024
  }
}

I have the RECV incoming audio working with vban_receptor, but can't get SEND audio working with vban_emitter due to the errors above. The remote source for both VBAN streams (incoming and outgoing) is VoiceMeter Banana running on windows 10.

quiniouben commented 6 years ago

Hi, I just setup a Ubuntu 18.04 VM at mine and reusing your .asoundrc, I can reproduce the issue. Let me do my best to understand what is happening. My 2 cents is that it probably has to do with alsa loopback. Please don't expect immediate answer (my spare time is very sparse) but stay tuned.

quiniouben commented 6 years ago

Ok, I think I got it: loopback device cannot be configured with the small buffer size vban_emitter tries to use. Alsa is made in such a way that there is no failure reported when emitter set the parameters to the alsa device, but the parameters impossible to reach are "silently" not applied. I just learnt that user applications of the alsa API are supposed to read back the values after setting them, to know what are the actual values. The actual consequence is that when reading samples, emitter does it assuming the small buffer_size setting was accepted and then reads in with a too small buffer size, thus the io error reported. Unfortunately, managing this in emitter code requires to re-design a portion of it, because VBAN packets are small and the code was designed to build one packet at a time on the fly, without additional buffering between alsa read and tcp socket write. My apologies for this: it is my single experience with alsa API and I did it the simplest possible, as this project only aimed to provide usable implementation example of VBAN (not of alsa :)). Let's see what I can do for this.

quiniouben commented 6 years ago

So... It is not exactly because of the buffer size, but rather the way used to set alsa parameters. I created a branch with a different approach that seems to do the trick at mine. @TGNThump : Can you give it a try ? Simply checkout the alsaSetParamsRework branch and compile (, install) and run. If you confirm that works, I will have to double check how it affects latency (especially for the receptor). Waiting for your feedback.

TGNThump commented 6 years ago

Hey, I'm now getting the following error spammed:

Error: alsa_write: snd_pcm_writei failed: Broken pipe
ALSA lib pcm.c:8306:(snd_pcm_recover) underrun occurred
Warning: main: wrote 0 bytes, expected 1024 bytes

I also modified my asoundrc a bit, but nothing that should cause above.

pcm.!default {
  type asym
  capture.pcm "mic"
  playback.pcm "speaker"
}

pcm.mic {
  type dsnoop
  ipc_key 1
  ipc_key_add_uid yes
  slave {
    pcm "hw:Loopback,1,1"
    rate 48000
    format S16_LE
    channels 2
    period_size 1024
  }
}

pcm.speaker {
  type route
  slave {
    pcm speakermix
    channels 2
  }
  ttable {
    0.0 1
    1.1 1
  }
}

pcm.speakermix {
  type dmix
  ipc_key 2
  ipc_key_add_uid yes
  slave {
    pcm "hw:Loopback,0,0"
    rate 48000
    format S16_LE
    channels 2
    period_size 1024
  }
}

pcm.send {
  type plug
  slave {
    pcm "hw:Loopback,1,0"
    rate 48000
    format S16_LE
  }
}

pcm.recv {
  type plug
  slave {
    pcm "hw:Loopback,0,1"
    rate 48000
    format S16_LE
  }
}
quiniouben commented 6 years ago

Hi, sorry for late answer. I had done several short attempts and sometimes experienced the spamming mentioned, but like 1 time out of 10, and that's the point when I asked you to try, to have feedback on your particular setup. If you have it permanently, then, that's obviously another story... Mmh, I will try to spend more time on this asap.

TGNThump commented 6 years ago

vban_emitter seems to be working perfectly now, however I am having a similar issue with vban_reciever:

ben@ubuntu:~/vban⟫ vban_receptor -i 192.168.0.51 -p 6980 -s Assistant -d recv -l 3
vban_receptor version 2.0.5

Info: socket_open: opening socket with port 6980
Info: socket_open with port: 6980
Info: audio_init: config is direction out, backend , device recv, buffer size 3072
Info: audio_backend_get_by_name: taking default backend alsa
Info: audio_set_map_config: new map config is nb channels 0
Info: audio_set_stream_config: new stream config is nb channels 2, sample rate 48000, bit_fmt 16I
Error: alsa_write: snd_pcm_writei failed: Broken pipe
ALSA lib pcm.c:8306:(snd_pcm_recover) underrun occurred
Warning: main: wrote 0 bytes, expected 1024 bytes
Error: alsa_write: snd_pcm_writei failed: Broken pipe
ALSA lib pcm.c:8306:(snd_pcm_recover) underrun occurred
Warning: main: wrote 0 bytes, expected 1024 bytes
Error: alsa_write: snd_pcm_writei failed: Broken pipe
ALSA lib pcm.c:8306:(snd_pcm_recover) underrun occurred
Warning: main: wrote 0 bytes, expected 1024 bytes
Error: alsa_write: snd_pcm_writei failed: Broken pipe
ALSA lib pcm.c:8306:(snd_pcm_recover) underrun occurred
Warning: main: wrote 0 bytes, expected 1024 bytes

with simplified .asoundrc:

pcm.!default {
  type asym
  capture.pcm "mic"
  playback.pcm "speaker"
}

pcm.mic {
  type plug
  slave {
    pcm "hw:Loopback,1,1"
    format S16_LE
    channels 2
    rate 48000
  }
}

pcm.speaker {
  type plug
  slave {
    pcm "hw:Loopback,0,0"
    format S16_LE
    channels 2
    rate 48000
  }
}

pcm.send {
  type plug
  slave {
    pcm "hw:Loopback,1,0"
    format S16_LE
    channels 2
    rate 48000
  }
}

pcm.recv {
  type plug
  slave {
    pcm "hw:Loopback,0,1"
    rate 48000
    format S16_LE
  }
}
TheStaticTurtle commented 6 years ago

Hey I Have The Same Issue I Use This Command To Sart The Programm: vban_emitter -I 192.168.1.10 -P 6980 -S Kali -L 4 -N 1 -R 44100 -B Alsa -D Sysdefault:CARD=Device (Yes My Soundcard Is Named Device) I Was Runnig That On A Full Tower Computer And It Worked Fine But After That I Moved The Sound Card To My Phone In Otg On A Chroot An Here It Started Crashing It Work For 1sec And Then Stop:

Vban_emitter Version 2.0.5

Info: Socket_open: Opening Socket With Port 6980
Info: Socket_open With Port: 6980
Info: Audio_init: Config Is Direction In, Backend Alsa, Device Sysdefault:CARD=Device, Buffer Size 1024
Info: Audio_backend_get_by_name: Found Backend Alsa
Info: Audio_set_map_config: New Map Config Is Nb Channels 0
Info: Audio_set_stream_config: New Stream Config Is Nb Channels 1, Sample Rate 44100, Bit_fmt 16I
Shared Memfd Open() Failed: Function Not Implemented
Debug: Alsa_open: Snd_pcm_open
Debug: Audio_read Invoked With Size 256
Debug: Packet_pcm_check: Packet Is Vban: 1312899670, Sr: 16, Nbs: 127, Nbc: 0, Bit: 1, Name: Stream3, Nu: 1
Debug: Socket_write Invoked
Debug: Audio_read Invoked With Size 256
Debug: Packet_pcm_check: Packet Is Vban: 1312899670, Sr: 16, Nbs: 127, Nbc: 0, Bit: 1, Name: Stream3, Nu: 2
Debug: Socket_write Invoked
Debug: Audio_read Invoked With Size 256
Debug: Packet_pcm_check: Packet Is Vban: 1312899670, Sr: 16, Nbs: 127, Nbc: 0, Bit: 1, Name: Stream3, Nu: 3
Debug: Socket_write Invoked
Debug: Audio_read Invoked With Size 256
Debug: Packet_pcm_check: Packet Is Vban: 1312899670, Sr: 16, Nbs: 127, Nbc: 0, Bit: 1, Name: Stream3, Nu: 4
Debug: Socket_write Invoked
Debug: Audio_read Invoked With Size 256
Debug: Packet_pcm_check: Packet Is Vban: 1312899670, Sr: 16, Nbs: 127, Nbc: 0, Bit: 1, Name: Stream3, Nu: 5
Debug: Socket_write Invoked
Debug: Audio_read Invoked With Size 256
Debug: Packet_pcm_check: Packet Is Vban: 1312899670, Sr: 16, Nbs: 127, Nbc: 0, Bit: 1, Name: Stream3, Nu: 6
Debug: Socket_write Invoked
Debug: Audio_read Invoked With Size 256
Debug: Packet_pcm_check: Packet Is Vban: 1312899670, Sr: 16, Nbs: 127, Nbc: 0, Bit: 1, Name: Stream3, Nu: 7
Debug: Socket_write Invoked
Debug: Audio_read Invoked With Size 256
Debug: Packet_pcm_check: Packet Is Vban: 1312899670, Sr: 16, Nbs: 127, Nbc: 0, Bit: 1, Name: Stream3, Nu: 8
Debug: Socket_write Invoked
Debug: Audio_read Invoked With Size 256
Debug: Packet_pcm_check: Packet Is Vban: 1312899670, Sr: 16, Nbs: 127, Nbc: 0, Bit: 1, Name: Stream3, Nu: 9
Debug: Socket_write Invoked
Debug: Audio_read Invoked With Size 256
Debug: Packet_pcm_check: Packet Is Vban: 1312899670, Sr: 16, Nbs: 127, Nbc: 0, Bit: 1, Name: Stream3, Nu: 10

[.....]

Debug: socket_write invoked
Debug: audio_read invoked with size 256
Debug: packet_pcm_check: packet is vban: 1312899670, sr: 16, nbs: 127, nbc: 0, bit: 1, name: Stream3, nu: 203
Debug: socket_write invoked
Debug: audio_read invoked with size 256
Debug: packet_pcm_check: packet is vban: 1312899670, sr: 16, nbs: 127, nbc: 0, bit: 1, name: Stream3, nu: 204
Debug: socket_write invoked
Debug: audio_read invoked with size 256
Debug: packet_pcm_check: packet is vban: 1312899670, sr: 16, nbs: 127, nbc: 0, bit: 1, name: Stream3, nu: 205
Debug: socket_write invoked
Debug: audio_read invoked with size 256
Error: alsa_read: short read (expected 128, wrote 80)
Debug: packet_pcm_check: packet is vban: 1312899670, sr: 16, nbs: 79, nbc: 0, bit: 1, name: Stream3, nu: 206
Debug: socket_write invoked
Debug: audio_read invoked with size 256
Error: alsa_read: snd_pcm_writei failed: Broken pipe
ALSA lib pcm.c:8424:(snd_pcm_recover) overrun occurred
Warning: packet_check: packet too small
Error: main: packet prepared is invalid
Info: socket_close: closing socket with port 6980

the time taht it run is very randow nu parameter varies between 10 and 500

i'm running armv7 have no .asoundrc / alsa service (weird right) and vban_receptor works correctly

quiniouben commented 6 years ago

Hi @TGNThump and @TurtleForGaming , As you noticed, I found no time in the past weeks to look through this more precisely and I fear it will continue to be so in the next weeks, I am sorry. @TurtleForGaming

in your log ? It is not coming from vban_emitter, it might be completely harmless... or not.

TheStaticTurtle commented 6 years ago

Yes acutally i'm running on android with the nethunter chroot and alway had this problem i think by updating the kernel I could remove this error but i can't due to custom kernel made by someone else. So the line Shared Memfd Open() Failed: Function Not Implemented does ansolutlynothing on this program. I will try this branch instead

TheStaticTurtle commented 6 years ago

Nop still same error

quiniouben commented 6 years ago

Hi, sorry I made no progress since a long time. I have the feeling that fixing this would require to use a more sophisticated approach of the alsa api. I don't know when I can find time to experiment around. But I would come back to you.

RFXMed commented 5 years ago

Bonjour... Désolé c'est en Français (Merci google traduction ;-) J'ai malheureusement ce même type d'erreur en voulant installer un double flux entrant et sortant sur un raspberry pi3. Pour contourner le problème je dois descendre la fréquence échantillonnage à 11025Hz et les quelques "crash" sont résolus par un watchdog qui relance vban_emitter ... Je sais c'est du bricolage mais c'est stable avec possibilité de faire du multiroom avec des enceintes/micros wifi ...

quiniouben commented 5 years ago

English below,

Bonjour @RFXMed, merci pour ce retour d'expérience, je vais essayer de traduire pour les lecteurs non-francophones.

Hi @RFXMed, thanks for your experience feedback, let me try to translate: " Unfortunately I have the same type of erreur when trying to setup a duplex stream on a raspberry pi3. To workaround the trouble, I have to reduce the sample frequency at 11.025kHz and with a watchdog, I can restart vban_emitter when it still crashes from time to time. I know it is a bit handcrafted but it is stable and I can do some multiroom microphone / speaker over wifi. "

Mikroxy commented 3 years ago

Hey any solution for this?

tilleul commented 3 years ago

This PR might help: https://github.com/quiniouben/vban/pull/77

madpsy commented 2 years ago

@tilleul Your PR is interesting however didn't fix the program exiting for me. If I omit the break; at line 243 it stops it exiting and appears to continue just fine but that seems messy.

The real question is why packet too small occurs but this is better than it exiting in my situation.

sputnik13 commented 1 year ago

sorry to resurrect an old thread but I was running into the same problem and alsaSetParamsRework branch works for me... any reason it has not been merged to main?

sputnik13 commented 1 year ago

@quiniouben rebased and opened PR https://github.com/quiniouben/vban/pull/84