Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ target_sources(${LRS_TARGET}
"${CMAKE_CURRENT_LIST_DIR}/frame-header.h"
"${CMAKE_CURRENT_LIST_DIR}/frame-holder.h"
"${CMAKE_CURRENT_LIST_DIR}/frame-interface.h"
"${CMAKE_CURRENT_LIST_DIR}/frame-processor-callback.h"
"${CMAKE_CURRENT_LIST_DIR}/info-interface.h"
"${CMAKE_CURRENT_LIST_DIR}/roi.h"
"${CMAKE_CURRENT_LIST_DIR}/matcher-factory.h"
Expand All @@ -33,14 +34,14 @@ target_sources(${LRS_TARGET}
"${CMAKE_CURRENT_LIST_DIR}/extension.h"
"${CMAKE_CURRENT_LIST_DIR}/pose-frame.h"
"${CMAKE_CURRENT_LIST_DIR}/pp-block-factory.h"
"${CMAKE_CURRENT_LIST_DIR}/processing.h"
"${CMAKE_CURRENT_LIST_DIR}/processing-block-interface.h"
"${CMAKE_CURRENT_LIST_DIR}/recommended-processing-blocks-interface.h"
"${CMAKE_CURRENT_LIST_DIR}/sensor-interface.h"
"${CMAKE_CURRENT_LIST_DIR}/serialization.h"
"${CMAKE_CURRENT_LIST_DIR}/stream-interface.h"
"${CMAKE_CURRENT_LIST_DIR}/stream-profile.h"
"${CMAKE_CURRENT_LIST_DIR}/stream-profile-interface.h"
"${CMAKE_CURRENT_LIST_DIR}/synthetic-source-interface.h"
"${CMAKE_CURRENT_LIST_DIR}/tagged-profile.h"
"${CMAKE_CURRENT_LIST_DIR}/has-features-interface.h"
"${CMAKE_CURRENT_LIST_DIR}/features-container.h"
Expand Down
45 changes: 45 additions & 0 deletions src/core/frame-processor-callback.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2023 Intel Corporation. All Rights Reserved.
#pragma once

#include "synthetic-source-interface.h"

#include <librealsense2/hpp/rs_types.hpp>
#include <memory>
#include <functional>


namespace librealsense {


struct frame_processor_callback : public rs2_frame_processor_callback
{
using fn = std::function< void( frame_holder &&, synthetic_source_interface * ) >;

explicit frame_processor_callback( fn && on_frame )
: _on_frame( std::move( on_frame ) )
{
}

void on_frame( rs2_frame * f, rs2_source * source ) override
{
frame_holder front( (frame_interface *)f );
_on_frame( std::move( front ), source->source );
}

void release() override { delete this; }

private:
fn _on_frame;
};


inline rs2_frame_processor_callback_sptr
make_frame_processor_callback( frame_processor_callback::fn && callback )
{
return { new frame_processor_callback( std::move( callback ) ),
[]( rs2_frame_processor_callback * p ) { p->release(); } };
}


} // namespace librealsense
2 changes: 1 addition & 1 deletion src/core/processing-block-interface.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// 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 "options-interface.h"
#include <src/types.h>

#include <vector>
Expand Down
24 changes: 4 additions & 20 deletions src/core/processing.h → src/core/synthetic-source-interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
#pragma once

#include "frame-holder.h"
#include "options-container.h"
#include "info.h"

#include <src/types.h>
#include <librealsense2/hpp/rs_types.hpp>

#include <vector>
#include <memory>

Expand All @@ -25,6 +24,8 @@ namespace librealsense
{
class stream_profile_interface;

// A synthetic source is simply the interface for exposing frame_source APIs
//
class synthetic_source_interface
{
public:
Expand All @@ -49,22 +50,5 @@ namespace librealsense
rs2_extension frame_type = RS2_EXTENSION_POINTS) = 0;

virtual void frame_ready(frame_holder result) = 0;
virtual rs2_source* get_c_wrapper() = 0;
};

template<class T>
class internal_frame_processor_callback : public rs2_frame_processor_callback
{
T on_frame_function;
public:
explicit internal_frame_processor_callback(T on_frame) : on_frame_function(on_frame) {}

void on_frame(rs2_frame * f, rs2_source * source) override
{
frame_holder front((frame_interface*)f);
on_frame_function(std::move(front), source->source);
}

void release() override { delete this; }
};
}
8 changes: 4 additions & 4 deletions src/device_hub.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2015 Intel Corporation. All Rights Reserved.

#include <librealsense2/rs.hpp>
#include "source.h"
#include "core/processing.h"
#include "proc/synthetic-stream.h"
#include "device_hub.h"

#include <rsutils/easylogging/easyloggingpp.h>
#include <librealsense2/rs.hpp>


namespace librealsense
{
typedef rs2::devices_changed_callback<std::function<void(rs2::event_information& info)>> hub_devices_changed_callback;
Expand Down
5 changes: 1 addition & 4 deletions src/gl/synthetic-stream-gl.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@

#pragma once

#include "../proc/synthetic-stream.h"
#include "../core/depth-frame.h"
#include "../core/processing.h"
#include "../image.h"
#include "../source.h"
#include "../points.h"

#include <librealsense2/hpp/rs_frame.hpp>
Expand All @@ -21,7 +19,6 @@
#include <deque>
#include <unordered_set>

#include "../proc/synthetic-stream.h"

#define RS2_EXTENSION_VIDEO_FRAME_GL (rs2_extension)(RS2_EXTENSION_COUNT)
#define RS2_EXTENSION_DEPTH_FRAME_GL (rs2_extension)(RS2_EXTENSION_COUNT + 1)
Expand Down
11 changes: 4 additions & 7 deletions src/pipeline/aggregator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "stream.h"
#include "aggregator.h"
#include <src/composite-frame.h>
#include <src/core/frame-processor-callback.h>

namespace librealsense
{
Expand All @@ -17,13 +18,9 @@ namespace librealsense
_streams_to_sync_ids(streams_to_sync),
_accepting(true)
{
auto processing_callback = [&](frame_holder frame, synthetic_source_interface* source)
{
handle_frame(std::move(frame), source);
};

set_processing_callback(std::shared_ptr<rs2_frame_processor_callback>(
new internal_frame_processor_callback<decltype(processing_callback)>(processing_callback)));
set_processing_callback(
make_frame_processor_callback( [&]( frame_holder && frame, synthetic_source_interface * source )
{ handle_frame( std::move( frame ), source ); } ) );
}

void aggregator::handle_frame(frame_holder frame, synthetic_source_interface* source)
Expand Down
11 changes: 5 additions & 6 deletions src/proc/align.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2017 Intel Corporation. All Rights Reserved.

#pragma once

#include "synthetic-stream.h"

#include <src/basics.h>
#include <map>
#include <utility>
#include "../core/processing.h"
#include "synthetic-stream.h"
#include "../image.h"
#include "../source.h"


namespace librealsense
{
Expand All @@ -19,7 +18,7 @@ namespace librealsense

protected:
align(rs2_stream to_stream, const char* name)
: generic_processing_block(name),
: generic_processing_block(name),
_to_stream_type(to_stream), _depth_scale(0)
{}

Expand Down
6 changes: 3 additions & 3 deletions src/proc/motion-transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "motion-transform.h"
#include "stream.h"
#include <src/platform/hid-data.h>
#include <src/core/frame-processor-callback.h>


namespace librealsense
Expand Down Expand Up @@ -141,7 +142,7 @@ namespace librealsense
void motion_to_accel_gyro::configure_processing_callback()
{
// define and set the frame processing callback
auto process_callback = [&](frame_holder frame, synthetic_source_interface* source)
auto process_callback = [&](frame_holder && frame, synthetic_source_interface* source)
{
auto profile = As<motion_stream_profile, stream_profile_interface>(frame.frame->get_stream());
if (!profile)
Expand Down Expand Up @@ -187,8 +188,7 @@ namespace librealsense
source->frame_ready(std::move(agf));
};

set_processing_callback(std::shared_ptr<rs2_frame_processor_callback>(
new internal_frame_processor_callback<decltype(process_callback)>(process_callback)));
set_processing_callback( make_frame_processor_callback( std::move( process_callback ) ) );
}

void motion_to_accel_gyro::process_function( uint8_t * const dest[], const uint8_t * source, int width, int height, int output_size, int actual_size)
Expand Down
6 changes: 3 additions & 3 deletions src/proc/syncer-processing-block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "sync.h"
#include "proc/synthetic-stream.h"
#include "proc/syncer-processing-block.h"
#include <src/core/frame-processor-callback.h>


namespace librealsense
Expand All @@ -29,7 +30,7 @@ namespace librealsense
// call the matchers with the frame and eventually call the next callback in the list using frame_ready().
// This callback can get called from multiple threads, one thread per stream -- but always in the correct
// frame order per stream.
auto f = [&, log](frame_holder frame, synthetic_source_interface* source)
auto f = [&, log](frame_holder && frame, synthetic_source_interface* source)
{
// if the syncer is disabled passthrough the frame
bool enabled = false;
Expand Down Expand Up @@ -80,8 +81,7 @@ namespace librealsense

};

set_processing_callback(std::shared_ptr<rs2_frame_processor_callback>(
new internal_frame_processor_callback<decltype(f)>(f)));
set_processing_callback( make_frame_processor_callback( std::move( f ) ) );
}

// Stopping the syncer means no more frames will be enqueued, and any existing frames
Expand Down
14 changes: 10 additions & 4 deletions src/proc/synthetic-stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "core/depth-frame.h"
#include <src/composite-frame.h>
#include <src/core/frame-callback.h>
#include <src/core/frame-processor-callback.h>
#include "option.h"
#include "stream.h"
#include "types.h"
Expand Down Expand Up @@ -46,7 +47,7 @@ namespace librealsense
frame_interface* ptr = nullptr;
std::swap(f.frame, ptr);

_callback->on_frame((rs2_frame*)ptr, _source_wrapper.get_c_wrapper());
_callback->on_frame( (rs2_frame *)ptr, _source_wrapper.get_rs2_source() );
}
}
catch (std::exception const & e)
Expand Down Expand Up @@ -326,6 +327,12 @@ namespace librealsense
return _stream_filter.match(frame);
}

synthetic_source::synthetic_source( frame_source & actual )
: _actual_source( actual )
, _c_wrapper( new rs2_source{ this } )
{
}

void synthetic_source::frame_ready(frame_holder result)
{
_actual_source.invoke_callback(std::move(result));
Expand Down Expand Up @@ -601,7 +608,7 @@ namespace librealsense
void interleaved_functional_processing_block::configure_processing_callback()
{
// define and set the frame processing callback
auto process_callback = [&](frame_holder frame, synthetic_source_interface* source)
auto process_callback = [&](frame_holder && frame, synthetic_source_interface* source)
{
auto profile = As<video_stream_profile, stream_profile_interface>(frame.frame->get_stream());
if (!profile)
Expand Down Expand Up @@ -658,7 +665,6 @@ namespace librealsense
source->frame_ready(std::move(rf));
};

set_processing_callback(std::shared_ptr<rs2_frame_processor_callback>(
new internal_frame_processor_callback<decltype(process_callback)>(process_callback)));
set_processing_callback( make_frame_processor_callback( std::move( process_callback ) ) );
}
}
18 changes: 11 additions & 7 deletions src/proc/synthetic-stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,26 @@

#pragma once

#include "../core/processing.h"
#include <src/core/synthetic-source-interface.h>
#include "../core/processing-block-interface.h"
#include "../image.h"
#include "../source.h"

