VMR9 : Allocator
VMR9 : Allocator
VMR9 : Allocator
VMR9 : Allocator
VMR9 : Allocator
VMR9 : Allocator VMR9 : Allocator VMR9 : Allocator VMR9 : Allocator VMR9 : Allocator VMR9 : Allocator VMR9 : Allocator VMR9 : Allocator
VMR9 : Allocator VMR9 : Allocator
VMR9 : Allocator
Go Back  Xtreme Visual Basic Talk > > > > VMR9 : Allocator


Reply
 
Thread Tools Display Modes
  #1  
Old 02-20-2007, 03:46 PM
RedKnight's Avatar
RedKnight RedKnight is offline
Regular
 
Join Date: Dec 2003
Location: Golden, Co
Posts: 70
Default VMR9 : Allocator


I haven't found many resources dealing with VB.NET and DirectShow, nor even C#.

DirectShow.Net as created easy access to the interfaces of DirectShow. Anyway I have been trying to follow their converted Allocator sample (in C#) and some found resources on the internet.

I think I have gotten far but having the main issue. I can't present the video image.

What I'm trying to do:
Basically play a video (through DirectShow) with the VMR9 filter that instead render in a self-made window but on a DirectX surface.

What I got:
I have been able to create a graph, with the VMR9 filter as the renderer filter and also 'notify' the renderer (VMR9) of the custom Allocator class. In the Allocator class I create a render target (and helper), tell the renderer (VMR9) to create surfaces with a 'power of 2' dimension.

after that when the 'PresentImage' event fires in the Allocator my D3D Device doesn't do anything. It doesn't error out, and it doesn't Present the back buffer, nor does it clear the back buffer to a noticeable color.

(You might notice that I'm not rendering to the render-to-target surface, thats just me trying to figure out what is going on)

Any guidance would be great, Thanks.

Code:
<ComVisible(True)> _
<ClassInterface(ClassInterfaceType.None)> _
Friend Class Xilon_VideoAllocator
	Implements IVMRSurfaceAllocator9
	Implements IVMRImagePresenter9
	Implements IDisposable

	Private rtsSurface As RenderToSurface
	Private surTarget As Surface
	Friend texTarget As Texture

	Private sanVM9SurfaceAllocatorNotify As IVMRSurfaceAllocatorNotify9
	Private iptSurfaces() As IntPtr
	Private iptMonitor As IntPtr

	Private intVideoWidth As Integer
	Private intVideoHeight As Integer
	Private sngTextureU As Single
	Private sngTexturev As Single

	Private disposedValue As Boolean = False

	Friend XilonEngine As Xilon_Engine

	Public Sub New(ByRef Engine As Xilon_Engine)
		XilonEngine = Engine
	End Sub

	Public Function AdviseNotify(ByVal lpIVMRSurfAllocNotify As DirectShowLib.IVMRSurfaceAllocatorNotify9) As Integer Implements DirectShowLib.IVMRSurfaceAllocator9.AdviseNotify
		XilonEngine.D3DDevice.Clear(ClearFlags.Target Or ClearFlags.ZBuffer, Drawing.Color.White, 1.0F, 0)

		sanVM9SurfaceAllocatorNotify = lpIVMRSurfAllocNotify
		iptMonitor = Manager.GetAdapterMonitor(XilonEngine.AdapterInfo.Adapter)
		Dim unmanagedDevice As IntPtr = XilonEngine.D3DDevice.GetObjectByValue(DxMagicNumber)
		SyncLock Me
			sanVM9SurfaceAllocatorNotify.SetD3DDevice(unmanagedDevice, iptMonitor)
		End SyncLock
		XilonEngine.D3DDevice.Clear(ClearFlags.Target Or ClearFlags.ZBuffer, Drawing.Color.Green, 1.0F, 0)

	End Function

	Public Function GetSurface(ByVal dwUserID As System.IntPtr, ByVal SurfaceIndex As Integer, ByVal SurfaceFlags As Integer, ByRef lplpSurface As System.IntPtr) As Integer Implements DirectShowLib.IVMRSurfaceAllocator9.GetSurface
		lplpSurface = IntPtr.Zero
		SyncLock Me
			If Not iptSurfaces Is Nothing Then
				If SurfaceIndex <= iptSurfaces.Length Then
					lplpSurface = iptSurfaces(SurfaceIndex)
					Marshal.AddRef(lplpSurface)
				End If
			End If
		End SyncLock
		Return 0
	End Function

	Public Function InitializeDevice(ByVal dwUserID As System.IntPtr, ByRef lpAllocInfo As DirectShowLib.VMR9AllocationInfo, ByRef lpNumBuffers As Integer) As Integer Implements DirectShowLib.IVMRSurfaceAllocator9.InitializeDevice
		Dim Width As Integer = 1, Height As Integer = 1

		While (Width < lpAllocInfo.dwWidth)
			Width = Width << 1
		End While
		While (Height < lpAllocInfo.dwHeight)
			Height = Height << 1
		End While
		'Change WxH to be dimensions of power of 2

		sngTextureU = Convert.ToSingle(lpAllocInfo.dwWidth) / Convert.ToSingle(Width)
		sngTexturev = Convert.ToSingle(lpAllocInfo.dwHeight) / Convert.ToSingle(Height)
		'arrange texture coordinates to cut extra space

		lpAllocInfo.dwWidth = Width
		lpAllocInfo.dwHeight = Height

		lpAllocInfo.dwFlags = lpAllocInfo.dwFlags Or VMR9SurfaceAllocationFlags.TextureSurface

		XilonEngine.D3DDevice.Clear(ClearFlags.Target Or ClearFlags.ZBuffer, Drawing.Color.Yellow, 1.0F, 0)

		ReDim iptSurfaces(lpNumBuffers)
		sanVM9SurfaceAllocatorNotify.AllocateSurfaceHelper(lpAllocInfo, lpNumBuffers, iptSurfaces)
		'let the VMR9 filter to create the surfaces

		XilonEngine.D3DDevice.Clear(ClearFlags.Target Or ClearFlags.ZBuffer, Drawing.Color.Orange, 1.0F, 0)

		intVideoWidth = lpAllocInfo.szNativeSize.Width
		intVideoHeight = lpAllocInfo.szNativeSize.Height

		rtsSurface = New RenderToSurface(XilonEngine.D3DDevice, Width, Height, Format.A8R8G8B8, False, DepthFormat.Unknown)
		texTarget = New Texture(XilonEngine.D3DDevice, Width, Height, 1, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default)
		surTarget = texTarget.GetSurfaceLevel(0)

		XilonEngine.D3DDevice.Clear(ClearFlags.Target Or ClearFlags.ZBuffer, Drawing.Color.Purple, 1.0F, 0)

		Return 0
	End Function

	Public Function TerminateDevice(ByVal dwID As System.IntPtr) As Integer Implements DirectShowLib.IVMRSurfaceAllocator9.TerminateDevice
		Return 0
	End Function

	Public Function PresentImage(ByVal dwUserID As System.IntPtr, ByRef lpPresInfo As DirectShowLib.VMR9PresentationInfo) As Integer Implements DirectShowLib.IVMRImagePresenter9.PresentImage

		Dim surTemp As Surface, texTemp As Texture
		If lpPresInfo.lpSurf <> IntPtr.Zero Then
			SyncLock Me
				'SyncLock XilonEngine.D3DDevice
				XilonEngine.D3DDevice.Clear(ClearFlags.Target Or ClearFlags.ZBuffer, Drawing.Color.Blue, 1.0F, 0)

				surTemp = New Surface(lpPresInfo.lpSurf)
				texTemp = CType(surTemp.GetContainer(IID_IDirect3DTexture9), Texture)

				'rtsSurface.BeginScene(surTarget)
				'rtsSurface.Device.SetTexture(0, texTemp)

				XilonEngine.D3DDevice.BeginScene()

				DXSetTexture(XilonEngine, texTemp)
				DXRender2DBox(XilonEngine, 0, 0, intVideoWidth, intVideoHeight, intVideoWidth * 0.5, intVideoHeight * 0.5, Color.White, 0, 0, 0, sngTextureU, sngTexturev)

				XilonEngine.D3DDevice.SetTexture(0, Nothing)

				XilonEngine.D3DDevice.EndScene()
				XilonEngine.D3DDevice.Present()

				'rtsSurface.EndScene(Filter.Box)
				'rtsSurface.Device.Present()
				'End SyncLock
			End SyncLock

			Return 0
		End If
	End Function

	Public Function StartPresenting(ByVal dwUserID As System.IntPtr) As Integer Implements DirectShowLib.IVMRImagePresenter9.StartPresenting
		XilonEngine.D3DDevice.Clear(ClearFlags.Target Or ClearFlags.ZBuffer, Drawing.Color.Pink, 1.0F, 0)
		Return 0
	End Function

	Public Function StopPresenting(ByVal dwUserID As System.IntPtr) As Integer Implements DirectShowLib.IVMRImagePresenter9.StopPresenting
		Return 0
	End Function

	Protected Overrides Sub Finalize()
		Me.Dispose()
		MyBase.Finalize()
	End Sub

	Protected Overridable Sub Dispose(ByVal disposing As Boolean)
		If Not Me.disposedValue Then
			If disposing Then
				If Not rtsSurface Is Nothing Then rtsSurface.Dispose()
				rtsSurface = Nothing
				If Not surTarget Is Nothing Then surTarget.Dispose()
				surTarget = Nothing
				If Not texTarget Is Nothing Then texTarget.Dispose()
				texTarget = Nothing

				Dim surTemp As Surface
				For Each iptSurface As IntPtr In iptSurfaces
					surTemp = New Surface(iptSurface)
					If Not surTemp Is Nothing Then surTemp.Dispose()
					surTemp = Nothing
				Next iptSurface

			End If
		End If
		Me.disposedValue = True
	End Sub

#Region " IDisposable Support "
	' This code added by Visual Basic to correctly implement the disposable pattern.
	Public Sub Dispose() Implements IDisposable.Dispose
		' Do not change this code.  Put cleanup code in Dispose(ByVal disposing As Boolean) above.
		Dispose(True)
		GC.SuppressFinalize(Me)
	End Sub
#End Region

End Class
Reply With Quote
  #2  
Old 02-28-2007, 11:57 AM
RedKnight's Avatar
RedKnight RedKnight is offline
Regular
 
Join Date: Dec 2003
Location: Golden, Co
Posts: 70
Default

Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
VMR9 : Allocator
VMR9 : Allocator
VMR9 : Allocator VMR9 : Allocator
VMR9 : Allocator
VMR9 : Allocator
VMR9 : Allocator VMR9 : Allocator VMR9 : Allocator VMR9 : Allocator VMR9 : Allocator VMR9 : Allocator VMR9 : Allocator
VMR9 : Allocator
VMR9 : Allocator
 
VMR9 : Allocator
VMR9 : Allocator
 
-->