Commit 1efc94f5 authored by Thomas Guillem's avatar 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.
parent 08916947
......@@ -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)
......
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