forked from dusty-nv/jetson-inference
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstream_options.py
135 lines (105 loc) · 4.93 KB
/
stream_options.py
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
import dash
import dash_bootstrap_components as dbc
from dash import dcc, html, callback, Input, Output, State, ALL
from dash.exceptions import PreventUpdate
from server import Server
def create_stream_dialog(stream={}):
"""
Create the top-level dialog container used for creating/configuring streams.
It's children will be created dynamically in create_stream_options() below.
"""
return dbc.Modal(create_stream_options(stream), id='stream_options_dialog', is_open=False)
def create_stream_options(stream={}):
"""
Create the dialog body used for creating/configuring streams.
"""
children = [dbc.ModalHeader(dbc.ModalTitle(stream.get('name', 'Add Stream')))]
form = dbc.Form([
html.Div([
dbc.Label('Stream Name', html_for='stream_options_name'),
dbc.Input(id='stream_options_name', value='/my_stream'), #placeholder='/my_stream'),
dbc.FormText('Your name of the stream (e.g. location)'),
], className='mb-3'),
html.Div([
dbc.Label('Video Source', html_for='stream_options_source'),
dbc.Input(id='stream_options_source', value='/dev/video0'), #placeholder='/dev/video0'),
dbc.FormText('Camera input: /dev/video*, csi://0, rtsp://, file://'),
], className='mb-3'),
html.Div([
dbc.Label('Models', html_for='stream_options_model'),
#dbc.Select(options=list_models(), multi=True, id='stream_options_model'),
dcc.Dropdown(options=list_models(), multi=True, id='stream_options_model'),
dbc.FormText("The DNN model(s) to use for processing the stream"),
], className='mb-3'),
html.Div([
dbc.Checklist(
options=[{'label' : 'Auto Play', 'value': 'auto_play'}],
value=['auto_play'],
id='stream_options_checklist'),
], className='mb-3'),
html.Div(id='hidden_div_stream', style={'display':'none'})
])
children += [dbc.ModalBody(form)]
children += [dbc.ModalFooter(dbc.Button('Create', id='stream_options_submit', className='ms-auto', n_clicks=0))]
return children
def list_models():
"""
Return a drop-down list of models from the server that can be selected.
"""
models = Server.request('/models').json() if Server.instance is not None else []
return [{'label': model, 'value': model} for model in models]
@dash.callback(
Output('stream_options_dialog', 'is_open'),
Output('stream_options_dialog', 'children'),
Input('navbar_add_stream', 'n_clicks'),
Input('stream_options_submit', 'n_clicks'),
Input({'type': 'card-settings-stream', 'index': ALL}, 'n_clicks'),
State('stream_options_dialog', 'is_open'),
)
def show_stream_dialog(n1, n2, n3, is_open):
"""
Callback for triggering to show/hide the stream options dialog
"""
stream = {}
#print(f'show_stream_dialog({n1}, {n2}, {n3}, {is_open})')
#print(dash.ctx.triggered)
if not dash.ctx.triggered[0]['value']:
raise PreventUpdate
if isinstance(dash.ctx.triggered_id, dict) and dash.ctx.triggered_id['type'] == 'card-settings-stream':
stream = Server.request(f"/streams/{dash.ctx.triggered_id['index']}").json()
if is_open:
return False, dash.no_update
else:
return True, create_stream_options(stream)
@dash.callback(
Output('hidden_div_stream', 'children'),
Input('stream_options_submit', 'n_clicks'),
State('stream_options_name', 'value'),
State('stream_options_source', 'value'),
State('stream_options_model', 'value'),
)
def stream_submit(n_clicks, name, source, model):
"""
Callback for when the stream form is submitted
"""
if n_clicks == 0:
raise PreventUpdate
print(f"adding stream {name} from source {source} with model {model}")
Server.request('POST', '/streams', json={'name': name, 'source': source, 'models': model})
raise PreventUpdate
'''
def create_stream_options(stream):
stream_config = Server.instance.get_resource('streams', stream)
"""
children = [
html.Video(id=stream_config['video_player'], controls=True, autoPlay=True, style=video_player_style),
html.Div(id={'type': 'hidden_div_video_player', 'index': stream}, style={'display':'none'}),
dcc.Store(id={'type': 'video_player_config', 'index': stream}, data=json.dumps(stream_config)),
]
"""
return create_card(f"Stream Settings for {stream}", title=f"{stream} Settings", id=f"stream_options_{stream}")
@card_callback(Input({'type': 'card-settings-stream', 'index': ALL}, 'n_clicks'))
def on_stream_settings(n_clicks):
if dash.ctx.triggered[0]['value'] > 0:
return create_stream_options(dash.ctx.triggered_id['index'])
'''