Java Code Examples for android.media.MediaCodecInfo#getCapabilitiesForType()

The following examples show how to use android.media.MediaCodecInfo#getCapabilitiesForType() . 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: VideoUtil.java    From VideoProcessor with Apache License 2.0 6 votes vote down vote up
public static boolean trySetProfileAndLevel(MediaCodec codec, String mime, MediaFormat format, int profileInt, int levelInt) {
    MediaCodecInfo codecInfo = codec.getCodecInfo();
    MediaCodecInfo.CodecCapabilities capabilities = codecInfo.getCapabilitiesForType(mime);
    MediaCodecInfo.CodecProfileLevel[] profileLevels = capabilities.profileLevels;
    if (profileLevels == null) {
        return false;
    }
    for (MediaCodecInfo.CodecProfileLevel level : profileLevels) {
        if (level.profile == profileInt) {
            if (level.level == levelInt) {
                format.setInteger(MediaFormat.KEY_PROFILE, profileInt);
                format.setInteger(MediaFormat.KEY_LEVEL, levelInt);
                return true;
            }
        }
    }
    return false;
}
 
Example 2
Source File: MediaCodecUtils.java    From libcommon with Apache License 2.0 6 votes vote down vote up
/**
 * CodecCapabilitiesを取得
 * @param codecInfo
 * @param mimeType
 * @return
 */
   public static MediaCodecInfo.CodecCapabilities getCodecCapabilities(final MediaCodecInfo codecInfo, final String mimeType) {
	HashMap<MediaCodecInfo, MediaCodecInfo.CodecCapabilities> caps = sCapabilities.get(mimeType);
	if (caps == null) {
		caps = new HashMap<MediaCodecInfo, MediaCodecInfo.CodecCapabilities>();
		sCapabilities.put(mimeType, caps);
	}
	MediaCodecInfo.CodecCapabilities capabilities = caps.get(codecInfo);
	if (capabilities == null) {
    	// XXX 通常の優先度ではSC-06DでMediaCodecInfo#getCapabilitiesForTypeが返ってこないので一時的に昇格
		Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
		try {
			capabilities = codecInfo.getCapabilitiesForType(mimeType);
			caps.put(codecInfo, capabilities);
		} finally {
			// 元の優先度に戻す
			Thread.currentThread().setPriority(Thread.NORM_PRIORITY);
		}
	}
	return capabilities;
}
 
Example 3
Source File: RecorderConfigActivity.java    From SoloPi with Apache License 2.0 6 votes vote down vote up
private void onResolutionChanged(int selectedPosition, String resolution) {
    String codecName = getSelectedVideoCodec();
    MediaCodecInfo codec = getVideoCodecInfo(codecName);
    if (codec == null) return;
    MediaCodecInfo.CodecCapabilities capabilities = codec.getCapabilitiesForType(ScreenRecorder.VIDEO_AVC);
    MediaCodecInfo.VideoCapabilities videoCapabilities = capabilities.getVideoCapabilities();
    String[] xes = resolution.split("x");
    if (xes.length != 2) throw new IllegalArgumentException();
    int width = Integer.parseInt(xes[1]);
    int height = Integer.parseInt(xes[0]);

    double selectedFramerate = getSelectedFramerate();
    int resetPos = Math.max(selectedPosition - 1, 0);
    if (!videoCapabilities.isSizeSupported(width, height)) {
        mVideoResolution.setSelectedPosition(resetPos);
        toastShort(getString(R.string.codec_config__unsupport_size,
                codecName, width, height));
        LogUtil.w(TAG, codecName +
                " height range: " + videoCapabilities.getSupportedHeights() +
                "\n width range: " + videoCapabilities.getSupportedHeights());
    } else if (!videoCapabilities.areSizeAndRateSupported(width, height, selectedFramerate)) {
        mVideoResolution.setSelectedPosition(resetPos);
        toastShort(getString(R.string.codec_config__unsupport_size_framerate,
                codecName, width, height, (int) selectedFramerate));
    }
}
 
