MPlatform SDK: using MLive and MRenderer with WebRTC

As you might know, our first implementation of WebRTC was done as an MWebRTC class that could be used as a plugin for transmitting WebRTC streams into the network and as a frames source to receive a remote WebRTC stream. Check our posts about remote preview and control for playout and transmitting WebRTC streams and messages between native applications for more information.

In the latest version of MPlatform, we made WebRTC support more natural for MPlatform users and used the same approach as with the NewTek NDI video over IP integration. Starting with MPlatform SDK version 1.6.1.8013 you can use the standard MLive to receive WebRTC streams and MRenderer to play them out.

Rendering WebRTC streams with MRenderer object


Check the MRenderer usage article for more details and try the Playlist sample application to evaluate WebRTC as part of the MRenderer implementation. 

The streamer name is represented as an output line, so you can specify it manually to identify your streamer.



A small code sample: 

// Create a renderer object  
MRendererClass m_objRenderer = new MRendererClass();

//Set own signaling server and room if needed, otherwise Medialooks test server
//with predefined room will be used (https://Medialooks.com:8889/LocalClientNNNNN)
//m_objRenderer.DeviceSet("renderer::signaling_server", "https://localhost:8889/room555", ""); 

// Set the WebRTC device  
m_objRenderer.DeviceSet("renderer", "WebRTC", "");  

//Specify the renderer name to let MLive to identify it  
m_objRenderer.DeviceSet("renderer::line-out", "myWebRTCSource", ""); 

// Start renderer.  
// It will receive stream form m_objPlaylist and out put to NDI  
m_objRenderer.ObjectStart(m_objPlaylist); 

Receiving WebRTC streams with MLive object

To receive a WebRTC stream you should use MLive and initialize the "WebRTC" device just like any other capture card. The available WebRTC sources will be represented as input lines of a "WebRTC" device.

Check MLive Advanced object usage article to get more details and try Writer sample application to evaluate WebRTC without any coding.



A small code sample: 

// Create MFLive Class instance   
MLiveClass m_objMLive = new MLiveClass();

//Set own signaling server and room if needed, otherwise Medialooks test server
//with predefined room will be used (https://Medialooks.com:8889/LocalClientNNNNN)
//m_objMLive.DeviceSet("video", "WebRTC", "signaling_server=https://localhost:8889/room555");

// Set the WebRTC live source    
m_objLive.DeviceSet("video", "WebRTC", "");   

// Get Input lines number.    
// The input lines for WebRTC represents WebRTC stream sources available in a network   
int lCount = 0;  
m_objLive.DeviceGetCount(0, "video::line-in", out lCount);   

// Get available WebRTC stream sources by input lines enumeratng.    
// Please note that WebRTC requires some time to register the source on a signaling server,   
// so you might heed to refresh the devices list several times until you will see your source     
if (lCount > 0)   
{   
    for (int i = 0; i < lCount; i++)   
    {   
        string strName;   
        string strDesc;
        m_objMLive.DeviceGetByIndex(0, "video::line-in", i, out strName, out strDesc);                           
    }   
}   

// Specify required stream source by seting the input line property.    
m_objMLive.DeviceSet("video::line-in", "myWebRTCSource", "");  

// Start live source object  
 m_objMLive.ObjectStart(null);