[vlc-commits] android/utils: remove AWindowHandler_releaseSurface

Thomas Guillem git at videolan.org
Wed Oct 5 12:16:25 CEST 2016


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Wed Oct  5 11:43:47 2016 +0200| [64252ac8e4d15b61835405bf8b95c5ad72123181] | committer: Thomas Guillem

android/utils: remove AWindowHandler_releaseSurface

AWindowHandler_releaseANativeWindow should be used instead.

AWindowHandler_getSurface and AWindowHandler_getANativeWindow do the same
initialisation now.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=64252ac8e4d15b61835405bf8b95c5ad72123181
---

 modules/codec/omxil/mediacodec.c     |  2 +-
 modules/video_output/android/utils.c | 77 +++++++++++++++++-------------------
 modules/video_output/android/utils.h |  5 +--
 3 files changed, 40 insertions(+), 44 deletions(-)

diff --git a/modules/codec/omxil/mediacodec.c b/modules/codec/omxil/mediacodec.c
index 250f063..6f291b6 100644
--- a/modules/codec/omxil/mediacodec.c
+++ b/modules/codec/omxil/mediacodec.c
@@ -577,7 +577,7 @@ static void StopMediaCodec(decoder_t *p_dec)
 
     p_sys->api->stop(p_sys->api);
     if (p_dec->fmt_in.i_cat == VIDEO_ES && p_sys->u.video.p_awh)
