summaryrefslogtreecommitdiffstats
path: root/sound/squeezelite/files/squeezelite.init
blob: 3fa008f63ee589f1212eb43e444ef6c03defdb98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/bin/sh /etc/rc.common
# Copyright (C) 2015 OpenWrt.org

START=99
STOP=1

USE_PROCD=1
PROG=/usr/bin/squeezelite

#
# Auto config checks for existing codec installations if not specified in config
# Explicit disable (override) by setting appropriate "decode_xxx" in config
#
checkcodec() {
	config_get_bool auto_conf options "decoder_auto_conf" 1
	config_get_bool codec options "$1" $auto_conf
	
	if [ $codec -ne 0 ] ; then 
		if [ $auto_conf -eq 0 ] ; then
			#force use requested
			echo "$4"
		else
			if [ -e "/usr/lib/${2}" ] ; then
				# Use codec (it exists)
				echo "$4"
			else
 				#exclude non-existant
			        if [ -z "$4" ] ; then
			                echo "-e $3"
			        else
			                echo "$4,$3"
			        fi
			fi
		fi
	else
		# explicitly excluded
	        if [ -z "$4" ] ; then
	                echo "-e $3"
	        else
	                echo "$4,$3"
	        fi
	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 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"

	#
	# ***NOTE: codec lib names are in squeezelite.h (set decode_auto_conf to 0 to ignore)
	#
	local excl_codecs=""
	excl_codecs=`checkcodec decode_flac "libFLAC.so.8" flac "$excl_codecs"`
	excl_codecs=`checkcodec decode_mp3 "libmad.so.0" mp3 "$excl_codecs"`
	excl_codecs=`checkcodec decode_aac "libfaad.so.2" aac "$excl_codecs"`
	excl_codecs=`checkcodec decode_ogg "libvorbisfile.so.3" ogg "$excl_codecs"`
	excl_codecs=`checkcodec decode_wma_alac "libavcodec.so.56" 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
}