• Advertisement
Sign in to follow this  

Sample Grabber

This topic is 4437 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Because my attempt with the VMR failed, I have decided to use a Sample Grabber to get a video rendered in my game. I am having some trouble though. I am using the SampleCB Callback and I have to get the the sample displayed onto a texture. I however don't really know how to do this, so can anyone help me? I tried doing the following, but it didn't work:
public int SampleCB(double SampleTime, IMediaSample pSample)
{
	IntPtr pBuffer;
	pSample.GetPointer(out pBuffer);

	int scan0 = (int)pBuffer;
	scan0 += (height - 1) * stride;
	Bitmap bmp = new Bitmap(width, height, -stride, System.Drawing.Imaging.PixelFormat.Format24bppRgb, (IntPtr)scan0);
	Surface surf = new Surface(this.device, bmp, Pool.Default);

	if (readBuffer == 0)
	{
		lock(this)
		{
			this.device.StretchRectangle(surf, 
				new Rectangle(0, 0, surf.Description.Width, surf.Description.Height), 
                                this.secondary.GetSurfaceLevel(0), 
				new Rectangle(0, 0, 640, 480), 
				TextureFilter.None);

				readBuffer = 1;
		}
	}
	else
	{
                lock (this) {
		        this.device.StretchRectangle(surf, 
			        new Rectangle(0, 0, surf.Description.Width,                   surf.Description.Height),					                        
                                this.primary.GetSurfaceLevel(0), 
                                new Rectangle(0, 0, 640, 480), 
		                TextureFilter.None);

		                readBuffer = 0;
               }
	}

	surf.Dispose();
	bmp.Dispose();

	Marshal.ReleaseComObject(pSample);
	return 0;
}

A note about the "readBuffer" variable, it just allows me to write to the texture not currently being drawn on screen, so it sort of acts like a buffer. Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement