1// Copyright (C) 2016 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
4#ifndef QGSTREAMERCAMERACONTROL_H
5#define QGSTREAMERCAMERACONTROL_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <private/qplatformcamera_p.h>
19#include <private/qmultimediautils_p.h>
20
21#include <mediacapture/qgstreamermediacapturesession_p.h>
22#include <common/qgst_p.h>
23#include <common/qgstpipeline_p.h>
24
25QT_BEGIN_NAMESPACE
26
27class QGstreamerCameraBase : public QPlatformCamera
28{
29public:
30 using QPlatformCamera::QPlatformCamera;
31
32 virtual QGstElement gstElement() const = 0;
33};
34
35class QGstreamerCamera : public QGstreamerCameraBase
36{
37public:
38 static QMaybe<QPlatformCamera *> create(QCamera *camera);
39
40 virtual ~QGstreamerCamera();
41
42 bool isActive() const override;
43 void setActive(bool active) override;
44
45 void setCamera(const QCameraDevice &camera) override;
46 bool setCameraFormat(const QCameraFormat &format) override;
47
48 QGstElement gstElement() const override { return gstCameraBin; }
49#if QT_CONFIG(gstreamer_photography)
50 GstPhotography *photography() const;
51#endif
52
53 void setFocusMode(QCamera::FocusMode mode) override;
54 bool isFocusModeSupported(QCamera::FocusMode mode) const override;
55
56 void setFlashMode(QCamera::FlashMode mode) override;
57 bool isFlashModeSupported(QCamera::FlashMode mode) const override;
58 bool isFlashReady() const override;
59
60 void setExposureMode(QCamera::ExposureMode) override;
61 bool isExposureModeSupported(QCamera::ExposureMode mode) const override;
62 void setExposureCompensation(float) override;
63 void setManualIsoSensitivity(int) override;
64 int isoSensitivity() const override;
65 void setManualExposureTime(float) override;
66 float exposureTime() const override;
67
68 bool isWhiteBalanceModeSupported(QCamera::WhiteBalanceMode mode) const override;
69 void setWhiteBalanceMode(QCamera::WhiteBalanceMode mode) override;
70 void setColorTemperature(int temperature) override;
71
72private:
73 QGstreamerCamera(QCamera *camera);
74
75 void updateCameraProperties();
76
77#if QT_CONFIG(linux_v4l)
78 bool isV4L2Camera() const;
79 void initV4L2Controls();
80 int setV4L2ColorTemperature(int temperature);
81 bool setV4L2Parameter(quint32 id, qint32 value);
82 int getV4L2Parameter(quint32 id) const;
83
84 bool v4l2AutoWhiteBalanceSupported = false;
85 bool v4l2ColorTemperatureSupported = false;
86 bool v4l2AutoExposureSupported = false;
87 bool v4l2ManualExposureSupported = false;
88 qint32 v4l2MinColorTemp = 5600; // Daylight...
89 qint32 v4l2MaxColorTemp = 5600;
90 qint32 v4l2MinExposure = 0;
91 qint32 v4l2MaxExposure = 0;
92 qint32 v4l2MinExposureAdjustment = 0;
93 qint32 v4l2MaxExposureAdjustment = 0;
94
95 template <typename Functor>
96 auto withV4L2DeviceFileDescriptor(Functor &&f) const
97 {
98 using ReturnType = std::invoke_result_t<Functor, int>;
99 Q_ASSERT(isV4L2Camera());
100
101 if (int gstreamerDeviceFd = gstCamera.getInt(property: "device-fd"); gstreamerDeviceFd != -1)
102 return f(gstreamerDeviceFd);
103
104 auto v4l2FileDescriptor = QFileDescriptorHandle{
105 qt_safe_open(pathname: m_v4l2DevicePath.toLocal8Bit().constData(), O_RDONLY),
106 };
107 if (!v4l2FileDescriptor) {
108 qWarning() << "Unable to open the camera" << m_v4l2DevicePath
109 << "for read to query the parameter info:" << qt_error_string(errno);
110 if constexpr (std::is_void_v<ReturnType>)
111 return;
112 else
113 return ReturnType{};
114 }
115 return f(v4l2FileDescriptor.get());
116 }
117#endif
118
119 QCameraDevice m_cameraDevice;
120
121 QGstBin gstCameraBin;
122 QGstElement gstCamera;
123 QGstElement gstCapsFilter;
124 QGstElement gstDecode;
125 QGstElement gstVideoConvert;
126 QGstElement gstVideoScale;
127
128 bool m_active = false;
129 QString m_v4l2DevicePath;
130};
131
132class QGstreamerCustomCamera : public QGstreamerCameraBase
133{
134public:
135 explicit QGstreamerCustomCamera(QCamera *);
136 explicit QGstreamerCustomCamera(QCamera *, QGstElement element);
137
138 QGstElement gstElement() const override { return gstCamera; }
139 void setCamera(const QCameraDevice &) override;
140
141 bool isActive() const override;
142 void setActive(bool) override;
143
144private:
145 QGstElement gstCamera;
146 bool m_active{};
147 const bool m_userProvidedGstElement;
148};
149
150QT_END_NAMESPACE
151
152#endif // QGSTREAMERCAMERACONTROL_H
153

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

source code of qtmultimedia/src/plugins/multimedia/gstreamer/mediacapture/qgstreamercamera_p.h