Example 4
Source File: RecorderConfigActivity.java    From SoloPi with Apache License 2.0 6 votes vote down vote up
private void onBitrateChanged(int selectedPosition, String bitrate) {
    String codecName = getSelectedVideoCodec();
    MediaCodecInfo codec = getVideoCodecInfo(codecName);
    if (codec == null) return;
    MediaCodecInfo.CodecCapabilities capabilities = codec.getCapabilitiesForType(ScreenRecorder.VIDEO_AVC);
    MediaCodecInfo.VideoCapabilities videoCapabilities = capabilities.getVideoCapabilities();
    int selectedBitrate = Integer.parseInt(bitrate) * 1000;

    int resetPos = Math.max(selectedPosition - 1, 0);
    if (!videoCapabilities.getBitrateRange().contains(selectedBitrate)) {
        mVideoBitrate.setSelectedPosition(resetPos);
        toastShort(getString(R.string.codec_config__unsupport_bitrate, codecName, selectedBitrate));
        LogUtil.w(TAG, codecName +
                " bitrate range: " + videoCapabilities.getBitrateRange());
    }
}
 
Example 5
Source File: MediaCodecUtil.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
  * Return an array of supported codecs and profiles.
  */
@CalledByNative
private static Object[] getSupportedCodecProfileLevels() {
    CodecProfileLevelList profileLevels = new CodecProfileLevelList();
    MediaCodecListHelper codecListHelper = new MediaCodecListHelper();
    for (MediaCodecInfo info : codecListHelper) {
        for (String mime : info.getSupportedTypes()) {
            // On versions L and M, VP9 codecCapabilities do not advertise profile level
            // support. In this case, estimate the level from MediaCodecInfo.VideoCapabilities
            // instead. Assume VP9 is not supported before L. For more information, consult
            // https://developer.android.com/reference/android/media/MediaCodecInfo.CodecProfileLevel.html
            CodecCapabilities codecCapabilities = info.getCapabilitiesForType(mime);
            if (mime.endsWith("vp9") && Build.VERSION_CODES.LOLLIPOP <= Build.VERSION.SDK_INT
                    && Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) {
                addVp9CodecProfileLevels(profileLevels, codecCapabilities);
                continue;
            }
            for (CodecProfileLevel profileLevel : codecCapabilities.profileLevels) {
                profileLevels.addCodecProfileLevel(mime, profileLevel);
            }
        }
    }
    return profileLevels.toArray();
}
 
Example 6
Source File: MediaVideoEncoder.java    From In77Camera with MIT License 6 votes vote down vote up
/**
   * select color format available on specific codec and we can use.
   * @return 0 if no colorFormat is matched
   */
  protected static final int selectColorFormat(final MediaCodecInfo codecInfo, final String mimeType) {
if (DEBUG) Log.i(TAG, "selectColorFormat: ");
  	int result = 0;
  	final MediaCodecInfo.CodecCapabilities caps;
  	try {
  		Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
  		caps = codecInfo.getCapabilitiesForType(mimeType);
  	} finally {
  		Thread.currentThread().setPriority(Thread.NORM_PRIORITY);
  	}
      int colorFormat;
      for (int i = 0; i < caps.colorFormats.length; i++) {
      	colorFormat = caps.colorFormats[i];
          if (isRecognizedViewoFormat(colorFormat)) {
          	if (result == 0)
          		result = colorFormat;
              break;
          }
      }
      if (result == 0)
      	Log.e(TAG, "couldn't find a good color format for " + codecInfo.getName() + " / " + mimeType);
      return result;
  }
 
Example 7
Source File: VideoEncoder.java    From rtmp-rtsp-stream-client-java with Apache License 2.0 5 votes vote down vote up
private FormatVideoEncoder chooseColorDynamically(MediaCodecInfo mediaCodecInfo) {
  for (int color : mediaCodecInfo.getCapabilitiesForType(type).colorFormats) {
    if (color == FormatVideoEncoder.YUV420PLANAR.getFormatCodec()) {
      return FormatVideoEncoder.YUV420PLANAR;
    } else if (color == FormatVideoEncoder.YUV420SEMIPLANAR.getFormatCodec()) {
      return FormatVideoEncoder.YUV420SEMIPLANAR;
    }
  }
  return null;
}
 
Example 8
Source File: VideoRecoder.java    From deltachat-android with GNU General Public License v3.0 5 votes vote down vote up
@SuppressLint("NewApi")
private static int selectColorFormat(MediaCodecInfo codecInfo, String mimeType) {
  MediaCodecInfo.CodecCapabilities capabilities = codecInfo.getCapabilitiesForType(mimeType);
  int lastColorFormat = 0;
  for (int i = 0; i < capabilities.colorFormats.length; i++) {
    int colorFormat = capabilities.colorFormats[i];
    if (isRecognizedFormat(colorFormat)) {
      lastColorFormat = colorFormat;
      if (!(codecInfo.getName().equals("OMX.SEC.AVC.Encoder") && colorFormat == 19)) {
        return colorFormat;
      }
    }
  }
  return lastColorFormat;
}
 
Example 9
Source File: VideoController.java    From VideoCompressor with Apache License 2.0 5 votes vote down vote up
@SuppressLint("NewApi")
public static int selectColorFormat(MediaCodecInfo codecInfo, String mimeType) {
    MediaCodecInfo.CodecCapabilities capabilities = codecInfo.getCapabilitiesForType(mimeType);
    int lastColorFormat = 0;
    for (int i = 0; i < capabilities.colorFormats.length; i++) {
        int colorFormat = capabilities.colorFormats[i];
        if (isRecognizedFormat(colorFormat)) {
            lastColorFormat = colorFormat;
            if (!(codecInfo.getName().equals("OMX.SEC.AVC.Encoder") && colorFormat == 19)) {
                return colorFormat;
            }
        }
    }
    return lastColorFormat;
}
 
Example 10
Source File: MediaCodecUtil.java    From Exoplayer_VLC with Apache License 2.0 5 votes vote down vote up
private static Pair<String, CodecCapabilities> getMediaCodecInfoInternal(CodecKey key,
    MediaCodecListCompat mediaCodecList) {
  String mimeType = key.mimeType;
  int numberOfCodecs = mediaCodecList.getCodecCount();
  boolean secureDecodersExplicit = mediaCodecList.secureDecodersExplicit();
  // Note: MediaCodecList is sorted by the framework such that the best decoders come first.
  for (int i = 0; i < numberOfCodecs; i++) {
    MediaCodecInfo info = mediaCodecList.getCodecInfoAt(i);
    String codecName = info.getName();
    if (!info.isEncoder() && codecName.startsWith("OMX.")
        && (secureDecodersExplicit || !codecName.endsWith(".secure"))) {
      String[] supportedTypes = info.getSupportedTypes();
      for (int j = 0; j < supportedTypes.length; j++) {
        String supportedType = supportedTypes[j];
        if (supportedType.equalsIgnoreCase(mimeType)) {
          CodecCapabilities capabilities = info.getCapabilitiesForType(supportedType);
          boolean secure = mediaCodecList.isSecurePlaybackSupported(key.mimeType, capabilities);
          if (!secureDecodersExplicit) {
            // Cache variants for both insecure and (if we think it's supported) secure playback.
            codecs.put(key.secure ? new CodecKey(mimeType, false) : key,
                Pair.create(codecName, capabilities));
            if (secure) {
              codecs.put(key.secure ? key : new CodecKey(mimeType, true),
                  Pair.create(codecName + ".secure", capabilities));
            }
          } else {
            // Only cache this variant. If both insecure and secure decoders are available, they
            // should both be listed separately.
            codecs.put(key.secure == secure ? key : new CodecKey(mimeType, secure),
                Pair.create(codecName, capabilities));
          }
          if (codecs.containsKey(key)) {
            return codecs.get(key);
          }
        }
      }
    }
  }
  return null;
}
 
