-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PR #12200 from Eran: Refactor device.h
- Loading branch information
Showing
45 changed files
with
833 additions
and
624 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// License: Apache 2.0. See LICENSE file in root directory. | ||
// Copyright(c) 2023 Intel Corporation. All Rights Reserved. | ||
|
||
#pragma once | ||
|
||
#include "info-interface.h" | ||
#include "tagged-profile.h" | ||
#include "stream-profile.h" | ||
|
||
#include <librealsense2/h/rs_sensor.h> | ||
#include <functional> | ||
#include <vector> | ||
#include <memory> | ||
#include <utility> // std::pair | ||
|
||
|
||
namespace librealsense { | ||
|
||
|
||
class sensor_interface; | ||
class matcher; | ||
class frame_holder; | ||
class context; | ||
class device_info; | ||
class stream_interface; | ||
class stream_profile_interface; | ||
|
||
|
||
// Base class for all devices in librealsense | ||
// | ||
class device_interface | ||
: public virtual info_interface | ||
, public std::enable_shared_from_this< device_interface > | ||
{ | ||
public: | ||
virtual ~device_interface() = default; | ||
|
||
// Return the context to which this device belongs | ||
// Typically, same as get_device_info()->context() | ||
// | ||
virtual std::shared_ptr< context > get_context() const = 0; | ||
|
||
// Returns the device_info object from which this device was created | ||
// | ||
virtual std::shared_ptr< const device_info > get_device_info() const = 0; | ||
|
||
virtual sensor_interface & get_sensor( size_t i ) = 0; | ||
virtual const sensor_interface & get_sensor( size_t i ) const = 0; | ||
virtual size_t get_sensors_count() const = 0; | ||
|
||
virtual void hardware_reset() = 0; | ||
|
||
virtual std::shared_ptr< matcher > create_matcher( const frame_holder & frame ) const = 0; | ||
|
||
virtual std::pair< uint32_t, rs2_extrinsics > get_extrinsics( const stream_interface & ) const = 0; | ||
|
||
virtual bool is_valid() const = 0; | ||
|
||
virtual std::vector< tagged_profile > get_profiles_tags() const = 0; | ||
|
||
using stream_profiles = std::vector< std::shared_ptr< stream_profile_interface > >; | ||
virtual void tag_profiles( stream_profiles profiles ) const = 0; | ||
|
||
// Return true if this device should use compression when recording to a bag file | ||
// | ||
virtual bool compress_while_record() const = 0; | ||
|
||
virtual bool contradicts( const stream_profile_interface * a, | ||
const std::vector< stream_profile > & others ) const = 0; | ||
}; | ||
|
||
|
||
} // namespace librealsense |
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// License: Apache 2.0. See LICENSE file in root directory. | ||
// Copyright(c) 2023 Intel Corporation. All Rights Reserved. | ||
|
||
#pragma once | ||
|
||
#include "extension.h" | ||
#include <src/basics.h> | ||
|
||
#include <librealsense2/h/rs_sensor.h> | ||
#include <string> | ||
|
||
|
||
namespace librealsense { | ||
|
||
|
||
// Anything that can support getting rs2_camera_info should implement this. | ||
// | ||
class info_interface : public virtual recordable< info_interface > | ||
{ | ||
public: | ||
virtual const std::string & get_info( rs2_camera_info info ) const = 0; | ||
virtual bool supports_info( rs2_camera_info info ) const = 0; | ||
|
||
virtual ~info_interface() = default; | ||
}; | ||
|
||
MAP_EXTENSION( RS2_EXTENSION_INFO, librealsense::info_interface ); | ||
|
||
|
||
} // namespace librealsense |
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 |
---|---|---|
@@ -1,37 +1,40 @@ | ||
// License: Apache 2.0. See LICENSE file in root directory. | ||
// Copyright(c) 2017 Intel Corporation. All Rights Reserved. | ||
// Copyright(c) 2023 Intel Corporation. All Rights Reserved. | ||
|
||
#pragma once | ||
|
||
#include "extension.h" | ||
#include "info-interface.h" | ||
|
||
#include <map> | ||
#include <string> | ||
#include <memory> | ||
|
||
|
||
namespace librealsense { | ||
|
||
namespace librealsense | ||
|
||
// Simple implementation of info_interface | ||
// | ||
class LRS_EXTENSION_API info_container | ||
: public virtual info_interface | ||
, public extension_snapshot | ||
{ | ||
class info_interface : public virtual recordable<info_interface> | ||
{ | ||
public: | ||
virtual const std::string& get_info(rs2_camera_info info) const = 0; | ||
virtual bool supports_info(rs2_camera_info info) const = 0; | ||
|
||
virtual ~info_interface() = default; | ||
}; | ||
|
||
MAP_EXTENSION(RS2_EXTENSION_INFO, librealsense::info_interface); | ||
|
||
class LRS_EXTENSION_API info_container : public virtual info_interface, public extension_snapshot | ||
{ | ||
public: | ||
const std::string& get_info(rs2_camera_info info) const override; | ||
bool supports_info(rs2_camera_info info) const override; | ||
|
||
void register_info(rs2_camera_info info, const std::string& val); | ||
void update_info(rs2_camera_info info, const std::string& val); | ||
void create_snapshot(std::shared_ptr<info_interface>& snapshot) const override; | ||
void enable_recording(std::function<void(const info_interface&)> record_action) override; | ||
void update(std::shared_ptr<extension_snapshot> ext) override; | ||
private: | ||
std::map<rs2_camera_info, std::string> _camera_info; | ||
}; | ||
|
||
} | ||
public: | ||
void register_info( rs2_camera_info info, const std::string & val ); | ||
void update_info( rs2_camera_info info, const std::string & val ); | ||
|
||
// info_interface | ||
const std::string & get_info( rs2_camera_info info ) const override; | ||
bool supports_info( rs2_camera_info info ) const override; | ||
|
||
// extension_snapshot | ||
void create_snapshot( std::shared_ptr< info_interface > & snapshot ) const override; | ||
void enable_recording( std::function< void( const info_interface & ) > record_action ) override; | ||
void update( std::shared_ptr< extension_snapshot > ext ) override; | ||
|
||
private: | ||
std::map< rs2_camera_info, std::string > _camera_info; | ||
}; | ||
|
||
|
||
} // namespace librealsense |
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 |
---|---|---|
@@ -0,0 +1,166 @@ | ||
// License: Apache 2.0. See LICENSE file in root directory. | ||
// Copyright(c) 2023 Intel Corporation. All Rights Reserved. | ||
|
||
#include "matcher-factory.h" | ||
#include "frame-holder.h" | ||
|
||
#include <src/sync.h> | ||
|
||
|
||
namespace librealsense { | ||
|
||
|
||
std::shared_ptr< matcher > matcher_factory::create( rs2_matchers matcher, | ||
std::vector< stream_interface * > const & profiles ) | ||
{ | ||
switch( matcher ) | ||
{ | ||
case RS2_MATCHER_DI: | ||
return create_DI_matcher( profiles ); | ||
case RS2_MATCHER_DI_C: | ||
return create_DI_C_matcher( profiles ); | ||
case RS2_MATCHER_DLR_C: | ||
return create_DLR_C_matcher( profiles ); | ||
case RS2_MATCHER_DLR: | ||
return create_DLR_matcher( profiles ); | ||
case RS2_MATCHER_DIC: | ||
return create_DIC_matcher( profiles ); | ||
case RS2_MATCHER_DIC_C: | ||
return create_DIC_C_matcher( profiles ); | ||
|
||
case RS2_MATCHER_DEFAULT: | ||
default: | ||
return create_timestamp_matcher( profiles ); | ||
} | ||
} | ||
|
||
|
||
std::shared_ptr< matcher > matcher_factory::create_DLR_C_matcher( std::vector< stream_interface * > const & profiles ) | ||
{ | ||
auto color = find_profile( RS2_STREAM_COLOR, 0, profiles ); | ||
if( ! color ) | ||
{ | ||
LOG_DEBUG( "Created default matcher" ); | ||
return create_timestamp_matcher( profiles ); | ||
} | ||
|
||
return create_timestamp_composite_matcher( { create_DLR_matcher( profiles ), create_identity_matcher( color ) } ); | ||
} | ||
|
||
|
||
std::shared_ptr< matcher > matcher_factory::create_DI_C_matcher( std::vector< stream_interface * > const & profiles ) | ||
{ | ||
auto color = find_profile( RS2_STREAM_COLOR, 0, profiles ); | ||
if( ! color ) | ||
{ | ||
LOG_DEBUG( "Created default matcher" ); | ||
return create_timestamp_matcher( profiles ); | ||
} | ||
|
||
return create_timestamp_composite_matcher( { create_DI_matcher( profiles ), create_identity_matcher( color ) } ); | ||
} | ||
|
||
|
||
std::shared_ptr< matcher > matcher_factory::create_DLR_matcher( std::vector< stream_interface * > const & profiles ) | ||
{ | ||
auto depth = find_profile( RS2_STREAM_DEPTH, 0, profiles ); | ||
auto left = find_profile( RS2_STREAM_INFRARED, 1, profiles ); | ||
auto right = find_profile( RS2_STREAM_INFRARED, 2, profiles ); | ||
|
||
if( ! depth || ! left || ! right ) | ||
{ | ||
LOG_DEBUG( "Created default matcher" ); | ||
return create_timestamp_matcher( profiles ); | ||
} | ||
return create_frame_number_matcher( { depth, left, right } ); | ||
} | ||
|
||
|
||
std::shared_ptr< matcher > matcher_factory::create_DI_matcher( std::vector< stream_interface * > const & profiles ) | ||
{ | ||
auto depth = find_profile( RS2_STREAM_DEPTH, 0, profiles ); | ||
auto ir = find_profile( RS2_STREAM_INFRARED, 1, profiles ); | ||
|
||
if( ! depth || ! ir ) | ||
{ | ||
LOG_DEBUG( "Created default matcher" ); | ||
return create_timestamp_matcher( profiles ); | ||
} | ||
return create_frame_number_matcher( { depth, ir } ); | ||
} | ||
|
||
|
||
std::shared_ptr< matcher > matcher_factory::create_DIC_matcher( std::vector< stream_interface * > const & profiles ) | ||
{ | ||
std::vector< std::shared_ptr< matcher > > matchers; | ||
if( auto depth = find_profile( RS2_STREAM_DEPTH, -1, profiles ) ) | ||
matchers.push_back( create_identity_matcher( depth ) ); | ||
if( auto ir = find_profile( RS2_STREAM_INFRARED, -1, profiles ) ) | ||
matchers.push_back( create_identity_matcher( ir ) ); | ||
if( auto confidence = find_profile( RS2_STREAM_CONFIDENCE, -1, profiles ) ) | ||
matchers.push_back( create_identity_matcher( confidence ) ); | ||
|
||
if( matchers.empty() ) | ||
{ | ||
LOG_ERROR( "no depth, ir, or confidence streams found for matcher" ); | ||
for( auto && p : profiles ) | ||
LOG_DEBUG( p->get_stream_type() << '/' << p->get_unique_id() ); | ||
throw std::runtime_error( "no depth, ir, or confidence streams found for matcher" ); | ||
} | ||
|
||
return create_timestamp_composite_matcher( matchers ); | ||
} | ||
|
||
|
||
std::shared_ptr< matcher > matcher_factory::create_DIC_C_matcher( std::vector< stream_interface * > const & profiles ) | ||
{ | ||
auto color = find_profile( RS2_STREAM_COLOR, 0, profiles ); | ||
if( ! color ) | ||
throw std::runtime_error( "no color stream found for matcher" ); | ||
|
||
return create_timestamp_composite_matcher( { create_DIC_matcher( profiles ), create_identity_matcher( color ) } ); | ||
} | ||
|
||
|
||
std::shared_ptr< matcher > | ||
matcher_factory::create_frame_number_matcher( std::vector< stream_interface * > const & profiles ) | ||
{ | ||
std::vector< std::shared_ptr< matcher > > matchers; | ||
for( auto & p : profiles ) | ||
matchers.push_back( std::make_shared< identity_matcher >( p->get_unique_id(), p->get_stream_type() ) ); | ||
|
||
return create_frame_number_composite_matcher( matchers ); | ||
} | ||
|
||
|
||
std::shared_ptr< matcher > | ||
matcher_factory::create_timestamp_matcher( std::vector< stream_interface * > const & profiles ) | ||
{ | ||
std::vector< std::shared_ptr< matcher > > matchers; | ||
for( auto & p : profiles ) | ||
matchers.push_back( std::make_shared< identity_matcher >( p->get_unique_id(), p->get_stream_type() ) ); | ||
|
||
return create_timestamp_composite_matcher( matchers ); | ||
} | ||
|
||
|
||
std::shared_ptr< matcher > matcher_factory::create_identity_matcher( stream_interface * profile ) | ||
{ | ||
return std::make_shared< identity_matcher >( profile->get_unique_id(), profile->get_stream_type() ); | ||
} | ||
|
||
std::shared_ptr< matcher > | ||
matcher_factory::create_frame_number_composite_matcher( std::vector< std::shared_ptr< matcher > > const & matchers ) | ||
{ | ||
return std::make_shared< frame_number_composite_matcher >( matchers ); | ||
} | ||
|
||
|
||
std::shared_ptr< matcher > | ||
matcher_factory::create_timestamp_composite_matcher( std::vector< std::shared_ptr< matcher > > const & matchers ) | ||
{ | ||
return std::make_shared< timestamp_composite_matcher >( matchers ); | ||
} | ||
|
||
|
||
} // namespace librealsense |
Oops, something went wrong.