Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qlibcamera_stream_p.h
Go to the documentation of this file.
1// Copyright (C) 2026 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3#ifndef QLIBCAMERA_STREAM_P_H
4#define QLIBCAMERA_STREAM_P_H
5
6//
7// W A R N I N G
8// -------------
9//
10// This file is not part of the Qt API. It exists purely as an
11// implementation detail. This header file may change from version to
12// version without notice, or even be removed.
13//
14// We mean it.
15//
16
17#include <QtMultimedia/qvideoframe.h>
18#include <QtMultimedia/qvideoframeformat.h>
19#include <QtMultimedia/private/qtmultimediaglobal_p.h>
20#include <QtCore/private/qexpected_p.h>
21#include <QtCore/qmutex.h>
22#include <QtCore/qobject.h>
23
24#include <libcamera/controls.h>
25
26#include <chrono>
27#include <memory>
28#include <mutex>
29#include <optional>
30
31namespace libcamera {
32class Camera;
33class FrameBuffer;
34class Request;
35class Stream;
36} // namespace libcamera
37
38QT_BEGIN_NAMESPACE
39
40namespace QLibCamera {
41
42#if QT_CONFIG(linux_dmabuf)
44#endif
45
46// Number of buffers requested from libcamera for a stream.
47inline constexpr unsigned kCaptureBufferCount = 8;
48
49// Controls set by the application. They are merged into the next request queued on the camera.
51{
52public:
53 template <typename Fn>
54 void with(Fn &&fn)
55 {
56 std::lock_guard lock(m_mutex);
57 fn(m_controls);
58 }
59
60 void mergeInto(libcamera::ControlList &controls)
61 {
62 std::lock_guard lock(m_mutex);
63 controls.merge(m_controls, libcamera::ControlList::MergePolicy::OverwriteExisting);
64 }
65
66private:
67 QMutex m_mutex;
68 libcamera::ControlList m_controls;
69};
70
71// Re-arms a completed request, applies the pending controls and queues it on the camera again.
72void requeueRequest(libcamera::Camera &camera, libcamera::Request *request,
73 QLibCameraPendingControls &pendingControls);
74
75class QLibCameraCameraStream final : public QObject
76{
78public:
82#if QT_CONFIG(linux_dmabuf)
83 ,
85#endif
86 );
87
88 // Runs on libcamera's CameraManager thread -- see the class comment above.
89 void handleRequestCompleted(libcamera::Request *);
90
91 libcamera::Stream *stream() const { return m_stream; }
92
95
96private:
97 q23::expected<QVideoFrame, QString> createFrame(libcamera::Request *,
98 const libcamera::FrameBuffer &);
99
100 const std::shared_ptr<libcamera::Camera> m_libcameraCamera;
101 libcamera::Stream *const m_stream;
102 const int m_bytesPerLine;
103 const QVideoFrameFormat m_frameFormat;
104 const double m_maxFrameRate;
105 const std::shared_ptr<QLibCameraPendingControls> m_pendingControls;
106#if QT_CONFIG(linux_dmabuf)
108#endif
109
110 std::optional<std::chrono::nanoseconds> m_firstFrameTimestamp;
111};
112
113} // namespace QLibCamera
114
115QT_END_NAMESPACE
116
117#endif // QLIBCAMERA_STREAM_P_H
QLibCameraCameraStream(std::shared_ptr< libcamera::Camera >, libcamera::Stream *, int bytesPerLine, QVideoFrameFormat, double maxFrameRate, std::shared_ptr< QLibCameraPendingControls >)
void handleRequestCompleted(libcamera::Request *)
libcamera::Stream * stream() const
void setExposureCompensation(float compensation) override
void setManualIsoSensitivity(int iso) override
void setActive(bool active) override
void setCamera(const QCameraDevice &) override
void setManualExposureTime(float seconds) override
bool setCameraFormat(const QCameraFormat &) override
void zoomTo(float newZoomFactor, float rate=-1.) override
void setExposureMode(QCamera::ExposureMode) override
QVideoFrameFormat frameFormat() const override
int cameraPixelFormatScore(QVideoFrameFormat::PixelFormat, QVideoFrameFormat::ColorRange) const override
void setColorTemperature(int temperature) override
void setWhiteBalanceMode(QCamera::WhiteBalanceMode) override
bool isExposureModeSupported(QCamera::ExposureMode mode) const override
void mergeInto(libcamera::ControlList &controls)
void setExposureCompensation(ControlList &pending, float stops)
void setAnalogueGainForIso(ControlList &pending, int iso)
void setAwbEnable(ControlList &pending, bool enable)
void setZoomFactor(ControlList &pending, const ControlInfoMap &controls, float zoomFactor)
void setColorTemperature(ControlList &pending, int kelvin)
void setManualExposureTime(ControlList &pending, float seconds)
void setAeEnable(ControlList &pending, bool enable)
constexpr unsigned kCaptureBufferCount
void requeueRequest(libcamera::Camera &camera, libcamera::Request *request, QLibCameraPendingControls &pendingControls)