Skip to content

Commit

Permalink
PR #13135 from noacoohen: Pipeline new API
Browse files Browse the repository at this point in the history
  • Loading branch information
Nir-Az authored Jul 11, 2024
2 parents 46893b0 + b01bb8b commit 60e02fa
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 3 deletions.
8 changes: 8 additions & 0 deletions include/librealsense2/h/rs_pipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ extern "C" {
*/
void rs2_pipeline_stop(rs2_pipeline* pipe, rs2_error ** error);

/**
* Set the device to be used in the pipline.
* The function is used to assign the device, useful when the user wish to set controls that cannot be set while streaming.
* \param[in] pipe the pipeline.
* \param[in] device the device to be used in the pipline.
*/
void rs2_pipeline_set_device( rs2_pipeline * pipe, rs2_device * device, rs2_error ** error );

/**
* Wait until a new set of frames becomes available.
* The frames set includes time-synchronized frames of each enabled stream in the pipeline.
Expand Down
12 changes: 12 additions & 0 deletions include/librealsense2/hpp/rs_pipeline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,18 @@ namespace rs2
error::handle(e);
}

/**
* Set the device to be used in the pipline.
* The function is used to assign the device, useful when the user wish to set controls that cannot be set while streaming.
* \param[in] device the device to be used in the pipline.
*/
void set_device( rs2::device* device )
{
rs2_error * e = nullptr;
rs2_pipeline_set_device( _pipeline.get(), device->get().get(), &e );
error::handle( e );
}

/**
* Wait until a new set of frames becomes available.
* The frames set includes time-synchronized frames of each enabled stream in the pipeline.
Expand Down
5 changes: 4 additions & 1 deletion src/pipeline/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,11 @@ namespace librealsense
std::lock_guard<std::mutex> lock(_mtx);
_resolved_profile.reset();

std::shared_ptr< librealsense::device_interface > requested_device = pipe->get_device();
if(! requested_device )
requested_device = resolve_device_requests( pipe, timeout );

//Resolve the the device that was specified by the user, this call will wait in case the device is not availabe.
auto requested_device = resolve_device_requests(pipe, timeout);
if (requested_device != nullptr)
{
_resolved_profile = resolve(requested_device);
Expand Down
10 changes: 10 additions & 0 deletions src/pipeline/pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ namespace librealsense
return unsafe_get_active_profile();
}

void pipeline::set_device( std::shared_ptr< librealsense::device_interface > dev )
{
_dev = dev;
}

std::shared_ptr< librealsense::device_interface > pipeline::get_device()
{
return _dev;
}

std::shared_ptr<profile> pipeline::get_active_profile() const
{
std::lock_guard<std::mutex> lock(_mtx);
Expand Down
3 changes: 3 additions & 0 deletions src/pipeline/pipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ namespace librealsense
std::shared_ptr<device_interface> wait_for_device(const std::chrono::milliseconds& timeout = std::chrono::hours::max(),
const std::string& serial = "");
std::shared_ptr<librealsense::context> get_context() const;
void set_device( std::shared_ptr< librealsense::device_interface > dev );
std::shared_ptr< librealsense::device_interface > get_device();

protected:
rs2_frame_callback_sptr get_callback(std::vector<int> unique_ids);
Expand All @@ -61,6 +63,7 @@ namespace librealsense

rs2_frame_callback_sptr _streams_callback;
std::vector<rs2_stream> _synced_streams;
std::shared_ptr< librealsense::device_interface > _dev = nullptr;
};
}
}
1 change: 1 addition & 0 deletions src/realsense.def
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ EXPORTS
rs2_pipeline_get_active_profile
rs2_pipeline_profile_get_device
rs2_pipeline_profile_get_streams
rs2_pipeline_set_device
rs2_delete_pipeline_profile

rs2_create_config
Expand Down
11 changes: 10 additions & 1 deletion src/rs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2201,7 +2201,16 @@ void rs2_pipeline_stop(rs2_pipeline* pipe, rs2_error ** error) BEGIN_API_CALL
}
HANDLE_EXCEPTIONS_AND_RETURN(, pipe)

rs2_frame* rs2_pipeline_wait_for_frames(rs2_pipeline* pipe, unsigned int timeout_ms, rs2_error ** error) BEGIN_API_CALL
void rs2_pipeline_set_device( rs2_pipeline * pipe, rs2_device * device, rs2_error ** error ) BEGIN_API_CALL
{
VALIDATE_NOT_NULL( pipe );
VALIDATE_NOT_NULL( device );

pipe->pipeline->set_device( device->device );
}
HANDLE_EXCEPTIONS_AND_RETURN(, pipe, device )

rs2_frame* rs2_pipeline_wait_for_frames(rs2_pipeline* pipe, unsigned int timeout_ms, rs2_error ** error)BEGIN_API_CALL
{
VALIDATE_NOT_NULL(pipe);

Expand Down
33 changes: 33 additions & 0 deletions unit-tests/live/d400/test-pipeline-set-device.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# License: Apache 2.0. See LICENSE file in root directory.
# Copyright(c) 2024 Intel Corporation. All Rights Reserved.

# LibCI doesn't have D435i so //test:device D435I// is disabled for now
# test:device D455

import pyrealsense2 as rs
from rspy import test

gyro_sensitivity_value = 4.0

with test.closure("pipeline - set device"):
cfg = rs.config()
ctx = rs.context()

dev = test.find_first_device_or_exit()
motion_sensor = dev.first_motion_sensor()
pipe = rs.pipeline(ctx)
pipe.set_device(dev)

motion_sensor.set_option(rs.option.gyro_sensitivity, gyro_sensitivity_value)

cfg.enable_stream(rs.stream.accel)
cfg.enable_stream(rs.stream.gyro)

profile = pipe.start(cfg)
device_from_profile = profile.get_device()
sensor = device_from_profile.first_motion_sensor()
sensor_gyro_sensitivity_value = sensor.get_option(rs.option.gyro_sensitivity)
test.check_equal(gyro_sensitivity_value, sensor_gyro_sensitivity_value)
pipe.stop()

test.print_results_and_exit()
5 changes: 4 additions & 1 deletion wrappers/python/pyrs_pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ void init_pipeline(py::module &m) {
auto success = self.try_wait_for_frames(&fs, timeout_ms);
return std::make_tuple(success, fs);
}, "timeout_ms"_a = 5000, py::call_guard<py::gil_scoped_release>())
.def("get_active_profile", &rs2::pipeline::get_active_profile); // No docstring in C++
.def("get_active_profile", &rs2::pipeline::get_active_profile) // No docstring in C++
.def( "set_device", &rs2::pipeline::set_device,
"The function is used to assign the device, useful when the user wish to set controls that cannot be set while streaming. ",
"device"_a );
/** end rs_pipeline.hpp **/
}

0 comments on commit 60e02fa

Please sign in to comment.