Discussion:
DirectX and C#
(too old to reply)
Kav
2006-01-30 17:40:32 UTC
Permalink
Hello,
I apologize in advance for my “Greenness” .

I posted a question a couple weeks ago asking how I could render a DIB frame
a custom decoder from unmanaged code to a c# window using DirectX – i.e. I
would like to get an overlay surface from c# and write my frame to the
surface then render it.

From what I’ve now found out, this isn’t an easy task. It sounded simple
enough but after looking at DirectX 9, only later to realize that most direct
show stuff was deprecated, and DirectX 10 I’m beginning to get worried.

Anyway, if anyone knows the simplest approach please, do tell. What
book/manual to rtfm, do I have to use filters, can I just blit my frames from
unmanaged code, is it worth buying a DirectX book which all seem to lean
towards game development. Should I use DirectX 10?

My app is a c# managed code. I have an unmanaged dll that is receiving
mpeg4 video frames over the net. I’ve got a custom decoder that can produce
raw video frames. Currently I was just using DDraw routines with a pop up
mfc window. I want to remove this last part and place the rendering in my c#
app with the dll providing me with video frames.

Thanks in advance for your help,
--
Chris Kavanagh

Software Developer
LibreStream Technologies Inc.
www.LibreStream.com
Unit 200 - 55 Rothwell Rd.
Winnipeg, Manitoba
Canada R3P 2M5
Thore Karlsen [DShow MVP]
2006-01-30 17:47:55 UTC
Permalink
Post by Kav
Hello,
I apologize in advance for my “Greenness” ?.
I posted a question a couple weeks ago asking how I could render a DIB frame
a custom decoder from unmanaged code to a c# window using DirectX – i.e. I
would like to get an overlay surface from c# and write my frame to the
surface then render it.
From what I’ve now found out, this isn’t an easy task. It sounded simple
enough but after looking at DirectX 9, only later to realize that most direct
show stuff was deprecated?, and DirectX 10 I’m beginning to get worried.
Anyway, if anyone knows the simplest approach please, do tell. What
book/manual to rtfm, do I have to use filters, can I just blit my frames from
unmanaged code, is it worth buying a DirectX book which all seem to lean
towards game development. Should I use DirectX 10?
My app is a c# managed code. I have an unmanaged dll that is receiving
mpeg4 video frames over the net. I’ve got a custom decoder that can produce
raw video frames. Currently I was just using DDraw routines with a pop up
mfc window. I want to remove this last part and place the rendering in my c#
app with the dll providing me with video frames.
If you want to use overlay surfaces, I believe you have to use
DirectDraw. DirectDraw has been deprecated, and I don't know if there
are managed interfaces for it. If you want to use Direct3D instead
(meaning no overlays), you should be able to use the managed interfaces
from C#, and I wouldn't expect that to be a big deal.

It doesn't sound like there's any need to bother with DirectShow, so if
I were you I would just use the managed interfaces for Direct3D.
--
New to newsgroups? Read: http://dev.6581.com/newsgroups.html
Alessandro Angeli [MVP::DigitalMedia]
2006-01-30 21:21:53 UTC
Permalink
Post by Thore Karlsen [DShow MVP]
If you want to use overlay surfaces, I believe you have
to use DirectDraw. DirectDraw has been deprecated, and I
don't know if there are managed interfaces for it.
Incredibly as it seems, MS deprecated and pulled out DD7
from the DX8 SDK but provided full managed DD7 support in
the mDX9 SDK.
--
// Alessandro Angeli
// MVP :: Digital Media
// a dot angeli at psynet dot net
Thore Karlsen [DShow MVP]
2006-01-30 21:35:21 UTC
Permalink
On Mon, 30 Jan 2006 22:21:53 +0100, "Alessandro Angeli
Post by Alessandro Angeli [MVP::DigitalMedia]
Post by Thore Karlsen [DShow MVP]
If you want to use overlay surfaces, I believe you have
to use DirectDraw. DirectDraw has been deprecated, and I
don't know if there are managed interfaces for it.
Incredibly as it seems, MS deprecated and pulled out DD7
from the DX8 SDK but provided full managed DD7 support in
the mDX9 SDK.
OK, that's just crazy. :)
--
New to newsgroups? Read: http://dev.6581.com/newsgroups.html
Iain
2006-01-30 18:37:23 UTC
Permalink
Post by Kav
Hello,
I apologize in advance for my “Greenness” .
I posted a question a couple weeks ago asking how I could render a DIB frame
a custom decoder from unmanaged code to a c# window using DirectX – i.e. I
would like to get an overlay surface from c# and write my frame to the
surface then render it.
From what I’ve now found out, this isn’t an easy task. It sounded simple
enough but after looking at DirectX 9, only later to realize that most direct
show stuff was deprecated, and DirectX 10 I’m beginning to get worried.
DirectShow is in no way deprecated.

