GMSL Camera Video in a Qt Project
General OpenViewLinuxPro (P100) only
A Qt app for the OpenView Pro (P100) that shows a live GMSL camera stream, with a rear-camera style guideline overlay on top.
The app starts on a black screen with two buttons, CAMERA and OVERLAY. CAMERA turns the live stream from the GMSL camera on and off, and OVERLAY draws green guidelines and red trajectory lines over it. The video itself is played by the Video Player Extension; the Qt code only starts and stops it.
Download the example code (qt-gmsl-camera.zip)
Before you start:
- An OpenView Pro (P100) with a GMSL camera on port GMSL0. Video playback isn't supported on OpenViewLinux displays.
- The toolkit set up and signed in, with Podman running — see Quick Start.
- Qt Creator 20 or newer, set up to build in the OpenPV container — see Developing QT Applications with Qt Creator.
Set Up the Project in the Toolkit
-
On the toolbar, click New..., select Ahsoka.QT.Blank (C++, "Blank Starter project for using QT with OpenPV"), and click Next.
Ahsoka.QT.Blank selected in Create New Project -
On Configure Project, click Choose Path... and pick where to create the project — here, C:\Projects\OpenPV\Demo. To give the folder its own name, untick Match Names and type it in Folder Name — here, Ahsoka.QT.Video.Pro. Set Selected Platform to Ahsoka.QT.Blank.Pro, the platform for the P100, and click Create.
Note: Project Name always matches the template, so the project itself stays Ahsoka.QT.Blank — only its folder takes the new name.
Configure Project, with the folder name and the Pro platform set -
If SDK Update Needed appears, click Yes, so the project builds against the current SDK. A Project Created message confirms the folder, here C:\Projects\OpenPV\Demo\Ahsoka.QT.Video.Pro — click Ok.
SDK Update Needed -
On the Packaging tab, set Target Platform to OpenViewLinuxPro (P100) — it starts out as OpenViewLinuxPro (Flex). Optionally, describe the package in Package Description — here, QT Blank starter project with the Video Player extension, showing a GMSL camera stream.
The Packaging tab, with the description and the P100 target platform -
On the Build tab, check these three settings — the template already sets them:
- Application Type: Cpp
- Service Manager: Native
- Development Tool: QT
The Build tab, with the three settings numbered -
On the Display tab (Screen 0, 1280 × 800), click Add Surface twice, and set up the two new surfaces under Layer Manager Surface Configuration. Surfaces 999 (startup logo), 1000 (installer) and 2000 (QTApp, the app's own window) are already there.
Surface ID Layer App Id X Y W H Used for 2001 Main GMSL_Camera1 0 0 1280 720 The camera stream 2002 Overlay cameraOverlay 0 0 1280 720 The guideline overlay Then click Save.... The next step's Rendering Surface list only shows the new surfaces once the project is saved.
Surfaces 2001 and 2002 set up on the Display tab -
On the Extensions tab, click Add an Extension..., select Video Player Extension, and click Install Extension.
Video Player Extension selected in Available Extensions -
Select the installed Video Player Extension, and click Configure Extension....
The Configure Extension button -
Video Players opens with one player already listed. Set it up as below, then close the window with its X. If GMSL_Camera1 isn't in the Rendering Surface list, save the project and try again.
- Input Type: GMSL
- Player Name: GMSL camera
- Camera Port: GMSL0
- Rendering Surface: 2001 - GMSL_Camera1, the camera surface from the Display tab
Advanced Options has more player settings, such as flipping the image horizontally or vertically.
The GMSL video player set up -
Click Save..., then CodeGen on the toolbar. Code generation runs in the background — to see its log, click Console.
Save and CodeGen, with the Console showing code generation loading the Video Player extension
Build the App in Qt Creator
-
Leave the toolkit open. Start Qt Creator, click Open Project..., select the CMakeLists.txt in the project folder — here, C:\Projects\OpenPV\Demo\Ahsoka.QT.Video.Pro\CMakeLists.txt — and click Open.
Opening the project's CMakeLists.txt -
Qt Creator asks Configure the development container? each time the project opens. Click Yes to start it.
Note: If Qt Creator stays on Starting the development container for more than a couple of minutes, close Qt Creator completely, reopen it, and open the project again.
Qt Creator starting the development container
The development container prompt -
When the kits appear, tick OpenViewPro (aarch64) and click Configure Project.
The OpenViewPro (aarch64) kit ticked -
Unzip the example code, and copy camera1.h, camera1.cpp, cameraoverlay.h and cameraoverlay.cpp into the project folder, next to main.cpp.
-
Copy the example's main.cpp, mainwindow.h and mainwindow.cpp over the project's own, so the app creates and manages the camera and overlay.
-
In Qt Creator, choose Build → Run CMake, so CMake picks up the new files. They then appear under Source Files.
The new files listed under Source Files -
Choose Build → Build Project "Ahsoka.QT.Blank" (Ctrl+B). Compile Output ends with the build finishing successfully.
The build finished successfully
Load It onto the P100
-
Back in the toolkit, click Generate on the toolbar to build the package — see Generate Package and Load To Target. If you're asked to update the SDK again, click Yes.
-
Connect the P100 over USB. On Targets, check that its connection is set up like this:
- Platform Family: OpenViewLinuxPro (P100)
- Description: OpenViewPro
- Host Name / IP: 192.168.5.1
- Service Port: 5001
- Security Port: 0
The OpenViewPro connection for the P100 -
The display must run the distribution that matches your OpenPV version. If it doesn't yet, put the P100 in DFU mode by powering it on with a magnet held over the ambient light sensor, then use Flash Distribution followed by Prep Target.
-
Click Load on the toolbar to load the package onto the P100 — see Generate Package and Load To Target.
What You'll See
The app starts on a black screen with two buttons at the bottom, CAMERA and OVERLAY.
Tap CAMERA. The button turns green, and the live GMSL stream fills the area above the buttons.
Tap OVERLAY. Green guidelines with distance markers, and red trajectory lines, are drawn over the stream.
How the Code Works
The app runs as two processes from the same executable, each on its own IVI surface. The camera image itself is rendered by the Video Player Extension's VideoService, not by Qt — the Qt code only starts and stops the video players. The surface IDs in main.cpp must match the surfaces on the Display tab:
| Surface ID | App Id | Layer | Drawn by |
|---|---|---|---|
| 2000 | QTApp | Main | The main process: MainWindow, the black page and its two buttons |
| 2001 | GMSL_Camera1 | Main | VideoService: the GMSL stream, 1280 × 720 |
| 2002 | cameraOverlay | Overlay | The overlay process: CameraOverlay, the guidelines |
main.cpp — with no arguments, it runs the main window: it sets QT_WAYLAND_SHELL_INTEGRATION to ivi-shell and QT_IVI_SURFACE_ID to 2000 before creating the QApplication (without the first, Qt 6 uses xdg-shell and ignores the surface ID), waits for the screen, starts the device service, releases startup, and sizes MainWindow to the screen. With --cameraOverlay, it runs the overlay instead, on surface 2002.
main.cpp#include "AhsokaServices.h"
#include "AhsokaRuntimeProcess.h"
#include <QApplication>
#include <QGuiApplication>
#include <QScreen>
#include <cstring>
#include "mainwindow.h"
#include "cameraoverlay.h"
namespace {
// IVI surface IDs (must match the Layer Manager configuration in OpenLinuxPro.PackageInfo.json)
constexpr const char *kMainSurfaceId = "2000"; // QTApp - MainLayer
constexpr const char *kOverlaySurfaceId = "2002"; // cameraOverlay - OverlayLayer
// 2001 = GMSL_Camera1 video surface, owned by the VideoService
bool hasArg(int argc, char *argv[], const char *arg)
{
for (int i = 1; i < argc; ++i)
if (std::strcmp(argv[i], arg) == 0)
return true;
return false;
}
// Secondary process started by MainWindow with "--cameraOverlay".
// It only shows the transparent guideline overlay on its own IVI surface.
int runCameraOverlay(int argc, char *argv[])
{
qputenv("QT_WAYLAND_SHELL_INTEGRATION", "ivi-shell");
qputenv("QT_IVI_SURFACE_ID", kOverlaySurfaceId);
AhsokaRuntime::WaitForScreen();
QApplication app(argc, argv);
CameraOverlay overlay;
overlay.show();
return app.exec();
}
}
int main(int argc, char *argv[])
{
if (hasArg(argc, argv, "--cameraOverlay"))
return runCameraOverlay(argc, argv);
// Force the ivi-shell client integration so the app binds ivi_application and claims
// its own ivi surface id. Qt6's QtWayland otherwise defaults to xdg-shell (because the
// compositor also advertises xdg_wm_base), which silently ignores QT_IVI_SURFACE_ID.
// Both must be set before the Wayland surface is created, i.e. before QApplication.
qputenv("QT_WAYLAND_SHELL_INTEGRATION", "ivi-shell");
qputenv("QT_IVI_SURFACE_ID", kMainSurfaceId);
AhsokaRuntime::WaitForScreen();
QApplication app(argc, argv);
// Used for Local Runs (Desktop).
// On Target, the service manager will manage all services.
AhsokaRuntime::StartLocalServiceManager();
AhsokaDevice::DeviceServiceClient client;
client.Start();
AhsokaRuntime::ReleaseStartup();
MainWindow window;
// Match the window to the actual screen (1280x800 on P100) so it renders 1:1.
const auto matchScreen = [&window] {
if (const QScreen *s = QGuiApplication::primaryScreen(); s && !s->size().isEmpty())
window.setFixedSize(s->size());
};
matchScreen();
if (QScreen *s = QGuiApplication::primaryScreen())
QObject::connect(s, &QScreen::geometryChanged, &window, [matchScreen](const QRect &) { matchScreen(); });
QObject::connect(qApp, &QGuiApplication::primaryScreenChanged, &window,
[matchScreen](QScreen *) { matchScreen(); });
window.show();
const int result = app.exec();
client.RequestServiceShutdown();
client.Stop();
AhsokaRuntime::StopAll();
return result;
}
mainwindow.h / mainwindow.cpp — the black page, the hidden camera widget, and the two toggle buttons. CAMERA shows or hides the camera widget, which starts or stops the video. OVERLAY starts the same executable again with --cameraOverlay through a QProcess, and stops it when turned off; if the overlay process ends on its own, the button turns off too.
mainwindow.h#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
class QPushButton;
class QProcess;
class camera1;
// Black page with two toggle buttons (75 px high) at the bottom of the screen:
// - "CAMERA" : shows / hides the GMSL video stream (camera1)
// - "OVERLAY" : shows / hides the guideline overlay (CameraOverlay, separate process on surface 2002)
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow() override;
protected:
void resizeEvent(QResizeEvent *event) override;
private:
void setCameraVisible(bool on);
void setOverlayVisible(bool on);
void startOverlayProcess();
void stopOverlayProcess();
void layoutChildren();
camera1 *m_camera = nullptr;
QPushButton *m_cameraButton = nullptr;
QPushButton *m_overlayButton = nullptr;
QProcess *m_overlayProcess = nullptr;
static constexpr int ButtonHeight = 75;
static constexpr int ButtonMargin = 10; // horizontal margin / gap between buttons
static constexpr int ButtonBottomOffset = 2; // gap between button bottom edge and screen bottom
};
#endif // MAINWINDOW_H
mainwindow.cpp#include "mainwindow.h"
#include "camera1.h"
#include <QCoreApplication>
#include <QDebug>
#include <QProcess>
#include <QPushButton>
#include <QResizeEvent>
#include <QSignalBlocker>
#include <QWidget>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
setWindowTitle("P100 GMSL Demo");
auto *central = new QWidget(this);
central->setObjectName("central");
central->setStyleSheet("#central { background-color: black; }");
setCentralWidget(central);
// --- GMSL video (top 1280x720, hidden at startup) ---
m_camera = new camera1(central);
m_camera->move(0, 0);
m_camera->hide();
// --- Toggle buttons ---
const QString buttonStyle = QStringLiteral(
"QPushButton {"
" background-color: #2b2b2b; color: white;"
" border: 2px solid #555; border-radius: 6px;"
" font-size: 24px; font-weight: bold;"
"}"
"QPushButton:checked {"
" background-color: #1e8c3a; border-color: #3fd96a;"
"}");
m_cameraButton = new QPushButton("CAMERA", central);
m_overlayButton = new QPushButton("OVERLAY", central);
for (QPushButton *b : {m_cameraButton, m_overlayButton}) {
b->setCheckable(true);
b->setFocusPolicy(Qt::NoFocus);
b->setStyleSheet(buttonStyle);
b->raise();
}
connect(m_cameraButton, &QPushButton::toggled, this, &MainWindow::setCameraVisible);
connect(m_overlayButton, &QPushButton::toggled, this, &MainWindow::setOverlayVisible);
// --- Overlay process (same executable, started with --cameraOverlay) ---
m_overlayProcess = new QProcess(this);
m_overlayProcess->setProcessChannelMode(QProcess::ForwardedChannels);
connect(m_overlayProcess, &QProcess::started, this, [this] {
qDebug() << "[MainWindow] cameraOverlay started, pid:" << m_overlayProcess->processId();
});
connect(m_overlayProcess, &QProcess::finished, this,
[this](int exitCode, QProcess::ExitStatus status) {
qDebug() << "[MainWindow] cameraOverlay finished, exitCode:" << exitCode << "status:" << status;
// Keep the button in sync if the overlay died on its own
if (m_overlayButton->isChecked()) {
QSignalBlocker block(m_overlayButton);
m_overlayButton->setChecked(false);
}
});
connect(m_overlayProcess, &QProcess::errorOccurred, this, [this](QProcess::ProcessError error) {
qWarning() << "[MainWindow] cameraOverlay error:" << error << m_overlayProcess->errorString();
});
layoutChildren();
}
MainWindow::~MainWindow()
{
stopOverlayProcess();
}
void MainWindow::resizeEvent(QResizeEvent *event)
{
QMainWindow::resizeEvent(event);
layoutChildren();
}
// Buttons: 75 px high, bottom edge 2 px above the bottom of the screen (y = 723..798 on a 1280x800 panel).
void MainWindow::layoutChildren()
{
const int w = width();
const int h = height();
const int y = h - ButtonHeight - ButtonBottomOffset;
const int bw = (w - 3 * ButtonMargin) / 2;
m_cameraButton->setGeometry(ButtonMargin, y, bw, ButtonHeight);
m_overlayButton->setGeometry(2 * ButtonMargin + bw, y, w - (3 * ButtonMargin + bw), ButtonHeight);
}
void MainWindow::setCameraVisible(bool on)
{
// camera1 starts the GMSL players in showEvent and stops them in hideEvent
m_camera->setVisible(on);
}
void MainWindow::setOverlayVisible(bool on)
{
if (on)
startOverlayProcess();
else
stopOverlayProcess();
}
void MainWindow::startOverlayProcess()
{
if (m_overlayProcess->state() != QProcess::NotRunning)
return;
m_overlayProcess->setProgram(QCoreApplication::applicationFilePath());
m_overlayProcess->setArguments({QStringLiteral("--cameraOverlay")});
m_overlayProcess->start();
}
void MainWindow::stopOverlayProcess()
{
if (!m_overlayProcess || m_overlayProcess->state() == QProcess::NotRunning)
return;
m_overlayProcess->terminate();
if (!m_overlayProcess->waitForFinished(500)) {
m_overlayProcess->kill();
m_overlayProcess->waitForFinished(500);
}
}
camera1.h / camera1.cpp — controls the stream through AhsokaVideo::VideoServiceClient. When the widget is shown, it gets the players set up in the Video Player Extension (retrying briefly, since the service can report started before it's ready) and plays each one; when hidden, it stops them. The widget itself draws nothing and lets touches through.
camera1.h#ifndef CAMERA1_H
#define CAMERA1_H
#include <QWidget>
#include <QVector>
#include "AhsokaServices.h" // provides AhsokaVideo::VideoServiceClient (SDK inc/services)
// Controls the GMSL video stream. The video itself is rendered by the VideoService
// on IVI surface 2001 (1280x720); this widget only starts the players when shown
// and stops them when hidden.
class camera1 : public QWidget
{
Q_OBJECT
public:
explicit camera1(QWidget *parent = nullptr);
~camera1() override;
protected:
void showEvent(QShowEvent *event) override;
void hideEvent(QHideEvent *event) override;
private:
AhsokaVideo::VideoServiceClient m_client;
QVector<AhsokaVideo::VideoPlayer> m_players;
bool m_started = false;
void startCameras();
void stopCameras();
};
#endif // CAMERA1_H
camera1.cpp#include "camera1.h"
#include <QThread>
#include <QDebug>
namespace {
constexpr int kCameraWidth = 1280;
constexpr int kCameraHeight = 720; // video area only - the 75 px button bar below stays free
// Max time to wait for a VideoService reply (timeout, not a start delay)
constexpr int kServiceTimeoutMs = 300;
}
camera1::camera1(QWidget *parent) :
QWidget(parent)
{
setFixedSize(kCameraWidth, kCameraHeight);
setAttribute(Qt::WA_TransparentForMouseEvents, true);
}
camera1::~camera1()
{
stopCameras();
m_client.Stop(); // the client connects automatically on the first request
}
void camera1::showEvent(QShowEvent *event)
{
QWidget::showEvent(event);
if (!m_started) {
startCameras();
m_started = true;
}
}
void camera1::hideEvent(QHideEvent *event)
{
QWidget::hideEvent(event);
if (m_started) {
stopCameras();
m_started = false;
}
}
void camera1::startCameras()
{
// The service reports "started" before its request handler is actually
// bound, so retry a few times.
std::unique_ptr<AhsokaVideo::VideoPlayerInfo> players;
for (int attempt = 0; attempt < 10 && !players; ++attempt) {
if (attempt > 0)
QThread::msleep(25);
players = m_client.GetVideoPlayers(kServiceTimeoutMs);
}
if (!players) {
qWarning() << "[camera1] GetVideoPlayers failed";
return;
}
m_players.clear();
for (auto &p : players->players())
m_players.push_back(p);
qDebug() << "[camera1] starting" << m_players.size() << "video players";
for (auto &p : m_players) {
AhsokaVideo::VideoPlaybackRequest req;
req.set_video_player_i_d(p.video_player_i_d());
req.set_status_update_in_ms(1000);
m_client.PlayVideo(req, kServiceTimeoutMs);
}
}
void camera1::stopCameras()
{
for (auto &p : m_players)
m_client.StopVideo(p, kServiceTimeoutMs);
m_players.clear();
}
cameraoverlay.h / cameraoverlay.cpp — a transparent, frameless 1280 × 720 window that draws the guidelines with QPainter and lets touches through to the buttons below. setSteering() bends the red trajectory lines from −1.0 (full left) to +1.0 (full right); nothing calls it in this example, so they stay at 0.6. It's the place to connect a real signal, such as a steering angle from CAN.
cameraoverlay.h#pragma once
#include <QWidget>
class QPaintEvent;
class QPainter;
// Rear-camera style guideline overlay (transparent, 1280x720, IVI surface 2002 / OverlayLayer):
// - green straight fixed guidelines with distance markers
// - red curved trajectory lines drawn on top
class CameraOverlay : public QWidget
{
public:
explicit CameraOverlay(QWidget *parent = nullptr);
// -1.0 = full left ... 0 = straight ... +1.0 = full right
void setSteering(qreal steering);
protected:
void paintEvent(QPaintEvent *event) override;
private:
void drawStaticGuides(QPainter &p);
void drawTrajectory(QPainter &p);
qreal m_steering = 0.6;
};
cameraoverlay.cpp#include "cameraoverlay.h"
#include <QPainter>
#include <QPainterPath>
#include <QPaintEvent>
#include <QPen>
#include <QtMath>
namespace {
// Guideline geometry as fractions of the overlay size (perspective trapezoid)
constexpr qreal kBottomY = 1.00; // lines start at the bottom of the video
constexpr qreal kFarY = 0.42; // far end ("horizon" side)
constexpr qreal kBottomHalfW = 0.28; // half-width at the bottom, from centre
constexpr qreal kFarHalfW = 0.11; // half-width at the far end, from centre
constexpr qreal kMaxBend = 0.14; // max lateral bend of the red lines at the far end (fraction of width)
const QColor kGreen(0, 220, 70);
const QColor kRed(235, 30, 30);
}
CameraOverlay::CameraOverlay(QWidget *parent)
: QWidget(parent)
{
// Surface 2002 (cameraOverlay) - position handled by the Layer Manager.
setFixedSize(1280, 720);
setWindowFlags(Qt::Window | Qt::FramelessWindowHint | Qt::Tool);
setAttribute(Qt::WA_TranslucentBackground, true);
setAttribute(Qt::WA_NoSystemBackground, true);
setAttribute(Qt::WA_TransparentForMouseEvents, true);
}
void CameraOverlay::setSteering(qreal steering)
{
m_steering = qBound<qreal>(-1.0, steering, 1.0);
update();
}
void CameraOverlay::paintEvent(QPaintEvent *)
{
QPainter p(this);
// Fully transparent background
p.setCompositionMode(QPainter::CompositionMode_Source);
p.fillRect(rect(), Qt::transparent);
p.setCompositionMode(QPainter::CompositionMode_SourceOver);
p.setRenderHint(QPainter::Antialiasing, true);
drawStaticGuides(p); // green, below
drawTrajectory(p); // red, on top
}
void CameraOverlay::drawStaticGuides(QPainter &p)
{
const qreal w = width();
const qreal h = height();
const qreal cx = w / 2.0;
const qreal yB = h * kBottomY;
const qreal yF = h * kFarY;
const QPointF leftB (cx - w * kBottomHalfW, yB);
const QPointF leftF (cx - w * kFarHalfW, yF);
const QPointF rightB(cx + w * kBottomHalfW, yB);
const QPointF rightF(cx + w * kFarHalfW, yF);
QPen pen(kGreen, 6, Qt::SolidLine, Qt::RoundCap);
p.setPen(pen);
p.drawLine(leftB, leftF);
p.drawLine(rightB, rightF);
// Distance markers: short horizontal ticks pointing inwards, thinner with distance
const qreal marks[] = {0.25, 0.55, 0.85, 1.0};
for (qreal t : marks) {
const QPointF l = leftB + (leftF - leftB) * t;
const QPointF r = rightB + (rightF - rightB) * t;
const qreal tick = (r.x() - l.x()) * 0.18;
pen.setWidthF(6.0 - 3.0 * t);
p.setPen(pen);
p.drawLine(l, QPointF(l.x() + tick, l.y()));
p.drawLine(r, QPointF(r.x() - tick, r.y()));
}
}
void CameraOverlay::drawTrajectory(QPainter &p)
{
const qreal w = width();
const qreal h = height();
const qreal cx = w / 2.0;
const qreal yB = h * kBottomY;
const qreal yF = h * kFarY;
const qreal bend = w * kMaxBend * m_steering;
// Quadratic Bezier with the control point on the straight line midpoint:
// lateral offset grows as t^2 -> parabolic path like a real rear-camera trajectory.
auto curve = [&](qreal halfB, qreal halfF) {
const QPointF start(cx + halfB, yB);
const QPointF straightEnd(cx + halfF, yF);
const QPointF ctrl = (start + straightEnd) / 2.0;
const QPointF end(straightEnd.x() + bend, yF + qAbs(bend) * 0.15);
QPainterPath path(start);
path.quadTo(ctrl, end);
return path;
};
QPen pen(kRed, 5, Qt::SolidLine, Qt::RoundCap);
p.setPen(pen);
p.setBrush(Qt::NoBrush);
p.drawPath(curve(-w * kBottomHalfW, -w * kFarHalfW));
p.drawPath(curve( w * kBottomHalfW, w * kFarHalfW));
}