Skip to main content

Session Class

The assembly stage — turns a list of Nodes into a runnable, deterministic pipeline. More...

Declaration

class simaai::neat::Session { ... }

Included Headers

#include <Session.h>

Public Member Typedefs Index

usingTensorCallback = std::function< bool(const simaai::neat::Tensor &)>

Callback signature used by source-mode pipelines (no input pushed; pipeline produces tensors continuously). More...

Friends Index

structsimaai::neat::internal::ModelAccess

Public Constructors Index

Session (const SessionOptions &opt={})

Construct an empty Session with the given options (or defaults). More...

Session (const Session &)=delete

Non-copyable. More...

Session (Session &&) noexcept

Move-constructible. More...

Public Destructor Index

~Session ()

Destroy the Session, stopping any running pipeline. More...

Public Operators Index

Session &operator= (const Session &)=delete

Non-copyable. More...

Session &operator= (Session &&) noexcept

Move-assignable. More...

Public Member Functions Index

Session &add (std::shared_ptr< Node > node)

Append a single Node to the Session. More...

Session &add (const NodeGroup &group)

Append a NodeGroup (a bundle of Nodes) by copy. More...

Session &add (NodeGroup &&group)

Append a NodeGroup by move (avoids copying internal Node vector). More...

Session &custom (std::string fragment)

Splice a raw GStreamer launch fragment into the pipeline. More...

Session &custom (std::string fragment, InputRole role)

Variant that declares the fragment's role (e.g., source vs. sink). More...

voidrun ()

Run a source-mode pipeline (no inputs pushed; producer Nodes drive the flow). More...

TensorListrun (const std::vector< cv::Mat > &inputs, const RunOptions &opt={})

One-shot synchronous push+pull from cv::Mat inputs. More...

TensorListrun (const TensorList &inputs, const RunOptions &opt={})

One-shot synchronous push+pull from Tensor inputs. More...

SampleListrun (const SampleList &inputs, const RunOptions &opt={})

One-shot synchronous push+pull from Sample inputs (carries per-buffer metadata). More...

Runbuild (const std::vector< cv::Mat > &inputs, RunMode mode=RunMode::Async, const RunOptions &opt={})

Build a long-lived Run handle, seeding caps from cv::Mat inputs. More...

Runbuild (const TensorList &inputs, RunMode mode=RunMode::Async, const RunOptions &opt={})

Build variant seeded with Tensor inputs. More...

Runbuild (const SampleList &inputs, RunMode mode=RunMode::Async, const RunOptions &opt={})

Build variant seeded with full Sample inputs (with per-buffer metadata). More...

SessionReportvalidate (const ValidateOptions &opt, const cv::Mat &input) const

Validate the Session against a real input sample without running the pipeline. More...

RtspServerHandlerun_rtsp (const RtspServerOptions &opt)

Build the Session and run it as an RTSP server. More...

SessionReportvalidate (const ValidateOptions &opt={}) const

Validate the Session structurally without running. More...

Session &add_output_tensor (const OutputTensorOptions &opt={})

Append a tensor-friendly output (auto-inserts convert/scale/caps + sink). More...

std::stringdescribe (const GraphPrinter::Options &opt={}) const

Returns a hierarchical, human-readable view of the Nodes added so far. More...

std::stringdescribe_backend (bool insert_boundaries=false) const

Returns the GStreamer launch string the Session would emit at build(). More...

voidset_guard (std::shared_ptr< void > guard)

Attach an external lifetime guard (used by externally-managed runtimes). More...

voidset_tensor_callback (TensorCallback cb)

Set the per-tensor callback used by source-mode run(). More...

voidsave (const std::string &path) const

Save the Session's Node list, options, and topology to a JSON file at path. More...

Runbuild (const RunOptions &opt={})

Build a Session as an asynchronous runner without seeding inputs. More...

const std::string &last_pipeline () const

Returns the GStreamer launch string from the most recent build() call. More...

Private Member Functions Index

voidbuild_cached_source ()

Private Member Attributes Index

std::vector< std::shared_ptr< Node > >nodes_
std::vector< GroupMeta >groups_
std::stringlast_pipeline_
std::shared_ptr< void >guard_
std::shared_ptr< void >verbose_guard_
SessionOptionsopt_ {}
TensorCallbacktensor_cb_
std::atomic< uint64_t >nodes_version_ {0}
std::unique_ptr< BuiltState >built_
std::unique_ptr< RunCache >run_cache_
uint64_tbuilt_version_ = 0
std::shared_ptr< const pipeline_internal::InputRouteProcessor >input_route_processor_

