Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qandroidcamerasession_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// Copyright (C) 2016 Ruslan Baratov
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5#ifndef QANDROIDCAMERASESSION_H
6#define QANDROIDCAMERASESSION_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <qcamera.h>
20#include <QImageCapture>
21#include <QSet>
22#include <QMutex>
23#include <private/qplatformimagecapture_p.h>
24#include "androidcamera_p.h"
25
27
30class QVideoSink;
31
33{
35public:
38
39 static const QList<QCameraDevice> &availableCameras();
40
41 void setSelectedCameraId(int cameraId) { m_selectedCamera = cameraId; }
42 int getSelectedCameraId() { return m_selectedCamera; }
43 AndroidCamera *camera() const { return m_camera; }
44
45 bool isActive() const { return m_active; }
46 void setActive(bool active);
47
48 void applyResolution(const QSize &captureSize = QSize(), bool restartPreview = true);
49
50 QAndroidVideoOutput *videoOutput() const { return m_videoOutput; }
52
54
55 QList<QSize> getSupportedPreviewSizes() const;
56 QList<QVideoFrameFormat::PixelFormat> getSupportedPixelFormats() const;
57 QList<AndroidCamera::FpsRange> getSupportedPreviewFpsRange() const;
58
59 QImageEncoderSettings imageSettings() const { return m_actualImageSettings; }
61
62 bool isReadyForCapture() const;
63 void setReadyForCapture(bool ready);
64 int capture(const QString &fileName);
65 int captureToBuffer();
66
67 int currentCameraRotation() const;
68
70
72 {
73 virtual void onFrameAvailable(const QVideoFrame &frame) = 0;
74 };
75 void setPreviewCallback(PreviewCallback *callback);
76
77 void setVideoSink(QVideoSink *surface);
78
79 void disableRotation();
80 void enableRotation();
81
82 void setKeepAlive(bool keepAlive);
83
85 void activeChanged(bool);
86 void error(int error, const QString &errorString);
87 void opened();
88
90 void imageExposed(int id);
91 void imageCaptured(int id, const QImage &preview);
93 void imageAvailable(int id, const QVideoFrame &buffer);
94 void imageSaved(int id, const QString &fileName);
95 void imageCaptureError(int id, int error, const QString &errorString);
96
97private Q_SLOTS:
98 void onVideoOutputReady(bool ready);
99 void updateOrientation();
100
101 void onApplicationStateChanged();
102
103 void onCameraTakePictureFailed();
104 void onCameraPictureExposed();
105 void onCameraPictureCaptured(const QByteArray &bytes, QVideoFrameFormat::PixelFormat format, QSize size, int bytesPerLine);
106 void onLastPreviewFrameFetched(const QVideoFrame &frame);
107 void onNewPreviewFrame(const QVideoFrame &frame);
108 void onCameraPreviewStarted();
109 void onCameraPreviewFailedToStart();
110 void onCameraPreviewStopped();
111
112private:
113 static void updateAvailableCameras();
114
115 bool open();
116 void close();
117
118 bool startPreview();
119 void stopPreview();
120
121 void applyImageSettings();
122
123 void processPreviewImage(int id, const QVideoFrame &frame, int rotation);
124 void processCapturedImage(int id, const QByteArray &bytes, const QString &fileName);
125 void processCapturedImageToBuffer(int id, const QByteArray &bytes,
127
128 void setActiveHelper(bool active);
129
130 int captureImage();
131
132 QSize getDefaultResolution() const;
133
134 int m_selectedCamera;
135 AndroidCamera *m_camera;
136 QAndroidVideoOutput *m_videoOutput;
137
138 bool m_active = false;
139 bool m_isStateSaved = false;
140 bool m_savedState = false;
141 bool m_previewStarted;
142
143 bool m_rotationEnabled = false;
144
145 QVideoSink *m_sink = nullptr;
146 QAndroidTextureVideoOutput *m_textureOutput = nullptr;
147
148 QImageEncoderSettings m_requestedImageSettings;
149 QImageEncoderSettings m_actualImageSettings;
150 AndroidCamera::FpsRange m_requestedFpsRange;
152
153 bool m_readyForCapture;
154 int m_currentImageCaptureId;
155 QString m_currentImageCaptureFileName;
156 bool m_imageCaptureToBuffer;
157
158 QMutex m_videoFrameCallbackMutex;
159 PreviewCallback *m_previewCallback;
160 bool m_keepActive;
161 QMetaObject::Connection m_retryPreviewConnection;
162};
163
165
166#endif // QANDROIDCAMERASESSION_H
QAndroidVideoOutput * videoOutput() const
void setVideoSink(QVideoSink *surface)
void imageMetadataAvailable(int id, const QMediaMetaData &key)
void setImageSettings(const QImageEncoderSettings &settings)
void imageCaptured(int id, const QImage &preview)
void error(int error, const QString &errorString)
QList< AndroidCamera::FpsRange > getSupportedPreviewFpsRange() const
void setCameraFormat(const QCameraFormat &format)
int capture(const QString &fileName)
void readyForCaptureChanged(bool)
void activeChanged(bool)
QAndroidCameraSession(QObject *parent=0)
void imageCaptureError(int id, int error, const QString &errorString)
void setVideoOutput(QAndroidVideoOutput *output)
QImageEncoderSettings imageSettings() const
void imageAvailable(int id, const QVideoFrame &buffer)
void setSelectedCameraId(int cameraId)
void applyResolution(const QSize &captureSize=QSize(), bool restartPreview=true)
AndroidCamera * camera() const
QList< QVideoFrameFormat::PixelFormat > getSupportedPixelFormats() const
QList< QSize > getSupportedPreviewSizes() const
void setKeepAlive(bool keepAlive)
void imageSaved(int id, const QString &fileName)
static const QList< QCameraDevice > & availableCameras()
void setPreviewFormat(AndroidCamera::ImageFormat format)
void imageExposed(int id)
void setPreviewCallback(PreviewCallback *callback)
\inmodule QtCore
Definition qbytearray.h:57
The QCameraFormat class describes a video format supported by a camera device. \inmodule QtMultimedia...
\inmodule QtGui
Definition qimage.h:37
\inmodule QtMultimedia
\inmodule QtCore Represents a handle to a signal-slot (or signal-functor) connection.
\inmodule QtCore
Definition qmutex.h:281
\inmodule QtCore
Definition qobject.h:103
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
\inmodule QtCore
Definition qsize.h:25
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
PixelFormat
Enumerates video data types.
The QVideoFrame class represents a frame of video data.
Definition qvideoframe.h:27
The QVideoSink class represents a generic sink for video data.
Definition qvideosink.h:22
Combined button and popup list for selecting options.
DBusConnection const char DBusError * error
GLuint64 key
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLuint buffer
GLint GLsizei GLsizei GLenum format
#define Q_OBJECT
#define Q_SLOTS
#define Q_SIGNALS
QT_BEGIN_NAMESPACE typedef uchar * output
QSettings settings("MySoft", "Star Runner")
[0]
QFrame frame
[0]
virtual void onFrameAvailable(const QVideoFrame &frame)=0