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_camera_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_CAMERA_P_H
4#define QLIBCAMERA_CAMERA_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 "qlibcamera_stream_p.h" // for the full QLibCameraCameraStream definition
18
19#include <QtMultimedia/private/qplatformcamera_p.h>
20#include <QtCore/private/qexpected_p.h>
21
22#include <chrono>
23#include <memory>
24#include <optional>
25#include <tuple>
26#include <utility>
27#include <vector>
28
29namespace libcamera {
30class Camera;
31class CameraConfiguration;
32class FrameBufferAllocator;
33class Request;
34} // namespace libcamera
35
36QT_BEGIN_NAMESPACE
37
38namespace QLibCamera {
39
41
42class QLibCameraCamera final : public QPlatformCamera
43{
44 Q_OBJECT
45public:
46 explicit QLibCameraCamera(QCamera *parent, std::shared_ptr<QLibCameraInstance>);
48
49 bool isActive() const override { return m_active; }
50 void setActive(bool active) override;
51
52 void setCamera(const QCameraDevice &) override;
53 bool setCameraFormat(const QCameraFormat &) override;
54
55 void setExposureMode(QCamera::ExposureMode) override;
56 bool isExposureModeSupported(QCamera::ExposureMode mode) const override;
57 void setExposureCompensation(float compensation) override;
59 void setManualExposureTime(float seconds) override;
60
62 void setColorTemperature(int temperature) override;
63
64 void zoomTo(float newZoomFactor, float rate = -1.) override;
65
66 QVideoFrameFormat frameFormat() const override;
67
68private:
70 QVideoFrameFormat::ColorRange) const override;
71
72 using StartCapturingResult = q23::expected<void, std::tuple<QCamera::Error, QString>>;
73
74 QCameraFormat resolveCameraFormat() const;
75
76 StartCapturingResult startCapturing();
77 void startCapturingReportingErrors();
78 void stopCapturing();
79
80 template <typename Fn>
81 void withPendingControls(Fn &&fn)
82 {
83 if (m_pendingControls)
84 m_pendingControls->with(std::forward<Fn>(fn));
85 }
86
87 // Lifecycle of the libcamera stream
88 enum class StreamState : uint8_t {
89 Idle,
90 Acquired,
91 Running,
92 };
93
94 std::shared_ptr<QLibCameraInstance> m_instance;
95 std::shared_ptr<libcamera::Camera> m_camera;
96 std::unique_ptr<QLibCameraCameraStream> m_stream;
97 std::shared_ptr<QLibCameraPendingControls> m_pendingControls;
98#if QT_CONFIG(linux_dmabuf)
99 std::shared_ptr<QLibCameraDmaBufRegistry> m_dmaBufRegistry;
100#endif
101
102 QCameraDevice m_cameraDevice;
103 QCameraFormat m_resolvedFormat;
104 bool m_active = false;
105 StreamState m_streamState = StreamState::Idle;
106 std::optional<std::chrono::microseconds> m_lastFrameStart;
107 std::optional<std::chrono::microseconds> m_lastFrameEnd;
108
109 std::unique_ptr<libcamera::CameraConfiguration> m_config;
110 std::unique_ptr<libcamera::FrameBufferAllocator> m_allocator;
111 std::vector<std::unique_ptr<libcamera::Request>> m_requests;
112
113 int m_stride = 0;
114 QVideoFrameFormat::ColorSpace m_colorSpace = QVideoFrameFormat::ColorSpace_Undefined;
115 QVideoFrameFormat::ColorRange m_colorRange = QVideoFrameFormat::ColorRange_Unknown;
116};
117
118} // namespace QLibCamera
119
120QT_END_NAMESPACE
121
122#endif // QLIBCAMERA_CAMERA_P_H
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 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