コード例 #1
0
ファイル: EncoderMuxer.cs プロジェクト: borisblanc/GrowPea
        private static int selectColorFormat(MediaCodecInfo codecInfo, String mimeType)
        {
            MediaCodecInfo.CodecCapabilities capabilities = codecInfo.GetCapabilitiesForType(mimeType);
            for (int i = 0; (i < capabilities.ColorFormats.Count); i++)
            {
                int colorFormat = capabilities.ColorFormats[i];
                if (isRecognizedFormat(colorFormat))
                {
                    _SelectedCodecColor = (MediaCodecCapabilities)System.Enum.ToObject(typeof(MediaCodecCapabilities), colorFormat);
                    return(colorFormat);
                }
            }

            Log.Warn(TAG, string.Format("couldn\'t find a good color format for codec {0} and mime {1}", codecInfo.Name, mimeType));
            return(0);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        /**
         * 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);
            }
        }