1 From 4d9d36139eed70da5ee922501bcf68443a349b44 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Micha=C5=82=20Piechowiak?= <misiek.piechowiak@gmail.com>
3 Date: Fri, 2 Aug 2013 18:55:34 +0200
4 Subject: [PATCH 05/11] platinum: add SearchSync method to SyncMediaBrowser
7 .../Devices/MediaServer/PltSyncMediaBrowser.cpp | 150 +++++++++++++++++++--
8 .../Devices/MediaServer/PltSyncMediaBrowser.h | 25 +++-
9 2 files changed, 164 insertions(+), 11 deletions(-)
11 diff --git a/lib/libUPnP/Platinum/Source/Devices/MediaServer/PltSyncMediaBrowser.cpp b/lib/libUPnP/Platinum/Source/Devices/MediaServer/PltSyncMediaBrowser.cpp
12 index 24219ff..96e4121 100644
13 --- a/lib/libUPnP/Platinum/Source/Devices/MediaServer/PltSyncMediaBrowser.cpp
14 +++ b/lib/libUPnP/Platinum/Source/Devices/MediaServer/PltSyncMediaBrowser.cpp
15 @@ -126,6 +126,24 @@ PLT_SyncMediaBrowser::Find(const char* ip, PLT_DeviceDataReference& device)
19 +static void OnResult(NPT_Result res,
20 + PLT_DeviceDataReference& device,
21 + PLT_BrowseInfo* info,
24 + NPT_COMPILER_UNUSED(device);
26 + if (!userdata) return;
28 + PLT_BrowseDataReference* data = (PLT_BrowseDataReference*) userdata;
30 + if (NPT_SUCCEEDED(res) && info) {
31 + (*data)->info = *info;
33 + (*data)->shared_var.SetValue(1);
37 /*----------------------------------------------------------------------
38 | PLT_SyncMediaBrowser::OnBrowseResult
39 +---------------------------------------------------------------------*/
40 @@ -135,17 +153,19 @@ PLT_SyncMediaBrowser::OnBrowseResult(NPT_Result res,
44 - NPT_COMPILER_UNUSED(device);
46 - if (!userdata) return;
47 + OnResult(res, device, info, userdata);
50 - PLT_BrowseDataReference* data = (PLT_BrowseDataReference*) userdata;
52 - if (NPT_SUCCEEDED(res) && info) {
53 - (*data)->info = *info;
55 - (*data)->shared_var.SetValue(1);
57 +/*----------------------------------------------------------------------
58 +| PLT_SyncMediaBrowser::OnSearchResult
59 ++---------------------------------------------------------------------*/
61 +PLT_SyncMediaBrowser::OnSearchResult(NPT_Result res,
62 + PLT_DeviceDataReference& device,
63 + PLT_BrowseInfo* info,
66 + OnResult(res, device, info, userdata);
69 /*----------------------------------------------------------------------
70 @@ -228,6 +248,38 @@ PLT_SyncMediaBrowser::BrowseSync(PLT_BrowseDataReference& browse_data,
73 /*----------------------------------------------------------------------
74 +| PLT_SyncMediaBrowser::SearchSync
75 ++---------------------------------------------------------------------*/
77 +PLT_SyncMediaBrowser::SearchSync(PLT_BrowseDataReference& browse_data,
78 + PLT_DeviceDataReference& device,
79 + const char* container_id,
80 + const char* search_criteria,
87 + browse_data->shared_var.SetValue(0);
88 + browse_data->info.si = index;
90 + // send off the search packet. Note that this will
91 + // not block. There is a call to WaitForResponse in order
92 + // to block until the response comes back.
93 + res = PLT_MediaBrowser::Search(device,
99 + new PLT_BrowseDataReference(browse_data));
100 + NPT_CHECK_SEVERE(res);
102 + return WaitForResponse(browse_data->shared_var);
105 +/*----------------------------------------------------------------------
106 | PLT_SyncMediaBrowser::BrowseSync
107 +---------------------------------------------------------------------*/
109 @@ -319,6 +371,84 @@ done:
112 /*----------------------------------------------------------------------
113 +| PLT_SyncMediaBrowser::SearchSync
114 ++---------------------------------------------------------------------*/
116 +PLT_SyncMediaBrowser::SearchSync(PLT_DeviceDataReference& device,
117 + const char* container_id,
118 + const char* search_criteria,
119 + PLT_MediaObjectListReference& list,
120 + NPT_Int32 start, /* = 0 */
121 + NPT_Cardinal max_results /* = 0 */)
123 + NPT_Result res = NPT_FAILURE;
124 + NPT_Int32 index = start;
125 + NPT_UInt32 count = 0;
127 + // reset output params
131 + PLT_BrowseDataReference browse_data(new PLT_BrowseData(), true);
133 + // send off the search packet. Note that this will
134 + // not block. There is a call to WaitForResponse in order
135 + // to block until the response comes back.
142 + 200); // DLNA recommendations for browsing children is no more than 30 at a time
144 + NPT_CHECK_LABEL_WARNING(res, done);
146 + if (NPT_FAILED(browse_data->res)) {
147 + res = browse_data->res;
148 + NPT_CHECK_LABEL_WARNING(res, done);
151 + // server returned no more, bail now
152 + if (browse_data->info.nr == 0)
155 + if (browse_data->info.nr != browse_data->info.items->GetItemCount()) {
156 + NPT_LOG_WARNING_2("Server returned unexpected number of items (%d vs %d)",
157 + browse_data->info.nr, browse_data->info.items->GetItemCount());
159 + count += std::max<NPT_UInt32>(browse_data->info.nr, browse_data->info.items->GetItemCount());
161 + if (list.IsNull()) {
162 + list = browse_data->info.items;
164 + list->Add(*browse_data->info.items);
165 + // clear the list items so that the data inside is not
166 + // cleaned up by PLT_MediaItemList dtor since we copied
167 + // each pointer into the new list.
168 + browse_data->info.items->Clear();
171 + // stop now if our list contains exactly what the server said it had.
172 + // Note that the server could return 0 if it didn't know how many items were
173 + // available. In this case we have to continue browsing until
174 + // nothing is returned back by the server.
175 + // Unless we were told to stop after reaching a certain amount to avoid
177 + // (some servers may return a total matches out of whack at some point too)
178 + if ((browse_data->info.tm && browse_data->info.tm <= count) ||
179 + (max_results && count >= max_results))
182 + // ask for the next chunk of entries
190 +/*----------------------------------------------------------------------
191 | PLT_SyncMediaBrowser::IsCached
192 +---------------------------------------------------------------------*/
194 diff --git a/lib/libUPnP/Platinum/Source/Devices/MediaServer/PltSyncMediaBrowser.h b/lib/libUPnP/Platinum/Source/Devices/MediaServer/PltSyncMediaBrowser.h
195 index ffdddda..5ef9f37 100644
196 --- a/lib/libUPnP/Platinum/Source/Devices/MediaServer/PltSyncMediaBrowser.h
197 +++ b/lib/libUPnP/Platinum/Source/Devices/MediaServer/PltSyncMediaBrowser.h
198 @@ -61,6 +61,9 @@ typedef struct PLT_BrowseData {
200 typedef NPT_Reference<PLT_BrowseData> PLT_BrowseDataReference;
202 +// explicitely specify res otherwise WMP won't return a URL!
203 +#define PLT_DEFAULT_FILTER "dc:date,dc:description,upnp:longDescription,upnp:genre,res,res@duration,res@size,upnp:albumArtURI,upnp:rating,upnp:lastPlaybackPosition,upnp:lastPlaybackTime,upnp:playbackCount,upnp:originalTrackNumber,upnp:episodeNumber,upnp:programTitle,upnp:seriesTitle,upnp:album,upnp:artist,upnp:author,upnp:director,dc:publisher,searchable,childCount,dc:title,dc:creator,upnp:actor,res@resolution,upnp:episodeCount,upnp:episodeSeason,xbmc:dateadded,xbmc:rating,xbmc:votes,xbmc:artwork"
205 /*----------------------------------------------------------------------
206 | PLT_MediaContainerListener
207 +---------------------------------------------------------------------*/
208 @@ -96,6 +99,10 @@ public:
209 PLT_DeviceDataReference& device,
210 PLT_BrowseInfo* info,
212 + virtual void OnSearchResult(NPT_Result res,
213 + PLT_DeviceDataReference& device,
214 + PLT_BrowseInfo* info,
218 void SetContainerListener(PLT_MediaContainerChangesListener* listener) {
219 @@ -108,6 +115,13 @@ public:
221 NPT_Cardinal max_results = 0); // 0 means all
223 + NPT_Result SearchSync(PLT_DeviceDataReference& device,
224 + const char* container_id,
225 + const char* search_criteria,
226 + PLT_MediaObjectListReference& list,
227 + NPT_Int32 start = 0,
228 + NPT_Cardinal max_results = 0); // 0 means all
230 const NPT_Lock<PLT_DeviceMap>& GetMediaServersMap() const { return m_MediaServers; }
231 bool IsCached(const char* uuid, const char* object_id);
233 @@ -118,8 +132,17 @@ protected:
236 bool browse_metadata = false,
237 - const char* filter = "dc:date,dc:description,upnp:longDescription,upnp:genre,res,res@duration,res@size,upnp:albumArtURI,upnp:rating,upnp:lastPlaybackPosition,upnp:lastPlaybackTime,upnp:playbackCount,upnp:originalTrackNumber,upnp:episodeNumber,upnp:programTitle,upnp:seriesTitle,upnp:album,upnp:artist,upnp:author,upnp:director,dc:publisher,searchable,childCount,dc:title,dc:creator,upnp:actor,res@resolution,upnp:episodeCount,upnp:episodeSeason,xbmc:dateadded,xbmc:rating,xbmc:votes,xbmc:artwork", // explicitely specify res otherwise WMP won't return a URL!
238 + const char* filter = PLT_DEFAULT_FILTER,
239 const char* sort = "");
241 + NPT_Result SearchSync(PLT_BrowseDataReference& browse_data,
242 + PLT_DeviceDataReference& device,
243 + const char* container_id,
244 + const char* search_criteria,
247 + const char* filter = PLT_DEFAULT_FILTER); // explicitely specify res otherwise WMP won't return a URL!
250 NPT_Result Find(const char* ip, PLT_DeviceDataReference& device);
251 NPT_Result WaitForResponse(NPT_SharedVariable& shared_var);