use of android.media.MediaCodecInfo in project Telegram-FOSS by Telegram-FOSS-Team.
the class HardwareVideoEncoderFactory method getSupportedCodecs.
@Override
public VideoCodecInfo[] getSupportedCodecs() {
// HW encoding is not supported below Android Kitkat.
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT || VoIPService.getSharedInstance() != null && VoIPService.getSharedInstance().groupCall != null) {
return new VideoCodecInfo[0];
}
List<VideoCodecInfo> supportedCodecInfos = new ArrayList<VideoCodecInfo>();
// VP8, VP9, H.265(optional), H264 (high profile), and H264 (baseline profile).
for (VideoCodecMimeType type : new VideoCodecMimeType[] { VideoCodecMimeType.VP8, VideoCodecMimeType.VP9, VideoCodecMimeType.H264, VideoCodecMimeType.H265 }) {
MediaCodecInfo codec = findCodecForType(type);
if (codec != null) {
String name = type.name();
// supported by the decoder.
if (type == VideoCodecMimeType.H264 && isH264HighProfileSupported(codec)) {
supportedCodecInfos.add(new VideoCodecInfo(name, MediaCodecUtils.getCodecProperties(type, /* highProfile= */
true)));
}
supportedCodecInfos.add(new VideoCodecInfo(name, MediaCodecUtils.getCodecProperties(type, /* highProfile= */
false)));
}
}
return supportedCodecInfos.toArray(new VideoCodecInfo[supportedCodecInfos.size()]);
}
use of android.media.MediaCodecInfo in project LiTr by linkedin.
the class CodecUtils method getHighestSupportedProfile.
/**
* Attempts to find highest supported codec profile for a given MIME type. Iterates through all codecs available,
* filters for codecs that support provided MIME type and picks highest profile available among them.
* Works only on API level 21 and above (Lollipop +)
* @param mimeType media MIME type
* @param isEncoder search through encoder codecs if true, decoder codecs if false
* @param targetProfile optional upper limit for codec profile, one of {@link android.media.MediaCodecInfo.CodecProfileLevel} profile constants,
* or UNDEFINED_VALUE for highest supported codec profile
* @return a {@link android.media.MediaCodecInfo.CodecProfileLevel} profile constant of successful, UNDEFINED_VALUE otherwise
*/
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
public static int getHighestSupportedProfile(@NonNull String mimeType, boolean isEncoder, int targetProfile) {
int highestSupportedProfile = UNDEFINED_VALUE;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
int maxProfileRank = targetProfile == UNDEFINED_VALUE ? Integer.MAX_VALUE : getProfileRank(mimeType, targetProfile);
MediaCodecList mediaCodecList = new MediaCodecList(MediaCodecList.ALL_CODECS);
for (MediaCodecInfo mediaCodecInfo : mediaCodecList.getCodecInfos()) {
if (supportsType(mediaCodecInfo, mimeType) && mediaCodecInfo.isEncoder() == isEncoder) {
MediaCodecInfo.CodecCapabilities codecCapabilities = mediaCodecInfo.getCapabilitiesForType(mimeType);
for (MediaCodecInfo.CodecProfileLevel codecProfileLevel : codecCapabilities.profileLevels) {
if (getProfileRank(mimeType, codecProfileLevel.profile) > getProfileRank(mimeType, highestSupportedProfile) && getProfileRank(mimeType, codecProfileLevel.profile) <= maxProfileRank) {
highestSupportedProfile = codecProfileLevel.profile;
}
}
}
}
}
return highestSupportedProfile;
}
use of android.media.MediaCodecInfo in project CameraView by natario1.
the class DeviceEncoders method getDeviceEncoders.
/**
* Collects all the device encoders, which means excluding decoders.
* @return encoders
*/
@NonNull
@SuppressLint("NewApi")
@VisibleForTesting
List<MediaCodecInfo> getDeviceEncoders() {
ArrayList<MediaCodecInfo> results = new ArrayList<>();
MediaCodecInfo[] array = new MediaCodecList(MediaCodecList.REGULAR_CODECS).getCodecInfos();
for (MediaCodecInfo info : array) {
if (info.isEncoder())
results.add(info);
}
return results;
}
use of android.media.MediaCodecInfo in project deltachat-android by deltachat.
the class VideoRecoder method selectColorFormat.
@SuppressLint("NewApi")
private static int selectColorFormat(MediaCodecInfo codecInfo, String mimeType) {
MediaCodecInfo.CodecCapabilities capabilities = codecInfo.getCapabilitiesForType(mimeType);
int lastColorFormat = 0;
for (int i = 0; i < capabilities.colorFormats.length; i++) {
int colorFormat = capabilities.colorFormats[i];
if (isRecognizedFormat(colorFormat)) {
lastColorFormat = colorFormat;
if (!(codecInfo.getName().equals("OMX.SEC.AVC.Encoder") && colorFormat == 19)) {
return colorFormat;
}
}
}
return lastColorFormat;
}
use of android.media.MediaCodecInfo in project AndroidUSBCamera by jiangdongguo.
the class MediaAudioEncoder method prepare.
@Override
protected void prepare() throws IOException {
if (DEBUG)
Log.v(TAG, "prepare:");
mTrackIndex = -1;
mMuxerStarted = mIsEOS = false;
// prepare MediaCodec for AAC encoding of audio data from inernal mic.
final MediaCodecInfo audioCodecInfo = selectAudioCodec(MIME_TYPE);
if (audioCodecInfo == null) {
Log.e(TAG, "Unable to find an appropriate codec for " + MIME_TYPE);
return;
}
if (DEBUG)
Log.i(TAG, "selected codec: " + audioCodecInfo.getName());
final MediaFormat audioFormat = MediaFormat.createAudioFormat(MIME_TYPE, SAMPLE_RATE, 1);
audioFormat.setInteger(MediaFormat.KEY_AAC_PROFILE, MediaCodecInfo.CodecProfileLevel.AACObjectLC);
audioFormat.setInteger(MediaFormat.KEY_CHANNEL_MASK, AudioFormat.CHANNEL_IN_MONO);
audioFormat.setInteger(MediaFormat.KEY_BIT_RATE, BIT_RATE);
audioFormat.setInteger(MediaFormat.KEY_CHANNEL_COUNT, 1);
// audioFormat.setLong(MediaFormat.KEY_DURATION, (long)durationInMs );
if (DEBUG)
Log.i(TAG, "format: " + audioFormat);
mMediaCodec = MediaCodec.createEncoderByType(MIME_TYPE);
mMediaCodec.configure(audioFormat, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
mMediaCodec.start();
if (DEBUG)
Log.i(TAG, "prepare finishing");
if (mListener != null) {
try {
mListener.onPrepared(this);
} catch (final Exception e) {
Log.e(TAG, "prepare:", e);
}
}
}
Aggregations