[Android] [PATCH 3/3] video: add an event handler for hardware acceleration failure

Felix Abecassis felix.abecassis at gmail.com
Tue Feb 18 19:25:01 CET 2014


If hardware acceleration failed, ask the user if they want to fallback
to software decoding.
---
 vlc-android/res/values/strings.xml                 |  3 ++
 .../vlc/gui/video/VideoPlayerActivity.java         | 41 ++++++++++++++++++++++
 2 files changed, 44 insertions(+)

diff --git a/vlc-android/res/values/strings.xml b/vlc-android/res/values/strings.xml
index 65c3d9b..251ab97 100644
--- a/vlc-android/res/values/strings.xml
+++ b/vlc-android/res/values/strings.xml
@@ -158,6 +158,9 @@
     <string name="search">Search</string>
     <string name="search_history">Search history</string>
 
+    <string name="hardware_acceleration_error_title">HW acceleration error</string>
+    <string name="hardware_acceleration_error_message">HW acceleration encountered an error. Do you want to disable it and try again?</string>
+
     <!-- About -->
     <string name="app_name_full">VLC for Android™</string>
     <string name="licence">License</string>
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
index e8eb025..8a1c84a 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -210,6 +210,10 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
      */
     private ArrayList<String> mSubtitleSelectedFiles = new ArrayList<String>();
 
+    // Whether fallback from HW acceleration to SW decoding was done.
+    private boolean mDisabledHardwareAcceleration = false;
+    private int mPreviousHardwareAccelerationMode;
+
     @Override
     @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
     protected void onCreate(Bundle savedInstanceState) {
@@ -452,6 +456,10 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
         EventHandler em = EventHandler.getInstance();
         em.removeHandler(eventHandler);
 
+        // HW acceleration was temporarily disabled because of an error, restore the previous value.
+        if (mDisabledHardwareAcceleration)
+            mLibVLC.setHardwareAcceleration(mPreviousHardwareAccelerationMode);
+
         mAudioManager = null;
     }
 
@@ -774,6 +782,10 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
                     Log.i(TAG, "MediaPlayerEncounteredError");
                     activity.encounteredError();
                     break;
+                case EventHandler.HardwareAccelerationError:
+                    Log.i(TAG, "HardwareAccelerationError");
+                    activity.handleHardwareAccelerationError();
+                    break;
                 default:
                     Log.e(TAG, String.format("Event not handled (0x%x)", msg.getData().getInt("event")));
                     break;
@@ -854,6 +866,35 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
         dialog.show();
     }
 
+    public void eventHardwareAccelerationError() {
+        EventHandler em = EventHandler.getInstance();
+        em.callback(EventHandler.HardwareAccelerationError, new Bundle());
+    }
+
+    private void handleHardwareAccelerationError() {
+        mLibVLC.stop();
+        AlertDialog dialog = new AlertDialog.Builder(VideoPlayerActivity.this)
+        .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
+            @Override
+            public void onClick(DialogInterface dialog, int id) {
+                mDisabledHardwareAcceleration = true;
+                mPreviousHardwareAccelerationMode = mLibVLC.getHardwareAcceleration();
+                mLibVLC.setHardwareAcceleration(0);
+                load();
+            }
+        })
+        .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
+            @Override
+            public void onClick(DialogInterface dialog, int id) {
+                finish();
+            }
+        })
+        .setTitle(R.string.hardware_acceleration_error_title)
+        .setMessage(R.string.hardware_acceleration_error_message)
+        .create();
+        dialog.show();
+    }
+
     private void handleVout(Message msg) {
         if (msg.getData().getInt("data") == 0 && !mEndReached) {
             /* Video track lost, open in audio mode */
-- 
1.8.3.2



More information about the Android mailing list