Chromium Code Reviews| Index: media/base/android/java/src/org/chromium/media/MediaCodecUtil.java |
| diff --git a/media/base/android/java/src/org/chromium/media/MediaCodecUtil.java b/media/base/android/java/src/org/chromium/media/MediaCodecUtil.java |
| index 83835836a6a701a0cab0d4477ae81d33e6a2ce8c..50882ee854a5ea140c34e18df774bef600691652 100644 |
| --- a/media/base/android/java/src/org/chromium/media/MediaCodecUtil.java |
| +++ b/media/base/android/java/src/org/chromium/media/MediaCodecUtil.java |
| @@ -15,10 +15,7 @@ import org.chromium.base.annotations.CalledByNative; |
| import org.chromium.base.annotations.JNINamespace; |
| import org.chromium.base.annotations.MainDex; |
| -import java.util.ArrayList; |
| -import java.util.HashMap; |
| import java.util.Locale; |
| -import java.util.Map; |
| /** |
| * A collection of MediaCodec utility functions. |
| @@ -32,37 +29,6 @@ class MediaCodecUtil { |
| static final int MEDIA_CODEC_ENCODER = 1; |
| /** |
| - * This class represents supported android codec information. |
| - */ |
| - @MainDex |
| - private static class CodecInfo { |
| - private final String mCodecType; // e.g. "video/x-vnd.on2.vp8". |
| - private final String mCodecName; // e.g. "OMX.google.vp8.decoder". |
| - private final int mDirection; |
| - |
| - private CodecInfo(String codecType, String codecName, int direction) { |
| - mCodecType = codecType; |
| - mCodecName = codecName; |
| - mDirection = direction; |
| - } |
| - |
| - @CalledByNative("CodecInfo") |
| - private String codecType() { |
| - return mCodecType; |
| - } |
| - |
| - @CalledByNative("CodecInfo") |
| - private String codecName() { |
| - return mCodecName; |
| - } |
| - |
| - @CalledByNative("CodecInfo") |
| - private int direction() { |
| - return mDirection; |
| - } |
| - } |
| - |
| - /** |
| * Class to pass parameters from createDecoder() |
| */ |
| @MainDex |
| @@ -72,62 +38,42 @@ class MediaCodecUtil { |
| } |
| /** |
| - * @return a list of supported android codec information. |
| - */ |
| - @SuppressWarnings("deprecation") |
| - @CalledByNative |
| - private static CodecInfo[] getCodecsInfo() { |
| - // Return the first (highest-priority) codec for each MIME type. |
| - Map<String, CodecInfo> encoderInfoMap = new HashMap<String, CodecInfo>(); |
| - Map<String, CodecInfo> decoderInfoMap = new HashMap<String, CodecInfo>(); |
| - int count = MediaCodecList.getCodecCount(); |
| - for (int i = 0; i < count; ++i) { |
| - MediaCodecInfo info = MediaCodecList.getCodecInfoAt(i); |
| - int direction = info.isEncoder() ? MEDIA_CODEC_ENCODER : MEDIA_CODEC_DECODER; |
| - String codecString = info.getName(); |
| - String[] supportedTypes = info.getSupportedTypes(); |
| - for (int j = 0; j < supportedTypes.length; ++j) { |
| - Map<String, CodecInfo> map = info.isEncoder() ? encoderInfoMap : decoderInfoMap; |
| - if (!map.containsKey(supportedTypes[j])) { |
| - map.put(supportedTypes[j], |
| - new CodecInfo(supportedTypes[j], codecString, direction)); |
| - } |
| - } |
| - } |
| - ArrayList<CodecInfo> codecInfos = |
| - new ArrayList<CodecInfo>(decoderInfoMap.size() + encoderInfoMap.size()); |
| - codecInfos.addAll(encoderInfoMap.values()); |
| - codecInfos.addAll(decoderInfoMap.values()); |
| - return codecInfos.toArray(new CodecInfo[codecInfos.size()]); |
| - } |
| - |
| - /** |
| * Get a name of default android codec. |
| * @param mime MIME type of the media. |
| * @param direction Whether this is encoder or decoder. |
| * @return name of the codec. |
| */ |
| - @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) |
| @SuppressWarnings("deprecation") |
| @CalledByNative |
| private static String getDefaultCodecName(String mime, int direction) { |
| - String codecName = ""; |
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { |
| try { |
| - MediaCodec mediaCodec = null; |
| - if (direction == MEDIA_CODEC_ENCODER) { |
| - mediaCodec = MediaCodec.createEncoderByType(mime); |
| - } else { |
| - mediaCodec = MediaCodec.createDecoderByType(mime); |
| - } |
| - codecName = mediaCodec.getName(); |
| + MediaCodec mediaCodec = direction == MEDIA_CODEC_ENCODER |
| + ? MediaCodec.createEncoderByType(mime) |
| + : MediaCodec.createDecoderByType(mime); |
| + String codecName = mediaCodec.getName(); |
| mediaCodec.release(); |
| + return codecName; |
| } catch (Exception e) { |
| Log.w(TAG, "getDefaultCodecName: Failed to create MediaCodec: %s, direction: %d", |
|
Tima Vaisburd
2016/03/15 21:38:17
nit: Does it make sense to add ", getting first ma
DaleCurtis
2016/03/15 23:02:45
I've deleted this code entirely in the latest patc
|
| mime, direction, e); |
| } |
| } |
| - return codecName; |
| + |
| + int codec_count = MediaCodecList.getCodecCount(); |
| + for (int i = 0; i < codec_count; ++i) { |
| + MediaCodecInfo info = MediaCodecList.getCodecInfoAt(i); |
| + |
| + int codec_direction = info.isEncoder() ? MEDIA_CODEC_ENCODER : MEDIA_CODEC_DECODER; |
| + if (codec_direction != direction) continue; |
| + |
| + String[] supportedTypes = info.getSupportedTypes(); |
| + for (int j = 0; j < supportedTypes.length; ++j) { |
| + if (supportedTypes[j].equals(mime)) return info.getName(); |
| + } |
| + } |
| + |
| + return ""; |
|
Tima Vaisburd
2016/03/15 21:38:17
nit: Log that it could not determine the name?
DaleCurtis
2016/03/15 23:02:45
Done. Used the wording from similar messages elsew
|
| } |
| /** |