Skip to content
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
8 changes: 4 additions & 4 deletions common/output-model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1083,12 +1083,12 @@ void frame_drops_dashboard::process_frame(rs2::frame f)
{
auto last = stream_to_time[f.get_profile().unique_id()];

long long fps = f.get_profile().fps();
double fps = (double)f.get_profile().fps();

if (f.supports_frame_metadata(RS2_FRAME_METADATA_ACTUAL_FPS))
fps = f.get_frame_metadata(RS2_FRAME_METADATA_ACTUAL_FPS);
if( f.supports_frame_metadata( RS2_FRAME_METADATA_ACTUAL_FPS ) )
fps = f.get_frame_metadata( RS2_FRAME_METADATA_ACTUAL_FPS ) / 1000.;

if (1000.f * (ts - last) > 1.5f * (1000.f / fps)) {
if (1000. * (ts - last) > 1.5 * (1000. / fps)) {
drops++;
}
}
Expand Down
11 changes: 6 additions & 5 deletions common/stream-model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ namespace rs2
"Frame Timestamp is normalized represetation of when the frame was taken.\n"
"It's a property of every frame, so when exact creation time is not provided by "
"the hardware, an approximation will be used.\n"
"Clock Domain feilds helps to interpret the meaning of timestamp\n"
"Clock Domain fields helps to interpret the meaning of timestamp\n"
"Timestamp is measured in milliseconds, and is allowed to roll-over (reset to "
"zero) in some situations" } );
stream_details.push_back(
Expand Down Expand Up @@ -891,11 +891,12 @@ namespace rs2
"When AE is set On, the value is controlled by firmware. Integer value" },
{ RS2_FRAME_METADATA_AUTO_EXPOSURE, "Auto Exposure Mode indicator. Zero corresponds to AE switched off. " },
{ RS2_FRAME_METADATA_WHITE_BALANCE, "White Balance setting as a color temperature. Kelvin degrees" },
{ RS2_FRAME_METADATA_TIME_OF_ARRIVAL, "Time of arrival in system clock " },
{ RS2_FRAME_METADATA_TIME_OF_ARRIVAL, "Time of arrival in system clock" },
{ RS2_FRAME_METADATA_TEMPERATURE,
"Temperature of the device, measured at the time of the frame capture. Celsius degrees " },
{ RS2_FRAME_METADATA_BACKEND_TIMESTAMP, "Timestamp get from uvc driver. usec" },
{ RS2_FRAME_METADATA_ACTUAL_FPS, "Actual hardware FPS. May differ from requested due to Auto-Exposure" },
{ RS2_FRAME_METADATA_ACTUAL_FPS, "Hardware FPS * 1000 =\n"
"1000000 * (frame-number - prev-frame-number) / (timestamp - prev-timestamp)" },
{ RS2_FRAME_METADATA_FRAME_LASER_POWER_MODE,
"Laser power mode. Zero corresponds to Laser power switched off and one for switched on." },
{ RS2_FRAME_METADATA_EXPOSURE_PRIORITY,
Expand All @@ -912,10 +913,10 @@ namespace rs2
{
auto val = (rs2_frame_metadata_value)i;
std::string name = rs2_frame_metadata_to_string( val );
std::string desc = "";
std::string desc;
if( descriptions.find( val ) != descriptions.end() )
desc = descriptions[val];
stream_details.push_back( { name, rsutils::string::from() << kvp.second, desc } );
stream_details.push_back( { name, rsutils::string::from( kvp.second ), desc } );
}
}

Expand Down
2 changes: 1 addition & 1 deletion doc/frame_metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ GAIN_LEVEL|16
AUTO_EXPOSURE|1
TIME_OF_ARRIVAL|1523871918775
BACKEND_TIMESTAMP|1523871918741
ACTUAL_FPS|30
ACTUAL_FPS|30000

- `rs-config-ui` includes a checkbox in the upper-right corner of stream's canvas, clicking on which will bring up an overlay window with the metadata attributes available.

