use of android.media.MediaCodecInfo in project libstreaming by fyhertz.
the class CodecManager method findDecodersForMimeType.
/**
* Lists all decoders that claim to support a color format that we know how to use.
* @return A list of those decoders
*/
@SuppressLint("NewApi")
public static synchronized Codec[] findDecodersForMimeType(String mimeType) {
if (sDecoders != null)
return sDecoders;
ArrayList<Codec> decoders = new ArrayList<>();
// We loop through the decoders, 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()]));
decoders.add(codec);
} catch (Exception e) {
Log.wtf(TAG, e);
}
}
}
}
sDecoders = (Codec[]) decoders.toArray(new Codec[decoders.size()]);
// We will use the decoder from google first, it seems to work properly on many phones
for (int i = 0; i < sDecoders.length; i++) {
if (sDecoders[i].name.equalsIgnoreCase("omx.google.h264.decoder")) {
Codec codec = sDecoders[0];
sDecoders[0] = sDecoders[i];
sDecoders[i] = codec;
}
}
return sDecoders;
}
use of android.media.MediaCodecInfo in project LanSoEditor_common by LanSoSdk.
the class VideoEditor method getColorFormat.
/**
* 增加获取手机SoC硬件支持的YUV格式, 有些手机不支持YUV420,但支持NV21.
* 2018年1月10日14:52:27增加
* @return
*/
public static String getColorFormat() {
MediaCodecInfo codecInfo = selectCodec(MIME_TYPE_AVC);
if (codecInfo == null) {
Log.e(TAG, "Unable to find an appropriate codec for " + MIME_TYPE_AVC);
return "yuv420p";
}
String str = selectColorFormat(codecInfo, MIME_TYPE_AVC);
Log.i(TAG, "video editor color format use ID:--->" + str);
return str;
}
use of android.media.MediaCodecInfo in project LanSoEditor_common by LanSoSdk.
the class VideoEditor method selectCodec.
private static MediaCodecInfo selectCodec(String mimeType) {
int numCodecs = MediaCodecList.getCodecCount();
for (int i = 0; i < numCodecs; i++) {
MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);
if (!codecInfo.isEncoder()) {
continue;
}
String[] types = codecInfo.getSupportedTypes();
for (int j = 0; j < types.length; j++) {
if (types[j].equalsIgnoreCase(mimeType)) {
return codecInfo;
}
}
}
return null;
}
use of android.media.MediaCodecInfo in project Pix-Art-Messenger by kriztan.
the class MediaCodecListCompat method findCoderForFormat.
private String findCoderForFormat(MediaFormat format, boolean findEncoder) {
String mimeType = format.getString(MediaFormat.KEY_MIME);
Iterator<MediaCodecInfo> iterator = new MediaCodecInfoIterator();
while (iterator.hasNext()) {
MediaCodecInfo codecInfo = iterator.next();
if (codecInfo.isEncoder() != findEncoder)
continue;
if (Arrays.asList(codecInfo.getSupportedTypes()).contains(mimeType)) {
return codecInfo.getName();
}
}
return null;
}
use of android.media.MediaCodecInfo in project EasyPlayer-RTMP-Android by EasyDSS.
the class EasyPlayerClient method codecName.
private static String codecName() {
ArrayList<String> array = new ArrayList<>();
int numCodecs = MediaCodecList.getCodecCount();
for (int i1 = 0; i1 < numCodecs; i1++) {
MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i1);
if (codecInfo.isEncoder()) {
continue;
}
if (codecMatch("video/avc", codecInfo)) {
String name = codecInfo.getName();
Log.d("DECODER", String.format("decoder:%s", name));
array.add(name);
}
}
// }
if (array.isEmpty()) {
return "";
}
return array.get(0);
}
Aggregations