MS have simply moved it from the DirectX SDK to the platform SDK. In fact
it is the better fit there (as it's used much more widely than gaming),
though the mechanics of the move and communication could have been done
better!
Post by Kav
Anyway, if anyone knows the simplest approach please, do tell. What
book/manual to rtfm, do I have to use filters, can I just blit my frames from
unmanaged code, is it worth buying a DirectX book which all seem to lean
towards game development. Should I use DirectX 10?
My app is a c# managed code. I have an unmanaged dll that is receiving
mpeg4 video frames over the net. I’ve got a custom decoder that can produce
raw video frames. Currently I was just using DDraw routines with a pop up
mfc window. I want to remove this last part and place the rendering in my c#
app with the dll providing me with video frames.
Thanks in advance for your help,
I'm not entirely sure I get this. You have a non direct show decoder which
produces DIB frames. YOu want to blit these into a managed DirectX
surface.

Do not bother with DirectShow. Instead go straight to DirectX. DX10 is
not out yet so I wouldn't worry about this and the basics will be the same
in any event.

What you need to do (broadly) is to create a D3D texture and copy the dib
onto the texture. YOu can then do pretty much anything you want with it.
This should be relatively easy.

Managed DirectX is great in that you it's a lot quicker to code. It is
crap in that the MS docs are REALLY pathetic.

I've got Managed DirectX by Miller (who wrote MDX) and also 3D Game
Programming for DirectX 9.0 by Luna which covers some of the basics rather
better, but is in C++. THe two are pretty much mirror images of each
other.

Or did you want to do something else?


Iain
--
Iain Downs (DirectShow MVP)
Commercial Software Therapist
www.idcl.co.uk
Kav
2006-02-10 14:56:29 UTC
Permalink
Hello,

This is exactly what I'd like to do - thanks for your input.

I've started playing around some more and working through Managed DirectX9
by Tom Miller.

I was wondering if anyone could comment on my first pass approach given my
slowly growing but still very limited knowledge in this area :)

I'll have all my managed directX objects and draw calls in my c# app. I
want to use a managed texture object to render video frames from c#, but I'd
like to pass that object into my unmanaged c++ code using something like
myManagedVideoFrameTexture.UnmanagedComPointer for processing via something
like a p/invoke call down into a dll.

Basically, in my unmanaged code, I'll have a thread that will continue
decoding into the textures private data via LockRect().



for ( ; ; ) {
D3DLOCKED_RECT rect;
GetNextEncodedVideoFrame(pEncodedVideoBuffer);
pIDirect3DTexture->LockRect(0,&rect,NULL,flags);
pDecodedYUY2Buffer = rect.pBits;
pMyDecoder->decode(pEncodedVideoBuffer ,pDecodedYUY2Buffer);
pIDirect3DTexture->UnlockRect(0);
}


Meanwhile, in c#

protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) {

device.BeginScene();
device.SetTexture(0, myManagedVideoFrameTexture);
device.VertexFormat = CustomVertex.TransformedTextured.Format;
device.SetStreamSource(0, vertices, 0);

device.DrawPrimitives(PrimitiveType.TriangleFan, 0, 2);
device.EndScene();
device.Present();
this.Invalidate();
}

I hope I didn't just embarrass myself!!! Is this a reasonable solution?
I've avoided using DirectDraw (I messed up in my org message, I meant to say
DirectDraw was deprecated). I hope as long as I use direct3d porting should
be easy b/w dx9 and dx10.

Thanks again for your help!
Chris
--
Chris Kavanagh

Software Developer
LibreStream Technologies Inc.
www.LibreStream.com
Unit 200 - 55 Rothwell Rd.
Winnipeg, Manitoba
Canada R3P 2M5
Post by Iain
Post by Kav
Hello,
I apologize in advance for my “Greenness” .
I posted a question a couple weeks ago asking how I could render a DIB frame
a custom decoder from unmanaged code to a c# window using DirectX – i.e. I
would like to get an overlay surface from c# and write my frame to the
surface then render it.
From what I’ve now found out, this isn’t an easy task. It sounded simple
enough but after looking at DirectX 9, only later to realize that most direct
show stuff was deprecated, and DirectX 10 I’m beginning to get worried.
DirectShow is in no way deprecated.
MS have simply moved it from the DirectX SDK to the platform SDK. In fact
it is the better fit there (as it's used much more widely than gaming),
though the mechanics of the move and communication could have been done
better!
Post by Kav
Anyway, if anyone knows the simplest approach please, do tell. What
book/manual to rtfm, do I have to use filters, can I just blit my frames from
unmanaged code, is it worth buying a DirectX book which all seem to lean
towards game development. Should I use DirectX 10?
My app is a c# managed code. I have an unmanaged dll that is receiving
mpeg4 video frames over the net. I’ve got a custom decoder that can produce
raw video frames. Currently I was just using DDraw routines with a pop up
mfc window. I want to remove this last part and place the rendering in my c#
app with the dll providing me with video frames.
Thanks in advance for your help,
I'm not entirely sure I get this. You have a non direct show decoder which
produces DIB frames. YOu want to blit these into a managed DirectX
surface.
Do not bother with DirectShow. Instead go straight to DirectX. DX10 is
not out yet so I wouldn't worry about this and the basics will be the same
in any event.
What you need to do (broadly) is to create a D3D texture and copy the dib
onto the texture. YOu can then do pretty much anything you want with it.
This should be relatively easy.
Managed DirectX is great in that you it's a lot quicker to code. It is
crap in that the MS docs are REALLY pathetic.
I've got Managed DirectX by Miller (who wrote MDX) and also 3D Game
Programming for DirectX 9.0 by Luna which covers some of the basics rather
better, but is in C++. THe two are pretty much mirror images of each
other.
Or did you want to do something else?
Iain
--
Iain Downs (DirectShow MVP)
Commercial Software Therapist
www.idcl.co.uk
Iain
2006-02-10 16:05:29 UTC
Permalink
Post by Kav
Hello,
This is exactly what I'd like to do - thanks for your input.
I've started playing around some more and working through Managed DirectX9
by Tom Miller.
I've not so far done anything which combines managed and unmanaged (in fact
I've done no unmanaged <g>).

I don't see any particular reason why it can't be made to work.

I did not see in your sample how you passed the texture/surface between
managed and unmanaged which would appear to me to be the critical aspect.

Iain
--
Iain Downs (DirectShow MVP)
Commercial Software Therapist
www.idcl.co.uk
Continue reading on narkive:
Loading...