Skip to content

Commit

Permalink
Add option: RS2_OPTION_GLOBAL_TIME_ENABLED. Disable it in unit-test.
Browse files Browse the repository at this point in the history
  • Loading branch information
doronhi committed May 13, 2019
1 parent 33651ca commit 8391341
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 19 deletions.
1 change: 1 addition & 0 deletions include/librealsense2/h/rs_option.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ extern "C" {
RS2_OPTION_MC_TEMPERATURE, /**< MC temperature*/
RS2_OPTION_MA_TEMPERATURE, /**< MA temperature*/
RS2_OPTION_HARDWARE_PRESET, /**< Hardware stream configuration */
RS2_OPTION_GLOBAL_TIME_ENABLED, /**< disable global time */
RS2_OPTION_COUNT /**< Number of enumeration values. Not a valid input: intended to be used in for-loops. */
} rs2_option;

Expand Down
5 changes: 3 additions & 2 deletions src/ds5/ds5-color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@ namespace librealsense
std::unique_ptr<frame_timestamp_reader> ds5_timestamp_reader_backup(new ds5_timestamp_reader(backend.create_time_service()));
std::unique_ptr<frame_timestamp_reader> ds5_timestamp_reader_metadata(new ds5_timestamp_reader_from_metadata(std::move(ds5_timestamp_reader_backup)));

auto enable_global_time_option = std::shared_ptr<global_time_option>(new global_time_option());
auto color_ep = std::make_shared<ds5_color_sensor>(this, backend.create_uvc_device(color_devices_info.front()),
std::unique_ptr<frame_timestamp_reader>(new global_timestamp_reader(std::move(ds5_timestamp_reader_metadata), _tf_keeper)));

std::unique_ptr<frame_timestamp_reader>(new global_timestamp_reader(std::move(ds5_timestamp_reader_metadata), _tf_keeper, enable_global_time_option)));

_color_device_idx = add_sensor(color_ep);

color_ep->register_option(RS2_OPTION_GLOBAL_TIME_ENABLED, enable_global_time_option);
color_ep->register_pixel_format(pf_yuyv);
color_ep->register_pixel_format(pf_yuy2);
color_ep->register_pixel_format(pf_bayer16);
Expand Down
10 changes: 8 additions & 2 deletions src/ds5/ds5-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,11 @@ namespace librealsense

std::unique_ptr<frame_timestamp_reader> timestamp_reader_backup(new ds5_timestamp_reader(backend.create_time_service()));
std::unique_ptr<frame_timestamp_reader> timestamp_reader_metadata(new ds5_timestamp_reader_from_metadata(std::move(timestamp_reader_backup)));
auto enable_global_time_option = std::shared_ptr<global_time_option>(new global_time_option());
auto depth_ep = std::make_shared<ds5_depth_sensor>(this, std::make_shared<platform::multi_pins_uvc_device>(depth_devices),
std::unique_ptr<frame_timestamp_reader>(new global_timestamp_reader(std::move(timestamp_reader_metadata), _tf_keeper)));
std::unique_ptr<frame_timestamp_reader>(new global_timestamp_reader(std::move(timestamp_reader_metadata), _tf_keeper, enable_global_time_option)));

depth_ep->register_option(RS2_OPTION_GLOBAL_TIME_ENABLED, enable_global_time_option);
depth_ep->register_xu(depth_xu); // make sure the XU is initialized every time we power the camera

depth_ep->register_pixel_format(pf_z16); // Depth
Expand Down Expand Up @@ -681,8 +683,12 @@ namespace librealsense

std::unique_ptr<frame_timestamp_reader> ds5_timestamp_reader_backup(new ds5_timestamp_reader(backend.create_time_service()));
std::unique_ptr<frame_timestamp_reader> ds5_timestamp_reader_metadata(new ds5_timestamp_reader_from_metadata(std::move(ds5_timestamp_reader_backup)));

auto enable_global_time_option = std::shared_ptr<global_time_option>(new global_time_option());
auto depth_ep = std::make_shared<ds5u_depth_sensor>(this, std::make_shared<platform::multi_pins_uvc_device>(depth_devices),
std::unique_ptr<frame_timestamp_reader>(new global_timestamp_reader(std::move(ds5_timestamp_reader_metadata), _tf_keeper)));
std::unique_ptr<frame_timestamp_reader>(new global_timestamp_reader(std::move(ds5_timestamp_reader_metadata), _tf_keeper, enable_global_time_option)));