Public Static Functions Index

static Sessionload (const std::string &path)

Reconstruct a Session from a previously-saved JSON file. More...

Description

The assembly stage — turns a list of Nodes into a runnable, deterministic pipeline.

A Session does five jobs when you call build():

  1. Composition — collects Nodes and NodeGroups in the order you added them.
  2. Validation — runs structural contracts (no empty pipeline, no null nodes, sink last, etc.) and surfaces issues as a structured SessionReport.
  3. Compilation — translates the Node sequence into a deterministic GStreamer pipeline string with stable element names like n3_videoconvert.
  4. Negotiation — hands the pipeline to GStreamer, which negotiates caps between adjacent elements (formats, resolutions, framerates, memory layouts).
  5. Materialization — instantiates the actual GStreamer elements, transitions through NULL → READY → PAUSED state, and returns a Run handle.
 sima::Session sess;
 sess.add(sima::nodes::groups::RtspDecodedInput({.url = "rtsp://camera/stream"}));
 sess.add(model.session());
 sess.add(sima::Output{});
 auto run = sess.build();

Sessions are non-copyable but movable. They are not thread-safe — build a Session on one thread, then hand the resulting Run to wherever it's needed.

See Also

Run for the runtime handle this produces

See Also

Model — the simplified entry point that wraps a Session for users who don't need composition flexibility

See Also

SessionReport for the structured error/diagnostics surface

See Also

RtspServerHandle for server-mode Sessions

Definition at line 140 of file Session.h.

Public Member Typedefs

TensorCallback

using simaai::neat::Session::TensorCallback = std::function<bool(const simaai::neat::Tensor&)>

Callback signature used by source-mode pipelines (no input pushed; pipeline produces tensors continuously).

Definition at line 144 of file Session.h.

144 using TensorCallback = std::function<bool(const simaai::neat::Tensor&)>;

Friends

simaai::neat::internal::ModelAccess

friend struct simaai::neat::internal::ModelAccess

Definition at line 295 of file Session.h.

Public Constructors

Session()

simaai::neat::Session::Session (const SessionOptions & opt={})
explicit

Construct an empty Session with the given options (or defaults).

Definition at line 147 of file Session.h.

Session()

simaai::neat::Session::Session (const Session &)
delete

Non-copyable.

Definition at line 150 of file Session.h.

Session()

simaai::neat::Session::Session (Session &&)
noexcept

Move-constructible.

Definition at line 152 of file Session.h.

Public Destructor

~Session()

simaai::neat::Session::~Session ()

Destroy the Session, stopping any running pipeline.

Definition at line 149 of file Session.h.

Public Operators

operator=()

Session & simaai::neat::Session::operator= (const Session &)
delete

Non-copyable.

Definition at line 151 of file Session.h.

operator=()

Session & simaai::neat::Session::operator= (Session &&)
noexcept

Move-assignable.

Definition at line 153 of file Session.h.

Public Member Functions

add()

Session & simaai::neat::Session::add (std::shared_ptr< Node > node)

Append a single Node to the Session.

Parameters
node

Shared pointer (typically returned by a Node factory like sima::nodes::common::Queue()).

Returns

*this to allow chaining.

Definition at line 162 of file Session.h.

add()

Session & simaai::neat::Session::add (const NodeGroup & group)

Append a NodeGroup (a bundle of Nodes) by copy.

Definition at line 164 of file Session.h.

add()

Session & simaai::neat::Session::add (NodeGroup && group)

Append a NodeGroup by move (avoids copying internal Node vector).

Definition at line 166 of file Session.h.

add_output_tensor()

Session & simaai::neat::Session::add_output_tensor (const OutputTensorOptions & opt={})

Append a tensor-friendly output (auto-inserts convert/scale/caps + sink).

Convenience for "I want my output as a Tensor in a specific format/shape." Equivalent to adding VideoConvert, VideoScale, Caps, and Output Nodes manually but encapsulated.

Returns

*this to allow chaining.

Definition at line 254 of file Session.h.

build()

