VMR9 allocator

Started by
10 comments, last by Evil Steve 14 years, 9 months ago
Hello, I am trying to migrate a VMR9 sample of Directshow.net written with MDX to SlimDX and I am stacked. If i try to get the RenderTarget with renderTarget = device.GetRenderTarget(0); it fails with "A first chance exception of type 'SlimDX.Direct3D9.Direct3D9Exception' occurred in SlimDX.dll" at the PresentHelper function at the line device.SetRenderTarget(0, renderTarget); if i try using renderTarget = SlimDX.Direct3D9.Surface.CreateRenderTarget(device, adapterInfo.CurrentDisplayMode.Width, adapterInfo.CurrentDisplayMode.Height, adapterInfo.CurrentDisplayMode.Format, MultisampleType.None, 0, false); i have sound of my video by the image is corrupted can please help me?
Advertisement
What do you mean by the image is corrupted? Does it look vaguely right, or is it just noise? I'm not a C# person, but is there not a way to get the error code that caused the exception (I.e. the D3D error code)? What do the Debug Runtimes tell you?
Hello Evil Steve and thank you for your reply,

The image looks like the first frame of the movie with missing squares and then it does not update or clear it.


If you would like i can post the code of what i have done up to now and take a look at it!!!
Hello Steve,

If i enable the debug version directx9 the code fails at the time that

return vmrSurfaceAllocatorNotify.SetD3DDevice(unmanagedDevice, hMonitor)

witch if use the retail version of the DirectX9 the

return vmrSurfaceAllocatorNotify.SetD3DDevice(unmanagedDevice, hMonitor)

returns 0 but anyway does not work
Quote:Original post by NicosAndreou
Hello Steve,

If i enable the debug version directx9 the code fails at the time that

return vmrSurfaceAllocatorNotify.SetD3DDevice(unmanagedDevice, hMonitor)

witch if use the retail version of the DirectX9 the

return vmrSurfaceAllocatorNotify.SetD3DDevice(unmanagedDevice, hMonitor)

returns 0 but anyway does not work
Ah yes, sorry - I forgot that VMR9 doesn't work with the debug runtimes [sad]

I think we'll need to see your code (In [ source ] tags please).
Hello Steve,

this is a sample of what i have on my windows

VMR9 Allocator
Hello Steve

here is my allocator source code

