[Android] Developer Preferences: Add a menu to force hardware decoder

Thomas Guillem git at videolan.org
Wed Oct 8 14:57:18 CEST 2014


vlc-ports/android | branch: master | Thomas Guillem <thomas.guillem at gmail.com> | Wed Oct  8 12:00:03 2014 +0200| [e1fd190437a13bb00b5e1351396b913208907658] | committer: Jean-Baptiste Kempf

Developer Preferences: Add a menu to force hardware decoder

Advanced hardware decoder in developer menu: bypass all others settings and
force iomx, iomx-dr, mediacodec or mediacodec-dr.
If the forced decoder fails, there will be no fallback, that's why it's for
developers only.

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=e1fd190437a13bb00b5e1351396b913208907658
---

 vlc-android/res/values/strings.xml                 |   21 ++++++++++
 vlc-android/res/xml/preferences.xml                |    7 ++++
 vlc-android/src/org/videolan/libvlc/LibVLC.java    |   42 ++++++++++++++++++--
 .../org/videolan/vlc/gui/PreferencesActivity.java  |    3 +-
 .../src/org/videolan/vlc/util/VLCInstance.java     |    8 ++++
 5 files changed, 77 insertions(+), 4 deletions(-)

diff --git a/vlc-android/res/values/strings.xml b/vlc-android/res/values/strings.xml
index f5f7180..bf6e2d4 100644
--- a/vlc-android/res/values/strings.xml
+++ b/vlc-android/res/values/strings.xml
@@ -206,6 +206,12 @@
     <string name="hardware_acceleration_disabled">Disabled</string>
     <string name="hardware_acceleration_decoding">Decoding acceleration</string>
     <string name="hardware_acceleration_full">Full acceleration</string>
+    <string name="dev_hardware_decoder">Advanced hardware decoder</string>
+    <string name="dev_hardware_decoder_summary">Force hardware decoder, for advanced users only</string>
+    <string name="dev_hardware_decoder_omx">iomx</string>
+    <string name="dev_hardware_decoder_omx_dr">iomx-dr</string>
+    <string name="dev_hardware_decoder_mediacodec">mediacodec</string>
+    <string name="dev_hardware_decoder_mediacodec_dr">mediacodec-dr</string>
     <string name="automatic">Automatic</string>
     <string name="screen_orientation">Video screen orientation</string>
     <string name="screen_orientation_sensor">Automatic (sensor)</string>
@@ -310,6 +316,21 @@
         <item>2</item>
     </string-array>
 
+    <string-array name="dev_hardware_decoder_list">
+        <item>@string/automatic</item>
+        <item>@string/dev_hardware_decoder_omx</item>
+        <item>@string/dev_hardware_decoder_omx_dr</item>
+        <item>@string/dev_hardware_decoder_mediacodec</item>
+        <item>@string/dev_hardware_decoder_mediacodec_dr</item>
+    </string-array>
+    <string-array name="dev_hardware_decoder_values" translatable="false">
+        <item>-1</item>
+        <item>0</item>
+        <item>1</item>
+        <item>2</item>
+        <item>3</item>
+    </string-array>
+
     <string-array name="deblocking_list">
         <item>@string/automatic</item>
         <item>@string/deblocking_always</item>
diff --git a/vlc-android/res/xml/preferences.xml b/vlc-android/res/xml/preferences.xml
index 6e3654c..8ec773f 100644
--- a/vlc-android/res/xml/preferences.xml
+++ b/vlc-android/res/xml/preferences.xml
@@ -145,6 +145,13 @@
         </PreferenceScreen>
         <PreferenceScreen android:title="@string/developer_prefs_category" >
             <PreferenceCategory android:title="@string/developer_prefs_category" >
+                <ListPreference
+                    android:defaultValue="-1"
+                    android:entries="@array/dev_hardware_decoder_list"
+                    android:entryValues="@array/dev_hardware_decoder_values"
+                    android:key="dev_hardware_decoder"
+                    android:summary="@string/dev_hardware_decoder_summary"
+                    android:title="@string/dev_hardware_decoder" />
                 <CheckBoxPreference
                     android:defaultValue="true"
                     android:key="enable_verbose_mode"
