-
Notifications
You must be signed in to change notification settings - Fork 2
/
utils.cpp
78 lines (73 loc) · 2.84 KB
/
utils.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
#include <fstream>
#include <algorithm>
#include "utils.h"
device_type get_device_type() {
std::ifstream device_name(DEVICE_PATH);
if (device_name.is_open()) {
std::string line;
while (std::getline(device_name, line)) {
std::string lowercase_line = line;
std::transform(lowercase_line.begin(), lowercase_line.end(), lowercase_line.begin(), ::tolower);
// Check for specific terms in a case-insensitive manner
if (lowercase_line.find("nvidia") != std::string::npos &&
(lowercase_line.find("orin") != std::string::npos ||
lowercase_line.find("nano") != std::string::npos ||
lowercase_line.find("agx") != std::string::npos ||
lowercase_line.find("jetson") != std::string::npos)) {
return device_type(device_type::jetson, "Jetson");
} else if (lowercase_line.find("raspberry") != std::string::npos &&
lowercase_line.find("pi") != std::string::npos) {
return device_type(device_type::pi, "Raspberry Pi");
}
}
device_name.close();
}
return device_type(device_type::unknown, "unkwnown");
}
device_params get_device_params(device_type device) {
switch (device.value) {
case device_type::jetson:
return device_params {
.input_source = JETSON_INPUT_SOURCE,
.input_format = JETSON_INPUT_FORMAT,
.video_converter = JETSON_VIDEO_CONVERTER,
.output_encoder = JETSON_OUTPUT_ENCODER
};
case device_type::pi:
return device_params {
.input_source = PI_INPUT_SOURCE,
.input_format = PI_INPUT_FORMAT,
.video_converter = PI_VIDEO_CONVERTER,
.output_encoder = PI_OUTPUT_ENCODER
};
default:
return device_params {
.input_source = DEFAULT_INPUT_SOURCE,
.input_format = DEFAULT_INPUT_FORMAT,
.video_converter = DEFAULT_VIDEO_CONVERTER,
.output_encoder = DEFAULT_OUTPUT_ENCODER
};
}
}
api_params get_api_params(device_type device) {
switch (device.value) {
case device_type::jetson:
return api_params {
.api_namespace = API_NAMESPACE,
.api_type = API_TYPE,
.api_subtype = JETSON_API_SUBTYPE
};
case device_type::pi:
return api_params {
.api_namespace = API_NAMESPACE,
.api_type = API_TYPE,
.api_subtype = PI_API_SUBTYPE
};
default:
return api_params {
.api_namespace = API_NAMESPACE,
.api_type = API_TYPE,
.api_subtype = DEFAULT_API_SUBTYPE
};
}
}