PDF Print E-mail
Written by Daniel P   
Tuesday, 16 January 2007

When I was testing the Mpeg decoder with movies of size 320x240, I didn't notice the problem. But when I started playing movies of size 640x480, I had a problem with writing the data to the GraphicsStream of my backbuffer object. So I rewrote the code as follow to get rid of the ineffeciency introduced by calling the GraphicsStream Write method for every bytes.

The code will copy the y, u, v components of the decoder output to the NV12 format of the DirectDraw surface. And it's almost identical to C/C++ code.

GraphicsStream gs; // our stream object
// scanPtr is a pointer to the y component
// scanR is a pointer to the Cr component

gs = backBuffer.Lock(LockFlags.WriteOnly).Data;
byte * tmpPtr = (byte*)((int)gs.InternalDataPointer+gs.Position);
byte * dst = tmpPtr;
for( int i = 1; i <= height; i++ )
{
  for( int j = 0; j < width; j++ )
  {
    *dst++ = *scanPtr++;
  }
  dst = tmpPtr+i*pitch;
}
tmpPtr = dst;
gs.Position += (height*pitch);         
for( int i = 1; i <= height/2; i++ )
{
  for( int j = 0; j < width/2; j++ )
  {
    *dst++ = *scanPtr++;
    *dst++ = *scanR++;
  }
  dst = tmpPtr+i*pitch;
}
gs.Position += (lenght*2);
backBuffer.Unlock();

I googled on the topic and I didn't come up with much. So if you're finding your GraphicsStream object writing too slow, you might want to try something like the above.  My situation was a bit particular because my decoder output is in native memory, but that's a start.




Bookmark it...
Digg!Reddit!Del.icio.us!Google!Facebook!Slashdot!Technorati!StumbleUpon!Newsvine!Furl!Yahoo!Ma.gnolia!
 
< Prev   Next >
Joomla Template by Joomlashack
Joomla Templates by JoomlaShack Joomla Templates by Compass Design