15 m_read_thread([]() {
return std::make_shared<dispatcher>(std::numeric_limits<unsigned int>::max()); }),
24 if (serializer ==
nullptr)
30 (*m_read_thread)->start();
42 auto profiles = sensor_pair.second->get_stream_profiles();
50 std::map<uint32_t, std::shared_ptr<playback_sensor>> sensors;
100 sensor->opened += [
this](
const std::vector<device_serializer::stream_identifier>&
filters) ->
void 108 sensor->closed += [
this](
const std::vector<device_serializer::stream_identifier>&
filters) ->
void 123 for (
auto sensor_pair : sensors_map)
127 for (
auto stream_profile : sensor_pair.second->get_stream_profiles())
151 if (
sensor.second !=
nullptr)
155 if((*m_read_thread)->flush() ==
false)
157 LOG_ERROR(
"Error - timeout waiting for flush, possible deadlock detected");
160 (*m_read_thread)->stop();
170 return *
m_sensors.at(static_cast<uint32_t>(i));
198 LOG_WARNING(
"Playback device does not provide a matcher");
200 return std::make_shared<identity_matcher>(
s->get_unique_id(),
s->get_stream_type());
205 LOG_INFO(
"Request to change playback frame rate to: " << rate);
212 LOG_INFO(
"Changing playback frame rate to: " << rate);
220 LOG_INFO(
"Request to seek to: " << time.count());
223 LOG_INFO(
"Seek to time: " << time.count());
232 auto current_frames =
m_reader->fetch_last_frames(time);
233 for (
auto&&
f : current_frames)
239 std::string error_msg =
to_string() <<
"Unexpected sensor index while playing file (Read index = " <<
frame->stream_id.sensor_index <<
")";
244 []() { return device_serializer::nanoseconds(0); },
245 []() { return false; },
248 std::lock_guard<std::mutex> locker(m_last_published_timestamp_mutex);
249 m_last_published_timestamp = time;
255 if ((*m_read_thread)->flush() ==
false)
257 LOG_ERROR(
"Error - timeout waiting for seek_to_time, possible deadlock detected");
271 return m_reader->query_duration().count();
297 sensor.second->flush_pending_frames();
300 LOG_DEBUG(
"Notifying RS2_PLAYBACK_STATUS_PAUSED");
303 if ((*m_read_thread)->flush() ==
false)
305 LOG_ERROR(
"Error - timeout waiting for pause, possible deadlock detected");
320 auto total_duration =
m_reader->query_duration();
332 if ((*m_read_thread)->flush() ==
false)
334 LOG_ERROR(
"Error - timeout waiting for resume, possible deadlock detected");
342 LOG_INFO(
"Set real time to " << ((real_time) ?
"True" :
"False"));
392 LOG_DEBUG(
"Time Now : " <<
now.time_since_epoch().count() <<
" , Time When Started: " << m_base_sys_time.time_since_epoch().count() <<
" , Diff: " << play_time.count() <<
" == " << (play_time.count() * 1
e-6) <<
"ms");
393 LOG_DEBUG(
"Original Recording Delta: " << time_diff.count() <<
" == " << (time_diff.count() * 1
e-6) <<
"ms");
394 LOG_DEBUG(
"Frame Time: " << timestamp.count() <<
" , First Frame: " << m_base_timestamp.count() <<
" , Diff: " << recorded_time.count() <<
" == " << (recorded_time.count() * 1
e-6) <<
"ms");
396 if(recorded_time < play_time)
398 LOG_DEBUG(
"Recorded Time < Playing Time (not sleeping)");
401 auto sleep_time = (recorded_time - play_time);
402 LOG_DEBUG(
"Sleep Time: " << sleep_time.count() <<
" == " << (sleep_time.count() * 1
e-6) <<
" ms");
434 if ((*m_read_thread)->flush() ==
false)
436 LOG_ERROR(
"Error - timeout waiting for flush, possible deadlock detected");
462 template <
typename T>
467 bool action_succeeded =
false;
470 action_succeeded =
action();
472 catch(
const std::exception&
e)
474 LOG_ERROR(
"Failed to read next frame from file: " << e.what());
476 action_succeeded =
false;
480 if(action_succeeded ==
false)
483 s.second->flush_pending_frames();
486 size_t active_sensors_count = m_active_sensors.size();
487 for (
size_t i = 0;
i<active_sensors_count;
i++)
489 if (m_active_sensors.size() == 0)
493 m_active_sensors.begin()->second->stop(
false);
516 if (
s.second->streams_contains_one_frame_or_more())
538 auto read_action = [
this]() ->
bool 544 std::shared_ptr<serialized_data>
data =
m_reader->read_next_data();
565 if (sleep_time.count() > 0)
569 LOG_DEBUG(
"Sleeping for: " << (sleep_time.count() * 1
e-6));
570 std::this_thread::sleep_for(sleep_time);
580 std::string error_msg =
to_string() <<
"Unexpected sensor index while playing file (Read index = " <<
frame->stream_id.sensor_index <<
")";
593 [
this,
timestamp]() { return calc_sleep_time(timestamp); },
594 [
this]() { return m_is_paused == true; },
597 std::lock_guard<std::mutex> locker(m_last_published_timestamp_mutex);
598 m_last_published_timestamp = timestamp;
605 m_sensors.at(option_data->sensor_id.sensor_index)->update_option(option_data->option_id, option_data->option);
611 m_sensors.at(notification_data->sensor_id.sensor_index)->raise_notification(notification_data->notif);
637 if (info_snapshot ==
nullptr)
639 LOG_WARNING(
"Recorded file does not contain device informatiom");
643 auto info_api = As<info_interface>(info_snapshot);
644 if (info_api ==
nullptr)
651 if (info_api->supports_info(info))
665 if (e1.second.first != e2.second.first)
674 auto extrinsic_fetcher = std::make_shared<lazy<rs2_extrinsics>>([
x]()
679 m_extrinsics_map[
p2->get_unique_id()] = e2.second;
693 switch (extension_type)
709 LOG_WARNING(
"Unsupported extension type: " << extension_type);
rs2_extrinsics calc_extrinsic(const rs2_extrinsics &from, const rs2_extrinsics &to)
rs2_camera_info
Read-only strings that can be queried from the device. Not all information attributes are available o...
std::shared_ptr< context > get_context() const override
std::map< stream_identifier, std::pair< uint32_t, rs2_extrinsics > > get_extrinsics_map() const
void set_frame_rate(double rate)
rs2_extrinsics from_pose(pose a)
void register_extrinsics(const device_serializer::device_snapshot &device_description)
std::shared_ptr< rs2_frame_callback > frame_callback_ptr
void tag_profiles(stream_profiles profiles) const override
std::shared_ptr< stream_profile_interface > get_stream(const std::map< unsigned, std::shared_ptr< playback_sensor >> &sensors_map, device_serializer::stream_identifier stream_id)
void seek_to_time(std::chrono::nanoseconds time)
std::shared_ptr< context > m_context
playback_device(std::shared_ptr< context > context, std::shared_ptr< device_serializer::reader > serializer)
bool is_real_time() const
const std::string & get_file_name() const
GLsizei const GLchar *const * string
signal< playback_device, rs2_playback_status > playback_status_changed
uint64_t get_position() const
platform::backend_device_group get_device_data() const override
bool extend_to(rs2_extension extension_type, void **ext) override
uint32_t get_sensor_index() const
static bool try_extend_snapshot(std::shared_ptr< extension_snapshot > &e, rs2_extension extension_type, void **ext)
std::atomic_bool m_is_paused
def info(name, value, persistent=False)
pose inverse(const pose &a)
pose to_pose(const rs2_extrinsics &a)
device_serializer::nanoseconds m_prev_timestamp
void register_extrinsics(const stream_interface &from, const stream_interface &to, std::weak_ptr< lazy< rs2_extrinsics >> extr)
void register_info(rs2_camera_info info, const std::string &val)
device_serializer::nanoseconds m_last_published_timestamp
std::shared_ptr< extension_snapshot > find(rs2_extension t) const
size_t get_sensors_count() const override
unsigned __int64 uint64_t
std::shared_ptr< device_serializer::reader > m_reader
std::atomic< double > m_sample_rate
device_serializer::nanoseconds m_base_timestamp
bool is_valid() const override
std::map< uint32_t, std::shared_ptr< playback_sensor > > m_active_sensors
void set_real_time(bool real_time)
static environment & get_instance()
extrinsics_graph & get_extrinsics_graph()
std::chrono::duration< uint64_t, std::nano > nanoseconds
std::map< uint32_t, std::shared_ptr< playback_sensor > > create_playback_sensors(const device_serializer::device_snapshot &device_description)
Cross-stream extrinsics: encodes the topology describing how the different devices are oriented...
rs2_playback_status get_current_status() const
LOG_INFO("Log message using LOG_INFO()")
virtual std::shared_ptr< stream_profile_interface > get_stream() const =0
void hardware_reset() override
rs2_extension
Specifies advanced interfaces (capabilities) objects may implement.
std::atomic_bool m_real_time
typename::boost::move_detail::remove_reference< T >::type && move(T &&t) BOOST_NOEXCEPT
device_serializer::device_snapshot m_device_description
std::string frame_holder_to_string(const frame_holder &f)
void update_time_base(device_serializer::nanoseconds base_timestamp)
virtual ~playback_device()
void register_device_info(const device_serializer::device_snapshot &device_description)
snapshot_collection get_device_extensions_snapshots() const
uint64_t get_duration() const
std::atomic_bool m_is_started
virtual int get_unique_id() const =0
std::vector< sensor_snapshot > get_sensors_snapshots() const
std::shared_ptr< matcher > create_matcher(const frame_holder &frame) const override
sensor_interface & get_sensor(size_t i) override
std::pair< uint32_t, rs2_extrinsics > get_extrinsics(const stream_interface &stream) const override
GeneratorWrapper< T > map(Func &&function, GeneratorWrapper< U > &&generator)
std::map< int, std::pair< uint32_t, rs2_extrinsics > > m_extrinsics_map
std::vector< std::shared_ptr< lazy< rs2_extrinsics > > > m_extrinsics_fetchers
std::map< uint32_t, std::shared_ptr< playback_sensor > > m_sensors
constexpr uint32_t get_device_index()
std::chrono::high_resolution_clock::time_point m_base_sys_time
void update_extensions(const device_serializer::device_snapshot &device_description)
device_serializer::nanoseconds calc_sleep_time(device_serializer::nanoseconds timestamp)
std::string to_string(T value)