diff options
Diffstat (limited to 'src/plugins/android/src/wrappers')
6 files changed, 62 insertions, 11 deletions
diff --git a/src/plugins/android/src/wrappers/jni/androidcamera.cpp b/src/plugins/android/src/wrappers/jni/androidcamera.cpp index 083803e38..b506f4fd4 100644 --- a/src/plugins/android/src/wrappers/jni/androidcamera.cpp +++ b/src/plugins/android/src/wrappers/jni/androidcamera.cpp @@ -744,6 +744,12 @@ void AndroidCamera::stopPreview() QMetaObject::invokeMethod(d, "stopPreview"); } +void AndroidCamera::stopPreviewSynchronous() +{ + Q_D(AndroidCamera); + QMetaObject::invokeMethod(d, "stopPreview", Qt::BlockingQueuedConnection); +} + AndroidCameraPrivate::AndroidCameraPrivate() : QObject(), m_parametersMutex(QMutex::Recursive) diff --git a/src/plugins/android/src/wrappers/jni/androidcamera.h b/src/plugins/android/src/wrappers/jni/androidcamera.h index 9e4c387c4..cefc1008c 100644 --- a/src/plugins/android/src/wrappers/jni/androidcamera.h +++ b/src/plugins/android/src/wrappers/jni/androidcamera.h @@ -155,6 +155,7 @@ public: void startPreview(); void stopPreview(); + void stopPreviewSynchronous(); void takePicture(); diff --git a/src/plugins/android/src/wrappers/jni/androidmediarecorder.cpp b/src/plugins/android/src/wrappers/jni/androidmediarecorder.cpp index fa32f31ef..34063056f 100644 --- a/src/plugins/android/src/wrappers/jni/androidmediarecorder.cpp +++ b/src/plugins/android/src/wrappers/jni/androidmediarecorder.cpp @@ -34,6 +34,8 @@ #include "androidmediarecorder.h" #include "androidcamera.h" +#include "androidsurfacetexture.h" +#include "androidsurfaceview.h" #include <QtCore/private/qjni_p.h> #include <qmap.h> @@ -339,6 +341,41 @@ void AndroidMediaRecorder::setOutputFile(const QString &path) } } +void AndroidMediaRecorder::setSurfaceTexture(AndroidSurfaceTexture *texture) +{ + QJNIEnvironmentPrivate env; + m_mediaRecorder.callMethod<void>("setPreviewDisplay", + "(Landroid/view/Surface;)V", + texture->surface()); + if (env->ExceptionCheck()) { +#ifdef QT_DEBUG + env->ExceptionDescribe(); +#endif + env->ExceptionClear(); + } +} + +void AndroidMediaRecorder::setSurfaceHolder(AndroidSurfaceHolder *holder) +{ + QJNIEnvironmentPrivate env; + QJNIObjectPrivate surfaceHolder(holder->surfaceHolder()); + QJNIObjectPrivate surface = surfaceHolder.callObjectMethod("getSurface", + "()Landroid/view/Surface;"); + if (!surface.isValid()) + return; + + m_mediaRecorder.callMethod<void>("setPreviewDisplay", + "(Landroid/view/Surface;)V", + surface.object()); + if (env->ExceptionCheck()) { +#ifdef QT_DEBUG + env->ExceptionDescribe(); +#endif + env->ExceptionClear(); + } +} + + bool AndroidMediaRecorder::initJNI(JNIEnv *env) { jclass clazz = QJNIEnvironmentPrivate::findClass(QtMediaRecorderListenerClassName, diff --git a/src/plugins/android/src/wrappers/jni/androidmediarecorder.h b/src/plugins/android/src/wrappers/jni/androidmediarecorder.h index 1aa83a201..95b48ed47 100644 --- a/src/plugins/android/src/wrappers/jni/androidmediarecorder.h +++ b/src/plugins/android/src/wrappers/jni/androidmediarecorder.h @@ -41,6 +41,8 @@ QT_BEGIN_NAMESPACE class AndroidCamera; +class AndroidSurfaceTexture; +class AndroidSurfaceHolder; class AndroidCamcorderProfile { @@ -149,6 +151,9 @@ public: void setOutputFormat(OutputFormat format); void setOutputFile(const QString &path); + void setSurfaceTexture(AndroidSurfaceTexture *texture); + void setSurfaceHolder(AndroidSurfaceHolder *holder); + static bool initJNI(JNIEnv *env); Q_SIGNALS: diff --git a/src/plugins/android/src/wrappers/jni/androidsurfacetexture.cpp b/src/plugins/android/src/wrappers/jni/androidsurfacetexture.cpp index ffa37d7d4..9a25b7e28 100644 --- a/src/plugins/android/src/wrappers/jni/androidsurfacetexture.cpp +++ b/src/plugins/android/src/wrappers/jni/androidsurfacetexture.cpp @@ -78,8 +78,8 @@ AndroidSurfaceTexture::AndroidSurfaceTexture(unsigned int texName) AndroidSurfaceTexture::~AndroidSurfaceTexture() { - if (QtAndroidPrivate::androidSdkVersion() > 13 && m_surfaceView.isValid()) - m_surfaceView.callMethod<void>("release"); + if (QtAndroidPrivate::androidSdkVersion() > 13 && m_surface.isValid()) + m_surface.callMethod<void>("release"); if (m_surfaceTexture.isValid()) { release(); @@ -124,21 +124,23 @@ jobject AndroidSurfaceTexture::surfaceTexture() return m_surfaceTexture.object(); } -jobject AndroidSurfaceTexture::surfaceView() +jobject AndroidSurfaceTexture::surface() { - return m_surfaceView.object(); + if (!m_surface.isValid()) { + m_surface = QJNIObjectPrivate("android/view/Surface", + "(Landroid/graphics/SurfaceTexture;)V", + m_surfaceTexture.object()); + } + + return m_surface.object(); } jobject AndroidSurfaceTexture::surfaceHolder() { if (!m_surfaceHolder.isValid()) { - m_surfaceView = QJNIObjectPrivate("android/view/Surface", - "(Landroid/graphics/SurfaceTexture;)V", - m_surfaceTexture.object()); - m_surfaceHolder = QJNIObjectPrivate("org/qtproject/qt5/android/multimedia/QtSurfaceTextureHolder", "(Landroid/view/Surface;)V", - m_surfaceView.object()); + surface()); } return m_surfaceHolder.object(); diff --git a/src/plugins/android/src/wrappers/jni/androidsurfacetexture.h b/src/plugins/android/src/wrappers/jni/androidsurfacetexture.h index 2618ed6c9..ac2af694e 100644 --- a/src/plugins/android/src/wrappers/jni/androidsurfacetexture.h +++ b/src/plugins/android/src/wrappers/jni/androidsurfacetexture.h @@ -50,7 +50,7 @@ public: int textureID() const { return m_texID; } jobject surfaceTexture(); - jobject surfaceView(); + jobject surface(); jobject surfaceHolder(); inline bool isValid() const { return m_surfaceTexture.isValid(); } @@ -66,7 +66,7 @@ Q_SIGNALS: private: int m_texID; QJNIObjectPrivate m_surfaceTexture; - QJNIObjectPrivate m_surfaceView; + QJNIObjectPrivate m_surface; QJNIObjectPrivate m_surfaceHolder; }; |