depth_ep->register_option(RS2_OPTION_GLOBAL_TIME_ENABLED, enable_global_time_option);

depth_ep->register_xu(depth_xu); // make sure the XU is initialized every time we power the camera

Expand Down
10 changes: 7 additions & 3 deletions src/ds5/ds5-motion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,14 @@ namespace librealsense

std::unique_ptr<frame_timestamp_reader> iio_hid_ts_reader(new iio_hid_timestamp_reader());
std::unique_ptr<frame_timestamp_reader> custom_hid_ts_reader(new ds5_custom_hid_timestamp_reader());
auto enable_global_time_option = std::shared_ptr<global_time_option>(new global_time_option());
auto hid_ep = std::make_shared<ds5_hid_sensor>(this, ctx->get_backend().create_hid_device(all_hid_infos.front()),
std::unique_ptr<frame_timestamp_reader>(new global_timestamp_reader(std::move(iio_hid_ts_reader), _tf_keeper)),
std::unique_ptr<frame_timestamp_reader>(new global_timestamp_reader(std::move(custom_hid_ts_reader), _tf_keeper)),
std::unique_ptr<frame_timestamp_reader>(new global_timestamp_reader(std::move(iio_hid_ts_reader), _tf_keeper, enable_global_time_option)),
std::unique_ptr<frame_timestamp_reader>(new global_timestamp_reader(std::move(custom_hid_ts_reader), _tf_keeper, enable_global_time_option)),
fps_and_sampling_frequency_per_rs2_stream,
sensor_name_and_hid_profiles);

hid_ep->register_option(RS2_OPTION_GLOBAL_TIME_ENABLED, enable_global_time_option);
hid_ep->register_pixel_format(pf_accel_axes);
hid_ep->register_pixel_format(pf_gyro_axes);

Expand Down Expand Up @@ -381,9 +383,11 @@ namespace librealsense
std::unique_ptr<frame_timestamp_reader> ds5_timestamp_reader_backup(new ds5_timestamp_reader(environment::get_instance().get_time_service()));
auto&& backend = ctx->get_backend();
std::unique_ptr<frame_timestamp_reader> ds5_timestamp_reader_metadata(new ds5_timestamp_reader_from_metadata(std::move(ds5_timestamp_reader_backup)));
auto enable_global_time_option = std::shared_ptr<global_time_option>(new global_time_option());
auto fisheye_ep = std::make_shared<ds5_fisheye_sensor>(this, backend.create_uvc_device(fisheye_infos.front()),
std::unique_ptr<frame_timestamp_reader>(new global_timestamp_reader(std::move(ds5_timestamp_reader_metadata), _tf_keeper)));
std::unique_ptr<frame_timestamp_reader>(new global_timestamp_reader(std::move(ds5_timestamp_reader_metadata), _tf_keeper, enable_global_time_option)));

fisheye_ep->register_option(RS2_OPTION_GLOBAL_TIME_ENABLED, enable_global_time_option);
fisheye_ep->register_xu(fisheye_xu); // make sure the XU is initialized everytime we power the camera
fisheye_ep->register_pixel_format(pf_raw8);
fisheye_ep->register_pixel_format(pf_fe_raw8_unpatched_kernel); // W/O for unpatched kernel
Expand Down
13 changes: 7 additions & 6 deletions src/global_timestamp_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,12 @@ namespace librealsense
return _coefs.calc_value(crnt_hw_time);
}

