Skip to content

Commit

Permalink
PR IntelRealSense#12585 from OhadMeir: Separate frame archives for IR…
Browse files Browse the repository at this point in the history
… streams
  • Loading branch information
OhadMeir authored Jan 18, 2024
2 parents 322e1c3 + 4fbf772 commit 6f26390
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 34 deletions.
9 changes: 5 additions & 4 deletions src/hid-sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,11 @@ void hid_sensor::start( rs2_frame_callback_sptr callback )

last_frame_number = frame_counter;
last_timestamp = timestamp;
frame_holder frame = _source.alloc_frame( { request->get_stream_type(), RS2_EXTENSION_MOTION_FRAME },
data_size,
std::move( fr->additional_data ),
true );
frame_holder frame = _source.alloc_frame(
{ request->get_stream_type(), request->get_stream_index(), RS2_EXTENSION_MOTION_FRAME },
data_size,
std::move( fr->additional_data ),
true );
memcpy( (void *)frame->get_frame_data(),
sensor_data.fo.pixels,
sizeof( uint8_t ) * sensor_data.fo.frame_size );
Expand Down
20 changes: 11 additions & 9 deletions src/media/ros/ros_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ namespace librealsense
}

frame_interface * frame = m_frame_source->alloc_frame(
{ stream_id.stream_type, frame_source::stream_to_frame_types( stream_id.stream_type ) },
{ stream_id.stream_type, stream_id.stream_index, frame_source::stream_to_frame_types( stream_id.stream_type ) },
msg->data.size(),
std::move( additional_data ),
true );
Expand Down Expand Up @@ -488,10 +488,11 @@ namespace librealsense
get_frame_metadata(m_file, info_topic, stream_id, motion_data, additional_data);
}

