use of android.media.MediaCodecInfo in project android_packages_apps_Snap by LineageOS.
the class SettingsManager method getSupportedHFRForAutoTest.
private List<String> getSupportedHFRForAutoTest(String videoSizeStr) {
ArrayList<String> supported = new ArrayList<String>();
ListPreference videoEncoder = mPreferenceGroup.findPreference(KEY_VIDEO_ENCODER);
if (videoEncoder == null)
return supported;
int videoEncoderNum = SettingTranslation.getVideoEncoder(videoEncoder.getValue());
VideoCapabilities videoCapabilities = null;
boolean findVideoEncoder = false;
if (videoSizeStr != null) {
Size videoSize = parseSize(videoSizeStr);
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 ((videoEncoderNum == MediaRecorder.VideoEncoder.MPEG_4_SP && type.equalsIgnoreCase(MediaFormat.MIMETYPE_VIDEO_MPEG4)) || (videoEncoderNum == MediaRecorder.VideoEncoder.H263 && type.equalsIgnoreCase(MediaFormat.MIMETYPE_VIDEO_H263)) || (videoEncoderNum == MediaRecorder.VideoEncoder.H264 && type.equalsIgnoreCase(MediaFormat.MIMETYPE_VIDEO_AVC)) || (videoEncoderNum == MediaRecorder.VideoEncoder.HEVC && type.equalsIgnoreCase(MediaFormat.MIMETYPE_VIDEO_HEVC))) {
CodecCapabilities codecCapabilities = info.getCapabilitiesForType(type);
videoCapabilities = codecCapabilities.getVideoCapabilities();
findVideoEncoder = true;
break;
}
}
if (findVideoEncoder)
break;
}
try {
Range[] range = getSupportedHighSpeedVideoFPSRange(mCameraId, videoSize);
for (Range r : range) {
// minmal FPS needs to be equal to maximum FPS
if ((int) r.getUpper() == (int) r.getLower()) {
if (videoCapabilities != null) {
if (videoCapabilities.areSizeAndRateSupported(videoSize.getWidth(), videoSize.getHeight(), (int) r.getUpper())) {
supported.add("hfr" + String.valueOf(r.getUpper()));
supported.add("hsr" + String.valueOf(r.getUpper()));
}
}
}
}
} catch (IllegalArgumentException ex) {
Log.w(TAG, "HFR is not supported for this resolution " + ex);
}
if (mExtendedHFRSize != null && mExtendedHFRSize.length >= 3) {
for (int i = 0; i < mExtendedHFRSize.length; i += 3) {
String item = "hfr" + mExtendedHFRSize[i + 2];
if (!supported.contains(item) && videoSize.getWidth() <= mExtendedHFRSize[i] && videoSize.getHeight() <= mExtendedHFRSize[i + 1]) {
if (videoCapabilities != null) {
if (videoCapabilities.areSizeAndRateSupported(videoSize.getWidth(), videoSize.getHeight(), mExtendedHFRSize[i + 2])) {
supported.add(item);
supported.add("hsr" + mExtendedHFRSize[i + 2]);
}
}
}
}
}
}
return supported;
}
use of android.media.MediaCodecInfo in project android_packages_apps_Snap by LineageOS.
the class SettingsManager method getSupportedHighFrameRate.
private List<String> getSupportedHighFrameRate() {
ArrayList<String> supported = new ArrayList<String>();
supported.add("off");
ListPreference videoQuality = mPreferenceGroup.findPreference(KEY_VIDEO_QUALITY);
ListPreference videoEncoder = mPreferenceGroup.findPreference(KEY_VIDEO_ENCODER);
if (videoQuality == null || videoEncoder == null)
return supported;
String videoSizeStr = videoQuality.getValue();
int videoEncoderNum = SettingTranslation.getVideoEncoder(videoEncoder.getValue());
VideoCapabilities videoCapabilities = null;
boolean findVideoEncoder = false;
if (videoSizeStr != null) {
Size videoSize = parseSize(videoSizeStr);
boolean above1080p = videoSize.getHeight() * videoSize.getWidth() > 1920 * 1080;
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 ((videoEncoderNum == MediaRecorder.VideoEncoder.MPEG_4_SP && type.equalsIgnoreCase(MediaFormat.MIMETYPE_VIDEO_MPEG4)) || (videoEncoderNum == MediaRecorder.VideoEncoder.H263 && type.equalsIgnoreCase(MediaFormat.MIMETYPE_VIDEO_H263)) || (videoEncoderNum == MediaRecorder.VideoEncoder.H264 && type.equalsIgnoreCase(MediaFormat.MIMETYPE_VIDEO_AVC)) || (videoEncoderNum == MediaRecorder.VideoEncoder.HEVC && type.equalsIgnoreCase(MediaFormat.MIMETYPE_VIDEO_HEVC))) {
CodecCapabilities codecCapabilities = info.getCapabilitiesForType(type);
videoCapabilities = codecCapabilities.getVideoCapabilities();
findVideoEncoder = true;
break;
}
}
if (findVideoEncoder)
break;
}
try {
Range[] range = getSupportedHighSpeedVideoFPSRange(mCameraId, videoSize);
String rate;
for (Range r : range) {
// minmal FPS needs to be equal to maximum FPS
if ((int) r.getUpper() == (int) r.getLower()) {
if (videoCapabilities != null) {
if (videoCapabilities.areSizeAndRateSupported(videoSize.getWidth(), videoSize.getHeight(), (int) r.getUpper())) {
rate = String.valueOf(r.getUpper());
supported.add("hfr" + rate);
supported.add("hsr" + rate);
mIsHFRSupportedOnCurrentResolution = true;
}
}
}
}
} catch (IllegalArgumentException ex) {
Log.w(TAG, "HFR is not supported for this resolution " + ex);
mIsHFRSupportedOnCurrentResolution = false;
}
if (mExtendedHFRSize != null && mExtendedHFRSize.length >= 3) {
for (int i = 0; i < mExtendedHFRSize.length; i += 3) {
String item = "hfr" + mExtendedHFRSize[i + 2];
if (!supported.contains(item) && videoSize.getWidth() <= mExtendedHFRSize[i] && videoSize.getHeight() <= mExtendedHFRSize[i + 1]) {
if (videoCapabilities != null) {
if (videoCapabilities.areSizeAndRateSupported(videoSize.getWidth(), videoSize.getHeight(), mExtendedHFRSize[i + 2])) {
supported.add(item);
supported.add("hsr" + mExtendedHFRSize[i + 2]);
}
}
}
}
}
}
return supported;
}
use of android.media.MediaCodecInfo in project android_packages_apps_Snap by LineageOS.
the class SettingsManager method getSupportedVideoEncoders.
private List<String> getSupportedVideoEncoders() {
ArrayList<String> supported = new ArrayList<String>();
supported.add(SettingTranslation.getVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT));
String str = null;
MediaCodecList list = new MediaCodecList(MediaCodecList.ALL_CODECS);
MediaCodecInfo[] codecInfos = list.getCodecInfos();
for (MediaCodecInfo info : codecInfos) {
if (!info.isEncoder() || info.getName().contains("google"))
continue;
Log.d(TAG, "name=" + info.getName());
if (info.getSupportedTypes().length > 0 && info.getSupportedTypes()[0] != null) {
for (String t : info.getSupportedTypes()) {
Log.d(TAG, "type=" + t);
}
int type = SettingTranslation.getVideoEncoderType(info.getSupportedTypes()[0]);
if (type != -1) {
str = SettingTranslation.getVideoEncoder(type);
Log.d(TAG, "type=" + type + " str=" + str);
if (isCurrentVideoResolutionSupportedByEncoder(info)) {
supported.add(str);
}
}
}
}
return supported;
}
use of android.media.MediaCodecInfo in project haven by guardianproject.
the class VideoEncoder method encodeDecodeVideoFromBuffer.
/**
* Tests encoding and subsequently decoding video from frames generated into
* a buffer.
*/
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
@SuppressLint("InlinedApi")
public boolean encodeDecodeVideoFromBuffer() throws Exception {
mLargestColorDelta = -1;
boolean result = true;
try {
MediaCodecInfo codecInfo = selectCodec(MIME_TYPE);
if (codecInfo == null) {
// Don't fail CTS if they don't have an AVC codec
Log.e(TAG, "Unable to find an appropriate codec for " + MIME_TYPE);
return false;
}
if (VERBOSE)
Log.d(TAG, "found codec: " + codecInfo.getName());
int colorFormat;
try {
colorFormat = selectColorFormat(codecInfo, MIME_TYPE);
} catch (Exception e) {
colorFormat = MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420SemiPlanar;
}
if (VERBOSE)
Log.d(TAG, "found colorFormat: " + colorFormat);
// We avoid the device-specific limitations on width and height by
// using values that
// are multiples of 16, which all tested devices seem to be able to
// handle.
MediaFormat format = MediaFormat.createVideoFormat(MIME_TYPE, mWidth, mHeight);
// Set some properties. Failing to specify some of these can cause
// the MediaCodec
// configure() call to throw an unhelpful exception.
format.setInteger(MediaFormat.KEY_COLOR_FORMAT, colorFormat);
format.setInteger(MediaFormat.KEY_BIT_RATE, mBitRate);
format.setInteger(MediaFormat.KEY_FRAME_RATE, FRAME_RATE);
format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, IFRAME_INTERVAL);
if (VERBOSE)
Log.d(TAG, "format: " + format);
// Create a MediaCodec for the desired codec, then configure it as
// an encoder with
// our desired properties.
mEncoder = MediaCodec.createByCodecName(codecInfo.getName());
mEncoder.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
mEncoder.start();
// Create a MediaCodec for the decoder, just based on the MIME type.
// The various
// format details will be passed through the csd-0 meta-data later
// on.
String outputPath = outputFile.getAbsolutePath();
try {
mMuxer = new MediaMuxer(outputPath, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
} catch (IOException ioe) {
// throw new RuntimeException("MediaMuxer creation failed",
// ioe);
ioe.printStackTrace();
}
result = doEncodeDecodeVideoFromBuffer(mEncoder, colorFormat);
} finally {
if (mEncoder != null) {
mEncoder.stop();
mEncoder.release();
}
if (mMuxer != null) {
mMuxer.stop();
mMuxer.release();
}
if (VERBOSE)
Log.i(TAG, "Largest color delta: " + mLargestColorDelta);
}
return result;
}
use of android.media.MediaCodecInfo in project haven by guardianproject.
the class VideoEncoder method selectCodec.
/**
* Returns the first codec capable of encoding the specified MIME type, or
* null if no match was found.
*/
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;
}
Aggregations