/** * Returns the first codec capable of encoding the specified MIME type, or null if no * match was found. */ private static MediaCodecInfo selectCodec(string mimeType) { int numCodecs = MediaCodecList.CodecCount; for (int i = 0; i < numCodecs; i++) { MediaCodecInfo codecInfo = MediaCodecList.GetCodecInfoAt(i); if (!codecInfo.IsEncoder) { continue; } var types = codecInfo.GetSupportedTypes(); for (int j = 0; j < types.Length; j++) { if (types[j].ToLower() == mimeType.ToLower()) { return(codecInfo); } } } return(null); }
public static Codec[] findEncodersForMimeType(System.String mimeType) { lock (lockEncoder) { if (sEncoders != null) { return(sEncoders); } List <Codec> encoders = new List <Codec>(); // We loop through the encoders, apparently this can take up to a sec (testes on a GS3) for (int j = MediaCodecList.CodecCount - 1; j >= 0; j--) { MediaCodecInfo codecInfo = MediaCodecList.GetCodecInfoAt(j); if (!codecInfo.IsEncoder) { continue; } System.String[] types = codecInfo.GetSupportedTypes(); for (int i = 0; i < types.Length; i++) { if (types[i].Equals(mimeType, StringComparison.CurrentCultureIgnoreCase)) { try { MediaCodecInfo.CodecCapabilities capabilities = codecInfo.GetCapabilitiesForType(mimeType); ISet <Integer> formats = new HashSet <Integer>(); // And through the color formats supported for (int k = 0; k < capabilities.ColorFormats.Count; k++) { int format = capabilities.ColorFormats[k]; for (int l = 0; l < SUPPORTED_COLOR_FORMATS.Length; l++) { if (format == SUPPORTED_COLOR_FORMATS[l]) { formats.Add((Integer)format); } } } Integer[] ar = new Integer[formats.Count]; formats.CopyTo(ar, 0); Codec codec = new Codec(codecInfo.Name, ar); encoders.Add(codec); } catch (Java.Lang.Exception e) { Log.Wtf(TAG, e); } } } } sEncoders = new Codec[encoders.Count]; //sEncoders = (Codec[])encoders.CopyTo(.ToArray(new Codec[encoders.Count]); encoders.CopyTo(sEncoders); } return(sEncoders); }
/** * Lists all decoders that claim to support a color format that we know how to use. * @return A list of those decoders */ // @SuppressLint("NewApi") public static Codec[] findDecodersForMimeType(System.String mimeType) { lock (lockDecoder) { if (sDecoders != null) { return(sDecoders); } List <Codec> decoders = new List <Codec>(); // We loop through the decoders, apparently this can take up to a sec (testes on a GS3) for (int j = MediaCodecList.CodecCount - 1; j >= 0; j--) { MediaCodecInfo codecInfo = MediaCodecList.GetCodecInfoAt(j); if (codecInfo.IsEncoder) { continue; } System.String[] types = codecInfo.GetSupportedTypes(); for (int i = 0; i < types.Length; i++) { if (types[i].Equals(mimeType)) { try { MediaCodecInfo.CodecCapabilities capabilities = codecInfo.GetCapabilitiesForType(mimeType); ISet <Integer> formats = new HashSet <Integer>(); // And through the color formats supported for (int k = 0; k < capabilities.ColorFormats.Count; k++) { int format = capabilities.ColorFormats[k]; for (int l = 0; l < SUPPORTED_COLOR_FORMATS.Length; l++) { if (format == SUPPORTED_COLOR_FORMATS[l]) { formats.Add((Integer)format); } } } Integer[] frt = new Integer[formats.Count]; formats.CopyTo(frt, 0); Codec codec = new Codec(codecInfo.Name, frt); decoders.Add(codec); } catch (Java.Lang.Exception e) { Log.Wtf(TAG, e); } } } } sDecoders = new Codec[decoders.Count]; decoders.CopyTo(sDecoders); // We will use the decoder from google first, it seems to work properly on many phones for (int i = 0; i < sDecoders.Length; i++) { if (sDecoders[i].name.Equals("omx.google.h264.decoder")) { Codec codec = sDecoders[0]; sDecoders[0] = sDecoders[i]; sDecoders[i] = codec; } } return(sDecoders); } }