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;
}
use of android.media.MediaCodecInfo in project android_packages_apps_Snap by LineageOS.
the class MFNRDrawer method updateBitrateForNonHFR.
private void updateBitrateForNonHFR(int videoEncoder, int bitRate, int height, int width) {
MediaCodecList allCodecs = new MediaCodecList(MediaCodecList.ALL_CODECS);
for (MediaCodecInfo info : allCodecs.getCodecInfos()) {
if (!info.isEncoder() || info.getName().contains("google"))
continue;
for (String type : info.getSupportedTypes()) {
if ((videoEncoder == MediaRecorder.VideoEncoder.MPEG_4_SP && type.equalsIgnoreCase(MediaFormat.MIMETYPE_VIDEO_MPEG4)) || (videoEncoder == MediaRecorder.VideoEncoder.H263 && type.equalsIgnoreCase(MediaFormat.MIMETYPE_VIDEO_H263))) {
CodecCapabilities codecCapabilities = info.getCapabilitiesForType(type);
VideoCapabilities videoCapabilities = codecCapabilities.getVideoCapabilities();
try {
if (videoCapabilities != null) {
Log.d(TAG, "updateBitrate type is " + type + " " + info.getName());
int maxBitRate = videoCapabilities.getBitrateRange().getUpper().intValue();
Log.d(TAG, "maxBitRate is " + maxBitRate + ", profileBitRate is " + bitRate);
mMediaRecorder.setVideoEncodingBitRate(Math.min(bitRate, maxBitRate));
return;
}
} catch (IllegalArgumentException e) {
}
}
}
}
Log.i(TAG, "updateBitrate video bitrate: " + bitRate);
mMediaRecorder.setVideoEncodingBitRate(bitRate);
}
use of android.media.MediaCodecInfo in project android_packages_apps_Snap by LineageOS.
the class SettingsManager method isCurrentVideoResolutionSupportedByEncoder.
private boolean isCurrentVideoResolutionSupportedByEncoder(MediaCodecInfo info) {
boolean supported = false;
ListPreference videoQuality = mPreferenceGroup.findPreference(KEY_VIDEO_QUALITY);
if (videoQuality == null)
return supported;
String videoSizeStr = videoQuality.getValue();
if (videoSizeStr != null) {
Size videoSize = parseSize(videoSizeStr);
String[] supportedTypes = info.getSupportedTypes();
MediaCodecInfo.VideoCapabilities capabilities = null;
for (String type : supportedTypes) {
if (type.equalsIgnoreCase(MediaFormat.MIMETYPE_VIDEO_MPEG4) || type.equalsIgnoreCase(MediaFormat.MIMETYPE_VIDEO_H263) || type.equalsIgnoreCase(MediaFormat.MIMETYPE_VIDEO_AVC) || type.equalsIgnoreCase(MediaFormat.MIMETYPE_VIDEO_HEVC)) {
capabilities = info.getCapabilitiesForType(type).getVideoCapabilities();
if (capabilities == null || !capabilities.getSupportedWidths().contains(videoSize.getWidth()) || !capabilities.getSupportedWidths().contains(videoSize.getHeight())) {
return false;
} else {
supported = true;
}
}
}
}
return supported;
}
use of android.media.MediaCodecInfo in project android_packages_apps_Snap by LineageOS.
the class SettingsManager method getSupportedVideoEncoderForAutoTest.
private List<String> getSupportedVideoEncoderForAutoTest(String videoSizeStr) {
ArrayList<String> supported = new ArrayList<String>();
ListPreference videoEncoder = mPreferenceGroup.findPreference(KEY_VIDEO_ENCODER);
if (videoEncoder == null)
return supported;
if (videoEncoder != null) {
String str = null;
MediaCodecList list = new MediaCodecList(MediaCodecList.ALL_CODECS);
MediaCodecInfo[] codecInfos = list.getCodecInfos();
for (MediaCodecInfo info : codecInfos) {
if (info.isEncoder()) {
int type = SettingTranslation.getVideoEncoderType(info.getSupportedTypes()[0]);
if (type != -1) {
str = SettingTranslation.getVideoEncoder(type);
if (isCurrentVideoResolutionSupportedByEncoder(info)) {
supported.add(str);
}
}
}
}
}
return supported;
}
Aggregations