Search in sources :

Example 71 with MediaCodecInfo

use of android.media.MediaCodecInfo in project robolectric by robolectric.

the class MediaCodecInfoBuilderTest method canCreateMediaCodecInfoWithMultipleFormats.

@Test
@Config(minSdk = Q)
public void canCreateMediaCodecInfoWithMultipleFormats() {
    CodecCapabilities avcEncoderCapabilities = MediaCodecInfoBuilder.CodecCapabilitiesBuilder.newBuilder().setMediaFormat(AVC_MEDIA_FORMAT).setIsEncoder(true).setProfileLevels(AVC_PROFILE_LEVELS).setColorFormats(AVC_COLOR_FORMATS).build();
    CodecCapabilities vp9EncoderCapabilities = MediaCodecInfoBuilder.CodecCapabilitiesBuilder.newBuilder().setMediaFormat(VP9_MEDIA_FORMAT).setIsEncoder(true).setProfileLevels(VP9_PROFILE_LEVELS).setColorFormats(VP9_COLOR_FORMATS).build();
    MediaCodecInfo mediaCodecInfo = MediaCodecInfoBuilder.newBuilder().setName(MULTIFORMAT_ENCODER_NAME).setIsEncoder(true).setCapabilities(avcEncoderCapabilities, vp9EncoderCapabilities).build();
    assertThat(mediaCodecInfo.getName()).isEqualTo(MULTIFORMAT_ENCODER_NAME);
    assertThat(mediaCodecInfo.isEncoder()).isTrue();
    assertThat(mediaCodecInfo.isVendor()).isFalse();
    assertThat(mediaCodecInfo.isSoftwareOnly()).isFalse();
    assertThat(mediaCodecInfo.isHardwareAccelerated()).isFalse();
    assertThat(mediaCodecInfo.getSupportedTypes()).asList().contains(MIMETYPE_VIDEO_AVC);
    assertThat(mediaCodecInfo.getSupportedTypes()).asList().contains(MIMETYPE_VIDEO_VP9);
    assertThat(mediaCodecInfo.getCapabilitiesForType(MIMETYPE_VIDEO_AVC)).isNotNull();
    assertThat(mediaCodecInfo.getCapabilitiesForType(MIMETYPE_VIDEO_VP9)).isNotNull();
}
Also used : MediaCodecInfo(android.media.MediaCodecInfo) CodecCapabilities(android.media.MediaCodecInfo.CodecCapabilities) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 72 with MediaCodecInfo

use of android.media.MediaCodecInfo in project robolectric by robolectric.

the class MediaCodecInfoBuilderTest method canCreateMediaCodecInfoForEncoder.

@Test
@Config(minSdk = Q)
public void canCreateMediaCodecInfoForEncoder() {
    CodecCapabilities codecCapabilities = MediaCodecInfoBuilder.CodecCapabilitiesBuilder.newBuilder().setMediaFormat(AAC_MEDIA_FORMAT).setIsEncoder(true).setProfileLevels(AAC_PROFILE_LEVELS).build();
    MediaCodecInfo mediaCodecInfo = MediaCodecInfoBuilder.newBuilder().setName(AAC_ENCODER_NAME).setIsEncoder(true).setIsVendor(true).setCapabilities(codecCapabilities).build();
    assertThat(mediaCodecInfo.getName()).isEqualTo(AAC_ENCODER_NAME);
    assertThat(mediaCodecInfo.isEncoder()).isTrue();
    assertThat(mediaCodecInfo.isVendor()).isTrue();
    assertThat(mediaCodecInfo.isSoftwareOnly()).isFalse();
    assertThat(mediaCodecInfo.isHardwareAccelerated()).isFalse();
    assertThat(mediaCodecInfo.getSupportedTypes()).asList().containsExactly(MIMETYPE_AUDIO_AAC);
    assertThat(mediaCodecInfo.getCapabilitiesForType(MIMETYPE_AUDIO_AAC)).isNotNull();
}
Also used : MediaCodecInfo(android.media.MediaCodecInfo) CodecCapabilities(android.media.MediaCodecInfo.CodecCapabilities) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 73 with MediaCodecInfo

use of android.media.MediaCodecInfo in project robolectric by robolectric.

the class MediaCodecInfoBuilderTest method mediaCodecInfo_preQ.

