Using virtual devices and mp:// links to stream content between applications (MFormats SDK)

The MFSink object of MFormats SDK provides 2 special options to deliver your content: virtual devices, and mp:// links. This post explains how to use both of these options.

Using virtual devices 

A virtual device is a DirectShow video capture source created by MFSink object  that can be used in third-party applications or DirectShow graphs. Using virtual devices is the easiest way to transmit your stream from MFormats SDK into a DirectShow application.

Please note that virtual devices created by MFormats' objects are DirectShow based and not equal to physical devices (like web cameras) based on windows drivers model. So they might be not available in third party applications like Skype or Google Hangouts if they accept streams from WDM sources only.

To enable a virtual device you need to create an MFSink class object and put frames into it just like into any other receiver object:
// Create sink object. 
MFSinkClass m_objMFSink; 
m_objMFSink = new MFSinkClass(); 

// Initialize it.  
// I'll set the sink name to "MFReaderSink" and call my virtual device "MFormats VSource"  
m_objMFSink.SinkInit("MFReaderSink", "MFormats VSource", null); 

// ... some code to make a thread for putting frames to the sink ...  

// Put frames into sink objects as usuall 
m_objMFSink.ReceiverFramePut(pFrame, -1, "");

Once this is done you can use this device in DirectShow graphs or third party applications.

Try this logic using our sample applications: create a virtual device with Sample File Playback and render it in GraphStudio.

Using mp:// links (our internal transmission protocol)

Except of virtual device creation, MFSink class object also creates an mp:// link that can be played by MFReader just like a common network URL. Using mp:// links is the easiest way to transmit your stream between independent MFormats based applications running on the same machine.

Once you have initialized MFSink object as described above, you can enumerate available sinks in other MFormats application, build the URL and playback it. The URL structure is very simple: it's just a sink name with leading "mp://". For example for the URL for the sink created with the code above is "mp://MFReaderSink".

Here is a code sample:

// Crearte MFReader class object to play the external mp:// link 
MFReaderClass m_objReader = new MFReaderClass(); 
// Get available senders number 
int nCount = 0;  
m_objReader.SendersGetCount(out nCount); 

// Enumerate available senders if needed 

// Get required sender's name 
// I'll use the first sender 
string strName; 
M_VID_PROPS vidProps; 
M_AUD_PROPS audProps; 
m_objReader.SendersGetByIndex(0, out strName, out vidProps, out audProps); 

// As we have got the sender name, we are ready to build the sender URL.  
// It is very simple: a sink name with leading "mp://"  
string senderURL = "mp://" + strName; 

// Now we can open a reader and playback the URL just like a common network stream 
m_objReader.ReaderOpen(senderURL, ""); 

// ... some code to make a loop for picking frames from the reader ...  

// Get frames as you do with any other source  
m_objReader.SourceFrameConvertedGet(ref m_avProps, -1, out pFrame, "");

Try this logic with our sample applications: create a virtual device with Sample File Playback, enumerate it in Sample File Writing and playback in Sample Network Playback.