Commit 61572e98 authored by flx42's avatar flx42 Committed by Jean-Baptiste Kempf

video: add an event handler for hardware acceleration failure

If hardware acceleration failed, ask the user if they want to fallback
to software decoding.
Signed-off-by: Jean-Baptiste Kempf's avatarJean-Baptiste Kempf <jb@videolan.org>
parent ad576857
...@@ -158,6 +158,9 @@ ...@@ -158,6 +158,9 @@
<string name="search">Search</string> <string name="search">Search</string>
<string name="search_history">Search history</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 --> <!-- About -->
<string name="app_name_full">VLC for Android™</string> <string name="app_name_full">VLC for Android™</string>
<string name="licence">License</string> <string name="licence">License</string>
......
...@@ -210,6 +210,10 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer { ...@@ -210,6 +210,10 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
*/ */
private ArrayList<String> mSubtitleSelectedFiles = new ArrayList<String>(); 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 @Override
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
...@@ -452,6 +456,10 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer { ...@@ -452,6 +456,10 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
EventHandler em = EventHandler.getInstance(); EventHandler em = EventHandler.getInstance();
em.removeHandler(eventHandler); em.removeHandler(eventHandler);
// HW acceleration was temporarily disabled because of an error, restore the previous value.
if (mDisabledHardwareAcceleration)
mLibVLC.setHardwareAcceleration(mPreviousHardwareAccelerationMode);
mAudioManager = null; mAudioManager = null;
} }
...@@ -774,6 +782,10 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer { ...@@ -774,6 +782,10 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
Log.i(TAG, "MediaPlayerEncounteredError"); Log.i(TAG, "MediaPlayerEncounteredError");
activity.encounteredError(); activity.encounteredError();
break; break;
case EventHandler.HardwareAccelerationError:
Log.i(TAG, "HardwareAccelerationError");
activity.handleHardwareAccelerationError();
break;
default: default:
Log.e(TAG, String.format("Event not handled (0x%x)", msg.getData().getInt("event"))); Log.e(TAG, String.format("Event not handled (0x%x)", msg.getData().getInt("event")));
break; break;
...@@ -854,6 +866,35 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer { ...@@ -854,6 +866,35 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
dialog.show(); 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) { private void handleVout(Message msg) {
if (msg.getData().getInt("data") == 0 && !mEndReached) { if (msg.getData().getInt("data") == 0 && !mEndReached) {
/* Video track lost, open in audio mode */ /* Video track lost, open in audio mode */
......
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