Skip to content

Commit

Permalink
Merge pull request xbmc#4764 from Montellese/upnp_improvements
Browse files Browse the repository at this point in the history
upnp: several additions and improvements
  • Loading branch information
Montellese committed Jun 2, 2014
2 parents 5e5325b + fadc4da commit b5e06ca
Show file tree
Hide file tree
Showing 17 changed files with 2,003 additions and 25 deletions.
20 changes: 18 additions & 2 deletions lib/libUPnP/Platinum/Source/Devices/MediaServer/PltDidl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@ NPT_SET_LOCAL_LOGGER("platinum.media.server.didl")
const char* didl_header = "<DIDL-Lite xmlns=\"urn:schemas-upnp-org:metadata-1-0/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:dlna=\"urn:schemas-dlna-org:metadata-1-0/\""
" xmlns:xbmc=\"urn:schemas-xbmc-org:metadata-1-0/\">";
const char* didl_footer = "</DIDL-Lite>";
const char* didl_namespace_dc = "http://purl.org/dc/elements/1.1/";
const char* didl_namespace_upnp = "urn:schemas-upnp-org:metadata-1-0/upnp/";
const char* didl_namespace_dlna = "urn:schemas-dlna-org:metadata-1-0/";
const char* didl_namespace_xbmc = "urn:schemas-xbmc-org:metadata-1-0/";

/*----------------------------------------------------------------------
| PLT_Didl::ConvertFilterToMask
Expand Down Expand Up @@ -135,6 +137,8 @@ PLT_Didl::ConvertFilterToMask(const NPT_String& filter)
mask |= PLT_FILTER_MASK_EPISODE;
} else if (NPT_String::CompareN(s+i, PLT_FILTER_FIELD_RATING, len, true) == 0) {
mask |= PLT_FILTER_MASK_RATING;
} else if (NPT_String::CompareN(s+i, PLT_FILTER_FIELD_PUBLISHER, len, true) == 0) {
mask |= PLT_FILTER_MASK_PUBLISHER;
} else if (NPT_String::CompareN(s+i, PLT_FILTER_FIELD_RES, len, true) == 0) {
mask |= PLT_FILTER_MASK_RES;
} else if (NPT_String::CompareN(s+i, PLT_FILTER_FIELD_RES_DURATION, len, true) == 0 ||
Expand All @@ -154,7 +158,19 @@ PLT_Didl::ConvertFilterToMask(const NPT_String& filter)
mask |= PLT_FILTER_MASK_RES | PLT_FILTER_MASK_RES_NRAUDIOCHANNELS;
} else if (NPT_String::CompareN(s+i, PLT_FILTER_FIELD_RES_SAMPLEFREQUENCY, len, true) == 0) {
mask |= PLT_FILTER_MASK_RES | PLT_FILTER_MASK_RES_SAMPLEFREQUENCY;
}
} else if (NPT_String::CompareN(s+i, PLT_FILTER_FIELD_EPISODE_COUNT, len, true) == 0) {
mask |= PLT_FILTER_MASK_EPISODE_COUNT;
} else if (NPT_String::CompareN(s+i, PLT_FILTER_FIELD_EPISODE_SEASON, len, true) == 0) {
mask |= PLT_FILTER_MASK_EPISODE_SEASON;
} else if (NPT_String::CompareN(s+i, PLT_FILTER_FIELD_XBMC_DATEADDED, len, true) == 0) {
mask |= PLT_FILTER_MASK_XBMC_DATEADDED;
} else if (NPT_String::CompareN(s+i, PLT_FILTER_FIELD_XBMC_RATING, len, true) == 0) {
mask |= PLT_FILTER_MASK_XBMC_RATING;
} else if (NPT_String::CompareN(s+i, PLT_FILTER_FIELD_XBMC_VOTES, len, true) == 0) {
mask |= PLT_FILTER_MASK_XBMC_VOTES;
} else if (NPT_String::CompareN(s+i, PLT_FILTER_FIELD_XBMC_ARTWORK, len, true) == 0) {
mask |= PLT_FILTER_MASK_XBMC_ARTWORK;
}

if (next_comma < 0) {
return mask;
Expand Down
20 changes: 20 additions & 0 deletions lib/libUPnP/Platinum/Source/Devices/MediaServer/PltDidl.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@
#define PLT_FILTER_MASK_LASTPLAYBACK NPT_UINT64_C(0x0000000200000000)
#define PLT_FILTER_MASK_PLAYCOUNT NPT_UINT64_C(0x0000000400000000)

#define PLT_FILTER_MASK_PUBLISHER NPT_UINT64_C(0x0000000800000000)

#define PLT_FILTER_MASK_EPISODE_COUNT NPT_UINT64_C(0x0000001000000000)
#define PLT_FILTER_MASK_EPISODE_SEASON NPT_UINT64_C(0x0000002000000000)

#define PLT_FILTER_MASK_XBMC_DATEADDED NPT_UINT64_C(0x0000100000000000)
#define PLT_FILTER_MASK_XBMC_RATING NPT_UINT64_C(0x0000200000000000)
#define PLT_FILTER_MASK_XBMC_VOTES NPT_UINT64_C(0x0000300000000000)
#define PLT_FILTER_MASK_XBMC_ARTWORK NPT_UINT64_C(0x0000400000000000)

#define PLT_FILTER_FIELD_TITLE "dc:title"
#define PLT_FILTER_FIELD_CREATOR "dc:creator"
#define PLT_FILTER_FIELD_DATE "dc:date"
Expand Down Expand Up @@ -118,6 +128,7 @@
#define PLT_FILTER_FIELD_CONTAINER_CHILDCOUNT "container@childCount"
#define PLT_FILTER_FIELD_CONTAINER_SEARCHABLE "container@searchable"
#define PLT_FILTER_FIELD_REFID "@refID"
#define PLT_FILTER_FIELD_PUBLISHER "dc:publisher"

#define PLT_FILTER_FIELD_RES "res"
#define PLT_FILTER_FIELD_RES_DURATION "res@duration"
Expand All @@ -130,11 +141,20 @@
#define PLT_FILTER_FIELD_RES_NRAUDIOCHANNELS "res@nrAudioChannels"
#define PLT_FILTER_FIELD_RES_SAMPLEFREQUENCY "res@sampleFrequency"

#define PLT_FILTER_FIELD_EPISODE_COUNT "upnp:episodeCount"
#define PLT_FILTER_FIELD_EPISODE_SEASON "upnp:episodeSeason"

#define PLT_FILTER_FIELD_XBMC_DATEADDED "xbmc:dateadded"
#define PLT_FILTER_FIELD_XBMC_RATING "xbmc:rating"
#define PLT_FILTER_FIELD_XBMC_VOTES "xbmc:votes"
#define PLT_FILTER_FIELD_XBMC_ARTWORK "xbmc:artwork"

extern const char* didl_header;
extern const char* didl_footer;
extern const char* didl_namespace_dc;
extern const char* didl_namespace_upnp;
extern const char* didl_namespace_dlna;
extern const char* didl_namespace_xbmc;

/*----------------------------------------------------------------------
| PLT_Didl
Expand Down
116 changes: 116 additions & 0 deletions lib/libUPnP/Platinum/Source/Devices/MediaServer/PltMediaBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,60 @@ PLT_MediaBrowser::Browse(PLT_DeviceDataReference& device,
return NPT_SUCCESS;
}

/*----------------------------------------------------------------------
| PLT_MediaBrowser::GetSearchCapabilities
+---------------------------------------------------------------------*/
NPT_Result
PLT_MediaBrowser::GetSearchCapabilities(PLT_DeviceDataReference& device,
void* userdata)
{
// verify device still in our list
PLT_DeviceDataReference device_data;
NPT_CHECK_WARNING(FindServer(device->GetUUID(), device_data));

// create action
PLT_ActionReference action;
NPT_CHECK_SEVERE(m_CtrlPoint->CreateAction(
device,
"urn:schemas-upnp-org:service:ContentDirectory:1",
"GetSearchCapabilities",
action));

// invoke the action
if (NPT_FAILED(m_CtrlPoint->InvokeAction(action, userdata))) {
return NPT_ERROR_INVALID_PARAMETERS;
}

return NPT_SUCCESS;
}

