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
|
||||
|
||||
static jclass g_qtCameraListenerClass = 0;
|
||||
static const char QtCameraListenerClassName[] = "org/qtproject/qt5/android/multimedia/QtCameraListener";
|
||||
static QMutex g_cameraMapMutex;
|
||||
typedef QMap<int, AndroidCamera *> CameraMap;
|
||||
Q_GLOBAL_STATIC(CameraMap, g_cameraMap)
|
||||
@@ -720,7 +720,7 @@ bool AndroidCameraPrivate::init(int cameraId)
|
||||
if (exceptionCheckAndClear(env) || !m_camera.isValid())
|
||||
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_camera.callStaticMethod<void>("android/hardware/Camera",
|
||||
"getCameraInfo",
|
||||
@@ -1392,24 +1392,22 @@ QStringList AndroidCameraPrivate::callParametersStringListMethod(const QByteArra
|
||||
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)
|
||||
{
|
||||
jclass clazz = env->FindClass("org/qtproject/qt5/android/multimedia/QtCameraListener");
|
||||
jclass clazz = QJNIEnvironmentPrivate::findClass(QtCameraListenerClassName,
|
||||
env);
|
||||
|
||||
if (!exceptionCheckAndClear(env) && clazz) {
|
||||
g_qtCameraListenerClass = static_cast<jclass>(env->NewGlobalRef(clazz));
|
||||
if (env->RegisterNatives(g_qtCameraListenerClass,
|
||||
methods,
|
||||
sizeof(methods) / sizeof(methods[0])) < 0) {
|
||||
return false;
|
||||
}
|
||||
static const JNINativeMethod methods[] = {
|
||||
{"notifyAutoFocusComplete", "(IZ)V", (void *)notifyAutoFocusComplete},
|
||||
{"notifyPictureExposed", "(I)V", (void *)notifyPictureExposed},
|
||||
{"notifyPictureCaptured", "(I[B)V", (void *)notifyPictureCaptured},
|
||||
{"notifyFrameFetched", "(I[B)V", (void *)notifyFrameFetched}
|
||||
};
|
||||
|
||||
if (clazz && env->RegisterNatives(clazz,
|
||||
methods,
|
||||
sizeof(methods) / sizeof(methods[0])) != JNI_OK) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
#include "androidsurfacetexture.h"
|
||||
#include <QMap>
|
||||
|
||||
static jclass mediaPlayerClass = Q_NULLPTR;
|
||||
static const char QtAndroidMediaPlayerClassName[] = "org/qtproject/qt5/android/multimedia/QtAndroidMediaPlayer";
|
||||
typedef QMap<jlong, AndroidMediaPlayer *> MediaPlayerMap;
|
||||
Q_GLOBAL_STATIC(MediaPlayerMap, mediaPlayers)
|
||||
|
||||
@@ -50,10 +50,10 @@ AndroidMediaPlayer::AndroidMediaPlayer()
|
||||
{
|
||||
|
||||
const jlong id = reinterpret_cast<jlong>(this);
|
||||
mMediaPlayer = QJNIObjectPrivate(mediaPlayerClass,
|
||||
"(Landroid/app/Activity;J)V",
|
||||
QtAndroidPrivate::activity(),
|
||||
id);
|
||||
mMediaPlayer = QJNIObjectPrivate(QtAndroidMediaPlayerClassName,
|
||||
"(Landroid/app/Activity;J)V",
|
||||
QtAndroidPrivate::activity(),
|
||||
id);
|
||||
(*mediaPlayers)[id] = this;
|
||||
}
|
||||
|
||||
@@ -233,26 +233,23 @@ static void onVideoSizeChangedNative(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) {
|
||||
mediaPlayerClass = static_cast<jclass>(env->NewGlobalRef(jClass));
|
||||
static const JNINativeMethod methods[] = {
|
||||
{"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[] = {
|
||||
{"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)}
|
||||
};
|
||||
|
||||
if (env->RegisterNatives(mediaPlayerClass,
|
||||
methods,
|
||||
sizeof(methods) / sizeof(methods[0])) < 0) {
|
||||
if (clazz && env->RegisterNatives(clazz,
|
||||
methods,
|
||||
sizeof(methods) / sizeof(methods[0])) != JNI_OK) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -113,7 +113,7 @@ AndroidCamcorderProfile::AndroidCamcorderProfile(const QJNIObjectPrivate &camcor
|
||||
m_camcorderProfile = camcorderProfile;
|
||||
}
|
||||
|
||||
static jclass g_qtMediaRecorderListenerClass = 0;
|
||||
static const char QtMediaRecorderListenerClassName[] = "org/qtproject/qt5/android/multimedia/QtMediaRecorderListener";
|
||||
typedef QMap<jlong, AndroidMediaRecorder*> MediaRecorderMap;
|
||||
Q_GLOBAL_STATIC(MediaRecorderMap, mediaRecorders)
|
||||
|
||||
@@ -137,7 +137,7 @@ AndroidMediaRecorder::AndroidMediaRecorder()
|
||||
{
|
||||
m_mediaRecorder = QJNIObjectPrivate("android/media/MediaRecorder");
|
||||
if (m_mediaRecorder.isValid()) {
|
||||
QJNIObjectPrivate listener(g_qtMediaRecorderListenerClass, "(J)V", m_id);
|
||||
QJNIObjectPrivate listener(QtMediaRecorderListenerClassName, "(J)V", m_id);
|
||||
m_mediaRecorder.callMethod<void>("setOnErrorListener",
|
||||
"(Landroid/media/MediaRecorder$OnErrorListener;)V",
|
||||
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)
|
||||
{
|
||||
jclass clazz = env->FindClass("org/qtproject/qt5/android/multimedia/QtMediaRecorderListener");
|
||||
if (env->ExceptionCheck())
|
||||
env->ExceptionClear();
|
||||
jclass clazz = QJNIEnvironmentPrivate::findClass(QtMediaRecorderListenerClassName,
|
||||
env);
|
||||
|
||||
if (clazz) {
|
||||
g_qtMediaRecorderListenerClass = static_cast<jclass>(env->NewGlobalRef(clazz));
|
||||
if (env->RegisterNatives(g_qtMediaRecorderListenerClass,
|
||||
methods,
|
||||
sizeof(methods) / sizeof(methods[0])) < 0) {
|
||||
static const JNINativeMethod methods[] = {
|
||||
{"notifyError", "(JII)V", (void *)notifyError},
|
||||
{"notifyInfo", "(JII)V", (void *)notifyInfo}
|
||||
};
|
||||
|
||||
if (clazz && env->RegisterNatives(clazz,
|
||||
methods,
|
||||
sizeof(methods) / sizeof(methods[0])) != JNI_OK) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
static jclass g_qtSurfaceTextureListenerClass = 0;
|
||||
static const char QtSurfaceTextureListenerClassName[] = "org/qtproject/qt5/android/multimedia/QtSurfaceTextureListener";
|
||||
static QMap<int, AndroidSurfaceTexture*> g_objectMap;
|
||||
|
||||
// native method for QtSurfaceTexture.java
|
||||
@@ -70,7 +70,7 @@ AndroidSurfaceTexture::AndroidSurfaceTexture(unsigned int texName)
|
||||
if (m_surfaceTexture.isValid())
|
||||
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",
|
||||
"(Landroid/graphics/SurfaceTexture$OnFrameAvailableListener;)V",
|
||||
listener.object());
|
||||
@@ -144,27 +144,23 @@ jobject AndroidSurfaceTexture::surfaceHolder()
|
||||
return m_surfaceHolder.object();
|
||||
}
|
||||
|
||||
static JNINativeMethod methods[] = {
|
||||
{"notifyFrameAvailable", "(I)V", (void *)notifyFrameAvailable}
|
||||
};
|
||||
|
||||
bool AndroidSurfaceTexture::initJNI(JNIEnv *env)
|
||||
{
|
||||
// SurfaceTexture is available since API 11.
|
||||
if (QtAndroidPrivate::androidSdkVersion() < 11)
|
||||
return false;
|
||||
|
||||
jclass clazz = env->FindClass("org/qtproject/qt5/android/multimedia/QtSurfaceTextureListener");
|
||||
if (env->ExceptionCheck())
|
||||
env->ExceptionClear();
|
||||
jclass clazz = QJNIEnvironmentPrivate::findClass(QtSurfaceTextureListenerClassName,
|
||||
env);
|
||||
|
||||
if (clazz) {
|
||||
g_qtSurfaceTextureListenerClass = static_cast<jclass>(env->NewGlobalRef(clazz));
|
||||
if (env->RegisterNatives(g_qtSurfaceTextureListenerClass,
|
||||
methods,
|
||||
sizeof(methods) / sizeof(methods[0])) < 0) {
|
||||
return false;
|
||||
}
|
||||
static const JNINativeMethod methods[] = {
|
||||
{"notifyFrameAvailable", "(I)V", (void *)notifyFrameAvailable}
|
||||
};
|
||||
|
||||
if (clazz && env->RegisterNatives(clazz,
|
||||
methods,
|
||||
sizeof(methods) / sizeof(methods[0])) != JNI_OK) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user