Author Topic: DLNA Media Controller plugin - Common library for UPnP AV  (Read 196714 times)

Offline guessed

  • Master Member
  • *******
  • Posts: 5300
  • Karma: +92/-22
  • Release compat is not a bolted-on afterthought
Re: Common library and services for UPnP AV / DLNA control
« Reply #15 on: October 07, 2013, 02:35:06 pm »
Not my intent to put you off, just to ensure that you're aware of the UPnP ruleset, vs what MCV has done...  mostly to avoid problems down the line (where we assume that the MCV [UPnP rules were correct, and box ourselves into a corner)...  This is easy to do, since they often don't validate stuff.

Quote
Ok, we keep a full service file for each specific UPnP device. I just discovered that they can be easily retrieved from one URL displayed by Device Spy. No need to create the file manually.
Yup, that's what I was referring to when I said you could do it dynamically.  Each UPnP endpoint provides a way to retrieve these, and they could be stored locally, using locally-derived names, as needed.  The rest would have to be code-gen'd, but again, not mission impossible (I tried this some time back in the SQ stuff, in UI4, but it should work better in UI5)

Quote
Is it possible with lua to go through the services attached to a device ?
There's a method to "ask" if a Device supports a service, not enumerate them, but I've never tried it:
    http://wiki.micasaverde.com/index.php/Luup_Lua_extensions#function:_device_supports_service

Worst case, it's always possible to derive since the I_*.xml stuff gets code-gen'd into fns.  You can likely grab hold of the fn table from inside of Lua, and then just enum it (again, haven't tried, but lots of stuff like this is exposed in Lua, so there's a lot of hacking potential).  The names of the code-gen'd stuff follow the Service/Action names with a reasonable pattern (a bit lossy).

... On a related note, I've always wondered if this technique can be used to dynamically inject methods [at startup, etc] into the runtime map of an I_*.xml, so that you could do the type of thing really needed....  just haven't had the time to play with that (or inclination, since I'll eventually move off Vera, it's just my prototyping platform).

I suspect the Service validations, added in UI5, would get a little in the way if it were tried.

Offline lolodomo

  • Moderator
  • Master Member
  • *****
  • Posts: 3484
  • Karma: +74/-10
Re: Common library and services for UPnP AV / DLNA control
« Reply #16 on: October 07, 2013, 03:34:43 pm »
Quote
Is it possible with lua to go through the services attached to a device ?
There's a method to "ask" if a Device supports a service, not enumerate them, but I've never tried it:
    http://wiki.micasaverde.com/index.php/Luup_Lua_extensions#function:_device_supports_service

This function does not eexactly what I expect because it returns true if you have a variable of a certain service id set for the device, even if this service is not declared in the D_xxx.xml file.
You could say that it might not normal to be in such a case. Maybe something to change in the Sonos plugin.

Offline lolodomo

  • Moderator
  • Master Member
  • *****
  • Posts: 3484
  • Karma: +74/-10
Re: Common library and services for UPnP AV / DLNA control
« Reply #17 on: October 09, 2013, 10:03:41 am »
Regarding UPnP AV standards, we can find all services here: http://upnp.org/index.php/sdcps-and-certification/standards/sdcps/

I see there are 4 versions of MediaServer and MediaRenderer.
Are they all used today ? Or is almost everybody using MediaServer:1 and MediaRenderer:1 ?

Offline macfly92

  • Full Member
  • ***
  • Posts: 132
  • Karma: +1/-0
Re: Common library and services for UPnP AV / DLNA control
« Reply #18 on: October 09, 2013, 10:58:20 am »
Just for Info if it can help, My Sony Amp Media Renderer and my Raspberry Media Renderer both use MediaRenderer:1 service

