Example #1
0
        public WM_ATTR GetCodecEnumerationSetting(int index, string name)
        {
            WMT_ATTR_DATATYPE type;
            object            obj;
            uint datalen = 0;

#if DEBUG && DEBUG_CODECINFO
            Logger.WriteLogMessage("Get property[" + index + "], name [" + name + "].");
#endif

            _codecInfo.GetCodecEnumerationSetting(ref _mediaType, (uint)index, name, out type, IntPtr.Zero, ref datalen);

            switch (type)
            {
            case WMT_ATTR_DATATYPE.WMT_TYPE_BOOL:
            case WMT_ATTR_DATATYPE.WMT_TYPE_DWORD:
                obj = (uint)0;
                break;

            case WMT_ATTR_DATATYPE.WMT_TYPE_GUID:
                obj = Guid.NewGuid();
                break;

            case WMT_ATTR_DATATYPE.WMT_TYPE_QWORD:
                obj = (ulong)0;
                break;

            case WMT_ATTR_DATATYPE.WMT_TYPE_WORD:
                obj = (ushort)0;
                break;

            case WMT_ATTR_DATATYPE.WMT_TYPE_STRING:
            case WMT_ATTR_DATATYPE.WMT_TYPE_BINARY:
                obj = new byte[datalen];
                break;

            default:
                throw new InvalidOperationException(String.Format("Not supported data type: {0}.", type.ToString()));
            }

            GCHandle h = GCHandle.Alloc(obj, GCHandleType.Pinned);

            try
            {
                IntPtr ptr = h.AddrOfPinnedObject();

                _codecInfo.GetCodecEnumerationSetting(ref _mediaType, (uint)index, name, out type, ptr, ref datalen);

                switch (type)
                {
                case WMT_ATTR_DATATYPE.WMT_TYPE_STRING:
                    obj = Marshal.PtrToStringUni(ptr);
                    break;

                case WMT_ATTR_DATATYPE.WMT_TYPE_BOOL:
                    obj = ((uint)obj != 0);
                    break;
                }
            }
            finally
            {
                h.Free();
            }

            return(new WM_ATTR(name, type, obj));
        }
        private void Test()
        {
            int numCodecs = -1;

            m_pCodecInfo.GetCodecInfoCount(MediaType.Audio, out numCodecs);
            Debug.Assert(numCodecs >= 0);

            if (numCodecs > 0)
            {
                for (int i = 0; i < numCodecs; i++)
                {
                    // Start testing IWMCodecInfo3
                    AttrDataType dataType;
                    byte[]       value = new byte[] { 2, 0, 0, 0 };
                    byte[]       outvalue;
                    int          size = 4;

                    // Start testing IWMCodecInfo2
                    int nameLen = -1;
                    m_pCodecInfo.GetCodecName(MediaType.Audio, i, null, ref nameLen);
                    Debug.Assert(nameLen >= 0);

                    StringBuilder sb = new StringBuilder(nameLen);
                    m_pCodecInfo.GetCodecName(MediaType.Audio, i, sb, ref nameLen);
                    Debug.Assert(sb.ToString().Length > 0);

                    Guid mt;
                    int  fCount;

                    mt = MediaType.Video;
                    m_pCodecInfo.GetCodecFormatCount(mt, i, out fCount);
                    for (int jjj = 0; jjj < fCount; jjj++)
                    {
                        TryOne(mt, jjj, Constants.g_wszComplexityMax);
                    }

                    if (sb.ToString().Equals("Windows Media Audio 9.2"))
                    {
                        m_pCodecInfo.SetCodecEnumerationSetting(MediaType.Audio, i, Constants.g_wszNumPasses, AttrDataType.DWORD, value, size);
                        size = -1;
                        m_pCodecInfo.GetCodecEnumerationSetting(MediaType.Audio, i, Constants.g_wszNumPasses, out dataType, null, ref size);
                        Debug.Assert(size == 4);

                        outvalue = new byte[size];
                        m_pCodecInfo.GetCodecEnumerationSetting(MediaType.Audio, 0, Constants.g_wszNumPasses, out dataType, outvalue, ref size);
                        Debug.Assert(BitConverter.ToInt32(value, 0) == BitConverter.ToInt32(outvalue, 0));
                    }
                    else if (sb.ToString().Equals("Windows Media Audio Voice 9"))
                    {
                        m_pCodecInfo.GetCodecFormatProp(MediaType.Audio, i, 0, Constants.g_wszSpeechCaps, out dataType, null, ref size);
                        Debug.Assert(size == 4);
                        outvalue = new byte[size];

                        m_pCodecInfo.GetCodecFormatProp(MediaType.Audio, i, 0, Constants.g_wszSpeechCaps, out dataType, outvalue, ref size);

                        int val = BitConverter.ToInt32(outvalue, 0);
                        Debug.Assert(size == 4);
                        Debug.Assert(dataType == AttrDataType.DWORD);
                        Debug.Assert(val > 0);
                    }
                }
            }
        }