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
qavfcamerabase_p.h
Go to the documentation of this file.
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 QAVFCAMERABASE_H
5#define QAVFCAMERABASE_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 <QtMultimedia/private/qplatformcamera_p.h>
19#include <QtCore/private/qexpected_p.h>
20
21#include <QtCore/qobject.h>
22
23#import <AVFoundation/AVCaptureDevice.h>
24
26
27// The purpose of this class is to provide camera controls on
28// both the old native Darwin backend and the FFmpeg backend.
29class Q_MULTIMEDIA_EXPORT QAVFCameraBase : public QPlatformCamera
30{
31Q_OBJECT
32public:
33 QAVFCameraBase(QCamera *camera);
34 ~QAVFCameraBase();
35
36 bool isActive() const override;
37 void setActive(bool active) override final;
38
39 void setCamera(const QCameraDevice &camera) override final;
40 bool setCameraFormat(const QCameraFormat &format) override final;
41
42 void setFocusMode(QCamera::FocusMode mode) override;
43
44 // FocusModeAuto maps to AVCaptureFocusModeContinuousFocusMode.
45 //
46 // FocusModeManual does not map to any specific AVCaptureFocusMode
47 // value, but rather to the setting setFocusModeLockedWithLensPosition.
48 // This setting doesn't actually change the AVCaptureFocusMode but puts it
49 // into a state where the AVCaptureFocusMode no longer applies.
50 // You can go back into autofocus mode by setting the AVCaptureDevice
51 // focus mode.
52 bool isFocusModeSupported(QCamera::FocusMode mode) const override;
53
54 void setCustomFocusPoint(const QPointF &point) override;
55
56 void setFocusDistance(float distance) override;
57 void zoomTo(float factor, float rate) override;
58
59 void setFlashMode(QCamera::FlashMode mode) override;
60 bool isFlashModeSupported(QCamera::FlashMode mode) const override;
61 bool isFlashReady() const override;
62
63 void setTorchMode(QCamera::TorchMode mode) override;
64 bool isTorchModeSupported(QCamera::TorchMode mode) const override;
65
66 void setExposureMode(QCamera::ExposureMode) override;
67 bool isExposureModeSupported(QCamera::ExposureMode mode) const override;
68
69 void setExposureCompensation(float bias) override;
70 void setManualIsoSensitivity(int value) override;
71 virtual int isoSensitivity() const override;
72 void setManualExposureTime(float value) override;
73 virtual float exposureTime() const override;
74
75#ifdef Q_OS_IOS
76 // not supported on macOS
77 bool isWhiteBalanceModeSupported(QCamera::WhiteBalanceMode mode) const override;
78 void setWhiteBalanceMode(QCamera::WhiteBalanceMode /*mode*/) override;
79 void setColorTemperature(int /*temperature*/) override;
80#endif
81
82 AVCaptureDevice *device() const;
83 [[nodiscard]] static AVCaptureDevice* tryGetAvCaptureDevice(const QCameraDevice &device);
84
85protected:
86 // Called by setActive() when the active status is about to change.
87 // If called with parameter active = true, camera permissions are
88 // guaranteed to have been granted already.
89 //
90 // The returned error message is public: it is propagated up to
91 // QCamera::errorString() and may end up in the UI.
92 [[nodiscard]] virtual q23::expected<void, QString> onActiveChanged(bool active) = 0;
93 // Called by setCamera() when the camera is successfully changed.
94 virtual void onCameraDeviceChanged(
95 const QCameraDevice &,
96 const QCameraFormat &) = 0;
97 // Should be implemented by the backend to apply the camera-format
98 // to the physical camera if possible.
99 // Returns true if the format was successfully applied.
100 [[nodiscard]] virtual bool tryApplyCameraFormat(const QCameraFormat&) = 0;
101
102 bool checkCameraPermission();
103
104 void updateCameraConfiguration(const QCameraDevice &);
105 void updateSupportedFeatures(const QCameraDevice &);
106 void applyFlashSettings();
107
108 // Applies the focusDistance to the AVCaptureDevice.
109 // Does NOT trigger focusDistanceChanged
110 void applyFocusDistanceToAVCaptureDevice(float distance);
111
112 QCameraDevice m_cameraDevice;
113 bool m_active = false;
114private:
115 bool isFlashSupported = false;
116 bool isFlashAutoSupported = false;
117 bool isTorchSupported = false;
118 bool isTorchAutoSupported = false;
119
120 void forceSetFocusMode(QCamera::FocusMode mode);
121 void forceZoomTo(float factor, float rate);
122};
123
124QT_END_NAMESPACE
125
126#endif