frame_interface * frame = m_frame_source->alloc_frame( { stream_id.stream_type, RS2_EXTENSION_MOTION_FRAME },
3 * sizeof( float ),
std::move( additional_data ),
true );
frame_interface * frame = m_frame_source->alloc_frame(
{ stream_id.stream_type, stream_id.stream_index, RS2_EXTENSION_MOTION_FRAME },
3 * sizeof( float ),
std::move( additional_data ),
true );
if (frame == nullptr)
{
LOG_WARNING("Failed to allocate new frame");
Expand Down Expand Up @@ -637,10 +638,11 @@ namespace librealsense

additional_data.timestamp = timestamp_ms.count();

frame_interface * new_frame = m_frame_source->alloc_frame( { stream_id.stream_type, frame_type },
frame_size,
std::move( additional_data ),
true );
frame_interface * new_frame = m_frame_source->alloc_frame(
{ stream_id.stream_type, stream_id.stream_index, frame_type },
frame_size,
std::move( additional_data ),
true );

if (new_frame == nullptr)
{
Expand Down
19 changes: 10 additions & 9 deletions src/proc/synthetic-stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ namespace librealsense

void processing_block::invoke(frame_holder f)
{
frame_source::archive_id id = { f->get_stream()->get_stream_type(), RS2_EXTENSION_VIDEO_FRAME };
frame_source::archive_id id
= { f->get_stream()->get_stream_type(), f->get_stream()->get_stream_index(), RS2_EXTENSION_VIDEO_FRAME };
auto callback = _source.begin_callback( id );
try
{
Expand Down Expand Up @@ -353,11 +354,11 @@ namespace librealsense
data.system_time = time_service::get_time();
data.is_blocking = original->is_blocking();

auto res
= _actual_source.alloc_frame( { vid_stream->get_stream_type(), frame_type },
vid_stream->get_width() * vid_stream->get_height() * sizeof( float ) * 5,
std::move( data ),
true );
auto res = _actual_source.alloc_frame(
{ vid_stream->get_stream_type(), vid_stream->get_stream_index(), frame_type },
vid_stream->get_width() * vid_stream->get_height() * sizeof( float ) * 5,
std::move( data ),
true );
if (!res) throw wrong_api_call_sequence_exception("Out of frame resources!");
res->set_sensor(original->get_sensor());
res->set_stream(stream);
Expand Down Expand Up @@ -421,7 +422,7 @@ namespace librealsense
throw std::runtime_error("Can not cast frame interface to frame");

frame_additional_data data = of->additional_data;
auto res = _actual_source.alloc_frame( { stream->get_stream_type(), frame_type },
auto res = _actual_source.alloc_frame( { stream->get_stream_type(), stream->get_stream_index(), frame_type },
stride * height,
std::move( data ),
true );
Expand Down Expand Up @@ -456,7 +457,7 @@ namespace librealsense
throw std::runtime_error("Frame interface is not frame");

frame_additional_data data = of->additional_data;
auto res = _actual_source.alloc_frame( { stream->get_stream_type(), frame_type },
auto res = _actual_source.alloc_frame( { stream->get_stream_type(), stream->get_stream_index(), frame_type },
of->get_frame_data_size(),
std::move( data ),
true );
Expand Down Expand Up @@ -509,7 +510,7 @@ namespace librealsense
for (auto&& f : holders)
req_size += get_embeded_frames_size(f.frame);

auto res = _actual_source.alloc_frame( { RS2_STREAM_ANY, RS2_EXTENSION_COMPOSITE_FRAME }, // Special case for composite frames
auto res = _actual_source.alloc_frame( { RS2_STREAM_ANY, 0, RS2_EXTENSION_COMPOSITE_FRAME }, // Special case for composite frames
req_size * sizeof( rs2_frame * ),
std::move( d ),
true );
Expand Down
5 changes: 4 additions & 1 deletion src/software-sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,10 @@ frame_interface * software_sensor::allocate_new_frame( rs2_extension extension,
frame_additional_data && data )
{
auto frame_number = data.frame_number; // For logging
auto frame = _source.alloc_frame( { profile->get_stream_type(), extension }, 0, std::move( data ), false );
auto frame = _source.alloc_frame( { profile->get_stream_type(), profile->get_stream_index(), extension },
0,
std::move( data ),
false );
if( ! frame )
{
LOG_WARNING( "Failed to allocate frame " << frame_number << " type " << profile->get_stream_type() );
Expand Down
16 changes: 8 additions & 8 deletions src/source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ namespace librealsense
{
std::lock_guard< std::recursive_mutex > lock( _mutex );

auto it = std::find( _supported_extensions.begin(), _supported_extensions.end(), id.second );
rs2_extension & ex = std::get< rs2_extension >( id );
auto it = std::find( _supported_extensions.begin(), _supported_extensions.end(), ex );
if( it == _supported_extensions.end() )
throw wrong_api_call_sequence_exception( "Requested frame type is not supported!" );

auto ret = _archive.insert( { id, make_archive( id.second, &_max_publish_list_size, _metadata_parsers ) } );
auto ret = _archive.insert( { id, make_archive( ex, &_max_publish_list_size, _metadata_parsers ) } );
if( ! ret.second || ! ret.first->second ) // Check insertion success and allocation success
throw std::runtime_error( rsutils::string::from()
<< "Failed to create archive of type " << get_string( id.second ) );
throw std::runtime_error( rsutils::string::from() << "Failed to create archive of type " << get_string( ex ) );

ret.first->second->set_sensor( _sensor );

Expand All @@ -89,8 +89,8 @@ namespace librealsense
callback_invocation_holder frame_source::begin_callback( archive_id id )
{
// We use a special index for extensions, like GPU accelerated frames. See add_extension.
if( id.second >= RS2_EXTENSION_COUNT )
id.first = RS2_STREAM_COUNT;
if( std::get< rs2_extension >( id ) >= RS2_EXTENSION_COUNT )
std::get< rs2_stream >( id ) = RS2_STREAM_COUNT; // For added extensions like GPU accelerated frames

std::lock_guard< std::recursive_mutex > lock( _mutex );

Expand All @@ -116,8 +116,8 @@ namespace librealsense
bool requires_memory )
{
// We use a special index for extensions, like GPU accelerated frames. See add_extension.
if( id.second >= RS2_EXTENSION_COUNT )
id.first = RS2_STREAM_COUNT; // For added extensions like GPU accelerated frames
if( std::get< rs2_extension>( id ) >= RS2_EXTENSION_COUNT )
std::get< rs2_stream >( id ) = RS2_STREAM_COUNT; // For added extensions like GPU accelerated frames

std::lock_guard< std::recursive_mutex > lock( _mutex );

Expand Down
5 changes: 3 additions & 2 deletions src/source.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <librealsense2/hpp/rs_types.hpp>
#include <src/frame-archive.h>

#include <tuple>

namespace librealsense
{
Expand All @@ -17,7 +18,7 @@ namespace librealsense
class LRS_EXTENSION_API frame_source
{
public:
using archive_id = std::pair< rs2_stream, rs2_extension >;
using archive_id = std::tuple< rs2_stream, int, rs2_extension >; // Stream type, stream index, extention type.

frame_source( uint32_t max_publish_list_size = 16 );

Expand Down Expand Up @@ -58,7 +59,7 @@ namespace librealsense

// We use a special index for extensions since we don't know the stream type here.
// We can't wait with the allocation because we need the type T in the creation.
archive_id special_index = { RS2_STREAM_COUNT, ex };
archive_id special_index = { RS2_STREAM_COUNT, 0, ex };
_archive[special_index] = std::make_shared< frame_archive< T > >( &_max_publish_list_size, _metadata_parsers );
}

Expand Down
2 changes: 1 addition & 1 deletion src/uvc-sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ void uvc_sensor::open( const stream_profiles & requests )

auto extension = frame_source::stream_to_frame_types( req_profile_base->get_stream_type() );
frame_holder fh = _source.alloc_frame(
{ req_profile_base->get_stream_type(), extension },
{ req_profile_base->get_stream_type(), req_profile_base->get_stream_index(), extension },
expected_size,
std::move( fr->additional_data ),
true );
Expand Down

0 comments on commit 6f26390

Please sign in to comment.