Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Power on UVC sensors after creation to speed initialization #12897

Merged
merged 1 commit into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/ds/d400/d400-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,9 @@ namespace librealsense

auto depth_ep = std::make_shared<d400_depth_sensor>(this, raw_depth_ep);

// Many commands need power during initialization phase, no point turning it on and off again for each.
raw_depth_ep->power_for_duration( std::chrono::milliseconds( 1000 ) );

depth_ep->register_info(RS2_CAMERA_INFO_PHYSICAL_PORT, filter_by_mi(all_device_infos, 0).front().device_path);

depth_ep->register_option(RS2_OPTION_GLOBAL_TIME_ENABLED, enable_global_time_option);
Expand Down
3 changes: 3 additions & 0 deletions src/ds/d500/d500-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,9 @@ namespace librealsense

auto depth_ep = std::make_shared<d500_depth_sensor>(this, raw_depth_ep);

// Many commands need power during initialization phase, no point turning it on and off again for each.
raw_depth_ep->power_for_duration( std::chrono::milliseconds( 1000 ) );

depth_ep->register_info(RS2_CAMERA_INFO_PHYSICAL_PORT, filter_by_mi(all_device_infos, 0).front().device_path);

depth_ep->register_option(RS2_OPTION_GLOBAL_TIME_ENABLED, enable_global_time_option);
Expand Down
14 changes: 14 additions & 0 deletions src/uvc-sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ class uvc_sensor : public raw_sensor_base
return action( *_device );
}


void power_for_duration( std::chrono::steady_clock::duration timeout = std::chrono::milliseconds( 500 ) )
{
acquire_power();
std::weak_ptr< uvc_sensor > weak = std::dynamic_pointer_cast< uvc_sensor >( shared_from_this() );
std::thread release_power_thread( [weak, timeout]()
{
std::this_thread::sleep_for( timeout );
if( auto strong = weak.lock() )
strong->release_power();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make sure release_power(); cannot throw.
Even if today it can't might be better to wrap with try/catch as an exception here will crash the application

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

release_power catches set_power_state exceptions.
Theoretically there might be an exception from locking a mutex, but I don't think we need to guard against it. If locking a mutex fails here will probably be the least of our problems.

} );
release_power_thread.detach();
}

protected:
stream_profiles init_stream_profiles() override;
void verify_supported_requests( const stream_profiles & requests ) const;
Expand Down
Loading