use of android.media.MediaCodecInfo in project platform_frameworks_base by android.
the class MediaCodecList method initCodecList.
private static final void initCodecList() {
synchronized (sInitLock) {
if (sRegularCodecInfos == null) {
int count = native_getCodecCount();
ArrayList<MediaCodecInfo> regulars = new ArrayList<MediaCodecInfo>();
ArrayList<MediaCodecInfo> all = new ArrayList<MediaCodecInfo>();
for (int index = 0; index < count; index++) {
try {
MediaCodecInfo info = getNewCodecInfoAt(index);
all.add(info);
info = info.makeRegular();
if (info != null) {
regulars.add(info);
}
} catch (Exception e) {
Log.e(TAG, "Could not get codec capabilities", e);
}
}
sRegularCodecInfos = regulars.toArray(new MediaCodecInfo[regulars.size()]);
sAllCodecInfos = all.toArray(new MediaCodecInfo[all.size()]);
}
}
}
use of android.media.MediaCodecInfo in project speechutils by Kaljurand.
the class AudioUtils method getEncoderNamesForType.
/**
* Maps the given mime type to a list of names of suitable codecs.
* Only OMX-codecs are considered.
*/
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public static List<String> getEncoderNamesForType(String mime) {
LinkedList<String> names = new LinkedList<>();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
int n = MediaCodecList.getCodecCount();
for (int i = 0; i < n; ++i) {
MediaCodecInfo info = MediaCodecList.getCodecInfoAt(i);
if (!info.isEncoder()) {
continue;
}
if (!info.getName().startsWith("OMX.")) {
// Unfortunately for legacy reasons, "AACEncoder", a
// non OMX component had to be in this list for the video
// editor code to work... but it cannot actually be instantiated
// using MediaCodec.
Log.i("skipping '" + info.getName() + "'.");
continue;
}
String[] supportedTypes = info.getSupportedTypes();
for (String type : supportedTypes) {
if (type.equalsIgnoreCase(mime)) {
names.push(info.getName());
break;
}
}
}
}
// TODO: maybe return null or throw exception
return names;
}
use of android.media.MediaCodecInfo in project android_frameworks_base by ResurrectionRemix.
the class MediaCodecList method initCodecList.
private static final void initCodecList() {
synchronized (sInitLock) {
if (sRegularCodecInfos == null) {
int count = native_getCodecCount();
ArrayList<MediaCodecInfo> regulars = new ArrayList<MediaCodecInfo>();
ArrayList<MediaCodecInfo> all = new ArrayList<MediaCodecInfo>();
for (int index = 0; index < count; index++) {
try {
MediaCodecInfo info = getNewCodecInfoAt(index);
all.add(info);
info = info.makeRegular();
if (info != null) {
regulars.add(info);
}
} catch (Exception e) {
Log.e(TAG, "Could not get codec capabilities", e);
}
}
sRegularCodecInfos = regulars.toArray(new MediaCodecInfo[regulars.size()]);
sAllCodecInfos = all.toArray(new MediaCodecInfo[all.size()]);
}
}
}
use of android.media.MediaCodecInfo in project android_frameworks_base by ResurrectionRemix.
the class CpuVideoTrackDecoder method findDecoderCodec.
/**
* Looks for a codec with the specified requirements.
*
* The set of codecs will be filtered down to those that meet the following requirements:
* <ol>
* <li>The codec is a decoder.</li>
* <li>The codec can decode a video of the specified format.</li>
* <li>The codec can decode to one of the specified color formats.</li>
* </ol>
* If multiple codecs are found, the one with the preferred color-format is taken. Color format
* preference is determined by the order of their appearance in the color format array.
*
* @param format The format the codec must decode.
* @param requiredColorFormats Array of target color spaces ordered by preference.
* @return A codec that meets the requirements, or null if no such codec was found.
*/
private static MediaCodec findDecoderCodec(MediaFormat format, int[] requiredColorFormats) {
TreeMap<Integer, String> candidateCodecs = new TreeMap<Integer, String>();
SparseIntArray colorPriorities = intArrayToPriorityMap(requiredColorFormats);
for (int i = 0; i < MediaCodecList.getCodecCount(); ++i) {
// Get next codec
MediaCodecInfo info = MediaCodecList.getCodecInfoAt(i);
// Check that this is a decoder
if (info.isEncoder()) {
continue;
}
// Check if this codec can decode the video in question
String requiredType = format.getString(MediaFormat.KEY_MIME);
String[] supportedTypes = info.getSupportedTypes();
Set<String> typeSet = new HashSet<String>(Arrays.asList(supportedTypes));
// Check if it can decode to one of the required color formats
if (typeSet.contains(requiredType)) {
CodecCapabilities capabilities = info.getCapabilitiesForType(requiredType);
for (int supportedColorFormat : capabilities.colorFormats) {
if (colorPriorities.indexOfKey(supportedColorFormat) >= 0) {
int priority = colorPriorities.get(supportedColorFormat);
candidateCodecs.put(priority, info.getName());
}
}
}
}
// Pick the best codec (with the highest color priority)
if (candidateCodecs.isEmpty()) {
return null;
} else {
String bestCodec = candidateCodecs.firstEntry().getValue();
try {
return MediaCodec.createByCodecName(bestCodec);
} catch (IOException e) {
throw new RuntimeException("failed to create codec for " + bestCodec, e);
}
}
}
use of android.media.MediaCodecInfo in project android_frameworks_base by crdroidandroid.
the class CpuVideoTrackDecoder method findDecoderCodec.
/**
* Looks for a codec with the specified requirements.
*
* The set of codecs will be filtered down to those that meet the following requirements:
* <ol>
* <li>The codec is a decoder.</li>
* <li>The codec can decode a video of the specified format.</li>
* <li>The codec can decode to one of the specified color formats.</li>
* </ol>
* If multiple codecs are found, the one with the preferred color-format is taken. Color format
* preference is determined by the order of their appearance in the color format array.
*
* @param format The format the codec must decode.
* @param requiredColorFormats Array of target color spaces ordered by preference.
* @return A codec that meets the requirements, or null if no such codec was found.
*/
private static MediaCodec findDecoderCodec(MediaFormat format, int[] requiredColorFormats) {
TreeMap<Integer, String> candidateCodecs = new TreeMap<Integer, String>();
SparseIntArray colorPriorities = intArrayToPriorityMap(requiredColorFormats);
for (int i = 0; i < MediaCodecList.getCodecCount(); ++i) {
// Get next codec
MediaCodecInfo info = MediaCodecList.getCodecInfoAt(i);
// Check that this is a decoder
if (info.isEncoder()) {
continue;
}
// Check if this codec can decode the video in question
String requiredType = format.getString(MediaFormat.KEY_MIME);
String[] supportedTypes = info.getSupportedTypes();
Set<String> typeSet = new HashSet<String>(Arrays.asList(supportedTypes));
// Check if it can decode to one of the required color formats
if (typeSet.contains(requiredType)) {
CodecCapabilities capabilities = info.getCapabilitiesForType(requiredType);
for (int supportedColorFormat : capabilities.colorFormats) {
if (colorPriorities.indexOfKey(supportedColorFormat) >= 0) {
int priority = colorPriorities.get(supportedColorFormat);
candidateCodecs.put(priority, info.getName());
}
}
}
}
// Pick the best codec (with the highest color priority)
if (candidateCodecs.isEmpty()) {
return null;
} else {
String bestCodec = candidateCodecs.firstEntry().getValue();
try {
return MediaCodec.createByCodecName(bestCodec);
} catch (IOException e) {
throw new RuntimeException("failed to create codec for " + bestCodec, e);
}
}
}
Aggregations