Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(165)

Side by Side Diff: media/base/android/java/src/org/chromium/media/MediaCodecUtil.java

Issue 2817663004: android: Swallow MediaCodecList constructor exception (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.media; 5 package org.chromium.media;
6 6
7 import android.annotation.TargetApi; 7 import android.annotation.TargetApi;
8 import android.media.MediaCodec; 8 import android.media.MediaCodec;
9 import android.media.MediaCodec.CryptoInfo; 9 import android.media.MediaCodec.CryptoInfo;
10 import android.media.MediaCodecInfo; 10 import android.media.MediaCodecInfo;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 FRAMERATE_ADJUSTMENT, 61 FRAMERATE_ADJUSTMENT,
62 } 62 }
63 63
64 /** 64 /**
65 * Class to abstract platform version API differences for interacting with 65 * Class to abstract platform version API differences for interacting with
66 * the MediaCodecList. 66 * the MediaCodecList.
67 */ 67 */
68 private static class MediaCodecListHelper implements Iterable<MediaCodecInfo > { 68 private static class MediaCodecListHelper implements Iterable<MediaCodecInfo > {
69 @TargetApi(Build.VERSION_CODES.LOLLIPOP) 69 @TargetApi(Build.VERSION_CODES.LOLLIPOP)
70 public MediaCodecListHelper() { 70 public MediaCodecListHelper() {
71 if (hasNewMediaCodecList()) { 71 if (supportsNewMediaCodecList()) {
72 mCodecList = new MediaCodecList(MediaCodecList.ALL_CODECS).getCo decInfos(); 72 try {
73 mCodecList = new MediaCodecList(MediaCodecList.ALL_CODECS).g etCodecInfos();
74 } catch (RuntimeException e) {
75 // Swallow the exception due to bad Android implementation a nd pretend
76 // MediaCodecList is not supported.
77 }
73 } 78 }
74 } 79 }
75 80
76 @Override 81 @Override
77 public Iterator<MediaCodecInfo> iterator() { 82 public Iterator<MediaCodecInfo> iterator() {
78 return new CodecInfoIterator(); 83 return new CodecInfoIterator();
79 } 84 }
80 85
81 @SuppressWarnings("deprecation") 86 @SuppressWarnings("deprecation")
82 private int getCodecCount() { 87 private int getCodecCount() {
83 if (hasNewMediaCodecList()) return mCodecList.length; 88 if (hasNewMediaCodecList()) return mCodecList.length;
84 return MediaCodecList.getCodecCount(); 89 return MediaCodecList.getCodecCount();
85 } 90 }
86 91
87 @SuppressWarnings("deprecation") 92 @SuppressWarnings("deprecation")
88 private MediaCodecInfo getCodecInfoAt(int index) { 93 private MediaCodecInfo getCodecInfoAt(int index) {
89 if (hasNewMediaCodecList()) return mCodecList[index]; 94 if (hasNewMediaCodecList()) return mCodecList[index];
90 return MediaCodecList.getCodecInfoAt(index); 95 return MediaCodecList.getCodecInfoAt(index);
91 } 96 }
92 97
98 private static boolean supportsNewMediaCodecList() {
99 return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
100 }
101
93 private boolean hasNewMediaCodecList() { 102 private boolean hasNewMediaCodecList() {
94 return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP; 103 return supportsNewMediaCodecList() && mCodecList != null;
95 } 104 }
96 105
97 private MediaCodecInfo[] mCodecList; 106 private MediaCodecInfo[] mCodecList;
98 107
99 private class CodecInfoIterator implements Iterator<MediaCodecInfo> { 108 private class CodecInfoIterator implements Iterator<MediaCodecInfo> {
100 private int mPosition = 0; 109 private int mPosition = 0;
101 110
102 @Override 111 @Override
103 public boolean hasNext() { 112 public boolean hasNext() {
104 return mPosition < getCodecCount(); 113 return mPosition < getCodecCount();
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 * supported. 633 * supported.
625 * This method was introduced in Android N. Note that if platformSupportsCbc sEncryption 634 * This method was introduced in Android N. Note that if platformSupportsCbc sEncryption
626 * returns true, then this function will set the pattern. 635 * returns true, then this function will set the pattern.
627 */ 636 */
628 static void setPatternIfSupported(CryptoInfo cryptoInfo, int encrypt, int sk ip) { 637 static void setPatternIfSupported(CryptoInfo cryptoInfo, int encrypt, int sk ip) {
629 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { 638 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
630 cryptoInfo.setPattern(new CryptoInfo.Pattern(encrypt, skip)); 639 cryptoInfo.setPattern(new CryptoInfo.Pattern(encrypt, skip));
631 } 640 }
632 } 641 }
633 } 642 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698