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.

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