-        AWindowHandler_releaseSurface(p_sys->u.video.p_awh, AWindow_Video);
+        AWindowHandler_releaseANativeWindow(p_sys->u.video.p_awh, AWindow_Video);
 }
 
 /*****************************************************************************
diff --git a/modules/video_output/android/utils.c b/modules/video_output/android/utils.c
index 09907b5..7c0c05a 100644
--- a/modules/video_output/android/utils.c
+++ b/modules/video_output/android/utils.c
@@ -503,10 +503,17 @@ AWindowHandler_new(vlc_object_t *p_obj)
 }
 
 static void
-AWindowHandler_releaseSurfaceEnv(AWindowHandler *p_awh, JNIEnv *p_env,
-                                 enum AWindow_ID id)
+AWindowHandler_releaseANativeWindowEnv(AWindowHandler *p_awh, JNIEnv *p_env,
+                                       enum AWindow_ID id)
 {
-    AWindowHandler_releaseANativeWindow(p_awh, id);
+    assert(id < AWindow_Max);
+
+    if (p_awh->views[id].p_anw)
+    {
+        p_awh->pf_winRelease(p_awh->views[id].p_anw);
+        p_awh->views[id].p_anw = NULL;
+    }
+
     if (p_awh->views[id].jsurface)
     {
         (*p_env)->DeleteGlobalRef(p_env, p_awh->views[id].jsurface);
@@ -523,8 +530,8 @@ AWindowHandler_destroy(AWindowHandler *p_awh)
     {
         if (p_awh->event.b_registered)
             JNI_CALL(CallBooleanMethod, setCallback, (jlong)0LL);
-        AWindowHandler_releaseSurfaceEnv(p_awh, p_env, AWindow_Video);
-        AWindowHandler_releaseSurfaceEnv(p_awh, p_env, AWindow_Subtitles);
+        AWindowHandler_releaseANativeWindowEnv(p_awh, p_env, AWindow_Video);
+        AWindowHandler_releaseANativeWindowEnv(p_awh, p_env, AWindow_Subtitles);
         (*p_env)->DeleteGlobalRef(p_env, p_awh->jobj);
     }
 
@@ -551,41 +558,22 @@ AWindowHandler_getANativeWindowPrivAPI(AWindowHandler *p_awh)
         return &p_awh->anwpriv_api;
 }
 
-jobject
-AWindowHandler_getSurface(AWindowHandler *p_awh, enum AWindow_ID id)
+static int
+WindowHandler_NewSurfaceEnv(AWindowHandler *p_awh, JNIEnv *p_env,
+                            enum AWindow_ID id)
 {
-    assert(id < AWindow_Max);
-
     jobject jsurface;
-    JNIEnv *p_env;
-
-    if (p_awh->views[id].jsurface)
-        return p_awh->views[id].jsurface;
-
-    p_env = AWindowHandler_getEnv(p_awh);
-    if (!p_env)
-        return NULL;
 
     if (id == AWindow_Video)
         jsurface = JNI_CALL(CallObjectMethod, getVideoSurface);
     else
         jsurface = JNI_CALL(CallObjectMethod, getSubtitlesSurface);
     if (!jsurface)
-        return NULL;
+        return VLC_EGENERIC;
 
     p_awh->views[id].jsurface = (*p_env)->NewGlobalRef(p_env, jsurface);
     (*p_env)->DeleteLocalRef(p_env, jsurface);
-    return p_awh->views[id].jsurface;
-}
-
-void
-AWindowHandler_releaseSurface(AWindowHandler *p_awh, enum AWindow_ID id)
-{
-    assert(id < AWindow_Max);
-
-    JNIEnv *p_env = AWindowHandler_getEnv(p_awh);
-    if (p_env)
-        AWindowHandler_releaseSurfaceEnv(p_awh, p_env, id);
+    return VLC_SUCCESS;
 }
 
 ANativeWindow *
@@ -593,7 +581,6 @@ AWindowHandler_getANativeWindow(AWindowHandler *p_awh, enum AWindow_ID id)
 {
     assert(id < AWindow_Max);
 
-    jobject jsurf;
     JNIEnv *p_env;
 
     if (p_awh->views[id].p_anw)
@@ -603,24 +590,34 @@ AWindowHandler_getANativeWindow(AWindowHandler *p_awh, enum AWindow_ID id)
     if (!p_env)
         return NULL;
 
-    jsurf = AWindowHandler_getSurface(p_awh, id);
-    if (!jsurf)
+    if (WindowHandler_NewSurfaceEnv(p_awh, p_env, id) != VLC_SUCCESS)
         return NULL;
+    assert(p_awh->views[id].jsurface != NULL);
 
-    p_awh->views[id].p_anw = p_awh->pf_winFromSurface(p_env, jsurf);
+    p_awh->views[id].p_anw = p_awh->pf_winFromSurface(p_env,
+                                                      p_awh->views[id].jsurface);
     return p_awh->views[id].p_anw;
 }
 
-void AWindowHandler_releaseANativeWindow(AWindowHandler *p_awh,
-                                         enum AWindow_ID id)
+jobject
+AWindowHandler_getSurface(AWindowHandler *p_awh, enum AWindow_ID id)
 {
     assert(id < AWindow_Max);
 
-    if (p_awh->views[id].p_anw)
-    {
-        p_awh->pf_winRelease(p_awh->views[id].p_anw);
-        p_awh->views[id].p_anw = NULL;
-    }
+    if (p_awh->views[id].jsurface)
+        return p_awh->views[id].jsurface;
+
+    AWindowHandler_getANativeWindow(p_awh, id);
+    return p_awh->views[id].jsurface;
+}
+
+
+void AWindowHandler_releaseANativeWindow(AWindowHandler *p_awh,
+                                         enum AWindow_ID id)
+{
+    JNIEnv *p_env = AWindowHandler_getEnv(p_awh);
+    if (p_env)
+        AWindowHandler_releaseANativeWindowEnv(p_awh, p_env, id);
 }
 
 static inline AWindowHandler *jlong_AWindowHandler(jlong handle)
diff --git a/modules/video_output/android/utils.h b/modules/video_output/android/utils.h
index 956f5e2..5adacd6 100644
--- a/modules/video_output/android/utils.h
+++ b/modules/video_output/android/utils.h
@@ -139,11 +139,10 @@ bool AWindowHandler_getWindowSize(AWindowHandler *p_awh,
 
 /**
  * This function returns the Video or the Subtitles Android Surface attached to
- * the MediaPlayer. It can be released with AWindowHandler_releaseSurface or by
- * AWindowHandler_destroy.
+ * the MediaPlayer. It can be released with AWindowHandler_releaseANativeWindow
+ * or by AWindowHandler_destroy.
  */
 jobject AWindowHandler_getSurface(AWindowHandler *p_awh, enum AWindow_ID id);
-void AWindowHandler_releaseSurface(AWindowHandler *p_awh, enum AWindow_ID id);
 
 /**
  * This function returns the Video or the Subtitles ANativeWindow attached to



More information about the vlc-commits mailing list