# Pipeline

Pipeline is a collection of [Nodes](https://docs.luxonis.com/software-v3/depthai/depthai-components/nodes.md) and links between
them. This flow provides an extensive flexibility that users get for their OAK device.

## Pipeline first steps

To get DepthAI up and running, you have to create a pipeline, populate it with nodes, configure the nodes and link them together.
After that, the pipeline can be loaded onto the
[Device](https://docs.luxonis.com/software-v3/depthai/depthai-components/device.md) and be started.

```python

with dai.Pipeline() as pipeline:

  # Create nodes, configure them and link them together
  ...

  # Upload the pipeline to the device
  pipeline.start()
```

## Using multiple devices

One pipeline can span several devices: add them with `pipeline.addDevice()` and pass the device to `pipeline.create()` for every
node that should run on it. Host nodes see the streams of all devices and links between nodes of different devices are relayed
through the host automatically.

```python
with dai.Pipeline(createImplicitDevice=False) as pipeline:
    deviceA = pipeline.addDevice("192.168.1.11")
    deviceB = pipeline.addDevice("192.168.1.12")
    cameraA = pipeline.create(dai.node.Camera, deviceA).build(dai.CameraBoardSocket.CAM_A)
    cameraB = pipeline.create(dai.node.Camera, deviceB).build(dai.CameraBoardSocket.CAM_A)
```

If a device disconnects, the other devices continue running while DepthAI attempts to reconnect it. Monitor transitions with
`pipeline.setDeviceStateCallback(...)`.

See [Multi-Device Pipelines](https://docs.luxonis.com/software-v3/depthai/depthai-components/multi-device.md) for synchronization,
device loss handling and the common coordinate system, or [Multi-Device
Setup](https://docs.luxonis.com/software-v3/depthai/tutorials/multi-device-setup.md) for a complete example.

## How to place it

#### Python

```python
pipeline = dai.Pipeline() # though we usually prefer to use the context manager (with statement)
```

#### C++

```cpp
dai::Pipeline pipeline;
```

## Reference

### dai::Pipeline

Kind: class

Represents the pipeline, set of nodes and connections between them.

#### PipelineAutoCalibrationMode AutoCalibrationMode

Kind: typedef

#### PipelineImpl::NodeConnectionMap NodeConnectionMap

Kind: typedef

#### PipelineImpl * impl()

Kind: function

#### const PipelineImpl * impl()

Kind: function

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

Kind: function

#### Pipeline(bool createImplicitDevice)

Kind: function

Creates a pipeline parameters: createImplicitDevice: If true, creates a default device (default = true)

#### Pipeline(std::shared_ptr< Device > device)

Kind: function

Creates a pipeline with specified device

#### Pipeline(std::shared_ptr< PipelineImpl > pimpl)

Kind: function

Creates a pipeline with specified device

#### GlobalProperties getGlobalProperties()

Kind: function

return: Global properties of current pipeline

#### void setGlobalProperties(GlobalProperties globalProperties)

Kind: function

Sets global properties of pipeline

#### void setDefaultDeviceProperties(DeviceProperties deviceProperties)

Kind: function

Sets default device properties

#### void setDefaultDevicePropertiesRef(DeviceProperties * deviceProperties)

Kind: function

Sets default device properties reference. The properties should live at least as long as the pipeline.

#### std::optional< DeviceProperties > getDefaultDeviceProperties()

Kind: function

Gets a copy of default device properties. If pipeline is in host only mode, returns host properties, otherwise returns device
properties

#### PipelineSchema getPipelineSchema(SerializationType type, bool includePipelineDebugging)

Kind: function

return: Pipeline schema

#### PipelineSchema getDevicePipelineSchema(SerializationType type, bool includePipelineDebugging)

Kind: function

return: Device pipeline schema (without host only nodes and connections)

#### void serialize(PipelineSchema & schema, Assets & assets, std::vector< std::uint8_t > & assetStorage)

Kind: function

#### nlohmann::json serializeToJson(bool includeAssests)

Kind: function

Returns whole pipeline represented as JSON.

#### std::shared_ptr< N > create(Args &&... args)

Kind: function

Creates and adds a node to the pipeline. Node is specified by template argument N

#### std::enable_if_t< std::is_base_of< DeviceNode , N >::value, std::shared_ptr< N > > create(std::shared_ptr< Device > device, Args &&... args)

Kind: function

Creates a device node on the specified device and adds it to the pipeline. The device becomes part of the pipeline on first use.
Only device nodes can be created this way - creating a host node with a device is a compile-time error.

#### std::enable_if_t< std::is_base_of< DeviceNode , N >::value, std::shared_ptr< N > > createForDevice(std::shared_ptr< Device > device, Args &&... args)

Kind: function

Creates a device node on the specified device and adds it to the pipeline. Same as create(device, ...) - kept as an explicitly
named alternative.

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

Kind: function

Adds an existing node to the pipeline

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

Kind: function

Removes a node from pipeline.

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

Kind: function

Get a vector of all nodes.

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

Kind: function

Get node with id if it exists, nullptr otherwise.

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

Kind: function

Get node with id if it exists, nullptr otherwise.

#### std::vector< Node::Connection > getConnections()

Kind: function

Get all connections.

#### NodeConnectionMap getConnectionMap()

Kind: function

#### const AssetManager & getAssetManager()

Kind: function

Get pipelines AssetManager as reference.

#### AssetManager & getAssetManager()

Kind: function

Get pipelines AssetManager as reference.

#### void setOpenVINOVersion(OpenVINO::Version version)

Kind: function

Set a specific OpenVINO version to use with this pipeline.

#### void setCalibrationData(CalibrationHandler calibrationDataHandler)

Kind: function

Sets the calibration in pipeline which overrides the calibration data in eeprom parameters: calibrationDataHandler:
CalibrationHandler object which is loaded with calibration information.

#### CalibrationHandler getCalibrationData()

Kind: function

gets the calibration data which is set through pipeline return: the calibrationHandler with calib data in the pipeline

#### bool isCalibrationDataAvailable()

Kind: function

check if calib data is available on the device return: true - calib data is available return: false - calib data is not available

#### std::optional< EepromData > getEepromData()

Kind: function

gets the eeprom data from the pipeline return: eepromData from the the pipeline

#### void setEepromData(std::optional< EepromData > eepromData)

Kind: function

Sets the eeprom data in pipeline parameters: eepromData: EepromData object that is loaded in the pipeline.

#### void setMultiDeviceCalibration(std::vector< MultiDeviceExtrinsics > graph)

Kind: function

Sets the cross-device calibration graph shared by all devices in the pipeline. The graph is validated with
beta::MultiDeviceCalibrationHandler . Before the pipeline is built it is only stored and travels to the devices with the pipeline
schema. On a built pipeline it is additionally checked against every assigned device's local calibration and pushed to all
assigned devices at runtime, so already streaming Camera and ToF nodes switch to the new graph. parameters: std::invalid_argument:
when the graph structure is invalid; std::runtime_error: when a device's local calibration does not match the graph or a device
rejects the update; devices updated before the failure are restored to the previous graph and the pipeline keeps the previous
graph parameters: graph: Directed cross-device calibration edges.

#### std::optional< std::vector< MultiDeviceExtrinsics > > getMultiDeviceCalibration()

Kind: function

Gets the cross-device calibration graph from the pipeline return: the graph when one is set, std::nullopt otherwise

#### void clearMultiDeviceCalibration()

Kind: function

Removes any cross-device calibration graph from the pipeline. On a built pipeline the removal is pushed to all assigned devices,
which then publish their local calibration metadata again. parameters: std::runtime_error: when a device rejects the update

#### uint32_t getEepromId()

Kind: function

Gets the eeprom id from the pipeline return: eeprom id from the pipeline

#### void setCameraTuningBlobPath(const fs::path & path)

Kind: function

Set a camera IQ (Image Quality) tuning blob, used for all cameras.

#### void setCameraTuningBlobPath(CameraBoardSocket socket, const fs::path & path)

Kind: function

Set a camera IQ (Image Quality) tuning blob, used for specific board socket.

#### void setXLinkChunkSize(int sizeBytes)

Kind: function

Set chunk size for splitting device-sent XLink packets, in bytes. A larger value could increase performance, with 0 disabling
chunking. A negative value won't modify the device defaults - configured per protocol, currently 64*1024 for both USB and
Ethernet.

#### void setSippBufferSize(int sizeBytes)

Kind: function

SIPP (Signal Image Processing Pipeline ) internal memory pool. SIPP is a framework used to schedule HW filters, e.g. ISP, Warp,
Median filter etc. Changing the size of this pool is meant for advanced use cases, pushing the limits of the HW. By default memory
is allocated in high speed CMX memory. Setting to 0 will allocate in DDR 256 kilobytes. Units are bytes.

#### void setSippDmaBufferSize(int sizeBytes)

Kind: function

SIPP (Signal Image Processing Pipeline ) internal DMA memory pool. SIPP is a framework used to schedule HW filters, e.g. ISP,
Warp, Median filter etc. Changing the size of this pool is meant for advanced use cases, pushing the limits of the HW. Memory is
allocated in high speed CMX memory Units are bytes.

#### void setBoardConfig(BoardConfig board)

Kind: function

Sets board configuration.

#### void setAutoCalibrationMode(AutoCalibrationMode mode)

Kind: function

Sets implicit automatic calibration policy for this pipeline.

#### AutoCalibrationMode getAutoCalibrationMode()

Kind: function

Gets implicit automatic calibration policy for this pipeline.

#### BoardConfig getBoardConfig()

Kind: function

Gets board configuration.

#### Device::Config getDeviceConfig()

Kind: function

Get device configuration needed for this pipeline.

#### bool isRunning()

Kind: function

#### bool isBuilt()

Kind: function

#### void build()

Kind: function

#### void buildDevice()

Kind: function

#### void start()

Kind: function

#### void wait()

Kind: function

#### void stop()

Kind: function

#### void processTasks(bool waitForTasks, double timeoutSeconds)

Kind: function

#### void run()

Kind: function

#### std::shared_ptr< Device > getDefaultDevice()

Kind: function

#### std::shared_ptr< const Device > getDefaultDevice()

Kind: function

#### std::shared_ptr< Device > addDevice(std::shared_ptr< Device > device)

Kind: function

Add a device to the pipeline. The first device added to a pipeline created without an implicit device is promoted to the default
device (master), so nodes created without an explicit device run on it. parameters: device: Already constructed device to add
return: The added device

#### std::shared_ptr< Device > addDevice(const DeviceInfo & deviceInfo)

Kind: function

Construct a device from the given device info and add it to the pipeline. parameters: deviceInfo: Device info to construct the
device from return: The constructed device

#### std::shared_ptr< Device > addDevice(const std::string & idOrIpOrName)

Kind: function

Construct a device from a device id, IP address or name and add it to the pipeline. parameters: idOrIpOrName: Device id, IP
address or name to construct the device from return: The constructed device

#### std::vector< std::shared_ptr< Device > > getDevices()

Kind: function

Get all devices that are part of this pipeline - the default device (master) first, then the rest in registration order. Devices
become part of the pipeline explicitly via addDevice or implicitly on first use by a node.

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

Kind: function

Get the pipeline-level state of a device: RUNNING, DISCONNECTED, RECONNECTING or FAILED. Losing a device does not stop the
pipeline (its streams go idle) unless it was the last device alive or a device consuming other devices' streams. See
setStopOnDeviceLoss to stop on any device loss.

#### void setDeviceStateCallback(std::function< void(std::shared_ptr< Device >, DeviceState)> callback)

Kind: function

Set a callback invoked on every device state transition. The callback is invoked from the affected device's monitor thread; do not
block in it and do not call pipeline stop/start from it directly.

#### void setStopOnDeviceLoss(bool stop)

Kind: function

Stop the pipeline when any device that runs a node is lost for good (strict mode). Off by default (permissive mode): the pipeline
keeps running, the lost device's streams go idle and it stops only when the last device alive or a device consuming other devices'
streams is lost. A device is lost for good when its state becomes FAILED - after the reconnection attempts are exhausted. To stop
as soon as a device disconnects, disable reconnection on the devices (Device::setMaxReconnectionAttempts(0)). Can be changed while
the pipeline runs. parameters: stop: True to stop the pipeline on any device loss

#### bool getStopOnDeviceLoss()

Kind: function

Get whether the pipeline stops when any device that runs a node is lost for good.

#### void setCameraTuningBlobPath(const std::shared_ptr< Device > & device, const fs::path & path)

Kind: function

Set a camera IQ (Image Quality) tuning blob for all cameras of the given pipeline device.

#### void setCameraTuningBlobPath(const std::shared_ptr< Device > & device, CameraBoardSocket socket, const fs::path & path)

Kind: function

Set a camera IQ (Image Quality) tuning blob for a specific board socket of the given pipeline device.

#### void setXLinkChunkSize(const std::shared_ptr< Device > & device, int sizeBytes)

Kind: function

Set chunk size for splitting device-sent XLink packets for the given pipeline device; see the no-device overload.

#### void setSippBufferSize(const std::shared_ptr< Device > & device, int sizeBytes)

Kind: function

Set the SIPP buffer size of the given pipeline device; see the no-device overload.

#### void setSippDmaBufferSize(const std::shared_ptr< Device > & device, int sizeBytes)

Kind: function

Set the SIPP DMA buffer size of the given pipeline device; see the no-device overload.

#### void setBoardConfig(const std::shared_ptr< Device > & device, const BoardConfig & board)

Kind: function

Sets the board configuration for the given pipeline device. Board configuration is applied when a device boots, so for an already
connected device it only takes effect on flows that (re)boot with this pipeline's configuration.

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

Kind: function

Gets the board configuration of the given pipeline device.

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

Kind: function

Get device configuration needed for this pipeline, for the given pipeline device.

#### void setCalibrationData(const std::shared_ptr< Device > & device, const CalibrationHandler & calibrationDataHandler)

Kind: function

Sets the calibration of the given pipeline device, overriding the one in eeprom.

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

Kind: function

Check if calibration data is available on the given pipeline device.

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

Kind: function

Gets the calibration data of the given pipeline device.

#### void setEepromData(const std::shared_ptr< Device > & device, const std::optional< EepromData > & eepromData)

Kind: function

Sets the eeprom data of the given pipeline device.

#### std::optional< EepromData > getEepromData(const std::shared_ptr< Device > & device)

Kind: function

Gets the eeprom data of the given pipeline device.

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

Kind: function

Gets the eeprom id of the given pipeline device.

#### void setDeviceProperties(const std::shared_ptr< Device > & device, const DeviceProperties & deviceProperties)

Kind: function

Sets device properties of the given pipeline device.

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

Kind: function

Gets device properties of the given pipeline device.

#### std::string getTelemetryPipelineId()

Kind: function

#### void addTask(std::function< void()> task)

Kind: function

#### void enableHolisticRecord(const RecordConfig & config)

Kind: function

Record and Replay.

#### void enableHolisticReplay(const std::string & pathToRecording)

Kind: function

#### bool isHolisticRecordEnabled()

Kind: function

#### bool isHolisticReplayEnabled()

Kind: function

#### void enablePipelineDebugging(bool enable)

Kind: function

Pipeline debugging.

#### bool isPipelineDebuggingEnabled()

Kind: function

#### std::shared_ptr< MessageQueue > getPipelineStateOut()

Kind: function

#### std::shared_ptr< InputQueue > getPipelineStateRequest()

Kind: function

#### PipelineStateApi getPipelineState()

Kind: function
