Log in

View Full Version : DirectShow: memcpy() into an Overlay Mixer's IMediaSample buffer?


bitbit
1st June 2008, 11:01
Hi,

I am new to DirectShow programming. So please pardon if I am not making sense and by posting here I am looking for enlightenment.

I am tryingto write a DirectShow decoding filter. At this point I am just sending blank YV12 frames to the Overlay Mixer. I have 2 threads to implement an output queue. The output thread takes a completed buffer at the queue head and sends it to the Overlay Mixer to be displayed. So it needs to copy the (YV12) pixel data into the IMediaSample obtained from Overlay Mixer's allocator. I used some simple "memcpy()'s" with the pointer given by IMediaSample::GetPointer() to do that.

What I found was those "memcpy()'s" are extremely slow! I reached this conclusion because I can see how slow the output thread is looping by the size of the (FIFO) queue. And if I raised the priority of the output thread above that of the input thread, the input thread got starved. Now if I left out those "memcpy()'s" and just sent the untouched IMediaSample back to the Overlay Mixer, the output thread just took off, no matter what priority the output thread was at, because the input thread currently doesn't do much. I also tried doing a similar "memcpy()" with the input thread's buffers and they didn't affect the performance like that.

So my question is: is "memcpy()" the right way to send the pixel data to the Overlay Mixer, or am I missing something? I suspect the memory in the IMediaSample from the Overlay Mixer is video memory since accessing it is slow. Is that true? If so, should there be some specialized method to "write" to video memory? Like DMA over the AGP bus?

If just sending a decoded frame to the video card took so many CPU cycles, trying to write "fast" code to decode the frame itself isn't that interesting anymore, is it?:p

Thanks in advance for your help!