-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
globalTimeStamp - going to idle #4073
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
86de935
sensor start and stop time_diff_keeper object when open and close.
doronhi 547ebb5
fix bug.
doronhi e007d9e
change logs
doronhi 8567892
Fixed logs.
doronhi 0d9cdcc
move control of time_diff_keeper to class global_time_interface.
doronhi 1a82880
add GLOBAL_TIME definitions.
doronhi a5214e4
fix some tests
doronhi 8f4a5b5
protect time_diff_keeper start and stop operations with mutex.
doronhi 2482ca5
time_diff_keeper: _users_count is not atomic.
doronhi b23dd3a
prevent global_timestamp_reader from starting on a playback backend.
doronhi 1725878
move playback_backend check into get_device_time_ms() function.
doronhi 44d9f6a
add todo remark.
doronhi 8e6e5ee
Merge branch 'development' into hwsystime
dorodnic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,11 +96,13 @@ namespace librealsense | |
return y; | ||
} | ||
|
||
time_diff_keeper::time_diff_keeper(device* dev, const unsigned int sampling_interval_ms) : | ||
time_diff_keeper::time_diff_keeper(global_time_interface* dev, const unsigned int sampling_interval_ms) : | ||
_device(dev), | ||
_poll_intervals_ms(sampling_interval_ms), | ||
_last_sample_hw_time(1e+200), | ||
_coefs(15), | ||
_users_count(0), | ||
_is_ready(false), | ||
_active_object([this](dispatcher::cancellable_timer cancellable_timer) | ||
{ | ||
polling(cancellable_timer); | ||
|
@@ -111,9 +113,28 @@ namespace librealsense | |
|
||
void time_diff_keeper::start() | ||
{ | ||
std::lock_guard<std::recursive_mutex> lock(_enable_mtx); | ||
_users_count++; | ||
LOG_DEBUG("time_diff_keeper::start: _users_count = " << _users_count); | ||
_active_object.start(); | ||
} | ||
|
||
void time_diff_keeper::stop() | ||
{ | ||
std::lock_guard<std::recursive_mutex> lock(_enable_mtx); | ||
if (_users_count <= 0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Couple of options - |
||
LOG_ERROR("time_diff_keeper users_count <= 0."); | ||
|
||
_users_count--; | ||
LOG_DEBUG("time_diff_keeper::stop: _users_count = " << _users_count); | ||
if (_users_count == 0) | ||
{ | ||
LOG_DEBUG("time_diff_keeper::stop: stop object."); | ||
_active_object.stop(); | ||
_coefs.reset(); | ||
} | ||
} | ||
|
||
time_diff_keeper::~time_diff_keeper() | ||
{ | ||
_active_object.stop(); | ||
|
@@ -124,11 +145,14 @@ namespace librealsense | |
using namespace std::chrono; | ||
try | ||
{ | ||
if (!_users_count) | ||
throw wrong_api_call_sequence_exception("time_diff_keeper::update_diff_time called before object started."); | ||
LOG_DEBUG("time_diff_keeper::update_diff_time - in"); | ||
std::lock_guard<std::recursive_mutex> lock(_mtx); | ||
LOG_DEBUG("time_diff_keeper::update_diff_time - lock"); | ||
double system_time_start = duration<double, std::milli>(system_clock::now().time_since_epoch()).count(); | ||
double sample_hw_time = _device->get_device_time(); | ||
|
||
double sample_hw_time = _device->get_device_time_ms(); | ||
double system_time_finish = duration<double, std::milli>(system_clock::now().time_since_epoch()).count(); | ||
double system_time((system_time_finish + system_time_start) / 2); | ||
if (sample_hw_time < _last_sample_hw_time) | ||
|
@@ -140,6 +164,7 @@ namespace librealsense | |
_last_sample_hw_time = sample_hw_time; | ||
CSample crnt_sample(_last_sample_hw_time, system_time); | ||
_coefs.add_value(crnt_sample); | ||
_is_ready = true; | ||
LOG_DEBUG("time_diff_keeper::update_diff_time - unlock"); | ||
return true; | ||
} | ||
|
@@ -171,7 +196,7 @@ namespace librealsense | |
} | ||
} | ||
|
||
double time_diff_keeper::get_system_hw_time(double crnt_hw_time) | ||
double time_diff_keeper::get_system_hw_time(double crnt_hw_time, bool& is_ready) | ||
{ | ||
static const double possible_loop_time(3000); | ||
{ | ||
|
@@ -184,15 +209,20 @@ namespace librealsense | |
} | ||
LOG_DEBUG("time_diff_keeper::get_system_hw_time - unlock"); | ||
} | ||
return _coefs.calc_value(crnt_hw_time); | ||
is_ready = _is_ready; | ||
if (_is_ready) | ||
return _coefs.calc_value(crnt_hw_time); | ||
else | ||
return 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, | ||
std::shared_ptr<global_time_option> enable_option) : | ||
_device_timestamp_reader(std::move(device_timestamp_reader)), | ||
_time_diff_keeper(timediff), | ||
_option_is_enabled(enable_option) | ||
_option_is_enabled(enable_option), | ||
_ts_is_ready(false) | ||
{ | ||
LOG_DEBUG("global_timestamp_reader created"); | ||
} | ||
|
@@ -205,7 +235,7 @@ namespace librealsense | |
{ | ||
auto sp = _time_diff_keeper.lock(); | ||
if (sp) | ||
frame_time = sp->get_system_hw_time(frame_time); | ||
frame_time = sp->get_system_hw_time(frame_time, _ts_is_ready); | ||
else | ||
LOG_DEBUG("Notification: global_timestamp_reader - time_diff_keeper is being shut-down"); | ||
} | ||
|
@@ -221,11 +251,23 @@ 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 (_option_is_enabled->is_true() && ts_domain == RS2_TIMESTAMP_DOMAIN_HARDWARE_CLOCK) ? RS2_TIMESTAMP_DOMAIN_GLOBAL_TIME : ts_domain; | ||
return (_option_is_enabled->is_true() && _ts_is_ready && ts_domain == RS2_TIMESTAMP_DOMAIN_HARDWARE_CLOCK) ? RS2_TIMESTAMP_DOMAIN_GLOBAL_TIME : ts_domain; | ||
} | ||
|
||
void global_timestamp_reader::reset() | ||
{ | ||
_device_timestamp_reader->reset(); | ||
} | ||
|
||
global_time_interface::global_time_interface() : | ||
_tf_keeper(std::make_shared<time_diff_keeper>(this, 100)) | ||
{} | ||
|
||
void global_time_interface::enable_time_diff_keeper(bool is_enable) | ||
{ | ||
if (is_enable) | ||
_tf_keeper->start(); | ||
else | ||
_tf_keeper->stop(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Start/Stop shall be muted-protected as the invocation can be done from multiple threads.