use of android.media.MediaCodecInfo in project aws-sdk-android by aws-amplify.
the class DefaultCameraConfigurationHelper method getSupportedCameraConfiguration.
public static CameraMediaSourceConfiguration.Builder getSupportedCameraConfiguration(final Context context, final String cameraId) {
final CameraCharacteristics cameraInfo = getCameraInfo(context, cameraId);
final Size supportedResolution = getSupportedResolution(context, cameraId);
final MediaCodecInfo supportedEncoder = getSupportedEncoder();
final String encoderMimeType = getMimeType(supportedEncoder);
final boolean isHardwareAccelerated = VideoEncoderUtils.isHardwareAccelerated(supportedEncoder);
return CameraMediaSourceConfiguration.builder().withCameraId(cameraId).withCameraFacing(getFacing(cameraInfo)).withCameraOrientation(getOrientation(cameraInfo)).withHorizontalResolution(supportedResolution.getWidth()).withVerticalResolution(supportedResolution.getHeight()).withGopDurationMillis(DEFAULT_GOP_DURATION).withFrameTimeScale(DEFAULT_TIMESCALE).withEncodingBitRate(DEFAULT_BITRATE).withFrameRate(DEFAULT_FRAMERATE).withEncodingMimeType(encoderMimeType).withIsEncoderHardwareAccelerated(isHardwareAccelerated);
}
use of android.media.MediaCodecInfo in project aws-sdk-android by aws-amplify.
the class VideoEncoderUtils method getSupportedMimeTypes.
/**
* Returns a list of mime types for supported encoders. For each mime type in the list
* there is an encoder which you can use which supports it,
* and accepts the frames in YUV_420_Flexible format
*/
public static List<MimeType> getSupportedMimeTypes() {
final Set<MimeType> suportedMimeTypes = EnumSet.noneOf(MimeType.class);
final List<MediaCodecInfo> encoders = getSystemSupportedEncoders();
for (final MimeType mimeType : MimeType.values()) {
for (final MediaCodecInfo encoder : encoders) {
if (supportsMimeAndYUV420(encoder, mimeType)) {
suportedMimeTypes.add(mimeType);
}
}
}
if (suportedMimeTypes.size() == 0) {
throw new RuntimeException("Unable to find encoders for supported types and image format");
}
return new ArrayList<MimeType>(suportedMimeTypes);
}
use of android.media.MediaCodecInfo in project aws-sdk-android by aws-amplify.
the class VideoEncoderUtils method getSupportedEncoder.
/**
* Tries to get a supported encoder. Defaults to h264 if supported,
* or otherwise returns any supported encoder by the media codec API.
*
* Currently for encoders to work with Kinesis Video they have to
* accept YUV_420_Flexible frames as input
*
* @throws RuntimeException if no supported encoders are found
*/
public static MediaCodecInfo getSupportedEncoder() {
final List<MediaCodecInfo> allSystemEncoders = getSystemSupportedEncoders();
final List<MediaCodecInfo> supportedEncoders = new ArrayList<MediaCodecInfo>();
final List<MediaCodecInfo> supportedHardwareEncoders = new ArrayList<MediaCodecInfo>();
for (final MimeType mimeType : MimeType.values()) {
for (final MediaCodecInfo encoder : allSystemEncoders) {
if (!supportsMimeAndYUV420(encoder, mimeType)) {
continue;
}
supportedEncoders.add(encoder);
if (isHardwareAccelerated(encoder)) {
supportedHardwareEncoders.add(encoder);
}
}
}
if (supportedEncoders.size() == 0) {
throw new RuntimeException("Could not found a supported encoder");
}
return tryChooseBestEncoder(supportedEncoders, supportedHardwareEncoders);
}
use of android.media.MediaCodecInfo in project platform_frameworks_base by android.
the class MediaCodecList method initCodecList.
private static final void initCodecList() {
synchronized (sInitLock) {
if (sRegularCodecInfos == null) {
int count = native_getCodecCount();
ArrayList<MediaCodecInfo> regulars = new ArrayList<MediaCodecInfo>();
ArrayList<MediaCodecInfo> all = new ArrayList<MediaCodecInfo>();
for (int index = 0; index < count; index++) {
try {
MediaCodecInfo info = getNewCodecInfoAt(index);
all.add(info);
info = info.makeRegular();
if (info != null) {
regulars.add(info);
}
} catch (Exception e) {
Log.e(TAG, "Could not get codec capabilities", e);
}
}
sRegularCodecInfos = regulars.toArray(new MediaCodecInfo[regulars.size()]);
sAllCodecInfos = all.toArray(new MediaCodecInfo[all.size()]);
}
}
}
use of android.media.MediaCodecInfo in project platform_frameworks_base by android.
the class CpuVideoTrackDecoder method findDecoderCodec.
/**
* Looks for a codec with the specified requirements.
*
* The set of codecs will be filtered down to those that meet the following requirements:
* <ol>
* <li>The codec is a decoder.</li>
* <li>The codec can decode a video of the specified format.</li>
* <li>The codec can decode to one of the specified color formats.</li>
* </ol>
* If multiple codecs are found, the one with the preferred color-format is taken. Color format
* preference is determined by the order of their appearance in the color format array.
*
* @param format The format the codec must decode.
* @param requiredColorFormats Array of target color spaces ordered by preference.
* @return A codec that meets the requirements, or null if no such codec was found.
*/
private static MediaCodec findDecoderCodec(MediaFormat format, int[] requiredColorFormats) {
TreeMap<Integer, String> candidateCodecs = new TreeMap<Integer, String>();
SparseIntArray colorPriorities = intArrayToPriorityMap(requiredColorFormats);
for (int i = 0; i < MediaCodecList.getCodecCount(); ++i) {
// Get next codec
MediaCodecInfo info = MediaCodecList.getCodecInfoAt(i);
// Check that this is a decoder
if (info.isEncoder()) {
continue;
}
// Check if this codec can decode the video in question
String requiredType = format.getString(MediaFormat.KEY_MIME);
String[] supportedTypes = info.getSupportedTypes();
Set<String> typeSet = new HashSet<String>(Arrays.asList(supportedTypes));
// Check if it can decode to one of the required color formats
if (typeSet.contains(requiredType)) {
CodecCapabilities capabilities = info.getCapabilitiesForType(requiredType);
for (int supportedColorFormat : capabilities.colorFormats) {
if (colorPriorities.indexOfKey(supportedColorFormat) >= 0) {
int priority = colorPriorities.get(supportedColorFormat);
candidateCodecs.put(priority, info.getName());
}
}
}
}
// Pick the best codec (with the highest color priority)
if (candidateCodecs.isEmpty()) {
return null;
} else {
String bestCodec = candidateCodecs.firstEntry().getValue();
try {
return MediaCodec.createByCodecName(bestCodec);
} catch (IOException e) {
throw new RuntimeException("failed to create codec for " + bestCodec, e);
}
}
}
Aggregations