1
0

squeezelite.init 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2015 OpenWrt.org
  3. START=99
  4. STOP=1
  5. USE_PROCD=1
  6. PROG=/usr/bin/squeezelite
  7. #
  8. # Auto config checks for existing codec installations if not specified in config
  9. # Explicit disable (override) by setting appropriate "decode_xxx" in config
  10. #
  11. checkcodec() {
  12. config_get_bool auto_conf options "decoder_auto_conf" 1
  13. config_get_bool codec options "$1" $auto_conf
  14. if [ $codec -ne 0 ] ; then
  15. if [ $auto_conf -eq 0 ] ; then
  16. #force use requested
  17. echo "$4"
  18. else
  19. if [ -e "/usr/lib/${2}" ] ; then
  20. # Use codec (it exists)
  21. echo "$4"
  22. else
  23. #exclude non-existant
  24. if [ -z "$4" ] ; then
  25. echo "-e $3"
  26. else
  27. echo "$4,$3"
  28. fi
  29. fi
  30. fi
  31. else
  32. # explicitly excluded
  33. if [ -z "$4" ] ; then
  34. echo "-e $3"
  35. else
  36. echo "$4,$3"
  37. fi
  38. fi
  39. }
  40. make_cmdline() {
  41. cmdline=""
  42. config_get name options name "SqueezeWrt"
  43. cmdline="$cmdline -n $name"
  44. config_get model_name options model_name "SqueezeLite"
  45. cmdline="$cmdline -M $model_name"
  46. config_get interface options interface ""
  47. [ -n "$interface" ] && cmdline="$cmdline -I $interface"
  48. config_get device options device ""
  49. [ -n "$device" ] && cmdline="$cmdline -o $device"
  50. config_get alsa_buffer options alsa_buffer 200
  51. [ $alsa_buffer -eq 0 ] && alsa_buffer="200"
  52. config_get alsa_period options alsa_period 4
  53. [ $alsa_period -eq 0 ] && alsa_period="4"
  54. config_get alsa_format options alsa_format 16
  55. [ $alsa_format = "0" ] && alsa_format="16"
  56. config_get alsa_mmap options alsa_mmap 0
  57. cmdline="$cmdline -a $alsa_buffer:$alsa_period:$alsa_format:$alsa_mmap"
  58. config_get stream_bufsiz options stream_bufsiz 2048
  59. config_get out_bufsiz options out_bufsiz 3763
  60. cmdline="$cmdline -b $stream_bufsiz:$out_bufsiz"
  61. config_get max_sr options max_sr 0
  62. if [ $max_sr -ne 0 ] ; then
  63. max_sr="-r $max_sr"
  64. config_get sr_delay options sr_delay 0
  65. [ $sr_delay -ne 0 ] && max_sr="$max_sr:$sr_delay"
  66. cmdline="$cmdline $max_sr"
  67. fi
  68. config_get close_delay options close_delay 0
  69. [ $close_delay -ne 0 ] && cmdline="$cmdline -C $close_delay"
  70. config_get server_addr options server_addr ""
  71. if [ -n "$server_addr" ] ; then
  72. config_get server_port options server_port 3483
  73. cmdline="$cmdline -s $server_addr:$server_port"
  74. fi
  75. config_get priority options priority 0
  76. [ $priority -ne 0 ] && cmdline="$cmdline -p $priority"
  77. #
  78. # ***NOTE: codec lib names are in squeezelite.h (set decode_auto_conf to 0 to ignore)
  79. #
  80. local excl_codecs=""
  81. local vorbis_lib="libvorbisidec.so.1"
  82. excl_codecs=`checkcodec decode_flac "libFLAC.so.8" flac "$excl_codecs"`
  83. excl_codecs=`checkcodec decode_mp3 "libmad.so.0" mp3 "$excl_codecs"`
  84. excl_codecs=`checkcodec decode_aac "libfaad.so.2" aac "$excl_codecs"`
  85. [ -e "/usr/lib/$vorbis_lib" ] || vorbis_lib="libvorbisfile.so.3"
  86. excl_codecs=`checkcodec decode_ogg "$vorbis_lib" ogg "$excl_codecs"`
  87. excl_codecs=`checkcodec decode_wma_alac "libavcodec.so.56" wma,alac "$excl_codecs"`
  88. cmdline="$cmdline $excl_codecs"
  89. config_get dop options dsd_over_pcm 0
  90. [ $dop -eq 1 ] && cmdline="$cmdline -D"
  91. }
  92. start_service() {
  93. config_load squeezelite
  94. config_get_bool enabled options 'enabled' 0
  95. [ $enabled -eq 0 ] && return
  96. # Build command params
  97. make_cmdline
  98. procd_open_instance
  99. logger -t 'squeezelite' "$cmdline"
  100. procd_set_param command "$PROG" $cmdline
  101. procd_close_instance
  102. }
  103. # Wait for service to exit and release sockets
  104. reload_service() {
  105. stop
  106. sleep 2
  107. start
  108. }
  109. restart() {
  110. reload_service
  111. }