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
qandroidintegration.cpp
Go to the documentation of this file.
1// Copyright (C) 2021 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
12#include "qandroidcamera_p.h"
13#include "qandroidimagecapture_p.h"
22#include <private/qplatformvideodevices_p.h>
23
24#include <QCoreApplication>
25#include <QtCore/qjnitypes.h>
26
27#include <QtMultimedia/private/qplatformmediaplugin_p.h>
28
30
31Q_LOGGING_CATEGORY(qtAndroidMediaPlugin, "qt.multimedia.android")
32
33namespace {
35{
36public:
38
39protected:
41 {
42 return QAndroidCameraSession::availableCameras();
43 }
44};
45} // namespace
46
48{
49 Q_OBJECT
50 Q_PLUGIN_METADATA(IID QPlatformMediaPlugin_iid FILE "android.json")
51
52public:
56
58 {
59 if (name == u"android")
60 return new QAndroidIntegration;
61 return nullptr;
62 }
63};
64
66
68{
69 return new QAndroidAudioDecoder(decoder);
70}
71
73{
74 return new QAndroidFormatInfo;
75}
76
81
83{
84 return new QAndroidMediaPlayer(player);
85}
86
87q23::expected<QPlatformCamera *, QString> QAndroidIntegration::createCamera(QCamera *camera)
88{
89 return new QAndroidCamera(camera);
90}
91
93{
94 return new QAndroidMediaEncoder(recorder);
95}
96
98{
99 return new QAndroidImageCapture(imageCapture);
100}
101
103{
104 return new QAndroidAudioOutput(q);
105}
106
108{
109 return new QAndroidAudioInput(audioInput);
110}
111
112q23::expected<QPlatformVideoSink *, QString> QAndroidIntegration::createVideoSink(QVideoSink *sink)
113{
114 return new QAndroidVideoSink(sink);
115}
116
117Q_DECLARE_JNI_CLASS(QtMultimediaUtils, "org/qtproject/qt/android/multimedia/QtMultimediaUtils")
118
119Q_DECL_EXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void * /*reserved*/)
120{
121 static bool initialized = false;
122 if (initialized)
123 return JNI_VERSION_1_6;
124 initialized = true;
125
126 QT_USE_NAMESPACE
127 typedef union {
128 JNIEnv *nativeEnvironment;
129 void *venv;
130 } UnionJNIEnvToVoid;
131
132 UnionJNIEnvToVoid uenv;
133 uenv.venv = NULL;
134
135 if (vm->GetEnv(&uenv.venv, JNI_VERSION_1_6) != JNI_OK)
136 return JNI_ERR;
137
138 const auto context = QNativeInterface::QAndroidApplication::context();
139 QtJniTypes::QtMultimediaUtils::callStaticMethod<void>("setContext", context);
140
141 if (!AndroidMediaPlayer::registerNativeMethods()
142 || !AndroidCamera::registerNativeMethods()
143 || !AndroidMediaRecorder::registerNativeMethods()
144 || !AndroidSurfaceHolder::registerNativeMethods()) {
145 return JNI_ERR;
146 }
147
148 AndroidSurfaceTexture::registerNativeMethods();
149
150 return JNI_VERSION_1_6;
151}
152
154{
155 return new AndroidVideoDevices(this);
156}
157
158QT_END_NAMESPACE
159
160#include "qandroidintegration.moc"
QPlatformVideoDevices * createVideoDevices() override
q23::expected< QPlatformAudioInput *, QString > createAudioInput(QAudioInput *audioInput) override
q23::expected< QPlatformAudioDecoder *, QString > createAudioDecoder(QAudioDecoder *decoder) override
q23::expected< QPlatformAudioOutput *, QString > createAudioOutput(QAudioOutput *q) override
q23::expected< QPlatformImageCapture *, QString > createImageCapture(QImageCapture *imageCapture) override
q23::expected< QPlatformMediaRecorder *, QString > createRecorder(QMediaRecorder *recorder) override
q23::expected< QPlatformMediaPlayer *, QString > createPlayer(QMediaPlayer *player) override
QPlatformMediaFormatInfo * createFormatInfo() override
q23::expected< QPlatformMediaCaptureSession *, QString > createCaptureSession() override
QList< QCameraDevice > findVideoInputs() const override
Q_DECLARE_JNI_CLASS(MotionEvent, "android/view/MotionEvent")