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
28
29Q_DECLARE_JNI_CLASS(QtJniCamera2, "org/qtproject/qt/android/multimedia/qffmpeg/QtCamera2");
30
31class QVideoFrame;
32class QAndroidVideoFrameFactory;
33
34namespace QFFmpeg {
35
37
39{
41public:
43 explicit QAndroidCamera(QCamera *camera);
45
46 bool isActive() const override { return m_state == State::Started; }
47 bool isFlashModeSupported(QCamera::FlashMode mode) const override;
48 bool isFlashReady() const override;
49 bool isFocusModeSupported(QCamera::FocusMode focusMode) const override;
50 bool isTorchModeSupported(QCamera::TorchMode mode) const override;
51 void setActive(bool active) override;
52 void setCamera(const QCameraDevice &camera) override;
53 bool setCameraFormat(const QCameraFormat &format) override;
54 void setFlashMode(QCamera::FlashMode mode) override;
55 void setFocusDistance(float distance) override;
56
57 // FocusModeAuto maps to CameraMetadata.CONTROL_AF_MODE_CONTINUOUS_PICTURE
58 //
59 // The CustomFocusPoint functionality maps to CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE
60 // but with the CaptureRequest.CONTROL_AF_REGIONS setting.
61 //
62 // FocusModeManual maps to CaptureRequest.CONTROL_AF_MODE_OFF
63 // but also requires us to be able to set focusDistance using
64 // CaptureRequest.LENS_FOCUS_DISTANCE.
65 //
66 // Currently implemented focus-modes: Auto, Manual
67 void setFocusMode(QCamera::FocusMode mode) override;
68 void setTorchMode(QCamera::TorchMode mode) override;
69 void zoomTo(float factor, float rate) override;
70
71 std::optional<int> ffmpegHWPixelFormat() const override;
72
73 QVideoFrameFormat frameFormat() const override;
74
75 static bool registerNativeMethods();
76
77 void capture();
78 void updateExif(const QString &filename);
79public slots:
81 void onCameraOpened();
82 void onCameraDisconnect();
83 void onCameraError(int error);
84 void frameAvailable(QJniObject image, bool takePhoto = false);
87 void onCaptureSessionFailed(int reason, long frameNumber);
88 void onSessionActive();
89 void onSessionClosed();
91
94 void onImageCaptureFailed(QImageCapture::Error error, const QString &errMsg);
95
96private:
97 bool isActivating() const { return m_state != State::Closed; }
98
99 void setState(State newState);
100 QtVideo::Rotation rotation() const;
101 void updateCameraCharacteristics();
102 void cleanCameraCharacteristics();
103
104 State m_state = State::Closed;
105 QCameraDevice m_cameraDevice;
106 QtJniCamera2 m_jniCamera;
107
108 std::unique_ptr<QFFmpeg::HWAccel> m_hwAccel;
109
110 std::shared_ptr<QAndroidVideoFrameFactory> m_frameFactory;
111 QVideoFrameFormat::PixelFormat m_androidFramePixelFormat;
112 QList<QCamera::FlashMode> m_supportedFlashModes;
113 // List of supported focus-modes as reported by the Android camera device. Queried once when
114 // camera-device is initialized. Useful for avoiding multiple JNI calls.
115 QList<QCamera::FocusMode> m_supportedFocusModes;
116 bool m_TorchModeSupported = false;
117 bool m_wasActive = false;
118
119 bool m_waitingForFirstFrame = false;
120};
121
122} // namespace QFFmpeg
123
124QT_END_NAMESPACE
125
126#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)
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
std::conditional_t< QT_FFMPEG_AVIO_WRITE_CONST, const uint8_t *, uint8_t * > AvioWriteBufferType
Q_DECLARE_JNI_CLASS(MotionEvent, "android/view/MotionEvent")