Java Code Examples for android.media.MediaCodecList#ALL_CODECS

The following examples show how to use android.media.MediaCodecList#ALL_CODECS . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DeviceUtil.java    From LiTr with BSD 2-Clause "Simplified" License 7 votes vote down vote up
@NonNull
public static String getAvcDecoderCapabilities(@NonNull Context context) {
    StringBuilder codecListStr = new StringBuilder();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        MediaCodecList mediaCodecList = new MediaCodecList(MediaCodecList.ALL_CODECS);
        for (MediaCodecInfo mediaCodecInfo: mediaCodecList.getCodecInfos()) {
            String codecName = mediaCodecInfo.getName().toLowerCase(Locale.ROOT); {
                if ((codecName.contains(TYPE_AVC) || codecName.contains(TYPE_H264)) && codecName.contains(TYPE_DECODER)) {
                    codecListStr.append(printCodecCapabilities(context, mediaCodecInfo));
                }
            }
        }
    }

    return codecListStr.toString();
}
 
Example 2
Source File: MediaVideoEncoder.java    From GPUVideo-android with MIT License 6 votes vote down vote up
/**
 * select the first codec that match a specific MIME type
 *
 * @param mimeType
 * @return null if no codec matched
 */
private static MediaCodecInfo selectVideoCodec(final String mimeType) {
    Log.v(TAG, "selectVideoCodec:");

    // get the list of available codecs
    MediaCodecList list = new MediaCodecList(MediaCodecList.ALL_CODECS);
    MediaCodecInfo[] codecInfos = list.getCodecInfos();

    final int numCodecs = codecInfos.length;
    for (int i = 0; i < numCodecs; i++) {
        final MediaCodecInfo codecInfo = codecInfos[i];

        if (!codecInfo.isEncoder()) {    // skipp decoder
            continue;
        }
        // select first codec that match a specific MIME type and color format
        final String[] types = codecInfo.getSupportedTypes();
        for (int j = 0; j < types.length; j++) {
            if (types[j].equalsIgnoreCase(mimeType)) {
                Log.i(TAG, "codec:" + codecInfo.getName() + ",MIME=" + types[j]);
                final int format = selectColorFormat(codecInfo, mimeType);
                if (format > 0) {
                    return codecInfo;
                }
            }
        }
    }
    return null;
}
 
Example 3
Source File: VideoUtils.java    From SoloPi with Apache License 2.0 6 votes vote down vote up
/**
 * Find an encoder supported specified MIME type
 *
 * @return Returns empty array if not found any encoder supported specified MIME type
 */
public static MediaCodecInfo[] findEncodersByType(String mimeType) {
    MediaCodecList codecList = new MediaCodecList(MediaCodecList.ALL_CODECS);
    List<MediaCodecInfo> infos = new ArrayList<>();
    for (MediaCodecInfo info : codecList.getCodecInfos()) {
        if (!info.isEncoder()) {
            continue;
        }
        try {
            MediaCodecInfo.CodecCapabilities cap = info.getCapabilitiesForType(mimeType);
            if (cap == null) continue;
        } catch (IllegalArgumentException e) {
            // unsupported
            continue;
        }
        infos.add(info);
    }

    return infos.toArray(new MediaCodecInfo[infos.size()]);
}
 
Example 4
Source File: Utils.java    From ScreenCapture with MIT License 6 votes vote down vote up
/**
 * Find an encoder supported specified MIME type
 *
 * @return Returns empty array if not found any encoder supported specified MIME type
 */
public static MediaCodecInfo[] findEncodersByType(String mimeType) {
    MediaCodecList codecList = new MediaCodecList(MediaCodecList.ALL_CODECS);
    List<MediaCodecInfo> infos = new ArrayList<>();
    for (MediaCodecInfo info : codecList.getCodecInfos()) {
        if (!info.isEncoder()) {
            continue;
        }
        try {
            MediaCodecInfo.CodecCapabilities cap = info.getCapabilitiesForType(mimeType);
            if (cap == null) continue;
        } catch (IllegalArgumentException e) {
            // unsupported
            continue;
        }
        infos.add(info);
    }

    return infos.toArray(new MediaCodecInfo[infos.size()]);
}
 
Example 5
Source File: MediaCodecUtil.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("nullness:initialization.fields.uninitialized")
public MediaCodecListCompatV21(boolean includeSecure, boolean includeTunneling) {
  codecKind =
      includeSecure || includeTunneling
          ? MediaCodecList.ALL_CODECS
          : MediaCodecList.REGULAR_CODECS;
}
 
Example 6
Source File: DeviceUtil.java    From LiTr with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@NonNull
public static String getCodecList() {
    StringBuilder codecListStr = new StringBuilder();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        MediaCodecList mediaCodecList = new MediaCodecList(MediaCodecList.ALL_CODECS);
        for (MediaCodecInfo mediaCodecInfo: mediaCodecList.getCodecInfos()) {
            codecListStr.append(mediaCodecInfo.getName());
            codecListStr.append('\n');
        }
    }

    return codecListStr.toString();
}
 
Example 7
Source File: DeviceUtil.java    From LiTr with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@NonNull
public static String getAvcEncoderCapabilities(@NonNull Context context) {
    StringBuilder codecListStr = new StringBuilder();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        MediaCodecList mediaCodecList = new MediaCodecList(MediaCodecList.ALL_CODECS);
        for (MediaCodecInfo mediaCodecInfo : mediaCodecList.getCodecInfos()) {
            String codecName = mediaCodecInfo.getName().toLowerCase(Locale.ROOT);
            if ((codecName.contains(TYPE_AVC) || codecName.contains(TYPE_H264)) && codecName.contains(TYPE_ENCODER)) {
                codecListStr.append(printCodecCapabilities(context, mediaCodecInfo));
            }
        }
    }

    return codecListStr.toString();
}
 
Example 8
Source File: MediaVideoEncoder.java    From CameraRecorder-android with MIT License 5 votes vote down vote up
/**
 * select the first codec that match a specific MIME type
 *
 * @param mimeType
 * @return null if no codec matched
 */
private static MediaCodecInfo selectVideoCodec(final String mimeType) {
    Log.v(TAG, "selectVideoCodec:");

    // get the list of available codecs
    MediaCodecList list = new MediaCodecList(MediaCodecList.ALL_CODECS);
    MediaCodecInfo[] codecInfos = list.getCodecInfos();

    final int numCodecs = codecInfos.length;
    for (int i = 0; i < numCodecs; i++) {
        final MediaCodecInfo codecInfo = codecInfos[i];

        if (!codecInfo.isEncoder()) {    // skipp decoder
            continue;
        }
        // select first codec that match a specific MIME type and color format
        final String[] types = codecInfo.getSupportedTypes();
        for (int j = 0; j < types.length; j++) {
            if (types[j].equalsIgnoreCase(mimeType)) {
                Log.i(TAG, "codec:" + codecInfo.getName() + ",MIME=" + types[j]);
                final int format = selectColorFormat(codecInfo, mimeType);
                if (format > 0) {
                    return codecInfo;
                }
            }
        }
    }
    return null;
}
 
Example 9
Source File: CodecUtil.java    From rtmp-rtsp-stream-client-java with Apache License 2.0 5 votes vote down vote up
public static List<MediaCodecInfo> getAllCodecs(boolean filterBroken) {
  List<MediaCodecInfo> mediaCodecInfoList = new ArrayList<>();
  if (Build.VERSION.SDK_INT >= 21) {
    MediaCodecList mediaCodecList = new MediaCodecList(MediaCodecList.ALL_CODECS);
    MediaCodecInfo[] mediaCodecInfos = mediaCodecList.getCodecInfos();
    mediaCodecInfoList.addAll(Arrays.asList(mediaCodecInfos));
  } else {
    int count = MediaCodecList.getCodecCount();
    for (int i = 0; i < count; i++) {
      MediaCodecInfo mci = MediaCodecList.getCodecInfoAt(i);
      mediaCodecInfoList.add(mci);
    }
  }
  return filterBroken ? filterBrokenCodecs(mediaCodecInfoList) : mediaCodecInfoList;
}
 
Example 10
Source File: MediaCodecUtil.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public MediaCodecListCompatV21(boolean includeSecure) {
  codecKind = includeSecure ? MediaCodecList.ALL_CODECS : MediaCodecList.REGULAR_CODECS;
}
 
Example 11
Source File: MediaCodecUtil.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public MediaCodecListCompatV21(boolean includeSecure) {
  codecKind = includeSecure ? MediaCodecList.ALL_CODECS : MediaCodecList.REGULAR_CODECS;
}
 
Example 12
Source File: MediaCodecUtil.java    From K-Sonic with MIT License 4 votes vote down vote up
public MediaCodecListCompatV21(boolean includeSecure) {
  codecKind = includeSecure ? MediaCodecList.ALL_CODECS : MediaCodecList.REGULAR_CODECS;
}
 
Example 13
Source File: MediaCodecUtil.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
public MediaCodecListCompatV21(boolean includeSecure, boolean includeTunneling) {
  codecKind =
      includeSecure || includeTunneling
          ? MediaCodecList.ALL_CODECS
          : MediaCodecList.REGULAR_CODECS;
}
 
Example 14
Source File: MediaCodecUtil.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
public MediaCodecListCompatV21(boolean includeSecure, boolean includeTunneling) {
  codecKind =
      includeSecure || includeTunneling
          ? MediaCodecList.ALL_CODECS
          : MediaCodecList.REGULAR_CODECS;
}