use of android.media.MediaCodecInfo in project robolectric by robolectric.
the class MediaCodecInfoBuilderTest method canCreateMediaCodecInfoForEncoder.
@Test
@Config(minSdk = Q)
public void canCreateMediaCodecInfoForEncoder() {
CodecCapabilities codecCapabilities = MediaCodecInfoBuilder.CodecCapabilitiesBuilder.newBuilder().setMediaFormat(AAC_MEDIA_FORMAT).setIsEncoder(true).setProfileLevels(AAC_PROFILE_LEVELS).build();
MediaCodecInfo mediaCodecInfo = MediaCodecInfoBuilder.newBuilder().setName(AAC_ENCODER_NAME).setIsEncoder(true).setIsVendor(true).setCapabilities(codecCapabilities).build();
assertThat(mediaCodecInfo.getName()).isEqualTo(AAC_ENCODER_NAME);
assertThat(mediaCodecInfo.isEncoder()).isTrue();
assertThat(mediaCodecInfo.isVendor()).isTrue();
assertThat(mediaCodecInfo.isSoftwareOnly()).isFalse();
assertThat(mediaCodecInfo.isHardwareAccelerated()).isFalse();
assertThat(mediaCodecInfo.getSupportedTypes()).asList().containsExactly(MIMETYPE_AUDIO_AAC);
assertThat(mediaCodecInfo.getCapabilitiesForType(MIMETYPE_AUDIO_AAC)).isNotNull();
}
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;
}
// TODO: do we still need this?
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 speechutils by Kaljurand.
the class AudioUtils method getAvailableEncoders.
// TODO: use MediaFormat.MIMETYPE_AUDIO_FLAC) on API>=21
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static List<String> getAvailableEncoders(String mime, int sampleRate) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
MediaFormat format = MediaFormatFactory.createMediaFormat(mime, sampleRate);
MediaCodecList mcl = new MediaCodecList(MediaCodecList.REGULAR_CODECS);
String encoderAsStr = mcl.findEncoderForFormat(format);
List<String> encoders = new ArrayList<>();
for (MediaCodecInfo info : mcl.getCodecInfos()) {
if (info.isEncoder()) {
String name = info.getName();
String infoAsStr = name + ": " + TextUtils.join(", ", info.getSupportedTypes());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
infoAsStr += String.format(": %s/%s/%s/%s", info.isHardwareAccelerated(), info.isSoftwareOnly(), info.isAlias(), info.isVendor());
}
if (name.equals(encoderAsStr)) {
infoAsStr = '#' + infoAsStr;
}
encoders.add(infoAsStr);
}
}
return encoders;
}
return Collections.emptyList();
}
use of android.media.MediaCodecInfo in project edx-app-android by edx.
the class MediaCodecUtil method getMediaCodecInfo.
/**
* Returns the best decoder and its capabilities for the given mimeType. If there's no decoder
* returns null.
*/
private static synchronized Pair<MediaCodecInfo, CodecCapabilities> getMediaCodecInfo(String mimeType) {
Pair<MediaCodecInfo, CodecCapabilities> result = codecs.get(mimeType);
if (result != null) {
return result;
}
int numberOfCodecs = MediaCodecList.getCodecCount();
// Note: MediaCodecList is sorted by the framework such that the best decoders come first.
for (int i = 0; i < numberOfCodecs; i++) {
MediaCodecInfo info = MediaCodecList.getCodecInfoAt(i);
String codecName = info.getName();
if (!info.isEncoder() && isOmxCodec(codecName)) {
String[] supportedTypes = info.getSupportedTypes();
for (int j = 0; j < supportedTypes.length; j++) {
String supportedType = supportedTypes[j];
if (supportedType.equalsIgnoreCase(mimeType)) {
result = Pair.create(info, info.getCapabilitiesForType(supportedType));
codecs.put(mimeType, result);
return result;
}
}
}
}
return null;
}
use of android.media.MediaCodecInfo in project libstreaming by fyhertz.
the class CodecManager method findEncodersForMimeType.
/**
* Lists all encoders that claim to support a color format that we know how to use.
* @return A list of those encoders
*/
@SuppressLint("NewApi")
public static synchronized Codec[] findEncodersForMimeType(String mimeType) {
if (sEncoders != null)
return sEncoders;
ArrayList<Codec> encoders = new ArrayList<>();
// We loop through the encoders, apparently this can take up to a sec (testes on a GS3)
for (int j = MediaCodecList.getCodecCount() - 1; j >= 0; j--) {
MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(j);
if (!codecInfo.isEncoder())
continue;
String[] types = codecInfo.getSupportedTypes();
for (int i = 0; i < types.length; i++) {
if (types[i].equalsIgnoreCase(mimeType)) {
try {
MediaCodecInfo.CodecCapabilities capabilities = codecInfo.getCapabilitiesForType(mimeType);
Set<Integer> formats = new HashSet<>();
// And through the color formats supported
for (int k = 0; k < capabilities.colorFormats.length; k++) {
int format = capabilities.colorFormats[k];
for (int l = 0; l < SUPPORTED_COLOR_FORMATS.length; l++) {
if (format == SUPPORTED_COLOR_FORMATS[l]) {
formats.add(format);
}
}
}
Codec codec = new Codec(codecInfo.getName(), (Integer[]) formats.toArray(new Integer[formats.size()]));
encoders.add(codec);
} catch (Exception e) {
Log.wtf(TAG, e);
}
}
}
}
sEncoders = (Codec[]) encoders.toArray(new Codec[encoders.size()]);
return sEncoders;
}
Aggregations