Expand Down
2 changes: 1 addition & 1 deletion include/librealsense2/h/rs_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ typedef enum rs2_frame_metadata_value
RS2_FRAME_METADATA_TIME_OF_ARRIVAL , /**< Time of arrival in system clock */
RS2_FRAME_METADATA_TEMPERATURE , /**< Temperature of the device, measured at the time of the frame capture. Celsius degrees */
RS2_FRAME_METADATA_BACKEND_TIMESTAMP , /**< Timestamp get from uvc driver. usec*/
RS2_FRAME_METADATA_ACTUAL_FPS , /**< Actual fps */
RS2_FRAME_METADATA_ACTUAL_FPS , /**< Actual fps, times 1000 (30.1 fps would be 30100 in the metadata) */
RS2_FRAME_METADATA_FRAME_LASER_POWER , /**< Laser power value 0-360. */
RS2_FRAME_METADATA_FRAME_LASER_POWER_MODE , /**< Laser power mode. Zero corresponds to Laser power switched off and one for switched on. deprecated, replaced by RS2_FRAME_METADATA_FRAME_EMITTER_MODE*/
RS2_FRAME_METADATA_EXPOSURE_PRIORITY , /**< Exposure priority. */
Expand Down
12 changes: 8 additions & 4 deletions src/algo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,14 @@ auto_exposure_mechanism::auto_exposure_mechanism(option& gain_option, option& ex

double values[2] = {};

values[0] = frame->supports_frame_metadata(RS2_FRAME_METADATA_ACTUAL_EXPOSURE) ?
static_cast<double>(frame->get_frame_metadata(RS2_FRAME_METADATA_ACTUAL_EXPOSURE)) : _exposure_option.query();
values[1] = frame->supports_frame_metadata(RS2_FRAME_METADATA_GAIN_LEVEL) ?
static_cast<double>(frame->get_frame_metadata(RS2_FRAME_METADATA_GAIN_LEVEL)) : _gain_option.query();
rs2_metadata_type actual_exposure_md;
values[0] = frame->find_metadata( RS2_FRAME_METADATA_ACTUAL_EXPOSURE, &actual_exposure_md )
? static_cast< double >( actual_exposure_md )
: _exposure_option.query();
rs2_metadata_type gain_level_md;
values[1] = frame->find_metadata( RS2_FRAME_METADATA_GAIN_LEVEL, &gain_level_md )
? static_cast< double >( gain_level_md )
: _gain_option.query();

values[0] /= 1000.; // Fisheye exposure value by extension control-
// is in units of MicroSeconds, from FW version 5.6.3.0
Expand Down
8 changes: 2 additions & 6 deletions src/composite-frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,9 @@ class composite_frame : public frame
// In the next section we make the composite frame "look and feel" like the first of its
// children
frame_header const & get_header() const override { return first()->get_header(); }
rs2_metadata_type get_frame_metadata( const rs2_frame_metadata_value & frame_metadata ) const override
bool find_metadata( rs2_frame_metadata_value frame_metadata, rs2_metadata_type * p_output_value ) const override
{
return first()->get_frame_metadata( frame_metadata );
}
bool supports_frame_metadata( const rs2_frame_metadata_value & frame_metadata ) const override
{
return first()->supports_frame_metadata( frame_metadata );
return first()->find_metadata( frame_metadata, p_output_value );
}
int get_frame_data_size() const override { return first()->get_frame_data_size(); }
const uint8_t * get_frame_data() const override { return first()->get_frame_data(); }
Expand Down
6 changes: 3 additions & 3 deletions src/core/frame-interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class frame_interface
{
public:
virtual frame_header const & get_header() const = 0;
virtual rs2_metadata_type get_frame_metadata( const rs2_frame_metadata_value & frame_metadata ) const = 0;
virtual bool supports_frame_metadata( const rs2_frame_metadata_value & frame_metadata ) const = 0;

virtual bool find_metadata( rs2_frame_metadata_value, rs2_metadata_type * p_output_value ) const = 0;
virtual int get_frame_data_size() const = 0;
virtual const uint8_t * get_frame_data() const = 0;
virtual rs2_time_t get_frame_timestamp() const = 0;
Expand All @@ -31,7 +31,7 @@ class frame_interface
virtual unsigned long long get_frame_number() const = 0;

virtual void set_timestamp_domain( rs2_timestamp_domain timestamp_domain ) = 0;
virtual rs2_time_t get_frame_system_time() const = 0;
virtual rs2_time_t get_frame_system_time() const = 0; // TIME_OF_ARRIVAL
virtual std::shared_ptr< stream_profile_interface > get_stream() const = 0;
virtual void set_stream( std::shared_ptr< stream_profile_interface > sp ) = 0;

Expand Down
13 changes: 8 additions & 5 deletions src/ds/d400/d400-auto-calibration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1270,13 +1270,16 @@ namespace librealsense
{
try
{
auto fi = (frame_interface *)f;
std::vector<uint8_t> res;
rs2_metadata_type frame_counter = ((frame_interface*)f)->get_frame_metadata(RS2_FRAME_METADATA_FRAME_COUNTER);
rs2_metadata_type frame_ts = ((frame_interface*)f)->get_frame_metadata(RS2_FRAME_METADATA_FRAME_TIMESTAMP);
rs2_metadata_type frame_counter;
if( ! fi->find_metadata( RS2_FRAME_METADATA_FRAME_COUNTER, &frame_counter ) )
throw invalid_value_exception( "missing FRAME_COUNTER" );
rs2_metadata_type frame_ts;
if( ! fi->find_metadata( RS2_FRAME_METADATA_FRAME_TIMESTAMP, &frame_ts ) )
throw invalid_value_exception( "missing FRAME_TIMESTAMP" );
bool tare_fc_workaround = (_action == auto_calib_action::RS2_OCC_ACTION_TARE_CALIB); //Tare calib shall use rolling frame counter
bool mipi_sku = ((frame_interface*)f)->supports_frame_metadata(RS2_FRAME_METADATA_CALIB_INFO);
if (mipi_sku)
frame_counter = ((frame_interface*)f)->get_frame_metadata(RS2_FRAME_METADATA_CALIB_INFO);
bool mipi_sku = fi->find_metadata( RS2_FRAME_METADATA_CALIB_INFO, &frame_counter );

if (_interactive_state == interactive_calibration_state::RS2_OCC_STATE_WAIT_TO_CAMERA_START)
{
Expand Down
2 changes: 1 addition & 1 deletion src/ds/d400/d400-factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1345,7 +1345,7 @@ namespace librealsense
std::vector<stream_interface*> streams = { _depth_stream.get() , _left_ir_stream.get() , _right_ir_stream.get(), _color_stream.get() };
std::vector<stream_interface*> mm_streams = { _accel_stream.get(), _gyro_stream.get()};
streams.insert(streams.end(), mm_streams.begin(), mm_streams.end());
if (frame.frame->supports_frame_metadata(RS2_FRAME_METADATA_FRAME_COUNTER))
if( frame.frame->find_metadata( RS2_FRAME_METADATA_FRAME_COUNTER, nullptr ) )
{
return matcher_factory::create(RS2_MATCHER_DLR_C, streams);
}
Expand Down
3 changes: 1 addition & 2 deletions src/ds/ds-color-common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ namespace librealsense
void ds_color_common::register_metadata()
{
_color_ep.register_metadata(RS2_FRAME_METADATA_FRAME_TIMESTAMP, make_uvc_header_parser(&platform::uvc_header::timestamp));
_color_ep.register_metadata(RS2_FRAME_METADATA_ACTUAL_FPS, std::make_shared<ds_md_attribute_actual_fps>(false, [](const rs2_metadata_type& param)
{return param * 100; })); //the units of the exposure of the RGB sensor are 100 microseconds so the md_attribute_actual_fps need the lambda to convert it to microseconds
_color_ep.register_metadata(RS2_FRAME_METADATA_ACTUAL_FPS, std::make_shared<ds_md_attribute_actual_fps>());

// attributes of md_capture_timing
auto md_prop_offset = offsetof(metadata_raw, mode) +
Expand Down
66 changes: 17 additions & 49 deletions src/frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,62 +133,18 @@ frame_interface * frame::publish( std::shared_ptr< archive_interface > new_owner
return owner->publish_frame( this );
}

rs2_metadata_type frame::get_frame_metadata( const rs2_frame_metadata_value & frame_metadata ) const
bool frame::find_metadata( rs2_frame_metadata_value frame_metadata, rs2_metadata_type * p_value ) const
{
if( ! metadata_parsers )
throw invalid_value_exception( rsutils::string::from()
<< "metadata not available for " << get_string( get_stream()->get_stream_type() )
<< " stream" );

return false;
auto parsers = metadata_parsers->equal_range( frame_metadata );
if( parsers.first
== metadata_parsers
->end() ) // Possible user error - md attribute is not supported by this frame type
throw invalid_value_exception( rsutils::string::from()
<< get_string( frame_metadata ) << " attribute is not applicable for "
<< get_string( get_stream()->get_stream_type() ) << " stream " );

rs2_metadata_type result = -1;

bool value_retrieved = false;
std::string exc_str;
for( auto it = parsers.first; it != parsers.second; ++it )
{
try
{
result = it->second->get( *this );
if( it->second->find( *this, p_value ) )
value_retrieved = true;
break;
}
catch( invalid_value_exception & e )
{
exc_str = e.what();
}
}
if( ! value_retrieved )
throw invalid_value_exception( exc_str );

return result;
}

bool frame::supports_frame_metadata( const rs2_frame_metadata_value & frame_metadata ) const
{
// verify preconditions
if( ! metadata_parsers )
return false; // No parsers are available or no metadata was attached

bool ret = false;
auto found = metadata_parsers->equal_range( frame_metadata );
if( found.first == metadata_parsers->end() )
return false;

for( auto it = found.first; it != found.second; ++it )
if( it->second->supports( *this ) )
{
ret = true;
break;
}

return ret;
return value_retrieved;
}

int frame::get_frame_data_size() const
Expand Down Expand Up @@ -223,6 +179,18 @@ unsigned long long frame::get_frame_number() const
return additional_data.frame_number;
}

double frame::calc_actual_fps() const
{
auto const dt = ( additional_data.timestamp - additional_data.last_timestamp );
if( dt > 0. && additional_data.frame_number > additional_data.last_frame_number )
{
auto const n_frames = additional_data.frame_number - additional_data.last_frame_number;
return 1000. * n_frames / dt;
}

return 0.; // Unknown actual FPS
}

rs2_time_t frame::get_frame_system_time() const
{
return additional_data.system_time;
Expand Down
6 changes: 4 additions & 2 deletions src/frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ class LRS_EXTENSION_API frame : public frame_interface

virtual ~frame() { on_release.reset(); }
frame_header const & get_header() const override { return additional_data; }
rs2_metadata_type get_frame_metadata( const rs2_frame_metadata_value & frame_metadata ) const override;
bool supports_frame_metadata( const rs2_frame_metadata_value & frame_metadata ) const override;
bool find_metadata( rs2_frame_metadata_value, rs2_metadata_type * p_output_value ) const override;
int get_frame_data_size() const override;
const uint8_t * get_frame_data() const override;
rs2_time_t get_frame_timestamp() const override;
Expand All @@ -51,6 +50,9 @@ class LRS_EXTENSION_API frame : public frame_interface
additional_data.timestamp_domain = timestamp_domain;
}

// Return FPS calculated as (1000*d_frames/d_timestamp), or 0 if this cannot be estimated
double calc_actual_fps() const;

rs2_time_t get_frame_system_time() const override;

std::shared_ptr< stream_profile_interface > get_stream() const override { return stream; }
Expand Down
3 changes: 3 additions & 0 deletions src/hid-sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ void hid_sensor::start( frame_callback_ptr callback )
<< rs2_timestamp_domain_to_string( timestamp_domain ) << ",last_frame_number,"
<< last_frame_number << ",last_timestamp," << last_timestamp );

if( frame_counter <= last_frame_number )
LOG_INFO( "Frame counter reset" );

last_frame_number = frame_counter;
last_timestamp = timestamp;
frame_holder frame
Expand Down
4 changes: 2 additions & 2 deletions src/media/ros/ros_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ namespace librealsense
for (int i = 0; i < static_cast<rs2_frame_metadata_value>(rs2_frame_metadata_value::RS2_FRAME_METADATA_COUNT); i++)
{
rs2_frame_metadata_value type = static_cast<rs2_frame_metadata_value>(i);
if (frame->supports_frame_metadata(type))
rs2_metadata_type md;
if (frame->find_metadata(type, &md))
{
auto md = frame->get_frame_metadata(type);
diagnostic_msgs::KeyValue md_msg;
md_msg.key = librealsense::get_string(type);
md_msg.value = std::to_string(md);
Expand Down
Loading