#include <src/core/info.h>
#include <src/core/options-container.h>

#include <librealsense2/hpp/rs_frame.hpp>
#include <librealsense2/hpp/rs_processing.hpp>

namespace librealsense
{


// A synthetic source is simply a wrapper around a new frame_source and its exposure thru the rs2_source APIs
//
class synthetic_source : public synthetic_source_interface
{
public:
synthetic_source(frame_source& actual)
: _actual_source(actual), _c_wrapper(new rs2_source{ this })
{
}
synthetic_source( frame_source & actual );

frame_interface* allocate_video_frame(std::shared_ptr<stream_profile_interface> stream,
frame_interface* original,
Expand All @@ -39,7 +43,7 @@ namespace librealsense

void frame_ready(frame_holder result) override;

rs2_source* get_c_wrapper() override { return _c_wrapper.get(); }
rs2_source* get_rs2_source() const { return _c_wrapper.get(); }

private:
frame_source & _actual_source;
Expand Down
1 change: 0 additions & 1 deletion src/rs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "core/motion-frame.h"
#include "core/disparity-frame.h"
#include "source.h"
#include "core/processing.h"
#include "proc/synthetic-stream.h"
#include "proc/processing-blocks-factory.h"
#include "proc/colorizer.h"
Expand Down
2 changes: 1 addition & 1 deletion src/sync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "sync.h"
#include "core/frame-holder.h"
#include "core/processing.h"
#include "core/synthetic-source-interface.h"
#include "core/stream-profile-interface.h"
#include "core/device-interface.h"
#include "core/sensor-interface.h"
Expand Down