Christoph
Christoph

Reputation: 2004

Is IMFSampleGrabberSinkCallback really a sink?

I have started writing some streaming code which connects a Windows Media Foundation session to the live555 streaming library. So far, I have started writing a IMFMediaSink and my own IMFStreamSink. However, the code got quickly quite complex.

I was wondering whether I could also use IMFSampleGrabberSinkCallback as it would just receive the samples which I would forward to live555.

Before refactoring the code, I wonder whether the MF sink is really a sink - I remember that in DirectShow, the sample grabber could not be used without another sink as it was a transform. Can I build a topology that receives samples, passes them through a DMO, an encoder and finally to the sink without any other nodes?

Furthermore, I wonder what the disadvantages of such an approach would be (provided it would work)? The obvious one I see is that IMFMediaSink supports multiple streams and hence could coordinate audio and video. However, as live555 does that purely via timestamps, I have no real benefit from it. Are there any other disadvantages?

Upvotes: 0

Views: 738

Answers (2)

Roman Ryltsov
Roman Ryltsov

Reputation: 69642

Sample Grabber works pretty much the same way as DirectShow Sample Grabber: you can insert a pipeline object with additional simplified outer interface so that you obtain ability to "export" payload data from the pipeline as it is streamed. You provide a callback interface to get called as new data is available. This is true for both sample grabbers.

DirectShow SG is more flexible in terms that it is a transform and you can add it anywhere in the topology. MF SG is an output node only. MF SG offers more callback methods (IMFClockStateSink methods). DirectShow SG is a really simple filter [a variant of which is] available in source code as SDK sample.

DirectShow SG was not originally the API core, but it was very popular among developers. I suppose its popularity was the primary reason a similar component was developed for MF: they kept the naming, the concept - everything. In the same time Microsoft retired DirectShow SG and excluded it from most recent OS versions even though it is clear that the API is still being used. Go figure the logic.

Upvotes: 1

Evgeny Pereguda
Evgeny Pereguda

Reputation: 583

You can call MFCreateSampleGrabberSinkActivate function for creating of activate MF object. This function needs MediaType - it must be type of encoding which is needed in your code. You can find example code for capturing video from web camera via MF on site videoinput. It includes source code and allows grab frames in RGB24, RGB32, AYUV formats. If you set H264 format then MF finds the suitable encoder for it and SampleGrabberSink callback with data of H264 format, but you must set the correct MediaType.

Regards.

Upvotes: 1

Related Questions