Example 11
Source File: MainActivity.java    From AndroidPlayground with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    findViewById(R.id.mCameraCapture).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(final View v) {
            startActivity(new Intent(MainActivity.this, CameraCaptureActivity.class));
        }
    });

    TextView tvInfo = (TextView) findViewById(R.id.mTvInfo);

    MediaFormat format = MediaFormat.createVideoFormat(MIME_TYPE, 1080, 720);

    // Set some properties.  Failing to specify some of these can cause the MediaCodec
    // configure() call to throw an unhelpful exception.
    format.setInteger(MediaFormat.KEY_COLOR_FORMAT,
            MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);
    format.setInteger(MediaFormat.KEY_BIT_RATE, 100000);
    format.setInteger(MediaFormat.KEY_FRAME_RATE, FRAME_RATE);
    format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, IFRAME_INTERVAL);

    MediaCodecInfo codecInfo = selectCodec(MIME_TYPE);
    MediaCodecInfo.CodecCapabilities capabilities = codecInfo.getCapabilitiesForType(MIME_TYPE);

    tvInfo.setText(
            "MaxSupportedInstances: " + capabilities.getMaxSupportedInstances() + "\n"
    );
}
 
Example 12
Source File: EncodeDecodeTest.java    From Android-MediaCodec-Examples with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a color format that is supported by the codec and by this test code.  If no
 * match is found, this throws a test failure -- the set of formats known to the test
 * should be expanded for new platforms.
 */
private static int selectColorFormat(MediaCodecInfo codecInfo, String mimeType) {
    MediaCodecInfo.CodecCapabilities capabilities = codecInfo.getCapabilitiesForType(mimeType);
    for (int i = 0; i < capabilities.colorFormats.length; i++) {
        int colorFormat = capabilities.colorFormats[i];
        if (isRecognizedFormat(colorFormat)) {
            return colorFormat;
        }
    }
    fail("couldn't find a good color format for " + codecInfo.getName() + " / " + mimeType);
    return 0;   // not reached
}
 
Example 13
Source File: MediaCodecUtil.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Get a list of encoder supported color formats for specified MIME type.
 * @param mime MIME type of the media format.
 * @return a list of encoder supported color formats.
 */
@CalledByNative
private static int[] getEncoderColorFormatsForMime(String mime) {
    MediaCodecListHelper codecListHelper = new MediaCodecListHelper();
    for (MediaCodecInfo info : codecListHelper) {
        if (!info.isEncoder()) continue;

        for (String supportedType : info.getSupportedTypes()) {
            if (supportedType.equalsIgnoreCase(mime)) {
                return info.getCapabilitiesForType(supportedType).colorFormats;
            }
        }
    }
    return null;
}
 
Example 14
Source File: MediaController.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@SuppressLint("NewApi")
public static int selectColorFormat(MediaCodecInfo codecInfo, String mimeType) {
    MediaCodecInfo.CodecCapabilities capabilities = codecInfo.getCapabilitiesForType(mimeType);
    int lastColorFormat = 0;
    for (int i = 0; i < capabilities.colorFormats.length; i++) {
        int colorFormat = capabilities.colorFormats[i];
        if (isRecognizedFormat(colorFormat)) {
            lastColorFormat = colorFormat;
            if (!(codecInfo.getName().equals("OMX.SEC.AVC.Encoder") && colorFormat == 19)) {
                return colorFormat;
            }
        }
    }
    return lastColorFormat;
}
 
