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); }
/// <summary> /// Number of markers in the header info object for the specified stream. Wraps IWMHeaderInfo.GetAttributeCount /// </summary> /// <param name="StreamNumber">Stream number. Zero means file level attributes</param> /// <returns>Number of attributes</returns> public int AttributeCount(int StreamNumber) { ushort res; m_HeaderInfo.GetAttributeCount((ushort)StreamNumber, out res); return(res); }
//------------------------------------------------------------------------------ // Name: CWMVCopy::CopyAttribute() // Desc: Copies all the header attributes from the reader file to the writer. //------------------------------------------------------------------------------ protected void CopyAttribute() { short wStreamNumber; short wAttributeCount; AttrDataType enumType; short cbNameLength = 0; short cbValueLength = 0; StringBuilder pwszName = null; byte[] pbValue = null; for (int i = 0; i <= m_dwStreamCount; i++) { if (i == m_dwStreamCount) { // // When the stream number is 0, the attribute is a file-level attribute // wStreamNumber = 0; } else { wStreamNumber = m_pwStreamNumber[i]; } // // Get the attribute count // m_pReaderHeaderInfo.GetAttributeCount(wStreamNumber, out wAttributeCount); // // Copy all attributes of this stream // for (short j = 0; j < wAttributeCount; j++) { // // Get the attribute name and value length // m_pReaderHeaderInfo.GetAttributeByIndex(j, ref wStreamNumber, null, ref cbNameLength, out enumType, null, ref cbValueLength); pwszName = new StringBuilder(cbNameLength); pbValue = new byte[cbValueLength]; // // Get the attribute name and value // m_pReaderHeaderInfo.GetAttributeByIndex(j, ref wStreamNumber, pwszName, ref cbNameLength, out enumType, pbValue, ref cbValueLength); // // Set the attribute for the writer // try { m_pWriterHeaderInfo.SetAttribute(wStreamNumber, pwszName.ToString(), enumType, pbValue, cbValueLength); } catch (Exception e) { int hr = Marshal.GetHRForException(e); if (E_InvalidArgument == hr) { // // Some attributes are read-only; we cannot set them. // They'll be set automatically by the writer. // } else { throw; } } } } }