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

Offline futzle

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3250
  • Karma: +189/-9
DLNA Media Controller plugin - Common library for UPnP AV
« Reply #225 on: November 17, 2013, 06:56:05 pm »
lolodomo,

This is one of those things where you will have to just play with it till it works. In this specific instance, I dispute that "%25e8" is valid input, and that you shouldn't be given a string like that in the first place.

The problem may be upstream from you. One source of encoding problems is that the Vera UI web page doesn't state what encoding it is in, leaving the decision up to the browser. If the browser decides that Vera web pages are Latin-1 then the user can introduce non-UTF-8 sequences into Vera's LuaUPnP data structures, where your plugin inherits them.

Naturally, I pointed out this problem to MCV years ago, but they used the classic Unix non-defence of "8-bit clean" and decided it wasn't their problem. So now it's your problem. Edit: perhaps I was hasty; this appears to have been fixed.

Working around bad input is really hard. Encoding-detection is actually an AI problem. You probably can't make a workaround that works for everyone.
« Last Edit: November 17, 2013, 10:03:16 pm by futzle »

Offline a-lurker

  • Hero Member
  • *****
  • Posts: 778
  • Karma: +45/-8
Re: DLNA Media Controller plugin - Common library for UPnP AV
« Reply #226 on: November 17, 2013, 08:08:50 pm »
Changing the Javascript encoding from the escape() to encodeuri() will produce the correct encoding when using the user interface:  sc%C3%A8ne

http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_escape
http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_encodeuri

http://meyerweb.com/eric/tools/dencoder/

Any XML you create must be in unicode (generally as UTF8). If not, it will cause a XML parse error at the server or renderer.

It may be useful to write out any URIs to the log.

« Last Edit: November 17, 2013, 08:49:08 pm by a-lurker »

Offline lolodomo

  • Moderator
  • Master Member
  • *****
  • Posts: 3484
  • Karma: +74/-10
Re: DLNA Media Controller plugin - Common library for UPnP AV
« Reply #227 on: November 18, 2013, 02:35:29 am »
I don't think Javascript is involved in my current problem.

I got the URL from a "browse" UPnP request (lua code). The URL is extracted from the returned URI meta data ("res" tag).

PS: The only link I see with Javascript is that the object to browse is coming from Javascript ... with an escape().

Offline lolodomo

  • Moderator
  • Master Member
  • *****
  • Posts: 3484
  • Karma: +74/-10
Re: DLNA Media Controller plugin - Common library for UPnP AV
« Reply #228 on: November 18, 2013, 04:41:18 am »
PS: The only link I see with Javascript is that the object to browse is coming from Javascript ... with an escape().

But I will try with encodeURI when passing the object ID to browse in case the server is clever and see that the id is ISO-8859-1 coded ans then returns data using the same coing.

But with your example below, it looks like & is not escaped by encode URI. As I explained it is a problem when calling a Vera action.
« Last Edit: November 18, 2013, 08:01:06 am by lolodomo »

Offline lolodomo

  • Moderator
  • Master Member
  • *****
  • Posts: 3484
  • Karma: +74/-10
Re: DLNA Media Controller plugin - Common library for UPnP AV
« Reply #229 on: November 18, 2013, 04:44:26 am »
Any XML you create must be in unicode (generally as UTF8). If not, it will cause a XML parse error at the server or renderer.

It could explain the UPnP event proxy crash we noticed ?

Offline futzle

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3250
  • Karma: +189/-9
Re: DLNA Media Controller plugin - Common library for UPnP AV
« Reply #230 on: November 18, 2013, 05:36:05 am »
You are conflating XML escaping (&) with URI encoding (%). There is almost no overlap in their uses.

Offline lolodomo

  • Moderator
  • Master Member
  • *****
  • Posts: 3484
  • Karma: +74/-10
Re: DLNA Media Controller plugin - Common library for UPnP AV
« Reply #231 on: November 18, 2013, 08:00:19 am »
You are conflating XML escaping (&) with URI encoding (%). There is almost no overlap in their uses.

No.

What I say is just that I cannot call a Vera action from JavaScript UI with a parameter containing a "&", at least with the function I am using. Maybe my function is wrong, I don't know.
That is the reason why I originally escaped URL in Javascript when I need to call a Vera action with this value as parameter.

Offline lolodomo

  • Moderator
  • Master Member
  • *****
  • Posts: 3484
  • Karma: +74/-10
