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
qandroidcamera_p.h
Go to the documentation of this file.
1// Copyright (C) 2022 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 QANDROIDCAMERA_H
5#define QANDROIDCAMERA_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
20#include <QtCore/qjniobject.h>
21#include <QtCore/qobject.h>
22
23#include <QtMultimedia/qimagecapture.h>
24
25#include <QtFFmpegMediaPluginImpl/private/qffmpeghwaccel_p.h>
26
27#include <atomic>
28#include <optional>
29
31
32Q_DECLARE_JNI_CLASS(QtJniCamera2, "org/qtproject/qt/android/multimedia/qffmpeg/QtCamera2");
33
34class QVideoFrame;
35class QAndroidVideoFrameFactory;
36
37namespace QFFmpeg {
38
40
42{
44public:
46 explicit QAndroidCamera(QCamera *camera);
48
49 bool isActive() const override { return m_state == State::Started; }
50 bool isFlashModeSupported(QCamera::FlashMode mode) const override;
51 bool isFlashReady() const override;
52 bool isFocusModeSupported(QCamera::FocusMode focusMode) const override;
53 bool isTorchModeSupported(QCamera::TorchMode mode) const override;
54 void setActive(bool active) override;
55 void setCamera(const QCameraDevice &camera) override;
56 bool setCameraFormat(const QCameraFormat &format) override;
57 void setFlashMode(QCamera::FlashMode mode) override;
58 void setFocusDistance(float distance) override;
59 void setStillCaptureResolution(QSize resolution);
60
61 // FocusModeAuto maps to CameraMetadata.CONTROL_AF_MODE_CONTINUOUS_PICTURE
62 //
63 // The CustomFocusPoint functionality maps to CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE
64 // but with the CaptureRequest.CONTROL_AF_REGIONS setting.
65 //
66 // FocusModeManual maps to CaptureRequest.CONTROL_AF_MODE_OFF
67 // but also requires us to be able to set focusDistance using
68 // CaptureRequest.LENS_FOCUS_DISTANCE.
69 //
70 // Currently implemented focus-modes: Auto, Manual
71 void setFocusMode(QCamera::FocusMode mode) override;
72 void setTorchMode(QCamera::TorchMode mode) override;
73 void zoomTo(float factor, float rate) override;
74
75 std::optional<int> ffmpegHWPixelFormat() const override;
76
77 QVideoFrameFormat frameFormat() const override;
78
79 static bool registerNativeMethods();
80
81 void capture();
82 void updateExif(const QString &filename);
83public Q_SLOTS:
85 void onCameraOpened();
86 void onCameraDisconnect();
87 void onCameraError(int error);
88 void frameAvailable(QJniObject image, bool takePhoto = false);
92 void onCaptureSessionFailed(int reason, long frameNumber);
93 void onSessionActive();
94 void onSessionClosed();
96
99 void onImageCaptureFailed(QImageCapture::Error error, const QString &errMsg);
100
101private:
102 bool isActivating() const { return m_state != State::Closed; }
103
104 void setState(State newState);
105 QtVideo::Rotation rotation() const;
106 void updateCameraCharacteristics();
107 void cleanCameraCharacteristics();
108 QSize stillResolution() const;
109 void applyStillResolution();
110
111 void restartCamera();
112 void queueCameraRestart();
113
114 State m_state = State::Closed;
115 QCameraDevice m_cameraDevice;
116 QtJniCamera2 m_jniCamera;
117
118 std::unique_ptr<QFFmpeg::HWAccel> m_hwAccel;
119
120 std::shared_ptr<QAndroidVideoFrameFactory> m_frameFactory;
121 QVideoFrameFormat::PixelFormat m_androidFramePixelFormat;
122 QList<QCamera::FlashMode> m_supportedFlashModes;
123 // List of supported focus-modes as reported by the Android camera device. Queried once when
124 // camera-device is initialized. Useful for avoiding multiple JNI calls.
125 QList<QCamera::FocusMode> m_supportedFocusModes;
126 bool m_TorchModeSupported = false;
127 bool m_wasActive = false;
128
129 bool m_waitingForFirstFrame = false;
130 QSize m_videoResolution;
131 QSize m_requestedStillResolution;
132 QSize m_stillReaderSize;
133 std::atomic<bool> m_restartPending = false;
134};
135
136} // namespace QFFmpeg
137
138QT_END_NAMESPACE
139
140#endif // QANDROIDCAMERA_H
void setFocusMode(QCamera::FocusMode mode) override
void onImageCaptureFailed(QImageCapture::Error error, const QString &errMsg)
bool isTorchModeSupported(QCamera::TorchMode mode) const override
QVideoFrameFormat frameFormat() const override
QAndroidCamera(QCamera *camera)
void setFlashMode(QCamera::FlashMode mode) override
static bool registerNativeMethods()
void onCaptureSessionFailed(int reason, long frameNumber)
void zoomTo(float factor, float rate) override
void setCamera(const QCameraDevice &camera) override
bool setCameraFormat(const QCameraFormat &format) override
void frameAvailable(QJniObject image, bool takePhoto=false)
bool isFlashReady() const override
bool isActive() const override
void setFocusDistance(float distance) override
void updateExif(const QString &filename)
void setStillCaptureResolution(QSize resolution)
bool isFocusModeSupported(QCamera::FocusMode focusMode) const override
bool isFlashModeSupported(QCamera::FlashMode mode) const override
std::optional< int > ffmpegHWPixelFormat() const override
void setActive(bool active) override
void onCameraError(int error)
void setTorchMode(QCamera::TorchMode mode) override
Q_DECLARE_JNI_CLASS(MotionEvent, "android/view/MotionEvent")