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.

101 lines
2.4 KiB

  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2009-2014 OpenWrt.org
  3. START=90
  4. STOP=10
  5. USE_PROCD=1
  6. PROG=/usr/bin/mjpg_streamer
  7. error() {
  8. echo "${initscript}:" "$@" 1>&2
  9. }
  10. start_instance() {
  11. local s="$1"
  12. config_get_bool enabled "$1" 'enabled' 0
  13. [ $enabled -eq 0 ] && return
  14. config_get input "$s" 'input'
  15. if [ -z "$input" ]; then
  16. error "in section '$s' option input is missing"
  17. return 1
  18. fi
  19. config_get output "$s" 'output'
  20. if [ -z "$output" ]; then
  21. error "in section '$s' option output is missing"
  22. return 1
  23. fi
  24. local input_arg
  25. if [ "x$input" = 'xuvc' ]; then
  26. input_arg="input_uvc.so"
  27. config_get device "$s" 'device'
  28. if [ ! -c "$device" ]; then
  29. error "device '$device' does not exist"
  30. return 1
  31. fi
  32. input_arg="${input_arg} --device $device"
  33. config_get fps "$s" 'fps'
  34. [ -n "$fps" ] && input_arg="${input_arg} --fps $fps"
  35. config_get_bool yuv "$s" 'yuv' 0
  36. if [ $yuv -ne 0 ]; then
  37. input_arg="${input_arg} --yuv"
  38. config_get quality "$s" 'quality'
  39. [ -n "$quality" ] && input_arg="${input_arg} --quality $quality"
  40. fi
  41. config_get resolution "$s" 'resolution'
  42. [ -n "$resolution" ] && input_arg="${input_arg} --resolution $resolution"
  43. config_get led "$s" 'led'
  44. [ -n "$led" ] && input_arg="${input_arg} --led $led"
  45. fi
  46. if [ -z "$input_arg" ]; then
  47. error "unsuported input option '$input' in section '$s'"
  48. return 1
  49. fi
  50. local output_arg
  51. if [ "x$output" = 'xhttp' ]; then
  52. output_arg="output_http.so"
  53. config_get port "$s" 'port'
  54. [ -n "$port" ] && output_arg="${output_arg} --port $port"
  55. config_get listen_ip "$s" 'listen_ip'
  56. [ -n "$listen_ip" ] && output_arg="${output_arg} --listen $listen_ip"
  57. config_get www "$s" 'www'
  58. [ -n "$www" ] && output_arg="${output_arg} --www $www"
  59. config_get username "$s" 'username'
  60. config_get password "$s" 'password'
  61. [ -n "$username" ] && [ -n "$password" ] && output_arg="${output_arg} --credentials $username:$password"
  62. fi
  63. if [ -z "$output_arg" ]; then
  64. error "unsuported output option '$output' in section '$s'"
  65. return 1
  66. fi
  67. procd_open_instance
  68. procd_set_param command "$PROG" --input "$input_arg" --output "$output_arg"
  69. [ "x$output" = 'xhttp' ] && procd_add_mdns "http" "tcp" "$port" "daemon=mjpg-streamer"
  70. procd_close_instance
  71. }
  72. start_service() {
  73. config_load 'mjpg-streamer'
  74. config_foreach start_instance 'mjpg-streamer'
  75. }
  76. service_triggers() {
  77. procd_add_reload_trigger 'mjpg-streamer'
  78. }