Skip to content
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

dds_stream now inherits from dds_stream_base #11036

Merged
merged 7 commits into from
Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from 6 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
67 changes: 38 additions & 29 deletions src/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,29 +501,29 @@ namespace librealsense
{
std::shared_ptr< realdds::dds_device > _dds_dev;

rs2_video_stream to_rs2_video_stream( const realdds::dds_video_stream_profile & profile )
rs2_video_stream to_rs2_video_stream( std::shared_ptr< realdds::dds_video_stream_profile > const & profile )
{
rs2_video_stream prof;
prof.type = RS2_STREAM_ANY;
prof.index = profile.uid().index;
prof.uid = profile.uid().sid;
prof.width = profile.width();
prof.height = profile.height();
prof.fps = profile.frequency();
prof.fmt = static_cast< rs2_format >( profile.format().to_rs2() );
prof.index = profile->uid().index;
prof.uid = profile->uid().sid;
prof.width = profile->width();
prof.height = profile->height();
prof.fps = profile->frequency();
prof.fmt = static_cast< rs2_format >( profile->format().to_rs2() );
// TODO - add intrinsics

return prof;
}

rs2_motion_stream to_rs2_motion_stream( const realdds::dds_motion_stream_profile & profile )
rs2_motion_stream to_rs2_motion_stream( std::shared_ptr< realdds::dds_motion_stream_profile > const & profile )
{
rs2_motion_stream prof;
prof.type = RS2_STREAM_ANY;
prof.index = profile.uid().index;
prof.uid = profile.uid().sid;
prof.fps = profile.frequency();
prof.fmt = static_cast< rs2_format >( profile.format().to_rs2() );
prof.index = profile->uid().index;
prof.uid = profile->uid().sid;
prof.fps = profile->frequency();
prof.fmt = static_cast< rs2_format >( profile->format().to_rs2() );

return prof;
}
Expand All @@ -543,32 +543,41 @@ namespace librealsense

//Assumes dds_device initialization finished
std::set< std::string > sensor_names;
_dds_dev->foreach_stream( [&]( std::shared_ptr< const realdds::dds_stream > stream ) {
if( sensor_names.find( stream->get_group_name() ) == sensor_names.end() )
{
sensor_names.insert( stream->get_group_name() );
this->add_dds_sensor( _dds_dev, stream->get_group_name() );
}
} );
_dds_dev->foreach_stream( [&]( std::shared_ptr< const realdds::dds_stream > const & stream ) {
if( sensor_names.find( stream->sensor_name() ) == sensor_names.end() )
{
sensor_names.insert( stream->sensor_name() );
this->add_dds_sensor( _dds_dev, stream->sensor_name() );
}
} );
for( size_t i = 0; i < sensor_names.size(); ++i )
{
software_sensor & sensor = get_software_sensor( i );
auto sensor_name = sensor.get_info( RS2_CAMERA_INFO_NAME );
_dds_dev->foreach_stream( [&]( std::shared_ptr< realdds::dds_stream > stream ) {
if ( sensor_name.compare( stream->get_group_name() ) == 0 )
_dds_dev->foreach_stream( [&]( std::shared_ptr< realdds::dds_stream > const & stream ) {
if ( sensor_name.compare( stream->sensor_name() ) == 0 )
{
stream->foreach_profile( [&]( const realdds::dds_stream_profile & profile, bool default_profile ) {
if(std::dynamic_pointer_cast< realdds::dds_video_stream >( stream ) )
auto video_stream = std::dynamic_pointer_cast< realdds::dds_video_stream >( stream );
auto motion_stream = std::dynamic_pointer_cast< realdds::dds_motion_stream >( stream );
auto & profiles = stream->profiles();
auto default_profile = profiles[stream->default_profile_index()];
for( auto & profile : profiles )
{
if( video_stream )
{
sensor.add_video_stream( to_rs2_video_stream( static_cast< const realdds::dds_video_stream_profile & >( profile ) ),
default_profile );
sensor.add_video_stream(
to_rs2_video_stream(
std::static_pointer_cast< realdds::dds_video_stream_profile >( profile ) ),
profile == default_profile );
}
if ( std::dynamic_pointer_cast< realdds::dds_motion_stream >( stream ) )
else if( motion_stream )
{
sensor.add_motion_stream( to_rs2_motion_stream( static_cast< const realdds::dds_motion_stream_profile & >( profile ) ),
default_profile );
sensor.add_motion_stream(
to_rs2_motion_stream(
std::static_pointer_cast< realdds::dds_motion_stream_profile >( profile ) ),
profile == default_profile );
}
} ); //End foreach_profile lambda
}
}
} ); //End foreach_stream lambda
}
Expand Down
5 changes: 3 additions & 2 deletions src/hw-monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ namespace librealsense
{
if (ptr) _heap.deallocate(ptr);
});
if (!token.get()) throw;
if (!token.get())
throw std::runtime_error( "no token in locked_transfer::send_receive" );

std::lock_guard<std::recursive_mutex> lock(_local_mtx);
return _uvc_sensor_base.invoke_powered([&]
Expand Down Expand Up @@ -350,7 +351,7 @@ namespace librealsense
{
T rv = 0;
if (index + sizeof(T) >= data.size())
throw new std::runtime_error("get_gvd_field - index out of bounds, buffer size: " +
throw std::runtime_error("get_gvd_field - index out of bounds, buffer size: " +
std::to_string(data.size()) + ", index: " + std::to_string(index));
for (int i = 0; i < sizeof(T); i++)
rv += data[index + i] << (i * 8);
Expand Down
10 changes: 6 additions & 4 deletions third-party/realdds/include/realdds/dds-stream-profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace realdds {

union dds_stream_uid
{
uint32_t whole;
uint32_t whole = 0;
Copy link
Contributor

@OhadMeir OhadMeir Oct 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant
If a non-static data member has a default member initializer and also appears in a member initializer list, then the member initializer is used and the default member initializer is ignored
cppreference

Copy link
Collaborator Author

@maloel maloel Oct 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hehe
And the default ctor?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. It was hidden in a collapsed part of the code.

But seeing the two added initializations made me wonder which initialization prevails :-)

struct
{
int16_t sid; // Stream ID; assigned by the server, but may not be unique because of index
Expand All @@ -32,9 +32,11 @@ union dds_stream_uid
}

dds_stream_uid( int sid_, int index_ )
: sid( static_cast< int16_t >( sid_ ))
, index( static_cast< int8_t >( index_ ))
{}
{
whole = 0; // it covers an extra byte, which needs to be 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to change in default constructor as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the default uses the = 0 from above.

sid = static_cast<int16_t>( sid_ );
index = static_cast<int8_t>( index_ );
}

std::string to_string() const;
};
Expand Down
119 changes: 61 additions & 58 deletions third-party/realdds/include/realdds/dds-stream.h
Original file line number Diff line number Diff line change
@@ -1,58 +1,61 @@
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2022 Intel Corporation. All Rights Reserved.

#pragma once

#include "dds-stream-profile.h"

#include <functional>
#include <memory>
#include <string>

namespace realdds {


// Represents a stream of information (images, motion data, etc..) from a single source received via the DDS system.
// A stream can have several profiles, i.e different data frequency, image resolution, etc..
class dds_stream
{
public:
virtual const std::string & get_group_name() const = 0;

virtual size_t foreach_profile( std::function< void( const dds_stream_profile & prof, bool def_prof ) > fn ) const = 0;

virtual ~dds_stream() = default;
};

class dds_video_stream : public dds_stream
{
public:
dds_video_stream( const std::string & group_name );

const std::string & get_group_name() const override;

void add_profile( dds_video_stream_profile && prof, bool default_profile );
size_t foreach_profile( std::function< void( const dds_stream_profile & prof, bool def_prof ) > fn ) const override;

private:
class impl;
std::shared_ptr< impl > _impl;
};

class dds_motion_stream : public dds_stream
{
public:
dds_motion_stream( const std::string & group_name );

const std::string & get_group_name() const override;

void add_profile( dds_motion_stream_profile && prof, bool default_profile );
size_t foreach_profile( std::function< void( const dds_stream_profile & prof, bool def_prof ) > fn ) const override;

private:
class impl;
std::shared_ptr< impl > _impl;
};


} // namespace realdds
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2022 Intel Corporation. All Rights Reserved.

#pragma once

#include "dds-stream-base.h"
#include "dds-stream-profile.h"

#include <functional>
#include <memory>
#include <string>

namespace realdds {


// Represents a stream of information (images, motion data, etc..) from a single source received via the DDS system.
// A stream can have several profiles, i.e different data frequency, image resolution, etc..
//
// This is a base class: you need to specify the type of stream via the instantiation of a video_stream, etc.
//
class dds_stream : public dds_stream_base
{
typedef dds_stream_base super;

protected:
dds_stream( std::string const & stream_name, std::string const & sensor_name );

// dds_stream_base
public:
bool is_open() const override;
bool is_streaming() const override;

std::shared_ptr< dds_topic > const & get_topic() const override;
};

class dds_video_stream : public dds_stream
{
typedef dds_stream super;

public:
dds_video_stream( std::string const & stream_name, std::string const & sensor_name );

private:
class impl;
std::shared_ptr< impl > _impl;
};

class dds_motion_stream : public dds_stream
{
typedef dds_stream super;

public:
dds_motion_stream( std::string const & stream_name, std::string const & sensor_name );

private:
class impl;
std::shared_ptr< impl > _impl;
};


} // namespace realdds
Loading