Commit a71c0d3a authored by Felix Abecassis's avatar 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.
parent b2f09c84
......@@ -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;
......
......@@ -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 {
......
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment