Search in sources :

Example 26 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 27 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 28 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 29 with MediaCodecInfo

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()]);
        }
    }
}
Also used : MediaCodecInfo(android.media.MediaCodecInfo) ArrayList(java.util.ArrayList)

Example 30 with MediaCodecInfo

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);
        }
    }
}
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

MediaCodecInfo (android.media.MediaCodecInfo)45 ArrayList (java.util.ArrayList)16 CodecCapabilities (android.media.MediaCodecInfo.CodecCapabilities)14 MediaCodecList (android.media.MediaCodecList)11 Point (android.graphics.Point)7 VideoCapabilities (android.media.MediaCodecInfo.VideoCapabilities)6 HashSet (java.util.HashSet)6 SuppressLint (android.annotation.SuppressLint)5 TargetApi (android.annotation.TargetApi)5 Size (android.util.Size)5 IOException (java.io.IOException)5 Test (org.junit.Test)5 Config (org.robolectric.annotation.Config)5 MediaFormat (android.media.MediaFormat)4 SparseIntArray (android.util.SparseIntArray)4 TreeMap (java.util.TreeMap)4 StreamConfigurationMap (android.hardware.camera2.params.StreamConfigurationMap)2 CodecProfileLevel (android.media.MediaCodecInfo.CodecProfileLevel)2 NonNull (android.support.annotation.NonNull)2 Range (android.util.Range)2