@Test
@Config(minSdk = LOLLIPOP)
public void mediaCodecInfo_preQ() {
    if (RuntimeEnvironment.getApiLevel() <= M) {
        MediaCodecList.getCodecCount();
    }
    CodecCapabilities codecCapabilities = MediaCodecInfoBuilder.CodecCapabilitiesBuilder.newBuilder().setMediaFormat(AAC_MEDIA_FORMAT).setIsEncoder(true).setProfileLevels(AAC_PROFILE_LEVELS).build();
    MediaCodecInfo mediaCodecInfo = MediaCodecInfoBuilder.newBuilder().setName(AAC_ENCODER_NAME).setIsEncoder(true).setCapabilities(codecCapabilities).build();
    assertThat(mediaCodecInfo.getName()).isEqualTo(AAC_ENCODER_NAME);
    assertThat(mediaCodecInfo.isEncoder()).isTrue();
    assertThat(mediaCodecInfo.getSupportedTypes()).asList().containsExactly(MIMETYPE_AUDIO_AAC);
    assertThat(mediaCodecInfo.getCapabilitiesForType(MIMETYPE_AUDIO_AAC)).isNotNull();
}
Also used : MediaCodecInfo(android.media.MediaCodecInfo) CodecCapabilities(android.media.MediaCodecInfo.CodecCapabilities) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 74 with MediaCodecInfo

use of android.media.MediaCodecInfo in project ExoPlayer by google.

the class EncoderUtil method getSupportedEncoders.

/**
 * Returns a list of {@link MediaCodecInfo encoders} that support the given {@code mimeType}, or
 * an empty list if there is none.
 */
public static ImmutableList<MediaCodecInfo> getSupportedEncoders(String mimeType) {
    maybePopulateEncoderInfos();
    ImmutableList.Builder<MediaCodecInfo> availableEncoders = new ImmutableList.Builder<>();
    for (int i = 0; i < encoders.size(); i++) {
        MediaCodecInfo encoderInfo = encoders.get(i);
        String[] supportedMimeTypes = encoderInfo.getSupportedTypes();
        for (String supportedMimeType : supportedMimeTypes) {
            if (Ascii.equalsIgnoreCase(supportedMimeType, mimeType)) {
                availableEncoders.add(encoderInfo);
            }
        }
    }
    return availableEncoders.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) MediaCodecInfo(android.media.MediaCodecInfo)

Example 75 with MediaCodecInfo

use of android.media.MediaCodecInfo in project robolectric by robolectric.

the class ShadowMediaCodec method __constructor__.

// Member methods.
@Implementation
protected void __constructor__(String name, boolean nameIsType, boolean encoder) {
    invokeConstructor(MediaCodec.class, realCodec, ClassParameter.from(String.class, name), ClassParameter.from(boolean.class, nameIsType), ClassParameter.from(boolean.class, encoder));
    if (!nameIsType) {
        for (MediaCodecInfo codecInfo : new MediaCodecList(MediaCodecList.ALL_CODECS).getCodecInfos()) {
            if (codecInfo.getName().equals(name)) {
                encoder = codecInfo.isEncoder();
                break;
            }
        }
    }
    CodecConfig codecConfig = encoder ? encoders.getOrDefault(name, DEFAULT_CODEC) : decoders.getOrDefault(name, DEFAULT_CODEC);
    fakeCodec = codecConfig.codec;
    for (int i = 0; i < BUFFER_COUNT; i++) {
        inputBuffers[i] = ByteBuffer.allocateDirect(codecConfig.inputBufferSize).order(ByteOrder.LITTLE_ENDIAN);
        outputBuffers[i] = ByteBuffer.allocateDirect(codecConfig.outputBufferSize).order(ByteOrder.LITTLE_ENDIAN);
        outputBufferInfos[i] = new BufferInfo();
    }
}
Also used : BufferInfo(android.media.MediaCodec.BufferInfo) MediaCodecInfo(android.media.MediaCodecInfo) MediaCodecList(android.media.MediaCodecList) Implementation(org.robolectric.annotation.Implementation)

Aggregations

MediaCodecInfo (android.media.MediaCodecInfo)108 ArrayList (java.util.ArrayList)33 MediaCodecList (android.media.MediaCodecList)22 SuppressLint (android.annotation.SuppressLint)20 MediaFormat (android.media.MediaFormat)17 CodecCapabilities (android.media.MediaCodecInfo.CodecCapabilities)15 IOException (java.io.IOException)14 TargetApi (android.annotation.TargetApi)10 Point (android.graphics.Point)9 VideoCapabilities (android.media.MediaCodecInfo.VideoCapabilities)6 Size (android.util.Size)6 Nullable (androidx.annotation.Nullable)6 HashSet (java.util.HashSet)6 Test (org.junit.Test)6 Config (org.robolectric.annotation.Config)5 SparseIntArray (android.util.SparseIntArray)4 NonNull (androidx.annotation.NonNull)4 TreeMap (java.util.TreeMap)4 MediaCodec (android.media.MediaCodec)3 Bundle (android.os.Bundle)3