use of android.media.MediaCodecInfo in project android_packages_apps_Snap by LineageOS.
the class SettingsManager method getSupportedPictureSize.
private List<String> getSupportedPictureSize(int cameraId) {
StreamConfigurationMap map = mCharacteristics.get(cameraId).get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
Size[] sizes = map.getOutputSizes(ImageFormat.JPEG);
List<String> res = new ArrayList<>();
boolean isDeepportrait = getDeepportraitEnabled();
boolean isHeifEnabled = getSavePictureFormat() == HEIF_FORMAT;
if (getQcfaPrefEnabled() && getIsSupportedQcfa(cameraId)) {
res.add(getSupportedQcfaDimension(cameraId));
}
VideoCapabilities heifCap = null;
if (isHeifEnabled) {
MediaCodecList list = new MediaCodecList(MediaCodecList.REGULAR_CODECS);
for (MediaCodecInfo info : list.getCodecInfos()) {
if (info.isEncoder() && info.getName().contains("heic")) {
heifCap = info.getCapabilitiesForType(MediaFormat.MIMETYPE_IMAGE_ANDROID_HEIC).getVideoCapabilities();
Log.d(TAG, "supported heif height range =" + heifCap.getSupportedHeights().toString() + " width range =" + heifCap.getSupportedWidths().toString());
}
}
}
if (sizes != null) {
for (int i = 0; i < sizes.length; i++) {
if (isHeifEnabled && heifCap != null) {
if (!heifCap.getSupportedWidths().contains(sizes[i].getWidth()) || !heifCap.getSupportedHeights().contains(sizes[i].getHeight())) {
continue;
}
}
if (isDeepportrait && (Math.min(sizes[i].getWidth(), sizes[i].getHeight()) < 720 || Math.max(sizes[i].getWidth(), sizes[i].getHeight()) <= 1024)) {
// some reslutions are not supported in deepportrait
continue;
}
res.add(sizes[i].toString());
}
}
Size[] highResSizes = map.getHighResolutionOutputSizes(ImageFormat.JPEG);
if (highResSizes != null) {
for (int i = 0; i < highResSizes.length; i++) {
if (isHeifEnabled && heifCap != null) {
if (!heifCap.getSupportedWidths().contains(highResSizes[i].getWidth()) || !heifCap.getSupportedHeights().contains(highResSizes[i].getHeight())) {
continue;
}
}
res.add(highResSizes[i].toString());
}
}
return res;
}
use of android.media.MediaCodecInfo in project ExoPlayer by google.
the class DefaultCodecFactory method getVideoEncoderSupportedFormat.
@RequiresNonNull("#1.sampleMimeType")
private static Format getVideoEncoderSupportedFormat(Format requestedFormat, List<String> allowedMimeTypes) throws TransformationException {
String mimeType = requestedFormat.sampleMimeType;
Format.Builder formatBuilder = requestedFormat.buildUpon();
// TODO(b/210591626) Implement encoder filtering.
if (!allowedMimeTypes.contains(mimeType) || EncoderUtil.getSupportedEncoders(mimeType).isEmpty()) {
mimeType = allowedMimeTypes.contains(DEFAULT_FALLBACK_MIME_TYPE) ? DEFAULT_FALLBACK_MIME_TYPE : allowedMimeTypes.get(0);
if (EncoderUtil.getSupportedEncoders(mimeType).isEmpty()) {
throw createTransformationException(new IllegalArgumentException("No encoder is found for requested MIME type " + requestedFormat.sampleMimeType), requestedFormat, /* isVideo= */
true, /* isDecoder= */
false, /* mediaCodecName= */
null);
}
}
formatBuilder.setSampleMimeType(mimeType);
MediaCodecInfo encoderInfo = EncoderUtil.getSupportedEncoders(mimeType).get(0);
int width = requestedFormat.width;
int height = requestedFormat.height;
@Nullable Pair<Integer, Integer> encoderSupportedResolution = EncoderUtil.getClosestSupportedResolution(encoderInfo, mimeType, width, height);
if (encoderSupportedResolution == null) {
throw createTransformationException(new IllegalArgumentException("Cannot find fallback resolution for resolution " + width + " x " + height), requestedFormat, /* isVideo= */
true, /* isDecoder= */
false, /* mediaCodecName= */
null);
}
width = encoderSupportedResolution.first;
height = encoderSupportedResolution.second;
formatBuilder.setWidth(width).setHeight(height);
// The frameRate does not affect the resulting frame rate. It affects the encoder's rate control
// algorithm. Setting it too high may lead to video quality degradation.
float frameRate = requestedFormat.frameRate != Format.NO_VALUE ? requestedFormat.frameRate : DEFAULT_FRAME_RATE;
int bitrate = EncoderUtil.getClosestSupportedBitrate(encoderInfo, mimeType, /* bitrate= */
requestedFormat.averageBitrate != Format.NO_VALUE ? requestedFormat.averageBitrate : getSuggestedBitrate(width, height, frameRate));
formatBuilder.setFrameRate(frameRate).setAverageBitrate(bitrate);
@Nullable Pair<Integer, Integer> profileLevel = MediaCodecUtil.getCodecProfileAndLevel(requestedFormat);
if (profileLevel == null || // Transcoding to another MIME type.
!requestedFormat.sampleMimeType.equals(mimeType) || !EncoderUtil.isProfileLevelSupported(encoderInfo, mimeType, /* profile= */
profileLevel.first, /* level= */
profileLevel.second)) {
formatBuilder.setCodecs(null);
}
return formatBuilder.build();
}
use of android.media.MediaCodecInfo in project ExoPlayer by google.
the class EncoderUtil method maybePopulateEncoderInfos.
private static synchronized void maybePopulateEncoderInfos() {
if (encoders.isEmpty()) {
MediaCodecList mediaCodecList = new MediaCodecList(MediaCodecList.ALL_CODECS);
MediaCodecInfo[] allCodecInfos = mediaCodecList.getCodecInfos();
for (MediaCodecInfo mediaCodecInfo : allCodecInfos) {
if (!mediaCodecInfo.isEncoder()) {
continue;
}
encoders.add(mediaCodecInfo);
}
}
}
use of android.media.MediaCodecInfo in project Signal-Android by WhisperSystems.
the class MediaConverter method selectCodec.
/**
* Returns the first codec capable of encoding the specified MIME type, or null if no match was
* found.
*/
static MediaCodecInfo selectCodec(final String mimeType) {
final int numCodecs = MediaCodecList.getCodecCount();
for (int i = 0; i < numCodecs; i++) {
final MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);
if (!codecInfo.isEncoder()) {
continue;
}
final String[] types = codecInfo.getSupportedTypes();
for (String type : types) {
if (type.equalsIgnoreCase(mimeType)) {
return codecInfo;
}
}
}
return null;
}
use of android.media.MediaCodecInfo in project Signal-Android by signalapp.
the class MediaConverter method selectCodec.
/**
* Returns the first codec capable of encoding the specified MIME type, or null if no match was
* found.
*/
static MediaCodecInfo selectCodec(final String mimeType) {
final int numCodecs = MediaCodecList.getCodecCount();
for (int i = 0; i < numCodecs; i++) {
final MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);
if (!codecInfo.isEncoder()) {
continue;
}
final String[] types = codecInfo.getSupportedTypes();
for (String type : types) {
if (type.equalsIgnoreCase(mimeType)) {
return codecInfo;
}
}
}
return null;
}
Aggregations