# Device Nodes

Nodes are the building blocks when populating the
[Pipeline](https://docs.luxonis.com/software-v3/depthai/depthai-components/pipeline.md). Each node provides a specific
functionality on the DepthAI, a set of configurable properties and inputs/outputs. After you create a node on a pipeline, you can
also configure it as desired and link it to other nodes.

A device node is a special type of node, which is run on device SoC (RVC) utilizing the resources of the device. Device nodes are
used to offload the host from processing tasks that can be done on the device itself. Alternatively, [host
nodes](https://docs.luxonis.com/software-v3/depthai/depthai-components/host_nodes.md) can be used to perform computation on the
host (PC).

On the table of contents (left side of the page) all nodes are listed under the Node entry. You can click on them to find out
more.

## Inputs and outputs

Each node can have zero, one or multiple inputs and outputs. For example, SystemLogger node has no inputs and 1 output and
EdgeDetector has 2 inputs and 1 output (as shown below). Script node can have any number of inputs/ouputs.

Each node's output has its pool; block in RAM where it stores messages. Each node's input has its queue for message pointers
(doesn't store the message itself, just a pointer to it).

### Node input

Node input queue is a queue for Messages. It can be linked with other node's output (that's how you link up nodes). Node inputs
are configurable - with input.setBlocking(bool) and input.setQueueSize(num), eg. edgeDetector.inputImage.setQueueSize(10). If the
input queue fills up, behavior of the input depends on blocking attribute.

Let's say we have linked ColorCamera preview output with NeuralNetwork input input.

If input is set to blocking mode, and input queue fills up, no new messages from ColorCamera will be able to enter the input
queue. This means ColorCamera will block and wait with sending its messages until it can push the message to the queue of
NeuralNetwork input. If ColorCamera preview is connected to multiple inputs, the same behavior implies, with the messages being
pushed sequentially to each input.

If blocking is disabled, new messages will push out old messages. This eliminates the risk of pipeline freezing, but can result in
dropped messages (eg. ImgFrame).

### Node output

Node outputs Messages. Some nodes have a configurable output message pool. Output message pool is a reserved memory region (to
reduce memory fragmentation) that holds output messages. After the node creates an output message (for example ImgFrame), it will
send it to other nodes as specified when linking the inputs/outputs of the node. Currently, some nodes (VideoEncoder,
NeuralNetwork, ImageManip, XLinkIn) can have the pool size configured. The size of the pool specifies how many messages can be
created and sent out while other messages are already somewhere in the pipeline.

> **Pipeline freezing**
> When all the messages from pool are sent out and none yet returned, that's when the node will block (freeze) and wait until a
message is released (not used by any node in the pipeline).

### dai::Node

Kind: class

Abstract Node .

#### dai::Node::Connection

Kind: struct

Connection between an Input and Output .

##### Id outputId

Kind: variable

##### std::string outputName

Kind: variable

##### std::string outputGroup

Kind: variable

##### Id inputId

Kind: variable

##### std::string inputName

Kind: variable

##### std::string inputGroup

Kind: variable

##### Connection(Output out, Input in)

Kind: function

##### Connection(ConnectionInternal c)

Kind: function

##### bool operator==(const Connection & rhs)

Kind: function

#### dai::Node::ConnectionInternal

Kind: struct

Connection between an Input and Output internal.

##### dai::Node::ConnectionInternal::Hash

Kind: struct

###### size_t operator()(const dai::Node::ConnectionInternal & obj)

Kind: function

##### std::weak_ptr< Node > outputNode

Kind: variable

##### std::string outputName

Kind: variable

##### std::string outputGroup

Kind: variable

##### std::weak_ptr< Node > inputNode

Kind: variable

##### std::string inputName

Kind: variable

##### std::string inputGroup

Kind: variable

##### Output * out

Kind: variable

##### Input * in

Kind: variable

##### ConnectionInternal(Output & out, Input & in)

Kind: function

##### bool operator==(const ConnectionInternal & rhs)

Kind: function

#### dai::Node::DatatypeHierarchy

Kind: struct

##### DatatypeEnum datatype

Kind: variable

##### bool descendants

Kind: variable

##### DatatypeHierarchy(DatatypeEnum d, bool c)

Kind: function

#### dai::Node::Input

Kind: class

##### Type

Kind: enum

###### SReceiver

Kind: enum_value

###### MReceiver

Kind: enum_value

##### std::vector< DatatypeHierarchy > possibleDatatypes

Kind: variable

##### ~Input()

Kind: function

##### Input(Node & par, InputDescription desc, bool ref)

Kind: function

##### const Node & getParent()

Kind: function

Get the parent node

##### Node & getParent()

Kind: function

Get the parent node

##### Type getType()

Kind: function

Get type

##### std::string toString()

Kind: function

Input to string representation

##### void setWaitForMessage(bool waitForMessage)

Kind: function

Overrides default wait for message behavior. Applicable for nodes with multiple inputs. Specifies behavior whether to wait for
this input when a Node processes certain data or not. parameters: waitForMessage: Whether to wait for message to arrive to this
input or not

##### bool getWaitForMessage()

Kind: function

Get behavior whether to wait for this input when a Node processes certain data or not return: Whether to wait for message to
arrive to this input or not

##### std::vector< DatatypeHierarchy > getPossibleDatatypes()

Kind: function

Get possible datatypes that can be received

##### void setPossibleDatatypes(std::vector< DatatypeHierarchy > types)

Kind: function

Set possible datatypes that can be received

##### void setReusePreviousMessage(bool reusePreviousMessage)

Kind: function

Equivalent to setWaitForMessage but with inverted logic.

##### bool getReusePreviousMessage()

Kind: function

Equivalent to getWaitForMessage but with inverted logic.

##### void setGroup(std::string group)

Kind: function

Set group name for this input

##### std::string getGroup()

Kind: function

Get group name for this input

##### bool isConnected()

Kind: function

Check if this input is connected

##### std::shared_ptr< InputQueue > createInputQueue(unsigned int maxSize, bool blocking)

Kind: function

Create an shared pointer to an input queue that can be used to send messages to this input from onhost.

parameters: maxSize: Maximum size of the input queue; blocking: Whether the input queue should block when full return:
std::shared_ptr<InputQueue>: shared pointer to an input queue

##### std::shared_ptr< dai::node::internal::XLinkInBridge > getXLinkBridge()

Kind: function

Get XLink bridge associated with this input (only valid for device inputs after pipeline build)

return: std::shared_ptr<dai::node::internal::XLinkInBridge>: pointer to the XLink bridge or nullptr if not applicable

#### dai::Node::InputDescription

Kind: struct

##### std::string name

Kind: variable

##### std::string group

Kind: variable

##### bool blocking

Kind: variable

##### int queueSize

Kind: variable

##### std::vector< DatatypeHierarchy > types DEFAULT_TYPES

Kind: variable

##### bool waitForMessage

Kind: variable

#### dai::Node::InputMap

Kind: class

Input map which keeps track of inputs assigned to a node Extends std::unordered_map<std::string, dai::Node::Input>

##### std::string name

Kind: variable

##### InputMap(Node & parent, InputDescription defaultInput)

Kind: function

##### InputMap(Node & parent, std::string name, InputDescription defaultInput)

Kind: function

##### Input & operator[](const std::string & key)

Kind: function

Create or modify an input.

##### Input & operator[](std::pair< std::string, std::string > groupKey)

Kind: function

Create or modify an input with specified group.

##### bool has(const std::string & key)

Kind: function

#### dai::Node::Output

Kind: class

##### dai::Node::Output::QueueConnection

Kind: struct

###### Output * output

Kind: variable

###### std::shared_ptr< MessageQueue > queue

Kind: variable

###### bool operator==(const QueueConnection & rhs)

Kind: function

##### Type

Kind: enum

###### MSender

Kind: enum_value

###### SSender

Kind: enum_value

##### ~Output()

Kind: function

##### Output(Node & par, OutputDescription desc, bool ref)

Kind: function

##### Node & getParent()

Kind: function

##### const Node & getParent()

Kind: function

##### std::string toString()

Kind: function

Output to string representation.

##### std::string getName()

Kind: function

Get name of the output

##### std::string getGroup()

Kind: function

Get group of the output

##### void setGroup(std::string group)

Kind: function

Set group name for this output

##### void setName(std::string name)

Kind: function

Set name for this output

##### Type getType()

Kind: function

Get type of the output

##### std::vector< DatatypeHierarchy > getPossibleDatatypes()

Kind: function

Get possible datatypes that can be sent

##### void setPossibleDatatypes(std::vector< DatatypeHierarchy > types)

Kind: function

Set possible datatypes that can be sent

##### bool isSamePipeline(const Input & in)

Kind: function

Check if this output and given input are on the same pipeline. see: canConnect for checking if connection is possible return: True
if output and input are on the same pipeline

##### bool canConnect(const Input & in)

Kind: function

Check if connection is possible parameters: in: Input to connect to return: True if connection is possible, false otherwise

##### std::vector< ConnectionInternal > getConnections()

Kind: function

Retrieve all connections from this output return: Vector of connections

##### std::vector< QueueConnection > getQueueConnections()

Kind: function

Retrieve all queue connections from this output return: Vector of queue connections

##### std::shared_ptr< dai::MessageQueue > createOutputQueue(unsigned int maxSize, bool blocking)

Kind: function

Construct and return a shared pointer to an output message queue.

parameters: maxSize: Maximum size of the output queue; blocking: Whether the output queue should block when full return:
std::shared_ptr<dai::MessageQueue>: shared pointer to an output queue

##### void link(Input & in)

Kind: function

Link current output to input. Throws an error if this output cannot be linked to given input, or if they are already linked
parameters: in: Input to link to

##### void link(std::shared_ptr< Node > in)

Kind: function

##### void unlink(Input & in)

Kind: function

Unlink a previously linked connection Throws an error if not linked. parameters: in: Input from which to unlink from

##### void send(const std::shared_ptr< ADatatype > & msg)

Kind: function

Sends a Message to all connected inputs parameters: msg: Message to send to all connected inputs

##### bool trySend(const std::shared_ptr< ADatatype > & msg)

Kind: function

Try sending a message to all connected inputs parameters: msg: Message to send to all connected inputs return: True if ALL
connected inputs got the message, false otherwise

##### std::shared_ptr< dai::node::internal::XLinkOutBridge > getXLinkBridge()

Kind: function

Get XLink bridge associated with this output (only valid for device outputs after pipeline build)

return: std::shared_ptr<dai::node::internal::XLinkOutBridge>: pointer to the XLink bridge or nullptr if not applicable

#### dai::Node::OutputDescription

Kind: struct

##### std::string name

Kind: variable

##### std::string group

Kind: variable

##### std::vector< DatatypeHierarchy > types DEFAULT_TYPES

Kind: variable

#### dai::Node::OutputMap

Kind: class

Output map which keeps track of extra outputs assigned to a node Extends std::unordered_map<std::string, dai::Node::Output>

##### std::string name

Kind: variable

##### OutputMap(Node & parent, std::string name, OutputDescription defaultOutput, bool ref)

Kind: function

##### OutputMap(Node & parent, OutputDescription defaultOutput, bool ref)

Kind: function

##### Output & operator[](const std::string & key)

Kind: function

Create or modify an output.

##### Output & operator[](std::pair< std::string, std::string > groupKey)

Kind: function

Create or modify an output with specified group.

#### dai::Node::PairHash

Kind: struct

##### std::size_t operator()(const std::pair< T1, T2 > & pair)

Kind: function

#### std::int64_t Id

Kind: enum

Node identificator. Unique for every node on a single Pipeline .

#### Id id

Kind: variable

Id of node. Assigned after being placed on the pipeline.

#### Id inputId

Kind: variable

#### Id outputId

Kind: variable

#### std::string alias

Kind: variable

alias or name

#### Node(const Node &)

Kind: function

#### Node & operator=(const Node &)

Kind: function

#### Node(Node &&)

Kind: function

#### Node & operator=(Node &&)

Kind: function

#### std::string createUniqueInputName()

Kind: function

#### std::string createUniqueOutputName()

Kind: function

#### Pipeline getParentPipeline()

Kind: function

#### const Pipeline getParentPipeline()

Kind: function

#### std::string getAlias()

Kind: function

Get alias.

#### void setAlias(std::string alias)

Kind: function

Set alias.

#### const char * getName()

Kind: function

Retrieves nodes name.

#### void start()

Kind: function

Start node execution.

#### void wait()

Kind: function

Wait for node to finish execution.

#### void stop()

Kind: function

Stop node execution.

#### void stopPipeline()

Kind: function

#### void buildStage1()

Kind: function

Build stages;.

#### void buildStage2()

Kind: function

#### void buildStage3()

Kind: function

#### void postBuildStage()

Kind: function

#### std::vector< Output > getOutputs()

Kind: function

Retrieves all nodes outputs.

#### std::vector< Input > getInputs()

Kind: function

Retrieves all nodes inputs.

#### std::vector< Output * > getOutputRefs()

Kind: function

Retrieves reference to node outputs.

#### std::vector< const Output * > getOutputRefs()

Kind: function

Retrieves reference to node outputs.

#### std::vector< Input * > getInputRefs()

Kind: function

Retrieves reference to node inputs.

#### std::vector< const Input * > getInputRefs()

Kind: function

Retrieves reference to node inputs.

#### std::vector< OutputMap * > getOutputMapRefs()

Kind: function

Retrieves reference to node outputs.

#### std::vector< InputMap * > getInputMapRefs()

Kind: function

Retrieves reference to node inputs.

#### Output * getOutputRef(std::string name)

Kind: function

Retrieves reference to specific output.

#### Output * getOutputRef(std::string group, std::string name)

Kind: function

#### Input * getInputRef(std::string name)

Kind: function

Retrieves reference to specific input.

#### Input * getInputRef(std::string group, std::string name)

Kind: function

#### OutputMap * getOutputMapRef(std::string group)

Kind: function

Retrieves reference to specific output map.

#### InputMap * getInputMapRef(std::string group)

Kind: function

Retrieves reference to specific input map.

#### bool isSourceNode()

Kind: function

#### ~Node()

Kind: function

#### const AssetManager & getAssetManager()

Kind: function

Get node AssetManager as a const reference.

#### AssetManager & getAssetManager()

Kind: function

Get node AssetManager as a reference.

#### std::vector< uint8_t > loadResource(std::filesystem::path uri)

Kind: function

Loads resource specified by URI and returns its data.

#### std::vector< uint8_t > moveResource(std::filesystem::path uri)

Kind: function

Moves the resource out.

#### std::shared_ptr< N > create()

Kind: function

Create and place Node to this Node .

#### void add(std::shared_ptr< Node > node)

Kind: function

Add existing node to nodeMap.

#### std::vector< std::shared_ptr< Node > > getAllNodes()

Kind: function

#### std::shared_ptr< const Node > getNode(Node::Id id)

Kind: function

#### std::shared_ptr< Node > getNode(Node::Id id)

Kind: function

#### void remove(std::shared_ptr< Node > node)

Kind: function

#### ConnectionMap getConnectionMap()

Kind: function

#### void link(const Node::Output & out, const Node::Input & in)

Kind: function

#### void unlink(const Node::Output & out, const Node::Input & in)

Kind: function

#### void link(std::shared_ptr< Node > in)

Kind: function

Get a reference to internal node map.

#### Node::Output * requestOutput(const Capability & capability, bool onHost)

Kind: function

#### std::vector< std::pair< Input &, std::shared_ptr< Capability > > > getRequiredInputs()

Kind: function

#### bool runOnHost()

Kind: function

Returns true or false whether the node should be run on host or not.

#### const NodeMap & getNodeMap()

Kind: function

#### void buildInternal()

Kind: function

Function called from within the
