#!/bin/bash

SERVERIP=`cat SERVERIP`
HOSTNAME=`hostname`
NUM=`grep ^$HOSTNAME\| HOSTS | cut -d\| -f4`
if [ -z "$NUM" ]; then
  echo "error: could not find host number for `hostname`!"
  exit 1
fi
ASESSION=$((4000+NUM))
VSESSION=$((4100+NUM))
echo "i am $HOSTNAME machine $NUM asession $ASESSION vsession $VSESSION server at $SERVERIP"

# different res is ok, MUST be mjpg
v4l2-ctl --set-fmt-video=width=320,height=240,pixelformat=MJPG
amixer -c 1 sset Mic,0 80%,80% unmute cap

(while true; do arecord -t raw -c 1 -f S16_LE -r 22050 -D hw:1 | nc $SERVERIP $ASESSION; sleep 1; done) &
while true; do ./v4lcap -o | nc $SERVERIP $VSESSION; sleep 1; done