In[

/****************************************************************************
While the underlying libraries are covered by LGPL, this sample is released
as public domain. It is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
*****************************************************************************/

using System;
using System.Collections;
using System.Drawing;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;

using DirectShowLib;

using SlimDX;
using SlimDX.Direct3D9;

namespace DirectShowLib.Sample
{
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
public class Allocator : IVMRSurfaceAllocator9, IVMRImagePresenter9, IDisposable
{
private const int E_FAIL = unchecked((int) 0x80004005);
private const int DxMagicNumber = -759872593;

private Control parentControl;

private PresentParameters presentParam;
private Device device = null;
private Surface renderTarget = null;
private AdapterInformation adapterInfo = null;

private Hashtable textures = null;
private Hashtable surfaces = null;
private IntPtr[] unmanagedSurfaces = null;
private Texture privateTexture = null;
private Surface privateSurface = null;

private IVMRSurfaceAllocatorNotify9 vmrSurfaceAllocatorNotify = null;

private PlaneScene scene = null;

private Direct3D _Direct3D = null;

public Allocator(Control control)
{
parentControl = control;
scene = new PlaneScene();

_Direct3D = new Direct3D();
//Device.IsUsingEventHandlers = false;

CreateDevice();
}

~Allocator()
{
Dispose();
}

private void CreateDevice()
{
adapterInfo = _Direct3D.Adapters.DefaultAdapter;
//adapterInfo = Manager.Adapters.Default;

presentParam = new PresentParameters();
presentParam.Windowed = true;
presentParam.PresentFlags = PresentFlags.Video;
presentParam.SwapEffect = SwapEffect.Copy;
presentParam.BackBufferFormat = adapterInfo.CurrentDisplayMode.Format;
presentParam.DeviceWindowHandle = parentControl.Handle;

device = new Device(_Direct3D,
0,
DeviceType.Hardware,
parentControl.Handle,
CreateFlags.SoftwareVertexProcessing | CreateFlags.Multithreaded,
presentParam
);


//renderTarget = device.GetRenderTarget(0);

/*
RenderToSurface rToSurface = new RenderToSurface(device, adapterInfo.CurrentDisplayMode.Width,
adapterInfo.CurrentDisplayMode.Height,
adapterInfo.CurrentDisplayMode.Format);
*/


renderTarget = SlimDX.Direct3D9.Surface.CreateRenderTarget(device,
640,
480,
adapterInfo.CurrentDisplayMode.Format,
MultisampleType.None,
0,
true);


// just a texture with respective flags set X8R8G8B8

//renderTarget = Surface.CreateOffscreenPlain(device, 720, 480, Format.A8R8G8B8, Pool.SystemMemory);

//Texture texture = new Texture(device, 512, 512, 0, Usage.RenderTarget, adapterInfo.CurrentDisplayMode.Format, Pool.Default);
//renderTarget = texture.GetSurfaceLevel(0);
}

private void DeleteSurfaces()
{
lock(this)
{
if (privateTexture != null)
{
privateTexture.Dispose();
privateTexture = null;
}

if (privateSurface != null)
{
privateSurface.Dispose();
privateSurface = null;
}

if (textures != null)
{
foreach (Texture tex in textures.Values)
{
tex.Dispose();
}
textures = null;
}

if (surfaces != null)
{
foreach (Surface surf in surfaces.Values)
{
surf.Dispose();
}
surfaces = null;
}
}
}

#region Membres de IVMRSurfaceAllocator9

public int InitializeDevice(IntPtr dwUserID, ref VMR9AllocationInfo lpAllocInfo, ref int lpNumBuffers)
{
int width = 1;
int height = 1;
float fTU = 1.0f;
float fTV = 1.0f;

if (vmrSurfaceAllocatorNotify == null)
{
return E_FAIL;
}

int hr = 0;

try
{
//IntPtr unmanagedDevice = device.GetObjectByValue(DxMagicNumber);
IntPtr unmanagedDevice = device.ComPointer;
//IntPtr hMonitor = Manager.GetAdapterMonitor(adapterInfo.Adapter);
IntPtr hMonitor = _Direct3D.GetAdapterMonitor(adapterInfo.Adapter);

hr = vmrSurfaceAllocatorNotify.SetD3DDevice(unmanagedDevice, hMonitor);
DsError.ThrowExceptionForHR(hr);

//if (device.DeviceCaps.TextureCaps.SupportsPower2)

if ((device.Capabilities.TextureCaps & TextureCaps.Pow2) != 0)
{
while (width < lpAllocInfo.dwWidth)
width = width << 1;
while (height < lpAllocInfo.dwHeight)
height = height << 1;

fTU = (float)(lpAllocInfo.dwWidth) / (float)(width);
fTV = (float)(lpAllocInfo.dwHeight) / (float)(height);
scene.SetSrcRect(fTU, fTV);

lpAllocInfo.dwWidth = width;
lpAllocInfo.dwHeight = height;
}

// NOTE:
// we need to make sure that we create textures because
// surfaces can not be textured onto a primitive.
lpAllocInfo.dwFlags |= VMR9SurfaceAllocationFlags.TextureSurface;

DeleteSurfaces();

unmanagedSurfaces = new IntPtr[lpNumBuffers];

hr = vmrSurfaceAllocatorNotify.AllocateSurfaceHelper(ref lpAllocInfo, ref lpNumBuffers, unmanagedSurfaces);

// If we couldn't create a texture surface and
// the format is not an alpha format,
// then we probably cannot create a texture.
// So what we need to do is create a private texture
// and copy the decoded images onto it.
if (hr < 0)
{
DeleteSurfaces();

FourCC fcc = new FourCC("0000");

// is surface YUV ?
if (lpAllocInfo.Format > fcc.ToInt32())
{
// create the private texture
privateTexture = new Texture(
device,
lpAllocInfo.dwWidth,
lpAllocInfo.dwHeight,
1,
Usage.RenderTarget,
adapterInfo.CurrentDisplayMode.Format,
Pool.Default
);

privateSurface = privateTexture.GetSurfaceLevel(0);
}

lpAllocInfo.dwFlags &= ~VMR9SurfaceAllocationFlags.TextureSurface;
lpAllocInfo.dwFlags |= VMR9SurfaceAllocationFlags.OffscreenSurface;

unmanagedSurfaces = new IntPtr[lpNumBuffers];

hr = vmrSurfaceAllocatorNotify.AllocateSurfaceHelper(ref lpAllocInfo, ref lpNumBuffers, unmanagedSurfaces);
if (hr < 0)
return hr;
}
else
{
surfaces = new Hashtable(unmanagedSurfaces.Length);
textures = new Hashtable(unmanagedSurfaces.Length);

for (int i = 0; i < lpNumBuffers; i++)
{
//Surface surf = new Surface(unmanagedSurfaces);
Surface surf = Surface.FromPointer(unmanagedSurfaces);
//Texture text = (Texture) surf.GetContainer(new Guid("85C31227-3DE5-4f00-9B3A-F11AC38C18B5"));
Texture text = surf.GetContainer<Texture>();
surfaces.Add(unmanagedSurfaces, surf);
textures.Add(unmanagedSurfaces, text);
}
}

return scene.Init(device);
}
catch (SlimDXException e)
{
//return e.ErrorCode;
return e.ResultCode.Code;
}
catch
{
return E_FAIL;
}
}

public int TerminateDevice(IntPtr dwID)
{
DeleteSurfaces();
return 0;
}

public int GetSurface(IntPtr dwUserID, int SurfaceIndex, int SurfaceFlags, out IntPtr lplpSurface)
{
lplpSurface = IntPtr.Zero;

if (SurfaceIndex > unmanagedSurfaces.Length)
return E_FAIL;

lock(this)
{
lplpSurface = unmanagedSurfaces[SurfaceIndex];
Marshal.AddRef(lplpSurface);
return 0;
}
}

public int AdviseNotify(IVMRSurfaceAllocatorNotify9 lpIVMRSurfAllocNotify)
{
lock(this)
{
vmrSurfaceAllocatorNotify = lpIVMRSurfAllocNotify;

IntPtr unmanagedDevice = device.ComPointer;//.GetObjectByValue(DxMagicNumber);
//IntPtr hMonitor = Manager.GetAdapterMonitor(Manager.Adapters.Default.Adapter);
IntPtr hMonitor = _Direct3D.GetAdapterMonitor(_Direct3D.Adapters.DefaultAdapter.Adapter);

return vmrSurfaceAllocatorNotify.SetD3DDevice(unmanagedDevice, hMonitor);
}
}

#endregion

#region Membres de IVMRImagePresenter9

public int StartPresenting(IntPtr dwUserID)
{
lock(this)
{
if (device == null)
return E_FAIL;

return 0;
}
}

public int StopPresenting(IntPtr dwUserID)
{
return 0;
}

public int PresentImage(IntPtr dwUserID, ref VMR9PresentationInfo lpPresInfo)
{
int hr = 0;

lock(this)
{
try
{
// if we are in the middle of the display change
if(NeedToHandleDisplayChange())
{
// NOTE: this piece of code is left as a user exercise.
// The D3DDevice here needs to be switched
// to the device that is using another adapter
}

hr = PresentHelper(lpPresInfo);

return hr;
}
catch (SlimDXException e)
{
return e.ResultCode.Code;
}
catch
{
return E_FAIL;
}
}
}

private int PresentHelper(VMR9PresentationInfo lpPresInfo)
{
int hr = 0;

try
{

device.SetRenderTarget(0, renderTarget);

if (privateTexture != null)
{
Marshal.AddRef(lpPresInfo.lpSurf);
//using(Surface surface = new Surface(lpPresInfo.lpSurf))
using (Surface surface = Surface.FromPointer(lpPresInfo.lpSurf))
{
device.StretchRectangle(
surface,
new Rectangle(0, 0, surface.Description.Width, surface.Description.Height),
privateSurface,
new Rectangle(0, 0, privateSurface.Description.Width, privateSurface.Description.Height),
TextureFilter.None
);
}

hr = scene.DrawScene(device, privateTexture);
if (hr < 0)
return hr;
}
else
{
if (textures.ContainsKey(lpPresInfo.lpSurf))
{
hr = scene.DrawScene(device, textures[lpPresInfo.lpSurf] as Texture);
if (hr < 0)
return hr;
}
else
hr = E_FAIL;
}

device.Present();
return 0;
}
catch (SlimDXException e)
{
return e.ResultCode.Code;
}
catch
{
return E_FAIL;
}
}

private bool NeedToHandleDisplayChange()
{
if (vmrSurfaceAllocatorNotify == null)
return false;

//IntPtr currentMonitor = Manager.GetAdapterMonitor(device.CreationParameters.AdapterOrdinal);
IntPtr currentMonitor = _Direct3D.GetAdapterMonitor(device.CreationParameters.AdapterOrdinal);

//IntPtr defaultMonitor = Manager.GetAdapterMonitor(adapterInfo.Adapter);
IntPtr defaultMonitor = _Direct3D.GetAdapterMonitor(adapterInfo.Adapter);

return currentMonitor != defaultMonitor;
}

#endregion

#region Membres de IDisposable

public void Dispose()
{
DeleteSurfaces();
scene.Dispose();
device.Dispose();
}

#endregion

}

public class FourCC
{
private int fourCC = 0;

public FourCC(string fcc)
{
if (fcc.Length != 4)
throw new ArgumentException(fcc + " is not a valid FourCC");

byte[] asc = Encoding.ASCII.GetBytes(fcc);

this.fourCC = asc[0];
this.fourCC |= asc[1] << 8;
this.fourCC |= asc[2] << 16;
this.fourCC |= asc[3] << 24;
}

public FourCC(char a, char b, char c, char d) : this(new string(new char[] {a, b, c, d}))
{}

public FourCC(int fcc)
{
this.fourCC = fcc;
}

public int ToInt32()
{
return this.fourCC;
}

public Guid ToMediaSubtype()
{
return new Guid(this.fourCC.ToString("X") + "-0000-0010-8000-00AA00389B71");
}

public static bool operator ==(FourCC fcc1, FourCC fcc2)
{
return fcc1.fourCC == fcc2.fourCC;
}

public static bool operator !=(FourCC fcc1, FourCC fcc2)
{
return fcc1.fourCC != fcc2.fourCC;
}

public override bool Equals(object obj)
{
if (!(obj is FourCC))
return false;

return (obj as FourCC).fourCC == this.fourCC;
}

public override int GetHashCode()
{
return this.fourCC.GetHashCode();
}
}
}
]

