-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp-nvr.jsonnet
More file actions
148 lines (130 loc) · 5.76 KB
/
app-nvr.jsonnet
File metadata and controls
148 lines (130 loc) · 5.76 KB
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
145
146
147
148
{
local common = import 'common.jsonnet',
local metaNameDesc (c) =
(if "name" in c then { name: c.name } else {}) +
(if "desc" in c then { desc: c.desc } else {}) +
(if "location" in c then { location: c.location } else {}) +
(if "address" in c then { address: c.address } else {}) +
(if "serial_number" in c then { serial_number: c.serial_number } else {}),
local dynamic (confApp, c) = (!("rec" in c) || (c.rec == "none")) && (!("allowDynamicSources" in confApp) || confApp.allowDynamicSources),
local camOrigMeta (cid, confApp, c) =
local meta = metaNameDesc(c);
{
__orig:: c + {
substreamOf: null,
camName: common.mk_cam_name(cid, confApp, c.id),
meta: meta,
},
meta: meta,
dynamic: dynamic(confApp, self.__orig),
},
local camOrigMetaSub (cid, confApp, c, ss) =
local origCamName = common.mk_cam_name(cid, confApp, c.id);
local meta = metaNameDesc(c) + { origin: origCamName, stream: ss.suffix };
{
__orig:: c + {
rec: if "rec" in ss then ss.rec else "none",
substreamOf: c.id,
id: c.id + "_" + ss.suffix,
recEventSource: common.mk_cam_name(cid, confApp, c.id),
camName: common.mk_cam_name_sub(cid, confApp, c.id, ss.suffix),
meta: meta,
} + (if "proc" in ss then { proc: ss.proc } else { proc: null }),
meta: meta,
dynamic: dynamic(confApp, self.__orig)
},
local substreams (c) = if "substreams" in c then c["substreams"] else [],
make_app (cid, appDef): {
local onvifSet = if "onvif" in appDef then appDef.onvif else [],
local rtspSet = if "rtsp" in appDef then appDef.rtsp else [],
local stripPathExt(p) =
local s = std.split(p, '/');
local basename = s[std.length(s)-1];
local e = std.split(basename, '.');
local res = std.join('.', e[:-1]);
res,
local mediafileSet = if "mediafile" in appDef then
std.map(function(p)
local res = {
id: stripPathExt(p),
path: p,
}; if std.type(p) == "string" then res else p,
appDef.mediafile) else [],
camOrigMeta: camOrigMeta,
camOrigMetaSub: camOrigMetaSub,
local mk_onvif_substreams(c) =
[common.mk_onvif(common.mk_cam_name_sub(cid, confApp, c.id, ss.suffix),
c.addr,
if "auth" in c
then c.auth
else appDef.creds[if "cred" in c then c["cred"] else 0],
ss.profile)
+ { enable: ['video', 'audio'] }
+ camOrigMetaSub(cid, confApp, c, ss)
for ss in substreams(c)],
local mk_rtsp_substreams(c) =
[common.mk_rtsp(common.mk_cam_name_sub(cid, confApp, c.id, ss.suffix),
ss.url,
if "cred" in c then appDef.creds[c.cred] else null)
+ { enable: ['video', 'audio'] }
+ camOrigMetaSub(cid, confApp, c, ss)
for ss in substreams(c)],
local srcOnvif =
std.map(function(c) common.mk_onvif(common.mk_cam_name(cid, confApp, c.id),
c.addr,
if "auth" in c
then c.auth
else appDef.creds[if "cred" in c then c["cred"] else 0],
if "profile" in c then c.profile else null) + camOrigMeta(cid, confApp, c),
onvifSet),
local srcRtsp =
std.map(function(c) common.mk_rtsp(common.mk_cam_name(cid, confApp, c.id), c.url,
if "auth" in c
then c.auth
else if "cred" in c then appDef.creds[c.cred] else null)
+ camOrigMeta(cid, confApp, c),
rtspSet),
local srcMediafiles =
std.map(function(c) local r = common.mk_mediafile(common.mk_cam_name(cid, confApp, c.id), c.path);
r + camOrigMeta(cid, confApp, c) + {dynamic: false}, mediafileSet),
local srcRtspSubstreams = std.flattenArrays(std.map(mk_rtsp_substreams, rtspSet)),
local srcOnvifSubstreams = std.flattenArrays(std.map(mk_onvif_substreams, onvifSet)),
sources: srcOnvif + srcRtsp + srcOnvifSubstreams + srcRtspSubstreams + srcMediafiles,
local recPermanent = std.filter(function (s) "rec" in s.__orig && s.__orig.rec == "permanent", self.sources),
local recMotion = std.filter(function (s) "rec" in s.__orig && s.__orig.rec == "motion", self.sources),
record: if std.all(std.map(function(s) s.__orig.rec == "none", self.sources)) then null else { motion: recMotion, permanent: recPermanent },
otherObjects: [],
otherLinks: [],
appDefault: {
webrtc: true,
rtspsrv: true,
websrv: true,
wamp: true,
metrics: true,
events: "sqlite",
repl: null,
zmq: null,
auth: null,
preserveSourceIds: false,
allowDynamicSources: true,
recordRetainDaysMax: null,
webrtcOverrides: {},
},
local confApp = self.appDefault + if "app" in appDef then appDef.app else {},
webrtc: confApp.webrtc,
rtspsrv: confApp.rtspsrv,
websrv: confApp.websrv,
wamp: confApp.wamp,
metrics: confApp.metrics,
events: confApp.events,
repl: confApp.repl,
zmq: confApp.zmq,
auth: confApp.auth,
// construct media source ids as "cam_CLUSTER_CAMID" or preserve just "CAMID"
preserveSourceIds: confApp.preserveSourceIds,
// global switch to disable dynamic sources
allowDynamicSources: confApp.allowDynamicSources,
recordRetainDaysMax: confApp.recordRetainDaysMax,
webrtcOverrides: confApp.webrtcOverrides,
}
}