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.

80 lines
1.6 KiB

  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2017 OpenWrt.org
  3. # TODO:
  4. # * support start multiple streams with one server
  5. # * support multiple usernames
  6. # * support HLS, etc.
  7. START=90
  8. STOP=10
  9. USE_PROCD=1
  10. SERVICE=v4l2rtspserver
  11. PROG=/usr/bin/$SERVICE
  12. error() {
  13. logger -t "$SERVICE" "$@"
  14. }
  15. start_instance() {
  16. local s="$1"
  17. config_get_bool enabled "$1" 'enabled' 0
  18. [ $enabled -eq 0 ] && return
  19. # validate device
  20. config_get device "$s" 'device'
  21. if [ ! -c "$device" ]; then
  22. error "device '$device' does not exist"
  23. return 1
  24. fi
  25. # get options
  26. config_get port "$s" 'port'
  27. config_get resolution "$s" 'resolution'
  28. config_get fps "$s" 'fps'
  29. config_get username "$s" 'username'
  30. config_get password "$s" 'password'
  31. config_get path "$s" 'path'
  32. config_get format "$s" 'format'
  33. # make sure format is uppercase
  34. format="$(echo $format | tr a-z A-Z)"
  35. # build args
  36. local args="-s"
  37. args="$args -P $port"
  38. args="$args -u ${path}"
  39. args="$args -F $fps"
  40. args="$args -G ${resolution}"
  41. if [ ! -z "$format" ]; then
  42. args="$args -f$format"
  43. fi
  44. args="$args -c" # fixes issue with corrupt frames with H264
  45. if [ -n "$username" ]; then
  46. args="$args -U ${username}:${password}"
  47. fi
  48. cmd="$PROG $args $device"
  49. # procd stuff
  50. procd_open_instance
  51. procd_set_param file /etc/config/$SERVICE
  52. procd_set_param command $cmd
  53. procd_set_param stdout 1
  54. procd_set_param stderr 1
  55. procd_add_mdns "rtsp" "tcp" "$port" "daemon=$SERVICE" "path=/$path"
  56. procd_close_instance
  57. }
  58. start_service() {
  59. config_load "$SERVICE"
  60. config_foreach start_instance "$SERVICE"
  61. }
  62. service_triggers() {
  63. procd_add_reload_trigger "$SERVICE"
  64. }