diff --git a/vlc-android/src/org/videolan/libvlc/LibVLC.java b/vlc-android/src/org/videolan/libvlc/LibVLC.java
index c30f61c..23bd241 100644
--- a/vlc-android/src/org/videolan/libvlc/LibVLC.java
+++ b/vlc-android/src/org/videolan/libvlc/LibVLC.java
@@ -43,6 +43,12 @@ public class LibVLC {
     public static final int HW_ACCELERATION_DECODING = 1;
     public static final int HW_ACCELERATION_FULL = 2;
 
+    public static final int DEV_HW_DECODER_AUTOMATIC = -1;
+    public static final int DEV_HW_DECODER_OMX = 0;
+    public static final int DEV_HW_DECODER_OMX_DR = 1;
+    public static final int DEV_HW_DECODER_MEDIACODEC = 2;
+    public static final int DEV_HW_DECODER_MEDIACODEC_DR = 3;
+
     private static final String DEFAULT_CODEC_LIST = "mediacodec,iomx,all";
 
     private static LibVLC sInstance;
@@ -67,7 +73,9 @@ public class LibVLC {
 
     /** Settings */
     private int hardwareAcceleration = HW_ACCELERATION_AUTOMATIC;
+    private int devHardwareDecoder = DEV_HW_DECODER_AUTOMATIC;
     private String codecList = DEFAULT_CODEC_LIST;
+    private String devCodecList = null;
     private String subtitlesEncoding = "";
     private int aout = LibVlcUtil.isGingerbreadOrLater() ? AOUT_OPENSLES : AOUT_AUDIOTRACK_JAVA;
     private int vout = VOUT_ANDROID_SURFACE;
@@ -293,13 +301,41 @@ public class LibVLC {
         }
     }
 
+    public int getDevHardwareDecoder() {
+        return this.devHardwareDecoder;
+    }
+
+    public void setDevHardwareDecoder(int devHardwareDecoder) {
+        if (devHardwareDecoder != DEV_HW_DECODER_AUTOMATIC) {
+            this.devHardwareDecoder = devHardwareDecoder;
+            if (this.devHardwareDecoder == DEV_HW_DECODER_OMX ||
+                    this.devHardwareDecoder == DEV_HW_DECODER_OMX_DR)
+                this.devCodecList = "iomx";
+            else
+                this.devCodecList = "mediacodec";
+
+            Log.d(TAG, "HWDec forced: " + this.devCodecList +
+                (isDirectRendering() ? "-dr" : ""));
+            this.devCodecList += ",none";
+        } else {
+            this.devHardwareDecoder = DEV_HW_DECODER_AUTOMATIC;
+            this.devCodecList = null;
+        }
+    }
 
     public boolean isDirectRendering() {
-        return this.hardwareAcceleration == HW_ACCELERATION_FULL;
+        if (devHardwareDecoder != DEV_HW_DECODER_AUTOMATIC) {
+            return (this.devHardwareDecoder == DEV_HW_DECODER_OMX_DR ||
+                    this.devHardwareDecoder == DEV_HW_DECODER_MEDIACODEC_DR);
+        } else {
+            return this.hardwareAcceleration == HW_ACCELERATION_FULL;
+        }
     }
 
     public String[] getMediaOptions(boolean noHardwareAcceleration, boolean noVideo) {
-        if (!noHardwareAcceleration)
+        if (this.devHardwareDecoder != DEV_HW_DECODER_AUTOMATIC)
+            noHardwareAcceleration = noVideo = false;
+        else if (!noHardwareAcceleration)
             noHardwareAcceleration = getHardwareAcceleration() == HW_ACCELERATION_DISABLED;
 
         ArrayList<String> options = new ArrayList<String>();
@@ -316,7 +352,7 @@ public class LibVLC {
              */
             options.add(":file-caching=1500");
             options.add(":network-caching=1500");
-            options.add(":codec="+this.codecList);
+            options.add(":codec="+ (this.devCodecList != null ? this.devCodecList : this.codecList));
         }
         if (noVideo)
             options.add(":no-video");
diff --git a/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java b/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
index 4c9539f..9f0109c 100644
--- a/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
@@ -289,7 +289,8 @@ public class PreferencesActivity extends PreferenceActivity implements OnSharedP
                 || key.equalsIgnoreCase("enable_frame_skip")
                 || key.equalsIgnoreCase("enable_time_stretching_audio")
                 || key.equalsIgnoreCase("enable_verbose_mode")
-                || key.equalsIgnoreCase("network_caching")) {
+                || key.equalsIgnoreCase("network_caching")
+                || key.equalsIgnoreCase("dev_hardware_decoder")) {
             VLCInstance.updateLibVlcSettings(sharedPreferences);
             LibVLC.restart(this);
         }
diff --git a/vlc-android/src/org/videolan/vlc/util/VLCInstance.java b/vlc-android/src/org/videolan/vlc/util/VLCInstance.java
index d020eeb..d0212c6 100644
--- a/vlc-android/src/org/videolan/vlc/util/VLCInstance.java
+++ b/vlc-android/src/org/videolan/vlc/util/VLCInstance.java
@@ -100,6 +100,13 @@ public class VLCInstance {
         catch(NumberFormatException nfe) {
             hardwareAcceleration = -1;
         }
+        int devHardwareDecoder;
+        try {
+            devHardwareDecoder = Integer.parseInt(pref.getString("dev_hardware_decoder", "-1"));
+        }
+        catch(NumberFormatException nfe) {
+            devHardwareDecoder = -1;
+        }
         int networkCaching = pref.getInt("network_caching_value", 0);
         if(networkCaching > 60000)
             networkCaching = 60000;
@@ -110,6 +117,7 @@ public class VLCInstance {
         instance.setDeblocking(deblocking);
         instance.setNetworkCaching(networkCaching);
         instance.setHardwareAcceleration(hardwareAcceleration);
+        instance.setDevHardwareDecoder(devHardwareDecoder);
     }
 
 



More information about the Android mailing list