I just realize I reply to your other thread about XBMC (http://forum.micasaverde.com/index.php/topic,16879.msg130899.html#msg130899) while my post probably must be here ....
« Last Edit: October 09, 2013, 11:00:32 am by macfly92 »

Offline lolodomo

  • Moderator
  • Master Member
  • *****
  • Posts: 3484
  • Karma: +74/-10
Re: Common library and services for UPnP AV / DLNA control
« Reply #19 on: October 10, 2013, 07:36:06 am »
My initial idea to control XBMC through UPnP has quickly evolved in a more general plugin that I could name "DLNA Media Renderer Controller". It should work with any DLNA Digital Media Renderer.
I will add some settings presets to help final users selecting the settings for certain usual DMR like XBMC, Windows Media Connect, BubbleUPnP, ...
If you can provide the URL of the XML description file of your specific DMR, I can add a preset for it. And the description file itself would be appreciated too.

Offline macfly92

  • Full Member
  • ***
  • Posts: 132
  • Karma: +1/-0
Re: Common library and services for UPnP AV / DLNA control
« Reply #20 on: October 10, 2013, 01:43:50 pm »
Your initial idea was cool, but your evolv is great  ;D

Ok if I don't missunderstood your request, this is the description of my renderers and a link for the service description xmls grab with Device Spy:

First is GMrender Resurect. This is a Linux shell apps that listen uPnp Request and play Media. (Actually installed on a Raspberry Pi).

Device Description URL : http://192.168.0.123:49494/description.xml
description.xml

Base URL   http://192.168.0.123:49494/
Device icon   Present, 128x128
Device URN   urn:schemas-upnp-org:device:MediaRenderer:1
Embedded devices   0
Expiration timeout   100
Friendly name   SalleDeBain
Has presentation   True
Manufacturer URL   http://github.com/hzeller/gmrender-resurrect
Model description   gmediarender 0.0.7-git
Model name   gmediarender
Model number   2013-09-07_9bcc832
Model URL   http://github.com/hzeller/gmrender-resurrect
Presentation URL   http://192.168.0.123:49494/
Product code   
Proprietary type   
Remote endpoint   192.168.0.123:49494
Serial number   
Services   3
Standard type   
Unique device name   GMediaRender-1_0-000-000-002
Version   1.0

Link to services URL, and xml link :

Methods   12
Parent presentation URL   http://192.168.0.123:49494/
Parent UDN   urn:schemas-upnp-org:device:MediaRenderer:1
Service ID   urn:upnp-org:serviceId:AVTransport
Service URL   http://192.168.0.123:49494/upnp/rendertransportSCPD.xml
State variables   30
Version   1.0
rendertransportSCPD.xml

Methods   21
Parent presentation URL   http://192.168.0.123:49494/
Parent UDN   urn:schemas-upnp-org:device:MediaRenderer:1
Service ID   urn:upnp-org:serviceId:RenderingControl
Service URL   http://192.168.0.123:49494/upnp/rendercontrolSCPD.xml
State variables   21
Version   1.0
rendercontrolSCPD.xml

Methods   4
Parent presentation URL   http://192.168.0.123:49494/
Parent UDN   urn:schemas-upnp-org:device:MediaRenderer:1
Service ID   urn:upnp-org:serviceId:ConnectionManager
Service URL   http://192.168.0.123:49494/upnp/renderconnmgrSCPD.xml
State variables   10
Version   1.0
renderconnmgrSCPD.xml


Second is a SONY Blu-ray HomeTheatre :

Device Description URL : http://192.168.0.90:52323/dmr.xml
dmr.xml

Base URL   http://192.168.0.90:52323/
Device icon   Present, 48x48
Device URN   urn:schemas-upnp-org:device:MediaRenderer:1
Embedded devices   0
Expiration timeout   1800
Friendly name   BLU-RAY HOME THEATRE SYSTEM
Has presentation   True
Interface to host   192.168.0.10
Manufacturer   Sony Corporation
Manufacturer URL   http://www.sony.net/
Model description   
Model name   BDV
Model number   
Presentation URL   http://192.168.0.90:52323/
Product code   
Proprietary type   
Remote endpoint   192.168.0.90:52323
Serial number   
Services   5
Standard type   
Unique device name   00000000-0000-1010-8000-544249199c7c
Version   1.0

Link to services URL, and xml link :

Methods   15
Parent presentation URL   http://192.168.0.90:52323/
Parent UDN   urn:schemas-upnp-org:device:MediaRenderer:1
Service ID   urn:upnp-org:serviceId:AVTransport
Service URL   http://192.168.0.90:52323/AVTransportSCPD.xml
State variables   33
Version   1.0
AVTransportSCPD.xml

Methods   6
Parent presentation URL   http://192.168.0.90:52323/
Parent UDN   urn:schemas-upnp-org:device:MediaRenderer:1
Service ID   urn:upnp-org:serviceId:RenderingControl
Service URL   http://192.168.0.90:52323/RenderingControlBdvSCPD.xml
State variables   7
Version   1.0
RenderingControlBdvSCPD.xml

Methods   3
Parent presentation URL   http://192.168.0.90:52323/
Parent UDN   urn:schemas-upnp-org:device:MediaRenderer:1
Service ID   urn:upnp-org:serviceId:ConnectionManager
Service URL   http://192.168.0.90:52323/ConnectionManagerSCPD.xml
State variables   10
Version   1.0
ConnectionManagerSCPD.xml


If I can provide any other help or beta test, please let me know !

Thanks.
« Last Edit: October 10, 2013, 02:04:49 pm by macfly92 »

Offline lolodomo

  • Moderator
  • Master Member
  • *****
  • Posts: 3484
  • Karma: +74/-10
Re: Common library and services for UPnP AV / DLNA control
« Reply #21 on: October 10, 2013, 01:55:01 pm »
Your initial idea was cool, but your evolv is great  ;D

Ok if I don't missunderstood your request, this is the description of my renderers and a link for the service description xmls grab with Device Spy:

In fact, what I need is the URL of the device description file. It is the URL opened when you request menu "Get Device XML" in Device Spy.

PS: it is something normally provided by the UPnP discovry process...

Offline macfly92

  • Full Member
  • ***
  • Posts: 132
  • Karma: +1/-0
Re: Common library and services for UPnP AV / DLNA control
« Reply #22 on: October 10, 2013, 02:06:21 pm »
Oww Ok, I edited my first post with the Device XML

Merci !
« Last Edit: October 10, 2013, 02:55:16 pm by macfly92 »

Offline lolodomo

  • Moderator
  • Master Member
  • *****
  • Posts: 3484
  • Karma: +74/-10
Re: Common library and services for UPnP AV / DLNA control
« Reply #23 on: October 13, 2013, 07:45:24 am »
I tested with Windows Media Player and BubbleUPnP renderers this morning and I encountered problems.

I switch to technical discussion. Help is welcome.

Event subscription is working for Windows Media Player and BubbleUPnP.

Problem with Windows Media Player, variables AVTransportURI, AVTransportURIMetaData and CurrentTrackURI are set to "" ! Is it compliant with the UPnP AV standard ?

Problem with BubbleUPnP, value for AVTransportURIMetaData has some characters replaced by code, for example I got &#60; rather than < and &#62; rather than >. I can fix that problem.
« Last Edit: October 13, 2013, 08:13:45 am by lolodomo »

Offline lolodomo

  • Moderator
  • Master Member
  • *****
  • Posts: 3484
  • Karma: +74/-10
Re: Common library and services for UPnP AV / DLNA control
« Reply #24 on: October 13, 2013, 08:12:36 am »
With Windows Media Player and BubbleUPnP, the UPnP request systematically failed with the HTTP code 415. This error code means I am using a bad format ! Two possibilities:
1 - the XML sent is not standard. The XML model is defined by the variable UPNP_REQUEST in L_Sonos1.lua. I see nothing choking.
2 - the content type is not right. In L_Sonos1.lua, it is set by default to "application/x-www-form-urlencoded". I tried with "application/xml" and "text/xml" with no success. What value has to be used ?

SOLVED.
I got my answer checking futzle's code in WeMo plugin. She uses text/xml; charset="utf-8" as content type and bingo it works with Windows Media Player and XBMC. I will check with Sonos and BubbleUPnP too and if it works, I will set this content type as new default in L_Sonos1.lua.
Edit:  and it is what is defined by the standard.
« Last Edit: October 13, 2013, 01:48:27 pm by lolodomo »

Offline garrettwp

  • Master Member
  • *******
  • Posts: 6371
  • Karma: +227/-128
  • Vera 3, Lite, ISY994
Re: Common library and services for UPnP AV / DLNA control
« Reply #25 on: October 13, 2013, 08:27:05 am »
Glad to see you are making progress.

- Garrett


Offline lolodomo

  • Moderator
  • Master Member
  • *****
  • Posts: 3484
  • Karma: +74/-10
Re: Common library and services for UPnP AV / DLNA control
« Reply #26 on: October 13, 2013, 09:04:34 am »
New specific problem with BubbleUPnP: UPnP request failed with code 401 and this description: No action by that name at this service. Missing SOAP action header.
I got the same error whatever the action.
Of course, the "Pause" action exists and I can run it through Device Spy.

Here is what is sent:

Code: [Select]
UPnP_request: url=[http://192.168.1.15:42316/dev/b4e54b11-54bc-7162-ffff-ffffdee3b0aa/svc/upnp-org/AVTransport/action], body=[<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<u:Pause xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID></u:Pause>
</s:Body>
</s:Envelope>] <0x302de680>

Any idea what could be wrong ?

Offline lolodomo

  • Moderator
  • Master Member
  • *****
  • Posts: 3484
  • Karma: +74/-10
Re: Common library and services for UPnP AV / DLNA control
« Reply #27 on: October 13, 2013, 09:20:40 am »
Other problem with Windows Media Player, I cannot request UPnP for RenderingControl. I got an error code 402 and the following description: Invalid Args

Here is my request:
Code: [Select]
50      10/13/13 15:16:54.936   luup_log:446: XBMC: UPnP_request: url=[http://192.168.1.16:2869/upnphost/udhisapi.dll?control=uuid:1cbdde94-4e1f-442c-9613-298d0aec799f+urn:upnp-org:serviceId:RenderingControl], body=[<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<u:SetMute xmlns:u="urn:schemas-upnp-org:service:RenderingControl:1"><InstanceID>0</InstanceID><DesiredMute>1</DesiredMute><Channel>Master</Channel></u:SetMute>
</s:Body>
</s:Envelope>] <0x2f71a680>
I got the same error with SetVolume.

I see nothing wrong.

Is the order of arguments important ? I mean, should I put in my request Channel before DesiredMute ?
What says the standard about that ?
« Last Edit: October 13, 2013, 09:23:31 am by lolodomo »

Offline macfly92

  • Full Member
  • ***
  • Posts: 132
  • Karma: +1/-0
Re: Common library and services for UPnP AV / DLNA control
« Reply #28 on: October 13, 2013, 10:46:47 am »
New specific problem with BubbleUPnP: UPnP request failed with code 401 and this description: No action by that name at this service. Missing SOAP action header.
I got the same error whatever the action.
Of course, the "Pause" action exists and I can run it through Device Spy.

Here is what is sent:

Code: [Select]
UPnP_request: url=[http://192.168.1.15:42316/dev/b4e54b11-54bc-7162-ffff-ffffdee3b0aa/svc/upnp-org/AVTransport/action], body=[<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<u:Pause xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID></u:Pause>
</s:Body>
</s:Envelope>] <0x302de680>

Any idea what could be wrong ?

The only difference I can see between your exemple and when I invoked this action with upnp spy is under the envelope opening tag : In Spy, s:encodingStyle is before xmlns:s ... I don't know if it change something or not ... But maybe it is the same problem than your second question : Is the order of arguments count ?


POST /dev/88dc63c0-34c9-8eb5-ffff-ffffb33991ec/svc/upnp-org/AVTransport/action HTTP/1.1
HOST: 192.168.xx.xx:47800
SOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#Pause"
CONTENT-TYPE: text/xml ; charset="utf-8"
Content-Length: 331

<?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:Pause xmlns:u="urn:schemas-upnp-org:service:AVTransport:1">
         <InstanceID>0</InstanceID>
      </u:Pause>
   </s:Body>
</s:Envelope>
« Last Edit: October 13, 2013, 10:49:21 am by macfly92 »

Offline lolodomo

  • Moderator
  • Master Member
  • *****
  • Posts: 3484
  • Karma: +74/-10
Re: Common library and services for UPnP AV / DLNA control
« Reply #29 on: October 13, 2013, 10:57:01 am »
How do you see the SOAP message with Device Spy ?

Yes the order is required by the standard and this is a major problem with the vera already discovered by others in the past. The way we manage things cannot guarantee the good order. I have to do it differently.
While I was reading the spec, I got confirmation that only in parameters have to be passed. I will fix that in Sonos plugin.

I will try to inverse the two tags as you propose.
« Last Edit: October 13, 2013, 11:00:04 am by lolodomo »