-
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
Unify notification and control messages using "flexible-message" #11063
Changes from all commits
d88a93e
3aac563
7a6ca4f
163d298
6936981
9d904ea
83b4e16
f811db7
5683978
290f2fb
718d5c3
716e5cf
fd3c6d5
e1b4ad9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,41 +15,6 @@ | |
namespace realdds { | ||
|
||
|
||
union dds_stream_uid | ||
{ | ||
uint32_t whole = 0; | ||
struct | ||
{ | ||
int16_t sid; // Stream ID; assigned by the server, but may not be unique because of index | ||
int8_t index; // Used to distinguish similar streams like IR L / R, 0 otherwise | ||
}; | ||
|
||
dds_stream_uid() = default; | ||
dds_stream_uid( dds_stream_uid const & ) = default; | ||
dds_stream_uid( dds_stream_uid && ) = default; | ||
|
||
dds_stream_uid( uint32_t whole_ ) | ||
: whole( whole_ ) | ||
{ | ||
} | ||
|
||
dds_stream_uid( int sid_, int index_ ) | ||
{ | ||
whole = 0; // it covers an extra byte, which needs to be 0 | ||
sid = static_cast<int16_t>( sid_ ); | ||
index = static_cast<int8_t>( index_ ); | ||
} | ||
|
||
std::string to_string() const; | ||
}; | ||
|
||
|
||
inline bool operator<( dds_stream_uid const & l, dds_stream_uid const & r ) | ||
{ | ||
return l.whole < r.whole; | ||
} | ||
|
||
|
||
// Similar to fourcc, this describes how a stream data is organized. The characters are zero-terminated so it can be | ||
// shorter than 'size' and can be easily converted from/to string. | ||
// | ||
|
@@ -83,39 +48,52 @@ class dds_stream_base; | |
|
||
class dds_stream_profile | ||
{ | ||
dds_stream_uid _uid; | ||
dds_stream_format _format; | ||
int16_t _frequency; // "Frames" per second | ||
dds_stream_format _format; | ||
|
||
std::weak_ptr< dds_stream_base > _stream; | ||
|
||
public: | ||
virtual ~dds_stream_profile() {} | ||
|
||
protected: | ||
dds_stream_profile( dds_stream_uid uid, dds_stream_format format, int16_t frequency ) | ||
: _uid( uid ) | ||
, _format( format ) | ||
dds_stream_profile( dds_stream_format format, int16_t frequency ) | ||
: _format( format ) | ||
, _frequency( frequency ) | ||
{ | ||
} | ||
dds_stream_profile( dds_stream_profile && ) = default; | ||
dds_stream_profile( nlohmann::json const &, int & index ); | ||
|
||
public: | ||
std::shared_ptr< dds_stream_base > stream() const { return _stream.lock(); } | ||
// This is for initialization and is called from dds_stream_base only! | ||
void init_stream( std::weak_ptr< dds_stream_base > const & stream ); | ||
|
||
dds_stream_uid uid() const { return _uid; } | ||
dds_stream_format format() const { return _format; } | ||
int16_t frequency() const { return _frequency; } | ||
|
||
// These are for debugging - not functional | ||
virtual std::string to_string() const; | ||
virtual std::string details_to_string() const; | ||
|
||
// Serialization to a JSON representation | ||
// Serialization to a JSON array representation | ||
virtual nlohmann::json to_json() const; | ||
|
||
// Build a profile from a json array object, e.g.: | ||
// auto profile = dds_stream_profile::from_json< dds_video_stream_profile >( j ); | ||
// This is the reverse of to_json() which returns a json array | ||
template< class final_stream_profile > | ||
static std::shared_ptr< final_stream_profile > from_json( nlohmann::json const & j ) | ||
{ | ||
int it = 0; | ||
auto profile = std::make_shared< final_stream_profile >( j, it ); | ||
verify_end_of_json( j, it ); // just so it's not in the header | ||
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. Why not put all of 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. It's a template... |
||
return profile; | ||
} | ||
|
||
private: | ||
static void verify_end_of_json( nlohmann::json const &, int index ); | ||
}; | ||
|
||
|
||
|
@@ -128,21 +106,19 @@ class dds_video_stream_profile : public dds_stream_profile | |
|
||
uint16_t _width; // Resolution width [pixels] | ||
uint16_t _height; // Resolution height [pixels] | ||
uint8_t _bytes_per_pixel; | ||
|
||
public: | ||
dds_video_stream_profile( dds_stream_uid uid, dds_stream_format format, int16_t frequency, uint16_t width, uint16_t height, uint8_t bytes_per_pixel ) | ||
: dds_stream_profile( uid, format, frequency ) | ||
dds_video_stream_profile( dds_stream_format format, int16_t frequency, uint16_t width, uint16_t height ) | ||
: super( format, frequency ) | ||
, _width( width ) | ||
, _height( height ) | ||
, _bytes_per_pixel( bytes_per_pixel ) | ||
{ | ||
} | ||
dds_video_stream_profile( nlohmann::json const &, int & index ); | ||
dds_video_stream_profile( dds_video_stream_profile && ) = default; | ||
|
||
uint16_t width() const { return _width; } | ||
uint16_t height() const { return _height; } | ||
uint8_t bytes_per_pixel() const { return _bytes_per_pixel; } | ||
|
||
std::string details_to_string() const override; | ||
|
||
|
@@ -155,8 +131,12 @@ class dds_motion_stream_profile : public dds_stream_profile | |
typedef dds_stream_profile super; | ||
|
||
public: | ||
dds_motion_stream_profile( dds_stream_uid uid, dds_stream_format format, int16_t frequency ) | ||
: dds_stream_profile( uid, format, frequency ) | ||
dds_motion_stream_profile( dds_stream_format format, int16_t frequency ) | ||
: super( format, frequency ) | ||
{ | ||
} | ||
dds_motion_stream_profile( nlohmann::json const & j, int & index ) | ||
: super( j, index ) | ||
{ | ||
} | ||
dds_motion_stream_profile( dds_motion_stream_profile && ) = default; | ||
|
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.
It is more efficient to initialize members by declaration order.
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.
AFAIK the init order is the order of decl, whatever order you write them in.