Advertisement
Guest User

HWDecoderUtil.java

a guest
Oct 22nd, 2014
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.03 KB | None | 0 0
  1. /*****************************************************************************
  2.  * HWDecUtil.java
  3.  *****************************************************************************
  4.  * Copyright © 2010-2013 VLC authors and VideoLAN
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify it
  7.  * under the terms of the GNU Lesser General Public License as published by
  8.  * the Free Software Foundation; either version 2.1 of the License, or
  9.  * (at your option) any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14.  * GNU Lesser General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU Lesser General Public License
  17.  * along with this program; if not, write to the Free Software Foundation,
  18.  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  19.  *****************************************************************************/
  20.  
  21. package org.videolan.libvlc;
  22.  
  23. import java.lang.reflect.Method;
  24. import java.util.HashMap;
  25.  
  26. /**
  27.  * Utility class that return the preferred hardware decoder from a list of known devices.
  28.  */
  29. public class HWDecoderUtil {
  30.  
  31.     public enum Decoder {
  32.         UNKNOWN, NONE, OMX, MEDIACODEC, ALL
  33.     }
  34.  
  35.     private static class DecoderBySOC {
  36.         public final String key;
  37.         public final Decoder dec;
  38.         public final String[] list;
  39.         public DecoderBySOC(String key, Decoder dec, String[] list) {
  40.             this.key = key;
  41.             this.dec = dec;
  42.             this.list = list;
  43.         }
  44.     }
  45.  
  46.     private static final DecoderBySOC[] sDecoderBySOCList = new DecoderBySOC[] {
  47.         /*
  48.          *  Put first devices you want to blacklist
  49.          *  because theses devices can match the next rules.
  50.          */
  51.         new DecoderBySOC ("ro.product.brand", Decoder.NONE, new  String[] {
  52.                 "SEMC",             // Xperia S
  53.         }),
  54.         new DecoderBySOC ("ro.board.platform", Decoder.NONE, new  String[] {
  55.                 "msm7627",          // QCOM S1
  56.         }),
  57.        
  58.         new DecoderBySOC ("ro.hardware", Decoder.NONE, new  String[] {
  59.                 "amlogic",          // amlogic
  60.         }),
  61.         /*
  62.          * Devices working on OMX
  63.          */
  64.         new DecoderBySOC ("ro.board.platform", Decoder.OMX, new  String[] {
  65.                 "omap3",            // Omap 3
  66.                 "rockchip", "rk29", // Rockchip RK29
  67.                 "tegra",            // Tegra 2
  68.                 "msm7630",          // QCOM S2
  69.                 "s5pc",             // Exynos 3
  70.                 "montblanc",        // Montblanc
  71.                 "exdroid",          // Allwinner A31
  72.         }),
  73.         new DecoderBySOC ("ro.hardware", Decoder.OMX, new  String[] {
  74.                 "sun6i",            // Allwinner A31
  75.         }),
  76.         /*
  77.          * Devices working on Mediacodec and OMX
  78.          */
  79.         new DecoderBySOC ("ro.board.platform", Decoder.ALL, new  String[] {
  80.                 "omap4",            // Omap 4
  81.                 "msm8660",          // QCOM S3
  82.                 "exynos4",          // Exynos 4 (Samsung Galaxy S2/S3)
  83.                 "exynos5",          // Exynos 5 (Samsung Galaxy S4)
  84.                 "rk30", "rk31",     // Rockchip RK3*
  85.         }),
  86.         new DecoderBySOC ("ro.hardware", Decoder.ALL, new  String[] {
  87.                 "mt65", "mt83",     // MTK
  88.         }),
  89.     };
  90.  
  91.     private static final HashMap<String, String> sSystemPropertyMap = new HashMap<String, String>();
  92.  
  93.     /**
  94.      * @return the hardware decoder known to work for the running device
  95.      * (Always return Dec.ALL after Android 4.3)
  96.      */
  97.     public static Decoder getDecoderFromDevice() {
  98.         for (DecoderBySOC decBySOC : sDecoderBySOCList) {
  99.             String prop = sSystemPropertyMap.get(decBySOC.key);
  100.             if (prop == null) {
  101.                 prop = getSystemProperty(decBySOC.key, "none");
  102.                 sSystemPropertyMap.put(decBySOC.key, prop);
  103.             }
  104.             if (prop != null) {
  105.                 for (String decProp: decBySOC.list)
  106.                     if (prop.contains(decProp))
  107.                         return decBySOC.dec;
  108.             }
  109.         }
  110.         if (LibVlcUtil.isJellyBeanMR2OrLater())
  111.             return Decoder.ALL;
  112.         else
  113.             return Decoder.UNKNOWN;
  114.     }
  115.  
  116.     private static String getSystemProperty(String key, String def) {
  117.         try {
  118.             final ClassLoader cl = ClassLoader.getSystemClassLoader();
  119.             final Class<?> SystemProperties = cl.loadClass("android.os.SystemProperties");
  120.             final Class<?>[] paramTypes = new Class[] { String.class, String.class };
  121.             final Method get = SystemProperties.getMethod("get", paramTypes);
  122.             final Object[] params = new Object[] { key, def };
  123.             return (String) get.invoke(SystemProperties, params);
  124.         } catch (Exception e){
  125.             return def;
  126.         }
  127.     }
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement