diff options
author | Yoann Lopes <yoann.lopes@theqtcompany.com> | 2015-08-24 14:31:24 +0200 |
---|---|---|
committer | Yoann Lopes <yoann.lopes@theqtcompany.com> | 2015-08-24 14:36:13 +0200 |
commit | a2244c9b7aa11e386c3331cbbc36336fb8fea3b9 (patch) | |
tree | a77ac99aa38c40e98aa483795e3cb8061f404203 /src/plugins/android/src/wrappers | |
parent | 31fce88b3fcdbb4d4b2b9a889d24e25c3a5c9507 (diff) | |
parent | 008d20e0ece4c6dac148915b998a0005657d73a1 (diff) |
Merge remote-tracking branch 'origin/5.5' into 5.6
Conflicts:
src/imports/multimedia/qdeclarativeaudio.cpp
Change-Id: I57c6252b084e4ed796f6f308b2e0c717d0f59b13
Diffstat (limited to 'src/plugins/android/src/wrappers')
-rw-r--r-- | src/plugins/android/src/wrappers/jni/androidcamera.cpp | 57 | ||||
-rw-r--r-- | src/plugins/android/src/wrappers/jni/androidcamera.h | 7 |
2 files changed, 34 insertions, 30 deletions
diff --git a/src/plugins/android/src/wrappers/jni/androidcamera.cpp b/src/plugins/android/src/wrappers/jni/androidcamera.cpp index 7496e9cdc..a4acbd8f9 100644 --- a/src/plugins/android/src/wrappers/jni/androidcamera.cpp +++ b/src/plugins/android/src/wrappers/jni/androidcamera.cpp @@ -114,7 +114,7 @@ static void notifyPictureCaptured(JNIEnv *env, jobject, int id, jbyteArray data) } } -static void notifyFrameFetched(JNIEnv *env, jobject, int id, jbyteArray data) +static void notifyNewPreviewFrame(JNIEnv *env, jobject, int id, jbyteArray data, int width, int height) { QMutexLocker locker(&g_cameraMapMutex); AndroidCamera *obj = g_cameraMap->value(id, 0); @@ -123,7 +123,7 @@ static void notifyFrameFetched(JNIEnv *env, jobject, int id, jbyteArray data) QByteArray bytes(arrayLength, Qt::Uninitialized); env->GetByteArrayRegion(data, 0, arrayLength, (jbyte*)bytes.data()); - Q_EMIT obj->frameFetched(bytes); + Q_EMIT obj->newPreviewFrame(bytes, width, height); } } @@ -204,7 +204,8 @@ public: Q_INVOKABLE void takePicture(); - Q_INVOKABLE void fetchEachFrame(bool fetch); + Q_INVOKABLE void setupPreviewFrameCallback(); + Q_INVOKABLE void notifyNewFrames(bool notify); Q_INVOKABLE void fetchLastPreviewFrame(); Q_INVOKABLE void applyParameters(); @@ -229,7 +230,7 @@ Q_SIGNALS: void whiteBalanceChanged(); - void previewFetched(const QByteArray &preview); + void lastPreviewFrameFetched(const QByteArray &preview, int width, int height); }; AndroidCamera::AndroidCamera(AndroidCameraPrivate *d, QThread *worker) @@ -247,7 +248,7 @@ AndroidCamera::AndroidCamera(AndroidCameraPrivate *d, QThread *worker) connect(d, &AndroidCameraPrivate::previewStopped, this, &AndroidCamera::previewStopped); connect(d, &AndroidCameraPrivate::autoFocusStarted, this, &AndroidCamera::autoFocusStarted); connect(d, &AndroidCameraPrivate::whiteBalanceChanged, this, &AndroidCamera::whiteBalanceChanged); - connect(d, &AndroidCameraPrivate::previewFetched, this, &AndroidCamera::previewFetched); + connect(d, &AndroidCameraPrivate::lastPreviewFrameFetched, this, &AndroidCamera::lastPreviewFrameFetched); } AndroidCamera::~AndroidCamera() @@ -633,10 +634,16 @@ void AndroidCamera::takePicture() QMetaObject::invokeMethod(d, "takePicture", Qt::BlockingQueuedConnection); } -void AndroidCamera::fetchEachFrame(bool fetch) +void AndroidCamera::setupPreviewFrameCallback() { Q_D(AndroidCamera); - QMetaObject::invokeMethod(d, "fetchEachFrame", Q_ARG(bool, fetch)); + QMetaObject::invokeMethod(d, "setupPreviewFrameCallback"); +} + +void AndroidCamera::notifyNewFrames(bool notify) +{ + Q_D(AndroidCamera); + QMetaObject::invokeMethod(d, "notifyNewFrames", Q_ARG(bool, notify)); } void AndroidCamera::fetchLastPreviewFrame() @@ -1307,17 +1314,7 @@ void AndroidCameraPrivate::setJpegQuality(int quality) void AndroidCameraPrivate::startPreview() { - //We need to clear preview buffers queue here, but there is no method to do it - //Though just resetting preview callback do the trick - m_camera.callMethod<void>("setPreviewCallbackWithBuffer", - "(Landroid/hardware/Camera$PreviewCallback;)V", - jobject(0)); - m_cameraListener.callMethod<void>("preparePreviewBuffer", "(Landroid/hardware/Camera;)V", m_camera.object()); - QJNIObjectPrivate buffer = m_cameraListener.callObjectMethod<jbyteArray>("callbackBuffer"); - m_camera.callMethod<void>("addCallbackBuffer", "([B)V", buffer.object()); - m_camera.callMethod<void>("setPreviewCallbackWithBuffer", - "(Landroid/hardware/Camera$PreviewCallback;)V", - m_cameraListener.object()); + setupPreviewFrameCallback(); m_camera.callMethod<void>("startPreview"); emit previewStarted(); } @@ -1338,28 +1335,34 @@ void AndroidCameraPrivate::takePicture() m_cameraListener.object()); } -void AndroidCameraPrivate::fetchEachFrame(bool fetch) +void AndroidCameraPrivate::setupPreviewFrameCallback() { - m_cameraListener.callMethod<void>("fetchEachFrame", "(Z)V", fetch); + m_cameraListener.callMethod<void>("setupPreviewCallback", "(Landroid/hardware/Camera;)V", m_camera.object()); +} + +void AndroidCameraPrivate::notifyNewFrames(bool notify) +{ + m_cameraListener.callMethod<void>("notifyNewFrames", "(Z)V", notify); } void AndroidCameraPrivate::fetchLastPreviewFrame() { QJNIEnvironmentPrivate env; - QJNIObjectPrivate data = m_cameraListener.callObjectMethod("lockAndFetchPreviewBuffer", "()[B"); - if (!data.isValid()) { - m_cameraListener.callMethod<void>("unlockPreviewBuffer"); + QJNIObjectPrivate data = m_cameraListener.callObjectMethod("lastPreviewBuffer", "()[B"); + + if (!data.isValid()) return; - } + const int arrayLength = env->GetArrayLength(static_cast<jbyteArray>(data.object())); QByteArray bytes(arrayLength, Qt::Uninitialized); env->GetByteArrayRegion(static_cast<jbyteArray>(data.object()), 0, arrayLength, reinterpret_cast<jbyte *>(bytes.data())); - m_cameraListener.callMethod<void>("unlockPreviewBuffer"); - emit previewFetched(bytes); + emit lastPreviewFrameFetched(bytes, + m_cameraListener.callMethod<jint>("previewWidth"), + m_cameraListener.callMethod<jint>("previewHeight")); } void AndroidCameraPrivate::applyParameters() @@ -1404,7 +1407,7 @@ bool AndroidCamera::initJNI(JNIEnv *env) {"notifyAutoFocusComplete", "(IZ)V", (void *)notifyAutoFocusComplete}, {"notifyPictureExposed", "(I)V", (void *)notifyPictureExposed}, {"notifyPictureCaptured", "(I[B)V", (void *)notifyPictureCaptured}, - {"notifyFrameFetched", "(I[B)V", (void *)notifyFrameFetched} + {"notifyNewPreviewFrame", "(I[BII)V", (void *)notifyNewPreviewFrame} }; if (clazz && env->RegisterNatives(clazz, diff --git a/src/plugins/android/src/wrappers/jni/androidcamera.h b/src/plugins/android/src/wrappers/jni/androidcamera.h index a14b77c7f..7a8ae8b23 100644 --- a/src/plugins/android/src/wrappers/jni/androidcamera.h +++ b/src/plugins/android/src/wrappers/jni/androidcamera.h @@ -155,7 +155,8 @@ public: void takePicture(); - void fetchEachFrame(bool fetch); + void setupPreviewFrameCallback(); + void notifyNewFrames(bool notify); void fetchLastPreviewFrame(); QJNIObjectPrivate getCameraObject(); @@ -176,8 +177,8 @@ Q_SIGNALS: void pictureExposed(); void pictureCaptured(const QByteArray &data); - void previewFetched(const QByteArray &preview); - void frameFetched(const QByteArray &frame); + void lastPreviewFrameFetched(const QByteArray &preview, int width, int height); + void newPreviewFrame(const QByteArray &frame, int width, int height); private: AndroidCamera(AndroidCameraPrivate *d, QThread *worker); |