[vlc-commits] mediacodec: use an helper for NewStringUTF

Thomas Guillem git at videolan.org
Thu Nov 12 10:54:06 CET 2015


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Thu Nov 12 10:45:26 2015 +0100| [1efc94f5b0304016637ea6672a91e927d4867f5b] | committer: Thomas Guillem

mediacodec: use an helper for NewStringUTF

Always check the return value of this helper.
This helper will aslo clear an exception if one occurs.

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

 modules/codec/omxil/mediacodec_jni.c |   43 ++++++++++++++++++++--------------
 1 file changed, 26 insertions(+), 17 deletions(-)

diff --git a/modules/codec/omxil/mediacodec_jni.c b/modules/codec/omxil/mediacodec_jni.c
index e245b3a..8c18461 100644
--- a/modules/codec/omxil/mediacodec_jni.c
+++ b/modules/codec/omxil/mediacodec_jni.c
@@ -167,10 +167,17 @@ static inline bool check_exception(JNIEnv *env)
 #define CHECK_EXCEPTION() check_exception( env )
 #define GET_ENV() if (!(env = android_getEnv(api->p_obj, THREAD_NAME))) return MC_API_ERROR;
 
+static inline jstring jni_new_string(JNIEnv *env, const char *psz_string)
+{
+    jstring jstring = (*env)->NewStringUTF(env, psz_string);
+    return !CHECK_EXCEPTION() ? jstring : NULL;
+}
+#define JNI_NEW_STRING(psz_string) jni_new_string(env, psz_string)
+
 static inline int get_integer(JNIEnv *env, jobject obj, const char *psz_name)
 {
-    jstring jname = (*env)->NewStringUTF(env, psz_name);
-    if (!CHECK_EXCEPTION() && jname)
+    jstring jname = JNI_NEW_STRING(psz_name);
+    if (jname)
     {
         int i_ret = (*env)->CallIntMethod(env, obj, jfields.get_integer, jname);
         (*env)->DeleteLocalRef(env, jname);
@@ -298,7 +305,7 @@ char* MediaCodec_GetName(vlc_object_t *p_obj, const char *psz_mime,
     if (!InitJNIFields(p_obj, env))
         return NULL;
 
-    jmime = (*env)->NewStringUTF(env, psz_mime);
+    jmime = JNI_NEW_STRING(psz_mime);
     if (!jmime)
         return NULL;
 
@@ -477,8 +484,6 @@ static int Start(mc_api *api, union mc_api_args *p_args)
     jstring jcodec_name = NULL;
     jobject jcodec = NULL;
     jobject jformat = NULL;
-    jstring jrotation_string = NULL;
-    jstring jmaxinputsize_string = NULL;
     jobject jinput_buffers = NULL;
     jobject joutput_buffers = NULL;
     jobject jbuffer_info = NULL;
@@ -486,8 +491,8 @@ static int Start(mc_api *api, union mc_api_args *p_args)
 
     GET_ENV();
 
-    jmime = (*env)->NewStringUTF(env, api->psz_mime);
-    jcodec_name = (*env)->NewStringUTF(env, api->psz_name);
+    jmime = JNI_NEW_STRING(api->psz_mime);
+    jcodec_name = JNI_NEW_STRING(api->psz_name);
     if (!jmime || !jcodec_name)
         goto error;
 
@@ -528,9 +533,13 @@ static int Start(mc_api *api, union mc_api_args *p_args)
 
         if (b_direct_rendering && p_args->video.i_angle != 0)
         {
-            jrotation_string = (*env)->NewStringUTF(env, "rotation-degrees");
-            (*env)->CallVoidMethod(env, jformat, jfields.set_integer,
-                                   jrotation_string, p_args->video.i_angle);
+            jstring jrotation_string = JNI_NEW_STRING("rotation-degrees");
+            if (jrotation_string)
+            {
+                (*env)->CallVoidMethod(env, jformat, jfields.set_integer,
+                                       jrotation_string, p_args->video.i_angle);
+                (*env)->DeleteLocalRef(env, jrotation_string);
+            }
         }
     }
     else
@@ -543,9 +552,13 @@ static int Start(mc_api *api, union mc_api_args *p_args)
                                                  p_args->audio.i_channel_count);
     }
     /* No limits for input size */
-    jmaxinputsize_string = (*env)->NewStringUTF(env, "max-input-size");
-    (*env)->CallVoidMethod(env, jformat, jfields.set_integer,
-                           jmaxinputsize_string, 0);
+    jstring jmaxinputsize_string = JNI_NEW_STRING("max-input-size");
+    if (jmaxinputsize_string)
+    {
+        (*env)->CallVoidMethod(env, jformat, jfields.set_integer,
+                               jmaxinputsize_string, 0);
+        (*env)->DeleteLocalRef(env, jmaxinputsize_string);
+    }
 
     if (b_direct_rendering)
     {
@@ -616,10 +629,6 @@ error:
         (*env)->DeleteLocalRef(env, jcodec);
     if (jformat)
         (*env)->DeleteLocalRef(env, jformat);
-    if (jrotation_string)
-        (*env)->DeleteLocalRef(env, jrotation_string);
-    if (jmaxinputsize_string)
-        (*env)->DeleteLocalRef(env, jmaxinputsize_string);
     if (jinput_buffers)
         (*env)->DeleteLocalRef(env, jinput_buffers);
     if (joutput_buffers)



More information about the vlc-commits mailing list