use of android.media.MediaCodecInfo in project acra by ACRA.
the class MediaCodecListCollector method collectCapabilitiesForType.
/**
* Retrieve capabilities (ColorFormats and CodecProfileLevels) for a
* specific codec type.
*
* @param codecInfo the currently inspected codec
* @param type supported type to collect
* @return the color formats and codec profile levels
* available for a specific codec type.
*/
@NonNull
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private JSONObject collectCapabilitiesForType(@NonNull final MediaCodecInfo codecInfo, @NonNull String type) throws JSONException {
final JSONObject result = new JSONObject();
final MediaCodecInfo.CodecCapabilities codecCapabilities = codecInfo.getCapabilitiesForType(type);
// Color Formats
final int[] colorFormats = codecCapabilities.colorFormats;
if (colorFormats.length > 0) {
JSONArray colorFormatsJson = new JSONArray();
for (int colorFormat : colorFormats) {
colorFormatsJson.put(mColorFormatValues.get(colorFormat));
}
result.put("colorFormats", colorFormatsJson);
}
final CodecType codecType = identifyCodecType(codecInfo);
// Profile Levels
final MediaCodecInfo.CodecProfileLevel[] codecProfileLevels = codecCapabilities.profileLevels;
if (codecProfileLevels.length > 0) {
JSONArray profileLevels = new JSONArray();
for (MediaCodecInfo.CodecProfileLevel codecProfileLevel : codecProfileLevels) {
final int profileValue = codecProfileLevel.profile;
final int levelValue = codecProfileLevel.level;
if (codecType == null) {
// Unknown codec
profileLevels.put(profileValue + '-' + levelValue);
break;
}
switch(codecType) {
case AVC:
profileLevels.put(profileValue + mAVCProfileValues.get(profileValue) + '-' + mAVCLevelValues.get(levelValue));
break;
case H263:
profileLevels.put(mH263ProfileValues.get(profileValue) + '-' + mH263LevelValues.get(levelValue));
break;
case MPEG4:
profileLevels.put(mMPEG4ProfileValues.get(profileValue) + '-' + mMPEG4LevelValues.get(levelValue));
break;
case AAC:
profileLevels.put(mAACProfileValues.get(profileValue));
break;
default:
break;
}
}
result.put("profileLevels", profileLevels);
}
return result;
}
use of android.media.MediaCodecInfo in project acra by ACRA.
the class MediaCodecListCollector method collectMediaCodecList.
/**
* Builds an Element describing the list of available codecs on the device
* with their capabilities (supported Color Formats, Codec Profiles et
* Levels).
*
* @return The media codecs information
*/
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@NonNull
private Element collectMediaCodecList() throws JSONException {
prepare();
final MediaCodecInfo[] infos;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
//noinspection deprecation
final int codecCount = MediaCodecList.getCodecCount();
infos = new MediaCodecInfo[codecCount];
for (int codecIdx = 0; codecIdx < codecCount; codecIdx++) {
//noinspection deprecation
infos[codecIdx] = MediaCodecList.getCodecInfoAt(codecIdx);
}
} else {
infos = new MediaCodecList(MediaCodecList.ALL_CODECS).getCodecInfos();
}
final ComplexElement result = new ComplexElement();
for (int i = 0; i < infos.length; i++) {
final MediaCodecInfo codecInfo = infos[i];
JSONObject codec = new JSONObject();
final String[] supportedTypes = codecInfo.getSupportedTypes();
codec.put("name", codecInfo.getName()).put("isEncoder", codecInfo.isEncoder());
JSONObject supportedTypesJson = new JSONObject();
for (String type : supportedTypes) {
supportedTypesJson.put(type, collectCapabilitiesForType(codecInfo, type));
}
codec.put("supportedTypes", supportedTypesJson);
result.put(String.valueOf(i), codec);
}
return result;
}
use of android.media.MediaCodecInfo in project android_frameworks_base by DirtyUnicorns.
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 DirtyUnicorns.
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 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()]);
}
}
}
Aggregations