Sending a video content to a DLNA/UPnP software/device using curl
The purpose of this article is to explain how to push the video content captured through AirPlay to a DLNA/UPnP renderer like XBMC. The technique applies to both mobile and desktop applications. curl is used to perform the task so that the reader can easily test it. It is a short guide and I encourage you to review the UPnP/DLNA specifications to get an exhaustive understanding of this logic.
UPnP (Universal Plug and Play) is a networking standard. One of its core capability is to facilitate the discovery of intelligent devices available on the network through its Simple Service Discovery Protocol (SSDP). In theory, with UPnP, you can play or share media anytime you want and anywhere you are.
DLNA is another standard that derives from UPnP. Basically, once a product is DLNA certified, it implies that the device/software is a UPnP device that meets a minimum of requirements. So DLNA can be losely viewed as a more restrictive “subgroup” of UPnP. The objective of DLNA is to ensure full interoperability between compliant devices.
As mentioned earlier, to replicate what is being done in this article, you just need curl and XBMC.
First, you need to identify potential renderers on your network. In our case, we already know that XBMC should be able to answer our requests but let’s pretend that we did not know and let’s run XBMC. As mentioned earlier, all UPnp/DLNA devices announce their availability thanks to SSDP. All you need to do is “ask” these renderers to let you know that they are available by sending a UDP message to the multicast address 22.214.171.124 on port 1900:
M-SEARCH * HTTP/1.1
You should get back something like:
HTTP/1.1 200 OK
Server: UPnP/1.0 DLNADOC/1.50 Platinum/0.6.9.1
Next, if you use the Location to query the renderer, you will get a description of the devices and the services that it supports:
<?xml version=”1.0″ encoding=”UTF-8″?>
<root xmlns=”urn:schemas-upnp-org:device-1-0″ xmlns:dlna=”urn:schemas-dlna-org:device-1-0″>
<modelDescription>XBMC Media Center – Media Renderer</modelDescription>
<modelName>XBMC Media Center</modelName>
What we are interested in is the AVTransport service which enables to send play and stop instructions to the renderer. Retrieve the controlURL. Mine looks like:
It takes two calls to the renderer to play a video content. The first call to “load” the content and the second call to “play” the content.
Assuming that you have a video content with the url http://my.site.com/path/to/my/content.mp4, then you load the content by executing the following command:
curl -H ‘Content-Type: text/xml; charset=utf-8’ -H ‘SOAPAction: “urn:schemas-upnp-org:service:AVTransport:1#SetAVTransportURI”‘ -d ‘<?xml version=”1.0″ encoding=”utf-8″?><s:Envelope s:encodingStyle=”http://schemas.xmlsoap.org/soap/encoding/” xmlns:s=”http://schemas.xmlsoap.org/soap/envelope/”><s:Body><u:SetAVTransportURI xmlns:u=”urn:schemas-upnp-org:service:AVTransport:1″><InstanceID>0</InstanceID><CurrentURI><![CDATA[http://my.site.com/path/to/my/content.mp4]]></CurrentURI><CurrentURIMetaData></CurrentURIMetaData></u:SetAVTransportURI></s:Body></s:Envelope>’ ‘http://192.168.1.101:59772/AVTransport/21fc4817-b8f7-ee43-1461-68a55e55fce0/control.xml‘
Next, we want to play it:
curl -H ‘Content-Type: text/xml; charset=utf-8’ -H ‘SOAPAction: “urn:schemas-upnp-org:service:AVTransport:1#Play”‘ -d ‘<?xml version=”1.0″ encoding=”utf-8″?><s:Envelope s:encodingStyle=”http://schemas.xmlsoap.org/soap/encoding/” xmlns:s=”http://schemas.xmlsoap.org/soap/envelope/”><s:Body><u:Play xmlns:u=”urn:schemas-upnp-org:service:AVTransport:1″><InstanceID>0</InstanceID><Speed>1</Speed></u:Play></s:Body></s:Envelope>’ ‘http://192.168.1.101:59772/AVTransport/21fc4817-b8f7-ee43-1461-68a55e55fce0/control.xml‘