vlc | branch: master | Adrien Maglo <mags...@videolan.org> | Wed Apr 30 
12:44:04 2014 +0200| [9d567fd0dfa3ee39b371092c6119339e5b613aea] | committer: 
Adrien Maglo

mediacodec: check exceptions after createByCodecName()

Release MediaCodec only if the codec has been successfully created.
This might avoid some crashes.

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

 modules/codec/omxil/android_mediacodec.c |   10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/modules/codec/omxil/android_mediacodec.c 
b/modules/codec/omxil/android_mediacodec.c
index ba70fdc..2d912d0 100644
--- a/modules/codec/omxil/android_mediacodec.c
+++ b/modules/codec/omxil/android_mediacodec.c
@@ -155,6 +155,7 @@ struct decoder_sys_t
     int crop_top, crop_left;
     char *name;
 
+    bool allocated;
     bool started;
     bool decoded;
     bool error_state;
@@ -451,6 +452,12 @@ static int OpenDecoder(vlc_object_t *p_this)
     // but not in 4.1 devices.
     p_sys->codec = (*env)->CallStaticObjectMethod(env, 
p_sys->media_codec_class,
                                                   p_sys->create_by_codec_name, 
codec_name);
+    if ((*env)->ExceptionOccurred(env)) {
+        msg_Warn(p_dec, "Exception occurred in MediaCodec.createByCodecName.");
+        (*env)->ExceptionClear(env);
+        goto error;
+    }
+    p_sys->allocated = true;
     p_sys->codec = (*env)->NewGlobalRef(env, p_sys->codec);
 
     jobject format = (*env)->CallStaticObjectMethod(env, 
p_sys->media_format_class,
@@ -566,7 +573,8 @@ static void CloseDecoder(vlc_object_t *p_this)
     if (p_sys->codec) {
         if (p_sys->started)
             (*env)->CallVoidMethod(env, p_sys->codec, p_sys->stop);
-        (*env)->CallVoidMethod(env, p_sys->codec, p_sys->release);
+        if (p_sys->allocated)
+            (*env)->CallVoidMethod(env, p_sys->codec, p_sys->release);
         (*env)->DeleteGlobalRef(env, p_sys->codec);
     }
     if (p_sys->buffer_info)

_______________________________________________
vlc-commits mailing list
vlc-commits@videolan.org
https://mailman.videolan.org/listinfo/vlc-commits

Reply via email to