# XLink Bridge

This example shows how to access the implicit XLink bridge created when a stream crosses the host-device boundary and adjust
transport settings such as FPS limit.

## Setup

This example requires the DepthAI v3 API, see [installation instructions](https://docs.luxonis.com/software-v3/depthai.md).

## Source code

#### Python

```python
#!/usr/bin/env python3

import argparse
import cv2
import depthai as dai

parser = argparse.ArgumentParser()
parser.add_argument(
    "--fps_limit", type=float, default=3.0, help="Limit output FPS (float, optional)"
)
args = parser.parse_args()

# Create pipeline
with dai.Pipeline() as pipeline:
    # Define source and output
    cam = pipeline.create(dai.node.Camera).build()
    videoOutput = cam.requestOutput((640, 400), fps=30)
    videoQueue = videoOutput.createOutputQueue()

    pipeline.build()

    # Optionally update internal settings
    # Note: xlink bridges are only generated after pipeline.build() is called
    xlinkBridge = videoOutput.getXLinkBridge()
    assert xlinkBridge is not None
    assert isinstance(xlinkBridge, dai.node.internal.XLinkOutBridge)
    xlinkBridge.xLinkOut.setFpsLimit(args.fps_limit)

    # Connect to device and start pipeline
    pipeline.start()
    while pipeline.isRunning():
        videoIn = videoQueue.get()
        assert isinstance(videoIn, dai.ImgFrame)
        cv2.imshow("video", videoIn.getCvFrame())

        if cv2.waitKey(1) == ord("q"):
            break
```

#### C++

```cpp
#include <cassert>
#include <memory>
#include <opencv2/opencv.hpp>

#include "depthai/depthai.hpp"

int main() {
    // Create device
    std::shared_ptr<dai::Device> device = std::make_shared<dai::Device>();

    // Create pipeline
    dai::Pipeline pipeline(device);

    // Create nodes
    auto cam = pipeline.create<dai::node::Camera>()->build();
    auto videoOutput = cam->requestOutput(std::make_pair(640, 400));
    auto videoQueue = videoOutput->createOutputQueue();

    pipeline.build();

    // Optionally update internal settings
    // Note: xlink bridges are only generated after pipeline.build() is called
    auto xlinkBridge = videoOutput->getXLinkBridge();
    assert(xlinkBridge != nullptr);
    assert(xlinkBridge->xLinkOut != nullptr);
    xlinkBridge->xLinkOut->setFpsLimit(3.0);

    // Start pipeline
    pipeline.start();

    while(true) {
        auto videoIn = videoQueue->get<dai::ImgFrame>();
        if(videoIn == nullptr) continue;

        cv::imshow("video", videoIn->getCvFrame());

        if(cv::waitKey(1) == 'q') {
            break;
        }
    }

    return 0;
}
```

### Need assistance?

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