Exemplo n.º 1
0
        private void TestAttr()
        {
            short i1, i2;
            short wStream = 0;

            m_head.GetAttributeCount(wStream, out i1);

            m_head.SetAttribute(wStream, "asdf", AttrDataType.DWORD, BitConverter.GetBytes(1234), 4);

            m_head.SetAttribute(wStream, "fdsa", AttrDataType.DWORD, BitConverter.GetBytes(4321), 4);

            m_head.GetAttributeCount(wStream, out i2);
            Debug.Assert(i2 - i1 == 2);

            short        pLen = 0;
            AttrDataType pType;

            m_head.GetAttributeByName(ref wStream, "asdf", out pType, null, ref pLen);
            byte [] b = new byte[pLen];
            m_head.GetAttributeByName(ref wStream, "asdf", out pType, b, ref pLen);
            Debug.Assert(BitConverter.ToInt32(b, 0) == 1234);

            short sNameLen = 0;

            m_head.GetAttributeByIndex((short)(i1 + 1), ref wStream, null, ref sNameLen, out pType, null, ref pLen);
            StringBuilder sb = new StringBuilder(sNameLen);

            byte [] b2 = new byte[pLen];
            m_head.GetAttributeByIndex((short)(i1 + 1), ref wStream, sb, ref sNameLen, out pType, b2, ref pLen);

            Debug.Assert(sb.ToString() == "fdsa" && pType == AttrDataType.DWORD && BitConverter.ToInt32(b2, 0) == 4321);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get the header attribute by name and by stream number. Wraps IWMHeaderInfo.GetAttributeByName
        /// </summary>
        /// <param name="StreamNumber">Stream numer. Zero means file level attributes</param>
        /// <param name="name">Nma of the desired attribute</param>
        /// <returns>Desired attribute <see cref="WM_Attr"/></returns>
        public WM_Attr GetAttribute(int StreamNumber, string name)
        {
            ushort            stream  = (ushort)StreamNumber;
            ushort            datalen = 0;
            object            obj;
            WMT_ATTR_DATATYPE type;

            m_HeaderInfo.GetAttributeByName(ref stream, 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();
                m_HeaderInfo.GetAttributeByName(ref stream, 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));
        }
Exemplo n.º 3
0
        // Use IWMMetadataEditor interface to access
        // StreamNumber attribute
        ///////////////////////////////////////////////////////////////////////////////
        void GetBoolAttribsFromEditor(IWMHeaderInfo pHeaderInfo, string pwszName, out bool pResult)
        {
            AttrDataType wmType;
            short        wStreamNum = 0;
            short        cbLen      = 0;

            pHeaderInfo.GetAttributeByName(ref wStreamNum, pwszName, out wmType, null, ref cbLen);

            byte[] pData = new byte[cbLen];
            pHeaderInfo.GetAttributeByName(ref wStreamNum, pwszName, out wmType, pData, ref cbLen);

            pResult = BitConverter.ToBoolean(pData, 0);
        }
Exemplo n.º 4
0
        private void GetHeaderAttribute(string pwszName, out byte[] ppbValue)
        {
            AttrDataType wmtType;
            short        cbLength   = 0;
            short        wAnyStream = 0;

            ppbValue = null;

            //
            // Sanity check
            //
            if (null == m_pHeaderInfo)
            {
                throw new COMException("Instance has been Disposed", E_Unexpected);
            }

            //
            // Get the count of bytes to be allocated for pbValue
            //
            m_pHeaderInfo.GetAttributeByName(ref wAnyStream,
                                             pwszName,
                                             out wmtType,
                                             null,
                                             ref cbLength);

            ppbValue = new byte[cbLength];

            //
            // Get the actual value
            //
            m_pHeaderInfo.GetAttributeByName(ref wAnyStream,
                                             pwszName,
                                             out wmtType,
                                             ppbValue,
                                             ref cbLength);
        }
Exemplo n.º 5
0
        //------------------------------------------------------------------------------
        // Name: CWMVCopy::CreateReader()
        // Desc: Creates a reader and opens the source file using this reader.
        //------------------------------------------------------------------------------
        protected void CreateReader(string pwszInputFile)
        {
            Console.WriteLine("Creating the Reader...");

            //
            // Create a reader
            //
            WMUtils.WMCreateReader(IntPtr.Zero, 0, out m_pReader);

            //
            // Get the IWMReaderAdvanced interface
            //
            m_pReaderAdvanced = m_pReader as IWMReaderAdvanced;

            //
            // Get the IWMHeaderInfo interface of the reader
            //
            m_pReaderHeaderInfo = m_pReader as IWMHeaderInfo;

            //
            // Open the reader; use "this" as the callback interface.
            //
            m_pReader.Open(pwszInputFile, this, IntPtr.Zero);

            //
            // Wait until WMT_OPENED status message is received in OnStatus()
            //
            WaitForCompletion();

            //
            // Get the duration of the source file
            //
            short        wStreamNumber = 0;
            AttrDataType enumType;
            short        cbLength = 8; // sizeof(m_qwDuration);

            byte[] b = new byte[cbLength];

            m_pReaderHeaderInfo.GetAttributeByName(ref wStreamNumber,
                                                   Constants.g_wszWMDuration,
                                                   out enumType,
                                                   b,
                                                   ref cbLength);

            m_qwDuration = BitConverter.ToInt64(b, 0);

            if (m_qwDuration == 0)
            {
                throw new COMException("Duration is zero", E_InvalidArgument);
            }

            //
            // Turn on the user clock
            //
            m_pReaderAdvanced.SetUserProvidedClock(true);

            //
            // Turn on manual stream selection, so we get all streams.
            //
            m_pReaderAdvanced.SetManualStreamSelection(true);
        }
Exemplo n.º 6
0
        // Use IWMMetadataEditor interface to access
        // StreamNumber attribute
        ///////////////////////////////////////////////////////////////////////////////
        void GetBoolAttribsFromEditor(IWMHeaderInfo pHeaderInfo, string pwszName, out bool pResult)
        {
            AttrDataType wmType;
            short wStreamNum = 0;
            short cbLen = 0;

            pHeaderInfo.GetAttributeByName(ref wStreamNum, pwszName, out wmType, null, ref cbLen);

            byte[] pData = new byte[cbLen];
            pHeaderInfo.GetAttributeByName(ref wStreamNum, pwszName, out wmType, pData, ref cbLen);

            pResult = BitConverter.ToBoolean(pData, 0);
        }