-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy path1file_ptis_iou_tracker_osd_window.cpp
173 lines (133 loc) · 6.03 KB
/
1file_ptis_iou_tracker_osd_window.cpp
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*
The MIT License
Copyright (c) 2021-2022, Prominence AI, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in-
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <iostream>
#include <glib.h>
#include "DslApi.h"
// File path for the single File Source
static const std::wstring file_path(L"/opt/nvidia/deepstream/deepstream/samples/streams/sample_qHD.mp4");
// Filespecs for the Primary Triton Inference Server (PTIS)
static const std::wstring primary_infer_config_file =
L"/opt/nvidia/deepstream/deepstream/samples/configs/deepstream-app-triton/config_infer_plan_engine_primary.txt";
// IOU Tracker config file
static const std::wstring tracker_config_file(
L"/opt/nvidia/deepstream/deepstream/samples/configs/deepstream-app/config_tracker_IOU.yml");
// File name for .dot file output
static const std::wstring dot_file = L"state-playing";
// Source file dimensions are 960 × 540.
int source_width = 960;
int source_height = 540;
// Window Sink dimensions same as Source dimensions - no scaling.
int sink_width = source_width;
int sink_height = source_height;
// Function to be called on XWindow KeyRelease event
//
void xwindow_key_event_handler(const wchar_t* in_key, void* client_data)
{
std::wstring wkey(in_key);
std::string key(wkey.begin(), wkey.end());
std::cout << "key released = " << key << std::endl;
key = std::toupper(key[0]);
if(key == "P"){
dsl_pipeline_pause(L"pipeline");
} else if (key == "R"){
dsl_pipeline_play(L"pipeline");
} else if (key == "Q"){
dsl_pipeline_stop(L"pipeline");
dsl_main_loop_quit();
}
}
// ##
// # Function to be called on XWindow Delete event
// ##
void xwindow_delete_event_handler(void* client_data)
{
std::cout<<"delete window event"<<std::endl;
dsl_pipeline_stop(L"pipeline");
dsl_main_loop_quit();
}
// # Function to be called on End-of-Stream (EOS) event
void eos_event_listener(void* client_data)
{
std::cout<<"Pipeline EOS event"<<std::endl;
dsl_pipeline_stop(L"pipeline");
dsl_main_loop_quit();
}
//
// Function to be called on every change of Pipeline state
//
void state_change_listener(uint old_state, uint new_state, void* client_data)
{
std::cout<<"previous state = " << dsl_state_value_to_string(old_state)
<< ", new state = " << dsl_state_value_to_string(new_state) << std::endl;
}
int main(int argc, char** argv)
{
DslReturnType retval;
// # Since we're not using args, we can Let DSL initialize GST on first call
while(true)
{
// # New File Source using the file path specified above, repeat diabled.
retval = dsl_source_file_new(L"file-source", file_path.c_str(), false);
if (retval != DSL_RESULT_SUCCESS) break;
// # New Primary TIS using the filespec specified above, with interval = 0
retval = dsl_infer_tis_primary_new(L"primary-tis", primary_infer_config_file.c_str(), 0);
if (retval != DSL_RESULT_SUCCESS) break;
// # New KTL Tracker, setting output width and height of tracked objects
retval = dsl_tracker_new(L"iou-tracker", tracker_config_file.c_str(), 480, 272);
if (retval != DSL_RESULT_SUCCESS) break;
// # New OSD with text, clock, bboxs enabled, mask display disabled
retval = dsl_osd_new(L"on-screen-display", true, true, true, false);
if (retval != DSL_RESULT_SUCCESS) break;
// # New Window Sink, 0 x/y offsets and dimensions
retval = dsl_sink_window_egl_new(L"egl-sink", 0, 0, sink_width, sink_height);
if (retval != DSL_RESULT_SUCCESS) break;
// Add the XWindow event handler functions defined above
retval = dsl_sink_window_key_event_handler_add(L"egl-sink",
xwindow_key_event_handler, NULL);
if (retval != DSL_RESULT_SUCCESS) break;
retval = dsl_sink_window_delete_event_handler_add(L"egl-sink",
xwindow_delete_event_handler, NULL);
if (retval != DSL_RESULT_SUCCESS) break;
// # Add all the components to a new pipeline
const wchar_t* components[] = { L"file-source",L"primary-tis",
L"iou-tracker",L"on-screen-display",L"egl-sink",nullptr};
retval = dsl_pipeline_new_component_add_many(L"pipeline", components);
if (retval != DSL_RESULT_SUCCESS) break;
// # Add the listener callback functions defined above
retval = dsl_pipeline_state_change_listener_add(L"pipeline",
state_change_listener, nullptr);
if (retval != DSL_RESULT_SUCCESS) break;
retval = dsl_pipeline_eos_listener_add(L"pipeline",
eos_event_listener, nullptr);
if (retval != DSL_RESULT_SUCCESS) break;
// # Play the pipeline
retval = dsl_pipeline_play(L"pipeline");
if (retval != DSL_RESULT_SUCCESS) break;
// # Join with main loop until released - blocking call
dsl_main_loop_run();
retval = DSL_RESULT_SUCCESS;
break;
}
// # Print out the final result
std::cout << dsl_return_value_to_string(retval) << std::endl;
dsl_delete_all();
std::cout<<"Goodbye!"<<std::endl;
return 0;
}