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.

144 lines
3.3 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. local enabled
  13. config_get_bool enabled "$1" 'enabled' 0
  14. [ "$enabled" ] || return
  15. local input
  16. config_get input "$s" 'input'
  17. [ -z "$input" ] && {
  18. error "in section '$s' option input is missing"
  19. return 1
  20. }
  21. local output
  22. config_get output "$s" 'output'
  23. [ -z "$output" ] && {
  24. error "in section '$s' option output is missing"
  25. return 1
  26. }
  27. local input_arg
  28. [ "x$input" = 'xuvc' ] && {
  29. input_arg="input_uvc.so"
  30. local device
  31. config_get device "$s" 'device'
  32. [ -c "$device" ] || {
  33. error "device '$device' does not exist"
  34. return 1
  35. }
  36. input_arg="${input_arg} --device $device"
  37. local fps
  38. config_get fps "$s" 'fps'
  39. [ -n "$fps" ] && input_arg="${input_arg} --fps $fps"
  40. local yuv
  41. config_get_bool yuv "$s" 'yuv' 0
  42. [ "$yuv" -ne 0 ] && {
  43. input_arg="${input_arg} --yuv"
  44. local quality
  45. config_get quality "$s" 'quality'
  46. [ -n "$quality" ] && input_arg="${input_arg} --quality $quality"
  47. }
  48. local resolution
  49. config_get resolution "$s" 'resolution'
  50. [ -n "$resolution" ] && input_arg="${input_arg} --resolution $resolution"
  51. local led
  52. config_get led "$s" 'led'
  53. [ -n "$led" ] && input_arg="${input_arg} --led $led"
  54. }
  55. [ -z "$input_arg" ] && {
  56. error "unsuported input option '$input' in section '$s'"
  57. return 1
  58. }
  59. local output_arg
  60. [ "x$output" = 'xhttp' ] && {
  61. output_arg="output_http.so"
  62. local port
  63. config_get port "$s" 'port'
  64. [ -n "$port" ] && output_arg="${output_arg} --port $port"
  65. local listen_ip
  66. config_get listen_ip "$s" 'listen_ip'
  67. [ -n "$listen_ip" ] && output_arg="${output_arg} --listen $listen_ip"
  68. local www
  69. config_get www "$s" 'www'
  70. [ -n "$www" ] && output_arg="${output_arg} --www $www"
  71. local username
  72. config_get username "$s" 'username'
  73. local password
  74. config_get password "$s" 'password'
  75. [ -n "$username" ] && [ -n "$password" ] && output_arg="${output_arg} --credentials $username:$password"
  76. }
  77. [ "x$output" = 'xfile' ] && {
  78. output_arg="output_file.so"
  79. local folder
  80. config_get folder "$s" 'folder'
  81. [ -n "$folder" ] && output_arg="${output_arg} --folder $folder"
  82. local delay
  83. config_get delay "$s" 'delay'
  84. [ -n "$delay" ] && output_arg="${output_arg} --delay $delay"
  85. local link
  86. config_get link "$s" 'link'
  87. [ -n "$link" ] && output_arg="${output_arg} --link $link"
  88. local ringbuffer
  89. config_get ringbuffer "$s" 'ringbuffer'
  90. [ -n "$ringbuffer" ] && output_arg="${output_arg} --size $ringbuffer"
  91. local exceed
  92. config_get exceed "$s" 'exceed'
  93. [ -n "$exceed" ] && output_arg="${output_arg} --exceed $exceed"
  94. local command
  95. config_get command "$s" 'command'
  96. [ -n "$command" ] && output_arg="${output_arg} --command $command"
  97. }
  98. [ -z "$output_arg" ] && {
  99. error "unsuported output option '$output' in section '$s'"
  100. return 1
  101. }
  102. procd_open_instance
  103. procd_set_param command "$PROG" --input "$input_arg" --output "$output_arg"
  104. [ "x$output" = 'xhttp' ] && procd_add_mdns "http" "tcp" "$port" "daemon=mjpg-streamer"
  105. procd_close_instance
  106. }
  107. start_service() {
  108. config_load 'mjpg-streamer'
  109. config_foreach start_instance 'mjpg-streamer'
  110. }
  111. service_triggers() {
  112. procd_add_reload_trigger 'mjpg-streamer'
  113. }