Skip to content

Commit 030eb70

Browse files
committed
additional code review changes. remove API method, implement platform init on a separate thread with 2 sec delay
1 parent 177520f commit 030eb70

File tree

9 files changed

+36
-71
lines changed

9 files changed

+36
-71
lines changed

src/core/device-interface.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ class device_interface
7070

7171
virtual bool contradicts( const stream_profile_interface * a,
7272
const std::vector< stream_profile > & others ) const = 0;
73-
74-
virtual void initialize() = 0;
7573
};
7674

7775

src/device.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@ class device
8989
bool device_changed_notifications_on() const { return _device_change_subscription.is_active(); }
9090

9191
format_conversion get_format_conversion() const;
92-
93-
virtual void initialize() override {};
9492

9593
protected:
9694
int add_sensor(const std::shared_ptr<sensor_interface>& sensor_base);

src/ds/d400/d400-fw-update-device.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ namespace librealsense
1919
virtual bool check_fw_compatibility(const std::vector<uint8_t>& image) const override;
2020

2121
float compute_progress(float progress, float start, float end, float threshold) const override;
22-
virtual void initialize() override {};
2322
private:
2423
std::string parse_serial_number(const std::vector<uint8_t>& buffer) const;
2524
};

src/ds/d500/d500-fw-update-device.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ namespace librealsense
2020
std::chrono::seconds timeout_seconds, rs2_update_progress_callback_sptr update_progress_callback) const;
2121
virtual void dfu_manifest_phase(const platform::rs_usb_messenger& messenger, rs2_update_progress_callback_sptr update_progress_callback) const override;
2222
float compute_progress(float progress, float start, float end, float threshold) const override;
23-
virtual void initialize() override {};
2423

2524
private:
2625
std::string parse_serial_number(const std::vector<uint8_t>& buffer) const;

src/media/playback/playback_device.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ namespace librealsense
6161

6262
bool compress_while_record() const override { return true; }
6363
bool contradicts(const stream_profile_interface* a, const std::vector<stream_profile>& others) const override { return false; }
64-
virtual void initialize() override {};
6564

6665
private:
6766
void update_time_base(device_serializer::nanoseconds base_timestamp);

src/media/record/record_device.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ namespace librealsense
4949
void tag_profiles(stream_profiles profiles) const override { m_device->tag_profiles(profiles); }
5050
bool compress_while_record() const override { return true; }
5151
bool contradicts(const stream_profile_interface* a, const std::vector<stream_profile>& others) const override { return m_device->contradicts(a, others); }
52-
virtual void initialize() override {};
5352

5453
private:
5554
template <typename T> void write_device_extension_changes(const T& ext);

src/platform-camera.cpp

Lines changed: 29 additions & 25 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,
@@ -117,34 +141,14 @@ platform_camera::platform_camera( std::shared_ptr< const device_info > const & d
117141
// For consistent (msec) measurements use "time of arrival" metadata attribute
118142
color_ep->register_metadata( RS2_FRAME_METADATA_FRAME_TIMESTAMP,
119143
make_uvc_header_parser( &platform::uvc_header::timestamp ) );
120-
}
121144

122-
void platform_camera::initialize()
123-
{
124-
auto const n_sensors = get_sensors_count();
125-
for (auto i = 0; i < n_sensors; ++i)
126-
{
127-
if (auto sensor = dynamic_cast<platform_camera_sensor*>(&(get_sensor(i))))
128-
{
129-
if (sensor->get_device().get_info(RS2_CAMERA_INFO_NAME) == "Platform Camera")
130-
{
131-
sensor->try_register_pu(RS2_OPTION_BACKLIGHT_COMPENSATION);
132-
sensor->try_register_pu(RS2_OPTION_BRIGHTNESS);
133-
sensor->try_register_pu(RS2_OPTION_CONTRAST);
134-
sensor->try_register_pu(RS2_OPTION_EXPOSURE);
135-
sensor->try_register_pu(RS2_OPTION_GAMMA);
136-
sensor->try_register_pu(RS2_OPTION_HUE);
137-
sensor->try_register_pu(RS2_OPTION_SATURATION);
138-
sensor->try_register_pu(RS2_OPTION_SHARPNESS);
139-
sensor->try_register_pu(RS2_OPTION_WHITE_BALANCE);
140-
sensor->try_register_pu(RS2_OPTION_ENABLE_AUTO_EXPOSURE);
141-
sensor->try_register_pu(RS2_OPTION_ENABLE_AUTO_WHITE_BALANCE);
142-
}
143-
}
144-
}
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
145150
}
146151

