Merge pull request #26220 from 78andyp/blurayfixes
[xbmc.git] / lib / libUPnP / patches / 0028-platinum-add-SearchSync-method-to-SyncMediaBrowser.patch
blobe5932710f66a2b23d9be43146f69ebd5a0d6b91e
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
6 ---
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)
16 return NPT_FAILURE;
19 +static void OnResult(NPT_Result res,
20 + PLT_DeviceDataReference& device,
21 + PLT_BrowseInfo* info,
22 + void* userdata)
24 + NPT_COMPILER_UNUSED(device);
26 + if (!userdata) return;
28 + PLT_BrowseDataReference* data = (PLT_BrowseDataReference*) userdata;
29 + (*data)->res = res;
30 + if (NPT_SUCCEEDED(res) && info) {
31 + (*data)->info = *info;
32 + }
33 + (*data)->shared_var.SetValue(1);
34 + delete data;
37 /*----------------------------------------------------------------------
38 | PLT_SyncMediaBrowser::OnBrowseResult
39 +---------------------------------------------------------------------*/
40 @@ -135,17 +153,19 @@ PLT_SyncMediaBrowser::OnBrowseResult(NPT_Result res,
41 PLT_BrowseInfo* info,
42 void* userdata)
44 - NPT_COMPILER_UNUSED(device);
46 - if (!userdata) return;
47 + OnResult(res, device, info, userdata);
50 - PLT_BrowseDataReference* data = (PLT_BrowseDataReference*) userdata;
51 - (*data)->res = res;
52 - if (NPT_SUCCEEDED(res) && info) {
53 - (*data)->info = *info;
54 - }
55 - (*data)->shared_var.SetValue(1);
56 - delete data;
57 +/*----------------------------------------------------------------------
58 +| PLT_SyncMediaBrowser::OnSearchResult
59 ++---------------------------------------------------------------------*/
60 +void
61 +PLT_SyncMediaBrowser::OnSearchResult(NPT_Result res,
62 + PLT_DeviceDataReference& device,
63 + PLT_BrowseInfo* info,
64 + void* userdata)
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 ++---------------------------------------------------------------------*/
76 +NPT_Result
77 +PLT_SyncMediaBrowser::SearchSync(PLT_BrowseDataReference& browse_data,
78 + PLT_DeviceDataReference& device,
79 + const char* container_id,
80 + const char* search_criteria,
81 + NPT_Int32 index,
82 + NPT_Int32 count,
83 + const char* filter)
85 + NPT_Result res;
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,
94 + container_id,
95 + search_criteria,
96 + index,
97 + count,
98 + filter,
99 + new PLT_BrowseDataReference(browse_data));
100 + NPT_CHECK_SEVERE(res);
102 + return WaitForResponse(browse_data->shared_var);
105 +/*----------------------------------------------------------------------
106 | PLT_SyncMediaBrowser::BrowseSync
107 +---------------------------------------------------------------------*/
108 NPT_Result
109 @@ -319,6 +371,84 @@ done:
112 /*----------------------------------------------------------------------
113 +| PLT_SyncMediaBrowser::SearchSync
114 ++---------------------------------------------------------------------*/
115 +NPT_Result
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
128 + list = NULL;
130 + do {
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.
136 + res = SearchSync(
137 + browse_data,
138 + device,
139 + container_id,
140 + search_criteria,
141 + index,
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)
153 + break;
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;
163 + } else {
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
176 + // length delays
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))
180 + break;
182 + // ask for the next chunk of entries
183 + index = count;
184 + } while(1);
186 +done:
187 + return res;
190 +/*----------------------------------------------------------------------
191 | PLT_SyncMediaBrowser::IsCached
192 +---------------------------------------------------------------------*/
193 bool
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,
211 void* userdata);
212 + virtual void OnSearchResult(NPT_Result res,
213 + PLT_DeviceDataReference& device,
214 + PLT_BrowseInfo* info,
215 + void* userdata);
217 // methods
218 void SetContainerListener(PLT_MediaContainerChangesListener* listener) {
219 @@ -108,6 +115,13 @@ public:
220 NPT_Int32 start = 0,
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:
234 NPT_Int32 index,
235 NPT_Int32 count,
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,
245 + NPT_Int32 index,
246 + NPT_Int32 count,
247 + const char* filter = PLT_DEFAULT_FILTER); // explicitely specify res otherwise WMP won't return a URL!
249 private:
250 NPT_Result Find(const char* ip, PLT_DeviceDataReference& device);
251 NPT_Result WaitForResponse(NPT_SharedVariable& shared_var);
253 1.7.11.msysgit.0