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

Remove redundant frame copies inside librealsense core #10573

Merged
Merged
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
20 changes: 13 additions & 7 deletions src/sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,12 @@ void log_callback_end( uint32_t fps,
{
auto system_time = environment::get_instance().get_time_service()->get_time();
auto fr = std::make_shared<frame>();
byte* pix = (byte*)fo.pixels;
std::vector<byte> pixels(pix, pix + fo.frame_size);
fr->data = pixels;

//REMOVED! - no need to add 2 copies to a frame
//byte* pix = (byte*)fo.pixels;
//std::vector<byte> pixels(pix, pix + fo.frame_size);
//fr->data = pixels;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is dangerous.
This leaves fr->data (for regular frames) basically uninitialized (empty), right? I.e., as long as it's not used, we're OK. So why not remove it?
I believe a composite frame still uses it... maybe we can move it there?
(not for this PR, but general thought)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree, like we said the generate_frame_from_data() needs to be refactored

fr->set_stream(profile);

frame_additional_data additional_data(0,
0,
system_time,
Expand Down Expand Up @@ -398,9 +399,12 @@ void log_callback_end( uint32_t fps,

if (fh.frame)
{
assert( expected_size == sizeof(byte) * fr->data.size() );
assert( expected_size == sizeof(byte) * /*fr->data.size()*/f.frame_size );

memcpy( (void *)fh->get_frame_data(),
/*fr->data.data()*/ f.pixels,
expected_size );

memcpy((void*)fh->get_frame_data(), fr->data.data(), expected_size);
auto&& video = (video_frame*)fh.frame;
video->assign(width, height, width * bpp / 8, bpp);
video->set_timestamp_domain(timestamp_domain);
Expand Down Expand Up @@ -898,7 +902,9 @@ void log_callback_end( uint32_t fps,
last_frame_number = frame_counter;
last_timestamp = timestamp;
frame_holder frame = _source.alloc_frame(RS2_EXTENSION_MOTION_FRAME, data_size, fr->additional_data, true);
memcpy((void*)frame->get_frame_data(), fr->data.data(), sizeof(byte)*fr->data.size());
memcpy( (void *)frame->get_frame_data(),
/*fr->data.data()*/ sensor_data.fo.pixels,
/*fr->data.size()*/ sizeof( byte ) * sensor_data.fo.frame_size );
if (!frame)
{
LOG_INFO("Dropped frame. alloc_frame(...) returned nullptr");
Expand Down