void TestGetRepresentation() { IntPtr ip = IntPtr.Zero; MFVideoFormat vf = new MFVideoFormat(); AMMediaType a = new AMMediaType(); try { int hr = m_mt.GetRepresentation(MFRepresentation.MFVideoFormat, out ip); MFError.ThrowExceptionForHR(hr); Marshal.PtrToStructure(ip, a); if (a.formatType == MFRepresentation.MFVideoFormat) { Marshal.PtrToStructure(a.formatPtr, vf); } hr = m_mt.FreeRepresentation(MFRepresentation.MFVideoFormat, ip); MFError.ThrowExceptionForHR(hr); } catch { } // fails because it's not fully formed. Tested in player.cs }
private void TestVF() { int hr; IMFVideoMediaType vmt; MFMediaEqual me; int i; MFVideoFormat vf; IMFMediaType mt, mt2, mt3; FourCC cc4 = new FourCC("YUY2"); hr = MFExtern.MFCreateMediaType(out mt); MFError.ThrowExceptionForHR(hr); hr = mt.SetGUID(MFAttributesClsid.MF_MT_SUBTYPE, cc4.ToMediaSubtype()); MFError.ThrowExceptionForHR(hr); hr = mt.SetGUID(MFAttributesClsid.MF_MT_MAJOR_TYPE, MFMediaType.Video); MFError.ThrowExceptionForHR(hr); hr = MFExtern.MFCreateMFVideoFormatFromMFMediaType(mt, out vf, out i); MFError.ThrowExceptionForHR(hr); int cc = MFExtern.MFGetUncompressedVideoFormat(vf); hr = MFExtern.MFCreateMediaType(out mt2); MFError.ThrowExceptionForHR(hr); hr = MFExtern.MFInitMediaTypeFromMFVideoFormat(mt2, vf, i); MFError.ThrowExceptionForHR(hr); int iRet = mt.IsEqual(mt2, out me); Debug.Assert(iRet == 0); AMMediaType amt = new AMMediaType(); hr = MFExtern.MFInitAMMediaTypeFromMFMediaType(mt, Guid.Empty, amt); MFError.ThrowExceptionForHR(hr); AMMediaType amt2; hr = MFExtern.MFCreateAMMediaTypeFromMFMediaType(mt, MFRepresentation.VideoInfo2, out amt2); MFError.ThrowExceptionForHR(hr); hr = MFExtern.MFCreateMediaType(out mt3); MFError.ThrowExceptionForHR(hr); hr = MFExtern.MFInitMediaTypeFromAMMediaType(mt3, amt2); MFError.ThrowExceptionForHR(hr); iRet = mt.IsEqual(mt3, out me); Debug.Assert(iRet == 0); hr = MFExtern.MFCreateVideoMediaType(vf, out vmt); VideoInfoHeader vih = new VideoInfoHeader(); Marshal.PtrToStructure(amt.formatPtr, vih); IMFMediaType mt4; hr = MFExtern.MFCreateMediaType(out mt4); MFError.ThrowExceptionForHR(hr); hr = MFExtern.MFInitMediaTypeFromVideoInfoHeader(mt4, vih, amt.formatSize, Guid.Empty); MFError.ThrowExceptionForHR(hr); iRet = mt.IsEqual(mt4, out me); Debug.Assert(iRet == 1 && me == (MediaFoundation.MFMediaEqual.MajorTypes | MediaFoundation.MFMediaEqual.FormatUserData)); VideoInfoHeader2 vih2 = new VideoInfoHeader2(); Marshal.PtrToStructure(amt2.formatPtr, vih2); IMFMediaType mt5; hr = MFExtern.MFCreateMediaType(out mt5); MFError.ThrowExceptionForHR(hr); hr = MFExtern.MFInitMediaTypeFromVideoInfoHeader2(mt5, vih2, amt2.formatSize, Guid.Empty); MFError.ThrowExceptionForHR(hr); iRet = mt.IsEqual(mt5, out me); Debug.Assert(iRet == 1 && me == (MediaFoundation.MFMediaEqual.MajorTypes | MediaFoundation.MFMediaEqual.FormatUserData)); IntPtr ip; hr = vmt.SetGUID(MFAttributesClsid.MF_MT_SUBTYPE, cc4.ToMediaSubtype()); MFError.ThrowExceptionForHR(hr); hr = vmt.SetGUID(MFAttributesClsid.MF_MT_MAJOR_TYPE, MFMediaType.Video); MFError.ThrowExceptionForHR(hr); vf = vmt.GetVideoFormat(); // This statement seems to cause crashes in 64bit code. The crash comes on leaving DoTests. // Since this doesn't occur in 32 bit, and since this is a deprecated method, I don't think // I care. vmt.GetVideoRepresentation(MFRepresentation.VideoInfo, out ip, 10); AMMediaType amt5 = new AMMediaType(); Marshal.PtrToStructure(ip, amt5); Debug.Assert(amt5.formatType == MFRepresentation.VideoInfo); hr = vmt.FreeRepresentation(MFRepresentation.VideoInfo, ip); MFError.ThrowExceptionForHR(hr); }