Search in sources :

Example 16 with CodecCapabilities

use of android.media.MediaCodecInfo.CodecCapabilities 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 17 with CodecCapabilities

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

the class MediaCodecInfoBuilderTest method canCreateVideoDecoderCapabilities.

@Test
@Config(minSdk = Q)
public void canCreateVideoDecoderCapabilities() {
    CodecCapabilities codecCapabilities = MediaCodecInfoBuilder.CodecCapabilitiesBuilder.newBuilder().setMediaFormat(VP9_MEDIA_FORMAT).setProfileLevels(VP9_PROFILE_LEVELS).setColorFormats(VP9_COLOR_FORMATS).build();
    assertThat(codecCapabilities.getMimeType()).isEqualTo(MIMETYPE_VIDEO_VP9);
    assertThat(codecCapabilities.getAudioCapabilities()).isNull();
    assertThat(codecCapabilities.getVideoCapabilities()).isNotNull();
    assertThat(codecCapabilities.getEncoderCapabilities()).isNull();
    assertThat(codecCapabilities.isFeatureSupported(CodecCapabilities.FEATURE_SecurePlayback)).isTrue();
    assertThat(codecCapabilities.isFeatureSupported(CodecCapabilities.FEATURE_MultipleFrames)).isTrue();
    assertThat(codecCapabilities.isFeatureSupported(CodecCapabilities.FEATURE_DynamicTimestamp)).isFalse();
    assertThat(codecCapabilities.profileLevels).hasLength(VP9_PROFILE_LEVELS.length);
    assertThat(codecCapabilities.profileLevels).isEqualTo(VP9_PROFILE_LEVELS);
    assertThat(codecCapabilities.colorFormats).hasLength(VP9_COLOR_FORMATS.length);
    assertThat(codecCapabilities.colorFormats).isEqualTo(VP9_COLOR_FORMATS);
}
Also used : CodecCapabilities(android.media.MediaCodecInfo.CodecCapabilities) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 18 with CodecCapabilities

use of android.media.MediaCodecInfo.CodecCapabilities 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 19 with CodecCapabilities

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

the class MediaCodecInfoBuilderTest method canCreateAudioDecoderCapabilities.

@Test
@Config(minSdk = Q)
public void canCreateAudioDecoderCapabilities() {
    CodecCapabilities codecCapabilities = MediaCodecInfoBuilder.CodecCapabilitiesBuilder.newBuilder().setMediaFormat(OPUS_MEDIA_FORMAT).setProfileLevels(new CodecProfileLevel[0]).build();
    assertThat(codecCapabilities.getMimeType()).isEqualTo(MIMETYPE_AUDIO_OPUS);
    assertThat(codecCapabilities.getAudioCapabilities()).isNotNull();
    assertThat(codecCapabilities.getVideoCapabilities()).isNull();
    assertThat(codecCapabilities.getEncoderCapabilities()).isNull();
    assertThat(codecCapabilities.isFeatureSupported(CodecCapabilities.FEATURE_AdaptivePlayback)).isTrue();
    assertThat(codecCapabilities.isFeatureSupported(CodecCapabilities.FEATURE_MultipleFrames)).isFalse();
    assertThat(codecCapabilities.profileLevels).hasLength(0);
}
Also used : CodecProfileLevel(android.media.MediaCodecInfo.CodecProfileLevel) CodecCapabilities(android.media.MediaCodecInfo.CodecCapabilities) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 20 with CodecCapabilities

use of android.media.MediaCodecInfo.CodecCapabilities 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);
        }
    }
}
Also used : IOException(java.io.IOException) TreeMap(java.util.TreeMap) SparseIntArray(android.util.SparseIntArray) MediaCodecInfo(android.media.MediaCodecInfo) CodecCapabilities(android.media.MediaCodecInfo.CodecCapabilities) HashSet(java.util.HashSet)

Aggregations

CodecCapabilities (android.media.MediaCodecInfo.CodecCapabilities)28 MediaCodecInfo (android.media.MediaCodecInfo)15 Test (org.junit.Test)11 Config (org.robolectric.annotation.Config)8 CodecProfileLevel (android.media.MediaCodecInfo.CodecProfileLevel)7 Nullable (androidx.annotation.Nullable)6 ArrayList (java.util.ArrayList)5 SparseIntArray (android.util.SparseIntArray)4 IOException (java.io.IOException)4 HashSet (java.util.HashSet)4 SuppressLint (android.annotation.SuppressLint)3 Point (android.graphics.Point)3 VideoCapabilities (android.media.MediaCodecInfo.VideoCapabilities)3 MediaCodecList (android.media.MediaCodecList)3 TreeMap (java.util.TreeMap)3 SurfaceTexture (android.graphics.SurfaceTexture)2 MediaFormat (android.media.MediaFormat)2 Handler (android.os.Handler)2 Looper (android.os.Looper)2 SystemClock (android.os.SystemClock)2