mjpg-streamer.init 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 www "$s" 'www'
  56. [ -n "$www" ] && output_arg="${output_arg} --www $www"
  57. config_get username "$s" 'username'
  58. config_get password "$s" 'password'
  59. [ -n "$username" ] && [ -n "$password" ] && output_arg="${output_arg} --credentials $username:$password"
  60. fi
  61. if [ -z "$output_arg" ]; then
  62. error "unsuported output option '$output' in section '$s'"
  63. return 1
  64. fi
  65. procd_open_instance
  66. procd_set_param command "$PROG" --input "$input_arg" --output "$output_arg"
  67. procd_close_instance
  68. }
  69. start_service() {
  70. config_load 'mjpg-streamer'
  71. config_foreach start_instance 'mjpg-streamer'
  72. }
  73. service_triggers() {
  74. procd_add_reload_trigger 'mjpg-streamer'
  75. }