Run simaai::neat::Session::build (const std::vector< cv::Mat > & inputs, RunMode mode=RunMode::Async, const RunOptions & opt={})

Build a long-lived Run handle, seeding caps from cv::Mat inputs.

Parameters
inputs

One Mat per ingress port; used for build-time adaptation.

mode

Async (default; pipeline runs continuously) or Sync.

opt

Runtime options (queue depth, overflow policy).

Exceptions
<a href="/reference/cppapi/classes/simaai-neat-sessionerror">SessionError</a>

on validation or build failure.

Definition at line 206 of file Session.h.

build()

Run simaai::neat::Session::build (const TensorList & inputs, RunMode mode=RunMode::Async, const RunOptions & opt={})

Build variant seeded with Tensor inputs.

Definition at line 209 of file Session.h.

build()

Run simaai::neat::Session::build (const SampleList & inputs, RunMode mode=RunMode::Async, const RunOptions & opt={})

Build variant seeded with full Sample inputs (with per-buffer metadata).

Definition at line 211 of file Session.h.

build()

Run simaai::neat::Session::build (const RunOptions & opt={})

Build a Session as an asynchronous runner without seeding inputs.

Use this for source pipelines (Sessions whose first Node is a producer like RTSPInput or StillImageInput — no push() from user code needed). Push pipelines should prefer build(inputs, ...) so caps can be derived from the actual input.

Definition at line 287 of file Session.h.

custom()

Session & simaai::neat::Session::custom (std::string fragment)

Splice a raw GStreamer launch fragment into the pipeline.

Useful for one-off experiments, third-party plugins NEAT doesn't wrap, or GStreamer features (tee, selector, dynamic pads) that are awkward to model as Nodes. The trade-off: you lose deterministic naming for the spliced fragment. Use sparingly.

Parameters
fragment

Raw GStreamer launch string (e.g., "identity silent=false ! videocrop ...").

Returns

*this to allow chaining.

Definition at line 179 of file Session.h.

custom()

Session & simaai::neat::Session::custom (std::string fragment, InputRole role)

Variant that declares the fragment's role (e.g., source vs. sink).

Definition at line 181 of file Session.h.

describe()

std::string simaai::neat::Session::describe (const GraphPrinter::Options & opt={})

Returns a hierarchical, human-readable view of the Nodes added so far.

Definition at line 258 of file Session.h.

describe_backend()

std::string simaai::neat::Session::describe_backend (bool insert_boundaries=false)

Returns the GStreamer launch string the Session would emit at build().

Paste into gst-launch-1.0 to reproduce the pipeline outside the framework — invaluable for debugging caps issues or isolating "is this NEAT's bug or GStreamer's?"

Parameters
insert_boundaries

If true, inserts diagnostic identity probes between Nodes.

Definition at line 267 of file Session.h.

last_pipeline()

const std::string & simaai::neat::Session::last_pipeline ()
inline

Returns the GStreamer launch string from the most recent build() call.

Definition at line 290 of file Session.h.

290 const std::string& last_pipeline() const {
291 return last_pipeline_;
292 }

run()

void simaai::neat::Session::run ()

Run a source-mode pipeline (no inputs pushed; producer Nodes drive the flow).

Used in conjunction with set_tensor_callback(). The pipeline runs until end-of-stream or until the callback returns false.

Exceptions
<a href="/reference/cppapi/classes/simaai-neat-sessionerror">SessionError</a>

on validation or runtime failure (with structured SessionReport).

Definition at line 192 of file Session.h.

run()

TensorList simaai::neat::Session::run (const std::vector< cv::Mat > & inputs, const RunOptions & opt={})

One-shot synchronous push+pull from cv::Mat inputs.

Definition at line 194 of file Session.h.

run()

TensorList simaai::neat::Session::run (const TensorList & inputs, const RunOptions & opt={})

One-shot synchronous push+pull from Tensor inputs.

Definition at line 196 of file Session.h.

run()

SampleList simaai::neat::Session::run (const SampleList & inputs, const RunOptions & opt={})

One-shot synchronous push+pull from Sample inputs (carries per-buffer metadata).

Definition at line 198 of file Session.h.

run_rtsp()

RtspServerHandle simaai::neat::Session::run_rtsp (const RtspServerOptions & opt)

Build the Session and run it as an RTSP server.

