-
Notifications
You must be signed in to change notification settings - Fork 3.4k
/
mjpg-streamer.init
144 lines (113 loc) · 3.27 KB
/
mjpg-streamer.init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/bin/sh /etc/rc.common
# Copyright (C) 2009-2014 OpenWrt.org
START=90
STOP=10
USE_PROCD=1
PROG=/usr/bin/mjpg_streamer
error() {
echo "${initscript}:" "$@" 1>&2
}
start_instance() {
local s="$1"
local enabled
config_get_bool enabled "$1" 'enabled' 0
[ "$enabled" ] || return
local input
config_get input "$s" 'input'
[ -z "$input" ] && {
error "in section '$s' option input is missing"
return 1
}
local output
config_get output "$s" 'output'
[ -z "$output" ] && {
error "in section '$s' option output is missing"
return 1
}
local input_arg
[ "x$input" = 'xuvc' ] && {
input_arg="input_uvc.so"
local device
config_get device "$s" 'device'
[ -c "$device" ] || {
error "device '$device' does not exist"
return 1
}
input_arg="${input_arg} --device $device"
local fps
config_get fps "$s" 'fps'
[ -n "$fps" ] && input_arg="${input_arg} --fps $fps"
local yuv
config_get_bool yuv "$s" 'yuv' 0
[ "$yuv" -ne 0 ] && {
input_arg="${input_arg} --yuv"
local quality
config_get quality "$s" 'quality'
[ -n "$quality" ] && input_arg="${input_arg} --quality $quality"
}
local resolution
config_get resolution "$s" 'resolution'
[ -n "$resolution" ] && input_arg="${input_arg} --resolution $resolution"
local led
config_get led "$s" 'led'
[ -n "$led" ] && input_arg="${input_arg} --led $led"
}
[ -z "$input_arg" ] && {
error "unsuported input option '$input' in section '$s'"
return 1
}
local output_arg
[ "x$output" = 'xhttp' ] && {
output_arg="output_http.so"
local port
config_get port "$s" 'port'
[ -n "$port" ] && output_arg="${output_arg} --port $port"
local listen_ip
config_get listen_ip "$s" 'listen_ip'
[ -n "$listen_ip" ] && output_arg="${output_arg} --listen $listen_ip"
local www
config_get www "$s" 'www'
[ -n "$www" ] && output_arg="${output_arg} --www $www"
local username
config_get username "$s" 'username'
local password
config_get password "$s" 'password'
[ -n "$username" ] && [ -n "$password" ] && output_arg="${output_arg} --credentials $username:$password"
}
[ "x$output" = 'xfile' ] && {
output_arg="output_file.so"
local folder
config_get folder "$s" 'folder'
[ -n "$folder" ] && output_arg="${output_arg} --folder $folder"
local delay
config_get delay "$s" 'delay'
[ -n "$delay" ] && output_arg="${output_arg} --delay $delay"
local link
config_get link "$s" 'link'
[ -n "$link" ] && output_arg="${output_arg} --link $link"
local ringbuffer
config_get ringbuffer "$s" 'ringbuffer'
[ -n "$ringbuffer" ] && output_arg="${output_arg} --size $ringbuffer"
local exceed
config_get exceed "$s" 'exceed'
[ -n "$exceed" ] && output_arg="${output_arg} --exceed $exceed"
local command
config_get command "$s" 'command'
[ -n "$command" ] && output_arg="${output_arg} --command $command"
}
[ -z "$output_arg" ] && {
error "unsuported output option '$output' in section '$s'"
return 1
}
procd_open_instance
procd_set_param command "$PROG" --input "$input_arg" --output "$output_arg"
[ "x$output" = 'xhttp' ] && procd_add_mdns "http" "tcp" "$port" "daemon=mjpg-streamer"
procd_close_instance
}
start_service() {
config_load 'mjpg-streamer'
config_foreach start_instance 'mjpg-streamer'
}
service_triggers() {
procd_add_reload_trigger 'mjpg-streamer'
}