/*----------------------------------------------------------------------
| PLT_MediaBrowser::GetSortCapabilities
+---------------------------------------------------------------------*/
NPT_Result
PLT_MediaBrowser::GetSortCapabilities(PLT_DeviceDataReference& device,
void* userdata)
{
// verify device still in our list
PLT_DeviceDataReference device_data;
NPT_CHECK_WARNING(FindServer(device->GetUUID(), device_data));

// create action
PLT_ActionReference action;
NPT_CHECK_SEVERE(m_CtrlPoint->CreateAction(
device,
"urn:schemas-upnp-org:service:ContentDirectory:1",
"GetSortCapabilities",
action));

// invoke the action
if (NPT_FAILED(m_CtrlPoint->InvokeAction(action, userdata))) {
return NPT_ERROR_INVALID_PARAMETERS;
}

return NPT_SUCCESS;
}

/*----------------------------------------------------------------------
| PLT_MediaBrowser::OnActionResponse
+---------------------------------------------------------------------*/
Expand All @@ -322,6 +376,10 @@ PLT_MediaBrowser::OnActionResponse(NPT_Result res,
return OnBrowseResponse(res, device, action, userdata);
} else if (actionName.Compare("Search", true) == 0) {
return OnSearchResponse(res, device, action, userdata);
} else if (actionName.Compare("GetSearchCapabilities", true) == 0) {
return OnGetSearchCapabilitiesResponse(res, device, action, userdata);
} else if (actionName.Compare("GetSortCapabilities", true) == 0) {
return OnGetSortCapabilitiesResponse(res, device, action, userdata);
}

