[Android] [PATCH] benchmark: set timeout for hung vlc-android

Duncan McNamara dcn.mcnamara at gmail.com
Tue Jul 31 17:19:28 CEST 2018


On some weak devices, the hardware decoder will end up hung.
To avoir stopping the benchmark, a timeout is set to stop vlc
and return to the benchmark for the next test.
---
 .../gui/video/benchmark/BenchActivity.java    | 52 +++++++++++++------
 1 file changed, 36 insertions(+), 16 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/video/benchmark/BenchActivity.java b/vlc-android/src/org/videolan/vlc/gui/video/benchmark/BenchActivity.java
index a8bdb8dd5..f9963542a 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/benchmark/BenchActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/benchmark/BenchActivity.java
@@ -76,7 +76,7 @@ public class BenchActivity extends ShallowVideoPlayer {
     private static final String TAG = "VLCBenchmark";
     private static final int REQUEST_SCREENSHOT = 666;
 
-    private static final int RESULT_FAILED = 0;
+    private static final int RESULT_FAILED = 6;
     private static final int RESULT_NO_HW = 1;
 
     private static final int VIRTUAL_DISPLAY_FLAGS = 0;
@@ -197,6 +197,35 @@ public class BenchActivity extends ShallowVideoPlayer {
             mWritePermission = true;
     }
 
+    @Override
+    protected void onResume() {
+        super.onResume();
+        setTimeout();
+    }
+
+    /**
+     * On some weak devices, the hardware decoder will end up hung.
+     * To avoid stopping the benchmark, a timeout is set to stop vlc
+     * and return to the benchmark for the next test.
+     */
+    private void setTimeout() {
+        if (mSetup && mHandler != null) {
+            Log.i(TAG, "setting benchmark timeout");
+            if (mTimeOut != null) {
+                mHandler.removeCallbacks(mTimeOut);
+                mTimeOut = null;
+            }
+            mTimeOut = new Runnable() {
+                @Override
+                public void run() {
+                    Log.e(TAG, "benchmark timeout: VLC Froze" );
+                    errorFinish("VLC Froze");
+                }
+            };
+            mHandler.postDelayed(mTimeOut, 10000);
+        }
+    }
+
     /**
      * Reacts on the event buffering before calling super:
      * <p/>
@@ -217,13 +246,14 @@ public class BenchActivity extends ShallowVideoPlayer {
         switch (event.type) {
             case MediaPlayer.Event.Vout:
                 mHasVout = true;
+            case MediaPlayer.Event.TimeChanged:
+                setTimeout();
             case MediaPlayer.Event.Buffering:
                 if (event.getBuffering() == 100f) {
                     /* initial setup that has to be done when the video
                      * has finished the first buffering */
                     if (!mSetup) {
-                        mSetup =
-                                true;
+                        mSetup = true;
                         if (mIsScreenshot) {
                             mService.pause();
                             Point size = new Point();
@@ -249,11 +279,6 @@ public class BenchActivity extends ShallowVideoPlayer {
                     /* Screenshot callback setup */
                     if (mIsScreenshot && mSetup && mScreenshotNumber < mTimestamp.size() && mSeeking) {
                         mSeeking = false;
-                        /* deactivating timeout*/
-                        if (mTimeOut != null) {
-                            mHandler.removeCallbacks(mTimeOut);
-                            mTimeOut = null;
-                        }
                         mImageReader = ImageReader.newInstance(mWidth, mHeight, PixelFormat.RGBA_8888, 2);
 
                         mVirtualDisplay =
@@ -284,14 +309,6 @@ public class BenchActivity extends ShallowVideoPlayer {
     private void seekScreenshot() {
         if (mProjectionManager != null && mScreenshotCount < mTimestamp.size()) {
             seek(mTimestamp.get(mScreenshotCount));
-            /* Setting a timeout system */
-            mTimeOut = new Runnable() {
-                @Override
-                public void run() {
-                    errorFinish("Seek froze");
-                }
-            };
-            mHandler.postDelayed(mTimeOut, 5000);
             ++mScreenshotCount;
             mSeeking = true;
         } else {
@@ -434,6 +451,9 @@ public class BenchActivity extends ShallowVideoPlayer {
         if (mMediaProjection != null) {
             mMediaProjection.stop();
         }
+        if (mTimeOut != null && mHandler != null) {
+            mHandler.removeCallbacks(mTimeOut);
+        }
         super.onDestroy();
     }
 
-- 
2.18.0



More information about the Android mailing list