[Android] Implement an event for LibVLC indicating VideoPlayerActivity was started

Felix Abecassis git at videolan.org
Mon Feb 24 18:59:11 CET 2014


vlc-ports/android | branch: master | Felix Abecassis <felix.abecassis at gmail.com> | Mon Feb 24 15:29:38 2014 +0100| [a71c0d3a2f5cc5be3cbb55661e968cb03a344321] | committer: Felix Abecassis

Implement an event for LibVLC indicating VideoPlayerActivity was started

This event is necessary in order to know if it is safe to use
MediaCodec opaque direct rendering. If VideoPlayerActivity is not
started, no surface will be attached to LibVLC and thus the decoder
will wait forever.

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=a71c0d3a2f5cc5be3cbb55661e968cb03a344321
---

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

diff --git a/vlc-android/jni/vout.c b/vlc-android/jni/vout.c
index eea4d9e..3fed2b9 100644
--- a/vlc-android/jni/vout.c
+++ b/vlc-android/jni/vout.c
@@ -32,6 +32,7 @@ static void *vout_android_surf = NULL;
 static void *vout_android_gui = NULL;
 static jobject vout_android_java_surf = NULL;
 static jobject vout_android_subtitles_surf = NULL;
+static bool vout_video_player_activity_created = false;
 
 void *jni_LockAndGetSubtitlesSurface() {
     pthread_mutex_lock(&vout_android_lock);
@@ -97,6 +98,19 @@ void jni_SetAndroidSurfaceSize(int width, int height, int visible_width, int vis
     (*myVm)->DetachCurrentThread (myVm);
 }
 
+bool jni_IsVideoPlayerActivityCreated() {
+    pthread_mutex_lock(&vout_android_lock);
+    bool result = vout_video_player_activity_created;
+    pthread_mutex_unlock(&vout_android_lock);
+    return result;
+}
+
+void Java_org_videolan_libvlc_LibVLC_eventVideoPlayerActivityCreated(JNIEnv *env, jobject thiz, jboolean created) {
+    pthread_mutex_lock(&vout_android_lock);
+    vout_video_player_activity_created = created;
+    pthread_mutex_unlock(&vout_android_lock);
+}
+
 void Java_org_videolan_libvlc_LibVLC_attachSurface(JNIEnv *env, jobject thiz, jobject surf, jobject gui) {
     pthread_mutex_lock(&vout_android_lock);
     jclass clz;
diff --git a/vlc-android/src/org/videolan/libvlc/LibVLC.java b/vlc-android/src/org/videolan/libvlc/LibVLC.java
index e5635e7..6238f01 100644
--- a/vlc-android/src/org/videolan/libvlc/LibVLC.java
+++ b/vlc-android/src/org/videolan/libvlc/LibVLC.java
@@ -84,6 +84,8 @@ public class LibVLC {
     public native void attachSubtitlesSurface(Surface surface);
     public native void detachSubtitlesSurface();
 
+    public native void eventVideoPlayerActivityCreated(boolean created);
+
     /* Load library before object instantiation */
     static {
         try {
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 385a501..305b3a8 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -335,6 +335,9 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
         /* Only show the subtitles surface when using "Full Acceleration" mode */
         if (mLibVLC.getHardwareAcceleration() == 2)
             mSubtitlesSurface.setVisibility(View.VISIBLE);
+        // Signal to LibVLC that the videoPlayerActivity was created, thus the
+        // SurfaceView is now available for MediaCodec direct rendering.
+        mLibVLC.eventVideoPlayerActivityCreated(true);
 
         EventHandler em = EventHandler.getInstance();
         em.addHandler(eventHandler);
@@ -457,6 +460,8 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
         EventHandler em = EventHandler.getInstance();
         em.removeHandler(eventHandler);
 
+        // MediaCodec opaque direct rendering should not be used anymore since there is no surface to attach.
+        mLibVLC.eventVideoPlayerActivityCreated(false);
         // HW acceleration was temporarily disabled because of an error, restore the previous value.
         if (mDisabledHardwareAcceleration)
             mLibVLC.setHardwareAcceleration(mPreviousHardwareAccelerationMode);



More information about the Android mailing list