return NPT_SUCCESS;
Expand Down Expand Up @@ -435,6 +493,64 @@ PLT_MediaBrowser::OnSearchResponse(NPT_Result res,
return NPT_FAILURE;
}

/*----------------------------------------------------------------------
| PLT_MediaBrowser::OnGetSearchCapabilitiesResponse
+---------------------------------------------------------------------*/
NPT_Result
PLT_MediaBrowser::OnGetSearchCapabilitiesResponse(NPT_Result res,
PLT_DeviceDataReference& device,
PLT_ActionReference& action,
void* userdata)
{
NPT_String value;

if (!m_Delegate) return NPT_SUCCESS;

if (NPT_FAILED(res) || action->GetErrorCode() != 0) {
goto bad_action;
}

if (NPT_FAILED(action->GetArgumentValue("SearchCaps", value))) {
goto bad_action;
}

m_Delegate->OnGetSearchCapabilitiesResult(NPT_SUCCESS, device, value, userdata);
return NPT_SUCCESS;

bad_action:
m_Delegate->OnGetSearchCapabilitiesResult(NPT_FAILURE, device, value, userdata);
return NPT_FAILURE;
}

/*----------------------------------------------------------------------
| PLT_MediaBrowser::OnGetSearchCapabilitiesResponse
+---------------------------------------------------------------------*/
NPT_Result
PLT_MediaBrowser::OnGetSortCapabilitiesResponse(NPT_Result res,
PLT_DeviceDataReference& device,
PLT_ActionReference& action,
void* userdata)
{
NPT_String value;

if (!m_Delegate) return NPT_SUCCESS;

if (NPT_FAILED(res) || action->GetErrorCode() != 0) {
goto bad_action;
}

if (NPT_FAILED(action->GetArgumentValue("SortCaps", value))) {
goto bad_action;
}

m_Delegate->OnGetSortCapabilitiesResult(NPT_SUCCESS, device, value, userdata);
return NPT_SUCCESS;

bad_action:
m_Delegate->OnGetSortCapabilitiesResult(NPT_FAILURE, device, value, userdata);
return NPT_FAILURE;
}

/*----------------------------------------------------------------------
| PLT_MediaBrowser::OnEventNotify
+---------------------------------------------------------------------*/
Expand Down
28 changes: 28 additions & 0 deletions lib/libUPnP/Platinum/Source/Devices/MediaServer/PltMediaBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ class PLT_MediaBrowserDelegate
PLT_DeviceDataReference& /*device*/,
PLT_BrowseInfo* /*info*/,
void* /*userdata*/) {}

virtual void OnGetSearchCapabilitiesResult(
NPT_Result /*res*/,
PLT_DeviceDataReference& /*device*/,
NPT_String /*searchCapabilities*/,
void* /*userdata*/) {}

virtual void OnGetSortCapabilitiesResult(
NPT_Result /*res*/,
PLT_DeviceDataReference& /*device*/,
NPT_String /*sortCapabilities*/,
void* /*userdata*/) {}
};

/*----------------------------------------------------------------------
Expand Down Expand Up @@ -124,6 +136,12 @@ class PLT_MediaBrowser : public PLT_CtrlPointListener
const char* filter = "dc:date,upnp:genre,res,res@duration,res@size,upnp:albumArtURI,upnp:originalTrackNumber,upnp:album,upnp:artist,upnp:author", // explicitely specify res otherwise WMP won't return a URL!
void* userdata = NULL);

virtual NPT_Result GetSearchCapabilities(PLT_DeviceDataReference& device,
void* userdata = NULL);

virtual NPT_Result GetSortCapabilities(PLT_DeviceDataReference& device,
void* userdata = NULL);

// methods
virtual const NPT_Lock<PLT_DeviceDataReferenceList>& GetMediaServers() { return m_MediaServers; }
virtual NPT_Result FindServer(const char* uuid, PLT_DeviceDataReference& device);
Expand All @@ -146,6 +164,16 @@ class PLT_MediaBrowser : public PLT_CtrlPointListener
PLT_DeviceDataReference& device,
PLT_ActionReference& action,
void* userdata);

virtual NPT_Result OnGetSearchCapabilitiesResponse(NPT_Result res,
PLT_DeviceDataReference& device,
PLT_ActionReference& action,
void* userdata);

virtual NPT_Result OnGetSortCapabilitiesResponse(NPT_Result res,
PLT_DeviceDataReference& device,
PLT_ActionReference& action,
void* userdata);

protected:
PLT_CtrlPointReference m_CtrlPoint;
Expand Down
Loading

0 comments on commit b5e06ca

Please sign in to comment.