Example 15
Source File: MediaCodecCapabilitiesTest.java    From jellyfin-androidtv with GNU General Public License v2.0 5 votes vote down vote up
private boolean supports(
        String mime, boolean isEncoder, int profile, int level) {
    MediaCodecList mcl = new MediaCodecList(MediaCodecList.REGULAR_CODECS);
    for (MediaCodecInfo info : mcl.getCodecInfos()) {
        if (isEncoder != info.isEncoder()) {
            continue;
        }
        try {
            MediaCodecInfo.CodecCapabilities caps = info.getCapabilitiesForType(mime);
            for (MediaCodecInfo.CodecProfileLevel pl : caps.profileLevels) {
                if (pl.profile != profile) {
                    continue;
                }
                // H.263 levels are not completely ordered:
                // Level45 support only implies Level10 support
                if (mime.equalsIgnoreCase(MIMETYPE_VIDEO_H263)) {
                    if (pl.level != level && pl.level == H263Level45 && level > H263Level10) {
                        continue;
                    }
                }
                if (pl.level >= level) {
                    return true;
                }
            }
        } catch (IllegalArgumentException e) {
            Timber.e(e);
        }
    }
    return false;
}
 
Example 16
Source File: MediaCodecVideoDecoder.java    From droidkit-webrtc with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private static DecoderProperties findVp8HwDecoder() {
  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT)
    return null; // MediaCodec.setParameters is missing.

  for (int i = 0; i < MediaCodecList.getCodecCount(); ++i) {
    MediaCodecInfo info = MediaCodecList.getCodecInfoAt(i);
    if (info.isEncoder()) {
      continue;
    }
    String name = null;
    for (String mimeType : info.getSupportedTypes()) {
      if (mimeType.equals(VP8_MIME_TYPE)) {
        name = info.getName();
        break;
      }
    }
    if (name == null) {
      continue;  // No VP8 support in this codec; try the next one.
    }
    Log.d(TAG, "Found candidate decoder " + name);
    CodecCapabilities capabilities =
        info.getCapabilitiesForType(VP8_MIME_TYPE);
    for (int colorFormat : capabilities.colorFormats) {
      Log.d(TAG, "   Color: 0x" + Integer.toHexString(colorFormat));
    }

    // Check if this is supported HW decoder
    for (String hwCodecPrefix : supportedHwCodecPrefixes) {
      if (!name.startsWith(hwCodecPrefix)) {
        continue;
      }
      // Check if codec supports either yuv420 or nv12
      for (int supportedColorFormat : supportedColorList) {
        for (int codecColorFormat : capabilities.colorFormats) {
          if (codecColorFormat == supportedColorFormat) {
            // Found supported HW VP8 decoder
            Log.d(TAG, "Found target decoder " + name +
                ". Color: 0x" + Integer.toHexString(codecColorFormat));
            return new DecoderProperties(name, codecColorFormat);
          }
        }
      }
    }
  }
  return null;  // No HW VP8 decoder.
}
 
Example 17
Source File: CodecManager.java    From spydroid-ipcamera with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Lists all encoders that claim to support a color format that we know how to use.
 * @return A list of those encoders
 */
@SuppressLint("NewApi")
public synchronized static Codec[] findEncodersForMimeType(String mimeType) {
	if (sEncoders != null) return sEncoders;

	ArrayList<Codec> encoders = new ArrayList<Codec>();

	// We loop through the encoders, apparently this can take up to a sec (testes on a GS3)
	for(int j = MediaCodecList.getCodecCount() - 1; j >= 0; j--){
		MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(j);
		if (!codecInfo.isEncoder()) continue;

		String[] types = codecInfo.getSupportedTypes();
		for (int i = 0; i < types.length; i++) {
			if (types[i].equalsIgnoreCase(mimeType)) {
				try {
					MediaCodecInfo.CodecCapabilities capabilities = codecInfo.getCapabilitiesForType(mimeType);
					Set<Integer> formats = new HashSet<Integer>();

					// And through the color formats supported
					for (int k = 0; k < capabilities.colorFormats.length; k++) {
						int format = capabilities.colorFormats[k];

						for (int l=0;l<SUPPORTED_COLOR_FORMATS.length;l++) {
							if (format == SUPPORTED_COLOR_FORMATS[l]) {
								formats.add(format);
							}
						}
					}
					
					Codec codec = new Codec(codecInfo.getName(), (Integer[]) formats.toArray(new Integer[formats.size()]));
					encoders.add(codec);
				} catch (Exception e) {
					Log.wtf(TAG,e);
				}
			}
		}
	}

	sEncoders = (Codec[]) encoders.toArray(new Codec[encoders.size()]);
	return sEncoders;

}
 
