[Android] [PATCH 1/2] jni: pass the surface frame to the attachSurface function.

Felix Abecassis felix.abecassis at gmail.com
Tue Jan 7 16:27:49 CET 2014


---
 vlc-android/jni/vout.c                               | 20 +++++++++++++++++++-
 vlc-android/src/org/videolan/libvlc/LibVLC.java      |  3 ++-
 .../videolan/vlc/gui/video/VideoPlayerActivity.java  |  2 +-
 3 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/vlc-android/jni/vout.c b/vlc-android/jni/vout.c
index a5ac276..51eace1 100644
--- a/vlc-android/jni/vout.c
+++ b/vlc-android/jni/vout.c
@@ -31,6 +31,7 @@ pthread_cond_t vout_android_surf_attached;
 static void *vout_android_surf = NULL;
 static void *vout_android_gui = NULL;
 static jobject vout_android_java_surf = NULL;
+static jobject vout_android_frame = NULL;
 
 void *jni_LockAndGetAndroidSurface() {
     pthread_mutex_lock(&vout_android_lock);
@@ -67,7 +68,7 @@ void jni_SetAndroidSurfaceSize(int width, int height, int visible_width, int vis
     (*myVm)->DetachCurrentThread (myVm);
 }
 
-void Java_org_videolan_libvlc_LibVLC_attachSurface(JNIEnv *env, jobject thiz, jobject surf, jobject gui) {
+void Java_org_videolan_libvlc_LibVLC_attachSurface(JNIEnv *env, jobject thiz, jobject surf, jobject frame, jobject gui) {
     pthread_mutex_lock(&vout_android_lock);
     jclass clz;
     jfieldID fid;
@@ -92,6 +93,7 @@ void Java_org_videolan_libvlc_LibVLC_attachSurface(JNIEnv *env, jobject thiz, jo
     }
     vout_android_gui = (*env)->NewGlobalRef(env, gui);
     vout_android_java_surf = (*env)->NewGlobalRef(env, surf);
+    vout_android_frame = (*env)->NewGlobalRef(env, frame);
     pthread_cond_signal(&vout_android_surf_attached);
     pthread_mutex_unlock(&vout_android_lock);
 }
@@ -107,3 +109,19 @@ void Java_org_videolan_libvlc_LibVLC_detachSurface(JNIEnv *env, jobject thiz) {
     vout_android_java_surf = NULL;
     pthread_mutex_unlock(&vout_android_lock);
 }
+
+void jni_GetFrameDimensions(int *width, int *height)
+{
+    JNIEnv *env;
+    (*myVm)->AttachCurrentThread(myVm, &env, NULL);
+
+    jclass cls = (*env)->GetObjectClass(env, vout_android_frame);
+    jmethodID getWidth = (*env)->GetMethodID(env, cls, "getWidth", "()I");
+    jmethodID getHeight = (*env)->GetMethodID(env, cls, "getHeight", "()I");
+    if (width)
+        *width = (*env)->CallIntMethod(env, vout_android_frame, getWidth);
+    if (height)
+        *height = (*env)->CallIntMethod(env, vout_android_frame, getHeight);
+
+    (*myVm)->DetachCurrentThread(myVm);
+}
diff --git a/vlc-android/src/org/videolan/libvlc/LibVLC.java b/vlc-android/src/org/videolan/libvlc/LibVLC.java
index 49aa22a..b42c1f1 100644
--- a/vlc-android/src/org/videolan/libvlc/LibVLC.java
+++ b/vlc-android/src/org/videolan/libvlc/LibVLC.java
@@ -27,6 +27,7 @@ import android.content.Context;
 import android.os.Build;
 import android.util.Log;
 import android.view.Surface;
+import android.widget.FrameLayout;
 
 public class LibVLC {
     private static final String TAG = "VLC/LibVLC";
@@ -72,7 +73,7 @@ public class LibVLC {
 
     /** Check in libVLC already initialized otherwise crash */
     private boolean mIsInitialized = false;
-    public native void attachSurface(Surface surface, IVideoPlayer player);
+    public native void attachSurface(Surface surface, FrameLayout SurfaceFrame, IVideoPlayer player);
 
     public native void detachSurface();
 
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
index ab79877..6ed633a 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -1301,7 +1301,7 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
                 Log.d(TAG, "Pixel format is YV12");
             else
                 Log.d(TAG, "Pixel format is other/unknown");
-            mLibVLC.attachSurface(holder.getSurface(), VideoPlayerActivity.this);
+            mLibVLC.attachSurface(holder.getSurface(), mSurfaceFrame, VideoPlayerActivity.this);
         }
 
         @Override
-- 
1.8.3.2



More information about the Android mailing list