You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
3.0 KiB

  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. # Check if a codec is disabled in the configuration (ie "decode_<codec> 0")
  8. checkcodec() {
  9. local codec
  10. config_get_bool codec options "$1" 1
  11. if [ "$codec" -eq 0 ] ; then
  12. if [ -z "$3" ] ; then
  13. echo "-e $2"
  14. else
  15. echo "$3,$2"
  16. fi
  17. else
  18. echo "$3"
  19. fi
  20. }
  21. make_cmdline() {
  22. cmdline=""
  23. local name
  24. config_get name options name "SqueezeWrt"
  25. cmdline="$cmdline -n $name"
  26. local model_name
  27. config_get model_name options model_name "SqueezeLite"
  28. cmdline="$cmdline -M $model_name"
  29. local interface
  30. config_get interface options interface ""
  31. [ -n "$interface" ] && cmdline="$cmdline -I $interface"
  32. local device
  33. config_get device options device ""
  34. [ -n "$device" ] && cmdline="$cmdline -o $device"
  35. local alsa_buffer
  36. config_get alsa_buffer options alsa_buffer 200
  37. [ "$alsa_buffer" -eq 0 ] && alsa_buffer="200"
  38. local alsa_period
  39. config_get alsa_period options alsa_period 4
  40. [ "$alsa_period" -eq 0 ] && alsa_period="4"
  41. local alsa_format
  42. config_get alsa_format options alsa_format 16
  43. [ "$alsa_format" = "0" ] && alsa_format="16"
  44. local alsa_mmap
  45. config_get alsa_mmap options alsa_mmap 0
  46. cmdline="$cmdline -a $alsa_buffer:$alsa_period:$alsa_format:$alsa_mmap"
  47. local stream_bufsiz
  48. local out_bufsiz
  49. config_get stream_bufsiz options stream_bufsiz 2048
  50. config_get out_bufsiz options out_bufsiz 3763
  51. cmdline="$cmdline -b $stream_bufsiz:$out_bufsiz"
  52. local max_sr
  53. config_get max_sr options max_sr 0
  54. [ "$max_sr" -ne 0 ] && {
  55. max_sr="-r $max_sr"
  56. local sr_delay
  57. config_get sr_delay options sr_delay 0
  58. [ "$sr_delay" -ne 0 ] && max_sr="$max_sr:$sr_delay"
  59. cmdline="$cmdline $max_sr"
  60. }
  61. local close_delay
  62. config_get close_delay options close_delay 0
  63. [ "$close_delay" -ne 0 ] && cmdline="$cmdline -C $close_delay"
  64. local server_addr
  65. config_get server_addr options server_addr ""
  66. [ -n "$server_addr" ] && {
  67. local server_port
  68. config_get server_port options server_port 3483
  69. cmdline="$cmdline -s $server_addr:$server_port"
  70. }
  71. local priority
  72. config_get priority options priority 0
  73. [ "$priority" -ne 0 ] && cmdline="$cmdline -p $priority"
  74. local excl_codecs=""
  75. excl_codecs=$(checkcodec decode_flac flac "$excl_codecs")
  76. excl_codecs=$(checkcodec decode_mp3 mp3 "$excl_codecs")
  77. excl_codecs=$(checkcodec decode_aac aac "$excl_codecs")
  78. excl_codecs=$(checkcodec decode_ogg ogg "$excl_codecs")
  79. excl_codecs=$(checkcodec decode_wma_alac wma,alac "$excl_codecs")
  80. cmdline="$cmdline $excl_codecs"
  81. local dop
  82. config_get dop options dsd_over_pcm 0
  83. [ "$dop" -eq 1 ] && cmdline="$cmdline -D"
  84. }
  85. start_service() {
  86. config_load squeezelite
  87. local enabled
  88. config_get_bool enabled options 'enabled' 0
  89. [ "$enabled" -eq 0 ] && return
  90. # Build command params
  91. make_cmdline
  92. procd_open_instance
  93. logger -t 'squeezelite' "$cmdline"
  94. procd_set_param command "$PROG" $cmdline
  95. procd_close_instance
  96. }
  97. # Wait for service to exit and release sockets
  98. reload_service() {
  99. stop
  100. sleep 2
  101. start
  102. }
  103. restart() {
  104. reload_service
  105. }