Example 18
Source File: FimiMediaCodecInfo.java    From FimiX8-RE with MIT License 4 votes vote down vote up
@TargetApi(16)
public static FimiMediaCodecInfo setupCandidate(MediaCodecInfo codecInfo, String mimeType) {
    if (codecInfo == null || VERSION.SDK_INT < 16) {
        return null;
    }
    String name = codecInfo.getName();
    if (TextUtils.isEmpty(name)) {
        return null;
    }
    name = name.toLowerCase(Locale.US);
    int rank = RANK_NO_SENSE;
    if (!name.startsWith("omx.")) {
        rank = RANK_NON_STANDARD;
    } else if (name.startsWith("omx.pv")) {
        rank = RANK_SOFTWARE;
    } else if (name.startsWith("omx.google.")) {
        rank = RANK_SOFTWARE;
    } else if (name.startsWith("omx.ffmpeg.")) {
        rank = RANK_SOFTWARE;
    } else if (name.startsWith("omx.k3.ffmpeg.")) {
        rank = RANK_SOFTWARE;
    } else if (name.startsWith("omx.avcodec.")) {
        rank = RANK_SOFTWARE;
    } else if (name.startsWith("omx.ittiam.")) {
        rank = RANK_NO_SENSE;
    } else if (!name.startsWith("omx.mtk.")) {
        Integer knownRank = (Integer) getKnownCodecList().get(name);
        if (knownRank != null) {
            rank = knownRank.intValue();
        } else {
            try {
                if (codecInfo.getCapabilitiesForType(mimeType) != null) {
                    rank = RANK_ACCEPTABLE;
                } else {
                    rank = RANK_LAST_CHANCE;
                }
            } catch (Throwable th) {
                rank = RANK_LAST_CHANCE;
            }
        }
    } else if (VERSION.SDK_INT < 18) {
        rank = RANK_NO_SENSE;
    } else {
        rank = RANK_TESTED;
    }
    FimiMediaCodecInfo candidate = new FimiMediaCodecInfo();
    candidate.mCodecInfo = codecInfo;
    candidate.mRank = rank;
    candidate.mMimeType = mimeType;
    return candidate;
}
 
