[Android] [PATCH] Implement an event for LibVLC indicating VideoPlayerActivity was started
Felix Abecassis
felix.abecassis at gmail.com
Mon Feb 24 15:36:28 CET 2014
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.
---
vlc-android/jni/vout.c | 20 ++++++++++++++++++++
vlc-android/src/org/videolan/libvlc/LibVLC.java | 3 +++
.../videolan/vlc/gui/video/VideoPlayerActivity.java | 5 +++++
3 files changed, 28 insertions(+)
diff --git a/vlc-android/jni/vout.c b/vlc-android/jni/vout.c
index eea4d9e..453f02b 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,25 @@ 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) {
+ pthread_mutex_lock(&vout_android_lock);
+ vout_video_player_activity_created = true;
+ pthread_mutex_unlock(&vout_android_lock);
+}
+
+void Java_org_videolan_libvlc_LibVLC_eventVideoPlayerActivityDestroyed(JNIEnv *env) {
+ pthread_mutex_lock(&vout_android_lock);
+ vout_video_player_activity_created = false;
+ 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..2dd6512 100644
--- a/vlc-android/src/org/videolan/libvlc/LibVLC.java
+++ b/vlc-android/src/org/videolan/libvlc/LibVLC.java
@@ -84,6 +84,9 @@ public class LibVLC {
public native void attachSubtitlesSurface(Surface surface);
public native void detachSubtitlesSurface();
+ public native void eventVideoPlayerActivityCreated();
+ public native void eventVideoPlayerActivityDestroyed();
+
/* 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..265b6cc 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();
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.eventVideoPlayerActivityDestroyed();
// HW acceleration was temporarily disabled because of an error, restore the previous value.
if (mDisabledHardwareAcceleration)
mLibVLC.setHardwareAcceleration(mPreviousHardwareAccelerationMode);
--
1.8.3.2
More information about the Android
mailing list