global_timestamp_reader::global_timestamp_reader(std::unique_ptr<frame_timestamp_reader> device_timestamp_reader, std::shared_ptr<time_diff_keeper> timediff) :
global_timestamp_reader::global_timestamp_reader(std::unique_ptr<frame_timestamp_reader> device_timestamp_reader,
std::shared_ptr<time_diff_keeper> timediff,
std::shared_ptr<global_time_option> enable_option) :
_device_timestamp_reader(std::move(device_timestamp_reader)),
_time_diff_keeper(timediff)
_time_diff_keeper(timediff),
_option_is_enabled(enable_option)
{
LOG_DEBUG("global_timestamp_reader created");
}
Expand All @@ -198,7 +201,7 @@ namespace librealsense
{
double frame_time = _device_timestamp_reader->get_frame_timestamp(mode, fo);
rs2_timestamp_domain ts_domain = _device_timestamp_reader->get_frame_timestamp_domain(mode, fo);
if (ts_domain == RS2_TIMESTAMP_DOMAIN_HARDWARE_CLOCK)
if (_option_is_enabled->is_true() && ts_domain == RS2_TIMESTAMP_DOMAIN_HARDWARE_CLOCK)
{
auto sp = _time_diff_keeper.lock();
if (sp)
Expand All @@ -218,13 +221,11 @@ namespace librealsense
rs2_timestamp_domain global_timestamp_reader::get_frame_timestamp_domain(const request_mapping& mode, const platform::frame_object& fo) const
{
rs2_timestamp_domain ts_domain = _device_timestamp_reader->get_frame_timestamp_domain(mode, fo);
return (ts_domain == RS2_TIMESTAMP_DOMAIN_HARDWARE_CLOCK) ? RS2_TIMESTAMP_DOMAIN_GLOBAL_TIME : ts_domain;
return (_option_is_enabled->is_true() && ts_domain == RS2_TIMESTAMP_DOMAIN_HARDWARE_CLOCK) ? RS2_TIMESTAMP_DOMAIN_GLOBAL_TIME : ts_domain;
}

void global_timestamp_reader::reset()
{
_device_timestamp_reader->reset();
}


}
13 changes: 12 additions & 1 deletion src/global_timestamp_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@

namespace librealsense
{
class LRS_EXTENSION_API global_time_option : public bool_option
{
public:
global_time_option() {}
// TODO: expose this outwards
const char* get_description() const override { return "Enable/Disable global timestamp."; }
};

class CSample
{
public:
Expand Down Expand Up @@ -69,7 +77,9 @@ namespace librealsense
class global_timestamp_reader : public frame_timestamp_reader
{
public:
global_timestamp_reader(std::unique_ptr<frame_timestamp_reader> device_timestamp_reader, std::shared_ptr<time_diff_keeper> timediff);
global_timestamp_reader(std::unique_ptr<frame_timestamp_reader> device_timestamp_reader,
std::shared_ptr<time_diff_keeper> timediff,
std::shared_ptr<global_time_option>);

rs2_time_t get_frame_timestamp(const request_mapping& mode, const platform::frame_object& fo) override;
unsigned long long get_frame_counter(const request_mapping& mode, const platform::frame_object& fo) const override;
Expand All @@ -80,5 +90,6 @@ namespace librealsense
std::unique_ptr<frame_timestamp_reader> _device_timestamp_reader;
std::weak_ptr<time_diff_keeper> _time_diff_keeper;
mutable std::recursive_mutex _mtx;
std::shared_ptr<global_time_option> _option_is_enabled;
};
}
4 changes: 3 additions & 1 deletion src/l500/l500-color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ namespace librealsense
auto&& backend = ctx->get_backend();

std::unique_ptr<frame_timestamp_reader> timestamp_reader_metadata(new ivcam2::l500_timestamp_reader_from_metadata(backend.create_time_service()));
auto enable_global_time_option = std::shared_ptr<global_time_option>(new global_time_option());
auto color_ep = std::make_shared<l500_color_sensor>(this, ctx->get_backend().create_uvc_device(color_devices_info.front()),
std::unique_ptr<frame_timestamp_reader>(new global_timestamp_reader(std::move(timestamp_reader_metadata), _tf_keeper)),
std::unique_ptr<frame_timestamp_reader>(new global_timestamp_reader(std::move(timestamp_reader_metadata), _tf_keeper, enable_global_time_option)),
ctx);

color_ep->register_option(RS2_OPTION_GLOBAL_TIME_ENABLED, enable_global_time_option);
color_ep->register_pixel_format(pf_yuy2);
color_ep->register_pixel_format(pf_yuyv);

Expand Down
4 changes: 3 additions & 1 deletion src/l500/l500-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,11 @@ namespace librealsense
depth_devices.push_back(backend.create_uvc_device(info));

std::unique_ptr<frame_timestamp_reader> timestamp_reader_metadata(new l500_timestamp_reader_from_metadata(backend.create_time_service()));
auto enable_global_time_option = std::shared_ptr<global_time_option>(new global_time_option());
auto depth_ep = std::make_shared<l500_depth_sensor>(this, std::make_shared<platform::multi_pins_uvc_device>(depth_devices),
std::unique_ptr<frame_timestamp_reader>(new global_timestamp_reader(std::move(timestamp_reader_metadata), _tf_keeper)));
std::unique_ptr<frame_timestamp_reader>(new global_timestamp_reader(std::move(timestamp_reader_metadata), _tf_keeper, enable_global_time_option)));

depth_ep->register_option(RS2_OPTION_GLOBAL_TIME_ENABLED, enable_global_time_option);
depth_ep->register_xu(depth_xu);
depth_ep->register_pixel_format(pf_z16_l500);
depth_ep->register_pixel_format(pf_confidence_l500);
Expand Down
6 changes: 4 additions & 2 deletions src/l500/l500-motion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,14 @@ namespace librealsense

std::unique_ptr<frame_timestamp_reader> iio_hid_ts_reader(new iio_hid_timestamp_reader());
std::unique_ptr<frame_timestamp_reader> custom_hid_ts_reader(new iio_hid_timestamp_reader());
auto enable_global_time_option = std::shared_ptr<global_time_option>(new global_time_option());
auto hid_ep = std::make_shared<l500_hid_sensor>(this, ctx->get_backend().create_hid_device(all_hid_infos.front()),
std::unique_ptr<frame_timestamp_reader>(new global_timestamp_reader(std::move(iio_hid_ts_reader), _tf_keeper)),
std::unique_ptr<frame_timestamp_reader>(new global_timestamp_reader(std::move(custom_hid_ts_reader), _tf_keeper)),
std::unique_ptr<frame_timestamp_reader>(new global_timestamp_reader(std::move(iio_hid_ts_reader), _tf_keeper, enable_global_time_option)),
std::unique_ptr<frame_timestamp_reader>(new global_timestamp_reader(std::move(custom_hid_ts_reader), _tf_keeper, enable_global_time_option)),
l500_fps_and_sampling_frequency_per_rs2_stream,
l500_sensor_name_and_hid_profiles);

hid_ep->register_option(RS2_OPTION_GLOBAL_TIME_ENABLED, enable_global_time_option);
hid_ep->register_pixel_format(pf_accel_axes);
hid_ep->register_pixel_format(pf_gyro_axes);

Expand Down
11 changes: 10 additions & 1 deletion src/option.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,19 @@ namespace librealsense
bool is_enabled() const override { return true; }
// TODO: expose this outwards
const char* get_description() const override { return "A simple custom option for a processing block"; }
private:
protected:
float _value;
};

class LRS_EXTENSION_API bool_option : public float_option
{
public:
bool_option() : float_option(option_range{ 0, 1, 1, 1 }) {}
bool is_true() { return (_value > _opt_range.min); }
// TODO: expose this outwards
const char* get_description() const override { return "A simple custom option for a processing block"; }
};

class uvc_pu_option : public option
{
public:
Expand Down
1 change: 1 addition & 0 deletions src/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ namespace librealsense
CASE(MC_TEMPERATURE)
CASE(MA_TEMPERATURE)
CASE(HARDWARE_PRESET)
CASE(GLOBAL_TIME_ENABLED)
default: assert(!is_valid(value)); return UNKNOWN_VALUE;
}
#undef CASE
Expand Down
3 changes: 3 additions & 0 deletions unit-tests/unit-tests-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ inline void disable_sensitive_options_for(rs2::sensor& sen)
REQUIRE_NOTHROW(range = sen.get_option_range(RS2_OPTION_EXPOSURE)); // TODO: fails sometimes with "Element Not Found!"
REQUIRE_NOTHROW(sen.set_option(RS2_OPTION_EXPOSURE, range.def));
}

if (sen.supports(RS2_OPTION_GLOBAL_TIME_ENABLED))
REQUIRE_NOTHROW(sen.set_option(RS2_OPTION_GLOBAL_TIME_ENABLED, 0));
}

inline void disable_sensitive_options_for(rs2::device& dev)
Expand Down
1 change: 1 addition & 0 deletions wrappers/python/pybackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ PYBIND11_MODULE(NAME, m) {
.value("filter_smooth_delta", RS2_OPTION_FILTER_SMOOTH_DELTA)
.value("filter_holes_fill", RS2_OPTION_HOLES_FILL)
.value("stereo_baseline", RS2_OPTION_STEREO_BASELINE)
.value("global_time_enabled", RS2_OPTION_GLOBAL_TIME_ENABLED)
.value("count", RS2_OPTION_COUNT);

py::enum_<platform::power_state> power_state(m, "power_state");
Expand Down

0 comments on commit 8391341

Please sign in to comment.