Android: Use the new findClass() method.
Avoid local caching. Change-Id: I1e30896da664c5a45c38c09412c16cb8ff70c5c7 Reviewed-by: Yoann Lopes <yoann.lopes@theqtcompany.com>
This commit is contained in:
committed by
Christian Stromme
parent
e128207f75
commit
b366a99eb1
@@ -43,7 +43,7 @@
|
|||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
static jclass g_qtCameraListenerClass = 0;
|
static const char QtCameraListenerClassName[] = "org/qtproject/qt5/android/multimedia/QtCameraListener";
|
||||||
static QMutex g_cameraMapMutex;
|
static QMutex g_cameraMapMutex;
|
||||||
typedef QMap<int, AndroidCamera *> CameraMap;
|
typedef QMap<int, AndroidCamera *> CameraMap;
|
||||||
Q_GLOBAL_STATIC(CameraMap, g_cameraMap)
|
Q_GLOBAL_STATIC(CameraMap, g_cameraMap)
|
||||||
@@ -720,7 +720,7 @@ bool AndroidCameraPrivate::init(int cameraId)
|
|||||||
if (exceptionCheckAndClear(env) || !m_camera.isValid())
|
if (exceptionCheckAndClear(env) || !m_camera.isValid())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
m_cameraListener = QJNIObjectPrivate(g_qtCameraListenerClass, "(I)V", m_cameraId);
|
m_cameraListener = QJNIObjectPrivate(QtCameraListenerClassName, "(I)V", m_cameraId);
|
||||||
m_info = QJNIObjectPrivate("android/hardware/Camera$CameraInfo");
|
m_info = QJNIObjectPrivate("android/hardware/Camera$CameraInfo");
|
||||||
m_camera.callStaticMethod<void>("android/hardware/Camera",
|
m_camera.callStaticMethod<void>("android/hardware/Camera",
|
||||||
"getCameraInfo",
|
"getCameraInfo",
|
||||||
@@ -1392,24 +1392,22 @@ QStringList AndroidCameraPrivate::callParametersStringListMethod(const QByteArra
|
|||||||
return stringList;
|
return stringList;
|
||||||
}
|
}
|
||||||
|
|
||||||
static JNINativeMethod methods[] = {
|
|
||||||
{"notifyAutoFocusComplete", "(IZ)V", (void *)notifyAutoFocusComplete},
|
|
||||||
{"notifyPictureExposed", "(I)V", (void *)notifyPictureExposed},
|
|
||||||
{"notifyPictureCaptured", "(I[B)V", (void *)notifyPictureCaptured},
|
|
||||||
{"notifyFrameFetched", "(I[B)V", (void *)notifyFrameFetched}
|
|
||||||
};
|
|
||||||
|
|
||||||
bool AndroidCamera::initJNI(JNIEnv *env)
|
bool AndroidCamera::initJNI(JNIEnv *env)
|
||||||
{
|
{
|
||||||
jclass clazz = env->FindClass("org/qtproject/qt5/android/multimedia/QtCameraListener");
|
jclass clazz = QJNIEnvironmentPrivate::findClass(QtCameraListenerClassName,
|
||||||
|
env);
|
||||||
|
|
||||||
if (!exceptionCheckAndClear(env) && clazz) {
|
static const JNINativeMethod methods[] = {
|
||||||
g_qtCameraListenerClass = static_cast<jclass>(env->NewGlobalRef(clazz));
|
{"notifyAutoFocusComplete", "(IZ)V", (void *)notifyAutoFocusComplete},
|
||||||
if (env->RegisterNatives(g_qtCameraListenerClass,
|
{"notifyPictureExposed", "(I)V", (void *)notifyPictureExposed},
|
||||||
methods,
|
{"notifyPictureCaptured", "(I[B)V", (void *)notifyPictureCaptured},
|
||||||
sizeof(methods) / sizeof(methods[0])) < 0) {
|
{"notifyFrameFetched", "(I[B)V", (void *)notifyFrameFetched}
|
||||||
return false;
|
};
|
||||||
}
|
|
||||||
|
if (clazz && env->RegisterNatives(clazz,
|
||||||
|
methods,
|
||||||
|
sizeof(methods) / sizeof(methods[0])) != JNI_OK) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -39,7 +39,7 @@
|
|||||||
#include "androidsurfacetexture.h"
|
#include "androidsurfacetexture.h"
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
|
|
||||||
static jclass mediaPlayerClass = Q_NULLPTR;
|
static const char QtAndroidMediaPlayerClassName[] = "org/qtproject/qt5/android/multimedia/QtAndroidMediaPlayer";
|
||||||
typedef QMap<jlong, AndroidMediaPlayer *> MediaPlayerMap;
|
typedef QMap<jlong, AndroidMediaPlayer *> MediaPlayerMap;
|
||||||
Q_GLOBAL_STATIC(MediaPlayerMap, mediaPlayers)
|
Q_GLOBAL_STATIC(MediaPlayerMap, mediaPlayers)
|
||||||
|
|
||||||
@@ -50,10 +50,10 @@ AndroidMediaPlayer::AndroidMediaPlayer()
|
|||||||
{
|
{
|
||||||
|
|
||||||
const jlong id = reinterpret_cast<jlong>(this);
|
const jlong id = reinterpret_cast<jlong>(this);
|
||||||
mMediaPlayer = QJNIObjectPrivate(mediaPlayerClass,
|
mMediaPlayer = QJNIObjectPrivate(QtAndroidMediaPlayerClassName,
|
||||||
"(Landroid/app/Activity;J)V",
|
"(Landroid/app/Activity;J)V",
|
||||||
QtAndroidPrivate::activity(),
|
QtAndroidPrivate::activity(),
|
||||||
id);
|
id);
|
||||||
(*mediaPlayers)[id] = this;
|
(*mediaPlayers)[id] = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -233,26 +233,23 @@ static void onVideoSizeChangedNative(JNIEnv *env,
|
|||||||
|
|
||||||
bool AndroidMediaPlayer::initJNI(JNIEnv *env)
|
bool AndroidMediaPlayer::initJNI(JNIEnv *env)
|
||||||
{
|
{
|
||||||
jclass jClass = env->FindClass("org/qtproject/qt5/android/multimedia/QtAndroidMediaPlayer");
|
jclass clazz = QJNIEnvironmentPrivate::findClass(QtAndroidMediaPlayerClassName,
|
||||||
|
env);
|
||||||
|
|
||||||
if (jClass) {
|
static const JNINativeMethod methods[] = {
|
||||||
mediaPlayerClass = static_cast<jclass>(env->NewGlobalRef(jClass));
|
{"onErrorNative", "(IIJ)V", reinterpret_cast<void *>(onErrorNative)},
|
||||||
|
{"onBufferingUpdateNative", "(IJ)V", reinterpret_cast<void *>(onBufferingUpdateNative)},
|
||||||
|
{"onProgressUpdateNative", "(IJ)V", reinterpret_cast<void *>(onProgressUpdateNative)},
|
||||||
|
{"onDurationChangedNative", "(IJ)V", reinterpret_cast<void *>(onDurationChangedNative)},
|
||||||
|
{"onInfoNative", "(IIJ)V", reinterpret_cast<void *>(onInfoNative)},
|
||||||
|
{"onVideoSizeChangedNative", "(IIJ)V", reinterpret_cast<void *>(onVideoSizeChangedNative)},
|
||||||
|
{"onStateChangedNative", "(IJ)V", reinterpret_cast<void *>(onStateChangedNative)}
|
||||||
|
};
|
||||||
|
|
||||||
JNINativeMethod methods[] = {
|
if (clazz && env->RegisterNatives(clazz,
|
||||||
{"onErrorNative", "(IIJ)V", reinterpret_cast<void *>(onErrorNative)},
|
methods,
|
||||||
{"onBufferingUpdateNative", "(IJ)V", reinterpret_cast<void *>(onBufferingUpdateNative)},
|
sizeof(methods) / sizeof(methods[0])) != JNI_OK) {
|
||||||
{"onProgressUpdateNative", "(IJ)V", reinterpret_cast<void *>(onProgressUpdateNative)},
|
|
||||||
{"onDurationChangedNative", "(IJ)V", reinterpret_cast<void *>(onDurationChangedNative)},
|
|
||||||
{"onInfoNative", "(IIJ)V", reinterpret_cast<void *>(onInfoNative)},
|
|
||||||
{"onVideoSizeChangedNative", "(IIJ)V", reinterpret_cast<void *>(onVideoSizeChangedNative)},
|
|
||||||
{"onStateChangedNative", "(IJ)V", reinterpret_cast<void *>(onStateChangedNative)}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (env->RegisterNatives(mediaPlayerClass,
|
|
||||||
methods,
|
|
||||||
sizeof(methods) / sizeof(methods[0])) < 0) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ AndroidCamcorderProfile::AndroidCamcorderProfile(const QJNIObjectPrivate &camcor
|
|||||||
m_camcorderProfile = camcorderProfile;
|
m_camcorderProfile = camcorderProfile;
|
||||||
}
|
}
|
||||||
|
|
||||||
static jclass g_qtMediaRecorderListenerClass = 0;
|
static const char QtMediaRecorderListenerClassName[] = "org/qtproject/qt5/android/multimedia/QtMediaRecorderListener";
|
||||||
typedef QMap<jlong, AndroidMediaRecorder*> MediaRecorderMap;
|
typedef QMap<jlong, AndroidMediaRecorder*> MediaRecorderMap;
|
||||||
Q_GLOBAL_STATIC(MediaRecorderMap, mediaRecorders)
|
Q_GLOBAL_STATIC(MediaRecorderMap, mediaRecorders)
|
||||||
|
|
||||||
@@ -137,7 +137,7 @@ AndroidMediaRecorder::AndroidMediaRecorder()
|
|||||||
{
|
{
|
||||||
m_mediaRecorder = QJNIObjectPrivate("android/media/MediaRecorder");
|
m_mediaRecorder = QJNIObjectPrivate("android/media/MediaRecorder");
|
||||||
if (m_mediaRecorder.isValid()) {
|
if (m_mediaRecorder.isValid()) {
|
||||||
QJNIObjectPrivate listener(g_qtMediaRecorderListenerClass, "(J)V", m_id);
|
QJNIObjectPrivate listener(QtMediaRecorderListenerClassName, "(J)V", m_id);
|
||||||
m_mediaRecorder.callMethod<void>("setOnErrorListener",
|
m_mediaRecorder.callMethod<void>("setOnErrorListener",
|
||||||
"(Landroid/media/MediaRecorder$OnErrorListener;)V",
|
"(Landroid/media/MediaRecorder$OnErrorListener;)V",
|
||||||
listener.object());
|
listener.object());
|
||||||
@@ -339,24 +339,20 @@ void AndroidMediaRecorder::setOutputFile(const QString &path)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static JNINativeMethod methods[] = {
|
|
||||||
{"notifyError", "(JII)V", (void *)notifyError},
|
|
||||||
{"notifyInfo", "(JII)V", (void *)notifyInfo}
|
|
||||||
};
|
|
||||||
|
|
||||||
bool AndroidMediaRecorder::initJNI(JNIEnv *env)
|
bool AndroidMediaRecorder::initJNI(JNIEnv *env)
|
||||||
{
|
{
|
||||||
jclass clazz = env->FindClass("org/qtproject/qt5/android/multimedia/QtMediaRecorderListener");
|
jclass clazz = QJNIEnvironmentPrivate::findClass(QtMediaRecorderListenerClassName,
|
||||||
if (env->ExceptionCheck())
|
env);
|
||||||
env->ExceptionClear();
|
|
||||||
|
|
||||||
if (clazz) {
|
static const JNINativeMethod methods[] = {
|
||||||
g_qtMediaRecorderListenerClass = static_cast<jclass>(env->NewGlobalRef(clazz));
|
{"notifyError", "(JII)V", (void *)notifyError},
|
||||||
if (env->RegisterNatives(g_qtMediaRecorderListenerClass,
|
{"notifyInfo", "(JII)V", (void *)notifyInfo}
|
||||||
methods,
|
};
|
||||||
sizeof(methods) / sizeof(methods[0])) < 0) {
|
|
||||||
|
if (clazz && env->RegisterNatives(clazz,
|
||||||
|
methods,
|
||||||
|
sizeof(methods) / sizeof(methods[0])) != JNI_OK) {
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -37,7 +37,7 @@
|
|||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
static jclass g_qtSurfaceTextureListenerClass = 0;
|
static const char QtSurfaceTextureListenerClassName[] = "org/qtproject/qt5/android/multimedia/QtSurfaceTextureListener";
|
||||||
static QMap<int, AndroidSurfaceTexture*> g_objectMap;
|
static QMap<int, AndroidSurfaceTexture*> g_objectMap;
|
||||||
|
|
||||||
// native method for QtSurfaceTexture.java
|
// native method for QtSurfaceTexture.java
|
||||||
@@ -70,7 +70,7 @@ AndroidSurfaceTexture::AndroidSurfaceTexture(unsigned int texName)
|
|||||||
if (m_surfaceTexture.isValid())
|
if (m_surfaceTexture.isValid())
|
||||||
g_objectMap.insert(int(texName), this);
|
g_objectMap.insert(int(texName), this);
|
||||||
|
|
||||||
QJNIObjectPrivate listener(g_qtSurfaceTextureListenerClass, "(I)V", jint(texName));
|
QJNIObjectPrivate listener(QtSurfaceTextureListenerClassName, "(I)V", jint(texName));
|
||||||
m_surfaceTexture.callMethod<void>("setOnFrameAvailableListener",
|
m_surfaceTexture.callMethod<void>("setOnFrameAvailableListener",
|
||||||
"(Landroid/graphics/SurfaceTexture$OnFrameAvailableListener;)V",
|
"(Landroid/graphics/SurfaceTexture$OnFrameAvailableListener;)V",
|
||||||
listener.object());
|
listener.object());
|
||||||
@@ -144,27 +144,23 @@ jobject AndroidSurfaceTexture::surfaceHolder()
|
|||||||
return m_surfaceHolder.object();
|
return m_surfaceHolder.object();
|
||||||
}
|
}
|
||||||
|
|
||||||
static JNINativeMethod methods[] = {
|
|
||||||
{"notifyFrameAvailable", "(I)V", (void *)notifyFrameAvailable}
|
|
||||||
};
|
|
||||||
|
|
||||||
bool AndroidSurfaceTexture::initJNI(JNIEnv *env)
|
bool AndroidSurfaceTexture::initJNI(JNIEnv *env)
|
||||||
{
|
{
|
||||||
// SurfaceTexture is available since API 11.
|
// SurfaceTexture is available since API 11.
|
||||||
if (QtAndroidPrivate::androidSdkVersion() < 11)
|
if (QtAndroidPrivate::androidSdkVersion() < 11)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
jclass clazz = env->FindClass("org/qtproject/qt5/android/multimedia/QtSurfaceTextureListener");
|
jclass clazz = QJNIEnvironmentPrivate::findClass(QtSurfaceTextureListenerClassName,
|
||||||
if (env->ExceptionCheck())
|
env);
|
||||||
env->ExceptionClear();
|
|
||||||
|
|
||||||
if (clazz) {
|
static const JNINativeMethod methods[] = {
|
||||||
g_qtSurfaceTextureListenerClass = static_cast<jclass>(env->NewGlobalRef(clazz));
|
{"notifyFrameAvailable", "(I)V", (void *)notifyFrameAvailable}
|
||||||
if (env->RegisterNatives(g_qtSurfaceTextureListenerClass,
|
};
|
||||||
methods,
|
|
||||||
sizeof(methods) / sizeof(methods[0])) < 0) {
|
if (clazz && env->RegisterNatives(clazz,
|
||||||
return false;
|
methods,
|
||||||
}
|
sizeof(methods) / sizeof(methods[0])) != JNI_OK) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user