# MessageDemux

The MessageDemux (Demultiplexer) node is used to separate a
[MessageGroup](https://docs.luxonis.com/software-v3/depthai/depthai-components/messages/message_group.md) into individual outputs.
It currently serves as way to demultiplex the output of
[Sync](https://docs.luxonis.com/software-v3/depthai/depthai-components/nodes/sync.md) node.

## How to Place It

#### Python

```python
pipeline = dai.Pipeline()
demux = pipeline.create(dai.node.MessageDemux)
```

#### C++

```cpp
dai::Pipeline pipeline;
auto demux = pipeline.create<dai::node::MessageDemux>();
```

## Inputs and Outputs

## Usage

The MessageDemux node is particularly useful for handling different types of data coming from a single source. For example, when
the [Sync](https://docs.luxonis.com/software-v3/depthai/depthai-components/nodes/sync.md) node is used to synchronize the outputs
of multiple nodes, the output of the Sync node is a
[MessageGroup](https://docs.luxonis.com/software-v3/depthai/depthai-components/messages/message_group.md) containing all the
messages from the synchronized nodes. The Demux node can be used to separate the messages into individual streams.

#### Python

```python
# Create sync node and set sync threshold
sync = pipeline.create(dai.node.Sync)
sync.setSyncThresholdMs(timedelta(milliseconds=100))

# Create demux node
demux = pipeline.create(dai.node.MessageDemux)

# Sync the outputs of multiple nodes
rgb.preview.link(sync.inputs["rgb"])
stereo.depth.link(sync.inputs["depth"])
script.outputs["out"].link(sync.inputs["script"])

sync.out.link(demux.input) # Sync output is a MessageGroup containing all the messages from the synchronized nodes

# Demux the MessageGroup into individual messages
demux.outputs["rgb"].link(xout1.input)
demux.outputs["depth"].link(xout2.input)
demux.outputs["script"].link(xout3.input)
```

#### C++

```cpp
// Create sync node and set sync threshold
auto sync = pipeline.create<dai::node::Sync>();
sync->setSyncThreshold(std::chrono::milliseconds(100));

// Create demux node
auto demux = pipeline.create<dai::node::MessageDemux>();

// Sync the outputs of multiple nodes
rgb.preview.link(sync->input["rgb"]);
stereo.depth.link(sync->input["depth"]);
script.outputs["out"].link(sync->input["script"]);

sync->out.link(demux->input); // Sync output is a MessageGroup containing all the messages from the synchronized nodes

// Demux the MessageGroup into individual messages
demux->outputs["rgb"].link(xout1.input);
demux->outputs["depth"].link(xout2.input);
demux->outputs["script"].link(xout3.input);
```

## Examples of Functionality

 * [Demuxing Synchronized Script
   Outputs](https://docs.luxonis.com/software-v3/depthai/depthai-components/messages/image_manip_config.md)

## Reference

### dai::node::MessageDemux

Kind: class

#### Input input

Kind: variable

Input message of type MessageGroup

#### OutputMap outputs

Kind: variable

A map of outputs, where keys are same as in the input MessageGroup

#### void setRunOnHost(bool runOnHost)

Kind: function

Specify whether to run on host or device By default, the node will run on device.

#### bool runOnHost()

Kind: function

Check if the node is set to run on host

#### void run()

Kind: function

#### void setProcessor(ProcessorType type)

Kind: function

Specify on which processor the node should run. RVC2 only. parameters: type: Processor type - Leon CSS or Leon MSS

#### ProcessorType getProcessor()

Kind: function

Get on which processor the node should run return: Processor type - Leon CSS or Leon MSS

#### DeviceNodeCRTP()

Kind: function

#### DeviceNodeCRTP(const std::shared_ptr< Device > & device)

Kind: function

#### DeviceNodeCRTP(std::unique_ptr< Properties > props)

Kind: function

#### DeviceNodeCRTP(std::unique_ptr< Properties > props, bool confMode)

Kind: function

#### DeviceNodeCRTP(const std::shared_ptr< Device > & device, std::unique_ptr< Properties > props, bool confMode)

Kind: function

### Need assistance?

Head over to [Discussion Forum](https://discuss.luxonis.com/) for technical support or any other questions you might have.
