Skip to content

Commit 1577f1c

Browse files
authored
PR #13985 from gilpazintel: Optimize RS-Viewer loading time
2 parents 547e831 + 030eb70 commit 1577f1c

File tree

3 files changed

+38
-17
lines changed

3 files changed

+38
-17
lines changed

src/platform-camera.cpp

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,30 @@ class platform_camera_sensor : public synthetic_sensor
6464

6565
} // namespace
6666

67+
void platform_camera::initialize()
68+
{
69+
auto const n_sensors = get_sensors_count();
70+
for (auto i = 0; i < n_sensors; ++i)
71+
{
72+
if (auto sensor = dynamic_cast<platform_camera_sensor*>(&(get_sensor(i))))
73+
{
74+
if (sensor->get_device().get_info(RS2_CAMERA_INFO_NAME) == "Platform Camera")
75+
{
76+
sensor->try_register_pu(RS2_OPTION_BACKLIGHT_COMPENSATION);
77+
sensor->try_register_pu(RS2_OPTION_BRIGHTNESS);
78+
sensor->try_register_pu(RS2_OPTION_CONTRAST);
79+
sensor->try_register_pu(RS2_OPTION_EXPOSURE);
80+
sensor->try_register_pu(RS2_OPTION_GAMMA);
81+
sensor->try_register_pu(RS2_OPTION_HUE);
82+
sensor->try_register_pu(RS2_OPTION_SATURATION);
83+
sensor->try_register_pu(RS2_OPTION_SHARPNESS);
84+
sensor->try_register_pu(RS2_OPTION_WHITE_BALANCE);
85+
sensor->try_register_pu(RS2_OPTION_ENABLE_AUTO_EXPOSURE);
86+
sensor->try_register_pu(RS2_OPTION_ENABLE_AUTO_WHITE_BALANCE);
87+
}
88+
}
89+
}
90+
}
6791

6892
platform_camera::platform_camera( std::shared_ptr< const device_info > const & dev_info,
6993
const std::vector< platform::uvc_device_info > & uvc_infos,
@@ -118,20 +142,13 @@ platform_camera::platform_camera( std::shared_ptr< const device_info > const & d
118142
color_ep->register_metadata( RS2_FRAME_METADATA_FRAME_TIMESTAMP,
119143
make_uvc_header_parser( &platform::uvc_header::timestamp ) );
120144

121-
color_ep->try_register_pu( RS2_OPTION_BACKLIGHT_COMPENSATION );
122-
color_ep->try_register_pu( RS2_OPTION_BRIGHTNESS );
123-
color_ep->try_register_pu( RS2_OPTION_CONTRAST );
124-
color_ep->try_register_pu( RS2_OPTION_EXPOSURE );
125-
color_ep->try_register_pu( RS2_OPTION_GAMMA );
126-
color_ep->try_register_pu( RS2_OPTION_HUE );
127-
color_ep->try_register_pu( RS2_OPTION_SATURATION );
128-
color_ep->try_register_pu( RS2_OPTION_SHARPNESS );
129-
color_ep->try_register_pu( RS2_OPTION_WHITE_BALANCE );
130-
color_ep->try_register_pu( RS2_OPTION_ENABLE_AUTO_EXPOSURE );
131-
color_ep->try_register_pu( RS2_OPTION_ENABLE_AUTO_WHITE_BALANCE );
145+
// Create a thread to call initialize after a delay
146+
std::thread([this]() {
147+
std::this_thread::sleep_for(std::chrono::seconds(2)); // Delay for 2 seconds
148+
this->initialize();
149+
}).detach(); // Detach the thread to let it run independently
132150
}
133151

134-
135152
std::vector< tagged_profile > platform_camera::get_profiles_tags() const
136153
{
137154
std::vector< tagged_profile > markers;

src/platform-camera.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ class platform_camera : public backend_device
2020
virtual rs2_intrinsics get_intrinsics( unsigned int, const stream_profile & ) const { return rs2_intrinsics{}; }
2121

2222
std::vector< tagged_profile > get_profiles_tags() const override;
23+
24+
private:
25+
void initialize();
2326
};
2427

2528

tools/realsense-viewer/realsense-viewer.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ void add_playback_device( context & ctx,
130130
// This function is called every frame
131131
// If between the frames there was an asyncronous connect/disconnect event
132132
// the function will pick up on this and add the device to the viewer
133-
bool refresh_devices(std::mutex& m,
133+
void refresh_devices(std::mutex& m,
134134
context& ctx,
135135
device_changes& devices_connection_changes,
136136
std::vector<device>& current_connected_devices,
@@ -139,9 +139,10 @@ bool refresh_devices(std::mutex& m,
139139
viewer_model& viewer_model,
140140
std::string& error_message)
141141
{
142+
142143
event_information info({}, {});
143144
if (!devices_connection_changes.try_get_next_changes(info))
144-
return false;
145+
return ;
145146
try
146147
{
147148
//Remove disconnected
@@ -283,7 +284,7 @@ bool refresh_devices(std::mutex& m,
283284
{
284285
error_message = "Unknown error";
285286
}
286-
return true;
287+
return;
287288
}
288289

289290

@@ -372,7 +373,7 @@ int main(int argc, const char** argv) try
372373
// Closing the window
373374
while (window)
374375
{
375-
auto device_changed = refresh_devices(m, ctx, devices_connection_changes, connected_devs,
376+
refresh_devices(m, ctx, devices_connection_changes, connected_devs,
376377
device_names, *device_models, viewer_model, error_message);
377378

378379
auto output_height = viewer_model.get_output_height();
@@ -504,7 +505,7 @@ int main(int argc, const char** argv) try
504505

505506
ImGui::PopStyleColor();
506507
ImGui::EndPopup();
507-
}
508+
}
508509
ImGui::PopFont();
509510
ImGui::PopStyleVar();
510511
ImGui::PopStyleColor();

0 commit comments

Comments
 (0)