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.

134 lines
3.3 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. #
  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 device options device ""
  47. [ -n $device ] && cmdline="$cmdline -o $device"
  48. config_get alsa_buffer options alsa_buffer 200
  49. [ $alsa_buffer -eq 0 ] && alsa_buffer="200"
  50. config_get alsa_period options alsa_period 4
  51. [ $alsa_period -eq 0 ] && alsa_period="4"
  52. config_get alsa_format options alsa_format 16
  53. [ $alsa_format = "0" ] && alsa_format="16"
  54. config_get alsa_mmap options alsa_mmap 0
  55. cmdline="$cmdline -a $alsa_buffer:$alsa_period:$alsa_format:$alsa_mmap"
  56. config_get stream_bufsiz options stream_bufsiz 2048
  57. config_get out_bufsiz options out_bufsiz 3763
  58. cmdline="$cmdline -b $stream_bufsiz:$out_bufsiz"
  59. config_get max_sr options max_sr 0
  60. if [ $max_sr -ne 0 ] ; then
  61. max_sr="-r $max_sr"
  62. config_get sr_delay options sr_delay 0
  63. [ $sr_delay -ne 0 ] && max_sr="$max_sr:$sr_delay"
  64. cmdline="$cmdline $max_sr"
  65. fi
  66. config_get close_delay options close_delay 0
  67. [ $close_delay -ne 0 ] && cmdline="$cmdline -C $close_delay"
  68. config_get server_addr options server_addr ""
  69. if [ -n "$server_addr" ] ; then
  70. config_get server_port options server_port 3483
  71. cmdline="$cmdline -s $server_addr:$server_port"
  72. fi
  73. config_get priority options priority 0
  74. [ $priority -ne 0 ] && cmdline="$cmdline -p $priority"
  75. #
  76. # ***NOTE: codec lib names are in squeezelite.h (set decode_auto_conf to 0 to ignore)
  77. #
  78. local excl_codecs=""
  79. excl_codecs=`checkcodec decode_flac "libFLAC.so.8" flac "$excl_codecs"`
  80. excl_codecs=`checkcodec decode_mp3 "libmad.so.0" mp3 "$excl_codecs"`
  81. excl_codecs=`checkcodec decode_aac "libfaad.so.2" aac "$excl_codecs"`
  82. excl_codecs=`checkcodec decode_ogg "libvorbisfile.so.3" ogg "$excl_codecs"`
  83. excl_codecs=`checkcodec decode_wma_alac "libavcodec.so.56" wma,alac "$excl_codecs"`
  84. cmdline="$cmdline $excl_codecs"
  85. config_get dop options dsd_over_pcm 0
  86. [ $dop -eq 1 ] && cmdline="$cmdline -D"
  87. }
  88. start_service() {
  89. config_load squeezelite
  90. config_get_bool enabled options 'enabled' 0
  91. [ $enabled -eq 0 ] && return
  92. # Build command params
  93. make_cmdline
  94. procd_open_instance
  95. logger -t 'squeezelite' "$cmdline"
  96. procd_set_param command "$PROG" $cmdline
  97. procd_close_instance
  98. }
  99. # Wait for service to exit and release sockets
  100. reload_service() {
  101. stop
  102. sleep 2
  103. start
  104. }
  105. restart() {
  106. reload_service
  107. }