Android Open Source - Billy H W Decoder Util






From Project

Back to project page Billy.

License

The source code is released under:

GNU General Public License

If you think the Android project Billy listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*****************************************************************************
 * HWDecUtil.java/*www.  j  a va2  s .  com*/
 *****************************************************************************
 * Copyright  2010-2013 VLC authors and VideoLAN
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

package org.videolan.libvlc;

import java.lang.reflect.Method;
import java.util.HashMap;

/**
 * Utility class that return the preferred hardware decoder from a list of known devices.
 */
public class HWDecoderUtil {

    public enum Decoder {
        UNKNOWN, NONE, OMX, MEDIACODEC, ALL
    }

    private static class DecoderBySOC {
        public final String key;
        public final Decoder dec;
        public final String[] list;
        public DecoderBySOC(String key, Decoder dec, String[] list) {
            this.key = key;
            this.dec = dec;
            this.list = list;
        }
    }

    private static final DecoderBySOC[] sDecoderBySOCList = new DecoderBySOC[] {
        /*
         *  Put first devices you want to blacklist
         *  because theses devices can match the next rules.
         */
        new DecoderBySOC ("ro.product.brand", Decoder.NONE, new  String[] {
                "SEMC",             // Xperia S
        }),
        new DecoderBySOC ("ro.board.platform", Decoder.NONE, new  String[] {
                "msm7627",          // QCOM S1
        }),
        /*
         * Devices working on OMX
         */
        new DecoderBySOC ("ro.board.platform", Decoder.OMX, new  String[] {
                "omap3",            // Omap 3
                "rockchip", "rk29", // Rockchip RK29
                "msm7630",          // QCOM S2
                "s5pc",             // Exynos 3
                "montblanc",        // Montblanc
                "exdroid",          // Allwinner A31
        }),
        new DecoderBySOC ("ro.hardware", Decoder.OMX, new  String[] {
                "sun6i",            // Allwinner A31
        }),
        /*
         * Devices working on Mediacodec and OMX
         */
        new DecoderBySOC ("ro.board.platform", Decoder.ALL, new  String[] {
                "omap4",            // Omap 4
                "tegra",            // Tegra 2 & 3
                "tegra3",           // Tegra 3
                "msm8660",          // QCOM S3
                "exynos4",          // Exynos 4 (Samsung Galaxy S2/S3)
                "exynos5",          // Exynos 5 (Samsung Galaxy S4)
                "rk30", "rk31",     // Rockchip RK3*
                "mv88de3100",       // Marvell ARMADA 1500
        }),
        new DecoderBySOC ("ro.hardware", Decoder.ALL, new  String[] {
                "mt65", "mt83",     // MTK
        }),
    };

    private static final HashMap<String, String> sSystemPropertyMap = new HashMap<String, String>();

    /**
     * @return the hardware decoder known to work for the running device
     * (Always return Dec.ALL after Android 4.3)
     */
    public static Decoder getDecoderFromDevice() {
        if (LibVlcUtil.isJellyBeanMR2OrLater())
            return Decoder.ALL;
        for (DecoderBySOC decBySOC : sDecoderBySOCList) {
            String prop = sSystemPropertyMap.get(decBySOC.key);
            if (prop == null) {
                prop = getSystemProperty(decBySOC.key, "none");
                sSystemPropertyMap.put(decBySOC.key, prop);
            }
            if (prop != null) {
                for (String decProp: decBySOC.list)
                    if (prop.contains(decProp))
                        return decBySOC.dec;
            }
        }
        return Decoder.UNKNOWN;
    }

    private static String getSystemProperty(String key, String def) {
        try {
            final ClassLoader cl = ClassLoader.getSystemClassLoader();
            final Class<?> SystemProperties = cl.loadClass("android.os.SystemProperties");
            final Class<?>[] paramTypes = new Class[] { String.class, String.class };
            final Method get = SystemProperties.getMethod("get", paramTypes);
            final Object[] params = new Object[] { key, def };
            return (String) get.invoke(SystemProperties, params);
        } catch (Exception e){
            return def;
        }
    }
}




Java Source Code List

com.vibin.billy.BillyApplication.java
com.vibin.billy.BillyItem.java
com.vibin.billy.BitmapLruCache.java
com.vibin.billy.ChangelogDialog.java
com.vibin.billy.CustomBaseAdapter.java
com.vibin.billy.CustomDatabaseAdapter.java
com.vibin.billy.CustomFragmentAdapter.java
com.vibin.billy.CustomListPreference.java
com.vibin.billy.CustomShareActionProvider.java
com.vibin.billy.CustomStringRequest.java
com.vibin.billy.DetailView.java
com.vibin.billy.LicensesFragment.java
com.vibin.billy.MainActivity.java
com.vibin.billy.MediaControl.java
com.vibin.billy.NotifyingScrollView.java
com.vibin.billy.PPlayerService.java
com.vibin.billy.PlayerService.java
com.vibin.billy.ProcessingTask.java
com.vibin.billy.ReorderedListPreference.java
com.vibin.billy.Settings.java
com.vibin.billy.SongsFragment.java
com.vibin.billy.SwingBottomInAnimationAdapter.java
com.vibin.billy.draglistview.DynamicListView.java
com.vibin.billy.draglistview.StableArrayAdapter.java
com.vibin.billy.swipeable.ActivitySwipeDismissListener.java
com.vibin.billy.swipeable.AnimationUtils.java
com.vibin.billy.swipeable.SwipeDismissViewGroup.java
com.vibin.billy.swipeable.SwipeListener.java
com.vibin.billy.swipeable.SwipeableActivity.java
com.vibin.billy.swipeable.WindowDimens.java
com.vibin.billy.swipeable.WindowUtils.java
org.videolan.libvlc.AudioOutput.java
org.videolan.libvlc.EventHandler.java
org.videolan.libvlc.HWDecoderUtil.java
org.videolan.libvlc.IVideoPlayer.java
org.videolan.libvlc.LibVLC.java
org.videolan.libvlc.LibVlcException.java
org.videolan.libvlc.LibVlcUtil.java
org.videolan.libvlc.MediaList.java
org.videolan.libvlc.Media.java
org.videolan.libvlc.TrackInfo.java