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