~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
TODO

- fix memory leak
  - reboot on schedule (daily?)
  - alternative: fix memory leak
x- make webclt start on boot
x- make alsaloop start on boot
x- fix airpogo sound quality

- improve webctl
  - add volume control for SqueezeLite
xx  - refresh button for main page?
x  - bug in volume control ?when webpage is initialized with TV or AirPogo
x    selected?
xx  - mute during source switch
x  - fix volume (TV not working?, airpogo not tested)
x  - add mute (master)
x  - add current samplerate
x  - add source switch

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
commands

# deploy webctl to pogo
rsync -av --exclude=.* --exclude=temp . pogo:/opt/webctl
ssh pogo "/etc/init.d/webctl restart"

# alsaloop audio switching commands:
alsaloop -C line_in -P line --sync=0 --tlatency=50000
alsaloop -C squeeze_loop -P line_out --sync=0 --tlatency=50000
alsaloop -C airpogo_loop -P line_out --sync=0 --tlatency=50000

# prevent crackling sound when running without dmix/resampling
squeezelite -a 500:4 -n Pogo -o squeeze &
# this seems better: lower latency, tested on both 48KHz and 44.1KHz
squeezelite -n Pogo -o squeeze -a 100

# alsaloop (TV Line in, 48KHz)
alsaloop -C line_in -P line --sync=0 --tlatency=100000
# lower latency, higher CPU, works when not using dmix
alsaloop -C line_in -P line --sync=0 --tlatency=20000

# check current sample rates
cat /proc/asound/card0/pcm0p/sub0/hw_params
cat /proc/asound/card0/pcm0c/sub0/hw_params
# or
cat /proc/asound/card0/pcm0*/sub0/hw_params

# top CPU users
ps -eo pcpu,pid,args | sort -k 1 -r | head -5

# free memory (%)
free -t | grep "buffers/cache" | awk '{print $4/($3+$4) * 100}'

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
problems and solutions

- PogoPlug does not boot with "machid" uBoot variable set
  - solution: unset "machid" in uBoot environment
    fw_setenv machid

- resampling not working (very high CPU, unresponsive processes, no sound)
  - solution: switch to speexrate_best
    - seems to work better than samplerate_* (libsamplerate0)

- same sample rate for all streams
  - 48KHz - best sound quality
  - 44.1KH - poor sound quality
    - in TV/Line in?
    - ?? in SqueezeLite, possibly due to buffer size
  - solution: eliminate dmix from alsa config
    - caveat: cannot listen to multiple streams at once (no problem)
    - alsaloop will not start if squeezelite is powered on (a good thing?)

- crackling, very poor sound quality from SqueezeLite, even at native stream sample rate
  - solution: increase buffer time
    - "-a 100" (100ms) seems to work well (default is 20ms)

- cannot reset alsa config
  - solution: execute the following commands
    /etc/init.d/alsa-utils stop
    chmod -x /etc/init.d/alsa-utils
    rm /var/lib/alsa/asound.state
    reboot
    chmod +x /etc/init.d/alsa-utils
    /etc/init.d/alsa-utils start

- crackling, very poor sound quality from ShairPlay
  - solution: set "period_time=100000" in /etc/libao.conf
    - check period_size and buffer_size:
      cat /proc/asound/card1/pcm0p/sub2/hw_params
    - seems to work best when hw_params buffer_size and period_size are equal
      (4410)

- webctl does not start on boot
  - solution: update-rc.d webctl defaults
    - run this command with the name of each script in init.d that should start
      on boot

- memory leak (kernel?)
  - troubleshooting steps
    - leak seems to be in size-512 slabs as seen in slabtop (kernel leak)
      SUnreclaim in /proc/meminfo increases constantly after boot
    - guess: wifi driver is leaking
      - first attempt: disable power save mode (create file and reboot):
        # cat /etc/modprobe.d/8192cu.conf
        options 8192cu rtw_power_mgnt=0

- clicking sound on power on/off squeezelite
- clicking sound on new samplerate

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
info page design

content:
- uptime
- free memory
- top CPU usage
- wifi stats
- audio hardware parameters:
  - playback
  - capture

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