Re: DLNA Media Controller plugin - Common library for UPnP AV
« Reply #232 on: November 18, 2013, 08:26:13 am »
To call a Vera action from Javascript, I am using Ajax.Request with a GET methiod and passing arguments (argument can be an URI).
What I have noticed is that without an excape of the "&", a parameter containing a "&" is truncated at this character.
Should I use rather a POST method to pass a URI as parameter ?
Or should I keep a kind of escaping for this specific character ?
« Last Edit: November 18, 2013, 08:44:32 am by lolodomo »

Offline a-lurker

  • Hero Member
  • *****
  • Posts: 778
  • Karma: +45/-8
Re: DLNA Media Controller plugin - Common library for UPnP AV
« Reply #233 on: November 18, 2013, 04:54:50 pm »
If the URL is being used in an AJAX call - then all you need to do is encode the value of each individual parameter being used. eg

Code: [Select]
var ajaxURI = 'http://www.test.com/vera?parm1='+encodeURIComponent('?ab&d?')+'&parm2='+encodeURIComponent('#?&d');
Gives:

http://www.test.com/vera?parm1=%C3%A9ab%26d%C3%A9&parm2=%23%3F%26d

Note that I put two French e with acute - they show as ? in the code box above but have been correctly encoded as %C3%A9.


The truncation of the last parameter you mentioned, likely indicates that the ampersand is being double encoded.

You can test the results easy enough by calling them from your browser. POST gives you more encoding options but the GET can be made to work.

Currently I'm not clear where this URL is coming from. Is it entered by the user or coming off a web page or are you constructing it in code? The source of the URL may have already altered it in some way and may need to be massaged.

As Futzle says, the xml is a separate issue, which also needs to be encoded correctly.
« Last Edit: November 18, 2013, 05:09:35 pm by a-lurker »

Offline a-lurker

  • Hero Member
  • *****
  • Posts: 778
  • Karma: +45/-8
Re: DLNA Media Controller plugin - Common library for UPnP AV
« Reply #234 on: November 18, 2013, 05:18:06 pm »
Quote
you cannot use Sonos as a server because Sonos provides URI that can be played only by Sonos.

Thanks for letting me know that: x-file-cifs:,  x-rincon-mp3radio:,  last.fm-radio:  etc are all SONOS specific. I thought they where more general and part of te uPNP spec. That explains why I couldn't find them there.

I have found that you cannot issue a Stop() if NO_MEDIA_PRESENT is true, according to the state diagram in the spec. What commands and or info needs to be executed/supplied to move from the NO_MEDIA_PRESENT state to the STOPPED state?

EDIT: looks like you have to issue a SetAVTransportURI

« Last Edit: November 19, 2013, 12:59:39 am by a-lurker »

Offline a-lurker

  • Hero Member
  • *****
  • Posts: 778
  • Karma: +45/-8
Re: DLNA Media Controller plugin - Common library for UPnP AV
« Reply #235 on: November 19, 2013, 01:31:50 am »
lolodomo

Have been messing around with the Yamaha and Device Spy.

First of all if the AVR is not set to the SERVER input (as opposed to say AV1, AV2,HDMI 1, HDMI 2, etc) any commands return "501 Action Failed ". So that's fair enough.

Once the SERVER input is selected the AVR state machine is in the NO_MEDIA_PRESENT. That's OK as well. So it looks like you need to do a SetAVTransportURI command at the very start. When I do that, I get a "714 Illegal MIME-type".

If I do a GetProtocolInfo on the AVR - I get:
Code: [Select]
http-get:*:audio/L16;rate=44100;channels=1:DLNA.ORG_PN=LPCM,
http-get:*:audio/L16;rate=44100;channels=2:DLNA.ORG_PN=LPCM,
http-get:*:audio/L16;rate=48000;channels=1:DLNA.ORG_PN=LPCM,
http-get:*:audio/L16;rate=48000;channels=2:DLNA.ORG_PN=LPCM,
http-get:*:audio/mpeg:DLNA.ORG_PN=MP3,
http-get:*:audio/x-ms-wma:DLNA.ORG_PN=WMABASE,
http-get:*:audio/x-ms-wma:DLNA.ORG_PN=WMAFULL,
http-wavetunes:*:audio/x-ms-wma:*,
http-get:*:audio/vnd.dlna.adts:DLNA.ORG_PN=AAC_ADTS,
http-get:*:image/jpeg:*

