Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save MaTriXy/8f0ae60d15edf74a3a56f8e6c81a11a0 to your computer and use it in GitHub Desktop.

Select an option

Save MaTriXy/8f0ae60d15edf74a3a56f8e6c81a11a0 to your computer and use it in GitHub Desktop.
Check How Many MediaCodec Instance Your Device Support
public static int getMaxCodecInstanceByName(String name) {
final Vector<MediaCodec> codecs = new Vector<>();
final MediaFormat format = MediaFormat.createVideoFormat(MIME_TYPE, 1920, 1080);
MediaCodec codec = null;
for (int i = 0; i < max; i++) {
try {
codec = MediaCodec.createDecoderByType(MediaFormat.MIMETYPE_VIDEO_AVC);
codec.configure(format, null, null, 0);
codec.start();
codecs.add(codec);
codec = null;
}
catch (IllegalArgumentException e) {
e.printStackTrace();
break;
}
catch (IOException e) {
e.printStackTrace();
break;
}
catch (Exception e) {
e.printStackTrace();
break;
}
finally {
if (codec != null) {
codec.release();
codec = null;
}
}
}
final int actualMax = codecs.size();
for (int i = 0; i < actualMax; i++) {
codecs.get(i).release();
}
codecs.clear();
return actualMax;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment