[vlc-devel] [PATCH] mediacodec: don't wait indefinitely for data

Thomas Guillem thomas at gllm.fr
Tue Mar 31 10:22:48 CEST 2015


The decoder can be in a bad state without throwing any exception.

Issue seen with a MPEG4 sample on a Tegra 3 and Tegra K1 tablet but may happens
on others devices/samples.
---
 modules/codec/omxil/android_mediacodec.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/modules/codec/omxil/android_mediacodec.c b/modules/codec/omxil/android_mediacodec.c
index be2e196..7c48954 100644
--- a/modules/codec/omxil/android_mediacodec.c
+++ b/modules/codec/omxil/android_mediacodec.c
@@ -1054,6 +1054,7 @@ static picture_t *DecodeVideo(decoder_t *p_dec, block_t **pp_block)
         p_dec->fmt_out.video.i_sar_den = p_dec->fmt_in.video.i_sar_den;
     }
 
+    unsigned int i_attempts = 0;
     jlong timeout = 0;
     int i_output_ret = 0;
     int i_input_ret = 0;
@@ -1090,12 +1091,22 @@ static picture_t *DecodeVideo(decoder_t *p_dec, block_t **pp_block)
             if (i_output_ret == -1) {
                 p_sys->error_state = true;
                 break;
-            } else if (i_output_ret == 0 && p_pic) {
-                picture_Release(p_pic);
-                p_pic = NULL;
+            } else if (i_output_ret == 0) {
+                if (p_pic) {
+                    picture_Release(p_pic);
+                    p_pic = NULL;
+                } else if (++i_attempts > 100) {
+                    /* No p_pic, so no pixel_format, thereforce mediacodec
+                     * didn't produce any output or events yet. Don't wait
+                     * indefinitely and abort after 2seconds (100 * 2 * 10ms)
+                     * without any data. Indeed, MediaCodec can fail without
+                     * throwing any exception or error returns... */
+                    p_sys->error_state = true;
+                    break;
+                }
             }
         }
-        timeout = 10 * 1000;
+        timeout = 10 * 1000; // 10 ms
     }
 
 endclean:
-- 
2.1.3




More information about the vlc-devel mailing list