You have a function resTable = upnp.getRes(xml) that's called in PlayItem. This is the only thing I can find that seems to mentions protocols. And I can't Play an Item because the state machine is still in the NO_MEDIA_PRESENT state.

I'm just learning - but it looks like when I set SetAVTransportURI I need to also set the CurrentURIMetaData?? I think if this is blank you use a default - can I alter the default to something that may work for me? Any ideas on how I can set up SetAVTransportURI to get to the STOPPED state? I can alter the code easy enough, if you have any ideas.

Maybe the Connection manager is needed to set source and sink allowed mime types.

I saw your code scanned the protocols and I recorded this information but it doesn't mention any protocol.

Code: [Select]
<DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:dlna="urn:schemas-dlna-org:metadata-1-0/" xmlns:arib="urn:schemas-arib-or-jp:elements-1-0/" xmlns:dtcp="urn:schemas-dtcp-com:metadata-1-0/" xmlns:pv="http://www.pv.com/pvns/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/">
<item id="0$1$11$26588R7890954" parentID="0$1$11$26588" restricted="1">
<dc:title>Greatest hits</dc:title>
<upnp:class>object.item.audioItem.musicTrack</upnp:class>
</item>
</DIDL-Lite> <0x30ad9680>

Hope some of this makes sense to you - It doesn't make a lot of sense to me yet!



Offline lolodomo

  • Moderator
  • Master Member
  • *****
  • Posts: 3484
  • Karma: +74/-10
Re: DLNA Media Controller plugin - Common library for UPnP AV
« Reply #236 on: November 19, 2013, 06:48:18 am »
Currently I'm not clear where this URL is coming from. Is it entered by the user or coming off a web page or are you constructing it in code? The source of the URL may have already altered it in some way and may need to be massaged.

In lua,  I send a browse UPnP request to the server to get all the children. The result (XML) is stored in a variable. This variable is read by the Javascript UI. When you select an item in the UI and push the button, the object ID (coming from the XML) is passed as argument to the action through an AJAX request. The action is run, gets the object ID in parameter and asks for object metadata to the server through a new browse UPnP request. The URL is finally extracted from the value returned by the browse request.

Offline lolodomo

  • Moderator
  • Master Member
  • *****
  • Posts: 3484
  • Karma: +74/-10
Re: DLNA Media Controller plugin - Common library for UPnP AV
« Reply #237 on: November 19, 2013, 06:51:31 am »
Quote
you cannot use Sonos as a server because Sonos provides URI that can be played only by Sonos.

Thanks for letting me know that: x-file-cifs:,  x-rincon-mp3radio:,  last.fm-radio:  etc are all SONOS specific. I thought they where more general and part of te uPNP spec. That explains why I couldn't find them there.

"x-" is for vendor specific protocol, meaning non standard protocol.

Quote
I have found that you cannot issue a Stop() if NO_MEDIA_PRESENT is true, according to the state diagram in the spec. What commands and or info needs to be executed/supplied to move from the NO_MEDIA_PRESENT state to the STOPPED state?

EDIT: looks like you have to issue a SetAVTransportURI

Yes, you have to load/define the media to play, meaning you have to call SetAVTransportURI.

Offline lolodomo

  • Moderator
  • Master Member
  • *****
  • Posts: 3484
  • Karma: +74/-10
Re: DLNA Media Controller plugin - Common library for UPnP AV
« Reply #238 on: November 19, 2013, 07:09:46 am »
First of all if the AVR is not set to the SERVER input (as opposed to say AV1, AV2,HDMI 1, HDMI 2, etc) any commands return "501 Action Failed ". So that's fair enough.

OK

Quote
If I do a GetProtocolInfo on the AVR - I get:
Code: [Select]
http-get:*:audio/L16;rate=44100;channels=1:DLNA.ORG_PN=LPCM,
http-get:*:audio/L16;rate=44100;channels=2:DLNA.ORG_PN=LPCM,
http-get:*:audio/L16;rate=48000;channels=1:DLNA.ORG_PN=LPCM,
http-get:*:audio/L16;rate=48000;channels=2:DLNA.ORG_PN=LPCM,
http-get:*:audio/mpeg:DLNA.ORG_PN=MP3,
http-get:*:audio/x-ms-wma:DLNA.ORG_PN=WMABASE,
http-get:*:audio/x-ms-wma:DLNA.ORG_PN=WMAFULL,
http-wavetunes:*:audio/x-ms-wma:*,
http-get:*:audio/vnd.dlna.adts:DLNA.ORG_PN=AAC_ADTS,
http-get:*:image/jpeg:*

