-
-
Save MaTriXy/8f0ae60d15edf74a3a56f8e6c81a11a0 to your computer and use it in GitHub Desktop.
Check How Many MediaCodec Instance Your Device Support
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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