2

I am working on a custom video player. I am using a mix of DirectShow/Media Foundation in my architecture. Basically, I'm using DS to grab VOB frames(unsupported by MF). I am able to get a sample from DirectShow but am stuck on passing it to the renderer. In MF, I get a Direct3DSurface9 (from IMFSample), and present it on the backbuffer using the IDirect3D9Device.

Using DirectShow, I'm getting IMediaSample as my data buffer object. I don't know how to convert and pass this as IMFSample. I found others getting bitmap info from the sample and use GDI+ to render. But my video data may not always have RGB data. I wish to get a IDirect3DSurface9 or maybe IMFSample from IMediaSample and pass it for rendering, where I will not have to bother about color space conversion.

I'm new to this. Please correct me if I'm going wrong. Thanks

casperOne
  • 73,706
  • 19
  • 184
  • 253
mots_g
  • 637
  • 8
  • 27

1 Answers1

4

IMediaSample you have from upstream decoder in DirectShow is nothing but a wrapper over memory backed buffer. There is no and cannot be any D3D surface behind it (unless you take care of it on your own and provide a custom allocator, in which case you would not have a question in first place). Hence, you are to memory-copy data from this buffer into MF sample buffer.

There you come to the question that you want buffer formats (media types) match, so that you could copy without conversion. One of the ways - and there might be perhaps a few - is to first establish MF pipeline and find out what exactly pixel type you are offered with buffers on the video hardware. Then make sure you have this pixel format and media type in DirectShow pipeline, by using respective grabber initialization or color space conversion filters, or via color space conversion DMO/MFT.

Roman R.
  • 68,205
  • 6
  • 94
  • 158
  • Thanks for replying. Suppose I wish to populate a D3D surface with the buffer data I have(in IMediaSample), how do I achieve this? I couldn't use the grabber approach to get the sample in the format needed by MF, because the grabber wouldn't connect before the renderer but always lied unconnected or, it would connect just before the decoder. I then resorted to an approach described here: http://www.codeproject.com/KB/audio-video/VideoImageGrabber.aspx I am now stuck as to how do I copy it on D3DSurface. I tried 'memcpy' but I couldn't see my frame data on rendering. – mots_g Feb 07 '12 at 10:59
  • You have to come up with a suitable sequence of initialization in order to make sure formats match. Or, alternatively, you can create `DShow` and `MF` parts separately restricting to some known formats, and then do conversion yourself, such as with help of `Color Converter DSP` http://msdn.microsoft.com/en-us/library/windows/desktop/ff819079%28v=vs.85%29.aspx – Roman R. Feb 07 '12 at 11:05