In theory, my feeling (knowledge at this point) is that this one should be ok for what we want:
http-get:*:audio/mpeg:DLNA.ORG_PN=MP3,

But macfly has a similar issue with its Sony BR player.

Quote
I'm just learning - but it looks like when I set SetAVTransportURI I need to also set the CurrentURIMetaData?? I think if this is blank you use a default - can I alter the default to something that may work for me? Any ideas on how I can set up SetAVTransportURI to get to the STOPPED state? I can alter the code easy enough, if you have any ideas.

Providing metada is not mandatory, I think.
As you previously said, you have to set a media to switch in the STOP state.

Quote
Maybe the Connection manager is needed to set source and sink allowed mime types.

Connection manager will mainly allow checking that the source is compatible with the renderer.
Getting a new AVTRansport ID could be important for certain DMR, I am not sure about that. But using Connection manager is the right way defined in the spec.

Quote
I saw your code scanned the protocols and I recorded this information but it doesn't mention any protocol.

Code: [Select]
<DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:dlna="urn:schemas-dlna-org:metadata-1-0/" xmlns:arib="urn:schemas-arib-or-jp:elements-1-0/" xmlns:dtcp="urn:schemas-dtcp-com:metadata-1-0/" xmlns:pv="http://www.pv.com/pvns/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/">
<item id="0$1$11$26588R7890954" parentID="0$1$11$26588" restricted="1">
<dc:title>Greatest hits</dc:title>
<upnp:class>object.item.audioItem.musicTrack</upnp:class>
</item>
</DIDL-Lite> <0x30ad9680>

Interesting.
I have to add a control in case there is no res tag provided. I should avoid setting and playing a media in this case, because there is nothing to set !
The SetAVTransportURI is certainly called with "" as URI.

But the question is why no res is provided ?
Could you check whether the value of the variable browseResult, updated when you browse to the container containing your item, contains or not res tags ? You should see the value change of the variable in the logs.

Offline Da_JoJo

  • Hero Member
  • *****
  • Posts: 1380
  • Karma: +16/-78
  • If something aint work, we can allways try n make
    • House Of Yu
Re: DLNA Media Controller plugin - Common library for UPnP AV
« Reply #239 on: November 19, 2013, 07:29:58 am »
the sonos files are required for me to be able to use the volume up/down so i keep this as this is a nice addition. it is strange however that my samsung DMR is not found anymore after putting the sonos files in. i dont know how to remove the sonos files from my vera so i can't test it right now if DMR discovery would work without these files. also not sure if samsung DMR should be found as i have set it allready as the default.
inscene:1 would be the thing that makes the scene usage work. shouldn't be to hard to make it work.
like futzle mentioned i meant indeed the "putting non-ASCII characters in filenames (such as e-with-acute-accent U+E9) causes a crash"
i dont know if it would work but perhaps you can set the codepage in java so it forces it to use one particular codepage, preferably utf-8 as this is most common and regionless. however i notice browsers do not often like utf-8 as also being seen with this forum here that puts "?" instead of a e-accent. perhaps this is also a part of the problem, so maybe its better to use the unicode or indian coding. i cannot say much about this as i have no idea which one is being used by vera and dlna. my samsung DMR can play allmost anything i throw at it and i have been testing again and recorded the error message on tv so i could read it as it went to fast to normally read it. i played back the recording step by step and it comes down to the samsung not being able to find the filename parsed to it. so this brings us to the topic of uri encoding again. gotta find out where it goes wrong with the url encoding and why. this seems to be not so simple as it looks :-/
i can try with a uri with just a picture in it and name this pic.jpg when im home. or maybe someone here can try this.
« Last Edit: November 19, 2013, 07:38:11 am by Da_JoJo »
Vera lite (1.5.622), 2x an-158/2, dead usb pl2302 rs-232, 2x greenwave 6 port, 4x Fibaro FGD211 v1.6, FGBS001, few FGS - 221, etc. AuthomationHD 3 for android :-)
Dutch & German translator http://wiki.micasaverde.com/index.php/Special:AllPages http://support.micasaverde.com http://domotica-shop.nl