147-
148152
std::vector< tagged_profile > platform_camera::get_profiles_tags() const
149153
{
150154
std::vector< tagged_profile > markers;

src/platform-camera.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ class platform_camera : public backend_device
1919

2020
virtual rs2_intrinsics get_intrinsics( unsigned int, const stream_profile & ) const { return rs2_intrinsics{}; }
2121

22-
virtual void initialize() override;
23-
2422
std::vector< tagged_profile > get_profiles_tags() const override;
23+
24+
private:
25+
void initialize();
2526
};
2627

2728

tools/realsense-viewer/realsense-viewer.cpp

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include <mutex>
2020
#include <set>
2121
#include <regex>
22-
#include <api.h>
2322

2423
#include <imgui_internal.h>
2524

@@ -135,8 +134,6 @@ void refresh_devices(std::mutex& m,
135134
context& ctx,
136135
device_changes& devices_connection_changes,
137136
std::vector<device>& current_connected_devices,
138-
std::vector<device>& future_initialization_devices,
139-
bool allow_future_initialization,
140137
std::vector<std::pair<std::string, std::string>>& device_names,
141138
device_models_list& device_models,
142139
viewer_model& viewer_model,
@@ -145,29 +142,7 @@ void refresh_devices(std::mutex& m,
145142

146143
event_information info({}, {});
147144
if (!devices_connection_changes.try_get_next_changes(info))
148-
{
149-
if (allow_future_initialization)
150-
{
151-
auto dev_itr = begin(future_initialization_devices);
152-
while (dev_itr != end(future_initialization_devices))
153-
{
154-
auto &dev = *dev_itr;
155-
const std::shared_ptr<rs2_device>& device_shared_ptr = dev.get();
156-
const rs2_device* p_rs2_device = device_shared_ptr.get();
157-
158-
auto add_controls_task = [p_rs2_device]() {
159-
p_rs2_device->device->initialize();
160-
};
161-
162-
std::thread add_controls_thread(add_controls_task);
163-
add_controls_thread.detach();
164-
165-
dev_itr = future_initialization_devices.erase(dev_itr);
166-
}
167-
}
168-
169-
return;
170-
}
145+
return ;
171146
try
172147
{
173148
//Remove disconnected
@@ -244,10 +219,6 @@ void refresh_devices(std::mutex& m,
244219
<< " was selected as a default device" );
245220
added = true;
246221
}
247-
else if(std::string(dev.get_info(RS2_CAMERA_INFO_NAME)) == "Platform Camera")
248-
{
249-
future_initialization_devices.push_back(dev);
250-
}
251222

252223
if (!initial_refresh)
253224
{
@@ -347,9 +318,7 @@ int main(int argc, const char** argv) try
347318
update_viewer_configuration(viewer_model);
348319

349320
std::vector<device> connected_devs;
350-
std::vector<device> future_initialization_devices;
351321
std::mutex m;
352-
bool allow_future_initialization = false;
353322

354323
#ifdef BUILD_EASYLOGGINGPP
355324
std::weak_ptr<notifications_model> notifications = viewer_model.not_model;
@@ -396,15 +365,15 @@ int main(int argc, const char** argv) try
396365

397366
window.on_load = [&]()
398367
{
399-
refresh_devices(m, ctx, devices_connection_changes, connected_devs, future_initialization_devices, allow_future_initialization,
368+
refresh_devices(m, ctx, devices_connection_changes, connected_devs,
400369
device_names, *device_models, viewer_model, error_message);
401370
return true;
402371
};
403372

404373
// Closing the window
405374
while (window)
406375
{
407-
refresh_devices(m, ctx, devices_connection_changes, connected_devs, future_initialization_devices, allow_future_initialization,
376+
refresh_devices(m, ctx, devices_connection_changes, connected_devs,
408377
device_names, *device_models, viewer_model, error_message);
409378

410379
auto output_height = viewer_model.get_output_height();
@@ -650,8 +619,7 @@ int main(int argc, const char** argv) try
650619

651620
// Fetch and process frames from queue
652621
viewer_model.handle_ready_frames(viewer_rect, window, static_cast<int>(device_models->size()), error_message);
653-
allow_future_initialization = true;
654-
}
622+
}
655623

656624
// Stopping post processing filter rendering thread
657625
viewer_model.ppf.stop();

0 commit comments

Comments
 (0)