The Session must terminate in an H.264 encoded stream. The returned handle owns a live RTSP server publishing the pipeline's output to network clients. Stop the server by calling handle.stop() or letting the handle go out of scope.

Parameters
opt

RTSP server options (mount point, port, RTP port range).

Returns

Live RtspServerHandle exposing the broadcast URL.

Definition at line 232 of file Session.h.

save()

void simaai::neat::Session::save (const std::string & path)

Save the Session's Node list, options, and topology to a JSON file at path.

Definition at line 276 of file Session.h.

set_guard()

void simaai::neat::Session::set_guard (std::shared_ptr< void > guard)

Attach an external lifetime guard (used by externally-managed runtimes).

Definition at line 270 of file Session.h.

set_tensor_callback()

void simaai::neat::Session::set_tensor_callback (TensorCallback cb)

Set the per-tensor callback used by source-mode run().

Definition at line 273 of file Session.h.

validate()

SessionReport simaai::neat::Session::validate (const ValidateOptions & opt, const cv::Mat & input)

Validate the Session against a real input sample without running the pipeline.

Runs structural contracts AND build-time adaptation against the input. Reports whether the pipeline would accept this input shape/format and what conversions would be needed. Useful in CI to catch shape mismatches before deploying.

Definition at line 219 of file Session.h.

validate()

SessionReport simaai::neat::Session::validate (const ValidateOptions & opt={})

Validate the Session structurally without running.

Runs all built-in contracts (NonEmptyPipeline, NoNullNodes, SinkLastForRun, etc.) and returns a structured SessionReport. Cheaper than build() because it doesn't instantiate GStreamer state. Useful in unit tests and CI.

Returns

SessionReport carrying any contract failures, with error_code and repro_note.

Definition at line 243 of file Session.h.

Private Member Functions

build_cached_source()

void simaai::neat::Session::build_cached_source ()

Definition at line 341 of file Session.h.

Private Member Attributes

built_

std::unique_ptr<BuiltState> simaai::neat::Session::built_

Definition at line 336 of file Session.h.

336 std::unique_ptr<BuiltState> built_;

built_version_

uint64_t simaai::neat::Session::built_version_ = 0

Definition at line 338 of file Session.h.

338 uint64_t built_version_ = 0;

groups_

std::vector<GroupMeta> simaai::neat::Session::groups_

Definition at line 329 of file Session.h.

329 std::vector<GroupMeta> groups_;

guard_

std::shared_ptr<void> simaai::neat::Session::guard_

Definition at line 331 of file Session.h.

331 std::shared_ptr<void> guard_;

input_route_processor_

std::shared_ptr<const pipeline_internal::InputRouteProcessor> simaai::neat::Session::input_route_processor_

Definition at line 339 of file Session.h.

339 std::shared_ptr<const pipeline_internal::InputRouteProcessor> input_route_processor_;

last_pipeline_

std::string simaai::neat::Session::last_pipeline_

Definition at line 330 of file Session.h.

330 std::string last_pipeline_;

nodes_

std::vector<std::shared_ptr<Node> > simaai::neat::Session::nodes_

Definition at line 328 of file Session.h.

328 std::vector<std::shared_ptr<Node>> nodes_;

nodes_version_

std::atomic<uint64_t> simaai::neat::Session::nodes_version_ {0}

Definition at line 335 of file Session.h.

335 std::atomic<uint64_t> nodes_version_{0};

opt_

SessionOptions simaai::neat::Session::opt_ {}

Definition at line 333 of file Session.h.

333 SessionOptions opt_{};

run_cache_

std::unique_ptr<RunCache> simaai::neat::Session::run_cache_

Definition at line 337 of file Session.h.

337 std::unique_ptr<RunCache> run_cache_;

tensor_cb_

TensorCallback simaai::neat::Session::tensor_cb_

Definition at line 334 of file Session.h.

334 TensorCallback tensor_cb_;

verbose_guard_

std::shared_ptr<void> simaai::neat::Session::verbose_guard_

Definition at line 332 of file Session.h.

332 std::shared_ptr<void> verbose_guard_;

Public Static Functions

load()

Session simaai::neat::Session::load (const std::string & path)
static

Reconstruct a Session from a previously-saved JSON file.

Definition at line 278 of file Session.h.


The documentation for this class was generated from the following file:


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.