Thanks Steve
/****************************************************************************While the underlying libraries are covered by LGPL, this sample is released as public domain. It is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *****************************************************************************/using System;using System.Collections;using System.Drawing;using System.Diagnostics;using System.Runtime.InteropServices;using System.Text;using System.Windows.Forms;using DirectShowLib;using SlimDX;using SlimDX.Direct3D9;namespace DirectShowLib.Sample{[ComVisible(true)][ClassInterface(ClassInterfaceType.None)]public class Allocator : IVMRSurfaceAllocator9, IVMRImagePresenter9, IDisposable{private const int E_FAIL = unchecked((int) 0x80004005);private const int DxMagicNumber = -759872593;private Control parentControl;private PresentParameters presentParam;private Device device = null;private Surface renderTarget = null;private AdapterInformation adapterInfo = null;private Hashtable textures = null;private Hashtable surfaces = null;private IntPtr[] unmanagedSurfaces = null;private Texture privateTexture = null;private Surface privateSurface = null;private IVMRSurfaceAllocatorNotify9 vmrSurfaceAllocatorNotify = null;private PlaneScene scene = null;private Direct3D _Direct3D = null;public Allocator(Control control){parentControl = control;scene = new PlaneScene();_Direct3D = new Direct3D();//Device.IsUsingEventHandlers = false;CreateDevice();}~Allocator(){Dispose();}private void CreateDevice(){adapterInfo = _Direct3D.Adapters.DefaultAdapter;//adapterInfo = Manager.Adapters.Default;presentParam = new PresentParameters();presentParam.Windowed = true;presentParam.PresentFlags = PresentFlags.Video;presentParam.SwapEffect = SwapEffect.Copy;presentParam.BackBufferFormat = adapterInfo.CurrentDisplayMode.Format;presentParam.DeviceWindowHandle = parentControl.Handle;device = new Device(_Direct3D,0,DeviceType.Hardware,parentControl.Handle,CreateFlags.SoftwareVertexProcessing | CreateFlags.Multithreaded,presentParam);//renderTarget = device.GetRenderTarget(0);/*RenderToSurface rToSurface = new RenderToSurface(device, adapterInfo.CurrentDisplayMode.Width,adapterInfo.CurrentDisplayMode.Height,adapterInfo.CurrentDisplayMode.Format);*/renderTarget = SlimDX.Direct3D9.Surface.CreateRenderTarget(device,640,480,adapterInfo.CurrentDisplayMode.Format,MultisampleType.None,0,true);// just a texture with respective flags set X8R8G8B8//renderTarget = Surface.CreateOffscreenPlain(device, 720, 480, Format.A8R8G8B8, Pool.SystemMemory);//Texture texture = new Texture(device, 512, 512, 0, Usage.RenderTarget, adapterInfo.CurrentDisplayMode.Format, Pool.Default);//renderTarget = texture.GetSurfaceLevel(0);}private void DeleteSurfaces(){lock(this){if (privateTexture != null){privateTexture.Dispose();privateTexture = null;}if (privateSurface != null){privateSurface.Dispose();privateSurface = null;}if (textures != null){foreach (Texture tex in textures.Values){tex.Dispose();}textures = null;}if (surfaces != null){foreach (Surface surf in surfaces.Values){surf.Dispose();}surfaces = null;}}}#region Membres de IVMRSurfaceAllocator9public int InitializeDevice(IntPtr dwUserID, ref VMR9AllocationInfo lpAllocInfo, ref int lpNumBuffers){int width = 1;int height = 1;float fTU = 1.0f;float fTV = 1.0f;if (vmrSurfaceAllocatorNotify == null){return E_FAIL;}int hr = 0;try{//IntPtr unmanagedDevice = device.GetObjectByValue(DxMagicNumber);IntPtr unmanagedDevice = device.ComPointer;//IntPtr hMonitor = Manager.GetAdapterMonitor(adapterInfo.Adapter);IntPtr hMonitor = _Direct3D.GetAdapterMonitor(adapterInfo.Adapter);hr = vmrSurfaceAllocatorNotify.SetD3DDevice(unmanagedDevice, hMonitor);DsError.ThrowExceptionForHR(hr);//if (device.DeviceCaps.TextureCaps.SupportsPower2)if ((device.Capabilities.TextureCaps & TextureCaps.Pow2) != 0){while (width < lpAllocInfo.dwWidth)width = width << 1;while (height < lpAllocInfo.dwHeight)height = height << 1;fTU = (float)(lpAllocInfo.dwWidth) / (float)(width);fTV = (float)(lpAllocInfo.dwHeight) / (float)(height);scene.SetSrcRect(fTU, fTV);lpAllocInfo.dwWidth = width;lpAllocInfo.dwHeight = height;}// NOTE:// we need to make sure that we create textures because// surfaces can not be textured onto a primitive.lpAllocInfo.dwFlags |= VMR9SurfaceAllocationFlags.TextureSurface;DeleteSurfaces();unmanagedSurfaces = new IntPtr[lpNumBuffers];hr = vmrSurfaceAllocatorNotify.AllocateSurfaceHelper(ref lpAllocInfo, ref lpNumBuffers, unmanagedSurfaces);// If we couldn't create a texture surface and // the format is not an alpha format,// then we probably cannot create a texture.// So what we need to do is create a private texture// and copy the decoded images onto it.if (hr < 0){DeleteSurfaces();FourCC fcc = new FourCC("0000");// is surface YUV ?if (lpAllocInfo.Format > fcc.ToInt32()){// create the private textureprivateTexture = new Texture(device,lpAllocInfo.dwWidth,lpAllocInfo.dwHeight,1,Usage.RenderTarget,adapterInfo.CurrentDisplayMode.Format,Pool.Default);privateSurface = privateTexture.GetSurfaceLevel(0);}lpAllocInfo.dwFlags &= ~VMR9SurfaceAllocationFlags.TextureSurface;lpAllocInfo.dwFlags |= VMR9SurfaceAllocationFlags.OffscreenSurface;unmanagedSurfaces = new IntPtr[lpNumBuffers];hr = vmrSurfaceAllocatorNotify.AllocateSurfaceHelper(ref lpAllocInfo, ref lpNumBuffers, unmanagedSurfaces);if (hr < 0)return hr;}else{surfaces = new Hashtable(unmanagedSurfaces.Length);textures = new Hashtable(unmanagedSurfaces.Length);for (int i = 0; i < lpNumBuffers; i++){//Surface surf = new Surface(unmanagedSurfaces);Surface surf = Surface.FromPointer(unmanagedSurfaces);//Texture text = (Texture) surf.GetContainer(new Guid("85C31227-3DE5-4f00-9B3A-F11AC38C18B5"));Texture text = surf.GetContainer<Texture>();surfaces.Add(unmanagedSurfaces, surf);textures.Add(unmanagedSurfaces, text);}}return scene.Init(device);}catch (SlimDXException e){//return e.ErrorCode;return e.ResultCode.Code;}catch{return E_FAIL;}}public int TerminateDevice(IntPtr dwID){DeleteSurfaces();return 0;}public int GetSurface(IntPtr dwUserID, int SurfaceIndex, int SurfaceFlags, out IntPtr lplpSurface){lplpSurface = IntPtr.Zero;if (SurfaceIndex > unmanagedSurfaces.Length)return E_FAIL;lock(this){lplpSurface = unmanagedSurfaces[SurfaceIndex];Marshal.AddRef(lplpSurface);return 0;}}public int AdviseNotify(IVMRSurfaceAllocatorNotify9 lpIVMRSurfAllocNotify){lock(this){vmrSurfaceAllocatorNotify = lpIVMRSurfAllocNotify;IntPtr unmanagedDevice = device.ComPointer;//.GetObjectByValue(DxMagicNumber);//IntPtr hMonitor = Manager.GetAdapterMonitor(Manager.Adapters.Default.Adapter);IntPtr hMonitor = _Direct3D.GetAdapterMonitor(_Direct3D.Adapters.DefaultAdapter.Adapter);return vmrSurfaceAllocatorNotify.SetD3DDevice(unmanagedDevice, hMonitor);}}#endregion#region Membres de IVMRImagePresenter9public int StartPresenting(IntPtr dwUserID){lock(this){if (device == null)return E_FAIL;return 0;}}public int StopPresenting(IntPtr dwUserID){return 0;}public int PresentImage(IntPtr dwUserID, ref VMR9PresentationInfo lpPresInfo){int hr = 0;lock(this){try{// if we are in the middle of the display changeif(NeedToHandleDisplayChange()){// NOTE: this piece of code is left as a user exercise. // The D3DDevice here needs to be switched// to the device that is using another adapter}hr = PresentHelper(lpPresInfo);return hr;}catch (SlimDXException e){return e.ResultCode.Code;}catch{return E_FAIL;}}}private int PresentHelper(VMR9PresentationInfo lpPresInfo){int hr = 0;try {device.SetRenderTarget(0, renderTarget);if (privateTexture != null){Marshal.AddRef(lpPresInfo.lpSurf);//using(Surface surface = new Surface(lpPresInfo.lpSurf))using (Surface surface = Surface.FromPointer(lpPresInfo.lpSurf)){device.StretchRectangle(surface,new Rectangle(0, 0, surface.Description.Width, surface.Description.Height),privateSurface,new Rectangle(0, 0, privateSurface.Description.Width, privateSurface.Description.Height),TextureFilter.None);}hr = scene.DrawScene(device, privateTexture);if (hr < 0)return hr;}else{if (textures.ContainsKey(lpPresInfo.lpSurf)){hr = scene.DrawScene(device, textures[lpPresInfo.lpSurf] as Texture);if (hr < 0)return hr;}elsehr = E_FAIL;}device.Present();return 0;}catch (SlimDXException e){return e.ResultCode.Code;}catch{return E_FAIL;}}private bool NeedToHandleDisplayChange(){if (vmrSurfaceAllocatorNotify == null)return false;//IntPtr currentMonitor = Manager.GetAdapterMonitor(device.CreationParameters.AdapterOrdinal);IntPtr currentMonitor = _Direct3D.GetAdapterMonitor(device.CreationParameters.AdapterOrdinal);//IntPtr defaultMonitor = Manager.GetAdapterMonitor(adapterInfo.Adapter);IntPtr defaultMonitor = _Direct3D.GetAdapterMonitor(adapterInfo.Adapter);return currentMonitor != defaultMonitor;}#endregion#region Membres de IDisposablepublic void Dispose(){DeleteSurfaces();scene.Dispose();device.Dispose();}#endregion}public class FourCC{private int fourCC = 0;public FourCC(string fcc){if (fcc.Length != 4)throw new ArgumentException(fcc + " is not a valid FourCC");byte[] asc = Encoding.ASCII.GetBytes(fcc);this.fourCC = asc[0];this.fourCC |= asc[1] << 8;this.fourCC |= asc[2] << 16;this.fourCC |= asc[3] << 24;}public FourCC(char a, char b, char c, char d) : this(new string(new char[] {a, b, c, d})){}public FourCC(int fcc){this.fourCC = fcc;}public int ToInt32(){return this.fourCC;}public Guid ToMediaSubtype(){return new Guid(this.fourCC.ToString("X") + "-0000-0010-8000-00AA00389B71");}public static bool operator ==(FourCC fcc1, FourCC fcc2){return fcc1.fourCC == fcc2.fourCC;}public static bool operator !=(FourCC fcc1, FourCC fcc2){return fcc1.fourCC != fcc2.fourCC;}public override bool Equals(object obj){if (!(obj is FourCC))return false;return (obj as FourCC).fourCC == this.fourCC;}public override int GetHashCode(){return this.fourCC.GetHashCode();}}}
Steve have you looked over the dource code?
Hi - sorry, I totally forgot about this thread...

VMR9 uses multiple threads, so you need to create your device as multi-threaded (There's a flag to the CreateDevice() call, I'm not sure what it is in C#/SlimDX). I'd guess that's what the problem is (It certainly won't be helping anyway).

If that doesn't solve the problem, you might need one of the SlimDX guys to give you a hand, the exception doesn't really tell you what's going on...

This topic is closed to new replies.

Advertisement