Example 19
Source File: IjkMediaCodecInfo.java    From DanDanPlayForAndroid with MIT License 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public static IjkMediaCodecInfo setupCandidate(MediaCodecInfo codecInfo,
        String mimeType) {
    if (codecInfo == null
            || Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN)
        return null;

    String name = codecInfo.getName();
    if (TextUtils.isEmpty(name))
        return null;

    name = name.toLowerCase(Locale.US);
    int rank = RANK_NO_SENSE;
    if (!name.startsWith("omx.")) {
        rank = RANK_NON_STANDARD;
    } else if (name.startsWith("omx.pv")) {
        rank = RANK_SOFTWARE;
    } else if (name.startsWith("omx.google.")) {
        rank = RANK_SOFTWARE;
    } else if (name.startsWith("omx.ffmpeg.")) {
        rank = RANK_SOFTWARE;
    } else if (name.startsWith("omx.k3.ffmpeg.")) {
        rank = RANK_SOFTWARE;
    } else if (name.startsWith("omx.avcodec.")) {
        rank = RANK_SOFTWARE;
    } else if (name.startsWith("omx.ittiam.")) {
        // unknown codec in qualcomm SoC
        rank = RANK_NO_SENSE;
    } else if (name.startsWith("omx.mtk.")) {
        // 1. MTK only works on 4.3 and above
        // 2. MTK works on MIUI 6 (4.2.1)
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2)
            rank = RANK_NO_SENSE;
        else
            rank = RANK_TESTED;
    } else {
        Integer knownRank = getKnownCodecList().get(name);
        if (knownRank != null) {
            rank = knownRank;
        } else {
            try {
                CodecCapabilities cap = codecInfo
                        .getCapabilitiesForType(mimeType);
                if (cap != null)
                    rank = RANK_ACCEPTABLE;
                else
                    rank = RANK_LAST_CHANCE;
            } catch (Throwable e) {
                rank = RANK_LAST_CHANCE;
            }
        }
    }

    IjkMediaCodecInfo candidate = new IjkMediaCodecInfo();
    candidate.mCodecInfo = codecInfo;
    candidate.mRank = rank;
    candidate.mMimeType = mimeType;
    return candidate;
}
 
Example 20
Source File: CodecManager.java    From libstreaming with Apache License 2.0 4 votes vote down vote up
/** 
 * Returns an associative array of the supported color formats and the names of the encoders for a given mime type
 * This can take up to sec on certain phones the first time you run it...
 **/
@SuppressLint("NewApi")
static private void findSupportedColorFormats(String mimeType) {
	SparseArray<ArrayList<String>> softwareCodecs = new SparseArray<ArrayList<String>>();
	SparseArray<ArrayList<String>> hardwareCodecs = new SparseArray<ArrayList<String>>();

	if (sSoftwareCodecs.containsKey(mimeType)) {
		return; 
	}

	Log.v(TAG,"Searching supported color formats for mime type \""+mimeType+"\"...");

	// We loop through the encoders, apparently this can take up to a sec (testes on a GS3)
	for(int j = MediaCodecList.getCodecCount() - 1; j >= 0; j--){
		MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(j);
		if (!codecInfo.isEncoder()) continue;

		String[] types = codecInfo.getSupportedTypes();
		for (int i = 0; i < types.length; i++) {
			if (types[i].equalsIgnoreCase(mimeType)) {
				MediaCodecInfo.CodecCapabilities capabilities = codecInfo.getCapabilitiesForType(mimeType);

				boolean software = false;
				for (int k=0;k<SOFTWARE_ENCODERS.length;k++) {
					if (codecInfo.getName().equalsIgnoreCase(SOFTWARE_ENCODERS[i])) {
						software = true;
					}
				}

				// And through the color formats supported
				for (int k = 0; k < capabilities.colorFormats.length; k++) {
					int format = capabilities.colorFormats[k];
					if (software) {
						if (softwareCodecs.get(format) == null) softwareCodecs.put(format, new ArrayList<String>());
						softwareCodecs.get(format).add(codecInfo.getName());
					} else {
						if (hardwareCodecs.get(format) == null) hardwareCodecs.put(format, new ArrayList<String>());
						hardwareCodecs.get(format).add(codecInfo.getName());
					}
				}

			}
		}
	}

	// Logs the supported color formats on the phone
	StringBuilder e = new StringBuilder();
	e.append("Supported color formats on this phone: ");
	for (int i=0;i<softwareCodecs.size();i++) e.append(softwareCodecs.keyAt(i)+", ");
	for (int i=0;i<hardwareCodecs.size();i++) e.append(hardwareCodecs.keyAt(i)+(i==hardwareCodecs.size()-1?".":", "));
	Log.v(TAG, e.toString());

	sSoftwareCodecs.put(mimeType, softwareCodecs);
	sHardwareCodecs.put(mimeType, hardwareCodecs);
	return;
}