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.

83 lines
1.7 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. # pull out resolution width and height from string
  34. local w="$(echo $resolution | cut -d'x' -f1)"
  35. local h="$(echo $resolution | cut -d'x' -f2)"
  36. # make sure format is uppercase
  37. format="$(echo $format | tr a-z A-Z)"
  38. # build args
  39. local args="-s"
  40. args="$args -P $port"
  41. args="$args -u ${path}"
  42. args="$args -F $fps"
  43. args="$args -W $w"
  44. args="$args -H $h"
  45. args="$args -f$format"
  46. args="$args -c" # fixes issue with corrupt frames with H264
  47. if [ -n "$username" ]; then
  48. args="$args -U ${username}:${password}"
  49. fi
  50. cmd="$PROG $args $device"
  51. # procd stuff
  52. procd_open_instance
  53. procd_set_param file /etc/config/$SERVICE
  54. procd_set_param command $cmd
  55. procd_set_param stdout 1
  56. procd_set_param stderr 1
  57. procd_add_mdns "rtsp" "tcp" "$port" "daemon=$SERVICE" "path=/$path"
  58. procd_close_instance
  59. }
  60. start_service() {
  61. config_load "$SERVICE"
  62. config_foreach start_instance "$SERVICE"
  63. }
  64. service_triggers() {
  65. procd_add_reload_trigger "$SERVICE"
  66. }