c@75
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
c@75
|
2
|
c@75
|
3 /*
|
c@75
|
4 Piper C++
|
c@75
|
5
|
c@75
|
6 Centre for Digital Music, Queen Mary, University of London.
|
cannam@220
|
7 Copyright 2015-2017 QMUL.
|
c@75
|
8
|
c@75
|
9 Permission is hereby granted, free of charge, to any person
|
c@75
|
10 obtaining a copy of this software and associated documentation
|
c@75
|
11 files (the "Software"), to deal in the Software without
|
c@75
|
12 restriction, including without limitation the rights to use, copy,
|
c@75
|
13 modify, merge, publish, distribute, sublicense, and/or sell copies
|
c@75
|
14 of the Software, and to permit persons to whom the Software is
|
c@75
|
15 furnished to do so, subject to the following conditions:
|
c@75
|
16
|
c@75
|
17 The above copyright notice and this permission notice shall be
|
c@75
|
18 included in all copies or substantial portions of the Software.
|
c@75
|
19
|
c@75
|
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
c@75
|
21 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
c@75
|
22 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
c@75
|
23 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
|
c@75
|
24 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
c@75
|
25 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
c@75
|
26 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
c@75
|
27
|
c@75
|
28 Except as contained in this notice, the names of the Centre for
|
c@75
|
29 Digital Music; Queen Mary, University of London; and Chris Cannam
|
c@75
|
30 shall not be used in advertising or otherwise to promote the sale,
|
c@75
|
31 use or other dealings in this Software without prior written
|
c@75
|
32 authorization.
|
c@75
|
33 */
|
c@75
|
34
|
c@75
|
35 #include "piper.capnp.h"
|
c@75
|
36
|
c@75
|
37 #include <capnp/message.h>
|
c@75
|
38
|
c@75
|
39 #include <vamp-hostsdk/Plugin.h>
|
c@75
|
40 #include <vamp-hostsdk/PluginLoader.h>
|
c@97
|
41
|
c@97
|
42 #include "vamp-support/PluginStaticData.h"
|
c@97
|
43 #include "vamp-support/PluginConfiguration.h"
|
c@97
|
44 #include "vamp-support/RequestResponse.h"
|
c@75
|
45
|
c@75
|
46 #include "vamp-support/PluginHandleMapper.h"
|
c@75
|
47 #include "vamp-support/PluginOutputIdMapper.h"
|
c@75
|
48 #include "vamp-support/RequestResponseType.h"
|
c@75
|
49
|
c@97
|
50 namespace piper_vamp
|
c@75
|
51 {
|
c@75
|
52
|
c@75
|
53 /**
|
c@75
|
54 * Convert the structures laid out in the Vamp SDK classes into Cap'n
|
c@75
|
55 * Proto structures (and back again).
|
c@75
|
56 *
|
c@75
|
57 * At least some of this will be necessary for any implementation
|
c@75
|
58 * using Cap'n Proto that uses the C++ Vamp SDK to provide its
|
c@75
|
59 * reference structures. An implementation could alternatively use the
|
c@75
|
60 * Cap'n Proto structures directly, and interact with Vamp plugins
|
c@75
|
61 * using the Vamp C API, without using the C++ Vamp SDK classes at
|
c@75
|
62 * all. That would avoid a lot of copying (in Cap'n Proto style).
|
c@75
|
63 */
|
c@75
|
64 class VampnProto
|
c@75
|
65 {
|
c@75
|
66 public:
|
c@75
|
67 typedef ::capnp::MallocMessageBuilder MsgBuilder;
|
c@75
|
68
|
c@75
|
69 template <typename T, typename B>
|
c@75
|
70 static void buildBasicDescriptor(B &basic, const T &t) {
|
c@75
|
71 basic.setIdentifier(t.identifier);
|
c@75
|
72 basic.setName(t.name);
|
c@75
|
73 basic.setDescription(t.description);
|
c@75
|
74 }
|
c@75
|
75
|
c@75
|
76 template <typename T, typename B>
|
c@75
|
77 static void readBasicDescriptor(T &t, const B &basic) {
|
c@75
|
78 t.identifier = basic.getIdentifier();
|
c@75
|
79 t.name = basic.getName();
|
c@75
|
80 t.description = basic.getDescription();
|
c@75
|
81 }
|
c@75
|
82
|
c@75
|
83 template <typename T, typename M>
|
c@75
|
84 static void buildValueExtents(M &m, const T &t) {
|
c@75
|
85 m.setMinValue(t.minValue);
|
c@75
|
86 m.setMaxValue(t.maxValue);
|
c@75
|
87 }
|
c@75
|
88
|
c@75
|
89 template <typename T, typename M>
|
c@75
|
90 static void readValueExtents(T &t, const M &m) {
|
c@75
|
91 t.minValue = m.getMinValue();
|
c@75
|
92 t.maxValue = m.getMaxValue();
|
c@75
|
93 }
|
c@75
|
94
|
c@97
|
95 static void buildRealTime(piper::RealTime::Builder &b,
|
c@97
|
96 const Vamp::RealTime &t) {
|
c@75
|
97 b.setSec(t.sec);
|
c@75
|
98 b.setNsec(t.nsec);
|
c@75
|
99 }
|
c@75
|
100
|
c@97
|
101 static void readRealTime(Vamp::RealTime &t,
|
c@97
|
102 const piper::RealTime::Reader &r) {
|
c@75
|
103 t.sec = r.getSec();
|
c@75
|
104 t.nsec = r.getNsec();
|
c@75
|
105 }
|
c@75
|
106
|
c@97
|
107 static piper::SampleType
|
c@75
|
108 fromSampleType(Vamp::Plugin::OutputDescriptor::SampleType t) {
|
c@75
|
109 switch (t) {
|
c@75
|
110 case Vamp::Plugin::OutputDescriptor::OneSamplePerStep:
|
c@97
|
111 return piper::SampleType::ONE_SAMPLE_PER_STEP;
|
c@75
|
112 case Vamp::Plugin::OutputDescriptor::FixedSampleRate:
|
c@97
|
113 return piper::SampleType::FIXED_SAMPLE_RATE;
|
c@75
|
114 case Vamp::Plugin::OutputDescriptor::VariableSampleRate:
|
c@97
|
115 return piper::SampleType::VARIABLE_SAMPLE_RATE;
|
c@75
|
116 }
|
c@75
|
117 throw std::logic_error("unexpected Vamp SampleType enum value");
|
c@75
|
118 }
|
c@75
|
119
|
c@75
|
120 static Vamp::Plugin::OutputDescriptor::SampleType
|
c@97
|
121 toSampleType(piper::SampleType t) {
|
c@75
|
122 switch (t) {
|
c@97
|
123 case piper::SampleType::ONE_SAMPLE_PER_STEP:
|
c@75
|
124 return Vamp::Plugin::OutputDescriptor::OneSamplePerStep;
|
c@97
|
125 case piper::SampleType::FIXED_SAMPLE_RATE:
|
c@75
|
126 return Vamp::Plugin::OutputDescriptor::FixedSampleRate;
|
c@97
|
127 case piper::SampleType::VARIABLE_SAMPLE_RATE:
|
c@75
|
128 return Vamp::Plugin::OutputDescriptor::VariableSampleRate;
|
c@75
|
129 }
|
c@75
|
130 throw std::logic_error("unexpected Capnp SampleType enum value");
|
c@75
|
131 }
|
c@75
|
132
|
c@75
|
133 static void
|
cannam@220
|
134 buildStaticOutputDescriptor(piper::StaticOutputDescriptor::Builder &b,
|
cannam@220
|
135 const StaticOutputDescriptor &sd) {
|
cannam@220
|
136 b.setTypeURI(sd.typeURI);
|
cannam@220
|
137 }
|
cannam@220
|
138
|
cannam@220
|
139 static void
|
c@97
|
140 buildConfiguredOutputDescriptor(piper::ConfiguredOutputDescriptor::Builder &b,
|
c@75
|
141 const Vamp::Plugin::OutputDescriptor &od) {
|
c@75
|
142
|
c@75
|
143 b.setUnit(od.unit);
|
c@75
|
144 b.setSampleType(fromSampleType(od.sampleType));
|
c@75
|
145 b.setSampleRate(od.sampleRate);
|
c@75
|
146 b.setHasDuration(od.hasDuration);
|
c@75
|
147
|
c@75
|
148 b.setHasFixedBinCount(od.hasFixedBinCount);
|
c@75
|
149 if (od.hasFixedBinCount) {
|
c@102
|
150 b.setBinCount(int(od.binCount));
|
c@75
|
151 if (od.binNames.size() > 0) {
|
c@102
|
152 auto binNames = b.initBinNames(unsigned(od.binNames.size()));
|
c@102
|
153 for (int i = 0; i < int(od.binNames.size()); ++i) {
|
c@75
|
154 binNames.set(i, od.binNames[i]);
|
c@75
|
155 }
|
c@75
|
156 }
|
c@75
|
157 }
|
c@75
|
158
|
c@75
|
159 b.setHasKnownExtents(od.hasKnownExtents);
|
c@75
|
160 if (od.hasKnownExtents) {
|
c@75
|
161 buildValueExtents(b, od);
|
c@75
|
162 }
|
c@75
|
163
|
c@75
|
164 b.setIsQuantized(od.isQuantized);
|
c@75
|
165 if (od.isQuantized) {
|
c@75
|
166 b.setQuantizeStep(od.quantizeStep);
|
c@75
|
167 }
|
c@75
|
168 }
|
c@75
|
169
|
c@75
|
170 static void
|
c@97
|
171 buildOutputDescriptor(piper::OutputDescriptor::Builder &b,
|
cannam@220
|
172 const Vamp::Plugin::OutputDescriptor &od,
|
cannam@220
|
173 const StaticOutputDescriptor &sd) {
|
c@75
|
174
|
c@75
|
175 auto basic = b.initBasic();
|
c@75
|
176 buildBasicDescriptor(basic, od);
|
c@75
|
177
|
c@75
|
178 auto configured = b.initConfigured();
|
c@75
|
179 buildConfiguredOutputDescriptor(configured, od);
|
cannam@220
|
180
|
cannam@220
|
181 auto statc = b.initStatic();
|
cannam@220
|
182 buildStaticOutputDescriptor(statc, sd);
|
cannam@220
|
183 }
|
cannam@220
|
184
|
cannam@220
|
185 static void
|
cannam@220
|
186 readStaticOutputDescriptor(StaticOutputDescriptor &sd,
|
cannam@220
|
187 const piper::StaticOutputDescriptor::Reader &r) {
|
cannam@220
|
188 sd.typeURI = r.getTypeURI();
|
c@75
|
189 }
|
c@75
|
190
|
c@75
|
191 static void
|
c@75
|
192 readConfiguredOutputDescriptor(Vamp::Plugin::OutputDescriptor &od,
|
c@97
|
193 const piper::ConfiguredOutputDescriptor::Reader &r) {
|
c@75
|
194
|
c@75
|
195 od.unit = r.getUnit();
|
c@75
|
196
|
c@75
|
197 od.sampleType = toSampleType(r.getSampleType());
|
c@75
|
198 od.sampleRate = r.getSampleRate();
|
c@75
|
199 od.hasDuration = r.getHasDuration();
|
c@75
|
200
|
c@75
|
201 od.hasFixedBinCount = r.getHasFixedBinCount();
|
c@75
|
202 if (od.hasFixedBinCount) {
|
c@75
|
203 od.binCount = r.getBinCount();
|
c@75
|
204 od.binNames.clear();
|
c@75
|
205 auto nn = r.getBinNames();
|
c@75
|
206 for (const auto &n: nn) {
|
c@75
|
207 od.binNames.push_back(n);
|
c@75
|
208 }
|
c@75
|
209 }
|
c@75
|
210
|
c@75
|
211 od.hasKnownExtents = r.getHasKnownExtents();
|
c@75
|
212 if (od.hasKnownExtents) {
|
c@75
|
213 readValueExtents(od, r);
|
c@75
|
214 }
|
c@75
|
215
|
c@75
|
216 od.isQuantized = r.getIsQuantized();
|
c@75
|
217 if (od.isQuantized) {
|
c@75
|
218 od.quantizeStep = r.getQuantizeStep();
|
c@75
|
219 }
|
c@75
|
220 }
|
c@75
|
221
|
c@75
|
222 static void
|
c@75
|
223 readOutputDescriptor(Vamp::Plugin::OutputDescriptor &od,
|
cannam@220
|
224 StaticOutputDescriptor &sd,
|
c@97
|
225 const piper::OutputDescriptor::Reader &r) {
|
c@75
|
226
|
c@75
|
227 readBasicDescriptor(od, r.getBasic());
|
cannam@220
|
228 readStaticOutputDescriptor(sd, r.getStatic());
|
c@75
|
229 readConfiguredOutputDescriptor(od, r.getConfigured());
|
c@75
|
230 }
|
c@75
|
231
|
c@75
|
232 static void
|
c@97
|
233 buildParameterDescriptor(piper::ParameterDescriptor::Builder &b,
|
c@75
|
234 const Vamp::Plugin::ParameterDescriptor &pd) {
|
c@75
|
235
|
c@75
|
236 auto basic = b.initBasic();
|
c@75
|
237 buildBasicDescriptor(basic, pd);
|
c@75
|
238
|
c@75
|
239 b.setUnit(pd.unit);
|
c@75
|
240
|
c@75
|
241 buildValueExtents(b, pd);
|
c@75
|
242
|
c@75
|
243 b.setDefaultValue(pd.defaultValue);
|
c@75
|
244
|
c@75
|
245 b.setIsQuantized(pd.isQuantized);
|
c@75
|
246 if (pd.isQuantized) {
|
c@75
|
247 b.setQuantizeStep(pd.quantizeStep);
|
c@75
|
248 }
|
c@75
|
249
|
c@75
|
250 if (pd.valueNames.size() > 0) {
|
c@102
|
251 auto valueNames = b.initValueNames(unsigned(pd.valueNames.size()));
|
c@102
|
252 for (int i = 0; i < int(pd.valueNames.size()); ++i) {
|
c@75
|
253 valueNames.set(i, pd.valueNames[i]);
|
c@75
|
254 }
|
c@75
|
255 }
|
c@75
|
256 }
|
c@75
|
257
|
c@75
|
258 static void
|
c@75
|
259 readParameterDescriptor(Vamp::Plugin::ParameterDescriptor &pd,
|
c@97
|
260 const piper::ParameterDescriptor::Reader &r) {
|
c@75
|
261
|
c@75
|
262 readBasicDescriptor(pd, r.getBasic());
|
c@75
|
263
|
c@75
|
264 pd.unit = r.getUnit();
|
c@75
|
265
|
c@75
|
266 readValueExtents(pd, r);
|
c@75
|
267
|
c@75
|
268 pd.defaultValue = r.getDefaultValue();
|
c@75
|
269
|
c@75
|
270 pd.isQuantized = r.getIsQuantized();
|
c@75
|
271 if (pd.isQuantized) {
|
c@75
|
272 pd.quantizeStep = r.getQuantizeStep();
|
c@75
|
273 }
|
c@75
|
274
|
c@75
|
275 pd.valueNames.clear();
|
c@75
|
276 auto nn = r.getValueNames();
|
c@75
|
277 for (const auto &n: nn) {
|
c@75
|
278 pd.valueNames.push_back(n);
|
c@75
|
279 }
|
c@75
|
280 }
|
c@75
|
281
|
c@75
|
282 static void
|
c@97
|
283 buildFeature(piper::Feature::Builder &b,
|
c@75
|
284 const Vamp::Plugin::Feature &f) {
|
c@75
|
285
|
c@75
|
286 b.setHasTimestamp(f.hasTimestamp);
|
c@75
|
287 if (f.hasTimestamp) {
|
c@75
|
288 auto timestamp = b.initTimestamp();
|
c@75
|
289 buildRealTime(timestamp, f.timestamp);
|
c@75
|
290 }
|
c@75
|
291
|
c@75
|
292 b.setHasDuration(f.hasDuration);
|
c@75
|
293 if (f.hasDuration) {
|
c@75
|
294 auto duration = b.initDuration();
|
c@75
|
295 buildRealTime(duration, f.duration);
|
c@75
|
296 }
|
c@75
|
297
|
c@75
|
298 b.setLabel(f.label);
|
c@75
|
299
|
c@75
|
300 if (f.values.size() > 0) {
|
c@102
|
301 auto values = b.initFeatureValues(unsigned(f.values.size()));
|
c@102
|
302 for (int i = 0; i < int(f.values.size()); ++i) {
|
c@75
|
303 values.set(i, f.values[i]);
|
c@75
|
304 }
|
c@75
|
305 }
|
c@75
|
306 }
|
c@75
|
307
|
c@75
|
308 static void
|
c@75
|
309 readFeature(Vamp::Plugin::Feature &f,
|
c@97
|
310 const piper::Feature::Reader &r) {
|
c@75
|
311
|
c@75
|
312 f.hasTimestamp = r.getHasTimestamp();
|
c@75
|
313 if (f.hasTimestamp) {
|
c@75
|
314 readRealTime(f.timestamp, r.getTimestamp());
|
c@75
|
315 }
|
c@75
|
316
|
c@75
|
317 f.hasDuration = r.getHasDuration();
|
c@75
|
318 if (f.hasDuration) {
|
c@75
|
319 readRealTime(f.duration, r.getDuration());
|
c@75
|
320 }
|
c@75
|
321
|
c@75
|
322 f.label = r.getLabel();
|
c@75
|
323
|
c@75
|
324 f.values.clear();
|
c@75
|
325 auto vv = r.getFeatureValues();
|
c@75
|
326 for (auto v: vv) {
|
c@75
|
327 f.values.push_back(v);
|
c@75
|
328 }
|
c@75
|
329 }
|
c@75
|
330
|
c@75
|
331 static void
|
c@97
|
332 buildFeatureSet(piper::FeatureSet::Builder &b,
|
c@75
|
333 const Vamp::Plugin::FeatureSet &fs,
|
c@75
|
334 const PluginOutputIdMapper &omapper) {
|
c@75
|
335
|
c@102
|
336 auto featureset = b.initFeaturePairs(unsigned(fs.size()));
|
c@75
|
337 int ix = 0;
|
c@75
|
338 for (const auto &fsi : fs) {
|
c@75
|
339 auto fspair = featureset[ix];
|
c@75
|
340 fspair.setOutput(omapper.indexToId(fsi.first));
|
c@102
|
341 auto featurelist = fspair.initFeatures(unsigned(fsi.second.size()));
|
c@102
|
342 for (int j = 0; j < int(fsi.second.size()); ++j) {
|
c@75
|
343 auto feature = featurelist[j];
|
c@75
|
344 buildFeature(feature, fsi.second[j]);
|
c@75
|
345 }
|
c@75
|
346 ++ix;
|
c@75
|
347 }
|
c@75
|
348 }
|
c@75
|
349
|
c@75
|
350 static void
|
c@75
|
351 readFeatureSet(Vamp::Plugin::FeatureSet &fs,
|
c@97
|
352 const piper::FeatureSet::Reader &r,
|
c@75
|
353 const PluginOutputIdMapper &omapper) {
|
c@75
|
354
|
c@75
|
355 fs.clear();
|
c@75
|
356 auto pp = r.getFeaturePairs();
|
c@75
|
357 for (const auto &p: pp) {
|
c@75
|
358 Vamp::Plugin::FeatureList vfl;
|
c@75
|
359 auto ff = p.getFeatures();
|
c@75
|
360 for (const auto &f: ff) {
|
c@75
|
361 Vamp::Plugin::Feature vf;
|
c@75
|
362 readFeature(vf, f);
|
c@75
|
363 vfl.push_back(vf);
|
c@75
|
364 }
|
c@75
|
365 fs[omapper.idToIndex(p.getOutput())] = vfl;
|
c@75
|
366 }
|
c@75
|
367 }
|
c@75
|
368
|
c@97
|
369 static piper::InputDomain
|
c@75
|
370 fromInputDomain(Vamp::Plugin::InputDomain d) {
|
c@75
|
371 switch(d) {
|
c@75
|
372 case Vamp::Plugin::TimeDomain:
|
c@97
|
373 return piper::InputDomain::TIME_DOMAIN;
|
c@75
|
374 case Vamp::Plugin::FrequencyDomain:
|
c@97
|
375 return piper::InputDomain::FREQUENCY_DOMAIN;
|
c@75
|
376 default:
|
c@75
|
377 throw std::logic_error("unexpected Vamp InputDomain enum value");
|
c@75
|
378 }
|
c@75
|
379 }
|
c@75
|
380
|
c@75
|
381 static Vamp::Plugin::InputDomain
|
c@97
|
382 toInputDomain(piper::InputDomain d) {
|
c@75
|
383 switch(d) {
|
c@97
|
384 case piper::InputDomain::TIME_DOMAIN:
|
c@75
|
385 return Vamp::Plugin::TimeDomain;
|
c@97
|
386 case piper::InputDomain::FREQUENCY_DOMAIN:
|
c@75
|
387 return Vamp::Plugin::FrequencyDomain;
|
c@75
|
388 default:
|
c@75
|
389 throw std::logic_error("unexpected Capnp InputDomain enum value");
|
c@75
|
390 }
|
c@75
|
391 }
|
c@75
|
392
|
c@75
|
393 static void
|
c@97
|
394 buildExtractorStaticData(piper::ExtractorStaticData::Builder &b,
|
c@97
|
395 const PluginStaticData &d) {
|
c@75
|
396
|
c@75
|
397 b.setKey(d.pluginKey);
|
c@75
|
398
|
c@75
|
399 auto basic = b.initBasic();
|
c@75
|
400 buildBasicDescriptor(basic, d.basic);
|
c@75
|
401
|
c@75
|
402 b.setMaker(d.maker);
|
cannam@216
|
403 b.setRights(d.copyright);
|
c@75
|
404 b.setVersion(d.pluginVersion);
|
c@75
|
405
|
c@102
|
406 auto clist = b.initCategory(unsigned(d.category.size()));
|
c@102
|
407 for (int i = 0; i < int(d.category.size()); ++i) {
|
c@75
|
408 clist.set(i, d.category[i]);
|
c@75
|
409 }
|
c@75
|
410
|
c@102
|
411 b.setMinChannelCount(int(d.minChannelCount));
|
c@102
|
412 b.setMaxChannelCount(int(d.maxChannelCount));
|
c@75
|
413
|
c@75
|
414 const auto &vparams = d.parameters;
|
c@102
|
415 auto plist = b.initParameters(unsigned(vparams.size()));
|
c@102
|
416 for (int i = 0; i < int(vparams.size()); ++i) {
|
c@75
|
417 auto pd = plist[i];
|
c@75
|
418 buildParameterDescriptor(pd, vparams[i]);
|
c@75
|
419 }
|
c@75
|
420
|
c@75
|
421 const auto &vprogs = d.programs;
|
c@102
|
422 auto pglist = b.initPrograms(unsigned(vprogs.size()));
|
c@102
|
423 for (int i = 0; i < int(vprogs.size()); ++i) {
|
c@75
|
424 pglist.set(i, vprogs[i]);
|
c@75
|
425 }
|
c@75
|
426
|
c@75
|
427 b.setInputDomain(fromInputDomain(d.inputDomain));
|
c@75
|
428
|
c@75
|
429 const auto &vouts = d.basicOutputInfo;
|
c@102
|
430 auto olist = b.initBasicOutputInfo(unsigned(vouts.size()));
|
c@102
|
431 for (int i = 0; i < int(vouts.size()); ++i) {
|
c@75
|
432 auto od = olist[i];
|
c@75
|
433 buildBasicDescriptor(od, vouts[i]);
|
c@75
|
434 }
|
cannam@220
|
435
|
cannam@220
|
436 const auto &vstatic = d.staticOutputInfo;
|
cannam@220
|
437 auto slist = b.initStaticOutputInfo(unsigned(vstatic.size()));
|
cannam@220
|
438 int i = 0;
|
cannam@220
|
439 for (const auto &vi: vstatic) {
|
cannam@220
|
440 auto spair = slist[i];
|
cannam@220
|
441 spair.setOutput(vi.first);
|
cannam@220
|
442 auto sdata = spair.initStatic();
|
cannam@220
|
443 sdata.setTypeURI(vi.second.typeURI);
|
cannam@220
|
444 ++i;
|
cannam@220
|
445 }
|
c@75
|
446 }
|
c@75
|
447
|
c@75
|
448 static void
|
c@97
|
449 readExtractorStaticData(PluginStaticData &d,
|
c@97
|
450 const piper::ExtractorStaticData::Reader &r) {
|
c@75
|
451
|
c@75
|
452 d.pluginKey = r.getKey();
|
c@75
|
453
|
c@75
|
454 readBasicDescriptor(d.basic, r.getBasic());
|
c@75
|
455
|
c@75
|
456 d.maker = r.getMaker();
|
cannam@216
|
457 d.copyright = r.getRights();
|
c@75
|
458 d.pluginVersion = r.getVersion();
|
c@75
|
459
|
c@75
|
460 d.category.clear();
|
c@75
|
461 auto cc = r.getCategory();
|
c@75
|
462 for (auto c: cc) {
|
c@75
|
463 d.category.push_back(c);
|
c@75
|
464 }
|
c@75
|
465
|
c@75
|
466 d.minChannelCount = r.getMinChannelCount();
|
c@75
|
467 d.maxChannelCount = r.getMaxChannelCount();
|
c@75
|
468
|
c@75
|
469 d.parameters.clear();
|
c@75
|
470 auto pp = r.getParameters();
|
c@75
|
471 for (auto p: pp) {
|
c@75
|
472 Vamp::Plugin::ParameterDescriptor pd;
|
c@75
|
473 readParameterDescriptor(pd, p);
|
c@75
|
474 d.parameters.push_back(pd);
|
c@75
|
475 }
|
c@75
|
476
|
c@75
|
477 d.programs.clear();
|
c@75
|
478 auto prp = r.getPrograms();
|
c@75
|
479 for (auto p: prp) {
|
c@75
|
480 d.programs.push_back(p);
|
c@75
|
481 }
|
c@75
|
482
|
c@75
|
483 d.inputDomain = toInputDomain(r.getInputDomain());
|
c@75
|
484
|
c@75
|
485 d.basicOutputInfo.clear();
|
c@75
|
486 auto oo = r.getBasicOutputInfo();
|
c@75
|
487 for (auto o: oo) {
|
c@97
|
488 PluginStaticData::Basic b;
|
c@75
|
489 readBasicDescriptor(b, o);
|
c@75
|
490 d.basicOutputInfo.push_back(b);
|
c@75
|
491 }
|
cannam@220
|
492
|
cannam@220
|
493 d.staticOutputInfo.clear();
|
cannam@220
|
494 auto sp = r.getStaticOutputInfo();
|
cannam@220
|
495 for (auto s: sp) {
|
cannam@220
|
496 std::string id = s.getOutput();
|
cannam@220
|
497 std::string typeURI = s.getStatic().getTypeURI();
|
cannam@220
|
498 d.staticOutputInfo[id] = { typeURI };
|
cannam@220
|
499 }
|
c@75
|
500 }
|
c@75
|
501
|
c@75
|
502 static void
|
c@97
|
503 buildConfiguration(piper::Configuration::Builder &b,
|
c@97
|
504 const PluginConfiguration &c) {
|
c@75
|
505
|
c@75
|
506 const auto &vparams = c.parameterValues;
|
c@102
|
507 auto params = b.initParameterValues(unsigned(vparams.size()));
|
c@75
|
508 int i = 0;
|
c@75
|
509 for (const auto &pp : vparams) {
|
c@75
|
510 auto param = params[i++];
|
c@75
|
511 param.setParameter(pp.first);
|
c@75
|
512 param.setValue(pp.second);
|
c@75
|
513 }
|
c@75
|
514
|
c@75
|
515 b.setCurrentProgram(c.currentProgram);
|
c@75
|
516 b.setChannelCount(c.channelCount);
|
cannam@185
|
517
|
cannam@185
|
518 auto framing = b.initFraming();
|
cannam@185
|
519 framing.setStepSize(c.framing.stepSize);
|
cannam@185
|
520 framing.setBlockSize(c.framing.blockSize);
|
c@75
|
521 }
|
c@75
|
522
|
c@75
|
523 static void
|
c@97
|
524 readConfiguration(PluginConfiguration &c,
|
c@97
|
525 const piper::Configuration::Reader &r) {
|
c@75
|
526
|
c@75
|
527 auto pp = r.getParameterValues();
|
c@75
|
528 for (const auto &p: pp) {
|
c@75
|
529 c.parameterValues[p.getParameter()] = p.getValue();
|
c@75
|
530 }
|
c@75
|
531
|
c@75
|
532 c.currentProgram = r.getCurrentProgram();
|
c@75
|
533 c.channelCount = r.getChannelCount();
|
cannam@185
|
534 c.framing.stepSize = r.getFraming().getStepSize();
|
cannam@185
|
535 c.framing.blockSize = r.getFraming().getBlockSize();
|
c@75
|
536 }
|
cannam@289
|
537
|
cannam@289
|
538 static void
|
cannam@289
|
539 buildProgramParameterMap(piper::LoadResponse::PPPair::Builder &b,
|
cannam@289
|
540 const PluginProgramParameters &pparams,
|
cannam@289
|
541 std::string program) {
|
cannam@289
|
542 b.setProgram(program);
|
cannam@289
|
543 if (pparams.programParameters.find(program) ==
|
cannam@289
|
544 pparams.programParameters.end()) {
|
cannam@289
|
545 b.initParameters(0);
|
cannam@289
|
546 return;
|
cannam@289
|
547 }
|
cannam@289
|
548 auto params = b.initParameters
|
cannam@289
|
549 (unsigned(pparams.programParameters.at(program).size()));
|
cannam@289
|
550 int i = 0;
|
cannam@289
|
551 for (auto pv: pparams.programParameters.at(program)) {
|
cannam@289
|
552 params[i].setParameter(pv.first);
|
cannam@289
|
553 params[i].setValue(pv.second);
|
cannam@289
|
554 ++i;
|
cannam@289
|
555 }
|
cannam@289
|
556 }
|
cannam@289
|
557
|
cannam@289
|
558 static void
|
cannam@289
|
559 readProgramParameterMap(PluginProgramParameters &pparams,
|
cannam@289
|
560 const piper::LoadResponse::PPPair::Reader &r) {
|
cannam@289
|
561
|
cannam@289
|
562 auto program = r.getProgram();
|
cannam@289
|
563 auto params = r.getParameters();
|
cannam@289
|
564 for (auto pv: params) {
|
cannam@289
|
565 pparams.programParameters[program][pv.getParameter()] = pv.getValue();
|
cannam@289
|
566 }
|
cannam@289
|
567 }
|
c@127
|
568
|
c@127
|
569 static void
|
c@127
|
570 buildListRequest(piper::ListRequest::Builder &r,
|
c@127
|
571 const ListRequest &resp) {
|
c@75
|
572
|
c@127
|
573 auto p = r.initFrom(unsigned(resp.from.size()));
|
c@127
|
574 for (int i = 0; i < int(resp.from.size()); ++i) {
|
c@127
|
575 p.set(i, resp.from[i]);
|
c@127
|
576 }
|
c@127
|
577 }
|
c@127
|
578
|
c@127
|
579 static void
|
c@127
|
580 readListRequest(ListRequest &lr,
|
c@127
|
581 const piper::ListRequest::Reader &r) {
|
c@127
|
582
|
c@127
|
583 lr.from.clear();
|
c@127
|
584 for (auto f: r.getFrom()) {
|
c@127
|
585 lr.from.push_back(f);
|
c@127
|
586 }
|
c@127
|
587 }
|
c@127
|
588
|
c@127
|
589 static void
|
c@127
|
590 buildListResponse(piper::ListResponse::Builder &r,
|
c@127
|
591 const ListResponse &resp) {
|
c@127
|
592
|
c@127
|
593 auto p = r.initAvailable(unsigned(resp.available.size()));
|
c@127
|
594 for (int i = 0; i < int(resp.available.size()); ++i) {
|
c@127
|
595 auto pd = p[i];
|
c@127
|
596 buildExtractorStaticData(pd, resp.available[i]);
|
c@127
|
597 }
|
c@127
|
598 }
|
c@127
|
599
|
c@75
|
600 static void
|
c@97
|
601 readListResponse(ListResponse &lr,
|
c@97
|
602 const piper::ListResponse::Reader &r) {
|
c@95
|
603
|
c@95
|
604 lr.available.clear();
|
c@95
|
605 auto pp = r.getAvailable();
|
c@95
|
606 for (const auto &p: pp) {
|
c@97
|
607 PluginStaticData psd;
|
c@95
|
608 readExtractorStaticData(psd, p);
|
c@95
|
609 lr.available.push_back(psd);
|
c@95
|
610 }
|
c@95
|
611 }
|
c@95
|
612
|
c@95
|
613 static void
|
c@97
|
614 buildLoadRequest(piper::LoadRequest::Builder &r,
|
c@97
|
615 const LoadRequest &req) {
|
c@75
|
616
|
c@75
|
617 r.setKey(req.pluginKey);
|
c@75
|
618 r.setInputSampleRate(req.inputSampleRate);
|
c@75
|
619
|
c@97
|
620 std::vector<piper::AdapterFlag> flags;
|
c@75
|
621 if (req.adapterFlags & Vamp::HostExt::PluginLoader::ADAPT_INPUT_DOMAIN) {
|
c@97
|
622 flags.push_back(piper::AdapterFlag::ADAPT_INPUT_DOMAIN);
|
c@75
|
623 }
|
c@75
|
624 if (req.adapterFlags & Vamp::HostExt::PluginLoader::ADAPT_CHANNEL_COUNT) {
|
c@97
|
625 flags.push_back(piper::AdapterFlag::ADAPT_CHANNEL_COUNT);
|
c@75
|
626 }
|
c@75
|
627 if (req.adapterFlags & Vamp::HostExt::PluginLoader::ADAPT_BUFFER_SIZE) {
|
c@97
|
628 flags.push_back(piper::AdapterFlag::ADAPT_BUFFER_SIZE);
|
c@75
|
629 }
|
c@75
|
630
|
c@102
|
631 auto f = r.initAdapterFlags(unsigned(flags.size()));
|
c@102
|
632 for (int i = 0; i < int(flags.size()); ++i) {
|
c@75
|
633 f.set(i, flags[i]);
|
c@75
|
634 }
|
c@75
|
635 }
|
c@75
|
636
|
c@75
|
637 static void
|
c@97
|
638 readLoadRequest(LoadRequest &req,
|
c@97
|
639 const piper::LoadRequest::Reader &r) {
|
c@75
|
640
|
c@75
|
641 req.pluginKey = r.getKey();
|
c@75
|
642 req.inputSampleRate = r.getInputSampleRate();
|
c@75
|
643
|
c@75
|
644 int flags = 0;
|
c@75
|
645 auto aa = r.getAdapterFlags();
|
c@75
|
646 for (auto a: aa) {
|
c@97
|
647 if (a == piper::AdapterFlag::ADAPT_INPUT_DOMAIN) {
|
c@75
|
648 flags |= Vamp::HostExt::PluginLoader::ADAPT_INPUT_DOMAIN;
|
c@75
|
649 }
|
c@97
|
650 if (a == piper::AdapterFlag::ADAPT_CHANNEL_COUNT) {
|
c@75
|
651 flags |= Vamp::HostExt::PluginLoader::ADAPT_CHANNEL_COUNT;
|
c@75
|
652 }
|
c@97
|
653 if (a == piper::AdapterFlag::ADAPT_BUFFER_SIZE) {
|
c@75
|
654 flags |= Vamp::HostExt::PluginLoader::ADAPT_BUFFER_SIZE;
|
c@75
|
655 }
|
c@75
|
656 }
|
c@75
|
657 req.adapterFlags = flags;
|
c@75
|
658 }
|
c@75
|
659
|
c@75
|
660 static void
|
c@97
|
661 buildLoadResponse(piper::LoadResponse::Builder &b,
|
c@97
|
662 const LoadResponse &resp,
|
c@75
|
663 const PluginHandleMapper &pmapper) {
|
c@75
|
664
|
c@75
|
665 b.setHandle(pmapper.pluginToHandle(resp.plugin));
|
c@75
|
666 auto sd = b.initStaticData();
|
c@75
|
667 buildExtractorStaticData(sd, resp.staticData);
|
c@75
|
668 auto conf = b.initDefaultConfiguration();
|
c@75
|
669 buildConfiguration(conf, resp.defaultConfiguration);
|
cannam@289
|
670
|
cannam@289
|
671 auto pp = b.initProgramParameters
|
cannam@289
|
672 (unsigned(resp.programParameters.programParameters.size()));
|
cannam@289
|
673
|
cannam@289
|
674 int i = 0;
|
cannam@289
|
675 for (auto prog: resp.programParameters.programParameters) {
|
cannam@289
|
676 auto pb = pp[i];
|
cannam@289
|
677 buildProgramParameterMap(pb, resp.programParameters, prog.first);
|
cannam@289
|
678 ++i;
|
cannam@289
|
679 }
|
c@75
|
680 }
|
c@75
|
681
|
c@75
|
682 static void
|
c@97
|
683 readLoadResponse(LoadResponse &resp,
|
c@97
|
684 const piper::LoadResponse::Reader &r,
|
c@75
|
685 const PluginHandleMapper &pmapper) {
|
c@75
|
686
|
cannam@275
|
687 auto h = r.getHandle();
|
cannam@275
|
688 resp.plugin = pmapper.handleToPlugin(h);
|
c@75
|
689 readExtractorStaticData(resp.staticData, r.getStaticData());
|
c@75
|
690 readConfiguration(resp.defaultConfiguration,
|
c@80
|
691 r.getDefaultConfiguration());
|
cannam@289
|
692
|
cannam@289
|
693 for (auto pp: r.getProgramParameters()) {
|
cannam@289
|
694 readProgramParameterMap(resp.programParameters, pp);
|
cannam@289
|
695 }
|
c@75
|
696 }
|
c@75
|
697
|
c@75
|
698 static void
|
c@97
|
699 buildConfigurationRequest(piper::ConfigurationRequest::Builder &b,
|
c@97
|
700 const ConfigurationRequest &cr,
|
c@75
|
701 const PluginHandleMapper &pmapper) {
|
c@75
|
702
|
c@75
|
703 b.setHandle(pmapper.pluginToHandle(cr.plugin));
|
c@75
|
704 auto c = b.initConfiguration();
|
c@75
|
705 buildConfiguration(c, cr.configuration);
|
c@75
|
706 }
|
c@75
|
707
|
c@75
|
708 static void
|
c@97
|
709 readConfigurationRequest(ConfigurationRequest &cr,
|
c@97
|
710 const piper::ConfigurationRequest::Reader &r,
|
c@75
|
711 const PluginHandleMapper &pmapper) {
|
c@75
|
712
|
c@75
|
713 auto h = r.getHandle();
|
c@75
|
714 cr.plugin = pmapper.handleToPlugin(h);
|
c@75
|
715 auto c = r.getConfiguration();
|
c@75
|
716 readConfiguration(cr.configuration, c);
|
c@75
|
717 }
|
c@75
|
718
|
c@75
|
719 static void
|
c@97
|
720 buildConfigurationResponse(piper::ConfigurationResponse::Builder &b,
|
c@97
|
721 const ConfigurationResponse &cr,
|
c@75
|
722 const PluginHandleMapper &pmapper) {
|
c@75
|
723
|
c@75
|
724 b.setHandle(pmapper.pluginToHandle(cr.plugin));
|
c@102
|
725 auto olist = b.initOutputs(unsigned(cr.outputs.size()));
|
cannam@220
|
726
|
c@102
|
727 for (int i = 0; i < int(cr.outputs.size()); ++i) {
|
cannam@220
|
728
|
cannam@220
|
729 auto id = cr.outputs[i].identifier;
|
cannam@220
|
730 StaticOutputDescriptor sd;
|
cannam@220
|
731 if (cr.staticOutputInfo.find(id) != cr.staticOutputInfo.end()) {
|
cannam@220
|
732 sd = cr.staticOutputInfo.at(id);
|
cannam@220
|
733 }
|
cannam@220
|
734
|
c@75
|
735 auto od = olist[i];
|
cannam@220
|
736 buildOutputDescriptor(od, cr.outputs[i], sd);
|
c@75
|
737 }
|
cannam@220
|
738
|
cannam@185
|
739 auto framing = b.initFraming();
|
cannam@185
|
740 framing.setStepSize(cr.framing.stepSize);
|
cannam@185
|
741 framing.setBlockSize(cr.framing.blockSize);
|
c@75
|
742 }
|
c@75
|
743
|
c@75
|
744 static void
|
c@97
|
745 readConfigurationResponse(ConfigurationResponse &cr,
|
c@97
|
746 const piper::ConfigurationResponse::Reader &r,
|
c@75
|
747 const PluginHandleMapper &pmapper) {
|
c@75
|
748
|
cannam@275
|
749 auto h = r.getHandle();
|
cannam@275
|
750 cr.plugin = pmapper.handleToPlugin(h);
|
c@75
|
751 cr.outputs.clear();
|
cannam@220
|
752 cr.staticOutputInfo.clear();
|
c@75
|
753 auto oo = r.getOutputs();
|
c@75
|
754 for (const auto &o: oo) {
|
c@75
|
755 Vamp::Plugin::OutputDescriptor desc;
|
cannam@220
|
756 StaticOutputDescriptor sd;
|
cannam@220
|
757 readOutputDescriptor(desc, sd, o);
|
c@75
|
758 cr.outputs.push_back(desc);
|
cannam@220
|
759 if (sd.typeURI != "") {
|
cannam@220
|
760 cr.staticOutputInfo[desc.identifier] = { sd.typeURI };
|
cannam@220
|
761 }
|
c@75
|
762 }
|
cannam@185
|
763 cr.framing.stepSize = r.getFraming().getStepSize();
|
cannam@185
|
764 cr.framing.blockSize = r.getFraming().getBlockSize();
|
c@75
|
765 }
|
c@75
|
766
|
c@75
|
767 static void
|
c@97
|
768 buildProcessInput(piper::ProcessInput::Builder &b,
|
c@75
|
769 Vamp::RealTime timestamp,
|
c@75
|
770 const std::vector<std::vector<float> > &buffers) {
|
c@75
|
771
|
c@75
|
772 auto t = b.initTimestamp();
|
c@75
|
773 buildRealTime(t, timestamp);
|
c@102
|
774 auto vv = b.initInputBuffers(unsigned(buffers.size()));
|
c@102
|
775 for (int ch = 0; ch < int(buffers.size()); ++ch) {
|
c@75
|
776 const int n = int(buffers[ch].size());
|
c@75
|
777 vv.init(ch, n);
|
c@75
|
778 auto v = vv[ch];
|
c@75
|
779 for (int i = 0; i < n; ++i) {
|
c@75
|
780 v.set(i, buffers[ch][i]);
|
c@75
|
781 }
|
c@75
|
782 }
|
c@75
|
783 }
|
c@75
|
784
|
c@75
|
785 static void
|
c@75
|
786 readProcessInput(Vamp::RealTime ×tamp,
|
c@75
|
787 std::vector<std::vector<float> > &buffers,
|
c@97
|
788 const piper::ProcessInput::Reader &b) {
|
c@75
|
789
|
c@75
|
790 readRealTime(timestamp, b.getTimestamp());
|
c@75
|
791 buffers.clear();
|
c@75
|
792 auto vv = b.getInputBuffers();
|
c@75
|
793 for (const auto &v: vv) {
|
c@75
|
794 std::vector<float> buf;
|
c@75
|
795 for (auto x: v) {
|
c@75
|
796 buf.push_back(x);
|
c@75
|
797 }
|
c@75
|
798 buffers.push_back(buf);
|
c@75
|
799 }
|
c@75
|
800 }
|
c@75
|
801
|
c@75
|
802 static void
|
c@97
|
803 buildProcessRequest(piper::ProcessRequest::Builder &b,
|
c@97
|
804 const ProcessRequest &pr,
|
c@75
|
805 const PluginHandleMapper &pmapper) {
|
c@75
|
806
|
c@75
|
807 b.setHandle(pmapper.pluginToHandle(pr.plugin));
|
c@75
|
808 auto input = b.initProcessInput();
|
c@75
|
809 buildProcessInput(input, pr.timestamp, pr.inputBuffers);
|
c@75
|
810 }
|
c@75
|
811
|
c@75
|
812 static void
|
c@97
|
813 readProcessRequest(ProcessRequest &pr,
|
c@97
|
814 const piper::ProcessRequest::Reader &r,
|
c@75
|
815 const PluginHandleMapper &pmapper) {
|
c@75
|
816
|
c@75
|
817 auto h = r.getHandle();
|
c@75
|
818 pr.plugin = pmapper.handleToPlugin(h);
|
c@75
|
819 readProcessInput(pr.timestamp, pr.inputBuffers, r.getProcessInput());
|
c@75
|
820 }
|
c@75
|
821
|
c@75
|
822 static void
|
c@97
|
823 buildProcessResponse(piper::ProcessResponse::Builder &b,
|
c@97
|
824 const ProcessResponse &pr,
|
c@75
|
825 const PluginHandleMapper &pmapper) {
|
c@75
|
826
|
c@75
|
827 b.setHandle(pmapper.pluginToHandle(pr.plugin));
|
c@75
|
828 auto f = b.initFeatures();
|
c@75
|
829 buildFeatureSet(f, pr.features,
|
c@75
|
830 *pmapper.pluginToOutputIdMapper(pr.plugin));
|
c@75
|
831 }
|
c@75
|
832
|
c@75
|
833 static void
|
c@97
|
834 readProcessResponse(ProcessResponse &pr,
|
c@97
|
835 const piper::ProcessResponse::Reader &r,
|
c@75
|
836 const PluginHandleMapper &pmapper) {
|
c@75
|
837
|
c@75
|
838 auto h = r.getHandle();
|
c@75
|
839 pr.plugin = pmapper.handleToPlugin(h);
|
c@75
|
840 readFeatureSet(pr.features, r.getFeatures(),
|
c@75
|
841 *pmapper.handleToOutputIdMapper(r.getHandle()));
|
c@75
|
842 }
|
c@75
|
843
|
c@75
|
844 static void
|
c@97
|
845 buildFinishResponse(piper::FinishResponse::Builder &b,
|
c@97
|
846 const FinishResponse &pr,
|
c@75
|
847 const PluginHandleMapper &pmapper) {
|
c@75
|
848
|
c@75
|
849 b.setHandle(pmapper.pluginToHandle(pr.plugin));
|
c@75
|
850 auto f = b.initFeatures();
|
c@75
|
851 buildFeatureSet(f, pr.features,
|
c@75
|
852 *pmapper.pluginToOutputIdMapper(pr.plugin));
|
c@75
|
853 }
|
c@75
|
854
|
c@75
|
855 static void
|
c@97
|
856 readFinishResponse(FinishResponse &pr,
|
c@97
|
857 const piper::FinishResponse::Reader &r,
|
c@75
|
858 const PluginHandleMapper &pmapper) {
|
c@75
|
859
|
c@75
|
860 auto h = r.getHandle();
|
c@75
|
861 pr.plugin = pmapper.handleToPlugin(h);
|
c@75
|
862 readFeatureSet(pr.features, r.getFeatures(),
|
c@75
|
863 *pmapper.handleToOutputIdMapper(r.getHandle()));
|
c@75
|
864 }
|
c@75
|
865
|
c@75
|
866 static void
|
c@127
|
867 buildRpcRequest_List(piper::RpcRequest::Builder &b,
|
c@127
|
868 const ListRequest &req) {
|
c@127
|
869 auto r = b.getRequest().initList();
|
c@127
|
870 buildListRequest(r, req);
|
c@75
|
871 }
|
c@75
|
872
|
c@75
|
873 static void
|
c@97
|
874 buildRpcResponse_List(piper::RpcResponse::Builder &b,
|
c@97
|
875 const ListResponse &resp) {
|
c@75
|
876
|
c@75
|
877 auto r = b.getResponse().initList();
|
c@127
|
878 buildListResponse(r, resp);
|
c@75
|
879 }
|
c@75
|
880
|
c@75
|
881 static void
|
c@97
|
882 buildRpcRequest_Load(piper::RpcRequest::Builder &b,
|
c@97
|
883 const LoadRequest &req) {
|
c@75
|
884 auto u = b.getRequest().initLoad();
|
c@75
|
885 buildLoadRequest(u, req);
|
c@75
|
886 }
|
c@75
|
887
|
c@75
|
888 static void
|
c@97
|
889 buildRpcResponse_Load(piper::RpcResponse::Builder &b,
|
c@97
|
890 const LoadResponse &resp,
|
c@80
|
891 const PluginHandleMapper &pmapper) {
|
c@75
|
892
|
c@75
|
893 if (resp.plugin) {
|
c@75
|
894 auto u = b.getResponse().initLoad();
|
c@75
|
895 buildLoadResponse(u, resp, pmapper);
|
c@75
|
896 } else {
|
c@75
|
897 buildRpcResponse_Error(b, "Failed to load plugin", RRType::Load);
|
c@75
|
898 }
|
c@75
|
899 }
|
c@75
|
900
|
c@75
|
901 static void
|
c@97
|
902 buildRpcRequest_Configure(piper::RpcRequest::Builder &b,
|
c@97
|
903 const ConfigurationRequest &cr,
|
c@80
|
904 const PluginHandleMapper &pmapper) {
|
c@75
|
905 auto u = b.getRequest().initConfigure();
|
c@75
|
906 buildConfigurationRequest(u, cr, pmapper);
|
c@75
|
907 }
|
c@75
|
908
|
c@75
|
909 static void
|
c@97
|
910 buildRpcResponse_Configure(piper::RpcResponse::Builder &b,
|
c@97
|
911 const ConfigurationResponse &cr,
|
c@80
|
912 const PluginHandleMapper &pmapper) {
|
c@75
|
913
|
c@75
|
914 if (!cr.outputs.empty()) {
|
c@75
|
915 auto u = b.getResponse().initConfigure();
|
c@75
|
916 buildConfigurationResponse(u, cr, pmapper);
|
c@75
|
917 } else {
|
c@75
|
918 buildRpcResponse_Error(b, "Failed to configure plugin",
|
c@75
|
919 RRType::Configure);
|
c@75
|
920 }
|
c@75
|
921 }
|
c@75
|
922
|
c@75
|
923 static void
|
c@97
|
924 buildRpcRequest_Process(piper::RpcRequest::Builder &b,
|
c@97
|
925 const ProcessRequest &pr,
|
c@80
|
926 const PluginHandleMapper &pmapper) {
|
c@75
|
927 auto u = b.getRequest().initProcess();
|
c@75
|
928 buildProcessRequest(u, pr, pmapper);
|
c@75
|
929 }
|
c@75
|
930
|
c@75
|
931 static void
|
c@97
|
932 buildRpcResponse_Process(piper::RpcResponse::Builder &b,
|
c@97
|
933 const ProcessResponse &pr,
|
c@80
|
934 const PluginHandleMapper &pmapper) {
|
c@75
|
935
|
c@75
|
936 auto u = b.getResponse().initProcess();
|
c@75
|
937 buildProcessResponse(u, pr, pmapper);
|
c@75
|
938 }
|
c@75
|
939
|
c@75
|
940 static void
|
c@97
|
941 buildRpcRequest_Finish(piper::RpcRequest::Builder &b,
|
c@97
|
942 const FinishRequest &req,
|
c@80
|
943 const PluginHandleMapper &pmapper) {
|
c@75
|
944
|
c@75
|
945 auto u = b.getRequest().initFinish();
|
c@75
|
946 u.setHandle(pmapper.pluginToHandle(req.plugin));
|
c@75
|
947 }
|
c@75
|
948
|
c@75
|
949 static void
|
c@97
|
950 buildRpcResponse_Finish(piper::RpcResponse::Builder &b,
|
c@97
|
951 const FinishResponse &pr,
|
c@80
|
952 const PluginHandleMapper &pmapper) {
|
c@75
|
953
|
c@75
|
954 auto u = b.getResponse().initFinish();
|
c@75
|
955 buildFinishResponse(u, pr, pmapper);
|
c@75
|
956 }
|
c@75
|
957
|
c@75
|
958 static void
|
c@97
|
959 buildRpcResponse_Error(piper::RpcResponse::Builder &b,
|
c@80
|
960 const std::string &errorText,
|
c@80
|
961 RRType responseType)
|
c@75
|
962 {
|
c@75
|
963 std::string type;
|
c@75
|
964
|
c@75
|
965 auto e = b.getResponse().initError();
|
c@75
|
966
|
c@75
|
967 if (responseType == RRType::List) {
|
c@75
|
968 type = "list";
|
c@75
|
969 } else if (responseType == RRType::Load) {
|
c@75
|
970 type = "load";
|
c@75
|
971 } else if (responseType == RRType::Configure) {
|
c@75
|
972 type = "configure";
|
c@75
|
973 } else if (responseType == RRType::Process) {
|
c@75
|
974 type = "process";
|
c@75
|
975 } else if (responseType == RRType::Finish) {
|
c@75
|
976 type = "finish";
|
c@75
|
977 } else {
|
c@75
|
978 type = "invalid";
|
c@75
|
979 }
|
c@75
|
980
|
c@75
|
981 e.setCode(0);
|
cannam@158
|
982
|
cannam@158
|
983 if (responseType == RRType::NotValid) {
|
cannam@158
|
984 e.setMessage(errorText);
|
cannam@158
|
985 } else {
|
cannam@158
|
986 e.setMessage
|
cannam@158
|
987 (std::string("error in ") + type + " request: " + errorText);
|
cannam@158
|
988 }
|
c@75
|
989 }
|
c@75
|
990
|
c@75
|
991 static void
|
c@97
|
992 buildRpcResponse_Exception(piper::RpcResponse::Builder &b,
|
c@80
|
993 const std::exception &e,
|
c@80
|
994 RRType responseType)
|
c@75
|
995 {
|
c@75
|
996 return buildRpcResponse_Error(b, e.what(), responseType);
|
c@75
|
997 }
|
c@75
|
998
|
c@75
|
999 static RRType
|
c@97
|
1000 getRequestResponseType(const piper::RpcRequest::Reader &r) {
|
c@75
|
1001 switch (r.getRequest().which()) {
|
c@97
|
1002 case piper::RpcRequest::Request::Which::LIST:
|
c@75
|
1003 return RRType::List;
|
c@97
|
1004 case piper::RpcRequest::Request::Which::LOAD:
|
c@75
|
1005 return RRType::Load;
|
c@97
|
1006 case piper::RpcRequest::Request::Which::CONFIGURE:
|
c@75
|
1007 return RRType::Configure;
|
c@97
|
1008 case piper::RpcRequest::Request::Which::PROCESS:
|
c@75
|
1009 return RRType::Process;
|
c@97
|
1010 case piper::RpcRequest::Request::Which::FINISH:
|
c@75
|
1011 return RRType::Finish;
|
c@75
|
1012 }
|
c@75
|
1013 return RRType::NotValid;
|
c@75
|
1014 }
|
c@75
|
1015
|
c@75
|
1016 static RRType
|
c@97
|
1017 getRequestResponseType(const piper::RpcResponse::Reader &r) {
|
c@75
|
1018 switch (r.getResponse().which()) {
|
c@97
|
1019 case piper::RpcResponse::Response::Which::ERROR:
|
cannam@170
|
1020 return RRType::NotValid;
|
c@97
|
1021 case piper::RpcResponse::Response::Which::LIST:
|
c@75
|
1022 return RRType::List;
|
c@97
|
1023 case piper::RpcResponse::Response::Which::LOAD:
|
c@75
|
1024 return RRType::Load;
|
c@97
|
1025 case piper::RpcResponse::Response::Which::CONFIGURE:
|
c@75
|
1026 return RRType::Configure;
|
c@97
|
1027 case piper::RpcResponse::Response::Which::PROCESS:
|
c@75
|
1028 return RRType::Process;
|
c@97
|
1029 case piper::RpcResponse::Response::Which::FINISH:
|
c@75
|
1030 return RRType::Finish;
|
c@75
|
1031 }
|
c@75
|
1032 return RRType::NotValid;
|
c@75
|
1033 }
|
c@75
|
1034
|
c@75
|
1035 static void
|
c@75
|
1036 readRpcResponse_Error(int &code,
|
c@75
|
1037 std::string &message,
|
c@97
|
1038 const piper::RpcResponse::Reader &r) {
|
c@75
|
1039 if (getRequestResponseType(r) != RRType::NotValid) {
|
c@75
|
1040 throw std::logic_error("not an error response");
|
c@75
|
1041 }
|
c@75
|
1042 code = r.getResponse().getError().getCode();
|
c@75
|
1043 message = r.getResponse().getError().getMessage();
|
c@75
|
1044 }
|
c@75
|
1045
|
c@75
|
1046 static void
|
c@127
|
1047 readRpcRequest_List(ListRequest &req,
|
c@127
|
1048 const piper::RpcRequest::Reader &r) {
|
c@75
|
1049 if (getRequestResponseType(r) != RRType::List) {
|
c@75
|
1050 throw std::logic_error("not a list request");
|
c@75
|
1051 }
|
c@127
|
1052 readListRequest(req, r.getRequest().getList());
|
c@75
|
1053 }
|
c@75
|
1054
|
c@75
|
1055 static void
|
c@97
|
1056 readRpcResponse_List(ListResponse &resp,
|
c@97
|
1057 const piper::RpcResponse::Reader &r) {
|
c@75
|
1058 if (getRequestResponseType(r) != RRType::List) {
|
c@75
|
1059 throw std::logic_error("not a list response");
|
c@75
|
1060 }
|
c@95
|
1061 readListResponse(resp, r.getResponse().getList());
|
c@75
|
1062 }
|
c@75
|
1063
|
c@75
|
1064 static void
|
c@97
|
1065 readRpcRequest_Load(LoadRequest &req,
|
c@97
|
1066 const piper::RpcRequest::Reader &r) {
|
c@75
|
1067 if (getRequestResponseType(r) != RRType::Load) {
|
c@75
|
1068 throw std::logic_error("not a load request");
|
c@75
|
1069 }
|
c@75
|
1070 readLoadRequest(req, r.getRequest().getLoad());
|
c@75
|
1071 }
|
c@75
|
1072
|
c@75
|
1073 static void
|
c@97
|
1074 readRpcResponse_Load(LoadResponse &resp,
|
c@97
|
1075 const piper::RpcResponse::Reader &r,
|
c@75
|
1076 const PluginHandleMapper &pmapper) {
|
c@75
|
1077 if (getRequestResponseType(r) != RRType::Load) {
|
c@75
|
1078 throw std::logic_error("not a load response");
|
c@75
|
1079 }
|
c@75
|
1080 resp = {};
|
c@75
|
1081 readLoadResponse(resp, r.getResponse().getLoad(), pmapper);
|
c@75
|
1082 }
|
c@75
|
1083
|
c@75
|
1084 static void
|
c@97
|
1085 readRpcRequest_Configure(ConfigurationRequest &req,
|
c@97
|
1086 const piper::RpcRequest::Reader &r,
|
c@80
|
1087 const PluginHandleMapper &pmapper) {
|
c@75
|
1088 if (getRequestResponseType(r) != RRType::Configure) {
|
c@75
|
1089 throw std::logic_error("not a configuration request");
|
c@75
|
1090 }
|
c@75
|
1091 readConfigurationRequest(req, r.getRequest().getConfigure(), pmapper);
|
c@75
|
1092 }
|
c@75
|
1093
|
c@75
|
1094 static void
|
c@97
|
1095 readRpcResponse_Configure(ConfigurationResponse &resp,
|
c@97
|
1096 const piper::RpcResponse::Reader &r,
|
c@80
|
1097 const PluginHandleMapper &pmapper) {
|
c@75
|
1098 if (getRequestResponseType(r) != RRType::Configure) {
|
c@75
|
1099 throw std::logic_error("not a configuration response");
|
c@75
|
1100 }
|
c@75
|
1101 resp = {};
|
c@75
|
1102 readConfigurationResponse(resp,
|
c@75
|
1103 r.getResponse().getConfigure(),
|
c@75
|
1104 pmapper);
|
c@75
|
1105 }
|
c@75
|
1106
|
c@75
|
1107 static void
|
c@97
|
1108 readRpcRequest_Process(ProcessRequest &req,
|
c@97
|
1109 const piper::RpcRequest::Reader &r,
|
c@80
|
1110 const PluginHandleMapper &pmapper) {
|
c@75
|
1111 if (getRequestResponseType(r) != RRType::Process) {
|
c@75
|
1112 throw std::logic_error("not a process request");
|
c@75
|
1113 }
|
c@75
|
1114 readProcessRequest(req, r.getRequest().getProcess(), pmapper);
|
c@75
|
1115 }
|
c@75
|
1116
|
c@75
|
1117 static void
|
c@97
|
1118 readRpcResponse_Process(ProcessResponse &resp,
|
c@97
|
1119 const piper::RpcResponse::Reader &r,
|
c@80
|
1120 const PluginHandleMapper &pmapper) {
|
c@75
|
1121 if (getRequestResponseType(r) != RRType::Process) {
|
c@75
|
1122 throw std::logic_error("not a process response");
|
c@75
|
1123 }
|
c@75
|
1124 resp = {};
|
c@75
|
1125 readProcessResponse(resp, r.getResponse().getProcess(), pmapper);
|
c@75
|
1126 }
|
c@75
|
1127
|
c@75
|
1128 static void
|
c@97
|
1129 readRpcRequest_Finish(FinishRequest &req,
|
c@97
|
1130 const piper::RpcRequest::Reader &r,
|
c@80
|
1131 const PluginHandleMapper &pmapper) {
|
c@75
|
1132 if (getRequestResponseType(r) != RRType::Finish) {
|
c@75
|
1133 throw std::logic_error("not a finish request");
|
c@75
|
1134 }
|
cannam@275
|
1135 auto h = r.getRequest().getFinish().getHandle();
|
cannam@275
|
1136 req.plugin = pmapper.handleToPlugin(h);
|
c@75
|
1137 }
|
c@75
|
1138
|
c@75
|
1139 static void
|
c@97
|
1140 readRpcResponse_Finish(FinishResponse &resp,
|
c@97
|
1141 const piper::RpcResponse::Reader &r,
|
c@80
|
1142 const PluginHandleMapper &pmapper) {
|
c@75
|
1143 if (getRequestResponseType(r) != RRType::Finish) {
|
c@75
|
1144 throw std::logic_error("not a finish response");
|
c@75
|
1145 }
|
c@75
|
1146 resp = {};
|
c@75
|
1147 readFinishResponse(resp, r.getResponse().getFinish(), pmapper);
|
c@75
|
1148 }
|
c@75
|
1149 };
|
c@75
|
1150
|
c@75
|
1151 }
|
c@75
|
1152
|
c@75
|
1153
|