- #!/bin/sh /etc/rc.common
- # Copyright (C) 2015 OpenWrt.org
-
- START=99
- STOP=1
-
- USE_PROCD=1
- PROG=/usr/bin/squeezelite
-
- # Check if a codec is disabled in the configuration (ie "decode_<codec> 0")
- checkcodec() {
- config_get_bool codec options "$1" 1
-
- if [ $codec -eq 0 ] ; then
- if [ -z "$3" ] ; then
- echo "-e $2"
- else
- echo "$3,$2"
- fi
- else
- echo "$3"
- fi
- }
-
- make_cmdline() {
- cmdline=""
-
- config_get name options name "SqueezeWrt"
- cmdline="$cmdline -n $name"
-
- config_get model_name options model_name "SqueezeLite"
- cmdline="$cmdline -M $model_name"
-
- config_get interface options interface ""
- [ -n "$interface" ] && cmdline="$cmdline -I $interface"
-
- config_get device options device ""
- [ -n "$device" ] && cmdline="$cmdline -o $device"
-
- config_get alsa_buffer options alsa_buffer 200
- [ $alsa_buffer -eq 0 ] && alsa_buffer="200"
-
- config_get alsa_period options alsa_period 4
- [ $alsa_period -eq 0 ] && alsa_period="4"
-
- config_get alsa_format options alsa_format 16
- [ $alsa_format = "0" ] && alsa_format="16"
-
- config_get alsa_mmap options alsa_mmap 0
- cmdline="$cmdline -a $alsa_buffer:$alsa_period:$alsa_format:$alsa_mmap"
-
- config_get stream_bufsiz options stream_bufsiz 2048
- config_get out_bufsiz options out_bufsiz 3763
- cmdline="$cmdline -b $stream_bufsiz:$out_bufsiz"
-
- config_get max_sr options max_sr 0
- if [ $max_sr -ne 0 ] ; then
- max_sr="-r $max_sr"
-
- config_get sr_delay options sr_delay 0
- [ $sr_delay -ne 0 ] && max_sr="$max_sr:$sr_delay"
- cmdline="$cmdline $max_sr"
- fi
-
-
- config_get close_delay options close_delay 0
- [ $close_delay -ne 0 ] && cmdline="$cmdline -C $close_delay"
-
- config_get server_addr options server_addr ""
- if [ -n "$server_addr" ] ; then
- config_get server_port options server_port 3483
- cmdline="$cmdline -s $server_addr:$server_port"
- fi
-
- config_get priority options priority 0
- [ $priority -ne 0 ] && cmdline="$cmdline -p $priority"
-
- local excl_codecs=""
- excl_codecs=$(checkcodec decode_flac flac "$excl_codecs")
- excl_codecs=$(checkcodec decode_mp3 mp3 "$excl_codecs")
- excl_codecs=$(checkcodec decode_aac aac "$excl_codecs")
- excl_codecs=$(checkcodec decode_ogg ogg "$excl_codecs")
- excl_codecs=$(checkcodec decode_wma_alac wma,alac "$excl_codecs")
- cmdline="$cmdline $excl_codecs"
-
- config_get dop options dsd_over_pcm 0
- [ $dop -eq 1 ] && cmdline="$cmdline -D"
- }
-
- start_service() {
- config_load squeezelite
-
- config_get_bool enabled options 'enabled' 0
- [ $enabled -eq 0 ] && return
-
- # Build command params
- make_cmdline
-
- procd_open_instance
- logger -t 'squeezelite' "$cmdline"
- procd_set_param command "$PROG" $cmdline
- procd_close_instance
- }
-
- # Wait for service to exit and release sockets
- reload_service() {
- stop
- sleep 2
- start
- }
-
- restart() {
- reload_service
- }
|